@tldraw/editor 3.14.0-canary.e0ab6f4c80f9 → 3.14.0-canary.e34e46232a4e
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 +129 -107
- package/dist-cjs/index.js +8 -8
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/config/TLSessionStateSnapshot.js +1 -12
- package/dist-cjs/lib/config/TLSessionStateSnapshot.js.map +3 -3
- package/dist-cjs/lib/editor/Editor.js +76 -78
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js +22 -22
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +16 -20
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +3 -3
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js +16 -16
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js.map +2 -2
- package/dist-cjs/lib/editor/managers/{ClickManager.js → ClickManager/ClickManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{EdgeScrollManager.js → EdgeScrollManager/EdgeScrollManager.js} +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{FocusManager.js → FocusManager/FocusManager.js} +2 -0
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{FontManager.js → FontManager/FontManager.js} +4 -1
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{HistoryManager.js → HistoryManager/HistoryManager.js} +64 -6
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{ScribbleManager.js → ScribbleManager/ScribbleManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{TextManager.js → TextManager/TextManager.js} +73 -42
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{TickManager.js → TickManager/TickManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{UserPreferencesManager.js → UserPreferencesManager/UserPreferencesManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +7 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +8 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +6 -0
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +3 -3
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js.map +1 -1
- package/dist-cjs/lib/hooks/useCanvasEvents.js +1 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +33 -33
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +18 -13
- package/dist-cjs/lib/primitives/Vec.js.map +3 -3
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +41 -21
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +11 -11
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +13 -16
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js +4 -4
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Edge2d.js +14 -21
- package/dist-cjs/lib/primitives/geometry/Edge2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +10 -10
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +5 -0
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Point2d.js +6 -6
- package/dist-cjs/lib/primitives/geometry/Point2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polygon2d.js +3 -0
- package/dist-cjs/lib/primitives/geometry/Polygon2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js +8 -5
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Rectangle2d.js +22 -11
- package/dist-cjs/lib/primitives/geometry/Rectangle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +22 -22
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
- package/dist-cjs/lib/utils/reorderShapes.js +11 -10
- package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
- package/dist-cjs/lib/utils/richText.js +7 -2
- package/dist-cjs/lib/utils/richText.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +129 -107
- package/dist-esm/index.mjs +15 -9
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/config/TLSessionStateSnapshot.mjs +1 -1
- package/dist-esm/lib/config/TLSessionStateSnapshot.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +76 -78
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +22 -22
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +16 -20
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +3 -3
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs +16 -16
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/{ClickManager.mjs → ClickManager/ClickManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{EdgeScrollManager.mjs → EdgeScrollManager/EdgeScrollManager.mjs} +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{FocusManager.mjs → FocusManager/FocusManager.mjs} +2 -0
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{FontManager.mjs → FontManager/FontManager.mjs} +4 -1
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{HistoryManager.mjs → HistoryManager/HistoryManager.mjs} +60 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{ScribbleManager.mjs → ScribbleManager/ScribbleManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{TextManager.mjs → TextManager/TextManager.mjs} +73 -42
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{TickManager.mjs → TickManager/TickManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{UserPreferencesManager.mjs → UserPreferencesManager/UserPreferencesManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +7 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +8 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +6 -0
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +3 -3
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +1 -1
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +1 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +33 -33
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +19 -14
- package/dist-esm/lib/primitives/Vec.mjs.map +3 -3
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +41 -21
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +11 -11
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +13 -16
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs +4 -4
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs +14 -21
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +11 -11
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +7 -1
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Point2d.mjs +6 -6
- package/dist-esm/lib/primitives/geometry/Point2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polygon2d.mjs +3 -0
- package/dist-esm/lib/primitives/geometry/Polygon2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +8 -5
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Rectangle2d.mjs +22 -11
- package/dist-esm/lib/primitives/geometry/Rectangle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +22 -22
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
- package/dist-esm/lib/utils/reorderShapes.mjs +11 -10
- package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
- package/dist-esm/lib/utils/richText.mjs +8 -3
- package/dist-esm/lib/utils/richText.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +433 -482
- package/package.json +8 -9
- package/src/index.ts +19 -8
- package/src/lib/config/TLSessionStateSnapshot.ts +1 -1
- package/src/lib/editor/Editor.test.ts +252 -3
- package/src/lib/editor/Editor.ts +77 -76
- package/src/lib/editor/bindings/BindingUtil.ts +6 -0
- package/src/lib/editor/derivations/bindingsIndex.ts +27 -26
- package/src/lib/editor/derivations/notVisibleShapes.ts +24 -25
- package/src/lib/editor/derivations/parentsToChildren.ts +28 -25
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +442 -0
- package/src/lib/editor/managers/{ClickManager.ts → ClickManager/ClickManager.ts} +3 -3
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +374 -0
- package/src/lib/editor/managers/{EdgeScrollManager.ts → EdgeScrollManager/EdgeScrollManager.ts} +3 -3
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +455 -0
- package/src/lib/editor/managers/{FocusManager.ts → FocusManager/FocusManager.ts} +3 -1
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +263 -0
- package/src/lib/editor/managers/{FontManager.ts → FontManager/FontManager.ts} +5 -2
- package/src/lib/editor/managers/{HistoryManager.test.ts → HistoryManager/HistoryManager.test.ts} +388 -1
- package/src/lib/editor/managers/{HistoryManager.ts → HistoryManager/HistoryManager.ts} +73 -2
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +624 -0
- package/src/lib/editor/managers/{ScribbleManager.ts → ScribbleManager/ScribbleManager.ts} +2 -2
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +485 -0
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +407 -0
- package/src/lib/editor/managers/{TextManager.ts → TextManager/TextManager.ts} +119 -87
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +314 -0
- package/src/lib/editor/managers/{TickManager.ts → TickManager/TickManager.ts} +2 -2
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +591 -0
- package/src/lib/editor/managers/{UserPreferencesManager.ts → UserPreferencesManager/UserPreferencesManager.ts} +2 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +11 -1
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +8 -0
- package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +5 -2
- package/src/lib/editor/tools/StateNode.ts +3 -3
- package/src/lib/editor/types/external-content.ts +11 -2
- package/src/lib/exports/getSvgJsx.tsx +1 -1
- package/src/lib/hooks/useCanvasEvents.ts +0 -1
- package/src/lib/primitives/Box.test.ts +588 -7
- package/src/lib/primitives/Box.ts +33 -33
- package/src/lib/primitives/Vec.test.ts +2 -2
- package/src/lib/primitives/Vec.ts +15 -10
- package/src/lib/primitives/geometry/Arc2d.ts +42 -23
- package/src/lib/primitives/geometry/Circle2d.ts +12 -12
- package/src/lib/primitives/geometry/CubicBezier2d.test.ts +5 -0
- package/src/lib/primitives/geometry/CubicBezier2d.ts +13 -17
- package/src/lib/primitives/geometry/CubicSpline2d.ts +5 -5
- package/src/lib/primitives/geometry/Edge2d.ts +14 -25
- package/src/lib/primitives/geometry/Ellipse2d.ts +12 -13
- package/src/lib/primitives/geometry/Geometry2d.ts +6 -0
- package/src/lib/primitives/geometry/Point2d.ts +6 -6
- package/src/lib/primitives/geometry/Polygon2d.ts +4 -0
- package/src/lib/primitives/geometry/Polyline2d.ts +10 -7
- package/src/lib/primitives/geometry/Rectangle2d.ts +24 -11
- package/src/lib/primitives/geometry/Stadium2d.ts +22 -23
- package/src/lib/utils/reorderShapes.ts +10 -13
- package/src/lib/utils/richText.ts +10 -4
- package/src/version.ts +3 -3
- package/dist-cjs/lib/editor/managers/ClickManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/EdgeScrollManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/FocusManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/FontManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/HistoryManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/ScribbleManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/Stack.js +0 -82
- package/dist-cjs/lib/editor/managers/Stack.js.map +0 -7
- package/dist-cjs/lib/editor/managers/TextManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/TickManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/UserPreferencesManager.js.map +0 -7
- package/dist-esm/lib/editor/managers/ClickManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/EdgeScrollManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/FocusManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/FontManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/HistoryManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/ScribbleManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/Stack.mjs +0 -62
- package/dist-esm/lib/editor/managers/Stack.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/TextManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/TickManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs.map +0 -7
- package/src/lib/editor/managers/ScribbleManager.test.ts +0 -32
- package/src/lib/editor/managers/Stack.ts +0 -71
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/editor/bindings/BindingUtil.ts"],
|
|
4
|
-
"sourcesContent": ["import { RecordProps, TLPropsMigrations, TLShape, TLUnknownBinding } from '@tldraw/tlschema'\nimport { Editor } from '../Editor'\n\n/** @public */\nexport interface TLBindingUtilConstructor<\n\tT extends TLUnknownBinding,\n\tU extends BindingUtil<T> = BindingUtil<T>,\n> {\n\tnew (editor: Editor): U\n\ttype: T['type']\n\t/** Validations for this binding's props. */\n\tprops?: RecordProps<T>\n\t/** Migrations for this binding's props. */\n\tmigrations?: TLPropsMigrations\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeCreate} and {@link BindingUtil.onAfterCreate},\n * describing a the creating a binding.\n *\n * @public\n */\nexport interface BindingOnCreateOptions<Binding extends TLUnknownBinding> {\n\t/** The binding being created. */\n\tbinding: Binding\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeChange} and {@link BindingUtil.onAfterChange},\n * describing the data associated with a binding being changed.\n *\n * @public\n */\nexport interface BindingOnChangeOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record before the change is made. */\n\tbindingBefore: Binding\n\t/** The binding record after the change is made. */\n\tbindingAfter: Binding\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeDelete} and {@link BindingUtil.onAfterDelete},\n * describing a binding being deleted.\n *\n * @public\n */\nexport interface BindingOnDeleteOptions<Binding extends TLUnknownBinding> {\n\t/** The binding being deleted. */\n\tbinding: Binding\n}\n\n/**\n * Options passed to {@link BindingUtil.onAfterChangeFromShape} and\n * {@link BindingUtil.onAfterChangeToShape}, describing a bound shape being changed.\n *\n * @public\n */\nexport interface BindingOnShapeChangeOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record linking these two shapes. */\n\tbinding: Binding\n\t/** The shape record before the change is made. */\n\tshapeBefore: TLShape\n\t/** The shape record after the change is made. */\n\tshapeAfter: TLShape\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeIsolateFromShape} and\n * {@link BindingUtil.onBeforeIsolateToShape}, describing a shape that is about to be isolated from\n * the one that it's bound to.\n *\n * Isolation happens whenever two bound shapes are separated. For example\n * 1. One is deleted, but the other is not.\n * 1. One is copied, but the other is not.\n * 1. One is duplicated, but the other is not.\n *\n * In each of these cases, if the remaining shape depends on the binding for its rendering, it may\n * now be in an inconsistent state. For example, tldraw's arrow shape depends on the binding to know\n * where the end of the arrow is. If we removed the binding without doing anything else, the arrow\n * would suddenly be pointing to the wrong location. Instead, when the shape the arrow is pointing\n * to is deleted, or the arrow is copied/duplicated, we use an isolation callback. The callback\n * updates the arrow based on the binding that's about to be removed, so it doesn't end up pointing\n * to the wrong place.\n *\n * For this style of consistency update, use isolation callbacks. For actions specific to deletion\n * (like deleting a sticker when the shape it's bound to is removed), use the delete callbacks\n * ({@link BindingUtil.onBeforeDeleteFromShape} and {@link BindingUtil.onBeforeDeleteToShape})\n * instead.\n *\n * @public\n */\nexport interface BindingOnShapeIsolateOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record that refers to the shape in question. */\n\tbinding: Binding\n\t/**\n\t * The shape being removed. For deletion, this is the deleted shape. For copy/duplicate, this is\n\t * the shape that _isn't_ being copied/duplicated and is getting left behind.\n\t */\n\tremovedShape: TLShape\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeDeleteFromShape} and\n * {@link BindingUtil.onBeforeDeleteToShape}, describing a bound shape that is about to be deleted.\n *\n * See {@link BindingOnShapeIsolateOptions} for discussion on when to use the delete vs. the isolate\n * callbacks.\n *\n * @public\n */\nexport interface BindingOnShapeDeleteOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record that refers to the shape in question. */\n\tbinding: Binding\n\t/** The shape that is about to be deleted. */\n\tshape: TLShape\n}\n\n/** @public */\nexport abstract class BindingUtil<Binding extends TLUnknownBinding = TLUnknownBinding> {\n\tconstructor(public editor: Editor) {}\n\tstatic props?: RecordProps<TLUnknownBinding>\n\tstatic migrations?: TLPropsMigrations\n\n\t/**\n\t * The type of the binding util, which should match the binding's type.\n\t *\n\t * @public\n\t */\n\tstatic type: string\n\n\t/**\n\t * Get the default props for a binding.\n\t *\n\t * @public\n\t */\n\tabstract getDefaultProps(): Partial<Binding['props']>\n\n\t/**\n\t * Called whenever a store operation involving this binding type has completed. This is useful\n\t * for working with networks of related bindings that may need to update together.\n\t *\n\t * @example\n\t * ```ts\n\t * class MyBindingUtil extends BindingUtil<MyBinding> {\n\t * changedBindingIds = new Set<TLBindingId>()\n\t *\n\t * onOperationComplete() {\n\t * doSomethingWithChangedBindings(this.changedBindingIds)\n\t * this.changedBindingIds.clear()\n\t * }\n\t *\n\t * onAfterChange({ bindingAfter }: BindingOnChangeOptions<MyBinding>) {\n\t * this.changedBindingIds.add(bindingAfter.id)\n\t * }\n\t * }\n\t * ```\n\t *\n\t * @public\n\t */\n\tonOperationComplete?(): void\n\n\t/**\n\t * Called when a binding is about to be created. See {@link BindingOnCreateOptions} for details.\n\t *\n\t * You can optionally return a new binding to replace the one being created - for example, to\n\t * set different initial props.\n\t *\n\t * @public\n\t */\n\tonBeforeCreate?(options: BindingOnCreateOptions<Binding>): Binding | void\n\n\t/**\n\t * Called after a binding has been created. See {@link BindingOnCreateOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterCreate?(options: BindingOnCreateOptions<Binding>): void\n\n\t/**\n\t * Called when a binding is about to be changed. See {@link BindingOnChangeOptions} for details.\n\t *\n\t * Note that this only fires when the binding record is changing, not when the shapes\n\t * associated change. Use {@link BindingUtil.onAfterChangeFromShape} and\n\t * {@link BindingUtil.onAfterChangeToShape} for that.\n\t *\n\t * You can optionally return a new binding to replace the one being changed - for example, to\n\t * enforce constraints on the binding's props.\n\t *\n\t * @public\n\t */\n\tonBeforeChange?(options: BindingOnChangeOptions<Binding>): Binding | void\n\n\t/**\n\t * Called after a binding has been changed. See {@link BindingOnChangeOptions} for details.\n\t *\n\t * Note that this only fires when the binding record is changing, not when the shapes\n\t * associated change. Use {@link BindingUtil.onAfterChangeFromShape} and\n\t * {@link BindingUtil.onAfterChangeToShape} for that.\n\t *\n\t * @public\n\t */\n\tonAfterChange?(options: BindingOnChangeOptions<Binding>): void\n\n\t/**\n\t * Called when a binding is about to be deleted. See {@link BindingOnDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonBeforeDelete?(options: BindingOnDeleteOptions<Binding>): void\n\n\t/**\n\t * Called after a binding has been deleted. See {@link BindingOnDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterDelete?(options: BindingOnDeleteOptions<Binding>): void\n\n\t/**\n\t * Called after the shape referenced in a binding's `fromId` is changed. Use this to propagate\n\t * any changes to the binding itself or the other shape as needed. See\n\t * {@link BindingOnShapeChangeOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterChangeFromShape?(options: BindingOnShapeChangeOptions<Binding>): void\n\n\t/**\n\t * Called after the shape referenced in a binding's `toId` is changed. Use this to propagate any\n\t * changes to the binding itself or the other shape as needed. See\n\t * {@link BindingOnShapeChangeOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterChangeToShape?(options: BindingOnShapeChangeOptions<Binding>): void\n\n\t/**\n\t * Called before the shape referenced in a binding's `fromId` is about to be deleted. Use this\n\t * with care - you may want to use {@link BindingUtil.onBeforeIsolateToShape} instead. See\n\t * {@link BindingOnShapeDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonBeforeDeleteFromShape?(options: BindingOnShapeDeleteOptions<Binding>): void\n\t/**\n\t * Called before the shape referenced in a binding's `toId` is about to be deleted. Use this\n\t * with care - you may want to use {@link BindingUtil.onBeforeIsolateFromShape} instead. See\n\t * {@link BindingOnShapeDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonBeforeDeleteToShape?(options: BindingOnShapeDeleteOptions<Binding>): void\n\n\t/**\n\t * Called before the shape referenced in a binding's `fromId` is about to be isolated from the\n\t * shape referenced in `toId`. See {@link BindingOnShapeIsolateOptions} for discussion on what\n\t * isolation means, and when/how to use this callback.\n\t */\n\tonBeforeIsolateFromShape?(options: BindingOnShapeIsolateOptions<Binding>): void\n\n\t/**\n\t * Called before the shape referenced in a binding's `toId` is about to be isolated from the\n\t * shape referenced in `fromId`. See {@link BindingOnShapeIsolateOptions} for discussion on what\n\t * isolation means, and when/how to use this callback.\n\t */\n\tonBeforeIsolateToShape?(options: BindingOnShapeIsolateOptions<Binding>): void\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { RecordProps, TLPropsMigrations, TLShape, TLUnknownBinding } from '@tldraw/tlschema'\nimport { Editor } from '../Editor'\n\n/** @public */\nexport interface TLBindingUtilConstructor<\n\tT extends TLUnknownBinding,\n\tU extends BindingUtil<T> = BindingUtil<T>,\n> {\n\tnew (editor: Editor): U\n\ttype: T['type']\n\t/** Validations for this binding's props. */\n\tprops?: RecordProps<T>\n\t/** Migrations for this binding's props. */\n\tmigrations?: TLPropsMigrations\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeCreate} and {@link BindingUtil.onAfterCreate},\n * describing a the creating a binding.\n *\n * @public\n */\nexport interface BindingOnCreateOptions<Binding extends TLUnknownBinding> {\n\t/** The binding being created. */\n\tbinding: Binding\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeChange} and {@link BindingUtil.onAfterChange},\n * describing the data associated with a binding being changed.\n *\n * @public\n */\nexport interface BindingOnChangeOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record before the change is made. */\n\tbindingBefore: Binding\n\t/** The binding record after the change is made. */\n\tbindingAfter: Binding\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeDelete} and {@link BindingUtil.onAfterDelete},\n * describing a binding being deleted.\n *\n * @public\n */\nexport interface BindingOnDeleteOptions<Binding extends TLUnknownBinding> {\n\t/** The binding being deleted. */\n\tbinding: Binding\n}\n\n/**\n * Options passed to {@link BindingUtil.onAfterChangeFromShape} and\n * {@link BindingUtil.onAfterChangeToShape}, describing a bound shape being changed.\n *\n * @public\n */\nexport interface BindingOnShapeChangeOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record linking these two shapes. */\n\tbinding: Binding\n\t/** The shape record before the change is made. */\n\tshapeBefore: TLShape\n\t/** The shape record after the change is made. */\n\tshapeAfter: TLShape\n\t/**\n\t * Why did this shape change?\n\t * - 'self': the shape itself changed\n\t * - 'ancestry': the ancestry of the shape changed, but the shape itself may not have done\n\t */\n\treason: 'self' | 'ancestry'\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeIsolateFromShape} and\n * {@link BindingUtil.onBeforeIsolateToShape}, describing a shape that is about to be isolated from\n * the one that it's bound to.\n *\n * Isolation happens whenever two bound shapes are separated. For example\n * 1. One is deleted, but the other is not.\n * 1. One is copied, but the other is not.\n * 1. One is duplicated, but the other is not.\n *\n * In each of these cases, if the remaining shape depends on the binding for its rendering, it may\n * now be in an inconsistent state. For example, tldraw's arrow shape depends on the binding to know\n * where the end of the arrow is. If we removed the binding without doing anything else, the arrow\n * would suddenly be pointing to the wrong location. Instead, when the shape the arrow is pointing\n * to is deleted, or the arrow is copied/duplicated, we use an isolation callback. The callback\n * updates the arrow based on the binding that's about to be removed, so it doesn't end up pointing\n * to the wrong place.\n *\n * For this style of consistency update, use isolation callbacks. For actions specific to deletion\n * (like deleting a sticker when the shape it's bound to is removed), use the delete callbacks\n * ({@link BindingUtil.onBeforeDeleteFromShape} and {@link BindingUtil.onBeforeDeleteToShape})\n * instead.\n *\n * @public\n */\nexport interface BindingOnShapeIsolateOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record that refers to the shape in question. */\n\tbinding: Binding\n\t/**\n\t * The shape being removed. For deletion, this is the deleted shape. For copy/duplicate, this is\n\t * the shape that _isn't_ being copied/duplicated and is getting left behind.\n\t */\n\tremovedShape: TLShape\n}\n\n/**\n * Options passed to {@link BindingUtil.onBeforeDeleteFromShape} and\n * {@link BindingUtil.onBeforeDeleteToShape}, describing a bound shape that is about to be deleted.\n *\n * See {@link BindingOnShapeIsolateOptions} for discussion on when to use the delete vs. the isolate\n * callbacks.\n *\n * @public\n */\nexport interface BindingOnShapeDeleteOptions<Binding extends TLUnknownBinding> {\n\t/** The binding record that refers to the shape in question. */\n\tbinding: Binding\n\t/** The shape that is about to be deleted. */\n\tshape: TLShape\n}\n\n/** @public */\nexport abstract class BindingUtil<Binding extends TLUnknownBinding = TLUnknownBinding> {\n\tconstructor(public editor: Editor) {}\n\tstatic props?: RecordProps<TLUnknownBinding>\n\tstatic migrations?: TLPropsMigrations\n\n\t/**\n\t * The type of the binding util, which should match the binding's type.\n\t *\n\t * @public\n\t */\n\tstatic type: string\n\n\t/**\n\t * Get the default props for a binding.\n\t *\n\t * @public\n\t */\n\tabstract getDefaultProps(): Partial<Binding['props']>\n\n\t/**\n\t * Called whenever a store operation involving this binding type has completed. This is useful\n\t * for working with networks of related bindings that may need to update together.\n\t *\n\t * @example\n\t * ```ts\n\t * class MyBindingUtil extends BindingUtil<MyBinding> {\n\t * changedBindingIds = new Set<TLBindingId>()\n\t *\n\t * onOperationComplete() {\n\t * doSomethingWithChangedBindings(this.changedBindingIds)\n\t * this.changedBindingIds.clear()\n\t * }\n\t *\n\t * onAfterChange({ bindingAfter }: BindingOnChangeOptions<MyBinding>) {\n\t * this.changedBindingIds.add(bindingAfter.id)\n\t * }\n\t * }\n\t * ```\n\t *\n\t * @public\n\t */\n\tonOperationComplete?(): void\n\n\t/**\n\t * Called when a binding is about to be created. See {@link BindingOnCreateOptions} for details.\n\t *\n\t * You can optionally return a new binding to replace the one being created - for example, to\n\t * set different initial props.\n\t *\n\t * @public\n\t */\n\tonBeforeCreate?(options: BindingOnCreateOptions<Binding>): Binding | void\n\n\t/**\n\t * Called after a binding has been created. See {@link BindingOnCreateOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterCreate?(options: BindingOnCreateOptions<Binding>): void\n\n\t/**\n\t * Called when a binding is about to be changed. See {@link BindingOnChangeOptions} for details.\n\t *\n\t * Note that this only fires when the binding record is changing, not when the shapes\n\t * associated change. Use {@link BindingUtil.onAfterChangeFromShape} and\n\t * {@link BindingUtil.onAfterChangeToShape} for that.\n\t *\n\t * You can optionally return a new binding to replace the one being changed - for example, to\n\t * enforce constraints on the binding's props.\n\t *\n\t * @public\n\t */\n\tonBeforeChange?(options: BindingOnChangeOptions<Binding>): Binding | void\n\n\t/**\n\t * Called after a binding has been changed. See {@link BindingOnChangeOptions} for details.\n\t *\n\t * Note that this only fires when the binding record is changing, not when the shapes\n\t * associated change. Use {@link BindingUtil.onAfterChangeFromShape} and\n\t * {@link BindingUtil.onAfterChangeToShape} for that.\n\t *\n\t * @public\n\t */\n\tonAfterChange?(options: BindingOnChangeOptions<Binding>): void\n\n\t/**\n\t * Called when a binding is about to be deleted. See {@link BindingOnDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonBeforeDelete?(options: BindingOnDeleteOptions<Binding>): void\n\n\t/**\n\t * Called after a binding has been deleted. See {@link BindingOnDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterDelete?(options: BindingOnDeleteOptions<Binding>): void\n\n\t/**\n\t * Called after the shape referenced in a binding's `fromId` is changed. Use this to propagate\n\t * any changes to the binding itself or the other shape as needed. See\n\t * {@link BindingOnShapeChangeOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterChangeFromShape?(options: BindingOnShapeChangeOptions<Binding>): void\n\n\t/**\n\t * Called after the shape referenced in a binding's `toId` is changed. Use this to propagate any\n\t * changes to the binding itself or the other shape as needed. See\n\t * {@link BindingOnShapeChangeOptions} for details.\n\t *\n\t * @public\n\t */\n\tonAfterChangeToShape?(options: BindingOnShapeChangeOptions<Binding>): void\n\n\t/**\n\t * Called before the shape referenced in a binding's `fromId` is about to be deleted. Use this\n\t * with care - you may want to use {@link BindingUtil.onBeforeIsolateToShape} instead. See\n\t * {@link BindingOnShapeDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonBeforeDeleteFromShape?(options: BindingOnShapeDeleteOptions<Binding>): void\n\t/**\n\t * Called before the shape referenced in a binding's `toId` is about to be deleted. Use this\n\t * with care - you may want to use {@link BindingUtil.onBeforeIsolateFromShape} instead. See\n\t * {@link BindingOnShapeDeleteOptions} for details.\n\t *\n\t * @public\n\t */\n\tonBeforeDeleteToShape?(options: BindingOnShapeDeleteOptions<Binding>): void\n\n\t/**\n\t * Called before the shape referenced in a binding's `fromId` is about to be isolated from the\n\t * shape referenced in `toId`. See {@link BindingOnShapeIsolateOptions} for discussion on what\n\t * isolation means, and when/how to use this callback.\n\t */\n\tonBeforeIsolateFromShape?(options: BindingOnShapeIsolateOptions<Binding>): void\n\n\t/**\n\t * Called before the shape referenced in a binding's `toId` is about to be isolated from the\n\t * shape referenced in `fromId`. See {@link BindingOnShapeIsolateOptions} for discussion on what\n\t * isolation means, and when/how to use this callback.\n\t */\n\tonBeforeIsolateToShape?(options: BindingOnShapeIsolateOptions<Binding>): void\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4HO,MAAe,YAAiE;AAAA,EACtF,YAAmB,QAAgB;AAAhB;AAAA,EAAiB;AAAA,EACpC,OAAO;AAAA,EACP,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOP,OAAO;AAyIR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,38 +23,38 @@ __export(bindingsIndex_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(bindingsIndex_exports);
|
|
24
24
|
var import_state = require("@tldraw/state");
|
|
25
25
|
var import_utils = require("@tldraw/utils");
|
|
26
|
+
function fromScratch(bindingsQuery) {
|
|
27
|
+
const allBindings = bindingsQuery.get();
|
|
28
|
+
const shapesToBindings = /* @__PURE__ */ new Map();
|
|
29
|
+
for (const binding of allBindings) {
|
|
30
|
+
const { fromId, toId } = binding;
|
|
31
|
+
const bindingsForFromShape = shapesToBindings.get(fromId);
|
|
32
|
+
if (!bindingsForFromShape) {
|
|
33
|
+
shapesToBindings.set(fromId, [binding]);
|
|
34
|
+
} else {
|
|
35
|
+
bindingsForFromShape.push(binding);
|
|
36
|
+
}
|
|
37
|
+
const bindingsForToShape = shapesToBindings.get(toId);
|
|
38
|
+
if (!bindingsForToShape) {
|
|
39
|
+
shapesToBindings.set(toId, [binding]);
|
|
40
|
+
} else {
|
|
41
|
+
bindingsForToShape.push(binding);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return shapesToBindings;
|
|
45
|
+
}
|
|
26
46
|
const bindingsIndex = (editor) => {
|
|
27
47
|
const { store } = editor;
|
|
28
48
|
const bindingsHistory = store.query.filterHistory("binding");
|
|
29
49
|
const bindingsQuery = store.query.records("binding");
|
|
30
|
-
function fromScratch() {
|
|
31
|
-
const allBindings = bindingsQuery.get();
|
|
32
|
-
const shape2Binding = /* @__PURE__ */ new Map();
|
|
33
|
-
for (const binding of allBindings) {
|
|
34
|
-
const { fromId, toId } = binding;
|
|
35
|
-
const bindingsForFromShape = shape2Binding.get(fromId);
|
|
36
|
-
if (!bindingsForFromShape) {
|
|
37
|
-
shape2Binding.set(fromId, [binding]);
|
|
38
|
-
} else {
|
|
39
|
-
bindingsForFromShape.push(binding);
|
|
40
|
-
}
|
|
41
|
-
const bindingsForToShape = shape2Binding.get(toId);
|
|
42
|
-
if (!bindingsForToShape) {
|
|
43
|
-
shape2Binding.set(toId, [binding]);
|
|
44
|
-
} else {
|
|
45
|
-
bindingsForToShape.push(binding);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return shape2Binding;
|
|
49
|
-
}
|
|
50
50
|
return (0, import_state.computed)("arrowBindingsIndex", (_lastValue, lastComputedEpoch) => {
|
|
51
51
|
if ((0, import_state.isUninitialized)(_lastValue)) {
|
|
52
|
-
return fromScratch();
|
|
52
|
+
return fromScratch(bindingsQuery);
|
|
53
53
|
}
|
|
54
54
|
const lastValue = _lastValue;
|
|
55
55
|
const diff = bindingsHistory.getDiffSince(lastComputedEpoch);
|
|
56
56
|
if (diff === import_state.RESET_VALUE) {
|
|
57
|
-
return fromScratch();
|
|
57
|
+
return fromScratch(bindingsQuery);
|
|
58
58
|
}
|
|
59
59
|
let nextValue = void 0;
|
|
60
60
|
function removingBinding(binding) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/editor/derivations/bindingsIndex.ts"],
|
|
4
|
-
"sourcesContent": ["import { Computed, RESET_VALUE, computed, isUninitialized } from '@tldraw/state'\nimport { TLBinding, TLShapeId } from '@tldraw/tlschema'\nimport { objectMapValues } from '@tldraw/utils'\nimport { Editor } from '../Editor'\n\ntype TLBindingsIndex = Map<TLShapeId, TLBinding[]>\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AAEjE,mBAAgC;
|
|
4
|
+
"sourcesContent": ["import { Computed, RESET_VALUE, computed, isUninitialized } from '@tldraw/state'\nimport { TLArrowBinding, TLBinding, TLShapeId, TLUnknownBinding } from '@tldraw/tlschema'\nimport { objectMapValues } from '@tldraw/utils'\nimport { Editor } from '../Editor'\n\ntype TLBindingsIndex = Map<TLShapeId, TLBinding[]>\n\nfunction fromScratch(bindingsQuery: Computed<(TLArrowBinding | TLUnknownBinding)[], unknown>) {\n\tconst allBindings = bindingsQuery.get() as TLBinding[]\n\n\tconst shapesToBindings: TLBindingsIndex = new Map()\n\n\tfor (const binding of allBindings) {\n\t\tconst { fromId, toId } = binding\n\t\tconst bindingsForFromShape = shapesToBindings.get(fromId)\n\t\tif (!bindingsForFromShape) {\n\t\t\tshapesToBindings.set(fromId, [binding])\n\t\t} else {\n\t\t\tbindingsForFromShape.push(binding)\n\t\t}\n\t\tconst bindingsForToShape = shapesToBindings.get(toId)\n\t\tif (!bindingsForToShape) {\n\t\t\tshapesToBindings.set(toId, [binding])\n\t\t} else {\n\t\t\tbindingsForToShape.push(binding)\n\t\t}\n\t}\n\n\treturn shapesToBindings\n}\n\nexport const bindingsIndex = (editor: Editor): Computed<TLBindingsIndex> => {\n\tconst { store } = editor\n\tconst bindingsHistory = store.query.filterHistory('binding')\n\tconst bindingsQuery = store.query.records('binding')\n\n\treturn computed<TLBindingsIndex>('arrowBindingsIndex', (_lastValue, lastComputedEpoch) => {\n\t\tif (isUninitialized(_lastValue)) {\n\t\t\treturn fromScratch(bindingsQuery)\n\t\t}\n\n\t\tconst lastValue = _lastValue\n\n\t\tconst diff = bindingsHistory.getDiffSince(lastComputedEpoch)\n\n\t\tif (diff === RESET_VALUE) {\n\t\t\treturn fromScratch(bindingsQuery)\n\t\t}\n\n\t\tlet nextValue: TLBindingsIndex | undefined = undefined\n\n\t\tfunction removingBinding(binding: TLBinding) {\n\t\t\tnextValue ??= new Map(lastValue)\n\t\t\tconst prevFrom = nextValue.get(binding.fromId)\n\t\t\tconst nextFrom = prevFrom?.filter((b) => b.id !== binding.id)\n\t\t\tif (!nextFrom?.length) {\n\t\t\t\tnextValue.delete(binding.fromId)\n\t\t\t} else {\n\t\t\t\tnextValue.set(binding.fromId, nextFrom)\n\t\t\t}\n\t\t\tconst prevTo = nextValue.get(binding.toId)\n\t\t\tconst nextTo = prevTo?.filter((b) => b.id !== binding.id)\n\t\t\tif (!nextTo?.length) {\n\t\t\t\tnextValue.delete(binding.toId)\n\t\t\t} else {\n\t\t\t\tnextValue.set(binding.toId, nextTo)\n\t\t\t}\n\t\t}\n\n\t\tfunction ensureNewArray(shapeId: TLShapeId) {\n\t\t\tnextValue ??= new Map(lastValue)\n\n\t\t\tlet result = nextValue.get(shapeId)\n\t\t\tif (!result) {\n\t\t\t\tresult = []\n\t\t\t\tnextValue.set(shapeId, result)\n\t\t\t} else if (result === lastValue.get(shapeId)) {\n\t\t\t\tresult = result.slice(0)\n\t\t\t\tnextValue.set(shapeId, result)\n\t\t\t}\n\t\t\treturn result\n\t\t}\n\n\t\tfunction addBinding(binding: TLBinding) {\n\t\t\tensureNewArray(binding.fromId).push(binding)\n\t\t\tensureNewArray(binding.toId).push(binding)\n\t\t}\n\n\t\tfor (const changes of diff) {\n\t\t\tfor (const newBinding of objectMapValues(changes.added)) {\n\t\t\t\taddBinding(newBinding)\n\t\t\t}\n\n\t\t\tfor (const [prev, next] of objectMapValues(changes.updated)) {\n\t\t\t\tremovingBinding(prev)\n\t\t\t\taddBinding(next)\n\t\t\t}\n\n\t\t\tfor (const prev of objectMapValues(changes.removed)) {\n\t\t\t\tremovingBinding(prev)\n\t\t\t}\n\t\t}\n\n\t\t// TODO: add diff entries if we need them\n\t\treturn nextValue ?? lastValue\n\t})\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AAEjE,mBAAgC;AAKhC,SAAS,YAAY,eAAyE;AAC7F,QAAM,cAAc,cAAc,IAAI;AAEtC,QAAM,mBAAoC,oBAAI,IAAI;AAElD,aAAW,WAAW,aAAa;AAClC,UAAM,EAAE,QAAQ,KAAK,IAAI;AACzB,UAAM,uBAAuB,iBAAiB,IAAI,MAAM;AACxD,QAAI,CAAC,sBAAsB;AAC1B,uBAAiB,IAAI,QAAQ,CAAC,OAAO,CAAC;AAAA,IACvC,OAAO;AACN,2BAAqB,KAAK,OAAO;AAAA,IAClC;AACA,UAAM,qBAAqB,iBAAiB,IA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,OAAO;AAClC,UAAI,CAAC,QAAQ;AACZ,iBAAS,CAAC;AACV,kBAAU,IAAI,SAAS,MAAM;AAAA,MAC9B,WAAW,WAAW,UAAU,IAAI,OAAO,GAAG;AAC7C,iBAAS,OAAO,MAAM,CAAC;AACvB,kBAAU,IAAI,SAAS,MAAM;AAAA,MAC9B;AACA,aAAO;AAAA,IACR;AAEA,aAAS,WAAW,SAAoB;AACvC,qBAAe,QAAQ,MAAM,EAAE,KAAK,OAAO;AAC3C,qBAAe,QAAQ,IAAI,EAAE,KAAK,OAAO;AAAA,IAC1C;AAEA,eAAW,WAAW,MAAM;AAC3B,iBAAW,kBAAc,8BAAgB,QAAQ,KAAK,GAAG;AACxD,mBAAW,UAAU;AAAA,MACtB;AAEA,iBAAW,CAAC,MAAM,IAAI,SAAK,8BAAgB,QAAQ,OAAO,GAAG;AAC5D,wBAAgB,IAAI;AACpB,mBAAW,IAAI;AAAA,MAChB;AAEA,iBAAW,YAAQ,8BAAgB,QAAQ,OAAO,GAAG;AACpD,wBAAgB,IAAI;AAAA,MACrB;AAAA,IACD;AAGA,WAAO,aAAa;AAAA,EACrB,CAAC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,28 +22,24 @@ __export(notVisibleShapes_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(notVisibleShapes_exports);
|
|
24
24
|
var import_state = require("@tldraw/state");
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
function fromScratch(editor) {
|
|
26
|
+
const shapesIds = editor.getCurrentPageShapeIds();
|
|
27
|
+
const viewportPageBounds = editor.getViewportPageBounds();
|
|
28
|
+
const notVisibleShapes2 = /* @__PURE__ */ new Set();
|
|
29
|
+
shapesIds.forEach((id) => {
|
|
30
|
+
const pageBounds = editor.getShapePageBounds(id);
|
|
31
|
+
if (pageBounds === void 0 || !viewportPageBounds.includes(pageBounds)) {
|
|
32
|
+
notVisibleShapes2.add(id);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return notVisibleShapes2;
|
|
29
36
|
}
|
|
30
|
-
|
|
31
|
-
function
|
|
32
|
-
const
|
|
33
|
-
const viewportPageBounds = editor2.getViewportPageBounds();
|
|
34
|
-
const notVisibleShapes2 = /* @__PURE__ */ new Set();
|
|
35
|
-
shapes.forEach((id) => {
|
|
36
|
-
if (isShapeNotVisible(editor2, id, viewportPageBounds)) {
|
|
37
|
-
notVisibleShapes2.add(id);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return notVisibleShapes2;
|
|
41
|
-
}
|
|
42
|
-
return (0, import_state.computed)("notVisibleShapes", (prevValue) => {
|
|
37
|
+
function notVisibleShapes(editor) {
|
|
38
|
+
return (0, import_state.computed)("notVisibleShapes", function updateNotVisibleShapes(prevValue) {
|
|
39
|
+
const nextValue = fromScratch(editor);
|
|
43
40
|
if ((0, import_state.isUninitialized)(prevValue)) {
|
|
44
|
-
return
|
|
41
|
+
return nextValue;
|
|
45
42
|
}
|
|
46
|
-
const nextValue = fromScratch(editor);
|
|
47
43
|
if (prevValue.size !== nextValue.size) return nextValue;
|
|
48
44
|
for (const prev of prevValue) {
|
|
49
45
|
if (!nextValue.has(prev)) {
|
|
@@ -52,5 +48,5 @@ const notVisibleShapes = (editor) => {
|
|
|
52
48
|
}
|
|
53
49
|
return prevValue;
|
|
54
50
|
});
|
|
55
|
-
}
|
|
51
|
+
}
|
|
56
52
|
//# sourceMappingURL=notVisibleShapes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/editor/derivations/notVisibleShapes.ts"],
|
|
4
|
-
"sourcesContent": ["import { computed, isUninitialized } from '@tldraw/state'\nimport { TLShapeId } from '@tldraw/tlschema'\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0C;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { computed, isUninitialized } from '@tldraw/state'\nimport { TLShapeId } from '@tldraw/tlschema'\nimport { Editor } from '../Editor'\n\nfunction fromScratch(editor: Editor): Set<TLShapeId> {\n\tconst shapesIds = editor.getCurrentPageShapeIds()\n\tconst viewportPageBounds = editor.getViewportPageBounds()\n\tconst notVisibleShapes = new Set<TLShapeId>()\n\tshapesIds.forEach((id) => {\n\t\t// If the shape is fully outside of the viewport page bounds, add it to the set.\n\t\t// We'll ignore masks here, since they're more expensive to compute and the overhead is not worth it.\n\t\tconst pageBounds = editor.getShapePageBounds(id)\n\t\tif (pageBounds === undefined || !viewportPageBounds.includes(pageBounds)) {\n\t\t\tnotVisibleShapes.add(id)\n\t\t}\n\t})\n\treturn notVisibleShapes\n}\n\n/**\n * Incremental derivation of not visible shapes.\n * Non visible shapes are shapes outside of the viewport page bounds.\n *\n * @param editor - Instance of the tldraw Editor.\n * @returns Incremental derivation of non visible shapes.\n */\nexport function notVisibleShapes(editor: Editor) {\n\treturn computed<Set<TLShapeId>>('notVisibleShapes', function updateNotVisibleShapes(prevValue) {\n\t\tconst nextValue = fromScratch(editor)\n\n\t\tif (isUninitialized(prevValue)) {\n\t\t\treturn nextValue\n\t\t}\n\n\t\t// If there are more or less shapes, we know there's a change\n\t\tif (prevValue.size !== nextValue.size) return nextValue\n\n\t\t// If any of the old shapes are not in the new set, we know there's a change\n\t\tfor (const prev of prevValue) {\n\t\t\tif (!nextValue.has(prev)) {\n\t\t\t\treturn nextValue\n\t\t\t}\n\t\t}\n\n\t\t// If we've made it here, we know that the set is the same\n\t\treturn prevValue\n\t})\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0C;AAI1C,SAAS,YAAY,QAAgC;AACpD,QAAM,YAAY,OAAO,uBAAuB;AAChD,QAAM,qBAAqB,OAAO,sBAAsB;AACxD,QAAMA,oBAAmB,oBAAI,IAAe;AAC5C,YAAU,QAAQ,CAAC,OAAO;AAGzB,UAAM,aAAa,OAAO,mBAAmB,EAAE;AAC/C,QAAI,eAAe,UAAa,CAAC,mBAAmB,SAAS,UAAU,GAAG;AACzE,MAAAA,kBAAiB,IAAI,EAAE;AAAA,IACxB;AAAA,EACD,CAAC;AACD,SAAOA;AACR;AASO,SAAS,iBAAiB,QAAgB;AAChD,aAAO,uBAAyB,oBAAoB,SAAS,uBAAuB,WAAW;AAC9F,UAAM,YAAY,YAAY,MAAM;AAEpC,YAAI,8BAAgB,SAAS,GAAG;AAC/B,aAAO;AAAA,IACR;AAGA,QAAI,UAAU,SAAS,UAAU,KAAM,QAAO;AAG9C,eAAW,QAAQ,WAAW;AAC7B,UAAI,CAAC,UAAU,IAAI,IAAI,GAAG;AACzB,eAAO;AAAA,MACR;AAAA,IACD;AAGA,WAAO;AAAA,EACR,CAAC;AACF;",
|
|
6
|
+
"names": ["notVisibleShapes"]
|
|
7
7
|
}
|
|
@@ -24,32 +24,32 @@ module.exports = __toCommonJS(parentsToChildren_exports);
|
|
|
24
24
|
var import_state = require("@tldraw/state");
|
|
25
25
|
var import_tlschema = require("@tldraw/tlschema");
|
|
26
26
|
var import_utils = require("@tldraw/utils");
|
|
27
|
+
function fromScratch(shapeIdsQuery, store) {
|
|
28
|
+
const result = {};
|
|
29
|
+
const shapeIds = shapeIdsQuery.get();
|
|
30
|
+
const shapes = Array(shapeIds.size);
|
|
31
|
+
shapeIds.forEach((id) => shapes.push(store.get(id)));
|
|
32
|
+
shapes.sort(import_utils.sortByIndex);
|
|
33
|
+
shapes.forEach((shape) => {
|
|
34
|
+
if (!result[shape.parentId]) {
|
|
35
|
+
result[shape.parentId] = [];
|
|
36
|
+
}
|
|
37
|
+
result[shape.parentId].push(shape.id);
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
27
41
|
const parentsToChildren = (store) => {
|
|
28
42
|
const shapeIdsQuery = store.query.ids("shape");
|
|
29
43
|
const shapeHistory = store.query.filterHistory("shape");
|
|
30
|
-
function fromScratch() {
|
|
31
|
-
const result = {};
|
|
32
|
-
const shapeIds = shapeIdsQuery.get();
|
|
33
|
-
const shapes = Array(shapeIds.size);
|
|
34
|
-
shapeIds.forEach((id) => shapes.push(store.get(id)));
|
|
35
|
-
shapes.sort(import_utils.sortByIndex);
|
|
36
|
-
shapes.forEach((shape) => {
|
|
37
|
-
if (!result[shape.parentId]) {
|
|
38
|
-
result[shape.parentId] = [];
|
|
39
|
-
}
|
|
40
|
-
result[shape.parentId].push(shape.id);
|
|
41
|
-
});
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
44
|
return (0, import_state.computed)(
|
|
45
45
|
"parentsToChildrenWithIndexes",
|
|
46
46
|
(lastValue, lastComputedEpoch) => {
|
|
47
47
|
if ((0, import_state.isUninitialized)(lastValue)) {
|
|
48
|
-
return fromScratch();
|
|
48
|
+
return fromScratch(shapeIdsQuery, store);
|
|
49
49
|
}
|
|
50
50
|
const diff = shapeHistory.getDiffSince(lastComputedEpoch);
|
|
51
51
|
if (diff === import_state.RESET_VALUE) {
|
|
52
|
-
return fromScratch();
|
|
52
|
+
return fromScratch(shapeIdsQuery, store);
|
|
53
53
|
}
|
|
54
54
|
if (diff.length === 0) return lastValue;
|
|
55
55
|
let newValue = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/editor/derivations/parentsToChildren.ts"],
|
|
4
|
-
"sourcesContent": ["import { computed, isUninitialized, RESET_VALUE } from '@tldraw/state'\nimport { RecordsDiff } from '@tldraw/store'\nimport { isShape, TLParentId, TLRecord, TLShape, TLShapeId, TLStore } from '@tldraw/tlschema'\nimport { compact, sortByIndex } from '@tldraw/utils'\n\ntype
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Computed, computed, isUninitialized, RESET_VALUE } from '@tldraw/state'\nimport { CollectionDiff, RecordsDiff } from '@tldraw/store'\nimport { isShape, TLParentId, TLRecord, TLShape, TLShapeId, TLStore } from '@tldraw/tlschema'\nimport { compact, sortByIndex } from '@tldraw/utils'\n\ntype ParentShapeIdsToChildShapeIds = Record<TLParentId, TLShapeId[]>\n\nfunction fromScratch(\n\tshapeIdsQuery: Computed<Set<TLShapeId>, CollectionDiff<TLShapeId>>,\n\tstore: TLStore\n) {\n\tconst result: ParentShapeIdsToChildShapeIds = {}\n\tconst shapeIds = shapeIdsQuery.get()\n\tconst shapes = Array(shapeIds.size) as TLShape[]\n\tshapeIds.forEach((id) => shapes.push(store.get(id)!))\n\n\t// Sort the shapes by index\n\tshapes.sort(sortByIndex)\n\n\t// Populate the result object with an array for each parent.\n\tshapes.forEach((shape) => {\n\t\tif (!result[shape.parentId]) {\n\t\t\tresult[shape.parentId] = []\n\t\t}\n\t\tresult[shape.parentId].push(shape.id)\n\t})\n\n\treturn result\n}\n\nexport const parentsToChildren = (store: TLStore) => {\n\tconst shapeIdsQuery = store.query.ids<'shape'>('shape')\n\tconst shapeHistory = store.query.filterHistory('shape')\n\n\treturn computed<ParentShapeIdsToChildShapeIds>(\n\t\t'parentsToChildrenWithIndexes',\n\t\t(lastValue, lastComputedEpoch) => {\n\t\t\tif (isUninitialized(lastValue)) {\n\t\t\t\treturn fromScratch(shapeIdsQuery, store)\n\t\t\t}\n\n\t\t\tconst diff = shapeHistory.getDiffSince(lastComputedEpoch)\n\n\t\t\tif (diff === RESET_VALUE) {\n\t\t\t\treturn fromScratch(shapeIdsQuery, store)\n\t\t\t}\n\n\t\t\tif (diff.length === 0) return lastValue\n\n\t\t\tlet newValue: Record<TLParentId, TLShapeId[]> | null = null\n\n\t\t\tconst ensureNewArray = (parentId: TLParentId) => {\n\t\t\t\tif (!newValue) {\n\t\t\t\t\tnewValue = { ...lastValue }\n\t\t\t\t}\n\t\t\t\tif (!newValue[parentId]) {\n\t\t\t\t\tnewValue[parentId] = []\n\t\t\t\t} else if (newValue[parentId] === lastValue[parentId]) {\n\t\t\t\t\tnewValue[parentId] = [...newValue[parentId]!]\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst toSort = new Set<TLShapeId[]>()\n\n\t\t\tlet changes: RecordsDiff<TLRecord>\n\n\t\t\tfor (let i = 0, n = diff.length; i < n; i++) {\n\t\t\t\tchanges = diff[i]\n\n\t\t\t\t// Iterate through the added shapes, add them to the new value and mark them for sorting\n\t\t\t\tfor (const record of Object.values(changes.added)) {\n\t\t\t\t\tif (!isShape(record)) continue\n\t\t\t\t\tensureNewArray(record.parentId)\n\t\t\t\t\tnewValue![record.parentId].push(record.id)\n\t\t\t\t\ttoSort.add(newValue![record.parentId])\n\t\t\t\t}\n\n\t\t\t\t// Iterate through the updated shapes, add them to their parents in the new value and mark them for sorting\n\t\t\t\tfor (const [from, to] of Object.values(changes.updated)) {\n\t\t\t\t\tif (!isShape(to)) continue\n\t\t\t\t\tif (!isShape(from)) continue\n\n\t\t\t\t\tif (from.parentId !== to.parentId) {\n\t\t\t\t\t\t// If the parents have changed, remove the new value from the old parent and add it to the new parent\n\t\t\t\t\t\tensureNewArray(from.parentId)\n\t\t\t\t\t\tensureNewArray(to.parentId)\n\t\t\t\t\t\tnewValue![from.parentId].splice(newValue![from.parentId].indexOf(to.id), 1)\n\t\t\t\t\t\tnewValue![to.parentId].push(to.id)\n\t\t\t\t\t\ttoSort.add(newValue![to.parentId])\n\t\t\t\t\t} else if (from.index !== to.index) {\n\t\t\t\t\t\t// If the parent is the same but the index has changed (e.g. if they've been reordered), update the parent's array at the new index\n\t\t\t\t\t\tensureNewArray(to.parentId)\n\t\t\t\t\t\tconst idx = newValue![to.parentId].indexOf(to.id)\n\t\t\t\t\t\tnewValue![to.parentId][idx] = to.id\n\t\t\t\t\t\ttoSort.add(newValue![to.parentId])\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Iterate through the removed shapes, remove them from their parents in new value\n\t\t\t\tfor (const record of Object.values(changes.removed)) {\n\t\t\t\t\tif (!isShape(record)) continue\n\t\t\t\t\tensureNewArray(record.parentId)\n\t\t\t\t\tnewValue![record.parentId].splice(newValue![record.parentId].indexOf(record.id), 1)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Sort the arrays that have been marked for sorting\n\t\t\tfor (const arr of toSort) {\n\t\t\t\t// It's possible that some of the shapes may be deleted. But in which case would this be so?\n\t\t\t\tconst shapesInArr = compact(arr.map((id) => store.get(id)))\n\t\t\t\tshapesInArr.sort(sortByIndex)\n\t\t\t\tarr.splice(0, arr.length, ...shapesInArr.map((shape) => shape.id))\n\t\t\t}\n\n\t\t\treturn newValue ?? lastValue\n\t\t}\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AAEjE,sBAA2E;AAC3E,mBAAqC;AAIrC,SAAS,YACR,eACA,OACC;AACD,QAAM,SAAwC,CAAC;AAC/C,QAAM,WAAW,cAAc,IAAI;AACnC,QAAM,SAAS,MAAM,SAAS,IAAI;AAClC,WAAS,QAAQ,CAAC,OAAO,OAAO,KAAK,MAAM,IAAI,EAAE,CAAE,CAAC;AAGpD,SAAO,KAAK,wBAAW;AAGvB,SAAO,QAAQ,CAAC,UAAU;AACzB,QAAI,CAAC,OAAO,MAAM,QAAQ,GAAG;AAC5B,aAAO,MAAM,QAAQ,IAAI,CAAC;AAAA,IAC3B;AACA,WAAO,MAAM,QAAQ,EAAE,KAAK,MAAM,EAAE;AAAA,EACrC,CAAC;AAED,SAAO;AACR;AAEO,MAAM,oBAAoB,CAAC,UAAmB;AACpD,QAAM,gBAAgB,MAAM,MAAM,IAAa,OAAO;AACtD,QAAM,eAAe,MAAM,MAAM,cAAc,OAAO;AAEtD,aAAO;AAAA,IACN;AAAA,IACA,CAAC,WAAW,sBAAsB;AACjC,cAAI,8BAAgB,S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,GAAG,QAAQ,EAAE,KAAK,GAAG,EAAE;AACjC,mBAAO,IAAI,SAAU,GAAG,QAAQ,CAAC;AAAA,UAClC,WAAW,KAAK,UAAU,GAAG,OAAO;AAEnC,2BAAe,GAAG,QAAQ;AAC1B,kBAAM,MAAM,SAAU,GAAG,QAAQ,EAAE,QAAQ,GAAG,EAAE;AAChD,qBAAU,GAAG,QAAQ,EAAE,GAAG,IAAI,GAAG;AACjC,mBAAO,IAAI,SAAU,GAAG,QAAQ,CAAC;AAAA,UAClC;AAAA,QACD;AAGA,mBAAW,UAAU,OAAO,OAAO,QAAQ,OAAO,GAAG;AACpD,cAAI,KAAC,yBAAQ,MAAM,EAAG;AACtB,yBAAe,OAAO,QAAQ;AAC9B,mBAAU,OAAO,QAAQ,EAAE,OAAO,SAAU,OAAO,QAAQ,EAAE,QAAQ,OAAO,EAAE,GAAG,CAAC;AAAA,QACnF;AAAA,MACD;AAGA,iBAAW,OAAO,QAAQ;AAEzB,cAAM,kBAAc,sBAAQ,IAAI,IAAI,CAAC,OAAO,MAAM,IAAI,EAAE,CAAC,CAAC;AAC1D,oBAAY,KAAK,wBAAW;AAC5B,YAAI,OAAO,GAAG,IAAI,QAAQ,GAAG,YAAY,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC;AAAA,MAClE;AAEA,aAAO,YAAY;AAAA,IACpB;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -68,7 +68,7 @@ __export(ClickManager_exports, {
|
|
|
68
68
|
});
|
|
69
69
|
module.exports = __toCommonJS(ClickManager_exports);
|
|
70
70
|
var import_utils = require("@tldraw/utils");
|
|
71
|
-
var import_Vec = require("
|
|
71
|
+
var import_Vec = require("../../../primitives/Vec");
|
|
72
72
|
var _cancelDoubleClickTimeout_dec, __getClickTimeout_dec, _init;
|
|
73
73
|
const MAX_CLICK_DISTANCE = 40;
|
|
74
74
|
__getClickTimeout_dec = [import_utils.bind], _cancelDoubleClickTimeout_dec = [import_utils.bind];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/editor/managers/ClickManager/ClickManager.ts"],
|
|
4
|
+
"sourcesContent": ["import { bind, uniqueId } from '@tldraw/utils'\nimport { Vec } from '../../../primitives/Vec'\nimport type { Editor } from '../../Editor'\nimport { TLClickEventInfo, TLPointerEventInfo } from '../../types/event-types'\n\n/** @public */\nexport type TLClickState =\n\t| 'idle'\n\t| 'pendingDouble'\n\t| 'pendingTriple'\n\t| 'pendingQuadruple'\n\t| 'pendingOverflow'\n\t| 'overflow'\n\nconst MAX_CLICK_DISTANCE = 40\n\n/** @public */\nexport class ClickManager {\n\tconstructor(public editor: Editor) {}\n\n\tprivate _clickId = ''\n\n\tprivate _clickTimeout?: any\n\n\tprivate _clickScreenPoint?: Vec\n\n\tprivate _previousScreenPoint?: Vec\n\n\t@bind\n\t_getClickTimeout(state: TLClickState, id = uniqueId()) {\n\t\tthis._clickId = id\n\t\tclearTimeout(this._clickTimeout)\n\t\tthis._clickTimeout = this.editor.timers.setTimeout(\n\t\t\t() => {\n\t\t\t\tif (this._clickState === state && this._clickId === id) {\n\t\t\t\t\tswitch (this._clickState) {\n\t\t\t\t\t\tcase 'pendingTriple': {\n\t\t\t\t\t\t\tthis.editor.dispatch({\n\t\t\t\t\t\t\t\t...this.lastPointerInfo,\n\t\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\t\tname: 'double_click',\n\t\t\t\t\t\t\t\tphase: 'settle',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'pendingQuadruple': {\n\t\t\t\t\t\t\tthis.editor.dispatch({\n\t\t\t\t\t\t\t\t...this.lastPointerInfo,\n\t\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\t\tname: 'triple_click',\n\t\t\t\t\t\t\t\tphase: 'settle',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'pendingOverflow': {\n\t\t\t\t\t\t\tthis.editor.dispatch({\n\t\t\t\t\t\t\t\t...this.lastPointerInfo,\n\t\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\t\tname: 'quadruple_click',\n\t\t\t\t\t\t\t\tphase: 'settle',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t// noop\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._clickState = 'idle'\n\t\t\t\t}\n\t\t\t},\n\t\t\tstate === 'idle' || state === 'pendingDouble'\n\t\t\t\t? this.editor.options.doubleClickDurationMs\n\t\t\t\t: this.editor.options.multiClickDurationMs\n\t\t)\n\t}\n\n\t/**\n\t * The current click state.\n\t *\n\t * @internal\n\t */\n\tprivate _clickState?: TLClickState = 'idle'\n\n\t/**\n\t * The current click state.\n\t *\n\t * @public\n\t */\n\t// eslint-disable-next-line no-restricted-syntax\n\tget clickState() {\n\t\treturn this._clickState\n\t}\n\n\tlastPointerInfo = {} as TLPointerEventInfo\n\n\thandlePointerEvent(info: TLPointerEventInfo): TLPointerEventInfo | TLClickEventInfo {\n\t\tswitch (info.name) {\n\t\t\tcase 'pointer_down': {\n\t\t\t\tif (!this._clickState) return info\n\t\t\t\tthis._clickScreenPoint = Vec.From(info.point)\n\n\t\t\t\tif (\n\t\t\t\t\tthis._previousScreenPoint &&\n\t\t\t\t\tVec.Dist2(this._previousScreenPoint, this._clickScreenPoint) > MAX_CLICK_DISTANCE ** 2\n\t\t\t\t) {\n\t\t\t\t\tthis._clickState = 'idle'\n\t\t\t\t}\n\n\t\t\t\tthis._previousScreenPoint = this._clickScreenPoint\n\n\t\t\t\tthis.lastPointerInfo = info\n\n\t\t\t\tswitch (this._clickState) {\n\t\t\t\t\tcase 'pendingDouble': {\n\t\t\t\t\t\tthis._clickState = 'pendingTriple'\n\t\t\t\t\t\tthis._clickTimeout = this._getClickTimeout(this._clickState)\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\tname: 'double_click',\n\t\t\t\t\t\t\tphase: 'down',\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcase 'pendingTriple': {\n\t\t\t\t\t\tthis._clickState = 'pendingQuadruple'\n\t\t\t\t\t\tthis._clickTimeout = this._getClickTimeout(this._clickState)\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\tname: 'triple_click',\n\t\t\t\t\t\t\tphase: 'down',\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcase 'pendingQuadruple': {\n\t\t\t\t\t\tthis._clickState = 'pendingOverflow'\n\t\t\t\t\t\tthis._clickTimeout = this._getClickTimeout(this._clickState)\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\tname: 'quadruple_click',\n\t\t\t\t\t\t\tphase: 'down',\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcase 'idle': {\n\t\t\t\t\t\tthis._clickState = 'pendingDouble'\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'pendingOverflow': {\n\t\t\t\t\t\tthis._clickState = 'overflow'\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\t// overflow\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis._clickTimeout = this._getClickTimeout(this._clickState)\n\t\t\t\treturn info\n\t\t\t}\n\t\t\tcase 'pointer_up': {\n\t\t\t\tif (!this._clickState) return info\n\t\t\t\tthis._clickScreenPoint = Vec.From(info.point)\n\n\t\t\t\tswitch (this._clickState) {\n\t\t\t\t\tcase 'pendingTriple': {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...this.lastPointerInfo,\n\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\tname: 'double_click',\n\t\t\t\t\t\t\tphase: 'up',\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcase 'pendingQuadruple': {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...this.lastPointerInfo,\n\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\tname: 'triple_click',\n\t\t\t\t\t\t\tphase: 'up',\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcase 'pendingOverflow': {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...this.lastPointerInfo,\n\t\t\t\t\t\t\ttype: 'click',\n\t\t\t\t\t\t\tname: 'quadruple_click',\n\t\t\t\t\t\t\tphase: 'up',\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\t// idle, pendingDouble, overflow\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn info\n\t\t\t}\n\t\t\tcase 'pointer_move': {\n\t\t\t\tif (\n\t\t\t\t\tthis._clickState !== 'idle' &&\n\t\t\t\t\tthis._clickScreenPoint &&\n\t\t\t\t\tVec.Dist2(this._clickScreenPoint, this.editor.inputs.currentScreenPoint) >\n\t\t\t\t\t\t(this.editor.getInstanceState().isCoarsePointer\n\t\t\t\t\t\t\t? this.editor.options.coarseDragDistanceSquared\n\t\t\t\t\t\t\t: this.editor.options.dragDistanceSquared)\n\t\t\t\t) {\n\t\t\t\t\tthis.cancelDoubleClickTimeout()\n\t\t\t\t}\n\t\t\t\treturn info\n\t\t\t}\n\t\t}\n\t\treturn info\n\t}\n\n\t/**\n\t * Cancel the double click timeout.\n\t *\n\t * @internal\n\t */\n\t@bind\n\tcancelDoubleClickTimeout() {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Y;AAAN,2BAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist-cjs/lib/editor/managers/{EdgeScrollManager.js → EdgeScrollManager/EdgeScrollManager.js}
RENAMED
|
@@ -21,8 +21,8 @@ __export(EdgeScrollManager_exports, {
|
|
|
21
21
|
EdgeScrollManager: () => EdgeScrollManager
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(EdgeScrollManager_exports);
|
|
24
|
-
var import_Vec = require("
|
|
25
|
-
var import_easings = require("
|
|
24
|
+
var import_Vec = require("../../../primitives/Vec");
|
|
25
|
+
var import_easings = require("../../../primitives/easings");
|
|
26
26
|
class EdgeScrollManager {
|
|
27
27
|
constructor(editor) {
|
|
28
28
|
this.editor = editor;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts"],
|
|
4
|
+
"sourcesContent": ["import { Vec } from '../../../primitives/Vec'\nimport { EASINGS } from '../../../primitives/easings'\nimport { Editor } from '../../Editor'\n\n/** @public */\nexport class EdgeScrollManager {\n\tconstructor(public editor: Editor) {}\n\n\tprivate _isEdgeScrolling = false\n\tprivate _edgeScrollDuration = -1\n\n\t/**\n\t * Update the camera position when the mouse is close to the edge of the screen.\n\t * Run this on every tick when in a state where edge scrolling is enabled.\n\t *\n\t * @public\n\t */\n\tupdateEdgeScrolling(elapsed: number) {\n\t\tconst { editor } = this\n\t\tconst edgeScrollProximityFactor = this.getEdgeScroll()\n\t\tif (edgeScrollProximityFactor.x === 0 && edgeScrollProximityFactor.y === 0) {\n\t\t\tif (this._isEdgeScrolling) {\n\t\t\t\tthis._isEdgeScrolling = false\n\t\t\t\tthis._edgeScrollDuration = 0\n\t\t\t}\n\t\t} else {\n\t\t\tif (!this._isEdgeScrolling) {\n\t\t\t\tthis._isEdgeScrolling = true\n\t\t\t\tthis._edgeScrollDuration = 0\n\t\t\t}\n\t\t\tthis._edgeScrollDuration += elapsed\n\t\t\tif (this._edgeScrollDuration > editor.options.edgeScrollDelay) {\n\t\t\t\tconst eased =\n\t\t\t\t\teditor.options.edgeScrollEaseDuration > 0\n\t\t\t\t\t\t? EASINGS.easeInCubic(\n\t\t\t\t\t\t\t\tMath.min(\n\t\t\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t\t\tthis._edgeScrollDuration /\n\t\t\t\t\t\t\t\t\t\t(editor.options.edgeScrollDelay + editor.options.edgeScrollEaseDuration)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: 1\n\t\t\t\tthis.moveCameraWhenCloseToEdge({\n\t\t\t\t\tx: edgeScrollProximityFactor.x * eased,\n\t\t\t\t\ty: edgeScrollProximityFactor.y * eased,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to get the scroll proximity factor for a given position.\n\t * @param position - The mouse position on the axis.\n\t * @param dimension - The component dimension on the axis.\n\t * @param isCoarse - Whether the pointer is coarse.\n\t * @param insetStart - Whether the pointer is inset at the start of the axis.\n\t * @param insetEnd - Whether the pointer is inset at the end of the axis.\n\t * @internal\n\t */\n\tprivate getEdgeProximityFactors(\n\t\tposition: number,\n\t\tdimension: number,\n\t\tisCoarse: boolean,\n\t\tinsetStart: boolean,\n\t\tinsetEnd: boolean\n\t) {\n\t\tconst { editor } = this\n\t\tconst dist = editor.options.edgeScrollDistance\n\t\tconst pw = isCoarse ? editor.options.coarsePointerWidth : 0 // pointer width\n\t\tconst pMin = position - pw\n\t\tconst pMax = position + pw\n\t\tconst min = insetStart ? 0 : dist\n\t\tconst max = insetEnd ? dimension : dimension - dist\n\t\tif (pMin < min) {\n\t\t\treturn Math.min(1, (min - pMin) / dist)\n\t\t} else if (pMax > max) {\n\t\t\treturn -Math.min(1, (pMax - max) / dist)\n\t\t}\n\t\treturn 0\n\t}\n\n\tprivate getEdgeScroll() {\n\t\tconst { editor } = this\n\t\tconst {\n\t\t\tinputs: {\n\t\t\t\tcurrentScreenPoint: { x, y },\n\t\t\t},\n\t\t} = editor\n\t\tconst screenBounds = editor.getViewportScreenBounds()\n\n\t\tconst {\n\t\t\tisCoarsePointer,\n\t\t\tinsets: [t, r, b, l],\n\t\t} = editor.getInstanceState()\n\t\tconst proximityFactorX = this.getEdgeProximityFactors(x, screenBounds.w, isCoarsePointer, l, r)\n\t\tconst proximityFactorY = this.getEdgeProximityFactors(y, screenBounds.h, isCoarsePointer, t, b)\n\n\t\treturn {\n\t\t\tx: proximityFactorX,\n\t\t\ty: proximityFactorY,\n\t\t}\n\t}\n\n\t/**\n\t * Moves the camera when the mouse is close to the edge of the screen.\n\t * @public\n\t */\n\tprivate moveCameraWhenCloseToEdge(proximityFactor: { x: number; y: number }) {\n\t\tconst { editor } = this\n\t\tif (!editor.inputs.isDragging || editor.inputs.isPanning || editor.getCameraOptions().isLocked)\n\t\t\treturn\n\n\t\tif (proximityFactor.x === 0 && proximityFactor.y === 0) return\n\n\t\tconst screenBounds = editor.getViewportScreenBounds()\n\n\t\t// Determines how much the speed is affected by the screen size\n\t\tconst screenSizeFactorX = screenBounds.w < 1000 ? 0.612 : 1\n\t\tconst screenSizeFactorY = screenBounds.h < 1000 ? 0.612 : 1\n\n\t\t// Determines the base speed of the scroll\n\t\tconst zoomLevel = editor.getZoomLevel()\n\t\tconst pxSpeed = editor.user.getEdgeScrollSpeed() * editor.options.edgeScrollSpeed\n\t\tconst scrollDeltaX = (pxSpeed * proximityFactor.x * screenSizeFactorX) / zoomLevel\n\t\tconst scrollDeltaY = (pxSpeed * proximityFactor.y * screenSizeFactorY) / zoomLevel\n\n\t\t// update the camera\n\t\tconst { x, y, z } = editor.getCamera()\n\t\teditor.setCamera(new Vec(x + scrollDeltaX, y + scrollDeltaY, z))\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoB;AACpB,qB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ACrC,WAAO,UAAU,IAAI,eAAI,IAAI,cAAc,IAAI,cAAc,CAAC,CAAC;AAAA,EAChE;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -62,6 +62,8 @@ class FocusManager {
|
|
|
62
62
|
}
|
|
63
63
|
handleKeyDown(keyEvent) {
|
|
64
64
|
const container = this.editor.getContainer();
|
|
65
|
+
if (this.editor.isIn("select.editing_shape")) return;
|
|
66
|
+
if (document.activeElement === container && this.editor.getSelectedShapeIds().length > 0) return;
|
|
65
67
|
if (["Tab", "ArrowUp", "ArrowDown"].includes(keyEvent.key)) {
|
|
66
68
|
container.classList.remove("tl-container__no-focus-ring");
|
|
67
69
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/editor/managers/FocusManager/FocusManager.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Editor } from '../../Editor'\n\n/**\n * A manager for ensuring correct focus across the editor.\n * It will listen for changes in the instance state to make sure the\n * container is focused when the editor is focused.\n * Also, it will make sure that the focus is on things like text\n * labels when the editor is in editing mode.\n *\n * @internal\n */\nexport class FocusManager {\n\tprivate disposeSideEffectListener?: () => void\n\n\tconstructor(\n\t\tpublic editor: Editor,\n\t\tautoFocus?: boolean\n\t) {\n\t\tthis.disposeSideEffectListener = editor.sideEffects.registerAfterChangeHandler(\n\t\t\t'instance',\n\t\t\t(prev, next) => {\n\t\t\t\tif (prev.isFocused !== next.isFocused) {\n\t\t\t\t\tthis.updateContainerClass()\n\t\t\t\t}\n\t\t\t}\n\t\t)\n\n\t\tconst currentFocusState = editor.getInstanceState().isFocused\n\t\tif (autoFocus !== currentFocusState) {\n\t\t\teditor.updateInstanceState({ isFocused: !!autoFocus })\n\t\t}\n\t\tthis.updateContainerClass()\n\n\t\tdocument.body.addEventListener('keydown', this.handleKeyDown.bind(this))\n\t\tdocument.body.addEventListener('mousedown', this.handleMouseDown.bind(this))\n\t}\n\n\t/**\n\t * The editor's focus state and the container's focus state\n\t * are not necessarily always in sync. For that reason we\n\t * can't rely on the css `:focus` or `:focus-within` selectors to style the\n\t * editor when it is in focus.\n\t *\n\t * For that reason we synchronize the editor's focus state with a\n\t * special class on the container: tl-container__focused\n\t */\n\tprivate updateContainerClass() {\n\t\tconst container = this.editor.getContainer()\n\t\tconst instanceState = this.editor.getInstanceState()\n\n\t\tif (instanceState.isFocused) {\n\t\t\tcontainer.classList.add('tl-container__focused')\n\t\t} else {\n\t\t\tcontainer.classList.remove('tl-container__focused')\n\t\t}\n\t\tcontainer.classList.add('tl-container__no-focus-ring')\n\t}\n\n\tprivate handleKeyDown(keyEvent: KeyboardEvent) {\n\t\tconst container = this.editor.getContainer()\n\t\tif (this.editor.isIn('select.editing_shape')) return\n\t\tif (document.activeElement === container && this.editor.getSelectedShapeIds().length > 0) return\n\t\tif (['Tab', 'ArrowUp', 'ArrowDown'].includes(keyEvent.key)) {\n\t\t\tcontainer.classList.remove('tl-container__no-focus-ring')\n\t\t}\n\t}\n\n\tprivate handleMouseDown() {\n\t\tconst container = this.editor.getContainer()\n\t\tcontainer.classList.add('tl-container__no-focus-ring')\n\t}\n\n\tfocus() {\n\t\tthis.editor.getContainer().focus()\n\t}\n\n\tblur() {\n\t\tthis.editor.complete() // stop any interaction\n\t\tthis.editor.getContainer().blur() // blur the container\n\t}\n\n\tdispose() {\n\t\tdocument.body.removeEventListener('keydown', this.handleKeyDown.bind(this))\n\t\tdocument.body.removeEventListener('mousedown', this.handleMouseDown.bind(this))\n\t\tthis.disposeSideEffectListener?.()\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAM,aAAa;AAAA,EAGzB,YACQ,QACP,WACC;AAFM;AAGP,SAAK,4BAA4B,OAAO,YAAY;AAAA,MACnD;AAAA,MACA,CAAC,MAAM,SAAS;AACf,YAAI,KAAK,cAAc,KAAK,WAAW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AAE,KAAK;AAAA,EACjC;AAAA,EAEA,UAAU;AACT,aAAS,KAAK,oBAAoB,WAAW,KAAK,cAAc,KAAK,IAAI,CAAC;AAC1E,aAAS,KAAK,oBAAoB,aAAa,KAAK,gBAAgB,KAAK,IAAI,CAAC;AAC9E,SAAK,4BAA4B;AAAA,EAClC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -34,7 +34,10 @@ class FontManager {
|
|
|
34
34
|
const shapeUtil = this.editor.getShapeUtil(shape);
|
|
35
35
|
return shapeUtil.getFontFaces(shape);
|
|
36
36
|
},
|
|
37
|
-
{
|
|
37
|
+
{
|
|
38
|
+
areResultsEqual: import_utils.areArraysShallowEqual,
|
|
39
|
+
areRecordsEqual: (a, b) => a.props === b.props && a.meta === b.meta
|
|
40
|
+
}
|
|
38
41
|
);
|
|
39
42
|
this.shapeFontLoadStateCache = editor.store.createCache(
|
|
40
43
|
(id) => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/editor/managers/FontManager/FontManager.ts"],
|
|
4
|
+
"sourcesContent": ["import { computed, EMPTY_ARRAY, transact } from '@tldraw/state'\nimport { AtomMap } from '@tldraw/store'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport {\n\tareArraysShallowEqual,\n\tcompact,\n\tFileHelpers,\n\tmapObjectMapValues,\n\tobjectMapEntries,\n} from '@tldraw/utils'\nimport { Editor } from '../../Editor'\n\n/**\n * Represents the `src` property of a {@link TLFontFace}.\n * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src | `src`} for details of the properties here.\n * @public\n */\nexport interface TLFontFaceSource {\n\t/**\n\t * A URL from which to load the font. If the value here is a key in\n\t * {@link tldraw#TLEditorAssetUrls.fonts}, the value from there will be used instead.\n\t */\n\turl: string\n\tformat?: string\n\ttech?: string\n}\n\n/**\n * A font face that can be used in the editor. The properties of this are largely the same as the\n * ones in the\n * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face | css `@font-face` rule}.\n * @public\n */\nexport interface TLFontFace {\n\t/**\n\t * How this font can be referred to in CSS.\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-family | `font-family`}.\n\t */\n\treadonly family: string\n\t/**\n\t * The source of the font. This\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src | `src`}.\n\t */\n\treadonly src: TLFontFaceSource\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/ascent-override | `ascent-override`}.\n\t */\n\treadonly ascentOverride?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/descent-override | `descent-override`}.\n\t */\n\treadonly descentOverride?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch | `font-stretch`}.\n\t */\n\treadonly stretch?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-style | `font-style`}.\n\t */\n\treadonly style?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-weight | `font-weight`}.\n\t */\n\treadonly weight?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings | `font-feature-settings`}.\n\t */\n\treadonly featureSettings?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/line-gap-override | `line-gap-override`}.\n\t */\n\treadonly lineGapOverride?: string\n\t/**\n\t * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range | `unicode-range`}.\n\t */\n\treadonly unicodeRange?: string\n}\n\ninterface FontState {\n\treadonly state: 'loading' | 'ready' | 'error'\n\treadonly instance: FontFace\n\treadonly loadingPromise: Promise<void>\n}\n\n/** @public */\nexport class FontManager {\n\tconstructor(\n\t\tprivate readonly editor: Editor,\n\t\tprivate readonly assetUrls?: { [key: string]: string | undefined }\n\t) {\n\t\tthis.shapeFontFacesCache = editor.store.createComputedCache(\n\t\t\t'shape font faces',\n\t\t\t(shape: TLShape) => {\n\t\t\t\tconst shapeUtil = this.editor.getShapeUtil(shape)\n\t\t\t\treturn shapeUtil.getFontFaces(shape)\n\t\t\t},\n\t\t\t{\n\t\t\t\tareResultsEqual: areArraysShallowEqual,\n\t\t\t\tareRecordsEqual: (a, b) => a.props === b.props && a.meta === b.meta,\n\t\t\t}\n\t\t)\n\n\t\tthis.shapeFontLoadStateCache = editor.store.createCache<(FontState | null)[], TLShape>(\n\t\t\t(id: TLShapeId) => {\n\t\t\t\tconst fontFacesComputed = computed('font faces', () => this.getShapeFontFaces(id))\n\t\t\t\treturn computed(\n\t\t\t\t\t'font load state',\n\t\t\t\t\t() => {\n\t\t\t\t\t\tconst states = fontFacesComputed.get().map((face) => this.getFontState(face))\n\t\t\t\t\t\treturn states\n\t\t\t\t\t},\n\t\t\t\t\t{ isEqual: areArraysShallowEqual }\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\t}\n\n\tprivate readonly shapeFontFacesCache\n\tprivate readonly shapeFontLoadStateCache\n\n\tgetShapeFontFaces(shape: TLShape | TLShapeId): TLFontFace[] {\n\t\tconst shapeId = typeof shape === 'string' ? shape : shape.id\n\t\treturn this.shapeFontFacesCache.get(shapeId) ?? EMPTY_ARRAY\n\t}\n\n\ttrackFontsForShape(shape: TLShape | TLShapeId) {\n\t\tconst shapeId = typeof shape === 'string' ? shape : shape.id\n\t\tthis.shapeFontLoadStateCache.get(shapeId)\n\t}\n\n\tasync loadRequiredFontsForCurrentPage(limit = Infinity) {\n\t\tconst neededFonts = new Set<TLFontFace>()\n\t\tfor (const shapeId of this.editor.getCurrentPageShapeIds()) {\n\t\t\tfor (const font of this.getShapeFontFaces(this.editor.getShape(shapeId)!)) {\n\t\t\t\tneededFonts.add(font)\n\t\t\t}\n\t\t}\n\n\t\tif (neededFonts.size > limit) {\n\t\t\treturn\n\t\t}\n\n\t\tconst promises = Array.from(neededFonts, (font) => this.ensureFontIsLoaded(font))\n\t\tawait Promise.all(promises)\n\t}\n\n\tprivate readonly fontStates = new AtomMap<TLFontFace, FontState>('font states')\n\tprivate getFontState(font: TLFontFace): FontState | null {\n\t\treturn this.fontStates.get(font) ?? null\n\t}\n\n\tensureFontIsLoaded(font: TLFontFace): Promise<void> {\n\t\tconst existingState = this.getFontState(font)\n\t\tif (existingState) return existingState.loadingPromise\n\n\t\tconst instance = this.findOrCreateFontFace(font)\n\t\tconst state: FontState = {\n\t\t\tstate: 'loading',\n\t\t\tinstance,\n\t\t\tloadingPromise: instance\n\t\t\t\t.load()\n\t\t\t\t.then(() => {\n\t\t\t\t\tdocument.fonts.add(instance)\n\t\t\t\t\tthis.fontStates.update(font, (s) => ({ ...s, state: 'ready' }))\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(err)\n\t\t\t\t\tthis.fontStates.update(font, (s) => ({ ...s, state: 'error' }))\n\t\t\t\t}),\n\t\t}\n\n\t\tthis.fontStates.set(font, state)\n\t\treturn state.loadingPromise\n\t}\n\n\tprivate fontsToLoad = new Set<TLFontFace>()\n\trequestFonts(fonts: TLFontFace[]) {\n\t\tif (!this.fontsToLoad.size) {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (this.editor.isDisposed) return\n\t\t\t\tconst toLoad = this.fontsToLoad\n\t\t\t\tthis.fontsToLoad = new Set()\n\t\t\t\ttransact(() => {\n\t\t\t\t\tfor (const font of toLoad) {\n\t\t\t\t\t\tthis.ensureFontIsLoaded(font)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t}\n\t\tfor (const font of fonts) {\n\t\t\tthis.fontsToLoad.add(font)\n\t\t}\n\t}\n\n\tprivate findOrCreateFontFace(font: TLFontFace) {\n\t\tfor (const existing of document.fonts) {\n\t\t\tif (\n\t\t\t\texisting.family === font.family &&\n\t\t\t\tobjectMapEntries(defaultFontFaceDescriptors).every(\n\t\t\t\t\t([key, defaultValue]) => existing[key] === (font[key] ?? defaultValue)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn existing\n\t\t\t}\n\t\t}\n\n\t\tconst url = this.assetUrls?.[font.src.url] ?? font.src.url\n\t\tconst instance = new FontFace(font.family, `url(${JSON.stringify(url)})`, {\n\t\t\t...mapObjectMapValues(defaultFontFaceDescriptors, (key) => font[key]),\n\t\t\tdisplay: 'swap',\n\t\t})\n\n\t\tdocument.fonts.add(instance)\n\n\t\treturn instance\n\t}\n\n\tasync toEmbeddedCssDeclaration(font: TLFontFace) {\n\t\tconst url = this.assetUrls?.[font.src.url] ?? font.src.url\n\t\tconst dataUrl = await FileHelpers.urlToDataUrl(url)\n\n\t\tconst src = compact([\n\t\t\t`url(\"${dataUrl}\")`,\n\t\t\tfont.src.format ? `format(${font.src.format})` : null,\n\t\t\tfont.src.tech ? `tech(${font.src.tech})` : null,\n\t\t]).join(' ')\n\t\treturn compact([\n\t\t\t`@font-face {`,\n\t\t\t` font-family: \"${font.family}\";`,\n\t\t\tfont.ascentOverride ? ` ascent-override: ${font.ascentOverride};` : null,\n\t\t\tfont.descentOverride ? ` descent-override: ${font.descentOverride};` : null,\n\t\t\tfont.stretch ? ` font-stretch: ${font.stretch};` : null,\n\t\t\tfont.style ? ` font-style: ${font.style};` : null,\n\t\t\tfont.weight ? ` font-weight: ${font.weight};` : null,\n\t\t\tfont.featureSettings ? ` font-feature-settings: ${font.featureSettings};` : null,\n\t\t\tfont.lineGapOverride ? ` line-gap-override: ${font.lineGapOverride};` : null,\n\t\t\tfont.unicodeRange ? ` unicode-range: ${font.unicodeRange};` : null,\n\t\t\t` src: ${src};`,\n\t\t\t`}`,\n\t\t]).join('\\n')\n\t}\n}\n\n// From https://drafts.csswg.org/css-font-loading/#fontface-interface\nconst defaultFontFaceDescriptors = {\n\tstyle: 'normal',\n\tweight: 'normal',\n\tstretch: 'normal',\n\tunicodeRange: 'U+0-10FFFF',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AiB,sBAAsB,KAAK,cAAc,MAAM;AAAA,MACrE,KAAK,kBAAkB,uBAAuB,KAAK,eAAe,MAAM;AAAA,MACxE,KAAK,UAAU,mBAAmB,KAAK,OAAO,MAAM;AAAA,MACpD,KAAK,QAAQ,iBAAiB,KAAK,KAAK,MAAM;AAAA,MAC9C,KAAK,SAAS,kBAAkB,KAAK,MAAM,MAAM;AAAA,MACjD,KAAK,kBAAkB,4BAA4B,KAAK,eAAe,MAAM;AAAA,MAC7E,KAAK,kBAAkB,wBAAwB,KAAK,eAAe,MAAM;AAAA,MACzE,KAAK,eAAe,oBAAoB,KAAK,YAAY,MAAM;AAAA,MAC/D,UAAU,GAAG;AAAA,MACb;AAAA,IACD,CAAC,EAAE,KAAK,IAAI;AAAA,EACb;AACD;AAGA,MAAM,6BAA6B;AAAA,EAClC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,iBAAiB;AAClB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -18,13 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var HistoryManager_exports = {};
|
|
20
20
|
__export(HistoryManager_exports, {
|
|
21
|
-
HistoryManager: () => HistoryManager
|
|
21
|
+
HistoryManager: () => HistoryManager,
|
|
22
|
+
stack: () => stack
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(HistoryManager_exports);
|
|
24
25
|
var import_state = require("@tldraw/state");
|
|
25
26
|
var import_store = require("@tldraw/store");
|
|
26
27
|
var import_utils = require("@tldraw/utils");
|
|
27
|
-
var
|
|
28
|
+
var import_state2 = require("@tldraw/state");
|
|
28
29
|
var HistoryRecorderState = /* @__PURE__ */ ((HistoryRecorderState2) => {
|
|
29
30
|
HistoryRecorderState2["Recording"] = "recording";
|
|
30
31
|
HistoryRecorderState2["RecordingPreserveRedoStack"] = "recordingPreserveRedoStack";
|
|
@@ -39,8 +40,8 @@ class HistoryManager {
|
|
|
39
40
|
stacks = (0, import_state.atom)(
|
|
40
41
|
"HistoryManager.stacks",
|
|
41
42
|
{
|
|
42
|
-
undos:
|
|
43
|
-
redos:
|
|
43
|
+
undos: stack(),
|
|
44
|
+
redos: stack()
|
|
44
45
|
},
|
|
45
46
|
{
|
|
46
47
|
isEqual: (a, b) => a.undos === b.undos && a.redos === b.redos
|
|
@@ -55,7 +56,7 @@ class HistoryManager {
|
|
|
55
56
|
switch (this.state) {
|
|
56
57
|
case "recording" /* Recording */:
|
|
57
58
|
this.pendingDiff.apply(entry.changes);
|
|
58
|
-
this.stacks.update(({ undos }) => ({ undos, redos:
|
|
59
|
+
this.stacks.update(({ undos }) => ({ undos, redos: stack() }));
|
|
59
60
|
break;
|
|
60
61
|
case "recordingPreserveRedoStack" /* RecordingPreserveRedoStack */:
|
|
61
62
|
this.pendingDiff.apply(entry.changes);
|
|
@@ -246,7 +247,7 @@ class HistoryManager {
|
|
|
246
247
|
});
|
|
247
248
|
}
|
|
248
249
|
clear() {
|
|
249
|
-
this.stacks.set({ undos:
|
|
250
|
+
this.stacks.set({ undos: stack(), redos: stack() });
|
|
250
251
|
this.pendingDiff.clear();
|
|
251
252
|
}
|
|
252
253
|
/** @internal */
|
|
@@ -296,4 +297,61 @@ class PendingDiff {
|
|
|
296
297
|
return { diff: this.diff, isEmpty: this.isEmpty() };
|
|
297
298
|
}
|
|
298
299
|
}
|
|
300
|
+
function stack(items) {
|
|
301
|
+
if (items) {
|
|
302
|
+
let result = EMPTY_STACK_ITEM;
|
|
303
|
+
while (items.length) {
|
|
304
|
+
result = result.push(items.pop());
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
return EMPTY_STACK_ITEM;
|
|
309
|
+
}
|
|
310
|
+
class EmptyStackItem {
|
|
311
|
+
length = 0;
|
|
312
|
+
head = null;
|
|
313
|
+
tail = this;
|
|
314
|
+
push(head) {
|
|
315
|
+
return new StackItem(head, this);
|
|
316
|
+
}
|
|
317
|
+
toArray() {
|
|
318
|
+
return import_state2.EMPTY_ARRAY;
|
|
319
|
+
}
|
|
320
|
+
[Symbol.iterator]() {
|
|
321
|
+
return {
|
|
322
|
+
next() {
|
|
323
|
+
return { value: void 0, done: true };
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const EMPTY_STACK_ITEM = new EmptyStackItem();
|
|
329
|
+
class StackItem {
|
|
330
|
+
constructor(head, tail) {
|
|
331
|
+
this.head = head;
|
|
332
|
+
this.tail = tail;
|
|
333
|
+
this.length = tail.length + 1;
|
|
334
|
+
}
|
|
335
|
+
length;
|
|
336
|
+
push(head) {
|
|
337
|
+
return new StackItem(head, this);
|
|
338
|
+
}
|
|
339
|
+
toArray() {
|
|
340
|
+
return Array.from(this);
|
|
341
|
+
}
|
|
342
|
+
[Symbol.iterator]() {
|
|
343
|
+
let stack2 = this;
|
|
344
|
+
return {
|
|
345
|
+
next() {
|
|
346
|
+
if (stack2.length) {
|
|
347
|
+
const value = stack2.head;
|
|
348
|
+
stack2 = stack2.tail;
|
|
349
|
+
return { value, done: false };
|
|
350
|
+
} else {
|
|
351
|
+
return { value: void 0, done: true };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
299
357
|
//# sourceMappingURL=HistoryManager.js.map
|