@lmzhen/dsh-evolution-client-kit 0.46.0 → 0.48.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/lib/generated/fallbacks.generated.js +1 -2
- package/lib/generated/routes.generated.js +1 -5
- package/lib/index.js +59 -576
- package/lib/types/generated/contracts.generated.d.ts +0 -2
- package/lib/types/generated/fallbacks.generated.d.ts +1 -1
- package/lib/types/generated/fallbacks.generated.js +0 -3
- package/lib/types/generated/routes.generated.d.ts +1 -5
- package/lib/types/generated/routes.generated.js +0 -4
- package/lib/types/index.d.ts +3 -12
- package/lib/types/index.js +3 -9
- package/lib/types/locale.d.ts +17 -0
- package/lib/types/locale.js +53 -0
- package/lib/types/panel.d.ts +2 -3
- package/lib/types/panel.js +4 -47
- package/lib/types/presentation/action-menu.d.ts +0 -14
- package/lib/types/presentation/action-menu.js +0 -25
- package/lib/types/styles.d.ts +4 -0
- package/lib/types/styles.js +13 -0
- package/lib/types/workbench-view.js +4 -43
- package/package.json +1 -1
- package/lib/types/action.d.ts +0 -42
- package/lib/types/action.js +0 -46
- package/lib/types/async-resource.d.ts +0 -48
- package/lib/types/async-resource.js +0 -96
- package/lib/types/notice.d.ts +0 -18
- package/lib/types/notice.js +0 -17
- package/lib/types/presentation/chips.d.ts +0 -23
- package/lib/types/presentation/chips.js +0 -24
- package/lib/types/presentation/disclosure-group.d.ts +0 -13
- package/lib/types/presentation/disclosure-group.js +0 -11
- package/lib/types/presentation/time-text.d.ts +0 -15
- package/lib/types/presentation/time-text.js +0 -20
- package/lib/types/settings-gateway.d.ts +0 -68
- package/lib/types/settings-gateway.js +0 -52
- package/lib/types/settings-seat.d.ts +0 -21
- package/lib/types/settings-seat.js +0 -172
package/lib/index.js
CHANGED
|
@@ -4,20 +4,58 @@ import "./generated/contracts.generated.js";
|
|
|
4
4
|
import { Block, FailureBlock, failureText, loadStateOf } from "./generated/states.generated.js";
|
|
5
5
|
import { TOKENS, TOKEN_CSS, tokenVars } from "./tokens.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
|
-
import { createElement
|
|
7
|
+
import { createElement } from "react";
|
|
8
8
|
//#region \0rolldown/runtime.js
|
|
9
9
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
|
-
/** Fail loud when a client bundle is mounted without the shell seats it consumes. */
|
|
11
|
-
function requireClientSeats(ctx, owner) {
|
|
12
|
-
const candidate = ctx;
|
|
13
|
-
if (candidate.slots === void 0 || candidate.locale === void 0) throw new Error(owner + ": the client slots/locale seats are not mounted");
|
|
14
|
-
return candidate;
|
|
15
|
-
}
|
|
16
10
|
function interpolate(text, values) {
|
|
17
11
|
if (values === void 0) return text;
|
|
18
12
|
return text.replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ""));
|
|
19
13
|
}
|
|
20
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Fill `{slot}` placeholders, keeping an unmatched placeholder visible.
|
|
16
|
+
* This is the panel-copy contract (a missing value is a bug to see, not an empty string).
|
|
17
|
+
*/
|
|
18
|
+
function fillTemplate(text, values) {
|
|
19
|
+
if (values === void 0) return text;
|
|
20
|
+
return text.replace(/\{(\w+)\}/g, (match, key) => {
|
|
21
|
+
const value = values[key];
|
|
22
|
+
return value === void 0 ? match : String(value);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** Register one namespace's dictionaries and bind a fallback-first lookup. */
|
|
26
|
+
function bindLocale(ctx, namespace, dictionaries, fallback = "en", register = true) {
|
|
27
|
+
const seam = ctx;
|
|
28
|
+
let registered = !register;
|
|
29
|
+
if (register) ctx.effect(() => {
|
|
30
|
+
try {
|
|
31
|
+
const dispose = seam.locale.register(namespace, dictionaries);
|
|
32
|
+
registered = true;
|
|
33
|
+
return dispose;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
ctx.logger.warn(namespace + ": the locale seat refused the dictionary (" + String(error) + "); falls back to the bundle copy");
|
|
36
|
+
return () => {};
|
|
37
|
+
}
|
|
38
|
+
}, namespace + ": locale");
|
|
39
|
+
const own = dictionaries[fallback] ?? dictionaries.en;
|
|
40
|
+
const lookup = (key) => {
|
|
41
|
+
const fallbackText = own[key] ?? key;
|
|
42
|
+
if (!registered) return fallbackText;
|
|
43
|
+
try {
|
|
44
|
+
return seam.locale.bind(namespace)(key);
|
|
45
|
+
} catch {
|
|
46
|
+
return fallbackText;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
t: (key, values) => interpolate(lookup(key), values),
|
|
51
|
+
label: () => lookup("entry.label")
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region lib/types/styles.js
|
|
56
|
+
/** The one owner of plugin `<style>` tags; a new owner replaces the old tag so the
|
|
57
|
+
* old disposer only removes a detached node. */
|
|
58
|
+
function injectPluginStyles(doc, css, tagId) {
|
|
21
59
|
if (doc === void 0) return () => {};
|
|
22
60
|
doc.querySelector("style[data-plugin-css=\"" + tagId + "\"]")?.remove();
|
|
23
61
|
const tag = doc.createElement("style");
|
|
@@ -28,6 +66,14 @@ function injectStyles$1(doc, css, tagId) {
|
|
|
28
66
|
tag.remove();
|
|
29
67
|
};
|
|
30
68
|
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region lib/types/panel.js
|
|
71
|
+
/** Fail loud when a client bundle is mounted without the shell seats it consumes. */
|
|
72
|
+
function requireClientSeats(ctx, owner) {
|
|
73
|
+
const candidate = ctx;
|
|
74
|
+
if (candidate.slots === void 0 || candidate.locale === void 0) throw new Error(owner + ": the client slots/locale seats are not mounted");
|
|
75
|
+
return candidate;
|
|
76
|
+
}
|
|
31
77
|
/**
|
|
32
78
|
* Register one sidebar row and its main body under one lifecycle.
|
|
33
79
|
* @param ctx - the client context carrying the slots and locale seats.
|
|
@@ -35,30 +81,8 @@ function injectStyles$1(doc, css, tagId) {
|
|
|
35
81
|
*/
|
|
36
82
|
function registerSidebarPanel(ctx, spec) {
|
|
37
83
|
const seam = ctx;
|
|
38
|
-
|
|
39
|
-
ctx.
|
|
40
|
-
try {
|
|
41
|
-
const dispose = seam.locale.register(spec.namespace, spec.dictionaries);
|
|
42
|
-
registered = true;
|
|
43
|
-
return dispose;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
ctx.logger.warn(spec.namespace + ": the locale seat refused the dictionary (" + String(error) + "); the panel falls back to the bundle copy");
|
|
46
|
-
return () => {};
|
|
47
|
-
}
|
|
48
|
-
}, spec.namespace + ": locale");
|
|
49
|
-
ctx.effect(() => injectStyles$1(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
50
|
-
const fallback = spec.dictionaries[spec.fallback ?? "en"] ?? spec.dictionaries.en;
|
|
51
|
-
const lookup = (key) => {
|
|
52
|
-
const own = fallback[key] ?? key;
|
|
53
|
-
if (!registered) return own;
|
|
54
|
-
try {
|
|
55
|
-
return seam.locale.bind(spec.namespace)(key);
|
|
56
|
-
} catch {
|
|
57
|
-
return own;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const t = (key, values) => interpolate(lookup(key), values);
|
|
61
|
-
const label = () => lookup("entry.label");
|
|
84
|
+
ctx.effect(() => injectPluginStyles(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
85
|
+
const { t, label } = bindLocale(ctx, spec.namespace, spec.dictionaries, spec.fallback ?? "en");
|
|
62
86
|
seam.slots.inject("sidebar.panellist", function* () {
|
|
63
87
|
yield seam.slots.register({
|
|
64
88
|
name: "sidebar.panellist",
|
|
@@ -77,17 +101,6 @@ function registerSidebarPanel(ctx, spec) {
|
|
|
77
101
|
}
|
|
78
102
|
//#endregion
|
|
79
103
|
//#region lib/types/workbench-view.js
|
|
80
|
-
function injectStyles(doc, css, tagId) {
|
|
81
|
-
if (doc === void 0) return () => {};
|
|
82
|
-
doc.querySelector("style[data-plugin-css=\"" + tagId + "\"]")?.remove();
|
|
83
|
-
const tag = doc.createElement("style");
|
|
84
|
-
tag.setAttribute("data-plugin-css", tagId);
|
|
85
|
-
tag.textContent = css;
|
|
86
|
-
doc.head.appendChild(tag);
|
|
87
|
-
return () => {
|
|
88
|
-
tag.remove();
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
104
|
/**
|
|
92
105
|
* Register one view into `evolution.workbench.view`.
|
|
93
106
|
* @param ctx - client cordis context.
|
|
@@ -95,33 +108,8 @@ function injectStyles(doc, css, tagId) {
|
|
|
95
108
|
*/
|
|
96
109
|
function registerWorkbenchView(ctx, spec) {
|
|
97
110
|
const seam = ctx;
|
|
98
|
-
|
|
99
|
-
ctx.
|
|
100
|
-
try {
|
|
101
|
-
const dispose = seam.locale.register(spec.namespace, spec.dictionaries);
|
|
102
|
-
registered = true;
|
|
103
|
-
return dispose;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
ctx.logger.warn(spec.namespace + ": locale refused (" + String(error) + "); the view falls back to the bundle copy");
|
|
106
|
-
return () => {};
|
|
107
|
-
}
|
|
108
|
-
}, spec.namespace + ": locale");
|
|
109
|
-
ctx.effect(() => injectStyles(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
110
|
-
const fallback = spec.dictionaries["en"];
|
|
111
|
-
const lookup = (key) => {
|
|
112
|
-
const own = fallback[key] ?? key;
|
|
113
|
-
if (!registered) return own;
|
|
114
|
-
try {
|
|
115
|
-
return seam.locale.bind(spec.namespace)(key);
|
|
116
|
-
} catch {
|
|
117
|
-
return own;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const t = (key, values) => {
|
|
121
|
-
const template = lookup(key);
|
|
122
|
-
if (values === void 0) return template;
|
|
123
|
-
return template.replace(/\{(\w+)\}/g, (match, slot) => values[slot] === void 0 ? match : String(values[slot]));
|
|
124
|
-
};
|
|
111
|
+
ctx.effect(() => injectPluginStyles(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
112
|
+
const { t } = bindLocale(ctx, spec.namespace, spec.dictionaries);
|
|
125
113
|
seam.slots.inject("evolution.workbench.view", function* () {
|
|
126
114
|
yield seam.slots.register({
|
|
127
115
|
name: "evolution.workbench.view",
|
|
@@ -133,202 +121,6 @@ function registerWorkbenchView(ctx, spec) {
|
|
|
133
121
|
});
|
|
134
122
|
}
|
|
135
123
|
//#endregion
|
|
136
|
-
//#region lib/types/settings-seat.js
|
|
137
|
-
const SETTINGS_DESCRIBE = ROUTES.settings.describe;
|
|
138
|
-
const SETTINGS_MUTATE = ROUTES.settings.mutate;
|
|
139
|
-
const EMPTY = Object.freeze({
|
|
140
|
-
status: "unavailable",
|
|
141
|
-
value: void 0,
|
|
142
|
-
user: void 0,
|
|
143
|
-
writable: false,
|
|
144
|
-
base: void 0,
|
|
145
|
-
revision: void 0,
|
|
146
|
-
reason: "transport"
|
|
147
|
-
});
|
|
148
|
-
function snapshotFrom(value, ns) {
|
|
149
|
-
if (typeof value !== "object" || value === null) return EMPTY;
|
|
150
|
-
const list = value.namespaces;
|
|
151
|
-
if (!Array.isArray(list)) return EMPTY;
|
|
152
|
-
const item = list.find((candidate) => typeof candidate === "object" && candidate !== null && candidate.ns === ns);
|
|
153
|
-
return item === void 0 ? {
|
|
154
|
-
...EMPTY,
|
|
155
|
-
reason: "not-served"
|
|
156
|
-
} : item;
|
|
157
|
-
}
|
|
158
|
-
async function describe(namespace) {
|
|
159
|
-
try {
|
|
160
|
-
const response = await fetch(SETTINGS_DESCRIBE, { headers: { accept: "application/json" } });
|
|
161
|
-
if (!response.ok) return EMPTY;
|
|
162
|
-
const body = await response.json();
|
|
163
|
-
if (body.ok !== true) return EMPTY;
|
|
164
|
-
return snapshotFrom(body.data, namespace);
|
|
165
|
-
} catch {
|
|
166
|
-
return EMPTY;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Classify one refused write from the exact route's response: the route answers 409 for a revision
|
|
171
|
-
* CAS loss and 400 with an "invalid config" error for a schema refusal, so the card can name the
|
|
172
|
-
* right cause instead of calling every refusal a concurrent edit.
|
|
173
|
-
* @param response - the non-ok response.
|
|
174
|
-
* @returns the refusal class; anything the route did not name stays transport.
|
|
175
|
-
*/
|
|
176
|
-
async function refusalKind(response) {
|
|
177
|
-
if (response.status === 409) return "conflict";
|
|
178
|
-
try {
|
|
179
|
-
const body = await response.json();
|
|
180
|
-
return typeof body.error === "string" && body.error.startsWith("invalid config") ? "validation" : "transport";
|
|
181
|
-
} catch {
|
|
182
|
-
return "transport";
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async function write(namespace, ops, expectedRevision) {
|
|
186
|
-
try {
|
|
187
|
-
const response = await fetch(SETTINGS_MUTATE, {
|
|
188
|
-
method: "POST",
|
|
189
|
-
headers: {
|
|
190
|
-
"content-type": "application/json",
|
|
191
|
-
accept: "application/json"
|
|
192
|
-
},
|
|
193
|
-
body: JSON.stringify({
|
|
194
|
-
ns: namespace,
|
|
195
|
-
ops,
|
|
196
|
-
...expectedRevision === void 0 ? {} : { expectedRevision }
|
|
197
|
-
})
|
|
198
|
-
});
|
|
199
|
-
if (!response.ok) return {
|
|
200
|
-
ok: false,
|
|
201
|
-
kind: await refusalKind(response)
|
|
202
|
-
};
|
|
203
|
-
const body = await response.json();
|
|
204
|
-
return {
|
|
205
|
-
ok: body.ok === true,
|
|
206
|
-
snapshot: snapshotFrom(body.data, namespace)
|
|
207
|
-
};
|
|
208
|
-
} catch {
|
|
209
|
-
return {
|
|
210
|
-
ok: false,
|
|
211
|
-
kind: "transport"
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function createForm(namespace, ctx) {
|
|
216
|
-
let snapshot = {
|
|
217
|
-
...EMPTY,
|
|
218
|
-
reason: "seat-missing"
|
|
219
|
-
};
|
|
220
|
-
let lastReady;
|
|
221
|
-
let generation = 0;
|
|
222
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
223
|
-
let remoteOff;
|
|
224
|
-
const notify = () => {
|
|
225
|
-
for (const listener of listeners) listener();
|
|
226
|
-
};
|
|
227
|
-
const absorb = (next) => {
|
|
228
|
-
if (next.status === "ready") {
|
|
229
|
-
lastReady = next;
|
|
230
|
-
snapshot = next;
|
|
231
|
-
} else if (lastReady !== void 0) snapshot = {
|
|
232
|
-
...lastReady,
|
|
233
|
-
stale: true,
|
|
234
|
-
reason: next.reason ?? "readback-failed"
|
|
235
|
-
};
|
|
236
|
-
else snapshot = next;
|
|
237
|
-
notify();
|
|
238
|
-
};
|
|
239
|
-
const refresh = async () => {
|
|
240
|
-
startRemote();
|
|
241
|
-
const ticket = ++generation;
|
|
242
|
-
const next = await describe(namespace);
|
|
243
|
-
if (ticket !== generation) return;
|
|
244
|
-
absorb(next);
|
|
245
|
-
};
|
|
246
|
-
const remote = () => ctx.get?.("remote");
|
|
247
|
-
const stopRemote = () => {
|
|
248
|
-
remoteOff?.();
|
|
249
|
-
remoteOff = void 0;
|
|
250
|
-
};
|
|
251
|
-
const startRemote = () => {
|
|
252
|
-
if (remoteOff !== void 0) return;
|
|
253
|
-
remoteOff = remote()?.$on?.("settings/document-updated", (changed) => {
|
|
254
|
-
if (changed === namespace) refresh();
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
const form = {
|
|
258
|
-
getSnapshot: () => snapshot,
|
|
259
|
-
subscribe: (listener) => {
|
|
260
|
-
listeners.add(listener);
|
|
261
|
-
startRemote();
|
|
262
|
-
refresh();
|
|
263
|
-
return () => {
|
|
264
|
-
listeners.delete(listener);
|
|
265
|
-
if (listeners.size === 0) stopRemote();
|
|
266
|
-
};
|
|
267
|
-
},
|
|
268
|
-
set: async (field, value) => await form.mutate([{
|
|
269
|
-
op: "set",
|
|
270
|
-
path: [field],
|
|
271
|
-
value
|
|
272
|
-
}]),
|
|
273
|
-
unset: async (field) => await form.mutate([{
|
|
274
|
-
op: "unset",
|
|
275
|
-
path: [field]
|
|
276
|
-
}]),
|
|
277
|
-
save: async (ops, expectedRevision) => {
|
|
278
|
-
const outcome = await write(namespace, ops, expectedRevision ?? snapshot.revision);
|
|
279
|
-
if (outcome.snapshot !== void 0) absorb(outcome.snapshot);
|
|
280
|
-
else await refresh();
|
|
281
|
-
return outcome.ok ? { written: true } : {
|
|
282
|
-
written: false,
|
|
283
|
-
kind: outcome.kind ?? "transport"
|
|
284
|
-
};
|
|
285
|
-
},
|
|
286
|
-
mutate: async (ops, expectedRevision) => {
|
|
287
|
-
const outcome = await write(namespace, ops, expectedRevision ?? snapshot.revision);
|
|
288
|
-
if (outcome.snapshot !== void 0) absorb(outcome.snapshot);
|
|
289
|
-
else await refresh();
|
|
290
|
-
return outcome.ok;
|
|
291
|
-
},
|
|
292
|
-
refresh,
|
|
293
|
-
dispose: () => {
|
|
294
|
-
stopRemote();
|
|
295
|
-
listeners.clear();
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
return form;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Build/return the ONE seat for one ClientContext. All panels share the same form,
|
|
302
|
-
* snapshot and revision; dispose removes the seat so a replacement context starts clean.
|
|
303
|
-
*/
|
|
304
|
-
const seats = /* @__PURE__ */ new WeakMap();
|
|
305
|
-
function createSettingsSeat(ctx) {
|
|
306
|
-
const key = ctx;
|
|
307
|
-
const existing = seats.get(key);
|
|
308
|
-
if (existing !== void 0) return existing;
|
|
309
|
-
const forms = /* @__PURE__ */ new Map();
|
|
310
|
-
const seat = {
|
|
311
|
-
get(namespace) {
|
|
312
|
-
let form = forms.get(namespace);
|
|
313
|
-
if (form === void 0) {
|
|
314
|
-
form = createForm(namespace, ctx);
|
|
315
|
-
forms.set(namespace, form);
|
|
316
|
-
}
|
|
317
|
-
return form;
|
|
318
|
-
},
|
|
319
|
-
dispose: () => {
|
|
320
|
-
for (const form of forms.values()) form.dispose?.();
|
|
321
|
-
forms.clear();
|
|
322
|
-
seats.delete(key);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
seats.set(key, seat);
|
|
326
|
-
ctx.inject?.(["remote"], () => {
|
|
327
|
-
for (const form of forms.values()) form.refresh?.();
|
|
328
|
-
});
|
|
329
|
-
return seat;
|
|
330
|
-
}
|
|
331
|
-
//#endregion
|
|
332
124
|
//#region lib/types/workspace.js
|
|
333
125
|
/**
|
|
334
126
|
* Best-effort workspace id; a seat that is absent or refuses leaves the panel in local scope.
|
|
@@ -345,112 +137,6 @@ function panelWorkspaceId(ctx) {
|
|
|
345
137
|
} catch {}
|
|
346
138
|
}
|
|
347
139
|
//#endregion
|
|
348
|
-
//#region lib/types/async-resource.js
|
|
349
|
-
/**
|
|
350
|
-
* One read operation's lifecycle: initial load, background refresh, stale-answer
|
|
351
|
-
* suppression, and an explicit failure slot. Consumers derive `empty` from a
|
|
352
|
-
* successful `data` value; this type never conflates "not loaded yet" with
|
|
353
|
-
* "loaded and empty".
|
|
354
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
355
|
-
*/
|
|
356
|
-
/**
|
|
357
|
-
* Serialize one resource's reads without remounting the consumer.
|
|
358
|
-
*/
|
|
359
|
-
var AsyncResource = class {
|
|
360
|
-
#state = Object.freeze({
|
|
361
|
-
status: "loading",
|
|
362
|
-
refreshing: false,
|
|
363
|
-
data: void 0,
|
|
364
|
-
failure: void 0,
|
|
365
|
-
generation: 0
|
|
366
|
-
});
|
|
367
|
-
#listeners = /* @__PURE__ */ new Set();
|
|
368
|
-
#generation = 0;
|
|
369
|
-
#controller;
|
|
370
|
-
#disposed = false;
|
|
371
|
-
/** @returns the stable snapshot for uSES. */
|
|
372
|
-
getSnapshot() {
|
|
373
|
-
return this.#state;
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Observe snapshot replacements.
|
|
377
|
-
* @param listener - called after each publish.
|
|
378
|
-
* @returns the disposer.
|
|
379
|
-
*/
|
|
380
|
-
subscribe(listener) {
|
|
381
|
-
this.#listeners.add(listener);
|
|
382
|
-
return () => {
|
|
383
|
-
this.#listeners.delete(listener);
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Run one read. A prior read is aborted; only this generation may publish.
|
|
388
|
-
* @param load - loader receiving the cancellation signal.
|
|
389
|
-
* @returns settlement after this generation commits or is superseded.
|
|
390
|
-
*/
|
|
391
|
-
async load(load) {
|
|
392
|
-
if (this.#disposed) return;
|
|
393
|
-
const generation = this.#generation + 1;
|
|
394
|
-
this.#generation = generation;
|
|
395
|
-
this.#controller?.abort();
|
|
396
|
-
const controller = new AbortController();
|
|
397
|
-
this.#controller = controller;
|
|
398
|
-
const previous = this.#state;
|
|
399
|
-
this.#publish({
|
|
400
|
-
status: previous.data === void 0 ? "loading" : "ready",
|
|
401
|
-
refreshing: previous.data !== void 0,
|
|
402
|
-
data: previous.data,
|
|
403
|
-
failure: previous.failure,
|
|
404
|
-
generation
|
|
405
|
-
});
|
|
406
|
-
try {
|
|
407
|
-
const data = await load(controller.signal);
|
|
408
|
-
if (this.#disposed || generation !== this.#generation) return;
|
|
409
|
-
this.#publish({
|
|
410
|
-
status: "ready",
|
|
411
|
-
refreshing: false,
|
|
412
|
-
data,
|
|
413
|
-
failure: void 0,
|
|
414
|
-
generation
|
|
415
|
-
});
|
|
416
|
-
} catch (failure) {
|
|
417
|
-
if (this.#disposed || generation !== this.#generation || controller.signal.aborted) return;
|
|
418
|
-
this.#publish({
|
|
419
|
-
status: previous.data === void 0 ? "error" : "ready",
|
|
420
|
-
refreshing: false,
|
|
421
|
-
data: previous.data,
|
|
422
|
-
failure,
|
|
423
|
-
generation
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
/** Drop the current value and return to the initial loading state. */
|
|
428
|
-
reset() {
|
|
429
|
-
this.#generation += 1;
|
|
430
|
-
this.#controller?.abort();
|
|
431
|
-
this.#controller = void 0;
|
|
432
|
-
this.#publish({
|
|
433
|
-
status: "loading",
|
|
434
|
-
refreshing: false,
|
|
435
|
-
data: void 0,
|
|
436
|
-
failure: void 0,
|
|
437
|
-
generation: this.#generation
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
/** Abort the in-flight read and stop notifying. */
|
|
441
|
-
dispose() {
|
|
442
|
-
this.#disposed = true;
|
|
443
|
-
this.#generation += 1;
|
|
444
|
-
this.#controller?.abort();
|
|
445
|
-
this.#controller = void 0;
|
|
446
|
-
this.#listeners.clear();
|
|
447
|
-
}
|
|
448
|
-
#publish(state) {
|
|
449
|
-
this.#state = Object.freeze(state);
|
|
450
|
-
for (const listener of this.#listeners) listener();
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
//#endregion
|
|
454
140
|
//#region lib/types/format.js
|
|
455
141
|
/** Parse an ISO string, epoch ms, or null into a valid Date; null when absent/invalid. */
|
|
456
142
|
function toLocalDate(value) {
|
|
@@ -500,23 +186,6 @@ function isSameLocalDay(value, now = /* @__PURE__ */ new Date()) {
|
|
|
500
186
|
return date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
|
|
501
187
|
}
|
|
502
188
|
//#endregion
|
|
503
|
-
//#region lib/types/notice.js
|
|
504
|
-
/** One inline state notice: semantic tone plus text, no surface-specific styling. */
|
|
505
|
-
/**
|
|
506
|
-
* Render one informative/warning/error line. The caller owns the surface class and CSS;
|
|
507
|
-
* this leaf owns only the accessible role and the fact/count split.
|
|
508
|
-
* @param props - tone, text, optional count/class.
|
|
509
|
-
* @returns a semantic state notice.
|
|
510
|
-
*/
|
|
511
|
-
function StateNotice({ tone, text, count, className }) {
|
|
512
|
-
return createElement("div", {
|
|
513
|
-
"data-role": "state-notice",
|
|
514
|
-
"data-tone": tone,
|
|
515
|
-
role: tone === "error" ? "alert" : "status",
|
|
516
|
-
...className === void 0 ? {} : { className }
|
|
517
|
-
}, createElement("span", { "data-role": "state-notice-text" }, text), count === void 0 ? null : createElement("span", { "data-role": "state-notice-count" }, String(count)));
|
|
518
|
-
}
|
|
519
|
-
//#endregion
|
|
520
189
|
//#region lib/types/presentation/decision-frame.js
|
|
521
190
|
/** One decision card: title, facts, at most one primary, secondary actions and details. */
|
|
522
191
|
function actionButton$1(action, role) {
|
|
@@ -566,31 +235,6 @@ function TaskBanner({ count, text, className }) {
|
|
|
566
235
|
}, createElement("strong", { "data-role": "task-banner-count" }, String(count)), createElement("span", { "data-role": "task-banner-text" }, text));
|
|
567
236
|
}
|
|
568
237
|
//#endregion
|
|
569
|
-
//#region lib/types/presentation/chips.js
|
|
570
|
-
/** Read-only status chips and toggleable filter chips. */
|
|
571
|
-
/** Render one semantic status word. */
|
|
572
|
-
function StatusChip({ label, tone = "neutral", className }) {
|
|
573
|
-
return createElement("span", {
|
|
574
|
-
"data-role": "status-chip",
|
|
575
|
-
"data-tone": tone,
|
|
576
|
-
...className === void 0 ? {} : { className }
|
|
577
|
-
}, label);
|
|
578
|
-
}
|
|
579
|
-
/** Render a toggleable filter with the pressed state exposed to assistive tech. */
|
|
580
|
-
function FilterChip({ label, active, onClick, count, disabled = false, className }) {
|
|
581
|
-
return createElement("button", {
|
|
582
|
-
type: "button",
|
|
583
|
-
"data-role": "filter-chip",
|
|
584
|
-
"data-active": active ? "true" : "false",
|
|
585
|
-
"aria-pressed": active ? "true" : "false",
|
|
586
|
-
disabled,
|
|
587
|
-
...className === void 0 ? {} : { className },
|
|
588
|
-
onClick: () => {
|
|
589
|
-
if (!disabled) onClick();
|
|
590
|
-
}
|
|
591
|
-
}, createElement("span", { "data-role": "filter-chip-label" }, label), count === void 0 ? null : createElement("span", { "data-role": "filter-chip-count" }, String(count)));
|
|
592
|
-
}
|
|
593
|
-
//#endregion
|
|
594
238
|
//#region lib/types/presentation/empty-state.js
|
|
595
239
|
/** A compact completed/empty state with at most one primary next step. */
|
|
596
240
|
function actionButton(action, role) {
|
|
@@ -641,36 +285,6 @@ const RESPONSIVE_TABLE_CSS = [
|
|
|
641
285
|
"}"
|
|
642
286
|
].join(String.fromCharCode(10));
|
|
643
287
|
//#endregion
|
|
644
|
-
//#region lib/types/presentation/disclosure-group.js
|
|
645
|
-
/** A native details group for normal/secondary facts. */
|
|
646
|
-
/** Render a closed-by-default disclosure without introducing another accordion model. */
|
|
647
|
-
function DisclosureGroup({ summary, count, children, defaultOpen = false, className }) {
|
|
648
|
-
return createElement("details", {
|
|
649
|
-
"data-role": "disclosure-group",
|
|
650
|
-
...defaultOpen ? { open: true } : {},
|
|
651
|
-
...className === void 0 ? {} : { className }
|
|
652
|
-
}, createElement("summary", { "data-role": "disclosure-summary" }, createElement("span", { "data-role": "disclosure-title" }, summary), count === void 0 ? null : createElement("span", { "data-role": "disclosure-count" }, String(count))), createElement("div", { "data-role": "disclosure-content" }, children));
|
|
653
|
-
}
|
|
654
|
-
//#endregion
|
|
655
|
-
//#region lib/types/presentation/time-text.js
|
|
656
|
-
/** The one local-time presentation used by reading surfaces. */
|
|
657
|
-
/**
|
|
658
|
-
* Render a local wall time, or a neutral dash when the fact is unknown.
|
|
659
|
-
* @param props - ISO/epoch value and seconds preference.
|
|
660
|
-
* @returns a time element with the raw value in dateTime when valid.
|
|
661
|
-
*/
|
|
662
|
-
function TimeText({ value, seconds = true, className }) {
|
|
663
|
-
const text = formatLocalDateTime(value, { seconds });
|
|
664
|
-
const ms = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : NaN;
|
|
665
|
-
const raw = Number.isFinite(ms) ? new Date(ms).toISOString() : void 0;
|
|
666
|
-
return createElement("time", {
|
|
667
|
-
"data-role": "time-text",
|
|
668
|
-
...raw === void 0 ? {} : { dateTime: raw },
|
|
669
|
-
...text === null ? {} : { title: text },
|
|
670
|
-
...className === void 0 ? {} : { className }
|
|
671
|
-
}, text ?? "—");
|
|
672
|
-
}
|
|
673
|
-
//#endregion
|
|
674
288
|
//#region lib/types/presentation/action-menu.js
|
|
675
289
|
/**
|
|
676
290
|
* The one seam onto the platform's menu material, plus a small fallback for deployments
|
|
@@ -678,31 +292,6 @@ function TimeText({ value, seconds = true, className }) {
|
|
|
678
292
|
*/
|
|
679
293
|
const PLATFORM_UI_MODULE = "@deepseek-ai/dsh-client-ui-primitives";
|
|
680
294
|
/**
|
|
681
|
-
* Render the coordinate/action menu through the platform primitives, or a plain fallback.
|
|
682
|
-
* @param props - rows, accessible label, position/style and optional primitive override.
|
|
683
|
-
* @returns the menu element.
|
|
684
|
-
*/
|
|
685
|
-
function ActionMenu({ actions, label, style, className, primitives = PLATFORM_MENU }) {
|
|
686
|
-
if (primitives !== void 0) return renderPlatformMenu(primitives, actions, label, style ?? {}, className);
|
|
687
|
-
return createElement("div", {
|
|
688
|
-
"data-role": "action-menu-fallback",
|
|
689
|
-
role: "menu",
|
|
690
|
-
"aria-label": label,
|
|
691
|
-
...style === void 0 ? {} : { style },
|
|
692
|
-
...className === void 0 ? {} : { className }
|
|
693
|
-
}, actions.map((action) => createElement("button", {
|
|
694
|
-
key: action.id,
|
|
695
|
-
type: "button",
|
|
696
|
-
role: "menuitem",
|
|
697
|
-
disabled: action.disabled === true,
|
|
698
|
-
"data-danger": action.danger === true ? "true" : "false",
|
|
699
|
-
...action.separatorBefore === true ? { "data-separator-before": "true" } : {},
|
|
700
|
-
onClick: () => {
|
|
701
|
-
if (action.disabled !== true) action.onSelect();
|
|
702
|
-
}
|
|
703
|
-
}, action.label)));
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
295
|
* Render the platform menu directly. Kept exported for callers that already own the primitive row.
|
|
707
296
|
* @param primitives - platform MenuSurface/MenuItemButton pair.
|
|
708
297
|
* @param actions - rows in display order.
|
|
@@ -751,51 +340,6 @@ const PLATFORM_MENU = (() => {
|
|
|
751
340
|
}
|
|
752
341
|
})();
|
|
753
342
|
//#endregion
|
|
754
|
-
//#region lib/types/action.js
|
|
755
|
-
/**
|
|
756
|
-
* Command-only actions. Approval decisions are a separate host API and must never
|
|
757
|
-
* be represented as a copyable command here.
|
|
758
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
759
|
-
*/
|
|
760
|
-
/**
|
|
761
|
-
* Copy one command and report the host verdict.
|
|
762
|
-
* @param action - the command action.
|
|
763
|
-
* @param writeClipboard - platform clipboard writer.
|
|
764
|
-
* @param confirm - optional in-UI confirmation.
|
|
765
|
-
* @returns the settled copy status.
|
|
766
|
-
*/
|
|
767
|
-
async function copyAction(action, writeClipboard, confirm) {
|
|
768
|
-
if (action.enabled === false) return "idle";
|
|
769
|
-
if (confirm !== void 0 && !confirm(action)) return "idle";
|
|
770
|
-
if (action.confirm !== void 0 && !action.confirm(action)) return "idle";
|
|
771
|
-
try {
|
|
772
|
-
return await writeClipboard(action.command) ? "copied" : "failed";
|
|
773
|
-
} catch {
|
|
774
|
-
return "failed";
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Render one command-copy action with real success/failure feedback.
|
|
779
|
-
* @param props - action, clipboard writer, and localized labels.
|
|
780
|
-
* @returns the button and its status line.
|
|
781
|
-
*/
|
|
782
|
-
function CommandCopyButton({ action, writeClipboard, labels, className }) {
|
|
783
|
-
const [status, setStatus] = useState("idle");
|
|
784
|
-
const text = status === "copying" ? labels.copying : status === "copied" ? labels.copied : status === "failed" ? labels.failed : labels.copy;
|
|
785
|
-
return createElement("span", { className }, createElement("button", {
|
|
786
|
-
type: "button",
|
|
787
|
-
disabled: action.enabled === false || status === "copying",
|
|
788
|
-
"aria-label": action.label,
|
|
789
|
-
onClick: () => {
|
|
790
|
-
setStatus("copying");
|
|
791
|
-
copyAction(action, writeClipboard).then(setStatus);
|
|
792
|
-
}
|
|
793
|
-
}, action.label), createElement("span", {
|
|
794
|
-
role: "status",
|
|
795
|
-
"aria-live": "polite"
|
|
796
|
-
}, text === labels.copy ? "" : text));
|
|
797
|
-
}
|
|
798
|
-
//#endregion
|
|
799
343
|
//#region lib/types/surface.js
|
|
800
344
|
/**
|
|
801
345
|
* Shared opaque page surface. Skin images may sit behind the shell; every
|
|
@@ -807,65 +351,4 @@ const PAGE_SURFACE_CLASS = "evolution-page-surface";
|
|
|
807
351
|
/** Stylesheet for {@link PAGE_SURFACE_CLASS}; consumers append it to their own CSS. */
|
|
808
352
|
const PAGE_SURFACE_CSS = ".evolution-page-surface{min-height:100%;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}";
|
|
809
353
|
//#endregion
|
|
810
|
-
|
|
811
|
-
/**
|
|
812
|
-
* Save one atomic op list and always read back.
|
|
813
|
-
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
814
|
-
* @returns the write verdict plus the separate read-back verdict.
|
|
815
|
-
*/
|
|
816
|
-
async function saveSettings(options) {
|
|
817
|
-
const revision = options.scope.getSnapshot().revision;
|
|
818
|
-
let written = false;
|
|
819
|
-
let failure;
|
|
820
|
-
try {
|
|
821
|
-
written = (await options.api.mutate({
|
|
822
|
-
ns: options.namespace,
|
|
823
|
-
ops: options.ops,
|
|
824
|
-
...revision === void 0 ? {} : { expectedRevision: revision }
|
|
825
|
-
})).result.ok;
|
|
826
|
-
} catch (error) {
|
|
827
|
-
failure = error;
|
|
828
|
-
}
|
|
829
|
-
let readback = "ok";
|
|
830
|
-
try {
|
|
831
|
-
await options.scope.load();
|
|
832
|
-
} catch (error) {
|
|
833
|
-
readback = "failed";
|
|
834
|
-
failure ??= error;
|
|
835
|
-
}
|
|
836
|
-
return failure === void 0 ? {
|
|
837
|
-
written,
|
|
838
|
-
readback
|
|
839
|
-
} : {
|
|
840
|
-
written,
|
|
841
|
-
readback,
|
|
842
|
-
failure
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Bind each namespace once and reuse that scope for every later save.
|
|
847
|
-
* @param binder - the platform settings-scope service.
|
|
848
|
-
* @param api - the mutation transport.
|
|
849
|
-
* @returns a lookup that creates one gateway per namespace.
|
|
850
|
-
*/
|
|
851
|
-
function createSettingsGatewayCache(binder, api) {
|
|
852
|
-
const cache = /* @__PURE__ */ new Map();
|
|
853
|
-
return (namespace) => {
|
|
854
|
-
const existing = cache.get(namespace);
|
|
855
|
-
if (existing !== void 0) return existing;
|
|
856
|
-
const scope = binder.bind({ namespace });
|
|
857
|
-
const gateway = {
|
|
858
|
-
scope,
|
|
859
|
-
save: async (ops) => await saveSettings({
|
|
860
|
-
namespace,
|
|
861
|
-
scope,
|
|
862
|
-
api,
|
|
863
|
-
ops
|
|
864
|
-
})
|
|
865
|
-
};
|
|
866
|
-
cache.set(namespace, gateway);
|
|
867
|
-
return gateway;
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
//#endregion
|
|
871
|
-
export { ActionMenu, AsyncResource, Block, CommandCopyButton, DecisionFrame, DisclosureGroup, EmptyState, FALLBACKS, FailureBlock, FilterChip, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, PLATFORM_MENU, RESPONSIVE_TABLE_CSS, ROUTES, StateNotice, StatusChip, TOKENS, TOKEN_CSS, TaskBanner, TimeText, copyAction, createSettingsGatewayCache, createSettingsSeat, failureText, formatLocalClock, formatLocalDateTime, isSameLocalDay, loadStateOf, menuPrimitivesFrom, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, renderPlatformMenu, requireClientSeats, saveSettings, tokenVars };
|
|
354
|
+
export { Block, DecisionFrame, EmptyState, FALLBACKS, FailureBlock, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, PLATFORM_MENU, RESPONSIVE_TABLE_CSS, ROUTES, TOKENS, TOKEN_CSS, TaskBanner, bindLocale, failureText, fillTemplate, formatLocalClock, formatLocalDateTime, injectPluginStyles, isSameLocalDay, loadStateOf, menuPrimitivesFrom, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, renderPlatformMenu, requireClientSeats, tokenVars };
|