@blackbelt-technology/pi-dashboard-client-utils 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +35 -3
- package/src/ActionList.tsx +54 -30
- package/src/ActionListMenuContext.ts +19 -0
- package/src/Dialog.tsx +38 -16
- package/src/LayerPortal.tsx +40 -6
- package/src/Popover.tsx +25 -23
- package/src/SearchableSelectDialog.tsx +94 -31
- package/src/StatusPill.tsx +28 -58
- package/src/ZoomControls.tsx +28 -15
- package/src/identity/dpop.ts +91 -0
- package/src/identity/login-flow.ts +197 -0
- package/src/identity/oidc-flow.ts +96 -0
- package/src/identity/pkce.ts +129 -0
- package/src/identity/token-store.ts +66 -0
- package/src/mdi-by-key.ts +90 -0
- package/src/minimal-chat/MinimalChatView.tsx +107 -14
- package/src/minimal-chat/index.ts +2 -0
- package/src/minimal-chat/live-tail-text.ts +27 -0
- package/src/minimal-chat/types.ts +26 -0
- package/src/tone.ts +28 -0
- package/src/useZoomPan.ts +33 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-client-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Small reusable React components, hooks, and helpers shared between the pi-dashboard shell and dashboard plugins. Per-subpath exports; no markdown stack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,10 +29,34 @@
|
|
|
29
29
|
"types": "./src/LayerPortal.tsx",
|
|
30
30
|
"default": "./src/LayerPortal.tsx"
|
|
31
31
|
},
|
|
32
|
+
"./tone": {
|
|
33
|
+
"types": "./src/tone.ts",
|
|
34
|
+
"default": "./src/tone.ts"
|
|
35
|
+
},
|
|
32
36
|
"./escape-stack": {
|
|
33
37
|
"types": "./src/escape-stack.ts",
|
|
34
38
|
"default": "./src/escape-stack.ts"
|
|
35
39
|
},
|
|
40
|
+
"./identity/pkce": {
|
|
41
|
+
"types": "./src/identity/pkce.ts",
|
|
42
|
+
"default": "./src/identity/pkce.ts"
|
|
43
|
+
},
|
|
44
|
+
"./identity/token-store": {
|
|
45
|
+
"types": "./src/identity/token-store.ts",
|
|
46
|
+
"default": "./src/identity/token-store.ts"
|
|
47
|
+
},
|
|
48
|
+
"./identity/oidc-flow": {
|
|
49
|
+
"types": "./src/identity/oidc-flow.ts",
|
|
50
|
+
"default": "./src/identity/oidc-flow.ts"
|
|
51
|
+
},
|
|
52
|
+
"./identity/login-flow": {
|
|
53
|
+
"types": "./src/identity/login-flow.ts",
|
|
54
|
+
"default": "./src/identity/login-flow.ts"
|
|
55
|
+
},
|
|
56
|
+
"./identity/dpop": {
|
|
57
|
+
"types": "./src/identity/dpop.ts",
|
|
58
|
+
"default": "./src/identity/dpop.ts"
|
|
59
|
+
},
|
|
36
60
|
"./Popover": {
|
|
37
61
|
"types": "./src/Popover.tsx",
|
|
38
62
|
"default": "./src/Popover.tsx"
|
|
@@ -89,6 +113,14 @@
|
|
|
89
113
|
"types": "./src/ActionList.tsx",
|
|
90
114
|
"default": "./src/ActionList.tsx"
|
|
91
115
|
},
|
|
116
|
+
"./ActionListMenuContext": {
|
|
117
|
+
"types": "./src/ActionListMenuContext.ts",
|
|
118
|
+
"default": "./src/ActionListMenuContext.ts"
|
|
119
|
+
},
|
|
120
|
+
"./mdi-by-key": {
|
|
121
|
+
"types": "./src/mdi-by-key.ts",
|
|
122
|
+
"default": "./src/mdi-by-key.ts"
|
|
123
|
+
},
|
|
92
124
|
"./StatusPill": {
|
|
93
125
|
"types": "./src/StatusPill.tsx",
|
|
94
126
|
"default": "./src/StatusPill.tsx"
|
|
@@ -127,8 +159,8 @@
|
|
|
127
159
|
"react-dom": ">=18.0.0"
|
|
128
160
|
},
|
|
129
161
|
"dependencies": {
|
|
130
|
-
"@blackbelt-technology/dashboard-plugin-runtime": "^0.
|
|
131
|
-
"@blackbelt-technology/pi-dashboard-shared": "^0.
|
|
162
|
+
"@blackbelt-technology/dashboard-plugin-runtime": "^0.10.0",
|
|
163
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.10.0",
|
|
132
164
|
"@mdi/js": "^7.4.47",
|
|
133
165
|
"@mdi/react": "^1.6.1"
|
|
134
166
|
},
|
package/src/ActionList.tsx
CHANGED
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
*
|
|
8
8
|
* See change: adopt-server-driven-intent-rendering.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
import * as mdi from "@mdi/js";
|
|
12
|
-
// We accept icon as a string key (MDI), look up via resolveMdiIcon at render time.
|
|
13
|
-
import type { UiActionListProps } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
10
|
+
|
|
14
11
|
import { sendPluginAction } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
12
|
+
// Icon is an MDI key string, resolved lazily via useMdiIconByKey.
|
|
13
|
+
import type { UiActionListItem, UiActionListProps } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
14
|
+
import Icon from "@mdi/react";
|
|
15
|
+
import { useContext } from "react";
|
|
16
|
+
import { ActionListMenuContext } from "./ActionListMenuContext.js";
|
|
17
|
+
import { useMdiIconByKey } from "./mdi-by-key.js";
|
|
18
|
+
import { toneAttr, toneIconClass, toneRowClass } from "./tone.js";
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* Extended item shape: in addition to `onClick`, items may carry a
|
|
@@ -20,36 +24,59 @@ import { sendPluginAction } from "@blackbelt-technology/dashboard-plugin-runtime
|
|
|
20
24
|
* Plugins emitting intents use `dataAction`; direct React callers can
|
|
21
25
|
* still pass `onClick`.
|
|
22
26
|
*/
|
|
23
|
-
|
|
24
|
-
label: string;
|
|
25
|
-
icon?: string;
|
|
26
|
-
tooltip?: string;
|
|
27
|
-
onClick?: () => void;
|
|
28
|
-
disabled?: boolean;
|
|
27
|
+
type ExtendedActionItem = UiActionListItem & {
|
|
29
28
|
dataAction?: {
|
|
30
29
|
pluginId: string;
|
|
31
30
|
sessionId?: string | null;
|
|
32
31
|
action: string;
|
|
33
32
|
payload?: Record<string, unknown>;
|
|
34
33
|
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function runAction(a: ExtendedActionItem): void {
|
|
37
|
+
if (a.dataAction) {
|
|
38
|
+
sendPluginAction(a.dataAction.pluginId, a.dataAction.sessionId ?? null, a.dataAction.action, a.dataAction.payload);
|
|
39
|
+
}
|
|
40
|
+
if (a.onClick) a.onClick();
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
export function ActionList({ actions }: UiActionListProps) {
|
|
44
|
+
const menu = useContext(ActionListMenuContext);
|
|
38
45
|
if (!actions || actions.length === 0) return null;
|
|
46
|
+
if (menu) {
|
|
47
|
+
// Menu context: vertical menuitems. Disabled items stay focusable
|
|
48
|
+
// (aria-disabled) and neither dispatch nor report activation.
|
|
49
|
+
return (
|
|
50
|
+
<div className="flex flex-col items-stretch">
|
|
51
|
+
{(actions as ExtendedActionItem[]).map((a, i) => (
|
|
52
|
+
<button
|
|
53
|
+
key={i}
|
|
54
|
+
type="button"
|
|
55
|
+
role="menuitem"
|
|
56
|
+
data-testid="action-list-item"
|
|
57
|
+
aria-disabled={a.disabled ? "true" : undefined}
|
|
58
|
+
data-action-tone={toneAttr(a.tone)}
|
|
59
|
+
title={a.tooltip}
|
|
60
|
+
onClick={() => {
|
|
61
|
+
if (a.disabled) return;
|
|
62
|
+
runAction(a);
|
|
63
|
+
menu.onActivate?.();
|
|
64
|
+
}}
|
|
65
|
+
className={`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-[var(--text-primary)] ${toneRowClass(a.tone, { disabled: !!a.disabled }) || "hover:bg-[var(--bg-tertiary)]"} aria-disabled:opacity-50 aria-disabled:cursor-not-allowed transition-colors`}
|
|
66
|
+
>
|
|
67
|
+
{a.icon ? <IconByKey iconKey={a.icon} className={toneIconClass(a.tone, { disabled: !!a.disabled })} /> : null}
|
|
68
|
+
<span>{a.label}</span>
|
|
69
|
+
</button>
|
|
70
|
+
))}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
39
74
|
return (
|
|
40
75
|
<div className="flex flex-row flex-wrap gap-1 items-center">
|
|
41
76
|
{(actions as ExtendedActionItem[]).map((a, i) => {
|
|
42
77
|
const handleClick = () => {
|
|
43
78
|
if (a.disabled) return;
|
|
44
|
-
|
|
45
|
-
sendPluginAction(
|
|
46
|
-
a.dataAction.pluginId,
|
|
47
|
-
a.dataAction.sessionId ?? null,
|
|
48
|
-
a.dataAction.action,
|
|
49
|
-
a.dataAction.payload,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
if (a.onClick) a.onClick();
|
|
79
|
+
runAction(a);
|
|
53
80
|
};
|
|
54
81
|
return (
|
|
55
82
|
<button
|
|
@@ -57,10 +84,11 @@ export function ActionList({ actions }: UiActionListProps) {
|
|
|
57
84
|
type="button"
|
|
58
85
|
onClick={handleClick}
|
|
59
86
|
disabled={a.disabled}
|
|
87
|
+
data-action-tone={toneAttr(a.tone)}
|
|
60
88
|
title={a.tooltip}
|
|
61
89
|
className={`inline-flex items-center gap-1 px-2 py-1 rounded text-xs border border-[var(--border-subtle)] bg-[var(--bg-secondary)] hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors`}
|
|
62
90
|
>
|
|
63
|
-
{a.icon ? <IconByKey iconKey={a.icon} /> : null}
|
|
91
|
+
{a.icon ? <IconByKey iconKey={a.icon} className={toneIconClass(a.tone, { disabled: !!a.disabled })} /> : null}
|
|
64
92
|
<span>{a.label}</span>
|
|
65
93
|
</button>
|
|
66
94
|
);
|
|
@@ -70,16 +98,12 @@ export function ActionList({ actions }: UiActionListProps) {
|
|
|
70
98
|
}
|
|
71
99
|
|
|
72
100
|
/**
|
|
73
|
-
* Render an MDI icon by its export-name key.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
101
|
+
* Render an MDI icon by its export-name key. Renders nothing while the full
|
|
102
|
+
* icon set loads and for unknown keys. See change:
|
|
103
|
+
* harden-ios-safari-memory-and-ws-diagnostics.
|
|
76
104
|
*/
|
|
77
|
-
function IconByKey({ iconKey }: { iconKey: string }) {
|
|
78
|
-
|
|
79
|
-
// is a synchronous flat property lookup — no dynamic import, no loading
|
|
80
|
-
// state. See change: shrink-client-index-chunk.
|
|
81
|
-
const candidate = (mdi as Record<string, unknown>)[iconKey];
|
|
82
|
-
const path = typeof candidate === "string" ? candidate : null;
|
|
105
|
+
function IconByKey({ iconKey, className }: { iconKey: string; className?: string }) {
|
|
106
|
+
const path = useMdiIconByKey(iconKey);
|
|
83
107
|
if (!path) return null;
|
|
84
|
-
return <Icon path={path} size={0.6} />;
|
|
108
|
+
return <Icon path={path} size={0.6} {...(className ? { className } : {})} />;
|
|
85
109
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Menu context for the `ui:action-list` primitive.
|
|
3
|
+
*
|
|
4
|
+
* When a non-null value is provided, `ActionList` renders its items as a
|
|
5
|
+
* vertical list of `role="menuitem"` buttons (instead of the horizontal chip
|
|
6
|
+
* row) and calls `onActivate` after a successful (enabled) activation so the
|
|
7
|
+
* hosting menu can close itself. `null` (the default) keeps the standalone
|
|
8
|
+
* horizontal-row rendering unchanged.
|
|
9
|
+
*
|
|
10
|
+
* See change: add-session-actions-flyout.
|
|
11
|
+
*/
|
|
12
|
+
import { createContext } from "react";
|
|
13
|
+
|
|
14
|
+
export interface ActionListMenuContextValue {
|
|
15
|
+
/** Called after an enabled item was activated (handler already ran). */
|
|
16
|
+
onActivate?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ActionListMenuContext = createContext<ActionListMenuContextValue | null>(null);
|
package/src/Dialog.tsx
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mdiClose } from "@mdi/js";
|
|
2
|
+
import { Icon } from "@mdi/react";
|
|
3
|
+
import {
|
|
4
|
+
type ReactNode,
|
|
5
|
+
useCallback,
|
|
2
6
|
useId,
|
|
3
7
|
useRef,
|
|
4
|
-
|
|
8
|
+
useState,
|
|
5
9
|
} from "react";
|
|
6
|
-
import { mdiClose } from "@mdi/js";
|
|
7
|
-
import { Icon } from "@mdi/react";
|
|
8
10
|
import { DialogPortal } from "./DialogPortal.js";
|
|
9
11
|
import { useEscapeDismiss } from "./escape-stack.js";
|
|
12
|
+
import { LayerHostProvider } from "./LayerPortal.js";
|
|
10
13
|
import { useFocusTrap } from "./useFocusTrap.js";
|
|
11
14
|
|
|
12
15
|
export type DialogSize = "sm" | "md" | "lg" | "full";
|
|
@@ -75,6 +78,16 @@ export function Dialog({
|
|
|
75
78
|
}: DialogProps) {
|
|
76
79
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
77
80
|
const titleId = useId();
|
|
81
|
+
// The panel doubles as the layer host for any `LayerPortal` overlay a child
|
|
82
|
+
// opens (e.g. the run-config ModelSelector): portaling to `document.body`
|
|
83
|
+
// would land it at `z-popover`, BELOW this dialog's `z-dialog` backdrop. State
|
|
84
|
+
// (not just the ref) so children re-render once the element exists.
|
|
85
|
+
// See change: fix-composer-popover-layering.
|
|
86
|
+
const [panelEl, setPanelEl] = useState<HTMLDivElement | null>(null);
|
|
87
|
+
const setPanel = useCallback((el: HTMLDivElement | null) => {
|
|
88
|
+
containerRef.current = el;
|
|
89
|
+
setPanelEl(el);
|
|
90
|
+
}, []);
|
|
78
91
|
|
|
79
92
|
useFocusTrap(containerRef, open);
|
|
80
93
|
|
|
@@ -96,19 +109,19 @@ export function Dialog({
|
|
|
96
109
|
<DialogPortal>
|
|
97
110
|
<div className="fixed inset-0 z-dialog flex items-center justify-center">
|
|
98
111
|
<div
|
|
99
|
-
className="absolute inset-0 bg-
|
|
112
|
+
className="absolute inset-0 bg-[var(--bg-overlay)]"
|
|
100
113
|
onClick={onClose}
|
|
101
114
|
data-testid={testId ? `${testId}-overlay` : undefined}
|
|
102
115
|
/>
|
|
103
116
|
<div
|
|
104
|
-
ref={
|
|
117
|
+
ref={setPanel}
|
|
105
118
|
role="dialog"
|
|
106
119
|
aria-modal="true"
|
|
107
120
|
aria-labelledby={title ? titleId : undefined}
|
|
108
121
|
aria-label={!title ? ariaLabel : undefined}
|
|
109
122
|
tabIndex={-1}
|
|
110
123
|
data-testid={testId}
|
|
111
|
-
className={`relative w-full mx-4 ${SIZE_MAX_W[size]} ${SIZE_MAX_H[size]} ${flush ? "overflow-hidden flex flex-col min-h-0" : "overflow-y-auto p-5 space-y-4"} bg-[var(--bg-
|
|
124
|
+
className={`relative w-full mx-4 ${SIZE_MAX_W[size]} ${SIZE_MAX_H[size]} ${flush ? "overflow-hidden flex flex-col min-h-0" : "overflow-y-auto p-5 space-y-4"} bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-xl shadow-xl focus:outline-none`}
|
|
112
125
|
>
|
|
113
126
|
{/* Standard close affordance on every non-flush dialog (Escape +
|
|
114
127
|
backdrop also close). Absolutely positioned; the headered branch
|
|
@@ -120,29 +133,29 @@ export function Dialog({
|
|
|
120
133
|
onClick={onClose}
|
|
121
134
|
aria-label="Close"
|
|
122
135
|
data-testid={testId ? `${testId}-close` : undefined}
|
|
123
|
-
className="absolute top-
|
|
136
|
+
className="absolute top-2 right-2 z-10 flex items-center justify-center min-h-[44px] min-w-[44px] sm:min-h-[36px] sm:min-w-[36px] rounded text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-surface)] transition-colors"
|
|
124
137
|
>
|
|
125
138
|
<Icon path={mdiClose} size={0.8} />
|
|
126
139
|
</button>
|
|
127
140
|
)}
|
|
128
141
|
{hasHeader && (
|
|
129
|
-
<div className="flex items-center gap-3 pr-
|
|
142
|
+
<div className="flex items-center gap-3 pr-12">
|
|
130
143
|
{icon && (
|
|
131
|
-
<div className="flex-shrink-0 flex items-center justify-center w-9 h-9 rounded-md bg-[var(--
|
|
144
|
+
<div className="flex-shrink-0 flex items-center justify-center w-9 h-9 rounded-md border border-[var(--severity-info-border)] bg-[var(--severity-info-bg)] text-[var(--severity-info-fg)]">
|
|
132
145
|
<Icon path={icon} size={0.85} />
|
|
133
146
|
</div>
|
|
134
147
|
)}
|
|
135
148
|
{title && (
|
|
136
149
|
<h3
|
|
137
150
|
id={titleId}
|
|
138
|
-
className="text-
|
|
151
|
+
className="text-lg font-semibold text-[var(--text-primary)]"
|
|
139
152
|
>
|
|
140
153
|
{title}
|
|
141
154
|
</h3>
|
|
142
155
|
)}
|
|
143
156
|
</div>
|
|
144
157
|
)}
|
|
145
|
-
{children}
|
|
158
|
+
<LayerHostProvider host={panelEl}>{children}</LayerHostProvider>
|
|
146
159
|
</div>
|
|
147
160
|
</div>
|
|
148
161
|
</DialogPortal>
|
|
@@ -157,6 +170,11 @@ function DialogFooter({ children }: { children: ReactNode }) {
|
|
|
157
170
|
);
|
|
158
171
|
}
|
|
159
172
|
|
|
173
|
+
// Shared by every action and Cancel: contract target size (44 px below `sm`,
|
|
174
|
+
// 36 px from `sm`) and semibold text. See change: align-ui-contract-recipes.
|
|
175
|
+
const ACTION_BASE =
|
|
176
|
+
"inline-flex items-center justify-center text-xs font-semibold px-3 rounded transition-colors min-h-[44px] sm:min-h-[36px]";
|
|
177
|
+
|
|
160
178
|
interface DialogCancelProps {
|
|
161
179
|
onClick: () => void;
|
|
162
180
|
children?: ReactNode;
|
|
@@ -169,17 +187,21 @@ function DialogCancel({ onClick, children = "Cancel", testId }: DialogCancelProp
|
|
|
169
187
|
type="button"
|
|
170
188
|
onClick={onClick}
|
|
171
189
|
data-testid={testId}
|
|
172
|
-
className=
|
|
190
|
+
className={`${ACTION_BASE} border border-[var(--border-primary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]`}
|
|
173
191
|
>
|
|
174
192
|
{children}
|
|
175
193
|
</button>
|
|
176
194
|
);
|
|
177
195
|
}
|
|
178
196
|
|
|
197
|
+
// Primary fills with --accent-solid (white on it is 5.17:1 in every theme);
|
|
198
|
+
// --accent-primary under white text is only 3.68:1.
|
|
199
|
+
// See change: add-pi-spec-driven-schema.
|
|
179
200
|
const INTENT_CLASS: Record<DialogIntent, string> = {
|
|
180
201
|
primary:
|
|
181
|
-
"bg-[var(--accent-
|
|
182
|
-
danger:
|
|
202
|
+
"bg-[var(--accent-solid)] text-white hover:opacity-90 border border-transparent",
|
|
203
|
+
danger:
|
|
204
|
+
"bg-[var(--tint-red-bg)] text-[var(--tint-red-fg)] border border-[var(--tint-red-border)] hover:opacity-90",
|
|
183
205
|
neutral:
|
|
184
206
|
"bg-transparent border border-[var(--border-primary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]",
|
|
185
207
|
};
|
|
@@ -205,7 +227,7 @@ function DialogAction({
|
|
|
205
227
|
onClick={onClick}
|
|
206
228
|
disabled={disabled}
|
|
207
229
|
data-testid={testId}
|
|
208
|
-
className={
|
|
230
|
+
className={`${ACTION_BASE} disabled:opacity-50 disabled:cursor-not-allowed ${INTENT_CLASS[intent]}`}
|
|
209
231
|
>
|
|
210
232
|
{children}
|
|
211
233
|
</button>
|
package/src/LayerPortal.tsx
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
|
+
import { createContext, type ReactNode, useContext } from "react";
|
|
1
2
|
import { createPortal } from "react-dom";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The nearest layer host a `LayerPortal` should portal INTO, overriding the
|
|
6
|
+
* default `document.body`.
|
|
7
|
+
*
|
|
8
|
+
* `body` is the right host only while nothing higher on the layer scale wraps
|
|
9
|
+
* the overlay. Inside a `Dialog` it is wrong: the dialog paints at `z-dialog`
|
|
10
|
+
* with a full-viewport backdrop, so a popover portaled to `body` becomes its
|
|
11
|
+
* SIBLING at the lower `z-popover` — it sinks behind the backdrop and every
|
|
12
|
+
* click on it dismisses the dialog instead. Portaling into the dialog panel
|
|
13
|
+
* keeps the popover inside the dialog's stacking context (so it rides the
|
|
14
|
+
* dialog's rank against the rest of the scale) and inside its focus trap, while
|
|
15
|
+
* still escaping the ancestor stacking contexts INSIDE the dialog.
|
|
16
|
+
*
|
|
17
|
+
* `null` (the default, and the value while a host element is still mounting)
|
|
18
|
+
* means `document.body` — the composer/card case, which must keep escaping all
|
|
19
|
+
* the way out.
|
|
20
|
+
*
|
|
21
|
+
* See change: fix-composer-popover-layering.
|
|
22
|
+
*/
|
|
23
|
+
export const LayerHostContext = createContext<HTMLElement | null>(null);
|
|
24
|
+
|
|
25
|
+
export function LayerHostProvider({
|
|
26
|
+
host,
|
|
27
|
+
children,
|
|
28
|
+
}: {
|
|
29
|
+
host: HTMLElement | null;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}) {
|
|
32
|
+
return <LayerHostContext.Provider value={host}>{children}</LayerHostContext.Provider>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* LayerPortal — portals an overlay to the nearest layer host, defaulting to the
|
|
37
|
+
* top-level layer root (`document.body`), so it escapes ALL ancestor stacking
|
|
38
|
+
* contexts (`transform`, `will-change`, `opacity < 1`, `isolation: isolate`, an
|
|
39
|
+
* ancestor's own `z-*`).
|
|
8
40
|
*
|
|
9
41
|
* This is the mechanism the `overlay-layering` spec calls "portal-or-perish":
|
|
10
42
|
* a numeric z-index only orders siblings WITHIN the nearest ancestor stacking
|
|
@@ -20,8 +52,10 @@ import type { ReactNode } from "react";
|
|
|
20
52
|
* its box. The portaled surface positions itself (`position: fixed`) from its
|
|
21
53
|
* trigger's viewport rect and carries a `z-*` layer utility.
|
|
22
54
|
*
|
|
23
|
-
* See openspec spec overlay-layering. See change: add-overlay-layering-system
|
|
55
|
+
* See openspec spec overlay-layering. See change: add-overlay-layering-system,
|
|
56
|
+
* fix-composer-popover-layering.
|
|
24
57
|
*/
|
|
25
58
|
export function LayerPortal({ children }: { children: ReactNode }) {
|
|
26
|
-
|
|
59
|
+
const host = useContext(LayerHostContext);
|
|
60
|
+
return createPortal(children, host ?? document.body);
|
|
27
61
|
}
|
package/src/Popover.tsx
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* The companion of `DialogPortal` for non-modal floating UI. Plugins render
|
|
5
5
|
* `<Popover anchorEl={btnRef.current} onDismiss={...}>...</Popover>` inline
|
|
6
6
|
* from their own component; the popover positions itself relative to
|
|
7
|
-
* `anchorEl`'s viewport rect, lives in a body
|
|
8
|
-
* escapes parent overflow/transform
|
|
9
|
-
* click or
|
|
7
|
+
* `anchorEl`'s viewport rect, lives in a `LayerPortal` (body, or the
|
|
8
|
+
* enclosing dialog's layer host) so it escapes parent overflow/transform
|
|
9
|
+
* contexts, paints at `var(--z-popover)`, and dismisses on outside click or
|
|
10
|
+
* Esc.
|
|
10
11
|
*
|
|
11
12
|
* NOT a modal. NOT a scroll-lock. NOT a tooltip. Strictly a click-anchored
|
|
12
13
|
* floating panel.
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
* See change: add-ui-popover-primitive.
|
|
27
28
|
*/
|
|
28
29
|
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
|
|
29
|
-
import {
|
|
30
|
+
import { LayerPortal } from "./LayerPortal.js";
|
|
30
31
|
|
|
31
32
|
export interface PopoverProps {
|
|
32
33
|
/** DOM element the popover is anchored to. Required. */
|
|
@@ -130,24 +131,25 @@ export function Popover({ anchorEl, onDismiss, children, offset = 6 }: PopoverPr
|
|
|
130
131
|
};
|
|
131
132
|
}, [anchorEl, onDismiss]);
|
|
132
133
|
|
|
133
|
-
return
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
134
|
+
return (
|
|
135
|
+
<LayerPortal>
|
|
136
|
+
<div
|
|
137
|
+
ref={popoverRef}
|
|
138
|
+
role="dialog"
|
|
139
|
+
data-testid="ui-popover"
|
|
140
|
+
data-placement={position?.placement ?? "below"}
|
|
141
|
+
style={{
|
|
142
|
+
position: "fixed",
|
|
143
|
+
top: position?.top ?? -9999,
|
|
144
|
+
left: position?.left ?? -9999,
|
|
145
|
+
zIndex: "var(--z-popover)",
|
|
146
|
+
// Until the first layout effect runs we render off-screen so the
|
|
147
|
+
// measurement happens without flicker.
|
|
148
|
+
visibility: position ? "visible" : "hidden",
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
{children}
|
|
152
|
+
</div>
|
|
153
|
+
</LayerPortal>
|
|
152
154
|
);
|
|
153
155
|
}
|
|
@@ -7,6 +7,26 @@ export interface SelectOption {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
badge?: string;
|
|
9
9
|
badgeColor?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Group caption this option renders under. Options sharing a group render
|
|
12
|
+
* beneath one caption, in first-appearance order; ungrouped options keep
|
|
13
|
+
* the flat list. Inert unless set.
|
|
14
|
+
*/
|
|
15
|
+
group?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Rendered visible but non-selectable (e.g. a picker entry whose selection
|
|
18
|
+
* would overwrite a conflicting credential). Arrow navigation skips it and
|
|
19
|
+
* Enter is a no-op. Inert unless set.
|
|
20
|
+
*/
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** Tooltip for a disabled option — names the way out (e.g. remove-first). */
|
|
23
|
+
disabledReason?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Always rendered, even when the search filter does not match — for a
|
|
26
|
+
* pinned entry (e.g. "Custom endpoint…") that must stay reachable under any
|
|
27
|
+
* search term. Inert unless set.
|
|
28
|
+
*/
|
|
29
|
+
pinned?: boolean;
|
|
10
30
|
}
|
|
11
31
|
|
|
12
32
|
interface Props {
|
|
@@ -38,37 +58,59 @@ export function SearchableSelectDialog({
|
|
|
38
58
|
const filtered = useMemo(() => {
|
|
39
59
|
if (!query.trim()) return options;
|
|
40
60
|
const q = query.toLowerCase();
|
|
61
|
+
// `value` is the id — the picker contract matches on display name AND id.
|
|
62
|
+
// Pinned options stay reachable under any search term.
|
|
41
63
|
return options.filter(
|
|
42
|
-
(o) =>
|
|
64
|
+
(o) =>
|
|
65
|
+
o.pinned ||
|
|
66
|
+
o.label.toLowerCase().includes(q) ||
|
|
67
|
+
o.description?.toLowerCase().includes(q) ||
|
|
68
|
+
o.value.toLowerCase().includes(q),
|
|
43
69
|
);
|
|
44
70
|
}, [options, query]);
|
|
45
71
|
|
|
46
72
|
// Reset selection when filter changes
|
|
47
73
|
useEffect(() => {
|
|
48
74
|
setSelectedIndex(0);
|
|
49
|
-
}, [filtered.length]);
|
|
75
|
+
}, [filtered.length, query]);
|
|
50
76
|
|
|
51
|
-
// Scroll selected item into view
|
|
77
|
+
// Scroll selected item into view. A group caption renders as its own child
|
|
78
|
+
// before its options, so children indices no longer map to option indices —
|
|
79
|
+
// target the selected row by attribute instead.
|
|
52
80
|
useEffect(() => {
|
|
53
|
-
const el = listRef.current?.
|
|
81
|
+
const el = listRef.current?.querySelector('[data-active="true"]') as HTMLElement | undefined;
|
|
54
82
|
el?.scrollIntoView?.({ block: "nearest" });
|
|
55
83
|
}, [selectedIndex]);
|
|
56
84
|
|
|
85
|
+
const moveSelection = (dir: 1 | -1) => {
|
|
86
|
+
setSelectedIndex((i) => {
|
|
87
|
+
let next = i;
|
|
88
|
+
// Arrow navigation skips disabled options so Enter never lands on one.
|
|
89
|
+
do {
|
|
90
|
+
next += dir;
|
|
91
|
+
} while (next > 0 && next < filtered.length - 1 && filtered[next]?.disabled);
|
|
92
|
+
return Math.max(0, Math.min(next, filtered.length - 1));
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
57
96
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
58
97
|
if (e.key === "ArrowDown") {
|
|
59
98
|
e.preventDefault();
|
|
60
|
-
|
|
99
|
+
moveSelection(1);
|
|
61
100
|
} else if (e.key === "ArrowUp") {
|
|
62
101
|
e.preventDefault();
|
|
63
|
-
|
|
102
|
+
moveSelection(-1);
|
|
64
103
|
} else if (e.key === "Enter") {
|
|
65
104
|
e.preventDefault();
|
|
66
|
-
|
|
67
|
-
|
|
105
|
+
const opt = filtered[selectedIndex];
|
|
106
|
+
if (opt && !opt.disabled) {
|
|
107
|
+
onSelect(opt.value);
|
|
68
108
|
}
|
|
69
109
|
}
|
|
70
110
|
};
|
|
71
111
|
|
|
112
|
+
let lastGroup: string | undefined;
|
|
113
|
+
|
|
72
114
|
return (
|
|
73
115
|
<Dialog open onClose={onCancel} title={title} size="sm">
|
|
74
116
|
{/* Search */}
|
|
@@ -89,30 +131,51 @@ export function SearchableSelectDialog({
|
|
|
89
131
|
{filtered.length === 0 ? (
|
|
90
132
|
<div className="px-3 py-4 text-xs text-[var(--text-muted)] text-center">{emptyMessage}</div>
|
|
91
133
|
) : (
|
|
92
|
-
filtered.map((opt, i) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}`}
|
|
102
|
-
>
|
|
103
|
-
<div className="flex-1 min-w-0">
|
|
104
|
-
<div className="text-xs truncate">{opt.label}</div>
|
|
105
|
-
{opt.description && (
|
|
106
|
-
<div className="text-[10px] text-[var(--text-muted)] truncate">{opt.description}</div>
|
|
134
|
+
filtered.map((opt, i) => {
|
|
135
|
+
const caption = opt.group !== undefined && opt.group !== lastGroup ? opt.group : null;
|
|
136
|
+
lastGroup = opt.group;
|
|
137
|
+
return (
|
|
138
|
+
<React.Fragment key={opt.value}>
|
|
139
|
+
{caption && (
|
|
140
|
+
<div className="px-2 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">
|
|
141
|
+
{caption}
|
|
142
|
+
</div>
|
|
107
143
|
)}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
{opt.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
144
|
+
<div
|
|
145
|
+
role="option"
|
|
146
|
+
aria-selected={i === selectedIndex && !opt.disabled}
|
|
147
|
+
aria-disabled={opt.disabled || undefined}
|
|
148
|
+
title={opt.disabled ? opt.disabledReason : undefined}
|
|
149
|
+
data-active={i === selectedIndex}
|
|
150
|
+
onClick={() => { if (!opt.disabled) onSelect(opt.value); }}
|
|
151
|
+
onMouseEnter={() => setSelectedIndex(i)}
|
|
152
|
+
className={`px-3 py-1.5 rounded-lg flex items-center gap-2 ${
|
|
153
|
+
opt.disabled
|
|
154
|
+
? "cursor-not-allowed opacity-55"
|
|
155
|
+
: "cursor-pointer"
|
|
156
|
+
} ${
|
|
157
|
+
i === selectedIndex
|
|
158
|
+
? "bg-blue-500/15 text-[var(--text-primary)]"
|
|
159
|
+
: "text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)]"
|
|
160
|
+
}`}
|
|
161
|
+
>
|
|
162
|
+
<div className="flex-1 min-w-0">
|
|
163
|
+
<div className="text-xs truncate">{opt.label}</div>
|
|
164
|
+
{opt.description && (
|
|
165
|
+
<div className="text-[10px] text-[var(--text-muted)] truncate">
|
|
166
|
+
{opt.description}
|
|
167
|
+
</div>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
{opt.badge && (
|
|
171
|
+
<span className={`text-[9px] px-1 py-0.5 rounded flex-shrink-0 ${opt.badgeColor || "text-[var(--text-tertiary)]"}`}>
|
|
172
|
+
{opt.badge}
|
|
173
|
+
</span>
|
|
174
|
+
)}
|
|
175
|
+
</div>
|
|
176
|
+
</React.Fragment>
|
|
177
|
+
);
|
|
178
|
+
})
|
|
116
179
|
)}
|
|
117
180
|
</div>
|
|
118
181
|
|