@tldraw/editor 5.5.0-canary.f39b241e2c26 → 5.5.0-canary.f7ff7a688554

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.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.f39b241e2c26",
395
+ "5.5.0-canary.f7ff7a688554",
396
396
  "cjs"
397
397
  );
398
398
  //# sourceMappingURL=index.js.map
@@ -1593,7 +1593,7 @@ class Editor extends import_eventemitter3.default {
1593
1593
  }
1594
1594
  const ids = this.getSortedChildIdsForParent(parentToSelectWithinId);
1595
1595
  if (ids.length <= 0) return this;
1596
- this.setSelectedShapes(this._getUnlockedShapeIds(ids));
1596
+ this.setSelectedShapes(ids.filter((id) => !this.getShape(id)?.isLocked));
1597
1597
  return this;
1598
1598
  }
1599
1599
  /**
@@ -1610,12 +1610,15 @@ class Editor extends import_eventemitter3.default {
1610
1610
  const selectedShapeIds = this.getSelectedShapeIds();
1611
1611
  const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
1612
1612
  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();
1613
+ const filteredShapes = this.getCurrentPageShapes().filter(
1614
+ (shape2) => !this.isShapeOrAncestorLocked(shape2) && (isSelectedWithinContainer ? shape2.parentId === firstParentId : (0, import_tlschema.isPageId)(shape2.parentId))
1615
+ );
1616
+ const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
1615
1617
  const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
1616
1618
  let adjacentShapeId;
1617
1619
  if (direction === "next" || direction === "prev") {
1618
1620
  const shapeIds = readingOrderShapes.map((shape2) => shape2.id);
1621
+ if (shapeIds.length === 0) return;
1619
1622
  const currentIndex = currentShapeId ? shapeIds.indexOf(currentShapeId) : -1;
1620
1623
  const startIndex = currentIndex === -1 && direction === "prev" ? 0 : currentIndex;
1621
1624
  const adjacentIndex = (startIndex + (direction === "next" ? 1 : -1) + shapeIds.length) % shapeIds.length;
@@ -2498,7 +2501,7 @@ class Editor extends import_eventemitter3.default {
2498
2501
  setCamera(point, opts) {
2499
2502
  const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture();
2500
2503
  if (isLocked && !opts?.force) return this;
2501
- const _point = import_Vec.Vec.Cast(point);
2504
+ const _point = new import_Vec.Vec(point.x, point.y, point.z ?? this.getZoomLevel());
2502
2505
  if (!Number.isFinite(_point.x) || !Number.isFinite(_point.y) || !Number.isFinite(_point.z)) {
2503
2506
  throw Error(
2504
2507
  `Editor.setCamera: expected finite values, got (${_point.x}, ${_point.y}, ${_point.z}).`
@@ -2920,6 +2923,7 @@ class Editor extends import_eventemitter3.default {
2920
2923
  }
2921
2924
  const isOnSamePage = presence.currentPageId === this.getCurrentPageId();
2922
2925
  if (!isOnSamePage) {
2926
+ this.markHistoryStoppingPoint("change-page");
2923
2927
  this.setCurrentPage(presence.currentPageId);
2924
2928
  }
2925
2929
  if (opts && opts.animation && !isOnSamePage) {
@@ -3751,7 +3755,9 @@ class Editor extends import_eventemitter3.default {
3751
3755
  if (ids.length <= 0) return this;
3752
3756
  this.run(
3753
3757
  () => {
3754
- this.store.props.assets.remove?.(ids);
3758
+ Promise.resolve(this.store.props.assets.remove?.(ids)).catch(
3759
+ (err) => console.error("Error while removing assets from the asset store:", err)
3760
+ );
3755
3761
  this.store.remove(ids);
3756
3762
  },
3757
3763
  { history: "ignore" }
@@ -6305,12 +6311,17 @@ class Editor extends import_eventemitter3.default {
6305
6311
  let remaining = duration;
6306
6312
  let t;
6307
6313
  const animations = [];
6314
+ const ignoreShapeLock = this._shouldIgnoreShapeLock;
6308
6315
  let partial, result;
6309
6316
  for (let i = 0, n = partials.length; i < n; i++) {
6310
6317
  partial = partials[i];
6311
6318
  if (!partial) continue;
6312
6319
  const shape = this.getShape(partial.id);
6313
6320
  if (!shape) continue;
6321
+ const unlocks = shape.isLocked && Object.hasOwn(partial, "isLocked") && !partial.isLocked;
6322
+ if (!ignoreShapeLock && !unlocks && this.isShapeOrAncestorLocked(shape)) {
6323
+ continue;
6324
+ }
6314
6325
  result = {
6315
6326
  start: (0, import_utils.structuredClone)(shape),
6316
6327
  end: applyPartialToRecordWithProps((0, import_utils.structuredClone)(shape), partial)
@@ -6326,7 +6337,7 @@ class Editor extends import_eventemitter3.default {
6326
6337
  (p) => p && animatingShapes2.get(p.id) === animationId
6327
6338
  );
6328
6339
  if (partialsToUpdate.length) {
6329
- this.updateShapes(partialsToUpdate);
6340
+ this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock });
6330
6341
  }
6331
6342
  this.off("tick", handleTick);
6332
6343
  return;
@@ -6366,6 +6377,7 @@ class Editor extends import_eventemitter3.default {
6366
6377
  (id) => this.getShape(id)
6367
6378
  )
6368
6379
  );
6380
+ if (shapesToGroup.length <= 1) return this;
6369
6381
  const sortedShapeIds = shapesToGroup.sort(import_utils.sortByIndex).map((s) => s.id);
6370
6382
  const childBounds = (0, import_utils.compact)(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
6371
6383
  const pageBounds = import_Box.Box.Common(childBounds);
@@ -6515,7 +6527,7 @@ class Editor extends import_eventemitter3.default {
6515
6527
  }
6516
6528
  /** @internal */
6517
6529
  _getUnlockedShapeIds(ids) {
6518
- return ids.filter((id) => !this.getShape(id)?.isLocked);
6530
+ return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
6519
6531
  }
6520
6532
  deleteShapes(_ids) {
6521
6533
  if (this.getIsReadonly()) return this;
@@ -6935,21 +6947,29 @@ class Editor extends import_eventemitter3.default {
6935
6947
  await Promise.allSettled(
6936
6948
  content.assets.map(async (asset) => {
6937
6949
  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);
6950
+ try {
6951
+ const objectUrl = await this.store.props.assets.resolve(asset, {
6952
+ screenScale: 1,
6953
+ steppedScreenScale: 1,
6954
+ dpr: 1,
6955
+ networkEffectiveType: null,
6956
+ shouldResolveToOriginal: true
6957
+ });
6958
+ if (objectUrl) {
6959
+ const response = await (0, import_utils.fetch)(objectUrl);
6960
+ if (response.ok) {
6961
+ const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6962
+ assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(await response.blob());
6963
+ assets.push(assetWithDataUrl);
6964
+ return;
6965
+ }
6966
+ console.warn(`Could not inline asset ${asset.id}: fetch returned ${response.status}`);
6967
+ }
6968
+ } catch (err) {
6969
+ console.warn(`Could not inline asset ${asset.id}`, err);
6970
+ }
6952
6971
  }
6972
+ assets.push(asset);
6953
6973
  })
6954
6974
  );
6955
6975
  content.assets = assets;
@@ -8297,8 +8317,8 @@ class Editor extends import_eventemitter3.default {
8297
8317
  break;
8298
8318
  }
8299
8319
  case "keyboard": {
8300
- if (info.key === "ShiftRight") info.key = "ShiftLeft";
8301
- if (info.key === "AltRight") info.key = "AltLeft";
8320
+ if (info.code === "ShiftRight") info.code = "ShiftLeft";
8321
+ if (info.code === "AltRight") info.code = "AltLeft";
8302
8322
  if (info.code === "ControlRight") info.code = "ControlLeft";
8303
8323
  if (info.code === "MetaRight") info.code = "MetaLeft";
8304
8324
  switch (info.name) {