@tano.page/workbench 0.15.0 → 0.16.0
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 +35 -14
- package/src/App.vue +68 -797
- package/src/assistant/agent-identities.ts +1 -97
- package/src/assistant/agent-task-context.ts +1 -54
- package/src/assistant/attachments.ts +1 -1
- package/src/assistant/completion.ts +1 -61
- package/src/assistant/components/AssistantPanel.vue +1 -1
- package/src/assistant/connection-actions.ts +237 -0
- package/src/assistant/document-mentions.ts +1 -33
- package/src/assistant/engine.ts +1 -585
- package/src/assistant/execution.ts +6 -33
- package/src/assistant/hash.ts +1 -4
- package/src/assistant/language.ts +10 -37
- package/src/assistant/plugin-bridge-builder.ts +146 -0
- package/src/assistant/prompts.ts +1 -65
- package/src/assistant/proposal-actions.ts +336 -0
- package/src/assistant/store.ts +87 -554
- package/src/assistant/structures.ts +1 -157
- package/src/assistant/tasks.ts +8 -94
- package/src/assistant/tool-rules.ts +1 -7
- package/src/composables/use-workbench-help.ts +177 -0
- package/src/composables/use-workbench-lifecycle.ts +249 -0
- package/src/composables/use-workbench-settings.ts +185 -0
- package/src/composables/use-workbench-shortcuts.ts +37 -1022
- package/src/composables/use-workbench-views.ts +325 -0
- package/src/documents/components/DocumentActionMenu.vue +279 -0
- package/src/documents/components/DocumentInspector.vue +168 -0
- package/src/documents/components/DocumentPane.vue +482 -0
- package/src/documents/description-merge.ts +1 -9
- package/src/files/components/FileMetadataPanel.vue +49 -15
- package/src/i18n/locale-catalogs.ts +7 -6
- package/src/i18n/locale-registry.ts +8 -6
- package/src/i18n/locales/de-DE.json +23 -1
- package/src/i18n/locales/en-US.json +23 -1
- package/src/i18n/locales/es-ES.json +23 -1
- package/src/i18n/locales/ja-JP.json +23 -1
- package/src/i18n/locales/zh-TW.json +23 -1
- package/src/mail/components/MailAccountDialog.vue +1 -0
- package/src/mail/components/MailComposerDialog.vue +1 -0
- package/src/mail/components/MailWorkspaceView.vue +1 -0
- package/src/mail/components/SidebarMail.vue +1 -0
- package/src/objects/content-references.ts +6 -56
- package/src/objects/wiki-links.ts +1 -48
- package/src/objects/workspace-objects.ts +2 -3
- package/src/plans/calendar.ts +2 -2
- package/src/plans/components/CalendarAgendaView.vue +165 -0
- package/src/plans/components/CalendarFilterBar.vue +128 -0
- package/src/plans/components/CalendarMonthView.vue +224 -0
- package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
- package/src/plans/components/CalendarTimelineView.vue +517 -0
- package/src/plans/components/CalendarTopbarControls.vue +101 -0
- package/src/plans/components/CalendarView.vue +162 -2106
- package/src/plans/components/CalendarYearView.vue +138 -0
- package/src/plans/components/PlanConnectionsDialog.vue +1 -1
- package/src/plans/components/calendar-shared.css +192 -0
- package/src/plans/composables/use-calendar-interactions.ts +396 -0
- package/src/plans/composables/use-calendar-scroll.ts +420 -0
- package/src/plugins/components/PluginDetailPage.vue +10 -6
- package/src/plugins/components/PluginDeveloperArea.vue +192 -0
- package/src/plugins/components/PluginExplorer.vue +6 -4
- package/src/plugins/components/PluginImportDialog.vue +1 -1
- package/src/plugins/components/PluginInstaller.vue +269 -178
- package/src/plugins/components/PluginMaintenance.vue +37 -49
- package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
- package/src/plugins/components/PluginSettingsForm.vue +2 -1
- package/src/plugins/components/PluginsTabPage.vue +61 -0
- package/src/plugins/components/plugin-center.css +5 -0
- package/src/plugins/data.ts +9 -86
- package/src/plugins/editor-plugin-adapters.ts +169 -0
- package/src/plugins/plugin-data.ts +2 -3
- package/src/plugins/plugin-rpc-router.ts +558 -0
- package/src/plugins/plugin-sdk.ts +1 -260
- package/src/plugins/plugin-ui-dialogs.ts +167 -0
- package/src/plugins/queries.ts +1 -75
- package/src/plugins/view-header.ts +2 -7
- package/src/runtime.ts +3 -2
- package/src/settings/components/SettingsPanel.vue +8 -3
- package/src/settings/components/WorkbenchSettings.vue +20 -7
- package/src/settings/components/settings-context.ts +1 -1
- package/src/settings/settings-tab.ts +1 -0
- package/src/shell/command-palette.ts +3 -3
- package/src/shell/components/EditorToolbar.vue +8 -9
- package/src/shell/components/EditorTools.vue +1 -5
- package/src/shell/components/PaneTopbar.vue +393 -0
- package/src/shell/components/SelectionToolbar.vue +0 -2
- package/src/shell/components/WorkbenchContextMenus.vue +37 -26
- package/src/shell/components/WorkbenchModals.vue +22 -18
- package/src/shell/components/WorkbenchPanes.vue +358 -1512
- package/src/shell/components/WorkbenchSidebar.vue +486 -0
- package/src/shell/pane-registry.ts +69 -0
- package/src/shell/use-surface-dismissal.ts +219 -0
- package/src/shell/use-workbench-commands.ts +599 -0
- package/src/shell/use-workbench-keybindings.ts +337 -0
- package/src/shell/use-workbench.ts +488 -1081
- package/src/shell/workbench-context.ts +30 -3
- package/src/stores/workspace-document-io.ts +807 -0
- package/src/stores/workspace-file-ops.ts +1 -1
- package/src/stores/workspace-knowledge.ts +1 -1
- package/src/stores/workspace-lifecycle.ts +459 -0
- package/src/stores/workspace-plugins-state.ts +71 -599
- package/src/stores/workspace-session.ts +287 -0
- package/src/stores/workspace-tabs-layout.ts +1 -1
- package/src/stores/workspace-types.ts +50 -0
- package/src/stores/workspace.ts +163 -1345
- package/src/styles.css +0 -1
- package/src/tabs/components/DesktopTabs.vue +19 -11
- package/src/windows/AuxiliaryWindows.vue +2 -2
- package/src/windows/use-window-event-bridge.ts +152 -0
- package/src/workspace/components/TemplateLibrary.vue +1 -1
- package/src/workspace/components/WorkspaceIconPicker.vue +5 -4
- package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
- package/src/assistant/locales/de-DE.json +0 -129
- package/src/assistant/locales/en-US.json +0 -129
- package/src/assistant/locales/es-ES.json +0 -129
- package/src/assistant/locales/ja-JP.json +0 -129
- package/src/assistant/locales/zh-CN.json +0 -129
- package/src/assistant/locales/zh-TW.json +0 -129
- package/src/assistant/task-prompts.json +0 -39
package/src/stores/workspace.ts
CHANGED
|
@@ -1,85 +1,38 @@
|
|
|
1
|
-
import { computed, onScopeDispose, ref
|
|
1
|
+
import { computed, onScopeDispose, ref } from 'vue';
|
|
2
2
|
import { defineStore } from 'pinia';
|
|
3
3
|
import {
|
|
4
|
-
basename,
|
|
5
|
-
documentLayoutPath,
|
|
6
4
|
FileRegistry,
|
|
7
|
-
isDataTableFilePath,
|
|
8
|
-
isMarkdown,
|
|
9
|
-
isWorkspaceInternalPath,
|
|
10
|
-
parentPath,
|
|
11
|
-
parseDocumentLayout,
|
|
12
|
-
validatePath,
|
|
13
5
|
type DataTable,
|
|
14
6
|
type FileEntry,
|
|
15
|
-
type PluginManifest,
|
|
16
7
|
type RecentWorkspace,
|
|
17
|
-
type TableLayout,
|
|
18
8
|
type Workspace,
|
|
19
|
-
type WorkspaceLayout,
|
|
20
|
-
type WorkspaceSession,
|
|
21
9
|
} from '@tano/protocol';
|
|
22
10
|
import { createWorkspaceAssistantBridge } from '../assistant/workspace-bridge';
|
|
23
11
|
import { createDataTableController } from '../data-tables/data-table-controller';
|
|
24
|
-
import { isTableTab, tableFileId, tableTabId } from '../data-tables/data-tables';
|
|
25
|
-
import { GRAPH_TAB_ID } from '../documents/document-graph';
|
|
26
12
|
import { useDocumentIndex } from '../documents/document-index';
|
|
27
13
|
import { createDocumentSession, documentDirty as dirty, type OpenDocument } from '../documents/document-session';
|
|
28
|
-
import { indexFolderHomes } from '../files/folder-home';
|
|
29
|
-
import { recordHelpCompleted } from '../help/help-checklist';
|
|
30
|
-
import { createHelpEditQueue } from '../help/help-edit-queue';
|
|
31
14
|
import { optimisticFiles } from '../files/optimistic-files';
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
type PluginWorkbenchView,
|
|
37
|
-
} from '../plugins/workbench';
|
|
38
|
-
import { useWorkbenchRuntime, type WorkbenchViewTab } from '../runtime';
|
|
39
|
-
import { SessionJournal } from '../shell/session-journal';
|
|
40
|
-
import {
|
|
41
|
-
DocumentLayoutConflict,
|
|
42
|
-
layoutDirty,
|
|
43
|
-
loadDocumentLayout,
|
|
44
|
-
saveDocumentLayout,
|
|
45
|
-
} from '../workspace/workspace-document-layout';
|
|
15
|
+
import { createHelpEditQueue } from '../help/help-edit-queue';
|
|
16
|
+
import type { InstalledObjectPlugin } from '../plugins/workspace-plugins';
|
|
17
|
+
import { useWorkbenchRuntime } from '../runtime';
|
|
18
|
+
import { layoutDirty } from '../workspace/workspace-document-layout';
|
|
46
19
|
import { WorkspaceLifecycle } from '../workspace/workspace-lifecycle';
|
|
47
|
-
import {
|
|
48
|
-
import { readStartupWorkspace, rememberStartupWorkspace } from '../workspace/workspace-startup';
|
|
49
|
-
import { addWorkspaceWelcome, workspaceWelcomePath } from '../workspace/workspace-welcome';
|
|
20
|
+
import { createWorkspaceDocumentIO } from './workspace-document-io';
|
|
50
21
|
import { createWorkspaceFileOps } from './workspace-file-ops';
|
|
51
22
|
import { createWorkspaceKnowledge } from './workspace-knowledge';
|
|
23
|
+
import { createWorkspaceLifecycle } from './workspace-lifecycle';
|
|
52
24
|
import { createWorkspacePluginsState } from './workspace-plugins-state';
|
|
53
25
|
import { createWorkspacePolicy } from './workspace-policy';
|
|
26
|
+
import { createWorkspaceSession } from './workspace-session';
|
|
54
27
|
import { createWorkspaceTabsLayout } from './workspace-tabs-layout';
|
|
28
|
+
import type {
|
|
29
|
+
Activity,
|
|
30
|
+
DocumentTab,
|
|
31
|
+
WorkspaceLifecycleHooks,
|
|
32
|
+
WorkspaceLoadingState,
|
|
33
|
+
} from './workspace-types';
|
|
55
34
|
|
|
56
|
-
export type { OpenDocument }
|
|
57
|
-
|
|
58
|
-
export interface DocumentTab {
|
|
59
|
-
id: string;
|
|
60
|
-
path: string;
|
|
61
|
-
blank: boolean;
|
|
62
|
-
graph: boolean;
|
|
63
|
-
plugins: boolean;
|
|
64
|
-
calendar: boolean;
|
|
65
|
-
view?: WorkbenchViewTab;
|
|
66
|
-
directory?: { path: string; name: string; missing: boolean };
|
|
67
|
-
pluginView?: PluginWorkbenchView;
|
|
68
|
-
pluginDetail?: PluginManifest;
|
|
69
|
-
document?: OpenDocument;
|
|
70
|
-
attachmentPreview: boolean;
|
|
71
|
-
attachment?: FileEntry;
|
|
72
|
-
dataTable?: { name: string; dirty: boolean; icon?: string };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface Activity {
|
|
76
|
-
id: string;
|
|
77
|
-
label: string;
|
|
78
|
-
detail: string;
|
|
79
|
-
time: number;
|
|
80
|
-
kind: 'external' | 'save' | 'conflict' | 'file';
|
|
81
|
-
change?: { before: string; after: string };
|
|
82
|
-
}
|
|
35
|
+
export type { Activity, DocumentTab, OpenDocument };
|
|
83
36
|
|
|
84
37
|
export const useWorkspaceStore = defineStore('workspace', () => {
|
|
85
38
|
const helpEdits = createHelpEditQueue();
|
|
@@ -96,20 +49,14 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
96
49
|
const documents = ref<OpenDocument[]>([]);
|
|
97
50
|
const documentIndex = useDocumentIndex(documents);
|
|
98
51
|
const tabIds = ref<string[]>([]);
|
|
99
|
-
// Most tabs use the file/page id directly. A context-menu "open in new tab"
|
|
100
|
-
// request can target an already open file, though, so those additional tab
|
|
101
|
-
// instances need an id of their own while continuing to share the open
|
|
102
|
-
// document and its draft.
|
|
103
52
|
const tabAliases = ref(new Map<string, string>());
|
|
104
53
|
const activeId = ref('');
|
|
105
54
|
const installedPlugins = ref<InstalledObjectPlugin[]>([]);
|
|
106
55
|
const activePluginSidebar = ref('');
|
|
107
56
|
|
|
108
57
|
const busy = ref(false);
|
|
109
|
-
// Folder selection keeps the current page visible. Presentation switches only
|
|
110
|
-
// once a target is confirmed, retaining the old session for flush/recovery.
|
|
111
58
|
const openingWorkspace = ref(false);
|
|
112
|
-
const workspaceLoading = ref({
|
|
59
|
+
const workspaceLoading = ref<WorkspaceLoadingState>({
|
|
113
60
|
files: false,
|
|
114
61
|
session: false,
|
|
115
62
|
settings: false,
|
|
@@ -127,16 +74,9 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
127
74
|
const recent = ref<RecentWorkspace[]>([]);
|
|
128
75
|
const sessionError = ref('');
|
|
129
76
|
|
|
130
|
-
let saveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
131
77
|
let chain: Promise<unknown> = Promise.resolve();
|
|
132
78
|
let disposed = false;
|
|
133
|
-
|
|
134
|
-
let sessionBlocked = false;
|
|
135
|
-
let beforeSwitch: (() => Promise<void>) | undefined;
|
|
136
|
-
let beforeWorkspaceChange: (() => Promise<void>) | undefined;
|
|
137
|
-
let afterSwitch: (() => Promise<void>) | undefined;
|
|
138
|
-
let beforeCloseDocument: ((id: string) => Promise<void>) | undefined;
|
|
139
|
-
let fileOpenRevision = 0;
|
|
79
|
+
const hooks: WorkspaceLifecycleHooks = {};
|
|
140
80
|
|
|
141
81
|
function serial<T>(task: () => Promise<T>): Promise<T> {
|
|
142
82
|
const next = chain.then(task, task);
|
|
@@ -150,7 +90,6 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
150
90
|
kind: Activity['kind'],
|
|
151
91
|
change?: Activity['change'],
|
|
152
92
|
) {
|
|
153
|
-
// Session history is bounded; larger versions remain in files/server history.
|
|
154
93
|
const preview =
|
|
155
94
|
change && change.before.length + change.after.length <= 256 * 1024 ? change : undefined;
|
|
156
95
|
activities.value.unshift({
|
|
@@ -173,7 +112,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
173
112
|
}
|
|
174
113
|
|
|
175
114
|
async function loadWorkspacePart(
|
|
176
|
-
part: keyof
|
|
115
|
+
part: keyof WorkspaceLoadingState,
|
|
177
116
|
load: () => Promise<unknown>,
|
|
178
117
|
) {
|
|
179
118
|
try {
|
|
@@ -208,7 +147,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
208
147
|
const workspaceLifecycle = new WorkspaceLifecycle(
|
|
209
148
|
{
|
|
210
149
|
watch: (changed) => adapter.watch(changed),
|
|
211
|
-
refresh,
|
|
150
|
+
refresh: () => lifecycle.refresh(),
|
|
212
151
|
report,
|
|
213
152
|
available: () => !!workspace.value && !disposed,
|
|
214
153
|
},
|
|
@@ -226,7 +165,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
226
165
|
}
|
|
227
166
|
if (!isDemo && !isWeb && !mobile && typeof window !== 'undefined') {
|
|
228
167
|
const refreshRecentOnFocus = () => {
|
|
229
|
-
void refreshWorkspaces();
|
|
168
|
+
void lifecycle.refreshWorkspaces();
|
|
230
169
|
};
|
|
231
170
|
window.addEventListener('focus', refreshRecentOnFocus);
|
|
232
171
|
onScopeDispose(() => window.removeEventListener('focus', refreshRecentOnFocus));
|
|
@@ -237,8 +176,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
237
176
|
layoutDirty(doc.tableLayout) &&
|
|
238
177
|
doc.tableLayout.conflict?.draft !== JSON.stringify(doc.tableLayout.file);
|
|
239
178
|
|
|
240
|
-
// Domain modules composed
|
|
241
|
-
// 1. Policy (workspace settings & capability rules)
|
|
179
|
+
// Domain modules composed in acyclic order:
|
|
242
180
|
const policy = createWorkspacePolicy({
|
|
243
181
|
adapter,
|
|
244
182
|
workspace,
|
|
@@ -248,7 +186,6 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
248
186
|
report,
|
|
249
187
|
});
|
|
250
188
|
|
|
251
|
-
// 2. Knowledge (objects, relations, metadata, templates, repeats, references)
|
|
252
189
|
const knowledge = createWorkspaceKnowledge({
|
|
253
190
|
adapter,
|
|
254
191
|
workspace,
|
|
@@ -265,7 +202,6 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
265
202
|
disposePluginExecutor: () => plugins.pluginExecutor.dispose(),
|
|
266
203
|
});
|
|
267
204
|
|
|
268
|
-
// 3. Plugins state (plugin runtime, host/executor/developer, pluginCall, OAuth/connections/packages)
|
|
269
205
|
const plugins = createWorkspacePluginsState({
|
|
270
206
|
adapter,
|
|
271
207
|
runtime,
|
|
@@ -288,13 +224,12 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
288
224
|
writable,
|
|
289
225
|
scheduleRefresh,
|
|
290
226
|
refreshObjects: knowledge.refreshObjects,
|
|
291
|
-
openInternal: (file, replaceId, current) => openInternal(file, replaceId, current),
|
|
227
|
+
openInternal: (file, replaceId, current) => docIO.openInternal(file, replaceId, current),
|
|
292
228
|
saveInternal: (doc) => saveInternal(doc),
|
|
293
229
|
ensureTabNavigation: (tabId, targetId) => tabsLayout.ensureTabNavigation(tabId, targetId),
|
|
294
230
|
touchNavigation: () => tabsLayout.touchNavigation(),
|
|
295
231
|
});
|
|
296
232
|
|
|
297
|
-
// 4. Tabs, split/multi-window layouts & tab navigation history
|
|
298
233
|
const tabsLayout = createWorkspaceTabsLayout({
|
|
299
234
|
workspace,
|
|
300
235
|
fileRegistry,
|
|
@@ -312,14 +247,13 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
312
247
|
busy,
|
|
313
248
|
displayPath,
|
|
314
249
|
layoutPending,
|
|
315
|
-
flush,
|
|
316
|
-
close,
|
|
317
|
-
openAttachment,
|
|
318
|
-
openPageTab,
|
|
319
|
-
openFile,
|
|
250
|
+
flush: () => docIO.flush(),
|
|
251
|
+
close: (id) => docIO.close(id),
|
|
252
|
+
openAttachment: (file, options) => docIO.openAttachment(file, options),
|
|
253
|
+
openPageTab: (id, options) => docIO.openPageTab(id, options),
|
|
254
|
+
openFile: (file, options) => docIO.openFile(file, options),
|
|
320
255
|
});
|
|
321
256
|
|
|
322
|
-
// 5. Assistant bridge & document suggestions
|
|
323
257
|
const assistantBridge = createWorkspaceAssistantBridge({
|
|
324
258
|
adapter,
|
|
325
259
|
workspace,
|
|
@@ -349,7 +283,6 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
349
283
|
activity,
|
|
350
284
|
});
|
|
351
285
|
|
|
352
|
-
// 6. Document session reconciliation/save
|
|
353
286
|
const { reconcile, save: saveInternal } = createDocumentSession({
|
|
354
287
|
adapter,
|
|
355
288
|
confirmCreation: (doc) => fileOps.confirmCreation(doc),
|
|
@@ -363,7 +296,6 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
363
296
|
},
|
|
364
297
|
});
|
|
365
298
|
|
|
366
|
-
// 7. File & folder mutation operations
|
|
367
299
|
const fileOps = createWorkspaceFileOps({
|
|
368
300
|
adapter,
|
|
369
301
|
mobile,
|
|
@@ -395,49 +327,108 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
395
327
|
writable,
|
|
396
328
|
report,
|
|
397
329
|
activity,
|
|
398
|
-
flush,
|
|
399
|
-
flushDocuments,
|
|
400
|
-
openInternal,
|
|
330
|
+
flush: () => docIO.flush(),
|
|
331
|
+
flushDocuments: () => docIO.flushDocuments(),
|
|
332
|
+
openInternal: (file, replaceId, current) => docIO.openInternal(file, replaceId, current),
|
|
401
333
|
reconcile,
|
|
402
|
-
hydrateDocumentLayout,
|
|
334
|
+
hydrateDocumentLayout: (doc) => docIO.hydrateDocumentLayout(doc),
|
|
403
335
|
});
|
|
404
336
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
337
|
+
const session = createWorkspaceSession({
|
|
338
|
+
adapter,
|
|
339
|
+
workspace,
|
|
340
|
+
fileRegistry,
|
|
341
|
+
documents,
|
|
342
|
+
documentIndex,
|
|
343
|
+
dataTables,
|
|
344
|
+
tabsLayout,
|
|
345
|
+
tabIds,
|
|
346
|
+
tabAliases,
|
|
347
|
+
activeId,
|
|
348
|
+
workspaceLoading,
|
|
349
|
+
restoringDocuments,
|
|
350
|
+
sessionError,
|
|
351
|
+
dataTableFileId: (id) => docIO.dataTableFileId(id),
|
|
352
|
+
loadWorkspacePart,
|
|
353
|
+
readOpenDocument: (file) => docIO.readOpenDocument(file),
|
|
354
|
+
openInternal: (file, replaceId, current) => docIO.openInternal(file, replaceId, current),
|
|
355
|
+
hydrateDocumentLayout: (doc) => docIO.hydrateDocumentLayout(doc),
|
|
356
|
+
reconcile,
|
|
357
|
+
saveInternal,
|
|
358
|
+
activity,
|
|
359
|
+
report,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
const docIO = createWorkspaceDocumentIO({
|
|
363
|
+
adapter,
|
|
364
|
+
workspace,
|
|
365
|
+
fileRegistry,
|
|
366
|
+
fileMutations,
|
|
367
|
+
documents,
|
|
368
|
+
documentIndex,
|
|
369
|
+
dataTables,
|
|
370
|
+
workspaceSettings: policy.workspaceSettings,
|
|
371
|
+
referenceTargets: knowledge.referenceTargets,
|
|
372
|
+
tabIds,
|
|
373
|
+
activeId,
|
|
374
|
+
busy,
|
|
375
|
+
openingDocuments,
|
|
376
|
+
plugins,
|
|
377
|
+
tabsLayout,
|
|
378
|
+
assistantBridge,
|
|
379
|
+
fileOps,
|
|
380
|
+
helpEdits,
|
|
381
|
+
journal: session.journal,
|
|
382
|
+
hooks,
|
|
383
|
+
isDisposed: () => disposed,
|
|
384
|
+
layoutPending,
|
|
385
|
+
serial,
|
|
386
|
+
saveInternal,
|
|
387
|
+
report,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const lifecycle = createWorkspaceLifecycle({
|
|
391
|
+
adapter,
|
|
392
|
+
isDemo,
|
|
393
|
+
isWeb,
|
|
394
|
+
remembersStartupWorkspace,
|
|
395
|
+
workspace,
|
|
396
|
+
fileRegistry,
|
|
397
|
+
documents,
|
|
398
|
+
tabIds,
|
|
399
|
+
tabAliases,
|
|
400
|
+
activeId,
|
|
401
|
+
installedPlugins,
|
|
402
|
+
busy,
|
|
403
|
+
openingWorkspace,
|
|
404
|
+
workspaceLoading,
|
|
405
|
+
restoringDocuments,
|
|
406
|
+
openingDocuments,
|
|
407
|
+
activities,
|
|
408
|
+
fatal,
|
|
409
|
+
recent,
|
|
410
|
+
sessionError,
|
|
411
|
+
workspaceLifecycle,
|
|
412
|
+
stopWatching,
|
|
413
|
+
dataTables,
|
|
414
|
+
policy,
|
|
415
|
+
knowledge,
|
|
416
|
+
plugins,
|
|
417
|
+
tabsLayout,
|
|
418
|
+
assistantBridge,
|
|
419
|
+
session,
|
|
420
|
+
hooks,
|
|
421
|
+
serial,
|
|
422
|
+
activity,
|
|
423
|
+
report,
|
|
424
|
+
loadWorkspacePart,
|
|
425
|
+
flush: docIO.flush,
|
|
426
|
+
reconcile,
|
|
427
|
+
saveInternal,
|
|
428
|
+
hydrateDocumentLayout: docIO.hydrateDocumentLayout,
|
|
429
|
+
saveTableLayout: docIO.saveTableLayout,
|
|
430
|
+
});
|
|
439
431
|
|
|
440
|
-
// Session journal & pending state
|
|
441
432
|
const pending = computed(
|
|
442
433
|
() =>
|
|
443
434
|
fileMutations.pending.value ||
|
|
@@ -445,1186 +436,14 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
445
436
|
!!assistantBridge.suggestionPersistence.value?.pending() ||
|
|
446
437
|
documents.value.some((d) => (dirty(d) || layoutPending(d)) && !d.conflict),
|
|
447
438
|
);
|
|
448
|
-
const journal = new SessionJournal(
|
|
449
|
-
(id, session) => adapter.saveSession!(id, session),
|
|
450
|
-
(error) => {
|
|
451
|
-
sessionError.value =
|
|
452
|
-
error === undefined
|
|
453
|
-
? ''
|
|
454
|
-
: `恢复草稿未写入:${String(error)}。文档仍会尝试正常保存。`;
|
|
455
|
-
},
|
|
456
|
-
);
|
|
457
|
-
// Track only recoverable fields. Saving/error flags, undo stacks and plugin
|
|
458
|
-
// state must not traverse/rewrite every open document on the input path.
|
|
459
|
-
const recoveryDocuments = new WeakMap<
|
|
460
|
-
OpenDocument,
|
|
461
|
-
ComputedRef<WorkspaceSession['documents'][number]>
|
|
462
|
-
>();
|
|
463
|
-
const mainTabIds = computed(() => layoutPanes(tabsLayout.layout.value).flatMap((pane) => pane.tabs));
|
|
464
|
-
const sessionDocuments = computed(() =>
|
|
465
|
-
documents.value
|
|
466
|
-
.filter((doc) => mainTabIds.value.some((id) => tabsLayout.tabTarget(id) === doc.id))
|
|
467
|
-
.map((doc) => {
|
|
468
|
-
let snapshot = recoveryDocuments.get(doc);
|
|
469
|
-
if (!snapshot) {
|
|
470
|
-
snapshot = computed(() => ({
|
|
471
|
-
id: doc.id,
|
|
472
|
-
path: doc.path,
|
|
473
|
-
...(dirty(doc) ? { draft: { content: doc.content, base: { ...doc.base } } } : {}),
|
|
474
|
-
}));
|
|
475
|
-
recoveryDocuments.set(doc, snapshot);
|
|
476
|
-
}
|
|
477
|
-
return snapshot.value;
|
|
478
|
-
}),
|
|
479
|
-
);
|
|
480
|
-
const sessionTables = computed(() =>
|
|
481
|
-
dataTables
|
|
482
|
-
.drafts()
|
|
483
|
-
.filter((draft) =>
|
|
484
|
-
mainTabIds.value.some(
|
|
485
|
-
(id) => tableFileId(tabsLayout.tabTarget(id)) === (draft.fileId ?? draft.id),
|
|
486
|
-
),
|
|
487
|
-
),
|
|
488
|
-
);
|
|
489
|
-
const sessionLayout = computed(
|
|
490
|
-
() => JSON.parse(JSON.stringify(tabsLayout.layout.value)) as WorkspaceLayout,
|
|
491
|
-
);
|
|
492
|
-
const sessionPayload = computed<WorkspaceSession>(() => ({
|
|
493
|
-
version: 1,
|
|
494
|
-
activeId:
|
|
495
|
-
layoutPanes(tabsLayout.layout.value).find(
|
|
496
|
-
(pane) => pane.id === tabsLayout.windowLayouts.value.main.activePaneId,
|
|
497
|
-
)?.activeId ?? '',
|
|
498
|
-
tabs: [...new Set(mainTabIds.value.map(tabsLayout.tabTarget))],
|
|
499
|
-
layout: sessionLayout.value,
|
|
500
|
-
dataTables: sessionTables.value,
|
|
501
|
-
documents: sessionDocuments.value,
|
|
502
|
-
}));
|
|
503
|
-
function queueSession() {
|
|
504
|
-
if (!sessionReady || sessionBlocked || !workspace.value || !adapter.saveSession) return;
|
|
505
|
-
journal.enqueue(workspace.value.id, sessionPayload.value);
|
|
506
|
-
}
|
|
507
|
-
const stopSessionWatch = watch(sessionPayload, queueSession, {
|
|
508
|
-
flush: 'sync',
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
// Workspace initialization, open, exit & session restoration
|
|
512
|
-
async function initialize(requestedWorkspace?: string) {
|
|
513
|
-
if (isDemo || isWeb) {
|
|
514
|
-
await openWorkspace(requestedWorkspace);
|
|
515
|
-
if (!workspace.value && requestedWorkspace) await openWorkspace();
|
|
516
|
-
if (isWeb) await refreshWorkspaces();
|
|
517
|
-
} else if (requestedWorkspace) {
|
|
518
|
-
await openWorkspace(requestedWorkspace);
|
|
519
|
-
} else if (adapter.recent && (await refreshWorkspaces())) {
|
|
520
|
-
const savedId = readStartupWorkspace();
|
|
521
|
-
const previous =
|
|
522
|
-
savedId === undefined
|
|
523
|
-
? recent.value.reduce<RecentWorkspace | undefined>(
|
|
524
|
-
(latest, item) => (!latest || item.openedAt > latest.openedAt ? item : latest),
|
|
525
|
-
undefined,
|
|
526
|
-
)
|
|
527
|
-
: recent.value.find((item) => item.id === savedId);
|
|
528
|
-
if (previous) await openWorkspace(previous.path);
|
|
529
|
-
else if (savedId) rememberStartupWorkspace(null);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
async function refreshWorkspaces() {
|
|
534
|
-
if (!adapter.recent) return false;
|
|
535
|
-
try {
|
|
536
|
-
recent.value = policy.decorateRecent(await adapter.recent());
|
|
537
|
-
return true;
|
|
538
|
-
} catch (error) {
|
|
539
|
-
report(error);
|
|
540
|
-
return false;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
async function openWorkspace(path?: string, newName?: string) {
|
|
545
|
-
if (busy.value) return;
|
|
546
|
-
busy.value = true;
|
|
547
|
-
let switching = false;
|
|
548
|
-
let pendingWorkspaceLoads: Promise<unknown>[] = [];
|
|
549
|
-
try {
|
|
550
|
-
if (path === undefined && newName === undefined && adapter.selectWorkspacePath) {
|
|
551
|
-
const selected = await adapter.selectWorkspacePath();
|
|
552
|
-
if (selected === null) return;
|
|
553
|
-
path = selected;
|
|
554
|
-
}
|
|
555
|
-
openingWorkspace.value = true;
|
|
556
|
-
for (const part of Object.keys(
|
|
557
|
-
workspaceLoading.value,
|
|
558
|
-
) as (keyof typeof workspaceLoading.value)[])
|
|
559
|
-
workspaceLoading.value[part] = true;
|
|
560
|
-
switching = true;
|
|
561
|
-
// Cancel queued old-workspace refreshes before flushing. Keep the watcher
|
|
562
|
-
// so failure can replay changes without losing external edits.
|
|
563
|
-
workspaceLifecycle.pause();
|
|
564
|
-
if (!(await flush())) {
|
|
565
|
-
report('还有未保存的修改。请先处理保存错误,再切换工作空间。');
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
await beforeSwitch?.();
|
|
569
|
-
await beforeWorkspaceChange?.();
|
|
570
|
-
await serial(async () => {
|
|
571
|
-
const previousReady = sessionReady;
|
|
572
|
-
sessionReady = false;
|
|
573
|
-
let next: Workspace | null;
|
|
574
|
-
try {
|
|
575
|
-
if (newName !== undefined && !adapter.createWorkspace)
|
|
576
|
-
throw new Error('此平台不能直接创建工作空间');
|
|
577
|
-
next =
|
|
578
|
-
newName === undefined
|
|
579
|
-
? await adapter.open(path)
|
|
580
|
-
: await adapter.createWorkspace!(newName);
|
|
581
|
-
} catch (error) {
|
|
582
|
-
sessionReady = previousReady;
|
|
583
|
-
throw error;
|
|
584
|
-
}
|
|
585
|
-
if (!next) {
|
|
586
|
-
sessionReady = previousReady;
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
const accountTabs = tabIds.value.filter(
|
|
590
|
-
(id) => tabsLayout.views.value.get(id)?.scope === 'account',
|
|
591
|
-
);
|
|
592
|
-
const accountActive = accountTabs.includes(activeId.value) ? activeId.value : undefined;
|
|
593
|
-
stopWatching();
|
|
594
|
-
plugins.pluginExecutor.dispose();
|
|
595
|
-
fatal.value = '';
|
|
596
|
-
if (next.reinitialized) {
|
|
597
|
-
report('.tano 已删除,工作区已重新初始化。旧对象已丢失,文档和附件保留。');
|
|
598
|
-
}
|
|
599
|
-
if (newName !== undefined || next.newlyCreated) {
|
|
600
|
-
try {
|
|
601
|
-
next = await addWorkspaceWelcome(adapter, next);
|
|
602
|
-
} catch (error) {
|
|
603
|
-
report(`工作区已创建,但入门文档未能添加:${String(error)}。可以继续新建文档。`);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
policy.resetPolicy(false);
|
|
607
|
-
workspace.value = next;
|
|
608
|
-
// The new file tree can render immediately; old documents must not
|
|
609
|
-
// appear under it while this workspace's metadata/session is loading.
|
|
610
|
-
documents.value = [];
|
|
611
|
-
tabIds.value = [];
|
|
612
|
-
activeId.value = '';
|
|
613
|
-
openingDocuments.value = {};
|
|
614
|
-
restoringDocuments.value = {};
|
|
615
|
-
tabsLayout.resetTabNavigation();
|
|
616
|
-
if (remembersStartupWorkspace) rememberStartupWorkspace(next.id);
|
|
617
|
-
knowledge.resetKnowledge(false);
|
|
618
|
-
dataTables.reset();
|
|
619
|
-
installedPlugins.value = [];
|
|
620
|
-
workspaceLoading.value.files = false;
|
|
621
|
-
// Publish the tree now. Session and document reads do not depend on
|
|
622
|
-
// plugin installation, object indexes, rules, or unrelated tables.
|
|
623
|
-
const settingsReady = loadWorkspacePart('settings', policy.refreshWorkspaceSettings);
|
|
624
|
-
const tablesReady = loadWorkspacePart('tables', () => dataTables.reload());
|
|
625
|
-
const objectsReady = knowledge.refreshObjects().catch(report);
|
|
626
|
-
const capabilitiesReady = loadWorkspacePart('capabilities', policy.refreshCapabilities);
|
|
627
|
-
pendingWorkspaceLoads = [settingsReady, tablesReady, objectsReady, capabilitiesReady];
|
|
628
|
-
assistantBridge.resetForWorkspaceChange();
|
|
629
|
-
activities.value = [];
|
|
630
|
-
sessionError.value = '';
|
|
631
|
-
sessionBlocked = false;
|
|
632
|
-
const watcherReady = workspaceLifecycle.start().catch(report);
|
|
633
|
-
pendingWorkspaceLoads.push(watcherReady);
|
|
634
|
-
let saved: WorkspaceSession | null = null;
|
|
635
|
-
if (adapter.loadSession) {
|
|
636
|
-
try {
|
|
637
|
-
saved = await adapter.loadSession(next.id);
|
|
638
|
-
} catch (error) {
|
|
639
|
-
sessionBlocked = true;
|
|
640
|
-
sessionError.value = `${String(error)}。本次不覆盖恢复记录。`;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
if (saved) await restoreSession(saved, tablesReady, objectsReady);
|
|
644
|
-
else await settingsReady; // Only the default page depends on settings.
|
|
645
|
-
const first =
|
|
646
|
-
next.files.find(
|
|
647
|
-
(f) =>
|
|
648
|
-
f.id === policy.workspaceSettings.value.homePageId &&
|
|
649
|
-
f.kind === 'file' &&
|
|
650
|
-
isMarkdown(f.path),
|
|
651
|
-
) ??
|
|
652
|
-
next.files.find((f) => f.path === workspaceWelcomePath) ??
|
|
653
|
-
next.files.find((f) => /^readme\.md$/i.test(f.path)) ??
|
|
654
|
-
next.files.find(
|
|
655
|
-
(f) => f.kind === 'file' && isMarkdown(f.path) && !isWorkspaceInternalPath(f.path),
|
|
656
|
-
);
|
|
657
|
-
if (!saved && first) {
|
|
658
|
-
try {
|
|
659
|
-
await openInitialDocument(first);
|
|
660
|
-
tabsLayout.ensureTabNavigation(activeId.value, activeId.value);
|
|
661
|
-
tabsLayout.touchNavigation();
|
|
662
|
-
} catch (error) {
|
|
663
|
-
report(error);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
workspaceLoading.value.session = false;
|
|
667
|
-
{
|
|
668
|
-
for (const id of accountTabs) {
|
|
669
|
-
if (!tabIds.value.includes(id)) tabIds.value.push(id);
|
|
670
|
-
tabsLayout.ensureTabNavigation(id);
|
|
671
|
-
}
|
|
672
|
-
if (accountActive) activeId.value = accountActive;
|
|
673
|
-
tabsLayout.touchNavigation();
|
|
674
|
-
}
|
|
675
|
-
// These completions protect persistence and adapter ownership, but each
|
|
676
|
-
// component has already revealed its own ready data independently.
|
|
677
|
-
await Promise.all([
|
|
678
|
-
settingsReady,
|
|
679
|
-
tablesReady,
|
|
680
|
-
objectsReady,
|
|
681
|
-
capabilitiesReady,
|
|
682
|
-
watcherReady,
|
|
683
|
-
]);
|
|
684
|
-
sessionReady = true;
|
|
685
|
-
queueSession();
|
|
686
|
-
if (adapter.recent) recent.value = policy.decorateRecentNames(await adapter.recent());
|
|
687
|
-
activity(isDemo ? '演示工作空间已就绪' : '工作空间已打开', next.name, 'file');
|
|
688
|
-
});
|
|
689
|
-
} catch (error) {
|
|
690
|
-
if (path && recent.value.some((item) => item.path === path)) {
|
|
691
|
-
await refreshWorkspaces();
|
|
692
|
-
if (!recent.value.some((item) => item.path === path)) {
|
|
693
|
-
fatal.value = '';
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
report(error);
|
|
698
|
-
} finally {
|
|
699
|
-
await Promise.allSettled(pendingWorkspaceLoads);
|
|
700
|
-
openingWorkspace.value = false;
|
|
701
|
-
for (const part of Object.keys(
|
|
702
|
-
workspaceLoading.value,
|
|
703
|
-
) as (keyof typeof workspaceLoading.value)[])
|
|
704
|
-
workspaceLoading.value[part] = false;
|
|
705
|
-
busy.value = false;
|
|
706
|
-
if (switching) {
|
|
707
|
-
workspaceLifecycle.resume();
|
|
708
|
-
try {
|
|
709
|
-
await afterSwitch?.();
|
|
710
|
-
} catch (error) {
|
|
711
|
-
report(error);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
function createWorkspace(name?: string) {
|
|
718
|
-
if (name === undefined) {
|
|
719
|
-
const spaces = [...recent.value, ...(workspace.value ? [workspace.value] : [])];
|
|
720
|
-
// Local display names can change independently of their backing folder names.
|
|
721
|
-
const occupied = new Set(
|
|
722
|
-
spaces.flatMap((space) => [space.name, basename(space.path.replace(/\\/g, '/'))]),
|
|
723
|
-
);
|
|
724
|
-
name = '新工作区';
|
|
725
|
-
for (let suffix = 2; occupied.has(name); suffix++) name = `新工作区 ${suffix}`;
|
|
726
|
-
}
|
|
727
|
-
return openWorkspace(undefined, name);
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
function leaveWorkspace(): Promise<boolean> {
|
|
731
|
-
return exitWorkspace();
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
function deleteWorkspace(workspaceId: string): Promise<boolean> {
|
|
735
|
-
return exitWorkspace(workspaceId);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
async function exitWorkspace(deleteId?: string): Promise<boolean> {
|
|
739
|
-
if (busy.value || !workspace.value) return false;
|
|
740
|
-
busy.value = true;
|
|
741
|
-
try {
|
|
742
|
-
const assertDeletion = () => {
|
|
743
|
-
if (deleteId === undefined) return;
|
|
744
|
-
if (workspace.value?.id !== deleteId) throw new Error('工作区已切换,请重新确认删除');
|
|
745
|
-
if (!adapter.deleteWorkspace || !workspace.value.canDelete)
|
|
746
|
-
throw new Error(
|
|
747
|
-
isWeb ? '仅工作区所有者可以删除工作区' : '此平台暂不支持删除本地工作区注册',
|
|
748
|
-
);
|
|
749
|
-
};
|
|
750
|
-
assertDeletion();
|
|
751
|
-
if (!(await flush())) {
|
|
752
|
-
report(
|
|
753
|
-
`还有未保存的修改。请先处理保存错误,再${deleteId === undefined ? '退出' : '删除'}工作区。`,
|
|
754
|
-
);
|
|
755
|
-
return false;
|
|
756
|
-
}
|
|
757
|
-
await beforeSwitch?.();
|
|
758
|
-
await beforeWorkspaceChange?.();
|
|
759
|
-
await serial(async () => {
|
|
760
|
-
assertDeletion();
|
|
761
|
-
const current = workspace.value;
|
|
762
|
-
if (!current) return;
|
|
763
|
-
queueSession();
|
|
764
|
-
await journal.flush();
|
|
765
|
-
if (deleteId !== undefined) await adapter.deleteWorkspace!(deleteId);
|
|
766
|
-
else await adapter.close?.(current.id);
|
|
767
|
-
if (remembersStartupWorkspace) rememberStartupWorkspace(null);
|
|
768
|
-
sessionReady = false;
|
|
769
|
-
stopWatching();
|
|
770
|
-
plugins.pluginHost.dispose();
|
|
771
|
-
plugins.pluginExecutor.dispose();
|
|
772
|
-
workspace.value = null;
|
|
773
|
-
dataTables.reset();
|
|
774
|
-
policy.resetPolicy(true);
|
|
775
|
-
assistantBridge.resetForWorkspaceChange();
|
|
776
|
-
documents.value = [];
|
|
777
|
-
tabIds.value = [];
|
|
778
|
-
tabAliases.value = new Map();
|
|
779
|
-
activeId.value = '';
|
|
780
|
-
tabsLayout.resetTabNavigation();
|
|
781
|
-
knowledge.resetKnowledge(true);
|
|
782
|
-
installedPlugins.value = [];
|
|
783
|
-
plugins.pluginError.value = '';
|
|
784
|
-
activities.value = [];
|
|
785
|
-
sessionError.value = '';
|
|
786
|
-
sessionBlocked = false;
|
|
787
|
-
fatal.value = '';
|
|
788
|
-
if (deleteId !== undefined) {
|
|
789
|
-
policy.forgetWorkspaceName(deleteId);
|
|
790
|
-
recent.value = recent.value.filter((item) => item.id !== deleteId);
|
|
791
|
-
knowledge.referenceDocumentCache.clear();
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
await refreshWorkspaces();
|
|
795
|
-
return true;
|
|
796
|
-
} catch (error) {
|
|
797
|
-
report(error);
|
|
798
|
-
return false;
|
|
799
|
-
} finally {
|
|
800
|
-
busy.value = false;
|
|
801
|
-
try {
|
|
802
|
-
await afterSwitch?.();
|
|
803
|
-
} catch (error) {
|
|
804
|
-
report(error);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
async function openInitialDocument(file: FileEntry) {
|
|
810
|
-
restoringDocuments.value = { ...restoringDocuments.value, [file.id]: file.path };
|
|
811
|
-
tabIds.value = [file.id];
|
|
812
|
-
activeId.value = file.id;
|
|
813
|
-
workspaceLoading.value.session = false;
|
|
814
|
-
try {
|
|
815
|
-
await openInternal(file);
|
|
816
|
-
} finally {
|
|
817
|
-
delete restoringDocuments.value[file.id];
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
async function restoreSession(
|
|
822
|
-
saved: WorkspaceSession,
|
|
823
|
-
tablesReady: Promise<void>,
|
|
824
|
-
objectsReady: Promise<void>,
|
|
825
|
-
) {
|
|
826
|
-
tabAliases.value = new Map();
|
|
827
|
-
const remapped = new Map<string, string>();
|
|
828
|
-
const pendingDocs = saved.documents.flatMap((tab) => {
|
|
829
|
-
const file = fileRegistry.value?.get(tab.id) ?? fileRegistry.value?.at(tab.path);
|
|
830
|
-
if (!file && !tab.draft) return [];
|
|
831
|
-
const id = file?.id ?? tab.id;
|
|
832
|
-
remapped.set(tab.id, id);
|
|
833
|
-
return [{ tab, file, id }];
|
|
834
|
-
});
|
|
835
|
-
restoringDocuments.value = Object.fromEntries(
|
|
836
|
-
pendingDocs.map(({ tab, file, id }) => [id, file?.path ?? tab.path]),
|
|
837
|
-
);
|
|
838
|
-
const planned = new Set(pendingDocs.map(({ id }) => id));
|
|
839
|
-
const requested = (saved.tabs ?? []).map((id) => remapped.get(id) ?? id);
|
|
840
|
-
tabIds.value = [
|
|
841
|
-
...new Set([
|
|
842
|
-
...requested.filter(
|
|
843
|
-
(id) =>
|
|
844
|
-
planned.has(id) ||
|
|
845
|
-
tabsLayout.isUtilityTab(id) ||
|
|
846
|
-
id.startsWith('plugin:'),
|
|
847
|
-
),
|
|
848
|
-
...planned,
|
|
849
|
-
]),
|
|
850
|
-
];
|
|
851
|
-
const restoredActive = remapped.get(saved.activeId) ?? saved.activeId;
|
|
852
|
-
tabsLayout.layout.value = restoreLayout(saved.layout, tabIds.value, remapped);
|
|
853
|
-
tabsLayout.activePaneId.value =
|
|
854
|
-
tabsLayout.panes.value.find((pane) => pane.tabs.includes(restoredActive))?.id ??
|
|
855
|
-
tabsLayout.panes.value[0].id;
|
|
856
|
-
activeId.value = tabIds.value.includes(restoredActive)
|
|
857
|
-
? restoredActive
|
|
858
|
-
: (tabIds.value[0] ?? '');
|
|
859
|
-
workspaceLoading.value.session = false;
|
|
860
|
-
// Visible documents get the first read slots. Background tabs cannot hold
|
|
861
|
-
// up either their labels or another pane whose document has already arrived.
|
|
862
|
-
const visible = new Set(tabsLayout.panes.value.map((pane) => pane.activeId));
|
|
863
|
-
const tableRecovery = (async () => {
|
|
864
|
-
await tablesReady;
|
|
865
|
-
if (saved.dataTables?.length) {
|
|
866
|
-
workspaceLoading.value.tables = true;
|
|
867
|
-
await loadWorkspacePart('tables', () => dataTables.restore(saved.dataTables!));
|
|
868
|
-
}
|
|
869
|
-
})();
|
|
870
|
-
const restoreDocument = async ({ tab, file, id }: (typeof pendingDocs)[number]) => {
|
|
871
|
-
try {
|
|
872
|
-
if (!tab.draft) {
|
|
873
|
-
if (file) {
|
|
874
|
-
const doc = await readOpenDocument(file);
|
|
875
|
-
if (!documentIndex.byId.value.has(id)) documents.value.push(doc);
|
|
876
|
-
}
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
const doc: OpenDocument = {
|
|
880
|
-
id: file?.id ?? tab.id,
|
|
881
|
-
path: file?.path ?? tab.path,
|
|
882
|
-
content: tab.draft.content,
|
|
883
|
-
base: tab.draft.base,
|
|
884
|
-
saving: false,
|
|
885
|
-
creating: file?.pendingCreation,
|
|
886
|
-
missing: !file,
|
|
887
|
-
};
|
|
888
|
-
if (!doc.creating) await hydrateDocumentLayout(doc);
|
|
889
|
-
documents.value.push(doc);
|
|
890
|
-
activity('已恢复未保存草稿', doc.path, 'file');
|
|
891
|
-
if (file) {
|
|
892
|
-
try {
|
|
893
|
-
if (!doc.creating) await reconcile(doc, await adapter.read(file.path));
|
|
894
|
-
await saveInternal(documentIndex.byId.value.get(doc.id)!);
|
|
895
|
-
} catch (error) {
|
|
896
|
-
doc.error = String(error);
|
|
897
|
-
report(error);
|
|
898
|
-
}
|
|
899
|
-
} else doc.error = '原文件已不存在,恢复草稿已保留,请另存副本';
|
|
900
|
-
} catch (error) {
|
|
901
|
-
report(error);
|
|
902
|
-
} finally {
|
|
903
|
-
delete restoringDocuments.value[id];
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
const priority = (id: string) => (id === restoredActive ? 2 : Number(visible.has(id)));
|
|
907
|
-
const queue = [...pendingDocs].sort((a, b) => priority(b.id) - priority(a.id));
|
|
908
|
-
const worker = async () => {
|
|
909
|
-
for (let next = queue.shift(); next; next = queue.shift()) await restoreDocument(next);
|
|
910
|
-
};
|
|
911
|
-
await Promise.all([
|
|
912
|
-
tableRecovery,
|
|
913
|
-
objectsReady,
|
|
914
|
-
...Array.from({ length: Math.min(4, queue.length) }, worker),
|
|
915
|
-
]);
|
|
916
|
-
// Resolve legacy table identities only after table records are available.
|
|
917
|
-
for (const id of saved.tabs ?? [])
|
|
918
|
-
if (isTableTab(id))
|
|
919
|
-
remapped.set(id, tableTabId(dataTableFileId(tableFileId(id))));
|
|
920
|
-
const byId = new Map(documents.value.map((doc) => [doc.id, doc]));
|
|
921
|
-
documents.value = pendingDocs
|
|
922
|
-
.map(({ id }) => byId.get(id))
|
|
923
|
-
.filter((doc): doc is OpenDocument => !!doc);
|
|
924
|
-
const restored = saved.tabs
|
|
925
|
-
?.map((id) => remapped.get(id) ?? id)
|
|
926
|
-
.filter(
|
|
927
|
-
(id) =>
|
|
928
|
-
tabsLayout.isUtilityTab(id) || documents.value.some((doc) => doc.id === id),
|
|
929
|
-
);
|
|
930
|
-
tabIds.value = [...new Set([...(restored ?? []), ...documents.value.map((doc) => doc.id)])];
|
|
931
|
-
const currentActive = remapped.get(activeId.value) ?? activeId.value;
|
|
932
|
-
tabsLayout.layout.value = restoreLayout(tabsLayout.layout.value, tabIds.value, remapped);
|
|
933
|
-
tabsLayout.activePaneId.value =
|
|
934
|
-
tabsLayout.panes.value.find((pane) => pane.tabs.includes(currentActive))?.id ??
|
|
935
|
-
tabsLayout.panes.value[0].id;
|
|
936
|
-
activeId.value = tabIds.value.includes(currentActive)
|
|
937
|
-
? currentActive
|
|
938
|
-
: (tabIds.value[0] ?? '');
|
|
939
|
-
for (const tabId of tabIds.value) tabsLayout.ensureTabNavigation(tabId, tabId);
|
|
940
|
-
tabsLayout.touchNavigation();
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
// Document opening, editing, saving, closing & conflict resolution
|
|
944
|
-
async function readOpenDocument(file: FileEntry): Promise<OpenDocument> {
|
|
945
|
-
const snapshot = await adapter.read(file.path);
|
|
946
|
-
const doc: OpenDocument = {
|
|
947
|
-
id: file.id,
|
|
948
|
-
path: file.path,
|
|
949
|
-
content: snapshot.content,
|
|
950
|
-
base: snapshot,
|
|
951
|
-
saving: false,
|
|
952
|
-
creating: file.pendingCreation,
|
|
953
|
-
missing: false,
|
|
954
|
-
};
|
|
955
|
-
if (!doc.creating) await hydrateDocumentLayout(doc);
|
|
956
|
-
return doc;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
async function openInternal(file: FileEntry, replaceId?: string, current = () => true) {
|
|
960
|
-
// The tree may already show a pending rename; storage still uses its
|
|
961
|
-
// confirmed path until the background mutation completes.
|
|
962
|
-
file = workspace.value?.files.find((entry) => entry.id === file.id) ?? file;
|
|
963
|
-
if (file.kind === 'file' && isDataTableFilePath(file.path)) {
|
|
964
|
-
tabsLayout.activateTab(tableTabId(file.id), replaceId);
|
|
965
|
-
return;
|
|
966
|
-
}
|
|
967
|
-
if (!isMarkdown(file.path) || file.kind !== 'file') return;
|
|
968
|
-
let doc = documentIndex.byId.value.get(file.id);
|
|
969
|
-
if (!doc) doc = await readOpenDocument(file);
|
|
970
|
-
if (!current()) return;
|
|
971
|
-
if (tabIds.value.includes(doc.id) && !documentIndex.byId.value.has(doc.id))
|
|
972
|
-
documents.value.push(doc);
|
|
973
|
-
tabsLayout.activateTab(doc.id, replaceId, doc);
|
|
974
|
-
const opened = documentIndex.byId.value.get(doc!.id)!;
|
|
975
|
-
if (opened.creating)
|
|
976
|
-
void fileOps.confirmCreation(opened).then((confirmed) => {
|
|
977
|
-
if (confirmed && !disposed && dirty(opened)) void flush();
|
|
978
|
-
});
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
async function prepareTabReplacement(id?: string) {
|
|
982
|
-
if (id && isTableTab(id) && !(await flush())) {
|
|
983
|
-
report('此数据表尚未保存,请先处理保存错误。');
|
|
984
|
-
return false;
|
|
985
|
-
}
|
|
986
|
-
if (assistantBridge.suggestionPersistence.value?.pending() && !(await flush())) return false;
|
|
987
|
-
const current = documentIndex.byId.value.get(tabsLayout.tabTarget(id ?? ''));
|
|
988
|
-
if (!current) return true;
|
|
989
|
-
if ((dirty(current) || layoutPending(current)) && !(await flush())) {
|
|
990
|
-
report('此文档尚未保存,请先处理保存错误。');
|
|
991
|
-
return false;
|
|
992
|
-
}
|
|
993
|
-
if (current.conflict || current.missing) {
|
|
994
|
-
report('请先处理当前文档的冲突或缺失,再替换标签页。');
|
|
995
|
-
return false;
|
|
996
|
-
}
|
|
997
|
-
await beforeCloseDocument?.(current.id);
|
|
998
|
-
if ((dirty(current) || layoutPending(current)) && !(await flush())) {
|
|
999
|
-
report('此文档尚未保存,请先处理保存错误。');
|
|
1000
|
-
return false;
|
|
1001
|
-
}
|
|
1002
|
-
if (current.conflict || current.missing) {
|
|
1003
|
-
report('请先处理当前文档的冲突或缺失,再替换标签页。');
|
|
1004
|
-
return false;
|
|
1005
|
-
}
|
|
1006
|
-
return true;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
function prefetchFile(file: FileEntry) {
|
|
1010
|
-
if (!adapter.prefetch || busy.value || disposed || file.kind !== 'file' || !isMarkdown(file.path))
|
|
1011
|
-
return;
|
|
1012
|
-
const entry = fileRegistry.value?.get(file.id);
|
|
1013
|
-
if (!entry || entry.pendingCreation) return;
|
|
1014
|
-
// This is only a hint. Opening still reports real read errors and validates
|
|
1015
|
-
// the current version; hovering must never surface an error banner.
|
|
1016
|
-
void adapter.prefetch(entry.path).catch(() => {});
|
|
1017
|
-
if (/^[0-9a-f]{6}$/.test(entry.id)) {
|
|
1018
|
-
const path = documentLayoutPath(entry.id);
|
|
1019
|
-
if (fileRegistry.value?.at(path)) void adapter.prefetch(path).catch(() => {});
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
function openCached(file: FileEntry, replaceId?: string) {
|
|
1024
|
-
if (fileMutations.pending.value) return false;
|
|
1025
|
-
const existing = documentIndex.byId.value.get(file.id);
|
|
1026
|
-
if (existing) {
|
|
1027
|
-
tabsLayout.activateTab(existing.id, replaceId, existing);
|
|
1028
|
-
return true;
|
|
1029
|
-
}
|
|
1030
|
-
const entry = fileRegistry.value?.get(file.id);
|
|
1031
|
-
if (!entry || entry.pendingCreation) return false;
|
|
1032
|
-
const snapshot = adapter.readCached?.(entry.path);
|
|
1033
|
-
if (!snapshot) return false;
|
|
1034
|
-
const doc: OpenDocument = {
|
|
1035
|
-
id: entry.id,
|
|
1036
|
-
path: entry.path,
|
|
1037
|
-
content: snapshot.content,
|
|
1038
|
-
base: snapshot,
|
|
1039
|
-
saving: false,
|
|
1040
|
-
missing: false,
|
|
1041
|
-
};
|
|
1042
|
-
if (/^[0-9a-f]{6}$/.test(entry.id)) {
|
|
1043
|
-
const path = documentLayoutPath(entry.id);
|
|
1044
|
-
const exists = !!fileRegistry.value?.at(path);
|
|
1045
|
-
const base = exists ? adapter.readCached?.(path) : null;
|
|
1046
|
-
if (exists && !base) return false;
|
|
1047
|
-
try {
|
|
1048
|
-
doc.tableLayout = {
|
|
1049
|
-
base: base ?? null,
|
|
1050
|
-
file: base
|
|
1051
|
-
? parseDocumentLayout(base.content, entry.id)
|
|
1052
|
-
: { version: 1, fileId: entry.id, tables: [] },
|
|
1053
|
-
};
|
|
1054
|
-
} catch {
|
|
1055
|
-
return false;
|
|
1056
|
-
} // The ordinary loader reports malformed layouts.
|
|
1057
|
-
}
|
|
1058
|
-
// Cache lookup and activation are synchronous. A background workspace scan
|
|
1059
|
-
// can reconcile later; it must not make displaying known bytes wait on I/O.
|
|
1060
|
-
tabsLayout.activateTab(doc.id, replaceId, doc);
|
|
1061
|
-
return true;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
function recordOpenedDocument(file: FileEntry) {
|
|
1065
|
-
recordHelpCompleted('welcome');
|
|
1066
|
-
if (
|
|
1067
|
-
workspace.value &&
|
|
1068
|
-
indexFolderHomes(
|
|
1069
|
-
workspace.value.files,
|
|
1070
|
-
policy.workspaceSettings.value.folderHomeFileName,
|
|
1071
|
-
).get(parentPath(file.path))?.id === file.id
|
|
1072
|
-
)
|
|
1073
|
-
recordHelpCompleted('folder-home');
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
/** Running plugins that declare fileHandlers can handle compound-suffix Markdown or attachments. */
|
|
1077
|
-
function fileEditorHandler(file: FileEntry) {
|
|
1078
|
-
if (file.kind !== 'file' || !workspace.value || !isMarkdown(file.path)) return undefined;
|
|
1079
|
-
return resolvePluginFileHandler(file.path, 'editor', plugins.pluginFileHandlers.value);
|
|
1080
|
-
}
|
|
1081
|
-
function filePreviewHandler(file: FileEntry) {
|
|
1082
|
-
if (
|
|
1083
|
-
file.kind !== 'file' ||
|
|
1084
|
-
!workspace.value ||
|
|
1085
|
-
isMarkdown(file.path) ||
|
|
1086
|
-
isDataTableFilePath(file.path)
|
|
1087
|
-
)
|
|
1088
|
-
return undefined;
|
|
1089
|
-
return resolvePluginFileHandler(file.path, 'preview', plugins.pluginFileHandlers.value);
|
|
1090
|
-
}
|
|
1091
|
-
async function openFileWithEditorHandler(file: FileEntry, handler: PluginWorkbenchFileHandler) {
|
|
1092
|
-
const currentWorkspace = workspace.value;
|
|
1093
|
-
if (!currentWorkspace) return false;
|
|
1094
|
-
try {
|
|
1095
|
-
await plugins.pluginExecutor.invoke(handler.pluginId, 'command', handler.command, {
|
|
1096
|
-
workspaceId: currentWorkspace.id,
|
|
1097
|
-
fileId: file.id,
|
|
1098
|
-
});
|
|
1099
|
-
return true;
|
|
1100
|
-
} catch (error) {
|
|
1101
|
-
report(error);
|
|
1102
|
-
return false;
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
function hasMarkdownFileHandler(file: FileEntry) {
|
|
1106
|
-
return !!fileEditorHandler(file);
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
async function openFile(
|
|
1110
|
-
file: FileEntry,
|
|
1111
|
-
options?: { historyIndex?: number; rawSource?: boolean },
|
|
1112
|
-
) {
|
|
1113
|
-
if (filePreviewHandler(file)) return openAttachment(file, options);
|
|
1114
|
-
const editorHandler = options?.rawSource ? undefined : fileEditorHandler(file);
|
|
1115
|
-
if (editorHandler && (await openFileWithEditorHandler(file, editorHandler))) return;
|
|
1116
|
-
const creationAtRequest = fileOps.getCreationRevision();
|
|
1117
|
-
const request = ++fileOpenRevision;
|
|
1118
|
-
const paneId = tabsLayout.activePaneId.value;
|
|
1119
|
-
const epoch = assistantBridge.assistantEpoch.value;
|
|
1120
|
-
const activation = tabsLayout.getActivationRevision();
|
|
1121
|
-
const workspaceId = workspace.value?.id;
|
|
1122
|
-
const current = () =>
|
|
1123
|
-
!disposed &&
|
|
1124
|
-
!busy.value &&
|
|
1125
|
-
request === fileOpenRevision &&
|
|
1126
|
-
creationAtRequest === fileOps.getCreationRevision() &&
|
|
1127
|
-
epoch === assistantBridge.assistantEpoch.value &&
|
|
1128
|
-
workspaceId === workspace.value?.id &&
|
|
1129
|
-
activation === tabsLayout.getActivationRevision();
|
|
1130
|
-
try {
|
|
1131
|
-
if (file.kind === 'file' && isDataTableFilePath(file.path))
|
|
1132
|
-
return openDataTable(file.id, options);
|
|
1133
|
-
if (!isMarkdown(file.path) || file.kind !== 'file') return;
|
|
1134
|
-
const replaceId =
|
|
1135
|
-
tabsLayout.isUtilityTab(activeId.value) &&
|
|
1136
|
-
!activeId.value.startsWith('blank:') &&
|
|
1137
|
-
!tabsLayout.isNavigationPage(activeId.value)
|
|
1138
|
-
? undefined
|
|
1139
|
-
: activeId.value;
|
|
1140
|
-
const wasOpen = documents.value.some((doc) => doc.id === file.id);
|
|
1141
|
-
prefetchFile(file);
|
|
1142
|
-
if (!wasOpen && !(await prepareTabReplacement(replaceId))) return;
|
|
1143
|
-
if (!current()) return;
|
|
1144
|
-
if (!wasOpen) openingDocuments.value[paneId] = { request, tabId: activeId.value };
|
|
1145
|
-
if (!openCached(file, replaceId))
|
|
1146
|
-
await serial(async () => {
|
|
1147
|
-
if (!current()) return;
|
|
1148
|
-
await openInternal(file, replaceId, current);
|
|
1149
|
-
});
|
|
1150
|
-
if (!wasOpen && replaceId && activeId.value === file.id)
|
|
1151
|
-
tabsLayout.recordTabNavigation(replaceId, file.id, options?.historyIndex);
|
|
1152
|
-
else if (!replaceId && activeId.value === file.id)
|
|
1153
|
-
tabsLayout.ensureTabNavigation(file.id, file.id);
|
|
1154
|
-
if (tabsLayout.active.value?.id === file.id) recordOpenedDocument(file);
|
|
1155
|
-
} catch (e) {
|
|
1156
|
-
if (current()) report(e);
|
|
1157
|
-
} finally {
|
|
1158
|
-
if (openingDocuments.value[paneId]?.request === request) delete openingDocuments.value[paneId];
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
async function openFileInNewTab(file: FileEntry, options?: { rawSource?: boolean }) {
|
|
1163
|
-
try {
|
|
1164
|
-
if (filePreviewHandler(file)) return openAttachmentInNewTab(file);
|
|
1165
|
-
const editorHandler = options?.rawSource ? undefined : fileEditorHandler(file);
|
|
1166
|
-
if (editorHandler && (await openFileWithEditorHandler(file, editorHandler))) return;
|
|
1167
|
-
await serial(async () => {
|
|
1168
|
-
if (file.kind === 'file' && isDataTableFilePath(file.path)) {
|
|
1169
|
-
const target = tableTabId(dataTableFileId(file.id));
|
|
1170
|
-
if (tabIds.value.includes(target)) {
|
|
1171
|
-
const alias = tabsLayout.newTabAlias(target);
|
|
1172
|
-
tabIds.value.push(alias);
|
|
1173
|
-
activeId.value = alias;
|
|
1174
|
-
tabsLayout.ensureTabNavigation(alias, target);
|
|
1175
|
-
tabsLayout.touchNavigation();
|
|
1176
|
-
} else await openDataTable(file.id, { newTab: true });
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
const target = file.id;
|
|
1180
|
-
if (tabIds.value.includes(target)) {
|
|
1181
|
-
const alias = tabsLayout.newTabAlias(target);
|
|
1182
|
-
tabIds.value.push(alias);
|
|
1183
|
-
activeId.value = alias;
|
|
1184
|
-
tabsLayout.ensureTabNavigation(alias, target);
|
|
1185
|
-
tabsLayout.touchNavigation();
|
|
1186
|
-
return;
|
|
1187
|
-
}
|
|
1188
|
-
await openInternal(file);
|
|
1189
|
-
if (activeId.value === file.id) tabsLayout.ensureTabNavigation(file.id, file.id);
|
|
1190
|
-
});
|
|
1191
|
-
if (tabsLayout.active.value?.id === file.id) recordOpenedDocument(file);
|
|
1192
|
-
} catch (error) {
|
|
1193
|
-
report(error);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
async function openAttachment(
|
|
1198
|
-
file: FileEntry,
|
|
1199
|
-
options?: { newTab?: boolean; historyIndex?: number },
|
|
1200
|
-
) {
|
|
1201
|
-
const currentWorkspace = workspace.value;
|
|
1202
|
-
if (
|
|
1203
|
-
!currentWorkspace ||
|
|
1204
|
-
file.kind !== 'file' ||
|
|
1205
|
-
isMarkdown(file.path) ||
|
|
1206
|
-
isDataTableFilePath(file.path) ||
|
|
1207
|
-
!currentWorkspace.files.some((entry) => entry.id === file.id && entry.path === file.path)
|
|
1208
|
-
)
|
|
1209
|
-
return;
|
|
1210
|
-
const workspaceId = currentWorkspace.id;
|
|
1211
|
-
const request = ++fileOpenRevision;
|
|
1212
|
-
const activation = tabsLayout.getActivationRevision();
|
|
1213
|
-
const current = () => request === fileOpenRevision && !busy.value && !disposed;
|
|
1214
|
-
const target = `attachment:${file.id}`;
|
|
1215
|
-
const handler = filePreviewHandler(file);
|
|
1216
|
-
const usePlugin =
|
|
1217
|
-
!!handler && plugins.pluginViews.value.some((view) => view.key === handler.viewKey);
|
|
1218
|
-
const id = usePlugin && handler ? handler.viewKey : target;
|
|
1219
|
-
// Preview plugins share one tab per view while navigation history follows individual files.
|
|
1220
|
-
const opened = await openPageTab(id, {
|
|
1221
|
-
...options,
|
|
1222
|
-
target,
|
|
1223
|
-
current: () => current() && tabsLayout.getActivationRevision() === activation,
|
|
1224
|
-
});
|
|
1225
|
-
if (
|
|
1226
|
-
!opened ||
|
|
1227
|
-
!usePlugin ||
|
|
1228
|
-
!handler ||
|
|
1229
|
-
!current() ||
|
|
1230
|
-
activeId.value !== id ||
|
|
1231
|
-
workspace.value?.id !== workspaceId
|
|
1232
|
-
)
|
|
1233
|
-
return;
|
|
1234
|
-
const previewActivation = tabsLayout.getActivationRevision();
|
|
1235
|
-
try {
|
|
1236
|
-
await plugins.pluginExecutor.invoke(handler.pluginId, 'command', handler.command, {
|
|
1237
|
-
workspaceId,
|
|
1238
|
-
fileId: file.id,
|
|
1239
|
-
viewAlreadyOpen: true,
|
|
1240
|
-
});
|
|
1241
|
-
} catch (error) {
|
|
1242
|
-
if (
|
|
1243
|
-
!current() ||
|
|
1244
|
-
tabsLayout.getActivationRevision() !== previewActivation ||
|
|
1245
|
-
workspace.value?.id !== workspaceId
|
|
1246
|
-
)
|
|
1247
|
-
return;
|
|
1248
|
-
report(error);
|
|
1249
|
-
await openPageTab(target, {
|
|
1250
|
-
target,
|
|
1251
|
-
current: () => current() && tabsLayout.getActivationRevision() === previewActivation,
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
function openAttachmentInNewTab(file: FileEntry) {
|
|
1257
|
-
return openAttachment(file, { newTab: true });
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
async function openFilesInNewTabsAt(
|
|
1261
|
-
ids: readonly string[],
|
|
1262
|
-
index: number,
|
|
1263
|
-
workspaceId: string,
|
|
1264
|
-
) {
|
|
1265
|
-
try {
|
|
1266
|
-
await serial(async () => {
|
|
1267
|
-
if (workspace.value?.id !== workspaceId) return;
|
|
1268
|
-
const files = [...new Set(ids)].map((id) =>
|
|
1269
|
-
workspace.value!.files.find((file) => file.id === id),
|
|
1270
|
-
);
|
|
1271
|
-
if (
|
|
1272
|
-
!files.length ||
|
|
1273
|
-
files.some(
|
|
1274
|
-
(file) =>
|
|
1275
|
-
!file ||
|
|
1276
|
-
file.kind !== 'file' ||
|
|
1277
|
-
!(isMarkdown(file.path) || isDataTableFilePath(file.path)),
|
|
1278
|
-
)
|
|
1279
|
-
)
|
|
1280
|
-
return;
|
|
1281
|
-
// Keep a stable neighbor while reads are pending and already-open tabs move.
|
|
1282
|
-
const moving = new Set(
|
|
1283
|
-
files.map((file) => (isDataTableFilePath(file!.path) ? tableTabId(file!.id) : file!.id)),
|
|
1284
|
-
);
|
|
1285
|
-
const following = tabIds.value.slice(Math.max(0, index)).filter((id) => !moving.has(id));
|
|
1286
|
-
for (const file of files) {
|
|
1287
|
-
await openInternal(file!);
|
|
1288
|
-
if (tabsLayout.active.value?.id === file!.id) recordHelpCompleted('welcome');
|
|
1289
|
-
const id = isDataTableFilePath(file!.path) ? tableTabId(file!.id) : file!.id;
|
|
1290
|
-
tabsLayout.ensureTabNavigation(id, id);
|
|
1291
|
-
const target = following.find((tabId) => tabIds.value.includes(tabId));
|
|
1292
|
-
if (target) tabsLayout.moveDocument(id, target, 'before');
|
|
1293
|
-
else tabsLayout.placeTab(id, tabIds.value.length);
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
} catch (error) {
|
|
1297
|
-
report(error);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
async function openPageTab(
|
|
1302
|
-
id: string,
|
|
1303
|
-
options?: { newTab?: boolean; historyIndex?: number; target?: string; current?: () => boolean },
|
|
1304
|
-
) {
|
|
1305
|
-
if (!workspace.value) return false;
|
|
1306
|
-
if (options?.newTab) {
|
|
1307
|
-
tabsLayout.activateTab(id);
|
|
1308
|
-
tabsLayout.ensureTabNavigation(id, options.target);
|
|
1309
|
-
if (options.target) tabsLayout.recordTabNavigation(id, id, undefined, options.target);
|
|
1310
|
-
else tabsLayout.touchNavigation();
|
|
1311
|
-
return true;
|
|
1312
|
-
}
|
|
1313
|
-
const workspaceId = workspace.value.id;
|
|
1314
|
-
const epoch = assistantBridge.assistantEpoch.value;
|
|
1315
|
-
const replaceId = activeId.value;
|
|
1316
|
-
const wasOpen = tabIds.value.includes(id);
|
|
1317
|
-
try {
|
|
1318
|
-
if (!wasOpen && !(await prepareTabReplacement(replaceId))) return false;
|
|
1319
|
-
return await serial(async () => {
|
|
1320
|
-
if (
|
|
1321
|
-
workspace.value?.id !== workspaceId ||
|
|
1322
|
-
assistantBridge.assistantEpoch.value !== epoch ||
|
|
1323
|
-
(options?.current && (!options.current() || activeId.value !== replaceId))
|
|
1324
|
-
)
|
|
1325
|
-
return false;
|
|
1326
|
-
const targetId = activeId.value === replaceId ? replaceId : undefined;
|
|
1327
|
-
tabsLayout.activateTab(id, targetId);
|
|
1328
|
-
if (!wasOpen && targetId)
|
|
1329
|
-
tabsLayout.recordTabNavigation(targetId, id, options?.historyIndex, options?.target);
|
|
1330
|
-
else if (options?.target) {
|
|
1331
|
-
tabsLayout.ensureTabNavigation(id, options.target);
|
|
1332
|
-
tabsLayout.recordTabNavigation(
|
|
1333
|
-
id,
|
|
1334
|
-
id,
|
|
1335
|
-
targetId === id ? options.historyIndex : undefined,
|
|
1336
|
-
options.target,
|
|
1337
|
-
);
|
|
1338
|
-
} else {
|
|
1339
|
-
tabsLayout.ensureTabNavigation(id);
|
|
1340
|
-
tabsLayout.touchNavigation();
|
|
1341
|
-
}
|
|
1342
|
-
return true;
|
|
1343
|
-
});
|
|
1344
|
-
} catch (error) {
|
|
1345
|
-
report(error);
|
|
1346
|
-
return false;
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
async function openGraphTab(options?: { newTab?: boolean; historyIndex?: number }) {
|
|
1351
|
-
await openPageTab(GRAPH_TAB_ID, options);
|
|
1352
|
-
if (workspace.value && activeId.value === GRAPH_TAB_ID) recordHelpCompleted('graph');
|
|
1353
|
-
}
|
|
1354
|
-
async function openDirectory(
|
|
1355
|
-
path: string,
|
|
1356
|
-
options?: { newTab?: boolean; historyIndex?: number },
|
|
1357
|
-
) {
|
|
1358
|
-
if (!workspace.value) return;
|
|
1359
|
-
const entry = workspace.value.files.find(
|
|
1360
|
-
(file) => file.kind === 'directory' && file.path === path,
|
|
1361
|
-
);
|
|
1362
|
-
if (path && !entry) return;
|
|
1363
|
-
await openPageTab(path ? `directory:${entry!.id}` : 'directory:/', options);
|
|
1364
|
-
}
|
|
1365
|
-
async function openPluginDetail(
|
|
1366
|
-
pluginId: string,
|
|
1367
|
-
options?: { newTab?: boolean; historyIndex?: number },
|
|
1368
|
-
) {
|
|
1369
|
-
if (tabsLayout.pluginDetailManifest(`plugin:${pluginId}`))
|
|
1370
|
-
await openPageTab(`plugin:${pluginId}`, options);
|
|
1371
|
-
}
|
|
1372
|
-
async function openPluginsTab(options?: { newTab?: boolean; historyIndex?: number }) {
|
|
1373
|
-
await openPageTab(PLUGINS_TAB_ID, options);
|
|
1374
|
-
if (workspace.value && activeId.value === PLUGINS_TAB_ID) recordHelpCompleted('plugins');
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
// Serialize adapter reads with workspace switches. The graph never writes
|
|
1378
|
-
// content, and open drafts take precedence over the filesystem snapshot.
|
|
1379
|
-
function readGraphDocument(
|
|
1380
|
-
expectedWorkspace: Pick<Workspace, 'id' | 'path'>,
|
|
1381
|
-
file: Pick<FileEntry, 'id'> & Partial<Pick<FileEntry, 'path'>>,
|
|
1382
|
-
) {
|
|
1383
|
-
return serial(async () => {
|
|
1384
|
-
if (
|
|
1385
|
-
workspace.value?.id !== expectedWorkspace.id ||
|
|
1386
|
-
workspace.value.path !== expectedWorkspace.path
|
|
1387
|
-
)
|
|
1388
|
-
throw new Error('工作区已切换');
|
|
1389
|
-
const entry = fileRegistry.value?.get(file.id);
|
|
1390
|
-
if (
|
|
1391
|
-
!entry ||
|
|
1392
|
-
(file.path !== undefined && entry.path !== file.path) ||
|
|
1393
|
-
entry.kind !== 'file' ||
|
|
1394
|
-
!isMarkdown(entry.path)
|
|
1395
|
-
)
|
|
1396
|
-
throw new Error('文档已移动或删除');
|
|
1397
|
-
const draft = documentIndex.byId.value.get(file.id);
|
|
1398
|
-
if (draft) return draft.content;
|
|
1399
|
-
const snapshot = await adapter.read(entry.path);
|
|
1400
|
-
return documentIndex.byId.value.get(file.id)?.content ?? snapshot.content;
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
function edit(content: string) {
|
|
1405
|
-
if (tabsLayout.active.value) editDocument(tabsLayout.active.value.id, content);
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
function editDocument(id: string, content: string, options: { origin?: 'local' | 'remote' } = {}) {
|
|
1409
|
-
const doc = documentIndex.byId.value.get(id);
|
|
1410
|
-
if (!doc || doc.conflict || workspace.value?.readOnly || fileRegistry.value?.get(id)?.readOnly)
|
|
1411
|
-
return;
|
|
1412
|
-
const before = doc.content;
|
|
1413
|
-
doc.content = content;
|
|
1414
|
-
if (!doc.creating) doc.error = undefined;
|
|
1415
|
-
clearTimeout(saveTimer);
|
|
1416
|
-
saveTimer = setTimeout(() => {
|
|
1417
|
-
void flush();
|
|
1418
|
-
}, 600);
|
|
1419
|
-
if (options.origin !== 'remote')
|
|
1420
|
-
helpEdits.record(id, before, content, knowledge.referenceTargets.value);
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
function receiveDocument(
|
|
1424
|
-
id: string,
|
|
1425
|
-
content: string,
|
|
1426
|
-
options: { origin?: 'local' | 'remote' } = {},
|
|
1427
|
-
) {
|
|
1428
|
-
const doc = documentIndex.byId.value.get(id);
|
|
1429
|
-
if (!doc || doc.conflict || doc.missing) return;
|
|
1430
|
-
const before = doc.content;
|
|
1431
|
-
doc.content = content;
|
|
1432
|
-
clearTimeout(saveTimer);
|
|
1433
|
-
saveTimer = setTimeout(() => {
|
|
1434
|
-
void flush();
|
|
1435
|
-
}, 600);
|
|
1436
|
-
if (options.origin === 'local')
|
|
1437
|
-
helpEdits.record(id, before, content, knowledge.referenceTargets.value);
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
async function hydrateDocumentLayout(doc: OpenDocument) {
|
|
1441
|
-
if (!workspace.value || !/^[0-9a-f]{6}$/.test(doc.id)) return;
|
|
1442
|
-
try {
|
|
1443
|
-
doc.tableLayout = await loadDocumentLayout(adapter, workspace.value, doc.id);
|
|
1444
|
-
} catch (error) {
|
|
1445
|
-
report(`无法读取表格布局,原文件已保留:${String(error)}`);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
function editTableLayout(id: string, tables: TableLayout[]) {
|
|
1450
|
-
const doc = documentIndex.byId.value.get(id);
|
|
1451
|
-
if (!doc?.tableLayout || doc.conflict || doc.missing || workspace.value?.readOnly) return;
|
|
1452
|
-
doc.tableLayout.file = {
|
|
1453
|
-
...doc.tableLayout.file,
|
|
1454
|
-
tables: JSON.parse(JSON.stringify(tables)),
|
|
1455
|
-
};
|
|
1456
|
-
doc.tableLayout.error = undefined;
|
|
1457
|
-
clearTimeout(saveTimer);
|
|
1458
|
-
saveTimer = setTimeout(() => {
|
|
1459
|
-
void flush();
|
|
1460
|
-
}, 300);
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
async function saveTableLayout(doc: OpenDocument) {
|
|
1464
|
-
const state = doc.tableLayout;
|
|
1465
|
-
if (!state || !layoutDirty(state) || doc.missing || doc.conflict) return;
|
|
1466
|
-
const draft = JSON.stringify(state.file);
|
|
1467
|
-
if (state.conflict?.draft === draft) return;
|
|
1468
|
-
try {
|
|
1469
|
-
const saved = await saveDocumentLayout(adapter, state);
|
|
1470
|
-
state.base = saved.base;
|
|
1471
|
-
if (JSON.stringify(state.file) === draft) state.file = saved.file;
|
|
1472
|
-
state.error = undefined;
|
|
1473
|
-
state.conflict = undefined;
|
|
1474
|
-
} catch (error) {
|
|
1475
|
-
if (error instanceof DocumentLayoutConflict) state.conflict = { path: error.path, draft };
|
|
1476
|
-
state.error = String(error);
|
|
1477
|
-
report(error);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
async function flush(): Promise<boolean> {
|
|
1482
|
-
await fileMutations.flush();
|
|
1483
|
-
return flushDocuments();
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
async function flushDocuments(): Promise<boolean> {
|
|
1487
|
-
await fileOps.awaitCreationChain();
|
|
1488
|
-
try {
|
|
1489
|
-
await assistantBridge.suggestionPersistence.value?.flush();
|
|
1490
|
-
} catch (error) {
|
|
1491
|
-
report(error);
|
|
1492
|
-
return false;
|
|
1493
|
-
}
|
|
1494
|
-
clearTimeout(saveTimer);
|
|
1495
|
-
const saved = await serial(async () => {
|
|
1496
|
-
const tablesSaved = await dataTables.persistAll();
|
|
1497
|
-
for (const doc of documents.value) {
|
|
1498
|
-
await saveInternal(doc);
|
|
1499
|
-
await saveTableLayout(doc);
|
|
1500
|
-
}
|
|
1501
|
-
return (
|
|
1502
|
-
tablesSaved &&
|
|
1503
|
-
documents.value.every((doc) => (!dirty(doc) || !!doc.conflict) && !layoutPending(doc))
|
|
1504
|
-
);
|
|
1505
|
-
});
|
|
1506
|
-
await journal.flush();
|
|
1507
|
-
return saved;
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
async function refresh() {
|
|
1511
|
-
if (!workspace.value) return;
|
|
1512
|
-
const expectedId = workspace.value.id;
|
|
1513
|
-
const expectedPath = workspace.value.path;
|
|
1514
|
-
try {
|
|
1515
|
-
await serial(async () => {
|
|
1516
|
-
if (workspace.value?.id !== expectedId || workspace.value.path !== expectedPath) return;
|
|
1517
|
-
workspace.value = await adapter.refresh();
|
|
1518
|
-
await policy.refreshCapabilities();
|
|
1519
|
-
await policy.refreshWorkspaceSettings();
|
|
1520
|
-
await knowledge.refreshObjects();
|
|
1521
|
-
await dataTables.reload();
|
|
1522
|
-
for (const doc of documents.value) {
|
|
1523
|
-
if (doc.creating) continue;
|
|
1524
|
-
const entry = fileRegistry.value?.get(doc.id);
|
|
1525
|
-
if (!entry) {
|
|
1526
|
-
if (!doc.missing) activity('文件已在外部移除', doc.path, 'external');
|
|
1527
|
-
doc.missing = true;
|
|
1528
|
-
continue;
|
|
1529
|
-
}
|
|
1530
|
-
if (doc.path !== entry.path) {
|
|
1531
|
-
activity('文件已在外部重命名', `${doc.path} → ${entry.path}`, 'external');
|
|
1532
|
-
doc.path = entry.path;
|
|
1533
|
-
}
|
|
1534
|
-
doc.missing = false;
|
|
1535
|
-
await reconcile(doc, await adapter.read(doc.path));
|
|
1536
|
-
await saveInternal(doc);
|
|
1537
|
-
if (doc.tableLayout && !layoutDirty(doc.tableLayout)) await hydrateDocumentLayout(doc);
|
|
1538
|
-
await saveTableLayout(doc);
|
|
1539
|
-
}
|
|
1540
|
-
});
|
|
1541
|
-
} catch (error) {
|
|
1542
|
-
knowledge.clearRevokedReferences(error);
|
|
1543
|
-
report(error);
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
async function close(id: string) {
|
|
1548
|
-
if (isTableTab(id) && !(await flush())) {
|
|
1549
|
-
report('数据表尚有未保存的修改,请先处理保存错误。');
|
|
1550
|
-
return;
|
|
1551
|
-
}
|
|
1552
|
-
const pane = tabsLayout.panes.value.find((pane) => pane.tabs.includes(id));
|
|
1553
|
-
const nextTab = () => {
|
|
1554
|
-
const candidate = tabsLayout.panes.value
|
|
1555
|
-
.find((item) => item.id === pane?.id)
|
|
1556
|
-
?.tabs.find((tabId) => tabId !== id && tabIds.value.includes(tabId));
|
|
1557
|
-
return candidate ?? tabIds.value.find((tabId) => tabId !== id) ?? '';
|
|
1558
|
-
};
|
|
1559
|
-
if (tabsLayout.isUtilityTab(id)) {
|
|
1560
|
-
tabIds.value = tabIds.value.filter((tabId) => tabId !== id);
|
|
1561
|
-
tabsLayout.removeTabAlias(id);
|
|
1562
|
-
tabsLayout.removeTabNavigation(id);
|
|
1563
|
-
if (activeId.value === id) activeId.value = nextTab();
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
if (!(await flush())) {
|
|
1567
|
-
report('此文档尚有未保存的修改或建议,请先处理保存错误。');
|
|
1568
|
-
return;
|
|
1569
|
-
}
|
|
1570
|
-
try {
|
|
1571
|
-
await beforeCloseDocument?.(tabsLayout.tabTarget(id));
|
|
1572
|
-
} catch (error) {
|
|
1573
|
-
report(error);
|
|
1574
|
-
return;
|
|
1575
|
-
}
|
|
1576
|
-
const target = tabsLayout.tabTarget(id);
|
|
1577
|
-
const doc = documentIndex.byId.value.get(target);
|
|
1578
|
-
if (doc && ((dirty(doc) && !doc.conflict) || layoutPending(doc))) {
|
|
1579
|
-
report('此文档尚未保存,请先另存副本或解决保存错误。');
|
|
1580
|
-
return;
|
|
1581
|
-
}
|
|
1582
|
-
tabIds.value = tabIds.value.filter((tabId) => tabId !== id);
|
|
1583
|
-
tabsLayout.removeTabAlias(id);
|
|
1584
|
-
tabsLayout.removeTabNavigation(id);
|
|
1585
|
-
if (!tabIds.value.some((tabId) => tabsLayout.tabTarget(tabId) === target))
|
|
1586
|
-
documents.value = documents.value.filter((d) => d.id !== target);
|
|
1587
|
-
if (activeId.value === id) activeId.value = nextTab();
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
async function resolveConflict(doc: OpenDocument, openCopy: boolean) {
|
|
1591
|
-
await serial(async () => {
|
|
1592
|
-
if (!doc.conflict) return;
|
|
1593
|
-
const copy = doc.conflict.copyPath;
|
|
1594
|
-
// Read again: the external writer may have changed the original since the conflict.
|
|
1595
|
-
const latest = await adapter.read(doc.path);
|
|
1596
|
-
doc.base = latest;
|
|
1597
|
-
doc.content = latest.content;
|
|
1598
|
-
doc.conflict = undefined;
|
|
1599
|
-
doc.missing = false;
|
|
1600
|
-
doc.error = undefined;
|
|
1601
|
-
if (openCopy) {
|
|
1602
|
-
workspace.value = await adapter.refresh();
|
|
1603
|
-
const file = fileRegistry.value?.at(copy);
|
|
1604
|
-
if (file) {
|
|
1605
|
-
await openInternal(file);
|
|
1606
|
-
tabsLayout.ensureTabNavigation(file.id, file.id);
|
|
1607
|
-
tabsLayout.touchNavigation();
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
}).catch(report);
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
async function reveal() {
|
|
1614
|
-
try {
|
|
1615
|
-
await adapter.reveal();
|
|
1616
|
-
} catch (e) {
|
|
1617
|
-
report(e);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
439
|
|
|
1621
440
|
function dispose() {
|
|
1622
441
|
disposed = true;
|
|
1623
442
|
helpEdits.dispose();
|
|
1624
443
|
plugins.disposePlugins();
|
|
1625
|
-
stopSessionWatch();
|
|
444
|
+
session.stopSessionWatch();
|
|
1626
445
|
stopWatching();
|
|
1627
|
-
|
|
446
|
+
docIO.clearSaveTimer();
|
|
1628
447
|
}
|
|
1629
448
|
|
|
1630
449
|
return {
|
|
@@ -1636,11 +455,11 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
1636
455
|
discardDataTable: dataTables.discard,
|
|
1637
456
|
copyDataTable: async (source: DataTable, parent = '') => {
|
|
1638
457
|
const id = await dataTables.create('blank', source, parent);
|
|
1639
|
-
await openDataTable(id);
|
|
458
|
+
await docIO.openDataTable(id);
|
|
1640
459
|
},
|
|
1641
|
-
createDataTable,
|
|
1642
|
-
renameDataTable,
|
|
1643
|
-
openDataTable,
|
|
460
|
+
createDataTable: docIO.createDataTable,
|
|
461
|
+
renameDataTable: docIO.renameDataTable,
|
|
462
|
+
openDataTable: docIO.openDataTable,
|
|
1644
463
|
layout: tabsLayout.layout,
|
|
1645
464
|
windowLayouts: tabsLayout.windowLayouts,
|
|
1646
465
|
moveTabToWindow: tabsLayout.moveTabToWindow,
|
|
@@ -1744,23 +563,23 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
1744
563
|
isWeb,
|
|
1745
564
|
pending,
|
|
1746
565
|
dirty,
|
|
1747
|
-
initialize,
|
|
1748
|
-
refreshWorkspaces,
|
|
1749
|
-
openWorkspace,
|
|
1750
|
-
leaveWorkspace,
|
|
1751
|
-
deleteWorkspace,
|
|
1752
|
-
createWorkspace,
|
|
1753
|
-
openFile,
|
|
1754
|
-
prefetchFile,
|
|
1755
|
-
openFileInNewTab,
|
|
1756
|
-
openAttachment,
|
|
1757
|
-
openAttachmentInNewTab,
|
|
1758
|
-
openDirectory,
|
|
1759
|
-
openFilesInNewTabsAt,
|
|
566
|
+
initialize: lifecycle.initialize,
|
|
567
|
+
refreshWorkspaces: lifecycle.refreshWorkspaces,
|
|
568
|
+
openWorkspace: lifecycle.openWorkspace,
|
|
569
|
+
leaveWorkspace: lifecycle.leaveWorkspace,
|
|
570
|
+
deleteWorkspace: lifecycle.deleteWorkspace,
|
|
571
|
+
createWorkspace: lifecycle.createWorkspace,
|
|
572
|
+
openFile: docIO.openFile,
|
|
573
|
+
prefetchFile: docIO.prefetchFile,
|
|
574
|
+
openFileInNewTab: docIO.openFileInNewTab,
|
|
575
|
+
openAttachment: docIO.openAttachment,
|
|
576
|
+
openAttachmentInNewTab: docIO.openAttachmentInNewTab,
|
|
577
|
+
openDirectory: docIO.openDirectory,
|
|
578
|
+
openFilesInNewTabsAt: docIO.openFilesInNewTabsAt,
|
|
1760
579
|
createBlankTab: tabsLayout.createBlankTab,
|
|
1761
|
-
openGraphTab,
|
|
1762
|
-
openPluginsTab,
|
|
1763
|
-
openPluginDetail,
|
|
580
|
+
openGraphTab: docIO.openGraphTab,
|
|
581
|
+
openPluginsTab: docIO.openPluginsTab,
|
|
582
|
+
openPluginDetail: docIO.openPluginDetail,
|
|
1764
583
|
openCalendarTab: tabsLayout.openCalendarTab,
|
|
1765
584
|
registerViews: tabsLayout.registerViews,
|
|
1766
585
|
pluginViews: plugins.pluginViews,
|
|
@@ -1770,7 +589,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
1770
589
|
pluginCodeBlockRenderers: plugins.pluginCodeBlockRenderers,
|
|
1771
590
|
pluginDecorationsFor: plugins.pluginDecorationsFor,
|
|
1772
591
|
pluginStatusBarItems: plugins.pluginStatusBarItems,
|
|
1773
|
-
hasMarkdownFileHandler,
|
|
592
|
+
hasMarkdownFileHandler: docIO.hasMarkdownFileHandler,
|
|
1774
593
|
activePluginSidebar,
|
|
1775
594
|
activeDocumentPluginSidebar: plugins.activeDocumentPluginSidebar,
|
|
1776
595
|
activePluginDialog: plugins.activePluginDialog,
|
|
@@ -1790,7 +609,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
1790
609
|
pluginHomeTabView: plugins.pluginHomeTabView,
|
|
1791
610
|
pluginNewTabView: plugins.pluginNewTabView,
|
|
1792
611
|
openViewTab: tabsLayout.openViewTab,
|
|
1793
|
-
readGraphDocument,
|
|
612
|
+
readGraphDocument: docIO.readGraphDocument,
|
|
1794
613
|
assistantSnapshot: assistantBridge.assistantSnapshot,
|
|
1795
614
|
assistantSearch: assistantBridge.assistantSearch,
|
|
1796
615
|
assistantRules: assistantBridge.assistantRules,
|
|
@@ -1803,30 +622,29 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
1803
622
|
writeDocumentSuggestions: assistantBridge.writeDocumentSuggestions,
|
|
1804
623
|
acceptDocumentSuggestion: assistantBridge.acceptDocumentSuggestion,
|
|
1805
624
|
setSuggestionPersistence: assistantBridge.setSuggestionPersistence,
|
|
1806
|
-
edit,
|
|
1807
|
-
editDocument,
|
|
1808
|
-
editTableLayout,
|
|
625
|
+
edit: docIO.edit,
|
|
626
|
+
editDocument: docIO.editDocument,
|
|
627
|
+
editTableLayout: docIO.editTableLayout,
|
|
1809
628
|
preserveDraft: fileOps.preserveDraft,
|
|
1810
|
-
receiveDocument,
|
|
629
|
+
receiveDocument: docIO.receiveDocument,
|
|
1811
630
|
setBeforeWorkspaceChange: (hook?: () => Promise<void>) => {
|
|
1812
|
-
beforeWorkspaceChange = hook;
|
|
631
|
+
hooks.beforeWorkspaceChange = hook;
|
|
1813
632
|
},
|
|
1814
|
-
setDocumentLifecycle: (
|
|
633
|
+
setDocumentLifecycle: (nextHooks: {
|
|
1815
634
|
beforeSwitch: () => Promise<void>;
|
|
1816
635
|
afterSwitch?: () => Promise<void>;
|
|
1817
636
|
beforeCloseDocument: (id: string) => Promise<void>;
|
|
1818
637
|
}) => {
|
|
1819
|
-
beforeSwitch =
|
|
1820
|
-
afterSwitch =
|
|
1821
|
-
beforeCloseDocument =
|
|
638
|
+
hooks.beforeSwitch = nextHooks.beforeSwitch;
|
|
639
|
+
hooks.afterSwitch = nextHooks.afterSwitch;
|
|
640
|
+
hooks.beforeCloseDocument = nextHooks.beforeCloseDocument;
|
|
1822
641
|
},
|
|
1823
|
-
flush,
|
|
1824
|
-
refresh,
|
|
642
|
+
flush: docIO.flush,
|
|
643
|
+
refresh: lifecycle.refresh,
|
|
1825
644
|
enableWorkspacePolling,
|
|
1826
645
|
search: async (query: string, signal?: AbortSignal) => {
|
|
1827
646
|
const scope = workspace.value?.id;
|
|
1828
647
|
if (!scope || !adapter.search || signal?.aborted) return [];
|
|
1829
|
-
// Read-only search must not hold the mutation queue while remote files load.
|
|
1830
648
|
const results = await adapter.search(scope, query, signal);
|
|
1831
649
|
return workspace.value?.id === scope && !signal?.aborted ? results : [];
|
|
1832
650
|
},
|
|
@@ -1847,9 +665,9 @@ export const useWorkspaceStore = defineStore('workspace', () => {
|
|
|
1847
665
|
removeEntries: fileOps.removeEntries,
|
|
1848
666
|
moveDocument: tabsLayout.moveDocument,
|
|
1849
667
|
placeTab: tabsLayout.placeTab,
|
|
1850
|
-
close,
|
|
1851
|
-
resolveConflict,
|
|
1852
|
-
reveal,
|
|
668
|
+
close: docIO.close,
|
|
669
|
+
resolveConflict: docIO.resolveConflict,
|
|
670
|
+
reveal: lifecycle.reveal,
|
|
1853
671
|
dispose,
|
|
1854
672
|
report,
|
|
1855
673
|
};
|