@tldraw/editor 3.10.3 → 3.11.0-canary.03a8f07c67a3

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 (83) hide show
  1. package/CHANGELOG.md +2 -23
  2. package/dist-cjs/index.d.ts +24 -10
  3. package/dist-cjs/index.js +1 -1
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +4 -4
  6. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  7. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +34 -26
  8. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
  9. package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
  10. package/dist-cjs/lib/config/TLUserPreferences.js.map +1 -1
  11. package/dist-cjs/lib/config/createTLStore.js +2 -1
  12. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  13. package/dist-cjs/lib/constants.js +1 -1
  14. package/dist-cjs/lib/constants.js.map +2 -2
  15. package/dist-cjs/lib/editor/Editor.js +18 -10
  16. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/FocusManager.js +15 -0
  18. package/dist-cjs/lib/editor/managers/FocusManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/managers/UserPreferencesManager.js +1 -1
  20. package/dist-cjs/lib/editor/managers/UserPreferencesManager.js.map +2 -2
  21. package/dist-cjs/lib/exports/exportToSvg.js.map +1 -1
  22. package/dist-cjs/lib/exports/getSvgJsx.js +1 -1
  23. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  24. package/dist-cjs/lib/hooks/useLocalStore.js +3 -0
  25. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  26. package/dist-cjs/lib/license/Watermark.js +7 -1
  27. package/dist-cjs/lib/license/Watermark.js.map +2 -2
  28. package/dist-cjs/lib/options.js +2 -1
  29. package/dist-cjs/lib/options.js.map +2 -2
  30. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +8 -0
  31. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  32. package/dist-cjs/version.js +3 -3
  33. package/dist-cjs/version.js.map +1 -1
  34. package/dist-esm/index.d.mts +24 -10
  35. package/dist-esm/index.mjs +4 -2
  36. package/dist-esm/index.mjs.map +2 -2
  37. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +4 -4
  38. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  39. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +34 -26
  40. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
  41. package/dist-esm/lib/config/TLUserPreferences.mjs +1 -1
  42. package/dist-esm/lib/config/TLUserPreferences.mjs.map +1 -1
  43. package/dist-esm/lib/config/createTLStore.mjs +2 -1
  44. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  45. package/dist-esm/lib/constants.mjs +1 -1
  46. package/dist-esm/lib/constants.mjs.map +2 -2
  47. package/dist-esm/lib/editor/Editor.mjs +18 -10
  48. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  49. package/dist-esm/lib/editor/managers/FocusManager.mjs +15 -0
  50. package/dist-esm/lib/editor/managers/FocusManager.mjs.map +2 -2
  51. package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs +1 -1
  52. package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs.map +2 -2
  53. package/dist-esm/lib/exports/exportToSvg.mjs.map +1 -1
  54. package/dist-esm/lib/exports/getSvgJsx.mjs +1 -1
  55. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  56. package/dist-esm/lib/hooks/useLocalStore.mjs +3 -0
  57. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  58. package/dist-esm/lib/license/Watermark.mjs +7 -1
  59. package/dist-esm/lib/license/Watermark.mjs.map +2 -2
  60. package/dist-esm/lib/options.mjs +2 -1
  61. package/dist-esm/lib/options.mjs.map +2 -2
  62. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +8 -0
  63. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  64. package/dist-esm/version.mjs +3 -3
  65. package/dist-esm/version.mjs.map +1 -1
  66. package/editor.css +1 -1
  67. package/package.json +10 -7
  68. package/src/index.ts +4 -1
  69. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +4 -4
  70. package/src/lib/components/default-components/DefaultShapeIndicators.tsx +52 -31
  71. package/src/lib/config/TLUserPreferences.ts +1 -1
  72. package/src/lib/config/createTLStore.ts +1 -0
  73. package/src/lib/constants.ts +1 -1
  74. package/src/lib/editor/Editor.ts +21 -12
  75. package/src/lib/editor/managers/FocusManager.ts +18 -0
  76. package/src/lib/editor/managers/UserPreferencesManager.ts +1 -1
  77. package/src/lib/exports/exportToSvg.tsx +1 -1
  78. package/src/lib/exports/getSvgJsx.tsx +1 -1
  79. package/src/lib/hooks/useLocalStore.ts +3 -0
  80. package/src/lib/license/Watermark.tsx +7 -1
  81. package/src/lib/options.ts +6 -0
  82. package/src/lib/utils/sync/LocalIndexedDb.ts +9 -0
  83. package/src/version.ts +3 -3
@@ -3237,7 +3237,13 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
3237
3237
  if (this.getIsReadonly()) return this;
3238
3238
  const ids = typeof assets[0] === "string" ? assets : assets.map((a) => a.id);
3239
3239
  if (ids.length <= 0) return this;
3240
- this.run(() => this.store.remove(ids), { history: "ignore" });
3240
+ this.run(
3241
+ () => {
3242
+ this.store.props.assets.remove?.(ids);
3243
+ this.store.remove(ids);
3244
+ },
3245
+ { history: "ignore" }
3246
+ );
3241
3247
  return this;
3242
3248
  }
3243
3249
  /**
@@ -4803,17 +4809,18 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4803
4809
  *
4804
4810
  * @example
4805
4811
  * ```ts
4806
- * editor.stackShapes([box1, box2], 'horizontal', 32)
4807
- * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 32)
4812
+ * editor.stackShapes([box1, box2], 'horizontal')
4813
+ * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal')
4808
4814
  * ```
4809
4815
  *
4810
4816
  * @param shapes - The shapes (or shape ids) to stack.
4811
4817
  * @param operation - Whether to stack horizontally or vertically.
4812
- * @param gap - The gap to leave between shapes.
4818
+ * @param gap - The gap to leave between shapes. By default, uses the editor's `adjacentShapeMargin` option.
4813
4819
  *
4814
4820
  * @public
4815
4821
  */
4816
4822
  stackShapes(shapes, operation, gap) {
4823
+ const _gap = gap ?? this.options.adjacentShapeMargin;
4817
4824
  const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4818
4825
  if (this.getIsReadonly()) return this;
4819
4826
  const shapesToStackFirstPass = compact(ids.map((id) => this.getShape(id)));
@@ -4849,7 +4856,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4849
4856
  allBounds.push(commonPageBounds);
4850
4857
  }
4851
4858
  const len = shapeClustersToStack.length;
4852
- if (gap === 0 && len < 3 || len < 2) return this;
4859
+ if (_gap === 0 && len < 3 || len < 2) return this;
4853
4860
  let val;
4854
4861
  let min;
4855
4862
  let max;
@@ -4866,7 +4873,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4866
4873
  dim = "height";
4867
4874
  }
4868
4875
  let shapeGap = 0;
4869
- if (gap === 0) {
4876
+ if (_gap === 0) {
4870
4877
  const gaps = {};
4871
4878
  shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
4872
4879
  for (let i = 0; i < len - 1; i++) {
@@ -4894,7 +4901,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4894
4901
  shapeGap /= totalCount;
4895
4902
  }
4896
4903
  } else {
4897
- shapeGap = gap;
4904
+ shapeGap = _gap;
4898
4905
  }
4899
4906
  const changes = [];
4900
4907
  let v = shapeClustersToStack[0].pageBounds[max];
@@ -4922,16 +4929,17 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4922
4929
  *
4923
4930
  * @example
4924
4931
  * ```ts
4925
- * editor.packShapes([box1, box2], 32)
4932
+ * editor.packShapes([box1, box2])
4926
4933
  * editor.packShapes(editor.getSelectedShapeIds(), 32)
4927
4934
  * ```
4928
4935
  *
4929
4936
  *
4930
4937
  * @param shapes - The shapes (or shape ids) to pack.
4931
- * @param gap - The padding to apply to the packed shapes. Defaults to 16.
4938
+ * @param gap - The padding to apply to the packed shapes. Defaults to the editor's `adjacentShapeMargin` option.
4932
4939
  */
4933
- packShapes(shapes, gap) {
4940
+ packShapes(shapes, _gap) {
4934
4941
  if (this.getIsReadonly()) return this;
4942
+ const gap = _gap ?? this.options.adjacentShapeMargin;
4935
4943
  const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4936
4944
  const shapesToPackFirstPass = compact(ids.map((id) => this.getShape(id)));
4937
4945
  const shapeClustersToPack = [];