@tldraw/editor 5.3.0-canary.fceaae5e9feb → 5.3.0-internal.fba91ed55f6c
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 +37 -2
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +6 -1
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +65 -13
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +9 -0
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +3 -0
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +3 -0
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/license/LicenseManager.js +62 -7
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/useLicenseManagerState.js +7 -0
- package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
- package/dist-cjs/lib/options.js +2 -1
- package/dist-cjs/lib/options.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 +37 -2
- package/dist-esm/index.mjs +5 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +6 -1
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +65 -13
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +9 -0
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +3 -0
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +3 -0
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseManager.mjs +63 -8
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/useLicenseManagerState.mjs +7 -0
- package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +2 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +10 -0
- package/package.json +7 -7
- package/src/index.ts +3 -1
- package/src/lib/TldrawEditor.tsx +10 -1
- package/src/lib/editor/Editor.ts +97 -18
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +66 -0
- package/src/lib/editor/managers/FontManager/FontManager.ts +14 -0
- package/src/lib/editor/managers/TextManager/TextManager.ts +3 -0
- package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +6 -1
- package/src/lib/editor/types/emit-types.ts +1 -0
- package/src/lib/license/LicenseManager.test.ts +220 -29
- package/src/lib/license/LicenseManager.ts +107 -6
- package/src/lib/license/useLicenseManagerState.ts +17 -1
- package/src/lib/options.ts +3 -1
- package/src/version.ts +3 -3
package/dist-esm/lib/options.mjs
CHANGED
|
@@ -30,7 +30,8 @@ const defaultTldrawOptions = {
|
|
|
30
30
|
collaboratorIdleTimeoutMs: 3e3,
|
|
31
31
|
collaboratorCheckIntervalMs: 1200,
|
|
32
32
|
cameraMovingTimeoutMs: 64,
|
|
33
|
-
hitTestMargin:
|
|
33
|
+
hitTestMargin: 3,
|
|
34
|
+
coarseHitTestMargin: 4,
|
|
34
35
|
edgeScrollDelay: 200,
|
|
35
36
|
edgeScrollEaseDuration: 200,
|
|
36
37
|
edgeScrollSpeed: 25,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/options.ts"],
|
|
4
|
-
"sourcesContent": ["import { Awaitable } from '@tldraw/utils'\nimport { ComponentType, Fragment } from 'react'\nimport { DEFAULT_CAMERA_OPTIONS } from './constants'\nimport type { Editor } from './editor/Editor'\nimport { TLContent } from './editor/types/clipboard-types'\nimport { TLExternalContent } from './editor/types/external-content'\nimport { TLCameraOptions } from './editor/types/misc-types'\nimport { VecLike } from './primitives/Vec'\nimport { TLDeepLinkOptions } from './utils/deepLinks'\nimport { TLTextOptions } from './utils/richText'\n\n/**\n * Identifies how a clipboard write was triggered (copy vs cut, keyboard vs menu).\n *\n * @public\n */\nexport interface TLClipboardWriteInfo {\n\treadonly operation: 'copy' | 'cut'\n\treadonly source: 'native' | 'menu'\n}\n\n/**\n * Raw clipboard paste payload, before tldraw parses clipboard contents into {@link TLExternalContent}.\n *\n * - `native-event`: from the `paste` event \u2014 `clipboardData` is available synchronously (unlike async\n * `navigator.clipboard.read()`).\n * - `clipboard-read`: from an explicit `navigator.clipboard.read()` call \u2014 only `ClipboardItem[]`\n * exists\n * (no `DataTransfer`).\n *\n * @public\n */\nexport type TLClipboardPasteRawInfo =\n\t| {\n\t\t\treadonly editor: Editor\n\t\t\treadonly source: 'native-event'\n\t\t\treadonly event: ClipboardEvent\n\t\t\treadonly clipboardData: DataTransfer | null\n\t\t\treadonly point: VecLike | undefined\n\t }\n\t| {\n\t\t\treadonly editor: Editor\n\t\t\treadonly source: 'clipboard-read'\n\t\t\treadonly clipboardItems: readonly ClipboardItem[]\n\t\t\treadonly point: VecLike | undefined\n\t }\n\n/**\n * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.\n *\n * @example\n * ```tsx\n * const options: Partial<TldrawOptions> = {\n * maxPages: 3,\n * maxShapesPerPage: 1000,\n * }\n *\n * function MyTldrawComponent() {\n * return <Tldraw options={options} />\n * }\n * ```\n *\n * @public\n */\nexport interface TldrawOptions {\n\treadonly maxShapesPerPage: number\n\treadonly maxFilesAtOnce: number\n\treadonly maxPages: number\n\treadonly animationMediumMs: number\n\treadonly followChaseViewportSnap: number\n\treadonly doubleClickDurationMs: number\n\treadonly multiClickDurationMs: number\n\treadonly coarseDragDistanceSquared: number\n\treadonly dragDistanceSquared: number\n\treadonly uiDragDistanceSquared: number\n\treadonly uiCoarseDragDistanceSquared: number\n\treadonly defaultSvgPadding: number\n\treadonly cameraSlideFriction: number\n\treadonly gridSteps: readonly {\n\t\treadonly min: number\n\t\treadonly mid: number\n\t\treadonly step: number\n\t}[]\n\treadonly collaboratorInactiveTimeoutMs: number\n\treadonly collaboratorIdleTimeoutMs: number\n\treadonly collaboratorCheckIntervalMs: number\n\treadonly cameraMovingTimeoutMs: number\n\treadonly hitTestMargin: number\n\treadonly edgeScrollDelay: number\n\treadonly edgeScrollEaseDuration: number\n\treadonly edgeScrollSpeed: number\n\treadonly edgeScrollDistance: number\n\treadonly coarsePointerWidth: number\n\treadonly coarseHandleRadius: number\n\treadonly handleRadius: number\n\treadonly longPressDurationMs: number\n\treadonly textShadowLod: number\n\treadonly adjacentShapeMargin: number\n\treadonly flattenImageBoundsExpand: number\n\treadonly flattenImageBoundsPadding: number\n\treadonly laserDelayMs: number\n\t/**\n\t * How long (in milliseconds) to fade all laser scribbles after the session ends.\n\t * The total points across all scribbles will be removed proportionally over this duration.\n\t * Defaults to 500ms (0.5 seconds).\n\t */\n\treadonly laserFadeoutMs: number\n\treadonly maxExportDelayMs: number\n\treadonly tooltipDelayMs: number\n\t/**\n\t * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before\n\t * they expire? Defaults to 3 minutes.\n\t */\n\treadonly temporaryAssetPreviewLifetimeMs: number\n\treadonly actionShortcutsLocation: 'menu' | 'toolbar' | 'swap'\n\treadonly createTextOnCanvasDoubleClick: boolean\n\t/**\n\t * The react provider to use when exporting an image. This is useful if your shapes depend on\n\t * external context providers. By default, this is `React.Fragment`.\n\t */\n\treadonly exportProvider: ComponentType<{ children: React.ReactNode }>\n\t/**\n\t * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.\n\t */\n\treadonly enableToolbarKeyboardShortcuts: boolean\n\t/**\n\t * The maximum number of fonts that will be loaded while blocking the main rendering of the\n\t * canvas. If there are more than this number of fonts needed, we'll just show the canvas right\n\t * away and let the fonts load in in the background.\n\t */\n\treadonly maxFontsToLoadBeforeRender: number\n\t/**\n\t * If you have a CSP policy that blocks inline styles, you can use this prop to provide a\n\t * nonce to use in the editor's styles.\n\t */\n\treadonly nonce: string | undefined\n\t/**\n\t * Branding name of the app, currently only used for adding aria-label for the application.\n\t */\n\treadonly branding?: string\n\t/**\n\t * Whether to use debounced zoom level for certain rendering optimizations. When true,\n\t * `editor.getEfficientZoomLevel()` returns a cached zoom value while the camera is moving,\n\t * reducing re-renders. When false, it always returns the current zoom level.\n\t */\n\treadonly debouncedZoom: boolean\n\t/**\n\t * The number of shapes that must be on the page for the debounced zoom level to be used.\n\t * Defaults to 500 shapes.\n\t */\n\treadonly debouncedZoomThreshold: number\n\t/**\n\t * Whether to allow spacebar panning. When true, the spacebar will pan the camera when held down.\n\t * When false, the spacebar will not pan the camera.\n\t */\n\treadonly spacebarPanning: boolean\n\t/**\n\t * Whether to allow right-click + drag to pan the camera. When true, right-click + drag pans the\n\t * camera and a static right-click opens the context menu at the release position. When false,\n\t * right-click opens the context menu on press (no drag-to-pan).\n\t */\n\treadonly rightClickPanning: boolean\n\t/**\n\t * The default padding (in pixels) used when zooming to fit content in the viewport.\n\t * This affects methods like `zoomToFit()`, `zoomToSelection()`, and `zoomToBounds()`.\n\t * The actual padding used is the minimum of this value and 28% of the viewport width.\n\t * Defaults to 128 pixels.\n\t */\n\treadonly zoomToFitPadding: number\n\t/**\n\t * The distance (in screen pixels) at which shapes snap to guides and other shapes.\n\t */\n\treadonly snapThreshold: number\n\t/**\n\t * Whether locked shapes can be selected with a left click. When false (default), left-clicking\n\t * a locked shape is treated as a click on the canvas \u2014 only right-click selects it. When true,\n\t * locked shapes can be selected via left click and included in brush and scribble selections,\n\t * but the editor's lock guards still prevent moving, resizing, editing, or deleting them.\n\t */\n\treadonly selectLockedShapes: boolean\n\t/**\n\t * Options for the editor's camera. These are the initial camera options.\n\t * Use {@link Editor.setCameraOptions} to update camera options at runtime.\n\t */\n\treadonly camera: Partial<TLCameraOptions>\n\t/**\n\t * Options for the editor's text rendering. These include TipTap configuration and\n\t * font handling. These are the initial text options and cannot be changed at runtime.\n\t */\n\treadonly text: TLTextOptions\n\t/**\n\t * Options for syncing the editor's camera state with the URL. Set to `true` to enable\n\t * with default options, or pass an options object to customize behavior.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Enable with defaults\n\t * <Tldraw options={{ deepLinks: true }} />\n\t *\n\t * // Enable with custom options\n\t * <Tldraw options={{ deepLinks: { param: 'd', debounceMs: 500 } }} />\n\t * ```\n\t */\n\treadonly deepLinks: true | TLDeepLinkOptions | undefined\n\t/**\n\t * Whether the quick-zoom brush preserves its screen-pixel size when the user\n\t * zooms the overview. When true, zooming in shrinks the target viewport (higher\n\t * return zoom); zooming out expands it. When false, the brush keeps the original\n\t * viewport's page dimensions regardless of overview zoom changes.\n\t */\n\treadonly quickZoomPreservesScreenBounds: boolean\n\t/**\n\t * Called before content is written to the clipboard during a copy or cut operation.\n\t * Receives the serialized content (shapes, bindings, assets) and can filter or transform\n\t * it before it reaches the clipboard.\n\t *\n\t * Return a modified `TLContent` object to change what is copied or cut. Return `false` to\n\t * cancel the clipboard write (for cut, the selected shapes are not removed). Return `void`\n\t * (or `undefined`) to pass through unchanged. You may return a `Promise` of those values if\n\t * the hook is async.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Filter out \"locked\" shapes from copy\n\t * onBeforeCopyToClipboard({ content, operation }) {\n\t * return {\n\t * ...content,\n\t * shapes: content.shapes.filter(s => !s.meta.locked),\n\t * rootShapeIds: content.rootShapeIds.filter(id =>\n\t * content.shapes.find(s => s.id === id && !s.meta.locked)\n\t * ),\n\t * }\n\t * }\n\t * ```\n\t */\n\tonBeforeCopyToClipboard?(\n\t\tinfo: { editor: Editor; content: TLContent } & TLClipboardWriteInfo\n\t): Awaitable<TLContent | false | void>\n\t/**\n\t * Called before pasted content is processed and shapes are created. Receives the parsed\n\t * external content from the clipboard and can filter, transform, or cancel it.\n\t *\n\t * Return `false` to cancel the paste. Return a modified content object to transform it.\n\t * Return `void` (or `undefined`) to pass through unchanged. You may return a `Promise` of\n\t * those values if the hook is async.\n\t *\n\t * This only fires for clipboard paste operations (keyboard shortcuts and menu actions),\n\t * not for file drops or programmatic `putExternalContent` calls.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Block pasting of image files\n\t * onBeforePasteFromClipboard({ content }) {\n\t * if (content.type === 'files') {\n\t * const nonImages = content.files.filter(f => !f.type.startsWith('image/'))\n\t * if (nonImages.length === 0) return false\n\t * return { ...content, files: nonImages }\n\t * }\n\t * }\n\t * ```\n\t */\n\tonBeforePasteFromClipboard?(info: {\n\t\teditor: Editor\n\t\tcontent: TLExternalContent<unknown>\n\t\tsource: 'native-event' | 'clipboard-read'\n\t\tpoint?: VecLike\n\t}): Awaitable<TLExternalContent<unknown> | false | void>\n\t/**\n\t * Called first for keyboard and menu paste, **before** tldraw handles or parses clipboard data\n\t * (and before {@link TldrawOptions.onBeforePasteFromClipboard}).\n\t *\n\t * Return `false` to cancel tldraw's default paste handling for this gesture (same convention as\n\t * {@link TldrawOptions.onBeforePasteFromClipboard}). Use this when you handle paste yourself from\n\t * raw clipboard data, or to block the gesture entirely. Return `void` (or `undefined`) to continue.\n\t */\n\tonClipboardPasteRaw?(info: TLClipboardPasteRawInfo): false | void\n\t/**\n\t * Called when content is dropped on the canvas. Provides the page position\n\t * where the drop occurred and the underlying drag event object.\n\t * Return true to prevent default drop handling (files, URLs, etc.)\n\t */\n\texperimental__onDropOnCanvas?(options: {\n\t\tpoint: VecLike\n\t\tevent: React.DragEvent<Element>\n\t}): boolean\n}\n\n/** @public */\nexport const defaultTldrawOptions = {\n\tmaxShapesPerPage: 4000,\n\tmaxFilesAtOnce: 100,\n\tmaxPages: 40,\n\tanimationMediumMs: 320,\n\tfollowChaseViewportSnap: 2,\n\tdoubleClickDurationMs: 450,\n\tmultiClickDurationMs: 200,\n\tcoarseDragDistanceSquared: 36, // 6 squared\n\tdragDistanceSquared: 16, // 4 squared\n\tuiDragDistanceSquared: 16, // 4 squared\n\t// it's really easy to accidentally drag from the toolbar on mobile, so we use a much larger\n\t// threshold than usual here to try and prevent accidental drags.\n\tuiCoarseDragDistanceSquared: 625, // 25 squared\n\tdefaultSvgPadding: 32,\n\tcameraSlideFriction: 0.09,\n\tgridSteps: [\n\t\t{ min: -1, mid: 0.15, step: 64 },\n\t\t{ min: 0.05, mid: 0.375, step: 16 },\n\t\t{ min: 0.15, mid: 1, step: 4 },\n\t\t{ min: 0.7, mid: 2.5, step: 1 },\n\t],\n\tcollaboratorInactiveTimeoutMs: 60000,\n\tcollaboratorIdleTimeoutMs: 3000,\n\tcollaboratorCheckIntervalMs: 1200,\n\tcameraMovingTimeoutMs: 64,\n\thitTestMargin: 8,\n\tedgeScrollDelay: 200,\n\tedgeScrollEaseDuration: 200,\n\tedgeScrollSpeed: 25,\n\tedgeScrollDistance: 8,\n\tcoarsePointerWidth: 12,\n\tcoarseHandleRadius: 20,\n\thandleRadius: 12,\n\tlongPressDurationMs: 500,\n\ttextShadowLod: 0.35,\n\tadjacentShapeMargin: 10,\n\tflattenImageBoundsExpand: 64,\n\tflattenImageBoundsPadding: 16,\n\tlaserDelayMs: 1200,\n\tlaserFadeoutMs: 500,\n\tmaxExportDelayMs: 5000,\n\ttooltipDelayMs: 700,\n\ttemporaryAssetPreviewLifetimeMs: 180000,\n\tactionShortcutsLocation: 'swap',\n\tcreateTextOnCanvasDoubleClick: true,\n\texportProvider: Fragment,\n\tenableToolbarKeyboardShortcuts: true,\n\tmaxFontsToLoadBeforeRender: Infinity,\n\tnonce: undefined,\n\tdebouncedZoom: true,\n\tdebouncedZoomThreshold: 500,\n\tspacebarPanning: true,\n\trightClickPanning: true,\n\tzoomToFitPadding: 128,\n\tsnapThreshold: 8,\n\tselectLockedShapes: false,\n\tcamera: DEFAULT_CAMERA_OPTIONS,\n\ttext: {},\n\tdeepLinks: undefined,\n\tquickZoomPreservesScreenBounds: true,\n\tonBeforeCopyToClipboard: undefined,\n\tonBeforePasteFromClipboard: undefined,\n\tonClipboardPasteRaw: undefined,\n\texperimental__onDropOnCanvas: undefined,\n} as const satisfies TldrawOptions\n"],
|
|
5
|
-
"mappings": "AACA,SAAwB,gBAAgB;AACxC,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import { Awaitable } from '@tldraw/utils'\nimport { ComponentType, Fragment } from 'react'\nimport { DEFAULT_CAMERA_OPTIONS } from './constants'\nimport type { Editor } from './editor/Editor'\nimport { TLContent } from './editor/types/clipboard-types'\nimport { TLExternalContent } from './editor/types/external-content'\nimport { TLCameraOptions } from './editor/types/misc-types'\nimport { VecLike } from './primitives/Vec'\nimport { TLDeepLinkOptions } from './utils/deepLinks'\nimport { TLTextOptions } from './utils/richText'\n\n/**\n * Identifies how a clipboard write was triggered (copy vs cut, keyboard vs menu).\n *\n * @public\n */\nexport interface TLClipboardWriteInfo {\n\treadonly operation: 'copy' | 'cut'\n\treadonly source: 'native' | 'menu'\n}\n\n/**\n * Raw clipboard paste payload, before tldraw parses clipboard contents into {@link TLExternalContent}.\n *\n * - `native-event`: from the `paste` event \u2014 `clipboardData` is available synchronously (unlike async\n * `navigator.clipboard.read()`).\n * - `clipboard-read`: from an explicit `navigator.clipboard.read()` call \u2014 only `ClipboardItem[]`\n * exists\n * (no `DataTransfer`).\n *\n * @public\n */\nexport type TLClipboardPasteRawInfo =\n\t| {\n\t\t\treadonly editor: Editor\n\t\t\treadonly source: 'native-event'\n\t\t\treadonly event: ClipboardEvent\n\t\t\treadonly clipboardData: DataTransfer | null\n\t\t\treadonly point: VecLike | undefined\n\t }\n\t| {\n\t\t\treadonly editor: Editor\n\t\t\treadonly source: 'clipboard-read'\n\t\t\treadonly clipboardItems: readonly ClipboardItem[]\n\t\t\treadonly point: VecLike | undefined\n\t }\n\n/**\n * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.\n *\n * @example\n * ```tsx\n * const options: Partial<TldrawOptions> = {\n * maxPages: 3,\n * maxShapesPerPage: 1000,\n * }\n *\n * function MyTldrawComponent() {\n * return <Tldraw options={options} />\n * }\n * ```\n *\n * @public\n */\nexport interface TldrawOptions {\n\treadonly maxShapesPerPage: number\n\treadonly maxFilesAtOnce: number\n\treadonly maxPages: number\n\treadonly animationMediumMs: number\n\treadonly followChaseViewportSnap: number\n\treadonly doubleClickDurationMs: number\n\treadonly multiClickDurationMs: number\n\treadonly coarseDragDistanceSquared: number\n\treadonly dragDistanceSquared: number\n\treadonly uiDragDistanceSquared: number\n\treadonly uiCoarseDragDistanceSquared: number\n\treadonly defaultSvgPadding: number\n\treadonly cameraSlideFriction: number\n\treadonly gridSteps: readonly {\n\t\treadonly min: number\n\t\treadonly mid: number\n\t\treadonly step: number\n\t}[]\n\treadonly collaboratorInactiveTimeoutMs: number\n\treadonly collaboratorIdleTimeoutMs: number\n\treadonly collaboratorCheckIntervalMs: number\n\treadonly cameraMovingTimeoutMs: number\n\treadonly hitTestMargin: number\n\treadonly coarseHitTestMargin: number\n\treadonly edgeScrollDelay: number\n\treadonly edgeScrollEaseDuration: number\n\treadonly edgeScrollSpeed: number\n\treadonly edgeScrollDistance: number\n\treadonly coarsePointerWidth: number\n\treadonly coarseHandleRadius: number\n\treadonly handleRadius: number\n\treadonly longPressDurationMs: number\n\treadonly textShadowLod: number\n\treadonly adjacentShapeMargin: number\n\treadonly flattenImageBoundsExpand: number\n\treadonly flattenImageBoundsPadding: number\n\treadonly laserDelayMs: number\n\t/**\n\t * How long (in milliseconds) to fade all laser scribbles after the session ends.\n\t * The total points across all scribbles will be removed proportionally over this duration.\n\t * Defaults to 500ms (0.5 seconds).\n\t */\n\treadonly laserFadeoutMs: number\n\treadonly maxExportDelayMs: number\n\treadonly tooltipDelayMs: number\n\t/**\n\t * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before\n\t * they expire? Defaults to 3 minutes.\n\t */\n\treadonly temporaryAssetPreviewLifetimeMs: number\n\treadonly actionShortcutsLocation: 'menu' | 'toolbar' | 'swap'\n\treadonly createTextOnCanvasDoubleClick: boolean\n\t/**\n\t * The react provider to use when exporting an image. This is useful if your shapes depend on\n\t * external context providers. By default, this is `React.Fragment`.\n\t */\n\treadonly exportProvider: ComponentType<{ children: React.ReactNode }>\n\t/**\n\t * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.\n\t */\n\treadonly enableToolbarKeyboardShortcuts: boolean\n\t/**\n\t * The maximum number of fonts that will be loaded while blocking the main rendering of the\n\t * canvas. If there are more than this number of fonts needed, we'll just show the canvas right\n\t * away and let the fonts load in in the background.\n\t */\n\treadonly maxFontsToLoadBeforeRender: number\n\t/**\n\t * If you have a CSP policy that blocks inline styles, you can use this prop to provide a\n\t * nonce to use in the editor's styles.\n\t */\n\treadonly nonce: string | undefined\n\t/**\n\t * Branding name of the app, currently only used for adding aria-label for the application.\n\t */\n\treadonly branding?: string\n\t/**\n\t * Whether to use debounced zoom level for certain rendering optimizations. When true,\n\t * `editor.getEfficientZoomLevel()` returns a cached zoom value while the camera is moving,\n\t * reducing re-renders. When false, it always returns the current zoom level.\n\t */\n\treadonly debouncedZoom: boolean\n\t/**\n\t * The number of shapes that must be on the page for the debounced zoom level to be used.\n\t * Defaults to 500 shapes.\n\t */\n\treadonly debouncedZoomThreshold: number\n\t/**\n\t * Whether to allow spacebar panning. When true, the spacebar will pan the camera when held down.\n\t * When false, the spacebar will not pan the camera.\n\t */\n\treadonly spacebarPanning: boolean\n\t/**\n\t * Whether to allow right-click + drag to pan the camera. When true, right-click + drag pans the\n\t * camera and a static right-click opens the context menu at the release position. When false,\n\t * right-click opens the context menu on press (no drag-to-pan).\n\t */\n\treadonly rightClickPanning: boolean\n\t/**\n\t * The default padding (in pixels) used when zooming to fit content in the viewport.\n\t * This affects methods like `zoomToFit()`, `zoomToSelection()`, and `zoomToBounds()`.\n\t * The actual padding used is the minimum of this value and 28% of the viewport width.\n\t * Defaults to 128 pixels.\n\t */\n\treadonly zoomToFitPadding: number\n\t/**\n\t * The distance (in screen pixels) at which shapes snap to guides and other shapes.\n\t */\n\treadonly snapThreshold: number\n\t/**\n\t * Whether locked shapes can be selected with a left click. When false (default), left-clicking\n\t * a locked shape is treated as a click on the canvas \u2014 only right-click selects it. When true,\n\t * locked shapes can be selected via left click and included in brush and scribble selections,\n\t * but the editor's lock guards still prevent moving, resizing, editing, or deleting them.\n\t */\n\treadonly selectLockedShapes: boolean\n\t/**\n\t * Options for the editor's camera. These are the initial camera options.\n\t * Use {@link Editor.setCameraOptions} to update camera options at runtime.\n\t */\n\treadonly camera: Partial<TLCameraOptions>\n\t/**\n\t * Options for the editor's text rendering. These include TipTap configuration and\n\t * font handling. These are the initial text options and cannot be changed at runtime.\n\t */\n\treadonly text: TLTextOptions\n\t/**\n\t * Options for syncing the editor's camera state with the URL. Set to `true` to enable\n\t * with default options, or pass an options object to customize behavior.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Enable with defaults\n\t * <Tldraw options={{ deepLinks: true }} />\n\t *\n\t * // Enable with custom options\n\t * <Tldraw options={{ deepLinks: { param: 'd', debounceMs: 500 } }} />\n\t * ```\n\t */\n\treadonly deepLinks: true | TLDeepLinkOptions | undefined\n\t/**\n\t * Whether the quick-zoom brush preserves its screen-pixel size when the user\n\t * zooms the overview. When true, zooming in shrinks the target viewport (higher\n\t * return zoom); zooming out expands it. When false, the brush keeps the original\n\t * viewport's page dimensions regardless of overview zoom changes.\n\t */\n\treadonly quickZoomPreservesScreenBounds: boolean\n\t/**\n\t * Called before content is written to the clipboard during a copy or cut operation.\n\t * Receives the serialized content (shapes, bindings, assets) and can filter or transform\n\t * it before it reaches the clipboard.\n\t *\n\t * Return a modified `TLContent` object to change what is copied or cut. Return `false` to\n\t * cancel the clipboard write (for cut, the selected shapes are not removed). Return `void`\n\t * (or `undefined`) to pass through unchanged. You may return a `Promise` of those values if\n\t * the hook is async.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Filter out \"locked\" shapes from copy\n\t * onBeforeCopyToClipboard({ content, operation }) {\n\t * return {\n\t * ...content,\n\t * shapes: content.shapes.filter(s => !s.meta.locked),\n\t * rootShapeIds: content.rootShapeIds.filter(id =>\n\t * content.shapes.find(s => s.id === id && !s.meta.locked)\n\t * ),\n\t * }\n\t * }\n\t * ```\n\t */\n\tonBeforeCopyToClipboard?(\n\t\tinfo: { editor: Editor; content: TLContent } & TLClipboardWriteInfo\n\t): Awaitable<TLContent | false | void>\n\t/**\n\t * Called before pasted content is processed and shapes are created. Receives the parsed\n\t * external content from the clipboard and can filter, transform, or cancel it.\n\t *\n\t * Return `false` to cancel the paste. Return a modified content object to transform it.\n\t * Return `void` (or `undefined`) to pass through unchanged. You may return a `Promise` of\n\t * those values if the hook is async.\n\t *\n\t * This only fires for clipboard paste operations (keyboard shortcuts and menu actions),\n\t * not for file drops or programmatic `putExternalContent` calls.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Block pasting of image files\n\t * onBeforePasteFromClipboard({ content }) {\n\t * if (content.type === 'files') {\n\t * const nonImages = content.files.filter(f => !f.type.startsWith('image/'))\n\t * if (nonImages.length === 0) return false\n\t * return { ...content, files: nonImages }\n\t * }\n\t * }\n\t * ```\n\t */\n\tonBeforePasteFromClipboard?(info: {\n\t\teditor: Editor\n\t\tcontent: TLExternalContent<unknown>\n\t\tsource: 'native-event' | 'clipboard-read'\n\t\tpoint?: VecLike\n\t}): Awaitable<TLExternalContent<unknown> | false | void>\n\t/**\n\t * Called first for keyboard and menu paste, **before** tldraw handles or parses clipboard data\n\t * (and before {@link TldrawOptions.onBeforePasteFromClipboard}).\n\t *\n\t * Return `false` to cancel tldraw's default paste handling for this gesture (same convention as\n\t * {@link TldrawOptions.onBeforePasteFromClipboard}). Use this when you handle paste yourself from\n\t * raw clipboard data, or to block the gesture entirely. Return `void` (or `undefined`) to continue.\n\t */\n\tonClipboardPasteRaw?(info: TLClipboardPasteRawInfo): false | void\n\t/**\n\t * Called when content is dropped on the canvas. Provides the page position\n\t * where the drop occurred and the underlying drag event object.\n\t * Return true to prevent default drop handling (files, URLs, etc.)\n\t */\n\texperimental__onDropOnCanvas?(options: {\n\t\tpoint: VecLike\n\t\tevent: React.DragEvent<Element>\n\t}): boolean\n}\n\n/** @public */\nexport const defaultTldrawOptions = {\n\tmaxShapesPerPage: 4000,\n\tmaxFilesAtOnce: 100,\n\tmaxPages: 40,\n\tanimationMediumMs: 320,\n\tfollowChaseViewportSnap: 2,\n\tdoubleClickDurationMs: 450,\n\tmultiClickDurationMs: 200,\n\tcoarseDragDistanceSquared: 36, // 6 squared\n\tdragDistanceSquared: 16, // 4 squared\n\tuiDragDistanceSquared: 16, // 4 squared\n\t// it's really easy to accidentally drag from the toolbar on mobile, so we use a much larger\n\t// threshold than usual here to try and prevent accidental drags.\n\tuiCoarseDragDistanceSquared: 625, // 25 squared\n\tdefaultSvgPadding: 32,\n\tcameraSlideFriction: 0.09,\n\tgridSteps: [\n\t\t{ min: -1, mid: 0.15, step: 64 },\n\t\t{ min: 0.05, mid: 0.375, step: 16 },\n\t\t{ min: 0.15, mid: 1, step: 4 },\n\t\t{ min: 0.7, mid: 2.5, step: 1 },\n\t],\n\tcollaboratorInactiveTimeoutMs: 60000,\n\tcollaboratorIdleTimeoutMs: 3000,\n\tcollaboratorCheckIntervalMs: 1200,\n\tcameraMovingTimeoutMs: 64,\n\thitTestMargin: 3,\n\tcoarseHitTestMargin: 4,\n\tedgeScrollDelay: 200,\n\tedgeScrollEaseDuration: 200,\n\tedgeScrollSpeed: 25,\n\tedgeScrollDistance: 8,\n\tcoarsePointerWidth: 12,\n\tcoarseHandleRadius: 20,\n\thandleRadius: 12,\n\tlongPressDurationMs: 500,\n\ttextShadowLod: 0.35,\n\tadjacentShapeMargin: 10,\n\tflattenImageBoundsExpand: 64,\n\tflattenImageBoundsPadding: 16,\n\tlaserDelayMs: 1200,\n\tlaserFadeoutMs: 500,\n\tmaxExportDelayMs: 5000,\n\ttooltipDelayMs: 700,\n\ttemporaryAssetPreviewLifetimeMs: 180000,\n\tactionShortcutsLocation: 'swap',\n\tcreateTextOnCanvasDoubleClick: true,\n\texportProvider: Fragment,\n\tenableToolbarKeyboardShortcuts: true,\n\tmaxFontsToLoadBeforeRender: Infinity,\n\tnonce: undefined,\n\tdebouncedZoom: true,\n\tdebouncedZoomThreshold: 500,\n\tspacebarPanning: true,\n\trightClickPanning: true,\n\tzoomToFitPadding: 128,\n\tsnapThreshold: 8,\n\tselectLockedShapes: false,\n\tcamera: DEFAULT_CAMERA_OPTIONS,\n\ttext: {},\n\tdeepLinks: undefined,\n\tquickZoomPreservesScreenBounds: true,\n\tonBeforeCopyToClipboard: undefined,\n\tonBeforePasteFromClipboard: undefined,\n\tonClipboardPasteRaw: undefined,\n\texperimental__onDropOnCanvas: undefined,\n} as const satisfies TldrawOptions\n"],
|
|
5
|
+
"mappings": "AACA,SAAwB,gBAAgB;AACxC,SAAS,8BAA8B;AA+RhC,MAAM,uBAAuB;AAAA,EACnC,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EACzB,uBAAuB;AAAA,EACvB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA;AAAA,EAC3B,qBAAqB;AAAA;AAAA,EACrB,uBAAuB;AAAA;AAAA;AAAA;AAAA,EAGvB,6BAA6B;AAAA;AAAA,EAC7B,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,WAAW;AAAA,IACV,EAAE,KAAK,IAAI,KAAK,MAAM,MAAM,GAAG;AAAA,IAC/B,EAAE,KAAK,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,IAClC,EAAE,KAAK,MAAM,KAAK,GAAG,MAAM,EAAE;AAAA,IAC7B,EAAE,KAAK,KAAK,KAAK,KAAK,MAAM,EAAE;AAAA,EAC/B;AAAA,EACA,+BAA+B;AAAA,EAC/B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,qBAAqB;AAAA,EACrB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,0BAA0B;AAAA,EAC1B,2BAA2B;AAAA,EAC3B,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,iCAAiC;AAAA,EACjC,yBAAyB;AAAA,EACzB,+BAA+B;AAAA,EAC/B,gBAAgB;AAAA,EAChB,gCAAgC;AAAA,EAChC,4BAA4B;AAAA,EAC5B,OAAO;AAAA,EACP,eAAe;AAAA,EACf,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,QAAQ;AAAA,EACR,MAAM,CAAC;AAAA,EACP,WAAW;AAAA,EACX,gCAAgC;AAAA,EAChC,yBAAyB;AAAA,EACzB,4BAA4B;AAAA,EAC5B,qBAAqB;AAAA,EACrB,8BAA8B;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/version.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const version = "5.3.0-
|
|
1
|
+
const version = "5.3.0-internal.fba91ed55f6c";
|
|
2
2
|
const publishDates = {
|
|
3
3
|
major: "2026-05-06T16:28:18.473Z",
|
|
4
|
-
minor: "2026-07-
|
|
5
|
-
patch: "2026-07-
|
|
4
|
+
minor: "2026-07-17T10:57:42.512Z",
|
|
5
|
+
patch: "2026-07-17T10:57:42.512Z"
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
8
|
publishDates,
|
package/dist-esm/version.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.3.0-
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.3.0-internal.fba91ed55f6c'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-07-17T10:57:42.512Z',\n\tpatch: '2026-07-17T10:57:42.512Z',\n}\n"],
|
|
5
5
|
"mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/editor.css
CHANGED
|
@@ -785,6 +785,16 @@ input,
|
|
|
785
785
|
.tl-rich-text h6 {
|
|
786
786
|
margin-top: 5px;
|
|
787
787
|
margin-bottom: 10px;
|
|
788
|
+
/**
|
|
789
|
+
* Headings render at a larger font-size than the body text (via the browser's
|
|
790
|
+
* default h1–h6 sizing), so they can't inherit the container's resolved
|
|
791
|
+
* whole-pixel line-height — that value is derived from the base font size and
|
|
792
|
+
* would cram the taller lines together. Instead, scale line-height with each
|
|
793
|
+
* heading's own font-size using tldraw's unitless line-height multiplier, which
|
|
794
|
+
* the rich-text render/measure paths expose here. The 1.35 fallback mirrors the
|
|
795
|
+
* default theme line-height (see defaultThemes.ts).
|
|
796
|
+
*/
|
|
797
|
+
line-height: var(--tl-rich-text-heading-line-height, 1.35);
|
|
788
798
|
}
|
|
789
799
|
|
|
790
800
|
.tl-rich-text a {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "tldraw infinite canvas SDK (editor).",
|
|
4
|
-
"version": "5.3.0-
|
|
4
|
+
"version": "5.3.0-internal.fba91ed55f6c",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"@tiptap/core": "^3.12.1",
|
|
50
50
|
"@tiptap/pm": "^3.12.1",
|
|
51
51
|
"@tiptap/react": "^3.12.1",
|
|
52
|
-
"@tldraw/state": "5.3.0-
|
|
53
|
-
"@tldraw/state-react": "5.3.0-
|
|
54
|
-
"@tldraw/store": "5.3.0-
|
|
55
|
-
"@tldraw/tlschema": "5.3.0-
|
|
56
|
-
"@tldraw/utils": "5.3.0-
|
|
57
|
-
"@tldraw/validate": "5.3.0-
|
|
52
|
+
"@tldraw/state": "5.3.0-internal.fba91ed55f6c",
|
|
53
|
+
"@tldraw/state-react": "5.3.0-internal.fba91ed55f6c",
|
|
54
|
+
"@tldraw/store": "5.3.0-internal.fba91ed55f6c",
|
|
55
|
+
"@tldraw/tlschema": "5.3.0-internal.fba91ed55f6c",
|
|
56
|
+
"@tldraw/utils": "5.3.0-internal.fba91ed55f6c",
|
|
57
|
+
"@tldraw/validate": "5.3.0-internal.fba91ed55f6c",
|
|
58
58
|
"classnames": "^2.5.1",
|
|
59
59
|
"eventemitter3": "^4.0.7",
|
|
60
60
|
"idb": "^7.1.1",
|
package/src/index.ts
CHANGED
|
@@ -324,12 +324,14 @@ export {
|
|
|
324
324
|
LicenseManager,
|
|
325
325
|
type InvalidLicenseKeyResult,
|
|
326
326
|
type InvalidLicenseReason,
|
|
327
|
+
type LicenseFeatureName,
|
|
327
328
|
type LicenseFromKeyResult,
|
|
328
329
|
type LicenseInfo,
|
|
329
330
|
type LicenseState,
|
|
330
331
|
type ValidLicenseKeyResult,
|
|
331
332
|
} from './lib/license/LicenseManager'
|
|
332
|
-
export { LICENSE_TIMEOUT } from './lib/license/LicenseProvider'
|
|
333
|
+
export { LICENSE_TIMEOUT, useLicenseContext } from './lib/license/LicenseProvider'
|
|
334
|
+
export { useLicenseFeatureFlag } from './lib/license/useLicenseManagerState'
|
|
333
335
|
export {
|
|
334
336
|
defaultTldrawOptions,
|
|
335
337
|
type TLClipboardPasteRawInfo,
|
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -801,7 +801,16 @@ export function useOnMount(onMount?: TLOnMountHandler) {
|
|
|
801
801
|
{ history: 'ignore' }
|
|
802
802
|
)
|
|
803
803
|
window.tldrawReady = true
|
|
804
|
-
return
|
|
804
|
+
return () => {
|
|
805
|
+
teardown?.()
|
|
806
|
+
// The editor's component can unmount without the editor being disposed (for example when
|
|
807
|
+
// the canvas is swapped for an error fallback), so emit `unmount` here rather than relying
|
|
808
|
+
// on disposal. If the editor is being disposed, `dispose()` emits `unmount` itself, so we
|
|
809
|
+
// only emit here when it's still mounted and alive.
|
|
810
|
+
if (editor.getIsMounted() && !editor.isDisposed) {
|
|
811
|
+
editor.run(() => editor.emit('unmount'), { history: 'ignore' })
|
|
812
|
+
}
|
|
813
|
+
}
|
|
805
814
|
})
|
|
806
815
|
|
|
807
816
|
React.useLayoutEffect(() => {
|
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -563,16 +563,34 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
563
563
|
let deletedBindings = new Map<TLBindingId, BindingOnDeleteOptions<any>>()
|
|
564
564
|
const deletedShapeIds = new Set<TLShapeId>()
|
|
565
565
|
const invalidParents = new Set<TLShapeId>()
|
|
566
|
+
const createdShapes = new Set<TLShapeId>()
|
|
566
567
|
let invalidBindingTypes = new Set<TLBinding['type']>()
|
|
567
568
|
|
|
568
569
|
this.disposables.add(
|
|
569
570
|
this.sideEffects.registerOperationCompleteHandler(() => {
|
|
570
571
|
// this needs to be cleared here because further effects may delete more shapes
|
|
571
572
|
// and we want the next invocation of this handler to handle those separately
|
|
573
|
+
const deletedIds = deletedShapeIds.size ? new Set(deletedShapeIds) : null
|
|
572
574
|
deletedShapeIds.clear()
|
|
573
575
|
|
|
576
|
+
if (deletedIds) {
|
|
577
|
+
const updates = compact(
|
|
578
|
+
this.getPageStates().map((pageState) => {
|
|
579
|
+
return cleanupInstancePageState(pageState, deletedIds)
|
|
580
|
+
})
|
|
581
|
+
)
|
|
582
|
+
|
|
583
|
+
if (updates.length) {
|
|
584
|
+
this.store.put(updates)
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const justCreatedShapeIds = new Set(createdShapes)
|
|
589
|
+
createdShapes.clear()
|
|
590
|
+
|
|
574
591
|
for (const parentId of invalidParents) {
|
|
575
592
|
invalidParents.delete(parentId)
|
|
593
|
+
if (justCreatedShapeIds.has(parentId)) continue
|
|
576
594
|
const parent = this.getShape(parentId)
|
|
577
595
|
if (!parent) continue
|
|
578
596
|
|
|
@@ -608,6 +626,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
608
626
|
this.disposables.add(
|
|
609
627
|
this.sideEffects.register({
|
|
610
628
|
shape: {
|
|
629
|
+
afterCreate: (shape) => {
|
|
630
|
+
createdShapes.add(shape.id)
|
|
631
|
+
if (shape.parentId && isShapeId(shape.parentId)) {
|
|
632
|
+
invalidParents.add(shape.parentId)
|
|
633
|
+
}
|
|
634
|
+
},
|
|
611
635
|
afterChange: (shapeBefore, shapeAfter) => {
|
|
612
636
|
for (const binding of this.getBindingsInvolvingShape(shapeAfter)) {
|
|
613
637
|
invalidBindingTypes.add(binding.type)
|
|
@@ -712,17 +736,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
712
736
|
if (deleteBindingIds.length) {
|
|
713
737
|
this.deleteBindings(deleteBindingIds)
|
|
714
738
|
}
|
|
715
|
-
|
|
716
|
-
const deletedIds = new Set([shape.id])
|
|
717
|
-
const updates = compact(
|
|
718
|
-
this.getPageStates().map((pageState) => {
|
|
719
|
-
return cleanupInstancePageState(pageState, deletedIds)
|
|
720
|
-
})
|
|
721
|
-
)
|
|
722
|
-
|
|
723
|
-
if (updates.length) {
|
|
724
|
-
this.store.put(updates)
|
|
725
|
-
}
|
|
726
739
|
},
|
|
727
740
|
},
|
|
728
741
|
binding: {
|
|
@@ -809,6 +822,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
809
822
|
},
|
|
810
823
|
instance_page_state: {
|
|
811
824
|
afterChange: (prev, next) => {
|
|
825
|
+
if (prev?.focusedGroupId !== next?.focusedGroupId) {
|
|
826
|
+
this.cancelDoubleClick()
|
|
827
|
+
}
|
|
828
|
+
|
|
812
829
|
if (prev?.selectedShapeIds !== next?.selectedShapeIds) {
|
|
813
830
|
// ensure that descendants and ancestors are not selected at the same time
|
|
814
831
|
const filtered = next.selectedShapeIds.filter((id) => {
|
|
@@ -899,6 +916,14 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
899
916
|
|
|
900
917
|
this.on('tick', this._flushEventsForTick)
|
|
901
918
|
|
|
919
|
+
this.on('mount', () => {
|
|
920
|
+
this._isMounted.set(true)
|
|
921
|
+
})
|
|
922
|
+
|
|
923
|
+
this.on('unmount', () => {
|
|
924
|
+
this._isMounted.set(false)
|
|
925
|
+
})
|
|
926
|
+
|
|
902
927
|
this.timers.requestAnimationFrame(() => {
|
|
903
928
|
this._tickManager.start()
|
|
904
929
|
})
|
|
@@ -1011,6 +1036,23 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1011
1036
|
*/
|
|
1012
1037
|
isDisposed = false
|
|
1013
1038
|
|
|
1039
|
+
private readonly _isMounted = atom('isMounted', false)
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Whether the editor is currently mounted. This is `true` while the editor's component is
|
|
1043
|
+
* mounted in the DOM (after the `mount` event) and `false` before mount and after `unmount`.
|
|
1044
|
+
*
|
|
1045
|
+
* Unlike disposal, mounting is not terminal: the editor's component can unmount and remount
|
|
1046
|
+
* (for example when the canvas is replaced by an error fallback and restored) without the
|
|
1047
|
+
* editor itself being disposed. To react to the transitions, listen to the editor's `mount`
|
|
1048
|
+
* and `unmount` events.
|
|
1049
|
+
*
|
|
1050
|
+
* @public
|
|
1051
|
+
*/
|
|
1052
|
+
@computed getIsMounted(): boolean {
|
|
1053
|
+
return this._isMounted.get()
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1014
1056
|
/**
|
|
1015
1057
|
* A manager for the editor's tick events.
|
|
1016
1058
|
*
|
|
@@ -1161,6 +1203,13 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1161
1203
|
* @public
|
|
1162
1204
|
*/
|
|
1163
1205
|
dispose() {
|
|
1206
|
+
// If the editor is disposed while still mounted (for example when its component tree is
|
|
1207
|
+
// unmounted all at once), emit `unmount` first — while listeners are still attached — so
|
|
1208
|
+
// that `mount` is always balanced by an `unmount` and `getIsMounted()` reads `false`.
|
|
1209
|
+
if (this._isMounted.get()) {
|
|
1210
|
+
this.emit('unmount')
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1164
1213
|
// Stop any in-progress camera animations and following before
|
|
1165
1214
|
// running disposables, so their cleanup listeners fire first
|
|
1166
1215
|
this.stopCameraAnimation()
|
|
@@ -5785,6 +5834,22 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5785
5834
|
return commonBounds
|
|
5786
5835
|
}
|
|
5787
5836
|
|
|
5837
|
+
/**
|
|
5838
|
+
* Get the hit-test margin in page space—the distance in page units within which a pointer is
|
|
5839
|
+
* considered to be touching a shape. This resolves to {@link TldrawOptions.hitTestMargin} (or
|
|
5840
|
+
* {@link TldrawOptions.coarseHitTestMargin} when using a coarse pointer) divided by the current
|
|
5841
|
+
* zoom level, so it stays a constant distance in screen space.
|
|
5842
|
+
*
|
|
5843
|
+
* @returns The hit-test margin in page space.
|
|
5844
|
+
*
|
|
5845
|
+
* @public
|
|
5846
|
+
*/
|
|
5847
|
+
@computed getHitTestMargin(): number {
|
|
5848
|
+
const { hitTestMargin, coarseHitTestMargin } = this.options
|
|
5849
|
+
const margin = this.getInstanceState().isCoarsePointer ? coarseHitTestMargin : hitTestMargin
|
|
5850
|
+
return margin / this.getZoomLevel()
|
|
5851
|
+
}
|
|
5852
|
+
|
|
5788
5853
|
/**
|
|
5789
5854
|
* Get the top-most selected shape at the given point, ignoring groups.
|
|
5790
5855
|
*
|
|
@@ -5794,10 +5859,25 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5794
5859
|
*/
|
|
5795
5860
|
getSelectedShapeAtPoint(point: VecLike): TLShape | undefined {
|
|
5796
5861
|
const selectedShapeIds = this.getSelectedShapeIds()
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5862
|
+
const margin = this.options.hitTestMargin / this.getZoomLevel()
|
|
5863
|
+
const sortedShapes = this.getCurrentPageShapesSorted()
|
|
5864
|
+
|
|
5865
|
+
for (let i = sortedShapes.length - 1; i >= 0; i--) {
|
|
5866
|
+
const shape = sortedShapes[i]
|
|
5867
|
+
if (shape.type === 'group') continue
|
|
5868
|
+
if (!selectedShapeIds.includes(shape.id)) continue
|
|
5869
|
+
if (
|
|
5870
|
+
this.getShapeGeometry(shape).hitTestPoint(
|
|
5871
|
+
this.getPointInShapeSpace(shape, point),
|
|
5872
|
+
margin,
|
|
5873
|
+
true
|
|
5874
|
+
)
|
|
5875
|
+
) {
|
|
5876
|
+
return shape
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5879
|
+
|
|
5880
|
+
return undefined
|
|
5801
5881
|
}
|
|
5802
5882
|
|
|
5803
5883
|
/**
|
|
@@ -5809,7 +5889,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5809
5889
|
* @returns The shape at the given point, or undefined if there is no shape at the point.
|
|
5810
5890
|
*/
|
|
5811
5891
|
getShapeAtPoint(point: VecLike, opts: TLGetShapeAtPointOptions = {}): TLShape | undefined {
|
|
5812
|
-
const zoomLevel = this.getZoomLevel()
|
|
5813
5892
|
const viewportPageBounds = this.getViewportPageBounds()
|
|
5814
5893
|
const {
|
|
5815
5894
|
filter,
|
|
@@ -5829,7 +5908,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5829
5908
|
let inMarginClosestToEdgeHit: TLShape | null = null
|
|
5830
5909
|
|
|
5831
5910
|
// Use larger margin for spatial search to account for edge distance checks
|
|
5832
|
-
const searchMargin = Math.max(innerMargin, outerMargin, this.
|
|
5911
|
+
const searchMargin = Math.max(innerMargin, outerMargin, this.getHitTestMargin())
|
|
5833
5912
|
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, searchMargin)
|
|
5834
5913
|
|
|
5835
5914
|
const shapesToCheck = (
|
|
@@ -5998,7 +6077,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5998
6077
|
// For open shapes (e.g. lines or draw shapes) always use the margin.
|
|
5999
6078
|
// If the distance is less than the margin, return the shape as the hit.
|
|
6000
6079
|
// Use the editor's configurable hit test margin.
|
|
6001
|
-
if (distance < this.
|
|
6080
|
+
if (distance < this.getHitTestMargin()) {
|
|
6002
6081
|
return shape
|
|
6003
6082
|
}
|
|
6004
6083
|
}
|
|
@@ -142,6 +142,72 @@ describe('FontManager', () => {
|
|
|
142
142
|
|
|
143
143
|
await secondPromise
|
|
144
144
|
})
|
|
145
|
+
|
|
146
|
+
it('ignores font load failures after disposal', async () => {
|
|
147
|
+
const font = createMockFont()
|
|
148
|
+
const error = new Error('Font load failed')
|
|
149
|
+
let rejectLoad: (err: Error) => void = () => {}
|
|
150
|
+
;(global.FontFace as Mock).mockImplementationOnce(function (family, src, descriptors) {
|
|
151
|
+
return {
|
|
152
|
+
family,
|
|
153
|
+
src,
|
|
154
|
+
...descriptors,
|
|
155
|
+
load: vi.fn(
|
|
156
|
+
() =>
|
|
157
|
+
new Promise<void>((_, reject) => {
|
|
158
|
+
rejectLoad = reject
|
|
159
|
+
})
|
|
160
|
+
),
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
164
|
+
const debugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {})
|
|
165
|
+
|
|
166
|
+
const promise = fontManager.ensureFontIsLoaded(font)
|
|
167
|
+
fontManager.dispose()
|
|
168
|
+
rejectLoad(error)
|
|
169
|
+
|
|
170
|
+
await expect(promise).resolves.toBeUndefined()
|
|
171
|
+
expect(errorSpy).not.toHaveBeenCalled()
|
|
172
|
+
expect(debugSpy).toHaveBeenCalledWith(
|
|
173
|
+
`Font "${font.family}" load interrupted by editor dispose`,
|
|
174
|
+
error
|
|
175
|
+
)
|
|
176
|
+
errorSpy.mockRestore()
|
|
177
|
+
debugSpy.mockRestore()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('ignores font loads that finish after disposal', async () => {
|
|
181
|
+
const font = createMockFont()
|
|
182
|
+
let resolveLoad: () => void = () => {}
|
|
183
|
+
;(global.FontFace as Mock).mockImplementationOnce(function (family, src, descriptors) {
|
|
184
|
+
return {
|
|
185
|
+
family,
|
|
186
|
+
src,
|
|
187
|
+
...descriptors,
|
|
188
|
+
load: vi.fn(
|
|
189
|
+
() =>
|
|
190
|
+
new Promise<void>((resolve) => {
|
|
191
|
+
resolveLoad = resolve
|
|
192
|
+
})
|
|
193
|
+
),
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
const debugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {})
|
|
197
|
+
|
|
198
|
+
const promise = fontManager.ensureFontIsLoaded(font)
|
|
199
|
+
fontManager.dispose()
|
|
200
|
+
resolveLoad()
|
|
201
|
+
|
|
202
|
+
await expect(promise).resolves.toBeUndefined()
|
|
203
|
+
// only the creation-time add from findOrCreateFontFace, not a second
|
|
204
|
+
// post-load add after dispose
|
|
205
|
+
expect(document.fonts.add).toHaveBeenCalledTimes(1)
|
|
206
|
+
expect(debugSpy).toHaveBeenCalledWith(
|
|
207
|
+
`Font "${font.family}" load interrupted by editor dispose`
|
|
208
|
+
)
|
|
209
|
+
debugSpy.mockRestore()
|
|
210
|
+
})
|
|
145
211
|
})
|
|
146
212
|
|
|
147
213
|
describe('getShapeFontFaces', () => {
|
|
@@ -106,16 +106,30 @@ export class FontManager {
|
|
|
106
106
|
if (existingState) return existingState.loadingPromise
|
|
107
107
|
|
|
108
108
|
const instance = this.findOrCreateFontFace(font)
|
|
109
|
+
// dispose() clears fontStates while loads may still be in flight, so a late
|
|
110
|
+
// callback must only touch the exact entry it was created for - not a fresh
|
|
111
|
+
// entry from a later request. Check identity, not just presence.
|
|
112
|
+
const isStale = () => this.fontStates.__unsafe__getWithoutCapture(font) !== state
|
|
109
113
|
const state: FontState = {
|
|
110
114
|
state: 'loading',
|
|
111
115
|
instance,
|
|
112
116
|
loadingPromise: instance
|
|
113
117
|
.load()
|
|
114
118
|
.then(() => {
|
|
119
|
+
if (isStale()) {
|
|
120
|
+
// eslint-disable-next-line no-console
|
|
121
|
+
console.debug(`Font "${font.family}" load interrupted by editor dispose`)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
115
124
|
this.editor.getContainerDocument().fonts.add(instance)
|
|
116
125
|
this.fontStates.update(font, (s) => ({ ...s, state: 'ready' }))
|
|
117
126
|
})
|
|
118
127
|
.catch((err) => {
|
|
128
|
+
if (isStale()) {
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
console.debug(`Font "${font.family}" load interrupted by editor dispose`, err)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
119
133
|
console.error(err)
|
|
120
134
|
this.fontStates.update(font, (s) => ({ ...s, state: 'error' }))
|
|
121
135
|
}),
|
|
@@ -183,6 +183,9 @@ export class TextManager extends EditorManager {
|
|
|
183
183
|
'font-weight': opts.fontWeight,
|
|
184
184
|
'font-size': opts.fontSize + 'px',
|
|
185
185
|
'line-height': `${resolveLineHeightPx(opts.fontSize, opts.lineHeight)}px`,
|
|
186
|
+
// Unitless multiplier consumed by the .tl-rich-text h1–h6 rule (see editor.css),
|
|
187
|
+
// so heading measurement matches on-canvas rendering.
|
|
188
|
+
'--tl-rich-text-heading-line-height': `${opts.lineHeight}`,
|
|
186
189
|
padding: opts.padding,
|
|
187
190
|
'max-width': opts.maxWidth ? opts.maxWidth + 'px' : undefined,
|
|
188
191
|
'min-width': opts.minWidth ? opts.minWidth + 'px' : undefined,
|
|
@@ -5,7 +5,7 @@ import { BaseBoxShapeUtil, TLBaseBoxShape } from './BaseBoxShapeUtil'
|
|
|
5
5
|
import { TLDragShapesInInfo, TLDragShapesOutInfo } from './ShapeUtil'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A base class for frame-like shapes — containers that clip their children,
|
|
8
|
+
* A base class for frame-like shapes — containers that clip their children except arrows,
|
|
9
9
|
* require full-brush selection, block erasure from inside, and support
|
|
10
10
|
* drag-and-drop reparenting.
|
|
11
11
|
*
|
|
@@ -17,6 +17,7 @@ import { TLDragShapesInInfo, TLDragShapesOutInfo } from './ShapeUtil'
|
|
|
17
17
|
* - `canReceiveNewChildrenOfType()` returns `true` unless the container is locked
|
|
18
18
|
* - `canRemoveChildrenOfType()` returns `true` unless the container is locked
|
|
19
19
|
* - `getClipPath()` returns the shape geometry's vertices
|
|
20
|
+
* - `shouldClipChild()` clips all children except arrows
|
|
20
21
|
* - `onDragShapesIn()` reparents shapes into the frame (with index restoration)
|
|
21
22
|
* - `onDragShapesOut()` reparents shapes back to the page
|
|
22
23
|
*
|
|
@@ -69,6 +70,10 @@ export abstract class BaseFrameLikeShapeUtil<
|
|
|
69
70
|
return this.editor.getShapeGeometry(shape.id).vertices
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
override shouldClipChild(child: TLShape): boolean {
|
|
74
|
+
return child.type !== 'arrow'
|
|
75
|
+
}
|
|
76
|
+
|
|
72
77
|
override onDragShapesIn(
|
|
73
78
|
shape: Shape,
|
|
74
79
|
draggingShapes: TLShape[],
|