@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
|
@@ -9,7 +9,8 @@ import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
|
9
9
|
import { cleanup, render, screen } from '@testing-library/react'
|
|
10
10
|
import { useSyncExternalStore } from 'react'
|
|
11
11
|
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
12
|
-
import { PetSettingsCard, PetSettingsCardController, type PetSettings } from './PetSettingsCard.tsx'
|
|
12
|
+
import { BUBBLE_SCALE_RANGE, INSET_RANGE, PetSettingsCard, PetSettingsCardController, SIZE_RANGE, type PetSettings } from './PetSettingsCard.tsx'
|
|
13
|
+
import { BUBBLE_SCALE_MAX, BUBBLE_SCALE_MIN, DISPLAY_INSET_MAX, DISPLAY_SIZE_MAX, DISPLAY_SIZE_MIN } from '../persist.ts'
|
|
13
14
|
import { t } from './locales.ts'
|
|
14
15
|
|
|
15
16
|
vi.mock('@deepseek-ai/dsh-client-store', () => ({ // test-standards-allow: the SDK client bundle is a browser module factory and cannot be imported by Vitest
|
|
@@ -103,13 +104,12 @@ describe('pet selection without a Host settings form', () => {
|
|
|
103
104
|
const face = controller.inject()
|
|
104
105
|
const state = () => face.hooks.petSettingsCard.getSnapshot()
|
|
105
106
|
|
|
106
|
-
// When the user chooses the maid whale
|
|
107
|
+
// When the user chooses the maid whale
|
|
107
108
|
expect(state()).toMatchObject({ petSelectionFallback: true, petId: { text: 'whale-girl' }, dirty: false })
|
|
108
109
|
face.edit('petId', '')
|
|
109
110
|
expect(state()).toMatchObject({ dirty: false, petId: { text: 'whale-girl' } })
|
|
110
111
|
face.edit('petId', 'jyn')
|
|
111
|
-
expect(state()).toMatchObject({
|
|
112
|
-
face.save()
|
|
112
|
+
expect(state()).toMatchObject({ petId: { text: 'jyn' } })
|
|
113
113
|
await vi.waitFor(() => { expect(state().saving).toBe(false) })
|
|
114
114
|
|
|
115
115
|
// Then the pet service holds it, the draft clears, and the absent Host form is untouched
|
|
@@ -120,7 +120,7 @@ describe('pet selection without a Host settings form', () => {
|
|
|
120
120
|
controller.dispose()
|
|
121
121
|
})
|
|
122
122
|
|
|
123
|
-
it('user
|
|
123
|
+
it('user sees the selection go back when the pet API refuses it', async () => {
|
|
124
124
|
// Given the Host has no pet form and the pet API still serves its selection
|
|
125
125
|
vi.useFakeTimers()
|
|
126
126
|
const { scope } = unavailableForm()
|
|
@@ -134,12 +134,11 @@ describe('pet selection without a Host settings form', () => {
|
|
|
134
134
|
const controller = new PetSettingsCardController(scope)
|
|
135
135
|
await vi.advanceTimersByTimeAsync(0)
|
|
136
136
|
const face = controller.inject()
|
|
137
|
-
// When the user
|
|
137
|
+
// When the user picks a pet the pet API refuses
|
|
138
138
|
face.edit('petId', 'jyn')
|
|
139
|
-
face.save()
|
|
140
139
|
await vi.waitFor(() => { expect(face.hooks.petSettingsCard.getSnapshot().saving).toBe(false) })
|
|
141
|
-
// Then the choice
|
|
142
|
-
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty:
|
|
140
|
+
// Then the choice is back on the persisted pet and the failure is visible
|
|
141
|
+
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty: false, failed: true, petId: { text: 'whale-girl' } })
|
|
143
142
|
controller.dispose()
|
|
144
143
|
})
|
|
145
144
|
})
|
|
@@ -166,11 +165,10 @@ describe('pet visibility without a Host settings form', () => {
|
|
|
166
165
|
const face = controller.inject()
|
|
167
166
|
const state = () => face.hooks.petSettingsCard.getSnapshot()
|
|
168
167
|
|
|
169
|
-
// When the user switches the pet off
|
|
168
|
+
// When the user switches the pet off
|
|
170
169
|
expect(state()).toMatchObject({ petSelectionFallback: true, visible: { text: 'true' }, dirty: false })
|
|
171
170
|
face.edit('visible', 'false')
|
|
172
|
-
expect(state()).toMatchObject({
|
|
173
|
-
face.save()
|
|
171
|
+
expect(state()).toMatchObject({ visible: { text: 'false' } })
|
|
174
172
|
await vi.waitFor(() => { expect(state().saving).toBe(false) })
|
|
175
173
|
|
|
176
174
|
// Then the pet service holds it, the draft clears, and the absent Host form is untouched
|
|
@@ -181,7 +179,7 @@ describe('pet visibility without a Host settings form', () => {
|
|
|
181
179
|
controller.dispose()
|
|
182
180
|
})
|
|
183
181
|
|
|
184
|
-
it('user
|
|
182
|
+
it('user sees the switch go back when the pet API refuses the visibility write', async () => {
|
|
185
183
|
// Given the Host has no pet form and the pet API refuses visibility writes
|
|
186
184
|
vi.useFakeTimers()
|
|
187
185
|
const { scope } = unavailableForm()
|
|
@@ -195,12 +193,11 @@ describe('pet visibility without a Host settings form', () => {
|
|
|
195
193
|
const controller = new PetSettingsCardController(scope)
|
|
196
194
|
await vi.advanceTimersByTimeAsync(0)
|
|
197
195
|
const face = controller.inject()
|
|
198
|
-
// When the user
|
|
196
|
+
// When the user flips a visibility the pet API refuses
|
|
199
197
|
face.edit('visible', 'false')
|
|
200
|
-
face.save()
|
|
201
198
|
await vi.waitFor(() => { expect(face.hooks.petSettingsCard.getSnapshot().saving).toBe(false) })
|
|
202
|
-
// Then the switch
|
|
203
|
-
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty:
|
|
199
|
+
// Then the switch is back on the persisted visibility and the failure is visible
|
|
200
|
+
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty: false, failed: true, visible: { text: 'true' } })
|
|
204
201
|
controller.dispose()
|
|
205
202
|
})
|
|
206
203
|
})
|
|
@@ -237,7 +234,7 @@ describe('pet settings card rendered without a Host settings form', () => {
|
|
|
237
234
|
expect(screen.getByLabelText(t('settings.pet'))).toBeTruthy()
|
|
238
235
|
expect(screen.getByLabelText(t('settings.visible'))).toBeTruthy()
|
|
239
236
|
// ...while the fields only the absent Host form owns stay hidden
|
|
240
|
-
expect(screen.
|
|
237
|
+
expect(screen.queryByRole('switch')).toBeNull()
|
|
241
238
|
expect(screen.queryByLabelText(t('settings.size'))).toBeNull()
|
|
242
239
|
controller.dispose()
|
|
243
240
|
})
|
|
@@ -273,13 +270,12 @@ describe('the status bubble switch on the Host settings form', () => {
|
|
|
273
270
|
expect(screen.getByLabelText(t('settings.statusBubbles'))).toBeTruthy()
|
|
274
271
|
expect(state()).toMatchObject({ statusBubbles: { text: 'auto', invalid: false } })
|
|
275
272
|
|
|
276
|
-
// When the user picks Off
|
|
273
|
+
// When the user picks Off
|
|
277
274
|
face.edit('statusBubbles', 'off')
|
|
278
|
-
expect(state()).toMatchObject({
|
|
279
|
-
face.save()
|
|
275
|
+
expect(state()).toMatchObject({ statusBubbles: { text: 'off' } })
|
|
280
276
|
await vi.waitFor(() => { expect(state().saving).toBe(false) })
|
|
281
277
|
|
|
282
|
-
// Then the settings document holds the mode, and the draft clears
|
|
278
|
+
// Then the settings document holds the mode with no further step, and the draft clears
|
|
283
279
|
expect(mutate).toHaveBeenCalledWith([{ op: 'set', path: ['statusBubbles'], value: 'off' }])
|
|
284
280
|
expect(value().user?.statusBubbles).toBe('off')
|
|
285
281
|
expect(state()).toMatchObject({ dirty: false, failed: false, statusBubbles: { text: 'off' } })
|
|
@@ -300,3 +296,13 @@ describe('the status bubble switch on the Host settings form', () => {
|
|
|
300
296
|
})
|
|
301
297
|
})
|
|
302
298
|
})
|
|
299
|
+
|
|
300
|
+
describe('the coarse sliders on the display fields', () => {
|
|
301
|
+
it('cover the bounds the host schema accepts for size and bubble scale', () => {
|
|
302
|
+
// The card spells the spans as literals because the browser half never
|
|
303
|
+
// imports the host module; this keeps the two from drifting apart.
|
|
304
|
+
expect(SIZE_RANGE).toMatchObject({ min: DISPLAY_SIZE_MIN, max: DISPLAY_SIZE_MAX })
|
|
305
|
+
expect(BUBBLE_SCALE_RANGE).toMatchObject({ min: BUBBLE_SCALE_MIN, max: BUBBLE_SCALE_MAX })
|
|
306
|
+
expect(INSET_RANGE.max).toBeLessThanOrEqual(DISPLAY_INSET_MAX)
|
|
307
|
+
})
|
|
308
|
+
})
|
|
@@ -15,7 +15,9 @@ import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
|
15
15
|
import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
16
16
|
// Type-only: pulls the settings-surface SlotMap merge (the 'settings.section' entry).
|
|
17
17
|
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
18
|
-
import {
|
|
18
|
+
import type {} from './web-extension-contract.ts'
|
|
19
|
+
import { PluginSettingsCard, ValueField, BooleanField, ChoiceField, ToggleSwitch } from './PluginSettingsCard.tsx'
|
|
20
|
+
import { PetPreview, type PetPreviewDefinition } from './PetPreview.tsx'
|
|
19
21
|
import { CardForm, booleanField, choiceField, numberField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
|
|
20
22
|
import sectionCss from './settings-section.module.css'
|
|
21
23
|
|
|
@@ -65,6 +67,8 @@ export interface PetSettingsCardState extends CardShell {
|
|
|
65
67
|
statusBubbles: CardFieldState
|
|
66
68
|
/** Pet choices (registry ids + display names), loaded from the host. */
|
|
67
69
|
petChoices: readonly { value: string; label: string }[]
|
|
70
|
+
/** The same registry entries with the visual data their thumbnails need. */
|
|
71
|
+
petPreviews: readonly PetPreviewDefinition[]
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
/** The registration-side face the card's slot entry injects. */
|
|
@@ -82,11 +86,18 @@ export interface PetSettingsCardFace extends CardActions {
|
|
|
82
86
|
*/
|
|
83
87
|
const STATUS_BUBBLE_CHOICES = ['auto', 'off'] as const
|
|
84
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The spans the coarse sliders cover, spelled as literals for the same reason.
|
|
91
|
+
* Size and bubble scale are the schema's own bounds (src/persist.ts); the
|
|
92
|
+
* insets reach the schema's far end only by typing, so their slider covers the
|
|
93
|
+
* distances a window can show.
|
|
94
|
+
*/
|
|
95
|
+
export const SIZE_RANGE = { min: 32, max: 1024, step: 1 }
|
|
96
|
+
export const INSET_RANGE = { min: 0, max: 1000, step: 1 }
|
|
97
|
+
export const BUBBLE_SCALE_RANGE = { min: 0.5, max: 2, step: 0.05 }
|
|
98
|
+
|
|
85
99
|
/** One registry choice as served by '/api/pet/pets'. */
|
|
86
|
-
|
|
87
|
-
id: string
|
|
88
|
-
displayName: string
|
|
89
|
-
}
|
|
100
|
+
type PetChoice = PetPreviewDefinition
|
|
90
101
|
|
|
91
102
|
/** Fetch the registry list (the same data the sprite renders from). */
|
|
92
103
|
async function fetchPetChoices(): Promise<PetChoice[]> {
|
|
@@ -122,11 +133,14 @@ export class PetSettingsCardController {
|
|
|
122
133
|
// without rebuilding the form.
|
|
123
134
|
private readonly petChoices: string[] = []
|
|
124
135
|
private readonly petLabels = new Map<string, string>()
|
|
136
|
+
private petPreviews: PetPreviewDefinition[] = []
|
|
125
137
|
private selectedPetId: string | undefined
|
|
126
138
|
private selectedVisible: boolean | undefined
|
|
127
139
|
private stagedPetId: string | undefined
|
|
128
140
|
private stagedVisible: boolean | undefined
|
|
129
141
|
private savingPet = false
|
|
142
|
+
/** A fallback pick made while a write was in flight. */
|
|
143
|
+
private fallbackQueued = false
|
|
130
144
|
private petSaveFailed = false
|
|
131
145
|
private loaded = false
|
|
132
146
|
private attempts = 0
|
|
@@ -171,6 +185,7 @@ export class PetSettingsCardController {
|
|
|
171
185
|
const list = await fetchPetChoices()
|
|
172
186
|
if (this.disposed) return
|
|
173
187
|
this.petChoices.splice(0, this.petChoices.length, ...list.map(choice => choice.id))
|
|
188
|
+
this.petPreviews = list
|
|
174
189
|
for (const choice of list) this.petLabels.set(choice.id, choice.displayName)
|
|
175
190
|
this.loaded = true
|
|
176
191
|
this.store.set(this.projection())
|
|
@@ -219,12 +234,16 @@ export class PetSettingsCardController {
|
|
|
219
234
|
* Persist the staged selection and visibility through the pet API — the only
|
|
220
235
|
* writer available when the aggregate shell serves this card, since there is
|
|
221
236
|
* no Host settings form to mutate — then confirm the read-back before the
|
|
222
|
-
* drafts are cleared.
|
|
237
|
+
* drafts are cleared. A refused write puts both picks back to what the pet
|
|
238
|
+
* persisted. A pick made while a write is in flight runs once it settles.
|
|
223
239
|
*/
|
|
224
240
|
private async saveFallback(): Promise<void> {
|
|
225
241
|
const petId = this.stagedPetId
|
|
226
242
|
const visible = this.stagedVisible
|
|
227
|
-
if (this.savingPet)
|
|
243
|
+
if (this.savingPet) {
|
|
244
|
+
this.fallbackQueued = true
|
|
245
|
+
return
|
|
246
|
+
}
|
|
228
247
|
if (petId === undefined && visible === undefined) return
|
|
229
248
|
if (petId !== undefined && !this.petChoices.includes(petId)) return
|
|
230
249
|
this.savingPet = true
|
|
@@ -259,10 +278,16 @@ export class PetSettingsCardController {
|
|
|
259
278
|
if (this.stagedVisible === visible) this.stagedVisible = undefined
|
|
260
279
|
} catch {
|
|
261
280
|
this.petSaveFailed = true
|
|
281
|
+
if (this.stagedPetId === petId) this.stagedPetId = undefined
|
|
282
|
+
if (this.stagedVisible === visible) this.stagedVisible = undefined
|
|
262
283
|
} finally {
|
|
263
284
|
this.savingPet = false
|
|
264
285
|
if (!this.disposed) this.store.set(this.projection())
|
|
265
286
|
}
|
|
287
|
+
if (this.fallbackQueued && !this.disposed) {
|
|
288
|
+
this.fallbackQueued = false
|
|
289
|
+
await this.saveFallback()
|
|
290
|
+
}
|
|
266
291
|
}
|
|
267
292
|
|
|
268
293
|
private projection(): PetSettingsCardState {
|
|
@@ -296,6 +321,7 @@ export class PetSettingsCardController {
|
|
|
296
321
|
? { ...configuredPet, text: this.selectedPetId }
|
|
297
322
|
: configuredPet,
|
|
298
323
|
petChoices: this.petChoices.map(id => ({ value: id, label: this.petLabels.get(id) ?? id })),
|
|
324
|
+
petPreviews: this.petPreviews,
|
|
299
325
|
}
|
|
300
326
|
}
|
|
301
327
|
|
|
@@ -307,6 +333,8 @@ export class PetSettingsCardController {
|
|
|
307
333
|
const actions = this.form.actions()
|
|
308
334
|
return {
|
|
309
335
|
hooks: { petSettingsCard: this.store },
|
|
336
|
+
// The fallback's two fields are both picks, so each is written through
|
|
337
|
+
// the pet API the moment it is made, as the form writes its own picks.
|
|
310
338
|
edit: (field, value) => {
|
|
311
339
|
if (!this.fallback()) return actions.edit(field, value)
|
|
312
340
|
if (field === 'petId') this.stagedPetId = value === '' ? undefined : value
|
|
@@ -314,6 +342,7 @@ export class PetSettingsCardController {
|
|
|
314
342
|
else return
|
|
315
343
|
this.petSaveFailed = false
|
|
316
344
|
this.store.set(this.projection())
|
|
345
|
+
void this.saveFallback()
|
|
317
346
|
},
|
|
318
347
|
resetField: (field) => {
|
|
319
348
|
if (!this.fallback()) return actions.resetField(field)
|
|
@@ -368,126 +397,188 @@ export function PetSettingsCard(props: PetSettingsCardProps) {
|
|
|
368
397
|
resetLabel: t('settings.reset'),
|
|
369
398
|
invalidLabel: t('settings.invalidNumber'),
|
|
370
399
|
disabled,
|
|
400
|
+
presentation: 'segment' as const,
|
|
371
401
|
}
|
|
402
|
+
// The master switch sits in the header, as the Workshop and Usage pages
|
|
403
|
+
// carry theirs; the fallback has no Host form to write it through.
|
|
404
|
+
const enabledSwitch = state.petSelectionFallback
|
|
405
|
+
? undefined
|
|
406
|
+
: (
|
|
407
|
+
<ToggleSwitch
|
|
408
|
+
labelledBy="settings-pet-title"
|
|
409
|
+
checked={state.enabled.text !== 'false'}
|
|
410
|
+
disabled={disabled}
|
|
411
|
+
onChange={(next) => { props.edit('enabled', String(next)) }}
|
|
412
|
+
/>
|
|
413
|
+
)
|
|
372
414
|
return (
|
|
373
415
|
<PluginSettingsCard
|
|
374
416
|
t={t}
|
|
375
417
|
titleKey="settings.title"
|
|
418
|
+
titleId="settings-pet-title"
|
|
376
419
|
descriptionKey="settings.description"
|
|
377
420
|
descriptionNode={state.petSelectionFallback ? t('settings.petHint') : undefined}
|
|
421
|
+
headerAction={enabledSwitch}
|
|
378
422
|
state={state}
|
|
379
423
|
onSave={props.save}
|
|
380
424
|
onDiscard={props.discard}
|
|
381
425
|
alwaysOpen
|
|
382
426
|
>
|
|
383
|
-
{
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
427
|
+
<div className={sectionCss.settingsLayout}>
|
|
428
|
+
<section className={sectionCss.selectionGroup}>
|
|
429
|
+
<div className={sectionCss.groupHeader}>
|
|
430
|
+
<h3 className={sectionCss.groupTitle} id="settings-pet-selection-title">{t('settings.pet')}</h3>
|
|
431
|
+
{state.petId.overridden
|
|
432
|
+
? (
|
|
433
|
+
<button
|
|
434
|
+
type="button"
|
|
435
|
+
className={sectionCss.textAction}
|
|
436
|
+
disabled={disabled}
|
|
437
|
+
onClick={() => { props.resetField('petId') }}
|
|
438
|
+
>
|
|
439
|
+
{t('settings.reset')}
|
|
440
|
+
</button>
|
|
441
|
+
)
|
|
442
|
+
: null}
|
|
443
|
+
</div>
|
|
444
|
+
<div
|
|
445
|
+
id="settings-pet-pet"
|
|
446
|
+
className={sectionCss.petGrid}
|
|
447
|
+
role="group"
|
|
448
|
+
aria-labelledby="settings-pet-selection-title"
|
|
449
|
+
>
|
|
450
|
+
{state.petPreviews.map(pet => {
|
|
451
|
+
const selected = state.petId.text === pet.id
|
|
452
|
+
return (
|
|
453
|
+
<button
|
|
454
|
+
key={pet.id}
|
|
455
|
+
type="button"
|
|
456
|
+
className={selected ? `${sectionCss.petChoice} ${sectionCss.petChoiceSelected}` : sectionCss.petChoice}
|
|
457
|
+
aria-pressed={selected}
|
|
458
|
+
title={pet.displayName}
|
|
459
|
+
disabled={disabled}
|
|
460
|
+
onClick={() => { props.edit('petId', pet.id) }}
|
|
461
|
+
>
|
|
462
|
+
<PetPreview pet={pet} />
|
|
463
|
+
<span className={sectionCss.petChoiceLabel}>{pet.displayName}</span>
|
|
464
|
+
</button>
|
|
465
|
+
)
|
|
466
|
+
})}
|
|
467
|
+
</div>
|
|
468
|
+
<p className={state.petId.invalid ? sectionCss.invalid : sectionCss.groupHint}>
|
|
469
|
+
{state.petId.invalid ? t('settings.invalidNumber') : t('settings.petHint')}
|
|
470
|
+
</p>
|
|
471
|
+
</section>
|
|
472
|
+
|
|
473
|
+
<div className={sectionCss.settingsColumn}>
|
|
474
|
+
<section className={sectionCss.settingsGroup}>
|
|
475
|
+
<div className={sectionCss.groupHeader}>
|
|
476
|
+
<h3 className={sectionCss.groupTitle} id="settings-pet-display-title">{t('settings.displayGroup')}</h3>
|
|
477
|
+
</div>
|
|
478
|
+
<div className={sectionCss.fields}>
|
|
479
|
+
<BooleanField
|
|
480
|
+
id="settings-pet-visible"
|
|
481
|
+
label={t('settings.visible')}
|
|
482
|
+
hint={t('settings.visibleHint')}
|
|
483
|
+
inheritLabel={t('settings.inherit')}
|
|
484
|
+
onLabel={t('settings.on')}
|
|
485
|
+
offLabel={t('settings.off')}
|
|
486
|
+
{...fieldProps}
|
|
487
|
+
{...state.visible}
|
|
488
|
+
onEdit={(text) => { props.edit('visible', text) }}
|
|
489
|
+
onReset={() => { props.resetField('visible') }}
|
|
490
|
+
/>
|
|
491
|
+
{state.petSelectionFallback ? null : <ValueField
|
|
492
|
+
id="settings-pet-size"
|
|
493
|
+
label={t('settings.size')}
|
|
494
|
+
hint={t('settings.sizeHint')}
|
|
495
|
+
numeric
|
|
496
|
+
range={SIZE_RANGE}
|
|
497
|
+
{...fieldProps}
|
|
498
|
+
{...state.size}
|
|
499
|
+
onEdit={(text) => { props.edit('size', text) }}
|
|
500
|
+
onReset={() => { props.resetField('size') }}
|
|
501
|
+
/>}
|
|
502
|
+
{state.petSelectionFallback ? null : <ValueField
|
|
503
|
+
id="settings-pet-right"
|
|
504
|
+
label={t('settings.right')}
|
|
505
|
+
hint={t('settings.rightHint')}
|
|
506
|
+
numeric
|
|
507
|
+
range={INSET_RANGE}
|
|
508
|
+
{...fieldProps}
|
|
509
|
+
{...state.right}
|
|
510
|
+
onEdit={(text) => { props.edit('right', text) }}
|
|
511
|
+
onReset={() => { props.resetField('right') }}
|
|
512
|
+
/>}
|
|
513
|
+
{state.petSelectionFallback ? null : <ValueField
|
|
514
|
+
id="settings-pet-bottom"
|
|
515
|
+
label={t('settings.bottom')}
|
|
516
|
+
hint={t('settings.bottomHint')}
|
|
517
|
+
numeric
|
|
518
|
+
range={INSET_RANGE}
|
|
519
|
+
{...fieldProps}
|
|
520
|
+
{...state.bottom}
|
|
521
|
+
onEdit={(text) => { props.edit('bottom', text) }}
|
|
522
|
+
onReset={() => { props.resetField('bottom') }}
|
|
523
|
+
/>}
|
|
524
|
+
</div>
|
|
525
|
+
</section>
|
|
526
|
+
|
|
527
|
+
{state.petSelectionFallback ? null : (
|
|
528
|
+
<section className={sectionCss.settingsGroup}>
|
|
529
|
+
<div className={sectionCss.groupHeader}>
|
|
530
|
+
<h3 className={sectionCss.groupTitle} id="settings-pet-behavior-title">{t('settings.bubbleGroup')}</h3>
|
|
531
|
+
</div>
|
|
532
|
+
<div className={sectionCss.fields}>
|
|
533
|
+
<BooleanField
|
|
534
|
+
id="settings-pet-decoration"
|
|
535
|
+
label={t('settings.decoration')}
|
|
536
|
+
hint={t('settings.decorationHint')}
|
|
537
|
+
inheritLabel={t('settings.inherit')}
|
|
538
|
+
onLabel={t('settings.on')}
|
|
539
|
+
offLabel={t('settings.off')}
|
|
540
|
+
{...fieldProps}
|
|
541
|
+
{...state.decorationEnabled}
|
|
542
|
+
onEdit={(text) => { props.edit('decorationEnabled', text) }}
|
|
543
|
+
onReset={() => { props.resetField('decorationEnabled') }}
|
|
544
|
+
/>
|
|
545
|
+
<ChoiceField
|
|
546
|
+
id="settings-pet-status-bubbles"
|
|
547
|
+
label={t('settings.statusBubbles')}
|
|
548
|
+
hint={t('settings.statusBubblesHint')}
|
|
549
|
+
inheritLabel={t('settings.inherit')}
|
|
550
|
+
{...fieldProps}
|
|
551
|
+
{...state.statusBubbles}
|
|
552
|
+
choices={[
|
|
553
|
+
{ value: STATUS_BUBBLE_CHOICES[0], label: t('settings.on') },
|
|
554
|
+
{ value: STATUS_BUBBLE_CHOICES[1], label: t('settings.off') },
|
|
555
|
+
]}
|
|
556
|
+
onEdit={(text) => { props.edit('statusBubbles', text) }}
|
|
557
|
+
onReset={() => { props.resetField('statusBubbles') }}
|
|
558
|
+
/>
|
|
559
|
+
<ValueField
|
|
560
|
+
id="settings-pet-bubble-scale"
|
|
561
|
+
label={t('settings.bubbleScale')}
|
|
562
|
+
hint={t('settings.bubbleScaleHint')}
|
|
563
|
+
numeric
|
|
564
|
+
range={BUBBLE_SCALE_RANGE}
|
|
565
|
+
{...fieldProps}
|
|
566
|
+
{...state.bubbleScale}
|
|
567
|
+
onEdit={(text) => { props.edit('bubbleScale', text) }}
|
|
568
|
+
onReset={() => { props.resetField('bubbleScale') }}
|
|
569
|
+
/>
|
|
570
|
+
</div>
|
|
571
|
+
</section>
|
|
572
|
+
)}
|
|
573
|
+
</div>
|
|
574
|
+
</div>
|
|
484
575
|
</PluginSettingsCard>
|
|
485
576
|
)
|
|
486
577
|
}
|
|
487
578
|
|
|
488
579
|
/** Props the settings section binds for the pet card page. */
|
|
489
580
|
export type PetSettingsSectionProps =
|
|
490
|
-
PropsRuntime<'settings.section'>
|
|
581
|
+
(PropsRuntime<'settings.section'> | PropsRuntime<'web-ui.extension'>)
|
|
491
582
|
& PropsLocale<'pet'>
|
|
492
583
|
& InjectFace<PetSettingsCardFace>
|
|
493
584
|
|
|
@@ -495,7 +586,7 @@ export type PetSettingsSectionProps =
|
|
|
495
586
|
export function PetSettingsSection(props: PetSettingsSectionProps): ReactNode {
|
|
496
587
|
const { t, usePetSettingsCard, save, discard, edit, resetField } = props
|
|
497
588
|
return (
|
|
498
|
-
<ul className={sectionCss.sectionList}>
|
|
589
|
+
<ul className={sectionCss.sectionList} data-dsh-plugin="pet" data-dsh-part="panel">
|
|
499
590
|
<PetSettingsCard t={t} usePetSettingsCard={usePetSettingsCard} save={save} discard={discard} edit={edit} resetField={resetField} />
|
|
500
591
|
</ul>
|
|
501
592
|
)
|