@tldraw/editor 4.6.0-next.d8328a2dcc3d → 4.6.0-next.e0f85e824397
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 +376 -98
- package/dist-cjs/index.js +12 -3
- package/dist-cjs/index.js.map +3 -3
- package/dist-cjs/lib/TldrawEditor.js +55 -12
- package/dist-cjs/lib/TldrawEditor.js.map +3 -3
- 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/config/createTLStore.js +7 -0
- 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/editor/Editor.js +200 -5
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- 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/FontManager/FontManager.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 +9 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- 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/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/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +376 -98
- package/dist-esm/index.mjs +13 -6
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +58 -12
- package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
- 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/config/createTLStore.mjs +10 -1
- 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/editor/Editor.mjs +200 -5
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- 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/FontManager/FontManager.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 +9 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/types/SvgExportContext.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/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/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +0 -33
- package/package.json +7 -7
- package/src/index.ts +8 -6
- package/src/lib/TldrawEditor.tsx +90 -13
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +3 -3
- package/src/lib/config/createTLStore.ts +22 -1
- package/src/lib/config/defaultAssets.ts +19 -0
- package/src/lib/editor/Editor.ts +285 -27
- package/src/lib/editor/assets/AssetUtil.ts +85 -0
- 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/ThemeManager/ThemeManager.ts +116 -0
- package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +605 -0
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +23 -29
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +5 -3
- package/src/lib/editor/shapes/ShapeUtil.ts +26 -1
- package/src/lib/editor/types/SvgExportContext.tsx +5 -0
- package/src/lib/editor/types/external-content.ts +1 -0
- package/src/lib/exports/getSvgJsx.tsx +21 -15
- 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/utils/reparenting.ts +6 -2
- package/src/lib/utils/richText.ts +1 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
- package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
- package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/components/default-components/CanvasShapeIndicators.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useComputed, useQuickReactor } from '@tldraw/state-react'\nimport { createComputedCache } from '@tldraw/store'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { dedupe } from '@tldraw/utils'\nimport { memo, useEffect, useRef } from 'react'\nimport { Editor } from '../../editor/Editor'\nimport { TLIndicatorPath } from '../../editor/shapes/ShapeUtil'\nimport { getComputedStyle } from '../../exports/domUtils'\nimport {
|
|
5
|
-
"mappings": "AA+RQ;AA/RR,SAAS,aAAa,uBAAuB;AAC7C,SAAS,2BAA2B;AAEpC,SAAS,cAAc;AACvB,SAAS,MAAM,WAAW,cAAc;AAGxC,SAAS,wBAAwB;AACjC,SAAS,
|
|
4
|
+
"sourcesContent": ["import { useComputed, useQuickReactor } from '@tldraw/state-react'\nimport { createComputedCache } from '@tldraw/store'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { dedupe } from '@tldraw/utils'\nimport { memo, useEffect, useRef } from 'react'\nimport { Editor } from '../../editor/Editor'\nimport { TLIndicatorPath } from '../../editor/shapes/ShapeUtil'\nimport { getComputedStyle } from '../../exports/domUtils'\nimport { useColorMode } from '../../hooks/useColorMode'\nimport { useEditor } from '../../hooks/useEditor'\nimport { useActivePeerIds$ } from '../../hooks/usePeerIds'\n\ninterface CollaboratorIndicatorData {\n\tcolor: string\n\tshapeIds: TLShapeId[]\n}\n\ninterface RenderData {\n\tidsToDisplay: Set<TLShapeId>\n\trenderingShapeIds: Set<TLShapeId>\n\thintingShapeIds: TLShapeId[]\n\tcollaboratorIndicators: CollaboratorIndicatorData[]\n}\n\nfunction setsEqual<T>(a: Set<T>, b: Set<T>): boolean {\n\tif (a.size !== b.size) return false\n\tfor (const item of a) {\n\t\tif (!b.has(item)) return false\n\t}\n\treturn true\n}\n\nfunction arraysEqual<T>(a: readonly T[], b: readonly T[]): boolean {\n\tif (a.length !== b.length) return false\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i] !== b[i]) return false\n\t}\n\treturn true\n}\n\nfunction collaboratorIndicatorsEqual(\n\ta: CollaboratorIndicatorData[],\n\tb: CollaboratorIndicatorData[]\n): boolean {\n\tif (a.length !== b.length) return false\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i].color !== b[i].color) return false\n\t\tif (!arraysEqual(a[i].shapeIds, b[i].shapeIds)) return false\n\t}\n\treturn true\n}\n\nfunction renderDataEqual(a: RenderData, b: RenderData): boolean {\n\treturn (\n\t\tsetsEqual(a.idsToDisplay, b.idsToDisplay) &&\n\t\tsetsEqual(a.renderingShapeIds, b.renderingShapeIds) &&\n\t\tarraysEqual(a.hintingShapeIds, b.hintingShapeIds) &&\n\t\tcollaboratorIndicatorsEqual(a.collaboratorIndicators, b.collaboratorIndicators)\n\t)\n}\n\nconst indicatorPathCache = createComputedCache(\n\t'indicatorPath',\n\t(editor: Editor, shape: TLShape) => {\n\t\tconst util = editor.getShapeUtil(shape)\n\t\treturn util.getIndicatorPath(shape)\n\t}\n)\n\nconst getIndicatorPath = (editor: Editor, shape: TLShape) => {\n\treturn indicatorPathCache.get(editor, shape.id)\n}\n\nfunction renderShapeIndicator(\n\tctx: CanvasRenderingContext2D,\n\teditor: Editor,\n\tshapeId: TLShapeId,\n\trenderingShapeIds: Set<TLShapeId>\n): boolean {\n\tif (!renderingShapeIds.has(shapeId)) return false\n\n\tconst shape = editor.getShape(shapeId)\n\tif (!shape || shape.isLocked) return false\n\n\tconst pageTransform = editor.getShapePageTransform(shape)\n\tif (!pageTransform) return false\n\n\tconst indicatorPath = getIndicatorPath(editor, shape)\n\tif (!indicatorPath) return false\n\n\tctx.save()\n\tctx.transform(\n\t\tpageTransform.a,\n\t\tpageTransform.b,\n\t\tpageTransform.c,\n\t\tpageTransform.d,\n\t\tpageTransform.e,\n\t\tpageTransform.f\n\t)\n\trenderIndicatorPath(ctx, indicatorPath)\n\tctx.restore()\n\n\treturn true\n}\n\nfunction renderIndicatorPath(ctx: CanvasRenderingContext2D, indicatorPath: TLIndicatorPath) {\n\tif (indicatorPath instanceof Path2D) {\n\t\tctx.stroke(indicatorPath)\n\t} else {\n\t\tconst { path, clipPath, additionalPaths } = indicatorPath\n\n\t\tif (clipPath) {\n\t\t\tctx.save()\n\t\t\tctx.clip(clipPath, 'evenodd')\n\t\t\tctx.stroke(path)\n\t\t\tctx.restore()\n\t\t} else {\n\t\t\tctx.stroke(path)\n\t\t}\n\n\t\tif (additionalPaths) {\n\t\t\tfor (const additionalPath of additionalPaths) {\n\t\t\t\tctx.stroke(additionalPath)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** @internal @react */\nexport const CanvasShapeIndicators = memo(function CanvasShapeIndicators() {\n\tconst editor = useEditor()\n\tconst canvasRef = useRef<HTMLCanvasElement>(null)\n\n\t// Cache the selected color to avoid getComputedStyle on every render\n\tconst rSelectedColor = useRef<string | null>(null)\n\tconst colorMode = useColorMode()\n\n\tuseEffect(() => {\n\t\tconst timer = editor.timers.setTimeout(() => {\n\t\t\trSelectedColor.current = null\n\t\t}, 0)\n\t\treturn () => clearTimeout(timer)\n\t}, [colorMode, editor])\n\n\t// Get active peer IDs (already handles time-based state transitions)\n\tconst activePeerIds$ = useActivePeerIds$()\n\n\tconst $renderData = useComputed(\n\t\t'indicator render data',\n\t\t() => {\n\t\t\tconst renderingShapeIds = new Set(editor.getRenderingShapes().map((s) => s.id))\n\n\t\t\t// Compute ids to display for selected/hovered shapes\n\t\t\tconst idsToDisplay = new Set<TLShapeId>()\n\t\t\tconst instanceState = editor.getInstanceState()\n\t\t\tconst isChangingStyle = instanceState.isChangingStyle\n\t\t\tconst isIdleOrEditing = editor.isInAny('select.idle', 'select.editing_shape')\n\t\t\tconst isInSelectState = editor.isInAny(\n\t\t\t\t'select.brushing',\n\t\t\t\t'select.scribble_brushing',\n\t\t\t\t'select.pointing_shape',\n\t\t\t\t'select.pointing_selection',\n\t\t\t\t'select.pointing_handle'\n\t\t\t)\n\n\t\t\tif (!isChangingStyle && (isIdleOrEditing || isInSelectState)) {\n\t\t\t\tfor (const id of editor.getSelectedShapeIds()) {\n\t\t\t\t\tidsToDisplay.add(id)\n\t\t\t\t}\n\t\t\t\tif (isIdleOrEditing && instanceState.isHoveringCanvas && !instanceState.isCoarsePointer) {\n\t\t\t\t\tconst hovered = editor.getHoveredShapeId()\n\t\t\t\t\tif (hovered) idsToDisplay.add(hovered)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Compute hinting shape ids\n\t\t\tconst hintingShapeIds = dedupe(editor.getHintingShapeIds())\n\n\t\t\t// Compute collaborator indicators\n\t\t\tconst collaboratorIndicators: CollaboratorIndicatorData[] = []\n\t\t\tconst currentPageId = editor.getCurrentPageId()\n\t\t\tconst activePeerIds = activePeerIds$.get()\n\n\t\t\tconst collaborators = editor.getCollaborators()\n\t\t\tfor (const peerId of activePeerIds.values()) {\n\t\t\t\t// Skip collaborators on different pages\n\t\t\t\tconst presence = collaborators.find((c) => c.userId === peerId)\n\t\t\t\tif (!presence || presence.currentPageId !== currentPageId) continue\n\n\t\t\t\t// Filter to shapes that are visible and on the current rendering set\n\t\t\t\tconst visibleShapeIds = presence.selectedShapeIds.filter(\n\t\t\t\t\t(id) => renderingShapeIds.has(id) && !editor.isShapeHidden(id)\n\t\t\t\t)\n\n\t\t\t\tif (visibleShapeIds.length > 0) {\n\t\t\t\t\tcollaboratorIndicators.push({\n\t\t\t\t\t\tcolor: presence.color,\n\t\t\t\t\t\tshapeIds: visibleShapeIds,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tidsToDisplay,\n\t\t\t\trenderingShapeIds,\n\t\t\t\thintingShapeIds,\n\t\t\t\tcollaboratorIndicators,\n\t\t\t}\n\t\t},\n\t\t{ isEqual: renderDataEqual },\n\t\t[editor, activePeerIds$]\n\t)\n\n\tuseQuickReactor(\n\t\t'canvas indicators render',\n\t\t() => {\n\t\t\tconst canvas = canvasRef.current\n\t\t\tif (!canvas) return\n\n\t\t\tconst ctx = canvas.getContext('2d')\n\t\t\tif (!ctx) return\n\n\t\t\tconst { idsToDisplay, renderingShapeIds, hintingShapeIds, collaboratorIndicators } =\n\t\t\t\t$renderData.get()\n\n\t\t\tconst { w, h } = editor.getViewportScreenBounds()\n\t\t\tconst dpr = editor.getInstanceState().devicePixelRatio\n\t\t\tconst { x: cx, y: cy, z: zoom } = editor.getCamera()\n\n\t\t\tconst canvasWidth = Math.ceil(w * dpr)\n\t\t\tconst canvasHeight = Math.ceil(h * dpr)\n\n\t\t\tif (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {\n\t\t\t\tcanvas.width = canvasWidth\n\t\t\t\tcanvas.height = canvasHeight\n\t\t\t\tcanvas.style.width = `${w}px`\n\t\t\t\tcanvas.style.height = `${h}px`\n\t\t\t}\n\n\t\t\tctx.resetTransform()\n\t\t\tctx.clearRect(0, 0, canvas.width, canvas.height)\n\n\t\t\tctx.scale(dpr, dpr)\n\t\t\tctx.scale(zoom, zoom)\n\t\t\tctx.translate(cx, cy)\n\n\t\t\tctx.lineCap = 'round'\n\t\t\tctx.lineJoin = 'round'\n\n\t\t\t// Draw collaborator indicators first (underneath local indicators)\n\t\t\t// Use 0.5 opacity to match the original SVG-based collaborator indicators\n\t\t\tctx.lineWidth = 1.5 / zoom\n\t\t\tfor (const collaborator of collaboratorIndicators) {\n\t\t\t\tctx.strokeStyle = collaborator.color\n\t\t\t\tctx.globalAlpha = 0.7\n\t\t\t\tfor (const shapeId of collaborator.shapeIds) {\n\t\t\t\t\trenderShapeIndicator(ctx, editor, shapeId, renderingShapeIds)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Reset alpha for local indicators\n\t\t\tctx.globalAlpha = 1.0\n\n\t\t\t// Use cached color, only call getComputedStyle when cache is empty\n\t\t\tif (!rSelectedColor.current) {\n\t\t\t\trSelectedColor.current = getComputedStyle(canvas).getPropertyValue('--tl-color-selected')\n\t\t\t}\n\n\t\t\tctx.strokeStyle = rSelectedColor.current\n\n\t\t\t// Draw selected/hovered indicators (1.5px stroke)\n\t\t\tctx.lineWidth = 1.5 / zoom\n\t\t\tfor (const shapeId of idsToDisplay) {\n\t\t\t\trenderShapeIndicator(ctx, editor, shapeId, renderingShapeIds)\n\t\t\t}\n\n\t\t\t// Draw hinted indicators with a thicker stroke (2.5px)\n\t\t\tif (hintingShapeIds.length > 0) {\n\t\t\t\tctx.lineWidth = 2.5 / zoom\n\t\t\t\tfor (const shapeId of hintingShapeIds) {\n\t\t\t\t\trenderShapeIndicator(ctx, editor, shapeId, renderingShapeIds)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, $renderData]\n\t)\n\n\treturn <canvas ref={canvasRef} className=\"tl-canvas-indicators\" />\n})\n"],
|
|
5
|
+
"mappings": "AA+RQ;AA/RR,SAAS,aAAa,uBAAuB;AAC7C,SAAS,2BAA2B;AAE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,KAAK,QAAQ,SAAS,iBAAiB;AAAA,QAC7D;AAAA,MACD;AAGA,UAAI,cAAc;AAGlB,UAAI,CAAC,eAAe,SAAS;AAC5B,uBAAe,UAAU,iBAAiB,MAAM,EAAE,iBAAiB,qBAAqB;AAAA,MACzF;AAEA,UAAI,cAAc,eAAe;AAGjC,UAAI,YAAY,MAAM;AACtB,iBAAW,WAAW,cAAc;AACnC,6BAAqB,KAAK,QAAQ,SAAS,iBAAiB;AAAA,MAC7D;AAGA,UAAI,gBAAgB,SAAS,GAAG;AAC/B,YAAI,YAAY,MAAM;AACtB,mBAAW,WAAW,iBAAiB;AACtC,+BAAqB,KAAK,QAAQ,SAAS,iBAAiB;AAAA,QAC7D;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,WAAW;AAAA,EACrB;AAEA,SAAO,oBAAC,YAAO,KAAK,WAAW,WAAU,wBAAuB;AACjE,CAAC;",
|
|
6
6
|
"names": ["CanvasShapeIndicators"]
|
|
7
7
|
}
|
|
@@ -4,10 +4,14 @@ import {
|
|
|
4
4
|
UserRecordType,
|
|
5
5
|
createCachedUserResolve,
|
|
6
6
|
createTLSchema,
|
|
7
|
-
createUserId
|
|
7
|
+
createUserId,
|
|
8
|
+
registerColorsFromThemes,
|
|
9
|
+
registerFontsFromThemes
|
|
8
10
|
} from "@tldraw/tlschema";
|
|
9
11
|
import { FileHelpers, assert } from "@tldraw/utils";
|
|
10
12
|
import { Editor } from "../editor/Editor.mjs";
|
|
13
|
+
import { resolveThemes } from "../editor/managers/ThemeManager/ThemeManager.mjs";
|
|
14
|
+
import { checkAssets } from "./defaultAssets.mjs";
|
|
11
15
|
import { checkBindings } from "./defaultBindings.mjs";
|
|
12
16
|
import { checkShapesAndAddCore } from "./defaultShapes.mjs";
|
|
13
17
|
import { loadSnapshot } from "./TLEditorSnapshot.mjs";
|
|
@@ -35,6 +39,7 @@ function createTLSchemaFromUtils(opts) {
|
|
|
35
39
|
return createTLSchema({
|
|
36
40
|
shapes: "shapeUtils" in opts && opts.shapeUtils ? utilsToMap(checkShapesAndAddCore(opts.shapeUtils)) : void 0,
|
|
37
41
|
bindings: "bindingUtils" in opts && opts.bindingUtils ? utilsToMap(checkBindings(opts.bindingUtils)) : void 0,
|
|
42
|
+
assets: "assetUtils" in opts && opts.assetUtils ? utilsToMap(checkAssets(opts.assetUtils)) : void 0,
|
|
38
43
|
records: "records" in opts ? opts.records : void 0,
|
|
39
44
|
migrations: "migrations" in opts ? opts.migrations : void 0
|
|
40
45
|
});
|
|
@@ -47,8 +52,12 @@ function createTLStore({
|
|
|
47
52
|
users = defaultUserStore,
|
|
48
53
|
onMount,
|
|
49
54
|
collaboration,
|
|
55
|
+
themes,
|
|
50
56
|
...rest
|
|
51
57
|
} = {}) {
|
|
58
|
+
const resolvedThemes = resolveThemes(themes);
|
|
59
|
+
registerColorsFromThemes(resolvedThemes);
|
|
60
|
+
registerFontsFromThemes(resolvedThemes);
|
|
52
61
|
const schema = createTLSchemaFromUtils(rest);
|
|
53
62
|
const store = new Store({
|
|
54
63
|
id,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/config/createTLStore.ts"],
|
|
4
|
-
"sourcesContent": ["import { Signal, computed } from '@tldraw/state'\nimport { HistoryEntry, MigrationSequence, SerializedStore, Store, StoreSchema } from '@tldraw/store'\nimport {\n\tCustomRecordInfo,\n\tSchemaPropsInfo,\n\tTLAssetStore,\n\tTLRecord,\n\tTLStore,\n\tTLStoreProps,\n\tTLStoreSnapshot,\n\tTLUser,\n\tTLUserStore,\n\tUserRecordType,\n\tcreateCachedUserResolve,\n\tcreateTLSchema,\n\tcreateUserId,\n} from '@tldraw/tlschema'\nimport { FileHelpers, assert } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { TLAnyBindingUtilConstructor, checkBindings } from './defaultBindings'\nimport { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'\nimport { TLEditorSnapshot, loadSnapshot } from './TLEditorSnapshot'\nimport { defaultUserPreferences, getUserPreferences } from './TLUserPreferences'\n\n/** @public */\nexport interface TLStoreBaseOptions {\n\t/** The initial data for the store. */\n\tinitialData?: SerializedStore<TLRecord>\n\n\t/** A snapshot of initial data to migrate and load into the store. */\n\tsnapshot?: Partial<TLEditorSnapshot> | TLStoreSnapshot\n\n\t/** The default name for the store. */\n\tdefaultName?: string\n\n\t/** How should this store upload & resolve assets? */\n\tassets?: TLAssetStore\n\n\t/** How should this store resolve users for attribution? */\n\tusers?: TLUserStore\n\n\t/** Called when the store is connected to an {@link @tldraw/editor#Editor}. */\n\tonMount?(editor: Editor): void | (() => void)\n}\n\n/** @public */\nexport type TLStoreSchemaOptions =\n\t| {\n\t\t\tschema?: StoreSchema<TLRecord, TLStoreProps>\n\t }\n\t| {\n\t\t\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\t\t\
|
|
5
|
-
"mappings": "AAAA,SAAiB,gBAAgB;AACjC,SAA2D,aAA0B;AACrF;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Signal, computed } from '@tldraw/state'\nimport { HistoryEntry, MigrationSequence, SerializedStore, Store, StoreSchema } from '@tldraw/store'\nimport {\n\tCustomRecordInfo,\n\tSchemaPropsInfo,\n\tTLAssetStore,\n\tTLRecord,\n\tTLStore,\n\tTLStoreProps,\n\tTLStoreSnapshot,\n\tTLThemes,\n\tTLUser,\n\tTLUserStore,\n\tUserRecordType,\n\tcreateCachedUserResolve,\n\tcreateTLSchema,\n\tcreateUserId,\n\tregisterColorsFromThemes,\n\tregisterFontsFromThemes,\n} from '@tldraw/tlschema'\nimport { FileHelpers, assert } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { resolveThemes } from '../editor/managers/ThemeManager/ThemeManager'\nimport { TLAnyAssetUtilConstructor, checkAssets } from './defaultAssets'\nimport { TLAnyBindingUtilConstructor, checkBindings } from './defaultBindings'\nimport { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'\nimport { TLEditorSnapshot, loadSnapshot } from './TLEditorSnapshot'\nimport { defaultUserPreferences, getUserPreferences } from './TLUserPreferences'\n\n/** @public */\nexport interface TLStoreBaseOptions {\n\t/** The initial data for the store. */\n\tinitialData?: SerializedStore<TLRecord>\n\n\t/** A snapshot of initial data to migrate and load into the store. */\n\tsnapshot?: Partial<TLEditorSnapshot> | TLStoreSnapshot\n\n\t/** The default name for the store. */\n\tdefaultName?: string\n\n\t/** How should this store upload & resolve assets? */\n\tassets?: TLAssetStore\n\n\t/**\n\t * Named theme definitions. When provided, custom color names are automatically\n\t * registered before the store is constructed so persisted data with those\n\t * colors passes validation on load.\n\t */\n\tthemes?: Partial<TLThemes>\n\n\t/** How should this store resolve users for attribution? */\n\tusers?: TLUserStore\n\n\t/** Called when the store is connected to an {@link @tldraw/editor#Editor}. */\n\tonMount?(editor: Editor): void | (() => void)\n}\n\n/** @public */\nexport type TLStoreSchemaOptions =\n\t| {\n\t\t\tschema?: StoreSchema<TLRecord, TLStoreProps>\n\t }\n\t| {\n\t\t\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\t\t\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\t\t\tassetUtils?: readonly TLAnyAssetUtilConstructor[]\n\t\t\tmigrations?: readonly MigrationSequence[]\n\t\t\trecords?: Record<string, CustomRecordInfo>\n\t }\n\n/** @public */\nexport type TLStoreOptions = TLStoreBaseOptions & {\n\tid?: string\n\t/** Collaboration options for the store. */\n\tcollaboration?: {\n\t\tstatus: Signal<'online' | 'offline'> | null\n\t\tmode?: Signal<'readonly' | 'readwrite'> | null\n\t}\n} & TLStoreSchemaOptions\n\n/** @public */\nexport type TLStoreEventInfo = HistoryEntry<TLRecord>\n\nconst defaultAssetResolve: NonNullable<TLAssetStore['resolve']> = (asset) => asset.props.src\n\nconst _defaultCurrentUser: Signal<TLUser | null> = computed('defaultCurrentUser', () => {\n\tconst prefs = getUserPreferences()\n\tif (!prefs.id) return null\n\treturn UserRecordType.create({\n\t\tid: createUserId(prefs.id),\n\t\tname: prefs.name ?? '',\n\t\tcolor: prefs.color ?? defaultUserPreferences.color,\n\t})\n})\n\n/** @public */\nexport const defaultUserStore: TLUserStore = {\n\tcurrentUser: _defaultCurrentUser,\n}\n\n/** @public */\nexport const inlineBase64AssetStore: TLAssetStore = {\n\tupload: async (_, file) => {\n\t\treturn { src: await FileHelpers.blobToDataUrl(file) }\n\t},\n}\n\n/**\n * A helper for creating a TLStore schema from either an object with shapeUtils, bindingUtils, and\n * migrations, or a schema.\n *\n * @param opts - Options for creating the schema.\n *\n * @public\n */\nexport function createTLSchemaFromUtils(\n\topts: TLStoreSchemaOptions\n): StoreSchema<TLRecord, TLStoreProps> {\n\tif ('schema' in opts && opts.schema) return opts.schema\n\n\treturn createTLSchema({\n\t\tshapes:\n\t\t\t'shapeUtils' in opts && opts.shapeUtils\n\t\t\t\t? utilsToMap(checkShapesAndAddCore(opts.shapeUtils))\n\t\t\t\t: undefined,\n\t\tbindings:\n\t\t\t'bindingUtils' in opts && opts.bindingUtils\n\t\t\t\t? utilsToMap(checkBindings(opts.bindingUtils))\n\t\t\t\t: undefined,\n\t\tassets:\n\t\t\t'assetUtils' in opts && opts.assetUtils\n\t\t\t\t? utilsToMap(checkAssets(opts.assetUtils))\n\t\t\t\t: undefined,\n\t\trecords: 'records' in opts ? opts.records : undefined,\n\t\tmigrations: 'migrations' in opts ? opts.migrations : undefined,\n\t})\n}\n\n/**\n * A helper for creating a TLStore.\n *\n * @param opts - Options for creating the store.\n *\n * @public\n */\nexport function createTLStore({\n\tinitialData,\n\tdefaultName = '',\n\tid,\n\tassets = inlineBase64AssetStore,\n\tusers = defaultUserStore,\n\tonMount,\n\tcollaboration,\n\tthemes,\n\t...rest\n}: TLStoreOptions = {}): TLStore {\n\tconst resolvedThemes = resolveThemes(themes)\n\tregisterColorsFromThemes(resolvedThemes)\n\tregisterFontsFromThemes(resolvedThemes)\n\tconst schema = createTLSchemaFromUtils(rest)\n\n\tconst store = new Store({\n\t\tid,\n\t\tschema,\n\t\tinitialData,\n\t\tprops: {\n\t\t\tdefaultName,\n\t\t\tassets: {\n\t\t\t\tupload: assets.upload,\n\t\t\t\tresolve: assets.resolve ?? defaultAssetResolve,\n\t\t\t\tremove: assets.remove ?? (() => Promise.resolve()),\n\t\t\t},\n\t\t\tusers: {\n\t\t\t\tcurrentUser: users.currentUser,\n\t\t\t\tresolve:\n\t\t\t\t\tusers.resolve ??\n\t\t\t\t\tcreateCachedUserResolve((userId) => {\n\t\t\t\t\t\tconst current = users.currentUser.get()\n\t\t\t\t\t\treturn current && current.id === createUserId(userId) ? current : null\n\t\t\t\t\t}),\n\t\t\t},\n\t\t\tonMount: (editor) => {\n\t\t\t\tassert(editor instanceof Editor)\n\t\t\t\tonMount?.(editor)\n\t\t\t},\n\t\t\tcollaboration,\n\t\t},\n\t})\n\n\tif (rest.snapshot) {\n\t\tif (initialData) throw new Error('Cannot provide both initialData and snapshot')\n\t\tloadSnapshot(store, rest.snapshot, { forceOverwriteSessionState: true })\n\t}\n\n\treturn store\n}\n\nfunction utilsToMap<T extends SchemaPropsInfo & { type: string }>(utils: T[]) {\n\treturn Object.fromEntries(\n\t\tutils.map((s): [string, SchemaPropsInfo] => [\n\t\t\ts.type,\n\t\t\t{\n\t\t\t\tprops: s.props,\n\t\t\t\tmigrations: s.migrations,\n\t\t\t},\n\t\t])\n\t)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAiB,gBAAgB;AACjC,SAA2D,aAA0B;AACrF;AAAA,EAWC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,cAAc;AACpC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAC9B,SAAoC,mBAAmB;AACvD,SAAsC,qBAAqB;AAC3D,SAAoC,6BAA6B;AACjE,SAA2B,oBAAoB;AAC/C,SAAS,wBAAwB,0BAA0B;A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Q,IAAI,MAAM;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACN;AAAA,MACA,QAAQ;AAAA,QACP,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO,WAAW;AAAA,QAC3B,QAAQ,OAAO,WAAW,MAAM,QAAQ,QAAQ;AAAA,MACjD;AAAA,MACA,OAAO;AAAA,QACN,aAAa,MAAM;AAAA,QACnB,SACC,MAAM,WACN,wBAAwB,CAAC,WAAW;AACnC,gBAAM,UAAU,MAAM,YAAY,IAAI;AACtC,iBAAO,WAAW,QAAQ,OAAO,aAAa,MAAM,IAAI,UAAU;AAAA,QACnE,CAAC;AAAA,MACH;AAAA,MACA,SAAS,CAAC,WAAW;AACpB,eAAO,kBAAkB,MAAM;AAC/B,kBAAU,MAAM;AAAA,MACjB;AAAA,MACA;AAAA,IACD;AAAA,EACD,CAAC;AAED,MAAI,KAAK,UAAU;AAClB,QAAI,YAAa,OAAM,IAAI,MAAM,8CAA8C;AAC/E,iBAAa,OAAO,KAAK,UAAU,EAAE,4BAA4B,KAAK,CAAC;AAAA,EACxE;AAEA,SAAO;AACR;AAEA,SAAS,WAAyD,OAAY;AAC7E,SAAO,OAAO;AAAA,IACb,MAAM,IAAI,CAAC,MAAiC;AAAA,MAC3C,EAAE;AAAA,MACF;AAAA,QACC,OAAO,EAAE;AAAA,QACT,YAAY,EAAE;AAAA,MACf;AAAA,IACD,CAAC;AAAA,EACF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function checkAssets(customAssets) {
|
|
2
|
+
const assets = [];
|
|
3
|
+
const addedCustomAssetTypes = /* @__PURE__ */ new Set();
|
|
4
|
+
for (const customAsset of customAssets) {
|
|
5
|
+
if (addedCustomAssetTypes.has(customAsset.type)) {
|
|
6
|
+
throw new Error(`Asset type "${customAsset.type}" is defined more than once`);
|
|
7
|
+
}
|
|
8
|
+
assets.push(customAsset);
|
|
9
|
+
addedCustomAssetTypes.add(customAsset.type);
|
|
10
|
+
}
|
|
11
|
+
return assets;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
checkAssets
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=defaultAssets.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/config/defaultAssets.ts"],
|
|
4
|
+
"sourcesContent": ["import { TLAssetUtilConstructor } from '../editor/assets/AssetUtil'\n\n/** @public */\nexport type TLAnyAssetUtilConstructor = TLAssetUtilConstructor<any>\n\nexport function checkAssets(customAssets: readonly TLAnyAssetUtilConstructor[]) {\n\tconst assets = [] as TLAnyAssetUtilConstructor[]\n\n\tconst addedCustomAssetTypes = new Set<string>()\n\tfor (const customAsset of customAssets) {\n\t\tif (addedCustomAssetTypes.has(customAsset.type)) {\n\t\t\tthrow new Error(`Asset type \"${customAsset.type}\" is defined more than once`)\n\t\t}\n\t\tassets.push(customAsset)\n\t\taddedCustomAssetTypes.add(customAsset.type)\n\t}\n\n\treturn assets\n}\n"],
|
|
5
|
+
"mappings": "AAKO,SAAS,YAAY,cAAoD;AAC/E,QAAM,SAAS,CAAC;AAEhB,QAAM,wBAAwB,oBAAI,IAAY;AAC9C,aAAW,eAAe,cAAc;AACvC,QAAI,sBAAsB,IAAI,YAAY,IAAI,GAAG;AAChD,YAAM,IAAI,MAAM,eAAe,YAAY,IAAI,6BAA6B;AAAA,IAC7E;AACA,WAAO,KAAK,WAAW;AACvB,0BAAsB,IAAI,YAAY,IAAI;AAAA,EAC3C;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -65,6 +65,7 @@ import {
|
|
|
65
65
|
} from "@tldraw/utils";
|
|
66
66
|
import EventEmitter from "eventemitter3";
|
|
67
67
|
import { createTLCurrentUser } from "../config/createTLCurrentUser.mjs";
|
|
68
|
+
import { checkAssets } from "../config/defaultAssets.mjs";
|
|
68
69
|
import { checkBindings } from "../config/defaultBindings.mjs";
|
|
69
70
|
import { checkShapesAndAddCore } from "../config/defaultShapes.mjs";
|
|
70
71
|
import {
|
|
@@ -119,6 +120,7 @@ import { ScribbleManager } from "./managers/ScribbleManager/ScribbleManager.mjs"
|
|
|
119
120
|
import { SnapManager } from "./managers/SnapManager/SnapManager.mjs";
|
|
120
121
|
import { SpatialIndexManager } from "./managers/SpatialIndexManager/SpatialIndexManager.mjs";
|
|
121
122
|
import { TextManager } from "./managers/TextManager/TextManager.mjs";
|
|
123
|
+
import { resolveThemes, ThemeManager } from "./managers/ThemeManager/ThemeManager.mjs";
|
|
122
124
|
import { TickManager } from "./managers/TickManager/TickManager.mjs";
|
|
123
125
|
import { UserPreferencesManager } from "./managers/UserPreferencesManager/UserPreferencesManager.mjs";
|
|
124
126
|
import { RootState } from "./tools/RootState.mjs";
|
|
@@ -129,6 +131,7 @@ class Editor extends EventEmitter {
|
|
|
129
131
|
user,
|
|
130
132
|
shapeUtils,
|
|
131
133
|
bindingUtils,
|
|
134
|
+
assetUtils: assetUtilConstructors,
|
|
132
135
|
tools,
|
|
133
136
|
getContainer,
|
|
134
137
|
// needs to be here for backwards compatibility with TldrawEditor
|
|
@@ -136,13 +139,15 @@ class Editor extends EventEmitter {
|
|
|
136
139
|
cameraOptions,
|
|
137
140
|
initialState,
|
|
138
141
|
autoFocus,
|
|
139
|
-
inferDarkMode,
|
|
140
142
|
options: _options,
|
|
141
143
|
// needs to be here for backwards compatibility with TldrawEditor
|
|
142
144
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
143
145
|
textOptions: _textOptions,
|
|
144
146
|
getShapeVisibility,
|
|
145
|
-
|
|
147
|
+
colorScheme,
|
|
148
|
+
fontAssetUrls,
|
|
149
|
+
themes,
|
|
150
|
+
initialTheme
|
|
146
151
|
}) {
|
|
147
152
|
super();
|
|
148
153
|
this._getShapeVisibility = getShapeVisibility;
|
|
@@ -165,18 +170,24 @@ class Editor extends EventEmitter {
|
|
|
165
170
|
...cameraOptions,
|
|
166
171
|
...options?.camera
|
|
167
172
|
});
|
|
173
|
+
this.getContainer = getContainer;
|
|
168
174
|
this._textOptions = atom("text options", options?.text ?? null);
|
|
169
|
-
this.user = new UserPreferencesManager(user ?? createTLCurrentUser(),
|
|
175
|
+
this.user = new UserPreferencesManager(user ?? createTLCurrentUser(), colorScheme ?? "light");
|
|
170
176
|
this.disposables.add(() => this.user.dispose());
|
|
171
|
-
this.getContainer = getContainer;
|
|
172
177
|
this.textMeasure = new TextManager(this);
|
|
173
178
|
this.disposables.add(() => this.textMeasure.dispose());
|
|
174
|
-
this.
|
|
179
|
+
this._themeManager = new ThemeManager(this, {
|
|
180
|
+
themes: resolveThemes(themes),
|
|
181
|
+
initial: initialTheme ?? "default"
|
|
182
|
+
});
|
|
183
|
+
this.disposables.add(() => this._themeManager.dispose());
|
|
175
184
|
this._tickManager = new TickManager(this);
|
|
185
|
+
this.disposables.add(() => this._tickManager.dispose());
|
|
176
186
|
this.disposables.add(() => {
|
|
177
187
|
this.off("tick", this._decayCameraStateTimeout);
|
|
178
188
|
this._setCameraState("idle");
|
|
179
189
|
});
|
|
190
|
+
this.fonts = new FontManager(this, fontAssetUrls);
|
|
180
191
|
this.inputs = new InputsManager(this);
|
|
181
192
|
class NewRoot extends RootState {
|
|
182
193
|
static initial = initialState ?? "";
|
|
@@ -205,6 +216,16 @@ class Editor extends EventEmitter {
|
|
|
205
216
|
}
|
|
206
217
|
this.shapeUtils = _shapeUtils;
|
|
207
218
|
this.styleProps = _styleProps;
|
|
219
|
+
const _shapeUtilsByAssetType = {};
|
|
220
|
+
for (const Util of allShapeUtils) {
|
|
221
|
+
const assetTypes = Util.handledAssetTypes;
|
|
222
|
+
if (assetTypes) {
|
|
223
|
+
for (const assetType of assetTypes) {
|
|
224
|
+
_shapeUtilsByAssetType[assetType] = _shapeUtils[Util.type];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
this._shapeUtilsByAssetType = _shapeUtilsByAssetType;
|
|
208
229
|
const allBindingUtils = checkBindings(bindingUtils);
|
|
209
230
|
const _bindingUtils = {};
|
|
210
231
|
for (const Util of allBindingUtils) {
|
|
@@ -212,6 +233,15 @@ class Editor extends EventEmitter {
|
|
|
212
233
|
_bindingUtils[Util.type] = util;
|
|
213
234
|
}
|
|
214
235
|
this.bindingUtils = _bindingUtils;
|
|
236
|
+
if (assetUtilConstructors) {
|
|
237
|
+
const allAssetUtils = checkAssets(assetUtilConstructors);
|
|
238
|
+
const _assetUtils = {};
|
|
239
|
+
for (const Util of allAssetUtils) {
|
|
240
|
+
const util = new Util(this);
|
|
241
|
+
_assetUtils[Util.type] = util;
|
|
242
|
+
}
|
|
243
|
+
this.assetUtils = _assetUtils;
|
|
244
|
+
}
|
|
215
245
|
for (const Tool of [...tools]) {
|
|
216
246
|
if (hasOwnProperty(this.root.children, Tool.id)) {
|
|
217
247
|
throw Error(`Can't override tool with id "${Tool.id}"`);
|
|
@@ -652,6 +682,11 @@ class Editor extends EventEmitter {
|
|
|
652
682
|
* @public
|
|
653
683
|
*/
|
|
654
684
|
snaps;
|
|
685
|
+
/**
|
|
686
|
+
* A manager for the spatial index, tracking where shapes exist on the canvas.
|
|
687
|
+
*
|
|
688
|
+
* @internal
|
|
689
|
+
*/
|
|
655
690
|
_spatialIndex;
|
|
656
691
|
/**
|
|
657
692
|
* A manager for the any asynchronous events and making sure they're
|
|
@@ -666,6 +701,12 @@ class Editor extends EventEmitter {
|
|
|
666
701
|
* @public
|
|
667
702
|
*/
|
|
668
703
|
user;
|
|
704
|
+
/**
|
|
705
|
+
* A manager for the editor's themes.
|
|
706
|
+
*
|
|
707
|
+
* @internal
|
|
708
|
+
*/
|
|
709
|
+
_themeManager;
|
|
669
710
|
/**
|
|
670
711
|
* A helper for measuring text.
|
|
671
712
|
*
|
|
@@ -737,12 +778,117 @@ class Editor extends EventEmitter {
|
|
|
737
778
|
* @public
|
|
738
779
|
*/
|
|
739
780
|
dispose() {
|
|
781
|
+
this.stopCameraAnimation();
|
|
782
|
+
if (this.getInstanceState().followingUserId) {
|
|
783
|
+
this.stopFollowingUser();
|
|
784
|
+
}
|
|
740
785
|
this.disposables.forEach((dispose) => dispose());
|
|
741
786
|
this.disposables.clear();
|
|
787
|
+
this.menus.clearOpenMenus();
|
|
742
788
|
this.store.dispose();
|
|
743
789
|
this.isDisposed = true;
|
|
744
790
|
this.emit("dispose");
|
|
745
791
|
}
|
|
792
|
+
/* ------------------ Themes (shadowing the theme manager) ------------------ */
|
|
793
|
+
/**
|
|
794
|
+
* Get the current color mode (`'light'` or `'dark'`), based on the user's dark mode preference.
|
|
795
|
+
*
|
|
796
|
+
* @public
|
|
797
|
+
*/
|
|
798
|
+
getColorMode() {
|
|
799
|
+
return this._themeManager.getColorMode();
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Set the color mode. Note that this is a convenience method that passes the mode to
|
|
803
|
+
* `user.updateUserPreferences`, which is the source of truth for the user's color mode preference.
|
|
804
|
+
*
|
|
805
|
+
* @public
|
|
806
|
+
*/
|
|
807
|
+
setColorMode(mode) {
|
|
808
|
+
this.user.updateUserPreferences({ colorScheme: mode });
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Get the id of the current theme.
|
|
813
|
+
*
|
|
814
|
+
* @public
|
|
815
|
+
*/
|
|
816
|
+
getCurrentThemeId() {
|
|
817
|
+
return this._themeManager.getCurrentThemeId();
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Get the current theme definition.
|
|
821
|
+
*
|
|
822
|
+
* @public
|
|
823
|
+
*/
|
|
824
|
+
getCurrentTheme() {
|
|
825
|
+
return this._themeManager.getCurrentTheme();
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Set the current theme by id.
|
|
829
|
+
*
|
|
830
|
+
* @public
|
|
831
|
+
*/
|
|
832
|
+
setCurrentTheme(id) {
|
|
833
|
+
this._themeManager.setCurrentTheme(id);
|
|
834
|
+
return this;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Get all registered theme definitions.
|
|
838
|
+
*
|
|
839
|
+
* @public
|
|
840
|
+
*/
|
|
841
|
+
getThemes() {
|
|
842
|
+
return this._themeManager.getThemes();
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Get a single theme definition by id.
|
|
846
|
+
*
|
|
847
|
+
* @public
|
|
848
|
+
*/
|
|
849
|
+
getTheme(id) {
|
|
850
|
+
return this._themeManager.getTheme(id);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Replace all theme definitions, or update them via a callback that receives a deep copy.
|
|
854
|
+
* The `'default'` theme must always be present in the result.
|
|
855
|
+
*
|
|
856
|
+
* @example
|
|
857
|
+
* ```ts
|
|
858
|
+
* // Replace all themes
|
|
859
|
+
* editor.updateThemes({ default: myDefaultTheme, ocean: myOceanTheme })
|
|
860
|
+
*
|
|
861
|
+
* // Update via callback
|
|
862
|
+
* editor.updateThemes((themes) => {
|
|
863
|
+
* delete themes.ocean
|
|
864
|
+
* return themes
|
|
865
|
+
* })
|
|
866
|
+
* ```
|
|
867
|
+
*
|
|
868
|
+
* @public
|
|
869
|
+
*/
|
|
870
|
+
updateThemes(themes) {
|
|
871
|
+
this._themeManager.updateThemes(themes);
|
|
872
|
+
return this;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Register or update a single theme definition. The theme is keyed by its `id` property.
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
* ```ts
|
|
879
|
+
* // Override a property on the default theme
|
|
880
|
+
* editor.updateTheme({ ...editor.getTheme('default')!, fontSize: 24 })
|
|
881
|
+
*
|
|
882
|
+
* // Register a new theme
|
|
883
|
+
* editor.updateTheme({ id: 'ocean', ...myOceanTheme })
|
|
884
|
+
* ```
|
|
885
|
+
*
|
|
886
|
+
* @public
|
|
887
|
+
*/
|
|
888
|
+
updateTheme(theme) {
|
|
889
|
+
this._themeManager.updateTheme(theme);
|
|
890
|
+
return this;
|
|
891
|
+
}
|
|
746
892
|
/* ------------------- Shape Utils ------------------ */
|
|
747
893
|
/**
|
|
748
894
|
* A map of shape utility classes (TLShapeUtils) by shape type.
|
|
@@ -750,6 +896,8 @@ class Editor extends EventEmitter {
|
|
|
750
896
|
* @public
|
|
751
897
|
*/
|
|
752
898
|
shapeUtils;
|
|
899
|
+
/** @internal */
|
|
900
|
+
_shapeUtilsByAssetType = {};
|
|
753
901
|
styleProps;
|
|
754
902
|
getShapeUtil(arg) {
|
|
755
903
|
const type = typeof arg === "string" ? arg : arg.type;
|
|
@@ -761,6 +909,17 @@ class Editor extends EventEmitter {
|
|
|
761
909
|
const type = typeof arg === "string" ? arg : arg.type;
|
|
762
910
|
return hasOwnProperty(this.shapeUtils, type);
|
|
763
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Get the shape util that handles the given asset type.
|
|
914
|
+
* Returns the shape util whose {@link ShapeUtil.handledAssetTypes} includes
|
|
915
|
+
* the given asset type, or undefined if none matches.
|
|
916
|
+
*
|
|
917
|
+
* @param assetType - The asset type string.
|
|
918
|
+
* @public
|
|
919
|
+
*/
|
|
920
|
+
getShapeUtilForAssetType(assetType) {
|
|
921
|
+
return getOwnProperty(this._shapeUtilsByAssetType, assetType);
|
|
922
|
+
}
|
|
764
923
|
/* ------------------- Binding Utils ------------------ */
|
|
765
924
|
/**
|
|
766
925
|
* A map of shape utility classes (TLShapeUtils) by shape type.
|
|
@@ -774,6 +933,42 @@ class Editor extends EventEmitter {
|
|
|
774
933
|
assert(bindingUtil, `No binding util found for type "${type}"`);
|
|
775
934
|
return bindingUtil;
|
|
776
935
|
}
|
|
936
|
+
/* ------------------- Asset Utils ------------------ */
|
|
937
|
+
/**
|
|
938
|
+
* A map of asset utility classes by asset type.
|
|
939
|
+
*
|
|
940
|
+
* @public
|
|
941
|
+
*/
|
|
942
|
+
assetUtils = {};
|
|
943
|
+
getAssetUtil(arg) {
|
|
944
|
+
const type = typeof arg === "string" ? arg : arg.type;
|
|
945
|
+
const assetUtil = getOwnProperty(this.assetUtils, type);
|
|
946
|
+
assert(assetUtil, `No asset util found for type "${type}"`);
|
|
947
|
+
return assetUtil;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Returns true if the editor has an asset util for the given asset type.
|
|
951
|
+
*
|
|
952
|
+
* @public
|
|
953
|
+
*/
|
|
954
|
+
hasAssetUtil(arg) {
|
|
955
|
+
const type = typeof arg === "string" ? arg : arg.type;
|
|
956
|
+
return hasOwnProperty(this.assetUtils, type);
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Get the asset util that accepts the given MIME type.
|
|
960
|
+
* Returns null if no registered asset util accepts the MIME type.
|
|
961
|
+
*
|
|
962
|
+
* @public
|
|
963
|
+
*/
|
|
964
|
+
getAssetUtilForMimeType(mimeType) {
|
|
965
|
+
for (const util of Object.values(this.assetUtils)) {
|
|
966
|
+
if (util && util.acceptsMimeType(mimeType)) {
|
|
967
|
+
return util;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return null;
|
|
971
|
+
}
|
|
777
972
|
/* --------------------- History -------------------- */
|
|
778
973
|
/**
|
|
779
974
|
* A manager for the editor's history.
|