@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import '../../styles/mail.css';
|
|
3
|
+
import { onMounted } from 'vue';
|
|
4
|
+
import {
|
|
5
|
+
Archive,
|
|
6
|
+
FileText,
|
|
7
|
+
Folder,
|
|
8
|
+
Inbox,
|
|
9
|
+
PenSquare,
|
|
10
|
+
Plus,
|
|
11
|
+
RefreshCw,
|
|
12
|
+
Send,
|
|
13
|
+
Settings2,
|
|
14
|
+
Star,
|
|
15
|
+
Trash2,
|
|
16
|
+
} from 'lucide-vue-next';
|
|
17
|
+
import { t } from '../../i18n/i18n';
|
|
18
|
+
import { useMailStore } from '../../stores/mail';
|
|
19
|
+
|
|
20
|
+
const emit = defineEmits<{ openMail: [] }>();
|
|
21
|
+
const mail = useMailStore();
|
|
22
|
+
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
void mail.init();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function folderIcon(specialUse: string | null) {
|
|
28
|
+
switch (specialUse) {
|
|
29
|
+
case 'inbox':
|
|
30
|
+
return Inbox;
|
|
31
|
+
case 'sent':
|
|
32
|
+
return Send;
|
|
33
|
+
case 'drafts':
|
|
34
|
+
return FileText;
|
|
35
|
+
case 'trash':
|
|
36
|
+
return Trash2;
|
|
37
|
+
case 'archive':
|
|
38
|
+
return Archive;
|
|
39
|
+
case 'flagged':
|
|
40
|
+
return Star;
|
|
41
|
+
default:
|
|
42
|
+
return Folder;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function pickFolder(folderId: string) {
|
|
47
|
+
emit('openMail');
|
|
48
|
+
await mail.selectFolder(folderId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function compose() {
|
|
52
|
+
emit('openMail');
|
|
53
|
+
mail.openComposer();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function openAccounts() {
|
|
57
|
+
emit('openMail');
|
|
58
|
+
mail.accountDialogOpen = true;
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<div class="sidebar-mail">
|
|
64
|
+
<!-- View-level actions live on the view's own header row (VSCode-style). -->
|
|
65
|
+
<div class="sidebar-mail-head">
|
|
66
|
+
<button
|
|
67
|
+
v-if="mail.accounts.length"
|
|
68
|
+
type="button"
|
|
69
|
+
class="sidebar-mail-row sidebar-mail-compose"
|
|
70
|
+
@click="compose"
|
|
71
|
+
>
|
|
72
|
+
<PenSquare :size="15" />
|
|
73
|
+
<span>{{ t('写邮件') }}</span>
|
|
74
|
+
</button>
|
|
75
|
+
<span v-else class="sidebar-mail-title">{{ t('邮箱') }}</span>
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
class="icon-button sidebar-mail-head-icon"
|
|
79
|
+
:aria-label="t('管理邮箱账号')"
|
|
80
|
+
:data-tooltip="t('管理邮箱账号')"
|
|
81
|
+
@click="openAccounts"
|
|
82
|
+
>
|
|
83
|
+
<Settings2 :size="15" />
|
|
84
|
+
</button>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<div v-if="!mail.accounts.length" class="sidebar-mail-empty">
|
|
88
|
+
<button type="button" class="sidebar-mail-row sidebar-mail-connect" @click="openAccounts">
|
|
89
|
+
<Plus :size="15" />
|
|
90
|
+
<span>{{ t('连接第一个邮箱') }}</span>
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<div v-else class="sidebar-mail-tree">
|
|
95
|
+
<section v-for="account in mail.accounts" :key="account.id" class="sidebar-mail-account">
|
|
96
|
+
<header class="sidebar-mail-account-head" :title="account.email">
|
|
97
|
+
<span class="sidebar-mail-account-name">{{ account.label || account.email }}</span>
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
class="icon-button sidebar-mail-sync"
|
|
101
|
+
:class="{ busy: mail.syncingAccountId === account.id }"
|
|
102
|
+
:aria-label="t('同步此邮箱')"
|
|
103
|
+
:data-tooltip="t('同步此邮箱')"
|
|
104
|
+
:disabled="mail.syncingAccountId === account.id"
|
|
105
|
+
@click="mail.syncAccount(account.id)"
|
|
106
|
+
>
|
|
107
|
+
<RefreshCw :size="13" :class="{ spinning: mail.syncingAccountId === account.id }" />
|
|
108
|
+
</button>
|
|
109
|
+
</header>
|
|
110
|
+
|
|
111
|
+
<ul class="sidebar-mail-folder-list">
|
|
112
|
+
<li
|
|
113
|
+
v-for="folder in mail.foldersByAccount.get(account.id) ?? []"
|
|
114
|
+
:key="folder.id"
|
|
115
|
+
>
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
class="sidebar-mail-row sidebar-mail-folder"
|
|
119
|
+
:class="{ active: mail.selectedFolderId === folder.id, unread: folder.unreadCount > 0 }"
|
|
120
|
+
:aria-current="mail.selectedFolderId === folder.id ? 'page' : undefined"
|
|
121
|
+
@click="pickFolder(folder.id)"
|
|
122
|
+
>
|
|
123
|
+
<component :is="folderIcon(folder.specialUse)" :size="15" />
|
|
124
|
+
<span class="sidebar-mail-folder-name">{{ folder.displayName }}</span>
|
|
125
|
+
<span v-if="folder.unreadCount > 0" class="sidebar-mail-count">
|
|
126
|
+
{{ folder.unreadCount > 999 ? '999+' : folder.unreadCount }}
|
|
127
|
+
</span>
|
|
128
|
+
</button>
|
|
129
|
+
</li>
|
|
130
|
+
</ul>
|
|
131
|
+
</section>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import type { MailAddress } from './types';
|
|
3
|
+
|
|
4
|
+
/** First visible character of a sender, upper-cased for Latin names. */
|
|
5
|
+
export function senderInitial(addr: MailAddress | undefined): string {
|
|
6
|
+
const source = (addr?.name || addr?.address || '?').trim().replace(/^["'<(]+/, '');
|
|
7
|
+
const first = Array.from(source)[0] ?? '?';
|
|
8
|
+
return first.toLocaleUpperCase();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Stable hue per address so the same sender keeps the same (muted) tint. */
|
|
12
|
+
export function avatarHue(addr: MailAddress | undefined): number {
|
|
13
|
+
const key = (addr?.address || addr?.name || '').toLowerCase();
|
|
14
|
+
let hash = 0;
|
|
15
|
+
for (let i = 0; i < key.length; i++) hash = (hash * 31 + key.charCodeAt(i)) | 0;
|
|
16
|
+
return Math.abs(hash) % 360;
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { nativeInvoke as invoke } from '../platform/native-bridge';
|
|
3
|
+
import type {
|
|
4
|
+
MailAccount,
|
|
5
|
+
MailAccountInput,
|
|
6
|
+
MailCacheStats,
|
|
7
|
+
MailCredentials,
|
|
8
|
+
MailDownloadedAttachment,
|
|
9
|
+
MailDraft,
|
|
10
|
+
MailFilter,
|
|
11
|
+
MailFlagsPatch,
|
|
12
|
+
MailFolder,
|
|
13
|
+
MailMessageDetail,
|
|
14
|
+
MailMessageSummary,
|
|
15
|
+
MailPreset,
|
|
16
|
+
MailSendRequest,
|
|
17
|
+
MailSendResult,
|
|
18
|
+
MailSyncSummary,
|
|
19
|
+
MailTestResult,
|
|
20
|
+
} from './types';
|
|
21
|
+
|
|
22
|
+
export const mailBridge = {
|
|
23
|
+
presetsList: () => invoke<MailPreset[]>('mail_presets_list'),
|
|
24
|
+
accountsList: () => invoke<MailAccount[]>('mail_accounts_list'),
|
|
25
|
+
accountTest: (input: MailAccountInput, credentials: MailCredentials) =>
|
|
26
|
+
invoke<MailTestResult>('mail_account_test', { input, credentials }),
|
|
27
|
+
accountSave: (input: MailAccountInput, credentials?: MailCredentials) =>
|
|
28
|
+
invoke<MailAccount>('mail_account_save', { input, credentials: credentials ?? null }),
|
|
29
|
+
accountRemove: (accountId: string) => invoke<void>('mail_account_remove', { accountId }),
|
|
30
|
+
foldersList: (accountId?: string) =>
|
|
31
|
+
invoke<MailFolder[]>('mail_folders_list', { accountId: accountId ?? null }),
|
|
32
|
+
syncAccount: (accountId: string) => invoke<MailSyncSummary>('mail_sync_account', { accountId }),
|
|
33
|
+
syncFolder: (folderId: string) => invoke<MailSyncSummary>('mail_sync_folder', { folderId }),
|
|
34
|
+
messagesList: (folderId: string, options?: { limit?: number; offset?: number; filter?: MailFilter }) =>
|
|
35
|
+
invoke<MailMessageSummary[]>('mail_messages_list', {
|
|
36
|
+
folderId,
|
|
37
|
+
limit: options?.limit ?? 60,
|
|
38
|
+
offset: options?.offset ?? 0,
|
|
39
|
+
filter: options?.filter && options.filter !== 'all' ? options.filter : null,
|
|
40
|
+
}),
|
|
41
|
+
messagesSearch: (query: string, accountId?: string, limit = 60) =>
|
|
42
|
+
invoke<MailMessageSummary[]>('mail_messages_search', {
|
|
43
|
+
accountId: accountId ?? null,
|
|
44
|
+
query,
|
|
45
|
+
limit,
|
|
46
|
+
}),
|
|
47
|
+
messageGet: (messageId: string, forceRefresh = false) =>
|
|
48
|
+
invoke<MailMessageDetail>('mail_message_get', { messageId, forceRefresh }),
|
|
49
|
+
updateFlags: (messageId: string, patch: MailFlagsPatch) =>
|
|
50
|
+
invoke<MailMessageDetail>('mail_message_flags_update', { messageId, patch }),
|
|
51
|
+
moveMessage: (messageId: string, targetFolderId: string) =>
|
|
52
|
+
invoke<void>('mail_message_move', { messageId, targetFolderId }),
|
|
53
|
+
updateInvite: (inviteId: string, importedObjectId?: string | null, rsvpStatus?: string | null) =>
|
|
54
|
+
invoke<void>('mail_invite_update', {
|
|
55
|
+
inviteId,
|
|
56
|
+
importedObjectId: importedObjectId ?? null,
|
|
57
|
+
rsvpStatus: rsvpStatus ?? null,
|
|
58
|
+
}),
|
|
59
|
+
downloadAttachment: (attachmentId: string) =>
|
|
60
|
+
invoke<MailDownloadedAttachment>('mail_attachment_download', { attachmentId }),
|
|
61
|
+
sendMail: (request: MailSendRequest) => invoke<MailSendResult>('mail_send', { request }),
|
|
62
|
+
cacheStats: () => invoke<MailCacheStats>('mail_cache_stats'),
|
|
63
|
+
cacheClear: () => invoke<MailCacheStats>('mail_cache_clear'),
|
|
64
|
+
draftsList: (accountId?: string) =>
|
|
65
|
+
invoke<MailDraft[]>('mail_drafts_list', { accountId: accountId ?? null }),
|
|
66
|
+
draftSave: (draft: MailDraft) => invoke<MailDraft>('mail_draft_save', { draft }),
|
|
67
|
+
draftDelete: (draftId: string) => invoke<void>('mail_draft_delete', { draftId }),
|
|
68
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import type { WorkspaceObject } from '@tano/protocol';
|
|
3
|
+
import type { ObjectRecord } from '../objects/workspace-objects';
|
|
4
|
+
import { parseCalendar } from '../plan-sync/ical';
|
|
5
|
+
import { itemProperties } from '../plan-sync/types';
|
|
6
|
+
import { hasEventTime } from '../plans/calendar';
|
|
7
|
+
import {
|
|
8
|
+
formatMailAddressList,
|
|
9
|
+
type MailCalendarInvite,
|
|
10
|
+
type MailMessageDetail,
|
|
11
|
+
type RsvpResponseStatus,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
export interface ParsedInvitePreview {
|
|
15
|
+
summary: string;
|
|
16
|
+
start?: string;
|
|
17
|
+
end?: string;
|
|
18
|
+
allDay?: boolean;
|
|
19
|
+
description: string;
|
|
20
|
+
organizerEmail: string | null;
|
|
21
|
+
conflicts: ObjectRecord[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function extractOrganizerEmail(rawIcs: string): string | null {
|
|
25
|
+
const unfolded = rawIcs.replace(/\r?\n[ \t]/g, '');
|
|
26
|
+
const match = unfolded.match(/^ORGANIZER[^:\r\n]*:(?:mailto:)?([^\r\n\s;]+)/im);
|
|
27
|
+
return match?.[1]?.trim() || null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function parseInvitePreview(
|
|
31
|
+
invite: MailCalendarInvite,
|
|
32
|
+
existingRecords: readonly ObjectRecord[],
|
|
33
|
+
): ParsedInvitePreview {
|
|
34
|
+
const organizerEmail = extractOrganizerEmail(invite.rawIcs);
|
|
35
|
+
try {
|
|
36
|
+
const parsed = parseCalendar(invite.rawIcs, 'calendar');
|
|
37
|
+
const first = parsed.items[0]?.value;
|
|
38
|
+
if (first) {
|
|
39
|
+
const conflicts = findOverlappingEvents(existingRecords, first.start, first.end);
|
|
40
|
+
return {
|
|
41
|
+
summary: first.name || invite.summary,
|
|
42
|
+
start: first.start,
|
|
43
|
+
end: first.end,
|
|
44
|
+
allDay: first.allDay,
|
|
45
|
+
description: first.description,
|
|
46
|
+
organizerEmail,
|
|
47
|
+
conflicts,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
// Fall back to lightweight header metadata when the ICS lacks optional VTIMEZONE definitions.
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
summary: invite.summary || '日历邀请',
|
|
55
|
+
description: '',
|
|
56
|
+
organizerEmail,
|
|
57
|
+
conflicts: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function findOverlappingEvents(
|
|
62
|
+
records: readonly ObjectRecord[],
|
|
63
|
+
startIso?: string,
|
|
64
|
+
endIso?: string,
|
|
65
|
+
): ObjectRecord[] {
|
|
66
|
+
if (!startIso || !endIso) return [];
|
|
67
|
+
const start = Date.parse(startIso);
|
|
68
|
+
const end = Date.parse(endIso);
|
|
69
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return [];
|
|
70
|
+
return records.filter((record) => {
|
|
71
|
+
if (record.object.archived || !hasEventTime(record)) return false;
|
|
72
|
+
const from = Date.parse(String(record.object.properties.start));
|
|
73
|
+
const to = Date.parse(String(record.object.properties.end));
|
|
74
|
+
return from < end && to > start;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function buildEventDraftFromInvite(
|
|
79
|
+
invite: MailCalendarInvite,
|
|
80
|
+
detail: MailMessageDetail,
|
|
81
|
+
existingRecords: readonly ObjectRecord[],
|
|
82
|
+
): Pick<WorkspaceObject, 'type' | 'name' | 'description' | 'archived' | 'properties'> {
|
|
83
|
+
const preview = parseInvitePreview(invite, existingRecords);
|
|
84
|
+
const sourceNote = [
|
|
85
|
+
`来源邮件:${detail.summary.subject}`,
|
|
86
|
+
`发件人:${formatMailAddressList(detail.summary.from)}`,
|
|
87
|
+
detail.summary.messageId ? `Message-ID: ${detail.summary.messageId}` : '',
|
|
88
|
+
]
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.join('\n');
|
|
91
|
+
const description = [preview.description.trim(), sourceNote].filter(Boolean).join('\n\n').slice(0, 18_000);
|
|
92
|
+
const properties = itemProperties(
|
|
93
|
+
{
|
|
94
|
+
name: preview.summary,
|
|
95
|
+
description,
|
|
96
|
+
start: preview.start,
|
|
97
|
+
end: preview.end,
|
|
98
|
+
allDay: preview.allDay,
|
|
99
|
+
archived: false,
|
|
100
|
+
},
|
|
101
|
+
'calendar',
|
|
102
|
+
);
|
|
103
|
+
return {
|
|
104
|
+
type: 'event',
|
|
105
|
+
name: preview.summary.slice(0, 200),
|
|
106
|
+
description,
|
|
107
|
+
archived: false,
|
|
108
|
+
properties,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function buildPlanDraftFromEmail(
|
|
113
|
+
detail: MailMessageDetail,
|
|
114
|
+
mode: 'calendar' | 'todo',
|
|
115
|
+
now = new Date(),
|
|
116
|
+
): Pick<WorkspaceObject, 'type' | 'name' | 'description' | 'archived' | 'properties'> {
|
|
117
|
+
const name = (detail.summary.subject || '来自邮件的事项').slice(0, 200);
|
|
118
|
+
const excerpt = (detail.textBody || detail.summary.snippet || '').trim().slice(0, 3000);
|
|
119
|
+
const description = [
|
|
120
|
+
`发件人:${formatMailAddressList(detail.summary.from)}`,
|
|
121
|
+
detail.summary.messageId ? `Message-ID: ${detail.summary.messageId}` : '',
|
|
122
|
+
excerpt,
|
|
123
|
+
]
|
|
124
|
+
.filter(Boolean)
|
|
125
|
+
.join('\n\n');
|
|
126
|
+
|
|
127
|
+
if (mode === 'todo') {
|
|
128
|
+
const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
|
|
129
|
+
return {
|
|
130
|
+
type: 'event',
|
|
131
|
+
name,
|
|
132
|
+
description,
|
|
133
|
+
archived: false,
|
|
134
|
+
properties: {
|
|
135
|
+
due: today,
|
|
136
|
+
checkable: true,
|
|
137
|
+
completed: false,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const start = new Date(now.getTime());
|
|
143
|
+
start.setMinutes(0, 0, 0);
|
|
144
|
+
start.setHours(start.getHours() + 1);
|
|
145
|
+
const end = new Date(start.getTime() + 60 * 60 * 1000);
|
|
146
|
+
return {
|
|
147
|
+
type: 'event',
|
|
148
|
+
name,
|
|
149
|
+
description,
|
|
150
|
+
archived: false,
|
|
151
|
+
properties: {
|
|
152
|
+
start: start.toISOString(),
|
|
153
|
+
end: end.toISOString(),
|
|
154
|
+
checkable: false,
|
|
155
|
+
completed: false,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Generates an RFC 5546 iTIP `METHOD:REPLY` VCALENDAR payload so the desktop client
|
|
162
|
+
* can send a real calendar RSVP through the user's own SMTP server.
|
|
163
|
+
*/
|
|
164
|
+
export function buildRsvpReplyIcs(
|
|
165
|
+
rawIcs: string,
|
|
166
|
+
attendeeEmail: string,
|
|
167
|
+
attendeeName: string,
|
|
168
|
+
status: RsvpResponseStatus,
|
|
169
|
+
now = new Date(),
|
|
170
|
+
): string {
|
|
171
|
+
const unfolded = rawIcs.replace(/\r?\n[ \t]/g, '');
|
|
172
|
+
const pick = (prop: string) => {
|
|
173
|
+
const m = unfolded.match(new RegExp(`^(${prop}(?:;[^:\\r\\n]*)?:[^\\r\\n]+)$`, 'im'));
|
|
174
|
+
return m?.[1]?.trim() ?? '';
|
|
175
|
+
};
|
|
176
|
+
const uidLine = pick('UID') || `UID:tano-${crypto.randomUUID()}`;
|
|
177
|
+
const dtstartLine = pick('DTSTART');
|
|
178
|
+
const dtendLine = pick('DTEND');
|
|
179
|
+
const summaryLine = pick('SUMMARY') || 'SUMMARY:Meeting';
|
|
180
|
+
const organizerLine = pick('ORGANIZER');
|
|
181
|
+
const sequenceLine = pick('SEQUENCE');
|
|
182
|
+
const stamp = now.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, 'Z');
|
|
183
|
+
const safeCn = attendeeName.replace(/["\r\n;,:]/g, ' ').trim();
|
|
184
|
+
const attendeeLine = safeCn
|
|
185
|
+
? `ATTENDEE;CN="${safeCn}";PARTSTAT=${status}:mailto:${attendeeEmail}`
|
|
186
|
+
: `ATTENDEE;PARTSTAT=${status}:mailto:${attendeeEmail}`;
|
|
187
|
+
|
|
188
|
+
return [
|
|
189
|
+
'BEGIN:VCALENDAR',
|
|
190
|
+
'PRODID:-//Tano//Desktop Mail//EN',
|
|
191
|
+
'VERSION:2.0',
|
|
192
|
+
'METHOD:REPLY',
|
|
193
|
+
'BEGIN:VEVENT',
|
|
194
|
+
uidLine,
|
|
195
|
+
`DTSTAMP:${stamp}`,
|
|
196
|
+
dtstartLine,
|
|
197
|
+
dtendLine,
|
|
198
|
+
summaryLine,
|
|
199
|
+
organizerLine,
|
|
200
|
+
sequenceLine,
|
|
201
|
+
attendeeLine,
|
|
202
|
+
'END:VEVENT',
|
|
203
|
+
'END:VCALENDAR',
|
|
204
|
+
'',
|
|
205
|
+
]
|
|
206
|
+
.filter((line, index, all) => line.length > 0 || index === all.length - 1)
|
|
207
|
+
.join('\r\n');
|
|
208
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { formatMailAddressList, type MailMessageDetail } from './types';
|
|
3
|
+
|
|
4
|
+
function escapeYaml(value: string): string {
|
|
5
|
+
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\r?\n/g, ' ')}"`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function escapeHtml(value: string): string {
|
|
9
|
+
return value
|
|
10
|
+
.replace(/&/g, '&')
|
|
11
|
+
.replace(/</g, '<')
|
|
12
|
+
.replace(/>/g, '>')
|
|
13
|
+
.replace(/"/g, '"');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function safeMailDocumentPath(detail: MailMessageDetail, folderPrefix = ''): string {
|
|
17
|
+
const date = new Date((detail.summary.dateTs || Math.floor(Date.now() / 1000)) * 1000);
|
|
18
|
+
const day = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
19
|
+
const cleanedSubject = (detail.summary.subject || '无主题邮件')
|
|
20
|
+
.replace(/[<>:"/\\|?*\u0000-\u001f]/g, ' ')
|
|
21
|
+
.replace(/\s+/g, ' ')
|
|
22
|
+
.trim()
|
|
23
|
+
.slice(0, 64);
|
|
24
|
+
const filename = `${day} ${cleanedSubject || '邮件'}.md`;
|
|
25
|
+
const prefix = folderPrefix.replace(/^\/+|\/+$/g, '');
|
|
26
|
+
return prefix ? `${prefix}/${filename}` : filename;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function emailToMarkdownDocument(
|
|
30
|
+
detail: MailMessageDetail,
|
|
31
|
+
importedAttachments: readonly { filename: string; relativePath: string }[] = [],
|
|
32
|
+
): string {
|
|
33
|
+
const sentAt = detail.summary.dateTs
|
|
34
|
+
? new Date(detail.summary.dateTs * 1000).toISOString()
|
|
35
|
+
: new Date().toISOString();
|
|
36
|
+
const from = formatMailAddressList(detail.summary.from);
|
|
37
|
+
const to = formatMailAddressList(detail.summary.to);
|
|
38
|
+
const cc = formatMailAddressList(detail.cc);
|
|
39
|
+
|
|
40
|
+
const frontmatter = [
|
|
41
|
+
'---',
|
|
42
|
+
`title: ${escapeYaml(detail.summary.subject || '无主题邮件')}`,
|
|
43
|
+
'source: mail',
|
|
44
|
+
`date: ${escapeYaml(sentAt)}`,
|
|
45
|
+
`mail_from: ${escapeYaml(from)}`,
|
|
46
|
+
`mail_to: ${escapeYaml(to)}`,
|
|
47
|
+
...(cc ? [`mail_cc: ${escapeYaml(cc)}`] : []),
|
|
48
|
+
...(detail.summary.messageId ? [`mail_message_id: ${escapeYaml(detail.summary.messageId)}`] : []),
|
|
49
|
+
'---',
|
|
50
|
+
].join('\n');
|
|
51
|
+
|
|
52
|
+
const body = (detail.textBody || stripHtmlToPlain(detail.htmlSanitized) || detail.summary.snippet).trim();
|
|
53
|
+
const headerLines = [
|
|
54
|
+
`# ${detail.summary.subject || '无主题邮件'}`,
|
|
55
|
+
'',
|
|
56
|
+
`- **发件人**:${from || '未知'}`,
|
|
57
|
+
`- **收件人**:${to || '未知'}`,
|
|
58
|
+
...(cc ? [`- **抄送**:${cc}`] : []),
|
|
59
|
+
`- **时间**:${new Date(sentAt).toLocaleString('zh-CN')}`,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const attachmentSection = importedAttachments.length
|
|
63
|
+
? [
|
|
64
|
+
'',
|
|
65
|
+
'## 附件',
|
|
66
|
+
'',
|
|
67
|
+
...importedAttachments.map((item) => `- [${item.filename}](${encodeURI(item.relativePath)})`),
|
|
68
|
+
]
|
|
69
|
+
: [];
|
|
70
|
+
|
|
71
|
+
return `${frontmatter}\n\n${headerLines.join('\n')}\n\n---\n\n${body}\n${attachmentSection.join('\n')}\n`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Converts lightweight Markdown from the mail composer into clean, email-client-safe HTML.
|
|
76
|
+
*/
|
|
77
|
+
export function markdownToEmailHtml(markdown: string): string {
|
|
78
|
+
const lines = markdown.replace(/\r\n/g, '\n').split('\n');
|
|
79
|
+
const blocks: string[] = [];
|
|
80
|
+
let inList = false;
|
|
81
|
+
|
|
82
|
+
const closeList = () => {
|
|
83
|
+
if (inList) {
|
|
84
|
+
blocks.push('</ul>');
|
|
85
|
+
inList = false;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
for (const rawLine of lines) {
|
|
90
|
+
const line = rawLine.trimEnd();
|
|
91
|
+
if (!line.trim()) {
|
|
92
|
+
closeList();
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const heading = line.match(/^(#{1,3})\s+(.+)$/);
|
|
96
|
+
if (heading) {
|
|
97
|
+
closeList();
|
|
98
|
+
const level = heading[1]!.length;
|
|
99
|
+
blocks.push(`<h${level} style="margin:14px 0 8px;line-height:1.4;">${renderInline(heading[2]!)}</h${level}>`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const bullet = line.match(/^[-*]\s+(.+)$/);
|
|
103
|
+
if (bullet) {
|
|
104
|
+
if (!inList) {
|
|
105
|
+
blocks.push('<ul style="margin:8px 0;padding-left:20px;">');
|
|
106
|
+
inList = true;
|
|
107
|
+
}
|
|
108
|
+
blocks.push(`<li style="margin:4px 0;">${renderInline(bullet[1]!)}</li>`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const quote = line.match(/^>\s?(.*)$/);
|
|
112
|
+
if (quote) {
|
|
113
|
+
closeList();
|
|
114
|
+
blocks.push(
|
|
115
|
+
`<blockquote style="margin:8px 0;padding:4px 12px;border-left:3px solid #d0d5dd;color:#475467;">${renderInline(quote[1]!)}</blockquote>`,
|
|
116
|
+
);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
closeList();
|
|
120
|
+
blocks.push(`<p style="margin:8px 0;line-height:1.65;">${renderInline(line)}</p>`);
|
|
121
|
+
}
|
|
122
|
+
closeList();
|
|
123
|
+
|
|
124
|
+
return `<!doctype html><html><body style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC',sans-serif;font-size:14px;color:#1f2328;line-height:1.65;">${blocks.join('')}</body></html>`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function renderInline(text: string): string {
|
|
128
|
+
let out = escapeHtml(text);
|
|
129
|
+
out = out.replace(/`([^`]+)`/g, '<code style="background:#f3f4f6;padding:1px 4px;border-radius:4px;">$1</code>');
|
|
130
|
+
out = out.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
|
131
|
+
out = out.replace(/\*([^*]+)\*/g, '<em>$1</em>');
|
|
132
|
+
out = out.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Builds the sandboxed `<iframe srcdoc>` content for rendering sanitized HTML emails.
|
|
138
|
+
* Remote images remain blocked unless `allowRemoteImages` is explicitly toggled on for the message.
|
|
139
|
+
*/
|
|
140
|
+
export function buildSandboxedEmailSrcdoc(sanitizedHtml: string, allowRemoteImages: boolean): string {
|
|
141
|
+
const rendered = allowRemoteImages
|
|
142
|
+
? sanitizedHtml.replace(/\bdata-tano-remote-src="(https?:\/\/[^"]+)"/gi, 'src="$1"')
|
|
143
|
+
: sanitizedHtml;
|
|
144
|
+
const csp = allowRemoteImages
|
|
145
|
+
? "default-src 'none'; img-src data: https: http:; style-src 'unsafe-inline';"
|
|
146
|
+
: "default-src 'none'; img-src data:; style-src 'unsafe-inline';";
|
|
147
|
+
return `<!doctype html>
|
|
148
|
+
<html>
|
|
149
|
+
<head>
|
|
150
|
+
<meta charset="utf-8" />
|
|
151
|
+
<meta http-equiv="Content-Security-Policy" content="${csp}" />
|
|
152
|
+
<base target="_blank" />
|
|
153
|
+
<style>
|
|
154
|
+
html, body {
|
|
155
|
+
margin: 0;
|
|
156
|
+
padding: 16px;
|
|
157
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
158
|
+
font-size: 14px;
|
|
159
|
+
line-height: 1.65;
|
|
160
|
+
color: #1f2328;
|
|
161
|
+
background: #ffffff;
|
|
162
|
+
word-break: break-word;
|
|
163
|
+
overflow-wrap: anywhere;
|
|
164
|
+
}
|
|
165
|
+
img { max-width: 100%; height: auto; }
|
|
166
|
+
table { max-width: 100%; border-collapse: collapse; }
|
|
167
|
+
blockquote {
|
|
168
|
+
margin: 8px 0;
|
|
169
|
+
padding: 4px 12px;
|
|
170
|
+
border-left: 3px solid #d0d5dd;
|
|
171
|
+
color: #57606a;
|
|
172
|
+
}
|
|
173
|
+
a { color: #3b5bdb; }
|
|
174
|
+
pre, code {
|
|
175
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
176
|
+
white-space: pre-wrap;
|
|
177
|
+
}
|
|
178
|
+
</style>
|
|
179
|
+
</head>
|
|
180
|
+
<body>${rendered}</body>
|
|
181
|
+
</html>`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function stripHtmlToPlain(html: string): string {
|
|
185
|
+
return html
|
|
186
|
+
.replace(/<br\s*\/?>/gi, '\n')
|
|
187
|
+
.replace(/<\/(p|div|li|tr|h[1-6])>/gi, '\n')
|
|
188
|
+
.replace(/<[^>]+>/g, '')
|
|
189
|
+
.replace(/ /g, ' ')
|
|
190
|
+
.replace(/&/g, '&')
|
|
191
|
+
.replace(/</g, '<')
|
|
192
|
+
.replace(/>/g, '>')
|
|
193
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
194
|
+
.trim();
|
|
195
|
+
}
|