@tldraw/editor 3.7.0-canary.916221bf1c79 → 3.7.0-canary.a152d144c038

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 (49) hide show
  1. package/dist-cjs/index.d.ts +11 -2
  2. package/dist-cjs/index.js +5 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +1 -1
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/LiveCollaborators.js +2 -1
  7. package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
  8. package/dist-cjs/lib/components/Shape.js +6 -4
  9. package/dist-cjs/lib/components/Shape.js.map +2 -2
  10. package/dist-cjs/lib/editor/Editor.js +13 -9
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/managers/TextManager.js +9 -15
  13. package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
  14. package/dist-cjs/lib/hooks/useEvent.js +18 -1
  15. package/dist-cjs/lib/hooks/useEvent.js.map +2 -2
  16. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +1 -0
  17. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  18. package/dist-cjs/version.js +3 -3
  19. package/dist-cjs/version.js.map +1 -1
  20. package/dist-esm/index.d.mts +11 -2
  21. package/dist-esm/index.mjs +6 -2
  22. package/dist-esm/index.mjs.map +2 -2
  23. package/dist-esm/lib/TldrawEditor.mjs +1 -1
  24. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  25. package/dist-esm/lib/components/LiveCollaborators.mjs +2 -1
  26. package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
  27. package/dist-esm/lib/components/Shape.mjs +6 -4
  28. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  29. package/dist-esm/lib/editor/Editor.mjs +14 -9
  30. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  31. package/dist-esm/lib/editor/managers/TextManager.mjs +9 -15
  32. package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
  33. package/dist-esm/lib/hooks/useEvent.mjs +18 -1
  34. package/dist-esm/lib/hooks/useEvent.mjs.map +2 -2
  35. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +1 -0
  36. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  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/index.ts +2 -1
  41. package/src/lib/TldrawEditor.tsx +1 -1
  42. package/src/lib/components/LiveCollaborators.tsx +3 -1
  43. package/src/lib/components/Shape.tsx +22 -10
  44. package/src/lib/editor/Editor.test.ts +64 -3
  45. package/src/lib/editor/Editor.ts +16 -11
  46. package/src/lib/editor/managers/TextManager.ts +9 -17
  47. package/src/lib/hooks/useEvent.tsx +29 -0
  48. package/src/lib/utils/sync/LocalIndexedDb.ts +7 -5
  49. package/src/version.ts +3 -3
@@ -1,3 +1,4 @@
1
+ import { useAtom } from '@tldraw/state-react'
1
2
  import { assert } from '@tldraw/utils'
2
3
  import { useCallback, useDebugValue, useLayoutEffect, useRef } from 'react'
3
4
 
@@ -42,3 +43,31 @@ export function useEvent<Args extends Array<unknown>, Result>(
42
43
  return fn(...args)
43
44
  }, [])
44
45
  }
46
+
47
+ /**
48
+ * like {@link useEvent}, but for use in reactive contexts - when the handler function changes, it
49
+ * will invalidate any reactive contexts that call it.
50
+ * @internal
51
+ */
52
+ export function useReactiveEvent<Args extends Array<unknown>, Result>(
53
+ handler: (...args: Args) => Result
54
+ ): (...args: Args) => Result {
55
+ const handlerAtom = useAtom<(...args: Args) => Result>('useReactiveEvent', () => handler)
56
+
57
+ // In a real implementation, this would run before layout effects
58
+ useLayoutEffect(() => {
59
+ handlerAtom.set(handler)
60
+ })
61
+
62
+ useDebugValue(handler)
63
+
64
+ return useCallback(
65
+ (...args: Args) => {
66
+ // In a real implementation, this would throw if called during render
67
+ const fn = handlerAtom.get()
68
+ assert(fn, 'fn does not exist')
69
+ return fn(...args)
70
+ },
71
+ [handlerAtom]
72
+ )
73
+ }
@@ -9,14 +9,16 @@ const STORE_PREFIX = 'TLDRAW_DOCUMENT_v2'
9
9
  const LEGACY_ASSET_STORE_PREFIX = 'TLDRAW_ASSET_STORE_v1'
10
10
  const dbNameIndexKey = 'TLDRAW_DB_NAME_INDEX_v2'
11
11
 
12
- const Table = {
12
+ /** @internal */
13
+ export const Table = {
13
14
  Records: 'records',
14
15
  Schema: 'schema',
15
16
  SessionState: 'session_state',
16
17
  Assets: 'assets',
17
18
  } as const
18
19
 
19
- type StoreName = (typeof Table)[keyof typeof Table]
20
+ /** @internal */
21
+ export type StoreName = (typeof Table)[keyof typeof Table]
20
22
 
21
23
  async function openLocalDb(persistenceKey: string) {
22
24
  const storeId = STORE_PREFIX + persistenceKey
@@ -109,7 +111,7 @@ export class LocalIndexedDb {
109
111
  })()
110
112
  }
111
113
 
112
- getDb() {
114
+ private getDb() {
113
115
  return this.getDbPromise
114
116
  }
115
117
 
@@ -288,14 +290,14 @@ export class LocalIndexedDb {
288
290
  })
289
291
  }
290
292
 
291
- async getAsset(assetId: string): Promise<Blob | undefined> {
293
+ async getAsset(assetId: string): Promise<File | undefined> {
292
294
  return await this.tx('readonly', [Table.Assets], async (tx) => {
293
295
  const assetsStore = tx.objectStore(Table.Assets)
294
296
  return await assetsStore.get(assetId)
295
297
  })
296
298
  }
297
299
 
298
- async storeAsset(assetId: string, blob: Blob) {
300
+ async storeAsset(assetId: string, blob: File) {
299
301
  await this.tx('readwrite', [Table.Assets], async (tx) => {
300
302
  const assetsStore = tx.objectStore(Table.Assets)
301
303
  await assetsStore.put(blob, assetId)
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 = '3.7.0-canary.916221bf1c79'
4
+ export const version = '3.7.0-canary.a152d144c038'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2024-12-04T16:24:39.611Z',
8
- patch: '2024-12-04T16:24:39.611Z',
7
+ minor: '2024-12-17T10:12:23.668Z',
8
+ patch: '2024-12-17T10:12:23.668Z',
9
9
  }