@tldraw/editor 4.4.0-canary.afdcafe834b3 → 4.4.0-canary.b56b70f6a630
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 +127 -26
- package/dist-cjs/index.js +4 -7
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +20 -8
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/ErrorBoundary.js.map +1 -1
- package/dist-cjs/lib/components/Shape.js +12 -17
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +26 -1
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +31 -16
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +5 -6
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultLoadingScreen.js +2 -2
- package/dist-cjs/lib/components/default-components/DefaultLoadingScreen.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +44 -15
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +1 -1
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +1 -1
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +32 -13
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +2 -3
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +1 -1
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/resizeBox.js.map +1 -1
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +1 -1
- package/dist-cjs/lib/editor/types/SvgExportContext.js.map +1 -1
- package/dist-cjs/lib/exports/exportToSvg.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js.map +1 -1
- package/dist-cjs/lib/{utils/hardResetEditor.js → hooks/EditorComponentsContext.js} +14 -8
- package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +7 -0
- package/dist-cjs/lib/hooks/useCanvasEvents.js +10 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditor.js.map +1 -1
- package/dist-cjs/lib/hooks/useEditorComponents.js +4 -10
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +3 -3
- package/dist-cjs/lib/hooks/usePeerIds.js +8 -2
- package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
- package/dist-cjs/lib/hooks/useShapeCulling.js +75 -0
- package/dist-cjs/lib/hooks/useShapeCulling.js.map +7 -0
- package/dist-cjs/lib/license/LicenseManager.js +6 -6
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/options.js +7 -1
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +10 -5
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/utils/areShapesContentEqual.js +3 -1
- package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
- package/dist-cjs/lib/utils/assets.js +4 -6
- package/dist-cjs/lib/utils/assets.js.map +2 -2
- package/dist-cjs/lib/utils/browserCanvasMaxSize.js +1 -2
- package/dist-cjs/lib/utils/browserCanvasMaxSize.js.map +2 -2
- package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
- package/dist-cjs/lib/utils/deepLinks.js.map +1 -1
- package/dist-cjs/lib/utils/dom.js +3 -3
- package/dist-cjs/lib/utils/dom.js.map +2 -2
- package/dist-cjs/lib/utils/getIncrementedName.js +1 -1
- package/dist-cjs/lib/utils/getIncrementedName.js.map +2 -2
- package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
- package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +1 -1
- package/dist-cjs/lib/utils/keyboard.js +2 -2
- package/dist-cjs/lib/utils/keyboard.js.map +2 -2
- package/dist-cjs/lib/utils/normalizeWheel.js +2 -5
- package/dist-cjs/lib/utils/normalizeWheel.js.map +2 -2
- package/dist-cjs/lib/utils/reorderShapes.js +6 -6
- package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +3 -4
- package/dist-cjs/lib/utils/reparenting.js.map +2 -2
- package/dist-cjs/lib/utils/richText.js.map +1 -1
- package/dist-cjs/lib/utils/rotation.js.map +1 -1
- package/dist-cjs/lib/utils/runtime.js +12 -0
- package/dist-cjs/lib/utils/runtime.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 +127 -26
- package/dist-esm/index.mjs +8 -5
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +20 -8
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/ErrorBoundary.mjs.map +1 -1
- package/dist-esm/lib/components/Shape.mjs +12 -17
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +27 -2
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +17 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +2 -3
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultLoadingScreen.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultLoadingScreen.mjs.map +1 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +44 -15
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +1 -1
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +32 -13
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +2 -3
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs.map +1 -1
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +1 -1
- package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +1 -1
- package/dist-esm/lib/exports/exportToSvg.mjs.map +1 -1
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +1 -1
- package/dist-esm/lib/hooks/EditorComponentsContext.mjs +14 -0
- package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +7 -0
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +10 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditor.mjs.map +1 -1
- package/dist-esm/lib/hooks/useEditorComponents.mjs +12 -36
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs +8 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
- package/dist-esm/lib/hooks/useShapeCulling.mjs +55 -0
- package/dist-esm/lib/hooks/useShapeCulling.mjs.map +7 -0
- package/dist-esm/lib/license/LicenseManager.mjs +6 -6
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +7 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +6 -1
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/utils/areShapesContentEqual.mjs +3 -1
- package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
- package/dist-esm/lib/utils/assets.mjs +4 -6
- package/dist-esm/lib/utils/assets.mjs.map +2 -2
- package/dist-esm/lib/utils/browserCanvasMaxSize.mjs +1 -2
- package/dist-esm/lib/utils/browserCanvasMaxSize.mjs.map +2 -2
- package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
- package/dist-esm/lib/utils/deepLinks.mjs.map +1 -1
- package/dist-esm/lib/utils/dom.mjs +3 -3
- package/dist-esm/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/lib/utils/getIncrementedName.mjs +1 -1
- package/dist-esm/lib/utils/getIncrementedName.mjs.map +2 -2
- package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
- package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +1 -1
- package/dist-esm/lib/utils/keyboard.mjs +2 -2
- package/dist-esm/lib/utils/keyboard.mjs.map +2 -2
- package/dist-esm/lib/utils/normalizeWheel.mjs +2 -5
- package/dist-esm/lib/utils/normalizeWheel.mjs.map +2 -2
- package/dist-esm/lib/utils/reorderShapes.mjs +6 -6
- package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +3 -4
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/lib/utils/richText.mjs.map +1 -1
- package/dist-esm/lib/utils/rotation.mjs.map +1 -1
- package/dist-esm/lib/utils/runtime.mjs +12 -0
- package/dist-esm/lib/utils/runtime.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +22 -2
- package/package.json +10 -11
- package/src/index.ts +7 -4
- package/src/lib/TldrawEditor.tsx +34 -12
- package/src/lib/components/ErrorBoundary.tsx +1 -1
- package/src/lib/components/Shape.tsx +15 -16
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +46 -2
- package/src/lib/components/default-components/DefaultCanvas.tsx +25 -3
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +2 -3
- package/src/lib/components/default-components/DefaultLoadingScreen.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicators.tsx +1 -1
- package/src/lib/editor/Editor.ts +74 -16
- package/src/lib/editor/bindings/BindingUtil.ts +1 -1
- package/src/lib/editor/derivations/bindingsIndex.ts +1 -1
- package/src/lib/editor/derivations/notVisibleShapes.ts +40 -18
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +0 -35
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +5 -9
- package/src/lib/editor/managers/FontManager/FontManager.ts +1 -1
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +1 -1
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +1 -1
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +2 -2
- package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +2 -2
- package/src/lib/editor/managers/TextManager/TextManager.ts +1 -1
- package/src/lib/editor/managers/TickManager/TickManager.ts +1 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +19 -5
- package/src/lib/editor/shapes/shared/resizeBox.ts +1 -1
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +2 -2
- package/src/lib/editor/types/SvgExportContext.tsx +1 -1
- package/src/lib/exports/exportToSvg.tsx +1 -1
- package/src/lib/exports/getSvgJsx.tsx +1 -1
- package/src/lib/hooks/EditorComponentsContext.tsx +63 -0
- package/src/lib/hooks/useCanvasEvents.ts +13 -2
- package/src/lib/hooks/useEditor.tsx +1 -1
- package/src/lib/hooks/useEditorComponents.tsx +20 -89
- package/src/lib/hooks/usePeerIds.ts +9 -2
- package/src/lib/hooks/useShapeCulling.tsx +98 -0
- package/src/lib/license/LicenseManager.ts +6 -6
- package/src/lib/options.ts +52 -2
- package/src/lib/primitives/Vec.ts +7 -1
- package/src/lib/utils/areShapesContentEqual.ts +9 -2
- package/src/lib/utils/assets.ts +15 -10
- package/src/lib/utils/browserCanvasMaxSize.ts +4 -2
- package/src/lib/utils/debug-flags.ts +0 -20
- package/src/lib/utils/deepLinks.ts +1 -1
- package/src/lib/utils/dom.ts +6 -7
- package/src/lib/utils/getIncrementedName.ts +1 -1
- package/src/lib/utils/getPointerInfo.ts +1 -0
- package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
- package/src/lib/utils/keyboard.ts +6 -4
- package/src/lib/utils/normalizeWheel.ts +8 -8
- package/src/lib/utils/reorderShapes.ts +17 -8
- package/src/lib/utils/reparenting.ts +5 -10
- package/src/lib/utils/richText.ts +1 -1
- package/src/lib/utils/rotation.ts +1 -1
- package/src/lib/utils/runtime.ts +26 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/utils/hardResetEditor.js.map +0 -7
- package/dist-cjs/lib/utils/refreshPage.js +0 -28
- package/dist-cjs/lib/utils/refreshPage.js.map +0 -7
- package/dist-cjs/lib/utils/window-open.js +0 -28
- package/dist-cjs/lib/utils/window-open.js.map +0 -7
- package/dist-esm/lib/utils/hardResetEditor.mjs +0 -8
- package/dist-esm/lib/utils/hardResetEditor.mjs.map +0 -7
- package/dist-esm/lib/utils/refreshPage.mjs +0 -8
- package/dist-esm/lib/utils/refreshPage.mjs.map +0 -7
- package/dist-esm/lib/utils/window-open.mjs +0 -8
- package/dist-esm/lib/utils/window-open.mjs.map +0 -7
- package/src/lib/utils/hardResetEditor.ts +0 -6
- package/src/lib/utils/refreshPage.ts +0 -6
- package/src/lib/utils/window-open.ts +0 -16
|
@@ -3,8 +3,8 @@ import { TLHandle, TLShape, TLShapeId, VecModel } from '@tldraw/tlschema'
|
|
|
3
3
|
import { assertExists, uniqueId } from '@tldraw/utils'
|
|
4
4
|
import { Vec } from '../../../primitives/Vec'
|
|
5
5
|
import { Geometry2d } from '../../../primitives/geometry/Geometry2d'
|
|
6
|
-
import { Editor } from '../../Editor'
|
|
7
|
-
import { PointsSnapIndicator, SnapData, SnapManager } from './SnapManager'
|
|
6
|
+
import type { Editor } from '../../Editor'
|
|
7
|
+
import type { PointsSnapIndicator, SnapData, SnapManager } from './SnapManager'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* When dragging a handle, users can snap the handle to key geometry on other nearby shapes.
|
|
@@ -35,17 +35,31 @@ export interface TLShapeUtilConstructor<T extends TLShape, U extends ShapeUtil<T
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Options passed to {@link ShapeUtil.canBind}. A binding that could be made. At least one of
|
|
38
|
-
* `
|
|
38
|
+
* `fromShape` or `toShape` will belong to this shape util.
|
|
39
|
+
*
|
|
40
|
+
* The shapes may be full {@link @tldraw/tlschema#TLShape} objects when available, or just
|
|
41
|
+
* `{ type }` stubs when the shape hasn't been created yet (e.g. during arrow creation). Use
|
|
42
|
+
* `'id' in shape` to check whether the full shape is available.
|
|
39
43
|
*
|
|
40
44
|
* @public
|
|
41
45
|
*/
|
|
42
46
|
export interface TLShapeUtilCanBindOpts<Shape extends TLShape = TLShape> {
|
|
43
|
-
/** The
|
|
44
|
-
|
|
45
|
-
/** The
|
|
46
|
-
|
|
47
|
+
/** The shape referenced by the `fromId` of the binding, or a `{ type }` stub if unavailable. */
|
|
48
|
+
fromShape: TLShape | { type: TLShape['type'] }
|
|
49
|
+
/** The shape referenced by the `toId` of the binding, or a `{ type }` stub if unavailable. */
|
|
50
|
+
toShape: TLShape | { type: TLShape['type'] }
|
|
47
51
|
/** The type of binding. */
|
|
48
52
|
bindingType: string
|
|
53
|
+
/**
|
|
54
|
+
* The type of shape referenced by the `fromId` of the binding.
|
|
55
|
+
* @deprecated Use `fromShape.type` instead.
|
|
56
|
+
*/
|
|
57
|
+
fromShapeType: TLShape['type']
|
|
58
|
+
/**
|
|
59
|
+
* The type of shape referenced by the `toId` of the binding.
|
|
60
|
+
* @deprecated Use `toShape.type` instead.
|
|
61
|
+
*/
|
|
62
|
+
toShapeType: TLShape['type']
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
/**
|
|
@@ -2,7 +2,7 @@ import { VecModel } from '@tldraw/tlschema'
|
|
|
2
2
|
import { Box } from '../../../primitives/Box'
|
|
3
3
|
import { Vec } from '../../../primitives/Vec'
|
|
4
4
|
import { TLResizeHandle } from '../../types/selection-types'
|
|
5
|
-
import { TLBaseBoxShape } from '../BaseBoxShapeUtil'
|
|
5
|
+
import type { TLBaseBoxShape } from '../BaseBoxShapeUtil'
|
|
6
6
|
import { TLResizeMode } from '../ShapeUtil'
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TLShape, createShapeId } from '@tldraw/tlschema'
|
|
2
2
|
import { structuredClone } from '@tldraw/utils'
|
|
3
3
|
import { Vec } from '../../../../primitives/Vec'
|
|
4
|
-
import { Editor } from '../../../Editor'
|
|
4
|
+
import type { Editor } from '../../../Editor'
|
|
5
5
|
import { TLBaseBoxShape } from '../../../shapes/BaseBoxShapeUtil'
|
|
6
6
|
import { TLPointerEventInfo } from '../../../types/event-types'
|
|
7
7
|
import { StateNode } from '../../StateNode'
|
|
8
|
-
import { BaseBoxShapeTool } from '../BaseBoxShapeTool'
|
|
8
|
+
import type { BaseBoxShapeTool } from '../BaseBoxShapeTool'
|
|
9
9
|
|
|
10
10
|
export class Pointing extends StateNode {
|
|
11
11
|
static override id = 'pointing'
|
|
@@ -4,7 +4,7 @@ import { ReactElement, ReactNode, createContext, useContext, useEffect, useState
|
|
|
4
4
|
import { ContainerProvider } from '../../hooks/useContainer'
|
|
5
5
|
import { EditorProvider } from '../../hooks/useEditor'
|
|
6
6
|
import { useEvent } from '../../hooks/useEvent'
|
|
7
|
-
import { Editor } from '../Editor'
|
|
7
|
+
import type { Editor } from '../Editor'
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
10
|
export interface SvgExportDef {
|
|
@@ -2,7 +2,7 @@ import { TLShapeId } from '@tldraw/tlschema'
|
|
|
2
2
|
import { assert } from '@tldraw/utils'
|
|
3
3
|
import { flushSync } from 'react-dom'
|
|
4
4
|
import { createRoot } from 'react-dom/client'
|
|
5
|
-
import { Editor } from '../editor/Editor'
|
|
5
|
+
import type { Editor } from '../editor/Editor'
|
|
6
6
|
import { TLSvgExportOptions } from '../editor/types/misc-types'
|
|
7
7
|
import { SVG_EXPORT_CLASSNAME } from './FontEmbedder'
|
|
8
8
|
import { StyleEmbedder } from './StyleEmbedder'
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import { flushSync } from 'react-dom'
|
|
21
21
|
import { ErrorBoundary } from '../components/ErrorBoundary'
|
|
22
22
|
import { InnerShape, InnerShapeBackground } from '../components/Shape'
|
|
23
|
-
import { Editor, TLRenderingShape } from '../editor/Editor'
|
|
23
|
+
import type { Editor, TLRenderingShape } from '../editor/Editor'
|
|
24
24
|
import { TLFontFace } from '../editor/managers/FontManager/FontManager'
|
|
25
25
|
import { ShapeUtil } from '../editor/shapes/ShapeUtil'
|
|
26
26
|
import {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ComponentType, RefAttributes, createContext, useContext } from 'react'
|
|
2
|
+
import type { TLBrushProps } from '../components/default-components/DefaultBrush'
|
|
3
|
+
import type { TLCanvasComponentProps } from '../components/default-components/DefaultCanvas'
|
|
4
|
+
import type { TLCollaboratorHintProps } from '../components/default-components/DefaultCollaboratorHint'
|
|
5
|
+
import type { TLCursorProps } from '../components/default-components/DefaultCursor'
|
|
6
|
+
import type { TLErrorFallbackComponent } from '../components/default-components/DefaultErrorFallback'
|
|
7
|
+
import type { TLGridProps } from '../components/default-components/DefaultGrid'
|
|
8
|
+
import type { TLHandleProps } from '../components/default-components/DefaultHandle'
|
|
9
|
+
import type { TLHandlesProps } from '../components/default-components/DefaultHandles'
|
|
10
|
+
import type { TLScribbleProps } from '../components/default-components/DefaultScribble'
|
|
11
|
+
import type { TLSelectionBackgroundProps } from '../components/default-components/DefaultSelectionBackground'
|
|
12
|
+
import type { TLSelectionForegroundProps } from '../components/default-components/DefaultSelectionForeground'
|
|
13
|
+
import type { TLShapeErrorFallbackComponent } from '../components/default-components/DefaultShapeErrorFallback'
|
|
14
|
+
import type { TLShapeIndicatorProps } from '../components/default-components/DefaultShapeIndicator'
|
|
15
|
+
import type { TLShapeIndicatorErrorFallbackComponent } from '../components/default-components/DefaultShapeIndicatorErrorFallback'
|
|
16
|
+
import type { TLShapeWrapperProps } from '../components/default-components/DefaultShapeWrapper'
|
|
17
|
+
import type { TLSnapIndicatorProps } from '../components/default-components/DefaultSnapIndictor'
|
|
18
|
+
|
|
19
|
+
/** @public */
|
|
20
|
+
export interface TLEditorComponents {
|
|
21
|
+
Background?: ComponentType | null
|
|
22
|
+
Brush?: ComponentType<TLBrushProps> | null
|
|
23
|
+
Canvas?: ComponentType<TLCanvasComponentProps> | null
|
|
24
|
+
CollaboratorBrush?: ComponentType<TLBrushProps> | null
|
|
25
|
+
CollaboratorCursor?: ComponentType<TLCursorProps> | null
|
|
26
|
+
CollaboratorHint?: ComponentType<TLCollaboratorHintProps> | null
|
|
27
|
+
CollaboratorScribble?: ComponentType<TLScribbleProps> | null
|
|
28
|
+
CollaboratorShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
|
|
29
|
+
Cursor?: ComponentType<TLCursorProps> | null
|
|
30
|
+
Grid?: ComponentType<TLGridProps> | null
|
|
31
|
+
Handle?: ComponentType<TLHandleProps> | null
|
|
32
|
+
Handles?: ComponentType<TLHandlesProps> | null
|
|
33
|
+
InFrontOfTheCanvas?: ComponentType | null
|
|
34
|
+
LoadingScreen?: ComponentType | null
|
|
35
|
+
OnTheCanvas?: ComponentType | null
|
|
36
|
+
Overlays?: ComponentType | null
|
|
37
|
+
Scribble?: ComponentType<TLScribbleProps> | null
|
|
38
|
+
SelectionBackground?: ComponentType<TLSelectionBackgroundProps> | null
|
|
39
|
+
SelectionForeground?: ComponentType<TLSelectionForegroundProps> | null
|
|
40
|
+
ShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
|
|
41
|
+
ShapeIndicators?: ComponentType | null
|
|
42
|
+
ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null
|
|
43
|
+
SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null
|
|
44
|
+
Spinner?: ComponentType<React.SVGProps<SVGSVGElement>> | null
|
|
45
|
+
SvgDefs?: ComponentType | null
|
|
46
|
+
ZoomBrush?: ComponentType<TLBrushProps> | null
|
|
47
|
+
|
|
48
|
+
// These will always have defaults
|
|
49
|
+
ErrorFallback?: TLErrorFallbackComponent
|
|
50
|
+
ShapeErrorFallback?: TLShapeErrorFallbackComponent
|
|
51
|
+
ShapeIndicatorErrorFallback?: TLShapeIndicatorErrorFallbackComponent
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const EditorComponentsContext = createContext<null | Required<TLEditorComponents>>(null)
|
|
55
|
+
|
|
56
|
+
/** @public */
|
|
57
|
+
export function useEditorComponents() {
|
|
58
|
+
const components = useContext(EditorComponentsContext)
|
|
59
|
+
if (!components) {
|
|
60
|
+
throw new Error('useEditorComponents must be used inside of <EditorComponentsProvider />')
|
|
61
|
+
}
|
|
62
|
+
return components
|
|
63
|
+
}
|
|
@@ -102,13 +102,24 @@ export function useCanvasEvents() {
|
|
|
102
102
|
preventDefault(e)
|
|
103
103
|
e.stopPropagation()
|
|
104
104
|
|
|
105
|
+
const pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY })
|
|
106
|
+
|
|
107
|
+
// Call the custom onDropOnCanvas callback if provided
|
|
108
|
+
if (editor.options.experimental__onDropOnCanvas) {
|
|
109
|
+
const handled = editor.options.experimental__onDropOnCanvas({
|
|
110
|
+
point: pagePoint,
|
|
111
|
+
event: e,
|
|
112
|
+
})
|
|
113
|
+
if (handled) return
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
if (e.dataTransfer?.files?.length) {
|
|
106
117
|
const files = Array.from(e.dataTransfer.files)
|
|
107
118
|
|
|
108
119
|
await editor.putExternalContent({
|
|
109
120
|
type: 'files',
|
|
110
121
|
files,
|
|
111
|
-
point:
|
|
122
|
+
point: pagePoint,
|
|
112
123
|
})
|
|
113
124
|
return
|
|
114
125
|
}
|
|
@@ -118,7 +129,7 @@ export function useCanvasEvents() {
|
|
|
118
129
|
await editor.putExternalContent({
|
|
119
130
|
type: 'url',
|
|
120
131
|
url,
|
|
121
|
-
point:
|
|
132
|
+
point: pagePoint,
|
|
122
133
|
})
|
|
123
134
|
return
|
|
124
135
|
}
|
|
@@ -1,90 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode, useMemo } from 'react'
|
|
2
2
|
import { DefaultBackground } from '../components/default-components/DefaultBackground'
|
|
3
|
-
import { DefaultBrush
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '../components/default-components/
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '../components/default-components/DefaultCollaboratorHint'
|
|
12
|
-
import { DefaultCursor, TLCursorProps } from '../components/default-components/DefaultCursor'
|
|
13
|
-
import {
|
|
14
|
-
DefaultErrorFallback,
|
|
15
|
-
TLErrorFallbackComponent,
|
|
16
|
-
} from '../components/default-components/DefaultErrorFallback'
|
|
17
|
-
import { DefaultGrid, TLGridProps } from '../components/default-components/DefaultGrid'
|
|
18
|
-
import { DefaultHandle, TLHandleProps } from '../components/default-components/DefaultHandle'
|
|
19
|
-
import { DefaultHandles, TLHandlesProps } from '../components/default-components/DefaultHandles'
|
|
3
|
+
import { DefaultBrush } from '../components/default-components/DefaultBrush'
|
|
4
|
+
import { DefaultCanvas } from '../components/default-components/DefaultCanvas'
|
|
5
|
+
import { DefaultCollaboratorHint } from '../components/default-components/DefaultCollaboratorHint'
|
|
6
|
+
import { DefaultCursor } from '../components/default-components/DefaultCursor'
|
|
7
|
+
import { DefaultErrorFallback } from '../components/default-components/DefaultErrorFallback'
|
|
8
|
+
import { DefaultGrid } from '../components/default-components/DefaultGrid'
|
|
9
|
+
import { DefaultHandle } from '../components/default-components/DefaultHandle'
|
|
10
|
+
import { DefaultHandles } from '../components/default-components/DefaultHandles'
|
|
20
11
|
import { DefaultLoadingScreen } from '../components/default-components/DefaultLoadingScreen'
|
|
21
|
-
import { DefaultScribble
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from '../components/default-components/DefaultSelectionForeground'
|
|
27
|
-
import {
|
|
28
|
-
DefaultShapeErrorFallback,
|
|
29
|
-
TLShapeErrorFallbackComponent,
|
|
30
|
-
} from '../components/default-components/DefaultShapeErrorFallback'
|
|
31
|
-
import {
|
|
32
|
-
DefaultShapeIndicator,
|
|
33
|
-
TLShapeIndicatorProps,
|
|
34
|
-
} from '../components/default-components/DefaultShapeIndicator'
|
|
35
|
-
import {
|
|
36
|
-
DefaultShapeIndicatorErrorFallback,
|
|
37
|
-
TLShapeIndicatorErrorFallbackComponent,
|
|
38
|
-
} from '../components/default-components/DefaultShapeIndicatorErrorFallback'
|
|
12
|
+
import { DefaultScribble } from '../components/default-components/DefaultScribble'
|
|
13
|
+
import { DefaultSelectionForeground } from '../components/default-components/DefaultSelectionForeground'
|
|
14
|
+
import { DefaultShapeErrorFallback } from '../components/default-components/DefaultShapeErrorFallback'
|
|
15
|
+
import { DefaultShapeIndicator } from '../components/default-components/DefaultShapeIndicator'
|
|
16
|
+
import { DefaultShapeIndicatorErrorFallback } from '../components/default-components/DefaultShapeIndicatorErrorFallback'
|
|
39
17
|
import { DefaultShapeIndicators } from '../components/default-components/DefaultShapeIndicators'
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
TLShapeWrapperProps,
|
|
43
|
-
} from '../components/default-components/DefaultShapeWrapper'
|
|
44
|
-
import {
|
|
45
|
-
DefaultSnapIndicator,
|
|
46
|
-
TLSnapIndicatorProps,
|
|
47
|
-
} from '../components/default-components/DefaultSnapIndictor'
|
|
18
|
+
import { DefaultShapeWrapper } from '../components/default-components/DefaultShapeWrapper'
|
|
19
|
+
import { DefaultSnapIndicator } from '../components/default-components/DefaultSnapIndictor'
|
|
48
20
|
import { DefaultSpinner } from '../components/default-components/DefaultSpinner'
|
|
49
21
|
import { DefaultSvgDefs } from '../components/default-components/DefaultSvgDefs'
|
|
22
|
+
import type { TLEditorComponents } from './EditorComponentsContext'
|
|
23
|
+
import { EditorComponentsContext } from './EditorComponentsContext'
|
|
50
24
|
import { useShallowObjectIdentity } from './useIdentity'
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
export
|
|
54
|
-
Background?: ComponentType | null
|
|
55
|
-
Brush?: ComponentType<TLBrushProps> | null
|
|
56
|
-
Canvas?: ComponentType<TLCanvasComponentProps> | null
|
|
57
|
-
CollaboratorBrush?: ComponentType<TLBrushProps> | null
|
|
58
|
-
CollaboratorCursor?: ComponentType<TLCursorProps> | null
|
|
59
|
-
CollaboratorHint?: ComponentType<TLCollaboratorHintProps> | null
|
|
60
|
-
CollaboratorScribble?: ComponentType<TLScribbleProps> | null
|
|
61
|
-
CollaboratorShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
|
|
62
|
-
Cursor?: ComponentType<TLCursorProps> | null
|
|
63
|
-
Grid?: ComponentType<TLGridProps> | null
|
|
64
|
-
Handle?: ComponentType<TLHandleProps> | null
|
|
65
|
-
Handles?: ComponentType<TLHandlesProps> | null
|
|
66
|
-
InFrontOfTheCanvas?: ComponentType | null
|
|
67
|
-
LoadingScreen?: ComponentType | null
|
|
68
|
-
OnTheCanvas?: ComponentType | null
|
|
69
|
-
Overlays?: ComponentType | null
|
|
70
|
-
Scribble?: ComponentType<TLScribbleProps> | null
|
|
71
|
-
SelectionBackground?: ComponentType<TLSelectionBackgroundProps> | null
|
|
72
|
-
SelectionForeground?: ComponentType<TLSelectionForegroundProps> | null
|
|
73
|
-
ShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
|
|
74
|
-
ShapeIndicators?: ComponentType | null
|
|
75
|
-
ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null
|
|
76
|
-
SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null
|
|
77
|
-
Spinner?: ComponentType<React.SVGProps<SVGSVGElement>> | null
|
|
78
|
-
SvgDefs?: ComponentType | null
|
|
79
|
-
ZoomBrush?: ComponentType<TLBrushProps> | null
|
|
80
|
-
|
|
81
|
-
// These will always have defaults
|
|
82
|
-
ErrorFallback?: TLErrorFallbackComponent
|
|
83
|
-
ShapeErrorFallback?: TLShapeErrorFallbackComponent
|
|
84
|
-
ShapeIndicatorErrorFallback?: TLShapeIndicatorErrorFallbackComponent
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const EditorComponentsContext = createContext<null | Required<TLEditorComponents>>(null)
|
|
26
|
+
export { useEditorComponents } from './EditorComponentsContext'
|
|
27
|
+
export type { TLEditorComponents } from './EditorComponentsContext'
|
|
88
28
|
|
|
89
29
|
interface ComponentsContextProviderProps {
|
|
90
30
|
overrides?: TLEditorComponents
|
|
@@ -138,12 +78,3 @@ export function EditorComponentsProvider({
|
|
|
138
78
|
<EditorComponentsContext.Provider value={value}>{children}</EditorComponentsContext.Provider>
|
|
139
79
|
)
|
|
140
80
|
}
|
|
141
|
-
|
|
142
|
-
/** @public */
|
|
143
|
-
export function useEditorComponents() {
|
|
144
|
-
const components = useContext(EditorComponentsContext)
|
|
145
|
-
if (!components) {
|
|
146
|
-
throw new Error('useEditorComponents must be used inside of <EditorComponentsProvider />')
|
|
147
|
-
}
|
|
148
|
-
return components
|
|
149
|
-
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useAtom, useComputed, useValue } from '@tldraw/state-react'
|
|
2
|
-
import { isEqual } from '@tldraw/utils'
|
|
3
2
|
import { useEffect } from 'react'
|
|
4
3
|
import {
|
|
5
4
|
getCollaboratorStateFromElapsedTime,
|
|
@@ -8,6 +7,14 @@ import {
|
|
|
8
7
|
import { uniq } from '../utils/uniq'
|
|
9
8
|
import { useEditor } from './useEditor'
|
|
10
9
|
|
|
10
|
+
function setsEqual<T>(a: Set<T>, b: Set<T>): boolean {
|
|
11
|
+
if (a.size !== b.size) return false
|
|
12
|
+
for (const item of a) {
|
|
13
|
+
if (!b.has(item)) return false
|
|
14
|
+
}
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
// TODO: maybe move this to a computed property on the App class?
|
|
12
19
|
/**
|
|
13
20
|
* @returns The list of peer UserIDs
|
|
@@ -60,7 +67,7 @@ export function useActivePeerIds$() {
|
|
|
60
67
|
.map((p) => p.userId)
|
|
61
68
|
)
|
|
62
69
|
},
|
|
63
|
-
{ isEqual },
|
|
70
|
+
{ isEqual: setsEqual },
|
|
64
71
|
[editor]
|
|
65
72
|
)
|
|
66
73
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TLShapeId } from '@tldraw/tlschema'
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, useRef } from 'react'
|
|
3
|
+
import { setStyleProperty } from '../utils/dom'
|
|
4
|
+
|
|
5
|
+
interface ShapeContainerEntry {
|
|
6
|
+
container: HTMLDivElement
|
|
7
|
+
bgContainer: HTMLDivElement | null
|
|
8
|
+
isCulled: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ShapeCullingContextValue {
|
|
12
|
+
register(
|
|
13
|
+
id: TLShapeId,
|
|
14
|
+
container: HTMLDivElement,
|
|
15
|
+
bgContainer: HTMLDivElement | null,
|
|
16
|
+
isCulled: boolean
|
|
17
|
+
): void
|
|
18
|
+
unregister(id: TLShapeId): void
|
|
19
|
+
updateCulling(culledShapes: Set<TLShapeId>): void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ShapeCullingContext = createContext<ShapeCullingContextValue | null>(null)
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
export interface ShapeCullingProviderProps {
|
|
26
|
+
children: React.ReactNode
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Provides centralized culling management for shape containers.
|
|
31
|
+
* This allows a single reactor to update all shape display states
|
|
32
|
+
* instead of each shape having its own subscription.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export function ShapeCullingProvider({ children }: ShapeCullingProviderProps) {
|
|
37
|
+
const containersRef = useRef(new Map<TLShapeId, ShapeContainerEntry>())
|
|
38
|
+
|
|
39
|
+
const register = useCallback(
|
|
40
|
+
(
|
|
41
|
+
id: TLShapeId,
|
|
42
|
+
container: HTMLDivElement,
|
|
43
|
+
bgContainer: HTMLDivElement | null,
|
|
44
|
+
isCulled: boolean
|
|
45
|
+
) => {
|
|
46
|
+
const display = isCulled ? 'none' : 'block'
|
|
47
|
+
setStyleProperty(container, 'display', display)
|
|
48
|
+
setStyleProperty(bgContainer, 'display', display)
|
|
49
|
+
|
|
50
|
+
containersRef.current.set(id, {
|
|
51
|
+
container,
|
|
52
|
+
bgContainer,
|
|
53
|
+
isCulled,
|
|
54
|
+
})
|
|
55
|
+
},
|
|
56
|
+
[]
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const unregister = useCallback((id: TLShapeId) => {
|
|
60
|
+
containersRef.current.delete(id)
|
|
61
|
+
}, [])
|
|
62
|
+
|
|
63
|
+
const updateCulling = useCallback((culledShapes: Set<TLShapeId>) => {
|
|
64
|
+
for (const [id, entry] of containersRef.current) {
|
|
65
|
+
const shouldBeCulled = culledShapes.has(id)
|
|
66
|
+
if (shouldBeCulled !== entry.isCulled) {
|
|
67
|
+
const display = shouldBeCulled ? 'none' : 'block'
|
|
68
|
+
setStyleProperty(entry.container, 'display', display)
|
|
69
|
+
setStyleProperty(entry.bgContainer, 'display', display)
|
|
70
|
+
entry.isCulled = shouldBeCulled
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, [])
|
|
74
|
+
|
|
75
|
+
const value = useMemo(
|
|
76
|
+
() => ({
|
|
77
|
+
register,
|
|
78
|
+
unregister,
|
|
79
|
+
updateCulling,
|
|
80
|
+
}),
|
|
81
|
+
[register, unregister, updateCulling]
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return <ShapeCullingContext.Provider value={value}>{children}</ShapeCullingContext.Provider>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Hook to access the shape culling context for container registration.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export function useShapeCulling(): ShapeCullingContextValue {
|
|
93
|
+
const context = useContext(ShapeCullingContext)
|
|
94
|
+
if (!context) {
|
|
95
|
+
throw new Error('useShapeCulling must be used within ShapeCullingProvider')
|
|
96
|
+
}
|
|
97
|
+
return context
|
|
98
|
+
}
|
|
@@ -431,25 +431,25 @@ export class LicenseManager {
|
|
|
431
431
|
private outputMessages(messages: string[], type: 'warning' | 'error' = 'error') {
|
|
432
432
|
if (this.isTest) return
|
|
433
433
|
if (this.verbose) {
|
|
434
|
-
this.outputDelimiter()
|
|
434
|
+
this.outputDelimiter(type)
|
|
435
435
|
for (const message of messages) {
|
|
436
|
-
const color = type === 'warning' ? 'orange' : 'crimson'
|
|
437
436
|
const bgColor = type === 'warning' ? 'orange' : 'crimson'
|
|
438
437
|
// eslint-disable-next-line no-console
|
|
439
438
|
console.log(
|
|
440
439
|
`%c${message}`,
|
|
441
|
-
`color:
|
|
440
|
+
`color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`
|
|
442
441
|
)
|
|
443
442
|
}
|
|
444
|
-
this.outputDelimiter()
|
|
443
|
+
this.outputDelimiter(type)
|
|
445
444
|
}
|
|
446
445
|
}
|
|
447
446
|
|
|
448
|
-
private outputDelimiter() {
|
|
447
|
+
private outputDelimiter(type: 'warning' | 'error' = 'error') {
|
|
448
|
+
const bgColor = type === 'warning' ? 'orange' : 'crimson'
|
|
449
449
|
// eslint-disable-next-line no-console
|
|
450
450
|
console.log(
|
|
451
451
|
'%c-------------------------------------------------------------------',
|
|
452
|
-
`color: white; background:
|
|
452
|
+
`color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`
|
|
453
453
|
)
|
|
454
454
|
}
|
|
455
455
|
|
package/src/lib/options.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { ComponentType, Fragment } from 'react'
|
|
2
|
+
import { DEFAULT_CAMERA_OPTIONS } from './constants'
|
|
3
|
+
import { TLCameraOptions } from './editor/types/misc-types'
|
|
4
|
+
import { VecLike } from './primitives/Vec'
|
|
5
|
+
import { TLDeepLinkOptions } from './utils/deepLinks'
|
|
6
|
+
import { TLTextOptions } from './utils/richText'
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.
|
|
@@ -95,13 +100,13 @@ export interface TldrawOptions {
|
|
|
95
100
|
readonly branding?: string
|
|
96
101
|
/**
|
|
97
102
|
* Whether to use debounced zoom level for certain rendering optimizations. When true,
|
|
98
|
-
* `editor.
|
|
103
|
+
* `editor.getEfficientZoomLevel()` returns a cached zoom value while the camera is moving,
|
|
99
104
|
* reducing re-renders. When false, it always returns the current zoom level.
|
|
100
105
|
*/
|
|
101
106
|
readonly debouncedZoom: boolean
|
|
102
107
|
/**
|
|
103
108
|
* The number of shapes that must be on the page for the debounced zoom level to be used.
|
|
104
|
-
* Defaults to
|
|
109
|
+
* Defaults to 500 shapes.
|
|
105
110
|
*/
|
|
106
111
|
readonly debouncedZoomThreshold: number
|
|
107
112
|
/**
|
|
@@ -120,6 +125,46 @@ export interface TldrawOptions {
|
|
|
120
125
|
* The distance (in screen pixels) at which shapes snap to guides and other shapes.
|
|
121
126
|
*/
|
|
122
127
|
readonly snapThreshold: number
|
|
128
|
+
/**
|
|
129
|
+
* Options for the editor's camera. These are the initial camera options.
|
|
130
|
+
* Use {@link Editor.setCameraOptions} to update camera options at runtime.
|
|
131
|
+
*/
|
|
132
|
+
readonly camera: Partial<TLCameraOptions>
|
|
133
|
+
/**
|
|
134
|
+
* Options for the editor's text rendering. These include TipTap configuration and
|
|
135
|
+
* font handling. These are the initial text options and cannot be changed at runtime.
|
|
136
|
+
*/
|
|
137
|
+
readonly text: TLTextOptions
|
|
138
|
+
/**
|
|
139
|
+
* Options for syncing the editor's camera state with the URL. Set to `true` to enable
|
|
140
|
+
* with default options, or pass an options object to customize behavior.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* // Enable with defaults
|
|
145
|
+
* <Tldraw options={{ deepLinks: true }} />
|
|
146
|
+
*
|
|
147
|
+
* // Enable with custom options
|
|
148
|
+
* <Tldraw options={{ deepLinks: { param: 'd', debounceMs: 500 } }} />
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
readonly deepLinks: true | TLDeepLinkOptions | undefined
|
|
152
|
+
/**
|
|
153
|
+
* Whether the quick-zoom brush preserves its screen-pixel size when the user
|
|
154
|
+
* zooms the overview. When true, zooming in shrinks the target viewport (higher
|
|
155
|
+
* return zoom); zooming out expands it. When false, the brush keeps the original
|
|
156
|
+
* viewport's page dimensions regardless of overview zoom changes.
|
|
157
|
+
*/
|
|
158
|
+
readonly quickZoomPreservesScreenBounds: boolean
|
|
159
|
+
/**
|
|
160
|
+
* Called when content is dropped on the canvas. Provides the page position
|
|
161
|
+
* where the drop occurred and the underlying drag event object.
|
|
162
|
+
* Return true to prevent default drop handling (files, URLs, etc.)
|
|
163
|
+
*/
|
|
164
|
+
experimental__onDropOnCanvas?(options: {
|
|
165
|
+
point: VecLike
|
|
166
|
+
event: React.DragEvent<Element>
|
|
167
|
+
}): boolean
|
|
123
168
|
}
|
|
124
169
|
|
|
125
170
|
/** @public */
|
|
@@ -178,4 +223,9 @@ export const defaultTldrawOptions = {
|
|
|
178
223
|
spacebarPanning: true,
|
|
179
224
|
zoomToFitPadding: 128,
|
|
180
225
|
snapThreshold: 8,
|
|
226
|
+
camera: DEFAULT_CAMERA_OPTIONS,
|
|
227
|
+
text: {},
|
|
228
|
+
deepLinks: undefined,
|
|
229
|
+
quickZoomPreservesScreenBounds: true,
|
|
230
|
+
experimental__onDropOnCanvas: undefined,
|
|
181
231
|
} as const satisfies TldrawOptions
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { VecModel } from '@tldraw/tlschema'
|
|
2
2
|
import { EASINGS } from './easings'
|
|
3
|
-
|
|
3
|
+
function clamp(n: number, min: number, max?: number): number {
|
|
4
|
+
return Math.max(min, typeof max !== 'undefined' ? Math.min(n, max) : n)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function toFixed(v: number) {
|
|
8
|
+
return Math.round(v * 1e2) / 1e2
|
|
9
|
+
}
|
|
4
10
|
|
|
5
11
|
/** @public */
|
|
6
12
|
export type VecLike = Vec | VecModel
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { TLShape } from '@tldraw/tlschema'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Checks if two shapes are equal by comparing their props and meta.
|
|
5
|
+
* @param a - The first shape.
|
|
6
|
+
* @param b - The second shape.
|
|
7
|
+
* @returns True if the shapes are equal, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export function areShapesContentEqual(a: TLShape, b: TLShape) {
|
|
10
|
+
return a.props === b.props && a.meta === b.meta
|
|
11
|
+
}
|