@linxin666/dsh-pet 0.4.10 → 0.4.11
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.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +4 -4
- package/lib/client.js +1092 -348
- package/lib/client.js.map +1 -1
- package/lib/types/client/PetPreview.d.ts +12 -0
- package/lib/types/client/PetPreview.d.ts.map +1 -0
- package/lib/types/client/PetPreview.js +32 -0
- package/lib/types/client/PetSettingsCard.d.ts +30 -2
- package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PetSettingsCard.js +48 -8
- package/lib/types/client/PluginSettingsCard.d.ts +131 -17
- package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PluginSettingsCard.js +158 -37
- package/lib/types/client/RangeBubble.d.ts +47 -0
- package/lib/types/client/RangeBubble.d.ts.map +1 -0
- package/lib/types/client/RangeBubble.js +107 -0
- package/lib/types/client/SegmentGroup.d.ts +29 -0
- package/lib/types/client/SegmentGroup.d.ts.map +1 -0
- package/lib/types/client/SegmentGroup.js +81 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +9 -28
- package/lib/types/client/locales.d.ts +36 -44
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/locales.js +36 -44
- package/lib/types/client/settings-form.d.ts +79 -41
- package/lib/types/client/settings-form.d.ts.map +1 -1
- package/lib/types/client/settings-form.js +96 -36
- package/lib/types/client/settings-registration.d.ts +15 -0
- package/lib/types/client/settings-registration.d.ts.map +1 -0
- package/lib/types/client/settings-registration.js +24 -0
- package/lib/types/client/web-extension-contract.d.ts +32 -0
- package/lib/types/client/web-extension-contract.d.ts.map +1 -0
- package/lib/types/client/web-extension-contract.js +6 -0
- package/lib/types/client/web-extension-page.d.ts +51 -0
- package/lib/types/client/web-extension-page.d.ts.map +1 -0
- package/lib/types/client/web-extension-page.js +122 -0
- package/package.json +1 -1
- package/src/client/PetPreview.tsx +51 -0
- package/src/client/PetSettingsCard.test.tsx +28 -22
- package/src/client/PetSettingsCard.tsx +201 -110
- package/src/client/PluginSettingsCard.tsx +369 -108
- package/src/client/RangeBubble.tsx +163 -0
- package/src/client/SegmentGroup.tsx +92 -0
- package/src/client/index.ts +9 -27
- package/src/client/locales.ts +36 -44
- package/src/client/settings-card.module.css +493 -91
- package/src/client/settings-form.ts +116 -49
- package/src/client/settings-registration.test.ts +79 -0
- package/src/client/settings-registration.ts +34 -0
- package/src/client/settings-section.module.css +182 -0
- package/src/client/web-extension-contract.ts +35 -0
- package/src/client/web-extension-page.ts +150 -0
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
// Generated by scripts/sync-shared.mjs from shared/client/settings/settings-form.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* Form model behind the plugin settings card. Every control applies itself:
|
|
3
|
+
* a pick (a segment, a select option, a reset) writes the moment it is made,
|
|
4
|
+
* and typed text writes once typing pauses or the reader leaves the field.
|
|
5
|
+
* Between the edit and the write the edit is held here as a draft, so what is
|
|
6
|
+
* on screen is exactly what the write will store; a write the Host refuses
|
|
7
|
+
* puts a pick back to the stored value and keeps typed text for correcting.
|
|
8
|
+
* Family-shared slice inlined into each plugin's client bundle.
|
|
9
9
|
*/
|
|
10
10
|
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store';
|
|
11
|
-
/**
|
|
11
|
+
/** How long typed text rests before it is written. */
|
|
12
|
+
export const TYPE_PAUSE_MS = 600;
|
|
13
|
+
/** A whole- or decimal-number field. An empty draft clears the field; any other draft that is not a finite number within the constraints stays unwritten. */
|
|
12
14
|
export function numberField(field, constraints = {}) {
|
|
13
15
|
const { integer = false, min } = constraints;
|
|
14
16
|
return {
|
|
15
17
|
field,
|
|
18
|
+
entry: 'type',
|
|
16
19
|
format: value => typeof value === 'number' ? String(value) : '',
|
|
17
20
|
parse: (text) => {
|
|
18
21
|
const trimmed = text.trim();
|
|
@@ -29,10 +32,14 @@ export function numberField(field, constraints = {}) {
|
|
|
29
32
|
},
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
35
|
+
/**
|
|
36
|
+
* A free-text field. An empty draft clears the field. `entry` is `pick` when
|
|
37
|
+
* the text arrives whole from a picker (a preset or a reasoning level).
|
|
38
|
+
*/
|
|
39
|
+
export function textField(field, entry = 'type') {
|
|
34
40
|
return {
|
|
35
41
|
field,
|
|
42
|
+
entry,
|
|
36
43
|
format: value => typeof value === 'string' ? value : '',
|
|
37
44
|
parse: (text) => {
|
|
38
45
|
const trimmed = text.trim();
|
|
@@ -53,6 +60,7 @@ export function secretField(field) {
|
|
|
53
60
|
export function booleanField(field) {
|
|
54
61
|
return {
|
|
55
62
|
field,
|
|
63
|
+
entry: 'pick',
|
|
56
64
|
format: value => typeof value === 'boolean' ? String(value) : '',
|
|
57
65
|
parse: (text) => {
|
|
58
66
|
const trimmed = text.trim();
|
|
@@ -70,6 +78,7 @@ export function booleanField(field) {
|
|
|
70
78
|
export function choiceField(field, choices) {
|
|
71
79
|
return {
|
|
72
80
|
field,
|
|
81
|
+
entry: 'pick',
|
|
73
82
|
format: value => typeof value === 'string' && choices.includes(value) ? value : '',
|
|
74
83
|
parse: (text) => {
|
|
75
84
|
if (text === '')
|
|
@@ -79,12 +88,14 @@ export function choiceField(field, choices) {
|
|
|
79
88
|
};
|
|
80
89
|
}
|
|
81
90
|
/**
|
|
82
|
-
*
|
|
91
|
+
* Applies one card's edits to one settings namespace as the reader makes them.
|
|
83
92
|
*
|
|
84
93
|
* The Host is the only authority on whether a value was accepted — its
|
|
85
94
|
* validators own the constraints no schema can express — so the outcome is
|
|
86
|
-
* read back from the section rather than predicted here. A
|
|
87
|
-
* land
|
|
95
|
+
* read back from the section rather than predicted here. A write that did not
|
|
96
|
+
* land puts each pick back to the stored value, the way a switch that could not
|
|
97
|
+
* flip springs back, and keeps typed text so the reader can correct it instead
|
|
98
|
+
* of retyping.
|
|
88
99
|
*/
|
|
89
100
|
export class CardForm {
|
|
90
101
|
scope;
|
|
@@ -94,7 +105,11 @@ export class CardForm {
|
|
|
94
105
|
/** The form subscription installed in the constructor; released by dispose(). */
|
|
95
106
|
disposeForm;
|
|
96
107
|
disposed = false;
|
|
108
|
+
/** The pending write of typed text, waiting for typing to pause. */
|
|
109
|
+
typePause;
|
|
97
110
|
saving = false;
|
|
111
|
+
/** A save asked for while one was in flight; it runs once the first settles (#1754). */
|
|
112
|
+
saveQueued = false;
|
|
98
113
|
failed = false;
|
|
99
114
|
failedReason;
|
|
100
115
|
/** @param scope - the bound configuration form for this card's namespace. */
|
|
@@ -111,6 +126,7 @@ export class CardForm {
|
|
|
111
126
|
if (this.disposed)
|
|
112
127
|
return;
|
|
113
128
|
this.disposed = true;
|
|
129
|
+
clearTimeout(this.typePause);
|
|
114
130
|
this.disposeForm();
|
|
115
131
|
this.listeners.clear();
|
|
116
132
|
}
|
|
@@ -120,7 +136,7 @@ export class CardForm {
|
|
|
120
136
|
this.listeners.add(() => { store.set(project()); });
|
|
121
137
|
return store;
|
|
122
138
|
}
|
|
123
|
-
/** Read the card-level state: what the Host serves, and what
|
|
139
|
+
/** Read the card-level state: what the Host serves, and what is still waiting to be written. */
|
|
124
140
|
shell() {
|
|
125
141
|
const snapshot = this.scope.getSnapshot();
|
|
126
142
|
const plan = this.plan();
|
|
@@ -156,8 +172,9 @@ export class CardForm {
|
|
|
156
172
|
resetField: (field) => {
|
|
157
173
|
this.stage(field, { text: this.specOf(field).format(this.baseValue(field)), clear: true });
|
|
158
174
|
},
|
|
159
|
-
save: () => {
|
|
175
|
+
save: () => { this.applyNow(); },
|
|
160
176
|
discard: () => {
|
|
177
|
+
clearTimeout(this.typePause);
|
|
161
178
|
if (this.staged.size === 0 && !this.failed)
|
|
162
179
|
return;
|
|
163
180
|
this.staged.clear();
|
|
@@ -168,31 +185,54 @@ export class CardForm {
|
|
|
168
185
|
};
|
|
169
186
|
}
|
|
170
187
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
188
|
+
* Run one write, and re-run it once if another was asked for while this one
|
|
189
|
+
* was still in flight.
|
|
190
|
+
*
|
|
191
|
+
* A write is a Host round trip that also drives the profile reconcile, and
|
|
192
|
+
* the Host runs it inside one exclusive transaction. Answering an edit that
|
|
193
|
+
* arrives mid-flight by returning immediately dropped it with no explanation
|
|
194
|
+
* (#1754). Serializing instead means an edit made while another write is
|
|
195
|
+
* still settling is written against the settled state.
|
|
196
|
+
* @returns settlement after the mutation and the read-back.
|
|
197
|
+
*/
|
|
198
|
+
async requestSave() {
|
|
199
|
+
if (this.saving) {
|
|
200
|
+
this.saveQueued = true;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
await this.save();
|
|
204
|
+
if (!this.saveQueued)
|
|
205
|
+
return;
|
|
206
|
+
this.saveQueued = false;
|
|
207
|
+
await this.requestSave();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Write every valid draft in one atomic form mutation, then re-seed from
|
|
211
|
+
* what the Host accepted. A draft the field does not accept stays on screen,
|
|
212
|
+
* unwritten, without holding the others back.
|
|
173
213
|
*
|
|
174
|
-
* The
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* the
|
|
214
|
+
* The batch rides one mutate, so cross-field validate hooks (baseURL+model)
|
|
215
|
+
* judge it as a unit: the Host either applies every write or refuses the
|
|
216
|
+
* batch. The form contract answers a refusal or a skipped write with `false`
|
|
217
|
+
* (it recovers with a fresh Host view instead of throwing), so the outcome is
|
|
218
|
+
* judged twice: the answer itself, and then the settled snapshot read back
|
|
219
|
+
* one planned write at a time. One missed write fails the whole batch. A
|
|
220
|
+
* transport that rejects instead (the dsh-web bridge controller on a dead
|
|
221
|
+
* connection) reports through the same failure path with its rejection
|
|
222
|
+
* message. A batch that did not land puts its picks and clears back to the
|
|
223
|
+
* stored value and keeps its typed text, so the reader can correct it.
|
|
184
224
|
* @returns settlement after the mutation and the read-back.
|
|
185
225
|
*/
|
|
186
226
|
async save() {
|
|
187
227
|
const plan = this.plan();
|
|
188
228
|
const valid = plan.filter((item) => item.judge !== undefined);
|
|
189
|
-
if (
|
|
229
|
+
if (valid.length === 0 || this.saving)
|
|
190
230
|
return;
|
|
191
|
-
// Snapshot the staged entries this
|
|
192
|
-
// is in flight (which replaces the same key) survives: only
|
|
193
|
-
// when the entry is still the one this
|
|
231
|
+
// Snapshot the staged entries this write carries, so an edit staged while
|
|
232
|
+
// it is in flight (which replaces the same key) survives: only settle the
|
|
233
|
+
// key when the entry is still the one this write started from.
|
|
194
234
|
const pending = new Map();
|
|
195
|
-
for (const item of
|
|
235
|
+
for (const item of valid)
|
|
196
236
|
pending.set(item.field, this.staged.get(item.field));
|
|
197
237
|
this.saving = true;
|
|
198
238
|
this.failed = false;
|
|
@@ -219,7 +259,9 @@ export class CardForm {
|
|
|
219
259
|
// whole save and keeps the drafts.
|
|
220
260
|
const landed = accepted && failedReason === undefined && valid.every(item => item.judge());
|
|
221
261
|
for (const [field, before] of pending) {
|
|
222
|
-
if (
|
|
262
|
+
if (this.staged.get(field) !== before)
|
|
263
|
+
continue;
|
|
264
|
+
if (landed || before === undefined || before.clear || this.specOf(field).entry === 'pick')
|
|
223
265
|
this.staged.delete(field);
|
|
224
266
|
}
|
|
225
267
|
this.saving = false;
|
|
@@ -231,9 +273,9 @@ export class CardForm {
|
|
|
231
273
|
this.publish();
|
|
232
274
|
}
|
|
233
275
|
/**
|
|
234
|
-
* Every staged edit a
|
|
235
|
-
* its field accepts carries no write: the form is still dirty, and the
|
|
236
|
-
*
|
|
276
|
+
* Every staged edit a write would carry. An entry whose draft is not a value
|
|
277
|
+
* its field accepts carries no write: the form is still dirty, and the draft
|
|
278
|
+
* stays on screen rather than being dropped. A staged edit that matches the
|
|
237
279
|
* effective section is not a write at all.
|
|
238
280
|
* @returns the planned writes, in the order the fields were staged.
|
|
239
281
|
*/
|
|
@@ -279,11 +321,29 @@ export class CardForm {
|
|
|
279
321
|
landedUnset(field) {
|
|
280
322
|
return !this.stored(field);
|
|
281
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Take one edit and schedule its write: a pick or a clear is written now,
|
|
326
|
+
* typed text once typing has rested for TYPE_PAUSE_MS.
|
|
327
|
+
*/
|
|
282
328
|
stage(field, edit) {
|
|
283
329
|
this.staged.set(field, edit);
|
|
284
330
|
this.failed = false;
|
|
285
331
|
this.failedReason = undefined;
|
|
286
332
|
this.publish();
|
|
333
|
+
if (edit.clear || this.specOf(field).entry === 'pick') {
|
|
334
|
+
this.applyNow();
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
clearTimeout(this.typePause);
|
|
338
|
+
this.typePause = setTimeout(() => { this.applyNow(); }, TYPE_PAUSE_MS);
|
|
339
|
+
}
|
|
340
|
+
/** Write every pending draft now, taking the place of a waiting pause. */
|
|
341
|
+
applyNow() {
|
|
342
|
+
clearTimeout(this.typePause);
|
|
343
|
+
this.typePause = undefined;
|
|
344
|
+
if (this.disposed)
|
|
345
|
+
return;
|
|
346
|
+
void this.requestSave();
|
|
287
347
|
}
|
|
288
348
|
specOf(field) {
|
|
289
349
|
const spec = this.specs.get(field);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pet settings page's contribution: the Web Extensions parent mounts it
|
|
3
|
+
* through its page service, while a standalone install keeps the original
|
|
4
|
+
* first-level settings section.
|
|
5
|
+
*/
|
|
6
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
7
|
+
import { type PetSettingsCardController } from './PetSettingsCard.tsx';
|
|
8
|
+
/**
|
|
9
|
+
* Register exactly one reachable pet entry and follow the parent across late
|
|
10
|
+
* loading or teardown. The controller belongs to apply(), not a registration,
|
|
11
|
+
* so moving seats never resets staged edits or subscriptions.
|
|
12
|
+
* @returns the page contribution's disposer.
|
|
13
|
+
*/
|
|
14
|
+
export declare function installPetSettingsRegistration(ctx: ClientContext, controller: PetSettingsCardController): () => void;
|
|
15
|
+
//# sourceMappingURL=settings-registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings-registration.d.ts","sourceRoot":"","sources":["../../../src/client/settings-registration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAKnE,OAAO,EAAsB,KAAK,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAI1F;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,yBAAyB,GACpC,MAAM,IAAI,CASZ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pet settings page's contribution: the Web Extensions parent mounts it
|
|
3
|
+
* through its page service, while a standalone install keeps the original
|
|
4
|
+
* first-level settings section.
|
|
5
|
+
*/
|
|
6
|
+
import { PetSettingsSection } from "./PetSettingsCard.js";
|
|
7
|
+
import { NS } from "./locales.js";
|
|
8
|
+
import { installWebExtensionPage } from "./web-extension-page.js";
|
|
9
|
+
/**
|
|
10
|
+
* Register exactly one reachable pet entry and follow the parent across late
|
|
11
|
+
* loading or teardown. The controller belongs to apply(), not a registration,
|
|
12
|
+
* so moving seats never resets staged edits or subscriptions.
|
|
13
|
+
* @returns the page contribution's disposer.
|
|
14
|
+
*/
|
|
15
|
+
export function installPetSettingsRegistration(ctx, controller) {
|
|
16
|
+
return installWebExtensionPage(ctx, {
|
|
17
|
+
key: 'pet',
|
|
18
|
+
order: 130,
|
|
19
|
+
locale: NS,
|
|
20
|
+
label: () => ctx.locale.bind(NS)('settings.title'),
|
|
21
|
+
inject: () => controller.inject(),
|
|
22
|
+
component: PetSettingsSection,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Web Extensions host contract consumed by the pet settings page. This
|
|
3
|
+
* package declares the collaboration types locally and never value-imports
|
|
4
|
+
* the host plugin, so a standalone pet install keeps working without it.
|
|
5
|
+
*/
|
|
6
|
+
import type { SettingsSectionOwnerProps } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
7
|
+
/** Optional navigator published by the Web Extensions parent section. */
|
|
8
|
+
export interface WebUiExtensionService {
|
|
9
|
+
/** The parent keeps the established first-level section id for deep links. */
|
|
10
|
+
readonly sectionId: 'web-ui-plugins';
|
|
11
|
+
/** Localized parent-section label used by the host's deep-link fallback. */
|
|
12
|
+
label(): string;
|
|
13
|
+
/** Open one extension tab by its keyed entry id. */
|
|
14
|
+
open(id: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
declare module '@deepseek-ai/cordis' {
|
|
17
|
+
interface Context {
|
|
18
|
+
/** Presence marks the Web Extensions parent as available. */
|
|
19
|
+
webUiExtensions?: WebUiExtensionService;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
23
|
+
interface SlotMap {
|
|
24
|
+
/** One keyed, root-scoped page inside the Web Extensions parent section. */
|
|
25
|
+
'web-ui.extension': {
|
|
26
|
+
kind: 'keyed';
|
|
27
|
+
scope: 'root';
|
|
28
|
+
owner: SettingsSectionOwnerProps;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=web-extension-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-extension-contract.d.ts","sourceRoot":"","sources":["../../../src/client/web-extension-contract.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAE3F,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAA;IACpC,4EAA4E;IAC5E,KAAK,IAAI,MAAM,CAAA;IACf,oDAAoD;IACpD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAA;CAC1B;AAED,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,6DAA6D;QAC7D,eAAe,CAAC,EAAE,qBAAqB,CAAA;KACxC;CACF;AAED,OAAO,QAAQ,kCAAkC,CAAC;IAChD,UAAU,OAAO;QACf,4EAA4E;QAC5E,kBAAkB,EAAE;YAClB,IAAI,EAAE,OAAO,CAAA;YACb,KAAK,EAAE,MAAM,CAAA;YACb,KAAK,EAAE,yBAAyB,CAAA;SACjC,CAAA;KACF;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One settings page's seat in either the Web Extensions parent or the legacy
|
|
3
|
+
* first-level settings navigation.
|
|
4
|
+
*
|
|
5
|
+
* The parent supplies the page contract; a child does not know which slot the
|
|
6
|
+
* parent uses internally. While `webUiExtensions` is live the page is handed
|
|
7
|
+
* to its service, which owns keyed mounting and disposal. Without the parent,
|
|
8
|
+
* the same component registers as its original first-level settings section,
|
|
9
|
+
* so a standalone install keeps a working entry.
|
|
10
|
+
*/
|
|
11
|
+
/** The parent service face this helper consumes. */
|
|
12
|
+
export interface WebExtensionPageService {
|
|
13
|
+
readonly sectionId: string;
|
|
14
|
+
registerPage(page: WebExtensionPageSeat): () => void;
|
|
15
|
+
}
|
|
16
|
+
/** Seat-independent page contribution. */
|
|
17
|
+
export interface WebExtensionPageSeat {
|
|
18
|
+
key: string;
|
|
19
|
+
order: number;
|
|
20
|
+
locale: string;
|
|
21
|
+
label(): string;
|
|
22
|
+
inject(): object;
|
|
23
|
+
component: unknown;
|
|
24
|
+
children?: Record<string, {
|
|
25
|
+
kind: 'keyed' | 'list';
|
|
26
|
+
scope: 'root';
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/** The slot-registry slice used for the standalone fallback. */
|
|
30
|
+
export interface WebExtensionPageSlots {
|
|
31
|
+
register(options: never, component: never): unknown;
|
|
32
|
+
spec?(key: string): unknown;
|
|
33
|
+
entries?(key: string): readonly {
|
|
34
|
+
component?: unknown;
|
|
35
|
+
options: Record<string, unknown>;
|
|
36
|
+
}[];
|
|
37
|
+
}
|
|
38
|
+
/** The context slice needed by the migration. */
|
|
39
|
+
export interface WebExtensionPageContext {
|
|
40
|
+
slots: WebExtensionPageSlots;
|
|
41
|
+
get?(name: string): unknown;
|
|
42
|
+
on?(event: string, listener: () => void): unknown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Keep exactly one reachable page contribution while the parent loads or
|
|
46
|
+
* unloads. The parent service owns integrated mounting; only the fallback uses
|
|
47
|
+
* this plugin's own slot registry. Slot disposal is synchronous, so the latch
|
|
48
|
+
* prevents a move from recursively registering a duplicate.
|
|
49
|
+
*/
|
|
50
|
+
export declare function installWebExtensionPage(ctx: WebExtensionPageContext, page: WebExtensionPageSeat): () => void;
|
|
51
|
+
//# sourceMappingURL=web-extension-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-extension-page.d.ts","sourceRoot":"","sources":["../../../src/client/web-extension-page.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,YAAY,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAA;CACrD;AAED,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,IAAI,MAAM,CAAA;IACf,MAAM,IAAI,MAAM,CAAA;IAChB,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACrE;AAED,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,OAAO,CAAA;IACnD,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,OAAO,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAAE,CAAA;CAC5F;AAED,iDAAiD;AACjD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,qBAAqB,CAAA;IAC5B,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAA;CAClD;AA4BD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,uBAAuB,EAC5B,IAAI,EAAE,oBAAoB,GACzB,MAAM,IAAI,CAwEZ"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One settings page's seat in either the Web Extensions parent or the legacy
|
|
3
|
+
* first-level settings navigation.
|
|
4
|
+
*
|
|
5
|
+
* The parent supplies the page contract; a child does not know which slot the
|
|
6
|
+
* parent uses internally. While `webUiExtensions` is live the page is handed
|
|
7
|
+
* to its service, which owns keyed mounting and disposal. Without the parent,
|
|
8
|
+
* the same component registers as its original first-level settings section,
|
|
9
|
+
* so a standalone install keeps a working entry.
|
|
10
|
+
*/
|
|
11
|
+
const SETTINGS_SECTION = 'settings.section';
|
|
12
|
+
const WEB_EXTENSION_SLOT = 'web-ui.extension';
|
|
13
|
+
function serviceOf(ctx) {
|
|
14
|
+
if (typeof ctx.get !== 'function')
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
const candidate = ctx.get('webUiExtensions');
|
|
18
|
+
return candidate !== null
|
|
19
|
+
&& typeof candidate === 'object'
|
|
20
|
+
&& typeof candidate.sectionId === 'string'
|
|
21
|
+
&& typeof candidate.registerPage === 'function'
|
|
22
|
+
? candidate
|
|
23
|
+
: undefined;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function warn(seat, error) {
|
|
30
|
+
try {
|
|
31
|
+
console.warn(`[dsh-web-settings] page "${seat}" could not be mounted`, error);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// A restricted console must not drop the remaining entry.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Keep exactly one reachable page contribution while the parent loads or
|
|
39
|
+
* unloads. The parent service owns integrated mounting; only the fallback uses
|
|
40
|
+
* this plugin's own slot registry. Slot disposal is synchronous, so the latch
|
|
41
|
+
* prevents a move from recursively registering a duplicate.
|
|
42
|
+
*/
|
|
43
|
+
export function installWebExtensionPage(ctx, page) {
|
|
44
|
+
let dispose;
|
|
45
|
+
let current;
|
|
46
|
+
let reconciling = false;
|
|
47
|
+
let disposed = false;
|
|
48
|
+
const present = (seat) => {
|
|
49
|
+
if (typeof ctx.slots.entries !== 'function')
|
|
50
|
+
return current === seat;
|
|
51
|
+
const slot = seat === 'integrated' ? WEB_EXTENSION_SLOT : SETTINGS_SECTION;
|
|
52
|
+
return ctx.slots.entries(slot).some(entry => entry.component === page.component
|
|
53
|
+
&& (seat === 'integrated' ? entry.options.key : entry.options.id) === page.key);
|
|
54
|
+
};
|
|
55
|
+
const registerSeat = (seat) => {
|
|
56
|
+
if (seat === 'integrated') {
|
|
57
|
+
const service = serviceOf(ctx);
|
|
58
|
+
if (service === undefined)
|
|
59
|
+
throw new Error('webUiExtensions service is unavailable');
|
|
60
|
+
return service.registerPage(page);
|
|
61
|
+
}
|
|
62
|
+
return ctx.slots.register({
|
|
63
|
+
name: SETTINGS_SECTION,
|
|
64
|
+
id: page.key,
|
|
65
|
+
order: page.order,
|
|
66
|
+
label: page.label,
|
|
67
|
+
locale: page.locale,
|
|
68
|
+
inject: page.inject,
|
|
69
|
+
...(page.children === undefined ? {} : { children: page.children }),
|
|
70
|
+
}, page.component);
|
|
71
|
+
};
|
|
72
|
+
const reconcile = () => {
|
|
73
|
+
if (disposed || reconciling)
|
|
74
|
+
return;
|
|
75
|
+
const target = serviceOf(ctx) === undefined ? 'legacy' : 'integrated';
|
|
76
|
+
if (current === target && present(target))
|
|
77
|
+
return;
|
|
78
|
+
const slot = target === 'integrated' ? WEB_EXTENSION_SLOT : SETTINGS_SECTION;
|
|
79
|
+
if (typeof ctx.slots.spec === 'function' && ctx.slots.spec(slot) === undefined)
|
|
80
|
+
return;
|
|
81
|
+
reconciling = true;
|
|
82
|
+
const previous = current;
|
|
83
|
+
const disposePrevious = dispose;
|
|
84
|
+
current = undefined;
|
|
85
|
+
dispose = undefined;
|
|
86
|
+
disposePrevious?.();
|
|
87
|
+
try {
|
|
88
|
+
dispose = registerSeat(target);
|
|
89
|
+
current = target;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
warn(target, error);
|
|
93
|
+
if (previous !== undefined && previous !== target) {
|
|
94
|
+
try {
|
|
95
|
+
dispose = registerSeat(previous);
|
|
96
|
+
current = previous;
|
|
97
|
+
}
|
|
98
|
+
catch (restoreError) {
|
|
99
|
+
warn(previous, restoreError);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
reconciling = false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
if (typeof ctx.on === 'function') {
|
|
108
|
+
try {
|
|
109
|
+
ctx.on('slots/changed', reconcile);
|
|
110
|
+
}
|
|
111
|
+
catch { /* the initial entry remains usable */ }
|
|
112
|
+
}
|
|
113
|
+
reconcile();
|
|
114
|
+
return () => {
|
|
115
|
+
if (disposed)
|
|
116
|
+
return;
|
|
117
|
+
disposed = true;
|
|
118
|
+
dispose?.();
|
|
119
|
+
dispose = undefined;
|
|
120
|
+
current = undefined;
|
|
121
|
+
};
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-pet",
|
|
3
3
|
"description": "Multi-pet companion plugin for the dsh web GUI: a registry-driven floating pet that reacts to model activity, with per-pet naming, petting/feeding interactions and an affinity score",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.11",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Lightweight, static pet thumbnails built from the registry's existing assets. */
|
|
2
|
+
|
|
3
|
+
import type { PetDefinition } from '../registry.ts'
|
|
4
|
+
import sectionCss from './settings-section.module.css'
|
|
5
|
+
|
|
6
|
+
/** Registry data needed by a thumbnail; older hosts may serve only id/name. */
|
|
7
|
+
export type PetPreviewDefinition = Pick<PetDefinition, 'id' | 'displayName'>
|
|
8
|
+
& Partial<Pick<PetDefinition, 'renderer' | 'cell' | 'columns' | 'atlasRows' | 'atlasUrl' | 'frames2d'>>
|
|
9
|
+
|
|
10
|
+
const PREVIEW_LIMIT = 72
|
|
11
|
+
const DEFAULT_CELL = { width: 192, height: 208 }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Render the atlas's first sprite cell or a frames2d idle frame. Live2d and
|
|
15
|
+
* incomplete legacy responses degrade to a text mark instead of a broken image.
|
|
16
|
+
*/
|
|
17
|
+
export function PetPreview(props: { pet: PetPreviewDefinition }) {
|
|
18
|
+
const { pet } = props
|
|
19
|
+
const renderer = pet.renderer ?? 'sprite2d'
|
|
20
|
+
if (renderer === 'sprite2d' && pet.atlasUrl !== undefined) {
|
|
21
|
+
const cell = pet.cell ?? DEFAULT_CELL
|
|
22
|
+
const scale = Math.min(PREVIEW_LIMIT / cell.width, PREVIEW_LIMIT / cell.height)
|
|
23
|
+
const width = Math.max(1, Math.round(cell.width * scale))
|
|
24
|
+
const height = Math.max(1, Math.round(cell.height * scale))
|
|
25
|
+
const columns = pet.columns ?? 8
|
|
26
|
+
const rows = pet.atlasRows ?? 9
|
|
27
|
+
return (
|
|
28
|
+
<span className={sectionCss.previewFrame} aria-hidden="true">
|
|
29
|
+
<span
|
|
30
|
+
className={sectionCss.previewAtlas}
|
|
31
|
+
style={{
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
backgroundImage: `url("${pet.atlasUrl}")`,
|
|
35
|
+
backgroundSize: `${columns * width}px ${rows * height}px`,
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
</span>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
const frame = renderer === 'frames2d'
|
|
42
|
+
? pet.frames2d?.tracks.idle?.frames[0] ?? pet.atlasUrl
|
|
43
|
+
: undefined
|
|
44
|
+
return (
|
|
45
|
+
<span className={sectionCss.previewFrame} aria-hidden="true">
|
|
46
|
+
{frame === undefined
|
|
47
|
+
? <span className={sectionCss.previewFallback}>{pet.displayName.slice(0, 1)}</span>
|
|
48
|
+
: <img className={sectionCss.previewImage} src={frame} alt="" draggable={false} />}
|
|
49
|
+
</span>
|
|
50
|
+
)
|
|
51
|
+
}
|