@tldraw/editor 3.13.0-canary.2928a5d81c67 → 3.13.0-canary.2b3a9b59ae37
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 +15 -2
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +10 -6
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +45 -9
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +1 -1
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +0 -3
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js +1 -2
- package/dist-cjs/lib/hooks/useEditorComponents.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 +15 -2
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +10 -6
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +45 -9
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +1 -1
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +0 -3
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +1 -4
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +7 -0
- package/package.json +7 -7
- package/src/lib/components/default-components/DefaultCanvas.tsx +11 -6
- package/src/lib/editor/Editor.ts +56 -9
- package/src/lib/editor/shapes/ShapeUtil.ts +1 -1
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +0 -4
- package/src/lib/hooks/useEditorComponents.tsx +2 -5
- package/src/version.ts +3 -3
|
@@ -1475,9 +1475,23 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1475
1475
|
this.setSelectedShapes(this._getUnlockedShapeIds(ids));
|
|
1476
1476
|
return this;
|
|
1477
1477
|
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Select the next shape in the reading order or in cardinal order.
|
|
1480
|
+
*
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* editor.selectAdjacentShape('next')
|
|
1484
|
+
* ```
|
|
1485
|
+
*
|
|
1486
|
+
* @public
|
|
1487
|
+
*/
|
|
1478
1488
|
selectAdjacentShape(direction) {
|
|
1479
|
-
const readingOrderShapes = this.getCurrentPageShapesInReadingOrder();
|
|
1480
1489
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1490
|
+
const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
|
|
1491
|
+
const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !isPageId(firstParentId);
|
|
1492
|
+
const readingOrderShapes = isSelectedWithinContainer ? this._getShapesInReadingOrder(
|
|
1493
|
+
this.getCurrentPageShapes().filter((shape2) => shape2.parentId === firstParentId)
|
|
1494
|
+
) : this.getCurrentPageShapesInReadingOrder();
|
|
1481
1495
|
const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
|
|
1482
1496
|
let adjacentShapeId;
|
|
1483
1497
|
if (direction === "next" || direction === "prev") {
|
|
@@ -1491,18 +1505,15 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1491
1505
|
}
|
|
1492
1506
|
const shape = this.getShape(adjacentShapeId);
|
|
1493
1507
|
if (!shape) return;
|
|
1494
|
-
this.
|
|
1495
|
-
this.zoomToSelectionIfOffscreen(256, {
|
|
1496
|
-
animation: {
|
|
1497
|
-
duration: this.options.animationMediumMs
|
|
1498
|
-
},
|
|
1499
|
-
inset: 0
|
|
1500
|
-
});
|
|
1508
|
+
this._selectShapesAndZoom([shape.id]);
|
|
1501
1509
|
}
|
|
1502
1510
|
getCurrentPageShapesInReadingOrder() {
|
|
1511
|
+
const shapes = this.getCurrentPageShapes().filter((shape) => isPageId(shape.parentId));
|
|
1512
|
+
return this._getShapesInReadingOrder(shapes);
|
|
1513
|
+
}
|
|
1514
|
+
_getShapesInReadingOrder(shapes) {
|
|
1503
1515
|
const SHALLOW_ANGLE = 20;
|
|
1504
1516
|
const ROW_THRESHOLD = 100;
|
|
1505
|
-
const shapes = this.getCurrentPageShapes();
|
|
1506
1517
|
const tabbableShapes = shapes.filter((shape) => this.getShapeUtil(shape).canTabTo(shape));
|
|
1507
1518
|
if (tabbableShapes.length <= 1) return tabbableShapes;
|
|
1508
1519
|
const shapesWithCenters = tabbableShapes.map((shape) => ({
|
|
@@ -1600,6 +1611,31 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1600
1611
|
});
|
|
1601
1612
|
return lowestScoringShape.shape.id;
|
|
1602
1613
|
}
|
|
1614
|
+
selectParentShape() {
|
|
1615
|
+
const selectedShape = this.getOnlySelectedShape();
|
|
1616
|
+
if (!selectedShape) return;
|
|
1617
|
+
const parentShape = this.getShape(selectedShape.parentId);
|
|
1618
|
+
if (!parentShape) return;
|
|
1619
|
+
this._selectShapesAndZoom([parentShape.id]);
|
|
1620
|
+
}
|
|
1621
|
+
selectFirstChildShape() {
|
|
1622
|
+
const selectedShapes = this.getSelectedShapes();
|
|
1623
|
+
if (!selectedShapes.length) return;
|
|
1624
|
+
const selectedShape = selectedShapes[0];
|
|
1625
|
+
const children = this.getSortedChildIdsForParent(selectedShape.id).map((id) => this.getShape(id)).filter((i) => i);
|
|
1626
|
+
const sortedChildren = this._getShapesInReadingOrder(children);
|
|
1627
|
+
if (sortedChildren.length === 0) return;
|
|
1628
|
+
this._selectShapesAndZoom([sortedChildren[0].id]);
|
|
1629
|
+
}
|
|
1630
|
+
_selectShapesAndZoom(ids) {
|
|
1631
|
+
this.setSelectedShapes(ids);
|
|
1632
|
+
this.zoomToSelectionIfOffscreen(256, {
|
|
1633
|
+
animation: {
|
|
1634
|
+
duration: this.options.animationMediumMs
|
|
1635
|
+
},
|
|
1636
|
+
inset: 0
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1603
1639
|
/**
|
|
1604
1640
|
* Clear the selection.
|
|
1605
1641
|
*
|