@tldraw/editor 5.3.0-canary.fa3355c81e86 → 5.3.0-internal.1640468db8fd
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.
- package/dist-cjs/index.d.ts +29 -0
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +7 -2
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/hooks/useCursor.js +1 -0
- package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
- package/dist-cjs/lib/license/LicenseManager.js +48 -2
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/useLicenseManagerState.js +7 -0
- package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +29 -0
- package/dist-esm/index.mjs +5 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +7 -2
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCursor.mjs +1 -0
- package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseManager.mjs +49 -3
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/useLicenseManagerState.mjs +7 -0
- package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +4 -0
- package/package.json +7 -7
- package/src/index.ts +3 -1
- package/src/lib/editor/Editor.ts +14 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +24 -0
- package/src/lib/hooks/useCursor.ts +1 -0
- package/src/lib/license/LicenseManager.test.ts +121 -0
- package/src/lib/license/LicenseManager.ts +91 -2
- package/src/lib/license/useLicenseManagerState.ts +17 -1
- package/src/version.ts +3 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "tldraw infinite canvas SDK (editor).",
|
|
4
|
-
"version": "5.3.0-
|
|
4
|
+
"version": "5.3.0-internal.1640468db8fd",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"@tiptap/core": "^3.12.1",
|
|
50
50
|
"@tiptap/pm": "^3.12.1",
|
|
51
51
|
"@tiptap/react": "^3.12.1",
|
|
52
|
-
"@tldraw/state": "5.3.0-
|
|
53
|
-
"@tldraw/state-react": "5.3.0-
|
|
54
|
-
"@tldraw/store": "5.3.0-
|
|
55
|
-
"@tldraw/tlschema": "5.3.0-
|
|
56
|
-
"@tldraw/utils": "5.3.0-
|
|
57
|
-
"@tldraw/validate": "5.3.0-
|
|
52
|
+
"@tldraw/state": "5.3.0-internal.1640468db8fd",
|
|
53
|
+
"@tldraw/state-react": "5.3.0-internal.1640468db8fd",
|
|
54
|
+
"@tldraw/store": "5.3.0-internal.1640468db8fd",
|
|
55
|
+
"@tldraw/tlschema": "5.3.0-internal.1640468db8fd",
|
|
56
|
+
"@tldraw/utils": "5.3.0-internal.1640468db8fd",
|
|
57
|
+
"@tldraw/validate": "5.3.0-internal.1640468db8fd",
|
|
58
58
|
"classnames": "^2.5.1",
|
|
59
59
|
"eventemitter3": "^4.0.7",
|
|
60
60
|
"idb": "^7.1.1",
|
package/src/index.ts
CHANGED
|
@@ -324,12 +324,14 @@ export {
|
|
|
324
324
|
LicenseManager,
|
|
325
325
|
type InvalidLicenseKeyResult,
|
|
326
326
|
type InvalidLicenseReason,
|
|
327
|
+
type LicenseFeatureName,
|
|
327
328
|
type LicenseFromKeyResult,
|
|
328
329
|
type LicenseInfo,
|
|
329
330
|
type LicenseState,
|
|
330
331
|
type ValidLicenseKeyResult,
|
|
331
332
|
} from './lib/license/LicenseManager'
|
|
332
|
-
export { LICENSE_TIMEOUT } from './lib/license/LicenseProvider'
|
|
333
|
+
export { LICENSE_TIMEOUT, useLicenseContext } from './lib/license/LicenseProvider'
|
|
334
|
+
export { useLicenseFeatureFlag } from './lib/license/useLicenseManagerState'
|
|
333
335
|
export {
|
|
334
336
|
defaultTldrawOptions,
|
|
335
337
|
type TLClipboardPasteRawInfo,
|
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -7145,7 +7145,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7145
7145
|
|
|
7146
7146
|
shape.index = index
|
|
7147
7147
|
})
|
|
7148
|
-
const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) =>
|
|
7148
|
+
const shapesToCreate = shapesToCreateWithOriginals.map(({ shape, originalShape }) => {
|
|
7149
|
+
// Give the shape util a chance to modify the duplicate, e.g. to re-stamp note
|
|
7150
|
+
// attribution to the current user so we don't forge the original author's identity.
|
|
7151
|
+
return this.getShapeUtil(shape).onBeforeDuplicate?.(originalShape, shape) ?? shape
|
|
7152
|
+
})
|
|
7149
7153
|
|
|
7150
7154
|
if (!this.canCreateShapes(shapesToCreate)) {
|
|
7151
7155
|
alertMaxShapes(this)
|
|
@@ -10039,7 +10043,15 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
10039
10043
|
const newId = shapeIdMap.get(oldShape.id)!
|
|
10040
10044
|
|
|
10041
10045
|
// Create the new shape (new except for the id)
|
|
10042
|
-
|
|
10046
|
+
let newShape = { ...oldShape, id: newId }
|
|
10047
|
+
|
|
10048
|
+
// Give the shape util a chance to modify the copy, e.g. to re-stamp note
|
|
10049
|
+
// attribution to the current user so we don't forge the original author's identity.
|
|
10050
|
+
// When ids are preserved the shape keeps its identity (e.g. moveShapesToPage
|
|
10051
|
+
// relocating it), so it's not a duplicate and the hook must not run.
|
|
10052
|
+
if (!preserveIds) {
|
|
10053
|
+
newShape = this.getShapeUtil(newShape).onBeforeDuplicate?.(oldShape, newShape) ?? newShape
|
|
10054
|
+
}
|
|
10043
10055
|
|
|
10044
10056
|
if (rootShapeIds.includes(oldShape.id)) {
|
|
10045
10057
|
newShape.parentId = currentPageId
|
|
@@ -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.
|
|
@@ -4,6 +4,7 @@ import { publishDates } from '../../version'
|
|
|
4
4
|
import { str2ab } from '../utils/licensing'
|
|
5
5
|
import {
|
|
6
6
|
FLAGS,
|
|
7
|
+
getEnabledFeatures,
|
|
7
8
|
getLicenseState,
|
|
8
9
|
LicenseManager,
|
|
9
10
|
PROPERTIES,
|
|
@@ -508,6 +509,62 @@ describe('LicenseManager', () => {
|
|
|
508
509
|
expect(result.isEvaluationLicense).toBe(true)
|
|
509
510
|
expect(result.isEvaluationLicenseExpired).toBe(true)
|
|
510
511
|
})
|
|
512
|
+
|
|
513
|
+
it('Checks for the commenting feature flag', async () => {
|
|
514
|
+
const commentingLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
515
|
+
commentingLicenseInfo[PROPERTIES.FLAGS] |= FLAGS.FEAT_COMMENTING
|
|
516
|
+
const commentingLicenseKey = await generateLicenseKey(
|
|
517
|
+
JSON.stringify(commentingLicenseInfo),
|
|
518
|
+
keyPair
|
|
519
|
+
)
|
|
520
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
521
|
+
commentingLicenseKey
|
|
522
|
+
)) as ValidLicenseKeyResult
|
|
523
|
+
expect(result.isCommentingEnabled).toBe(true)
|
|
524
|
+
expect(result.isCollaborationEnabled).toBe(false)
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
it('Checks for the collaboration feature flag', async () => {
|
|
528
|
+
const collaborationLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
529
|
+
collaborationLicenseInfo[PROPERTIES.FLAGS] |= FLAGS.FEAT_COLLABORATION
|
|
530
|
+
const collaborationLicenseKey = await generateLicenseKey(
|
|
531
|
+
JSON.stringify(collaborationLicenseInfo),
|
|
532
|
+
keyPair
|
|
533
|
+
)
|
|
534
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
535
|
+
collaborationLicenseKey
|
|
536
|
+
)) as ValidLicenseKeyResult
|
|
537
|
+
expect(result.isCollaborationEnabled).toBe(true)
|
|
538
|
+
// The collaboration umbrella grants the commenting sub-feature.
|
|
539
|
+
expect(result.isCommentingEnabled).toBe(true)
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
it('Leaves feature flags off when no feature bits are set', async () => {
|
|
543
|
+
const standardLicenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
544
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
545
|
+
standardLicenseKey
|
|
546
|
+
)) as ValidLicenseKeyResult
|
|
547
|
+
expect(result.isCollaborationEnabled).toBe(false)
|
|
548
|
+
expect(result.isCommentingEnabled).toBe(false)
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
it('Enables features synchronously in development, before validation resolves', () => {
|
|
552
|
+
process.env.NODE_ENV = 'development'
|
|
553
|
+
// @ts-ignore
|
|
554
|
+
delete window.location
|
|
555
|
+
// @ts-ignore
|
|
556
|
+
window.location = new URL('https://www.example.com')
|
|
557
|
+
|
|
558
|
+
try {
|
|
559
|
+
// No await: the feature flags should already reflect development (all enabled) rather
|
|
560
|
+
// than the fail-closed default, which only lifts once async validation resolves.
|
|
561
|
+
const devLicenseManager = new LicenseManager('', keyPair.publicKey)
|
|
562
|
+
expect(devLicenseManager.isFeatureEnabled('commenting')).toBe(true)
|
|
563
|
+
expect(devLicenseManager.isFeatureEnabled('collaboration')).toBe(true)
|
|
564
|
+
} finally {
|
|
565
|
+
process.env.NODE_ENV = 'test'
|
|
566
|
+
}
|
|
567
|
+
})
|
|
511
568
|
})
|
|
512
569
|
|
|
513
570
|
describe('Expiry date timezone handling', () => {
|
|
@@ -793,6 +850,8 @@ function getDefaultLicenseResult(overrides: Partial<ValidLicenseKeyResult>): Val
|
|
|
793
850
|
isLicensedWithWatermark: false,
|
|
794
851
|
isEvaluationLicense: false,
|
|
795
852
|
isEvaluationLicenseExpired: false,
|
|
853
|
+
isCollaborationEnabled: false,
|
|
854
|
+
isCommentingEnabled: false,
|
|
796
855
|
daysSinceExpiry: 0,
|
|
797
856
|
// WatermarkManager does not check these fields, it relies on the calculated values like isAnnualLicenseExpired
|
|
798
857
|
license: {
|
|
@@ -1094,3 +1153,65 @@ describe('getLicenseState', () => {
|
|
|
1094
1153
|
})
|
|
1095
1154
|
})
|
|
1096
1155
|
})
|
|
1156
|
+
|
|
1157
|
+
describe('getEnabledFeatures', () => {
|
|
1158
|
+
it('enables every feature in development regardless of flags', () => {
|
|
1159
|
+
const result = getDefaultLicenseResult({
|
|
1160
|
+
isCollaborationEnabled: false,
|
|
1161
|
+
isCommentingEnabled: false,
|
|
1162
|
+
})
|
|
1163
|
+
expect(getEnabledFeatures(result, 'unlicensed', true)).toEqual({
|
|
1164
|
+
collaboration: true,
|
|
1165
|
+
commenting: true,
|
|
1166
|
+
})
|
|
1167
|
+
})
|
|
1168
|
+
|
|
1169
|
+
it('reflects the license flags for a valid licensed state', () => {
|
|
1170
|
+
const result = getDefaultLicenseResult({
|
|
1171
|
+
isCollaborationEnabled: false,
|
|
1172
|
+
isCommentingEnabled: true,
|
|
1173
|
+
})
|
|
1174
|
+
expect(getEnabledFeatures(result, 'licensed', false)).toEqual({
|
|
1175
|
+
collaboration: false,
|
|
1176
|
+
commenting: true,
|
|
1177
|
+
})
|
|
1178
|
+
})
|
|
1179
|
+
|
|
1180
|
+
it('still grants features while showing a watermark', () => {
|
|
1181
|
+
const result = getDefaultLicenseResult({
|
|
1182
|
+
isCollaborationEnabled: true,
|
|
1183
|
+
isCommentingEnabled: true,
|
|
1184
|
+
})
|
|
1185
|
+
expect(getEnabledFeatures(result, 'licensed-with-watermark', false)).toEqual({
|
|
1186
|
+
collaboration: true,
|
|
1187
|
+
commenting: true,
|
|
1188
|
+
})
|
|
1189
|
+
})
|
|
1190
|
+
|
|
1191
|
+
it.each(['unlicensed', 'unlicensed-production', 'expired', 'pending'] as const)(
|
|
1192
|
+
'disables all features for the %s state in production',
|
|
1193
|
+
(state) => {
|
|
1194
|
+
const result = getDefaultLicenseResult({
|
|
1195
|
+
isCollaborationEnabled: true,
|
|
1196
|
+
isCommentingEnabled: true,
|
|
1197
|
+
})
|
|
1198
|
+
expect(getEnabledFeatures(result, state, false)).toEqual({
|
|
1199
|
+
collaboration: false,
|
|
1200
|
+
commenting: false,
|
|
1201
|
+
})
|
|
1202
|
+
}
|
|
1203
|
+
)
|
|
1204
|
+
|
|
1205
|
+
it('disables all features when the license is not parseable', () => {
|
|
1206
|
+
expect(
|
|
1207
|
+
getEnabledFeatures(
|
|
1208
|
+
{ isLicenseParseable: false, reason: 'no-key-provided' },
|
|
1209
|
+
'licensed',
|
|
1210
|
+
false
|
|
1211
|
+
)
|
|
1212
|
+
).toEqual({
|
|
1213
|
+
collaboration: false,
|
|
1214
|
+
commenting: false,
|
|
1215
|
+
})
|
|
1216
|
+
})
|
|
1217
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { atom } from '@tldraw/state'
|
|
1
|
+
import { atom, transact } from '@tldraw/state'
|
|
2
2
|
import { publishDates, version } from '../../version'
|
|
3
3
|
import { getDefaultCdnBaseUrl } from '../utils/assets'
|
|
4
4
|
import { importPublicKey, str2ab } from '../utils/licensing'
|
|
@@ -22,6 +22,12 @@ export const FLAGS = {
|
|
|
22
22
|
// Native means the license is for native apps which switches
|
|
23
23
|
// on special-case logic.
|
|
24
24
|
NATIVE_LICENSE: 1 << 5,
|
|
25
|
+
|
|
26
|
+
// -- FEATURE FLAGS --
|
|
27
|
+
// Collaboration is the umbrella flag for collaboration features; it grants all sub-features.
|
|
28
|
+
FEAT_COLLABORATION: 1 << 6,
|
|
29
|
+
// Commenting is the first sub-feature of collaboration.
|
|
30
|
+
FEAT_COMMENTING: 1 << 7,
|
|
25
31
|
}
|
|
26
32
|
const HIGHEST_FLAG = Math.max(...Object.values(FLAGS))
|
|
27
33
|
|
|
@@ -45,6 +51,23 @@ export interface LicenseInfo {
|
|
|
45
51
|
expiryDate: string
|
|
46
52
|
}
|
|
47
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Names of the licensable product features gated by the license. `collaboration` is an umbrella
|
|
56
|
+
* that also grants all of its sub-features (currently just `commenting`).
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export type LicenseFeatureName = 'collaboration' | 'commenting'
|
|
61
|
+
|
|
62
|
+
const NO_FEATURES: Readonly<Record<LicenseFeatureName, boolean>> = {
|
|
63
|
+
collaboration: false,
|
|
64
|
+
commenting: false,
|
|
65
|
+
}
|
|
66
|
+
const ALL_FEATURES: Readonly<Record<LicenseFeatureName, boolean>> = {
|
|
67
|
+
collaboration: true,
|
|
68
|
+
commenting: true,
|
|
69
|
+
}
|
|
70
|
+
|
|
48
71
|
/** @internal */
|
|
49
72
|
export type LicenseState =
|
|
50
73
|
| 'pending' // License validation is in progress
|
|
@@ -84,6 +107,8 @@ export interface ValidLicenseKeyResult {
|
|
|
84
107
|
isLicensedWithWatermark: boolean
|
|
85
108
|
isEvaluationLicense: boolean
|
|
86
109
|
isEvaluationLicenseExpired: boolean
|
|
110
|
+
isCollaborationEnabled: boolean
|
|
111
|
+
isCommentingEnabled: boolean
|
|
87
112
|
daysSinceExpiry: number
|
|
88
113
|
}
|
|
89
114
|
|
|
@@ -98,6 +123,9 @@ export class LicenseManager {
|
|
|
98
123
|
public isTest: boolean
|
|
99
124
|
public isCryptoAvailable: boolean
|
|
100
125
|
state = atom<LicenseState>('license state', 'pending')
|
|
126
|
+
featureFlags = atom<Record<LicenseFeatureName, boolean>>('license feature flags', {
|
|
127
|
+
...NO_FEATURES,
|
|
128
|
+
})
|
|
101
129
|
public verbose = true
|
|
102
130
|
|
|
103
131
|
constructor(licenseKey: string | undefined, testPublicKey?: string) {
|
|
@@ -106,6 +134,14 @@ export class LicenseManager {
|
|
|
106
134
|
this.publicKey = testPublicKey || this.publicKey
|
|
107
135
|
this.isCryptoAvailable = !!crypto.subtle
|
|
108
136
|
|
|
137
|
+
// In development every feature is enabled (see `getEnabledFeatures`), and that doesn't depend
|
|
138
|
+
// on the async validation result. Reflect it eagerly so features aren't reported as disabled
|
|
139
|
+
// during the validation window — or left disabled if validation rejects (the `.catch` below
|
|
140
|
+
// never sets `featureFlags`). In production the fail-closed default stands until validation.
|
|
141
|
+
if (this.isDevelopment) {
|
|
142
|
+
this.featureFlags.set({ ...ALL_FEATURES })
|
|
143
|
+
}
|
|
144
|
+
|
|
109
145
|
this.getLicenseFromKey(licenseKey)
|
|
110
146
|
.then((result) => {
|
|
111
147
|
const licenseState = getLicenseState(
|
|
@@ -116,7 +152,12 @@ export class LicenseManager {
|
|
|
116
152
|
|
|
117
153
|
this.maybeTrack(result, licenseState)
|
|
118
154
|
|
|
119
|
-
|
|
155
|
+
// Update both atoms atomically so dependents never observe the license state and the
|
|
156
|
+
// feature flags out of sync mid-update.
|
|
157
|
+
transact(() => {
|
|
158
|
+
this.state.set(licenseState)
|
|
159
|
+
this.featureFlags.set(getEnabledFeatures(result, licenseState, this.isDevelopment))
|
|
160
|
+
})
|
|
120
161
|
})
|
|
121
162
|
.catch((error) => {
|
|
122
163
|
console.error('License validation failed:', error)
|
|
@@ -124,6 +165,14 @@ export class LicenseManager {
|
|
|
124
165
|
})
|
|
125
166
|
}
|
|
126
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Returns whether a given licensable feature is enabled. Reactive: reading this inside a signal
|
|
170
|
+
* recomputes when license validation resolves.
|
|
171
|
+
*/
|
|
172
|
+
isFeatureEnabled(feature: LicenseFeatureName): boolean {
|
|
173
|
+
return this.featureFlags.get()[feature]
|
|
174
|
+
}
|
|
175
|
+
|
|
127
176
|
private getIsDevelopment() {
|
|
128
177
|
// If we are using https on a non-loopback domain we assume it's a production env and a development one otherwise
|
|
129
178
|
return (
|
|
@@ -286,6 +335,12 @@ export class LicenseManager {
|
|
|
286
335
|
const isPerpetualLicenseExpired =
|
|
287
336
|
isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate)
|
|
288
337
|
|
|
338
|
+
// The collaboration umbrella grants all of its sub-features, so commenting is enabled
|
|
339
|
+
// by either the commenting flag or the collaboration flag.
|
|
340
|
+
const isCollaborationEnabled = this.isFlagEnabled(licenseInfo.flags, FLAGS.FEAT_COLLABORATION)
|
|
341
|
+
const isCommentingEnabled =
|
|
342
|
+
isCollaborationEnabled || this.isFlagEnabled(licenseInfo.flags, FLAGS.FEAT_COMMENTING)
|
|
343
|
+
|
|
289
344
|
// For perpetual licenses, the calendar expiry date only gates access to future
|
|
290
345
|
// major/minor releases; it does not "expire" the license itself. While the user
|
|
291
346
|
// is still on a covered version we report `daysSinceExpiry` as 0 so consumers
|
|
@@ -309,6 +364,8 @@ export class LicenseManager {
|
|
|
309
364
|
isEvaluationLicense,
|
|
310
365
|
isEvaluationLicenseExpired:
|
|
311
366
|
isEvaluationLicense && this.isEvaluationLicenseExpired(expiryDate),
|
|
367
|
+
isCollaborationEnabled,
|
|
368
|
+
isCommentingEnabled,
|
|
312
369
|
daysSinceExpiry,
|
|
313
370
|
}
|
|
314
371
|
this.outputLicenseInfoIfNeeded(result)
|
|
@@ -483,6 +540,38 @@ export class LicenseManager {
|
|
|
483
540
|
static className = 'tl-watermark_SEE-LICENSE'
|
|
484
541
|
}
|
|
485
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Derives which licensable features are enabled from the parse result and the derived license
|
|
545
|
+
* state. In development every feature is enabled so SDK developers can build against them; in
|
|
546
|
+
* production a feature requires both an active, valid license and the corresponding flag.
|
|
547
|
+
*
|
|
548
|
+
* @internal
|
|
549
|
+
*/
|
|
550
|
+
export function getEnabledFeatures(
|
|
551
|
+
result: LicenseFromKeyResult,
|
|
552
|
+
licenseState: LicenseState,
|
|
553
|
+
isDevelopment: boolean
|
|
554
|
+
): Record<LicenseFeatureName, boolean> {
|
|
555
|
+
// Development gets all features so SDK developers can build against them.
|
|
556
|
+
if (isDevelopment) {
|
|
557
|
+
return { ...ALL_FEATURES }
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// Features require an active, valid license. Both the 30-day grace-period 'licensed' state and
|
|
561
|
+
// the watermark state count as valid; unlicensed/expired/pending do not.
|
|
562
|
+
if (
|
|
563
|
+
!result.isLicenseParseable ||
|
|
564
|
+
(licenseState !== 'licensed' && licenseState !== 'licensed-with-watermark')
|
|
565
|
+
) {
|
|
566
|
+
return { ...NO_FEATURES }
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
return {
|
|
570
|
+
collaboration: result.isCollaborationEnabled,
|
|
571
|
+
commenting: result.isCommentingEnabled,
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
486
575
|
export function getLicenseState(
|
|
487
576
|
result: LicenseFromKeyResult,
|
|
488
577
|
outputMessages: (messages: string[]) => void,
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { useValue } from '@tldraw/state-react'
|
|
2
|
-
import { LicenseManager, LicenseState } from './LicenseManager'
|
|
2
|
+
import { LicenseFeatureName, LicenseManager, LicenseState } from './LicenseManager'
|
|
3
3
|
|
|
4
4
|
/** @internal */
|
|
5
5
|
export function useLicenseManagerState(licenseManager: LicenseManager): LicenseState {
|
|
6
6
|
return useValue('watermarkState', () => licenseManager.state.get(), [licenseManager])
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reactively reads whether a licensable feature is enabled for the current license. Re-renders when
|
|
11
|
+
* license validation resolves.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function useLicenseFeatureFlag(
|
|
16
|
+
licenseManager: LicenseManager,
|
|
17
|
+
feature: LicenseFeatureName
|
|
18
|
+
): boolean {
|
|
19
|
+
return useValue('licenseFeature', () => licenseManager.isFeatureEnabled(feature), [
|
|
20
|
+
licenseManager,
|
|
21
|
+
feature,
|
|
22
|
+
])
|
|
23
|
+
}
|
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-
|
|
4
|
+
export const version = '5.3.0-internal.1640468db8fd'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2026-05-06T16:28:18.473Z',
|
|
7
|
-
minor: '2026-07-
|
|
8
|
-
patch: '2026-07-
|
|
7
|
+
minor: '2026-07-23T13:41:51.397Z',
|
|
8
|
+
patch: '2026-07-23T13:41:51.397Z',
|
|
9
9
|
}
|