@tano.page/workbench 0.14.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 +50 -16
- package/src/App.vue +82 -752
- package/src/appearance/appearance.ts +14 -4
- package/src/appearance/components/ThemePresetPreview.vue +52 -8
- package/src/appearance/interface-font.ts +99 -0
- package/src/appearance/theme.ts +26 -10
- package/src/appearance/use-interface-font.ts +30 -0
- package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
- package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
- package/src/assets/mail-provider-icons/gmail.svg +1 -0
- package/src/assets/mail-provider-icons/icloud.svg +12 -0
- package/src/assets/mail-provider-icons/netease-126.svg +5 -0
- package/src/assets/mail-provider-icons/netease-163.svg +5 -0
- package/src/assets/mail-provider-icons/qq.svg +9 -0
- package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
- 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/AssistantChangeList.vue +98 -21
- package/src/assistant/components/AssistantPanel.vue +425 -8
- package/src/assistant/components/PluginToolProposalCard.vue +235 -0
- package/src/assistant/connection-actions.ts +237 -0
- package/src/assistant/document-mentions.ts +1 -33
- package/src/assistant/engine.ts +1 -532
- package/src/assistant/execution.ts +6 -33
- package/src/assistant/files.ts +5 -13
- package/src/assistant/hash.ts +1 -4
- package/src/assistant/inbox.ts +1 -148
- package/src/assistant/language.ts +10 -37
- package/src/assistant/mention-autocomplete.ts +69 -0
- package/src/assistant/plugin-bridge-builder.ts +146 -0
- package/src/assistant/prompts.ts +1 -58
- package/src/assistant/proposal-actions.ts +336 -0
- package/src/assistant/results.ts +20 -86
- package/src/assistant/store.ts +167 -327
- package/src/assistant/structures.ts +1 -155
- package/src/assistant/tasks.ts +8 -96
- package/src/assistant/tool-rules.ts +1 -7
- package/src/assistant/workspace-bridge.ts +1 -1
- package/src/composables/use-document-actions.ts +38 -20
- package/src/composables/use-file-tree-controller.ts +7 -12
- package/src/composables/use-workbench-help.ts +177 -0
- package/src/composables/use-workbench-history.ts +2 -4
- package/src/composables/use-workbench-lifecycle.ts +249 -0
- package/src/composables/use-workbench-modals.ts +6 -1
- package/src/composables/use-workbench-outline.ts +0 -5
- package/src/composables/use-workbench-settings.ts +185 -0
- package/src/composables/use-workbench-shortcuts.ts +40 -1021
- package/src/composables/use-workbench-views.ts +325 -0
- package/src/data-tables/data-tables.ts +1 -2
- package/src/documents/components/DocumentActionMenu.vue +279 -0
- package/src/documents/components/DocumentHistoryPanel.vue +3 -1
- 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/features.ts +1 -0
- package/src/files/components/FileMetadataPanel.vue +49 -15
- package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
- package/src/fonts/Inter-Latin.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
- package/src/help/help-milestones.ts +3 -5
- package/src/i18n/locale-catalogs.ts +7 -6
- package/src/i18n/locale-registry.ts +8 -6
- package/src/i18n/locales/de-DE.json +371 -3
- package/src/i18n/locales/en-US.json +371 -2
- package/src/i18n/locales/es-ES.json +371 -3
- package/src/i18n/locales/ja-JP.json +370 -2
- package/src/i18n/locales/zh-TW.json +370 -2
- package/src/mail/components/MailAccountDialog.vue +450 -0
- package/src/mail/components/MailComposerDialog.vue +326 -0
- package/src/mail/components/MailProviderIcon.vue +30 -0
- package/src/mail/components/MailWorkspaceView.vue +821 -0
- package/src/mail/components/SidebarMail.vue +134 -0
- package/src/mail/mail-avatar.ts +17 -0
- package/src/mail/mail-bridge.ts +68 -0
- package/src/mail/mail-calendar.ts +208 -0
- package/src/mail/mail-markdown.ts +195 -0
- package/src/mail/types.ts +226 -0
- package/src/objects/components/ObjectDetailModal.vue +1001 -0
- package/src/objects/content-references.ts +6 -56
- package/src/objects/wiki-links.ts +1 -48
- package/src/objects/workspace-objects.ts +3 -4
- package/src/plan-sync/types.ts +6 -3
- package/src/plans/calendar-interaction.ts +194 -0
- package/src/plans/calendar.ts +65 -9
- package/src/plans/components/CalendarAgendaView.vue +165 -0
- package/src/plans/components/CalendarDayPopover.vue +172 -39
- 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 +264 -748
- package/src/plans/components/CalendarYearView.vue +138 -0
- package/src/plans/components/PlanArchiveDialog.vue +295 -0
- package/src/plans/components/PlanConnectionsDialog.vue +1 -1
- package/src/plans/components/PlanDateField.vue +6 -4
- package/src/plans/components/PlanDetailPanel.vue +227 -32
- package/src/plans/components/PlanEventList.vue +16 -4
- package/src/plans/components/SidebarPlan.vue +22 -15
- package/src/plans/components/TaskRepeatControls.vue +169 -30
- 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/plans/local-reminders.ts +149 -0
- package/src/plans/personal-plans.ts +10 -1
- package/src/plans/plan-date.ts +8 -1
- package/src/plans/plan-migration.ts +95 -0
- package/src/plans/recurrence.ts +95 -0
- package/src/plans/task-repeat.ts +8 -8
- package/src/plans/timeline-layout.ts +92 -0
- package/src/plugins/assistant-bridge.ts +520 -0
- package/src/plugins/attachment-reader.ts +3 -1
- package/src/plugins/cache-storage.ts +42 -2
- package/src/plugins/components/PluginAutomations.vue +3 -3
- package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
- package/src/plugins/components/PluginChangeSummary.vue +16 -3
- package/src/plugins/components/PluginConnections.vue +1 -1
- package/src/plugins/components/PluginCustomView.vue +2 -2
- package/src/plugins/components/PluginDetailPage.vue +136 -57
- package/src/plugins/components/PluginDeveloperArea.vue +192 -0
- package/src/plugins/components/PluginDocumentSlot.vue +63 -0
- package/src/plugins/components/PluginExplorer.vue +21 -25
- package/src/plugins/components/PluginImportDialog.vue +410 -0
- package/src/plugins/components/PluginInstaller.vue +273 -288
- package/src/plugins/components/PluginListItem.vue +3 -0
- package/src/plugins/components/PluginMaintenance.vue +37 -34
- package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
- package/src/plugins/components/PluginRuntimePanel.vue +3 -3
- package/src/plugins/components/PluginSettingsForm.vue +112 -0
- package/src/plugins/components/PluginStatusBar.vue +161 -0
- package/src/plugins/components/PluginSurface.vue +18 -6
- package/src/plugins/components/PluginUiDialog.vue +452 -0
- 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/excalidraw/bundle.tano-plugin.json +1 -1
- package/src/plugins/excalidraw/manifest.json +12 -1
- package/src/plugins/host.ts +662 -43
- package/src/plugins/native.ts +2 -10
- package/src/plugins/overlay-mapping.ts +125 -0
- package/src/plugins/packages.ts +73 -1
- package/src/plugins/plugin-data.ts +2 -3
- package/src/plugins/plugin-permissions.ts +57 -0
- package/src/plugins/plugin-rpc-router.ts +558 -0
- package/src/plugins/plugin-sdk.ts +1 -94
- package/src/plugins/plugin-ui-dialogs.ts +167 -0
- package/src/plugins/policy.ts +53 -3
- package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
- package/src/plugins/presentation-preview/manifest.json +2 -1
- package/src/plugins/queries.ts +1 -73
- package/src/plugins/sandbox.ts +15 -1
- package/src/plugins/use-plugin-actions.ts +67 -20
- package/src/plugins/user-plugins.ts +254 -0
- package/src/plugins/view-header.ts +2 -7
- package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
- package/src/plugins/word-preview/manifest.json +13 -1
- package/src/plugins/workbench.ts +175 -2
- package/src/plugins/worker.js +105 -8
- package/src/plugins/workspace-plugin-runtime.ts +23 -7
- package/src/plugins/workspace-plugins.ts +212 -21
- package/src/runtime.ts +103 -4
- package/src/settings/components/SettingsAppearancePage.vue +46 -0
- package/src/settings/components/SettingsDocumentsPage.vue +0 -1
- 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/components/settings-search.ts +2 -3
- 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/SidebarNavigation.vue +22 -2
- package/src/shell/components/WorkbenchContextMenus.vue +58 -34
- package/src/shell/components/WorkbenchModals.vue +47 -62
- package/src/shell/components/WorkbenchPanes.vue +371 -1342
- package/src/shell/components/WorkbenchSidebar.vue +486 -0
- package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
- package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
- 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 +531 -1153
- package/src/shell/workbench-async-components.ts +14 -5
- package/src/shell/workbench-context.ts +30 -3
- package/src/stores/mail.ts +414 -0
- package/src/stores/plan-sync.ts +2 -1
- package/src/stores/plans.ts +2 -9
- package/src/stores/workspace-document-io.ts +807 -0
- package/src/stores/workspace-file-ops.ts +1 -1
- package/src/stores/workspace-knowledge.ts +2 -114
- package/src/stores/workspace-lifecycle.ts +459 -0
- package/src/stores/workspace-plugins-state.ts +254 -259
- package/src/stores/workspace-session.ts +287 -0
- package/src/stores/workspace-tabs-layout.ts +6 -44
- package/src/stores/workspace-types.ts +50 -0
- package/src/stores/workspace.ts +184 -1363
- package/src/styles/agent-diff-modals.css +0 -7
- package/src/styles/dark-theme.css +3 -3
- package/src/styles/inspector.css +0 -59
- package/src/styles/layout-themes.css +346 -0
- package/src/styles/mail.css +1568 -0
- package/src/styles/mobile.css +2 -2
- package/src/styles/recent-and-media.css +0 -17
- package/src/styles/theme-contract.css +3 -3
- package/src/styles/workbench-shell.css +110 -17
- package/src/styles/workspace-states.css +9 -33
- package/src/styles.css +0 -1
- package/src/tabs/components/DesktopTabs.vue +19 -14
- package/src/tabs/components/NewTabPicker.vue +10 -4
- package/src/tabs/tab-label.ts +0 -1
- 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/WorkspaceGeneralSettings.vue +0 -13
- package/src/workspace/components/WorkspaceIconPicker.vue +30 -7
- package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
- package/src/workspace/workspace-comments.ts +11 -151
- package/src/workspace/workspace-welcome.ts +1 -1
- package/src/assistant/locales/de-DE.json +0 -126
- package/src/assistant/locales/en-US.json +0 -126
- package/src/assistant/locales/es-ES.json +0 -126
- package/src/assistant/locales/ja-JP.json +0 -126
- package/src/assistant/locales/zh-CN.json +0 -126
- package/src/assistant/locales/zh-TW.json +0 -126
- package/src/assistant/task-prompts.json +0 -39
- package/src/documents/components/FormulaMenu.vue +0 -50
- package/src/files/components/FileDatabasePage.vue +0 -152
- package/src/files/components/FolderHomeIcon.vue +0 -12
- package/src/objects/components/ObjectDatabasePage.vue +0 -100
- package/src/objects/components/ObjectPanel.vue +0 -554
- package/src/plans/components/PersonalPlanDialog.vue +0 -105
- package/src/shell/components/WorkspaceViewPage.vue +0 -127
- package/src/shell/components/WorkspaceViewTab.vue +0 -24
- package/src/styles/object-panel.css +0 -163
- package/src/workspace/components/GitInspectionPanel.vue +0 -35
- package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
- package/src/workspace/welcome-slogans.ts +0 -11
- package/src/workspace/workspace-git.ts +0 -35
- package/src/workspace/workspace-sync.ts +0 -46
- package/src/workspace/workspace-views.ts +0 -48
|
@@ -23,7 +23,7 @@ import { t } from '../i18n/i18n';
|
|
|
23
23
|
import type { FileMutationPreview, optimisticFiles } from '../files/optimistic-files';
|
|
24
24
|
import { writeWorkspaceImport } from '../workspace/workspace-import';
|
|
25
25
|
import type { WorkspaceSettings } from '../workspace/workspace-settings';
|
|
26
|
-
import type { Activity } from './workspace';
|
|
26
|
+
import type { Activity } from './workspace-types';
|
|
27
27
|
|
|
28
28
|
export interface WorkspaceFileOpsDeps {
|
|
29
29
|
adapter: WorkspaceAdapter;
|
|
@@ -2,10 +2,7 @@ import { computed, onScopeDispose, ref, type Ref } from 'vue';
|
|
|
2
2
|
import type { WorkspaceCapabilities } from '@tano/editor/runtime';
|
|
3
3
|
import {
|
|
4
4
|
assetTargets,
|
|
5
|
-
basename,
|
|
6
5
|
coreRelationTypes,
|
|
7
|
-
defaultFileDatabaseQuery,
|
|
8
|
-
defaultObjectViewQuery,
|
|
9
6
|
documentTargets,
|
|
10
7
|
FileRegistry,
|
|
11
8
|
isMarkdown,
|
|
@@ -14,14 +11,11 @@ import {
|
|
|
14
11
|
objectDirectory,
|
|
15
12
|
objectTypeRegistry,
|
|
16
13
|
parseObject,
|
|
17
|
-
parseWorkspaceView,
|
|
18
14
|
referenceKey,
|
|
19
|
-
RelationIndex,
|
|
20
15
|
relationKey,
|
|
21
16
|
validateObjectProperties,
|
|
22
17
|
validateRelation,
|
|
23
18
|
WorkspaceAccessRevokedError,
|
|
24
|
-
workspaceViewPath,
|
|
25
19
|
type FileSnapshot,
|
|
26
20
|
type ReferenceIdentity,
|
|
27
21
|
type ReferenceTarget,
|
|
@@ -29,7 +23,6 @@ import {
|
|
|
29
23
|
type WorkspaceAdapter,
|
|
30
24
|
type WorkspaceObject,
|
|
31
25
|
type WorkspaceRelation,
|
|
32
|
-
type WorkspaceViewDefinition,
|
|
33
26
|
} from '@tano/protocol';
|
|
34
27
|
import { contentReferences, referenceContext } from '../objects/content-references';
|
|
35
28
|
import type { useDocumentIndex } from '../documents/document-index';
|
|
@@ -47,8 +40,7 @@ import { loadObjects, saveObject, type ObjectRecord } from '../objects/workspace
|
|
|
47
40
|
import type { InstalledObjectPlugin } from '../plugins/workspace-plugins';
|
|
48
41
|
import { loadRelations, saveRelationChange, type RelationChange } from '../objects/workspace-relations';
|
|
49
42
|
import { loadTemplates, saveTemplate, type DocumentTemplate } from '../workspace/workspace-templates';
|
|
50
|
-
import {
|
|
51
|
-
import type { Activity } from './workspace';
|
|
43
|
+
import type { Activity } from './workspace-types';
|
|
52
44
|
|
|
53
45
|
export interface WorkspaceKnowledgeDeps {
|
|
54
46
|
adapter: WorkspaceAdapter;
|
|
@@ -67,12 +59,11 @@ export interface WorkspaceKnowledgeDeps {
|
|
|
67
59
|
change?: Activity['change'],
|
|
68
60
|
) => void;
|
|
69
61
|
loadWorkspacePart: (
|
|
70
|
-
part: 'plugins' | 'objects' | '
|
|
62
|
+
part: 'plugins' | 'objects' | 'relations',
|
|
71
63
|
load: () => Promise<unknown>,
|
|
72
64
|
) => Promise<void>;
|
|
73
65
|
refreshPlugins: (current: Workspace) => Promise<void>;
|
|
74
66
|
disposePluginExecutor: () => void;
|
|
75
|
-
openWorkspaceView: (id: string, options?: { newTab?: boolean; historyIndex?: number }) => Promise<void>;
|
|
76
67
|
}
|
|
77
68
|
|
|
78
69
|
export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
@@ -90,11 +81,8 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
90
81
|
loadWorkspacePart,
|
|
91
82
|
refreshPlugins,
|
|
92
83
|
disposePluginExecutor,
|
|
93
|
-
openWorkspaceView,
|
|
94
84
|
} = deps;
|
|
95
85
|
|
|
96
|
-
const workspaceViews = ref<WorkspaceViewRecord[]>([]);
|
|
97
|
-
const workspaceViewErrors = ref<string[]>([]);
|
|
98
86
|
const objects = ref<ObjectRecord[]>([]);
|
|
99
87
|
const objectErrors = ref<string[]>([]);
|
|
100
88
|
const relations = ref<WorkspaceRelation[]>([]);
|
|
@@ -107,7 +95,6 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
107
95
|
.filter((item) => item.enabled)
|
|
108
96
|
.flatMap((item) => item.manifest.relationTypes),
|
|
109
97
|
]);
|
|
110
|
-
const relationIndex = computed(() => new RelationIndex(relations.value));
|
|
111
98
|
const objectDefinitions = ref(objectTypeRegistry.list());
|
|
112
99
|
onScopeDispose(
|
|
113
100
|
objectTypeRegistry.subscribe(() => {
|
|
@@ -133,7 +120,6 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
133
120
|
objectDefinitions.value.find((entry) => entry.type === object.type) ??
|
|
134
121
|
objectTypeRegistry.get(object.type);
|
|
135
122
|
if (definition?.storage !== 'record') return false;
|
|
136
|
-
if (definition.retired) return true;
|
|
137
123
|
try {
|
|
138
124
|
validateObjectProperties(object.type, object.properties);
|
|
139
125
|
return true;
|
|
@@ -219,16 +205,6 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
219
205
|
objects.value = loaded.records;
|
|
220
206
|
objectErrors.value = loaded.errors;
|
|
221
207
|
}),
|
|
222
|
-
loadWorkspacePart('views', async () => {
|
|
223
|
-
try {
|
|
224
|
-
const loadedViews = await loadWorkspaceViews(adapter, current);
|
|
225
|
-
workspaceViews.value = loadedViews.records;
|
|
226
|
-
workspaceViewErrors.value = loadedViews.errors;
|
|
227
|
-
} catch (error) {
|
|
228
|
-
workspaceViews.value = [];
|
|
229
|
-
workspaceViewErrors.value = [`无法读取工作区视图:${String(error)}`];
|
|
230
|
-
}
|
|
231
|
-
}),
|
|
232
208
|
loadWorkspacePart('relations', async () => {
|
|
233
209
|
try {
|
|
234
210
|
const loadedRelations = await loadRelations(adapter, current);
|
|
@@ -279,86 +255,6 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
279
255
|
return saved;
|
|
280
256
|
});
|
|
281
257
|
|
|
282
|
-
// Workspace databases / views
|
|
283
|
-
async function createObjectDatabase() {
|
|
284
|
-
const scope = workspace.value?.id;
|
|
285
|
-
const id = `objects-${crypto.randomUUID()}`;
|
|
286
|
-
await serial(async () => {
|
|
287
|
-
if (!scope || workspace.value?.id !== scope) throw new Error(t('工作区已切换'));
|
|
288
|
-
writable();
|
|
289
|
-
if (!capabilities.value.features.objectReferences)
|
|
290
|
-
throw new Error('「工作区对象与引用」已关闭');
|
|
291
|
-
const view = parseWorkspaceView(
|
|
292
|
-
JSON.stringify({
|
|
293
|
-
version: 1,
|
|
294
|
-
layer: 'view',
|
|
295
|
-
workspaceId: scope,
|
|
296
|
-
id,
|
|
297
|
-
name: '对象数据库',
|
|
298
|
-
kind: 'objects',
|
|
299
|
-
sources: [],
|
|
300
|
-
objectDatabase: defaultObjectViewQuery(),
|
|
301
|
-
}),
|
|
302
|
-
);
|
|
303
|
-
await adapter.create(workspaceViewPath(id), JSON.stringify(view, null, 2) + '\n');
|
|
304
|
-
workspace.value = await adapter.refresh();
|
|
305
|
-
await refreshObjects();
|
|
306
|
-
});
|
|
307
|
-
await openWorkspaceView(id, { newTab: true });
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async function createFileDatabase(directory = '') {
|
|
311
|
-
const scope = workspace.value?.id;
|
|
312
|
-
const id = `files-${crypto.randomUUID()}`;
|
|
313
|
-
await serial(async () => {
|
|
314
|
-
if (!scope || workspace.value?.id !== scope) throw new Error(t('工作区已切换'));
|
|
315
|
-
writable();
|
|
316
|
-
if (
|
|
317
|
-
directory &&
|
|
318
|
-
!workspace.value.files.some((f) => f.kind === 'directory' && f.path === directory)
|
|
319
|
-
)
|
|
320
|
-
throw new Error('目录已不存在');
|
|
321
|
-
const view = parseWorkspaceView(
|
|
322
|
-
JSON.stringify({
|
|
323
|
-
version: 1,
|
|
324
|
-
layer: 'view',
|
|
325
|
-
workspaceId: scope,
|
|
326
|
-
id,
|
|
327
|
-
name: `${directory ? basename(directory) : workspace.value.name} · 文件数据库`,
|
|
328
|
-
kind: 'files',
|
|
329
|
-
sources: [],
|
|
330
|
-
database: defaultFileDatabaseQuery(directory),
|
|
331
|
-
}),
|
|
332
|
-
);
|
|
333
|
-
await adapter.create(workspaceViewPath(id), JSON.stringify(view, null, 2) + '\n');
|
|
334
|
-
workspace.value = await adapter.refresh();
|
|
335
|
-
await refreshObjects();
|
|
336
|
-
});
|
|
337
|
-
await openWorkspaceView(id, { newTab: true });
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const saveFileDatabase = (view: WorkspaceViewDefinition, base: FileSnapshot) =>
|
|
341
|
-
serial(async () => {
|
|
342
|
-
if (workspace.value?.id !== view.workspaceId) throw new Error(t('工作区已切换'));
|
|
343
|
-
writable();
|
|
344
|
-
const checked = parseWorkspaceView(JSON.stringify(view));
|
|
345
|
-
const result = await adapter.write(
|
|
346
|
-
workspaceViewPath(checked.id),
|
|
347
|
-
JSON.stringify(checked, null, 2) + '\n',
|
|
348
|
-
base.hash,
|
|
349
|
-
);
|
|
350
|
-
if (result.status !== 'saved') {
|
|
351
|
-
const copy = `.tano/conflicts/view-${checked.id}-${crypto.randomUUID()}.tano.json`;
|
|
352
|
-
await adapter.create(copy, JSON.stringify(checked, null, 2) + '\n');
|
|
353
|
-
throw new Error(
|
|
354
|
-
t('视图已被外部修改或删除,外部版本未覆盖;当前设置已保留在 {0}', [copy]),
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
workspace.value = await adapter.refresh();
|
|
358
|
-
await refreshObjects();
|
|
359
|
-
return result.snapshot;
|
|
360
|
-
});
|
|
361
|
-
|
|
362
258
|
// Relations CRUD
|
|
363
259
|
async function editRelation(change: RelationChange, expectedWorkspace: string) {
|
|
364
260
|
return serial(async () => {
|
|
@@ -704,16 +600,12 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
704
600
|
function resetKnowledge(clearErrors = false) {
|
|
705
601
|
objects.value = [];
|
|
706
602
|
objectErrors.value = [];
|
|
707
|
-
workspaceViews.value = [];
|
|
708
|
-
workspaceViewErrors.value = [];
|
|
709
603
|
relations.value = [];
|
|
710
604
|
relationBase = null;
|
|
711
605
|
if (clearErrors) relationError.value = '';
|
|
712
606
|
}
|
|
713
607
|
|
|
714
608
|
return {
|
|
715
|
-
workspaceViews,
|
|
716
|
-
workspaceViewErrors,
|
|
717
609
|
objects,
|
|
718
610
|
objectErrors,
|
|
719
611
|
objectDefinitions,
|
|
@@ -721,7 +613,6 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
721
613
|
relationError,
|
|
722
614
|
getRelationBase: () => relationBase,
|
|
723
615
|
relationDefinitions,
|
|
724
|
-
relationIndex,
|
|
725
616
|
referenceTargets,
|
|
726
617
|
referenceRevision,
|
|
727
618
|
referenceDocumentCache,
|
|
@@ -729,9 +620,6 @@ export function createWorkspaceKnowledge(deps: WorkspaceKnowledgeDeps) {
|
|
|
729
620
|
refreshObjects,
|
|
730
621
|
readFileMetadata,
|
|
731
622
|
updateFileMetadata,
|
|
732
|
-
createObjectDatabase,
|
|
733
|
-
createFileDatabase,
|
|
734
|
-
saveFileDatabase,
|
|
735
623
|
createRelation,
|
|
736
624
|
removeRelation,
|
|
737
625
|
setRelationSource,
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
basename,
|
|
4
|
+
isMarkdown,
|
|
5
|
+
isWorkspaceInternalPath,
|
|
6
|
+
type FileRegistry,
|
|
7
|
+
type FileSnapshot,
|
|
8
|
+
type RecentWorkspace,
|
|
9
|
+
type Workspace,
|
|
10
|
+
type WorkspaceAdapter,
|
|
11
|
+
type WorkspaceSession,
|
|
12
|
+
} from '@tano/protocol';
|
|
13
|
+
import type { createWorkspaceAssistantBridge } from '../assistant/workspace-bridge';
|
|
14
|
+
import type { createDataTableController } from '../data-tables/data-table-controller';
|
|
15
|
+
import type { OpenDocument } from '../documents/document-session';
|
|
16
|
+
import type { InstalledObjectPlugin } from '../plugins/workspace-plugins';
|
|
17
|
+
import { layoutDirty } from '../workspace/workspace-document-layout';
|
|
18
|
+
import type { WorkspaceLifecycle } from '../workspace/workspace-lifecycle';
|
|
19
|
+
import { readStartupWorkspace, rememberStartupWorkspace } from '../workspace/workspace-startup';
|
|
20
|
+
import { addWorkspaceWelcome, workspaceWelcomePath } from '../workspace/workspace-welcome';
|
|
21
|
+
import type { createWorkspaceKnowledge } from './workspace-knowledge';
|
|
22
|
+
import type { createWorkspacePluginsState } from './workspace-plugins-state';
|
|
23
|
+
import type { createWorkspacePolicy } from './workspace-policy';
|
|
24
|
+
import type { createWorkspaceSession } from './workspace-session';
|
|
25
|
+
import type { createWorkspaceTabsLayout } from './workspace-tabs-layout';
|
|
26
|
+
import type { Activity, WorkspaceLifecycleHooks, WorkspaceLoadingState } from './workspace-types';
|
|
27
|
+
|
|
28
|
+
export interface WorkspaceLifecycleDeps {
|
|
29
|
+
adapter: WorkspaceAdapter;
|
|
30
|
+
isDemo: boolean;
|
|
31
|
+
isWeb: boolean;
|
|
32
|
+
remembersStartupWorkspace: boolean;
|
|
33
|
+
workspace: Ref<Workspace | null>;
|
|
34
|
+
fileRegistry: Ref<FileRegistry | null>;
|
|
35
|
+
documents: Ref<OpenDocument[]>;
|
|
36
|
+
tabIds: Ref<string[]>;
|
|
37
|
+
tabAliases: Ref<Map<string, string>>;
|
|
38
|
+
activeId: Ref<string>;
|
|
39
|
+
installedPlugins: Ref<InstalledObjectPlugin[]>;
|
|
40
|
+
busy: Ref<boolean>;
|
|
41
|
+
openingWorkspace: Ref<boolean>;
|
|
42
|
+
workspaceLoading: Ref<WorkspaceLoadingState>;
|
|
43
|
+
restoringDocuments: Ref<Record<string, string>>;
|
|
44
|
+
openingDocuments: Ref<Record<string, { request: number; tabId: string }>>;
|
|
45
|
+
activities: Ref<Activity[]>;
|
|
46
|
+
fatal: Ref<string>;
|
|
47
|
+
recent: Ref<RecentWorkspace[]>;
|
|
48
|
+
sessionError: Ref<string>;
|
|
49
|
+
workspaceLifecycle: WorkspaceLifecycle;
|
|
50
|
+
stopWatching: () => void;
|
|
51
|
+
dataTables: ReturnType<typeof createDataTableController>;
|
|
52
|
+
policy: ReturnType<typeof createWorkspacePolicy>;
|
|
53
|
+
knowledge: ReturnType<typeof createWorkspaceKnowledge>;
|
|
54
|
+
plugins: ReturnType<typeof createWorkspacePluginsState>;
|
|
55
|
+
tabsLayout: ReturnType<typeof createWorkspaceTabsLayout>;
|
|
56
|
+
assistantBridge: ReturnType<typeof createWorkspaceAssistantBridge>;
|
|
57
|
+
session: ReturnType<typeof createWorkspaceSession>;
|
|
58
|
+
hooks: WorkspaceLifecycleHooks;
|
|
59
|
+
serial: <T>(task: () => Promise<T>) => Promise<T>;
|
|
60
|
+
activity: (label: string, detail: string, kind: Activity['kind'], change?: Activity['change']) => void;
|
|
61
|
+
report: (error: unknown) => void;
|
|
62
|
+
loadWorkspacePart: (part: keyof WorkspaceLoadingState, load: () => Promise<unknown>) => Promise<void>;
|
|
63
|
+
flush: () => Promise<boolean>;
|
|
64
|
+
reconcile: (doc: OpenDocument, snapshot: FileSnapshot) => Promise<void>;
|
|
65
|
+
saveInternal: (doc: OpenDocument) => Promise<void>;
|
|
66
|
+
hydrateDocumentLayout: (doc: OpenDocument) => Promise<void>;
|
|
67
|
+
saveTableLayout: (doc: OpenDocument) => Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createWorkspaceLifecycle(deps: WorkspaceLifecycleDeps) {
|
|
71
|
+
const {
|
|
72
|
+
adapter,
|
|
73
|
+
isDemo,
|
|
74
|
+
isWeb,
|
|
75
|
+
remembersStartupWorkspace,
|
|
76
|
+
workspace,
|
|
77
|
+
fileRegistry,
|
|
78
|
+
documents,
|
|
79
|
+
tabIds,
|
|
80
|
+
tabAliases,
|
|
81
|
+
activeId,
|
|
82
|
+
installedPlugins,
|
|
83
|
+
busy,
|
|
84
|
+
openingWorkspace,
|
|
85
|
+
workspaceLoading,
|
|
86
|
+
restoringDocuments,
|
|
87
|
+
openingDocuments,
|
|
88
|
+
activities,
|
|
89
|
+
fatal,
|
|
90
|
+
recent,
|
|
91
|
+
sessionError,
|
|
92
|
+
workspaceLifecycle,
|
|
93
|
+
stopWatching,
|
|
94
|
+
dataTables,
|
|
95
|
+
policy,
|
|
96
|
+
knowledge,
|
|
97
|
+
plugins,
|
|
98
|
+
tabsLayout,
|
|
99
|
+
assistantBridge,
|
|
100
|
+
session,
|
|
101
|
+
hooks,
|
|
102
|
+
serial,
|
|
103
|
+
activity,
|
|
104
|
+
report,
|
|
105
|
+
loadWorkspacePart,
|
|
106
|
+
flush,
|
|
107
|
+
reconcile,
|
|
108
|
+
saveInternal,
|
|
109
|
+
hydrateDocumentLayout,
|
|
110
|
+
saveTableLayout,
|
|
111
|
+
} = deps;
|
|
112
|
+
|
|
113
|
+
async function refreshWorkspaces() {
|
|
114
|
+
if (!adapter.recent) return false;
|
|
115
|
+
try {
|
|
116
|
+
recent.value = policy.decorateRecent(await adapter.recent());
|
|
117
|
+
return true;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
report(error);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function initialize(requestedWorkspace?: string) {
|
|
125
|
+
if (isDemo || isWeb) {
|
|
126
|
+
await openWorkspace(requestedWorkspace);
|
|
127
|
+
if (!workspace.value && requestedWorkspace) await openWorkspace();
|
|
128
|
+
if (isWeb) await refreshWorkspaces();
|
|
129
|
+
} else if (requestedWorkspace) {
|
|
130
|
+
await openWorkspace(requestedWorkspace);
|
|
131
|
+
} else if (adapter.recent && (await refreshWorkspaces())) {
|
|
132
|
+
const savedId = readStartupWorkspace();
|
|
133
|
+
const previous =
|
|
134
|
+
savedId === undefined
|
|
135
|
+
? recent.value.reduce<RecentWorkspace | undefined>(
|
|
136
|
+
(latest, item) => (!latest || item.openedAt > latest.openedAt ? item : latest),
|
|
137
|
+
undefined,
|
|
138
|
+
)
|
|
139
|
+
: recent.value.find((item) => item.id === savedId);
|
|
140
|
+
if (previous) await openWorkspace(previous.path);
|
|
141
|
+
else if (savedId) rememberStartupWorkspace(null);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function openWorkspace(path?: string, newName?: string) {
|
|
146
|
+
if (busy.value) return;
|
|
147
|
+
busy.value = true;
|
|
148
|
+
let switching = false;
|
|
149
|
+
let pendingWorkspaceLoads: Promise<unknown>[] = [];
|
|
150
|
+
try {
|
|
151
|
+
if (path === undefined && newName === undefined && adapter.selectWorkspacePath) {
|
|
152
|
+
const selected = await adapter.selectWorkspacePath();
|
|
153
|
+
if (selected === null) return;
|
|
154
|
+
path = selected;
|
|
155
|
+
}
|
|
156
|
+
openingWorkspace.value = true;
|
|
157
|
+
for (const part of Object.keys(
|
|
158
|
+
workspaceLoading.value,
|
|
159
|
+
) as (keyof WorkspaceLoadingState)[])
|
|
160
|
+
workspaceLoading.value[part] = true;
|
|
161
|
+
switching = true;
|
|
162
|
+
workspaceLifecycle.pause();
|
|
163
|
+
if (!(await flush())) {
|
|
164
|
+
report('还有未保存的修改。请先处理保存错误,再切换工作空间。');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
await hooks.beforeSwitch?.();
|
|
168
|
+
await hooks.beforeWorkspaceChange?.();
|
|
169
|
+
await serial(async () => {
|
|
170
|
+
const previousReady = session.isReady();
|
|
171
|
+
session.setReady(false);
|
|
172
|
+
let next: Workspace | null;
|
|
173
|
+
try {
|
|
174
|
+
if (newName !== undefined && !adapter.createWorkspace)
|
|
175
|
+
throw new Error('此平台不能直接创建工作空间');
|
|
176
|
+
next =
|
|
177
|
+
newName === undefined
|
|
178
|
+
? await adapter.open(path)
|
|
179
|
+
: await adapter.createWorkspace!(newName);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
session.setReady(previousReady);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
if (!next) {
|
|
185
|
+
session.setReady(previousReady);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const accountTabs = tabIds.value.filter(
|
|
189
|
+
(id) => tabsLayout.views.value.get(id)?.scope === 'account',
|
|
190
|
+
);
|
|
191
|
+
const accountActive = accountTabs.includes(activeId.value) ? activeId.value : undefined;
|
|
192
|
+
stopWatching();
|
|
193
|
+
plugins.pluginExecutor.dispose();
|
|
194
|
+
fatal.value = '';
|
|
195
|
+
if (next.reinitialized) {
|
|
196
|
+
report('.tano 已删除,工作区已重新初始化。旧对象已丢失,文档和附件保留。');
|
|
197
|
+
}
|
|
198
|
+
if (newName !== undefined || next.newlyCreated) {
|
|
199
|
+
try {
|
|
200
|
+
next = await addWorkspaceWelcome(adapter, next);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
report(`工作区已创建,但入门文档未能添加:${String(error)}。可以继续新建文档。`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
policy.resetPolicy(false);
|
|
206
|
+
workspace.value = next;
|
|
207
|
+
documents.value = [];
|
|
208
|
+
tabIds.value = [];
|
|
209
|
+
activeId.value = '';
|
|
210
|
+
openingDocuments.value = {};
|
|
211
|
+
restoringDocuments.value = {};
|
|
212
|
+
tabsLayout.resetTabNavigation();
|
|
213
|
+
if (remembersStartupWorkspace) rememberStartupWorkspace(next.id);
|
|
214
|
+
knowledge.resetKnowledge(false);
|
|
215
|
+
dataTables.reset();
|
|
216
|
+
installedPlugins.value = [];
|
|
217
|
+
workspaceLoading.value.files = false;
|
|
218
|
+
|
|
219
|
+
const settingsReady = loadWorkspacePart('settings', policy.refreshWorkspaceSettings);
|
|
220
|
+
const tablesReady = loadWorkspacePart('tables', () => dataTables.reload());
|
|
221
|
+
const objectsReady = knowledge.refreshObjects().catch(report);
|
|
222
|
+
const capabilitiesReady = loadWorkspacePart('capabilities', policy.refreshCapabilities);
|
|
223
|
+
pendingWorkspaceLoads = [settingsReady, tablesReady, objectsReady, capabilitiesReady];
|
|
224
|
+
assistantBridge.resetForWorkspaceChange();
|
|
225
|
+
activities.value = [];
|
|
226
|
+
sessionError.value = '';
|
|
227
|
+
session.setBlocked(false);
|
|
228
|
+
const watcherReady = workspaceLifecycle.start().catch(report);
|
|
229
|
+
pendingWorkspaceLoads.push(watcherReady);
|
|
230
|
+
|
|
231
|
+
let saved: WorkspaceSession | null = null;
|
|
232
|
+
if (adapter.loadSession) {
|
|
233
|
+
try {
|
|
234
|
+
saved = await adapter.loadSession(next.id);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
session.setBlocked(true);
|
|
237
|
+
sessionError.value = `${String(error)}。本次不覆盖恢复记录。`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (saved) await session.restoreSession(saved, tablesReady, objectsReady);
|
|
241
|
+
else await settingsReady;
|
|
242
|
+
|
|
243
|
+
const first =
|
|
244
|
+
next.files.find(
|
|
245
|
+
(f) =>
|
|
246
|
+
f.id === policy.workspaceSettings.value.homePageId &&
|
|
247
|
+
f.kind === 'file' &&
|
|
248
|
+
isMarkdown(f.path),
|
|
249
|
+
) ??
|
|
250
|
+
next.files.find((f) => f.path === workspaceWelcomePath) ??
|
|
251
|
+
next.files.find((f) => /^readme\.md$/i.test(f.path)) ??
|
|
252
|
+
next.files.find(
|
|
253
|
+
(f) => f.kind === 'file' && isMarkdown(f.path) && !isWorkspaceInternalPath(f.path),
|
|
254
|
+
);
|
|
255
|
+
if (!saved && first) {
|
|
256
|
+
try {
|
|
257
|
+
await session.openInitialDocument(first);
|
|
258
|
+
tabsLayout.ensureTabNavigation(activeId.value, activeId.value);
|
|
259
|
+
tabsLayout.touchNavigation();
|
|
260
|
+
} catch (error) {
|
|
261
|
+
report(error);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
workspaceLoading.value.session = false;
|
|
265
|
+
{
|
|
266
|
+
for (const id of accountTabs) {
|
|
267
|
+
if (!tabIds.value.includes(id)) tabIds.value.push(id);
|
|
268
|
+
tabsLayout.ensureTabNavigation(id);
|
|
269
|
+
}
|
|
270
|
+
if (accountActive) activeId.value = accountActive;
|
|
271
|
+
tabsLayout.touchNavigation();
|
|
272
|
+
}
|
|
273
|
+
await Promise.all([
|
|
274
|
+
settingsReady,
|
|
275
|
+
tablesReady,
|
|
276
|
+
objectsReady,
|
|
277
|
+
capabilitiesReady,
|
|
278
|
+
watcherReady,
|
|
279
|
+
]);
|
|
280
|
+
session.setReady(true);
|
|
281
|
+
session.queueSession();
|
|
282
|
+
if (adapter.recent) recent.value = policy.decorateRecentNames(await adapter.recent());
|
|
283
|
+
activity(isDemo ? '演示工作空间已就绪' : '工作空间已打开', next.name, 'file');
|
|
284
|
+
});
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (path && recent.value.some((item) => item.path === path)) {
|
|
287
|
+
await refreshWorkspaces();
|
|
288
|
+
if (!recent.value.some((item) => item.path === path)) {
|
|
289
|
+
fatal.value = '';
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
report(error);
|
|
294
|
+
} finally {
|
|
295
|
+
await Promise.allSettled(pendingWorkspaceLoads);
|
|
296
|
+
openingWorkspace.value = false;
|
|
297
|
+
for (const part of Object.keys(
|
|
298
|
+
workspaceLoading.value,
|
|
299
|
+
) as (keyof WorkspaceLoadingState)[])
|
|
300
|
+
workspaceLoading.value[part] = false;
|
|
301
|
+
busy.value = false;
|
|
302
|
+
if (switching) {
|
|
303
|
+
workspaceLifecycle.resume();
|
|
304
|
+
try {
|
|
305
|
+
await hooks.afterSwitch?.();
|
|
306
|
+
} catch (error) {
|
|
307
|
+
report(error);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function createWorkspace(name?: string) {
|
|
314
|
+
if (name === undefined) {
|
|
315
|
+
const spaces = [...recent.value, ...(workspace.value ? [workspace.value] : [])];
|
|
316
|
+
const occupied = new Set(
|
|
317
|
+
spaces.flatMap((space) => [space.name, basename(space.path.replace(/\\/g, '/'))]),
|
|
318
|
+
);
|
|
319
|
+
name = '新工作区';
|
|
320
|
+
for (let suffix = 2; occupied.has(name); suffix++) name = `新工作区 ${suffix}`;
|
|
321
|
+
}
|
|
322
|
+
return openWorkspace(undefined, name);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function exitWorkspace(deleteId?: string): Promise<boolean> {
|
|
326
|
+
if (busy.value || !workspace.value) return false;
|
|
327
|
+
busy.value = true;
|
|
328
|
+
try {
|
|
329
|
+
const assertDeletion = () => {
|
|
330
|
+
if (deleteId === undefined) return;
|
|
331
|
+
if (workspace.value?.id !== deleteId) throw new Error('工作区已切换,请重新确认删除');
|
|
332
|
+
if (!adapter.deleteWorkspace || !workspace.value.canDelete)
|
|
333
|
+
throw new Error(
|
|
334
|
+
isWeb ? '仅工作区所有者可以删除工作区' : '此平台暂不支持删除本地工作区注册',
|
|
335
|
+
);
|
|
336
|
+
};
|
|
337
|
+
assertDeletion();
|
|
338
|
+
if (!(await flush())) {
|
|
339
|
+
report(
|
|
340
|
+
`还有未保存的修改。请先处理保存错误,再${deleteId === undefined ? '退出' : '删除'}工作区。`,
|
|
341
|
+
);
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
await hooks.beforeSwitch?.();
|
|
345
|
+
await hooks.beforeWorkspaceChange?.();
|
|
346
|
+
await serial(async () => {
|
|
347
|
+
assertDeletion();
|
|
348
|
+
const current = workspace.value;
|
|
349
|
+
if (!current) return;
|
|
350
|
+
session.queueSession();
|
|
351
|
+
await session.journal.flush();
|
|
352
|
+
if (deleteId !== undefined) await adapter.deleteWorkspace!(deleteId);
|
|
353
|
+
else await adapter.close?.(current.id);
|
|
354
|
+
if (remembersStartupWorkspace) rememberStartupWorkspace(null);
|
|
355
|
+
session.setReady(false);
|
|
356
|
+
stopWatching();
|
|
357
|
+
plugins.pluginHost.dispose();
|
|
358
|
+
plugins.pluginExecutor.dispose();
|
|
359
|
+
workspace.value = null;
|
|
360
|
+
dataTables.reset();
|
|
361
|
+
policy.resetPolicy(true);
|
|
362
|
+
assistantBridge.resetForWorkspaceChange();
|
|
363
|
+
documents.value = [];
|
|
364
|
+
tabIds.value = [];
|
|
365
|
+
tabAliases.value = new Map();
|
|
366
|
+
activeId.value = '';
|
|
367
|
+
tabsLayout.resetTabNavigation();
|
|
368
|
+
knowledge.resetKnowledge(true);
|
|
369
|
+
installedPlugins.value = [];
|
|
370
|
+
plugins.pluginError.value = '';
|
|
371
|
+
activities.value = [];
|
|
372
|
+
sessionError.value = '';
|
|
373
|
+
session.setBlocked(false);
|
|
374
|
+
fatal.value = '';
|
|
375
|
+
if (deleteId !== undefined) {
|
|
376
|
+
policy.forgetWorkspaceName(deleteId);
|
|
377
|
+
recent.value = recent.value.filter((item) => item.id !== deleteId);
|
|
378
|
+
knowledge.referenceDocumentCache.clear();
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
await refreshWorkspaces();
|
|
382
|
+
return true;
|
|
383
|
+
} catch (error) {
|
|
384
|
+
report(error);
|
|
385
|
+
return false;
|
|
386
|
+
} finally {
|
|
387
|
+
busy.value = false;
|
|
388
|
+
try {
|
|
389
|
+
await hooks.afterSwitch?.();
|
|
390
|
+
} catch (error) {
|
|
391
|
+
report(error);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function leaveWorkspace(): Promise<boolean> {
|
|
397
|
+
return exitWorkspace();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function deleteWorkspace(workspaceId: string): Promise<boolean> {
|
|
401
|
+
return exitWorkspace(workspaceId);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
async function refresh() {
|
|
405
|
+
if (!workspace.value) return;
|
|
406
|
+
const expectedId = workspace.value.id;
|
|
407
|
+
const expectedPath = workspace.value.path;
|
|
408
|
+
try {
|
|
409
|
+
await serial(async () => {
|
|
410
|
+
if (workspace.value?.id !== expectedId || workspace.value.path !== expectedPath) return;
|
|
411
|
+
workspace.value = await adapter.refresh();
|
|
412
|
+
await policy.refreshCapabilities();
|
|
413
|
+
await policy.refreshWorkspaceSettings();
|
|
414
|
+
await knowledge.refreshObjects();
|
|
415
|
+
await dataTables.reload();
|
|
416
|
+
for (const doc of documents.value) {
|
|
417
|
+
if (doc.creating) continue;
|
|
418
|
+
const entry = fileRegistry.value?.get(doc.id);
|
|
419
|
+
if (!entry) {
|
|
420
|
+
if (!doc.missing) activity('文件已在外部移除', doc.path, 'external');
|
|
421
|
+
doc.missing = true;
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (doc.path !== entry.path) {
|
|
425
|
+
activity('文件已在外部重命名', `${doc.path} → ${entry.path}`, 'external');
|
|
426
|
+
doc.path = entry.path;
|
|
427
|
+
}
|
|
428
|
+
doc.missing = false;
|
|
429
|
+
await reconcile(doc, await adapter.read(doc.path));
|
|
430
|
+
await saveInternal(doc);
|
|
431
|
+
if (doc.tableLayout && !layoutDirty(doc.tableLayout)) await hydrateDocumentLayout(doc);
|
|
432
|
+
await saveTableLayout(doc);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
} catch (error) {
|
|
436
|
+
knowledge.clearRevokedReferences(error);
|
|
437
|
+
report(error);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async function reveal() {
|
|
442
|
+
try {
|
|
443
|
+
await adapter.reveal();
|
|
444
|
+
} catch (e) {
|
|
445
|
+
report(e);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return {
|
|
450
|
+
initialize,
|
|
451
|
+
refreshWorkspaces,
|
|
452
|
+
openWorkspace,
|
|
453
|
+
createWorkspace,
|
|
454
|
+
leaveWorkspace,
|
|
455
|
+
deleteWorkspace,
|
|
456
|
+
refresh,
|
|
457
|
+
reveal,
|
|
458
|
+
};
|
|
459
|
+
}
|