rita-workspace 0.5.46 → 0.5.48

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.
package/dist/index.js CHANGED
@@ -431,6 +431,13 @@ function isLanguageSupported(langCode) {
431
431
  return lang in translations;
432
432
  }
433
433
 
434
+ // src/state/saveGuard.ts
435
+ function shouldAbortSaveDueToIdMismatch(expectedDrawingId, currentActiveDrawingId) {
436
+ if (!expectedDrawingId) return true;
437
+ if (!currentActiveDrawingId) return true;
438
+ return expectedDrawingId !== currentActiveDrawingId;
439
+ }
440
+
434
441
  // src/state/WorkspaceContext.tsx
435
442
  var import_jsx_runtime = require("react/jsx-runtime");
436
443
  warmDB();
@@ -992,7 +999,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
992
999
  }
993
1000
  }, [workspace]);
994
1001
  const saveCurrentDrawing = (0, import_react.useCallback)(async (expectedDrawingId, elements, appState, files) => {
995
- if (expectedDrawingId !== activeDrawingIdRef.current) {
1002
+ if (shouldAbortSaveDueToIdMismatch(expectedDrawingId, activeDrawingIdRef.current)) {
996
1003
  return;
997
1004
  }
998
1005
  if (!activeDrawing || activeDrawing.id !== expectedDrawingId) return;
@@ -1000,7 +1007,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
1000
1007
  try {
1001
1008
  const fresh = await getDrawing(expectedDrawingId);
1002
1009
  if (fresh && fresh.updatedAt > (activeDrawing.updatedAt ?? 0)) return;
1003
- if (expectedDrawingId !== activeDrawingIdRef.current) return;
1010
+ if (shouldAbortSaveDueToIdMismatch(expectedDrawingId, activeDrawingIdRef.current)) return;
1004
1011
  if (Array.isArray(elements) && elements.length === 0 && fresh && Array.isArray(fresh.elements) && fresh.elements.length > 0) {
1005
1012
  return;
1006
1013
  }
@@ -1758,11 +1765,7 @@ var DrawingsDialog = ({
1758
1765
  setSelectedId(null);
1759
1766
  }
1760
1767
  setIsRefreshing(true);
1761
- refreshDrawings().then(() => {
1762
- if (isFirstOpen) {
1763
- setExpandedFolders(new Set(foldersRef.current.map((f) => f.id)));
1764
- }
1765
- }).finally(() => setIsRefreshing(false));
1768
+ refreshDrawings().finally(() => setIsRefreshing(false));
1766
1769
  }
1767
1770
  prevOpenRef.current = open;
1768
1771
  }, [open, refreshDrawings]);
@@ -2404,27 +2407,7 @@ var DrawingsDialog = ({
2404
2407
  borderBottom: "1px solid var(--default-border-color, #e0e0e0)"
2405
2408
  },
2406
2409
  children: [
2407
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("h2", { style: { margin: 0, fontSize: "18px", fontWeight: 600, display: "flex", alignItems: "center", gap: "8px" }, children: [
2408
- t.dialogTitle,
2409
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2410
- "span",
2411
- {
2412
- style: {
2413
- fontSize: "10px",
2414
- fontWeight: 700,
2415
- letterSpacing: "0.5px",
2416
- padding: "2px 8px",
2417
- borderRadius: "10px",
2418
- backgroundColor: "#fff3cd",
2419
- color: "#856404",
2420
- border: "1px solid #ffc107",
2421
- textTransform: "uppercase"
2422
- },
2423
- title: "Beta \u2014 funktionen \xE4r under utveckling och kan \xE4ndras",
2424
- children: "BETA"
2425
- }
2426
- )
2427
- ] }),
2410
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h2", { style: { margin: 0, fontSize: "18px", fontWeight: 600 }, children: t.dialogTitle }),
2428
2411
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2429
2412
  "button",
2430
2413
  {
package/dist/index.mjs CHANGED
@@ -359,6 +359,13 @@ function isLanguageSupported(langCode) {
359
359
  return lang in translations;
360
360
  }
361
361
 
362
+ // src/state/saveGuard.ts
363
+ function shouldAbortSaveDueToIdMismatch(expectedDrawingId, currentActiveDrawingId) {
364
+ if (!expectedDrawingId) return true;
365
+ if (!currentActiveDrawingId) return true;
366
+ return expectedDrawingId !== currentActiveDrawingId;
367
+ }
368
+
362
369
  // src/state/WorkspaceContext.tsx
363
370
  import { jsx } from "react/jsx-runtime";
364
371
  warmDB();
@@ -920,7 +927,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
920
927
  }
921
928
  }, [workspace]);
922
929
  const saveCurrentDrawing = useCallback(async (expectedDrawingId, elements, appState, files) => {
923
- if (expectedDrawingId !== activeDrawingIdRef.current) {
930
+ if (shouldAbortSaveDueToIdMismatch(expectedDrawingId, activeDrawingIdRef.current)) {
924
931
  return;
925
932
  }
926
933
  if (!activeDrawing || activeDrawing.id !== expectedDrawingId) return;
@@ -928,7 +935,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
928
935
  try {
929
936
  const fresh = await getDrawing(expectedDrawingId);
930
937
  if (fresh && fresh.updatedAt > (activeDrawing.updatedAt ?? 0)) return;
931
- if (expectedDrawingId !== activeDrawingIdRef.current) return;
938
+ if (shouldAbortSaveDueToIdMismatch(expectedDrawingId, activeDrawingIdRef.current)) return;
932
939
  if (Array.isArray(elements) && elements.length === 0 && fresh && Array.isArray(fresh.elements) && fresh.elements.length > 0) {
933
940
  return;
934
941
  }
@@ -1686,11 +1693,7 @@ var DrawingsDialog = ({
1686
1693
  setSelectedId(null);
1687
1694
  }
1688
1695
  setIsRefreshing(true);
1689
- refreshDrawings().then(() => {
1690
- if (isFirstOpen) {
1691
- setExpandedFolders(new Set(foldersRef.current.map((f) => f.id)));
1692
- }
1693
- }).finally(() => setIsRefreshing(false));
1696
+ refreshDrawings().finally(() => setIsRefreshing(false));
1694
1697
  }
1695
1698
  prevOpenRef.current = open;
1696
1699
  }, [open, refreshDrawings]);
@@ -2332,27 +2335,7 @@ var DrawingsDialog = ({
2332
2335
  borderBottom: "1px solid var(--default-border-color, #e0e0e0)"
2333
2336
  },
2334
2337
  children: [
2335
- /* @__PURE__ */ jsxs4("h2", { style: { margin: 0, fontSize: "18px", fontWeight: 600, display: "flex", alignItems: "center", gap: "8px" }, children: [
2336
- t.dialogTitle,
2337
- /* @__PURE__ */ jsx6(
2338
- "span",
2339
- {
2340
- style: {
2341
- fontSize: "10px",
2342
- fontWeight: 700,
2343
- letterSpacing: "0.5px",
2344
- padding: "2px 8px",
2345
- borderRadius: "10px",
2346
- backgroundColor: "#fff3cd",
2347
- color: "#856404",
2348
- border: "1px solid #ffc107",
2349
- textTransform: "uppercase"
2350
- },
2351
- title: "Beta \u2014 funktionen \xE4r under utveckling och kan \xE4ndras",
2352
- children: "BETA"
2353
- }
2354
- )
2355
- ] }),
2338
+ /* @__PURE__ */ jsx6("h2", { style: { margin: 0, fontSize: "18px", fontWeight: 600 }, children: t.dialogTitle }),
2356
2339
  /* @__PURE__ */ jsx6(
2357
2340
  "button",
2358
2341
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rita-workspace",
3
- "version": "0.5.46",
3
+ "version": "0.5.48",
4
4
  "description": "Multi-drawing workspace feature for Rita (Excalidraw fork)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",