Adds isInSession
to prevent conflicts.
This commit is contained in:
parent
38534e0798
commit
badda0bb1c
2 changed files with 198 additions and 70 deletions
|
@ -89,6 +89,10 @@ class SessionManager {
|
||||||
this.#current = undefined
|
this.#current = undefined
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isInSession() {
|
||||||
|
return this.#current !== undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = new SessionManager()
|
const session = new SessionManager()
|
||||||
|
|
264
state/state.ts
264
state/state.ts
|
@ -132,44 +132,158 @@ const state = createState({
|
||||||
else: ['zoomCameraToActual'],
|
else: ['zoomCameraToActual'],
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
COPIED: { if: 'hasSelection', do: 'copyToClipboard' },
|
|
||||||
PASTED: { do: 'pasteFromClipboard' },
|
|
||||||
PASTED_SHAPES_FROM_CLIPBOARD: 'pasteShapesFromClipboard',
|
|
||||||
COPIED_STATE_TO_CLIPBOARD: 'copyStateToClipboard',
|
|
||||||
LOADED_FONTS: 'resetShapes',
|
LOADED_FONTS: 'resetShapes',
|
||||||
TOGGLED_SHAPE_LOCK: { if: 'hasSelection', do: 'lockSelection' },
|
USED_PEN_DEVICE: 'enablePenLock',
|
||||||
TOGGLED_SHAPE_HIDE: { if: 'hasSelection', do: 'hideSelection' },
|
DISABLED_PEN_LOCK: 'disablePenLock',
|
||||||
|
TOGGLED_CODE_PANEL_OPEN: 'toggleCodePanel',
|
||||||
|
TOGGLED_STYLE_PANEL_OPEN: 'toggleStylePanel',
|
||||||
|
PANNED_CAMERA: 'panCamera',
|
||||||
|
POINTED_CANVAS: ['closeStylePanel', 'clearCurrentParentId'],
|
||||||
|
COPIED_STATE_TO_CLIPBOARD: 'copyStateToClipboard',
|
||||||
|
COPIED: { if: 'hasSelection', do: 'copyToClipboard' },
|
||||||
|
PASTED: {
|
||||||
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
|
do: 'pasteFromClipboard',
|
||||||
|
},
|
||||||
|
PASTED_SHAPES_FROM_CLIPBOARD: {
|
||||||
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
|
do: 'pasteShapesFromClipboard',
|
||||||
|
},
|
||||||
|
TOGGLED_SHAPE_LOCK: {
|
||||||
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
|
if: 'hasSelection',
|
||||||
|
do: 'lockSelection',
|
||||||
|
},
|
||||||
|
TOGGLED_SHAPE_HIDE: {
|
||||||
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
|
if: 'hasSelection',
|
||||||
|
do: 'hideSelection',
|
||||||
|
},
|
||||||
TOGGLED_SHAPE_ASPECT_LOCK: {
|
TOGGLED_SHAPE_ASPECT_LOCK: {
|
||||||
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
if: 'hasSelection',
|
if: 'hasSelection',
|
||||||
do: 'aspectLockSelection',
|
do: 'aspectLockSelection',
|
||||||
},
|
},
|
||||||
TOGGLED_CODE_PANEL_OPEN: 'toggleCodePanel',
|
CHANGED_STYLE: {
|
||||||
TOGGLED_STYLE_PANEL_OPEN: 'toggleStylePanel',
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
POINTED_CANVAS: ['closeStylePanel', 'clearCurrentParentId'],
|
do: ['updateStyles', 'applyStylesToSelection'],
|
||||||
CHANGED_STYLE: ['updateStyles', 'applyStylesToSelection'],
|
},
|
||||||
USED_PEN_DEVICE: 'enablePenLock',
|
|
||||||
DISABLED_PEN_LOCK: 'disablePenLock',
|
|
||||||
CLEARED_PAGE: {
|
CLEARED_PAGE: {
|
||||||
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
if: 'hasSelection',
|
if: 'hasSelection',
|
||||||
do: 'deleteSelection',
|
do: 'deleteSelection',
|
||||||
else: ['selectAll', 'deleteSelection'],
|
else: ['selectAll', 'deleteSelection'],
|
||||||
},
|
},
|
||||||
SELECTED_ALL: { to: 'selecting', do: 'selectAll' },
|
CREATED_PAGE: {
|
||||||
CHANGED_PAGE: 'changePage',
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
CREATED_PAGE: ['clearSelectedIds', 'createPage'],
|
do: ['clearSelectedIds', 'createPage'],
|
||||||
DELETED_PAGE: { unless: 'hasOnlyOnePage', do: 'deletePage' },
|
},
|
||||||
LOADED_FROM_FILE: ['loadDocumentFromJson', 'resetHistory'],
|
DELETED_PAGE: {
|
||||||
PANNED_CAMERA: 'panCamera',
|
unlessAny: ['isReadOnly', 'isInSession', 'hasOnlyOnePage'],
|
||||||
SELECTED_SELECT_TOOL: { to: 'selecting' },
|
do: 'deletePage',
|
||||||
SELECTED_DRAW_TOOL: { unless: 'isReadOnly', to: 'draw' },
|
},
|
||||||
SELECTED_ARROW_TOOL: { unless: 'isReadOnly', to: 'arrow' },
|
SELECTED_SELECT_TOOL: {
|
||||||
SELECTED_DOT_TOOL: { unless: 'isReadOnly', to: 'dot' },
|
unless: 'isInSession',
|
||||||
SELECTED_ELLIPSE_TOOL: { unless: 'isReadOnly', to: 'ellipse' },
|
to: 'selecting',
|
||||||
SELECTED_RAY_TOOL: { unless: 'isReadOnly', to: 'ray' },
|
},
|
||||||
SELECTED_LINE_TOOL: { unless: 'isReadOnly', to: 'line' },
|
SELECTED_DRAW_TOOL: {
|
||||||
SELECTED_POLYLINE_TOOL: { unless: 'isReadOnly', to: 'polyline' },
|
unlessAny: ['isReadOnly', 'isInSession'],
|
||||||
SELECTED_RECTANGLE_TOOL: { unless: 'isReadOnly', to: 'rectangle' },
|
to: 'draw',
|
||||||
SELECTED_TEXT_TOOL: { unless: 'isReadOnly', to: 'text' },
|
},
|
||||||
|
SELECTED_ARROW_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'arrow',
|
||||||
|
},
|
||||||
|
SELECTED_DOT_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'dot',
|
||||||
|
},
|
||||||
|
SELECTED_ELLIPSE_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'ellipse',
|
||||||
|
},
|
||||||
|
SELECTED_RAY_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'ray',
|
||||||
|
},
|
||||||
|
SELECTED_LINE_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'line',
|
||||||
|
},
|
||||||
|
SELECTED_POLYLINE_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'polyline',
|
||||||
|
},
|
||||||
|
SELECTED_RECTANGLE_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'rectangle',
|
||||||
|
},
|
||||||
|
SELECTED_TEXT_TOOL: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
to: 'text',
|
||||||
|
},
|
||||||
|
GENERATED_FROM_CODE: {
|
||||||
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
|
do: ['setCodeControls', 'setGeneratedShapes'],
|
||||||
|
},
|
||||||
|
UNDO: {
|
||||||
|
unless: 'isInSession',
|
||||||
|
do: 'undo',
|
||||||
|
},
|
||||||
|
REDO: {
|
||||||
|
unless: 'isInSession',
|
||||||
|
do: 'redo',
|
||||||
|
},
|
||||||
|
SAVED: {
|
||||||
|
unlessAny: ['isInSession', 'isReadOnly'],
|
||||||
|
do: 'forceSave',
|
||||||
|
},
|
||||||
|
LOADED_FROM_FILE: {
|
||||||
|
unless: 'isInSession',
|
||||||
|
do: ['loadDocumentFromJson', 'resetHistory'],
|
||||||
|
},
|
||||||
|
SELECTED_ALL: {
|
||||||
|
unless: 'isInSession',
|
||||||
|
to: 'selecting',
|
||||||
|
do: 'selectAll',
|
||||||
|
},
|
||||||
|
CHANGED_PAGE: {
|
||||||
|
unless: 'isInSession',
|
||||||
|
do: 'changePage',
|
||||||
|
},
|
||||||
|
ZOOMED_TO_ACTUAL: {
|
||||||
|
if: 'hasSelection',
|
||||||
|
do: 'zoomCameraToSelectionActual',
|
||||||
|
else: 'zoomCameraToActual',
|
||||||
|
},
|
||||||
|
ZOOMED_CAMERA: 'zoomCamera',
|
||||||
|
INCREASED_CODE_FONT_SIZE: 'increaseCodeFontSize',
|
||||||
|
DECREASED_CODE_FONT_SIZE: 'decreaseCodeFontSize',
|
||||||
|
CHANGED_CODE_CONTROL: 'updateControls',
|
||||||
|
TOGGLED_TOOL_LOCK: 'toggleToolLock',
|
||||||
|
ZOOMED_TO_SELECTION: {
|
||||||
|
if: 'hasSelection',
|
||||||
|
do: 'zoomCameraToSelection',
|
||||||
|
},
|
||||||
|
STARTED_PINCHING: {
|
||||||
|
unless: 'isInSession',
|
||||||
|
to: 'pinching',
|
||||||
|
},
|
||||||
|
ZOOMED_TO_FIT: ['zoomCameraToFit', 'zoomCameraToActual'],
|
||||||
|
ZOOMED_IN: 'zoomIn',
|
||||||
|
ZOOMED_OUT: 'zoomOut',
|
||||||
|
RESET_CAMERA: 'resetCamera',
|
||||||
|
COPIED_TO_SVG: 'copyToSvg',
|
||||||
|
LOADED_FROM_FILE_STSTEM: 'loadFromFileSystem',
|
||||||
|
SAVED_AS_TO_FILESYSTEM: 'saveAsToFileSystem',
|
||||||
|
SAVED_TO_FILESYSTEM: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
then: {
|
||||||
|
if: 'isReadOnly',
|
||||||
|
do: 'saveAsToFileSystem',
|
||||||
|
else: 'saveToFileSystem',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
initial: 'selecting',
|
initial: 'selecting',
|
||||||
states: {
|
states: {
|
||||||
|
@ -179,52 +293,60 @@ const state = createState({
|
||||||
UNDO: 'undo',
|
UNDO: 'undo',
|
||||||
REDO: 'redo',
|
REDO: 'redo',
|
||||||
SAVED: 'forceSave',
|
SAVED: 'forceSave',
|
||||||
LOADED_FROM_FILE_STSTEM: 'loadFromFileSystem',
|
DELETED: {
|
||||||
SAVED_TO_FILESYSTEM: 'saveToFileSystem',
|
unless: 'isReadOnly',
|
||||||
SAVED_AS_TO_FILESYSTEM: 'saveAsToFileSystem',
|
do: 'deleteSelection',
|
||||||
SAVED_CODE: 'saveCode',
|
},
|
||||||
DELETED: 'deleteSelection',
|
SAVED_CODE: {
|
||||||
INCREASED_CODE_FONT_SIZE: 'increaseCodeFontSize',
|
unless: 'isReadOnly',
|
||||||
DECREASED_CODE_FONT_SIZE: 'decreaseCodeFontSize',
|
do: 'saveCode',
|
||||||
CHANGED_CODE_CONTROL: 'updateControls',
|
},
|
||||||
GENERATED_FROM_CODE: ['setCodeControls', 'setGeneratedShapes'],
|
|
||||||
TOGGLED_TOOL_LOCK: 'toggleToolLock',
|
|
||||||
MOVED_TO_PAGE: {
|
MOVED_TO_PAGE: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
if: 'hasSelection',
|
if: 'hasSelection',
|
||||||
do: ['moveSelectionToPage', 'zoomCameraToSelectionActual'],
|
do: ['moveSelectionToPage', 'zoomCameraToSelectionActual'],
|
||||||
},
|
},
|
||||||
MOVED: { if: 'hasSelection', do: 'moveSelection' },
|
MOVED: {
|
||||||
DUPLICATED: { if: 'hasSelection', do: 'duplicateSelection' },
|
unless: 'isReadOnly',
|
||||||
ROTATED_CCW: { if: 'hasSelection', do: 'rotateSelectionCcw' },
|
if: 'hasSelection',
|
||||||
ALIGNED: { if: 'hasMultipleSelection', do: 'alignSelection' },
|
do: 'moveSelection',
|
||||||
STRETCHED: { if: 'hasMultipleSelection', do: 'stretchSelection' },
|
},
|
||||||
|
DUPLICATED: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
if: 'hasSelection',
|
||||||
|
do: 'duplicateSelection',
|
||||||
|
},
|
||||||
|
ROTATED_CCW: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
if: 'hasSelection',
|
||||||
|
do: 'rotateSelectionCcw',
|
||||||
|
},
|
||||||
|
ALIGNED: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
if: 'hasMultipleSelection',
|
||||||
|
do: 'alignSelection',
|
||||||
|
},
|
||||||
|
STRETCHED: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
if: 'hasMultipleSelection',
|
||||||
|
do: 'stretchSelection',
|
||||||
|
},
|
||||||
DISTRIBUTED: {
|
DISTRIBUTED: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
if: 'hasMultipleSelection',
|
if: 'hasMultipleSelection',
|
||||||
do: 'distributeSelection',
|
do: 'distributeSelection',
|
||||||
},
|
},
|
||||||
GROUPED: { if: 'hasMultipleSelection', do: 'groupSelection' },
|
GROUPED: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
if: 'hasMultipleSelection',
|
||||||
|
do: 'groupSelection',
|
||||||
|
},
|
||||||
UNGROUPED: {
|
UNGROUPED: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
if: ['hasSelection', 'selectionIncludesGroups'],
|
if: ['hasSelection', 'selectionIncludesGroups'],
|
||||||
do: 'ungroupSelection',
|
do: 'ungroupSelection',
|
||||||
},
|
},
|
||||||
NUDGED: { do: 'nudgeSelection' },
|
NUDGED: { do: 'nudgeSelection' },
|
||||||
ZOOMED_CAMERA: {
|
|
||||||
do: 'zoomCamera',
|
|
||||||
},
|
|
||||||
ZOOMED_TO_ACTUAL: {
|
|
||||||
if: 'hasSelection',
|
|
||||||
do: 'zoomCameraToSelectionActual',
|
|
||||||
else: 'zoomCameraToActual',
|
|
||||||
},
|
|
||||||
ZOOMED_TO_SELECTION: {
|
|
||||||
if: 'hasSelection',
|
|
||||||
do: 'zoomCameraToSelection',
|
|
||||||
},
|
|
||||||
ZOOMED_TO_FIT: ['zoomCameraToFit', 'zoomCameraToActual'],
|
|
||||||
ZOOMED_IN: 'zoomIn',
|
|
||||||
ZOOMED_OUT: 'zoomOut',
|
|
||||||
RESET_CAMERA: 'resetCamera',
|
|
||||||
COPIED_TO_SVG: 'copyToSvg',
|
|
||||||
},
|
},
|
||||||
initial: 'notPointing',
|
initial: 'notPointing',
|
||||||
states: {
|
states: {
|
||||||
|
@ -232,7 +354,6 @@ const state = createState({
|
||||||
onEnter: 'clearPointedId',
|
onEnter: 'clearPointedId',
|
||||||
on: {
|
on: {
|
||||||
CANCELLED: 'clearSelectedIds',
|
CANCELLED: 'clearSelectedIds',
|
||||||
STARTED_PINCHING: { to: 'pinching' },
|
|
||||||
POINTED_CANVAS: { to: 'brushSelecting' },
|
POINTED_CANVAS: { to: 'brushSelecting' },
|
||||||
POINTED_BOUNDS: [
|
POINTED_BOUNDS: [
|
||||||
{
|
{
|
||||||
|
@ -242,21 +363,27 @@ const state = createState({
|
||||||
{ to: 'pointingBounds' },
|
{ to: 'pointingBounds' },
|
||||||
],
|
],
|
||||||
POINTED_BOUNDS_HANDLE: {
|
POINTED_BOUNDS_HANDLE: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
if: 'isPointingRotationHandle',
|
if: 'isPointingRotationHandle',
|
||||||
to: 'rotatingSelection',
|
to: 'rotatingSelection',
|
||||||
else: { to: 'transformingSelection' },
|
else: { to: 'transformingSelection' },
|
||||||
},
|
},
|
||||||
STARTED_EDITING_SHAPE: {
|
STARTED_EDITING_SHAPE: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
get: 'firstSelectedShape',
|
get: 'firstSelectedShape',
|
||||||
if: ['hasSingleSelection', 'canEditSelectedShape'],
|
if: ['hasSingleSelection', 'canEditSelectedShape'],
|
||||||
do: 'setEditingId',
|
do: 'setEditingId',
|
||||||
to: 'editingShape',
|
to: 'editingShape',
|
||||||
},
|
},
|
||||||
DOUBLE_POINTED_BOUNDS_HANDLE: {
|
DOUBLE_POINTED_BOUNDS_HANDLE: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
if: 'hasSingleSelection',
|
if: 'hasSingleSelection',
|
||||||
do: 'resetShapeBounds',
|
do: 'resetShapeBounds',
|
||||||
},
|
},
|
||||||
POINTED_HANDLE: { to: 'translatingHandles' },
|
POINTED_HANDLE: {
|
||||||
|
unless: 'isReadOnly',
|
||||||
|
to: 'translatingHandles',
|
||||||
|
},
|
||||||
MOVED_OVER_SHAPE: {
|
MOVED_OVER_SHAPE: {
|
||||||
if: 'pointHitsShape',
|
if: 'pointHitsShape',
|
||||||
then: {
|
then: {
|
||||||
|
@ -360,7 +487,7 @@ const state = createState({
|
||||||
{ to: 'notPointing' },
|
{ to: 'notPointing' },
|
||||||
],
|
],
|
||||||
MOVED_POINTER: {
|
MOVED_POINTER: {
|
||||||
unless: 'isReadOnly',
|
unless: ['isReadOnly', 'isInSession'],
|
||||||
if: 'distanceImpliesDrag',
|
if: 'distanceImpliesDrag',
|
||||||
to: 'translatingSelection',
|
to: 'translatingSelection',
|
||||||
},
|
},
|
||||||
|
@ -506,12 +633,6 @@ const state = createState({
|
||||||
do: 'createShape',
|
do: 'createShape',
|
||||||
to: 'draw.editing',
|
to: 'draw.editing',
|
||||||
},
|
},
|
||||||
UNDO: 'undo',
|
|
||||||
REDO: 'redo',
|
|
||||||
SAVED: 'forceSave',
|
|
||||||
LOADED_FROM_FILE_STSTEM: 'loadFromFileSystem',
|
|
||||||
SAVED_TO_FILESYSTEM: 'saveToFileSystem',
|
|
||||||
SAVED_AS_TO_FILESYSTEM: 'saveAsToFileSystem',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
editing: {
|
editing: {
|
||||||
|
@ -883,6 +1004,9 @@ const state = createState({
|
||||||
isReadOnly(data) {
|
isReadOnly(data) {
|
||||||
return data.isReadOnly
|
return data.isReadOnly
|
||||||
},
|
},
|
||||||
|
isInSession() {
|
||||||
|
return session.isInSession
|
||||||
|
},
|
||||||
canEditSelectedShape(data, payload, result: Shape) {
|
canEditSelectedShape(data, payload, result: Shape) {
|
||||||
return getShapeUtils(result).canEdit && !result.isLocked
|
return getShapeUtils(result).canEdit && !result.isLocked
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue