@tldraw/editor 4.3.0-canary.bf87ebaf143a → 4.3.0-canary.c08047039e53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist-cjs/index.d.ts +392 -118
- package/dist-cjs/index.js +7 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/ErrorBoundary.js.map +1 -1
- package/dist-cjs/lib/components/GeometryDebuggingView.js +1 -17
- package/dist-cjs/lib/components/GeometryDebuggingView.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/constants.js +1 -3
- package/dist-cjs/lib/constants.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +301 -278
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +16 -23
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +3 -3
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js +12 -3
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +1 -1
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +5 -6
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +591 -0
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/RBushIndex.js +144 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/RBushIndex.js.map +7 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +181 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +1 -22
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +31 -23
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +3 -3
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
- package/dist-cjs/lib/exports/parseCss.js +1 -1
- package/dist-cjs/lib/exports/parseCss.js.map +2 -2
- package/dist-cjs/lib/hooks/useEvent.js +1 -1
- package/dist-cjs/lib/hooks/useEvent.js.map +2 -2
- package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useGestureEvents.js +1 -1
- package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useScreenBounds.js.map +2 -2
- package/dist-cjs/lib/hooks/useStateAttribute.js +4 -1
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +2 -2
- package/dist-cjs/lib/hooks/useTransform.js.map +1 -1
- package/dist-cjs/lib/options.js +4 -1
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +3 -0
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +1 -0
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/utils/rotation.js +1 -1
- package/dist-cjs/lib/utils/rotation.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +392 -118
- package/dist-esm/index.mjs +7 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/ErrorBoundary.mjs.map +1 -1
- package/dist-esm/lib/components/GeometryDebuggingView.mjs +1 -17
- package/dist-esm/lib/components/GeometryDebuggingView.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/constants.mjs +1 -3
- package/dist-esm/lib/constants.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +302 -281
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +16 -23
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +3 -3
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs +13 -4
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +5 -6
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +573 -0
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/RBushIndex.mjs +114 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/RBushIndex.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +161 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +1 -22
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +31 -23
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +3 -3
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
- package/dist-esm/lib/exports/parseCss.mjs +1 -1
- package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEvent.mjs +1 -1
- package/dist-esm/lib/hooks/useEvent.mjs.map +2 -2
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs +1 -1
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useScreenBounds.mjs.map +2 -2
- package/dist-esm/lib/hooks/useStateAttribute.mjs +4 -1
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +2 -2
- package/dist-esm/lib/hooks/useTransform.mjs.map +1 -1
- package/dist-esm/lib/options.mjs +4 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +3 -0
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +1 -0
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/utils/rotation.mjs +1 -1
- package/dist-esm/lib/utils/rotation.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +6 -8
- package/package.json +21 -17
- package/src/index.ts +4 -0
- package/src/lib/components/ErrorBoundary.tsx +1 -1
- package/src/lib/components/GeometryDebuggingView.tsx +1 -19
- package/src/lib/components/default-components/DefaultCanvas.tsx +1 -5
- package/src/lib/config/TLUserPreferences.test.ts +40 -0
- package/src/lib/constants.ts +0 -2
- package/src/lib/editor/Editor.test.ts +140 -0
- package/src/lib/editor/Editor.ts +374 -321
- package/src/lib/editor/derivations/notVisibleShapes.ts +21 -33
- package/src/lib/editor/derivations/parentsToChildren.ts +18 -7
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +17 -31
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +1 -1
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +129 -79
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +10 -6
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +566 -0
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +0 -4
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +12 -0
- package/src/lib/editor/managers/SnapManager/SnapManager.ts +1 -1
- package/src/lib/editor/managers/SpatialIndexManager/RBushIndex.ts +144 -0
- package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +215 -0
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +40 -107
- package/src/lib/editor/managers/TickManager/TickManager.ts +2 -32
- package/src/lib/editor/shapes/ShapeUtil.ts +67 -24
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +3 -3
- package/src/lib/exports/parseCss.test.ts +1 -0
- package/src/lib/exports/parseCss.ts +1 -1
- package/src/lib/hooks/useEvent.tsx +1 -1
- package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +1 -1
- package/src/lib/hooks/useGestureEvents.ts +2 -2
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +1 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +1 -1
- package/src/lib/hooks/useScreenBounds.ts +1 -1
- package/src/lib/hooks/useStateAttribute.ts +4 -1
- package/src/lib/hooks/useTransform.ts +1 -1
- package/src/lib/options.ts +19 -0
- package/src/lib/primitives/Box.ts +9 -0
- package/src/lib/primitives/geometry/Geometry2d.ts +1 -0
- package/src/lib/utils/rotation.ts +1 -1
- package/src/version.ts +3 -3
|
@@ -104,7 +104,6 @@ var import_assets = require("../utils/assets");
|
|
|
104
104
|
var import_debug_flags = require("../utils/debug-flags");
|
|
105
105
|
var import_deepLinks = require("../utils/deepLinks");
|
|
106
106
|
var import_getIncrementedName = require("../utils/getIncrementedName");
|
|
107
|
-
var import_keyboard = require("../utils/keyboard");
|
|
108
107
|
var import_reorderShapes = require("../utils/reorderShapes");
|
|
109
108
|
var import_rotation = require("../utils/rotation");
|
|
110
109
|
var import_bindingsIndex = require("./derivations/bindingsIndex");
|
|
@@ -116,14 +115,16 @@ var import_EdgeScrollManager = require("./managers/EdgeScrollManager/EdgeScrollM
|
|
|
116
115
|
var import_FocusManager = require("./managers/FocusManager/FocusManager");
|
|
117
116
|
var import_FontManager = require("./managers/FontManager/FontManager");
|
|
118
117
|
var import_HistoryManager = require("./managers/HistoryManager/HistoryManager");
|
|
118
|
+
var import_InputsManager = require("./managers/InputsManager/InputsManager");
|
|
119
119
|
var import_ScribbleManager = require("./managers/ScribbleManager/ScribbleManager");
|
|
120
120
|
var import_SnapManager = require("./managers/SnapManager/SnapManager");
|
|
121
|
+
var import_SpatialIndexManager = require("./managers/SpatialIndexManager/SpatialIndexManager");
|
|
121
122
|
var import_TextManager = require("./managers/TextManager/TextManager");
|
|
122
123
|
var import_TickManager = require("./managers/TickManager/TickManager");
|
|
123
124
|
var import_UserPreferencesManager = require("./managers/UserPreferencesManager/UserPreferencesManager");
|
|
124
125
|
var import_RootState = require("./tools/RootState");
|
|
125
|
-
var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, _getNotVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getEfficientZoomLevel_dec, __getAboveDebouncedZoomThreshold_dec, _getDebouncedZoomLevel_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getCurrentPageShapesInReadingOrder_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec,
|
|
126
|
-
class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed],
|
|
126
|
+
var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, _getNotVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getEfficientZoomLevel_dec, __getAboveDebouncedZoomThreshold_dec, _getDebouncedZoomLevel_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getCurrentPageShapesInReadingOrder_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _canRedo_dec, _canUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
|
|
127
|
+
class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _canUndo_dec = [import_state.computed], _canRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getCurrentPageShapesInReadingOrder_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getRichTextEditor_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getDebouncedZoomLevel_dec = [import_state.computed], __getAboveDebouncedZoomThreshold_dec = [import_state.computed], _getEfficientZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], _getNotVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
|
|
127
128
|
constructor({
|
|
128
129
|
store,
|
|
129
130
|
user,
|
|
@@ -159,7 +160,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
159
160
|
*/
|
|
160
161
|
__publicField(this, "root");
|
|
161
162
|
/**
|
|
162
|
-
* A set of functions to call when the
|
|
163
|
+
* A set of functions to call when the editor is disposed.
|
|
163
164
|
*
|
|
164
165
|
* @public
|
|
165
166
|
*/
|
|
@@ -170,14 +171,24 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
170
171
|
* @public
|
|
171
172
|
*/
|
|
172
173
|
__publicField(this, "isDisposed", false);
|
|
173
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* A manager for the editor's tick events.
|
|
176
|
+
*
|
|
177
|
+
* @internal */
|
|
174
178
|
__publicField(this, "_tickManager");
|
|
175
179
|
/**
|
|
176
|
-
* A manager for the
|
|
180
|
+
* A manager for the editor's input state.
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
__publicField(this, "inputs");
|
|
185
|
+
/**
|
|
186
|
+
* A manager for the editor's snapping feature.
|
|
177
187
|
*
|
|
178
188
|
* @public
|
|
179
189
|
*/
|
|
180
190
|
__publicField(this, "snaps");
|
|
191
|
+
__publicField(this, "_spatialIndex");
|
|
181
192
|
/**
|
|
182
193
|
* A manager for the any asynchronous events and making sure they're
|
|
183
194
|
* cleaned up upon disposal.
|
|
@@ -255,7 +266,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
255
266
|
__publicField(this, "bindingUtils");
|
|
256
267
|
/* --------------------- History -------------------- */
|
|
257
268
|
/**
|
|
258
|
-
* A manager for the
|
|
269
|
+
* A manager for the editor's history.
|
|
259
270
|
*
|
|
260
271
|
* @readonly
|
|
261
272
|
*/
|
|
@@ -294,6 +305,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
294
305
|
/* --------------------- Shapes --------------------- */
|
|
295
306
|
__publicField(this, "_shapeGeometryCaches", {});
|
|
296
307
|
__publicField(this, "_notVisibleShapes", (0, import_notVisibleShapes.notVisibleShapes)(this));
|
|
308
|
+
__publicField(this, "_culledShapesCache", null);
|
|
297
309
|
// Parents and children
|
|
298
310
|
/**
|
|
299
311
|
* A cache of parents to children.
|
|
@@ -321,54 +333,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
321
333
|
tldraw: null,
|
|
322
334
|
excalidraw: null
|
|
323
335
|
});
|
|
324
|
-
/* --------------------- Events --------------------- */
|
|
325
|
-
/**
|
|
326
|
-
* The app's current input state.
|
|
327
|
-
*
|
|
328
|
-
* @public
|
|
329
|
-
*/
|
|
330
|
-
__publicField(this, "inputs", {
|
|
331
|
-
/** The most recent pointer down's position in the current page space. */
|
|
332
|
-
originPagePoint: new import_Vec.Vec(),
|
|
333
|
-
/** The most recent pointer down's position in screen space. */
|
|
334
|
-
originScreenPoint: new import_Vec.Vec(),
|
|
335
|
-
/** The previous pointer position in the current page space. */
|
|
336
|
-
previousPagePoint: new import_Vec.Vec(),
|
|
337
|
-
/** The previous pointer position in screen space. */
|
|
338
|
-
previousScreenPoint: new import_Vec.Vec(),
|
|
339
|
-
/** The most recent pointer position in the current page space. */
|
|
340
|
-
currentPagePoint: new import_Vec.Vec(),
|
|
341
|
-
/** The most recent pointer position in screen space. */
|
|
342
|
-
currentScreenPoint: new import_Vec.Vec(),
|
|
343
|
-
/** A set containing the currently pressed keys. */
|
|
344
|
-
keys: /* @__PURE__ */ new Set(),
|
|
345
|
-
/** A set containing the currently pressed buttons. */
|
|
346
|
-
buttons: /* @__PURE__ */ new Set(),
|
|
347
|
-
/** Whether the input is from a pe. */
|
|
348
|
-
isPen: false,
|
|
349
|
-
/** Whether the shift key is currently pressed. */
|
|
350
|
-
shiftKey: false,
|
|
351
|
-
/** Whether the meta key is currently pressed. */
|
|
352
|
-
metaKey: false,
|
|
353
|
-
/** Whether the control or command key is currently pressed. */
|
|
354
|
-
ctrlKey: false,
|
|
355
|
-
/** Whether the alt or option key is currently pressed. */
|
|
356
|
-
altKey: false,
|
|
357
|
-
/** Whether the user is dragging. */
|
|
358
|
-
isDragging: false,
|
|
359
|
-
/** Whether the user is pointing. */
|
|
360
|
-
isPointing: false,
|
|
361
|
-
/** Whether the user is pinching. */
|
|
362
|
-
isPinching: false,
|
|
363
|
-
/** Whether the user is editing. */
|
|
364
|
-
isEditing: false,
|
|
365
|
-
/** Whether the user is panning. */
|
|
366
|
-
isPanning: false,
|
|
367
|
-
/** Whether the user is spacebar panning. */
|
|
368
|
-
isSpacebarPanning: false,
|
|
369
|
-
/** Velocity of mouse pointer, in pixels per millisecond */
|
|
370
|
-
pointerVelocity: new import_Vec.Vec()
|
|
371
|
-
});
|
|
372
336
|
/**
|
|
373
337
|
* A manager for recording multiple click events.
|
|
374
338
|
*
|
|
@@ -392,8 +356,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
392
356
|
/** @internal */
|
|
393
357
|
__publicField(this, "_restoreToolId", "select");
|
|
394
358
|
/** @internal */
|
|
395
|
-
__publicField(this, "_pinchStart", 1);
|
|
396
|
-
/** @internal */
|
|
397
359
|
__publicField(this, "_didPinch", false);
|
|
398
360
|
/** @internal */
|
|
399
361
|
__publicField(this, "_selectedShapeIdsAtPointerDown", []);
|
|
@@ -419,6 +381,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
419
381
|
}
|
|
420
382
|
});
|
|
421
383
|
this.snaps = new import_SnapManager.SnapManager(this);
|
|
384
|
+
this._spatialIndex = new import_SpatialIndexManager.SpatialIndexManager(this);
|
|
385
|
+
this.disposables.add(() => this._spatialIndex.dispose());
|
|
422
386
|
this.disposables.add(this.timers.dispose);
|
|
423
387
|
this._cameraOptions.set({ ...import_constants.DEFAULT_CAMERA_OPTIONS, ...cameraOptions });
|
|
424
388
|
this._textOptions = (0, import_state.atom)("text options", textOptions ?? null);
|
|
@@ -429,6 +393,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
429
393
|
this.disposables.add(() => this.textMeasure.dispose());
|
|
430
394
|
this.fonts = new import_FontManager.FontManager(this, fontAssetUrls);
|
|
431
395
|
this._tickManager = new import_TickManager.TickManager(this);
|
|
396
|
+
this.inputs = new import_InputsManager.InputsManager(this);
|
|
432
397
|
class NewRoot extends import_RootState.RootState {
|
|
433
398
|
static initial = initialState ?? "";
|
|
434
399
|
}
|
|
@@ -895,9 +860,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
895
860
|
this.history.undo();
|
|
896
861
|
return this;
|
|
897
862
|
}
|
|
898
|
-
|
|
863
|
+
canUndo() {
|
|
899
864
|
return this.history.getNumUndos() > 0;
|
|
900
865
|
}
|
|
866
|
+
getCanUndo() {
|
|
867
|
+
return this.canUndo();
|
|
868
|
+
}
|
|
901
869
|
/**
|
|
902
870
|
* Redo to the next mark.
|
|
903
871
|
*
|
|
@@ -914,13 +882,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
914
882
|
this.history.redo();
|
|
915
883
|
return this;
|
|
916
884
|
}
|
|
885
|
+
canRedo() {
|
|
886
|
+
return this.history.getNumRedos() > 0;
|
|
887
|
+
}
|
|
888
|
+
getCanRedo() {
|
|
889
|
+
return this.canRedo();
|
|
890
|
+
}
|
|
917
891
|
clearHistory() {
|
|
918
892
|
this.history.clear();
|
|
919
893
|
return this;
|
|
920
894
|
}
|
|
921
|
-
getCanRedo() {
|
|
922
|
-
return this.history.getNumRedos() > 0;
|
|
923
|
-
}
|
|
924
895
|
/**
|
|
925
896
|
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
926
897
|
* any redos. You typically want to do this just before a user interaction begins or is handled.
|
|
@@ -1075,7 +1046,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1075
1046
|
}),
|
|
1076
1047
|
selectionCount: this.getSelectedShapes().length,
|
|
1077
1048
|
editingShape: editingShapeId ? this.getShape(editingShapeId) : void 0,
|
|
1078
|
-
inputs: this.inputs,
|
|
1049
|
+
inputs: this.inputs.toJson(),
|
|
1079
1050
|
pageState: this.getCurrentPageState(),
|
|
1080
1051
|
instanceState: this.getInstanceState(),
|
|
1081
1052
|
collaboratorCount: this.getCollaboratorsOnCurrentPage().length
|
|
@@ -1096,7 +1067,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1096
1067
|
* we're in a transaction that's about to be rolled back due to the same error we're currently
|
|
1097
1068
|
* reporting.
|
|
1098
1069
|
*
|
|
1099
|
-
* Instead, to listen to changes to this value, you need to listen to
|
|
1070
|
+
* Instead, to listen to changes to this value, you need to listen to editor's `crash` event.
|
|
1100
1071
|
*
|
|
1101
1072
|
* @internal
|
|
1102
1073
|
*/
|
|
@@ -1747,6 +1718,28 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1747
1718
|
const editingShapeId = this.getEditingShapeId();
|
|
1748
1719
|
return editingShapeId ? this.getShape(editingShapeId) : void 0;
|
|
1749
1720
|
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Whether the shape can be edited.
|
|
1723
|
+
*
|
|
1724
|
+
* @param shape - The shape (or shape id) to check if it can be edited.
|
|
1725
|
+
* @param info - The info about the edit start.
|
|
1726
|
+
*
|
|
1727
|
+
* @public
|
|
1728
|
+
* @returns true if the shape can be edited, false otherwise.
|
|
1729
|
+
*/
|
|
1730
|
+
canEditShape(shape, info) {
|
|
1731
|
+
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1732
|
+
if (!id) return false;
|
|
1733
|
+
if (id === this.getEditingShapeId()) return false;
|
|
1734
|
+
const _shape = this.getShape(id);
|
|
1735
|
+
if (!_shape) return false;
|
|
1736
|
+
const util = this.getShapeUtil(_shape);
|
|
1737
|
+
const _info = info ?? { type: "unknown" };
|
|
1738
|
+
if (!util.canEdit(_shape, _info)) return false;
|
|
1739
|
+
if (this.getIsReadonly() && !util.canEditInReadonly(_shape)) return false;
|
|
1740
|
+
if (this.isShapeOrAncestorLocked(_shape) && !util.canEditWhileLocked(_shape)) return false;
|
|
1741
|
+
return true;
|
|
1742
|
+
}
|
|
1750
1743
|
/**
|
|
1751
1744
|
* Set the current editing shape.
|
|
1752
1745
|
*
|
|
@@ -1762,42 +1755,42 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1762
1755
|
*/
|
|
1763
1756
|
setEditingShape(shape) {
|
|
1764
1757
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1765
|
-
|
|
1766
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
1767
|
-
if (id !== prevEditingShapeId) {
|
|
1768
|
-
if (id) {
|
|
1769
|
-
const shape2 = this.getShape(id);
|
|
1770
|
-
if (shape2 && this.getShapeUtil(shape2).canEdit(shape2)) {
|
|
1771
|
-
this.run(
|
|
1772
|
-
() => {
|
|
1773
|
-
this._updateCurrentPageState({ editingShapeId: id });
|
|
1774
|
-
if (prevEditingShapeId) {
|
|
1775
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1776
|
-
if (prevEditingShape) {
|
|
1777
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
this.getShapeUtil(shape2).onEditStart?.(shape2);
|
|
1781
|
-
},
|
|
1782
|
-
{ history: "ignore" }
|
|
1783
|
-
);
|
|
1784
|
-
return this;
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1758
|
+
if (!id) {
|
|
1787
1759
|
this.run(
|
|
1788
1760
|
() => {
|
|
1789
|
-
this.
|
|
1790
|
-
this._currentRichTextEditor.set(null);
|
|
1761
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
1791
1762
|
if (prevEditingShapeId) {
|
|
1792
1763
|
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1793
1764
|
if (prevEditingShape) {
|
|
1794
1765
|
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1795
1766
|
}
|
|
1796
1767
|
}
|
|
1768
|
+
this._updateCurrentPageState({ editingShapeId: null });
|
|
1769
|
+
this._currentRichTextEditor.set(null);
|
|
1797
1770
|
},
|
|
1798
1771
|
{ history: "ignore" }
|
|
1799
1772
|
);
|
|
1773
|
+
return this;
|
|
1800
1774
|
}
|
|
1775
|
+
if (!this.canEditShape(id)) return this;
|
|
1776
|
+
this.run(
|
|
1777
|
+
() => {
|
|
1778
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
1779
|
+
if (prevEditingShapeId) {
|
|
1780
|
+
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1781
|
+
if (prevEditingShape) {
|
|
1782
|
+
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
this._updateCurrentPageState({ editingShapeId: null });
|
|
1786
|
+
this._currentRichTextEditor.set(null);
|
|
1787
|
+
this.select(id);
|
|
1788
|
+
this._updateCurrentPageState({ editingShapeId: id });
|
|
1789
|
+
const nextEditingShape = this.getShape(id);
|
|
1790
|
+
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
1791
|
+
},
|
|
1792
|
+
{ history: "ignore" }
|
|
1793
|
+
);
|
|
1801
1794
|
return this;
|
|
1802
1795
|
}
|
|
1803
1796
|
getRichTextEditor() {
|
|
@@ -1930,6 +1923,25 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1930
1923
|
getCroppingShapeId() {
|
|
1931
1924
|
return this.getCurrentPageState().croppingShapeId;
|
|
1932
1925
|
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Whether the shape can be cropped.
|
|
1928
|
+
*
|
|
1929
|
+
* @param shape - The shape (or shape id) to check if it can be cropped.
|
|
1930
|
+
*
|
|
1931
|
+
* @public
|
|
1932
|
+
* @returns true if the shape can be cropped, false otherwise.
|
|
1933
|
+
*/
|
|
1934
|
+
canCropShape(shape) {
|
|
1935
|
+
if (!shape) return false;
|
|
1936
|
+
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1937
|
+
if (!id) return false;
|
|
1938
|
+
const _shape = this.getShape(id);
|
|
1939
|
+
if (!_shape) return false;
|
|
1940
|
+
const util = this.getShapeUtil(_shape);
|
|
1941
|
+
if (!util.canCrop(_shape)) return false;
|
|
1942
|
+
if (this.isShapeOrAncestorLocked(_shape)) return false;
|
|
1943
|
+
return true;
|
|
1944
|
+
}
|
|
1933
1945
|
/**
|
|
1934
1946
|
* Set the current cropping shape.
|
|
1935
1947
|
*
|
|
@@ -1951,12 +1963,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1951
1963
|
() => {
|
|
1952
1964
|
if (!id) {
|
|
1953
1965
|
this.updateCurrentPageState({ croppingShapeId: null });
|
|
1954
|
-
} else {
|
|
1955
|
-
|
|
1956
|
-
const util = this.getShapeUtil(shape2);
|
|
1957
|
-
if (shape2 && util.canCrop(shape2)) {
|
|
1958
|
-
this.updateCurrentPageState({ croppingShapeId: id });
|
|
1959
|
-
}
|
|
1966
|
+
} else if (this.canCropShape(id)) {
|
|
1967
|
+
this.updateCurrentPageState({ croppingShapeId: id });
|
|
1960
1968
|
}
|
|
1961
1969
|
},
|
|
1962
1970
|
{ history: "ignore" }
|
|
@@ -2292,7 +2300,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2292
2300
|
},
|
|
2293
2301
|
{ history: "ignore" }
|
|
2294
2302
|
);
|
|
2295
|
-
const
|
|
2303
|
+
const currentScreenPoint = this.inputs.getCurrentScreenPoint();
|
|
2304
|
+
const currentPagePoint = this.inputs.getCurrentPagePoint();
|
|
2296
2305
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2297
2306
|
this.updatePointer({
|
|
2298
2307
|
immediate: opts?.immediate,
|
|
@@ -2427,7 +2436,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2427
2436
|
* ```ts
|
|
2428
2437
|
* editor.zoomIn()
|
|
2429
2438
|
* editor.zoomIn(editor.getViewportScreenCenter(), { animation: { duration: 200 } })
|
|
2430
|
-
* editor.zoomIn(editor.inputs.
|
|
2439
|
+
* editor.zoomIn(editor.inputs.getCurrentScreenPoint(), { animation: { duration: 200 } })
|
|
2431
2440
|
* ```
|
|
2432
2441
|
*
|
|
2433
2442
|
* @param point - The screen point to zoom in on. Defaults to the screen center
|
|
@@ -2468,7 +2477,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2468
2477
|
* ```ts
|
|
2469
2478
|
* editor.zoomOut()
|
|
2470
2479
|
* editor.zoomOut(editor.getViewportScreenCenter(), { animation: { duration: 120 } })
|
|
2471
|
-
* editor.zoomOut(editor.inputs.
|
|
2480
|
+
* editor.zoomOut(editor.inputs.getCurrentScreenPoint(), { animation: { duration: 120 } })
|
|
2472
2481
|
* ```
|
|
2473
2482
|
*
|
|
2474
2483
|
* @param point - The point to zoom out on. Defaults to the viewport screen center.
|
|
@@ -2520,10 +2529,15 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2520
2529
|
if (isLocked && !opts?.force) return this;
|
|
2521
2530
|
const selectionPageBounds = this.getSelectionPageBounds();
|
|
2522
2531
|
if (selectionPageBounds) {
|
|
2523
|
-
this.
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
}
|
|
2532
|
+
const currentZoom = this.getZoomLevel();
|
|
2533
|
+
if (Math.abs(currentZoom - 1) < 0.01) {
|
|
2534
|
+
this.zoomToBounds(selectionPageBounds, opts);
|
|
2535
|
+
} else {
|
|
2536
|
+
this.zoomToBounds(selectionPageBounds, {
|
|
2537
|
+
targetZoom: 1,
|
|
2538
|
+
...opts
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2527
2541
|
}
|
|
2528
2542
|
return this;
|
|
2529
2543
|
}
|
|
@@ -2563,7 +2577,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2563
2577
|
const cameraOptions = this._cameraOptions.__unsafe__getWithoutCapture();
|
|
2564
2578
|
if (cameraOptions.isLocked && !opts?.force) return this;
|
|
2565
2579
|
const viewportScreenBounds = this.getViewportScreenBounds();
|
|
2566
|
-
const inset = opts?.inset ?? Math.min(
|
|
2580
|
+
const inset = opts?.inset ?? Math.min(this.options.zoomToFitPadding, viewportScreenBounds.width * 0.28);
|
|
2567
2581
|
const baseZoom = this.getBaseZoom();
|
|
2568
2582
|
const zoomMin = cameraOptions.zoomSteps[0];
|
|
2569
2583
|
const zoomMax = (0, import_utils.last)(cameraOptions.zoomSteps);
|
|
@@ -3833,14 +3847,29 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3833
3847
|
const notVisibleShapes2 = this.getNotVisibleShapes();
|
|
3834
3848
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
3835
3849
|
const editingId = this.getEditingShapeId();
|
|
3836
|
-
const
|
|
3850
|
+
const nextValue = new Set(notVisibleShapes2);
|
|
3837
3851
|
if (editingId) {
|
|
3838
|
-
|
|
3852
|
+
nextValue.delete(editingId);
|
|
3839
3853
|
}
|
|
3840
3854
|
selectedShapeIds.forEach((id) => {
|
|
3841
|
-
|
|
3855
|
+
nextValue.delete(id);
|
|
3842
3856
|
});
|
|
3843
|
-
|
|
3857
|
+
const prevValue = this._culledShapesCache;
|
|
3858
|
+
if (prevValue) {
|
|
3859
|
+
if (prevValue.size !== nextValue.size) {
|
|
3860
|
+
this._culledShapesCache = nextValue;
|
|
3861
|
+
return nextValue;
|
|
3862
|
+
}
|
|
3863
|
+
for (const id of prevValue) {
|
|
3864
|
+
if (!nextValue.has(id)) {
|
|
3865
|
+
this._culledShapesCache = nextValue;
|
|
3866
|
+
return nextValue;
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3869
|
+
return prevValue;
|
|
3870
|
+
}
|
|
3871
|
+
this._culledShapesCache = nextValue;
|
|
3872
|
+
return nextValue;
|
|
3844
3873
|
}
|
|
3845
3874
|
getCurrentPageBounds() {
|
|
3846
3875
|
let commonBounds;
|
|
@@ -3890,7 +3919,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3890
3919
|
let inHollowSmallestAreaHit = null;
|
|
3891
3920
|
let inMarginClosestToEdgeDistance = Infinity;
|
|
3892
3921
|
let inMarginClosestToEdgeHit = null;
|
|
3922
|
+
const searchMargin = Math.max(innerMargin, outerMargin, this.options.hitTestMargin / zoomLevel);
|
|
3923
|
+
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, searchMargin);
|
|
3893
3924
|
const shapesToCheck = (opts.renderingOnly ? this.getCurrentPageRenderingShapesSorted() : this.getCurrentPageShapesSorted()).filter((shape) => {
|
|
3925
|
+
if (!candidateIds.has(shape.id) && !this.isShapeOfType(shape, "frame")) return false;
|
|
3894
3926
|
if (shape.isLocked && !hitLocked || this.isShapeHidden(shape) || this.isShapeOfType(shape, "group"))
|
|
3895
3927
|
return false;
|
|
3896
3928
|
const pageMask = this.getShapeMask(shape);
|
|
@@ -3997,7 +4029,33 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3997
4029
|
* @public
|
|
3998
4030
|
*/
|
|
3999
4031
|
getShapesAtPoint(point, opts = {}) {
|
|
4000
|
-
|
|
4032
|
+
const margin = opts.margin ?? 0;
|
|
4033
|
+
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, margin);
|
|
4034
|
+
return this.getCurrentPageShapesSorted().filter((shape) => {
|
|
4035
|
+
if (this.isShapeHidden(shape)) return false;
|
|
4036
|
+
if (!candidateIds.has(shape.id) && !this.isShapeOfType(shape, "frame")) return false;
|
|
4037
|
+
return this.isPointInShape(shape, point, opts);
|
|
4038
|
+
}).reverse();
|
|
4039
|
+
}
|
|
4040
|
+
/**
|
|
4041
|
+
* Get shape IDs within the given bounds.
|
|
4042
|
+
*
|
|
4043
|
+
* Note: Uses shape page bounds only. Frames with labels outside their bounds
|
|
4044
|
+
* may not be included even if the label is within the search bounds.
|
|
4045
|
+
*
|
|
4046
|
+
* Note: Results are unordered. If you need z-order, combine with sorted shapes:
|
|
4047
|
+
* ```ts
|
|
4048
|
+
* const candidates = editor.getShapeIdsInsideBounds(bounds)
|
|
4049
|
+
* const sorted = editor.getCurrentPageShapesSorted().filter(s => candidates.has(s.id))
|
|
4050
|
+
* ```
|
|
4051
|
+
*
|
|
4052
|
+
* @param bounds - The bounds to search within.
|
|
4053
|
+
* @returns Unordered set of shape IDs within the given bounds.
|
|
4054
|
+
*
|
|
4055
|
+
* @internal
|
|
4056
|
+
*/
|
|
4057
|
+
getShapeIdsInsideBounds(bounds) {
|
|
4058
|
+
return this._spatialIndex.getShapeIdsInsideBounds(bounds);
|
|
4001
4059
|
}
|
|
4002
4060
|
/**
|
|
4003
4061
|
* Test whether a point (in the current page space) will will a shape. This method takes into account masks,
|
|
@@ -5680,8 +5738,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5680
5738
|
isAspectRatioLocked: options.isAspectRatioLocked
|
|
5681
5739
|
});
|
|
5682
5740
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
5683
|
-
|
|
5684
|
-
rotation
|
|
5741
|
+
const parentRotation = this.getShapeParentTransform(id).rotation();
|
|
5742
|
+
const rotation = -options.initialShape.rotation - 2 * parentRotation;
|
|
5685
5743
|
this.updateShapes([{ id, type, rotation }]);
|
|
5686
5744
|
}
|
|
5687
5745
|
const preScaleShapePageCenter = import_Mat.Mat.applyToPoint(
|
|
@@ -5694,9 +5752,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5694
5752
|
scale,
|
|
5695
5753
|
options.scaleAxisRotation
|
|
5696
5754
|
);
|
|
5697
|
-
const pageBounds = this.getShapePageBounds(id);
|
|
5698
5755
|
const pageTransform = this.getShapePageTransform(id);
|
|
5699
|
-
const
|
|
5756
|
+
const currentLocalBounds = this.getShapeGeometry(id).bounds;
|
|
5757
|
+
const currentPageCenter = import_Mat.Mat.applyToPoint(pageTransform, currentLocalBounds.center);
|
|
5700
5758
|
const shapePageTransformOrigin = pageTransform.point();
|
|
5701
5759
|
if (!currentPageCenter || !shapePageTransformOrigin) return this;
|
|
5702
5760
|
const pageDelta = import_Vec.Vec.Sub(postScaleShapePageCenter, currentPageCenter);
|
|
@@ -5982,7 +6040,11 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5982
6040
|
)
|
|
5983
6041
|
);
|
|
5984
6042
|
const sortedShapeIds = shapesToGroup.sort(import_utils.sortByIndex).map((s) => s.id);
|
|
5985
|
-
const
|
|
6043
|
+
const childBounds = (0, import_utils.compact)(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
|
|
6044
|
+
const pageBounds = import_Box.Box.Common(childBounds);
|
|
6045
|
+
if (!pageBounds.isValid()) {
|
|
6046
|
+
throw Error(`Editor.groupShapes: group bounds are invalid (NaN).`);
|
|
6047
|
+
}
|
|
5986
6048
|
const { x, y } = pageBounds.point;
|
|
5987
6049
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
|
|
5988
6050
|
if (this.getCurrentToolId() !== "select") return this;
|
|
@@ -6935,60 +6997,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
6935
6997
|
height
|
|
6936
6998
|
};
|
|
6937
6999
|
}
|
|
6938
|
-
|
|
6939
|
-
* Update the input points from a pointer, pinch, or wheel event.
|
|
6940
|
-
*
|
|
6941
|
-
* @param info - The event info.
|
|
6942
|
-
*/
|
|
6943
|
-
_updateInputsFromEvent(info) {
|
|
6944
|
-
const {
|
|
6945
|
-
pointerVelocity,
|
|
6946
|
-
previousScreenPoint,
|
|
6947
|
-
previousPagePoint,
|
|
6948
|
-
currentScreenPoint,
|
|
6949
|
-
currentPagePoint,
|
|
6950
|
-
originScreenPoint,
|
|
6951
|
-
originPagePoint
|
|
6952
|
-
} = this.inputs;
|
|
6953
|
-
const { screenBounds } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
|
|
6954
|
-
const { x: cx, y: cy, z: cz } = (0, import_state.unsafe__withoutCapture)(() => this.getCamera());
|
|
6955
|
-
const sx = info.point.x - screenBounds.x;
|
|
6956
|
-
const sy = info.point.y - screenBounds.y;
|
|
6957
|
-
const sz = info.point.z ?? 0.5;
|
|
6958
|
-
previousScreenPoint.setTo(currentScreenPoint);
|
|
6959
|
-
previousPagePoint.setTo(currentPagePoint);
|
|
6960
|
-
currentScreenPoint.set(sx, sy);
|
|
6961
|
-
const nx = sx / cz - cx;
|
|
6962
|
-
const ny = sy / cz - cy;
|
|
6963
|
-
if (isFinite(nx) && isFinite(ny)) {
|
|
6964
|
-
currentPagePoint.set(nx, ny, sz);
|
|
6965
|
-
}
|
|
6966
|
-
this.inputs.isPen = info.type === "pointer" && info.isPen;
|
|
6967
|
-
if (info.name === "pointer_down" || this.inputs.isPinching) {
|
|
6968
|
-
pointerVelocity.set(0, 0);
|
|
6969
|
-
originScreenPoint.setTo(currentScreenPoint);
|
|
6970
|
-
originPagePoint.setTo(currentPagePoint);
|
|
6971
|
-
}
|
|
6972
|
-
this.run(
|
|
6973
|
-
() => {
|
|
6974
|
-
this.store.put([
|
|
6975
|
-
{
|
|
6976
|
-
id: import_tlschema.TLPOINTER_ID,
|
|
6977
|
-
typeName: "pointer",
|
|
6978
|
-
x: currentPagePoint.x,
|
|
6979
|
-
y: currentPagePoint.y,
|
|
6980
|
-
lastActivityTimestamp: (
|
|
6981
|
-
// If our pointer moved only because we're following some other user, then don't
|
|
6982
|
-
// update our last activity timestamp; otherwise, update it to the current timestamp.
|
|
6983
|
-
info.type === "pointer" && info.pointerId === import_constants.INTERNAL_POINTER_IDS.CAMERA_MOVE ? this.store.unsafeGetWithoutCapture(import_tlschema.TLPOINTER_ID)?.lastActivityTimestamp ?? this._tickManager.now : this._tickManager.now
|
|
6984
|
-
),
|
|
6985
|
-
meta: {}
|
|
6986
|
-
}
|
|
6987
|
-
]);
|
|
6988
|
-
},
|
|
6989
|
-
{ history: "ignore" }
|
|
6990
|
-
);
|
|
6991
|
-
}
|
|
7000
|
+
/* --------------------- Events --------------------- */
|
|
6992
7001
|
/**
|
|
6993
7002
|
* Dispatch a cancel event.
|
|
6994
7003
|
*
|
|
@@ -7053,18 +7062,19 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7053
7062
|
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7054
7063
|
// we need to convert back into true screen space first. we should fix this...
|
|
7055
7064
|
import_Vec.Vec.Add(
|
|
7056
|
-
this.inputs.
|
|
7065
|
+
this.inputs.getCurrentScreenPoint(),
|
|
7057
7066
|
this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID).screenBounds
|
|
7058
7067
|
),
|
|
7059
7068
|
pointerId: options?.pointerId ?? 0,
|
|
7060
7069
|
button: options?.button ?? 0,
|
|
7061
|
-
isPen: options?.isPen ?? this.inputs.
|
|
7062
|
-
shiftKey: options?.shiftKey ?? this.inputs.
|
|
7063
|
-
altKey: options?.altKey ?? this.inputs.
|
|
7064
|
-
ctrlKey: options?.ctrlKey ?? this.inputs.
|
|
7065
|
-
metaKey: options?.metaKey ?? this.inputs.
|
|
7066
|
-
accelKey:
|
|
7070
|
+
isPen: options?.isPen ?? this.inputs.getIsPen(),
|
|
7071
|
+
shiftKey: options?.shiftKey ?? this.inputs.getShiftKey(),
|
|
7072
|
+
altKey: options?.altKey ?? this.inputs.getAltKey(),
|
|
7073
|
+
ctrlKey: options?.ctrlKey ?? this.inputs.getCtrlKey(),
|
|
7074
|
+
metaKey: options?.metaKey ?? this.inputs.getMetaKey(),
|
|
7075
|
+
accelKey: false
|
|
7067
7076
|
};
|
|
7077
|
+
event.accelKey = options?.accelKey ?? this.inputs.getAccelKey();
|
|
7068
7078
|
if (options?.immediate) {
|
|
7069
7079
|
this._flushEventForTick(event);
|
|
7070
7080
|
} else {
|
|
@@ -7380,58 +7390,58 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7380
7390
|
this._clickManager.cancelDoubleClickTimeout();
|
|
7381
7391
|
}
|
|
7382
7392
|
_setShiftKeyTimeout() {
|
|
7383
|
-
this.inputs.
|
|
7393
|
+
this.inputs.setShiftKey(false);
|
|
7384
7394
|
this.dispatch({
|
|
7385
7395
|
type: "keyboard",
|
|
7386
7396
|
name: "key_up",
|
|
7387
7397
|
key: "Shift",
|
|
7388
|
-
shiftKey: this.inputs.
|
|
7389
|
-
ctrlKey: this.inputs.
|
|
7390
|
-
altKey: this.inputs.
|
|
7391
|
-
metaKey: this.inputs.
|
|
7392
|
-
accelKey:
|
|
7398
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7399
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7400
|
+
altKey: this.inputs.getAltKey(),
|
|
7401
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7402
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7393
7403
|
code: "ShiftLeft"
|
|
7394
7404
|
});
|
|
7395
7405
|
}
|
|
7396
7406
|
_setAltKeyTimeout() {
|
|
7397
|
-
this.inputs.
|
|
7407
|
+
this.inputs.setAltKey(false);
|
|
7398
7408
|
this.dispatch({
|
|
7399
7409
|
type: "keyboard",
|
|
7400
7410
|
name: "key_up",
|
|
7401
7411
|
key: "Alt",
|
|
7402
|
-
shiftKey: this.inputs.
|
|
7403
|
-
ctrlKey: this.inputs.
|
|
7404
|
-
altKey: this.inputs.
|
|
7405
|
-
metaKey: this.inputs.
|
|
7406
|
-
accelKey:
|
|
7412
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7413
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7414
|
+
altKey: this.inputs.getAltKey(),
|
|
7415
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7416
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7407
7417
|
code: "AltLeft"
|
|
7408
7418
|
});
|
|
7409
7419
|
}
|
|
7410
7420
|
_setCtrlKeyTimeout() {
|
|
7411
|
-
this.inputs.
|
|
7421
|
+
this.inputs.setCtrlKey(false);
|
|
7412
7422
|
this.dispatch({
|
|
7413
7423
|
type: "keyboard",
|
|
7414
7424
|
name: "key_up",
|
|
7415
7425
|
key: "Ctrl",
|
|
7416
|
-
shiftKey: this.inputs.
|
|
7417
|
-
ctrlKey: this.inputs.
|
|
7418
|
-
altKey: this.inputs.
|
|
7419
|
-
metaKey: this.inputs.
|
|
7420
|
-
accelKey:
|
|
7426
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7427
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7428
|
+
altKey: this.inputs.getAltKey(),
|
|
7429
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7430
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7421
7431
|
code: "ControlLeft"
|
|
7422
7432
|
});
|
|
7423
7433
|
}
|
|
7424
7434
|
_setMetaKeyTimeout() {
|
|
7425
|
-
this.inputs.
|
|
7435
|
+
this.inputs.setMetaKey(false);
|
|
7426
7436
|
this.dispatch({
|
|
7427
7437
|
type: "keyboard",
|
|
7428
7438
|
name: "key_up",
|
|
7429
7439
|
key: "Meta",
|
|
7430
|
-
shiftKey: this.inputs.
|
|
7431
|
-
ctrlKey: this.inputs.
|
|
7432
|
-
altKey: this.inputs.
|
|
7433
|
-
metaKey: this.inputs.
|
|
7434
|
-
accelKey:
|
|
7440
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7441
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7442
|
+
altKey: this.inputs.getAltKey(),
|
|
7443
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7444
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7435
7445
|
code: "MetaLeft"
|
|
7436
7446
|
});
|
|
7437
7447
|
}
|
|
@@ -7502,10 +7512,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7502
7512
|
const { type } = info;
|
|
7503
7513
|
if (info.type === "misc") {
|
|
7504
7514
|
if (info.name === "cancel" || info.name === "complete") {
|
|
7505
|
-
this.inputs.
|
|
7506
|
-
if (this.inputs.
|
|
7507
|
-
this.inputs.
|
|
7508
|
-
this.inputs.
|
|
7515
|
+
this.inputs.setIsDragging(false);
|
|
7516
|
+
if (this.inputs.getIsPanning()) {
|
|
7517
|
+
this.inputs.setIsPanning(false);
|
|
7518
|
+
this.inputs.setIsSpacebarPanning(false);
|
|
7509
7519
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7510
7520
|
}
|
|
7511
7521
|
}
|
|
@@ -7516,34 +7526,33 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7516
7526
|
if (info.shiftKey) {
|
|
7517
7527
|
clearTimeout(this._shiftKeyTimeout);
|
|
7518
7528
|
this._shiftKeyTimeout = -1;
|
|
7519
|
-
inputs.
|
|
7520
|
-
} else if (!info.shiftKey && inputs.
|
|
7529
|
+
inputs.setShiftKey(true);
|
|
7530
|
+
} else if (!info.shiftKey && inputs.getShiftKey() && this._shiftKeyTimeout === -1) {
|
|
7521
7531
|
this._shiftKeyTimeout = this.timers.setTimeout(this._setShiftKeyTimeout, 150);
|
|
7522
7532
|
}
|
|
7523
7533
|
if (info.altKey) {
|
|
7524
7534
|
clearTimeout(this._altKeyTimeout);
|
|
7525
7535
|
this._altKeyTimeout = -1;
|
|
7526
|
-
inputs.
|
|
7527
|
-
} else if (!info.altKey && inputs.
|
|
7536
|
+
inputs.setAltKey(true);
|
|
7537
|
+
} else if (!info.altKey && inputs.getAltKey() && this._altKeyTimeout === -1) {
|
|
7528
7538
|
this._altKeyTimeout = this.timers.setTimeout(this._setAltKeyTimeout, 150);
|
|
7529
7539
|
}
|
|
7530
7540
|
if (info.ctrlKey) {
|
|
7531
7541
|
clearTimeout(this._ctrlKeyTimeout);
|
|
7532
7542
|
this._ctrlKeyTimeout = -1;
|
|
7533
|
-
inputs.
|
|
7534
|
-
} else if (!info.ctrlKey && inputs.
|
|
7543
|
+
inputs.setCtrlKey(true);
|
|
7544
|
+
} else if (!info.ctrlKey && inputs.getCtrlKey() && this._ctrlKeyTimeout === -1) {
|
|
7535
7545
|
this._ctrlKeyTimeout = this.timers.setTimeout(this._setCtrlKeyTimeout, 150);
|
|
7536
7546
|
}
|
|
7537
7547
|
if (info.metaKey) {
|
|
7538
7548
|
clearTimeout(this._metaKeyTimeout);
|
|
7539
7549
|
this._metaKeyTimeout = -1;
|
|
7540
|
-
inputs.
|
|
7541
|
-
} else if (!info.metaKey && inputs.
|
|
7550
|
+
inputs.setMetaKey(true);
|
|
7551
|
+
} else if (!info.metaKey && inputs.getMetaKey() && this._metaKeyTimeout === -1) {
|
|
7542
7552
|
this._metaKeyTimeout = this.timers.setTimeout(this._setMetaKeyTimeout, 150);
|
|
7543
7553
|
}
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
inputs.isDragging = false;
|
|
7554
|
+
if (!inputs.getIsPointing()) {
|
|
7555
|
+
inputs.setIsDragging(false);
|
|
7547
7556
|
}
|
|
7548
7557
|
const instanceState = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
|
|
7549
7558
|
const pageState = this.store.get(this._getCurrentPageStateId());
|
|
@@ -7552,23 +7561,23 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7552
7561
|
case "pinch": {
|
|
7553
7562
|
if (cameraOptions.isLocked) return;
|
|
7554
7563
|
clearTimeout(this._longPressTimeout);
|
|
7555
|
-
this.
|
|
7564
|
+
this.inputs.updateFromEvent(info);
|
|
7556
7565
|
switch (info.name) {
|
|
7557
7566
|
case "pinch_start": {
|
|
7558
|
-
if (inputs.
|
|
7559
|
-
if (!inputs.
|
|
7560
|
-
this._pinchStart = this.getCamera().z;
|
|
7567
|
+
if (inputs.getIsPinching()) return;
|
|
7568
|
+
if (!inputs.getIsEditing()) {
|
|
7561
7569
|
if (!this._selectedShapeIdsAtPointerDown.length) {
|
|
7562
7570
|
this._selectedShapeIdsAtPointerDown = [...pageState.selectedShapeIds];
|
|
7563
7571
|
}
|
|
7564
7572
|
this._didPinch = true;
|
|
7565
|
-
inputs.
|
|
7573
|
+
inputs.setIsPinching(true);
|
|
7566
7574
|
this.interrupt();
|
|
7567
7575
|
}
|
|
7576
|
+
this.emit("event", info);
|
|
7568
7577
|
return;
|
|
7569
7578
|
}
|
|
7570
7579
|
case "pinch": {
|
|
7571
|
-
if (!inputs.
|
|
7580
|
+
if (!inputs.getIsPinching()) return;
|
|
7572
7581
|
const {
|
|
7573
7582
|
point: { z = 1 },
|
|
7574
7583
|
delta: { x: dx, y: dy }
|
|
@@ -7592,11 +7601,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7592
7601
|
),
|
|
7593
7602
|
{ immediate: true }
|
|
7594
7603
|
);
|
|
7604
|
+
this.emit("event", info);
|
|
7595
7605
|
return;
|
|
7596
7606
|
}
|
|
7597
7607
|
case "pinch_end": {
|
|
7598
|
-
if (!inputs.
|
|
7599
|
-
inputs.
|
|
7608
|
+
if (!inputs.getIsPinching()) return this;
|
|
7609
|
+
inputs.setIsPinching(false);
|
|
7600
7610
|
const { _selectedShapeIdsAtPointerDown: shapesToReselect } = this;
|
|
7601
7611
|
this.setSelectedShapes(this._selectedShapeIdsAtPointerDown);
|
|
7602
7612
|
this._selectedShapeIdsAtPointerDown = [];
|
|
@@ -7610,13 +7620,14 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7610
7620
|
});
|
|
7611
7621
|
}
|
|
7612
7622
|
}
|
|
7623
|
+
this.emit("event", info);
|
|
7613
7624
|
return;
|
|
7614
7625
|
}
|
|
7615
7626
|
}
|
|
7616
7627
|
}
|
|
7617
7628
|
case "wheel": {
|
|
7618
7629
|
if (cameraOptions.isLocked) return;
|
|
7619
|
-
this.
|
|
7630
|
+
this.inputs.updateFromEvent(info);
|
|
7620
7631
|
const { panSpeed, zoomSpeed } = cameraOptions;
|
|
7621
7632
|
let wheelBehavior = cameraOptions.wheelBehavior;
|
|
7622
7633
|
const inputMode = this.user.getUserPreferences().inputMode;
|
|
@@ -7634,7 +7645,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7634
7645
|
if (info.ctrlKey) behavior = wheelBehavior === "pan" ? "zoom" : "pan";
|
|
7635
7646
|
switch (behavior) {
|
|
7636
7647
|
case "zoom": {
|
|
7637
|
-
const { x, y } = this.inputs.
|
|
7648
|
+
const { x, y } = this.inputs.getCurrentScreenPoint();
|
|
7638
7649
|
let delta = dz;
|
|
7639
7650
|
if (wheelBehavior === "zoom") {
|
|
7640
7651
|
if (Math.abs(dy) > 10) {
|
|
@@ -7648,6 +7659,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7648
7659
|
immediate: true
|
|
7649
7660
|
});
|
|
7650
7661
|
this.maybeTrackPerformance("Zooming");
|
|
7662
|
+
this.root.handleEvent(info);
|
|
7663
|
+
this.emit("event", info);
|
|
7651
7664
|
return;
|
|
7652
7665
|
}
|
|
7653
7666
|
case "pan": {
|
|
@@ -7655,6 +7668,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7655
7668
|
immediate: true
|
|
7656
7669
|
});
|
|
7657
7670
|
this.maybeTrackPerformance("Panning");
|
|
7671
|
+
this.root.handleEvent(info);
|
|
7672
|
+
this.emit("event", info);
|
|
7658
7673
|
return;
|
|
7659
7674
|
}
|
|
7660
7675
|
}
|
|
@@ -7662,14 +7677,14 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7662
7677
|
break;
|
|
7663
7678
|
}
|
|
7664
7679
|
case "pointer": {
|
|
7665
|
-
if (inputs.
|
|
7666
|
-
this.
|
|
7680
|
+
if (inputs.getIsPinching()) return;
|
|
7681
|
+
this.inputs.updateFromEvent(info);
|
|
7667
7682
|
const { isPen } = info;
|
|
7668
7683
|
const { isPenMode } = instanceState;
|
|
7669
7684
|
switch (info.name) {
|
|
7670
7685
|
case "pointer_down": {
|
|
7671
7686
|
if (isPenMode && !isPen) return;
|
|
7672
|
-
if (!this.inputs.
|
|
7687
|
+
if (!this.inputs.getIsPanning()) {
|
|
7673
7688
|
this._longPressTimeout = this.timers.setTimeout(() => {
|
|
7674
7689
|
const vsb = this.getViewportScreenBounds();
|
|
7675
7690
|
this.dispatch({
|
|
@@ -7678,7 +7693,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7678
7693
|
// viewport bounds, and will be again when this event is handled...
|
|
7679
7694
|
// so we need to counter-adjust from the stored value so that the
|
|
7680
7695
|
// new value is set correctly.
|
|
7681
|
-
point: this.inputs.
|
|
7696
|
+
point: this.inputs.getOriginScreenPoint().clone().addXY(vsb.x, vsb.y),
|
|
7682
7697
|
name: "long_press"
|
|
7683
7698
|
});
|
|
7684
7699
|
}, this.options.longPressDurationMs);
|
|
@@ -7686,21 +7701,21 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7686
7701
|
this._selectedShapeIdsAtPointerDown = this.getSelectedShapeIds();
|
|
7687
7702
|
if (info.button === import_constants.LEFT_MOUSE_BUTTON) this.capturedPointerId = info.pointerId;
|
|
7688
7703
|
inputs.buttons.add(info.button);
|
|
7689
|
-
inputs.
|
|
7690
|
-
inputs.
|
|
7704
|
+
inputs.setIsPointing(true);
|
|
7705
|
+
inputs.setIsDragging(false);
|
|
7691
7706
|
if (!isPenMode && isPen) this.updateInstanceState({ isPenMode: true });
|
|
7692
7707
|
if (info.button === import_constants.STYLUS_ERASER_BUTTON) {
|
|
7693
7708
|
this._restoreToolId = this.getCurrentToolId();
|
|
7694
7709
|
this.complete();
|
|
7695
7710
|
this.setCurrentTool("eraser");
|
|
7696
7711
|
} else if (info.button === import_constants.MIDDLE_MOUSE_BUTTON) {
|
|
7697
|
-
if (!this.inputs.
|
|
7712
|
+
if (!this.inputs.getIsPanning()) {
|
|
7698
7713
|
this._prevCursor = this.getInstanceState().cursor.type;
|
|
7699
7714
|
}
|
|
7700
|
-
this.inputs.
|
|
7715
|
+
this.inputs.setIsPanning(true);
|
|
7701
7716
|
clearTimeout(this._longPressTimeout);
|
|
7702
7717
|
}
|
|
7703
|
-
if (this.inputs.
|
|
7718
|
+
if (this.inputs.getIsPanning()) {
|
|
7704
7719
|
this.stopCameraAnimation();
|
|
7705
7720
|
this.setCursor({ type: "grabbing", rotation: 0 });
|
|
7706
7721
|
return this;
|
|
@@ -7710,8 +7725,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7710
7725
|
case "pointer_move": {
|
|
7711
7726
|
if (!isPen && isPenMode) return;
|
|
7712
7727
|
const { x: cx, y: cy, z: cz } = (0, import_state.unsafe__withoutCapture)(() => this.getCamera());
|
|
7713
|
-
if (this.inputs.
|
|
7714
|
-
const
|
|
7728
|
+
if (this.inputs.getIsPanning() && this.inputs.getIsPointing()) {
|
|
7729
|
+
const currentScreenPoint = this.inputs.getCurrentScreenPoint();
|
|
7730
|
+
const previousScreenPoint = this.inputs.getPreviousScreenPoint();
|
|
7715
7731
|
const offset = import_Vec.Vec.Sub(currentScreenPoint, previousScreenPoint);
|
|
7716
7732
|
this.setCamera(new import_Vec.Vec(cx + offset.x / cz, cy + offset.y / cz, cz), {
|
|
7717
7733
|
immediate: true
|
|
@@ -7719,15 +7735,15 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7719
7735
|
this.maybeTrackPerformance("Panning");
|
|
7720
7736
|
return;
|
|
7721
7737
|
}
|
|
7722
|
-
if (inputs.
|
|
7723
|
-
inputs.
|
|
7738
|
+
if (inputs.getIsPointing() && !inputs.getIsDragging() && import_Vec.Vec.Dist2(inputs.getOriginPagePoint(), inputs.getCurrentPagePoint()) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {
|
|
7739
|
+
inputs.setIsDragging(true);
|
|
7724
7740
|
clearTimeout(this._longPressTimeout);
|
|
7725
7741
|
}
|
|
7726
7742
|
break;
|
|
7727
7743
|
}
|
|
7728
7744
|
case "pointer_up": {
|
|
7729
|
-
inputs.
|
|
7730
|
-
inputs.
|
|
7745
|
+
inputs.setIsDragging(false);
|
|
7746
|
+
inputs.setIsPointing(false);
|
|
7731
7747
|
clearTimeout(this._longPressTimeout);
|
|
7732
7748
|
inputs.buttons.delete(info.button);
|
|
7733
7749
|
if (instanceState.isPenMode && !isPen) return;
|
|
@@ -7735,12 +7751,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7735
7751
|
this.capturedPointerId = null;
|
|
7736
7752
|
info.button = 0;
|
|
7737
7753
|
}
|
|
7738
|
-
if (inputs.
|
|
7754
|
+
if (inputs.getIsPanning()) {
|
|
7739
7755
|
if (!inputs.keys.has("Space")) {
|
|
7740
|
-
inputs.
|
|
7741
|
-
inputs.
|
|
7756
|
+
inputs.setIsPanning(false);
|
|
7757
|
+
inputs.setIsSpacebarPanning(false);
|
|
7742
7758
|
}
|
|
7743
|
-
const slideDirection = this.inputs.
|
|
7759
|
+
const slideDirection = this.inputs.getPointerVelocity();
|
|
7744
7760
|
const slideSpeed = Math.min(2, slideDirection.len());
|
|
7745
7761
|
switch (info.button) {
|
|
7746
7762
|
case import_constants.LEFT_MOUSE_BUTTON: {
|
|
@@ -7777,51 +7793,58 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7777
7793
|
switch (info.name) {
|
|
7778
7794
|
case "key_down": {
|
|
7779
7795
|
inputs.keys.add(info.code);
|
|
7780
|
-
if (
|
|
7781
|
-
if (!
|
|
7782
|
-
this.
|
|
7783
|
-
|
|
7784
|
-
this.inputs.isPanning = true;
|
|
7785
|
-
this.inputs.isSpacebarPanning = true;
|
|
7786
|
-
clearTimeout(this._longPressTimeout);
|
|
7787
|
-
this.setCursor({ type: this.inputs.isPointing ? "grabbing" : "grab", rotation: 0 });
|
|
7788
|
-
}
|
|
7789
|
-
if (this.inputs.isSpacebarPanning) {
|
|
7790
|
-
let offset;
|
|
7791
|
-
switch (info.code) {
|
|
7792
|
-
case "ArrowUp": {
|
|
7793
|
-
offset = new import_Vec.Vec(0, -1);
|
|
7794
|
-
break;
|
|
7796
|
+
if (this.options.spacebarPanning) {
|
|
7797
|
+
if (info.code === "Space" && !info.ctrlKey) {
|
|
7798
|
+
if (!this.inputs.getIsPanning()) {
|
|
7799
|
+
this._prevCursor = instanceState.cursor.type;
|
|
7795
7800
|
}
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7801
|
+
this.inputs.setIsPanning(true);
|
|
7802
|
+
this.inputs.setIsSpacebarPanning(true);
|
|
7803
|
+
clearTimeout(this._longPressTimeout);
|
|
7804
|
+
this.setCursor({
|
|
7805
|
+
type: this.inputs.getIsPointing() ? "grabbing" : "grab",
|
|
7806
|
+
rotation: 0
|
|
7807
|
+
});
|
|
7808
|
+
}
|
|
7809
|
+
if (this.inputs.getIsSpacebarPanning()) {
|
|
7810
|
+
let offset;
|
|
7811
|
+
switch (info.code) {
|
|
7812
|
+
case "ArrowUp": {
|
|
7813
|
+
offset = new import_Vec.Vec(0, -1);
|
|
7814
|
+
break;
|
|
7815
|
+
}
|
|
7816
|
+
case "ArrowRight": {
|
|
7817
|
+
offset = new import_Vec.Vec(1, 0);
|
|
7818
|
+
break;
|
|
7819
|
+
}
|
|
7820
|
+
case "ArrowDown": {
|
|
7821
|
+
offset = new import_Vec.Vec(0, 1);
|
|
7822
|
+
break;
|
|
7823
|
+
}
|
|
7824
|
+
case "ArrowLeft": {
|
|
7825
|
+
offset = new import_Vec.Vec(-1, 0);
|
|
7826
|
+
break;
|
|
7827
|
+
}
|
|
7803
7828
|
}
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7829
|
+
if (offset) {
|
|
7830
|
+
const bounds = this.getViewportPageBounds();
|
|
7831
|
+
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
|
|
7832
|
+
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
7807
7833
|
}
|
|
7808
7834
|
}
|
|
7809
|
-
if (offset) {
|
|
7810
|
-
const bounds = this.getViewportPageBounds();
|
|
7811
|
-
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
|
|
7812
|
-
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
7813
|
-
}
|
|
7814
7835
|
}
|
|
7815
7836
|
break;
|
|
7816
7837
|
}
|
|
7817
7838
|
case "key_up": {
|
|
7818
7839
|
inputs.keys.delete(info.code);
|
|
7819
|
-
if (
|
|
7820
|
-
if (
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7840
|
+
if (this.options.spacebarPanning) {
|
|
7841
|
+
if (info.code === "Space") {
|
|
7842
|
+
if (this.inputs.buttons.has(import_constants.MIDDLE_MOUSE_BUTTON)) {
|
|
7843
|
+
} else {
|
|
7844
|
+
this.inputs.setIsPanning(false);
|
|
7845
|
+
this.inputs.setIsSpacebarPanning(false);
|
|
7846
|
+
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7847
|
+
}
|
|
7825
7848
|
}
|
|
7826
7849
|
}
|
|
7827
7850
|
break;
|
|
@@ -7874,8 +7897,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7874
7897
|
}
|
|
7875
7898
|
_init = __decoratorStart(_a);
|
|
7876
7899
|
__decorateElement(_init, 1, "getIsShapeHiddenCache", _getIsShapeHiddenCache_dec, Editor);
|
|
7877
|
-
__decorateElement(_init, 1, "
|
|
7878
|
-
__decorateElement(_init, 1, "
|
|
7900
|
+
__decorateElement(_init, 1, "canUndo", _canUndo_dec, Editor);
|
|
7901
|
+
__decorateElement(_init, 1, "canRedo", _canRedo_dec, Editor);
|
|
7879
7902
|
__decorateElement(_init, 1, "getPath", _getPath_dec, Editor);
|
|
7880
7903
|
__decorateElement(_init, 1, "getCurrentTool", _getCurrentTool_dec, Editor);
|
|
7881
7904
|
__decorateElement(_init, 1, "getCurrentToolId", _getCurrentToolId_dec, Editor);
|