@tldraw/editor 5.3.0-next.a6e6f66f8517 → 5.3.0-next.af17ff0c1f3d

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 (58) hide show
  1. package/dist-cjs/index.d.ts +54 -2
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/TldrawEditor.js +6 -1
  4. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  5. package/dist-cjs/lib/editor/Editor.js +72 -15
  6. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  7. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +9 -0
  8. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  9. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +3 -0
  10. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  11. package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +3 -0
  12. package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +2 -2
  13. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  14. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  15. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +25 -1
  16. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  17. package/dist-cjs/lib/license/LicenseManager.js +14 -5
  18. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  19. package/dist-cjs/lib/options.js +2 -1
  20. package/dist-cjs/lib/options.js.map +2 -2
  21. package/dist-cjs/version.js +3 -3
  22. package/dist-cjs/version.js.map +1 -1
  23. package/dist-esm/index.d.mts +54 -2
  24. package/dist-esm/index.mjs +1 -1
  25. package/dist-esm/lib/TldrawEditor.mjs +6 -1
  26. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  27. package/dist-esm/lib/editor/Editor.mjs +72 -15
  28. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  29. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +9 -0
  30. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  31. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +3 -0
  32. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  33. package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +3 -0
  34. package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +2 -2
  35. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  36. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +25 -1
  37. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  38. package/dist-esm/lib/license/LicenseManager.mjs +14 -5
  39. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  40. package/dist-esm/lib/options.mjs +2 -1
  41. package/dist-esm/lib/options.mjs.map +2 -2
  42. package/dist-esm/version.mjs +3 -3
  43. package/dist-esm/version.mjs.map +1 -1
  44. package/editor.css +10 -0
  45. package/package.json +7 -7
  46. package/src/lib/TldrawEditor.tsx +10 -1
  47. package/src/lib/editor/Editor.ts +111 -20
  48. package/src/lib/editor/managers/FontManager/FontManager.test.ts +66 -0
  49. package/src/lib/editor/managers/FontManager/FontManager.ts +14 -0
  50. package/src/lib/editor/managers/TextManager/TextManager.ts +3 -0
  51. package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +6 -1
  52. package/src/lib/editor/shapes/ShapeUtil.ts +24 -0
  53. package/src/lib/editor/types/emit-types.ts +1 -0
  54. package/src/lib/hooks/usePassThroughWheelEvents.ts +44 -2
  55. package/src/lib/license/LicenseManager.test.ts +99 -29
  56. package/src/lib/license/LicenseManager.ts +16 -4
  57. package/src/lib/options.ts +3 -1
  58. package/src/version.ts +3 -3
@@ -106,16 +106,30 @@ export class FontManager {
106
106
  if (existingState) return existingState.loadingPromise
107
107
 
108
108
  const instance = this.findOrCreateFontFace(font)
109
+ // dispose() clears fontStates while loads may still be in flight, so a late
110
+ // callback must only touch the exact entry it was created for - not a fresh
111
+ // entry from a later request. Check identity, not just presence.
112
+ const isStale = () => this.fontStates.__unsafe__getWithoutCapture(font) !== state
109
113
  const state: FontState = {
110
114
  state: 'loading',
111
115
  instance,
112
116
  loadingPromise: instance
113
117
  .load()
114
118
  .then(() => {
119
+ if (isStale()) {
120
+ // eslint-disable-next-line no-console
121
+ console.debug(`Font "${font.family}" load interrupted by editor dispose`)
122
+ return
123
+ }
115
124
  this.editor.getContainerDocument().fonts.add(instance)
116
125
  this.fontStates.update(font, (s) => ({ ...s, state: 'ready' }))
117
126
  })
118
127
  .catch((err) => {
128
+ if (isStale()) {
129
+ // eslint-disable-next-line no-console
130
+ console.debug(`Font "${font.family}" load interrupted by editor dispose`, err)
131
+ return
132
+ }
119
133
  console.error(err)
120
134
  this.fontStates.update(font, (s) => ({ ...s, state: 'error' }))
121
135
  }),
@@ -183,6 +183,9 @@ export class TextManager extends EditorManager {
183
183
  'font-weight': opts.fontWeight,
184
184
  'font-size': opts.fontSize + 'px',
185
185
  'line-height': `${resolveLineHeightPx(opts.fontSize, opts.lineHeight)}px`,
186
+ // Unitless multiplier consumed by the .tl-rich-text h1–h6 rule (see editor.css),
187
+ // so heading measurement matches on-canvas rendering.
188
+ '--tl-rich-text-heading-line-height': `${opts.lineHeight}`,
186
189
  padding: opts.padding,
187
190
  'max-width': opts.maxWidth ? opts.maxWidth + 'px' : undefined,
188
191
  'min-width': opts.minWidth ? opts.minWidth + 'px' : undefined,
@@ -5,7 +5,7 @@ import { BaseBoxShapeUtil, TLBaseBoxShape } from './BaseBoxShapeUtil'
5
5
  import { TLDragShapesInInfo, TLDragShapesOutInfo } from './ShapeUtil'
6
6
 
7
7
  /**
8
- * A base class for frame-like shapes — containers that clip their children,
8
+ * A base class for frame-like shapes — containers that clip their children except arrows,
9
9
  * require full-brush selection, block erasure from inside, and support
10
10
  * drag-and-drop reparenting.
11
11
  *
@@ -17,6 +17,7 @@ import { TLDragShapesInInfo, TLDragShapesOutInfo } from './ShapeUtil'
17
17
  * - `canReceiveNewChildrenOfType()` returns `true` unless the container is locked
18
18
  * - `canRemoveChildrenOfType()` returns `true` unless the container is locked
19
19
  * - `getClipPath()` returns the shape geometry's vertices
20
+ * - `shouldClipChild()` clips all children except arrows
20
21
  * - `onDragShapesIn()` reparents shapes into the frame (with index restoration)
21
22
  * - `onDragShapesOut()` reparents shapes back to the page
22
23
  *
@@ -69,6 +70,10 @@ export abstract class BaseFrameLikeShapeUtil<
69
70
  return this.editor.getShapeGeometry(shape.id).vertices
70
71
  }
71
72
 
73
+ override shouldClipChild(child: TLShape): boolean {
74
+ return child.type !== 'arrow'
75
+ }
76
+
72
77
  override onDragShapesIn(
73
78
  shape: Shape,
74
79
  draggingShapes: TLShape[],
@@ -669,6 +669,30 @@ export abstract class ShapeUtil<Shape extends TLShape = TLShape> {
669
669
  */
670
670
  onBeforeCreate?(next: Shape): Shape | void
671
671
 
672
+ /**
673
+ * A callback called when a shape is reproduced from an existing shape, either by duplicating
674
+ * ({@link Editor.duplicateShapes}) or by pasting/putting content onto the page
675
+ * ({@link Editor.putContentOntoCurrentPage}). This provides a last chance to modify the copy
676
+ * before it's created — for example, to re-stamp attribution so the copy is credited to the
677
+ * current user rather than the original author. It is not called when content is put with
678
+ * `preserveIds` (e.g. {@link Editor.moveShapesToPage}), since the shape keeps its identity
679
+ * and no copy is made.
680
+ *
681
+ * @example
682
+ *
683
+ * ```ts
684
+ * onBeforeDuplicate = (source, duplicate) => {
685
+ * return { ...duplicate, props: { ...duplicate.props, editedBy: this.editor.getAttributionUserId() } }
686
+ * }
687
+ * ```
688
+ *
689
+ * @param source - The shape being copied from.
690
+ * @param duplicate - The new copy (with its own id), before it's created.
691
+ * @returns The next shape or void.
692
+ * @public
693
+ */
694
+ onBeforeDuplicate?(source: Shape, duplicate: Shape): Shape | void
695
+
672
696
  /**
673
697
  * A callback called just before a shape is updated. This method provides a last chance to modify
674
698
  * the updated shape.
@@ -6,6 +6,7 @@ import { TLEventInfo } from './event-types'
6
6
  export interface TLEventMap {
7
7
  // Lifecycle / Internal
8
8
  mount: []
9
+ unmount: []
9
10
  'max-shapes': [{ name: string; pageId: TLPageId; count: number }]
10
11
  change: [HistoryEntry<TLRecord>]
11
12
  update: []
@@ -3,6 +3,48 @@ import { preventDefault } from '../utils/dom'
3
3
  import { useContainer } from './useContainer'
4
4
  import { useMaybeEditor } from './useEditor'
5
5
 
6
+ function isScrollableOverflow(overflow: string) {
7
+ return overflow === 'auto' || overflow === 'scroll' || overflow === 'overlay'
8
+ }
9
+
10
+ // An element only consumes a wheel event when it's a real scroll container: its content overflows
11
+ // AND its computed overflow is scrollable. Checking scrollHeight/scrollWidth alone is not enough —
12
+ // an `overflow: visible` element whose content merely overflows (e.g. a comment pin whose hover
13
+ // `transform: scale()` inflates scrollHeight past clientHeight) never scrolls, so the wheel must
14
+ // still pass through to the canvas.
15
+ function isScrollable(elm: HTMLElement) {
16
+ // Cheap first: if nothing overflows, it can't scroll — skip the getComputedStyle read. This runs
17
+ // per ancestor on every wheel event, so avoid resolving styles for the common (non-overflowing) case.
18
+ const overflowsY = elm.scrollHeight > elm.clientHeight
19
+ const overflowsX = elm.scrollWidth > elm.clientWidth
20
+ if (!overflowsY && !overflowsX) return false
21
+
22
+ const style = getComputedStyle(elm)
23
+ return (
24
+ (overflowsY && isScrollableOverflow(style.overflowY)) ||
25
+ (overflowsX && isScrollableOverflow(style.overflowX))
26
+ )
27
+ }
28
+
29
+ // Walk from the wheeled element up to (and including) the pass-through root, looking for a scroll
30
+ // container. If one is found, the wheel belongs to it — don't redispatch it to the canvas.
31
+ function hasScrollableElement(target: EventTarget | null, root: HTMLElement) {
32
+ if (!(target instanceof Node)) {
33
+ return isScrollable(root)
34
+ }
35
+
36
+ let elm: Element | null = target instanceof Element ? target : target.parentElement
37
+ while (elm) {
38
+ if (elm instanceof HTMLElement && isScrollable(elm)) {
39
+ return true
40
+ }
41
+ if (elm === root) return false
42
+ elm = elm.parentElement
43
+ }
44
+
45
+ return false
46
+ }
47
+
6
48
  /** @public */
7
49
  export function usePassThroughWheelEvents(ref: RefObject<HTMLElement | null>) {
8
50
  if (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')
@@ -16,9 +58,9 @@ export function usePassThroughWheelEvents(ref: RefObject<HTMLElement | null>) {
16
58
 
17
59
  if ((e as any).isSpecialRedispatchedEvent) return
18
60
 
19
- // if the element is scrollable, don't redispatch the event
61
+ // If the wheel is over a scrollable element, let it scroll instead of redispatching.
20
62
  const elm = ref.current
21
- if (elm && elm.scrollHeight > elm.clientHeight) {
63
+ if (elm && hasScrollableElement(e.target, elm)) {
22
64
  return
23
65
  }
24
66
 
@@ -510,6 +510,60 @@ describe('LicenseManager', () => {
510
510
  })
511
511
  })
512
512
 
513
+ describe('Expiry date timezone handling', () => {
514
+ afterEach(() => {
515
+ vi.useRealTimers()
516
+ })
517
+
518
+ // The named expiry date is minted as a date-only string and should mean "the license
519
+ // is fully usable through the end of that day in UTC", giving every user the same
520
+ // cutoff regardless of their local timezone.
521
+ async function makeEvaluationLicenseWithExpiry(expiry: string) {
522
+ const licenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
523
+ licenseInfo[PROPERTIES.FLAGS] = FLAGS.EVALUATION_LICENSE
524
+ licenseInfo[PROPERTIES.EXPIRY_DATE] = expiry
525
+ return generateLicenseKey(JSON.stringify(licenseInfo), keyPair)
526
+ }
527
+
528
+ it('Keeps the license valid through the end of the named expiry day (UTC)', async () => {
529
+ const key = await makeEvaluationLicenseWithExpiry('2026-06-26')
530
+
531
+ // The final moment of the named day is still valid.
532
+ vi.useFakeTimers()
533
+ vi.setSystemTime(new Date('2026-06-26T23:59:59.000Z'))
534
+ expect(
535
+ ((await licenseManager.getLicenseFromKey(key)) as ValidLicenseKeyResult)
536
+ .isEvaluationLicenseExpired
537
+ ).toBe(false)
538
+ })
539
+
540
+ it('Expires the license at the start of the day after the named expiry day (UTC)', async () => {
541
+ const key = await makeEvaluationLicenseWithExpiry('2026-06-26')
542
+
543
+ vi.useFakeTimers()
544
+ vi.setSystemTime(new Date('2026-06-27T00:00:01.000Z'))
545
+ expect(
546
+ ((await licenseManager.getLicenseFromKey(key)) as ValidLicenseKeyResult)
547
+ .isEvaluationLicenseExpired
548
+ ).toBe(true)
549
+ })
550
+
551
+ it('Does not expire early for users west of UTC who are still on the named day locally', async () => {
552
+ const key = await makeEvaluationLicenseWithExpiry('2026-06-26')
553
+
554
+ // Under the old logic a user west of UTC parsed the date one calendar day early and
555
+ // expired at the *start* of that day, losing most of a day. With the uniform UTC
556
+ // cutoff the license stays valid all through June 26 for everyone, no matter their
557
+ // local offset. 1pm UTC on June 26 is well before the cutoff, so it is still valid.
558
+ vi.useFakeTimers()
559
+ vi.setSystemTime(new Date('2026-06-26T13:00:00.000Z'))
560
+ expect(
561
+ ((await licenseManager.getLicenseFromKey(key)) as ValidLicenseKeyResult)
562
+ .isEvaluationLicenseExpired
563
+ ).toBe(false)
564
+ })
565
+ })
566
+
513
567
  describe('License expiry and grace period', () => {
514
568
  it('Fails if the license key has expired beyond grace period', async () => {
515
569
  const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
@@ -540,38 +594,54 @@ describe('LicenseManager', () => {
540
594
  })
541
595
 
542
596
  it('Handles grace period correctly - 20 days expired should still be within grace period', async () => {
543
- const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
544
- const expiredDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 20) // 20 days ago
545
- expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiredDate.toISOString()
546
-
547
- const expiredLicenseKey = await generateLicenseKey(
548
- JSON.stringify(expiredLicenseInfo),
549
- keyPair
550
- )
551
-
552
- // Test the getLicenseFromKey method to verify grace period calculation
553
- const result = (await licenseManager.getLicenseFromKey(
554
- expiredLicenseKey
555
- )) as ValidLicenseKeyResult
556
- expect(result.isAnnualLicense).toBe(true)
557
- expect(result.isAnnualLicenseExpired).toBe(false) // Within 30-day grace period
558
- expect(result.daysSinceExpiry).toBe(20)
597
+ // Pin the clock and use a date-only UTC expiry so the calculation is timezone
598
+ // independent. The named day is fully usable, so an expiry 20 calendar days before
599
+ // "now" has been past its usable window for 19 full days.
600
+ vi.useFakeTimers()
601
+ vi.setSystemTime(new Date('2026-06-26T12:00:00.000Z'))
602
+ try {
603
+ const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
604
+ expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = '2026-06-06' // 20 days before now
605
+
606
+ const expiredLicenseKey = await generateLicenseKey(
607
+ JSON.stringify(expiredLicenseInfo),
608
+ keyPair
609
+ )
610
+
611
+ // Test the getLicenseFromKey method to verify grace period calculation
612
+ const result = (await licenseManager.getLicenseFromKey(
613
+ expiredLicenseKey
614
+ )) as ValidLicenseKeyResult
615
+ expect(result.isAnnualLicense).toBe(true)
616
+ expect(result.isAnnualLicenseExpired).toBe(false) // Within 30-day grace period
617
+ expect(result.daysSinceExpiry).toBe(19)
618
+ } finally {
619
+ vi.useRealTimers()
620
+ }
559
621
  })
560
622
 
561
623
  it('Calculates days since expiry correctly', async () => {
562
- const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
563
- const expiredDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 15) // 15 days ago
564
- expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiredDate.toISOString()
565
-
566
- const expiredLicenseKey = await generateLicenseKey(
567
- JSON.stringify(expiredLicenseInfo),
568
- keyPair
569
- )
570
-
571
- const result = (await licenseManager.getLicenseFromKey(
572
- expiredLicenseKey
573
- )) as ValidLicenseKeyResult
574
- expect(result.daysSinceExpiry).toBe(15)
624
+ // Pin the clock and use a date-only UTC expiry so the calculation is timezone
625
+ // independent. The named day is fully usable, so an expiry 15 calendar days before
626
+ // "now" has been past its usable window for 14 full days.
627
+ vi.useFakeTimers()
628
+ vi.setSystemTime(new Date('2026-06-26T12:00:00.000Z'))
629
+ try {
630
+ const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
631
+ expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = '2026-06-11' // 15 days before now
632
+
633
+ const expiredLicenseKey = await generateLicenseKey(
634
+ JSON.stringify(expiredLicenseInfo),
635
+ keyPair
636
+ )
637
+
638
+ const result = (await licenseManager.getLicenseFromKey(
639
+ expiredLicenseKey
640
+ )) as ValidLicenseKeyResult
641
+ expect(result.daysSinceExpiry).toBe(14)
642
+ } finally {
643
+ vi.useRealTimers()
644
+ }
575
645
  })
576
646
  })
577
647
 
@@ -372,14 +372,26 @@ export class LicenseManager {
372
372
  }
373
373
 
374
374
  private getExpirationDateWithoutGracePeriod(expiryDate: Date) {
375
- return new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate())
375
+ // The named expiry date is the last day the license is fully usable, so the license
376
+ // expires at the end of that day, i.e. the start of the following day. We work in UTC
377
+ // (the expiry date is minted and parsed as a UTC date-only string) so the cutoff is a
378
+ // single predictable instant for every user regardless of their local timezone.
379
+ return new Date(
380
+ Date.UTC(
381
+ expiryDate.getUTCFullYear(),
382
+ expiryDate.getUTCMonth(),
383
+ expiryDate.getUTCDate() + 1 // Add 1 day so the named date is fully usable
384
+ )
385
+ )
376
386
  }
377
387
 
378
388
  private getExpirationDateWithGracePeriod(expiryDate: Date) {
379
389
  return new Date(
380
- expiryDate.getFullYear(),
381
- expiryDate.getMonth(),
382
- expiryDate.getDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day
390
+ Date.UTC(
391
+ expiryDate.getUTCFullYear(),
392
+ expiryDate.getUTCMonth(),
393
+ expiryDate.getUTCDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day
394
+ )
383
395
  )
384
396
  }
385
397
 
@@ -86,6 +86,7 @@ export interface TldrawOptions {
86
86
  readonly collaboratorCheckIntervalMs: number
87
87
  readonly cameraMovingTimeoutMs: number
88
88
  readonly hitTestMargin: number
89
+ readonly coarseHitTestMargin: number
89
90
  readonly edgeScrollDelay: number
90
91
  readonly edgeScrollEaseDuration: number
91
92
  readonly edgeScrollSpeed: number
@@ -312,7 +313,8 @@ export const defaultTldrawOptions = {
312
313
  collaboratorIdleTimeoutMs: 3000,
313
314
  collaboratorCheckIntervalMs: 1200,
314
315
  cameraMovingTimeoutMs: 64,
315
- hitTestMargin: 8,
316
+ hitTestMargin: 3,
317
+ coarseHitTestMargin: 4,
316
318
  edgeScrollDelay: 200,
317
319
  edgeScrollEaseDuration: 200,
318
320
  edgeScrollSpeed: 25,
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.3.0-next.a6e6f66f8517'
4
+ export const version = '5.3.0-next.af17ff0c1f3d'
5
5
  export const publishDates = {
6
6
  major: '2026-05-06T16:28:18.473Z',
7
- minor: '2026-07-01T09:35:37.719Z',
8
- patch: '2026-07-01T09:35:37.719Z',
7
+ minor: '2026-07-29T10:52:57.101Z',
8
+ patch: '2026-07-29T10:52:57.101Z',
9
9
  }