@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
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
TLGroupShape,
|
|
5
5
|
TLShape,
|
|
6
6
|
TLShapeId,
|
|
7
|
+
getColorValue,
|
|
7
8
|
getDefaultColorTheme,
|
|
8
9
|
} from '@tldraw/tlschema'
|
|
9
10
|
import { hasOwnProperty, promiseWithResolve, uniqueId } from '@tldraw/utils'
|
|
@@ -56,33 +57,21 @@ export function getSvgJsx(editor: Editor, ids: TLShapeId[], opts: TLImageExportO
|
|
|
56
57
|
.filter(({ id }) => shapeIdsToInclude.has(id))
|
|
57
58
|
|
|
58
59
|
// --- Common bounding box of all shapes
|
|
60
|
+
const singleFrameShapeId =
|
|
61
|
+
ids.length === 1 && editor.isShapeOfType<TLFrameShape>(editor.getShape(ids[0])!, 'frame')
|
|
62
|
+
? ids[0]
|
|
63
|
+
: null
|
|
64
|
+
|
|
59
65
|
let bbox: null | Box = null
|
|
60
66
|
if (opts.bounds) {
|
|
61
|
-
bbox = opts.bounds
|
|
67
|
+
bbox = opts.bounds.clone().expandBy(padding)
|
|
62
68
|
} else {
|
|
63
|
-
|
|
64
|
-
const maskedPageBounds = editor.getShapeMaskedPageBounds(id)
|
|
65
|
-
if (!maskedPageBounds) continue
|
|
66
|
-
if (bbox) {
|
|
67
|
-
bbox.union(maskedPageBounds)
|
|
68
|
-
} else {
|
|
69
|
-
bbox = maskedPageBounds.clone()
|
|
70
|
-
}
|
|
71
|
-
}
|
|
69
|
+
bbox = getExportDefaultBounds(editor, renderingShapes, padding, singleFrameShapeId)
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
// no unmasked shapes to export
|
|
75
73
|
if (!bbox) return
|
|
76
74
|
|
|
77
|
-
const singleFrameShapeId =
|
|
78
|
-
ids.length === 1 && editor.isShapeOfType<TLFrameShape>(editor.getShape(ids[0])!, 'frame')
|
|
79
|
-
? ids[0]
|
|
80
|
-
: null
|
|
81
|
-
if (!singleFrameShapeId) {
|
|
82
|
-
// Expand by an extra 32 pixels
|
|
83
|
-
bbox.expandBy(padding)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
75
|
// We want the svg image to be BIGGER THAN USUAL to account for image quality
|
|
87
76
|
const w = bbox.width * scale
|
|
88
77
|
const h = bbox.height * scale
|
|
@@ -119,6 +108,75 @@ export function getSvgJsx(editor: Editor, ids: TLShapeId[], opts: TLImageExportO
|
|
|
119
108
|
return { jsx: svg, width: w, height: h, exportDelay }
|
|
120
109
|
}
|
|
121
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Calculates the default bounds for an SVG export. This function handles:
|
|
113
|
+
* 1. Computing masked page bounds for each shape
|
|
114
|
+
* 2. Container logic: if a shape is marked as an export bounds container and it
|
|
115
|
+
* contains all other shapes, use its bounds and skip padding
|
|
116
|
+
* 3. Otherwise, create a union of all shape bounds and apply padding
|
|
117
|
+
*
|
|
118
|
+
* The container logic is useful for cases like annotating on an image - if the image
|
|
119
|
+
* contains all annotations, we want to export exactly the image bounds without extra padding.
|
|
120
|
+
*
|
|
121
|
+
* @param editor - The editor instance
|
|
122
|
+
* @param renderingShapes - The shapes to include in the export
|
|
123
|
+
* @param padding - Padding to add around the bounds (only applied if no container bounds)
|
|
124
|
+
* @param singleFrameShapeId - If exporting a single frame, this is its ID (skips padding)
|
|
125
|
+
* @returns The calculated bounds box, or null if no shapes to export
|
|
126
|
+
*/
|
|
127
|
+
export function getExportDefaultBounds(
|
|
128
|
+
editor: Editor,
|
|
129
|
+
renderingShapes: TLRenderingShape[],
|
|
130
|
+
padding: number,
|
|
131
|
+
singleFrameShapeId: TLShapeId | null
|
|
132
|
+
) {
|
|
133
|
+
let isBoundedByContainer = false
|
|
134
|
+
let bbox: null | Box = null
|
|
135
|
+
|
|
136
|
+
for (const { id } of renderingShapes) {
|
|
137
|
+
const maskedPageBounds = editor.getShapeMaskedPageBounds(id)
|
|
138
|
+
if (!maskedPageBounds) continue
|
|
139
|
+
|
|
140
|
+
// Check if this shape is an export bounds container (e.g., an image being annotated)
|
|
141
|
+
const shape = editor.getShape(id)!
|
|
142
|
+
const isContainer = editor.getShapeUtil(shape).isExportBoundsContainer(shape)
|
|
143
|
+
|
|
144
|
+
if (bbox) {
|
|
145
|
+
// Container logic: if this is a container and it contains all shapes processed so far,
|
|
146
|
+
// use the container's bounds instead of the union. This prevents extra padding around
|
|
147
|
+
// things like annotated images.
|
|
148
|
+
if (isContainer && Box.ContainsApproximately(maskedPageBounds, bbox)) {
|
|
149
|
+
isBoundedByContainer = true
|
|
150
|
+
bbox = maskedPageBounds.clone()
|
|
151
|
+
} else {
|
|
152
|
+
// If we were previously bounded by a container but this shape extends outside it,
|
|
153
|
+
// we're no longer bounded by a container
|
|
154
|
+
if (isBoundedByContainer && !Box.ContainsApproximately(bbox, maskedPageBounds)) {
|
|
155
|
+
isBoundedByContainer = false
|
|
156
|
+
}
|
|
157
|
+
// Expand the bounding box to include this shape
|
|
158
|
+
bbox.union(maskedPageBounds)
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
// First shape sets the initial bounds
|
|
162
|
+
isBoundedByContainer = isContainer
|
|
163
|
+
bbox = maskedPageBounds.clone()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// No unmasked shapes to export
|
|
168
|
+
if (!bbox) return null
|
|
169
|
+
|
|
170
|
+
// Only apply padding if:
|
|
171
|
+
// - Not exporting a single frame (frames have their own padding rules)
|
|
172
|
+
// - Not bounded by a container (containers define their own bounds precisely)
|
|
173
|
+
if (!singleFrameShapeId && !isBoundedByContainer) {
|
|
174
|
+
bbox.expandBy(padding)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return bbox
|
|
178
|
+
}
|
|
179
|
+
|
|
122
180
|
function SvgExport({
|
|
123
181
|
editor,
|
|
124
182
|
preserveAspectRatio,
|
|
@@ -373,8 +431,7 @@ function SvgExport({
|
|
|
373
431
|
| { options: { showColors: boolean } }
|
|
374
432
|
if (frameShapeUtil?.options.showColors) {
|
|
375
433
|
const shape = editor.getShape(singleFrameShapeId)! as TLFrameShape
|
|
376
|
-
|
|
377
|
-
backgroundColor = color.frame.fill
|
|
434
|
+
backgroundColor = getColorValue(theme, shape.props.color, 'frameFill')
|
|
378
435
|
} else {
|
|
379
436
|
backgroundColor = theme.solid
|
|
380
437
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useValue } from '@tldraw/state-react'
|
|
2
|
-
import React, { useMemo } from 'react'
|
|
2
|
+
import React, { useEffect, useMemo } from 'react'
|
|
3
3
|
import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
4
4
|
import {
|
|
5
|
+
markEventAsHandled,
|
|
5
6
|
preventDefault,
|
|
6
7
|
releasePointerCapture,
|
|
7
8
|
setPointerCapture,
|
|
8
|
-
|
|
9
|
+
wasEventAlreadyHandled,
|
|
9
10
|
} from '../utils/dom'
|
|
10
11
|
import { getPointerInfo } from '../utils/getPointerInfo'
|
|
11
12
|
import { useEditor } from './useEditor'
|
|
@@ -16,11 +17,8 @@ export function useCanvasEvents() {
|
|
|
16
17
|
|
|
17
18
|
const events = useMemo(
|
|
18
19
|
function canvasEvents() {
|
|
19
|
-
// Track the last screen point
|
|
20
|
-
let lastX: number, lastY: number
|
|
21
|
-
|
|
22
20
|
function onPointerDown(e: React.PointerEvent) {
|
|
23
|
-
if ((e
|
|
21
|
+
if (wasEventAlreadyHandled(e)) return
|
|
24
22
|
|
|
25
23
|
if (e.button === RIGHT_MOUSE_BUTTON) {
|
|
26
24
|
editor.dispatch({
|
|
@@ -44,35 +42,9 @@ export function useCanvasEvents() {
|
|
|
44
42
|
})
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
function onPointerMove(e: React.PointerEvent) {
|
|
48
|
-
if ((e as any).isKilled) return
|
|
49
|
-
|
|
50
|
-
if (e.clientX === lastX && e.clientY === lastY) return
|
|
51
|
-
lastX = e.clientX
|
|
52
|
-
lastY = e.clientY
|
|
53
|
-
|
|
54
|
-
// For tools that benefit from a higher fidelity of events,
|
|
55
|
-
// we dispatch the coalesced events.
|
|
56
|
-
// N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.
|
|
57
|
-
const events =
|
|
58
|
-
currentTool.useCoalescedEvents && e.nativeEvent.getCoalescedEvents
|
|
59
|
-
? e.nativeEvent.getCoalescedEvents()
|
|
60
|
-
: [e]
|
|
61
|
-
for (const singleEvent of events) {
|
|
62
|
-
editor.dispatch({
|
|
63
|
-
type: 'pointer',
|
|
64
|
-
target: 'canvas',
|
|
65
|
-
name: 'pointer_move',
|
|
66
|
-
...getPointerInfo(singleEvent),
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
45
|
function onPointerUp(e: React.PointerEvent) {
|
|
72
|
-
if ((e
|
|
46
|
+
if (wasEventAlreadyHandled(e)) return
|
|
73
47
|
if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
|
|
74
|
-
lastX = e.clientX
|
|
75
|
-
lastY = e.clientY
|
|
76
48
|
|
|
77
49
|
releasePointerCapture(e.currentTarget, e)
|
|
78
50
|
|
|
@@ -85,50 +57,54 @@ export function useCanvasEvents() {
|
|
|
85
57
|
}
|
|
86
58
|
|
|
87
59
|
function onPointerEnter(e: React.PointerEvent) {
|
|
88
|
-
if ((e
|
|
60
|
+
if (wasEventAlreadyHandled(e)) return
|
|
89
61
|
if (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return
|
|
90
62
|
const canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'
|
|
91
63
|
editor.updateInstanceState({ isHoveringCanvas: canHover ? true : null })
|
|
92
64
|
}
|
|
93
65
|
|
|
94
66
|
function onPointerLeave(e: React.PointerEvent) {
|
|
95
|
-
if ((e
|
|
67
|
+
if (wasEventAlreadyHandled(e)) return
|
|
96
68
|
if (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return
|
|
97
69
|
const canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'
|
|
98
70
|
editor.updateInstanceState({ isHoveringCanvas: canHover ? false : null })
|
|
99
71
|
}
|
|
100
72
|
|
|
101
73
|
function onTouchStart(e: React.TouchEvent) {
|
|
102
|
-
|
|
74
|
+
if (wasEventAlreadyHandled(e)) return
|
|
75
|
+
markEventAsHandled(e)
|
|
103
76
|
preventDefault(e)
|
|
104
77
|
}
|
|
105
78
|
|
|
106
79
|
function onTouchEnd(e: React.TouchEvent) {
|
|
107
|
-
|
|
80
|
+
if (wasEventAlreadyHandled(e)) return
|
|
81
|
+
markEventAsHandled(e)
|
|
108
82
|
// check that e.target is an HTMLElement
|
|
109
83
|
if (!(e.target instanceof HTMLElement)) return
|
|
110
84
|
|
|
85
|
+
const editingShapeId = editor.getEditingShape()?.id
|
|
111
86
|
if (
|
|
87
|
+
// if the target is not inside the editing shape
|
|
88
|
+
!(editingShapeId && e.target.closest(`[data-shape-id="${editingShapeId}"]`)) &&
|
|
89
|
+
// and the target is not an clickable element
|
|
112
90
|
e.target.tagName !== 'A' &&
|
|
91
|
+
// or a TextArea.tsx ?
|
|
113
92
|
e.target.tagName !== 'TEXTAREA' &&
|
|
114
|
-
!e.target.isContentEditable
|
|
115
|
-
// When in EditingShape state, we are actually clicking on a 'DIV'
|
|
116
|
-
// not A/TEXTAREA/contenteditable element yet. So, to preserve cursor position
|
|
117
|
-
// for edit mode on mobile we need to not preventDefault.
|
|
118
|
-
// TODO: Find out if we still need this preventDefault in general though.
|
|
119
|
-
!(editor.getEditingShape() && e.target.className.includes('tl-text-content'))
|
|
93
|
+
!e.target.isContentEditable
|
|
120
94
|
) {
|
|
121
95
|
preventDefault(e)
|
|
122
96
|
}
|
|
123
97
|
}
|
|
124
98
|
|
|
125
99
|
function onDragOver(e: React.DragEvent<Element>) {
|
|
100
|
+
if (wasEventAlreadyHandled(e)) return
|
|
126
101
|
preventDefault(e)
|
|
127
102
|
}
|
|
128
103
|
|
|
129
104
|
async function onDrop(e: React.DragEvent<Element>) {
|
|
105
|
+
if (wasEventAlreadyHandled(e)) return
|
|
130
106
|
preventDefault(e)
|
|
131
|
-
|
|
107
|
+
e.stopPropagation()
|
|
132
108
|
|
|
133
109
|
if (e.dataTransfer?.files?.length) {
|
|
134
110
|
const files = Array.from(e.dataTransfer.files)
|
|
@@ -153,12 +129,12 @@ export function useCanvasEvents() {
|
|
|
153
129
|
}
|
|
154
130
|
|
|
155
131
|
function onClick(e: React.MouseEvent) {
|
|
156
|
-
|
|
132
|
+
if (wasEventAlreadyHandled(e)) return
|
|
133
|
+
e.stopPropagation()
|
|
157
134
|
}
|
|
158
135
|
|
|
159
136
|
return {
|
|
160
137
|
onPointerDown,
|
|
161
|
-
onPointerMove,
|
|
162
138
|
onPointerUp,
|
|
163
139
|
onPointerEnter,
|
|
164
140
|
onPointerLeave,
|
|
@@ -169,8 +145,45 @@ export function useCanvasEvents() {
|
|
|
169
145
|
onClick,
|
|
170
146
|
}
|
|
171
147
|
},
|
|
172
|
-
[editor
|
|
148
|
+
[editor]
|
|
173
149
|
)
|
|
174
150
|
|
|
151
|
+
// onPointerMove is special: where we're only interested in the other events when they're
|
|
152
|
+
// happening _on_ the canvas (as opposed to outside of it, or on UI floating over it), we want
|
|
153
|
+
// the pointer position to be up to date regardless of whether it's over the tldraw canvas or
|
|
154
|
+
// not. So instead of returning a listener to be attached to the canvas, we directly attach a
|
|
155
|
+
// listener to the whole document instead.
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
let lastX: number, lastY: number
|
|
158
|
+
|
|
159
|
+
function onPointerMove(e: PointerEvent) {
|
|
160
|
+
if (wasEventAlreadyHandled(e)) return
|
|
161
|
+
markEventAsHandled(e)
|
|
162
|
+
|
|
163
|
+
if (e.clientX === lastX && e.clientY === lastY) return
|
|
164
|
+
lastX = e.clientX
|
|
165
|
+
lastY = e.clientY
|
|
166
|
+
|
|
167
|
+
// For tools that benefit from a higher fidelity of events,
|
|
168
|
+
// we dispatch the coalesced events.
|
|
169
|
+
// N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.
|
|
170
|
+
const events =
|
|
171
|
+
currentTool.useCoalescedEvents && e.getCoalescedEvents ? e.getCoalescedEvents() : [e]
|
|
172
|
+
for (const singleEvent of events) {
|
|
173
|
+
editor.dispatch({
|
|
174
|
+
type: 'pointer',
|
|
175
|
+
target: 'canvas',
|
|
176
|
+
name: 'pointer_move',
|
|
177
|
+
...getPointerInfo(singleEvent),
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
document.body.addEventListener('pointermove', onPointerMove)
|
|
183
|
+
return () => {
|
|
184
|
+
document.body.removeEventListener('pointermove', onPointerMove)
|
|
185
|
+
}
|
|
186
|
+
}, [editor, currentTool])
|
|
187
|
+
|
|
175
188
|
return events
|
|
176
189
|
}
|
|
@@ -2,7 +2,12 @@ import { useValue } from '@tldraw/state-react'
|
|
|
2
2
|
import { useEffect } from 'react'
|
|
3
3
|
import { Editor } from '../editor/Editor'
|
|
4
4
|
import { TLKeyboardEventInfo } from '../editor/types/event-types'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
activeElementShouldCaptureKeys,
|
|
7
|
+
markEventAsHandled,
|
|
8
|
+
preventDefault,
|
|
9
|
+
wasEventAlreadyHandled,
|
|
10
|
+
} from '../utils/dom'
|
|
6
11
|
import { isAccelKey } from '../utils/keyboard'
|
|
7
12
|
import { useContainer } from './useContainer'
|
|
8
13
|
import { useEditor } from './useEditor'
|
|
@@ -29,7 +34,7 @@ export function useDocumentEvents() {
|
|
|
29
34
|
// re-dispatched, which would lead to an infinite loop.
|
|
30
35
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
31
36
|
preventDefault(e)
|
|
32
|
-
|
|
37
|
+
e.stopPropagation()
|
|
33
38
|
const cvs = container.querySelector('.tl-canvas')
|
|
34
39
|
if (!cvs) return
|
|
35
40
|
const newEvent = new DragEvent(e.type, e)
|
|
@@ -103,8 +108,8 @@ export function useDocumentEvents() {
|
|
|
103
108
|
preventDefault(e)
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
if ((e
|
|
107
|
-
|
|
111
|
+
if (wasEventAlreadyHandled(e)) return
|
|
112
|
+
markEventAsHandled(e)
|
|
108
113
|
const hasSelectedShapes = !!editor.getSelectedShapeIds().length
|
|
109
114
|
|
|
110
115
|
switch (e.key) {
|
|
@@ -211,8 +216,8 @@ export function useDocumentEvents() {
|
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
const handleKeyUp = (e: KeyboardEvent) => {
|
|
214
|
-
if ((e
|
|
215
|
-
|
|
219
|
+
if (wasEventAlreadyHandled(e)) return
|
|
220
|
+
markEventAsHandled(e)
|
|
216
221
|
|
|
217
222
|
if (areShortcutsDisabled(editor)) {
|
|
218
223
|
return
|
|
@@ -21,13 +21,14 @@ export function useMaybeEditor(): Editor | null {
|
|
|
21
21
|
return React.useContext(EditorContext)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
children,
|
|
27
|
-
}: {
|
|
24
|
+
/** @public */
|
|
25
|
+
export interface EditorProviderProps {
|
|
28
26
|
editor: Editor
|
|
29
27
|
children: React.ReactNode
|
|
30
|
-
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @public @react */
|
|
31
|
+
export function EditorProvider({ editor, children }: EditorProviderProps) {
|
|
31
32
|
return (
|
|
32
33
|
<EditorContext.Provider value={editor}>
|
|
33
34
|
<IdProvider>{children}</IdProvider>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType, ReactNode, createContext, useContext, useMemo } from 'react'
|
|
1
|
+
import { ComponentType, ReactNode, RefAttributes, createContext, useContext, useMemo } from 'react'
|
|
2
2
|
import { DefaultBackground } from '../components/default-components/DefaultBackground'
|
|
3
3
|
import { DefaultBrush, TLBrushProps } from '../components/default-components/DefaultBrush'
|
|
4
4
|
import {
|
|
@@ -37,6 +37,10 @@ import {
|
|
|
37
37
|
TLShapeIndicatorErrorFallbackComponent,
|
|
38
38
|
} from '../components/default-components/DefaultShapeIndicatorErrorFallback'
|
|
39
39
|
import { DefaultShapeIndicators } from '../components/default-components/DefaultShapeIndicators'
|
|
40
|
+
import {
|
|
41
|
+
DefaultShapeWrapper,
|
|
42
|
+
TLShapeWrapperProps,
|
|
43
|
+
} from '../components/default-components/DefaultShapeWrapper'
|
|
40
44
|
import {
|
|
41
45
|
DefaultSnapIndicator,
|
|
42
46
|
TLSnapIndicatorProps,
|
|
@@ -68,8 +72,9 @@ export interface TLEditorComponents {
|
|
|
68
72
|
SelectionForeground?: ComponentType<TLSelectionForegroundProps> | null
|
|
69
73
|
ShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
|
|
70
74
|
ShapeIndicators?: ComponentType | null
|
|
75
|
+
ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null
|
|
71
76
|
SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null
|
|
72
|
-
Spinner?: ComponentType | null
|
|
77
|
+
Spinner?: ComponentType<React.SVGProps<SVGSVGElement>> | null
|
|
73
78
|
SvgDefs?: ComponentType | null
|
|
74
79
|
ZoomBrush?: ComponentType<TLBrushProps> | null
|
|
75
80
|
|
|
@@ -114,6 +119,7 @@ export function EditorComponentsProvider({
|
|
|
114
119
|
SelectionForeground: DefaultSelectionForeground,
|
|
115
120
|
ShapeIndicator: DefaultShapeIndicator,
|
|
116
121
|
ShapeIndicators: DefaultShapeIndicators,
|
|
122
|
+
ShapeWrapper: DefaultShapeWrapper,
|
|
117
123
|
SnapIndicator: DefaultSnapIndicator,
|
|
118
124
|
Spinner: DefaultSpinner,
|
|
119
125
|
SvgDefs: DefaultSvgDefs,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react'
|
|
2
|
-
import { preventDefault } from '../utils/dom'
|
|
2
|
+
import { markEventAsHandled, preventDefault } from '../utils/dom'
|
|
3
3
|
import { useEditor } from './useEditor'
|
|
4
4
|
|
|
5
5
|
const IGNORED_TAGS = ['textarea', 'input']
|
|
@@ -19,7 +19,7 @@ export function useFixSafariDoubleTapZoomPencilEvents(ref: React.RefObject<HTMLE
|
|
|
19
19
|
|
|
20
20
|
const handleEvent = (e: PointerEvent | TouchEvent) => {
|
|
21
21
|
if (e instanceof PointerEvent && e.pointerType === 'pen') {
|
|
22
|
-
|
|
22
|
+
markEventAsHandled(e)
|
|
23
23
|
const { target } = e
|
|
24
24
|
|
|
25
25
|
// Allow events to propagate if the app is editing a shape, or if the event is occurring in a text area or input
|
|
@@ -3,7 +3,7 @@ import { createUseGesture, pinchAction, wheelAction } from '@use-gesture/react'
|
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
import { TLWheelEventInfo } from '../editor/types/event-types'
|
|
5
5
|
import { Vec } from '../primitives/Vec'
|
|
6
|
-
import { preventDefault
|
|
6
|
+
import { preventDefault } from '../utils/dom'
|
|
7
7
|
import { isAccelKey } from '../utils/keyboard'
|
|
8
8
|
import { normalizeWheel } from '../utils/normalizeWheel'
|
|
9
9
|
import { useEditor } from './useEditor'
|
|
@@ -113,7 +113,7 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
preventDefault(event)
|
|
116
|
-
|
|
116
|
+
event.stopPropagation()
|
|
117
117
|
const delta = normalizeWheel(event)
|
|
118
118
|
|
|
119
119
|
if (delta.x === 0 && delta.y === 0) return
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { TLArrowShape, TLLineShape, TLShapeId } from '@tldraw/tlschema'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import { Editor } from '../editor/Editor'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
loopToHtmlElement,
|
|
6
|
+
releasePointerCapture,
|
|
7
|
+
setPointerCapture,
|
|
8
|
+
wasEventAlreadyHandled,
|
|
9
|
+
} from '../utils/dom'
|
|
5
10
|
import { getPointerInfo } from '../utils/getPointerInfo'
|
|
6
11
|
import { useEditor } from './useEditor'
|
|
7
12
|
|
|
@@ -16,7 +21,7 @@ export function useHandleEvents(id: TLShapeId, handleId: string) {
|
|
|
16
21
|
|
|
17
22
|
return React.useMemo(() => {
|
|
18
23
|
const onPointerDown = (e: React.PointerEvent) => {
|
|
19
|
-
if ((e
|
|
24
|
+
if (wasEventAlreadyHandled(e)) return
|
|
20
25
|
|
|
21
26
|
// Must set pointer capture on an HTML element!
|
|
22
27
|
const target = loopToHtmlElement(e.currentTarget)
|
|
@@ -40,7 +45,7 @@ export function useHandleEvents(id: TLShapeId, handleId: string) {
|
|
|
40
45
|
let lastX: number, lastY: number
|
|
41
46
|
|
|
42
47
|
const onPointerMove = (e: React.PointerEvent) => {
|
|
43
|
-
if ((e
|
|
48
|
+
if (wasEventAlreadyHandled(e)) return
|
|
44
49
|
if (e.clientX === lastX && e.clientY === lastY) return
|
|
45
50
|
lastX = e.clientX
|
|
46
51
|
lastY = e.clientY
|
|
@@ -60,7 +65,7 @@ export function useHandleEvents(id: TLShapeId, handleId: string) {
|
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
const onPointerUp = (e: React.PointerEvent) => {
|
|
63
|
-
if ((e
|
|
68
|
+
if (wasEventAlreadyHandled(e)) return
|
|
64
69
|
|
|
65
70
|
const target = loopToHtmlElement(e.currentTarget)
|
|
66
71
|
releasePointerCapture(target, e)
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { RefObject, useEffect } from 'react'
|
|
2
2
|
import { preventDefault } from '../utils/dom'
|
|
3
3
|
import { useContainer } from './useContainer'
|
|
4
|
+
import { useMaybeEditor } from './useEditor'
|
|
4
5
|
|
|
5
6
|
/** @public */
|
|
6
7
|
export function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {
|
|
7
8
|
if (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')
|
|
8
9
|
const container = useContainer()
|
|
10
|
+
const editor = useMaybeEditor()
|
|
9
11
|
|
|
10
12
|
useEffect(() => {
|
|
11
13
|
function onMouseOver(e: MouseEvent) {
|
|
14
|
+
if (!editor?.getInstanceState().isFocused) return
|
|
12
15
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
13
16
|
preventDefault(e)
|
|
14
17
|
const cvs = container.querySelector('.tl-canvas')
|
|
@@ -25,5 +28,5 @@ export function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {
|
|
|
25
28
|
return () => {
|
|
26
29
|
elm.removeEventListener('mouseover', onMouseOver)
|
|
27
30
|
}
|
|
28
|
-
}, [container, ref])
|
|
31
|
+
}, [container, editor, ref])
|
|
29
32
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { RefObject, useEffect } from 'react'
|
|
2
2
|
import { preventDefault } from '../utils/dom'
|
|
3
3
|
import { useContainer } from './useContainer'
|
|
4
|
+
import { useMaybeEditor } from './useEditor'
|
|
4
5
|
|
|
5
6
|
/** @public */
|
|
6
7
|
export function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {
|
|
7
8
|
if (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')
|
|
8
9
|
const container = useContainer()
|
|
10
|
+
const editor = useMaybeEditor()
|
|
9
11
|
|
|
10
12
|
useEffect(() => {
|
|
11
13
|
function onWheel(e: WheelEvent) {
|
|
14
|
+
// Only pass through wheel events if the editor is focused
|
|
15
|
+
if (!editor?.getInstanceState().isFocused) return
|
|
16
|
+
|
|
12
17
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
13
18
|
|
|
14
19
|
// if the element is scrollable, don't redispatch the event
|
|
@@ -32,5 +37,5 @@ export function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {
|
|
|
32
37
|
return () => {
|
|
33
38
|
elm.removeEventListener('wheel', onWheel)
|
|
34
39
|
}
|
|
35
|
-
}, [container, ref])
|
|
40
|
+
}, [container, editor, ref])
|
|
36
41
|
}
|
|
@@ -3,9 +3,10 @@ import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
|
3
3
|
import { TLSelectionHandle } from '../editor/types/selection-types'
|
|
4
4
|
import {
|
|
5
5
|
loopToHtmlElement,
|
|
6
|
+
markEventAsHandled,
|
|
6
7
|
releasePointerCapture,
|
|
7
8
|
setPointerCapture,
|
|
8
|
-
|
|
9
|
+
wasEventAlreadyHandled,
|
|
9
10
|
} from '../utils/dom'
|
|
10
11
|
import { getPointerInfo } from '../utils/getPointerInfo'
|
|
11
12
|
import { useEditor } from './useEditor'
|
|
@@ -17,7 +18,7 @@ export function useSelectionEvents(handle: TLSelectionHandle) {
|
|
|
17
18
|
const events = useMemo(
|
|
18
19
|
function selectionEvents() {
|
|
19
20
|
const onPointerDown: React.PointerEventHandler = (e) => {
|
|
20
|
-
if ((e
|
|
21
|
+
if (wasEventAlreadyHandled(e)) return
|
|
21
22
|
|
|
22
23
|
if (e.button === RIGHT_MOUSE_BUTTON) {
|
|
23
24
|
editor.dispatch({
|
|
@@ -54,14 +55,14 @@ export function useSelectionEvents(handle: TLSelectionHandle) {
|
|
|
54
55
|
handle,
|
|
55
56
|
...getPointerInfo(e),
|
|
56
57
|
})
|
|
57
|
-
|
|
58
|
+
markEventAsHandled(e)
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
// Track the last screen point
|
|
61
62
|
let lastX: number, lastY: number
|
|
62
63
|
|
|
63
64
|
function onPointerMove(e: React.PointerEvent) {
|
|
64
|
-
if ((e
|
|
65
|
+
if (wasEventAlreadyHandled(e)) return
|
|
65
66
|
if (e.button !== 0) return
|
|
66
67
|
if (e.clientX === lastX && e.clientY === lastY) return
|
|
67
68
|
lastX = e.clientX
|
|
@@ -77,7 +78,7 @@ export function useSelectionEvents(handle: TLSelectionHandle) {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
const onPointerUp: React.PointerEventHandler = (e) => {
|
|
80
|
-
if ((e
|
|
81
|
+
if (wasEventAlreadyHandled(e)) return
|
|
81
82
|
if (e.button !== 0) return
|
|
82
83
|
|
|
83
84
|
editor.dispatch({
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { react } from '@tldraw/state'
|
|
2
|
+
import { useLayoutEffect } from 'react'
|
|
3
|
+
import { useEditor } from './useEditor'
|
|
4
|
+
|
|
5
|
+
export function useStateAttribute() {
|
|
6
|
+
const editor = useEditor()
|
|
7
|
+
|
|
8
|
+
// we use a layout effect because we don't want there to be any perceptible delay between the
|
|
9
|
+
// editor mounting and this attribute being applied, because styles may depend on it:
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
return react('stateAttribute', () => {
|
|
12
|
+
editor.getContainer().setAttribute('data-state', editor.getPath())
|
|
13
|
+
})
|
|
14
|
+
}, [editor])
|
|
15
|
+
}
|