@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
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Family-shared chrome for plugin settings cards: a disclosure header naming
|
|
3
|
-
* the plugin and what its settings govern, the controls inside, and the
|
|
4
|
-
* that
|
|
3
|
+
* the plugin and what its settings govern, the controls inside, and the line
|
|
4
|
+
* that reports a refused write. A pick is written the moment it is made and a
|
|
5
|
+
* typed value after a pause, so the card has no save button and nothing waits
|
|
6
|
+
* on the reader. Renders nothing while the namespace is unavailable — a
|
|
5
7
|
* deployment that does not compose the owning plugin should show no trace of
|
|
6
8
|
* it. Inlined into each consumer's client bundle; mirrors the official
|
|
7
9
|
* ui-plugin-config PluginCard in a self-contained slice.
|
|
10
|
+
*
|
|
11
|
+
* Every field inside the body is one settings row: the label and its hint on
|
|
12
|
+
* the left, the control on the right, a hairline between two rows; a narrow
|
|
13
|
+
* card stacks the control under the text (settings-card.module.css).
|
|
8
14
|
*/
|
|
9
15
|
import { type ReactNode } from 'react';
|
|
10
16
|
import type { CardShell } from './settings-form.ts';
|
|
11
17
|
/** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
|
|
12
|
-
export declare const CARD_COPY_KEYS: readonly ["settings.collapse", "settings.expand", "settings.notExposed", "settings.
|
|
18
|
+
export declare const CARD_COPY_KEYS: readonly ["settings.collapse", "settings.expand", "settings.notExposed", "settings.readOnly", "settings.saveFailed"];
|
|
13
19
|
/** Copy key the card chrome itself reads. */
|
|
14
20
|
export type CardCopyKey = (typeof CARD_COPY_KEYS)[number];
|
|
15
21
|
/** Key domain for the plugin's own copy (inferred per consumer). */
|
|
@@ -24,12 +30,40 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
24
30
|
descriptionKey: TKey;
|
|
25
31
|
/** Optional rich header description rendered instead of the plain t(descriptionKey) text (the plain text stays as the tooltip). */
|
|
26
32
|
descriptionNode?: ReactNode;
|
|
27
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Locale key of the full sentence behind a shortened description: when
|
|
35
|
+
* present, the header's native `title` takes this text while the visible
|
|
36
|
+
* line keeps `descriptionKey`/`descriptionNode`, so a compact card can
|
|
37
|
+
* compress the sentence without keeping a second visible copy of it.
|
|
38
|
+
* Defaults to the description key.
|
|
39
|
+
*/
|
|
40
|
+
descriptionTitleKey?: TKey;
|
|
41
|
+
/**
|
|
42
|
+
* Optional leading mark identifying the plugin. A card without one keeps the
|
|
43
|
+
* plain official header shape, so the chrome stays a readable sibling of the
|
|
44
|
+
* built-in PluginCard wherever a family plugin lands in the official bundle
|
|
45
|
+
* seat.
|
|
46
|
+
*/
|
|
47
|
+
icon?: ReactNode;
|
|
48
|
+
/** The card's form state: availability, writability, and how the last write went. */
|
|
28
49
|
state: CardShell;
|
|
29
|
-
/** Write every
|
|
50
|
+
/** Write every pending draft now: a text field's Enter or blur. */
|
|
30
51
|
onSave: () => void;
|
|
31
|
-
/** Drop every
|
|
52
|
+
/** Drop every pending draft: a text field's Escape. */
|
|
32
53
|
onDiscard: () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Id applied to the card's title element, so a header control (an immediate
|
|
56
|
+
* toggle in `headerAction`) can name itself through `aria-labelledby`
|
|
57
|
+
* instead of repeating the title as a string.
|
|
58
|
+
*/
|
|
59
|
+
titleId?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Render the header only, with no body region. A card whose whole setting is
|
|
62
|
+
* the header control (a switch whose explanation is the description) has no
|
|
63
|
+
* controls to lay out below it, and an empty body would draw a divider line
|
|
64
|
+
* with nothing under it.
|
|
65
|
+
*/
|
|
66
|
+
headerOnly?: boolean;
|
|
33
67
|
/**
|
|
34
68
|
* Render the controls expanded on arrival (still collapsible). Defaults to
|
|
35
69
|
* true: promoted first-level sections show their settings immediately.
|
|
@@ -42,15 +76,29 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
42
76
|
*/
|
|
43
77
|
alwaysOpen?: boolean;
|
|
44
78
|
/**
|
|
45
|
-
* Hide the
|
|
46
|
-
*
|
|
47
|
-
*
|
|
79
|
+
* Hide the line under the body that reports a refused write: a card whose
|
|
80
|
+
* body applies its own changes (an embedded external settings section)
|
|
81
|
+
* reports its own failures.
|
|
48
82
|
*/
|
|
49
83
|
hideFooter?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Optional control rendered at the header's trailing edge, before the
|
|
86
|
+
* chevron. A card whose setting is one immediate flip (it
|
|
87
|
+
* applies outside the card's form) puts its ToggleSwitch here, so the control
|
|
88
|
+
* is reachable without opening the card and matches a plugin card's shape.
|
|
89
|
+
*/
|
|
90
|
+
headerAction?: ReactNode;
|
|
50
91
|
/** Render children even when the settings namespace is not exposed by the host. */
|
|
51
92
|
renderChildrenWhenNotExposed?: boolean;
|
|
52
93
|
/** Hide the 'not exposed' warning banner when the settings namespace is not exposed. */
|
|
53
94
|
hideNotExposedNotice?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Compact chrome for a topic card rendered inside another card's body: a
|
|
97
|
+
* smaller title, a tighter header and body inset, and a one-line description
|
|
98
|
+
* whose full text stays on the header's own title. Defaults to the
|
|
99
|
+
* first-level chrome, which is unchanged.
|
|
100
|
+
*/
|
|
101
|
+
density?: 'nested';
|
|
54
102
|
/** The plugin's controls. */
|
|
55
103
|
children: ReactNode;
|
|
56
104
|
}
|
|
@@ -68,9 +116,15 @@ export interface FieldProps {
|
|
|
68
116
|
label: string;
|
|
69
117
|
/** One-line explanation rendered under the control. */
|
|
70
118
|
hint: string;
|
|
119
|
+
/**
|
|
120
|
+
* Full sentence behind the visible hint, exposed as the paragraph's native
|
|
121
|
+
* `title` so a card can shorten the line without losing the text. Omitted:
|
|
122
|
+
* the paragraph carries no title attribute at all.
|
|
123
|
+
*/
|
|
124
|
+
hintTitle?: string;
|
|
71
125
|
/** Draft text this control renders. */
|
|
72
126
|
text: string;
|
|
73
|
-
/** True when
|
|
127
|
+
/** True when the field holds a user-layer entry over the inherited value. */
|
|
74
128
|
overridden: boolean;
|
|
75
129
|
/** True when the draft is not a value this field accepts. */
|
|
76
130
|
invalid: boolean;
|
|
@@ -82,17 +136,29 @@ export interface FieldProps {
|
|
|
82
136
|
invalidLabel: string;
|
|
83
137
|
/** Disables every control (read-only document, or an unavailable namespace). */
|
|
84
138
|
disabled: boolean;
|
|
85
|
-
/**
|
|
139
|
+
/** Take new draft text; the card writes it as the field's entry rule says. */
|
|
86
140
|
onEdit: (text: string) => void;
|
|
87
|
-
/**
|
|
141
|
+
/** Clear the field at once so it re-inherits the composition layer. */
|
|
88
142
|
onReset: () => void;
|
|
89
143
|
}
|
|
90
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* A typed value field. Its draft is written after a pause in typing, at once on
|
|
146
|
+
* Enter or when focus leaves, and Escape puts the stored value back. `numeric`
|
|
147
|
+
* only hints the keypad: which drafts a field accepts is decided by its spec.
|
|
148
|
+
* A field given a `range` also offers the coarse slider bubble: dragging fills
|
|
149
|
+
* the draft live and releasing writes it.
|
|
150
|
+
*/
|
|
91
151
|
export declare function ValueField(props: FieldProps & {
|
|
92
152
|
/** Hints a numeric keypad without narrowing what the control accepts. */
|
|
93
153
|
numeric?: boolean;
|
|
94
154
|
/** Placeholder shown while the draft is empty. */
|
|
95
155
|
placeholder?: string;
|
|
156
|
+
/** Bounds of a numeric field, for the coarse slider; the spec still judges every draft. */
|
|
157
|
+
range?: {
|
|
158
|
+
min: number;
|
|
159
|
+
max: number;
|
|
160
|
+
step: number;
|
|
161
|
+
};
|
|
96
162
|
}): import("react").JSX.Element;
|
|
97
163
|
interface SelectOption {
|
|
98
164
|
value: string;
|
|
@@ -103,8 +169,8 @@ interface SelectOption {
|
|
|
103
169
|
* renders the legacy native `<select>` untouched, so element-level skin
|
|
104
170
|
* selectors keep working; under the default appearance it renders a
|
|
105
171
|
* self-drawn `role="listbox"` popup whose open/close is transition-animated.
|
|
106
|
-
*
|
|
107
|
-
*
|
|
172
|
+
* Cards reach it through BooleanField/ChoiceField; editors outside a card
|
|
173
|
+
* (the side-card prefs) bind it directly through onEdit.
|
|
108
174
|
* 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
|
|
109
175
|
*/
|
|
110
176
|
export declare function SelectField(props: {
|
|
@@ -115,7 +181,25 @@ export declare function SelectField(props: {
|
|
|
115
181
|
invalid: boolean;
|
|
116
182
|
onEdit: (text: string) => void;
|
|
117
183
|
}): import("react").JSX.Element;
|
|
118
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* A visible segmented group for a small set of mutually exclusive values.
|
|
186
|
+
* Every option stays on screen, so inherit/on/off and short enum fields take
|
|
187
|
+
* one click without opening a popup. The pressed option carries the group's
|
|
188
|
+
* sliding highlight and `aria-pressed`; the group takes the field label as its
|
|
189
|
+
* accessible name.
|
|
190
|
+
*/
|
|
191
|
+
export declare function SegmentField(props: {
|
|
192
|
+
id: string;
|
|
193
|
+
label: string;
|
|
194
|
+
options: ReadonlyArray<SelectOption>;
|
|
195
|
+
value: string;
|
|
196
|
+
disabled: boolean;
|
|
197
|
+
invalid: boolean;
|
|
198
|
+
onEdit: (text: string) => void;
|
|
199
|
+
}): import("react").JSX.Element;
|
|
200
|
+
/** How a small single-choice field presents its options. */
|
|
201
|
+
export type FieldPresentation = 'select' | 'segment';
|
|
202
|
+
/** A boolean field: 继承 / 开 / 关. */
|
|
119
203
|
export declare function BooleanField(props: FieldProps & {
|
|
120
204
|
/** Copy for the inherit option. */
|
|
121
205
|
inheritLabel: string;
|
|
@@ -123,8 +207,10 @@ export declare function BooleanField(props: FieldProps & {
|
|
|
123
207
|
onLabel: string;
|
|
124
208
|
/** Copy for the off option. */
|
|
125
209
|
offLabel: string;
|
|
210
|
+
/** Defaults to the visible segments: the three answers always fit on one row. */
|
|
211
|
+
presentation?: FieldPresentation;
|
|
126
212
|
}): import("react").JSX.Element;
|
|
127
|
-
/**
|
|
213
|
+
/** An enumerated field, selecting or segmenting its small choice set. */
|
|
128
214
|
export declare function ChoiceField(props: FieldProps & {
|
|
129
215
|
/** Copy for the inherit option (draft text is the empty string). */
|
|
130
216
|
inheritLabel: string;
|
|
@@ -133,6 +219,34 @@ export declare function ChoiceField(props: FieldProps & {
|
|
|
133
219
|
value: string;
|
|
134
220
|
label: string;
|
|
135
221
|
}>;
|
|
222
|
+
/**
|
|
223
|
+
* Visible segmented options for a short fixed set; defaults to the compact
|
|
224
|
+
* select, which also suits a list whose length follows the deployment.
|
|
225
|
+
*/
|
|
226
|
+
presentation?: FieldPresentation;
|
|
227
|
+
}): import("react").JSX.Element;
|
|
228
|
+
/**
|
|
229
|
+
* A boolean toggle drawn as a switch track, for a setting that is only on or
|
|
230
|
+
* off and applies on flip. It is a real button with
|
|
231
|
+
* `role="switch"` and `aria-checked`, so keyboard and assistive activation
|
|
232
|
+
* arrive as a click and the state is announced instead of inferred from a
|
|
233
|
+
* checkbox tick.
|
|
234
|
+
*
|
|
235
|
+
* The thumb bounces across only once the reader has pressed this switch: the
|
|
236
|
+
* press writes the mark that arms the bounce, so a page opening, a TAB
|
|
237
|
+
* switching back or a value arriving from elsewhere draws every thumb at rest.
|
|
238
|
+
*/
|
|
239
|
+
export declare function ToggleSwitch(props: {
|
|
240
|
+
/** Id of the element naming the switch (the card's title). */
|
|
241
|
+
labelledBy?: string;
|
|
242
|
+
/** Accessible name when no element labels it. */
|
|
243
|
+
ariaLabel?: string;
|
|
244
|
+
/** Current state. */
|
|
245
|
+
checked: boolean;
|
|
246
|
+
/** Disables the switch while a write is in flight or the Host refuses writes. */
|
|
247
|
+
disabled?: boolean;
|
|
248
|
+
/** Called with the requested next state. */
|
|
249
|
+
onChange: (next: boolean) => void;
|
|
136
250
|
}): import("react").JSX.Element;
|
|
137
251
|
export {};
|
|
138
252
|
//# sourceMappingURL=PluginSettingsCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginSettingsCard.d.ts","sourceRoot":"","sources":["../../../src/client/PluginSettingsCard.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PluginSettingsCard.d.ts","sourceRoot":"","sources":["../../../src/client/PluginSettingsCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAA4G,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAChJ,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAKnD,oGAAoG;AACpG,eAAO,MAAM,cAAc,sHAMjB,CAAA;AASV,6CAA6C;AAC7C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzD,oEAAoE;AACpE,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI,IAAI,GAAG,WAAW,CAAA;AAE9E,wDAAwD;AACxD,MAAM,WAAW,uBAAuB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IACnE,0CAA0C;IAC1C,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,MAAM,CAAA;IACnF,uCAAuC;IACvC,QAAQ,EAAE,IAAI,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|
@@ -1,27 +1,38 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// Generated by scripts/sync-shared.mjs from shared/client/settings/PluginSettingsCard.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
2
|
/**
|
|
4
3
|
* Family-shared chrome for plugin settings cards: a disclosure header naming
|
|
5
|
-
* the plugin and what its settings govern, the controls inside, and the
|
|
6
|
-
* that
|
|
4
|
+
* the plugin and what its settings govern, the controls inside, and the line
|
|
5
|
+
* that reports a refused write. A pick is written the moment it is made and a
|
|
6
|
+
* typed value after a pause, so the card has no save button and nothing waits
|
|
7
|
+
* on the reader. Renders nothing while the namespace is unavailable — a
|
|
7
8
|
* deployment that does not compose the owning plugin should show no trace of
|
|
8
9
|
* it. Inlined into each consumer's client bundle; mirrors the official
|
|
9
10
|
* ui-plugin-config PluginCard in a self-contained slice.
|
|
11
|
+
*
|
|
12
|
+
* Every field inside the body is one settings row: the label and its hint on
|
|
13
|
+
* the left, the control on the right, a hairline between two rows; a narrow
|
|
14
|
+
* card stacks the control under the text (settings-card.module.css).
|
|
10
15
|
*/
|
|
11
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
16
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
17
|
+
import { RangeBubble } from "./RangeBubble.js";
|
|
18
|
+
import { SegmentGroup } from "./SegmentGroup.js";
|
|
12
19
|
import css from './settings-card.module.css';
|
|
13
20
|
/** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
|
|
14
21
|
export const CARD_COPY_KEYS = [
|
|
15
22
|
'settings.collapse',
|
|
16
23
|
'settings.expand',
|
|
17
24
|
'settings.notExposed',
|
|
18
|
-
'settings.unsaved',
|
|
19
25
|
'settings.readOnly',
|
|
20
26
|
'settings.saveFailed',
|
|
21
|
-
'settings.discard',
|
|
22
|
-
'settings.save',
|
|
23
|
-
'settings.saving',
|
|
24
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* What a text field inside a card reaches without its plugin wiring it: write
|
|
30
|
+
* the pending draft now (Enter, leaving the field) or put it back (Escape).
|
|
31
|
+
* Picks need neither; they are written the moment they are made.
|
|
32
|
+
*/
|
|
33
|
+
const CardApply = createContext(null);
|
|
34
|
+
/** Length of the body's disclosure motion; it matches `--settings-card-motion` on the card root. */
|
|
35
|
+
const BODY_MOTION_MS = 180;
|
|
25
36
|
/**
|
|
26
37
|
* Render one plugin settings card.
|
|
27
38
|
* @param props - the plugin's copy keys, its form state, and its controls.
|
|
@@ -30,41 +41,102 @@ export const CARD_COPY_KEYS = [
|
|
|
30
41
|
export function PluginSettingsCard(props) {
|
|
31
42
|
const [open, setOpen] = useState(props.defaultOpen ?? true);
|
|
32
43
|
const { state, alwaysOpen } = props;
|
|
44
|
+
const expanded = alwaysOpen === true || open;
|
|
45
|
+
const [bodyPhase, setBodyPhase] = useState(expanded ? 'shown' : 'hidden');
|
|
46
|
+
const bodyRef = useRef(null);
|
|
47
|
+
// Enter and leave run the same pair: a body that should open is mounted
|
|
48
|
+
// closed for one frame so its transition has a state to leave, and a closing
|
|
49
|
+
// one stays mounted until its leg has run.
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
if (expanded) {
|
|
52
|
+
if (bodyPhase === 'hidden')
|
|
53
|
+
setBodyPhase('collapsed');
|
|
54
|
+
else if (bodyPhase === 'collapsed') {
|
|
55
|
+
const node = bodyRef.current;
|
|
56
|
+
if (node !== null)
|
|
57
|
+
void node.offsetHeight;
|
|
58
|
+
setBodyPhase('entering');
|
|
59
|
+
}
|
|
60
|
+
else if (bodyPhase === 'closing')
|
|
61
|
+
setBodyPhase('entering');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (bodyPhase === 'collapsed')
|
|
65
|
+
setBodyPhase('hidden');
|
|
66
|
+
else if (bodyPhase === 'entering' || bodyPhase === 'shown')
|
|
67
|
+
setBodyPhase('closing');
|
|
68
|
+
}, [expanded, bodyPhase]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (bodyPhase !== 'entering' && bodyPhase !== 'closing')
|
|
71
|
+
return;
|
|
72
|
+
const timer = setTimeout(() => {
|
|
73
|
+
setBodyPhase(bodyPhase === 'entering' ? 'shown' : 'hidden');
|
|
74
|
+
}, BODY_MOTION_MS);
|
|
75
|
+
return () => { clearTimeout(timer); };
|
|
76
|
+
}, [bodyPhase]);
|
|
33
77
|
if (!state.available)
|
|
34
78
|
return null;
|
|
35
79
|
const title = props.t(props.titleKey);
|
|
36
80
|
const description = props.t(props.descriptionKey);
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const cardClass =
|
|
81
|
+
const descriptionTitle = props.descriptionTitleKey === undefined ? description : props.t(props.descriptionTitleKey);
|
|
82
|
+
const baseClass = expanded ? `${css.cardOpen} ${css.card}` : css.card;
|
|
83
|
+
const cardClass = props.density === 'nested' ? `${baseClass} ${css.cardNested}` : baseClass;
|
|
84
|
+
/** The body region both legs share; a hidden phase renders nothing at all. */
|
|
85
|
+
const bodyRegion = (content) => bodyPhase === 'hidden'
|
|
86
|
+
? null
|
|
87
|
+
: (_jsx("div", { className: css.disclosure, "data-state": bodyPhase, ref: bodyRef, children: _jsx("div", { className: css.body, children: content }) }));
|
|
40
88
|
// With alwaysOpen the nav entry already provides the selection, so the
|
|
41
89
|
// header is a static title row instead of a disclosure button.
|
|
42
90
|
const header = alwaysOpen === true
|
|
43
|
-
? (_jsxs("div", { className: css.headerStatic, children: [_jsxs("span", { className: css.headText, children: [_jsx("span", { className: css.name, title: title, children: title }), _jsx("span", { className: css.description, title:
|
|
44
|
-
: (_jsxs("button", { type: "button", className: css.header, "aria-expanded": open, "aria-label": `${props.t(open ? 'settings.collapse' : 'settings.expand')}: ${title}`, onClick: () => { setOpen(!open); }, children: [_jsxs("span", { className: css.headText, children: [_jsx("span", { className: css.name, title: title, children: title }), _jsx("span", { className: css.description, title:
|
|
91
|
+
? (_jsxs("div", { className: css.headerStatic, children: [props.icon !== undefined ? _jsx("span", { className: css.mark, "aria-hidden": "true", children: props.icon }) : null, _jsxs("span", { className: css.headText, children: [_jsx("span", { className: css.name, id: props.titleId, title: title, children: title }), _jsx("span", { className: css.description, title: descriptionTitle, children: props.descriptionNode ?? description })] }), props.headerAction !== undefined ? _jsx("span", { className: css.headerAction, children: props.headerAction }) : null] }))
|
|
92
|
+
: (_jsxs("button", { type: "button", className: css.header, "aria-expanded": open, "aria-label": `${props.t(open ? 'settings.collapse' : 'settings.expand')}: ${title}`, onClick: () => { setOpen(!open); }, children: [props.icon !== undefined ? _jsx("span", { className: css.mark, "aria-hidden": "true", children: props.icon }) : null, _jsxs("span", { className: css.headText, children: [_jsx("span", { className: css.name, id: props.titleId, title: title, children: title }), _jsx("span", { className: css.description, title: descriptionTitle, children: props.descriptionNode ?? description })] }), props.headerAction !== undefined ? _jsx("span", { className: css.headerAction, children: props.headerAction }) : null, _jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: open ? `${css.chevron} ${css.chevronOpen}` : css.chevron, children: _jsx("path", { d: "M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z", fill: "currentColor" }) })] }));
|
|
45
93
|
// The namespace exists but the Host does not serve it to this client (the
|
|
46
94
|
// official settings allowlist omits third-party namespaces): show a card
|
|
47
95
|
// that explains the gap instead of vanishing, so a missing card never
|
|
48
96
|
// reads as a missing plugin.
|
|
49
97
|
if (!state.exposed && props.renderChildrenWhenNotExposed !== true) {
|
|
50
98
|
const showNotice = props.hideNotExposedNotice !== true;
|
|
51
|
-
return (_jsxs("li", { className: cardClass, children: [header,
|
|
52
|
-
? (_jsx("div", { className: css.body, children: showNotice ? _jsx("p", { className: css.notExposed, role: "status", children: props.t('settings.notExposed') }) : null }))
|
|
53
|
-
: null] }));
|
|
99
|
+
return (_jsxs("li", { className: cardClass, children: [header, bodyRegion(showNotice ? _jsx("p", { className: css.notExposed, role: "status", children: props.t('settings.notExposed') }) : null)] }));
|
|
54
100
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
101
|
+
// A header-only card has no body region at all: the divider would otherwise
|
|
102
|
+
// sit above an empty box.
|
|
103
|
+
const bodyVisible = props.headerOnly !== true;
|
|
104
|
+
return (_jsxs("li", { className: cardClass, children: [header, bodyVisible
|
|
105
|
+
? bodyRegion(_jsxs(_Fragment, { children: [!state.writable ? _jsx("p", { className: css.readOnly, role: "status", children: props.t('settings.readOnly') }) : null, _jsx(CardApply.Provider, { value: { commit: props.onSave, revert: props.onDiscard }, children: props.children }), props.hideFooter !== true && state.failed
|
|
106
|
+
? (_jsxs("p", { className: css.failed, role: "status", children: [props.t('settings.saveFailed'), state.failedReason ? ' - ' + state.failedReason : ''] }))
|
|
107
|
+
: null] }))
|
|
61
108
|
: null] }));
|
|
62
109
|
}
|
|
63
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* A typed value field. Its draft is written after a pause in typing, at once on
|
|
112
|
+
* Enter or when focus leaves, and Escape puts the stored value back. `numeric`
|
|
113
|
+
* only hints the keypad: which drafts a field accepts is decided by its spec.
|
|
114
|
+
* A field given a `range` also offers the coarse slider bubble: dragging fills
|
|
115
|
+
* the draft live and releasing writes it.
|
|
116
|
+
*/
|
|
64
117
|
export function ValueField(props) {
|
|
118
|
+
const apply = useContext(CardApply);
|
|
119
|
+
const onKeyDown = (event) => {
|
|
120
|
+
if (apply === null || (event.key !== 'Enter' && event.key !== 'Escape'))
|
|
121
|
+
return;
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
if (event.key === 'Enter')
|
|
124
|
+
apply.commit();
|
|
125
|
+
else
|
|
126
|
+
apply.revert();
|
|
127
|
+
event.currentTarget.blur();
|
|
128
|
+
};
|
|
129
|
+
const input = (_jsx("input", { id: props.id, className: props.invalid ? css.inputInvalid : css.input, type: "text", ...props.numeric === true ? { inputMode: 'numeric' } : {}, ...props.invalid ? { 'aria-invalid': true } : {}, value: props.text, placeholder: props.placeholder ?? '', disabled: props.disabled, onChange: (event) => { props.onEdit(event.target.value); }, onKeyDown: onKeyDown, onBlur: () => { apply?.commit(); } }));
|
|
130
|
+
const { range } = props;
|
|
131
|
+
const typed = Number(props.text);
|
|
65
132
|
return (_jsxs("div", { className: css.field, children: [_jsxs("div", { className: css.head, children: [_jsx("label", { className: css.label, htmlFor: props.id, children: props.label }), props.overridden
|
|
66
133
|
? (_jsxs("span", { className: css.badges, children: [_jsx("span", { className: css.badge, children: props.overriddenLabel }), _jsx("button", { type: "button", className: css.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })] }))
|
|
67
|
-
: null] }),
|
|
134
|
+
: null] }), range === undefined
|
|
135
|
+
? input
|
|
136
|
+
: (_jsx(RangeBubble, { min: range.min, max: range.max, step: range.step, value: props.text.trim() === '' || Number.isNaN(typed) ? range.min : typed, label: `${props.label} ${range.min}–${range.max}`, disabled: props.disabled, onInput: (value) => { props.onEdit(String(value)); }, onCommit: (value) => {
|
|
137
|
+
props.onEdit(String(value));
|
|
138
|
+
apply?.commit();
|
|
139
|
+
}, children: input })), _jsx("p", { className: props.invalid ? css.invalid : css.hint, title: props.hintTitle, children: props.invalid ? props.invalidLabel : props.hint })] }));
|
|
68
140
|
}
|
|
69
141
|
const NON_SKIN_BODY_MARKERS = new Set(['dshSkinCenter', 'dshSidebarCollapsed']);
|
|
70
142
|
// 检测使用使用皮肤,用了皮肤退回原生select样式,防止样式冲突。默认外观下使用优化后的select样式。
|
|
@@ -79,8 +151,8 @@ const SELECT_CLOSE_MS = 100;
|
|
|
79
151
|
* renders the legacy native `<select>` untouched, so element-level skin
|
|
80
152
|
* selectors keep working; under the default appearance it renders a
|
|
81
153
|
* self-drawn `role="listbox"` popup whose open/close is transition-animated.
|
|
82
|
-
*
|
|
83
|
-
*
|
|
154
|
+
* Cards reach it through BooleanField/ChoiceField; editors outside a card
|
|
155
|
+
* (the side-card prefs) bind it directly through onEdit.
|
|
84
156
|
* 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
|
|
85
157
|
*/
|
|
86
158
|
export function SelectField(props) {
|
|
@@ -201,19 +273,68 @@ export function SelectField(props) {
|
|
|
201
273
|
? (_jsx("div", { className: popupClass, role: "listbox", ref: popupRef, children: options.map((option, index) => (_jsx("div", { id: `${id}-o${index}`, role: "option", "aria-selected": option.value === value, className: `${css.selectOption}${option.value === value ? ` ${css.selectOptionSelected}` : ''}${index === activeIndex && !closing ? ` ${css.selectOptionActive}` : ''}`, onClick: () => { commit(index); }, children: option.label }, option.value))) }))
|
|
202
274
|
: null] }));
|
|
203
275
|
}
|
|
204
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* A visible segmented group for a small set of mutually exclusive values.
|
|
278
|
+
* Every option stays on screen, so inherit/on/off and short enum fields take
|
|
279
|
+
* one click without opening a popup. The pressed option carries the group's
|
|
280
|
+
* sliding highlight and `aria-pressed`; the group takes the field label as its
|
|
281
|
+
* accessible name.
|
|
282
|
+
*/
|
|
283
|
+
export function SegmentField(props) {
|
|
284
|
+
return (_jsx(SegmentGroup, { id: props.id, role: "group", "aria-label": props.label, "aria-invalid": props.invalid || undefined, children: props.options.map((option, index) => {
|
|
285
|
+
const active = option.value === props.value;
|
|
286
|
+
return (_jsx("button", { type: "button", className: css.segment, "aria-pressed": active, disabled: props.disabled, "data-active": active ? '' : undefined, "data-segment-index": index, onClick: () => {
|
|
287
|
+
if (!active)
|
|
288
|
+
props.onEdit(option.value);
|
|
289
|
+
}, children: option.label }, option.value));
|
|
290
|
+
}) }));
|
|
291
|
+
}
|
|
292
|
+
/** A boolean field: 继承 / 开 / 关. */
|
|
205
293
|
export function BooleanField(props) {
|
|
206
|
-
|
|
294
|
+
const segmented = props.presentation !== 'select';
|
|
295
|
+
return (_jsxs("div", { className: css.field, children: [_jsxs("div", { className: css.head, children: [segmented
|
|
296
|
+
? _jsx("span", { className: css.label, children: props.label })
|
|
297
|
+
: _jsx("label", { className: css.label, htmlFor: props.id, children: props.label }), props.overridden
|
|
207
298
|
? (_jsxs("span", { className: css.badges, children: [_jsx("span", { className: css.badge, children: props.overriddenLabel }), _jsx("button", { type: "button", className: css.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })] }))
|
|
208
|
-
: null] }),
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
299
|
+
: null] }), segmented
|
|
300
|
+
? (_jsx(SegmentField, { id: props.id, label: props.label, options: [
|
|
301
|
+
{ value: '', label: props.inheritLabel },
|
|
302
|
+
{ value: 'true', label: props.onLabel },
|
|
303
|
+
{ value: 'false', label: props.offLabel },
|
|
304
|
+
], value: props.text, disabled: props.disabled, invalid: props.invalid, onEdit: props.onEdit }))
|
|
305
|
+
: (_jsx(SelectField, { id: props.id, options: [
|
|
306
|
+
{ value: '', label: props.inheritLabel },
|
|
307
|
+
{ value: 'true', label: props.onLabel },
|
|
308
|
+
{ value: 'false', label: props.offLabel },
|
|
309
|
+
], value: props.text, disabled: props.disabled, invalid: props.invalid, onEdit: props.onEdit })), _jsx("p", { className: css.hint, title: props.hintTitle, children: props.hint })] }));
|
|
213
310
|
}
|
|
214
|
-
/**
|
|
311
|
+
/** An enumerated field, selecting or segmenting its small choice set. */
|
|
215
312
|
export function ChoiceField(props) {
|
|
216
|
-
|
|
313
|
+
const segmented = props.presentation === 'segment';
|
|
314
|
+
const options = [{ value: '', label: props.inheritLabel }, ...props.choices];
|
|
315
|
+
return (_jsxs("div", { className: css.field, children: [_jsxs("div", { className: css.head, children: [segmented
|
|
316
|
+
? _jsx("span", { className: css.label, children: props.label })
|
|
317
|
+
: _jsx("label", { className: css.label, htmlFor: props.id, children: props.label }), props.overridden
|
|
217
318
|
? (_jsxs("span", { className: css.badges, children: [_jsx("span", { className: css.badge, children: props.overriddenLabel }), _jsx("button", { type: "button", className: css.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })] }))
|
|
218
|
-
: null] }),
|
|
319
|
+
: null] }), segmented
|
|
320
|
+
? (_jsx(SegmentField, { id: props.id, label: props.label, options: options, value: props.text, disabled: props.disabled, invalid: props.invalid, onEdit: props.onEdit }))
|
|
321
|
+
: (_jsx(SelectField, { id: props.id, options: options, value: props.text, disabled: props.disabled, invalid: props.invalid, onEdit: props.onEdit })), _jsx("p", { className: props.invalid ? css.invalid : css.hint, title: props.hintTitle, children: props.invalid ? props.invalidLabel : props.hint })] }));
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* A boolean toggle drawn as a switch track, for a setting that is only on or
|
|
325
|
+
* off and applies on flip. It is a real button with
|
|
326
|
+
* `role="switch"` and `aria-checked`, so keyboard and assistive activation
|
|
327
|
+
* arrive as a click and the state is announced instead of inferred from a
|
|
328
|
+
* checkbox tick.
|
|
329
|
+
*
|
|
330
|
+
* The thumb bounces across only once the reader has pressed this switch: the
|
|
331
|
+
* press writes the mark that arms the bounce, so a page opening, a TAB
|
|
332
|
+
* switching back or a value arriving from elsewhere draws every thumb at rest.
|
|
333
|
+
*/
|
|
334
|
+
export function ToggleSwitch(props) {
|
|
335
|
+
const [moved, setMoved] = useState(false);
|
|
336
|
+
return (_jsx("button", { type: "button", className: css.toggle, role: "switch", "aria-checked": props.checked, "aria-labelledby": props.labelledBy, "aria-label": props.labelledBy === undefined ? props.ariaLabel : undefined, disabled: props.disabled, "data-moved": moved ? '' : undefined, onClick: () => {
|
|
337
|
+
setMoved(true);
|
|
338
|
+
props.onChange(!props.checked);
|
|
339
|
+
}, children: _jsx("span", { className: css.toggleTrack, children: _jsx("span", { className: css.toggleThumb }) }) }));
|
|
219
340
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coarse adjustment for a bounded number: resting the pointer on the control
|
|
3
|
+
* (or moving focus into it) raises a small bubble holding a slider across the
|
|
4
|
+
* field's whole range, so a large change is one drag instead of many presses
|
|
5
|
+
* or a retyped value. The control itself stays the precise entry.
|
|
6
|
+
*
|
|
7
|
+
* The bubble belongs to the anchor's subtree, so moving from the control onto
|
|
8
|
+
* the bubble never counts as leaving. It opens after a short rest and closes a
|
|
9
|
+
* moment after the pointer and focus have both gone, so crossing the control
|
|
10
|
+
* on the way elsewhere does not flash it. While a drag is in progress the
|
|
11
|
+
* bubble stays put even if the pointer strays off it.
|
|
12
|
+
*
|
|
13
|
+
* Dragging reports each value through `onInput`, so the field shows it live;
|
|
14
|
+
* releasing the thumb, or a key press on it, reports `onCommit` once. The
|
|
15
|
+
* bubble opens on the side of the control that has room inside the nearest
|
|
16
|
+
* scrolling ancestor, so a row near the top of a settings page does not hang
|
|
17
|
+
* its bubble under the page edge.
|
|
18
|
+
*/
|
|
19
|
+
import { type ReactNode } from 'react';
|
|
20
|
+
/** Props of {@link RangeBubble}. */
|
|
21
|
+
export interface RangeBubbleProps {
|
|
22
|
+
/** Lowest value the slider reaches. */
|
|
23
|
+
min: number;
|
|
24
|
+
/** Highest value the slider reaches. */
|
|
25
|
+
max: number;
|
|
26
|
+
/** Slider granularity. */
|
|
27
|
+
step: number;
|
|
28
|
+
/** Current value; a value outside the range parks the thumb at the nearer end. */
|
|
29
|
+
value: number;
|
|
30
|
+
/** Accessible name of the slider. */
|
|
31
|
+
label: string;
|
|
32
|
+
/** Disables the bubble along with the control. */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** Each value while the thumb moves. */
|
|
35
|
+
onInput: (value: number) => void;
|
|
36
|
+
/** The value the thumb was released on, once per drag or key press. */
|
|
37
|
+
onCommit: (value: number) => void;
|
|
38
|
+
/** The precise control the bubble hangs off. */
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Render the control with its coarse-adjustment bubble.
|
|
43
|
+
* @param props - the range, the value and the two report callbacks.
|
|
44
|
+
* @returns the anchor holding the control and the bubble.
|
|
45
|
+
*/
|
|
46
|
+
export declare function RangeBubble(props: RangeBubbleProps): ReactNode;
|
|
47
|
+
//# sourceMappingURL=RangeBubble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RangeBubble.d.ts","sourceRoot":"","sources":["../../../src/client/RangeBubble.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAyF,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAU7H,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAA;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAA;IACb,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,kDAAkD;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wCAAwC;IACxC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,uEAAuE;IACvE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,gDAAgD;IAChD,QAAQ,EAAE,SAAS,CAAA;CACpB;AAWD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAiG9D"}
|