rita-workspace 0.5.44 → 0.5.46

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.d.mts CHANGED
@@ -160,7 +160,7 @@ interface WorkspaceContextValue {
160
160
  /** Re-numbers `position` for the given drawing IDs in order. Use the full ordered slice
161
161
  * the user reordered (e.g. all root drawings, or all drawings in a folder). */
162
162
  reorderDrawings: (orderedIds: string[]) => Promise<void>;
163
- saveCurrentDrawing: (elements: unknown[], appState: Record<string, unknown>, files?: Record<string, unknown>) => Promise<void>;
163
+ saveCurrentDrawing: (expectedDrawingId: string, elements: unknown[], appState: Record<string, unknown>, files?: Record<string, unknown>) => Promise<void>;
164
164
  saveDrawingById: (id: string, elements: unknown[], appState: Record<string, unknown>, files?: Record<string, unknown>) => Promise<void>;
165
165
  refreshDrawings: () => Promise<void>;
166
166
  exportWorkspace: () => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -160,7 +160,7 @@ interface WorkspaceContextValue {
160
160
  /** Re-numbers `position` for the given drawing IDs in order. Use the full ordered slice
161
161
  * the user reordered (e.g. all root drawings, or all drawings in a folder). */
162
162
  reorderDrawings: (orderedIds: string[]) => Promise<void>;
163
- saveCurrentDrawing: (elements: unknown[], appState: Record<string, unknown>, files?: Record<string, unknown>) => Promise<void>;
163
+ saveCurrentDrawing: (expectedDrawingId: string, elements: unknown[], appState: Record<string, unknown>, files?: Record<string, unknown>) => Promise<void>;
164
164
  saveDrawingById: (id: string, elements: unknown[], appState: Record<string, unknown>, files?: Record<string, unknown>) => Promise<void>;
165
165
  refreshDrawings: () => Promise<void>;
166
166
  exportWorkspace: () => Promise<void>;
package/dist/index.js CHANGED
@@ -991,12 +991,16 @@ function WorkspaceProvider({ children, lang = "en" }) {
991
991
  return null;
992
992
  }
993
993
  }, [workspace]);
994
- const saveCurrentDrawing = (0, import_react.useCallback)(async (elements, appState, files) => {
995
- if (!activeDrawing) return;
996
- if (isDrawingOpenedEarlierInOtherTab(activeDrawing.id)) return;
994
+ const saveCurrentDrawing = (0, import_react.useCallback)(async (expectedDrawingId, elements, appState, files) => {
995
+ if (expectedDrawingId !== activeDrawingIdRef.current) {
996
+ return;
997
+ }
998
+ if (!activeDrawing || activeDrawing.id !== expectedDrawingId) return;
999
+ if (isDrawingOpenedEarlierInOtherTab(expectedDrawingId)) return;
997
1000
  try {
998
- const fresh = await getDrawing(activeDrawing.id);
1001
+ const fresh = await getDrawing(expectedDrawingId);
999
1002
  if (fresh && fresh.updatedAt > (activeDrawing.updatedAt ?? 0)) return;
1003
+ if (expectedDrawingId !== activeDrawingIdRef.current) return;
1000
1004
  if (Array.isArray(elements) && elements.length === 0 && fresh && Array.isArray(fresh.elements) && fresh.elements.length > 0) {
1001
1005
  return;
1002
1006
  }
@@ -1007,7 +1011,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
1007
1011
  if (files) {
1008
1012
  updateData.files = files;
1009
1013
  }
1010
- await updateDrawing(activeDrawing.id, updateData);
1014
+ await updateDrawing(expectedDrawingId, updateData);
1011
1015
  const now = Date.now();
1012
1016
  const patch = {
1013
1017
  elements,
@@ -1015,8 +1019,8 @@ function WorkspaceProvider({ children, lang = "en" }) {
1015
1019
  ...files ? { files } : {},
1016
1020
  updatedAt: now
1017
1021
  };
1018
- setDrawings((prev) => prev.map((d) => d.id === activeDrawing.id ? { ...d, ...patch } : d));
1019
- setActiveDrawing2((prev) => prev && prev.id === activeDrawing.id ? { ...prev, ...patch } : prev);
1022
+ setDrawings((prev) => prev.map((d) => d.id === expectedDrawingId ? { ...d, ...patch } : d));
1023
+ setActiveDrawing2((prev) => prev && prev.id === expectedDrawingId ? { ...prev, ...patch } : prev);
1020
1024
  } catch (err) {
1021
1025
  setError(err instanceof Error ? err.message : "Failed to save drawing");
1022
1026
  }
@@ -1767,6 +1771,20 @@ var DrawingsDialog = ({
1767
1771
  newFolderInputRef.current.focus();
1768
1772
  }
1769
1773
  }, [creatingFolder]);
1774
+ (0, import_react5.useEffect)(() => {
1775
+ if (!open) return;
1776
+ const handler = (e) => {
1777
+ if (e.key !== "Escape") return;
1778
+ const active = document.activeElement;
1779
+ const tag = active?.tagName;
1780
+ if (tag === "INPUT" || tag === "TEXTAREA" || active?.isContentEditable) {
1781
+ return;
1782
+ }
1783
+ onClose();
1784
+ };
1785
+ document.addEventListener("keydown", handler);
1786
+ return () => document.removeEventListener("keydown", handler);
1787
+ }, [open, onClose]);
1770
1788
  const handleMouseDown = (0, import_react5.useCallback)((e) => {
1771
1789
  if (e.target.closest("button")) return;
1772
1790
  if (e.target.closest("input")) return;
@@ -2825,12 +2843,14 @@ function useExcalidrawBridge({
2825
2843
  if (saveTimeoutRef.current) {
2826
2844
  clearTimeout(saveTimeoutRef.current);
2827
2845
  }
2846
+ const expectedId = activeDrawing?.id;
2847
+ if (!expectedId) return;
2828
2848
  saveTimeoutRef.current = setTimeout(async () => {
2829
2849
  const elements = excalidrawAPI.getSceneElements();
2830
2850
  const appState = excalidrawAPI.getAppState();
2831
- await saveCurrentDrawing(elements, appState);
2851
+ await saveCurrentDrawing(expectedId, elements, appState);
2832
2852
  }, autoSaveInterval);
2833
- }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval]);
2853
+ }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval, activeDrawing]);
2834
2854
  (0, import_react6.useEffect)(() => {
2835
2855
  return () => {
2836
2856
  if (saveTimeoutRef.current) {
@@ -2868,7 +2888,7 @@ function WorkspaceBridge({
2868
2888
  scrollY: appState.scrollY
2869
2889
  // Add other persistent properties as needed
2870
2890
  };
2871
- await saveCurrentDrawing(elements, persistentAppState, files);
2891
+ await saveCurrentDrawing(activeDrawing.id, elements, persistentAppState, files);
2872
2892
  onDrawingSave?.(activeDrawing.id);
2873
2893
  } catch (error) {
2874
2894
  console.error("[WorkspaceBridge] Failed to save drawing:", error);
package/dist/index.mjs CHANGED
@@ -919,12 +919,16 @@ function WorkspaceProvider({ children, lang = "en" }) {
919
919
  return null;
920
920
  }
921
921
  }, [workspace]);
922
- const saveCurrentDrawing = useCallback(async (elements, appState, files) => {
923
- if (!activeDrawing) return;
924
- if (isDrawingOpenedEarlierInOtherTab(activeDrawing.id)) return;
922
+ const saveCurrentDrawing = useCallback(async (expectedDrawingId, elements, appState, files) => {
923
+ if (expectedDrawingId !== activeDrawingIdRef.current) {
924
+ return;
925
+ }
926
+ if (!activeDrawing || activeDrawing.id !== expectedDrawingId) return;
927
+ if (isDrawingOpenedEarlierInOtherTab(expectedDrawingId)) return;
925
928
  try {
926
- const fresh = await getDrawing(activeDrawing.id);
929
+ const fresh = await getDrawing(expectedDrawingId);
927
930
  if (fresh && fresh.updatedAt > (activeDrawing.updatedAt ?? 0)) return;
931
+ if (expectedDrawingId !== activeDrawingIdRef.current) return;
928
932
  if (Array.isArray(elements) && elements.length === 0 && fresh && Array.isArray(fresh.elements) && fresh.elements.length > 0) {
929
933
  return;
930
934
  }
@@ -935,7 +939,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
935
939
  if (files) {
936
940
  updateData.files = files;
937
941
  }
938
- await updateDrawing(activeDrawing.id, updateData);
942
+ await updateDrawing(expectedDrawingId, updateData);
939
943
  const now = Date.now();
940
944
  const patch = {
941
945
  elements,
@@ -943,8 +947,8 @@ function WorkspaceProvider({ children, lang = "en" }) {
943
947
  ...files ? { files } : {},
944
948
  updatedAt: now
945
949
  };
946
- setDrawings((prev) => prev.map((d) => d.id === activeDrawing.id ? { ...d, ...patch } : d));
947
- setActiveDrawing2((prev) => prev && prev.id === activeDrawing.id ? { ...prev, ...patch } : prev);
950
+ setDrawings((prev) => prev.map((d) => d.id === expectedDrawingId ? { ...d, ...patch } : d));
951
+ setActiveDrawing2((prev) => prev && prev.id === expectedDrawingId ? { ...prev, ...patch } : prev);
948
952
  } catch (err) {
949
953
  setError(err instanceof Error ? err.message : "Failed to save drawing");
950
954
  }
@@ -1695,6 +1699,20 @@ var DrawingsDialog = ({
1695
1699
  newFolderInputRef.current.focus();
1696
1700
  }
1697
1701
  }, [creatingFolder]);
1702
+ useEffect3(() => {
1703
+ if (!open) return;
1704
+ const handler = (e) => {
1705
+ if (e.key !== "Escape") return;
1706
+ const active = document.activeElement;
1707
+ const tag = active?.tagName;
1708
+ if (tag === "INPUT" || tag === "TEXTAREA" || active?.isContentEditable) {
1709
+ return;
1710
+ }
1711
+ onClose();
1712
+ };
1713
+ document.addEventListener("keydown", handler);
1714
+ return () => document.removeEventListener("keydown", handler);
1715
+ }, [open, onClose]);
1698
1716
  const handleMouseDown = useCallback2((e) => {
1699
1717
  if (e.target.closest("button")) return;
1700
1718
  if (e.target.closest("input")) return;
@@ -2753,12 +2771,14 @@ function useExcalidrawBridge({
2753
2771
  if (saveTimeoutRef.current) {
2754
2772
  clearTimeout(saveTimeoutRef.current);
2755
2773
  }
2774
+ const expectedId = activeDrawing?.id;
2775
+ if (!expectedId) return;
2756
2776
  saveTimeoutRef.current = setTimeout(async () => {
2757
2777
  const elements = excalidrawAPI.getSceneElements();
2758
2778
  const appState = excalidrawAPI.getAppState();
2759
- await saveCurrentDrawing(elements, appState);
2779
+ await saveCurrentDrawing(expectedId, elements, appState);
2760
2780
  }, autoSaveInterval);
2761
- }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval]);
2781
+ }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval, activeDrawing]);
2762
2782
  useEffect4(() => {
2763
2783
  return () => {
2764
2784
  if (saveTimeoutRef.current) {
@@ -2796,7 +2816,7 @@ function WorkspaceBridge({
2796
2816
  scrollY: appState.scrollY
2797
2817
  // Add other persistent properties as needed
2798
2818
  };
2799
- await saveCurrentDrawing(elements, persistentAppState, files);
2819
+ await saveCurrentDrawing(activeDrawing.id, elements, persistentAppState, files);
2800
2820
  onDrawingSave?.(activeDrawing.id);
2801
2821
  } catch (error) {
2802
2822
  console.error("[WorkspaceBridge] Failed to save drawing:", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rita-workspace",
3
- "version": "0.5.44",
3
+ "version": "0.5.46",
4
4
  "description": "Multi-drawing workspace feature for Rita (Excalidraw fork)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",