@haklex/rich-ext-excalidraw 0.0.52 → 0.0.53

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ExcalidrawEditRenderer.d.ts","sourceRoot":"","sources":["../src/ExcalidrawEditRenderer.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAiB,EAAE,EAAE,MAAM,OAAO,CAAA;AAM9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGjD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAA;IACnC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAA;CACzD;AAsYD,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAiIlE,CAAA"}
1
+ {"version":3,"file":"ExcalidrawEditRenderer.d.ts","sourceRoot":"","sources":["../src/ExcalidrawEditRenderer.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAiB,EAAE,EAAE,MAAM,OAAO,CAAA;AAM9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGjD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAA;IACnC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAA;CACzD;AA4aD,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAiIlE,CAAA"}
package/dist/index.mjs CHANGED
@@ -150,22 +150,15 @@ const ExcalidrawEditorDialogContent = ({
150
150
  const mode = storageModeRef.current;
151
151
  if (mode === "delta" && saveSnapshot) {
152
152
  setIsSaving(true);
153
- const frozenDoc = structuredClone(doc);
153
+ structuredClone(doc);
154
154
  return (async () => {
155
155
  try {
156
156
  const currentBaseUrl = baseRefRef.current;
157
157
  const currentBaseData = baseDataRef.current;
158
- if (currentBaseUrl && currentBaseData) {
159
- const { diff } = await import("jsondiffpatch");
160
- const delta = diff(currentBaseData, frozenDoc);
161
- onSave(
162
- delta ? { type: "delta", baseUrl: currentBaseUrl, delta } : { type: "remote", url: currentBaseUrl }
163
- );
164
- } else {
158
+ if (!currentBaseUrl || !currentBaseData) {
165
159
  const ref = await saveSnapshot(doc);
166
160
  baseRefRef.current = ref;
167
161
  baseDataRef.current = doc;
168
- onSave({ type: "remote", url: ref });
169
162
  setSavedRef(ref);
170
163
  }
171
164
  isDirtyRef.current = false;
@@ -176,10 +169,14 @@ const ExcalidrawEditorDialogContent = ({
176
169
  })();
177
170
  }
178
171
  if (mode === "remote" && saveSnapshot) {
172
+ if (baseRefRef.current && baseDataRef.current && JSON.stringify(doc) === JSON.stringify(baseDataRef.current)) {
173
+ isDirtyRef.current = false;
174
+ setIsDirty(false);
175
+ return Promise.resolve();
176
+ }
179
177
  setIsSaving(true);
180
178
  return saveSnapshot(doc).then(
181
179
  (ref) => {
182
- onSave({ type: "remote", url: ref });
183
180
  baseRefRef.current = ref;
184
181
  baseDataRef.current = doc;
185
182
  isDirtyRef.current = false;
@@ -192,14 +189,40 @@ const ExcalidrawEditorDialogContent = ({
192
189
  }
193
190
  );
194
191
  }
195
- try {
196
- onSave({ type: "inline", data: doc });
197
- isDirtyRef.current = false;
198
- setIsDirty(false);
199
- } catch (err) {
200
- console.error("[excalidraw] inline save failed", err);
201
- }
192
+ isDirtyRef.current = false;
193
+ setIsDirty(false);
202
194
  return Promise.resolve();
195
+ }, [saveSnapshot, getSnapshot]);
196
+ const emitSnapshot = useCallback(async () => {
197
+ const doc = getSnapshot();
198
+ if (!doc) return;
199
+ const mode = storageModeRef.current;
200
+ if (mode === "delta" && saveSnapshot) {
201
+ const currentBaseUrl = baseRefRef.current;
202
+ const currentBaseData = baseDataRef.current;
203
+ if (currentBaseUrl && currentBaseData) {
204
+ const { diff } = await import("jsondiffpatch");
205
+ const delta = diff(currentBaseData, structuredClone(doc));
206
+ onSave(
207
+ delta ? { type: "delta", baseUrl: currentBaseUrl, delta } : { type: "remote", url: currentBaseUrl }
208
+ );
209
+ } else {
210
+ const ref = await saveSnapshot(doc);
211
+ onSave({ type: "remote", url: ref });
212
+ }
213
+ return;
214
+ }
215
+ if (mode === "remote") {
216
+ const ref = baseRefRef.current;
217
+ if (ref) {
218
+ onSave({ type: "remote", url: ref });
219
+ } else if (saveSnapshot) {
220
+ const newRef = await saveSnapshot(doc);
221
+ onSave({ type: "remote", url: newRef });
222
+ }
223
+ return;
224
+ }
225
+ onSave({ type: "inline", data: doc });
203
226
  }, [onSave, saveSnapshot, getSnapshot]);
204
227
  const handleChange = useCallback(
205
228
  (elements) => {
@@ -218,12 +241,12 @@ const ExcalidrawEditorDialogContent = ({
218
241
  [performSave]
219
242
  );
220
243
  const handleSaveAndClose = useCallback(() => {
221
- void performSave().then(() => {
222
- const doc = getSnapshot();
223
- onClose(doc);
244
+ void performSave().then(async () => {
245
+ await emitSnapshot();
246
+ onClose(getSnapshot());
224
247
  dismiss();
225
248
  });
226
- }, [performSave, getSnapshot, onClose, dismiss]);
249
+ }, [performSave, emitSnapshot, getSnapshot, onClose, dismiss]);
227
250
  const handleDiscard = useCallback(() => {
228
251
  if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
229
252
  dismiss();
@@ -285,10 +308,12 @@ const ExcalidrawEditorDialogContent = ({
285
308
  if (isDirtyRef.current) {
286
309
  showConfirmDialog();
287
310
  } else {
288
- onClose(getSnapshot());
289
- dismiss();
311
+ void emitSnapshot().then(() => {
312
+ onClose(getSnapshot());
313
+ dismiss();
314
+ });
290
315
  }
291
- }, [dismiss, showConfirmDialog, getSnapshot, onClose]);
316
+ }, [dismiss, showConfirmDialog, emitSnapshot, getSnapshot, onClose]);
292
317
  useEffect(() => {
293
318
  const handleKeyDown = (e) => {
294
319
  if (e.key === "Escape") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-ext-excalidraw",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "description": "Excalidraw whiteboard extension",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,10 +22,10 @@
22
22
  "dependencies": {
23
23
  "@excalidraw/excalidraw": "0.17.0",
24
24
  "jsondiffpatch": "^0.7.3",
25
- "@haklex/rich-editor": "0.0.52",
26
- "@haklex/rich-headless": "0.0.52",
27
- "@haklex/rich-editor-ui": "0.0.52",
28
- "@haklex/rich-style-token": "0.0.52"
25
+ "@haklex/rich-editor": "0.0.53",
26
+ "@haklex/rich-headless": "0.0.53",
27
+ "@haklex/rich-editor-ui": "0.0.53",
28
+ "@haklex/rich-style-token": "0.0.53"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@lexical/react": "^0.41.0",