@dsh-plus/notify-email 0.1.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.
@@ -0,0 +1,83 @@
1
+ /**
2
+ * 配置卡片数据通道:同源 fetch 调自建 webServer 路由。
3
+ * (官方 settings.* RPC 白名单硬编码不含第三方 namespace,见 config-api.ts 注释。)
4
+ * @module notify-email/client/api
5
+ */
6
+
7
+ export interface WireSmtp {
8
+ host: string
9
+ port: number
10
+ secure: boolean
11
+ user: string
12
+ from: string
13
+ passConfigured: boolean
14
+ }
15
+
16
+ export interface WireTriggers {
17
+ onComplete: boolean
18
+ onError: boolean
19
+ onAborted: boolean
20
+ onQuestion: boolean
21
+ onPlanReview: boolean
22
+ }
23
+
24
+ export interface WireConfig {
25
+ enabled: boolean
26
+ smtp: WireSmtp
27
+ to: string[]
28
+ triggers: WireTriggers
29
+ idleDebounceMs: number
30
+ maxBodyChars: number
31
+ dryRun: boolean
32
+ writable: boolean
33
+ }
34
+
35
+ export interface WirePatch {
36
+ enabled: boolean
37
+ smtp: {
38
+ host: string
39
+ port: number
40
+ secure: boolean
41
+ user: string
42
+ pass: string
43
+ from: string
44
+ }
45
+ to: string[]
46
+ triggers: WireTriggers
47
+ idleDebounceMs: number
48
+ maxBodyChars: number
49
+ dryRun: boolean
50
+ }
51
+
52
+ export interface TestResult {
53
+ ok: boolean
54
+ detail: string
55
+ }
56
+
57
+ const ROUTE_CONFIG = '/dsh-plus/notify-email/config'
58
+ const ROUTE_TEST = '/dsh-plus/notify-email/test'
59
+
60
+ async function parse<T>(res: Response): Promise<T> {
61
+ const body = (await res.json()) as T & { error?: string }
62
+ if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`)
63
+ return body
64
+ }
65
+
66
+ export async function fetchConfig(): Promise<WireConfig> {
67
+ return parse<WireConfig>(await fetch(ROUTE_CONFIG, { credentials: 'same-origin' }))
68
+ }
69
+
70
+ export async function saveConfig(patch: WirePatch): Promise<WireConfig> {
71
+ return parse<WireConfig>(
72
+ await fetch(ROUTE_CONFIG, {
73
+ method: 'PUT',
74
+ credentials: 'same-origin',
75
+ headers: { 'content-type': 'application/json' },
76
+ body: JSON.stringify(patch),
77
+ }),
78
+ )
79
+ }
80
+
81
+ export async function sendTest(): Promise<TestResult> {
82
+ return parse<TestResult>(await fetch(ROUTE_TEST, { method: 'POST', credentials: 'same-origin' }))
83
+ }
@@ -0,0 +1,239 @@
1
+ /**
2
+ * 「邮件通知」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
3
+ * 交互对齐官方卡片:折叠/展开、staged draft、未保存标记、保存/放弃;
4
+ * 另加「发送测试邮件」。数据走自建同源路由(api.ts)。
5
+ * @module notify-email/client/card
6
+ */
7
+ import { useEffect, useMemo, useState, type ReactElement } from 'react'
8
+
9
+ import {
10
+ fetchConfig, saveConfig, sendTest, type WireConfig, type WirePatch, type WireTriggers,
11
+ } from './api.ts'
12
+ import { CheckRow, TextField } from './fields.tsx'
13
+
14
+ export interface CardProps {
15
+ t(key: string): string
16
+ }
17
+
18
+ interface Draft {
19
+ enabled: boolean
20
+ host: string
21
+ port: string
22
+ secure: boolean
23
+ user: string
24
+ pass: string
25
+ from: string
26
+ toText: string
27
+ triggers: WireTriggers
28
+ idleDebounceMs: string
29
+ maxBodyChars: string
30
+ dryRun: boolean
31
+ }
32
+
33
+ interface Status {
34
+ kind: 'idle' | 'ok' | 'error'
35
+ text: string
36
+ }
37
+
38
+ const IDLE_STATUS: Status = { kind: 'idle', text: '' }
39
+
40
+ function draftFromWire(wire: WireConfig): Draft {
41
+ return {
42
+ enabled: wire.enabled,
43
+ host: wire.smtp.host,
44
+ port: String(wire.smtp.port),
45
+ secure: wire.smtp.secure,
46
+ user: wire.smtp.user,
47
+ pass: '',
48
+ from: wire.smtp.from,
49
+ toText: wire.to.join(', '),
50
+ triggers: { ...wire.triggers },
51
+ idleDebounceMs: String(wire.idleDebounceMs),
52
+ maxBodyChars: String(wire.maxBodyChars),
53
+ dryRun: wire.dryRun,
54
+ }
55
+ }
56
+
57
+ function isPositiveInt(text: string): boolean {
58
+ return /^[0-9]+$/.test(text) && Number(text) > 0
59
+ }
60
+
61
+ function toPatch(draft: Draft): WirePatch {
62
+ return {
63
+ enabled: draft.enabled,
64
+ smtp: {
65
+ host: draft.host.trim(),
66
+ port: Number(draft.port),
67
+ secure: draft.secure,
68
+ user: draft.user.trim(),
69
+ pass: draft.pass,
70
+ from: draft.from.trim(),
71
+ },
72
+ to: draft.toText.split(',').map((s) => s.trim()).filter((s) => s.length > 0),
73
+ triggers: { ...draft.triggers },
74
+ idleDebounceMs: Number(draft.idleDebounceMs),
75
+ maxBodyChars: Number(draft.maxBodyChars),
76
+ dryRun: draft.dryRun,
77
+ }
78
+ }
79
+
80
+ const TRIGGER_KEYS = ['onComplete', 'onError', 'onAborted', 'onQuestion', 'onPlanReview'] as const
81
+
82
+ export function NotifyEmailCard(props: CardProps): ReactElement | null {
83
+ const { t } = props
84
+ const [open, setOpen] = useState(false)
85
+ const [wire, setWire] = useState<WireConfig | null>(null)
86
+ const [draft, setDraft] = useState<Draft | null>(null)
87
+ const [failed, setFailed] = useState(false)
88
+ const [saving, setSaving] = useState(false)
89
+ const [testing, setTesting] = useState(false)
90
+ const [status, setStatus] = useState<Status>(IDLE_STATUS)
91
+
92
+ useEffect(() => {
93
+ let alive = true
94
+ fetchConfig()
95
+ .then((loaded) => {
96
+ if (!alive) return
97
+ setWire(loaded)
98
+ setDraft(draftFromWire(loaded))
99
+ })
100
+ .catch(() => {
101
+ if (alive) setFailed(true)
102
+ })
103
+ return () => {
104
+ alive = false
105
+ }
106
+ }, [])
107
+
108
+ const dirty = useMemo(
109
+ () => wire !== null && draft !== null && JSON.stringify(toPatch(draft)) !== JSON.stringify(toPatch(draftFromWire(wire))),
110
+ [wire, draft],
111
+ )
112
+ const invalid = useMemo(
113
+ () =>
114
+ draft !== null &&
115
+ (!isPositiveInt(draft.port) || !isPositiveInt(draft.idleDebounceMs) ||
116
+ !isPositiveInt(draft.maxBodyChars) || Number(draft.maxBodyChars) < 200),
117
+ [draft],
118
+ )
119
+
120
+ if (failed) return null
121
+ if (wire === null || draft === null) {
122
+ return <li className="dne-card"><p className="dne-readOnly">{t('loading')}</p></li>
123
+ }
124
+ const edit = <K extends keyof Draft>(key: K, value: Draft[K]): void => {
125
+ setDraft({ ...draft, [key]: value })
126
+ setStatus(IDLE_STATUS)
127
+ }
128
+ const editTrigger = (key: keyof WireTriggers, checked: boolean): void => {
129
+ edit('triggers', { ...draft.triggers, [key]: checked })
130
+ }
131
+ const onSave = (): void => {
132
+ setSaving(true)
133
+ saveConfig(toPatch(draft))
134
+ .then((saved) => {
135
+ setWire(saved)
136
+ setDraft(draftFromWire(saved))
137
+ setStatus(IDLE_STATUS)
138
+ })
139
+ .catch((error: unknown) => {
140
+ setStatus({ kind: 'error', text: `${t('saveFailed')} ${error instanceof Error ? error.message : ''}` })
141
+ })
142
+ .finally(() => setSaving(false))
143
+ }
144
+ const onTest = (): void => {
145
+ setTesting(true)
146
+ sendTest()
147
+ .then((result) => {
148
+ if (result.ok) {
149
+ setStatus({ kind: 'ok', text: result.detail === 'dry-run' ? t('testDryRun') : t('testOk') })
150
+ } else {
151
+ const why = result.detail === 'incomplete' ? t('incomplete') : result.detail
152
+ setStatus({ kind: 'error', text: `${t('testFailed')}${why}` })
153
+ }
154
+ })
155
+ .catch((error: unknown) => {
156
+ setStatus({ kind: 'error', text: `${t('testFailed')}${error instanceof Error ? error.message : ''}` })
157
+ })
158
+ .finally(() => setTesting(false))
159
+ }
160
+
161
+ const disabled = !wire.writable
162
+ return (
163
+ <li className={`dne-card${open ? ' dne-cardOpen' : ''}`}>
164
+ <button
165
+ type="button"
166
+ className="dne-header"
167
+ aria-expanded={open}
168
+ aria-label={`${t(open ? 'collapse' : 'expand')}: ${t('title')}`}
169
+ onClick={() => setOpen(!open)}
170
+ >
171
+ <span className="dne-headText">
172
+ <span className="dne-name">{t('title')}</span>
173
+ <span className="dne-description">{t('description')}</span>
174
+ </span>
175
+ {dirty ? <span className="dne-pending">{t('unsaved')}</span> : null}
176
+ <span className={`dne-chevron${open ? ' dne-chevronOpen' : ''}`}>▾</span>
177
+ </button>
178
+ {open ? (
179
+ <div className="dne-body">
180
+ {disabled ? <p className="dne-readOnly" role="status">{t('readOnly')}</p> : null}
181
+ <CheckRow id="dne-enabled" label={t('enabled')} checked={draft.enabled} disabled={disabled}
182
+ onEdit={(v) => edit('enabled', v)} />
183
+ <TextField id="dne-host" label={t('host')} hint={t('hostHint')} value={draft.host}
184
+ disabled={disabled} onEdit={(v) => edit('host', v)} />
185
+ <TextField id="dne-port" label={t('port')} hint={t('portHint')} value={draft.port} numeric
186
+ disabled={disabled} invalid={!isPositiveInt(draft.port)} invalidLabel={t('invalidNumber')}
187
+ onEdit={(v) => edit('port', v)} />
188
+ <CheckRow id="dne-secure" label={t('secure')} checked={draft.secure} disabled={disabled}
189
+ onEdit={(v) => edit('secure', v)} />
190
+ <TextField id="dne-user" label={t('user')} hint={t('userHint')} value={draft.user}
191
+ disabled={disabled} onEdit={(v) => edit('user', v)} />
192
+ <TextField id="dne-pass" label={t('pass')} hint={t('passHint')} value={draft.pass} password
193
+ disabled={disabled}
194
+ badge={{ text: wire.smtp.passConfigured ? t('passSet') : t('passUnset'), set: wire.smtp.passConfigured }}
195
+ onEdit={(v) => edit('pass', v)} />
196
+ <TextField id="dne-from" label={t('from')} hint={t('fromHint')} value={draft.from}
197
+ disabled={disabled} onEdit={(v) => edit('from', v)} />
198
+ <TextField id="dne-to" label={t('to')} hint={t('toHint')} value={draft.toText}
199
+ disabled={disabled} onEdit={(v) => edit('toText', v)} />
200
+ <p className="dne-groupLabel">{t('triggerGroup')}</p>
201
+ {TRIGGER_KEYS.map((key) => (
202
+ <CheckRow key={key} id={`dne-${key}`} label={t(key)} checked={draft.triggers[key]}
203
+ disabled={disabled} onEdit={(v) => editTrigger(key, v)} />
204
+ ))}
205
+ <TextField id="dne-debounce" label={t('idleDebounceMs')} hint={t('idleDebounceMsHint')}
206
+ value={draft.idleDebounceMs} numeric disabled={disabled}
207
+ invalid={!isPositiveInt(draft.idleDebounceMs)} invalidLabel={t('invalidNumber')}
208
+ onEdit={(v) => edit('idleDebounceMs', v)} />
209
+ <TextField id="dne-maxchars" label={t('maxBodyChars')} hint={t('maxBodyCharsHint')}
210
+ value={draft.maxBodyChars} numeric disabled={disabled}
211
+ invalid={!isPositiveInt(draft.maxBodyChars) || Number(draft.maxBodyChars) < 200}
212
+ invalidLabel={t('invalidNumber')}
213
+ onEdit={(v) => edit('maxBodyChars', v)} />
214
+ <CheckRow id="dne-dryrun" label={t('dryRun')} checked={draft.dryRun} disabled={disabled}
215
+ onEdit={(v) => edit('dryRun', v)} />
216
+ <div className="dne-footer">
217
+ {status.kind !== 'idle' ? (
218
+ <p className={`dne-status${status.kind === 'error' ? ' dne-statusError' : ''}`} role="status">
219
+ {status.text}
220
+ </p>
221
+ ) : null}
222
+ <button type="button" className="dne-btn dne-btnGhost" disabled={testing}
223
+ onClick={onTest}>
224
+ {t(testing ? 'testing' : 'test')}
225
+ </button>
226
+ <button type="button" className="dne-btn dne-btnGhost" disabled={!dirty || saving}
227
+ onClick={() => { setDraft(draftFromWire(wire)); setStatus(IDLE_STATUS) }}>
228
+ {t('discard')}
229
+ </button>
230
+ <button type="button" className="dne-btn dne-btnPrimary" disabled={!dirty || invalid || saving || disabled}
231
+ onClick={onSave}>
232
+ {t(saving ? 'saving' : 'save')}
233
+ </button>
234
+ </div>
235
+ </div>
236
+ ) : null}
237
+ </li>
238
+ )
239
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 浏览器半入口:注册 locale 字典 + 向 settings.plugin.item 插槽注册「邮件通知」卡片。
3
+ * 构建产物为 window.__ModuleLoader__.load({id, factory}) 形式的 CJS factory
4
+ * (包装见 tsdown.config.ts);样式沿用官方 data-plugin-css 约定,HMR 据此卸载。
5
+ *
6
+ * 类型说明:浏览器半只用到 slots/locale 的很窄一面,此处以最小本地接口声明,
7
+ * 避免为构建期类型引入整条官方 client 依赖树;运行时契约以官方
8
+ * dsh-client-ui-settings-plugins 的 settings.plugin.item 插槽为准。
9
+ * @module @dsh-plus/notify-email/client
10
+ */
11
+ import type { Context } from '@deepseek-ai/cordis'
12
+
13
+ import { NotifyEmailCard } from './card.tsx'
14
+ import { en, NS, zh } from './i18n.ts'
15
+ import { injectStyle } from './styles.ts'
16
+
17
+ export const name = 'dsh-plus-notify-email'
18
+
19
+ /** 浏览器半需要的 cordis 服务 key(loader 据此注入;package.json 的 dsh.client.inject 管包加载顺序)。 */
20
+ export const inject = ['slots', 'locale'] as const
21
+
22
+ interface SlotsLike {
23
+ inject(key: string, callback: () => unknown): unknown
24
+ register(options: Record<string, unknown>, component: unknown): () => void
25
+ }
26
+
27
+ interface LocaleLike {
28
+ register(ns: string, dict: { zh: Record<string, string>; en: Record<string, string> }): () => void
29
+ bind(ns: string): (key: string) => string
30
+ }
31
+
32
+ interface ClientContext {
33
+ slots: SlotsLike
34
+ locale: LocaleLike
35
+ effect(execute: () => () => void, label?: string): unknown
36
+ }
37
+
38
+ export function apply(ctx: Context): void {
39
+ const c = ctx as unknown as ClientContext
40
+ const tag = injectStyle()
41
+ c.effect(
42
+ () => () => {
43
+ tag?.remove()
44
+ },
45
+ 'notify-email: style',
46
+ )
47
+ c.effect(
48
+ () => c.locale.register(NS, { zh, en }),
49
+ 'notify-email: locale',
50
+ )
51
+ c.slots.inject('settings.plugin.item', () =>
52
+ c.slots.register(
53
+ {
54
+ name: 'settings.plugin.item',
55
+ id: 'notify-email',
56
+ order: 100,
57
+ locale: NS,
58
+ inject: () => ({ t: c.locale.bind(NS) }),
59
+ },
60
+ NotifyEmailCard,
61
+ ),
62
+ )
63
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 配置卡片的基础控件:文本/数字/密码字段与勾选行。
3
+ * 视觉对齐官方卡片字段(label + hint + input 纵列)。
4
+ * @module notify-email/client/fields
5
+ */
6
+ import type { ReactElement } from 'react'
7
+
8
+ export interface TextFieldProps {
9
+ id: string
10
+ label: string
11
+ hint?: string
12
+ value: string
13
+ disabled?: boolean
14
+ invalid?: boolean
15
+ invalidLabel?: string
16
+ numeric?: boolean
17
+ password?: boolean
18
+ badge?: { text: string; set: boolean }
19
+ onEdit(text: string): void
20
+ }
21
+
22
+ export function TextField(props: TextFieldProps): ReactElement {
23
+ const invalid = props.invalid === true
24
+ return (
25
+ <div className="dne-field">
26
+ <div className="dne-head">
27
+ <label className="dne-label" htmlFor={props.id}>
28
+ {props.label}
29
+ </label>
30
+ {props.badge !== undefined ? (
31
+ <span className={`dne-badge ${props.badge.set ? 'dne-badgeSet' : 'dne-badgeUnset'}`}>
32
+ {props.badge.text}
33
+ </span>
34
+ ) : null}
35
+ </div>
36
+ <input
37
+ id={props.id}
38
+ className={`dne-input${invalid ? ' dne-inputInvalid' : ''}`}
39
+ type={props.password === true ? 'password' : 'text'}
40
+ inputMode={props.numeric === true ? 'numeric' : undefined}
41
+ autoComplete={props.password === true ? 'off' : undefined}
42
+ aria-invalid={invalid || undefined}
43
+ value={props.value}
44
+ disabled={props.disabled === true}
45
+ onChange={(event) => props.onEdit(event.target.value)}
46
+ />
47
+ <p className={invalid ? 'dne-invalid' : 'dne-hint'}>
48
+ {invalid ? (props.invalidLabel ?? '') : (props.hint ?? '')}
49
+ </p>
50
+ </div>
51
+ )
52
+ }
53
+
54
+ export interface CheckRowProps {
55
+ id: string
56
+ label: string
57
+ checked: boolean
58
+ disabled?: boolean
59
+ onEdit(checked: boolean): void
60
+ }
61
+
62
+ export function CheckRow(props: CheckRowProps): ReactElement {
63
+ return (
64
+ <div className="dne-checkRow">
65
+ <input
66
+ id={props.id}
67
+ type="checkbox"
68
+ checked={props.checked}
69
+ disabled={props.disabled === true}
70
+ onChange={(event) => props.onEdit(event.target.checked)}
71
+ />
72
+ <label htmlFor={props.id}>{props.label}</label>
73
+ </div>
74
+ )
75
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * 配置卡片文案(zh/en)。经 ctx.locale.register 注册、bind 取用,与官方卡片同机制。
3
+ * @module notify-email/client/i18n
4
+ */
5
+
6
+ export const NS = 'dsh-plus-notify-email'
7
+
8
+ export const zh: Record<string, string> = {
9
+ title: '邮件通知',
10
+ description: '任务结束、等待决策或出错时向指定邮箱发送邮件。',
11
+ enabled: '启用通知',
12
+ host: 'SMTP 服务器',
13
+ hostHint: '如 smtp.qq.com、smtp.163.com。',
14
+ port: '端口',
15
+ portHint: '465(TLS)或 587(STARTTLS)。',
16
+ secure: 'TLS 直连',
17
+ user: '登录用户名',
18
+ userHint: '通常为发件邮箱地址;免认证服务器可留空。',
19
+ pass: '密码 / 授权码',
20
+ passHint: '留空表示保持已存密码不变。',
21
+ passSet: '已配置',
22
+ passUnset: '未配置',
23
+ from: '发件地址',
24
+ fromHint: '邮件 From 头,通常与登录用户名一致。',
25
+ to: '收件邮箱',
26
+ toHint: '多个收件人用英文逗号分隔。',
27
+ triggerGroup: '通知时机',
28
+ onComplete: '任务执行完毕',
29
+ onError: '报错 / 失败停止',
30
+ onAborted: '被用户取消',
31
+ onQuestion: '提问等待回答',
32
+ onPlanReview: 'Plan 待审批',
33
+ idleDebounceMs: '空闲确认(毫秒)',
34
+ idleDebounceMsHint: '任务结束后等待该时长确认无后续工作再发信。',
35
+ maxBodyChars: '正文截断长度',
36
+ maxBodyCharsHint: '邮件正文内容超过该长度时截断。',
37
+ dryRun: '仅记录日志(不真实发送)',
38
+ save: '保存',
39
+ saving: '保存中…',
40
+ discard: '放弃',
41
+ unsaved: '未保存',
42
+ test: '发送测试邮件',
43
+ testing: '发送中…',
44
+ testOk: '测试邮件已发送。',
45
+ testDryRun: '已按 dry-run 记录日志(未真实发送)。',
46
+ testFailed: '测试发送失败:',
47
+ saveFailed: '保存失败,请检查填写内容。',
48
+ loading: '加载中…',
49
+ unavailable: '配置服务不可用。',
50
+ readOnly: '当前部署无 settings provider,配置为只读;请编辑 settings.yaml。',
51
+ expand: '展开',
52
+ collapse: '收起',
53
+ invalidNumber: '请输入有效数字',
54
+ incomplete: 'SMTP 配置不完整(服务器/发件地址/收件人必填)。',
55
+ }
56
+
57
+ export const en: Record<string, string> = {
58
+ title: 'Email notifications',
59
+ description: 'Email a mailbox when a task finishes, awaits a decision, or fails.',
60
+ enabled: 'Enable notifications',
61
+ host: 'SMTP host',
62
+ hostHint: 'e.g. smtp.qq.com, smtp.gmail.com.',
63
+ port: 'Port',
64
+ portHint: '465 (TLS) or 587 (STARTTLS).',
65
+ secure: 'Direct TLS',
66
+ user: 'Username',
67
+ userHint: 'Usually the sender address; leave empty for auth-less servers.',
68
+ pass: 'Password / app token',
69
+ passHint: 'Leave blank to keep the stored password.',
70
+ passSet: 'Configured',
71
+ passUnset: 'Not configured',
72
+ from: 'From address',
73
+ fromHint: 'The From header, usually same as the username.',
74
+ to: 'Recipients',
75
+ toHint: 'Separate multiple recipients with commas.',
76
+ triggerGroup: 'Notify when',
77
+ onComplete: 'Task completed',
78
+ onError: 'Task failed',
79
+ onAborted: 'Cancelled by user',
80
+ onQuestion: 'Waiting for an answer',
81
+ onPlanReview: 'Plan pending approval',
82
+ idleDebounceMs: 'Idle confirmation (ms)',
83
+ idleDebounceMsHint: 'Wait this long after completion to confirm no follow-up work.',
84
+ maxBodyChars: 'Body truncation',
85
+ maxBodyCharsHint: 'Truncate mail body content beyond this length.',
86
+ dryRun: 'Log only (do not send)',
87
+ save: 'Save',
88
+ saving: 'Saving…',
89
+ discard: 'Discard',
90
+ unsaved: 'Unsaved',
91
+ test: 'Send test email',
92
+ testing: 'Sending…',
93
+ testOk: 'Test email sent.',
94
+ testDryRun: 'Recorded as dry-run (not actually sent).',
95
+ testFailed: 'Test failed: ',
96
+ saveFailed: 'Save failed; please check the fields.',
97
+ loading: 'Loading…',
98
+ unavailable: 'Configuration service unavailable.',
99
+ readOnly: 'No settings provider in this deployment; edit settings.yaml instead.',
100
+ expand: 'Expand',
101
+ collapse: 'Collapse',
102
+ invalidNumber: 'Enter a valid number',
103
+ incomplete: 'SMTP config incomplete (host/from/recipients required).',
104
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 配置卡片样式:沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),
3
+ * 视觉对齐官方卡片(--dsw-alias-* 变量),不覆盖上游任何选择器。
4
+ * @module notify-email/client/styles
5
+ */
6
+
7
+ export const PLUGIN_ID = '@dsh-plus/notify-email'
8
+ export const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`
9
+
10
+ export const cardCss = `
11
+ .dne-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
12
+ .dne-card:hover{border-color:var(--dsw-alias-label-dimmed)}
13
+ .dne-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
14
+ .dne-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
15
+ .dne-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
16
+ .dne-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
17
+ .dne-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
18
+ .dne-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
19
+ .dne-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
20
+ .dne-chevronOpen{transform:rotate(180deg)}
21
+ .dne-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
22
+ .dne-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
23
+ .dne-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
24
+ .dne-field+.dne-field{border-top:1px solid var(--dsw-alias-border-l2)}
25
+ .dne-head{align-items:center;gap:8px;display:flex}
26
+ .dne-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
27
+ .dne-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
28
+ .dne-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
29
+ .dne-badgeUnset{color:var(--dsw-alias-label-tertiary)}
30
+ .dne-input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px}
31
+ .dne-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
32
+ .dne-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
33
+ .dne-inputInvalid{border-color:var(--dsw-alias-label-error)}
34
+ .dne-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
35
+ .dne-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
36
+ .dne-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
37
+ .dne-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
38
+ .dne-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
39
+ .dne-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
40
+ .dne-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
41
+ .dne-footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex;flex-wrap:wrap}
42
+ .dne-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
43
+ .dne-statusError{color:var(--dsw-alias-label-error)}
44
+ .dne-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
45
+ .dne-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
46
+ .dne-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
47
+ .dne-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
48
+ .dne-btn:disabled{opacity:.4;cursor:default}
49
+ .dne-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
50
+ `
51
+
52
+ /** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
53
+ export function injectStyle(): HTMLStyleElement | null {
54
+ if (typeof document === 'undefined') return null
55
+ if (document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`) !== null) {
56
+ return null
57
+ }
58
+ const tag = document.createElement('style')
59
+ tag.dataset.plugin = PLUGIN_ID
60
+ tag.dataset.pluginCss = STYLE_TAG_ID
61
+ tag.textContent = cardCss
62
+ document.head.appendChild(tag)
63
+ return tag
64
+ }