rita-workspace 0.5.45 → 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
  }
@@ -2839,12 +2843,14 @@ function useExcalidrawBridge({
2839
2843
  if (saveTimeoutRef.current) {
2840
2844
  clearTimeout(saveTimeoutRef.current);
2841
2845
  }
2846
+ const expectedId = activeDrawing?.id;
2847
+ if (!expectedId) return;
2842
2848
  saveTimeoutRef.current = setTimeout(async () => {
2843
2849
  const elements = excalidrawAPI.getSceneElements();
2844
2850
  const appState = excalidrawAPI.getAppState();
2845
- await saveCurrentDrawing(elements, appState);
2851
+ await saveCurrentDrawing(expectedId, elements, appState);
2846
2852
  }, autoSaveInterval);
2847
- }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval]);
2853
+ }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval, activeDrawing]);
2848
2854
  (0, import_react6.useEffect)(() => {
2849
2855
  return () => {
2850
2856
  if (saveTimeoutRef.current) {
@@ -2882,7 +2888,7 @@ function WorkspaceBridge({
2882
2888
  scrollY: appState.scrollY
2883
2889
  // Add other persistent properties as needed
2884
2890
  };
2885
- await saveCurrentDrawing(elements, persistentAppState, files);
2891
+ await saveCurrentDrawing(activeDrawing.id, elements, persistentAppState, files);
2886
2892
  onDrawingSave?.(activeDrawing.id);
2887
2893
  } catch (error) {
2888
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
  }
@@ -2767,12 +2771,14 @@ function useExcalidrawBridge({
2767
2771
  if (saveTimeoutRef.current) {
2768
2772
  clearTimeout(saveTimeoutRef.current);
2769
2773
  }
2774
+ const expectedId = activeDrawing?.id;
2775
+ if (!expectedId) return;
2770
2776
  saveTimeoutRef.current = setTimeout(async () => {
2771
2777
  const elements = excalidrawAPI.getSceneElements();
2772
2778
  const appState = excalidrawAPI.getAppState();
2773
- await saveCurrentDrawing(elements, appState);
2779
+ await saveCurrentDrawing(expectedId, elements, appState);
2774
2780
  }, autoSaveInterval);
2775
- }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval]);
2781
+ }, [excalidrawAPI, saveCurrentDrawing, autoSaveInterval, activeDrawing]);
2776
2782
  useEffect4(() => {
2777
2783
  return () => {
2778
2784
  if (saveTimeoutRef.current) {
@@ -2810,7 +2816,7 @@ function WorkspaceBridge({
2810
2816
  scrollY: appState.scrollY
2811
2817
  // Add other persistent properties as needed
2812
2818
  };
2813
- await saveCurrentDrawing(elements, persistentAppState, files);
2819
+ await saveCurrentDrawing(activeDrawing.id, elements, persistentAppState, files);
2814
2820
  onDrawingSave?.(activeDrawing.id);
2815
2821
  } catch (error) {
2816
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.45",
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",