@tldraw/editor 3.16.0-canary.f60032f16651 → 3.16.0-canary.faec5de49906

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 (167) hide show
  1. package/dist-cjs/index.d.ts +77 -101
  2. package/dist-cjs/index.js +3 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +6 -6
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +7 -10
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
  12. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  14. package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
  15. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  16. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
  17. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  18. package/dist-cjs/lib/config/TLUserPreferences.js +9 -3
  19. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  20. package/dist-cjs/lib/editor/Editor.js +61 -126
  21. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  22. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
  23. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  24. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +9 -4
  25. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  26. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +23 -0
  27. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  28. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  29. package/dist-cjs/lib/exports/getSvgJsx.js +35 -16
  30. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  31. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  32. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  33. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  34. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  35. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  36. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  37. package/dist-cjs/lib/license/LicenseManager.js +120 -50
  38. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  39. package/dist-cjs/lib/license/LicenseProvider.js +39 -1
  40. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  41. package/dist-cjs/lib/license/Watermark.js +72 -10
  42. package/dist-cjs/lib/license/Watermark.js.map +3 -3
  43. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  44. package/dist-cjs/lib/options.js +7 -0
  45. package/dist-cjs/lib/options.js.map +2 -2
  46. package/dist-cjs/lib/primitives/Box.js +3 -0
  47. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  48. package/dist-cjs/lib/primitives/Vec.js +0 -4
  49. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  50. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +50 -20
  51. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  52. package/dist-cjs/lib/primitives/geometry/Group2d.js +8 -1
  53. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  54. package/dist-cjs/lib/utils/reparenting.js +2 -35
  55. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  56. package/dist-cjs/version.js +3 -3
  57. package/dist-cjs/version.js.map +1 -1
  58. package/dist-esm/index.d.mts +77 -101
  59. package/dist-esm/index.mjs +3 -5
  60. package/dist-esm/index.mjs.map +2 -2
  61. package/dist-esm/lib/TldrawEditor.mjs +6 -6
  62. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  63. package/dist-esm/lib/components/Shape.mjs +7 -10
  64. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  65. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  66. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  67. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  68. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
  69. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  70. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  71. package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
  72. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  73. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
  74. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  75. package/dist-esm/lib/config/TLUserPreferences.mjs +9 -3
  76. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  77. package/dist-esm/lib/editor/Editor.mjs +61 -126
  78. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  79. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
  80. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  81. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +9 -4
  82. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  83. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +23 -0
  84. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  85. package/dist-esm/lib/exports/getSvgJsx.mjs +36 -16
  86. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  87. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  88. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  89. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  90. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  91. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  92. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  93. package/dist-esm/lib/license/LicenseManager.mjs +121 -51
  94. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  95. package/dist-esm/lib/license/LicenseProvider.mjs +39 -2
  96. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  97. package/dist-esm/lib/license/Watermark.mjs +72 -10
  98. package/dist-esm/lib/license/Watermark.mjs.map +3 -3
  99. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  100. package/dist-esm/lib/options.mjs +7 -0
  101. package/dist-esm/lib/options.mjs.map +2 -2
  102. package/dist-esm/lib/primitives/Box.mjs +4 -1
  103. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  104. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  105. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  106. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +53 -21
  107. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  108. package/dist-esm/lib/primitives/geometry/Group2d.mjs +8 -1
  109. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  110. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  111. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  112. package/dist-esm/version.mjs +3 -3
  113. package/dist-esm/version.mjs.map +1 -1
  114. package/editor.css +308 -290
  115. package/package.json +14 -37
  116. package/src/index.ts +2 -9
  117. package/src/lib/TldrawEditor.tsx +7 -14
  118. package/src/lib/components/Shape.tsx +6 -12
  119. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  120. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  121. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
  122. package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
  123. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
  124. package/src/lib/config/TLUserPreferences.ts +8 -1
  125. package/src/lib/editor/Editor.test.ts +12 -11
  126. package/src/lib/editor/Editor.ts +79 -168
  127. package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
  128. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
  129. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
  130. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
  131. package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
  132. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
  133. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
  134. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
  135. package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
  136. package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
  137. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +34 -26
  138. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +6 -1
  139. package/src/lib/editor/shapes/ShapeUtil.ts +46 -0
  140. package/src/lib/editor/types/misc-types.ts +0 -6
  141. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  142. package/src/lib/exports/getSvgJsx.tsx +78 -21
  143. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  144. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  145. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  146. package/src/lib/license/LicenseManager.test.ts +648 -383
  147. package/src/lib/license/LicenseManager.ts +173 -53
  148. package/src/lib/license/LicenseProvider.tsx +74 -2
  149. package/src/lib/license/Watermark.test.tsx +2 -1
  150. package/src/lib/license/Watermark.tsx +77 -10
  151. package/src/lib/license/useLicenseManagerState.ts +2 -2
  152. package/src/lib/options.ts +8 -0
  153. package/src/lib/primitives/Box.test.ts +126 -0
  154. package/src/lib/primitives/Box.ts +10 -1
  155. package/src/lib/primitives/Vec.ts +0 -5
  156. package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
  157. package/src/lib/primitives/geometry/Geometry2d.ts +78 -21
  158. package/src/lib/primitives/geometry/Group2d.ts +10 -1
  159. package/src/lib/utils/reparenting.ts +3 -69
  160. package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
  161. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
  162. package/src/version.ts +3 -3
  163. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  164. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  165. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  166. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  167. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -116,7 +116,6 @@ import {
116
116
  } from '../constants'
117
117
  import { exportToSvg } from '../exports/exportToSvg'
118
118
  import { getSvgAsImage } from '../exports/getSvgAsImage'
119
- import { tlenv } from '../globals/environment'
120
119
  import { tlmenus } from '../globals/menus'
121
120
  import { tltime } from '../globals/time'
122
121
  import { TldrawOptions, defaultTldrawOptions } from '../options'
@@ -244,16 +243,6 @@ export interface TLEditorOptions {
244
243
  options?: Partial<TldrawOptions>
245
244
  licenseKey?: string
246
245
  fontAssetUrls?: { [key: string]: string | undefined }
247
- /**
248
- * A predicate that should return true if the given shape should be hidden.
249
- *
250
- * @deprecated Use {@link Editor#getShapeVisibility} instead.
251
- *
252
- * @param shape - The shape to check.
253
- * @param editor - The editor instance.
254
- */
255
- isShapeHidden?(shape: TLShape, editor: Editor): boolean
256
-
257
246
  /**
258
247
  * Provides a way to hide shapes.
259
248
  *
@@ -309,21 +298,12 @@ export class Editor extends EventEmitter<TLEventMap> {
309
298
  autoFocus,
310
299
  inferDarkMode,
311
300
  options,
312
- // eslint-disable-next-line @typescript-eslint/no-deprecated
313
- isShapeHidden,
314
301
  getShapeVisibility,
315
302
  fontAssetUrls,
316
303
  }: TLEditorOptions) {
317
304
  super()
318
- assert(
319
- !(isShapeHidden && getShapeVisibility),
320
- 'Cannot use both isShapeHidden and getShapeVisibility'
321
- )
322
305
 
323
- this._getShapeVisibility = isShapeHidden
324
- ? // eslint-disable-next-line @typescript-eslint/no-deprecated
325
- (shape: TLShape, editor: Editor) => (isShapeHidden(shape, editor) ? 'hidden' : 'inherit')
326
- : getShapeVisibility
306
+ this._getShapeVisibility = getShapeVisibility
327
307
 
328
308
  this.options = { ...defaultTldrawOptions, ...options }
329
309
 
@@ -907,14 +887,6 @@ export class Editor extends EventEmitter<TLEventMap> {
907
887
  */
908
888
  readonly fonts: FontManager
909
889
 
910
- /**
911
- * A manager for the editor's environment.
912
- *
913
- * @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
914
- * @public
915
- */
916
- readonly environment = tlenv
917
-
918
890
  /**
919
891
  * A manager for the editor's scribbles.
920
892
  *
@@ -1119,35 +1091,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1119
1091
  return this.history.getNumRedos() > 0
1120
1092
  }
1121
1093
 
1122
- /**
1123
- * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1124
- * any redos.
1125
- *
1126
- * @example
1127
- * ```ts
1128
- * editor.mark()
1129
- * editor.mark('flip shapes')
1130
- * ```
1131
- *
1132
- * @param markId - The mark's id, usually the reason for adding the mark.
1133
- *
1134
- * @public
1135
- * @deprecated use {@link Editor.markHistoryStoppingPoint} instead
1136
- */
1137
- mark(markId?: string): this {
1138
- if (typeof markId === 'string') {
1139
- console.warn(
1140
- `[tldraw] \`editor.history.mark("${markId}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`
1141
- )
1142
- } else {
1143
- console.warn(
1144
- '[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead.'
1145
- )
1146
- }
1147
- this.history._mark(markId ?? uniqueId())
1148
- return this
1149
- }
1150
-
1151
1094
  /**
1152
1095
  * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1153
1096
  * any redos. You typically want to do this just before a user interaction begins or is handled.
@@ -1272,13 +1215,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1272
1215
  return this
1273
1216
  }
1274
1217
 
1275
- /**
1276
- * @deprecated Use `Editor.run` instead.
1277
- */
1278
- batch(fn: () => void, opts?: TLEditorRunOptions): this {
1279
- return this.run(fn, opts)
1280
- }
1281
-
1282
1218
  /* --------------------- Errors --------------------- */
1283
1219
 
1284
1220
  /** @internal */
@@ -1580,54 +1516,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1580
1516
 
1581
1517
  menus = tlmenus.forContext(this.contextId)
1582
1518
 
1583
- /**
1584
- * @deprecated Use `editor.menus.getOpenMenus` instead.
1585
- *
1586
- * @public
1587
- */
1588
- @computed getOpenMenus(): string[] {
1589
- return this.menus.getOpenMenus()
1590
- }
1591
-
1592
- /**
1593
- * @deprecated Use `editor.menus.addOpenMenu` instead.
1594
- *
1595
- * @public
1596
- */
1597
- addOpenMenu(id: string): this {
1598
- this.menus.addOpenMenu(id)
1599
- return this
1600
- }
1601
-
1602
- /**
1603
- * @deprecated Use `editor.menus.deleteOpenMenu` instead.
1604
- *
1605
- * @public
1606
- */
1607
- deleteOpenMenu(id: string): this {
1608
- this.menus.deleteOpenMenu(id)
1609
- return this
1610
- }
1611
-
1612
- /**
1613
- * @deprecated Use `editor.menus.clearOpenMenus` instead.
1614
- *
1615
- * @public
1616
- */
1617
- clearOpenMenus(): this {
1618
- this.menus.clearOpenMenus()
1619
- return this
1620
- }
1621
-
1622
- /**
1623
- * @deprecated Use `editor.menus.hasAnyOpenMenus` instead.
1624
- *
1625
- * @public
1626
- */
1627
- @computed getIsMenuOpen(): boolean {
1628
- return this.menus.hasAnyOpenMenus()
1629
- }
1630
-
1631
1519
  /* --------------------- Cursor --------------------- */
1632
1520
 
1633
1521
  /**
@@ -4792,8 +4680,10 @@ export class Editor extends EventEmitter<TLEventMap> {
4792
4680
  return this.store.createComputedCache<Box, TLShape>('pageBoundsCache', (shape) => {
4793
4681
  const pageTransform = this.getShapePageTransform(shape)
4794
4682
  if (!pageTransform) return undefined
4795
- const geometry = this.getShapeGeometry(shape)
4796
- return Box.FromPoints(pageTransform.applyToPoints(geometry.vertices))
4683
+
4684
+ return Box.FromPoints(
4685
+ pageTransform.applyToPoints(this.getShapeGeometry(shape).boundsVertices)
4686
+ )
4797
4687
  })
4798
4688
  }
4799
4689
 
@@ -4860,27 +4750,25 @@ export class Editor extends EventEmitter<TLEventMap> {
4860
4750
  return this.store.createComputedCache('pageMaskCache', (shape) => {
4861
4751
  if (isPageId(shape.parentId)) return undefined
4862
4752
 
4863
- const frameAncestors = this.getShapeAncestors(shape.id).filter((shape) =>
4864
- this.isShapeOfType<TLFrameShape>(shape, 'frame')
4865
- )
4866
-
4867
- if (frameAncestors.length === 0) return undefined
4868
-
4869
- const pageMask = frameAncestors
4870
- .map<Vec[] | undefined>((s) => {
4871
- // Apply the frame transform to the frame outline to get the frame outline in the current page space
4872
- const geometry = this.getShapeGeometry(s.id)
4873
- const pageTransform = this.getShapePageTransform(s.id)
4874
- return pageTransform.applyToPoints(geometry.vertices)
4875
- })
4876
- .reduce((acc, b) => {
4877
- if (!(b && acc)) return undefined
4878
- const intersection = intersectPolygonPolygon(acc, b)
4879
- if (intersection) {
4880
- return intersection.map(Vec.Cast)
4881
- }
4882
- return []
4883
- })
4753
+ const clipPaths: Vec[][] = []
4754
+ // Get all ancestors that can potentially clip this shape
4755
+ for (const ancestor of this.getShapeAncestors(shape.id)) {
4756
+ const util = this.getShapeUtil(ancestor)
4757
+ const clipPath = util.getClipPath?.(ancestor)
4758
+ if (!clipPath) continue
4759
+ if (util.shouldClipChild?.(shape) === false) continue
4760
+ const pageTransform = this.getShapePageTransform(ancestor.id)
4761
+ clipPaths.push(pageTransform.applyToPoints(clipPath))
4762
+ }
4763
+ if (clipPaths.length === 0) return undefined
4764
+
4765
+ const pageMask = clipPaths.reduce((acc, b) => {
4766
+ const intersection = intersectPolygonPolygon(acc, b)
4767
+ if (intersection) {
4768
+ return intersection.map(Vec.Cast)
4769
+ }
4770
+ return []
4771
+ })
4884
4772
 
4885
4773
  return pageMask
4886
4774
  })
@@ -5841,11 +5729,6 @@ export class Editor extends EventEmitter<TLEventMap> {
5841
5729
  return shapeIds
5842
5730
  }
5843
5731
 
5844
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
5845
- getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
5846
- return this.getDraggingOverShape(point, droppingShapes)
5847
- }
5848
-
5849
5732
  /**
5850
5733
  * Get the shape that some shapes should be dropped on at a given point.
5851
5734
  *
@@ -6333,7 +6216,17 @@ export class Editor extends EventEmitter<TLEventMap> {
6333
6216
 
6334
6217
  this.createShapes(shapesToCreate)
6335
6218
  this.createBindings(bindingsToCreate)
6336
- this.setSelectedShapes(compact(ids.map((id) => shapeIds.get(id))))
6219
+
6220
+ this.setSelectedShapes(
6221
+ compact(
6222
+ ids.map((oldId) => {
6223
+ const newId = shapeIds.get(oldId)
6224
+ if (!newId) return null
6225
+ if (!this.getShape(newId)) return null
6226
+ return newId
6227
+ })
6228
+ )
6229
+ )
6337
6230
 
6338
6231
  if (offset !== undefined) {
6339
6232
  // If we've offset the duplicated shapes, check to see whether their new bounds is entirely
@@ -7857,25 +7750,32 @@ export class Editor extends EventEmitter<TLEventMap> {
7857
7750
  ) {
7858
7751
  let parentId: TLParentId = this.getFocusedGroupId()
7859
7752
 
7860
- for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
7861
- const parent = currentPageShapesSorted[i]
7862
- const util = this.getShapeUtil(parent)
7863
- if (
7864
- util.canReceiveNewChildrenOfType(parent, partial.type) &&
7865
- !this.isShapeHidden(parent) &&
7866
- this.isPointInShape(
7867
- parent,
7868
- // If no parent is provided, then we can treat the
7869
- // shape's provided x/y as being in the page's space.
7870
- { x: partial.x ?? 0, y: partial.y ?? 0 },
7871
- {
7872
- margin: 0,
7873
- hitInside: true,
7874
- }
7875
- )
7876
- ) {
7877
- parentId = parent.id
7878
- break
7753
+ const isPositioned = partial.x !== undefined && partial.y !== undefined
7754
+
7755
+ // If the shape has been explicitly positioned, we'll try to find a parent at
7756
+ // that position. If not, we'll assume the user isn't deliberately placing the
7757
+ // shape and the positioning will be handled later by another system.
7758
+ if (isPositioned) {
7759
+ for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
7760
+ const parent = currentPageShapesSorted[i]
7761
+ const util = this.getShapeUtil(parent)
7762
+ if (
7763
+ util.canReceiveNewChildrenOfType(parent, partial.type) &&
7764
+ !this.isShapeHidden(parent) &&
7765
+ this.isPointInShape(
7766
+ parent,
7767
+ // If no parent is provided, then we can treat the
7768
+ // shape's provided x/y as being in the page's space.
7769
+ { x: partial.x ?? 0, y: partial.y ?? 0 },
7770
+ {
7771
+ margin: 0,
7772
+ hitInside: true,
7773
+ }
7774
+ )
7775
+ ) {
7776
+ parentId = parent.id
7777
+ break
7778
+ }
7879
7779
  }
7880
7780
  }
7881
7781
 
@@ -9444,13 +9344,6 @@ export class Editor extends EventEmitter<TLEventMap> {
9444
9344
  }
9445
9345
  }
9446
9346
 
9447
- /** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
9448
- async getSvg(shapes: TLShapeId[] | TLShape[], opts: TLSvgExportOptions = {}) {
9449
- const result = await this.getSvgElement(shapes, opts)
9450
- if (!result) return undefined
9451
- return result.svg
9452
- }
9453
-
9454
9347
  /**
9455
9348
  * Get an exported image of the given shapes.
9456
9349
  *
@@ -9502,6 +9395,24 @@ export class Editor extends EventEmitter<TLEventMap> {
9502
9395
  }
9503
9396
  }
9504
9397
 
9398
+ /**
9399
+ * Get an exported image of the given shapes as a data URL.
9400
+ *
9401
+ * @param shapes - The shapes (or shape ids) to export.
9402
+ * @param opts - Options for the export.
9403
+ *
9404
+ * @returns A data URL of the image.
9405
+ * @public
9406
+ */
9407
+ async toImageDataUrl(shapes: TLShapeId[] | TLShape[], opts: TLImageExportOptions = {}) {
9408
+ const { blob, width, height } = await this.toImage(shapes, opts)
9409
+ return {
9410
+ url: await FileHelpers.blobToDataUrl(blob),
9411
+ width,
9412
+ height,
9413
+ }
9414
+ }
9415
+
9505
9416
  /* --------------------- Events --------------------- */
9506
9417
 
9507
9418
  /**
@@ -7,6 +7,12 @@ function fromScratch(editor: Editor): Set<TLShapeId> {
7
7
  const viewportPageBounds = editor.getViewportPageBounds()
8
8
  const notVisibleShapes = new Set<TLShapeId>()
9
9
  shapesIds.forEach((id) => {
10
+ const shape = editor.getShape(id)
11
+ if (!shape) return
12
+
13
+ const canCull = editor.getShapeUtil(shape.type).canCull(shape)
14
+ if (!canCull) return
15
+
10
16
  // If the shape is fully outside of the viewport page bounds, add it to the set.
11
17
  // We'll ignore masks here, since they're more expensive to compute and the overhead is not worth it.
12
18
  const pageBounds = editor.getShapePageBounds(id)
@@ -1,12 +1,13 @@
1
+ import { Mocked, vi } from 'vitest'
1
2
  import { Editor } from '../../Editor'
2
3
  import { TLClickEventInfo, TLPointerEventInfo } from '../../types/event-types'
3
4
  import { ClickManager } from './ClickManager'
4
5
 
5
6
  // Mock the Editor class
6
- jest.mock('../../Editor')
7
+ vi.mock('../../Editor')
7
8
 
8
9
  describe('ClickManager', () => {
9
- let editor: jest.Mocked<Editor>
10
+ let editor: Mocked<Editor>
10
11
  let clickManager: ClickManager
11
12
  let mockTimers: any
12
13
 
@@ -29,14 +30,14 @@ describe('ClickManager', () => {
29
30
  })
30
31
 
31
32
  beforeEach(() => {
32
- jest.useFakeTimers()
33
+ vi.useFakeTimers()
33
34
  mockTimers = {
34
- setTimeout: jest.fn((fn, delay) => setTimeout(fn, delay)),
35
+ setTimeout: vi.fn((fn, delay) => setTimeout(fn, delay)),
35
36
  }
36
37
 
37
38
  editor = {
38
39
  timers: mockTimers,
39
- dispatch: jest.fn(),
40
+ dispatch: vi.fn(),
40
41
  options: {
41
42
  doubleClickDurationMs: 300,
42
43
  multiClickDurationMs: 300,
@@ -46,7 +47,7 @@ describe('ClickManager', () => {
46
47
  inputs: {
47
48
  currentScreenPoint: { x: 0, y: 0 },
48
49
  },
49
- getInstanceState: jest.fn(() => ({
50
+ getInstanceState: vi.fn(() => ({
50
51
  isCoarsePointer: false,
51
52
  })),
52
53
  } as any
@@ -55,8 +56,8 @@ describe('ClickManager', () => {
55
56
  })
56
57
 
57
58
  afterEach(() => {
58
- jest.useRealTimers()
59
- jest.clearAllMocks()
59
+ vi.useRealTimers()
60
+ vi.clearAllMocks()
60
61
  })
61
62
 
62
63
  describe('constructor and initial state', () => {
@@ -100,7 +101,7 @@ describe('ClickManager', () => {
100
101
  clickManager.handlePointerEvent(pointerEvent)
101
102
  expect(clickManager.clickState).toBe('pendingDouble')
102
103
 
103
- jest.advanceTimersByTime(350)
104
+ vi.advanceTimersByTime(350)
104
105
 
105
106
  expect(clickManager.clickState).toBe('idle')
106
107
  })
@@ -141,7 +142,7 @@ describe('ClickManager', () => {
141
142
  clickManager.handlePointerEvent(firstDown)
142
143
  clickManager.handlePointerEvent(secondDown)
143
144
 
144
- jest.advanceTimersByTime(350)
145
+ vi.advanceTimersByTime(350)
145
146
 
146
147
  expect(editor.dispatch).toHaveBeenCalledWith(
147
148
  expect.objectContaining({
@@ -235,7 +236,7 @@ describe('ClickManager', () => {
235
236
  clickManager.handlePointerEvent(pointerDown) // second
236
237
  clickManager.handlePointerEvent(pointerDown) // third
237
238
 
238
- jest.advanceTimersByTime(350)
239
+ vi.advanceTimersByTime(350)
239
240
 
240
241
  expect(editor.dispatch).toHaveBeenCalledWith(
241
242
  expect.objectContaining({
@@ -255,7 +256,7 @@ describe('ClickManager', () => {
255
256
  clickManager.handlePointerEvent(pointerDown) // third
256
257
  clickManager.handlePointerEvent(pointerDown) // fourth
257
258
 
258
- jest.advanceTimersByTime(350)
259
+ vi.advanceTimersByTime(350)
259
260
 
260
261
  expect(editor.dispatch).toHaveBeenCalledWith(
261
262
  expect.objectContaining({
@@ -277,7 +278,7 @@ describe('ClickManager', () => {
277
278
  editor.options.doubleClickDurationMs
278
279
  )
279
280
 
280
- jest.clearAllMocks()
281
+ vi.clearAllMocks()
281
282
 
282
283
  // Second click - should use multiClickDurationMs
283
284
  clickManager.handlePointerEvent(pointerDown)
@@ -392,7 +393,7 @@ describe('ClickManager', () => {
392
393
  clickManager.cancelDoubleClickTimeout()
393
394
 
394
395
  // Advance time - should not dispatch settle event
395
- jest.advanceTimersByTime(350)
396
+ vi.advanceTimersByTime(350)
396
397
 
397
398
  expect(editor.dispatch).not.toHaveBeenCalled()
398
399
  expect(clickManager.clickState).toBe('idle')
@@ -1,19 +1,20 @@
1
+ import { Mock, Mocked, vi } from 'vitest'
1
2
  import { Box } from '../../../primitives/Box'
2
3
  import { Vec } from '../../../primitives/Vec'
3
4
  import { Editor } from '../../Editor'
4
5
  import { EdgeScrollManager } from './EdgeScrollManager'
5
6
 
6
7
  // Mock the Editor class
7
- jest.mock('../../Editor')
8
+ vi.mock('../../Editor')
8
9
 
9
10
  describe('EdgeScrollManager', () => {
10
- let editor: jest.Mocked<
11
+ let editor: Mocked<
11
12
  Editor & {
12
- user: { getEdgeScrollSpeed: jest.Mock }
13
- getCamera: jest.Mock
14
- getCameraOptions: jest.Mock
15
- getZoomLevel: jest.Mock
16
- getViewportScreenBounds: jest.Mock
13
+ user: { getEdgeScrollSpeed: Mock }
14
+ getCamera: Mock
15
+ getCameraOptions: Mock
16
+ getZoomLevel: Mock
17
+ getViewportScreenBounds: Mock
17
18
  }
18
19
  >
19
20
  let edgeScrollManager: EdgeScrollManager
@@ -33,33 +34,33 @@ describe('EdgeScrollManager', () => {
33
34
  isPanning: false,
34
35
  },
35
36
  user: {
36
- getEdgeScrollSpeed: jest.fn(() => 1),
37
+ getEdgeScrollSpeed: vi.fn(() => 1),
37
38
  },
38
- getViewportScreenBounds: jest.fn(() => new Box(0, 0, 1000, 600)),
39
- getInstanceState: jest.fn(
39
+ getViewportScreenBounds: vi.fn(() => new Box(0, 0, 1000, 600)),
40
+ getInstanceState: vi.fn(
40
41
  () =>
41
42
  ({
42
43
  isCoarsePointer: false,
43
44
  insets: [false, false, false, false], // [top, right, bottom, left]
44
45
  }) as any
45
46
  ),
46
- getCameraOptions: jest.fn(() => ({
47
+ getCameraOptions: vi.fn(() => ({
47
48
  isLocked: false,
48
49
  panSpeed: 1,
49
50
  zoomSpeed: 1,
50
51
  zoomSteps: [1],
51
52
  wheelBehavior: 'pan' as const,
52
53
  })),
53
- getZoomLevel: jest.fn(() => 1),
54
- getCamera: jest.fn(() => new Vec(0, 0, 1)),
55
- setCamera: jest.fn(),
54
+ getZoomLevel: vi.fn(() => 1),
55
+ getCamera: vi.fn(() => new Vec(0, 0, 1)),
56
+ setCamera: vi.fn(),
56
57
  } as any
57
58
 
58
59
  edgeScrollManager = new EdgeScrollManager(editor as any)
59
60
  })
60
61
 
61
62
  afterEach(() => {
62
- jest.clearAllMocks()
63
+ vi.clearAllMocks()
63
64
  })
64
65
 
65
66
  describe('constructor and initialization', () => {