@tldraw/editor 3.16.0-internal.a478398270c6 → 3.16.0-internal.f8b97f0c414f
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 +350 -142
- package/dist-cjs/index.js +13 -6
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +10 -8
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/SVGContainer.js +1 -1
- package/dist-cjs/lib/components/SVGContainer.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +11 -36
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultBrush.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +15 -24
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCursor.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultGrid.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultGrid.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultHandles.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultHandles.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +53 -0
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +7 -0
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js +27 -15
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +3 -3
- package/dist-cjs/lib/config/TLUserPreferences.js +15 -3
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +174 -180
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +14 -4
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/BaseBoxShapeUtil.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +23 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +20 -1
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +35 -16
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +44 -35
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useDocumentEvents.js +5 -5
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditor.js +1 -4
- package/dist-cjs/lib/hooks/useEditor.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -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/useHandleEvents.js +3 -3
- package/dist-cjs/lib/hooks/useHandleEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useSelectionEvents.js +4 -4
- package/dist-cjs/lib/hooks/useSelectionEvents.js.map +2 -2
- package/dist-cjs/lib/{utils/nearestMultiple.js → hooks/useStateAttribute.js} +15 -14
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
- package/dist-cjs/lib/license/LicenseManager.js +140 -53
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +39 -1
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +75 -13
- package/dist-cjs/lib/license/Watermark.js.map +3 -3
- package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
- package/dist-cjs/lib/options.js +7 -0
- 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/Vec.js +0 -4
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +3 -1
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +50 -20
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Group2d.js +8 -1
- package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/geometry-constants.js +2 -2
- package/dist-cjs/lib/primitives/geometry/geometry-constants.js.map +2 -2
- package/dist-cjs/lib/primitives/intersect.js +4 -4
- package/dist-cjs/lib/primitives/intersect.js.map +2 -2
- package/dist-cjs/lib/primitives/utils.js +4 -0
- package/dist-cjs/lib/primitives/utils.js.map +2 -2
- package/dist-cjs/lib/utils/EditorAtom.js +45 -0
- package/dist-cjs/lib/utils/EditorAtom.js.map +7 -0
- package/dist-cjs/lib/utils/dom.js +12 -1
- package/dist-cjs/lib/utils/dom.js.map +2 -2
- package/dist-cjs/lib/utils/getPointerInfo.js +2 -2
- package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +2 -35
- package/dist-cjs/lib/utils/reparenting.js.map +3 -3
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +0 -1
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.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 +350 -142
- package/dist-esm/index.mjs +24 -8
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +11 -9
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/SVGContainer.mjs +1 -1
- package/dist-esm/lib/components/SVGContainer.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +11 -36
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +16 -25
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultGrid.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultGrid.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultHandles.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultHandles.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +23 -0
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +7 -0
- package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultSpinner.mjs +17 -15
- package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs +15 -3
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +174 -180
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +14 -4
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/BaseBoxShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +23 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +20 -1
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +36 -16
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +47 -37
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +11 -6
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditor.mjs +1 -4
- package/dist-esm/lib/hooks/useEditor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +4 -0
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +2 -3
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useHandleEvents.mjs +9 -4
- package/dist-esm/lib/hooks/useHandleEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useSelectionEvents.mjs +6 -5
- package/dist-esm/lib/hooks/useSelectionEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useStateAttribute.mjs +15 -0
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
- package/dist-esm/lib/license/LicenseManager.mjs +141 -54
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +39 -2
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +76 -14
- package/dist-esm/lib/license/Watermark.mjs.map +3 -3
- package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +7 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +4 -1
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +0 -4
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +3 -1
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +53 -21
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +8 -1
- package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/geometry-constants.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/geometry-constants.mjs.map +2 -2
- package/dist-esm/lib/primitives/intersect.mjs +5 -5
- package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
- package/dist-esm/lib/primitives/utils.mjs +4 -0
- package/dist-esm/lib/primitives/utils.mjs.map +2 -2
- package/dist-esm/lib/utils/EditorAtom.mjs +25 -0
- package/dist-esm/lib/utils/EditorAtom.mjs.map +7 -0
- package/dist-esm/lib/utils/dom.mjs +12 -1
- package/dist-esm/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/lib/utils/getPointerInfo.mjs +2 -2
- package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +3 -40
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +0 -1
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +327 -315
- package/package.json +16 -38
- package/src/index.ts +19 -10
- package/src/lib/TldrawEditor.tsx +16 -21
- package/src/lib/components/MenuClickCapture.tsx +0 -8
- package/src/lib/components/SVGContainer.tsx +1 -1
- package/src/lib/components/Shape.tsx +12 -33
- package/src/lib/components/default-components/DefaultBrush.tsx +1 -1
- package/src/lib/components/default-components/DefaultCanvas.tsx +13 -24
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +2 -2
- package/src/lib/components/default-components/DefaultCursor.tsx +1 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/components/default-components/DefaultGrid.tsx +1 -1
- package/src/lib/components/default-components/DefaultHandles.tsx +5 -1
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +6 -2
- package/src/lib/components/default-components/DefaultShapeWrapper.tsx +35 -0
- package/src/lib/components/default-components/DefaultSnapIndictor.tsx +1 -1
- package/src/lib/components/default-components/DefaultSpinner.tsx +12 -12
- package/src/lib/config/TLUserPreferences.ts +15 -1
- package/src/lib/editor/Editor.test.ts +512 -8
- package/src/lib/editor/Editor.ts +252 -267
- package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
- package/src/lib/editor/derivations/parentsToChildren.ts +1 -1
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +38 -27
- package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +55 -26
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +14 -1
- package/src/lib/editor/shapes/BaseBoxShapeUtil.tsx +2 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +108 -8
- package/src/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.ts +2 -1
- package/src/lib/editor/tools/StateNode.test.ts +285 -0
- package/src/lib/editor/tools/StateNode.ts +27 -1
- package/src/lib/editor/types/misc-types.ts +73 -7
- package/src/lib/exports/getSvgJsx.test.ts +874 -0
- package/src/lib/exports/getSvgJsx.tsx +78 -21
- package/src/lib/hooks/useCanvasEvents.ts +60 -47
- package/src/lib/hooks/useDocumentEvents.ts +11 -6
- package/src/lib/hooks/useEditor.tsx +6 -5
- package/src/lib/hooks/useEditorComponents.tsx +8 -2
- package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +2 -2
- package/src/lib/hooks/useGestureEvents.ts +2 -2
- package/src/lib/hooks/useHandleEvents.ts +9 -4
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
- package/src/lib/hooks/useSelectionEvents.ts +6 -5
- package/src/lib/hooks/useStateAttribute.ts +15 -0
- package/src/lib/license/LicenseManager.test.ts +724 -383
- package/src/lib/license/LicenseManager.ts +201 -58
- package/src/lib/license/LicenseProvider.tsx +74 -2
- package/src/lib/license/Watermark.test.tsx +2 -1
- package/src/lib/license/Watermark.tsx +81 -14
- package/src/lib/license/useLicenseManagerState.ts +2 -2
- package/src/lib/options.ts +8 -0
- package/src/lib/primitives/Box.test.ts +126 -0
- package/src/lib/primitives/Box.ts +10 -1
- package/src/lib/primitives/Vec.ts +0 -5
- package/src/lib/primitives/geometry/Arc2d.ts +2 -2
- package/src/lib/primitives/geometry/Circle2d.ts +2 -2
- package/src/lib/primitives/geometry/CubicBezier2d.ts +4 -1
- package/src/lib/primitives/geometry/Ellipse2d.ts +2 -2
- package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
- package/src/lib/primitives/geometry/Geometry2d.ts +78 -21
- package/src/lib/primitives/geometry/Group2d.ts +10 -1
- package/src/lib/primitives/geometry/geometry-constants.ts +2 -1
- package/src/lib/primitives/intersect.test.ts +946 -0
- package/src/lib/primitives/intersect.ts +12 -5
- package/src/lib/primitives/utils.ts +11 -0
- package/src/lib/test/InFrontOfTheCanvas.test.tsx +187 -0
- package/src/lib/utils/EditorAtom.ts +37 -0
- package/src/lib/utils/dom.test.ts +94 -0
- package/src/lib/utils/dom.ts +38 -1
- package/src/lib/utils/getPointerInfo.ts +2 -1
- package/src/lib/utils/reparenting.ts +3 -69
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
- package/src/lib/utils/sync/TLLocalSyncClient.ts +0 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
- package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
- package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
- package/src/lib/test/currentToolIdMask.test.ts +0 -49
- package/src/lib/utils/nearestMultiple.ts +0 -13
|
@@ -13,7 +13,7 @@ export class UserPreferencesManager {
|
|
|
13
13
|
private readonly user: TLUser,
|
|
14
14
|
private readonly inferDarkMode: boolean
|
|
15
15
|
) {
|
|
16
|
-
if (typeof window === 'undefined' || !
|
|
16
|
+
if (typeof window === 'undefined' || !window.matchMedia) return
|
|
17
17
|
|
|
18
18
|
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
|
19
19
|
if (darkModeMediaQuery?.matches) {
|
|
@@ -43,11 +43,13 @@ export class UserPreferencesManager {
|
|
|
43
43
|
locale: this.getLocale(),
|
|
44
44
|
color: this.getColor(),
|
|
45
45
|
animationSpeed: this.getAnimationSpeed(),
|
|
46
|
+
areKeyboardShortcutsEnabled: this.getAreKeyboardShortcutsEnabled(),
|
|
46
47
|
isSnapMode: this.getIsSnapMode(),
|
|
47
48
|
colorScheme: this.user.userPreferences.get().colorScheme,
|
|
48
49
|
isDarkMode: this.getIsDarkMode(),
|
|
49
50
|
isWrapMode: this.getIsWrapMode(),
|
|
50
51
|
isDynamicResizeMode: this.getIsDynamicResizeMode(),
|
|
52
|
+
showUiLabels: this.getShowUiLabels(),
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -75,6 +77,13 @@ export class UserPreferencesManager {
|
|
|
75
77
|
return this.user.userPreferences.get().animationSpeed ?? defaultUserPreferences.animationSpeed
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
@computed getAreKeyboardShortcutsEnabled() {
|
|
81
|
+
return (
|
|
82
|
+
this.user.userPreferences.get().areKeyboardShortcutsEnabled ??
|
|
83
|
+
defaultUserPreferences.areKeyboardShortcutsEnabled
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
78
87
|
@computed getId() {
|
|
79
88
|
return this.user.userPreferences.get().id
|
|
80
89
|
}
|
|
@@ -111,4 +120,8 @@ export class UserPreferencesManager {
|
|
|
111
120
|
defaultUserPreferences.isPasteAtCursorMode
|
|
112
121
|
)
|
|
113
122
|
}
|
|
123
|
+
|
|
124
|
+
@computed getShowUiLabels() {
|
|
125
|
+
return this.user.userPreferences.get().showUiLabels ?? defaultUserPreferences.showUiLabels
|
|
126
|
+
}
|
|
114
127
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TLShape } from '@tldraw/tlschema'
|
|
2
2
|
import { lerp } from '@tldraw/utils'
|
|
3
3
|
import { Geometry2d } from '../../primitives/geometry/Geometry2d'
|
|
4
4
|
import { Rectangle2d } from '../../primitives/geometry/Rectangle2d'
|
|
@@ -7,7 +7,7 @@ import { ShapeUtil, TLResizeInfo } from './ShapeUtil'
|
|
|
7
7
|
import { resizeBox } from './shared/resizeBox'
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
|
-
export type TLBaseBoxShape =
|
|
10
|
+
export type TLBaseBoxShape = Extract<TLShape, { props: { w: number; h: number } }>
|
|
11
11
|
|
|
12
12
|
/** @public */
|
|
13
13
|
export abstract class BaseBoxShapeUtil<Shape extends TLBaseBoxShape> extends ShapeUtil<Shape> {
|
|
@@ -26,10 +26,7 @@ import { TLClickEventInfo } from '../types/event-types'
|
|
|
26
26
|
import { TLResizeHandle } from '../types/selection-types'
|
|
27
27
|
|
|
28
28
|
/** @public */
|
|
29
|
-
export interface TLShapeUtilConstructor<
|
|
30
|
-
T extends TLUnknownShape,
|
|
31
|
-
U extends ShapeUtil<T> = ShapeUtil<T>,
|
|
32
|
-
> {
|
|
29
|
+
export interface TLShapeUtilConstructor<T extends TLShape, U extends ShapeUtil<T> = ShapeUtil<T>> {
|
|
33
30
|
new (editor: Editor): U
|
|
34
31
|
type: T['type']
|
|
35
32
|
props?: RecordProps<T>
|
|
@@ -42,11 +39,11 @@ export interface TLShapeUtilConstructor<
|
|
|
42
39
|
*
|
|
43
40
|
* @public
|
|
44
41
|
*/
|
|
45
|
-
export interface TLShapeUtilCanBindOpts<Shape extends
|
|
42
|
+
export interface TLShapeUtilCanBindOpts<Shape extends TLShape = TLShape> {
|
|
46
43
|
/** The type of shape referenced by the `fromId` of the binding. */
|
|
47
|
-
fromShapeType:
|
|
44
|
+
fromShapeType: TLShape['type']
|
|
48
45
|
/** The type of shape referenced by the `toId` of the binding. */
|
|
49
|
-
toShapeType:
|
|
46
|
+
toShapeType: TLShape['type']
|
|
50
47
|
/** The type of binding. */
|
|
51
48
|
bindingType: string
|
|
52
49
|
}
|
|
@@ -79,7 +76,7 @@ export interface TLShapeUtilCanvasSvgDef {
|
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
/** @public */
|
|
82
|
-
export abstract class ShapeUtil<Shape extends
|
|
79
|
+
export abstract class ShapeUtil<Shape extends TLShape = TLShape> {
|
|
83
80
|
/** Configure this shape utils {@link ShapeUtil.options | `options`}. */
|
|
84
81
|
static configure<T extends TLShapeUtilConstructor<any, any>>(
|
|
85
82
|
this: T,
|
|
@@ -283,6 +280,17 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
283
280
|
return true
|
|
284
281
|
}
|
|
285
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Whether this shape can be culled. By default, shapes are culled for
|
|
285
|
+
* performance reasons when they are outside of the viewport. Culled shapes are still rendered
|
|
286
|
+
* to the DOM, but have their `display` property set to `none`.
|
|
287
|
+
*
|
|
288
|
+
* @param shape - The shape.
|
|
289
|
+
*/
|
|
290
|
+
canCull(_shape: Shape): boolean {
|
|
291
|
+
return true
|
|
292
|
+
}
|
|
293
|
+
|
|
286
294
|
/**
|
|
287
295
|
* Does this shape provide a background for its children? If this is true,
|
|
288
296
|
* then any children with a `renderBackground` method will have their
|
|
@@ -296,6 +304,27 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
296
304
|
return false
|
|
297
305
|
}
|
|
298
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Get the clip path to apply to this shape's children.
|
|
309
|
+
*
|
|
310
|
+
* @param shape - The shape to get the clip path for
|
|
311
|
+
* @returns Array of points defining the clipping polygon in local coordinates, or undefined if no clipping
|
|
312
|
+
* @public
|
|
313
|
+
*/
|
|
314
|
+
getClipPath?(shape: Shape): Vec[] | undefined
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Whether a specific child shape should be clipped by this shape.
|
|
318
|
+
* Only called if getClipPath returns a valid polygon.
|
|
319
|
+
*
|
|
320
|
+
* If not defined, the default behavior is to clip all children.
|
|
321
|
+
*
|
|
322
|
+
* @param child - The child shape to check
|
|
323
|
+
* @returns boolean indicating if this child should be clipped
|
|
324
|
+
* @public
|
|
325
|
+
*/
|
|
326
|
+
shouldClipChild?(child: TLShape): boolean
|
|
327
|
+
|
|
299
328
|
/**
|
|
300
329
|
* Whether the shape should hide its resize handles when selected.
|
|
301
330
|
*
|
|
@@ -341,6 +370,20 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
341
370
|
return false
|
|
342
371
|
}
|
|
343
372
|
|
|
373
|
+
/**
|
|
374
|
+
* By default, the bounds of an image export are the bounds of all the shapes it contains, plus
|
|
375
|
+
* some padding. If an export includes a shape where `isExportBoundsContainer` is true, then the
|
|
376
|
+
* padding is skipped _if the bounds of that shape contains all the other shapes_. This is
|
|
377
|
+
* useful in cases like annotating on top of an image, where you usually want to avoid extra
|
|
378
|
+
* padding around the image if you don't need it.
|
|
379
|
+
*
|
|
380
|
+
* @param _shape - The shape to check
|
|
381
|
+
* @returns True if this shape should be treated as an export bounds container
|
|
382
|
+
*/
|
|
383
|
+
isExportBoundsContainer(_shape: Shape): boolean {
|
|
384
|
+
return false
|
|
385
|
+
}
|
|
386
|
+
|
|
344
387
|
/**
|
|
345
388
|
* Get a JSX element for the shape (as an HTML element) to be rendered as part of the canvas background - behind any other shape content.
|
|
346
389
|
*
|
|
@@ -584,6 +627,15 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
584
627
|
*/
|
|
585
628
|
onResizeEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | void
|
|
586
629
|
|
|
630
|
+
/**
|
|
631
|
+
* A callback called when a shape resize is cancelled.
|
|
632
|
+
*
|
|
633
|
+
* @param initial - The shape at the start of the resize.
|
|
634
|
+
* @param current - The current shape.
|
|
635
|
+
* @public
|
|
636
|
+
*/
|
|
637
|
+
onResizeCancel?(initial: Shape, current: Shape): void
|
|
638
|
+
|
|
587
639
|
/**
|
|
588
640
|
* A callback called when a shape starts being translated.
|
|
589
641
|
*
|
|
@@ -613,6 +665,25 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
613
665
|
*/
|
|
614
666
|
onTranslateEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | void
|
|
615
667
|
|
|
668
|
+
/**
|
|
669
|
+
* A callback called when a shape translation is cancelled.
|
|
670
|
+
*
|
|
671
|
+
* @param initial - The shape at the start of the translation.
|
|
672
|
+
* @param current - The current shape.
|
|
673
|
+
* @public
|
|
674
|
+
*/
|
|
675
|
+
onTranslateCancel?(initial: Shape, current: Shape): void
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* A callback called when a shape's handle starts being dragged.
|
|
679
|
+
*
|
|
680
|
+
* @param shape - The shape.
|
|
681
|
+
* @param info - An object containing the handle and whether the handle is 'precise' or not.
|
|
682
|
+
* @returns A change to apply to the shape, or void.
|
|
683
|
+
* @public
|
|
684
|
+
*/
|
|
685
|
+
onHandleDragStart?(shape: Shape, info: TLHandleDragInfo<Shape>): TLShapePartial<Shape> | void
|
|
686
|
+
|
|
616
687
|
/**
|
|
617
688
|
* A callback called when a shape's handle changes.
|
|
618
689
|
*
|
|
@@ -623,6 +694,25 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
623
694
|
*/
|
|
624
695
|
onHandleDrag?(shape: Shape, info: TLHandleDragInfo<Shape>): TLShapePartial<Shape> | void
|
|
625
696
|
|
|
697
|
+
/**
|
|
698
|
+
* A callback called when a shape's handle finishes being dragged.
|
|
699
|
+
*
|
|
700
|
+
* @param current - The current shape.
|
|
701
|
+
* @param info - An object containing the handle and whether the handle is 'precise' or not.
|
|
702
|
+
* @returns A change to apply to the shape, or void.
|
|
703
|
+
* @public
|
|
704
|
+
*/
|
|
705
|
+
onHandleDragEnd?(current: Shape, info: TLHandleDragInfo<Shape>): TLShapePartial<Shape> | void
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* A callback called when a shape's handle drag is cancelled.
|
|
709
|
+
*
|
|
710
|
+
* @param current - The current shape.
|
|
711
|
+
* @param info - An object containing the handle and whether the handle is 'precise' or not.
|
|
712
|
+
* @public
|
|
713
|
+
*/
|
|
714
|
+
onHandleDragCancel?(current: Shape, info: TLHandleDragInfo<Shape>): void
|
|
715
|
+
|
|
626
716
|
/**
|
|
627
717
|
* A callback called when a shape starts being rotated.
|
|
628
718
|
*
|
|
@@ -652,6 +742,15 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
652
742
|
*/
|
|
653
743
|
onRotateEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | void
|
|
654
744
|
|
|
745
|
+
/**
|
|
746
|
+
* A callback called when a shape rotation is cancelled.
|
|
747
|
+
*
|
|
748
|
+
* @param initial - The shape at the start of the rotation.
|
|
749
|
+
* @param current - The current shape.
|
|
750
|
+
* @public
|
|
751
|
+
*/
|
|
752
|
+
onRotateCancel?(initial: Shape, current: Shape): void
|
|
753
|
+
|
|
655
754
|
/**
|
|
656
755
|
* Not currently used.
|
|
657
756
|
*
|
|
@@ -819,5 +918,6 @@ export interface TLResizeInfo<T extends TLShape> {
|
|
|
819
918
|
export interface TLHandleDragInfo<T extends TLShape> {
|
|
820
919
|
handle: TLHandle
|
|
821
920
|
isPrecise: boolean
|
|
921
|
+
isCreatingShape: boolean
|
|
822
922
|
initial?: T | undefined
|
|
823
923
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TLShape } from '@tldraw/tlschema'
|
|
2
|
+
import { TLBaseBoxShape } from '../../shapes/BaseBoxShapeUtil'
|
|
2
3
|
import { StateNode, TLStateNodeConstructor } from '../StateNode'
|
|
3
4
|
import { Idle } from './children/Idle'
|
|
4
5
|
import { Pointing } from './children/Pointing'
|
|
@@ -11,7 +12,7 @@ export abstract class BaseBoxShapeTool extends StateNode {
|
|
|
11
12
|
return [Idle, Pointing]
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
abstract override shapeType:
|
|
15
|
+
abstract override shapeType: TLBaseBoxShape['type']
|
|
15
16
|
|
|
16
17
|
onCreate?(_shape: TLShape | null): void | null
|
|
17
18
|
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { createTLStore } from '../../config/createTLStore'
|
|
2
|
+
import { Editor } from '../Editor'
|
|
3
|
+
import { StateNode } from './StateNode'
|
|
4
|
+
|
|
5
|
+
describe('StateNode.addChild', () => {
|
|
6
|
+
// Test state node classes for addChild tests
|
|
7
|
+
class ParentState extends StateNode {
|
|
8
|
+
static override id = 'parent'
|
|
9
|
+
static override initial = 'child1'
|
|
10
|
+
static override children() {
|
|
11
|
+
return [ChildState1]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class ChildState1 extends StateNode {
|
|
16
|
+
static override id = 'child1'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class ChildState2 extends StateNode {
|
|
20
|
+
static override id = 'child2'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class ChildState3 extends StateNode {
|
|
24
|
+
static override id = 'child3'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class LeafState extends StateNode {
|
|
28
|
+
static override id = 'leaf'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class RootState extends StateNode {
|
|
32
|
+
static override id = 'root'
|
|
33
|
+
static override initial = 'child1'
|
|
34
|
+
static override children() {
|
|
35
|
+
return [ChildState1]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class RootStateWithoutChildren extends StateNode {
|
|
40
|
+
static override id = 'rootWithoutChildren'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let editor: Editor
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
editor = new Editor({
|
|
47
|
+
initialState: 'parent',
|
|
48
|
+
shapeUtils: [],
|
|
49
|
+
bindingUtils: [],
|
|
50
|
+
tools: [
|
|
51
|
+
ParentState,
|
|
52
|
+
ChildState1,
|
|
53
|
+
ChildState2,
|
|
54
|
+
ChildState3,
|
|
55
|
+
LeafState,
|
|
56
|
+
RootState,
|
|
57
|
+
RootStateWithoutChildren,
|
|
58
|
+
],
|
|
59
|
+
store: createTLStore({ shapeUtils: [], bindingUtils: [] }),
|
|
60
|
+
getContainer: () => document.body,
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('should add a child to a branch state node', () => {
|
|
65
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
66
|
+
|
|
67
|
+
// Initially should have one child
|
|
68
|
+
expect(Object.keys(parentState.children!)).toHaveLength(1)
|
|
69
|
+
expect(parentState.children!['child1']).toBeDefined()
|
|
70
|
+
|
|
71
|
+
// Add a new child
|
|
72
|
+
parentState.addChild(ChildState2)
|
|
73
|
+
|
|
74
|
+
// Should now have two children
|
|
75
|
+
expect(Object.keys(parentState.children!)).toHaveLength(2)
|
|
76
|
+
expect(parentState.children!['child1']).toBeDefined()
|
|
77
|
+
expect(parentState.children!['child2']).toBeDefined()
|
|
78
|
+
expect(parentState.children!['child2']).toBeInstanceOf(ChildState2)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should add a child to a root state node', () => {
|
|
82
|
+
const rootState = editor.root.children!['root'] as RootState
|
|
83
|
+
|
|
84
|
+
// Initially should have one child
|
|
85
|
+
expect(Object.keys(rootState.children!)).toHaveLength(1)
|
|
86
|
+
expect(rootState.children!['child1']).toBeDefined()
|
|
87
|
+
|
|
88
|
+
// Add a new child
|
|
89
|
+
rootState.addChild(ChildState2)
|
|
90
|
+
|
|
91
|
+
// Should now have two children
|
|
92
|
+
expect(Object.keys(rootState.children!)).toHaveLength(2)
|
|
93
|
+
expect(rootState.children!['child1']).toBeDefined()
|
|
94
|
+
expect(rootState.children!['child2']).toBeDefined()
|
|
95
|
+
expect(rootState.children!['child2']).toBeInstanceOf(ChildState2)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('should throw an error when trying to add a child to a leaf state node', () => {
|
|
99
|
+
const leafState = editor.root.children!['leaf'] as LeafState
|
|
100
|
+
|
|
101
|
+
// Leaf state should not have children
|
|
102
|
+
expect(leafState.children).toBeUndefined()
|
|
103
|
+
|
|
104
|
+
// Should throw an error when trying to add a child
|
|
105
|
+
expect(() => {
|
|
106
|
+
leafState.addChild(ChildState2)
|
|
107
|
+
}).toThrow('StateNode.addChild: cannot add child to a leaf node')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('should return the parent state node for chaining', () => {
|
|
111
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
112
|
+
|
|
113
|
+
const result = parentState.addChild(ChildState2)
|
|
114
|
+
|
|
115
|
+
expect(result).toBe(parentState)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('should create the child with the correct editor and parent', () => {
|
|
119
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
120
|
+
|
|
121
|
+
parentState.addChild(ChildState2)
|
|
122
|
+
const childState = parentState.children!['child2'] as ChildState2
|
|
123
|
+
|
|
124
|
+
expect(childState.editor).toBe(editor)
|
|
125
|
+
expect(childState.parent).toBe(parentState)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('should allow adding multiple children', () => {
|
|
129
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
130
|
+
|
|
131
|
+
// Add multiple children
|
|
132
|
+
parentState.addChild(ChildState2).addChild(ChildState3)
|
|
133
|
+
|
|
134
|
+
// Should have three children
|
|
135
|
+
expect(Object.keys(parentState.children!)).toHaveLength(3)
|
|
136
|
+
expect(parentState.children!['child1']).toBeDefined()
|
|
137
|
+
expect(parentState.children!['child2']).toBeDefined()
|
|
138
|
+
expect(parentState.children!['child3']).toBeDefined()
|
|
139
|
+
expect(parentState.children!['child2']).toBeInstanceOf(ChildState2)
|
|
140
|
+
expect(parentState.children!['child3']).toBeInstanceOf(ChildState3)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('should allow transitioning to added children', () => {
|
|
144
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
145
|
+
|
|
146
|
+
// Add a new child
|
|
147
|
+
parentState.addChild(ChildState2)
|
|
148
|
+
|
|
149
|
+
// Should be able to transition to the new child
|
|
150
|
+
expect(() => {
|
|
151
|
+
parentState.transition('child2')
|
|
152
|
+
}).not.toThrow()
|
|
153
|
+
|
|
154
|
+
// The current state should be the new child
|
|
155
|
+
expect(parentState.getCurrent()?.id).toBe('child2')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should maintain existing children when adding new ones', () => {
|
|
159
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
160
|
+
const originalChild = parentState.children!['child1']
|
|
161
|
+
|
|
162
|
+
// Add a new child
|
|
163
|
+
parentState.addChild(ChildState2)
|
|
164
|
+
|
|
165
|
+
// Original child should still exist and be the same instance
|
|
166
|
+
expect(parentState.children!['child1']).toBe(originalChild)
|
|
167
|
+
expect(parentState.children!['child1']).toBeInstanceOf(ChildState1)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('should initialize children object for root nodes without static children', () => {
|
|
171
|
+
// Create a StateNode directly as a root node (no parent)
|
|
172
|
+
const mockEditor = {} as Editor
|
|
173
|
+
const rootStateWithoutChildren = new RootStateWithoutChildren(mockEditor, undefined)
|
|
174
|
+
|
|
175
|
+
// Root state without static children should not have children initially
|
|
176
|
+
expect(rootStateWithoutChildren.children).toBeUndefined()
|
|
177
|
+
|
|
178
|
+
// Adding a child should initialize the children object
|
|
179
|
+
rootStateWithoutChildren.addChild(ChildState2)
|
|
180
|
+
|
|
181
|
+
// Should now have children object with the added child
|
|
182
|
+
expect(rootStateWithoutChildren.children).toBeDefined()
|
|
183
|
+
expect(Object.keys(rootStateWithoutChildren.children!)).toHaveLength(1)
|
|
184
|
+
expect(rootStateWithoutChildren.children!['child2']).toBeDefined()
|
|
185
|
+
expect(rootStateWithoutChildren.children!['child2']).toBeInstanceOf(ChildState2)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
it('should throw an error when trying to add a child with a duplicate ID', () => {
|
|
189
|
+
const parentState = editor.root.children!['parent'] as ParentState
|
|
190
|
+
|
|
191
|
+
// Initially should have one child
|
|
192
|
+
expect(Object.keys(parentState.children!)).toHaveLength(1)
|
|
193
|
+
expect(parentState.children!['child1']).toBeDefined()
|
|
194
|
+
|
|
195
|
+
// Should throw an error when trying to add a child with the same ID
|
|
196
|
+
expect(() => {
|
|
197
|
+
parentState.addChild(ChildState1)
|
|
198
|
+
}).toThrow("StateNode.addChild: a child with id 'child1' already exists")
|
|
199
|
+
|
|
200
|
+
// Should still have only one child
|
|
201
|
+
expect(Object.keys(parentState.children!)).toHaveLength(1)
|
|
202
|
+
expect(parentState.children!['child1']).toBeDefined()
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('should throw an error when trying to add a child with a duplicate ID to a root state', () => {
|
|
206
|
+
const rootState = editor.root.children!['root'] as RootState
|
|
207
|
+
|
|
208
|
+
// Initially should have one child
|
|
209
|
+
expect(Object.keys(rootState.children!)).toHaveLength(1)
|
|
210
|
+
expect(rootState.children!['child1']).toBeDefined()
|
|
211
|
+
|
|
212
|
+
// Should throw an error when trying to add a child with the same ID
|
|
213
|
+
expect(() => {
|
|
214
|
+
rootState.addChild(ChildState1)
|
|
215
|
+
}).toThrow("StateNode.addChild: a child with id 'child1' already exists")
|
|
216
|
+
|
|
217
|
+
// Should still have only one child
|
|
218
|
+
expect(Object.keys(rootState.children!)).toHaveLength(1)
|
|
219
|
+
expect(rootState.children!['child1']).toBeDefined()
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('should throw an error when trying to add a child with a duplicate ID to a root state without static children', () => {
|
|
223
|
+
// Create a StateNode directly as a root node (no parent)
|
|
224
|
+
const mockEditor = {} as Editor
|
|
225
|
+
const rootStateWithoutChildren = new RootStateWithoutChildren(mockEditor, undefined)
|
|
226
|
+
|
|
227
|
+
// Add a child first
|
|
228
|
+
rootStateWithoutChildren.addChild(ChildState1)
|
|
229
|
+
|
|
230
|
+
// Should throw an error when trying to add a child with the same ID
|
|
231
|
+
expect(() => {
|
|
232
|
+
rootStateWithoutChildren.addChild(ChildState1)
|
|
233
|
+
}).toThrow("StateNode.addChild: a child with id 'child1' already exists")
|
|
234
|
+
|
|
235
|
+
// Should still have only one child
|
|
236
|
+
expect(Object.keys(rootStateWithoutChildren.children!)).toHaveLength(1)
|
|
237
|
+
expect(rootStateWithoutChildren.children!['child1']).toBeDefined()
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
describe('current tool id mask', () => {
|
|
242
|
+
// Tool mask test classes
|
|
243
|
+
class ToolA extends StateNode {
|
|
244
|
+
static override id = 'A'
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
class ToolB extends StateNode {
|
|
248
|
+
static override id = 'B'
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
class ToolC extends StateNode {
|
|
252
|
+
static override id = 'C'
|
|
253
|
+
|
|
254
|
+
override onEnter() {
|
|
255
|
+
this.setCurrentToolIdMask('A')
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let toolMaskEditor: Editor
|
|
260
|
+
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
toolMaskEditor = new Editor({
|
|
263
|
+
initialState: 'A',
|
|
264
|
+
shapeUtils: [],
|
|
265
|
+
bindingUtils: [],
|
|
266
|
+
tools: [ToolA, ToolB, ToolC],
|
|
267
|
+
store: createTLStore({ shapeUtils: [], bindingUtils: [] }),
|
|
268
|
+
getContainer: () => document.body,
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('starts with the correct tool id', () => {
|
|
273
|
+
expect(toolMaskEditor.getCurrentToolId()).toBe('A')
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it('updates the current tool id', () => {
|
|
277
|
+
toolMaskEditor.setCurrentTool('B')
|
|
278
|
+
expect(toolMaskEditor.getCurrentToolId()).toBe('B')
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it('masks the current tool id', () => {
|
|
282
|
+
toolMaskEditor.setCurrentTool('C')
|
|
283
|
+
expect(toolMaskEditor.getCurrentToolId()).toBe('A')
|
|
284
|
+
})
|
|
285
|
+
})
|
|
@@ -62,7 +62,7 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
|
|
|
62
62
|
|
|
63
63
|
this.parent = parent ?? ({} as any)
|
|
64
64
|
|
|
65
|
-
if (
|
|
65
|
+
if (parent) {
|
|
66
66
|
if (children && initial) {
|
|
67
67
|
this.type = 'branch'
|
|
68
68
|
this.initial = initial
|
|
@@ -238,6 +238,32 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
|
|
|
238
238
|
this._currentToolIdMask.set(id)
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Add a child node to this state node.
|
|
243
|
+
*
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
addChild(childConstructor: TLStateNodeConstructor): this {
|
|
247
|
+
if (this.type === 'leaf') {
|
|
248
|
+
throw new Error('StateNode.addChild: cannot add child to a leaf node')
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Initialize children if it's undefined (for root nodes without static children)
|
|
252
|
+
if (!this.children) {
|
|
253
|
+
this.children = {}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const child = new childConstructor(this.editor, this)
|
|
257
|
+
|
|
258
|
+
// Check if a child with this ID already exists
|
|
259
|
+
if (this.children[child.id]) {
|
|
260
|
+
throw new Error(`StateNode.addChild: a child with id '${child.id}' already exists`)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
this.children[child.id] = child
|
|
264
|
+
return this
|
|
265
|
+
}
|
|
266
|
+
|
|
241
267
|
onWheel?(info: TLWheelEventInfo): void
|
|
242
268
|
onPointerDown?(info: TLPointerEventInfo): void
|
|
243
269
|
onPointerMove?(info: TLPointerEventInfo): void
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoxModel } from '@tldraw/tlschema'
|
|
1
|
+
import { BoxModel, TLShape } from '@tldraw/tlschema'
|
|
2
2
|
import { Box } from '../../primitives/Box'
|
|
3
3
|
import { VecLike } from '../../primitives/Vec'
|
|
4
4
|
|
|
@@ -72,12 +72,6 @@ export interface TLImageExportOptions extends TLSvgExportOptions {
|
|
|
72
72
|
format?: TLExportType
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* @public
|
|
77
|
-
* @deprecated use {@link TLImageExportOptions} instead
|
|
78
|
-
*/
|
|
79
|
-
export type TLSvgOptions = TLImageExportOptions
|
|
80
|
-
|
|
81
75
|
/** @public */
|
|
82
76
|
export interface TLCameraMoveOptions {
|
|
83
77
|
/** Whether to move the camera immediately, rather than on the next tick. */
|
|
@@ -187,3 +181,75 @@ export interface TLCameraConstraints {
|
|
|
187
181
|
y: 'free' | 'fixed' | 'inside' | 'outside' | 'contain'
|
|
188
182
|
}
|
|
189
183
|
}
|
|
184
|
+
|
|
185
|
+
/** @public */
|
|
186
|
+
export interface TLUpdatePointerOptions {
|
|
187
|
+
/** Whether to update the pointer immediately, rather than on the next tick. */
|
|
188
|
+
immediate?: boolean
|
|
189
|
+
/**
|
|
190
|
+
* The point, in screen-space, to update the pointer to. Defaults to the position of the last
|
|
191
|
+
* pointer event.
|
|
192
|
+
*/
|
|
193
|
+
point?: VecLike
|
|
194
|
+
pointerId?: number
|
|
195
|
+
ctrlKey?: boolean
|
|
196
|
+
altKey?: boolean
|
|
197
|
+
shiftKey?: boolean
|
|
198
|
+
metaKey?: boolean
|
|
199
|
+
accelKey?: boolean
|
|
200
|
+
isPen?: boolean
|
|
201
|
+
button?: number
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Options to {@link Editor.getShapeAtPoint}.
|
|
206
|
+
*
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
export interface TLGetShapeAtPointOptions {
|
|
210
|
+
/**
|
|
211
|
+
* The margin to apply to the shape.
|
|
212
|
+
* If a number, it will be applied to both the inside and outside of the shape.
|
|
213
|
+
* If an array, the first element will be applied to the inside of the shape, and the second element will be applied to the outside.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* // Get the shape at the center of the screen
|
|
218
|
+
* const shape = editor.getShapeAtProps({
|
|
219
|
+
* margin: 10,
|
|
220
|
+
* })
|
|
221
|
+
*
|
|
222
|
+
* // Get the shape at the center of the screen with a 10px inner margin and a 5px outer margin
|
|
223
|
+
* const shape = editor.getShapeAtProps({
|
|
224
|
+
* margin: [10, 5],
|
|
225
|
+
* })
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
margin?: number | [number, number]
|
|
229
|
+
/**
|
|
230
|
+
* Whether to register hits inside of shapes (beyond the margin), such as the inside of a solid shape.
|
|
231
|
+
*/
|
|
232
|
+
hitInside?: boolean
|
|
233
|
+
/**
|
|
234
|
+
* Whether to register hits on locked shapes.
|
|
235
|
+
*/
|
|
236
|
+
hitLocked?: boolean
|
|
237
|
+
/**
|
|
238
|
+
* Whether to register hits on labels.
|
|
239
|
+
*/
|
|
240
|
+
hitLabels?: boolean
|
|
241
|
+
/**
|
|
242
|
+
* Whether to only return hits on shapes that are currently being rendered.
|
|
243
|
+
* todo: rename this to hitCulled or hitNotRendering
|
|
244
|
+
*/
|
|
245
|
+
renderingOnly?: boolean
|
|
246
|
+
/**
|
|
247
|
+
* Whether to register hits on the inside of frame shapes.
|
|
248
|
+
* todo: rename this to hitInsideFrames
|
|
249
|
+
*/
|
|
250
|
+
hitFrameInside?: boolean
|
|
251
|
+
/**
|
|
252
|
+
* A filter function to apply to the shapes.
|
|
253
|
+
*/
|
|
254
|
+
filter?(shape: TLShape): boolean
|
|
255
|
+
}
|