@surfishs/dsh-prompt-enhance 0.0.4 → 0.0.6

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.
@@ -31,7 +31,6 @@ import { fetchReasoningCapabilities } from './reasoning-options'
31
31
  import { useLlmRouting, type LlmRoutingState } from './llm-catalog'
32
32
  import {
33
33
  SegmentedControl,
34
- SettingsForm,
35
34
  SettingsFormModel,
36
35
  Switch,
37
36
  settingsNumberField,
@@ -169,8 +168,8 @@ const ROWS: readonly Row[] = [
169
168
  { key: 'streaming', kind: 'boolean', label: 'settings.row.streaming.label', hint: 'settings.row.streaming.hint' },
170
169
  { key: 'provider', kind: 'provider', label: 'settings.row.provider.label', hint: 'settings.row.provider.hint' },
171
170
  { key: 'model', kind: 'model', label: 'settings.row.model.label', hint: 'settings.row.model.hint' },
172
- { key: 'temperature', kind: 'number', label: 'settings.row.temperature.label', hint: 'settings.row.temperature.hint' },
173
171
  { key: 'reasoningEffort', kind: 'reasoning', label: 'settings.row.reasoningEffort.label', hint: 'settings.row.reasoningEffort.hint' },
172
+ { key: 'temperature', kind: 'number', label: 'settings.row.temperature.label', hint: 'settings.row.temperature.hint' },
174
173
  { key: 'maxOutputTokens', kind: 'number', label: 'settings.row.maxOutputTokens.label', hint: 'settings.row.maxOutputTokens.hint' },
175
174
  { key: 'maxInputChars', kind: 'number', label: 'settings.row.maxInputChars.label', hint: 'settings.row.maxInputChars.hint' },
176
175
  { key: 'timeoutMs', kind: 'number', label: 'settings.row.timeoutMs.label', hint: 'settings.row.timeoutMs.hint' },
@@ -280,8 +279,10 @@ function sectionCopy(t: Translate, chinese: boolean): RowCopy {
280
279
  unavailable: t('settings.unavailable'),
281
280
  readOnly: t('settings.readOnly'),
282
281
  saveFailed: t('settings.saveFailed'),
282
+ saveFailedShort: t('settings.saveFailedShort'),
283
283
  save: t('settings.save'),
284
284
  saving: t('settings.saving'),
285
+ saved: t('settings.saved'),
285
286
  reset: t('settings.reset'),
286
287
  invalidNumber: t('settings.invalidNumber'),
287
288
  },
@@ -305,8 +306,10 @@ function pageCopy(t: Translate): RowCopy {
305
306
  unavailable: t('settings.unavailable'),
306
307
  readOnly: t('settings.readOnly'),
307
308
  saveFailed: t('settings.saveFailed'),
309
+ saveFailedShort: t('settings.saveFailedShort'),
308
310
  save: t('settings.save'),
309
311
  saving: t('settings.saving'),
312
+ saved: t('settings.saved'),
310
313
  reset: t('settings.reset'),
311
314
  invalidNumber: t('settings.invalidNumber'),
312
315
  },
@@ -526,6 +529,7 @@ interface FormProps {
526
529
  resetField?: (key: string) => void
527
530
  save?: () => void
528
531
  discard?: () => void
532
+ writeField?: (key: string, text: string) => Promise<'saved' | 'invalid' | 'failed'>
529
533
  }
530
534
 
531
535
  /** One locale snapshot, as the client locale service exposes it. */
@@ -577,6 +581,8 @@ interface RowProps {
577
581
  onEdit: (text: string) => void
578
582
  /** Clear the stored value so the row re-inherits the composition default. */
579
583
  onReset: () => void
584
+ /** Commit the current text now, e.g. on blur or Enter. */
585
+ onCommit?: () => void
580
586
  }
581
587
 
582
588
  /**
@@ -669,7 +675,7 @@ function BooleanRow(props: RowProps): ReactElement {
669
675
  * @param props - the row, its choices, its state, and its actions.
670
676
  * @returns the row element.
671
677
  */
672
- function ChoiceRow(props: RowProps & { options: readonly { value: string; label: string }[] }): ReactElement {
678
+ function ChoiceRow(props: RowProps & { options: readonly { value: string; label: string; title?: string }[] }): ReactElement {
673
679
  return (
674
680
  <div style={ROW_STYLE}>
675
681
  <div style={HEAD_STYLE}>
@@ -678,8 +684,9 @@ function ChoiceRow(props: RowProps & { options: readonly { value: string; label:
678
684
  </div>
679
685
  <SegmentedControl
680
686
  id={props.id}
687
+ className="dsh-pe-segmented-labels"
681
688
  value={props.view.text}
682
- options={props.options}
689
+ options={props.options.map((option) => ({ ...option, title: option.title ?? option.label }))}
683
690
  disabled={props.disabled}
684
691
  label={props.label}
685
692
  onChange={(next: string) => props.onEdit(next)}
@@ -783,11 +790,15 @@ function ReasoningRow(props: RowProps & { provider: string; model: string }): Re
783
790
  options.push({
784
791
  value: effort.id,
785
792
  label: effort.name,
786
- ...effort.description === undefined ? {} : { title: effort.description },
793
+ title: effort.description === undefined ? effort.name : `${effort.name} — ${effort.description}`,
787
794
  })
788
795
  }
789
796
  }
790
- options.push({ value: 'inherit', label: props.copy.choice('settings.reasoning.inherit') })
797
+ options.push({
798
+ value: 'inherit',
799
+ label: props.copy.choice('settings.reasoning.inherit'),
800
+ title: props.copy.choice('settings.reasoning.inherit'),
801
+ })
791
802
  const unsupported = !noTiers && phase === 'ready' && capabilities?.source !== 'unavailable'
792
803
  && current !== '' && current !== 'inherit' && !realTierKnown
793
804
  const refreshing = feedback === 'refreshing'
@@ -815,6 +826,7 @@ function ReasoningRow(props: RowProps & { provider: string; model: string }): Re
815
826
  </div>
816
827
  <SegmentedControl
817
828
  id={props.id}
829
+ className="dsh-pe-segmented-labels"
818
830
  // A route that declares no tiers is presented as "follow provider
819
831
  // default"; the stored tier stays in the config and the host omits it
820
832
  // on the call, so the displayed state matches what actually happens.
@@ -995,9 +1007,15 @@ function TextControl(props: {
995
1007
  invalid?: boolean
996
1008
  disabled?: boolean
997
1009
  onChange: (value: string) => void
1010
+ onCommit?: () => void
998
1011
  }): ReactElement {
999
1012
  const [focused, setFocused] = useState(false)
1000
- const borderColor = props.invalid === true
1013
+ const [revealedInvalid, setRevealedInvalid] = useState(false)
1014
+ useEffect(() => {
1015
+ if (props.invalid !== true) setRevealedInvalid(false)
1016
+ }, [props.invalid])
1017
+ const showInvalid = props.invalid === true && revealedInvalid
1018
+ const borderColor = showInvalid
1001
1019
  ? 'var(--dsw-alias-state-error-primary, #f85149)'
1002
1020
  : focused ? 'var(--dsw-alias-state-business-primary, #4f8cff)' : undefined
1003
1021
  return (
@@ -1005,7 +1023,7 @@ function TextControl(props: {
1005
1023
  id={props.id}
1006
1024
  type="text"
1007
1025
  inputMode={props.numeric === true ? 'numeric' : undefined}
1008
- aria-invalid={props.invalid === true || undefined}
1026
+ aria-invalid={showInvalid || undefined}
1009
1027
  disabled={props.disabled}
1010
1028
  placeholder={props.placeholder}
1011
1029
  value={props.value}
@@ -1015,7 +1033,17 @@ function TextControl(props: {
1015
1033
  ...borderColor === undefined ? {} : { borderColor },
1016
1034
  }}
1017
1035
  onFocus={() => setFocused(true)}
1018
- onBlur={() => setFocused(false)}
1036
+ onBlur={() => {
1037
+ setFocused(false)
1038
+ if (props.invalid === true) setRevealedInvalid(true)
1039
+ props.onCommit?.()
1040
+ }}
1041
+ onKeyDown={(event) => {
1042
+ if (event.key !== 'Enter') return
1043
+ event.preventDefault()
1044
+ if (props.invalid === true) setRevealedInvalid(true)
1045
+ props.onCommit?.()
1046
+ }}
1019
1047
  onChange={(event) => props.onChange(event.target.value)}
1020
1048
  />
1021
1049
  )
@@ -1037,6 +1065,7 @@ function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string }):
1037
1065
  invalid={invalid}
1038
1066
  disabled={props.disabled}
1039
1067
  onChange={props.onEdit}
1068
+ onCommit={props.onCommit}
1040
1069
  />
1041
1070
  <p style={HINT_STYLE}>{props.hint}</p>
1042
1071
  {invalid ? <p style={INVALID_STYLE}>{props.copy.labels.invalidNumber}</p> : null}
@@ -1049,7 +1078,7 @@ function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string }):
1049
1078
  * @param props - the row, its copy, its state, its actions, and the pinned pair.
1050
1079
  * @returns the row element.
1051
1080
  */
1052
- function SettingsRow(props: { row: Row; copy: RowCopy; view: FieldView; disabled: boolean; reasoningPair: { provider: string; model: string }; routing: LlmRoutingState; providerValue: string; onEdit: (text: string) => void; onReset: () => void }): ReactElement {
1081
+ function SettingsRow(props: { row: Row; copy: RowCopy; view: FieldView; disabled: boolean; reasoningPair: { provider: string; model: string }; routing: LlmRoutingState; providerValue: string; onEdit: (text: string) => void; onReset: () => void; onCommit?: () => void }): ReactElement {
1053
1082
  const shared = {
1054
1083
  id: `dsh-prompt-enhance-${props.row.key}`,
1055
1084
  label: props.copy.title(props.row),
@@ -1059,6 +1088,7 @@ function SettingsRow(props: { row: Row; copy: RowCopy; view: FieldView; disabled
1059
1088
  disabled: props.disabled,
1060
1089
  onEdit: props.onEdit,
1061
1090
  onReset: props.onReset,
1091
+ onCommit: props.onCommit,
1062
1092
  }
1063
1093
  switch (props.row.kind) {
1064
1094
  case 'boolean':
@@ -1088,14 +1118,136 @@ function SettingsRows(props: {
1088
1118
  resetField: (key: string) => void
1089
1119
  save?: () => void
1090
1120
  discard?: () => void
1121
+ writeField?: (key: string, text: string) => Promise<'saved' | 'invalid' | 'failed'>
1091
1122
  }): ReactElement {
1092
1123
  // The reasoning row reads the staged pair so options follow the fields before
1093
1124
  // they are saved (typing a custom model refreshes them on its own).
1094
1125
  const provider = viewOf(props.state, 'provider').text.trim()
1095
1126
  const model = viewOf(props.state, 'model').text.trim()
1096
1127
  const routing = useLlmRouting(provider, model)
1128
+ const [saveState, setSaveState] = useState<'idle' | 'saving' | 'saved' | 'failed'>('idle')
1129
+ const timers = useRef(new Map<string, ReturnType<typeof setTimeout>>())
1130
+ const savedTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
1131
+ const savedValues = useRef(new Map<string, string>())
1132
+ const sequence = useRef(0)
1133
+
1134
+ useEffect(() => {
1135
+ for (const row of ROWS) {
1136
+ if (!savedValues.current.has(row.key)) {
1137
+ savedValues.current.set(row.key, viewOf(props.state, row.key).text)
1138
+ }
1139
+ }
1140
+ }, [props.state])
1141
+
1142
+ const runSave = async (key: string, text: string): Promise<void> => {
1143
+ if (props.writeField === undefined) return
1144
+ // A focus/blur with no edit, or an edit reverted to the stored value, is
1145
+ // not a write: skip it without touching the footer status.
1146
+ if (savedValues.current.get(key) === text) return
1147
+ const ticket = ++sequence.current
1148
+ setSaveState('saving')
1149
+ const result = await props.writeField(key, text)
1150
+ if (ticket !== sequence.current) return
1151
+ if (result === 'invalid') {
1152
+ setSaveState('idle')
1153
+ return
1154
+ }
1155
+ if (result === 'failed') {
1156
+ setSaveState('failed')
1157
+ return
1158
+ }
1159
+ savedValues.current.set(key, text)
1160
+ markSaved()
1161
+ }
1162
+
1163
+ const markSaved = (): void => {
1164
+ setSaveState('saved')
1165
+ if (savedTimer.current !== undefined) clearTimeout(savedTimer.current)
1166
+ savedTimer.current = setTimeout(() => {
1167
+ setSaveState('idle')
1168
+ savedTimer.current = undefined
1169
+ }, 2000)
1170
+ }
1171
+
1172
+ const manualSave = async (): Promise<void> => {
1173
+ if (props.writeField === undefined) {
1174
+ // Hosts without per-field writes keep the original whole-form action.
1175
+ props.save?.()
1176
+ markSaved()
1177
+ return
1178
+ }
1179
+ const changed = ROWS
1180
+ .map((row) => ({ key: row.key, text: viewOf(props.state, row.key).text }))
1181
+ .filter((item) => savedValues.current.get(item.key) !== item.text)
1182
+ if (changed.length === 0) {
1183
+ markSaved()
1184
+ return
1185
+ }
1186
+ const ticket = ++sequence.current
1187
+ setSaveState('saving')
1188
+ let failed = false
1189
+ let invalid = false
1190
+ for (const item of changed) {
1191
+ const result = await props.writeField(item.key, item.text)
1192
+ if (result === 'saved') savedValues.current.set(item.key, item.text)
1193
+ else if (result === 'failed') failed = true
1194
+ else invalid = true
1195
+ }
1196
+ if (ticket !== sequence.current) return
1197
+ if (failed) setSaveState('failed')
1198
+ else if (invalid && changed.every((item) => savedValues.current.get(item.key) !== item.text)) setSaveState('idle')
1199
+ else markSaved()
1200
+ }
1201
+
1202
+ const scheduleSave = (key: string, text: string, immediate: boolean): void => {
1203
+ const pending = timers.current.get(key)
1204
+ if (pending !== undefined) clearTimeout(pending)
1205
+ if (immediate) {
1206
+ timers.current.delete(key)
1207
+ void runSave(key, text)
1208
+ return
1209
+ }
1210
+ const timer = setTimeout(() => {
1211
+ timers.current.delete(key)
1212
+ void runSave(key, text)
1213
+ }, 800)
1214
+ timers.current.set(key, timer)
1215
+ }
1216
+
1217
+ const onEdit = (key: string, text: string): void => {
1218
+ props.edit(key, text)
1219
+ const row = ROWS.find((item) => item.key === key)
1220
+ const debounced = row !== undefined && (row.kind === 'text' || row.kind === 'number')
1221
+ scheduleSave(key, text, !debounced)
1222
+ }
1223
+
1224
+ const flushField = (key: string, text?: string): void => {
1225
+ const pending = timers.current.get(key)
1226
+ if (pending !== undefined) {
1227
+ clearTimeout(pending)
1228
+ timers.current.delete(key)
1229
+ }
1230
+ void runSave(key, text ?? viewOf(props.state, key).text)
1231
+ }
1232
+
1233
+ useEffect(() => () => {
1234
+ for (const timer of timers.current.values()) clearTimeout(timer)
1235
+ timers.current.clear()
1236
+ if (savedTimer.current !== undefined) clearTimeout(savedTimer.current)
1237
+ }, [])
1238
+
1239
+ const statusText = props.state.writable === false
1240
+ ? props.copy.labels.readOnly
1241
+ : saveState === 'saving'
1242
+ ? props.copy.labels.saving
1243
+ : saveState === 'saved'
1244
+ ? props.copy.labels.saved
1245
+ : saveState === 'failed'
1246
+ ? props.copy.labels.saveFailedShort
1247
+ : ''
1248
+
1097
1249
  return (
1098
- <SettingsForm labels={props.copy.labels} state={props.state} onSave={props.save} onDiscard={props.discard}>
1250
+ <div className="dsh-pe-form">
1099
1251
  {ROWS.map((row, index) => {
1100
1252
  const raw = viewOf(props.state, row.key)
1101
1253
  // Hide the override badge once the value is back at its default; the
@@ -1111,13 +1263,29 @@ function SettingsRows(props: {
1111
1263
  reasoningPair={{ provider, model }}
1112
1264
  routing={routing}
1113
1265
  providerValue={provider}
1114
- onEdit={(text: string) => props.edit(row.key, text)}
1266
+ onEdit={(text: string) => onEdit(row.key, text)}
1115
1267
  onReset={() => props.resetField(row.key)}
1268
+ onCommit={() => flushField(row.key, viewOf(props.state, row.key).text)}
1116
1269
  />
1117
1270
  </div>
1118
1271
  )
1119
1272
  })}
1120
- </SettingsForm>
1273
+ <div className="dsh-pe-form-footer">
1274
+ <div className="dsh-pe-save-group">
1275
+ {statusText === ''
1276
+ ? null
1277
+ : <span className="dsh-pe-save-status" role="status" aria-live="polite">{statusText}</span>}
1278
+ <button
1279
+ type="button"
1280
+ className="dsh-pe-save-button"
1281
+ disabled={props.save === undefined || props.state.writable === false}
1282
+ onClick={() => { void manualSave() }}
1283
+ >
1284
+ {props.copy.labels.save}
1285
+ </button>
1286
+ </div>
1287
+ </div>
1288
+ </div>
1121
1289
  )
1122
1290
  }
1123
1291
 
@@ -1153,6 +1321,7 @@ export function SettingsSection(props: SectionProps): unknown {
1153
1321
  resetField={resetField}
1154
1322
  save={props.save}
1155
1323
  discard={props.discard}
1324
+ writeField={props.writeField}
1156
1325
  />
1157
1326
  </div>
1158
1327
  )
@@ -1185,6 +1354,7 @@ export function SettingsPage(props: PageProps): unknown {
1185
1354
  resetField={resetField}
1186
1355
  save={props.save}
1187
1356
  discard={props.discard}
1357
+ writeField={props.writeField}
1188
1358
  />
1189
1359
  )
1190
1360
  }
@@ -1193,6 +1363,8 @@ export function SettingsPage(props: PageProps): unknown {
1193
1363
  interface ConfigScopeLike {
1194
1364
  getSnapshot?: () => unknown
1195
1365
  subscribe?: (listener: () => void) => () => void
1366
+ set?: (field: string, value: unknown) => Promise<boolean>
1367
+ unset?: (field: string) => Promise<boolean>
1196
1368
  }
1197
1369
 
1198
1370
  /** Structural face of the host's config-forms provider. */
@@ -1210,6 +1382,7 @@ interface SlotsFace {
1210
1382
  /** Bridges one settings scope onto both pages' staged form. */
1211
1383
  class SettingsPageController {
1212
1384
  private readonly form: SettingsFormModel
1385
+ private readonly scope: ConfigScopeLike
1213
1386
  private readonly store: unknown
1214
1387
  private readonly getLocale: (() => LocaleFaceLike | undefined) | undefined
1215
1388
 
@@ -1219,6 +1392,7 @@ class SettingsPageController {
1219
1392
  */
1220
1393
  constructor(scope: ConfigScopeLike, getLocale?: () => LocaleFaceLike | undefined) {
1221
1394
  this.getLocale = getLocale
1395
+ this.scope = scope
1222
1396
  this.form = createSettingsForm(scope)
1223
1397
  this.store = this.form.bind(() => {
1224
1398
  const out = this.form.shell()
@@ -1236,7 +1410,11 @@ class SettingsPageController {
1236
1410
  /** The props the slots hand their pages. */
1237
1411
  inject(): Record<string, unknown> {
1238
1412
  const face = this.getLocale?.()
1239
- const props: Record<string, unknown> = { hooks: { promptEnhance: this.store }, ...this.form.actions() }
1413
+ const props: Record<string, unknown> = {
1414
+ hooks: { promptEnhance: this.store },
1415
+ ...this.form.actions(),
1416
+ writeField: (key: string, text: string) => this.writeField(key, text),
1417
+ }
1240
1418
  if (face !== undefined) {
1241
1419
  // A small observable the slot turns into `usePromptEnhanceLocale`; the
1242
1420
  // page reads the active language from it and re-renders on a switch.
@@ -1249,6 +1427,26 @@ class SettingsPageController {
1249
1427
  return props
1250
1428
  }
1251
1429
 
1430
+ /** Write one field through the host's per-field mutation API. */
1431
+ private async writeField(key: string, text: string): Promise<'saved' | 'invalid' | 'failed'> {
1432
+ const descriptor = FIELD_SPECS.find((item) => item.field === key)
1433
+ if (descriptor === undefined) return 'failed'
1434
+ const parsed = descriptor.parse(text)
1435
+ if (parsed === undefined) return 'invalid'
1436
+ if (this.scope.set === undefined) return 'failed'
1437
+ try {
1438
+ if (parsed.kind === 'clear') {
1439
+ if (this.scope.unset === undefined) return 'failed'
1440
+ if (!(await this.scope.unset(key))) return 'failed'
1441
+ } else {
1442
+ if (!(await this.scope.set(key, parsed.value))) return 'failed'
1443
+ }
1444
+ return 'saved'
1445
+ } catch {
1446
+ return 'failed'
1447
+ }
1448
+ }
1449
+
1252
1450
  /** Release the form's subscriptions. */
1253
1451
  dispose(): void {
1254
1452
  try {
@@ -59,8 +59,15 @@ export const CSS = `
59
59
  font-weight: 600;
60
60
  }
61
61
  .dsh-pe-head .dsh-pe-title { display: inline-flex; align-items: center; gap: 6px; }
62
- .dsh-pe-head .dsh-pe-badge {
62
+ .dsh-pe-head .dsh-pe-head-actions {
63
+ display: flex;
64
+ align-items: center;
65
+ gap: 8px;
63
66
  margin-left: auto;
67
+ min-width: 0;
68
+ }
69
+ .dsh-pe-head .dsh-pe-badge {
70
+ margin-left: 0;
64
71
  border: 1px solid var(--pe-border);
65
72
  border-radius: 999px;
66
73
  padding: 1px 8px;
@@ -211,22 +218,99 @@ export const CSS = `
211
218
  display: flex;
212
219
  align-items: center;
213
220
  gap: 8px;
214
- padding: 2px 4px;
221
+ width: fit-content;
222
+ margin-left: auto;
223
+ padding: 3px 6px 3px 10px;
224
+ border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
225
+ border-radius: 12px;
226
+ background: var(--dsw-alias-bg-layer-1, transparent);
215
227
  font-size: 12px;
216
228
  color: inherit;
217
- opacity: 0.85;
218
229
  }
219
- .dsh-pe-undo .dsh-pe-undo-check { color: #7ed491; }
230
+ .dsh-pe-undo .dsh-pe-undo-check {
231
+ color: var(--dsw-alias-state-success-primary, #2da44e);
232
+ font-weight: 600;
233
+ }
220
234
  .dsh-pe-undo-link {
221
- border: none; background: var(--pe-hover); color: inherit;
222
- border-radius: 5px; padding: 3px 10px; font-size: 12px; cursor: pointer;
235
+ display: inline-flex;
236
+ align-items: center;
237
+ justify-content: center;
238
+ gap: 6px;
239
+ height: 28px;
240
+ padding: 0 10px;
241
+ border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
242
+ border-radius: 6px;
243
+ background: transparent;
244
+ color: inherit;
245
+ font-size: 12px;
246
+ cursor: pointer;
247
+ transition: background-color 120ms ease;
223
248
  }
224
- .dsh-pe-undo-link:hover { background: rgba(127,127,127,0.3); }
249
+ .dsh-pe-undo-link:hover { background: rgba(127, 127, 127, 0.16); }
250
+ .dsh-pe-undo-link:active { background: rgba(127, 127, 127, 0.22); }
225
251
  .dsh-pe-undo-x {
226
- border: none; background: transparent; color: inherit; opacity: 0.55;
227
- cursor: pointer; padding: 0 4px; font-size: 12px;
252
+ display: inline-flex;
253
+ align-items: center;
254
+ justify-content: center;
255
+ width: 28px;
256
+ height: 28px;
257
+ border: none;
258
+ border-radius: 6px;
259
+ background: transparent;
260
+ color: inherit;
261
+ opacity: 0.55;
262
+ cursor: pointer;
263
+ padding: 0;
264
+ font-size: 12px;
265
+ }
266
+ .dsh-pe-undo-x:hover { opacity: 1; background: var(--dsw-alias-bg-layer-2, rgba(128, 128, 128, 0.12)); }
267
+ .dsh-pe-segmented-labels [role="tab"] {
268
+ min-width: 0;
269
+ overflow: hidden;
270
+ text-overflow: ellipsis;
271
+ text-align: center;
272
+ white-space: nowrap;
273
+ }
274
+ .dsh-pe-form-footer {
275
+ display: flex;
276
+ justify-content: flex-end;
277
+ margin-top: 12px;
278
+ padding-top: 10px;
279
+ border-top: 1px solid var(--dsw-alias-border-l3, rgba(128, 128, 128, 0.22));
280
+ }
281
+ .dsh-pe-save-group {
282
+ display: flex;
283
+ align-items: center;
284
+ justify-content: flex-end;
285
+ flex-wrap: wrap;
286
+ gap: 8px;
287
+ min-width: 0;
288
+ max-width: 100%;
289
+ margin-left: auto;
290
+ }
291
+ .dsh-pe-save-status {
292
+ min-width: 0;
293
+ max-width: 100%;
294
+ font-size: 12px;
295
+ color: var(--dsw-alias-label-secondary, inherit);
296
+ text-align: right;
297
+ overflow-wrap: anywhere;
298
+ }
299
+ .dsh-pe-save-button {
300
+ flex: none;
301
+ margin-left: 0;
302
+ height: 28px;
303
+ padding: 0 14px;
304
+ border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
305
+ border-radius: 8px;
306
+ background: var(--dsw-alias-bg-layer-1, transparent);
307
+ color: inherit;
308
+ font: inherit;
309
+ font-size: 12px;
310
+ cursor: pointer;
228
311
  }
229
- .dsh-pe-undo-x:hover { opacity: 1; }
312
+ .dsh-pe-save-button:hover:not(:disabled) { background: rgba(127, 127, 127, 0.12); }
313
+ .dsh-pe-save-button:disabled { opacity: 0.5; cursor: default; }
230
314
  `
231
315
 
232
316
  /**
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Align a dock entry to the composer card below it.
3
+ *
4
+ * The host renders conversation.input.dock entries full-width, while the
5
+ * composer card is narrower and may be centered or offset. This hook measures
6
+ * the nearest editor below the dock, walks up to the composer's rounded
7
+ * surface, and copies its width and left margin onto the returned wrapper.
8
+ * When no editor is found, the host's full width is left untouched.
9
+ * @module dsh-prompt-enhance/client/useDockAlignment
10
+ */
11
+
12
+ import { useEffect, useRef, type RefObject } from 'react'
13
+
14
+ /** Measure the composer below the dock and align the returned wrapper to it. */
15
+ export function useDockAlignment(active: boolean): RefObject<HTMLDivElement> {
16
+ const rootRef = useRef<HTMLDivElement>(null)
17
+
18
+ useEffect(() => {
19
+ if (!active) return
20
+ const root = rootRef.current
21
+ if (root === null) return
22
+ let frame = 0
23
+ const align = (): void => {
24
+ const parent = root.parentElement
25
+ if (parent === null) return
26
+ // A transform-only offset is applied to the wrong base when the host
27
+ // already centers this entry, and a translated box can be clipped by its
28
+ // parent; use a layout margin instead. The previous margin is subtracted
29
+ // from the measured left so repeated runs do not accumulate drift.
30
+ root.style.transform = ''
31
+ const previousMargin = parseFloat(root.style.marginLeft) || 0
32
+ const rootRect = root.getBoundingClientRect()
33
+ const editors = Array.from(document.querySelectorAll<HTMLElement>('textarea, [contenteditable="true"], [role="textbox"]'))
34
+ const editor = editors.find((node) => {
35
+ const rect = node.getBoundingClientRect()
36
+ return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4
37
+ })
38
+ if (editor === undefined) {
39
+ root.style.width = ''
40
+ root.style.marginLeft = ''
41
+ root.style.transform = ''
42
+ return
43
+ }
44
+ const editorRect = editor.getBoundingClientRect()
45
+ // Collect every rounded, opaque ancestor of the editor, then take the
46
+ // widest one that is still plausibly the composer card. The first match
47
+ // is often an inner wrapper a few pixels narrower than the card; the
48
+ // conversation pane above it is too wide. Center proximity rejects the
49
+ // pane when the composer is off-center, and the width cap rejects it
50
+ // when both are centered.
51
+ const candidates: { node: HTMLElement; rect: DOMRect }[] = []
52
+ let node: HTMLElement | null = editor
53
+ for (let depth = 0; depth < 12 && node !== null; depth++) {
54
+ const rect = node.getBoundingClientRect()
55
+ const style = getComputedStyle(node)
56
+ if (
57
+ rect.width >= editorRect.width
58
+ && rect.width > 360
59
+ && rect.height > 48
60
+ && (parseFloat(style.borderTopLeftRadius) || 0) >= 4
61
+ && style.backgroundColor !== 'rgba(0, 0, 0, 0)'
62
+ ) {
63
+ candidates.push({ node, rect })
64
+ }
65
+ node = node.parentElement
66
+ }
67
+ const editorCenter = editorRect.left + editorRect.width / 2
68
+ const cardEntry = candidates
69
+ .filter((candidate) => (
70
+ candidate.rect.width <= window.innerWidth * 0.8
71
+ && Math.abs(candidate.rect.left + candidate.rect.width / 2 - editorCenter) < 40
72
+ ))
73
+ .sort((a, b) => b.rect.width - a.rect.width)[0]
74
+ ?? candidates.sort((a, b) => b.rect.width - a.rect.width)[0]
75
+ if (cardEntry === undefined) return
76
+ const cardRect = cardEntry.rect
77
+ const width = `${cardRect.width}px`
78
+ if (root.style.width !== width) root.style.width = width
79
+ // Width can shift a centered entry; measure again before deriving the
80
+ // margin so the final left edge matches the composer card.
81
+ const afterWidth = root.getBoundingClientRect()
82
+ const currentMargin = parseFloat(root.style.marginLeft) || 0
83
+ const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`
84
+ if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft
85
+ }
86
+ const schedule = (): void => {
87
+ cancelAnimationFrame(frame)
88
+ frame = requestAnimationFrame(align)
89
+ }
90
+ schedule()
91
+ schedule()
92
+ window.addEventListener('resize', schedule)
93
+ const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule)
94
+ observer?.observe(document.documentElement)
95
+ return () => {
96
+ cancelAnimationFrame(frame)
97
+ window.removeEventListener('resize', schedule)
98
+ observer?.disconnect()
99
+ }
100
+ }, [active])
101
+
102
+ return rootRef
103
+ }