@tldraw/editor 5.4.0-canary.587f42e00c65 → 5.4.0-canary.5a084792df77

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 (51) hide show
  1. package/dist-cjs/index.js +1 -1
  2. package/dist-cjs/lib/editor/Editor.js +39 -62
  3. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  4. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -3
  5. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
  6. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +1 -1
  7. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
  8. package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -0
  9. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  10. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +1 -0
  11. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  12. package/dist-cjs/lib/hooks/usePeerIds.js +2 -1
  13. package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
  14. package/dist-cjs/lib/utils/deepLinks.js +5 -1
  15. package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
  16. package/dist-cjs/lib/utils/sync/alerts.js +1 -1
  17. package/dist-cjs/lib/utils/sync/alerts.js.map +1 -1
  18. package/dist-cjs/version.js +3 -3
  19. package/dist-cjs/version.js.map +1 -1
  20. package/dist-esm/index.mjs +1 -1
  21. package/dist-esm/lib/editor/Editor.mjs +40 -62
  22. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  23. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -3
  24. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
  25. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +1 -1
  26. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
  27. package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -0
  28. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  29. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +1 -0
  30. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  31. package/dist-esm/lib/hooks/usePeerIds.mjs +2 -1
  32. package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
  33. package/dist-esm/lib/utils/deepLinks.mjs +5 -1
  34. package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
  35. package/dist-esm/lib/utils/sync/alerts.mjs +1 -1
  36. package/dist-esm/lib/utils/sync/alerts.mjs.map +1 -1
  37. package/dist-esm/version.mjs +3 -3
  38. package/dist-esm/version.mjs.map +1 -1
  39. package/package.json +7 -7
  40. package/src/lib/editor/Editor.ts +70 -87
  41. package/src/lib/editor/managers/ClickManager/ClickManager.ts +5 -3
  42. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +4 -1
  43. package/src/lib/hooks/useCanvasEvents.ts +2 -0
  44. package/src/lib/hooks/usePassThroughWheelEvents.ts +3 -0
  45. package/src/lib/hooks/usePeerIds.ts +2 -1
  46. package/src/lib/test/useCanvasEvents.test.tsx +74 -0
  47. package/src/lib/test/usePassThroughWheelEvents.test.tsx +25 -2
  48. package/src/lib/utils/deepLinks.test.ts +15 -0
  49. package/src/lib/utils/deepLinks.ts +7 -1
  50. package/src/lib/utils/sync/alerts.ts +1 -1
  51. package/src/version.ts +3 -3
@@ -72,6 +72,7 @@ import {
72
72
  Result,
73
73
  ZERO_INDEX_KEY,
74
74
  annotateError,
75
+ areArraysShallowEqual,
75
76
  assert,
76
77
  assertExists,
77
78
  bind,
@@ -552,6 +553,14 @@ export class Editor extends EventEmitter<TLEventMap> {
552
553
  nextPageState.editingShapeId = null
553
554
  }
554
555
 
556
+ if (
557
+ prevPageState.croppingShapeId &&
558
+ shapesNoLongerInPage.has(prevPageState.croppingShapeId)
559
+ ) {
560
+ if (!nextPageState) nextPageState = { ...prevPageState }
561
+ nextPageState.croppingShapeId = null
562
+ }
563
+
555
564
  const hintingShapeIds = prevPageState.hintingShapeIds.filter(
556
565
  (id) => !shapesNoLongerInPage.has(id)
557
566
  )
@@ -2808,57 +2817,38 @@ export class Editor extends EventEmitter<TLEventMap> {
2808
2817
  setEditingShape(shape: TLShapeId | TLShape | null): this {
2809
2818
  const id = typeof shape === 'string' ? shape : (shape?.id ?? null)
2810
2819
 
2811
- if (!id) {
2812
- // setting the editing shape to null
2820
+ // id was provided but the next editing shape was not editable or didn't exist, so do nothing
2821
+ if (id && !this.canEditShape(id)) return this
2822
+
2823
+ this.run(() => {
2824
+ // Clean up the previous editing shape. This runs outside the history-ignored batch below,
2825
+ // otherwise document changes made by onEditEnd (e.g. deleting an empty text shape) are
2826
+ // never recorded and leave a phantom undo entry whose redo resurrects the shape.
2827
+ const prevEditingShapeId = this.getEditingShapeId()
2828
+ if (prevEditingShapeId) {
2829
+ const prevEditingShape = this.getShape(prevEditingShapeId)
2830
+ if (prevEditingShape) {
2831
+ this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape)
2832
+ }
2833
+ }
2834
+
2813
2835
  this.run(
2814
2836
  () => {
2815
- // Clean up the previous editing shape
2816
- const prevEditingShapeId = this.getEditingShapeId()
2817
- if (prevEditingShapeId) {
2818
- const prevEditingShape = this.getShape(prevEditingShapeId)
2819
- if (prevEditingShape) {
2820
- this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape)
2821
- }
2822
- }
2823
-
2824
2837
  // Clean up the editing shape state and rich text editor
2825
2838
  this._updateCurrentPageState({ editingShapeId: null })
2826
2839
  this._currentRichTextEditor.set(null)
2827
- },
2828
- { history: 'ignore' }
2829
- )
2830
-
2831
- return this
2832
- }
2833
2840
 
2834
- // id was provided but the next editing shape was not editable or didn't exist, so do nothing
2835
- if (!this.canEditShape(id)) return this
2836
-
2837
- // id was provided and the next editing shape is editable, so set the rich text editor to null
2838
- this.run(
2839
- () => {
2840
- // Clean up the previous editing shape
2841
- const prevEditingShapeId = this.getEditingShapeId()
2842
- if (prevEditingShapeId) {
2843
- const prevEditingShape = this.getShape(prevEditingShapeId)
2844
- if (prevEditingShape) {
2845
- this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape)
2846
- }
2847
- }
2841
+ if (!id) return
2848
2842
 
2849
- // Clean up the editing shape state and rich text editor
2850
- this._updateCurrentPageState({ editingShapeId: null })
2851
- this._currentRichTextEditor.set(null)
2843
+ this.select(id)
2844
+ this._updateCurrentPageState({ editingShapeId: id })
2852
2845
 
2853
- // Set the new editing shape
2854
- this.select(id)
2855
- this._updateCurrentPageState({ editingShapeId: id })
2856
-
2857
- const nextEditingShape = this.getShape(id)! // shape should be there because canEditShape checked it. Possible small chance that onEditEnd deleted it?
2858
- this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape)
2859
- },
2860
- { history: 'ignore' }
2861
- )
2846
+ const nextEditingShape = this.getShape(id)! // shape should be there because canEditShape checked it. Possible small chance that onEditEnd deleted it?
2847
+ this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape)
2848
+ },
2849
+ { history: 'ignore' }
2850
+ )
2851
+ })
2862
2852
 
2863
2853
  return this
2864
2854
  }
@@ -3023,26 +3013,17 @@ export class Editor extends EventEmitter<TLEventMap> {
3023
3013
  * @public
3024
3014
  */
3025
3015
  setErasingShapes(shapes: TLShapeId[] | TLShape[]): this {
3016
+ // copy before sorting: the caller may pass a store-owned (frozen) array
3026
3017
  const ids =
3027
3018
  typeof shapes[0] === 'string'
3028
- ? (shapes as TLShapeId[])
3019
+ ? (shapes as TLShapeId[]).slice()
3029
3020
  : (shapes as TLShape[]).map((shape) => shape.id)
3030
3021
  ids.sort() // sort the incoming ids
3031
3022
  const erasingShapeIds = this.getErasingShapeIds()
3032
3023
  this.run(
3033
3024
  () => {
3034
- if (ids.length === erasingShapeIds.length) {
3035
- // if the new ids are the same length as the current ids, they might be the same.
3036
- // presuming the current ids are also sorted, check each item to see if it's the same;
3037
- // if we find any unequal, then we know the new ids are different.
3038
- for (let i = 0; i < ids.length; i++) {
3039
- if (ids[i] !== erasingShapeIds[i]) {
3040
- this._updateCurrentPageState({ erasingShapeIds: ids })
3041
- break
3042
- }
3043
- }
3044
- } else {
3045
- // if the ids are a different length, then we know they're different.
3025
+ // the current ids are also sorted, so a shallow comparison tells us whether they changed
3026
+ if (!areArraysShallowEqual(ids, erasingShapeIds)) {
3046
3027
  this._updateCurrentPageState({ erasingShapeIds: ids })
3047
3028
  }
3048
3029
  },
@@ -3079,6 +3060,7 @@ export class Editor extends EventEmitter<TLEventMap> {
3079
3060
  if (!_shape) return false
3080
3061
  const util = this.getShapeUtil(_shape)
3081
3062
  if (!util.canCrop(_shape)) return false
3063
+ if (this.getIsReadonly()) return false
3082
3064
  if (this.isShapeOrAncestorLocked(_shape)) return false
3083
3065
  return true
3084
3066
  }
@@ -3367,7 +3349,9 @@ export class Editor extends EventEmitter<TLEventMap> {
3367
3349
  ...this._cameraOptions.__unsafe__getWithoutCapture(),
3368
3350
  ...opts,
3369
3351
  })
3370
- if (next.zoomSteps?.length < 1) next.zoomSteps = [1]
3352
+ // `undefined < 1` is false, so an explicit `zoomSteps: undefined` would otherwise get through
3353
+ // and make every later camera move throw
3354
+ if (!next.zoomSteps || next.zoomSteps.length < 1) next.zoomSteps = [1]
3371
3355
  this._cameraOptions.set(next)
3372
3356
  this.setCamera(this.getCamera())
3373
3357
  return this
@@ -3413,8 +3397,8 @@ export class Editor extends EventEmitter<TLEventMap> {
3413
3397
  const { constraints } = cameraOptions
3414
3398
 
3415
3399
  // Clamp padding to half the viewport size on either dimension
3416
- const py = Math.min(constraints.padding.y, vsb.w / 2)
3417
- const px = Math.min(constraints.padding.x, vsb.h / 2)
3400
+ const px = Math.min(constraints.padding.x, vsb.w / 2)
3401
+ const py = Math.min(constraints.padding.y, vsb.h / 2)
3418
3402
 
3419
3403
  // Expand the bounds by the padding
3420
3404
  const bounds = Box.From(cameraOptions.constraints.bounds)
@@ -3483,14 +3467,14 @@ export class Editor extends EventEmitter<TLEventMap> {
3483
3467
  }
3484
3468
  case 'inside': {
3485
3469
  // When below fit zoom, constrain the camera so that the bounds stay completely within the viewport
3486
- if (z < zx) x = clamp(x, minX, (vsb.w - px) / z - bounds.w)
3470
+ if (z < zx) x = clamp(x, minX, (vsb.w - px) / z - bounds.w - bounds.x)
3487
3471
  // When above fit zoom, keep the bounds within padding distance of the viewport edge
3488
3472
  else x = clamp(x, minX + freeW, minX)
3489
3473
  break
3490
3474
  }
3491
3475
  case 'outside': {
3492
3476
  // Constrain the camera so that the bounds never leaves the viewport
3493
- x = clamp(x, px / z - bounds.w, (vsb.w - px) / z)
3477
+ x = clamp(x, px / z - bounds.w - bounds.x, (vsb.w - px) / z - bounds.x)
3494
3478
  break
3495
3479
  }
3496
3480
  case 'free': {
@@ -3515,12 +3499,12 @@ export class Editor extends EventEmitter<TLEventMap> {
3515
3499
  break
3516
3500
  }
3517
3501
  case 'inside': {
3518
- if (z < zy) y = clamp(y, minY, (vsb.h - py) / z - bounds.h)
3502
+ if (z < zy) y = clamp(y, minY, (vsb.h - py) / z - bounds.h - bounds.y)
3519
3503
  else y = clamp(y, minY + freeH, minY)
3520
3504
  break
3521
3505
  }
3522
3506
  case 'outside': {
3523
- y = clamp(y, py / z - bounds.h, (vsb.h - py) / z)
3507
+ y = clamp(y, py / z - bounds.h - bounds.y, (vsb.h - py) / z - bounds.y)
3524
3508
  break
3525
3509
  }
3526
3510
  case 'free': {
@@ -5599,7 +5583,13 @@ export class Editor extends EventEmitter<TLEventMap> {
5599
5583
  if (pageMask) {
5600
5584
  if (pageMask.length === 0) return undefined
5601
5585
  const { corners } = pageBounds
5602
- if (corners.every((p, i) => p && Vec.Equals(p, pageMask[i]))) return pageBounds.clone()
5586
+ // the mask may have fewer than four points (e.g. a triangular clip path)
5587
+ if (
5588
+ pageMask.length === corners.length &&
5589
+ corners.every((p, i) => Vec.Equals(p, pageMask[i]))
5590
+ ) {
5591
+ return pageBounds.clone()
5592
+ }
5603
5593
  const intersection = intersectPolygonPolygon(pageMask, corners)
5604
5594
  if (!intersection) return
5605
5595
  return Box.FromPoints(intersection)
@@ -5927,17 +5917,19 @@ export class Editor extends EventEmitter<TLEventMap> {
5927
5917
 
5928
5918
  const pointInShapeSpace = this.getPointInShapeSpace(shape, point)
5929
5919
 
5930
- // Check labels first
5920
+ // Check labels first. Only group geometries can carry a label child; a frame-like
5921
+ // shape util may still return a plain geometry.
5931
5922
  const shapeUtil = this.getShapeUtil(shape)
5932
5923
  const isShapeFrameLike = this.isShapeFrameLike(shape)
5933
5924
  if (
5934
- isShapeFrameLike ||
5935
- ((this.isShapeOfType(shape, 'note') ||
5936
- this.isShapeOfType(shape, 'arrow') ||
5937
- (this.isShapeOfType(shape, 'geo') && shape.props.fill === 'none')) &&
5938
- shapeUtil.getText(shape)?.trim())
5925
+ isGroup &&
5926
+ (isShapeFrameLike ||
5927
+ ((this.isShapeOfType(shape, 'note') ||
5928
+ this.isShapeOfType(shape, 'arrow') ||
5929
+ (this.isShapeOfType(shape, 'geo') && shape.props.fill === 'none')) &&
5930
+ shapeUtil.getText(shape)?.trim()))
5939
5931
  ) {
5940
- for (const childGeometry of (geometry as Group2d).children) {
5932
+ for (const childGeometry of geometry.children) {
5941
5933
  if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
5942
5934
  return shape
5943
5935
  }
@@ -7246,27 +7238,17 @@ export class Editor extends EventEmitter<TLEventMap> {
7246
7238
 
7247
7239
  if (this.getIsReadonly() || ids.length === 0) return this
7248
7240
 
7249
- let allLocked = true,
7250
- allUnlocked = true
7241
+ let allLocked = true
7251
7242
  const shapesToToggle: TLShape[] = []
7252
7243
  for (const id of ids) {
7253
7244
  const shape = this.getShape(id)
7254
7245
  if (shape) {
7255
7246
  shapesToToggle.push(shape)
7256
- if (shape.isLocked) {
7257
- allUnlocked = false
7258
- } else {
7259
- allLocked = false
7260
- }
7247
+ if (!shape.isLocked) allLocked = false
7261
7248
  }
7262
7249
  }
7263
7250
  this.run(() => {
7264
- if (allUnlocked) {
7265
- this.updateShapes(
7266
- shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
7267
- )
7268
- this.setSelectedShapes([])
7269
- } else if (allLocked) {
7251
+ if (allLocked) {
7270
7252
  this.updateShapes(
7271
7253
  shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: false }))
7272
7254
  )
@@ -7274,6 +7256,7 @@ export class Editor extends EventEmitter<TLEventMap> {
7274
7256
  this.updateShapes(
7275
7257
  shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
7276
7258
  )
7259
+ this.setSelectedShapes([])
7277
7260
  }
7278
7261
  })
7279
7262
 
@@ -11767,10 +11750,10 @@ function withIsolatedShapes<T>(
11767
11750
 
11768
11751
  function getCameraFitXFitY(editor: Editor, cameraOptions: TLCameraOptions) {
11769
11752
  if (!cameraOptions.constraints) throw Error('Should have constraints here')
11770
- const {
11771
- padding: { x: px, y: py },
11772
- } = cameraOptions.constraints
11773
11753
  const vsb = editor.getViewportScreenBounds()
11754
+ // Clamp padding to half the viewport size on either dimension, as getConstrainedCamera does
11755
+ const px = Math.min(cameraOptions.constraints.padding.x, vsb.w / 2)
11756
+ const py = Math.min(cameraOptions.constraints.padding.y, vsb.h / 2)
11774
11757
  const bounds = Box.From(cameraOptions.constraints.bounds)
11775
11758
  const zx = (vsb.w - px * 2) / bounds.w
11776
11759
  const zy = (vsb.h - py * 2) / bounds.h
@@ -94,7 +94,7 @@ export class ClickManager {
94
94
  switch (this._clickState) {
95
95
  case 'pendingDouble': {
96
96
  this._clickState = 'pendingOverflow'
97
- this._clickTimeout = this._getClickTimeout(this._clickState)
97
+ this._getClickTimeout(this._clickState)
98
98
  return {
99
99
  ...info,
100
100
  type: 'click',
@@ -114,7 +114,7 @@ export class ClickManager {
114
114
  // overflow
115
115
  }
116
116
  }
117
- this._clickTimeout = this._getClickTimeout(this._clickState)
117
+ this._getClickTimeout(this._clickState)
118
118
  return info
119
119
  }
120
120
  case 'pointer_up': {
@@ -141,10 +141,12 @@ export class ClickManager {
141
141
  return info
142
142
  }
143
143
  case 'pointer_move': {
144
+ // Compare in client coordinates like _clickScreenPoint; the container-relative
145
+ // inputs screen point would add the container offset and cancel on any movement.
144
146
  if (
145
147
  this._clickState !== 'idle' &&
146
148
  this._clickScreenPoint &&
147
- Vec.Dist2(this._clickScreenPoint, this.editor.inputs.getCurrentScreenPoint()) >
149
+ Vec.Dist2(this._clickScreenPoint, info.point) >
148
150
  (this.editor.getInstanceState().isCoarsePointer
149
151
  ? this.editor.options.coarseDragDistanceSquared
150
152
  : this.editor.options.dragDistanceSquared)
@@ -75,7 +75,10 @@ export class Pointing extends StateNode {
75
75
  }
76
76
 
77
77
  override onComplete() {
78
- this.complete()
78
+ // `complete` arrives mid-press from undo, menus opening, page changes, and focus loss,
79
+ // none of which is a release; committing here would drop a default-size shape the user
80
+ // never asked for. Match the text and arrow tools and leave nothing behind.
81
+ this.cancel()
79
82
  }
80
83
 
81
84
  override onInterrupt() {
@@ -153,6 +153,7 @@ export function useCanvasEvents() {
153
153
  if (e.dataTransfer?.files?.length) {
154
154
  const files = Array.from(e.dataTransfer.files)
155
155
 
156
+ editor.markHistoryStoppingPoint('drop')
156
157
  await editor.putExternalContent({
157
158
  type: 'files',
158
159
  files,
@@ -163,6 +164,7 @@ export function useCanvasEvents() {
163
164
 
164
165
  const url = e.dataTransfer.getData('url')
165
166
  if (url) {
167
+ editor.markHistoryStoppingPoint('drop')
166
168
  await editor.putExternalContent({
167
169
  type: 'url',
168
170
  url,
@@ -70,6 +70,9 @@ export function usePassThroughWheelEvents(ref: RefObject<HTMLElement | null>) {
70
70
  const newEvent = new WheelEvent('wheel', e as any)
71
71
  ;(newEvent as any).isSpecialRedispatchedEvent = true
72
72
  cvs.dispatchEvent(newEvent)
73
+ // Flag the original too: it keeps bubbling, and an enclosing pass-through root (the
74
+ // navigation panel around the minimap) would otherwise redispatch it a second time.
75
+ ;(e as any).isSpecialRedispatchedEvent = true
73
76
  })
74
77
 
75
78
  // The element the listener is currently on, which isn't necessarily `ref.current`: a `RefObject`
@@ -1,4 +1,5 @@
1
1
  import { useComputed, useValue } from '@tldraw/state-react'
2
+ import { areArraysShallowEqual } from '@tldraw/utils'
2
3
  import { uniq } from '../utils/uniq'
3
4
  import { useEditor } from './useEditor'
4
5
 
@@ -17,7 +18,7 @@ export function usePeerIds() {
17
18
  const $userIds = useComputed(
18
19
  'userIds',
19
20
  () => uniq(editor.getVisibleCollaborators().map((p) => p.userId)).sort(),
20
- { isEqual: (a, b) => a.join(',') === b.join?.(',') },
21
+ { isEqual: areArraysShallowEqual },
21
22
  [editor]
22
23
  )
23
24
 
@@ -0,0 +1,74 @@
1
+ import { act, render } from '@testing-library/react'
2
+ import { Editor } from '../editor/Editor'
3
+ import { TldrawEditor } from '../TldrawEditor'
4
+
5
+ function dropEvent(dataTransfer: { files: File[]; getData(type: string): string }) {
6
+ const event = new Event('drop', { bubbles: true, cancelable: true })
7
+ Object.defineProperty(event, 'dataTransfer', { value: dataTransfer })
8
+ return event
9
+ }
10
+
11
+ describe('useCanvasEvents drop handling', () => {
12
+ let editor: Editor
13
+ let canvas: HTMLElement
14
+
15
+ beforeEach(async () => {
16
+ await act(async () => {
17
+ render(
18
+ <TldrawEditor
19
+ shapeUtils={[]}
20
+ bindingUtils={[]}
21
+ onMount={(e) => {
22
+ editor = e
23
+ }}
24
+ />
25
+ )
26
+ })
27
+ canvas = document.querySelector('[data-testid="canvas"]') as HTMLElement
28
+
29
+ // Stand-ins for the default handlers: any undoable change will do.
30
+ editor.registerExternalContentHandler('files', async () => {
31
+ editor.createPage({ name: 'dropped' })
32
+ })
33
+ editor.registerExternalContentHandler('url', async () => {
34
+ editor.createPage({ name: 'dropped' })
35
+ })
36
+
37
+ // An unmarked change before the drop, like a stroke the user just drew.
38
+ editor.createPage({ name: 'before drop' })
39
+ })
40
+
41
+ afterEach(() => {
42
+ editor?.dispose()
43
+ })
44
+
45
+ function pageNames() {
46
+ return editor.getPages().map((p) => p.name)
47
+ }
48
+
49
+ it('makes a dropped file its own undo step', async () => {
50
+ await act(async () => {
51
+ canvas.dispatchEvent(
52
+ dropEvent({ files: [new File(['x'], 'x.png', { type: 'image/png' })], getData: () => '' })
53
+ )
54
+ })
55
+ expect(pageNames()).toEqual(['Page 1', 'before drop', 'dropped'])
56
+
57
+ editor.undo()
58
+
59
+ expect(pageNames()).toEqual(['Page 1', 'before drop'])
60
+ })
61
+
62
+ it('makes a dropped url its own undo step', async () => {
63
+ await act(async () => {
64
+ canvas.dispatchEvent(
65
+ dropEvent({ files: [], getData: (type) => (type === 'url' ? 'https://example.com' : '') })
66
+ )
67
+ })
68
+ expect(pageNames()).toEqual(['Page 1', 'before drop', 'dropped'])
69
+
70
+ editor.undo()
71
+
72
+ expect(pageNames()).toEqual(['Page 1', 'before drop'])
73
+ })
74
+ })
@@ -22,11 +22,27 @@ function Culled() {
22
22
  return <button ref={ref} data-testid="marker" />
23
23
  }
24
24
 
25
+ /**
26
+ * The shape the navigation panel has: a pass-through root wrapping another pass-through root (the
27
+ * minimap).
28
+ */
29
+ function Nested() {
30
+ const outer = useRef<HTMLDivElement>(null)
31
+ const inner = useRef<HTMLButtonElement>(null)
32
+ usePassThroughWheelEvents(outer)
33
+ usePassThroughWheelEvents(inner)
34
+ return (
35
+ <div ref={outer}>
36
+ <button ref={inner} data-testid="marker" />
37
+ </div>
38
+ )
39
+ }
40
+
25
41
  describe('usePassThroughWheelEvents', () => {
26
- async function renderEditor() {
42
+ async function renderEditor(InFrontOfTheCanvas = Culled) {
27
43
  const store = createTLStore({ shapeUtils: [], bindingUtils: [] })
28
44
  await act(async () => {
29
- render(<TldrawEditor store={store} components={{ InFrontOfTheCanvas: Culled }} />)
45
+ render(<TldrawEditor store={store} components={{ InFrontOfTheCanvas }} />)
30
46
  })
31
47
  return document.querySelector(`.${TL_CONTAINER_CLASS}`)!
32
48
  }
@@ -64,6 +80,13 @@ describe('usePassThroughWheelEvents', () => {
64
80
  expect(wheelOverMarker(container)).toHaveLength(1)
65
81
  })
66
82
 
83
+ // Issue #10441: the original event keeps bubbling after the inner root redispatches it, so
84
+ // without a flag on it the outer root would redispatch it again.
85
+ it('redispatches once when the element is inside another pass-through element', async () => {
86
+ const container = await renderEditor(Nested)
87
+ expect(wheelOverMarker(container)).toHaveLength(1)
88
+ })
89
+
67
90
  it('stops redispatching once the owner unmounts', async () => {
68
91
  const container = await renderEditor()
69
92
  const marker = container.querySelector('[data-testid="marker"]')!
@@ -70,3 +70,18 @@ test.each(testCases)('works with $name', ({ deepLink, expected }) => {
70
70
  expect(createDeepLinkString(deepLink)).toBe(expected)
71
71
  expect(parseDeepLinkString(expected)).toEqual(deepLink)
72
72
  })
73
+
74
+ describe('parseDeepLinkString', () => {
75
+ it('throws on a viewport link with non-numeric bounds', () => {
76
+ expect(() => parseDeepLinkString('vabc.def.ghi.jkl')).toThrow('Invalid deep link string')
77
+ })
78
+
79
+ it('throws on a viewport link with missing bounds', () => {
80
+ expect(() => parseDeepLinkString('v1.2')).toThrow('Invalid deep link string')
81
+ expect(() => parseDeepLinkString('v')).toThrow('Invalid deep link string')
82
+ })
83
+
84
+ it('throws on an unknown link type', () => {
85
+ expect(() => parseDeepLinkString('xabc')).toThrow('Invalid deep link string')
86
+ })
87
+ })
@@ -73,9 +73,15 @@ export function parseDeepLinkString(deepLinkString: string): TLDeepLink {
73
73
  }
74
74
  case 'v': {
75
75
  const [x, y, w, h, pageId] = deepLinkString.slice(1).split('.')
76
+ const bounds = new Box(Number(x), Number(y), Number(w), Number(h))
77
+ // Number('abc') is NaN rather than an error, so without this check a malformed
78
+ // viewport link would bypass the caller's fallback and park the camera at the origin
79
+ if (![bounds.x, bounds.y, bounds.w, bounds.h].every(Number.isFinite)) {
80
+ throw Error('Invalid deep link string')
81
+ }
76
82
  return {
77
83
  type: 'viewport',
78
- bounds: new Box(Number(x), Number(y), Number(w), Number(h)),
84
+ bounds,
79
85
  pageId: pageId ? PageRecordType.createId(decodeURIComponent(pageId)) : undefined,
80
86
  }
81
87
  }
@@ -12,7 +12,7 @@ Keep seeing this message?
12
12
  /** @internal */
13
13
  export function showCantReadFromIndexDbAlert() {
14
14
  window.alert(
15
- `Oops! We could not access your browser's storage—and the app won't work correctly without that. We now need to reload the page and try again.
15
+ `Oops! We could not access your browser's storage—and the app won't work correctly without that. Reload the page to try again.
16
16
 
17
17
  Keep seeing this message?
18
18
  • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '5.4.0-canary.587f42e00c65'
4
+ export const version = '5.4.0-canary.5a084792df77'
5
5
  export const publishDates = {
6
6
  major: '2026-05-06T16:28:18.473Z',
7
- minor: '2026-08-20T12:57:14.523Z',
8
- patch: '2026-08-20T12:57:14.523Z',
7
+ minor: '2026-08-22T06:59:19.473Z',
8
+ patch: '2026-08-22T06:59:19.473Z',
9
9
  }