tldraw 4.1.0-canary.9c36de6e611c → 4.1.0-canary.a152954244d2
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 +46 -12
- package/dist-cjs/index.js +6 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/canvas/TldrawCropHandles.js +1 -1
- package/dist-cjs/lib/canvas/TldrawScribble.js +1 -1
- package/dist-cjs/lib/canvas/TldrawSelectionForeground.js +1 -1
- package/dist-cjs/lib/defaultEmbedDefinitions.js +25 -30
- package/dist-cjs/lib/defaultEmbedDefinitions.js.map +2 -2
- package/dist-cjs/lib/defaultExternalContentHandlers.js +10 -33
- package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +3 -0
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/curved-arrow.js +8 -2
- package/dist-cjs/lib/shapes/arrow/curved-arrow.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/straight-arrow.js +4 -1
- package/dist-cjs/lib/shapes/arrow/straight-arrow.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +44 -102
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js +138 -0
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +7 -0
- package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +25 -3
- package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +1 -1
- package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +1 -1
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js +3 -0
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +1 -1
- package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -1
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/ShapeFill.js +1 -1
- package/dist-cjs/lib/shapes/text/PlainTextArea.js +1 -1
- package/dist-cjs/lib/shapes/text/RichTextArea.js +1 -1
- package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Cropping.js +20 -4
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Cropping.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Idle.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.js +23 -11
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +27 -6
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js +21 -9
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingResizeHandle.js +24 -8
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingResizeHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingRotateHandle.js +21 -9
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingRotateHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +23 -8
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js +21 -9
- package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +26 -11
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/ui/TldrawUi.js +2 -2
- package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js +3 -3
- package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js.map +1 -1
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialog.js +1 -1
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +1 -1
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +1 -1
- package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +1 -1
- package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +5 -0
- package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
- package/dist-cjs/lib/ui/components/OfflineIndicator/OfflineIndicator.js +1 -1
- package/dist-cjs/lib/ui/components/SharePanel/PeopleMenu.js +6 -2
- package/dist-cjs/lib/ui/components/SharePanel/PeopleMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js +1 -1
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +1 -1
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +64 -56
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js +54 -47
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +3 -3
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js +63 -56
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js +13 -6
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +1 -1
- package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +1 -1
- package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +1 -1
- package/dist-cjs/lib/ui/components/menu-items.js +2 -2
- package/dist-cjs/lib/ui/components/menu-items.js.map +1 -1
- package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButton.js +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiDropdownMenu.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/layout.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +1 -1
- package/dist-cjs/lib/ui/context/actions.js +44 -30
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/context/breakpoints.js +1 -1
- package/dist-cjs/lib/ui/context/events.js +1 -1
- package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +1 -1
- package/dist-cjs/lib/ui/hooks/useEditorEvents.js +1 -1
- package/dist-cjs/lib/ui/hooks/useEditorEvents.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js +1 -1
- package/dist-cjs/lib/ui/hooks/useLocalStorageState.js +1 -1
- package/dist-cjs/lib/ui/hooks/useTools.js +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +4 -4
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/useTranslation.js +1 -1
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/text/richText.js +4 -4
- package/dist-esm/index.d.mts +46 -12
- package/dist-esm/index.mjs +12 -4
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/defaultEmbedDefinitions.mjs +25 -30
- package/dist-esm/lib/defaultEmbedDefinitions.mjs.map +2 -2
- package/dist-esm/lib/defaultExternalContentHandlers.mjs +10 -33
- package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +3 -0
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/curved-arrow.mjs +8 -2
- package/dist-esm/lib/shapes/arrow/curved-arrow.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/straight-arrow.mjs +4 -1
- package/dist-esm/lib/shapes/arrow/straight-arrow.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +46 -101
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs +124 -0
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +7 -0
- package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +26 -3
- package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +3 -0
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +1 -1
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Cropping.mjs +20 -4
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Cropping.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Idle.mjs +1 -1
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.mjs +23 -11
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +29 -7
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +1 -1
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs +21 -9
- package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingResizeHandle.mjs +24 -8
- package/dist-esm/lib/tools/SelectTool/childStates/PointingResizeHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingRotateHandle.mjs +21 -9
- package/dist-esm/lib/tools/SelectTool/childStates/PointingRotateHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +23 -8
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs +21 -9
- package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +26 -11
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/ui/components/DebugMenu/DefaultDebugMenuContent.mjs +2 -2
- package/dist-esm/lib/ui/components/DebugMenu/DefaultDebugMenuContent.mjs.map +1 -1
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +1 -1
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +1 -1
- package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +5 -0
- package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/PeopleMenu.mjs +6 -2
- package/dist-esm/lib/ui/components/SharePanel/PeopleMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +68 -57
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +54 -47
- package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +3 -3
- package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs +63 -56
- package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs +12 -5
- package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/menu-items.mjs +2 -2
- package/dist-esm/lib/ui/components/menu-items.mjs.map +1 -1
- package/dist-esm/lib/ui/context/actions.mjs +43 -29
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useEditorEvents.mjs +1 -1
- package/dist-esm/lib/ui/hooks/useEditorEvents.mjs.map +1 -1
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +4 -4
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +1 -1
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +4 -0
- package/src/lib/defaultEmbedDefinitions.ts +20 -24
- package/src/lib/defaultExternalContentHandlers.ts +12 -37
- package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +211 -1
- package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +3 -0
- package/src/lib/shapes/arrow/curved-arrow.ts +8 -2
- package/src/lib/shapes/arrow/straight-arrow.ts +5 -1
- package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +51 -135
- package/src/lib/shapes/bookmark/bookmarks.ts +170 -0
- package/src/lib/shapes/embed/EmbedShapeUtil.tsx +28 -2
- package/src/lib/shapes/line/LineShapeUtil.tsx +3 -0
- package/src/lib/shapes/shared/RichTextLabel.tsx +1 -1
- package/src/lib/shapes/text/TextShapeTool.test.ts +74 -0
- package/src/lib/tools/SelectTool/childStates/Crop/children/Cropping.ts +23 -6
- package/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts +1 -1
- package/src/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.ts +24 -12
- package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +34 -11
- package/src/lib/tools/SelectTool/childStates/Idle.ts +1 -1
- package/src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts +23 -11
- package/src/lib/tools/SelectTool/childStates/PointingResizeHandle.ts +26 -9
- package/src/lib/tools/SelectTool/childStates/PointingRotateHandle.ts +23 -10
- package/src/lib/tools/SelectTool/childStates/Resizing.ts +24 -9
- package/src/lib/tools/SelectTool/childStates/Rotating.ts +27 -11
- package/src/lib/tools/SelectTool/childStates/Translating.ts +28 -12
- package/src/lib/ui/components/DebugMenu/DefaultDebugMenuContent.tsx +2 -2
- package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +1 -1
- package/src/lib/ui/components/Minimap/MinimapManager.ts +6 -0
- package/src/lib/ui/components/SharePanel/PeopleMenu.tsx +6 -2
- package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +60 -49
- package/src/lib/ui/components/StylePanel/StylePanelButtonPicker.tsx +70 -53
- package/src/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.tsx +105 -90
- package/src/lib/ui/components/StylePanel/StylePanelDropdownPicker.tsx +72 -51
- package/src/lib/ui/components/menu-items.tsx +2 -2
- package/src/lib/ui/context/actions.tsx +49 -31
- package/src/lib/ui/hooks/useEditorEvents.ts +1 -1
- package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +4 -4
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/utils/embeds/embeds.test.ts +16 -34
- package/src/test/SelectTool.test.ts +251 -0
- package/src/test/bookmark-shapes.test.ts +129 -7
- package/src/test/customSnapping.test.tsx +55 -11
- package/tldraw.css +7 -2
|
@@ -648,3 +648,254 @@ test('right clicking a shape inside of a group does not focus the group if the g
|
|
|
648
648
|
editor.pointerUp(100, 100, { target: 'shape', button: 0, shape: editor.getShape(boxAId)! })
|
|
649
649
|
expect(editor.getFocusedGroupId()).toBe(groupId)
|
|
650
650
|
})
|
|
651
|
+
|
|
652
|
+
describe('when passing a function to onInteractionEnd', () => {
|
|
653
|
+
it('calls the function for cropping', () => {
|
|
654
|
+
const id = createShapeId('image')
|
|
655
|
+
editor.createShapes([
|
|
656
|
+
{
|
|
657
|
+
id,
|
|
658
|
+
type: 'image',
|
|
659
|
+
x: 100,
|
|
660
|
+
y: 100,
|
|
661
|
+
props: {
|
|
662
|
+
w: 1200,
|
|
663
|
+
h: 800,
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
])
|
|
667
|
+
|
|
668
|
+
editor.select(id)
|
|
669
|
+
|
|
670
|
+
const fn = vi.fn()
|
|
671
|
+
editor.setCurrentTool('select.cropping', {
|
|
672
|
+
handle: 'bottom_right',
|
|
673
|
+
onInteractionEnd: fn,
|
|
674
|
+
})
|
|
675
|
+
editor.pointerUp(50, 50)
|
|
676
|
+
|
|
677
|
+
expect(fn).toHaveBeenCalled()
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
it('calls the function for pointing crop handle', () => {
|
|
681
|
+
const fn = vi.fn()
|
|
682
|
+
editor.setCurrentTool('select.crop.pointing_crop_handle', {
|
|
683
|
+
onInteractionEnd: fn,
|
|
684
|
+
})
|
|
685
|
+
editor.pointerUp(50, 50)
|
|
686
|
+
expect(fn).toHaveBeenCalled()
|
|
687
|
+
})
|
|
688
|
+
|
|
689
|
+
it('calls the function for pointing arrow label', () => {
|
|
690
|
+
const fn = vi.fn()
|
|
691
|
+
const id = createShapeId('arrow')
|
|
692
|
+
|
|
693
|
+
const arrow = {
|
|
694
|
+
id,
|
|
695
|
+
type: 'arrow' as const,
|
|
696
|
+
x: 100,
|
|
697
|
+
y: 100,
|
|
698
|
+
props: {
|
|
699
|
+
richText: toRichText('Test Label'),
|
|
700
|
+
start: { x: 0, y: 0 },
|
|
701
|
+
end: { x: 100, y: 0 },
|
|
702
|
+
},
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
editor.createShapes<TLArrowShape>([arrow])
|
|
706
|
+
|
|
707
|
+
editor.setCurrentTool('select.pointing_arrow_label', {
|
|
708
|
+
shape: arrow,
|
|
709
|
+
onInteractionEnd: fn,
|
|
710
|
+
})
|
|
711
|
+
editor.pointerUp(50, 50)
|
|
712
|
+
expect(fn).toHaveBeenCalled()
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
it('calls the function for pointing a resize handle', () => {
|
|
716
|
+
const fn = vi.fn()
|
|
717
|
+
editor.setCurrentTool('select.pointing_resize_handle', {
|
|
718
|
+
target: 'selection',
|
|
719
|
+
handle: 'bottom_right',
|
|
720
|
+
onInteractionEnd: fn,
|
|
721
|
+
})
|
|
722
|
+
editor.pointerUp(50, 50)
|
|
723
|
+
expect(fn).toHaveBeenCalled()
|
|
724
|
+
})
|
|
725
|
+
|
|
726
|
+
it('calls the function for pointing a rotate handle', () => {
|
|
727
|
+
const fn = vi.fn()
|
|
728
|
+
editor.setCurrentTool('select.pointing_rotate_handle', {
|
|
729
|
+
target: 'selection',
|
|
730
|
+
handle: 'bottom_right_rotate',
|
|
731
|
+
onInteractionEnd: fn,
|
|
732
|
+
})
|
|
733
|
+
editor.pointerUp(50, 50)
|
|
734
|
+
expect(fn).toHaveBeenCalled()
|
|
735
|
+
})
|
|
736
|
+
|
|
737
|
+
it('calls the function for resizing', () => {
|
|
738
|
+
const id = createShapeId('box')
|
|
739
|
+
editor.createShapes([
|
|
740
|
+
{
|
|
741
|
+
id,
|
|
742
|
+
type: 'geo',
|
|
743
|
+
x: 100,
|
|
744
|
+
y: 100,
|
|
745
|
+
},
|
|
746
|
+
])
|
|
747
|
+
|
|
748
|
+
editor.select(id)
|
|
749
|
+
|
|
750
|
+
const fn = vi.fn()
|
|
751
|
+
editor.setCurrentTool('select.resizing', {
|
|
752
|
+
target: 'selection',
|
|
753
|
+
handle: 'bottom_right',
|
|
754
|
+
onInteractionEnd: fn,
|
|
755
|
+
})
|
|
756
|
+
editor.pointerUp(50, 50)
|
|
757
|
+
expect(fn).toHaveBeenCalled()
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
it('calls the function for translating', () => {
|
|
761
|
+
const id = createShapeId('box')
|
|
762
|
+
editor.createShapes([
|
|
763
|
+
{
|
|
764
|
+
id,
|
|
765
|
+
type: 'geo',
|
|
766
|
+
x: 100,
|
|
767
|
+
y: 100,
|
|
768
|
+
},
|
|
769
|
+
])
|
|
770
|
+
editor.select(id)
|
|
771
|
+
|
|
772
|
+
const fn = vi.fn()
|
|
773
|
+
editor.setCurrentTool('select.translating', {
|
|
774
|
+
onInteractionEnd: fn,
|
|
775
|
+
})
|
|
776
|
+
editor.pointerUp(50, 50)
|
|
777
|
+
expect(fn).toHaveBeenCalled()
|
|
778
|
+
})
|
|
779
|
+
})
|
|
780
|
+
|
|
781
|
+
describe('when passing a string to onInteractionEnd', () => {
|
|
782
|
+
it('transitions to the tool for cropping', () => {
|
|
783
|
+
const id = createShapeId('image')
|
|
784
|
+
editor.createShapes([
|
|
785
|
+
{
|
|
786
|
+
id,
|
|
787
|
+
type: 'image',
|
|
788
|
+
x: 100,
|
|
789
|
+
y: 100,
|
|
790
|
+
props: {
|
|
791
|
+
w: 1200,
|
|
792
|
+
h: 800,
|
|
793
|
+
},
|
|
794
|
+
},
|
|
795
|
+
])
|
|
796
|
+
|
|
797
|
+
editor.select(id)
|
|
798
|
+
|
|
799
|
+
editor.setCurrentTool('select.cropping', {
|
|
800
|
+
handle: 'bottom_right',
|
|
801
|
+
onInteractionEnd: 'select.idle',
|
|
802
|
+
})
|
|
803
|
+
editor.pointerUp(50, 50)
|
|
804
|
+
|
|
805
|
+
editor.expectToBeIn('select.idle')
|
|
806
|
+
})
|
|
807
|
+
|
|
808
|
+
it('transitions to the tool for pointing crop handle', () => {
|
|
809
|
+
editor.setCurrentTool('select.crop.pointing_crop_handle', {
|
|
810
|
+
onInteractionEnd: 'select.idle',
|
|
811
|
+
})
|
|
812
|
+
editor.pointerUp(50, 50)
|
|
813
|
+
editor.expectToBeIn('select.idle')
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
it('transitions to the tool for pointing arrow label', () => {
|
|
817
|
+
const id = createShapeId('arrow')
|
|
818
|
+
|
|
819
|
+
const arrow = {
|
|
820
|
+
id,
|
|
821
|
+
type: 'arrow' as const,
|
|
822
|
+
x: 100,
|
|
823
|
+
y: 100,
|
|
824
|
+
props: {
|
|
825
|
+
richText: toRichText('Test Label'),
|
|
826
|
+
start: { x: 0, y: 0 },
|
|
827
|
+
end: { x: 100, y: 0 },
|
|
828
|
+
},
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
editor.createShapes<TLArrowShape>([arrow])
|
|
832
|
+
|
|
833
|
+
editor.setCurrentTool('select.pointing_arrow_label', {
|
|
834
|
+
shape: arrow,
|
|
835
|
+
onInteractionEnd: 'select.idle',
|
|
836
|
+
})
|
|
837
|
+
editor.pointerUp(50, 50)
|
|
838
|
+
editor.expectToBeIn('select.idle')
|
|
839
|
+
})
|
|
840
|
+
|
|
841
|
+
it('transitions to the tool for pointing a resize handle', () => {
|
|
842
|
+
editor.setCurrentTool('select.pointing_resize_handle', {
|
|
843
|
+
target: 'selection',
|
|
844
|
+
handle: 'bottom_right',
|
|
845
|
+
onInteractionEnd: 'select.idle',
|
|
846
|
+
})
|
|
847
|
+
editor.pointerUp(50, 50)
|
|
848
|
+
editor.expectToBeIn('select.idle')
|
|
849
|
+
})
|
|
850
|
+
|
|
851
|
+
it('transitions to the tool for pointing a rotate handle', () => {
|
|
852
|
+
editor.setCurrentTool('select.pointing_rotate_handle', {
|
|
853
|
+
target: 'selection',
|
|
854
|
+
handle: 'bottom_right_rotate',
|
|
855
|
+
onInteractionEnd: 'select.idle',
|
|
856
|
+
})
|
|
857
|
+
editor.pointerUp(50, 50)
|
|
858
|
+
editor.expectToBeIn('select.idle')
|
|
859
|
+
})
|
|
860
|
+
|
|
861
|
+
it('transitions to the tool for resizing', () => {
|
|
862
|
+
const id = createShapeId('box')
|
|
863
|
+
editor.createShapes([
|
|
864
|
+
{
|
|
865
|
+
id,
|
|
866
|
+
type: 'geo',
|
|
867
|
+
x: 100,
|
|
868
|
+
y: 100,
|
|
869
|
+
},
|
|
870
|
+
])
|
|
871
|
+
|
|
872
|
+
editor.select(id)
|
|
873
|
+
|
|
874
|
+
editor.setCurrentTool('select.resizing', {
|
|
875
|
+
target: 'selection',
|
|
876
|
+
handle: 'bottom_right',
|
|
877
|
+
onInteractionEnd: 'select.idle',
|
|
878
|
+
})
|
|
879
|
+
editor.pointerUp(50, 50)
|
|
880
|
+
editor.expectToBeIn('select.idle')
|
|
881
|
+
})
|
|
882
|
+
|
|
883
|
+
it('transitions to the tool for translating', () => {
|
|
884
|
+
const id = createShapeId('box')
|
|
885
|
+
editor.createShapes([
|
|
886
|
+
{
|
|
887
|
+
id,
|
|
888
|
+
type: 'geo',
|
|
889
|
+
x: 100,
|
|
890
|
+
y: 100,
|
|
891
|
+
},
|
|
892
|
+
])
|
|
893
|
+
editor.select(id)
|
|
894
|
+
|
|
895
|
+
editor.setCurrentTool('select.translating', {
|
|
896
|
+
onInteractionEnd: 'select.idle',
|
|
897
|
+
})
|
|
898
|
+
editor.pointerUp(50, 50)
|
|
899
|
+
editor.expectToBeIn('select.idle')
|
|
900
|
+
})
|
|
901
|
+
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TLBookmarkShape, createShapeId } from '@tldraw/editor'
|
|
2
|
-
import {
|
|
2
|
+
import { vi } from 'vitest'
|
|
3
|
+
import { createBookmarkFromUrl, getHumanReadableAddress } from '../lib/shapes/bookmark/bookmarks'
|
|
3
4
|
import { TestEditor } from './TestEditor'
|
|
4
5
|
|
|
5
6
|
let editor: TestEditor
|
|
@@ -74,12 +75,12 @@ describe('The URL formatter', () => {
|
|
|
74
75
|
const e = editor.getShape<TLBookmarkShape>(ids.e)!
|
|
75
76
|
const f = editor.getShape<TLBookmarkShape>(ids.f)!
|
|
76
77
|
|
|
77
|
-
expect(getHumanReadableAddress(a)).toBe('github.com')
|
|
78
|
-
expect(getHumanReadableAddress(b)).toBe('github.com')
|
|
79
|
-
expect(getHumanReadableAddress(c)).toBe('github.com')
|
|
80
|
-
expect(getHumanReadableAddress(d)).toBe('github.com')
|
|
81
|
-
expect(getHumanReadableAddress(e)).toBe('github.com')
|
|
82
|
-
expect(getHumanReadableAddress(f)).toBe('github.com')
|
|
78
|
+
expect(getHumanReadableAddress(a.props.url)).toBe('github.com')
|
|
79
|
+
expect(getHumanReadableAddress(b.props.url)).toBe('github.com')
|
|
80
|
+
expect(getHumanReadableAddress(c.props.url)).toBe('github.com')
|
|
81
|
+
expect(getHumanReadableAddress(d.props.url)).toBe('github.com')
|
|
82
|
+
expect(getHumanReadableAddress(e.props.url)).toBe('github.com')
|
|
83
|
+
expect(getHumanReadableAddress(f.props.url)).toBe('github.com')
|
|
83
84
|
})
|
|
84
85
|
|
|
85
86
|
it("Doesn't resize bookmarks", () => {
|
|
@@ -132,3 +133,124 @@ describe('The URL formatter', () => {
|
|
|
132
133
|
expect(newBookmark.props.h).toBe(320)
|
|
133
134
|
})
|
|
134
135
|
})
|
|
136
|
+
|
|
137
|
+
describe('createBookmarkFromUrl', () => {
|
|
138
|
+
it('creates a bookmark shape with unfurled metadata', async () => {
|
|
139
|
+
const url = 'https://example.com'
|
|
140
|
+
const center = { x: 100, y: 200 }
|
|
141
|
+
|
|
142
|
+
// Mock the asset creation to return a test asset
|
|
143
|
+
const mockAsset = {
|
|
144
|
+
id: 'asset:test-asset-id' as any,
|
|
145
|
+
typeName: 'asset' as const,
|
|
146
|
+
type: 'bookmark' as const,
|
|
147
|
+
props: {
|
|
148
|
+
src: url,
|
|
149
|
+
title: 'Example Site',
|
|
150
|
+
description: 'An example website',
|
|
151
|
+
image: 'https://example.com/image.jpg',
|
|
152
|
+
favicon: 'https://example.com/favicon.ico',
|
|
153
|
+
},
|
|
154
|
+
meta: {},
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Mock the getAssetForExternalContent method
|
|
158
|
+
vi.spyOn(editor, 'getAssetForExternalContent').mockResolvedValue(mockAsset)
|
|
159
|
+
|
|
160
|
+
const result = await createBookmarkFromUrl(editor, { url, center })
|
|
161
|
+
|
|
162
|
+
assert(result.ok, 'Failed to create bookmark')
|
|
163
|
+
const shape = result.value
|
|
164
|
+
expect(shape.type).toBe('bookmark')
|
|
165
|
+
expect(shape.props.url).toBe(url)
|
|
166
|
+
expect(shape.props.assetId).toBe('asset:test-asset-id')
|
|
167
|
+
expect(shape.props.w).toBe(300)
|
|
168
|
+
expect(shape.props.h).toBe(320)
|
|
169
|
+
expect(shape.x).toBe(center.x - 150) // BOOKMARK_WIDTH / 2
|
|
170
|
+
expect(shape.y).toBe(center.y - 160) // BOOKMARK_HEIGHT / 2
|
|
171
|
+
|
|
172
|
+
// Verify the shape was created in the editor
|
|
173
|
+
const createdShape = editor.getShape(result.value.id)
|
|
174
|
+
expect(createdShape).toBeDefined()
|
|
175
|
+
expect(createdShape?.type).toBe('bookmark')
|
|
176
|
+
|
|
177
|
+
// Verify the asset was created
|
|
178
|
+
const createdAsset = editor.getAsset('asset:test-asset-id' as any)
|
|
179
|
+
expect(createdAsset).toBeDefined()
|
|
180
|
+
expect(createdAsset?.type).toBe('bookmark')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('creates a bookmark shape with default center when no center provided', async () => {
|
|
184
|
+
const url = 'https://example.com'
|
|
185
|
+
const viewportCenter = { x: 500, y: 300 }
|
|
186
|
+
|
|
187
|
+
// Mock getViewportPageBounds to return a known center
|
|
188
|
+
vi.spyOn(editor, 'getViewportPageBounds').mockReturnValue({
|
|
189
|
+
x: 0,
|
|
190
|
+
y: 0,
|
|
191
|
+
w: 1000,
|
|
192
|
+
h: 600,
|
|
193
|
+
center: viewportCenter,
|
|
194
|
+
} as any)
|
|
195
|
+
|
|
196
|
+
const mockAsset = {
|
|
197
|
+
id: 'asset:test-asset-id' as any,
|
|
198
|
+
typeName: 'asset' as const,
|
|
199
|
+
type: 'bookmark' as const,
|
|
200
|
+
props: {
|
|
201
|
+
src: url,
|
|
202
|
+
title: 'Example Site',
|
|
203
|
+
description: 'An example website',
|
|
204
|
+
image: '',
|
|
205
|
+
favicon: '',
|
|
206
|
+
},
|
|
207
|
+
meta: {},
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
vi.spyOn(editor, 'getAssetForExternalContent').mockResolvedValue(mockAsset)
|
|
211
|
+
|
|
212
|
+
const result = await createBookmarkFromUrl(editor, { url })
|
|
213
|
+
|
|
214
|
+
assert(result.ok, 'Failed to create bookmark')
|
|
215
|
+
const shape = result.value
|
|
216
|
+
expect(shape.x).toBe(viewportCenter.x - 150)
|
|
217
|
+
expect(shape.y).toBe(viewportCenter.y - 160)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('handles asset creation failure gracefully', async () => {
|
|
221
|
+
const url = 'https://invalid-url.com'
|
|
222
|
+
const center = { x: 100, y: 200 }
|
|
223
|
+
|
|
224
|
+
// Mock the asset creation to fail
|
|
225
|
+
vi.spyOn(editor, 'getAssetForExternalContent').mockRejectedValue(new Error('Failed to fetch'))
|
|
226
|
+
|
|
227
|
+
const result = await createBookmarkFromUrl(editor, { url, center })
|
|
228
|
+
|
|
229
|
+
assert(!result.ok, 'Failed to create bookmark')
|
|
230
|
+
expect(result.error).toBe('Failed to fetch')
|
|
231
|
+
|
|
232
|
+
// Verify no shape was created
|
|
233
|
+
const shapes = editor.getCurrentPageShapes()
|
|
234
|
+
expect(shapes).toHaveLength(0)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('creates bookmark shape even when asset creation returns null', async () => {
|
|
238
|
+
const url = 'https://example.com'
|
|
239
|
+
const center = { x: 100, y: 200 }
|
|
240
|
+
|
|
241
|
+
// Mock the asset creation to return null
|
|
242
|
+
vi.spyOn(editor, 'getAssetForExternalContent').mockResolvedValue(null as any)
|
|
243
|
+
|
|
244
|
+
const result = await createBookmarkFromUrl(editor, { url, center })
|
|
245
|
+
|
|
246
|
+
assert(result.ok, 'Failed to create bookmark')
|
|
247
|
+
const shape = result.value
|
|
248
|
+
expect(shape.type).toBe('bookmark')
|
|
249
|
+
expect(shape.props.url).toBe(url)
|
|
250
|
+
expect(shape.props.assetId).toBe(null)
|
|
251
|
+
|
|
252
|
+
// Verify the shape was created
|
|
253
|
+
const createdShape = editor.getShape(result.value.id)
|
|
254
|
+
expect(createdShape).toBeDefined()
|
|
255
|
+
})
|
|
256
|
+
})
|
|
@@ -173,6 +173,7 @@ describe('custom handle snapping', () => {
|
|
|
173
173
|
handlePoints: VecModel[] | 'default'
|
|
174
174
|
selfSnapOutline: VecModel[] | 'default'
|
|
175
175
|
selfSnapPoints: VecModel[] | 'default'
|
|
176
|
+
handleSnapType?: 'point' | 'align'
|
|
176
177
|
}
|
|
177
178
|
>
|
|
178
179
|
class TestShapeUtil extends BaseBoxShapeUtil<TestShape> {
|
|
@@ -213,17 +214,23 @@ describe('custom handle snapping', () => {
|
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
override getHandles(shape: TestShape): TLHandle[] {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
const handle: TLHandle = {
|
|
218
|
+
id: 'handle',
|
|
219
|
+
label: 'handle',
|
|
220
|
+
type: 'vertex',
|
|
221
|
+
x: shape.props.ownHandle.x,
|
|
222
|
+
y: shape.props.ownHandle.y,
|
|
223
|
+
index: ZERO_INDEX_KEY,
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (shape.props.handleSnapType) {
|
|
227
|
+
handle.snapType = shape.props.handleSnapType
|
|
228
|
+
} else {
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
230
|
+
handle.canSnap = true
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return [handle]
|
|
227
234
|
}
|
|
228
235
|
override onHandleDrag(shape: TestShape, { handle }: TLHandleDragInfo<TestShape>) {
|
|
229
236
|
return { ...shape, props: { ...shape.props, ownHandle: { x: handle.x, y: handle.y } } }
|
|
@@ -495,5 +502,42 @@ describe('custom handle snapping', () => {
|
|
|
495
502
|
expect(ownHandlePosition()).toMatchObject({ x: 20, y: 50 })
|
|
496
503
|
})
|
|
497
504
|
})
|
|
505
|
+
|
|
506
|
+
describe('with snapType set to align', () => {
|
|
507
|
+
beforeEach(() => {
|
|
508
|
+
editor.updateShape<TestShape>({
|
|
509
|
+
id: ids.test,
|
|
510
|
+
type: 'test',
|
|
511
|
+
props: {
|
|
512
|
+
selfSnapPoints: [
|
|
513
|
+
{ x: 20, y: 50 },
|
|
514
|
+
{ x: 60, y: 10 },
|
|
515
|
+
],
|
|
516
|
+
handleSnapType: 'align',
|
|
517
|
+
},
|
|
518
|
+
})
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
test('snaps to the y axis', () => {
|
|
522
|
+
startDraggingOwnHandle()
|
|
523
|
+
editor.pointerMove(18, 0, undefined, { ctrlKey: true })
|
|
524
|
+
expect(editor.snaps.getIndicators()).toHaveLength(1)
|
|
525
|
+
expect(ownHandlePosition()).toMatchObject({ x: 20, y: 0 })
|
|
526
|
+
})
|
|
527
|
+
|
|
528
|
+
test('snaps to the x axis', () => {
|
|
529
|
+
startDraggingOwnHandle()
|
|
530
|
+
editor.pointerMove(0, 48, undefined, { ctrlKey: true })
|
|
531
|
+
expect(editor.snaps.getIndicators()).toHaveLength(1)
|
|
532
|
+
expect(ownHandlePosition()).toMatchObject({ x: 0, y: 50 })
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
test('snaps to both axes', () => {
|
|
536
|
+
startDraggingOwnHandle()
|
|
537
|
+
editor.pointerMove(18, 9, undefined, { ctrlKey: true })
|
|
538
|
+
expect(editor.snaps.getIndicators()).toHaveLength(2)
|
|
539
|
+
expect(ownHandlePosition()).toMatchObject({ x: 20, y: 10 })
|
|
540
|
+
})
|
|
541
|
+
})
|
|
498
542
|
})
|
|
499
543
|
})
|
package/tldraw.css
CHANGED
|
@@ -1325,6 +1325,10 @@ input,
|
|
|
1325
1325
|
flex: 1;
|
|
1326
1326
|
}
|
|
1327
1327
|
|
|
1328
|
+
.tl-bookmark__copy_container:has(.tl-bookmark__link:only-child) {
|
|
1329
|
+
justify-content: center;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1328
1332
|
.tl-bookmark__heading,
|
|
1329
1333
|
.tl-bookmark__description,
|
|
1330
1334
|
.tl-bookmark__link {
|
|
@@ -1357,7 +1361,7 @@ input,
|
|
|
1357
1361
|
line-clamp: 3;
|
|
1358
1362
|
text-overflow: ellipsis;
|
|
1359
1363
|
display: -webkit-box;
|
|
1360
|
-
color: var(--tl-color-text-
|
|
1364
|
+
color: var(--tl-color-text-1);
|
|
1361
1365
|
margin: var(--tl-space-2) 0px;
|
|
1362
1366
|
}
|
|
1363
1367
|
|
|
@@ -1369,11 +1373,12 @@ input,
|
|
|
1369
1373
|
font-size: 12px;
|
|
1370
1374
|
pointer-events: all;
|
|
1371
1375
|
display: flex;
|
|
1372
|
-
color: var(--tl-color-text-
|
|
1376
|
+
color: var(--tl-color-text-1);
|
|
1373
1377
|
align-items: center;
|
|
1374
1378
|
cursor: var(--tl-cursor-pointer);
|
|
1375
1379
|
width: fit-content;
|
|
1376
1380
|
max-width: 100%;
|
|
1381
|
+
text-decoration: none;
|
|
1377
1382
|
}
|
|
1378
1383
|
|
|
1379
1384
|
.tl-bookmark__link > span {
|