@excalidraw/excalidraw 0.18.0-a18b139 → 0.18.0-a30e1b2

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 (97) hide show
  1. package/dist/dev/{chunk-X3RYHLJU.js → chunk-CARD3WJZ.js} +9 -4
  2. package/dist/dev/chunk-CARD3WJZ.js.map +7 -0
  3. package/dist/dev/{chunk-U3G3LY5D.js → chunk-ETWEPOFC.js} +7284 -6864
  4. package/dist/dev/chunk-ETWEPOFC.js.map +7 -0
  5. package/dist/dev/{chunk-MJMGTOVG.js → chunk-RS23HYC4.js} +2 -2
  6. package/dist/dev/data/{image-Y366K5SN.js → image-AYLHSOBV.js} +3 -3
  7. package/dist/dev/index.css +43 -2
  8. package/dist/dev/index.css.map +3 -3
  9. package/dist/dev/index.js +2959 -1807
  10. package/dist/dev/index.js.map +4 -4
  11. package/dist/dev/locales/{en-CKWC2GMK.js → en-E3O5XSXJ.js} +2 -2
  12. package/dist/dev/subset-shared.chunk.js +1 -1
  13. package/dist/dev/subset-worker.chunk.js +1 -1
  14. package/dist/prod/chunk-6BSJPDKJ.js +33 -0
  15. package/dist/prod/{chunk-IUH5AXLB.js → chunk-FGHASORR.js} +4 -4
  16. package/dist/prod/{chunk-VQA74LVG.js → chunk-SBKTMZM7.js} +1 -1
  17. package/dist/prod/data/image-VAYKYPXV.js +1 -0
  18. package/dist/prod/index.css +1 -1
  19. package/dist/prod/index.js +19 -18
  20. package/dist/prod/locales/{en-SBO6ZHT2.js → en-44IKVKYT.js} +1 -1
  21. package/dist/prod/subset-shared.chunk.js +1 -1
  22. package/dist/prod/subset-worker.chunk.js +1 -1
  23. package/dist/types/common/src/constants.d.ts +2 -0
  24. package/dist/types/{excalidraw → common/src}/emitter.d.ts +1 -1
  25. package/dist/types/common/src/font-metadata.d.ts +4 -2
  26. package/dist/types/common/src/index.d.ts +1 -0
  27. package/dist/types/common/src/utility-types.d.ts +5 -0
  28. package/dist/types/common/src/utils.d.ts +9 -0
  29. package/dist/types/element/src/binding.d.ts +10 -2
  30. package/dist/types/element/src/bounds.d.ts +1 -1
  31. package/dist/types/{excalidraw/change.d.ts → element/src/delta.d.ts} +40 -35
  32. package/dist/types/element/src/frame.d.ts +1 -0
  33. package/dist/types/element/src/index.d.ts +2 -2
  34. package/dist/types/element/src/linearElementEditor.d.ts +3 -7
  35. package/dist/types/element/src/newElement.d.ts +2 -2
  36. package/dist/types/element/src/store.d.ts +227 -0
  37. package/dist/types/element/src/transformHandles.d.ts +2 -2
  38. package/dist/types/element/src/typeChecks.d.ts +3 -0
  39. package/dist/types/element/src/types.d.ts +7 -0
  40. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +18 -36
  41. package/dist/types/excalidraw/actions/actionAlign.d.ts +8 -8
  42. package/dist/types/excalidraw/actions/actionBoundText.d.ts +12 -24
  43. package/dist/types/excalidraw/actions/actionCanvas.d.ts +107 -185
  44. package/dist/types/excalidraw/actions/actionClipboard.d.ts +39 -75
  45. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +6 -12
  46. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +19 -37
  47. package/dist/types/excalidraw/actions/actionDistribute.d.ts +4 -4
  48. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
  49. package/dist/types/excalidraw/actions/actionElementLink.d.ts +5 -11
  50. package/dist/types/excalidraw/actions/actionElementLock.d.ts +14 -26
  51. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +6 -12
  52. package/dist/types/excalidraw/actions/actionExport.d.ts +81 -135
  53. package/dist/types/excalidraw/actions/actionFinalize.d.ts +13 -25
  54. package/dist/types/excalidraw/actions/actionFlip.d.ts +4 -4
  55. package/dist/types/excalidraw/actions/actionFrame.d.ts +26 -50
  56. package/dist/types/excalidraw/actions/actionGroup.d.ts +16 -28
  57. package/dist/types/excalidraw/actions/actionHistory.d.ts +1 -2
  58. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +6 -12
  59. package/dist/types/excalidraw/actions/actionLink.d.ts +8 -14
  60. package/dist/types/excalidraw/actions/actionMenu.d.ts +19 -37
  61. package/dist/types/excalidraw/actions/actionNavigate.d.ts +12 -24
  62. package/dist/types/excalidraw/actions/actionProperties.d.ts +96 -186
  63. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +8 -14
  64. package/dist/types/excalidraw/actions/actionStyles.d.ts +10 -16
  65. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +8 -14
  66. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +8 -14
  67. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +7 -186
  68. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +19 -0
  69. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +8 -14
  70. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +8 -14
  71. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +8 -14
  72. package/dist/types/excalidraw/actions/actionZindex.d.ts +8 -8
  73. package/dist/types/excalidraw/actions/types.d.ts +3 -3
  74. package/dist/types/excalidraw/appState.d.ts +14 -14
  75. package/dist/types/excalidraw/components/App.d.ts +5 -3
  76. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +49 -0
  77. package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +2 -1
  78. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -8
  79. package/dist/types/excalidraw/editor-jotai.d.ts +6 -6
  80. package/dist/types/excalidraw/history.d.ts +14 -22
  81. package/dist/types/excalidraw/hooks/useEmitter.d.ts +1 -1
  82. package/dist/types/excalidraw/index.d.ts +1 -1
  83. package/dist/types/excalidraw/renderer/helpers.d.ts +6 -1
  84. package/dist/types/excalidraw/types.d.ts +11 -3
  85. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +3 -1
  86. package/dist/types/math/src/curve.d.ts +2 -0
  87. package/dist/types/math/src/vector.d.ts +4 -0
  88. package/history.ts +68 -94
  89. package/package.json +3 -3
  90. package/dist/dev/chunk-U3G3LY5D.js.map +0 -7
  91. package/dist/dev/chunk-X3RYHLJU.js.map +0 -7
  92. package/dist/prod/chunk-PUQLEN73.js +0 -33
  93. package/dist/prod/data/image-WY2VMQLG.js +0 -1
  94. package/dist/types/excalidraw/store.d.ts +0 -129
  95. /package/dist/dev/{chunk-MJMGTOVG.js.map → chunk-RS23HYC4.js.map} +0 -0
  96. /package/dist/dev/data/{image-Y366K5SN.js.map → image-AYLHSOBV.js.map} +0 -0
  97. /package/dist/dev/locales/{en-CKWC2GMK.js.map → en-E3O5XSXJ.js.map} +0 -0
package/history.ts CHANGED
@@ -1,12 +1,17 @@
1
- import type { SceneElementsMap } from "@excalidraw/element/types";
1
+ import { Emitter } from "@excalidraw/common";
2
+
3
+ import {
4
+ CaptureUpdateAction,
5
+ StoreChange,
6
+ StoreDelta,
7
+ type Store,
8
+ } from "@excalidraw/element/store";
2
9
 
3
- import { Emitter } from "./emitter";
10
+ import type { SceneElementsMap } from "@excalidraw/element/types";
4
11
 
5
- import type { AppStateChange, ElementsChange } from "./change";
6
- import type { Snapshot } from "./store";
7
12
  import type { AppState } from "./types";
8
13
 
9
- type HistoryStack = HistoryEntry[];
14
+ class HistoryEntry extends StoreDelta {}
10
15
 
11
16
  export class HistoryChangedEvent {
12
17
  constructor(
@@ -20,8 +25,8 @@ export class History {
20
25
  [HistoryChangedEvent]
21
26
  >();
22
27
 
23
- private readonly undoStack: HistoryStack = [];
24
- private readonly redoStack: HistoryStack = [];
28
+ public readonly undoStack: HistoryEntry[] = [];
29
+ public readonly redoStack: HistoryEntry[] = [];
25
30
 
26
31
  public get isUndoStackEmpty() {
27
32
  return this.undoStack.length === 0;
@@ -31,60 +36,52 @@ export class History {
31
36
  return this.redoStack.length === 0;
32
37
  }
33
38
 
39
+ constructor(private readonly store: Store) {}
40
+
34
41
  public clear() {
35
42
  this.undoStack.length = 0;
36
43
  this.redoStack.length = 0;
37
44
  }
38
45
 
39
46
  /**
40
- * Record a local change which will go into the history
47
+ * Record a non-empty local durable increment, which will go into the undo stack..
48
+ * Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
41
49
  */
42
- public record(
43
- elementsChange: ElementsChange,
44
- appStateChange: AppStateChange,
45
- ) {
46
- const entry = HistoryEntry.create(appStateChange, elementsChange);
50
+ public record(delta: StoreDelta) {
51
+ if (delta.isEmpty() || delta instanceof HistoryEntry) {
52
+ return;
53
+ }
47
54
 
48
- if (!entry.isEmpty()) {
49
- // we have the latest changes, no need to `applyLatest`, which is done within `History.push`
50
- this.undoStack.push(entry.inverse());
55
+ // construct history entry, so once it's emitted, it's not recorded again
56
+ const entry = HistoryEntry.inverse(delta);
51
57
 
52
- if (!entry.elementsChange.isEmpty()) {
53
- // don't reset redo stack on local appState changes,
54
- // as a simple click (unselect) could lead to losing all the redo entries
55
- // only reset on non empty elements changes!
56
- this.redoStack.length = 0;
57
- }
58
+ this.undoStack.push(entry);
58
59
 
59
- this.onHistoryChangedEmitter.trigger(
60
- new HistoryChangedEvent(this.isUndoStackEmpty, this.isRedoStackEmpty),
61
- );
60
+ if (!entry.elements.isEmpty()) {
61
+ // don't reset redo stack on local appState changes,
62
+ // as a simple click (unselect) could lead to losing all the redo entries
63
+ // only reset on non empty elements changes!
64
+ this.redoStack.length = 0;
62
65
  }
66
+
67
+ this.onHistoryChangedEmitter.trigger(
68
+ new HistoryChangedEvent(this.isUndoStackEmpty, this.isRedoStackEmpty),
69
+ );
63
70
  }
64
71
 
65
- public undo(
66
- elements: SceneElementsMap,
67
- appState: AppState,
68
- snapshot: Readonly<Snapshot>,
69
- ) {
72
+ public undo(elements: SceneElementsMap, appState: AppState) {
70
73
  return this.perform(
71
74
  elements,
72
75
  appState,
73
- snapshot,
74
76
  () => History.pop(this.undoStack),
75
77
  (entry: HistoryEntry) => History.push(this.redoStack, entry, elements),
76
78
  );
77
79
  }
78
80
 
79
- public redo(
80
- elements: SceneElementsMap,
81
- appState: AppState,
82
- snapshot: Readonly<Snapshot>,
83
- ) {
81
+ public redo(elements: SceneElementsMap, appState: AppState) {
84
82
  return this.perform(
85
83
  elements,
86
84
  appState,
87
- snapshot,
88
85
  () => History.pop(this.redoStack),
89
86
  (entry: HistoryEntry) => History.push(this.undoStack, entry, elements),
90
87
  );
@@ -93,7 +90,6 @@ export class History {
93
90
  private perform(
94
91
  elements: SceneElementsMap,
95
92
  appState: AppState,
96
- snapshot: Readonly<Snapshot>,
97
93
  pop: () => HistoryEntry | null,
98
94
  push: (entry: HistoryEntry) => void,
99
95
  ): [SceneElementsMap, AppState] | void {
@@ -104,6 +100,10 @@ export class History {
104
100
  return;
105
101
  }
106
102
 
103
+ const action = CaptureUpdateAction.IMMEDIATELY;
104
+
105
+ let prevSnapshot = this.store.snapshot;
106
+
107
107
  let nextElements = elements;
108
108
  let nextAppState = appState;
109
109
  let containsVisibleChange = false;
@@ -112,9 +112,29 @@ export class History {
112
112
  while (historyEntry) {
113
113
  try {
114
114
  [nextElements, nextAppState, containsVisibleChange] =
115
- historyEntry.applyTo(nextElements, nextAppState, snapshot);
115
+ StoreDelta.applyTo(
116
+ historyEntry,
117
+ nextElements,
118
+ nextAppState,
119
+ prevSnapshot,
120
+ );
121
+
122
+ const nextSnapshot = prevSnapshot.maybeClone(
123
+ action,
124
+ nextElements,
125
+ nextAppState,
126
+ );
127
+
128
+ // schedule immediate capture, so that it's emitted for the sync purposes
129
+ this.store.scheduleMicroAction({
130
+ action,
131
+ change: StoreChange.create(prevSnapshot, nextSnapshot),
132
+ delta: historyEntry,
133
+ });
134
+
135
+ prevSnapshot = nextSnapshot;
116
136
  } finally {
117
- // make sure to always push / pop, even if the increment is corrupted
137
+ // make sure to always push, even if the delta is corrupted
118
138
  push(historyEntry);
119
139
  }
120
140
 
@@ -135,7 +155,7 @@ export class History {
135
155
  }
136
156
  }
137
157
 
138
- private static pop(stack: HistoryStack): HistoryEntry | null {
158
+ private static pop(stack: HistoryEntry[]): HistoryEntry | null {
139
159
  if (!stack.length) {
140
160
  return null;
141
161
  }
@@ -150,63 +170,17 @@ export class History {
150
170
  }
151
171
 
152
172
  private static push(
153
- stack: HistoryStack,
173
+ stack: HistoryEntry[],
154
174
  entry: HistoryEntry,
155
175
  prevElements: SceneElementsMap,
156
176
  ) {
157
- const updatedEntry = entry.inverse().applyLatestChanges(prevElements);
158
- return stack.push(updatedEntry);
159
- }
160
- }
161
-
162
- export class HistoryEntry {
163
- private constructor(
164
- public readonly appStateChange: AppStateChange,
165
- public readonly elementsChange: ElementsChange,
166
- ) {}
167
-
168
- public static create(
169
- appStateChange: AppStateChange,
170
- elementsChange: ElementsChange,
171
- ) {
172
- return new HistoryEntry(appStateChange, elementsChange);
173
- }
174
-
175
- public inverse(): HistoryEntry {
176
- return new HistoryEntry(
177
- this.appStateChange.inverse(),
178
- this.elementsChange.inverse(),
177
+ const inversedEntry = HistoryEntry.inverse(entry);
178
+ const updatedEntry = HistoryEntry.applyLatestChanges(
179
+ inversedEntry,
180
+ prevElements,
181
+ "inserted",
179
182
  );
180
- }
181
-
182
- public applyTo(
183
- elements: SceneElementsMap,
184
- appState: AppState,
185
- snapshot: Readonly<Snapshot>,
186
- ): [SceneElementsMap, AppState, boolean] {
187
- const [nextElements, elementsContainVisibleChange] =
188
- this.elementsChange.applyTo(elements, snapshot.elements);
189
183
 
190
- const [nextAppState, appStateContainsVisibleChange] =
191
- this.appStateChange.applyTo(appState, nextElements);
192
-
193
- const appliedVisibleChanges =
194
- elementsContainVisibleChange || appStateContainsVisibleChange;
195
-
196
- return [nextElements, nextAppState, appliedVisibleChanges];
197
- }
198
-
199
- /**
200
- * Apply latest (remote) changes to the history entry, creates new instance of `HistoryEntry`.
201
- */
202
- public applyLatestChanges(elements: SceneElementsMap): HistoryEntry {
203
- const updatedElementsChange =
204
- this.elementsChange.applyLatestChanges(elements);
205
-
206
- return HistoryEntry.create(this.appStateChange, updatedElementsChange);
207
- }
208
-
209
- public isEmpty(): boolean {
210
- return this.appStateChange.isEmpty() && this.elementsChange.isEmpty();
184
+ return stack.push(updatedEntry);
211
185
  }
212
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/excalidraw",
3
- "version": "0.18.0-a18b139",
3
+ "version": "0.18.0-a30e1b2",
4
4
  "type": "module",
5
5
  "types": "./dist/types/excalidraw/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -129,7 +129,7 @@
129
129
  "bugs": "https://github.com/excalidraw/excalidraw/issues",
130
130
  "homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
131
131
  "scripts": {
132
- "gen:types": "rm -rf types && tsc",
133
- "build:esm": "rm -rf dist && node ../../scripts/buildPackage.js && yarn gen:types"
132
+ "gen:types": "rimraf types && tsc",
133
+ "build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
134
134
  }
135
135
  }