@dsh-plus/notify-email 0.1.9 → 0.1.10
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/lib/client.js +494 -387
- package/package.json +3 -2
- package/src/client/card.tsx +175 -187
- package/src/client/client.ts +6 -86
- package/src/client/i18n.ts +16 -33
- package/src/client/fields.tsx +0 -75
- package/src/client/scope.ts +0 -59
- package/src/client/styles.ts +0 -64
package/lib/client.js
CHANGED
|
@@ -4,53 +4,97 @@ window.__ModuleLoader__.load({
|
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
-
let react = require("react");
|
|
8
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
8
|
+
let react = require("react");
|
|
9
|
+
//#region ../shared/src/client/card.tsx
|
|
10
|
+
const IDLE_STATUS = {
|
|
11
|
+
kind: "idle",
|
|
12
|
+
text: ""
|
|
13
|
+
};
|
|
14
|
+
function CardChrome(props) {
|
|
15
|
+
const p = props.prefix;
|
|
16
|
+
const badge = props.statusBadge;
|
|
17
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
18
|
+
className: `${p}-card${props.open ? ` ${p}-cardOpen` : ""}`,
|
|
19
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
20
|
+
type: "button",
|
|
21
|
+
className: `${p}-header`,
|
|
22
|
+
"aria-expanded": props.open,
|
|
23
|
+
"aria-label": props.title,
|
|
24
|
+
onClick: () => props.onToggle(!props.open),
|
|
25
|
+
children: [
|
|
26
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
27
|
+
className: `${p}-headText`,
|
|
28
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
29
|
+
className: `${p}-name`,
|
|
30
|
+
children: props.title
|
|
31
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
32
|
+
className: `${p}-description`,
|
|
33
|
+
children: props.description
|
|
34
|
+
})]
|
|
35
|
+
}),
|
|
36
|
+
badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
37
|
+
className: `${p}-statusBadge ${badge.on ? `${p}-statusOn` : `${p}-statusOff`}`,
|
|
38
|
+
children: badge.text
|
|
39
|
+
}) : null,
|
|
40
|
+
props.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
41
|
+
className: `${p}-pending`,
|
|
42
|
+
children: props.dirtyLabel
|
|
43
|
+
}) : null,
|
|
44
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
45
|
+
className: `${p}-chevron${props.open ? ` ${p}-chevronOpen` : ""}`,
|
|
46
|
+
children: "▾"
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
}), props.open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
50
|
+
className: `${p}-body`,
|
|
51
|
+
children: [
|
|
52
|
+
props.readOnlyNotice !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
53
|
+
className: `${p}-readOnly`,
|
|
54
|
+
role: "status",
|
|
55
|
+
children: props.readOnlyNotice
|
|
56
|
+
}) : null,
|
|
57
|
+
props.children,
|
|
58
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
59
|
+
className: `${p}-footer`,
|
|
60
|
+
children: [props.status !== void 0 && props.status.kind !== "idle" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
61
|
+
className: `${p}-status${props.status.kind === "error" ? ` ${p}-statusError` : ""}`,
|
|
62
|
+
role: "status",
|
|
63
|
+
children: props.status.text
|
|
64
|
+
}) : null, props.actions.map((action) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
65
|
+
type: "button",
|
|
66
|
+
className: `${p}-btn ${action.variant === "primary" ? `${p}-btnPrimary` : `${p}-btnGhost`}`,
|
|
67
|
+
disabled: action.disabled === true,
|
|
68
|
+
onClick: action.onClick,
|
|
69
|
+
children: action.label
|
|
70
|
+
}, action.key))]
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
}) : null]
|
|
74
|
+
});
|
|
32
75
|
}
|
|
33
76
|
//#endregion
|
|
34
|
-
//#region src/client/fields.tsx
|
|
77
|
+
//#region ../shared/src/client/fields.tsx
|
|
35
78
|
function TextField(props) {
|
|
79
|
+
const p = props.prefix ?? "dshp";
|
|
36
80
|
const invalid = props.invalid === true;
|
|
37
81
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
38
|
-
className:
|
|
82
|
+
className: `${p}-field`,
|
|
39
83
|
children: [
|
|
40
84
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
41
|
-
className:
|
|
85
|
+
className: `${p}-head`,
|
|
42
86
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
43
|
-
className:
|
|
87
|
+
className: `${p}-label`,
|
|
44
88
|
htmlFor: props.id,
|
|
45
89
|
children: props.label
|
|
46
90
|
}), props.badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
47
|
-
className:
|
|
91
|
+
className: `${p}-badge ${props.badge.set ? `${p}-badgeSet` : `${p}-badgeUnset`}`,
|
|
48
92
|
children: props.badge.text
|
|
49
93
|
}) : null]
|
|
50
94
|
}),
|
|
51
95
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
52
96
|
id: props.id,
|
|
53
|
-
className:
|
|
97
|
+
className: `${p}-input${invalid ? ` ${p}-inputInvalid` : ""}`,
|
|
54
98
|
type: props.password === true ? "password" : "text",
|
|
55
99
|
inputMode: props.numeric === true ? "numeric" : void 0,
|
|
56
100
|
autoComplete: props.password === true ? "off" : void 0,
|
|
@@ -60,15 +104,16 @@ window.__ModuleLoader__.load({
|
|
|
60
104
|
onChange: (event) => props.onEdit(event.target.value)
|
|
61
105
|
}),
|
|
62
106
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
63
|
-
className: invalid ?
|
|
107
|
+
className: invalid ? `${p}-invalid` : `${p}-hint`,
|
|
64
108
|
children: invalid ? props.invalidLabel ?? "" : props.hint ?? ""
|
|
65
109
|
})
|
|
66
110
|
]
|
|
67
111
|
});
|
|
68
112
|
}
|
|
69
113
|
function CheckRow(props) {
|
|
114
|
+
const p = props.prefix ?? "dshp";
|
|
70
115
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
71
|
-
className:
|
|
116
|
+
className: `${p}-checkRow`,
|
|
72
117
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
73
118
|
id: props.id,
|
|
74
119
|
type: "checkbox",
|
|
@@ -82,20 +127,251 @@ window.__ModuleLoader__.load({
|
|
|
82
127
|
});
|
|
83
128
|
}
|
|
84
129
|
//#endregion
|
|
130
|
+
//#region ../shared/src/client/i18n.ts
|
|
131
|
+
/** 卡片通用文案(save/discard/unsaved/loading 等四插件共有键)。 */
|
|
132
|
+
const commonZh = {
|
|
133
|
+
save: "保存",
|
|
134
|
+
saving: "保存中…",
|
|
135
|
+
discard: "放弃",
|
|
136
|
+
unsaved: "未保存",
|
|
137
|
+
loading: "加载中…",
|
|
138
|
+
unavailable: "配置服务不可用。",
|
|
139
|
+
readOnly: "当前部署无 settings provider,配置为只读;请编辑 settings.yaml。",
|
|
140
|
+
invalidNumber: "请输入正整数。",
|
|
141
|
+
collapse: "收起",
|
|
142
|
+
expand: "展开",
|
|
143
|
+
enabledOn: "已启用",
|
|
144
|
+
enabledOff: "未启用",
|
|
145
|
+
saveFailed: "保存失败,请检查填写内容。",
|
|
146
|
+
confirm: "确认",
|
|
147
|
+
cancel: "取消"
|
|
148
|
+
};
|
|
149
|
+
const commonEn = {
|
|
150
|
+
save: "Save",
|
|
151
|
+
saving: "Saving…",
|
|
152
|
+
discard: "Discard",
|
|
153
|
+
unsaved: "Unsaved",
|
|
154
|
+
loading: "Loading…",
|
|
155
|
+
unavailable: "Settings service unavailable.",
|
|
156
|
+
readOnly: "No settings provider in this deployment; config is read-only. Edit settings.yaml.",
|
|
157
|
+
invalidNumber: "Enter a positive integer.",
|
|
158
|
+
collapse: "Collapse",
|
|
159
|
+
expand: "Expand",
|
|
160
|
+
enabledOn: "On",
|
|
161
|
+
enabledOff: "Off",
|
|
162
|
+
saveFailed: "Save failed; check the fields.",
|
|
163
|
+
confirm: "Confirm",
|
|
164
|
+
cancel: "Cancel"
|
|
165
|
+
};
|
|
166
|
+
/** own 覆盖同键合并(返回新对象,入参不可变)。 */
|
|
167
|
+
function mergeDict(base, own) {
|
|
168
|
+
return {
|
|
169
|
+
...base,
|
|
170
|
+
...own
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region ../shared/src/client/scope.ts
|
|
175
|
+
/**
|
|
176
|
+
* api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
|
|
177
|
+
* 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
|
|
178
|
+
* 刷新:remote `settings/document-updated`(按命名空间过滤)与
|
|
179
|
+
* `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
|
|
180
|
+
* (loopback 或 tailnet 信任域名)下行为一致。
|
|
181
|
+
* effect 归属调用方 fiber(label 需含插件名以便诊断)。
|
|
182
|
+
*/
|
|
183
|
+
function createApiScope(api, ns, c, label) {
|
|
184
|
+
let state = {
|
|
185
|
+
status: "loading",
|
|
186
|
+
value: void 0,
|
|
187
|
+
revision: void 0,
|
|
188
|
+
writable: false
|
|
189
|
+
};
|
|
190
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
191
|
+
let generation = 0;
|
|
192
|
+
const publish = (next) => {
|
|
193
|
+
state = next;
|
|
194
|
+
for (const listener of [...listeners]) listener();
|
|
195
|
+
};
|
|
196
|
+
const load = async () => {
|
|
197
|
+
const gen = ++generation;
|
|
198
|
+
let response;
|
|
199
|
+
try {
|
|
200
|
+
response = await api.describe({});
|
|
201
|
+
} catch {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (gen !== generation || !response.result.ok) return;
|
|
205
|
+
const writable = response.result.value?.writable ?? false;
|
|
206
|
+
const view = response.result.value?.namespaces.find((candidate) => candidate.ns === ns);
|
|
207
|
+
if (view === void 0) {
|
|
208
|
+
publish({
|
|
209
|
+
status: "unavailable",
|
|
210
|
+
value: void 0,
|
|
211
|
+
revision: void 0,
|
|
212
|
+
writable
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
publish({
|
|
217
|
+
status: "ready",
|
|
218
|
+
value: view.value,
|
|
219
|
+
revision: view.revision,
|
|
220
|
+
writable
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
const refresh = (namespace) => {
|
|
224
|
+
if (namespace !== void 0 && namespace !== ns) return;
|
|
225
|
+
load();
|
|
226
|
+
};
|
|
227
|
+
const disposers = [c.get("remote").$on("settings/document-updated", refresh), c.on("connection/reset", () => {
|
|
228
|
+
load();
|
|
229
|
+
})];
|
|
230
|
+
c.effect(() => () => {
|
|
231
|
+
for (const dispose of disposers) dispose();
|
|
232
|
+
}, label);
|
|
233
|
+
load();
|
|
234
|
+
return {
|
|
235
|
+
getSnapshot: () => state,
|
|
236
|
+
subscribe: (listener) => {
|
|
237
|
+
listeners.add(listener);
|
|
238
|
+
return () => {
|
|
239
|
+
listeners.delete(listener);
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
load
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region ../shared/src/client/styles.ts
|
|
247
|
+
/**
|
|
248
|
+
* 配置卡片样式工厂(各插件 client 的公共收编版)。
|
|
249
|
+
* 视觉规则与迁移前逐字一致(类名前缀换为各插件自身,DOM 类名不变),
|
|
250
|
+
* 另补移动端与可达性增强(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
|
|
251
|
+
* - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
|
|
252
|
+
* - footer 按钮等宽换行、状态文字独占一行;
|
|
253
|
+
* - 展开态 body 底部 sticky 保存栏(长表单滚动中始终可达)。
|
|
254
|
+
* 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
|
|
255
|
+
* @module @dsh-plus/shared/client/styles
|
|
256
|
+
*/
|
|
257
|
+
/** 生成全套卡片 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
|
|
258
|
+
function cardCss(prefix, extra = "") {
|
|
259
|
+
return `
|
|
260
|
+
.${prefix}-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}
|
|
261
|
+
.${prefix}-card:hover{border-color:var(--dsw-alias-label-dimmed)}
|
|
262
|
+
.${prefix}-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
|
|
263
|
+
.${prefix}-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}
|
|
264
|
+
.${prefix}-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
|
|
265
|
+
.${prefix}-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
|
|
266
|
+
.${prefix}-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
|
|
267
|
+
.${prefix}-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
|
|
268
|
+
.${prefix}-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
|
|
269
|
+
.${prefix}-chevronOpen{transform:rotate(180deg)}
|
|
270
|
+
.${prefix}-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}
|
|
271
|
+
.${prefix}-statusBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
272
|
+
.${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
273
|
+
.${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
|
|
274
|
+
.${prefix}-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
|
|
275
|
+
.${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
|
|
276
|
+
.${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
|
|
277
|
+
.${prefix}-head{align-items:center;gap:8px;display:flex}
|
|
278
|
+
.${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
|
|
279
|
+
.${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
280
|
+
.${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
281
|
+
.${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
|
|
282
|
+
.${prefix}-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}
|
|
283
|
+
.${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
|
|
284
|
+
.${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
285
|
+
.${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
|
|
286
|
+
.${prefix}-select{appearance:none;background-image:linear-gradient(45deg,transparent 50%,var(--dsw-alias-label-tertiary) 50%),linear-gradient(135deg,var(--dsw-alias-label-tertiary) 50%,transparent 50%);background-position:calc(100% - 16px) 50%,calc(100% - 11px) 50%;background-size:5px 5px;background-repeat:no-repeat;padding-right:28px}
|
|
287
|
+
.${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
|
|
288
|
+
.${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
|
|
289
|
+
.${prefix}-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
|
|
290
|
+
.${prefix}-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
|
|
291
|
+
.${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
|
|
292
|
+
.${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
|
|
293
|
+
.${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
294
|
+
.${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
295
|
+
.${prefix}-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}
|
|
296
|
+
.${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
|
|
297
|
+
.${prefix}-statusError{color:var(--dsw-alias-label-error)}
|
|
298
|
+
.${prefix}-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
|
|
299
|
+
.${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
|
|
300
|
+
.${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
|
|
301
|
+
.${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
302
|
+
.${prefix}-btn:disabled{opacity:.4;cursor:default}
|
|
303
|
+
.${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
304
|
+
@media (max-width:767px){
|
|
305
|
+
.${prefix}-body{margin:0 10px}
|
|
306
|
+
.${prefix}-header{padding:12px 12px}
|
|
307
|
+
.${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
|
|
308
|
+
.${prefix}-checkRow{min-height:44px;padding:8px 0}
|
|
309
|
+
.${prefix}-checkRow input{width:18px;height:18px;flex:none}
|
|
310
|
+
.${prefix}-footer{position:sticky;bottom:0;background:var(--dsw-alias-bg-layer-2);margin:0 -10px;padding:10px 10px 6px;border-top:1px solid var(--dsw-alias-border-l2);border-bottom-left-radius:12px;border-bottom-right-radius:12px}
|
|
311
|
+
.${prefix}-status{flex-basis:100%;flex:none}
|
|
312
|
+
.${prefix}-btn{min-height:44px;flex:1;min-width:96px}
|
|
313
|
+
.${prefix}-statusBadge{display:none}
|
|
314
|
+
}
|
|
315
|
+
@media (pointer:coarse){
|
|
316
|
+
.${prefix}-btn{min-height:44px}
|
|
317
|
+
.${prefix}-checkRow{min-height:44px}
|
|
318
|
+
.${prefix}-input,.${prefix}-select{height:40px}
|
|
319
|
+
}
|
|
320
|
+
${extra}
|
|
321
|
+
`;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
|
|
325
|
+
* 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
|
|
326
|
+
*/
|
|
327
|
+
function injectCardStyle(pluginId, css) {
|
|
328
|
+
if (typeof document === "undefined") return null;
|
|
329
|
+
const tagId = `${pluginId}/card.css`;
|
|
330
|
+
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
|
|
331
|
+
const tag = document.createElement("style");
|
|
332
|
+
tag.dataset.plugin = pluginId;
|
|
333
|
+
tag.dataset.pluginCss = tagId;
|
|
334
|
+
tag.textContent = css;
|
|
335
|
+
document.head.appendChild(tag);
|
|
336
|
+
return tag;
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/ns.ts
|
|
340
|
+
/**
|
|
341
|
+
* settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
|
|
342
|
+
* 服务端经 settingsNamespace() 品牌化后使用(config.ts),浏览器半将其作为
|
|
343
|
+
* settings.plugin.item keyed 槽位的 key —— 同一字面量两处共用,防止漂移。
|
|
344
|
+
* 契约:dsh rc7 起该槽位按「卡片编辑的 settings 命名空间」作 key 分发,
|
|
345
|
+
* 官方配置页只渲染 key 命中 Host 已注册命名空间的卡片。
|
|
346
|
+
* @module notify-email/ns
|
|
347
|
+
*/
|
|
348
|
+
const SETTINGS_NS = "dsh-plus-notify-email";
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/client/api.ts
|
|
351
|
+
const ROUTE_TEST = "/dsh-plus/notify-email/test";
|
|
352
|
+
async function parse(res) {
|
|
353
|
+
const body = await res.json();
|
|
354
|
+
if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`);
|
|
355
|
+
return body;
|
|
356
|
+
}
|
|
357
|
+
async function sendTest() {
|
|
358
|
+
return parse(await fetch(ROUTE_TEST, {
|
|
359
|
+
method: "POST",
|
|
360
|
+
credentials: "same-origin"
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
85
364
|
//#region src/client/card.tsx
|
|
86
365
|
/**
|
|
87
366
|
* 「邮件通知」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
367
|
+
* 外壳与基础控件走 @dsh-plus/shared/client 套件(CardChrome/TextField/CheckRow),
|
|
368
|
+
* 本文件只保留业务字段与保存/测试逻辑。交互对齐官方卡片:折叠/展开、
|
|
369
|
+
* staged draft、未保存标记、保存/放弃;另加「发送测试邮件」。
|
|
370
|
+
* 配置读写走官方 settingsScope 传输:value 为 schema 解析后的脱敏视图
|
|
371
|
+
* (smtp.pass 不出现,passConfigured 由 describe 的 secrets 探测),
|
|
92
372
|
* 保存经 settings.update 深合并(空 pass 剔除 = 保持不变)。
|
|
93
373
|
* @module notify-email/client/card
|
|
94
374
|
*/
|
|
95
|
-
const IDLE_STATUS = {
|
|
96
|
-
kind: "idle",
|
|
97
|
-
text: ""
|
|
98
|
-
};
|
|
99
375
|
function draftFromValue(value) {
|
|
100
376
|
return {
|
|
101
377
|
enabled: value.enabled,
|
|
@@ -232,198 +508,179 @@ window.__ModuleLoader__.load({
|
|
|
232
508
|
}).finally(() => setTesting(false));
|
|
233
509
|
};
|
|
234
510
|
const disabled = !snapshot.writable;
|
|
235
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
type: "button",
|
|
398
|
-
className: "dne-btn dne-btnGhost",
|
|
399
|
-
disabled: !dirty || saving,
|
|
400
|
-
onClick: () => {
|
|
401
|
-
setDraft(draftFromValue(value));
|
|
402
|
-
setStatus(IDLE_STATUS);
|
|
403
|
-
},
|
|
404
|
-
children: t("discard")
|
|
405
|
-
}),
|
|
406
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
407
|
-
type: "button",
|
|
408
|
-
className: "dne-btn dne-btnPrimary",
|
|
409
|
-
disabled: !dirty || invalid || saving || disabled,
|
|
410
|
-
onClick: onSave,
|
|
411
|
-
children: t(saving ? "saving" : "save")
|
|
412
|
-
})
|
|
413
|
-
]
|
|
414
|
-
})
|
|
415
|
-
]
|
|
416
|
-
}) : null]
|
|
511
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CardChrome, {
|
|
512
|
+
prefix: "dne",
|
|
513
|
+
title: t("title"),
|
|
514
|
+
description: t("description"),
|
|
515
|
+
open,
|
|
516
|
+
onToggle: setOpen,
|
|
517
|
+
statusBadge: {
|
|
518
|
+
text: t(draft.enabled ? "enabledOn" : "enabledOff"),
|
|
519
|
+
on: draft.enabled
|
|
520
|
+
},
|
|
521
|
+
dirty,
|
|
522
|
+
dirtyLabel: t("unsaved"),
|
|
523
|
+
readOnlyNotice: disabled ? t("readOnly") : void 0,
|
|
524
|
+
status,
|
|
525
|
+
actions: [
|
|
526
|
+
{
|
|
527
|
+
key: "test",
|
|
528
|
+
label: t(testing ? "testing" : "test"),
|
|
529
|
+
disabled: testing,
|
|
530
|
+
onClick: onTest
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
key: "discard",
|
|
534
|
+
label: t("discard"),
|
|
535
|
+
disabled: !dirty || saving,
|
|
536
|
+
onClick: () => {
|
|
537
|
+
setDraft(draftFromValue(value));
|
|
538
|
+
setStatus(IDLE_STATUS);
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
key: "save",
|
|
543
|
+
label: t(saving ? "saving" : "save"),
|
|
544
|
+
variant: "primary",
|
|
545
|
+
disabled: !dirty || invalid || saving || disabled,
|
|
546
|
+
onClick: onSave
|
|
547
|
+
}
|
|
548
|
+
],
|
|
549
|
+
children: [
|
|
550
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
551
|
+
prefix: "dne",
|
|
552
|
+
id: "dne-enabled",
|
|
553
|
+
label: t("enabled"),
|
|
554
|
+
checked: draft.enabled,
|
|
555
|
+
disabled,
|
|
556
|
+
onEdit: (v) => edit("enabled", v)
|
|
557
|
+
}),
|
|
558
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
559
|
+
prefix: "dne",
|
|
560
|
+
id: "dne-host",
|
|
561
|
+
label: t("host"),
|
|
562
|
+
hint: t("hostHint"),
|
|
563
|
+
value: draft.host,
|
|
564
|
+
disabled,
|
|
565
|
+
onEdit: (v) => edit("host", v)
|
|
566
|
+
}),
|
|
567
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
568
|
+
prefix: "dne",
|
|
569
|
+
id: "dne-port",
|
|
570
|
+
label: t("port"),
|
|
571
|
+
hint: t("portHint"),
|
|
572
|
+
value: draft.port,
|
|
573
|
+
numeric: true,
|
|
574
|
+
disabled,
|
|
575
|
+
invalid: !isPositiveInt(draft.port),
|
|
576
|
+
invalidLabel: t("invalidNumber"),
|
|
577
|
+
onEdit: (v) => edit("port", v)
|
|
578
|
+
}),
|
|
579
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
580
|
+
prefix: "dne",
|
|
581
|
+
id: "dne-secure",
|
|
582
|
+
label: t("secure"),
|
|
583
|
+
checked: draft.secure,
|
|
584
|
+
disabled,
|
|
585
|
+
onEdit: (v) => edit("secure", v)
|
|
586
|
+
}),
|
|
587
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
588
|
+
prefix: "dne",
|
|
589
|
+
id: "dne-user",
|
|
590
|
+
label: t("user"),
|
|
591
|
+
hint: t("userHint"),
|
|
592
|
+
value: draft.user,
|
|
593
|
+
disabled,
|
|
594
|
+
onEdit: (v) => edit("user", v)
|
|
595
|
+
}),
|
|
596
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
597
|
+
prefix: "dne",
|
|
598
|
+
id: "dne-pass",
|
|
599
|
+
label: t("pass"),
|
|
600
|
+
hint: t("passHint"),
|
|
601
|
+
value: draft.pass,
|
|
602
|
+
password: true,
|
|
603
|
+
disabled,
|
|
604
|
+
badge: {
|
|
605
|
+
text: passConfigured ? t("passSet") : t("passUnset"),
|
|
606
|
+
set: passConfigured
|
|
607
|
+
},
|
|
608
|
+
onEdit: (v) => edit("pass", v)
|
|
609
|
+
}),
|
|
610
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
611
|
+
prefix: "dne",
|
|
612
|
+
id: "dne-from",
|
|
613
|
+
label: t("from"),
|
|
614
|
+
hint: t("fromHint"),
|
|
615
|
+
value: draft.from,
|
|
616
|
+
disabled,
|
|
617
|
+
onEdit: (v) => edit("from", v)
|
|
618
|
+
}),
|
|
619
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
620
|
+
prefix: "dne",
|
|
621
|
+
id: "dne-to",
|
|
622
|
+
label: t("to"),
|
|
623
|
+
hint: t("toHint"),
|
|
624
|
+
value: draft.toText,
|
|
625
|
+
disabled,
|
|
626
|
+
onEdit: (v) => edit("toText", v)
|
|
627
|
+
}),
|
|
628
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
629
|
+
className: "dne-groupLabel",
|
|
630
|
+
children: t("triggerGroup")
|
|
631
|
+
}),
|
|
632
|
+
TRIGGER_KEYS.map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
633
|
+
prefix: "dne",
|
|
634
|
+
id: `dne-${key}`,
|
|
635
|
+
label: t(key),
|
|
636
|
+
checked: draft.triggers[key],
|
|
637
|
+
disabled,
|
|
638
|
+
onEdit: (v) => editTrigger(key, v)
|
|
639
|
+
}, key)),
|
|
640
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
641
|
+
prefix: "dne",
|
|
642
|
+
id: "dne-debounce",
|
|
643
|
+
label: t("idleDebounceMs"),
|
|
644
|
+
hint: t("idleDebounceMsHint"),
|
|
645
|
+
value: draft.idleDebounceMs,
|
|
646
|
+
numeric: true,
|
|
647
|
+
disabled,
|
|
648
|
+
invalid: !isPositiveInt(draft.idleDebounceMs),
|
|
649
|
+
invalidLabel: t("invalidNumber"),
|
|
650
|
+
onEdit: (v) => edit("idleDebounceMs", v)
|
|
651
|
+
}),
|
|
652
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
653
|
+
prefix: "dne",
|
|
654
|
+
id: "dne-maxchars",
|
|
655
|
+
label: t("maxBodyChars"),
|
|
656
|
+
hint: t("maxBodyCharsHint"),
|
|
657
|
+
value: draft.maxBodyChars,
|
|
658
|
+
numeric: true,
|
|
659
|
+
disabled,
|
|
660
|
+
invalid: !isPositiveInt(draft.maxBodyChars) || Number(draft.maxBodyChars) < 200,
|
|
661
|
+
invalidLabel: t("invalidNumber"),
|
|
662
|
+
onEdit: (v) => edit("maxBodyChars", v)
|
|
663
|
+
}),
|
|
664
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
665
|
+
prefix: "dne",
|
|
666
|
+
id: "dne-dryrun",
|
|
667
|
+
label: t("dryRun"),
|
|
668
|
+
checked: draft.dryRun,
|
|
669
|
+
disabled,
|
|
670
|
+
onEdit: (v) => edit("dryRun", v)
|
|
671
|
+
})
|
|
672
|
+
]
|
|
417
673
|
});
|
|
418
674
|
}
|
|
419
675
|
//#endregion
|
|
420
676
|
//#region src/client/i18n.ts
|
|
421
677
|
/**
|
|
422
678
|
* 配置卡片文案(zh/en)。经 ctx.locale.register 注册、bind 取用,与官方卡片同机制。
|
|
679
|
+
* 公共键(save/discard/unsaved 等)来自 shared 的 common 字典,本文件只维护业务键。
|
|
423
680
|
* @module notify-email/client/i18n
|
|
424
681
|
*/
|
|
425
682
|
const NS = "dsh-plus-notify-email";
|
|
426
|
-
const
|
|
683
|
+
const ownZh = {
|
|
427
684
|
title: "邮件通知",
|
|
428
685
|
description: "任务结束、等待决策或出错时向指定邮箱发送邮件。",
|
|
429
686
|
enabled: "启用通知",
|
|
@@ -453,25 +710,14 @@ window.__ModuleLoader__.load({
|
|
|
453
710
|
maxBodyChars: "正文截断长度",
|
|
454
711
|
maxBodyCharsHint: "邮件正文内容超过该长度时截断。",
|
|
455
712
|
dryRun: "仅记录日志(不真实发送)",
|
|
456
|
-
save: "保存",
|
|
457
|
-
saving: "保存中…",
|
|
458
|
-
discard: "放弃",
|
|
459
|
-
unsaved: "未保存",
|
|
460
713
|
test: "发送测试邮件",
|
|
461
714
|
testing: "发送中…",
|
|
462
715
|
testOk: "测试邮件已发送。",
|
|
463
716
|
testDryRun: "已按 dry-run 记录日志(未真实发送)。",
|
|
464
717
|
testFailed: "测试发送失败:",
|
|
465
|
-
saveFailed: "保存失败,请检查填写内容。",
|
|
466
|
-
loading: "加载中…",
|
|
467
|
-
unavailable: "配置服务不可用。",
|
|
468
|
-
readOnly: "当前部署无 settings provider,配置为只读;请编辑 settings.yaml。",
|
|
469
|
-
expand: "展开",
|
|
470
|
-
collapse: "收起",
|
|
471
|
-
invalidNumber: "请输入有效数字",
|
|
472
718
|
incomplete: "SMTP 配置不完整(服务器/发件地址/收件人必填)。"
|
|
473
719
|
};
|
|
474
|
-
const
|
|
720
|
+
const ownEn = {
|
|
475
721
|
title: "Email notifications",
|
|
476
722
|
description: "Email a mailbox when a task finishes, awaits a decision, or fails.",
|
|
477
723
|
enabled: "Enable notifications",
|
|
@@ -494,92 +740,22 @@ window.__ModuleLoader__.load({
|
|
|
494
740
|
onComplete: "Task completed",
|
|
495
741
|
onError: "Task failed",
|
|
496
742
|
onAborted: "Cancelled by user",
|
|
497
|
-
onQuestion: "
|
|
498
|
-
onPlanReview: "Plan
|
|
499
|
-
idleDebounceMs: "Idle
|
|
500
|
-
idleDebounceMsHint: "
|
|
501
|
-
maxBodyChars: "Body truncation",
|
|
502
|
-
maxBodyCharsHint: "Truncate
|
|
503
|
-
dryRun: "Log only (do not send)",
|
|
504
|
-
save: "Save",
|
|
505
|
-
saving: "Saving…",
|
|
506
|
-
discard: "Discard",
|
|
507
|
-
unsaved: "Unsaved",
|
|
743
|
+
onQuestion: "Question awaiting answer",
|
|
744
|
+
onPlanReview: "Plan awaiting review",
|
|
745
|
+
idleDebounceMs: "Idle debounce (ms)",
|
|
746
|
+
idleDebounceMsHint: "After completion, wait this long to confirm no follow-up before sending.",
|
|
747
|
+
maxBodyChars: "Body truncation length",
|
|
748
|
+
maxBodyCharsHint: "Truncate the email body beyond this length.",
|
|
749
|
+
dryRun: "Log only (do not actually send)",
|
|
508
750
|
test: "Send test email",
|
|
509
751
|
testing: "Sending…",
|
|
510
752
|
testOk: "Test email sent.",
|
|
511
|
-
testDryRun: "
|
|
512
|
-
testFailed: "Test failed: ",
|
|
513
|
-
saveFailed: "Save failed; please check the fields.",
|
|
514
|
-
loading: "Loading…",
|
|
515
|
-
unavailable: "Configuration service unavailable.",
|
|
516
|
-
readOnly: "No settings provider in this deployment; edit settings.yaml instead.",
|
|
517
|
-
expand: "Expand",
|
|
518
|
-
collapse: "Collapse",
|
|
519
|
-
invalidNumber: "Enter a valid number",
|
|
753
|
+
testDryRun: "Logged in dry-run mode (not sent).",
|
|
754
|
+
testFailed: "Test send failed: ",
|
|
520
755
|
incomplete: "SMTP config incomplete (host/from/recipients required)."
|
|
521
756
|
};
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* 配置卡片样式:沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),
|
|
526
|
-
* 视觉对齐官方卡片(--dsw-alias-* 变量),不覆盖上游任何选择器。
|
|
527
|
-
* @module notify-email/client/styles
|
|
528
|
-
*/
|
|
529
|
-
const PLUGIN_ID = "@dsh-plus/notify-email";
|
|
530
|
-
const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`;
|
|
531
|
-
const cardCss = `
|
|
532
|
-
.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}
|
|
533
|
-
.dne-card:hover{border-color:var(--dsw-alias-label-dimmed)}
|
|
534
|
-
.dne-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
|
|
535
|
-
.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}
|
|
536
|
-
.dne-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
|
|
537
|
-
.dne-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
|
|
538
|
-
.dne-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
|
|
539
|
-
.dne-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
|
|
540
|
-
.dne-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
|
|
541
|
-
.dne-chevronOpen{transform:rotate(180deg)}
|
|
542
|
-
.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}
|
|
543
|
-
.dne-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
|
|
544
|
-
.dne-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
|
|
545
|
-
.dne-field+.dne-field{border-top:1px solid var(--dsw-alias-border-l2)}
|
|
546
|
-
.dne-head{align-items:center;gap:8px;display:flex}
|
|
547
|
-
.dne-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
|
|
548
|
-
.dne-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
549
|
-
.dne-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
550
|
-
.dne-badgeUnset{color:var(--dsw-alias-label-tertiary)}
|
|
551
|
-
.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}
|
|
552
|
-
.dne-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
|
|
553
|
-
.dne-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
554
|
-
.dne-inputInvalid{border-color:var(--dsw-alias-label-error)}
|
|
555
|
-
.dne-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
|
|
556
|
-
.dne-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
|
|
557
|
-
.dne-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
|
|
558
|
-
.dne-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
|
|
559
|
-
.dne-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
|
|
560
|
-
.dne-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
|
|
561
|
-
.dne-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
562
|
-
.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}
|
|
563
|
-
.dne-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
|
|
564
|
-
.dne-statusError{color:var(--dsw-alias-label-error)}
|
|
565
|
-
.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}
|
|
566
|
-
.dne-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
|
|
567
|
-
.dne-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
|
|
568
|
-
.dne-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
569
|
-
.dne-btn:disabled{opacity:.4;cursor:default}
|
|
570
|
-
.dne-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
571
|
-
`;
|
|
572
|
-
/** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
|
|
573
|
-
function injectStyle() {
|
|
574
|
-
if (typeof document === "undefined") return null;
|
|
575
|
-
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`) !== null) return null;
|
|
576
|
-
const tag = document.createElement("style");
|
|
577
|
-
tag.dataset.plugin = PLUGIN_ID;
|
|
578
|
-
tag.dataset.pluginCss = STYLE_TAG_ID;
|
|
579
|
-
tag.textContent = cardCss;
|
|
580
|
-
document.head.appendChild(tag);
|
|
581
|
-
return tag;
|
|
582
|
-
}
|
|
757
|
+
const zh = mergeDict(commonZh, ownZh);
|
|
758
|
+
const en = mergeDict(commonEn, ownEn);
|
|
583
759
|
//#endregion
|
|
584
760
|
//#region src/client/client.ts
|
|
585
761
|
const name = "dsh-plus-notify-email";
|
|
@@ -590,78 +766,9 @@ window.__ModuleLoader__.load({
|
|
|
590
766
|
"connection",
|
|
591
767
|
"remote"
|
|
592
768
|
];
|
|
593
|
-
/**
|
|
594
|
-
* api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
|
|
595
|
-
* 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
|
|
596
|
-
* 刷新:remote `settings/document-updated`(按命名空间过滤)与
|
|
597
|
-
* `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
|
|
598
|
-
* (loopback 或 tailnet 信任域名)下行为一致。
|
|
599
|
-
*/
|
|
600
|
-
function createApiScope(api, ns, c) {
|
|
601
|
-
let state = {
|
|
602
|
-
status: "loading",
|
|
603
|
-
value: void 0,
|
|
604
|
-
revision: void 0,
|
|
605
|
-
writable: false
|
|
606
|
-
};
|
|
607
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
608
|
-
let generation = 0;
|
|
609
|
-
const publish = (next) => {
|
|
610
|
-
state = next;
|
|
611
|
-
for (const listener of [...listeners]) listener();
|
|
612
|
-
};
|
|
613
|
-
const load = async () => {
|
|
614
|
-
const gen = ++generation;
|
|
615
|
-
let response;
|
|
616
|
-
try {
|
|
617
|
-
response = await api.describe({});
|
|
618
|
-
} catch {
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
if (gen !== generation || !response.result.ok) return;
|
|
622
|
-
const writable = response.result.value?.writable ?? false;
|
|
623
|
-
const view = response.result.value?.namespaces.find((candidate) => candidate.ns === ns);
|
|
624
|
-
if (view === void 0) {
|
|
625
|
-
publish({
|
|
626
|
-
status: "unavailable",
|
|
627
|
-
value: void 0,
|
|
628
|
-
revision: void 0,
|
|
629
|
-
writable
|
|
630
|
-
});
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
publish({
|
|
634
|
-
status: "ready",
|
|
635
|
-
value: view.value,
|
|
636
|
-
revision: view.revision,
|
|
637
|
-
writable
|
|
638
|
-
});
|
|
639
|
-
};
|
|
640
|
-
const refresh = (namespace) => {
|
|
641
|
-
if (namespace !== void 0 && namespace !== ns) return;
|
|
642
|
-
load();
|
|
643
|
-
};
|
|
644
|
-
const disposers = [c.get("remote").$on("settings/document-updated", refresh), c.on("connection/reset", () => {
|
|
645
|
-
load();
|
|
646
|
-
})];
|
|
647
|
-
c.effect(() => () => {
|
|
648
|
-
for (const dispose of disposers) dispose();
|
|
649
|
-
}, "notify-email: settings scope");
|
|
650
|
-
load();
|
|
651
|
-
return {
|
|
652
|
-
getSnapshot: () => state,
|
|
653
|
-
subscribe: (listener) => {
|
|
654
|
-
listeners.add(listener);
|
|
655
|
-
return () => {
|
|
656
|
-
listeners.delete(listener);
|
|
657
|
-
};
|
|
658
|
-
},
|
|
659
|
-
load
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
769
|
function apply(ctx) {
|
|
663
770
|
const c = ctx;
|
|
664
|
-
const tag =
|
|
771
|
+
const tag = injectCardStyle("@dsh-plus/notify-email", cardCss("dne"));
|
|
665
772
|
c.effect(() => () => {
|
|
666
773
|
tag?.remove();
|
|
667
774
|
}, "notify-email: style");
|
|
@@ -670,7 +777,7 @@ window.__ModuleLoader__.load({
|
|
|
670
777
|
en
|
|
671
778
|
}), "notify-email: locale");
|
|
672
779
|
const api = c.get("connection").api.settings;
|
|
673
|
-
const scope = createApiScope(api, SETTINGS_NS, c);
|
|
780
|
+
const scope = createApiScope(api, SETTINGS_NS, c, "notify-email: settings scope");
|
|
674
781
|
c.slots.inject("settings.plugin.item", () => c.slots.register({
|
|
675
782
|
name: "settings.plugin.item",
|
|
676
783
|
key: SETTINGS_NS,
|