@dsh-plus/access-gate 0.3.32 → 0.3.34

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", {
@@ -44,11 +69,26 @@ window.__ModuleLoader__.load({
44
69
  }
45
70
  //#endregion
46
71
  //#region ../shared/src/client/card.tsx
72
+ /**
73
+ * 配置卡片外壳与排版件:`ConfigShell`(卡片级无边框分节)、`Section`(卡片内二级
74
+ * 分组)、`FieldGrid`(字段排布)、`Note`(只读说明)、`ListEditor`(数组型资源
75
+ * 统一编辑)、`CardLoading`(取值未到达占位)。
76
+ *
77
+ * 宿主页面(`plugins.row.config` / `plugins.bundle.config` 的 page 视图)自己画
78
+ * 标题、图标、面包屑与页面级内边距,视图只填内容区——所以这里不再自绘带边框
79
+ * 卡片(会形成卡片套卡片,把移动端可用宽度逐层扣掉),也不做折叠:page 视图
80
+ * 本身就是表单落地页。度量对齐官方设置页(dsh-client-ui-primitives 的
81
+ * settings-form):小节标题 13px/600、字段区零横向内边距、页脚非 sticky。
82
+ *
83
+ * 各插件 card.tsx 只填 children 字段区与 actions;类名前缀与样式由
84
+ * cardCss(prefix) 配套。
85
+ * @module @dsh-plus/shared/client/card
86
+ */
47
87
  const IDLE_STATUS = {
48
88
  kind: "idle",
49
89
  text: ""
50
90
  };
51
- function CardChrome(props) {
91
+ function ConfigShell(props) {
52
92
  const p = props.prefix;
53
93
  const badge = props.statusBadge;
54
94
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
@@ -104,7 +144,7 @@ window.__ModuleLoader__.load({
104
144
  ]
105
145
  });
106
146
  }
107
- /** 取值未到达时的占位:与 CardChrome 同形态,避免宿主页里闪一次卡片外壳。 */
147
+ /** 取值未到达时的占位:与 ConfigShell 同形态,避免宿主页里闪一次卡片外壳。 */
108
148
  function CardLoading(props) {
109
149
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
110
150
  className: `${props.prefix}-section`,
@@ -116,14 +156,744 @@ window.__ModuleLoader__.load({
116
156
  });
117
157
  }
118
158
  //#endregion
159
+ //#region ../shared/src/client/code-ops.ts
160
+ /** 是否为普通对象(配置文档的合法节点)。 */
161
+ function isPlainObject(value) {
162
+ if (value === null || typeof value !== "object") return false;
163
+ const proto = Object.getPrototypeOf(value);
164
+ return proto === Object.prototype || proto === null;
165
+ }
166
+ /** 从 V8 语法错误消息中取行列;新版带 `(line L column C)`,旧版只有偏移量。 */
167
+ function positionOf(message, text) {
168
+ const located = /\(line (\d+) column (\d+)\)/.exec(message);
169
+ if (located !== null) return {
170
+ line: Number(located[1]),
171
+ column: Number(located[2])
172
+ };
173
+ const offset = /at position (\d+)/.exec(message);
174
+ if (offset === null) return {
175
+ line: null,
176
+ column: null
177
+ };
178
+ const index = Math.min(Number(offset[1]), text.length);
179
+ const head = text.slice(0, index);
180
+ return {
181
+ line: head.split("\n").length,
182
+ column: index - head.lastIndexOf("\n")
183
+ };
184
+ }
185
+ /**
186
+ * 解析配置文档:必须是 JSON 对象(配置根节点为行级 Config 对象)。
187
+ * @param text - 编辑器全文。
188
+ * @returns 成功给出对象;失败给出原因与可定位的行列。
189
+ */
190
+ function parseConfigJson(text) {
191
+ if (text.trim() === "") return {
192
+ ok: false,
193
+ reason: "empty",
194
+ message: "",
195
+ line: null,
196
+ column: null
197
+ };
198
+ let parsed;
199
+ try {
200
+ parsed = JSON.parse(text);
201
+ } catch (error) {
202
+ const message = error instanceof Error ? error.message : String(error);
203
+ return {
204
+ ok: false,
205
+ reason: "syntax",
206
+ message,
207
+ ...positionOf(message, text)
208
+ };
209
+ }
210
+ if (!isPlainObject(parsed)) return {
211
+ ok: false,
212
+ reason: "root",
213
+ message: "",
214
+ line: 1,
215
+ column: 1
216
+ };
217
+ return {
218
+ ok: true,
219
+ value: parsed
220
+ };
221
+ }
222
+ /** 两空格缩进格式化(解析失败时原样返回输入与失败信息)。 */
223
+ function formatConfigJson(text) {
224
+ const parsed = parseConfigJson(text);
225
+ if (!parsed.ok) return {
226
+ ok: false,
227
+ result: parsed
228
+ };
229
+ return {
230
+ ok: true,
231
+ text: `${JSON.stringify(parsed.value, null, 2)}\n`
232
+ };
233
+ }
234
+ /** 差分:对象删键 → unset;数组删元素 → 下标降序 unset(保持其余下标有效)。 */
235
+ function diffToOps(before, after) {
236
+ const ops = [];
237
+ walk(before, after, [], ops);
238
+ return ops;
239
+ }
240
+ function walk(before, after, path, ops) {
241
+ if (Array.isArray(after)) {
242
+ walkArray(before, after, path, ops);
243
+ return;
244
+ }
245
+ if (isPlainObject(after)) {
246
+ walkObject(before, after, path, ops);
247
+ return;
248
+ }
249
+ if (!Object.is(before, after)) ops.push({
250
+ op: "set",
251
+ path: [...path],
252
+ value: after
253
+ });
254
+ }
255
+ function walkObject(before, after, path, ops) {
256
+ if (!isPlainObject(before)) {
257
+ ops.push({
258
+ op: "set",
259
+ path: [...path],
260
+ value: after
261
+ });
262
+ return;
263
+ }
264
+ for (const [key, value] of Object.entries(after)) {
265
+ if (!Object.hasOwn(before, key)) {
266
+ ops.push({
267
+ op: "set",
268
+ path: [...path, key],
269
+ value
270
+ });
271
+ continue;
272
+ }
273
+ walk(before[key], value, [...path, key], ops);
274
+ }
275
+ for (const key of Object.keys(before)) if (!Object.hasOwn(after, key)) ops.push({
276
+ op: "unset",
277
+ path: [...path, key]
278
+ });
279
+ }
280
+ function walkArray(before, after, path, ops) {
281
+ if (!Array.isArray(before)) {
282
+ ops.push({
283
+ op: "set",
284
+ path: [...path],
285
+ value: after
286
+ });
287
+ return;
288
+ }
289
+ const shared = Math.min(before.length, after.length);
290
+ for (let index = 0; index < shared; index += 1) walk(before[index], after[index], [...path, String(index)], ops);
291
+ for (let index = before.length - 1; index >= after.length; index -= 1) ops.push({
292
+ op: "unset",
293
+ path: [...path, String(index)]
294
+ });
295
+ for (let index = before.length; index < after.length; index += 1) ops.push({
296
+ op: "set",
297
+ path: [...path, String(index)],
298
+ value: after[index]
299
+ });
300
+ }
301
+ /** schema JSON 里的密钥字段路径(`meta.role === 'secret'`):源码编辑器不呈现它们。 */
302
+ function secretPathsOf(schemaJson) {
303
+ const refs = refsOf(schemaJson);
304
+ if (refs === null) return [];
305
+ const root = schemaJson.uid;
306
+ if (typeof root !== "number") return [];
307
+ const out = [];
308
+ collectSecretPaths(refs, root, [], out, /* @__PURE__ */ new Set());
309
+ return out;
310
+ }
311
+ /**
312
+ * 文档里 schema 未声明的键路径。
313
+ *
314
+ * schemastery 对未声明键**透传忽略**(不报错、不剥离),所以这类键会被原样写进
315
+ * 用户层并永久留存——典型来源是历史配置键与手写拼写错误。源码编辑器把它作为
316
+ * 非阻断警告列出来(迁移期新旧键并存时不至于挡住应用)。
317
+ */
318
+ function unknownKeysOf(schemaJson, value) {
319
+ const refs = refsOf(schemaJson);
320
+ if (refs === null || !isPlainObject(value)) return [];
321
+ const root = schemaJson.uid;
322
+ if (typeof root !== "number") return [];
323
+ return [...unknownKeysAt(refs, root, value)].sort();
324
+ }
325
+ /** 返回「该节点下所有未被 schema 声明的键路径」的集合。 */
326
+ function unknownKeysAt(refs, index, value) {
327
+ const node = refs[String(index)];
328
+ if (node === void 0) return /* @__PURE__ */ new Set();
329
+ if (node.list !== void 0) return intersectBranches(refs, node.list, value);
330
+ if (node.inner !== void 0) {
331
+ if (Array.isArray(value)) {
332
+ const out = /* @__PURE__ */ new Set();
333
+ for (const [at, item] of value.entries()) for (const path of unknownKeysAt(refs, node.inner, item)) out.add(`${at}.${path}`);
334
+ return out;
335
+ }
336
+ return unknownKeysAt(refs, node.inner, value);
337
+ }
338
+ if (node.dict === void 0 || !isPlainObject(value)) return /* @__PURE__ */ new Set();
339
+ const out = /* @__PURE__ */ new Set();
340
+ for (const [key, child] of Object.entries(value)) {
341
+ const next = node.dict[key];
342
+ if (next === void 0) {
343
+ out.add(key);
344
+ continue;
345
+ }
346
+ for (const path of unknownKeysAt(refs, next, child)) out.add(`${key}.${path}`);
347
+ }
348
+ return out;
349
+ }
350
+ /** 联合类型:只在「对象型分支」之间取交集(标量分支不否决键判定)。 */
351
+ function intersectBranches(refs, list, value) {
352
+ const objectBranches = list.filter((branch) => refs[String(branch)]?.dict !== void 0);
353
+ if (objectBranches.length === 0) return /* @__PURE__ */ new Set();
354
+ let result = null;
355
+ for (const branch of objectBranches) {
356
+ const keys = unknownKeysAt(refs, branch, value);
357
+ if (result === null) {
358
+ result = keys;
359
+ continue;
360
+ }
361
+ for (const key of [...result]) if (!keys.has(key)) result.delete(key);
362
+ }
363
+ return result ?? /* @__PURE__ */ new Set();
364
+ }
365
+ function refsOf(schemaJson) {
366
+ if (!isPlainObject(schemaJson)) return null;
367
+ const refs = schemaJson.refs;
368
+ return isPlainObject(refs) ? refs : null;
369
+ }
370
+ function collectSecretPaths(refs, index, path, out, seen) {
371
+ const node = refs[String(index)];
372
+ if (node === void 0) return;
373
+ const marker = `${index}:${path.join(".")}`;
374
+ if (seen.has(marker)) return;
375
+ seen.add(marker);
376
+ if (node.meta?.role === "secret") {
377
+ out.push([...path]);
378
+ return;
379
+ }
380
+ for (const [key, child] of Object.entries(node.dict ?? {})) collectSecretPaths(refs, child, [...path, key], out, seen);
381
+ if (typeof node.inner === "number") collectSecretPaths(refs, node.inner, path, out, seen);
382
+ for (const child of node.list ?? []) collectSecretPaths(refs, child, path, out, seen);
383
+ }
384
+ //#endregion
385
+ //#region ../shared/src/client/code-validate.ts
386
+ /**
387
+ * 配置源码编辑的模式校验:用宿主 `describe` 回传的 schema JSON 在浏览器本地
388
+ * 重建同一套 schemastery 校验(库 23KB 纯 JS,随 client bundle 打苞——浏览器端
389
+ * 没有宿主实例,不存在跨实例符号身份问题,见 docs/reference/官方机制参照.md
390
+ * 「客户端平台」)。
391
+ *
392
+ * 校验与宿主写入路径同源:`new Schema(json)` 后按同一份 volatile 投影调用,
393
+ * 因此本地拦下的错误与宿主 `settings/rejected` 的判据一致。
394
+ * @module @dsh-plus/shared/client/code-validate
395
+ */
396
+ /** 重建结果按 schema JSON 对象身份缓存(describe 每次应答一个新对象,无泄漏风险)。 */
397
+ const cache = /* @__PURE__ */ new WeakMap();
398
+ function rebuild(schemaJson) {
399
+ if (!isPlainObject(schemaJson)) return null;
400
+ const cached = cache.get(schemaJson);
401
+ if (cached !== void 0) return cached;
402
+ let built = null;
403
+ try {
404
+ built = new _deepseek_ai_schemastery.default(schemaJson);
405
+ } catch {
406
+ built = null;
407
+ }
408
+ cache.set(schemaJson, built);
409
+ return built;
410
+ }
411
+ /** 从 schemastery 错误消息里取路径前缀:`$.a.b expected number but got x` → `a.b`。 */
412
+ function pathOf(message) {
413
+ const located = /^\$\.([^\s]+)/.exec(message);
414
+ return located === null ? "" : located[1] ?? "";
415
+ }
416
+ /**
417
+ * 按宿主 schema 校验一份配置文档。
418
+ * @param schemaJson - `describe` 应答里的 `schema`(schemastery `toJSON()` 形态)。
419
+ * @param value - 编辑器解析出的对象。
420
+ * @returns 通过(含「未校验」标记)或问题清单。
421
+ */
422
+ function validateAgainstSchema(schemaJson, value) {
423
+ const validate = rebuild(schemaJson);
424
+ if (validate === null) return {
425
+ ok: true,
426
+ validated: false
427
+ };
428
+ try {
429
+ validate(value);
430
+ return {
431
+ ok: true,
432
+ validated: true
433
+ };
434
+ } catch (error) {
435
+ const message = error instanceof Error ? error.message : String(error);
436
+ return {
437
+ ok: false,
438
+ validated: true,
439
+ issues: [{
440
+ path: pathOf(message),
441
+ message
442
+ }]
443
+ };
444
+ }
445
+ }
446
+ //#endregion
447
+ //#region ../shared/src/client/styles.ts
448
+ /**
449
+ * 配置分节样式工厂(各插件 client 的公共收编版)。
450
+ *
451
+ * 目标宿主 dsh 0.2.1-alpha.2:插件页把配置视图放进已有页面级内边距的容器里
452
+ * (`div.detailSections[data-plugin-config]` 或 `section.detailSection[data-plugin-config]`),
453
+ * 外层无边框——故这里输出的是**无边框分节**(小节标题 13px/600、字段 12px 0、
454
+ * 横向零内边距、页脚非 sticky),度量对齐官方设置页
455
+ * (`@deepseek-ai/dsh-client-ui-primitives` 的 settings-form)。
456
+ *
457
+ * 移动端与可达性(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
458
+ * - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
459
+ * - 页脚按钮等宽换行、状态文字独占一行。
460
+ * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
461
+ * @module @dsh-plus/shared/client/styles
462
+ */
463
+ /** 生成全套分节 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
464
+ function cardCss(prefix, extra = "") {
465
+ return `
466
+ .${prefix}-section{box-sizing:border-box;flex-direction:column;width:100%;min-width:0;padding:16px 0;display:flex}
467
+ .${prefix}-sectionHead{align-items:center;gap:8px;min-width:0;display:flex}
468
+ .${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}
469
+ .${prefix}-sectionBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
470
+ .${prefix}-sectionDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
471
+ .${prefix}-sectionBody{flex-direction:column;min-width:0;display:flex}
472
+ .${prefix}-sectionFooter{align-items:center;gap:8px;padding-top:16px;display:flex;flex-wrap:wrap}
473
+ .${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}
474
+ .${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
475
+ .${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
476
+ .${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
477
+ .${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
478
+ .${prefix}-head{align-items:center;gap:8px;display:flex}
479
+ .${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
480
+ .${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
481
+ .${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
482
+ .${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
483
+ .${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}
484
+ .${prefix}-input:hover:not(:disabled):not(:focus-visible){border-color:var(--dsw-alias-label-dimmed)}
485
+ .${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
486
+ .${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
487
+ .${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
488
+ .${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%}
489
+ .${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}
490
+ .${prefix}-select:hover:not(:disabled){background-color:var(--dsw-alias-interactive-bg-hover)}
491
+ .${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
492
+ .${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
493
+ .${prefix}-checkRow{align-items:center;gap:10px;display:flex;padding:6px 0}
494
+ .${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer;flex:1;min-width:0}
495
+ /* 自绘圆角扁平开关(官方 UI 无可见原生 checkbox,选择类全走胶囊/菜单) */
496
+ .${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}
497
+ .${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)}
498
+ .${prefix}-checkRow input:checked{background:var(--dsw-alias-brand-primary)}
499
+ .${prefix}-checkRow input:checked::after{left:16px;background:var(--dsw-alias-bg-base)}
500
+ .${prefix}-checkRow input:disabled{opacity:.4;cursor:default}
501
+ .${prefix}-checkRow input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
502
+ .${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
503
+ /* 分节(Section):卡片内的二级分组,与一级分节同度量、无边框 */
504
+ .${prefix}-sub{flex-direction:column;padding:12px 0 0;display:flex}
505
+ .${prefix}-subHead{align-items:center;gap:8px;min-width:0;display:flex}
506
+ .${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}
507
+ .${prefix}-subDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
508
+ .${prefix}-subBody{flex-direction:column;min-width:0;display:flex}
509
+ .${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}
510
+ .${prefix}-subToggle:hover{color:var(--dsw-alias-label-primary)}
511
+ /* 字段排布(FieldGrid):窄屏单列,宽屏可两列 */
512
+ .${prefix}-grid{display:grid;grid-template-columns:1fr;min-width:0}
513
+ @media (min-width:768px){
514
+ .${prefix}-grid2{grid-template-columns:1fr 1fr;column-gap:16px}
515
+ }
516
+ /* 只读说明块(Note) */
517
+ .${prefix}-note{background:var(--dsw-alias-bg-module-platform);border-radius:8px;margin:12px 0 0;padding:10px 12px}
518
+ .${prefix}-noteTitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px;font-weight:600;line-height:1.5}
519
+ .${prefix}-noteBody{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5;white-space:pre-wrap}
520
+ /* 列表编辑器(ListEditor):条目头 + 折叠 + 行内操作 */
521
+ .${prefix}-list{flex-direction:column;gap:8px;padding:8px 0 0;display:flex}
522
+ .${prefix}-listItem{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:8px 12px}
523
+ .${prefix}-listItemHead{align-items:center;gap:8px;min-width:0;display:flex}
524
+ .${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}
525
+ .${prefix}-listItemBody{flex-direction:column;min-width:0;display:flex;padding-top:4px}
526
+ .${prefix}-listActions{align-items:center;gap:4px;display:flex;flex-wrap:wrap}
527
+ .${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}
528
+ .${prefix}-iconBtn:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}
529
+ .${prefix}-iconBtn:disabled{opacity:.4;cursor:default}
530
+ .${prefix}-listAdd{align-self:flex-start}
531
+ .${prefix}-listAddRow{align-items:center;align-self:flex-start;gap:8px;display:flex;flex-wrap:wrap}
532
+ .${prefix}-listEmpty{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5;padding:4px 0}
533
+ .${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
534
+ .${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
535
+ .${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
536
+ .${prefix}-statusError{color:var(--dsw-alias-label-error)}
537
+ .${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}
538
+ .${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
539
+ .${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
540
+ .${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
541
+ .${prefix}-btn:disabled{opacity:.4;cursor:default}
542
+ .${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
543
+ @media (max-width:767px){
544
+ .${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
545
+ .${prefix}-checkRow{min-height:44px;padding:8px 0}
546
+ .${prefix}-status{flex-basis:100%;flex:none}
547
+ .${prefix}-btn{min-height:44px;flex:1;min-width:96px}
548
+ }
549
+ @media (pointer:coarse){
550
+ .${prefix}-btn{min-height:44px}
551
+ .${prefix}-checkRow{min-height:44px}
552
+ .${prefix}-input,.${prefix}-select{height:40px}
553
+ }
554
+ ${extra}
555
+ `;
556
+ }
557
+ /** 源码编辑节的固定类名前缀。 */
558
+ const CODE_SECTION_PREFIX = "dshc";
559
+ /**
560
+ * 源码编辑节(ConfigCodeSection)专用样式:前缀固定 `dshc`,由 shared 自行注入
561
+ * (插件卡片不必知道它的存在)。基础规则复用 cardCss,只追加 details/摘要与
562
+ * 代码文本域的度量。
563
+ */
564
+ function codeSectionCss() {
565
+ return cardCss(CODE_SECTION_PREFIX, `
566
+ .${CODE_SECTION_PREFIX}-details{padding:4px 0 0}
567
+ .${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}
568
+ .${CODE_SECTION_PREFIX}-summary::-webkit-details-marker{display:none}
569
+ .${CODE_SECTION_PREFIX}-summary::before{content:"▸";color:var(--dsw-alias-label-tertiary);display:inline-block;margin-right:6px;transition:transform .18s}
570
+ .${CODE_SECTION_PREFIX}-details[open] .${CODE_SECTION_PREFIX}-summary::before{transform:rotate(90deg)}
571
+ .${CODE_SECTION_PREFIX}-desc{color:var(--dsw-alias-label-tertiary);margin:0 0 8px;font-size:12px;line-height:1.5}
572
+ .${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%}
573
+ .${CODE_SECTION_PREFIX}-foot{align-items:center;gap:8px;display:flex;flex-wrap:wrap;padding-top:12px}
574
+ .${CODE_SECTION_PREFIX}-foot .${CODE_SECTION_PREFIX}-btn:last-child{margin-left:auto}
575
+ @media (max-width:767px){
576
+ .${CODE_SECTION_PREFIX}-input{font-size:16px}
577
+ }
578
+ `);
579
+ }
580
+ /**
581
+ * 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
582
+ * 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
583
+ */
584
+ function injectCardStyle(pluginId, css) {
585
+ if (typeof document === "undefined") return null;
586
+ const tagId = `${pluginId}/card.css`;
587
+ if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
588
+ const tag = document.createElement("style");
589
+ tag.dataset.plugin = pluginId;
590
+ tag.dataset.pluginCss = tagId;
591
+ tag.textContent = css;
592
+ document.head.appendChild(tag);
593
+ return tag;
594
+ }
595
+ //#endregion
596
+ //#region ../shared/src/client/code-section.ts
597
+ /**
598
+ * 配置源码编辑节(自动追加到每张插件配置卡片页)。
599
+ *
600
+ * 形态:无边框分节,与 ConfigShell/Section 的小节度量一致;文档=宿主 `describe` 回传的
601
+ * volatile 投影(JSON,两空格缩进),校验=本地 JSON 语法 + schemastery 模式,
602
+ * 写回=官方 `settings.mutate` 路径 ops(密钥字段不进文档,也不会被写坏)。
603
+ *
604
+ * 本文件刻意不写 JSX:`@dsh-plus/shared` 的 client 纯逻辑测试用 `node --test`
605
+ * 直跑 .ts(Node 原生类型擦除不支持 JSX),而 `config-slots.ts` 会被测试导入,
606
+ * 因此这条导入链上的模块一律用 `createElement`。React 只经默认导入取用
607
+ * (react 是 CJS,Node ESM 下具名导入不保证可解析)。
608
+ * @module @dsh-plus/shared/client/code-section
609
+ */
610
+ const { createElement: h$1, useEffect: useEffect$3, useMemo: useMemo$2, useState: useState$3, useSyncExternalStore: useSyncExternalStore$2 } = react.default;
611
+ const IDLE = {
612
+ kind: "idle",
613
+ text: ""
614
+ };
615
+ /** 文档播种文本:对象 → 两空格缩进 JSON。 */
616
+ function seedText(value) {
617
+ return value === void 0 ? "{}\n" : `${JSON.stringify(value, null, 2)}\n`;
618
+ }
619
+ /** 解析/校验失败的原因文案(逐条给出行列或字段路径)。 */
620
+ function problemLines(text, snapshot, t) {
621
+ const parsed = parseConfigJson(text);
622
+ if (!parsed.ok) {
623
+ if (parsed.reason === "empty") return {
624
+ problems: [t("codeInvalidEmpty")],
625
+ validated: false
626
+ };
627
+ if (parsed.reason === "root") return {
628
+ problems: [t("codeInvalidRoot")],
629
+ validated: false
630
+ };
631
+ const line = t("codeLine").replace("{line}", String(parsed.line ?? 0)).replace("{column}", String(parsed.column ?? 0));
632
+ return {
633
+ problems: [`${t("codeInvalidJson")}(${line})${parsed.message}`],
634
+ validated: false
635
+ };
636
+ }
637
+ const result = validateAgainstSchema(snapshot.schema, parsed.value);
638
+ if (result.ok) return {
639
+ problems: [],
640
+ validated: result.validated
641
+ };
642
+ return {
643
+ problems: result.issues.map((issue) => `${t("codeInvalidSchema")}:${issue.path === "" ? issue.message : `${issue.path} — ${issue.message}`}`),
644
+ validated: true
645
+ };
646
+ }
647
+ /** 与当前快照的差分(无改动时为空数组)。 */
648
+ function opsOf(text, snapshot) {
649
+ const parsed = parseConfigJson(text);
650
+ return parsed.ok ? diffToOps(snapshot.value, parsed.value) : [];
651
+ }
652
+ /** 应用:官方路径 ops 写回,成功后重载快照(revision 变化会重新播种文档)。 */
653
+ function applyOps(options) {
654
+ const { api, scope, ops, revision, t, setStatus, setApplying } = options;
655
+ setApplying(true);
656
+ api.mutate(ops, revision).then(() => {
657
+ setStatus({
658
+ kind: "ok",
659
+ text: t("codeApplied")
660
+ });
661
+ return scope.load();
662
+ }).catch((error) => {
663
+ const message = error instanceof Error ? error.message : String(error);
664
+ setStatus({
665
+ kind: "error",
666
+ text: `${t("codeApplyFailed")}${message}`
667
+ });
668
+ }).finally(() => setApplying(false));
669
+ }
670
+ /** 草稿动作:应用(官方路径 ops 写回)、格式化、编辑与 Tab 缩进。 */
671
+ function draftHandlers(options) {
672
+ const { api, scope, t, snapshot, text, ops, setText, setStatus, setApplying } = options;
673
+ return {
674
+ onApply: () => {
675
+ applyOps({
676
+ api,
677
+ scope,
678
+ ops,
679
+ revision: snapshot.revision,
680
+ t,
681
+ setStatus,
682
+ setApplying
683
+ });
684
+ },
685
+ onFormat: () => {
686
+ const formatted = formatConfigJson(text);
687
+ if (formatted.ok) setText(formatted.text);
688
+ },
689
+ onChange: (event) => {
690
+ setText(event.target.value);
691
+ setStatus(IDLE);
692
+ },
693
+ onKeyDown: (event) => {
694
+ if (event.key !== "Tab") return;
695
+ event.preventDefault();
696
+ const target = event.currentTarget;
697
+ const { selectionStart, selectionEnd, value } = target;
698
+ setText(`${value.slice(0, selectionStart)} ${value.slice(selectionEnd)}`);
699
+ queueMicrotask(() => {
700
+ target.selectionStart = selectionStart + 2;
701
+ target.selectionEnd = selectionStart + 2;
702
+ });
703
+ }
704
+ };
705
+ }
706
+ /** 校验派生量:逐次编辑重算(problems 供提示与禁用判定,validated 区分「模式外」)。 */
707
+ function useCodeChecks(text, snapshot, t) {
708
+ const { problems, validated } = useMemo$2(() => problemLines(text, snapshot, t), [
709
+ text,
710
+ snapshot,
711
+ t
712
+ ]);
713
+ return {
714
+ problems,
715
+ validated,
716
+ ops: useMemo$2(() => opsOf(text, snapshot), [text, snapshot]),
717
+ secrets: useMemo$2(() => secretPathsOf(snapshot.schema), [snapshot.schema]),
718
+ unknown: useMemo$2(() => {
719
+ const parsed = parseConfigJson(text);
720
+ return parsed.ok ? unknownKeysOf(snapshot.schema, parsed.value) : [];
721
+ }, [text, snapshot.schema])
722
+ };
723
+ }
724
+ /** 分节状态:快照订阅、文档文本、校验结果与草稿动作(主组件只做组装)。 */
725
+ function useCodeSection(props) {
726
+ const { ns, t, scope, api } = props;
727
+ const snapshot = useSyncExternalStore$2((listener) => scope.subscribe(listener), () => scope.getSnapshot());
728
+ const [text, setText] = useState$3(() => seedText(snapshot.value));
729
+ const [status, setStatus] = useState$3(IDLE);
730
+ const [applying, setApplying] = useState$3(false);
731
+ const [open, setOpen] = useState$3(false);
732
+ const revision = snapshot.revision;
733
+ const snapshotStatus = snapshot.status;
734
+ useEffect$3(() => {
735
+ setText(seedText(snapshot.value));
736
+ setStatus(IDLE);
737
+ }, [revision, snapshotStatus]);
738
+ useEffect$3(() => {
739
+ injectCardStyle("@dsh-plus/shared", codeSectionCss());
740
+ }, []);
741
+ const { problems, validated, ops, secrets, unknown } = useCodeChecks(text, snapshot, t);
742
+ const ready = snapshot.status === "ready";
743
+ const disabled = !ready || !snapshot.writable || applying;
744
+ return {
745
+ ready,
746
+ ns,
747
+ t,
748
+ scope,
749
+ snapshot,
750
+ text,
751
+ setText,
752
+ status,
753
+ setStatus,
754
+ applying,
755
+ setApplying,
756
+ open,
757
+ setOpen,
758
+ problems,
759
+ validated,
760
+ ops,
761
+ secrets,
762
+ unknown,
763
+ disabled,
764
+ canApply: !disabled && problems.length === 0 && ops.length > 0,
765
+ ...draftHandlers({
766
+ api,
767
+ scope,
768
+ t,
769
+ snapshot,
770
+ text,
771
+ ops,
772
+ setText,
773
+ setStatus,
774
+ setApplying
775
+ })
776
+ };
777
+ }
778
+ /** 提示行:无改动 / 未校验 / 密钥计数 / 模式外键 / 不可用或只读。 */
779
+ function noteLines(state) {
780
+ const { t, ready, problems, validated, ops, secrets, unknown, snapshot } = state;
781
+ const notes = [];
782
+ if (problems.length === 0 && ops.length === 0 && ready) notes.push(h$1("p", {
783
+ className: "dshc-hint",
784
+ key: "no-change"
785
+ }, t("codeNoChanges")));
786
+ if (problems.length === 0 && !validated) notes.push(h$1("p", {
787
+ className: "dshc-hint",
788
+ key: "unvalidated"
789
+ }, t("codeUnvalidated")));
790
+ if (secrets.length > 0) notes.push(h$1("p", {
791
+ className: "dshc-hint",
792
+ key: "secrets"
793
+ }, t("codeSecretsNote").replace("{n}", String(secrets.length))));
794
+ if (unknown.length > 0) notes.push(h$1("p", {
795
+ className: "dshc-hint",
796
+ key: "unknown"
797
+ }, t("codeUnknownKeys").replace("{n}", String(unknown.length)).replace("{keys}", unknown.slice(0, 8).join("、"))));
798
+ if (snapshot.status === "unavailable") notes.push(h$1("p", {
799
+ className: "dshc-hint",
800
+ key: "unavailable"
801
+ }, t("codeUnavailable")));
802
+ else if (!snapshot.writable) notes.push(h$1("p", {
803
+ className: "dshc-hint",
804
+ key: "readonly"
805
+ }, t("codeReadOnly")));
806
+ return notes;
807
+ }
808
+ /** 页脚:状态行 + 格式化 / 应用按钮。 */
809
+ function codeFooter(state) {
810
+ const { t, status, disabled, canApply, applying, onFormat, onApply } = state;
811
+ return h$1("div", { className: "dshc-foot" }, status.kind === "idle" ? null : h$1("p", {
812
+ className: `dshc-status${status.kind === "error" ? " dshc-statusError" : ""}`,
813
+ role: "status"
814
+ }, status.text), h$1("button", {
815
+ type: "button",
816
+ className: "dshc-btn dshc-btnGhost",
817
+ disabled,
818
+ onClick: onFormat
819
+ }, t("codeFormat")), h$1("button", {
820
+ type: "button",
821
+ className: "dshc-btn dshc-btnPrimary",
822
+ disabled: !canApply,
823
+ onClick: onApply
824
+ }, applying ? t("codeApplying") : t("codeApply")));
825
+ }
826
+ function ConfigCodeSection(props) {
827
+ const state = useCodeSection(props);
828
+ const { ns, t, text, disabled, open, setOpen, status, problems, onChange, onKeyDown } = state;
829
+ return h$1("section", {
830
+ className: "dshc-section",
831
+ "aria-label": `${ns} ${t("codeSectionTitle")}`
832
+ }, h$1("details", {
833
+ className: "dshc-details",
834
+ open: open || status.kind === "error",
835
+ onToggle: (event) => {
836
+ setOpen(event.currentTarget.open);
837
+ }
838
+ }, h$1("summary", { className: "dshc-summary" }, t("codeSectionTitle")), h$1("p", { className: "dshc-desc" }, t("codeSectionDesc")), h$1("textarea", {
839
+ className: `dshc-input${problems.length > 0 ? " dshc-inputInvalid" : ""}`,
840
+ rows: 16,
841
+ spellCheck: false,
842
+ "aria-invalid": problems.length > 0 ? true : void 0,
843
+ value: text,
844
+ disabled,
845
+ onChange,
846
+ onKeyDown
847
+ }), problems.map((problem) => h$1("p", {
848
+ className: "dshc-invalid",
849
+ role: "alert",
850
+ key: problem
851
+ }, problem)), ...noteLines(state), codeFooter(state)));
852
+ }
853
+ //#endregion
119
854
  //#region ../shared/src/client/config-slots.ts
855
+ /**
856
+ * 配置卡片的槽位注册助手(目标宿主:dsh 0.2.1-alpha.2)。
857
+ *
858
+ * 官方插件页(`dsh-client-ui-plugin-manager`)为第三方配置视图声明两个 keyed 槽位:
859
+ * - `plugins.row.config`(key = `<bundle 包名>#<row id>`):bundle 详情页对应行出现
860
+ * 「配置」入口,行配置页渲染 `view: 'summary'`(一行简介)与 `view: 'page'`
861
+ * (带保存控件的表单);
862
+ * - `plugins.bundle.config`(key = 包名):包详情页本体配置,仅渲染 `view: 'page'`。
863
+ *
864
+ * 页面自己画标题、图标、面包屑与页面级内边距(`detailSections` 内无边框容器),
865
+ * 故 page 视图输出无边框分节(见 card.tsx),summary 视图只返回一行文本。
866
+ * 旧 `settings.plugin.item` 槽位已随官方插件页迁移删除,不再注册。
867
+ *
868
+ * **源码编辑节自动追加**:注册时把插件组件包一层,page 视图在原卡片之后追加
869
+ * `ConfigCodeSection`(复用同一份 scope/api),summary 视图原样透传。因此「只要
870
+ * 插件存在可配置项」就有源码编辑入口,插件侧零接线;命名空间没有 volatile 字段时
871
+ * 它本身不出现在 describe 视图里,该节自然显示为不可用。
872
+ *
873
+ * @module @dsh-plus/shared/client/config-slots
874
+ */
875
+ const { createElement: h, Fragment } = react.default;
120
876
  /** dsh-plus 聚合 bundle 的包名(各插件 row 均经其补丁层插入 profile)。 */
121
877
  const DSH_PLUS_BUNDLE = "@dsh-plus/bundle-main";
878
+ /** page 视图:插件卡片 + 自动追加的源码编辑节(summary 视图原样透传)。 */
879
+ function withCodeSection(component, ns) {
880
+ return function AutoConfigView(props) {
881
+ const card = h(component, props);
882
+ if (props.view !== "page") return card;
883
+ return h(Fragment, null, card, h(ConfigCodeSection, {
884
+ ns,
885
+ t: props.t,
886
+ scope: props.scope,
887
+ api: props.api
888
+ }));
889
+ };
890
+ }
122
891
  /**
123
892
  * 把一张配置卡片注册进插件页的两个配置槽位。
124
893
  * 两个槽位都由 0.2.1-alpha.2 的插件页声明,任一缺席即报错——不做版本探测。
125
894
  */
126
895
  function injectPluginConfigCard(slots, reg) {
896
+ const component = withCodeSection(reg.component, reg.ns);
127
897
  const base = {
128
898
  locale: reg.ns,
129
899
  inject: reg.inject
@@ -132,14 +902,26 @@ window.__ModuleLoader__.load({
132
902
  name: "plugins.row.config",
133
903
  key: `${DSH_PLUS_BUNDLE}#${reg.rowId}`,
134
904
  ...base
135
- }, reg.component));
905
+ }, component));
136
906
  slots.inject("plugins.bundle.config", () => slots.register({
137
907
  name: "plugins.bundle.config",
138
908
  key: reg.pkg,
139
909
  ...base
140
- }, reg.component));
910
+ }, component));
141
911
  }
142
912
  //#endregion
913
+ //#region ../shared/src/client/credentials.tsx
914
+ /**
915
+ * 凭据面(共享件):官方 settings-controller 的 `remote.credentials` 命名空间
916
+ * (describe/set/unset/onChange),复用官方 credentials seam,不另开 HTTP 端点。
917
+ * **值只写不读**——describe 只回「已配置 / 来源 / 可写」,没有任何方法回传值。
918
+ *
919
+ * 凭据与 settings 草稿相互独立:不进命名空间、不参与脏判定,保存即落
920
+ * `$DSH_HOME/.credentials.yaml` 并热生效(宿主每次工具调用重新 resolve),
921
+ * 因此改口令不需要保存卡片、也不需要 /reload 或重启。
922
+ * @module @dsh-plus/shared/client/credentials
923
+ */
924
+ //#endregion
143
925
  //#region ../shared/src/client/draft.ts
144
926
  /**
145
927
  * 单命名空间 staged 草稿(简单配置卡片共用):读 scope 快照、播种草稿、
@@ -168,7 +950,31 @@ window.__ModuleLoader__.load({
168
950
  enabledOff: "未启用",
169
951
  saveFailed: "保存失败,请检查填写内容。",
170
952
  confirm: "确认",
171
- cancel: "取消"
953
+ cancel: "取消",
954
+ listAdd: "新增",
955
+ listRemove: "删除",
956
+ listMoveUp: "上移",
957
+ listMoveDown: "下移",
958
+ listDuplicate: "复制",
959
+ listEmpty: "暂无条目。",
960
+ codeSectionTitle: "源码编辑(JSON)",
961
+ codeSectionDesc: "直接编辑本插件的可配置字段(仅 .volatile() 字段)。「应用」按官方路径编辑写回用户层,密钥字段不在此编辑器内。",
962
+ codeFormat: "格式化",
963
+ codeApply: "应用",
964
+ codeApplying: "应用中…",
965
+ codeApplied: "已应用。",
966
+ codeNoChanges: "与当前配置一致,无需应用。",
967
+ codeInvalidJson: "JSON 语法错误",
968
+ codeInvalidEmpty: "配置不能为空。",
969
+ codeInvalidRoot: "根节点必须是对象。",
970
+ codeInvalidSchema: "模式校验未通过",
971
+ codeUnvalidated: "宿主未回传 schema,已跳过本地校验(写入仍由宿主把关)。",
972
+ codeSecretsNote: "有 {n} 个密钥字段不在此编辑器内(在凭据区或行级配置中管理)。",
973
+ codeUnknownKeys: "有 {n} 个键不在 schema 里({keys}):会被原样保留并被运行时忽略,建议删除。",
974
+ codeUnavailable: "该行未激活或命名空间不可用,源码编辑不可用。",
975
+ codeReadOnly: "当前部署无 settings provider,源码编辑只读。",
976
+ codeApplyFailed: "应用失败:",
977
+ codeLine: "第 {line} 行第 {column} 列"
172
978
  };
173
979
  const commonEn = {
174
980
  save: "Save",
@@ -185,7 +991,31 @@ window.__ModuleLoader__.load({
185
991
  enabledOff: "Off",
186
992
  saveFailed: "Save failed; check the fields.",
187
993
  confirm: "Confirm",
188
- cancel: "Cancel"
994
+ cancel: "Cancel",
995
+ listAdd: "Add",
996
+ listRemove: "Remove",
997
+ listMoveUp: "Move up",
998
+ listMoveDown: "Move down",
999
+ listDuplicate: "Duplicate",
1000
+ listEmpty: "No entries yet.",
1001
+ codeSectionTitle: "Source editor (JSON)",
1002
+ codeSectionDesc: "Edit this plugin’s configurable fields directly (only .volatile() fields). Apply writes back through the official path edits; secret fields never appear here.",
1003
+ codeFormat: "Format",
1004
+ codeApply: "Apply",
1005
+ codeApplying: "Applying…",
1006
+ codeApplied: "Applied.",
1007
+ codeNoChanges: "Identical to the current config; nothing to apply.",
1008
+ codeInvalidJson: "JSON syntax error",
1009
+ codeInvalidEmpty: "Config must not be empty.",
1010
+ codeInvalidRoot: "The root node must be an object.",
1011
+ codeInvalidSchema: "Schema validation failed",
1012
+ codeUnvalidated: "The host returned no schema, so local validation was skipped (writes are still validated by the host).",
1013
+ codeSecretsNote: "{n} secret field(s) are not editable here (manage them in the credentials section or at the row level).",
1014
+ codeUnknownKeys: "{n} key(s) are absent from the schema ({keys}): they are preserved verbatim and ignored at runtime; remove them.",
1015
+ codeUnavailable: "This row is inactive or its namespace is unavailable; the source editor is disabled.",
1016
+ codeReadOnly: "No settings provider in this deployment; the source editor is read-only.",
1017
+ codeApplyFailed: "Apply failed: ",
1018
+ codeLine: "line {line}, column {column}"
189
1019
  };
190
1020
  /**
191
1021
  * own 覆盖同键合并(返回新对象,入参不可变)。
@@ -212,6 +1042,8 @@ window.__ModuleLoader__.load({
212
1042
  let state = {
213
1043
  status: "loading",
214
1044
  value: void 0,
1045
+ schema: void 0,
1046
+ secrets: [],
215
1047
  revision: void 0,
216
1048
  writable: false
217
1049
  };
@@ -237,6 +1069,8 @@ window.__ModuleLoader__.load({
237
1069
  publish({
238
1070
  status: "unavailable",
239
1071
  value: void 0,
1072
+ schema: void 0,
1073
+ secrets: [],
240
1074
  revision: void 0,
241
1075
  writable: view.writable
242
1076
  });
@@ -245,6 +1079,8 @@ window.__ModuleLoader__.load({
245
1079
  publish({
246
1080
  status: "ready",
247
1081
  value: namespace.value,
1082
+ schema: namespace.schema,
1083
+ secrets: namespace.secrets,
248
1084
  revision: namespace.revision,
249
1085
  writable: view.writable
250
1086
  });
@@ -278,6 +1114,10 @@ window.__ModuleLoader__.load({
278
1114
  const response = await remote.update(ns, patch, expectedRevision);
279
1115
  if (!response.ok) throw new Error(response.error.message ?? "settings update failed");
280
1116
  },
1117
+ mutate: async (ops, expectedRevision) => {
1118
+ const response = await remote.mutate(ns, ops, expectedRevision);
1119
+ if (!response.ok) throw new Error(response.error.message ?? "settings mutate failed");
1120
+ },
281
1121
  describe: async () => {
282
1122
  const response = await remote.describe();
283
1123
  if (!response.ok) throw new Error(response.error.message ?? "settings describe failed");
@@ -286,101 +1126,6 @@ window.__ModuleLoader__.load({
286
1126
  };
287
1127
  }
288
1128
  //#endregion
289
- //#region ../shared/src/client/styles.ts
290
- /**
291
- * 配置分节样式工厂(各插件 client 的公共收编版)。
292
- *
293
- * 目标宿主 dsh 0.2.1-alpha.2:插件页把配置视图放进已有页面级内边距的容器里
294
- * (`div.detailSections[data-plugin-config]` 或 `section.detailSection[data-plugin-config]`),
295
- * 外层无边框——故这里输出的是**无边框分节**(小节标题 13px/600、字段 12px 0、
296
- * 横向零内边距、页脚非 sticky),度量对齐官方设置页
297
- * (`@deepseek-ai/dsh-client-ui-primitives` 的 settings-form)。
298
- *
299
- * 移动端与可达性(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
300
- * - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
301
- * - 页脚按钮等宽换行、状态文字独占一行。
302
- * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
303
- * @module @dsh-plus/shared/client/styles
304
- */
305
- /** 生成全套分节 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
306
- function cardCss(prefix, extra = "") {
307
- return `
308
- .${prefix}-section{box-sizing:border-box;flex-direction:column;width:100%;min-width:0;padding:16px 0;display:flex}
309
- .${prefix}-sectionHead{align-items:center;gap:8px;min-width:0;display:flex}
310
- .${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}
311
- .${prefix}-sectionBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
312
- .${prefix}-sectionDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
313
- .${prefix}-sectionBody{flex-direction:column;min-width:0;display:flex}
314
- .${prefix}-sectionFooter{align-items:center;gap:8px;padding-top:16px;display:flex;flex-wrap:wrap}
315
- .${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}
316
- .${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
317
- .${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
318
- .${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
319
- .${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
320
- .${prefix}-head{align-items:center;gap:8px;display:flex}
321
- .${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
322
- .${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
323
- .${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
324
- .${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
325
- .${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}
326
- .${prefix}-input:hover:not(:disabled):not(:focus-visible){border-color:var(--dsw-alias-label-dimmed)}
327
- .${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
328
- .${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
329
- .${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
330
- .${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}
331
- .${prefix}-select:hover:not(:disabled){background-color:var(--dsw-alias-interactive-bg-hover)}
332
- .${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
333
- .${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
334
- .${prefix}-checkRow{align-items:center;gap:10px;display:flex;padding:6px 0}
335
- .${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer;flex:1;min-width:0}
336
- /* 自绘圆角扁平开关(官方 UI 无可见原生 checkbox,选择类全走胶囊/菜单) */
337
- .${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}
338
- .${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)}
339
- .${prefix}-checkRow input:checked{background:var(--dsw-alias-brand-primary)}
340
- .${prefix}-checkRow input:checked::after{left:16px;background:var(--dsw-alias-bg-base)}
341
- .${prefix}-checkRow input:disabled{opacity:.4;cursor:default}
342
- .${prefix}-checkRow input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
343
- .${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
344
- .${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
345
- .${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
346
- .${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
347
- .${prefix}-statusError{color:var(--dsw-alias-label-error)}
348
- .${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}
349
- .${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
350
- .${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
351
- .${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
352
- .${prefix}-btn:disabled{opacity:.4;cursor:default}
353
- .${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
354
- @media (max-width:767px){
355
- .${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
356
- .${prefix}-checkRow{min-height:44px;padding:8px 0}
357
- .${prefix}-status{flex-basis:100%;flex:none}
358
- .${prefix}-btn{min-height:44px;flex:1;min-width:96px}
359
- }
360
- @media (pointer:coarse){
361
- .${prefix}-btn{min-height:44px}
362
- .${prefix}-checkRow{min-height:44px}
363
- .${prefix}-input,.${prefix}-select{height:40px}
364
- }
365
- ${extra}
366
- `;
367
- }
368
- /**
369
- * 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
370
- * 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
371
- */
372
- function injectCardStyle(pluginId, css) {
373
- if (typeof document === "undefined") return null;
374
- const tagId = `${pluginId}/card.css`;
375
- if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
376
- const tag = document.createElement("style");
377
- tag.dataset.plugin = pluginId;
378
- tag.dataset.pluginCss = tagId;
379
- tag.textContent = css;
380
- document.head.appendChild(tag);
381
- return tag;
382
- }
383
- //#endregion
384
1129
  //#region src/ns.ts
385
1130
  /**
386
1131
  * settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
@@ -397,7 +1142,7 @@ ${extra}
397
1142
  /**
398
1143
  * 「访问控制」配置卡片:经 injectPluginConfigCard 注册(插件页 plugins.row.config /
399
1144
  * plugins.bundle.config,view 分发 summary/page)。
400
- * 外壳与基础控件走 @dsh-plus/shared/client 套件(CardChrome/TextField/CheckRow),
1145
+ * 外壳与基础控件走 @dsh-plus/shared/client 套件(ConfigShell/TextField/CheckRow),
401
1146
  * 本文件保留业务字段(白名单 textarea/诊断面板)与保存逻辑。
402
1147
  * 配置读写经共享层 ctx.remote.settings 直连(settingsScope 已由
403
1148
  * configForms 取代):value 为 schema 解析后的视图,保存经 settings.update 深合并。
@@ -410,7 +1155,6 @@ ${extra}
410
1155
  */
411
1156
  function draftFromValue(value) {
412
1157
  return {
413
- enabled: value.enabled,
414
1158
  allowedIpsText: value.allowedIps.join("\n"),
415
1159
  trustForwardedFor: value.trustForwardedFor,
416
1160
  autoLoginTrustedIps: value.autoLoginTrustedIps
@@ -418,7 +1162,6 @@ ${extra}
418
1162
  }
419
1163
  function toPatch(draft) {
420
1164
  return {
421
- enabled: draft.enabled,
422
1165
  allowedIps: draft.allowedIpsText.split("\n").map((s) => s.trim()).filter((s) => s.length > 0),
423
1166
  trustForwardedFor: draft.trustForwardedFor,
424
1167
  autoLoginTrustedIps: draft.autoLoginTrustedIps
@@ -436,7 +1179,6 @@ ${extra}
436
1179
  return key === void 0 ? reason : t(key);
437
1180
  }
438
1181
  function verdictLabel(t, diag) {
439
- if (!diag.enabled) return t("diagOff");
440
1182
  if (diag.verdict === "pass") return t("diagPass");
441
1183
  if (diag.verdict === "token-page") return t("diagTokenPage");
442
1184
  if (diag.verdict === "autologin") return t("diagAutoLogin");
@@ -572,14 +1314,10 @@ ${extra}
572
1314
  }).finally(() => setSaving(false));
573
1315
  };
574
1316
  const disabled = !snapshot.writable;
575
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CardChrome, {
1317
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ConfigShell, {
576
1318
  prefix: "dag",
577
1319
  title: t("title"),
578
1320
  description: t("description"),
579
- statusBadge: {
580
- text: t(draft.enabled ? "enabledOn" : "enabledOff"),
581
- on: draft.enabled
582
- },
583
1321
  dirty,
584
1322
  dirtyLabel: t("unsaved"),
585
1323
  readOnlyNotice: disabled ? t("readOnly") : void 0,
@@ -604,14 +1342,6 @@ ${extra}
604
1342
  className: "dag-hint",
605
1343
  children: t("mergedHint")
606
1344
  }),
607
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
608
- prefix: "dag",
609
- id: "dag-enabled",
610
- label: t("enabledHint"),
611
- checked: draft.enabled,
612
- disabled,
613
- onEdit: (v) => edit("enabled", v)
614
- }),
615
1345
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
616
1346
  className: "dag-field",
617
1347
  children: [
@@ -672,8 +1402,6 @@ ${extra}
672
1402
  title: "访问控制",
673
1403
  description: "Web 访问围栏:与官方登录合并——官方 cookie 为唯一凭据;未认证导航显示启动令牌输入页(PWA 内可用);可选 IP 附加围栏。",
674
1404
  summaryLine: "Web 访问围栏:官方登录合并、启动令牌页与可选 IP 白名单。",
675
- enabled: "启用访问围栏",
676
- enabledHint: "关闭即完全旁路(等价插件缺席);启用后未认证流量被拦截到令牌输入页或拒绝。",
677
1405
  mergedHint: "登录凭据由官方认证持有(启动令牌换 30 天 cookie)。获取当前令牌:服务器执行 dshctl url,或本机访问 /dsh-plus/gate/launch-url。",
678
1406
  allowedIps: "附加 IP 围栏白名单",
679
1407
  allowedIpsHint: "每行一个:精确 IP 或 CIDR(IPv4/IPv6 皆可)。非空时仅白名单来源可通行与登录;留空 = 不限制来源 IP(仅官方登录保护)。",
@@ -697,15 +1425,12 @@ ${extra}
697
1425
  diagAutoLoginVerdict: "自动登录(免 token 进入)",
698
1426
  diagAutoLoginReady: "已就绪(签名密钥可读)",
699
1427
  diagAutoLoginNoSecret: "不可用(签名密钥读取失败,已降级)",
700
- diagOff: "围栏未启用",
701
1428
  diagInvalid: "白名单存在无法解析的条目:"
702
1429
  };
703
1430
  const ownEn = {
704
1431
  title: "Access Control",
705
1432
  description: "Web access gate merged with official auth: the official cookie is the sole credential; unauthenticated navigations get a launch-token page (works inside the PWA); optional IP fence.",
706
1433
  summaryLine: "Web access gate: merged official auth, launch-token page, optional IP allowlist.",
707
- enabled: "Enable access gate",
708
- enabledHint: "Off means full bypass (as if absent); on, unauthenticated traffic hits the token page or is refused.",
709
1434
  mergedHint: "Credentials are owned by official auth (launch token exchange, 30-day cookie). Get the current token: run dshctl url on the server, or visit /dsh-plus/gate/launch-url locally.",
710
1435
  allowedIps: "Additional IP fence allowlist",
711
1436
  allowedIpsHint: "One per line: exact IP or CIDR (IPv4/IPv6). When non-empty only listed sources may pass or log in; empty = no IP restriction (official login only).",
@@ -729,7 +1454,6 @@ ${extra}
729
1454
  diagAutoLoginVerdict: "auto login (token-free entry)",
730
1455
  diagAutoLoginReady: "ready (signing secret readable)",
731
1456
  diagAutoLoginNoSecret: "unavailable (signing secret unreadable, degraded)",
732
- diagOff: "gate disabled",
733
1457
  diagInvalid: "Allowlist entries that failed to parse:"
734
1458
  };
735
1459
  const zh = mergeDict(commonZh, ownZh);