dsh-agent-control-center 0.3.1 → 0.4.1

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.
@@ -146,20 +146,6 @@
146
146
  return h(C.Btn, { tone: 'ghost', onClick: copy, title: label, 'aria-live': 'polite' }, label)
147
147
  }
148
148
 
149
- /** Esc collapses the open detail panel while it is open. */
150
- function useEscape(active, onEscape) {
151
- ACC.useEffect(() => {
152
- if (!active) return undefined
153
- const handler = (event) => {
154
- if (event.key !== 'Escape') return
155
- event.stopPropagation()
156
- onEscape()
157
- }
158
- document.addEventListener('keydown', handler)
159
- return () => document.removeEventListener('keydown', handler)
160
- }, [active, onEscape])
161
- }
162
-
163
149
  /** @param {{ value: unknown, onOpen: Function, t: Function }} props */
164
150
  function SourceBadge(props) {
165
151
  const source = props.value || {}
@@ -474,7 +460,42 @@
474
460
  [selected, days, agentId],
475
461
  )
476
462
 
477
- useEscape(selected.length > 0, ACC.useCallback(() => setSelected(''), []))
463
+ // Escape closes the host Settings dialog. Local state (an open detail row or a
464
+ // non-empty search) must consume the key first: a capture-phase listener runs
465
+ // before the host's document-level handler, and stopPropagation keeps it from
466
+ // reaching the dialog.
467
+ ACC.useEffect(() => {
468
+ // The host may close the Settings dialog from any of the three key events
469
+ // at any level, so the whole Escape gesture is consumed here: keydown
470
+ // decides whether the page owns it, keypress/keyup follow for the same
471
+ // gesture so a later phase cannot reopen the dialog's close path.
472
+ let ownedByPage = false
473
+ const handler = (event) => {
474
+ if (event.key !== 'Escape') return
475
+ const input = searchRef.current
476
+ if (event.type === 'keydown') {
477
+ ownedByPage = selected !== '' || search !== '' || (input !== null && document.activeElement === input)
478
+ }
479
+ if (!ownedByPage) return
480
+ event.preventDefault()
481
+ event.stopPropagation()
482
+ if (event.type !== 'keydown') return
483
+ if (selected !== '') {
484
+ setSelected('')
485
+ return
486
+ }
487
+ if (search !== '') {
488
+ setSearch('')
489
+ return
490
+ }
491
+ if (input !== null) input.blur()
492
+ }
493
+ const types = ['keydown', 'keypress', 'keyup']
494
+ for (const type of types) window.addEventListener(type, handler, true)
495
+ return () => {
496
+ for (const type of types) window.removeEventListener(type, handler, true)
497
+ }
498
+ }, [selected, search])
478
499
  ACC.useEffect(() => {
479
500
  const onKey = (event) => {
480
501
  if (event.key !== '/' || event.metaKey || event.ctrlKey || event.altKey) return
@@ -560,7 +581,12 @@
560
581
  placeholder: t('tools.searchPlaceholder'),
561
582
  value: search,
562
583
  onChange: (event) => setSearch(event.target.value),
563
- onKeyDown: (event) => { if (event.key === 'Escape') setSearch('') },
584
+ onKeyDown: (event) => {
585
+ if (event.key !== 'Escape') return
586
+ // The page-level capture handler already clears the query; keep the
587
+ // dialog open if it ever arrives here first.
588
+ event.preventDefault()
589
+ },
564
590
  'aria-label': t('tools.search'),
565
591
  style: { minWidth: '180px' },
566
592
  }),