@tldraw/editor 5.7.0-internal.5fe8922939ec → 5.7.0-internal.d83eaf8e2d50

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.d.ts +9 -48
  2. package/dist-cjs/index.js +1 -3
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +2 -10
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/config/createTLStore.js +1 -3
  7. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  8. package/dist-cjs/lib/editor/Editor.js +8 -37
  9. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  10. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +2 -44
  11. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  12. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  13. package/dist-cjs/lib/license/LicenseManager.js +16 -8
  14. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  15. package/dist-cjs/version.js +3 -3
  16. package/dist-cjs/version.js.map +1 -1
  17. package/dist-esm/index.d.mts +9 -48
  18. package/dist-esm/index.mjs +1 -3
  19. package/dist-esm/index.mjs.map +2 -2
  20. package/dist-esm/lib/TldrawEditor.mjs +3 -11
  21. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  22. package/dist-esm/lib/config/createTLStore.mjs +1 -3
  23. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  24. package/dist-esm/lib/editor/Editor.mjs +8 -38
  25. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  26. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +2 -44
  27. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  28. package/dist-esm/lib/license/LicenseManager.mjs +16 -8
  29. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  30. package/dist-esm/version.mjs +3 -3
  31. package/dist-esm/version.mjs.map +1 -1
  32. package/package.json +7 -7
  33. package/src/index.ts +1 -6
  34. package/src/lib/TldrawEditor.tsx +1 -10
  35. package/src/lib/config/createTLStore.ts +4 -11
  36. package/src/lib/editor/Editor.ts +8 -47
  37. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +2 -58
  38. package/src/lib/editor/types/emit-types.ts +2 -14
  39. package/src/lib/license/LicenseManager.test.ts +62 -21
  40. package/src/lib/license/LicenseManager.ts +25 -11
  41. package/src/version.ts +3 -3
  42. package/dist-cjs/lib/editor/managers/AuthorizeManager/AuthorizeManager.js +0 -94
  43. package/dist-cjs/lib/editor/managers/AuthorizeManager/AuthorizeManager.js.map +0 -7
  44. package/dist-cjs/lib/hooks/useStableAuthorize.js +0 -45
  45. package/dist-cjs/lib/hooks/useStableAuthorize.js.map +0 -7
  46. package/dist-esm/lib/editor/managers/AuthorizeManager/AuthorizeManager.mjs +0 -76
  47. package/dist-esm/lib/editor/managers/AuthorizeManager/AuthorizeManager.mjs.map +0 -7
  48. package/dist-esm/lib/hooks/useStableAuthorize.mjs +0 -25
  49. package/dist-esm/lib/hooks/useStableAuthorize.mjs.map +0 -7
  50. package/src/lib/editor/managers/AuthorizeManager/AuthorizeManager.ts +0 -110
  51. package/src/lib/hooks/useStableAuthorize.ts +0 -31
@@ -5,7 +5,6 @@ import {
5
5
  SchemaPropsInfo,
6
6
  TLAssetStore,
7
7
  TLRecord,
8
- TLAuthorize,
9
8
  TLStore,
10
9
  TLStoreProps,
11
10
  TLStoreSnapshot,
@@ -54,13 +53,6 @@ export interface TLStoreBaseOptions {
54
53
 
55
54
  /** Called when the store is connected to an {@link @tldraw/editor#Editor}. */
56
55
  onMount?(editor: Editor): void | (() => void)
57
-
58
- /**
59
- * The authorize hooks. The editor runs `authorize.write` on each of this user's operations and
60
- * reverts the ones it refuses, and asks `authorize.can` in {@link @tldraw/editor#Editor.can}. Pass
61
- * the same object to the sync room. Keep it stable: a new object makes a new store.
62
- */
63
- authorize?: TLAuthorize
64
56
  }
65
57
 
66
58
  /** @public */
@@ -80,7 +72,10 @@ export type TLStoreSchemaOptions =
80
72
  export type TLStoreOptions = TLStoreBaseOptions & {
81
73
  id?: string
82
74
  /** Collaboration options for the store. */
83
- collaboration?: TLStoreProps['collaboration']
75
+ collaboration?: {
76
+ status: Signal<'online' | 'offline'> | null
77
+ mode?: Signal<'readonly' | 'readwrite'> | null
78
+ }
84
79
  } & TLStoreSchemaOptions
85
80
 
86
81
  /** @public */
@@ -156,7 +151,6 @@ export function createTLStore({
156
151
  users = defaultUserStore,
157
152
  onMount,
158
153
  collaboration,
159
- authorize,
160
154
  themes,
161
155
  ...rest
162
156
  }: TLStoreOptions = {}): TLStore {
@@ -190,7 +184,6 @@ export function createTLStore({
190
184
  return onMount?.(editor)
191
185
  },
192
186
  collaboration,
193
- authorize,
194
187
  },
195
188
  })
196
189
 
@@ -57,15 +57,12 @@ import {
57
57
  TLUserId,
58
58
  TLVideoAsset,
59
59
  UserRecordType,
60
- bindAuthorizeCan,
61
60
  createBindingId,
62
61
  createShapeId,
63
62
  createUserId,
64
63
  getShapePropKeysByStyle,
65
64
  isPageId,
66
65
  isShapeId,
67
- TLPermission,
68
- TLPermissionDataMap,
69
66
  } from '@tldraw/tlschema'
70
67
  import {
71
68
  FileHelpers,
@@ -165,7 +162,6 @@ import { bindingsIndex } from './derivations/bindingsIndex'
165
162
  import { notVisibleShapes } from './derivations/notVisibleShapes'
166
163
  import { parentsToChildren } from './derivations/parentsToChildren'
167
164
  import { deriveShapeIdsInCurrentPage } from './derivations/shapeIdsInCurrentPage'
168
- import { AuthorizeManager, getAuthorizeUserId } from './managers/AuthorizeManager/AuthorizeManager'
169
165
  import { ClickManager } from './managers/ClickManager/ClickManager'
170
166
  import { CollaboratorsManager } from './managers/CollaboratorsManager/CollaboratorsManager'
171
167
  import { EdgeScrollManager } from './managers/EdgeScrollManager/EdgeScrollManager'
@@ -407,9 +403,6 @@ export class Editor extends EventEmitter<TLEventMap> {
407
403
 
408
404
  this.snaps = new SnapManager(this)
409
405
 
410
- const authorizeManager = new AuthorizeManager(this)
411
- this.disposables.add(() => authorizeManager.dispose())
412
-
413
406
  this._spatialIndex = new SpatialIndexManager(this)
414
407
  this.disposables.add(() => this._spatialIndex.dispose())
415
408
 
@@ -1760,8 +1753,7 @@ export class Editor extends EventEmitter<TLEventMap> {
1760
1753
  const previousIgnoreShapeLock = this._shouldIgnoreShapeLock
1761
1754
  this._shouldIgnoreShapeLock = opts?.ignoreShapeLock ?? previousIgnoreShapeLock
1762
1755
  try {
1763
- // one editor operation is one checked unit, however many store operations it makes
1764
- this.store.checkAsOneOperation(() => this.history.batch(fn, opts))
1756
+ this.history.batch(fn, opts)
1765
1757
  } finally {
1766
1758
  this._shouldIgnoreShapeLock = previousIgnoreShapeLock
1767
1759
  }
@@ -1769,29 +1761,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1769
1761
  return this
1770
1762
  }
1771
1763
 
1772
- /**
1773
- * Whether the current user has a permission, for example `'tl:shape:edit'` for a shape. The
1774
- * editor asks the store's `authorize.can` with the current user's id: the one the sync room
1775
- * gave this session, or else {@link @tldraw/editor#UserPreferencesManager.getExternalId}. With
1776
- * no `can`, every permission is granted. In a read-only editor, no permission is granted.
1777
- *
1778
- * @example
1779
- * ```ts
1780
- * if (editor.can('tl:shape:edit', { shape })) {
1781
- * editor.updateShape({ ...shape, x: 100 })
1782
- * }
1783
- * ```
1784
- *
1785
- * @public
1786
- */
1787
- can<P extends TLPermission>(permission: P, data?: TLPermissionDataMap[P]): boolean {
1788
- if (this.getIsReadonly()) return false
1789
- const can = bindAuthorizeCan(this.store.props.authorize?.can, {
1790
- userId: getAuthorizeUserId(this),
1791
- })
1792
- return can(permission, data)
1793
- }
1794
-
1795
1764
  /* --------------------- Errors --------------------- */
1796
1765
 
1797
1766
  /** @internal */
@@ -2873,7 +2842,6 @@ export class Editor extends EventEmitter<TLEventMap> {
2873
2842
  const _info: TLEditStartInfo = info ?? { type: 'unknown' }
2874
2843
  if (!util.canEdit(_shape, _info)) return false // shape is not editable
2875
2844
  if (this.getIsReadonly() && !util.canEditInReadonly(_shape)) return false // readonly and no exception
2876
- if (!this.getIsReadonly() && !this.can('tl:shape:edit', { shape: _shape })) return false // the app says the user can't change it
2877
2845
  if (this.isShapeOrAncestorLocked(_shape) && !util.canEditWhileLocked(_shape)) return false // locked and no exception. Note here: we're not distinguishing between a locked shape and a shape that is the descendant of a locked shape.
2878
2846
  return true // shape is editable
2879
2847
  }
@@ -3133,7 +3101,6 @@ export class Editor extends EventEmitter<TLEventMap> {
3133
3101
  if (!util.canCrop(_shape)) return false
3134
3102
  if (this.getIsReadonly()) return false
3135
3103
  if (this.isShapeOrAncestorLocked(_shape)) return false
3136
- if (!this.can('tl:shape:edit', { shape: _shape })) return false
3137
3104
  return true
3138
3105
  }
3139
3106
 
@@ -4505,14 +4472,11 @@ export class Editor extends EventEmitter<TLEventMap> {
4505
4472
  ) {
4506
4473
  return
4507
4474
  }
4508
- // housekeeping for the current user, so the write hook never sees it
4509
- this.store.runUnchecked(() =>
4510
- this.run(
4511
- () => {
4512
- this.store.put([user])
4513
- },
4514
- { history: 'ignore' }
4515
- )
4475
+ this.run(
4476
+ () => {
4477
+ this.store.put([user])
4478
+ },
4479
+ { history: 'ignore' }
4516
4480
  )
4517
4481
  }
4518
4482
 
@@ -9642,9 +9606,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9642
9606
  info: TLExternalContent<E>,
9643
9607
  opts = {} as { force?: boolean }
9644
9608
  ): Promise<void> {
9645
- // can() is false when read-only. Asked before the handler runs: an upload for a shape that is
9646
- // then refused can't be taken back. `force` skips it; authorize.write still checks the change.
9647
- if (!opts.force && !this.can('tl:shape:create')) return
9609
+ if (!opts.force && this.getIsReadonly()) return
9648
9610
 
9649
9611
  return this.externalContentHandlers[info.type]?.(info as any)
9650
9612
  }
@@ -9659,8 +9621,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9659
9621
  info: TLExternalContent<E>,
9660
9622
  opts = {} as { force?: boolean }
9661
9623
  ): Promise<void> {
9662
- // as in putExternalContent: the upload happens before authorize.write sees the change
9663
- if (!opts.force && !this.can('tl:shape:edit')) return
9624
+ if (!opts.force && this.getIsReadonly()) return
9664
9625
  return this.externalContentHandlers[info.type]?.(info as any)
9665
9626
  }
9666
9627
 
@@ -42,9 +42,8 @@ export class HistoryManager<R extends UnknownRecord> {
42
42
  constructor(opts: { store: Store<R>; annotateError?(error: unknown): void }) {
43
43
  this.store = opts.store
44
44
  this.annotateError = opts.annotateError ?? noop
45
- const stopIntercepting = this.store.addHistoryInterceptor((entry, source) => {
45
+ this.dispose = this.store.addHistoryInterceptor((entry, source) => {
46
46
  if (source !== 'user') return
47
- if (this.state !== HistoryRecorderState.Paused) this.keepForRefusal()
48
47
 
49
48
  switch (this.state) {
50
49
  case HistoryRecorderState.Recording:
@@ -64,33 +63,6 @@ export class HistoryManager<R extends UnknownRecord> {
64
63
  exhaustiveSwitchError(this.state)
65
64
  }
66
65
  })
67
- const stopSettling = this.store.onCheckedOperationSettled((outcome) => {
68
- const kept = this.keptForRefusal
69
- this.keptForRefusal = null
70
- // an aborted operation's transaction rolled the stacks back already, but not the pending
71
- // diff, which isn't an atom
72
- if (outcome !== 'accepted' && kept) {
73
- this.stacks.set(kept.stacks)
74
- this.pendingDiff.restore(kept.pendingDiff)
75
- }
76
- })
77
- this.dispose = () => {
78
- stopIntercepting()
79
- stopSettling()
80
- }
81
- }
82
-
83
- // History as it was when the checked operation in progress first touched it. A refused or
84
- // aborted operation leaves no trace in history, so this is put back: a redo stack the edit
85
- // cleared, the steps an undo or bail inside an outer operation moved.
86
- private keptForRefusal: {
87
- stacks: { undos: Stack<TLHistoryEntry<R>>; redos: Stack<TLHistoryEntry<R>> }
88
- pendingDiff: RecordsDiff<R>
89
- } | null = null
90
-
91
- private keepForRefusal() {
92
- if (this.keptForRefusal || !this.store.isInCheckedOperation()) return
93
- this.keptForRefusal = { stacks: this.stacks.get(), pendingDiff: this.pendingDiff.copy() }
94
66
  }
95
67
 
96
68
  private flushPendingDiff() {
@@ -153,20 +125,7 @@ export class HistoryManager<R extends UnknownRecord> {
153
125
  }
154
126
 
155
127
  // History
156
- _undo(opts: { pushToRedoStack: boolean; toMark?: string }) {
157
- // an undo is judged like any other change; refused, it leaves history where it was
158
- this.store.checkAsOneOperation(() => this._undoUnchecked(opts))
159
- return this
160
- }
161
-
162
- private _undoUnchecked({
163
- pushToRedoStack,
164
- toMark = undefined,
165
- }: {
166
- pushToRedoStack: boolean
167
- toMark?: string
168
- }) {
169
- this.keepForRefusal()
128
+ _undo({ pushToRedoStack, toMark = undefined }: { pushToRedoStack: boolean; toMark?: string }) {
170
129
  const previousState = this.state
171
130
  const previousIsReplaying = this._isReplaying
172
131
  this.state = HistoryRecorderState.Paused
@@ -249,12 +208,6 @@ export class HistoryManager<R extends UnknownRecord> {
249
208
  }
250
209
 
251
210
  redo() {
252
- this.store.checkAsOneOperation(() => this._redoUnchecked())
253
- return this
254
- }
255
-
256
- private _redoUnchecked() {
257
- this.keepForRefusal()
258
211
  const previousState = this.state
259
212
  const previousIsReplaying = this._isReplaying
260
213
  this.state = HistoryRecorderState.Paused
@@ -313,7 +266,6 @@ export class HistoryManager<R extends UnknownRecord> {
313
266
  }
314
267
 
315
268
  squashToMark(id: string) {
316
- this.keepForRefusal()
317
269
  // remove marks between head and the mark
318
270
 
319
271
  let top = this.stacks.get().undos
@@ -350,7 +302,6 @@ export class HistoryManager<R extends UnknownRecord> {
350
302
 
351
303
  /** @internal */
352
304
  _mark(id: string) {
353
- this.keepForRefusal()
354
305
  transact(() => {
355
306
  this.flushPendingDiff()
356
307
  this.stacks.update(({ undos, redos }) => ({ undos: undos.push({ type: 'stop', id }), redos }))
@@ -358,7 +309,6 @@ export class HistoryManager<R extends UnknownRecord> {
358
309
  }
359
310
 
360
311
  clear() {
361
- this.keepForRefusal()
362
312
  this.stacks.set({ undos: stack(), redos: stack() })
363
313
  this.pendingDiff.clear()
364
314
  }
@@ -404,12 +354,6 @@ class PendingDiff<R extends UnknownRecord> {
404
354
  return diff
405
355
  }
406
356
 
407
- copy() {
408
- const diff = createEmptyRecordsDiff<R>()
409
- squashRecordDiffsMutable(diff, [this.diff])
410
- return diff
411
- }
412
-
413
357
  restore(diff: RecordsDiff<R>) {
414
358
  this.diff = diff
415
359
  this.isEmptyAtom.set(isRecordsDiffEmpty(diff))
@@ -1,24 +1,14 @@
1
1
  import { HistoryEntry } from '@tldraw/store'
2
- import { BoxModel, TLPageId, TLRecord, TLShapeId, TLWriteRefusal } from '@tldraw/tlschema'
2
+ import { BoxModel, TLPageId, TLRecord, TLShapeId } from '@tldraw/tlschema'
3
3
  import { TLEventInfo } from './event-types'
4
4
 
5
- /**
6
- * A refused change, as the editor's `'refused'` event reports it. `source` is `'local'` when the
7
- * editor's own `authorize.write` refused it, and `'server'` when the room did. Either way the
8
- * change is already rolled back.
9
- *
10
- * @public
11
- */
12
- export interface TLRefusal extends TLWriteRefusal {
13
- source: 'local' | 'server'
14
- }
15
-
16
5
  /** @public */
17
6
  export interface TLEventMap {
18
7
  // Lifecycle / Internal
19
8
  mount: []
20
9
  unmount: []
21
10
  'max-shapes': [{ name: string; pageId: TLPageId; count: number }]
11
+ 'confirm-open-link': [{ url: string }]
22
12
  change: [HistoryEntry<TLRecord>]
23
13
  update: []
24
14
  crash: [{ error: unknown }]
@@ -35,8 +25,6 @@ export interface TLEventMap {
35
25
  'edited-shapes': [TLRecord[]]
36
26
  'deleted-shapes': [TLShapeId[]]
37
27
  edit: []
38
- /** The editor or the room refused one of this user's changes. It is already rolled back. */
39
- refused: [TLRefusal]
40
28
  dispose: []
41
29
  }
42
30
 
@@ -23,6 +23,7 @@ vi.mock('../../version', () => {
23
23
  })
24
24
 
25
25
  const now = new Date()
26
+ const EXPECTED_GRACE_PERIOD_DAYS = 5
26
27
  const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 5).toISOString()
27
28
 
28
29
  const STANDARD_LICENSE_INFO = JSON.stringify([
@@ -728,12 +729,17 @@ describe('LicenseManager', () => {
728
729
  isLicensedWithWatermark: true,
729
730
  isCollaborationEnabled: true,
730
731
  isCommentingEnabled: true,
732
+ isLibrariesEnabled: true,
731
733
  isAnnualLicenseExpired: false,
732
734
  isPerpetualLicenseExpired: false,
733
735
  daysSinceExpiry: 0,
734
736
  })
735
737
  expect(manager.state.get()).toBe('licensed-with-watermark')
736
- expect(manager.featureFlags.get()).toEqual({ collaboration: true, commenting: true })
738
+ expect(manager.featureFlags.get()).toEqual({
739
+ collaboration: true,
740
+ commenting: true,
741
+ libraries: true,
742
+ })
737
743
  manager.dispose()
738
744
  }
739
745
  })
@@ -755,7 +761,11 @@ describe('LicenseManager', () => {
755
761
  reason: 'no-key-provided',
756
762
  })
757
763
  expect(manager.state.get()).toBe('unlicensed-production')
758
- expect(manager.featureFlags.get()).toEqual({ collaboration: false, commenting: false })
764
+ expect(manager.featureFlags.get()).toEqual({
765
+ collaboration: false,
766
+ commenting: false,
767
+ libraries: false,
768
+ })
759
769
  manager.dispose()
760
770
  }
761
771
  })
@@ -994,8 +1004,24 @@ describe('LicenseManager', () => {
994
1004
  collaborationLicenseKey
995
1005
  )) as ValidLicenseKeyResult
996
1006
  expect(result.isCollaborationEnabled).toBe(true)
997
- // The collaboration umbrella grants the commenting sub-feature.
1007
+ // The collaboration umbrella grants the commenting and libraries sub-features.
998
1008
  expect(result.isCommentingEnabled).toBe(true)
1009
+ expect(result.isLibrariesEnabled).toBe(true)
1010
+ })
1011
+
1012
+ it('Checks for the libraries feature flag', async () => {
1013
+ const librariesLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
1014
+ librariesLicenseInfo[PROPERTIES.FLAGS] |= FLAGS.FEAT_LIBRARIES
1015
+ const librariesLicenseKey = await generateLicenseKey(
1016
+ JSON.stringify(librariesLicenseInfo),
1017
+ keyPair
1018
+ )
1019
+ const result = (await licenseManager.getLicenseFromKey(
1020
+ librariesLicenseKey
1021
+ )) as ValidLicenseKeyResult
1022
+ expect(result.isLibrariesEnabled).toBe(true)
1023
+ expect(result.isCollaborationEnabled).toBe(false)
1024
+ expect(result.isCommentingEnabled).toBe(false)
999
1025
  })
1000
1026
 
1001
1027
  it('Leaves feature flags off when no feature bits are set', async () => {
@@ -1005,6 +1031,7 @@ describe('LicenseManager', () => {
1005
1031
  )) as ValidLicenseKeyResult
1006
1032
  expect(result.isCollaborationEnabled).toBe(false)
1007
1033
  expect(result.isCommentingEnabled).toBe(false)
1034
+ expect(result.isLibrariesEnabled).toBe(false)
1008
1035
  })
1009
1036
 
1010
1037
  it('Enables features synchronously in development, before validation resolves', () => {
@@ -1020,6 +1047,7 @@ describe('LicenseManager', () => {
1020
1047
  const devLicenseManager = new LicenseManager('', keyPair.publicKey)
1021
1048
  expect(devLicenseManager.isFeatureEnabled('commenting')).toBe(true)
1022
1049
  expect(devLicenseManager.isFeatureEnabled('collaboration')).toBe(true)
1050
+ expect(devLicenseManager.isFeatureEnabled('libraries')).toBe(true)
1023
1051
  } finally {
1024
1052
  process.env.NODE_ENV = 'test'
1025
1053
  }
@@ -1083,7 +1111,7 @@ describe('LicenseManager', () => {
1083
1111
  describe('License expiry and grace period', () => {
1084
1112
  it('Fails if the license key has expired beyond grace period', async () => {
1085
1113
  const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
1086
- const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 40) // 40 days ago (beyond 30-day grace period)
1114
+ const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 10)
1087
1115
  expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiryDate
1088
1116
  const expiredLicenseKey = await generateLicenseKey(
1089
1117
  JSON.stringify(expiredLicenseInfo),
@@ -1097,7 +1125,7 @@ describe('LicenseManager', () => {
1097
1125
 
1098
1126
  it('Allows a grace period for expired licenses', async () => {
1099
1127
  const almostExpiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
1100
- const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 5) // 5 days ago
1128
+ const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 4)
1101
1129
  almostExpiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiryDate
1102
1130
  const almostExpiredLicenseKey = await generateLicenseKey(
1103
1131
  JSON.stringify(almostExpiredLicenseInfo),
@@ -1109,15 +1137,15 @@ describe('LicenseManager', () => {
1109
1137
  expect(result.isAnnualLicenseExpired).toBe(false)
1110
1138
  })
1111
1139
 
1112
- it('Handles grace period correctly - 20 days expired should still be within grace period', async () => {
1140
+ it('Handles grace period correctly - 4 days expired should still be within grace period', async () => {
1113
1141
  // Pin the clock and use a date-only UTC expiry so the calculation is timezone
1114
- // independent. The named day is fully usable, so an expiry 20 calendar days before
1115
- // "now" has been past its usable window for 19 full days.
1142
+ // independent. The named day is fully usable, so an expiry 4 calendar days before
1143
+ // "now" has been past its usable window for 3 full days.
1116
1144
  vi.useFakeTimers()
1117
1145
  vi.setSystemTime(new Date('2026-06-26T12:00:00.000Z'))
1118
1146
  try {
1119
1147
  const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
1120
- expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = '2026-06-06' // 20 days before now
1148
+ expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = '2026-06-22' // 4 days before now
1121
1149
 
1122
1150
  const expiredLicenseKey = await generateLicenseKey(
1123
1151
  JSON.stringify(expiredLicenseInfo),
@@ -1129,8 +1157,8 @@ describe('LicenseManager', () => {
1129
1157
  expiredLicenseKey
1130
1158
  )) as ValidLicenseKeyResult
1131
1159
  expect(result.isAnnualLicense).toBe(true)
1132
- expect(result.isAnnualLicenseExpired).toBe(false) // Within 30-day grace period
1133
- expect(result.daysSinceExpiry).toBe(19)
1160
+ expect(result.isAnnualLicenseExpired).toBe(false) // Within grace period
1161
+ expect(result.daysSinceExpiry).toBe(3)
1134
1162
  } finally {
1135
1163
  vi.useRealTimers()
1136
1164
  }
@@ -1311,6 +1339,7 @@ function getDefaultLicenseResult(overrides: Partial<ValidLicenseKeyResult>): Val
1311
1339
  isEvaluationLicenseExpired: false,
1312
1340
  isCollaborationEnabled: false,
1313
1341
  isCommentingEnabled: false,
1342
+ isLibrariesEnabled: false,
1314
1343
  daysSinceExpiry: 0,
1315
1344
  // WatermarkManager does not check these fields, it relies on the calculated values like isAnnualLicenseExpired
1316
1345
  license: {
@@ -1495,12 +1524,12 @@ describe('getLicenseState', () => {
1495
1524
  })
1496
1525
 
1497
1526
  describe('Grace period handling', () => {
1498
- it('returns "licensed" for license 0-30 days past expiry', () => {
1527
+ it('returns "licensed" for license within grace period', () => {
1499
1528
  const messages: string[][] = []
1500
1529
  const licenseResult = getDefaultLicenseResult({
1501
1530
  isAnnualLicense: true,
1502
- isAnnualLicenseExpired: false, // Still within 30-day grace period
1503
- daysSinceExpiry: 20, // 20 days past expiry
1531
+ isAnnualLicenseExpired: false, // Still within grace period
1532
+ daysSinceExpiry: 4,
1504
1533
  isInternalLicense: false,
1505
1534
  })
1506
1535
 
@@ -1509,19 +1538,19 @@ describe('getLicenseState', () => {
1509
1538
  expect(messages).toHaveLength(1)
1510
1539
  expect(messages[0]).toEqual([
1511
1540
  'Your tldraw license has expired.',
1512
- 'License expired 20 days ago.',
1541
+ 'License expired 4 days ago.',
1513
1542
  'Please reach out to sales@tldraw.com to renew your license.',
1514
1543
  ])
1515
1544
  })
1516
1545
  })
1517
1546
 
1518
1547
  describe('Expired licenses', () => {
1519
- it('returns "expired" for license 30+ days past expiry', () => {
1548
+ it('returns "expired" for license past expiry+grace period', () => {
1520
1549
  const messages: string[][] = []
1521
1550
  const licenseResult = getDefaultLicenseResult({
1522
1551
  isAnnualLicense: true,
1523
- isAnnualLicenseExpired: true, // Beyond 30-day grace period
1524
- daysSinceExpiry: 35, // 35 days past expiry
1552
+ isAnnualLicenseExpired: true, // Beyond grace period
1553
+ daysSinceExpiry: 10,
1525
1554
  isInternalLicense: false,
1526
1555
  })
1527
1556
 
@@ -1529,7 +1558,7 @@ describe('getLicenseState', () => {
1529
1558
 
1530
1559
  expect(messages).toHaveLength(1)
1531
1560
  expect(messages[0]).toEqual([
1532
- 'Your tldraw license has been expired for more than 30 days!',
1561
+ `Your tldraw license has been expired for more than ${EXPECTED_GRACE_PERIOD_DAYS} days!`,
1533
1562
  'Please reach out to sales@tldraw.com to renew your license.',
1534
1563
  ])
1535
1564
  })
@@ -1586,7 +1615,7 @@ describe('getLicenseState', () => {
1586
1615
 
1587
1616
  expect(messages).toHaveLength(1)
1588
1617
  expect(messages[0]).toEqual([
1589
- 'Your tldraw license has been expired for more than 30 days!',
1618
+ `Your tldraw license has been expired for more than ${EXPECTED_GRACE_PERIOD_DAYS} days!`,
1590
1619
  'Please reach out to sales@tldraw.com to renew your license.',
1591
1620
  ])
1592
1621
  })
@@ -1606,7 +1635,7 @@ describe('getLicenseState', () => {
1606
1635
 
1607
1636
  expect(messages).toHaveLength(1)
1608
1637
  expect(messages[0]).toEqual([
1609
- 'Your tldraw license has been expired for more than 30 days!',
1638
+ `Your tldraw license has been expired for more than ${EXPECTED_GRACE_PERIOD_DAYS} days!`,
1610
1639
  'Please reach out to sales@tldraw.com to renew your license.',
1611
1640
  ])
1612
1641
  })
@@ -1618,10 +1647,12 @@ describe('getEnabledFeatures', () => {
1618
1647
  const result = getDefaultLicenseResult({
1619
1648
  isCollaborationEnabled: false,
1620
1649
  isCommentingEnabled: false,
1650
+ isLibrariesEnabled: false,
1621
1651
  })
1622
1652
  expect(getEnabledFeatures(result, 'unlicensed', true)).toEqual({
1623
1653
  collaboration: true,
1624
1654
  commenting: true,
1655
+ libraries: true,
1625
1656
  })
1626
1657
  })
1627
1658
 
@@ -1633,6 +1664,7 @@ describe('getEnabledFeatures', () => {
1633
1664
  expect(getEnabledFeatures(result, 'licensed', false)).toEqual({
1634
1665
  collaboration: false,
1635
1666
  commenting: true,
1667
+ libraries: false,
1636
1668
  })
1637
1669
  })
1638
1670
 
@@ -1640,10 +1672,12 @@ describe('getEnabledFeatures', () => {
1640
1672
  const result = getDefaultLicenseResult({
1641
1673
  isCollaborationEnabled: true,
1642
1674
  isCommentingEnabled: true,
1675
+ isLibrariesEnabled: true,
1643
1676
  })
1644
1677
  expect(getEnabledFeatures(result, 'licensed-with-watermark', false)).toEqual({
1645
1678
  collaboration: true,
1646
1679
  commenting: true,
1680
+ libraries: true,
1647
1681
  })
1648
1682
  })
1649
1683
 
@@ -1653,10 +1687,12 @@ describe('getEnabledFeatures', () => {
1653
1687
  const result = getDefaultLicenseResult({
1654
1688
  isCollaborationEnabled: true,
1655
1689
  isCommentingEnabled: true,
1690
+ isLibrariesEnabled: true,
1656
1691
  })
1657
1692
  expect(getEnabledFeatures(result, state, false)).toEqual({
1658
1693
  collaboration: false,
1659
1694
  commenting: false,
1695
+ libraries: false,
1660
1696
  })
1661
1697
  }
1662
1698
  )
@@ -1666,10 +1702,12 @@ describe('getEnabledFeatures', () => {
1666
1702
  isEvaluationLicense: true,
1667
1703
  isCollaborationEnabled: false,
1668
1704
  isCommentingEnabled: false,
1705
+ isLibrariesEnabled: false,
1669
1706
  })
1670
1707
  expect(getEnabledFeatures(result, 'licensed', false)).toEqual({
1671
1708
  collaboration: true,
1672
1709
  commenting: true,
1710
+ libraries: true,
1673
1711
  })
1674
1712
  })
1675
1713
 
@@ -1679,10 +1717,12 @@ describe('getEnabledFeatures', () => {
1679
1717
  isEvaluationLicenseExpired: true,
1680
1718
  isCollaborationEnabled: false,
1681
1719
  isCommentingEnabled: false,
1720
+ isLibrariesEnabled: false,
1682
1721
  })
1683
1722
  expect(getEnabledFeatures(result, 'expired', false)).toEqual({
1684
1723
  collaboration: false,
1685
1724
  commenting: false,
1725
+ libraries: false,
1686
1726
  })
1687
1727
  })
1688
1728
 
@@ -1696,6 +1736,7 @@ describe('getEnabledFeatures', () => {
1696
1736
  ).toEqual({
1697
1737
  collaboration: false,
1698
1738
  commenting: false,
1739
+ libraries: false,
1699
1740
  })
1700
1741
  })
1701
1742
  })