@linxin666/dsh-pet 0.4.10 → 0.4.12
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 +1137 -352
- package/lib/client.js.map +1 -1
- package/lib/index.js +32 -0
- 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 +46 -3
- package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PetSettingsCard.js +96 -11
- 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/lib/types/registry.d.ts.map +1 -1
- package/lib/types/registry.js +35 -0
- package/package.json +1 -1
- package/src/client/PetPreview.tsx +51 -0
- package/src/client/PetSettingsCard.test.tsx +78 -22
- package/src/client/PetSettingsCard.tsx +252 -115
- 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
- package/src/registry.test.ts +121 -1
- package/src/registry.ts +37 -0
package/lib/index.js
CHANGED
|
@@ -4790,6 +4790,27 @@ function resolveFrames2dEntry(manifest, dir, options) {
|
|
|
4790
4790
|
...remarks === void 0 ? {} : { remarks }
|
|
4791
4791
|
};
|
|
4792
4792
|
}
|
|
4793
|
+
/**
|
|
4794
|
+
* Directory-name suffix the market installer carries while it downloads:
|
|
4795
|
+
* '<id>.install-<base36 ms>-<base36 suffix>'
|
|
4796
|
+
* (`installAsset` in dsh-web `packages/dsh-market/src/core/installer.ts` builds
|
|
4797
|
+
* it as `dest + '.install-' + Date.now().toString(36) + '-' +
|
|
4798
|
+
* Math.random().toString(36).slice(2, 8)`). Success renames the staging
|
|
4799
|
+
* directory onto its id, and the failure path removes it, so such a directory
|
|
4800
|
+
* surviving on disk means an install was interrupted and what it holds is a
|
|
4801
|
+
* partial pet.
|
|
4802
|
+
*
|
|
4803
|
+
* The bounds are the producer's real range rather than a guess: base36 of
|
|
4804
|
+
* `Date.now()` is 8 digits today and stays under 11 for several millennia,
|
|
4805
|
+
* and `.slice(2, 8)` always yields exactly 6 base36 characters. A directory
|
|
4806
|
+
* whose name merely mentions '.install-' outside that shape stays an ordinary
|
|
4807
|
+
* pet directory.
|
|
4808
|
+
*/
|
|
4809
|
+
const PET_INSTALL_STAGING_NAME = /\.install-[0-9a-z]{1,11}-[0-9a-z]{1,11}$/;
|
|
4810
|
+
/** True when a pet directory name is an interrupted-install staging leftover. */
|
|
4811
|
+
function isPetInstallStagingName(name) {
|
|
4812
|
+
return PET_INSTALL_STAGING_NAME.test(name);
|
|
4813
|
+
}
|
|
4793
4814
|
/** Scan one directory of pet folders; entries come back in name order. */
|
|
4794
4815
|
function scanPetDir(dir, options) {
|
|
4795
4816
|
if (!existsSync(dir)) return [];
|
|
@@ -4802,6 +4823,17 @@ function scanPetDir(dir, options) {
|
|
|
4802
4823
|
names.sort();
|
|
4803
4824
|
const entries = [];
|
|
4804
4825
|
for (const name of names) {
|
|
4826
|
+
if (isPetInstallStagingName(name)) {
|
|
4827
|
+
const leftover = join(dir, name);
|
|
4828
|
+
const message = "skipping install staging leftover " + name + " (" + leftover + "): an interrupted install left it behind, and it is ignored so it cannot override the finished pet with the same id";
|
|
4829
|
+
options.warnings?.push(message);
|
|
4830
|
+
options.diagnostics?.push({
|
|
4831
|
+
level: "warning",
|
|
4832
|
+
source: leftover,
|
|
4833
|
+
message
|
|
4834
|
+
});
|
|
4835
|
+
continue;
|
|
4836
|
+
}
|
|
4805
4837
|
const manifestFile = join(dir, name, "pet.json");
|
|
4806
4838
|
if (!existsSync(manifestFile)) continue;
|
|
4807
4839
|
const parsed = readPetJson(manifestFile, options);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Lightweight, static pet thumbnails built from the registry's existing assets. */
|
|
2
|
+
import type { PetDefinition } from '../registry.ts';
|
|
3
|
+
/** Registry data needed by a thumbnail; older hosts may serve only id/name. */
|
|
4
|
+
export type PetPreviewDefinition = Pick<PetDefinition, 'id' | 'displayName'> & Partial<Pick<PetDefinition, 'renderer' | 'cell' | 'columns' | 'atlasRows' | 'atlasUrl' | 'frames2d'>>;
|
|
5
|
+
/**
|
|
6
|
+
* Render the atlas's first sprite cell or a frames2d idle frame. Live2d and
|
|
7
|
+
* incomplete legacy responses degrade to a text mark instead of a broken image.
|
|
8
|
+
*/
|
|
9
|
+
export declare function PetPreview(props: {
|
|
10
|
+
pet: PetPreviewDefinition;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
//# sourceMappingURL=PetPreview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PetPreview.d.ts","sourceRoot":"","sources":["../../../src/client/PetPreview.tsx"],"names":[],"mappings":"AAAA,oFAAoF;AAEpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAGnD,+EAA+E;AAC/E,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,aAAa,CAAC,GACxE,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,CAAA;AAKzG;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,GAAG,EAAE,oBAAoB,CAAA;CAAE,+BAkC9D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import sectionCss from './settings-section.module.css';
|
|
3
|
+
const PREVIEW_LIMIT = 72;
|
|
4
|
+
const DEFAULT_CELL = { width: 192, height: 208 };
|
|
5
|
+
/**
|
|
6
|
+
* Render the atlas's first sprite cell or a frames2d idle frame. Live2d and
|
|
7
|
+
* incomplete legacy responses degrade to a text mark instead of a broken image.
|
|
8
|
+
*/
|
|
9
|
+
export function PetPreview(props) {
|
|
10
|
+
const { pet } = props;
|
|
11
|
+
const renderer = pet.renderer ?? 'sprite2d';
|
|
12
|
+
if (renderer === 'sprite2d' && pet.atlasUrl !== undefined) {
|
|
13
|
+
const cell = pet.cell ?? DEFAULT_CELL;
|
|
14
|
+
const scale = Math.min(PREVIEW_LIMIT / cell.width, PREVIEW_LIMIT / cell.height);
|
|
15
|
+
const width = Math.max(1, Math.round(cell.width * scale));
|
|
16
|
+
const height = Math.max(1, Math.round(cell.height * scale));
|
|
17
|
+
const columns = pet.columns ?? 8;
|
|
18
|
+
const rows = pet.atlasRows ?? 9;
|
|
19
|
+
return (_jsx("span", { className: sectionCss.previewFrame, "aria-hidden": "true", children: _jsx("span", { className: sectionCss.previewAtlas, style: {
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
backgroundImage: `url("${pet.atlasUrl}")`,
|
|
23
|
+
backgroundSize: `${columns * width}px ${rows * height}px`,
|
|
24
|
+
} }) }));
|
|
25
|
+
}
|
|
26
|
+
const frame = renderer === 'frames2d'
|
|
27
|
+
? pet.frames2d?.tracks.idle?.frames[0] ?? pet.atlasUrl
|
|
28
|
+
: undefined;
|
|
29
|
+
return (_jsx("span", { className: sectionCss.previewFrame, "aria-hidden": "true", children: frame === undefined
|
|
30
|
+
? _jsx("span", { className: sectionCss.previewFallback, children: pet.displayName.slice(0, 1) })
|
|
31
|
+
: _jsx("img", { className: sectionCss.previewImage, src: frame, alt: "", draggable: false }) }));
|
|
32
|
+
}
|
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
* the same list the sprite renders from — so the card carries no per-pet
|
|
9
9
|
* knowledge.
|
|
10
10
|
*/
|
|
11
|
-
import type
|
|
11
|
+
import { type ReactNode } from 'react';
|
|
12
12
|
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
13
13
|
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
14
14
|
import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
|
|
15
|
+
import { type PetPreviewDefinition } from './PetPreview.tsx';
|
|
15
16
|
import { type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts';
|
|
16
17
|
/** The pet's settings fields this card edits (the namespace's full schema). */
|
|
17
18
|
export interface PetSettings {
|
|
@@ -61,6 +62,8 @@ export interface PetSettingsCardState extends CardShell {
|
|
|
61
62
|
value: string;
|
|
62
63
|
label: string;
|
|
63
64
|
}[];
|
|
65
|
+
/** The same registry entries with the visual data their thumbnails need. */
|
|
66
|
+
petPreviews: readonly PetPreviewDefinition[];
|
|
64
67
|
}
|
|
65
68
|
/** The registration-side face the card's slot entry injects. */
|
|
66
69
|
export interface PetSettingsCardFace extends CardActions {
|
|
@@ -68,20 +71,52 @@ export interface PetSettingsCardFace extends CardActions {
|
|
|
68
71
|
/** Card snapshot bound by the renderer as usePetSettingsCard. */
|
|
69
72
|
petSettingsCard: SnapshotStore<PetSettingsCardState>;
|
|
70
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Ask the card for the pet registry again. The pet API only exists while the
|
|
76
|
+
* plugin is enabled, so opening the master switch has to be able to re-ask
|
|
77
|
+
* instead of leaving the picker empty until the page reloads.
|
|
78
|
+
*/
|
|
79
|
+
refreshPets(): void;
|
|
71
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* The spans the coarse sliders cover, spelled as literals for the same reason.
|
|
83
|
+
* Size and bubble scale are the schema's own bounds (src/persist.ts); the
|
|
84
|
+
* insets reach the schema's far end only by typing, so their slider covers the
|
|
85
|
+
* distances a window can show.
|
|
86
|
+
*/
|
|
87
|
+
export declare const SIZE_RANGE: {
|
|
88
|
+
min: number;
|
|
89
|
+
max: number;
|
|
90
|
+
step: number;
|
|
91
|
+
};
|
|
92
|
+
export declare const INSET_RANGE: {
|
|
93
|
+
min: number;
|
|
94
|
+
max: number;
|
|
95
|
+
step: number;
|
|
96
|
+
};
|
|
97
|
+
export declare const BUBBLE_SCALE_RANGE: {
|
|
98
|
+
min: number;
|
|
99
|
+
max: number;
|
|
100
|
+
step: number;
|
|
101
|
+
};
|
|
72
102
|
/** Bridges the 'pet' scope onto the card's staged form. */
|
|
73
103
|
export declare class PetSettingsCardController {
|
|
74
104
|
private readonly form;
|
|
75
105
|
private readonly store;
|
|
76
106
|
private readonly petChoices;
|
|
77
107
|
private readonly petLabels;
|
|
108
|
+
private petPreviews;
|
|
78
109
|
private selectedPetId;
|
|
79
110
|
private selectedVisible;
|
|
80
111
|
private stagedPetId;
|
|
81
112
|
private stagedVisible;
|
|
82
113
|
private savingPet;
|
|
114
|
+
/** A fallback pick made while a write was in flight. */
|
|
115
|
+
private fallbackQueued;
|
|
83
116
|
private petSaveFailed;
|
|
84
117
|
private loaded;
|
|
118
|
+
/** A registry request is in flight. */
|
|
119
|
+
private loading;
|
|
85
120
|
private attempts;
|
|
86
121
|
private disposed;
|
|
87
122
|
/** Pending deferred-load or retry timer; cancelled by dispose(). */
|
|
@@ -90,6 +125,13 @@ export declare class PetSettingsCardController {
|
|
|
90
125
|
constructor(scope: ConfigForm<PetSettings>);
|
|
91
126
|
/** Resolve the registry choices once (retried a few times on failure). */
|
|
92
127
|
private loadPets;
|
|
128
|
+
/**
|
|
129
|
+
* Re-read the registry on demand. The pet API is registered only while the
|
|
130
|
+
* plugin is enabled, so the first read can fail while the master switch is
|
|
131
|
+
* off; this lets the card try again the moment the switch opens instead of
|
|
132
|
+
* waiting for a page reload.
|
|
133
|
+
*/
|
|
134
|
+
refreshPets(): void;
|
|
93
135
|
private loadPetState;
|
|
94
136
|
private fallback;
|
|
95
137
|
/**
|
|
@@ -102,7 +144,8 @@ export declare class PetSettingsCardController {
|
|
|
102
144
|
* Persist the staged selection and visibility through the pet API — the only
|
|
103
145
|
* writer available when the aggregate shell serves this card, since there is
|
|
104
146
|
* no Host settings form to mutate — then confirm the read-back before the
|
|
105
|
-
* drafts are cleared.
|
|
147
|
+
* drafts are cleared. A refused write puts both picks back to what the pet
|
|
148
|
+
* persisted. A pick made while a write is in flight runs once it settles.
|
|
106
149
|
*/
|
|
107
150
|
private saveFallback;
|
|
108
151
|
private projection;
|
|
@@ -126,7 +169,7 @@ export type PetSettingsCardProps = PropsLocale<'pet'> & InjectFace<PetSettingsCa
|
|
|
126
169
|
*/
|
|
127
170
|
export declare function PetSettingsCard(props: PetSettingsCardProps): import("react").JSX.Element;
|
|
128
171
|
/** Props the settings section binds for the pet card page. */
|
|
129
|
-
export type PetSettingsSectionProps = PropsRuntime<'settings.section'> & PropsLocale<'pet'> & InjectFace<PetSettingsCardFace>;
|
|
172
|
+
export type PetSettingsSectionProps = (PropsRuntime<'settings.section'> | PropsRuntime<'web-ui.extension'>) & PropsLocale<'pet'> & InjectFace<PetSettingsCardFace>;
|
|
130
173
|
/** Render the pet settings card as a first-level settings page. */
|
|
131
174
|
export declare function PetSettingsSection(props: PetSettingsSectionProps): ReactNode;
|
|
132
175
|
//# sourceMappingURL=PetSettingsCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PetSettingsCard.d.ts","sourceRoot":"","sources":["../../../src/client/PetSettingsCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"PetSettingsCard.d.ts","sourceRoot":"","sources":["../../../src/client/PetSettingsCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAC7F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAKlE,OAAO,EAAc,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAoD,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAG1J,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC1B,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qBAAqB;IACrB,OAAO,CAAC,EAAE,OAAO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BAAoB,GAC9B,WAAW,CAAC,KAAK,CAAC,GAChB,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAEnC;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,+BAqM1D;AAED,8DAA8D;AAC9D,MAAM,MAAM,uBAAuB,GACjC,CAAC,YAAY,CAAC,kBAAkB,CAAC,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC,GACnE,WAAW,CAAC,KAAK,CAAC,GAClB,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAEnC,mEAAmE;AACnE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,SAAS,CAe5E"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The pet settings card: pet selection plus display layout, staged over the
|
|
4
|
+
* 'pet' profile entry's own configuration (a plugin's settings ARE its Cordis
|
|
5
|
+
* Config since 0.1.7, so the Host serves one form per profile entry).
|
|
6
|
+
* Rendered as an always-open first-level settings page; the section wrapper
|
|
7
|
+
* below mounts it as the content of the top-level 'settings.section' nav
|
|
8
|
+
* entry. The petId choices come from the registry endpoint ('/api/pet/pets') —
|
|
9
|
+
* the same list the sprite renders from — so the card carries no per-pet
|
|
10
|
+
* knowledge.
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect } from 'react';
|
|
13
|
+
import { PluginSettingsCard, ValueField, BooleanField, ChoiceField, ToggleSwitch } from "./PluginSettingsCard.js";
|
|
14
|
+
import { PetPreview } from "./PetPreview.js";
|
|
3
15
|
import { CardForm, booleanField, choiceField, numberField } from "./settings-form.js";
|
|
4
16
|
import sectionCss from './settings-section.module.css';
|
|
5
17
|
/**
|
|
@@ -8,9 +20,20 @@ import sectionCss from './settings-section.module.css';
|
|
|
8
20
|
* host module for a value, so the accepted set is spelled here as literals.
|
|
9
21
|
*/
|
|
10
22
|
const STATUS_BUBBLE_CHOICES = ['auto', 'off'];
|
|
23
|
+
/**
|
|
24
|
+
* The spans the coarse sliders cover, spelled as literals for the same reason.
|
|
25
|
+
* Size and bubble scale are the schema's own bounds (src/persist.ts); the
|
|
26
|
+
* insets reach the schema's far end only by typing, so their slider covers the
|
|
27
|
+
* distances a window can show.
|
|
28
|
+
*/
|
|
29
|
+
export const SIZE_RANGE = { min: 32, max: 1024, step: 1 };
|
|
30
|
+
export const INSET_RANGE = { min: 0, max: 1000, step: 1 };
|
|
31
|
+
export const BUBBLE_SCALE_RANGE = { min: 0.5, max: 2, step: 0.05 };
|
|
11
32
|
/** Fetch the registry list (the same data the sprite renders from). */
|
|
12
33
|
async function fetchPetChoices() {
|
|
13
|
-
|
|
34
|
+
// Never from cache: the list is exactly what changes when the plugin is
|
|
35
|
+
// switched on (the API only exists then) or a pet is installed.
|
|
36
|
+
const response = await fetch('/api/pet/pets', { cache: 'no-store' });
|
|
14
37
|
if (!response.ok)
|
|
15
38
|
throw new Error('pet pets failed: ' + response.status);
|
|
16
39
|
return (await response.json());
|
|
@@ -35,13 +58,18 @@ export class PetSettingsCardController {
|
|
|
35
58
|
// without rebuilding the form.
|
|
36
59
|
petChoices = [];
|
|
37
60
|
petLabels = new Map();
|
|
61
|
+
petPreviews = [];
|
|
38
62
|
selectedPetId;
|
|
39
63
|
selectedVisible;
|
|
40
64
|
stagedPetId;
|
|
41
65
|
stagedVisible;
|
|
42
66
|
savingPet = false;
|
|
67
|
+
/** A fallback pick made while a write was in flight. */
|
|
68
|
+
fallbackQueued = false;
|
|
43
69
|
petSaveFailed = false;
|
|
44
70
|
loaded = false;
|
|
71
|
+
/** A registry request is in flight. */
|
|
72
|
+
loading = false;
|
|
45
73
|
attempts = 0;
|
|
46
74
|
disposed = false;
|
|
47
75
|
/** Pending deferred-load or retry timer; cancelled by dispose(). */
|
|
@@ -78,13 +106,15 @@ export class PetSettingsCardController {
|
|
|
78
106
|
}
|
|
79
107
|
/** Resolve the registry choices once (retried a few times on failure). */
|
|
80
108
|
async loadPets() {
|
|
81
|
-
if (this.loaded || this.disposed)
|
|
109
|
+
if (this.loaded || this.disposed || this.loading)
|
|
82
110
|
return;
|
|
111
|
+
this.loading = true;
|
|
83
112
|
try {
|
|
84
113
|
const list = await fetchPetChoices();
|
|
85
114
|
if (this.disposed)
|
|
86
115
|
return;
|
|
87
116
|
this.petChoices.splice(0, this.petChoices.length, ...list.map(choice => choice.id));
|
|
117
|
+
this.petPreviews = list;
|
|
88
118
|
for (const choice of list)
|
|
89
119
|
this.petLabels.set(choice.id, choice.displayName);
|
|
90
120
|
this.loaded = true;
|
|
@@ -103,6 +133,22 @@ export class PetSettingsCardController {
|
|
|
103
133
|
}, 3000);
|
|
104
134
|
}
|
|
105
135
|
}
|
|
136
|
+
finally {
|
|
137
|
+
this.loading = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Re-read the registry on demand. The pet API is registered only while the
|
|
142
|
+
* plugin is enabled, so the first read can fail while the master switch is
|
|
143
|
+
* off; this lets the card try again the moment the switch opens instead of
|
|
144
|
+
* waiting for a page reload.
|
|
145
|
+
*/
|
|
146
|
+
refreshPets() {
|
|
147
|
+
if (this.disposed || this.loading)
|
|
148
|
+
return;
|
|
149
|
+
this.loaded = false;
|
|
150
|
+
this.attempts = 0;
|
|
151
|
+
void this.loadPets();
|
|
106
152
|
}
|
|
107
153
|
async loadPetState() {
|
|
108
154
|
try {
|
|
@@ -135,13 +181,16 @@ export class PetSettingsCardController {
|
|
|
135
181
|
* Persist the staged selection and visibility through the pet API — the only
|
|
136
182
|
* writer available when the aggregate shell serves this card, since there is
|
|
137
183
|
* no Host settings form to mutate — then confirm the read-back before the
|
|
138
|
-
* drafts are cleared.
|
|
184
|
+
* drafts are cleared. A refused write puts both picks back to what the pet
|
|
185
|
+
* persisted. A pick made while a write is in flight runs once it settles.
|
|
139
186
|
*/
|
|
140
187
|
async saveFallback() {
|
|
141
188
|
const petId = this.stagedPetId;
|
|
142
189
|
const visible = this.stagedVisible;
|
|
143
|
-
if (this.savingPet)
|
|
190
|
+
if (this.savingPet) {
|
|
191
|
+
this.fallbackQueued = true;
|
|
144
192
|
return;
|
|
193
|
+
}
|
|
145
194
|
if (petId === undefined && visible === undefined)
|
|
146
195
|
return;
|
|
147
196
|
if (petId !== undefined && !this.petChoices.includes(petId))
|
|
@@ -184,12 +233,20 @@ export class PetSettingsCardController {
|
|
|
184
233
|
}
|
|
185
234
|
catch {
|
|
186
235
|
this.petSaveFailed = true;
|
|
236
|
+
if (this.stagedPetId === petId)
|
|
237
|
+
this.stagedPetId = undefined;
|
|
238
|
+
if (this.stagedVisible === visible)
|
|
239
|
+
this.stagedVisible = undefined;
|
|
187
240
|
}
|
|
188
241
|
finally {
|
|
189
242
|
this.savingPet = false;
|
|
190
243
|
if (!this.disposed)
|
|
191
244
|
this.store.set(this.projection());
|
|
192
245
|
}
|
|
246
|
+
if (this.fallbackQueued && !this.disposed) {
|
|
247
|
+
this.fallbackQueued = false;
|
|
248
|
+
await this.saveFallback();
|
|
249
|
+
}
|
|
193
250
|
}
|
|
194
251
|
projection() {
|
|
195
252
|
const fallback = this.fallback();
|
|
@@ -222,6 +279,7 @@ export class PetSettingsCardController {
|
|
|
222
279
|
? { ...configuredPet, text: this.selectedPetId }
|
|
223
280
|
: configuredPet,
|
|
224
281
|
petChoices: this.petChoices.map(id => ({ value: id, label: this.petLabels.get(id) ?? id })),
|
|
282
|
+
petPreviews: this.petPreviews,
|
|
225
283
|
};
|
|
226
284
|
}
|
|
227
285
|
/**
|
|
@@ -232,6 +290,8 @@ export class PetSettingsCardController {
|
|
|
232
290
|
const actions = this.form.actions();
|
|
233
291
|
return {
|
|
234
292
|
hooks: { petSettingsCard: this.store },
|
|
293
|
+
// The fallback's two fields are both picks, so each is written through
|
|
294
|
+
// the pet API the moment it is made, as the form writes its own picks.
|
|
235
295
|
edit: (field, value) => {
|
|
236
296
|
if (!this.fallback())
|
|
237
297
|
return actions.edit(field, value);
|
|
@@ -243,6 +303,7 @@ export class PetSettingsCardController {
|
|
|
243
303
|
return;
|
|
244
304
|
this.petSaveFailed = false;
|
|
245
305
|
this.store.set(this.projection());
|
|
306
|
+
void this.saveFallback();
|
|
246
307
|
},
|
|
247
308
|
resetField: (field) => {
|
|
248
309
|
if (!this.fallback())
|
|
@@ -268,6 +329,7 @@ export class PetSettingsCardController {
|
|
|
268
329
|
this.petSaveFailed = false;
|
|
269
330
|
this.store.set(this.projection());
|
|
270
331
|
},
|
|
332
|
+
refreshPets: () => { this.refreshPets(); },
|
|
271
333
|
};
|
|
272
334
|
}
|
|
273
335
|
/**
|
|
@@ -294,19 +356,42 @@ export function PetSettingsCard(props) {
|
|
|
294
356
|
const { t } = props;
|
|
295
357
|
const state = props.usePetSettingsCard(snapshot => snapshot);
|
|
296
358
|
const disabled = !state.writable;
|
|
359
|
+
// The registry is read once, when the plugin starts; the pet API that serves
|
|
360
|
+
// it exists only while the master switch is on. A card that opened empty
|
|
361
|
+
// therefore asks again as soon as the switch is on, instead of leaving the
|
|
362
|
+
// picker blank until the page reloads (the deferred reads had already spent
|
|
363
|
+
// their retries while the API was absent).
|
|
364
|
+
const enabled = state.enabled.text !== 'false';
|
|
365
|
+
const hasChoices = state.petPreviews.length > 0;
|
|
366
|
+
const { refreshPets } = props;
|
|
367
|
+
useEffect(() => {
|
|
368
|
+
if (enabled && !hasChoices)
|
|
369
|
+
refreshPets();
|
|
370
|
+
}, [enabled, hasChoices, refreshPets]);
|
|
297
371
|
const fieldProps = {
|
|
298
372
|
overriddenLabel: t('settings.overridden'),
|
|
299
373
|
resetLabel: t('settings.reset'),
|
|
300
374
|
invalidLabel: t('settings.invalidNumber'),
|
|
301
375
|
disabled,
|
|
376
|
+
presentation: 'segment',
|
|
302
377
|
};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
378
|
+
// The master switch sits in the header, as the Workshop and Usage pages
|
|
379
|
+
// carry theirs; the fallback has no Host form to write it through.
|
|
380
|
+
const enabledSwitch = state.petSelectionFallback
|
|
381
|
+
? undefined
|
|
382
|
+
: (_jsx(ToggleSwitch, { labelledBy: "settings-pet-title", checked: state.enabled.text !== 'false', disabled: disabled, onChange: (next) => { props.edit('enabled', String(next)); } }));
|
|
383
|
+
return (_jsx(PluginSettingsCard, { t: t, titleKey: "settings.title", titleId: "settings-pet-title", descriptionKey: "settings.description", descriptionNode: state.petSelectionFallback ? t('settings.petHint') : undefined, headerAction: enabledSwitch, state: state, onSave: props.save, onDiscard: props.discard, alwaysOpen: true, children: _jsxs("div", { className: sectionCss.settingsLayout, children: [_jsxs("section", { className: sectionCss.selectionGroup, children: [_jsxs("div", { className: sectionCss.groupHeader, children: [_jsx("h3", { className: sectionCss.groupTitle, id: "settings-pet-selection-title", children: t('settings.pet') }), state.petId.overridden
|
|
384
|
+
? (_jsx("button", { type: "button", className: sectionCss.textAction, disabled: disabled, onClick: () => { props.resetField('petId'); }, children: t('settings.reset') }))
|
|
385
|
+
: null] }), _jsx("div", { id: "settings-pet-pet", className: sectionCss.petGrid, role: "group", "aria-labelledby": "settings-pet-selection-title", children: state.petPreviews.map(pet => {
|
|
386
|
+
const selected = state.petId.text === pet.id;
|
|
387
|
+
return (_jsxs("button", { type: "button", className: selected ? `${sectionCss.petChoice} ${sectionCss.petChoiceSelected}` : sectionCss.petChoice, "aria-pressed": selected, title: pet.displayName, disabled: disabled, onClick: () => { props.edit('petId', pet.id); }, children: [_jsx(PetPreview, { pet: pet }), _jsx("span", { className: sectionCss.petChoiceLabel, children: pet.displayName })] }, pet.id));
|
|
388
|
+
}) }), _jsx("p", { className: state.petId.invalid ? sectionCss.invalid : sectionCss.groupHint, children: state.petId.invalid ? t('settings.invalidNumber') : t('settings.petHint') })] }), _jsxs("div", { className: sectionCss.settingsColumn, children: [_jsxs("section", { className: sectionCss.settingsGroup, children: [_jsx("div", { className: sectionCss.groupHeader, children: _jsx("h3", { className: sectionCss.groupTitle, id: "settings-pet-display-title", children: t('settings.displayGroup') }) }), _jsxs("div", { className: sectionCss.fields, children: [_jsx(BooleanField, { id: "settings-pet-visible", label: t('settings.visible'), hint: t('settings.visibleHint'), inheritLabel: t('settings.inherit'), onLabel: t('settings.on'), offLabel: t('settings.off'), ...fieldProps, ...state.visible, onEdit: (text) => { props.edit('visible', text); }, onReset: () => { props.resetField('visible'); } }), state.petSelectionFallback ? null : _jsx(ValueField, { id: "settings-pet-size", label: t('settings.size'), hint: t('settings.sizeHint'), numeric: true, range: SIZE_RANGE, ...fieldProps, ...state.size, onEdit: (text) => { props.edit('size', text); }, onReset: () => { props.resetField('size'); } }), state.petSelectionFallback ? null : _jsx(ValueField, { id: "settings-pet-right", label: t('settings.right'), hint: t('settings.rightHint'), numeric: true, range: INSET_RANGE, ...fieldProps, ...state.right, onEdit: (text) => { props.edit('right', text); }, onReset: () => { props.resetField('right'); } }), state.petSelectionFallback ? null : _jsx(ValueField, { id: "settings-pet-bottom", label: t('settings.bottom'), hint: t('settings.bottomHint'), numeric: true, range: INSET_RANGE, ...fieldProps, ...state.bottom, onEdit: (text) => { props.edit('bottom', text); }, onReset: () => { props.resetField('bottom'); } })] })] }), state.petSelectionFallback ? null : (_jsxs("section", { className: sectionCss.settingsGroup, children: [_jsx("div", { className: sectionCss.groupHeader, children: _jsx("h3", { className: sectionCss.groupTitle, id: "settings-pet-behavior-title", children: t('settings.bubbleGroup') }) }), _jsxs("div", { className: sectionCss.fields, children: [_jsx(BooleanField, { id: "settings-pet-decoration", label: t('settings.decoration'), hint: t('settings.decorationHint'), inheritLabel: t('settings.inherit'), onLabel: t('settings.on'), offLabel: t('settings.off'), ...fieldProps, ...state.decorationEnabled, onEdit: (text) => { props.edit('decorationEnabled', text); }, onReset: () => { props.resetField('decorationEnabled'); } }), _jsx(ChoiceField, { id: "settings-pet-status-bubbles", label: t('settings.statusBubbles'), hint: t('settings.statusBubblesHint'), inheritLabel: t('settings.inherit'), ...fieldProps, ...state.statusBubbles, choices: [
|
|
389
|
+
{ value: STATUS_BUBBLE_CHOICES[0], label: t('settings.on') },
|
|
390
|
+
{ value: STATUS_BUBBLE_CHOICES[1], label: t('settings.off') },
|
|
391
|
+
], onEdit: (text) => { props.edit('statusBubbles', text); }, onReset: () => { props.resetField('statusBubbles'); } }), _jsx(ValueField, { id: "settings-pet-bubble-scale", label: t('settings.bubbleScale'), hint: t('settings.bubbleScaleHint'), numeric: true, range: BUBBLE_SCALE_RANGE, ...fieldProps, ...state.bubbleScale, onEdit: (text) => { props.edit('bubbleScale', text); }, onReset: () => { props.resetField('bubbleScale'); } })] })] }))] })] }) }));
|
|
307
392
|
}
|
|
308
393
|
/** Render the pet settings card as a first-level settings page. */
|
|
309
394
|
export function PetSettingsSection(props) {
|
|
310
|
-
const { t, usePetSettingsCard, save, discard, edit, resetField } = props;
|
|
311
|
-
return (_jsx("ul", { className: sectionCss.sectionList, children: _jsx(PetSettingsCard, { t: t, usePetSettingsCard: usePetSettingsCard, save: save, discard: discard, edit: edit, resetField: resetField }) }));
|
|
395
|
+
const { t, usePetSettingsCard, save, discard, edit, resetField, refreshPets } = props;
|
|
396
|
+
return (_jsx("ul", { className: sectionCss.sectionList, "data-dsh-plugin": "pet", "data-dsh-part": "panel", children: _jsx(PetSettingsCard, { t: t, usePetSettingsCard: usePetSettingsCard, save: save, discard: discard, edit: edit, resetField: resetField, refreshPets: refreshPets }) }));
|
|
312
397
|
}
|