@jayyuen66/dsh-zvec-grep 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/LICENSE +1 -1
- package/README.md +4 -3
- package/README.zh-CN.md +4 -3
- package/THIRD_PARTY_NOTICES.md +18 -9
- package/client.js +769 -376
- package/docs/DETAIL.md +28 -0
- package/docs/DETAIL.zh.md +28 -0
- package/host.js +505 -188
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +58 -42
package/client.js
CHANGED
|
@@ -7,6 +7,7 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
let exports = module.exports;
|
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
9
|
let react = require("react");
|
|
10
|
+
let zod = require("zod");
|
|
10
11
|
// lib/embedding-catalog.ts
|
|
11
12
|
/** 默认模型:本地最强(1024 维 / 8192 上下文 / 中英通用),约 640MB 一次性下载。 */
|
|
12
13
|
const DEFAULT_EMBEDDING = "local/qwen3-embedding-0.6b";
|
|
@@ -16,16 +17,7 @@ const DEFAULT_EMBEDDING = "local/qwen3-embedding-0.6b";
|
|
|
16
17
|
* 而不是静默产出一个不在联合里的字符串。
|
|
17
18
|
*/
|
|
18
19
|
const TRANSFORMERS_JS_BACKEND = "transformers-js";
|
|
19
|
-
|
|
20
|
-
* 本地候选清单,按后端分三档(体积/语言口径,实测 zg v0.2.1):
|
|
21
|
-
* - llama-cpp:qwen3-embedding-0.6b 约 640MB(本包默认)、
|
|
22
|
-
* embeddinggemma-300m 约 300MB(英文)——两档都要原生件,Metal 加速由 zg 侧 device=auto 试;
|
|
23
|
-
* - model2vec:potion-code-16m-v2 约 32MB(代码专用、最轻最快)、potion-multilingual-128m
|
|
24
|
-
* (多语言轻量)、potion-retrieval-32m(通用检索)——纯 JS worker,零原生依赖;
|
|
25
|
-
* - transformers-js:其余 ONNX 小模型,384 维那批是英文/多语言轻量档,768 维那批里
|
|
26
|
-
* jina 面向代码、gte/nomic 面向 8192 长文。
|
|
27
|
-
*/
|
|
28
|
-
const LOCAL_EMBEDDINGS = [
|
|
20
|
+
const LOCAL_EMBEDDINGS = Object.freeze([
|
|
29
21
|
{
|
|
30
22
|
reference: "local/qwen3-embedding-0.6b",
|
|
31
23
|
backend: "llama-cpp",
|
|
@@ -81,28 +73,564 @@ const LOCAL_EMBEDDINGS = [
|
|
|
81
73
|
backend: TRANSFORMERS_JS_BACKEND,
|
|
82
74
|
dimension: 768
|
|
83
75
|
}
|
|
84
|
-
];
|
|
76
|
+
].map((entry) => Object.freeze(entry)));
|
|
85
77
|
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-diff.js
|
|
86
|
-
function e$
|
|
78
|
+
function e$2(t, n, r) {
|
|
87
79
|
if (t == null || n == null) return (t ?? null) === (n ?? null);
|
|
88
80
|
if (Object.is(t, n)) return !0;
|
|
89
81
|
if (typeof t != `object` || typeof n != `object`) return !1;
|
|
90
82
|
if (r.get(t) === n) return !0;
|
|
91
|
-
if (r.set(t, n), Array.isArray(t) || Array.isArray(n)) return !Array.isArray(t) || !Array.isArray(n) || t.length !== n.length ? !1 : t.every((t, i) => e$
|
|
83
|
+
if (r.set(t, n), Array.isArray(t) || Array.isArray(n)) return !Array.isArray(t) || !Array.isArray(n) || t.length !== n.length ? !1 : t.every((t, i) => e$2(t, n[i], r));
|
|
92
84
|
let i = Object.keys(t), a = Object.keys(n);
|
|
93
|
-
return i.length === a.length && i.every((i) => Object.hasOwn(n, i) && e$
|
|
85
|
+
return i.length === a.length && i.every((i) => Object.hasOwn(n, i) && e$2(Reflect.get(t, i), Reflect.get(n, i), r));
|
|
94
86
|
}
|
|
95
|
-
function t$
|
|
87
|
+
function t$2(t, n) {
|
|
96
88
|
let r = [];
|
|
97
|
-
for (let i of Object.keys(t)) e$
|
|
89
|
+
for (let i of Object.keys(t)) e$2(t[i], n[i], /* @__PURE__ */ new WeakMap()) || r.push(i);
|
|
98
90
|
return r;
|
|
99
91
|
}
|
|
92
|
+
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-ui.js
|
|
93
|
+
const c = `
|
|
94
|
+
.dsu-form{display:flex;flex-direction:column}
|
|
95
|
+
.dsu-section{margin-top:24px;padding-top:24px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
96
|
+
.dsu-form>.dsu-section:first-child{margin-top:0;padding-top:0;border-top:0}
|
|
97
|
+
.dsu-sectionTitle{margin:0;font-size:15px;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary)}
|
|
98
|
+
.dsu-sectionHint{margin:4px 0 0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
99
|
+
.dsu-statusbar{display:flex;flex-wrap:wrap;gap:4px 8px;margin-top:8px;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
100
|
+
.dsu-field{display:grid;grid-template-columns:minmax(0,1fr) minmax(240px,360px);column-gap:32px;align-items:center;padding:12px 0;border-top:.5px solid var(--dsw-alias-border-l2)}
|
|
101
|
+
.dsu-fieldMeta{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
102
|
+
.dsu-labelRow{display:flex;align-items:center;gap:6px;min-width:0}
|
|
103
|
+
.dsu-label{font-size:13px;font-weight:500;line-height:1.5;color:var(--dsw-alias-label-primary)}
|
|
104
|
+
.dsu-labelMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px}
|
|
105
|
+
.dsu-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
106
|
+
.dsu-control{min-width:0;display:flex;align-items:center;gap:8px}
|
|
107
|
+
.dsu-fieldWide{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
108
|
+
.dsu-fieldWide .dsu-control{width:100%;max-width:720px;margin-top:2px}
|
|
109
|
+
.dsu-help{display:inline-flex;align-items:center;gap:6px;min-width:0}
|
|
110
|
+
.dsu-helpBtn{appearance:none;border:0;background:transparent;padding:0;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary);cursor:help;border-radius:50%;flex:none}
|
|
111
|
+
.dsu-help:hover .dsu-helpBtn,.dsu-helpBtn:focus-visible{color:var(--dsw-alias-label-primary)}
|
|
112
|
+
.dsu-helpBtn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
113
|
+
.dsu-tip{position:fixed;z-index:60;box-sizing:border-box;max-width:min(340px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow:auto;overflow-wrap:anywhere;padding:10px 12px;border-radius:10px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);box-shadow:0 12px 32px rgb(0 0 0 / 45%);font-size:12px;line-height:1.6;font-weight:400;color:var(--dsw-alias-label-secondary)}
|
|
114
|
+
.dsu-input{width:100%;height:34px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px}
|
|
115
|
+
.dsu-input:focus-visible{outline:none;border-color:var(--dsw-alias-state-business-primary)}
|
|
116
|
+
.dsu-input[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary)}
|
|
117
|
+
.dsu-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
118
|
+
.dsu-input::placeholder{color:var(--dsw-alias-label-tertiary)}
|
|
119
|
+
.dsu-textarea{height:auto;min-height:96px;padding:8px 12px;line-height:1.6;resize:vertical}
|
|
120
|
+
.dsu-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
121
|
+
.dsu-numberWrap{display:flex;flex-direction:column;gap:4px;width:100%;min-width:0}
|
|
122
|
+
.dsu-number{display:flex;align-items:center;gap:8px;min-width:0}
|
|
123
|
+
.dsu-number .dsu-input{min-width:0}
|
|
124
|
+
.dsu-unit{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
125
|
+
.dsu-error{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary)}
|
|
126
|
+
.dsu-switch{appearance:none;width:36px;height:20px;border-radius:999px;border:0;padding:2px;background:var(--dsw-alias-border-l3);display:flex;align-items:center;cursor:pointer;flex:none;transition:background-color .16s}
|
|
127
|
+
.dsu-knob{width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary);transition:transform .16s,background-color .16s}
|
|
128
|
+
.dsu-switch[aria-checked="true"]{background:var(--dsw-alias-label-primary)}
|
|
129
|
+
.dsu-switch[aria-checked="true"] .dsu-knob{transform:translateX(16px);background:var(--dsw-alias-label-primary-foreground)}
|
|
130
|
+
.dsu-switch:disabled{opacity:.4;cursor:not-allowed}
|
|
131
|
+
.dsu-switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
|
|
132
|
+
.dsu-selectWrap{position:relative;width:100%;min-width:0}
|
|
133
|
+
.dsu-select{display:flex;align-items:center;justify-content:space-between;gap:8px;text-align:left;cursor:pointer}
|
|
134
|
+
.dsu-select[aria-expanded="true"]{border-color:var(--dsw-alias-state-business-primary)}
|
|
135
|
+
.dsu-selectValue{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
136
|
+
.dsu-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}
|
|
137
|
+
.dsu-select[aria-expanded="true"] .dsu-chevron{transform:rotate(180deg)}
|
|
138
|
+
.dsu-menu{position:fixed;z-index:70;padding:4px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);border-radius:12px;box-shadow:0 12px 32px rgb(0 0 0 / 50%);max-height:280px;overflow:auto}
|
|
139
|
+
.dsu-option{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.4;width:100%;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 10px;border-radius:8px;cursor:pointer;text-align:left}
|
|
140
|
+
.dsu-option:hover,.dsu-option[data-active="true"]{background:var(--dsw-alias-bg-layer-3)}
|
|
141
|
+
.dsu-option:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
|
|
142
|
+
.dsu-option:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
|
|
143
|
+
.dsu-optionGroup{padding:6px 10px 2px;font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary)}
|
|
144
|
+
.dsu-check{opacity:0;flex:none}
|
|
145
|
+
.dsu-option[aria-selected="true"] .dsu-check{opacity:1}
|
|
146
|
+
.dsu-savebar{display:flex;align-items:center;gap:8px;padding:12px 0;margin-top:24px;border-top:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base)}
|
|
147
|
+
.dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
|
|
148
|
+
.dsu-btn{appearance:none;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.5;border-radius:var(--dsw-radius-md);padding:5px 14px;cursor:pointer;transition:background-color .12s,border-color .12s,color .12s,filter .12s}
|
|
149
|
+
.dsu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l3)}
|
|
150
|
+
.dsu-btn:active:not(:disabled){background:var(--dsw-alias-bg-layer-1)}
|
|
151
|
+
.dsu-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
152
|
+
.dsu-btn:disabled{opacity:.4;cursor:not-allowed}
|
|
153
|
+
.dsu-btnPrimary{background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
154
|
+
.dsu-btnPrimary:hover:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.9)}
|
|
155
|
+
.dsu-btnPrimary:active:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.84)}
|
|
156
|
+
.dsu-btnDanger{color:var(--dsw-alias-state-error-primary)}
|
|
157
|
+
.dsu-btnDanger:hover:not(:disabled){color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary);background:var(--dsw-alias-bg-layer-2)}
|
|
158
|
+
.dsu-status{margin-left:auto;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
159
|
+
.dsu-statusError{color:var(--dsw-alias-state-error-primary)}
|
|
160
|
+
.dsu-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr));gap:0 24px}
|
|
161
|
+
.dsu-grid>.dsu-field{display:flex;flex-direction:column;align-items:stretch;gap:6px;padding:10px 0;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
162
|
+
.dsu-grid>.dsu-field .dsu-control{width:100%}
|
|
163
|
+
@media (max-width:640px){
|
|
164
|
+
.dsu-field{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
165
|
+
.dsu-control{width:100%;max-width:720px}
|
|
166
|
+
.dsu-section{margin-top:20px;padding-top:20px}
|
|
167
|
+
}
|
|
168
|
+
@media (prefers-reduced-motion:reduce){
|
|
169
|
+
.dsu-switch,.dsu-knob,.dsu-chevron,.dsu-btn{transition:none}
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
function l(e, t = 30) {
|
|
173
|
+
return e.length <= t ? { hint: e } : { detail: e };
|
|
174
|
+
}
|
|
175
|
+
function u(t) {
|
|
176
|
+
return (0, react.createElement)(`div`, { className: `dsu-form` }, t.children);
|
|
177
|
+
}
|
|
178
|
+
function d(t) {
|
|
179
|
+
return (0, react.createElement)(`section`, { className: `dsu-section` }, (0, react.createElement)(`h2`, { className: `dsu-sectionTitle` }, t.title), t.hint === void 0 ? null : (0, react.createElement)(`p`, { className: `dsu-sectionHint` }, t.hint), t.children);
|
|
180
|
+
}
|
|
181
|
+
function m(a) {
|
|
182
|
+
let c = (0, react.useId)(), [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(!1), p = (0, react.useRef)(!1), m = (0, react.useRef)(!1), h = (0, react.useRef)(!1), g = (0, react.useRef)(null), _ = (0, react.useRef)(null), v = (0, react.useRef)(null), y = (0, react.useCallback)(() => {
|
|
183
|
+
v.current !== null && (clearTimeout(v.current), v.current = null);
|
|
184
|
+
}, []), b = (0, react.useCallback)(() => {
|
|
185
|
+
let e = g.current, t = _.current;
|
|
186
|
+
/* v8 ignore next 3 -- place 只在 open 的 layout effect 与挂载期监听器里调用;refs 为空只可能是卸载竞态 */
|
|
187
|
+
if (e === null || t === null) return;
|
|
188
|
+
let n = e.getBoundingClientRect(), r = t.offsetWidth, i = t.offsetHeight, { left: a } = n, o = n.bottom + 8;
|
|
189
|
+
o + i > window.innerHeight - 8 && (o = n.top - i - 8), a + r > window.innerWidth - 8 && (a = window.innerWidth - r - 8);
|
|
190
|
+
let s = Math.max(8, window.innerWidth - r - 8), c = Math.max(8, window.innerHeight - i - 8);
|
|
191
|
+
t.style.left = `${Math.min(Math.max(8, a), s)}px`, t.style.top = `${Math.min(Math.max(8, o), c)}px`;
|
|
192
|
+
}, []), x = (0, react.useCallback)(() => {
|
|
193
|
+
y(), h.current = !1, f(!1), u(!1);
|
|
194
|
+
}, [y]), S = (0, react.useCallback)(() => {
|
|
195
|
+
y(), u(!0);
|
|
196
|
+
}, [y]), C = (0, react.useCallback)(() => {
|
|
197
|
+
y(), !(p.current || m.current || h.current) && (v.current = setTimeout(() => {
|
|
198
|
+
/* v8 ignore next 3 -- 任何重新进入/钉住都会 cancelHide;这次复查只防未来的异步路径 */
|
|
199
|
+
v.current = null, p.current || m.current || h.current || u(!1);
|
|
200
|
+
}, 120));
|
|
201
|
+
}, [y]), w = (0, react.useCallback)((e) => {
|
|
202
|
+
h.current = e, f(e);
|
|
203
|
+
}, []);
|
|
204
|
+
(0, react.useLayoutEffect)(() => {
|
|
205
|
+
if (!l) return () => {};
|
|
206
|
+
b();
|
|
207
|
+
let e = (e) => {
|
|
208
|
+
let { target: t } = e;
|
|
209
|
+
t instanceof Node && _.current?.contains(t) === !0 || (h.current ? b() : x());
|
|
210
|
+
}, t = () => {
|
|
211
|
+
b();
|
|
212
|
+
};
|
|
213
|
+
return window.addEventListener(`scroll`, e, !0), window.addEventListener(`resize`, t), () => {
|
|
214
|
+
window.removeEventListener(`scroll`, e, !0), window.removeEventListener(`resize`, t);
|
|
215
|
+
};
|
|
216
|
+
}, [
|
|
217
|
+
l,
|
|
218
|
+
a.detail,
|
|
219
|
+
b,
|
|
220
|
+
x
|
|
221
|
+
]), (0, react.useEffect)(() => {
|
|
222
|
+
if (!l) return () => {};
|
|
223
|
+
let e = (e) => {
|
|
224
|
+
e.key === `Escape` && x();
|
|
225
|
+
};
|
|
226
|
+
return document.addEventListener(`keydown`, e), () => {
|
|
227
|
+
document.removeEventListener(`keydown`, e);
|
|
228
|
+
};
|
|
229
|
+
}, [l, x]), (0, react.useEffect)(() => y, [y]);
|
|
230
|
+
let T = (0, react.createElement)(`button`, {
|
|
231
|
+
ref: g,
|
|
232
|
+
type: `button`,
|
|
233
|
+
className: `dsu-helpBtn`,
|
|
234
|
+
"aria-label": `${a.label} 说明`,
|
|
235
|
+
"aria-describedby": c,
|
|
236
|
+
"aria-pressed": d,
|
|
237
|
+
onClick: () => {
|
|
238
|
+
h.current ? x() : (w(!0), S());
|
|
239
|
+
}
|
|
240
|
+
}, (0, react.createElement)(`svg`, {
|
|
241
|
+
width: 12,
|
|
242
|
+
height: 12,
|
|
243
|
+
viewBox: `0 0 14 14`,
|
|
244
|
+
"aria-hidden": !0
|
|
245
|
+
}, (0, react.createElement)(`circle`, {
|
|
246
|
+
cx: 7,
|
|
247
|
+
cy: 7,
|
|
248
|
+
r: 6,
|
|
249
|
+
fill: `none`,
|
|
250
|
+
stroke: `currentColor`,
|
|
251
|
+
strokeWidth: 1.2
|
|
252
|
+
}), (0, react.createElement)(`path`, {
|
|
253
|
+
d: `M7 6.2v4`,
|
|
254
|
+
stroke: `currentColor`,
|
|
255
|
+
strokeWidth: 1.3,
|
|
256
|
+
strokeLinecap: `round`
|
|
257
|
+
}), (0, react.createElement)(`circle`, {
|
|
258
|
+
cx: 7,
|
|
259
|
+
cy: 4.3,
|
|
260
|
+
r: .8,
|
|
261
|
+
fill: `currentColor`
|
|
262
|
+
}))), E = (0, react.createElement)(`div`, {
|
|
263
|
+
ref: _,
|
|
264
|
+
id: c,
|
|
265
|
+
role: `tooltip`,
|
|
266
|
+
className: `dsu-tip`,
|
|
267
|
+
hidden: !l
|
|
268
|
+
}, a.detail), D = a.showLabel === !1 ? null : (0, react.createElement)(`span`, { className: `dsu-label${a.compact === !0 ? ` dsu-labelMono` : ``}` }, a.label);
|
|
269
|
+
return (0, react.createElement)(`span`, {
|
|
270
|
+
className: `dsu-help`,
|
|
271
|
+
onMouseEnter: () => {
|
|
272
|
+
p.current = !0, S();
|
|
273
|
+
},
|
|
274
|
+
onMouseLeave: () => {
|
|
275
|
+
p.current = !1, C();
|
|
276
|
+
},
|
|
277
|
+
onFocus: () => {
|
|
278
|
+
m.current = !0, S();
|
|
279
|
+
},
|
|
280
|
+
onBlur: (e) => {
|
|
281
|
+
let t = e.relatedTarget;
|
|
282
|
+
t instanceof Node && e.currentTarget.contains(t) || (m.current = !1, C());
|
|
283
|
+
}
|
|
284
|
+
}, D, T, E);
|
|
285
|
+
}
|
|
286
|
+
function h(t) {
|
|
287
|
+
let n = `dsu-label${t.compact === !0 ? ` dsu-labelMono` : ``}`, r = t.controlId === void 0 ? (0, react.createElement)(`span`, { className: n }, t.label) : (0, react.createElement)(`label`, {
|
|
288
|
+
className: n,
|
|
289
|
+
htmlFor: t.controlId
|
|
290
|
+
}, t.label);
|
|
291
|
+
return (0, react.createElement)(`div`, { className: `dsu-labelRow` }, r, t.detail === void 0 ? null : (0, react.createElement)(m, {
|
|
292
|
+
label: t.label,
|
|
293
|
+
detail: t.detail,
|
|
294
|
+
showLabel: !1
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
function g(t) {
|
|
298
|
+
let n = t.controlId === void 0 ? void 0 : `${t.controlId}-hint`;
|
|
299
|
+
return (0, react.createElement)(`div`, { className: `dsu-field${t.wide === !0 ? ` dsu-fieldWide` : ``}` }, (0, react.createElement)(`div`, { className: `dsu-fieldMeta` }, (0, react.createElement)(h, {
|
|
300
|
+
label: t.label,
|
|
301
|
+
detail: t.detail,
|
|
302
|
+
compact: t.compact,
|
|
303
|
+
controlId: t.controlId
|
|
304
|
+
}), t.hint === void 0 ? null : (0, react.createElement)(`p`, {
|
|
305
|
+
className: `dsu-hint`,
|
|
306
|
+
id: n
|
|
307
|
+
}, t.hint)), (0, react.createElement)(`div`, { className: `dsu-control` }, t.children));
|
|
308
|
+
}
|
|
309
|
+
function _(t) {
|
|
310
|
+
let n = (0, react.useId)(), i = t.hint === void 0 ? void 0 : `${n}-hint`;
|
|
311
|
+
return (0, react.createElement)(g, {
|
|
312
|
+
...t,
|
|
313
|
+
controlId: n
|
|
314
|
+
}, (0, react.createElement)(`button`, {
|
|
315
|
+
type: `button`,
|
|
316
|
+
role: `switch`,
|
|
317
|
+
id: n,
|
|
318
|
+
className: `dsu-switch`,
|
|
319
|
+
"aria-checked": t.checked,
|
|
320
|
+
"aria-describedby": i,
|
|
321
|
+
"data-field": t.field,
|
|
322
|
+
disabled: t.disabled === !0,
|
|
323
|
+
onClick: () => {
|
|
324
|
+
t.onChange(!t.checked);
|
|
325
|
+
}
|
|
326
|
+
}, (0, react.createElement)(`span`, { className: `dsu-knob` })));
|
|
327
|
+
}
|
|
328
|
+
function v(t) {
|
|
329
|
+
let i = typeof t.value == `number` && Number.isFinite(t.value) ? String(t.value) : ``, [a, c] = (0, react.useState)(i), [l, u] = (0, react.useState)(!1), d = (0, react.useRef)(void 0), f = (0, react.useId)(), p = (0, react.useId)(), m = [t.hint === void 0 ? void 0 : `${f}-hint`, l ? p : void 0].filter((e) => e !== void 0), h = m.length === 0 ? void 0 : m.join(` `);
|
|
330
|
+
(0, react.useEffect)(() => {
|
|
331
|
+
t.value !== d.current && (d.current = t.value, c(i), u(!1));
|
|
332
|
+
}, [t.value, i]);
|
|
333
|
+
let _ = (e) => {
|
|
334
|
+
let n = t.min ?? -1 / 0, r = t.max ?? 1 / 0;
|
|
335
|
+
if (!Number.isFinite(e) || e < n || e > r) return !1;
|
|
336
|
+
let { step: i } = t;
|
|
337
|
+
if (i === void 0 || i <= 0) return !0;
|
|
338
|
+
let a = (e - (t.min ?? 0)) / i;
|
|
339
|
+
return Math.abs(a - Math.round(a)) < 1e-9;
|
|
340
|
+
}, v = (e) => {
|
|
341
|
+
if (c(e), e === ``) {
|
|
342
|
+
u(!1), d.current = void 0, t.onChange(void 0);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
let n = Number(e);
|
|
346
|
+
_(n) ? (u(!1), d.current = n, t.onChange(n)) : u(!0);
|
|
347
|
+
}, y = () => {
|
|
348
|
+
a === `` || l || c(String(Number(a)));
|
|
349
|
+
};
|
|
350
|
+
return (0, react.createElement)(g, {
|
|
351
|
+
...t,
|
|
352
|
+
controlId: f
|
|
353
|
+
}, (0, react.createElement)(`div`, { className: `dsu-numberWrap` }, (0, react.createElement)(`div`, { className: `dsu-number` }, (0, react.createElement)(`input`, {
|
|
354
|
+
className: `dsu-input`,
|
|
355
|
+
type: `number`,
|
|
356
|
+
inputMode: `numeric`,
|
|
357
|
+
id: f,
|
|
358
|
+
value: a,
|
|
359
|
+
min: t.min,
|
|
360
|
+
max: t.max,
|
|
361
|
+
step: t.step,
|
|
362
|
+
placeholder: t.placeholder,
|
|
363
|
+
"aria-invalid": l || void 0,
|
|
364
|
+
"aria-describedby": h,
|
|
365
|
+
"data-field": t.field,
|
|
366
|
+
disabled: t.disabled === !0,
|
|
367
|
+
onChange: (e) => {
|
|
368
|
+
v(e.target.value);
|
|
369
|
+
},
|
|
370
|
+
onBlur: y
|
|
371
|
+
}), t.unit === void 0 ? null : (0, react.createElement)(`span`, { className: `dsu-unit` }, t.unit)), l ? (0, react.createElement)(`p`, {
|
|
372
|
+
className: `dsu-error`,
|
|
373
|
+
id: p
|
|
374
|
+
}, t.invalidHint) : null));
|
|
375
|
+
}
|
|
376
|
+
function y(t) {
|
|
377
|
+
let [i, a] = (0, react.useState)(t.value), [o, c] = (0, react.useState)(!1), l = (0, react.useId)(), u = t.hint === void 0 ? void 0 : `${l}-hint`;
|
|
378
|
+
(0, react.useEffect)(() => {
|
|
379
|
+
o || a(t.value);
|
|
380
|
+
}, [t.value, o]);
|
|
381
|
+
let d = {
|
|
382
|
+
id: l,
|
|
383
|
+
className: `dsu-input${t.multiline === !0 ? ` dsu-textarea` : ``}${t.monospace === !0 ? ` dsu-mono` : ``}`,
|
|
384
|
+
value: i,
|
|
385
|
+
placeholder: t.placeholder,
|
|
386
|
+
"aria-describedby": u,
|
|
387
|
+
"data-field": t.field,
|
|
388
|
+
disabled: t.disabled === !0,
|
|
389
|
+
onFocus: () => {
|
|
390
|
+
c(!0);
|
|
391
|
+
},
|
|
392
|
+
onBlur: () => {
|
|
393
|
+
c(!1);
|
|
394
|
+
},
|
|
395
|
+
onChange: (e) => {
|
|
396
|
+
a(e.target.value), t.onChange(e.target.value);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
return (0, react.createElement)(g, {
|
|
400
|
+
...t,
|
|
401
|
+
controlId: l
|
|
402
|
+
}, t.multiline === !0 ? (0, react.createElement)(`textarea`, d) : (0, react.createElement)(`input`, d));
|
|
403
|
+
}
|
|
404
|
+
function x(c) {
|
|
405
|
+
let [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(0), p = (0, react.useRef)(null), m = (0, react.useRef)(null), h = (0, react.useId)(), _ = (0, react.useId)(), v = c.hint === void 0 ? void 0 : `${_}-hint`, { disabled: y, value: b, options: x, onChange: S } = c, C = (0, react.useMemo)(() => x.map((e, t) => ({
|
|
406
|
+
option: e,
|
|
407
|
+
index: t
|
|
408
|
+
})).filter((e) => e.option.disabled !== !0), [x]), w = x.find((e) => e.value === b)?.label ?? b, T = x[d], E = T !== void 0 && T.disabled !== !0, D = (0, react.useCallback)(() => {
|
|
409
|
+
let e = p.current, t = m.current;
|
|
410
|
+
/* v8 ignore next 3 -- place 只在 open 的 layout effect 里调用;refs 为空只可能是卸载竞态 */
|
|
411
|
+
if (e === null || t === null) return;
|
|
412
|
+
let n = e.getBoundingClientRect(), r = Math.min(n.width, window.innerWidth - 16), { left: i } = n;
|
|
413
|
+
i + r > window.innerWidth - 8 && (i = window.innerWidth - r - 8);
|
|
414
|
+
let a = t.offsetHeight, o = n.bottom + 6;
|
|
415
|
+
o + a > window.innerHeight - 8 && (o = n.top - a - 6);
|
|
416
|
+
let s = Math.max(8, window.innerWidth - r - 8), c = Math.max(8, window.innerHeight - a - 8);
|
|
417
|
+
t.style.width = `${r}px`, t.style.left = `${Math.min(Math.max(8, i), s)}px`, t.style.top = `${Math.min(Math.max(8, o), c)}px`;
|
|
418
|
+
}, []), O = (0, react.useCallback)(() => {
|
|
419
|
+
u(!1);
|
|
420
|
+
}, []), k = (0, react.useCallback)(() => {
|
|
421
|
+
if (y === !0) return;
|
|
422
|
+
let e = C.find((e) => e.option.value === b) ?? C.at(0);
|
|
423
|
+
e !== void 0 && (f(e.index), u(!0));
|
|
424
|
+
}, [
|
|
425
|
+
y,
|
|
426
|
+
b,
|
|
427
|
+
C
|
|
428
|
+
]), A = (0, react.useCallback)((e) => {
|
|
429
|
+
/* v8 ignore next 3 -- 浮层只能经由 openMenu 打开;组件禁用时打不开 */
|
|
430
|
+
if (y === !0) return;
|
|
431
|
+
let t = x[e];
|
|
432
|
+
/* v8 ignore next 3 -- disabled 选项在浏览器里不派发 click;越界下标由调用面保证 */
|
|
433
|
+
t !== void 0 && t.disabled !== !0 && (S(t.value), O(), p.current?.focus());
|
|
434
|
+
}, [
|
|
435
|
+
y,
|
|
436
|
+
x,
|
|
437
|
+
S,
|
|
438
|
+
O
|
|
439
|
+
]), j = (0, react.useCallback)((e) => {
|
|
440
|
+
let t = C.findIndex((e) => e.index === d);
|
|
441
|
+
/* v8 ignore next 5 -- open 时归一 effect 已保证 enabled 非空且 active 落在可用项上 */
|
|
442
|
+
if (t === -1 || C.length === 0) return;
|
|
443
|
+
let n = (t + e + C.length) % C.length, r = C[n];
|
|
444
|
+
/* v8 ignore next 3 -- next 由取模保证在界内 */
|
|
445
|
+
r !== void 0 && f(r.index);
|
|
446
|
+
}, [d, C]);
|
|
447
|
+
(0, react.useLayoutEffect)(() => {
|
|
448
|
+
if (!l) return () => {};
|
|
449
|
+
D();
|
|
450
|
+
let e = (e) => {
|
|
451
|
+
let t = e.target;
|
|
452
|
+
m.current?.contains(t) !== !0 && p.current?.contains(t) !== !0 && O();
|
|
453
|
+
}, t = (e) => {
|
|
454
|
+
let { target: t } = e;
|
|
455
|
+
t instanceof Node && m.current?.contains(t) === !0 || O();
|
|
456
|
+
}, n = () => {
|
|
457
|
+
D();
|
|
458
|
+
};
|
|
459
|
+
return document.addEventListener(`pointerdown`, e, !0), window.addEventListener(`scroll`, t, !0), window.addEventListener(`resize`, n), () => {
|
|
460
|
+
document.removeEventListener(`pointerdown`, e, !0), window.removeEventListener(`scroll`, t, !0), window.removeEventListener(`resize`, n);
|
|
461
|
+
};
|
|
462
|
+
}, [
|
|
463
|
+
l,
|
|
464
|
+
c.options,
|
|
465
|
+
D,
|
|
466
|
+
O
|
|
467
|
+
]), (0, react.useEffect)(() => {
|
|
468
|
+
if (!l) return;
|
|
469
|
+
if (y === !0 || C.length === 0) {
|
|
470
|
+
O();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (C.some((e) => e.index === d)) return;
|
|
474
|
+
let e = C.find((e) => e.option.value === b) ?? C.at(0);
|
|
475
|
+
/* v8 ignore next 3 -- enabled 非空在上一分支已保证 */
|
|
476
|
+
e !== void 0 && f(e.index);
|
|
477
|
+
}, [
|
|
478
|
+
l,
|
|
479
|
+
y,
|
|
480
|
+
b,
|
|
481
|
+
x,
|
|
482
|
+
d,
|
|
483
|
+
O,
|
|
484
|
+
C
|
|
485
|
+
]), (0, react.useLayoutEffect)(() => {
|
|
486
|
+
if (!l) return;
|
|
487
|
+
let e = m.current;
|
|
488
|
+
/* v8 ignore next 2 -- 同上,menu 在 open 的 commit 之后必然已挂上 */
|
|
489
|
+
if (e === null) return;
|
|
490
|
+
let t = e.querySelector(`[data-active="true"]`);
|
|
491
|
+
/* v8 ignore next 2 -- active 已由归一 effect 保证落在可用项上 */
|
|
492
|
+
t !== null && (t.offsetTop < e.scrollTop ? e.scrollTop = t.offsetTop : t.offsetTop + t.offsetHeight > e.scrollTop + e.clientHeight && (e.scrollTop = t.offsetTop + t.offsetHeight - e.clientHeight));
|
|
493
|
+
}, [
|
|
494
|
+
l,
|
|
495
|
+
d,
|
|
496
|
+
x
|
|
497
|
+
]);
|
|
498
|
+
let M = (e) => {
|
|
499
|
+
if (e.key === `ArrowDown` || e.key === `ArrowUp`) {
|
|
500
|
+
if (e.preventDefault(), !l) {
|
|
501
|
+
k();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
j(e.key === `ArrowDown` ? 1 : -1);
|
|
505
|
+
} else if (e.key === `Home` || e.key === `End`) {
|
|
506
|
+
if (e.preventDefault(), l || k(), C.length === 0) return;
|
|
507
|
+
let t = e.key === `Home` ? C.at(0) : C.at(-1);
|
|
508
|
+
/* v8 ignore next 3 -- enabled 为空已在上一条返回 */
|
|
509
|
+
if (t === void 0) return;
|
|
510
|
+
f(t.index);
|
|
511
|
+
} else if (e.key === `Enter` || e.key === ` `) {
|
|
512
|
+
if (e.preventDefault(), !l) {
|
|
513
|
+
k();
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
A(d);
|
|
517
|
+
} else (e.key === `Tab` || e.key === `Escape`) && O();
|
|
518
|
+
}, N = [], P;
|
|
519
|
+
for (let [t, n] of x.entries()) n.group !== P && (n.group !== void 0 && N.push((0, react.createElement)(`div`, {
|
|
520
|
+
key: `group-${t}-${n.group}`,
|
|
521
|
+
className: `dsu-optionGroup`,
|
|
522
|
+
role: `presentation`
|
|
523
|
+
}, n.group)), P = n.group), N.push((0, react.createElement)(`button`, {
|
|
524
|
+
key: `option-${n.value}`,
|
|
525
|
+
type: `button`,
|
|
526
|
+
role: `option`,
|
|
527
|
+
id: `${h}-${t}`,
|
|
528
|
+
className: `dsu-option`,
|
|
529
|
+
tabIndex: -1,
|
|
530
|
+
"aria-selected": n.value === c.value,
|
|
531
|
+
"data-active": t === d,
|
|
532
|
+
disabled: n.disabled === !0,
|
|
533
|
+
onMouseDown: (e) => {
|
|
534
|
+
e.preventDefault();
|
|
535
|
+
},
|
|
536
|
+
onClick: () => {
|
|
537
|
+
A(t);
|
|
538
|
+
},
|
|
539
|
+
onMouseEnter: () => {
|
|
540
|
+
/* v8 ignore next -- happy-dom 对 disabled 元素不派发 mouse 事件;浏览器实现各有差异,保留禁用检查 */
|
|
541
|
+
n.disabled !== !0 && f(t);
|
|
542
|
+
}
|
|
543
|
+
}, (0, react.createElement)(`span`, null, n.label), (0, react.createElement)(`svg`, {
|
|
544
|
+
className: `dsu-check`,
|
|
545
|
+
width: 14,
|
|
546
|
+
height: 14,
|
|
547
|
+
viewBox: `0 0 14 14`,
|
|
548
|
+
"aria-hidden": !0
|
|
549
|
+
}, (0, react.createElement)(`path`, {
|
|
550
|
+
d: `M2.5 7.5l3 3 6-7`,
|
|
551
|
+
fill: `none`,
|
|
552
|
+
stroke: `currentColor`,
|
|
553
|
+
strokeWidth: 1.5,
|
|
554
|
+
strokeLinecap: `round`,
|
|
555
|
+
strokeLinejoin: `round`
|
|
556
|
+
}))));
|
|
557
|
+
return (0, react.createElement)(g, {
|
|
558
|
+
...c,
|
|
559
|
+
controlId: _
|
|
560
|
+
}, (0, react.createElement)(`div`, {
|
|
561
|
+
className: `dsu-selectWrap`,
|
|
562
|
+
onBlur: (e) => {
|
|
563
|
+
let t = e.relatedTarget;
|
|
564
|
+
t instanceof Node && e.currentTarget.contains(t) || O();
|
|
565
|
+
}
|
|
566
|
+
}, (0, react.createElement)(`button`, {
|
|
567
|
+
ref: p,
|
|
568
|
+
type: `button`,
|
|
569
|
+
id: _,
|
|
570
|
+
className: `dsu-select dsu-input`,
|
|
571
|
+
role: `combobox`,
|
|
572
|
+
"aria-haspopup": `listbox`,
|
|
573
|
+
"aria-expanded": l,
|
|
574
|
+
"aria-controls": `${h}-list`,
|
|
575
|
+
"aria-activedescendant": l && E ? `${h}-${d}` : void 0,
|
|
576
|
+
"aria-describedby": v,
|
|
577
|
+
"data-field": c.field,
|
|
578
|
+
disabled: y === !0 || x.length === 0,
|
|
579
|
+
onClick: () => {
|
|
580
|
+
l ? O() : k();
|
|
581
|
+
},
|
|
582
|
+
onKeyDown: M
|
|
583
|
+
}, (0, react.createElement)(`span`, { className: `dsu-selectValue` }, w), (0, react.createElement)(`svg`, {
|
|
584
|
+
className: `dsu-chevron`,
|
|
585
|
+
width: 14,
|
|
586
|
+
height: 14,
|
|
587
|
+
viewBox: `0 0 14 14`,
|
|
588
|
+
"aria-hidden": !0
|
|
589
|
+
}, (0, react.createElement)(`path`, {
|
|
590
|
+
d: `M3 5l4 4 4-4`,
|
|
591
|
+
fill: `none`,
|
|
592
|
+
stroke: `currentColor`,
|
|
593
|
+
strokeWidth: 1.5,
|
|
594
|
+
strokeLinecap: `round`,
|
|
595
|
+
strokeLinejoin: `round`
|
|
596
|
+
}))), (0, react.createElement)(`div`, {
|
|
597
|
+
ref: m,
|
|
598
|
+
id: `${h}-list`,
|
|
599
|
+
role: `listbox`,
|
|
600
|
+
className: `dsu-menu`,
|
|
601
|
+
"aria-label": c.label,
|
|
602
|
+
hidden: !l
|
|
603
|
+
}, ...N)));
|
|
604
|
+
}
|
|
605
|
+
function S(t) {
|
|
606
|
+
let n = !t.writable || t.busy || !t.dirty, r;
|
|
607
|
+
return r = t.error === null ? t.writable ? t.dirty ? t.dirtyLabel : t.cleanLabel : t.readOnlyLabel : t.error, (0, react.createElement)(`div`, {
|
|
608
|
+
className: `dsu-savebar`,
|
|
609
|
+
"data-dirty": t.dirty
|
|
610
|
+
}, (0, react.createElement)(`button`, {
|
|
611
|
+
type: `button`,
|
|
612
|
+
className: `dsu-btn dsu-btnPrimary`,
|
|
613
|
+
"data-field": `save`,
|
|
614
|
+
disabled: n,
|
|
615
|
+
onClick: t.onSave
|
|
616
|
+
}, t.busy ? t.savingLabel : t.saveLabel), (0, react.createElement)(`button`, {
|
|
617
|
+
type: `button`,
|
|
618
|
+
className: `dsu-btn`,
|
|
619
|
+
"data-field": `discard`,
|
|
620
|
+
disabled: n,
|
|
621
|
+
onClick: t.onDiscard
|
|
622
|
+
}, t.revertLabel), (0, react.createElement)(`span`, { className: t.error === null ? `dsu-status` : `dsu-status dsu-statusError` }, r));
|
|
623
|
+
}
|
|
100
624
|
// lib/card-draft.ts
|
|
101
625
|
/** 草稿优先取值:touched 有该键(哪怕值是 undefined=待清空)即用草稿。
|
|
102
|
-
*
|
|
103
|
-
* `constructor` 这类继承键,把 Object.prototype
|
|
626
|
+
* 两层都只判**自有**属性:本函数收任意字段名,`in`/裸下标会沿原型链命中 `toString` /
|
|
627
|
+
* `constructor` 这类继承键,把 Object.prototype 的成员当成已提交值交出去。 */
|
|
628
|
+
function hasDraft(touched, field) {
|
|
629
|
+
return Object.hasOwn(touched, field);
|
|
630
|
+
}
|
|
104
631
|
function draftOf(touched, value, field) {
|
|
105
|
-
|
|
632
|
+
if (hasDraft(touched, field)) return touched[field];
|
|
633
|
+
return Object.hasOwn(value, field) ? value[field] : void 0;
|
|
106
634
|
}
|
|
107
635
|
/** 数值型输入的显示文本:非有限数(含 undefined)回落到默认文案。 */
|
|
108
636
|
function numberText(raw, fallback) {
|
|
@@ -156,80 +684,62 @@ function cardStore(scope) {
|
|
|
156
684
|
/**
|
|
157
685
|
* 三个数值字段的显示值都是「草稿优先 + 默认文案」,且共享同一条清空语义:
|
|
158
686
|
* touched 里显式写了 undefined(用户清空输入)= 待 unset,显示空串;「从没动过、
|
|
159
|
-
*
|
|
160
|
-
*
|
|
687
|
+
* 快照里也没有」不是清空,显示默认文案。判据统一收在这里,与卡片数值控件
|
|
688
|
+
* (numberDisplay / NumberField)的「清空即回『未填』」对齐。
|
|
161
689
|
*/
|
|
162
690
|
function numericFieldDisplay(touched, value, field, fallback) {
|
|
163
691
|
const draft = draftOf(touched, value, field);
|
|
164
|
-
if (draft === void 0) return
|
|
692
|
+
if (draft === void 0) return hasDraft(touched, field) ? "" : fallback;
|
|
165
693
|
return numberText(draft, fallback);
|
|
166
694
|
}
|
|
695
|
+
/** 已提交端点值只收 HTTP(S);坏文本显示成空(输入框里键入的草稿不走这条过滤)。 */
|
|
696
|
+
const HTTP_URL_SCHEMA = zod.z.url({ protocol: /^https?$/u });
|
|
697
|
+
/**
|
|
698
|
+
* 端点字段的显示值:**草稿优先**,与三个数值字段同一条清空语义。
|
|
699
|
+
*
|
|
700
|
+
* 用户正在逐字键入时,草稿是「这一格此刻的文本」而不是待校验的值——半截 URL
|
|
701
|
+
* 必须原样回显,否则输入第一个字符就被过滤成空串、删掉已提交 URL 的一个字符就整格清空。
|
|
702
|
+
* 只有「这一格没动过、显示的是已提交快照」时才过 HTTP(S) 形态过滤:脏快照不该显示成
|
|
703
|
+
* 一个看起来能保存的地址。
|
|
704
|
+
*/
|
|
705
|
+
function endpointFieldDisplay(touched, value) {
|
|
706
|
+
if (Object.hasOwn(touched, "hfEndpoint")) {
|
|
707
|
+
const draft = touched["hfEndpoint"];
|
|
708
|
+
return typeof draft === "string" ? draft : "";
|
|
709
|
+
}
|
|
710
|
+
const committed = value["hfEndpoint"];
|
|
711
|
+
return typeof committed === "string" && HTTP_URL_SCHEMA.safeParse(committed).success ? committed : "";
|
|
712
|
+
}
|
|
167
713
|
/** 六个字段的草稿显示值(ZgCard 只渲染这里算出来的东西)。 */
|
|
168
714
|
function draftFields(touched, value) {
|
|
169
715
|
const embedding = draftOf(touched, value, "defaultEmbedding");
|
|
170
|
-
const endpoint = draftOf(touched, value, "hfEndpoint");
|
|
171
716
|
const enforce = draftOf(touched, value, "enforceSearchFirst");
|
|
172
717
|
return {
|
|
173
718
|
embedding: typeof embedding === "string" && embedding.length > 0 ? embedding : DEFAULT_EMBEDDING,
|
|
174
719
|
limitDisplay: numericFieldDisplay(touched, value, "defaultLimit", String(10)),
|
|
175
|
-
hfEndpoint:
|
|
720
|
+
hfEndpoint: endpointFieldDisplay(touched, value),
|
|
176
721
|
enforceSearchFirst: enforce !== false,
|
|
177
722
|
grepBudget: numericFieldDisplay(touched, value, "grepBudgetPerSearch", String(3)),
|
|
178
723
|
unlockWindow: numericFieldDisplay(touched, value, "unlockWindowMin", String(10))
|
|
179
724
|
};
|
|
180
725
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
value: 1
|
|
199
|
-
})
|
|
200
|
-
};
|
|
201
|
-
if (num > 50) return {
|
|
202
|
-
kind: "clamped",
|
|
203
|
-
value: 50,
|
|
204
|
-
hint: t("limitClamped", {
|
|
205
|
-
min: 1,
|
|
206
|
-
max: 50,
|
|
207
|
-
value: 50
|
|
208
|
-
})
|
|
209
|
-
};
|
|
210
|
-
return {
|
|
211
|
-
kind: "valid",
|
|
212
|
-
value: num
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function limitDraftOf(raw, t) {
|
|
216
|
-
const resolution = resolveLimitInput(raw, t);
|
|
217
|
-
if (resolution.kind === "invalid") return {
|
|
218
|
-
draft: void 0,
|
|
219
|
-
error: resolution.hint,
|
|
220
|
-
hint: null
|
|
221
|
-
};
|
|
222
|
-
if (resolution.kind === "empty") return {
|
|
223
|
-
draft: void 0,
|
|
224
|
-
error: null,
|
|
225
|
-
hint: null
|
|
226
|
-
};
|
|
227
|
-
return {
|
|
228
|
-
draft: resolution.value,
|
|
229
|
-
error: null,
|
|
230
|
-
hint: resolution.kind === "clamped" ? resolution.hint : null
|
|
231
|
-
};
|
|
232
|
-
}
|
|
726
|
+
const LIMIT_SCHEMA = zod.z.int().min(1).max(50);
|
|
727
|
+
const BUDGET_SCHEMA = zod.z.int().min(1).max(20);
|
|
728
|
+
const WINDOW_SCHEMA = zod.z.int().min(1).max(240);
|
|
729
|
+
/** 轮询应答的宽容形状:未知状态、非数字退出码、非字符串输出都折成缺位,
|
|
730
|
+
* 下游文案只按“缺位”兜底,不把坏类型带到渲染期。 */
|
|
731
|
+
const REBUILD_STATUSES = [
|
|
732
|
+
"running",
|
|
733
|
+
"stopping",
|
|
734
|
+
"completed",
|
|
735
|
+
"killed",
|
|
736
|
+
"failed"
|
|
737
|
+
];
|
|
738
|
+
const REBUILD_POLL_SCHEMA = zod.z.object({
|
|
739
|
+
status: zod.z.preprocess((value) => typeof value === "string" && REBUILD_STATUSES.some((status) => status === value) ? value : void 0, zod.z.enum(REBUILD_STATUSES).optional()),
|
|
740
|
+
exitCode: zod.z.preprocess((value) => typeof value === "number" && Number.isFinite(value) ? value : void 0, zod.z.number().optional()),
|
|
741
|
+
output: zod.z.preprocess((value) => typeof value === "string" ? value : void 0, zod.z.string().optional())
|
|
742
|
+
});
|
|
233
743
|
/**
|
|
234
744
|
* 轮询应答 → 卡片状态。
|
|
235
745
|
* 关键:harness 的 bash-local 对**任何自然退出**都置 `status:'completed'`
|
|
@@ -241,8 +751,9 @@ function limitDraftOf(raw, t) {
|
|
|
241
751
|
* - `failed`:注册表侧判定失败(生产者的 done 被拒、或收尾抛错),此时没有退出码可读。
|
|
242
752
|
*/
|
|
243
753
|
function parseRebuildPoll(body, t) {
|
|
244
|
-
const
|
|
245
|
-
const
|
|
754
|
+
const parsed = REBUILD_POLL_SCHEMA.safeParse(body);
|
|
755
|
+
const { status, exitCode, output } = parsed.success ? parsed.data : {};
|
|
756
|
+
const outputText = output ?? "";
|
|
246
757
|
if (status === "running" || status === "stopping") return {
|
|
247
758
|
phase: "running",
|
|
248
759
|
output: outputText.length > 0 ? outputText : t("rebuildRunning")
|
|
@@ -272,6 +783,14 @@ const REBUILD_NAMESPACE = "zvecGrepRebuild";
|
|
|
272
783
|
const REBUILD_SERVICE_KEY = `remote.${REBUILD_NAMESPACE}`;
|
|
273
784
|
/** 卡片所在 bundle 的包名(`$mount` 的 `package` 位与槽位键同源,见 client-entry.ts 的 BUNDLE_PKG)。 */
|
|
274
785
|
const PACKAGE_NAME = "@jayyuen66/dsh-zvec-grep";
|
|
786
|
+
/** strict codec 的统一出口:失败交给 zod 的 `prettifyError`,读到的是一份带字段路径的说明。 */
|
|
787
|
+
function parseOrThrow(schema, value) {
|
|
788
|
+
const parsed = schema.safeParse(value);
|
|
789
|
+
if (!parsed.success) throw new TypeError(zod.z.prettifyError(parsed.error));
|
|
790
|
+
return parsed.data;
|
|
791
|
+
}
|
|
792
|
+
const START_SCHEMA = zod.z.object({ root: zod.z.string({ error: "rebuild request requires a string root" }).trim().min(1, { error: "rebuild request requires a non-empty root" }) }, { error: "rebuild request requires a string root" });
|
|
793
|
+
const STATUS_SCHEMA = zod.z.object({ jobId: zod.z.string({ error: "rebuild status request requires a string jobId" }).trim().min(1, { error: "rebuild status request requires a non-empty jobId" }) }, { error: "rebuild status request requires a string jobId" });
|
|
275
794
|
/** 把宿主那三个方法挂到客户端远程面上的描述符(`id` 的形状照生成器:`<包>#<命名空间>/<方法>`)。
|
|
276
795
|
* 导出它只为一件事:`test/rebuild-remote.test.ts` 拿它与宿主侧 `remoteMethods()` 的标记对质
|
|
277
796
|
* —— 两侧分叉时卡片不会报错,只会"读不到",所以那条比较必须在门禁里。 */
|
|
@@ -299,8 +818,7 @@ const REBUILD_DESCRIPTORS = [
|
|
|
299
818
|
mode: "strict",
|
|
300
819
|
typeSymbol: `${PACKAGE_NAME}#rebuild-request`,
|
|
301
820
|
create: () => ({ parse(value) {
|
|
302
|
-
|
|
303
|
-
return { root: value["root"] };
|
|
821
|
+
return parseOrThrow(START_SCHEMA, value);
|
|
304
822
|
} })
|
|
305
823
|
}
|
|
306
824
|
}],
|
|
@@ -320,8 +838,7 @@ const REBUILD_DESCRIPTORS = [
|
|
|
320
838
|
mode: "strict",
|
|
321
839
|
typeSymbol: `${PACKAGE_NAME}#rebuild-status-request`,
|
|
322
840
|
create: () => ({ parse(value) {
|
|
323
|
-
|
|
324
|
-
return { jobId: value["jobId"] };
|
|
841
|
+
return parseOrThrow(STATUS_SCHEMA, value);
|
|
325
842
|
} })
|
|
326
843
|
}
|
|
327
844
|
}],
|
|
@@ -361,7 +878,7 @@ function buildRebuildReader(ctx) {
|
|
|
361
878
|
mounted = void 0;
|
|
362
879
|
throw error;
|
|
363
880
|
}
|
|
364
|
-
const namespace = ctx.get?.(REBUILD_SERVICE_KEY
|
|
881
|
+
const namespace = ctx.get?.(REBUILD_SERVICE_KEY);
|
|
365
882
|
if (!isRebuildNamespace(namespace)) throw new Error(`${REBUILD_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
|
|
366
883
|
return namespace;
|
|
367
884
|
};
|
|
@@ -398,31 +915,34 @@ function createRebuildReader(ctx) {
|
|
|
398
915
|
// src/ui-messages.ts
|
|
399
916
|
const UI_MESSAGES = {
|
|
400
917
|
zh: {
|
|
401
|
-
cardTitle: "zvec-grep(zg)",
|
|
402
|
-
cardDescription: "工作区语义检索:zg_search / zg_index / zg_status;本地 embedding + BM25 + 向量 RRF",
|
|
403
918
|
statusReadOnly: "当前作用域只读",
|
|
404
919
|
statusDirty: "有未保存的修改,点「保存」生效",
|
|
405
920
|
statusClean: "无未保存的修改",
|
|
921
|
+
dirtyCount: "已修改 {count} 项",
|
|
406
922
|
save: "保存",
|
|
407
923
|
saving: "保存中…",
|
|
408
924
|
revert: "撤销",
|
|
409
925
|
saveFailed: "保存失败:{reason}",
|
|
410
926
|
saveRejected: "保存被宿主拒绝(配置校验未通过或写入被跳过),修改未生效",
|
|
927
|
+
modelSection: "检索模型",
|
|
928
|
+
indexSection: "网络与索引",
|
|
929
|
+
unitResults: "条",
|
|
930
|
+
unitTimes: "次",
|
|
931
|
+
unitMinutes: "分钟",
|
|
932
|
+
outOfRange: "超出允许范围,未保存",
|
|
411
933
|
embeddingLabel: "默认本地 embedding",
|
|
412
934
|
embeddingHint: "只影响「新建」索引;切换并保存后,已有索引需点下方「重建」重新 embedding",
|
|
413
|
-
limitLabel: "
|
|
935
|
+
limitLabel: "默认每组结果数",
|
|
414
936
|
limitInvalid: "请输入 {min}-{max} 的整数",
|
|
415
937
|
limitClamped: "已钳到 {min}-{max} 范围:{value}",
|
|
416
|
-
endpointLabel: "HuggingFace
|
|
938
|
+
endpointLabel: "HuggingFace 镜像地址",
|
|
417
939
|
endpointHint: "留空走 huggingface.co;国内网络可填 https://modelscope.cn/models 等兼容镜像(仅 llama-cpp 后端生效,如 qwen3)",
|
|
418
940
|
enforceLabel: "强制 search-first(先 zg_search 再 grep/rg)",
|
|
419
941
|
enforceHint: "开启后,已建索引工作区内的 grep/rg 受配额门禁约束:每次成功 zg_search 解锁下方次数的 grep/rg(时效见下),用尽或过期后再次拦截(提高检索覆盖与准确性)",
|
|
420
|
-
budgetLabel: "每次 zg_search 解锁的 grep/rg
|
|
942
|
+
budgetLabel: "每次 zg_search 解锁的 grep/rg 次数",
|
|
421
943
|
budgetHint: "配额越小语义检索越频繁、准确性约束越强;清空恢复默认 {default}",
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
windowHint: "超过该时长未再次 zg_search,配额整体过期;清空恢复默认 {default}",
|
|
425
|
-
windowInvalid: "解锁时效必须是 {min}-{max} 的整数",
|
|
944
|
+
windowLabel: "解锁时效",
|
|
945
|
+
windowHint: "超过该时长未再次 zg_search,配额整体过期;清空恢复默认 {default}(单位:分钟)",
|
|
426
946
|
rebuildLabel: "工作区重建(切换 embedding 并保存后执行)",
|
|
427
947
|
daemonReadyNote: "守护进程:就绪(zg server 在跑)。",
|
|
428
948
|
daemonOfflineNote: "守护进程:未就绪。守护进程提供的索引增量刷新、refresh=background 与常驻模型池在缺席时都不可用;需要时在终端执行 `zg server on`。",
|
|
@@ -446,31 +966,34 @@ const UI_MESSAGES = {
|
|
|
446
966
|
backendModel2Vec: "model2vec(纯 JS worker,最轻)"
|
|
447
967
|
},
|
|
448
968
|
en: {
|
|
449
|
-
cardTitle: "zvec-grep (zg)",
|
|
450
|
-
cardDescription: "Workspace semantic search: zg_search / zg_index / zg_status; local embedding + BM25 + vector RRF",
|
|
451
969
|
statusReadOnly: "This scope is read-only",
|
|
452
970
|
statusDirty: "Unsaved changes — press Save to apply",
|
|
453
971
|
statusClean: "No unsaved changes",
|
|
972
|
+
dirtyCount: "{count} changed",
|
|
454
973
|
save: "Save",
|
|
455
974
|
saving: "Saving…",
|
|
456
975
|
revert: "Revert",
|
|
457
976
|
saveFailed: "save failed: {reason}",
|
|
458
977
|
saveRejected: "save rejected by host (validation failed or write skipped) — changes not applied",
|
|
978
|
+
modelSection: "Retrieval model",
|
|
979
|
+
indexSection: "Network and index",
|
|
980
|
+
unitResults: "hits",
|
|
981
|
+
unitTimes: "times",
|
|
982
|
+
unitMinutes: "minutes",
|
|
983
|
+
outOfRange: "Out of the allowed range — not saved",
|
|
459
984
|
embeddingLabel: "Default local embedding",
|
|
460
985
|
embeddingHint: "Affects newly built indexes only; after switching and saving, press Rebuild below to re-embed existing indexes",
|
|
461
|
-
limitLabel: "Default hits per group
|
|
986
|
+
limitLabel: "Default hits per group",
|
|
462
987
|
limitInvalid: "enter an integer between {min} and {max}",
|
|
463
988
|
limitClamped: "clamped into the {min}-{max} range: {value}",
|
|
464
|
-
endpointLabel: "HuggingFace mirror URL
|
|
989
|
+
endpointLabel: "HuggingFace mirror URL",
|
|
465
990
|
endpointHint: "Leave empty for huggingface.co; on networks that cannot reach HF, fill a compatible mirror such as https://modelscope.cn/models (llama-cpp backends only, e.g. qwen3)",
|
|
466
991
|
enforceLabel: "Enforce search-first (zg_search before grep/rg)",
|
|
467
992
|
enforceHint: "When on, grep/rg inside indexed workspaces is quota-gated: each successful zg_search unlocks the number of grep/rg calls below (valid for the window below), and the gate blocks again once it is spent or expired (better coverage and relevance)",
|
|
468
|
-
budgetLabel: "grep/rg calls unlocked per zg_search
|
|
993
|
+
budgetLabel: "grep/rg calls unlocked per zg_search",
|
|
469
994
|
budgetHint: "A smaller quota means more semantic searches and a stronger relevance constraint; clear to restore the default {default}",
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
windowHint: "Without another zg_search inside this window the whole quota expires; clear to restore the default {default}",
|
|
473
|
-
windowInvalid: "the unlock window must be an integer between {min} and {max}",
|
|
995
|
+
windowLabel: "Unlock window",
|
|
996
|
+
windowHint: "Without another zg_search inside this window the whole quota expires; clear to restore the default {default} (minutes)",
|
|
474
997
|
rebuildLabel: "Workspace rebuild (run after switching embedding and saving)",
|
|
475
998
|
daemonReadyNote: "Daemon: ready (zg server is running).",
|
|
476
999
|
daemonOfflineNote: "Daemon: not ready. What the daemon provides — incremental index refresh, refresh=background and the resident embedding model pool — is unavailable while it is absent; run `zg server on` in a terminal when you want it.",
|
|
@@ -543,44 +1066,15 @@ const BUNDLE_PKG = "@jayyuen66/dsh-zvec-grep";
|
|
|
543
1066
|
/** 重建轮询间隔(宿主后台进程,2s 足够跟上 zg 的进度输出)。 */
|
|
544
1067
|
const REBUILD_POLL_MS = 2e3;
|
|
545
1068
|
const CARD_CSS = [
|
|
546
|
-
".zgc-
|
|
547
|
-
".zgc-
|
|
548
|
-
".zgc-
|
|
549
|
-
".zgc-card-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}",
|
|
550
|
-
".zgc-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}",
|
|
551
|
-
".zgc-card-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}",
|
|
552
|
-
".zgc-card-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}",
|
|
553
|
-
".zgc-card-desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
|
|
554
|
-
".zgc-card-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}",
|
|
555
|
-
".zgc-card-chevron-open{transform:rotate(180deg)}",
|
|
556
|
-
".zgc-card-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:8px 0 12px}",
|
|
557
|
-
".zgc-row{display:flex;flex-direction:column;gap:6px;padding:9px 0}",
|
|
558
|
-
".zgc-label{font-size:13px;color:var(--dsw-alias-label-primary,inherit)}",
|
|
559
|
-
".zgc-hint{font-size:12px;color:var(--dsw-alias-label-tertiary,#8a8f99)}",
|
|
560
|
-
".zgc-select{width:100%;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l3,#d8dbe2);border-radius:6px;padding:6px 8px;box-sizing:border-box}",
|
|
561
|
-
".zgc-input{width:100%;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l3,#d8dbe2);border-radius:6px;padding:6px 8px;box-sizing:border-box}",
|
|
562
|
-
".zgc-button{appearance:none;border:1px solid var(--dsw-alias-brand-primary,#2f6fed);color:var(--dsw-alias-brand-primary,#2f6fed);background:transparent;border-radius:6px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer}",
|
|
563
|
-
".zgc-button:hover:not(:disabled){background:var(--dsw-alias-fill-secondary,rgba(0,0,0,.05))}",
|
|
564
|
-
".zgc-button:disabled{opacity:.5;cursor:progress}",
|
|
565
|
-
".zgc-output{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,inherit);white-space:pre-wrap;word-break:break-all;max-height:180px;overflow:auto;background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l2);border-radius:6px;padding:8px}",
|
|
566
|
-
".zgc-error{font-size:12px;color:var(--dsw-alias-text-danger,#d33)}",
|
|
567
|
-
".zgc-savebar{display:flex;gap:8px;align-items:center;padding:10px 0 2px;border-top:1px dashed var(--dsw-alias-border-l2);margin-top:6px;flex-wrap:wrap}",
|
|
568
|
-
".zgc-btn-primary{appearance:none;border:1px solid var(--dsw-alias-brand-primary,#2f6fed);background:var(--dsw-alias-brand-primary,#2f6fed);color:var(--dsw-alias-label-primary-foreground,#fff);border-radius:6px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer}",
|
|
569
|
-
".zgc-btn-plain{appearance:none;border:1px solid var(--dsw-alias-border-l2,#d8dbe2);background:transparent;color:var(--dsw-alias-label-primary,inherit);border-radius:6px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer}",
|
|
570
|
-
".zgc-button:focus-visible,.zgc-btn-primary:focus-visible,.zgc-btn-plain:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#2f6fed);outline-offset:1px}",
|
|
571
|
-
".zgc-btn-primary:hover:not(:disabled){filter:brightness(.96)}",
|
|
572
|
-
".zgc-btn-plain:hover:not(:disabled){background:var(--dsw-alias-fill-secondary,rgba(0,0,0,.05))}",
|
|
573
|
-
".zgc-btn-primary:disabled,.zgc-btn-plain:disabled{opacity:.5;cursor:not-allowed}",
|
|
574
|
-
".zgc-dirty{font-size:12px;color:var(--dsw-alias-label-tertiary,#8a8f99)}",
|
|
575
|
-
".zgc-saveerr{font-size:12px;color:var(--dsw-alias-text-danger,#d33)}"
|
|
1069
|
+
".zgc-rebuildInput{flex:1 1 240px;min-width:0}",
|
|
1070
|
+
".zgc-output{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,inherit);white-space:pre-wrap;word-break:break-all;max-height:180px;overflow:auto;background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l2);border-radius:6px;padding:8px;margin-top:8px}",
|
|
1071
|
+
".zgc-error{font-size:12px;color:var(--dsw-alias-text-danger,#d33);margin-top:8px}"
|
|
576
1072
|
].join("\n");
|
|
577
1073
|
const BACKENDS = [
|
|
578
1074
|
"llama-cpp",
|
|
579
1075
|
"transformers-js",
|
|
580
1076
|
"model2vec"
|
|
581
1077
|
];
|
|
582
|
-
/** SVG path 的 data 属性键(id-length 豁免需经变量计算键表达,oxfmt 不解引号)。 */
|
|
583
|
-
const PATH_DATA_KEY = "d";
|
|
584
1078
|
/** 重建 root 输入框的候选列表 id(与 <datalist> 配对)。 */
|
|
585
1079
|
const ROOT_OPTIONS_ID = "zgc-rebuild-root-options";
|
|
586
1080
|
/** 候选按后端分组,供 <optgroup> 使用(文案取自 UI 字典,这里只留键)。 */
|
|
@@ -594,59 +1088,6 @@ const BACKEND_LABEL_KEY = {
|
|
|
594
1088
|
function snapshotValue(snap) {
|
|
595
1089
|
return snap.value;
|
|
596
1090
|
}
|
|
597
|
-
function PluginCard(props) {
|
|
598
|
-
const { title, description, children } = props;
|
|
599
|
-
const [open, setOpen] = (0, react.useState)(false);
|
|
600
|
-
const headInner = (0, react.createElement)("span", { className: "zgc-card-head" }, (0, react.createElement)("span", { className: "zgc-card-name" }, title), (0, react.createElement)("span", { className: "zgc-card-desc" }, description));
|
|
601
|
-
const chevron = (0, react.createElement)("svg", {
|
|
602
|
-
width: 14,
|
|
603
|
-
height: 14,
|
|
604
|
-
viewBox: "0 0 14 14",
|
|
605
|
-
"aria-hidden": true,
|
|
606
|
-
className: open ? "zgc-card-chevron zgc-card-chevron-open" : "zgc-card-chevron"
|
|
607
|
-
}, (0, react.createElement)("path", {
|
|
608
|
-
[PATH_DATA_KEY]: "M3 5l4 4 4-4",
|
|
609
|
-
fill: "none",
|
|
610
|
-
stroke: "currentColor",
|
|
611
|
-
strokeWidth: 1.5,
|
|
612
|
-
strokeLinecap: "round",
|
|
613
|
-
strokeLinejoin: "round"
|
|
614
|
-
}));
|
|
615
|
-
const header = (0, react.createElement)("button", {
|
|
616
|
-
type: "button",
|
|
617
|
-
className: "zgc-card-header",
|
|
618
|
-
"aria-expanded": open,
|
|
619
|
-
onClick: () => {
|
|
620
|
-
setOpen(!open);
|
|
621
|
-
}
|
|
622
|
-
}, headInner, chevron);
|
|
623
|
-
const body = open ? (0, react.createElement)("div", { className: "zgc-card-body" }, children) : null;
|
|
624
|
-
return (0, react.createElement)("li", { className: open ? "zgc-card zgc-card-open" : "zgc-card" }, header, body);
|
|
625
|
-
}
|
|
626
|
-
/** 保存条(全自研插件统一)。 */
|
|
627
|
-
function SaveBar(props) {
|
|
628
|
-
const { t } = props;
|
|
629
|
-
const disabled = !props.writable || props.busy;
|
|
630
|
-
const saveBtn = (0, react.createElement)("button", {
|
|
631
|
-
type: "button",
|
|
632
|
-
className: "zgc-btn-primary",
|
|
633
|
-
"data-field": "save",
|
|
634
|
-
disabled: disabled || !props.dirty,
|
|
635
|
-
onClick: props.onSave
|
|
636
|
-
}, props.busy ? t("saving") : t("save"));
|
|
637
|
-
const discardBtn = (0, react.createElement)("button", {
|
|
638
|
-
type: "button",
|
|
639
|
-
className: "zgc-btn-plain",
|
|
640
|
-
"data-field": "discard",
|
|
641
|
-
disabled: disabled || !props.dirty,
|
|
642
|
-
onClick: props.onDiscard
|
|
643
|
-
}, t("revert"));
|
|
644
|
-
let statusNode;
|
|
645
|
-
if (props.error !== null) statusNode = (0, react.createElement)("span", { className: "zgc-saveerr" }, props.error);
|
|
646
|
-
else if (props.writable) statusNode = (0, react.createElement)("span", { className: "zgc-dirty" }, props.dirty ? t("statusDirty") : t("statusClean"));
|
|
647
|
-
else statusNode = (0, react.createElement)("span", { className: "zgc-dirty" }, t("statusReadOnly"));
|
|
648
|
-
return (0, react.createElement)("div", { className: "zgc-savebar" }, saveBtn, discardBtn, statusNode);
|
|
649
|
-
}
|
|
650
1091
|
/**
|
|
651
1092
|
* embedding 候选项文本(官方 locale 的 {name} 插值)。提成模块级函数是为了不把
|
|
652
1093
|
* t() 嵌进 createElement(unicorn/max-nested-calls 上限 3)。
|
|
@@ -664,149 +1105,65 @@ function rebuildHintText(t, embedding, hasRoots) {
|
|
|
664
1105
|
roots: t(hasRoots ? "rootsNoteWith" : "rootsNoteEmpty")
|
|
665
1106
|
});
|
|
666
1107
|
}
|
|
667
|
-
/**
|
|
668
|
-
function
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
1108
|
+
/** embedding 候选的显示文本与分组(供共享 SelectField 的 options)。 */
|
|
1109
|
+
function embeddingOptions(t) {
|
|
1110
|
+
const options = [];
|
|
1111
|
+
for (const backend of BACKENDS) for (const entry of LOCAL_EMBEDDINGS) if (entry.backend === backend) options.push({
|
|
1112
|
+
value: entry.reference,
|
|
1113
|
+
label: modelOptionText(t, entry.reference, entry.dimension),
|
|
1114
|
+
group: t(BACKEND_LABEL_KEY[backend])
|
|
672
1115
|
});
|
|
1116
|
+
return options;
|
|
673
1117
|
}
|
|
674
|
-
/**
|
|
675
|
-
function
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
const options = [];
|
|
679
|
-
for (const entry of LOCAL_EMBEDDINGS) if (entry.backend === backend) {
|
|
680
|
-
const { reference, dimension } = entry;
|
|
681
|
-
options.push((0, react.createElement)("option", {
|
|
682
|
-
key: reference,
|
|
683
|
-
value: reference
|
|
684
|
-
}, modelOptionText(t, reference, dimension)));
|
|
685
|
-
}
|
|
686
|
-
groups.push((0, react.createElement)("optgroup", {
|
|
687
|
-
key: backend,
|
|
688
|
-
label: t(BACKEND_LABEL_KEY[backend])
|
|
689
|
-
}, options));
|
|
690
|
-
}
|
|
691
|
-
return [(0, react.createElement)("select", {
|
|
692
|
-
className: "zgc-select",
|
|
693
|
-
value: embeddingValue,
|
|
694
|
-
disabled: !editable,
|
|
695
|
-
onChange: (ev) => {
|
|
696
|
-
setField("defaultEmbedding", ev.target.value);
|
|
697
|
-
}
|
|
698
|
-
}, groups)];
|
|
699
|
-
}
|
|
700
|
-
/** embedding 行:本地后端分组的 <select>(候选文本带维度插值)。 */
|
|
701
|
-
function buildEmbeddingRow(deps) {
|
|
702
|
-
const { editable, fields, setField, t } = deps;
|
|
703
|
-
const embeddingLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("embeddingLabel"));
|
|
704
|
-
const embeddingHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("embeddingHint"));
|
|
705
|
-
const embeddingSelects = buildOptionGroups(t, fields.embedding, editable, setField);
|
|
706
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, embeddingLabel, embeddingHint, embeddingSelects[0]);
|
|
707
|
-
}
|
|
708
|
-
/** defaultLimit 行:数字输入,区间判定在 lib/card-logic.ts 的 limitDraftOf。 */
|
|
709
|
-
function buildLimitRow(deps) {
|
|
710
|
-
const { editable, fields, setField, setSaveError, t } = deps;
|
|
711
|
-
const limitLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("limitLabel", {
|
|
712
|
-
min: 1,
|
|
713
|
-
max: 50
|
|
714
|
-
}));
|
|
715
|
-
const limitInput = (0, react.createElement)("input", {
|
|
716
|
-
className: "zgc-input",
|
|
717
|
-
type: "number",
|
|
718
|
-
min: 1,
|
|
719
|
-
max: 50,
|
|
720
|
-
value: fields.limitDisplay,
|
|
721
|
-
disabled: !editable,
|
|
722
|
-
onChange: (ev) => {
|
|
723
|
-
const draft = limitDraftOf(ev.target.value, t);
|
|
724
|
-
setSaveError(draft.error ?? draft.hint);
|
|
725
|
-
if (draft.error === null) setField("defaultLimit", draft.draft);
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, limitLabel, limitInput);
|
|
1118
|
+
/** 数字草稿串 → 控件值:区间由 zod schema 判定;空串是「清空 = 恢复默认」,不是 0。 */
|
|
1119
|
+
function numberDisplay(display, schema) {
|
|
1120
|
+
const parsed = schema.safeParse(display === "" ? NaN : Number(display));
|
|
1121
|
+
return parsed.success ? parsed.data : void 0;
|
|
729
1122
|
}
|
|
730
|
-
/**
|
|
731
|
-
function
|
|
1123
|
+
/** 检索模型小节:embedding 下拉(按本地后端分组)+ 每组结果数。 */
|
|
1124
|
+
function buildModelSection(deps) {
|
|
732
1125
|
const { editable, fields, setField, t } = deps;
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
value: fields.
|
|
738
|
-
|
|
1126
|
+
const embedding = (0, react.createElement)(x, {
|
|
1127
|
+
label: t("embeddingLabel"),
|
|
1128
|
+
...l(t("embeddingHint")),
|
|
1129
|
+
field: "defaultEmbedding",
|
|
1130
|
+
value: fields.embedding,
|
|
1131
|
+
options: embeddingOptions(t),
|
|
739
1132
|
disabled: !editable,
|
|
740
|
-
onChange: (
|
|
741
|
-
setField("
|
|
1133
|
+
onChange: (next) => {
|
|
1134
|
+
setField("defaultEmbedding", next);
|
|
742
1135
|
}
|
|
743
1136
|
});
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
const enforceText = (0, react.createElement)("span", { className: "zgc-label" }, t("enforceLabel"));
|
|
758
|
-
const enforceInner = (0, react.createElement)("label", { style: {
|
|
759
|
-
display: "flex",
|
|
760
|
-
gap: "8px",
|
|
761
|
-
alignItems: "center",
|
|
762
|
-
cursor: editable ? "pointer" : "default"
|
|
763
|
-
} }, enforceCheckbox, enforceText);
|
|
764
|
-
const enforceHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("enforceHint"));
|
|
765
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, enforceInner, enforceHint);
|
|
766
|
-
}
|
|
767
|
-
/** 配额 / 时效行:区间内落草稿、清空即回「未填」、越界给区间文案并置保存条错误。 */
|
|
768
|
-
function buildRangeRow(deps, spec) {
|
|
769
|
-
const { editable, setField, setSaveError, t } = deps;
|
|
770
|
-
const label = (0, react.createElement)("div", { className: "zgc-label" }, t(spec.labelKey, {
|
|
771
|
-
min: 1,
|
|
772
|
-
max: spec.max
|
|
773
|
-
}));
|
|
774
|
-
const hint = (0, react.createElement)("div", { className: "zgc-hint" }, t(spec.hintKey, { default: spec.default }));
|
|
775
|
-
const input = (0, react.createElement)("input", {
|
|
776
|
-
className: "zgc-input",
|
|
777
|
-
type: "number",
|
|
778
|
-
min: 1,
|
|
779
|
-
max: spec.max,
|
|
780
|
-
value: spec.value,
|
|
1137
|
+
const limit = (0, react.createElement)(v, {
|
|
1138
|
+
label: t("limitLabel"),
|
|
1139
|
+
hint: t("limitInvalid", {
|
|
1140
|
+
min: 1,
|
|
1141
|
+
max: 50
|
|
1142
|
+
}),
|
|
1143
|
+
field: "defaultLimit",
|
|
1144
|
+
value: numberDisplay(fields.limitDisplay, LIMIT_SCHEMA),
|
|
1145
|
+
min: LIMIT_SCHEMA.minValue ?? 1,
|
|
1146
|
+
max: LIMIT_SCHEMA.maxValue ?? 50,
|
|
1147
|
+
step: 1,
|
|
1148
|
+
unit: t("unitResults"),
|
|
1149
|
+
invalidHint: t("outOfRange"),
|
|
781
1150
|
disabled: !editable,
|
|
782
|
-
onChange: (
|
|
783
|
-
|
|
784
|
-
if (raw === "") {
|
|
785
|
-
setSaveError(null);
|
|
786
|
-
setField(spec.field, void 0);
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
const num = Number(raw);
|
|
790
|
-
if (Number.isSafeInteger(num) && num >= 1 && num <= spec.max) {
|
|
791
|
-
setSaveError(null);
|
|
792
|
-
setField(spec.field, num);
|
|
793
|
-
} else setSaveError(rangeErrorText(t, spec.invalidKey, spec.max));
|
|
1151
|
+
onChange: (next) => {
|
|
1152
|
+
setField("defaultLimit", next);
|
|
794
1153
|
}
|
|
795
1154
|
});
|
|
796
|
-
return (0, react.createElement)(
|
|
1155
|
+
return (0, react.createElement)(d, { title: t("modelSection") }, embedding, limit);
|
|
797
1156
|
}
|
|
798
1157
|
/** 重建行:root 输入(白名单候选进 <datalist>)+ 触发按钮(在跑时禁用)。 */
|
|
799
|
-
function
|
|
1158
|
+
function buildRebuildField(deps) {
|
|
800
1159
|
const { fields, rebuild, root, roots, setRoot, t } = deps;
|
|
801
|
-
const rebuildLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("rebuildLabel"));
|
|
802
|
-
const rebuildHint = (0, react.createElement)("div", { className: "zgc-hint" }, rebuildHintText(t, fields.embedding, roots.length > 0));
|
|
803
1160
|
const rootOptions = roots.map((entry) => (0, react.createElement)("option", {
|
|
804
1161
|
key: entry,
|
|
805
1162
|
value: entry
|
|
806
1163
|
}));
|
|
807
1164
|
const rootDatalist = (0, react.createElement)("datalist", { id: ROOT_OPTIONS_ID }, ...rootOptions);
|
|
808
1165
|
const rebuildInput = (0, react.createElement)("input", {
|
|
809
|
-
className: "zgc-
|
|
1166
|
+
className: "dsu-input zgc-rebuildInput",
|
|
810
1167
|
value: root,
|
|
811
1168
|
list: ROOT_OPTIONS_ID,
|
|
812
1169
|
placeholder: "/absolute/path/to/workspace",
|
|
@@ -816,12 +1173,16 @@ function buildRebuildRow(deps) {
|
|
|
816
1173
|
});
|
|
817
1174
|
const rebuildButton = (0, react.createElement)("button", {
|
|
818
1175
|
type: "button",
|
|
819
|
-
className: "
|
|
1176
|
+
className: "dsu-btn",
|
|
820
1177
|
"data-field": "rebuild",
|
|
821
1178
|
disabled: rebuild.phase === "running",
|
|
822
1179
|
onClick: deps.onRebuild
|
|
823
1180
|
}, rebuild.phase === "running" ? t("rebuildRunning") : t("rebuildButton"));
|
|
824
|
-
return (0, react.createElement)(
|
|
1181
|
+
return (0, react.createElement)(g, {
|
|
1182
|
+
label: t("rebuildLabel"),
|
|
1183
|
+
...l(rebuildHintText(t, fields.embedding, roots.length > 0)),
|
|
1184
|
+
wide: true
|
|
1185
|
+
}, rootDatalist, rebuildInput, rebuildButton);
|
|
825
1186
|
}
|
|
826
1187
|
/**
|
|
827
1188
|
* 守护进程(`zg server`)就绪态一行,取自 rebuild-roots 引导端点。
|
|
@@ -835,8 +1196,7 @@ function buildDaemonNote(deps) {
|
|
|
835
1196
|
const { t } = deps;
|
|
836
1197
|
const key = daemonNoteKey(deps.serverReady);
|
|
837
1198
|
if (key === void 0) return null;
|
|
838
|
-
|
|
839
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, note);
|
|
1199
|
+
return (0, react.createElement)("p", { className: "dsu-hint" }, t(key));
|
|
840
1200
|
}
|
|
841
1201
|
/** 重建状态节点:phase 非 idle 才出现;done 且无输出时给一句「已完成」。 */
|
|
842
1202
|
function buildRebuildStatusRow(deps) {
|
|
@@ -848,50 +1208,81 @@ function buildRebuildStatusRow(deps) {
|
|
|
848
1208
|
else displayText = rebuild.output;
|
|
849
1209
|
return (0, react.createElement)("div", { className: displayClass }, displayText);
|
|
850
1210
|
}
|
|
851
|
-
/**
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1211
|
+
/** 网络与索引小节:镜像地址、search-first 开关、配额与时效、工作区重建与守护进程状态。 */
|
|
1212
|
+
function buildIndexSection(deps) {
|
|
1213
|
+
const { editable, fields, setField, t } = deps;
|
|
1214
|
+
const endpoint = (0, react.createElement)(y, {
|
|
1215
|
+
label: t("endpointLabel"),
|
|
1216
|
+
...l(t("endpointHint")),
|
|
1217
|
+
field: "hfEndpoint",
|
|
1218
|
+
value: fields.hfEndpoint,
|
|
1219
|
+
placeholder: "https://modelscope.cn/models",
|
|
1220
|
+
monospace: true,
|
|
1221
|
+
disabled: !editable,
|
|
1222
|
+
onChange: (next) => {
|
|
1223
|
+
setField("hfEndpoint", next.trim() === "" ? void 0 : next.trim());
|
|
1224
|
+
}
|
|
1225
|
+
});
|
|
1226
|
+
const enforce = (0, react.createElement)(_, {
|
|
1227
|
+
label: t("enforceLabel"),
|
|
1228
|
+
...l(t("enforceHint")),
|
|
1229
|
+
field: "enforceSearchFirst",
|
|
1230
|
+
checked: fields.enforceSearchFirst,
|
|
1231
|
+
disabled: !editable,
|
|
1232
|
+
onChange: (next) => {
|
|
1233
|
+
setField("enforceSearchFirst", next);
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
const budget = (0, react.createElement)(v, {
|
|
1237
|
+
label: t("budgetLabel"),
|
|
1238
|
+
...l(t("budgetHint", { default: 3 })),
|
|
1239
|
+
field: "grepBudgetPerSearch",
|
|
1240
|
+
value: numberDisplay(fields.grepBudget, BUDGET_SCHEMA),
|
|
1241
|
+
min: BUDGET_SCHEMA.minValue ?? 1,
|
|
1242
|
+
max: BUDGET_SCHEMA.maxValue ?? 20,
|
|
1243
|
+
step: 1,
|
|
1244
|
+
unit: t("unitTimes"),
|
|
1245
|
+
invalidHint: t("outOfRange"),
|
|
1246
|
+
disabled: !editable,
|
|
1247
|
+
onChange: (next) => {
|
|
1248
|
+
setField("grepBudgetPerSearch", next);
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
const window = (0, react.createElement)(v, {
|
|
1252
|
+
label: t("windowLabel"),
|
|
1253
|
+
...l(t("windowHint", { default: 10 })),
|
|
1254
|
+
field: "unlockWindowMin",
|
|
1255
|
+
value: numberDisplay(fields.unlockWindow, WINDOW_SCHEMA),
|
|
1256
|
+
min: WINDOW_SCHEMA.minValue ?? 1,
|
|
1257
|
+
max: WINDOW_SCHEMA.maxValue ?? 240,
|
|
1258
|
+
step: 1,
|
|
1259
|
+
unit: t("unitMinutes"),
|
|
1260
|
+
invalidHint: t("outOfRange"),
|
|
1261
|
+
disabled: !editable,
|
|
1262
|
+
onChange: (next) => {
|
|
1263
|
+
setField("unlockWindowMin", next);
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
return (0, react.createElement)(d, { title: t("indexSection") }, endpoint, enforce, budget, window, buildDaemonNote(deps), buildRebuildField(deps), buildRebuildStatusRow(deps));
|
|
1267
|
+
}
|
|
1268
|
+
/** 卡片主体:检索模型 / 网络与索引两节 + 保存条。 */
|
|
855
1269
|
function buildCardBody(deps) {
|
|
856
|
-
const {
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
labelKey: "windowLabel",
|
|
873
|
-
hintKey: "windowHint",
|
|
874
|
-
field: "unlockWindowMin",
|
|
875
|
-
invalidKey: "windowInvalid",
|
|
876
|
-
max: 240,
|
|
877
|
-
default: 10,
|
|
878
|
-
value: fields.unlockWindow
|
|
879
|
-
}),
|
|
880
|
-
(0, react.createElement)(SaveBar, {
|
|
881
|
-
t,
|
|
882
|
-
dirty: deps.dirty,
|
|
883
|
-
writable: deps.writable,
|
|
884
|
-
busy: deps.busy,
|
|
885
|
-
error: deps.saveError,
|
|
886
|
-
onSave: deps.onSave,
|
|
887
|
-
onDiscard: deps.onDiscard
|
|
888
|
-
}),
|
|
889
|
-
buildDaemonNote(deps),
|
|
890
|
-
buildRebuildRow(deps)
|
|
891
|
-
];
|
|
892
|
-
const status = buildRebuildStatusRow(deps);
|
|
893
|
-
if (status !== null) rows.push(status);
|
|
894
|
-
return rows;
|
|
1270
|
+
const { t } = deps;
|
|
1271
|
+
const saveBar = (0, react.createElement)(S, {
|
|
1272
|
+
dirty: deps.dirty,
|
|
1273
|
+
busy: deps.busy,
|
|
1274
|
+
writable: deps.writable,
|
|
1275
|
+
error: deps.saveError,
|
|
1276
|
+
saveLabel: t("save"),
|
|
1277
|
+
savingLabel: t("saving"),
|
|
1278
|
+
revertLabel: t("revert"),
|
|
1279
|
+
dirtyLabel: t("dirtyCount", { count: deps.dirtyCount }),
|
|
1280
|
+
cleanLabel: t("statusClean"),
|
|
1281
|
+
readOnlyLabel: t("statusReadOnly"),
|
|
1282
|
+
onSave: deps.onSave,
|
|
1283
|
+
onDiscard: deps.onDiscard
|
|
1284
|
+
});
|
|
1285
|
+
return (0, react.createElement)(u, null, buildModelSection(deps), buildIndexSection(deps), saveBar);
|
|
895
1286
|
}
|
|
896
1287
|
/** 显式字段写入(schema-coverage 门禁按 set('字段名') 字面量识别绑定)。 */
|
|
897
1288
|
function pushFieldWrite(ops, key, draft, set) {
|
|
@@ -926,17 +1317,22 @@ function useRebuild(t, reader) {
|
|
|
926
1317
|
});
|
|
927
1318
|
const pollRef = (0, react.useRef)(null);
|
|
928
1319
|
const pollingRef = (0, react.useRef)(false);
|
|
1320
|
+
const jobRef = (0, react.useRef)(null);
|
|
929
1321
|
const mountedRef = (0, react.useRef)(true);
|
|
930
1322
|
const isMounted = () => mountedRef.current;
|
|
931
1323
|
function stopPolling() {
|
|
1324
|
+
jobRef.current = null;
|
|
932
1325
|
if (pollRef.current !== null) {
|
|
933
1326
|
clearInterval(pollRef.current);
|
|
934
1327
|
pollRef.current = null;
|
|
935
1328
|
}
|
|
936
1329
|
}
|
|
937
|
-
(0, react.useEffect)(() =>
|
|
938
|
-
mountedRef.current =
|
|
939
|
-
|
|
1330
|
+
(0, react.useEffect)(() => {
|
|
1331
|
+
mountedRef.current = true;
|
|
1332
|
+
return () => {
|
|
1333
|
+
mountedRef.current = false;
|
|
1334
|
+
stopPolling();
|
|
1335
|
+
};
|
|
940
1336
|
}, []);
|
|
941
1337
|
/** 拉白名单 + 就绪态。失败**不**改重建面板:面板 idle 时冒一个红字只是噪音,
|
|
942
1338
|
* 用户真点「重建」时 start() 会把同一错误显示出来。 */
|
|
@@ -959,11 +1355,11 @@ function useRebuild(t, reader) {
|
|
|
959
1355
|
})();
|
|
960
1356
|
}, [refreshAccess]);
|
|
961
1357
|
async function pollStatus(jobId) {
|
|
962
|
-
if (pollingRef.current || !isMounted()) return;
|
|
1358
|
+
if (pollingRef.current || !isMounted() || jobRef.current !== jobId) return;
|
|
963
1359
|
pollingRef.current = true;
|
|
964
1360
|
try {
|
|
965
1361
|
const body = await requireReader(reader, t).status(jobId);
|
|
966
|
-
if (!isMounted()) return;
|
|
1362
|
+
if (!isMounted() || jobRef.current !== jobId) return;
|
|
967
1363
|
const poll = parseRebuildPoll(body, t);
|
|
968
1364
|
if (poll.phase !== "running") stopPolling();
|
|
969
1365
|
setRebuild({
|
|
@@ -971,7 +1367,7 @@ function useRebuild(t, reader) {
|
|
|
971
1367
|
output: poll.output
|
|
972
1368
|
});
|
|
973
1369
|
} catch (error) {
|
|
974
|
-
if (!isMounted()) return;
|
|
1370
|
+
if (!isMounted() || jobRef.current !== jobId) return;
|
|
975
1371
|
stopPolling();
|
|
976
1372
|
setRebuild({
|
|
977
1373
|
phase: "error",
|
|
@@ -984,8 +1380,10 @@ function useRebuild(t, reader) {
|
|
|
984
1380
|
/** 发起一次重建;成功后进入轮询。 */
|
|
985
1381
|
async function startOnce() {
|
|
986
1382
|
const started = await requireReader(reader, t).rebuild(root.trim());
|
|
987
|
-
|
|
988
|
-
|
|
1383
|
+
const parsedStarted = zod.z.object({ jobId: zod.z.string() }).safeParse(started);
|
|
1384
|
+
if (!parsedStarted.success) throw new TypeError(t("rebuildMissingJobId"));
|
|
1385
|
+
const { jobId } = parsedStarted.data;
|
|
1386
|
+
jobRef.current = jobId;
|
|
989
1387
|
pollRef.current = setInterval(() => {
|
|
990
1388
|
pollStatus(jobId);
|
|
991
1389
|
}, REBUILD_POLL_MS);
|
|
@@ -1033,7 +1431,8 @@ function ZgCard(props) {
|
|
|
1033
1431
|
const [saveError, setSaveError] = (0, react.useState)(null);
|
|
1034
1432
|
const rebuildView = useRebuild(t, props.rebuildRemote);
|
|
1035
1433
|
const fields = draftFields(touched, value);
|
|
1036
|
-
const
|
|
1434
|
+
const dirtyCount = t$2(touched, value).length;
|
|
1435
|
+
const dirty = dirtyCount > 0;
|
|
1037
1436
|
const setField = (field, draft) => {
|
|
1038
1437
|
setTouched((prev) => ({
|
|
1039
1438
|
...prev,
|
|
@@ -1041,7 +1440,7 @@ function ZgCard(props) {
|
|
|
1041
1440
|
}));
|
|
1042
1441
|
};
|
|
1043
1442
|
const save = async () => {
|
|
1044
|
-
const keys = t$
|
|
1443
|
+
const keys = t$2(touched, value);
|
|
1045
1444
|
if (keys.length === 0) return;
|
|
1046
1445
|
setBusy(true);
|
|
1047
1446
|
setSaveError(null);
|
|
@@ -1071,7 +1470,7 @@ function ZgCard(props) {
|
|
|
1071
1470
|
setTouched({});
|
|
1072
1471
|
setSaveError(null);
|
|
1073
1472
|
};
|
|
1074
|
-
|
|
1473
|
+
return buildCardBody({
|
|
1075
1474
|
t,
|
|
1076
1475
|
fields,
|
|
1077
1476
|
writable,
|
|
@@ -1081,11 +1480,11 @@ function ZgCard(props) {
|
|
|
1081
1480
|
root: rebuildView.root,
|
|
1082
1481
|
rebuild: rebuildView.state,
|
|
1083
1482
|
dirty,
|
|
1483
|
+
dirtyCount,
|
|
1084
1484
|
busy,
|
|
1085
1485
|
saveError,
|
|
1086
1486
|
setField,
|
|
1087
1487
|
setRoot: rebuildView.setRoot,
|
|
1088
|
-
setSaveError,
|
|
1089
1488
|
onSave: () => {
|
|
1090
1489
|
save();
|
|
1091
1490
|
},
|
|
@@ -1094,11 +1493,6 @@ function ZgCard(props) {
|
|
|
1094
1493
|
rebuildView.start();
|
|
1095
1494
|
}
|
|
1096
1495
|
});
|
|
1097
|
-
const body = (0, react.createElement)("div", { style: { padding: "2px 0" } }, rows);
|
|
1098
|
-
return (0, react.createElement)(PluginCard, {
|
|
1099
|
-
title: t("cardTitle"),
|
|
1100
|
-
description: t("cardDescription")
|
|
1101
|
-
}, body);
|
|
1102
1496
|
}
|
|
1103
1497
|
const inject = [
|
|
1104
1498
|
"slots",
|
|
@@ -1109,7 +1503,7 @@ function apply(ctx) {
|
|
|
1109
1503
|
ctx.effect(() => {
|
|
1110
1504
|
const tag = document.createElement("style");
|
|
1111
1505
|
tag.id = "zvec-grep-card-css";
|
|
1112
|
-
tag.textContent = CARD_CSS
|
|
1506
|
+
tag.textContent = `${CARD_CSS}\n${c}`;
|
|
1113
1507
|
document.head.append(tag);
|
|
1114
1508
|
return () => {
|
|
1115
1509
|
tag.remove();
|
|
@@ -1155,7 +1549,6 @@ exports.cardStore = cardStore;
|
|
|
1155
1549
|
exports.draftFields = draftFields;
|
|
1156
1550
|
exports.inject = inject;
|
|
1157
1551
|
exports.parseRebuildPoll = parseRebuildPoll;
|
|
1158
|
-
exports.resolveLimitInput = resolveLimitInput;
|
|
1159
1552
|
return module.exports;
|
|
1160
1553
|
},
|
|
1161
1554
|
});
|