@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
|
@@ -46,7 +46,7 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
|
|
|
46
46
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
47
47
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
48
48
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
49
|
-
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,
|
|
49
|
+
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;
|
|
50
50
|
import {
|
|
51
51
|
EMPTY_ARRAY,
|
|
52
52
|
atom,
|
|
@@ -64,7 +64,6 @@ import {
|
|
|
64
64
|
PageRecordType,
|
|
65
65
|
TLDOCUMENT_ID,
|
|
66
66
|
TLINSTANCE_ID,
|
|
67
|
-
TLPOINTER_ID,
|
|
68
67
|
createBindingId,
|
|
69
68
|
createShapeId,
|
|
70
69
|
getShapePropKeysByStyle,
|
|
@@ -116,8 +115,7 @@ import {
|
|
|
116
115
|
LEFT_MOUSE_BUTTON,
|
|
117
116
|
MIDDLE_MOUSE_BUTTON,
|
|
118
117
|
RIGHT_MOUSE_BUTTON,
|
|
119
|
-
STYLUS_ERASER_BUTTON
|
|
120
|
-
ZOOM_TO_FIT_PADDING
|
|
118
|
+
STYLUS_ERASER_BUTTON
|
|
121
119
|
} from "../constants.mjs";
|
|
122
120
|
import { exportToSvg } from "../exports/exportToSvg.mjs";
|
|
123
121
|
import { getSvgAsImage } from "../exports/getSvgAsImage.mjs";
|
|
@@ -140,7 +138,6 @@ import {
|
|
|
140
138
|
parseDeepLinkString
|
|
141
139
|
} from "../utils/deepLinks.mjs";
|
|
142
140
|
import { getIncrementedName } from "../utils/getIncrementedName.mjs";
|
|
143
|
-
import { isAccelKey } from "../utils/keyboard.mjs";
|
|
144
141
|
import { getReorderingShapesChanges } from "../utils/reorderShapes.mjs";
|
|
145
142
|
import { applyRotationToSnapshotShapes, getRotationSnapshot } from "../utils/rotation.mjs";
|
|
146
143
|
import { bindingsIndex } from "./derivations/bindingsIndex.mjs";
|
|
@@ -152,13 +149,15 @@ import { EdgeScrollManager } from "./managers/EdgeScrollManager/EdgeScrollManage
|
|
|
152
149
|
import { FocusManager } from "./managers/FocusManager/FocusManager.mjs";
|
|
153
150
|
import { FontManager } from "./managers/FontManager/FontManager.mjs";
|
|
154
151
|
import { HistoryManager } from "./managers/HistoryManager/HistoryManager.mjs";
|
|
152
|
+
import { InputsManager } from "./managers/InputsManager/InputsManager.mjs";
|
|
155
153
|
import { ScribbleManager } from "./managers/ScribbleManager/ScribbleManager.mjs";
|
|
156
154
|
import { SnapManager } from "./managers/SnapManager/SnapManager.mjs";
|
|
155
|
+
import { SpatialIndexManager } from "./managers/SpatialIndexManager/SpatialIndexManager.mjs";
|
|
157
156
|
import { TextManager } from "./managers/TextManager/TextManager.mjs";
|
|
158
157
|
import { TickManager } from "./managers/TickManager/TickManager.mjs";
|
|
159
158
|
import { UserPreferencesManager } from "./managers/UserPreferencesManager/UserPreferencesManager.mjs";
|
|
160
159
|
import { RootState } from "./tools/RootState.mjs";
|
|
161
|
-
class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed],
|
|
160
|
+
class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed], _canUndo_dec = [computed], _canRedo_dec = [computed], _getPath_dec = [computed], _getCurrentTool_dec = [computed], _getCurrentToolId_dec = [computed], _getDocumentSettings_dec = [computed], _getInstanceState_dec = [computed], _getPageStates_dec = [computed], __getPageStatesQuery_dec = [computed], _getCurrentPageState_dec = [computed], __getCurrentPageStateId_dec = [computed], _getSelectedShapeIds_dec = [computed], _getSelectedShapes_dec = [computed], _getCurrentPageShapesInReadingOrder_dec = [computed], _getOnlySelectedShapeId_dec = [computed], _getOnlySelectedShape_dec = [computed], _getSelectionPageBounds_dec = [computed], _getSelectionRotation_dec = [computed], _getSelectionRotatedPageBounds_dec = [computed], _getSelectionRotatedScreenBounds_dec = [computed], _getFocusedGroupId_dec = [computed], _getFocusedGroup_dec = [computed], _getEditingShapeId_dec = [computed], _getEditingShape_dec = [computed], _getRichTextEditor_dec = [computed], _getHoveredShapeId_dec = [computed], _getHoveredShape_dec = [computed], _getHintingShapeIds_dec = [computed], _getHintingShape_dec = [computed], _getErasingShapeIds_dec = [computed], _getErasingShapes_dec = [computed], __unsafe_getCameraId_dec = [computed], _getCamera_dec = [computed], _getViewportPageBoundsForFollowing_dec = [computed], _getCameraForFollowing_dec = [computed], _getZoomLevel_dec = [computed], _getDebouncedZoomLevel_dec = [computed], __getAboveDebouncedZoomThreshold_dec = [computed], _getEfficientZoomLevel_dec = [computed], _getViewportScreenBounds_dec = [computed], _getViewportScreenCenter_dec = [computed], _getViewportPageBounds_dec = [computed], __getCollaboratorsQuery_dec = [computed], _getCollaborators_dec = [computed], _getCollaboratorsOnCurrentPage_dec = [computed], _getRenderingShapes_dec = [computed], __getAllPagesQuery_dec = [computed], _getPages_dec = [computed], _getCurrentPageId_dec = [computed], _getCurrentPageShapeIdsSorted_dec = [computed], __getAllAssetsQuery_dec = [computed], __getShapeHandlesCache_dec = [computed], __getShapePageTransformCache_dec = [computed], __getShapePageBoundsCache_dec = [computed], __getShapeClipPathCache_dec = [computed], __getShapeMaskCache_dec = [computed], __getShapeMaskedPageBoundsCache_dec = [computed], _getNotVisibleShapes_dec = [computed], _getCulledShapes_dec = [computed], _getCurrentPageBounds_dec = [computed], _getCurrentPageShapes_dec = [computed], _getCurrentPageShapesSorted_dec = [computed], _getCurrentPageRenderingShapesSorted_dec = [computed], __getBindingsIndexCache_dec = [computed], __getSelectionSharedStyles_dec = [computed], _getSharedStyles_dec = [computed({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [computed], _getIsFocused_dec = [computed], _getIsReadonly_dec = [computed], __setShiftKeyTimeout_dec = [bind], __setAltKeyTimeout_dec = [bind], __setCtrlKeyTimeout_dec = [bind], __setMetaKeyTimeout_dec = [bind], _a) {
|
|
162
161
|
constructor({
|
|
163
162
|
store,
|
|
164
163
|
user,
|
|
@@ -194,7 +193,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
194
193
|
*/
|
|
195
194
|
__publicField(this, "root");
|
|
196
195
|
/**
|
|
197
|
-
* A set of functions to call when the
|
|
196
|
+
* A set of functions to call when the editor is disposed.
|
|
198
197
|
*
|
|
199
198
|
* @public
|
|
200
199
|
*/
|
|
@@ -205,14 +204,24 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
205
204
|
* @public
|
|
206
205
|
*/
|
|
207
206
|
__publicField(this, "isDisposed", false);
|
|
208
|
-
/**
|
|
207
|
+
/**
|
|
208
|
+
* A manager for the editor's tick events.
|
|
209
|
+
*
|
|
210
|
+
* @internal */
|
|
209
211
|
__publicField(this, "_tickManager");
|
|
210
212
|
/**
|
|
211
|
-
* A manager for the
|
|
213
|
+
* A manager for the editor's input state.
|
|
214
|
+
*
|
|
215
|
+
* @public
|
|
216
|
+
*/
|
|
217
|
+
__publicField(this, "inputs");
|
|
218
|
+
/**
|
|
219
|
+
* A manager for the editor's snapping feature.
|
|
212
220
|
*
|
|
213
221
|
* @public
|
|
214
222
|
*/
|
|
215
223
|
__publicField(this, "snaps");
|
|
224
|
+
__publicField(this, "_spatialIndex");
|
|
216
225
|
/**
|
|
217
226
|
* A manager for the any asynchronous events and making sure they're
|
|
218
227
|
* cleaned up upon disposal.
|
|
@@ -290,7 +299,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
290
299
|
__publicField(this, "bindingUtils");
|
|
291
300
|
/* --------------------- History -------------------- */
|
|
292
301
|
/**
|
|
293
|
-
* A manager for the
|
|
302
|
+
* A manager for the editor's history.
|
|
294
303
|
*
|
|
295
304
|
* @readonly
|
|
296
305
|
*/
|
|
@@ -329,6 +338,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
329
338
|
/* --------------------- Shapes --------------------- */
|
|
330
339
|
__publicField(this, "_shapeGeometryCaches", {});
|
|
331
340
|
__publicField(this, "_notVisibleShapes", notVisibleShapes(this));
|
|
341
|
+
__publicField(this, "_culledShapesCache", null);
|
|
332
342
|
// Parents and children
|
|
333
343
|
/**
|
|
334
344
|
* A cache of parents to children.
|
|
@@ -356,54 +366,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
356
366
|
tldraw: null,
|
|
357
367
|
excalidraw: null
|
|
358
368
|
});
|
|
359
|
-
/* --------------------- Events --------------------- */
|
|
360
|
-
/**
|
|
361
|
-
* The app's current input state.
|
|
362
|
-
*
|
|
363
|
-
* @public
|
|
364
|
-
*/
|
|
365
|
-
__publicField(this, "inputs", {
|
|
366
|
-
/** The most recent pointer down's position in the current page space. */
|
|
367
|
-
originPagePoint: new Vec(),
|
|
368
|
-
/** The most recent pointer down's position in screen space. */
|
|
369
|
-
originScreenPoint: new Vec(),
|
|
370
|
-
/** The previous pointer position in the current page space. */
|
|
371
|
-
previousPagePoint: new Vec(),
|
|
372
|
-
/** The previous pointer position in screen space. */
|
|
373
|
-
previousScreenPoint: new Vec(),
|
|
374
|
-
/** The most recent pointer position in the current page space. */
|
|
375
|
-
currentPagePoint: new Vec(),
|
|
376
|
-
/** The most recent pointer position in screen space. */
|
|
377
|
-
currentScreenPoint: new Vec(),
|
|
378
|
-
/** A set containing the currently pressed keys. */
|
|
379
|
-
keys: /* @__PURE__ */ new Set(),
|
|
380
|
-
/** A set containing the currently pressed buttons. */
|
|
381
|
-
buttons: /* @__PURE__ */ new Set(),
|
|
382
|
-
/** Whether the input is from a pe. */
|
|
383
|
-
isPen: false,
|
|
384
|
-
/** Whether the shift key is currently pressed. */
|
|
385
|
-
shiftKey: false,
|
|
386
|
-
/** Whether the meta key is currently pressed. */
|
|
387
|
-
metaKey: false,
|
|
388
|
-
/** Whether the control or command key is currently pressed. */
|
|
389
|
-
ctrlKey: false,
|
|
390
|
-
/** Whether the alt or option key is currently pressed. */
|
|
391
|
-
altKey: false,
|
|
392
|
-
/** Whether the user is dragging. */
|
|
393
|
-
isDragging: false,
|
|
394
|
-
/** Whether the user is pointing. */
|
|
395
|
-
isPointing: false,
|
|
396
|
-
/** Whether the user is pinching. */
|
|
397
|
-
isPinching: false,
|
|
398
|
-
/** Whether the user is editing. */
|
|
399
|
-
isEditing: false,
|
|
400
|
-
/** Whether the user is panning. */
|
|
401
|
-
isPanning: false,
|
|
402
|
-
/** Whether the user is spacebar panning. */
|
|
403
|
-
isSpacebarPanning: false,
|
|
404
|
-
/** Velocity of mouse pointer, in pixels per millisecond */
|
|
405
|
-
pointerVelocity: new Vec()
|
|
406
|
-
});
|
|
407
369
|
/**
|
|
408
370
|
* A manager for recording multiple click events.
|
|
409
371
|
*
|
|
@@ -427,8 +389,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
427
389
|
/** @internal */
|
|
428
390
|
__publicField(this, "_restoreToolId", "select");
|
|
429
391
|
/** @internal */
|
|
430
|
-
__publicField(this, "_pinchStart", 1);
|
|
431
|
-
/** @internal */
|
|
432
392
|
__publicField(this, "_didPinch", false);
|
|
433
393
|
/** @internal */
|
|
434
394
|
__publicField(this, "_selectedShapeIdsAtPointerDown", []);
|
|
@@ -454,6 +414,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
454
414
|
}
|
|
455
415
|
});
|
|
456
416
|
this.snaps = new SnapManager(this);
|
|
417
|
+
this._spatialIndex = new SpatialIndexManager(this);
|
|
418
|
+
this.disposables.add(() => this._spatialIndex.dispose());
|
|
457
419
|
this.disposables.add(this.timers.dispose);
|
|
458
420
|
this._cameraOptions.set({ ...DEFAULT_CAMERA_OPTIONS, ...cameraOptions });
|
|
459
421
|
this._textOptions = atom("text options", textOptions ?? null);
|
|
@@ -464,6 +426,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
464
426
|
this.disposables.add(() => this.textMeasure.dispose());
|
|
465
427
|
this.fonts = new FontManager(this, fontAssetUrls);
|
|
466
428
|
this._tickManager = new TickManager(this);
|
|
429
|
+
this.inputs = new InputsManager(this);
|
|
467
430
|
class NewRoot extends RootState {
|
|
468
431
|
static initial = initialState ?? "";
|
|
469
432
|
}
|
|
@@ -930,9 +893,12 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
930
893
|
this.history.undo();
|
|
931
894
|
return this;
|
|
932
895
|
}
|
|
933
|
-
|
|
896
|
+
canUndo() {
|
|
934
897
|
return this.history.getNumUndos() > 0;
|
|
935
898
|
}
|
|
899
|
+
getCanUndo() {
|
|
900
|
+
return this.canUndo();
|
|
901
|
+
}
|
|
936
902
|
/**
|
|
937
903
|
* Redo to the next mark.
|
|
938
904
|
*
|
|
@@ -949,13 +915,16 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
949
915
|
this.history.redo();
|
|
950
916
|
return this;
|
|
951
917
|
}
|
|
918
|
+
canRedo() {
|
|
919
|
+
return this.history.getNumRedos() > 0;
|
|
920
|
+
}
|
|
921
|
+
getCanRedo() {
|
|
922
|
+
return this.canRedo();
|
|
923
|
+
}
|
|
952
924
|
clearHistory() {
|
|
953
925
|
this.history.clear();
|
|
954
926
|
return this;
|
|
955
927
|
}
|
|
956
|
-
getCanRedo() {
|
|
957
|
-
return this.history.getNumRedos() > 0;
|
|
958
|
-
}
|
|
959
928
|
/**
|
|
960
929
|
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
961
930
|
* any redos. You typically want to do this just before a user interaction begins or is handled.
|
|
@@ -1110,7 +1079,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1110
1079
|
}),
|
|
1111
1080
|
selectionCount: this.getSelectedShapes().length,
|
|
1112
1081
|
editingShape: editingShapeId ? this.getShape(editingShapeId) : void 0,
|
|
1113
|
-
inputs: this.inputs,
|
|
1082
|
+
inputs: this.inputs.toJson(),
|
|
1114
1083
|
pageState: this.getCurrentPageState(),
|
|
1115
1084
|
instanceState: this.getInstanceState(),
|
|
1116
1085
|
collaboratorCount: this.getCollaboratorsOnCurrentPage().length
|
|
@@ -1131,7 +1100,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1131
1100
|
* we're in a transaction that's about to be rolled back due to the same error we're currently
|
|
1132
1101
|
* reporting.
|
|
1133
1102
|
*
|
|
1134
|
-
* Instead, to listen to changes to this value, you need to listen to
|
|
1103
|
+
* Instead, to listen to changes to this value, you need to listen to editor's `crash` event.
|
|
1135
1104
|
*
|
|
1136
1105
|
* @internal
|
|
1137
1106
|
*/
|
|
@@ -1782,6 +1751,28 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1782
1751
|
const editingShapeId = this.getEditingShapeId();
|
|
1783
1752
|
return editingShapeId ? this.getShape(editingShapeId) : void 0;
|
|
1784
1753
|
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Whether the shape can be edited.
|
|
1756
|
+
*
|
|
1757
|
+
* @param shape - The shape (or shape id) to check if it can be edited.
|
|
1758
|
+
* @param info - The info about the edit start.
|
|
1759
|
+
*
|
|
1760
|
+
* @public
|
|
1761
|
+
* @returns true if the shape can be edited, false otherwise.
|
|
1762
|
+
*/
|
|
1763
|
+
canEditShape(shape, info) {
|
|
1764
|
+
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1765
|
+
if (!id) return false;
|
|
1766
|
+
if (id === this.getEditingShapeId()) return false;
|
|
1767
|
+
const _shape = this.getShape(id);
|
|
1768
|
+
if (!_shape) return false;
|
|
1769
|
+
const util = this.getShapeUtil(_shape);
|
|
1770
|
+
const _info = info ?? { type: "unknown" };
|
|
1771
|
+
if (!util.canEdit(_shape, _info)) return false;
|
|
1772
|
+
if (this.getIsReadonly() && !util.canEditInReadonly(_shape)) return false;
|
|
1773
|
+
if (this.isShapeOrAncestorLocked(_shape) && !util.canEditWhileLocked(_shape)) return false;
|
|
1774
|
+
return true;
|
|
1775
|
+
}
|
|
1785
1776
|
/**
|
|
1786
1777
|
* Set the current editing shape.
|
|
1787
1778
|
*
|
|
@@ -1797,42 +1788,42 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1797
1788
|
*/
|
|
1798
1789
|
setEditingShape(shape) {
|
|
1799
1790
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1800
|
-
|
|
1801
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
1802
|
-
if (id !== prevEditingShapeId) {
|
|
1803
|
-
if (id) {
|
|
1804
|
-
const shape2 = this.getShape(id);
|
|
1805
|
-
if (shape2 && this.getShapeUtil(shape2).canEdit(shape2)) {
|
|
1806
|
-
this.run(
|
|
1807
|
-
() => {
|
|
1808
|
-
this._updateCurrentPageState({ editingShapeId: id });
|
|
1809
|
-
if (prevEditingShapeId) {
|
|
1810
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1811
|
-
if (prevEditingShape) {
|
|
1812
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
this.getShapeUtil(shape2).onEditStart?.(shape2);
|
|
1816
|
-
},
|
|
1817
|
-
{ history: "ignore" }
|
|
1818
|
-
);
|
|
1819
|
-
return this;
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1791
|
+
if (!id) {
|
|
1822
1792
|
this.run(
|
|
1823
1793
|
() => {
|
|
1824
|
-
this.
|
|
1825
|
-
this._currentRichTextEditor.set(null);
|
|
1794
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
1826
1795
|
if (prevEditingShapeId) {
|
|
1827
1796
|
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1828
1797
|
if (prevEditingShape) {
|
|
1829
1798
|
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1830
1799
|
}
|
|
1831
1800
|
}
|
|
1801
|
+
this._updateCurrentPageState({ editingShapeId: null });
|
|
1802
|
+
this._currentRichTextEditor.set(null);
|
|
1832
1803
|
},
|
|
1833
1804
|
{ history: "ignore" }
|
|
1834
1805
|
);
|
|
1806
|
+
return this;
|
|
1835
1807
|
}
|
|
1808
|
+
if (!this.canEditShape(id)) return this;
|
|
1809
|
+
this.run(
|
|
1810
|
+
() => {
|
|
1811
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
1812
|
+
if (prevEditingShapeId) {
|
|
1813
|
+
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1814
|
+
if (prevEditingShape) {
|
|
1815
|
+
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
this._updateCurrentPageState({ editingShapeId: null });
|
|
1819
|
+
this._currentRichTextEditor.set(null);
|
|
1820
|
+
this.select(id);
|
|
1821
|
+
this._updateCurrentPageState({ editingShapeId: id });
|
|
1822
|
+
const nextEditingShape = this.getShape(id);
|
|
1823
|
+
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
1824
|
+
},
|
|
1825
|
+
{ history: "ignore" }
|
|
1826
|
+
);
|
|
1836
1827
|
return this;
|
|
1837
1828
|
}
|
|
1838
1829
|
getRichTextEditor() {
|
|
@@ -1965,6 +1956,25 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1965
1956
|
getCroppingShapeId() {
|
|
1966
1957
|
return this.getCurrentPageState().croppingShapeId;
|
|
1967
1958
|
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Whether the shape can be cropped.
|
|
1961
|
+
*
|
|
1962
|
+
* @param shape - The shape (or shape id) to check if it can be cropped.
|
|
1963
|
+
*
|
|
1964
|
+
* @public
|
|
1965
|
+
* @returns true if the shape can be cropped, false otherwise.
|
|
1966
|
+
*/
|
|
1967
|
+
canCropShape(shape) {
|
|
1968
|
+
if (!shape) return false;
|
|
1969
|
+
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1970
|
+
if (!id) return false;
|
|
1971
|
+
const _shape = this.getShape(id);
|
|
1972
|
+
if (!_shape) return false;
|
|
1973
|
+
const util = this.getShapeUtil(_shape);
|
|
1974
|
+
if (!util.canCrop(_shape)) return false;
|
|
1975
|
+
if (this.isShapeOrAncestorLocked(_shape)) return false;
|
|
1976
|
+
return true;
|
|
1977
|
+
}
|
|
1968
1978
|
/**
|
|
1969
1979
|
* Set the current cropping shape.
|
|
1970
1980
|
*
|
|
@@ -1986,12 +1996,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1986
1996
|
() => {
|
|
1987
1997
|
if (!id) {
|
|
1988
1998
|
this.updateCurrentPageState({ croppingShapeId: null });
|
|
1989
|
-
} else {
|
|
1990
|
-
|
|
1991
|
-
const util = this.getShapeUtil(shape2);
|
|
1992
|
-
if (shape2 && util.canCrop(shape2)) {
|
|
1993
|
-
this.updateCurrentPageState({ croppingShapeId: id });
|
|
1994
|
-
}
|
|
1999
|
+
} else if (this.canCropShape(id)) {
|
|
2000
|
+
this.updateCurrentPageState({ croppingShapeId: id });
|
|
1995
2001
|
}
|
|
1996
2002
|
},
|
|
1997
2003
|
{ history: "ignore" }
|
|
@@ -2327,7 +2333,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2327
2333
|
},
|
|
2328
2334
|
{ history: "ignore" }
|
|
2329
2335
|
);
|
|
2330
|
-
const
|
|
2336
|
+
const currentScreenPoint = this.inputs.getCurrentScreenPoint();
|
|
2337
|
+
const currentPagePoint = this.inputs.getCurrentPagePoint();
|
|
2331
2338
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2332
2339
|
this.updatePointer({
|
|
2333
2340
|
immediate: opts?.immediate,
|
|
@@ -2462,7 +2469,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2462
2469
|
* ```ts
|
|
2463
2470
|
* editor.zoomIn()
|
|
2464
2471
|
* editor.zoomIn(editor.getViewportScreenCenter(), { animation: { duration: 200 } })
|
|
2465
|
-
* editor.zoomIn(editor.inputs.
|
|
2472
|
+
* editor.zoomIn(editor.inputs.getCurrentScreenPoint(), { animation: { duration: 200 } })
|
|
2466
2473
|
* ```
|
|
2467
2474
|
*
|
|
2468
2475
|
* @param point - The screen point to zoom in on. Defaults to the screen center
|
|
@@ -2503,7 +2510,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2503
2510
|
* ```ts
|
|
2504
2511
|
* editor.zoomOut()
|
|
2505
2512
|
* editor.zoomOut(editor.getViewportScreenCenter(), { animation: { duration: 120 } })
|
|
2506
|
-
* editor.zoomOut(editor.inputs.
|
|
2513
|
+
* editor.zoomOut(editor.inputs.getCurrentScreenPoint(), { animation: { duration: 120 } })
|
|
2507
2514
|
* ```
|
|
2508
2515
|
*
|
|
2509
2516
|
* @param point - The point to zoom out on. Defaults to the viewport screen center.
|
|
@@ -2555,10 +2562,15 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2555
2562
|
if (isLocked && !opts?.force) return this;
|
|
2556
2563
|
const selectionPageBounds = this.getSelectionPageBounds();
|
|
2557
2564
|
if (selectionPageBounds) {
|
|
2558
|
-
this.
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
}
|
|
2565
|
+
const currentZoom = this.getZoomLevel();
|
|
2566
|
+
if (Math.abs(currentZoom - 1) < 0.01) {
|
|
2567
|
+
this.zoomToBounds(selectionPageBounds, opts);
|
|
2568
|
+
} else {
|
|
2569
|
+
this.zoomToBounds(selectionPageBounds, {
|
|
2570
|
+
targetZoom: 1,
|
|
2571
|
+
...opts
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2562
2574
|
}
|
|
2563
2575
|
return this;
|
|
2564
2576
|
}
|
|
@@ -2598,7 +2610,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2598
2610
|
const cameraOptions = this._cameraOptions.__unsafe__getWithoutCapture();
|
|
2599
2611
|
if (cameraOptions.isLocked && !opts?.force) return this;
|
|
2600
2612
|
const viewportScreenBounds = this.getViewportScreenBounds();
|
|
2601
|
-
const inset = opts?.inset ?? Math.min(
|
|
2613
|
+
const inset = opts?.inset ?? Math.min(this.options.zoomToFitPadding, viewportScreenBounds.width * 0.28);
|
|
2602
2614
|
const baseZoom = this.getBaseZoom();
|
|
2603
2615
|
const zoomMin = cameraOptions.zoomSteps[0];
|
|
2604
2616
|
const zoomMax = last(cameraOptions.zoomSteps);
|
|
@@ -3868,14 +3880,29 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3868
3880
|
const notVisibleShapes2 = this.getNotVisibleShapes();
|
|
3869
3881
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
3870
3882
|
const editingId = this.getEditingShapeId();
|
|
3871
|
-
const
|
|
3883
|
+
const nextValue = new Set(notVisibleShapes2);
|
|
3872
3884
|
if (editingId) {
|
|
3873
|
-
|
|
3885
|
+
nextValue.delete(editingId);
|
|
3874
3886
|
}
|
|
3875
3887
|
selectedShapeIds.forEach((id) => {
|
|
3876
|
-
|
|
3888
|
+
nextValue.delete(id);
|
|
3877
3889
|
});
|
|
3878
|
-
|
|
3890
|
+
const prevValue = this._culledShapesCache;
|
|
3891
|
+
if (prevValue) {
|
|
3892
|
+
if (prevValue.size !== nextValue.size) {
|
|
3893
|
+
this._culledShapesCache = nextValue;
|
|
3894
|
+
return nextValue;
|
|
3895
|
+
}
|
|
3896
|
+
for (const id of prevValue) {
|
|
3897
|
+
if (!nextValue.has(id)) {
|
|
3898
|
+
this._culledShapesCache = nextValue;
|
|
3899
|
+
return nextValue;
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
return prevValue;
|
|
3903
|
+
}
|
|
3904
|
+
this._culledShapesCache = nextValue;
|
|
3905
|
+
return nextValue;
|
|
3879
3906
|
}
|
|
3880
3907
|
getCurrentPageBounds() {
|
|
3881
3908
|
let commonBounds;
|
|
@@ -3925,7 +3952,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3925
3952
|
let inHollowSmallestAreaHit = null;
|
|
3926
3953
|
let inMarginClosestToEdgeDistance = Infinity;
|
|
3927
3954
|
let inMarginClosestToEdgeHit = null;
|
|
3955
|
+
const searchMargin = Math.max(innerMargin, outerMargin, this.options.hitTestMargin / zoomLevel);
|
|
3956
|
+
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, searchMargin);
|
|
3928
3957
|
const shapesToCheck = (opts.renderingOnly ? this.getCurrentPageRenderingShapesSorted() : this.getCurrentPageShapesSorted()).filter((shape) => {
|
|
3958
|
+
if (!candidateIds.has(shape.id) && !this.isShapeOfType(shape, "frame")) return false;
|
|
3929
3959
|
if (shape.isLocked && !hitLocked || this.isShapeHidden(shape) || this.isShapeOfType(shape, "group"))
|
|
3930
3960
|
return false;
|
|
3931
3961
|
const pageMask = this.getShapeMask(shape);
|
|
@@ -4032,7 +4062,33 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4032
4062
|
* @public
|
|
4033
4063
|
*/
|
|
4034
4064
|
getShapesAtPoint(point, opts = {}) {
|
|
4035
|
-
|
|
4065
|
+
const margin = opts.margin ?? 0;
|
|
4066
|
+
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, margin);
|
|
4067
|
+
return this.getCurrentPageShapesSorted().filter((shape) => {
|
|
4068
|
+
if (this.isShapeHidden(shape)) return false;
|
|
4069
|
+
if (!candidateIds.has(shape.id) && !this.isShapeOfType(shape, "frame")) return false;
|
|
4070
|
+
return this.isPointInShape(shape, point, opts);
|
|
4071
|
+
}).reverse();
|
|
4072
|
+
}
|
|
4073
|
+
/**
|
|
4074
|
+
* Get shape IDs within the given bounds.
|
|
4075
|
+
*
|
|
4076
|
+
* Note: Uses shape page bounds only. Frames with labels outside their bounds
|
|
4077
|
+
* may not be included even if the label is within the search bounds.
|
|
4078
|
+
*
|
|
4079
|
+
* Note: Results are unordered. If you need z-order, combine with sorted shapes:
|
|
4080
|
+
* ```ts
|
|
4081
|
+
* const candidates = editor.getShapeIdsInsideBounds(bounds)
|
|
4082
|
+
* const sorted = editor.getCurrentPageShapesSorted().filter(s => candidates.has(s.id))
|
|
4083
|
+
* ```
|
|
4084
|
+
*
|
|
4085
|
+
* @param bounds - The bounds to search within.
|
|
4086
|
+
* @returns Unordered set of shape IDs within the given bounds.
|
|
4087
|
+
*
|
|
4088
|
+
* @internal
|
|
4089
|
+
*/
|
|
4090
|
+
getShapeIdsInsideBounds(bounds) {
|
|
4091
|
+
return this._spatialIndex.getShapeIdsInsideBounds(bounds);
|
|
4036
4092
|
}
|
|
4037
4093
|
/**
|
|
4038
4094
|
* Test whether a point (in the current page space) will will a shape. This method takes into account masks,
|
|
@@ -5715,8 +5771,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5715
5771
|
isAspectRatioLocked: options.isAspectRatioLocked
|
|
5716
5772
|
});
|
|
5717
5773
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
5718
|
-
|
|
5719
|
-
rotation
|
|
5774
|
+
const parentRotation = this.getShapeParentTransform(id).rotation();
|
|
5775
|
+
const rotation = -options.initialShape.rotation - 2 * parentRotation;
|
|
5720
5776
|
this.updateShapes([{ id, type, rotation }]);
|
|
5721
5777
|
}
|
|
5722
5778
|
const preScaleShapePageCenter = Mat.applyToPoint(
|
|
@@ -5729,9 +5785,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5729
5785
|
scale,
|
|
5730
5786
|
options.scaleAxisRotation
|
|
5731
5787
|
);
|
|
5732
|
-
const pageBounds = this.getShapePageBounds(id);
|
|
5733
5788
|
const pageTransform = this.getShapePageTransform(id);
|
|
5734
|
-
const
|
|
5789
|
+
const currentLocalBounds = this.getShapeGeometry(id).bounds;
|
|
5790
|
+
const currentPageCenter = Mat.applyToPoint(pageTransform, currentLocalBounds.center);
|
|
5735
5791
|
const shapePageTransformOrigin = pageTransform.point();
|
|
5736
5792
|
if (!currentPageCenter || !shapePageTransformOrigin) return this;
|
|
5737
5793
|
const pageDelta = Vec.Sub(postScaleShapePageCenter, currentPageCenter);
|
|
@@ -6017,7 +6073,11 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6017
6073
|
)
|
|
6018
6074
|
);
|
|
6019
6075
|
const sortedShapeIds = shapesToGroup.sort(sortByIndex).map((s) => s.id);
|
|
6020
|
-
const
|
|
6076
|
+
const childBounds = compact(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
|
|
6077
|
+
const pageBounds = Box.Common(childBounds);
|
|
6078
|
+
if (!pageBounds.isValid()) {
|
|
6079
|
+
throw Error(`Editor.groupShapes: group bounds are invalid (NaN).`);
|
|
6080
|
+
}
|
|
6021
6081
|
const { x, y } = pageBounds.point;
|
|
6022
6082
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
|
|
6023
6083
|
if (this.getCurrentToolId() !== "select") return this;
|
|
@@ -6970,60 +7030,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6970
7030
|
height
|
|
6971
7031
|
};
|
|
6972
7032
|
}
|
|
6973
|
-
|
|
6974
|
-
* Update the input points from a pointer, pinch, or wheel event.
|
|
6975
|
-
*
|
|
6976
|
-
* @param info - The event info.
|
|
6977
|
-
*/
|
|
6978
|
-
_updateInputsFromEvent(info) {
|
|
6979
|
-
const {
|
|
6980
|
-
pointerVelocity,
|
|
6981
|
-
previousScreenPoint,
|
|
6982
|
-
previousPagePoint,
|
|
6983
|
-
currentScreenPoint,
|
|
6984
|
-
currentPagePoint,
|
|
6985
|
-
originScreenPoint,
|
|
6986
|
-
originPagePoint
|
|
6987
|
-
} = this.inputs;
|
|
6988
|
-
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
6989
|
-
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
|
|
6990
|
-
const sx = info.point.x - screenBounds.x;
|
|
6991
|
-
const sy = info.point.y - screenBounds.y;
|
|
6992
|
-
const sz = info.point.z ?? 0.5;
|
|
6993
|
-
previousScreenPoint.setTo(currentScreenPoint);
|
|
6994
|
-
previousPagePoint.setTo(currentPagePoint);
|
|
6995
|
-
currentScreenPoint.set(sx, sy);
|
|
6996
|
-
const nx = sx / cz - cx;
|
|
6997
|
-
const ny = sy / cz - cy;
|
|
6998
|
-
if (isFinite(nx) && isFinite(ny)) {
|
|
6999
|
-
currentPagePoint.set(nx, ny, sz);
|
|
7000
|
-
}
|
|
7001
|
-
this.inputs.isPen = info.type === "pointer" && info.isPen;
|
|
7002
|
-
if (info.name === "pointer_down" || this.inputs.isPinching) {
|
|
7003
|
-
pointerVelocity.set(0, 0);
|
|
7004
|
-
originScreenPoint.setTo(currentScreenPoint);
|
|
7005
|
-
originPagePoint.setTo(currentPagePoint);
|
|
7006
|
-
}
|
|
7007
|
-
this.run(
|
|
7008
|
-
() => {
|
|
7009
|
-
this.store.put([
|
|
7010
|
-
{
|
|
7011
|
-
id: TLPOINTER_ID,
|
|
7012
|
-
typeName: "pointer",
|
|
7013
|
-
x: currentPagePoint.x,
|
|
7014
|
-
y: currentPagePoint.y,
|
|
7015
|
-
lastActivityTimestamp: (
|
|
7016
|
-
// If our pointer moved only because we're following some other user, then don't
|
|
7017
|
-
// update our last activity timestamp; otherwise, update it to the current timestamp.
|
|
7018
|
-
(info.type === "pointer" && info.pointerId === INTERNAL_POINTER_IDS.CAMERA_MOVE ? this.store.unsafeGetWithoutCapture(TLPOINTER_ID)?.lastActivityTimestamp ?? this._tickManager.now : this._tickManager.now)
|
|
7019
|
-
),
|
|
7020
|
-
meta: {}
|
|
7021
|
-
}
|
|
7022
|
-
]);
|
|
7023
|
-
},
|
|
7024
|
-
{ history: "ignore" }
|
|
7025
|
-
);
|
|
7026
|
-
}
|
|
7033
|
+
/* --------------------- Events --------------------- */
|
|
7027
7034
|
/**
|
|
7028
7035
|
* Dispatch a cancel event.
|
|
7029
7036
|
*
|
|
@@ -7088,18 +7095,19 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7088
7095
|
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7089
7096
|
// we need to convert back into true screen space first. we should fix this...
|
|
7090
7097
|
Vec.Add(
|
|
7091
|
-
this.inputs.
|
|
7098
|
+
this.inputs.getCurrentScreenPoint(),
|
|
7092
7099
|
this.store.unsafeGetWithoutCapture(TLINSTANCE_ID).screenBounds
|
|
7093
7100
|
),
|
|
7094
7101
|
pointerId: options?.pointerId ?? 0,
|
|
7095
7102
|
button: options?.button ?? 0,
|
|
7096
|
-
isPen: options?.isPen ?? this.inputs.
|
|
7097
|
-
shiftKey: options?.shiftKey ?? this.inputs.
|
|
7098
|
-
altKey: options?.altKey ?? this.inputs.
|
|
7099
|
-
ctrlKey: options?.ctrlKey ?? this.inputs.
|
|
7100
|
-
metaKey: options?.metaKey ?? this.inputs.
|
|
7101
|
-
accelKey:
|
|
7103
|
+
isPen: options?.isPen ?? this.inputs.getIsPen(),
|
|
7104
|
+
shiftKey: options?.shiftKey ?? this.inputs.getShiftKey(),
|
|
7105
|
+
altKey: options?.altKey ?? this.inputs.getAltKey(),
|
|
7106
|
+
ctrlKey: options?.ctrlKey ?? this.inputs.getCtrlKey(),
|
|
7107
|
+
metaKey: options?.metaKey ?? this.inputs.getMetaKey(),
|
|
7108
|
+
accelKey: false
|
|
7102
7109
|
};
|
|
7110
|
+
event.accelKey = options?.accelKey ?? this.inputs.getAccelKey();
|
|
7103
7111
|
if (options?.immediate) {
|
|
7104
7112
|
this._flushEventForTick(event);
|
|
7105
7113
|
} else {
|
|
@@ -7415,58 +7423,58 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7415
7423
|
this._clickManager.cancelDoubleClickTimeout();
|
|
7416
7424
|
}
|
|
7417
7425
|
_setShiftKeyTimeout() {
|
|
7418
|
-
this.inputs.
|
|
7426
|
+
this.inputs.setShiftKey(false);
|
|
7419
7427
|
this.dispatch({
|
|
7420
7428
|
type: "keyboard",
|
|
7421
7429
|
name: "key_up",
|
|
7422
7430
|
key: "Shift",
|
|
7423
|
-
shiftKey: this.inputs.
|
|
7424
|
-
ctrlKey: this.inputs.
|
|
7425
|
-
altKey: this.inputs.
|
|
7426
|
-
metaKey: this.inputs.
|
|
7427
|
-
accelKey:
|
|
7431
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7432
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7433
|
+
altKey: this.inputs.getAltKey(),
|
|
7434
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7435
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7428
7436
|
code: "ShiftLeft"
|
|
7429
7437
|
});
|
|
7430
7438
|
}
|
|
7431
7439
|
_setAltKeyTimeout() {
|
|
7432
|
-
this.inputs.
|
|
7440
|
+
this.inputs.setAltKey(false);
|
|
7433
7441
|
this.dispatch({
|
|
7434
7442
|
type: "keyboard",
|
|
7435
7443
|
name: "key_up",
|
|
7436
7444
|
key: "Alt",
|
|
7437
|
-
shiftKey: this.inputs.
|
|
7438
|
-
ctrlKey: this.inputs.
|
|
7439
|
-
altKey: this.inputs.
|
|
7440
|
-
metaKey: this.inputs.
|
|
7441
|
-
accelKey:
|
|
7445
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7446
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7447
|
+
altKey: this.inputs.getAltKey(),
|
|
7448
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7449
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7442
7450
|
code: "AltLeft"
|
|
7443
7451
|
});
|
|
7444
7452
|
}
|
|
7445
7453
|
_setCtrlKeyTimeout() {
|
|
7446
|
-
this.inputs.
|
|
7454
|
+
this.inputs.setCtrlKey(false);
|
|
7447
7455
|
this.dispatch({
|
|
7448
7456
|
type: "keyboard",
|
|
7449
7457
|
name: "key_up",
|
|
7450
7458
|
key: "Ctrl",
|
|
7451
|
-
shiftKey: this.inputs.
|
|
7452
|
-
ctrlKey: this.inputs.
|
|
7453
|
-
altKey: this.inputs.
|
|
7454
|
-
metaKey: this.inputs.
|
|
7455
|
-
accelKey:
|
|
7459
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7460
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7461
|
+
altKey: this.inputs.getAltKey(),
|
|
7462
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7463
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7456
7464
|
code: "ControlLeft"
|
|
7457
7465
|
});
|
|
7458
7466
|
}
|
|
7459
7467
|
_setMetaKeyTimeout() {
|
|
7460
|
-
this.inputs.
|
|
7468
|
+
this.inputs.setMetaKey(false);
|
|
7461
7469
|
this.dispatch({
|
|
7462
7470
|
type: "keyboard",
|
|
7463
7471
|
name: "key_up",
|
|
7464
7472
|
key: "Meta",
|
|
7465
|
-
shiftKey: this.inputs.
|
|
7466
|
-
ctrlKey: this.inputs.
|
|
7467
|
-
altKey: this.inputs.
|
|
7468
|
-
metaKey: this.inputs.
|
|
7469
|
-
accelKey:
|
|
7473
|
+
shiftKey: this.inputs.getShiftKey(),
|
|
7474
|
+
ctrlKey: this.inputs.getCtrlKey(),
|
|
7475
|
+
altKey: this.inputs.getAltKey(),
|
|
7476
|
+
metaKey: this.inputs.getMetaKey(),
|
|
7477
|
+
accelKey: this.inputs.getAccelKey(),
|
|
7470
7478
|
code: "MetaLeft"
|
|
7471
7479
|
});
|
|
7472
7480
|
}
|
|
@@ -7537,10 +7545,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7537
7545
|
const { type } = info;
|
|
7538
7546
|
if (info.type === "misc") {
|
|
7539
7547
|
if (info.name === "cancel" || info.name === "complete") {
|
|
7540
|
-
this.inputs.
|
|
7541
|
-
if (this.inputs.
|
|
7542
|
-
this.inputs.
|
|
7543
|
-
this.inputs.
|
|
7548
|
+
this.inputs.setIsDragging(false);
|
|
7549
|
+
if (this.inputs.getIsPanning()) {
|
|
7550
|
+
this.inputs.setIsPanning(false);
|
|
7551
|
+
this.inputs.setIsSpacebarPanning(false);
|
|
7544
7552
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7545
7553
|
}
|
|
7546
7554
|
}
|
|
@@ -7551,34 +7559,33 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7551
7559
|
if (info.shiftKey) {
|
|
7552
7560
|
clearTimeout(this._shiftKeyTimeout);
|
|
7553
7561
|
this._shiftKeyTimeout = -1;
|
|
7554
|
-
inputs.
|
|
7555
|
-
} else if (!info.shiftKey && inputs.
|
|
7562
|
+
inputs.setShiftKey(true);
|
|
7563
|
+
} else if (!info.shiftKey && inputs.getShiftKey() && this._shiftKeyTimeout === -1) {
|
|
7556
7564
|
this._shiftKeyTimeout = this.timers.setTimeout(this._setShiftKeyTimeout, 150);
|
|
7557
7565
|
}
|
|
7558
7566
|
if (info.altKey) {
|
|
7559
7567
|
clearTimeout(this._altKeyTimeout);
|
|
7560
7568
|
this._altKeyTimeout = -1;
|
|
7561
|
-
inputs.
|
|
7562
|
-
} else if (!info.altKey && inputs.
|
|
7569
|
+
inputs.setAltKey(true);
|
|
7570
|
+
} else if (!info.altKey && inputs.getAltKey() && this._altKeyTimeout === -1) {
|
|
7563
7571
|
this._altKeyTimeout = this.timers.setTimeout(this._setAltKeyTimeout, 150);
|
|
7564
7572
|
}
|
|
7565
7573
|
if (info.ctrlKey) {
|
|
7566
7574
|
clearTimeout(this._ctrlKeyTimeout);
|
|
7567
7575
|
this._ctrlKeyTimeout = -1;
|
|
7568
|
-
inputs.
|
|
7569
|
-
} else if (!info.ctrlKey && inputs.
|
|
7576
|
+
inputs.setCtrlKey(true);
|
|
7577
|
+
} else if (!info.ctrlKey && inputs.getCtrlKey() && this._ctrlKeyTimeout === -1) {
|
|
7570
7578
|
this._ctrlKeyTimeout = this.timers.setTimeout(this._setCtrlKeyTimeout, 150);
|
|
7571
7579
|
}
|
|
7572
7580
|
if (info.metaKey) {
|
|
7573
7581
|
clearTimeout(this._metaKeyTimeout);
|
|
7574
7582
|
this._metaKeyTimeout = -1;
|
|
7575
|
-
inputs.
|
|
7576
|
-
} else if (!info.metaKey && inputs.
|
|
7583
|
+
inputs.setMetaKey(true);
|
|
7584
|
+
} else if (!info.metaKey && inputs.getMetaKey() && this._metaKeyTimeout === -1) {
|
|
7577
7585
|
this._metaKeyTimeout = this.timers.setTimeout(this._setMetaKeyTimeout, 150);
|
|
7578
7586
|
}
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
inputs.isDragging = false;
|
|
7587
|
+
if (!inputs.getIsPointing()) {
|
|
7588
|
+
inputs.setIsDragging(false);
|
|
7582
7589
|
}
|
|
7583
7590
|
const instanceState = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
7584
7591
|
const pageState = this.store.get(this._getCurrentPageStateId());
|
|
@@ -7587,23 +7594,23 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7587
7594
|
case "pinch": {
|
|
7588
7595
|
if (cameraOptions.isLocked) return;
|
|
7589
7596
|
clearTimeout(this._longPressTimeout);
|
|
7590
|
-
this.
|
|
7597
|
+
this.inputs.updateFromEvent(info);
|
|
7591
7598
|
switch (info.name) {
|
|
7592
7599
|
case "pinch_start": {
|
|
7593
|
-
if (inputs.
|
|
7594
|
-
if (!inputs.
|
|
7595
|
-
this._pinchStart = this.getCamera().z;
|
|
7600
|
+
if (inputs.getIsPinching()) return;
|
|
7601
|
+
if (!inputs.getIsEditing()) {
|
|
7596
7602
|
if (!this._selectedShapeIdsAtPointerDown.length) {
|
|
7597
7603
|
this._selectedShapeIdsAtPointerDown = [...pageState.selectedShapeIds];
|
|
7598
7604
|
}
|
|
7599
7605
|
this._didPinch = true;
|
|
7600
|
-
inputs.
|
|
7606
|
+
inputs.setIsPinching(true);
|
|
7601
7607
|
this.interrupt();
|
|
7602
7608
|
}
|
|
7609
|
+
this.emit("event", info);
|
|
7603
7610
|
return;
|
|
7604
7611
|
}
|
|
7605
7612
|
case "pinch": {
|
|
7606
|
-
if (!inputs.
|
|
7613
|
+
if (!inputs.getIsPinching()) return;
|
|
7607
7614
|
const {
|
|
7608
7615
|
point: { z = 1 },
|
|
7609
7616
|
delta: { x: dx, y: dy }
|
|
@@ -7627,11 +7634,12 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7627
7634
|
),
|
|
7628
7635
|
{ immediate: true }
|
|
7629
7636
|
);
|
|
7637
|
+
this.emit("event", info);
|
|
7630
7638
|
return;
|
|
7631
7639
|
}
|
|
7632
7640
|
case "pinch_end": {
|
|
7633
|
-
if (!inputs.
|
|
7634
|
-
inputs.
|
|
7641
|
+
if (!inputs.getIsPinching()) return this;
|
|
7642
|
+
inputs.setIsPinching(false);
|
|
7635
7643
|
const { _selectedShapeIdsAtPointerDown: shapesToReselect } = this;
|
|
7636
7644
|
this.setSelectedShapes(this._selectedShapeIdsAtPointerDown);
|
|
7637
7645
|
this._selectedShapeIdsAtPointerDown = [];
|
|
@@ -7645,13 +7653,14 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7645
7653
|
});
|
|
7646
7654
|
}
|
|
7647
7655
|
}
|
|
7656
|
+
this.emit("event", info);
|
|
7648
7657
|
return;
|
|
7649
7658
|
}
|
|
7650
7659
|
}
|
|
7651
7660
|
}
|
|
7652
7661
|
case "wheel": {
|
|
7653
7662
|
if (cameraOptions.isLocked) return;
|
|
7654
|
-
this.
|
|
7663
|
+
this.inputs.updateFromEvent(info);
|
|
7655
7664
|
const { panSpeed, zoomSpeed } = cameraOptions;
|
|
7656
7665
|
let wheelBehavior = cameraOptions.wheelBehavior;
|
|
7657
7666
|
const inputMode = this.user.getUserPreferences().inputMode;
|
|
@@ -7669,7 +7678,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7669
7678
|
if (info.ctrlKey) behavior = wheelBehavior === "pan" ? "zoom" : "pan";
|
|
7670
7679
|
switch (behavior) {
|
|
7671
7680
|
case "zoom": {
|
|
7672
|
-
const { x, y } = this.inputs.
|
|
7681
|
+
const { x, y } = this.inputs.getCurrentScreenPoint();
|
|
7673
7682
|
let delta = dz;
|
|
7674
7683
|
if (wheelBehavior === "zoom") {
|
|
7675
7684
|
if (Math.abs(dy) > 10) {
|
|
@@ -7683,6 +7692,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7683
7692
|
immediate: true
|
|
7684
7693
|
});
|
|
7685
7694
|
this.maybeTrackPerformance("Zooming");
|
|
7695
|
+
this.root.handleEvent(info);
|
|
7696
|
+
this.emit("event", info);
|
|
7686
7697
|
return;
|
|
7687
7698
|
}
|
|
7688
7699
|
case "pan": {
|
|
@@ -7690,6 +7701,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7690
7701
|
immediate: true
|
|
7691
7702
|
});
|
|
7692
7703
|
this.maybeTrackPerformance("Panning");
|
|
7704
|
+
this.root.handleEvent(info);
|
|
7705
|
+
this.emit("event", info);
|
|
7693
7706
|
return;
|
|
7694
7707
|
}
|
|
7695
7708
|
}
|
|
@@ -7697,14 +7710,14 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7697
7710
|
break;
|
|
7698
7711
|
}
|
|
7699
7712
|
case "pointer": {
|
|
7700
|
-
if (inputs.
|
|
7701
|
-
this.
|
|
7713
|
+
if (inputs.getIsPinching()) return;
|
|
7714
|
+
this.inputs.updateFromEvent(info);
|
|
7702
7715
|
const { isPen } = info;
|
|
7703
7716
|
const { isPenMode } = instanceState;
|
|
7704
7717
|
switch (info.name) {
|
|
7705
7718
|
case "pointer_down": {
|
|
7706
7719
|
if (isPenMode && !isPen) return;
|
|
7707
|
-
if (!this.inputs.
|
|
7720
|
+
if (!this.inputs.getIsPanning()) {
|
|
7708
7721
|
this._longPressTimeout = this.timers.setTimeout(() => {
|
|
7709
7722
|
const vsb = this.getViewportScreenBounds();
|
|
7710
7723
|
this.dispatch({
|
|
@@ -7713,7 +7726,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7713
7726
|
// viewport bounds, and will be again when this event is handled...
|
|
7714
7727
|
// so we need to counter-adjust from the stored value so that the
|
|
7715
7728
|
// new value is set correctly.
|
|
7716
|
-
point: this.inputs.
|
|
7729
|
+
point: this.inputs.getOriginScreenPoint().clone().addXY(vsb.x, vsb.y),
|
|
7717
7730
|
name: "long_press"
|
|
7718
7731
|
});
|
|
7719
7732
|
}, this.options.longPressDurationMs);
|
|
@@ -7721,21 +7734,21 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7721
7734
|
this._selectedShapeIdsAtPointerDown = this.getSelectedShapeIds();
|
|
7722
7735
|
if (info.button === LEFT_MOUSE_BUTTON) this.capturedPointerId = info.pointerId;
|
|
7723
7736
|
inputs.buttons.add(info.button);
|
|
7724
|
-
inputs.
|
|
7725
|
-
inputs.
|
|
7737
|
+
inputs.setIsPointing(true);
|
|
7738
|
+
inputs.setIsDragging(false);
|
|
7726
7739
|
if (!isPenMode && isPen) this.updateInstanceState({ isPenMode: true });
|
|
7727
7740
|
if (info.button === STYLUS_ERASER_BUTTON) {
|
|
7728
7741
|
this._restoreToolId = this.getCurrentToolId();
|
|
7729
7742
|
this.complete();
|
|
7730
7743
|
this.setCurrentTool("eraser");
|
|
7731
7744
|
} else if (info.button === MIDDLE_MOUSE_BUTTON) {
|
|
7732
|
-
if (!this.inputs.
|
|
7745
|
+
if (!this.inputs.getIsPanning()) {
|
|
7733
7746
|
this._prevCursor = this.getInstanceState().cursor.type;
|
|
7734
7747
|
}
|
|
7735
|
-
this.inputs.
|
|
7748
|
+
this.inputs.setIsPanning(true);
|
|
7736
7749
|
clearTimeout(this._longPressTimeout);
|
|
7737
7750
|
}
|
|
7738
|
-
if (this.inputs.
|
|
7751
|
+
if (this.inputs.getIsPanning()) {
|
|
7739
7752
|
this.stopCameraAnimation();
|
|
7740
7753
|
this.setCursor({ type: "grabbing", rotation: 0 });
|
|
7741
7754
|
return this;
|
|
@@ -7745,8 +7758,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7745
7758
|
case "pointer_move": {
|
|
7746
7759
|
if (!isPen && isPenMode) return;
|
|
7747
7760
|
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
|
|
7748
|
-
if (this.inputs.
|
|
7749
|
-
const
|
|
7761
|
+
if (this.inputs.getIsPanning() && this.inputs.getIsPointing()) {
|
|
7762
|
+
const currentScreenPoint = this.inputs.getCurrentScreenPoint();
|
|
7763
|
+
const previousScreenPoint = this.inputs.getPreviousScreenPoint();
|
|
7750
7764
|
const offset = Vec.Sub(currentScreenPoint, previousScreenPoint);
|
|
7751
7765
|
this.setCamera(new Vec(cx + offset.x / cz, cy + offset.y / cz, cz), {
|
|
7752
7766
|
immediate: true
|
|
@@ -7754,15 +7768,15 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7754
7768
|
this.maybeTrackPerformance("Panning");
|
|
7755
7769
|
return;
|
|
7756
7770
|
}
|
|
7757
|
-
if (inputs.
|
|
7758
|
-
inputs.
|
|
7771
|
+
if (inputs.getIsPointing() && !inputs.getIsDragging() && Vec.Dist2(inputs.getOriginPagePoint(), inputs.getCurrentPagePoint()) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {
|
|
7772
|
+
inputs.setIsDragging(true);
|
|
7759
7773
|
clearTimeout(this._longPressTimeout);
|
|
7760
7774
|
}
|
|
7761
7775
|
break;
|
|
7762
7776
|
}
|
|
7763
7777
|
case "pointer_up": {
|
|
7764
|
-
inputs.
|
|
7765
|
-
inputs.
|
|
7778
|
+
inputs.setIsDragging(false);
|
|
7779
|
+
inputs.setIsPointing(false);
|
|
7766
7780
|
clearTimeout(this._longPressTimeout);
|
|
7767
7781
|
inputs.buttons.delete(info.button);
|
|
7768
7782
|
if (instanceState.isPenMode && !isPen) return;
|
|
@@ -7770,12 +7784,12 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7770
7784
|
this.capturedPointerId = null;
|
|
7771
7785
|
info.button = 0;
|
|
7772
7786
|
}
|
|
7773
|
-
if (inputs.
|
|
7787
|
+
if (inputs.getIsPanning()) {
|
|
7774
7788
|
if (!inputs.keys.has("Space")) {
|
|
7775
|
-
inputs.
|
|
7776
|
-
inputs.
|
|
7789
|
+
inputs.setIsPanning(false);
|
|
7790
|
+
inputs.setIsSpacebarPanning(false);
|
|
7777
7791
|
}
|
|
7778
|
-
const slideDirection = this.inputs.
|
|
7792
|
+
const slideDirection = this.inputs.getPointerVelocity();
|
|
7779
7793
|
const slideSpeed = Math.min(2, slideDirection.len());
|
|
7780
7794
|
switch (info.button) {
|
|
7781
7795
|
case LEFT_MOUSE_BUTTON: {
|
|
@@ -7812,51 +7826,58 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7812
7826
|
switch (info.name) {
|
|
7813
7827
|
case "key_down": {
|
|
7814
7828
|
inputs.keys.add(info.code);
|
|
7815
|
-
if (
|
|
7816
|
-
if (!
|
|
7817
|
-
this.
|
|
7818
|
-
|
|
7819
|
-
this.inputs.isPanning = true;
|
|
7820
|
-
this.inputs.isSpacebarPanning = true;
|
|
7821
|
-
clearTimeout(this._longPressTimeout);
|
|
7822
|
-
this.setCursor({ type: this.inputs.isPointing ? "grabbing" : "grab", rotation: 0 });
|
|
7823
|
-
}
|
|
7824
|
-
if (this.inputs.isSpacebarPanning) {
|
|
7825
|
-
let offset;
|
|
7826
|
-
switch (info.code) {
|
|
7827
|
-
case "ArrowUp": {
|
|
7828
|
-
offset = new Vec(0, -1);
|
|
7829
|
-
break;
|
|
7829
|
+
if (this.options.spacebarPanning) {
|
|
7830
|
+
if (info.code === "Space" && !info.ctrlKey) {
|
|
7831
|
+
if (!this.inputs.getIsPanning()) {
|
|
7832
|
+
this._prevCursor = instanceState.cursor.type;
|
|
7830
7833
|
}
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7834
|
+
this.inputs.setIsPanning(true);
|
|
7835
|
+
this.inputs.setIsSpacebarPanning(true);
|
|
7836
|
+
clearTimeout(this._longPressTimeout);
|
|
7837
|
+
this.setCursor({
|
|
7838
|
+
type: this.inputs.getIsPointing() ? "grabbing" : "grab",
|
|
7839
|
+
rotation: 0
|
|
7840
|
+
});
|
|
7841
|
+
}
|
|
7842
|
+
if (this.inputs.getIsSpacebarPanning()) {
|
|
7843
|
+
let offset;
|
|
7844
|
+
switch (info.code) {
|
|
7845
|
+
case "ArrowUp": {
|
|
7846
|
+
offset = new Vec(0, -1);
|
|
7847
|
+
break;
|
|
7848
|
+
}
|
|
7849
|
+
case "ArrowRight": {
|
|
7850
|
+
offset = new Vec(1, 0);
|
|
7851
|
+
break;
|
|
7852
|
+
}
|
|
7853
|
+
case "ArrowDown": {
|
|
7854
|
+
offset = new Vec(0, 1);
|
|
7855
|
+
break;
|
|
7856
|
+
}
|
|
7857
|
+
case "ArrowLeft": {
|
|
7858
|
+
offset = new Vec(-1, 0);
|
|
7859
|
+
break;
|
|
7860
|
+
}
|
|
7838
7861
|
}
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7862
|
+
if (offset) {
|
|
7863
|
+
const bounds = this.getViewportPageBounds();
|
|
7864
|
+
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
|
|
7865
|
+
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
7842
7866
|
}
|
|
7843
7867
|
}
|
|
7844
|
-
if (offset) {
|
|
7845
|
-
const bounds = this.getViewportPageBounds();
|
|
7846
|
-
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
|
|
7847
|
-
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
7848
|
-
}
|
|
7849
7868
|
}
|
|
7850
7869
|
break;
|
|
7851
7870
|
}
|
|
7852
7871
|
case "key_up": {
|
|
7853
7872
|
inputs.keys.delete(info.code);
|
|
7854
|
-
if (
|
|
7855
|
-
if (
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7873
|
+
if (this.options.spacebarPanning) {
|
|
7874
|
+
if (info.code === "Space") {
|
|
7875
|
+
if (this.inputs.buttons.has(MIDDLE_MOUSE_BUTTON)) {
|
|
7876
|
+
} else {
|
|
7877
|
+
this.inputs.setIsPanning(false);
|
|
7878
|
+
this.inputs.setIsSpacebarPanning(false);
|
|
7879
|
+
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7880
|
+
}
|
|
7860
7881
|
}
|
|
7861
7882
|
}
|
|
7862
7883
|
break;
|
|
@@ -7909,8 +7930,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7909
7930
|
}
|
|
7910
7931
|
_init = __decoratorStart(_a);
|
|
7911
7932
|
__decorateElement(_init, 1, "getIsShapeHiddenCache", _getIsShapeHiddenCache_dec, Editor);
|
|
7912
|
-
__decorateElement(_init, 1, "
|
|
7913
|
-
__decorateElement(_init, 1, "
|
|
7933
|
+
__decorateElement(_init, 1, "canUndo", _canUndo_dec, Editor);
|
|
7934
|
+
__decorateElement(_init, 1, "canRedo", _canRedo_dec, Editor);
|
|
7914
7935
|
__decorateElement(_init, 1, "getPath", _getPath_dec, Editor);
|
|
7915
7936
|
__decorateElement(_init, 1, "getCurrentTool", _getCurrentTool_dec, Editor);
|
|
7916
7937
|
__decorateElement(_init, 1, "getCurrentToolId", _getCurrentToolId_dec, Editor);
|