dsh-extra-paths 0.0.0-stage → 0.1.0
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/README.md +79 -2
- package/cordis.patch.yml +6 -0
- package/lib/argv.js +45 -0
- package/lib/argv.js.map +1 -0
- package/lib/client.js +905 -0
- package/lib/config.js +123 -0
- package/lib/config.js.map +1 -0
- package/lib/context.js +30 -0
- package/lib/context.js.map +1 -0
- package/lib/grant.js +21 -0
- package/lib/grant.js.map +1 -0
- package/lib/index.js +173 -0
- package/lib/index.js.map +1 -0
- package/lib/listener.js +57 -0
- package/lib/listener.js.map +1 -0
- package/lib/paths.js +70 -0
- package/lib/paths.js.map +1 -0
- package/lib/pattern.js +206 -0
- package/lib/pattern.js.map +1 -0
- package/lib/policy.js +17 -0
- package/lib/policy.js.map +1 -0
- package/lib/preview.js +126 -0
- package/lib/preview.js.map +1 -0
- package/lib/resolve.js +153 -0
- package/lib/resolve.js.map +1 -0
- package/lib/schema.js +54 -0
- package/lib/schema.js.map +1 -0
- package/lib/types/argv.d.ts +17 -0
- package/lib/types/config.d.ts +55 -0
- package/lib/types/context.d.ts +13 -0
- package/lib/types/grant.d.ts +17 -0
- package/lib/types/index.d.ts +86 -0
- package/lib/types/listener.d.ts +40 -0
- package/lib/types/paths.d.ts +32 -0
- package/lib/types/pattern.d.ts +88 -0
- package/lib/types/policy.d.ts +21 -0
- package/lib/types/preview.d.ts +77 -0
- package/lib/types/resolve.d.ts +63 -0
- package/lib/types/schema.d.ts +42 -0
- package/lib/types/wrap-fs.d.ts +50 -0
- package/lib/types/wrap-sandbox.d.ts +60 -0
- package/lib/wrap-fs.js +75 -0
- package/lib/wrap-fs.js.map +1 -0
- package/lib/wrap-sandbox.js +89 -0
- package/lib/wrap-sandbox.js.map +1 -0
- package/package.json +113 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-extra-paths",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
//#endregion
|
|
29
|
+
let react = require("react");
|
|
30
|
+
react = __toESM(react, 1);
|
|
31
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
//#region src/client/paths.ts
|
|
33
|
+
/**
|
|
34
|
+
* Lexical path resolution for the settings page's live column. It mirrors the
|
|
35
|
+
* host's `expandPath` (a relative entry resolves against the session workspace,
|
|
36
|
+
* `~` against the home directory) WITHOUT touching the filesystem, so a
|
|
37
|
+
* half-typed row can show where it would land before it is saved.
|
|
38
|
+
*
|
|
39
|
+
* Symbolic links are deliberately not resolved here — the browser cannot
|
|
40
|
+
* realpath. The host's own preview is the authoritative answer, and the page
|
|
41
|
+
* keeps showing both: this one instantly, the host's on every settled edit.
|
|
42
|
+
* @module dsh-extra-paths/client/paths
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Collapse `.`, `..` and duplicate separators in an absolute POSIX spelling.
|
|
46
|
+
* @param path - an absolute spelling (the caller guarantees the leading `/`).
|
|
47
|
+
* @returns the collapsed absolute path; `..` above the root is clamped there.
|
|
48
|
+
*/
|
|
49
|
+
function collapse(path) {
|
|
50
|
+
const segments = [];
|
|
51
|
+
for (const segment of path.split("/")) {
|
|
52
|
+
if (segment === "" || segment === ".") continue;
|
|
53
|
+
if (segment === "..") {
|
|
54
|
+
segments.pop();
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
segments.push(segment);
|
|
58
|
+
}
|
|
59
|
+
return `/${segments.join("/")}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolve one configured entry the way the host will, lexically.
|
|
63
|
+
* @param entry - the row's raw spelling.
|
|
64
|
+
* @param workspaceRoot - the workspace a relative entry resolves against.
|
|
65
|
+
* @param home - the host's home directory, once the preview has reported it.
|
|
66
|
+
* @returns the absolute path, or undefined when it cannot be resolved yet
|
|
67
|
+
* (`~` before the home directory is known, or a relative entry with no usable
|
|
68
|
+
* workspace base).
|
|
69
|
+
*/
|
|
70
|
+
function resolveLexically(entry, workspaceRoot, home) {
|
|
71
|
+
const trimmed = entry.trim();
|
|
72
|
+
if (trimmed === "") return void 0;
|
|
73
|
+
if (trimmed === "~" || trimmed.startsWith("~/")) {
|
|
74
|
+
if (home === void 0 || home === "") return void 0;
|
|
75
|
+
return collapse(trimmed === "~" ? home : `${home}/${trimmed.slice(2)}`);
|
|
76
|
+
}
|
|
77
|
+
if (trimmed.startsWith("/")) return collapse(trimmed);
|
|
78
|
+
if (!workspaceRoot.startsWith("/")) return void 0;
|
|
79
|
+
return collapse(`${workspaceRoot}/${trimmed}`);
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/client/preview.ts
|
|
83
|
+
const ROUTE = "/extra-paths/resolved";
|
|
84
|
+
/**
|
|
85
|
+
* Fetch the effective roots for one workspace.
|
|
86
|
+
*
|
|
87
|
+
* The unsaved rows travel with the request so the answer describes the DRAFT:
|
|
88
|
+
* previously the preview only ever described the stored document, which is what
|
|
89
|
+
* made configuring a relative path a guess-until-you-save exercise.
|
|
90
|
+
* @param cwd - the workspace path to resolve against.
|
|
91
|
+
* @param paths - the page's current rows (strings or `{path, scope, surfaces}`).
|
|
92
|
+
* @param signal - optional abort signal.
|
|
93
|
+
* @returns the preview, or undefined when the route is unavailable.
|
|
94
|
+
*/
|
|
95
|
+
async function fetchPreview(cwd, paths, signal) {
|
|
96
|
+
try {
|
|
97
|
+
const query = new URLSearchParams({ cwd });
|
|
98
|
+
if (paths !== void 0) query.set("paths", JSON.stringify(paths));
|
|
99
|
+
const response = await fetch(`${ROUTE}?${query.toString()}`, {
|
|
100
|
+
signal,
|
|
101
|
+
credentials: "same-origin"
|
|
102
|
+
});
|
|
103
|
+
if (!response.ok) return void 0;
|
|
104
|
+
return await response.json();
|
|
105
|
+
} catch {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/client/styles.ts
|
|
111
|
+
const box = { boxSizing: "border-box" };
|
|
112
|
+
const card = {
|
|
113
|
+
...box,
|
|
114
|
+
display: "flex",
|
|
115
|
+
flexDirection: "column",
|
|
116
|
+
gap: 8,
|
|
117
|
+
padding: "10px 12px",
|
|
118
|
+
border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.25))",
|
|
119
|
+
borderRadius: 8
|
|
120
|
+
};
|
|
121
|
+
const button = {
|
|
122
|
+
...box,
|
|
123
|
+
padding: "4px 10px",
|
|
124
|
+
borderRadius: 6,
|
|
125
|
+
border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.35))",
|
|
126
|
+
background: "transparent",
|
|
127
|
+
color: "inherit",
|
|
128
|
+
fontSize: 12,
|
|
129
|
+
cursor: "pointer"
|
|
130
|
+
};
|
|
131
|
+
/** The page's style map. */
|
|
132
|
+
const styles = {
|
|
133
|
+
page: {
|
|
134
|
+
display: "flex",
|
|
135
|
+
flexDirection: "column",
|
|
136
|
+
gap: 12,
|
|
137
|
+
padding: "4px 0",
|
|
138
|
+
maxWidth: 760
|
|
139
|
+
},
|
|
140
|
+
intro: {
|
|
141
|
+
fontSize: 12,
|
|
142
|
+
lineHeight: 1.6,
|
|
143
|
+
opacity: .75
|
|
144
|
+
},
|
|
145
|
+
baseRow: {
|
|
146
|
+
display: "flex",
|
|
147
|
+
gap: 8,
|
|
148
|
+
alignItems: "center",
|
|
149
|
+
flexWrap: "wrap"
|
|
150
|
+
},
|
|
151
|
+
baseField: { width: 380 },
|
|
152
|
+
toolbar: {
|
|
153
|
+
display: "flex",
|
|
154
|
+
gap: 8,
|
|
155
|
+
alignItems: "center",
|
|
156
|
+
flexWrap: "wrap"
|
|
157
|
+
},
|
|
158
|
+
card,
|
|
159
|
+
cardHead: {
|
|
160
|
+
display: "flex",
|
|
161
|
+
alignItems: "center",
|
|
162
|
+
justifyContent: "space-between",
|
|
163
|
+
gap: 8
|
|
164
|
+
},
|
|
165
|
+
cardHeadRight: {
|
|
166
|
+
display: "flex",
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
gap: 8
|
|
169
|
+
},
|
|
170
|
+
cardTitle: {
|
|
171
|
+
fontSize: 12,
|
|
172
|
+
fontWeight: 600,
|
|
173
|
+
opacity: .75
|
|
174
|
+
},
|
|
175
|
+
pathInput: {
|
|
176
|
+
...box,
|
|
177
|
+
width: "100%",
|
|
178
|
+
padding: "6px 8px",
|
|
179
|
+
borderRadius: 6,
|
|
180
|
+
border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.35))",
|
|
181
|
+
background: "transparent",
|
|
182
|
+
color: "inherit",
|
|
183
|
+
fontFamily: "var(--dsh-font-mono, monospace)",
|
|
184
|
+
fontSize: 13
|
|
185
|
+
},
|
|
186
|
+
resolvedRow: {
|
|
187
|
+
display: "flex",
|
|
188
|
+
gap: 6,
|
|
189
|
+
alignItems: "baseline",
|
|
190
|
+
minHeight: 18,
|
|
191
|
+
fontSize: 12,
|
|
192
|
+
flexWrap: "wrap"
|
|
193
|
+
},
|
|
194
|
+
code: {
|
|
195
|
+
fontFamily: "var(--dsh-font-mono, monospace)",
|
|
196
|
+
fontSize: 12,
|
|
197
|
+
wordBreak: "break-all"
|
|
198
|
+
},
|
|
199
|
+
dim: {
|
|
200
|
+
opacity: .6,
|
|
201
|
+
fontSize: 12,
|
|
202
|
+
lineHeight: 1.5
|
|
203
|
+
},
|
|
204
|
+
controlsRow: {
|
|
205
|
+
display: "flex",
|
|
206
|
+
gap: 16,
|
|
207
|
+
alignItems: "center",
|
|
208
|
+
flexWrap: "wrap"
|
|
209
|
+
},
|
|
210
|
+
field: {
|
|
211
|
+
display: "flex",
|
|
212
|
+
gap: 6,
|
|
213
|
+
alignItems: "center",
|
|
214
|
+
fontSize: 12,
|
|
215
|
+
opacity: .85
|
|
216
|
+
},
|
|
217
|
+
select: {
|
|
218
|
+
padding: "3px 6px",
|
|
219
|
+
borderRadius: 6,
|
|
220
|
+
background: "transparent",
|
|
221
|
+
color: "inherit",
|
|
222
|
+
fontSize: 12
|
|
223
|
+
},
|
|
224
|
+
pills: {
|
|
225
|
+
display: "flex",
|
|
226
|
+
gap: 6,
|
|
227
|
+
alignItems: "center"
|
|
228
|
+
},
|
|
229
|
+
pillOn: {
|
|
230
|
+
...button,
|
|
231
|
+
borderColor: "var(--dsh-color-accent, #2f6fd0)",
|
|
232
|
+
background: "var(--dsh-color-accent-soft, rgba(47,111,208,0.15))"
|
|
233
|
+
},
|
|
234
|
+
pillOff: {
|
|
235
|
+
...button,
|
|
236
|
+
opacity: .55
|
|
237
|
+
},
|
|
238
|
+
button,
|
|
239
|
+
primary: {
|
|
240
|
+
...button,
|
|
241
|
+
borderColor: "var(--dsh-color-accent, #2f6fd0)",
|
|
242
|
+
fontWeight: 600
|
|
243
|
+
},
|
|
244
|
+
linkButton: {
|
|
245
|
+
...button,
|
|
246
|
+
border: "none",
|
|
247
|
+
opacity: .7,
|
|
248
|
+
padding: "2px 4px"
|
|
249
|
+
},
|
|
250
|
+
panel: {
|
|
251
|
+
...box,
|
|
252
|
+
display: "flex",
|
|
253
|
+
flexDirection: "column",
|
|
254
|
+
gap: 8,
|
|
255
|
+
padding: "10px 12px",
|
|
256
|
+
border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.25))",
|
|
257
|
+
borderRadius: 8
|
|
258
|
+
},
|
|
259
|
+
panelHead: {
|
|
260
|
+
display: "flex",
|
|
261
|
+
alignItems: "center",
|
|
262
|
+
justifyContent: "space-between",
|
|
263
|
+
gap: 8,
|
|
264
|
+
fontSize: 12,
|
|
265
|
+
fontWeight: 600,
|
|
266
|
+
opacity: .8
|
|
267
|
+
},
|
|
268
|
+
entry: {
|
|
269
|
+
display: "flex",
|
|
270
|
+
gap: 6,
|
|
271
|
+
alignItems: "baseline",
|
|
272
|
+
flexWrap: "wrap",
|
|
273
|
+
fontSize: 12
|
|
274
|
+
},
|
|
275
|
+
statusOk: { color: "var(--dsh-color-success, #15803d)" },
|
|
276
|
+
statusMissing: { color: "var(--dsh-color-warning, #b45309)" },
|
|
277
|
+
statusRejected: { color: "var(--dsh-color-danger, #b91c1c)" },
|
|
278
|
+
warn: {
|
|
279
|
+
color: "var(--dsh-color-warning, #b45309)",
|
|
280
|
+
fontSize: 12,
|
|
281
|
+
lineHeight: 1.5
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Interactive states cannot live in a style OBJECT (there is no `:focus` key),
|
|
286
|
+
* and the shell's default focus ring is a heavy black outline on these fields.
|
|
287
|
+
* One small stylesheet, scoped by the `xp-` prefix, supplies a friendly accent
|
|
288
|
+
* ring plus hover feedback; the inline styles above stay the source of truth for
|
|
289
|
+
* everything static.
|
|
290
|
+
*/
|
|
291
|
+
const css = `
|
|
292
|
+
.xp-input, .xp-select {
|
|
293
|
+
box-sizing: border-box;
|
|
294
|
+
padding: 6px 8px;
|
|
295
|
+
border-radius: 6px;
|
|
296
|
+
border: 1px solid var(--dsh-color-border, rgba(128,128,128,0.35));
|
|
297
|
+
background: transparent;
|
|
298
|
+
color: inherit;
|
|
299
|
+
font-size: 13px;
|
|
300
|
+
transition: border-color 120ms ease, box-shadow 120ms ease;
|
|
301
|
+
}
|
|
302
|
+
.xp-input:hover, .xp-select:hover { border-color: var(--dsh-color-border-strong, rgba(128,128,128,0.6)); }
|
|
303
|
+
.xp-input:focus, .xp-select:focus { outline: none; }
|
|
304
|
+
.xp-input:focus-visible, .xp-select:focus-visible {
|
|
305
|
+
outline: none;
|
|
306
|
+
border-color: var(--dsh-color-accent, #2f6fd0);
|
|
307
|
+
box-shadow: 0 0 0 2px var(--dsh-color-accent-soft, rgba(47,111,208,0.25));
|
|
308
|
+
}
|
|
309
|
+
.xp-input::placeholder { color: currentColor; opacity: 0.38; }
|
|
310
|
+
.xp-button {
|
|
311
|
+
box-sizing: border-box;
|
|
312
|
+
padding: 4px 10px;
|
|
313
|
+
border-radius: 6px;
|
|
314
|
+
border: 1px solid var(--dsh-color-border, rgba(128,128,128,0.35));
|
|
315
|
+
background: transparent;
|
|
316
|
+
color: inherit;
|
|
317
|
+
font-size: 12px;
|
|
318
|
+
cursor: pointer;
|
|
319
|
+
transition: background-color 120ms ease, border-color 120ms ease;
|
|
320
|
+
}
|
|
321
|
+
.xp-button:hover:not(:disabled) { background: var(--dsh-color-hover, rgba(128,128,128,0.12)); }
|
|
322
|
+
.xp-button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsh-color-accent-soft, rgba(47,111,208,0.25)); }
|
|
323
|
+
.xp-button:disabled { opacity: 0.45; cursor: default; }
|
|
324
|
+
.xp-button-on { border-color: var(--dsh-color-accent, #2f6fd0); background: var(--dsh-color-accent-soft, rgba(47,111,208,0.15)); }
|
|
325
|
+
.xp-button-off { opacity: 0.55; }
|
|
326
|
+
.xp-link { border: none; background: none; padding: 2px 4px; opacity: 0.7; font-size: 12px; cursor: pointer; color: inherit; }
|
|
327
|
+
.xp-link:hover { opacity: 1; text-decoration: underline; }
|
|
328
|
+
`;
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/client/page.tsx
|
|
331
|
+
/**
|
|
332
|
+
* The Extra paths settings page: one card per configured path, Chinese labels,
|
|
333
|
+
* a LIVE lexical resolution per row against a base workspace, quick add
|
|
334
|
+
* buttons, and the host's authoritative preview of the DRAFT (unsaved rows).
|
|
335
|
+
*
|
|
336
|
+
* The base workspace comes from the shell's standard `useWorkspaces` hook when
|
|
337
|
+
* the slot supplies it — a snapshot read once during activation would be
|
|
338
|
+
* `undefined` whenever the registry had not loaded yet, which is exactly how the
|
|
339
|
+
* picker ended up empty. `getWorkspaces` stays as a lazy fallback for
|
|
340
|
+
* compositions that pass no standard props.
|
|
341
|
+
* @module dsh-extra-paths/client/page
|
|
342
|
+
*/
|
|
343
|
+
const NOOP_HOOK = () => void 0;
|
|
344
|
+
const IDENTITY = (snapshot) => snapshot;
|
|
345
|
+
function itemsOf(value) {
|
|
346
|
+
const items = value?.items;
|
|
347
|
+
return Array.isArray(items) ? items : [];
|
|
348
|
+
}
|
|
349
|
+
const STATUS_LABEL = {
|
|
350
|
+
ok: "生效",
|
|
351
|
+
missing: "目录不存在",
|
|
352
|
+
rejected: "已拒绝"
|
|
353
|
+
};
|
|
354
|
+
const STATUS_STYLE = {
|
|
355
|
+
ok: styles.statusOk,
|
|
356
|
+
missing: styles.statusMissing,
|
|
357
|
+
rejected: styles.statusRejected
|
|
358
|
+
};
|
|
359
|
+
const SCOPE_LABEL = {
|
|
360
|
+
write: "随会话模式(read-only 下拒绝)",
|
|
361
|
+
"always-write": "始终可写(read-only 下也允许)"
|
|
362
|
+
};
|
|
363
|
+
function rowsOf(section) {
|
|
364
|
+
const rows = [];
|
|
365
|
+
for (const item of section?.paths ?? []) if (typeof item === "string") rows.push({
|
|
366
|
+
path: item,
|
|
367
|
+
scope: "write",
|
|
368
|
+
surfaces: ["fs", "shell"]
|
|
369
|
+
});
|
|
370
|
+
else rows.push({
|
|
371
|
+
path: item.path ?? "",
|
|
372
|
+
scope: item.scope ?? "write",
|
|
373
|
+
surfaces: [...item.surfaces ?? ["fs", "shell"]]
|
|
374
|
+
});
|
|
375
|
+
return rows;
|
|
376
|
+
}
|
|
377
|
+
function payloadOf(rows) {
|
|
378
|
+
return rows.filter((row) => row.path.trim() !== "").map((row) => ({
|
|
379
|
+
path: row.path.trim(),
|
|
380
|
+
scope: row.scope,
|
|
381
|
+
surfaces: [...row.surfaces]
|
|
382
|
+
}));
|
|
383
|
+
}
|
|
384
|
+
function useSnapshot(scope) {
|
|
385
|
+
const [snapshot, setSnapshot] = react.useState(() => scope.getSnapshot());
|
|
386
|
+
react.useEffect(() => scope.subscribe(() => {
|
|
387
|
+
setSnapshot(scope.getSnapshot());
|
|
388
|
+
}), [scope]);
|
|
389
|
+
return snapshot;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Render the page.
|
|
393
|
+
* @param props - the bound settings scope, the standard workspace hook, and the
|
|
394
|
+
* lazy fallback used when the composition supplies no standard props.
|
|
395
|
+
*/
|
|
396
|
+
function ExtraPathsPage({ scope, getWorkspaces, useWorkspaces }) {
|
|
397
|
+
const snapshot = useSnapshot(scope);
|
|
398
|
+
const fromHook = itemsOf((useWorkspaces ?? NOOP_HOOK)(IDENTITY));
|
|
399
|
+
const candidates = (fromHook.length > 0 ? fromHook : itemsOf(getWorkspaces?.()?.list?.getSnapshot?.())).map((item) => item.path).filter((path) => typeof path === "string" && path !== "");
|
|
400
|
+
const [rows, setRows] = react.useState(() => rowsOf(snapshot.value));
|
|
401
|
+
const [dirty, setDirty] = react.useState(false);
|
|
402
|
+
const [busy, setBusy] = react.useState(false);
|
|
403
|
+
const [error, setError] = react.useState(void 0);
|
|
404
|
+
const [preview, setPreview] = react.useState(void 0);
|
|
405
|
+
const [cwd, setCwd] = react.useState(() => candidates[0] ?? "");
|
|
406
|
+
const [cwdPinned, setCwdPinned] = react.useState(false);
|
|
407
|
+
const [manualBase, setManualBase] = react.useState(false);
|
|
408
|
+
react.useEffect(() => {
|
|
409
|
+
if (!dirty) setRows(rowsOf(snapshot.value));
|
|
410
|
+
}, [snapshot, dirty]);
|
|
411
|
+
const first = candidates[0];
|
|
412
|
+
react.useEffect(() => {
|
|
413
|
+
if (!cwdPinned && cwd === "" && first !== void 0) setCwd(first);
|
|
414
|
+
}, [
|
|
415
|
+
cwdPinned,
|
|
416
|
+
cwd,
|
|
417
|
+
first
|
|
418
|
+
]);
|
|
419
|
+
const typedBase = cwd.trim();
|
|
420
|
+
const usableBase = typedBase.startsWith("/") || typedBase === "~" || typedBase.startsWith("~/");
|
|
421
|
+
const base = typedBase.startsWith("~") ? resolveLexically(typedBase, "", preview?.home) ?? "" : typedBase;
|
|
422
|
+
const request = JSON.stringify(payloadOf(rows));
|
|
423
|
+
react.useEffect(() => {
|
|
424
|
+
if (base === "") return;
|
|
425
|
+
let live = true;
|
|
426
|
+
const timer = setTimeout(() => {
|
|
427
|
+
const draft = JSON.parse(request);
|
|
428
|
+
fetchPreview(base, draft).then((result) => {
|
|
429
|
+
if (live) setPreview(result);
|
|
430
|
+
});
|
|
431
|
+
}, 250);
|
|
432
|
+
return () => {
|
|
433
|
+
live = false;
|
|
434
|
+
clearTimeout(timer);
|
|
435
|
+
};
|
|
436
|
+
}, [
|
|
437
|
+
base,
|
|
438
|
+
request,
|
|
439
|
+
snapshot
|
|
440
|
+
]);
|
|
441
|
+
const update = (index, patch) => {
|
|
442
|
+
setDirty(true);
|
|
443
|
+
setRows((current) => current.map((row, i) => i === index ? {
|
|
444
|
+
...row,
|
|
445
|
+
...patch
|
|
446
|
+
} : row));
|
|
447
|
+
};
|
|
448
|
+
const toggleSurface = (index, surface) => {
|
|
449
|
+
const row = rows[index];
|
|
450
|
+
if (row === void 0) return;
|
|
451
|
+
const surfaces = row.surfaces.includes(surface) ? row.surfaces.filter((item) => item !== surface) : [...row.surfaces, surface];
|
|
452
|
+
update(index, { surfaces });
|
|
453
|
+
};
|
|
454
|
+
const append = (path) => {
|
|
455
|
+
setDirty(true);
|
|
456
|
+
setRows((current) => [...current, {
|
|
457
|
+
path,
|
|
458
|
+
scope: "write",
|
|
459
|
+
surfaces: ["fs", "shell"]
|
|
460
|
+
}]);
|
|
461
|
+
};
|
|
462
|
+
const reset = () => {
|
|
463
|
+
setRows(rowsOf(snapshot.value));
|
|
464
|
+
setDirty(false);
|
|
465
|
+
setError(void 0);
|
|
466
|
+
};
|
|
467
|
+
const save = () => {
|
|
468
|
+
setBusy(true);
|
|
469
|
+
setError(void 0);
|
|
470
|
+
scope.set("paths", payloadOf(rows)).then(() => {
|
|
471
|
+
setDirty(false);
|
|
472
|
+
}).catch((cause) => {
|
|
473
|
+
setError(String(cause));
|
|
474
|
+
}).finally(() => {
|
|
475
|
+
setBusy(false);
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
const hostEntriesOf = (path) => preview?.entries.filter((entry) => entry.raw === path.trim()) ?? [];
|
|
479
|
+
const hostEntryOf = (path) => hostEntriesOf(path)[0];
|
|
480
|
+
const picker = !manualBase && candidates.length > 0;
|
|
481
|
+
const known = candidates.includes(typedBase);
|
|
482
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
483
|
+
style: styles.page,
|
|
484
|
+
children: [
|
|
485
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: css }),
|
|
486
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
487
|
+
style: styles.intro,
|
|
488
|
+
children: [
|
|
489
|
+
"这些路径在会话工作区之外也可以写,",
|
|
490
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "不需要审批" }),
|
|
491
|
+
";写工具与终端都按下面的「作用面」生效。 相对路径按「基准工作区」解析——执法时用的是",
|
|
492
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "各会话自己的工作区" }),
|
|
493
|
+
",所以同一份配置在不同会话会指向不同目录。"
|
|
494
|
+
]
|
|
495
|
+
}),
|
|
496
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
497
|
+
style: styles.baseRow,
|
|
498
|
+
children: [
|
|
499
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
500
|
+
style: styles.cardTitle,
|
|
501
|
+
children: "基准工作区"
|
|
502
|
+
}),
|
|
503
|
+
picker ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
504
|
+
className: "xp-select",
|
|
505
|
+
style: styles.baseField,
|
|
506
|
+
value: known ? typedBase : "",
|
|
507
|
+
onChange: (event) => {
|
|
508
|
+
setCwdPinned(true);
|
|
509
|
+
setCwd(event.target.value);
|
|
510
|
+
},
|
|
511
|
+
children: [known ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
512
|
+
value: typedBase,
|
|
513
|
+
children: typedBase === "" ? "(未选择)" : typedBase
|
|
514
|
+
}), candidates.map((path) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
515
|
+
value: path,
|
|
516
|
+
children: path
|
|
517
|
+
}, path))]
|
|
518
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
519
|
+
className: "xp-input",
|
|
520
|
+
style: styles.baseField,
|
|
521
|
+
value: cwd,
|
|
522
|
+
placeholder: "绝对路径,或以 ~/ 开头(例如 ~/projects)",
|
|
523
|
+
onChange: (event) => {
|
|
524
|
+
setCwdPinned(true);
|
|
525
|
+
setCwd(event.target.value);
|
|
526
|
+
}
|
|
527
|
+
}),
|
|
528
|
+
candidates.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
529
|
+
type: "button",
|
|
530
|
+
className: "xp-link",
|
|
531
|
+
onClick: () => {
|
|
532
|
+
setManualBase(!manualBase);
|
|
533
|
+
},
|
|
534
|
+
children: picker ? "手填" : "从列表选"
|
|
535
|
+
}) : null,
|
|
536
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
537
|
+
style: styles.dim,
|
|
538
|
+
children: "仅用于预览与行内解析"
|
|
539
|
+
})
|
|
540
|
+
]
|
|
541
|
+
}),
|
|
542
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
543
|
+
style: styles.toolbar,
|
|
544
|
+
children: [
|
|
545
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
546
|
+
type: "button",
|
|
547
|
+
className: "xp-button xp-button-on",
|
|
548
|
+
disabled: busy || !dirty,
|
|
549
|
+
onClick: save,
|
|
550
|
+
children: busy ? "保存中…" : "保存"
|
|
551
|
+
}),
|
|
552
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
553
|
+
type: "button",
|
|
554
|
+
className: "xp-button",
|
|
555
|
+
onClick: () => {
|
|
556
|
+
append("");
|
|
557
|
+
},
|
|
558
|
+
children: "添加路径"
|
|
559
|
+
}),
|
|
560
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
561
|
+
type: "button",
|
|
562
|
+
className: "xp-button",
|
|
563
|
+
onClick: () => {
|
|
564
|
+
append("..");
|
|
565
|
+
},
|
|
566
|
+
children: "添加工作区上一层(..)"
|
|
567
|
+
}),
|
|
568
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
569
|
+
type: "button",
|
|
570
|
+
className: "xp-button",
|
|
571
|
+
disabled: !dirty,
|
|
572
|
+
onClick: reset,
|
|
573
|
+
children: "放弃修改"
|
|
574
|
+
}),
|
|
575
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
576
|
+
style: styles.dim,
|
|
577
|
+
children: dirty ? "有未保存的修改" : "已与配置同步"
|
|
578
|
+
})
|
|
579
|
+
]
|
|
580
|
+
}),
|
|
581
|
+
rows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
582
|
+
style: styles.dim,
|
|
583
|
+
children: "还没有配置路径:用上面的「添加路径」或「添加工作区上一层(..)」开始。"
|
|
584
|
+
}) : null,
|
|
585
|
+
rows.map((row, index) => {
|
|
586
|
+
const patternRow = row.path.includes("*");
|
|
587
|
+
const resolved = patternRow ? void 0 : resolveLexically(row.path, base, preview?.home);
|
|
588
|
+
const hostMatches = hostEntriesOf(row.path);
|
|
589
|
+
const hostEntry = hostEntryOf(row.path);
|
|
590
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
591
|
+
style: styles.card,
|
|
592
|
+
children: [
|
|
593
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
594
|
+
style: styles.cardHead,
|
|
595
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
596
|
+
style: styles.cardTitle,
|
|
597
|
+
children: ["路径 ", index + 1]
|
|
598
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
599
|
+
style: styles.cardHeadRight,
|
|
600
|
+
children: [hostEntry !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
601
|
+
style: STATUS_STYLE[hostEntry.status],
|
|
602
|
+
children: [
|
|
603
|
+
"[",
|
|
604
|
+
STATUS_LABEL[hostEntry.status],
|
|
605
|
+
hostMatches.length > 1 ? ` ×${hostMatches.length}` : "",
|
|
606
|
+
"]"
|
|
607
|
+
]
|
|
608
|
+
}) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
609
|
+
type: "button",
|
|
610
|
+
className: "xp-link",
|
|
611
|
+
onClick: () => {
|
|
612
|
+
setDirty(true);
|
|
613
|
+
setRows((current) => current.filter((_, i) => i !== index));
|
|
614
|
+
},
|
|
615
|
+
children: "删除"
|
|
616
|
+
})]
|
|
617
|
+
})]
|
|
618
|
+
}),
|
|
619
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
620
|
+
className: "xp-input",
|
|
621
|
+
style: styles.pathInput,
|
|
622
|
+
value: row.path,
|
|
623
|
+
placeholder: "~/projects/notes/home、../某仓库、..(上一层)、~/projects/**/.worktrees/..(模式)",
|
|
624
|
+
onChange: (event) => {
|
|
625
|
+
update(index, { path: event.target.value });
|
|
626
|
+
}
|
|
627
|
+
}),
|
|
628
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
629
|
+
style: styles.resolvedRow,
|
|
630
|
+
children: patternRow ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
631
|
+
style: styles.dim,
|
|
632
|
+
children: [
|
|
633
|
+
"模式:由宿主按目录结构展开",
|
|
634
|
+
" ",
|
|
635
|
+
hostMatches.length > 0 ? `当前命中 ${hostMatches.length} 个目录(见下方预览)` : "(暂无命中,或被展开上限拦截)"
|
|
636
|
+
]
|
|
637
|
+
}) : resolved === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
638
|
+
style: styles.dim,
|
|
639
|
+
children: row.path.trim() === "" ? "填入路径后这里会显示解析结果" : typedBase === "" ? "相对路径需要基准工作区:请在上面选择或填写" : !usableBase ? "基准工作区需要绝对路径,或以 ~/ 开头(例如 ~/projects)" : "~ 需要宿主的家目录(第一次预览返回后即可解析)"
|
|
640
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
641
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
642
|
+
style: styles.dim,
|
|
643
|
+
children: "解析为"
|
|
644
|
+
}),
|
|
645
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
646
|
+
style: styles.code,
|
|
647
|
+
children: resolved
|
|
648
|
+
}),
|
|
649
|
+
hostEntry !== void 0 && hostEntry.resolved !== resolved ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
650
|
+
style: styles.dim,
|
|
651
|
+
children: [
|
|
652
|
+
"(宿主解析:",
|
|
653
|
+
hostEntry.resolved,
|
|
654
|
+
")"
|
|
655
|
+
]
|
|
656
|
+
}) : null
|
|
657
|
+
] })
|
|
658
|
+
}),
|
|
659
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
660
|
+
style: styles.controlsRow,
|
|
661
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
662
|
+
style: styles.field,
|
|
663
|
+
children: ["生效模式", /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
664
|
+
className: "xp-select",
|
|
665
|
+
value: row.scope,
|
|
666
|
+
onChange: (event) => {
|
|
667
|
+
update(index, { scope: event.target.value });
|
|
668
|
+
},
|
|
669
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
670
|
+
value: "write",
|
|
671
|
+
children: SCOPE_LABEL.write
|
|
672
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
673
|
+
value: "always-write",
|
|
674
|
+
children: SCOPE_LABEL["always-write"]
|
|
675
|
+
})]
|
|
676
|
+
})]
|
|
677
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
678
|
+
style: styles.pills,
|
|
679
|
+
children: [
|
|
680
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
681
|
+
style: styles.dim,
|
|
682
|
+
children: "作用面"
|
|
683
|
+
}),
|
|
684
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
685
|
+
type: "button",
|
|
686
|
+
className: row.surfaces.includes("fs") ? "xp-button xp-button-on" : "xp-button xp-button-off",
|
|
687
|
+
onClick: () => {
|
|
688
|
+
toggleSurface(index, "fs");
|
|
689
|
+
},
|
|
690
|
+
children: "写工具"
|
|
691
|
+
}),
|
|
692
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
693
|
+
type: "button",
|
|
694
|
+
className: row.surfaces.includes("shell") ? "xp-button xp-button-on" : "xp-button xp-button-off",
|
|
695
|
+
onClick: () => {
|
|
696
|
+
toggleSurface(index, "shell");
|
|
697
|
+
},
|
|
698
|
+
children: "终端"
|
|
699
|
+
})
|
|
700
|
+
]
|
|
701
|
+
})]
|
|
702
|
+
})
|
|
703
|
+
]
|
|
704
|
+
}, index);
|
|
705
|
+
}),
|
|
706
|
+
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
707
|
+
style: styles.warn,
|
|
708
|
+
children: error
|
|
709
|
+
}),
|
|
710
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
711
|
+
style: styles.panel,
|
|
712
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
713
|
+
style: styles.panelHead,
|
|
714
|
+
children: [
|
|
715
|
+
"解析预览",
|
|
716
|
+
dirty ? "(含未保存修改)" : "",
|
|
717
|
+
preview !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
718
|
+
style: styles.dim,
|
|
719
|
+
children: [
|
|
720
|
+
"生效根 ",
|
|
721
|
+
preview.effective.length,
|
|
722
|
+
" 条"
|
|
723
|
+
]
|
|
724
|
+
}) : null
|
|
725
|
+
]
|
|
726
|
+
}), typedBase === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
727
|
+
style: styles.dim,
|
|
728
|
+
children: "先在上面选择或填写「基准工作区」,这里就会显示宿主解析出的生效根。"
|
|
729
|
+
}) : !usableBase ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
730
|
+
style: styles.dim,
|
|
731
|
+
children: "基准工作区需要绝对路径,或以 ~/ 开头(例如 ~/projects);相对路径不能当基准用。"
|
|
732
|
+
}) : base === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
733
|
+
style: styles.dim,
|
|
734
|
+
children: "正在展开 ~:宿主的家目录会在第一次预览返回后给出。"
|
|
735
|
+
}) : preview === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
736
|
+
style: styles.dim,
|
|
737
|
+
children: "预览不可用(宿主没提供该路由、连接还没就绪,或基准工作区被宿主拒绝)。"
|
|
738
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [preview.entries.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
739
|
+
style: styles.dim,
|
|
740
|
+
children: "还没有可解析的路径。"
|
|
741
|
+
}) : preview.entries.map((entry, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
742
|
+
style: styles.entry,
|
|
743
|
+
children: [
|
|
744
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
745
|
+
style: STATUS_STYLE[entry.status],
|
|
746
|
+
children: [
|
|
747
|
+
"[",
|
|
748
|
+
STATUS_LABEL[entry.status],
|
|
749
|
+
"]"
|
|
750
|
+
]
|
|
751
|
+
}),
|
|
752
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
753
|
+
style: styles.code,
|
|
754
|
+
children: entry.raw
|
|
755
|
+
}),
|
|
756
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
757
|
+
style: styles.dim,
|
|
758
|
+
children: "→"
|
|
759
|
+
}),
|
|
760
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
761
|
+
style: styles.code,
|
|
762
|
+
children: entry.resolved === "" ? "(未解析)" : entry.resolved
|
|
763
|
+
})
|
|
764
|
+
]
|
|
765
|
+
}, `${index}-${entry.raw}`)), preview.warnings.map((warning) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
766
|
+
style: styles.warn,
|
|
767
|
+
children: warning
|
|
768
|
+
}, warning))] })]
|
|
769
|
+
})
|
|
770
|
+
]
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
//#endregion
|
|
774
|
+
//#region src/client/index.tsx
|
|
775
|
+
/**
|
|
776
|
+
* Client half: contributes the Extra paths configuration page to the settings
|
|
777
|
+
* dialog twice — as a `settings.section` nav row (the settings sidebar) and as
|
|
778
|
+
* the plugin's own card (0.1.5: `settings.plugin.item`, keyed by the settings
|
|
779
|
+
* namespace; 0.2.x: `plugins.item`, a list slot).
|
|
780
|
+
*
|
|
781
|
+
* TWO HOST GENERATIONS, ONE PAGE. The settings scope this page edits moved in
|
|
782
|
+
* 0.2.0: `ctx.settingsScope` (0.1.5) is gone and replaced by `ctx.configForms`
|
|
783
|
+
* — which however exposes the SAME three methods the page was written against
|
|
784
|
+
* (`getSnapshot`/`subscribe`/`set`). So the page keeps its narrow `PageScope`
|
|
785
|
+
* interface and this file supplies whichever implementation the running host
|
|
786
|
+
* has, through a late-bound proxy: the scope may not exist yet when the plugin
|
|
787
|
+
* activates, and listing an absent service in `inject` would leave the plugin
|
|
788
|
+
* waiting forever.
|
|
789
|
+
*
|
|
790
|
+
* Slot keys, register shapes and the module table were taken from the RUNNING
|
|
791
|
+
* version's own official occupants (`dsh-client-ui-settings-plugins`,
|
|
792
|
+
* `dsh-client-ui-settings-agent-loop`) and their published contracts. A slot key
|
|
793
|
+
* that nothing declares is inert under `ctx.slots.inject` (the callback never
|
|
794
|
+
* runs), which is what lets one build register into both generations' cards.
|
|
795
|
+
*
|
|
796
|
+
* Every @deepseek-ai/* import here is TYPE-ONLY (erased): the runtime services
|
|
797
|
+
* arrive through cordis, and react resolves from the page's module table
|
|
798
|
+
* (see dsh.client in package.json).
|
|
799
|
+
* @module dsh-extra-paths/client
|
|
800
|
+
*/
|
|
801
|
+
/**
|
|
802
|
+
* Client services this half needs.
|
|
803
|
+
*
|
|
804
|
+
* Only `slots`: the settings scope is fetched late-bound below, because the
|
|
805
|
+
* 0.1.5 (`settingsScope`) and 0.2.x (`configForms`) providers differ and an
|
|
806
|
+
* `inject` entry for a service that never appears would block activation.
|
|
807
|
+
*/
|
|
808
|
+
const inject = ["slots"];
|
|
809
|
+
/** The settings namespace this page edits — the one the host half registers. */
|
|
810
|
+
const NAMESPACE = "extra-paths";
|
|
811
|
+
/**
|
|
812
|
+
* A `PageScope` that forwards to whichever real scope arrives.
|
|
813
|
+
*
|
|
814
|
+
* Subscribers are held here rather than on the real scope so a page that mounted
|
|
815
|
+
* before the service appeared still repaints once it does.
|
|
816
|
+
* @returns a stable scope plus its attach hook.
|
|
817
|
+
*/
|
|
818
|
+
function lateBoundScope() {
|
|
819
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
820
|
+
let real;
|
|
821
|
+
let unsubscribe;
|
|
822
|
+
const notify = () => {
|
|
823
|
+
for (const listener of [...listeners]) listener();
|
|
824
|
+
};
|
|
825
|
+
return {
|
|
826
|
+
scope: {
|
|
827
|
+
getSnapshot: () => real?.getSnapshot() ?? {
|
|
828
|
+
status: "loading",
|
|
829
|
+
value: void 0
|
|
830
|
+
},
|
|
831
|
+
subscribe: (listener) => {
|
|
832
|
+
listeners.add(listener);
|
|
833
|
+
return () => {
|
|
834
|
+
listeners.delete(listener);
|
|
835
|
+
};
|
|
836
|
+
},
|
|
837
|
+
set: (field, value) => real?.set(field, value) ?? Promise.resolve()
|
|
838
|
+
},
|
|
839
|
+
attach: (next) => {
|
|
840
|
+
if (next === void 0) return;
|
|
841
|
+
unsubscribe?.();
|
|
842
|
+
real = next;
|
|
843
|
+
unsubscribe = next.subscribe(notify);
|
|
844
|
+
notify();
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Client entry.
|
|
850
|
+
* @param ctx - the client context.
|
|
851
|
+
*/
|
|
852
|
+
function apply(ctx) {
|
|
853
|
+
const { scope, attach } = lateBoundScope();
|
|
854
|
+
ctx.inject(["settingsScope"], (child) => {
|
|
855
|
+
const { settingsScope } = child;
|
|
856
|
+
attach(settingsScope.bind({ namespace: NAMESPACE }));
|
|
857
|
+
});
|
|
858
|
+
ctx.inject(["configForms"], (child) => {
|
|
859
|
+
const { configForms } = child;
|
|
860
|
+
attach({
|
|
861
|
+
getSnapshot: () => configForms.get(NAMESPACE).getSnapshot(),
|
|
862
|
+
subscribe: (listener) => configForms.get(NAMESPACE).subscribe(listener),
|
|
863
|
+
set: (field, value) => configForms.get(NAMESPACE).set(field, value).then(() => void 0)
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
const getWorkspaces = () => ctx.get("workspaces", false);
|
|
867
|
+
const props = () => ({
|
|
868
|
+
scope,
|
|
869
|
+
getWorkspaces
|
|
870
|
+
});
|
|
871
|
+
const page = () => react.createElement(ExtraPathsPage, props());
|
|
872
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
873
|
+
name: "settings.section",
|
|
874
|
+
id: NAMESPACE,
|
|
875
|
+
order: 40,
|
|
876
|
+
label: () => "额外可写路径",
|
|
877
|
+
locale: NAMESPACE,
|
|
878
|
+
inject: props
|
|
879
|
+
}, page));
|
|
880
|
+
ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
|
|
881
|
+
name: "settings.plugin.item",
|
|
882
|
+
key: NAMESPACE,
|
|
883
|
+
locale: NAMESPACE,
|
|
884
|
+
inject: props
|
|
885
|
+
}, page));
|
|
886
|
+
const registerCard = () => ctx.slots.inject("plugins.item", () => ctx.slots.register({
|
|
887
|
+
name: "plugins.item",
|
|
888
|
+
id: NAMESPACE,
|
|
889
|
+
order: 40,
|
|
890
|
+
label: () => "额外可写路径",
|
|
891
|
+
locale: NAMESPACE,
|
|
892
|
+
inject: props
|
|
893
|
+
}, page));
|
|
894
|
+
const forms = ctx.get("configForms", false);
|
|
895
|
+
if (typeof forms?.whileServed === "function" && typeof ctx.effect === "function") ctx.effect(() => forms.whileServed?.(["extra-paths"], registerCard) ?? registerCard(), "extra-paths: card while served");
|
|
896
|
+
else registerCard();
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
exports.NAMESPACE = NAMESPACE;
|
|
900
|
+
exports.apply = apply;
|
|
901
|
+
exports.inject = inject;
|
|
902
|
+
exports.lateBoundScope = lateBoundScope;
|
|
903
|
+
return module.exports;
|
|
904
|
+
}
|
|
905
|
+
});
|