@tldraw/editor 5.4.0-next.038cf4b0c054 → 5.4.0-next.07f66c1cfcb8
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 +64 -1
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +4 -2
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +6 -8
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasOverlays.js +1 -3
- package/dist-cjs/lib/components/default-components/CanvasOverlays.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +1 -1
- package/dist-cjs/lib/config/TLUserPreferences.js +6 -2
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/config/createTLStore.js +1 -1
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +156 -280
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -3
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +8 -8
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +2 -1
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +79 -6
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +7 -0
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +0 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +1 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +6 -3
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +12 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/overlays/OverlayManager.js +3 -7
- package/dist-cjs/lib/editor/overlays/OverlayManager.js.map +2 -2
- package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js +0 -1
- package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +3 -1
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +1 -0
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +1 -1
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +3 -2
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/globals/editors.js +57 -0
- package/dist-cjs/lib/globals/editors.js.map +7 -0
- package/dist-cjs/lib/globals/menus.js +9 -4
- package/dist-cjs/lib/globals/menus.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -0
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useDocumentEvents.js +39 -9
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useLocalStore.js +10 -6
- package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +1 -0
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePeerIds.js +2 -1
- package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +2 -1
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +4 -3
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/utils.js +2 -1
- package/dist-cjs/lib/primitives/utils.js.map +2 -2
- package/dist-cjs/lib/utils/deepLinks.js +5 -1
- package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
- package/dist-cjs/lib/utils/rotation.js +1 -9
- package/dist-cjs/lib/utils/rotation.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +17 -0
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
- package/dist-cjs/lib/utils/sync/alerts.js +1 -1
- package/dist-cjs/lib/utils/sync/alerts.js.map +1 -1
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +64 -1
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +5 -3
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +6 -8
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasOverlays.mjs +1 -3
- package/dist-esm/lib/components/default-components/CanvasOverlays.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +1 -1
- package/dist-esm/lib/config/TLUserPreferences.mjs +6 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/config/createTLStore.mjs +1 -1
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +164 -281
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -3
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +9 -9
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +2 -1
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +81 -8
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +7 -0
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +0 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +2 -3
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +6 -3
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +12 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/overlays/OverlayManager.mjs +3 -7
- package/dist-esm/lib/editor/overlays/OverlayManager.mjs.map +2 -2
- package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs +0 -1
- package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +3 -1
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +1 -0
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +1 -1
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +3 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/globals/editors.mjs +37 -0
- package/dist-esm/lib/globals/editors.mjs.map +7 -0
- package/dist-esm/lib/globals/menus.mjs +9 -4
- package/dist-esm/lib/globals/menus.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -0
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +40 -10
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useLocalStore.mjs +11 -7
- package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +1 -0
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs +2 -1
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +2 -1
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +4 -3
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/utils.mjs +2 -1
- package/dist-esm/lib/primitives/utils.mjs.map +2 -2
- package/dist-esm/lib/utils/deepLinks.mjs +5 -1
- package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
- package/dist-esm/lib/utils/rotation.mjs +1 -9
- package/dist-esm/lib/utils/rotation.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +17 -0
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/alerts.mjs +1 -1
- package/dist-esm/lib/utils/sync/alerts.mjs.map +1 -1
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +1 -0
- package/src/lib/TldrawEditor.tsx +12 -3
- package/src/lib/components/MenuClickCapture.tsx +19 -18
- package/src/lib/components/default-components/CanvasOverlays.tsx +1 -3
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/config/TLUserPreferences.test.ts +18 -1
- package/src/lib/config/TLUserPreferences.ts +8 -4
- package/src/lib/config/createTLStore.ts +1 -1
- package/src/lib/editor/Editor.ts +231 -359
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +5 -3
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +9 -9
- package/src/lib/editor/managers/FontManager/FontManager.ts +2 -1
- package/src/lib/editor/managers/InputsManager/InputsManager.test.ts +199 -3
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +128 -9
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +12 -1
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +0 -2
- package/src/lib/editor/managers/TextManager/TextManager.ts +2 -6
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +13 -0
- package/src/lib/editor/managers/TickManager/TickManager.ts +9 -3
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +64 -3
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +18 -1
- package/src/lib/editor/overlays/OverlayManager.ts +3 -7
- package/src/lib/editor/overlays/strokeShapeIndicators.ts +0 -1
- package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +5 -1
- package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +3 -0
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +4 -1
- package/src/lib/editor/tools/StateNode.test.ts +64 -0
- package/src/lib/editor/tools/StateNode.ts +12 -2
- package/src/lib/globals/editors.test.ts +76 -0
- package/src/lib/globals/editors.ts +53 -0
- package/src/lib/globals/menus.test.ts +33 -0
- package/src/lib/globals/menus.ts +11 -4
- package/src/lib/hooks/useCanvasEvents.ts +2 -0
- package/src/lib/hooks/useDocumentEvents.ts +60 -16
- package/src/lib/hooks/useLocalStore.ts +16 -8
- package/src/lib/hooks/usePassThroughWheelEvents.ts +3 -0
- package/src/lib/hooks/usePeerIds.ts +2 -1
- package/src/lib/primitives/Box.test.ts +9 -1
- package/src/lib/primitives/Box.ts +3 -1
- package/src/lib/primitives/Vec.test.ts +10 -0
- package/src/lib/primitives/Vec.ts +4 -4
- package/src/lib/primitives/geometry/Arc2d.test.ts +226 -3
- package/src/lib/primitives/geometry/CubicBezier2d.test.ts +173 -3
- package/src/lib/primitives/geometry/CubicSpline2d.test.ts +160 -3
- package/src/lib/primitives/geometry/Ellipse2d.test.ts +243 -3
- package/src/lib/primitives/geometry/Geometry2d.test.ts +553 -1
- package/src/lib/primitives/geometry/Group2d.test.ts +398 -3
- package/src/lib/primitives/geometry/Polyline2d.test.ts +207 -0
- package/src/lib/primitives/geometry/Stadium2d.test.ts +191 -3
- package/src/lib/primitives/utils.test.ts +10 -1
- package/src/lib/primitives/utils.ts +4 -1
- package/src/lib/test/useCanvasEvents.test.tsx +74 -0
- package/src/lib/test/useDocumentEvents.test.tsx +107 -0
- package/src/lib/test/usePassThroughWheelEvents.test.tsx +25 -2
- package/src/lib/utils/deepLinks.test.ts +15 -0
- package/src/lib/utils/deepLinks.ts +7 -1
- package/src/lib/utils/rotation.ts +4 -12
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +56 -0
- package/src/lib/utils/sync/TLLocalSyncClient.ts +24 -0
- package/src/lib/utils/sync/alerts.ts +1 -1
- package/src/version.ts +3 -3
- package/src/lib/primitives/geometry/Polyline.test.ts +0 -5
|
@@ -53,6 +53,7 @@ var import_constants = require("../constants");
|
|
|
53
53
|
var import_domUtils = require("../exports/domUtils");
|
|
54
54
|
var import_exportToSvg = require("../exports/exportToSvg");
|
|
55
55
|
var import_getSvgAsImage = require("../exports/getSvgAsImage");
|
|
56
|
+
var import_editors = require("../globals/editors");
|
|
56
57
|
var import_menus = require("../globals/menus");
|
|
57
58
|
var import_time = require("../globals/time");
|
|
58
59
|
var import_options = require("../options");
|
|
@@ -256,6 +257,10 @@ class Editor extends import_eventemitter3.default {
|
|
|
256
257
|
if (!nextPageState) nextPageState = { ...prevPageState };
|
|
257
258
|
nextPageState.editingShapeId = null;
|
|
258
259
|
}
|
|
260
|
+
if (prevPageState.croppingShapeId && shapesNoLongerInPage.has(prevPageState.croppingShapeId)) {
|
|
261
|
+
if (!nextPageState) nextPageState = { ...prevPageState };
|
|
262
|
+
nextPageState.croppingShapeId = null;
|
|
263
|
+
}
|
|
259
264
|
const hintingShapeIds = prevPageState.hintingShapeIds.filter(
|
|
260
265
|
(id) => !shapesNoLongerInPage.has(id)
|
|
261
266
|
);
|
|
@@ -498,10 +503,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
498
503
|
this.cancelDoubleClick();
|
|
499
504
|
}
|
|
500
505
|
if (prev?.selectedShapeIds !== next?.selectedShapeIds) {
|
|
506
|
+
const selectedShapeIds = new Set(next.selectedShapeIds);
|
|
501
507
|
const filtered = next.selectedShapeIds.filter((id) => {
|
|
502
508
|
let parentId = this.getShape(id)?.parentId;
|
|
503
509
|
while ((0, import_tlschema.isShapeId)(parentId)) {
|
|
504
|
-
if (
|
|
510
|
+
if (selectedShapeIds.has(parentId)) {
|
|
505
511
|
return false;
|
|
506
512
|
}
|
|
507
513
|
parentId = this.getShape(parentId)?.parentId;
|
|
@@ -571,9 +577,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
571
577
|
this.on("tick", this._flushEventsForTick);
|
|
572
578
|
this.on("mount", () => {
|
|
573
579
|
this._isMounted.set(true);
|
|
580
|
+
(0, import_editors.registerMountedEditor)(this);
|
|
574
581
|
});
|
|
575
582
|
this.on("unmount", () => {
|
|
576
583
|
this._isMounted.set(false);
|
|
584
|
+
(0, import_editors.unregisterMountedEditor)(this);
|
|
577
585
|
});
|
|
578
586
|
this.timers.requestAnimationFrame(() => {
|
|
579
587
|
this._tickManager.start();
|
|
@@ -583,7 +591,10 @@ class Editor extends import_eventemitter3.default {
|
|
|
583
591
|
const mode = this.store.props.collaboration.mode;
|
|
584
592
|
this.disposables.add(
|
|
585
593
|
(0, import_state.react)("update collaboration mode", () => {
|
|
586
|
-
|
|
594
|
+
const isReadonly = mode.get() === "readonly";
|
|
595
|
+
(0, import_state.unsafe__withoutCapture)(
|
|
596
|
+
() => this._updateInstanceState({ isReadonly }, { history: "ignore" })
|
|
597
|
+
);
|
|
587
598
|
})
|
|
588
599
|
);
|
|
589
600
|
}
|
|
@@ -815,6 +826,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
815
826
|
if (this._isMounted.get()) {
|
|
816
827
|
this.emit("unmount");
|
|
817
828
|
}
|
|
829
|
+
(0, import_editors.unregisterMountedEditor)(this);
|
|
818
830
|
this.stopCameraAnimation();
|
|
819
831
|
if (this.getInstanceState().followingUserId) {
|
|
820
832
|
this.stopFollowingUser();
|
|
@@ -940,7 +952,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
940
952
|
getShapeUtil(arg) {
|
|
941
953
|
const type = typeof arg === "string" ? arg : arg.type;
|
|
942
954
|
const shapeUtil = (0, import_utils.getOwnProperty)(this.shapeUtils, type);
|
|
943
|
-
|
|
955
|
+
if (!shapeUtil) throw new Error(`No shape util found for type "${type}"`);
|
|
944
956
|
return shapeUtil;
|
|
945
957
|
}
|
|
946
958
|
hasShapeUtil(arg) {
|
|
@@ -1729,7 +1741,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
1729
1741
|
const selectedShapes = this.getSelectedShapes();
|
|
1730
1742
|
if (!selectedShapes.length) return;
|
|
1731
1743
|
const selectedShape = selectedShapes[0];
|
|
1732
|
-
const children =
|
|
1744
|
+
const children = (0, import_utils.compact)(
|
|
1745
|
+
this.getSortedChildIdsForParent(selectedShape.id).map((id) => this.getShape(id))
|
|
1746
|
+
);
|
|
1733
1747
|
const sortedChildren = this._getShapesInReadingOrder(children);
|
|
1734
1748
|
if (sortedChildren.length === 0) return;
|
|
1735
1749
|
this._selectShapesAndZoom([sortedChildren[0].id]);
|
|
@@ -1796,18 +1810,13 @@ class Editor extends import_eventemitter3.default {
|
|
|
1796
1810
|
* @internal
|
|
1797
1811
|
*/
|
|
1798
1812
|
getShapesSharedRotation(shapeIds) {
|
|
1799
|
-
let foundFirst = false;
|
|
1800
1813
|
let rotation = 0;
|
|
1801
1814
|
for (let i = 0, n = shapeIds.length; i < n; i++) {
|
|
1802
|
-
const
|
|
1803
|
-
if (
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
}
|
|
1808
|
-
} else {
|
|
1809
|
-
foundFirst = true;
|
|
1810
|
-
rotation = pageTransform.rotation();
|
|
1815
|
+
const pageRotation = this.getShapePageTransform(shapeIds[i]).rotation();
|
|
1816
|
+
if (i === 0) {
|
|
1817
|
+
rotation = pageRotation;
|
|
1818
|
+
} else if (pageRotation !== rotation) {
|
|
1819
|
+
return 0;
|
|
1811
1820
|
}
|
|
1812
1821
|
}
|
|
1813
1822
|
return rotation;
|
|
@@ -1833,11 +1842,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
1833
1842
|
return bounds;
|
|
1834
1843
|
}
|
|
1835
1844
|
const boxFromRotatedVertices = import_Box.Box.FromPoints(
|
|
1836
|
-
shapeIds.flatMap(
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
return pageTransform.applyToPoints(this.getShapeGeometry(id).bounds.corners);
|
|
1840
|
-
}).map((p) => p.rot(-selectionRotation))
|
|
1845
|
+
shapeIds.flatMap(
|
|
1846
|
+
(id) => this.getShapePageTransform(id).applyToPoints(this.getShapeGeometry(id).bounds.corners)
|
|
1847
|
+
).map((p) => p.rot(-selectionRotation))
|
|
1841
1848
|
);
|
|
1842
1849
|
boxFromRotatedVertices.point = boxFromRotatedVertices.point.rot(selectionRotation);
|
|
1843
1850
|
return boxFromRotatedVertices;
|
|
@@ -1848,9 +1855,14 @@ class Editor extends import_eventemitter3.default {
|
|
|
1848
1855
|
getSelectionRotatedScreenBounds() {
|
|
1849
1856
|
const bounds = this.getSelectionRotatedPageBounds();
|
|
1850
1857
|
if (!bounds) return void 0;
|
|
1851
|
-
const
|
|
1852
|
-
const zoom = this.
|
|
1853
|
-
return new import_Box.Box(
|
|
1858
|
+
const screenBounds = this.getViewportScreenBounds();
|
|
1859
|
+
const { x: cx, y: cy, z: zoom } = this.getCamera();
|
|
1860
|
+
return new import_Box.Box(
|
|
1861
|
+
(bounds.x + cx) * zoom + screenBounds.x,
|
|
1862
|
+
(bounds.y + cy) * zoom + screenBounds.y,
|
|
1863
|
+
bounds.width * zoom,
|
|
1864
|
+
bounds.height * zoom
|
|
1865
|
+
);
|
|
1854
1866
|
}
|
|
1855
1867
|
getFocusedGroupId() {
|
|
1856
1868
|
return this.getCurrentPageState().focusedGroupId ?? this.getCurrentPageId();
|
|
@@ -1951,42 +1963,28 @@ class Editor extends import_eventemitter3.default {
|
|
|
1951
1963
|
*/
|
|
1952
1964
|
setEditingShape(shape) {
|
|
1953
1965
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1954
|
-
if (!id)
|
|
1966
|
+
if (id && !this.canEditShape(id)) return this;
|
|
1967
|
+
this.run(() => {
|
|
1968
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
1969
|
+
if (prevEditingShapeId) {
|
|
1970
|
+
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1971
|
+
if (prevEditingShape) {
|
|
1972
|
+
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1955
1975
|
this.run(
|
|
1956
1976
|
() => {
|
|
1957
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
1958
|
-
if (prevEditingShapeId) {
|
|
1959
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1960
|
-
if (prevEditingShape) {
|
|
1961
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
1977
|
this._updateCurrentPageState({ editingShapeId: null });
|
|
1965
1978
|
this._currentRichTextEditor.set(null);
|
|
1979
|
+
if (!id) return;
|
|
1980
|
+
this.select(id);
|
|
1981
|
+
this._updateCurrentPageState({ editingShapeId: id });
|
|
1982
|
+
const nextEditingShape = this.getShape(id);
|
|
1983
|
+
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
1966
1984
|
},
|
|
1967
1985
|
{ history: "ignore" }
|
|
1968
1986
|
);
|
|
1969
|
-
|
|
1970
|
-
}
|
|
1971
|
-
if (!this.canEditShape(id)) return this;
|
|
1972
|
-
this.run(
|
|
1973
|
-
() => {
|
|
1974
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
1975
|
-
if (prevEditingShapeId) {
|
|
1976
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1977
|
-
if (prevEditingShape) {
|
|
1978
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
this._updateCurrentPageState({ editingShapeId: null });
|
|
1982
|
-
this._currentRichTextEditor.set(null);
|
|
1983
|
-
this.select(id);
|
|
1984
|
-
this._updateCurrentPageState({ editingShapeId: id });
|
|
1985
|
-
const nextEditingShape = this.getShape(id);
|
|
1986
|
-
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
1987
|
-
},
|
|
1988
|
-
{ history: "ignore" }
|
|
1989
|
-
);
|
|
1987
|
+
});
|
|
1990
1988
|
return this;
|
|
1991
1989
|
}
|
|
1992
1990
|
// Rich text editor
|
|
@@ -2092,19 +2090,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
2092
2090
|
* @public
|
|
2093
2091
|
*/
|
|
2094
2092
|
setErasingShapes(shapes) {
|
|
2095
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
|
|
2093
|
+
const ids = typeof shapes[0] === "string" ? shapes.slice() : shapes.map((shape) => shape.id);
|
|
2096
2094
|
ids.sort();
|
|
2097
2095
|
const erasingShapeIds = this.getErasingShapeIds();
|
|
2098
2096
|
this.run(
|
|
2099
2097
|
() => {
|
|
2100
|
-
if (ids
|
|
2101
|
-
for (let i = 0; i < ids.length; i++) {
|
|
2102
|
-
if (ids[i] !== erasingShapeIds[i]) {
|
|
2103
|
-
this._updateCurrentPageState({ erasingShapeIds: ids });
|
|
2104
|
-
break;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
} else {
|
|
2098
|
+
if (!(0, import_utils.areArraysShallowEqual)(ids, erasingShapeIds)) {
|
|
2108
2099
|
this._updateCurrentPageState({ erasingShapeIds: ids });
|
|
2109
2100
|
}
|
|
2110
2101
|
},
|
|
@@ -2137,6 +2128,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2137
2128
|
if (!_shape) return false;
|
|
2138
2129
|
const util = this.getShapeUtil(_shape);
|
|
2139
2130
|
if (!util.canCrop(_shape)) return false;
|
|
2131
|
+
if (this.getIsReadonly()) return false;
|
|
2140
2132
|
if (this.isShapeOrAncestorLocked(_shape)) return false;
|
|
2141
2133
|
return true;
|
|
2142
2134
|
}
|
|
@@ -2201,11 +2193,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
2201
2193
|
const collaborators = this.getCollaborators();
|
|
2202
2194
|
let leaderPresence = null;
|
|
2203
2195
|
while (targetUserId && !visited.includes(targetUserId)) {
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2196
|
+
const nextPresence = collaborators.find((c) => c.userId === targetUserId);
|
|
2197
|
+
if (!nextPresence) break;
|
|
2198
|
+
leaderPresence = nextPresence;
|
|
2199
|
+
targetUserId = nextPresence.followingUserId ?? null;
|
|
2200
|
+
visited.push(nextPresence.userId);
|
|
2209
2201
|
}
|
|
2210
2202
|
return leaderPresence;
|
|
2211
2203
|
}
|
|
@@ -2268,39 +2260,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2268
2260
|
*
|
|
2269
2261
|
* @public */
|
|
2270
2262
|
getInitialZoom() {
|
|
2271
|
-
|
|
2272
|
-
if (!cameraOptions.constraints) return 1;
|
|
2273
|
-
if (cameraOptions.constraints.initialZoom === "default") return 1;
|
|
2274
|
-
const { zx, zy } = getCameraFitXFitY(this, cameraOptions);
|
|
2275
|
-
switch (cameraOptions.constraints.initialZoom) {
|
|
2276
|
-
case "fit-min": {
|
|
2277
|
-
return Math.max(zx, zy);
|
|
2278
|
-
}
|
|
2279
|
-
case "fit-max": {
|
|
2280
|
-
return Math.min(zx, zy);
|
|
2281
|
-
}
|
|
2282
|
-
case "fit-x": {
|
|
2283
|
-
return zx;
|
|
2284
|
-
}
|
|
2285
|
-
case "fit-y": {
|
|
2286
|
-
return zy;
|
|
2287
|
-
}
|
|
2288
|
-
case "fit-min-100": {
|
|
2289
|
-
return Math.min(1, Math.max(zx, zy));
|
|
2290
|
-
}
|
|
2291
|
-
case "fit-max-100": {
|
|
2292
|
-
return Math.min(1, Math.min(zx, zy));
|
|
2293
|
-
}
|
|
2294
|
-
case "fit-x-100": {
|
|
2295
|
-
return Math.min(1, zx);
|
|
2296
|
-
}
|
|
2297
|
-
case "fit-y-100": {
|
|
2298
|
-
return Math.min(1, zy);
|
|
2299
|
-
}
|
|
2300
|
-
default: {
|
|
2301
|
-
throw (0, import_utils.exhaustiveSwitchError)(cameraOptions.constraints.initialZoom);
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2263
|
+
return this._getFitZoom(this.getCameraOptions().constraints?.initialZoom ?? "default");
|
|
2304
2264
|
}
|
|
2305
2265
|
/**
|
|
2306
2266
|
* Get the camera's base level for calculating actual zoom levels based on the zoom steps.
|
|
@@ -2312,11 +2272,13 @@ class Editor extends import_eventemitter3.default {
|
|
|
2312
2272
|
*
|
|
2313
2273
|
* @public */
|
|
2314
2274
|
getBaseZoom() {
|
|
2275
|
+
return this._getFitZoom(this.getCameraOptions().constraints?.baseZoom ?? "default");
|
|
2276
|
+
}
|
|
2277
|
+
_getFitZoom(fit) {
|
|
2315
2278
|
const cameraOptions = this.getCameraOptions();
|
|
2316
|
-
if (!cameraOptions.constraints) return 1;
|
|
2317
|
-
if (cameraOptions.constraints.baseZoom === "default") return 1;
|
|
2279
|
+
if (!cameraOptions.constraints || fit === "default") return 1;
|
|
2318
2280
|
const { zx, zy } = getCameraFitXFitY(this, cameraOptions);
|
|
2319
|
-
switch (
|
|
2281
|
+
switch (fit) {
|
|
2320
2282
|
case "fit-min": {
|
|
2321
2283
|
return Math.max(zx, zy);
|
|
2322
2284
|
}
|
|
@@ -2342,7 +2304,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2342
2304
|
return Math.min(1, zy);
|
|
2343
2305
|
}
|
|
2344
2306
|
default: {
|
|
2345
|
-
throw (0, import_utils.exhaustiveSwitchError)(
|
|
2307
|
+
throw (0, import_utils.exhaustiveSwitchError)(fit);
|
|
2346
2308
|
}
|
|
2347
2309
|
}
|
|
2348
2310
|
}
|
|
@@ -2376,7 +2338,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2376
2338
|
...this._cameraOptions.__unsafe__getWithoutCapture(),
|
|
2377
2339
|
...opts
|
|
2378
2340
|
});
|
|
2379
|
-
if (next.zoomSteps
|
|
2341
|
+
if (!next.zoomSteps || next.zoomSteps.length < 1) next.zoomSteps = [1];
|
|
2380
2342
|
this._cameraOptions.set(next);
|
|
2381
2343
|
this.setCamera(this.getCamera());
|
|
2382
2344
|
return this;
|
|
@@ -2397,8 +2359,8 @@ class Editor extends import_eventemitter3.default {
|
|
|
2397
2359
|
const vsb = this.getViewportScreenBounds();
|
|
2398
2360
|
if (cameraOptions.constraints) {
|
|
2399
2361
|
const { constraints } = cameraOptions;
|
|
2400
|
-
const
|
|
2401
|
-
const
|
|
2362
|
+
const px = Math.min(constraints.padding.x, vsb.w / 2);
|
|
2363
|
+
const py = Math.min(constraints.padding.y, vsb.h / 2);
|
|
2402
2364
|
const bounds = import_Box.Box.From(cameraOptions.constraints.bounds);
|
|
2403
2365
|
const zx = (vsb.w - px * 2) / bounds.w;
|
|
2404
2366
|
const zy = (vsb.h - py * 2) / bounds.h;
|
|
@@ -2437,12 +2399,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
2437
2399
|
break;
|
|
2438
2400
|
}
|
|
2439
2401
|
case "inside": {
|
|
2440
|
-
if (z < zx) x = (0, import_utils2.clamp)(x, minX, (vsb.w - px) / z - bounds.w);
|
|
2402
|
+
if (z < zx) x = (0, import_utils2.clamp)(x, minX, (vsb.w - px) / z - bounds.w - bounds.x);
|
|
2441
2403
|
else x = (0, import_utils2.clamp)(x, minX + freeW, minX);
|
|
2442
2404
|
break;
|
|
2443
2405
|
}
|
|
2444
2406
|
case "outside": {
|
|
2445
|
-
x = (0, import_utils2.clamp)(x, px / z - bounds.w, (vsb.w - px) / z);
|
|
2407
|
+
x = (0, import_utils2.clamp)(x, px / z - bounds.w - bounds.x, (vsb.w - px) / z - bounds.x);
|
|
2446
2408
|
break;
|
|
2447
2409
|
}
|
|
2448
2410
|
case "free": {
|
|
@@ -2463,12 +2425,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
2463
2425
|
break;
|
|
2464
2426
|
}
|
|
2465
2427
|
case "inside": {
|
|
2466
|
-
if (z < zy) y = (0, import_utils2.clamp)(y, minY, (vsb.h - py) / z - bounds.h);
|
|
2428
|
+
if (z < zy) y = (0, import_utils2.clamp)(y, minY, (vsb.h - py) / z - bounds.h - bounds.y);
|
|
2467
2429
|
else y = (0, import_utils2.clamp)(y, minY + freeH, minY);
|
|
2468
2430
|
break;
|
|
2469
2431
|
}
|
|
2470
2432
|
case "outside": {
|
|
2471
|
-
y = (0, import_utils2.clamp)(y, py / z - bounds.h, (vsb.h - py) / z);
|
|
2433
|
+
y = (0, import_utils2.clamp)(y, py / z - bounds.h - bounds.y, (vsb.h - py) / z - bounds.y);
|
|
2472
2434
|
break;
|
|
2473
2435
|
}
|
|
2474
2436
|
case "free": {
|
|
@@ -2836,9 +2798,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
2836
2798
|
}
|
|
2837
2799
|
const remaining = duration - elapsed;
|
|
2838
2800
|
const t = easing(1 - remaining / duration);
|
|
2839
|
-
const left = start.minX
|
|
2840
|
-
const top = start.minY
|
|
2841
|
-
const right = start.maxX
|
|
2801
|
+
const left = (0, import_utils.lerp)(start.minX, end.minX, t);
|
|
2802
|
+
const top = (0, import_utils.lerp)(start.minY, end.minY, t);
|
|
2803
|
+
const right = (0, import_utils.lerp)(start.maxX, end.maxX, t);
|
|
2842
2804
|
this._setCamera(new import_Vec.Vec(-left, -top, this.getViewportScreenBounds().width / (right - left)), {
|
|
2843
2805
|
force: true
|
|
2844
2806
|
});
|
|
@@ -2916,7 +2878,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2916
2878
|
let newCy = cy + dy;
|
|
2917
2879
|
let newCz = cz;
|
|
2918
2880
|
if (dirZ !== 0) {
|
|
2919
|
-
newCz = cz * (
|
|
2881
|
+
newCz = cz * Math.exp(dirZ * currentSpeed * elapsed);
|
|
2920
2882
|
const center = this.getViewportScreenCenter();
|
|
2921
2883
|
newCx += center.x / newCz - center.x / cz;
|
|
2922
2884
|
newCy += center.y / newCz - center.y / cz;
|
|
@@ -3354,12 +3316,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
3354
3316
|
const renderingShapes = [];
|
|
3355
3317
|
let nextIndex = this.options.maxShapesPerPage * 2;
|
|
3356
3318
|
let nextBackgroundIndex = this.options.maxShapesPerPage;
|
|
3357
|
-
const erasingShapeIds = this.getErasingShapeIds();
|
|
3319
|
+
const erasingShapeIds = new Set(this.getErasingShapeIds());
|
|
3358
3320
|
const addShapeById = (id, opacity, isAncestorErasing) => {
|
|
3359
3321
|
const shape = this.getShape(id);
|
|
3360
3322
|
if (!shape) return;
|
|
3361
3323
|
if (this.isShapeHidden(shape)) {
|
|
3362
|
-
const isErasing = isAncestorErasing || erasingShapeIds.
|
|
3324
|
+
const isErasing = isAncestorErasing || erasingShapeIds.has(id);
|
|
3363
3325
|
for (const childId of this.getSortedChildIdsForParent(id)) {
|
|
3364
3326
|
addShapeById(childId, opacity, isErasing);
|
|
3365
3327
|
}
|
|
@@ -3369,7 +3331,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
3369
3331
|
let isShapeErasing = false;
|
|
3370
3332
|
const util = this.getShapeUtil(shape);
|
|
3371
3333
|
if (useEditorState) {
|
|
3372
|
-
isShapeErasing = !isAncestorErasing && erasingShapeIds.
|
|
3334
|
+
isShapeErasing = !isAncestorErasing && erasingShapeIds.has(id);
|
|
3373
3335
|
if (isShapeErasing) {
|
|
3374
3336
|
opacity *= 0.32;
|
|
3375
3337
|
}
|
|
@@ -3961,10 +3923,8 @@ class Editor extends import_eventemitter3.default {
|
|
|
3961
3923
|
}
|
|
3962
3924
|
_getShapePageBoundsCache() {
|
|
3963
3925
|
return this.store.createComputedCache("pageBoundsCache", (shape) => {
|
|
3964
|
-
const pageTransform = this.getShapePageTransform(shape);
|
|
3965
|
-
if (!pageTransform) return void 0;
|
|
3966
3926
|
return import_Box.Box.FromPoints(
|
|
3967
|
-
|
|
3927
|
+
this.getShapePageTransform(shape).applyToPoints(this.getShapeGeometry(shape).boundsVertices)
|
|
3968
3928
|
);
|
|
3969
3929
|
});
|
|
3970
3930
|
}
|
|
@@ -4082,7 +4042,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
4082
4042
|
if (pageMask) {
|
|
4083
4043
|
if (pageMask.length === 0) return void 0;
|
|
4084
4044
|
const { corners } = pageBounds;
|
|
4085
|
-
if (corners.every((p, i) =>
|
|
4045
|
+
if (pageMask.length === corners.length && corners.every((p, i) => import_Vec.Vec.Equals(p, pageMask[i]))) {
|
|
4046
|
+
return pageBounds.clone();
|
|
4047
|
+
}
|
|
4086
4048
|
const intersection = (0, import_intersect.intersectPolygonPolygon)(pageMask, corners);
|
|
4087
4049
|
if (!intersection) return;
|
|
4088
4050
|
return import_Box.Box.FromPoints(intersection);
|
|
@@ -4321,7 +4283,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4321
4283
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
4322
4284
|
const shapeUtil = this.getShapeUtil(shape);
|
|
4323
4285
|
const isShapeFrameLike = this.isShapeFrameLike(shape);
|
|
4324
|
-
if (isShapeFrameLike || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shapeUtil.getText(shape)?.trim()) {
|
|
4286
|
+
if (isGroup && (isShapeFrameLike || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shapeUtil.getText(shape)?.trim())) {
|
|
4325
4287
|
for (const childGeometry of geometry.children) {
|
|
4326
4288
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
4327
4289
|
return shape;
|
|
@@ -4513,9 +4475,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4513
4475
|
const freshShape = this.getShape(id);
|
|
4514
4476
|
if (!freshShape) return new import_Vec.Vec(0, 0);
|
|
4515
4477
|
if ((0, import_tlschema.isPageId)(freshShape.parentId)) return import_Vec.Vec.From(point);
|
|
4516
|
-
|
|
4517
|
-
if (!parentTransform) return import_Vec.Vec.From(point);
|
|
4518
|
-
return parentTransform.clone().invert().applyToPoint(point);
|
|
4478
|
+
return this.getShapePageTransform(freshShape.parentId).clone().invert().applyToPoint(point);
|
|
4519
4479
|
}
|
|
4520
4480
|
getCurrentPageShapes() {
|
|
4521
4481
|
return Array.from(this.getCurrentPageShapeIds(), (id) => this.store.get(id));
|
|
@@ -4627,23 +4587,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4627
4587
|
* @public
|
|
4628
4588
|
*/
|
|
4629
4589
|
isShapeInPage(shape, pageId = this.getCurrentPageId()) {
|
|
4630
|
-
|
|
4631
|
-
const shapeToCheck = this.getShape(id);
|
|
4632
|
-
if (!shapeToCheck) return false;
|
|
4633
|
-
let shapeIsInPage = false;
|
|
4634
|
-
if (shapeToCheck.parentId === pageId) {
|
|
4635
|
-
shapeIsInPage = true;
|
|
4636
|
-
} else {
|
|
4637
|
-
let parent = this.getShape(shapeToCheck.parentId);
|
|
4638
|
-
isInPageSearch: while (parent) {
|
|
4639
|
-
if (parent.parentId === pageId) {
|
|
4640
|
-
shapeIsInPage = true;
|
|
4641
|
-
break isInPageSearch;
|
|
4642
|
-
}
|
|
4643
|
-
parent = this.getShape(parent.parentId);
|
|
4644
|
-
}
|
|
4645
|
-
}
|
|
4646
|
-
return shapeIsInPage;
|
|
4590
|
+
return this.getAncestorPageId(shape) === pageId;
|
|
4647
4591
|
}
|
|
4648
4592
|
/**
|
|
4649
4593
|
* Get the id of the containing page for a given shape.
|
|
@@ -4724,10 +4668,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4724
4668
|
for (let i = 0; i < shapesToReparent.length; i++) {
|
|
4725
4669
|
const shape = shapesToReparent[i];
|
|
4726
4670
|
const pageTransform = this.getShapePageTransform(shape);
|
|
4727
|
-
|
|
4728
|
-
const pagePoint = pageTransform.point();
|
|
4729
|
-
if (!pagePoint) continue;
|
|
4730
|
-
const newPoint = invertedParentTransform.applyToPoint(pagePoint);
|
|
4671
|
+
const newPoint = invertedParentTransform.applyToPoint(pageTransform.point());
|
|
4731
4672
|
const newRotation = pageTransform.rotation() - parentPageRotation;
|
|
4732
4673
|
if (shape.id === parentId) {
|
|
4733
4674
|
throw Error("Attempted to reparent a shape to itself!");
|
|
@@ -4816,7 +4757,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4816
4757
|
*/
|
|
4817
4758
|
getShapeAndDescendantIds(ids) {
|
|
4818
4759
|
const shapeIds = /* @__PURE__ */ new Set();
|
|
4819
|
-
for (const shape of ids.map((id) => this.getShape(id)).sort(import_utils.sortByIndex)) {
|
|
4760
|
+
for (const shape of (0, import_utils.compact)(ids.map((id) => this.getShape(id))).sort(import_utils.sortByIndex)) {
|
|
4820
4761
|
shapeIds.add(shape.id);
|
|
4821
4762
|
this.visitDescendants(shape, (descendantId) => {
|
|
4822
4763
|
shapeIds.add(descendantId);
|
|
@@ -4838,11 +4779,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
4838
4779
|
const draggingShapes = (0, import_utils.compact)(droppingShapes.map((s) => this.getShape(s))).filter(
|
|
4839
4780
|
(s) => !s.isLocked && !this.isShapeHidden(s)
|
|
4840
4781
|
);
|
|
4782
|
+
const excludedIds = this.getShapeAndDescendantIds(draggingShapes.map((s) => s.id));
|
|
4841
4783
|
const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
|
|
4842
4784
|
hitInside: true,
|
|
4843
4785
|
margin: 0
|
|
4844
4786
|
}).filter(
|
|
4845
|
-
(s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !
|
|
4787
|
+
(s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !excludedIds.has(s.id)
|
|
4846
4788
|
);
|
|
4847
4789
|
for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
|
|
4848
4790
|
const shapeUtil = this.getShapeUtil(maybeDraggingOverShape);
|
|
@@ -5095,8 +5037,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5095
5037
|
for (const id of ids) {
|
|
5096
5038
|
const shape = this.getShape(id);
|
|
5097
5039
|
const localDelta = import_Vec.Vec.From(offset);
|
|
5098
|
-
|
|
5099
|
-
if (parentTransform) localDelta.rot(-parentTransform.rotation());
|
|
5040
|
+
localDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5100
5041
|
changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)));
|
|
5101
5042
|
}
|
|
5102
5043
|
this.updateShapes(changes);
|
|
@@ -5151,7 +5092,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5151
5092
|
if (!originalShape) continue;
|
|
5152
5093
|
let ox = 0;
|
|
5153
5094
|
let oy = 0;
|
|
5154
|
-
if (offset && initialIds.has(originalId)) {
|
|
5095
|
+
if (offset && initialIds.has(originalId) && !shapeIdSet.has(originalShape.parentId)) {
|
|
5155
5096
|
const parentTransform = this.getShapeParentTransform(originalShape);
|
|
5156
5097
|
const vec = new import_Vec.Vec(offset.x, offset.y).rot(-parentTransform.rotation());
|
|
5157
5098
|
ox = vec.x;
|
|
@@ -5265,26 +5206,17 @@ class Editor extends import_eventemitter3.default {
|
|
|
5265
5206
|
toggleLock(shapes) {
|
|
5266
5207
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5267
5208
|
if (this.getIsReadonly() || ids.length === 0) return this;
|
|
5268
|
-
let allLocked = true
|
|
5209
|
+
let allLocked = true;
|
|
5269
5210
|
const shapesToToggle = [];
|
|
5270
5211
|
for (const id of ids) {
|
|
5271
5212
|
const shape = this.getShape(id);
|
|
5272
5213
|
if (shape) {
|
|
5273
5214
|
shapesToToggle.push(shape);
|
|
5274
|
-
if (shape.isLocked)
|
|
5275
|
-
allUnlocked = false;
|
|
5276
|
-
} else {
|
|
5277
|
-
allLocked = false;
|
|
5278
|
-
}
|
|
5215
|
+
if (!shape.isLocked) allLocked = false;
|
|
5279
5216
|
}
|
|
5280
5217
|
}
|
|
5281
5218
|
this.run(() => {
|
|
5282
|
-
if (
|
|
5283
|
-
this.updateShapes(
|
|
5284
|
-
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
|
|
5285
|
-
);
|
|
5286
|
-
this.setSelectedShapes([]);
|
|
5287
|
-
} else if (allLocked) {
|
|
5219
|
+
if (allLocked) {
|
|
5288
5220
|
this.updateShapes(
|
|
5289
5221
|
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: false }))
|
|
5290
5222
|
);
|
|
@@ -5292,6 +5224,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5292
5224
|
this.updateShapes(
|
|
5293
5225
|
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
|
|
5294
5226
|
);
|
|
5227
|
+
this.setSelectedShapes([]);
|
|
5295
5228
|
}
|
|
5296
5229
|
});
|
|
5297
5230
|
return this;
|
|
@@ -5402,9 +5335,10 @@ class Editor extends import_eventemitter3.default {
|
|
|
5402
5335
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5403
5336
|
let freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
|
|
5404
5337
|
if (opts?.filterAxisAligned) {
|
|
5405
|
-
freshShapes = freshShapes.filter(
|
|
5406
|
-
|
|
5407
|
-
|
|
5338
|
+
freshShapes = freshShapes.filter((s) => {
|
|
5339
|
+
const remainder = Math.abs(this.getShapePageTransform(s).rotation() % import_utils2.HALF_PI);
|
|
5340
|
+
return Math.min(remainder, import_utils2.HALF_PI - remainder) < 1e-9;
|
|
5341
|
+
});
|
|
5408
5342
|
}
|
|
5409
5343
|
const clusters = [];
|
|
5410
5344
|
const allBounds = [];
|
|
@@ -5569,9 +5503,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
5569
5503
|
dim = "height";
|
|
5570
5504
|
}
|
|
5571
5505
|
let shapeGap = 0;
|
|
5506
|
+
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
5572
5507
|
if (_gap === 0) {
|
|
5573
5508
|
const gaps = {};
|
|
5574
|
-
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
5575
5509
|
for (let i = 0; i < len - 1; i++) {
|
|
5576
5510
|
const currCluster = shapeClustersToStack[i];
|
|
5577
5511
|
const nextCluster = shapeClustersToStack[i + 1];
|
|
@@ -5609,8 +5543,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5609
5543
|
const shapeDelta = delta.clone();
|
|
5610
5544
|
const parent = this.getShapeParent(shape);
|
|
5611
5545
|
if (parent) {
|
|
5612
|
-
|
|
5613
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5546
|
+
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5614
5547
|
}
|
|
5615
5548
|
shapeDelta.add(shape);
|
|
5616
5549
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5648,7 +5581,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5648
5581
|
}
|
|
5649
5582
|
const commonBounds = import_Box.Box.Common(allBounds);
|
|
5650
5583
|
const maxWidth = commonBounds.width;
|
|
5651
|
-
shapeClustersToPack.sort((a, b) =>
|
|
5584
|
+
shapeClustersToPack.sort((a, b) => b.pageBounds.width - a.pageBounds.width).sort((a, b) => b.pageBounds.height - a.pageBounds.height);
|
|
5652
5585
|
const startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
|
|
5653
5586
|
const spaces = [new import_Box.Box(commonBounds.x, commonBounds.y, startWidth, Infinity)];
|
|
5654
5587
|
let width = 0;
|
|
@@ -5696,8 +5629,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5696
5629
|
const shapeDelta = delta.clone();
|
|
5697
5630
|
const parent = this.getShapeParent(shape);
|
|
5698
5631
|
if (parent) {
|
|
5699
|
-
|
|
5700
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5632
|
+
shapeDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5701
5633
|
}
|
|
5702
5634
|
shapeDelta.add(shape);
|
|
5703
5635
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5763,8 +5695,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5763
5695
|
const shapeDelta = delta.clone();
|
|
5764
5696
|
const parent = this.getShapeParent(shape);
|
|
5765
5697
|
if (parent) {
|
|
5766
|
-
|
|
5767
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5698
|
+
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5768
5699
|
}
|
|
5769
5700
|
shapeDelta.add(shape);
|
|
5770
5701
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5838,8 +5769,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5838
5769
|
const shapeDelta = delta.clone();
|
|
5839
5770
|
const parent = this.getShapeParent(shape);
|
|
5840
5771
|
if (parent) {
|
|
5841
|
-
|
|
5842
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5772
|
+
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5843
5773
|
}
|
|
5844
5774
|
shapeDelta.add(shape);
|
|
5845
5775
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5894,8 +5824,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5894
5824
|
scale[val] = commonBounds[dim] / pageBounds[dim];
|
|
5895
5825
|
for (const shape of shapes2) {
|
|
5896
5826
|
const shapeLocalOffset = localOffset.clone();
|
|
5897
|
-
|
|
5898
|
-
if (parentTransform) shapeLocalOffset.rot(-parentTransform.rotation());
|
|
5827
|
+
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5899
5828
|
shapeLocalOffset.add(shape);
|
|
5900
5829
|
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5901
5830
|
this.updateShape(changes);
|
|
@@ -5951,8 +5880,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5951
5880
|
);
|
|
5952
5881
|
for (const shape of shapes2) {
|
|
5953
5882
|
const shapeLocalOffset = localOffset.clone();
|
|
5954
|
-
|
|
5955
|
-
if (parentTransform) shapeLocalOffset.rot(-parentTransform.rotation());
|
|
5883
|
+
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5956
5884
|
shapeLocalOffset.add(shape);
|
|
5957
5885
|
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5958
5886
|
this.updateShape(changes);
|
|
@@ -6001,9 +5929,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6001
5929
|
const scaleOrigin = opts.scaleOrigin ?? this.getShapePageBounds(id)?.center;
|
|
6002
5930
|
if (!scaleOrigin) return null;
|
|
6003
5931
|
const pageTransform = opts.initialPageTransform ? import_Mat.Mat.Cast(opts.initialPageTransform) : this.getShapePageTransform(id);
|
|
6004
|
-
if (!pageTransform) return null;
|
|
6005
5932
|
const pageRotation = pageTransform.rotation();
|
|
6006
|
-
if (pageRotation == null) return null;
|
|
6007
5933
|
const scaleAxisRotation = opts.scaleAxisRotation ?? pageRotation;
|
|
6008
5934
|
const initialBounds = opts.initialBounds ?? this.getShapeGeometry(id).bounds;
|
|
6009
5935
|
if (!initialBounds) return null;
|
|
@@ -6154,7 +6080,6 @@ class Editor extends import_eventemitter3.default {
|
|
|
6154
6080
|
const currentLocalBounds = this.getShapeGeometry(id).bounds;
|
|
6155
6081
|
const currentPageCenter = import_Mat.Mat.applyToPoint(pageTransform, currentLocalBounds.center);
|
|
6156
6082
|
const shapePageTransformOrigin = pageTransform.point();
|
|
6157
|
-
if (!currentPageCenter || !shapePageTransformOrigin) return this;
|
|
6158
6083
|
const pageDelta = import_Vec.Vec.Sub(postScaleShapePageCenter, currentPageCenter);
|
|
6159
6084
|
const postScaleShapePagePoint = import_Vec.Vec.Add(shapePageTransformOrigin, pageDelta);
|
|
6160
6085
|
const { x, y } = this.getPointInParentSpace(id, postScaleShapePagePoint);
|
|
@@ -6413,10 +6338,10 @@ class Editor extends import_eventemitter3.default {
|
|
|
6413
6338
|
if (animationIdForShape !== animationId) continue;
|
|
6414
6339
|
updates.push({
|
|
6415
6340
|
...end,
|
|
6416
|
-
x: start.x
|
|
6417
|
-
y: start.y
|
|
6418
|
-
opacity: start.opacity
|
|
6419
|
-
rotation: start.rotation
|
|
6341
|
+
x: (0, import_utils.lerp)(start.x, end.x, t),
|
|
6342
|
+
y: (0, import_utils.lerp)(start.y, end.y, t),
|
|
6343
|
+
opacity: (0, import_utils.lerp)(start.opacity, end.opacity, t),
|
|
6344
|
+
rotation: (0, import_utils.lerp)(start.rotation, end.rotation, t),
|
|
6420
6345
|
props: this.getShapeUtil(end).getInterpolatedProps?.(start, end, t) ?? end.props
|
|
6421
6346
|
});
|
|
6422
6347
|
}
|
|
@@ -6542,7 +6467,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6542
6467
|
* @public
|
|
6543
6468
|
*/
|
|
6544
6469
|
updateShapes(partials) {
|
|
6545
|
-
const compactedPartials =
|
|
6470
|
+
const compactedPartials = [];
|
|
6546
6471
|
for (let i = 0, n = partials.length; i < n; i++) {
|
|
6547
6472
|
const partial = partials[i];
|
|
6548
6473
|
if (!partial) continue;
|
|
@@ -6613,28 +6538,32 @@ class Editor extends import_eventemitter3.default {
|
|
|
6613
6538
|
}
|
|
6614
6539
|
/* --------------------- Styles --------------------- */
|
|
6615
6540
|
/**
|
|
6616
|
-
*
|
|
6541
|
+
* Groups have no styles of their own: a style read or write on a selection applies to the
|
|
6542
|
+
* non-group shapes beneath each group, however deeply nested. Returns those shapes.
|
|
6617
6543
|
*
|
|
6618
6544
|
* @internal
|
|
6619
6545
|
*/
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
if (
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6546
|
+
_getStyleableShapes(shapes) {
|
|
6547
|
+
const result = [];
|
|
6548
|
+
const visit = (shape) => {
|
|
6549
|
+
if (this.isShapeOfType(shape, "group")) {
|
|
6550
|
+
for (const childId of this.getSortedChildIdsForParent(shape.id)) {
|
|
6551
|
+
const child = this.getShape(childId);
|
|
6552
|
+
if (child) visit(child);
|
|
6553
|
+
}
|
|
6554
|
+
} else {
|
|
6555
|
+
result.push(shape);
|
|
6630
6556
|
}
|
|
6631
|
-
}
|
|
6557
|
+
};
|
|
6558
|
+
for (const shape of shapes) visit(shape);
|
|
6559
|
+
return result;
|
|
6632
6560
|
}
|
|
6633
6561
|
_getSelectionSharedStyles() {
|
|
6634
|
-
const selectedShapes = this.getSelectedShapes();
|
|
6635
6562
|
const sharedStyles = new import_SharedStylesMap.SharedStyleMap();
|
|
6636
|
-
for (const
|
|
6637
|
-
|
|
6563
|
+
for (const shape of this._getStyleableShapes(this.getSelectedShapes())) {
|
|
6564
|
+
for (const [style, propKey] of this.styleProps[shape.type]) {
|
|
6565
|
+
sharedStyles.applyValue(style, (0, import_utils.getOwnProperty)(shape.props, propKey));
|
|
6566
|
+
}
|
|
6638
6567
|
}
|
|
6639
6568
|
return sharedStyles;
|
|
6640
6569
|
}
|
|
@@ -6666,38 +6595,16 @@ class Editor extends import_eventemitter3.default {
|
|
|
6666
6595
|
const styles = new import_SharedStylesMap.SharedStyleMap();
|
|
6667
6596
|
if (!currentTool) return styles;
|
|
6668
6597
|
if (currentTool.shapeType) {
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
if (style.id === "tldraw:color") continue;
|
|
6672
|
-
styles.applyValue(style, this.getStyleForNextShape(style));
|
|
6673
|
-
}
|
|
6674
|
-
} else {
|
|
6675
|
-
for (const style of this.styleProps[currentTool.shapeType].keys()) {
|
|
6676
|
-
styles.applyValue(style, this.getStyleForNextShape(style));
|
|
6677
|
-
}
|
|
6598
|
+
for (const style of this.styleProps[currentTool.shapeType].keys()) {
|
|
6599
|
+
styles.applyValue(style, this.getStyleForNextShape(style));
|
|
6678
6600
|
}
|
|
6679
6601
|
}
|
|
6680
6602
|
return styles;
|
|
6681
6603
|
}
|
|
6682
6604
|
getSharedOpacity() {
|
|
6683
6605
|
if (this.isIn("select") && this.getSelectedShapeIds().length > 0) {
|
|
6684
|
-
const shapesToCheck = [];
|
|
6685
|
-
const addShape = (shapeId) => {
|
|
6686
|
-
const shape = this.getShape(shapeId);
|
|
6687
|
-
if (!shape) return;
|
|
6688
|
-
if (this.isShapeOfType(shape, "group")) {
|
|
6689
|
-
for (const childId of this.getSortedChildIdsForParent(shape.id)) {
|
|
6690
|
-
addShape(childId);
|
|
6691
|
-
}
|
|
6692
|
-
} else {
|
|
6693
|
-
shapesToCheck.push(shape);
|
|
6694
|
-
}
|
|
6695
|
-
};
|
|
6696
|
-
for (const shapeId of this.getSelectedShapeIds()) {
|
|
6697
|
-
addShape(shapeId);
|
|
6698
|
-
}
|
|
6699
6606
|
let opacity = null;
|
|
6700
|
-
for (const shape of
|
|
6607
|
+
for (const shape of this._getStyleableShapes(this.getSelectedShapes())) {
|
|
6701
6608
|
if (opacity === null) {
|
|
6702
6609
|
opacity = shape.opacity;
|
|
6703
6610
|
} else if (opacity !== shape.opacity) {
|
|
@@ -6736,28 +6643,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
6736
6643
|
setOpacityForSelectedShapes(opacity) {
|
|
6737
6644
|
const selectedShapes = this.getSelectedShapes();
|
|
6738
6645
|
if (selectedShapes.length > 0) {
|
|
6739
|
-
const shapesToUpdate = [];
|
|
6740
|
-
const addShapeById = (shape) => {
|
|
6741
|
-
if (this.isShapeOfType(shape, "group")) {
|
|
6742
|
-
const childIds = this.getSortedChildIdsForParent(shape);
|
|
6743
|
-
for (const childId of childIds) {
|
|
6744
|
-
addShapeById(this.getShape(childId));
|
|
6745
|
-
}
|
|
6746
|
-
} else {
|
|
6747
|
-
shapesToUpdate.push(shape);
|
|
6748
|
-
}
|
|
6749
|
-
};
|
|
6750
|
-
for (const id of selectedShapes) {
|
|
6751
|
-
addShapeById(id);
|
|
6752
|
-
}
|
|
6753
6646
|
this.updateShapes(
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
};
|
|
6760
|
-
})
|
|
6647
|
+
this._getStyleableShapes(selectedShapes).map((shape) => ({
|
|
6648
|
+
id: shape.id,
|
|
6649
|
+
type: shape.type,
|
|
6650
|
+
opacity
|
|
6651
|
+
}))
|
|
6761
6652
|
);
|
|
6762
6653
|
}
|
|
6763
6654
|
return this;
|
|
@@ -6802,33 +6693,17 @@ class Editor extends import_eventemitter3.default {
|
|
|
6802
6693
|
const selectedShapes = this.getSelectedShapes();
|
|
6803
6694
|
if (selectedShapes.length > 0) {
|
|
6804
6695
|
const updates = [];
|
|
6805
|
-
const
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
const stylePropKey = this.styleProps[shape.type].get(style);
|
|
6814
|
-
if (stylePropKey) {
|
|
6815
|
-
const shapePartial = {
|
|
6816
|
-
id: shape.id,
|
|
6817
|
-
type: shape.type,
|
|
6818
|
-
props: { [stylePropKey]: value }
|
|
6819
|
-
};
|
|
6820
|
-
updates.push({
|
|
6821
|
-
util,
|
|
6822
|
-
originalShape: shape,
|
|
6823
|
-
updatePartial: shapePartial
|
|
6824
|
-
});
|
|
6825
|
-
}
|
|
6696
|
+
for (const shape of this._getStyleableShapes(selectedShapes)) {
|
|
6697
|
+
const stylePropKey = this.styleProps[shape.type].get(style);
|
|
6698
|
+
if (stylePropKey) {
|
|
6699
|
+
updates.push({
|
|
6700
|
+
id: shape.id,
|
|
6701
|
+
type: shape.type,
|
|
6702
|
+
props: { [stylePropKey]: value }
|
|
6703
|
+
});
|
|
6826
6704
|
}
|
|
6827
|
-
};
|
|
6828
|
-
for (const shape of selectedShapes) {
|
|
6829
|
-
addShapeById(shape);
|
|
6830
6705
|
}
|
|
6831
|
-
this.updateShapes(updates
|
|
6706
|
+
this.updateShapes(updates);
|
|
6832
6707
|
}
|
|
6833
6708
|
return this;
|
|
6834
6709
|
}
|
|
@@ -7224,7 +7099,6 @@ class Editor extends import_eventemitter3.default {
|
|
|
7224
7099
|
if (shapeIdMap.has(newShape.parentId)) {
|
|
7225
7100
|
newShape.parentId = shapeIdMap.get(oldShape.parentId);
|
|
7226
7101
|
} else {
|
|
7227
|
-
rootShapeIds.push(newShape.id);
|
|
7228
7102
|
newShape.index = index;
|
|
7229
7103
|
index = (0, import_utils.getIndexAbove)(index);
|
|
7230
7104
|
}
|
|
@@ -7249,8 +7123,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
7249
7123
|
continue;
|
|
7250
7124
|
}
|
|
7251
7125
|
if (asset.type === "image" && asset.props.src?.startsWith("data:image") || asset.type === "video" && asset.props.src?.startsWith("data:video")) {
|
|
7252
|
-
assetsToUpdate.push(
|
|
7253
|
-
|
|
7126
|
+
assetsToUpdate.push(asset);
|
|
7127
|
+
const assetWithoutSrc = (0, import_utils.structuredClone)(asset);
|
|
7128
|
+
assetWithoutSrc.props.src = null;
|
|
7129
|
+
assetsToCreate.push(assetWithoutSrc);
|
|
7130
|
+
continue;
|
|
7254
7131
|
}
|
|
7255
7132
|
assetsToCreate.push(asset);
|
|
7256
7133
|
}
|
|
@@ -8077,7 +7954,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
8077
7954
|
if (info.type === "misc") {
|
|
8078
7955
|
if (info.name === "cancel" || info.name === "complete") {
|
|
8079
7956
|
this.inputs.setIsDragging(false);
|
|
8080
|
-
if (this.inputs.getIsPanning()) {
|
|
7957
|
+
if (this.inputs.getIsPanning() && !this.inputs.keys.has("Space")) {
|
|
8081
7958
|
this.inputs.setIsPanning(false);
|
|
8082
7959
|
this.inputs.setIsSpacebarPanning(false);
|
|
8083
7960
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
@@ -8829,10 +8706,9 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
8829
8706
|
}
|
|
8830
8707
|
function getCameraFitXFitY(editor, cameraOptions) {
|
|
8831
8708
|
if (!cameraOptions.constraints) throw Error("Should have constraints here");
|
|
8832
|
-
const {
|
|
8833
|
-
padding: { x: px, y: py }
|
|
8834
|
-
} = cameraOptions.constraints;
|
|
8835
8709
|
const vsb = editor.getViewportScreenBounds();
|
|
8710
|
+
const px = Math.min(cameraOptions.constraints.padding.x, vsb.w / 2);
|
|
8711
|
+
const py = Math.min(cameraOptions.constraints.padding.y, vsb.h / 2);
|
|
8836
8712
|
const bounds = import_Box.Box.From(cameraOptions.constraints.bounds);
|
|
8837
8713
|
const zx = (vsb.w - px * 2) / bounds.w;
|
|
8838
8714
|
const zy = (vsb.h - py * 2) / bounds.h;
|