@lincyaw/aegis-ui 0.11.0 → 0.12.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/dist/agent/ask/AskPanel.cjs +1 -1
- package/dist/agent/ask/AskPanel.cjs.map +1 -1
- package/dist/agent/ask/AskPanel.js +25 -25
- package/dist/agent/ask/AskPanel.js.map +1 -1
- package/dist/components/ui/Button.cjs.map +1 -1
- package/dist/components/ui/Button.d.ts +4 -2
- package/dist/components/ui/Button.js.map +1 -1
- package/dist/components/ui/CheckGrid.cjs +1 -1
- package/dist/components/ui/CheckGrid.cjs.map +1 -1
- package/dist/components/ui/CheckGrid.js +18 -17
- package/dist/components/ui/CheckGrid.js.map +1 -1
- package/dist/components/ui/CodeEditor.cjs +1 -1
- package/dist/components/ui/CodeEditor.cjs.map +1 -1
- package/dist/components/ui/CodeEditor.js +95 -87
- package/dist/components/ui/CodeEditor.js.map +1 -1
- package/dist/components/ui/CommandInvocationCard.cjs +1 -1
- package/dist/components/ui/CommandInvocationCard.cjs.map +1 -1
- package/dist/components/ui/CommandInvocationCard.js +10 -10
- package/dist/components/ui/CommandInvocationCard.js.map +1 -1
- package/dist/components/ui/DangerZone.cjs +1 -1
- package/dist/components/ui/DangerZone.cjs.map +1 -1
- package/dist/components/ui/DangerZone.js +12 -12
- package/dist/components/ui/DangerZone.js.map +1 -1
- package/dist/components/ui/DataList.cjs +1 -1
- package/dist/components/ui/DataList.cjs.map +1 -1
- package/dist/components/ui/DataList.js +4 -3
- package/dist/components/ui/DataList.js.map +1 -1
- package/dist/components/ui/DataTable.cjs +1 -1
- package/dist/components/ui/DataTable.cjs.map +1 -1
- package/dist/components/ui/DataTable.d.ts +2 -1
- package/dist/components/ui/DataTable.js +125 -108
- package/dist/components/ui/DataTable.js.map +1 -1
- package/dist/components/ui/DiffViewer.cjs +1 -1
- package/dist/components/ui/DiffViewer.cjs.map +1 -1
- package/dist/components/ui/DiffViewer.js +29 -25
- package/dist/components/ui/DiffViewer.js.map +1 -1
- package/dist/components/ui/DropdownMenu.cjs.map +1 -1
- package/dist/components/ui/DropdownMenu.d.ts +1 -0
- package/dist/components/ui/DropdownMenu.js.map +1 -1
- package/dist/components/ui/FileDropzone.cjs +1 -1
- package/dist/components/ui/FileDropzone.cjs.map +1 -1
- package/dist/components/ui/FileDropzone.js +12 -12
- package/dist/components/ui/FileDropzone.js.map +1 -1
- package/dist/components/ui/FilePreview.cjs +1 -1
- package/dist/components/ui/FilePreview.cjs.map +1 -1
- package/dist/components/ui/FilePreview.js +16 -13
- package/dist/components/ui/FilePreview.js.map +1 -1
- package/dist/components/ui/ParetoChart.cjs +1 -1
- package/dist/components/ui/ParetoChart.cjs.map +1 -1
- package/dist/components/ui/ParetoChart.js +247 -212
- package/dist/components/ui/ParetoChart.js.map +1 -1
- package/dist/components/ui/QueryAutocomplete.cjs +1 -1
- package/dist/components/ui/QueryAutocomplete.cjs.map +1 -1
- package/dist/components/ui/QueryAutocomplete.d.ts +4 -1
- package/dist/components/ui/QueryAutocomplete.js +136 -123
- package/dist/components/ui/QueryAutocomplete.js.map +1 -1
- package/dist/components/ui/RankBar.cjs +1 -1
- package/dist/components/ui/RankBar.cjs.map +1 -1
- package/dist/components/ui/RankBar.js +9 -9
- package/dist/components/ui/RankBar.js.map +1 -1
- package/dist/components/ui/ReplayStepStrip.cjs +1 -1
- package/dist/components/ui/ReplayStepStrip.cjs.map +1 -1
- package/dist/components/ui/ReplayStepStrip.d.ts +6 -3
- package/dist/components/ui/ReplayStepStrip.js +71 -61
- package/dist/components/ui/ReplayStepStrip.js.map +1 -1
- package/dist/components/ui/ServiceMap.cjs +1 -1
- package/dist/components/ui/ServiceMap.cjs.map +1 -1
- package/dist/components/ui/ServiceMap.d.ts +9 -1
- package/dist/components/ui/ServiceMap.js +333 -268
- package/dist/components/ui/ServiceMap.js.map +1 -1
- package/dist/components/ui/SparkLine.cjs +1 -1
- package/dist/components/ui/SparkLine.cjs.map +1 -1
- package/dist/components/ui/SparkLine.d.ts +5 -2
- package/dist/components/ui/SparkLine.js +33 -29
- package/dist/components/ui/SparkLine.js.map +1 -1
- package/dist/components/ui/TableOfContents.cjs +1 -1
- package/dist/components/ui/TableOfContents.cjs.map +1 -1
- package/dist/components/ui/TableOfContents.js +16 -19
- package/dist/components/ui/TableOfContents.js.map +1 -1
- package/dist/components/ui/Tabs.cjs +2 -2
- package/dist/components/ui/Tabs.cjs.map +1 -1
- package/dist/components/ui/Tabs.js +107 -87
- package/dist/components/ui/Tabs.js.map +1 -1
- package/dist/components/ui/TimeRangePicker.cjs +1 -1
- package/dist/components/ui/TimeRangePicker.cjs.map +1 -1
- package/dist/components/ui/TimeRangePicker.d.ts +12 -1
- package/dist/components/ui/TimeRangePicker.js +69 -63
- package/dist/components/ui/TimeRangePicker.js.map +1 -1
- package/dist/components/ui/Timeline.cjs.map +1 -1
- package/dist/components/ui/Timeline.d.ts +4 -4
- package/dist/components/ui/Timeline.js.map +1 -1
- package/dist/components/ui/TimelineChart.cjs +2 -2
- package/dist/components/ui/TimelineChart.cjs.map +1 -1
- package/dist/components/ui/TimelineChart.d.ts +1 -0
- package/dist/components/ui/TimelineChart.js +131 -137
- package/dist/components/ui/TimelineChart.js.map +1 -1
- package/dist/components/ui/TraceTree.cjs +1 -1
- package/dist/components/ui/TraceTree.cjs.map +1 -1
- package/dist/components/ui/TraceTree.d.ts +4 -0
- package/dist/components/ui/TraceTree.js +88 -87
- package/dist/components/ui/TraceTree.js.map +1 -1
- package/dist/components/ui/TrajectoryStep.cjs +2 -1
- package/dist/components/ui/TrajectoryStep.cjs.map +1 -1
- package/dist/components/ui/TrajectoryStep.js +64 -43
- package/dist/components/ui/TrajectoryStep.js.map +1 -1
- package/dist/components/ui/useColumnWidths.cjs +1 -1
- package/dist/components/ui/useColumnWidths.cjs.map +1 -1
- package/dist/components/ui/useColumnWidths.d.ts +6 -1
- package/dist/components/ui/useColumnWidths.js +139 -123
- package/dist/components/ui/useColumnWidths.js.map +1 -1
- package/dist/layouts/shell/AegisShell.cjs +1 -1
- package/dist/layouts/shell/AegisShell.cjs.map +1 -1
- package/dist/layouts/shell/AegisShell.js +33 -34
- package/dist/layouts/shell/AegisShell.js.map +1 -1
- package/dist/lib/breakAtSeparators.cjs +2 -0
- package/dist/lib/breakAtSeparators.cjs.map +1 -0
- package/dist/lib/breakAtSeparators.d.ts +6 -0
- package/dist/lib/breakAtSeparators.js +10 -0
- package/dist/lib/breakAtSeparators.js.map +1 -0
- package/dist/locale/strings.cjs +1 -1
- package/dist/locale/strings.cjs.map +1 -1
- package/dist/locale/strings.d.ts +6 -0
- package/dist/locale/strings.js +27 -19
- package/dist/locale/strings.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/theme/antdTheme.cjs +1 -1
- package/dist/theme/antdTheme.cjs.map +1 -1
- package/dist/theme/antdTheme.js +50 -29
- package/dist/theme/antdTheme.js.map +1 -1
- package/dist/transports/agentm/AgentmChannelProvider.cjs +1 -1
- package/dist/transports/agentm/AgentmChannelProvider.cjs.map +1 -1
- package/dist/transports/agentm/AgentmChannelProvider.js +66 -61
- package/dist/transports/agentm/AgentmChannelProvider.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),m=require("react"),T=require("../../components/ui/ChatComposer.cjs"),A=require("../../components/ui/Chip.cjs"),R=require("../../hooks/useIsomorphicLayoutEffect.cjs"),q=require("../core/aegisRuntimeContext.cjs");;/* empty css */const C=require("../../locale/useStrings.cjs"),H=8,M=8,I=160;function S(a,r,c,o){if(typeof window>"u")return null;const f=window.innerWidth,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),m=require("react"),T=require("../../components/ui/ChatComposer.cjs"),A=require("../../components/ui/Chip.cjs"),R=require("../../hooks/useIsomorphicLayoutEffect.cjs"),q=require("../core/aegisRuntimeContext.cjs");;/* empty css */const C=require("../../locale/useStrings.cjs"),H=8,M=8,I=160;function S(a,r,c,o){if(typeof window>"u")return null;const f=window.innerWidth,g=window.innerHeight,i=M,l=H,t=a?.x??r?.left??i,N=a?.y??r?.bottom??i,u=g-N-i,h=N-i,p=f-t-i,x=t-i,d=u>=h,b=Math.max(d?u:h,I),k=Math.min(o,b-l);let v=d?N+l:N-l-k,w=p>=x?t+l:t-l-c;return w=Math.max(i,Math.min(w,f-c-i)),v=Math.max(i,Math.min(v,g-k-i)),{left:w,top:v,maxHeight:k}}function L(a,r,c){if(r)return r;if(!a)return[];if(c.entity){const o=a.inspect({kind:"entity",entityId:c.entity.id});if(o)return o.actions}if(c.surface){const o=a.inspect({kind:"surface",surfaceId:c.surface.id});if(o)return o.actions}return a.listActions()}function F({context:a,tools:r,anchorRect:c,anchorPoint:o,onClose:f,onSend:g,sending:i=!1,popover:l=!0}){const t=C.useStrings(),u=m.useContext(q.AegisRuntimeContext)?.runtime??null,h=m.useRef(null),[p,x]=m.useState(null),[d,b]=m.useState(()=>L(u,r,a));m.useEffect(()=>{const e=()=>{b(L(u,r,a))};if(e(),!(r!==void 0||!u))return u.subscribe(n=>{(n.type==="registry.changed"||n.type==="snapshot.changed")&&e()})},[u,r,a]);const k=m.useCallback(e=>{const n={prompt:e,context:a,tools:d,history:[]};u?.emitAskSubmit(n),g?.(n)},[u,a,d,g]);m.useEffect(()=>{if(!l)return;const e=_=>{_.key==="Escape"&&(_.stopPropagation(),f())},n=_=>{const y=h.current;y&&(_.target instanceof Node&&y.contains(_.target)||f())};return window.addEventListener("keydown",e,!0),window.addEventListener("mousedown",n,!0),()=>{window.removeEventListener("keydown",e,!0),window.removeEventListener("mousedown",n,!0)}},[f,l]);const v=!l||p!==null;m.useEffect(()=>{if(!v)return;const e=document.activeElement,n=h.current;return(n?.querySelector("textarea:not(:disabled)")??n)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[v]),R.useIsomorphicLayoutEffect(()=>{if(!l){x(null);return}const e=()=>{const n=h.current;if(!n)return;const _=n.scrollHeight||n.offsetHeight,y=n.offsetWidth,P=S(o??null,c??null,y,_);x(P)};return e(),window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[l,o,c,d,a]);const j=l?p?{position:"fixed",left:p.left,top:p.top,maxHeight:p.maxHeight}:{position:"fixed",left:-9999,top:-9999,visibility:"hidden"}:{},w=a.entity?.label??a.entity?.id,E=a.surface?.label??a.surface?.id;return s.jsxs("div",{ref:h,className:l?"aegis-ask-panel aegis-ask-panel--popover":"aegis-ask-panel",role:"dialog","aria-label":t.askPanelTitle,tabIndex:-1,"data-aegis-ask-panel":"open","data-ask-origin":a.origin,style:j,children:[s.jsxs("header",{className:"aegis-ask-panel__header",children:[s.jsx("div",{className:"aegis-ask-panel__title",children:t.askPanelTitle}),s.jsx("button",{type:"button",className:"aegis-ask-panel__close","aria-label":t.close,onClick:f,children:"×"})]}),s.jsxs("div",{className:"aegis-ask-panel__meta",children:[E&&s.jsxs("div",{className:"aegis-ask-panel__meta-row",children:[s.jsx("span",{className:"aegis-ask-panel__meta-label",children:t.askSurface}),s.jsx("span",{className:"aegis-ask-panel__meta-value",children:E})]}),w&&s.jsxs("div",{className:"aegis-ask-panel__meta-row",children:[s.jsx("span",{className:"aegis-ask-panel__meta-label",children:t.askEntity}),s.jsx("span",{className:"aegis-ask-panel__meta-value",children:w})]})]}),a.suggestions.length>0&&s.jsxs("div",{className:"aegis-ask-panel__section",children:[s.jsx("div",{className:"aegis-ask-panel__section-label",children:t.suggestions}),s.jsx("div",{className:"aegis-ask-panel__chips",children:a.suggestions.map(e=>s.jsx(A.Chip,{tone:"ghost",onClick:g&&!i?()=>{k(e)}:void 0,children:e},e))})]}),s.jsxs("div",{className:"aegis-ask-panel__section",children:[s.jsx("div",{className:"aegis-ask-panel__section-label",children:t.askToolsAvailable(d.length)}),d.length===0?s.jsx("div",{className:"aegis-ask-panel__empty",children:t.askNoTools}):s.jsx("ul",{className:"aegis-ask-panel__tools",children:d.slice(0,8).map(e=>s.jsxs("li",{className:"aegis-ask-panel__tool",children:[s.jsx("span",{className:"aegis-ask-panel__tool-id",children:e.id}),s.jsx("span",{className:"aegis-ask-panel__tool-label",children:e.label})]},e.id))})]}),g?s.jsx(T.ChatComposer,{className:"aegis-ask-panel__composer",onSend:k,sending:i,placeholder:t.askPlaceholder}):s.jsx("p",{className:"aegis-ask-panel__note",children:t.askNoAgent})]})}exports.AskPanel=F;
|
|
2
2
|
//# sourceMappingURL=AskPanel.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskPanel.cjs","sources":["../../../src/agent/ask/AskPanel.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactElement,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { ChatComposer } from '../../components/ui/ChatComposer';\nimport { Chip } from '../../components/ui/Chip';\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useStrings } from '../../locale';\nimport { AegisRuntimeContext } from '../core/aegisRuntimeContext';\nimport type { AegisRuntime } from '../core/runtime';\nimport type {\n AegisActionDescriptor,\n AskContext,\n AskRequest,\n} from '../core/types';\nimport './AskPanel.css';\n\nexport interface AskPanelProps {\n context: AskContext;\n /** Tools the agent could invoke. Defaults to deriving from snapshot. */\n tools?: AegisActionDescriptor[];\n /** Optional anchor — the panel positions itself near this rect. */\n anchorRect?: DOMRect | null;\n /** Preferred anchor point (e.g. mouse position). Wins over anchorRect. */\n anchorPoint?: { x: number; y: number } | null;\n onClose: () => void;\n /**\n * Hands the question to the agent. Without it the panel shows the\n * context and its tools but offers no way to ask.\n */\n onSend?: (request: AskRequest) => void;\n /** True while the agent is still answering; holds the composer. */\n sending?: boolean;\n /**\n * When true (default), a fixed popover that closes on Escape and on a\n * click outside it; when false, inline.\n */\n popover?: boolean;\n}\n\nconst PANEL_OFFSET_PX = 8;\nconst VIEWPORT_MARGIN_PX = 8;\nconst PANEL_MIN_HEIGHT_PX = 160;\n\ninterface Placement {\n left: number;\n top: number;\n maxHeight: number;\n}\n\nfunction placeNear(\n point: { x: number; y: number } | null,\n rect: DOMRect | null | undefined,\n panelWidth: number,\n panelHeight: number,\n): Placement | null {\n if (typeof window === 'undefined') {\n return null;\n }\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const margin = VIEWPORT_MARGIN_PX;\n const offset = PANEL_OFFSET_PX;\n\n // Anchor: prefer mouse point; fall back to rect's bottom-left corner.\n const ax = point?.x ?? rect?.left ?? margin;\n const ay = point?.y ?? rect?.bottom ?? margin;\n\n const spaceBelow = vh - ay - margin;\n const spaceAbove = ay - margin;\n const spaceRight = vw - ax - margin;\n const spaceLeft = ax - margin;\n\n // Pick vertical side with more room; allow shrinking max-height to fit.\n const placeBelow = spaceBelow >= spaceAbove;\n const verticalRoom = Math.max(\n placeBelow ? spaceBelow : spaceAbove,\n PANEL_MIN_HEIGHT_PX,\n );\n const maxHeight = Math.min(panelHeight, verticalRoom - offset);\n\n let top = placeBelow ? ay + offset : ay - offset - maxHeight;\n // Pick horizontal side with more room.\n const placeRight = spaceRight >= spaceLeft;\n let left = placeRight ? ax + offset : ax - offset - panelWidth;\n\n // Clamp into viewport.\n left = Math.max(margin, Math.min(left, vw - panelWidth - margin));\n top = Math.max(margin, Math.min(top, vh - maxHeight - margin));\n\n return { left, top, maxHeight };\n}\n\nfunction resolveTools(\n runtime: AegisRuntime | null,\n tools: AegisActionDescriptor[] | undefined,\n context: AskContext,\n): AegisActionDescriptor[] {\n if (tools) {\n return tools;\n }\n if (!runtime) {\n return [];\n }\n if (context.entity) {\n const r = runtime.inspect({ kind: 'entity', entityId: context.entity.id });\n if (r) {\n return r.actions;\n }\n }\n if (context.surface) {\n const r = runtime.inspect({\n kind: 'surface',\n surfaceId: context.surface.id,\n });\n if (r) {\n return r.actions;\n }\n }\n return runtime.listActions();\n}\n\n/**\n * Mounting it opens it: focus moves to its question field, or to the panel\n * when there is no agent to ask, and returns on unmount to the element that\n * had it.\n */\nexport function AskPanel({\n context,\n tools,\n anchorRect,\n anchorPoint,\n onClose,\n onSend,\n sending = false,\n popover = true,\n}: AskPanelProps): ReactElement {\n const strings = useStrings();\n const ctx = useContext(AegisRuntimeContext);\n const runtime = ctx?.runtime ?? null;\n const rootRef = useRef<HTMLDivElement>(null);\n const [placement, setPlacement] = useState<Placement | null>(null);\n\n const [resolvedTools, setResolvedTools] = useState<AegisActionDescriptor[]>(\n () => resolveTools(runtime, tools, context),\n );\n\n useEffect(() => {\n const refresh = (): void => {\n setResolvedTools(resolveTools(runtime, tools, context));\n };\n refresh();\n if (tools !== undefined || !runtime) {\n return;\n }\n return runtime.subscribe((e) => {\n if (e.type === 'registry.changed' || e.type === 'snapshot.changed') {\n refresh();\n }\n });\n }, [runtime, tools, context]);\n\n const ask = useCallback(\n (prompt: string) => {\n const request: AskRequest = {\n prompt,\n context,\n tools: resolvedTools,\n history: [],\n };\n runtime?.emitAskSubmit(request);\n onSend?.(request);\n },\n [runtime, context, resolvedTools, onSend],\n );\n\n useEffect(() => {\n if (!popover) {\n return;\n }\n const onKey = (e: KeyboardEvent): void => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onClose();\n }\n };\n const onDown = (e: MouseEvent): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n if (e.target instanceof Node && el.contains(e.target)) {\n return;\n }\n onClose();\n };\n window.addEventListener('keydown', onKey, true);\n window.addEventListener('mousedown', onDown, true);\n return () => {\n window.removeEventListener('keydown', onKey, true);\n window.removeEventListener('mousedown', onDown, true);\n };\n }, [onClose, popover]);\n\n // A popover is hidden, and so cannot take focus, until it is placed.\n const ready = !popover || placement !== null;\n useEffect(() => {\n if (!ready) {\n return;\n }\n const returnFocusTo = document.activeElement;\n const root = rootRef.current;\n (\n root?.querySelector<HTMLElement>('textarea:not(:disabled)') ?? root\n )?.focus();\n return () => {\n if (returnFocusTo instanceof HTMLElement && returnFocusTo.isConnected) {\n returnFocusTo.focus();\n }\n };\n }, [ready]);\n\n useIsomorphicLayoutEffect(() => {\n if (!popover) {\n setPlacement(null);\n return;\n }\n const compute = (): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n // Use the natural (unconstrained) size as the desired height; the\n // placement function will clamp it to the larger viewport gap.\n const naturalHeight = el.scrollHeight || el.offsetHeight;\n const width = el.offsetWidth;\n const next = placeNear(\n anchorPoint ?? null,\n anchorRect ?? null,\n width,\n naturalHeight,\n );\n setPlacement(next);\n };\n compute();\n window.addEventListener('resize', compute);\n window.addEventListener('scroll', compute, true);\n return () => {\n window.removeEventListener('resize', compute);\n window.removeEventListener('scroll', compute, true);\n };\n }, [popover, anchorPoint, anchorRect, resolvedTools, context]);\n\n const style: CSSProperties = popover\n ? placement\n ? {\n position: 'fixed',\n left: placement.left,\n top: placement.top,\n maxHeight: placement.maxHeight,\n }\n : // First paint before measurement: render off-screen to avoid flicker.\n {\n position: 'fixed',\n left: -9999,\n top: -9999,\n visibility: 'hidden',\n }\n : {};\n\n const headerLabel = context.entity?.label ?? context.entity?.id;\n const surfaceLabel = context.surface?.label ?? context.surface?.id;\n\n return (\n <div\n ref={rootRef}\n className=\"aegis-ask-panel\"\n role=\"dialog\"\n aria-label={strings.askPanelTitle}\n tabIndex={-1}\n data-aegis-ask-panel=\"open\"\n data-ask-origin={context.origin}\n style={style}\n >\n <header className=\"aegis-ask-panel__header\">\n <div className=\"aegis-ask-panel__title\">{strings.askPanelTitle}</div>\n <button\n type=\"button\"\n className=\"aegis-ask-panel__close\"\n aria-label={strings.close}\n onClick={onClose}\n >\n ×\n </button>\n </header>\n <div className=\"aegis-ask-panel__meta\">\n {surfaceLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askSurface}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{surfaceLabel}</span>\n </div>\n )}\n {headerLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askEntity}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{headerLabel}</span>\n </div>\n )}\n </div>\n {context.suggestions.length > 0 && (\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.suggestions}\n </div>\n <div className=\"aegis-ask-panel__chips\">\n {context.suggestions.map((s) => (\n <Chip\n key={s}\n tone=\"ghost\"\n onClick={\n onSend && !sending\n ? () => {\n ask(s);\n }\n : undefined\n }\n >\n {s}\n </Chip>\n ))}\n </div>\n </div>\n )}\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.askToolsAvailable(resolvedTools.length)}\n </div>\n {resolvedTools.length === 0 ? (\n <div className=\"aegis-ask-panel__empty\">{strings.askNoTools}</div>\n ) : (\n <ul className=\"aegis-ask-panel__tools\">\n {resolvedTools.slice(0, 8).map((t) => (\n <li key={t.id} className=\"aegis-ask-panel__tool\">\n <span className=\"aegis-ask-panel__tool-id\">{t.id}</span>\n <span className=\"aegis-ask-panel__tool-label\">{t.label}</span>\n </li>\n ))}\n </ul>\n )}\n </div>\n {onSend ? (\n <ChatComposer\n className=\"aegis-ask-panel__composer\"\n onSend={ask}\n sending={sending}\n placeholder={strings.askPlaceholder}\n />\n ) : (\n <p className=\"aegis-ask-panel__note\">{strings.askNoAgent}</p>\n )}\n </div>\n );\n}\n"],"names":["PANEL_OFFSET_PX","VIEWPORT_MARGIN_PX","PANEL_MIN_HEIGHT_PX","placeNear","point","rect","panelWidth","panelHeight","vw","vh","margin","offset","ax","ay","spaceBelow","spaceAbove","spaceRight","spaceLeft","placeBelow","verticalRoom","maxHeight","top","left","resolveTools","runtime","tools","context","r","AskPanel","anchorRect","anchorPoint","onClose","onSend","sending","popover","strings","useStrings","useContext","AegisRuntimeContext","rootRef","useRef","placement","setPlacement","useState","resolvedTools","setResolvedTools","useEffect","refresh","e","ask","useCallback","prompt","request","onKey","onDown","el","ready","returnFocusTo","root","useIsomorphicLayoutEffect","compute","naturalHeight","width","next","style","headerLabel","surfaceLabel","jsxs","jsx","s","Chip","t","ChatComposer"],"mappings":"qZA8CMA,EAAkB,EAClBC,EAAqB,EACrBC,EAAsB,IAQ5B,SAASC,EACPC,EACAC,EACAC,EACAC,EACkB,CAClB,GAAI,OAAO,OAAW,IACpB,OAAO,KAET,MAAMC,EAAK,OAAO,WACZC,EAAK,OAAO,YACZC,EAAST,EACTU,EAASX,EAGTY,EAAKR,GAAO,GAAKC,GAAM,MAAQK,EAC/BG,EAAKT,GAAO,GAAKC,GAAM,QAAUK,EAEjCI,EAAaL,EAAKI,EAAKH,EACvBK,EAAaF,EAAKH,EAClBM,EAAaR,EAAKI,EAAKF,EACvBO,EAAYL,EAAKF,EAGjBQ,EAAaJ,GAAcC,EAC3BI,EAAe,KAAK,IACxBD,EAAaJ,EAAaC,EAC1Bb,CAAA,EAEIkB,EAAY,KAAK,IAAIb,EAAaY,EAAeR,CAAM,EAE7D,IAAIU,EAAMH,EAAaL,EAAKF,EAASE,EAAKF,EAASS,EAG/CE,EADeN,GAAcC,EACTL,EAAKD,EAASC,EAAKD,EAASL,EAGpD,OAAAgB,EAAO,KAAK,IAAIZ,EAAQ,KAAK,IAAIY,EAAMd,EAAKF,EAAaI,CAAM,CAAC,EAChEW,EAAM,KAAK,IAAIX,EAAQ,KAAK,IAAIW,EAAKZ,EAAKW,EAAYV,CAAM,CAAC,EAEtD,CAAE,KAAAY,EAAM,IAAAD,EAAK,UAAAD,CAAA,CACtB,CAEA,SAASG,EACPC,EACAC,EACAC,EACyB,CACzB,GAAID,EACF,OAAOA,EAET,GAAI,CAACD,EACH,MAAO,CAAA,EAET,GAAIE,EAAQ,OAAQ,CAClB,MAAMC,EAAIH,EAAQ,QAAQ,CAAE,KAAM,SAAU,SAAUE,EAAQ,OAAO,GAAI,EACzE,GAAIC,EACF,OAAOA,EAAE,OAEb,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,EAAAA,IAAC,MAAA,CAAI,UAAU,iCACZ,SAAAjC,EAAQ,YACX,EACAiC,EAAAA,IAAC,OAAI,UAAU,yBACZ,WAAQ,YAAY,IAAKC,GACxBD,EAAAA,IAACE,EAAAA,KAAA,CAEC,KAAK,QACL,QACEtC,GAAU,CAACC,EACP,IAAM,CACJgB,EAAIoB,CAAC,CACP,EACA,OAGL,SAAAA,CAAA,EAVIA,CAAA,CAYR,CAAA,CACH,CAAA,EACF,EAEFF,EAAAA,KAAC,MAAA,CAAI,UAAU,2BACb,SAAA,CAAAC,EAAAA,IAAC,OAAI,UAAU,iCACZ,WAAQ,kBAAkBxB,EAAc,MAAM,EACjD,EACCA,EAAc,SAAW,EACxBwB,EAAAA,IAAC,MAAA,CAAI,UAAU,yBAA0B,SAAAjC,EAAQ,UAAA,CAAW,EAE5DiC,EAAAA,IAAC,KAAA,CAAG,UAAU,yBACX,SAAAxB,EAAc,MAAM,EAAG,CAAC,EAAE,IAAK2B,GAC9BJ,EAAAA,KAAC,KAAA,CAAc,UAAU,wBACvB,SAAA,CAAAC,EAAAA,IAAC,OAAA,CAAK,UAAU,2BAA4B,SAAAG,EAAE,GAAG,EACjDH,EAAAA,IAAC,OAAA,CAAK,UAAU,8BAA+B,WAAE,KAAA,CAAM,CAAA,GAFhDG,EAAE,EAGX,CACD,CAAA,CACH,CAAA,EAEJ,EACCvC,EACCoC,EAAAA,IAACI,EAAAA,aAAA,CACC,UAAU,4BACV,OAAQvB,EACR,QAAAhB,EACA,YAAaE,EAAQ,cAAA,CAAA,EAGvBiC,EAAAA,IAAC,IAAA,CAAE,UAAU,wBAAyB,WAAQ,UAAA,CAAW,CAAA,CAAA,CAAA,CAIjE"}
|
|
1
|
+
{"version":3,"file":"AskPanel.cjs","sources":["../../../src/agent/ask/AskPanel.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactElement,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { ChatComposer } from '../../components/ui/ChatComposer';\nimport { Chip } from '../../components/ui/Chip';\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useStrings } from '../../locale';\nimport { AegisRuntimeContext } from '../core/aegisRuntimeContext';\nimport type { AegisRuntime } from '../core/runtime';\nimport type {\n AegisActionDescriptor,\n AskContext,\n AskRequest,\n} from '../core/types';\nimport './AskPanel.css';\n\nexport interface AskPanelProps {\n context: AskContext;\n /** Tools the agent could invoke. Defaults to deriving from snapshot. */\n tools?: AegisActionDescriptor[];\n /** Optional anchor — the panel positions itself near this rect. */\n anchorRect?: DOMRect | null;\n /** Preferred anchor point (e.g. mouse position). Wins over anchorRect. */\n anchorPoint?: { x: number; y: number } | null;\n onClose: () => void;\n /**\n * Hands the question to the agent. Without it the panel shows the\n * context and its tools but offers no way to ask.\n */\n onSend?: (request: AskRequest) => void;\n /** True while the agent is still answering; holds the composer. */\n sending?: boolean;\n /**\n * When true (default), a fixed popover that closes on Escape and on a\n * click outside it; when false, inline.\n */\n popover?: boolean;\n}\n\nconst PANEL_OFFSET_PX = 8;\nconst VIEWPORT_MARGIN_PX = 8;\nconst PANEL_MIN_HEIGHT_PX = 160;\n\ninterface Placement {\n left: number;\n top: number;\n maxHeight: number;\n}\n\nfunction placeNear(\n point: { x: number; y: number } | null,\n rect: DOMRect | null | undefined,\n panelWidth: number,\n panelHeight: number,\n): Placement | null {\n if (typeof window === 'undefined') {\n return null;\n }\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const margin = VIEWPORT_MARGIN_PX;\n const offset = PANEL_OFFSET_PX;\n\n // Anchor: prefer mouse point; fall back to rect's bottom-left corner.\n const ax = point?.x ?? rect?.left ?? margin;\n const ay = point?.y ?? rect?.bottom ?? margin;\n\n const spaceBelow = vh - ay - margin;\n const spaceAbove = ay - margin;\n const spaceRight = vw - ax - margin;\n const spaceLeft = ax - margin;\n\n // Pick vertical side with more room; allow shrinking max-height to fit.\n const placeBelow = spaceBelow >= spaceAbove;\n const verticalRoom = Math.max(\n placeBelow ? spaceBelow : spaceAbove,\n PANEL_MIN_HEIGHT_PX,\n );\n const maxHeight = Math.min(panelHeight, verticalRoom - offset);\n\n let top = placeBelow ? ay + offset : ay - offset - maxHeight;\n // Pick horizontal side with more room.\n const placeRight = spaceRight >= spaceLeft;\n let left = placeRight ? ax + offset : ax - offset - panelWidth;\n\n // Clamp into viewport.\n left = Math.max(margin, Math.min(left, vw - panelWidth - margin));\n top = Math.max(margin, Math.min(top, vh - maxHeight - margin));\n\n return { left, top, maxHeight };\n}\n\nfunction resolveTools(\n runtime: AegisRuntime | null,\n tools: AegisActionDescriptor[] | undefined,\n context: AskContext,\n): AegisActionDescriptor[] {\n if (tools) {\n return tools;\n }\n if (!runtime) {\n return [];\n }\n if (context.entity) {\n const r = runtime.inspect({ kind: 'entity', entityId: context.entity.id });\n if (r) {\n return r.actions;\n }\n }\n if (context.surface) {\n const r = runtime.inspect({\n kind: 'surface',\n surfaceId: context.surface.id,\n });\n if (r) {\n return r.actions;\n }\n }\n return runtime.listActions();\n}\n\n/**\n * Mounting it opens it: focus moves to its question field, or to the panel\n * when there is no agent to ask, and returns on unmount to the element that\n * had it.\n */\nexport function AskPanel({\n context,\n tools,\n anchorRect,\n anchorPoint,\n onClose,\n onSend,\n sending = false,\n popover = true,\n}: AskPanelProps): ReactElement {\n const strings = useStrings();\n const ctx = useContext(AegisRuntimeContext);\n const runtime = ctx?.runtime ?? null;\n const rootRef = useRef<HTMLDivElement>(null);\n const [placement, setPlacement] = useState<Placement | null>(null);\n\n const [resolvedTools, setResolvedTools] = useState<AegisActionDescriptor[]>(\n () => resolveTools(runtime, tools, context),\n );\n\n useEffect(() => {\n const refresh = (): void => {\n setResolvedTools(resolveTools(runtime, tools, context));\n };\n refresh();\n if (tools !== undefined || !runtime) {\n return;\n }\n return runtime.subscribe((e) => {\n if (e.type === 'registry.changed' || e.type === 'snapshot.changed') {\n refresh();\n }\n });\n }, [runtime, tools, context]);\n\n const ask = useCallback(\n (prompt: string) => {\n const request: AskRequest = {\n prompt,\n context,\n tools: resolvedTools,\n history: [],\n };\n runtime?.emitAskSubmit(request);\n onSend?.(request);\n },\n [runtime, context, resolvedTools, onSend],\n );\n\n useEffect(() => {\n if (!popover) {\n return;\n }\n const onKey = (e: KeyboardEvent): void => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onClose();\n }\n };\n const onDown = (e: MouseEvent): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n if (e.target instanceof Node && el.contains(e.target)) {\n return;\n }\n onClose();\n };\n window.addEventListener('keydown', onKey, true);\n window.addEventListener('mousedown', onDown, true);\n return () => {\n window.removeEventListener('keydown', onKey, true);\n window.removeEventListener('mousedown', onDown, true);\n };\n }, [onClose, popover]);\n\n // A popover is hidden, and so cannot take focus, until it is placed.\n const ready = !popover || placement !== null;\n useEffect(() => {\n if (!ready) {\n return;\n }\n const returnFocusTo = document.activeElement;\n const root = rootRef.current;\n (\n root?.querySelector<HTMLElement>('textarea:not(:disabled)') ?? root\n )?.focus();\n return () => {\n if (returnFocusTo instanceof HTMLElement && returnFocusTo.isConnected) {\n returnFocusTo.focus();\n }\n };\n }, [ready]);\n\n useIsomorphicLayoutEffect(() => {\n if (!popover) {\n setPlacement(null);\n return;\n }\n const compute = (): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n // Use the natural (unconstrained) size as the desired height; the\n // placement function will clamp it to the larger viewport gap.\n const naturalHeight = el.scrollHeight || el.offsetHeight;\n const width = el.offsetWidth;\n const next = placeNear(\n anchorPoint ?? null,\n anchorRect ?? null,\n width,\n naturalHeight,\n );\n setPlacement(next);\n };\n compute();\n window.addEventListener('resize', compute);\n window.addEventListener('scroll', compute, true);\n return () => {\n window.removeEventListener('resize', compute);\n window.removeEventListener('scroll', compute, true);\n };\n }, [popover, anchorPoint, anchorRect, resolvedTools, context]);\n\n const style: CSSProperties = popover\n ? placement\n ? {\n position: 'fixed',\n left: placement.left,\n top: placement.top,\n maxHeight: placement.maxHeight,\n }\n : // First paint before measurement: render off-screen to avoid flicker.\n {\n position: 'fixed',\n left: -9999,\n top: -9999,\n visibility: 'hidden',\n }\n : {};\n\n const headerLabel = context.entity?.label ?? context.entity?.id;\n const surfaceLabel = context.surface?.label ?? context.surface?.id;\n\n return (\n <div\n ref={rootRef}\n className={\n popover ? 'aegis-ask-panel aegis-ask-panel--popover' : 'aegis-ask-panel'\n }\n role=\"dialog\"\n aria-label={strings.askPanelTitle}\n tabIndex={-1}\n data-aegis-ask-panel=\"open\"\n data-ask-origin={context.origin}\n style={style}\n >\n <header className=\"aegis-ask-panel__header\">\n <div className=\"aegis-ask-panel__title\">{strings.askPanelTitle}</div>\n <button\n type=\"button\"\n className=\"aegis-ask-panel__close\"\n aria-label={strings.close}\n onClick={onClose}\n >\n ×\n </button>\n </header>\n <div className=\"aegis-ask-panel__meta\">\n {surfaceLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askSurface}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{surfaceLabel}</span>\n </div>\n )}\n {headerLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askEntity}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{headerLabel}</span>\n </div>\n )}\n </div>\n {context.suggestions.length > 0 && (\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.suggestions}\n </div>\n <div className=\"aegis-ask-panel__chips\">\n {context.suggestions.map((s) => (\n <Chip\n key={s}\n tone=\"ghost\"\n onClick={\n onSend && !sending\n ? () => {\n ask(s);\n }\n : undefined\n }\n >\n {s}\n </Chip>\n ))}\n </div>\n </div>\n )}\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.askToolsAvailable(resolvedTools.length)}\n </div>\n {resolvedTools.length === 0 ? (\n <div className=\"aegis-ask-panel__empty\">{strings.askNoTools}</div>\n ) : (\n <ul className=\"aegis-ask-panel__tools\">\n {resolvedTools.slice(0, 8).map((t) => (\n <li key={t.id} className=\"aegis-ask-panel__tool\">\n <span className=\"aegis-ask-panel__tool-id\">{t.id}</span>\n <span className=\"aegis-ask-panel__tool-label\">{t.label}</span>\n </li>\n ))}\n </ul>\n )}\n </div>\n {onSend ? (\n <ChatComposer\n className=\"aegis-ask-panel__composer\"\n onSend={ask}\n sending={sending}\n placeholder={strings.askPlaceholder}\n />\n ) : (\n <p className=\"aegis-ask-panel__note\">{strings.askNoAgent}</p>\n )}\n </div>\n );\n}\n"],"names":["PANEL_OFFSET_PX","VIEWPORT_MARGIN_PX","PANEL_MIN_HEIGHT_PX","placeNear","point","rect","panelWidth","panelHeight","vw","vh","margin","offset","ax","ay","spaceBelow","spaceAbove","spaceRight","spaceLeft","placeBelow","verticalRoom","maxHeight","top","left","resolveTools","runtime","tools","context","r","AskPanel","anchorRect","anchorPoint","onClose","onSend","sending","popover","strings","useStrings","useContext","AegisRuntimeContext","rootRef","useRef","placement","setPlacement","useState","resolvedTools","setResolvedTools","useEffect","refresh","e","ask","useCallback","prompt","request","onKey","onDown","el","ready","returnFocusTo","root","useIsomorphicLayoutEffect","compute","naturalHeight","width","next","style","headerLabel","surfaceLabel","jsxs","jsx","s","Chip","t","ChatComposer"],"mappings":"qZA8CMA,EAAkB,EAClBC,EAAqB,EACrBC,EAAsB,IAQ5B,SAASC,EACPC,EACAC,EACAC,EACAC,EACkB,CAClB,GAAI,OAAO,OAAW,IACpB,OAAO,KAET,MAAMC,EAAK,OAAO,WACZC,EAAK,OAAO,YACZC,EAAST,EACTU,EAASX,EAGTY,EAAKR,GAAO,GAAKC,GAAM,MAAQK,EAC/BG,EAAKT,GAAO,GAAKC,GAAM,QAAUK,EAEjCI,EAAaL,EAAKI,EAAKH,EACvBK,EAAaF,EAAKH,EAClBM,EAAaR,EAAKI,EAAKF,EACvBO,EAAYL,EAAKF,EAGjBQ,EAAaJ,GAAcC,EAC3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AAA,CAAG,UAAU,yBACX,SAAAxB,EAAc,MAAM,EAAG,CAAC,EAAE,IAAK2B,GAC9BJ,EAAAA,KAAC,KAAA,CAAc,UAAU,wBACvB,SAAA,CAAAC,EAAAA,IAAC,OAAA,CAAK,UAAU,2BAA4B,SAAAG,EAAE,GAAG,EACjDH,EAAAA,IAAC,OAAA,CAAK,UAAU,8BAA+B,WAAE,KAAA,CAAM,CAAA,GAFhDG,EAAE,EAGX,CACD,CAAA,CACH,CAAA,EAEJ,EACCvC,EACCoC,EAAAA,IAACI,EAAAA,aAAA,CACC,UAAU,4BACV,OAAQvB,EACR,QAAAhB,EACA,YAAaE,EAAQ,cAAA,CAAA,EAGvBiC,EAAAA,IAAC,IAAA,CAAE,UAAU,wBAAyB,WAAQ,UAAA,CAAW,CAAA,CAAA,CAAA,CAIjE"}
|
|
@@ -10,12 +10,12 @@ const q = 8, z = 8, B = 160;
|
|
|
10
10
|
function G(s, r, o, c) {
|
|
11
11
|
if (typeof window > "u")
|
|
12
12
|
return null;
|
|
13
|
-
const
|
|
14
|
-
u ? d :
|
|
13
|
+
const p = window.innerWidth, f = window.innerHeight, i = z, l = q, t = s?.x ?? r?.left ?? i, N = s?.y ?? r?.bottom ?? i, d = f - N - i, g = N - i, h = p - t - i, y = t - i, u = d >= g, E = Math.max(
|
|
14
|
+
u ? d : g,
|
|
15
15
|
B
|
|
16
16
|
), k = Math.min(c, E - l);
|
|
17
|
-
let w = u ? N + l : N - l - k, v =
|
|
18
|
-
return v = Math.max(i, Math.min(v,
|
|
17
|
+
let w = u ? N + l : N - l - k, v = h >= y ? t + l : t - l - o;
|
|
18
|
+
return v = Math.max(i, Math.min(v, p - o - i)), w = Math.max(i, Math.min(w, f - k - i)), { left: v, top: w, maxHeight: k };
|
|
19
19
|
}
|
|
20
20
|
function H(s, r, o) {
|
|
21
21
|
if (r)
|
|
@@ -42,12 +42,12 @@ function Y({
|
|
|
42
42
|
tools: r,
|
|
43
43
|
anchorRect: o,
|
|
44
44
|
anchorPoint: c,
|
|
45
|
-
onClose:
|
|
46
|
-
onSend:
|
|
45
|
+
onClose: p,
|
|
46
|
+
onSend: f,
|
|
47
47
|
sending: i = !1,
|
|
48
48
|
popover: l = !0
|
|
49
49
|
}) {
|
|
50
|
-
const t = j(), d = R(X)?.runtime ?? null,
|
|
50
|
+
const t = j(), d = R(X)?.runtime ?? null, g = I(null), [h, y] = A(null), [u, E] = A(
|
|
51
51
|
() => H(d, r, s)
|
|
52
52
|
);
|
|
53
53
|
L(() => {
|
|
@@ -67,28 +67,28 @@ function Y({
|
|
|
67
67
|
tools: u,
|
|
68
68
|
history: []
|
|
69
69
|
};
|
|
70
|
-
d?.emitAskSubmit(a),
|
|
70
|
+
d?.emitAskSubmit(a), f?.(a);
|
|
71
71
|
},
|
|
72
|
-
[d, s, u,
|
|
72
|
+
[d, s, u, f]
|
|
73
73
|
);
|
|
74
74
|
L(() => {
|
|
75
75
|
if (!l)
|
|
76
76
|
return;
|
|
77
77
|
const e = (_) => {
|
|
78
|
-
_.key === "Escape" && (_.stopPropagation(),
|
|
78
|
+
_.key === "Escape" && (_.stopPropagation(), p());
|
|
79
79
|
}, a = (_) => {
|
|
80
|
-
const b =
|
|
81
|
-
b && (_.target instanceof Node && b.contains(_.target) ||
|
|
80
|
+
const b = g.current;
|
|
81
|
+
b && (_.target instanceof Node && b.contains(_.target) || p());
|
|
82
82
|
};
|
|
83
83
|
return window.addEventListener("keydown", e, !0), window.addEventListener("mousedown", a, !0), () => {
|
|
84
84
|
window.removeEventListener("keydown", e, !0), window.removeEventListener("mousedown", a, !0);
|
|
85
85
|
};
|
|
86
|
-
}, [
|
|
87
|
-
const w = !l ||
|
|
86
|
+
}, [p, l]);
|
|
87
|
+
const w = !l || h !== null;
|
|
88
88
|
L(() => {
|
|
89
89
|
if (!w)
|
|
90
90
|
return;
|
|
91
|
-
const e = document.activeElement, a =
|
|
91
|
+
const e = document.activeElement, a = g.current;
|
|
92
92
|
return (a?.querySelector("textarea:not(:disabled)") ?? a)?.focus(), () => {
|
|
93
93
|
e instanceof HTMLElement && e.isConnected && e.focus();
|
|
94
94
|
};
|
|
@@ -98,7 +98,7 @@ function Y({
|
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
const e = () => {
|
|
101
|
-
const a =
|
|
101
|
+
const a = g.current;
|
|
102
102
|
if (!a)
|
|
103
103
|
return;
|
|
104
104
|
const _ = a.scrollHeight || a.offsetHeight, b = a.offsetWidth, M = G(
|
|
@@ -113,11 +113,11 @@ function Y({
|
|
|
113
113
|
window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
|
|
114
114
|
};
|
|
115
115
|
}, [l, c, o, u, s]);
|
|
116
|
-
const T = l ?
|
|
116
|
+
const T = l ? h ? {
|
|
117
117
|
position: "fixed",
|
|
118
|
-
left:
|
|
119
|
-
top:
|
|
120
|
-
maxHeight:
|
|
118
|
+
left: h.left,
|
|
119
|
+
top: h.top,
|
|
120
|
+
maxHeight: h.maxHeight
|
|
121
121
|
} : (
|
|
122
122
|
// First paint before measurement: render off-screen to avoid flicker.
|
|
123
123
|
{
|
|
@@ -130,8 +130,8 @@ function Y({
|
|
|
130
130
|
return /* @__PURE__ */ m(
|
|
131
131
|
"div",
|
|
132
132
|
{
|
|
133
|
-
ref:
|
|
134
|
-
className: "aegis-ask-panel",
|
|
133
|
+
ref: g,
|
|
134
|
+
className: l ? "aegis-ask-panel aegis-ask-panel--popover" : "aegis-ask-panel",
|
|
135
135
|
role: "dialog",
|
|
136
136
|
"aria-label": t.askPanelTitle,
|
|
137
137
|
tabIndex: -1,
|
|
@@ -147,7 +147,7 @@ function Y({
|
|
|
147
147
|
type: "button",
|
|
148
148
|
className: "aegis-ask-panel__close",
|
|
149
149
|
"aria-label": t.close,
|
|
150
|
-
onClick:
|
|
150
|
+
onClick: p,
|
|
151
151
|
children: "×"
|
|
152
152
|
}
|
|
153
153
|
)
|
|
@@ -168,7 +168,7 @@ function Y({
|
|
|
168
168
|
S,
|
|
169
169
|
{
|
|
170
170
|
tone: "ghost",
|
|
171
|
-
onClick:
|
|
171
|
+
onClick: f && !i ? () => {
|
|
172
172
|
k(e);
|
|
173
173
|
} : void 0,
|
|
174
174
|
children: e
|
|
@@ -183,7 +183,7 @@ function Y({
|
|
|
183
183
|
/* @__PURE__ */ n("span", { className: "aegis-ask-panel__tool-label", children: e.label })
|
|
184
184
|
] }, e.id)) })
|
|
185
185
|
] }),
|
|
186
|
-
|
|
186
|
+
f ? /* @__PURE__ */ n(
|
|
187
187
|
x,
|
|
188
188
|
{
|
|
189
189
|
className: "aegis-ask-panel__composer",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskPanel.js","sources":["../../../src/agent/ask/AskPanel.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactElement,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { ChatComposer } from '../../components/ui/ChatComposer';\nimport { Chip } from '../../components/ui/Chip';\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useStrings } from '../../locale';\nimport { AegisRuntimeContext } from '../core/aegisRuntimeContext';\nimport type { AegisRuntime } from '../core/runtime';\nimport type {\n AegisActionDescriptor,\n AskContext,\n AskRequest,\n} from '../core/types';\nimport './AskPanel.css';\n\nexport interface AskPanelProps {\n context: AskContext;\n /** Tools the agent could invoke. Defaults to deriving from snapshot. */\n tools?: AegisActionDescriptor[];\n /** Optional anchor — the panel positions itself near this rect. */\n anchorRect?: DOMRect | null;\n /** Preferred anchor point (e.g. mouse position). Wins over anchorRect. */\n anchorPoint?: { x: number; y: number } | null;\n onClose: () => void;\n /**\n * Hands the question to the agent. Without it the panel shows the\n * context and its tools but offers no way to ask.\n */\n onSend?: (request: AskRequest) => void;\n /** True while the agent is still answering; holds the composer. */\n sending?: boolean;\n /**\n * When true (default), a fixed popover that closes on Escape and on a\n * click outside it; when false, inline.\n */\n popover?: boolean;\n}\n\nconst PANEL_OFFSET_PX = 8;\nconst VIEWPORT_MARGIN_PX = 8;\nconst PANEL_MIN_HEIGHT_PX = 160;\n\ninterface Placement {\n left: number;\n top: number;\n maxHeight: number;\n}\n\nfunction placeNear(\n point: { x: number; y: number } | null,\n rect: DOMRect | null | undefined,\n panelWidth: number,\n panelHeight: number,\n): Placement | null {\n if (typeof window === 'undefined') {\n return null;\n }\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const margin = VIEWPORT_MARGIN_PX;\n const offset = PANEL_OFFSET_PX;\n\n // Anchor: prefer mouse point; fall back to rect's bottom-left corner.\n const ax = point?.x ?? rect?.left ?? margin;\n const ay = point?.y ?? rect?.bottom ?? margin;\n\n const spaceBelow = vh - ay - margin;\n const spaceAbove = ay - margin;\n const spaceRight = vw - ax - margin;\n const spaceLeft = ax - margin;\n\n // Pick vertical side with more room; allow shrinking max-height to fit.\n const placeBelow = spaceBelow >= spaceAbove;\n const verticalRoom = Math.max(\n placeBelow ? spaceBelow : spaceAbove,\n PANEL_MIN_HEIGHT_PX,\n );\n const maxHeight = Math.min(panelHeight, verticalRoom - offset);\n\n let top = placeBelow ? ay + offset : ay - offset - maxHeight;\n // Pick horizontal side with more room.\n const placeRight = spaceRight >= spaceLeft;\n let left = placeRight ? ax + offset : ax - offset - panelWidth;\n\n // Clamp into viewport.\n left = Math.max(margin, Math.min(left, vw - panelWidth - margin));\n top = Math.max(margin, Math.min(top, vh - maxHeight - margin));\n\n return { left, top, maxHeight };\n}\n\nfunction resolveTools(\n runtime: AegisRuntime | null,\n tools: AegisActionDescriptor[] | undefined,\n context: AskContext,\n): AegisActionDescriptor[] {\n if (tools) {\n return tools;\n }\n if (!runtime) {\n return [];\n }\n if (context.entity) {\n const r = runtime.inspect({ kind: 'entity', entityId: context.entity.id });\n if (r) {\n return r.actions;\n }\n }\n if (context.surface) {\n const r = runtime.inspect({\n kind: 'surface',\n surfaceId: context.surface.id,\n });\n if (r) {\n return r.actions;\n }\n }\n return runtime.listActions();\n}\n\n/**\n * Mounting it opens it: focus moves to its question field, or to the panel\n * when there is no agent to ask, and returns on unmount to the element that\n * had it.\n */\nexport function AskPanel({\n context,\n tools,\n anchorRect,\n anchorPoint,\n onClose,\n onSend,\n sending = false,\n popover = true,\n}: AskPanelProps): ReactElement {\n const strings = useStrings();\n const ctx = useContext(AegisRuntimeContext);\n const runtime = ctx?.runtime ?? null;\n const rootRef = useRef<HTMLDivElement>(null);\n const [placement, setPlacement] = useState<Placement | null>(null);\n\n const [resolvedTools, setResolvedTools] = useState<AegisActionDescriptor[]>(\n () => resolveTools(runtime, tools, context),\n );\n\n useEffect(() => {\n const refresh = (): void => {\n setResolvedTools(resolveTools(runtime, tools, context));\n };\n refresh();\n if (tools !== undefined || !runtime) {\n return;\n }\n return runtime.subscribe((e) => {\n if (e.type === 'registry.changed' || e.type === 'snapshot.changed') {\n refresh();\n }\n });\n }, [runtime, tools, context]);\n\n const ask = useCallback(\n (prompt: string) => {\n const request: AskRequest = {\n prompt,\n context,\n tools: resolvedTools,\n history: [],\n };\n runtime?.emitAskSubmit(request);\n onSend?.(request);\n },\n [runtime, context, resolvedTools, onSend],\n );\n\n useEffect(() => {\n if (!popover) {\n return;\n }\n const onKey = (e: KeyboardEvent): void => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onClose();\n }\n };\n const onDown = (e: MouseEvent): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n if (e.target instanceof Node && el.contains(e.target)) {\n return;\n }\n onClose();\n };\n window.addEventListener('keydown', onKey, true);\n window.addEventListener('mousedown', onDown, true);\n return () => {\n window.removeEventListener('keydown', onKey, true);\n window.removeEventListener('mousedown', onDown, true);\n };\n }, [onClose, popover]);\n\n // A popover is hidden, and so cannot take focus, until it is placed.\n const ready = !popover || placement !== null;\n useEffect(() => {\n if (!ready) {\n return;\n }\n const returnFocusTo = document.activeElement;\n const root = rootRef.current;\n (\n root?.querySelector<HTMLElement>('textarea:not(:disabled)') ?? root\n )?.focus();\n return () => {\n if (returnFocusTo instanceof HTMLElement && returnFocusTo.isConnected) {\n returnFocusTo.focus();\n }\n };\n }, [ready]);\n\n useIsomorphicLayoutEffect(() => {\n if (!popover) {\n setPlacement(null);\n return;\n }\n const compute = (): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n // Use the natural (unconstrained) size as the desired height; the\n // placement function will clamp it to the larger viewport gap.\n const naturalHeight = el.scrollHeight || el.offsetHeight;\n const width = el.offsetWidth;\n const next = placeNear(\n anchorPoint ?? null,\n anchorRect ?? null,\n width,\n naturalHeight,\n );\n setPlacement(next);\n };\n compute();\n window.addEventListener('resize', compute);\n window.addEventListener('scroll', compute, true);\n return () => {\n window.removeEventListener('resize', compute);\n window.removeEventListener('scroll', compute, true);\n };\n }, [popover, anchorPoint, anchorRect, resolvedTools, context]);\n\n const style: CSSProperties = popover\n ? placement\n ? {\n position: 'fixed',\n left: placement.left,\n top: placement.top,\n maxHeight: placement.maxHeight,\n }\n : // First paint before measurement: render off-screen to avoid flicker.\n {\n position: 'fixed',\n left: -9999,\n top: -9999,\n visibility: 'hidden',\n }\n : {};\n\n const headerLabel = context.entity?.label ?? context.entity?.id;\n const surfaceLabel = context.surface?.label ?? context.surface?.id;\n\n return (\n <div\n ref={rootRef}\n className=\"aegis-ask-panel\"\n role=\"dialog\"\n aria-label={strings.askPanelTitle}\n tabIndex={-1}\n data-aegis-ask-panel=\"open\"\n data-ask-origin={context.origin}\n style={style}\n >\n <header className=\"aegis-ask-panel__header\">\n <div className=\"aegis-ask-panel__title\">{strings.askPanelTitle}</div>\n <button\n type=\"button\"\n className=\"aegis-ask-panel__close\"\n aria-label={strings.close}\n onClick={onClose}\n >\n ×\n </button>\n </header>\n <div className=\"aegis-ask-panel__meta\">\n {surfaceLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askSurface}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{surfaceLabel}</span>\n </div>\n )}\n {headerLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askEntity}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{headerLabel}</span>\n </div>\n )}\n </div>\n {context.suggestions.length > 0 && (\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.suggestions}\n </div>\n <div className=\"aegis-ask-panel__chips\">\n {context.suggestions.map((s) => (\n <Chip\n key={s}\n tone=\"ghost\"\n onClick={\n onSend && !sending\n ? () => {\n ask(s);\n }\n : undefined\n }\n >\n {s}\n </Chip>\n ))}\n </div>\n </div>\n )}\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.askToolsAvailable(resolvedTools.length)}\n </div>\n {resolvedTools.length === 0 ? (\n <div className=\"aegis-ask-panel__empty\">{strings.askNoTools}</div>\n ) : (\n <ul className=\"aegis-ask-panel__tools\">\n {resolvedTools.slice(0, 8).map((t) => (\n <li key={t.id} className=\"aegis-ask-panel__tool\">\n <span className=\"aegis-ask-panel__tool-id\">{t.id}</span>\n <span className=\"aegis-ask-panel__tool-label\">{t.label}</span>\n </li>\n ))}\n </ul>\n )}\n </div>\n {onSend ? (\n <ChatComposer\n className=\"aegis-ask-panel__composer\"\n onSend={ask}\n sending={sending}\n placeholder={strings.askPlaceholder}\n />\n ) : (\n <p className=\"aegis-ask-panel__note\">{strings.askNoAgent}</p>\n )}\n </div>\n );\n}\n"],"names":["PANEL_OFFSET_PX","VIEWPORT_MARGIN_PX","PANEL_MIN_HEIGHT_PX","placeNear","point","rect","panelWidth","panelHeight","vw","vh","margin","offset","ax","ay","spaceBelow","spaceAbove","spaceRight","spaceLeft","placeBelow","verticalRoom","maxHeight","top","left","resolveTools","runtime","tools","context","r","AskPanel","anchorRect","anchorPoint","onClose","onSend","sending","popover","strings","useStrings","useContext","AegisRuntimeContext","rootRef","useRef","placement","setPlacement","useState","resolvedTools","setResolvedTools","useEffect","refresh","e","ask","useCallback","prompt","request","onKey","onDown","el","ready","returnFocusTo","root","useIsomorphicLayoutEffect","compute","naturalHeight","width","next","style","headerLabel","surfaceLabel","jsxs","jsx","s","Chip","t","ChatComposer"],"mappings":";;;;;;;;AA8CA,MAAMA,IAAkB,GAClBC,IAAqB,GACrBC,IAAsB;AAQ5B,SAASC,EACPC,GACAC,GACAC,GACAC,GACkB;AAClB,MAAI,OAAO,SAAW;AACpB,WAAO;AAET,QAAMC,IAAK,OAAO,YACZC,IAAK,OAAO,aACZC,IAAST,GACTU,IAASX,GAGTY,IAAKR,GAAO,KAAKC,GAAM,QAAQK,GAC/BG,IAAKT,GAAO,KAAKC,GAAM,UAAUK,GAEjCI,IAAaL,IAAKI,IAAKH,GACvBK,IAAaF,IAAKH,GAClBM,IAAaR,IAAKI,IAAKF,GACvBO,IAAYL,IAAKF,GAGjBQ,IAAaJ,KAAcC,GAC3BI,IAAe,KAAK;AAAA,IACxBD,IAAaJ,IAAaC;AAAA,IAC1Bb;AAAA,EAAA,GAEIkB,IAAY,KAAK,IAAIb,GAAaY,IAAeR,CAAM;AAE7D,MAAIU,IAAMH,IAAaL,IAAKF,IAASE,IAAKF,IAASS,GAG/CE,IADeN,KAAcC,IACTL,IAAKD,IAASC,IAAKD,IAASL;AAGpD,SAAAgB,IAAO,KAAK,IAAIZ,GAAQ,KAAK,IAAIY,GAAMd,IAAKF,IAAaI,CAAM,CAAC,GAChEW,IAAM,KAAK,IAAIX,GAAQ,KAAK,IAAIW,GAAKZ,IAAKW,IAAYV,CAAM,CAAC,GAEtD,EAAE,MAAAY,GAAM,KAAAD,GAAK,WAAAD,EAAA;AACtB;AAEA,SAASG,EACPC,GACAC,GACAC,GACyB;AACzB,MAAID;AACF,WAAOA;AAET,MAAI,CAACD;AACH,WAAO,CAAA;AAET,MAAIE,EAAQ,QAAQ;AAClB,UAAMC,IAAIH,EAAQ,QAAQ,EAAE,MAAM,UAAU,UAAUE,EAAQ,OAAO,IAAI;AACzE,QAAIC;AACF,aAAOA,E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Ac,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC2B,MAC9B,gBAAAJ,EAAC,MAAA,EAAc,WAAU,yBACvB,UAAA;AAAA,YAAA,gBAAAC,EAAC,QAAA,EAAK,WAAU,4BAA4B,UAAAG,EAAE,IAAG;AAAA,YACjD,gBAAAH,EAAC,QAAA,EAAK,WAAU,+BAA+B,YAAE,MAAA,CAAM;AAAA,UAAA,KAFhDG,EAAE,EAGX,CACD,EAAA,CACH;AAAA,QAAA,GAEJ;AAAA,QACCvC,IACC,gBAAAoC;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,QAAQvB;AAAA,YACR,SAAAhB;AAAA,YACA,aAAaE,EAAQ;AAAA,UAAA;AAAA,QAAA,IAGvB,gBAAAiC,EAAC,KAAA,EAAE,WAAU,yBAAyB,YAAQ,WAAA,CAAW;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIjE;"}
|
|
1
|
+
{"version":3,"file":"AskPanel.js","sources":["../../../src/agent/ask/AskPanel.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactElement,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { ChatComposer } from '../../components/ui/ChatComposer';\nimport { Chip } from '../../components/ui/Chip';\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useStrings } from '../../locale';\nimport { AegisRuntimeContext } from '../core/aegisRuntimeContext';\nimport type { AegisRuntime } from '../core/runtime';\nimport type {\n AegisActionDescriptor,\n AskContext,\n AskRequest,\n} from '../core/types';\nimport './AskPanel.css';\n\nexport interface AskPanelProps {\n context: AskContext;\n /** Tools the agent could invoke. Defaults to deriving from snapshot. */\n tools?: AegisActionDescriptor[];\n /** Optional anchor — the panel positions itself near this rect. */\n anchorRect?: DOMRect | null;\n /** Preferred anchor point (e.g. mouse position). Wins over anchorRect. */\n anchorPoint?: { x: number; y: number } | null;\n onClose: () => void;\n /**\n * Hands the question to the agent. Without it the panel shows the\n * context and its tools but offers no way to ask.\n */\n onSend?: (request: AskRequest) => void;\n /** True while the agent is still answering; holds the composer. */\n sending?: boolean;\n /**\n * When true (default), a fixed popover that closes on Escape and on a\n * click outside it; when false, inline.\n */\n popover?: boolean;\n}\n\nconst PANEL_OFFSET_PX = 8;\nconst VIEWPORT_MARGIN_PX = 8;\nconst PANEL_MIN_HEIGHT_PX = 160;\n\ninterface Placement {\n left: number;\n top: number;\n maxHeight: number;\n}\n\nfunction placeNear(\n point: { x: number; y: number } | null,\n rect: DOMRect | null | undefined,\n panelWidth: number,\n panelHeight: number,\n): Placement | null {\n if (typeof window === 'undefined') {\n return null;\n }\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const margin = VIEWPORT_MARGIN_PX;\n const offset = PANEL_OFFSET_PX;\n\n // Anchor: prefer mouse point; fall back to rect's bottom-left corner.\n const ax = point?.x ?? rect?.left ?? margin;\n const ay = point?.y ?? rect?.bottom ?? margin;\n\n const spaceBelow = vh - ay - margin;\n const spaceAbove = ay - margin;\n const spaceRight = vw - ax - margin;\n const spaceLeft = ax - margin;\n\n // Pick vertical side with more room; allow shrinking max-height to fit.\n const placeBelow = spaceBelow >= spaceAbove;\n const verticalRoom = Math.max(\n placeBelow ? spaceBelow : spaceAbove,\n PANEL_MIN_HEIGHT_PX,\n );\n const maxHeight = Math.min(panelHeight, verticalRoom - offset);\n\n let top = placeBelow ? ay + offset : ay - offset - maxHeight;\n // Pick horizontal side with more room.\n const placeRight = spaceRight >= spaceLeft;\n let left = placeRight ? ax + offset : ax - offset - panelWidth;\n\n // Clamp into viewport.\n left = Math.max(margin, Math.min(left, vw - panelWidth - margin));\n top = Math.max(margin, Math.min(top, vh - maxHeight - margin));\n\n return { left, top, maxHeight };\n}\n\nfunction resolveTools(\n runtime: AegisRuntime | null,\n tools: AegisActionDescriptor[] | undefined,\n context: AskContext,\n): AegisActionDescriptor[] {\n if (tools) {\n return tools;\n }\n if (!runtime) {\n return [];\n }\n if (context.entity) {\n const r = runtime.inspect({ kind: 'entity', entityId: context.entity.id });\n if (r) {\n return r.actions;\n }\n }\n if (context.surface) {\n const r = runtime.inspect({\n kind: 'surface',\n surfaceId: context.surface.id,\n });\n if (r) {\n return r.actions;\n }\n }\n return runtime.listActions();\n}\n\n/**\n * Mounting it opens it: focus moves to its question field, or to the panel\n * when there is no agent to ask, and returns on unmount to the element that\n * had it.\n */\nexport function AskPanel({\n context,\n tools,\n anchorRect,\n anchorPoint,\n onClose,\n onSend,\n sending = false,\n popover = true,\n}: AskPanelProps): ReactElement {\n const strings = useStrings();\n const ctx = useContext(AegisRuntimeContext);\n const runtime = ctx?.runtime ?? null;\n const rootRef = useRef<HTMLDivElement>(null);\n const [placement, setPlacement] = useState<Placement | null>(null);\n\n const [resolvedTools, setResolvedTools] = useState<AegisActionDescriptor[]>(\n () => resolveTools(runtime, tools, context),\n );\n\n useEffect(() => {\n const refresh = (): void => {\n setResolvedTools(resolveTools(runtime, tools, context));\n };\n refresh();\n if (tools !== undefined || !runtime) {\n return;\n }\n return runtime.subscribe((e) => {\n if (e.type === 'registry.changed' || e.type === 'snapshot.changed') {\n refresh();\n }\n });\n }, [runtime, tools, context]);\n\n const ask = useCallback(\n (prompt: string) => {\n const request: AskRequest = {\n prompt,\n context,\n tools: resolvedTools,\n history: [],\n };\n runtime?.emitAskSubmit(request);\n onSend?.(request);\n },\n [runtime, context, resolvedTools, onSend],\n );\n\n useEffect(() => {\n if (!popover) {\n return;\n }\n const onKey = (e: KeyboardEvent): void => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onClose();\n }\n };\n const onDown = (e: MouseEvent): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n if (e.target instanceof Node && el.contains(e.target)) {\n return;\n }\n onClose();\n };\n window.addEventListener('keydown', onKey, true);\n window.addEventListener('mousedown', onDown, true);\n return () => {\n window.removeEventListener('keydown', onKey, true);\n window.removeEventListener('mousedown', onDown, true);\n };\n }, [onClose, popover]);\n\n // A popover is hidden, and so cannot take focus, until it is placed.\n const ready = !popover || placement !== null;\n useEffect(() => {\n if (!ready) {\n return;\n }\n const returnFocusTo = document.activeElement;\n const root = rootRef.current;\n (\n root?.querySelector<HTMLElement>('textarea:not(:disabled)') ?? root\n )?.focus();\n return () => {\n if (returnFocusTo instanceof HTMLElement && returnFocusTo.isConnected) {\n returnFocusTo.focus();\n }\n };\n }, [ready]);\n\n useIsomorphicLayoutEffect(() => {\n if (!popover) {\n setPlacement(null);\n return;\n }\n const compute = (): void => {\n const el = rootRef.current;\n if (!el) {\n return;\n }\n // Use the natural (unconstrained) size as the desired height; the\n // placement function will clamp it to the larger viewport gap.\n const naturalHeight = el.scrollHeight || el.offsetHeight;\n const width = el.offsetWidth;\n const next = placeNear(\n anchorPoint ?? null,\n anchorRect ?? null,\n width,\n naturalHeight,\n );\n setPlacement(next);\n };\n compute();\n window.addEventListener('resize', compute);\n window.addEventListener('scroll', compute, true);\n return () => {\n window.removeEventListener('resize', compute);\n window.removeEventListener('scroll', compute, true);\n };\n }, [popover, anchorPoint, anchorRect, resolvedTools, context]);\n\n const style: CSSProperties = popover\n ? placement\n ? {\n position: 'fixed',\n left: placement.left,\n top: placement.top,\n maxHeight: placement.maxHeight,\n }\n : // First paint before measurement: render off-screen to avoid flicker.\n {\n position: 'fixed',\n left: -9999,\n top: -9999,\n visibility: 'hidden',\n }\n : {};\n\n const headerLabel = context.entity?.label ?? context.entity?.id;\n const surfaceLabel = context.surface?.label ?? context.surface?.id;\n\n return (\n <div\n ref={rootRef}\n className={\n popover ? 'aegis-ask-panel aegis-ask-panel--popover' : 'aegis-ask-panel'\n }\n role=\"dialog\"\n aria-label={strings.askPanelTitle}\n tabIndex={-1}\n data-aegis-ask-panel=\"open\"\n data-ask-origin={context.origin}\n style={style}\n >\n <header className=\"aegis-ask-panel__header\">\n <div className=\"aegis-ask-panel__title\">{strings.askPanelTitle}</div>\n <button\n type=\"button\"\n className=\"aegis-ask-panel__close\"\n aria-label={strings.close}\n onClick={onClose}\n >\n ×\n </button>\n </header>\n <div className=\"aegis-ask-panel__meta\">\n {surfaceLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askSurface}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{surfaceLabel}</span>\n </div>\n )}\n {headerLabel && (\n <div className=\"aegis-ask-panel__meta-row\">\n <span className=\"aegis-ask-panel__meta-label\">\n {strings.askEntity}\n </span>\n <span className=\"aegis-ask-panel__meta-value\">{headerLabel}</span>\n </div>\n )}\n </div>\n {context.suggestions.length > 0 && (\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.suggestions}\n </div>\n <div className=\"aegis-ask-panel__chips\">\n {context.suggestions.map((s) => (\n <Chip\n key={s}\n tone=\"ghost\"\n onClick={\n onSend && !sending\n ? () => {\n ask(s);\n }\n : undefined\n }\n >\n {s}\n </Chip>\n ))}\n </div>\n </div>\n )}\n <div className=\"aegis-ask-panel__section\">\n <div className=\"aegis-ask-panel__section-label\">\n {strings.askToolsAvailable(resolvedTools.length)}\n </div>\n {resolvedTools.length === 0 ? (\n <div className=\"aegis-ask-panel__empty\">{strings.askNoTools}</div>\n ) : (\n <ul className=\"aegis-ask-panel__tools\">\n {resolvedTools.slice(0, 8).map((t) => (\n <li key={t.id} className=\"aegis-ask-panel__tool\">\n <span className=\"aegis-ask-panel__tool-id\">{t.id}</span>\n <span className=\"aegis-ask-panel__tool-label\">{t.label}</span>\n </li>\n ))}\n </ul>\n )}\n </div>\n {onSend ? (\n <ChatComposer\n className=\"aegis-ask-panel__composer\"\n onSend={ask}\n sending={sending}\n placeholder={strings.askPlaceholder}\n />\n ) : (\n <p className=\"aegis-ask-panel__note\">{strings.askNoAgent}</p>\n )}\n </div>\n );\n}\n"],"names":["PANEL_OFFSET_PX","VIEWPORT_MARGIN_PX","PANEL_MIN_HEIGHT_PX","placeNear","point","rect","panelWidth","panelHeight","vw","vh","margin","offset","ax","ay","spaceBelow","spaceAbove","spaceRight","spaceLeft","placeBelow","verticalRoom","maxHeight","top","left","resolveTools","runtime","tools","context","r","AskPanel","anchorRect","anchorPoint","onClose","onSend","sending","popover","strings","useStrings","useContext","AegisRuntimeContext","rootRef","useRef","placement","setPlacement","useState","resolvedTools","setResolvedTools","useEffect","refresh","e","ask","useCallback","prompt","request","onKey","onDown","el","ready","returnFocusTo","root","useIsomorphicLayoutEffect","compute","naturalHeight","width","next","style","headerLabel","surfaceLabel","jsxs","jsx","s","Chip","t","ChatComposer"],"mappings":";;;;;;;;AA8CA,MAAMA,IAAkB,GAClBC,IAAqB,GACrBC,IAAsB;AAQ5B,SAASC,EACPC,GACAC,GACAC,GACAC,GACkB;AAClB,MAAI,OAAO,SAAW;AACpB,WAAO;AAET,QAAMC,IAAK,OAAO,YACZC,IAAK,OAAO,aACZC,IAAST,GACTU,IAASX,GAGTY,IAAKR,GAAO,KAAKC,GAAM,QAAQK,GAC/BG,IAAKT,GAAO,KAAKC,GAAM,UAAUK,GAEjCI,IAAaL,IAAKI,IAAKH,GACvBK,IAAaF,IAAKH,GAClBM,IAAaR,IAAKI,IAAKF,GACvBO,IAAYL,IAAKF,GAGjBQ,IAAaJ,KAAcC,GAC3BI,IAAe,KAAK;AAAA,IACxBD,IAAaJ,IAAaC;AAAA,IAC1Bb;AAAA,EAAA,GAEIkB,IAAY,KAAK,IAAIb,GAAaY,IAAeR,CAAM;AAE7D,MAAIU,IAAMH,IAAaL,IAAKF,IAASE,IAAKF,IAASS,GAG/CE,IADeN,KAAcC,IACTL,IAAKD,IAASC,IAAKD,IAASL;AAGpD,SAAAgB,IAAO,KAAK,IAAIZ,GAAQ,KAAK,IAAIY,GAAMd,IAAKF,IAAaI,CAAM,CAAC,GAChEW,IAAM,KAAK,IAAIX,GAAQ,KAAK,IAAIW,GAAKZ,IAAKW,IAAYV,CAAM,CAAC,GAEtD,EAAE,MAAAY,GAAM,KAAAD,GAAK,WAAAD,EAAA;AACtB;AAE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AAA,UAAA,gBAAAC,EAAC,SAAI,WAAU,kCACZ,YAAQ,kBAAkBxB,EAAc,MAAM,GACjD;AAAA,UACCA,EAAc,WAAW,IACxB,gBAAAwB,EAAC,OAAA,EAAI,WAAU,0BAA0B,UAAAjC,EAAQ,WAAA,CAAW,IAE5D,gBAAAiC,EAAC,MAAA,EAAG,WAAU,0BACX,UAAAxB,EAAc,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC2B,MAC9B,gBAAAJ,EAAC,MAAA,EAAc,WAAU,yBACvB,UAAA;AAAA,YAAA,gBAAAC,EAAC,QAAA,EAAK,WAAU,4BAA4B,UAAAG,EAAE,IAAG;AAAA,YACjD,gBAAAH,EAAC,QAAA,EAAK,WAAU,+BAA+B,YAAE,MAAA,CAAM;AAAA,UAAA,KAFhDG,EAAE,EAGX,CACD,EAAA,CACH;AAAA,QAAA,GAEJ;AAAA,QACCvC,IACC,gBAAAoC;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,QAAQvB;AAAA,YACR,SAAAhB;AAAA,YACA,aAAaE,EAAQ;AAAA,UAAA;AAAA,QAAA,IAGvB,gBAAAiC,EAAC,KAAA,EAAE,WAAU,yBAAyB,YAAQ,WAAA,CAAW;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIjE;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.cjs","sources":["../../../src/components/ui/Button.tsx"],"sourcesContent":["import {\n type ButtonHTMLAttributes,\n type MouseEvent,\n type ReactNode,\n forwardRef,\n useCallback,\n} from 'react';\n\nimport { useAegisAction } from '../../agent/core/hooks';\nimport type { AegisAction } from '../../agent/core/types';\nimport './Button.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport type ButtonTone
|
|
1
|
+
{"version":3,"file":"Button.cjs","sources":["../../../src/components/ui/Button.tsx"],"sourcesContent":["import {\n type ButtonHTMLAttributes,\n type MouseEvent,\n type ReactNode,\n forwardRef,\n useCallback,\n} from 'react';\n\nimport { useAegisAction } from '../../agent/core/hooks';\nimport type { AegisAction } from '../../agent/core/types';\nimport './Button.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport type ButtonTone =\n | 'primary'\n | 'secondary'\n | 'ghost'\n | 'glass'\n | 'caution';\n\ntype ButtonIconPosition = 'start' | 'end';\n\ninterface ButtonLookProps {\n children: ReactNode;\n /**\n * Visual treatment. `glass` is the secondary button frosted for a tinted,\n * gradient or image background. `caution` is a destructive or\n * irreversible action, e.g. delete: the caution wash and border, never\n * the anomaly red, which marks failures.\n */\n tone?: ButtonTone;\n /** Icon beside the label, sized to the button's icon slot. */\n icon?: ReactNode;\n /** Side of the label the icon sits on. */\n iconPosition?: ButtonIconPosition;\n}\n\nfunction buttonClassName(\n tone: ButtonTone,\n className: string | undefined,\n): string {\n return ['aegis-button', `aegis-button--${tone}`, className ?? '']\n .filter(Boolean)\n .join(' ');\n}\n\nfunction ButtonContent({\n children,\n icon,\n iconPosition,\n}: Pick<ButtonLookProps, 'children' | 'icon'> & {\n iconPosition: ButtonIconPosition;\n}) {\n const iconSlot =\n icon === undefined ? null : (\n <span className=\"aegis-button__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n );\n return (\n <>\n {iconPosition === 'start' && iconSlot}\n {children}\n {iconPosition === 'end' && iconSlot}\n </>\n );\n}\n\ntype NativeButtonProps = Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n 'type' | 'children'\n>;\n\ninterface ButtonProps extends NativeButtonProps, ButtonLookProps {\n /** Optional aegis-ui agent action — also wires the agent runtime. */\n action?: AegisAction<void, unknown>;\n /** Native HTML button type. */\n type?: 'button' | 'submit' | 'reset';\n}\n\n/** A toggle button passes `aria-pressed`; the pressed state is the inverted fill. */\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n children,\n tone = 'primary',\n icon,\n iconPosition = 'start',\n action,\n onClick,\n disabled,\n className,\n type = 'button',\n title,\n ...rest\n },\n ref,\n ) => {\n const bound = useAegisAction<void, unknown>(action);\n const isUnavailable = action ? !bound.available : false;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>): void => {\n onClick?.(event);\n if (event.defaultPrevented) {\n return;\n }\n if (action) {\n void bound.invoke();\n }\n },\n [onClick, action, bound],\n );\n\n const resolvedTitle =\n title ?? (isUnavailable ? bound.unavailableReason : undefined);\n\n return (\n <button\n ref={ref}\n type={type}\n className={buttonClassName(tone, className)}\n disabled={disabled ?? isUnavailable}\n title={resolvedTitle}\n data-agent-action-id={action?.id}\n onClick={handleClick}\n {...rest}\n >\n <ButtonContent icon={icon} iconPosition={iconPosition}>\n {children}\n </ButtonContent>\n </button>\n );\n },\n);\nButton.displayName = 'Button';\n\ninterface ButtonLinkProps extends ButtonLookProps {\n /** Destination; the control navigates instead of firing a handler. */\n to: string;\n /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */\n linkComponent?: LinkComponent;\n className?: string;\n}\n\n/** A link that looks like a Button, for actions that open another page. */\nexport function ButtonLink({\n to,\n children,\n tone = 'primary',\n icon,\n iconPosition = 'start',\n linkComponent,\n className,\n}: ButtonLinkProps) {\n const LinkImpl = linkComponent ?? DefaultLink;\n return (\n <LinkImpl to={to} className={buttonClassName(tone, className)}>\n <ButtonContent icon={icon} iconPosition={iconPosition}>\n {children}\n </ButtonContent>\n </LinkImpl>\n );\n}\n"],"names":["buttonClassName","tone","className","ButtonContent","children","icon","iconPosition","iconSlot","jsx","jsxs","Fragment","Button","forwardRef","action","onClick","disabled","type","title","rest","ref","bound","useAegisAction","isUnavailable","handleClick","useCallback","event","resolvedTitle","ButtonLink","to","linkComponent","LinkImpl","DefaultLink"],"mappings":"mPAqCA,SAASA,EACPC,EACAC,EACQ,CACR,MAAO,CAAC,eAAgB,iBAAiBD,CAAI,GAAIC,GAAa,EAAE,EAC7D,OAAO,OAAO,EACd,KAAK,GAAG,CACb,CAEA,SAASC,EAAc,CACrB,SAAAC,EACA,KAAAC,E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,EAAQ,UAAW5B,EAAgBC,EAAMC,CAAS,EAC1D,SAAAM,EAAAA,IAACL,EAAA,CAAc,KAAAE,EAAY,aAAAC,EACxB,SAAAF,EACH,EACF,CAEJ"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
import { AegisAction } from '../../agent/core/types';
|
|
3
3
|
import { LinkComponent } from './linkComponent';
|
|
4
|
-
export type ButtonTone = 'primary' | 'secondary' | 'ghost' | 'glass';
|
|
4
|
+
export type ButtonTone = 'primary' | 'secondary' | 'ghost' | 'glass' | 'caution';
|
|
5
5
|
type ButtonIconPosition = 'start' | 'end';
|
|
6
6
|
interface ButtonLookProps {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
/**
|
|
9
9
|
* Visual treatment. `glass` is the secondary button frosted for a tinted,
|
|
10
|
-
* gradient or image background.
|
|
10
|
+
* gradient or image background. `caution` is a destructive or
|
|
11
|
+
* irreversible action, e.g. delete: the caution wash and border, never
|
|
12
|
+
* the anomaly red, which marks failures.
|
|
11
13
|
*/
|
|
12
14
|
tone?: ButtonTone;
|
|
13
15
|
/** Icon beside the label, sized to the button's icon slot. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../../src/components/ui/Button.tsx"],"sourcesContent":["import {\n type ButtonHTMLAttributes,\n type MouseEvent,\n type ReactNode,\n forwardRef,\n useCallback,\n} from 'react';\n\nimport { useAegisAction } from '../../agent/core/hooks';\nimport type { AegisAction } from '../../agent/core/types';\nimport './Button.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport type ButtonTone
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../../src/components/ui/Button.tsx"],"sourcesContent":["import {\n type ButtonHTMLAttributes,\n type MouseEvent,\n type ReactNode,\n forwardRef,\n useCallback,\n} from 'react';\n\nimport { useAegisAction } from '../../agent/core/hooks';\nimport type { AegisAction } from '../../agent/core/types';\nimport './Button.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport type ButtonTone =\n | 'primary'\n | 'secondary'\n | 'ghost'\n | 'glass'\n | 'caution';\n\ntype ButtonIconPosition = 'start' | 'end';\n\ninterface ButtonLookProps {\n children: ReactNode;\n /**\n * Visual treatment. `glass` is the secondary button frosted for a tinted,\n * gradient or image background. `caution` is a destructive or\n * irreversible action, e.g. delete: the caution wash and border, never\n * the anomaly red, which marks failures.\n */\n tone?: ButtonTone;\n /** Icon beside the label, sized to the button's icon slot. */\n icon?: ReactNode;\n /** Side of the label the icon sits on. */\n iconPosition?: ButtonIconPosition;\n}\n\nfunction buttonClassName(\n tone: ButtonTone,\n className: string | undefined,\n): string {\n return ['aegis-button', `aegis-button--${tone}`, className ?? '']\n .filter(Boolean)\n .join(' ');\n}\n\nfunction ButtonContent({\n children,\n icon,\n iconPosition,\n}: Pick<ButtonLookProps, 'children' | 'icon'> & {\n iconPosition: ButtonIconPosition;\n}) {\n const iconSlot =\n icon === undefined ? null : (\n <span className=\"aegis-button__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n );\n return (\n <>\n {iconPosition === 'start' && iconSlot}\n {children}\n {iconPosition === 'end' && iconSlot}\n </>\n );\n}\n\ntype NativeButtonProps = Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n 'type' | 'children'\n>;\n\ninterface ButtonProps extends NativeButtonProps, ButtonLookProps {\n /** Optional aegis-ui agent action — also wires the agent runtime. */\n action?: AegisAction<void, unknown>;\n /** Native HTML button type. */\n type?: 'button' | 'submit' | 'reset';\n}\n\n/** A toggle button passes `aria-pressed`; the pressed state is the inverted fill. */\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n children,\n tone = 'primary',\n icon,\n iconPosition = 'start',\n action,\n onClick,\n disabled,\n className,\n type = 'button',\n title,\n ...rest\n },\n ref,\n ) => {\n const bound = useAegisAction<void, unknown>(action);\n const isUnavailable = action ? !bound.available : false;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>): void => {\n onClick?.(event);\n if (event.defaultPrevented) {\n return;\n }\n if (action) {\n void bound.invoke();\n }\n },\n [onClick, action, bound],\n );\n\n const resolvedTitle =\n title ?? (isUnavailable ? bound.unavailableReason : undefined);\n\n return (\n <button\n ref={ref}\n type={type}\n className={buttonClassName(tone, className)}\n disabled={disabled ?? isUnavailable}\n title={resolvedTitle}\n data-agent-action-id={action?.id}\n onClick={handleClick}\n {...rest}\n >\n <ButtonContent icon={icon} iconPosition={iconPosition}>\n {children}\n </ButtonContent>\n </button>\n );\n },\n);\nButton.displayName = 'Button';\n\ninterface ButtonLinkProps extends ButtonLookProps {\n /** Destination; the control navigates instead of firing a handler. */\n to: string;\n /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */\n linkComponent?: LinkComponent;\n className?: string;\n}\n\n/** A link that looks like a Button, for actions that open another page. */\nexport function ButtonLink({\n to,\n children,\n tone = 'primary',\n icon,\n iconPosition = 'start',\n linkComponent,\n className,\n}: ButtonLinkProps) {\n const LinkImpl = linkComponent ?? DefaultLink;\n return (\n <LinkImpl to={to} className={buttonClassName(tone, className)}>\n <ButtonContent icon={icon} iconPosition={iconPosition}>\n {children}\n </ButtonContent>\n </LinkImpl>\n );\n}\n"],"names":["buttonClassName","tone","className","ButtonContent","children","icon","iconPosition","iconSlot","jsx","jsxs","Fragment","Button","forwardRef","action","onClick","disabled","type","title","rest","ref","bound","useAegisAction","isUnavailable","handleClick","useCallback","event","resolvedTitle","ButtonLink","to","linkComponent","DefaultLink"],"mappings":";;;;;AAqCA,SAASA,EACPC,GACAC,GACQ;AACR,SAAO,CAAC,gBAAgB,iBAAiBD,CAAI,IAAIC,KAAa,EAAE,EAC7D,OAAO,OAAO,EACd,KAAK,GAAG;AACb;AAEA,SAASC,EAAc;AAAA,EACrB,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAAC;AACF,GAEG;AACD,QAAMC,IACJF,MAAS,SAAY,OACnB,gBA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AO;AAAA,EACP,MAAAI;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,eAAAuB;AAAA,EACA,WAAA3B;AACF,GAAoB;AAElB,SACE,gBAAAM,EAFeqB,KAAiBC,GAE/B,EAAS,IAAAF,GAAQ,WAAW5B,EAAgBC,GAAMC,CAAS,GAC1D,UAAA,gBAAAM,EAACL,GAAA,EAAc,MAAAE,GAAY,cAAAC,GACxB,UAAAF,GACH,GACF;AAEJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");;/* empty css */function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("../../lib/breakAtSeparators.cjs");;/* empty css */function _({columns:s,rows:a,rowHeader:i,passedLabel:h,uncheckedLabel:n,caption:r,className:t}){const g=["aegis-check-grid",t??""].filter(Boolean).join(" ");return e.jsxs("figure",{className:g,children:[e.jsx("div",{className:"aegis-check-grid__scroll",children:e.jsxs("table",{className:"aegis-check-grid__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"aegis-check-grid__corner",children:i}),s.map(c=>e.jsx("th",{scope:"col",className:"aegis-check-grid__run",children:d.breakAtSeparators(c.label)},c.key))]})}),e.jsx("tbody",{children:a.map(c=>e.jsxs("tr",{children:[e.jsx("th",{scope:"row",className:"aegis-check-grid__check",children:d.breakAtSeparators(c.label)}),s.map(l=>e.jsx("td",{className:"aegis-check-grid__slot",children:e.jsx(k,{cell:c.cells[l.key],passedLabel:h,uncheckedLabel:n})},l.key))]},c.key))})]})}),r!==void 0&&e.jsx("figcaption",{className:"aegis-check-grid__caption",children:r})]})}function k({cell:s,passedLabel:a,uncheckedLabel:i}){switch(s.state){case"passed":return e.jsx("span",{className:"aegis-check-grid__cell aegis-check-grid__cell--passed",children:e.jsx("span",{className:"aegis-check-grid__value",children:a})});case"missed":return e.jsx("span",{className:"aegis-check-grid__cell aegis-check-grid__cell--missed",title:s.value,children:e.jsx("span",{className:"aegis-check-grid__value",children:s.value})});case"unchecked":return e.jsxs("span",{className:"aegis-check-grid__cell aegis-check-grid__cell--unchecked",children:[e.jsx("span",{className:"aegis-check-grid__value","aria-hidden":"true",children:"—"}),e.jsx("span",{className:"aegis-check-grid__spoken",children:i})]})}}exports.CheckGrid=_;
|
|
2
2
|
//# sourceMappingURL=CheckGrid.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckGrid.cjs","sources":["../../../src/components/ui/CheckGrid.tsx"],"sourcesContent":["import { type ReactNode } from 'react';\n\nimport './CheckGrid.css';\n\n/**\n * One check in one run. `missed` carries how far the run fell short, e.g.\n * \"−0.80\" or \"replica\"; `unchecked` (the check never ran, e.g. after a\n * failed gate) shows an em dash.\n */\nexport type CheckGridCell =\n | { state: 'passed' }\n | { state: 'missed'; value: string }\n | { state: 'unchecked' };\n\nexport interface CheckGridColumn<C extends string> {\n key: C;\n /** Column header, e.g. \"运行 1\". */\n label: ReactNode;\n}\n\nexport interface CheckGridRow<C extends string> {\n key: string;\n /** Row header, e.g. the check's id. */\n label: ReactNode;\n /** The check's outcome in every column, keyed by column key. */\n cells: Readonly<Record<C, CheckGridCell>>;\n}\n\nexport interface CheckGridProps<C extends string> {\n /** Runs, left to right. */\n columns: Array<CheckGridColumn<C>>;\n /** Checks, top to bottom. */\n rows: Array<CheckGridRow<C>>;\n /** Header over the row labels, e.g. \"检查\". */\n rowHeader: ReactNode;\n /** Text of every passed cell, e.g. \"通过\". */\n passedLabel: string;\n /** Read out in place of an unchecked cell's em dash, e.g. \"未检查\". */\n uncheckedLabel: string;\n /** Note under the grid, e.g. \"图 1 · …\". */\n caption?: ReactNode;\n className?: string;\n}\n\n/**\n * Checks against runs: one row per check, one column per run. Every cell\n * writes its outcome — the passed label, the miss, or an em dash — so the\n * colour is never the only signal.\n */\nexport function CheckGrid<C extends string>({\n columns,\n rows,\n rowHeader,\n passedLabel,\n uncheckedLabel,\n caption,\n className,\n}: CheckGridProps<C>) {\n const cls = ['aegis-check-grid', className ?? ''].filter(Boolean).join(' ');\n return (\n <figure className={cls}>\n <div className=\"aegis-check-grid__scroll\">\n <table className=\"aegis-check-grid__table\">\n <thead>\n <tr>\n <th scope=\"col\" className=\"aegis-check-grid__corner\">\n {rowHeader}\n </th>\n {columns.map((column) => (\n <th\n key={column.key}\n scope=\"col\"\n className=\"aegis-check-grid__run\"\n >\n {column.label}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {rows.map((row) => (\n <tr key={row.key}>\n <th scope=\"row\" className=\"aegis-check-grid__check\">\n {row.label}\n </th>\n {columns.map((column) => (\n <td key={column.key} className=\"aegis-check-grid__slot\">\n <CheckGridMark\n cell={row.cells[column.key]}\n passedLabel={passedLabel}\n uncheckedLabel={uncheckedLabel}\n />\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n {caption !== undefined && (\n <figcaption className=\"aegis-check-grid__caption\">{caption}</figcaption>\n )}\n </figure>\n );\n}\n\ninterface CheckGridMarkProps {\n cell: CheckGridCell;\n passedLabel: string;\n uncheckedLabel: string;\n}\n\nfunction CheckGridMark({\n cell,\n passedLabel,\n uncheckedLabel,\n}: CheckGridMarkProps) {\n switch (cell.state) {\n case 'passed':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--passed\">\n <span className=\"aegis-check-grid__value\">{passedLabel}</span>\n </span>\n );\n case 'missed':\n return (\n <span\n className=\"aegis-check-grid__cell aegis-check-grid__cell--missed\"\n title={cell.value}\n >\n <span className=\"aegis-check-grid__value\">{cell.value}</span>\n </span>\n );\n case 'unchecked':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--unchecked\">\n <span className=\"aegis-check-grid__value\" aria-hidden=\"true\">\n —\n </span>\n <span className=\"aegis-check-grid__spoken\">{uncheckedLabel}</span>\n </span>\n );\n }\n}\n"],"names":["CheckGrid","columns","rows","rowHeader","passedLabel","uncheckedLabel","caption","className","cls","jsxs","jsx","column","row","CheckGridMark","cell"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CheckGrid.cjs","sources":["../../../src/components/ui/CheckGrid.tsx"],"sourcesContent":["import { type ReactNode } from 'react';\n\nimport { breakAtSeparators } from '../../lib/breakAtSeparators';\nimport './CheckGrid.css';\n\n/**\n * One check in one run. `missed` carries how far the run fell short, e.g.\n * \"−0.80\" or \"replica\"; `unchecked` (the check never ran, e.g. after a\n * failed gate) shows an em dash.\n */\nexport type CheckGridCell =\n | { state: 'passed' }\n | { state: 'missed'; value: string }\n | { state: 'unchecked' };\n\nexport interface CheckGridColumn<C extends string> {\n key: C;\n /** Column header, e.g. \"运行 1\". */\n label: ReactNode;\n}\n\nexport interface CheckGridRow<C extends string> {\n key: string;\n /** Row header, e.g. the check's id. */\n label: ReactNode;\n /** The check's outcome in every column, keyed by column key. */\n cells: Readonly<Record<C, CheckGridCell>>;\n}\n\nexport interface CheckGridProps<C extends string> {\n /** Runs, left to right. */\n columns: Array<CheckGridColumn<C>>;\n /** Checks, top to bottom. */\n rows: Array<CheckGridRow<C>>;\n /** Header over the row labels, e.g. \"检查\". */\n rowHeader: ReactNode;\n /** Text of every passed cell, e.g. \"通过\". */\n passedLabel: string;\n /** Read out in place of an unchecked cell's em dash, e.g. \"未检查\". */\n uncheckedLabel: string;\n /** Note under the grid, e.g. \"图 1 · …\". */\n caption?: ReactNode;\n className?: string;\n}\n\n/**\n * Checks against runs: one row per check, one column per run. Every cell\n * writes its outcome — the passed label, the miss, or an em dash — so the\n * colour is never the only signal.\n */\nexport function CheckGrid<C extends string>({\n columns,\n rows,\n rowHeader,\n passedLabel,\n uncheckedLabel,\n caption,\n className,\n}: CheckGridProps<C>) {\n const cls = ['aegis-check-grid', className ?? ''].filter(Boolean).join(' ');\n return (\n <figure className={cls}>\n <div className=\"aegis-check-grid__scroll\">\n <table className=\"aegis-check-grid__table\">\n <thead>\n <tr>\n <th scope=\"col\" className=\"aegis-check-grid__corner\">\n {rowHeader}\n </th>\n {columns.map((column) => (\n <th\n key={column.key}\n scope=\"col\"\n className=\"aegis-check-grid__run\"\n >\n {breakAtSeparators(column.label)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {rows.map((row) => (\n <tr key={row.key}>\n <th scope=\"row\" className=\"aegis-check-grid__check\">\n {breakAtSeparators(row.label)}\n </th>\n {columns.map((column) => (\n <td key={column.key} className=\"aegis-check-grid__slot\">\n <CheckGridMark\n cell={row.cells[column.key]}\n passedLabel={passedLabel}\n uncheckedLabel={uncheckedLabel}\n />\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n {caption !== undefined && (\n <figcaption className=\"aegis-check-grid__caption\">{caption}</figcaption>\n )}\n </figure>\n );\n}\n\ninterface CheckGridMarkProps {\n cell: CheckGridCell;\n passedLabel: string;\n uncheckedLabel: string;\n}\n\nfunction CheckGridMark({\n cell,\n passedLabel,\n uncheckedLabel,\n}: CheckGridMarkProps) {\n switch (cell.state) {\n case 'passed':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--passed\">\n <span className=\"aegis-check-grid__value\">{passedLabel}</span>\n </span>\n );\n case 'missed':\n return (\n <span\n className=\"aegis-check-grid__cell aegis-check-grid__cell--missed\"\n title={cell.value}\n >\n <span className=\"aegis-check-grid__value\">{cell.value}</span>\n </span>\n );\n case 'unchecked':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--unchecked\">\n <span className=\"aegis-check-grid__value\" aria-hidden=\"true\">\n —\n </span>\n <span className=\"aegis-check-grid__spoken\">{uncheckedLabel}</span>\n </span>\n );\n }\n}\n"],"names":["CheckGrid","columns","rows","rowHeader","passedLabel","uncheckedLabel","caption","className","cls","jsxs","jsx","column","breakAtSeparators","row","CheckGridMark","cell"],"mappings":"iMAkDO,SAASA,EAA4B,CAC1C,QAAAC,EACA,KAAAC,EACA,UAAAC,EACA,YAAAC,EACA,eAAAC,E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eAAC,OAAA,CAAK,UAAU,0BAA2B,SAAAN,CAAA,CAAY,CAAA,CACzD,EAEJ,IAAK,SACH,OACEM,EAAAA,IAAC,OAAA,CACC,UAAU,wDACV,MAAOK,EAAK,MAEZ,SAAAL,EAAAA,IAAC,OAAA,CAAK,UAAU,0BAA2B,WAAK,KAAA,CAAM,CAAA,CAAA,EAG5D,IAAK,YACH,OACED,EAAAA,KAAC,OAAA,CAAK,UAAU,2DACd,SAAA,CAAAC,MAAC,OAAA,CAAK,UAAU,0BAA0B,cAAY,OAAO,SAAA,IAE7D,EACAA,EAAAA,IAAC,OAAA,CAAK,UAAU,2BAA4B,SAAAL,CAAA,CAAe,CAAA,EAC7D,CAAA,CAGR"}
|
|
@@ -1,48 +1,49 @@
|
|
|
1
1
|
import { jsxs as s, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { breakAtSeparators as h } from "../../lib/breakAtSeparators.js";
|
|
2
3
|
/* empty css */
|
|
3
|
-
function
|
|
4
|
+
function N({
|
|
4
5
|
columns: c,
|
|
5
6
|
rows: i,
|
|
6
|
-
rowHeader:
|
|
7
|
-
passedLabel:
|
|
8
|
-
uncheckedLabel:
|
|
9
|
-
caption:
|
|
10
|
-
className:
|
|
7
|
+
rowHeader: r,
|
|
8
|
+
passedLabel: n,
|
|
9
|
+
uncheckedLabel: g,
|
|
10
|
+
caption: l,
|
|
11
|
+
className: _
|
|
11
12
|
}) {
|
|
12
|
-
const
|
|
13
|
-
return /* @__PURE__ */ s("figure", { className:
|
|
13
|
+
const t = ["aegis-check-grid", _ ?? ""].filter(Boolean).join(" ");
|
|
14
|
+
return /* @__PURE__ */ s("figure", { className: t, children: [
|
|
14
15
|
/* @__PURE__ */ e("div", { className: "aegis-check-grid__scroll", children: /* @__PURE__ */ s("table", { className: "aegis-check-grid__table", children: [
|
|
15
16
|
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ s("tr", { children: [
|
|
16
|
-
/* @__PURE__ */ e("th", { scope: "col", className: "aegis-check-grid__corner", children:
|
|
17
|
+
/* @__PURE__ */ e("th", { scope: "col", className: "aegis-check-grid__corner", children: r }),
|
|
17
18
|
c.map((a) => /* @__PURE__ */ e(
|
|
18
19
|
"th",
|
|
19
20
|
{
|
|
20
21
|
scope: "col",
|
|
21
22
|
className: "aegis-check-grid__run",
|
|
22
|
-
children: a.label
|
|
23
|
+
children: h(a.label)
|
|
23
24
|
},
|
|
24
25
|
a.key
|
|
25
26
|
))
|
|
26
27
|
] }) }),
|
|
27
28
|
/* @__PURE__ */ e("tbody", { children: i.map((a) => /* @__PURE__ */ s("tr", { children: [
|
|
28
|
-
/* @__PURE__ */ e("th", { scope: "row", className: "aegis-check-grid__check", children: a.label }),
|
|
29
|
+
/* @__PURE__ */ e("th", { scope: "row", className: "aegis-check-grid__check", children: h(a.label) }),
|
|
29
30
|
c.map((d) => /* @__PURE__ */ e("td", { className: "aegis-check-grid__slot", children: /* @__PURE__ */ e(
|
|
30
31
|
k,
|
|
31
32
|
{
|
|
32
33
|
cell: a.cells[d.key],
|
|
33
|
-
passedLabel:
|
|
34
|
-
uncheckedLabel:
|
|
34
|
+
passedLabel: n,
|
|
35
|
+
uncheckedLabel: g
|
|
35
36
|
}
|
|
36
37
|
) }, d.key))
|
|
37
38
|
] }, a.key)) })
|
|
38
39
|
] }) }),
|
|
39
|
-
|
|
40
|
+
l !== void 0 && /* @__PURE__ */ e("figcaption", { className: "aegis-check-grid__caption", children: l })
|
|
40
41
|
] });
|
|
41
42
|
}
|
|
42
43
|
function k({
|
|
43
44
|
cell: c,
|
|
44
45
|
passedLabel: i,
|
|
45
|
-
uncheckedLabel:
|
|
46
|
+
uncheckedLabel: r
|
|
46
47
|
}) {
|
|
47
48
|
switch (c.state) {
|
|
48
49
|
case "passed":
|
|
@@ -59,11 +60,11 @@ function k({
|
|
|
59
60
|
case "unchecked":
|
|
60
61
|
return /* @__PURE__ */ s("span", { className: "aegis-check-grid__cell aegis-check-grid__cell--unchecked", children: [
|
|
61
62
|
/* @__PURE__ */ e("span", { className: "aegis-check-grid__value", "aria-hidden": "true", children: "—" }),
|
|
62
|
-
/* @__PURE__ */ e("span", { className: "aegis-check-grid__spoken", children:
|
|
63
|
+
/* @__PURE__ */ e("span", { className: "aegis-check-grid__spoken", children: r })
|
|
63
64
|
] });
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
export {
|
|
67
|
-
|
|
68
|
+
N as CheckGrid
|
|
68
69
|
};
|
|
69
70
|
//# sourceMappingURL=CheckGrid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckGrid.js","sources":["../../../src/components/ui/CheckGrid.tsx"],"sourcesContent":["import { type ReactNode } from 'react';\n\nimport './CheckGrid.css';\n\n/**\n * One check in one run. `missed` carries how far the run fell short, e.g.\n * \"−0.80\" or \"replica\"; `unchecked` (the check never ran, e.g. after a\n * failed gate) shows an em dash.\n */\nexport type CheckGridCell =\n | { state: 'passed' }\n | { state: 'missed'; value: string }\n | { state: 'unchecked' };\n\nexport interface CheckGridColumn<C extends string> {\n key: C;\n /** Column header, e.g. \"运行 1\". */\n label: ReactNode;\n}\n\nexport interface CheckGridRow<C extends string> {\n key: string;\n /** Row header, e.g. the check's id. */\n label: ReactNode;\n /** The check's outcome in every column, keyed by column key. */\n cells: Readonly<Record<C, CheckGridCell>>;\n}\n\nexport interface CheckGridProps<C extends string> {\n /** Runs, left to right. */\n columns: Array<CheckGridColumn<C>>;\n /** Checks, top to bottom. */\n rows: Array<CheckGridRow<C>>;\n /** Header over the row labels, e.g. \"检查\". */\n rowHeader: ReactNode;\n /** Text of every passed cell, e.g. \"通过\". */\n passedLabel: string;\n /** Read out in place of an unchecked cell's em dash, e.g. \"未检查\". */\n uncheckedLabel: string;\n /** Note under the grid, e.g. \"图 1 · …\". */\n caption?: ReactNode;\n className?: string;\n}\n\n/**\n * Checks against runs: one row per check, one column per run. Every cell\n * writes its outcome — the passed label, the miss, or an em dash — so the\n * colour is never the only signal.\n */\nexport function CheckGrid<C extends string>({\n columns,\n rows,\n rowHeader,\n passedLabel,\n uncheckedLabel,\n caption,\n className,\n}: CheckGridProps<C>) {\n const cls = ['aegis-check-grid', className ?? ''].filter(Boolean).join(' ');\n return (\n <figure className={cls}>\n <div className=\"aegis-check-grid__scroll\">\n <table className=\"aegis-check-grid__table\">\n <thead>\n <tr>\n <th scope=\"col\" className=\"aegis-check-grid__corner\">\n {rowHeader}\n </th>\n {columns.map((column) => (\n <th\n key={column.key}\n scope=\"col\"\n className=\"aegis-check-grid__run\"\n >\n {column.label}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {rows.map((row) => (\n <tr key={row.key}>\n <th scope=\"row\" className=\"aegis-check-grid__check\">\n {row.label}\n </th>\n {columns.map((column) => (\n <td key={column.key} className=\"aegis-check-grid__slot\">\n <CheckGridMark\n cell={row.cells[column.key]}\n passedLabel={passedLabel}\n uncheckedLabel={uncheckedLabel}\n />\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n {caption !== undefined && (\n <figcaption className=\"aegis-check-grid__caption\">{caption}</figcaption>\n )}\n </figure>\n );\n}\n\ninterface CheckGridMarkProps {\n cell: CheckGridCell;\n passedLabel: string;\n uncheckedLabel: string;\n}\n\nfunction CheckGridMark({\n cell,\n passedLabel,\n uncheckedLabel,\n}: CheckGridMarkProps) {\n switch (cell.state) {\n case 'passed':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--passed\">\n <span className=\"aegis-check-grid__value\">{passedLabel}</span>\n </span>\n );\n case 'missed':\n return (\n <span\n className=\"aegis-check-grid__cell aegis-check-grid__cell--missed\"\n title={cell.value}\n >\n <span className=\"aegis-check-grid__value\">{cell.value}</span>\n </span>\n );\n case 'unchecked':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--unchecked\">\n <span className=\"aegis-check-grid__value\" aria-hidden=\"true\">\n —\n </span>\n <span className=\"aegis-check-grid__spoken\">{uncheckedLabel}</span>\n </span>\n );\n }\n}\n"],"names":["CheckGrid","columns","rows","rowHeader","passedLabel","uncheckedLabel","caption","className","cls","jsxs","jsx","column","row","CheckGridMark","cell"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CheckGrid.js","sources":["../../../src/components/ui/CheckGrid.tsx"],"sourcesContent":["import { type ReactNode } from 'react';\n\nimport { breakAtSeparators } from '../../lib/breakAtSeparators';\nimport './CheckGrid.css';\n\n/**\n * One check in one run. `missed` carries how far the run fell short, e.g.\n * \"−0.80\" or \"replica\"; `unchecked` (the check never ran, e.g. after a\n * failed gate) shows an em dash.\n */\nexport type CheckGridCell =\n | { state: 'passed' }\n | { state: 'missed'; value: string }\n | { state: 'unchecked' };\n\nexport interface CheckGridColumn<C extends string> {\n key: C;\n /** Column header, e.g. \"运行 1\". */\n label: ReactNode;\n}\n\nexport interface CheckGridRow<C extends string> {\n key: string;\n /** Row header, e.g. the check's id. */\n label: ReactNode;\n /** The check's outcome in every column, keyed by column key. */\n cells: Readonly<Record<C, CheckGridCell>>;\n}\n\nexport interface CheckGridProps<C extends string> {\n /** Runs, left to right. */\n columns: Array<CheckGridColumn<C>>;\n /** Checks, top to bottom. */\n rows: Array<CheckGridRow<C>>;\n /** Header over the row labels, e.g. \"检查\". */\n rowHeader: ReactNode;\n /** Text of every passed cell, e.g. \"通过\". */\n passedLabel: string;\n /** Read out in place of an unchecked cell's em dash, e.g. \"未检查\". */\n uncheckedLabel: string;\n /** Note under the grid, e.g. \"图 1 · …\". */\n caption?: ReactNode;\n className?: string;\n}\n\n/**\n * Checks against runs: one row per check, one column per run. Every cell\n * writes its outcome — the passed label, the miss, or an em dash — so the\n * colour is never the only signal.\n */\nexport function CheckGrid<C extends string>({\n columns,\n rows,\n rowHeader,\n passedLabel,\n uncheckedLabel,\n caption,\n className,\n}: CheckGridProps<C>) {\n const cls = ['aegis-check-grid', className ?? ''].filter(Boolean).join(' ');\n return (\n <figure className={cls}>\n <div className=\"aegis-check-grid__scroll\">\n <table className=\"aegis-check-grid__table\">\n <thead>\n <tr>\n <th scope=\"col\" className=\"aegis-check-grid__corner\">\n {rowHeader}\n </th>\n {columns.map((column) => (\n <th\n key={column.key}\n scope=\"col\"\n className=\"aegis-check-grid__run\"\n >\n {breakAtSeparators(column.label)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {rows.map((row) => (\n <tr key={row.key}>\n <th scope=\"row\" className=\"aegis-check-grid__check\">\n {breakAtSeparators(row.label)}\n </th>\n {columns.map((column) => (\n <td key={column.key} className=\"aegis-check-grid__slot\">\n <CheckGridMark\n cell={row.cells[column.key]}\n passedLabel={passedLabel}\n uncheckedLabel={uncheckedLabel}\n />\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n {caption !== undefined && (\n <figcaption className=\"aegis-check-grid__caption\">{caption}</figcaption>\n )}\n </figure>\n );\n}\n\ninterface CheckGridMarkProps {\n cell: CheckGridCell;\n passedLabel: string;\n uncheckedLabel: string;\n}\n\nfunction CheckGridMark({\n cell,\n passedLabel,\n uncheckedLabel,\n}: CheckGridMarkProps) {\n switch (cell.state) {\n case 'passed':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--passed\">\n <span className=\"aegis-check-grid__value\">{passedLabel}</span>\n </span>\n );\n case 'missed':\n return (\n <span\n className=\"aegis-check-grid__cell aegis-check-grid__cell--missed\"\n title={cell.value}\n >\n <span className=\"aegis-check-grid__value\">{cell.value}</span>\n </span>\n );\n case 'unchecked':\n return (\n <span className=\"aegis-check-grid__cell aegis-check-grid__cell--unchecked\">\n <span className=\"aegis-check-grid__value\" aria-hidden=\"true\">\n —\n </span>\n <span className=\"aegis-check-grid__spoken\">{uncheckedLabel}</span>\n </span>\n );\n }\n}\n"],"names":["CheckGrid","columns","rows","rowHeader","passedLabel","uncheckedLabel","caption","className","cls","jsxs","jsx","column","breakAtSeparators","row","CheckGridMark","cell"],"mappings":";;;AAkDO,SAASA,EAA4B;AAAA,EAC1C,SAAAC;AAAA,EACA,MAAAC;AAAA,EACA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