tldraw 5.4.0-next.ef99ab47e5ce → 5.4.0
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/DOCS.md +2826 -3226
- package/RELEASE_NOTES.md +190 -2
- package/dist-cjs/index.d.ts +264 -275
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/defaultExternalContentHandlers.js +32 -16
- package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/curved-arrow.js +2 -2
- package/dist-cjs/lib/shapes/arrow/curved-arrow.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/elbow/getElbowArrowInfo.js +2 -2
- package/dist-cjs/lib/shapes/arrow/elbow/getElbowArrowInfo.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/getArrowInfo.js +1 -1
- package/dist-cjs/lib/shapes/arrow/getArrowInfo.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/straight-arrow.js +2 -2
- package/dist-cjs/lib/shapes/arrow/straight-arrow.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/toolStates/Idle.js +2 -3
- package/dist-cjs/lib/shapes/arrow/toolStates/Idle.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +7 -5
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js +8 -6
- package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/getGeoShapePath.js +3 -1
- package/dist-cjs/lib/shapes/geo/getGeoShapePath.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/toolStates/Idle.js +2 -3
- package/dist-cjs/lib/shapes/geo/toolStates/Idle.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js +2 -6
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/note/noteHelpers.js +6 -5
- package/dist-cjs/lib/shapes/note/noteHelpers.js.map +2 -2
- package/dist-cjs/lib/shapes/note/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/note/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/crop.js +1 -1
- package/dist-cjs/lib/shapes/shared/crop.js.map +2 -2
- package/dist-cjs/lib/shapes/text/toolStates/Idle.js +1 -1
- package/dist-cjs/lib/shapes/text/toolStates/Idle.js.map +2 -2
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js +1 -0
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -2
- package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +2 -2
- package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +2 -0
- package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
- package/dist-cjs/lib/tools/HandTool/childStates/OneFingerZooming.js +6 -0
- package/dist-cjs/lib/tools/HandTool/childStates/OneFingerZooming.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/SelectTool.js +3 -0
- package/dist-cjs/lib/tools/SelectTool/SelectTool.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Brushing.js +1 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Brushing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/Crop.js +1 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/Crop.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +1 -3
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +6 -3
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingCanvas.js +3 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingCanvas.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingHandle.js +1 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +22 -30
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/ScribbleBrushing.js +1 -3
- package/dist-cjs/lib/tools/SelectTool/childStates/ScribbleBrushing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +4 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/selectHelpers.js +10 -0
- package/dist-cjs/lib/tools/SelectTool/selectHelpers.js.map +2 -2
- package/dist-cjs/lib/ui/TldrawUi.js +2 -3
- package/dist-cjs/lib/ui/TldrawUi.js.map +2 -2
- package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +1 -11
- package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenu.js +6 -1
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenuContent.js +1 -1
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenuContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/Dialogs.js +8 -0
- package/dist-cjs/lib/ui/components/Dialogs.js.map +2 -2
- package/dist-cjs/lib/ui/components/EditLinkDialog.js +5 -5
- package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
- package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +4 -20
- package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuItem.js +1 -2
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuItem.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js +2 -0
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +1 -0
- package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +10 -8
- package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +20 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +8 -8
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +2 -0
- package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useCommentingEnabled.js +1 -1
- package/dist-cjs/lib/ui/hooks/useCommentingEnabled.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useFlatten.js +42 -23
- package/dist-cjs/lib/ui/hooks/useFlatten.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-esm/index.d.mts +264 -275
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/defaultExternalContentHandlers.mjs +32 -16
- package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/curved-arrow.mjs +2 -2
- package/dist-esm/lib/shapes/arrow/curved-arrow.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/elbow/getElbowArrowInfo.mjs +2 -2
- package/dist-esm/lib/shapes/arrow/elbow/getElbowArrowInfo.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/getArrowInfo.mjs +1 -1
- package/dist-esm/lib/shapes/arrow/getArrowInfo.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/straight-arrow.mjs +2 -2
- package/dist-esm/lib/shapes/arrow/straight-arrow.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/toolStates/Idle.mjs +3 -4
- package/dist-esm/lib/shapes/arrow/toolStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +7 -5
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs +8 -6
- package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/getGeoShapePath.mjs +3 -1
- package/dist-esm/lib/shapes/geo/getGeoShapePath.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/toolStates/Idle.mjs +3 -4
- package/dist-esm/lib/shapes/geo/toolStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs +1 -1
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs +2 -7
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +4 -4
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/noteHelpers.mjs +6 -5
- package/dist-esm/lib/shapes/note/noteHelpers.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs +1 -1
- package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/crop.mjs +1 -1
- package/dist-esm/lib/shapes/shared/crop.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/toolStates/Idle.mjs +2 -2
- package/dist-esm/lib/shapes/text/toolStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs +1 -0
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -2
- package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +2 -0
- package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
- package/dist-esm/lib/tools/HandTool/childStates/OneFingerZooming.mjs +6 -0
- package/dist-esm/lib/tools/HandTool/childStates/OneFingerZooming.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/SelectTool.mjs +3 -0
- package/dist-esm/lib/tools/SelectTool/SelectTool.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Brushing.mjs +1 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Brushing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/Crop.mjs +1 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/Crop.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +1 -3
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +6 -3
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs +1 -1
- package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingCanvas.mjs +3 -0
- package/dist-esm/lib/tools/SelectTool/childStates/PointingCanvas.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs +5 -1
- package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +1 -1
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +22 -31
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/ScribbleBrushing.mjs +1 -3
- package/dist-esm/lib/tools/SelectTool/childStates/ScribbleBrushing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +4 -1
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/selectHelpers.mjs +10 -0
- package/dist-esm/lib/tools/SelectTool/selectHelpers.mjs.map +2 -2
- package/dist-esm/lib/ui/TldrawUi.mjs +2 -3
- package/dist-esm/lib/ui/TldrawUi.mjs.map +2 -2
- package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +2 -12
- package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenu.mjs +7 -2
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenuContent.mjs +1 -1
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenuContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Dialogs.mjs +9 -1
- package/dist-esm/lib/ui/components/Dialogs.mjs.map +2 -2
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs +5 -5
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs +5 -22
- package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuItem.mjs +1 -2
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuItem.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs +2 -0
- package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +1 -0
- package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +10 -8
- package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +20 -1
- package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +8 -8
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +2 -0
- package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useCommentingEnabled.mjs +2 -2
- package/dist-esm/lib/ui/hooks/useCommentingEnabled.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useFlatten.mjs +42 -23
- package/dist-esm/lib/ui/hooks/useFlatten.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/package.json +12 -6
- package/src/lib/defaultExternalContentHandlers.test.ts +43 -0
- package/src/lib/defaultExternalContentHandlers.ts +40 -18
- package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +17 -0
- package/src/lib/shapes/arrow/curved-arrow.ts +2 -2
- package/src/lib/shapes/arrow/elbow/getElbowArrowInfo.tsx +5 -3
- package/src/lib/shapes/arrow/getArrowInfo.ts +2 -1
- package/src/lib/shapes/arrow/straight-arrow.ts +2 -2
- package/src/lib/shapes/arrow/toolStates/Idle.tsx +3 -4
- package/src/lib/shapes/arrow/toolStates/Pointing.tsx +10 -6
- package/src/lib/shapes/draw/DrawShapeTool.test.ts +19 -0
- package/src/lib/shapes/draw/toolStates/Drawing.ts +12 -6
- package/src/lib/shapes/frame/FrameShapeTool.test.ts +17 -0
- package/src/lib/shapes/geo/GeoShapeTool.test.ts +28 -0
- package/src/lib/shapes/geo/getGeoShapePath.ts +3 -1
- package/src/lib/shapes/geo/toolStates/Idle.ts +3 -4
- package/src/lib/shapes/geo/toolStates/Pointing.ts +2 -1
- package/src/lib/shapes/line/LineShapeTool.test.ts +30 -1
- package/src/lib/shapes/line/toolStates/Pointing.ts +6 -7
- package/src/lib/shapes/note/NoteShapeTool.test.ts +45 -0
- package/src/lib/shapes/note/NoteShapeUtil.tsx +7 -4
- package/src/lib/shapes/note/noteHelpers.ts +18 -8
- package/src/lib/shapes/note/toolStates/Pointing.ts +2 -1
- package/src/lib/shapes/shared/crop.ts +7 -1
- package/src/lib/shapes/text/TextShapeTool.test.ts +33 -0
- package/src/lib/shapes/text/toolStates/Idle.ts +2 -2
- package/src/lib/shapes/text/toolStates/Pointing.ts +3 -0
- package/src/lib/shapes/video/VideoShapeUtil.tsx +4 -2
- package/src/lib/tools/EraserTool/childStates/Erasing.ts +5 -0
- package/src/lib/tools/HandTool/childStates/OneFingerZooming.ts +10 -0
- package/src/lib/tools/SelectTool/SelectTool.ts +4 -0
- package/src/lib/tools/SelectTool/childStates/Brushing.ts +4 -0
- package/src/lib/tools/SelectTool/childStates/Crop/Crop.ts +4 -0
- package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +3 -4
- package/src/lib/tools/SelectTool/childStates/Idle.ts +10 -3
- package/src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts +1 -1
- package/src/lib/tools/SelectTool/childStates/PointingCanvas.ts +4 -0
- package/src/lib/tools/SelectTool/childStates/PointingHandle.ts +6 -1
- package/src/lib/tools/SelectTool/childStates/PointingShape.ts +4 -1
- package/src/lib/tools/SelectTool/childStates/Resizing.ts +30 -33
- package/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts +3 -3
- package/src/lib/tools/SelectTool/childStates/Translating.ts +6 -0
- package/src/lib/tools/SelectTool/selectHelpers.ts +21 -0
- package/src/lib/ui/TldrawUi.tsx +1 -2
- package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +4 -14
- package/src/lib/ui/components/ContextMenu/DefaultContextMenu.tsx +8 -2
- package/src/lib/ui/components/ContextMenu/DefaultContextMenuContent.tsx +5 -1
- package/src/lib/ui/components/Dialogs.tsx +17 -1
- package/src/lib/ui/components/EditLinkDialog.tsx +8 -7
- package/src/lib/ui/components/Minimap/DefaultMinimap.tsx +5 -23
- package/src/lib/ui/components/SharePanel/DefaultPeopleMenuItem.tsx +2 -3
- package/src/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.tsx +2 -0
- package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +1 -0
- package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +13 -8
- package/src/lib/ui/components/primitives/TldrawUiSlider.test.tsx +92 -0
- package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +25 -1
- package/src/lib/ui/context/actions.tsx +25 -8
- package/src/lib/ui/hooks/useClipboardEvents.ts +2 -0
- package/src/lib/ui/hooks/useCommentingEnabled.ts +5 -3
- package/src/lib/ui/hooks/useFlatten.ts +56 -23
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/ui.css +7 -16
- package/src/test/ClickManager.test.ts +18 -0
- package/src/test/Editor.test.tsx +3 -0
- package/src/test/EraserTool.test.ts +18 -2
- package/src/test/HandTool.test.ts +21 -0
- package/src/test/LaserTool.test.ts +46 -0
- package/src/test/ScribbleManager.test.ts +19 -0
- package/src/test/SelectTool.test.ts +110 -0
- package/src/test/TldrawEditor.test.tsx +18 -0
- package/src/test/VideoShapeUtil.test.tsx +126 -0
- package/src/test/actions-menu-readonly.test.tsx +37 -0
- package/src/test/bookmark-shapes.test.ts +110 -0
- package/src/test/commands/__snapshots__/packShapes.test.ts.snap +6 -6
- package/src/test/commands/clipboard.test.ts +36 -1
- package/src/test/commands/lockShapes.test.ts +11 -0
- package/src/test/commands/packShapes.test.ts +20 -0
- package/src/test/commands/putContent.test.ts +35 -1
- package/src/test/commands/setCamera.test.ts +69 -0
- package/src/test/commands/stackShapes.test.ts +12 -0
- package/src/test/commands/updateViewportPageBounds.test.ts +8 -0
- package/src/test/cropping.test.ts +162 -0
- package/src/test/customSnapping.test.tsx +32 -0
- package/src/test/defaultHandleExternalFileContent.test.ts +86 -0
- package/src/test/drawing.test.ts +60 -1
- package/src/test/duplicate.test.ts +22 -0
- package/src/test/flatten.test.ts +135 -0
- package/src/test/frames.test.ts +51 -0
- package/src/test/getShapeAtPoint.test.ts +44 -1
- package/src/test/handleDeepLink.test.tsx +15 -0
- package/src/test/minimap-wheel.test.tsx +48 -0
- package/src/test/resizing.test.ts +46 -0
- package/src/test/selection-omnibus.test.ts +50 -0
- package/src/test/spacebarPanning.test.ts +58 -0
- package/src/test/translating.test.ts +42 -0
- package/src/test/ui/AltTextEditor.test.tsx +51 -0
- package/src/test/ui/ContextMenu.test.tsx +61 -2
- package/src/test/ui/EditLinkDialog.test.tsx +77 -0
- package/src/test/ui/ImageToolbar.test.tsx +58 -0
- package/src/test/ui/StylePanel.test.tsx +33 -2
- package/src/test/ui/keyboardShortcuts.test.tsx +27 -0
- package/src/test/ui/presenceActivity.test.tsx +44 -0
- package/src/test/ui/unlockAll.test.tsx +55 -0
- package/src/test/ui-outside-editor.test.tsx +74 -0
- package/src/test/viewport-following.test.ts +29 -1
- package/tldraw.css +7 -16
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AssetRecordType, TLBookmarkShape, createShapeId, getHashForString } from '@tldraw/editor'
|
|
2
2
|
import { vi } from 'vitest'
|
|
3
|
+
import { defaultHandleExternalUrlAsset } from '../lib/defaultExternalContentHandlers'
|
|
3
4
|
import {
|
|
4
5
|
createBookmarkFromUrl,
|
|
5
6
|
getBookmarkShapeHeight,
|
|
@@ -482,3 +483,112 @@ describe('createBookmarkFromUrl', () => {
|
|
|
482
483
|
expect(editor.getShapeGeometry(redone.id).bounds.height).toBe(shortHeight)
|
|
483
484
|
})
|
|
484
485
|
})
|
|
486
|
+
|
|
487
|
+
describe('defaultHandleExternalUrlAsset', () => {
|
|
488
|
+
const url = 'https://example.com/some/page'
|
|
489
|
+
|
|
490
|
+
let opts: any
|
|
491
|
+
let fetchMock: ReturnType<typeof vi.fn>
|
|
492
|
+
|
|
493
|
+
beforeEach(() => {
|
|
494
|
+
opts = {
|
|
495
|
+
toasts: { addToast: vi.fn(), removeToast: vi.fn(), clearToasts: vi.fn() },
|
|
496
|
+
msg: (id: string) => id,
|
|
497
|
+
}
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
afterEach(() => {
|
|
501
|
+
vi.unstubAllGlobals()
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
function mockResponseBody(html: string) {
|
|
505
|
+
fetchMock = vi.fn().mockResolvedValue({ text: async () => html })
|
|
506
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function mockPageHead(head: string) {
|
|
510
|
+
mockResponseBody(`<html><head>${head}</head><body></body></html>`)
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
it('leaves the image and favicon empty when the page provides neither', async () => {
|
|
514
|
+
mockPageHead('<title>Example</title>')
|
|
515
|
+
|
|
516
|
+
const asset = await defaultHandleExternalUrlAsset(editor, { type: 'url', url }, opts)
|
|
517
|
+
|
|
518
|
+
expect(asset.props.image).toBe('')
|
|
519
|
+
expect(asset.props.favicon).toBe('')
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
it('resolves relative image and favicon urls against the page', async () => {
|
|
523
|
+
mockPageHead(
|
|
524
|
+
'<meta property="og:image" content="/img/preview.png" />' +
|
|
525
|
+
'<link rel="icon" href="favicon.ico" />'
|
|
526
|
+
)
|
|
527
|
+
|
|
528
|
+
const asset = await defaultHandleExternalUrlAsset(editor, { type: 'url', url }, opts)
|
|
529
|
+
|
|
530
|
+
expect(asset.props.image).toBe('https://example.com/img/preview.png')
|
|
531
|
+
expect(asset.props.favicon).toBe('https://example.com/some/favicon.ico')
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
it('leaves absolute image urls alone', async () => {
|
|
535
|
+
mockPageHead('<meta property="og:image" content="https://cdn.example.com/preview.png" />')
|
|
536
|
+
|
|
537
|
+
const asset = await defaultHandleExternalUrlAsset(editor, { type: 'url', url }, opts)
|
|
538
|
+
|
|
539
|
+
expect(asset.props.image).toBe('https://cdn.example.com/preview.png')
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
it('toasts and returns a blank bookmark when the fetch throws', async () => {
|
|
543
|
+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
544
|
+
fetchMock = vi.fn().mockRejectedValue(new Error('CORS'))
|
|
545
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
546
|
+
|
|
547
|
+
const asset = await defaultHandleExternalUrlAsset(editor, { type: 'url', url }, opts)
|
|
548
|
+
|
|
549
|
+
expect(opts.toasts.addToast).toHaveBeenCalledWith(
|
|
550
|
+
expect.objectContaining({ severity: 'error' })
|
|
551
|
+
)
|
|
552
|
+
expect(asset.props.src).toBe(url)
|
|
553
|
+
expect(asset.props.image).toBe('')
|
|
554
|
+
expect(asset.props.title).toBe('')
|
|
555
|
+
|
|
556
|
+
consoleSpy.mockRestore()
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
// Pins behaviour we'd like to change, so that changing it is deliberate.
|
|
560
|
+
describe('behaviour to revisit', () => {
|
|
561
|
+
it('extracts nothing at all from a cross-origin page', async () => {
|
|
562
|
+
// `mode: 'no-cors'` makes the response opaque cross-origin, and an
|
|
563
|
+
// opaque body always reads as ''.
|
|
564
|
+
mockResponseBody('')
|
|
565
|
+
|
|
566
|
+
const asset = await defaultHandleExternalUrlAsset(editor, { type: 'url', url }, opts)
|
|
567
|
+
|
|
568
|
+
expect(fetchMock).toHaveBeenCalledWith(url, expect.objectContaining({ mode: 'no-cors' }))
|
|
569
|
+
expect(asset.props.image).toBe('')
|
|
570
|
+
expect(asset.props.favicon).toBe('')
|
|
571
|
+
expect(asset.props.description).toBe('')
|
|
572
|
+
expect(asset.props.title).toBe(url)
|
|
573
|
+
expect(opts.toasts.addToast).not.toHaveBeenCalled()
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
it('ignores twitter card tags, og:image:secure_url and <title>', async () => {
|
|
577
|
+
mockPageHead(
|
|
578
|
+
'<title>Example</title>' +
|
|
579
|
+
'<meta property="og:image:secure_url" content="https://cdn.example.com/secure.png" />' +
|
|
580
|
+
'<meta name="twitter:image" content="https://cdn.example.com/twitter.png" />' +
|
|
581
|
+
'<meta name="twitter:title" content="Example, from twitter" />' +
|
|
582
|
+
'<meta name="description" content="A plain meta description" />'
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
const asset = await defaultHandleExternalUrlAsset(editor, { type: 'url', url }, opts)
|
|
586
|
+
|
|
587
|
+
// cloudflare-workers-unfurl reads all four of these; this handler
|
|
588
|
+
// reads only the plain `og:` tags.
|
|
589
|
+
expect(asset.props.image).toBe('')
|
|
590
|
+
expect(asset.props.description).toBe('')
|
|
591
|
+
expect(asset.props.title).toBe(url)
|
|
592
|
+
})
|
|
593
|
+
})
|
|
594
|
+
})
|
|
@@ -38,8 +38,8 @@ exports[`editor.packShapes > packs rotated shapes > packed shapes 1`] = `
|
|
|
38
38
|
"rotation": 3.141592653589793,
|
|
39
39
|
"type": "geo",
|
|
40
40
|
"typeName": "shape",
|
|
41
|
-
"x":
|
|
42
|
-
"y":
|
|
41
|
+
"x": 134,
|
|
42
|
+
"y": 250,
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
"id": "shape:boxB",
|
|
@@ -77,8 +77,8 @@ exports[`editor.packShapes > packs rotated shapes > packed shapes 1`] = `
|
|
|
77
77
|
"rotation": 0,
|
|
78
78
|
"type": "geo",
|
|
79
79
|
"typeName": "shape",
|
|
80
|
-
"x":
|
|
81
|
-
"y":
|
|
80
|
+
"x": 150,
|
|
81
|
+
"y": 150,
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
"id": "shape:boxC",
|
|
@@ -116,8 +116,8 @@ exports[`editor.packShapes > packs rotated shapes > packed shapes 1`] = `
|
|
|
116
116
|
"rotation": 0,
|
|
117
117
|
"type": "geo",
|
|
118
118
|
"typeName": "shape",
|
|
119
|
-
"x":
|
|
120
|
-
"y":
|
|
119
|
+
"x": 266,
|
|
120
|
+
"y": 150,
|
|
121
121
|
},
|
|
122
122
|
]
|
|
123
123
|
`;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { act, renderHook } from '@testing-library/react'
|
|
2
|
+
import { createShapeId, EditorContext, TLArrowShape } from '@tldraw/editor'
|
|
3
|
+
import { createElement } from 'react'
|
|
2
4
|
import { vi } from 'vitest'
|
|
3
5
|
import { getArrowBindings } from '../../lib/shapes/arrow/shared'
|
|
6
|
+
import { useMenuClipboardEvents } from '../../lib/ui/hooks/useClipboardEvents'
|
|
4
7
|
import { TestEditor } from '../TestEditor'
|
|
5
8
|
|
|
6
9
|
let editor: TestEditor
|
|
@@ -481,3 +484,35 @@ describe('When copying and pasting', () => {
|
|
|
481
484
|
expect(pastedPoint).toMatchObject({ x: 150, y: 150 }) // center of group
|
|
482
485
|
})
|
|
483
486
|
})
|
|
487
|
+
|
|
488
|
+
describe('When cutting', () => {
|
|
489
|
+
function renderCut() {
|
|
490
|
+
const { result } = renderHook(() => useMenuClipboardEvents(), {
|
|
491
|
+
wrapper: ({ children }) => createElement(EditorContext.Provider, { value: editor }, children),
|
|
492
|
+
})
|
|
493
|
+
return result.current.cut
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
it('marks a history stopping point so undo does not roll back earlier changes', async () => {
|
|
497
|
+
// the cut writes to the clipboard before it deletes anything
|
|
498
|
+
Object.assign(window.navigator, { clipboard: { write: vi.fn() } })
|
|
499
|
+
globalThis.ClipboardItem = class {} as any
|
|
500
|
+
|
|
501
|
+
const cut = renderCut()
|
|
502
|
+
editor.createShape({ id: ids.box1, type: 'geo', x: 0, y: 0 })
|
|
503
|
+
editor.markHistoryStoppingPoint('rename page')
|
|
504
|
+
editor.renamePage(editor.getCurrentPageId(), 'My page')
|
|
505
|
+
editor.select(ids.box1)
|
|
506
|
+
|
|
507
|
+
await act(async () => {
|
|
508
|
+
await cut('menu')
|
|
509
|
+
})
|
|
510
|
+
expect(editor.getShape(ids.box1)).toBeUndefined()
|
|
511
|
+
|
|
512
|
+
editor.undo()
|
|
513
|
+
|
|
514
|
+
// the cut is undone, but the page rename before it is not
|
|
515
|
+
expect(editor.getShape(ids.box1)).toBeDefined()
|
|
516
|
+
expect(editor.getCurrentPage().name).toBe('My page')
|
|
517
|
+
})
|
|
518
|
+
})
|
|
@@ -88,6 +88,17 @@ describe('Locking', () => {
|
|
|
88
88
|
// Locking deselects the shape
|
|
89
89
|
expect(editor.getSelectedShapeIds()).toEqual([])
|
|
90
90
|
})
|
|
91
|
+
|
|
92
|
+
it('Locks and deselects a mixed selection of locked and unlocked shapes', () => {
|
|
93
|
+
editor.run(() => editor.setSelectedShapes([ids.lockedShapeA, ids.unlockedShapeA]), {
|
|
94
|
+
ignoreShapeLock: true,
|
|
95
|
+
})
|
|
96
|
+
editor.toggleLock(editor.getSelectedShapeIds())
|
|
97
|
+
expect(
|
|
98
|
+
[ids.lockedShapeA, ids.unlockedShapeA].map((id) => editor.getShape(id)!.isLocked)
|
|
99
|
+
).toStrictEqual([true, true])
|
|
100
|
+
expect(editor.getSelectedShapeIds()).toEqual([])
|
|
101
|
+
})
|
|
91
102
|
})
|
|
92
103
|
|
|
93
104
|
describe('Locked shapes', () => {
|
|
@@ -74,4 +74,24 @@ describe('editor.packShapes', () => {
|
|
|
74
74
|
editor.getCurrentPageShapes().map((s) => ({ ...s, parentId: 'wahtever' }))
|
|
75
75
|
).toMatchSnapshot('packed shapes')
|
|
76
76
|
})
|
|
77
|
+
|
|
78
|
+
it('packs shapes of different heights into rows, tallest first', () => {
|
|
79
|
+
// With the clusters sorted ascending by height, every shape after the first was too tall
|
|
80
|
+
// for the row's remaining space and fell into a single left-hand column.
|
|
81
|
+
editor.selectAll()
|
|
82
|
+
editor.deleteShapes(editor.getSelectedShapeIds())
|
|
83
|
+
editor.createShapes([
|
|
84
|
+
{ id: ids.boxA, type: 'geo', x: 0, y: 0, props: { w: 100, h: 100 } },
|
|
85
|
+
{ id: ids.boxB, type: 'geo', x: 200, y: 0, props: { w: 100, h: 60 } },
|
|
86
|
+
{ id: ids.boxC, type: 'geo', x: 400, y: 0, props: { w: 120, h: 80 } },
|
|
87
|
+
{ id: ids.boxD, type: 'geo', x: 600, y: 0, props: { w: 100, h: 120 } },
|
|
88
|
+
])
|
|
89
|
+
editor.packShapes([ids.boxA, ids.boxB, ids.boxC, ids.boxD], 20)
|
|
90
|
+
editor.expectShapeToMatch(
|
|
91
|
+
{ id: ids.boxD, x: 110, y: 0 },
|
|
92
|
+
{ id: ids.boxA, x: 230, y: 0 },
|
|
93
|
+
{ id: ids.boxC, x: 350, y: 0 },
|
|
94
|
+
{ id: ids.boxB, x: 490, y: 0 }
|
|
95
|
+
)
|
|
96
|
+
})
|
|
77
97
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TLContent, createShapeId, structuredClone } from '@tldraw/editor'
|
|
1
|
+
import { AssetRecordType, TLContent, createShapeId, structuredClone } from '@tldraw/editor'
|
|
2
2
|
import { TestEditor } from '../TestEditor'
|
|
3
3
|
|
|
4
4
|
let editor: TestEditor
|
|
@@ -39,6 +39,40 @@ describe('Migrations', () => {
|
|
|
39
39
|
})
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
+
describe('Input content', () => {
|
|
43
|
+
it('is not mutated when it carries data url assets', () => {
|
|
44
|
+
const assetId = AssetRecordType.createId('imageAsset')
|
|
45
|
+
const imageId = createShapeId('image')
|
|
46
|
+
const src = 'data:image/png;base64,AAAA'
|
|
47
|
+
editor.createAssets([
|
|
48
|
+
{
|
|
49
|
+
type: 'image',
|
|
50
|
+
id: assetId,
|
|
51
|
+
typeName: 'asset',
|
|
52
|
+
props: { w: 100, h: 100, name: '', isAnimated: false, mimeType: 'image/png', src },
|
|
53
|
+
meta: {},
|
|
54
|
+
},
|
|
55
|
+
])
|
|
56
|
+
editor.createShape({
|
|
57
|
+
id: imageId,
|
|
58
|
+
type: 'image',
|
|
59
|
+
x: 0,
|
|
60
|
+
y: 0,
|
|
61
|
+
props: { w: 100, h: 100, assetId },
|
|
62
|
+
})
|
|
63
|
+
// the content holds the live records when no migration applies, so putting it into another
|
|
64
|
+
// editor must not write through to this editor's asset
|
|
65
|
+
const content = editor.getContentFromCurrentPage([imageId])!
|
|
66
|
+
const other = new TestEditor()
|
|
67
|
+
other.putContentOntoCurrentPage(content)
|
|
68
|
+
|
|
69
|
+
expect(content.assets[0].props.src).toBe(src)
|
|
70
|
+
expect(content.rootShapeIds).toEqual([imageId])
|
|
71
|
+
expect(editor.getAsset(assetId)!.props.src).toBe(src)
|
|
72
|
+
other.dispose()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
42
76
|
describe('Post-positioning reparent into frame', () => {
|
|
43
77
|
it('reparents shapes into a frame when they land inside it without an explicit point', () => {
|
|
44
78
|
const frameId = createShapeId('frame')
|
|
@@ -1256,3 +1256,72 @@ test('calling setCameraOptions will apply the new constraints', () => {
|
|
|
1256
1256
|
}
|
|
1257
1257
|
`)
|
|
1258
1258
|
})
|
|
1259
|
+
|
|
1260
|
+
describe('Constraint bounds away from the page origin', () => {
|
|
1261
|
+
it('keeps the bounds inside the padded viewport with the inside behavior', () => {
|
|
1262
|
+
editor.setCameraOptions({
|
|
1263
|
+
...DEFAULT_CAMERA_OPTIONS,
|
|
1264
|
+
constraints: {
|
|
1265
|
+
...DEFAULT_CONSTRAINTS,
|
|
1266
|
+
bounds: { x: 1000, y: 0, w: 800, h: 600 },
|
|
1267
|
+
padding: { x: 100, y: 100 },
|
|
1268
|
+
behavior: { x: 'inside', y: 'free' },
|
|
1269
|
+
},
|
|
1270
|
+
})
|
|
1271
|
+
// the bounds' right edge stops at the right padding edge
|
|
1272
|
+
editor.setCamera({ x: 100000, y: 0, z: 1 })
|
|
1273
|
+
expect(editor.getCamera()).toMatchObject({ x: -300, y: 0, z: 1 })
|
|
1274
|
+
expect(editor.pageToScreen({ x: 1800, y: 0 }).x).toBe(1500)
|
|
1275
|
+
// the bounds' left edge stops at the left padding edge
|
|
1276
|
+
editor.setCamera({ x: -100000, y: 0, z: 1 })
|
|
1277
|
+
expect(editor.getCamera()).toMatchObject({ x: -900, y: 0, z: 1 })
|
|
1278
|
+
expect(editor.pageToScreen({ x: 1000, y: 0 }).x).toBe(100)
|
|
1279
|
+
})
|
|
1280
|
+
|
|
1281
|
+
it('keeps the bounds adjacent to the padded viewport with the outside behavior', () => {
|
|
1282
|
+
editor.setCameraOptions({
|
|
1283
|
+
...DEFAULT_CAMERA_OPTIONS,
|
|
1284
|
+
constraints: {
|
|
1285
|
+
...DEFAULT_CONSTRAINTS,
|
|
1286
|
+
bounds: { x: 1000, y: 0, w: 800, h: 600 },
|
|
1287
|
+
padding: { x: 100, y: 100 },
|
|
1288
|
+
behavior: { x: 'outside', y: 'free' },
|
|
1289
|
+
},
|
|
1290
|
+
})
|
|
1291
|
+
// the bounds' left edge stops at the right padding edge
|
|
1292
|
+
editor.setCamera({ x: 100000, y: 0, z: 1 })
|
|
1293
|
+
expect(editor.getCamera()).toMatchObject({ x: 500, y: 0, z: 1 })
|
|
1294
|
+
expect(editor.pageToScreen({ x: 1000, y: 0 }).x).toBe(1500)
|
|
1295
|
+
// the bounds' right edge stops at the left padding edge
|
|
1296
|
+
editor.setCamera({ x: -100000, y: 0, z: 1 })
|
|
1297
|
+
expect(editor.getCamera()).toMatchObject({ x: -1700, y: 0, z: 1 })
|
|
1298
|
+
expect(editor.pageToScreen({ x: 1800, y: 0 }).x).toBe(100)
|
|
1299
|
+
})
|
|
1300
|
+
})
|
|
1301
|
+
|
|
1302
|
+
test('clamps horizontal padding against the viewport width, not its height', () => {
|
|
1303
|
+
editor.setCameraOptions({
|
|
1304
|
+
...DEFAULT_CAMERA_OPTIONS,
|
|
1305
|
+
constraints: {
|
|
1306
|
+
...DEFAULT_CONSTRAINTS,
|
|
1307
|
+
bounds: { x: 0, y: 0, w: 200, h: 100 },
|
|
1308
|
+
padding: { x: 600, y: 0 },
|
|
1309
|
+
behavior: { x: 'inside', y: 'free' },
|
|
1310
|
+
},
|
|
1311
|
+
})
|
|
1312
|
+
// 600 is below half of the 1600px viewport width, so the padding is honoured as is
|
|
1313
|
+
editor.setCamera({ x: -100000, y: 0, z: 1 })
|
|
1314
|
+
expect(editor.getCamera()).toMatchObject({ x: 600, y: 0, z: 1 })
|
|
1315
|
+
})
|
|
1316
|
+
|
|
1317
|
+
test('slideCamera zoom momentum survives a long frame', () => {
|
|
1318
|
+
editor.user.updateUserPreferences({ animationSpeed: 1 })
|
|
1319
|
+
editor.setCamera({ x: 0, y: 0, z: 1 })
|
|
1320
|
+
editor.slideCamera({ speed: 1, direction: { x: 0, y: 0, z: -0.01 } })
|
|
1321
|
+
// a 100ms frame would have driven a linear zoom factor to zero (and the camera to NaN)
|
|
1322
|
+
editor.emit('tick', 100)
|
|
1323
|
+
const { x, y, z } = editor.getCamera()
|
|
1324
|
+
expect(z).toBeGreaterThan(0)
|
|
1325
|
+
expect(z).toBeLessThan(1)
|
|
1326
|
+
expect(Number.isFinite(x) && Number.isFinite(y)).toBe(true)
|
|
1327
|
+
})
|
|
@@ -143,6 +143,18 @@ describe('distributeShapes command', () => {
|
|
|
143
143
|
})
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
+
it('stacks in spatial order, not selection order, when a gap is given', () => {
|
|
147
|
+
// boxC sits between boxA and boxB on the page but comes after both in the input
|
|
148
|
+
editor.updateShapes([{ id: ids.boxC, type: 'geo', x: 50, y: 0 }])
|
|
149
|
+
editor.stackShapes([ids.boxA, ids.boxB, ids.boxC], 'horizontal', 10)
|
|
150
|
+
vi.advanceTimersByTime(1000)
|
|
151
|
+
editor.expectShapeToMatch(
|
|
152
|
+
{ id: ids.boxA, x: 0 },
|
|
153
|
+
{ id: ids.boxC, x: 110 },
|
|
154
|
+
{ id: ids.boxB, x: 220 }
|
|
155
|
+
)
|
|
156
|
+
})
|
|
157
|
+
|
|
146
158
|
it('stacks the shapes based on the most common gap', () => {
|
|
147
159
|
editor.setSelectedShapes([ids.boxA, ids.boxB, ids.boxC, ids.boxD])
|
|
148
160
|
editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 0)
|
|
@@ -47,6 +47,14 @@ describe('When resizing', () => {
|
|
|
47
47
|
h: 1,
|
|
48
48
|
})
|
|
49
49
|
})
|
|
50
|
+
|
|
51
|
+
it('updates the selection screen bounds when the container moves', () => {
|
|
52
|
+
editor.createShape({ type: 'geo', x: 100, y: 100, props: { w: 100, h: 100 } })
|
|
53
|
+
editor.selectAll()
|
|
54
|
+
expect(editor.getSelectionRotatedScreenBounds()).toMatchObject({ x: 100, y: 100 })
|
|
55
|
+
editor.setScreenBounds({ x: 300, y: 200, w: 1080, h: 720 })
|
|
56
|
+
expect(editor.getSelectionRotatedScreenBounds()).toMatchObject({ x: 400, y: 300 })
|
|
57
|
+
})
|
|
50
58
|
})
|
|
51
59
|
|
|
52
60
|
describe('When center is false', () => {
|
|
@@ -211,6 +211,48 @@ describe('When in the select.idle state', () => {
|
|
|
211
211
|
expect(editor.getCroppingShapeId()).toBe(ids.imageB)
|
|
212
212
|
})
|
|
213
213
|
|
|
214
|
+
it('does not start cropping when the editor is readonly', () => {
|
|
215
|
+
editor.updateInstanceState({ isReadonly: true })
|
|
216
|
+
|
|
217
|
+
// enter
|
|
218
|
+
editor
|
|
219
|
+
.expectToBeIn('select.idle')
|
|
220
|
+
.select(ids.imageB)
|
|
221
|
+
.keyDown('Enter')
|
|
222
|
+
.keyUp('Enter')
|
|
223
|
+
.expectToBeIn('select.idle')
|
|
224
|
+
|
|
225
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
226
|
+
|
|
227
|
+
// double clicking a selection handle
|
|
228
|
+
editor
|
|
229
|
+
.doubleClick(550, 550, {
|
|
230
|
+
target: 'selection',
|
|
231
|
+
handle: 'bottom_right',
|
|
232
|
+
})
|
|
233
|
+
.expectToBeIn('select.idle')
|
|
234
|
+
|
|
235
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
236
|
+
|
|
237
|
+
// control-pointing a selection handle
|
|
238
|
+
editor
|
|
239
|
+
.pointerDown(500, 550, {
|
|
240
|
+
target: 'selection',
|
|
241
|
+
handle: 'bottom',
|
|
242
|
+
ctrlKey: true,
|
|
243
|
+
accelKey: true,
|
|
244
|
+
})
|
|
245
|
+
.expectToBeIn('select.brushing')
|
|
246
|
+
.cancel()
|
|
247
|
+
|
|
248
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
249
|
+
|
|
250
|
+
// setting the cropping shape directly
|
|
251
|
+
editor.setCroppingShape(ids.imageB)
|
|
252
|
+
expect(editor.canCropShape(ids.imageB)).toBe(false)
|
|
253
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
254
|
+
})
|
|
255
|
+
|
|
214
256
|
it('when only an image is selected control-pointing a selection handle should transition to select.crop.pointing_crop_handle', () => {
|
|
215
257
|
// two shapes / edge
|
|
216
258
|
editor
|
|
@@ -286,6 +328,17 @@ describe('When in the crop.idle state', () => {
|
|
|
286
328
|
.expectToBeIn('select.idle')
|
|
287
329
|
})
|
|
288
330
|
|
|
331
|
+
it('deleting the cropping shape clears the cropping shape id and leaves crop mode', () => {
|
|
332
|
+
editor
|
|
333
|
+
.expectToBeIn('select.idle')
|
|
334
|
+
.doubleClick(550, 550, ids.imageB)
|
|
335
|
+
.expectToBeIn('select.crop.idle')
|
|
336
|
+
expect(editor.getCroppingShapeId()).toBe(ids.imageB)
|
|
337
|
+
editor.deleteShapes([ids.imageB])
|
|
338
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
339
|
+
editor.expectToBeIn('select.idle')
|
|
340
|
+
})
|
|
341
|
+
|
|
289
342
|
it('pointing the canvas should point canvas', () => {
|
|
290
343
|
editor
|
|
291
344
|
.expectToBeIn('select.idle')
|
|
@@ -584,6 +637,74 @@ describe('When in the select.crop.translating_crop state', () => {
|
|
|
584
637
|
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(before)
|
|
585
638
|
})
|
|
586
639
|
|
|
640
|
+
it('pressing escape mid-drag reverts only that drag, not earlier crops in the session', () => {
|
|
641
|
+
const original = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
642
|
+
|
|
643
|
+
editor
|
|
644
|
+
.expectToBeIn('select.idle')
|
|
645
|
+
.doubleClick(550, 550, ids.imageB)
|
|
646
|
+
.expectToBeIn('select.crop.idle')
|
|
647
|
+
.pointerDown(500, 600, { target: 'selection', handle: 'bottom', ctrlKey: false })
|
|
648
|
+
.pointerMove(510, 590)
|
|
649
|
+
.expectToBeIn('select.crop.cropping')
|
|
650
|
+
.pointerUp()
|
|
651
|
+
.expectToBeIn('select.crop.idle')
|
|
652
|
+
|
|
653
|
+
const afterFirstCrop = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
654
|
+
expect(afterFirstCrop).not.toMatchObject(original)
|
|
655
|
+
|
|
656
|
+
editor
|
|
657
|
+
.pointerDown(550, 550, { target: 'shape', shape: editor.getShape(ids.imageB) })
|
|
658
|
+
.pointerMove(250, 250)
|
|
659
|
+
.expectToBeIn('select.crop.translating_crop')
|
|
660
|
+
|
|
661
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).not.toMatchObject(afterFirstCrop)
|
|
662
|
+
|
|
663
|
+
editor.cancel().expectToBeIn('select.crop.idle')
|
|
664
|
+
|
|
665
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(afterFirstCrop)
|
|
666
|
+
|
|
667
|
+
// The session is still open: escaping from idle reverts everything since crop mode began
|
|
668
|
+
editor.cancel().expectToBeIn('select.idle')
|
|
669
|
+
|
|
670
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(original)
|
|
671
|
+
})
|
|
672
|
+
|
|
673
|
+
it('pressing escape mid-drag keeps the session squashing into one undo step on exit', () => {
|
|
674
|
+
const original = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
675
|
+
|
|
676
|
+
editor
|
|
677
|
+
.doubleClick(550, 550, ids.imageB)
|
|
678
|
+
.expectToBeIn('select.crop.idle')
|
|
679
|
+
.pointerDown(500, 600, { target: 'selection', handle: 'bottom', ctrlKey: false })
|
|
680
|
+
.pointerMove(510, 590)
|
|
681
|
+
.pointerUp()
|
|
682
|
+
.expectToBeIn('select.crop.idle')
|
|
683
|
+
.pointerDown(550, 550, { target: 'shape', shape: editor.getShape(ids.imageB) })
|
|
684
|
+
.pointerMove(250, 250)
|
|
685
|
+
.expectToBeIn('select.crop.translating_crop')
|
|
686
|
+
.cancel()
|
|
687
|
+
.expectToBeIn('select.crop.idle')
|
|
688
|
+
.pointerDown(550, 550, { target: 'shape', shape: editor.getShape(ids.imageB) })
|
|
689
|
+
.pointerMove(300, 300)
|
|
690
|
+
.pointerUp()
|
|
691
|
+
.expectToBeIn('select.crop.idle')
|
|
692
|
+
.pointerDown(550, 550, { target: 'shape', shape: editor.getShape(ids.imageB) })
|
|
693
|
+
.pointerMove(500, 500)
|
|
694
|
+
.pointerUp()
|
|
695
|
+
.expectToBeIn('select.crop.idle')
|
|
696
|
+
|
|
697
|
+
const afterSession = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
698
|
+
expect(afterSession).not.toMatchObject(original)
|
|
699
|
+
|
|
700
|
+
editor.keyDown('Enter').keyUp('Enter').expectToBeIn('select.idle')
|
|
701
|
+
|
|
702
|
+
editor.undo()
|
|
703
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(original)
|
|
704
|
+
editor.redo()
|
|
705
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(afterSession)
|
|
706
|
+
})
|
|
707
|
+
|
|
587
708
|
it('pressing enter / pointer up / complete should transition to select.crop.idle', () => {
|
|
588
709
|
const before = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
589
710
|
|
|
@@ -717,6 +838,35 @@ describe('When in the select.crop.cropping state', () => {
|
|
|
717
838
|
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(before)
|
|
718
839
|
})
|
|
719
840
|
|
|
841
|
+
it('escape / cancel mid-drag reverts only that drag, not earlier crops in the session', () => {
|
|
842
|
+
const original = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
843
|
+
|
|
844
|
+
editor
|
|
845
|
+
.cancel()
|
|
846
|
+
.expectToBeIn('select.idle')
|
|
847
|
+
.doubleClick(550, 550, ids.imageB)
|
|
848
|
+
.expectToBeIn('select.crop.idle')
|
|
849
|
+
.pointerDown(500, 600, { target: 'selection', handle: 'bottom', ctrlKey: false })
|
|
850
|
+
.pointerMove(510, 590)
|
|
851
|
+
.expectToBeIn('select.crop.cropping')
|
|
852
|
+
.pointerUp()
|
|
853
|
+
.expectToBeIn('select.crop.idle')
|
|
854
|
+
|
|
855
|
+
const afterFirstCrop = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
856
|
+
expect(afterFirstCrop).not.toMatchObject(original)
|
|
857
|
+
|
|
858
|
+
editor
|
|
859
|
+
.pointerDown(700, 550, { target: 'selection', handle: 'right', ctrlKey: false })
|
|
860
|
+
.pointerMove(650, 550)
|
|
861
|
+
.expectToBeIn('select.crop.cropping')
|
|
862
|
+
|
|
863
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).not.toMatchObject(afterFirstCrop)
|
|
864
|
+
|
|
865
|
+
editor.cancel().expectToBeIn('select.crop.idle')
|
|
866
|
+
|
|
867
|
+
expect(editor.getShape<TLImageShape>(ids.imageB)!.props.crop!).toMatchObject(afterFirstCrop)
|
|
868
|
+
})
|
|
869
|
+
|
|
720
870
|
it('pointer up / complete should commit the change and transition to crop.idle when that is the history state', () => {
|
|
721
871
|
const before = editor.getShape<TLImageShape>(ids.imageB)!.props.crop!
|
|
722
872
|
|
|
@@ -1240,3 +1390,15 @@ describe('When cropping with modifiers and snapping...', () => {
|
|
|
1240
1390
|
expect(editor.snaps.getIndicators().length).toBe(0)
|
|
1241
1391
|
})
|
|
1242
1392
|
})
|
|
1393
|
+
|
|
1394
|
+
describe('Leaving crop mode by switching tools', () => {
|
|
1395
|
+
it('clears the cropping shape', () => {
|
|
1396
|
+
editor.doubleClick(550, 550, ids.imageB).expectToBeIn('select.crop.idle')
|
|
1397
|
+
expect(editor.getCroppingShapeId()).toBe(ids.imageB)
|
|
1398
|
+
editor.setCurrentTool('hand')
|
|
1399
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
1400
|
+
editor.setCurrentTool('select')
|
|
1401
|
+
editor.expectToBeIn('select.idle')
|
|
1402
|
+
expect(editor.getCroppingShapeId()).toBe(null)
|
|
1403
|
+
})
|
|
1404
|
+
})
|
|
@@ -321,6 +321,38 @@ describe('custom handle snapping', () => {
|
|
|
321
321
|
expect(editor.snaps.getIndicators()).toHaveLength(0)
|
|
322
322
|
expect(handlePosition()).toMatchObject({ x: 251, y: 251 })
|
|
323
323
|
})
|
|
324
|
+
|
|
325
|
+
test('lands on the snap target when the dragged shape is rotated', () => {
|
|
326
|
+
// Rotating the line around its start puts its end handle at page (0, 100); the snap
|
|
327
|
+
// nudge is in page space and must come off by the shape's own rotation.
|
|
328
|
+
editor.updateShape<TLLineShape>({
|
|
329
|
+
id: ids.line,
|
|
330
|
+
type: 'line',
|
|
331
|
+
rotation: Math.PI / 2,
|
|
332
|
+
props: {
|
|
333
|
+
points: {
|
|
334
|
+
a1: { id: 'a1', index: 'a1' as IndexKey, x: 0, y: 0 },
|
|
335
|
+
a2: { id: 'a2', index: 'a2' as IndexKey, x: 100, y: 0 },
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
})
|
|
339
|
+
editor.updateShape({ id: ids.test2, type: TEST2_TYPE, x: 10, y: 110 })
|
|
340
|
+
const line = editor.select(ids.line).getOnlySelectedShape()! as TLLineShape
|
|
341
|
+
const endHandle = editor.getShapeHandles(line)!.at(-1)!
|
|
342
|
+
const endHandlePagePoint = editor.getShapePageTransform(line).applyToPoint(endHandle)
|
|
343
|
+
editor.pointerDown(endHandlePagePoint.x, endHandlePagePoint.y, {
|
|
344
|
+
target: 'handle',
|
|
345
|
+
shape: line,
|
|
346
|
+
handle: endHandle,
|
|
347
|
+
})
|
|
348
|
+
editor.pointerMove(7, 109, undefined, { ctrlKey: true })
|
|
349
|
+
expect(editor.snaps.getIndicators()).toHaveLength(1)
|
|
350
|
+
const shape = editor.getShape<TLLineShape>(ids.line)!
|
|
351
|
+
const handle = editor.getShapeHandles(shape)!.at(-1)!
|
|
352
|
+
const pagePoint = editor.getShapePageTransform(shape).applyToPoint(handle)
|
|
353
|
+
expect(pagePoint.x).toBeCloseTo(10)
|
|
354
|
+
expect(pagePoint.y).toBeCloseTo(110)
|
|
355
|
+
})
|
|
324
356
|
})
|
|
325
357
|
|
|
326
358
|
describe('with empty handleSnapGeometry.outline', () => {
|