@tano.page/workbench 0.14.0 → 0.15.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.
Files changed (177) hide show
  1. package/package.json +21 -8
  2. package/src/App.vue +76 -17
  3. package/src/appearance/appearance.ts +14 -4
  4. package/src/appearance/components/ThemePresetPreview.vue +52 -8
  5. package/src/appearance/interface-font.ts +99 -0
  6. package/src/appearance/theme.ts +26 -10
  7. package/src/appearance/use-interface-font.ts +30 -0
  8. package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
  9. package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
  10. package/src/assets/mail-provider-icons/gmail.svg +1 -0
  11. package/src/assets/mail-provider-icons/icloud.svg +12 -0
  12. package/src/assets/mail-provider-icons/netease-126.svg +5 -0
  13. package/src/assets/mail-provider-icons/netease-163.svg +5 -0
  14. package/src/assets/mail-provider-icons/qq.svg +9 -0
  15. package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
  16. package/src/assistant/components/AssistantChangeList.vue +98 -21
  17. package/src/assistant/components/AssistantPanel.vue +424 -7
  18. package/src/assistant/components/PluginToolProposalCard.vue +235 -0
  19. package/src/assistant/engine.ts +56 -3
  20. package/src/assistant/files.ts +5 -13
  21. package/src/assistant/inbox.ts +1 -148
  22. package/src/assistant/locales/de-DE.json +4 -1
  23. package/src/assistant/locales/en-US.json +4 -1
  24. package/src/assistant/locales/es-ES.json +4 -1
  25. package/src/assistant/locales/ja-JP.json +4 -1
  26. package/src/assistant/locales/zh-CN.json +4 -1
  27. package/src/assistant/locales/zh-TW.json +4 -1
  28. package/src/assistant/mention-autocomplete.ts +69 -0
  29. package/src/assistant/prompts.ts +7 -0
  30. package/src/assistant/results.ts +20 -86
  31. package/src/assistant/store.ts +319 -12
  32. package/src/assistant/structures.ts +7 -5
  33. package/src/assistant/tasks.ts +3 -5
  34. package/src/assistant/workspace-bridge.ts +1 -1
  35. package/src/composables/use-document-actions.ts +38 -20
  36. package/src/composables/use-file-tree-controller.ts +7 -12
  37. package/src/composables/use-workbench-history.ts +2 -4
  38. package/src/composables/use-workbench-modals.ts +6 -1
  39. package/src/composables/use-workbench-outline.ts +0 -5
  40. package/src/composables/use-workbench-shortcuts.ts +26 -22
  41. package/src/data-tables/data-tables.ts +1 -2
  42. package/src/documents/components/DocumentHistoryPanel.vue +3 -1
  43. package/src/features.ts +1 -0
  44. package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
  45. package/src/fonts/Inter-Latin.woff2 +0 -0
  46. package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
  47. package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
  48. package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
  49. package/src/help/help-milestones.ts +3 -5
  50. package/src/i18n/locales/de-DE.json +349 -3
  51. package/src/i18n/locales/en-US.json +349 -2
  52. package/src/i18n/locales/es-ES.json +349 -3
  53. package/src/i18n/locales/ja-JP.json +348 -2
  54. package/src/i18n/locales/zh-TW.json +348 -2
  55. package/src/mail/components/MailAccountDialog.vue +449 -0
  56. package/src/mail/components/MailComposerDialog.vue +325 -0
  57. package/src/mail/components/MailProviderIcon.vue +30 -0
  58. package/src/mail/components/MailWorkspaceView.vue +820 -0
  59. package/src/mail/components/SidebarMail.vue +133 -0
  60. package/src/mail/mail-avatar.ts +17 -0
  61. package/src/mail/mail-bridge.ts +68 -0
  62. package/src/mail/mail-calendar.ts +208 -0
  63. package/src/mail/mail-markdown.ts +195 -0
  64. package/src/mail/types.ts +226 -0
  65. package/src/objects/components/ObjectDetailModal.vue +1001 -0
  66. package/src/objects/workspace-objects.ts +1 -1
  67. package/src/plan-sync/types.ts +6 -3
  68. package/src/plans/calendar-interaction.ts +194 -0
  69. package/src/plans/calendar.ts +63 -7
  70. package/src/plans/components/CalendarDayPopover.vue +172 -39
  71. package/src/plans/components/CalendarView.vue +1736 -276
  72. package/src/plans/components/PlanArchiveDialog.vue +295 -0
  73. package/src/plans/components/PlanDateField.vue +6 -4
  74. package/src/plans/components/PlanDetailPanel.vue +227 -32
  75. package/src/plans/components/PlanEventList.vue +16 -4
  76. package/src/plans/components/SidebarPlan.vue +22 -15
  77. package/src/plans/components/TaskRepeatControls.vue +169 -30
  78. package/src/plans/local-reminders.ts +149 -0
  79. package/src/plans/personal-plans.ts +10 -1
  80. package/src/plans/plan-date.ts +8 -1
  81. package/src/plans/plan-migration.ts +95 -0
  82. package/src/plans/recurrence.ts +95 -0
  83. package/src/plans/task-repeat.ts +8 -8
  84. package/src/plans/timeline-layout.ts +92 -0
  85. package/src/plugins/assistant-bridge.ts +520 -0
  86. package/src/plugins/attachment-reader.ts +3 -1
  87. package/src/plugins/cache-storage.ts +42 -2
  88. package/src/plugins/components/PluginAutomations.vue +3 -3
  89. package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
  90. package/src/plugins/components/PluginChangeSummary.vue +16 -3
  91. package/src/plugins/components/PluginConnections.vue +1 -1
  92. package/src/plugins/components/PluginCustomView.vue +2 -2
  93. package/src/plugins/components/PluginDetailPage.vue +129 -54
  94. package/src/plugins/components/PluginDocumentSlot.vue +63 -0
  95. package/src/plugins/components/PluginExplorer.vue +15 -21
  96. package/src/plugins/components/PluginImportDialog.vue +410 -0
  97. package/src/plugins/components/PluginInstaller.vue +39 -145
  98. package/src/plugins/components/PluginListItem.vue +3 -0
  99. package/src/plugins/components/PluginMaintenance.vue +21 -6
  100. package/src/plugins/components/PluginRuntimePanel.vue +3 -3
  101. package/src/plugins/components/PluginSettingsForm.vue +111 -0
  102. package/src/plugins/components/PluginStatusBar.vue +161 -0
  103. package/src/plugins/components/PluginSurface.vue +18 -6
  104. package/src/plugins/components/PluginUiDialog.vue +452 -0
  105. package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
  106. package/src/plugins/excalidraw/manifest.json +12 -1
  107. package/src/plugins/host.ts +662 -43
  108. package/src/plugins/native.ts +2 -10
  109. package/src/plugins/overlay-mapping.ts +125 -0
  110. package/src/plugins/packages.ts +73 -1
  111. package/src/plugins/plugin-permissions.ts +57 -0
  112. package/src/plugins/plugin-sdk.ts +174 -8
  113. package/src/plugins/policy.ts +53 -3
  114. package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
  115. package/src/plugins/presentation-preview/manifest.json +2 -1
  116. package/src/plugins/queries.ts +3 -1
  117. package/src/plugins/sandbox.ts +15 -1
  118. package/src/plugins/use-plugin-actions.ts +67 -20
  119. package/src/plugins/user-plugins.ts +254 -0
  120. package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
  121. package/src/plugins/word-preview/manifest.json +13 -1
  122. package/src/plugins/workbench.ts +175 -2
  123. package/src/plugins/worker.js +105 -8
  124. package/src/plugins/workspace-plugin-runtime.ts +23 -7
  125. package/src/plugins/workspace-plugins.ts +212 -21
  126. package/src/runtime.ts +101 -3
  127. package/src/settings/components/SettingsAppearancePage.vue +46 -0
  128. package/src/settings/components/SettingsDocumentsPage.vue +0 -1
  129. package/src/settings/components/settings-search.ts +2 -3
  130. package/src/shell/components/SidebarNavigation.vue +22 -2
  131. package/src/shell/components/WorkbenchContextMenus.vue +21 -8
  132. package/src/shell/components/WorkbenchModals.vue +27 -46
  133. package/src/shell/components/WorkbenchPanes.vue +267 -84
  134. package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
  135. package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
  136. package/src/shell/use-workbench.ts +116 -145
  137. package/src/shell/workbench-async-components.ts +14 -5
  138. package/src/stores/mail.ts +414 -0
  139. package/src/stores/plan-sync.ts +2 -1
  140. package/src/stores/plans.ts +2 -9
  141. package/src/stores/workspace-knowledge.ts +1 -113
  142. package/src/stores/workspace-plugins-state.ts +537 -14
  143. package/src/stores/workspace-tabs-layout.ts +5 -43
  144. package/src/stores/workspace.ts +69 -66
  145. package/src/styles/agent-diff-modals.css +0 -7
  146. package/src/styles/dark-theme.css +3 -3
  147. package/src/styles/inspector.css +0 -59
  148. package/src/styles/layout-themes.css +346 -0
  149. package/src/styles/mail.css +1568 -0
  150. package/src/styles/mobile.css +2 -2
  151. package/src/styles/recent-and-media.css +0 -17
  152. package/src/styles/theme-contract.css +3 -3
  153. package/src/styles/workbench-shell.css +110 -17
  154. package/src/styles/workspace-states.css +9 -33
  155. package/src/styles.css +1 -1
  156. package/src/tabs/components/DesktopTabs.vue +0 -3
  157. package/src/tabs/components/NewTabPicker.vue +10 -4
  158. package/src/tabs/tab-label.ts +0 -1
  159. package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
  160. package/src/workspace/components/WorkspaceIconPicker.vue +28 -6
  161. package/src/workspace/workspace-comments.ts +11 -151
  162. package/src/workspace/workspace-welcome.ts +1 -1
  163. package/src/documents/components/FormulaMenu.vue +0 -50
  164. package/src/files/components/FileDatabasePage.vue +0 -152
  165. package/src/files/components/FolderHomeIcon.vue +0 -12
  166. package/src/objects/components/ObjectDatabasePage.vue +0 -100
  167. package/src/objects/components/ObjectPanel.vue +0 -554
  168. package/src/plans/components/PersonalPlanDialog.vue +0 -105
  169. package/src/shell/components/WorkspaceViewPage.vue +0 -127
  170. package/src/shell/components/WorkspaceViewTab.vue +0 -24
  171. package/src/styles/object-panel.css +0 -163
  172. package/src/workspace/components/GitInspectionPanel.vue +0 -35
  173. package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
  174. package/src/workspace/welcome-slogans.ts +0 -11
  175. package/src/workspace/workspace-git.ts +0 -35
  176. package/src/workspace/workspace-sync.ts +0 -46
  177. package/src/workspace/workspace-views.ts +0 -48
@@ -0,0 +1,820 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, onMounted, ref, watch } from 'vue';
3
+ import {
4
+ AlertTriangle,
5
+ Archive,
6
+ CalendarDays,
7
+ CalendarPlus,
8
+ Check,
9
+ ChevronRight,
10
+ Download,
11
+ FilePlus2,
12
+ FileText,
13
+ Forward,
14
+ Image as ImageIcon,
15
+ ListTodo,
16
+ Mail,
17
+ MailOpen,
18
+ Paperclip,
19
+ Plus,
20
+ RefreshCw,
21
+ Reply,
22
+ ReplyAll,
23
+ Search,
24
+ ShieldCheck,
25
+ Star,
26
+ Trash2,
27
+ X,
28
+ } from 'lucide-vue-next';
29
+ import { t } from '../../i18n/i18n';
30
+ import { useMailStore } from '../../stores/mail';
31
+ import { usePlanStore } from '../../stores/plans';
32
+ import { useWorkspaceStore } from '../../stores/workspace';
33
+ import {
34
+ buildEventDraftFromInvite,
35
+ buildPlanDraftFromEmail,
36
+ buildRsvpReplyIcs,
37
+ parseInvitePreview,
38
+ } from '../mail-calendar';
39
+ import {
40
+ buildSandboxedEmailSrcdoc,
41
+ emailToMarkdownDocument,
42
+ safeMailDocumentPath,
43
+ } from '../mail-markdown';
44
+ import {
45
+ formatMailAddressList,
46
+ type MailAttachmentInfo,
47
+ type MailCalendarInvite,
48
+ type MailFilter,
49
+ type RsvpResponseStatus,
50
+ } from '../types';
51
+ import { avatarHue, senderInitial } from '../mail-avatar';
52
+ import MailAccountDialog from './MailAccountDialog.vue';
53
+ import MailComposerDialog from './MailComposerDialog.vue';
54
+ import MailProviderIcon from './MailProviderIcon.vue';
55
+
56
+ const mail = useMailStore();
57
+ const plans = usePlanStore();
58
+ const workspace = useWorkspaceStore();
59
+
60
+ const searchInput = ref('');
61
+ const allowRemoteImages = ref(false);
62
+ const actionFeedback = ref('');
63
+ const actionError = ref('');
64
+ const busyAction = ref('');
65
+
66
+ onMounted(() => {
67
+ void mail.init();
68
+ });
69
+
70
+ watch(
71
+ () => mail.selectedMessageId,
72
+ () => {
73
+ allowRemoteImages.value = false;
74
+ actionFeedback.value = '';
75
+ actionError.value = '';
76
+ },
77
+ );
78
+
79
+ // Success notices are transient; errors stay until dismissed or replaced.
80
+ let feedbackTimer: ReturnType<typeof setTimeout> | undefined;
81
+ watch(actionFeedback, (msg) => {
82
+ clearTimeout(feedbackTimer);
83
+ if (msg) feedbackTimer = setTimeout(() => (actionFeedback.value = ''), 4000);
84
+ });
85
+
86
+ const filters: { id: MailFilter; label: string }[] = [
87
+ { id: 'all', label: t('全部') },
88
+ { id: 'unread', label: t('未读') },
89
+ { id: 'flagged', label: t('星标') },
90
+ { id: 'calendar', label: t('日程') },
91
+ { id: 'attachments', label: t('附件') },
92
+ ];
93
+
94
+ const detail = computed(() => mail.currentDetail);
95
+ const currentAccount = computed(() =>
96
+ mail.accounts.find((a) => a.id === detail.value?.summary.accountId),
97
+ );
98
+
99
+ const sandboxSrcdoc = computed(() =>
100
+ detail.value?.htmlSanitized
101
+ ? buildSandboxedEmailSrcdoc(detail.value.htmlSanitized, allowRemoteImages.value)
102
+ : '',
103
+ );
104
+
105
+ const invitePreviews = computed(() => {
106
+ if (!detail.value) return [];
107
+ const existing = plans.recordsFor('all');
108
+ return detail.value.invites.map((invite) => ({
109
+ invite,
110
+ preview: parseInvitePreview(invite, existing),
111
+ }));
112
+ });
113
+
114
+ const visibleAttachments = computed(() =>
115
+ (detail.value?.attachments ?? []).filter((att) => !att.isInline),
116
+ );
117
+
118
+ function formatDate(ts: number): string {
119
+ if (!ts) return '';
120
+ const date = new Date(ts * 1000);
121
+ const now = new Date();
122
+ const sameDay =
123
+ date.getFullYear() === now.getFullYear() &&
124
+ date.getMonth() === now.getMonth() &&
125
+ date.getDate() === now.getDate();
126
+ return sameDay
127
+ ? date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
128
+ : date.toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' });
129
+ }
130
+
131
+ function formatFullDate(ts: number): string {
132
+ if (!ts) return '';
133
+ return new Date(ts * 1000).toLocaleString('zh-CN', {
134
+ dateStyle: 'medium',
135
+ timeStyle: 'short',
136
+ });
137
+ }
138
+
139
+ function formatSize(bytes: number): string {
140
+ if (bytes < 1024) return `${bytes} B`;
141
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
142
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
143
+ }
144
+
145
+ async function runAction(name: string, fn: () => Promise<string | void>) {
146
+ busyAction.value = name;
147
+ actionError.value = '';
148
+ actionFeedback.value = '';
149
+ try {
150
+ const msg = await fn();
151
+ if (msg) actionFeedback.value = msg;
152
+ } catch (err) {
153
+ actionError.value = err instanceof Error ? err.message : String(err);
154
+ } finally {
155
+ busyAction.value = '';
156
+ }
157
+ }
158
+
159
+ function onSearchSubmit() {
160
+ void mail.search(searchInput.value);
161
+ }
162
+
163
+ function openAccountDialog(presetId = '') {
164
+ mail.accountDialogPreset = presetId;
165
+ mail.accountDialogOpen = true;
166
+ }
167
+
168
+ function clearSearch() {
169
+ searchInput.value = '';
170
+ void mail.search('');
171
+ }
172
+
173
+ function senderLabel(addr: { name: string; address: string } | undefined): string {
174
+ return addr?.name || addr?.address || t('未知发件人');
175
+ }
176
+
177
+ /* ---- Message list: keyboard navigation + hover quick actions ---------- */
178
+ const listRef = ref<HTMLElement>();
179
+
180
+ async function focusMessage(id: string) {
181
+ await nextTick();
182
+ listRef.value
183
+ ?.querySelector<HTMLButtonElement>(`[data-message-id="${CSS.escape(id)}"]`)
184
+ ?.focus({ preventScroll: false });
185
+ }
186
+
187
+ function onListKeydown(event: KeyboardEvent) {
188
+ const keys = ['ArrowDown', 'ArrowUp', 'j', 'k', 'Home', 'End'];
189
+ if (!keys.includes(event.key) || event.altKey || event.ctrlKey || event.metaKey) return;
190
+ const list = mail.messages;
191
+ if (!list.length) return;
192
+ event.preventDefault();
193
+ const current = list.findIndex((m) => m.id === mail.selectedMessageId);
194
+ let next = current;
195
+ if (event.key === 'Home') next = 0;
196
+ else if (event.key === 'End') next = list.length - 1;
197
+ else if (event.key === 'ArrowDown' || event.key === 'j') next = Math.min(list.length - 1, current + 1);
198
+ else next = Math.max(0, current < 0 ? 0 : current - 1);
199
+ const target = list[next];
200
+ if (!target || target.id === mail.selectedMessageId) return;
201
+ void mail.selectMessage(target.id);
202
+ void focusMessage(target.id);
203
+ }
204
+
205
+ function quickArchive(id: string) {
206
+ void runAction('archive', () => mail.moveToSpecialFolder(id, 'archive'));
207
+ }
208
+
209
+ function quickTrash(id: string) {
210
+ void runAction('trash', () => mail.moveToSpecialFolder(id, 'trash'));
211
+ }
212
+
213
+ function openReply(replyAll: boolean) {
214
+ if (!detail.value || !currentAccount.value) return;
215
+ const sender =
216
+ detail.value.replyTo[0]?.address || detail.value.summary.from[0]?.address || '';
217
+ const selfEmail = currentAccount.value.email.toLowerCase();
218
+ const cc = replyAll
219
+ ? [...detail.value.summary.to, ...detail.value.cc]
220
+ .map((a) => a.address)
221
+ .filter((addr) => addr.toLowerCase() !== selfEmail && addr.toLowerCase() !== sender.toLowerCase())
222
+ : [];
223
+ const subj = detail.value.summary.subject;
224
+ const quoted = (detail.value.textBody || detail.value.summary.snippet)
225
+ .split('\n')
226
+ .slice(0, 40)
227
+ .map((line) => `> ${line}`)
228
+ .join('\n');
229
+ const refs = detail.value.summary.messageId
230
+ ? [...detail.value.references, detail.value.summary.messageId]
231
+ : detail.value.references;
232
+ mail.openComposer({
233
+ accountId: currentAccount.value.id,
234
+ to: sender ? [sender] : [],
235
+ cc,
236
+ subject: /^re:/i.test(subj) ? subj : `Re: ${subj}`,
237
+ markdownBody: `\n\n---\n${t('原邮件发件人:')}${formatMailAddressList(detail.value.summary.from)}\n\n${quoted}`,
238
+ inReplyTo: detail.value.summary.messageId || null,
239
+ references: refs,
240
+ });
241
+ }
242
+
243
+ function openForward() {
244
+ if (!detail.value || !currentAccount.value) return;
245
+ const subj = detail.value.summary.subject;
246
+ mail.openComposer({
247
+ accountId: currentAccount.value.id,
248
+ subject: /^(fwd|fw):/i.test(subj) ? subj : `Fwd: ${subj}`,
249
+ markdownBody: [
250
+ '',
251
+ '---------- 转发的邮件 ----------',
252
+ `发件人:${formatMailAddressList(detail.value.summary.from)}`,
253
+ `时间:${formatFullDate(detail.value.summary.dateTs)}`,
254
+ `主题:${subj}`,
255
+ '',
256
+ detail.value.textBody || detail.value.summary.snippet,
257
+ ].join('\n'),
258
+ });
259
+ }
260
+
261
+ async function importInvite(invite: MailCalendarInvite, scope: 'personal' | 'workspace') {
262
+ if (!detail.value) return;
263
+ await runAction(`import-${invite.id}`, async () => {
264
+ const draft = buildEventDraftFromInvite(invite, detail.value!, plans.recordsFor('all'));
265
+ const created = await plans.create(
266
+ draft,
267
+ scope,
268
+ scope === 'workspace' ? workspace.workspace?.id : undefined,
269
+ );
270
+ await mail.markInviteState(invite.id, created.object.id, undefined);
271
+ return scope === 'workspace' ? t('已加入当前工作区日历。') : t('已加入个人日历。');
272
+ });
273
+ }
274
+
275
+ async function respondInvite(invite: MailCalendarInvite, status: RsvpResponseStatus) {
276
+ if (!detail.value || !currentAccount.value) return;
277
+ await runAction(`rsvp-${invite.id}`, async () => {
278
+ const preview = parseInvitePreview(invite, plans.recordsFor('all'));
279
+ const organizer = preview.organizerEmail || detail.value!.summary.from[0]?.address;
280
+ if (!organizer) throw new Error(t('无法识别会议组织者邮箱,无法发送回执'));
281
+ const replyIcs = buildRsvpReplyIcs(
282
+ invite.rawIcs,
283
+ currentAccount.value!.email,
284
+ currentAccount.value!.displayName || currentAccount.value!.email,
285
+ status,
286
+ );
287
+ const labelMap: Record<RsvpResponseStatus, string> = {
288
+ ACCEPTED: t('已接受'),
289
+ TENTATIVE: t('暂定'),
290
+ DECLINED: t('已拒绝'),
291
+ };
292
+ await mail.sendMail({
293
+ accountId: currentAccount.value!.id,
294
+ to: [organizer],
295
+ subject: `${labelMap[status]}: ${preview.summary}`,
296
+ textBody: `${currentAccount.value!.displayName || currentAccount.value!.email} ${labelMap[status]}了日程邀请「${preview.summary}」。`,
297
+ calendarIcs: replyIcs,
298
+ calendarMethod: 'REPLY',
299
+ inReplyTo: detail.value!.summary.messageId || undefined,
300
+ });
301
+ let importedId = invite.importedObjectId;
302
+ if (status !== 'DECLINED' && !importedId) {
303
+ const targetScope = plans.workspaceWritable ? 'workspace' : 'personal';
304
+ const draft = buildEventDraftFromInvite(invite, detail.value!, plans.recordsFor('all'));
305
+ const created = await plans.create(
306
+ draft,
307
+ targetScope,
308
+ targetScope === 'workspace' ? workspace.workspace?.id : undefined,
309
+ );
310
+ importedId = created.object.id;
311
+ }
312
+ await mail.markInviteState(invite.id, importedId, status);
313
+ return t('已通过本人邮箱向组织者发送「{0}」回执。', [labelMap[status]]);
314
+ });
315
+ }
316
+
317
+ async function addEmailToPlans(mode: 'calendar' | 'todo') {
318
+ if (!detail.value) return;
319
+ await runAction(`plan-${mode}`, async () => {
320
+ const scope = plans.workspaceWritable ? 'workspace' : 'personal';
321
+ const draft = buildPlanDraftFromEmail(detail.value!, mode);
322
+ await plans.create(draft, scope, scope === 'workspace' ? workspace.workspace?.id : undefined);
323
+ return mode === 'todo' ? t('已转为待办事项。') : t('已加入日历日程。');
324
+ });
325
+ }
326
+
327
+ async function saveEmailAsMarkdown() {
328
+ if (!detail.value) return;
329
+ if (!workspace.workspace || workspace.workspace.readOnly) {
330
+ actionError.value = t('请先打开一个可写的工作区,再将邮件存为 Markdown 文档。');
331
+ return;
332
+ }
333
+ await runAction('save-md', async () => {
334
+ const path = safeMailDocumentPath(detail.value!);
335
+ const content = emailToMarkdownDocument(detail.value!);
336
+ await workspace.create(path, false, content, workspace.workspace!.id);
337
+ return t('已存为工作区文档:{0}', [path]);
338
+ });
339
+ }
340
+
341
+ async function downloadAttachment(att: MailAttachmentInfo) {
342
+ await runAction(`att-${att.id}`, async () => {
343
+ const data = await mail.downloadAttachment(att.id);
344
+ const binary = atob(data.bytesBase64);
345
+ const bytes = new Uint8Array(binary.length);
346
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
347
+ const blob = new Blob([bytes], { type: data.contentType || 'application/octet-stream' });
348
+ const url = URL.createObjectURL(blob);
349
+ const anchor = document.createElement('a');
350
+ anchor.href = url;
351
+ anchor.download = data.filename;
352
+ anchor.click();
353
+ setTimeout(() => URL.revokeObjectURL(url), 5000);
354
+ return t('已下载附件:{0}', [data.filename]);
355
+ });
356
+ }
357
+ </script>
358
+
359
+ <template>
360
+ <div class="mail-workspace">
361
+ <div v-if="!mail.available" class="mail-hero">
362
+ <span class="mail-hero-icon"><Mail :size="26" /></span>
363
+ <h2>{{ t('原生邮箱直连仅支持桌面端') }}</h2>
364
+ <p>{{ t('为了保护你的邮箱凭据与邮件隐私,Tano 仅在桌面客户端通过本机加密直连 IMAP/SMTP,不在云端代管邮箱。') }}</p>
365
+ </div>
366
+
367
+ <div v-else-if="!mail.accounts.length" class="mail-welcome">
368
+ <header class="mail-welcome-head">
369
+ <span class="mail-hero-icon"><Mail :size="24" /></span>
370
+ <h2>{{ t('连接你的个人邮箱') }}</h2>
371
+ <p>{{ t('在 Tano 中收发邮件、回复日程邀请,并把邮件一键存为 Markdown 文档。') }}</p>
372
+ </header>
373
+
374
+ <section class="mail-welcome-providers" :aria-label="t('选择邮箱服务商')">
375
+ <h3>{{ t('选择邮箱服务商') }}</h3>
376
+ <div v-if="mail.presets.length" class="mail-provider-grid">
377
+ <button
378
+ v-for="(preset, index) in mail.presets"
379
+ :key="preset.id"
380
+ type="button"
381
+ class="mail-provider"
382
+ :style="{ '--i': index }"
383
+ @click="openAccountDialog(preset.id)"
384
+ >
385
+ <MailProviderIcon :provider="preset.id" />
386
+ <span class="mail-provider-name">{{ preset.name }}</span>
387
+ <ChevronRight :size="15" class="mail-provider-chevron" />
388
+ </button>
389
+ </div>
390
+ <button
391
+ v-else
392
+ type="button"
393
+ class="mail-btn-primary mail-btn-lg"
394
+ @click="openAccountDialog()"
395
+ >
396
+ <Plus :size="16" /> {{ t('添加邮箱账号') }}
397
+ </button>
398
+ </section>
399
+
400
+ <p class="mail-welcome-note">
401
+ <ShieldCheck :size="13" />
402
+ <span>{{ t('由桌面端直连邮箱服务器,授权码仅存系统凭据库,不经过 Tano 云端。') }}</span>
403
+ </p>
404
+ </div>
405
+
406
+ <div v-else class="mail-split">
407
+ <!-- Message list pane -->
408
+ <aside class="mail-list-pane">
409
+ <header class="mail-list-header">
410
+ <form class="mail-search-box" role="search" @submit.prevent="onSearchSubmit">
411
+ <Search :size="14" />
412
+ <input
413
+ v-model="searchInput"
414
+ type="text"
415
+ :aria-label="t('搜索主题、发件人或正文…')"
416
+ :placeholder="t('搜索主题、发件人或正文…')"
417
+ @input="!searchInput && mail.search('')"
418
+ @keydown.esc="clearSearch"
419
+ />
420
+ <button
421
+ v-if="searchInput"
422
+ type="button"
423
+ class="mail-search-clear"
424
+ :aria-label="t('关闭')"
425
+ @click="clearSearch"
426
+ >
427
+ <X :size="13" />
428
+ </button>
429
+ </form>
430
+ <button
431
+ type="button"
432
+ class="icon-button"
433
+ :aria-label="t('同步当前文件夹')"
434
+ :data-tooltip="t('同步当前文件夹')"
435
+ :disabled="!!mail.syncingAccountId || !mail.selectedFolderId"
436
+ @click="mail.syncSelectedFolder()"
437
+ >
438
+ <RefreshCw :size="15" :class="{ spinning: !!mail.syncingAccountId }" />
439
+ </button>
440
+ </header>
441
+
442
+ <div class="mail-filter-bar" role="toolbar">
443
+ <button
444
+ v-for="item in filters"
445
+ :key="item.id"
446
+ type="button"
447
+ class="mail-filter-pill"
448
+ :class="{ active: mail.filter === item.id }"
449
+ :aria-pressed="mail.filter === item.id"
450
+ @click="mail.setFilter(item.id)"
451
+ >
452
+ {{ item.label }}
453
+ </button>
454
+ </div>
455
+
456
+ <p v-if="mail.error" class="mail-alert error mail-list-alert">
457
+ <AlertTriangle :size="14" /> <span>{{ mail.error }}</span>
458
+ </p>
459
+
460
+ <ul ref="listRef" class="mail-message-list" @keydown="onListKeydown">
461
+ <li v-if="!mail.messages.length" class="mail-list-empty">
462
+ <Search v-if="mail.searchQuery" :size="20" />
463
+ <Mail v-else :size="20" />
464
+ <span>{{ mail.searchQuery ? t('没有匹配的本地缓存邮件') : t('当前文件夹暂无邮件,点击右上角刷新同步') }}</span>
465
+ </li>
466
+ <li
467
+ v-for="item in mail.messages"
468
+ :key="item.id"
469
+ class="mail-message-row"
470
+ :class="{ active: mail.selectedMessageId === item.id, unread: !item.seen }"
471
+ >
472
+ <button
473
+ type="button"
474
+ class="mail-message-item"
475
+ :data-message-id="item.id"
476
+ :aria-current="mail.selectedMessageId === item.id ? 'true' : undefined"
477
+ @click="mail.selectMessage(item.id)"
478
+ >
479
+ <span v-if="!item.seen" class="mail-unread-dot" aria-hidden="true" />
480
+ <span
481
+ class="mail-avatar"
482
+ :style="{ '--avatar-hue': avatarHue(item.from[0]) }"
483
+ aria-hidden="true"
484
+ >{{ senderInitial(item.from[0]) }}</span>
485
+ <span class="mail-item-main">
486
+ <span class="mail-item-top">
487
+ <span class="mail-item-sender">{{ senderLabel(item.from[0]) }}</span>
488
+ <time class="mail-item-date">{{ formatDate(item.dateTs) }}</time>
489
+ </span>
490
+ <span class="mail-item-subject">{{ item.subject || t('(无主题)') }}</span>
491
+ <span class="mail-item-bottom">
492
+ <span class="mail-item-snippet">{{ item.snippet }}</span>
493
+ <span class="mail-item-icons">
494
+ <Star v-if="item.flagged" :size="12" class="mail-icon-star" />
495
+ <CalendarDays v-if="item.hasIcs" :size="12" />
496
+ <Paperclip v-if="item.hasAttachments" :size="12" />
497
+ </span>
498
+ </span>
499
+ </span>
500
+ </button>
501
+ <!-- Hover / focus quick actions, siblings of the row button. -->
502
+ <span class="mail-row-actions">
503
+ <button
504
+ type="button"
505
+ class="mail-row-action"
506
+ :aria-label="item.seen ? t('标为未读') : t('标为已读')"
507
+ :data-tooltip="item.seen ? t('标为未读') : t('标为已读')"
508
+ @click.stop="mail.toggleSeen(item.id, !item.seen)"
509
+ >
510
+ <MailOpen v-if="!item.seen" :size="14" />
511
+ <Mail v-else :size="14" />
512
+ </button>
513
+ <button
514
+ type="button"
515
+ class="mail-row-action"
516
+ :class="{ on: item.flagged }"
517
+ :aria-label="item.flagged ? t('取消星标') : t('加星标')"
518
+ :data-tooltip="item.flagged ? t('取消星标') : t('加星标')"
519
+ @click.stop="mail.toggleFlagged(item.id, !item.flagged)"
520
+ >
521
+ <Star :size="14" />
522
+ </button>
523
+ <button
524
+ type="button"
525
+ class="mail-row-action"
526
+ :aria-label="t('归档')"
527
+ :data-tooltip="t('归档')"
528
+ @click.stop="quickArchive(item.id)"
529
+ >
530
+ <Archive :size="14" />
531
+ </button>
532
+ <button
533
+ type="button"
534
+ class="mail-row-action danger"
535
+ :aria-label="t('移至已删除')"
536
+ :data-tooltip="t('移至已删除')"
537
+ @click.stop="quickTrash(item.id)"
538
+ >
539
+ <Trash2 :size="14" />
540
+ </button>
541
+ </span>
542
+ </li>
543
+ </ul>
544
+ </aside>
545
+
546
+ <!-- Reader pane -->
547
+ <main class="mail-reader-pane">
548
+ <div v-if="mail.loadingMessage" class="mail-reader-loading" aria-busy="true">
549
+ <span class="mail-skeleton w40" />
550
+ <span class="mail-skeleton w70 tall" />
551
+ <span class="mail-skeleton w30" />
552
+ <span class="mail-skeleton block" />
553
+ <span class="mail-sr-only">{{ t('正在从邮箱加载正文…') }}</span>
554
+ </div>
555
+ <div v-else-if="!detail" class="mail-reader-empty">
556
+ <span class="mail-hero-icon small"><MailOpen :size="22" /></span>
557
+ <p>{{ t('选择左侧一封邮件开始阅读,或点击「写邮件」发起新对话。') }}</p>
558
+ </div>
559
+ <article v-else :key="detail.summary.id" class="mail-reader-article">
560
+ <!-- Actions scoped to this message, on the message's own header row. -->
561
+ <div class="mail-reader-toolbar" role="toolbar">
562
+ <div class="mail-toolbar-group">
563
+ <button type="button" class="icon-button" :aria-label="t('回复')" :data-tooltip="t('回复')" @click="openReply(false)">
564
+ <Reply :size="16" />
565
+ </button>
566
+ <button type="button" class="icon-button" :aria-label="t('全部回复')" :data-tooltip="t('全部回复')" @click="openReply(true)">
567
+ <ReplyAll :size="16" />
568
+ </button>
569
+ <button type="button" class="icon-button" :aria-label="t('转发')" :data-tooltip="t('转发')" @click="openForward">
570
+ <Forward :size="16" />
571
+ </button>
572
+ </div>
573
+ <span class="mail-toolbar-divider" aria-hidden="true" />
574
+ <div class="mail-toolbar-group">
575
+ <button
576
+ type="button"
577
+ class="icon-button"
578
+ :aria-label="t('加入日历')"
579
+ :data-tooltip="t('加入日历')"
580
+ :disabled="!!busyAction"
581
+ @click="addEmailToPlans('calendar')"
582
+ >
583
+ <CalendarPlus :size="16" />
584
+ </button>
585
+ <button
586
+ type="button"
587
+ class="icon-button"
588
+ :aria-label="t('转为待办')"
589
+ :data-tooltip="t('转为待办')"
590
+ :disabled="!!busyAction"
591
+ @click="addEmailToPlans('todo')"
592
+ >
593
+ <ListTodo :size="16" />
594
+ </button>
595
+ <button
596
+ type="button"
597
+ class="icon-button"
598
+ :aria-label="t('存为文档')"
599
+ :data-tooltip="t('存为文档')"
600
+ :disabled="!!busyAction"
601
+ @click="saveEmailAsMarkdown"
602
+ >
603
+ <FilePlus2 :size="16" />
604
+ </button>
605
+ </div>
606
+ <div class="mail-toolbar-group end">
607
+ <button
608
+ type="button"
609
+ class="icon-button"
610
+ :class="{ 'is-on': detail.summary.flagged }"
611
+ :aria-pressed="detail.summary.flagged"
612
+ :aria-label="detail.summary.flagged ? t('取消星标') : t('加星标')"
613
+ :data-tooltip="detail.summary.flagged ? t('取消星标') : t('加星标')"
614
+ @click="mail.toggleFlagged(detail.summary.id, !detail.summary.flagged)"
615
+ >
616
+ <Star :size="16" :class="{ 'mail-icon-star': detail.summary.flagged }" />
617
+ </button>
618
+ <button
619
+ type="button"
620
+ class="icon-button"
621
+ :aria-label="t('标为未读')"
622
+ :data-tooltip="t('标为未读')"
623
+ @click="mail.toggleSeen(detail.summary.id, false)"
624
+ >
625
+ <MailOpen :size="16" />
626
+ </button>
627
+ <button
628
+ type="button"
629
+ class="icon-button"
630
+ :aria-label="t('归档')"
631
+ :data-tooltip="t('归档')"
632
+ @click="runAction('archive', () => mail.moveToSpecialFolder(detail!.summary.id, 'archive'))"
633
+ >
634
+ <Archive :size="16" />
635
+ </button>
636
+ <button
637
+ type="button"
638
+ class="icon-button danger"
639
+ :aria-label="t('移至已删除')"
640
+ :data-tooltip="t('移至已删除')"
641
+ @click="runAction('trash', () => mail.moveToSpecialFolder(detail!.summary.id, 'trash'))"
642
+ >
643
+ <Trash2 :size="16" />
644
+ </button>
645
+ </div>
646
+ </div>
647
+
648
+ <div class="mail-reader-scroll">
649
+ <header class="mail-reader-header">
650
+ <h1 class="mail-reader-subject">{{ detail.summary.subject || t('(无主题)') }}</h1>
651
+ <div class="mail-reader-sender">
652
+ <span
653
+ class="mail-avatar lg"
654
+ :style="{ '--avatar-hue': avatarHue(detail.summary.from[0]) }"
655
+ aria-hidden="true"
656
+ >{{ senderInitial(detail.summary.from[0]) }}</span>
657
+ <div class="mail-reader-sender-text">
658
+ <div class="mail-reader-sender-line">
659
+ <strong>{{ senderLabel(detail.summary.from[0]) }}</strong>
660
+ <span v-if="detail.summary.from[0]?.name" class="mail-reader-address">
661
+ {{ detail.summary.from[0]?.address }}
662
+ </span>
663
+ <time class="mail-reader-time">{{ formatFullDate(detail.summary.dateTs) }}</time>
664
+ </div>
665
+ <div class="mail-reader-recipients">
666
+ <span>{{ t('收件人:') }}{{ formatMailAddressList(detail.summary.to) || t('未知') }}</span>
667
+ <span v-if="detail.cc.length">{{ t('抄送:') }}{{ formatMailAddressList(detail.cc) }}</span>
668
+ </div>
669
+ </div>
670
+ </div>
671
+
672
+ <Transition name="mail-notice">
673
+ <p v-if="actionError" key="err" class="mail-alert error" role="alert">
674
+ <AlertTriangle :size="14" />
675
+ <span>{{ actionError }}</span>
676
+ <button type="button" class="mail-alert-close" :aria-label="t('关闭')" @click="actionError = ''">
677
+ <X :size="13" />
678
+ </button>
679
+ </p>
680
+ <p v-else-if="actionFeedback" key="ok" class="mail-alert success" role="status">
681
+ <Check :size="14" /> <span>{{ actionFeedback }}</span>
682
+ </p>
683
+ </Transition>
684
+ </header>
685
+
686
+ <!-- Calendar invitation cards (.ics) -->
687
+ <section v-if="invitePreviews.length" class="mail-invites-section">
688
+ <div
689
+ v-for="{ invite, preview } in invitePreviews"
690
+ :key="invite.id"
691
+ class="mail-invite-card"
692
+ >
693
+ <span class="mail-invite-date" aria-hidden="true">
694
+ <template v-if="preview.start">
695
+ <small>{{ new Date(preview.start).toLocaleDateString('zh-CN', { month: 'short' }) }}</small>
696
+ <b>{{ new Date(preview.start).getDate() }}</b>
697
+ </template>
698
+ <CalendarDays v-else :size="18" />
699
+ </span>
700
+ <div class="mail-invite-info">
701
+ <strong>{{ preview.summary }}</strong>
702
+ <span v-if="preview.start" class="mail-invite-time">
703
+ {{ new Date(preview.start).toLocaleString('zh-CN', { weekday: 'short', hour: '2-digit', minute: '2-digit' }) }}
704
+ <template v-if="preview.end">
705
+ – {{ new Date(preview.end).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }) }}
706
+ </template>
707
+ </span>
708
+ <span v-if="preview.conflicts.length" class="mail-conflict-tag">
709
+ <AlertTriangle :size="12" />
710
+ {{ t('与现有 {0} 个日程时间重叠', [preview.conflicts.length]) }}
711
+ </span>
712
+ </div>
713
+ <div class="mail-invite-actions">
714
+ <template v-if="invite.method === 'REQUEST'">
715
+ <div class="mail-rsvp" role="group">
716
+ <button
717
+ type="button"
718
+ :class="{ selected: invite.rsvpStatus === 'ACCEPTED' }"
719
+ :disabled="!!busyAction"
720
+ @click="respondInvite(invite, 'ACCEPTED')"
721
+ >
722
+ {{ invite.rsvpStatus === 'ACCEPTED' ? t('已接受') : t('接受') }}
723
+ </button>
724
+ <button
725
+ type="button"
726
+ :class="{ selected: invite.rsvpStatus === 'TENTATIVE' }"
727
+ :disabled="!!busyAction"
728
+ @click="respondInvite(invite, 'TENTATIVE')"
729
+ >
730
+ {{ t('暂定') }}
731
+ </button>
732
+ <button
733
+ type="button"
734
+ class="decline"
735
+ :class="{ selected: invite.rsvpStatus === 'DECLINED' }"
736
+ :disabled="!!busyAction"
737
+ @click="respondInvite(invite, 'DECLINED')"
738
+ >
739
+ {{ t('拒绝') }}
740
+ </button>
741
+ </div>
742
+ </template>
743
+ <button
744
+ type="button"
745
+ class="mail-btn-secondary mail-btn-sm"
746
+ :disabled="!!busyAction || !!invite.importedObjectId"
747
+ @click="importInvite(invite, 'personal')"
748
+ >
749
+ <Check v-if="invite.importedObjectId" :size="13" />
750
+ {{ invite.importedObjectId ? t('已加入日历') : t('加入个人日历') }}
751
+ </button>
752
+ <button
753
+ v-if="plans.workspaceWritable && !invite.importedObjectId"
754
+ type="button"
755
+ class="mail-btn-ghost mail-btn-sm"
756
+ :disabled="!!busyAction"
757
+ @click="importInvite(invite, 'workspace')"
758
+ >
759
+ {{ t('加入工作区日历') }}
760
+ </button>
761
+ </div>
762
+ </div>
763
+ </section>
764
+
765
+ <!-- Privacy shield for remote images -->
766
+ <div
767
+ v-if="detail.hasRemoteImages && !allowRemoteImages"
768
+ class="mail-remote-banner"
769
+ >
770
+ <ImageIcon :size="14" />
771
+ <span>{{ t('为防止打开追踪,已默认拦截此邮件中的外部远程图片。') }}</span>
772
+ <button type="button" class="mail-link-btn" @click="allowRemoteImages = true">
773
+ {{ t('加载外部图片') }}
774
+ </button>
775
+ </div>
776
+
777
+ <!-- Sandboxed HTML or plain text body -->
778
+ <div class="mail-body-wrap">
779
+ <iframe
780
+ v-if="sandboxSrcdoc"
781
+ class="mail-body-iframe"
782
+ :title="detail.summary.subject || t('邮件正文')"
783
+ sandbox="allow-popups allow-popups-to-escape-sandbox"
784
+ referrerpolicy="no-referrer"
785
+ :srcdoc="sandboxSrcdoc"
786
+ />
787
+ <pre v-else class="mail-body-plain">{{ detail.textBody || detail.summary.snippet }}</pre>
788
+ </div>
789
+
790
+ <!-- Attachments -->
791
+ <section v-if="visibleAttachments.length" class="mail-attachments-bar">
792
+ <h3><Paperclip :size="13" /> {{ t('附件({0})', [visibleAttachments.length]) }}</h3>
793
+ <div class="mail-attachments-list">
794
+ <button
795
+ v-for="att in visibleAttachments"
796
+ :key="att.id"
797
+ type="button"
798
+ class="mail-attachment-card"
799
+ :disabled="!!busyAction"
800
+ :title="att.filename"
801
+ @click="downloadAttachment(att)"
802
+ >
803
+ <span class="mail-attachment-icon"><FileText :size="16" /></span>
804
+ <span class="mail-attachment-text">
805
+ <span class="mail-attachment-name">{{ att.filename }}</span>
806
+ <small>{{ formatSize(att.sizeBytes) }}</small>
807
+ </span>
808
+ <Download :size="14" class="mail-attachment-dl" />
809
+ </button>
810
+ </div>
811
+ </section>
812
+ </div>
813
+ </article>
814
+ </main>
815
+ </div>
816
+
817
+ <MailAccountDialog />
818
+ <MailComposerDialog />
819
+ </div>
820
+ </template>