@tldraw/editor 4.2.0-next.f100cedfc45b → 4.3.0-canary.03ae87dcc44b

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 (58) hide show
  1. package/dist-cjs/index.d.ts +59 -37
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/editor/Editor.js +11 -18
  4. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  5. package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +2 -2
  6. package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
  7. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
  8. package/dist-cjs/lib/editor/shapes/BaseBoxShapeUtil.js.map +1 -1
  9. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  10. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  11. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.js.map +2 -2
  12. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
  13. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  14. package/dist-cjs/lib/hooks/useCanvasEvents.js +4 -3
  15. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  16. package/dist-cjs/lib/license/Watermark.js +8 -4
  17. package/dist-cjs/lib/license/Watermark.js.map +2 -2
  18. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  19. package/dist-cjs/version.js +3 -3
  20. package/dist-cjs/version.js.map +1 -1
  21. package/dist-esm/index.d.mts +59 -37
  22. package/dist-esm/index.mjs +1 -1
  23. package/dist-esm/lib/editor/Editor.mjs +11 -18
  24. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  25. package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +2 -2
  26. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  27. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
  28. package/dist-esm/lib/editor/shapes/BaseBoxShapeUtil.mjs.map +1 -1
  29. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  30. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  31. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.mjs.map +2 -2
  32. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
  33. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  34. package/dist-esm/lib/hooks/useCanvasEvents.mjs +4 -3
  35. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  36. package/dist-esm/lib/license/Watermark.mjs +8 -4
  37. package/dist-esm/lib/license/Watermark.mjs.map +2 -2
  38. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  39. package/dist-esm/version.mjs +3 -3
  40. package/dist-esm/version.mjs.map +1 -1
  41. package/package.json +10 -10
  42. package/src/lib/editor/Editor.test.ts +278 -10
  43. package/src/lib/editor/Editor.ts +92 -65
  44. package/src/lib/editor/bindings/BindingUtil.ts +15 -9
  45. package/src/lib/editor/derivations/bindingsIndex.ts +2 -2
  46. package/src/lib/editor/managers/FontManager/FontManager.test.ts +14 -4
  47. package/src/lib/editor/managers/SnapManager/SnapManager.ts +3 -3
  48. package/src/lib/editor/shapes/BaseBoxShapeUtil.tsx +2 -2
  49. package/src/lib/editor/shapes/ShapeUtil.ts +5 -8
  50. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -3
  51. package/src/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.ts +2 -1
  52. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +3 -3
  53. package/src/lib/exports/getSvgJsx.test.ts +10 -19
  54. package/src/lib/exports/getSvgJsx.tsx +2 -5
  55. package/src/lib/hooks/useCanvasEvents.ts +4 -3
  56. package/src/lib/license/Watermark.tsx +8 -5
  57. package/src/lib/utils/reparenting.ts +5 -5
  58. package/src/version.ts +3 -3
@@ -859,26 +859,30 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
859
859
  * after the editor has already been initialized.
860
860
  *
861
861
  * @param Tool - The tool to set.
862
+ * @param parent - The parent state node to set the tool on.
862
863
  *
863
864
  * @public
864
865
  */
865
- setTool(Tool) {
866
- if (hasOwnProperty(this.root.children, Tool.id)) {
866
+ setTool(Tool, parent) {
867
+ parent ??= this.root;
868
+ if (hasOwnProperty(parent.children, Tool.id)) {
867
869
  throw Error(`Can't override tool with id "${Tool.id}"`);
868
870
  }
869
- this.root.children[Tool.id] = new Tool(this, this.root);
871
+ parent.children[Tool.id] = new Tool(this, parent);
870
872
  }
871
873
  /**
872
874
  * Remove a tool. Useful if you need to remove a tool from the state chart on demand,
873
875
  * after the editor has already been initialized.
874
876
  *
875
877
  * @param Tool - The tool to delete.
878
+ * @param parent - The parent state node to remove the tool from.
876
879
  *
877
880
  * @public
878
881
  */
879
- removeTool(Tool) {
880
- if (hasOwnProperty(this.root.children, Tool.id)) {
881
- delete this.root.children[Tool.id];
882
+ removeTool(Tool, parent) {
883
+ parent ??= this.root;
884
+ if (hasOwnProperty(parent.children, Tool.id)) {
885
+ delete parent.children[Tool.id];
882
886
  }
883
887
  }
884
888
  /**
@@ -4431,30 +4435,18 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4431
4435
  getBinding(id) {
4432
4436
  return this.store.get(id);
4433
4437
  }
4434
- /**
4435
- * Get all bindings of a certain type _from_ a particular shape. These are the bindings whose
4436
- * `fromId` matched the shape's ID.
4437
- */
4438
4438
  getBindingsFromShape(shape, type) {
4439
4439
  const id = typeof shape === "string" ? shape : shape.id;
4440
4440
  return this.getBindingsInvolvingShape(id).filter(
4441
4441
  (b) => b.fromId === id && b.type === type
4442
4442
  );
4443
4443
  }
4444
- /**
4445
- * Get all bindings of a certain type _to_ a particular shape. These are the bindings whose
4446
- * `toId` matches the shape's ID.
4447
- */
4448
4444
  getBindingsToShape(shape, type) {
4449
4445
  const id = typeof shape === "string" ? shape : shape.id;
4450
4446
  return this.getBindingsInvolvingShape(id).filter(
4451
4447
  (b) => b.toId === id && b.type === type
4452
4448
  );
4453
4449
  }
4454
- /**
4455
- * Get all bindings involving a particular shape. This includes bindings where the shape is the
4456
- * `fromId` or `toId`. If a type is provided, only bindings of that type are returned.
4457
- */
4458
4450
  getBindingsInvolvingShape(shape, type) {
4459
4451
  const id = typeof shape === "string" ? shape : shape.id;
4460
4452
  const result = this._getBindingsIndexCache().get(id) ?? EMPTY_ARRAY;
@@ -7512,6 +7504,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
7512
7504
  this.setCursor({ type: this._prevCursor, rotation: 0 });
7513
7505
  }
7514
7506
  }
7507
+ this.emit("event", info);
7515
7508
  this.root.handleEvent(info);
7516
7509
  return;
7517
7510
  }