@tldraw/editor 3.16.0-internal.51e99e128bd4 → 3.16.0-internal.a478398270c6
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 +16 -217
- package/dist-cjs/index.js +1 -8
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +1 -3
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +5 -0
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/SVGContainer.js +1 -1
- package/dist-cjs/lib/components/SVGContainer.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +26 -4
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultBrush.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCursor.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCursor.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 +2 -2
- package/dist-cjs/lib/components/default-components/DefaultGrid.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultGrid.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultHandles.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultHandles.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +1 -9
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js +15 -27
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +3 -3
- package/dist-cjs/lib/config/TLUserPreferences.js +3 -15
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +67 -134
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +4 -14
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +1 -20
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +2 -1
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +20 -24
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditor.js +4 -1
- package/dist-cjs/lib/hooks/useEditor.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js +0 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +8 -8
- package/dist-cjs/lib/license/Watermark.js.map +2 -2
- package/dist-cjs/lib/options.js +0 -7
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +1 -3
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/geometry-constants.js +2 -2
- package/dist-cjs/lib/primitives/geometry/geometry-constants.js.map +2 -2
- package/dist-cjs/lib/primitives/intersect.js +4 -4
- package/dist-cjs/lib/primitives/intersect.js.map +2 -2
- package/dist-cjs/lib/primitives/utils.js +0 -4
- package/dist-cjs/lib/primitives/utils.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +1 -0
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.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 +16 -217
- package/dist-esm/index.mjs +2 -16
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +1 -3
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +5 -0
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/SVGContainer.mjs +1 -1
- package/dist-esm/lib/components/SVGContainer.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +26 -4
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCursor.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 +2 -2
- package/dist-esm/lib/components/default-components/DefaultGrid.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultGrid.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultHandles.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultHandles.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +1 -9
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultSpinner.mjs +15 -17
- package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs +3 -15
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +67 -134
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +4 -14
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +1 -20
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +21 -25
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditor.mjs +4 -1
- package/dist-esm/lib/hooks/useEditor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +0 -4
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +8 -8
- package/dist-esm/lib/license/Watermark.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +0 -7
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +1 -3
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/geometry-constants.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/geometry-constants.mjs.map +2 -2
- package/dist-esm/lib/primitives/intersect.mjs +5 -5
- package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
- package/dist-esm/lib/primitives/utils.mjs +0 -4
- package/dist-esm/lib/primitives/utils.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +1 -0
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +313 -312
- package/package.json +38 -16
- package/src/index.ts +1 -15
- package/src/lib/TldrawEditor.tsx +5 -7
- package/src/lib/components/MenuClickCapture.tsx +8 -0
- package/src/lib/components/SVGContainer.tsx +1 -1
- package/src/lib/components/Shape.tsx +21 -6
- package/src/lib/components/default-components/DefaultBrush.tsx +1 -1
- package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +2 -2
- package/src/lib/components/default-components/DefaultCursor.tsx +1 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/components/default-components/DefaultGrid.tsx +1 -1
- package/src/lib/components/default-components/DefaultHandles.tsx +1 -5
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +2 -6
- package/src/lib/components/default-components/DefaultSnapIndictor.tsx +1 -1
- package/src/lib/components/default-components/DefaultSpinner.tsx +12 -12
- package/src/lib/config/TLUserPreferences.ts +1 -15
- package/src/lib/editor/Editor.test.ts +8 -416
- package/src/lib/editor/Editor.ts +92 -177
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +14 -15
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +15 -16
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +48 -49
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +23 -24
- package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +6 -7
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +11 -12
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +50 -57
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +26 -51
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +13 -14
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +26 -55
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +1 -14
- package/src/lib/editor/shapes/ShapeUtil.ts +0 -57
- package/src/lib/editor/tools/StateNode.ts +1 -27
- package/src/lib/editor/types/misc-types.ts +1 -73
- package/src/lib/exports/getSvgJsx.tsx +2 -2
- package/src/lib/hooks/useCanvasEvents.ts +32 -39
- package/src/lib/hooks/useEditor.tsx +5 -6
- package/src/lib/hooks/useEditorComponents.tsx +2 -8
- package/src/lib/license/LicenseManager.test.ts +1 -3
- package/src/lib/license/Watermark.test.tsx +1 -2
- package/src/lib/license/Watermark.tsx +8 -8
- package/src/lib/options.ts +0 -8
- package/src/lib/primitives/geometry/Arc2d.ts +2 -2
- package/src/lib/primitives/geometry/Circle2d.ts +2 -2
- package/src/lib/primitives/geometry/CubicBezier2d.ts +1 -4
- package/src/lib/primitives/geometry/Ellipse2d.ts +2 -2
- package/src/lib/primitives/geometry/geometry-constants.ts +1 -2
- package/src/lib/primitives/intersect.ts +5 -12
- package/src/lib/primitives/utils.ts +0 -11
- package/src/lib/test/currentToolIdMask.test.ts +49 -0
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +1 -2
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
- package/src/lib/utils/sync/TLLocalSyncClient.ts +1 -0
- package/src/version.ts +3 -3
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +0 -53
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +0 -7
- package/dist-cjs/lib/hooks/useStateAttribute.js +0 -35
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +0 -7
- package/dist-cjs/lib/utils/EditorAtom.js +0 -45
- package/dist-cjs/lib/utils/EditorAtom.js.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +0 -23
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +0 -7
- package/dist-esm/lib/hooks/useStateAttribute.mjs +0 -15
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +0 -7
- package/dist-esm/lib/utils/EditorAtom.mjs +0 -25
- package/dist-esm/lib/utils/EditorAtom.mjs.map +0 -7
- package/src/lib/components/default-components/DefaultShapeWrapper.tsx +0 -35
- package/src/lib/editor/tools/StateNode.test.ts +0 -285
- package/src/lib/hooks/useStateAttribute.ts +0 -15
- package/src/lib/primitives/intersect.test.ts +0 -946
- package/src/lib/utils/EditorAtom.ts +0 -37
|
@@ -1432,9 +1432,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1432
1432
|
return this;
|
|
1433
1433
|
}
|
|
1434
1434
|
/**
|
|
1435
|
-
* Select all
|
|
1436
|
-
* select all shapes within that parent. If the user has not selected any shapes,
|
|
1437
|
-
* or if the shapes shapes are only on select all shapes on the current page.
|
|
1435
|
+
* Select all direct children of the current page.
|
|
1438
1436
|
*
|
|
1439
1437
|
* @example
|
|
1440
1438
|
* ```ts
|
|
@@ -1444,23 +1442,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1444
1442
|
* @public
|
|
1445
1443
|
*/
|
|
1446
1444
|
selectAll() {
|
|
1447
|
-
|
|
1448
|
-
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1449
|
-
if (selectedShapeIds.length > 0) {
|
|
1450
|
-
for (const id of selectedShapeIds) {
|
|
1451
|
-
const shape = this.getShape(id);
|
|
1452
|
-
if (!shape) continue;
|
|
1453
|
-
if (parentToSelectWithinId === null) {
|
|
1454
|
-
parentToSelectWithinId = shape.parentId;
|
|
1455
|
-
} else if (parentToSelectWithinId !== shape.parentId) {
|
|
1456
|
-
return this;
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
if (!parentToSelectWithinId) {
|
|
1461
|
-
parentToSelectWithinId = this.getCurrentPageId();
|
|
1462
|
-
}
|
|
1463
|
-
const ids = this.getSortedChildIdsForParent(parentToSelectWithinId);
|
|
1445
|
+
const ids = this.getSortedChildIdsForParent(this.getCurrentPageId());
|
|
1464
1446
|
if (ids.length <= 0) return this;
|
|
1465
1447
|
this.setSelectedShapes(this._getUnlockedShapeIds(ids));
|
|
1466
1448
|
return this;
|
|
@@ -1479,8 +1461,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1479
1461
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1480
1462
|
const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
|
|
1481
1463
|
const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !(0, import_tlschema.isPageId)(firstParentId);
|
|
1482
|
-
const
|
|
1483
|
-
|
|
1464
|
+
const readingOrderShapes = isSelectedWithinContainer ? this._getShapesInReadingOrder(
|
|
1465
|
+
this.getCurrentPageShapes().filter((shape2) => shape2.parentId === firstParentId)
|
|
1466
|
+
) : this.getCurrentPageShapesInReadingOrder();
|
|
1484
1467
|
const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
|
|
1485
1468
|
let adjacentShapeId;
|
|
1486
1469
|
if (direction === "next" || direction === "prev") {
|
|
@@ -1490,7 +1473,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1490
1473
|
adjacentShapeId = shapeIds[adjacentIndex];
|
|
1491
1474
|
} else {
|
|
1492
1475
|
if (!currentShapeId) return;
|
|
1493
|
-
adjacentShapeId = this.getNearestAdjacentShape(
|
|
1476
|
+
adjacentShapeId = this.getNearestAdjacentShape(currentShapeId, direction);
|
|
1494
1477
|
}
|
|
1495
1478
|
const shape = this.getShape(adjacentShapeId);
|
|
1496
1479
|
if (!shape) return;
|
|
@@ -1556,10 +1539,11 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
1556
1539
|
*
|
|
1557
1540
|
* @public
|
|
1558
1541
|
*/
|
|
1559
|
-
getNearestAdjacentShape(
|
|
1542
|
+
getNearestAdjacentShape(currentShapeId, direction) {
|
|
1560
1543
|
const directionToAngle = { right: 0, left: 180, down: 90, up: 270 };
|
|
1561
1544
|
const currentShape = this.getShape(currentShapeId);
|
|
1562
1545
|
if (!currentShape) return currentShapeId;
|
|
1546
|
+
const shapes = this.getCurrentPageShapes();
|
|
1563
1547
|
const tabbableShapes = shapes.filter(
|
|
1564
1548
|
(shape) => this.getShapeUtil(shape).canTabTo(shape) && shape.id !== currentShapeId
|
|
1565
1549
|
);
|
|
@@ -2323,11 +2307,28 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2323
2307
|
{ history: "ignore" }
|
|
2324
2308
|
);
|
|
2325
2309
|
const { currentScreenPoint, currentPagePoint } = this.inputs;
|
|
2310
|
+
const { screenBounds } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
|
|
2326
2311
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2312
|
+
const event = {
|
|
2313
|
+
type: "pointer",
|
|
2314
|
+
target: "canvas",
|
|
2315
|
+
name: "pointer_move",
|
|
2316
|
+
// weird but true: we need to put the screen point back into client space
|
|
2317
|
+
point: import_Vec.Vec.AddXY(currentScreenPoint, screenBounds.x, screenBounds.y),
|
|
2318
|
+
pointerId: import_constants.INTERNAL_POINTER_IDS.CAMERA_MOVE,
|
|
2319
|
+
ctrlKey: this.inputs.ctrlKey,
|
|
2320
|
+
altKey: this.inputs.altKey,
|
|
2321
|
+
shiftKey: this.inputs.shiftKey,
|
|
2322
|
+
metaKey: this.inputs.metaKey,
|
|
2323
|
+
accelKey: (0, import_keyboard.isAccelKey)(this.inputs),
|
|
2324
|
+
button: 0,
|
|
2325
|
+
isPen: this.getInstanceState().isPenMode ?? false
|
|
2326
|
+
};
|
|
2327
|
+
if (opts?.immediate) {
|
|
2328
|
+
this._flushEventForTick(event);
|
|
2329
|
+
} else {
|
|
2330
|
+
this.dispatch(event);
|
|
2331
|
+
}
|
|
2331
2332
|
}
|
|
2332
2333
|
this._tickCameraState();
|
|
2333
2334
|
});
|
|
@@ -3296,24 +3297,19 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3296
3297
|
*/
|
|
3297
3298
|
deletePage(page) {
|
|
3298
3299
|
const id = typeof page === "string" ? page : page.id;
|
|
3299
|
-
this.run(
|
|
3300
|
-
()
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
this.deleteShapes(shapes);
|
|
3313
|
-
this.store.remove([deletedPage.id]);
|
|
3314
|
-
},
|
|
3315
|
-
{ ignoreShapeLock: true }
|
|
3316
|
-
);
|
|
3300
|
+
this.run(() => {
|
|
3301
|
+
if (this.getIsReadonly()) return;
|
|
3302
|
+
const pages = this.getPages();
|
|
3303
|
+
if (pages.length === 1) return;
|
|
3304
|
+
const deletedPage = this.getPage(id);
|
|
3305
|
+
if (!deletedPage) return;
|
|
3306
|
+
if (id === this.getCurrentPageId()) {
|
|
3307
|
+
const index = pages.findIndex((page2) => page2.id === id);
|
|
3308
|
+
const next = pages[index - 1] ?? pages[index + 1];
|
|
3309
|
+
this.setCurrentPage(next.id);
|
|
3310
|
+
}
|
|
3311
|
+
this.store.remove([deletedPage.id]);
|
|
3312
|
+
});
|
|
3317
3313
|
return this;
|
|
3318
3314
|
}
|
|
3319
3315
|
/**
|
|
@@ -3910,7 +3906,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3910
3906
|
hitInside = false,
|
|
3911
3907
|
hitFrameInside = false
|
|
3912
3908
|
} = opts;
|
|
3913
|
-
const [innerMargin, outerMargin] = Array.isArray(margin) ? margin : [margin, margin];
|
|
3914
3909
|
let inHollowSmallestArea = Infinity;
|
|
3915
3910
|
let inHollowSmallestAreaHit = null;
|
|
3916
3911
|
let inMarginClosestToEdgeDistance = Infinity;
|
|
@@ -3920,7 +3915,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3920
3915
|
return false;
|
|
3921
3916
|
const pageMask = this.getShapeMask(shape);
|
|
3922
3917
|
if (pageMask && !(0, import_utils2.pointInPolygon)(point, pageMask)) return false;
|
|
3923
|
-
if (filter
|
|
3918
|
+
if (filter) return filter(shape);
|
|
3924
3919
|
return true;
|
|
3925
3920
|
});
|
|
3926
3921
|
for (let i = shapesToCheck.length - 1; i >= 0; i--) {
|
|
@@ -3928,7 +3923,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3928
3923
|
const geometry = this.getShapeGeometry(shape);
|
|
3929
3924
|
const isGroup = geometry instanceof import_Group2d.Group2d;
|
|
3930
3925
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
3931
|
-
if (this.isShapeOfType(shape, "frame") ||
|
|
3926
|
+
if (this.isShapeOfType(shape, "frame") || this.isShapeOfType(shape, "arrow") && shape.props.text.trim() || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && this.getShapeUtil(shape).getText(shape)?.trim()) {
|
|
3932
3927
|
for (const childGeometry of geometry.children) {
|
|
3933
3928
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
3934
3929
|
return shape;
|
|
@@ -3936,8 +3931,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3936
3931
|
}
|
|
3937
3932
|
}
|
|
3938
3933
|
if (this.isShapeOfType(shape, "frame")) {
|
|
3939
|
-
const distance2 = geometry.distanceToPoint(pointInShapeSpace,
|
|
3940
|
-
if (
|
|
3934
|
+
const distance2 = geometry.distanceToPoint(pointInShapeSpace, hitInside);
|
|
3935
|
+
if (Math.abs(distance2) <= margin) {
|
|
3941
3936
|
return inMarginClosestToEdgeHit || shape;
|
|
3942
3937
|
}
|
|
3943
3938
|
if (geometry.hitTestPoint(pointInShapeSpace, 0, true)) {
|
|
@@ -3957,10 +3952,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3957
3952
|
}
|
|
3958
3953
|
distance = minDistance;
|
|
3959
3954
|
} else {
|
|
3960
|
-
if (
|
|
3955
|
+
if (margin === 0 && (geometry.bounds.w < 1 || geometry.bounds.h < 1)) {
|
|
3961
3956
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside);
|
|
3962
3957
|
} else {
|
|
3963
|
-
if (geometry.bounds.containsPoint(pointInShapeSpace,
|
|
3958
|
+
if (geometry.bounds.containsPoint(pointInShapeSpace, margin)) {
|
|
3964
3959
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside);
|
|
3965
3960
|
} else {
|
|
3966
3961
|
distance = Infinity;
|
|
@@ -3968,22 +3963,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3968
3963
|
}
|
|
3969
3964
|
}
|
|
3970
3965
|
if (geometry.isClosed) {
|
|
3971
|
-
if (distance <=
|
|
3966
|
+
if (distance <= margin) {
|
|
3972
3967
|
if (geometry.isFilled || isGroup && geometry.children[0].isFilled) {
|
|
3973
3968
|
return inMarginClosestToEdgeHit || shape;
|
|
3974
3969
|
} else {
|
|
3975
3970
|
if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
|
|
3976
|
-
if (
|
|
3977
|
-
// On hitInside, the distance will be negative for hits inside
|
|
3978
|
-
// If the distance is positive, check against the outer margin
|
|
3979
|
-
distance > 0 && distance <= outerMargin || // If the distance is negative, check against the inner margin
|
|
3980
|
-
distance <= 0 && distance > -innerMargin
|
|
3981
|
-
) : (
|
|
3982
|
-
// If hitInside is false, then sadly _we do not know_ whether the
|
|
3983
|
-
// point is inside or outside of the shape, so we check against
|
|
3984
|
-
// the max of the two margins
|
|
3985
|
-
Math.abs(distance) <= Math.max(innerMargin, outerMargin)
|
|
3986
|
-
)) {
|
|
3971
|
+
if (Math.abs(distance) < margin) {
|
|
3987
3972
|
if (Math.abs(distance) < inMarginClosestToEdgeDistance) {
|
|
3988
3973
|
inMarginClosestToEdgeDistance = Math.abs(distance);
|
|
3989
3974
|
inMarginClosestToEdgeHit = shape;
|
|
@@ -4748,16 +4733,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
4748
4733
|
}
|
|
4749
4734
|
this.createShapes(shapesToCreate);
|
|
4750
4735
|
this.createBindings(bindingsToCreate);
|
|
4751
|
-
this.setSelectedShapes(
|
|
4752
|
-
(0, import_utils.compact)(
|
|
4753
|
-
ids.map((oldId) => {
|
|
4754
|
-
const newId = shapeIds.get(oldId);
|
|
4755
|
-
if (!newId) return null;
|
|
4756
|
-
if (!this.getShape(newId)) return null;
|
|
4757
|
-
return newId;
|
|
4758
|
-
})
|
|
4759
|
-
)
|
|
4760
|
-
);
|
|
4736
|
+
this.setSelectedShapes((0, import_utils.compact)(ids.map((id) => shapeIds.get(id))));
|
|
4761
4737
|
if (offset !== void 0) {
|
|
4762
4738
|
const selectionPageBounds = this.getSelectionPageBounds();
|
|
4763
4739
|
const viewportPageBounds = this.getViewportPageBounds();
|
|
@@ -5511,7 +5487,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5511
5487
|
const shapesMovingTogether = [shape];
|
|
5512
5488
|
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5513
5489
|
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
5514
|
-
type: "stretch"
|
|
5490
|
+
type: "stretch",
|
|
5491
|
+
shapes: shapesToStretchFirstPass
|
|
5515
5492
|
})) {
|
|
5516
5493
|
continue;
|
|
5517
5494
|
}
|
|
@@ -5836,24 +5813,21 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5836
5813
|
}
|
|
5837
5814
|
if (!partial.parentId || !(this.store.has(partial.parentId) || shapes.some((p) => p.id === partial.parentId))) {
|
|
5838
5815
|
let parentId = this.getFocusedGroupId();
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
margin: 0,
|
|
5851
|
-
hitInside: true
|
|
5852
|
-
}
|
|
5853
|
-
)) {
|
|
5854
|
-
parentId = parent.id;
|
|
5855
|
-
break;
|
|
5816
|
+
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
5817
|
+
const parent = currentPageShapesSorted[i];
|
|
5818
|
+
const util = this.getShapeUtil(parent);
|
|
5819
|
+
if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
|
|
5820
|
+
parent,
|
|
5821
|
+
// If no parent is provided, then we can treat the
|
|
5822
|
+
// shape's provided x/y as being in the page's space.
|
|
5823
|
+
{ x: partial.x ?? 0, y: partial.y ?? 0 },
|
|
5824
|
+
{
|
|
5825
|
+
margin: 0,
|
|
5826
|
+
hitInside: true
|
|
5856
5827
|
}
|
|
5828
|
+
)) {
|
|
5829
|
+
parentId = parent.id;
|
|
5830
|
+
break;
|
|
5857
5831
|
}
|
|
5858
5832
|
}
|
|
5859
5833
|
const prevParentId = partial.parentId;
|
|
@@ -7038,47 +7012,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7038
7012
|
this.dispatch({ type: "misc", name: "complete" });
|
|
7039
7013
|
return this;
|
|
7040
7014
|
}
|
|
7041
|
-
/**
|
|
7042
|
-
* Dispatch a pointer move event in the current position of the pointer. This is useful when
|
|
7043
|
-
* external circumstances have changed (e.g. the camera moved or a shape was moved) and you want
|
|
7044
|
-
* the current interaction to respond to that change.
|
|
7045
|
-
*
|
|
7046
|
-
* @example
|
|
7047
|
-
* ```ts
|
|
7048
|
-
* editor.updatePointer()
|
|
7049
|
-
* ```
|
|
7050
|
-
*
|
|
7051
|
-
* @param options - The options for updating the pointer.
|
|
7052
|
-
* @returns The editor instance.
|
|
7053
|
-
* @public
|
|
7054
|
-
*/
|
|
7055
|
-
updatePointer(options) {
|
|
7056
|
-
const event = {
|
|
7057
|
-
type: "pointer",
|
|
7058
|
-
target: "canvas",
|
|
7059
|
-
name: "pointer_move",
|
|
7060
|
-
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7061
|
-
// we need to convert back into true screen space first. we should fix this...
|
|
7062
|
-
import_Vec.Vec.Add(
|
|
7063
|
-
this.inputs.currentScreenPoint,
|
|
7064
|
-
this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID).screenBounds
|
|
7065
|
-
),
|
|
7066
|
-
pointerId: options?.pointerId ?? 0,
|
|
7067
|
-
button: options?.button ?? 0,
|
|
7068
|
-
isPen: options?.isPen ?? this.inputs.isPen,
|
|
7069
|
-
shiftKey: options?.shiftKey ?? this.inputs.shiftKey,
|
|
7070
|
-
altKey: options?.altKey ?? this.inputs.altKey,
|
|
7071
|
-
ctrlKey: options?.ctrlKey ?? this.inputs.ctrlKey,
|
|
7072
|
-
metaKey: options?.metaKey ?? this.inputs.metaKey,
|
|
7073
|
-
accelKey: options?.accelKey ?? (0, import_keyboard.isAccelKey)(this.inputs)
|
|
7074
|
-
};
|
|
7075
|
-
if (options?.immediate) {
|
|
7076
|
-
this._flushEventForTick(event);
|
|
7077
|
-
} else {
|
|
7078
|
-
this.dispatch(event);
|
|
7079
|
-
}
|
|
7080
|
-
return this;
|
|
7081
|
-
}
|
|
7082
7015
|
/**
|
|
7083
7016
|
* Puts the editor into focused mode.
|
|
7084
7017
|
*
|