@tldraw/editor 5.5.0-canary.d9aaed7d08b4 → 5.5.0-canary.dd5a6dc4824a
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 +1 -0
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/editor/Editor.js +68 -34
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +14 -6
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +3 -3
- package/dist-cjs/lib/exports/ExportDelay.js +10 -2
- package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
- package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +13 -17
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +78 -40
- 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 +1 -0
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/editor/Editor.mjs +68 -34
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +14 -6
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +3 -3
- package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
- package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
- package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +13 -17
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +78 -40
- 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/package.json +7 -7
- package/src/lib/editor/Editor.ts +112 -44
- package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +23 -8
- package/src/lib/exports/ExportDelay.tsx +16 -4
- package/src/lib/exports/getSvgAsImage.ts +13 -5
- package/src/lib/exports/getSvgJsx.test.ts +43 -1
- package/src/lib/exports/getSvgJsx.tsx +28 -16
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +28 -0
- package/src/lib/utils/sync/LocalIndexedDb.ts +18 -20
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +236 -0
- package/src/lib/utils/sync/TLLocalSyncClient.ts +106 -54
- package/src/version.ts +3 -3
package/dist-cjs/index.d.ts
CHANGED
|
@@ -3483,6 +3483,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3483
3483
|
deleteBindings(bindings: (TLBinding | TLBindingId)[], { isolateShapes }?: {
|
|
3484
3484
|
isolateShapes?: boolean | undefined;
|
|
3485
3485
|
}): this;
|
|
3486
|
+
/* Excluded from this release type: _deleteBindings */
|
|
3486
3487
|
/**
|
|
3487
3488
|
* Delete a binding by its ID. If the binding doesn't exist, it's ignored.
|
|
3488
3489
|
*/
|
package/dist-cjs/index.js
CHANGED
|
@@ -392,7 +392,7 @@ var import_uniq = require("./lib/utils/uniq");
|
|
|
392
392
|
var import_defaultThemes2 = require("./lib/editor/managers/ThemeManager/defaultThemes");
|
|
393
393
|
(0, import_utils.registerTldrawLibraryVersion)(
|
|
394
394
|
"@tldraw/editor",
|
|
395
|
-
"5.5.0-canary.
|
|
395
|
+
"5.5.0-canary.dd5a6dc4824a",
|
|
396
396
|
"cjs"
|
|
397
397
|
);
|
|
398
398
|
//# sourceMappingURL=index.js.map
|
|
@@ -421,7 +421,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
if (deleteBindingIds.length) {
|
|
424
|
-
this.
|
|
424
|
+
this.store.remove(deleteBindingIds);
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
},
|
|
@@ -1381,6 +1381,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
1381
1381
|
* @public
|
|
1382
1382
|
**/
|
|
1383
1383
|
updateDocumentSettings(settings) {
|
|
1384
|
+
if (this.getIsReadonly()) return this;
|
|
1384
1385
|
this.run(
|
|
1385
1386
|
() => {
|
|
1386
1387
|
this.store.put([{ ...this.getDocumentSettings(), ...settings }]);
|
|
@@ -1593,7 +1594,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
1593
1594
|
}
|
|
1594
1595
|
const ids = this.getSortedChildIdsForParent(parentToSelectWithinId);
|
|
1595
1596
|
if (ids.length <= 0) return this;
|
|
1596
|
-
this.setSelectedShapes(this.
|
|
1597
|
+
this.setSelectedShapes(ids.filter((id) => !this.getShape(id)?.isLocked));
|
|
1597
1598
|
return this;
|
|
1598
1599
|
}
|
|
1599
1600
|
/**
|
|
@@ -1610,12 +1611,15 @@ class Editor extends import_eventemitter3.default {
|
|
|
1610
1611
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1611
1612
|
const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
|
|
1612
1613
|
const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !(0, import_tlschema.isPageId)(firstParentId);
|
|
1613
|
-
const filteredShapes =
|
|
1614
|
-
|
|
1614
|
+
const filteredShapes = this.getCurrentPageShapes().filter(
|
|
1615
|
+
(shape2) => !this.isShapeOrAncestorLocked(shape2) && (isSelectedWithinContainer ? shape2.parentId === firstParentId : (0, import_tlschema.isPageId)(shape2.parentId))
|
|
1616
|
+
);
|
|
1617
|
+
const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
|
|
1615
1618
|
const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
|
|
1616
1619
|
let adjacentShapeId;
|
|
1617
1620
|
if (direction === "next" || direction === "prev") {
|
|
1618
1621
|
const shapeIds = readingOrderShapes.map((shape2) => shape2.id);
|
|
1622
|
+
if (shapeIds.length === 0) return;
|
|
1619
1623
|
const currentIndex = currentShapeId ? shapeIds.indexOf(currentShapeId) : -1;
|
|
1620
1624
|
const startIndex = currentIndex === -1 && direction === "prev" ? 0 : currentIndex;
|
|
1621
1625
|
const adjacentIndex = (startIndex + (direction === "next" ? 1 : -1) + shapeIds.length) % shapeIds.length;
|
|
@@ -2498,7 +2502,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2498
2502
|
setCamera(point, opts) {
|
|
2499
2503
|
const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture();
|
|
2500
2504
|
if (isLocked && !opts?.force) return this;
|
|
2501
|
-
const _point = import_Vec.Vec.
|
|
2505
|
+
const _point = new import_Vec.Vec(point.x, point.y, point.z ?? this.getZoomLevel());
|
|
2502
2506
|
if (!Number.isFinite(_point.x) || !Number.isFinite(_point.y) || !Number.isFinite(_point.z)) {
|
|
2503
2507
|
throw Error(
|
|
2504
2508
|
`Editor.setCamera: expected finite values, got (${_point.x}, ${_point.y}, ${_point.z}).`
|
|
@@ -2920,6 +2924,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2920
2924
|
}
|
|
2921
2925
|
const isOnSamePage = presence.currentPageId === this.getCurrentPageId();
|
|
2922
2926
|
if (!isOnSamePage) {
|
|
2927
|
+
this.markHistoryStoppingPoint("change-page");
|
|
2923
2928
|
this.setCurrentPage(presence.currentPageId);
|
|
2924
2929
|
}
|
|
2925
2930
|
if (opts && opts.animation && !isOnSamePage) {
|
|
@@ -3751,7 +3756,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
3751
3756
|
if (ids.length <= 0) return this;
|
|
3752
3757
|
this.run(
|
|
3753
3758
|
() => {
|
|
3754
|
-
this.store.props.assets.remove?.(ids)
|
|
3759
|
+
Promise.resolve(this.store.props.assets.remove?.(ids)).catch(
|
|
3760
|
+
(err) => console.error("Error while removing assets from the asset store:", err)
|
|
3761
|
+
);
|
|
3755
3762
|
this.store.remove(ids);
|
|
3756
3763
|
},
|
|
3757
3764
|
{ history: "ignore" }
|
|
@@ -4865,6 +4872,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4865
4872
|
* binding, but the `type`, `toId`, and `fromId` must all be provided.
|
|
4866
4873
|
*/
|
|
4867
4874
|
createBindings(partials) {
|
|
4875
|
+
if (this.getIsReadonly()) return this;
|
|
4868
4876
|
const bindings = [];
|
|
4869
4877
|
for (const partial of partials) {
|
|
4870
4878
|
const fromShape = this.getShape(partial.fromId);
|
|
@@ -4899,6 +4907,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4899
4907
|
* binding is skipped. The changes from the partial are merged into the existing record.
|
|
4900
4908
|
*/
|
|
4901
4909
|
updateBindings(partials) {
|
|
4910
|
+
if (this.getIsReadonly()) return this;
|
|
4902
4911
|
const updated = [];
|
|
4903
4912
|
for (const partial of partials) {
|
|
4904
4913
|
if (!partial) continue;
|
|
@@ -4927,6 +4936,16 @@ class Editor extends import_eventemitter3.default {
|
|
|
4927
4936
|
* Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
|
|
4928
4937
|
*/
|
|
4929
4938
|
deleteBindings(bindings, { isolateShapes = false } = {}) {
|
|
4939
|
+
if (this.getIsReadonly()) return this;
|
|
4940
|
+
return this._deleteBindings(bindings, { isolateShapes });
|
|
4941
|
+
}
|
|
4942
|
+
/**
|
|
4943
|
+
* Unguarded so that withIsolatedShapes can transiently isolate shapes for copy and export in
|
|
4944
|
+
* readonly mode; the public deleteBindings is what readonly blocks.
|
|
4945
|
+
*
|
|
4946
|
+
* @internal
|
|
4947
|
+
*/
|
|
4948
|
+
_deleteBindings(bindings, { isolateShapes = false } = {}) {
|
|
4930
4949
|
const ids = bindings.map((binding) => typeof binding === "string" ? binding : binding.id);
|
|
4931
4950
|
if (isolateShapes) {
|
|
4932
4951
|
this.store.atomic(() => {
|
|
@@ -5360,7 +5379,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5360
5379
|
const shapesMovingTogether = [shape];
|
|
5361
5380
|
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5362
5381
|
this.collectShapesViaArrowBindings({
|
|
5363
|
-
bindings: this.
|
|
5382
|
+
bindings: this.getBindingsInvolvingShape(shape.id, "arrow"),
|
|
5364
5383
|
initialShapes: freshShapes,
|
|
5365
5384
|
resultShapes: shapesMovingTogether,
|
|
5366
5385
|
resultBounds: boundsOfShapesMovingTogether,
|
|
@@ -6305,12 +6324,17 @@ class Editor extends import_eventemitter3.default {
|
|
|
6305
6324
|
let remaining = duration;
|
|
6306
6325
|
let t;
|
|
6307
6326
|
const animations = [];
|
|
6327
|
+
const ignoreShapeLock = this._shouldIgnoreShapeLock;
|
|
6308
6328
|
let partial, result;
|
|
6309
6329
|
for (let i = 0, n = partials.length; i < n; i++) {
|
|
6310
6330
|
partial = partials[i];
|
|
6311
6331
|
if (!partial) continue;
|
|
6312
6332
|
const shape = this.getShape(partial.id);
|
|
6313
6333
|
if (!shape) continue;
|
|
6334
|
+
const unlocks = shape.isLocked && Object.hasOwn(partial, "isLocked") && !partial.isLocked;
|
|
6335
|
+
if (!ignoreShapeLock && !unlocks && this.isShapeOrAncestorLocked(shape)) {
|
|
6336
|
+
continue;
|
|
6337
|
+
}
|
|
6314
6338
|
result = {
|
|
6315
6339
|
start: (0, import_utils.structuredClone)(shape),
|
|
6316
6340
|
end: applyPartialToRecordWithProps((0, import_utils.structuredClone)(shape), partial)
|
|
@@ -6326,7 +6350,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6326
6350
|
(p) => p && animatingShapes2.get(p.id) === animationId
|
|
6327
6351
|
);
|
|
6328
6352
|
if (partialsToUpdate.length) {
|
|
6329
|
-
this.updateShapes(partialsToUpdate);
|
|
6353
|
+
this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock });
|
|
6330
6354
|
}
|
|
6331
6355
|
this.off("tick", handleTick);
|
|
6332
6356
|
return;
|
|
@@ -6360,12 +6384,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
6360
6384
|
}
|
|
6361
6385
|
if (this.getIsReadonly()) return this;
|
|
6362
6386
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
6363
|
-
if (ids.length <= 1) return this;
|
|
6364
6387
|
const shapesToGroup = (0, import_utils.compact)(
|
|
6365
6388
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
|
|
6366
6389
|
(id) => this.getShape(id)
|
|
6367
6390
|
)
|
|
6368
6391
|
);
|
|
6392
|
+
if (shapesToGroup.length <= 1) return this;
|
|
6369
6393
|
const sortedShapeIds = shapesToGroup.sort(import_utils.sortByIndex).map((s) => s.id);
|
|
6370
6394
|
const childBounds = (0, import_utils.compact)(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
|
|
6371
6395
|
const pageBounds = import_Box.Box.Common(childBounds);
|
|
@@ -6374,8 +6398,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
6374
6398
|
}
|
|
6375
6399
|
const { x, y } = pageBounds.point;
|
|
6376
6400
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
|
|
6377
|
-
if (this.
|
|
6378
|
-
|
|
6401
|
+
if (!this.canCreateShapes([groupId])) {
|
|
6402
|
+
alertMaxShapes(this);
|
|
6403
|
+
return this;
|
|
6404
|
+
}
|
|
6405
|
+
if (this.isIn("select") && !this.isIn("select.idle")) {
|
|
6379
6406
|
this.cancel();
|
|
6380
6407
|
}
|
|
6381
6408
|
const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(import_utils.sortByIndex);
|
|
@@ -6410,8 +6437,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6410
6437
|
)
|
|
6411
6438
|
);
|
|
6412
6439
|
if (shapesToUngroup.length === 0) return this;
|
|
6413
|
-
if (this.
|
|
6414
|
-
if (!this.isIn("select.idle")) {
|
|
6440
|
+
if (this.isIn("select") && !this.isIn("select.idle")) {
|
|
6415
6441
|
this.cancel();
|
|
6416
6442
|
}
|
|
6417
6443
|
const idsToSelect = /* @__PURE__ */ new Set();
|
|
@@ -6425,16 +6451,16 @@ class Editor extends import_eventemitter3.default {
|
|
|
6425
6451
|
});
|
|
6426
6452
|
if (groups.length === 0) return this;
|
|
6427
6453
|
this.run(() => {
|
|
6428
|
-
let group;
|
|
6429
6454
|
for (let i = 0, n = groups.length; i < n; i++) {
|
|
6430
|
-
group = groups[i];
|
|
6455
|
+
const group = this.getShape(groups[i].id);
|
|
6456
|
+
if (!group) continue;
|
|
6431
6457
|
const childIds = this.getSortedChildIdsForParent(group.id);
|
|
6432
6458
|
for (let j = 0, n2 = childIds.length; j < n2; j++) {
|
|
6433
6459
|
idsToSelect.add(childIds[j]);
|
|
6434
6460
|
}
|
|
6435
6461
|
this.reparentShapes(childIds, group.parentId, group.index);
|
|
6436
6462
|
}
|
|
6437
|
-
this.deleteShapes(groups.map((
|
|
6463
|
+
this.deleteShapes(groups.map((group) => group.id));
|
|
6438
6464
|
if (select) {
|
|
6439
6465
|
this.select(...idsToSelect);
|
|
6440
6466
|
}
|
|
@@ -6515,7 +6541,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6515
6541
|
}
|
|
6516
6542
|
/** @internal */
|
|
6517
6543
|
_getUnlockedShapeIds(ids) {
|
|
6518
|
-
return ids.filter((id) => !this.
|
|
6544
|
+
return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
|
|
6519
6545
|
}
|
|
6520
6546
|
deleteShapes(_ids) {
|
|
6521
6547
|
if (this.getIsReadonly()) return this;
|
|
@@ -6935,21 +6961,29 @@ class Editor extends import_eventemitter3.default {
|
|
|
6935
6961
|
await Promise.allSettled(
|
|
6936
6962
|
content.assets.map(async (asset) => {
|
|
6937
6963
|
if ((asset.type === "image" || asset.type === "video") && !asset.props.src?.startsWith("data:image") && !asset.props.src?.startsWith("data:video") && !asset.props.src?.startsWith("http")) {
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6964
|
+
try {
|
|
6965
|
+
const objectUrl = await this.store.props.assets.resolve(asset, {
|
|
6966
|
+
screenScale: 1,
|
|
6967
|
+
steppedScreenScale: 1,
|
|
6968
|
+
dpr: 1,
|
|
6969
|
+
networkEffectiveType: null,
|
|
6970
|
+
shouldResolveToOriginal: true
|
|
6971
|
+
});
|
|
6972
|
+
if (objectUrl) {
|
|
6973
|
+
const response = await (0, import_utils.fetch)(objectUrl);
|
|
6974
|
+
if (response.ok) {
|
|
6975
|
+
const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
|
|
6976
|
+
assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(await response.blob());
|
|
6977
|
+
assets.push(assetWithDataUrl);
|
|
6978
|
+
return;
|
|
6979
|
+
}
|
|
6980
|
+
console.warn(`Could not inline asset ${asset.id}: fetch returned ${response.status}`);
|
|
6981
|
+
}
|
|
6982
|
+
} catch (err) {
|
|
6983
|
+
console.warn(`Could not inline asset ${asset.id}`, err);
|
|
6984
|
+
}
|
|
6952
6985
|
}
|
|
6986
|
+
assets.push(asset);
|
|
6953
6987
|
})
|
|
6954
6988
|
);
|
|
6955
6989
|
content.assets = assets;
|
|
@@ -8297,8 +8331,8 @@ class Editor extends import_eventemitter3.default {
|
|
|
8297
8331
|
break;
|
|
8298
8332
|
}
|
|
8299
8333
|
case "keyboard": {
|
|
8300
|
-
if (info.
|
|
8301
|
-
if (info.
|
|
8334
|
+
if (info.code === "ShiftRight") info.code = "ShiftLeft";
|
|
8335
|
+
if (info.code === "AltRight") info.code = "AltLeft";
|
|
8302
8336
|
if (info.code === "ControlRight") info.code = "ControlLeft";
|
|
8303
8337
|
if (info.code === "MetaRight") info.code = "MetaLeft";
|
|
8304
8338
|
switch (info.name) {
|
|
@@ -8690,7 +8724,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
8690
8724
|
}
|
|
8691
8725
|
}
|
|
8692
8726
|
}
|
|
8693
|
-
editor.
|
|
8727
|
+
editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
|
|
8694
8728
|
try {
|
|
8695
8729
|
result = import_utils.Result.ok(callback(bindingsWithBoth));
|
|
8696
8730
|
} catch (error) {
|