@linxin666/dsh-pet 0.4.11 → 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/lib/client.js +46 -5
- package/lib/client.js.map +1 -1
- package/lib/index.js +32 -0
- package/lib/types/client/PetSettingsCard.d.ts +16 -1
- package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PetSettingsCard.js +49 -4
- package/lib/types/registry.d.ts.map +1 -1
- package/lib/types/registry.js +35 -0
- package/package.json +1 -1
- package/src/client/PetSettingsCard.test.tsx +50 -0
- package/src/client/PetSettingsCard.tsx +51 -5
- package/src/registry.test.ts +121 -1
- package/src/registry.ts +37 -0
package/lib/client.js
CHANGED
|
@@ -4244,6 +4244,16 @@ window.__ModuleLoader__.load({
|
|
|
4244
4244
|
//#endregion
|
|
4245
4245
|
//#region src/client/PetSettingsCard.tsx
|
|
4246
4246
|
/**
|
|
4247
|
+
* The pet settings card: pet selection plus display layout, staged over the
|
|
4248
|
+
* 'pet' profile entry's own configuration (a plugin's settings ARE its Cordis
|
|
4249
|
+
* Config since 0.1.7, so the Host serves one form per profile entry).
|
|
4250
|
+
* Rendered as an always-open first-level settings page; the section wrapper
|
|
4251
|
+
* below mounts it as the content of the top-level 'settings.section' nav
|
|
4252
|
+
* entry. The petId choices come from the registry endpoint ('/api/pet/pets') —
|
|
4253
|
+
* the same list the sprite renders from — so the card carries no per-pet
|
|
4254
|
+
* knowledge.
|
|
4255
|
+
*/
|
|
4256
|
+
/**
|
|
4247
4257
|
* The bubble modes this card can write, in render order. Mirrors the host
|
|
4248
4258
|
* schema's union (see PetStatusBubbleMode); the browser half never imports the
|
|
4249
4259
|
* host module for a value, so the accepted set is spelled here as literals.
|
|
@@ -4272,7 +4282,7 @@ window.__ModuleLoader__.load({
|
|
|
4272
4282
|
};
|
|
4273
4283
|
/** Fetch the registry list (the same data the sprite renders from). */
|
|
4274
4284
|
async function fetchPetChoices() {
|
|
4275
|
-
const response = await fetch("/api/pet/pets");
|
|
4285
|
+
const response = await fetch("/api/pet/pets", { cache: "no-store" });
|
|
4276
4286
|
if (!response.ok) throw new Error("pet pets failed: " + response.status);
|
|
4277
4287
|
return await response.json();
|
|
4278
4288
|
}
|
|
@@ -4303,6 +4313,8 @@ window.__ModuleLoader__.load({
|
|
|
4303
4313
|
fallbackQueued = false;
|
|
4304
4314
|
petSaveFailed = false;
|
|
4305
4315
|
loaded = false;
|
|
4316
|
+
/** A registry request is in flight. */
|
|
4317
|
+
loading = false;
|
|
4306
4318
|
attempts = 0;
|
|
4307
4319
|
disposed = false;
|
|
4308
4320
|
/** Pending deferred-load or retry timer; cancelled by dispose(). */
|
|
@@ -4330,7 +4342,8 @@ window.__ModuleLoader__.load({
|
|
|
4330
4342
|
}
|
|
4331
4343
|
/** Resolve the registry choices once (retried a few times on failure). */
|
|
4332
4344
|
async loadPets() {
|
|
4333
|
-
if (this.loaded || this.disposed) return;
|
|
4345
|
+
if (this.loaded || this.disposed || this.loading) return;
|
|
4346
|
+
this.loading = true;
|
|
4334
4347
|
try {
|
|
4335
4348
|
const list = await fetchPetChoices();
|
|
4336
4349
|
if (this.disposed) return;
|
|
@@ -4347,8 +4360,22 @@ window.__ModuleLoader__.load({
|
|
|
4347
4360
|
if (this.disposed) return;
|
|
4348
4361
|
this.loadPets();
|
|
4349
4362
|
}, 3e3);
|
|
4363
|
+
} finally {
|
|
4364
|
+
this.loading = false;
|
|
4350
4365
|
}
|
|
4351
4366
|
}
|
|
4367
|
+
/**
|
|
4368
|
+
* Re-read the registry on demand. The pet API is registered only while the
|
|
4369
|
+
* plugin is enabled, so the first read can fail while the master switch is
|
|
4370
|
+
* off; this lets the card try again the moment the switch opens instead of
|
|
4371
|
+
* waiting for a page reload.
|
|
4372
|
+
*/
|
|
4373
|
+
refreshPets() {
|
|
4374
|
+
if (this.disposed || this.loading) return;
|
|
4375
|
+
this.loaded = false;
|
|
4376
|
+
this.attempts = 0;
|
|
4377
|
+
this.loadPets();
|
|
4378
|
+
}
|
|
4352
4379
|
async loadPetState() {
|
|
4353
4380
|
try {
|
|
4354
4381
|
const state = await fetchPetState();
|
|
@@ -4505,6 +4532,9 @@ window.__ModuleLoader__.load({
|
|
|
4505
4532
|
this.stagedVisible = void 0;
|
|
4506
4533
|
this.petSaveFailed = false;
|
|
4507
4534
|
this.store.set(this.projection());
|
|
4535
|
+
},
|
|
4536
|
+
refreshPets: () => {
|
|
4537
|
+
this.refreshPets();
|
|
4508
4538
|
}
|
|
4509
4539
|
};
|
|
4510
4540
|
}
|
|
@@ -4531,6 +4561,16 @@ window.__ModuleLoader__.load({
|
|
|
4531
4561
|
const { t } = props;
|
|
4532
4562
|
const state = props.usePetSettingsCard((snapshot) => snapshot);
|
|
4533
4563
|
const disabled = !state.writable;
|
|
4564
|
+
const enabled = state.enabled.text !== "false";
|
|
4565
|
+
const hasChoices = state.petPreviews.length > 0;
|
|
4566
|
+
const { refreshPets } = props;
|
|
4567
|
+
(0, react.useEffect)(() => {
|
|
4568
|
+
if (enabled && !hasChoices) refreshPets();
|
|
4569
|
+
}, [
|
|
4570
|
+
enabled,
|
|
4571
|
+
hasChoices,
|
|
4572
|
+
refreshPets
|
|
4573
|
+
]);
|
|
4534
4574
|
const fieldProps = {
|
|
4535
4575
|
overriddenLabel: t("settings.overridden"),
|
|
4536
4576
|
resetLabel: t("settings.reset"),
|
|
@@ -4756,7 +4796,7 @@ window.__ModuleLoader__.load({
|
|
|
4756
4796
|
}
|
|
4757
4797
|
/** Render the pet settings card as a first-level settings page. */
|
|
4758
4798
|
function PetSettingsSection(props) {
|
|
4759
|
-
const { t, usePetSettingsCard, save, discard, edit, resetField } = props;
|
|
4799
|
+
const { t, usePetSettingsCard, save, discard, edit, resetField, refreshPets } = props;
|
|
4760
4800
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
4761
4801
|
className: settings_section_module_css_default.sectionList,
|
|
4762
4802
|
"data-dsh-plugin": "pet",
|
|
@@ -4767,7 +4807,8 @@ window.__ModuleLoader__.load({
|
|
|
4767
4807
|
save,
|
|
4768
4808
|
discard,
|
|
4769
4809
|
edit,
|
|
4770
|
-
resetField
|
|
4810
|
+
resetField,
|
|
4811
|
+
refreshPets
|
|
4771
4812
|
})
|
|
4772
4813
|
});
|
|
4773
4814
|
}
|
|
@@ -5063,7 +5104,7 @@ window.__ModuleLoader__.load({
|
|
|
5063
5104
|
/** The building package's version, when the bundle carries it. */
|
|
5064
5105
|
function bakedVersion() {
|
|
5065
5106
|
try {
|
|
5066
|
-
return "0.4.
|
|
5107
|
+
return "0.4.12";
|
|
5067
5108
|
} catch {
|
|
5068
5109
|
return;
|
|
5069
5110
|
}
|