@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.
- package/dist-cjs/index.d.ts +11 -2
- package/dist-cjs/index.js +5 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +1 -1
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/LiveCollaborators.js +2 -1
- package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +6 -4
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +13 -9
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager.js +9 -15
- package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
- package/dist-cjs/lib/hooks/useEvent.js +18 -1
- package/dist-cjs/lib/hooks/useEvent.js.map +2 -2
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +1 -0
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.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 +11 -2
- package/dist-esm/index.mjs +6 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +1 -1
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/LiveCollaborators.mjs +2 -1
- package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +6 -4
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +14 -9
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager.mjs +9 -15
- package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEvent.mjs +18 -1
- package/dist-esm/lib/hooks/useEvent.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +1 -0
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +2 -1
- package/src/lib/TldrawEditor.tsx +1 -1
- package/src/lib/components/LiveCollaborators.tsx +3 -1
- package/src/lib/components/Shape.tsx +22 -10
- package/src/lib/editor/Editor.test.ts +64 -3
- package/src/lib/editor/Editor.ts +16 -11
- package/src/lib/editor/managers/TextManager.ts +9 -17
- package/src/lib/hooks/useEvent.tsx +29 -0
- package/src/lib/utils/sync/LocalIndexedDb.ts +7 -5
- 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
|
-
|
|
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
|
-
|
|
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<
|
|
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:
|
|
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.
|
|
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-
|
|
8
|
-
patch: '2024-12-
|
|
7
|
+
minor: '2024-12-17T10:12:23.668Z',
|
|
8
|
+
patch: '2024-12-17T10:12:23.668Z',
|
|
9
9
|
}
|