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.
Files changed (247) hide show
  1. package/dist-cjs/index.d.ts +161 -95
  2. package/dist-cjs/index.js +42 -31
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawImage.js +5 -2
  5. package/dist-cjs/lib/TldrawImage.js.map +3 -3
  6. package/dist-cjs/lib/canvas/TldrawCropHandles.js +1 -1
  7. package/dist-cjs/lib/canvas/TldrawCropHandles.js.map +2 -2
  8. package/dist-cjs/lib/canvas/TldrawHandles.js +1 -1
  9. package/dist-cjs/lib/canvas/TldrawHandles.js.map +2 -2
  10. package/dist-cjs/lib/canvas/TldrawOverlays.js +1 -1
  11. package/dist-cjs/lib/canvas/TldrawOverlays.js.map +2 -2
  12. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js +279 -271
  13. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js.map +2 -2
  14. package/dist-cjs/lib/defaultExternalContentHandlers.js +1 -0
  15. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  16. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +22 -36
  17. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  18. package/dist-cjs/lib/shapes/arrow/arrowLabel.js +16 -4
  19. package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +2 -2
  20. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +3 -0
  21. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
  22. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +5 -5
  23. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  24. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +15 -1
  25. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  26. package/dist-cjs/lib/shapes/shared/PathBuilder.js +21 -3
  27. package/dist-cjs/lib/shapes/shared/PathBuilder.js.map +2 -2
  28. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -0
  29. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
  30. package/dist-cjs/lib/shapes/shared/RichTextLabel.js +1 -0
  31. package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
  32. package/dist-cjs/lib/shapes/text/TextShapeUtil.js +5 -11
  33. package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
  34. package/dist-cjs/lib/styles.js.map +2 -2
  35. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +43 -22
  36. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
  37. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +2 -15
  38. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
  39. package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +5 -0
  40. package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
  41. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +8 -0
  42. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
  43. package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js +8 -0
  44. package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js.map +2 -2
  45. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +8 -0
  46. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  47. package/dist-cjs/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.js.map +2 -2
  48. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +51 -1
  49. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +2 -2
  50. package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js +1 -0
  51. package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js.map +2 -2
  52. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js +3 -4
  53. package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js.map +2 -2
  54. package/dist-cjs/lib/ui/components/Spinner.js +2 -25
  55. package/dist-cjs/lib/ui/components/Spinner.js.map +2 -2
  56. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +2 -1
  57. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  58. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
  59. package/dist-cjs/lib/ui/components/menu-items.js +16 -0
  60. package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
  61. package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButtonIcon.js.map +2 -2
  62. package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js +1 -1
  63. package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js.map +2 -2
  64. package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js +35 -1
  65. package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js.map +2 -2
  66. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +6 -2
  67. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  68. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +1 -0
  69. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  70. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js.map +2 -2
  71. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +0 -2
  72. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
  73. package/dist-cjs/lib/ui/context/actions.js +42 -8
  74. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  75. package/dist-cjs/lib/ui/context/events.js.map +2 -2
  76. package/dist-cjs/lib/ui/hooks/menu-hooks.js.map +2 -2
  77. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +24 -7
  78. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +2 -2
  79. package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js +2 -2
  80. package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js.map +2 -2
  81. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  82. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  83. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +8 -0
  84. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  85. package/dist-cjs/lib/ui/kbd-utils.js +2 -1
  86. package/dist-cjs/lib/ui/kbd-utils.js.map +2 -2
  87. package/dist-cjs/lib/ui/version.js +3 -3
  88. package/dist-cjs/lib/ui/version.js.map +1 -1
  89. package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js +1 -1
  90. package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js.map +2 -2
  91. package/dist-cjs/lib/utils/tldr/buildFromV1Document.js +3 -2
  92. package/dist-cjs/lib/utils/tldr/buildFromV1Document.js.map +2 -2
  93. package/dist-esm/index.d.mts +161 -95
  94. package/dist-esm/index.mjs +154 -135
  95. package/dist-esm/index.mjs.map +2 -2
  96. package/dist-esm/lib/TldrawImage.mjs +5 -2
  97. package/dist-esm/lib/TldrawImage.mjs.map +2 -2
  98. package/dist-esm/lib/canvas/TldrawCropHandles.mjs +1 -1
  99. package/dist-esm/lib/canvas/TldrawCropHandles.mjs.map +2 -2
  100. package/dist-esm/lib/canvas/TldrawHandles.mjs +1 -1
  101. package/dist-esm/lib/canvas/TldrawHandles.mjs.map +2 -2
  102. package/dist-esm/lib/canvas/TldrawOverlays.mjs +1 -1
  103. package/dist-esm/lib/canvas/TldrawOverlays.mjs.map +2 -2
  104. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs +279 -271
  105. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs.map +2 -2
  106. package/dist-esm/lib/defaultExternalContentHandlers.mjs +1 -0
  107. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  108. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +24 -36
  109. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  110. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +19 -5
  111. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +2 -2
  112. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +3 -0
  113. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
  114. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +5 -5
  115. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  116. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +15 -1
  117. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  118. package/dist-esm/lib/shapes/shared/PathBuilder.mjs +22 -3
  119. package/dist-esm/lib/shapes/shared/PathBuilder.mjs.map +2 -2
  120. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +1 -0
  121. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
  122. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +1 -0
  123. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
  124. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +5 -11
  125. package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
  126. package/dist-esm/lib/styles.mjs.map +2 -2
  127. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +43 -22
  128. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
  129. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +2 -15
  130. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
  131. package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +5 -0
  132. package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
  133. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +8 -0
  134. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
  135. package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs +8 -0
  136. package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs.map +2 -2
  137. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +8 -0
  138. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  139. package/dist-esm/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.mjs.map +2 -2
  140. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +51 -1
  141. package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +2 -2
  142. package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs +2 -0
  143. package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs.map +2 -2
  144. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs +3 -4
  145. package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs.map +2 -2
  146. package/dist-esm/lib/ui/components/Spinner.mjs +3 -26
  147. package/dist-esm/lib/ui/components/Spinner.mjs.map +2 -2
  148. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +2 -1
  149. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  150. package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
  151. package/dist-esm/lib/ui/components/menu-items.mjs +16 -0
  152. package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
  153. package/dist-esm/lib/ui/components/primitives/Button/TldrawUiButtonIcon.mjs.map +2 -2
  154. package/dist-esm/lib/ui/components/primitives/TldrawUiDialog.mjs +1 -1
  155. package/dist-esm/lib/ui/components/primitives/TldrawUiDialog.mjs.map +2 -2
  156. package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs +36 -2
  157. package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs.map +2 -2
  158. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +6 -2
  159. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  160. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +1 -0
  161. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  162. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs.map +2 -2
  163. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +0 -2
  164. package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
  165. package/dist-esm/lib/ui/context/actions.mjs +42 -8
  166. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  167. package/dist-esm/lib/ui/context/events.mjs.map +2 -2
  168. package/dist-esm/lib/ui/hooks/menu-hooks.mjs.map +2 -2
  169. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +24 -7
  170. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +2 -2
  171. package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs +2 -2
  172. package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs.map +2 -2
  173. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  174. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +8 -0
  175. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  176. package/dist-esm/lib/ui/kbd-utils.mjs +2 -1
  177. package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
  178. package/dist-esm/lib/ui/version.mjs +3 -3
  179. package/dist-esm/lib/ui/version.mjs.map +1 -1
  180. package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs +1 -1
  181. package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs.map +2 -2
  182. package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs +3 -2
  183. package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs.map +2 -2
  184. package/package.json +4 -3
  185. package/src/index.ts +174 -160
  186. package/src/lib/TldrawImage.tsx +6 -2
  187. package/src/lib/canvas/TldrawCropHandles.tsx +3 -1
  188. package/src/lib/canvas/TldrawHandles.tsx +5 -1
  189. package/src/lib/canvas/TldrawOverlays.tsx +1 -1
  190. package/src/lib/canvas/TldrawSelectionForeground.tsx +5 -1
  191. package/src/lib/defaultExternalContentHandlers.ts +2 -1
  192. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +5 -5
  193. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +25 -39
  194. package/src/lib/shapes/arrow/arrowLabel.ts +23 -3
  195. package/src/lib/shapes/arrow/toolStates/Pointing.tsx +3 -0
  196. package/src/lib/shapes/frame/FrameShapeUtil.tsx +5 -7
  197. package/src/lib/shapes/line/LineShapeUtil.tsx +19 -2
  198. package/src/lib/shapes/shared/PathBuilder.test.tsx +1 -1
  199. package/src/lib/shapes/shared/PathBuilder.tsx +35 -1
  200. package/src/lib/shapes/shared/PlainTextLabel.tsx +1 -0
  201. package/src/lib/shapes/shared/RichTextLabel.tsx +1 -0
  202. package/src/lib/shapes/text/TextShapeUtil.tsx +5 -12
  203. package/src/lib/styles.tsx +3 -1
  204. package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +54 -30
  205. package/src/lib/tools/SelectTool/childStates/Idle.ts +2 -24
  206. package/src/lib/tools/SelectTool/childStates/PointingShape.ts +7 -0
  207. package/src/lib/tools/SelectTool/childStates/Resizing.ts +12 -1
  208. package/src/lib/tools/SelectTool/childStates/Rotating.ts +11 -0
  209. package/src/lib/tools/SelectTool/childStates/Translating.ts +11 -0
  210. package/src/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.ts +1 -0
  211. package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +40 -0
  212. package/src/lib/ui/components/MainMenu/DefaultMainMenuContent.tsx +2 -0
  213. package/src/lib/ui/components/NavigationPanel/DefaultNavigationPanel.tsx +3 -4
  214. package/src/lib/ui/components/Spinner.tsx +2 -24
  215. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +1 -0
  216. package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +3 -1
  217. package/src/lib/ui/components/menu-items.tsx +17 -0
  218. package/src/lib/ui/components/primitives/Button/TldrawUiButtonIcon.tsx +2 -2
  219. package/src/lib/ui/components/primitives/TldrawUiDialog.tsx +1 -1
  220. package/src/lib/ui/components/primitives/TldrawUiIcon.tsx +41 -3
  221. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +6 -1
  222. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +4 -0
  223. package/src/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.tsx +2 -2
  224. package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +3 -4
  225. package/src/lib/ui/context/actions.tsx +44 -9
  226. package/src/lib/ui/context/events.tsx +4 -2
  227. package/src/lib/ui/hooks/menu-hooks.ts +1 -0
  228. package/src/lib/ui/hooks/useClipboardEvents.ts +31 -10
  229. package/src/lib/ui/hooks/useKeyboardShortcuts.ts +3 -2
  230. package/src/lib/ui/hooks/useTools.tsx +2 -1
  231. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +8 -0
  232. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +8 -0
  233. package/src/lib/ui/kbd-utils.ts +2 -1
  234. package/src/lib/ui/version.ts +3 -3
  235. package/src/lib/ui.css +8 -22
  236. package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +16 -2
  237. package/src/lib/utils/excalidraw/putExcalidrawContent.ts +1 -1
  238. package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +24 -3
  239. package/src/lib/utils/tldr/buildFromV1Document.ts +2 -1
  240. package/src/test/Editor.test.tsx +68 -1
  241. package/src/test/SelectTool.test.ts +37 -11
  242. package/src/test/commands/clipboard.test.ts +1 -1
  243. package/src/test/commands/deletePage.test.ts +84 -1
  244. package/src/test/navigation.test.ts +254 -0
  245. package/src/test/shapeutils.test.ts +394 -45
  246. package/tldraw.css +29 -49
  247. 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 { PlainTextLabel } from '../shared/PlainTextLabel'
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 (!shape.props.text) return EMPTY_ARRAY
160
- return [DefaultFontFaces[`tldraw_${shape.props.font}`].normal.normal]
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
- text: '',
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.text.trim()) {
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.text
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.text
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
- <PlainTextLabel
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
- text={shape.props.text}
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={shape.props.text.trim().length > 0}
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.text.trim() === '') {
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
- <SvgTextLabel
932
+ <RichTextSVG
948
933
  fontSize={getArrowLabelFontSize(shape)}
949
934
  font={shape.props.font}
950
935
  align="middle"
951
936
  verticalAlign="middle"
952
- text={shape.props.text}
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 || shape.props.text.trim().length > 0}
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 text = shape.props.text || 'i'
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.measureText(text, {
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.measureText(text, {
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
- y={-0.5 / zoomLevel}
244
- x={-0.5 / zoomLevel}
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,0L91.23532468849007,-7.455843959357096L81.64709960511827,-13.25483368860933L71.44121219537817,-17.39696918901332L60.82354990476352,-19.882250461825734L50.000000178767834,-20.71067750830319L39.17645046288481,-19.882250329702327L28.558788202608024,-17.396968927279783L18.35290084343114,-13.254833302292194L8.764675830847777,-7.455843455996203L6.103515630684342e-7,6.103515559630068e-7L-7.4558434559962,8.764675830847771L-13.254833302292194,18.35290084343114L-17.396968927279772,28.55878820260801L-19.882250329702327,39.17645046288479L-20.710677508303192,50.00000017876782L-19.88225046182574,60.823549904763496L-17.39696918901333,71.44121219537817L-13.254833688609331,81.64709960511824L-7.455843959357106,91.23532468849007L-1.4210854715202004e-14,99.99999999999999L0,0Z"`
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.cubicBezierTo(end.x, end.y, cp1x, cp1y, cp2x, cp2y, bezierOpts)
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
@@ -81,6 +81,7 @@ export const PlainTextLabel = React.memo(function PlainTextLabel({
81
81
  return (
82
82
  <div
83
83
  className={`${cssPrefix}-label tl-text-wrapper tl-plain-text-wrapper`}
84
+ aria-hidden={!isEditing}
84
85
  data-font={font}
85
86
  data-align={align}
86
87
  data-hastext={!isEmpty}
@@ -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, autoSize, size, w } = props
306
+ const { font, richText, size, w } = props
307
307
 
308
- const minWidth = autoSize ? 16 : Math.max(16, w)
308
+ const minWidth = 16
309
309
  const fontSize = FONT_SIZES[size]
310
310
 
311
- const cw = autoSize
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: cw,
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
  }
@@ -1,7 +1,9 @@
1
+ import { TLUiIconJsx } from './ui/components/primitives/TldrawUiIcon'
2
+
1
3
  /** @public */
2
4
  export type StyleValuesForUi<T> = readonly {
3
5
  readonly value: T
4
- readonly icon: string
6
+ readonly icon: string | TLUiIconJsx
5
7
  }[]
6
8
 
7
9
  // todo: default styles prop?
@@ -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 = '' as TLShapeId
30
- initialHandle = {} as TLHandle
31
- initialAdjacentHandle = null as TLHandle | null
32
- initialPagePoint = {} as Vec
30
+ shapeId!: TLShapeId
31
+ initialHandle!: TLHandle
32
+ initialAdjacentHandle!: TLHandle | null
33
+ initialPagePoint!: Vec
33
34
 
34
- markId = ''
35
- initialPageTransform: any
36
- initialPageRotation: any
35
+ markId!: string
36
+ initialPageTransform!: Mat
37
+ initialPageRotation!: number
37
38
 
38
- info = {} as DraggingHandleInfo
39
+ info!: DraggingHandleInfo
39
40
 
40
41
  isPrecise = false
41
- isPreciseId = null as TLShapeId | null
42
- pointingId = null as TLShapeId | null
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