@tldraw/editor 5.5.0-canary.fa8dc460ac73 → 5.5.0-canary.fe69c9620403

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 (60) 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 +94 -57
  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/exports/ExportDelay.js +10 -2
  8. package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
  9. package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
  10. package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
  11. package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
  12. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  13. package/dist-cjs/lib/license/LicenseManager.js +9 -1
  14. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  15. package/dist-cjs/lib/license/LicenseProvider.js +12 -4
  16. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  17. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +13 -17
  18. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  19. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +78 -40
  20. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  21. package/dist-cjs/version.js +3 -3
  22. package/dist-cjs/version.js.map +1 -1
  23. package/dist-esm/index.d.mts +1 -0
  24. package/dist-esm/index.mjs +1 -1
  25. package/dist-esm/lib/editor/Editor.mjs +94 -57
  26. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  27. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
  28. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  29. package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
  30. package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
  31. package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
  32. package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
  33. package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
  34. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  35. package/dist-esm/lib/license/LicenseManager.mjs +9 -1
  36. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  37. package/dist-esm/lib/license/LicenseProvider.mjs +13 -5
  38. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  39. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +13 -17
  40. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  41. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +78 -40
  42. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  43. package/dist-esm/version.mjs +3 -3
  44. package/dist-esm/version.mjs.map +1 -1
  45. package/package.json +7 -7
  46. package/src/lib/editor/Editor.test.ts +20 -0
  47. package/src/lib/editor/Editor.ts +149 -138
  48. package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
  49. package/src/lib/exports/ExportDelay.tsx +16 -4
  50. package/src/lib/exports/getSvgAsImage.ts +13 -5
  51. package/src/lib/exports/getSvgJsx.test.ts +43 -1
  52. package/src/lib/exports/getSvgJsx.tsx +28 -16
  53. package/src/lib/license/LicenseManager.ts +13 -1
  54. package/src/lib/license/LicenseProvider.test.tsx +76 -0
  55. package/src/lib/license/LicenseProvider.tsx +19 -5
  56. package/src/lib/utils/sync/LocalIndexedDb.test.ts +28 -0
  57. package/src/lib/utils/sync/LocalIndexedDb.ts +18 -20
  58. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +236 -0
  59. package/src/lib/utils/sync/TLLocalSyncClient.ts +106 -54
  60. 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.fa8dc460ac73",
395
+ "5.5.0-canary.fe69c9620403",
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 }]);
@@ -1540,7 +1541,7 @@ class Editor extends import_eventemitter3.default {
1540
1541
  * @public
1541
1542
  */
1542
1543
  select(...shapes) {
1543
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
1544
+ const ids = toShapeIds(shapes);
1544
1545
  this.setSelectedShapes(ids);
1545
1546
  return this;
1546
1547
  }
@@ -1555,7 +1556,7 @@ class Editor extends import_eventemitter3.default {
1555
1556
  * @public
1556
1557
  */
1557
1558
  deselect(...shapes) {
1558
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
1559
+ const ids = toShapeIds(shapes);
1559
1560
  const selectedShapeIds = this.getSelectedShapeIds();
1560
1561
  if (selectedShapeIds.length > 0 && ids.length > 0) {
1561
1562
  this.setSelectedShapes(selectedShapeIds.filter((id) => !ids.includes(id)));
@@ -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
  /**
@@ -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 = isSelectedWithinContainer ? this.getCurrentPageShapes().filter((shape2) => shape2.parentId === firstParentId) : this.getCurrentPageShapes().filter((shape2) => (0, import_tlschema.isPageId)(shape2.parentId));
1614
- const readingOrderShapes = isSelectedWithinContainer ? this._getShapesInReadingOrder(filteredShapes) : this.getCurrentPageShapesInReadingOrder();
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;
@@ -2061,7 +2065,7 @@ class Editor extends import_eventemitter3.default {
2061
2065
  * @public
2062
2066
  */
2063
2067
  setHintingShapes(shapes) {
2064
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
2068
+ const ids = toShapeIds(shapes);
2065
2069
  this.run(
2066
2070
  () => {
2067
2071
  this._updateCurrentPageState({ hintingShapeIds: (0, import_utils.dedupe)(ids) });
@@ -2091,7 +2095,7 @@ class Editor extends import_eventemitter3.default {
2091
2095
  * @public
2092
2096
  */
2093
2097
  setErasingShapes(shapes) {
2094
- const ids = typeof shapes[0] === "string" ? shapes.slice() : shapes.map((shape) => shape.id);
2098
+ const ids = toShapeIds(shapes).slice();
2095
2099
  ids.sort();
2096
2100
  const erasingShapeIds = this.getErasingShapeIds();
2097
2101
  this.run(
@@ -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.Cast(point);
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" }
@@ -4133,7 +4140,7 @@ class Editor extends import_eventemitter3.default {
4133
4140
  if (shapes.length === 0) {
4134
4141
  return;
4135
4142
  }
4136
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4143
+ const ids = toShapeIds(shapes);
4137
4144
  const freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4138
4145
  if (freshShapes.length === 1) {
4139
4146
  const parentId = freshShapes[0].parentId;
@@ -4636,7 +4643,7 @@ class Editor extends import_eventemitter3.default {
4636
4643
  * @public
4637
4644
  */
4638
4645
  reparentShapes(shapes, parentId, insertIndex) {
4639
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4646
+ const ids = toShapeIds(shapes);
4640
4647
  if (ids.length === 0) return this;
4641
4648
  const changes = [];
4642
4649
  const parentTransform = (0, import_tlschema.isPageId)(parentId) ? import_Mat.Mat.Identity() : this.getShapePageTransform(parentId);
@@ -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(() => {
@@ -4985,7 +5004,7 @@ class Editor extends import_eventemitter3.default {
4985
5004
  * @param opts - The options for the rotation.
4986
5005
  */
4987
5006
  rotateShapesBy(shapes, delta, opts) {
4988
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5007
+ const ids = toShapeIds(shapes);
4989
5008
  if (ids.length <= 0) return this;
4990
5009
  const snapshot = (0, import_rotation.getRotationSnapshot)({ editor: this, ids });
4991
5010
  if (!snapshot) return this;
@@ -5034,7 +5053,7 @@ class Editor extends import_eventemitter3.default {
5034
5053
  * @param offset - The offset to apply to the shapes.
5035
5054
  */
5036
5055
  nudgeShapes(shapes, offset) {
5037
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5056
+ const ids = toShapeIds(shapes);
5038
5057
  if (ids.length <= 0) return this;
5039
5058
  const changes = [];
5040
5059
  for (const id of ids) {
@@ -5062,7 +5081,7 @@ class Editor extends import_eventemitter3.default {
5062
5081
  */
5063
5082
  duplicateShapes(shapes, offset) {
5064
5083
  this.run(() => {
5065
- const _ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5084
+ const _ids = toShapeIds(shapes);
5066
5085
  const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
5067
5086
  if (ids.length <= 0) return this;
5068
5087
  const initialIds = new Set(ids);
@@ -5171,7 +5190,7 @@ class Editor extends import_eventemitter3.default {
5171
5190
  * @public
5172
5191
  */
5173
5192
  moveShapesToPage(shapes, pageId) {
5174
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5193
+ const ids = toShapeIds(shapes);
5175
5194
  if (ids.length === 0) return this;
5176
5195
  if (this.getIsReadonly()) return this;
5177
5196
  const currentPageId = this.getCurrentPageId();
@@ -5207,7 +5226,7 @@ class Editor extends import_eventemitter3.default {
5207
5226
  * @public
5208
5227
  */
5209
5228
  toggleLock(shapes) {
5210
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5229
+ const ids = toShapeIds(shapes);
5211
5230
  if (this.getIsReadonly() || ids.length === 0) return this;
5212
5231
  let allLocked = true;
5213
5232
  const shapesToToggle = [];
@@ -5246,7 +5265,7 @@ class Editor extends import_eventemitter3.default {
5246
5265
  * @public
5247
5266
  */
5248
5267
  sendToBack(shapes) {
5249
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5268
+ const ids = toShapeIds(shapes);
5250
5269
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toBack", ids, {
5251
5270
  considerAllShapes: true
5252
5271
  });
@@ -5276,7 +5295,7 @@ class Editor extends import_eventemitter3.default {
5276
5295
  * @public
5277
5296
  */
5278
5297
  sendBackward(shapes, opts = {}) {
5279
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5298
+ const ids = toShapeIds(shapes);
5280
5299
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "backward", ids, opts);
5281
5300
  if (changes) this.updateShapes(changes);
5282
5301
  return this;
@@ -5304,7 +5323,7 @@ class Editor extends import_eventemitter3.default {
5304
5323
  * @public
5305
5324
  */
5306
5325
  bringForward(shapes, opts = {}) {
5307
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5326
+ const ids = toShapeIds(shapes);
5308
5327
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "forward", ids, opts);
5309
5328
  if (changes) this.updateShapes(changes);
5310
5329
  return this;
@@ -5323,7 +5342,7 @@ class Editor extends import_eventemitter3.default {
5323
5342
  * @public
5324
5343
  */
5325
5344
  bringToFront(shapes) {
5326
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5345
+ const ids = toShapeIds(shapes);
5327
5346
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toFront", ids);
5328
5347
  if (changes) this.updateShapes(changes);
5329
5348
  return this;
@@ -5335,7 +5354,7 @@ class Editor extends import_eventemitter3.default {
5335
5354
  * @internal
5336
5355
  */
5337
5356
  getShapeClusters(shapes, type, opts) {
5338
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5357
+ const ids = toShapeIds(shapes);
5339
5358
  let freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5340
5359
  if (opts?.filterAxisAligned) {
5341
5360
  freshShapes = freshShapes.filter((s) => {
@@ -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.getBindingsToShape(shape.id, "arrow"),
5382
+ bindings: this.getBindingsInvolvingShape(shape.id, "arrow"),
5364
5383
  initialShapes: freshShapes,
5365
5384
  resultShapes: shapesMovingTogether,
5366
5385
  resultBounds: boundsOfShapesMovingTogether,
@@ -5416,7 +5435,7 @@ class Editor extends import_eventemitter3.default {
5416
5435
  */
5417
5436
  flipShapes(shapes, operation) {
5418
5437
  if (this.getIsReadonly()) return this;
5419
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5438
+ const ids = toShapeIds(shapes);
5420
5439
  const shapesToFlipFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5421
5440
  for (const shape of shapesToFlipFirstPass) {
5422
5441
  if (this.isShapeOfType(shape, "group")) {
@@ -5745,7 +5764,7 @@ class Editor extends import_eventemitter3.default {
5745
5764
  const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
5746
5765
  if (first === last2) {
5747
5766
  const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
5748
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5767
+ const ids = toShapeIds(shapes);
5749
5768
  return this.distributeShapes(
5750
5769
  ids.filter((id) => !excludedShapeIds.has(id)),
5751
5770
  operation
@@ -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;
@@ -6359,13 +6383,13 @@ class Editor extends import_eventemitter3.default {
6359
6383
  throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");
6360
6384
  }
6361
6385
  if (this.getIsReadonly()) return this;
6362
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6363
- if (ids.length <= 1) return this;
6386
+ const ids = toShapeIds(shapes);
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.getCurrentToolId() !== "select") return this;
6378
- 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")) {
6379
6406
  this.cancel();
6380
6407
  }
6381
6408
  const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(import_utils.sortByIndex);
@@ -6403,15 +6430,14 @@ class Editor extends import_eventemitter3.default {
6403
6430
  ungroupShapes(shapes, opts = {}) {
6404
6431
  if (this.getIsReadonly()) return this;
6405
6432
  const { select = true } = opts;
6406
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6433
+ const ids = toShapeIds(shapes);
6407
6434
  const shapesToUngroup = (0, import_utils.compact)(
6408
6435
  (this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
6409
6436
  (id) => this.getShape(id)
6410
6437
  )
6411
6438
  );
6412
6439
  if (shapesToUngroup.length === 0) return this;
6413
- if (this.getCurrentToolId() !== "select") return 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((group2) => group2.id));
6463
+ this.deleteShapes(groups.map((group) => group.id));
6438
6464
  if (select) {
6439
6465
  this.select(...idsToSelect);
6440
6466
  }
@@ -6515,14 +6541,14 @@ class Editor extends import_eventemitter3.default {
6515
6541
  }
6516
6542
  /** @internal */
6517
6543
  _getUnlockedShapeIds(ids) {
6518
- return ids.filter((id) => !this.getShape(id)?.isLocked);
6544
+ return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
6519
6545
  }
6520
6546
  deleteShapes(_ids) {
6521
6547
  if (this.getIsReadonly()) return this;
6522
6548
  if (!Array.isArray(_ids)) {
6523
6549
  throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");
6524
6550
  }
6525
- const shapeIds = typeof _ids[0] === "string" ? _ids : _ids.map((s) => s.id);
6551
+ const shapeIds = toShapeIds(_ids);
6526
6552
  const shapeIdsToDelete = this._shouldIgnoreShapeLock ? shapeIds : this._getUnlockedShapeIds(shapeIds);
6527
6553
  if (shapeIdsToDelete.length === 0) return this;
6528
6554
  const allShapeIdsToDelete = new Set(shapeIdsToDelete);
@@ -6867,7 +6893,7 @@ class Editor extends import_eventemitter3.default {
6867
6893
  * @public
6868
6894
  */
6869
6895
  getContentFromCurrentPage(shapes) {
6870
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6896
+ const ids = toShapeIds(shapes);
6871
6897
  if (!ids) return;
6872
6898
  if (ids.length === 0) return;
6873
6899
  const shapeIds = this.getShapeAndDescendantIds(ids);
@@ -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
- const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6939
- const objectUrl = await this.store.props.assets.resolve(asset, {
6940
- screenScale: 1,
6941
- steppedScreenScale: 1,
6942
- dpr: 1,
6943
- networkEffectiveType: null,
6944
- shouldResolveToOriginal: true
6945
- });
6946
- assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(
6947
- await (0, import_utils.fetch)(objectUrl).then((r) => r.blob())
6948
- );
6949
- assets.push(assetWithDataUrl);
6950
- } else {
6951
- 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
+ }
6952
6985
  }
6986
+ assets.push(asset);
6953
6987
  })
6954
6988
  );
6955
6989
  content.assets = assets;
@@ -7243,7 +7277,7 @@ class Editor extends import_eventemitter3.default {
7243
7277
  * @public
7244
7278
  */
7245
7279
  async getSvgElement(shapes, opts = {}) {
7246
- const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
7280
+ const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : toShapeIds(shapes);
7247
7281
  if (ids.length === 0) return void 0;
7248
7282
  await this.fonts.loadRequiredFontsForCurrentPage(this.options.maxFontsToLoadBeforeRender);
7249
7283
  return (0, import_exportToSvg.exportToSvg)(this, ids, opts);
@@ -8297,8 +8331,8 @@ class Editor extends import_eventemitter3.default {
8297
8331
  break;
8298
8332
  }
8299
8333
  case "keyboard": {
8300
- if (info.key === "ShiftRight") info.key = "ShiftLeft";
8301
- if (info.key === "AltRight") info.key = "AltLeft";
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) {
@@ -8668,6 +8702,9 @@ function pushShapeWithDescendants(editor, id, result) {
8668
8702
  pushShapeWithDescendants(editor, childIds[i], result);
8669
8703
  }
8670
8704
  }
8705
+ function toShapeIds(shapes) {
8706
+ return typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
8707
+ }
8671
8708
  function withIsolatedShapes(editor, shapeIds, callback) {
8672
8709
  let result;
8673
8710
  editor.run(
@@ -8690,7 +8727,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
8690
8727
  }
8691
8728
  }
8692
8729
  }
8693
- editor.deleteBindings([...bindingsToRemove], { isolateShapes: true });
8730
+ editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
8694
8731
  try {
8695
8732
  result = import_utils.Result.ok(callback(bindingsWithBoth));
8696
8733
  } catch (error) {