@dsh-plus/access-gate 0.1.0 → 0.1.2

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,8 +4,338 @@ window.__ModuleLoader__.load({
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
- let react = require("react");
8
7
  let react_jsx_runtime = require("react/jsx-runtime");
8
+ let react = require("react");
9
+ //#region ../shared/src/client/card.tsx
10
+ const IDLE_STATUS = {
11
+ kind: "idle",
12
+ text: ""
13
+ };
14
+ function CardChrome(props) {
15
+ const p = props.prefix;
16
+ const badge = props.statusBadge;
17
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
18
+ className: `${p}-card${props.open ? ` ${p}-cardOpen` : ""}`,
19
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
20
+ type: "button",
21
+ className: `${p}-header`,
22
+ "aria-expanded": props.open,
23
+ "aria-label": props.title,
24
+ onClick: () => props.onToggle(!props.open),
25
+ children: [
26
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
27
+ className: `${p}-headText`,
28
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
29
+ className: `${p}-name`,
30
+ children: props.title
31
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
32
+ className: `${p}-description`,
33
+ children: props.description
34
+ })]
35
+ }),
36
+ badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
37
+ className: `${p}-statusBadge ${badge.on ? `${p}-statusOn` : `${p}-statusOff`}`,
38
+ children: badge.text
39
+ }) : null,
40
+ props.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
41
+ className: `${p}-pending`,
42
+ children: props.dirtyLabel
43
+ }) : null,
44
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
45
+ className: `${p}-chevron${props.open ? ` ${p}-chevronOpen` : ""}`,
46
+ children: "▾"
47
+ })
48
+ ]
49
+ }), props.open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
50
+ className: `${p}-body`,
51
+ children: [
52
+ props.readOnlyNotice !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
53
+ className: `${p}-readOnly`,
54
+ role: "status",
55
+ children: props.readOnlyNotice
56
+ }) : null,
57
+ props.children,
58
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
59
+ className: `${p}-footer`,
60
+ children: [props.status !== void 0 && props.status.kind !== "idle" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
61
+ className: `${p}-status${props.status.kind === "error" ? ` ${p}-statusError` : ""}`,
62
+ role: "status",
63
+ children: props.status.text
64
+ }) : null, props.actions.map((action) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
65
+ type: "button",
66
+ className: `${p}-btn ${action.variant === "primary" ? `${p}-btnPrimary` : `${p}-btnGhost`}`,
67
+ disabled: action.disabled === true,
68
+ onClick: action.onClick,
69
+ children: action.label
70
+ }, action.key))]
71
+ })
72
+ ]
73
+ }) : null]
74
+ });
75
+ }
76
+ //#endregion
77
+ //#region ../shared/src/client/fields.tsx
78
+ function TextField(props) {
79
+ const p = props.prefix ?? "dshp";
80
+ const invalid = props.invalid === true;
81
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
82
+ className: `${p}-field`,
83
+ children: [
84
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
85
+ className: `${p}-head`,
86
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
87
+ className: `${p}-label`,
88
+ htmlFor: props.id,
89
+ children: props.label
90
+ }), props.badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
91
+ className: `${p}-badge ${props.badge.set ? `${p}-badgeSet` : `${p}-badgeUnset`}`,
92
+ children: props.badge.text
93
+ }) : null]
94
+ }),
95
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
96
+ id: props.id,
97
+ className: `${p}-input${invalid ? ` ${p}-inputInvalid` : ""}`,
98
+ type: props.password === true ? "password" : "text",
99
+ inputMode: props.numeric === true ? "numeric" : void 0,
100
+ autoComplete: props.password === true ? "off" : void 0,
101
+ "aria-invalid": invalid || void 0,
102
+ value: props.value,
103
+ disabled: props.disabled === true,
104
+ onChange: (event) => props.onEdit(event.target.value)
105
+ }),
106
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
107
+ className: invalid ? `${p}-invalid` : `${p}-hint`,
108
+ children: invalid ? props.invalidLabel ?? "" : props.hint ?? ""
109
+ })
110
+ ]
111
+ });
112
+ }
113
+ function CheckRow(props) {
114
+ const p = props.prefix ?? "dshp";
115
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
116
+ className: `${p}-checkRow`,
117
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
118
+ id: props.id,
119
+ type: "checkbox",
120
+ checked: props.checked,
121
+ disabled: props.disabled === true,
122
+ onChange: (event) => props.onEdit(event.target.checked)
123
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
124
+ htmlFor: props.id,
125
+ children: props.label
126
+ })]
127
+ });
128
+ }
129
+ //#endregion
130
+ //#region ../shared/src/client/i18n.ts
131
+ /** 卡片通用文案(save/discard/unsaved/loading 等四插件共有键)。 */
132
+ const commonZh = {
133
+ save: "保存",
134
+ saving: "保存中…",
135
+ discard: "放弃",
136
+ unsaved: "未保存",
137
+ loading: "加载中…",
138
+ unavailable: "配置服务不可用。",
139
+ readOnly: "当前部署无 settings provider,配置为只读;请编辑 settings.yaml。",
140
+ invalidNumber: "请输入正整数。",
141
+ collapse: "收起",
142
+ expand: "展开",
143
+ enabledOn: "已启用",
144
+ enabledOff: "未启用",
145
+ saveFailed: "保存失败,请检查填写内容。",
146
+ confirm: "确认",
147
+ cancel: "取消"
148
+ };
149
+ const commonEn = {
150
+ save: "Save",
151
+ saving: "Saving…",
152
+ discard: "Discard",
153
+ unsaved: "Unsaved",
154
+ loading: "Loading…",
155
+ unavailable: "Settings service unavailable.",
156
+ readOnly: "No settings provider in this deployment; config is read-only. Edit settings.yaml.",
157
+ invalidNumber: "Enter a positive integer.",
158
+ collapse: "Collapse",
159
+ expand: "Expand",
160
+ enabledOn: "On",
161
+ enabledOff: "Off",
162
+ saveFailed: "Save failed; check the fields.",
163
+ confirm: "Confirm",
164
+ cancel: "Cancel"
165
+ };
166
+ /** own 覆盖同键合并(返回新对象,入参不可变)。 */
167
+ function mergeDict(base, own) {
168
+ return {
169
+ ...base,
170
+ ...own
171
+ };
172
+ }
173
+ //#endregion
174
+ //#region ../shared/src/client/scope.ts
175
+ /**
176
+ * api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
177
+ * 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
178
+ * 刷新:remote `settings/document-updated`(按命名空间过滤)与
179
+ * `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
180
+ * (loopback 或 tailnet 信任域名)下行为一致。
181
+ * effect 归属调用方 fiber(label 需含插件名以便诊断)。
182
+ */
183
+ function createApiScope(api, ns, c, label) {
184
+ let state = {
185
+ status: "loading",
186
+ value: void 0,
187
+ revision: void 0,
188
+ writable: false
189
+ };
190
+ const listeners = /* @__PURE__ */ new Set();
191
+ let generation = 0;
192
+ const publish = (next) => {
193
+ state = next;
194
+ for (const listener of [...listeners]) listener();
195
+ };
196
+ const load = async () => {
197
+ const gen = ++generation;
198
+ let response;
199
+ try {
200
+ response = await api.describe({});
201
+ } catch {
202
+ return;
203
+ }
204
+ if (gen !== generation || !response.result.ok) return;
205
+ const writable = response.result.value?.writable ?? false;
206
+ const view = response.result.value?.namespaces.find((candidate) => candidate.ns === ns);
207
+ if (view === void 0) {
208
+ publish({
209
+ status: "unavailable",
210
+ value: void 0,
211
+ revision: void 0,
212
+ writable
213
+ });
214
+ return;
215
+ }
216
+ publish({
217
+ status: "ready",
218
+ value: view.value,
219
+ revision: view.revision,
220
+ writable
221
+ });
222
+ };
223
+ const refresh = (namespace) => {
224
+ if (namespace !== void 0 && namespace !== ns) return;
225
+ load();
226
+ };
227
+ const disposers = [c.get("remote").$on("settings/document-updated", refresh), c.on("connection/reset", () => {
228
+ load();
229
+ })];
230
+ c.effect(() => () => {
231
+ for (const dispose of disposers) dispose();
232
+ }, label);
233
+ load();
234
+ return {
235
+ getSnapshot: () => state,
236
+ subscribe: (listener) => {
237
+ listeners.add(listener);
238
+ return () => {
239
+ listeners.delete(listener);
240
+ };
241
+ },
242
+ load
243
+ };
244
+ }
245
+ //#endregion
246
+ //#region ../shared/src/client/styles.ts
247
+ /**
248
+ * 配置卡片样式工厂(各插件 client 的公共收编版)。
249
+ * 视觉规则与迁移前逐字一致(类名前缀换为各插件自身,DOM 类名不变),
250
+ * 另补移动端与可达性增强(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
251
+ * - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
252
+ * - footer 按钮等宽换行、状态文字独占一行;
253
+ * - 展开态 body 底部 sticky 保存栏(长表单滚动中始终可达)。
254
+ * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
255
+ * @module @dsh-plus/shared/client/styles
256
+ */
257
+ /** 生成全套卡片 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
258
+ function cardCss(prefix, extra = "") {
259
+ return `
260
+ .${prefix}-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
261
+ .${prefix}-card:hover{border-color:var(--dsw-alias-label-dimmed)}
262
+ .${prefix}-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
263
+ .${prefix}-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
264
+ .${prefix}-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
265
+ .${prefix}-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
266
+ .${prefix}-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
267
+ .${prefix}-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
268
+ .${prefix}-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
269
+ .${prefix}-chevronOpen{transform:rotate(180deg)}
270
+ .${prefix}-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
271
+ .${prefix}-statusBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
272
+ .${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
273
+ .${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
274
+ .${prefix}-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
275
+ .${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
276
+ .${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
277
+ .${prefix}-head{align-items:center;gap:8px;display:flex}
278
+ .${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
279
+ .${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
280
+ .${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
281
+ .${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
282
+ .${prefix}-input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px}
283
+ .${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
284
+ .${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
285
+ .${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
286
+ .${prefix}-select{appearance:none;background-image:linear-gradient(45deg,transparent 50%,var(--dsw-alias-label-tertiary) 50%),linear-gradient(135deg,var(--dsw-alias-label-tertiary) 50%,transparent 50%);background-position:calc(100% - 16px) 50%,calc(100% - 11px) 50%;background-size:5px 5px;background-repeat:no-repeat;padding-right:28px}
287
+ .${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
288
+ .${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
289
+ .${prefix}-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
290
+ .${prefix}-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
291
+ .${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
292
+ .${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
293
+ .${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
294
+ .${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
295
+ .${prefix}-footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex;flex-wrap:wrap}
296
+ .${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
297
+ .${prefix}-statusError{color:var(--dsw-alias-label-error)}
298
+ .${prefix}-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
299
+ .${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
300
+ .${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
301
+ .${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
302
+ .${prefix}-btn:disabled{opacity:.4;cursor:default}
303
+ .${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
304
+ @media (max-width:767px){
305
+ .${prefix}-body{margin:0 10px}
306
+ .${prefix}-header{padding:12px 12px}
307
+ .${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
308
+ .${prefix}-checkRow{min-height:44px;padding:8px 0}
309
+ .${prefix}-checkRow input{width:18px;height:18px;flex:none}
310
+ .${prefix}-footer{position:sticky;bottom:0;background:var(--dsw-alias-bg-layer-2);margin:0 -10px;padding:10px 10px 6px;border-top:1px solid var(--dsw-alias-border-l2);border-bottom-left-radius:12px;border-bottom-right-radius:12px}
311
+ .${prefix}-status{flex-basis:100%;flex:none}
312
+ .${prefix}-btn{min-height:44px;flex:1;min-width:96px}
313
+ .${prefix}-statusBadge{display:none}
314
+ }
315
+ @media (pointer:coarse){
316
+ .${prefix}-btn{min-height:44px}
317
+ .${prefix}-checkRow{min-height:44px}
318
+ .${prefix}-input,.${prefix}-select{height:40px}
319
+ }
320
+ ${extra}
321
+ `;
322
+ }
323
+ /**
324
+ * 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
325
+ * 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
326
+ */
327
+ function injectCardStyle(pluginId, css) {
328
+ if (typeof document === "undefined") return null;
329
+ const tagId = `${pluginId}/card.css`;
330
+ if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
331
+ const tag = document.createElement("style");
332
+ tag.dataset.plugin = pluginId;
333
+ tag.dataset.pluginCss = tagId;
334
+ tag.textContent = css;
335
+ document.head.appendChild(tag);
336
+ return tag;
337
+ }
338
+ //#endregion
9
339
  //#region src/ns.ts
10
340
  /**
11
341
  * settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
@@ -18,17 +348,14 @@ window.__ModuleLoader__.load({
18
348
  //#region src/client/card.tsx
19
349
  /**
20
350
  * 「访问控制」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
21
- * 交互对齐官方卡片:折叠/展开、staged draft、未保存标记、保存/放弃。
22
- * 配置读写走官方 settingsScope 传输(scope.ts):value 为 schema 解析后的
23
- * 脱敏视图(token 不出现,tokenConfigured 经 describe 的 secrets 探测),
351
+ * 外壳与基础控件走 @dsh-plus/shared/client 套件(CardChrome/TextField/CheckRow),
352
+ * 本文件保留业务字段(token/白名单 textarea/诊断面板)与保存逻辑。
353
+ * 配置读写走官方 settingsScope 传输:value 为 schema 解析后的脱敏视图
354
+ * (token 不出现,tokenConfigured 经 describe 的 secrets 探测),
24
355
  * 保存经 settings.update 深合并(空 token 剔除 = 保持不变)。
25
356
  * 卡片顶部「当前页面诊断」读 /dsh-plus/gate/status(本页放行原因/客户端 IP)。
26
357
  * @module access-gate/client/card
27
358
  */
28
- const IDLE_STATUS = {
29
- kind: "idle",
30
- text: ""
31
- };
32
359
  function draftFromValue(value) {
33
360
  return {
34
361
  enabled: value.enabled,
@@ -140,315 +467,192 @@ window.__ModuleLoader__.load({
140
467
  }).finally(() => setSaving(false));
141
468
  };
142
469
  const disabled = !snapshot.writable;
143
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
144
- className: `dag-card${open ? " dag-cardOpen" : ""}`,
145
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
146
- type: "button",
147
- className: "dag-header",
148
- "aria-expanded": open,
149
- "aria-label": `${t(open ? "collapse" : "expand")}: ${t("title")}`,
150
- onClick: () => setOpen(!open),
151
- children: [
152
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
153
- className: "dag-headText",
154
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
155
- className: "dag-name",
156
- children: t("title")
157
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
158
- className: "dag-description",
159
- children: t("description")
160
- })]
161
- }),
162
- dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
163
- className: "dag-pending",
164
- children: t("unsaved")
165
- }) : null,
166
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
167
- className: `dag-chevron${open ? " dag-chevronOpen" : ""}`,
168
- children: "▾"
169
- })
170
- ]
171
- }), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
172
- className: "dag-body",
173
- children: [
174
- disabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
175
- className: "dag-readOnly",
176
- role: "status",
177
- children: t("readOnly")
178
- }) : null,
179
- failClosed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
180
- className: "dag-warn",
181
- children: t("warnFailClosed")
182
- }) : null,
183
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
184
- className: "dag-field",
185
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
470
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CardChrome, {
471
+ prefix: "dag",
472
+ title: t("title"),
473
+ description: t("description"),
474
+ open,
475
+ onToggle: setOpen,
476
+ statusBadge: {
477
+ text: t(draft.enabled ? "enabledOn" : "enabledOff"),
478
+ on: draft.enabled
479
+ },
480
+ dirty,
481
+ dirtyLabel: t("unsaved"),
482
+ readOnlyNotice: disabled ? t("readOnly") : void 0,
483
+ status,
484
+ actions: [{
485
+ key: "discard",
486
+ label: t("discard"),
487
+ disabled: !dirty || saving,
488
+ onClick: () => {
489
+ setDraft(draftFromValue(value));
490
+ setStatus(IDLE_STATUS);
491
+ }
492
+ }, {
493
+ key: "save",
494
+ label: t(saving ? "saving" : "save"),
495
+ variant: "primary",
496
+ disabled: !dirty || invalid || saving || disabled,
497
+ onClick: onSave
498
+ }],
499
+ children: [
500
+ failClosed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
501
+ className: "dag-warn",
502
+ children: t("warnFailClosed")
503
+ }) : null,
504
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
505
+ prefix: "dag",
506
+ id: "dag-enabled",
507
+ label: t("enabledHint"),
508
+ checked: draft.enabled,
509
+ disabled,
510
+ onEdit: (v) => edit("enabled", v)
511
+ }),
512
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
513
+ prefix: "dag",
514
+ id: "dag-token",
515
+ label: t("token"),
516
+ hint: t("tokenHint"),
517
+ value: draft.token,
518
+ password: true,
519
+ disabled,
520
+ badge: {
521
+ text: t(tokenConfigured ? "tokenSet" : "tokenUnset"),
522
+ set: tokenConfigured
523
+ },
524
+ onEdit: (v) => edit("token", v)
525
+ }),
526
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
527
+ className: "dag-field",
528
+ children: [
529
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
186
530
  className: "dag-head",
187
531
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
188
532
  className: "dag-label",
189
- htmlFor: "dag-enabled",
190
- children: t("enabled")
533
+ htmlFor: "dag-allowed",
534
+ children: t("allowedIps")
191
535
  })
192
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
193
- className: "dag-checkRow",
194
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
195
- id: "dag-enabled",
196
- type: "checkbox",
197
- checked: draft.enabled,
198
- disabled,
199
- onChange: (event) => edit("enabled", event.target.checked)
200
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
201
- htmlFor: "dag-enabled",
202
- children: t("enabledHint")
536
+ }),
537
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
538
+ id: "dag-allowed",
539
+ className: "dag-textarea",
540
+ rows: Math.min(8, Math.max(3, draft.allowedIpsText.split("\n").length)),
541
+ value: draft.allowedIpsText,
542
+ disabled,
543
+ onChange: (event) => edit("allowedIpsText", event.target.value)
544
+ }),
545
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
546
+ className: "dag-hint",
547
+ children: t("allowedIpsHint")
548
+ })
549
+ ]
550
+ }),
551
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
552
+ prefix: "dag",
553
+ id: "dag-xff",
554
+ label: t("trustForwardedForHint"),
555
+ checked: draft.trustForwardedFor,
556
+ disabled,
557
+ onEdit: (v) => edit("trustForwardedFor", v)
558
+ }),
559
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
560
+ prefix: "dag",
561
+ id: "dag-cookie",
562
+ label: t("cookieMaxAgeHours"),
563
+ hint: t("cookieMaxAgeHoursHint"),
564
+ value: draft.cookieMaxAgeHours,
565
+ numeric: true,
566
+ disabled,
567
+ invalid: !isPositiveInt(draft.cookieMaxAgeHours),
568
+ invalidLabel: t("invalidNumber"),
569
+ onEdit: (v) => edit("cookieMaxAgeHours", v)
570
+ }),
571
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
572
+ prefix: "dag",
573
+ id: "dag-faillimit",
574
+ label: t("loginFailLimit"),
575
+ hint: t("loginFailLimitHint"),
576
+ value: draft.loginFailLimit,
577
+ numeric: true,
578
+ disabled,
579
+ invalid: !isPositiveInt(draft.loginFailLimit),
580
+ invalidLabel: t("invalidNumber"),
581
+ onEdit: (v) => edit("loginFailLimit", v)
582
+ }),
583
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
584
+ prefix: "dag",
585
+ id: "dag-cooldown",
586
+ label: t("loginCooldownMs"),
587
+ hint: t("loginCooldownMsHint"),
588
+ value: draft.loginCooldownMs,
589
+ numeric: true,
590
+ disabled,
591
+ invalid: !isPositiveInt(draft.loginCooldownMs),
592
+ invalidLabel: t("invalidNumber"),
593
+ onEdit: (v) => edit("loginCooldownMs", v)
594
+ }),
595
+ diag !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
596
+ className: `dag-diag${diag.invalidEntries.length > 0 ? " dag-diagWarn" : ""}`,
597
+ children: [
598
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
599
+ className: "dag-diagTitle",
600
+ children: t("diagTitle")
601
+ }),
602
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
603
+ className: "dag-diagRow",
604
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
605
+ className: "dag-diagKey",
606
+ children: t("diagVerdict")
607
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
608
+ className: "dag-diagVal",
609
+ children: verdictLabel(t, diag)
203
610
  })]
204
- })]
205
- }),
206
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
207
- className: "dag-field",
208
- children: [
209
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
210
- className: "dag-head",
211
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
212
- className: "dag-label",
213
- htmlFor: "dag-token",
214
- children: t("token")
215
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
216
- className: `dag-badge ${tokenConfigured ? "dag-badgeSet" : "dag-badgeUnset"}`,
217
- children: t(tokenConfigured ? "tokenSet" : "tokenUnset")
218
- })]
219
- }),
220
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
221
- id: "dag-token",
222
- className: "dag-input",
223
- type: "password",
224
- autoComplete: "off",
225
- value: draft.token,
226
- disabled,
227
- onChange: (event) => edit("token", event.target.value)
228
- }),
229
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
230
- className: "dag-hint",
231
- children: t("tokenHint")
232
- })
233
- ]
234
- }),
235
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
236
- className: "dag-field",
237
- children: [
238
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
239
- className: "dag-head",
240
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
241
- className: "dag-label",
242
- htmlFor: "dag-allowed",
243
- children: t("allowedIps")
244
- })
245
- }),
246
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
247
- id: "dag-allowed",
248
- className: "dag-textarea",
249
- rows: Math.min(8, Math.max(3, draft.allowedIpsText.split("\n").length)),
250
- value: draft.allowedIpsText,
251
- disabled,
252
- onChange: (event) => edit("allowedIpsText", event.target.value)
253
- }),
254
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
255
- className: "dag-hint",
256
- children: t("allowedIpsHint")
257
- })
258
- ]
259
- }),
260
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
261
- className: "dag-field",
262
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
263
- className: "dag-head",
264
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
265
- className: "dag-label",
266
- htmlFor: "dag-xff",
267
- children: t("trustForwardedFor")
268
- })
269
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
270
- className: "dag-checkRow",
271
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
272
- id: "dag-xff",
273
- type: "checkbox",
274
- checked: draft.trustForwardedFor,
275
- disabled,
276
- onChange: (event) => edit("trustForwardedFor", event.target.checked)
277
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
278
- htmlFor: "dag-xff",
279
- children: t("trustForwardedForHint")
611
+ }),
612
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
613
+ className: "dag-diagRow",
614
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
615
+ className: "dag-diagKey",
616
+ children: t("diagClientIp")
617
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
618
+ className: "dag-diagVal",
619
+ children: diag.clientIp ?? "—"
280
620
  })]
281
- })]
282
- }),
283
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
284
- className: "dag-field",
285
- children: [
286
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
287
- className: "dag-head",
288
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
289
- className: "dag-label",
290
- htmlFor: "dag-cookie",
291
- children: t("cookieMaxAgeHours")
292
- })
293
- }),
294
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
295
- id: "dag-cookie",
296
- className: `dag-input${isPositiveInt(draft.cookieMaxAgeHours) ? "" : " dag-inputInvalid"}`,
297
- type: "text",
298
- inputMode: "numeric",
299
- value: draft.cookieMaxAgeHours,
300
- disabled,
301
- "aria-invalid": !isPositiveInt(draft.cookieMaxAgeHours) || void 0,
302
- onChange: (event) => edit("cookieMaxAgeHours", event.target.value)
303
- }),
304
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
305
- className: isPositiveInt(draft.cookieMaxAgeHours) ? "dag-hint" : "dag-invalid",
306
- children: isPositiveInt(draft.cookieMaxAgeHours) ? t("cookieMaxAgeHoursHint") : t("invalidNumber")
307
- })
308
- ]
309
- }),
310
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
311
- className: "dag-field",
312
- children: [
313
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
314
- className: "dag-head",
315
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
316
- className: "dag-label",
317
- htmlFor: "dag-faillimit",
318
- children: t("loginFailLimit")
319
- })
320
- }),
321
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
322
- id: "dag-faillimit",
323
- className: `dag-input${isPositiveInt(draft.loginFailLimit) ? "" : " dag-inputInvalid"}`,
324
- type: "text",
325
- inputMode: "numeric",
326
- value: draft.loginFailLimit,
327
- disabled,
328
- "aria-invalid": !isPositiveInt(draft.loginFailLimit) || void 0,
329
- onChange: (event) => edit("loginFailLimit", event.target.value)
330
- }),
331
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
332
- className: isPositiveInt(draft.loginFailLimit) ? "dag-hint" : "dag-invalid",
333
- children: isPositiveInt(draft.loginFailLimit) ? t("loginFailLimitHint") : t("invalidNumber")
334
- })
335
- ]
336
- }),
337
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
338
- className: "dag-field",
339
- children: [
340
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
341
- className: "dag-head",
342
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
343
- className: "dag-label",
344
- htmlFor: "dag-cooldown",
345
- children: t("loginCooldownMs")
346
- })
347
- }),
348
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
349
- id: "dag-cooldown",
350
- className: `dag-input${isPositiveInt(draft.loginCooldownMs) ? "" : " dag-inputInvalid"}`,
351
- type: "text",
352
- inputMode: "numeric",
353
- value: draft.loginCooldownMs,
354
- disabled,
355
- "aria-invalid": !isPositiveInt(draft.loginCooldownMs) || void 0,
356
- onChange: (event) => edit("loginCooldownMs", event.target.value)
357
- }),
358
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
359
- className: isPositiveInt(draft.loginCooldownMs) ? "dag-hint" : "dag-invalid",
360
- children: isPositiveInt(draft.loginCooldownMs) ? t("loginCooldownMsHint") : t("invalidNumber")
361
- })
362
- ]
363
- }),
364
- diag !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
365
- className: `dag-diag${diag.invalidEntries.length > 0 ? " dag-diagWarn" : ""}`,
366
- children: [
367
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
368
- className: "dag-diagTitle",
369
- children: t("diagTitle")
370
- }),
371
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
372
- className: "dag-diagRow",
373
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
374
- className: "dag-diagKey",
375
- children: t("diagVerdict")
376
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
377
- className: "dag-diagVal",
378
- children: verdictLabel(t, diag)
379
- })]
380
- }),
381
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
382
- className: "dag-diagRow",
383
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
384
- className: "dag-diagKey",
385
- children: t("diagClientIp")
386
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
387
- className: "dag-diagVal",
388
- children: diag.clientIp ?? "—"
389
- })]
390
- }),
391
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
392
- className: "dag-diagRow",
393
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
394
- className: "dag-diagKey",
395
- children: t("diagReason")
396
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
397
- className: "dag-diagVal",
398
- children: diag.reason !== null ? t(REASON_KEYS[diag.reason] ?? diag.reason) : "—"
399
- })]
400
- }),
401
- diag.invalidEntries.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
402
- className: "dag-diagRow",
403
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
404
- className: "dag-diagKey",
405
- children: "!"
406
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
407
- className: "dag-diagVal",
408
- children: [t("diagInvalid"), diag.invalidEntries.join("、")]
409
- })]
410
- }) : null
411
- ]
412
- }) : null,
413
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
414
- className: "dag-footer",
415
- children: [
416
- status.kind !== "idle" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
417
- className: `dag-status${status.kind === "error" ? " dag-statusError" : ""}`,
418
- role: "status",
419
- children: status.text
420
- }) : null,
421
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
422
- type: "button",
423
- className: "dag-btn dag-btnGhost",
424
- disabled: !dirty || saving,
425
- onClick: () => {
426
- setDraft(draftFromValue(value));
427
- setStatus(IDLE_STATUS);
428
- },
429
- children: t("discard")
430
- }),
431
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
432
- type: "button",
433
- className: "dag-btn dag-btnPrimary",
434
- disabled: !dirty || invalid || saving || disabled,
435
- onClick: onSave,
436
- children: t(saving ? "saving" : "save")
437
- })
438
- ]
439
- })
440
- ]
441
- }) : null]
621
+ }),
622
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
623
+ className: "dag-diagRow",
624
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
625
+ className: "dag-diagKey",
626
+ children: t("diagReason")
627
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
628
+ className: "dag-diagVal",
629
+ children: diag.reason !== null ? t(REASON_KEYS[diag.reason] ?? diag.reason) : "—"
630
+ })]
631
+ }),
632
+ diag.invalidEntries.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
633
+ className: "dag-diagRow",
634
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
635
+ className: "dag-diagKey",
636
+ children: "!"
637
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
638
+ className: "dag-diagVal",
639
+ children: [t("diagInvalid"), diag.invalidEntries.join("、")]
640
+ })]
641
+ }) : null
642
+ ]
643
+ }) : null
644
+ ]
442
645
  });
443
646
  }
444
647
  //#endregion
445
648
  //#region src/client/i18n.ts
446
649
  /**
447
650
  * 配置卡片文案(zh/en)。经 ctx.locale.register 注册、bind 取用,与官方卡片同机制。
651
+ * 公共键(save/discard/unsaved 等)来自 shared 的 common 字典,本文件只维护业务键。
448
652
  * @module access-gate/client/i18n
449
653
  */
450
654
  const NS = "dsh-plus-access-gate";
451
- const zh = {
655
+ const ownZh = {
452
656
  title: "访问控制",
453
657
  description: "Web 访问围栏:本机直连放行;远程按白名单 IP 或访问令牌放行,其余拦截到登录页。",
454
658
  enabled: "启用访问围栏",
@@ -479,20 +683,9 @@ window.__ModuleLoader__.load({
479
683
  diagLogin: "登录页",
480
684
  diagOff: "围栏未启用",
481
685
  diagInvalid: "白名单存在无法解析的条目:",
482
- warnFailClosed: "警告:已启用但令牌与白名单均为空——所有远程访问将被拒绝(含本页之外的设备)。",
483
- save: "保存",
484
- saving: "保存中…",
485
- discard: "放弃",
486
- unsaved: "未保存",
487
- saveFailed: "保存失败,请检查填写内容。",
488
- loading: "加载中…",
489
- unavailable: "配置服务不可用。",
490
- readOnly: "当前部署无 settings provider,配置为只读;请编辑 settings.yaml。",
491
- expand: "展开",
492
- collapse: "收起",
493
- invalidNumber: "请输入有效数字"
686
+ warnFailClosed: "警告:已启用但令牌与白名单均为空——所有远程访问将被拒绝(含本页之外的设备)。"
494
687
  };
495
- const en = {
688
+ const ownEn = {
496
689
  title: "Access Control",
497
690
  description: "Web access gate: loopback passes; remote traffic needs an allowlisted IP or the token, others hit the login page.",
498
691
  enabled: "Enable access gate",
@@ -523,71 +716,23 @@ window.__ModuleLoader__.load({
523
716
  diagLogin: "login page",
524
717
  diagOff: "gate disabled",
525
718
  diagInvalid: "Allowlist entries that failed to parse:",
526
- warnFailClosed: "Warning: enabled with no token and an empty allowlist — all remote access will be refused.",
527
- save: "Save",
528
- saving: "Saving…",
529
- discard: "Discard",
530
- unsaved: "Unsaved",
531
- saveFailed: "Save failed; please check the inputs.",
532
- loading: "Loading…",
533
- unavailable: "Settings service unavailable.",
534
- readOnly: "No settings provider in this deployment; read-only. Edit settings.yaml instead.",
535
- expand: "Expand",
536
- collapse: "Collapse",
537
- invalidNumber: "Enter a valid number"
719
+ warnFailClosed: "Warning: enabled with no token and an empty allowlist — all remote access will be refused."
538
720
  };
721
+ const zh = mergeDict(commonZh, ownZh);
722
+ const en = mergeDict(commonEn, ownEn);
539
723
  //#endregion
540
724
  //#region src/client/styles.ts
541
725
  /**
542
- * 配置卡片样式:沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),
543
- * 视觉对齐官方卡片(--dsw-alias-* 变量),不覆盖上游任何选择器。
726
+ * 配置卡片样式:基础规则走 @dsh-plus/shared/client 的 cardCss('dag'),
727
+ * 本文件只补插件特有规则(textarea / 诊断面板 / 警示条)。
728
+ * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载)。
544
729
  * @module access-gate/client/styles
545
730
  */
546
731
  const PLUGIN_ID = "@dsh-plus/access-gate";
547
- const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`;
548
- const cardCss = `
549
- .dag-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
550
- .dag-card:hover{border-color:var(--dsw-alias-label-dimmed)}
551
- .dag-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
552
- .dag-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
553
- .dag-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
554
- .dag-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
555
- .dag-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
556
- .dag-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
557
- .dag-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
558
- .dag-chevronOpen{transform:rotate(180deg)}
559
- .dag-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}
560
- .dag-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
561
- .dag-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
562
- .dag-field+.dag-field{border-top:1px solid var(--dsw-alias-border-l2)}
563
- .dag-head{align-items:center;gap:8px;display:flex}
564
- .dag-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
565
- .dag-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
566
- .dag-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
567
- .dag-badgeUnset{color:var(--dsw-alias-label-tertiary)}
568
- .dag-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}
569
- .dag-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
570
- .dag-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
571
- .dag-inputInvalid{border-color:var(--dsw-alias-label-error)}
732
+ const cardCssAll = cardCss("dag", `
572
733
  .dag-textarea{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:8px 12px;font-size:13px;line-height:1.6;min-height:96px;resize:vertical;font-family:var(--dsw-alias-font-mono,ui-monospace,monospace)}
573
734
  .dag-textarea:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
574
735
  .dag-textarea:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
575
- .dag-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
576
- .dag-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
577
- .dag-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
578
- .dag-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
579
- .dag-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
580
- .dag-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
581
- .dag-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
582
- .dag-footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex;flex-wrap:wrap}
583
- .dag-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
584
- .dag-statusError{color:var(--dsw-alias-label-error)}
585
- .dag-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
586
- .dag-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
587
- .dag-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
588
- .dag-btnPrimary{background:var(--dsh-plus-brand,#3d6dff);color:#fff}
589
- .dag-btn:disabled{opacity:.4;cursor:default}
590
- .dag-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
591
736
  .dag-diag{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:10px 12px;margin:12px 0 0;flex-direction:column;gap:4px;display:flex}
592
737
  .dag-diagTitle{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;margin:0}
593
738
  .dag-diagRow{display:flex;gap:8px;font-size:12px;line-height:1.6}
@@ -595,17 +740,15 @@ window.__ModuleLoader__.load({
595
740
  .dag-diagVal{color:var(--dsw-alias-label-primary);margin:0}
596
741
  .dag-diagWarn{color:var(--dsw-alias-label-error);border-color:var(--dsw-alias-label-error)}
597
742
  .dag-warn{color:var(--dsh-plus-warn,#c9503f);border:1px solid var(--dsh-plus-warn-border,rgba(201,80,63,.4));border-radius:8px;padding:8px 12px;margin:12px 0 0;font-size:12px;line-height:1.6}
598
- `;
743
+ @media (max-width:767px){
744
+ .dag-diagRow{flex-direction:column;gap:2px}
745
+ .dag-diagKey{min-width:0}
746
+ .dag-textarea{font-size:16px}
747
+ }
748
+ `);
599
749
  /** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
600
750
  function injectStyle() {
601
- if (typeof document === "undefined") return null;
602
- if (document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`) !== null) return null;
603
- const tag = document.createElement("style");
604
- tag.dataset.plugin = PLUGIN_ID;
605
- tag.dataset.pluginCss = STYLE_TAG_ID;
606
- tag.textContent = cardCss;
607
- document.head.append(tag);
608
- return tag;
751
+ return injectCardStyle(PLUGIN_ID, cardCssAll);
609
752
  }
610
753
  //#endregion
611
754
  //#region src/client/client.ts
@@ -617,75 +760,6 @@ window.__ModuleLoader__.load({
617
760
  "connection",
618
761
  "remote"
619
762
  ];
620
- /**
621
- * api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
622
- * 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
623
- * 刷新:remote `settings/document-updated`(按命名空间过滤)与
624
- * `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
625
- * (loopback 或 tailnet 信任域名)下行为一致。
626
- */
627
- function createApiScope(api, ns, c) {
628
- let state = {
629
- status: "loading",
630
- value: void 0,
631
- revision: void 0,
632
- writable: false
633
- };
634
- const listeners = /* @__PURE__ */ new Set();
635
- let generation = 0;
636
- const publish = (next) => {
637
- state = next;
638
- for (const listener of [...listeners]) listener();
639
- };
640
- const load = async () => {
641
- const gen = ++generation;
642
- let response;
643
- try {
644
- response = await api.describe({});
645
- } catch {
646
- return;
647
- }
648
- if (gen !== generation || !response.result.ok) return;
649
- const writable = response.result.value?.writable ?? false;
650
- const view = response.result.value?.namespaces.find((candidate) => candidate.ns === ns);
651
- if (view === void 0) {
652
- publish({
653
- status: "unavailable",
654
- value: void 0,
655
- revision: void 0,
656
- writable
657
- });
658
- return;
659
- }
660
- publish({
661
- status: "ready",
662
- value: view.value,
663
- revision: view.revision,
664
- writable
665
- });
666
- };
667
- const refresh = (namespace) => {
668
- if (namespace !== void 0 && namespace !== ns) return;
669
- load();
670
- };
671
- const disposers = [c.get("remote").$on("settings/document-updated", refresh), c.on("connection/reset", () => {
672
- load();
673
- })];
674
- c.effect(() => () => {
675
- for (const dispose of disposers) dispose();
676
- }, "access-gate: settings scope");
677
- load();
678
- return {
679
- getSnapshot: () => state,
680
- subscribe: (listener) => {
681
- listeners.add(listener);
682
- return () => {
683
- listeners.delete(listener);
684
- };
685
- },
686
- load
687
- };
688
- }
689
763
  function apply(ctx) {
690
764
  const c = ctx;
691
765
  const tag = injectStyle();
@@ -697,7 +771,7 @@ window.__ModuleLoader__.load({
697
771
  en
698
772
  }), "access-gate: locale");
699
773
  const api = c.get("connection").api.settings;
700
- const scope = createApiScope(api, SETTINGS_NS, c);
774
+ const scope = createApiScope(api, SETTINGS_NS, c, "access-gate: settings scope");
701
775
  c.slots.inject("settings.plugin.item", () => c.slots.register({
702
776
  name: "settings.plugin.item",
703
777
  key: SETTINGS_NS,