@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
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
documentLayoutPath,
|
|
4
|
+
isDataTableFilePath,
|
|
5
|
+
isMarkdown,
|
|
6
|
+
parentPath,
|
|
7
|
+
parseDocumentLayout,
|
|
8
|
+
validatePath,
|
|
9
|
+
type FileEntry,
|
|
10
|
+
type FileRegistry,
|
|
11
|
+
type ReferenceTarget,
|
|
12
|
+
type TableLayout,
|
|
13
|
+
type Workspace,
|
|
14
|
+
type WorkspaceAdapter,
|
|
15
|
+
} from '@tano/protocol';
|
|
16
|
+
import type { WorkspaceSettings } from '../workspace/workspace-settings';
|
|
17
|
+
import type { createWorkspaceAssistantBridge } from '../assistant/workspace-bridge';
|
|
18
|
+
import type { createDataTableController } from '../data-tables/data-table-controller';
|
|
19
|
+
import { isTableTab, tableTabId } from '../data-tables/data-tables';
|
|
20
|
+
import { GRAPH_TAB_ID } from '../documents/document-graph';
|
|
21
|
+
import type { useDocumentIndex } from '../documents/document-index';
|
|
22
|
+
import { documentDirty as dirty, type OpenDocument } from '../documents/document-session';
|
|
23
|
+
import { indexFolderHomes } from '../files/folder-home';
|
|
24
|
+
import type { optimisticFiles } from '../files/optimistic-files';
|
|
25
|
+
import { recordHelpCompleted } from '../help/help-checklist';
|
|
26
|
+
import type { createHelpEditQueue } from '../help/help-edit-queue';
|
|
27
|
+
import {
|
|
28
|
+
resolvePluginFileHandler,
|
|
29
|
+
type PluginWorkbenchFileHandler,
|
|
30
|
+
} from '../plugins/workbench';
|
|
31
|
+
import { PLUGINS_TAB_ID } from '../plugins/workspace-plugins';
|
|
32
|
+
import type { SessionJournal } from '../shell/session-journal';
|
|
33
|
+
import {
|
|
34
|
+
DocumentLayoutConflict,
|
|
35
|
+
layoutDirty,
|
|
36
|
+
loadDocumentLayout,
|
|
37
|
+
saveDocumentLayout,
|
|
38
|
+
} from '../workspace/workspace-document-layout';
|
|
39
|
+
import type { createWorkspaceFileOps } from './workspace-file-ops';
|
|
40
|
+
import type { createWorkspacePluginsState } from './workspace-plugins-state';
|
|
41
|
+
import type { createWorkspaceTabsLayout } from './workspace-tabs-layout';
|
|
42
|
+
import type { WorkspaceLifecycleHooks } from './workspace-types';
|
|
43
|
+
|
|
44
|
+
export interface WorkspaceDocumentIODeps {
|
|
45
|
+
adapter: WorkspaceAdapter;
|
|
46
|
+
workspace: Ref<Workspace | null>;
|
|
47
|
+
fileRegistry: Ref<FileRegistry | null>;
|
|
48
|
+
fileMutations: ReturnType<typeof optimisticFiles>;
|
|
49
|
+
documents: Ref<OpenDocument[]>;
|
|
50
|
+
documentIndex: ReturnType<typeof useDocumentIndex>;
|
|
51
|
+
dataTables: ReturnType<typeof createDataTableController>;
|
|
52
|
+
workspaceSettings: Ref<WorkspaceSettings>;
|
|
53
|
+
referenceTargets: Ref<ReferenceTarget[]>;
|
|
54
|
+
tabIds: Ref<string[]>;
|
|
55
|
+
activeId: Ref<string>;
|
|
56
|
+
busy: Ref<boolean>;
|
|
57
|
+
openingDocuments: Ref<Record<string, { request: number; tabId: string }>>;
|
|
58
|
+
plugins: ReturnType<typeof createWorkspacePluginsState>;
|
|
59
|
+
tabsLayout: ReturnType<typeof createWorkspaceTabsLayout>;
|
|
60
|
+
assistantBridge: ReturnType<typeof createWorkspaceAssistantBridge>;
|
|
61
|
+
fileOps: ReturnType<typeof createWorkspaceFileOps>;
|
|
62
|
+
helpEdits: ReturnType<typeof createHelpEditQueue>;
|
|
63
|
+
journal: SessionJournal;
|
|
64
|
+
hooks: WorkspaceLifecycleHooks;
|
|
65
|
+
isDisposed: () => boolean;
|
|
66
|
+
layoutPending: (doc: OpenDocument) => boolean;
|
|
67
|
+
serial: <T>(task: () => Promise<T>) => Promise<T>;
|
|
68
|
+
saveInternal: (doc: OpenDocument) => Promise<void>;
|
|
69
|
+
report: (error: unknown) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createWorkspaceDocumentIO(deps: WorkspaceDocumentIODeps) {
|
|
73
|
+
const {
|
|
74
|
+
adapter,
|
|
75
|
+
workspace,
|
|
76
|
+
fileRegistry,
|
|
77
|
+
fileMutations,
|
|
78
|
+
documents,
|
|
79
|
+
documentIndex,
|
|
80
|
+
dataTables,
|
|
81
|
+
workspaceSettings,
|
|
82
|
+
referenceTargets,
|
|
83
|
+
tabIds,
|
|
84
|
+
activeId,
|
|
85
|
+
busy,
|
|
86
|
+
openingDocuments,
|
|
87
|
+
plugins,
|
|
88
|
+
tabsLayout,
|
|
89
|
+
assistantBridge,
|
|
90
|
+
fileOps,
|
|
91
|
+
helpEdits,
|
|
92
|
+
journal,
|
|
93
|
+
hooks,
|
|
94
|
+
isDisposed,
|
|
95
|
+
layoutPending,
|
|
96
|
+
serial,
|
|
97
|
+
saveInternal,
|
|
98
|
+
report,
|
|
99
|
+
} = deps;
|
|
100
|
+
|
|
101
|
+
let saveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
102
|
+
let fileOpenRevision = 0;
|
|
103
|
+
|
|
104
|
+
function dataTableFileId(id: string) {
|
|
105
|
+
if (workspace.value?.files.some((file) => file.id === id && isDataTableFilePath(file.path)))
|
|
106
|
+
return id;
|
|
107
|
+
return dataTables.records.value.find((record) => record.table.id === id)?.fileId ?? id;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function openDataTable(
|
|
111
|
+
id?: string,
|
|
112
|
+
options?: { newTab?: boolean; historyIndex?: number },
|
|
113
|
+
) {
|
|
114
|
+
if (!id) {
|
|
115
|
+
tabsLayout.createBlankTab();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await openPageTab(tableTabId(dataTableFileId(id)), options);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function createDataTable(template: 'blank' | 'parts' = 'blank', parent = '') {
|
|
122
|
+
const id = await dataTables.create(template, undefined, parent);
|
|
123
|
+
recordHelpCompleted('data-table');
|
|
124
|
+
await openDataTable(id);
|
|
125
|
+
return id;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function renameDataTable(id: string, name: string) {
|
|
129
|
+
const file = workspace.value?.files.find(
|
|
130
|
+
(file) => file.id === id && isDataTableFilePath(file.path),
|
|
131
|
+
);
|
|
132
|
+
if (!file) throw new Error('数据表文件已不存在');
|
|
133
|
+
const path = `${parentPath(file.path) ? `${parentPath(file.path)}/` : ''}${name.trim().normalize('NFC')}.table.json`;
|
|
134
|
+
if (!name.trim() || /[\\/]/.test(name)) throw new Error('请输入有效的文件名称');
|
|
135
|
+
const error = validatePath(path);
|
|
136
|
+
if (error) throw new Error(error);
|
|
137
|
+
if (path !== file.path) await fileOps.renameEntry(file, path);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function hydrateDocumentLayout(doc: OpenDocument) {
|
|
141
|
+
if (!workspace.value || !/^[0-9a-f]{6}$/.test(doc.id)) return;
|
|
142
|
+
try {
|
|
143
|
+
doc.tableLayout = await loadDocumentLayout(adapter, workspace.value, doc.id);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
report(`无法读取表格布局,原文件已保留:${String(error)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function saveTableLayout(doc: OpenDocument) {
|
|
150
|
+
const state = doc.tableLayout;
|
|
151
|
+
if (!state || !layoutDirty(state) || doc.missing || doc.conflict) return;
|
|
152
|
+
const draft = JSON.stringify(state.file);
|
|
153
|
+
if (state.conflict?.draft === draft) return;
|
|
154
|
+
try {
|
|
155
|
+
const saved = await saveDocumentLayout(adapter, state);
|
|
156
|
+
state.base = saved.base;
|
|
157
|
+
if (JSON.stringify(state.file) === draft) state.file = saved.file;
|
|
158
|
+
state.error = undefined;
|
|
159
|
+
state.conflict = undefined;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error instanceof DocumentLayoutConflict) state.conflict = { path: error.path, draft };
|
|
162
|
+
state.error = String(error);
|
|
163
|
+
report(error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isMarkdownEntry(file: FileEntry): boolean {
|
|
168
|
+
return file.kind === 'file' && isMarkdown(file.path);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function readOpenDocument(file: FileEntry): Promise<OpenDocument> {
|
|
172
|
+
const snapshot = await adapter.read(file.path);
|
|
173
|
+
const doc: OpenDocument = {
|
|
174
|
+
id: file.id,
|
|
175
|
+
path: file.path,
|
|
176
|
+
content: snapshot.content,
|
|
177
|
+
base: snapshot,
|
|
178
|
+
saving: false,
|
|
179
|
+
creating: file.pendingCreation,
|
|
180
|
+
missing: false,
|
|
181
|
+
};
|
|
182
|
+
if (!doc.creating) await hydrateDocumentLayout(doc);
|
|
183
|
+
return doc;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function openInternal(file: FileEntry, replaceId?: string, current = () => true) {
|
|
187
|
+
file = workspace.value?.files.find((entry) => entry.id === file.id) ?? file;
|
|
188
|
+
if (file.kind === 'file' && isDataTableFilePath(file.path)) {
|
|
189
|
+
tabsLayout.activateTab(tableTabId(file.id), replaceId);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (!isMarkdownEntry(file)) return;
|
|
193
|
+
let doc = documentIndex.byId.value.get(file.id);
|
|
194
|
+
if (!doc) doc = await readOpenDocument(file);
|
|
195
|
+
if (!current()) return;
|
|
196
|
+
if (tabIds.value.includes(doc.id) && !documentIndex.byId.value.has(doc.id))
|
|
197
|
+
documents.value.push(doc);
|
|
198
|
+
tabsLayout.activateTab(doc.id, replaceId, doc);
|
|
199
|
+
const opened = documentIndex.byId.value.get(doc!.id)!;
|
|
200
|
+
if (opened.creating)
|
|
201
|
+
void fileOps.confirmCreation(opened).then((confirmed) => {
|
|
202
|
+
if (confirmed && !isDisposed() && dirty(opened)) void flush();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function prepareTabReplacement(id?: string) {
|
|
207
|
+
if (id && isTableTab(id) && !(await flush())) {
|
|
208
|
+
report('此数据表尚未保存,请先处理保存错误。');
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if (assistantBridge.suggestionPersistence.value?.pending() && !(await flush())) return false;
|
|
212
|
+
const current = documentIndex.byId.value.get(tabsLayout.tabTarget(id ?? ''));
|
|
213
|
+
if (!current) return true;
|
|
214
|
+
if ((dirty(current) || layoutPending(current)) && !(await flush())) {
|
|
215
|
+
report('此文档尚未保存,请先处理保存错误。');
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (current.conflict || current.missing) {
|
|
219
|
+
report('请先处理当前文档的冲突或缺失,再替换标签页。');
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
await hooks.beforeCloseDocument?.(current.id);
|
|
223
|
+
if ((dirty(current) || layoutPending(current)) && !(await flush())) {
|
|
224
|
+
report('此文档尚未保存,请先处理保存错误。');
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
if (current.conflict || current.missing) {
|
|
228
|
+
report('请先处理当前文档的冲突或缺失,再替换标签页。');
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function prefetchFile(file: FileEntry) {
|
|
235
|
+
if (!adapter.prefetch || busy.value || isDisposed() || !isMarkdownEntry(file))
|
|
236
|
+
return;
|
|
237
|
+
const entry = fileRegistry.value?.get(file.id);
|
|
238
|
+
if (!entry || entry.pendingCreation) return;
|
|
239
|
+
void adapter.prefetch(entry.path).catch(() => {});
|
|
240
|
+
if (/^[0-9a-f]{6}$/.test(entry.id)) {
|
|
241
|
+
const path = documentLayoutPath(entry.id);
|
|
242
|
+
if (fileRegistry.value?.at(path)) void adapter.prefetch(path).catch(() => {});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function openCached(file: FileEntry, replaceId?: string) {
|
|
247
|
+
if (fileMutations.pending.value) return false;
|
|
248
|
+
const existing = documentIndex.byId.value.get(file.id);
|
|
249
|
+
if (existing) {
|
|
250
|
+
tabsLayout.activateTab(existing.id, replaceId, existing);
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
const entry = fileRegistry.value?.get(file.id);
|
|
254
|
+
if (!entry || entry.pendingCreation) return false;
|
|
255
|
+
if (!isMarkdownEntry(entry)) return false;
|
|
256
|
+
const snapshot = adapter.readCached?.(entry.path);
|
|
257
|
+
if (!snapshot) return false;
|
|
258
|
+
const doc: OpenDocument = {
|
|
259
|
+
id: entry.id,
|
|
260
|
+
path: entry.path,
|
|
261
|
+
content: snapshot.content,
|
|
262
|
+
base: snapshot,
|
|
263
|
+
saving: false,
|
|
264
|
+
missing: false,
|
|
265
|
+
};
|
|
266
|
+
if (/^[0-9a-f]{6}$/.test(entry.id)) {
|
|
267
|
+
const path = documentLayoutPath(entry.id);
|
|
268
|
+
const exists = !!fileRegistry.value?.at(path);
|
|
269
|
+
const base = exists ? adapter.readCached?.(path) : null;
|
|
270
|
+
if (exists && !base) return false;
|
|
271
|
+
try {
|
|
272
|
+
doc.tableLayout = {
|
|
273
|
+
base: base ?? null,
|
|
274
|
+
file: base
|
|
275
|
+
? parseDocumentLayout(base.content, entry.id)
|
|
276
|
+
: { version: 1, fileId: entry.id, tables: [] },
|
|
277
|
+
};
|
|
278
|
+
} catch {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
tabsLayout.activateTab(doc.id, replaceId, doc);
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function recordOpenedDocument(file: FileEntry) {
|
|
287
|
+
recordHelpCompleted('welcome');
|
|
288
|
+
if (
|
|
289
|
+
workspace.value &&
|
|
290
|
+
indexFolderHomes(
|
|
291
|
+
workspace.value.files,
|
|
292
|
+
workspaceSettings.value.folderHomeFileName,
|
|
293
|
+
).get(parentPath(file.path))?.id === file.id
|
|
294
|
+
)
|
|
295
|
+
recordHelpCompleted('folder-home');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function fileEditorHandler(file: FileEntry) {
|
|
299
|
+
if (file.kind !== 'file' || !workspace.value || !isMarkdown(file.path)) return undefined;
|
|
300
|
+
return resolvePluginFileHandler(file.path, 'editor', plugins.pluginFileHandlers.value);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function filePreviewHandler(file: FileEntry) {
|
|
304
|
+
if (
|
|
305
|
+
file.kind !== 'file' ||
|
|
306
|
+
!workspace.value ||
|
|
307
|
+
isMarkdown(file.path) ||
|
|
308
|
+
isDataTableFilePath(file.path)
|
|
309
|
+
)
|
|
310
|
+
return undefined;
|
|
311
|
+
return resolvePluginFileHandler(file.path, 'preview', plugins.pluginFileHandlers.value);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function openFileWithEditorHandler(file: FileEntry, handler: PluginWorkbenchFileHandler) {
|
|
315
|
+
const currentWorkspace = workspace.value;
|
|
316
|
+
if (!currentWorkspace) return false;
|
|
317
|
+
try {
|
|
318
|
+
await plugins.pluginExecutor.invoke(handler.pluginId, 'command', handler.command, {
|
|
319
|
+
workspaceId: currentWorkspace.id,
|
|
320
|
+
fileId: file.id,
|
|
321
|
+
});
|
|
322
|
+
return true;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
report(error);
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function hasMarkdownFileHandler(file: FileEntry) {
|
|
330
|
+
return !!fileEditorHandler(file);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function openFile(
|
|
334
|
+
file: FileEntry,
|
|
335
|
+
options?: { historyIndex?: number; rawSource?: boolean },
|
|
336
|
+
) {
|
|
337
|
+
if (filePreviewHandler(file)) return openAttachment(file, options);
|
|
338
|
+
const editorHandler = options?.rawSource ? undefined : fileEditorHandler(file);
|
|
339
|
+
if (editorHandler && (await openFileWithEditorHandler(file, editorHandler))) return;
|
|
340
|
+
const creationAtRequest = fileOps.getCreationRevision();
|
|
341
|
+
const request = ++fileOpenRevision;
|
|
342
|
+
const paneId = tabsLayout.activePaneId.value;
|
|
343
|
+
const epoch = assistantBridge.assistantEpoch.value;
|
|
344
|
+
const activation = tabsLayout.getActivationRevision();
|
|
345
|
+
const workspaceId = workspace.value?.id;
|
|
346
|
+
const current = () =>
|
|
347
|
+
!isDisposed() &&
|
|
348
|
+
!busy.value &&
|
|
349
|
+
request === fileOpenRevision &&
|
|
350
|
+
creationAtRequest === fileOps.getCreationRevision() &&
|
|
351
|
+
epoch === assistantBridge.assistantEpoch.value &&
|
|
352
|
+
workspaceId === workspace.value?.id &&
|
|
353
|
+
activation === tabsLayout.getActivationRevision();
|
|
354
|
+
try {
|
|
355
|
+
if (file.kind === 'file' && isDataTableFilePath(file.path))
|
|
356
|
+
return openDataTable(file.id, options);
|
|
357
|
+
if (!isMarkdown(file.path) || file.kind !== 'file') return;
|
|
358
|
+
const replaceId =
|
|
359
|
+
tabsLayout.isUtilityTab(activeId.value) &&
|
|
360
|
+
!activeId.value.startsWith('blank:') &&
|
|
361
|
+
!tabsLayout.isNavigationPage(activeId.value)
|
|
362
|
+
? undefined
|
|
363
|
+
: activeId.value;
|
|
364
|
+
const wasOpen = documents.value.some((doc) => doc.id === file.id);
|
|
365
|
+
prefetchFile(file);
|
|
366
|
+
if (!wasOpen && !(await prepareTabReplacement(replaceId))) return;
|
|
367
|
+
if (!current()) return;
|
|
368
|
+
if (!wasOpen) openingDocuments.value[paneId] = { request, tabId: activeId.value };
|
|
369
|
+
if (!openCached(file, replaceId))
|
|
370
|
+
await serial(async () => {
|
|
371
|
+
if (!current()) return;
|
|
372
|
+
await openInternal(file, replaceId, current);
|
|
373
|
+
});
|
|
374
|
+
if (!wasOpen && replaceId && activeId.value === file.id)
|
|
375
|
+
tabsLayout.recordTabNavigation(replaceId, file.id, options?.historyIndex);
|
|
376
|
+
else if (!replaceId && activeId.value === file.id)
|
|
377
|
+
tabsLayout.ensureTabNavigation(file.id, file.id);
|
|
378
|
+
if (tabsLayout.active.value?.id === file.id) recordOpenedDocument(file);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
if (current()) report(e);
|
|
381
|
+
} finally {
|
|
382
|
+
if (openingDocuments.value[paneId]?.request === request) delete openingDocuments.value[paneId];
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function openFileInNewTab(file: FileEntry, options?: { rawSource?: boolean }) {
|
|
387
|
+
try {
|
|
388
|
+
if (filePreviewHandler(file)) return openAttachmentInNewTab(file);
|
|
389
|
+
const editorHandler = options?.rawSource ? undefined : fileEditorHandler(file);
|
|
390
|
+
if (editorHandler && (await openFileWithEditorHandler(file, editorHandler))) return;
|
|
391
|
+
await serial(async () => {
|
|
392
|
+
if (file.kind === 'file' && isDataTableFilePath(file.path)) {
|
|
393
|
+
const target = tableTabId(dataTableFileId(file.id));
|
|
394
|
+
if (tabIds.value.includes(target)) {
|
|
395
|
+
const alias = tabsLayout.newTabAlias(target);
|
|
396
|
+
tabIds.value.push(alias);
|
|
397
|
+
activeId.value = alias;
|
|
398
|
+
tabsLayout.ensureTabNavigation(alias, target);
|
|
399
|
+
tabsLayout.touchNavigation();
|
|
400
|
+
} else await openDataTable(file.id, { newTab: true });
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const target = file.id;
|
|
404
|
+
if (tabIds.value.includes(target)) {
|
|
405
|
+
const alias = tabsLayout.newTabAlias(target);
|
|
406
|
+
tabIds.value.push(alias);
|
|
407
|
+
activeId.value = alias;
|
|
408
|
+
tabsLayout.ensureTabNavigation(alias, target);
|
|
409
|
+
tabsLayout.touchNavigation();
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
await openInternal(file);
|
|
413
|
+
if (activeId.value === file.id) tabsLayout.ensureTabNavigation(file.id, file.id);
|
|
414
|
+
});
|
|
415
|
+
if (tabsLayout.active.value?.id === file.id) recordOpenedDocument(file);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
report(error);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async function openAttachment(
|
|
422
|
+
file: FileEntry,
|
|
423
|
+
options?: { newTab?: boolean; historyIndex?: number },
|
|
424
|
+
) {
|
|
425
|
+
const currentWorkspace = workspace.value;
|
|
426
|
+
if (
|
|
427
|
+
!currentWorkspace ||
|
|
428
|
+
file.kind !== 'file' ||
|
|
429
|
+
isMarkdown(file.path) ||
|
|
430
|
+
isDataTableFilePath(file.path) ||
|
|
431
|
+
!currentWorkspace.files.some((entry) => entry.id === file.id && entry.path === file.path)
|
|
432
|
+
)
|
|
433
|
+
return;
|
|
434
|
+
const workspaceId = currentWorkspace.id;
|
|
435
|
+
const request = ++fileOpenRevision;
|
|
436
|
+
const activation = tabsLayout.getActivationRevision();
|
|
437
|
+
const current = () => request === fileOpenRevision && !busy.value && !isDisposed();
|
|
438
|
+
const target = `attachment:${file.id}`;
|
|
439
|
+
const handler = filePreviewHandler(file);
|
|
440
|
+
const usePlugin =
|
|
441
|
+
!!handler && plugins.pluginViews.value.some((view) => view.key === handler.viewKey);
|
|
442
|
+
const id = usePlugin && handler ? handler.viewKey : target;
|
|
443
|
+
const opened = await openPageTab(id, {
|
|
444
|
+
...options,
|
|
445
|
+
target,
|
|
446
|
+
current: () => current() && tabsLayout.getActivationRevision() === activation,
|
|
447
|
+
});
|
|
448
|
+
if (
|
|
449
|
+
!opened ||
|
|
450
|
+
!usePlugin ||
|
|
451
|
+
!handler ||
|
|
452
|
+
!current() ||
|
|
453
|
+
activeId.value !== id ||
|
|
454
|
+
workspace.value?.id !== workspaceId
|
|
455
|
+
)
|
|
456
|
+
return;
|
|
457
|
+
const previewActivation = tabsLayout.getActivationRevision();
|
|
458
|
+
try {
|
|
459
|
+
await plugins.pluginExecutor.invoke(handler.pluginId, 'command', handler.command, {
|
|
460
|
+
workspaceId,
|
|
461
|
+
fileId: file.id,
|
|
462
|
+
viewAlreadyOpen: true,
|
|
463
|
+
});
|
|
464
|
+
} catch (error) {
|
|
465
|
+
if (
|
|
466
|
+
!current() ||
|
|
467
|
+
tabsLayout.getActivationRevision() !== previewActivation ||
|
|
468
|
+
workspace.value?.id !== workspaceId
|
|
469
|
+
)
|
|
470
|
+
return;
|
|
471
|
+
report(error);
|
|
472
|
+
await openPageTab(target, {
|
|
473
|
+
target,
|
|
474
|
+
current: () => current() && tabsLayout.getActivationRevision() === previewActivation,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function openAttachmentInNewTab(file: FileEntry) {
|
|
480
|
+
return openAttachment(file, { newTab: true });
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
async function openFilesInNewTabsAt(
|
|
484
|
+
ids: readonly string[],
|
|
485
|
+
index: number,
|
|
486
|
+
workspaceId: string,
|
|
487
|
+
) {
|
|
488
|
+
try {
|
|
489
|
+
await serial(async () => {
|
|
490
|
+
if (workspace.value?.id !== workspaceId) return;
|
|
491
|
+
const files = [...new Set(ids)].map((id) =>
|
|
492
|
+
workspace.value!.files.find((file) => file.id === id),
|
|
493
|
+
);
|
|
494
|
+
if (
|
|
495
|
+
!files.length ||
|
|
496
|
+
files.some(
|
|
497
|
+
(file) =>
|
|
498
|
+
!file ||
|
|
499
|
+
file.kind !== 'file' ||
|
|
500
|
+
!(isMarkdown(file.path) || isDataTableFilePath(file.path)),
|
|
501
|
+
)
|
|
502
|
+
)
|
|
503
|
+
return;
|
|
504
|
+
const moving = new Set(
|
|
505
|
+
files.map((file) => (isDataTableFilePath(file!.path) ? tableTabId(file!.id) : file!.id)),
|
|
506
|
+
);
|
|
507
|
+
const following = tabIds.value.slice(Math.max(0, index)).filter((id) => !moving.has(id));
|
|
508
|
+
for (const file of files) {
|
|
509
|
+
await openInternal(file!);
|
|
510
|
+
if (tabsLayout.active.value?.id === file!.id) recordHelpCompleted('welcome');
|
|
511
|
+
const id = isDataTableFilePath(file!.path) ? tableTabId(file!.id) : file!.id;
|
|
512
|
+
tabsLayout.ensureTabNavigation(id, id);
|
|
513
|
+
const target = following.find((tabId) => tabIds.value.includes(tabId));
|
|
514
|
+
if (target) tabsLayout.moveDocument(id, target, 'before');
|
|
515
|
+
else tabsLayout.placeTab(id, tabIds.value.length);
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
} catch (error) {
|
|
519
|
+
report(error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
async function openPageTab(
|
|
524
|
+
id: string,
|
|
525
|
+
options?: { newTab?: boolean; historyIndex?: number; target?: string; current?: () => boolean },
|
|
526
|
+
) {
|
|
527
|
+
if (!workspace.value) return false;
|
|
528
|
+
if (options?.newTab) {
|
|
529
|
+
tabsLayout.activateTab(id);
|
|
530
|
+
tabsLayout.ensureTabNavigation(id, options.target);
|
|
531
|
+
if (options.target) tabsLayout.recordTabNavigation(id, id, undefined, options.target);
|
|
532
|
+
else tabsLayout.touchNavigation();
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
const workspaceId = workspace.value.id;
|
|
536
|
+
const epoch = assistantBridge.assistantEpoch.value;
|
|
537
|
+
const replaceId = activeId.value;
|
|
538
|
+
const wasOpen = tabIds.value.includes(id);
|
|
539
|
+
try {
|
|
540
|
+
if (!wasOpen && !(await prepareTabReplacement(replaceId))) return false;
|
|
541
|
+
return await serial(async () => {
|
|
542
|
+
if (
|
|
543
|
+
workspace.value?.id !== workspaceId ||
|
|
544
|
+
assistantBridge.assistantEpoch.value !== epoch ||
|
|
545
|
+
(options?.current && (!options.current() || activeId.value !== replaceId))
|
|
546
|
+
)
|
|
547
|
+
return false;
|
|
548
|
+
const targetId = activeId.value === replaceId ? replaceId : undefined;
|
|
549
|
+
tabsLayout.activateTab(id, targetId);
|
|
550
|
+
if (!wasOpen && targetId)
|
|
551
|
+
tabsLayout.recordTabNavigation(targetId, id, options?.historyIndex, options?.target);
|
|
552
|
+
else if (options?.target) {
|
|
553
|
+
tabsLayout.ensureTabNavigation(id, options.target);
|
|
554
|
+
tabsLayout.recordTabNavigation(
|
|
555
|
+
id,
|
|
556
|
+
id,
|
|
557
|
+
targetId === id ? options.historyIndex : undefined,
|
|
558
|
+
options.target,
|
|
559
|
+
);
|
|
560
|
+
} else {
|
|
561
|
+
tabsLayout.ensureTabNavigation(id);
|
|
562
|
+
tabsLayout.touchNavigation();
|
|
563
|
+
}
|
|
564
|
+
return true;
|
|
565
|
+
});
|
|
566
|
+
} catch (error) {
|
|
567
|
+
report(error);
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
async function openGraphTab(options?: { newTab?: boolean; historyIndex?: number }) {
|
|
573
|
+
await openPageTab(GRAPH_TAB_ID, options);
|
|
574
|
+
if (workspace.value && activeId.value === GRAPH_TAB_ID) recordHelpCompleted('graph');
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async function openDirectory(
|
|
578
|
+
path: string,
|
|
579
|
+
options?: { newTab?: boolean; historyIndex?: number },
|
|
580
|
+
) {
|
|
581
|
+
if (!workspace.value) return;
|
|
582
|
+
const entry = workspace.value.files.find(
|
|
583
|
+
(file) => file.kind === 'directory' && file.path === path,
|
|
584
|
+
);
|
|
585
|
+
if (path && !entry) return;
|
|
586
|
+
await openPageTab(path ? `directory:${entry!.id}` : 'directory:/', options);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
async function openPluginDetail(
|
|
590
|
+
pluginId: string,
|
|
591
|
+
options?: { newTab?: boolean; historyIndex?: number },
|
|
592
|
+
) {
|
|
593
|
+
if (tabsLayout.pluginDetailManifest(`plugin:${pluginId}`))
|
|
594
|
+
await openPageTab(`plugin:${pluginId}`, options);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
async function openPluginsTab(options?: { newTab?: boolean; historyIndex?: number }) {
|
|
598
|
+
await openPageTab(PLUGINS_TAB_ID, options);
|
|
599
|
+
if (workspace.value && activeId.value === PLUGINS_TAB_ID) recordHelpCompleted('plugins');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function readGraphDocument(
|
|
603
|
+
expectedWorkspace: Pick<Workspace, 'id' | 'path'>,
|
|
604
|
+
file: Pick<FileEntry, 'id'> & Partial<Pick<FileEntry, 'path'>>,
|
|
605
|
+
) {
|
|
606
|
+
return serial(async () => {
|
|
607
|
+
if (
|
|
608
|
+
workspace.value?.id !== expectedWorkspace.id ||
|
|
609
|
+
workspace.value.path !== expectedWorkspace.path
|
|
610
|
+
)
|
|
611
|
+
throw new Error('工作区已切换');
|
|
612
|
+
const entry = fileRegistry.value?.get(file.id);
|
|
613
|
+
if (
|
|
614
|
+
!entry ||
|
|
615
|
+
(file.path !== undefined && entry.path !== file.path) ||
|
|
616
|
+
entry.kind !== 'file' ||
|
|
617
|
+
!isMarkdown(entry.path)
|
|
618
|
+
)
|
|
619
|
+
throw new Error('文档已移动或删除');
|
|
620
|
+
const draft = documentIndex.byId.value.get(file.id);
|
|
621
|
+
if (draft) return draft.content;
|
|
622
|
+
const snapshot = await adapter.read(entry.path);
|
|
623
|
+
return documentIndex.byId.value.get(file.id)?.content ?? snapshot.content;
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function edit(content: string) {
|
|
628
|
+
if (tabsLayout.active.value) editDocument(tabsLayout.active.value.id, content);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function editDocument(id: string, content: string, options: { origin?: 'local' | 'remote' } = {}) {
|
|
632
|
+
const doc = documentIndex.byId.value.get(id);
|
|
633
|
+
if (!doc || doc.conflict || workspace.value?.readOnly || fileRegistry.value?.get(id)?.readOnly)
|
|
634
|
+
return;
|
|
635
|
+
const before = doc.content;
|
|
636
|
+
doc.content = content;
|
|
637
|
+
if (!doc.creating) doc.error = undefined;
|
|
638
|
+
clearTimeout(saveTimer);
|
|
639
|
+
saveTimer = setTimeout(() => {
|
|
640
|
+
void flush();
|
|
641
|
+
}, 600);
|
|
642
|
+
if (options.origin !== 'remote')
|
|
643
|
+
helpEdits.record(id, before, content, referenceTargets.value);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function receiveDocument(
|
|
647
|
+
id: string,
|
|
648
|
+
content: string,
|
|
649
|
+
options: { origin?: 'local' | 'remote' } = {},
|
|
650
|
+
) {
|
|
651
|
+
const doc = documentIndex.byId.value.get(id);
|
|
652
|
+
if (!doc || doc.conflict || doc.missing) return;
|
|
653
|
+
const before = doc.content;
|
|
654
|
+
doc.content = content;
|
|
655
|
+
clearTimeout(saveTimer);
|
|
656
|
+
saveTimer = setTimeout(() => {
|
|
657
|
+
void flush();
|
|
658
|
+
}, 600);
|
|
659
|
+
if (options.origin === 'local')
|
|
660
|
+
helpEdits.record(id, before, content, referenceTargets.value);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function editTableLayout(id: string, tables: TableLayout[]) {
|
|
664
|
+
const doc = documentIndex.byId.value.get(id);
|
|
665
|
+
if (!doc?.tableLayout || doc.conflict || doc.missing || workspace.value?.readOnly) return;
|
|
666
|
+
doc.tableLayout.file = {
|
|
667
|
+
...doc.tableLayout.file,
|
|
668
|
+
tables: JSON.parse(JSON.stringify(tables)),
|
|
669
|
+
};
|
|
670
|
+
doc.tableLayout.error = undefined;
|
|
671
|
+
clearTimeout(saveTimer);
|
|
672
|
+
saveTimer = setTimeout(() => {
|
|
673
|
+
void flush();
|
|
674
|
+
}, 300);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
async function flush(): Promise<boolean> {
|
|
678
|
+
await fileMutations.flush();
|
|
679
|
+
return flushDocuments();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
async function flushDocuments(): Promise<boolean> {
|
|
683
|
+
await fileOps.awaitCreationChain();
|
|
684
|
+
try {
|
|
685
|
+
await assistantBridge.suggestionPersistence.value?.flush();
|
|
686
|
+
} catch (error) {
|
|
687
|
+
report(error);
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
clearTimeout(saveTimer);
|
|
691
|
+
const saved = await serial(async () => {
|
|
692
|
+
const tablesSaved = await dataTables.persistAll();
|
|
693
|
+
for (const doc of documents.value) {
|
|
694
|
+
await saveInternal(doc);
|
|
695
|
+
await saveTableLayout(doc);
|
|
696
|
+
}
|
|
697
|
+
return (
|
|
698
|
+
tablesSaved &&
|
|
699
|
+
documents.value.every((doc) => (!dirty(doc) || !!doc.conflict) && !layoutPending(doc))
|
|
700
|
+
);
|
|
701
|
+
});
|
|
702
|
+
await journal.flush();
|
|
703
|
+
return saved;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
async function close(id: string) {
|
|
707
|
+
if (isTableTab(id) && !(await flush())) {
|
|
708
|
+
report('数据表尚有未保存的修改,请先处理保存错误。');
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const pane = tabsLayout.panes.value.find((pane) => pane.tabs.includes(id));
|
|
712
|
+
const nextTab = () => {
|
|
713
|
+
const candidate = tabsLayout.panes.value
|
|
714
|
+
.find((item) => item.id === pane?.id)
|
|
715
|
+
?.tabs.find((tabId) => tabId !== id && tabIds.value.includes(tabId));
|
|
716
|
+
return candidate ?? tabIds.value.find((tabId) => tabId !== id) ?? '';
|
|
717
|
+
};
|
|
718
|
+
if (tabsLayout.isUtilityTab(id)) {
|
|
719
|
+
tabIds.value = tabIds.value.filter((tabId) => tabId !== id);
|
|
720
|
+
tabsLayout.removeTabAlias(id);
|
|
721
|
+
tabsLayout.removeTabNavigation(id);
|
|
722
|
+
if (activeId.value === id) activeId.value = nextTab();
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (!(await flush())) {
|
|
726
|
+
report('此文档尚有未保存的修改或建议,请先处理保存错误。');
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
await hooks.beforeCloseDocument?.(tabsLayout.tabTarget(id));
|
|
731
|
+
} catch (error) {
|
|
732
|
+
report(error);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const target = tabsLayout.tabTarget(id);
|
|
736
|
+
const doc = documentIndex.byId.value.get(target);
|
|
737
|
+
if (doc && ((dirty(doc) && !doc.conflict) || layoutPending(doc))) {
|
|
738
|
+
report('此文档尚未保存,请先另存副本或解决保存错误。');
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
tabIds.value = tabIds.value.filter((tabId) => tabId !== id);
|
|
742
|
+
tabsLayout.removeTabAlias(id);
|
|
743
|
+
tabsLayout.removeTabNavigation(id);
|
|
744
|
+
if (!tabIds.value.some((tabId) => tabsLayout.tabTarget(tabId) === target))
|
|
745
|
+
documents.value = documents.value.filter((d) => d.id !== target);
|
|
746
|
+
if (activeId.value === id) activeId.value = nextTab();
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
async function resolveConflict(doc: OpenDocument, openCopy: boolean) {
|
|
750
|
+
await serial(async () => {
|
|
751
|
+
if (!doc.conflict) return;
|
|
752
|
+
const copy = doc.conflict.copyPath;
|
|
753
|
+
const latest = await adapter.read(doc.path);
|
|
754
|
+
doc.base = latest;
|
|
755
|
+
doc.content = latest.content;
|
|
756
|
+
doc.conflict = undefined;
|
|
757
|
+
doc.missing = false;
|
|
758
|
+
doc.error = undefined;
|
|
759
|
+
if (openCopy) {
|
|
760
|
+
workspace.value = await adapter.refresh();
|
|
761
|
+
const file = fileRegistry.value?.at(copy);
|
|
762
|
+
if (file) {
|
|
763
|
+
await openInternal(file);
|
|
764
|
+
tabsLayout.ensureTabNavigation(file.id, file.id);
|
|
765
|
+
tabsLayout.touchNavigation();
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}).catch(report);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function clearSaveTimer() {
|
|
772
|
+
clearTimeout(saveTimer);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
return {
|
|
776
|
+
dataTableFileId,
|
|
777
|
+
openDataTable,
|
|
778
|
+
createDataTable,
|
|
779
|
+
renameDataTable,
|
|
780
|
+
hydrateDocumentLayout,
|
|
781
|
+
saveTableLayout,
|
|
782
|
+
readOpenDocument,
|
|
783
|
+
openInternal,
|
|
784
|
+
prefetchFile,
|
|
785
|
+
hasMarkdownFileHandler,
|
|
786
|
+
openFile,
|
|
787
|
+
openFileInNewTab,
|
|
788
|
+
openAttachment,
|
|
789
|
+
openAttachmentInNewTab,
|
|
790
|
+
openFilesInNewTabsAt,
|
|
791
|
+
openPageTab,
|
|
792
|
+
openGraphTab,
|
|
793
|
+
openDirectory,
|
|
794
|
+
openPluginDetail,
|
|
795
|
+
openPluginsTab,
|
|
796
|
+
readGraphDocument,
|
|
797
|
+
edit,
|
|
798
|
+
editDocument,
|
|
799
|
+
receiveDocument,
|
|
800
|
+
editTableLayout,
|
|
801
|
+
flush,
|
|
802
|
+
flushDocuments,
|
|
803
|
+
close,
|
|
804
|
+
resolveConflict,
|
|
805
|
+
clearSaveTimer,
|
|
806
|
+
};
|
|
807
|
+
}
|