@tldraw/editor 5.3.1 → 5.3.2

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 (39) hide show
  1. package/dist-cjs/index.d.ts +3 -0
  2. package/dist-cjs/index.js +2 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +3 -0
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/editor/Editor.js +8 -0
  7. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  8. package/dist-cjs/lib/license/LicenseManager.js +9 -2
  9. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  10. package/dist-cjs/lib/license/LicenseProvider.js +16 -3
  11. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  12. package/dist-cjs/lib/license/useLicenseManagerState.js +5 -4
  13. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  14. package/dist-cjs/version.js +2 -2
  15. package/dist-cjs/version.js.map +1 -1
  16. package/dist-esm/index.d.mts +3 -0
  17. package/dist-esm/index.mjs +7 -2
  18. package/dist-esm/index.mjs.map +2 -2
  19. package/dist-esm/lib/TldrawEditor.mjs +4 -1
  20. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  21. package/dist-esm/lib/editor/Editor.mjs +8 -0
  22. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  23. package/dist-esm/lib/license/LicenseManager.mjs +9 -2
  24. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  25. package/dist-esm/lib/license/LicenseProvider.mjs +16 -3
  26. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  27. package/dist-esm/lib/license/useLicenseManagerState.mjs +5 -4
  28. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  29. package/dist-esm/version.mjs +2 -2
  30. package/dist-esm/version.mjs.map +1 -1
  31. package/package.json +13 -7
  32. package/src/index.ts +5 -1
  33. package/src/lib/TldrawEditor.tsx +4 -1
  34. package/src/lib/editor/Editor.ts +10 -0
  35. package/src/lib/license/LicenseManager.test.ts +160 -0
  36. package/src/lib/license/LicenseManager.ts +13 -4
  37. package/src/lib/license/LicenseProvider.tsx +24 -3
  38. package/src/lib/license/useLicenseManagerState.ts +8 -6
  39. package/src/version.ts +2 -2
@@ -174,10 +174,17 @@ export class LicenseManager {
174
174
  }
175
175
 
176
176
  private getIsDevelopment() {
177
- // If we are using https on a non-loopback domain we assume it's a production env and a development one otherwise
177
+ const protocol = window.location.protocol
178
+ const hostname = window.location.hostname
179
+
180
+ // Tauri uses `tauri://localhost` on macOS and Linux and `http://tauri.localhost` on Windows.
181
+ if (hostname.toLowerCase().endsWith('.localhost')) {
182
+ return process.env.NODE_ENV !== 'production'
183
+ }
184
+
178
185
  return (
179
- !['https:', 'vscode-webview:'].includes(window.location.protocol) ||
180
- this.isLoopbackHost(window.location.hostname) ||
186
+ protocol === 'http:' ||
187
+ (protocol === 'https:' && this.isLoopbackHost(hostname)) ||
181
188
  process.env.NODE_ENV !== 'production'
182
189
  )
183
190
  }
@@ -407,7 +414,9 @@ export class LicenseManager {
407
414
 
408
415
  // Glob testing, we only support '*.somedomain.com' right now.
409
416
  if (host.includes('*')) {
410
- const globToRegex = new RegExp(host.replace(/\*/g, '.*?'))
417
+ const globToRegex = new RegExp(
418
+ normalizedHostOrUrlRegex.replace(/\./g, '\\.').replace(/\*/g, '.*?') + '$'
419
+ )
411
420
  return globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)
412
421
  }
413
422
 
@@ -1,13 +1,34 @@
1
1
  import { useValue } from '@tldraw/state-react'
2
2
  import { createContext, ReactNode, useContext, useEffect, useState } from 'react'
3
+ import { useMaybeEditor } from '../hooks/useEditor'
3
4
  import { LicenseManager } from './LicenseManager'
4
5
 
5
6
  /** @internal */
6
- export const LicenseContext = createContext({} as LicenseManager)
7
+ export const LicenseContext = createContext<LicenseManager | null>(null)
7
8
 
8
9
  /** @internal */
9
- export function useLicenseContext() {
10
- return useContext(LicenseContext)
10
+ export function useLicenseContext(): LicenseManager {
11
+ const licenseManager = useMaybeLicenseManager()
12
+ if (!licenseManager) {
13
+ throw new Error(
14
+ 'useLicenseContext must be used inside of the <Tldraw /> or <TldrawEditor /> components, or inside an <EditorProvider /> wrapping an editor created by them'
15
+ )
16
+ }
17
+ return licenseManager
18
+ }
19
+
20
+ /**
21
+ * Returns the license manager for the current editor, or `null` if there is none. Reads the
22
+ * license context when inside `<TldrawEditor />`, and otherwise falls back to the license manager
23
+ * of the nearest editor, so UI mounted outside the editor tree (via `EditorProvider`) resolves the
24
+ * same license as the editor it belongs to.
25
+ *
26
+ * @internal
27
+ */
28
+ export function useMaybeLicenseManager(): LicenseManager | null {
29
+ const licenseManager = useContext(LicenseContext)
30
+ const editor = useMaybeEditor()
31
+ return licenseManager ?? editor?.licenseManager ?? null
11
32
  }
12
33
 
13
34
  function shouldHideEditorAfterDelay(licenseState: string): boolean {
@@ -8,16 +8,18 @@ export function useLicenseManagerState(licenseManager: LicenseManager): LicenseS
8
8
 
9
9
  /**
10
10
  * Reactively reads whether a licensable feature is enabled for the current license. Re-renders when
11
- * license validation resolves.
11
+ * license validation resolves. Returns `false` when there is no license manager, so gated UI stays
12
+ * hidden when mounted without an editor or license context.
12
13
  *
13
14
  * @internal
14
15
  */
15
16
  export function useLicenseFeatureFlag(
16
- licenseManager: LicenseManager,
17
+ licenseManager: LicenseManager | null,
17
18
  feature: LicenseFeatureName
18
19
  ): boolean {
19
- return useValue('licenseFeature', () => licenseManager.isFeatureEnabled(feature), [
20
- licenseManager,
21
- feature,
22
- ])
20
+ return useValue(
21
+ 'licenseFeature',
22
+ () => (licenseManager ? licenseManager.isFeatureEnabled(feature) : false),
23
+ [licenseManager, feature]
24
+ )
23
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.1'
4
+ export const version = '5.3.2'
5
5
  export const publishDates = {
6
6
  major: '2026-05-06T16:28:18.473Z',
7
7
  minor: '2026-08-05T11:39:54.978Z',
8
- patch: '2026-08-14T10:46:20.010Z',
8
+ patch: '2026-08-18T09:59:40.172Z',
9
9
  }