tldraw 3.15.0-next.f1dfcef63951 → 3.16.0-next.c30b1b5e551a
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 +161 -95
- package/dist-cjs/index.js +42 -31
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawImage.js +5 -2
- package/dist-cjs/lib/TldrawImage.js.map +3 -3
- package/dist-cjs/lib/canvas/TldrawCropHandles.js +1 -1
- package/dist-cjs/lib/canvas/TldrawCropHandles.js.map +2 -2
- package/dist-cjs/lib/canvas/TldrawHandles.js +1 -1
- package/dist-cjs/lib/canvas/TldrawHandles.js.map +2 -2
- package/dist-cjs/lib/canvas/TldrawOverlays.js +1 -1
- package/dist-cjs/lib/canvas/TldrawOverlays.js.map +2 -2
- package/dist-cjs/lib/canvas/TldrawSelectionForeground.js +279 -271
- package/dist-cjs/lib/canvas/TldrawSelectionForeground.js.map +2 -2
- package/dist-cjs/lib/defaultExternalContentHandlers.js +1 -0
- package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +22 -36
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/arrowLabel.js +16 -4
- package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +3 -0
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +5 -5
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js +15 -1
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/PathBuilder.js +21 -3
- package/dist-cjs/lib/shapes/shared/PathBuilder.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -0
- package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js +1 -0
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/text/TextShapeUtil.js +5 -11
- package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
- package/dist-cjs/lib/styles.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +43 -22
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +2 -15
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +5 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +8 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js +8 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +8 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.js.map +2 -2
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +51 -1
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js +1 -0
- package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js +3 -4
- package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js.map +2 -2
- package/dist-cjs/lib/ui/components/Spinner.js +2 -25
- package/dist-cjs/lib/ui/components/Spinner.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +2 -1
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
- package/dist-cjs/lib/ui/components/menu-items.js +16 -0
- package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButtonIcon.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js +35 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +6 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +1 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +0 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +42 -8
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/context/events.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/menu-hooks.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +24 -7
- package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js +2 -2
- package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +8 -0
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
- package/dist-cjs/lib/ui/kbd-utils.js +2 -1
- package/dist-cjs/lib/ui/kbd-utils.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-cjs/lib/utils/excalidraw/putExcalidrawContent.js +1 -1
- package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js.map +2 -2
- package/dist-cjs/lib/utils/tldr/buildFromV1Document.js +3 -2
- package/dist-cjs/lib/utils/tldr/buildFromV1Document.js.map +2 -2
- package/dist-esm/index.d.mts +161 -95
- package/dist-esm/index.mjs +154 -135
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawImage.mjs +5 -2
- package/dist-esm/lib/TldrawImage.mjs.map +2 -2
- package/dist-esm/lib/canvas/TldrawCropHandles.mjs +1 -1
- package/dist-esm/lib/canvas/TldrawCropHandles.mjs.map +2 -2
- package/dist-esm/lib/canvas/TldrawHandles.mjs +1 -1
- package/dist-esm/lib/canvas/TldrawHandles.mjs.map +2 -2
- package/dist-esm/lib/canvas/TldrawOverlays.mjs +1 -1
- package/dist-esm/lib/canvas/TldrawOverlays.mjs.map +2 -2
- package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs +279 -271
- package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs.map +2 -2
- package/dist-esm/lib/defaultExternalContentHandlers.mjs +1 -0
- package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +24 -36
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +19 -5
- package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +3 -0
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +5 -5
- package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +15 -1
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/PathBuilder.mjs +22 -3
- package/dist-esm/lib/shapes/shared/PathBuilder.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +1 -0
- package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +1 -0
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +5 -11
- package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/styles.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +43 -22
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +2 -15
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +5 -0
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +8 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs +8 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +8 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.mjs.map +2 -2
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +51 -1
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs +2 -0
- package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs +3 -4
- package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Spinner.mjs +3 -26
- package/dist-esm/lib/ui/components/Spinner.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +2 -1
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
- package/dist-esm/lib/ui/components/menu-items.mjs +16 -0
- package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/Button/TldrawUiButtonIcon.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiDialog.mjs +1 -1
- package/dist-esm/lib/ui/components/primitives/TldrawUiDialog.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs +36 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +6 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +1 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +0 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +42 -8
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/context/events.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/menu-hooks.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +24 -7
- package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs +2 -2
- package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +8 -0
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
- package/dist-esm/lib/ui/kbd-utils.mjs +2 -1
- package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs +1 -1
- package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs.map +2 -2
- package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs +3 -2
- package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs.map +2 -2
- package/package.json +4 -3
- package/src/index.ts +174 -160
- package/src/lib/TldrawImage.tsx +6 -2
- package/src/lib/canvas/TldrawCropHandles.tsx +3 -1
- package/src/lib/canvas/TldrawHandles.tsx +5 -1
- package/src/lib/canvas/TldrawOverlays.tsx +1 -1
- package/src/lib/canvas/TldrawSelectionForeground.tsx +5 -1
- package/src/lib/defaultExternalContentHandlers.ts +2 -1
- package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +5 -5
- package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +25 -39
- package/src/lib/shapes/arrow/arrowLabel.ts +23 -3
- package/src/lib/shapes/arrow/toolStates/Pointing.tsx +3 -0
- package/src/lib/shapes/frame/FrameShapeUtil.tsx +5 -7
- package/src/lib/shapes/line/LineShapeUtil.tsx +19 -2
- package/src/lib/shapes/shared/PathBuilder.test.tsx +1 -1
- package/src/lib/shapes/shared/PathBuilder.tsx +35 -1
- package/src/lib/shapes/shared/PlainTextLabel.tsx +1 -0
- package/src/lib/shapes/shared/RichTextLabel.tsx +1 -0
- package/src/lib/shapes/text/TextShapeUtil.tsx +5 -12
- package/src/lib/styles.tsx +3 -1
- package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +54 -30
- package/src/lib/tools/SelectTool/childStates/Idle.ts +2 -24
- package/src/lib/tools/SelectTool/childStates/PointingShape.ts +7 -0
- package/src/lib/tools/SelectTool/childStates/Resizing.ts +12 -1
- package/src/lib/tools/SelectTool/childStates/Rotating.ts +11 -0
- package/src/lib/tools/SelectTool/childStates/Translating.ts +11 -0
- package/src/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.ts +1 -0
- package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +40 -0
- package/src/lib/ui/components/MainMenu/DefaultMainMenuContent.tsx +2 -0
- package/src/lib/ui/components/NavigationPanel/DefaultNavigationPanel.tsx +3 -4
- package/src/lib/ui/components/Spinner.tsx +2 -24
- package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +1 -0
- package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +3 -1
- package/src/lib/ui/components/menu-items.tsx +17 -0
- package/src/lib/ui/components/primitives/Button/TldrawUiButtonIcon.tsx +2 -2
- package/src/lib/ui/components/primitives/TldrawUiDialog.tsx +1 -1
- package/src/lib/ui/components/primitives/TldrawUiIcon.tsx +41 -3
- package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +6 -1
- package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +4 -0
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.tsx +2 -2
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +3 -4
- package/src/lib/ui/context/actions.tsx +44 -9
- package/src/lib/ui/context/events.tsx +4 -2
- package/src/lib/ui/hooks/menu-hooks.ts +1 -0
- package/src/lib/ui/hooks/useClipboardEvents.ts +31 -10
- package/src/lib/ui/hooks/useKeyboardShortcuts.ts +3 -2
- package/src/lib/ui/hooks/useTools.tsx +2 -1
- package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +8 -0
- package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +8 -0
- package/src/lib/ui/kbd-utils.ts +2 -1
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/ui.css +8 -22
- package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +16 -2
- package/src/lib/utils/excalidraw/putExcalidrawContent.ts +1 -1
- package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +24 -3
- package/src/lib/utils/tldr/buildFromV1Document.ts +2 -1
- package/src/test/Editor.test.tsx +68 -1
- package/src/test/SelectTool.test.ts +37 -11
- package/src/test/commands/clipboard.test.ts +1 -1
- package/src/test/commands/deletePage.test.ts +84 -1
- package/src/test/navigation.test.ts +254 -0
- package/src/test/shapeutils.test.ts +394 -45
- package/tldraw.css +29 -49
- package/src/test/editor.test.ts +0 -77
|
@@ -32,12 +32,14 @@ import {
|
|
|
32
32
|
debugFlags,
|
|
33
33
|
exhaustiveSwitchError,
|
|
34
34
|
getDefaultColorTheme,
|
|
35
|
+
getFontsFromRichText,
|
|
35
36
|
invLerp,
|
|
36
37
|
lerp,
|
|
37
38
|
mapObjectMapValues,
|
|
38
39
|
maybeSnapToGrid,
|
|
39
40
|
structuredClone,
|
|
40
41
|
toDomPrecision,
|
|
42
|
+
toRichText,
|
|
41
43
|
track,
|
|
42
44
|
useEditor,
|
|
43
45
|
useIsEditing,
|
|
@@ -46,12 +48,11 @@ import {
|
|
|
46
48
|
} from '@tldraw/editor'
|
|
47
49
|
import React, { useMemo } from 'react'
|
|
48
50
|
import { updateArrowTerminal } from '../../bindings/arrow/ArrowBindingUtil'
|
|
51
|
+
import { isEmptyRichText, renderPlaintextFromRichText } from '../../utils/text/richText'
|
|
49
52
|
import { PathBuilder } from '../shared/PathBuilder'
|
|
50
|
-
import {
|
|
53
|
+
import { RichTextLabel, RichTextSVG } from '../shared/RichTextLabel'
|
|
51
54
|
import { ShapeFill } from '../shared/ShapeFill'
|
|
52
|
-
import { SvgTextLabel } from '../shared/SvgTextLabel'
|
|
53
55
|
import { ARROW_LABEL_PADDING, STROKE_SIZES, TEXT_PROPS } from '../shared/default-shape-constants'
|
|
54
|
-
import { DefaultFontFaces } from '../shared/defaultFonts'
|
|
55
56
|
import { getFillDefForCanvas, getFillDefForExport } from '../shared/defaultStyleDefs'
|
|
56
57
|
import { useDefaultColorTheme } from '../shared/useDefaultColorTheme'
|
|
57
58
|
import { getArrowBodyPath, getArrowHandlePath } from './ArrowPath'
|
|
@@ -156,8 +157,13 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
override getFontFaces(shape: TLArrowShape) {
|
|
159
|
-
if (
|
|
160
|
-
|
|
160
|
+
if (isEmptyRichText(shape.props.richText)) return EMPTY_ARRAY
|
|
161
|
+
|
|
162
|
+
return getFontsFromRichText(this.editor, shape.props.richText, {
|
|
163
|
+
family: `tldraw_${shape.props.font}`,
|
|
164
|
+
weight: 'normal',
|
|
165
|
+
style: 'normal',
|
|
166
|
+
})
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
override getDefaultProps(): TLArrowShape['props'] {
|
|
@@ -174,7 +180,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
174
180
|
end: { x: 2, y: 0 },
|
|
175
181
|
arrowheadStart: 'none',
|
|
176
182
|
arrowheadEnd: 'arrow',
|
|
177
|
-
|
|
183
|
+
richText: toRichText(''),
|
|
178
184
|
labelPosition: 0.5,
|
|
179
185
|
font: 'draw',
|
|
180
186
|
scale: 1,
|
|
@@ -204,7 +210,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
204
210
|
: new Polyline2d({ points: info.route.points })
|
|
205
211
|
|
|
206
212
|
let labelGeom
|
|
207
|
-
if (isEditing || shape.props.
|
|
213
|
+
if (isEditing || !isEmptyRichText(shape.props.richText)) {
|
|
208
214
|
const labelPosition = getArrowLabelPosition(this.editor, shape)
|
|
209
215
|
if (debugFlags.debugGeometry.get()) {
|
|
210
216
|
debugGeom.push(...labelPosition.debugGeom)
|
|
@@ -276,7 +282,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
276
282
|
}
|
|
277
283
|
|
|
278
284
|
override getText(shape: TLArrowShape) {
|
|
279
|
-
return shape.props.
|
|
285
|
+
return renderPlaintextFromRichText(this.editor, shape.props.richText)
|
|
280
286
|
}
|
|
281
287
|
|
|
282
288
|
override onHandleDrag(shape: TLArrowShape, info: TLHandleDragInfo<TLArrowShape>) {
|
|
@@ -757,7 +763,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
757
763
|
const labelPosition = getArrowLabelPosition(this.editor, shape)
|
|
758
764
|
const isSelected = shape.id === this.editor.getOnlySelectedShapeId()
|
|
759
765
|
const isEditing = this.editor.getEditingShapeId() === shape.id
|
|
760
|
-
const showArrowLabel = isEditing || shape.props.
|
|
766
|
+
const showArrowLabel = isEditing || !isEmptyRichText(shape.props.richText)
|
|
761
767
|
|
|
762
768
|
return (
|
|
763
769
|
<>
|
|
@@ -771,16 +777,15 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
771
777
|
)}
|
|
772
778
|
</SVGContainer>
|
|
773
779
|
{showArrowLabel && (
|
|
774
|
-
<
|
|
780
|
+
<RichTextLabel
|
|
775
781
|
shapeId={shape.id}
|
|
776
|
-
classNamePrefix="tl-arrow"
|
|
777
782
|
type="arrow"
|
|
778
783
|
font={shape.props.font}
|
|
779
784
|
fontSize={getArrowLabelFontSize(shape)}
|
|
780
785
|
lineHeight={TEXT_PROPS.lineHeight}
|
|
781
786
|
align="middle"
|
|
782
787
|
verticalAlign="middle"
|
|
783
|
-
|
|
788
|
+
richText={shape.props.richText}
|
|
784
789
|
labelColor={theme[shape.props.labelColor].solid}
|
|
785
790
|
textWidth={labelPosition.box.w - ARROW_LABEL_PADDING * 2 * shape.props.scale}
|
|
786
791
|
isSelected={isSelected}
|
|
@@ -806,9 +811,9 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
806
811
|
const { start, end } = getArrowTerminalsInArrowSpace(this.editor, shape, info?.bindings)
|
|
807
812
|
const geometry = this.editor.getShapeGeometry<Group2d>(shape)
|
|
808
813
|
const bounds = geometry.bounds
|
|
814
|
+
const isEmpty = isEmptyRichText(shape.props.richText)
|
|
809
815
|
|
|
810
|
-
const labelGeometry =
|
|
811
|
-
isEditing || shape.props.text.trim() ? (geometry.children[1] as Rectangle2d) : null
|
|
816
|
+
const labelGeometry = isEditing || !isEmpty ? (geometry.children[1] as Rectangle2d) : null
|
|
812
817
|
|
|
813
818
|
if (Vec.Equals(start, end)) return null
|
|
814
819
|
|
|
@@ -847,7 +852,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
847
852
|
<defs>
|
|
848
853
|
<ArrowClipPath
|
|
849
854
|
radius={3.5 * shape.props.scale}
|
|
850
|
-
hasText={
|
|
855
|
+
hasText={!isEmpty}
|
|
851
856
|
bounds={bounds}
|
|
852
857
|
labelBounds={labelBounds}
|
|
853
858
|
as={clipStartArrowhead && as ? as : ''}
|
|
@@ -905,7 +910,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
905
910
|
}
|
|
906
911
|
|
|
907
912
|
override onEditStart(shape: TLArrowShape) {
|
|
908
|
-
if (shape.props.
|
|
913
|
+
if (isEmptyRichText(shape.props.richText)) {
|
|
909
914
|
// editing text for the first time, so set the position to the default:
|
|
910
915
|
const labelPosition = getArrowLabelDefaultPosition(this.editor, shape)
|
|
911
916
|
this.editor.updateShape<TLArrowShape>({
|
|
@@ -916,26 +921,6 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
916
921
|
}
|
|
917
922
|
}
|
|
918
923
|
|
|
919
|
-
override onEditEnd(shape: TLArrowShape) {
|
|
920
|
-
const {
|
|
921
|
-
id,
|
|
922
|
-
type,
|
|
923
|
-
props: { text },
|
|
924
|
-
} = shape
|
|
925
|
-
|
|
926
|
-
if (text.trimEnd() !== shape.props.text) {
|
|
927
|
-
this.editor.updateShapes<TLArrowShape>([
|
|
928
|
-
{
|
|
929
|
-
id,
|
|
930
|
-
type,
|
|
931
|
-
props: {
|
|
932
|
-
text: text.trimEnd(),
|
|
933
|
-
},
|
|
934
|
-
},
|
|
935
|
-
])
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
|
|
939
924
|
override toSvg(shape: TLArrowShape, ctx: SvgExportContext) {
|
|
940
925
|
ctx.addExportDef(getFillDefForExport(shape.props.fill))
|
|
941
926
|
const theme = getDefaultColorTheme(ctx)
|
|
@@ -944,12 +929,12 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|
|
944
929
|
return (
|
|
945
930
|
<g transform={`scale(${scaleFactor})`}>
|
|
946
931
|
<ArrowSvg shape={shape} shouldDisplayHandles={false} />
|
|
947
|
-
<
|
|
932
|
+
<RichTextSVG
|
|
948
933
|
fontSize={getArrowLabelFontSize(shape)}
|
|
949
934
|
font={shape.props.font}
|
|
950
935
|
align="middle"
|
|
951
936
|
verticalAlign="middle"
|
|
952
|
-
|
|
937
|
+
richText={shape.props.richText}
|
|
953
938
|
labelColor={theme[shape.props.labelColor].solid}
|
|
954
939
|
bounds={getArrowLabelPosition(this.editor, shape)
|
|
955
940
|
.box.clone()
|
|
@@ -1031,6 +1016,7 @@ const ArrowSvg = track(function ArrowSvg({
|
|
|
1031
1016
|
if (!geometry) return null
|
|
1032
1017
|
const bounds = Box.ZeroFix(geometry.bounds)
|
|
1033
1018
|
const bindings = getArrowBindings(editor, shape)
|
|
1019
|
+
const isEmpty = isEmptyRichText(shape.props.richText)
|
|
1034
1020
|
|
|
1035
1021
|
if (!info?.isValid) return null
|
|
1036
1022
|
|
|
@@ -1081,7 +1067,7 @@ const ArrowSvg = track(function ArrowSvg({
|
|
|
1081
1067
|
<clipPath id={clipPathId}>
|
|
1082
1068
|
<ArrowClipPath
|
|
1083
1069
|
radius={3.5 * shape.props.scale}
|
|
1084
|
-
hasText={isEditing ||
|
|
1070
|
+
hasText={isEditing || !isEmpty}
|
|
1085
1071
|
bounds={bounds}
|
|
1086
1072
|
labelBounds={labelPosition.box}
|
|
1087
1073
|
as={clipStartArrowhead && as ? as : ''}
|
|
@@ -9,13 +9,17 @@ import {
|
|
|
9
9
|
Polygon2d,
|
|
10
10
|
Polyline2d,
|
|
11
11
|
TLArrowShape,
|
|
12
|
+
TLShape,
|
|
12
13
|
Vec,
|
|
13
14
|
VecLike,
|
|
14
15
|
clamp,
|
|
15
16
|
createComputedCache,
|
|
16
17
|
exhaustiveSwitchError,
|
|
17
18
|
getChangedKeys,
|
|
19
|
+
pointInPolygon,
|
|
20
|
+
toRichText,
|
|
18
21
|
} from '@tldraw/editor'
|
|
22
|
+
import { isEmptyRichText, renderHtmlFromRichTextForMeasurement } from '../../utils/text/richText'
|
|
19
23
|
import {
|
|
20
24
|
ARROW_LABEL_FONT_SIZES,
|
|
21
25
|
ARROW_LABEL_PADDING,
|
|
@@ -59,14 +63,18 @@ const labelSizeCache = createComputedCache(
|
|
|
59
63
|
|
|
60
64
|
const bodyGeom = getArrowBodyGeometry(editor, shape)
|
|
61
65
|
// We use 'i' as a default label to measure against as a minimum width.
|
|
62
|
-
const
|
|
66
|
+
const isEmpty = isEmptyRichText(shape.props.richText)
|
|
67
|
+
const html = renderHtmlFromRichTextForMeasurement(
|
|
68
|
+
editor,
|
|
69
|
+
isEmpty ? toRichText('i') : shape.props.richText
|
|
70
|
+
)
|
|
63
71
|
|
|
64
72
|
const bodyBounds = bodyGeom.bounds
|
|
65
73
|
|
|
66
74
|
const fontSize = getArrowLabelFontSize(shape)
|
|
67
75
|
|
|
68
76
|
// First we measure the text with no constraints
|
|
69
|
-
const { w, h } = editor.textMeasure.
|
|
77
|
+
const { w, h } = editor.textMeasure.measureHtml(html, {
|
|
70
78
|
...TEXT_PROPS,
|
|
71
79
|
fontFamily: FONT_FAMILIES[shape.props.font],
|
|
72
80
|
fontSize,
|
|
@@ -96,7 +104,7 @@ const labelSizeCache = createComputedCache(
|
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
if (shouldSquish) {
|
|
99
|
-
const { w: squishedWidth, h: squishedHeight } = editor.textMeasure.
|
|
107
|
+
const { w: squishedWidth, h: squishedHeight } = editor.textMeasure.measureHtml(html, {
|
|
100
108
|
...TEXT_PROPS,
|
|
101
109
|
fontFamily: FONT_FAMILIES[shape.props.font],
|
|
102
110
|
fontSize,
|
|
@@ -292,3 +300,15 @@ export function getArrowLabelDefaultPosition(editor: Editor, shape: TLArrowShape
|
|
|
292
300
|
exhaustiveSwitchError(info, 'type')
|
|
293
301
|
}
|
|
294
302
|
}
|
|
303
|
+
|
|
304
|
+
/** @internal */
|
|
305
|
+
export function isOverArrowLabel(editor: Editor, shape: TLShape) {
|
|
306
|
+
if (!editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) return false
|
|
307
|
+
|
|
308
|
+
const pointInShapeSpace = editor.getPointInShapeSpace(shape, editor.inputs.currentPagePoint)
|
|
309
|
+
// How should we handle multiple labels? Do shapes ever have multiple labels?
|
|
310
|
+
const labelGeometry = editor.getShapeGeometry<Group2d>(shape).children[1]
|
|
311
|
+
// Knowing what we know about arrows... if the shape has no text in its label,
|
|
312
|
+
// then the label geometry should not be there.
|
|
313
|
+
return labelGeometry && pointInPolygon(pointInShapeSpace, labelGeometry.vertices)
|
|
314
|
+
}
|
|
@@ -118,6 +118,7 @@ export class Pointing extends StateNode {
|
|
|
118
118
|
const change = util.onHandleDrag?.(shape, {
|
|
119
119
|
handle: { ...startHandle, x: 0, y: 0 },
|
|
120
120
|
isPrecise: true,
|
|
121
|
+
isCreatingShape: true,
|
|
121
122
|
initial: initial,
|
|
122
123
|
})
|
|
123
124
|
|
|
@@ -145,6 +146,7 @@ export class Pointing extends StateNode {
|
|
|
145
146
|
const change = util.onHandleDrag?.(shape, {
|
|
146
147
|
handle: { ...startHandle, x: 0, y: 0 },
|
|
147
148
|
isPrecise: this.isPrecise,
|
|
149
|
+
isCreatingShape: true,
|
|
148
150
|
initial: initial,
|
|
149
151
|
})
|
|
150
152
|
|
|
@@ -162,6 +164,7 @@ export class Pointing extends StateNode {
|
|
|
162
164
|
const change = util.onHandleDrag?.(this.editor.getShape(shape)!, {
|
|
163
165
|
handle: { ...endHandle, x: point.x, y: point.y },
|
|
164
166
|
isPrecise: false,
|
|
167
|
+
isCreatingShape: true,
|
|
165
168
|
initial: initial,
|
|
166
169
|
})
|
|
167
170
|
|
|
@@ -219,9 +219,6 @@ export class FrameShapeUtil extends BaseBoxShapeUtil<TLFrameShape> {
|
|
|
219
219
|
[shape.id]
|
|
220
220
|
)
|
|
221
221
|
|
|
222
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
223
|
-
const zoomLevel = useValue('zoom level', () => this.editor.getZoomLevel(), [this.editor])
|
|
224
|
-
|
|
225
222
|
const showFrameColors = this.options.showColors
|
|
226
223
|
|
|
227
224
|
const color = theme[shape.props.color]
|
|
@@ -236,12 +233,13 @@ export class FrameShapeUtil extends BaseBoxShapeUtil<TLFrameShape> {
|
|
|
236
233
|
<SVGContainer>
|
|
237
234
|
<rect
|
|
238
235
|
className={classNames('tl-frame__body', { 'tl-frame__creating': isCreating })}
|
|
239
|
-
width={shape.props.w + 1 / zoomLevel}
|
|
240
|
-
height={shape.props.h + 1 / zoomLevel}
|
|
241
236
|
fill={frameFill}
|
|
242
237
|
stroke={frameStroke}
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
style={{
|
|
239
|
+
width: `calc(${shape.props.w}px + 1px / var(--tl-zoom))`,
|
|
240
|
+
height: `calc(${shape.props.h}px + 1px / var(--tl-zoom))`,
|
|
241
|
+
transform: `translate(calc(-0.5px / var(--tl-zoom)), calc(-0.5px / var(--tl-zoom)))`,
|
|
242
|
+
}}
|
|
245
243
|
/>
|
|
246
244
|
</SVGContainer>
|
|
247
245
|
{isCreating ? null : (
|
|
@@ -145,8 +145,6 @@ export class LineShapeUtil extends ShapeUtil<TLLineShape> {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
override onHandleDrag(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {
|
|
148
|
-
// we should only ever be dragging vertex handles
|
|
149
|
-
if (handle.type !== 'vertex') return
|
|
150
148
|
const newPoint = maybeSnapToGrid(new Vec(handle.x, handle.y), this.editor)
|
|
151
149
|
return {
|
|
152
150
|
...shape,
|
|
@@ -160,6 +158,25 @@ export class LineShapeUtil extends ShapeUtil<TLLineShape> {
|
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
|
|
161
|
+
override onHandleDragStart(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {
|
|
162
|
+
// For line shapes, if we're dragging a "create" handle, then
|
|
163
|
+
// create a new vertex handle at that point; and make this handle
|
|
164
|
+
// the handle that we're dragging.
|
|
165
|
+
if (handle.type === 'create') {
|
|
166
|
+
return {
|
|
167
|
+
...shape,
|
|
168
|
+
props: {
|
|
169
|
+
...shape.props,
|
|
170
|
+
points: {
|
|
171
|
+
...shape.props.points,
|
|
172
|
+
[handle.index]: { id: handle.index, index: handle.index, x: handle.x, y: handle.y },
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
163
180
|
component(shape: TLLineShape) {
|
|
164
181
|
return (
|
|
165
182
|
<SVGContainer style={{ minWidth: 50, minHeight: 50 }}>
|
|
@@ -138,7 +138,7 @@ describe('PathBuilder', () => {
|
|
|
138
138
|
.toGeometry()
|
|
139
139
|
|
|
140
140
|
expect(geometry?.toSimpleSvgPath()).toMatchInlineSnapshot(
|
|
141
|
-
`"M0,0L100,100L100,
|
|
141
|
+
`"M0,0L100,100L100,0L84.92197106154207,-11.50593202657044L67.93757691512266,-18.409491194065584L50.000000178767834,-20.71067750830319L32.06242347050369,-18.409490975101022L15.078029408356239,-11.505931600276853L6.103515630684342e-7,6.103515559630068e-7L-11.505931600276849,15.078029408356231L-18.409490975101022,32.062423470503674L-20.710677508303192,50.00000017876782L-18.409491194065588,67.93757691512262L-11.50593202657045,84.92197106154204L-1.4210854715202004e-14,99.99999999999999L0,0Z"`
|
|
142
142
|
)
|
|
143
143
|
})
|
|
144
144
|
})
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
Geometry2dFilters,
|
|
11
11
|
Geometry2dOptions,
|
|
12
12
|
getPerfectDashProps,
|
|
13
|
+
getVerticesCountForArcLength,
|
|
13
14
|
Group2d,
|
|
14
15
|
modulate,
|
|
15
16
|
PerfectDashTerminal,
|
|
@@ -121,6 +122,7 @@ export interface CubicBezierToPathBuilderCommand extends PathBuilderCommandBase
|
|
|
121
122
|
type: 'cubic'
|
|
122
123
|
cp1: VecModel
|
|
123
124
|
cp2: VecModel
|
|
125
|
+
resolution?: number
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
/** @internal */
|
|
@@ -317,8 +319,17 @@ export class PathBuilder {
|
|
|
317
319
|
// Calculate the sweep angle
|
|
318
320
|
const sweepAngle = endAngle - startAngle
|
|
319
321
|
|
|
322
|
+
// Calculate the approximate arc length. General ellipse arc length is expensive - there's
|
|
323
|
+
// no closed form solution, so we have to do iterative numerical approximation. As we only
|
|
324
|
+
// use this to control the resolution of later approximations, let's cheat and just use the
|
|
325
|
+
// circular arc length with the largest radius:
|
|
326
|
+
const approximateArcLength = Math.max(rx1, ry1) * Math.abs(sweepAngle)
|
|
327
|
+
|
|
320
328
|
// Approximate the arc using cubic bezier curves
|
|
321
329
|
const numSegments = Math.min(4, Math.ceil(Math.abs(sweepAngle) / (Math.PI / 2)))
|
|
330
|
+
const resolutionPerSegment = Math.ceil(
|
|
331
|
+
getVerticesCountForArcLength(approximateArcLength) / numSegments
|
|
332
|
+
)
|
|
322
333
|
const anglePerSegment = sweepAngle / numSegments
|
|
323
334
|
|
|
324
335
|
// Helper function to compute point on ellipse
|
|
@@ -364,7 +375,16 @@ export class PathBuilder {
|
|
|
364
375
|
const cp2y = end.y - handleScale * d2.y
|
|
365
376
|
|
|
366
377
|
const bezierOpts = i === 0 ? opts : { ...opts, mergeWithPrevious: true }
|
|
367
|
-
this.
|
|
378
|
+
this.cubicBezierToWithResolution(
|
|
379
|
+
end.x,
|
|
380
|
+
end.y,
|
|
381
|
+
cp1x,
|
|
382
|
+
cp1y,
|
|
383
|
+
cp2x,
|
|
384
|
+
cp2y,
|
|
385
|
+
bezierOpts,
|
|
386
|
+
resolutionPerSegment
|
|
387
|
+
)
|
|
368
388
|
}
|
|
369
389
|
|
|
370
390
|
return this
|
|
@@ -378,6 +398,18 @@ export class PathBuilder {
|
|
|
378
398
|
cp2X: number,
|
|
379
399
|
cp2Y: number,
|
|
380
400
|
opts?: PathBuilderCommandOpts
|
|
401
|
+
) {
|
|
402
|
+
return this.cubicBezierToWithResolution(x, y, cp1X, cp1Y, cp2X, cp2Y, opts)
|
|
403
|
+
}
|
|
404
|
+
private cubicBezierToWithResolution(
|
|
405
|
+
x: number,
|
|
406
|
+
y: number,
|
|
407
|
+
cp1X: number,
|
|
408
|
+
cp1Y: number,
|
|
409
|
+
cp2X: number,
|
|
410
|
+
cp2Y: number,
|
|
411
|
+
opts?: PathBuilderCommandOpts,
|
|
412
|
+
resolution?: number
|
|
381
413
|
) {
|
|
382
414
|
this.assertHasMoveTo()
|
|
383
415
|
this.commands.push({
|
|
@@ -388,6 +420,7 @@ export class PathBuilder {
|
|
|
388
420
|
cp2: { x: cp2X, y: cp2Y },
|
|
389
421
|
isClose: false,
|
|
390
422
|
opts,
|
|
423
|
+
resolution,
|
|
391
424
|
})
|
|
392
425
|
return this
|
|
393
426
|
}
|
|
@@ -972,6 +1005,7 @@ export class PathBuilderGeometry2d extends Geometry2d {
|
|
|
972
1005
|
cp1: Vec.From(command.cp1),
|
|
973
1006
|
cp2: Vec.From(command.cp2),
|
|
974
1007
|
end: Vec.From(command),
|
|
1008
|
+
resolution: command.resolution,
|
|
975
1009
|
})
|
|
976
1010
|
)
|
|
977
1011
|
break
|
|
@@ -128,6 +128,7 @@ export const RichTextLabel = React.memo(function RichTextLabel({
|
|
|
128
128
|
return (
|
|
129
129
|
<div
|
|
130
130
|
className={`${cssPrefix}-label tl-text-wrapper tl-rich-text-wrapper`}
|
|
131
|
+
aria-hidden={!isEditing}
|
|
131
132
|
data-font={font}
|
|
132
133
|
data-align={align}
|
|
133
134
|
data-hastext={!isEmpty}
|
|
@@ -303,33 +303,26 @@ export class TextShapeUtil extends ShapeUtil<TLTextShape> {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
function getTextSize(editor: Editor, props: TLTextShape['props']) {
|
|
306
|
-
const { font, richText,
|
|
306
|
+
const { font, richText, size, w } = props
|
|
307
307
|
|
|
308
|
-
const minWidth =
|
|
308
|
+
const minWidth = 16
|
|
309
309
|
const fontSize = FONT_SIZES[size]
|
|
310
310
|
|
|
311
|
-
const
|
|
312
|
-
? null
|
|
313
|
-
: // `measureText` floors the number so we need to do the same here to avoid issues.
|
|
314
|
-
Math.floor(Math.max(minWidth, w))
|
|
311
|
+
const maybeFixedWidth = props.autoSize ? null : Math.max(minWidth, Math.floor(w))
|
|
315
312
|
|
|
316
313
|
const html = renderHtmlFromRichTextForMeasurement(editor, richText)
|
|
317
314
|
const result = editor.textMeasure.measureHtml(html, {
|
|
318
315
|
...TEXT_PROPS,
|
|
319
316
|
fontFamily: FONT_FAMILIES[font],
|
|
320
317
|
fontSize: fontSize,
|
|
321
|
-
maxWidth:
|
|
318
|
+
maxWidth: maybeFixedWidth,
|
|
322
319
|
})
|
|
323
320
|
|
|
324
321
|
// If we're autosizing the measureText will essentially `Math.floor`
|
|
325
322
|
// the numbers so `19` rather than `19.3`, this means we must +1 to
|
|
326
323
|
// whatever we get to avoid wrapping.
|
|
327
|
-
if (autoSize) {
|
|
328
|
-
result.w += 1
|
|
329
|
-
}
|
|
330
|
-
|
|
331
324
|
return {
|
|
332
|
-
width: Math.max(minWidth, result.w),
|
|
325
|
+
width: maybeFixedWidth ?? Math.max(minWidth, result.w + 1),
|
|
333
326
|
height: Math.max(fontSize, result.h),
|
|
334
327
|
}
|
|
335
328
|
}
|
package/src/lib/styles.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Mat,
|
|
2
3
|
StateNode,
|
|
3
4
|
TLArrowShape,
|
|
4
5
|
TLHandle,
|
|
@@ -26,20 +27,20 @@ export type DraggingHandleInfo = TLPointerEventInfo & {
|
|
|
26
27
|
export class DraggingHandle extends StateNode {
|
|
27
28
|
static override id = 'dragging_handle'
|
|
28
29
|
|
|
29
|
-
shapeId
|
|
30
|
-
initialHandle
|
|
31
|
-
initialAdjacentHandle
|
|
32
|
-
initialPagePoint
|
|
30
|
+
shapeId!: TLShapeId
|
|
31
|
+
initialHandle!: TLHandle
|
|
32
|
+
initialAdjacentHandle!: TLHandle | null
|
|
33
|
+
initialPagePoint!: Vec
|
|
33
34
|
|
|
34
|
-
markId
|
|
35
|
-
initialPageTransform
|
|
36
|
-
initialPageRotation
|
|
35
|
+
markId!: string
|
|
36
|
+
initialPageTransform!: Mat
|
|
37
|
+
initialPageRotation!: number
|
|
37
38
|
|
|
38
|
-
info
|
|
39
|
+
info!: DraggingHandleInfo
|
|
39
40
|
|
|
40
41
|
isPrecise = false
|
|
41
|
-
isPreciseId
|
|
42
|
-
pointingId
|
|
42
|
+
isPreciseId: TLShapeId | null = null
|
|
43
|
+
pointingId: TLShapeId | null = null
|
|
43
44
|
|
|
44
45
|
override onEnter(info: DraggingHandleInfo) {
|
|
45
46
|
const { shape, isCreating, creatingMarkId, handle } = info
|
|
@@ -66,26 +67,6 @@ export class DraggingHandle extends StateNode {
|
|
|
66
67
|
|
|
67
68
|
this.initialHandle = structuredClone(handle)
|
|
68
69
|
|
|
69
|
-
if (this.editor.isShapeOfType<TLLineShape>(shape, 'line')) {
|
|
70
|
-
// For line shapes, if we're dragging a "create" handle, then
|
|
71
|
-
// create a new vertex handle at that point; and make this handle
|
|
72
|
-
// the handle that we're dragging.
|
|
73
|
-
if (this.initialHandle.type === 'create') {
|
|
74
|
-
this.editor.updateShape({
|
|
75
|
-
...shape,
|
|
76
|
-
props: {
|
|
77
|
-
points: {
|
|
78
|
-
...shape.props.points,
|
|
79
|
-
[handle.index]: { id: handle.index, index: handle.index, x: handle.x, y: handle.y },
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
const handlesAfter = this.editor.getShapeHandles(shape)!
|
|
84
|
-
const handleAfter = handlesAfter.find((h) => h.index === handle.index)!
|
|
85
|
-
this.initialHandle = structuredClone(handleAfter)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
70
|
this.initialPageTransform = this.editor.getShapePageTransform(shape)!
|
|
90
71
|
this.initialPageRotation = this.initialPageTransform.rotation()
|
|
91
72
|
this.initialPagePoint = this.editor.inputs.originPagePoint.clone()
|
|
@@ -135,6 +116,19 @@ export class DraggingHandle extends StateNode {
|
|
|
135
116
|
}
|
|
136
117
|
// -->
|
|
137
118
|
|
|
119
|
+
// Call onHandleDragStart callback
|
|
120
|
+
const handleDragInfo = {
|
|
121
|
+
handle: this.initialHandle,
|
|
122
|
+
isPrecise: this.isPrecise,
|
|
123
|
+
isCreatingShape: !!this.info.isCreating,
|
|
124
|
+
initial: shape,
|
|
125
|
+
}
|
|
126
|
+
const util = this.editor.getShapeUtil(shape)
|
|
127
|
+
const startChanges = util.onHandleDragStart?.(shape, handleDragInfo)
|
|
128
|
+
if (startChanges) {
|
|
129
|
+
this.editor.updateShapes([{ ...startChanges, id: shape.id, type: shape.type }])
|
|
130
|
+
}
|
|
131
|
+
|
|
138
132
|
this.update()
|
|
139
133
|
|
|
140
134
|
this.editor.select(this.shapeId)
|
|
@@ -204,6 +198,22 @@ export class DraggingHandle extends StateNode {
|
|
|
204
198
|
this.editor.snaps.clearIndicators()
|
|
205
199
|
kickoutOccludedShapes(this.editor, [this.shapeId])
|
|
206
200
|
|
|
201
|
+
// Call onHandleDragEnd callback before state transitions
|
|
202
|
+
const shape = this.editor.getShape(this.shapeId)
|
|
203
|
+
if (shape) {
|
|
204
|
+
const util = this.editor.getShapeUtil(shape)
|
|
205
|
+
const handleDragInfo = {
|
|
206
|
+
handle: this.initialHandle,
|
|
207
|
+
isPrecise: this.isPrecise,
|
|
208
|
+
isCreatingShape: !!this.info.isCreating,
|
|
209
|
+
initial: this.info.shape,
|
|
210
|
+
}
|
|
211
|
+
const endChanges = util.onHandleDragEnd?.(shape, handleDragInfo)
|
|
212
|
+
if (endChanges) {
|
|
213
|
+
this.editor.updateShapes([{ ...endChanges, id: shape.id, type: shape.type }])
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
207
217
|
const { onInteractionEnd } = this.info
|
|
208
218
|
if (this.editor.getInstanceState().isToolLocked && onInteractionEnd) {
|
|
209
219
|
// Return to the tool that was active before this one,
|
|
@@ -216,6 +226,19 @@ export class DraggingHandle extends StateNode {
|
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
private cancel() {
|
|
229
|
+
// Call onHandleDragCancel callback before bailing to mark
|
|
230
|
+
const shape = this.editor.getShape(this.shapeId)
|
|
231
|
+
if (shape) {
|
|
232
|
+
const util = this.editor.getShapeUtil(shape)
|
|
233
|
+
const handleDragInfo = {
|
|
234
|
+
handle: this.initialHandle,
|
|
235
|
+
isPrecise: this.isPrecise,
|
|
236
|
+
isCreatingShape: !!this.info.isCreating,
|
|
237
|
+
initial: this.info.shape,
|
|
238
|
+
}
|
|
239
|
+
util.onHandleDragCancel?.(shape, handleDragInfo)
|
|
240
|
+
}
|
|
241
|
+
|
|
219
242
|
this.editor.bailToMark(this.markId)
|
|
220
243
|
this.editor.snaps.clearIndicators()
|
|
221
244
|
|
|
@@ -284,6 +307,7 @@ export class DraggingHandle extends StateNode {
|
|
|
284
307
|
const changes = util.onHandleDrag?.(shape, {
|
|
285
308
|
handle: nextHandle,
|
|
286
309
|
isPrecise: this.isPrecise || altKey,
|
|
310
|
+
isCreatingShape: !!this.info.isCreating,
|
|
287
311
|
initial: initial,
|
|
288
312
|
})
|
|
289
313
|
|