@tldraw/editor 4.2.2 → 4.2.3
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/dist-cjs/index.d.ts +155 -498
- package/dist-cjs/index.js +1 -6
- 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 +17 -1
- package/dist-cjs/lib/components/GeometryDebuggingView.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +3 -3
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/constants.js +3 -1
- package/dist-cjs/lib/constants.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +286 -292
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +17 -18
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +3 -3
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js +3 -12
- 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 +6 -5
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- 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/TickManager/TickManager.js +22 -1
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/BaseBoxShapeUtil.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +23 -31
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/DashedOutlineBox.js +1 -1
- package/dist-cjs/lib/editor/shapes/group/DashedOutlineBox.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.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/editor/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.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/globals/environment.js +9 -45
- package/dist-cjs/lib/globals/environment.js.map +2 -2
- package/dist-cjs/lib/globals/menus.js +1 -1
- package/dist-cjs/lib/globals/menus.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +3 -4
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useCoarsePointer.js +29 -14
- package/dist-cjs/lib/hooks/useCoarsePointer.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 +1 -4
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +2 -2
- package/dist-cjs/lib/hooks/useTransform.js.map +1 -1
- package/dist-cjs/lib/hooks/useZoomCss.js +8 -4
- package/dist-cjs/lib/hooks/useZoomCss.js.map +2 -2
- package/dist-cjs/lib/options.js +1 -6
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +0 -3
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +0 -1
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.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 +155 -498
- package/dist-esm/index.mjs +2 -7
- 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 +17 -1
- package/dist-esm/lib/components/GeometryDebuggingView.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +3 -3
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/constants.mjs +3 -1
- package/dist-esm/lib/constants.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +289 -293
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +17 -18
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +3 -3
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs +4 -13
- 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 +6 -5
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- 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/TickManager/TickManager.mjs +22 -1
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/BaseBoxShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +23 -31
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/DashedOutlineBox.mjs +1 -1
- package/dist-esm/lib/editor/shapes/group/DashedOutlineBox.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.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/getSvgJsx.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/globals/environment.mjs +9 -45
- package/dist-esm/lib/globals/environment.mjs.map +2 -2
- package/dist-esm/lib/globals/menus.mjs +1 -1
- package/dist-esm/lib/globals/menus.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +3 -4
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCoarsePointer.mjs +30 -15
- package/dist-esm/lib/hooks/useCoarsePointer.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 +1 -4
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +2 -2
- package/dist-esm/lib/hooks/useTransform.mjs.map +1 -1
- package/dist-esm/lib/hooks/useZoomCss.mjs +8 -4
- package/dist-esm/lib/hooks/useZoomCss.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +1 -6
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +0 -3
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +0 -1
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.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 +12 -14
- package/package.json +16 -18
- package/src/index.ts +1 -4
- package/src/lib/components/ErrorBoundary.tsx +1 -1
- package/src/lib/components/GeometryDebuggingView.tsx +19 -1
- package/src/lib/components/default-components/DefaultCanvas.tsx +3 -4
- package/src/lib/constants.ts +2 -0
- package/src/lib/editor/Editor.test.ts +10 -150
- package/src/lib/editor/Editor.ts +379 -459
- package/src/lib/editor/bindings/BindingUtil.ts +9 -15
- package/src/lib/editor/derivations/bindingsIndex.ts +2 -2
- package/src/lib/editor/derivations/notVisibleShapes.ts +23 -37
- package/src/lib/editor/derivations/parentsToChildren.ts +7 -18
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +31 -17
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +1 -1
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +79 -129
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +6 -10
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +4 -14
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +4 -0
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +0 -12
- package/src/lib/editor/managers/SnapManager/SnapManager.ts +4 -4
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +107 -40
- package/src/lib/editor/managers/TickManager/TickManager.ts +32 -2
- package/src/lib/editor/shapes/BaseBoxShapeUtil.tsx +2 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +32 -72
- package/src/lib/editor/shapes/group/DashedOutlineBox.tsx +1 -1
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +3 -1
- package/src/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.ts +1 -2
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +6 -6
- package/src/lib/editor/types/emit-types.ts +1 -3
- package/src/lib/exports/getSvgJsx.test.ts +19 -10
- package/src/lib/exports/getSvgJsx.tsx +5 -2
- package/src/lib/exports/parseCss.test.ts +0 -1
- package/src/lib/exports/parseCss.ts +1 -1
- package/src/lib/globals/environment.ts +10 -65
- package/src/lib/globals/menus.ts +1 -1
- package/src/lib/hooks/useCanvasEvents.ts +3 -4
- package/src/lib/hooks/useCoarsePointer.ts +59 -16
- 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 +1 -4
- package/src/lib/hooks/useTransform.ts +1 -1
- package/src/lib/hooks/useZoomCss.ts +8 -3
- package/src/lib/options.ts +0 -32
- package/src/lib/primitives/Box.ts +0 -9
- package/src/lib/primitives/geometry/Geometry2d.ts +0 -1
- package/src/lib/utils/reparenting.ts +5 -5
- package/src/lib/utils/rotation.ts +1 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +0 -591
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +0 -7
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +0 -573
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +0 -7
- package/src/lib/config/TLUserPreferences.test.ts +0 -40
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +0 -566
|
@@ -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,
|
|
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, _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, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
|
|
50
50
|
import {
|
|
51
51
|
EMPTY_ARRAY,
|
|
52
52
|
atom,
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
PageRecordType,
|
|
65
65
|
TLDOCUMENT_ID,
|
|
66
66
|
TLINSTANCE_ID,
|
|
67
|
+
TLPOINTER_ID,
|
|
67
68
|
createBindingId,
|
|
68
69
|
createShapeId,
|
|
69
70
|
getShapePropKeysByStyle,
|
|
@@ -115,7 +116,8 @@ import {
|
|
|
115
116
|
LEFT_MOUSE_BUTTON,
|
|
116
117
|
MIDDLE_MOUSE_BUTTON,
|
|
117
118
|
RIGHT_MOUSE_BUTTON,
|
|
118
|
-
STYLUS_ERASER_BUTTON
|
|
119
|
+
STYLUS_ERASER_BUTTON,
|
|
120
|
+
ZOOM_TO_FIT_PADDING
|
|
119
121
|
} from "../constants.mjs";
|
|
120
122
|
import { exportToSvg } from "../exports/exportToSvg.mjs";
|
|
121
123
|
import { getSvgAsImage } from "../exports/getSvgAsImage.mjs";
|
|
@@ -138,6 +140,7 @@ import {
|
|
|
138
140
|
parseDeepLinkString
|
|
139
141
|
} from "../utils/deepLinks.mjs";
|
|
140
142
|
import { getIncrementedName } from "../utils/getIncrementedName.mjs";
|
|
143
|
+
import { isAccelKey } from "../utils/keyboard.mjs";
|
|
141
144
|
import { getReorderingShapesChanges } from "../utils/reorderShapes.mjs";
|
|
142
145
|
import { applyRotationToSnapshotShapes, getRotationSnapshot } from "../utils/rotation.mjs";
|
|
143
146
|
import { bindingsIndex } from "./derivations/bindingsIndex.mjs";
|
|
@@ -149,14 +152,13 @@ import { EdgeScrollManager } from "./managers/EdgeScrollManager/EdgeScrollManage
|
|
|
149
152
|
import { FocusManager } from "./managers/FocusManager/FocusManager.mjs";
|
|
150
153
|
import { FontManager } from "./managers/FontManager/FontManager.mjs";
|
|
151
154
|
import { HistoryManager } from "./managers/HistoryManager/HistoryManager.mjs";
|
|
152
|
-
import { InputsManager } from "./managers/InputsManager/InputsManager.mjs";
|
|
153
155
|
import { ScribbleManager } from "./managers/ScribbleManager/ScribbleManager.mjs";
|
|
154
156
|
import { SnapManager } from "./managers/SnapManager/SnapManager.mjs";
|
|
155
157
|
import { TextManager } from "./managers/TextManager/TextManager.mjs";
|
|
156
158
|
import { TickManager } from "./managers/TickManager/TickManager.mjs";
|
|
157
159
|
import { UserPreferencesManager } from "./managers/UserPreferencesManager/UserPreferencesManager.mjs";
|
|
158
160
|
import { RootState } from "./tools/RootState.mjs";
|
|
159
|
-
class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed],
|
|
161
|
+
class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed], _getCanUndo_dec = [computed], _getCanRedo_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], _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) {
|
|
160
162
|
constructor({
|
|
161
163
|
store,
|
|
162
164
|
user,
|
|
@@ -192,7 +194,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
192
194
|
*/
|
|
193
195
|
__publicField(this, "root");
|
|
194
196
|
/**
|
|
195
|
-
* A set of functions to call when the
|
|
197
|
+
* A set of functions to call when the app is disposed.
|
|
196
198
|
*
|
|
197
199
|
* @public
|
|
198
200
|
*/
|
|
@@ -203,19 +205,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
203
205
|
* @public
|
|
204
206
|
*/
|
|
205
207
|
__publicField(this, "isDisposed", false);
|
|
206
|
-
/**
|
|
207
|
-
* A manager for the editor's tick events.
|
|
208
|
-
*
|
|
209
|
-
* @internal */
|
|
208
|
+
/** @internal */
|
|
210
209
|
__publicField(this, "_tickManager");
|
|
211
210
|
/**
|
|
212
|
-
* A manager for the
|
|
213
|
-
*
|
|
214
|
-
* @public
|
|
215
|
-
*/
|
|
216
|
-
__publicField(this, "inputs");
|
|
217
|
-
/**
|
|
218
|
-
* A manager for the editor's snapping feature.
|
|
211
|
+
* A manager for the app's snapping feature.
|
|
219
212
|
*
|
|
220
213
|
* @public
|
|
221
214
|
*/
|
|
@@ -297,7 +290,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
297
290
|
__publicField(this, "bindingUtils");
|
|
298
291
|
/* --------------------- History -------------------- */
|
|
299
292
|
/**
|
|
300
|
-
* A manager for the
|
|
293
|
+
* A manager for the app's history.
|
|
301
294
|
*
|
|
302
295
|
* @readonly
|
|
303
296
|
*/
|
|
@@ -312,7 +305,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
312
305
|
// Rich text editor
|
|
313
306
|
__publicField(this, "_currentRichTextEditor", atom("rich text editor", null));
|
|
314
307
|
__publicField(this, "_textOptions");
|
|
315
|
-
__publicField(this, "_debouncedZoomLevel", atom("debounced zoom level", 1));
|
|
316
308
|
__publicField(this, "_cameraOptions", atom("camera options", DEFAULT_CAMERA_OPTIONS));
|
|
317
309
|
/** @internal */
|
|
318
310
|
__publicField(this, "_viewportAnimation", null);
|
|
@@ -363,6 +355,54 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
363
355
|
tldraw: null,
|
|
364
356
|
excalidraw: null
|
|
365
357
|
});
|
|
358
|
+
/* --------------------- Events --------------------- */
|
|
359
|
+
/**
|
|
360
|
+
* The app's current input state.
|
|
361
|
+
*
|
|
362
|
+
* @public
|
|
363
|
+
*/
|
|
364
|
+
__publicField(this, "inputs", {
|
|
365
|
+
/** The most recent pointer down's position in the current page space. */
|
|
366
|
+
originPagePoint: new Vec(),
|
|
367
|
+
/** The most recent pointer down's position in screen space. */
|
|
368
|
+
originScreenPoint: new Vec(),
|
|
369
|
+
/** The previous pointer position in the current page space. */
|
|
370
|
+
previousPagePoint: new Vec(),
|
|
371
|
+
/** The previous pointer position in screen space. */
|
|
372
|
+
previousScreenPoint: new Vec(),
|
|
373
|
+
/** The most recent pointer position in the current page space. */
|
|
374
|
+
currentPagePoint: new Vec(),
|
|
375
|
+
/** The most recent pointer position in screen space. */
|
|
376
|
+
currentScreenPoint: new Vec(),
|
|
377
|
+
/** A set containing the currently pressed keys. */
|
|
378
|
+
keys: /* @__PURE__ */ new Set(),
|
|
379
|
+
/** A set containing the currently pressed buttons. */
|
|
380
|
+
buttons: /* @__PURE__ */ new Set(),
|
|
381
|
+
/** Whether the input is from a pe. */
|
|
382
|
+
isPen: false,
|
|
383
|
+
/** Whether the shift key is currently pressed. */
|
|
384
|
+
shiftKey: false,
|
|
385
|
+
/** Whether the meta key is currently pressed. */
|
|
386
|
+
metaKey: false,
|
|
387
|
+
/** Whether the control or command key is currently pressed. */
|
|
388
|
+
ctrlKey: false,
|
|
389
|
+
/** Whether the alt or option key is currently pressed. */
|
|
390
|
+
altKey: false,
|
|
391
|
+
/** Whether the user is dragging. */
|
|
392
|
+
isDragging: false,
|
|
393
|
+
/** Whether the user is pointing. */
|
|
394
|
+
isPointing: false,
|
|
395
|
+
/** Whether the user is pinching. */
|
|
396
|
+
isPinching: false,
|
|
397
|
+
/** Whether the user is editing. */
|
|
398
|
+
isEditing: false,
|
|
399
|
+
/** Whether the user is panning. */
|
|
400
|
+
isPanning: false,
|
|
401
|
+
/** Whether the user is spacebar panning. */
|
|
402
|
+
isSpacebarPanning: false,
|
|
403
|
+
/** Velocity of mouse pointer, in pixels per millisecond */
|
|
404
|
+
pointerVelocity: new Vec()
|
|
405
|
+
});
|
|
366
406
|
/**
|
|
367
407
|
* A manager for recording multiple click events.
|
|
368
408
|
*
|
|
@@ -386,6 +426,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
386
426
|
/** @internal */
|
|
387
427
|
__publicField(this, "_restoreToolId", "select");
|
|
388
428
|
/** @internal */
|
|
429
|
+
__publicField(this, "_pinchStart", 1);
|
|
430
|
+
/** @internal */
|
|
389
431
|
__publicField(this, "_didPinch", false);
|
|
390
432
|
/** @internal */
|
|
391
433
|
__publicField(this, "_selectedShapeIdsAtPointerDown", []);
|
|
@@ -421,7 +463,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
421
463
|
this.disposables.add(() => this.textMeasure.dispose());
|
|
422
464
|
this.fonts = new FontManager(this, fontAssetUrls);
|
|
423
465
|
this._tickManager = new TickManager(this);
|
|
424
|
-
this.inputs = new InputsManager(this);
|
|
425
466
|
class NewRoot extends RootState {
|
|
426
467
|
static initial = initialState ?? "";
|
|
427
468
|
}
|
|
@@ -854,7 +895,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
854
895
|
this.disposables.clear();
|
|
855
896
|
this.store.dispose();
|
|
856
897
|
this.isDisposed = true;
|
|
857
|
-
this.emit("dispose");
|
|
858
898
|
}
|
|
859
899
|
getShapeUtil(arg) {
|
|
860
900
|
const type = typeof arg === "string" ? arg : arg.type;
|
|
@@ -888,11 +928,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
888
928
|
this.history.undo();
|
|
889
929
|
return this;
|
|
890
930
|
}
|
|
891
|
-
canUndo() {
|
|
892
|
-
return this.history.getNumUndos() > 0;
|
|
893
|
-
}
|
|
894
931
|
getCanUndo() {
|
|
895
|
-
return this.
|
|
932
|
+
return this.history.getNumUndos() > 0;
|
|
896
933
|
}
|
|
897
934
|
/**
|
|
898
935
|
* Redo to the next mark.
|
|
@@ -910,16 +947,13 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
910
947
|
this.history.redo();
|
|
911
948
|
return this;
|
|
912
949
|
}
|
|
913
|
-
canRedo() {
|
|
914
|
-
return this.history.getNumRedos() > 0;
|
|
915
|
-
}
|
|
916
|
-
getCanRedo() {
|
|
917
|
-
return this.canRedo();
|
|
918
|
-
}
|
|
919
950
|
clearHistory() {
|
|
920
951
|
this.history.clear();
|
|
921
952
|
return this;
|
|
922
953
|
}
|
|
954
|
+
getCanRedo() {
|
|
955
|
+
return this.history.getNumRedos() > 0;
|
|
956
|
+
}
|
|
923
957
|
/**
|
|
924
958
|
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
925
959
|
* any redos. You typically want to do this just before a user interaction begins or is handled.
|
|
@@ -1074,7 +1108,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1074
1108
|
}),
|
|
1075
1109
|
selectionCount: this.getSelectedShapes().length,
|
|
1076
1110
|
editingShape: editingShapeId ? this.getShape(editingShapeId) : void 0,
|
|
1077
|
-
inputs: this.inputs
|
|
1111
|
+
inputs: this.inputs,
|
|
1078
1112
|
pageState: this.getCurrentPageState(),
|
|
1079
1113
|
instanceState: this.getInstanceState(),
|
|
1080
1114
|
collaboratorCount: this.getCollaboratorsOnCurrentPage().length
|
|
@@ -1095,7 +1129,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1095
1129
|
* we're in a transaction that's about to be rolled back due to the same error we're currently
|
|
1096
1130
|
* reporting.
|
|
1097
1131
|
*
|
|
1098
|
-
* Instead, to listen to changes to this value, you need to listen to
|
|
1132
|
+
* Instead, to listen to changes to this value, you need to listen to app's `crash` event.
|
|
1099
1133
|
*
|
|
1100
1134
|
* @internal
|
|
1101
1135
|
*/
|
|
@@ -1746,28 +1780,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1746
1780
|
const editingShapeId = this.getEditingShapeId();
|
|
1747
1781
|
return editingShapeId ? this.getShape(editingShapeId) : void 0;
|
|
1748
1782
|
}
|
|
1749
|
-
/**
|
|
1750
|
-
* Whether the shape can be edited.
|
|
1751
|
-
*
|
|
1752
|
-
* @param shape - The shape (or shape id) to check if it can be edited.
|
|
1753
|
-
* @param info - The info about the edit start.
|
|
1754
|
-
*
|
|
1755
|
-
* @public
|
|
1756
|
-
* @returns true if the shape can be edited, false otherwise.
|
|
1757
|
-
*/
|
|
1758
|
-
canEditShape(shape, info) {
|
|
1759
|
-
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1760
|
-
if (!id) return false;
|
|
1761
|
-
if (id === this.getEditingShapeId()) return false;
|
|
1762
|
-
const _shape = this.getShape(id);
|
|
1763
|
-
if (!_shape) return false;
|
|
1764
|
-
const util = this.getShapeUtil(_shape);
|
|
1765
|
-
const _info = info ?? { type: "unknown" };
|
|
1766
|
-
if (!util.canEdit(_shape, _info)) return false;
|
|
1767
|
-
if (this.getIsReadonly() && !util.canEditInReadonly(_shape)) return false;
|
|
1768
|
-
if (this.isShapeOrAncestorLocked(_shape) && !util.canEditWhileLocked(_shape)) return false;
|
|
1769
|
-
return true;
|
|
1770
|
-
}
|
|
1771
1783
|
/**
|
|
1772
1784
|
* Set the current editing shape.
|
|
1773
1785
|
*
|
|
@@ -1783,42 +1795,42 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1783
1795
|
*/
|
|
1784
1796
|
setEditingShape(shape) {
|
|
1785
1797
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1786
|
-
|
|
1798
|
+
this.setRichTextEditor(null);
|
|
1799
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
1800
|
+
if (id !== prevEditingShapeId) {
|
|
1801
|
+
if (id) {
|
|
1802
|
+
const shape2 = this.getShape(id);
|
|
1803
|
+
if (shape2 && this.getShapeUtil(shape2).canEdit(shape2)) {
|
|
1804
|
+
this.run(
|
|
1805
|
+
() => {
|
|
1806
|
+
this._updateCurrentPageState({ editingShapeId: id });
|
|
1807
|
+
if (prevEditingShapeId) {
|
|
1808
|
+
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1809
|
+
if (prevEditingShape) {
|
|
1810
|
+
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
this.getShapeUtil(shape2).onEditStart?.(shape2);
|
|
1814
|
+
},
|
|
1815
|
+
{ history: "ignore" }
|
|
1816
|
+
);
|
|
1817
|
+
return this;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1787
1820
|
this.run(
|
|
1788
1821
|
() => {
|
|
1789
|
-
|
|
1822
|
+
this._updateCurrentPageState({ editingShapeId: null });
|
|
1823
|
+
this._currentRichTextEditor.set(null);
|
|
1790
1824
|
if (prevEditingShapeId) {
|
|
1791
1825
|
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1792
1826
|
if (prevEditingShape) {
|
|
1793
1827
|
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1794
1828
|
}
|
|
1795
1829
|
}
|
|
1796
|
-
this._updateCurrentPageState({ editingShapeId: null });
|
|
1797
|
-
this._currentRichTextEditor.set(null);
|
|
1798
1830
|
},
|
|
1799
1831
|
{ history: "ignore" }
|
|
1800
1832
|
);
|
|
1801
|
-
return this;
|
|
1802
1833
|
}
|
|
1803
|
-
if (!this.canEditShape(id)) return this;
|
|
1804
|
-
this.run(
|
|
1805
|
-
() => {
|
|
1806
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
1807
|
-
if (prevEditingShapeId) {
|
|
1808
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1809
|
-
if (prevEditingShape) {
|
|
1810
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
this._updateCurrentPageState({ editingShapeId: null });
|
|
1814
|
-
this._currentRichTextEditor.set(null);
|
|
1815
|
-
this.select(id);
|
|
1816
|
-
this._updateCurrentPageState({ editingShapeId: id });
|
|
1817
|
-
const nextEditingShape = this.getShape(id);
|
|
1818
|
-
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
1819
|
-
},
|
|
1820
|
-
{ history: "ignore" }
|
|
1821
|
-
);
|
|
1822
1834
|
return this;
|
|
1823
1835
|
}
|
|
1824
1836
|
getRichTextEditor() {
|
|
@@ -1951,25 +1963,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1951
1963
|
getCroppingShapeId() {
|
|
1952
1964
|
return this.getCurrentPageState().croppingShapeId;
|
|
1953
1965
|
}
|
|
1954
|
-
/**
|
|
1955
|
-
* Whether the shape can be cropped.
|
|
1956
|
-
*
|
|
1957
|
-
* @param shape - The shape (or shape id) to check if it can be cropped.
|
|
1958
|
-
*
|
|
1959
|
-
* @public
|
|
1960
|
-
* @returns true if the shape can be cropped, false otherwise.
|
|
1961
|
-
*/
|
|
1962
|
-
canCropShape(shape) {
|
|
1963
|
-
if (!shape) return false;
|
|
1964
|
-
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1965
|
-
if (!id) return false;
|
|
1966
|
-
const _shape = this.getShape(id);
|
|
1967
|
-
if (!_shape) return false;
|
|
1968
|
-
const util = this.getShapeUtil(_shape);
|
|
1969
|
-
if (!util.canCrop(_shape)) return false;
|
|
1970
|
-
if (this.isShapeOrAncestorLocked(_shape)) return false;
|
|
1971
|
-
return true;
|
|
1972
|
-
}
|
|
1973
1966
|
/**
|
|
1974
1967
|
* Set the current cropping shape.
|
|
1975
1968
|
*
|
|
@@ -1991,8 +1984,12 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1991
1984
|
() => {
|
|
1992
1985
|
if (!id) {
|
|
1993
1986
|
this.updateCurrentPageState({ croppingShapeId: null });
|
|
1994
|
-
} else
|
|
1995
|
-
this.
|
|
1987
|
+
} else {
|
|
1988
|
+
const shape2 = this.getShape(id);
|
|
1989
|
+
const util = this.getShapeUtil(shape2);
|
|
1990
|
+
if (shape2 && util.canCrop(shape2)) {
|
|
1991
|
+
this.updateCurrentPageState({ croppingShapeId: id });
|
|
1992
|
+
}
|
|
1996
1993
|
}
|
|
1997
1994
|
},
|
|
1998
1995
|
{ history: "ignore" }
|
|
@@ -2067,22 +2064,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2067
2064
|
getZoomLevel() {
|
|
2068
2065
|
return this.getCamera().z;
|
|
2069
2066
|
}
|
|
2070
|
-
getDebouncedZoomLevel() {
|
|
2071
|
-
if (this.options.debouncedZoom) {
|
|
2072
|
-
if (this.getCameraState() === "idle") {
|
|
2073
|
-
return this.getZoomLevel();
|
|
2074
|
-
} else {
|
|
2075
|
-
return this._debouncedZoomLevel.get();
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
return this.getZoomLevel();
|
|
2079
|
-
}
|
|
2080
|
-
_getAboveDebouncedZoomThreshold() {
|
|
2081
|
-
return this.getCurrentPageShapeIds().size > this.options.debouncedZoomThreshold;
|
|
2082
|
-
}
|
|
2083
|
-
getEfficientZoomLevel() {
|
|
2084
|
-
return this._getAboveDebouncedZoomThreshold() ? this.getDebouncedZoomLevel() : this.getZoomLevel();
|
|
2085
|
-
}
|
|
2086
2067
|
/**
|
|
2087
2068
|
* Get the camera's initial or reset zoom level.
|
|
2088
2069
|
*
|
|
@@ -2328,8 +2309,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2328
2309
|
},
|
|
2329
2310
|
{ history: "ignore" }
|
|
2330
2311
|
);
|
|
2331
|
-
const currentScreenPoint = this.inputs
|
|
2332
|
-
const currentPagePoint = this.inputs.getCurrentPagePoint();
|
|
2312
|
+
const { currentScreenPoint, currentPagePoint } = this.inputs;
|
|
2333
2313
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2334
2314
|
this.updatePointer({
|
|
2335
2315
|
immediate: opts?.immediate,
|
|
@@ -2464,7 +2444,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2464
2444
|
* ```ts
|
|
2465
2445
|
* editor.zoomIn()
|
|
2466
2446
|
* editor.zoomIn(editor.getViewportScreenCenter(), { animation: { duration: 200 } })
|
|
2467
|
-
* editor.zoomIn(editor.inputs.
|
|
2447
|
+
* editor.zoomIn(editor.inputs.currentScreenPoint, { animation: { duration: 200 } })
|
|
2468
2448
|
* ```
|
|
2469
2449
|
*
|
|
2470
2450
|
* @param point - The screen point to zoom in on. Defaults to the screen center
|
|
@@ -2505,7 +2485,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2505
2485
|
* ```ts
|
|
2506
2486
|
* editor.zoomOut()
|
|
2507
2487
|
* editor.zoomOut(editor.getViewportScreenCenter(), { animation: { duration: 120 } })
|
|
2508
|
-
* editor.zoomOut(editor.inputs.
|
|
2488
|
+
* editor.zoomOut(editor.inputs.currentScreenPoint, { animation: { duration: 120 } })
|
|
2509
2489
|
* ```
|
|
2510
2490
|
*
|
|
2511
2491
|
* @param point - The point to zoom out on. Defaults to the viewport screen center.
|
|
@@ -2557,15 +2537,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2557
2537
|
if (isLocked && !opts?.force) return this;
|
|
2558
2538
|
const selectionPageBounds = this.getSelectionPageBounds();
|
|
2559
2539
|
if (selectionPageBounds) {
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
}
|
|
2564
|
-
this.zoomToBounds(selectionPageBounds, {
|
|
2565
|
-
targetZoom: 1,
|
|
2566
|
-
...opts
|
|
2567
|
-
});
|
|
2568
|
-
}
|
|
2540
|
+
this.zoomToBounds(selectionPageBounds, {
|
|
2541
|
+
targetZoom: Math.max(1, this.getZoomLevel()),
|
|
2542
|
+
...opts
|
|
2543
|
+
});
|
|
2569
2544
|
}
|
|
2570
2545
|
return this;
|
|
2571
2546
|
}
|
|
@@ -2605,7 +2580,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2605
2580
|
const cameraOptions = this._cameraOptions.__unsafe__getWithoutCapture();
|
|
2606
2581
|
if (cameraOptions.isLocked && !opts?.force) return this;
|
|
2607
2582
|
const viewportScreenBounds = this.getViewportScreenBounds();
|
|
2608
|
-
const inset = opts?.inset ?? Math.min(
|
|
2583
|
+
const inset = opts?.inset ?? Math.min(ZOOM_TO_FIT_PADDING, viewportScreenBounds.width * 0.28);
|
|
2609
2584
|
const baseZoom = this.getBaseZoom();
|
|
2610
2585
|
const zoomMin = cameraOptions.zoomSteps[0];
|
|
2611
2586
|
const zoomMax = last(cameraOptions.zoomSteps);
|
|
@@ -2829,20 +2804,18 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2829
2804
|
}
|
|
2830
2805
|
if (_willSetInitialBounds) {
|
|
2831
2806
|
this.updateInstanceState({ screenBounds: screenBounds.toJson(), insets });
|
|
2832
|
-
this.emit("resize", screenBounds.toJson());
|
|
2833
2807
|
this.setCamera(this.getCamera());
|
|
2834
2808
|
} else {
|
|
2835
2809
|
if (center && !this.getInstanceState().followingUserId) {
|
|
2836
2810
|
const before = this.getViewportPageBounds().center;
|
|
2837
2811
|
this.updateInstanceState({ screenBounds: screenBounds.toJson(), insets });
|
|
2838
|
-
this.emit("resize", screenBounds.toJson());
|
|
2839
2812
|
this.centerOnPoint(before);
|
|
2840
2813
|
} else {
|
|
2841
2814
|
this.updateInstanceState({ screenBounds: screenBounds.toJson(), insets });
|
|
2842
|
-
this.emit("resize", screenBounds.toJson());
|
|
2843
2815
|
this._setCamera(Vec.From({ ...this.getCamera() }));
|
|
2844
2816
|
}
|
|
2845
2817
|
}
|
|
2818
|
+
this._tickCameraState();
|
|
2846
2819
|
return this;
|
|
2847
2820
|
}
|
|
2848
2821
|
getViewportScreenBounds() {
|
|
@@ -3122,7 +3095,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3122
3095
|
this._cameraStateTimeoutRemaining = this.options.cameraMovingTimeoutMs;
|
|
3123
3096
|
if (this._cameraState.__unsafe__getWithoutCapture() !== "idle") return;
|
|
3124
3097
|
this._cameraState.set("moving");
|
|
3125
|
-
this._debouncedZoomLevel.set(unsafe__withoutCapture(() => this.getCamera().z));
|
|
3126
3098
|
this.on("tick", this._decayCameraStateTimeout);
|
|
3127
3099
|
}
|
|
3128
3100
|
/**
|
|
@@ -4463,18 +4435,30 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4463
4435
|
getBinding(id) {
|
|
4464
4436
|
return this.store.get(id);
|
|
4465
4437
|
}
|
|
4438
|
+
/**
|
|
4439
|
+
* Get all bindings of a certain type _from_ a particular shape. These are the bindings whose
|
|
4440
|
+
* `fromId` matched the shape's ID.
|
|
4441
|
+
*/
|
|
4466
4442
|
getBindingsFromShape(shape, type) {
|
|
4467
4443
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
4468
4444
|
return this.getBindingsInvolvingShape(id).filter(
|
|
4469
4445
|
(b) => b.fromId === id && b.type === type
|
|
4470
4446
|
);
|
|
4471
4447
|
}
|
|
4448
|
+
/**
|
|
4449
|
+
* Get all bindings of a certain type _to_ a particular shape. These are the bindings whose
|
|
4450
|
+
* `toId` matches the shape's ID.
|
|
4451
|
+
*/
|
|
4472
4452
|
getBindingsToShape(shape, type) {
|
|
4473
4453
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
4474
4454
|
return this.getBindingsInvolvingShape(id).filter(
|
|
4475
4455
|
(b) => b.toId === id && b.type === type
|
|
4476
4456
|
);
|
|
4477
4457
|
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Get all bindings involving a particular shape. This includes bindings where the shape is the
|
|
4460
|
+
* `fromId` or `toId`. If a type is provided, only bindings of that type are returned.
|
|
4461
|
+
*/
|
|
4478
4462
|
getBindingsInvolvingShape(shape, type) {
|
|
4479
4463
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
4480
4464
|
const result = this._getBindingsIndexCache().get(id) ?? EMPTY_ARRAY;
|
|
@@ -5722,8 +5706,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5722
5706
|
isAspectRatioLocked: options.isAspectRatioLocked
|
|
5723
5707
|
});
|
|
5724
5708
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
5725
|
-
|
|
5726
|
-
|
|
5709
|
+
let { rotation } = Mat.Decompose(options.initialPageTransform);
|
|
5710
|
+
rotation -= 2 * rotation;
|
|
5727
5711
|
this.updateShapes([{ id, type, rotation }]);
|
|
5728
5712
|
}
|
|
5729
5713
|
const preScaleShapePageCenter = Mat.applyToPoint(
|
|
@@ -5736,9 +5720,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5736
5720
|
scale,
|
|
5737
5721
|
options.scaleAxisRotation
|
|
5738
5722
|
);
|
|
5723
|
+
const pageBounds = this.getShapePageBounds(id);
|
|
5739
5724
|
const pageTransform = this.getShapePageTransform(id);
|
|
5740
|
-
const
|
|
5741
|
-
const currentPageCenter = Mat.applyToPoint(pageTransform, currentLocalBounds.center);
|
|
5725
|
+
const currentPageCenter = pageBounds.center;
|
|
5742
5726
|
const shapePageTransformOrigin = pageTransform.point();
|
|
5743
5727
|
if (!currentPageCenter || !shapePageTransformOrigin) return this;
|
|
5744
5728
|
const pageDelta = Vec.Sub(postScaleShapePageCenter, currentPageCenter);
|
|
@@ -6024,11 +6008,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6024
6008
|
)
|
|
6025
6009
|
);
|
|
6026
6010
|
const sortedShapeIds = shapesToGroup.sort(sortByIndex).map((s) => s.id);
|
|
6027
|
-
const
|
|
6028
|
-
const pageBounds = Box.Common(childBounds);
|
|
6029
|
-
if (!pageBounds.isValid()) {
|
|
6030
|
-
throw Error(`Editor.groupShapes: group bounds are invalid (NaN).`);
|
|
6031
|
-
}
|
|
6011
|
+
const pageBounds = Box.Common(compact(shapesToGroup.map((id) => this.getShapePageBounds(id))));
|
|
6032
6012
|
const { x, y } = pageBounds.point;
|
|
6033
6013
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
|
|
6034
6014
|
if (this.getCurrentToolId() !== "select") return this;
|
|
@@ -6718,25 +6698,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6718
6698
|
}
|
|
6719
6699
|
}
|
|
6720
6700
|
}
|
|
6721
|
-
if (point) {
|
|
6722
|
-
const shapesById = new Map(shapes.map((shape) => [shape.id, shape]));
|
|
6723
|
-
const rootShapesFromContent = compact(rootShapeIds.map((id) => shapesById.get(id)));
|
|
6724
|
-
if (rootShapesFromContent.length > 0) {
|
|
6725
|
-
const targetParent = this.getShapeAtPoint(point, {
|
|
6726
|
-
hitInside: true,
|
|
6727
|
-
hitFrameInside: true,
|
|
6728
|
-
hitLocked: true,
|
|
6729
|
-
filter: (shape) => {
|
|
6730
|
-
const util = this.getShapeUtil(shape);
|
|
6731
|
-
if (!util.canReceiveNewChildrenOfType) return false;
|
|
6732
|
-
return rootShapesFromContent.every(
|
|
6733
|
-
(rootShape) => util.canReceiveNewChildrenOfType(shape, rootShape.type)
|
|
6734
|
-
);
|
|
6735
|
-
}
|
|
6736
|
-
});
|
|
6737
|
-
pasteParentId = targetParent ? targetParent.id : currentPageId;
|
|
6738
|
-
}
|
|
6739
|
-
}
|
|
6740
6701
|
let isDuplicating = false;
|
|
6741
6702
|
if (!isPageId(pasteParentId)) {
|
|
6742
6703
|
const parent = this.getShape(pasteParentId);
|
|
@@ -6981,7 +6942,60 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6981
6942
|
height
|
|
6982
6943
|
};
|
|
6983
6944
|
}
|
|
6984
|
-
|
|
6945
|
+
/**
|
|
6946
|
+
* Update the input points from a pointer, pinch, or wheel event.
|
|
6947
|
+
*
|
|
6948
|
+
* @param info - The event info.
|
|
6949
|
+
*/
|
|
6950
|
+
_updateInputsFromEvent(info) {
|
|
6951
|
+
const {
|
|
6952
|
+
pointerVelocity,
|
|
6953
|
+
previousScreenPoint,
|
|
6954
|
+
previousPagePoint,
|
|
6955
|
+
currentScreenPoint,
|
|
6956
|
+
currentPagePoint,
|
|
6957
|
+
originScreenPoint,
|
|
6958
|
+
originPagePoint
|
|
6959
|
+
} = this.inputs;
|
|
6960
|
+
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
6961
|
+
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
|
|
6962
|
+
const sx = info.point.x - screenBounds.x;
|
|
6963
|
+
const sy = info.point.y - screenBounds.y;
|
|
6964
|
+
const sz = info.point.z ?? 0.5;
|
|
6965
|
+
previousScreenPoint.setTo(currentScreenPoint);
|
|
6966
|
+
previousPagePoint.setTo(currentPagePoint);
|
|
6967
|
+
currentScreenPoint.set(sx, sy);
|
|
6968
|
+
const nx = sx / cz - cx;
|
|
6969
|
+
const ny = sy / cz - cy;
|
|
6970
|
+
if (isFinite(nx) && isFinite(ny)) {
|
|
6971
|
+
currentPagePoint.set(nx, ny, sz);
|
|
6972
|
+
}
|
|
6973
|
+
this.inputs.isPen = info.type === "pointer" && info.isPen;
|
|
6974
|
+
if (info.name === "pointer_down" || this.inputs.isPinching) {
|
|
6975
|
+
pointerVelocity.set(0, 0);
|
|
6976
|
+
originScreenPoint.setTo(currentScreenPoint);
|
|
6977
|
+
originPagePoint.setTo(currentPagePoint);
|
|
6978
|
+
}
|
|
6979
|
+
this.run(
|
|
6980
|
+
() => {
|
|
6981
|
+
this.store.put([
|
|
6982
|
+
{
|
|
6983
|
+
id: TLPOINTER_ID,
|
|
6984
|
+
typeName: "pointer",
|
|
6985
|
+
x: currentPagePoint.x,
|
|
6986
|
+
y: currentPagePoint.y,
|
|
6987
|
+
lastActivityTimestamp: (
|
|
6988
|
+
// If our pointer moved only because we're following some other user, then don't
|
|
6989
|
+
// update our last activity timestamp; otherwise, update it to the current timestamp.
|
|
6990
|
+
(info.type === "pointer" && info.pointerId === INTERNAL_POINTER_IDS.CAMERA_MOVE ? this.store.unsafeGetWithoutCapture(TLPOINTER_ID)?.lastActivityTimestamp ?? this._tickManager.now : this._tickManager.now)
|
|
6991
|
+
),
|
|
6992
|
+
meta: {}
|
|
6993
|
+
}
|
|
6994
|
+
]);
|
|
6995
|
+
},
|
|
6996
|
+
{ history: "ignore" }
|
|
6997
|
+
);
|
|
6998
|
+
}
|
|
6985
6999
|
/**
|
|
6986
7000
|
* Dispatch a cancel event.
|
|
6987
7001
|
*
|
|
@@ -7046,19 +7060,18 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7046
7060
|
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7047
7061
|
// we need to convert back into true screen space first. we should fix this...
|
|
7048
7062
|
Vec.Add(
|
|
7049
|
-
this.inputs.
|
|
7063
|
+
this.inputs.currentScreenPoint,
|
|
7050
7064
|
this.store.unsafeGetWithoutCapture(TLINSTANCE_ID).screenBounds
|
|
7051
7065
|
),
|
|
7052
7066
|
pointerId: options?.pointerId ?? 0,
|
|
7053
7067
|
button: options?.button ?? 0,
|
|
7054
|
-
isPen: options?.isPen ?? this.inputs.
|
|
7055
|
-
shiftKey: options?.shiftKey ?? this.inputs.
|
|
7056
|
-
altKey: options?.altKey ?? this.inputs.
|
|
7057
|
-
ctrlKey: options?.ctrlKey ?? this.inputs.
|
|
7058
|
-
metaKey: options?.metaKey ?? this.inputs.
|
|
7059
|
-
accelKey:
|
|
7068
|
+
isPen: options?.isPen ?? this.inputs.isPen,
|
|
7069
|
+
shiftKey: options?.shiftKey ?? this.inputs.shiftKey,
|
|
7070
|
+
altKey: options?.altKey ?? this.inputs.altKey,
|
|
7071
|
+
ctrlKey: options?.ctrlKey ?? this.inputs.ctrlKey,
|
|
7072
|
+
metaKey: options?.metaKey ?? this.inputs.metaKey,
|
|
7073
|
+
accelKey: options?.accelKey ?? isAccelKey(this.inputs)
|
|
7060
7074
|
};
|
|
7061
|
-
event.accelKey = options?.accelKey ?? this.inputs.getAccelKey();
|
|
7062
7075
|
if (options?.immediate) {
|
|
7063
7076
|
this._flushEventForTick(event);
|
|
7064
7077
|
} else {
|
|
@@ -7374,58 +7387,58 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7374
7387
|
this._clickManager.cancelDoubleClickTimeout();
|
|
7375
7388
|
}
|
|
7376
7389
|
_setShiftKeyTimeout() {
|
|
7377
|
-
this.inputs.
|
|
7390
|
+
this.inputs.shiftKey = false;
|
|
7378
7391
|
this.dispatch({
|
|
7379
7392
|
type: "keyboard",
|
|
7380
7393
|
name: "key_up",
|
|
7381
7394
|
key: "Shift",
|
|
7382
|
-
shiftKey: this.inputs.
|
|
7383
|
-
ctrlKey: this.inputs.
|
|
7384
|
-
altKey: this.inputs.
|
|
7385
|
-
metaKey: this.inputs.
|
|
7386
|
-
accelKey: this.inputs
|
|
7395
|
+
shiftKey: this.inputs.shiftKey,
|
|
7396
|
+
ctrlKey: this.inputs.ctrlKey,
|
|
7397
|
+
altKey: this.inputs.altKey,
|
|
7398
|
+
metaKey: this.inputs.metaKey,
|
|
7399
|
+
accelKey: isAccelKey(this.inputs),
|
|
7387
7400
|
code: "ShiftLeft"
|
|
7388
7401
|
});
|
|
7389
7402
|
}
|
|
7390
7403
|
_setAltKeyTimeout() {
|
|
7391
|
-
this.inputs.
|
|
7404
|
+
this.inputs.altKey = false;
|
|
7392
7405
|
this.dispatch({
|
|
7393
7406
|
type: "keyboard",
|
|
7394
7407
|
name: "key_up",
|
|
7395
7408
|
key: "Alt",
|
|
7396
|
-
shiftKey: this.inputs.
|
|
7397
|
-
ctrlKey: this.inputs.
|
|
7398
|
-
altKey: this.inputs.
|
|
7399
|
-
metaKey: this.inputs.
|
|
7400
|
-
accelKey: this.inputs
|
|
7409
|
+
shiftKey: this.inputs.shiftKey,
|
|
7410
|
+
ctrlKey: this.inputs.ctrlKey,
|
|
7411
|
+
altKey: this.inputs.altKey,
|
|
7412
|
+
metaKey: this.inputs.metaKey,
|
|
7413
|
+
accelKey: isAccelKey(this.inputs),
|
|
7401
7414
|
code: "AltLeft"
|
|
7402
7415
|
});
|
|
7403
7416
|
}
|
|
7404
7417
|
_setCtrlKeyTimeout() {
|
|
7405
|
-
this.inputs.
|
|
7418
|
+
this.inputs.ctrlKey = false;
|
|
7406
7419
|
this.dispatch({
|
|
7407
7420
|
type: "keyboard",
|
|
7408
7421
|
name: "key_up",
|
|
7409
7422
|
key: "Ctrl",
|
|
7410
|
-
shiftKey: this.inputs.
|
|
7411
|
-
ctrlKey: this.inputs.
|
|
7412
|
-
altKey: this.inputs.
|
|
7413
|
-
metaKey: this.inputs.
|
|
7414
|
-
accelKey: this.inputs
|
|
7423
|
+
shiftKey: this.inputs.shiftKey,
|
|
7424
|
+
ctrlKey: this.inputs.ctrlKey,
|
|
7425
|
+
altKey: this.inputs.altKey,
|
|
7426
|
+
metaKey: this.inputs.metaKey,
|
|
7427
|
+
accelKey: isAccelKey(this.inputs),
|
|
7415
7428
|
code: "ControlLeft"
|
|
7416
7429
|
});
|
|
7417
7430
|
}
|
|
7418
7431
|
_setMetaKeyTimeout() {
|
|
7419
|
-
this.inputs.
|
|
7432
|
+
this.inputs.metaKey = false;
|
|
7420
7433
|
this.dispatch({
|
|
7421
7434
|
type: "keyboard",
|
|
7422
7435
|
name: "key_up",
|
|
7423
7436
|
key: "Meta",
|
|
7424
|
-
shiftKey: this.inputs.
|
|
7425
|
-
ctrlKey: this.inputs.
|
|
7426
|
-
altKey: this.inputs.
|
|
7427
|
-
metaKey: this.inputs.
|
|
7428
|
-
accelKey: this.inputs
|
|
7437
|
+
shiftKey: this.inputs.shiftKey,
|
|
7438
|
+
ctrlKey: this.inputs.ctrlKey,
|
|
7439
|
+
altKey: this.inputs.altKey,
|
|
7440
|
+
metaKey: this.inputs.metaKey,
|
|
7441
|
+
accelKey: isAccelKey(this.inputs),
|
|
7429
7442
|
code: "MetaLeft"
|
|
7430
7443
|
});
|
|
7431
7444
|
}
|
|
@@ -7496,47 +7509,47 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7496
7509
|
const { type } = info;
|
|
7497
7510
|
if (info.type === "misc") {
|
|
7498
7511
|
if (info.name === "cancel" || info.name === "complete") {
|
|
7499
|
-
this.inputs.
|
|
7500
|
-
if (this.inputs.
|
|
7501
|
-
this.inputs.
|
|
7502
|
-
this.inputs.
|
|
7512
|
+
this.inputs.isDragging = false;
|
|
7513
|
+
if (this.inputs.isPanning) {
|
|
7514
|
+
this.inputs.isPanning = false;
|
|
7515
|
+
this.inputs.isSpacebarPanning = false;
|
|
7503
7516
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7504
7517
|
}
|
|
7505
7518
|
}
|
|
7506
7519
|
this.root.handleEvent(info);
|
|
7507
|
-
this.emit("event", info);
|
|
7508
7520
|
return;
|
|
7509
7521
|
}
|
|
7510
7522
|
if (info.shiftKey) {
|
|
7511
7523
|
clearTimeout(this._shiftKeyTimeout);
|
|
7512
7524
|
this._shiftKeyTimeout = -1;
|
|
7513
|
-
inputs.
|
|
7514
|
-
} else if (!info.shiftKey && inputs.
|
|
7525
|
+
inputs.shiftKey = true;
|
|
7526
|
+
} else if (!info.shiftKey && inputs.shiftKey && this._shiftKeyTimeout === -1) {
|
|
7515
7527
|
this._shiftKeyTimeout = this.timers.setTimeout(this._setShiftKeyTimeout, 150);
|
|
7516
7528
|
}
|
|
7517
7529
|
if (info.altKey) {
|
|
7518
7530
|
clearTimeout(this._altKeyTimeout);
|
|
7519
7531
|
this._altKeyTimeout = -1;
|
|
7520
|
-
inputs.
|
|
7521
|
-
} else if (!info.altKey && inputs.
|
|
7532
|
+
inputs.altKey = true;
|
|
7533
|
+
} else if (!info.altKey && inputs.altKey && this._altKeyTimeout === -1) {
|
|
7522
7534
|
this._altKeyTimeout = this.timers.setTimeout(this._setAltKeyTimeout, 150);
|
|
7523
7535
|
}
|
|
7524
7536
|
if (info.ctrlKey) {
|
|
7525
7537
|
clearTimeout(this._ctrlKeyTimeout);
|
|
7526
7538
|
this._ctrlKeyTimeout = -1;
|
|
7527
|
-
inputs.
|
|
7528
|
-
} else if (!info.ctrlKey && inputs.
|
|
7539
|
+
inputs.ctrlKey = true;
|
|
7540
|
+
} else if (!info.ctrlKey && inputs.ctrlKey && this._ctrlKeyTimeout === -1) {
|
|
7529
7541
|
this._ctrlKeyTimeout = this.timers.setTimeout(this._setCtrlKeyTimeout, 150);
|
|
7530
7542
|
}
|
|
7531
7543
|
if (info.metaKey) {
|
|
7532
7544
|
clearTimeout(this._metaKeyTimeout);
|
|
7533
7545
|
this._metaKeyTimeout = -1;
|
|
7534
|
-
inputs.
|
|
7535
|
-
} else if (!info.metaKey && inputs.
|
|
7546
|
+
inputs.metaKey = true;
|
|
7547
|
+
} else if (!info.metaKey && inputs.metaKey && this._metaKeyTimeout === -1) {
|
|
7536
7548
|
this._metaKeyTimeout = this.timers.setTimeout(this._setMetaKeyTimeout, 150);
|
|
7537
7549
|
}
|
|
7538
|
-
|
|
7539
|
-
|
|
7550
|
+
const { originPagePoint, currentPagePoint } = inputs;
|
|
7551
|
+
if (!inputs.isPointing) {
|
|
7552
|
+
inputs.isDragging = false;
|
|
7540
7553
|
}
|
|
7541
7554
|
const instanceState = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
7542
7555
|
const pageState = this.store.get(this._getCurrentPageStateId());
|
|
@@ -7545,23 +7558,23 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7545
7558
|
case "pinch": {
|
|
7546
7559
|
if (cameraOptions.isLocked) return;
|
|
7547
7560
|
clearTimeout(this._longPressTimeout);
|
|
7548
|
-
this.
|
|
7561
|
+
this._updateInputsFromEvent(info);
|
|
7549
7562
|
switch (info.name) {
|
|
7550
7563
|
case "pinch_start": {
|
|
7551
|
-
if (inputs.
|
|
7552
|
-
if (!inputs.
|
|
7564
|
+
if (inputs.isPinching) return;
|
|
7565
|
+
if (!inputs.isEditing) {
|
|
7566
|
+
this._pinchStart = this.getCamera().z;
|
|
7553
7567
|
if (!this._selectedShapeIdsAtPointerDown.length) {
|
|
7554
7568
|
this._selectedShapeIdsAtPointerDown = [...pageState.selectedShapeIds];
|
|
7555
7569
|
}
|
|
7556
7570
|
this._didPinch = true;
|
|
7557
|
-
inputs.
|
|
7571
|
+
inputs.isPinching = true;
|
|
7558
7572
|
this.interrupt();
|
|
7559
7573
|
}
|
|
7560
|
-
this.emit("event", info);
|
|
7561
7574
|
return;
|
|
7562
7575
|
}
|
|
7563
7576
|
case "pinch": {
|
|
7564
|
-
if (!inputs.
|
|
7577
|
+
if (!inputs.isPinching) return;
|
|
7565
7578
|
const {
|
|
7566
7579
|
point: { z = 1 },
|
|
7567
7580
|
delta: { x: dx, y: dy }
|
|
@@ -7585,12 +7598,11 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7585
7598
|
),
|
|
7586
7599
|
{ immediate: true }
|
|
7587
7600
|
);
|
|
7588
|
-
this.emit("event", info);
|
|
7589
7601
|
return;
|
|
7590
7602
|
}
|
|
7591
7603
|
case "pinch_end": {
|
|
7592
|
-
if (!inputs.
|
|
7593
|
-
inputs.
|
|
7604
|
+
if (!inputs.isPinching) return this;
|
|
7605
|
+
inputs.isPinching = false;
|
|
7594
7606
|
const { _selectedShapeIdsAtPointerDown: shapesToReselect } = this;
|
|
7595
7607
|
this.setSelectedShapes(this._selectedShapeIdsAtPointerDown);
|
|
7596
7608
|
this._selectedShapeIdsAtPointerDown = [];
|
|
@@ -7604,14 +7616,13 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7604
7616
|
});
|
|
7605
7617
|
}
|
|
7606
7618
|
}
|
|
7607
|
-
this.emit("event", info);
|
|
7608
7619
|
return;
|
|
7609
7620
|
}
|
|
7610
7621
|
}
|
|
7611
7622
|
}
|
|
7612
7623
|
case "wheel": {
|
|
7613
7624
|
if (cameraOptions.isLocked) return;
|
|
7614
|
-
this.
|
|
7625
|
+
this._updateInputsFromEvent(info);
|
|
7615
7626
|
const { panSpeed, zoomSpeed } = cameraOptions;
|
|
7616
7627
|
let wheelBehavior = cameraOptions.wheelBehavior;
|
|
7617
7628
|
const inputMode = this.user.getUserPreferences().inputMode;
|
|
@@ -7629,7 +7640,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7629
7640
|
if (info.ctrlKey) behavior = wheelBehavior === "pan" ? "zoom" : "pan";
|
|
7630
7641
|
switch (behavior) {
|
|
7631
7642
|
case "zoom": {
|
|
7632
|
-
const { x, y } = this.inputs.
|
|
7643
|
+
const { x, y } = this.inputs.currentScreenPoint;
|
|
7633
7644
|
let delta = dz;
|
|
7634
7645
|
if (wheelBehavior === "zoom") {
|
|
7635
7646
|
if (Math.abs(dy) > 10) {
|
|
@@ -7643,8 +7654,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7643
7654
|
immediate: true
|
|
7644
7655
|
});
|
|
7645
7656
|
this.maybeTrackPerformance("Zooming");
|
|
7646
|
-
this.root.handleEvent(info);
|
|
7647
|
-
this.emit("event", info);
|
|
7648
7657
|
return;
|
|
7649
7658
|
}
|
|
7650
7659
|
case "pan": {
|
|
@@ -7652,8 +7661,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7652
7661
|
immediate: true
|
|
7653
7662
|
});
|
|
7654
7663
|
this.maybeTrackPerformance("Panning");
|
|
7655
|
-
this.root.handleEvent(info);
|
|
7656
|
-
this.emit("event", info);
|
|
7657
7664
|
return;
|
|
7658
7665
|
}
|
|
7659
7666
|
}
|
|
@@ -7661,14 +7668,14 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7661
7668
|
break;
|
|
7662
7669
|
}
|
|
7663
7670
|
case "pointer": {
|
|
7664
|
-
if (inputs.
|
|
7665
|
-
this.
|
|
7671
|
+
if (inputs.isPinching) return;
|
|
7672
|
+
this._updateInputsFromEvent(info);
|
|
7666
7673
|
const { isPen } = info;
|
|
7667
7674
|
const { isPenMode } = instanceState;
|
|
7668
7675
|
switch (info.name) {
|
|
7669
7676
|
case "pointer_down": {
|
|
7670
7677
|
if (isPenMode && !isPen) return;
|
|
7671
|
-
if (!this.inputs.
|
|
7678
|
+
if (!this.inputs.isPanning) {
|
|
7672
7679
|
this._longPressTimeout = this.timers.setTimeout(() => {
|
|
7673
7680
|
const vsb = this.getViewportScreenBounds();
|
|
7674
7681
|
this.dispatch({
|
|
@@ -7677,7 +7684,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7677
7684
|
// viewport bounds, and will be again when this event is handled...
|
|
7678
7685
|
// so we need to counter-adjust from the stored value so that the
|
|
7679
7686
|
// new value is set correctly.
|
|
7680
|
-
point: this.inputs.
|
|
7687
|
+
point: this.inputs.originScreenPoint.clone().addXY(vsb.x, vsb.y),
|
|
7681
7688
|
name: "long_press"
|
|
7682
7689
|
});
|
|
7683
7690
|
}, this.options.longPressDurationMs);
|
|
@@ -7685,21 +7692,21 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7685
7692
|
this._selectedShapeIdsAtPointerDown = this.getSelectedShapeIds();
|
|
7686
7693
|
if (info.button === LEFT_MOUSE_BUTTON) this.capturedPointerId = info.pointerId;
|
|
7687
7694
|
inputs.buttons.add(info.button);
|
|
7688
|
-
inputs.
|
|
7689
|
-
inputs.
|
|
7695
|
+
inputs.isPointing = true;
|
|
7696
|
+
inputs.isDragging = false;
|
|
7690
7697
|
if (!isPenMode && isPen) this.updateInstanceState({ isPenMode: true });
|
|
7691
7698
|
if (info.button === STYLUS_ERASER_BUTTON) {
|
|
7692
7699
|
this._restoreToolId = this.getCurrentToolId();
|
|
7693
7700
|
this.complete();
|
|
7694
7701
|
this.setCurrentTool("eraser");
|
|
7695
7702
|
} else if (info.button === MIDDLE_MOUSE_BUTTON) {
|
|
7696
|
-
if (!this.inputs.
|
|
7703
|
+
if (!this.inputs.isPanning) {
|
|
7697
7704
|
this._prevCursor = this.getInstanceState().cursor.type;
|
|
7698
7705
|
}
|
|
7699
|
-
this.inputs.
|
|
7706
|
+
this.inputs.isPanning = true;
|
|
7700
7707
|
clearTimeout(this._longPressTimeout);
|
|
7701
7708
|
}
|
|
7702
|
-
if (this.inputs.
|
|
7709
|
+
if (this.inputs.isPanning) {
|
|
7703
7710
|
this.stopCameraAnimation();
|
|
7704
7711
|
this.setCursor({ type: "grabbing", rotation: 0 });
|
|
7705
7712
|
return this;
|
|
@@ -7709,9 +7716,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7709
7716
|
case "pointer_move": {
|
|
7710
7717
|
if (!isPen && isPenMode) return;
|
|
7711
7718
|
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
|
|
7712
|
-
if (this.inputs.
|
|
7713
|
-
const currentScreenPoint = this.inputs
|
|
7714
|
-
const previousScreenPoint = this.inputs.getPreviousScreenPoint();
|
|
7719
|
+
if (this.inputs.isPanning && this.inputs.isPointing) {
|
|
7720
|
+
const { currentScreenPoint, previousScreenPoint } = this.inputs;
|
|
7715
7721
|
const offset = Vec.Sub(currentScreenPoint, previousScreenPoint);
|
|
7716
7722
|
this.setCamera(new Vec(cx + offset.x / cz, cy + offset.y / cz, cz), {
|
|
7717
7723
|
immediate: true
|
|
@@ -7719,15 +7725,15 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7719
7725
|
this.maybeTrackPerformance("Panning");
|
|
7720
7726
|
return;
|
|
7721
7727
|
}
|
|
7722
|
-
if (inputs.
|
|
7723
|
-
inputs.
|
|
7728
|
+
if (inputs.isPointing && !inputs.isDragging && Vec.Dist2(originPagePoint, currentPagePoint) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {
|
|
7729
|
+
inputs.isDragging = true;
|
|
7724
7730
|
clearTimeout(this._longPressTimeout);
|
|
7725
7731
|
}
|
|
7726
7732
|
break;
|
|
7727
7733
|
}
|
|
7728
7734
|
case "pointer_up": {
|
|
7729
|
-
inputs.
|
|
7730
|
-
inputs.
|
|
7735
|
+
inputs.isDragging = false;
|
|
7736
|
+
inputs.isPointing = false;
|
|
7731
7737
|
clearTimeout(this._longPressTimeout);
|
|
7732
7738
|
inputs.buttons.delete(info.button);
|
|
7733
7739
|
if (instanceState.isPenMode && !isPen) return;
|
|
@@ -7735,12 +7741,12 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7735
7741
|
this.capturedPointerId = null;
|
|
7736
7742
|
info.button = 0;
|
|
7737
7743
|
}
|
|
7738
|
-
if (inputs.
|
|
7744
|
+
if (inputs.isPanning) {
|
|
7739
7745
|
if (!inputs.keys.has("Space")) {
|
|
7740
|
-
inputs.
|
|
7741
|
-
inputs.
|
|
7746
|
+
inputs.isPanning = false;
|
|
7747
|
+
inputs.isSpacebarPanning = false;
|
|
7742
7748
|
}
|
|
7743
|
-
const slideDirection = this.inputs.
|
|
7749
|
+
const slideDirection = this.inputs.pointerVelocity;
|
|
7744
7750
|
const slideSpeed = Math.min(2, slideDirection.len());
|
|
7745
7751
|
switch (info.button) {
|
|
7746
7752
|
case LEFT_MOUSE_BUTTON: {
|
|
@@ -7777,58 +7783,51 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7777
7783
|
switch (info.name) {
|
|
7778
7784
|
case "key_down": {
|
|
7779
7785
|
inputs.keys.add(info.code);
|
|
7780
|
-
if (
|
|
7781
|
-
if (
|
|
7782
|
-
|
|
7783
|
-
this._prevCursor = instanceState.cursor.type;
|
|
7784
|
-
}
|
|
7785
|
-
this.inputs.setIsPanning(true);
|
|
7786
|
-
this.inputs.setIsSpacebarPanning(true);
|
|
7787
|
-
clearTimeout(this._longPressTimeout);
|
|
7788
|
-
this.setCursor({
|
|
7789
|
-
type: this.inputs.getIsPointing() ? "grabbing" : "grab",
|
|
7790
|
-
rotation: 0
|
|
7791
|
-
});
|
|
7786
|
+
if (info.code === "Space" && !info.ctrlKey) {
|
|
7787
|
+
if (!this.inputs.isPanning) {
|
|
7788
|
+
this._prevCursor = instanceState.cursor.type;
|
|
7792
7789
|
}
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
case "ArrowDown": {
|
|
7805
|
-
offset = new Vec(0, 1);
|
|
7806
|
-
break;
|
|
7807
|
-
}
|
|
7808
|
-
case "ArrowLeft": {
|
|
7809
|
-
offset = new Vec(-1, 0);
|
|
7810
|
-
break;
|
|
7811
|
-
}
|
|
7790
|
+
this.inputs.isPanning = true;
|
|
7791
|
+
this.inputs.isSpacebarPanning = true;
|
|
7792
|
+
clearTimeout(this._longPressTimeout);
|
|
7793
|
+
this.setCursor({ type: this.inputs.isPointing ? "grabbing" : "grab", rotation: 0 });
|
|
7794
|
+
}
|
|
7795
|
+
if (this.inputs.isSpacebarPanning) {
|
|
7796
|
+
let offset;
|
|
7797
|
+
switch (info.code) {
|
|
7798
|
+
case "ArrowUp": {
|
|
7799
|
+
offset = new Vec(0, -1);
|
|
7800
|
+
break;
|
|
7812
7801
|
}
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
7802
|
+
case "ArrowRight": {
|
|
7803
|
+
offset = new Vec(1, 0);
|
|
7804
|
+
break;
|
|
7817
7805
|
}
|
|
7806
|
+
case "ArrowDown": {
|
|
7807
|
+
offset = new Vec(0, 1);
|
|
7808
|
+
break;
|
|
7809
|
+
}
|
|
7810
|
+
case "ArrowLeft": {
|
|
7811
|
+
offset = new Vec(-1, 0);
|
|
7812
|
+
break;
|
|
7813
|
+
}
|
|
7814
|
+
}
|
|
7815
|
+
if (offset) {
|
|
7816
|
+
const bounds = this.getViewportPageBounds();
|
|
7817
|
+
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
|
|
7818
|
+
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
7818
7819
|
}
|
|
7819
7820
|
}
|
|
7820
7821
|
break;
|
|
7821
7822
|
}
|
|
7822
7823
|
case "key_up": {
|
|
7823
7824
|
inputs.keys.delete(info.code);
|
|
7824
|
-
if (
|
|
7825
|
-
if (
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7831
|
-
}
|
|
7825
|
+
if (info.code === "Space") {
|
|
7826
|
+
if (this.inputs.buttons.has(MIDDLE_MOUSE_BUTTON)) {
|
|
7827
|
+
} else {
|
|
7828
|
+
this.inputs.isPanning = false;
|
|
7829
|
+
this.inputs.isSpacebarPanning = false;
|
|
7830
|
+
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7832
7831
|
}
|
|
7833
7832
|
}
|
|
7834
7833
|
break;
|
|
@@ -7881,8 +7880,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7881
7880
|
}
|
|
7882
7881
|
_init = __decoratorStart(_a);
|
|
7883
7882
|
__decorateElement(_init, 1, "getIsShapeHiddenCache", _getIsShapeHiddenCache_dec, Editor);
|
|
7884
|
-
__decorateElement(_init, 1, "
|
|
7885
|
-
__decorateElement(_init, 1, "
|
|
7883
|
+
__decorateElement(_init, 1, "getCanUndo", _getCanUndo_dec, Editor);
|
|
7884
|
+
__decorateElement(_init, 1, "getCanRedo", _getCanRedo_dec, Editor);
|
|
7886
7885
|
__decorateElement(_init, 1, "getPath", _getPath_dec, Editor);
|
|
7887
7886
|
__decorateElement(_init, 1, "getCurrentTool", _getCurrentTool_dec, Editor);
|
|
7888
7887
|
__decorateElement(_init, 1, "getCurrentToolId", _getCurrentToolId_dec, Editor);
|
|
@@ -7917,9 +7916,6 @@ __decorateElement(_init, 1, "getCamera", _getCamera_dec, Editor);
|
|
|
7917
7916
|
__decorateElement(_init, 1, "getViewportPageBoundsForFollowing", _getViewportPageBoundsForFollowing_dec, Editor);
|
|
7918
7917
|
__decorateElement(_init, 1, "getCameraForFollowing", _getCameraForFollowing_dec, Editor);
|
|
7919
7918
|
__decorateElement(_init, 1, "getZoomLevel", _getZoomLevel_dec, Editor);
|
|
7920
|
-
__decorateElement(_init, 1, "getDebouncedZoomLevel", _getDebouncedZoomLevel_dec, Editor);
|
|
7921
|
-
__decorateElement(_init, 1, "_getAboveDebouncedZoomThreshold", __getAboveDebouncedZoomThreshold_dec, Editor);
|
|
7922
|
-
__decorateElement(_init, 1, "getEfficientZoomLevel", _getEfficientZoomLevel_dec, Editor);
|
|
7923
7919
|
__decorateElement(_init, 1, "getViewportScreenBounds", _getViewportScreenBounds_dec, Editor);
|
|
7924
7920
|
__decorateElement(_init, 1, "getViewportScreenCenter", _getViewportScreenCenter_dec, Editor);
|
|
7925
7921
|
__decorateElement(_init, 1, "getViewportPageBounds", _getViewportPageBounds_dec, Editor);
|