@fish-under-sea/dsh-client-ui-task-board-fish 1.0.2 → 2.0.0
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/NOTICE +1 -1
- package/README.en.md +6 -4
- package/README.md +6 -4
- package/README.zh.md +6 -4
- package/icon.png +0 -0
- package/lib/client.js +4428 -1508
- package/lib/client.js.map +1 -1
- package/lib/index.js +2670 -496
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +130 -19
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/ExecutionLog.d.ts +24 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/TaskForm.d.ts +4 -0
- package/lib/types/client/board/VerificationReport.d.ts +2 -15
- package/lib/types/client/board/model-options.d.ts +87 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +87 -9
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/plugin-card-seat.d.ts +3 -1
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/client/settings-form.d.ts +73 -51
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +57 -8
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +116 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/session-reuse.d.ts +7 -1
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +100 -37
- package/lib/types/core/tasks.d.ts +94 -10
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-tag.d.ts +36 -0
- package/lib/types/core/use-cases/task-update.d.ts +22 -1
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/core/workspace-target.d.ts +23 -3
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host/launch-admission.d.ts +71 -0
- package/lib/types/host-ledger.d.ts +114 -47
- package/lib/types/host-routes.d.ts +63 -0
- package/lib/types/host-runner.d.ts +164 -18
- package/lib/types/host-service.d.ts +182 -46
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +173 -54
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +52 -11
- package/lib/types/tool-surface.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +36 -29
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +385 -111
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/TaskBoardSettingsCard.tsx +332 -37
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/ExecutionLog.tsx +154 -0
- package/src/client/board/LinkSubtaskModal.tsx +1 -1
- package/src/client/board/NewTaskModal.tsx +154 -45
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TagManagerModal.tsx +151 -2
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskCard.tsx +45 -23
- package/src/client/board/TaskDetail.tsx +468 -258
- package/src/client/board/TaskForm.tsx +19 -4
- package/src/client/board/VerificationReport.tsx +143 -104
- package/src/client/board/model-options.ts +208 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board/task-markdown.module.css +11 -8
- package/src/client/board-settings.module.css +35 -7
- package/src/client/board.module.css +1044 -105
- package/src/client/body-mutations.ts +133 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +109 -95
- package/src/client/locales.ts +205 -48
- package/src/client/pending-verify.ts +90 -0
- package/src/client/plugin-card-seat.ts +8 -2
- package/src/client/service.ts +24 -0
- package/src/client/settings-card.module.css +466 -89
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/settings-form.ts +102 -60
- package/src/core/attachment.ts +287 -0
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +90 -11
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +120 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +19 -1
- package/src/core/subtask.ts +144 -68
- package/src/core/tasks.ts +117 -10
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-tag.ts +56 -0
- package/src/core/use-cases/task-update.ts +33 -5
- package/src/core/wire-projection.ts +81 -0
- package/src/core/workspace-target.ts +27 -3
- package/src/host/agent-tools.ts +33 -21
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host/launch-admission.ts +139 -0
- package/src/host-ledger.ts +248 -117
- package/src/host-routes.ts +233 -15
- package/src/host-runner.ts +395 -61
- package/src/host-service.ts +512 -139
- package/src/host-spend.ts +105 -0
- package/src/index.ts +312 -92
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +83 -18
- package/src/tool-surface.ts +1 -0
- package/icon.svg +0 -3
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
// 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".
|
|
2
2
|
/**
|
|
3
3
|
* Family-shared chrome for plugin settings cards: a disclosure header naming
|
|
4
|
-
* the plugin and what its settings govern, the controls inside, and the
|
|
5
|
-
* 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
|
|
6
8
|
* deployment that does not compose the owning plugin should show no trace of
|
|
7
9
|
* it. Inlined into each consumer's client bundle; mirrors the official
|
|
8
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).
|
|
9
15
|
*/
|
|
10
16
|
|
|
11
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
|
|
17
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
|
|
12
18
|
import type { CardShell } from './settings-form.ts'
|
|
19
|
+
import { RangeBubble } from './RangeBubble.tsx'
|
|
20
|
+
import { SegmentGroup } from './SegmentGroup.tsx'
|
|
13
21
|
import css from './settings-card.module.css'
|
|
14
22
|
|
|
15
23
|
/** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
|
|
@@ -17,14 +25,17 @@ export const CARD_COPY_KEYS = [
|
|
|
17
25
|
'settings.collapse',
|
|
18
26
|
'settings.expand',
|
|
19
27
|
'settings.notExposed',
|
|
20
|
-
'settings.unsaved',
|
|
21
28
|
'settings.readOnly',
|
|
22
29
|
'settings.saveFailed',
|
|
23
|
-
'settings.discard',
|
|
24
|
-
'settings.save',
|
|
25
|
-
'settings.saving',
|
|
26
30
|
] as const
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* What a text field inside a card reaches without its plugin wiring it: write
|
|
34
|
+
* the pending draft now (Enter, leaving the field) or put it back (Escape).
|
|
35
|
+
* Picks need neither; they are written the moment they are made.
|
|
36
|
+
*/
|
|
37
|
+
const CardApply = createContext<{ commit(): void, revert(): void } | null>(null)
|
|
38
|
+
|
|
28
39
|
/** Copy key the card chrome itself reads. */
|
|
29
40
|
export type CardCopyKey = (typeof CARD_COPY_KEYS)[number]
|
|
30
41
|
|
|
@@ -41,6 +52,14 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
41
52
|
descriptionKey: TKey
|
|
42
53
|
/** Optional rich header description rendered instead of the plain t(descriptionKey) text (the plain text stays as the tooltip). */
|
|
43
54
|
descriptionNode?: ReactNode
|
|
55
|
+
/**
|
|
56
|
+
* Locale key of the full sentence behind a shortened description: when
|
|
57
|
+
* present, the header's native `title` takes this text while the visible
|
|
58
|
+
* line keeps `descriptionKey`/`descriptionNode`, so a compact card can
|
|
59
|
+
* compress the sentence without keeping a second visible copy of it.
|
|
60
|
+
* Defaults to the description key.
|
|
61
|
+
*/
|
|
62
|
+
descriptionTitleKey?: TKey
|
|
44
63
|
/**
|
|
45
64
|
* Optional leading mark identifying the plugin. A card without one keeps the
|
|
46
65
|
* plain official header shape, so the chrome stays a readable sibling of the
|
|
@@ -48,12 +67,25 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
48
67
|
* seat.
|
|
49
68
|
*/
|
|
50
69
|
icon?: ReactNode
|
|
51
|
-
/** The card's form state: availability, writability, and
|
|
70
|
+
/** The card's form state: availability, writability, and how the last write went. */
|
|
52
71
|
state: CardShell
|
|
53
|
-
/** Write every
|
|
72
|
+
/** Write every pending draft now: a text field's Enter or blur. */
|
|
54
73
|
onSave: () => void
|
|
55
|
-
/** Drop every
|
|
74
|
+
/** Drop every pending draft: a text field's Escape. */
|
|
56
75
|
onDiscard: () => void
|
|
76
|
+
/**
|
|
77
|
+
* Id applied to the card's title element, so a header control (an immediate
|
|
78
|
+
* toggle in `headerAction`) can name itself through `aria-labelledby`
|
|
79
|
+
* instead of repeating the title as a string.
|
|
80
|
+
*/
|
|
81
|
+
titleId?: string
|
|
82
|
+
/**
|
|
83
|
+
* Render the header only, with no body region. A card whose whole setting is
|
|
84
|
+
* the header control (a switch whose explanation is the description) has no
|
|
85
|
+
* controls to lay out below it, and an empty body would draw a divider line
|
|
86
|
+
* with nothing under it.
|
|
87
|
+
*/
|
|
88
|
+
headerOnly?: boolean
|
|
57
89
|
/**
|
|
58
90
|
* Render the controls expanded on arrival (still collapsible). Defaults to
|
|
59
91
|
* true: promoted first-level sections show their settings immediately.
|
|
@@ -66,19 +98,47 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
66
98
|
*/
|
|
67
99
|
alwaysOpen?: boolean
|
|
68
100
|
/**
|
|
69
|
-
* Hide the
|
|
70
|
-
*
|
|
71
|
-
*
|
|
101
|
+
* Hide the line under the body that reports a refused write: a card whose
|
|
102
|
+
* body applies its own changes (an embedded external settings section)
|
|
103
|
+
* reports its own failures.
|
|
72
104
|
*/
|
|
73
105
|
hideFooter?: boolean
|
|
74
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Optional control rendered at the header's trailing edge, before the
|
|
108
|
+
* chevron. A card whose setting is one immediate flip (it
|
|
109
|
+
* applies outside the card's form) puts its ToggleSwitch here, so the control
|
|
110
|
+
* is reachable without opening the card and matches a plugin card's shape.
|
|
111
|
+
*/
|
|
112
|
+
headerAction?: ReactNode
|
|
113
|
+
/**
|
|
114
|
+
* Render children even when the settings namespace is not exposed by the
|
|
115
|
+
* host. The 'not exposed' notice still explains the card above them; a card
|
|
116
|
+
* that wants the rows alone hides it through `hideNotExposedNotice`.
|
|
117
|
+
*/
|
|
75
118
|
renderChildrenWhenNotExposed?: boolean
|
|
76
|
-
/** Hide the 'not exposed'
|
|
119
|
+
/** Hide the 'not exposed' notice, whichever branch renders the card body. */
|
|
77
120
|
hideNotExposedNotice?: boolean
|
|
121
|
+
/**
|
|
122
|
+
* Compact chrome for a topic card rendered inside another card's body: a
|
|
123
|
+
* smaller title, a tighter header and body inset, and a one-line description
|
|
124
|
+
* whose full text stays on the header's own title. Defaults to the
|
|
125
|
+
* first-level chrome, which is unchanged.
|
|
126
|
+
*/
|
|
127
|
+
density?: 'nested'
|
|
78
128
|
/** The plugin's controls. */
|
|
79
129
|
children: ReactNode
|
|
80
130
|
}
|
|
81
131
|
|
|
132
|
+
/** Length of the body's disclosure motion; it matches `--settings-card-motion` on the card root. */
|
|
133
|
+
const BODY_MOTION_MS = 180
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Lifecycle of one card body. `collapsed` is the mounted-but-closed frame the
|
|
137
|
+
* enter leg starts from, `entering` and `closing` are the two moving legs, and
|
|
138
|
+
* `shown` is the settled open body, which releases its clipping box.
|
|
139
|
+
*/
|
|
140
|
+
type BodyPhase = 'hidden' | 'collapsed' | 'entering' | 'shown' | 'closing'
|
|
141
|
+
|
|
82
142
|
/**
|
|
83
143
|
* Render one plugin settings card.
|
|
84
144
|
* @param props - the plugin's copy keys, its form state, and its controls.
|
|
@@ -87,12 +147,46 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
87
147
|
export function PluginSettingsCard<TKey extends string = string>(props: PluginSettingsCardProps<TKey>) {
|
|
88
148
|
const [open, setOpen] = useState(props.defaultOpen ?? true)
|
|
89
149
|
const { state, alwaysOpen } = props
|
|
150
|
+
const expanded = alwaysOpen === true || open
|
|
151
|
+
const [bodyPhase, setBodyPhase] = useState<BodyPhase>(expanded ? 'shown' : 'hidden')
|
|
152
|
+
const bodyRef = useRef<HTMLDivElement | null>(null)
|
|
153
|
+
// Enter and leave run the same pair: a body that should open is mounted
|
|
154
|
+
// closed for one frame so its transition has a state to leave, and a closing
|
|
155
|
+
// one stays mounted until its leg has run.
|
|
156
|
+
useLayoutEffect(() => {
|
|
157
|
+
if (expanded) {
|
|
158
|
+
if (bodyPhase === 'hidden') setBodyPhase('collapsed')
|
|
159
|
+
else if (bodyPhase === 'collapsed') {
|
|
160
|
+
const node = bodyRef.current
|
|
161
|
+
if (node !== null) void node.offsetHeight
|
|
162
|
+
setBodyPhase('entering')
|
|
163
|
+
} else if (bodyPhase === 'closing') setBodyPhase('entering')
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
if (bodyPhase === 'collapsed') setBodyPhase('hidden')
|
|
167
|
+
else if (bodyPhase === 'entering' || bodyPhase === 'shown') setBodyPhase('closing')
|
|
168
|
+
}, [expanded, bodyPhase])
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (bodyPhase !== 'entering' && bodyPhase !== 'closing') return
|
|
171
|
+
const timer = setTimeout(() => {
|
|
172
|
+
setBodyPhase(bodyPhase === 'entering' ? 'shown' : 'hidden')
|
|
173
|
+
}, BODY_MOTION_MS)
|
|
174
|
+
return () => { clearTimeout(timer) }
|
|
175
|
+
}, [bodyPhase])
|
|
90
176
|
if (!state.available) return null
|
|
91
177
|
const title = props.t(props.titleKey)
|
|
92
178
|
const description = props.t(props.descriptionKey)
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const cardClass =
|
|
179
|
+
const descriptionTitle = props.descriptionTitleKey === undefined ? description : props.t(props.descriptionTitleKey)
|
|
180
|
+
const baseClass = expanded ? `${css.cardOpen} ${css.card}` : css.card
|
|
181
|
+
const cardClass = props.density === 'nested' ? `${baseClass} ${css.cardNested}` : baseClass
|
|
182
|
+
/** The body region both legs share; a hidden phase renders nothing at all. */
|
|
183
|
+
const bodyRegion = (content: ReactNode) => bodyPhase === 'hidden'
|
|
184
|
+
? null
|
|
185
|
+
: (
|
|
186
|
+
<div className={css.disclosure} data-state={bodyPhase} ref={bodyRef}>
|
|
187
|
+
<div className={css.body}>{content}</div>
|
|
188
|
+
</div>
|
|
189
|
+
)
|
|
96
190
|
// With alwaysOpen the nav entry already provides the selection, so the
|
|
97
191
|
// header is a static title row instead of a disclosure button.
|
|
98
192
|
const header = alwaysOpen === true
|
|
@@ -100,10 +194,10 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
100
194
|
<div className={css.headerStatic}>
|
|
101
195
|
{props.icon !== undefined ? <span className={css.mark} aria-hidden="true">{props.icon}</span> : null}
|
|
102
196
|
<span className={css.headText}>
|
|
103
|
-
<span className={css.name} title={title}>{title}</span>
|
|
104
|
-
<span className={css.description} title={
|
|
197
|
+
<span className={css.name} id={props.titleId} title={title}>{title}</span>
|
|
198
|
+
<span className={css.description} title={descriptionTitle}>{props.descriptionNode ?? description}</span>
|
|
105
199
|
</span>
|
|
106
|
-
{
|
|
200
|
+
{props.headerAction !== undefined ? <span className={css.headerAction}>{props.headerAction}</span> : null}
|
|
107
201
|
</div>
|
|
108
202
|
)
|
|
109
203
|
: (
|
|
@@ -116,10 +210,10 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
116
210
|
>
|
|
117
211
|
{props.icon !== undefined ? <span className={css.mark} aria-hidden="true">{props.icon}</span> : null}
|
|
118
212
|
<span className={css.headText}>
|
|
119
|
-
<span className={css.name} title={title}>{title}</span>
|
|
120
|
-
<span className={css.description} title={
|
|
213
|
+
<span className={css.name} id={props.titleId} title={title}>{title}</span>
|
|
214
|
+
<span className={css.description} title={descriptionTitle}>{props.descriptionNode ?? description}</span>
|
|
121
215
|
</span>
|
|
122
|
-
{
|
|
216
|
+
{props.headerAction !== undefined ? <span className={css.headerAction}>{props.headerAction}</span> : null}
|
|
123
217
|
<svg
|
|
124
218
|
width="14"
|
|
125
219
|
height="14"
|
|
@@ -138,60 +232,41 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
138
232
|
// The namespace exists but the Host does not serve it to this client (the
|
|
139
233
|
// official settings allowlist omits third-party namespaces): show a card
|
|
140
234
|
// that explains the gap instead of vanishing, so a missing card never
|
|
141
|
-
// reads as a missing plugin.
|
|
235
|
+
// reads as a missing plugin. A card that keeps its rows anyway keeps the
|
|
236
|
+
// same explanation above them, unless it hides the notice outright.
|
|
237
|
+
const notExposedNotice = state.exposed || props.hideNotExposedNotice === true
|
|
238
|
+
? null
|
|
239
|
+
: <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p>
|
|
142
240
|
if (!state.exposed && props.renderChildrenWhenNotExposed !== true) {
|
|
143
|
-
const showNotice = props.hideNotExposedNotice !== true
|
|
144
241
|
return (
|
|
145
242
|
<li className={cardClass}>
|
|
146
243
|
{header}
|
|
147
|
-
{
|
|
148
|
-
? (
|
|
149
|
-
<div className={css.body}>
|
|
150
|
-
{showNotice ? <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p> : null}
|
|
151
|
-
</div>
|
|
152
|
-
)
|
|
153
|
-
: null}
|
|
244
|
+
{bodyRegion(notExposedNotice)}
|
|
154
245
|
</li>
|
|
155
246
|
)
|
|
156
247
|
}
|
|
248
|
+
// A header-only card has no body region at all: the divider would otherwise
|
|
249
|
+
// sit above an empty box.
|
|
250
|
+
const bodyVisible = props.headerOnly !== true
|
|
157
251
|
return (
|
|
158
252
|
<li className={cardClass}>
|
|
159
253
|
{header}
|
|
160
|
-
{
|
|
161
|
-
? (
|
|
162
|
-
|
|
254
|
+
{bodyVisible
|
|
255
|
+
? bodyRegion(
|
|
256
|
+
<>
|
|
257
|
+
{notExposedNotice}
|
|
163
258
|
{!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
|
|
164
|
-
{props.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
: null}
|
|
176
|
-
<button
|
|
177
|
-
type="button"
|
|
178
|
-
className={css.discard}
|
|
179
|
-
disabled={!state.dirty || state.saving}
|
|
180
|
-
onClick={props.onDiscard}
|
|
181
|
-
>
|
|
182
|
-
{props.t('settings.discard')}
|
|
183
|
-
</button>
|
|
184
|
-
<button
|
|
185
|
-
type="button"
|
|
186
|
-
className={css.save}
|
|
187
|
-
disabled={blocked}
|
|
188
|
-
onClick={props.onSave}
|
|
189
|
-
>
|
|
190
|
-
{props.t(!state.saving ? 'settings.save' : 'settings.saving')}
|
|
191
|
-
</button>
|
|
192
|
-
</div>
|
|
193
|
-
)}
|
|
194
|
-
</div>
|
|
259
|
+
<CardApply.Provider value={{ commit: props.onSave, revert: props.onDiscard }}>
|
|
260
|
+
{props.children}
|
|
261
|
+
</CardApply.Provider>
|
|
262
|
+
{props.hideFooter !== true && state.failed
|
|
263
|
+
? (
|
|
264
|
+
<p className={css.failed} role="status">
|
|
265
|
+
{props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}
|
|
266
|
+
</p>
|
|
267
|
+
)
|
|
268
|
+
: null}
|
|
269
|
+
</>,
|
|
195
270
|
)
|
|
196
271
|
: null}
|
|
197
272
|
</li>
|
|
@@ -206,9 +281,15 @@ export interface FieldProps {
|
|
|
206
281
|
label: string
|
|
207
282
|
/** One-line explanation rendered under the control. */
|
|
208
283
|
hint: string
|
|
284
|
+
/**
|
|
285
|
+
* Full sentence behind the visible hint, exposed as the paragraph's native
|
|
286
|
+
* `title` so a card can shorten the line without losing the text. Omitted:
|
|
287
|
+
* the paragraph carries no title attribute at all.
|
|
288
|
+
*/
|
|
289
|
+
hintTitle?: string
|
|
209
290
|
/** Draft text this control renders. */
|
|
210
291
|
text: string
|
|
211
|
-
/** True when
|
|
292
|
+
/** True when the field holds a user-layer entry over the inherited value. */
|
|
212
293
|
overridden: boolean
|
|
213
294
|
/** True when the draft is not a value this field accepts. */
|
|
214
295
|
invalid: boolean
|
|
@@ -220,19 +301,65 @@ export interface FieldProps {
|
|
|
220
301
|
invalidLabel: string
|
|
221
302
|
/** Disables every control (read-only document, or an unavailable namespace). */
|
|
222
303
|
disabled: boolean
|
|
223
|
-
/**
|
|
304
|
+
/** Take new draft text; the card writes it as the field's entry rule says. */
|
|
224
305
|
onEdit: (text: string) => void
|
|
225
|
-
/**
|
|
306
|
+
/** Clear the field at once so it re-inherits the composition layer. */
|
|
226
307
|
onReset: () => void
|
|
227
308
|
}
|
|
228
309
|
|
|
229
|
-
/**
|
|
310
|
+
/**
|
|
311
|
+
* A typed value field. Its draft is written after a pause in typing, at once on
|
|
312
|
+
* Enter or when focus leaves, and Escape puts the stored value back. `numeric`
|
|
313
|
+
* only hints the keypad: which drafts a field accepts is decided by its spec.
|
|
314
|
+
* A field given a `range` also offers the coarse slider bubble: dragging fills
|
|
315
|
+
* the draft live and releasing writes it.
|
|
316
|
+
*/
|
|
230
317
|
export function ValueField(props: FieldProps & {
|
|
231
318
|
/** Hints a numeric keypad without narrowing what the control accepts. */
|
|
232
319
|
numeric?: boolean
|
|
233
320
|
/** Placeholder shown while the draft is empty. */
|
|
234
321
|
placeholder?: string
|
|
322
|
+
/** Bounds of a numeric field, for the coarse slider; the spec still judges every draft. */
|
|
323
|
+
range?: { min: number, max: number, step: number }
|
|
235
324
|
}) {
|
|
325
|
+
const apply = useContext(CardApply)
|
|
326
|
+
// Enter and Escape settle the draft themselves and then leave the field, so
|
|
327
|
+
// the blur they cause is that same settlement reaching the field's edge, not
|
|
328
|
+
// a second write. Without this an Escape reported a discard and then a save,
|
|
329
|
+
// which reads to a consumer as a write still waiting to happen.
|
|
330
|
+
const settledByKey = useRef(false)
|
|
331
|
+
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
332
|
+
if (apply === null || (event.key !== 'Enter' && event.key !== 'Escape')) return
|
|
333
|
+
event.preventDefault()
|
|
334
|
+
settledByKey.current = true
|
|
335
|
+
if (event.key === 'Enter') apply.commit()
|
|
336
|
+
else apply.revert()
|
|
337
|
+
event.currentTarget.blur()
|
|
338
|
+
}
|
|
339
|
+
const input = (
|
|
340
|
+
<input
|
|
341
|
+
id={props.id}
|
|
342
|
+
className={props.invalid ? css.inputInvalid : css.input}
|
|
343
|
+
type="text"
|
|
344
|
+
{...props.numeric === true ? { inputMode: 'numeric' as const } : {}}
|
|
345
|
+
{...props.invalid ? { 'aria-invalid': true } : {}}
|
|
346
|
+
value={props.text}
|
|
347
|
+
placeholder={props.placeholder ?? ''}
|
|
348
|
+
disabled={props.disabled}
|
|
349
|
+
onChange={(event) => { props.onEdit(event.target.value) }}
|
|
350
|
+
onKeyDown={onKeyDown}
|
|
351
|
+
onFocus={() => { settledByKey.current = false }}
|
|
352
|
+
onBlur={() => {
|
|
353
|
+
if (settledByKey.current) {
|
|
354
|
+
settledByKey.current = false
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
apply?.commit()
|
|
358
|
+
}}
|
|
359
|
+
/>
|
|
360
|
+
)
|
|
361
|
+
const { range } = props
|
|
362
|
+
const typed = Number(props.text)
|
|
236
363
|
return (
|
|
237
364
|
<div className={css.field}>
|
|
238
365
|
<div className={css.head}>
|
|
@@ -253,18 +380,26 @@ export function ValueField(props: FieldProps & {
|
|
|
253
380
|
)
|
|
254
381
|
: null}
|
|
255
382
|
</div>
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
383
|
+
{range === undefined
|
|
384
|
+
? input
|
|
385
|
+
: (
|
|
386
|
+
<RangeBubble
|
|
387
|
+
min={range.min}
|
|
388
|
+
max={range.max}
|
|
389
|
+
step={range.step}
|
|
390
|
+
value={props.text.trim() === '' || Number.isNaN(typed) ? range.min : typed}
|
|
391
|
+
label={`${props.label} ${range.min}–${range.max}`}
|
|
392
|
+
disabled={props.disabled}
|
|
393
|
+
onInput={(value) => { props.onEdit(String(value)) }}
|
|
394
|
+
onCommit={(value) => {
|
|
395
|
+
props.onEdit(String(value))
|
|
396
|
+
apply?.commit()
|
|
397
|
+
}}
|
|
398
|
+
>
|
|
399
|
+
{input}
|
|
400
|
+
</RangeBubble>
|
|
401
|
+
)}
|
|
402
|
+
<p className={props.invalid ? css.invalid : css.hint} title={props.hintTitle}>
|
|
268
403
|
{props.invalid ? props.invalidLabel : props.hint}
|
|
269
404
|
</p>
|
|
270
405
|
</div>
|
|
@@ -291,8 +426,8 @@ const SELECT_CLOSE_MS = 100
|
|
|
291
426
|
* renders the legacy native `<select>` untouched, so element-level skin
|
|
292
427
|
* selectors keep working; under the default appearance it renders a
|
|
293
428
|
* self-drawn `role="listbox"` popup whose open/close is transition-animated.
|
|
294
|
-
*
|
|
295
|
-
*
|
|
429
|
+
* Cards reach it through BooleanField/ChoiceField; editors outside a card
|
|
430
|
+
* (the side-card prefs) bind it directly through onEdit.
|
|
296
431
|
* 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
|
|
297
432
|
*/
|
|
298
433
|
export function SelectField(props: {
|
|
@@ -475,7 +610,56 @@ export function SelectField(props: {
|
|
|
475
610
|
)
|
|
476
611
|
}
|
|
477
612
|
|
|
478
|
-
/**
|
|
613
|
+
/**
|
|
614
|
+
* A visible segmented group for a small set of mutually exclusive values.
|
|
615
|
+
* Every option stays on screen, so inherit/on/off and short enum fields take
|
|
616
|
+
* one click without opening a popup. The pressed option carries the group's
|
|
617
|
+
* sliding highlight and `aria-pressed`; the group takes the field label as its
|
|
618
|
+
* accessible name.
|
|
619
|
+
*/
|
|
620
|
+
export function SegmentField(props: {
|
|
621
|
+
id: string
|
|
622
|
+
label: string
|
|
623
|
+
options: ReadonlyArray<SelectOption>
|
|
624
|
+
value: string
|
|
625
|
+
disabled: boolean
|
|
626
|
+
invalid: boolean
|
|
627
|
+
onEdit: (text: string) => void
|
|
628
|
+
}) {
|
|
629
|
+
return (
|
|
630
|
+
<SegmentGroup
|
|
631
|
+
id={props.id}
|
|
632
|
+
role="group"
|
|
633
|
+
aria-label={props.label}
|
|
634
|
+
aria-invalid={props.invalid || undefined}
|
|
635
|
+
>
|
|
636
|
+
{props.options.map((option, index) => {
|
|
637
|
+
const active = option.value === props.value
|
|
638
|
+
return (
|
|
639
|
+
<button
|
|
640
|
+
key={option.value}
|
|
641
|
+
type="button"
|
|
642
|
+
className={css.segment}
|
|
643
|
+
aria-pressed={active}
|
|
644
|
+
disabled={props.disabled}
|
|
645
|
+
data-active={active ? '' : undefined}
|
|
646
|
+
data-segment-index={index}
|
|
647
|
+
onClick={() => {
|
|
648
|
+
if (!active) props.onEdit(option.value)
|
|
649
|
+
}}
|
|
650
|
+
>
|
|
651
|
+
{option.label}
|
|
652
|
+
</button>
|
|
653
|
+
)
|
|
654
|
+
})}
|
|
655
|
+
</SegmentGroup>
|
|
656
|
+
)
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** How a small single-choice field presents its options. */
|
|
660
|
+
export type FieldPresentation = 'select' | 'segment'
|
|
661
|
+
|
|
662
|
+
/** A boolean field: 继承 / 开 / 关. */
|
|
479
663
|
export function BooleanField(props: FieldProps & {
|
|
480
664
|
/** Copy for the inherit option. */
|
|
481
665
|
inheritLabel: string
|
|
@@ -483,11 +667,16 @@ export function BooleanField(props: FieldProps & {
|
|
|
483
667
|
onLabel: string
|
|
484
668
|
/** Copy for the off option. */
|
|
485
669
|
offLabel: string
|
|
670
|
+
/** Defaults to the visible segments: the three answers always fit on one row. */
|
|
671
|
+
presentation?: FieldPresentation
|
|
486
672
|
}) {
|
|
673
|
+
const segmented = props.presentation !== 'select'
|
|
487
674
|
return (
|
|
488
675
|
<div className={css.field}>
|
|
489
676
|
<div className={css.head}>
|
|
490
|
-
|
|
677
|
+
{segmented
|
|
678
|
+
? <span className={css.label}>{props.label}</span>
|
|
679
|
+
: <label className={css.label} htmlFor={props.id}>{props.label}</label>}
|
|
491
680
|
{props.overridden
|
|
492
681
|
? (
|
|
493
682
|
<span className={css.badges}>
|
|
@@ -504,34 +693,61 @@ export function BooleanField(props: FieldProps & {
|
|
|
504
693
|
)
|
|
505
694
|
: null}
|
|
506
695
|
</div>
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
696
|
+
{segmented
|
|
697
|
+
? (
|
|
698
|
+
<SegmentField
|
|
699
|
+
id={props.id}
|
|
700
|
+
label={props.label}
|
|
701
|
+
options={[
|
|
702
|
+
{ value: '', label: props.inheritLabel },
|
|
703
|
+
{ value: 'true', label: props.onLabel },
|
|
704
|
+
{ value: 'false', label: props.offLabel },
|
|
705
|
+
]}
|
|
706
|
+
value={props.text}
|
|
707
|
+
disabled={props.disabled}
|
|
708
|
+
invalid={props.invalid}
|
|
709
|
+
onEdit={props.onEdit}
|
|
710
|
+
/>
|
|
711
|
+
)
|
|
712
|
+
: (
|
|
713
|
+
<SelectField
|
|
714
|
+
id={props.id}
|
|
715
|
+
options={[
|
|
716
|
+
{ value: '', label: props.inheritLabel },
|
|
717
|
+
{ value: 'true', label: props.onLabel },
|
|
718
|
+
{ value: 'false', label: props.offLabel },
|
|
719
|
+
]}
|
|
720
|
+
value={props.text}
|
|
721
|
+
disabled={props.disabled}
|
|
722
|
+
invalid={props.invalid}
|
|
723
|
+
onEdit={props.onEdit}
|
|
724
|
+
/>
|
|
725
|
+
)}
|
|
726
|
+
<p className={css.hint} title={props.hintTitle}>{props.hint}</p>
|
|
520
727
|
</div>
|
|
521
728
|
)
|
|
522
729
|
}
|
|
523
730
|
|
|
524
|
-
/**
|
|
731
|
+
/** An enumerated field, selecting or segmenting its small choice set. */
|
|
525
732
|
export function ChoiceField(props: FieldProps & {
|
|
526
733
|
/** Copy for the inherit option (draft text is the empty string). */
|
|
527
734
|
inheritLabel: string
|
|
528
735
|
/** Choices rendered in order; `value` is the draft/stored text. */
|
|
529
736
|
choices: ReadonlyArray<{ value: string; label: string }>
|
|
737
|
+
/**
|
|
738
|
+
* Visible segmented options for a short fixed set; defaults to the compact
|
|
739
|
+
* select, which also suits a list whose length follows the deployment.
|
|
740
|
+
*/
|
|
741
|
+
presentation?: FieldPresentation
|
|
530
742
|
}) {
|
|
743
|
+
const segmented = props.presentation === 'segment'
|
|
744
|
+
const options = [{ value: '', label: props.inheritLabel }, ...props.choices]
|
|
531
745
|
return (
|
|
532
746
|
<div className={css.field}>
|
|
533
747
|
<div className={css.head}>
|
|
534
|
-
|
|
748
|
+
{segmented
|
|
749
|
+
? <span className={css.label}>{props.label}</span>
|
|
750
|
+
: <label className={css.label} htmlFor={props.id}>{props.label}</label>}
|
|
535
751
|
{props.overridden
|
|
536
752
|
? (
|
|
537
753
|
<span className={css.badges}>
|
|
@@ -548,17 +764,75 @@ export function ChoiceField(props: FieldProps & {
|
|
|
548
764
|
)
|
|
549
765
|
: null}
|
|
550
766
|
</div>
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
767
|
+
{segmented
|
|
768
|
+
? (
|
|
769
|
+
<SegmentField
|
|
770
|
+
id={props.id}
|
|
771
|
+
label={props.label}
|
|
772
|
+
options={options}
|
|
773
|
+
value={props.text}
|
|
774
|
+
disabled={props.disabled}
|
|
775
|
+
invalid={props.invalid}
|
|
776
|
+
onEdit={props.onEdit}
|
|
777
|
+
/>
|
|
778
|
+
)
|
|
779
|
+
: (
|
|
780
|
+
<SelectField
|
|
781
|
+
id={props.id}
|
|
782
|
+
options={options}
|
|
783
|
+
value={props.text}
|
|
784
|
+
disabled={props.disabled}
|
|
785
|
+
invalid={props.invalid}
|
|
786
|
+
onEdit={props.onEdit}
|
|
787
|
+
/>
|
|
788
|
+
)}
|
|
789
|
+
<p className={props.invalid ? css.invalid : css.hint} title={props.hintTitle}>
|
|
560
790
|
{props.invalid ? props.invalidLabel : props.hint}
|
|
561
791
|
</p>
|
|
562
792
|
</div>
|
|
563
793
|
)
|
|
564
794
|
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* A boolean toggle drawn as a switch track, for a setting that is only on or
|
|
798
|
+
* off and applies on flip. It is a real button with
|
|
799
|
+
* `role="switch"` and `aria-checked`, so keyboard and assistive activation
|
|
800
|
+
* arrive as a click and the state is announced instead of inferred from a
|
|
801
|
+
* checkbox tick.
|
|
802
|
+
*
|
|
803
|
+
* The thumb bounces across only once the reader has pressed this switch: the
|
|
804
|
+
* press writes the mark that arms the bounce, so a page opening, a TAB
|
|
805
|
+
* switching back or a value arriving from elsewhere draws every thumb at rest.
|
|
806
|
+
*/
|
|
807
|
+
export function ToggleSwitch(props: {
|
|
808
|
+
/** Id of the element naming the switch (the card's title). */
|
|
809
|
+
labelledBy?: string
|
|
810
|
+
/** Accessible name when no element labels it. */
|
|
811
|
+
ariaLabel?: string
|
|
812
|
+
/** Current state. */
|
|
813
|
+
checked: boolean
|
|
814
|
+
/** Disables the switch while a write is in flight or the Host refuses writes. */
|
|
815
|
+
disabled?: boolean
|
|
816
|
+
/** Called with the requested next state. */
|
|
817
|
+
onChange: (next: boolean) => void
|
|
818
|
+
}) {
|
|
819
|
+
const [moved, setMoved] = useState(false)
|
|
820
|
+
return (
|
|
821
|
+
<button
|
|
822
|
+
type="button"
|
|
823
|
+
className={css.toggle}
|
|
824
|
+
role="switch"
|
|
825
|
+
aria-checked={props.checked}
|
|
826
|
+
aria-labelledby={props.labelledBy}
|
|
827
|
+
aria-label={props.labelledBy === undefined ? props.ariaLabel : undefined}
|
|
828
|
+
disabled={props.disabled}
|
|
829
|
+
data-moved={moved ? '' : undefined}
|
|
830
|
+
onClick={() => {
|
|
831
|
+
setMoved(true)
|
|
832
|
+
props.onChange(!props.checked)
|
|
833
|
+
}}
|
|
834
|
+
>
|
|
835
|
+
<span className={css.toggleTrack}><span className={css.toggleThumb} /></span>
|
|
836
|
+
</button>
|
|
837
|
+
)
|
|
838
|
+
}
|