@gemboss/ui 0.52.0 → 0.53.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.
@@ -4,8 +4,9 @@ export { AssistantHost, AssistantMenuItem, type AssistantHostLabels, type Assist
4
4
  export { AssistantProvider, SIDE_WIDTH_VAR, useAssistant, useAssistantPageFacts, type AssistantDockApi, type AssistantOptions } from "./provider";
5
5
  export * from "./dock";
6
6
  export { AssistantWorkspaceLayout, OpenChatTabs, SessionRail, SESSION_RAIL_EN, groupSessions, normalizeForSearch, relativeTime, type AssistantSession, type SessionGroup, type SessionRailIcons, type SessionRailLabels } from "./sessions";
7
- export { BRIDGE_TONE, BridgeNotice, ENGINE_PICKER_EN, EnginePanel, EnginePicker, engineChipName, useEnginePicker, type BridgeSetup, type BridgeState, type BridgeStatus, type Choice, type EngineChoice, type EnginePickerLabels, type EnginePickerProps, type EnginePickerTab } from "./engine";
8
- // 0.52.0: the engine in the surface's Settings ("AI & engines"): the chip opens it (`onOpenSettings`), the section draws it.
7
+ export { BRIDGE_TONE, BridgeNotice, ENGINE_PICKER_EN, EnginePicker, engineChipName, useEnginePicker, type BridgeSetup, type BridgeState, type BridgeStatus, type Choice, type EngineChoice, type EnginePickerLabels, type EnginePickerProps, type EnginePickerTab } from "./engine";
8
+ // The engine in the surface's Settings ("AI & engines", 0.52.0; the only place since 0.53.0): the chip opens it
9
+ // (`onOpenSettings`), the section draws it.
9
10
  export { EngineSettings, EngineSettingsSection, type EngineSettingsProps } from "./engine-settings";
10
11
  // 0.29.0: the chat BODY as components (the surface hands in messages and actions), its markdown, and each engine's mark.
11
12
  export { AssistantChat, ChatAttach, ChatBubble, ChatComposer, ChatError, ChatLabelsProvider, ChatMarkdown, ChatMessage, ChatMeta, ChatNote, ChatPending, ChatStarters, ChatSteps, ChatThread, CHAT_EN, PaperclipIcon, firstBlank, selectBlank, useComposerDensity, useFullChromeRoom, type AssistantChatProps, type ChatComposerProps, type ChatFix, type ChatLabels, type ChatMarkdownProps, type ChatMessageData, type ChatStarter, type ChatStep, type ComposerDensity } from "./chat";
@@ -1 +1 @@
1
- .gb-engine{display:inline-flex;min-width:0;max-width:100%}.gb-engine-chip{display:inline-flex;align-items:center;gap:6px;min-width:0;max-width:100%;box-sizing:border-box;height:var(--ui-btn-h, 28px);padding:0 24px 0 8px;font:inherit;font-size:var(--ui-fs-caption, 12px);font-weight:500;line-height:20px;white-space:nowrap;color:var(--ui-text-muted);background-color:transparent;border:1px solid transparent;border-radius:var(--ui-radius-md, 8px);cursor:pointer;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23686b71' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 8px center}@media (hover: hover){.gb-engine-chip:hover{color:var(--ui-text);background-color:var(--gemboss-hover, rgba(0,0,0,.05))}}@media (hover: none){.gb-engine-chip{color:var(--ui-text)}}.gb-engine-chip[aria-expanded=true]{color:var(--ui-text);background-color:var(--gemboss-hover, rgba(0,0,0,.05))}.gb-engine-chip:focus-visible{color:var(--ui-text);outline:2px solid var(--ui-focus);outline-offset:2px}.gb-engine-chiplabel{min-width:0;overflow:hidden;text-overflow:ellipsis}.gb-engine-chipsub{font-weight:450}.gb-engine-chip:disabled{cursor:default;opacity:.55}.gemboss-engine-mark{display:block;width:14px;height:14px;flex:0 0 auto}.gb-engine-chipmark{display:none}.gb-engine-chipmark .gemboss-engine-mark{width:16px;height:16px}.gemboss-ec-input:not([data-density=full]) .gb-engine-chipsub{display:none}.gemboss-ec-input:is([data-density=icon],[data-density=tight]) .gb-engine-chip.has-mark .gb-engine-chiplabel{display:none}.gemboss-ec-input:is([data-density=icon],[data-density=tight]) .gb-engine-chip.has-mark .gb-engine-chipmark{display:block}.gemboss-ec-input:is([data-density=icon],[data-density=tight]) .gb-engine:has(.has-mark){flex-shrink:0}.gb-engine-dot{flex:none;display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--ui-text-muted);vertical-align:middle}.gb-engine-dot--ok{background:var(--gemboss-success, #007f5f)}.gb-engine-dot--warn{background:#e8a10a;box-shadow:0 0 0 1px var(--gemboss-warning, #9a6700) inset}.gb-engine-dot--down{background:var(--gemboss-danger, #d72c0d)}.gb-engine-dot--idle{background:transparent;box-shadow:0 0 0 1.5px var(--ui-text-muted) inset}.gb-engine-panel{position:fixed;z-index:1000;inset:auto;margin:0;width:min(360px,calc(100vw - 16px));box-sizing:border-box;overflow:auto;overscroll-behavior:contain;padding:0 0 var(--ui-space-3, 12px);color:var(--ui-text);font-size:var(--ui-fs-caption, 12px);line-height:16px}.gb-engine-panel[hidden],.gb-engine-panel[popover]:not(:popover-open):not([data-open]){display:none}:where(.gb-engine-panel[popover]){border:0;background:none;color:inherit}.gb-engine-panel--inline{position:static;z-index:auto;overflow:visible}.gb-engine-tabs{padding:0 var(--ui-space-2, 8px)}.gb-engine-tabs>button{gap:6px}.gb-engine-pane{display:grid;gap:var(--ui-space-3, 12px);padding:var(--ui-space-3, 12px) var(--ui-space-3, 12px) 0}.gb-engine-pane p{margin:0}.gb-engine-field{display:grid;gap:6px}.gb-engine-label{font-weight:550;color:var(--ui-text-strong, var(--ui-text))}.gb-engine-note{color:var(--ui-text-muted)}.gb-engine-list{display:grid;border:1px solid var(--ui-border);border-radius:var(--ui-radius-md, 8px);overflow:hidden}.gb-engine-row{display:grid;gap:2px;min-height:44px;padding:6px 10px 6px 32px;box-sizing:border-box;position:relative;font:inherit;text-align:left;color:inherit;background:transparent;border:0;cursor:pointer}.gb-engine-row+.gb-engine-row{border-top:1px solid var(--ui-border)}.gb-engine-row:before{content:"";position:absolute;left:10px;top:50%;width:14px;height:14px;margin-top:-7px;box-sizing:border-box;border:1.5px solid var(--ui-text-muted);border-radius:50%}.gb-engine-row[aria-checked=true]{background:var(--gemboss-active-bg, #f0f1f4)}.gb-engine-row[aria-checked=true]:before{border:4.5px solid var(--ui-accent)}.gb-engine-row[aria-checked=true] .gb-engine-rowname{font-weight:600}@media (hover: hover){.gb-engine-row:hover:not(:disabled){background:var(--ui-surface-2)}}.gb-engine-row:focus-visible{outline:2px solid var(--ui-focus);outline-offset:-2px}.gb-engine-row:disabled{cursor:not-allowed}.gb-engine-row:disabled .gb-engine-rowname{color:var(--ui-text-muted)}.gb-engine-rowhead{display:flex;align-items:center;gap:var(--ui-space-2, 8px);min-width:0}.gb-engine-rowname{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:450}.gb-engine-opts{display:flex;flex-wrap:wrap;gap:var(--ui-space-2, 8px)}.gb-engine-opt{height:var(--ui-btn-h, 28px);padding:0 10px;box-sizing:border-box;font:inherit;font-weight:500;color:var(--ui-text);background:transparent;border:1px solid var(--ui-border);border-radius:var(--ui-radius-md, 8px);cursor:pointer}@media (hover: hover){.gb-engine-opt:hover:not(:disabled){background:var(--ui-surface-2)}}.gb-engine-opt[aria-pressed=true]{background:var(--gemboss-active-bg, #f0f1f4);border-color:var(--ui-text);font-weight:600}.gb-engine-opt:focus-visible{outline:2px solid var(--ui-focus);outline-offset:2px}.gb-engine-opt:disabled{opacity:.5;cursor:not-allowed}.gb-engine-select{width:100%}.gb-engine-groups{display:grid;gap:var(--ui-space-3, 12px)}.gb-engine-group{display:grid;gap:6px}.gb-engine-group+.gb-engine-group{padding-top:var(--ui-space-3, 12px);border-top:1px solid var(--ui-border)}.gb-engine-group[data-current] .gb-engine-rowname{font-weight:600}.gb-engine-problem{color:var(--gemboss-danger-strong, #b42318)}.gb-engine-notes{display:grid;gap:4px;color:var(--ui-text-muted)}.gb-engine-notes p{margin:0}.gb-engine-callout{padding:8px 10px;border-radius:var(--ui-radius-md, 8px);border:1px solid}.gb-engine-callout--warn{background:var(--gemboss-warning-soft, #fff8e0);border-color:var(--gemboss-warning-border, #f5d569);color:var(--gemboss-warning, #9a6700)}.gb-engine-callout--down{background:var(--gemboss-danger-soft, #fff0e9);border-color:var(--gemboss-danger-border, #f5c9bc);color:var(--gemboss-danger-strong, #b42318)}.gb-engine-steps ol,.gb-engine-steps ul{margin:0;padding-left:18px;display:grid;gap:4px}.gb-engine-cmd{margin:0;padding:8px 10px;border-radius:var(--ui-radius-md, 8px);background:var(--ui-surface-2);border:1px solid var(--ui-border);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:16px;white-space:pre-wrap;word-break:break-all;user-select:all;max-height:96px;overflow:auto}.gb-engine-cmd code{padding:0;border:0;background:none;font:inherit;color:inherit}.gb-engine-actions{display:flex;flex-wrap:wrap;align-items:center;gap:var(--ui-space-2, 8px)}.gb-engine-said{color:var(--ui-text-muted)}.gb-engine-said:empty{display:none}.gb-engine-code code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-weight:600;letter-spacing:.04em;user-select:all}.gb-engine-rows{display:grid;grid-template-columns:auto 1fr;gap:6px 12px;margin:0}.gb-engine-rows dt{color:var(--ui-text-muted)}.gb-engine-rows dd{margin:0;display:flex;align-items:center;gap:6px;min-width:0;overflow-wrap:anywhere}.gb-engine-settings{display:grid;gap:var(--ui-space-4, 16px);max-width:662px;font-size:var(--ui-fs-body, 13px);line-height:20px}.gb-engine-sect{display:grid;gap:var(--ui-space-3, 12px)}.gb-engine-sect>.ui-card__title{margin:0}.gb-engine-sect p{margin:0}.gb-engine-sect:focus,.gb-engine-sub:focus{outline:none}.gb-engine-sub{display:grid;gap:var(--ui-space-3, 12px);padding-top:var(--ui-space-3, 12px);border-top:1px solid var(--ui-border);scroll-margin-top:var(--ui-space-4, 16px)}.gb-engine-subtitle{margin:0;font-size:inherit;line-height:inherit;font-weight:650}.gb-engine-settings .gb-engine-cmd{max-height:none}.gb-engine-notice{display:grid;grid-template-columns:auto minmax(0,1fr);align-items:start;gap:4px 6px;margin:0;padding:4px 0;font-size:var(--ui-fs-caption, 12px);line-height:16px;color:var(--ui-text-muted)}.gb-engine-notice>.gb-engine-dot{margin-top:4px}.gb-engine-notice>.gb-engine-notice-link{grid-column:2;justify-self:start}.gb-engine-notice--down .gb-engine-notice-text,.gb-engine-notice--warn .gb-engine-notice-text{color:var(--ui-text)}.gb-engine-notice-text{min-width:0;overflow-wrap:anywhere}.gb-engine-notice-link{flex:none;display:inline-flex;align-items:center;min-height:24px;margin:-4px 0 -4px -4px;padding:0 4px;border:0;border-radius:4px;background:none;font:inherit;font-weight:550;color:var(--ui-accent);text-decoration:underline;text-underline-offset:2px;cursor:pointer}.gb-engine-notice-link:focus-visible{outline:2px solid var(--ui-focus);outline-offset:0}@media (pointer: coarse),(max-width: 47.9975em){.gb-engine-chip{min-height:44px}.gb-engine-opt{min-height:44px;min-width:44px}.gb-engine-notice-link{min-height:44px;margin:-14px 0 -14px -8px;padding:0 8px}}@media (prefers-reduced-motion: no-preference){.gb-engine-chip,.gb-engine-opt,.gb-engine-row{transition:background-color .12s ease,color .12s ease}}
1
+ .gb-engine{display:inline-flex;min-width:0;max-width:100%}.gb-engine-chip{display:inline-flex;align-items:center;gap:6px;min-width:0;max-width:100%;box-sizing:border-box;height:var(--ui-btn-h, 28px);padding:0 24px 0 8px;font:inherit;font-size:var(--ui-fs-caption, 12px);font-weight:500;line-height:20px;white-space:nowrap;color:var(--ui-text-muted);background-color:transparent;border:1px solid transparent;border-radius:var(--ui-radius-md, 8px);cursor:pointer;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23686b71' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 8px center}@media (hover: hover){.gb-engine-chip:hover{color:var(--ui-text);background-color:var(--gemboss-hover, rgba(0,0,0,.05))}}@media (hover: none){.gb-engine-chip{color:var(--ui-text)}}.gb-engine-chip:focus-visible{color:var(--ui-text);outline:2px solid var(--ui-focus);outline-offset:2px}.gb-engine-chiplabel{min-width:0;overflow:hidden;text-overflow:ellipsis}.gb-engine-chipsub{font-weight:450}.gb-engine-chip:disabled{cursor:default;opacity:.55}.gemboss-engine-mark{display:block;width:14px;height:14px;flex:0 0 auto}.gb-engine-chipmark{display:none}.gb-engine-chipmark .gemboss-engine-mark{width:16px;height:16px}.gemboss-ec-input:not([data-density=full]) .gb-engine-chipsub{display:none}.gemboss-ec-input:is([data-density=icon],[data-density=tight]) .gb-engine-chip.has-mark .gb-engine-chiplabel{display:none}.gemboss-ec-input:is([data-density=icon],[data-density=tight]) .gb-engine-chip.has-mark .gb-engine-chipmark{display:block}.gemboss-ec-input:is([data-density=icon],[data-density=tight]) .gb-engine:has(.has-mark){flex-shrink:0}.gb-engine-dot{flex:none;display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--ui-text-muted);vertical-align:middle}.gb-engine-dot--ok{background:var(--gemboss-success, #007f5f)}.gb-engine-dot--warn{background:#e8a10a;box-shadow:0 0 0 1px var(--gemboss-warning, #9a6700) inset}.gb-engine-dot--down{background:var(--gemboss-danger, #d72c0d)}.gb-engine-dot--idle{background:transparent;box-shadow:0 0 0 1.5px var(--ui-text-muted) inset}.gb-engine-field{display:grid;gap:6px}.gb-engine-label{font-weight:550;color:var(--ui-text-strong, var(--ui-text))}.gb-engine-note{color:var(--ui-text-muted)}.gb-engine-list{display:grid;border:1px solid var(--ui-border);border-radius:var(--ui-radius-md, 8px);overflow:hidden}.gb-engine-row{display:grid;gap:2px;min-height:44px;padding:6px 10px 6px 32px;box-sizing:border-box;position:relative;font:inherit;text-align:left;color:inherit;background:transparent;border:0;cursor:pointer}.gb-engine-row+.gb-engine-row{border-top:1px solid var(--ui-border)}.gb-engine-row:before{content:"";position:absolute;left:10px;top:50%;width:14px;height:14px;margin-top:-7px;box-sizing:border-box;border:1.5px solid var(--ui-text-muted);border-radius:50%}.gb-engine-row[aria-checked=true]{background:var(--gemboss-active-bg, #f0f1f4)}.gb-engine-row[aria-checked=true]:before{border:4.5px solid var(--ui-accent)}.gb-engine-row[aria-checked=true] .gb-engine-rowname{font-weight:600}@media (hover: hover){.gb-engine-row:hover:not(:disabled){background:var(--ui-surface-2)}}.gb-engine-row:focus-visible{outline:2px solid var(--ui-focus);outline-offset:-2px}.gb-engine-row:disabled{cursor:not-allowed}.gb-engine-row:disabled .gb-engine-rowname{color:var(--ui-text-muted)}.gb-engine-rowhead{display:flex;align-items:center;gap:var(--ui-space-2, 8px);min-width:0}.gb-engine-rowname{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:450}.gb-engine-opts{display:flex;flex-wrap:wrap;gap:var(--ui-space-2, 8px)}.gb-engine-opt{height:var(--ui-btn-h, 28px);padding:0 10px;box-sizing:border-box;font:inherit;font-weight:500;color:var(--ui-text);background:transparent;border:1px solid var(--ui-border);border-radius:var(--ui-radius-md, 8px);cursor:pointer}@media (hover: hover){.gb-engine-opt:hover:not(:disabled){background:var(--ui-surface-2)}}.gb-engine-opt[aria-pressed=true]{background:var(--gemboss-active-bg, #f0f1f4);border-color:var(--ui-text);font-weight:600}.gb-engine-opt:focus-visible{outline:2px solid var(--ui-focus);outline-offset:2px}.gb-engine-opt:disabled{opacity:.5;cursor:not-allowed}.gb-engine-select{width:100%}.gb-engine-groups{display:grid;gap:var(--ui-space-3, 12px)}.gb-engine-group{display:grid;gap:6px}.gb-engine-group+.gb-engine-group{padding-top:var(--ui-space-3, 12px);border-top:1px solid var(--ui-border)}.gb-engine-group[data-current] .gb-engine-rowname{font-weight:600}.gb-engine-problem{color:var(--gemboss-danger-strong, #b42318)}.gb-engine-notes{display:grid;gap:4px;color:var(--ui-text-muted)}.gb-engine-notes p{margin:0}.gb-engine-callout{padding:8px 10px;border-radius:var(--ui-radius-md, 8px);border:1px solid}.gb-engine-callout--warn{background:var(--gemboss-warning-soft, #fff8e0);border-color:var(--gemboss-warning-border, #f5d569);color:var(--gemboss-warning, #9a6700)}.gb-engine-callout--down{background:var(--gemboss-danger-soft, #fff0e9);border-color:var(--gemboss-danger-border, #f5c9bc);color:var(--gemboss-danger-strong, #b42318)}.gb-engine-steps ol,.gb-engine-steps ul{margin:0;padding-left:18px;display:grid;gap:4px}.gb-engine-cmd{margin:0;padding:8px 10px;border-radius:var(--ui-radius-md, 8px);background:var(--ui-surface-2);border:1px solid var(--ui-border);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:16px;white-space:pre-wrap;word-break:break-all;user-select:all}.gb-engine-cmd code{padding:0;border:0;background:none;font:inherit;color:inherit}.gb-engine-actions{display:flex;flex-wrap:wrap;align-items:center;gap:var(--ui-space-2, 8px)}.gb-engine-said{color:var(--ui-text-muted)}.gb-engine-said:empty{display:none}.gb-engine-code code{padding:0;border:0;background:none;color:inherit;font-size:inherit;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-weight:600;letter-spacing:.04em;user-select:all}.gb-engine-rows{display:grid;grid-template-columns:auto 1fr;gap:6px 12px;margin:0}.gb-engine-rows dt{color:var(--ui-text-muted)}.gb-engine-rows dd{margin:0;display:flex;align-items:center;gap:6px;min-width:0;overflow-wrap:anywhere}.gb-engine-settings{display:grid;gap:var(--ui-space-4, 16px);max-width:662px;font-size:var(--ui-fs-body, 13px);line-height:20px}.gb-engine-sect{display:grid;gap:var(--ui-space-3, 12px)}.gb-engine-sect>.ui-card__title{margin:0}.gb-engine-sect p{margin:0}.gb-engine-sect:focus,.gb-engine-sub:focus{outline:none}.gb-engine-sub{display:grid;gap:var(--ui-space-3, 12px);padding-top:var(--ui-space-3, 12px);border-top:1px solid var(--ui-border);scroll-margin-top:var(--ui-space-4, 16px)}.gb-engine-subtitle{margin:0;font-size:inherit;line-height:inherit;font-weight:650}.gb-engine-notice{display:grid;grid-template-columns:auto minmax(0,1fr);align-items:start;gap:4px 6px;margin:0;padding:4px 0;font-size:var(--ui-fs-caption, 12px);line-height:16px;color:var(--ui-text-muted)}.gb-engine-notice>.gb-engine-dot{margin-top:4px}.gb-engine-notice>.gb-engine-notice-link{grid-column:2;justify-self:start}.gb-engine-notice--down .gb-engine-notice-text,.gb-engine-notice--warn .gb-engine-notice-text{color:var(--ui-text)}.gb-engine-notice-text{min-width:0;overflow-wrap:anywhere}.gb-engine-notice-link{flex:none;display:inline-flex;align-items:center;min-height:24px;margin:-4px 0 -4px -4px;padding:0 4px;border:0;border-radius:4px;background:none;font:inherit;font-weight:550;color:var(--ui-accent);text-decoration:underline;text-underline-offset:2px;cursor:pointer}.gb-engine-notice-link:focus-visible{outline:2px solid var(--ui-focus);outline-offset:0}@media (pointer: coarse),(max-width: 47.9975em){.gb-engine-chip{min-height:44px}.gb-engine-opt{min-height:44px;min-width:44px}.gb-engine-notice-link{min-height:44px;margin:-14px 0 -14px -8px;padding:0 8px}}@media (prefers-reduced-motion: no-preference){.gb-engine-chip,.gb-engine-opt,.gb-engine-row{transition:background-color .12s ease,color .12s ease}}
package/src/dialog.tsx CHANGED
@@ -14,7 +14,9 @@
14
14
  * to the right edge: it renders `Dialog` and brings sheet.css, so the markup and the behaviour each have one owner.
15
15
  */
16
16
  import React, { useEffect, useId, useRef } from "react";
17
+ import { flushSync } from "react-dom";
17
18
  import { Icon } from "./icons";
19
+ import { consumeEscape } from "./escape";
18
20
 
19
21
  const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
20
22
 
@@ -34,6 +36,24 @@ const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean)
34
36
  * leave the screen as they act, and focusing them does nothing). SettingsDialog's default is `[data-settings-trigger]`.
35
37
  * - The page behind holds still while any kit popup is modal: `html:has(dialog.ui-modal:modal)` (kit-plain.css).
36
38
  */
39
+ // The control a press last landed on (24/10/2026). Polaris' buttons blur themselves on mouseup (UnstyledButton's
40
+ // handleMouseUpByBlurring), so a popup opened by a click on one found <body> focused and gave the focus back to <body> on Escape:
41
+ // the catalogue picker's Change, and any Polaris button that opens a kit popup. Read only when the focus is on <body> as it opens,
42
+ // and only a press of the last 2 s still in the page; an opener that kept its focus (a key press, a kit button) is unchanged.
43
+ let lastPressed: { el: Element; at: number } | null = null;
44
+ if (typeof document !== "undefined") {
45
+ document.addEventListener("pointerdown", (e) => {
46
+ const el = (e.target as Element | null)?.closest?.("button, a[href], [role=button], input, select, textarea, [tabindex]");
47
+ // A press on something that takes no focus (a row with a click handler) forgets the last one: it opened what opens next.
48
+ lastPressed = el ? { el, at: Date.now() } : null;
49
+ }, true);
50
+ }
51
+ const openerNow = (): Element | null => {
52
+ const a = document.activeElement;
53
+ if (a && a !== document.body) return a;
54
+ return lastPressed && lastPressed.el.isConnected && Date.now() - lastPressed.at < 2000 ? lastPressed.el : a;
55
+ };
56
+
37
57
  export function useModalDialog(open: boolean, onClose: () => void, { focusPanel = false, returnFocusTo }: { focusPanel?: boolean; returnFocusTo?: string } = {}) {
38
58
  const ref = useRef<HTMLDialogElement>(null);
39
59
  const opener = useRef<Element | null>(null);
@@ -52,7 +72,7 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
52
72
  const d = ref.current;
53
73
  if (!d) return;
54
74
  if (open && !d.open) {
55
- opener.current = document.activeElement;
75
+ opener.current = openerNow();
56
76
  d.showModal();
57
77
  shown.current = true;
58
78
  if (focusPanel) d.focus({ preventScroll: true });
@@ -65,7 +85,9 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
65
85
  if (!d) return undefined;
66
86
  const onNativeClose = () => {
67
87
  shown.current = false;
68
- close.current();
88
+ // What closing changes is on the page before the focus goes back: a picker's typed handle, saved as it closes, replaces its
89
+ // "Choose a product" with the chosen row, and the focus went to that button an instant before it left (measured, 24/10/2026).
90
+ flushSync(() => close.current());
69
91
  giveFocusBack();
70
92
  };
71
93
  d.addEventListener("close", onNativeClose);
@@ -99,15 +121,22 @@ export interface DialogProps {
99
121
  className?: string;
100
122
  /** On open, focus the popup itself rather than its first control (Sheet does). */
101
123
  focusPanel?: boolean;
124
+ /** A selector focused on close when what opened it is gone by then (useModalDialog's `returnFocusTo`): a picker's first pick
125
+ * replaces its "Choose" with the chosen row's Change. */
126
+ returnFocusTo?: string;
102
127
  }
103
128
 
104
- export function Dialog({ open, onClose, title, subtitle, actions, children, footer, wide = false, closeLabel = "Close", className, focusPanel = false }: DialogProps) {
105
- const { ref, onClick, onPointerDown } = useModalDialog(open, onClose, { focusPanel });
129
+ export function Dialog({ open, onClose, title, subtitle, actions, children, footer, wide = false, closeLabel = "Close", className, focusPanel = false, returnFocusTo }: DialogProps) {
130
+ const { ref, onClick, onPointerDown } = useModalDialog(open, onClose, { focusPanel, returnFocusTo });
106
131
  const titleId = useId();
107
132
  const subId = useId();
108
133
  return (
109
134
  <dialog ref={ref} className={cx("ui-modal", wide && "ui-modal--wide", className)} aria-labelledby={titleId}
110
- aria-describedby={subtitle ? subId : undefined} tabIndex={focusPanel ? -1 : undefined} onClick={onClick} onPointerDown={onPointerDown}>
135
+ aria-describedby={subtitle ? subId : undefined} tabIndex={focusPanel ? -1 : undefined} onClick={onClick} onPointerDown={onPointerDown}
136
+ // Its Escape closes it and only it, as the kit's Popover: the browser closes the <dialog>, and neither the keydown nor the keyup
137
+ // goes further out, where a Polaris Modal it was opened from closed as well (on the keyup; escape.ts). A box that clears its
138
+ // words on Escape (PickerList's) consumes the key before it gets here.
139
+ onKeyDown={(e) => { if (e.key === "Escape" && !e.nativeEvent.isComposing) consumeEscape(e); }}>
111
140
  <div className="ui-modal__head">
112
141
  {subtitle
113
142
  ? <div className="ui-modal__title"><span id={titleId}>{title}</span><span className="ui-modal__subtitle" id={subId}>{subtitle}</span></div>
@@ -13,6 +13,7 @@ import "../editor-picker-grid.css";
13
13
  import React, { useEffect, useId, useRef, useState } from "react";
14
14
  import { Icon } from "../icons";
15
15
  import { PickNothing, PickSearch, typesFirst, usePickHighlight, type PickerSearch } from "./picker";
16
+ import { consumeEscape } from "../escape";
16
17
 
17
18
  export interface PickerTile {
18
19
  /** What `onSelect` / `onActivate` get, and what `selected` is compared with. */
@@ -97,6 +98,8 @@ export function PickerGrid({ label, tiles, selected = null, onSelect, onActivate
97
98
  if (use && onActivate) onActivate(t!.key); else onSelect(t!.key);
98
99
  };
99
100
  const clear = () => { search?.onChange(""); boxRef.current?.focus(); };
101
+ // Try again leaves with the error it sat in: the focus goes back to the box, not to <body> (24/10/2026, the placement picker).
102
+ const retry = error?.onRetry ? { ...error, onRetry: () => { error.onRetry!(); boxRef.current?.focus(); } } : error;
100
103
  // As PickerList: `search.autoFocus`, the box takes the focus once, as the grid appears.
101
104
  useEffect(() => { if (typesFirst(search)) boxRef.current?.focus(); }, []); // eslint-disable-line react-hooks/exhaustive-deps
102
105
  const keyDown = (e: React.KeyboardEvent, fromBox: boolean) => {
@@ -113,7 +116,7 @@ export function PickerGrid({ label, tiles, selected = null, onSelect, onActivate
113
116
  else if (grid && e.key === "End") go("last");
114
117
  else if (e.key === "Enter") { if (shown.length) e.preventDefault(); choose(shown[active], true); }
115
118
  else if (!fromBox && e.key === " ") { e.preventDefault(); choose(shown[active], false); }
116
- else if (fromBox && e.key === "Escape" && query) { e.preventDefault(); e.stopPropagation(); clear(); }
119
+ else if (fromBox && e.key === "Escape" && query) { e.preventDefault(); consumeEscape(e); clear(); }
117
120
  };
118
121
  // The uploads in flight, said aloud from outside the grid (below).
119
122
  const sending = tiles.filter((t) => t.status?.busy).map((t) => t.title);
@@ -126,7 +129,7 @@ export function PickerGrid({ label, tiles, selected = null, onSelect, onActivate
126
129
  <div className="gemboss-ei-pick">
127
130
  {search ? <PickSearch search={search} boxRef={boxRef} listId={listId} hasList={hasTiles} activeId={activeId} onKeyDown={(e) => keyDown(e, true)} onClear={clear} /> : null}
128
131
  {phase === "loading" || phase === "error" || !hasTiles ? (
129
- <PickNothing phase={phase === "loading" ? "loading" : phase === "error" ? "error" : "empty"} error={error} empty={empty} query={query} onClear={clear}
132
+ <PickNothing phase={phase === "loading" ? "loading" : phase === "error" ? "error" : "empty"} error={retry} empty={empty} query={query} onClear={clear}
130
133
  skeleton={
131
134
  <div className={`gemboss-ei-pickgrid${size === "icon" ? " is-icon" : ""}`} role="status" aria-label="Loading">
132
135
  {Array.from({ length: loadingTiles }, (_, i) => (
@@ -24,6 +24,7 @@
24
24
  import "../editor-picker.css";
25
25
  import React, { useEffect, useId, useMemo, useRef, useState } from "react";
26
26
  import { Icon, type IconName } from "../icons";
27
+ import { consumeEscape } from "../escape";
27
28
 
28
29
  export type PickerTone = "neutral" | "info" | "success" | "warning" | "critical";
29
30
 
@@ -188,6 +189,8 @@ export function PickerList({ label, items, current = null, onPick, search, state
188
189
  highlight(shown[pickable[next]!]!.key, "keys");
189
190
  };
190
191
  const clear = () => { search?.onChange(""); boxRef.current?.focus(); };
192
+ // Try again leaves with the error it sat in: the focus goes back to the box, not to <body> (24/10/2026, the placement picker).
193
+ const retry = error?.onRetry ? { ...error, onRetry: () => { error.onRetry!(); boxRef.current?.focus(); } } : error;
191
194
  // The box carries `data-autofocus`, which the kit's Dialog and Popover focus as they open; this covers a list that appears in a
192
195
  // container already open (a drill-down's new list). Once, as the list appears.
193
196
  useEffect(() => { if (typesFirst(search)) boxRef.current?.focus(); }, []); // eslint-disable-line react-hooks/exhaustive-deps
@@ -201,7 +204,7 @@ export function PickerList({ label, items, current = null, onPick, search, state
201
204
  // Reloading: the rows answer another search; Enter waits for this one (nothing is written).
202
205
  if (shown.length) e.preventDefault();
203
206
  pick(shown[active]);
204
- } else if (fromBox && e.key === "Escape" && query) { e.preventDefault(); e.stopPropagation(); clear(); }
207
+ } else if (fromBox && e.key === "Escape" && query) { e.preventDefault(); consumeEscape(e); clear(); }
205
208
  };
206
209
 
207
210
  const listId = `${base}-list`;
@@ -213,7 +216,7 @@ export function PickerList({ label, items, current = null, onPick, search, state
213
216
  {search ? <PickSearch search={search} boxRef={boxRef} listId={listId} hasList={hasList} activeId={activeId} onKeyDown={(e) => keyDown(e, true)} onClear={clear} /> : null}
214
217
 
215
218
  {phase === "loading" || phase === "error" || !hasList ? (
216
- <PickNothing phase={phase === "loading" ? "loading" : phase === "error" ? "error" : "empty"} error={error} empty={empty} query={query} onClear={clear}
219
+ <PickNothing phase={phase === "loading" ? "loading" : phase === "error" ? "error" : "empty"} error={retry} empty={empty} query={query} onClear={clear}
217
220
  skeleton={
218
221
  <div className="gemboss-ei-pick-skeleton" role="status" aria-label="Loading">
219
222
  {Array.from({ length: loadingRows }, (_, i) => (
@@ -20,6 +20,7 @@ import React, { useEffect, useId, useLayoutEffect, useRef } from "react";
20
20
  import { createPortal } from "react-dom";
21
21
  import { Icon } from "../icons";
22
22
  import { canFloatMenus, placeFloating } from "../menu-layer";
23
+ import { consumeEscape } from "../escape";
23
24
 
24
25
  export interface PopoverProps {
25
26
  open: boolean;
@@ -147,7 +148,7 @@ export function Popover({ open, anchor, returnTo, onClose, title, onBack, childr
147
148
  if (!open) return null;
148
149
  const layer = (
149
150
  <div ref={ref} className={`gemboss-ei-pop gemboss-popover-surface${floating ? "" : " gemboss-ei-pop--inline"}`} role="dialog" aria-labelledby={titleId}
150
- tabIndex={-1} onKeyDown={(e) => { if (e.key === "Escape" && !e.nativeEvent.isComposing) { e.preventDefault(); e.stopPropagation(); if (onBack) back(); else shut(); } }}>
151
+ tabIndex={-1} onKeyDown={(e) => { if (e.key === "Escape" && !e.nativeEvent.isComposing) { e.preventDefault(); consumeEscape(e); if (onBack) back(); else shut(); } }}>
151
152
  <div className="gemboss-ei-pop-head">
152
153
  {onBack ? <button type="button" className="gemboss-ei-pop-btn" aria-label="Back" onClick={back}><Icon name="chevronLeft" size={16} /></button> : null}
153
154
  <span className="gemboss-ei-pop-title" id={titleId}>{title}</span>
@@ -1 +1 @@
1
- (function(j){"use strict";var A=j.gembossUI;if(!A){j.console&&j.console.error("@gemboss/ui engine-plain.js: load kit-plain.js first (it defines gembossUI)");return}if(A.enginePicker)return;var ce={chip:"Engine",dialog:"Assistant engine",tabs:"Engine, setup and status",engineTab:"Engine",setupTab:"Setup",statusTab:"Status",engine:"Engine",model:"Model",effort:"Effort",defaultChoice:"Default",copy:"Copy command",copied:"Copied",copyFailed:"Select the command and copy it",pairingCode:"Pairing code",steps:"Paste the command into Terminal, then press Enter.",bridge:"Bridge on your machine",version:"Version",latest:"Latest",startsAtSignIn:"Starts at sign-in",machine:"Machine",lastSeen:"Last seen",yes:"Yes",no:"No",unknown:"Not known",running:"Running",outdated:"Outdated",offline:"Not connected",unpaired:"Not set up",checking:"Checking",updateDue:"Update available",close:"Close",state:"State",setupTitle:"Install or update"},J={running:"ok",outdated:"warn",offline:"down",unpaired:"down",checking:"idle"},M={ok:"gb-engine-dot gb-engine-dot--ok",warn:"gb-engine-dot gb-engine-dot--warn",down:"gb-engine-dot gb-engine-dot--down",idle:"gb-engine-dot gb-engine-dot--idle"},ge={success:"ui-badge ui-badge--success",warning:"ui-badge ui-badge--warning",critical:"ui-badge ui-badge--critical",info:"ui-badge ui-badge--info"},fe={warn:"gb-engine-notice gb-engine-notice--warn",down:"gb-engine-notice gb-engine-notice--down"},be=["notes","modelControl","statusActions"],Q=function(o){return o&&A.engineMark?A.engineMark(o,{decorative:!0}):null},H=typeof HTMLElement<"u"&&Object.prototype.hasOwnProperty.call(HTMLElement.prototype,"popover"),q=function(o){return typeof Node<"u"&&o instanceof Node},pe=0;function r(o,c,t){var u=document.createElement(o);if(c)for(var s in c){var g=c[s];g==null||g===!1||(s==="text"?u.textContent=String(g):s==="className"?u.className=g:u.setAttribute(s,g===!0?"":String(g)))}return W(u,t),u}function W(o,c){return c==null||c===!1?o:Array.isArray(c)?(c.forEach(function(t){W(o,t)}),o):(o.appendChild(q(c)?c:document.createTextNode(String(c))),o)}function O(o){return typeof DocumentFragment<"u"&&o instanceof DocumentFragment?Array.prototype.slice.call(o.childNodes):o}var me=function(o){return q(o)||Array.isArray(o)&&o.some(q)};function k(o,c){for(var t=Array.prototype.slice.call(c.childNodes),u=0;u<t.length;u++){var s=t[u],g=o.childNodes[u];g?g.nodeType===s.nodeType&&(g.nodeType!==1||g.tagName===s.tagName&&g.getAttribute("data-gb-key")===s.getAttribute("data-gb-key"))?he(g,s):o.replaceChild(s,g):o.appendChild(s)}for(;o.childNodes.length>t.length;)o.removeChild(o.lastChild)}function he(o,c){if(o.nodeType!==1){o.nodeValue!==c.nodeValue&&(o.nodeValue=c.nodeValue);return}var t,u;for(t=o.attributes.length-1;t>=0;t--)u=o.attributes[t].name,u!=="style"&&!c.hasAttribute(u)&&o.removeAttribute(u);for(t=0;t<c.attributes.length;t++)u=c.attributes[t],o.getAttribute(u.name)!==u.value&&o.setAttribute(u.name,u.value);o.hasAttribute("data-gb-slot")||(k(o,c),o.tagName==="SELECT"&&o.value!==c.getAttribute("data-value")&&(o.value=c.getAttribute("data-value")||""))}function ve(o){var c=function(){try{var t=document.createElement("textarea");t.value=o,t.setAttribute("readonly",""),t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();var u=document.execCommand("copy");return t.remove(),u}catch{return!1}};try{if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(o).then(function(){return!0},c)}catch{}return Promise.resolve(c())}function ye(o,c){var t={},u="gb-engine-"+ ++pe,s={open:!1,tab:"engine",said:"",saidTimer:0,focus:null},g=null,l=Object.assign({},ce),V={};function X(n){Object.keys(n||{}).forEach(function(e){var a=n[e];if((e==="bridge"||e==="setup")&&a&&typeof a=="object"&&t[e]&&typeof t[e]=="object"&&(a=Object.assign({},t[e],a)),e==="labels"){l=Object.assign({},l,a||{});return}be.indexOf(e)>=0&&(a=O(a)),e==="engines"&&Array.isArray(a)&&(a=a.map(function(i){return i&&i.note?Object.assign({},i,{note:O(i.note)}):i})),e==="setup"&&a&&a.steps&&(a=Object.assign({},a,{steps:O(a.steps)})),e==="bridge"&&a&&a.detail&&(a=Object.assign({},a,{detail:O(a.detail)})),t[e]=a})}X(c);var S=document.createElement("span");S.className="gb-engine"+(t.className?" "+t.className:"");var m=r("button",{type:"button",className:"gb-engine-chip","aria-haspopup":"dialog","aria-expanded":t.onOpenSettings?null:"false","aria-controls":t.onOpenSettings?null:u+"-panel"}),d=r("div",{id:u+"-panel",className:"gb-engine-panel gemboss-popover-surface",role:"dialog","aria-label":l.dialog,hidden:!0});H&&d.setAttribute("popover","manual"),S.appendChild(m),H?S.appendChild(d):document.body.appendChild(d),o.appendChild(S);function R(){return["engine"].concat(t.setup?["setup"]:[],t.bridge?["status"]:[])}function U(){return R().indexOf(s.tab)>=0?s.tab:"engine"}function w(n,e){return me(e)?(V[n]=Array.isArray(e)?e.filter(q):[e],r("span",{"data-gb-slot":n,"data-gb-key":"slot-"+n,style:"display:contents"})):e}function Z(n){n.querySelectorAll("[data-gb-slot]").forEach(function(e){var a=V[e.getAttribute("data-gb-slot")]||[],i=Array.prototype.slice.call(e.childNodes);i.length===a.length&&i.every(function(b,f){return b===a[f]})||e.replaceChildren.apply(e,a)})}function Ce(){var n=t.bridge&&t.showBridgeDot!==!1?J[t.bridge.state]:null,e=(t.engines||[]).filter(function(b){return b.id===t.engine})[0],a=t.model?(t.models||[]).filter(function(b){return b.id===t.model})[0]:null,i=e?Q(e.mark):null;return r("span",null,[n?r("span",{className:M[n],"aria-hidden":"true"}):null,r("span",{className:"gb-engine-chiplabel"},[e?e.label:t.engine||"",a?r("span",{className:"gb-engine-chipsub",text:" \xB7 "+a.label}):null]),i?r("span",{className:"gb-engine-chipmark"},i):null])}function Ae(){var n=(t.engines||[]).filter(function(i){return i.id===t.engine})[0],e=t.model?(t.models||[]).filter(function(i){return i.id===t.model})[0]:null,a=t.bridge&&t.showBridgeDot!==!1&&t.bridge.state!=="running"?". "+l.bridge+": "+l[t.bridge.state]:"";return l.chip+": "+(n?n.label:t.engine)+(e?" \xB7 "+e.label:"")+a}function $(n,e,a,i,b,f){var h=t.locked||!b||!!f,y=typeof f=="string"?f:void 0;if(a.length>6||a.some(function(p){return p.group})){var P=r("select",{className:"ui-select ui-select--slim gb-engine-select",disabled:h,title:y,"data-kind":n,"data-value":i||""}),C=null,E;return a.forEach(function(p){var de=r("option",{value:p.id,title:p.title,text:p.label,selected:(i||"")===p.id});p.group?((!C||E!==p.group)&&(C=r("optgroup",{label:p.group}),E=p.group,P.appendChild(C)),C.appendChild(de)):(C=null,E=void 0,P.appendChild(de))}),r("label",{className:"gb-engine-field","data-gb-key":n},[r("span",{className:"gb-engine-label",text:e}),P])}var B=u+"-lbl-"+n;return r("div",{className:"gb-engine-field","data-gb-key":n},[r("span",{className:"gb-engine-label",id:B,text:e}),r("div",{className:"gb-engine-opts",role:"group","aria-labelledby":B},a.map(function(p){return r("button",{type:"button",className:"gb-engine-opt","aria-pressed":String((i||"")===p.id),disabled:h,title:y||p.title,text:p.label,"data-kind":n,"data-choice":p.id})}))])}function F(n){return!(t.locked||n.disabled||!t.onEngineChange)}function ee(n){var e=n||u+"-lbl-engine",a=t.engines||[],i=(a.filter(function(f){return f.id===t.engine&&F(f)})[0]||a.filter(F)[0]||{}).id,b=[r("div",{className:"gb-engine-field","data-gb-key":"engine"},[n?null:r("span",{className:"gb-engine-label",id:e,text:l.engine}),r("div",{className:"gb-engine-list",role:"radiogroup","aria-labelledby":e},a.map(function(f){return r("button",{type:"button",role:"radio","aria-checked":String(f.id===t.engine),"data-engine":f.id,"data-gb-key":"engine-"+f.id,tabindex:f.id===i?"0":"-1",className:"gb-engine-row",disabled:!F(f)},[r("span",{className:"gb-engine-rowhead"},[r("span",{className:"gb-engine-rowname",text:f.label}),f.badge?r("span",{className:f.badgeTone?ge[f.badgeTone]:"ui-badge",text:f.badge}):null]),f.note?r("span",{className:"gb-engine-note"},w("note-"+f.id,f.note)):null])}))])];return t.modelControl?b.push(r("div",{className:"gb-engine-field","data-gb-key":"model"},[r("span",{className:"gb-engine-label",text:l.model}),w("modelControl",t.modelControl)])):t.models&&t.models.length&&b.push($("model",l.model,t.models,t.model,t.onModelChange)),t.efforts&&t.efforts.length&&b.push($("effort",l.effort,t.efforts,t.effort,t.onEffortChange,t.effortDisabled)),t.notes&&b.push(r("div",{className:"gb-engine-notes"},w("notes",t.notes))),b}function ne(){var n=t.bridge;return!!n&&(n.state==="outdated"||n.state==="offline"||n.state==="unpaired")}function te(){var n=t.bridge;return ne()?r("p",{className:"gb-engine-callout "+(n.state==="outdated"?"gb-engine-callout--warn":"gb-engine-callout--down"),"data-gb-key":"callout"},[r("strong",{text:l.bridge+": "+l[n.state].toLowerCase()+"."}),n.detail?" ":null,n.detail?w("detail",n.detail):null]):null}function ae(n){var e=t.setup||{},a=[],i=n?null:te();return i&&a.push(i),(e.steps||e.command)&&a.push(r("div",{className:"gb-engine-steps"},e.steps?w("steps",e.steps):r("p",{text:l.steps}))),e.command&&(a.push(r("pre",{className:"gb-engine-cmd"},r("code",{text:e.command}))),a.push(r("div",{className:"gb-engine-actions"},[r("button",{type:"button",className:"ui-btn ui-btn--primary","data-gb-copy":"",text:s.said==="copied"?l.copied:l.copy}),r("span",{className:"gb-engine-said",role:"status",text:s.said==="failed"?l.copyFailed:s.said==="copied"?l.copied:""})]))),e.pairingCode&&a.push(r("p",{className:"gb-engine-code"},[l.pairingCode+": ",r("code",{text:e.pairingCode})])),e.note&&a.push(r("p",{className:"gb-engine-note"},e.note)),a}function ie(n){var e=t.bridge,a=r("dl",{className:"gb-engine-rows"}),i=function(h,y){a.appendChild(r("dt",{text:h})),a.appendChild(r("dd",null,y))},b=function(h){return h==null?l.unknown:h?l.yes:l.no};i(n?l.state:l.bridge,[r("span",{className:M[J[e.state]],"aria-hidden":"true"})," "+l[e.state]]),e.version&&i(l.version,e.version+(e.latest&&e.latest!==e.version?" \xB7 "+l.latest+" "+e.latest:"")),i(l.startsAtSignIn,b(e.autostart)),e.machine&&i(l.machine,e.machine),e.lastSeen&&i(l.lastSeen,e.lastSeen);var f=[a];return e.detail&&e.state!=="running"&&!(n&&ne())&&f.push(r("p",{className:"gb-engine-note"},w("detail",e.detail))),t.statusActions&&f.push(r("div",{className:"gb-engine-actions"},w("statusActions",t.statusActions))),f}function we(){var n=R(),e=U(),a=document.createElement("div");return n.length>1&&a.appendChild(r("div",{className:"ui-tabs gb-engine-tabs",role:"tablist","aria-label":l.tabs,"data-gb-key":"tabs"},n.map(function(i){return r("button",{type:"button",role:"tab",id:u+"-tab-"+i,"aria-controls":u+"-pane-"+i,"aria-selected":String(e===i),tabindex:e===i?"0":"-1","data-tab":i,"data-gb-key":"tab-"+i},[{engine:l.engineTab,setup:l.setupTab,status:l.statusTab}[i],i==="setup"&&t.bridge&&t.bridge.state==="outdated"?r("span",{className:"gb-engine-dot gb-engine-dot--warn",role:"img","aria-label":l.updateDue}):null])}))),a.appendChild(r("div",{className:"gb-engine-pane",role:n.length>1?"tabpanel":null,id:u+"-pane-"+e,"aria-labelledby":n.length>1?u+"-tab-"+e:null,"data-gb-key":"pane-"+e},e==="engine"?ee():e==="setup"?ae():ie())),a}function Te(){var n=document.createElement("div"),e=u+"-s-engine",a=u+"-s-bridge",i=u+"-s-setup";if(n.appendChild(r("section",{className:"ui-card gb-engine-sect","data-gb-part":"engine","aria-labelledby":e,"data-gb-key":"s-engine"},[r("h3",{className:"ui-card__title",id:e,text:l.engine})].concat(ee(e)))),t.bridge||t.setup){var b=[r("h3",{className:"ui-card__title",id:a,text:l.bridge}),te()];t.bridge&&(b=b.concat(ie(!0))),t.setup&&b.push(r("div",{className:"gb-engine-sub","data-gb-part":"setup",role:"group","aria-labelledby":i,tabindex:"-1","data-gb-key":"s-setup"},[r("h4",{className:"gb-engine-subtitle",id:i,text:l.setupTitle})].concat(ae(!0)))),n.appendChild(r("section",{className:"ui-card gb-engine-sect","data-gb-part":"bridge","aria-labelledby":a,tabindex:"-1","data-gb-key":"s-bridge"},b))}return n}var D=null;function v(){var n=Ae();m.setAttribute("aria-label",n),m.title=n,t.onOpenSettings||m.setAttribute("aria-expanded",s.open?"true":"false");var e=(t.engines||[]).filter(function(i){return i.id===t.engine})[0];if(m.className=e&&Q(e.mark)?"gb-engine-chip has-mark":"gb-engine-chip",k(m,Ce()),d.setAttribute("aria-label",l.dialog),V={},g&&(k(g,Te()),Z(g)),!s.open){k(d,document.createElement("div"));return}k(d,we()),Z(d);var a=d.querySelector(".gb-engine-pane");T&&a!==D&&(D&&T.unobserve(D),a&&T.observe(a),D=a)}function x(){s.open&&A.placeFloating(d,m,t.end)}function re(n){n!==t.engine&&(t.engine=n,t.onEngineChange&&t.onEngineChange(n),v())}function oe(n,e,a){var i=n==="model"?t.model:t.effort,b=n==="model"?t.onModelChange:t.onEffortChange;!b||t.locked||((i||"")!==e&&(n==="model"?t.model=e:t.effort=e,b(e)),a?le():v())}function se(n,e){if(n!==U()&&(s.tab=n,t.onTabChange&&t.onTabChange(n),v(),x()),e){var a=d.querySelector('[role="tab"][data-tab="'+n+'"]');a&&a.focus()}}function Se(n){var e=n.currentTarget,a=n.target.closest?n.target:n.target.parentElement,i=a&&a.closest("button");!i||!e.contains(i)||i.disabled||(i.hasAttribute("data-tab")?se(i.getAttribute("data-tab")):i.hasAttribute("data-engine")?re(i.getAttribute("data-engine")):i.hasAttribute("data-choice")?oe(i.getAttribute("data-kind"),i.getAttribute("data-choice"),e===d):i.hasAttribute("data-gb-copy")&&Oe())}function xe(n){var e=n.target;e&&e.tagName==="SELECT"&&e.hasAttribute("data-kind")&&n.currentTarget.contains(e)&&oe(e.getAttribute("data-kind"),e.value,!1)}function Ee(n){var e=n.currentTarget,a=n.target;if(!(!a||!a.getAttribute)){if(a.getAttribute("role")==="tab"){var i=R(),b=i.indexOf(U()),f=n.key==="ArrowRight"?i[(b+1)%i.length]:n.key==="ArrowLeft"?i[(b-1+i.length)%i.length]:n.key==="Home"?i[0]:n.key==="End"?i[i.length-1]:null;if(!f)return;n.preventDefault(),se(f,!0)}else if(a.hasAttribute("data-engine")){var h=n.key==="ArrowDown"||n.key==="ArrowRight"?1:n.key==="ArrowUp"||n.key==="ArrowLeft"?-1:0,y=(t.engines||[]).filter(F);if(!h||!y.length)return;n.preventDefault();var P=y.map(function(B){return B.id}).indexOf(a.getAttribute("data-engine")),C=y[(P+h+y.length)%y.length];re(C.id);var E=e.querySelector('[data-engine="'+(j.CSS&&CSS.escape?CSS.escape(C.id):C.id)+'"]');E&&E.focus()}}}function _(n,e){var a=e?"addEventListener":"removeEventListener";n[a]("click",Se),n[a]("change",xe),n[a]("keydown",Ee)}_(d,!0);function Oe(){var n=t.setup||{};n.command&&ve(n.command).then(function(e){s.said=e?"copied":"failed",v(),clearTimeout(s.saidTimer),s.saidTimer=setTimeout(function(){s.said="",v()},2e3)})}var z=-1,L=0,T=typeof ResizeObserver>"u"?null:new ResizeObserver(function(){d.scrollHeight!==z&&(z=d.scrollHeight,x())});function ke(n){if(!(n.key!=="Escape"||n.defaultPrevented||!s.open)&&!(n.isComposing||n.keyCode===229)){var e=document.activeElement,a=e&&e.closest?e.closest('dialog[open], [aria-modal="true"]'):null;a&&!d.contains(a)||(n.preventDefault(),e&&(d.contains(e)||m.contains(e))?(n.stopPropagation(),le()):N(!1))}}function De(n){var e=n.target,a=e&&e.closest?e.closest('dialog[open], [aria-modal="true"]'):null;a&&!d.contains(a)&&N(!1)}function Le(n){var e=n.target;d.contains(e)||m.contains(e)||e&&e.closest&&e.closest('dialog[open], [aria-modal="true"], .ui-overlay')||N(!1)}function Ie(n){var e=n.target;!e||d.contains(e)||e!==document&&e.nodeType!==9&&!e.contains(m)||L||(L=requestAnimationFrame(function(){L=0,x()}))}function Pe(n){var e=n?"addEventListener":"removeEventListener";document[e]("keydown",ke,!0),document[e]("pointerdown",Le,!0),document[e]("focusin",De,!0),document[e]("scroll",Ie,!0),window[e]("resize",x),n?T&&T.observe(d):(cancelAnimationFrame(L),L=0,T&&T.disconnect(),D=null,z=-1)}function N(n){if(n!==s.open){if(s.open=n,n||(s.tab="engine"),d.hidden=!n,n?d.setAttribute("data-open",""):d.removeAttribute("data-open"),H&&(n&&!d.matches(":popover-open")&&d.showPopover(),!n&&d.matches(":popover-open")&&d.hidePopover()),Pe(n),v(),x(),n){var e=d.querySelector('[role="tab"][aria-selected="true"]')||d.querySelector("button:not([disabled])");e&&e.focus()}t.onOpenChange&&t.onOpenChange(n)}}function le(){N(!1),m.focus()}m.addEventListener("click",function(){if(t.onOpenSettings){s.focus="engine",t.onOpenSettings("engine");return}N(!s.open)});function ue(){var n=s.focus;if(s.focus=null,!(!g||!n||n==="engine")){var e=g.querySelector('[data-gb-part="'+(n==="status"?"bridge":n)+'"]');e&&requestAnimationFrame(function(){e.scrollIntoView({block:"start"});var a=e.querySelector("button:not([disabled]), select:not([disabled]), input:not([disabled])");(a||e).focus({preventScroll:!0})})}}var K=!1,I=null;function G(n){n!==K&&(K=n,t.onOpenChange&&t.onOpenChange(n))}function je(n){g&&Y(),g=r("div",{className:"gb-engine-settings"}),_(g,!0),n.appendChild(g),v(),ue(),typeof IntersectionObserver>"u"?G(!0):(I=new IntersectionObserver(function(e){G(e[e.length-1].isIntersecting)}),I.observe(g))}function Y(){g&&(I&&(I.disconnect(),I=null),_(g,!1),g.remove(),g=null,G(!1))}return v(),{element:S,panel:d,update:function(n){X(n),v()},openTab:function(n){if(t.onOpenSettings){s.focus=n,t.onOpenSettings(n),g&&ue();return}var e=s.open;if(n!==s.tab&&(s.tab=n,t.onTabChange&&t.onTabChange(n)),!e)N(!0);else{v(),x();var a=d.querySelector('[role="tab"][aria-selected="true"]');a&&a.focus()}},open:function(){N(!0)},close:function(){t.onOpenSettings||N(!1)},isOpen:function(){return t.onOpenSettings?K:s.open},mountSettings:je,unmountSettings:Y,destroy:function(){N(!1),Y(),clearTimeout(s.saidTimer),S.remove(),d.remove()}}}function Ne(o){o=o||{};var c=o.tone==="warn"?"warn":"down",t=r("p",{className:fe[c]+(o.className?" "+o.className:""),role:"status"},[r("span",{className:M[c],"aria-hidden":"true"}),r("span",{className:"gb-engine-notice-text"},O(o.node)||o.text||"")]);if(o.onOpenSetup){var u=r("button",{type:"button",className:"gb-engine-notice-link",text:o.action||"Open setup"});u.addEventListener("click",o.onOpenSetup),t.appendChild(u)}return t}A.enginePicker=ye,A.bridgeNotice=Ne})(typeof globalThis<"u"?globalThis:this);
1
+ (function(v){"use strict";var y=v.gembossUI;if(!y){v.console&&v.console.error("@gemboss/ui engine-plain.js: load kit-plain.js first (it defines gembossUI)");return}if(y.enginePicker)return;var Z={chip:"Engine",engine:"Engine",model:"Model",effort:"Effort",defaultChoice:"Default",copy:"Copy command",copied:"Copied",copyFailed:"Select the command and copy it",pairingCode:"Pairing code",steps:"Paste the command into Terminal, then press Enter.",bridge:"Bridge on your machine",version:"Version",latest:"Latest",startsAtSignIn:"Starts at sign-in",machine:"Machine",lastSeen:"Last seen",yes:"Yes",no:"No",unknown:"Not known",running:"Running",outdated:"Outdated",offline:"Not connected",unpaired:"Not set up",checking:"Checking",state:"State",setupTitle:"Install or update"},M={running:"ok",outdated:"warn",offline:"down",unpaired:"down",checking:"idle"},I={ok:"gb-engine-dot gb-engine-dot--ok",warn:"gb-engine-dot gb-engine-dot--warn",down:"gb-engine-dot gb-engine-dot--down",idle:"gb-engine-dot gb-engine-dot--idle"},$={success:"ui-badge ui-badge--success",warning:"ui-badge ui-badge--warning",critical:"ui-badge ui-badge--critical",info:"ui-badge ui-badge--info"},ee={warn:"gb-engine-notice gb-engine-notice--warn",down:"gb-engine-notice gb-engine-notice--down"},ne=["notes","modelControl","statusActions"],V=function(i){return i&&y.engineMark?y.engineMark(i,{decorative:!0}):null},k=function(i){return typeof Node<"u"&&i instanceof Node},te=0;function r(i,l,n){var d=document.createElement(i);if(l)for(var f in l){var u=l[f];u==null||u===!1||(f==="text"?d.textContent=String(u):f==="className"?d.className=u:d.setAttribute(f,u===!0?"":String(u)))}return _(d,n),d}function _(i,l){return l==null||l===!1?i:Array.isArray(l)?(l.forEach(function(n){_(i,n)}),i):(i.appendChild(k(l)?l:document.createTextNode(String(l))),i)}function C(i){return typeof DocumentFragment<"u"&&i instanceof DocumentFragment?Array.prototype.slice.call(i.childNodes):i}var ie=function(i){return k(i)||Array.isArray(i)&&i.some(k)},B=function(i,l){return i.nodeType===l.nodeType&&(i.nodeType!==1||i.tagName===l.tagName&&i.getAttribute("data-gb-key")===l.getAttribute("data-gb-key"))},U=function(i){return i.nodeType===1?i.getAttribute("data-gb-key"):null};function D(i,l){for(var n=Array.prototype.slice.call(l.childNodes),d=0;d<n.length;d++){var f=n[d],u=i.childNodes[d],s;if(!u){i.appendChild(f);continue}if(B(u,f)){R(u,f);continue}if(U(u)&&n.slice(d+1).some(function(A){return B(u,A)})){i.insertBefore(f,u);continue}if(U(f)){for(s=d+1;s<i.childNodes.length&&!B(i.childNodes[s],f);s++);if(s<i.childNodes.length){for(;s-- >d;)i.removeChild(i.childNodes[d]);R(i.childNodes[d],f);continue}}i.replaceChild(f,u)}for(;i.childNodes.length>n.length;)i.removeChild(i.lastChild)}function R(i,l){if(i.nodeType!==1){i.nodeValue!==l.nodeValue&&(i.nodeValue=l.nodeValue);return}var n,d;for(n=i.attributes.length-1;n>=0;n--)d=i.attributes[n].name,d!=="style"&&!l.hasAttribute(d)&&i.removeAttribute(d);for(n=0;n<l.attributes.length;n++)d=l.attributes[n],i.getAttribute(d.name)!==d.value&&i.setAttribute(d.name,d.value);i.hasAttribute("data-gb-slot")||(D(i,l),i.tagName==="SELECT"&&i.value!==l.getAttribute("data-value")&&(i.value=l.getAttribute("data-value")||""))}function ae(i){var l=function(){try{var n=document.createElement("textarea");n.value=i,n.setAttribute("readonly",""),n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select();var d=document.execCommand("copy");return n.remove(),d}catch{return!1}};try{if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(i).then(function(){return!0},l)}catch{}return Promise.resolve(l())}function re(i,l){var n={},d="gb-engine-"+ ++te,f={said:"",saidTimer:0,focus:null},u=null,s=Object.assign({},Z),A={};function G(e){Object.keys(e||{}).forEach(function(t){var a=e[t];if((t==="bridge"||t==="setup")&&a&&typeof a=="object"&&n[t]&&typeof n[t]=="object"&&(a=Object.assign({},n[t],a)),t==="labels"){s=Object.assign({},s,a||{});return}ne.indexOf(t)>=0&&(a=C(a)),t==="engines"&&Array.isArray(a)&&(a=a.map(function(o){return o&&o.note?Object.assign({},o,{note:C(o.note)}):o})),t==="setup"&&a&&a.steps&&(a=Object.assign({},a,{steps:C(a.steps)})),t==="bridge"&&a&&a.detail&&(a=Object.assign({},a,{detail:C(a.detail)})),n[t]=a})}G(l),typeof n.onOpenSettings!="function"&&v.console&&v.console.error("@gemboss/ui engine-plain.js: enginePicker needs onOpenSettings (the chip opens your Settings \u203A AI & engines)");var w=document.createElement("span");w.className="gb-engine"+(n.className?" "+n.className:"");var N=r("button",{type:"button",className:"gb-engine-chip","aria-haspopup":"dialog"});w.appendChild(N),i.appendChild(w);function m(e,t){return ie(t)?(A[e]=Array.isArray(t)?t.filter(k):[t],r("span",{"data-gb-slot":e,"data-gb-key":"slot-"+e,style:"display:contents"})):t}function se(e){e.querySelectorAll("[data-gb-slot]").forEach(function(t){var a=A[t.getAttribute("data-gb-slot")]||[],o=Array.prototype.slice.call(t.childNodes);o.length===a.length&&o.every(function(g,c){return g===a[c]})||t.replaceChildren.apply(t,a)})}function le(){var e=n.bridge&&n.showBridgeDot!==!1?M[n.bridge.state]:null,t=(n.engines||[]).filter(function(g){return g.id===n.engine})[0],a=n.model?(n.models||[]).filter(function(g){return g.id===n.model})[0]:null,o=t?V(t.mark):null;return r("span",null,[e?r("span",{className:I[e],"aria-hidden":"true"}):null,r("span",{className:"gb-engine-chiplabel"},[t?t.label:n.engine||"",a?r("span",{className:"gb-engine-chipsub",text:" \xB7 "+a.label}):null]),o?r("span",{className:"gb-engine-chipmark"},o):null])}function de(){var e=(n.engines||[]).filter(function(o){return o.id===n.engine})[0],t=n.model?(n.models||[]).filter(function(o){return o.id===n.model})[0]:null,a=n.bridge&&n.showBridgeDot!==!1&&n.bridge.state!=="running"?". "+s.bridge+": "+s[n.bridge.state]:"";return s.chip+": "+(e?e.label:n.engine)+(t?" \xB7 "+t.label:"")+a}function H(e,t,a,o,g,c){var p=n.locked||!g||!!c,S=typeof c=="string"?c:void 0;if(a.length>6||a.some(function(b){return b.group})){var T=r("select",{className:"ui-select ui-select--slim gb-engine-select",disabled:p,title:S,"data-kind":e,"data-value":o||""}),E=null,F;return a.forEach(function(b){var X=r("option",{value:b.id,title:b.title,text:b.label,selected:(o||"")===b.id});b.group?((!E||F!==b.group)&&(E=r("optgroup",{label:b.group}),F=b.group,T.appendChild(E)),E.appendChild(X)):(E=null,F=void 0,T.appendChild(X))}),r("label",{className:"gb-engine-field","data-gb-key":e},[r("span",{className:"gb-engine-label",text:t}),T])}var W=d+"-lbl-"+e;return r("div",{className:"gb-engine-field","data-gb-key":e},[r("span",{className:"gb-engine-label",id:W,text:t}),r("div",{className:"gb-engine-opts",role:"group","aria-labelledby":W},a.map(function(b){return r("button",{type:"button",className:"gb-engine-opt","aria-pressed":String((o||"")===b.id),disabled:p,title:S||b.title,text:b.label,"data-kind":e,"data-choice":b.id})}))])}function O(e){return!(n.locked||e.disabled||!n.onEngineChange)}function ue(e){var t=e,a=n.engines||[],o=(a.filter(function(c){return c.id===n.engine&&O(c)})[0]||a.filter(O)[0]||{}).id,g=[r("div",{className:"gb-engine-field","data-gb-key":"engine"},[r("div",{className:"gb-engine-list",role:"radiogroup","aria-labelledby":t},a.map(function(c){return r("button",{type:"button",role:"radio","aria-checked":String(c.id===n.engine),"data-engine":c.id,"data-gb-key":"engine-"+c.id,tabindex:c.id===o?"0":"-1",className:"gb-engine-row",disabled:!O(c)},[r("span",{className:"gb-engine-rowhead"},[r("span",{className:"gb-engine-rowname",text:c.label}),c.badge?r("span",{className:c.badgeTone?$[c.badgeTone]:"ui-badge",text:c.badge}):null]),c.note?r("span",{className:"gb-engine-note"},m("note-"+c.id,c.note)):null])}))])];return n.modelControl?g.push(r("div",{className:"gb-engine-field","data-gb-key":"model"},[r("span",{className:"gb-engine-label",text:s.model}),m("modelControl",n.modelControl)])):n.models&&n.models.length&&g.push(H("model",s.model,n.models,n.model,n.onModelChange)),n.efforts&&n.efforts.length&&g.push(H("effort",s.effort,n.efforts,n.effort,n.onEffortChange,n.effortDisabled)),n.notes&&g.push(r("div",{className:"gb-engine-notes"},m("notes",n.notes))),g}function K(){var e=n.bridge;return!!e&&(e.state==="outdated"||e.state==="offline"||e.state==="unpaired")}function ce(){var e=n.bridge;return K()?r("p",{className:"gb-engine-callout "+(e.state==="outdated"?"gb-engine-callout--warn":"gb-engine-callout--down"),"data-gb-key":"callout"},[r("strong",{text:s.bridge+": "+s[e.state].toLowerCase()+"."}),e.detail?" ":null,e.detail?m("detail",e.detail):null]):null}function ge(){var e=n.setup||{},t=[];return(e.steps||e.command)&&t.push(r("div",{className:"gb-engine-steps"},e.steps?m("steps",e.steps):r("p",{text:s.steps}))),e.command&&(t.push(r("pre",{className:"gb-engine-cmd"},r("code",{text:e.command}))),t.push(r("div",{className:"gb-engine-actions"},[r("button",{type:"button",className:"ui-btn ui-btn--primary","data-gb-copy":"",text:f.said==="copied"?s.copied:s.copy}),r("span",{className:"gb-engine-said",role:"status",text:f.said==="failed"?s.copyFailed:f.said==="copied"?s.copied:""})]))),e.pairingCode&&t.push(r("p",{className:"gb-engine-code"},[s.pairingCode+": ",r("code",{text:e.pairingCode})])),e.note&&t.push(r("p",{className:"gb-engine-note"},e.note)),t}function fe(){var e=n.bridge,t=r("dl",{className:"gb-engine-rows"}),a=function(c,p){t.appendChild(r("dt",{text:c})),t.appendChild(r("dd",null,p))},o=function(c){return c==null?s.unknown:c?s.yes:s.no};a(s.state,[r("span",{className:I[M[e.state]],"aria-hidden":"true"})," "+s[e.state]]),e.version&&a(s.version,e.version+(e.latest&&e.latest!==e.version?" \xB7 "+s.latest+" "+e.latest:"")),a(s.startsAtSignIn,o(e.autostart)),e.machine&&a(s.machine,e.machine),e.lastSeen&&a(s.lastSeen,e.lastSeen);var g=[t];return e.detail&&e.state!=="running"&&!K()&&g.push(r("p",{className:"gb-engine-note"},m("detail",e.detail))),n.statusActions&&g.push(r("div",{className:"gb-engine-actions"},m("statusActions",n.statusActions))),g}function be(){var e=document.createElement("div"),t=d+"-s-engine",a=d+"-s-bridge",o=d+"-s-setup";if(e.appendChild(r("section",{className:"ui-card gb-engine-sect","data-gb-part":"engine","aria-labelledby":t,"data-gb-key":"s-engine"},[r("h3",{className:"ui-card__title",id:t,text:s.engine})].concat(ue(t)))),n.bridge||n.setup){var g=[r("h3",{className:"ui-card__title",id:a,text:s.bridge}),ce()];n.bridge&&(g=g.concat(fe())),n.setup&&g.push(r("div",{className:"gb-engine-sub","data-gb-part":"setup",role:"group","aria-labelledby":o,tabindex:"-1","data-gb-key":"s-setup"},[r("h4",{className:"gb-engine-subtitle",id:o,text:s.setupTitle})].concat(ge()))),e.appendChild(r("section",{className:"ui-card gb-engine-sect","data-gb-part":"bridge","aria-labelledby":a,tabindex:"-1","data-gb-key":"s-bridge"},g))}return e}function h(){var e=de();N.setAttribute("aria-label",e),N.title=e;var t=(n.engines||[]).filter(function(a){return a.id===n.engine})[0];N.className=t&&V(t.mark)?"gb-engine-chip has-mark":"gb-engine-chip",D(N,le()),A={},u&&(D(u,be()),se(u))}function Y(e){e!==n.engine&&(n.engine=e,n.onEngineChange&&n.onEngineChange(e),h())}function z(e,t){var a=e==="model"?n.model:n.effort,o=e==="model"?n.onModelChange:n.onEffortChange;!o||n.locked||((a||"")!==t&&(e==="model"?n.model=t:n.effort=t,o(t)),h())}function pe(e){var t=e.currentTarget,a=e.target.closest?e.target:e.target.parentElement,o=a&&a.closest("button");!o||!t.contains(o)||o.disabled||(o.hasAttribute("data-engine")?Y(o.getAttribute("data-engine")):o.hasAttribute("data-choice")?z(o.getAttribute("data-kind"),o.getAttribute("data-choice")):o.hasAttribute("data-gb-copy")&&ve())}function me(e){var t=e.target;t&&t.tagName==="SELECT"&&t.hasAttribute("data-kind")&&e.currentTarget.contains(t)&&z(t.getAttribute("data-kind"),t.value)}function he(e){var t=e.currentTarget,a=e.target;if(!(!a||!a.getAttribute||!a.hasAttribute("data-engine"))){var o=e.key==="ArrowDown"||e.key==="ArrowRight"?1:e.key==="ArrowUp"||e.key==="ArrowLeft"?-1:0,g=(n.engines||[]).filter(O);if(!(!o||!g.length)){e.preventDefault();var c=g.map(function(T){return T.id}).indexOf(a.getAttribute("data-engine")),p=g[(c+o+g.length)%g.length];Y(p.id);var S=t.querySelector('[data-engine="'+(v.CSS&&CSS.escape?CSS.escape(p.id):p.id)+'"]');S&&S.focus()}}}function J(e,t){var a=t?"addEventListener":"removeEventListener";e[a]("click",pe),e[a]("change",me),e[a]("keydown",he)}function ve(){var e=n.setup||{};e.command&&ae(e.command).then(function(t){f.said=t?"copied":"failed",h(),clearTimeout(f.saidTimer),f.saidTimer=setTimeout(function(){f.said="",h()},2e3)})}function L(e){f.focus=e,typeof n.onOpenSettings=="function"&&n.onOpenSettings(e),u&&Q()}N.addEventListener("click",function(){L("engine")});function Q(){var e=f.focus;if(f.focus=null,!(!u||!e||e==="engine")){var t=u.querySelector('[data-gb-part="'+(e==="status"?"bridge":e)+'"]');t&&requestAnimationFrame(function(){t.scrollIntoView({block:"start"});var a=t.querySelector("button:not([disabled]), select:not([disabled]), input:not([disabled])");(a||t).focus({preventScroll:!0})})}}var P=!1,x=null;function j(e){e!==P&&(P=e,n.onOpenChange&&n.onOpenChange(e))}function ye(e){u&&q(),u=r("div",{className:"gb-engine-settings"}),J(u,!0),e.appendChild(u),h(),Q(),typeof IntersectionObserver>"u"?j(!0):(x=new IntersectionObserver(function(t){j(t[t.length-1].isIntersecting)}),x.observe(u))}function q(){u&&(x&&(x.disconnect(),x=null),J(u,!1),u.remove(),u=null,j(!1))}return h(),{element:w,update:function(e){G(e),h()},openTab:L,open:function(){L("engine")},close:function(){},isOpen:function(){return P},mountSettings:ye,unmountSettings:q,destroy:function(){q(),clearTimeout(f.saidTimer),w.remove()}}}function oe(i){i=i||{};var l=i.tone==="warn"?"warn":"down",n=r("p",{className:ee[l]+(i.className?" "+i.className:""),role:"status"},[r("span",{className:I[l],"aria-hidden":"true"}),r("span",{className:"gb-engine-notice-text"},C(i.node)||i.text||"")]);if(i.onOpenSetup){var d=r("button",{type:"button",className:"gb-engine-notice-link",text:i.action||"Open setup"});d.addEventListener("click",i.onOpenSetup),n.appendChild(d)}return n}y.enginePicker=re,y.bridgeNotice=oe})(typeof globalThis<"u"?globalThis:this);
package/src/escape.ts ADDED
@@ -0,0 +1,16 @@
1
+ // ESCAPE, CONSUMED (24/10/2026). A kit part that acts on Escape (a Dialog closing, a picker's box clearing its words, a Popover
2
+ // stepping back or closing) stops the keydown from going further out AND the keyup that follows it: a Polaris Modal it sits in
3
+ // closes on the Escape KEYUP (its keydown only marks it closing, Modal/Dialog.js), so stopping the keydown alone still closed the
4
+ // modal behind the picker (measured: a funnel step's page picker, a product picker over the new-funnel modal). The keyup is caught
5
+ // on the window in the capture phase, before any listener on the document, once, within a second.
6
+ let swallowing = false;
7
+
8
+ export function consumeEscape(e: { stopPropagation: () => void }): void {
9
+ e.stopPropagation();
10
+ if (typeof window === "undefined" || swallowing) return;
11
+ swallowing = true;
12
+ const done = () => { swallowing = false; window.removeEventListener("keyup", onUp, true); clearTimeout(timer); };
13
+ const onUp = (up: KeyboardEvent) => { if (up.key === "Escape") { up.stopPropagation(); done(); } };
14
+ const timer = setTimeout(done, 1000);
15
+ window.addEventListener("keyup", onUp, true);
16
+ }