rita-workspace 0.5.35 → 0.5.37
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/README.md +17 -2
- package/dist/index.js +11 -4
- package/dist/index.mjs +11 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,8 @@ yarn add rita-workspace
|
|
|
26
26
|
|
|
27
27
|
## Integration Guide
|
|
28
28
|
|
|
29
|
+
> 📘 For the full host-app integration walkthrough (10 steps including auto-save debounce, switch effect, conflict handling, and replacing Excalidraw's "Open from file"), see [docs/INTEGRATION.md](./docs/INTEGRATION.md).
|
|
30
|
+
|
|
29
31
|
### 1. `App.tsx` - Add Provider
|
|
30
32
|
|
|
31
33
|
```tsx
|
|
@@ -124,6 +126,19 @@ const [workspaceEnabled] = useState(() =>
|
|
|
124
126
|
- State stored in `sessionStorage` (not shared between tabs)
|
|
125
127
|
- When disabled: auto-save to workspace skipped, drawing-switch disabled, footer hidden
|
|
126
128
|
|
|
129
|
+
### Auto-start preference
|
|
130
|
+
|
|
131
|
+
Users can opt into starting every new tab in workspace mode via a checkbox in `DrawingsDialog`. The preference is stored in `localStorage['rita-workspace-auto-start']` (`"true"` to enable, removed when disabled). The host app reads this flag at init time as a fallback when `sessionStorage` has no explicit value:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
const [workspaceEnabled] = useState(() => {
|
|
135
|
+
const sessionVal = sessionStorage.getItem("rita-workspace-enabled");
|
|
136
|
+
if (sessionVal === "true") return true;
|
|
137
|
+
if (sessionVal === "false") return false;
|
|
138
|
+
return localStorage.getItem("rita-workspace-auto-start") === "true";
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
127
142
|
## API Reference
|
|
128
143
|
|
|
129
144
|
### Components
|
|
@@ -131,7 +146,7 @@ const [workspaceEnabled] = useState(() =>
|
|
|
131
146
|
| Component | Description |
|
|
132
147
|
|-----------|-------------|
|
|
133
148
|
| `WorkspaceProvider` | React context provider. Props: `lang`, `children` |
|
|
134
|
-
| `DrawingsDialog` | Management dialog. Props: `open`, `onClose`, `onDrawingSelect
|
|
149
|
+
| `DrawingsDialog` | Management dialog. Props: `open`, `onClose`, `onDrawingSelect` (called on both switch and create), `renderThumbnail` |
|
|
135
150
|
|
|
136
151
|
### Hooks
|
|
137
152
|
|
|
@@ -185,7 +200,7 @@ const {
|
|
|
185
200
|
importWorkspace, // () => Promise<void>
|
|
186
201
|
exportDrawingAsExcalidraw, // (id) => Promise<void>
|
|
187
202
|
exportAllDrawingsAsExcalidraw, // () => Promise<void> — downloads all as .excalidraw files
|
|
188
|
-
importExcalidrawFile, // () => Promise<void>
|
|
203
|
+
importExcalidrawFile, // () => Promise<void> — imports .excalidraw files; switches to the last imported drawing
|
|
189
204
|
} = useWorkspace();
|
|
190
205
|
```
|
|
191
206
|
|
package/dist/index.js
CHANGED
|
@@ -1192,6 +1192,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
|
|
|
1192
1192
|
input.click();
|
|
1193
1193
|
});
|
|
1194
1194
|
if (!files || files.length === 0) return;
|
|
1195
|
+
let lastImportedId = null;
|
|
1195
1196
|
for (const file of Array.from(files)) {
|
|
1196
1197
|
const text = await file.text();
|
|
1197
1198
|
const data = JSON.parse(text);
|
|
@@ -1206,16 +1207,20 @@ function WorkspaceProvider({ children, lang = "en" }) {
|
|
|
1206
1207
|
files: data.files || {}
|
|
1207
1208
|
});
|
|
1208
1209
|
await addDrawingToWorkspace(workspace.id, drawing.id);
|
|
1210
|
+
lastImportedId = drawing.id;
|
|
1209
1211
|
}
|
|
1210
1212
|
const allDrawings = await getAllDrawings();
|
|
1211
1213
|
const ws = await getOrCreateDefaultWorkspace();
|
|
1212
1214
|
const wsDrawings = allDrawings.filter((dr) => ws.drawingIds.includes(dr.id));
|
|
1213
1215
|
setWorkspace(ws);
|
|
1214
1216
|
setDrawings(wsDrawings);
|
|
1217
|
+
if (lastImportedId) {
|
|
1218
|
+
await switchDrawing(lastImportedId);
|
|
1219
|
+
}
|
|
1215
1220
|
} catch (err) {
|
|
1216
1221
|
setError(err instanceof Error ? err.message : "Failed to import drawing");
|
|
1217
1222
|
}
|
|
1218
|
-
}, [workspace, t]);
|
|
1223
|
+
}, [workspace, t, switchDrawing]);
|
|
1219
1224
|
const createFolder2 = (0, import_react.useCallback)(async (name) => {
|
|
1220
1225
|
const now = Date.now();
|
|
1221
1226
|
const tempId = `temp-${now}`;
|
|
@@ -1781,8 +1786,11 @@ var DrawingsDialog = ({
|
|
|
1781
1786
|
setSwitchingId(null);
|
|
1782
1787
|
}, [switchDrawing, onDrawingSelect]);
|
|
1783
1788
|
const handleCreate = (0, import_react5.useCallback)(async (folderId) => {
|
|
1784
|
-
await createNewDrawing(void 0, folderId
|
|
1785
|
-
|
|
1789
|
+
const created = await createNewDrawing(void 0, folderId);
|
|
1790
|
+
if (created) {
|
|
1791
|
+
onDrawingSelect?.(created);
|
|
1792
|
+
}
|
|
1793
|
+
}, [createNewDrawing, onDrawingSelect]);
|
|
1786
1794
|
const handleStartEdit = (0, import_react5.useCallback)((drawing) => {
|
|
1787
1795
|
setEditingId(drawing.id);
|
|
1788
1796
|
setEditName(drawing.name);
|
|
@@ -2189,7 +2197,6 @@ var DrawingsDialog = ({
|
|
|
2189
2197
|
},
|
|
2190
2198
|
style: { background: "none", border: "none", cursor: "pointer", padding: "4px", fontSize: "14px", opacity: 0.5 },
|
|
2191
2199
|
title: t.delete,
|
|
2192
|
-
disabled: drawings.length <= 1,
|
|
2193
2200
|
children: "\u{1F5D1}\uFE0F"
|
|
2194
2201
|
}
|
|
2195
2202
|
)
|
package/dist/index.mjs
CHANGED
|
@@ -1120,6 +1120,7 @@ function WorkspaceProvider({ children, lang = "en" }) {
|
|
|
1120
1120
|
input.click();
|
|
1121
1121
|
});
|
|
1122
1122
|
if (!files || files.length === 0) return;
|
|
1123
|
+
let lastImportedId = null;
|
|
1123
1124
|
for (const file of Array.from(files)) {
|
|
1124
1125
|
const text = await file.text();
|
|
1125
1126
|
const data = JSON.parse(text);
|
|
@@ -1134,16 +1135,20 @@ function WorkspaceProvider({ children, lang = "en" }) {
|
|
|
1134
1135
|
files: data.files || {}
|
|
1135
1136
|
});
|
|
1136
1137
|
await addDrawingToWorkspace(workspace.id, drawing.id);
|
|
1138
|
+
lastImportedId = drawing.id;
|
|
1137
1139
|
}
|
|
1138
1140
|
const allDrawings = await getAllDrawings();
|
|
1139
1141
|
const ws = await getOrCreateDefaultWorkspace();
|
|
1140
1142
|
const wsDrawings = allDrawings.filter((dr) => ws.drawingIds.includes(dr.id));
|
|
1141
1143
|
setWorkspace(ws);
|
|
1142
1144
|
setDrawings(wsDrawings);
|
|
1145
|
+
if (lastImportedId) {
|
|
1146
|
+
await switchDrawing(lastImportedId);
|
|
1147
|
+
}
|
|
1143
1148
|
} catch (err) {
|
|
1144
1149
|
setError(err instanceof Error ? err.message : "Failed to import drawing");
|
|
1145
1150
|
}
|
|
1146
|
-
}, [workspace, t]);
|
|
1151
|
+
}, [workspace, t, switchDrawing]);
|
|
1147
1152
|
const createFolder2 = useCallback(async (name) => {
|
|
1148
1153
|
const now = Date.now();
|
|
1149
1154
|
const tempId = `temp-${now}`;
|
|
@@ -1709,8 +1714,11 @@ var DrawingsDialog = ({
|
|
|
1709
1714
|
setSwitchingId(null);
|
|
1710
1715
|
}, [switchDrawing, onDrawingSelect]);
|
|
1711
1716
|
const handleCreate = useCallback2(async (folderId) => {
|
|
1712
|
-
await createNewDrawing(void 0, folderId
|
|
1713
|
-
|
|
1717
|
+
const created = await createNewDrawing(void 0, folderId);
|
|
1718
|
+
if (created) {
|
|
1719
|
+
onDrawingSelect?.(created);
|
|
1720
|
+
}
|
|
1721
|
+
}, [createNewDrawing, onDrawingSelect]);
|
|
1714
1722
|
const handleStartEdit = useCallback2((drawing) => {
|
|
1715
1723
|
setEditingId(drawing.id);
|
|
1716
1724
|
setEditName(drawing.name);
|
|
@@ -2117,7 +2125,6 @@ var DrawingsDialog = ({
|
|
|
2117
2125
|
},
|
|
2118
2126
|
style: { background: "none", border: "none", cursor: "pointer", padding: "4px", fontSize: "14px", opacity: 0.5 },
|
|
2119
2127
|
title: t.delete,
|
|
2120
|
-
disabled: drawings.length <= 1,
|
|
2121
2128
|
children: "\u{1F5D1}\uFE0F"
|
|
2122
2129
|
}
|
|
2123
2130
|
)
|