@tldraw/editor 3.14.0-canary.8141719daaf3 → 3.14.0-canary.8704233e0ed5
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 +133 -18
- package/dist-cjs/index.js +5 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +81 -25
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +3 -1
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +3 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +0 -10
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +13 -6
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
- package/dist-cjs/lib/editor/tools/StateNode.js +3 -3
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/hooks/useCanvasEvents.js +1 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditor.js +1 -4
- package/dist-cjs/lib/hooks/useEditor.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +6 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Group2d.js +11 -6
- package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
- package/dist-cjs/lib/utils/dom.js +1 -1
- package/dist-cjs/lib/utils/dom.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +232 -0
- package/dist-cjs/lib/utils/reparenting.js.map +7 -0
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +133 -18
- package/dist-esm/index.mjs +11 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +81 -25
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +3 -1
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +3 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +0 -10
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +13 -6
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
- package/dist-esm/lib/editor/tools/StateNode.mjs +3 -3
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +1 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditor.mjs +1 -4
- package/dist-esm/lib/hooks/useEditor.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +6 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +11 -6
- package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
- package/dist-esm/lib/utils/dom.mjs +1 -1
- package/dist-esm/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +216 -0
- package/dist-esm/lib/utils/reparenting.mjs.map +7 -0
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +34 -12
- package/package.json +7 -7
- package/src/index.ts +13 -1
- package/src/lib/editor/Editor.ts +101 -36
- package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +3 -1
- package/src/lib/editor/managers/TextManager/TextManager.ts +4 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +47 -15
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +25 -17
- package/src/lib/editor/tools/StateNode.ts +3 -3
- package/src/lib/editor/types/emit-types.ts +4 -0
- package/src/lib/editor/types/external-content.ts +11 -2
- package/src/lib/hooks/useCanvasEvents.ts +0 -1
- package/src/lib/hooks/useEditor.tsx +6 -5
- package/src/lib/primitives/geometry/Geometry2d.ts +7 -2
- package/src/lib/primitives/geometry/Group2d.ts +11 -5
- package/src/lib/utils/dom.ts +1 -1
- package/src/lib/utils/reparenting.ts +383 -0
- package/src/version.ts +3 -3
- package/CHANGELOG.md +0 -4327
|
@@ -357,6 +357,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
357
357
|
__publicField(this, "externalContentHandlers", {
|
|
358
358
|
text: null,
|
|
359
359
|
files: null,
|
|
360
|
+
"file-replace": null,
|
|
360
361
|
embed: null,
|
|
361
362
|
"svg-text": null,
|
|
362
363
|
url: null,
|
|
@@ -1675,6 +1676,19 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1675
1676
|
getSelectionPageBounds() {
|
|
1676
1677
|
return this.getShapesPageBounds(this.getSelectedShapeIds());
|
|
1677
1678
|
}
|
|
1679
|
+
/**
|
|
1680
|
+
* The bounds of the selection bounding box in the current page space.
|
|
1681
|
+
*
|
|
1682
|
+
* @readonly
|
|
1683
|
+
* @public
|
|
1684
|
+
*/
|
|
1685
|
+
getSelectionScreenBounds() {
|
|
1686
|
+
const bounds = this.getSelectionPageBounds();
|
|
1687
|
+
if (!bounds) return void 0;
|
|
1688
|
+
const { x, y } = this.pageToScreen(bounds.point);
|
|
1689
|
+
const zoom = this.getZoomLevel();
|
|
1690
|
+
return new Box(x, y, bounds.width * zoom, bounds.height * zoom);
|
|
1691
|
+
}
|
|
1678
1692
|
/**
|
|
1679
1693
|
* @internal
|
|
1680
1694
|
*/
|
|
@@ -2808,7 +2822,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2808
2822
|
* @public
|
|
2809
2823
|
*/
|
|
2810
2824
|
updateViewportScreenBounds(screenBounds, center = false) {
|
|
2811
|
-
if (screenBounds instanceof
|
|
2825
|
+
if (!(screenBounds instanceof Box)) {
|
|
2812
2826
|
const rect = screenBounds.getBoundingClientRect();
|
|
2813
2827
|
screenBounds = new Box(
|
|
2814
2828
|
rect.left || rect.x,
|
|
@@ -4151,7 +4165,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4151
4165
|
if (!id) return void 0;
|
|
4152
4166
|
const freshShape = this.getShape(id);
|
|
4153
4167
|
if (freshShape === void 0 || !isShapeId(freshShape.parentId)) return void 0;
|
|
4154
|
-
return this.
|
|
4168
|
+
return this.getShape(freshShape.parentId);
|
|
4155
4169
|
}
|
|
4156
4170
|
/**
|
|
4157
4171
|
* If siblingShape and targetShape are siblings, this returns targetShape. If targetShape has an
|
|
@@ -4283,6 +4297,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4283
4297
|
if (!pagePoint) continue;
|
|
4284
4298
|
const newPoint = invertedParentTransform.applyToPoint(pagePoint);
|
|
4285
4299
|
const newRotation = pageTransform.rotation() - parentPageRotation;
|
|
4300
|
+
if (shape.id === parentId) {
|
|
4301
|
+
throw Error("Attempted to reparent a shape to itself!");
|
|
4302
|
+
}
|
|
4286
4303
|
changes.push({
|
|
4287
4304
|
id: shape.id,
|
|
4288
4305
|
type: shape.type,
|
|
@@ -4375,6 +4392,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4375
4392
|
}
|
|
4376
4393
|
return shapeIds;
|
|
4377
4394
|
}
|
|
4395
|
+
/** @deprecated Use {@link Editor.getDraggingOverShape} instead */
|
|
4396
|
+
getDroppingOverShape(point, droppingShapes) {
|
|
4397
|
+
return this.getDraggingOverShape(point, droppingShapes);
|
|
4398
|
+
}
|
|
4378
4399
|
/**
|
|
4379
4400
|
* Get the shape that some shapes should be dropped on at a given point.
|
|
4380
4401
|
*
|
|
@@ -4385,22 +4406,20 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4385
4406
|
*
|
|
4386
4407
|
* @public
|
|
4387
4408
|
*/
|
|
4388
|
-
|
|
4389
|
-
const
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
if (maskedPageBounds && maskedPageBounds.containsPoint(point) && this.getShapeGeometry(shape).hitTestPoint(this.getPointInShapeSpace(shape, point), 0, true)) {
|
|
4403
|
-
return shape;
|
|
4409
|
+
getDraggingOverShape(point, droppingShapes) {
|
|
4410
|
+
const draggingShapes = compact(droppingShapes.map((s) => this.getShape(s))).filter(
|
|
4411
|
+
(s) => !s.isLocked && !this.isShapeHidden(s)
|
|
4412
|
+
);
|
|
4413
|
+
const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
|
|
4414
|
+
hitInside: true,
|
|
4415
|
+
margin: 0
|
|
4416
|
+
}).filter(
|
|
4417
|
+
(s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !draggingShapes.includes(s)
|
|
4418
|
+
);
|
|
4419
|
+
for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
|
|
4420
|
+
const shapeUtil = this.getShapeUtil(maybeDraggingOverShape);
|
|
4421
|
+
if (shapeUtil.onDragShapesOver || shapeUtil.onDragShapesIn || shapeUtil.onDragShapesOut || shapeUtil.onDropShapesOver) {
|
|
4422
|
+
return maybeDraggingOverShape;
|
|
4404
4423
|
}
|
|
4405
4424
|
}
|
|
4406
4425
|
}
|
|
@@ -4677,7 +4696,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4677
4696
|
*/
|
|
4678
4697
|
duplicateShapes(shapes, offset) {
|
|
4679
4698
|
this.run(() => {
|
|
4680
|
-
const
|
|
4699
|
+
const _ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4700
|
+
const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
|
|
4681
4701
|
if (ids.length <= 0) return this;
|
|
4682
4702
|
const initialIds = new Set(ids);
|
|
4683
4703
|
const shapeIdSet = this.getShapeAndDescendantIds(ids);
|
|
@@ -4741,8 +4761,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4741
4761
|
shape.index = index;
|
|
4742
4762
|
});
|
|
4743
4763
|
const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape);
|
|
4744
|
-
|
|
4745
|
-
if (maxShapesReached) {
|
|
4764
|
+
if (!this.canCreateShapes(shapesToCreate)) {
|
|
4746
4765
|
alertMaxShapes(this);
|
|
4747
4766
|
return;
|
|
4748
4767
|
}
|
|
@@ -5757,6 +5776,26 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5757
5776
|
getInitialMetaForShape(_shape) {
|
|
5758
5777
|
return {};
|
|
5759
5778
|
}
|
|
5779
|
+
/**
|
|
5780
|
+
* Get whether the provided shape can be created.
|
|
5781
|
+
*
|
|
5782
|
+
* @param shape - The shape or shape IDs to check.
|
|
5783
|
+
*
|
|
5784
|
+
* @public
|
|
5785
|
+
*/
|
|
5786
|
+
canCreateShape(shape) {
|
|
5787
|
+
return this.canCreateShapes([shape]);
|
|
5788
|
+
}
|
|
5789
|
+
/**
|
|
5790
|
+
* Get whether the provided shapes can be created.
|
|
5791
|
+
*
|
|
5792
|
+
* @param shapes - The shapes or shape IDs to create.
|
|
5793
|
+
*
|
|
5794
|
+
* @public
|
|
5795
|
+
*/
|
|
5796
|
+
canCreateShapes(shapes) {
|
|
5797
|
+
return shapes.length + this.getCurrentPageShapeIds().size <= this.options.maxShapesPerPage;
|
|
5798
|
+
}
|
|
5760
5799
|
/**
|
|
5761
5800
|
* Create a single shape.
|
|
5762
5801
|
*
|
|
@@ -5810,7 +5849,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5810
5849
|
let parentId = this.getFocusedGroupId();
|
|
5811
5850
|
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
5812
5851
|
const parent = currentPageShapesSorted[i];
|
|
5813
|
-
|
|
5852
|
+
const util = this.getShapeUtil(parent);
|
|
5853
|
+
if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
|
|
5814
5854
|
parent,
|
|
5815
5855
|
// If no parent is provided, then we can treat the
|
|
5816
5856
|
// shape's provided x/y as being in the page's space.
|
|
@@ -5885,6 +5925,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5885
5925
|
...shape.meta
|
|
5886
5926
|
};
|
|
5887
5927
|
});
|
|
5928
|
+
this.emit("created-shapes", shapeRecordsToCreate);
|
|
5929
|
+
this.emit("edit");
|
|
5888
5930
|
this.store.put(shapeRecordsToCreate);
|
|
5889
5931
|
});
|
|
5890
5932
|
return this;
|
|
@@ -6126,6 +6168,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6126
6168
|
updated = this.getShapeUtil(shape).onBeforeUpdate?.(shape, updated) ?? updated;
|
|
6127
6169
|
updates.push(updated);
|
|
6128
6170
|
}
|
|
6171
|
+
this.emit("edited-shapes", updates);
|
|
6172
|
+
this.emit("edit");
|
|
6129
6173
|
this.store.put(updates);
|
|
6130
6174
|
});
|
|
6131
6175
|
}
|
|
@@ -6147,6 +6191,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6147
6191
|
allShapeIdsToDelete.add(childId);
|
|
6148
6192
|
});
|
|
6149
6193
|
}
|
|
6194
|
+
this.emit("deleted-shapes", [...allShapeIdsToDelete]);
|
|
6195
|
+
this.emit("edit");
|
|
6150
6196
|
return this.run(() => this.store.remove([...allShapeIdsToDelete]));
|
|
6151
6197
|
}
|
|
6152
6198
|
deleteShape(_id) {
|
|
@@ -6490,6 +6536,14 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6490
6536
|
async putExternalContent(info) {
|
|
6491
6537
|
return this.externalContentHandlers[info.type]?.(info);
|
|
6492
6538
|
}
|
|
6539
|
+
/**
|
|
6540
|
+
* Handle replacing external content.
|
|
6541
|
+
*
|
|
6542
|
+
* @param info - Info about the external content.
|
|
6543
|
+
*/
|
|
6544
|
+
async replaceExternalContent(info) {
|
|
6545
|
+
return this.externalContentHandlers[info.type]?.(info);
|
|
6546
|
+
}
|
|
6493
6547
|
/**
|
|
6494
6548
|
* Get content that can be exported for the given shape ids.
|
|
6495
6549
|
*
|
|
@@ -6907,7 +6961,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6907
6961
|
previousScreenPoint,
|
|
6908
6962
|
previousPagePoint,
|
|
6909
6963
|
currentScreenPoint,
|
|
6910
|
-
currentPagePoint
|
|
6964
|
+
currentPagePoint,
|
|
6965
|
+
originScreenPoint,
|
|
6966
|
+
originPagePoint
|
|
6911
6967
|
} = this.inputs;
|
|
6912
6968
|
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
6913
6969
|
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
|
|
@@ -6925,8 +6981,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6925
6981
|
this.inputs.isPen = info.type === "pointer" && info.isPen;
|
|
6926
6982
|
if (info.name === "pointer_down" || this.inputs.isPinching) {
|
|
6927
6983
|
pointerVelocity.set(0, 0);
|
|
6928
|
-
|
|
6929
|
-
|
|
6984
|
+
originScreenPoint.setTo(currentScreenPoint);
|
|
6985
|
+
originPagePoint.setTo(currentPagePoint);
|
|
6930
6986
|
}
|
|
6931
6987
|
this.run(
|
|
6932
6988
|
() => {
|