@tldraw/editor 5.6.0-canary.41de65b8a92d → 5.6.0-canary.4e8f62261c4b

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 (50) hide show
  1. package/dist-cjs/index.d.ts +8 -1
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/editor/Editor.js +27 -13
  4. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  5. package/dist-cjs/lib/editor/derivations/shapeIdsInCurrentPage.js +10 -3
  6. package/dist-cjs/lib/editor/derivations/shapeIdsInCurrentPage.js.map +2 -2
  7. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -1
  8. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
  9. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +19 -2
  10. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +7 -1
  12. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  13. package/dist-cjs/lib/hooks/useDocumentEvents.js +28 -3
  14. package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
  15. package/dist-cjs/lib/options.js +1 -1
  16. package/dist-cjs/lib/options.js.map +1 -1
  17. package/dist-cjs/version.js +3 -3
  18. package/dist-cjs/version.js.map +1 -1
  19. package/dist-esm/index.d.mts +8 -1
  20. package/dist-esm/index.mjs +1 -1
  21. package/dist-esm/lib/editor/Editor.mjs +27 -13
  22. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  23. package/dist-esm/lib/editor/derivations/shapeIdsInCurrentPage.mjs +10 -3
  24. package/dist-esm/lib/editor/derivations/shapeIdsInCurrentPage.mjs.map +2 -2
  25. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -1
  26. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
  27. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +20 -3
  28. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  29. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +7 -1
  30. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  31. package/dist-esm/lib/hooks/useDocumentEvents.mjs +28 -3
  32. package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
  33. package/dist-esm/lib/options.mjs +1 -1
  34. package/dist-esm/lib/options.mjs.map +1 -1
  35. package/dist-esm/version.mjs +3 -3
  36. package/dist-esm/version.mjs.map +1 -1
  37. package/editor.css +1 -1
  38. package/package.json +7 -7
  39. package/src/lib/editor/Editor.ts +47 -24
  40. package/src/lib/editor/derivations/shapeIdsInCurrentPage.ts +19 -3
  41. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +17 -0
  42. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +2 -2
  43. package/src/lib/editor/managers/FontManager/FontManager.test.ts +1 -0
  44. package/src/lib/editor/managers/FontManager/FontManager.ts +26 -3
  45. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +32 -0
  46. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +16 -7
  47. package/src/lib/hooks/useDocumentEvents.ts +51 -3
  48. package/src/lib/options.ts +1 -1
  49. package/src/lib/test/useDocumentEvents.test.tsx +153 -22
  50. package/src/version.ts +3 -3
@@ -1059,7 +1059,7 @@ export declare const defaultTldrawOptions: {
1059
1059
  readonly step: 1;
1060
1060
  }];
1061
1061
  readonly handleRadius: 12;
1062
- readonly hitTestMargin: 3;
1062
+ readonly hitTestMargin: 4.5;
1063
1063
  readonly laserDelayMs: 1200;
1064
1064
  readonly laserFadeoutMs: 500;
1065
1065
  readonly longPressDurationMs: 500;
@@ -1922,10 +1922,13 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1922
1922
  /**
1923
1923
  * Generates a reading order for shapes based on rows grouping.
1924
1924
  * Tries to keep a natural reading order (left-to-right, top-to-bottom).
1925
+ * Shapes whose util returns `false` from {@link ShapeUtil.canTabTo} are left out, as are
1926
+ * locked shapes unless the `selectLockedShapes` option is enabled.
1925
1927
  *
1926
1928
  * @public
1927
1929
  */
1928
1930
  getCurrentPageShapesInReadingOrder(): TLShape[];
1931
+ private _canTabToShape;
1929
1932
  private _getShapesInReadingOrder;
1930
1933
  /**
1931
1934
  * Find the nearest adjacent shape in a specific direction.
@@ -4734,6 +4737,10 @@ export declare class FontManager {
4734
4737
  loadRequiredFontsForCurrentPage(limit?: number): Promise<void>;
4735
4738
  private readonly fontStates;
4736
4739
  private getFontState;
4740
+ private readonly fontLoadEpoch;
4741
+ /* Excluded from this release type: getFontLoadEpoch */
4742
+ private isFontLoadEpochBumpPending;
4743
+ private setFontState;
4737
4744
  ensureFontIsLoaded(font: TLFontFace): Promise<void>;
4738
4745
  private fontsToLoad;
4739
4746
  requestFonts(fonts: TLFontFace[]): void;
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.6.0-canary.41de65b8a92d",
395
+ "5.6.0-canary.4e8f62261c4b",
396
396
  "cjs"
397
397
  );
398
398
  //# sourceMappingURL=index.js.map
@@ -1616,7 +1616,7 @@ class Editor extends import_eventemitter3.default {
1616
1616
  const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
1617
1617
  const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !(0, import_tlschema.isPageId)(firstParentId);
1618
1618
  const filteredShapes = this.getCurrentPageShapes().filter(
1619
- (shape2) => !this.isShapeOrAncestorLocked(shape2) && (isSelectedWithinContainer ? shape2.parentId === firstParentId : (0, import_tlschema.isPageId)(shape2.parentId))
1619
+ (shape2) => isSelectedWithinContainer ? shape2.parentId === firstParentId : (0, import_tlschema.isPageId)(shape2.parentId)
1620
1620
  );
1621
1621
  const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
1622
1622
  const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
@@ -1640,10 +1640,16 @@ class Editor extends import_eventemitter3.default {
1640
1640
  const shapes = this.getCurrentPageShapes().filter((shape) => (0, import_tlschema.isPageId)(shape.parentId));
1641
1641
  return this._getShapesInReadingOrder(shapes);
1642
1642
  }
1643
+ // Locked shapes (and children of locked containers) can't be selected by clicking or
1644
+ // select all, so the reading order and keyboard traversal leave them out too (#10421),
1645
+ // except when selectLockedShapes makes them clickable again
1646
+ _canTabToShape(shape) {
1647
+ return this.getShapeUtil(shape).canTabTo(shape) && (this.options.selectLockedShapes || !this.isShapeOrAncestorLocked(shape));
1648
+ }
1643
1649
  _getShapesInReadingOrder(shapes) {
1644
1650
  const SHALLOW_ANGLE = 20;
1645
1651
  const ROW_THRESHOLD = 100;
1646
- const tabbableShapes = shapes.filter((shape) => this.getShapeUtil(shape).canTabTo(shape));
1652
+ const tabbableShapes = shapes.filter((shape) => this._canTabToShape(shape));
1647
1653
  if (tabbableShapes.length <= 1) return tabbableShapes;
1648
1654
  const shapesWithCenters = tabbableShapes.map((shape) => ({
1649
1655
  shape,
@@ -1701,7 +1707,7 @@ class Editor extends import_eventemitter3.default {
1701
1707
  const currentShape = this.getShape(currentShapeId);
1702
1708
  if (!currentShape) return currentShapeId;
1703
1709
  const tabbableShapes = shapes.filter(
1704
- (shape) => this.getShapeUtil(shape).canTabTo(shape) && shape.id !== currentShapeId
1710
+ (shape) => this._canTabToShape(shape) && shape.id !== currentShapeId
1705
1711
  );
1706
1712
  if (!tabbableShapes.length) return currentShapeId;
1707
1713
  const currentCenter = this.getShapePageBounds(currentShape).center;
@@ -1759,6 +1765,11 @@ class Editor extends import_eventemitter3.default {
1759
1765
  this._selectShapesAndZoom([sortedChildren[0].id]);
1760
1766
  }
1761
1767
  _selectShapesAndZoom(ids) {
1768
+ const selectedShapeIds = this.getSelectedShapeIds();
1769
+ const isSelectionChanging = ids.length !== selectedShapeIds.length || ids.some((id) => !selectedShapeIds.includes(id));
1770
+ if (isSelectionChanging) {
1771
+ this.markHistoryStoppingPoint("selecting adjacent shape");
1772
+ }
1762
1773
  this.setSelectedShapes(ids);
1763
1774
  this.zoomToSelectionIfOffscreen(256, {
1764
1775
  animation: {
@@ -5928,9 +5939,10 @@ class Editor extends import_eventemitter3.default {
5928
5939
  }
5929
5940
  }
5930
5941
  let workingShape = null;
5942
+ const initialPagePoint = import_Mat.Mat.applyToPoint(pageTransform, new import_Vec.Vec());
5931
5943
  if (util.onResize && util.canResize(initialShape)) {
5932
5944
  const newPagePoint = this._scalePagePoint(
5933
- import_Mat.Mat.applyToPoint(pageTransform, new import_Vec.Vec(0, 0)),
5945
+ initialPagePoint,
5934
5946
  scaleOrigin,
5935
5947
  scale,
5936
5948
  scaleAxisRotation
@@ -5943,7 +5955,6 @@ class Editor extends import_eventemitter3.default {
5943
5955
  );
5944
5956
  myScale.x = areWidthAndHeightAlignedWithCorrectAxis ? scale.x : scale.y;
5945
5957
  myScale.y = areWidthAndHeightAlignedWithCorrectAxis ? scale.y : scale.x;
5946
- const initialPagePoint = import_Mat.Mat.applyToPoint(pageTransform, new import_Vec.Vec());
5947
5958
  const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint);
5948
5959
  workingShape = initialShape;
5949
5960
  if (!opts.skipStartAndEndCallbacks) {
@@ -5989,24 +6000,26 @@ class Editor extends import_eventemitter3.default {
5989
6000
  scale,
5990
6001
  scaleAxisRotation
5991
6002
  );
5992
- const initialPageCenterInParentSpace = this.getPointInParentSpace(
6003
+ const repositionedPagePoint = import_Vec.Vec.Add(
6004
+ newPageCenter,
6005
+ import_Vec.Vec.Sub(initialPagePoint, initialPageCenter)
6006
+ );
6007
+ const repositionedLocalPoint = this.getPointInParentSpace(
5993
6008
  initialShape.id,
5994
- initialPageCenter
6009
+ repositionedPagePoint
5995
6010
  );
5996
- const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter);
5997
- const delta = import_Vec.Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace);
5998
6011
  if (workingShape) {
5999
6012
  return {
6000
6013
  ...workingShape,
6001
- x: initialShape.x + delta.x,
6002
- y: initialShape.y + delta.y
6014
+ x: repositionedLocalPoint.x,
6015
+ y: repositionedLocalPoint.y
6003
6016
  };
6004
6017
  }
6005
6018
  return {
6006
6019
  id,
6007
6020
  type: initialShape.type,
6008
- x: initialShape.x + delta.x,
6009
- y: initialShape.y + delta.y
6021
+ x: repositionedLocalPoint.x,
6022
+ y: repositionedLocalPoint.y
6010
6023
  };
6011
6024
  }
6012
6025
  /** @internal */
@@ -8354,6 +8367,7 @@ class Editor extends import_eventemitter3.default {
8354
8367
  break;
8355
8368
  }
8356
8369
  case "key_repeat": {
8370
+ inputs.keys.add(info.code);
8357
8371
  break;
8358
8372
  }
8359
8373
  }