@tldraw/editor 3.14.0-canary.fe38dba85730 → 3.14.0-canary.fea5990646e1

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 (51) hide show
  1. package/dist-cjs/index.d.ts +13 -98
  2. package/dist-cjs/index.js +1 -4
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/editor/Editor.js +23 -56
  5. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  6. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +1 -3
  7. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  8. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +2 -2
  9. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  10. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +10 -0
  11. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +6 -10
  13. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
  14. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  15. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +2 -6
  16. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  17. package/dist-cjs/version.js +3 -3
  18. package/dist-cjs/version.js.map +1 -1
  19. package/dist-esm/index.d.mts +13 -98
  20. package/dist-esm/index.mjs +1 -4
  21. package/dist-esm/index.mjs.map +2 -2
  22. package/dist-esm/lib/editor/Editor.mjs +23 -56
  23. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  24. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +1 -3
  25. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  26. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +2 -2
  27. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  28. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +10 -0
  29. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  30. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +6 -10
  31. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
  32. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +2 -6
  33. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  34. package/dist-esm/version.mjs +3 -3
  35. package/dist-esm/version.mjs.map +1 -1
  36. package/editor.css +11 -10
  37. package/package.json +7 -7
  38. package/src/index.ts +0 -5
  39. package/src/lib/editor/Editor.ts +33 -73
  40. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +1 -3
  41. package/src/lib/editor/managers/TextManager/TextManager.ts +2 -3
  42. package/src/lib/editor/shapes/ShapeUtil.ts +15 -47
  43. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +17 -22
  44. package/src/lib/editor/types/emit-types.ts +0 -4
  45. package/src/lib/primitives/geometry/Geometry2d.ts +2 -7
  46. package/src/version.ts +3 -3
  47. package/dist-cjs/lib/utils/reparenting.js +0 -232
  48. package/dist-cjs/lib/utils/reparenting.js.map +0 -7
  49. package/dist-esm/lib/utils/reparenting.mjs +0 -216
  50. package/dist-esm/lib/utils/reparenting.mjs.map +0 -7
  51. package/src/lib/utils/reparenting.ts +0 -383
@@ -4165,7 +4165,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4165
4165
  if (!id) return void 0;
4166
4166
  const freshShape = this.getShape(id);
4167
4167
  if (freshShape === void 0 || !isShapeId(freshShape.parentId)) return void 0;
4168
- return this.getShape(freshShape.parentId);
4168
+ return this.store.get(freshShape.parentId);
4169
4169
  }
4170
4170
  /**
4171
4171
  * If siblingShape and targetShape are siblings, this returns targetShape. If targetShape has an
@@ -4297,9 +4297,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4297
4297
  if (!pagePoint) continue;
4298
4298
  const newPoint = invertedParentTransform.applyToPoint(pagePoint);
4299
4299
  const newRotation = pageTransform.rotation() - parentPageRotation;
4300
- if (shape.id === parentId) {
4301
- throw Error("Attempted to reparent a shape to itself!");
4302
- }
4303
4300
  changes.push({
4304
4301
  id: shape.id,
4305
4302
  type: shape.type,
@@ -4392,10 +4389,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4392
4389
  }
4393
4390
  return shapeIds;
4394
4391
  }
4395
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
4396
- getDroppingOverShape(point, droppingShapes) {
4397
- return this.getDraggingOverShape(point, droppingShapes);
4398
- }
4399
4392
  /**
4400
4393
  * Get the shape that some shapes should be dropped on at a given point.
4401
4394
  *
@@ -4406,20 +4399,22 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4406
4399
  *
4407
4400
  * @public
4408
4401
  */
4409
- getDraggingOverShape(point, droppingShapes) {
4410
- const draggingShapes = compact(droppingShapes.map((s) => this.getShape(s))).filter(
4411
- (s) => !s.isLocked && !this.isShapeHidden(s)
4412
- );
4413
- const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
4414
- hitInside: true,
4415
- margin: 0
4416
- }).filter(
4417
- (s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !draggingShapes.includes(s)
4418
- );
4419
- for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
4420
- const shapeUtil = this.getShapeUtil(maybeDraggingOverShape);
4421
- if (shapeUtil.onDragShapesOver || shapeUtil.onDragShapesIn || shapeUtil.onDragShapesOut || shapeUtil.onDropShapesOver) {
4422
- return maybeDraggingOverShape;
4402
+ getDroppingOverShape(point, droppingShapes = []) {
4403
+ const currentPageShapesSorted = this.getCurrentPageShapesSorted();
4404
+ for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
4405
+ const shape = currentPageShapesSorted[i];
4406
+ if (
4407
+ // ignore hidden shapes
4408
+ this.isShapeHidden(shape) || // don't allow dropping on selected shapes
4409
+ this.getSelectedShapeIds().includes(shape.id) || // only allow shapes that can receive children
4410
+ !this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) || // don't allow dropping a shape on itself or one of it's children
4411
+ droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
4412
+ ) {
4413
+ continue;
4414
+ }
4415
+ const maskedPageBounds = this.getShapeMaskedPageBounds(shape.id);
4416
+ if (maskedPageBounds && maskedPageBounds.containsPoint(point) && this.getShapeGeometry(shape).hitTestPoint(this.getPointInShapeSpace(shape, point), 0, true)) {
4417
+ return shape;
4423
4418
  }
4424
4419
  }
4425
4420
  }
@@ -4761,7 +4756,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4761
4756
  shape.index = index;
4762
4757
  });
4763
4758
  const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape);
4764
- if (!this.canCreateShapes(shapesToCreate)) {
4759
+ const maxShapesReached = shapesToCreate.length + this.getCurrentPageShapeIds().size > this.options.maxShapesPerPage;
4760
+ if (maxShapesReached) {
4765
4761
  alertMaxShapes(this);
4766
4762
  return;
4767
4763
  }
@@ -5776,26 +5772,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
5776
5772
  getInitialMetaForShape(_shape) {
5777
5773
  return {};
5778
5774
  }
5779
- /**
5780
- * Get whether the provided shape can be created.
5781
- *
5782
- * @param shape - The shape or shape IDs to check.
5783
- *
5784
- * @public
5785
- */
5786
- canCreateShape(shape) {
5787
- return this.canCreateShapes([shape]);
5788
- }
5789
- /**
5790
- * Get whether the provided shapes can be created.
5791
- *
5792
- * @param shapes - The shapes or shape IDs to create.
5793
- *
5794
- * @public
5795
- */
5796
- canCreateShapes(shapes) {
5797
- return shapes.length + this.getCurrentPageShapeIds().size <= this.options.maxShapesPerPage;
5798
- }
5799
5775
  /**
5800
5776
  * Create a single shape.
5801
5777
  *
@@ -5849,8 +5825,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
5849
5825
  let parentId = this.getFocusedGroupId();
5850
5826
  for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
5851
5827
  const parent = currentPageShapesSorted[i];
5852
- const util = this.getShapeUtil(parent);
5853
- if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
5828
+ if (!this.isShapeHidden(parent) && this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) && this.isPointInShape(
5854
5829
  parent,
5855
5830
  // If no parent is provided, then we can treat the
5856
5831
  // shape's provided x/y as being in the page's space.
@@ -5925,8 +5900,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
5925
5900
  ...shape.meta
5926
5901
  };
5927
5902
  });
5928
- this.emit("created-shapes", shapeRecordsToCreate);
5929
- this.emit("edit");
5930
5903
  this.store.put(shapeRecordsToCreate);
5931
5904
  });
5932
5905
  return this;
@@ -6168,8 +6141,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6168
6141
  updated = this.getShapeUtil(shape).onBeforeUpdate?.(shape, updated) ?? updated;
6169
6142
  updates.push(updated);
6170
6143
  }
6171
- this.emit("edited-shapes", updates);
6172
- this.emit("edit");
6173
6144
  this.store.put(updates);
6174
6145
  });
6175
6146
  }
@@ -6191,8 +6162,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6191
6162
  allShapeIdsToDelete.add(childId);
6192
6163
  });
6193
6164
  }
6194
- this.emit("deleted-shapes", [...allShapeIdsToDelete]);
6195
- this.emit("edit");
6196
6165
  return this.run(() => this.store.remove([...allShapeIdsToDelete]));
6197
6166
  }
6198
6167
  deleteShape(_id) {
@@ -6961,9 +6930,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6961
6930
  previousScreenPoint,
6962
6931
  previousPagePoint,
6963
6932
  currentScreenPoint,
6964
- currentPagePoint,
6965
- originScreenPoint,
6966
- originPagePoint
6933
+ currentPagePoint
6967
6934
  } = this.inputs;
6968
6935
  const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
6969
6936
  const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
@@ -6981,8 +6948,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6981
6948
  this.inputs.isPen = info.type === "pointer" && info.isPen;
6982
6949
  if (info.name === "pointer_down" || this.inputs.isPinching) {
6983
6950
  pointerVelocity.set(0, 0);
6984
- originScreenPoint.setTo(currentScreenPoint);
6985
- originPagePoint.setTo(currentPagePoint);
6951
+ this.inputs.originScreenPoint.setTo(currentScreenPoint);
6952
+ this.inputs.originPagePoint.setTo(currentPagePoint);
6986
6953
  }
6987
6954
  this.run(
6988
6955
  () => {