@tldraw/editor 4.6.0-internal.e29318c66fb0 → 4.6.0-next.0a51207761bb
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 +850 -118
- package/dist-cjs/index.js +20 -6
- package/dist-cjs/index.js.map +3 -3
- package/dist-cjs/lib/TldrawEditor.js +59 -14
- package/dist-cjs/lib/TldrawEditor.js.map +3 -3
- package/dist-cjs/lib/components/MenuClickCapture.js +16 -1
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +3 -3
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
- package/dist-cjs/lib/config/{createTLUser.js → createTLCurrentUser.js} +9 -9
- package/dist-cjs/lib/config/createTLCurrentUser.js.map +7 -0
- package/dist-cjs/lib/config/createTLStore.js +31 -1
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/config/defaultAssets.js +36 -0
- package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
- package/dist-cjs/lib/config/defaultShapes.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +329 -12
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/assets/AssetUtil.js +66 -0
- package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -1
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js +80 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js.map +7 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +466 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js +17 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js.map +7 -0
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -4
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +102 -30
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +106 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +586 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +7 -0
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +6 -4
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +21 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +6 -0
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +14 -17
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
- package/dist-cjs/lib/editor/types/clipboard-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js +12 -7
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/globals/environment.js +18 -1
- package/dist-cjs/lib/globals/environment.js.map +2 -2
- package/dist-cjs/lib/hooks/{useIsDarkMode.js → useColorMode.js} +14 -10
- package/dist-cjs/lib/hooks/useColorMode.js.map +7 -0
- package/dist-cjs/lib/hooks/useCursor.js +3 -7
- package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
- package/dist-cjs/lib/hooks/useDarkMode.js +4 -4
- package/dist-cjs/lib/hooks/useDarkMode.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/useGestureEvents.js +171 -127
- package/dist-cjs/lib/hooks/useGestureEvents.js.map +3 -3
- package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
- package/dist-cjs/lib/options.js +3 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +1 -1
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +4 -3
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
- package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +2 -1
- package/dist-cjs/lib/utils/reparenting.js.map +2 -2
- package/dist-cjs/lib/utils/richText.js.map +2 -2
- package/dist-cjs/lib/utils/runtime.js +2 -1
- package/dist-cjs/lib/utils/runtime.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +1 -1
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
- package/dist-cjs/lib/utils/sync/hardReset.js +0 -8
- package/dist-cjs/lib/utils/sync/hardReset.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 +850 -118
- package/dist-esm/index.mjs +28 -10
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +62 -14
- package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
- package/dist-esm/lib/components/MenuClickCapture.mjs +16 -1
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +3 -3
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
- package/dist-esm/lib/config/{createTLUser.mjs → createTLCurrentUser.mjs} +6 -6
- package/dist-esm/lib/config/createTLCurrentUser.mjs.map +7 -0
- package/dist-esm/lib/config/createTLStore.mjs +37 -2
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/config/defaultAssets.mjs +16 -0
- package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
- package/dist-esm/lib/config/defaultShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +332 -13
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/assets/AssetUtil.mjs +46 -0
- package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs +60 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +438 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs +1 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -4
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +102 -30
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +88 -0
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +568 -0
- package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +6 -4
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +21 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +6 -0
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +14 -17
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +12 -10
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/globals/environment.mjs +18 -1
- package/dist-esm/lib/globals/environment.mjs.map +2 -2
- package/dist-esm/lib/hooks/useColorMode.mjs +19 -0
- package/dist-esm/lib/hooks/useColorMode.mjs.map +7 -0
- package/dist-esm/lib/hooks/useCursor.mjs +3 -7
- package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDarkMode.mjs +4 -4
- package/dist-esm/lib/hooks/useDarkMode.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs +171 -127
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +3 -3
- package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +3 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +1 -1
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +4 -3
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
- package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +2 -1
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/lib/utils/richText.mjs.map +2 -2
- package/dist-esm/lib/utils/runtime.mjs +2 -1
- package/dist-esm/lib/utils/runtime.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +1 -1
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/hardReset.mjs +0 -8
- package/dist-esm/lib/utils/sync/hardReset.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +13 -33
- package/package.json +8 -9
- package/src/index.ts +37 -8
- package/src/lib/TldrawEditor.tsx +99 -20
- package/src/lib/components/MenuClickCapture.tsx +20 -0
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +3 -3
- package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
- package/src/lib/config/TLEditorSnapshot.test.ts +1 -1
- package/src/lib/config/{createTLUser.ts → createTLCurrentUser.ts} +6 -6
- package/src/lib/config/createTLStore.ts +58 -3
- package/src/lib/config/defaultAssets.ts +19 -0
- package/src/lib/config/defaultShapes.ts +1 -1
- package/src/lib/editor/Editor.ts +448 -36
- package/src/lib/editor/assets/AssetUtil.ts +85 -0
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +1 -1
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +9 -2
- package/src/lib/editor/managers/FontManager/FontManager.ts +1 -67
- package/src/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.ts +82 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +522 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +583 -0
- package/src/lib/editor/managers/PerformanceManager/perf-types.ts +196 -0
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +1 -1
- package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +1 -1
- package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +5 -5
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +18 -4
- package/src/lib/editor/managers/TextManager/TextManager.ts +140 -34
- package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +116 -0
- package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +605 -0
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +25 -31
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +7 -5
- package/src/lib/editor/shapes/ShapeUtil.ts +41 -5
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
- package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +7 -0
- package/src/lib/editor/tools/StateNode.ts +16 -18
- package/src/lib/editor/types/SvgExportContext.tsx +5 -0
- package/src/lib/editor/types/clipboard-types.ts +2 -1
- package/src/lib/editor/types/external-content.ts +1 -0
- package/src/lib/exports/StyleEmbedder.ts +1 -1
- package/src/lib/exports/getSvgJsx.tsx +22 -16
- package/src/lib/globals/environment.ts +18 -0
- package/src/lib/hooks/{useIsDarkMode.ts → useColorMode.ts} +9 -5
- package/src/lib/hooks/useCursor.ts +3 -7
- package/src/lib/hooks/useDarkMode.ts +4 -4
- package/src/lib/hooks/useEditorComponents.tsx +1 -1
- package/src/lib/hooks/useGestureEvents.ts +240 -168
- package/src/lib/hooks/useLocalStore.ts +1 -1
- package/src/lib/options.ts +108 -0
- package/src/lib/primitives/Box.test.ts +30 -0
- package/src/lib/primitives/Box.ts +1 -1
- package/src/lib/primitives/geometry/Arc2d.ts +2 -2
- package/src/lib/primitives/geometry/Circle2d.ts +2 -2
- package/src/lib/primitives/geometry/Ellipse2d.ts +2 -2
- package/src/lib/primitives/geometry/Geometry2d.test.ts +21 -0
- package/src/lib/primitives/geometry/Geometry2d.ts +4 -3
- package/src/lib/primitives/geometry/Polyline2d.ts +1 -1
- package/src/lib/primitives/geometry/Stadium2d.ts +1 -1
- package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
- package/src/lib/utils/reparenting.ts +6 -2
- package/src/lib/utils/richText.ts +1 -1
- package/src/lib/utils/runtime.ts +3 -1
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +1 -1
- package/src/lib/utils/sync/TLLocalSyncClient.ts +1 -1
- package/src/lib/utils/sync/hardReset.ts +0 -8
- package/src/version.ts +3 -3
- package/dist-cjs/lib/config/createTLUser.js.map +0 -7
- package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
- package/dist-esm/lib/config/createTLUser.mjs.map +0 -7
- package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
- package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { MigrationSequence, Store } from '@tldraw/store'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
TLShape,
|
|
4
|
+
TLStore,
|
|
5
|
+
TLStoreSnapshot,
|
|
6
|
+
TLTheme,
|
|
7
|
+
TLThemeId,
|
|
8
|
+
TLThemes,
|
|
9
|
+
registerColorsFromThemes,
|
|
10
|
+
registerFontsFromThemes,
|
|
11
|
+
} from '@tldraw/tlschema'
|
|
3
12
|
import { annotateError, Required } from '@tldraw/utils'
|
|
4
13
|
import classNames from 'classnames'
|
|
5
14
|
import React, {
|
|
@@ -16,16 +25,18 @@ import React, {
|
|
|
16
25
|
import { version } from '../version'
|
|
17
26
|
import { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'
|
|
18
27
|
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
|
28
|
+
import { createTLCurrentUser, TLCurrentUser } from './config/createTLCurrentUser'
|
|
19
29
|
import { TLStoreBaseOptions } from './config/createTLStore'
|
|
20
|
-
import {
|
|
30
|
+
import { TLAnyAssetUtilConstructor } from './config/defaultAssets'
|
|
21
31
|
import { TLAnyBindingUtilConstructor } from './config/defaultBindings'
|
|
22
32
|
import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
|
|
23
33
|
import { TLEditorSnapshot } from './config/TLEditorSnapshot'
|
|
24
34
|
import { Editor } from './editor/Editor'
|
|
35
|
+
import { resolveThemes } from './editor/managers/ThemeManager/ThemeManager'
|
|
25
36
|
import { TLStateNodeConstructor } from './editor/tools/StateNode'
|
|
26
37
|
import { TLCameraOptions } from './editor/types/misc-types'
|
|
27
|
-
import type { TLEditorComponents } from './hooks/EditorComponentsContext'
|
|
28
38
|
import { useEditorComponents } from './hooks/EditorComponentsContext'
|
|
39
|
+
import type { TLEditorComponents } from './hooks/EditorComponentsContext'
|
|
29
40
|
import { ContainerProvider, useContainer } from './hooks/useContainer'
|
|
30
41
|
import { useCursor } from './hooks/useCursor'
|
|
31
42
|
import { useDarkMode } from './hooks/useDarkMode'
|
|
@@ -121,6 +132,11 @@ export interface TldrawEditorBaseProps {
|
|
|
121
132
|
*/
|
|
122
133
|
bindingUtils?: readonly TLAnyBindingUtilConstructor[]
|
|
123
134
|
|
|
135
|
+
/**
|
|
136
|
+
* An array of asset utils to use in the editor.
|
|
137
|
+
*/
|
|
138
|
+
assetUtils?: readonly TLAnyAssetUtilConstructor[]
|
|
139
|
+
|
|
124
140
|
/**
|
|
125
141
|
* An array of tools to add to the editor's state chart.
|
|
126
142
|
*/
|
|
@@ -154,12 +170,26 @@ export interface TldrawEditorBaseProps {
|
|
|
154
170
|
/**
|
|
155
171
|
* The user interacting with the editor.
|
|
156
172
|
*/
|
|
157
|
-
user?:
|
|
173
|
+
user?: TLCurrentUser
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The editor's color scheme. Defaults to `'light'`.
|
|
177
|
+
*
|
|
178
|
+
* - `'light'` - Always use light mode.
|
|
179
|
+
* - `'dark'` - Always use dark mode.
|
|
180
|
+
* - `'system'` - Follow the OS color scheme preference.
|
|
181
|
+
*/
|
|
182
|
+
colorScheme?: 'light' | 'dark' | 'system'
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Named themes for the editor.
|
|
186
|
+
*/
|
|
187
|
+
themes?: Partial<TLThemes>
|
|
158
188
|
|
|
159
189
|
/**
|
|
160
|
-
*
|
|
190
|
+
* The id of the initially active theme. Defaults to `'default'`.
|
|
161
191
|
*/
|
|
162
|
-
|
|
192
|
+
initialTheme?: TLThemeId
|
|
163
193
|
|
|
164
194
|
/**
|
|
165
195
|
* Camera options for the editor.
|
|
@@ -242,6 +272,7 @@ declare global {
|
|
|
242
272
|
|
|
243
273
|
const EMPTY_SHAPE_UTILS_ARRAY = [] as const
|
|
244
274
|
const EMPTY_BINDING_UTILS_ARRAY = [] as const
|
|
275
|
+
const EMPTY_ASSET_UTILS_ARRAY = [] as const
|
|
245
276
|
const EMPTY_TOOLS_ARRAY = [] as const
|
|
246
277
|
/** @internal */
|
|
247
278
|
export const TL_CONTAINER_CLASS = 'tl-container'
|
|
@@ -259,8 +290,15 @@ export const TldrawEditor = memo(function TldrawEditor({
|
|
|
259
290
|
deepLinks: _deepLinks,
|
|
260
291
|
...rest
|
|
261
292
|
}: TldrawEditorProps) {
|
|
293
|
+
// Register custom colors and fonts before effects run. For external stores,
|
|
294
|
+
// users should also pass themes to createTLStore so they are
|
|
295
|
+
// registered before data is loaded into the store.
|
|
296
|
+
const resolvedThemes = resolveThemes(rest.themes)
|
|
297
|
+
registerColorsFromThemes(resolvedThemes)
|
|
298
|
+
registerFontsFromThemes(resolvedThemes)
|
|
299
|
+
|
|
262
300
|
const [container, setContainer] = useState<HTMLElement | null>(null)
|
|
263
|
-
const user = useMemo(() => _user ??
|
|
301
|
+
const user = useMemo(() => _user ?? createTLCurrentUser(), [_user])
|
|
264
302
|
|
|
265
303
|
const ErrorFallback =
|
|
266
304
|
components?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback
|
|
@@ -285,6 +323,7 @@ export const TldrawEditor = memo(function TldrawEditor({
|
|
|
285
323
|
...rest,
|
|
286
324
|
shapeUtils: rest.shapeUtils ?? EMPTY_SHAPE_UTILS_ARRAY,
|
|
287
325
|
bindingUtils: rest.bindingUtils ?? EMPTY_BINDING_UTILS_ARRAY,
|
|
326
|
+
assetUtils: rest.assetUtils ?? EMPTY_ASSET_UTILS_ARRAY,
|
|
288
327
|
tools: rest.tools ?? EMPTY_TOOLS_ARRAY,
|
|
289
328
|
components,
|
|
290
329
|
options: useShallowObjectIdentity(mergedOptions),
|
|
@@ -331,8 +370,8 @@ export const TldrawEditor = memo(function TldrawEditor({
|
|
|
331
370
|
|
|
332
371
|
function TldrawEditorWithOwnStore(
|
|
333
372
|
props: Required<
|
|
334
|
-
TldrawEditorProps & { store: undefined; user:
|
|
335
|
-
'shapeUtils' | 'bindingUtils' | 'tools'
|
|
373
|
+
TldrawEditorProps & { store: undefined; user: TLCurrentUser },
|
|
374
|
+
'shapeUtils' | 'bindingUtils' | 'assetUtils' | 'tools'
|
|
336
375
|
>
|
|
337
376
|
) {
|
|
338
377
|
const {
|
|
@@ -341,23 +380,29 @@ function TldrawEditorWithOwnStore(
|
|
|
341
380
|
initialData,
|
|
342
381
|
shapeUtils,
|
|
343
382
|
bindingUtils,
|
|
383
|
+
assetUtils,
|
|
344
384
|
persistenceKey,
|
|
345
385
|
sessionId,
|
|
346
386
|
user,
|
|
347
387
|
assets,
|
|
388
|
+
users,
|
|
348
389
|
migrations,
|
|
390
|
+
themes,
|
|
349
391
|
} = props
|
|
350
392
|
|
|
351
393
|
const syncedStore = useLocalStore({
|
|
352
394
|
shapeUtils,
|
|
353
395
|
bindingUtils,
|
|
396
|
+
assetUtils,
|
|
354
397
|
initialData,
|
|
355
398
|
persistenceKey,
|
|
356
399
|
sessionId,
|
|
357
400
|
defaultName,
|
|
358
401
|
snapshot,
|
|
359
402
|
assets,
|
|
403
|
+
users,
|
|
360
404
|
migrations,
|
|
405
|
+
themes,
|
|
361
406
|
})
|
|
362
407
|
|
|
363
408
|
return <TldrawEditorWithLoadingStore {...props} store={syncedStore} user={user} />
|
|
@@ -368,8 +413,8 @@ const TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({
|
|
|
368
413
|
user,
|
|
369
414
|
...rest
|
|
370
415
|
}: Required<
|
|
371
|
-
TldrawEditorProps & { store: TLStoreWithStatus; user:
|
|
372
|
-
'shapeUtils' | 'bindingUtils' | 'tools'
|
|
416
|
+
TldrawEditorProps & { store: TLStoreWithStatus; user: TLCurrentUser },
|
|
417
|
+
'shapeUtils' | 'bindingUtils' | 'assetUtils' | 'tools'
|
|
373
418
|
>) {
|
|
374
419
|
const container = useContainer()
|
|
375
420
|
|
|
@@ -415,22 +460,25 @@ function TldrawEditorWithReadyStore({
|
|
|
415
460
|
tools,
|
|
416
461
|
shapeUtils,
|
|
417
462
|
bindingUtils,
|
|
463
|
+
assetUtils,
|
|
418
464
|
user,
|
|
419
465
|
initialState,
|
|
420
466
|
autoFocus = true,
|
|
421
|
-
inferDarkMode,
|
|
422
467
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
423
468
|
cameraOptions,
|
|
424
469
|
options,
|
|
425
470
|
licenseKey,
|
|
426
471
|
getShapeVisibility,
|
|
472
|
+
colorScheme,
|
|
427
473
|
assetUrls,
|
|
474
|
+
themes,
|
|
475
|
+
initialTheme,
|
|
428
476
|
}: Required<
|
|
429
477
|
TldrawEditorProps & {
|
|
430
478
|
store: TLStore
|
|
431
|
-
user:
|
|
479
|
+
user: TLCurrentUser
|
|
432
480
|
},
|
|
433
|
-
'shapeUtils' | 'bindingUtils' | 'tools'
|
|
481
|
+
'shapeUtils' | 'bindingUtils' | 'assetUtils' | 'tools'
|
|
434
482
|
>) {
|
|
435
483
|
const { ErrorFallback } = useEditorComponents()
|
|
436
484
|
const container = useContainer()
|
|
@@ -446,44 +494,58 @@ function TldrawEditorWithReadyStore({
|
|
|
446
494
|
const editorOptionsRef = useRef({
|
|
447
495
|
// for these, it's because they're only used when the editor first mounts:
|
|
448
496
|
autoFocus: autoFocus && !noAutoFocus(),
|
|
449
|
-
inferDarkMode,
|
|
450
497
|
initialState,
|
|
498
|
+
colorScheme,
|
|
451
499
|
|
|
452
500
|
// for these, it's because we keep them up to date in a separate effect:
|
|
453
501
|
cameraOptions,
|
|
454
502
|
deepLinks,
|
|
503
|
+
themes,
|
|
504
|
+
initialTheme,
|
|
455
505
|
})
|
|
456
506
|
|
|
457
507
|
useLayoutEffect(() => {
|
|
458
508
|
editorOptionsRef.current = {
|
|
459
509
|
autoFocus: autoFocus && !noAutoFocus(),
|
|
460
|
-
inferDarkMode,
|
|
461
510
|
initialState,
|
|
511
|
+
colorScheme,
|
|
462
512
|
cameraOptions,
|
|
463
513
|
deepLinks,
|
|
514
|
+
themes,
|
|
515
|
+
initialTheme,
|
|
464
516
|
}
|
|
465
|
-
}, [autoFocus,
|
|
517
|
+
}, [autoFocus, initialState, colorScheme, cameraOptions, deepLinks, themes, initialTheme])
|
|
466
518
|
|
|
467
519
|
useLayoutEffect(
|
|
468
520
|
() => {
|
|
469
|
-
const {
|
|
470
|
-
|
|
521
|
+
const {
|
|
522
|
+
autoFocus,
|
|
523
|
+
initialState,
|
|
524
|
+
colorScheme: initColorScheme,
|
|
525
|
+
cameraOptions,
|
|
526
|
+
deepLinks,
|
|
527
|
+
themes,
|
|
528
|
+
initialTheme,
|
|
529
|
+
} = editorOptionsRef.current
|
|
471
530
|
const editor = new Editor({
|
|
472
531
|
store,
|
|
473
532
|
shapeUtils,
|
|
474
533
|
bindingUtils,
|
|
534
|
+
assetUtils,
|
|
475
535
|
tools,
|
|
476
536
|
getContainer: () => container,
|
|
477
537
|
user,
|
|
478
538
|
initialState,
|
|
479
539
|
// we should check for some kind of query parameter that turns off autofocus
|
|
480
540
|
autoFocus,
|
|
481
|
-
inferDarkMode,
|
|
482
541
|
cameraOptions,
|
|
483
542
|
options,
|
|
484
543
|
licenseKey,
|
|
485
544
|
getShapeVisibility,
|
|
545
|
+
colorScheme: initColorScheme,
|
|
486
546
|
fontAssetUrls: assetUrls?.fonts,
|
|
547
|
+
themes: themes,
|
|
548
|
+
initialTheme: initialTheme,
|
|
487
549
|
})
|
|
488
550
|
|
|
489
551
|
editor.updateViewportScreenBounds(canvasRef.current ?? container)
|
|
@@ -508,7 +570,9 @@ function TldrawEditorWithReadyStore({
|
|
|
508
570
|
},
|
|
509
571
|
// if any of these change, we need to recreate the editor.
|
|
510
572
|
[
|
|
573
|
+
assetUtils,
|
|
511
574
|
bindingUtils,
|
|
575
|
+
colorScheme,
|
|
512
576
|
container,
|
|
513
577
|
options,
|
|
514
578
|
shapeUtils,
|
|
@@ -537,6 +601,21 @@ function TldrawEditorWithReadyStore({
|
|
|
537
601
|
}
|
|
538
602
|
}, [editor, cameraOptions, options?.camera])
|
|
539
603
|
|
|
604
|
+
// keep the editor up to date with the latest theme definitions
|
|
605
|
+
useLayoutEffect(() => {
|
|
606
|
+
if (editor && themes) {
|
|
607
|
+
for (const def of Object.values(themes) as TLTheme[]) {
|
|
608
|
+
editor.updateTheme(def)
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}, [editor, themes])
|
|
612
|
+
|
|
613
|
+
useLayoutEffect(() => {
|
|
614
|
+
if (editor && initialTheme) {
|
|
615
|
+
editor.setCurrentTheme(initialTheme)
|
|
616
|
+
}
|
|
617
|
+
}, [editor, initialTheme])
|
|
618
|
+
|
|
540
619
|
const crashingError = useSyncExternalStore(
|
|
541
620
|
useCallback(
|
|
542
621
|
(onStoreChange) => {
|
|
@@ -42,6 +42,22 @@ export function MenuClickCapture() {
|
|
|
42
42
|
}
|
|
43
43
|
rDidAPointerDownAndDragWhileMenuWasOpen.current = false
|
|
44
44
|
}
|
|
45
|
+
if (e.button === 2) {
|
|
46
|
+
// Swallow the contextmenu event that follows this right-click pointerdown.
|
|
47
|
+
// clearOpenMenus() below triggers a synchronous render that unmounts this
|
|
48
|
+
// component, so our React onContextMenu handler won't be around to catch it.
|
|
49
|
+
// Without this, the contextmenu event reaches the Radix Trigger and briefly
|
|
50
|
+
// opens a new context menu (which then immediately dismisses — causing a flash).
|
|
51
|
+
const ownerDocument = editor.getContainerDocument()
|
|
52
|
+
ownerDocument.addEventListener(
|
|
53
|
+
'contextmenu',
|
|
54
|
+
(event) => {
|
|
55
|
+
event.preventDefault()
|
|
56
|
+
event.stopImmediatePropagation()
|
|
57
|
+
},
|
|
58
|
+
{ capture: true, once: true }
|
|
59
|
+
)
|
|
60
|
+
}
|
|
45
61
|
editor.menus.clearOpenMenus()
|
|
46
62
|
},
|
|
47
63
|
[editor]
|
|
@@ -117,6 +133,10 @@ export function MenuClickCapture() {
|
|
|
117
133
|
onPointerDown={handlePointerDown}
|
|
118
134
|
onPointerMove={handlePointerMove}
|
|
119
135
|
onPointerUp={handlePointerUp}
|
|
136
|
+
onContextMenu={(e) => {
|
|
137
|
+
e.preventDefault()
|
|
138
|
+
e.stopPropagation()
|
|
139
|
+
}}
|
|
120
140
|
/>
|
|
121
141
|
)
|
|
122
142
|
)
|
|
@@ -6,8 +6,8 @@ import { memo, useEffect, useRef } from 'react'
|
|
|
6
6
|
import { Editor } from '../../editor/Editor'
|
|
7
7
|
import { TLIndicatorPath } from '../../editor/shapes/ShapeUtil'
|
|
8
8
|
import { getComputedStyle } from '../../exports/domUtils'
|
|
9
|
+
import { useColorMode } from '../../hooks/useColorMode'
|
|
9
10
|
import { useEditor } from '../../hooks/useEditor'
|
|
10
|
-
import { useIsDarkMode } from '../../hooks/useIsDarkMode'
|
|
11
11
|
import { useActivePeerIds$ } from '../../hooks/usePeerIds'
|
|
12
12
|
|
|
13
13
|
interface CollaboratorIndicatorData {
|
|
@@ -133,14 +133,14 @@ export const CanvasShapeIndicators = memo(function CanvasShapeIndicators() {
|
|
|
133
133
|
|
|
134
134
|
// Cache the selected color to avoid getComputedStyle on every render
|
|
135
135
|
const rSelectedColor = useRef<string | null>(null)
|
|
136
|
-
const
|
|
136
|
+
const colorMode = useColorMode()
|
|
137
137
|
|
|
138
138
|
useEffect(() => {
|
|
139
139
|
const timer = editor.timers.setTimeout(() => {
|
|
140
140
|
rSelectedColor.current = null
|
|
141
141
|
}, 0)
|
|
142
142
|
return () => clearTimeout(timer)
|
|
143
|
-
}, [
|
|
143
|
+
}, [colorMode, editor])
|
|
144
144
|
|
|
145
145
|
// Get active peer IDs (already handles time-based state transitions)
|
|
146
146
|
const activePeerIds$ = useActivePeerIds$()
|
|
@@ -19,8 +19,8 @@ import { useScreenBounds } from '../../hooks/useScreenBounds'
|
|
|
19
19
|
import { ShapeCullingProvider, useShapeCulling } from '../../hooks/useShapeCulling'
|
|
20
20
|
import { Box } from '../../primitives/Box'
|
|
21
21
|
import { Mat } from '../../primitives/Mat'
|
|
22
|
-
import { Vec } from '../../primitives/Vec'
|
|
23
22
|
import { toDomPrecision } from '../../primitives/utils'
|
|
23
|
+
import { Vec } from '../../primitives/Vec'
|
|
24
24
|
import { debugFlags } from '../../utils/debug-flags'
|
|
25
25
|
import { setStyleProperty } from '../../utils/dom'
|
|
26
26
|
import { GeometryDebuggingView } from '../GeometryDebuggingView'
|
|
@@ -4,8 +4,8 @@ import { useRef } from 'react'
|
|
|
4
4
|
import { useSharedSafeId } from '../../hooks/useSafeId'
|
|
5
5
|
import { useTransform } from '../../hooks/useTransform'
|
|
6
6
|
import { Box } from '../../primitives/Box'
|
|
7
|
-
import { Vec } from '../../primitives/Vec'
|
|
8
7
|
import { clamp } from '../../primitives/utils'
|
|
8
|
+
import { Vec } from '../../primitives/Vec'
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export interface TLCollaboratorHintProps {
|
|
@@ -2,8 +2,8 @@ import { PageRecordType, TLStore, createShapeId } from '@tldraw/tlschema'
|
|
|
2
2
|
import { IndexKey } from '@tldraw/utils'
|
|
3
3
|
import { Editor } from '../editor/Editor'
|
|
4
4
|
import { Box } from '../primitives/Box'
|
|
5
|
-
import { TLEditorSnapshot, getSnapshot, loadSnapshot } from './TLEditorSnapshot'
|
|
6
5
|
import { createTLStore } from './createTLStore'
|
|
6
|
+
import { TLEditorSnapshot, getSnapshot, loadSnapshot } from './TLEditorSnapshot'
|
|
7
7
|
|
|
8
8
|
const createEditor = (store: TLStore) => {
|
|
9
9
|
return new Editor({
|
|
@@ -5,7 +5,7 @@ import { useShallowObjectIdentity } from '../hooks/useIdentity'
|
|
|
5
5
|
import { TLUserPreferences, getUserPreferences, setUserPreferences } from './TLUserPreferences'
|
|
6
6
|
|
|
7
7
|
/** @public */
|
|
8
|
-
export interface
|
|
8
|
+
export interface TLCurrentUser {
|
|
9
9
|
readonly userPreferences: Signal<TLUserPreferences>
|
|
10
10
|
// eslint-disable-next-line tldraw/method-signature-style
|
|
11
11
|
readonly setUserPreferences: (userPreferences: TLUserPreferences) => void
|
|
@@ -16,13 +16,13 @@ const defaultLocalStorageUserPrefs = computed('defaultLocalStorageUserPrefs', ()
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
/** @public */
|
|
19
|
-
export function
|
|
19
|
+
export function createTLCurrentUser(
|
|
20
20
|
opts = {} as {
|
|
21
21
|
userPreferences?: Signal<TLUserPreferences>
|
|
22
22
|
// eslint-disable-next-line tldraw/method-signature-style
|
|
23
23
|
setUserPreferences?: (userPreferences: TLUserPreferences) => void
|
|
24
24
|
}
|
|
25
|
-
):
|
|
25
|
+
): TLCurrentUser {
|
|
26
26
|
return {
|
|
27
27
|
userPreferences: opts.userPreferences ?? defaultLocalStorageUserPrefs,
|
|
28
28
|
setUserPreferences: opts.setUserPreferences ?? setUserPreferences,
|
|
@@ -32,11 +32,11 @@ export function createTLUser(
|
|
|
32
32
|
/**
|
|
33
33
|
* @public
|
|
34
34
|
*/
|
|
35
|
-
export function
|
|
35
|
+
export function useTldrawCurrentUser(opts: {
|
|
36
36
|
userPreferences?: Signal<TLUserPreferences> | TLUserPreferences
|
|
37
37
|
// eslint-disable-next-line tldraw/method-signature-style
|
|
38
38
|
setUserPreferences?: (userPreferences: TLUserPreferences) => void
|
|
39
|
-
}):
|
|
39
|
+
}): TLCurrentUser {
|
|
40
40
|
const prefs = useShallowObjectIdentity(opts.userPreferences ?? defaultLocalStorageUserPrefs)
|
|
41
41
|
const userAtom = useAtom<TLUserPreferences | Signal<TLUserPreferences>>('userAtom', prefs)
|
|
42
42
|
useEffect(() => {
|
|
@@ -45,7 +45,7 @@ export function useTldrawUser(opts: {
|
|
|
45
45
|
|
|
46
46
|
return useMemo(
|
|
47
47
|
() =>
|
|
48
|
-
|
|
48
|
+
createTLCurrentUser({
|
|
49
49
|
userPreferences: computed('userPreferences', () => {
|
|
50
50
|
const userStuff = userAtom.get()
|
|
51
51
|
return isSignal(userStuff) ? userStuff.get() : userStuff
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Signal } from '@tldraw/state'
|
|
1
|
+
import { Signal, computed } from '@tldraw/state'
|
|
2
2
|
import { HistoryEntry, MigrationSequence, SerializedStore, Store, StoreSchema } from '@tldraw/store'
|
|
3
3
|
import {
|
|
4
4
|
CustomRecordInfo,
|
|
@@ -8,13 +8,24 @@ import {
|
|
|
8
8
|
TLStore,
|
|
9
9
|
TLStoreProps,
|
|
10
10
|
TLStoreSnapshot,
|
|
11
|
+
TLThemes,
|
|
12
|
+
TLUser,
|
|
13
|
+
TLUserStore,
|
|
14
|
+
UserRecordType,
|
|
15
|
+
createCachedUserResolve,
|
|
11
16
|
createTLSchema,
|
|
17
|
+
createUserId,
|
|
18
|
+
registerColorsFromThemes,
|
|
19
|
+
registerFontsFromThemes,
|
|
12
20
|
} from '@tldraw/tlschema'
|
|
13
21
|
import { FileHelpers, assert } from '@tldraw/utils'
|
|
14
22
|
import { Editor } from '../editor/Editor'
|
|
15
|
-
import {
|
|
23
|
+
import { resolveThemes } from '../editor/managers/ThemeManager/ThemeManager'
|
|
24
|
+
import { TLAnyAssetUtilConstructor, checkAssets } from './defaultAssets'
|
|
16
25
|
import { TLAnyBindingUtilConstructor, checkBindings } from './defaultBindings'
|
|
17
26
|
import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'
|
|
27
|
+
import { TLEditorSnapshot, loadSnapshot } from './TLEditorSnapshot'
|
|
28
|
+
import { defaultUserPreferences, getUserPreferences } from './TLUserPreferences'
|
|
18
29
|
|
|
19
30
|
/** @public */
|
|
20
31
|
export interface TLStoreBaseOptions {
|
|
@@ -30,6 +41,16 @@ export interface TLStoreBaseOptions {
|
|
|
30
41
|
/** How should this store upload & resolve assets? */
|
|
31
42
|
assets?: TLAssetStore
|
|
32
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Named theme definitions. When provided, custom color names are automatically
|
|
46
|
+
* registered before the store is constructed so persisted data with those
|
|
47
|
+
* colors passes validation on load.
|
|
48
|
+
*/
|
|
49
|
+
themes?: Partial<TLThemes>
|
|
50
|
+
|
|
51
|
+
/** How should this store resolve users for attribution? */
|
|
52
|
+
users?: TLUserStore
|
|
53
|
+
|
|
33
54
|
/** Called when the store is connected to an {@link @tldraw/editor#Editor}. */
|
|
34
55
|
onMount?(editor: Editor): void | (() => void)
|
|
35
56
|
}
|
|
@@ -41,8 +62,9 @@ export type TLStoreSchemaOptions =
|
|
|
41
62
|
}
|
|
42
63
|
| {
|
|
43
64
|
shapeUtils?: readonly TLAnyShapeUtilConstructor[]
|
|
44
|
-
migrations?: readonly MigrationSequence[]
|
|
45
65
|
bindingUtils?: readonly TLAnyBindingUtilConstructor[]
|
|
66
|
+
assetUtils?: readonly TLAnyAssetUtilConstructor[]
|
|
67
|
+
migrations?: readonly MigrationSequence[]
|
|
46
68
|
records?: Record<string, CustomRecordInfo>
|
|
47
69
|
}
|
|
48
70
|
|
|
@@ -61,6 +83,21 @@ export type TLStoreEventInfo = HistoryEntry<TLRecord>
|
|
|
61
83
|
|
|
62
84
|
const defaultAssetResolve: NonNullable<TLAssetStore['resolve']> = (asset) => asset.props.src
|
|
63
85
|
|
|
86
|
+
const _defaultCurrentUser: Signal<TLUser | null> = computed('defaultCurrentUser', () => {
|
|
87
|
+
const prefs = getUserPreferences()
|
|
88
|
+
if (!prefs.id) return null
|
|
89
|
+
return UserRecordType.create({
|
|
90
|
+
id: createUserId(prefs.id),
|
|
91
|
+
name: prefs.name ?? '',
|
|
92
|
+
color: prefs.color ?? defaultUserPreferences.color,
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
/** @public */
|
|
97
|
+
export const defaultUserStore: TLUserStore = {
|
|
98
|
+
currentUser: _defaultCurrentUser,
|
|
99
|
+
}
|
|
100
|
+
|
|
64
101
|
/** @public */
|
|
65
102
|
export const inlineBase64AssetStore: TLAssetStore = {
|
|
66
103
|
upload: async (_, file) => {
|
|
@@ -90,6 +127,10 @@ export function createTLSchemaFromUtils(
|
|
|
90
127
|
'bindingUtils' in opts && opts.bindingUtils
|
|
91
128
|
? utilsToMap(checkBindings(opts.bindingUtils))
|
|
92
129
|
: undefined,
|
|
130
|
+
assets:
|
|
131
|
+
'assetUtils' in opts && opts.assetUtils
|
|
132
|
+
? utilsToMap(checkAssets(opts.assetUtils))
|
|
133
|
+
: undefined,
|
|
93
134
|
records: 'records' in opts ? opts.records : undefined,
|
|
94
135
|
migrations: 'migrations' in opts ? opts.migrations : undefined,
|
|
95
136
|
})
|
|
@@ -107,10 +148,15 @@ export function createTLStore({
|
|
|
107
148
|
defaultName = '',
|
|
108
149
|
id,
|
|
109
150
|
assets = inlineBase64AssetStore,
|
|
151
|
+
users = defaultUserStore,
|
|
110
152
|
onMount,
|
|
111
153
|
collaboration,
|
|
154
|
+
themes,
|
|
112
155
|
...rest
|
|
113
156
|
}: TLStoreOptions = {}): TLStore {
|
|
157
|
+
const resolvedThemes = resolveThemes(themes)
|
|
158
|
+
registerColorsFromThemes(resolvedThemes)
|
|
159
|
+
registerFontsFromThemes(resolvedThemes)
|
|
114
160
|
const schema = createTLSchemaFromUtils(rest)
|
|
115
161
|
|
|
116
162
|
const store = new Store({
|
|
@@ -124,6 +170,15 @@ export function createTLStore({
|
|
|
124
170
|
resolve: assets.resolve ?? defaultAssetResolve,
|
|
125
171
|
remove: assets.remove ?? (() => Promise.resolve()),
|
|
126
172
|
},
|
|
173
|
+
users: {
|
|
174
|
+
currentUser: users.currentUser,
|
|
175
|
+
resolve:
|
|
176
|
+
users.resolve ??
|
|
177
|
+
createCachedUserResolve((userId) => {
|
|
178
|
+
const current = users.currentUser.get()
|
|
179
|
+
return current && current.id === createUserId(userId) ? current : null
|
|
180
|
+
}),
|
|
181
|
+
},
|
|
127
182
|
onMount: (editor) => {
|
|
128
183
|
assert(editor instanceof Editor)
|
|
129
184
|
onMount?.(editor)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TLAssetUtilConstructor } from '../editor/assets/AssetUtil'
|
|
2
|
+
|
|
3
|
+
/** @public */
|
|
4
|
+
export type TLAnyAssetUtilConstructor = TLAssetUtilConstructor<any>
|
|
5
|
+
|
|
6
|
+
export function checkAssets(customAssets: readonly TLAnyAssetUtilConstructor[]) {
|
|
7
|
+
const assets = [] as TLAnyAssetUtilConstructor[]
|
|
8
|
+
|
|
9
|
+
const addedCustomAssetTypes = new Set<string>()
|
|
10
|
+
for (const customAsset of customAssets) {
|
|
11
|
+
if (addedCustomAssetTypes.has(customAsset.type)) {
|
|
12
|
+
throw new Error(`Asset type "${customAsset.type}" is defined more than once`)
|
|
13
|
+
}
|
|
14
|
+
assets.push(customAsset)
|
|
15
|
+
addedCustomAssetTypes.add(customAsset.type)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return assets
|
|
19
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TLShapeUtilConstructor } from '../editor/shapes/ShapeUtil'
|
|
2
1
|
import { GroupShapeUtil } from '../editor/shapes/group/GroupShapeUtil'
|
|
2
|
+
import { TLShapeUtilConstructor } from '../editor/shapes/ShapeUtil'
|
|
3
3
|
|
|
4
4
|
/** @public */
|
|
5
5
|
export type TLAnyShapeUtilConstructor = TLShapeUtilConstructor<any>
|