@dsh-plus/notify-email 0.1.48 → 0.1.50

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 CHANGED
@@ -4,11 +4,36 @@ 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_jsx_runtime = require("react/jsx-runtime");
7
+ //#region \0rolldown/runtime.js
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
16
+ key = keys[i];
17
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: ((k) => from[k]).bind(null, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ //#endregion
8
29
  let react = require("react");
30
+ react = __toESM(react, 1);
31
+ let react_jsx_runtime = require("react/jsx-runtime");
32
+ let _deepseek_ai_schemastery = require("@deepseek-ai/schemastery");
33
+ _deepseek_ai_schemastery = __toESM(_deepseek_ai_schemastery, 1);
9
34
  require("@deepseek-ai/dsh-client-ui-primitives");
10
35
  //#region ../shared/src/client/fields.tsx
11
- /** 卡片按钮(与 CardChrome 页脚同一套类名与视觉)。 */
36
+ /** 卡片按钮(与 ConfigShell 页脚同一套类名与视觉)。 */
12
37
  function Button(props) {
13
38
  const p = props.prefix ?? "dshp";
14
39
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
@@ -77,13 +102,38 @@ window.__ModuleLoader__.load({
77
102
  })]
78
103
  });
79
104
  }
105
+ /**
106
+ * 数值字段:文本承载(不静默改写用户输入),越界/非法由调用方判定并传 invalid;
107
+ * 空值与 `-`/`0` 等中间态不在这里过滤,避免编辑过程被打断。
108
+ */
109
+ function NumberField(props) {
110
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
111
+ ...props,
112
+ numeric: true
113
+ });
114
+ }
80
115
  //#endregion
81
116
  //#region ../shared/src/client/card.tsx
117
+ /**
118
+ * 配置卡片外壳与排版件:`ConfigShell`(卡片级无边框分节)、`Section`(卡片内二级
119
+ * 分组)、`FieldGrid`(字段排布)、`Note`(只读说明)、`ListEditor`(数组型资源
120
+ * 统一编辑)、`CardLoading`(取值未到达占位)。
121
+ *
122
+ * 宿主页面(`plugins.row.config` / `plugins.bundle.config` 的 page 视图)自己画
123
+ * 标题、图标、面包屑与页面级内边距,视图只填内容区——所以这里不再自绘带边框
124
+ * 卡片(会形成卡片套卡片,把移动端可用宽度逐层扣掉),也不做折叠:page 视图
125
+ * 本身就是表单落地页。度量对齐官方设置页(dsh-client-ui-primitives 的
126
+ * settings-form):小节标题 13px/600、字段区零横向内边距、页脚非 sticky。
127
+ *
128
+ * 各插件 card.tsx 只填 children 字段区与 actions;类名前缀与样式由
129
+ * cardCss(prefix) 配套。
130
+ * @module @dsh-plus/shared/client/card
131
+ */
82
132
  const IDLE_STATUS = {
83
133
  kind: "idle",
84
134
  text: ""
85
135
  };
86
- function CardChrome(props) {
136
+ function ConfigShell(props) {
87
137
  const p = props.prefix;
88
138
  const badge = props.statusBadge;
89
139
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
@@ -139,7 +189,37 @@ window.__ModuleLoader__.load({
139
189
  ]
140
190
  });
141
191
  }
142
- /** 取值未到达时的占位:与 CardChrome 同形态,避免宿主页里闪一次卡片外壳。 */
192
+ function Section(props) {
193
+ const p = props.prefix;
194
+ const [open, setOpen] = (0, react.useState)(props.toggle?.defaultOpen ?? true);
195
+ const collapsible = props.toggle !== void 0;
196
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
197
+ className: `${p}-sub`,
198
+ children: [
199
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
200
+ className: `${p}-subHead`,
201
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
202
+ className: `${p}-subTitle`,
203
+ children: props.title
204
+ }), collapsible ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
205
+ type: "button",
206
+ className: `${p}-subToggle`,
207
+ onClick: () => setOpen(!open),
208
+ children: open ? props.toggle?.close : props.toggle?.open
209
+ }) : null]
210
+ }),
211
+ props.description === void 0 || props.description === "" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
212
+ className: `${p}-subDesc`,
213
+ children: props.description
214
+ }),
215
+ open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
216
+ className: `${p}-subBody`,
217
+ children: props.children
218
+ }) : null
219
+ ]
220
+ });
221
+ }
222
+ /** 取值未到达时的占位:与 ConfigShell 同形态,避免宿主页里闪一次卡片外壳。 */
143
223
  function CardLoading(props) {
144
224
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
145
225
  className: `${props.prefix}-section`,
@@ -151,14 +231,744 @@ window.__ModuleLoader__.load({
151
231
  });
152
232
  }
153
233
  //#endregion
234
+ //#region ../shared/src/client/code-ops.ts
235
+ /** 是否为普通对象(配置文档的合法节点)。 */
236
+ function isPlainObject(value) {
237
+ if (value === null || typeof value !== "object") return false;
238
+ const proto = Object.getPrototypeOf(value);
239
+ return proto === Object.prototype || proto === null;
240
+ }
241
+ /** 从 V8 语法错误消息中取行列;新版带 `(line L column C)`,旧版只有偏移量。 */
242
+ function positionOf(message, text) {
243
+ const located = /\(line (\d+) column (\d+)\)/.exec(message);
244
+ if (located !== null) return {
245
+ line: Number(located[1]),
246
+ column: Number(located[2])
247
+ };
248
+ const offset = /at position (\d+)/.exec(message);
249
+ if (offset === null) return {
250
+ line: null,
251
+ column: null
252
+ };
253
+ const index = Math.min(Number(offset[1]), text.length);
254
+ const head = text.slice(0, index);
255
+ return {
256
+ line: head.split("\n").length,
257
+ column: index - head.lastIndexOf("\n")
258
+ };
259
+ }
260
+ /**
261
+ * 解析配置文档:必须是 JSON 对象(配置根节点为行级 Config 对象)。
262
+ * @param text - 编辑器全文。
263
+ * @returns 成功给出对象;失败给出原因与可定位的行列。
264
+ */
265
+ function parseConfigJson(text) {
266
+ if (text.trim() === "") return {
267
+ ok: false,
268
+ reason: "empty",
269
+ message: "",
270
+ line: null,
271
+ column: null
272
+ };
273
+ let parsed;
274
+ try {
275
+ parsed = JSON.parse(text);
276
+ } catch (error) {
277
+ const message = error instanceof Error ? error.message : String(error);
278
+ return {
279
+ ok: false,
280
+ reason: "syntax",
281
+ message,
282
+ ...positionOf(message, text)
283
+ };
284
+ }
285
+ if (!isPlainObject(parsed)) return {
286
+ ok: false,
287
+ reason: "root",
288
+ message: "",
289
+ line: 1,
290
+ column: 1
291
+ };
292
+ return {
293
+ ok: true,
294
+ value: parsed
295
+ };
296
+ }
297
+ /** 两空格缩进格式化(解析失败时原样返回输入与失败信息)。 */
298
+ function formatConfigJson(text) {
299
+ const parsed = parseConfigJson(text);
300
+ if (!parsed.ok) return {
301
+ ok: false,
302
+ result: parsed
303
+ };
304
+ return {
305
+ ok: true,
306
+ text: `${JSON.stringify(parsed.value, null, 2)}\n`
307
+ };
308
+ }
309
+ /** 差分:对象删键 → unset;数组删元素 → 下标降序 unset(保持其余下标有效)。 */
310
+ function diffToOps(before, after) {
311
+ const ops = [];
312
+ walk(before, after, [], ops);
313
+ return ops;
314
+ }
315
+ function walk(before, after, path, ops) {
316
+ if (Array.isArray(after)) {
317
+ walkArray(before, after, path, ops);
318
+ return;
319
+ }
320
+ if (isPlainObject(after)) {
321
+ walkObject(before, after, path, ops);
322
+ return;
323
+ }
324
+ if (!Object.is(before, after)) ops.push({
325
+ op: "set",
326
+ path: [...path],
327
+ value: after
328
+ });
329
+ }
330
+ function walkObject(before, after, path, ops) {
331
+ if (!isPlainObject(before)) {
332
+ ops.push({
333
+ op: "set",
334
+ path: [...path],
335
+ value: after
336
+ });
337
+ return;
338
+ }
339
+ for (const [key, value] of Object.entries(after)) {
340
+ if (!Object.hasOwn(before, key)) {
341
+ ops.push({
342
+ op: "set",
343
+ path: [...path, key],
344
+ value
345
+ });
346
+ continue;
347
+ }
348
+ walk(before[key], value, [...path, key], ops);
349
+ }
350
+ for (const key of Object.keys(before)) if (!Object.hasOwn(after, key)) ops.push({
351
+ op: "unset",
352
+ path: [...path, key]
353
+ });
354
+ }
355
+ function walkArray(before, after, path, ops) {
356
+ if (!Array.isArray(before)) {
357
+ ops.push({
358
+ op: "set",
359
+ path: [...path],
360
+ value: after
361
+ });
362
+ return;
363
+ }
364
+ const shared = Math.min(before.length, after.length);
365
+ for (let index = 0; index < shared; index += 1) walk(before[index], after[index], [...path, String(index)], ops);
366
+ for (let index = before.length - 1; index >= after.length; index -= 1) ops.push({
367
+ op: "unset",
368
+ path: [...path, String(index)]
369
+ });
370
+ for (let index = before.length; index < after.length; index += 1) ops.push({
371
+ op: "set",
372
+ path: [...path, String(index)],
373
+ value: after[index]
374
+ });
375
+ }
376
+ /** schema JSON 里的密钥字段路径(`meta.role === 'secret'`):源码编辑器不呈现它们。 */
377
+ function secretPathsOf(schemaJson) {
378
+ const refs = refsOf(schemaJson);
379
+ if (refs === null) return [];
380
+ const root = schemaJson.uid;
381
+ if (typeof root !== "number") return [];
382
+ const out = [];
383
+ collectSecretPaths(refs, root, [], out, /* @__PURE__ */ new Set());
384
+ return out;
385
+ }
386
+ /**
387
+ * 文档里 schema 未声明的键路径。
388
+ *
389
+ * schemastery 对未声明键**透传忽略**(不报错、不剥离),所以这类键会被原样写进
390
+ * 用户层并永久留存——典型来源是历史配置键与手写拼写错误。源码编辑器把它作为
391
+ * 非阻断警告列出来(迁移期新旧键并存时不至于挡住应用)。
392
+ */
393
+ function unknownKeysOf(schemaJson, value) {
394
+ const refs = refsOf(schemaJson);
395
+ if (refs === null || !isPlainObject(value)) return [];
396
+ const root = schemaJson.uid;
397
+ if (typeof root !== "number") return [];
398
+ return [...unknownKeysAt(refs, root, value)].sort();
399
+ }
400
+ /** 返回「该节点下所有未被 schema 声明的键路径」的集合。 */
401
+ function unknownKeysAt(refs, index, value) {
402
+ const node = refs[String(index)];
403
+ if (node === void 0) return /* @__PURE__ */ new Set();
404
+ if (node.list !== void 0) return intersectBranches(refs, node.list, value);
405
+ if (node.inner !== void 0) {
406
+ if (Array.isArray(value)) {
407
+ const out = /* @__PURE__ */ new Set();
408
+ for (const [at, item] of value.entries()) for (const path of unknownKeysAt(refs, node.inner, item)) out.add(`${at}.${path}`);
409
+ return out;
410
+ }
411
+ return unknownKeysAt(refs, node.inner, value);
412
+ }
413
+ if (node.dict === void 0 || !isPlainObject(value)) return /* @__PURE__ */ new Set();
414
+ const out = /* @__PURE__ */ new Set();
415
+ for (const [key, child] of Object.entries(value)) {
416
+ const next = node.dict[key];
417
+ if (next === void 0) {
418
+ out.add(key);
419
+ continue;
420
+ }
421
+ for (const path of unknownKeysAt(refs, next, child)) out.add(`${key}.${path}`);
422
+ }
423
+ return out;
424
+ }
425
+ /** 联合类型:只在「对象型分支」之间取交集(标量分支不否决键判定)。 */
426
+ function intersectBranches(refs, list, value) {
427
+ const objectBranches = list.filter((branch) => refs[String(branch)]?.dict !== void 0);
428
+ if (objectBranches.length === 0) return /* @__PURE__ */ new Set();
429
+ let result = null;
430
+ for (const branch of objectBranches) {
431
+ const keys = unknownKeysAt(refs, branch, value);
432
+ if (result === null) {
433
+ result = keys;
434
+ continue;
435
+ }
436
+ for (const key of [...result]) if (!keys.has(key)) result.delete(key);
437
+ }
438
+ return result ?? /* @__PURE__ */ new Set();
439
+ }
440
+ function refsOf(schemaJson) {
441
+ if (!isPlainObject(schemaJson)) return null;
442
+ const refs = schemaJson.refs;
443
+ return isPlainObject(refs) ? refs : null;
444
+ }
445
+ function collectSecretPaths(refs, index, path, out, seen) {
446
+ const node = refs[String(index)];
447
+ if (node === void 0) return;
448
+ const marker = `${index}:${path.join(".")}`;
449
+ if (seen.has(marker)) return;
450
+ seen.add(marker);
451
+ if (node.meta?.role === "secret") {
452
+ out.push([...path]);
453
+ return;
454
+ }
455
+ for (const [key, child] of Object.entries(node.dict ?? {})) collectSecretPaths(refs, child, [...path, key], out, seen);
456
+ if (typeof node.inner === "number") collectSecretPaths(refs, node.inner, path, out, seen);
457
+ for (const child of node.list ?? []) collectSecretPaths(refs, child, path, out, seen);
458
+ }
459
+ //#endregion
460
+ //#region ../shared/src/client/code-validate.ts
461
+ /**
462
+ * 配置源码编辑的模式校验:用宿主 `describe` 回传的 schema JSON 在浏览器本地
463
+ * 重建同一套 schemastery 校验(库 23KB 纯 JS,随 client bundle 打苞——浏览器端
464
+ * 没有宿主实例,不存在跨实例符号身份问题,见 docs/reference/官方机制参照.md
465
+ * 「客户端平台」)。
466
+ *
467
+ * 校验与宿主写入路径同源:`new Schema(json)` 后按同一份 volatile 投影调用,
468
+ * 因此本地拦下的错误与宿主 `settings/rejected` 的判据一致。
469
+ * @module @dsh-plus/shared/client/code-validate
470
+ */
471
+ /** 重建结果按 schema JSON 对象身份缓存(describe 每次应答一个新对象,无泄漏风险)。 */
472
+ const cache = /* @__PURE__ */ new WeakMap();
473
+ function rebuild(schemaJson) {
474
+ if (!isPlainObject(schemaJson)) return null;
475
+ const cached = cache.get(schemaJson);
476
+ if (cached !== void 0) return cached;
477
+ let built = null;
478
+ try {
479
+ built = new _deepseek_ai_schemastery.default(schemaJson);
480
+ } catch {
481
+ built = null;
482
+ }
483
+ cache.set(schemaJson, built);
484
+ return built;
485
+ }
486
+ /** 从 schemastery 错误消息里取路径前缀:`$.a.b expected number but got x` → `a.b`。 */
487
+ function pathOf(message) {
488
+ const located = /^\$\.([^\s]+)/.exec(message);
489
+ return located === null ? "" : located[1] ?? "";
490
+ }
491
+ /**
492
+ * 按宿主 schema 校验一份配置文档。
493
+ * @param schemaJson - `describe` 应答里的 `schema`(schemastery `toJSON()` 形态)。
494
+ * @param value - 编辑器解析出的对象。
495
+ * @returns 通过(含「未校验」标记)或问题清单。
496
+ */
497
+ function validateAgainstSchema(schemaJson, value) {
498
+ const validate = rebuild(schemaJson);
499
+ if (validate === null) return {
500
+ ok: true,
501
+ validated: false
502
+ };
503
+ try {
504
+ validate(value);
505
+ return {
506
+ ok: true,
507
+ validated: true
508
+ };
509
+ } catch (error) {
510
+ const message = error instanceof Error ? error.message : String(error);
511
+ return {
512
+ ok: false,
513
+ validated: true,
514
+ issues: [{
515
+ path: pathOf(message),
516
+ message
517
+ }]
518
+ };
519
+ }
520
+ }
521
+ //#endregion
522
+ //#region ../shared/src/client/styles.ts
523
+ /**
524
+ * 配置分节样式工厂(各插件 client 的公共收编版)。
525
+ *
526
+ * 目标宿主 dsh 0.2.1-alpha.2:插件页把配置视图放进已有页面级内边距的容器里
527
+ * (`div.detailSections[data-plugin-config]` 或 `section.detailSection[data-plugin-config]`),
528
+ * 外层无边框——故这里输出的是**无边框分节**(小节标题 13px/600、字段 12px 0、
529
+ * 横向零内边距、页脚非 sticky),度量对齐官方设置页
530
+ * (`@deepseek-ai/dsh-client-ui-primitives` 的 settings-form)。
531
+ *
532
+ * 移动端与可达性(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
533
+ * - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
534
+ * - 页脚按钮等宽换行、状态文字独占一行。
535
+ * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
536
+ * @module @dsh-plus/shared/client/styles
537
+ */
538
+ /** 生成全套分节 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
539
+ function cardCss(prefix, extra = "") {
540
+ return `
541
+ .${prefix}-section{box-sizing:border-box;flex-direction:column;width:100%;min-width:0;padding:16px 0;display:flex}
542
+ .${prefix}-sectionHead{align-items:center;gap:8px;min-width:0;display:flex}
543
+ .${prefix}-sectionTitle{min-width:0;color:var(--dsw-alias-label-primary);flex:1;margin:0;font-size:13px;font-weight:600;line-height:1.5}
544
+ .${prefix}-sectionBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
545
+ .${prefix}-sectionDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
546
+ .${prefix}-sectionBody{flex-direction:column;min-width:0;display:flex}
547
+ .${prefix}-sectionFooter{align-items:center;gap:8px;padding-top:16px;display:flex;flex-wrap:wrap}
548
+ .${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}
549
+ .${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
550
+ .${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
551
+ .${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
552
+ .${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
553
+ .${prefix}-head{align-items:center;gap:8px;display:flex}
554
+ .${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
555
+ .${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
556
+ .${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
557
+ .${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
558
+ .${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;transition:border-color .18s,background .18s}
559
+ .${prefix}-input:hover:not(:disabled):not(:focus-visible){border-color:var(--dsw-alias-label-dimmed)}
560
+ .${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
561
+ .${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
562
+ .${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
563
+ .${prefix}-textarea{box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;height:auto;line-height:1.6;min-height:120px;padding:8px 12px;resize:vertical;white-space:pre;width:100%}
564
+ .${prefix}-select{appearance:none;background:var(--dsw-alias-bg-module-platform);border:none;cursor:pointer;background-image:linear-gradient(45deg,transparent 50%,var(--dsw-alias-label-secondary) 50%),linear-gradient(135deg,var(--dsw-alias-label-secondary) 50%,transparent 50%);background-position:calc(100% - 16px) 50%,calc(100% - 11px) 50%;background-size:5px 5px;background-repeat:no-repeat;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;height:34px;box-sizing:border-box;border-radius:8px;padding:0 30px 0 12px;transition:background-color .18s}
565
+ .${prefix}-select:hover:not(:disabled){background-color:var(--dsw-alias-interactive-bg-hover)}
566
+ .${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
567
+ .${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
568
+ .${prefix}-checkRow{align-items:center;gap:10px;display:flex;padding:6px 0}
569
+ .${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer;flex:1;min-width:0}
570
+ /* 自绘圆角扁平开关(官方 UI 无可见原生 checkbox,选择类全走胶囊/菜单) */
571
+ .${prefix}-checkRow input{appearance:none;-webkit-appearance:none;position:relative;box-sizing:border-box;background:var(--dsw-alias-bg-module-platform);border:none;border-radius:999px;width:34px;height:20px;flex:none;cursor:pointer;transition:background .18s;margin:0}
572
+ .${prefix}-checkRow input::after{content:"";position:absolute;top:2px;left:2px;background:var(--dsw-alias-label-primary);border-radius:999px;width:16px;height:16px;transition:left .18s cubic-bezier(.4,0,.2,1)}
573
+ .${prefix}-checkRow input:checked{background:var(--dsw-alias-brand-primary)}
574
+ .${prefix}-checkRow input:checked::after{left:16px;background:var(--dsw-alias-bg-base)}
575
+ .${prefix}-checkRow input:disabled{opacity:.4;cursor:default}
576
+ .${prefix}-checkRow input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
577
+ .${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
578
+ /* 分节(Section):卡片内的二级分组,与一级分节同度量、无边框 */
579
+ .${prefix}-sub{flex-direction:column;padding:12px 0 0;display:flex}
580
+ .${prefix}-subHead{align-items:center;gap:8px;min-width:0;display:flex}
581
+ .${prefix}-subTitle{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;font-weight:600;line-height:1.5}
582
+ .${prefix}-subDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
583
+ .${prefix}-subBody{flex-direction:column;min-width:0;display:flex}
584
+ .${prefix}-subToggle{appearance:none;background:0 0;border:none;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;font-size:12px;padding:2px 6px;border-radius:6px}
585
+ .${prefix}-subToggle:hover{color:var(--dsw-alias-label-primary)}
586
+ /* 字段排布(FieldGrid):窄屏单列,宽屏可两列 */
587
+ .${prefix}-grid{display:grid;grid-template-columns:1fr;min-width:0}
588
+ @media (min-width:768px){
589
+ .${prefix}-grid2{grid-template-columns:1fr 1fr;column-gap:16px}
590
+ }
591
+ /* 只读说明块(Note) */
592
+ .${prefix}-note{background:var(--dsw-alias-bg-module-platform);border-radius:8px;margin:12px 0 0;padding:10px 12px}
593
+ .${prefix}-noteTitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px;font-weight:600;line-height:1.5}
594
+ .${prefix}-noteBody{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5;white-space:pre-wrap}
595
+ /* 列表编辑器(ListEditor):条目头 + 折叠 + 行内操作 */
596
+ .${prefix}-list{flex-direction:column;gap:8px;padding:8px 0 0;display:flex}
597
+ .${prefix}-listItem{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:8px 12px}
598
+ .${prefix}-listItemHead{align-items:center;gap:8px;min-width:0;display:flex}
599
+ .${prefix}-listItemTitle{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
600
+ .${prefix}-listItemBody{flex-direction:column;min-width:0;display:flex;padding-top:4px}
601
+ .${prefix}-listActions{align-items:center;gap:4px;display:flex;flex-wrap:wrap}
602
+ .${prefix}-iconBtn{appearance:none;background:0 0;border:1px solid #0000;border-radius:6px;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;font-size:12px;line-height:1.5;padding:2px 8px}
603
+ .${prefix}-iconBtn:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}
604
+ .${prefix}-iconBtn:disabled{opacity:.4;cursor:default}
605
+ .${prefix}-listAdd{align-self:flex-start}
606
+ .${prefix}-listAddRow{align-items:center;align-self:flex-start;gap:8px;display:flex;flex-wrap:wrap}
607
+ .${prefix}-listEmpty{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5;padding:4px 0}
608
+ .${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
609
+ .${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
610
+ .${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
611
+ .${prefix}-statusError{color:var(--dsw-alias-label-error)}
612
+ .${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}
613
+ .${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
614
+ .${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
615
+ .${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
616
+ .${prefix}-btn:disabled{opacity:.4;cursor:default}
617
+ .${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
618
+ @media (max-width:767px){
619
+ .${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
620
+ .${prefix}-checkRow{min-height:44px;padding:8px 0}
621
+ .${prefix}-status{flex-basis:100%;flex:none}
622
+ .${prefix}-btn{min-height:44px;flex:1;min-width:96px}
623
+ }
624
+ @media (pointer:coarse){
625
+ .${prefix}-btn{min-height:44px}
626
+ .${prefix}-checkRow{min-height:44px}
627
+ .${prefix}-input,.${prefix}-select{height:40px}
628
+ }
629
+ ${extra}
630
+ `;
631
+ }
632
+ /** 源码编辑节的固定类名前缀。 */
633
+ const CODE_SECTION_PREFIX = "dshc";
634
+ /**
635
+ * 源码编辑节(ConfigCodeSection)专用样式:前缀固定 `dshc`,由 shared 自行注入
636
+ * (插件卡片不必知道它的存在)。基础规则复用 cardCss,只追加 details/摘要与
637
+ * 代码文本域的度量。
638
+ */
639
+ function codeSectionCss() {
640
+ return cardCss(CODE_SECTION_PREFIX, `
641
+ .${CODE_SECTION_PREFIX}-details{padding:4px 0 0}
642
+ .${CODE_SECTION_PREFIX}-summary{color:var(--dsw-alias-label-primary);cursor:pointer;font-size:13px;font-weight:600;line-height:1.5;list-style:none;padding:8px 0}
643
+ .${CODE_SECTION_PREFIX}-summary::-webkit-details-marker{display:none}
644
+ .${CODE_SECTION_PREFIX}-summary::before{content:"▸";color:var(--dsw-alias-label-tertiary);display:inline-block;margin-right:6px;transition:transform .18s}
645
+ .${CODE_SECTION_PREFIX}-details[open] .${CODE_SECTION_PREFIX}-summary::before{transform:rotate(90deg)}
646
+ .${CODE_SECTION_PREFIX}-desc{color:var(--dsw-alias-label-tertiary);margin:0 0 8px;font-size:12px;line-height:1.5}
647
+ .${CODE_SECTION_PREFIX}-input{box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;height:auto;line-height:1.6;min-height:240px;padding:10px 12px;resize:vertical;tab-size:2;white-space:pre;width:100%}
648
+ .${CODE_SECTION_PREFIX}-foot{align-items:center;gap:8px;display:flex;flex-wrap:wrap;padding-top:12px}
649
+ .${CODE_SECTION_PREFIX}-foot .${CODE_SECTION_PREFIX}-btn:last-child{margin-left:auto}
650
+ @media (max-width:767px){
651
+ .${CODE_SECTION_PREFIX}-input{font-size:16px}
652
+ }
653
+ `);
654
+ }
655
+ /**
656
+ * 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
657
+ * 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
658
+ */
659
+ function injectCardStyle(pluginId, css) {
660
+ if (typeof document === "undefined") return null;
661
+ const tagId = `${pluginId}/card.css`;
662
+ if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
663
+ const tag = document.createElement("style");
664
+ tag.dataset.plugin = pluginId;
665
+ tag.dataset.pluginCss = tagId;
666
+ tag.textContent = css;
667
+ document.head.appendChild(tag);
668
+ return tag;
669
+ }
670
+ //#endregion
671
+ //#region ../shared/src/client/code-section.ts
672
+ /**
673
+ * 配置源码编辑节(自动追加到每张插件配置卡片页)。
674
+ *
675
+ * 形态:无边框分节,与 ConfigShell/Section 的小节度量一致;文档=宿主 `describe` 回传的
676
+ * volatile 投影(JSON,两空格缩进),校验=本地 JSON 语法 + schemastery 模式,
677
+ * 写回=官方 `settings.mutate` 路径 ops(密钥字段不进文档,也不会被写坏)。
678
+ *
679
+ * 本文件刻意不写 JSX:`@dsh-plus/shared` 的 client 纯逻辑测试用 `node --test`
680
+ * 直跑 .ts(Node 原生类型擦除不支持 JSX),而 `config-slots.ts` 会被测试导入,
681
+ * 因此这条导入链上的模块一律用 `createElement`。React 只经默认导入取用
682
+ * (react 是 CJS,Node ESM 下具名导入不保证可解析)。
683
+ * @module @dsh-plus/shared/client/code-section
684
+ */
685
+ const { createElement: h$1, useEffect: useEffect$3, useMemo: useMemo$2, useState: useState$3, useSyncExternalStore: useSyncExternalStore$2 } = react.default;
686
+ const IDLE = {
687
+ kind: "idle",
688
+ text: ""
689
+ };
690
+ /** 文档播种文本:对象 → 两空格缩进 JSON。 */
691
+ function seedText(value) {
692
+ return value === void 0 ? "{}\n" : `${JSON.stringify(value, null, 2)}\n`;
693
+ }
694
+ /** 解析/校验失败的原因文案(逐条给出行列或字段路径)。 */
695
+ function problemLines(text, snapshot, t) {
696
+ const parsed = parseConfigJson(text);
697
+ if (!parsed.ok) {
698
+ if (parsed.reason === "empty") return {
699
+ problems: [t("codeInvalidEmpty")],
700
+ validated: false
701
+ };
702
+ if (parsed.reason === "root") return {
703
+ problems: [t("codeInvalidRoot")],
704
+ validated: false
705
+ };
706
+ const line = t("codeLine").replace("{line}", String(parsed.line ?? 0)).replace("{column}", String(parsed.column ?? 0));
707
+ return {
708
+ problems: [`${t("codeInvalidJson")}(${line})${parsed.message}`],
709
+ validated: false
710
+ };
711
+ }
712
+ const result = validateAgainstSchema(snapshot.schema, parsed.value);
713
+ if (result.ok) return {
714
+ problems: [],
715
+ validated: result.validated
716
+ };
717
+ return {
718
+ problems: result.issues.map((issue) => `${t("codeInvalidSchema")}:${issue.path === "" ? issue.message : `${issue.path} — ${issue.message}`}`),
719
+ validated: true
720
+ };
721
+ }
722
+ /** 与当前快照的差分(无改动时为空数组)。 */
723
+ function opsOf(text, snapshot) {
724
+ const parsed = parseConfigJson(text);
725
+ return parsed.ok ? diffToOps(snapshot.value, parsed.value) : [];
726
+ }
727
+ /** 应用:官方路径 ops 写回,成功后重载快照(revision 变化会重新播种文档)。 */
728
+ function applyOps(options) {
729
+ const { api, scope, ops, revision, t, setStatus, setApplying } = options;
730
+ setApplying(true);
731
+ api.mutate(ops, revision).then(() => {
732
+ setStatus({
733
+ kind: "ok",
734
+ text: t("codeApplied")
735
+ });
736
+ return scope.load();
737
+ }).catch((error) => {
738
+ const message = error instanceof Error ? error.message : String(error);
739
+ setStatus({
740
+ kind: "error",
741
+ text: `${t("codeApplyFailed")}${message}`
742
+ });
743
+ }).finally(() => setApplying(false));
744
+ }
745
+ /** 草稿动作:应用(官方路径 ops 写回)、格式化、编辑与 Tab 缩进。 */
746
+ function draftHandlers(options) {
747
+ const { api, scope, t, snapshot, text, ops, setText, setStatus, setApplying } = options;
748
+ return {
749
+ onApply: () => {
750
+ applyOps({
751
+ api,
752
+ scope,
753
+ ops,
754
+ revision: snapshot.revision,
755
+ t,
756
+ setStatus,
757
+ setApplying
758
+ });
759
+ },
760
+ onFormat: () => {
761
+ const formatted = formatConfigJson(text);
762
+ if (formatted.ok) setText(formatted.text);
763
+ },
764
+ onChange: (event) => {
765
+ setText(event.target.value);
766
+ setStatus(IDLE);
767
+ },
768
+ onKeyDown: (event) => {
769
+ if (event.key !== "Tab") return;
770
+ event.preventDefault();
771
+ const target = event.currentTarget;
772
+ const { selectionStart, selectionEnd, value } = target;
773
+ setText(`${value.slice(0, selectionStart)} ${value.slice(selectionEnd)}`);
774
+ queueMicrotask(() => {
775
+ target.selectionStart = selectionStart + 2;
776
+ target.selectionEnd = selectionStart + 2;
777
+ });
778
+ }
779
+ };
780
+ }
781
+ /** 校验派生量:逐次编辑重算(problems 供提示与禁用判定,validated 区分「模式外」)。 */
782
+ function useCodeChecks(text, snapshot, t) {
783
+ const { problems, validated } = useMemo$2(() => problemLines(text, snapshot, t), [
784
+ text,
785
+ snapshot,
786
+ t
787
+ ]);
788
+ return {
789
+ problems,
790
+ validated,
791
+ ops: useMemo$2(() => opsOf(text, snapshot), [text, snapshot]),
792
+ secrets: useMemo$2(() => secretPathsOf(snapshot.schema), [snapshot.schema]),
793
+ unknown: useMemo$2(() => {
794
+ const parsed = parseConfigJson(text);
795
+ return parsed.ok ? unknownKeysOf(snapshot.schema, parsed.value) : [];
796
+ }, [text, snapshot.schema])
797
+ };
798
+ }
799
+ /** 分节状态:快照订阅、文档文本、校验结果与草稿动作(主组件只做组装)。 */
800
+ function useCodeSection(props) {
801
+ const { ns, t, scope, api } = props;
802
+ const snapshot = useSyncExternalStore$2((listener) => scope.subscribe(listener), () => scope.getSnapshot());
803
+ const [text, setText] = useState$3(() => seedText(snapshot.value));
804
+ const [status, setStatus] = useState$3(IDLE);
805
+ const [applying, setApplying] = useState$3(false);
806
+ const [open, setOpen] = useState$3(false);
807
+ const revision = snapshot.revision;
808
+ const snapshotStatus = snapshot.status;
809
+ useEffect$3(() => {
810
+ setText(seedText(snapshot.value));
811
+ setStatus(IDLE);
812
+ }, [revision, snapshotStatus]);
813
+ useEffect$3(() => {
814
+ injectCardStyle("@dsh-plus/shared", codeSectionCss());
815
+ }, []);
816
+ const { problems, validated, ops, secrets, unknown } = useCodeChecks(text, snapshot, t);
817
+ const ready = snapshot.status === "ready";
818
+ const disabled = !ready || !snapshot.writable || applying;
819
+ return {
820
+ ready,
821
+ ns,
822
+ t,
823
+ scope,
824
+ snapshot,
825
+ text,
826
+ setText,
827
+ status,
828
+ setStatus,
829
+ applying,
830
+ setApplying,
831
+ open,
832
+ setOpen,
833
+ problems,
834
+ validated,
835
+ ops,
836
+ secrets,
837
+ unknown,
838
+ disabled,
839
+ canApply: !disabled && problems.length === 0 && ops.length > 0,
840
+ ...draftHandlers({
841
+ api,
842
+ scope,
843
+ t,
844
+ snapshot,
845
+ text,
846
+ ops,
847
+ setText,
848
+ setStatus,
849
+ setApplying
850
+ })
851
+ };
852
+ }
853
+ /** 提示行:无改动 / 未校验 / 密钥计数 / 模式外键 / 不可用或只读。 */
854
+ function noteLines(state) {
855
+ const { t, ready, problems, validated, ops, secrets, unknown, snapshot } = state;
856
+ const notes = [];
857
+ if (problems.length === 0 && ops.length === 0 && ready) notes.push(h$1("p", {
858
+ className: "dshc-hint",
859
+ key: "no-change"
860
+ }, t("codeNoChanges")));
861
+ if (problems.length === 0 && !validated) notes.push(h$1("p", {
862
+ className: "dshc-hint",
863
+ key: "unvalidated"
864
+ }, t("codeUnvalidated")));
865
+ if (secrets.length > 0) notes.push(h$1("p", {
866
+ className: "dshc-hint",
867
+ key: "secrets"
868
+ }, t("codeSecretsNote").replace("{n}", String(secrets.length))));
869
+ if (unknown.length > 0) notes.push(h$1("p", {
870
+ className: "dshc-hint",
871
+ key: "unknown"
872
+ }, t("codeUnknownKeys").replace("{n}", String(unknown.length)).replace("{keys}", unknown.slice(0, 8).join("、"))));
873
+ if (snapshot.status === "unavailable") notes.push(h$1("p", {
874
+ className: "dshc-hint",
875
+ key: "unavailable"
876
+ }, t("codeUnavailable")));
877
+ else if (!snapshot.writable) notes.push(h$1("p", {
878
+ className: "dshc-hint",
879
+ key: "readonly"
880
+ }, t("codeReadOnly")));
881
+ return notes;
882
+ }
883
+ /** 页脚:状态行 + 格式化 / 应用按钮。 */
884
+ function codeFooter(state) {
885
+ const { t, status, disabled, canApply, applying, onFormat, onApply } = state;
886
+ return h$1("div", { className: "dshc-foot" }, status.kind === "idle" ? null : h$1("p", {
887
+ className: `dshc-status${status.kind === "error" ? " dshc-statusError" : ""}`,
888
+ role: "status"
889
+ }, status.text), h$1("button", {
890
+ type: "button",
891
+ className: "dshc-btn dshc-btnGhost",
892
+ disabled,
893
+ onClick: onFormat
894
+ }, t("codeFormat")), h$1("button", {
895
+ type: "button",
896
+ className: "dshc-btn dshc-btnPrimary",
897
+ disabled: !canApply,
898
+ onClick: onApply
899
+ }, applying ? t("codeApplying") : t("codeApply")));
900
+ }
901
+ function ConfigCodeSection(props) {
902
+ const state = useCodeSection(props);
903
+ const { ns, t, text, disabled, open, setOpen, status, problems, onChange, onKeyDown } = state;
904
+ return h$1("section", {
905
+ className: "dshc-section",
906
+ "aria-label": `${ns} ${t("codeSectionTitle")}`
907
+ }, h$1("details", {
908
+ className: "dshc-details",
909
+ open: open || status.kind === "error",
910
+ onToggle: (event) => {
911
+ setOpen(event.currentTarget.open);
912
+ }
913
+ }, h$1("summary", { className: "dshc-summary" }, t("codeSectionTitle")), h$1("p", { className: "dshc-desc" }, t("codeSectionDesc")), h$1("textarea", {
914
+ className: `dshc-input${problems.length > 0 ? " dshc-inputInvalid" : ""}`,
915
+ rows: 16,
916
+ spellCheck: false,
917
+ "aria-invalid": problems.length > 0 ? true : void 0,
918
+ value: text,
919
+ disabled,
920
+ onChange,
921
+ onKeyDown
922
+ }), problems.map((problem) => h$1("p", {
923
+ className: "dshc-invalid",
924
+ role: "alert",
925
+ key: problem
926
+ }, problem)), ...noteLines(state), codeFooter(state)));
927
+ }
928
+ //#endregion
154
929
  //#region ../shared/src/client/config-slots.ts
930
+ /**
931
+ * 配置卡片的槽位注册助手(目标宿主:dsh 0.2.1-alpha.2)。
932
+ *
933
+ * 官方插件页(`dsh-client-ui-plugin-manager`)为第三方配置视图声明两个 keyed 槽位:
934
+ * - `plugins.row.config`(key = `<bundle 包名>#<row id>`):bundle 详情页对应行出现
935
+ * 「配置」入口,行配置页渲染 `view: 'summary'`(一行简介)与 `view: 'page'`
936
+ * (带保存控件的表单);
937
+ * - `plugins.bundle.config`(key = 包名):包详情页本体配置,仅渲染 `view: 'page'`。
938
+ *
939
+ * 页面自己画标题、图标、面包屑与页面级内边距(`detailSections` 内无边框容器),
940
+ * 故 page 视图输出无边框分节(见 card.tsx),summary 视图只返回一行文本。
941
+ * 旧 `settings.plugin.item` 槽位已随官方插件页迁移删除,不再注册。
942
+ *
943
+ * **源码编辑节自动追加**:注册时把插件组件包一层,page 视图在原卡片之后追加
944
+ * `ConfigCodeSection`(复用同一份 scope/api),summary 视图原样透传。因此「只要
945
+ * 插件存在可配置项」就有源码编辑入口,插件侧零接线;命名空间没有 volatile 字段时
946
+ * 它本身不出现在 describe 视图里,该节自然显示为不可用。
947
+ *
948
+ * @module @dsh-plus/shared/client/config-slots
949
+ */
950
+ const { createElement: h, Fragment } = react.default;
155
951
  /** dsh-plus 聚合 bundle 的包名(各插件 row 均经其补丁层插入 profile)。 */
156
952
  const DSH_PLUS_BUNDLE = "@dsh-plus/bundle-main";
953
+ /** page 视图:插件卡片 + 自动追加的源码编辑节(summary 视图原样透传)。 */
954
+ function withCodeSection(component, ns) {
955
+ return function AutoConfigView(props) {
956
+ const card = h(component, props);
957
+ if (props.view !== "page") return card;
958
+ return h(Fragment, null, card, h(ConfigCodeSection, {
959
+ ns,
960
+ t: props.t,
961
+ scope: props.scope,
962
+ api: props.api
963
+ }));
964
+ };
965
+ }
157
966
  /**
158
967
  * 把一张配置卡片注册进插件页的两个配置槽位。
159
968
  * 两个槽位都由 0.2.1-alpha.2 的插件页声明,任一缺席即报错——不做版本探测。
160
969
  */
161
970
  function injectPluginConfigCard(slots, reg) {
971
+ const component = withCodeSection(reg.component, reg.ns);
162
972
  const base = {
163
973
  locale: reg.ns,
164
974
  inject: reg.inject
@@ -167,14 +977,26 @@ window.__ModuleLoader__.load({
167
977
  name: "plugins.row.config",
168
978
  key: `${DSH_PLUS_BUNDLE}#${reg.rowId}`,
169
979
  ...base
170
- }, reg.component));
980
+ }, component));
171
981
  slots.inject("plugins.bundle.config", () => slots.register({
172
982
  name: "plugins.bundle.config",
173
983
  key: reg.pkg,
174
984
  ...base
175
- }, reg.component));
985
+ }, component));
176
986
  }
177
987
  //#endregion
988
+ //#region ../shared/src/client/credentials.tsx
989
+ /**
990
+ * 凭据面(共享件):官方 settings-controller 的 `remote.credentials` 命名空间
991
+ * (describe/set/unset/onChange),复用官方 credentials seam,不另开 HTTP 端点。
992
+ * **值只写不读**——describe 只回「已配置 / 来源 / 可写」,没有任何方法回传值。
993
+ *
994
+ * 凭据与 settings 草稿相互独立:不进命名空间、不参与脏判定,保存即落
995
+ * `$DSH_HOME/.credentials.yaml` 并热生效(宿主每次工具调用重新 resolve),
996
+ * 因此改口令不需要保存卡片、也不需要 /reload 或重启。
997
+ * @module @dsh-plus/shared/client/credentials
998
+ */
999
+ //#endregion
178
1000
  //#region ../shared/src/client/draft.ts
179
1001
  /**
180
1002
  * 单命名空间 staged 草稿(简单配置卡片共用):读 scope 快照、播种草稿、
@@ -203,7 +1025,31 @@ window.__ModuleLoader__.load({
203
1025
  enabledOff: "未启用",
204
1026
  saveFailed: "保存失败,请检查填写内容。",
205
1027
  confirm: "确认",
206
- cancel: "取消"
1028
+ cancel: "取消",
1029
+ listAdd: "新增",
1030
+ listRemove: "删除",
1031
+ listMoveUp: "上移",
1032
+ listMoveDown: "下移",
1033
+ listDuplicate: "复制",
1034
+ listEmpty: "暂无条目。",
1035
+ codeSectionTitle: "源码编辑(JSON)",
1036
+ codeSectionDesc: "直接编辑本插件的可配置字段(仅 .volatile() 字段)。「应用」按官方路径编辑写回用户层,密钥字段不在此编辑器内。",
1037
+ codeFormat: "格式化",
1038
+ codeApply: "应用",
1039
+ codeApplying: "应用中…",
1040
+ codeApplied: "已应用。",
1041
+ codeNoChanges: "与当前配置一致,无需应用。",
1042
+ codeInvalidJson: "JSON 语法错误",
1043
+ codeInvalidEmpty: "配置不能为空。",
1044
+ codeInvalidRoot: "根节点必须是对象。",
1045
+ codeInvalidSchema: "模式校验未通过",
1046
+ codeUnvalidated: "宿主未回传 schema,已跳过本地校验(写入仍由宿主把关)。",
1047
+ codeSecretsNote: "有 {n} 个密钥字段不在此编辑器内(在凭据区或行级配置中管理)。",
1048
+ codeUnknownKeys: "有 {n} 个键不在 schema 里({keys}):会被原样保留并被运行时忽略,建议删除。",
1049
+ codeUnavailable: "该行未激活或命名空间不可用,源码编辑不可用。",
1050
+ codeReadOnly: "当前部署无 settings provider,源码编辑只读。",
1051
+ codeApplyFailed: "应用失败:",
1052
+ codeLine: "第 {line} 行第 {column} 列"
207
1053
  };
208
1054
  const commonEn = {
209
1055
  save: "Save",
@@ -220,7 +1066,31 @@ window.__ModuleLoader__.load({
220
1066
  enabledOff: "Off",
221
1067
  saveFailed: "Save failed; check the fields.",
222
1068
  confirm: "Confirm",
223
- cancel: "Cancel"
1069
+ cancel: "Cancel",
1070
+ listAdd: "Add",
1071
+ listRemove: "Remove",
1072
+ listMoveUp: "Move up",
1073
+ listMoveDown: "Move down",
1074
+ listDuplicate: "Duplicate",
1075
+ listEmpty: "No entries yet.",
1076
+ codeSectionTitle: "Source editor (JSON)",
1077
+ codeSectionDesc: "Edit this plugin’s configurable fields directly (only .volatile() fields). Apply writes back through the official path edits; secret fields never appear here.",
1078
+ codeFormat: "Format",
1079
+ codeApply: "Apply",
1080
+ codeApplying: "Applying…",
1081
+ codeApplied: "Applied.",
1082
+ codeNoChanges: "Identical to the current config; nothing to apply.",
1083
+ codeInvalidJson: "JSON syntax error",
1084
+ codeInvalidEmpty: "Config must not be empty.",
1085
+ codeInvalidRoot: "The root node must be an object.",
1086
+ codeInvalidSchema: "Schema validation failed",
1087
+ codeUnvalidated: "The host returned no schema, so local validation was skipped (writes are still validated by the host).",
1088
+ codeSecretsNote: "{n} secret field(s) are not editable here (manage them in the credentials section or at the row level).",
1089
+ codeUnknownKeys: "{n} key(s) are absent from the schema ({keys}): they are preserved verbatim and ignored at runtime; remove them.",
1090
+ codeUnavailable: "This row is inactive or its namespace is unavailable; the source editor is disabled.",
1091
+ codeReadOnly: "No settings provider in this deployment; the source editor is read-only.",
1092
+ codeApplyFailed: "Apply failed: ",
1093
+ codeLine: "line {line}, column {column}"
224
1094
  };
225
1095
  /**
226
1096
  * own 覆盖同键合并(返回新对象,入参不可变)。
@@ -247,6 +1117,8 @@ window.__ModuleLoader__.load({
247
1117
  let state = {
248
1118
  status: "loading",
249
1119
  value: void 0,
1120
+ schema: void 0,
1121
+ secrets: [],
250
1122
  revision: void 0,
251
1123
  writable: false
252
1124
  };
@@ -272,6 +1144,8 @@ window.__ModuleLoader__.load({
272
1144
  publish({
273
1145
  status: "unavailable",
274
1146
  value: void 0,
1147
+ schema: void 0,
1148
+ secrets: [],
275
1149
  revision: void 0,
276
1150
  writable: view.writable
277
1151
  });
@@ -280,6 +1154,8 @@ window.__ModuleLoader__.load({
280
1154
  publish({
281
1155
  status: "ready",
282
1156
  value: namespace.value,
1157
+ schema: namespace.schema,
1158
+ secrets: namespace.secrets,
283
1159
  revision: namespace.revision,
284
1160
  writable: view.writable
285
1161
  });
@@ -313,6 +1189,10 @@ window.__ModuleLoader__.load({
313
1189
  const response = await remote.update(ns, patch, expectedRevision);
314
1190
  if (!response.ok) throw new Error(response.error.message ?? "settings update failed");
315
1191
  },
1192
+ mutate: async (ops, expectedRevision) => {
1193
+ const response = await remote.mutate(ns, ops, expectedRevision);
1194
+ if (!response.ok) throw new Error(response.error.message ?? "settings mutate failed");
1195
+ },
316
1196
  describe: async () => {
317
1197
  const response = await remote.describe();
318
1198
  if (!response.ok) throw new Error(response.error.message ?? "settings describe failed");
@@ -321,101 +1201,6 @@ window.__ModuleLoader__.load({
321
1201
  };
322
1202
  }
323
1203
  //#endregion
324
- //#region ../shared/src/client/styles.ts
325
- /**
326
- * 配置分节样式工厂(各插件 client 的公共收编版)。
327
- *
328
- * 目标宿主 dsh 0.2.1-alpha.2:插件页把配置视图放进已有页面级内边距的容器里
329
- * (`div.detailSections[data-plugin-config]` 或 `section.detailSection[data-plugin-config]`),
330
- * 外层无边框——故这里输出的是**无边框分节**(小节标题 13px/600、字段 12px 0、
331
- * 横向零内边距、页脚非 sticky),度量对齐官方设置页
332
- * (`@deepseek-ai/dsh-client-ui-primitives` 的 settings-form)。
333
- *
334
- * 移动端与可达性(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
335
- * - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
336
- * - 页脚按钮等宽换行、状态文字独占一行。
337
- * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
338
- * @module @dsh-plus/shared/client/styles
339
- */
340
- /** 生成全套分节 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
341
- function cardCss(prefix, extra = "") {
342
- return `
343
- .${prefix}-section{box-sizing:border-box;flex-direction:column;width:100%;min-width:0;padding:16px 0;display:flex}
344
- .${prefix}-sectionHead{align-items:center;gap:8px;min-width:0;display:flex}
345
- .${prefix}-sectionTitle{min-width:0;color:var(--dsw-alias-label-primary);flex:1;margin:0;font-size:13px;font-weight:600;line-height:1.5}
346
- .${prefix}-sectionBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
347
- .${prefix}-sectionDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
348
- .${prefix}-sectionBody{flex-direction:column;min-width:0;display:flex}
349
- .${prefix}-sectionFooter{align-items:center;gap:8px;padding-top:16px;display:flex;flex-wrap:wrap}
350
- .${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}
351
- .${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
352
- .${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
353
- .${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
354
- .${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
355
- .${prefix}-head{align-items:center;gap:8px;display:flex}
356
- .${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
357
- .${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
358
- .${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
359
- .${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
360
- .${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;transition:border-color .18s,background .18s}
361
- .${prefix}-input:hover:not(:disabled):not(:focus-visible){border-color:var(--dsw-alias-label-dimmed)}
362
- .${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
363
- .${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
364
- .${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
365
- .${prefix}-select{appearance:none;background:var(--dsw-alias-bg-module-platform);border:none;cursor:pointer;background-image:linear-gradient(45deg,transparent 50%,var(--dsw-alias-label-secondary) 50%),linear-gradient(135deg,var(--dsw-alias-label-secondary) 50%,transparent 50%);background-position:calc(100% - 16px) 50%,calc(100% - 11px) 50%;background-size:5px 5px;background-repeat:no-repeat;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;height:34px;box-sizing:border-box;border-radius:8px;padding:0 30px 0 12px;transition:background-color .18s}
366
- .${prefix}-select:hover:not(:disabled){background-color:var(--dsw-alias-interactive-bg-hover)}
367
- .${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
368
- .${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
369
- .${prefix}-checkRow{align-items:center;gap:10px;display:flex;padding:6px 0}
370
- .${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer;flex:1;min-width:0}
371
- /* 自绘圆角扁平开关(官方 UI 无可见原生 checkbox,选择类全走胶囊/菜单) */
372
- .${prefix}-checkRow input{appearance:none;-webkit-appearance:none;position:relative;box-sizing:border-box;background:var(--dsw-alias-bg-module-platform);border:none;border-radius:999px;width:34px;height:20px;flex:none;cursor:pointer;transition:background .18s;margin:0}
373
- .${prefix}-checkRow input::after{content:"";position:absolute;top:2px;left:2px;background:var(--dsw-alias-label-primary);border-radius:999px;width:16px;height:16px;transition:left .18s cubic-bezier(.4,0,.2,1)}
374
- .${prefix}-checkRow input:checked{background:var(--dsw-alias-brand-primary)}
375
- .${prefix}-checkRow input:checked::after{left:16px;background:var(--dsw-alias-bg-base)}
376
- .${prefix}-checkRow input:disabled{opacity:.4;cursor:default}
377
- .${prefix}-checkRow input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
378
- .${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
379
- .${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
380
- .${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
381
- .${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
382
- .${prefix}-statusError{color:var(--dsw-alias-label-error)}
383
- .${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}
384
- .${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
385
- .${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
386
- .${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
387
- .${prefix}-btn:disabled{opacity:.4;cursor:default}
388
- .${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
389
- @media (max-width:767px){
390
- .${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
391
- .${prefix}-checkRow{min-height:44px;padding:8px 0}
392
- .${prefix}-status{flex-basis:100%;flex:none}
393
- .${prefix}-btn{min-height:44px;flex:1;min-width:96px}
394
- }
395
- @media (pointer:coarse){
396
- .${prefix}-btn{min-height:44px}
397
- .${prefix}-checkRow{min-height:44px}
398
- .${prefix}-input,.${prefix}-select{height:40px}
399
- }
400
- ${extra}
401
- `;
402
- }
403
- /**
404
- * 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
405
- * 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
406
- */
407
- function injectCardStyle(pluginId, css) {
408
- if (typeof document === "undefined") return null;
409
- const tagId = `${pluginId}/card.css`;
410
- if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
411
- const tag = document.createElement("style");
412
- tag.dataset.plugin = pluginId;
413
- tag.dataset.pluginCss = tagId;
414
- tag.textContent = css;
415
- document.head.appendChild(tag);
416
- return tag;
417
- }
418
- //#endregion
419
1204
  //#region src/ns.ts
420
1205
  /**
421
1206
  * settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
@@ -456,7 +1241,6 @@ ${extra}
456
1241
  }
457
1242
  function draftFromValue(value) {
458
1243
  return {
459
- enabled: value.enabled,
460
1244
  host: value.smtp.host,
461
1245
  port: String(value.smtp.port),
462
1246
  secure: value.smtp.secure,
@@ -473,7 +1257,6 @@ ${extra}
473
1257
  /** 草稿 → 提交形状(pass 为空表示「保持已存密钥」,由调用方剔除该键)。 */
474
1258
  function toPatch(draft) {
475
1259
  return {
476
- enabled: draft.enabled,
477
1260
  smtp: {
478
1261
  host: draft.host.trim(),
479
1262
  port: Number(draft.port),
@@ -509,13 +1292,12 @@ ${extra}
509
1292
  disabled,
510
1293
  onEdit: (v) => onEdit("host", v)
511
1294
  }),
512
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
1295
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberField, {
513
1296
  prefix: "dne",
514
1297
  id: "dne-port",
515
1298
  label: t("port"),
516
1299
  hint: t("portHint"),
517
1300
  value: draft.port,
518
- numeric: true,
519
1301
  disabled,
520
1302
  invalid: !isPositiveInt(draft.port),
521
1303
  invalidLabel: t("invalidNumber"),
@@ -576,10 +1358,6 @@ ${extra}
576
1358
  disabled,
577
1359
  onEdit: (v) => onEdit("toText", v)
578
1360
  }),
579
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
580
- className: "dne-groupLabel",
581
- children: t("triggerGroup")
582
- }),
583
1361
  TRIGGER_KEYS.map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
584
1362
  prefix: "dne",
585
1363
  id: `dne-${key}`,
@@ -588,25 +1366,23 @@ ${extra}
588
1366
  disabled,
589
1367
  onEdit: (v) => props.onTrigger(key, v)
590
1368
  }, key)),
591
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
1369
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberField, {
592
1370
  prefix: "dne",
593
1371
  id: "dne-debounce",
594
1372
  label: t("idleDebounceMs"),
595
1373
  hint: t("idleDebounceMsHint"),
596
1374
  value: draft.idleDebounceMs,
597
- numeric: true,
598
1375
  disabled,
599
1376
  invalid: !isPositiveInt(draft.idleDebounceMs),
600
1377
  invalidLabel: t("invalidNumber"),
601
1378
  onEdit: (v) => onEdit("idleDebounceMs", v)
602
1379
  }),
603
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
1380
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberField, {
604
1381
  prefix: "dne",
605
1382
  id: "dne-maxchars",
606
1383
  label: t("maxBodyChars"),
607
1384
  hint: t("maxBodyCharsHint"),
608
1385
  value: draft.maxBodyChars,
609
- numeric: true,
610
1386
  disabled,
611
1387
  invalid: !isPositiveInt(draft.maxBodyChars) || Number(draft.maxBodyChars) < 200,
612
1388
  invalidLabel: t("invalidNumber"),
@@ -627,7 +1403,7 @@ ${extra}
627
1403
  /**
628
1404
  * 「邮件通知」配置卡片:经 injectPluginConfigCard 注册(插件页 plugins.row.config /
629
1405
  * plugins.bundle.config,view 分发 summary/page)。
630
- * 外壳与基础控件走 @dsh-plus/shared/client 套件(CardChrome/TextField/CheckRow),
1406
+ * 外壳与基础控件走 @dsh-plus/shared/client 套件(ConfigShell/Section/字段控件),
631
1407
  * 本文件只保留业务字段与保存/测试逻辑。交互对齐官方卡片:折叠/展开、
632
1408
  * staged draft、未保存标记、保存/放弃;另加「发送测试邮件」。
633
1409
  * 配置读写经 ctx.remote.settings 直连(connection.api.settings
@@ -758,14 +1534,10 @@ ${extra}
758
1534
  sendTestMail(t, setStatus, () => setTesting(false));
759
1535
  };
760
1536
  const disabled = !snapshot.writable;
761
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CardChrome, {
1537
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ConfigShell, {
762
1538
  prefix: "dne",
763
1539
  title: t("title"),
764
1540
  description: t("description"),
765
- statusBadge: {
766
- text: t(draft.enabled ? "enabledOn" : "enabledOff"),
767
- on: draft.enabled
768
- },
769
1541
  dirty,
770
1542
  dirtyLabel: t("unsaved"),
771
1543
  readOnlyNotice: disabled ? t("readOnly") : void 0,
@@ -784,30 +1556,27 @@ ${extra}
784
1556
  },
785
1557
  onSave
786
1558
  }),
787
- children: [
788
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
789
- prefix: "dne",
790
- id: "dne-enabled",
791
- label: t("enabled"),
792
- checked: draft.enabled,
793
- disabled,
794
- onEdit: (v) => edit("enabled", v)
795
- }),
796
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SmtpFields, {
1559
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Section, {
1560
+ prefix: "dne",
1561
+ title: t("smtpGroup"),
1562
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SmtpFields, {
797
1563
  t,
798
1564
  draft,
799
1565
  disabled,
800
1566
  passConfigured,
801
1567
  onEdit: edit
802
- }),
803
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TriggerFields, {
1568
+ })
1569
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Section, {
1570
+ prefix: "dne",
1571
+ title: t("triggerGroup"),
1572
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TriggerFields, {
804
1573
  t,
805
1574
  draft,
806
1575
  disabled,
807
1576
  onEdit: edit,
808
1577
  onTrigger: editTrigger
809
1578
  })
810
- ]
1579
+ })]
811
1580
  });
812
1581
  }
813
1582
  //#endregion
@@ -822,7 +1591,7 @@ ${extra}
822
1591
  title: "邮件通知",
823
1592
  description: "任务结束、等待决策或出错时向指定邮箱发送邮件。",
824
1593
  summaryLine: "任务结束、等待决策或出错时向指定邮箱发送邮件。",
825
- enabled: "启用通知",
1594
+ smtpGroup: "SMTP 连接",
826
1595
  host: "SMTP 服务器",
827
1596
  hostHint: "如 smtp.qq.com、smtp.163.com。",
828
1597
  port: "端口",
@@ -860,7 +1629,7 @@ ${extra}
860
1629
  title: "Email notifications",
861
1630
  description: "Email a mailbox when a task finishes, awaits a decision, or fails.",
862
1631
  summaryLine: "Email a mailbox when a task finishes, awaits a decision, or fails.",
863
- enabled: "Enable notifications",
1632
+ smtpGroup: "SMTP connection",
864
1633
  host: "SMTP host",
865
1634
  hostHint: "e.g. smtp.qq.com, smtp.gmail.com.",
866
1635
  port: "Port",