@tldraw/editor 5.5.0-canary.b4354a7bcf2e → 5.5.0-canary.b97e737b35f1

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.
Files changed (32) hide show
  1. package/dist-cjs/index.d.ts +1 -0
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/editor/Editor.js +59 -29
  4. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  5. package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
  6. package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
  7. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +13 -17
  8. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  9. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +78 -40
  10. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  11. package/dist-cjs/version.js +3 -3
  12. package/dist-cjs/version.js.map +1 -1
  13. package/dist-esm/index.d.mts +1 -0
  14. package/dist-esm/index.mjs +1 -1
  15. package/dist-esm/lib/editor/Editor.mjs +59 -29
  16. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  17. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
  18. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  19. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +13 -17
  20. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  21. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +78 -40
  22. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  23. package/dist-esm/version.mjs +3 -3
  24. package/dist-esm/version.mjs.map +1 -1
  25. package/package.json +7 -7
  26. package/src/lib/editor/Editor.ts +92 -34
  27. package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
  28. package/src/lib/utils/sync/LocalIndexedDb.test.ts +28 -0
  29. package/src/lib/utils/sync/LocalIndexedDb.ts +18 -20
  30. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +236 -0
  31. package/src/lib/utils/sync/TLLocalSyncClient.ts +106 -54
  32. package/src/version.ts +3 -3
@@ -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.b4354a7bcf2e",
395
+ "5.5.0-canary.b97e737b35f1",
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.deleteBindings(deleteBindingIds);
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._getUnlockedShapeIds(ids));
1597
+ this.setSelectedShapes(ids.filter((id) => !this.getShape(id)?.isLocked));
1597
1598
  return this;
1598
1599
  }
1599
1600
  /**
@@ -2501,7 +2502,7 @@ class Editor extends import_eventemitter3.default {
2501
2502
  setCamera(point, opts) {
2502
2503
  const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture();
2503
2504
  if (isLocked && !opts?.force) return this;
2504
- const _point = import_Vec.Vec.Cast(point);
2505
+ const _point = new import_Vec.Vec(point.x, point.y, point.z ?? this.getZoomLevel());
2505
2506
  if (!Number.isFinite(_point.x) || !Number.isFinite(_point.y) || !Number.isFinite(_point.z)) {
2506
2507
  throw Error(
2507
2508
  `Editor.setCamera: expected finite values, got (${_point.x}, ${_point.y}, ${_point.z}).`
@@ -3755,7 +3756,9 @@ class Editor extends import_eventemitter3.default {
3755
3756
  if (ids.length <= 0) return this;
3756
3757
  this.run(
3757
3758
  () => {
3758
- 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
+ );
3759
3762
  this.store.remove(ids);
3760
3763
  },
3761
3764
  { history: "ignore" }
@@ -4869,6 +4872,7 @@ class Editor extends import_eventemitter3.default {
4869
4872
  * binding, but the `type`, `toId`, and `fromId` must all be provided.
4870
4873
  */
4871
4874
  createBindings(partials) {
4875
+ if (this.getIsReadonly()) return this;
4872
4876
  const bindings = [];
4873
4877
  for (const partial of partials) {
4874
4878
  const fromShape = this.getShape(partial.fromId);
@@ -4903,6 +4907,7 @@ class Editor extends import_eventemitter3.default {
4903
4907
  * binding is skipped. The changes from the partial are merged into the existing record.
4904
4908
  */
4905
4909
  updateBindings(partials) {
4910
+ if (this.getIsReadonly()) return this;
4906
4911
  const updated = [];
4907
4912
  for (const partial of partials) {
4908
4913
  if (!partial) continue;
@@ -4931,6 +4936,16 @@ class Editor extends import_eventemitter3.default {
4931
4936
  * Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
4932
4937
  */
4933
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 } = {}) {
4934
4949
  const ids = bindings.map((binding) => typeof binding === "string" ? binding : binding.id);
4935
4950
  if (isolateShapes) {
4936
4951
  this.store.atomic(() => {
@@ -6309,12 +6324,17 @@ class Editor extends import_eventemitter3.default {
6309
6324
  let remaining = duration;
6310
6325
  let t;
6311
6326
  const animations = [];
6327
+ const ignoreShapeLock = this._shouldIgnoreShapeLock;
6312
6328
  let partial, result;
6313
6329
  for (let i = 0, n = partials.length; i < n; i++) {
6314
6330
  partial = partials[i];
6315
6331
  if (!partial) continue;
6316
6332
  const shape = this.getShape(partial.id);
6317
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
+ }
6318
6338
  result = {
6319
6339
  start: (0, import_utils.structuredClone)(shape),
6320
6340
  end: applyPartialToRecordWithProps((0, import_utils.structuredClone)(shape), partial)
@@ -6330,7 +6350,7 @@ class Editor extends import_eventemitter3.default {
6330
6350
  (p) => p && animatingShapes2.get(p.id) === animationId
6331
6351
  );
6332
6352
  if (partialsToUpdate.length) {
6333
- this.updateShapes(partialsToUpdate);
6353
+ this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock });
6334
6354
  }
6335
6355
  this.off("tick", handleTick);
6336
6356
  return;
@@ -6364,12 +6384,12 @@ class Editor extends import_eventemitter3.default {
6364
6384
  }
6365
6385
  if (this.getIsReadonly()) return this;
6366
6386
  const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6367
- if (ids.length <= 1) return this;
6368
6387
  const shapesToGroup = (0, import_utils.compact)(
6369
6388
  (this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
6370
6389
  (id) => this.getShape(id)
6371
6390
  )
6372
6391
  );
6392
+ if (shapesToGroup.length <= 1) return this;
6373
6393
  const sortedShapeIds = shapesToGroup.sort(import_utils.sortByIndex).map((s) => s.id);
6374
6394
  const childBounds = (0, import_utils.compact)(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
6375
6395
  const pageBounds = import_Box.Box.Common(childBounds);
@@ -6378,8 +6398,11 @@ class Editor extends import_eventemitter3.default {
6378
6398
  }
6379
6399
  const { x, y } = pageBounds.point;
6380
6400
  const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
6381
- if (this.getCurrentToolId() !== "select") return this;
6382
- if (!this.isIn("select.idle")) {
6401
+ if (!this.canCreateShapes([groupId])) {
6402
+ alertMaxShapes(this);
6403
+ return this;
6404
+ }
6405
+ if (this.isIn("select") && !this.isIn("select.idle")) {
6383
6406
  this.cancel();
6384
6407
  }
6385
6408
  const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(import_utils.sortByIndex);
@@ -6414,8 +6437,7 @@ class Editor extends import_eventemitter3.default {
6414
6437
  )
6415
6438
  );
6416
6439
  if (shapesToUngroup.length === 0) return this;
6417
- if (this.getCurrentToolId() !== "select") return this;
6418
- if (!this.isIn("select.idle")) {
6440
+ if (this.isIn("select") && !this.isIn("select.idle")) {
6419
6441
  this.cancel();
6420
6442
  }
6421
6443
  const idsToSelect = /* @__PURE__ */ new Set();
@@ -6429,16 +6451,16 @@ class Editor extends import_eventemitter3.default {
6429
6451
  });
6430
6452
  if (groups.length === 0) return this;
6431
6453
  this.run(() => {
6432
- let group;
6433
6454
  for (let i = 0, n = groups.length; i < n; i++) {
6434
- group = groups[i];
6455
+ const group = this.getShape(groups[i].id);
6456
+ if (!group) continue;
6435
6457
  const childIds = this.getSortedChildIdsForParent(group.id);
6436
6458
  for (let j = 0, n2 = childIds.length; j < n2; j++) {
6437
6459
  idsToSelect.add(childIds[j]);
6438
6460
  }
6439
6461
  this.reparentShapes(childIds, group.parentId, group.index);
6440
6462
  }
6441
- this.deleteShapes(groups.map((group2) => group2.id));
6463
+ this.deleteShapes(groups.map((group) => group.id));
6442
6464
  if (select) {
6443
6465
  this.select(...idsToSelect);
6444
6466
  }
@@ -6519,7 +6541,7 @@ class Editor extends import_eventemitter3.default {
6519
6541
  }
6520
6542
  /** @internal */
6521
6543
  _getUnlockedShapeIds(ids) {
6522
- return ids.filter((id) => !this.getShape(id)?.isLocked);
6544
+ return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
6523
6545
  }
6524
6546
  deleteShapes(_ids) {
6525
6547
  if (this.getIsReadonly()) return this;
@@ -6939,21 +6961,29 @@ class Editor extends import_eventemitter3.default {
6939
6961
  await Promise.allSettled(
6940
6962
  content.assets.map(async (asset) => {
6941
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")) {
6942
- const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6943
- const objectUrl = await this.store.props.assets.resolve(asset, {
6944
- screenScale: 1,
6945
- steppedScreenScale: 1,
6946
- dpr: 1,
6947
- networkEffectiveType: null,
6948
- shouldResolveToOriginal: true
6949
- });
6950
- assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(
6951
- await (0, import_utils.fetch)(objectUrl).then((r) => r.blob())
6952
- );
6953
- assets.push(assetWithDataUrl);
6954
- } else {
6955
- assets.push(asset);
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
+ }
6956
6985
  }
6986
+ assets.push(asset);
6957
6987
  })
6958
6988
  );
6959
6989
  content.assets = assets;
@@ -8694,7 +8724,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
8694
8724
  }
8695
8725
  }
8696
8726
  }
8697
- editor.deleteBindings([...bindingsToRemove], { isolateShapes: true });
8727
+ editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
8698
8728
  try {
8699
8729
  result = import_utils.Result.ok(callback(bindingsWithBoth));
8700
8730
  } catch (error) {