@vuu-ui/vuu-shell 4.0.0-alpha.9 → 4.0.0-beta.2
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/package.json +19 -20
- package/src/app-header/AppHeader.css.js +1 -1
- package/src/app-header/AppHeader.js +26 -36
- package/src/application-provider/ApplicationContext.js +5 -2
- package/src/application-provider/ApplicationProvider.js +59 -8
- package/src/feature/Feature.js +34 -3
- package/src/feature/FeatureErrorBoundary.js +33 -0
- package/src/feature/index.js +0 -1
- package/src/feature-list/FeatureList.css.js +5 -27
- package/src/feature-list/FeatureList.js +96 -117
- package/src/index.js +3 -3
- package/src/left-nav/LeftNav.css.js +4 -2
- package/src/left-nav/LeftNav.js +100 -139
- package/src/persistence-manager/PersistenceProvider.js +3 -10
- package/src/persistence-manager/index.js +0 -3
- package/src/shell-layout-templates/context-panel/ContextPanel.css.js +8 -8
- package/src/shell-layout-templates/context-panel/ContextPanel.js +35 -17
- package/src/shell-layout-templates/context-panel/index.js +0 -1
- package/src/shell-layout-templates/full-height-left-panel/useFullHeightLeftPanel.js +40 -54
- package/src/shell-layout-templates/inlay-left-panel/useInlayLeftPanel.js +64 -54
- package/src/shell-layout-templates/left-main-tabs/useLeftMainTabs.js +28 -49
- package/src/shell-layout-templates/side-panel/SidePanel.css.js +1 -3
- package/src/shell-layout-templates/simple-content-pane/useSimpleContentPane.js +35 -43
- package/src/shell.css.js +3 -86
- package/src/shell.js +70 -148
- package/src/user-settings/SettingsForm.css.js +10 -0
- package/src/user-settings/SettingsForm.js +141 -0
- package/src/user-settings/UserSettingsPanel.css.js +9 -0
- package/src/user-settings/UserSettingsPanel.js +29 -0
- package/src/user-settings/index.js +2 -0
- package/src/workspace-management/LayoutList.js +99 -59
- package/src/workspace-management/SaveLayoutPanel.js +3 -3
- package/src/workspace-management/WorkspaceProvider.js +178 -699
- package/src/workspace-management/index.js +0 -8
- package/src/workspace-management/useWorkspaceContextMenuItems.js +6 -12
- package/types/app-header/AppHeader.d.ts +2 -2
- package/types/application-provider/ApplicationContext.d.ts +6 -1
- package/types/application-provider/ApplicationProvider.d.ts +14 -5
- package/types/feature/Feature.d.ts +10 -2
- package/types/feature/FeatureErrorBoundary.d.ts +1 -1
- package/types/feature/Loader.d.ts +1 -1
- package/types/feature/index.d.ts +1 -2
- package/types/feature-list/FeatureList.d.ts +4 -4
- package/types/index.d.ts +3 -3
- package/types/left-nav/LeftNav.d.ts +1 -2
- package/types/login/LoginPanel.d.ts +1 -1
- package/types/login/VuuLogo.d.ts +1 -1
- package/types/persistence-manager/PersistenceProvider.d.ts +3 -7
- package/types/persistence-manager/index.d.ts +0 -3
- package/types/shell-layout-templates/context-panel/ContextPanel.d.ts +11 -9
- package/types/shell-layout-templates/context-panel/index.d.ts +0 -1
- package/types/shell-layout-templates/full-height-left-panel/useFullHeightLeftPanel.d.ts +1 -1
- package/types/shell-layout-templates/inlay-left-panel/useInlayLeftPanel.d.ts +1 -1
- package/types/shell-layout-templates/left-main-tabs/useLeftMainTabs.d.ts +1 -1
- package/types/shell-layout-templates/side-panel/SidePanel.d.ts +1 -1
- package/types/shell-layout-templates/simple-content-pane/useSimpleContentPane.d.ts +1 -1
- package/types/shell-layout-templates/useShellLayout.d.ts +2 -4
- package/types/shell.d.ts +15 -19
- package/types/theme-switch/ThemeSwitch.d.ts +1 -1
- package/types/workspace-management/LayoutList.d.ts +2 -2
- package/types/workspace-management/LayoutTile.d.ts +1 -1
- package/types/workspace-management/SaveLayoutPanel.d.ts +2 -2
- package/types/workspace-management/WorkspaceProvider.d.ts +50 -61
- package/types/workspace-management/defaultWorkspaceJSON.d.ts +6 -7
- package/types/workspace-management/index.d.ts +0 -8
- package/types/workspace-management/useWorkspaceContextMenuItems.d.ts +1 -1
- package/src/module-registry/getRegisteredModules.js +0 -12
- package/src/persistence-manager/LocalWorkspacePersistenceService.js +0 -129
- package/src/persistence-manager/RemoteWorkspacePersistenceService.js +0 -112
- package/src/persistence-manager/WorkspacePersistenceService.js +0 -9
- package/src/shell-layout-templates/context-panel/ApplicationSettingsContextPanel.js +0 -24
- package/src/workspace-management/WorkspaceController.js +0 -73
- package/src/workspace-management/WorkspaceHost.js +0 -194
- package/src/workspace-management/WorkspacePersistentState.js +0 -67
- package/src/workspace-management/WorkspaceRepository.js +0 -127
- package/src/workspace-management/WorkspaceStartPanel.css.js +0 -44
- package/src/workspace-management/WorkspaceStartPanel.js +0 -34
- package/src/workspace-management/shell-workspace-components.js +0 -59
- package/src/workspace-management/workspace-component-registry.js +0 -30
- package/src/workspace-management/workspace-schemas.js +0 -257
- package/types/module-registry/getRegisteredModules.d.ts +0 -5
- package/types/persistence-manager/LocalWorkspacePersistenceService.d.ts +0 -18
- package/types/persistence-manager/RemoteWorkspacePersistenceService.d.ts +0 -25
- package/types/persistence-manager/WorkspacePersistenceService.d.ts +0 -27
- package/types/shell-layout-templates/context-panel/ApplicationSettingsContextPanel.d.ts +0 -1
- package/types/src/ShellContextProvider.d.ts +0 -7
- package/types/src/app-header/AppHeader.d.ts +0 -6
- package/types/src/app-header/index.d.ts +0 -1
- package/types/src/application-provider/ApplicationContext.d.ts +0 -11
- package/types/src/application-provider/ApplicationProvider.d.ts +0 -17
- package/types/src/application-provider/index.d.ts +0 -1
- package/types/src/feature/Feature.d.ts +0 -10
- package/types/src/feature/FeatureErrorBoundary.d.ts +0 -13
- package/types/src/feature/Loader.d.ts +0 -1
- package/types/src/feature/index.d.ts +0 -1
- package/types/src/feature-and-layout-provider/FeatureAndLayoutProvider.d.ts +0 -19
- package/types/src/feature-and-layout-provider/index.d.ts +0 -1
- package/types/src/feature-list/FeatureList.d.ts +0 -7
- package/types/src/feature-list/index.d.ts +0 -1
- package/types/src/get-layout-history.d.ts +0 -8
- package/types/src/index.d.ts +0 -14
- package/types/src/left-nav/LeftNav.d.ts +0 -14
- package/types/src/left-nav/index.d.ts +0 -1
- package/types/src/login/LoginPanel.d.ts +0 -6
- package/types/src/login/VuuLogo.d.ts +0 -1
- package/types/src/persistence-manager/LocalPersistenceManager.d.ts +0 -20
- package/types/src/persistence-manager/PersistenceManager.d.ts +0 -71
- package/types/src/persistence-manager/PersistenceProvider.d.ts +0 -11
- package/types/src/persistence-manager/RemotePersistenceManager.d.ts +0 -25
- package/types/src/persistence-manager/StaticPersistenceManager.d.ts +0 -25
- package/types/src/persistence-manager/index.d.ts +0 -5
- package/types/src/shell-layout-templates/context-panel/ContextPanel.d.ts +0 -13
- package/types/src/shell-layout-templates/context-panel/index.d.ts +0 -1
- package/types/src/shell-layout-templates/full-height-left-panel/useFullHeightLeftPanel.d.ts +0 -2
- package/types/src/shell-layout-templates/index.d.ts +0 -3
- package/types/src/shell-layout-templates/inlay-left-panel/useInlayLeftPanel.d.ts +0 -2
- package/types/src/shell-layout-templates/left-main-tabs/useLeftMainTabs.d.ts +0 -2
- package/types/src/shell-layout-templates/side-panel/SidePanel.d.ts +0 -8
- package/types/src/shell-layout-templates/side-panel/index.d.ts +0 -1
- package/types/src/shell-layout-templates/simple-content-pane/useSimpleContentPane.d.ts +0 -2
- package/types/src/shell-layout-templates/useShellLayout.d.ts +0 -51
- package/types/src/shell.d.ts +0 -17
- package/types/src/theme-switch/ThemeSwitch.d.ts +0 -8
- package/types/src/theme-switch/index.d.ts +0 -1
- package/types/src/user-settings/SettingsForm.d.ts +0 -46
- package/types/src/user-settings/UserSettingsPanel.d.ts +0 -3
- package/types/src/user-settings/index.d.ts +0 -2
- package/types/src/workspace-management/LayoutList.d.ts +0 -2
- package/types/src/workspace-management/LayoutTile.d.ts +0 -7
- package/types/src/workspace-management/SaveLayoutPanel.d.ts +0 -9
- package/types/src/workspace-management/WorkspaceProvider.d.ts +0 -52
- package/types/src/workspace-management/defaultWorkspaceJSON.d.ts +0 -10
- package/types/src/workspace-management/index.d.ts +0 -5
- package/types/src/workspace-management/screenshot-utils.d.ts +0 -6
- package/types/src/workspace-management/useWorkspaceContextMenuItems.d.ts +0 -5
- package/types/workspace-management/WorkspaceController.d.ts +0 -32
- package/types/workspace-management/WorkspaceHost.d.ts +0 -1
- package/types/workspace-management/WorkspacePersistentState.d.ts +0 -19
- package/types/workspace-management/WorkspaceRepository.d.ts +0 -13
- package/types/workspace-management/WorkspaceStartPanel.d.ts +0 -1
- package/types/workspace-management/shell-workspace-components.d.ts +0 -2
- package/types/workspace-management/workspace-component-registry.d.ts +0 -12
- package/types/workspace-management/workspace-schemas.d.ts +0 -69
|
@@ -1,730 +1,209 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { isLayoutJSON, resolveJSONPath } from "@vuu-ui/vuu-layout";
|
|
3
3
|
import { useNotifications } from "@vuu-ui/vuu-notifications";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
layout: {
|
|
12
|
-
columns: [
|
|
13
|
-
"1fr"
|
|
14
|
-
],
|
|
15
|
-
id: "empty-workspace",
|
|
16
|
-
items: [
|
|
17
|
-
{
|
|
18
|
-
column: {
|
|
19
|
-
span: 1,
|
|
20
|
-
start: 1
|
|
21
|
-
},
|
|
22
|
-
id: "empty-workspace-placeholder",
|
|
23
|
-
row: {
|
|
24
|
-
span: 1,
|
|
25
|
-
start: 1
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
placeholderIds: [
|
|
30
|
-
"empty-workspace-placeholder"
|
|
31
|
-
],
|
|
32
|
-
rows: [
|
|
33
|
-
"1fr"
|
|
34
|
-
],
|
|
35
|
-
stacks: []
|
|
36
|
-
},
|
|
37
|
-
version: GRID_LAYOUT_DOCUMENT_VERSION
|
|
38
|
-
};
|
|
39
|
-
const emptyWorkspaceSnapshot = {
|
|
40
|
-
componentState: {},
|
|
41
|
-
layout: emptyLayout,
|
|
42
|
-
version: WORKSPACE_SNAPSHOT_VERSION
|
|
43
|
-
};
|
|
44
|
-
const missing = async ()=>{
|
|
45
|
-
throw new Error("WorkspaceProvider is not mounted");
|
|
46
|
-
};
|
|
47
|
-
const WorkspaceContext = /*#__PURE__*/ createContext({
|
|
48
|
-
activeWorkspaceInstanceId: null,
|
|
49
|
-
closeWorkspace: missing,
|
|
50
|
-
createWorkspaceFromSnapshot: async ()=>{
|
|
51
|
-
throw new Error("WorkspaceProvider is not mounted");
|
|
52
|
-
},
|
|
53
|
-
controllers: [],
|
|
54
|
-
deleteNamedWorkspace: missing,
|
|
55
|
-
getApplicationSetting: ()=>void 0,
|
|
56
|
-
getApplicationSettings: ()=>void 0,
|
|
57
|
-
namedWorkspaces: [],
|
|
58
|
-
openNamedWorkspace: missing,
|
|
59
|
-
openSystemWorkspace: missing,
|
|
60
|
-
renameWorkspace: missing,
|
|
61
|
-
saveActiveWorkspaceAs: missing,
|
|
62
|
-
saveApplicationSettings: missing,
|
|
63
|
-
selectWorkspace: missing,
|
|
64
|
-
setApplicationSetting: missing,
|
|
65
|
-
settings: {},
|
|
66
|
-
scopeIdentity: "missing",
|
|
67
|
-
status: "loading",
|
|
68
|
-
systemWorkspaces: [],
|
|
69
|
-
resetApplication: missing
|
|
70
|
-
});
|
|
71
|
-
let nextWorkspaceInstance = 1;
|
|
72
|
-
const createInstanceId = ()=>`workspace-${Date.now().toString(36)}-${nextWorkspaceInstance++}`;
|
|
73
|
-
const errorFrom = (cause, message)=>cause instanceof Error ? cause : new Error(message);
|
|
74
|
-
class StaleWorkspaceScopeError extends Error {
|
|
75
|
-
constructor(){
|
|
76
|
-
super("Workspace operation belongs to an inactive persistence scope");
|
|
77
|
-
this.name = "StaleWorkspaceScopeError";
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const remapSnapshot = (source, instanceId)=>{
|
|
81
|
-
const { document, mappings } = remapGridLayoutDocumentIds(source.layout, createSequentialGridLayoutIdAllocator(instanceId));
|
|
82
|
-
const componentIds = new Map(mappings.filter(({ kind })=>"component" === kind).map(({ newId, oldId })=>[
|
|
83
|
-
oldId,
|
|
84
|
-
newId
|
|
85
|
-
]));
|
|
4
|
+
import { VuuShellLocation, WorkspaceContext, logger } from "@vuu-ui/vuu-utils";
|
|
5
|
+
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { usePersistenceManager } from "../persistence-manager/index.js";
|
|
7
|
+
import { getWorkspaceWithLayoutJSON, loadingJSON } from "./defaultWorkspaceJSON.js";
|
|
8
|
+
const { info: info } = logger("useLayoutManager");
|
|
9
|
+
const ensureLayoutHasTitle = (layout, layoutMetadata)=>{
|
|
10
|
+
if (layout.props?.title !== void 0) return layout;
|
|
86
11
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
]))
|
|
12
|
+
...layout,
|
|
13
|
+
props: {
|
|
14
|
+
...layout.props,
|
|
15
|
+
title: layoutMetadata.name
|
|
16
|
+
}
|
|
93
17
|
};
|
|
94
18
|
};
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
19
|
+
const loadingApplicationJSON = {
|
|
20
|
+
workspaceJSON: loadingJSON
|
|
21
|
+
};
|
|
22
|
+
const WorkspaceProvider = ({ TabstripProps, children, layoutJSON, activeLayoutIndex, layoutPlaceholderJSON, showTabs, workspaceJSON: customWorkspaceJSON })=>{
|
|
23
|
+
const [layoutMetadata, setLayoutMetadata] = useState([]);
|
|
24
|
+
const [, forceRefresh] = useState({});
|
|
98
25
|
const { showNotification } = useNotifications();
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
};
|
|
122
|
-
const status = loadedScope !== scopeKey ? "loading" : loadError ? "error" : 0 === controllers.length ? "empty" : "ready";
|
|
123
|
-
const notifyError = useCallback((header, cause)=>{
|
|
124
|
-
const error = errorFrom(cause, header);
|
|
125
|
-
showNotification({
|
|
126
|
-
content: error.message,
|
|
127
|
-
header,
|
|
128
|
-
status: "error",
|
|
129
|
-
type: "toast"
|
|
130
|
-
});
|
|
131
|
-
return error;
|
|
132
|
-
}, [
|
|
133
|
-
showNotification
|
|
134
|
-
]);
|
|
135
|
-
const captureScope = useCallback((expectedService = service, expectedScopeKey = scopeKey)=>{
|
|
136
|
-
const active = activeScope.current;
|
|
137
|
-
if (!expectedService || active.service !== expectedService || active.scopeKey !== expectedScopeKey || active.generation !== generation.current) throw new StaleWorkspaceScopeError();
|
|
138
|
-
return {
|
|
139
|
-
generation: active.generation,
|
|
140
|
-
scopeKey: active.scopeKey,
|
|
141
|
-
service: expectedService
|
|
142
|
-
};
|
|
26
|
+
const persistenceManager = usePersistenceManager();
|
|
27
|
+
const applicationJSONRef = useRef(loadingApplicationJSON);
|
|
28
|
+
const setApplicationJSON = useCallback((applicationJSON, rerender = true)=>{
|
|
29
|
+
applicationJSONRef.current = applicationJSON;
|
|
30
|
+
if (rerender) forceRefresh({});
|
|
31
|
+
}, []);
|
|
32
|
+
const setWorkspaceJSON = useCallback((workspaceJSON, rerender = true)=>{
|
|
33
|
+
setApplicationJSON({
|
|
34
|
+
...applicationJSONRef.current,
|
|
35
|
+
workspaceJSON
|
|
36
|
+
}, rerender);
|
|
37
|
+
}, [
|
|
38
|
+
setApplicationJSON
|
|
39
|
+
]);
|
|
40
|
+
const setApplicationSettings = useCallback((settings)=>{
|
|
41
|
+
setApplicationJSON({
|
|
42
|
+
...applicationJSONRef.current,
|
|
43
|
+
settings: {
|
|
44
|
+
...applicationJSONRef.current.settings,
|
|
45
|
+
...settings
|
|
46
|
+
}
|
|
47
|
+
}, false);
|
|
143
48
|
}, [
|
|
144
|
-
|
|
145
|
-
service
|
|
49
|
+
setApplicationJSON
|
|
146
50
|
]);
|
|
147
|
-
const assertScope = useCallback((guard)=>{
|
|
148
|
-
const active = activeScope.current;
|
|
149
|
-
if (generation.current !== guard.generation || active.generation !== guard.generation || active.scopeKey !== guard.scopeKey || active.service !== guard.service) throw new StaleWorkspaceScopeError();
|
|
150
|
-
}, []);
|
|
151
|
-
const replaceControllers = useCallback((next)=>{
|
|
152
|
-
controllersRef.current = next;
|
|
153
|
-
setControllers(next);
|
|
154
|
-
}, []);
|
|
155
51
|
useEffect(()=>{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (legacyProps.length > 0) {
|
|
182
|
-
const error = notifyError("Legacy Workspace Configuration Is Not Supported", new Error(`WorkspaceProvider no longer accepts ${legacyProps.join(", ")}; inject a WorkspacePersistenceService and provide defaultWorkspace as a versioned snapshot`));
|
|
183
|
-
setLoadError(error);
|
|
184
|
-
setLoadedScope(scopeKey);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (!scopeIsValid) {
|
|
188
|
-
const error = notifyError("Workspace Scope Does Not Match", new Error(`Workspace persistence scope "${service.scope.userId}" does not match authenticated user "${userId}"`));
|
|
189
|
-
setLoadError(error);
|
|
190
|
-
setLoadedScope(scopeKey);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const guard = captureScope();
|
|
194
|
-
const load = async ()=>{
|
|
195
|
-
const restored = [];
|
|
196
|
-
try {
|
|
197
|
-
assertScope(guard);
|
|
198
|
-
const [loadedSession, metadata] = await Promise.all([
|
|
199
|
-
guard.service.loadApplicationSession(),
|
|
200
|
-
guard.service.listNamedWorkspaceMetadata()
|
|
201
|
-
]);
|
|
202
|
-
assertScope(guard);
|
|
203
|
-
if (loadedSession) {
|
|
204
|
-
const descriptors = new Map(loadedSession.openWorkspaces.map((entry)=>[
|
|
205
|
-
entry.instanceId,
|
|
206
|
-
entry
|
|
207
|
-
]));
|
|
208
|
-
for (const instanceId of loadedSession.workspaceOrder){
|
|
209
|
-
const descriptor = descriptors.get(instanceId);
|
|
210
|
-
if (!descriptor) throw new Error(`Session references missing workspace "${instanceId}"`);
|
|
211
|
-
assertScope(guard);
|
|
212
|
-
const record = await guard.service.loadWorkspaceSnapshot(descriptor.snapshotId);
|
|
213
|
-
assertScope(guard);
|
|
214
|
-
if (!record) throw new Error(`Snapshot for workspace "${instanceId}" was not found`);
|
|
215
|
-
const definitionMetadata = metadata.find(({ id })=>id === descriptor.definitionId);
|
|
216
|
-
restored.push(new WorkspaceController({
|
|
217
|
-
definitionId: descriptor.definitionId,
|
|
218
|
-
instanceId,
|
|
219
|
-
name: descriptor.title ?? definitionMetadata?.name ?? instanceId,
|
|
220
|
-
onError: (error)=>{
|
|
221
|
-
try {
|
|
222
|
-
assertScope(guard);
|
|
223
|
-
notifyError("Failed to Save Workspace", error);
|
|
224
|
-
} catch {}
|
|
225
|
-
},
|
|
226
|
-
renderers: componentRenderers ?? (()=>{
|
|
227
|
-
throw new Error("Workspace component renderers are required");
|
|
228
|
-
})(),
|
|
229
|
-
service: guard.service,
|
|
230
|
-
revision: record.revision,
|
|
231
|
-
settingsCodecs: settingsCodecs ?? (()=>{
|
|
232
|
-
throw new Error("Workspace settings codecs are required");
|
|
233
|
-
})(),
|
|
234
|
-
snapshot: record.snapshot
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
let resolvedSession = loadedSession ?? {
|
|
239
|
-
activeWorkspaceInstanceId: null,
|
|
240
|
-
openWorkspaces: [],
|
|
241
|
-
settings: {},
|
|
242
|
-
version: APPLICATION_SESSION_VERSION,
|
|
243
|
-
workspaceOrder: []
|
|
244
|
-
};
|
|
245
|
-
if (!loadedSession && defaultWorkspace) {
|
|
246
|
-
if (!componentRenderers || !settingsCodecs) throw new Error("Default workspace requires component renderers and settings codecs");
|
|
247
|
-
const instanceId = createInstanceId();
|
|
248
|
-
const initialSnapshot = remapSnapshot(defaultWorkspace, instanceId);
|
|
249
|
-
const controller = new WorkspaceController({
|
|
250
|
-
instanceId,
|
|
251
|
-
name: "Workspace",
|
|
252
|
-
onError: (error)=>{
|
|
253
|
-
try {
|
|
254
|
-
assertScope(guard);
|
|
255
|
-
notifyError("Failed to Save Workspace", error);
|
|
256
|
-
} catch {}
|
|
257
|
-
},
|
|
258
|
-
renderers: componentRenderers,
|
|
259
|
-
service: guard.service,
|
|
260
|
-
settingsCodecs,
|
|
261
|
-
snapshot: initialSnapshot
|
|
262
|
-
});
|
|
263
|
-
assertScope(guard);
|
|
264
|
-
await controller.repository.save(initialSnapshot);
|
|
265
|
-
assertScope(guard);
|
|
266
|
-
restored.push(controller);
|
|
267
|
-
resolvedSession = {
|
|
268
|
-
activeWorkspaceInstanceId: instanceId,
|
|
269
|
-
openWorkspaces: [
|
|
270
|
-
{
|
|
271
|
-
instanceId,
|
|
272
|
-
snapshotId: instanceId,
|
|
273
|
-
title: "Workspace"
|
|
274
|
-
}
|
|
275
|
-
],
|
|
276
|
-
settings: {},
|
|
277
|
-
version: APPLICATION_SESSION_VERSION,
|
|
278
|
-
workspaceOrder: [
|
|
279
|
-
instanceId
|
|
280
|
-
]
|
|
281
|
-
};
|
|
282
|
-
await guard.service.saveApplicationSession(resolvedSession);
|
|
283
|
-
assertScope(guard);
|
|
284
|
-
}
|
|
285
|
-
assertScope(guard);
|
|
286
|
-
replaceControllers(restored);
|
|
287
|
-
sessionRef.current = resolvedSession;
|
|
288
|
-
setSession(resolvedSession);
|
|
289
|
-
setNamedWorkspaces(metadata);
|
|
290
|
-
setLoadedScope(scopeKey);
|
|
291
|
-
} catch (cause) {
|
|
292
|
-
restored.forEach((controller)=>{
|
|
293
|
-
controller.dispose();
|
|
52
|
+
persistenceManager?.loadMetadata().then((metadata)=>{
|
|
53
|
+
setLayoutMetadata(metadata);
|
|
54
|
+
}).catch((error)=>{
|
|
55
|
+
showNotification({
|
|
56
|
+
content: "Could not load list of available layouts",
|
|
57
|
+
header: "Failed to Load Layouts",
|
|
58
|
+
status: "error",
|
|
59
|
+
type: "toast"
|
|
60
|
+
});
|
|
61
|
+
console.error("Error occurred while retrieving metadata", error);
|
|
62
|
+
});
|
|
63
|
+
persistenceManager?.loadApplicationJSON().then((applicationJSON)=>{
|
|
64
|
+
if (applicationJSON) {
|
|
65
|
+
info?.("applicationJSON loaded successfully");
|
|
66
|
+
setApplicationJSON(applicationJSON);
|
|
67
|
+
} else {
|
|
68
|
+
const workspaceJSON = getWorkspaceWithLayoutJSON(customWorkspaceJSON, layoutJSON, activeLayoutIndex, {
|
|
69
|
+
TabstripProps,
|
|
70
|
+
showTabs
|
|
71
|
+
});
|
|
72
|
+
info?.(`applicationJSON not found, getting defaultWorkspaceJSON,
|
|
73
|
+
${JSON.stringify(workspaceJSON, null, 2)}
|
|
74
|
+
`);
|
|
75
|
+
setApplicationJSON({
|
|
76
|
+
workspaceJSON
|
|
294
77
|
});
|
|
295
|
-
if (!(cause instanceof StaleWorkspaceScopeError)) try {
|
|
296
|
-
assertScope(guard);
|
|
297
|
-
const error = notifyError("Failed to Load Workspaces", cause);
|
|
298
|
-
setLoadError(error);
|
|
299
|
-
setLoadedScope(scopeKey);
|
|
300
|
-
} catch {}
|
|
301
78
|
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
};
|
|
79
|
+
}).catch((error)=>{
|
|
80
|
+
showNotification({
|
|
81
|
+
content: "Could not load your latest view",
|
|
82
|
+
header: "Failed to Load Layout",
|
|
83
|
+
status: "error",
|
|
84
|
+
type: "toast"
|
|
85
|
+
});
|
|
86
|
+
console.error("Error occurred while retrieving application layout", error);
|
|
87
|
+
});
|
|
312
88
|
}, [
|
|
313
|
-
|
|
89
|
+
TabstripProps,
|
|
314
90
|
activeLayoutIndex,
|
|
315
|
-
|
|
316
|
-
captureScope,
|
|
317
|
-
defaultWorkspace,
|
|
91
|
+
customWorkspaceJSON,
|
|
318
92
|
layoutJSON,
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (resetGeneration.current !== expectedResetGeneration) throw new Error("Workspace operation was invalidated by application reset");
|
|
347
|
-
return operation();
|
|
348
|
-
});
|
|
349
|
-
operationQueue.current = result.then(()=>void 0, ()=>void 0);
|
|
350
|
-
return result;
|
|
351
|
-
}, [
|
|
352
|
-
assertScope
|
|
353
|
-
]);
|
|
354
|
-
const addWorkspace = useCallback(async (sourceSnapshot, name, definitionId, operationGuard)=>{
|
|
355
|
-
if (!service || !componentRenderers || !settingsCodecs) throw new Error("Workspace runtime is not configured");
|
|
356
|
-
const guard = operationGuard ?? captureScope();
|
|
357
|
-
return enqueueOperation(guard, async ()=>{
|
|
358
|
-
assertScope(guard);
|
|
359
|
-
const instanceId = createInstanceId();
|
|
360
|
-
const snapshot = remapSnapshot(sourceSnapshot, instanceId);
|
|
361
|
-
const controller = new WorkspaceController({
|
|
362
|
-
definitionId,
|
|
363
|
-
instanceId,
|
|
364
|
-
name,
|
|
365
|
-
onError: (error)=>void notifyError("Failed to Save Workspace", error),
|
|
366
|
-
renderers: componentRenderers,
|
|
367
|
-
service: guard.service,
|
|
368
|
-
settingsCodecs,
|
|
369
|
-
snapshot
|
|
93
|
+
showNotification,
|
|
94
|
+
persistenceManager,
|
|
95
|
+
setApplicationJSON,
|
|
96
|
+
showTabs
|
|
97
|
+
]);
|
|
98
|
+
const saveApplicationLayout = useCallback((layout)=>{
|
|
99
|
+
if (isLayoutJSON(layout)) {
|
|
100
|
+
setWorkspaceJSON(layout, false);
|
|
101
|
+
persistenceManager?.saveApplicationJSON(applicationJSONRef.current);
|
|
102
|
+
} else console.error("Tried to save invalid application layout", layout);
|
|
103
|
+
}, [
|
|
104
|
+
persistenceManager,
|
|
105
|
+
setWorkspaceJSON
|
|
106
|
+
]);
|
|
107
|
+
const saveLayout = useCallback((metadata)=>{
|
|
108
|
+
let layoutToSave;
|
|
109
|
+
try {
|
|
110
|
+
const { workspaceJSON } = applicationJSONRef.current;
|
|
111
|
+
if (Array.isArray(workspaceJSON)) console.log("how do we identify the right thing to save");
|
|
112
|
+
else layoutToSave = resolveJSONPath(workspaceJSON, `#${VuuShellLocation.Workspace}.ACTIVE_CHILD`);
|
|
113
|
+
} catch (e) {}
|
|
114
|
+
if (layoutToSave && isLayoutJSON(layoutToSave)) persistenceManager?.createLayout(metadata, ensureLayoutHasTitle(layoutToSave, metadata)).then((metadata)=>{
|
|
115
|
+
showNotification({
|
|
116
|
+
content: `${metadata.name} saved successfully`,
|
|
117
|
+
header: "Layout Saved Successfully",
|
|
118
|
+
status: "success",
|
|
119
|
+
type: "toast"
|
|
370
120
|
});
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
activeWorkspaceInstanceId: null,
|
|
375
|
-
openWorkspaces: [],
|
|
376
|
-
settings: {},
|
|
377
|
-
version: APPLICATION_SESSION_VERSION,
|
|
378
|
-
workspaceOrder: []
|
|
379
|
-
};
|
|
380
|
-
try {
|
|
381
|
-
await writeSession({
|
|
382
|
-
...current,
|
|
383
|
-
activeWorkspaceInstanceId: instanceId,
|
|
384
|
-
openWorkspaces: [
|
|
385
|
-
...current.openWorkspaces,
|
|
386
|
-
{
|
|
387
|
-
...void 0 === definitionId ? {} : {
|
|
388
|
-
definitionId
|
|
389
|
-
},
|
|
390
|
-
instanceId,
|
|
391
|
-
snapshotId: instanceId,
|
|
392
|
-
title: name
|
|
393
|
-
}
|
|
394
|
-
],
|
|
395
|
-
workspaceOrder: [
|
|
396
|
-
...current.workspaceOrder,
|
|
397
|
-
instanceId
|
|
398
|
-
]
|
|
399
|
-
}, guard);
|
|
400
|
-
assertScope(guard);
|
|
401
|
-
replaceControllers([
|
|
402
|
-
...controllersRef.current,
|
|
403
|
-
controller
|
|
121
|
+
setLayoutMetadata((prev)=>[
|
|
122
|
+
...prev,
|
|
123
|
+
metadata
|
|
404
124
|
]);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
});
|
|
414
|
-
}, [
|
|
415
|
-
componentRenderers,
|
|
416
|
-
assertScope,
|
|
417
|
-
captureScope,
|
|
418
|
-
enqueueOperation,
|
|
419
|
-
notifyError,
|
|
420
|
-
replaceControllers,
|
|
421
|
-
service,
|
|
422
|
-
settingsCodecs,
|
|
423
|
-
writeSession
|
|
424
|
-
]);
|
|
425
|
-
const addDefinition = useCallback((definition, operationGuard)=>addWorkspace(definition.snapshot, definition.name, definition.id, operationGuard), [
|
|
426
|
-
addWorkspace
|
|
427
|
-
]);
|
|
428
|
-
const openSystemWorkspace = useCallback(async (definition)=>{
|
|
429
|
-
await addDefinition(definition);
|
|
430
|
-
}, [
|
|
431
|
-
addDefinition
|
|
432
|
-
]);
|
|
433
|
-
const createWorkspaceFromSnapshot = useCallback(async (snapshot, title = "Untitled")=>{
|
|
434
|
-
try {
|
|
435
|
-
return await addWorkspace(snapshot, title);
|
|
436
|
-
} catch (cause) {
|
|
437
|
-
if (!(cause instanceof StaleWorkspaceScopeError)) notifyError("Failed to Create Workspace", cause);
|
|
438
|
-
throw cause;
|
|
439
|
-
}
|
|
440
|
-
}, [
|
|
441
|
-
addWorkspace,
|
|
442
|
-
notifyError
|
|
443
|
-
]);
|
|
444
|
-
const openNamedWorkspace = useCallback(async (definitionId)=>{
|
|
445
|
-
if (!service) throw new Error("Workspace persistence service is not configured");
|
|
446
|
-
const guard = captureScope();
|
|
447
|
-
const expectedResetGeneration = resetGeneration.current;
|
|
448
|
-
try {
|
|
449
|
-
assertScope(guard);
|
|
450
|
-
const definition = await guard.service.loadNamedWorkspaceDefinition(definitionId);
|
|
451
|
-
assertScope(guard);
|
|
452
|
-
if (resetGeneration.current !== expectedResetGeneration) throw new Error("Workspace operation was invalidated by application reset");
|
|
453
|
-
if (!definition) throw new Error(`Workspace definition "${definitionId}" was not found`);
|
|
454
|
-
await addDefinition(definition, guard);
|
|
455
|
-
} catch (cause) {
|
|
456
|
-
if (!(cause instanceof StaleWorkspaceScopeError)) notifyError("Failed to Open Workspace", cause);
|
|
457
|
-
}
|
|
458
|
-
}, [
|
|
459
|
-
addDefinition,
|
|
460
|
-
assertScope,
|
|
461
|
-
captureScope,
|
|
462
|
-
notifyError,
|
|
463
|
-
service
|
|
464
|
-
]);
|
|
465
|
-
const selectWorkspace = useCallback(async (instanceId)=>{
|
|
466
|
-
const guard = captureScope();
|
|
467
|
-
await enqueueOperation(guard, async ()=>{
|
|
468
|
-
const current = sessionRef.current;
|
|
469
|
-
if (!current || !current.workspaceOrder.includes(instanceId)) throw new Error(`Workspace "${instanceId}" is not open`);
|
|
470
|
-
await writeSession({
|
|
471
|
-
...current,
|
|
472
|
-
activeWorkspaceInstanceId: instanceId
|
|
473
|
-
}, guard);
|
|
125
|
+
}).catch((error)=>{
|
|
126
|
+
showNotification({
|
|
127
|
+
content: `Failed to save layout ${metadata.name}`,
|
|
128
|
+
header: "Failed to Save Layout",
|
|
129
|
+
status: "error",
|
|
130
|
+
type: "toast"
|
|
131
|
+
});
|
|
132
|
+
console.error("Error occurred while saving layout", error);
|
|
474
133
|
});
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (!trimmedTitle) throw new Error("Workspace title must not be empty");
|
|
483
|
-
const guard = captureScope();
|
|
484
|
-
try {
|
|
485
|
-
await enqueueOperation(guard, async ()=>{
|
|
486
|
-
const current = sessionRef.current;
|
|
487
|
-
const controller = controllersRef.current.find((candidate)=>candidate.instanceId === instanceId);
|
|
488
|
-
if (!current || !controller) throw new Error(`Workspace "${instanceId}" is not open`);
|
|
489
|
-
await writeSession({
|
|
490
|
-
...current,
|
|
491
|
-
openWorkspaces: current.openWorkspaces.map((workspace)=>workspace.instanceId === instanceId ? {
|
|
492
|
-
...workspace,
|
|
493
|
-
title: trimmedTitle
|
|
494
|
-
} : workspace)
|
|
495
|
-
}, guard);
|
|
496
|
-
assertScope(guard);
|
|
497
|
-
controller.rename(trimmedTitle);
|
|
498
|
-
replaceControllers([
|
|
499
|
-
...controllersRef.current
|
|
500
|
-
]);
|
|
134
|
+
else {
|
|
135
|
+
console.error("Tried to save invalid layout", layoutToSave);
|
|
136
|
+
showNotification({
|
|
137
|
+
content: "Cannot save invalid layout",
|
|
138
|
+
header: "Failed to Save Layout",
|
|
139
|
+
status: "error",
|
|
140
|
+
type: "toast"
|
|
501
141
|
});
|
|
502
|
-
} catch (cause) {
|
|
503
|
-
if (!(cause instanceof StaleWorkspaceScopeError)) notifyError("Failed to Rename Workspace", cause);
|
|
504
|
-
throw cause;
|
|
505
142
|
}
|
|
506
143
|
}, [
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
enqueueOperation,
|
|
510
|
-
notifyError,
|
|
511
|
-
replaceControllers,
|
|
512
|
-
writeSession
|
|
513
|
-
]);
|
|
514
|
-
const closeWorkspace = useCallback(async (instanceId)=>{
|
|
515
|
-
if (!service) throw new Error("Workspace persistence service is not configured");
|
|
516
|
-
const guard = captureScope();
|
|
517
|
-
await enqueueOperation(guard, async ()=>{
|
|
518
|
-
const current = sessionRef.current;
|
|
519
|
-
const controller = controllersRef.current.find((candidate)=>candidate.instanceId === instanceId);
|
|
520
|
-
if (!current || !controller) return;
|
|
521
|
-
const nextControllers = controllersRef.current.filter((candidate)=>candidate !== controller);
|
|
522
|
-
const closedIndex = current.workspaceOrder.indexOf(instanceId);
|
|
523
|
-
const order = current.workspaceOrder.filter((id)=>id !== instanceId);
|
|
524
|
-
const active = current.activeWorkspaceInstanceId === instanceId ? order[Math.min(closedIndex, order.length - 1)] ?? null : current.activeWorkspaceInstanceId;
|
|
525
|
-
await writeSession({
|
|
526
|
-
...current,
|
|
527
|
-
activeWorkspaceInstanceId: active,
|
|
528
|
-
openWorkspaces: current.openWorkspaces.filter(({ instanceId: id })=>id !== instanceId),
|
|
529
|
-
workspaceOrder: order
|
|
530
|
-
}, guard);
|
|
531
|
-
assertScope(guard);
|
|
532
|
-
await controller.dispose();
|
|
533
|
-
replaceControllers(nextControllers);
|
|
534
|
-
await guard.service.deleteWorkspaceSnapshot(instanceId);
|
|
535
|
-
assertScope(guard);
|
|
536
|
-
});
|
|
537
|
-
}, [
|
|
538
|
-
assertScope,
|
|
539
|
-
captureScope,
|
|
540
|
-
enqueueOperation,
|
|
541
|
-
replaceControllers,
|
|
542
|
-
service,
|
|
543
|
-
writeSession
|
|
144
|
+
showNotification,
|
|
145
|
+
persistenceManager
|
|
544
146
|
]);
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}, [
|
|
553
|
-
assertScope,
|
|
554
|
-
captureScope,
|
|
555
|
-
service
|
|
556
|
-
]);
|
|
557
|
-
const saveActiveWorkspaceAs = useCallback(async (name, description)=>{
|
|
558
|
-
if (!service) throw new Error("Workspace persistence service is not configured");
|
|
559
|
-
const guard = captureScope();
|
|
560
|
-
assertScope(guard);
|
|
561
|
-
const activeId = sessionRef.current?.activeWorkspaceInstanceId;
|
|
562
|
-
const active = controllersRef.current.find(({ instanceId })=>instanceId === activeId);
|
|
563
|
-
if (!active) throw new Error("There is no active workspace to save");
|
|
564
|
-
const now = new Date().toISOString();
|
|
565
|
-
const id = createInstanceId();
|
|
566
|
-
const definition = {
|
|
567
|
-
createdAt: now,
|
|
568
|
-
...void 0 === description ? {} : {
|
|
569
|
-
description
|
|
570
|
-
},
|
|
571
|
-
id,
|
|
572
|
-
name,
|
|
573
|
-
snapshot: active.snapshot,
|
|
574
|
-
updatedAt: now,
|
|
575
|
-
version: NAMED_WORKSPACE_DEFINITION_VERSION
|
|
576
|
-
};
|
|
577
|
-
await guard.service.saveNamedWorkspaceDefinition(definition);
|
|
578
|
-
assertScope(guard);
|
|
579
|
-
setNamedWorkspaces((current)=>[
|
|
580
|
-
...current,
|
|
581
|
-
{
|
|
582
|
-
createdAt: now,
|
|
583
|
-
...void 0 === description ? {} : {
|
|
584
|
-
description
|
|
585
|
-
},
|
|
586
|
-
id,
|
|
587
|
-
name,
|
|
588
|
-
updatedAt: now,
|
|
589
|
-
version: NAMED_WORKSPACE_DEFINITION_VERSION
|
|
590
|
-
}
|
|
591
|
-
]);
|
|
147
|
+
const saveApplicationSettings = useCallback((settings, key)=>{
|
|
148
|
+
const { settings: applicationSettings } = applicationJSONRef.current;
|
|
149
|
+
key ? setApplicationSettings({
|
|
150
|
+
...applicationSettings,
|
|
151
|
+
[key]: settings
|
|
152
|
+
}) : setApplicationSettings(settings);
|
|
153
|
+
persistenceManager?.saveApplicationJSON(applicationJSONRef.current);
|
|
592
154
|
}, [
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
service
|
|
155
|
+
persistenceManager,
|
|
156
|
+
setApplicationSettings
|
|
596
157
|
]);
|
|
597
|
-
const
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
158
|
+
const getApplicationSettings = useCallback((key)=>{
|
|
159
|
+
const { settings } = applicationJSONRef.current;
|
|
160
|
+
return key ? settings?.[key] : settings;
|
|
161
|
+
}, []);
|
|
162
|
+
const loadLayoutById = useCallback((id)=>{
|
|
163
|
+
persistenceManager?.loadLayout(id).then((layoutJson)=>{
|
|
164
|
+
const { workspaceJSON: currentLayout } = applicationJSONRef.current;
|
|
165
|
+
if (Array.isArray(currentLayout)) console.log("how do we deal witha amulti layoput");
|
|
166
|
+
else setWorkspaceJSON({
|
|
167
|
+
...currentLayout,
|
|
168
|
+
children: (currentLayout.children || []).concat(layoutJson),
|
|
169
|
+
props: {
|
|
170
|
+
...currentLayout.props,
|
|
171
|
+
active: currentLayout.children?.length ?? 0
|
|
607
172
|
}
|
|
608
|
-
}
|
|
609
|
-
})
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
if ("object" != typeof value || null === value || Array.isArray(value)) throw new Error("Application settings must be a JSON object");
|
|
618
|
-
const guard = captureScope();
|
|
619
|
-
await enqueueOperation(guard, async ()=>{
|
|
620
|
-
const current = sessionRef.current;
|
|
621
|
-
if (!current) throw new Error("Application session has not loaded");
|
|
622
|
-
await writeSession({
|
|
623
|
-
...current,
|
|
624
|
-
settings: value
|
|
625
|
-
}, guard);
|
|
626
|
-
});
|
|
627
|
-
}, [
|
|
628
|
-
captureScope,
|
|
629
|
-
enqueueOperation,
|
|
630
|
-
setApplicationSetting,
|
|
631
|
-
writeSession
|
|
632
|
-
]);
|
|
633
|
-
const resetApplication = useCallback(async ()=>{
|
|
634
|
-
const guard = captureScope();
|
|
635
|
-
assertScope(guard);
|
|
636
|
-
if (resetPending.current) throw new Error("Application reset is already in progress");
|
|
637
|
-
resetPending.current = true;
|
|
638
|
-
resetGeneration.current += 1;
|
|
639
|
-
const reset = operationQueue.current.catch(()=>void 0).then(async ()=>{
|
|
640
|
-
assertScope(guard);
|
|
641
|
-
const instanceIds = sessionRef.current?.openWorkspaces.map(({ snapshotId })=>snapshotId) ?? [];
|
|
642
|
-
await guard.service.deleteApplicationSession();
|
|
643
|
-
assertScope(guard);
|
|
644
|
-
await Promise.all(controllersRef.current.map((controller)=>controller.dispose()));
|
|
645
|
-
replaceControllers([]);
|
|
646
|
-
const emptySession = {
|
|
647
|
-
activeWorkspaceInstanceId: null,
|
|
648
|
-
openWorkspaces: [],
|
|
649
|
-
settings: {},
|
|
650
|
-
version: APPLICATION_SESSION_VERSION,
|
|
651
|
-
workspaceOrder: []
|
|
652
|
-
};
|
|
653
|
-
sessionRef.current = emptySession;
|
|
654
|
-
setSession(emptySession);
|
|
655
|
-
for (const snapshotId of instanceIds){
|
|
656
|
-
assertScope(guard);
|
|
657
|
-
await guard.service.deleteWorkspaceSnapshot(snapshotId);
|
|
658
|
-
assertScope(guard);
|
|
659
|
-
}
|
|
173
|
+
});
|
|
174
|
+
}).catch((error)=>{
|
|
175
|
+
showNotification({
|
|
176
|
+
content: "Failed to load the requested layout",
|
|
177
|
+
header: "Failed to Load Layout",
|
|
178
|
+
status: "error",
|
|
179
|
+
type: "toast"
|
|
180
|
+
});
|
|
181
|
+
console.error("Error occurred while loading layout", error);
|
|
660
182
|
});
|
|
661
|
-
operationQueue.current = reset.then(()=>void 0, ()=>void 0);
|
|
662
|
-
try {
|
|
663
|
-
await reset;
|
|
664
|
-
} finally{
|
|
665
|
-
if (activeScope.current.generation === guard.generation && activeScope.current.scopeKey === guard.scopeKey) resetPending.current = false;
|
|
666
|
-
}
|
|
667
|
-
}, [
|
|
668
|
-
assertScope,
|
|
669
|
-
captureScope,
|
|
670
|
-
replaceControllers
|
|
671
|
-
]);
|
|
672
|
-
const value = useMemo(()=>{
|
|
673
|
-
const settings = session?.settings ?? {};
|
|
674
|
-
const visibleControllers = "loading" === status ? [] : controllers;
|
|
675
|
-
const activeWorkspace = visibleControllers.find(({ instanceId })=>instanceId === session?.activeWorkspaceInstanceId);
|
|
676
|
-
return {
|
|
677
|
-
activeWorkspace,
|
|
678
|
-
activeWorkspaceInstanceId: session?.activeWorkspaceInstanceId ?? null,
|
|
679
|
-
closeWorkspace,
|
|
680
|
-
componentRenderers,
|
|
681
|
-
controllers: visibleControllers,
|
|
682
|
-
createWorkspaceFromSnapshot,
|
|
683
|
-
deleteNamedWorkspace,
|
|
684
|
-
error: loadError,
|
|
685
|
-
getApplicationSetting: (key)=>settings[key],
|
|
686
|
-
getApplicationSettings: (key)=>void 0 === key ? settings : settings[key],
|
|
687
|
-
namedWorkspaces,
|
|
688
|
-
openNamedWorkspace,
|
|
689
|
-
openSystemWorkspace,
|
|
690
|
-
renameWorkspace,
|
|
691
|
-
saveActiveWorkspaceAs,
|
|
692
|
-
saveApplicationSettings,
|
|
693
|
-
selectWorkspace,
|
|
694
|
-
setApplicationSetting,
|
|
695
|
-
settings,
|
|
696
|
-
settingsCodecs,
|
|
697
|
-
scopeIdentity: scopeKey,
|
|
698
|
-
status,
|
|
699
|
-
systemWorkspaces,
|
|
700
|
-
resetApplication
|
|
701
|
-
};
|
|
702
183
|
}, [
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
createWorkspaceFromSnapshot,
|
|
707
|
-
deleteNamedWorkspace,
|
|
708
|
-
loadError,
|
|
709
|
-
namedWorkspaces,
|
|
710
|
-
openNamedWorkspace,
|
|
711
|
-
openSystemWorkspace,
|
|
712
|
-
renameWorkspace,
|
|
713
|
-
saveActiveWorkspaceAs,
|
|
714
|
-
saveApplicationSettings,
|
|
715
|
-
selectWorkspace,
|
|
716
|
-
session,
|
|
717
|
-
setApplicationSetting,
|
|
718
|
-
settingsCodecs,
|
|
719
|
-
scopeKey,
|
|
720
|
-
status,
|
|
721
|
-
systemWorkspaces,
|
|
722
|
-
resetApplication
|
|
184
|
+
showNotification,
|
|
185
|
+
persistenceManager,
|
|
186
|
+
setWorkspaceJSON
|
|
723
187
|
]);
|
|
724
188
|
return /*#__PURE__*/ jsx(WorkspaceContext.Provider, {
|
|
725
|
-
value:
|
|
189
|
+
value: {
|
|
190
|
+
getApplicationSettings,
|
|
191
|
+
layoutMetadata,
|
|
192
|
+
layoutPlaceholderJSON,
|
|
193
|
+
saveLayout,
|
|
194
|
+
workspaceJSON: applicationJSONRef.current.workspaceJSON,
|
|
195
|
+
saveApplicationLayout,
|
|
196
|
+
saveApplicationSettings,
|
|
197
|
+
loadLayoutById
|
|
198
|
+
},
|
|
726
199
|
children: children
|
|
727
200
|
});
|
|
728
201
|
};
|
|
729
|
-
const useWorkspace = ()=>
|
|
730
|
-
|
|
202
|
+
const useWorkspace = ()=>{
|
|
203
|
+
const { workspaceJSON = getWorkspaceWithLayoutJSON(), ...contextProps } = useContext(WorkspaceContext);
|
|
204
|
+
return {
|
|
205
|
+
...contextProps,
|
|
206
|
+
workspaceJSON
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
export { WorkspaceProvider, useWorkspace };
|