@tldraw/editor 4.4.0-canary.2d6554e2c18e → 4.4.0-canary.2f80fa863d5a

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 (157) hide show
  1. package/dist-cjs/index.d.ts +126 -25
  2. package/dist-cjs/index.js +4 -7
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +20 -8
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +12 -17
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +26 -1
  9. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +16 -1
  11. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +3 -4
  13. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  14. package/dist-cjs/lib/editor/Editor.js +23 -7
  15. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  16. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +32 -13
  17. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  18. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +2 -3
  19. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
  20. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  21. package/dist-cjs/lib/hooks/useCanvasEvents.js +10 -2
  22. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  23. package/dist-cjs/lib/hooks/usePeerIds.js +8 -2
  24. package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
  25. package/dist-cjs/lib/hooks/useShapeCulling.js +75 -0
  26. package/dist-cjs/lib/hooks/useShapeCulling.js.map +7 -0
  27. package/dist-cjs/lib/license/LicenseManager.js +6 -6
  28. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  29. package/dist-cjs/lib/options.js +7 -1
  30. package/dist-cjs/lib/options.js.map +2 -2
  31. package/dist-cjs/lib/utils/areShapesContentEqual.js +3 -1
  32. package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
  33. package/dist-cjs/lib/utils/assets.js +4 -6
  34. package/dist-cjs/lib/utils/assets.js.map +2 -2
  35. package/dist-cjs/lib/utils/browserCanvasMaxSize.js +1 -2
  36. package/dist-cjs/lib/utils/browserCanvasMaxSize.js.map +2 -2
  37. package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
  38. package/dist-cjs/lib/utils/dom.js +3 -3
  39. package/dist-cjs/lib/utils/dom.js.map +2 -2
  40. package/dist-cjs/lib/utils/getIncrementedName.js +1 -1
  41. package/dist-cjs/lib/utils/getIncrementedName.js.map +2 -2
  42. package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
  43. package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +1 -1
  44. package/dist-cjs/lib/utils/keyboard.js +2 -2
  45. package/dist-cjs/lib/utils/keyboard.js.map +2 -2
  46. package/dist-cjs/lib/utils/normalizeWheel.js +2 -5
  47. package/dist-cjs/lib/utils/normalizeWheel.js.map +2 -2
  48. package/dist-cjs/lib/utils/reorderShapes.js +6 -6
  49. package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
  50. package/dist-cjs/lib/utils/reparenting.js +3 -4
  51. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  52. package/dist-cjs/lib/utils/runtime.js +12 -0
  53. package/dist-cjs/lib/utils/runtime.js.map +2 -2
  54. package/dist-cjs/version.js +3 -3
  55. package/dist-cjs/version.js.map +1 -1
  56. package/dist-esm/index.d.mts +126 -25
  57. package/dist-esm/index.mjs +8 -5
  58. package/dist-esm/index.mjs.map +2 -2
  59. package/dist-esm/lib/TldrawEditor.mjs +20 -8
  60. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  61. package/dist-esm/lib/components/Shape.mjs +12 -17
  62. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  63. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +27 -2
  64. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
  65. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +16 -1
  66. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  67. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -2
  68. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  69. package/dist-esm/lib/editor/Editor.mjs +23 -7
  70. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  71. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +32 -13
  72. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  73. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +2 -3
  74. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
  75. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  76. package/dist-esm/lib/hooks/useCanvasEvents.mjs +10 -2
  77. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  78. package/dist-esm/lib/hooks/usePeerIds.mjs +8 -2
  79. package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
  80. package/dist-esm/lib/hooks/useShapeCulling.mjs +55 -0
  81. package/dist-esm/lib/hooks/useShapeCulling.mjs.map +7 -0
  82. package/dist-esm/lib/license/LicenseManager.mjs +6 -6
  83. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  84. package/dist-esm/lib/options.mjs +7 -1
  85. package/dist-esm/lib/options.mjs.map +2 -2
  86. package/dist-esm/lib/utils/areShapesContentEqual.mjs +3 -1
  87. package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
  88. package/dist-esm/lib/utils/assets.mjs +4 -6
  89. package/dist-esm/lib/utils/assets.mjs.map +2 -2
  90. package/dist-esm/lib/utils/browserCanvasMaxSize.mjs +1 -2
  91. package/dist-esm/lib/utils/browserCanvasMaxSize.mjs.map +2 -2
  92. package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
  93. package/dist-esm/lib/utils/dom.mjs +3 -3
  94. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  95. package/dist-esm/lib/utils/getIncrementedName.mjs +1 -1
  96. package/dist-esm/lib/utils/getIncrementedName.mjs.map +2 -2
  97. package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
  98. package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +1 -1
  99. package/dist-esm/lib/utils/keyboard.mjs +2 -2
  100. package/dist-esm/lib/utils/keyboard.mjs.map +2 -2
  101. package/dist-esm/lib/utils/normalizeWheel.mjs +2 -5
  102. package/dist-esm/lib/utils/normalizeWheel.mjs.map +2 -2
  103. package/dist-esm/lib/utils/reorderShapes.mjs +6 -6
  104. package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
  105. package/dist-esm/lib/utils/reparenting.mjs +3 -4
  106. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  107. package/dist-esm/lib/utils/runtime.mjs +12 -0
  108. package/dist-esm/lib/utils/runtime.mjs.map +2 -2
  109. package/dist-esm/version.mjs +3 -3
  110. package/dist-esm/version.mjs.map +1 -1
  111. package/editor.css +17 -2
  112. package/package.json +10 -11
  113. package/src/index.ts +7 -4
  114. package/src/lib/TldrawEditor.tsx +34 -12
  115. package/src/lib/components/Shape.tsx +15 -16
  116. package/src/lib/components/default-components/CanvasShapeIndicators.tsx +46 -2
  117. package/src/lib/components/default-components/DefaultCanvas.tsx +24 -2
  118. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -2
  119. package/src/lib/editor/Editor.ts +42 -8
  120. package/src/lib/editor/derivations/notVisibleShapes.ts +39 -17
  121. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +0 -35
  122. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +4 -8
  123. package/src/lib/editor/shapes/ShapeUtil.ts +19 -5
  124. package/src/lib/hooks/useCanvasEvents.ts +13 -2
  125. package/src/lib/hooks/usePeerIds.ts +9 -2
  126. package/src/lib/hooks/useShapeCulling.tsx +98 -0
  127. package/src/lib/license/LicenseManager.ts +6 -6
  128. package/src/lib/options.ts +52 -2
  129. package/src/lib/utils/areShapesContentEqual.ts +9 -2
  130. package/src/lib/utils/assets.ts +15 -10
  131. package/src/lib/utils/browserCanvasMaxSize.ts +4 -2
  132. package/src/lib/utils/debug-flags.ts +0 -20
  133. package/src/lib/utils/dom.ts +6 -7
  134. package/src/lib/utils/getIncrementedName.ts +1 -1
  135. package/src/lib/utils/getPointerInfo.ts +1 -0
  136. package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
  137. package/src/lib/utils/keyboard.ts +6 -4
  138. package/src/lib/utils/normalizeWheel.ts +8 -8
  139. package/src/lib/utils/reorderShapes.ts +16 -7
  140. package/src/lib/utils/reparenting.ts +5 -10
  141. package/src/lib/utils/runtime.ts +26 -1
  142. package/src/version.ts +3 -3
  143. package/dist-cjs/lib/utils/hardResetEditor.js +0 -28
  144. package/dist-cjs/lib/utils/hardResetEditor.js.map +0 -7
  145. package/dist-cjs/lib/utils/refreshPage.js +0 -28
  146. package/dist-cjs/lib/utils/refreshPage.js.map +0 -7
  147. package/dist-cjs/lib/utils/window-open.js +0 -28
  148. package/dist-cjs/lib/utils/window-open.js.map +0 -7
  149. package/dist-esm/lib/utils/hardResetEditor.mjs +0 -8
  150. package/dist-esm/lib/utils/hardResetEditor.mjs.map +0 -7
  151. package/dist-esm/lib/utils/refreshPage.mjs +0 -8
  152. package/dist-esm/lib/utils/refreshPage.mjs.map +0 -7
  153. package/dist-esm/lib/utils/window-open.mjs +0 -8
  154. package/dist-esm/lib/utils/window-open.mjs.map +0 -7
  155. package/src/lib/utils/hardResetEditor.ts +0 -6
  156. package/src/lib/utils/refreshPage.ts +0 -6
  157. package/src/lib/utils/window-open.ts +0 -16
@@ -16,6 +16,7 @@ import { useGestureEvents } from '../../hooks/useGestureEvents'
16
16
  import { useHandleEvents } from '../../hooks/useHandleEvents'
17
17
  import { useSharedSafeId } from '../../hooks/useSafeId'
18
18
  import { useScreenBounds } from '../../hooks/useScreenBounds'
19
+ import { ShapeCullingProvider, useShapeCulling } from '../../hooks/useShapeCulling'
19
20
  import { Box } from '../../primitives/Box'
20
21
  import { Mat } from '../../primitives/Mat'
21
22
  import { Vec } from '../../primitives/Vec'
@@ -428,18 +429,39 @@ function ReflowIfNeeded() {
428
429
  return null
429
430
  }
430
431
 
432
+ /**
433
+ * Centralized culling controller that updates shape container visibility.
434
+ * This single reactor replaces per-shape subscriptions for O(1) instead of O(N) subscriptions.
435
+ */
436
+ function CullingController() {
437
+ const editor = useEditor()
438
+ const { updateCulling } = useShapeCulling()
439
+
440
+ useQuickReactor(
441
+ 'update shape culling',
442
+ () => {
443
+ const culledShapes = editor.getCulledShapes()
444
+ updateCulling(culledShapes)
445
+ },
446
+ [editor, updateCulling]
447
+ )
448
+
449
+ return null
450
+ }
451
+
431
452
  function ShapesToDisplay() {
432
453
  const editor = useEditor()
433
454
 
434
455
  const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
435
456
 
436
457
  return (
437
- <>
458
+ <ShapeCullingProvider>
438
459
  {renderingShapes.map((result) => (
439
460
  <Shape key={result.id + '_shape'} {...result} />
440
461
  ))}
462
+ <CullingController />
441
463
  {tlenv.isSafari && <ReflowIfNeeded />}
442
- </>
464
+ </ShapeCullingProvider>
443
465
  )
444
466
  }
445
467
 
@@ -5,8 +5,7 @@ import { ComponentType, useEffect, useLayoutEffect, useRef, useState } from 'rea
5
5
  import { Editor } from '../../editor/Editor'
6
6
  import { EditorProvider } from '../../hooks/useEditor'
7
7
  import { useEditorComponents } from '../../hooks/useEditorComponents'
8
- import { hardResetEditor } from '../../utils/hardResetEditor'
9
- import { refreshPage } from '../../utils/refreshPage'
8
+ import { hardResetEditor, refreshPage } from '../../utils/runtime'
10
9
  import { ErrorBoundary } from '../ErrorBoundary'
11
10
 
12
11
  const BASE_ERROR_URL = 'https://github.com/tldraw/tldraw/issues/new'
@@ -153,7 +153,13 @@ import { SpatialIndexManager } from './managers/SpatialIndexManager/SpatialIndex
153
153
  import { TextManager } from './managers/TextManager/TextManager'
154
154
  import { TickManager } from './managers/TickManager/TickManager'
155
155
  import { UserPreferencesManager } from './managers/UserPreferencesManager/UserPreferencesManager'
156
- import { ShapeUtil, TLEditStartInfo, TLGeometryOpts, TLResizeMode } from './shapes/ShapeUtil'
156
+ import {
157
+ ShapeUtil,
158
+ TLEditStartInfo,
159
+ TLGeometryOpts,
160
+ TLResizeMode,
161
+ TLShapeUtilCanBindOpts,
162
+ } from './shapes/ShapeUtil'
157
163
  import { RootState } from './tools/RootState'
158
164
  import { StateNode, TLStateNodeConstructor } from './tools/StateNode'
159
165
  import { TLContent } from './types/clipboard-types'
@@ -228,10 +234,17 @@ export interface TLEditorOptions {
228
234
  inferDarkMode?: boolean
229
235
  /**
230
236
  * Options for the editor's camera.
237
+ *
238
+ * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
231
239
  */
232
240
  cameraOptions?: Partial<TLCameraOptions>
233
- textOptions?: TLTextOptions
234
241
  options?: Partial<TldrawOptions>
242
+ /**
243
+ * Text options for the editor.
244
+ *
245
+ * @deprecated Use `options.text` instead. This prop will be removed in a future release.
246
+ */
247
+ textOptions?: TLTextOptions
235
248
  licenseKey?: string
236
249
  fontAssetUrls?: { [key: string]: string | undefined }
237
250
  /**
@@ -283,12 +296,16 @@ export class Editor extends EventEmitter<TLEventMap> {
283
296
  bindingUtils,
284
297
  tools,
285
298
  getContainer,
299
+ // needs to be here for backwards compatibility with TldrawEditor
300
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
286
301
  cameraOptions,
287
- textOptions,
288
302
  initialState,
289
303
  autoFocus,
290
304
  inferDarkMode,
291
- options,
305
+ options: _options,
306
+ // needs to be here for backwards compatibility with TldrawEditor
307
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
308
+ textOptions: _textOptions,
292
309
  getShapeVisibility,
293
310
  fontAssetUrls,
294
311
  }: TLEditorOptions) {
@@ -296,6 +313,10 @@ export class Editor extends EventEmitter<TLEventMap> {
296
313
 
297
314
  this._getShapeVisibility = getShapeVisibility
298
315
 
316
+ // Merge deprecated textOptions prop with options.text
317
+ // options.text takes precedence over the deprecated textOptions prop
318
+ const options = _textOptions ? { ..._options, text: _options?.text ?? _textOptions } : _options
319
+
299
320
  this.options = { ...defaultTldrawOptions, ...options }
300
321
 
301
322
  this.store = store
@@ -314,9 +335,14 @@ export class Editor extends EventEmitter<TLEventMap> {
314
335
 
315
336
  this.disposables.add(this.timers.dispose)
316
337
 
317
- this._cameraOptions.set({ ...DEFAULT_CAMERA_OPTIONS, ...cameraOptions })
338
+ // Merge camera options: options.cameraOptions takes precedence over deprecated cameraOptions prop
339
+ this._cameraOptions.set({
340
+ ...DEFAULT_CAMERA_OPTIONS,
341
+ ...cameraOptions,
342
+ ...options?.camera,
343
+ })
318
344
 
319
- this._textOptions = atom('text options', textOptions ?? null)
345
+ this._textOptions = atom('text options', options?.text ?? null)
320
346
 
321
347
  this.user = new UserPreferencesManager(user ?? createTLUser(), inferDarkMode ?? false)
322
348
  this.disposables.add(() => this.user.dispose())
@@ -795,6 +821,7 @@ export class Editor extends EventEmitter<TLEventMap> {
795
821
  }
796
822
 
797
823
  private readonly _getShapeVisibility?: TLEditorOptions['getShapeVisibility']
824
+
798
825
  @computed
799
826
  private getIsShapeHiddenCache() {
800
827
  if (!this._getShapeVisibility) return null
@@ -5484,7 +5511,7 @@ export class Editor extends EventEmitter<TLEventMap> {
5484
5511
  * @param bounds - The bounds to search within.
5485
5512
  * @returns Unordered set of shape IDs within the given bounds.
5486
5513
  *
5487
- * @internal
5514
+ * @public
5488
5515
  */
5489
5516
  getShapeIdsInsideBounds(bounds: Box): Set<TLShapeId> {
5490
5517
  return this._spatialIndex.getShapeIdsInsideBounds(bounds)
@@ -6249,7 +6276,13 @@ export class Editor extends EventEmitter<TLEventMap> {
6249
6276
  const toShapeType = typeof toShape === 'string' ? toShape : toShape.type
6250
6277
  const bindingType = typeof binding === 'string' ? binding : binding.type
6251
6278
 
6252
- const canBindOpts = { fromShapeType, toShapeType, bindingType } as const
6279
+ const canBindOpts: TLShapeUtilCanBindOpts = {
6280
+ fromShape: typeof fromShape === 'string' ? { type: fromShape } : fromShape,
6281
+ toShape: typeof toShape === 'string' ? { type: toShape } : toShape,
6282
+ bindingType,
6283
+ fromShapeType,
6284
+ toShapeType,
6285
+ }
6253
6286
 
6254
6287
  if (fromShapeType === toShapeType) {
6255
6288
  return this.getShapeUtil(fromShapeType).canBind(canBindOpts)
@@ -7842,6 +7875,7 @@ export class Editor extends EventEmitter<TLEventMap> {
7842
7875
  initialShape: options.initialShape,
7843
7876
  initialBounds: options.initialBounds,
7844
7877
  isAspectRatioLocked: options.isAspectRatioLocked,
7878
+ initialPageTransform: options.initialPageTransform,
7845
7879
  })
7846
7880
 
7847
7881
  // then if the shape is flipped in one axis only, we need to apply an extra rotation
@@ -1,5 +1,5 @@
1
1
  import { computed, isUninitialized } from '@tldraw/state'
2
- import { TLShapeId } from '@tldraw/tlschema'
2
+ import { TLShape, TLShapeId } from '@tldraw/tlschema'
3
3
  import { Editor } from '../Editor'
4
4
 
5
5
  /**
@@ -9,34 +9,56 @@ import { Editor } from '../Editor'
9
9
  * @returns Incremental derivation of non visible shapes.
10
10
  */
11
11
  export function notVisibleShapes(editor: Editor) {
12
+ const emptySet = new Set<TLShapeId>()
13
+
12
14
  return computed<Set<TLShapeId>>('notVisibleShapes', function (prevValue) {
13
- const allShapeIds = editor.getCurrentPageShapeIds()
15
+ const allShapes = editor.getCurrentPageShapes()
14
16
  const viewportPageBounds = editor.getViewportPageBounds()
15
17
  const visibleIds = editor.getShapeIdsInsideBounds(viewportPageBounds)
16
18
 
17
- const nextValue = new Set<TLShapeId>()
18
-
19
- // Non-visible shapes are all shapes minus visible shapes
20
- for (const id of allShapeIds) {
21
- if (!visibleIds.has(id)) {
22
- const shape = editor.getShape(id)
23
- if (!shape) continue
19
+ let shape: TLShape | undefined
24
20
 
25
- const canCull = editor.getShapeUtil(shape.type).canCull(shape)
26
- if (!canCull) continue
27
-
28
- nextValue.add(id)
21
+ // Fast path: if all shapes are visible, return empty set
22
+ if (visibleIds.size === allShapes.length) {
23
+ if (isUninitialized(prevValue) || prevValue.size > 0) {
24
+ return emptySet
29
25
  }
26
+ return prevValue
30
27
  }
31
28
 
32
- if (isUninitialized(prevValue) || prevValue.size !== nextValue.size) {
29
+ // First run: compute from scratch
30
+ if (isUninitialized(prevValue)) {
31
+ const nextValue = new Set<TLShapeId>()
32
+ for (let i = 0; i < allShapes.length; i++) {
33
+ shape = allShapes[i]
34
+ if (visibleIds.has(shape.id)) continue
35
+ if (!editor.getShapeUtil(shape.type).canCull(shape)) continue
36
+ nextValue.add(shape.id)
37
+ }
33
38
  return nextValue
34
39
  }
35
40
 
36
- for (const prev of prevValue) {
37
- if (!nextValue.has(prev)) return nextValue
41
+ // Subsequent runs: single pass to collect IDs and detect changes
42
+ const notVisibleIds: TLShapeId[] = []
43
+ for (let i = 0; i < allShapes.length; i++) {
44
+ shape = allShapes[i]
45
+ if (visibleIds.has(shape.id)) continue
46
+ if (!editor.getShapeUtil(shape.type).canCull(shape)) continue
47
+ notVisibleIds.push(shape.id)
48
+ }
49
+
50
+ // Check if the result changed
51
+ if (notVisibleIds.length === prevValue.size) {
52
+ let same = true
53
+ for (let i = 0; i < notVisibleIds.length; i++) {
54
+ if (!prevValue.has(notVisibleIds[i])) {
55
+ same = false
56
+ break
57
+ }
58
+ }
59
+ if (same) return prevValue
38
60
  }
39
61
 
40
- return prevValue
62
+ return new Set(notVisibleIds)
41
63
  })
42
64
  }
@@ -240,41 +240,6 @@ describe('EdgeScrollManager', () => {
240
240
  })
241
241
  })
242
242
 
243
- describe('camera movement conditions', () => {
244
- it('should not move camera when not dragging', () => {
245
- editor.inputs.setIsDragging(false)
246
- mockInputs.setCurrentScreenPoint(new Vec(5, 300))
247
-
248
- edgeScrollManager.updateEdgeScrolling(300)
249
-
250
- expect(editor.setCamera).not.toHaveBeenCalled()
251
- })
252
-
253
- it('should not move camera when panning', () => {
254
- editor.inputs.setIsPanning(true)
255
- mockInputs.setCurrentScreenPoint(new Vec(5, 300))
256
-
257
- edgeScrollManager.updateEdgeScrolling(300)
258
-
259
- expect(editor.setCamera).not.toHaveBeenCalled()
260
- })
261
-
262
- it('should not move camera when camera is locked', () => {
263
- editor.getCameraOptions.mockReturnValue({
264
- isLocked: true,
265
- panSpeed: 1,
266
- zoomSpeed: 1,
267
- zoomSteps: [1],
268
- wheelBehavior: 'pan' as const,
269
- })
270
- mockInputs.setCurrentScreenPoint(new Vec(5, 300))
271
-
272
- edgeScrollManager.updateEdgeScrolling(300)
273
-
274
- expect(editor.setCamera).not.toHaveBeenCalled()
275
- })
276
- })
277
-
278
243
  describe('camera movement calculation', () => {
279
244
  it('should calculate scroll speed based on user preference', () => {
280
245
  editor.user.getEdgeScrollSpeed.mockReturnValue(2)
@@ -21,6 +21,9 @@ export class EdgeScrollManager {
21
21
  */
22
22
  updateEdgeScrolling(elapsed: number) {
23
23
  const { editor } = this
24
+
25
+ if (editor.getCameraOptions().isLocked) return
26
+
24
27
  const edgeScrollProximityFactor = this.getEdgeScroll()
25
28
  if (edgeScrollProximityFactor.x === 0 && edgeScrollProximityFactor.y === 0) {
26
29
  if (this._isEdgeScrolling) {
@@ -106,15 +109,8 @@ export class EdgeScrollManager {
106
109
  * @public
107
110
  */
108
111
  private moveCameraWhenCloseToEdge(proximityFactor: { x: number; y: number }) {
109
- const { editor } = this
110
- if (
111
- !editor.inputs.getIsDragging() ||
112
- editor.inputs.getIsPanning() ||
113
- editor.getCameraOptions().isLocked
114
- )
115
- return
116
-
117
112
  if (proximityFactor.x === 0 && proximityFactor.y === 0) return
113
+ const { editor } = this
118
114
 
119
115
  const screenBounds = editor.getViewportScreenBounds()
120
116
 
@@ -35,17 +35,31 @@ export interface TLShapeUtilConstructor<T extends TLShape, U extends ShapeUtil<T
35
35
 
36
36
  /**
37
37
  * Options passed to {@link ShapeUtil.canBind}. A binding that could be made. At least one of
38
- * `fromShapeType` or `toShapeType` will belong to this shape util.
38
+ * `fromShape` or `toShape` will belong to this shape util.
39
+ *
40
+ * The shapes may be full {@link @tldraw/tlschema#TLShape} objects when available, or just
41
+ * `{ type }` stubs when the shape hasn't been created yet (e.g. during arrow creation). Use
42
+ * `'id' in shape` to check whether the full shape is available.
39
43
  *
40
44
  * @public
41
45
  */
42
46
  export interface TLShapeUtilCanBindOpts<Shape extends TLShape = TLShape> {
43
- /** The type of shape referenced by the `fromId` of the binding. */
44
- fromShapeType: TLShape['type']
45
- /** The type of shape referenced by the `toId` of the binding. */
46
- toShapeType: TLShape['type']
47
+ /** The shape referenced by the `fromId` of the binding, or a `{ type }` stub if unavailable. */
48
+ fromShape: TLShape | { type: TLShape['type'] }
49
+ /** The shape referenced by the `toId` of the binding, or a `{ type }` stub if unavailable. */
50
+ toShape: TLShape | { type: TLShape['type'] }
47
51
  /** The type of binding. */
48
52
  bindingType: string
53
+ /**
54
+ * The type of shape referenced by the `fromId` of the binding.
55
+ * @deprecated Use `fromShape.type` instead.
56
+ */
57
+ fromShapeType: TLShape['type']
58
+ /**
59
+ * The type of shape referenced by the `toId` of the binding.
60
+ * @deprecated Use `toShape.type` instead.
61
+ */
62
+ toShapeType: TLShape['type']
49
63
  }
50
64
 
51
65
  /**
@@ -102,13 +102,24 @@ export function useCanvasEvents() {
102
102
  preventDefault(e)
103
103
  e.stopPropagation()
104
104
 
105
+ const pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY })
106
+
107
+ // Call the custom onDropOnCanvas callback if provided
108
+ if (editor.options.experimental__onDropOnCanvas) {
109
+ const handled = editor.options.experimental__onDropOnCanvas({
110
+ point: pagePoint,
111
+ event: e,
112
+ })
113
+ if (handled) return
114
+ }
115
+
105
116
  if (e.dataTransfer?.files?.length) {
106
117
  const files = Array.from(e.dataTransfer.files)
107
118
 
108
119
  await editor.putExternalContent({
109
120
  type: 'files',
110
121
  files,
111
- point: editor.screenToPage({ x: e.clientX, y: e.clientY }),
122
+ point: pagePoint,
112
123
  })
113
124
  return
114
125
  }
@@ -118,7 +129,7 @@ export function useCanvasEvents() {
118
129
  await editor.putExternalContent({
119
130
  type: 'url',
120
131
  url,
121
- point: editor.screenToPage({ x: e.clientX, y: e.clientY }),
132
+ point: pagePoint,
122
133
  })
123
134
  return
124
135
  }
@@ -1,5 +1,4 @@
1
1
  import { useAtom, useComputed, useValue } from '@tldraw/state-react'
2
- import { isEqual } from '@tldraw/utils'
3
2
  import { useEffect } from 'react'
4
3
  import {
5
4
  getCollaboratorStateFromElapsedTime,
@@ -8,6 +7,14 @@ import {
8
7
  import { uniq } from '../utils/uniq'
9
8
  import { useEditor } from './useEditor'
10
9
 
10
+ function setsEqual<T>(a: Set<T>, b: Set<T>): boolean {
11
+ if (a.size !== b.size) return false
12
+ for (const item of a) {
13
+ if (!b.has(item)) return false
14
+ }
15
+ return true
16
+ }
17
+
11
18
  // TODO: maybe move this to a computed property on the App class?
12
19
  /**
13
20
  * @returns The list of peer UserIDs
@@ -60,7 +67,7 @@ export function useActivePeerIds$() {
60
67
  .map((p) => p.userId)
61
68
  )
62
69
  },
63
- { isEqual },
70
+ { isEqual: setsEqual },
64
71
  [editor]
65
72
  )
66
73
  }
@@ -0,0 +1,98 @@
1
+ import { TLShapeId } from '@tldraw/tlschema'
2
+ import { createContext, useCallback, useContext, useMemo, useRef } from 'react'
3
+ import { setStyleProperty } from '../utils/dom'
4
+
5
+ interface ShapeContainerEntry {
6
+ container: HTMLDivElement
7
+ bgContainer: HTMLDivElement | null
8
+ isCulled: boolean
9
+ }
10
+
11
+ interface ShapeCullingContextValue {
12
+ register(
13
+ id: TLShapeId,
14
+ container: HTMLDivElement,
15
+ bgContainer: HTMLDivElement | null,
16
+ isCulled: boolean
17
+ ): void
18
+ unregister(id: TLShapeId): void
19
+ updateCulling(culledShapes: Set<TLShapeId>): void
20
+ }
21
+
22
+ const ShapeCullingContext = createContext<ShapeCullingContextValue | null>(null)
23
+
24
+ /** @internal */
25
+ export interface ShapeCullingProviderProps {
26
+ children: React.ReactNode
27
+ }
28
+
29
+ /**
30
+ * Provides centralized culling management for shape containers.
31
+ * This allows a single reactor to update all shape display states
32
+ * instead of each shape having its own subscription.
33
+ *
34
+ * @internal
35
+ */
36
+ export function ShapeCullingProvider({ children }: ShapeCullingProviderProps) {
37
+ const containersRef = useRef(new Map<TLShapeId, ShapeContainerEntry>())
38
+
39
+ const register = useCallback(
40
+ (
41
+ id: TLShapeId,
42
+ container: HTMLDivElement,
43
+ bgContainer: HTMLDivElement | null,
44
+ isCulled: boolean
45
+ ) => {
46
+ const display = isCulled ? 'none' : 'block'
47
+ setStyleProperty(container, 'display', display)
48
+ setStyleProperty(bgContainer, 'display', display)
49
+
50
+ containersRef.current.set(id, {
51
+ container,
52
+ bgContainer,
53
+ isCulled,
54
+ })
55
+ },
56
+ []
57
+ )
58
+
59
+ const unregister = useCallback((id: TLShapeId) => {
60
+ containersRef.current.delete(id)
61
+ }, [])
62
+
63
+ const updateCulling = useCallback((culledShapes: Set<TLShapeId>) => {
64
+ for (const [id, entry] of containersRef.current) {
65
+ const shouldBeCulled = culledShapes.has(id)
66
+ if (shouldBeCulled !== entry.isCulled) {
67
+ const display = shouldBeCulled ? 'none' : 'block'
68
+ setStyleProperty(entry.container, 'display', display)
69
+ setStyleProperty(entry.bgContainer, 'display', display)
70
+ entry.isCulled = shouldBeCulled
71
+ }
72
+ }
73
+ }, [])
74
+
75
+ const value = useMemo(
76
+ () => ({
77
+ register,
78
+ unregister,
79
+ updateCulling,
80
+ }),
81
+ [register, unregister, updateCulling]
82
+ )
83
+
84
+ return <ShapeCullingContext.Provider value={value}>{children}</ShapeCullingContext.Provider>
85
+ }
86
+
87
+ /**
88
+ * Hook to access the shape culling context for container registration.
89
+ *
90
+ * @internal
91
+ */
92
+ export function useShapeCulling(): ShapeCullingContextValue {
93
+ const context = useContext(ShapeCullingContext)
94
+ if (!context) {
95
+ throw new Error('useShapeCulling must be used within ShapeCullingProvider')
96
+ }
97
+ return context
98
+ }
@@ -431,25 +431,25 @@ export class LicenseManager {
431
431
  private outputMessages(messages: string[], type: 'warning' | 'error' = 'error') {
432
432
  if (this.isTest) return
433
433
  if (this.verbose) {
434
- this.outputDelimiter()
434
+ this.outputDelimiter(type)
435
435
  for (const message of messages) {
436
- const color = type === 'warning' ? 'orange' : 'crimson'
437
436
  const bgColor = type === 'warning' ? 'orange' : 'crimson'
438
437
  // eslint-disable-next-line no-console
439
438
  console.log(
440
439
  `%c${message}`,
441
- `color: ${color}; background: ${bgColor}; padding: 2px; border-radius: 3px;`
440
+ `color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`
442
441
  )
443
442
  }
444
- this.outputDelimiter()
443
+ this.outputDelimiter(type)
445
444
  }
446
445
  }
447
446
 
448
- private outputDelimiter() {
447
+ private outputDelimiter(type: 'warning' | 'error' = 'error') {
448
+ const bgColor = type === 'warning' ? 'orange' : 'crimson'
449
449
  // eslint-disable-next-line no-console
450
450
  console.log(
451
451
  '%c-------------------------------------------------------------------',
452
- `color: white; background: crimson; padding: 2px; border-radius: 3px;`
452
+ `color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`
453
453
  )
454
454
  }
455
455
 
@@ -1,4 +1,9 @@
1
1
  import { ComponentType, Fragment } from 'react'
2
+ import { DEFAULT_CAMERA_OPTIONS } from './constants'
3
+ import { TLCameraOptions } from './editor/types/misc-types'
4
+ import { VecLike } from './primitives/Vec'
5
+ import { TLDeepLinkOptions } from './utils/deepLinks'
6
+ import { TLTextOptions } from './utils/richText'
2
7
 
3
8
  /**
4
9
  * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.
@@ -95,13 +100,13 @@ export interface TldrawOptions {
95
100
  readonly branding?: string
96
101
  /**
97
102
  * Whether to use debounced zoom level for certain rendering optimizations. When true,
98
- * `editor.getDebouncedZoomLevel()` returns a cached zoom value while the camera is moving,
103
+ * `editor.getEfficientZoomLevel()` returns a cached zoom value while the camera is moving,
99
104
  * reducing re-renders. When false, it always returns the current zoom level.
100
105
  */
101
106
  readonly debouncedZoom: boolean
102
107
  /**
103
108
  * The number of shapes that must be on the page for the debounced zoom level to be used.
104
- * Defaults to 300 shapes.
109
+ * Defaults to 500 shapes.
105
110
  */
106
111
  readonly debouncedZoomThreshold: number
107
112
  /**
@@ -120,6 +125,46 @@ export interface TldrawOptions {
120
125
  * The distance (in screen pixels) at which shapes snap to guides and other shapes.
121
126
  */
122
127
  readonly snapThreshold: number
128
+ /**
129
+ * Options for the editor's camera. These are the initial camera options.
130
+ * Use {@link Editor.setCameraOptions} to update camera options at runtime.
131
+ */
132
+ readonly camera: Partial<TLCameraOptions>
133
+ /**
134
+ * Options for the editor's text rendering. These include TipTap configuration and
135
+ * font handling. These are the initial text options and cannot be changed at runtime.
136
+ */
137
+ readonly text: TLTextOptions
138
+ /**
139
+ * Options for syncing the editor's camera state with the URL. Set to `true` to enable
140
+ * with default options, or pass an options object to customize behavior.
141
+ *
142
+ * @example
143
+ * ```tsx
144
+ * // Enable with defaults
145
+ * <Tldraw options={{ deepLinks: true }} />
146
+ *
147
+ * // Enable with custom options
148
+ * <Tldraw options={{ deepLinks: { param: 'd', debounceMs: 500 } }} />
149
+ * ```
150
+ */
151
+ readonly deepLinks: true | TLDeepLinkOptions | undefined
152
+ /**
153
+ * Whether the quick-zoom brush preserves its screen-pixel size when the user
154
+ * zooms the overview. When true, zooming in shrinks the target viewport (higher
155
+ * return zoom); zooming out expands it. When false, the brush keeps the original
156
+ * viewport's page dimensions regardless of overview zoom changes.
157
+ */
158
+ readonly quickZoomPreservesScreenBounds: boolean
159
+ /**
160
+ * Called when content is dropped on the canvas. Provides the page position
161
+ * where the drop occurred and the underlying drag event object.
162
+ * Return true to prevent default drop handling (files, URLs, etc.)
163
+ */
164
+ experimental__onDropOnCanvas?(options: {
165
+ point: VecLike
166
+ event: React.DragEvent<Element>
167
+ }): boolean
123
168
  }
124
169
 
125
170
  /** @public */
@@ -178,4 +223,9 @@ export const defaultTldrawOptions = {
178
223
  spacebarPanning: true,
179
224
  zoomToFitPadding: 128,
180
225
  snapThreshold: 8,
226
+ camera: DEFAULT_CAMERA_OPTIONS,
227
+ text: {},
228
+ deepLinks: undefined,
229
+ quickZoomPreservesScreenBounds: true,
230
+ experimental__onDropOnCanvas: undefined,
181
231
  } as const satisfies TldrawOptions
@@ -1,4 +1,11 @@
1
1
  import { TLShape } from '@tldraw/tlschema'
2
2
 
3
- export const areShapesContentEqual = (a: TLShape, b: TLShape) =>
4
- a.props === b.props && a.meta === b.meta
3
+ /**
4
+ * Checks if two shapes are equal by comparing their props and meta.
5
+ * @param a - The first shape.
6
+ * @param b - The second shape.
7
+ * @returns True if the shapes are equal, false otherwise.
8
+ */
9
+ export function areShapesContentEqual(a: TLShape, b: TLShape) {
10
+ return a.props === b.props && a.meta === b.meta
11
+ }