@tldraw/editor 3.14.0-canary.d8a1c8c23469 → 3.14.0-canary.db789786fb06
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 +220 -117
- package/dist-cjs/index.js +11 -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 +132 -101
- 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/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} +67 -7
- 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 -10
- 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/tools/BaseBoxShapeTool/children/Pointing.js +10 -6
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
- 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/emit-types.js.map +1 -1
- 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 +13 -8
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- 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 -17
- 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 +6 -2
- 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/reparenting.js +232 -0
- package/dist-cjs/lib/utils/reparenting.js.map +7 -0
- 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 +220 -117
- package/dist-esm/index.mjs +15 -8
- 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 +132 -101
- 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/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} +63 -3
- 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 -10
- 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/tools/BaseBoxShapeTool/children/Pointing.mjs +10 -6
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
- 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 +13 -8
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- 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 -17
- 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 +6 -2
- 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/reparenting.mjs +216 -0
- package/dist-esm/lib/utils/reparenting.mjs.map +7 -0
- 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 +442 -492
- package/package.json +8 -9
- package/src/index.ts +20 -7
- package/src/lib/config/TLSessionStateSnapshot.ts +1 -1
- package/src/lib/editor/Editor.test.ts +252 -3
- package/src/lib/editor/Editor.ts +150 -109
- 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} +1 -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} +76 -3
- 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 +57 -16
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +8 -0
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +22 -17
- package/src/lib/editor/tools/StateNode.ts +3 -3
- package/src/lib/editor/types/emit-types.ts +4 -0
- 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 +13 -8
- 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 -18
- package/src/lib/primitives/geometry/Ellipse2d.ts +12 -13
- package/src/lib/primitives/geometry/Geometry2d.ts +7 -2
- 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/reparenting.ts +383 -0
- 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
- /package/dist-cjs/lib/editor/managers/{FocusManager.js → FocusManager/FocusManager.js} +0 -0
- /package/dist-esm/lib/editor/managers/{FocusManager.mjs → FocusManager/FocusManager.mjs} +0 -0
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -148,16 +148,16 @@ import { bindingsIndex } from './derivations/bindingsIndex'
|
|
|
148
148
|
import { notVisibleShapes } from './derivations/notVisibleShapes'
|
|
149
149
|
import { parentsToChildren } from './derivations/parentsToChildren'
|
|
150
150
|
import { deriveShapeIdsInCurrentPage } from './derivations/shapeIdsInCurrentPage'
|
|
151
|
-
import { ClickManager } from './managers/ClickManager'
|
|
152
|
-
import { EdgeScrollManager } from './managers/EdgeScrollManager'
|
|
153
|
-
import { FocusManager } from './managers/FocusManager'
|
|
154
|
-
import { FontManager } from './managers/FontManager'
|
|
155
|
-
import { HistoryManager } from './managers/HistoryManager'
|
|
156
|
-
import { ScribbleManager } from './managers/ScribbleManager'
|
|
151
|
+
import { ClickManager } from './managers/ClickManager/ClickManager'
|
|
152
|
+
import { EdgeScrollManager } from './managers/EdgeScrollManager/EdgeScrollManager'
|
|
153
|
+
import { FocusManager } from './managers/FocusManager/FocusManager'
|
|
154
|
+
import { FontManager } from './managers/FontManager/FontManager'
|
|
155
|
+
import { HistoryManager } from './managers/HistoryManager/HistoryManager'
|
|
156
|
+
import { ScribbleManager } from './managers/ScribbleManager/ScribbleManager'
|
|
157
157
|
import { SnapManager } from './managers/SnapManager/SnapManager'
|
|
158
|
-
import { TextManager } from './managers/TextManager'
|
|
159
|
-
import { TickManager } from './managers/TickManager'
|
|
160
|
-
import { UserPreferencesManager } from './managers/UserPreferencesManager'
|
|
158
|
+
import { TextManager } from './managers/TextManager/TextManager'
|
|
159
|
+
import { TickManager } from './managers/TickManager/TickManager'
|
|
160
|
+
import { UserPreferencesManager } from './managers/UserPreferencesManager/UserPreferencesManager'
|
|
161
161
|
import { ShapeUtil, TLGeometryOpts, TLResizeMode } from './shapes/ShapeUtil'
|
|
162
162
|
import { RootState } from './tools/RootState'
|
|
163
163
|
import { StateNode, TLStateNodeConstructor } from './tools/StateNode'
|
|
@@ -328,7 +328,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
328
328
|
this.store = store
|
|
329
329
|
this.history = new HistoryManager<TLRecord>({
|
|
330
330
|
store,
|
|
331
|
-
annotateError: (error) => {
|
|
331
|
+
annotateError: (error: any) => {
|
|
332
332
|
this.annotateError(error, { origin: 'history.batch', willCrashApp: true })
|
|
333
333
|
this.crash(error)
|
|
334
334
|
},
|
|
@@ -348,6 +348,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
348
348
|
this.getContainer = getContainer
|
|
349
349
|
|
|
350
350
|
this.textMeasure = new TextManager(this)
|
|
351
|
+
this.disposables.add(() => this.textMeasure.dispose())
|
|
352
|
+
|
|
351
353
|
this.fonts = new FontManager(this, fontAssetUrls)
|
|
352
354
|
|
|
353
355
|
this._tickManager = new TickManager(this)
|
|
@@ -512,6 +514,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
512
514
|
binding,
|
|
513
515
|
shapeBefore,
|
|
514
516
|
shapeAfter,
|
|
517
|
+
reason: 'self',
|
|
515
518
|
})
|
|
516
519
|
}
|
|
517
520
|
if (binding.toId === shapeAfter.id) {
|
|
@@ -519,6 +522,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
519
522
|
binding,
|
|
520
523
|
shapeBefore,
|
|
521
524
|
shapeAfter,
|
|
525
|
+
reason: 'self',
|
|
522
526
|
})
|
|
523
527
|
}
|
|
524
528
|
}
|
|
@@ -537,6 +541,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
537
541
|
binding,
|
|
538
542
|
shapeBefore: descendantShape,
|
|
539
543
|
shapeAfter: descendantShape,
|
|
544
|
+
reason: 'ancestry',
|
|
540
545
|
})
|
|
541
546
|
}
|
|
542
547
|
if (binding.toId === descendantShape.id) {
|
|
@@ -544,6 +549,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
544
549
|
binding,
|
|
545
550
|
shapeBefore: descendantShape,
|
|
546
551
|
shapeAfter: descendantShape,
|
|
552
|
+
reason: 'ancestry',
|
|
547
553
|
})
|
|
548
554
|
}
|
|
549
555
|
}
|
|
@@ -2116,6 +2122,20 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2116
2122
|
return this.getShapesPageBounds(this.getSelectedShapeIds())
|
|
2117
2123
|
}
|
|
2118
2124
|
|
|
2125
|
+
/**
|
|
2126
|
+
* The bounds of the selection bounding box in the current page space.
|
|
2127
|
+
*
|
|
2128
|
+
* @readonly
|
|
2129
|
+
* @public
|
|
2130
|
+
*/
|
|
2131
|
+
getSelectionScreenBounds(): Box | undefined {
|
|
2132
|
+
const bounds = this.getSelectionPageBounds()
|
|
2133
|
+
if (!bounds) return undefined
|
|
2134
|
+
const { x, y } = this.pageToScreen(bounds.point)
|
|
2135
|
+
const zoom = this.getZoomLevel()
|
|
2136
|
+
return new Box(x, y, bounds.width * zoom, bounds.height * zoom)
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2119
2139
|
/**
|
|
2120
2140
|
* @internal
|
|
2121
2141
|
*/
|
|
@@ -3715,10 +3735,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
3715
3735
|
*/
|
|
3716
3736
|
@computed getViewportScreenCenter() {
|
|
3717
3737
|
const viewportScreenBounds = this.getViewportScreenBounds()
|
|
3718
|
-
return new Vec(
|
|
3719
|
-
viewportScreenBounds.midX - viewportScreenBounds.minX,
|
|
3720
|
-
viewportScreenBounds.midY - viewportScreenBounds.minY
|
|
3721
|
-
)
|
|
3738
|
+
return new Vec(viewportScreenBounds.w / 2, viewportScreenBounds.h / 2)
|
|
3722
3739
|
}
|
|
3723
3740
|
|
|
3724
3741
|
/**
|
|
@@ -4644,44 +4661,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4644
4661
|
)! as T
|
|
4645
4662
|
}
|
|
4646
4663
|
|
|
4647
|
-
private _shapePageGeometryCaches: Record<string, ComputedCache<Geometry2d, TLShape>> = {}
|
|
4648
|
-
|
|
4649
|
-
/**
|
|
4650
|
-
* Get the geometry of a shape in page-space.
|
|
4651
|
-
*
|
|
4652
|
-
* @example
|
|
4653
|
-
* ```ts
|
|
4654
|
-
* editor.getShapePageGeometry(myShape)
|
|
4655
|
-
* editor.getShapePageGeometry(myShapeId)
|
|
4656
|
-
* editor.getShapePageGeometry(myShapeId, { context: "arrow" })
|
|
4657
|
-
* ```
|
|
4658
|
-
*
|
|
4659
|
-
* @param shape - The shape (or shape id) to get the geometry for.
|
|
4660
|
-
* @param opts - Additional options about the request for geometry. Passed to {@link ShapeUtil.getGeometry}.
|
|
4661
|
-
*
|
|
4662
|
-
* @public
|
|
4663
|
-
*/
|
|
4664
|
-
getShapePageGeometry<T extends Geometry2d>(shape: TLShape | TLShapeId, opts?: TLGeometryOpts): T {
|
|
4665
|
-
const context = opts?.context ?? 'none'
|
|
4666
|
-
if (!this._shapePageGeometryCaches[context]) {
|
|
4667
|
-
this._shapePageGeometryCaches[context] = this.store.createComputedCache(
|
|
4668
|
-
'bounds',
|
|
4669
|
-
(shape) => {
|
|
4670
|
-
const geometry = this.getShapeGeometry(shape.id, opts)
|
|
4671
|
-
const pageTransform = this.getShapePageTransform(shape.id)
|
|
4672
|
-
return geometry.transform(pageTransform)
|
|
4673
|
-
},
|
|
4674
|
-
{
|
|
4675
|
-
// we only depend directly on the shape id, and changing geometry/transform will update us anyway
|
|
4676
|
-
areRecordsEqual: () => true,
|
|
4677
|
-
}
|
|
4678
|
-
)
|
|
4679
|
-
}
|
|
4680
|
-
return this._shapePageGeometryCaches[context].get(
|
|
4681
|
-
typeof shape === 'string' ? shape : shape.id
|
|
4682
|
-
)! as T
|
|
4683
|
-
}
|
|
4684
|
-
|
|
4685
4664
|
/** @internal */
|
|
4686
4665
|
@computed private _getShapeHandlesCache(): ComputedCache<TLHandle[] | undefined, TLShape> {
|
|
4687
4666
|
return this.store.createComputedCache(
|
|
@@ -4794,7 +4773,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4794
4773
|
/** @internal */
|
|
4795
4774
|
@computed private _getShapePageBoundsCache(): ComputedCache<Box, TLShape> {
|
|
4796
4775
|
return this.store.createComputedCache<Box, TLShape>('pageBoundsCache', (shape) => {
|
|
4797
|
-
|
|
4776
|
+
const pageTransform = this.getShapePageTransform(shape)
|
|
4777
|
+
if (!pageTransform) return undefined
|
|
4778
|
+
const geometry = this.getShapeGeometry(shape)
|
|
4779
|
+
return Box.FromPoints(pageTransform.applyToPoints(geometry.vertices))
|
|
4798
4780
|
})
|
|
4799
4781
|
}
|
|
4800
4782
|
|
|
@@ -4868,11 +4850,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4868
4850
|
if (frameAncestors.length === 0) return undefined
|
|
4869
4851
|
|
|
4870
4852
|
const pageMask = frameAncestors
|
|
4871
|
-
.map<Vec[] | undefined>(
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4853
|
+
.map<Vec[] | undefined>((s) => {
|
|
4854
|
+
// Apply the frame transform to the frame outline to get the frame outline in the current page space
|
|
4855
|
+
const geometry = this.getShapeGeometry(s.id)
|
|
4856
|
+
const pageTransform = this.getShapePageTransform(s.id)
|
|
4857
|
+
return pageTransform.applyToPoints(geometry.vertices)
|
|
4858
|
+
})
|
|
4876
4859
|
.reduce((acc, b) => {
|
|
4877
4860
|
if (!(b && acc)) return undefined
|
|
4878
4861
|
const intersection = intersectPolygonPolygon(acc, b)
|
|
@@ -5070,28 +5053,33 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5070
5053
|
*
|
|
5071
5054
|
* @public
|
|
5072
5055
|
*/
|
|
5073
|
-
isShapeOrAncestorLocked(shape?: TLShape): boolean
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
if (shape.isLocked) return true
|
|
5079
|
-
return this.isShapeOrAncestorLocked(this.getShapeParent(shape))
|
|
5056
|
+
isShapeOrAncestorLocked(shape?: TLShape | TLShapeId): boolean {
|
|
5057
|
+
const _shape = shape && this.getShape(shape)
|
|
5058
|
+
if (_shape === undefined) return false
|
|
5059
|
+
if (_shape.isLocked) return true
|
|
5060
|
+
return this.isShapeOrAncestorLocked(this.getShapeParent(_shape))
|
|
5080
5061
|
}
|
|
5081
5062
|
|
|
5063
|
+
/**
|
|
5064
|
+
* Get shapes that are outside of the viewport.
|
|
5065
|
+
*
|
|
5066
|
+
* @public
|
|
5067
|
+
*/
|
|
5082
5068
|
@computed
|
|
5083
|
-
|
|
5084
|
-
return
|
|
5069
|
+
getNotVisibleShapes() {
|
|
5070
|
+
return this._notVisibleShapes.get()
|
|
5085
5071
|
}
|
|
5086
5072
|
|
|
5073
|
+
private _notVisibleShapes = notVisibleShapes(this)
|
|
5074
|
+
|
|
5087
5075
|
/**
|
|
5088
|
-
* Get culled shapes.
|
|
5076
|
+
* Get culled shapes (those that should not render), taking into account which shapes are selected or editing.
|
|
5089
5077
|
*
|
|
5090
5078
|
* @public
|
|
5091
5079
|
*/
|
|
5092
5080
|
@computed
|
|
5093
5081
|
getCulledShapes() {
|
|
5094
|
-
const notVisibleShapes = this.
|
|
5082
|
+
const notVisibleShapes = this.getNotVisibleShapes()
|
|
5095
5083
|
const selectedShapeIds = this.getSelectedShapeIds()
|
|
5096
5084
|
const editingId = this.getEditingShapeId()
|
|
5097
5085
|
const culledShapes = new Set<TLShapeId>(notVisibleShapes)
|
|
@@ -5340,21 +5328,23 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5340
5328
|
* @example
|
|
5341
5329
|
* ```ts
|
|
5342
5330
|
* editor.getShapesAtPoint({ x: 100, y: 100 })
|
|
5343
|
-
* editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true,
|
|
5331
|
+
* editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, margin: 8 })
|
|
5344
5332
|
* ```
|
|
5345
5333
|
*
|
|
5346
5334
|
* @param point - The page point to test.
|
|
5347
5335
|
* @param opts - The options for the hit point testing.
|
|
5348
5336
|
*
|
|
5337
|
+
* @returns An array of shapes at the given point, sorted in reverse order of their absolute z-index (top-most shape first).
|
|
5338
|
+
*
|
|
5349
5339
|
* @public
|
|
5350
5340
|
*/
|
|
5351
5341
|
getShapesAtPoint(
|
|
5352
5342
|
point: VecLike,
|
|
5353
5343
|
opts = {} as { margin?: number; hitInside?: boolean }
|
|
5354
5344
|
): TLShape[] {
|
|
5355
|
-
return this.
|
|
5356
|
-
(shape) => !this.isShapeHidden(shape) && this.isPointInShape(shape, point, opts)
|
|
5357
|
-
|
|
5345
|
+
return this.getCurrentPageShapesSorted()
|
|
5346
|
+
.filter((shape) => !this.isShapeHidden(shape) && this.isPointInShape(shape, point, opts))
|
|
5347
|
+
.reverse()
|
|
5358
5348
|
}
|
|
5359
5349
|
|
|
5360
5350
|
/**
|
|
@@ -5538,7 +5528,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5538
5528
|
if (!id) return undefined
|
|
5539
5529
|
const freshShape = this.getShape(id)
|
|
5540
5530
|
if (freshShape === undefined || !isShapeId(freshShape.parentId)) return undefined
|
|
5541
|
-
return this.
|
|
5531
|
+
return this.getShape(freshShape.parentId)
|
|
5542
5532
|
}
|
|
5543
5533
|
|
|
5544
5534
|
/**
|
|
@@ -5721,6 +5711,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5721
5711
|
const newPoint = invertedParentTransform.applyToPoint(pagePoint)
|
|
5722
5712
|
const newRotation = pageTransform.rotation() - parentPageRotation
|
|
5723
5713
|
|
|
5714
|
+
if (shape.id === parentId) {
|
|
5715
|
+
throw Error('Attempted to reparent a shape to itself!')
|
|
5716
|
+
}
|
|
5717
|
+
|
|
5724
5718
|
changes.push({
|
|
5725
5719
|
id: shape.id,
|
|
5726
5720
|
type: shape.type,
|
|
@@ -5796,8 +5790,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5796
5790
|
parent: TLParentId | TLPage | TLShape,
|
|
5797
5791
|
visitor: (id: TLShapeId) => void | false
|
|
5798
5792
|
): this {
|
|
5799
|
-
const
|
|
5800
|
-
const children = this.getSortedChildIdsForParent(parentId)
|
|
5793
|
+
const children = this.getSortedChildIdsForParent(parent)
|
|
5801
5794
|
for (const id of children) {
|
|
5802
5795
|
if (visitor(id) === false) continue
|
|
5803
5796
|
this.visitDescendants(id, visitor)
|
|
@@ -5825,6 +5818,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5825
5818
|
return shapeIds
|
|
5826
5819
|
}
|
|
5827
5820
|
|
|
5821
|
+
/** @deprecated Use {@link Editor.getDraggingOverShape} instead */
|
|
5822
|
+
getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
|
|
5823
|
+
return this.getDraggingOverShape(point, droppingShapes)
|
|
5824
|
+
}
|
|
5825
|
+
|
|
5828
5826
|
/**
|
|
5829
5827
|
* Get the shape that some shapes should be dropped on at a given point.
|
|
5830
5828
|
*
|
|
@@ -5835,35 +5833,33 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5835
5833
|
*
|
|
5836
5834
|
* @public
|
|
5837
5835
|
*/
|
|
5838
|
-
|
|
5839
|
-
//
|
|
5840
|
-
const
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
if (
|
|
5845
|
-
// ignore hidden shapes
|
|
5846
|
-
this.isShapeHidden(shape) ||
|
|
5847
|
-
// don't allow dropping on selected shapes
|
|
5848
|
-
this.getSelectedShapeIds().includes(shape.id) ||
|
|
5849
|
-
// only allow shapes that can receive children
|
|
5850
|
-
!this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) ||
|
|
5851
|
-
// don't allow dropping a shape on itself or one of it's children
|
|
5852
|
-
droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
|
|
5853
|
-
) {
|
|
5854
|
-
continue
|
|
5855
|
-
}
|
|
5836
|
+
getDraggingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
|
|
5837
|
+
// get fresh moving shapes
|
|
5838
|
+
const draggingShapes = compact(droppingShapes.map((s) => this.getShape(s))).filter(
|
|
5839
|
+
(s) => !s.isLocked && !this.isShapeHidden(s)
|
|
5840
|
+
)
|
|
5856
5841
|
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5842
|
+
const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
|
|
5843
|
+
hitInside: true,
|
|
5844
|
+
margin: 0,
|
|
5845
|
+
}).filter(
|
|
5846
|
+
(s) =>
|
|
5847
|
+
!droppingShapes.includes(s) &&
|
|
5848
|
+
!s.isLocked &&
|
|
5849
|
+
!this.isShapeHidden(s) &&
|
|
5850
|
+
!draggingShapes.includes(s)
|
|
5851
|
+
)
|
|
5860
5852
|
|
|
5853
|
+
for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
|
|
5854
|
+
const shapeUtil = this.getShapeUtil(maybeDraggingOverShape)
|
|
5855
|
+
// Any shape that can handle any dragging interactions is a valid target
|
|
5861
5856
|
if (
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5857
|
+
shapeUtil.onDragShapesOver ||
|
|
5858
|
+
shapeUtil.onDragShapesIn ||
|
|
5859
|
+
shapeUtil.onDragShapesOut ||
|
|
5860
|
+
shapeUtil.onDropShapesOver
|
|
5865
5861
|
) {
|
|
5866
|
-
return
|
|
5862
|
+
return maybeDraggingOverShape
|
|
5867
5863
|
}
|
|
5868
5864
|
}
|
|
5869
5865
|
}
|
|
@@ -6222,11 +6218,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6222
6218
|
*/
|
|
6223
6219
|
duplicateShapes(shapes: TLShapeId[] | TLShape[], offset?: VecLike): this {
|
|
6224
6220
|
this.run(() => {
|
|
6225
|
-
const
|
|
6221
|
+
const _ids =
|
|
6226
6222
|
typeof shapes[0] === 'string'
|
|
6227
6223
|
? (shapes as TLShapeId[])
|
|
6228
6224
|
: (shapes as TLShape[]).map((s) => s.id)
|
|
6229
6225
|
|
|
6226
|
+
const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids)
|
|
6230
6227
|
if (ids.length <= 0) return this
|
|
6231
6228
|
|
|
6232
6229
|
const initialIds = new Set(ids)
|
|
@@ -6306,10 +6303,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6306
6303
|
})
|
|
6307
6304
|
const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape)
|
|
6308
6305
|
|
|
6309
|
-
|
|
6310
|
-
shapesToCreate.length + this.getCurrentPageShapeIds().size > this.options.maxShapesPerPage
|
|
6311
|
-
|
|
6312
|
-
if (maxShapesReached) {
|
|
6306
|
+
if (!this.canCreateShapes(shapesToCreate)) {
|
|
6313
6307
|
alertMaxShapes(this)
|
|
6314
6308
|
return
|
|
6315
6309
|
}
|
|
@@ -7738,6 +7732,32 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7738
7732
|
return {}
|
|
7739
7733
|
}
|
|
7740
7734
|
|
|
7735
|
+
/**
|
|
7736
|
+
* Get whether the provided shape can be created.
|
|
7737
|
+
*
|
|
7738
|
+
* @param shape - The shape or shape IDs to check.
|
|
7739
|
+
*
|
|
7740
|
+
* @public
|
|
7741
|
+
*/
|
|
7742
|
+
canCreateShape<T extends TLUnknownShape>(
|
|
7743
|
+
shape: OptionalKeys<TLShapePartial<T>, 'id'> | T['id']
|
|
7744
|
+
): boolean {
|
|
7745
|
+
return this.canCreateShapes([shape])
|
|
7746
|
+
}
|
|
7747
|
+
|
|
7748
|
+
/**
|
|
7749
|
+
* Get whether the provided shapes can be created.
|
|
7750
|
+
*
|
|
7751
|
+
* @param shapes - The shapes or shape IDs to create.
|
|
7752
|
+
*
|
|
7753
|
+
* @public
|
|
7754
|
+
*/
|
|
7755
|
+
canCreateShapes<T extends TLUnknownShape>(
|
|
7756
|
+
shapes: (T['id'] | OptionalKeys<TLShapePartial<T>, 'id'>)[]
|
|
7757
|
+
): boolean {
|
|
7758
|
+
return shapes.length + this.getCurrentPageShapeIds().size <= this.options.maxShapesPerPage
|
|
7759
|
+
}
|
|
7760
|
+
|
|
7741
7761
|
/**
|
|
7742
7762
|
* Create a single shape.
|
|
7743
7763
|
*
|
|
@@ -7784,6 +7804,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7784
7804
|
if (maxShapesReached) {
|
|
7785
7805
|
// can't create more shapes than fit on the page
|
|
7786
7806
|
alertMaxShapes(this)
|
|
7807
|
+
// todo: throw an error here? Otherwise we'll need to check every time whether the shapes were actually created
|
|
7787
7808
|
return this
|
|
7788
7809
|
}
|
|
7789
7810
|
|
|
@@ -7816,9 +7837,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7816
7837
|
|
|
7817
7838
|
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
7818
7839
|
const parent = currentPageShapesSorted[i]
|
|
7840
|
+
const util = this.getShapeUtil(parent)
|
|
7819
7841
|
if (
|
|
7842
|
+
util.canReceiveNewChildrenOfType(parent, partial.type) &&
|
|
7820
7843
|
!this.isShapeHidden(parent) &&
|
|
7821
|
-
this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) &&
|
|
7822
7844
|
this.isPointInShape(
|
|
7823
7845
|
parent,
|
|
7824
7846
|
// If no parent is provided, then we can treat the
|
|
@@ -7947,6 +7969,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7947
7969
|
}
|
|
7948
7970
|
})
|
|
7949
7971
|
|
|
7972
|
+
this.emit('created-shapes', shapeRecordsToCreate)
|
|
7973
|
+
this.emit('edit')
|
|
7950
7974
|
this.store.put(shapeRecordsToCreate)
|
|
7951
7975
|
})
|
|
7952
7976
|
|
|
@@ -8341,6 +8365,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8341
8365
|
updates.push(updated)
|
|
8342
8366
|
}
|
|
8343
8367
|
|
|
8368
|
+
this.emit('edited-shapes', updates)
|
|
8369
|
+
this.emit('edit')
|
|
8344
8370
|
this.store.put(updates)
|
|
8345
8371
|
})
|
|
8346
8372
|
}
|
|
@@ -8390,6 +8416,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8390
8416
|
})
|
|
8391
8417
|
}
|
|
8392
8418
|
|
|
8419
|
+
this.emit('deleted-shapes', [...allShapeIdsToDelete])
|
|
8420
|
+
this.emit('edit')
|
|
8393
8421
|
return this.run(() => this.store.remove([...allShapeIdsToDelete]))
|
|
8394
8422
|
}
|
|
8395
8423
|
|
|
@@ -8838,6 +8866,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8838
8866
|
} = {
|
|
8839
8867
|
text: null,
|
|
8840
8868
|
files: null,
|
|
8869
|
+
'file-replace': null,
|
|
8841
8870
|
embed: null,
|
|
8842
8871
|
'svg-text': null,
|
|
8843
8872
|
url: null,
|
|
@@ -8887,6 +8916,15 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8887
8916
|
return this.externalContentHandlers[info.type]?.(info as any)
|
|
8888
8917
|
}
|
|
8889
8918
|
|
|
8919
|
+
/**
|
|
8920
|
+
* Handle replacing external content.
|
|
8921
|
+
*
|
|
8922
|
+
* @param info - Info about the external content.
|
|
8923
|
+
*/
|
|
8924
|
+
async replaceExternalContent<E>(info: TLExternalContent<E>): Promise<void> {
|
|
8925
|
+
return this.externalContentHandlers[info.type]?.(info as any)
|
|
8926
|
+
}
|
|
8927
|
+
|
|
8890
8928
|
/**
|
|
8891
8929
|
* Get content that can be exported for the given shape ids.
|
|
8892
8930
|
*
|
|
@@ -9304,6 +9342,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9304
9342
|
if (rootShapes.length === 1) {
|
|
9305
9343
|
const onlyRoot = rootShapes[0] as TLFrameShape
|
|
9306
9344
|
// If the old bounds are in the viewport...
|
|
9345
|
+
// todo: replace frame references with shapes that can accept children
|
|
9307
9346
|
if (this.isShapeOfType<TLFrameShape>(onlyRoot, 'frame')) {
|
|
9308
9347
|
while (
|
|
9309
9348
|
this.getShapesAtPoint(point).some(
|
|
@@ -9505,6 +9544,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9505
9544
|
previousPagePoint,
|
|
9506
9545
|
currentScreenPoint,
|
|
9507
9546
|
currentPagePoint,
|
|
9547
|
+
originScreenPoint,
|
|
9548
|
+
originPagePoint,
|
|
9508
9549
|
} = this.inputs
|
|
9509
9550
|
|
|
9510
9551
|
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID)!
|
|
@@ -9533,8 +9574,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9533
9574
|
// Reset velocity on pointer down, or when a pinch starts or ends
|
|
9534
9575
|
if (info.name === 'pointer_down' || this.inputs.isPinching) {
|
|
9535
9576
|
pointerVelocity.set(0, 0)
|
|
9536
|
-
|
|
9537
|
-
|
|
9577
|
+
originScreenPoint.setTo(currentScreenPoint)
|
|
9578
|
+
originPagePoint.setTo(currentPagePoint)
|
|
9538
9579
|
}
|
|
9539
9580
|
|
|
9540
9581
|
// todo: We only have to do this if there are multiple users in the document
|
|
@@ -62,6 +62,12 @@ export interface BindingOnShapeChangeOptions<Binding extends TLUnknownBinding> {
|
|
|
62
62
|
shapeBefore: TLShape
|
|
63
63
|
/** The shape record after the change is made. */
|
|
64
64
|
shapeAfter: TLShape
|
|
65
|
+
/**
|
|
66
|
+
* Why did this shape change?
|
|
67
|
+
* - 'self': the shape itself changed
|
|
68
|
+
* - 'ancestry': the ancestry of the shape changed, but the shape itself may not have done
|
|
69
|
+
*/
|
|
70
|
+
reason: 'self' | 'ancestry'
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
/**
|
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
import { Computed, RESET_VALUE, computed, isUninitialized } from '@tldraw/state'
|
|
2
|
-
import { TLBinding, TLShapeId } from '@tldraw/tlschema'
|
|
2
|
+
import { TLArrowBinding, TLBinding, TLShapeId, TLUnknownBinding } from '@tldraw/tlschema'
|
|
3
3
|
import { objectMapValues } from '@tldraw/utils'
|
|
4
4
|
import { Editor } from '../Editor'
|
|
5
5
|
|
|
6
6
|
type TLBindingsIndex = Map<TLShapeId, TLBinding[]>
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const bindingsHistory = store.query.filterHistory('binding')
|
|
11
|
-
const bindingsQuery = store.query.records('binding')
|
|
12
|
-
function fromScratch() {
|
|
13
|
-
const allBindings = bindingsQuery.get() as TLBinding[]
|
|
8
|
+
function fromScratch(bindingsQuery: Computed<(TLArrowBinding | TLUnknownBinding)[], unknown>) {
|
|
9
|
+
const allBindings = bindingsQuery.get() as TLBinding[]
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
const shapesToBindings: TLBindingsIndex = new Map()
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
13
|
+
for (const binding of allBindings) {
|
|
14
|
+
const { fromId, toId } = binding
|
|
15
|
+
const bindingsForFromShape = shapesToBindings.get(fromId)
|
|
16
|
+
if (!bindingsForFromShape) {
|
|
17
|
+
shapesToBindings.set(fromId, [binding])
|
|
18
|
+
} else {
|
|
19
|
+
bindingsForFromShape.push(binding)
|
|
20
|
+
}
|
|
21
|
+
const bindingsForToShape = shapesToBindings.get(toId)
|
|
22
|
+
if (!bindingsForToShape) {
|
|
23
|
+
shapesToBindings.set(toId, [binding])
|
|
24
|
+
} else {
|
|
25
|
+
bindingsForToShape.push(binding)
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
return shape2Binding
|
|
34
27
|
}
|
|
35
28
|
|
|
29
|
+
return shapesToBindings
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const bindingsIndex = (editor: Editor): Computed<TLBindingsIndex> => {
|
|
33
|
+
const { store } = editor
|
|
34
|
+
const bindingsHistory = store.query.filterHistory('binding')
|
|
35
|
+
const bindingsQuery = store.query.records('binding')
|
|
36
|
+
|
|
36
37
|
return computed<TLBindingsIndex>('arrowBindingsIndex', (_lastValue, lastComputedEpoch) => {
|
|
37
38
|
if (isUninitialized(_lastValue)) {
|
|
38
|
-
return fromScratch()
|
|
39
|
+
return fromScratch(bindingsQuery)
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const lastValue = _lastValue
|
|
@@ -43,7 +44,7 @@ export const bindingsIndex = (editor: Editor): Computed<TLBindingsIndex> => {
|
|
|
43
44
|
const diff = bindingsHistory.getDiffSince(lastComputedEpoch)
|
|
44
45
|
|
|
45
46
|
if (diff === RESET_VALUE) {
|
|
46
|
-
return fromScratch()
|
|
47
|
+
return fromScratch(bindingsQuery)
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
let nextValue: TLBindingsIndex | undefined = undefined
|
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
import { computed, isUninitialized } from '@tldraw/state'
|
|
2
2
|
import { TLShapeId } from '@tldraw/tlschema'
|
|
3
|
-
import { Box } from '../../primitives/Box'
|
|
4
3
|
import { Editor } from '../Editor'
|
|
5
4
|
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
function fromScratch(editor: Editor): Set<TLShapeId> {
|
|
6
|
+
const shapesIds = editor.getCurrentPageShapeIds()
|
|
7
|
+
const viewportPageBounds = editor.getViewportPageBounds()
|
|
8
|
+
const notVisibleShapes = new Set<TLShapeId>()
|
|
9
|
+
shapesIds.forEach((id) => {
|
|
10
|
+
// If the shape is fully outside of the viewport page bounds, add it to the set.
|
|
11
|
+
// We'll ignore masks here, since they're more expensive to compute and the overhead is not worth it.
|
|
12
|
+
const pageBounds = editor.getShapePageBounds(id)
|
|
13
|
+
if (pageBounds === undefined || !viewportPageBounds.includes(pageBounds)) {
|
|
14
|
+
notVisibleShapes.add(id)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
return notVisibleShapes
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Incremental derivation of not visible shapes.
|
|
17
|
-
* Non visible shapes are shapes outside of the viewport page bounds
|
|
22
|
+
* Non visible shapes are shapes outside of the viewport page bounds.
|
|
18
23
|
*
|
|
19
24
|
* @param editor - Instance of the tldraw Editor.
|
|
20
25
|
* @returns Incremental derivation of non visible shapes.
|
|
21
26
|
*/
|
|
22
|
-
export
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const notVisibleShapes = new Set<TLShapeId>()
|
|
27
|
-
shapes.forEach((id) => {
|
|
28
|
-
if (isShapeNotVisible(editor, id, viewportPageBounds)) {
|
|
29
|
-
notVisibleShapes.add(id)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
return notVisibleShapes
|
|
33
|
-
}
|
|
34
|
-
return computed<Set<TLShapeId>>('notVisibleShapes', (prevValue) => {
|
|
27
|
+
export function notVisibleShapes(editor: Editor) {
|
|
28
|
+
return computed<Set<TLShapeId>>('notVisibleShapes', function updateNotVisibleShapes(prevValue) {
|
|
29
|
+
const nextValue = fromScratch(editor)
|
|
30
|
+
|
|
35
31
|
if (isUninitialized(prevValue)) {
|
|
36
|
-
return
|
|
32
|
+
return nextValue
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
// If there are more or less shapes, we know there's a change
|
|
41
36
|
if (prevValue.size !== nextValue.size) return nextValue
|
|
37
|
+
|
|
38
|
+
// If any of the old shapes are not in the new set, we know there's a change
|
|
42
39
|
for (const prev of prevValue) {
|
|
43
40
|
if (!nextValue.has(prev)) {
|
|
44
41
|
return nextValue
|
|
45
42
|
}
|
|
46
43
|
}
|
|
44
|
+
|
|
45
|
+
// If we've made it here, we know that the set is the same
|
|
47
46
|
return prevValue
|
|
48
47
|
})
|
|
49
48
|
}
|