tldraw 5.4.0-next.ebc95cf01337 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/DOCS.md +2826 -3226
  2. package/RELEASE_NOTES.md +190 -2
  3. package/dist-cjs/index.js +1 -1
  4. package/dist-cjs/lib/defaultExternalContentHandlers.js +30 -14
  5. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  6. package/dist-cjs/lib/shapes/arrow/curved-arrow.js +2 -2
  7. package/dist-cjs/lib/shapes/arrow/curved-arrow.js.map +2 -2
  8. package/dist-cjs/lib/shapes/arrow/elbow/getElbowArrowInfo.js +2 -2
  9. package/dist-cjs/lib/shapes/arrow/elbow/getElbowArrowInfo.js.map +2 -2
  10. package/dist-cjs/lib/shapes/arrow/getArrowInfo.js +1 -1
  11. package/dist-cjs/lib/shapes/arrow/getArrowInfo.js.map +2 -2
  12. package/dist-cjs/lib/shapes/arrow/straight-arrow.js +2 -2
  13. package/dist-cjs/lib/shapes/arrow/straight-arrow.js.map +2 -2
  14. package/dist-cjs/lib/shapes/arrow/toolStates/Idle.js +2 -3
  15. package/dist-cjs/lib/shapes/arrow/toolStates/Idle.js.map +2 -2
  16. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +7 -5
  17. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
  18. package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js +8 -6
  19. package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js.map +2 -2
  20. package/dist-cjs/lib/shapes/geo/getGeoShapePath.js +3 -1
  21. package/dist-cjs/lib/shapes/geo/getGeoShapePath.js.map +2 -2
  22. package/dist-cjs/lib/shapes/geo/toolStates/Idle.js +2 -3
  23. package/dist-cjs/lib/shapes/geo/toolStates/Idle.js.map +2 -2
  24. package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js +1 -1
  25. package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js.map +2 -2
  26. package/dist-cjs/lib/shapes/line/toolStates/Pointing.js +2 -6
  27. package/dist-cjs/lib/shapes/line/toolStates/Pointing.js.map +2 -2
  28. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
  29. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  30. package/dist-cjs/lib/shapes/note/noteHelpers.js +6 -5
  31. package/dist-cjs/lib/shapes/note/noteHelpers.js.map +2 -2
  32. package/dist-cjs/lib/shapes/note/toolStates/Pointing.js +1 -1
  33. package/dist-cjs/lib/shapes/note/toolStates/Pointing.js.map +2 -2
  34. package/dist-cjs/lib/shapes/shared/crop.js +1 -1
  35. package/dist-cjs/lib/shapes/shared/crop.js.map +2 -2
  36. package/dist-cjs/lib/shapes/text/toolStates/Idle.js +1 -1
  37. package/dist-cjs/lib/shapes/text/toolStates/Idle.js.map +2 -2
  38. package/dist-cjs/lib/shapes/text/toolStates/Pointing.js +1 -0
  39. package/dist-cjs/lib/shapes/text/toolStates/Pointing.js.map +2 -2
  40. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +3 -2
  41. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +2 -2
  42. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js +2 -0
  43. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  44. package/dist-cjs/lib/tools/HandTool/childStates/OneFingerZooming.js +6 -0
  45. package/dist-cjs/lib/tools/HandTool/childStates/OneFingerZooming.js.map +2 -2
  46. package/dist-cjs/lib/tools/SelectTool/SelectTool.js +3 -0
  47. package/dist-cjs/lib/tools/SelectTool/SelectTool.js.map +2 -2
  48. package/dist-cjs/lib/tools/SelectTool/childStates/Brushing.js +1 -0
  49. package/dist-cjs/lib/tools/SelectTool/childStates/Brushing.js.map +2 -2
  50. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/Crop.js +1 -0
  51. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/Crop.js.map +2 -2
  52. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +1 -3
  53. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
  54. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +6 -3
  55. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
  56. package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js +1 -1
  57. package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js.map +2 -2
  58. package/dist-cjs/lib/tools/SelectTool/childStates/PointingCanvas.js +3 -0
  59. package/dist-cjs/lib/tools/SelectTool/childStates/PointingCanvas.js.map +2 -2
  60. package/dist-cjs/lib/tools/SelectTool/childStates/PointingHandle.js +1 -0
  61. package/dist-cjs/lib/tools/SelectTool/childStates/PointingHandle.js.map +2 -2
  62. package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +1 -1
  63. package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
  64. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +22 -30
  65. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
  66. package/dist-cjs/lib/tools/SelectTool/childStates/ScribbleBrushing.js +1 -3
  67. package/dist-cjs/lib/tools/SelectTool/childStates/ScribbleBrushing.js.map +2 -2
  68. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +4 -1
  69. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  70. package/dist-cjs/lib/tools/SelectTool/selectHelpers.js +10 -0
  71. package/dist-cjs/lib/tools/SelectTool/selectHelpers.js.map +2 -2
  72. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +1 -8
  73. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
  74. package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenu.js +6 -1
  75. package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenu.js.map +2 -2
  76. package/dist-cjs/lib/ui/components/Dialogs.js +8 -0
  77. package/dist-cjs/lib/ui/components/Dialogs.js.map +2 -2
  78. package/dist-cjs/lib/ui/components/EditLinkDialog.js +5 -5
  79. package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
  80. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +4 -20
  81. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js.map +2 -2
  82. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js +2 -0
  83. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +2 -2
  84. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +1 -0
  85. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  86. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +10 -8
  87. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  88. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +20 -1
  89. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  90. package/dist-cjs/lib/ui/context/actions.js +8 -7
  91. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  92. package/dist-cjs/lib/ui/hooks/useCommentingEnabled.js +1 -1
  93. package/dist-cjs/lib/ui/hooks/useCommentingEnabled.js.map +2 -2
  94. package/dist-cjs/lib/ui/version.js +3 -3
  95. package/dist-cjs/lib/ui/version.js.map +1 -1
  96. package/dist-esm/index.mjs +1 -1
  97. package/dist-esm/lib/defaultExternalContentHandlers.mjs +30 -14
  98. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  99. package/dist-esm/lib/shapes/arrow/curved-arrow.mjs +2 -2
  100. package/dist-esm/lib/shapes/arrow/curved-arrow.mjs.map +2 -2
  101. package/dist-esm/lib/shapes/arrow/elbow/getElbowArrowInfo.mjs +2 -2
  102. package/dist-esm/lib/shapes/arrow/elbow/getElbowArrowInfo.mjs.map +2 -2
  103. package/dist-esm/lib/shapes/arrow/getArrowInfo.mjs +1 -1
  104. package/dist-esm/lib/shapes/arrow/getArrowInfo.mjs.map +2 -2
  105. package/dist-esm/lib/shapes/arrow/straight-arrow.mjs +2 -2
  106. package/dist-esm/lib/shapes/arrow/straight-arrow.mjs.map +2 -2
  107. package/dist-esm/lib/shapes/arrow/toolStates/Idle.mjs +3 -4
  108. package/dist-esm/lib/shapes/arrow/toolStates/Idle.mjs.map +2 -2
  109. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +7 -5
  110. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
  111. package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs +8 -6
  112. package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs.map +2 -2
  113. package/dist-esm/lib/shapes/geo/getGeoShapePath.mjs +3 -1
  114. package/dist-esm/lib/shapes/geo/getGeoShapePath.mjs.map +2 -2
  115. package/dist-esm/lib/shapes/geo/toolStates/Idle.mjs +3 -4
  116. package/dist-esm/lib/shapes/geo/toolStates/Idle.mjs.map +2 -2
  117. package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs +1 -1
  118. package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs.map +2 -2
  119. package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs +2 -7
  120. package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs.map +2 -2
  121. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +4 -4
  122. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  123. package/dist-esm/lib/shapes/note/noteHelpers.mjs +6 -5
  124. package/dist-esm/lib/shapes/note/noteHelpers.mjs.map +2 -2
  125. package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs +1 -1
  126. package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs.map +2 -2
  127. package/dist-esm/lib/shapes/shared/crop.mjs +1 -1
  128. package/dist-esm/lib/shapes/shared/crop.mjs.map +2 -2
  129. package/dist-esm/lib/shapes/text/toolStates/Idle.mjs +2 -2
  130. package/dist-esm/lib/shapes/text/toolStates/Idle.mjs.map +2 -2
  131. package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs +1 -0
  132. package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs.map +2 -2
  133. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +3 -2
  134. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +2 -2
  135. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs +2 -0
  136. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  137. package/dist-esm/lib/tools/HandTool/childStates/OneFingerZooming.mjs +6 -0
  138. package/dist-esm/lib/tools/HandTool/childStates/OneFingerZooming.mjs.map +2 -2
  139. package/dist-esm/lib/tools/SelectTool/SelectTool.mjs +3 -0
  140. package/dist-esm/lib/tools/SelectTool/SelectTool.mjs.map +2 -2
  141. package/dist-esm/lib/tools/SelectTool/childStates/Brushing.mjs +1 -0
  142. package/dist-esm/lib/tools/SelectTool/childStates/Brushing.mjs.map +2 -2
  143. package/dist-esm/lib/tools/SelectTool/childStates/Crop/Crop.mjs +1 -0
  144. package/dist-esm/lib/tools/SelectTool/childStates/Crop/Crop.mjs.map +2 -2
  145. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +1 -3
  146. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
  147. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +6 -3
  148. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
  149. package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs +1 -1
  150. package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs.map +2 -2
  151. package/dist-esm/lib/tools/SelectTool/childStates/PointingCanvas.mjs +3 -0
  152. package/dist-esm/lib/tools/SelectTool/childStates/PointingCanvas.mjs.map +2 -2
  153. package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs +5 -1
  154. package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs.map +2 -2
  155. package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +1 -1
  156. package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
  157. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +22 -31
  158. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
  159. package/dist-esm/lib/tools/SelectTool/childStates/ScribbleBrushing.mjs +1 -3
  160. package/dist-esm/lib/tools/SelectTool/childStates/ScribbleBrushing.mjs.map +2 -2
  161. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +4 -1
  162. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  163. package/dist-esm/lib/tools/SelectTool/selectHelpers.mjs +10 -0
  164. package/dist-esm/lib/tools/SelectTool/selectHelpers.mjs.map +2 -2
  165. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +1 -8
  166. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
  167. package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenu.mjs +7 -2
  168. package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenu.mjs.map +2 -2
  169. package/dist-esm/lib/ui/components/Dialogs.mjs +9 -1
  170. package/dist-esm/lib/ui/components/Dialogs.mjs.map +2 -2
  171. package/dist-esm/lib/ui/components/EditLinkDialog.mjs +5 -5
  172. package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
  173. package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs +5 -22
  174. package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs.map +2 -2
  175. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs +2 -0
  176. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +2 -2
  177. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +1 -0
  178. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  179. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +10 -8
  180. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  181. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +20 -1
  182. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  183. package/dist-esm/lib/ui/context/actions.mjs +8 -7
  184. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  185. package/dist-esm/lib/ui/hooks/useCommentingEnabled.mjs +2 -2
  186. package/dist-esm/lib/ui/hooks/useCommentingEnabled.mjs.map +2 -2
  187. package/dist-esm/lib/ui/version.mjs +3 -3
  188. package/dist-esm/lib/ui/version.mjs.map +1 -1
  189. package/package.json +12 -6
  190. package/src/lib/defaultExternalContentHandlers.test.ts +43 -0
  191. package/src/lib/defaultExternalContentHandlers.ts +38 -16
  192. package/src/lib/shapes/arrow/ArrowShapeTool.test.ts +17 -0
  193. package/src/lib/shapes/arrow/curved-arrow.ts +2 -2
  194. package/src/lib/shapes/arrow/elbow/getElbowArrowInfo.tsx +5 -3
  195. package/src/lib/shapes/arrow/getArrowInfo.ts +2 -1
  196. package/src/lib/shapes/arrow/straight-arrow.ts +2 -2
  197. package/src/lib/shapes/arrow/toolStates/Idle.tsx +3 -4
  198. package/src/lib/shapes/arrow/toolStates/Pointing.tsx +10 -6
  199. package/src/lib/shapes/draw/DrawShapeTool.test.ts +19 -0
  200. package/src/lib/shapes/draw/toolStates/Drawing.ts +12 -6
  201. package/src/lib/shapes/frame/FrameShapeTool.test.ts +17 -0
  202. package/src/lib/shapes/geo/GeoShapeTool.test.ts +28 -0
  203. package/src/lib/shapes/geo/getGeoShapePath.ts +3 -1
  204. package/src/lib/shapes/geo/toolStates/Idle.ts +3 -4
  205. package/src/lib/shapes/geo/toolStates/Pointing.ts +2 -1
  206. package/src/lib/shapes/line/LineShapeTool.test.ts +30 -1
  207. package/src/lib/shapes/line/toolStates/Pointing.ts +6 -7
  208. package/src/lib/shapes/note/NoteShapeTool.test.ts +45 -0
  209. package/src/lib/shapes/note/NoteShapeUtil.tsx +7 -4
  210. package/src/lib/shapes/note/noteHelpers.ts +18 -8
  211. package/src/lib/shapes/note/toolStates/Pointing.ts +2 -1
  212. package/src/lib/shapes/shared/crop.ts +7 -1
  213. package/src/lib/shapes/text/TextShapeTool.test.ts +33 -0
  214. package/src/lib/shapes/text/toolStates/Idle.ts +2 -2
  215. package/src/lib/shapes/text/toolStates/Pointing.ts +3 -0
  216. package/src/lib/shapes/video/VideoShapeUtil.tsx +4 -2
  217. package/src/lib/tools/EraserTool/childStates/Erasing.ts +5 -0
  218. package/src/lib/tools/HandTool/childStates/OneFingerZooming.ts +10 -0
  219. package/src/lib/tools/SelectTool/SelectTool.ts +4 -0
  220. package/src/lib/tools/SelectTool/childStates/Brushing.ts +4 -0
  221. package/src/lib/tools/SelectTool/childStates/Crop/Crop.ts +4 -0
  222. package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +3 -4
  223. package/src/lib/tools/SelectTool/childStates/Idle.ts +10 -3
  224. package/src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts +1 -1
  225. package/src/lib/tools/SelectTool/childStates/PointingCanvas.ts +4 -0
  226. package/src/lib/tools/SelectTool/childStates/PointingHandle.ts +6 -1
  227. package/src/lib/tools/SelectTool/childStates/PointingShape.ts +4 -1
  228. package/src/lib/tools/SelectTool/childStates/Resizing.ts +30 -33
  229. package/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts +3 -3
  230. package/src/lib/tools/SelectTool/childStates/Translating.ts +6 -0
  231. package/src/lib/tools/SelectTool/selectHelpers.ts +21 -0
  232. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +3 -9
  233. package/src/lib/ui/components/ContextMenu/DefaultContextMenu.tsx +8 -2
  234. package/src/lib/ui/components/Dialogs.tsx +17 -1
  235. package/src/lib/ui/components/EditLinkDialog.tsx +8 -7
  236. package/src/lib/ui/components/Minimap/DefaultMinimap.tsx +5 -23
  237. package/src/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.tsx +2 -0
  238. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +1 -0
  239. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +13 -8
  240. package/src/lib/ui/components/primitives/TldrawUiSlider.test.tsx +92 -0
  241. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +25 -1
  242. package/src/lib/ui/context/actions.tsx +25 -7
  243. package/src/lib/ui/hooks/useCommentingEnabled.ts +5 -3
  244. package/src/lib/ui/version.ts +3 -3
  245. package/src/test/ClickManager.test.ts +18 -0
  246. package/src/test/Editor.test.tsx +3 -0
  247. package/src/test/EraserTool.test.ts +18 -2
  248. package/src/test/HandTool.test.ts +21 -0
  249. package/src/test/LaserTool.test.ts +46 -0
  250. package/src/test/ScribbleManager.test.ts +19 -0
  251. package/src/test/SelectTool.test.ts +110 -0
  252. package/src/test/TldrawEditor.test.tsx +18 -0
  253. package/src/test/VideoShapeUtil.test.tsx +126 -0
  254. package/src/test/actions-menu-readonly.test.tsx +37 -0
  255. package/src/test/commands/__snapshots__/packShapes.test.ts.snap +6 -6
  256. package/src/test/commands/lockShapes.test.ts +11 -0
  257. package/src/test/commands/packShapes.test.ts +20 -0
  258. package/src/test/commands/putContent.test.ts +35 -1
  259. package/src/test/commands/setCamera.test.ts +69 -0
  260. package/src/test/commands/stackShapes.test.ts +12 -0
  261. package/src/test/commands/updateViewportPageBounds.test.ts +8 -0
  262. package/src/test/cropping.test.ts +162 -0
  263. package/src/test/customSnapping.test.tsx +32 -0
  264. package/src/test/defaultHandleExternalFileContent.test.ts +86 -0
  265. package/src/test/drawing.test.ts +60 -1
  266. package/src/test/duplicate.test.ts +22 -0
  267. package/src/test/frames.test.ts +51 -0
  268. package/src/test/getShapeAtPoint.test.ts +44 -1
  269. package/src/test/handleDeepLink.test.tsx +15 -0
  270. package/src/test/minimap-wheel.test.tsx +48 -0
  271. package/src/test/resizing.test.ts +46 -0
  272. package/src/test/selection-omnibus.test.ts +50 -0
  273. package/src/test/spacebarPanning.test.ts +58 -0
  274. package/src/test/translating.test.ts +42 -0
  275. package/src/test/ui/AltTextEditor.test.tsx +51 -0
  276. package/src/test/ui/ContextMenu.test.tsx +61 -2
  277. package/src/test/ui/EditLinkDialog.test.tsx +77 -0
  278. package/src/test/ui/ImageToolbar.test.tsx +58 -0
  279. package/src/test/ui/StylePanel.test.tsx +33 -2
  280. package/src/test/ui/keyboardShortcuts.test.tsx +27 -0
  281. package/src/test/ui/presenceActivity.test.tsx +44 -0
  282. package/src/test/ui/unlockAll.test.tsx +55 -0
  283. package/src/test/ui-outside-editor.test.tsx +74 -0
  284. package/src/test/viewport-following.test.ts +29 -1
@@ -1,3 +1,4 @@
1
+ import { PageRecordType } from '@tldraw/editor'
1
2
  import { vi } from 'vitest'
2
3
  import { TestEditor } from './TestEditor'
3
4
 
@@ -385,6 +386,51 @@ describe('LaserTool', () => {
385
386
  })
386
387
  })
387
388
 
389
+ describe('Page changes', () => {
390
+ it('clears the trail when the current page changes', () => {
391
+ editor.setCurrentTool('laser')
392
+
393
+ editor.pointerDown(0, 0)
394
+ for (let i = 1; i <= 10; i++) {
395
+ editor.pointerMove(i * 5, i * 5)
396
+ vi.advanceTimersByTime(16)
397
+ }
398
+ editor.pointerUp()
399
+ expect(editor.getInstanceState().scribbles.length).toBeGreaterThan(0)
400
+
401
+ const page2Id = PageRecordType.createId('page2')
402
+ editor.createPage({ id: page2Id, name: 'Page 2' })
403
+ editor.setCurrentPage(page2Id)
404
+ vi.advanceTimersByTime(16)
405
+
406
+ expect(editor.getInstanceState().scribbles).toEqual([])
407
+ })
408
+
409
+ it('starts a fresh session on the new page after a page change', () => {
410
+ editor.setCurrentTool('laser')
411
+
412
+ editor.pointerDown(0, 0)
413
+ editor.pointerMove(10, 10)
414
+ vi.advanceTimersByTime(16)
415
+ editor.pointerUp()
416
+
417
+ const page2Id = PageRecordType.createId('page2')
418
+ editor.createPage({ id: page2Id, name: 'Page 2' })
419
+ editor.setCurrentPage(page2Id)
420
+ vi.advanceTimersByTime(16)
421
+
422
+ editor.pointerDown(0, 50)
423
+ for (let i = 1; i <= 10; i++) {
424
+ editor.pointerMove(i * 5, 50 + i * 5)
425
+ vi.advanceTimersByTime(16)
426
+ }
427
+ editor.pointerUp()
428
+
429
+ // Only the stroke drawn on the new page is visible
430
+ expect(editor.getInstanceState().scribbles.length).toBe(1)
431
+ })
432
+ })
433
+
388
434
  describe('Edge cases', () => {
389
435
  it('handles rapid pointer up/down', () => {
390
436
  editor.setCurrentTool('laser')
@@ -1,3 +1,4 @@
1
+ import { PageRecordType } from '@tldraw/editor'
1
2
  import { vi } from 'vitest'
2
3
  import { TestEditor } from './TestEditor'
3
4
 
@@ -341,6 +342,24 @@ describe('ScribbleManager', () => {
341
342
 
342
343
  expect(editor.scribbles.isSessionActive(sessionId)).toBe(false)
343
344
  })
345
+
346
+ it('clears sessions started on another page when the current page changes', () => {
347
+ const sessionId = editor.scribbles.startSession({ selfConsume: false })
348
+ const item = editor.scribbles.addScribbleToSession(sessionId, {})
349
+ for (let i = 0; i < 10; i++) {
350
+ editor.scribbles.addPointToSession(sessionId, item.id, i * 5, i * 5)
351
+ editor.scribbles.tick(16)
352
+ }
353
+ expect(editor.getInstanceState().scribbles.length).toBe(1)
354
+
355
+ const page2Id = PageRecordType.createId('page2')
356
+ editor.createPage({ id: page2Id, name: 'Page 2' })
357
+ editor.setCurrentPage(page2Id)
358
+ editor.scribbles.tick(16)
359
+
360
+ expect(editor.getInstanceState().scribbles).toEqual([])
361
+ expect(editor.scribbles.isSessionActive(sessionId)).toBe(false)
362
+ })
344
363
  })
345
364
  })
346
365
 
@@ -3,6 +3,7 @@ import {
3
3
  ShapeUtil,
4
4
  TLArrowShape,
5
5
  TLFrameShape,
6
+ TLGeoShape,
6
7
  createShapeId,
7
8
  toRichText,
8
9
  } from '@tldraw/editor'
@@ -47,6 +48,13 @@ describe('TLSelectTool.Idle', () => {
47
48
  editor.expectToBeIn('select.pointing_canvas')
48
49
  })
49
50
 
51
+ it('Returns to idle when a canvas press is cancelled', () => {
52
+ editor.pointerDown(10, 10, { target: 'canvas' })
53
+ editor.expectToBeIn('select.pointing_canvas')
54
+ editor.cancel()
55
+ editor.expectToBeIn('select.idle')
56
+ })
57
+
50
58
  it('Nudges selected shapes on arrow key down', () => {
51
59
  const shape = editor.getShape(ids.box1)!
52
60
  editor.select(shape.id)
@@ -56,6 +64,47 @@ describe('TLSelectTool.Idle', () => {
56
64
  expect(nudgedShape).toBeDefined()
57
65
  expect(nudgedShape?.x).toBe(101)
58
66
  })
67
+
68
+ it('Does not nudge selected shapes on arrow key down while spacebar panning', () => {
69
+ const shape = editor.getShape(ids.box1)!
70
+ editor.select(shape.id)
71
+ editor.keyDown(' ')
72
+ expect(editor.inputs.getIsSpacebarPanning()).toBe(true)
73
+ editor.keyDown('ArrowRight')
74
+ editor.keyRepeat('ArrowRight')
75
+ editor.keyUp('ArrowRight')
76
+ editor.keyUp(' ')
77
+ expect(editor.getShape(shape.id)).toMatchObject({ x: 100, y: 100 })
78
+ })
79
+
80
+ it('Does not nudge selected shapes on arrow key down while alt is held', () => {
81
+ const shape = editor.getShape(ids.box1)!
82
+ editor.select(shape.id)
83
+ editor.keyDown('Alt')
84
+ editor.keyDown('ArrowRight')
85
+ editor.keyRepeat('ArrowRight')
86
+ editor.keyUp('ArrowRight')
87
+ editor.keyUp('Alt')
88
+ expect(editor.getShape(shape.id)).toMatchObject({ x: 100, y: 100 })
89
+ })
90
+
91
+ it('Makes a shape double click change its own undo step', () => {
92
+ const shape = editor.getShape<TLGeoShape>(ids.box1)!
93
+ expect(shape.props.geo).toBe('rectangle')
94
+
95
+ // Alt+double-click swaps a rectangle to a check-box via GeoShapeUtil.onDoubleClick
96
+ editor.keyDown('Alt')
97
+ editor.doubleClick(150, 150, { target: 'shape', shape }, { altKey: true })
98
+ editor.keyUp('Alt')
99
+
100
+ expect(editor.getShape<TLGeoShape>(ids.box1)!.props.geo).toBe('check-box')
101
+ expect(editor.getOnlySelectedShapeId()).toBe(ids.box1)
102
+
103
+ editor.undo()
104
+
105
+ expect(editor.getShape<TLGeoShape>(ids.box1)!.props.geo).toBe('rectangle')
106
+ expect(editor.getOnlySelectedShapeId()).toBe(ids.box1)
107
+ })
59
108
  })
60
109
 
61
110
  // todo: turn on feature flag for these tests or remove them
@@ -501,6 +550,42 @@ describe('PointingLabel', () => {
501
550
  editor.expectToBeIn('select.idle')
502
551
  })
503
552
 
553
+ it('Keeps the dragged label position on complete', () => {
554
+ editor.createShapes([
555
+ {
556
+ id: ids.arrow1,
557
+ type: 'arrow',
558
+ x: 100,
559
+ y: 100,
560
+ props: {
561
+ richText: toRichText('Test Label'),
562
+ start: { x: 0, y: 0 },
563
+ end: { x: 100, y: 0 },
564
+ },
565
+ },
566
+ ])
567
+ const shape = editor.getShape<TLArrowShape>(ids.arrow1)!
568
+ const initialLabelPosition = shape.props.labelPosition
569
+
570
+ editor.pointerDown(150, 100, {
571
+ target: 'shape',
572
+ shape,
573
+ })
574
+ editor.pointerMove(160, 100)
575
+ editor.expectToBeIn('select.pointing_arrow_label')
576
+ editor.pointerMove(190, 100)
577
+
578
+ const draggedLabelPosition = editor.getShape<TLArrowShape>(ids.arrow1)!.props.labelPosition
579
+ expect(draggedLabelPosition).not.toBe(initialLabelPosition)
580
+
581
+ // A menu opening or an undo keypress mid-drag completes the interaction
582
+ editor.complete()
583
+ editor.expectToBeIn('select.idle')
584
+ expect(editor.getShape<TLArrowShape>(ids.arrow1)!.props.labelPosition).toBe(
585
+ draggedLabelPosition
586
+ )
587
+ })
588
+
504
589
  it('Doesnt go into pointing_arrow_label mode if not selecting the arrow shape', () => {
505
590
  editor.createShapes([
506
591
  {
@@ -744,6 +829,31 @@ describe('When double clicking a selection handle that registers as a canvas eve
744
829
 
745
830
  expect(overlayEditor.getShape<TLArrowShape>(id)!.props.arrowheadEnd).toBe('arrow')
746
831
  })
832
+
833
+ it('Undoes an arrowhead toggled by handle double-click without undoing the selection', () => {
834
+ const id = createShapeId()
835
+ overlayEditor
836
+ .createShapes([
837
+ {
838
+ id,
839
+ type: 'arrow',
840
+ x: 100,
841
+ y: 100,
842
+ props: { start: { x: 0, y: 0 }, end: { x: 100, y: 100 } },
843
+ },
844
+ ])
845
+ .selectNone()
846
+ overlayEditor.markHistoryStoppingPoint('before selecting arrow')
847
+ overlayEditor.select(id)
848
+
849
+ overlayEditor.doubleClick(200, 200)
850
+ expect(overlayEditor.getShape<TLArrowShape>(id)!.props.arrowheadEnd).toBe('none')
851
+
852
+ overlayEditor.undo()
853
+
854
+ expect(overlayEditor.getShape<TLArrowShape>(id)!.props.arrowheadEnd).toBe('arrow')
855
+ expect(overlayEditor.getSelectedShapeIds()).toEqual([id])
856
+ })
747
857
  })
748
858
 
749
859
  describe('When editing shapes', () => {
@@ -13,6 +13,7 @@ import {
13
13
  createTLStore,
14
14
  noop,
15
15
  react,
16
+ tleditors,
16
17
  toRichText,
17
18
  } from '@tldraw/editor'
18
19
  import { StrictMode } from 'react'
@@ -95,6 +96,21 @@ describe('<TldrawEditor />', () => {
95
96
  )
96
97
  })
97
98
 
99
+ it('runs the teardown returned by the store onMount option when unmounted', async () => {
100
+ const teardown = vi.fn()
101
+ const storeOnMount = vi.fn(() => teardown)
102
+ const store = createTLStore({ shapeUtils: [], bindingUtils: [], onMount: storeOnMount })
103
+ const rendered = await renderTldrawComponent(
104
+ <TldrawEditor store={store} tools={defaultTools} initialState="select" />,
105
+ { waitForPatterns: false }
106
+ )
107
+ expect(storeOnMount).toHaveBeenCalledTimes(1)
108
+ expect(teardown).not.toHaveBeenCalled()
109
+
110
+ act(() => rendered.unmount())
111
+ expect(teardown).toHaveBeenCalledTimes(1)
112
+ })
113
+
98
114
  it('throws if the store has different shapes to the ones passed in', async () => {
99
115
  const spy = vi.spyOn(console, 'error').mockImplementation(noop)
100
116
  // expect(() =>
@@ -181,6 +197,7 @@ describe('<TldrawEditor />', () => {
181
197
 
182
198
  // mounted after render:
183
199
  expect(editor.getIsMounted()).toBe(true)
200
+ expect(tleditors.getMounted()).toEqual([editor])
184
201
 
185
202
  // getIsMounted is reactive:
186
203
  const mountedValues: boolean[] = []
@@ -191,6 +208,7 @@ describe('<TldrawEditor />', () => {
191
208
  // the unmount event fired and the mounted state flipped back to false:
192
209
  expect(onUnmount).toHaveBeenCalledTimes(1)
193
210
  expect(editor.getIsMounted()).toBe(false)
211
+ expect(tleditors.getMounted()).toEqual([])
194
212
  expect(mountedValues).toEqual([true, false])
195
213
 
196
214
  stop()
@@ -0,0 +1,126 @@
1
+ import { act, fireEvent } from '@testing-library/react'
2
+ import { AssetRecordType, Editor, TLAssetId, TLShapeId, createShapeId } from '@tldraw/editor'
3
+ import { Tldraw } from '../lib/Tldraw'
4
+ import { renderTldrawComponentWithEditor } from './testutils/renderTldrawComponent'
5
+
6
+ const LOADING_BACKGROUND = 'var(--tl-color-low)'
7
+ const LOADING_BORDER = '1px solid var(--tl-color-low-border)'
8
+
9
+ let editor: Editor
10
+ let videoShapeId: TLShapeId
11
+ let videoAssetId: TLAssetId
12
+
13
+ function getShapeContainer() {
14
+ const container = document.getElementById(videoShapeId)
15
+ expect(container).toBeTruthy()
16
+ return container!
17
+ }
18
+
19
+ beforeEach(async () => {
20
+ videoShapeId = createShapeId('video')
21
+ videoAssetId = AssetRecordType.createId('videoAsset')
22
+
23
+ const result = await renderTldrawComponentWithEditor((onMount) => <Tldraw onMount={onMount} />, {
24
+ waitForPatterns: false,
25
+ })
26
+ editor = result.editor
27
+ })
28
+
29
+ describe('VideoShapeUtil loading state', () => {
30
+ it('shows the loading plate when the asset record is missing', async () => {
31
+ await act(async () => {
32
+ editor.createShapes([
33
+ { id: videoShapeId, type: 'video', x: 0, y: 0, props: { w: 100, h: 100 } },
34
+ ])
35
+ })
36
+
37
+ const container = getShapeContainer()
38
+ expect(container.style.backgroundColor).toBe(LOADING_BACKGROUND)
39
+ expect(container.style.border).toBe(LOADING_BORDER)
40
+ })
41
+
42
+ it('shows the loading plate while the asset is uploading (no src)', async () => {
43
+ await act(async () => {
44
+ editor.createAssets([
45
+ {
46
+ id: videoAssetId,
47
+ type: 'video',
48
+ typeName: 'asset',
49
+ props: {
50
+ w: 100,
51
+ h: 100,
52
+ name: 'video.mp4',
53
+ isAnimated: true,
54
+ mimeType: 'video/mp4',
55
+ src: '',
56
+ },
57
+ meta: {},
58
+ },
59
+ ])
60
+ editor.createShapes([
61
+ {
62
+ id: videoShapeId,
63
+ type: 'video',
64
+ x: 0,
65
+ y: 0,
66
+ props: { w: 100, h: 100, assetId: videoAssetId },
67
+ },
68
+ ])
69
+ })
70
+
71
+ const container = getShapeContainer()
72
+ expect(container.style.backgroundColor).toBe(LOADING_BACKGROUND)
73
+ expect(container.style.border).toBe(LOADING_BORDER)
74
+ })
75
+
76
+ it('shows the loading plate until the video loads, then goes transparent', async () => {
77
+ await act(async () => {
78
+ editor.createAssets([
79
+ {
80
+ id: videoAssetId,
81
+ type: 'video',
82
+ typeName: 'asset',
83
+ props: {
84
+ w: 100,
85
+ h: 100,
86
+ name: 'video.mp4',
87
+ isAnimated: true,
88
+ mimeType: 'video/mp4',
89
+ src: 'http://localhost/video.mp4',
90
+ },
91
+ meta: {},
92
+ },
93
+ ])
94
+ editor.createShapes([
95
+ {
96
+ id: videoShapeId,
97
+ type: 'video',
98
+ x: 0,
99
+ y: 0,
100
+ props: { w: 100, h: 100, assetId: videoAssetId },
101
+ },
102
+ ])
103
+ })
104
+
105
+ // Wait for the async asset URL resolution so the <video> element renders
106
+ await act(async () => {
107
+ await new Promise((resolve) => setTimeout(resolve, 0))
108
+ })
109
+
110
+ const container = getShapeContainer()
111
+ const video = container.querySelector('video')
112
+ expect(video).toBeTruthy()
113
+
114
+ // The video element exists but hasn't fired loadeddata yet
115
+ expect(container.style.backgroundColor).toBe(LOADING_BACKGROUND)
116
+ expect(container.style.border).toBe(LOADING_BORDER)
117
+
118
+ await act(async () => {
119
+ fireEvent.loadedData(video!)
120
+ })
121
+
122
+ expect(container.style.backgroundColor).toBe('transparent')
123
+ // jsdom doesn't round-trip the `border: none` shorthand, so check the style directly
124
+ expect(container.style.borderStyle).toBe('none')
125
+ })
126
+ })
@@ -0,0 +1,37 @@
1
+ import { act } from '@testing-library/react'
2
+ import { Editor } from '@tldraw/editor'
3
+ import { Tldraw } from '../lib/Tldraw'
4
+ import { renderTldrawComponentWithEditor } from './testutils/renderTldrawComponent'
5
+
6
+ let editor: Editor
7
+ let rendered: Awaited<ReturnType<typeof renderTldrawComponentWithEditor>>['rendered']
8
+
9
+ beforeEach(async () => {
10
+ // Pin the quick actions into the menu panel so the test does not depend on jsdom's viewport width
11
+ ;({ editor, rendered } = await renderTldrawComponentWithEditor(
12
+ (onMount) => <Tldraw onMount={onMount} options={{ actionShortcutsLocation: 'menu' }} />,
13
+ { waitForPatterns: true }
14
+ ))
15
+ })
16
+
17
+ afterEach(() => {
18
+ editor?.dispose()
19
+ })
20
+
21
+ describe('actions menu in readonly mode', () => {
22
+ it('shows the actions menu button when not readonly', async () => {
23
+ expect(await rendered.findByTestId('actions-menu.button')).toBeTruthy()
24
+ })
25
+
26
+ it.each(['select', 'hand', 'zoom', 'eraser'])(
27
+ 'hides the actions menu button in readonly mode with the %s tool',
28
+ async (toolId) => {
29
+ act(() => {
30
+ editor.updateInstanceState({ isReadonly: true })
31
+ editor.setCurrentTool(toolId)
32
+ })
33
+ expect(editor.getCurrentToolId()).toBe(toolId)
34
+ expect(rendered.queryByTestId('actions-menu.button')).toBeNull()
35
+ }
36
+ )
37
+ })
@@ -38,8 +38,8 @@ exports[`editor.packShapes > packs rotated shapes > packed shapes 1`] = `
38
38
  "rotation": 3.141592653589793,
39
39
  "type": "geo",
40
40
  "typeName": "shape",
41
- "x": 192,
42
- "y": 308,
41
+ "x": 134,
42
+ "y": 250,
43
43
  },
44
44
  {
45
45
  "id": "shape:boxB",
@@ -77,8 +77,8 @@ exports[`editor.packShapes > packs rotated shapes > packed shapes 1`] = `
77
77
  "rotation": 0,
78
78
  "type": "geo",
79
79
  "typeName": "shape",
80
- "x": 92,
81
- "y": 92,
80
+ "x": 150,
81
+ "y": 150,
82
82
  },
83
83
  {
84
84
  "id": "shape:boxC",
@@ -116,8 +116,8 @@ exports[`editor.packShapes > packs rotated shapes > packed shapes 1`] = `
116
116
  "rotation": 0,
117
117
  "type": "geo",
118
118
  "typeName": "shape",
119
- "x": 208,
120
- "y": 92,
119
+ "x": 266,
120
+ "y": 150,
121
121
  },
122
122
  ]
123
123
  `;
@@ -88,6 +88,17 @@ describe('Locking', () => {
88
88
  // Locking deselects the shape
89
89
  expect(editor.getSelectedShapeIds()).toEqual([])
90
90
  })
91
+
92
+ it('Locks and deselects a mixed selection of locked and unlocked shapes', () => {
93
+ editor.run(() => editor.setSelectedShapes([ids.lockedShapeA, ids.unlockedShapeA]), {
94
+ ignoreShapeLock: true,
95
+ })
96
+ editor.toggleLock(editor.getSelectedShapeIds())
97
+ expect(
98
+ [ids.lockedShapeA, ids.unlockedShapeA].map((id) => editor.getShape(id)!.isLocked)
99
+ ).toStrictEqual([true, true])
100
+ expect(editor.getSelectedShapeIds()).toEqual([])
101
+ })
91
102
  })
92
103
 
93
104
  describe('Locked shapes', () => {
@@ -74,4 +74,24 @@ describe('editor.packShapes', () => {
74
74
  editor.getCurrentPageShapes().map((s) => ({ ...s, parentId: 'wahtever' }))
75
75
  ).toMatchSnapshot('packed shapes')
76
76
  })
77
+
78
+ it('packs shapes of different heights into rows, tallest first', () => {
79
+ // With the clusters sorted ascending by height, every shape after the first was too tall
80
+ // for the row's remaining space and fell into a single left-hand column.
81
+ editor.selectAll()
82
+ editor.deleteShapes(editor.getSelectedShapeIds())
83
+ editor.createShapes([
84
+ { id: ids.boxA, type: 'geo', x: 0, y: 0, props: { w: 100, h: 100 } },
85
+ { id: ids.boxB, type: 'geo', x: 200, y: 0, props: { w: 100, h: 60 } },
86
+ { id: ids.boxC, type: 'geo', x: 400, y: 0, props: { w: 120, h: 80 } },
87
+ { id: ids.boxD, type: 'geo', x: 600, y: 0, props: { w: 100, h: 120 } },
88
+ ])
89
+ editor.packShapes([ids.boxA, ids.boxB, ids.boxC, ids.boxD], 20)
90
+ editor.expectShapeToMatch(
91
+ { id: ids.boxD, x: 110, y: 0 },
92
+ { id: ids.boxA, x: 230, y: 0 },
93
+ { id: ids.boxC, x: 350, y: 0 },
94
+ { id: ids.boxB, x: 490, y: 0 }
95
+ )
96
+ })
77
97
  })
@@ -1,4 +1,4 @@
1
- import { TLContent, createShapeId, structuredClone } from '@tldraw/editor'
1
+ import { AssetRecordType, TLContent, createShapeId, structuredClone } from '@tldraw/editor'
2
2
  import { TestEditor } from '../TestEditor'
3
3
 
4
4
  let editor: TestEditor
@@ -39,6 +39,40 @@ describe('Migrations', () => {
39
39
  })
40
40
  })
41
41
 
42
+ describe('Input content', () => {
43
+ it('is not mutated when it carries data url assets', () => {
44
+ const assetId = AssetRecordType.createId('imageAsset')
45
+ const imageId = createShapeId('image')
46
+ const src = 'data:image/png;base64,AAAA'
47
+ editor.createAssets([
48
+ {
49
+ type: 'image',
50
+ id: assetId,
51
+ typeName: 'asset',
52
+ props: { w: 100, h: 100, name: '', isAnimated: false, mimeType: 'image/png', src },
53
+ meta: {},
54
+ },
55
+ ])
56
+ editor.createShape({
57
+ id: imageId,
58
+ type: 'image',
59
+ x: 0,
60
+ y: 0,
61
+ props: { w: 100, h: 100, assetId },
62
+ })
63
+ // the content holds the live records when no migration applies, so putting it into another
64
+ // editor must not write through to this editor's asset
65
+ const content = editor.getContentFromCurrentPage([imageId])!
66
+ const other = new TestEditor()
67
+ other.putContentOntoCurrentPage(content)
68
+
69
+ expect(content.assets[0].props.src).toBe(src)
70
+ expect(content.rootShapeIds).toEqual([imageId])
71
+ expect(editor.getAsset(assetId)!.props.src).toBe(src)
72
+ other.dispose()
73
+ })
74
+ })
75
+
42
76
  describe('Post-positioning reparent into frame', () => {
43
77
  it('reparents shapes into a frame when they land inside it without an explicit point', () => {
44
78
  const frameId = createShapeId('frame')
@@ -1256,3 +1256,72 @@ test('calling setCameraOptions will apply the new constraints', () => {
1256
1256
  }
1257
1257
  `)
1258
1258
  })
1259
+
1260
+ describe('Constraint bounds away from the page origin', () => {
1261
+ it('keeps the bounds inside the padded viewport with the inside behavior', () => {
1262
+ editor.setCameraOptions({
1263
+ ...DEFAULT_CAMERA_OPTIONS,
1264
+ constraints: {
1265
+ ...DEFAULT_CONSTRAINTS,
1266
+ bounds: { x: 1000, y: 0, w: 800, h: 600 },
1267
+ padding: { x: 100, y: 100 },
1268
+ behavior: { x: 'inside', y: 'free' },
1269
+ },
1270
+ })
1271
+ // the bounds' right edge stops at the right padding edge
1272
+ editor.setCamera({ x: 100000, y: 0, z: 1 })
1273
+ expect(editor.getCamera()).toMatchObject({ x: -300, y: 0, z: 1 })
1274
+ expect(editor.pageToScreen({ x: 1800, y: 0 }).x).toBe(1500)
1275
+ // the bounds' left edge stops at the left padding edge
1276
+ editor.setCamera({ x: -100000, y: 0, z: 1 })
1277
+ expect(editor.getCamera()).toMatchObject({ x: -900, y: 0, z: 1 })
1278
+ expect(editor.pageToScreen({ x: 1000, y: 0 }).x).toBe(100)
1279
+ })
1280
+
1281
+ it('keeps the bounds adjacent to the padded viewport with the outside behavior', () => {
1282
+ editor.setCameraOptions({
1283
+ ...DEFAULT_CAMERA_OPTIONS,
1284
+ constraints: {
1285
+ ...DEFAULT_CONSTRAINTS,
1286
+ bounds: { x: 1000, y: 0, w: 800, h: 600 },
1287
+ padding: { x: 100, y: 100 },
1288
+ behavior: { x: 'outside', y: 'free' },
1289
+ },
1290
+ })
1291
+ // the bounds' left edge stops at the right padding edge
1292
+ editor.setCamera({ x: 100000, y: 0, z: 1 })
1293
+ expect(editor.getCamera()).toMatchObject({ x: 500, y: 0, z: 1 })
1294
+ expect(editor.pageToScreen({ x: 1000, y: 0 }).x).toBe(1500)
1295
+ // the bounds' right edge stops at the left padding edge
1296
+ editor.setCamera({ x: -100000, y: 0, z: 1 })
1297
+ expect(editor.getCamera()).toMatchObject({ x: -1700, y: 0, z: 1 })
1298
+ expect(editor.pageToScreen({ x: 1800, y: 0 }).x).toBe(100)
1299
+ })
1300
+ })
1301
+
1302
+ test('clamps horizontal padding against the viewport width, not its height', () => {
1303
+ editor.setCameraOptions({
1304
+ ...DEFAULT_CAMERA_OPTIONS,
1305
+ constraints: {
1306
+ ...DEFAULT_CONSTRAINTS,
1307
+ bounds: { x: 0, y: 0, w: 200, h: 100 },
1308
+ padding: { x: 600, y: 0 },
1309
+ behavior: { x: 'inside', y: 'free' },
1310
+ },
1311
+ })
1312
+ // 600 is below half of the 1600px viewport width, so the padding is honoured as is
1313
+ editor.setCamera({ x: -100000, y: 0, z: 1 })
1314
+ expect(editor.getCamera()).toMatchObject({ x: 600, y: 0, z: 1 })
1315
+ })
1316
+
1317
+ test('slideCamera zoom momentum survives a long frame', () => {
1318
+ editor.user.updateUserPreferences({ animationSpeed: 1 })
1319
+ editor.setCamera({ x: 0, y: 0, z: 1 })
1320
+ editor.slideCamera({ speed: 1, direction: { x: 0, y: 0, z: -0.01 } })
1321
+ // a 100ms frame would have driven a linear zoom factor to zero (and the camera to NaN)
1322
+ editor.emit('tick', 100)
1323
+ const { x, y, z } = editor.getCamera()
1324
+ expect(z).toBeGreaterThan(0)
1325
+ expect(z).toBeLessThan(1)
1326
+ expect(Number.isFinite(x) && Number.isFinite(y)).toBe(true)
1327
+ })
@@ -143,6 +143,18 @@ describe('distributeShapes command', () => {
143
143
  })
144
144
  })
145
145
 
146
+ it('stacks in spatial order, not selection order, when a gap is given', () => {
147
+ // boxC sits between boxA and boxB on the page but comes after both in the input
148
+ editor.updateShapes([{ id: ids.boxC, type: 'geo', x: 50, y: 0 }])
149
+ editor.stackShapes([ids.boxA, ids.boxB, ids.boxC], 'horizontal', 10)
150
+ vi.advanceTimersByTime(1000)
151
+ editor.expectShapeToMatch(
152
+ { id: ids.boxA, x: 0 },
153
+ { id: ids.boxC, x: 110 },
154
+ { id: ids.boxB, x: 220 }
155
+ )
156
+ })
157
+
146
158
  it('stacks the shapes based on the most common gap', () => {
147
159
  editor.setSelectedShapes([ids.boxA, ids.boxB, ids.boxC, ids.boxD])
148
160
  editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 0)
@@ -47,6 +47,14 @@ describe('When resizing', () => {
47
47
  h: 1,
48
48
  })
49
49
  })
50
+
51
+ it('updates the selection screen bounds when the container moves', () => {
52
+ editor.createShape({ type: 'geo', x: 100, y: 100, props: { w: 100, h: 100 } })
53
+ editor.selectAll()
54
+ expect(editor.getSelectionRotatedScreenBounds()).toMatchObject({ x: 100, y: 100 })
55
+ editor.setScreenBounds({ x: 300, y: 200, w: 1080, h: 720 })
56
+ expect(editor.getSelectionRotatedScreenBounds()).toMatchObject({ x: 400, y: 300 })
57
+ })
50
58
  })
51
59
 
52
60
  describe('When center is false', () => {