dsh-better-ask-user 0.3.1 → 0.3.2

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.
@@ -64,20 +64,7 @@ function parseDraft(draft: Draft): ConfigValue | undefined {
64
64
  return { questionTimeoutSeconds: seconds, timeoutBehavior: draft.timeoutBehavior, goalTimeoutBehavior: draft.goalTimeoutBehavior }
65
65
  }
66
66
 
67
- /** Compact settings row with an optional dependency description. */
68
- function Row({ id, label, hint, children }: { id: string; label: string; hint?: string; children: ReactNode }) {
69
- return (
70
- <div className={css.row}>
71
- <div className={css.rowText}>
72
- <span className={css.rowTitle} id={`${id}-label`}>{label}</span>
73
- {hint ? <span className={css.rowDesc} id={`${id}-hint`}>{hint}</span> : null}
74
- </div>
75
- <div className={css.control}>{children}</div>
76
- </div>
77
- )
78
- }
79
-
80
- /** Native radio semantics with one compact, fully styled choice surface. */
67
+ /** Native radio semantics with one compact segmented surface. */
81
68
  function Choices({ id, value, options, disabled, describedBy, onChange }: {
82
69
  id: string
83
70
  value: string
@@ -105,6 +92,70 @@ function Choices({ id, value, options, disabled, describedBy, onChange }: {
105
92
  )
106
93
  }
107
94
 
95
+ /** Radio-backed choice cards with a small diagram per consequence. */
96
+ function ChoiceCards({ id, value, options, disabled, describedBy, onChange }: {
97
+ id: string
98
+ value: string
99
+ options: Array<{ value: string; label: string; description: string; diagram: ReactNode }>
100
+ disabled: boolean
101
+ describedBy?: string
102
+ onChange: (value: string) => void
103
+ }) {
104
+ const name = useId()
105
+ return (
106
+ <div className={css.cards} id={id} role="radiogroup" aria-labelledby={`${id}-label`} aria-describedby={describedBy} aria-disabled={disabled}>
107
+ {options.map((option) => (
108
+ <label className={css.card} key={option.value} data-choice={option.value}>
109
+ <input
110
+ id={`${id}-${option.value}`}
111
+ className={css.cardInput}
112
+ type="radio" name={name} value={option.value}
113
+ checked={value === option.value} disabled={disabled}
114
+ aria-describedby={`${id}-${option.value}-desc`}
115
+ onChange={() => { onChange(option.value) }}
116
+ />
117
+ <span className={css.cardHead}>
118
+ <span className={css.cardName}>{option.label}</span>
119
+ <span className={css.cardMark} aria-hidden="true" />
120
+ </span>
121
+ <span className={css.cardDesc} id={`${id}-${option.value}-desc`}>{option.description}</span>
122
+ <span className={css.cardDiagram} aria-hidden="true">{option.diagram}</span>
123
+ </label>
124
+ ))}
125
+ </div>
126
+ )
127
+ }
128
+
129
+ /** Question goes out, wait, then the timeout keeps it open and answerable. */
130
+ function OpenFlow() {
131
+ return (
132
+ <svg viewBox="0 0 104 24" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden="true">
133
+ <rect x="1" y="5" width="24" height="14" rx="3" />
134
+ <path d="M7 10h12M7 14h7" strokeWidth="1" />
135
+ <path d="M27 12h14" />
136
+ <circle cx="47" cy="12" r="4" />
137
+ <path d="M51 12h14" />
138
+ <path d="m61 8 4 4-4 4" />
139
+ <path d="M71 7v10M78 7v10M85 7v10" strokeWidth="1" />
140
+ </svg>
141
+ )
142
+ }
143
+
144
+ /** Question goes out, wait, then the default answer is selected automatically. */
145
+ function DefaultFlow() {
146
+ return (
147
+ <svg viewBox="0 0 104 24" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden="true">
148
+ <rect x="1" y="5" width="24" height="14" rx="3" />
149
+ <path d="M7 10h12M7 14h7" strokeWidth="1" />
150
+ <path d="M27 12h16" />
151
+ <circle cx="49" cy="12" r="4" />
152
+ <path d="M53 12h16" />
153
+ <circle cx="78" cy="12" r="7" />
154
+ <path d="m75 12 2 2 4-4" />
155
+ </svg>
156
+ )
157
+ }
158
+
108
159
  /** Page body, rendered inside the settings host's row config page. */
109
160
  export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: SettingsKey) => string }) {
110
161
  const state = form?.state
@@ -170,66 +221,92 @@ export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: Se
170
221
  const invalid = parsed === undefined
171
222
  const unlimited = live.questionTimeoutSeconds === '-1'
172
223
  const controlsDisabled = !writable || busy
173
- const behaviors = [{ value: 'native', label: t('native') }, { value: 'default', label: t('default') }]
224
+ const seconds = parsed?.questionTimeoutSeconds
225
+ const waitAmount = unlimited ? '∞' : seconds === undefined ? '—' : `${t('timelineWait')} ${seconds} ${t('seconds')}`
226
+ const presets = [
227
+ { seconds: 30, label: `30${t('secondShort')}` },
228
+ { seconds: 120, label: `2${t('minuteShort')}` },
229
+ { seconds: 300, label: `5${t('minuteShort')}` },
230
+ { seconds: 600, label: `10${t('minuteShort')}` },
231
+ ]
232
+ const behaviorCards = [
233
+ { value: 'native', label: t('native'), description: t('nativeHint'), diagram: <OpenFlow /> },
234
+ { value: 'default', label: t('default'), description: t('defaultHint'), diagram: <DefaultFlow /> },
235
+ ]
174
236
 
175
237
  return (
176
238
  <div className={css.cfg} aria-busy={busy} data-settings-dirty={dirty} data-settings-busy={busy}>
177
- <div className={css.pageHead}>
239
+ <header className={css.pageHead}>
178
240
  <h2 className={css.title} id="better-ask-user-title">{t('title')}</h2>
241
+ <p className={css.purpose}>{t('purpose')}</p>
179
242
  {writable ? null : <span className={css.badge} role="status">{t('readonly')}</span>}
180
- </div>
243
+ </header>
181
244
  <section className={css.group} aria-label={t('title')}>
182
- <Row id="better-ask-user-wait-mode" label={t('waitLabel')}>
183
- <Choices
184
- id="better-ask-user-wait-mode" value={unlimited ? 'unlimited' : 'timed'}
185
- options={[{ value: 'timed', label: t('timed') }, { value: 'unlimited', label: t('unlimited') }]}
186
- disabled={controlsDisabled} describedBy="better-ask-user-wait-hint"
187
- onChange={(value) => {
188
- const nextUnlimited = value === 'unlimited'
189
- if (nextUnlimited && !invalid) setTimedSeconds(live.questionTimeoutSeconds)
190
- edit(current => ({ ...current, questionTimeoutSeconds: nextUnlimited ? '-1' : timedSeconds }))
191
- }}
192
- />
193
- {unlimited ? null : <span className={css.duration}>
194
- <input
195
- id="better-ask-user-wait" className={css.input}
196
- aria-label={t('durationLabel')}
197
- aria-describedby={invalid ? 'better-ask-user-error' : 'better-ask-user-wait-hint'}
198
- type="text" inputMode="numeric" aria-invalid={invalid || undefined}
199
- value={live.questionTimeoutSeconds} disabled={controlsDisabled}
200
- onChange={(event) => { edit(current => ({ ...current, questionTimeoutSeconds: event.target.value })) }}
201
- />
202
- <span className={css.unit}>{t('seconds')}</span>
203
- </span>}
204
- </Row>
205
- <p className={css.srOnly} id="better-ask-user-wait-hint">{t(unlimited ? 'unlimitedHint' : 'waitHint')}</p>
206
- {invalid && <p className={css.fieldError} id="better-ask-user-error" role="alert">{t('invalidWait')}</p>}
207
- {!unlimited && <>
208
- <h3 className={css.sectionLabel}>{t('timeoutTitle')}</h3>
209
- <Row id="better-ask-user-behavior" label={t('behaviorLabel')}>
245
+ <div className={css.section} data-ask-section="wait">
246
+ <div className={css.waitHead}>
247
+ <h3 className={css.sectionLabel} id="better-ask-user-wait-mode-label">{t('waitLabel')}</h3>
210
248
  <Choices
211
- id="better-ask-user-behavior" value={live.timeoutBehavior} options={behaviors}
212
- disabled={controlsDisabled} describedBy="better-ask-user-timeout-hint"
213
- onChange={(value) => { edit(current => ({ ...current, timeoutBehavior: value as Behavior })) }}
249
+ id="better-ask-user-wait-mode" value={unlimited ? 'unlimited' : 'timed'}
250
+ options={[{ value: 'timed', label: t('timed') }, { value: 'unlimited', label: t('unlimited') }]}
251
+ disabled={controlsDisabled} describedBy="better-ask-user-wait-hint"
252
+ onChange={(value) => {
253
+ const nextUnlimited = value === 'unlimited'
254
+ if (nextUnlimited && !invalid) setTimedSeconds(live.questionTimeoutSeconds)
255
+ edit(current => ({ ...current, questionTimeoutSeconds: nextUnlimited ? '-1' : timedSeconds }))
256
+ }}
214
257
  />
215
- </Row>
216
- <p className={css.srOnly} id="better-ask-user-timeout-hint">{t(live.timeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}</p>
217
- <details className={css.advanced}>
218
- <summary>
219
- <span>{t('advanced')}</span>
220
- {live.goalTimeoutBehavior !== DEFAULTS.goalTimeoutBehavior && <span className={css.advancedValue}>{t('goalBehaviorLabel')} · {t(live.goalTimeoutBehavior)}</span>}
221
- <span className={css.chevron} aria-hidden="true" />
222
- </summary>
223
- <Row id="better-ask-user-goal-behavior" label={t('goalBehaviorLabel')}>
224
- <Choices
225
- id="better-ask-user-goal-behavior" value={live.goalTimeoutBehavior} options={behaviors}
226
- disabled={controlsDisabled} describedBy="better-ask-user-goal-hint"
227
- onChange={(value) => { edit(current => ({ ...current, goalTimeoutBehavior: value as Behavior })) }}
258
+ </div>
259
+ {unlimited ? null : <div className={css.waitControl}>
260
+ <span className={css.duration}>
261
+ <input
262
+ id="better-ask-user-wait" className={css.input}
263
+ aria-label={t('durationLabel')}
264
+ aria-describedby={invalid ? 'better-ask-user-error' : 'better-ask-user-wait-hint'}
265
+ type="text" inputMode="numeric" aria-invalid={invalid || undefined}
266
+ value={live.questionTimeoutSeconds} disabled={controlsDisabled}
267
+ onChange={(event) => { edit(current => ({ ...current, questionTimeoutSeconds: event.target.value })) }}
228
268
  />
229
- </Row>
230
- <p className={css.srOnly} id="better-ask-user-goal-hint">{t(live.goalTimeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}</p>
231
- </details>
232
- </>}
269
+ <span className={css.unit}>{t('seconds')}</span>
270
+ </span>
271
+ <div className={css.presets} role="group" aria-label={t('presetLabel')}>
272
+ {presets.map((preset) => (
273
+ <button
274
+ key={preset.seconds} type="button" className={css.chip}
275
+ data-preset={preset.seconds}
276
+ aria-pressed={seconds === preset.seconds}
277
+ disabled={controlsDisabled}
278
+ onClick={() => { edit(current => ({ ...current, questionTimeoutSeconds: String(preset.seconds) })) }}
279
+ >{preset.label}</button>
280
+ ))}
281
+ </div>
282
+ </div>}
283
+ <div className={css.timeline} data-unlimited={unlimited} aria-hidden="true">
284
+ <span className={css.timelineNode}>{t('timelineAsk')}</span>
285
+ <span className={css.timelineRail}>
286
+ <span className={css.timelineChip}>{waitAmount}</span>
287
+ </span>
288
+ <span className={css.timelineNode}>{unlimited ? t('unlimited') : t('timelineEnd')}</span>
289
+ </div>
290
+ <p className={css.sectionNote} id="better-ask-user-wait-hint">{t(unlimited ? 'unlimitedHint' : 'waitHint')}</p>
291
+ {invalid && <p className={css.fieldError} id="better-ask-user-error" role="alert">{t('invalidWait')}</p>}
292
+ </div>
293
+ {unlimited ? null : <div className={css.section} data-ask-section="timeout">
294
+ <h3 className={css.sectionLabel} id="better-ask-user-behavior-label">{t('timeoutTitle')}</h3>
295
+ <ChoiceCards
296
+ id="better-ask-user-behavior" value={live.timeoutBehavior} options={behaviorCards}
297
+ disabled={controlsDisabled}
298
+ onChange={(value) => { edit(current => ({ ...current, timeoutBehavior: value as Behavior })) }}
299
+ />
300
+ </div>}
301
+ <div className={css.section} data-ask-section="goal">
302
+ <h3 className={css.sectionLabel} id="better-ask-user-goal-behavior-label">{t('goalBehaviorLabel')}</h3>
303
+ <p className={css.sectionNote} id="better-ask-user-goal-hint">{t('goalExplain')}</p>
304
+ <ChoiceCards
305
+ id="better-ask-user-goal-behavior" value={live.goalTimeoutBehavior} options={behaviorCards}
306
+ disabled={controlsDisabled} describedBy="better-ask-user-goal-hint"
307
+ onChange={(value) => { edit(current => ({ ...current, goalTimeoutBehavior: value as Behavior })) }}
308
+ />
309
+ </div>
233
310
  </section>
234
311
  {notice !== null && <p className={notice.tone === 'ok' ? css.status : css.fieldError} role={notice.tone === 'error' ? 'alert' : 'status'}>{notice.text}</p>}
235
312
  {dirty && <div className={css.footer} id="better-ask-user-settings-footer">