@lmzhen/dsh-evolution-client-kit 0.32.6 → 0.34.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/index.js +58 -35
- package/lib/types/panel.d.ts +7 -0
- package/lib/types/panel.js +7 -1
- package/lib/types/seam.d.ts +6 -0
- package/lib/types/settings-seat.d.ts +5 -0
- package/lib/types/settings-seat.js +49 -30
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -61,7 +61,9 @@ function registerSidebarPanel(ctx, spec) {
|
|
|
61
61
|
yield seam.slots.register({
|
|
62
62
|
name: "main",
|
|
63
63
|
key: spec.id,
|
|
64
|
-
inject: () => spec.body(t)
|
|
64
|
+
inject: () => spec.body(t),
|
|
65
|
+
...spec.children === void 0 ? {} : { children: spec.children },
|
|
66
|
+
...spec.store === void 0 ? {} : { store: spec.store }
|
|
65
67
|
}, spec.component);
|
|
66
68
|
});
|
|
67
69
|
}
|
|
@@ -185,34 +187,51 @@ function createForm(namespace, ctx) {
|
|
|
185
187
|
...EMPTY,
|
|
186
188
|
reason: "seat-missing"
|
|
187
189
|
};
|
|
190
|
+
let lastReady;
|
|
191
|
+
let generation = 0;
|
|
188
192
|
const listeners = /* @__PURE__ */ new Set();
|
|
189
|
-
let
|
|
190
|
-
let listening = false;
|
|
193
|
+
let remoteOff;
|
|
191
194
|
const notify = () => {
|
|
192
195
|
for (const listener of listeners) listener();
|
|
193
196
|
};
|
|
194
|
-
const
|
|
195
|
-
|
|
197
|
+
const absorb = (next) => {
|
|
198
|
+
if (next.status === "ready") {
|
|
199
|
+
lastReady = next;
|
|
200
|
+
snapshot = next;
|
|
201
|
+
} else if (lastReady !== void 0) snapshot = {
|
|
202
|
+
...lastReady,
|
|
203
|
+
stale: true,
|
|
204
|
+
reason: next.reason ?? "readback-failed"
|
|
205
|
+
};
|
|
206
|
+
else snapshot = next;
|
|
196
207
|
notify();
|
|
197
208
|
};
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
const refresh = async () => {
|
|
210
|
+
const ticket = ++generation;
|
|
211
|
+
const next = await describe(namespace);
|
|
212
|
+
if (ticket !== generation) return;
|
|
213
|
+
absorb(next);
|
|
214
|
+
};
|
|
215
|
+
const remote = () => ctx.get?.("remote");
|
|
216
|
+
const stopRemote = () => {
|
|
217
|
+
remoteOff?.();
|
|
218
|
+
remoteOff = void 0;
|
|
219
|
+
};
|
|
220
|
+
const startRemote = () => {
|
|
221
|
+
if (remoteOff !== void 0) return;
|
|
222
|
+
remoteOff = remote()?.$on?.("settings/document-updated", (changed) => {
|
|
223
|
+
if (changed === namespace) refresh();
|
|
224
|
+
});
|
|
208
225
|
};
|
|
209
226
|
const form = {
|
|
210
227
|
getSnapshot: () => snapshot,
|
|
211
228
|
subscribe: (listener) => {
|
|
212
229
|
listeners.add(listener);
|
|
213
|
-
|
|
230
|
+
startRemote();
|
|
231
|
+
refresh();
|
|
214
232
|
return () => {
|
|
215
233
|
listeners.delete(listener);
|
|
234
|
+
if (listeners.size === 0) stopRemote();
|
|
216
235
|
};
|
|
217
236
|
},
|
|
218
237
|
set: async (field, value) => await form.mutate([{
|
|
@@ -226,35 +245,39 @@ function createForm(namespace, ctx) {
|
|
|
226
245
|
}]),
|
|
227
246
|
mutate: async (ops, expectedRevision) => {
|
|
228
247
|
const outcome = await write(namespace, ops, expectedRevision ?? snapshot.revision);
|
|
229
|
-
if (outcome.snapshot !== void 0)
|
|
230
|
-
|
|
231
|
-
notify();
|
|
232
|
-
} else await refresh();
|
|
248
|
+
if (outcome.snapshot !== void 0) absorb(outcome.snapshot);
|
|
249
|
+
else await refresh();
|
|
233
250
|
return outcome.ok;
|
|
251
|
+
},
|
|
252
|
+
refresh,
|
|
253
|
+
dispose: () => {
|
|
254
|
+
stopRemote();
|
|
255
|
+
listeners.clear();
|
|
234
256
|
}
|
|
235
257
|
};
|
|
236
258
|
return form;
|
|
237
259
|
}
|
|
238
260
|
/**
|
|
239
|
-
* Build one
|
|
240
|
-
*
|
|
241
|
-
*
|
|
261
|
+
* Build one seat per client registration; every form's remote listener is released by
|
|
262
|
+
* the caller's effect. No module-level WeakMap: a replaced registration must not share
|
|
263
|
+
* a dead seat with the previous one.
|
|
242
264
|
*/
|
|
243
|
-
const seats = /* @__PURE__ */ new WeakMap();
|
|
244
265
|
function createSettingsSeat(ctx) {
|
|
245
|
-
const cached = seats.get(ctx);
|
|
246
|
-
if (cached !== void 0) return cached;
|
|
247
266
|
const forms = /* @__PURE__ */ new Map();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
form
|
|
252
|
-
|
|
267
|
+
return {
|
|
268
|
+
get(namespace) {
|
|
269
|
+
let form = forms.get(namespace);
|
|
270
|
+
if (form === void 0) {
|
|
271
|
+
form = createForm(namespace, ctx);
|
|
272
|
+
forms.set(namespace, form);
|
|
273
|
+
}
|
|
274
|
+
return form;
|
|
275
|
+
},
|
|
276
|
+
dispose: () => {
|
|
277
|
+
for (const form of forms.values()) form.dispose?.();
|
|
278
|
+
forms.clear();
|
|
253
279
|
}
|
|
254
|
-
|
|
255
|
-
} };
|
|
256
|
-
seats.set(ctx, seat);
|
|
257
|
-
return seat;
|
|
280
|
+
};
|
|
258
281
|
}
|
|
259
282
|
//#endregion
|
|
260
283
|
//#region lib/types/workspace.js
|
package/lib/types/panel.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export interface SidebarPanelSpec<Face> {
|
|
|
34
34
|
component: (props: never) => ReactNode;
|
|
35
35
|
/** The body face factory; receives the bound translator. */
|
|
36
36
|
body: (t: Translate) => Face;
|
|
37
|
+
/** Child slots the main keyed occupant declares (the rc.3 main contract). */
|
|
38
|
+
children?: Readonly<Record<string, {
|
|
39
|
+
readonly kind: 'list' | 'keyed';
|
|
40
|
+
readonly scope: 'root';
|
|
41
|
+
}>>;
|
|
42
|
+
/** Optional store owned by this registration; the platform binds it to the occupant. */
|
|
43
|
+
store?: unknown;
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
46
|
* Register one sidebar row and its main body under one lifecycle.
|
package/lib/types/panel.js
CHANGED
|
@@ -52,7 +52,13 @@ export function registerSidebarPanel(ctx, spec) {
|
|
|
52
52
|
const label = () => lookup('entry.label');
|
|
53
53
|
seam.slots.inject('sidebar.panellist', function* () {
|
|
54
54
|
yield seam.slots.register({ name: 'sidebar.panellist', id: spec.id, order: spec.order, label }, spec.icon);
|
|
55
|
-
yield seam.slots.register({
|
|
55
|
+
yield seam.slots.register({
|
|
56
|
+
name: 'main',
|
|
57
|
+
key: spec.id,
|
|
58
|
+
inject: () => spec.body(t),
|
|
59
|
+
...(spec.children === undefined ? {} : { children: spec.children }),
|
|
60
|
+
...(spec.store === undefined ? {} : { store: spec.store }),
|
|
61
|
+
}, spec.component);
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
64
|
//# sourceMappingURL=panel.js.map
|
package/lib/types/seam.d.ts
CHANGED
|
@@ -64,9 +64,15 @@ export interface ConfigFormLike<T = Record<string, unknown>> {
|
|
|
64
64
|
unset(field: string): Promise<boolean>;
|
|
65
65
|
/** Atomic multi-field save; `expectedRevision` is the read the caller is replacing. */
|
|
66
66
|
mutate(ops: readonly ConfigPathOpLike[], expectedRevision?: number): Promise<boolean>;
|
|
67
|
+
/** Re-read the row (used by the card's readback verdict). */
|
|
68
|
+
refresh?(): Promise<void>;
|
|
69
|
+
/** Stop the form's remote subscription; owned by the seat. */
|
|
70
|
+
dispose?(): void;
|
|
67
71
|
}
|
|
68
72
|
export interface ConfigFormsSeat {
|
|
69
73
|
get<T = Record<string, unknown>>(entryId: string): ConfigFormLike<T> | undefined;
|
|
74
|
+
/** Release every form's remote listener; called from the client effect. */
|
|
75
|
+
dispose?(): void;
|
|
70
76
|
}
|
|
71
77
|
export interface SettingsFace {
|
|
72
78
|
merge?: ConfigFormLike;
|
|
@@ -15,6 +15,11 @@ interface ContextLike {
|
|
|
15
15
|
$on?: (event: string, listener: (namespace: string) => void) => () => void;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Build one seat per client registration; every form's remote listener is released by
|
|
20
|
+
* the caller's effect. No module-level WeakMap: a replaced registration must not share
|
|
21
|
+
* a dead seat with the previous one.
|
|
22
|
+
*/
|
|
18
23
|
export declare function createSettingsSeat(ctx: ContextLike): ConfigFormsSeat;
|
|
19
24
|
export {};
|
|
20
25
|
//# sourceMappingURL=settings-seat.d.ts.map
|
|
@@ -45,62 +45,78 @@ async function write(namespace, ops, expectedRevision) {
|
|
|
45
45
|
}
|
|
46
46
|
function createForm(namespace, ctx) {
|
|
47
47
|
let snapshot = { ...EMPTY, reason: 'seat-missing' };
|
|
48
|
+
let lastReady;
|
|
49
|
+
let generation = 0;
|
|
48
50
|
const listeners = new Set();
|
|
49
|
-
let
|
|
50
|
-
let listening = false;
|
|
51
|
+
let remoteOff;
|
|
51
52
|
const notify = () => { for (const listener of listeners)
|
|
52
53
|
listener(); };
|
|
53
|
-
const
|
|
54
|
-
|
|
54
|
+
const absorb = (next) => {
|
|
55
|
+
if (next.status === 'ready') {
|
|
56
|
+
lastReady = next;
|
|
57
|
+
snapshot = next;
|
|
58
|
+
}
|
|
59
|
+
else if (lastReady !== undefined) {
|
|
60
|
+
// A failed re-read must not erase the last usable values. Keep ready + mark stale;
|
|
61
|
+
// the card shows the values with a warning instead of claiming the plugin is absent.
|
|
62
|
+
snapshot = { ...lastReady, stale: true, reason: next.reason ?? 'readback-failed' };
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
snapshot = next;
|
|
66
|
+
}
|
|
55
67
|
notify();
|
|
56
68
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
69
|
+
const refresh = async () => {
|
|
70
|
+
const ticket = ++generation;
|
|
71
|
+
const next = await describe(namespace);
|
|
72
|
+
if (ticket !== generation)
|
|
73
|
+
return;
|
|
74
|
+
absorb(next);
|
|
75
|
+
};
|
|
76
|
+
const remote = () => ctx.get?.('remote');
|
|
77
|
+
const stopRemote = () => { remoteOff?.(); remoteOff = undefined; };
|
|
78
|
+
const startRemote = () => {
|
|
79
|
+
if (remoteOff !== undefined)
|
|
59
80
|
return;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
listening = true;
|
|
63
|
-
const remote = ctx.get?.('remote');
|
|
64
|
-
remote?.$on?.('settings/document-updated', (changed) => { if (changed === namespace)
|
|
65
|
-
void refresh(); });
|
|
66
|
-
}
|
|
67
|
-
void refresh();
|
|
81
|
+
remoteOff = remote()?.$on?.('settings/document-updated', (changed) => { if (changed === namespace)
|
|
82
|
+
void refresh(); });
|
|
68
83
|
};
|
|
69
84
|
const form = {
|
|
70
85
|
getSnapshot: () => snapshot,
|
|
71
86
|
subscribe: (listener) => {
|
|
72
87
|
listeners.add(listener);
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
startRemote();
|
|
89
|
+
void refresh();
|
|
90
|
+
return () => {
|
|
91
|
+
listeners.delete(listener);
|
|
92
|
+
if (listeners.size === 0)
|
|
93
|
+
stopRemote();
|
|
94
|
+
};
|
|
75
95
|
},
|
|
76
96
|
set: async (field, value) => (await form.mutate([{ op: 'set', path: [field], value }])),
|
|
77
97
|
unset: async (field) => (await form.mutate([{ op: 'unset', path: [field] }])),
|
|
78
98
|
mutate: async (ops, expectedRevision) => {
|
|
79
99
|
const revision = expectedRevision ?? snapshot.revision;
|
|
80
100
|
const outcome = await write(namespace, ops, revision);
|
|
81
|
-
if (outcome.snapshot !== undefined)
|
|
82
|
-
|
|
83
|
-
notify();
|
|
84
|
-
}
|
|
101
|
+
if (outcome.snapshot !== undefined)
|
|
102
|
+
absorb(outcome.snapshot);
|
|
85
103
|
else
|
|
86
104
|
await refresh();
|
|
87
105
|
return outcome.ok;
|
|
88
106
|
},
|
|
107
|
+
refresh,
|
|
108
|
+
dispose: () => { stopRemote(); listeners.clear(); },
|
|
89
109
|
};
|
|
90
110
|
return form;
|
|
91
111
|
}
|
|
92
112
|
/**
|
|
93
|
-
* Build one
|
|
94
|
-
*
|
|
95
|
-
*
|
|
113
|
+
* Build one seat per client registration; every form's remote listener is released by
|
|
114
|
+
* the caller's effect. No module-level WeakMap: a replaced registration must not share
|
|
115
|
+
* a dead seat with the previous one.
|
|
96
116
|
*/
|
|
97
|
-
const seats = new WeakMap();
|
|
98
117
|
export function createSettingsSeat(ctx) {
|
|
99
|
-
const cached = seats.get(ctx);
|
|
100
|
-
if (cached !== undefined)
|
|
101
|
-
return cached;
|
|
102
118
|
const forms = new Map();
|
|
103
|
-
|
|
119
|
+
return {
|
|
104
120
|
get(namespace) {
|
|
105
121
|
let form = forms.get(namespace);
|
|
106
122
|
if (form === undefined) {
|
|
@@ -109,8 +125,11 @@ export function createSettingsSeat(ctx) {
|
|
|
109
125
|
}
|
|
110
126
|
return form;
|
|
111
127
|
},
|
|
128
|
+
dispose: () => {
|
|
129
|
+
for (const form of forms.values())
|
|
130
|
+
form.dispose?.();
|
|
131
|
+
forms.clear();
|
|
132
|
+
},
|
|
112
133
|
};
|
|
113
|
-
seats.set(ctx, seat);
|
|
114
|
-
return seat;
|
|
115
134
|
}
|
|
116
135
|
//# sourceMappingURL=settings-seat.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-client-kit",
|
|
3
3
|
"description": "Shared browser seams and lifecycle for the evolution family sidebar panels (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.34.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|