@lincyaw/aegis-ui 0.20.1 → 0.21.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.
Files changed (41) hide show
  1. package/dist/components/ui/CodeBlock.cjs +2 -2
  2. package/dist/components/ui/CodeBlock.cjs.map +1 -1
  3. package/dist/components/ui/CodeBlock.d.ts +6 -1
  4. package/dist/components/ui/CodeBlock.js +43 -38
  5. package/dist/components/ui/CodeBlock.js.map +1 -1
  6. package/dist/components/ui/DataTable.cjs +1 -1
  7. package/dist/components/ui/DataTable.cjs.map +1 -1
  8. package/dist/components/ui/DataTable.d.ts +37 -2
  9. package/dist/components/ui/DataTable.js +262 -235
  10. package/dist/components/ui/DataTable.js.map +1 -1
  11. package/dist/components/ui/IdentityCell.cjs +1 -1
  12. package/dist/components/ui/IdentityCell.cjs.map +1 -1
  13. package/dist/components/ui/IdentityCell.d.ts +16 -1
  14. package/dist/components/ui/IdentityCell.js +30 -22
  15. package/dist/components/ui/IdentityCell.js.map +1 -1
  16. package/dist/components/ui/MetadataList.cjs +1 -1
  17. package/dist/components/ui/MetadataList.cjs.map +1 -1
  18. package/dist/components/ui/MetadataList.d.ts +10 -1
  19. package/dist/components/ui/MetadataList.js +24 -22
  20. package/dist/components/ui/MetadataList.js.map +1 -1
  21. package/dist/components/ui/SectionDivider.cjs +1 -1
  22. package/dist/components/ui/SectionDivider.cjs.map +1 -1
  23. package/dist/components/ui/SectionDivider.d.ts +4 -2
  24. package/dist/components/ui/SectionDivider.js +13 -13
  25. package/dist/components/ui/SectionDivider.js.map +1 -1
  26. package/dist/components/ui/SegmentBar.cjs +2 -0
  27. package/dist/components/ui/SegmentBar.cjs.map +1 -0
  28. package/dist/components/ui/SegmentBar.d.ts +26 -0
  29. package/dist/components/ui/SegmentBar.js +20 -0
  30. package/dist/components/ui/SegmentBar.js.map +1 -0
  31. package/dist/components/ui/StatusDot.cjs +1 -1
  32. package/dist/components/ui/StatusDot.cjs.map +1 -1
  33. package/dist/components/ui/StatusDot.d.ts +8 -1
  34. package/dist/components/ui/StatusDot.js +19 -15
  35. package/dist/components/ui/StatusDot.js.map +1 -1
  36. package/dist/components/ui/index.d.ts +2 -0
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +161 -159
  39. package/dist/index.js.map +1 -1
  40. package/dist/style.css +1 -1
  41. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),o=require("react"),K=require("../../agent/core/usePrimitiveSurface.cjs"),L=require("../../hooks/useCopyToClipboard.cjs");;/* empty css */const z=require("./CopyGlyph.cjs"),I=require("../../locale/useStrings.cjs");function J({code:i,language:b="text",showLineNumbers:w=!1,maxHeight:_,className:N,surface:q,selectedLines:m,onSelectLines:g,onSelectedLinesAnchor:y}){const k=o.useRef(null),h=o.useRef(null),C=o.useRef(null),[M,B]=o.useState(null),n=m===void 0?M:m,x=g!==void 0,T=w||x,O=K.usePrimitiveSurface(q,{code:i,language:b},"code",k),{copied:j,copy:v}=L.useCopyToClipboard(1500),a=I.useStrings(),P=o.useCallback(()=>{v(i)},[v,i]),u=i.split(`
2
- `),A=String(u.length).length,d=o.useCallback(t=>({getBoundingClientRect:()=>{const c=h.current?.querySelectorAll(".aegis-code-block__line"),e=c?.[t.start-1]?.getBoundingClientRect(),r=c?.[t.end-1]?.getBoundingClientRect();return!e||!r?new DOMRect:new DOMRect(e.left,e.top,e.width,r.bottom-e.top)},contains:c=>h.current?.contains(c)??!1}),[]),D=o.useCallback((t,c)=>{const e=c.shiftKey?C.current:null,l=n?.start===t&&n.end===t&&e===null?null:e===null?{start:t,end:t}:{start:Math.min(e,t),end:Math.max(e,t)};e===null&&(C.current=l?t:null),B(l),g?.(l,l?d(l):null)},[n,g,d]),p=n&&n.start<=u.length?n.start:null,f=n&&p!==null?Math.min(n.end,u.length):null,R=o.useMemo(()=>p===null||f===null?null:d({start:p,end:f}),[d,p,f]),S=o.useRef(y);S.current=y,o.useEffect(()=>{S.current?.(R)},[R]);const E=o.useMemo(()=>n?t=>t>=n.start&&t<=n.end:()=>!1,[n]),G=["aegis-code-block",N??""].filter(Boolean).join(" ");return s.jsxs("div",{ref:k,className:G,...O,children:[s.jsxs("div",{className:"aegis-code-block__header",children:[s.jsx("span",{className:"aegis-code-block__lang",children:b==="text"?a.plainTextLanguage:b}),s.jsxs("button",{type:"button",className:"aegis-code-block__copy",onClick:P,"aria-label":a.copyToClipboard,children:[s.jsx(z.CopyGlyph,{copied:j}),j?a.copied:a.copy]})]}),s.jsx("pre",{ref:h,className:"aegis-code-block__pre",style:_===void 0?void 0:{maxHeight:_},children:s.jsx("code",{children:u.map((t,c)=>{const e=c+1,r=E(e),l=String(e).padStart(A," ");return s.jsxs("div",{className:r?"aegis-code-block__line aegis-code-block__line--selected":"aegis-code-block__line",children:[T&&(x?s.jsx("button",{type:"button",className:"aegis-code-block__ln aegis-code-block__ln--button","aria-label":a.codeLine(e),"aria-pressed":r,onClick:F=>{D(e,F)},children:l}):s.jsx("span",{className:"aegis-code-block__ln",children:l})),s.jsx("span",{className:"aegis-code-block__body",children:t||" "})]},c)})})})]})}exports.CodeBlock=J;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),o=require("react"),L=require("../../agent/core/usePrimitiveSurface.cjs"),z=require("../../hooks/useCopyToClipboard.cjs");;/* empty css */const I=require("./CopyGlyph.cjs"),J=require("../../locale/useStrings.cjs");function Q({code:i,language:p="text",showLineNumbers:N=!1,maxHeight:_,className:q,bare:m=!1,surface:M,selectedLines:k,onSelectLines:g,onSelectedLinesAnchor:y}){const C=o.useRef(null),f=o.useRef(null),x=o.useRef(null),[B,T]=o.useState(null),n=k===void 0?B:k,j=g!==void 0,O=N||j,P=L.usePrimitiveSurface(M,{code:i,language:p},"code",C),{copied:v,copy:R}=z.useCopyToClipboard(1500),a=J.useStrings(),A=o.useCallback(()=>{R(i)},[R,i]),u=i.split(`
2
+ `),D=String(u.length).length,d=o.useCallback(t=>({getBoundingClientRect:()=>{const c=f.current?.querySelectorAll(".aegis-code-block__line"),e=c?.[t.start-1]?.getBoundingClientRect(),r=c?.[t.end-1]?.getBoundingClientRect();return!e||!r?new DOMRect:new DOMRect(e.left,e.top,e.width,r.bottom-e.top)},contains:c=>f.current?.contains(c)??!1}),[]),E=o.useCallback((t,c)=>{const e=c.shiftKey?x.current:null,l=n?.start===t&&n.end===t&&e===null?null:e===null?{start:t,end:t}:{start:Math.min(e,t),end:Math.max(e,t)};e===null&&(x.current=l?t:null),T(l),g?.(l,l?d(l):null)},[n,g,d]),b=n&&n.start<=u.length?n.start:null,h=n&&b!==null?Math.min(n.end,u.length):null,S=o.useMemo(()=>b===null||h===null?null:d({start:b,end:h}),[d,b,h]),w=o.useRef(y);w.current=y,o.useEffect(()=>{w.current?.(S)},[S]);const G=o.useMemo(()=>n?t=>t>=n.start&&t<=n.end:()=>!1,[n]),F=["aegis-code-block",m?"aegis-code-block--bare":"",q??""].filter(Boolean).join(" ");return s.jsxs("div",{ref:C,className:F,...P,children:[!m&&s.jsxs("div",{className:"aegis-code-block__header",children:[s.jsx("span",{className:"aegis-code-block__lang",children:p==="text"?a.plainTextLanguage:p}),s.jsxs("button",{type:"button",className:"aegis-code-block__copy",onClick:A,"aria-label":a.copyToClipboard,children:[s.jsx(I.CopyGlyph,{copied:v}),v?a.copied:a.copy]})]}),s.jsx("pre",{ref:f,className:"aegis-code-block__pre",style:_===void 0?void 0:{maxHeight:_},children:s.jsx("code",{children:u.map((t,c)=>{const e=c+1,r=G(e),l=String(e).padStart(D," ");return s.jsxs("div",{className:r?"aegis-code-block__line aegis-code-block__line--selected":"aegis-code-block__line",children:[O&&(j?s.jsx("button",{type:"button",className:"aegis-code-block__ln aegis-code-block__ln--button","aria-label":a.codeLine(e),"aria-pressed":r,onClick:K=>{E(e,K)},children:l}):s.jsx("span",{className:"aegis-code-block__ln",children:l})),s.jsx("span",{className:"aegis-code-block__body",children:t||" "})]},c)})})})]})}exports.CodeBlock=Q;
3
3
  //# sourceMappingURL=CodeBlock.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlock.cjs","sources":["../../../src/components/ui/CodeBlock.tsx"],"sourcesContent":["import {\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useCopyToClipboard } from '../../hooks/useCopyToClipboard';\nimport { useStrings } from '../../locale';\nimport type { PopoverAnchor } from './AnchoredPopover';\nimport './CodeBlock.css';\nimport { CopyGlyph } from './CopyGlyph';\n\n/** Lines `start` to `end`, 1-based and inclusive. */\nexport interface CodeLineRange {\n start: number;\n end: number;\n}\n\nexport type CodeBlockSurface = PrimitiveSurface<{\n code: string;\n language: string;\n}>;\n\ninterface CodeBlockProps {\n code: string;\n /** Shown as the header label, e.g. `json`, `typescript`, `python`. */\n language?: string;\n showLineNumbers?: boolean;\n /** Caps the code area's height (number → px); longer code scrolls inside. */\n maxHeight?: number | string;\n className?: string;\n surface?: CodeBlockSurface;\n /**\n * The selected lines, drawn in the brand's soft surface with a brand rule\n * at their left. Leave it out to let the block keep its own selection.\n */\n selectedLines?: CodeLineRange | null;\n /**\n * Makes the line numbers buttons that select lines: a press selects its\n * line, Shift extends the range from the last line pressed, and pressing\n * the only selected line clears it. Receives the range and an anchor over\n * its lines, for an `AnchoredPopover`; turns line numbers on.\n */\n onSelectLines?: (\n range: CodeLineRange | null,\n anchor: PopoverAnchor | null,\n ) => void;\n /**\n * Receives an anchor over the selected lines as drawn, for an\n * `AnchoredPopover`, whenever the drawn selection changes: on mount, on a\n * press, and when a controlled `selectedLines` changes, such as one read\n * from the page's address. Receives null while no line in the code is\n * selected. The anchor measures the lines each time it is asked, so it\n * follows them as the page scrolls or reflows.\n */\n onSelectedLinesAnchor?: (anchor: PopoverAnchor | null) => void;\n}\n\nexport function CodeBlock({\n code,\n language = 'text',\n showLineNumbers = false,\n maxHeight,\n className,\n surface,\n selectedLines,\n onSelectLines,\n onSelectedLinesAnchor,\n}: CodeBlockProps) {\n const wrapRef = useRef<HTMLDivElement>(null);\n const preRef = useRef<HTMLPreElement>(null);\n const pivot = useRef<number | null>(null);\n const [ownSelection, setOwnSelection] = useState<CodeLineRange | null>(null);\n const selection = selectedLines === undefined ? ownSelection : selectedLines;\n const selectable = onSelectLines !== undefined;\n const numbered = showLineNumbers || selectable;\n const agentAttrs = usePrimitiveSurface(\n surface,\n { code, language },\n 'code',\n wrapRef,\n );\n const { copied, copy } = useCopyToClipboard(1500);\n const strings = useStrings();\n\n const handleCopy = useCallback(() => {\n void copy(code);\n }, [copy, code]);\n\n const lines = code.split('\\n');\n const padLen = String(lines.length).length;\n\n const anchorFor = useCallback(\n (range: CodeLineRange): PopoverAnchor => ({\n getBoundingClientRect: () => {\n const rows = preRef.current?.querySelectorAll<HTMLElement>(\n '.aegis-code-block__line',\n );\n const first = rows?.[range.start - 1]?.getBoundingClientRect();\n const last = rows?.[range.end - 1]?.getBoundingClientRect();\n if (!first || !last) {\n return new DOMRect();\n }\n return new DOMRect(\n first.left,\n first.top,\n first.width,\n last.bottom - first.top,\n );\n },\n contains: (node) => preRef.current?.contains(node) ?? false,\n }),\n [],\n );\n\n const handleLinePress = useCallback(\n (line: number, event: MouseEvent<HTMLButtonElement>) => {\n const from = event.shiftKey ? pivot.current : null;\n const only =\n selection?.start === line && selection.end === line && from === null;\n const next: CodeLineRange | null = only\n ? null\n : from === null\n ? { start: line, end: line }\n : { start: Math.min(from, line), end: Math.max(from, line) };\n if (from === null) {\n pivot.current = next ? line : null;\n }\n setOwnSelection(next);\n onSelectLines?.(next, next ? anchorFor(next) : null);\n },\n [selection, onSelectLines, anchorFor],\n );\n\n const drawnStart =\n selection && selection.start <= lines.length ? selection.start : null;\n const drawnEnd =\n selection && drawnStart !== null\n ? Math.min(selection.end, lines.length)\n : null;\n const drawnAnchor = useMemo(\n () =>\n drawnStart === null || drawnEnd === null\n ? null\n : anchorFor({ start: drawnStart, end: drawnEnd }),\n [anchorFor, drawnStart, drawnEnd],\n );\n // Read by the effect below, which runs only when the drawn selection does.\n const anchorListener = useRef(onSelectedLinesAnchor);\n anchorListener.current = onSelectedLinesAnchor;\n useEffect(() => {\n anchorListener.current?.(drawnAnchor);\n }, [drawnAnchor]);\n\n const selectedSet = useMemo(\n () =>\n selection\n ? (line: number) => line >= selection.start && line <= selection.end\n : () => false,\n [selection],\n );\n\n const cls = ['aegis-code-block', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <div ref={wrapRef} className={cls} {...agentAttrs}>\n <div className=\"aegis-code-block__header\">\n <span className=\"aegis-code-block__lang\">\n {language === 'text' ? strings.plainTextLanguage : language}\n </span>\n <button\n type=\"button\"\n className=\"aegis-code-block__copy\"\n onClick={handleCopy}\n aria-label={strings.copyToClipboard}\n >\n <CopyGlyph copied={copied} />\n {copied ? strings.copied : strings.copy}\n </button>\n </div>\n <pre\n ref={preRef}\n className=\"aegis-code-block__pre\"\n style={maxHeight === undefined ? undefined : { maxHeight }}\n >\n <code>\n {lines.map((line, i) => {\n const number = i + 1;\n const selected = selectedSet(number);\n const label = String(number).padStart(padLen, ' ');\n return (\n <div\n key={i}\n className={\n selected\n ? 'aegis-code-block__line aegis-code-block__line--selected'\n : 'aegis-code-block__line'\n }\n >\n {numbered &&\n (selectable ? (\n <button\n type=\"button\"\n className=\"aegis-code-block__ln aegis-code-block__ln--button\"\n aria-label={strings.codeLine(number)}\n aria-pressed={selected}\n onClick={(event) => {\n handleLinePress(number, event);\n }}\n >\n {label}\n </button>\n ) : (\n <span className=\"aegis-code-block__ln\">{label}</span>\n ))}\n <span className=\"aegis-code-block__body\">{line || ' '}</span>\n </div>\n );\n })}\n </code>\n </pre>\n </div>\n );\n}\n"],"names":["CodeBlock","code","language","showLineNumbers","maxHeight","className","surface","selectedLines","onSelectLines","onSelectedLinesAnchor","wrapRef","useRef","preRef","pivot","ownSelection","setOwnSelection","useState","selection","selectable","numbered","agentAttrs","usePrimitiveSurface","copied","copy","useCopyToClipboard","strings","useStrings","handleCopy","useCallback","lines","padLen","anchorFor","range","rows","first","last","node","handleLinePress","line","event","from","next","drawnStart","drawnEnd","drawnAnchor","useMemo","anchorListener","useEffect","selectedSet","cls","jsxs","jsx","CopyGlyph","i","number","selected","label"],"mappings":"yVAiEO,SAASA,EAAU,CACxB,KAAAC,EACA,SAAAC,EAAW,OACX,gBAAAC,EAAkB,GAClB,UAAAC,EACA,UAAAC,EACA,QAAAC,EACA,cAAAC,EACA,cAAAC,EACA,sBAAAC,CACF,EAAmB,CACjB,MAAMC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAASD,EAAAA,OAAuB,IAAI,EACpCE,EAAQF,EAAAA,OAAsB,IAAI,EAClC,CAACG,EAAcC,CAAe,EAAIC,EAAAA,SAA+B,IAAI,EACrEC,EAAYV,IAAkB,OAAYO,EAAeP,EACzDW,EAAaV,IAAkB,OAC/BW,EAAWhB,GAAmBe,EAC9BE,EAAaC,EAAAA,oBACjBf,EACA,CAAE,KAAAL,EAAM,SAAAC,CAAA,EACR,OACAQ,CAAA,EAEI,CAAE,OAAAY,EAAQ,KAAAC,GAASC,EAAAA,mBAAmB,IAAI,EAC1CC,EAAUC,EAAAA,WAAA,EAEVC,EAAaC,EAAAA,YAAY,IAAM,CAC9BL,EAAKtB,CAAI,CAChB,EAAG,CAACsB,EAAMtB,CAAI,CAAC,EAET4B,EAAQ5B,EAAK,MAAM;AAAA,CAAI,EACvB6B,EAAS,OAAOD,EAAM,MAAM,EAAE,OAE9BE,EAAYH,EAAAA,YACfI,IAAyC,CACxC,sBAAuB,IAAM,CAC3B,MAAMC,EAAOrB,EAAO,SAAS,iBAC3B,yBAAA,EAEIsB,EAAQD,IAAOD,EAAM,MAAQ,CAAC,GAAG,sBAAA,EACjCG,EAAOF,IAAOD,EAAM,IAAM,CAAC,GAAG,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,CACH,CAAA,CAAA,CACF,EACF,CAEJ"}
1
+ {"version":3,"file":"CodeBlock.cjs","sources":["../../../src/components/ui/CodeBlock.tsx"],"sourcesContent":["import {\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useCopyToClipboard } from '../../hooks/useCopyToClipboard';\nimport { useStrings } from '../../locale';\nimport type { PopoverAnchor } from './AnchoredPopover';\nimport './CodeBlock.css';\nimport { CopyGlyph } from './CopyGlyph';\n\n/** Lines `start` to `end`, 1-based and inclusive. */\nexport interface CodeLineRange {\n start: number;\n end: number;\n}\n\nexport type CodeBlockSurface = PrimitiveSurface<{\n code: string;\n language: string;\n}>;\n\ninterface CodeBlockProps {\n code: string;\n /** Shown as the header label, e.g. `json`, `typescript`, `python`. */\n language?: string;\n showLineNumbers?: boolean;\n /** Caps the code area's height (number → px); longer code scrolls inside. */\n maxHeight?: number | string;\n className?: string;\n /**\n * Draws the code without its frame and header, on the surface it sits on,\n * for a file viewer that fills a pane. The copy button goes with the header.\n */\n bare?: boolean;\n surface?: CodeBlockSurface;\n /**\n * The selected lines, drawn in the brand's soft surface with a brand rule\n * at their left. Leave it out to let the block keep its own selection.\n */\n selectedLines?: CodeLineRange | null;\n /**\n * Makes the line numbers buttons that select lines: a press selects its\n * line, Shift extends the range from the last line pressed, and pressing\n * the only selected line clears it. Receives the range and an anchor over\n * its lines, for an `AnchoredPopover`; turns line numbers on.\n */\n onSelectLines?: (\n range: CodeLineRange | null,\n anchor: PopoverAnchor | null,\n ) => void;\n /**\n * Receives an anchor over the selected lines as drawn, for an\n * `AnchoredPopover`, whenever the drawn selection changes: on mount, on a\n * press, and when a controlled `selectedLines` changes, such as one read\n * from the page's address. Receives null while no line in the code is\n * selected. The anchor measures the lines each time it is asked, so it\n * follows them as the page scrolls or reflows.\n */\n onSelectedLinesAnchor?: (anchor: PopoverAnchor | null) => void;\n}\n\nexport function CodeBlock({\n code,\n language = 'text',\n showLineNumbers = false,\n maxHeight,\n className,\n bare = false,\n surface,\n selectedLines,\n onSelectLines,\n onSelectedLinesAnchor,\n}: CodeBlockProps) {\n const wrapRef = useRef<HTMLDivElement>(null);\n const preRef = useRef<HTMLPreElement>(null);\n const pivot = useRef<number | null>(null);\n const [ownSelection, setOwnSelection] = useState<CodeLineRange | null>(null);\n const selection = selectedLines === undefined ? ownSelection : selectedLines;\n const selectable = onSelectLines !== undefined;\n const numbered = showLineNumbers || selectable;\n const agentAttrs = usePrimitiveSurface(\n surface,\n { code, language },\n 'code',\n wrapRef,\n );\n const { copied, copy } = useCopyToClipboard(1500);\n const strings = useStrings();\n\n const handleCopy = useCallback(() => {\n void copy(code);\n }, [copy, code]);\n\n const lines = code.split('\\n');\n const padLen = String(lines.length).length;\n\n const anchorFor = useCallback(\n (range: CodeLineRange): PopoverAnchor => ({\n getBoundingClientRect: () => {\n const rows = preRef.current?.querySelectorAll<HTMLElement>(\n '.aegis-code-block__line',\n );\n const first = rows?.[range.start - 1]?.getBoundingClientRect();\n const last = rows?.[range.end - 1]?.getBoundingClientRect();\n if (!first || !last) {\n return new DOMRect();\n }\n return new DOMRect(\n first.left,\n first.top,\n first.width,\n last.bottom - first.top,\n );\n },\n contains: (node) => preRef.current?.contains(node) ?? false,\n }),\n [],\n );\n\n const handleLinePress = useCallback(\n (line: number, event: MouseEvent<HTMLButtonElement>) => {\n const from = event.shiftKey ? pivot.current : null;\n const only =\n selection?.start === line && selection.end === line && from === null;\n const next: CodeLineRange | null = only\n ? null\n : from === null\n ? { start: line, end: line }\n : { start: Math.min(from, line), end: Math.max(from, line) };\n if (from === null) {\n pivot.current = next ? line : null;\n }\n setOwnSelection(next);\n onSelectLines?.(next, next ? anchorFor(next) : null);\n },\n [selection, onSelectLines, anchorFor],\n );\n\n const drawnStart =\n selection && selection.start <= lines.length ? selection.start : null;\n const drawnEnd =\n selection && drawnStart !== null\n ? Math.min(selection.end, lines.length)\n : null;\n const drawnAnchor = useMemo(\n () =>\n drawnStart === null || drawnEnd === null\n ? null\n : anchorFor({ start: drawnStart, end: drawnEnd }),\n [anchorFor, drawnStart, drawnEnd],\n );\n // Read by the effect below, which runs only when the drawn selection does.\n const anchorListener = useRef(onSelectedLinesAnchor);\n anchorListener.current = onSelectedLinesAnchor;\n useEffect(() => {\n anchorListener.current?.(drawnAnchor);\n }, [drawnAnchor]);\n\n const selectedSet = useMemo(\n () =>\n selection\n ? (line: number) => line >= selection.start && line <= selection.end\n : () => false,\n [selection],\n );\n\n const cls = [\n 'aegis-code-block',\n bare ? 'aegis-code-block--bare' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div ref={wrapRef} className={cls} {...agentAttrs}>\n {!bare && (\n <div className=\"aegis-code-block__header\">\n <span className=\"aegis-code-block__lang\">\n {language === 'text' ? strings.plainTextLanguage : language}\n </span>\n <button\n type=\"button\"\n className=\"aegis-code-block__copy\"\n onClick={handleCopy}\n aria-label={strings.copyToClipboard}\n >\n <CopyGlyph copied={copied} />\n {copied ? strings.copied : strings.copy}\n </button>\n </div>\n )}\n <pre\n ref={preRef}\n className=\"aegis-code-block__pre\"\n style={maxHeight === undefined ? undefined : { maxHeight }}\n >\n <code>\n {lines.map((line, i) => {\n const number = i + 1;\n const selected = selectedSet(number);\n const label = String(number).padStart(padLen, ' ');\n return (\n <div\n key={i}\n className={\n selected\n ? 'aegis-code-block__line aegis-code-block__line--selected'\n : 'aegis-code-block__line'\n }\n >\n {numbered &&\n (selectable ? (\n <button\n type=\"button\"\n className=\"aegis-code-block__ln aegis-code-block__ln--button\"\n aria-label={strings.codeLine(number)}\n aria-pressed={selected}\n onClick={(event) => {\n handleLinePress(number, event);\n }}\n >\n {label}\n </button>\n ) : (\n <span className=\"aegis-code-block__ln\">{label}</span>\n ))}\n <span className=\"aegis-code-block__body\">{line || ' '}</span>\n </div>\n );\n })}\n </code>\n </pre>\n </div>\n );\n}\n"],"names":["CodeBlock","code","language","showLineNumbers","maxHeight","className","bare","surface","selectedLines","onSelectLines","onSelectedLinesAnchor","wrapRef","useRef","preRef","pivot","ownSelection","setOwnSelection","useState","selection","selectable","numbered","agentAttrs","usePrimitiveSurface","copied","copy","useCopyToClipboard","strings","useStrings","handleCopy","useCallback","lines","padLen","anchorFor","range","rows","first","last","node","handleLinePress","line","event","from","next","drawnStart","drawnEnd","drawnAnchor","useMemo","anchorListener","useEffect","selectedSet","cls","jsxs","jsx","CopyGlyph","i","number","selected","label"],"mappings":"yVAsEO,SAASA,EAAU,CACxB,KAAAC,EACA,SAAAC,EAAW,OACX,gBAAAC,EAAkB,GAClB,UAAAC,EACA,UAAAC,EACA,KAAAC,EAAO,GACP,QAAAC,EACA,cAAAC,EACA,cAAAC,EACA,sBAAAC,CACF,EAAmB,CACjB,MAAMC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAASD,EAAAA,OAAuB,IAAI,EACpCE,EAAQF,EAAAA,OAAsB,IAAI,EAClC,CAACG,EAAcC,CAAe,EAAIC,EAAAA,SAA+B,IAAI,EACrEC,EAAYV,IAAkB,OAAYO,EAAeP,EACzDW,EAAaV,IAAkB,OAC/BW,EAAWjB,GAAmBgB,EAC9BE,EAAaC,EAAAA,oBACjBf,EACA,CAAE,KAAAN,EAAM,SAAAC,CAAA,EACR,OACAS,CAAA,EAEI,CAAE,OAAAY,EAAQ,KAAAC,GAASC,EAAAA,mBAAmB,IAAI,EAC1CC,EAAUC,EAAAA,WAAA,EAEVC,EAAaC,EAAAA,YAAY,IAAM,CAC9BL,EAAKvB,CAAI,CAChB,EAAG,CAACuB,EAAMvB,CAAI,CAAC,EAET6B,EAAQ7B,EAAK,MAAM;AAAA,CAAI,EACvB8B,EAAS,OAAOD,EAAM,MAAM,EAAE,OAE9BE,EAAYH,EAAAA,YACfI,IAAyC,CACxC,sBAAuB,IAAM,CAC3B,MAAMC,EAAOrB,EAAO,SAAS,iBAC3B,yBAAA,EA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AK,CAAA,CAAM,GAElDL,EAAAA,IAAC,OAAA,CAAK,UAAU,yBAA0B,YAAQ,GAAA,CAAI,CAAA,CAAA,EAvBjDE,CAAA,CA0BX,CAAC,CAAA,CACH,CAAA,CAAA,CACF,EACF,CAEJ"}
@@ -17,6 +17,11 @@ interface CodeBlockProps {
17
17
  /** Caps the code area's height (number → px); longer code scrolls inside. */
18
18
  maxHeight?: number | string;
19
19
  className?: string;
20
+ /**
21
+ * Draws the code without its frame and header, on the surface it sits on,
22
+ * for a file viewer that fills a pane. The copy button goes with the header.
23
+ */
24
+ bare?: boolean;
20
25
  surface?: CodeBlockSurface;
21
26
  /**
22
27
  * The selected lines, drawn in the brand's soft surface with a brand rule
@@ -40,5 +45,5 @@ interface CodeBlockProps {
40
45
  */
41
46
  onSelectedLinesAnchor?: (anchor: PopoverAnchor | null) => void;
42
47
  }
43
- export declare function CodeBlock({ code, language, showLineNumbers, maxHeight, className, surface, selectedLines, onSelectLines, onSelectedLinesAnchor, }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
48
+ export declare function CodeBlock({ code, language, showLineNumbers, maxHeight, className, bare, surface, selectedLines, onSelectLines, onSelectedLinesAnchor, }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
44
49
  export {};
@@ -1,30 +1,31 @@
1
1
  import { jsxs as p, jsx as c } from "react/jsx-runtime";
2
- import { useRef as m, useState as I, useCallback as _, useMemo as B, useEffect as J } from "react";
3
- import { usePrimitiveSurface as Q } from "../../agent/core/usePrimitiveSurface.js";
4
- import { useCopyToClipboard as U } from "../../hooks/useCopyToClipboard.js";
2
+ import { useRef as m, useState as J, useCallback as _, useMemo as j, useEffect as Q } from "react";
3
+ import { usePrimitiveSurface as U } from "../../agent/core/usePrimitiveSurface.js";
4
+ import { useCopyToClipboard as V } from "../../hooks/useCopyToClipboard.js";
5
5
  /* empty css */
6
- import { CopyGlyph as V } from "./CopyGlyph.js";
7
- import { useStrings as W } from "../../locale/useStrings.js";
8
- function ne({
6
+ import { CopyGlyph as W } from "./CopyGlyph.js";
7
+ import { useStrings as X } from "../../locale/useStrings.js";
8
+ function oe({
9
9
  code: a,
10
10
  language: b = "text",
11
- showLineNumbers: j = !1,
11
+ showLineNumbers: O = !1,
12
12
  maxHeight: k,
13
- className: O,
14
- surface: T,
15
- selectedLines: y,
13
+ className: T,
14
+ bare: y = !1,
15
+ surface: A,
16
+ selectedLines: C,
16
17
  onSelectLines: f,
17
- onSelectedLinesAnchor: C
18
+ onSelectedLinesAnchor: v
18
19
  }) {
19
- const v = m(null), g = m(null), w = m(null), [A, D] = I(null), n = y === void 0 ? A : y, N = f !== void 0, E = j || N, P = Q(
20
- T,
20
+ const w = m(null), g = m(null), N = m(null), [D, E] = J(null), n = C === void 0 ? D : C, R = f !== void 0, P = O || R, q = U(
21
+ A,
21
22
  { code: a, language: b },
22
23
  "code",
23
- v
24
- ), { copied: R, copy: S } = U(1500), r = W(), q = _(() => {
25
- S(a);
26
- }, [S, a]), i = a.split(`
27
- `), F = String(i.length).length, d = _(
24
+ w
25
+ ), { copied: S, copy: x } = V(1500), r = X(), F = _(() => {
26
+ x(a);
27
+ }, [x, a]), i = a.split(`
28
+ `), G = String(i.length).length, d = _(
28
29
  (t) => ({
29
30
  getBoundingClientRect: () => {
30
31
  const o = g.current?.querySelectorAll(
@@ -40,36 +41,40 @@ function ne({
40
41
  contains: (o) => g.current?.contains(o) ?? !1
41
42
  }),
42
43
  []
43
- ), G = _(
44
+ ), K = _(
44
45
  (t, o) => {
45
- const e = o.shiftKey ? w.current : null, l = n?.start === t && n.end === t && e === null ? null : e === null ? { start: t, end: t } : { start: Math.min(e, t), end: Math.max(e, t) };
46
- e === null && (w.current = l ? t : null), D(l), f?.(l, l ? d(l) : null);
46
+ const e = o.shiftKey ? N.current : null, l = n?.start === t && n.end === t && e === null ? null : e === null ? { start: t, end: t } : { start: Math.min(e, t), end: Math.max(e, t) };
47
+ e === null && (N.current = l ? t : null), E(l), f?.(l, l ? d(l) : null);
47
48
  },
48
49
  [n, f, d]
49
- ), u = n && n.start <= i.length ? n.start : null, h = n && u !== null ? Math.min(n.end, i.length) : null, x = B(
50
+ ), u = n && n.start <= i.length ? n.start : null, h = n && u !== null ? Math.min(n.end, i.length) : null, M = j(
50
51
  () => u === null || h === null ? null : d({ start: u, end: h }),
51
52
  [d, u, h]
52
- ), M = m(C);
53
- M.current = C, J(() => {
54
- M.current?.(x);
55
- }, [x]);
56
- const K = B(
53
+ ), B = m(v);
54
+ B.current = v, Q(() => {
55
+ B.current?.(M);
56
+ }, [M]);
57
+ const L = j(
57
58
  () => n ? (t) => t >= n.start && t <= n.end : () => !1,
58
59
  [n]
59
- ), L = ["aegis-code-block", O ?? ""].filter(Boolean).join(" ");
60
- return /* @__PURE__ */ p("div", { ref: v, className: L, ...P, children: [
61
- /* @__PURE__ */ p("div", { className: "aegis-code-block__header", children: [
60
+ ), z = [
61
+ "aegis-code-block",
62
+ y ? "aegis-code-block--bare" : "",
63
+ T ?? ""
64
+ ].filter(Boolean).join(" ");
65
+ return /* @__PURE__ */ p("div", { ref: w, className: z, ...q, children: [
66
+ !y && /* @__PURE__ */ p("div", { className: "aegis-code-block__header", children: [
62
67
  /* @__PURE__ */ c("span", { className: "aegis-code-block__lang", children: b === "text" ? r.plainTextLanguage : b }),
63
68
  /* @__PURE__ */ p(
64
69
  "button",
65
70
  {
66
71
  type: "button",
67
72
  className: "aegis-code-block__copy",
68
- onClick: q,
73
+ onClick: F,
69
74
  "aria-label": r.copyToClipboard,
70
75
  children: [
71
- /* @__PURE__ */ c(V, { copied: R }),
72
- R ? r.copied : r.copy
76
+ /* @__PURE__ */ c(W, { copied: S }),
77
+ S ? r.copied : r.copy
73
78
  ]
74
79
  }
75
80
  )
@@ -81,21 +86,21 @@ function ne({
81
86
  className: "aegis-code-block__pre",
82
87
  style: k === void 0 ? void 0 : { maxHeight: k },
83
88
  children: /* @__PURE__ */ c("code", { children: i.map((t, o) => {
84
- const e = o + 1, s = K(e), l = String(e).padStart(F, " ");
89
+ const e = o + 1, s = L(e), l = String(e).padStart(G, " ");
85
90
  return /* @__PURE__ */ p(
86
91
  "div",
87
92
  {
88
93
  className: s ? "aegis-code-block__line aegis-code-block__line--selected" : "aegis-code-block__line",
89
94
  children: [
90
- E && (N ? /* @__PURE__ */ c(
95
+ P && (R ? /* @__PURE__ */ c(
91
96
  "button",
92
97
  {
93
98
  type: "button",
94
99
  className: "aegis-code-block__ln aegis-code-block__ln--button",
95
100
  "aria-label": r.codeLine(e),
96
101
  "aria-pressed": s,
97
- onClick: (z) => {
98
- G(e, z);
102
+ onClick: (I) => {
103
+ K(e, I);
99
104
  },
100
105
  children: l
101
106
  }
@@ -111,6 +116,6 @@ function ne({
111
116
  ] });
112
117
  }
113
118
  export {
114
- ne as CodeBlock
119
+ oe as CodeBlock
115
120
  };
116
121
  //# sourceMappingURL=CodeBlock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlock.js","sources":["../../../src/components/ui/CodeBlock.tsx"],"sourcesContent":["import {\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useCopyToClipboard } from '../../hooks/useCopyToClipboard';\nimport { useStrings } from '../../locale';\nimport type { PopoverAnchor } from './AnchoredPopover';\nimport './CodeBlock.css';\nimport { CopyGlyph } from './CopyGlyph';\n\n/** Lines `start` to `end`, 1-based and inclusive. */\nexport interface CodeLineRange {\n start: number;\n end: number;\n}\n\nexport type CodeBlockSurface = PrimitiveSurface<{\n code: string;\n language: string;\n}>;\n\ninterface CodeBlockProps {\n code: string;\n /** Shown as the header label, e.g. `json`, `typescript`, `python`. */\n language?: string;\n showLineNumbers?: boolean;\n /** Caps the code area's height (number → px); longer code scrolls inside. */\n maxHeight?: number | string;\n className?: string;\n surface?: CodeBlockSurface;\n /**\n * The selected lines, drawn in the brand's soft surface with a brand rule\n * at their left. Leave it out to let the block keep its own selection.\n */\n selectedLines?: CodeLineRange | null;\n /**\n * Makes the line numbers buttons that select lines: a press selects its\n * line, Shift extends the range from the last line pressed, and pressing\n * the only selected line clears it. Receives the range and an anchor over\n * its lines, for an `AnchoredPopover`; turns line numbers on.\n */\n onSelectLines?: (\n range: CodeLineRange | null,\n anchor: PopoverAnchor | null,\n ) => void;\n /**\n * Receives an anchor over the selected lines as drawn, for an\n * `AnchoredPopover`, whenever the drawn selection changes: on mount, on a\n * press, and when a controlled `selectedLines` changes, such as one read\n * from the page's address. Receives null while no line in the code is\n * selected. The anchor measures the lines each time it is asked, so it\n * follows them as the page scrolls or reflows.\n */\n onSelectedLinesAnchor?: (anchor: PopoverAnchor | null) => void;\n}\n\nexport function CodeBlock({\n code,\n language = 'text',\n showLineNumbers = false,\n maxHeight,\n className,\n surface,\n selectedLines,\n onSelectLines,\n onSelectedLinesAnchor,\n}: CodeBlockProps) {\n const wrapRef = useRef<HTMLDivElement>(null);\n const preRef = useRef<HTMLPreElement>(null);\n const pivot = useRef<number | null>(null);\n const [ownSelection, setOwnSelection] = useState<CodeLineRange | null>(null);\n const selection = selectedLines === undefined ? ownSelection : selectedLines;\n const selectable = onSelectLines !== undefined;\n const numbered = showLineNumbers || selectable;\n const agentAttrs = usePrimitiveSurface(\n surface,\n { code, language },\n 'code',\n wrapRef,\n );\n const { copied, copy } = useCopyToClipboard(1500);\n const strings = useStrings();\n\n const handleCopy = useCallback(() => {\n void copy(code);\n }, [copy, code]);\n\n const lines = code.split('\\n');\n const padLen = String(lines.length).length;\n\n const anchorFor = useCallback(\n (range: CodeLineRange): PopoverAnchor => ({\n getBoundingClientRect: () => {\n const rows = preRef.current?.querySelectorAll<HTMLElement>(\n '.aegis-code-block__line',\n );\n const first = rows?.[range.start - 1]?.getBoundingClientRect();\n const last = rows?.[range.end - 1]?.getBoundingClientRect();\n if (!first || !last) {\n return new DOMRect();\n }\n return new DOMRect(\n first.left,\n first.top,\n first.width,\n last.bottom - first.top,\n );\n },\n contains: (node) => preRef.current?.contains(node) ?? false,\n }),\n [],\n );\n\n const handleLinePress = useCallback(\n (line: number, event: MouseEvent<HTMLButtonElement>) => {\n const from = event.shiftKey ? pivot.current : null;\n const only =\n selection?.start === line && selection.end === line && from === null;\n const next: CodeLineRange | null = only\n ? null\n : from === null\n ? { start: line, end: line }\n : { start: Math.min(from, line), end: Math.max(from, line) };\n if (from === null) {\n pivot.current = next ? line : null;\n }\n setOwnSelection(next);\n onSelectLines?.(next, next ? anchorFor(next) : null);\n },\n [selection, onSelectLines, anchorFor],\n );\n\n const drawnStart =\n selection && selection.start <= lines.length ? selection.start : null;\n const drawnEnd =\n selection && drawnStart !== null\n ? Math.min(selection.end, lines.length)\n : null;\n const drawnAnchor = useMemo(\n () =>\n drawnStart === null || drawnEnd === null\n ? null\n : anchorFor({ start: drawnStart, end: drawnEnd }),\n [anchorFor, drawnStart, drawnEnd],\n );\n // Read by the effect below, which runs only when the drawn selection does.\n const anchorListener = useRef(onSelectedLinesAnchor);\n anchorListener.current = onSelectedLinesAnchor;\n useEffect(() => {\n anchorListener.current?.(drawnAnchor);\n }, [drawnAnchor]);\n\n const selectedSet = useMemo(\n () =>\n selection\n ? (line: number) => line >= selection.start && line <= selection.end\n : () => false,\n [selection],\n );\n\n const cls = ['aegis-code-block', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <div ref={wrapRef} className={cls} {...agentAttrs}>\n <div className=\"aegis-code-block__header\">\n <span className=\"aegis-code-block__lang\">\n {language === 'text' ? strings.plainTextLanguage : language}\n </span>\n <button\n type=\"button\"\n className=\"aegis-code-block__copy\"\n onClick={handleCopy}\n aria-label={strings.copyToClipboard}\n >\n <CopyGlyph copied={copied} />\n {copied ? strings.copied : strings.copy}\n </button>\n </div>\n <pre\n ref={preRef}\n className=\"aegis-code-block__pre\"\n style={maxHeight === undefined ? undefined : { maxHeight }}\n >\n <code>\n {lines.map((line, i) => {\n const number = i + 1;\n const selected = selectedSet(number);\n const label = String(number).padStart(padLen, ' ');\n return (\n <div\n key={i}\n className={\n selected\n ? 'aegis-code-block__line aegis-code-block__line--selected'\n : 'aegis-code-block__line'\n }\n >\n {numbered &&\n (selectable ? (\n <button\n type=\"button\"\n className=\"aegis-code-block__ln aegis-code-block__ln--button\"\n aria-label={strings.codeLine(number)}\n aria-pressed={selected}\n onClick={(event) => {\n handleLinePress(number, event);\n }}\n >\n {label}\n </button>\n ) : (\n <span className=\"aegis-code-block__ln\">{label}</span>\n ))}\n <span className=\"aegis-code-block__body\">{line || ' '}</span>\n </div>\n );\n })}\n </code>\n </pre>\n </div>\n );\n}\n"],"names":["CodeBlock","code","language","showLineNumbers","maxHeight","className","surface","selectedLines","onSelectLines","onSelectedLinesAnchor","wrapRef","useRef","preRef","pivot","ownSelection","setOwnSelection","useState","selection","selectable","numbered","agentAttrs","usePrimitiveSurface","copied","copy","useCopyToClipboard","strings","useStrings","handleCopy","useCallback","lines","padLen","anchorFor","range","rows","first","last","node","handleLinePress","line","event","from","next","drawnStart","drawnEnd","drawnAnchor","useMemo","anchorListener","useEffect","selectedSet","cls","jsxs","jsx","CopyGlyph","i","number","selected","label"],"mappings":";;;;;;;AAiEO,SAASA,GAAU;AAAA,EACxB,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,SAAAC;AAAA,EACA,eAAAC;AAAA,EACA,eAAAC;AAAA,EACA,uBAAAC;AACF,GAAmB;AACjB,QAAMC,IAAUC,EAAuB,IAAI,GACrCC,IAASD,EAAuB,IAAI,GACpCE,IAAQF,EAAsB,IAAI,GAClC,CAACG,GAAcC,CAAe,IAAIC,EAA+B,IAAI,GACrEC,IAAYV,MAAkB,SAAYO,IAAeP,GACzDW,IAAaV,MAAkB,QAC/BW,IAAWhB,KAAmBe,GAC9BE,IAAaC;AAAA,IACjBf;AAAA,IACA,EAAE,MAAAL,GAAM,UAAAC,EAAA;AAAA,IACR;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A;AAAA,IACrC,GACF;AAAA,IACA,gBAAA0B;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAKvC;AAAA,QACL,WAAU;AAAA,QACV,OAAOR,MAAc,SAAY,SAAY,EAAE,WAAAA,EAAA;AAAA,QAE/C,4BAAC,QAAA,EACE,UAAAyB,EAAM,IAAI,CAACS,GAAMe,MAAM;AACtB,gBAAMC,IAASD,IAAI,GACbE,IAAWP,EAAYM,CAAM,GAC7BE,IAAQ,OAAOF,CAAM,EAAE,SAASxB,GAAQ,GAAG;AACjD,iBACE,gBAAAoB;AAAA,YAAC;AAAA,YAAA;AAAA,cAEC,WACEK,IACI,4DACA;AAAA,cAGL,UAAA;AAAA,gBAAApC,MACED,IACC,gBAAAiC;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAK;AAAA,oBACL,WAAU;AAAA,oBACV,cAAY1B,EAAQ,SAAS6B,CAAM;AAAA,oBACnC,gBAAcC;AAAA,oBACd,SAAS,CAAChB,MAAU;AAClB,sBAAAF,EAAgBiB,GAAQf,CAAK;AAAA,oBAC/B;AAAA,oBAEC,UAAAiB;AAAA,kBAAA;AAAA,gBAAA,IAGH,gBAAAL,EAAC,QAAA,EAAK,WAAU,wBAAwB,UAAAK,EAAA,CAAM;AAAA,gBAElD,gBAAAL,EAAC,QAAA,EAAK,WAAU,0BAA0B,eAAQ,IAAA,CAAI;AAAA,cAAA;AAAA,YAAA;AAAA,YAvBjDE;AAAA,UAAA;AAAA,QA0BX,CAAC,EAAA,CACH;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,GACF;AAEJ;"}
1
+ {"version":3,"file":"CodeBlock.js","sources":["../../../src/components/ui/CodeBlock.tsx"],"sourcesContent":["import {\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useCopyToClipboard } from '../../hooks/useCopyToClipboard';\nimport { useStrings } from '../../locale';\nimport type { PopoverAnchor } from './AnchoredPopover';\nimport './CodeBlock.css';\nimport { CopyGlyph } from './CopyGlyph';\n\n/** Lines `start` to `end`, 1-based and inclusive. */\nexport interface CodeLineRange {\n start: number;\n end: number;\n}\n\nexport type CodeBlockSurface = PrimitiveSurface<{\n code: string;\n language: string;\n}>;\n\ninterface CodeBlockProps {\n code: string;\n /** Shown as the header label, e.g. `json`, `typescript`, `python`. */\n language?: string;\n showLineNumbers?: boolean;\n /** Caps the code area's height (number → px); longer code scrolls inside. */\n maxHeight?: number | string;\n className?: string;\n /**\n * Draws the code without its frame and header, on the surface it sits on,\n * for a file viewer that fills a pane. The copy button goes with the header.\n */\n bare?: boolean;\n surface?: CodeBlockSurface;\n /**\n * The selected lines, drawn in the brand's soft surface with a brand rule\n * at their left. Leave it out to let the block keep its own selection.\n */\n selectedLines?: CodeLineRange | null;\n /**\n * Makes the line numbers buttons that select lines: a press selects its\n * line, Shift extends the range from the last line pressed, and pressing\n * the only selected line clears it. Receives the range and an anchor over\n * its lines, for an `AnchoredPopover`; turns line numbers on.\n */\n onSelectLines?: (\n range: CodeLineRange | null,\n anchor: PopoverAnchor | null,\n ) => void;\n /**\n * Receives an anchor over the selected lines as drawn, for an\n * `AnchoredPopover`, whenever the drawn selection changes: on mount, on a\n * press, and when a controlled `selectedLines` changes, such as one read\n * from the page's address. Receives null while no line in the code is\n * selected. The anchor measures the lines each time it is asked, so it\n * follows them as the page scrolls or reflows.\n */\n onSelectedLinesAnchor?: (anchor: PopoverAnchor | null) => void;\n}\n\nexport function CodeBlock({\n code,\n language = 'text',\n showLineNumbers = false,\n maxHeight,\n className,\n bare = false,\n surface,\n selectedLines,\n onSelectLines,\n onSelectedLinesAnchor,\n}: CodeBlockProps) {\n const wrapRef = useRef<HTMLDivElement>(null);\n const preRef = useRef<HTMLPreElement>(null);\n const pivot = useRef<number | null>(null);\n const [ownSelection, setOwnSelection] = useState<CodeLineRange | null>(null);\n const selection = selectedLines === undefined ? ownSelection : selectedLines;\n const selectable = onSelectLines !== undefined;\n const numbered = showLineNumbers || selectable;\n const agentAttrs = usePrimitiveSurface(\n surface,\n { code, language },\n 'code',\n wrapRef,\n );\n const { copied, copy } = useCopyToClipboard(1500);\n const strings = useStrings();\n\n const handleCopy = useCallback(() => {\n void copy(code);\n }, [copy, code]);\n\n const lines = code.split('\\n');\n const padLen = String(lines.length).length;\n\n const anchorFor = useCallback(\n (range: CodeLineRange): PopoverAnchor => ({\n getBoundingClientRect: () => {\n const rows = preRef.current?.querySelectorAll<HTMLElement>(\n '.aegis-code-block__line',\n );\n const first = rows?.[range.start - 1]?.getBoundingClientRect();\n const last = rows?.[range.end - 1]?.getBoundingClientRect();\n if (!first || !last) {\n return new DOMRect();\n }\n return new DOMRect(\n first.left,\n first.top,\n first.width,\n last.bottom - first.top,\n );\n },\n contains: (node) => preRef.current?.contains(node) ?? false,\n }),\n [],\n );\n\n const handleLinePress = useCallback(\n (line: number, event: MouseEvent<HTMLButtonElement>) => {\n const from = event.shiftKey ? pivot.current : null;\n const only =\n selection?.start === line && selection.end === line && from === null;\n const next: CodeLineRange | null = only\n ? null\n : from === null\n ? { start: line, end: line }\n : { start: Math.min(from, line), end: Math.max(from, line) };\n if (from === null) {\n pivot.current = next ? line : null;\n }\n setOwnSelection(next);\n onSelectLines?.(next, next ? anchorFor(next) : null);\n },\n [selection, onSelectLines, anchorFor],\n );\n\n const drawnStart =\n selection && selection.start <= lines.length ? selection.start : null;\n const drawnEnd =\n selection && drawnStart !== null\n ? Math.min(selection.end, lines.length)\n : null;\n const drawnAnchor = useMemo(\n () =>\n drawnStart === null || drawnEnd === null\n ? null\n : anchorFor({ start: drawnStart, end: drawnEnd }),\n [anchorFor, drawnStart, drawnEnd],\n );\n // Read by the effect below, which runs only when the drawn selection does.\n const anchorListener = useRef(onSelectedLinesAnchor);\n anchorListener.current = onSelectedLinesAnchor;\n useEffect(() => {\n anchorListener.current?.(drawnAnchor);\n }, [drawnAnchor]);\n\n const selectedSet = useMemo(\n () =>\n selection\n ? (line: number) => line >= selection.start && line <= selection.end\n : () => false,\n [selection],\n );\n\n const cls = [\n 'aegis-code-block',\n bare ? 'aegis-code-block--bare' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div ref={wrapRef} className={cls} {...agentAttrs}>\n {!bare && (\n <div className=\"aegis-code-block__header\">\n <span className=\"aegis-code-block__lang\">\n {language === 'text' ? strings.plainTextLanguage : language}\n </span>\n <button\n type=\"button\"\n className=\"aegis-code-block__copy\"\n onClick={handleCopy}\n aria-label={strings.copyToClipboard}\n >\n <CopyGlyph copied={copied} />\n {copied ? strings.copied : strings.copy}\n </button>\n </div>\n )}\n <pre\n ref={preRef}\n className=\"aegis-code-block__pre\"\n style={maxHeight === undefined ? undefined : { maxHeight }}\n >\n <code>\n {lines.map((line, i) => {\n const number = i + 1;\n const selected = selectedSet(number);\n const label = String(number).padStart(padLen, ' ');\n return (\n <div\n key={i}\n className={\n selected\n ? 'aegis-code-block__line aegis-code-block__line--selected'\n : 'aegis-code-block__line'\n }\n >\n {numbered &&\n (selectable ? (\n <button\n type=\"button\"\n className=\"aegis-code-block__ln aegis-code-block__ln--button\"\n aria-label={strings.codeLine(number)}\n aria-pressed={selected}\n onClick={(event) => {\n handleLinePress(number, event);\n }}\n >\n {label}\n </button>\n ) : (\n <span className=\"aegis-code-block__ln\">{label}</span>\n ))}\n <span className=\"aegis-code-block__body\">{line || ' '}</span>\n </div>\n );\n })}\n </code>\n </pre>\n </div>\n );\n}\n"],"names":["CodeBlock","code","language","showLineNumbers","maxHeight","className","bare","surface","selectedLines","onSelectLines","onSelectedLinesAnchor","wrapRef","useRef","preRef","pivot","ownSelection","setOwnSelection","useState","selection","selectable","numbered","agentAttrs","usePrimitiveSurface","copied","copy","useCopyToClipboard","strings","useStrings","handleCopy","useCallback","lines","padLen","anchorFor","range","rows","first","last","node","handleLinePress","line","event","from","next","drawnStart","drawnEnd","drawnAnchor","useMemo","anchorListener","useEffect","selectedSet","cls","jsxs","jsx","CopyGlyph","i","number","selected","label"],"mappings":";;;;;;;AAsEO,SAASA,GAAU;AAAA,EACxB,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,SAAAC;AAAA,EACA,eAAAC;AAAA,EACA,eAAAC;AAAA,EACA,uBAAAC;AACF,GAAmB;AACjB,QAAMC,IAAUC,EAAuB,IAAI,GACrCC,IAASD,EAAuB,IAAI,GACpCE,IAAQF,EAAsB,IAAI,GAClC,CAACG,GAAcC,CAAe,IAAIC,EAA+B,IAAI,GACrEC,IAAYV,MAAkB,SAAYO,IAAeP,GACzDW,IAAaV,MAAkB,QAC/BW,IAAWjB,KAAmBgB,GAC9BE,IAAaC;AAAA,IACjBf;AAAA,IACA,EAAE,MAAAN,GAAM,UAAAC,EAAA;AAAA,IACR;AAAA,IACAS;AAAA,EAAA,GAEI,EAAE,QAAAY,GAAQ,MAAAC,MAASC,EAAmB,IAAI,GAC1CC,IAAUC,EAAA,GAEVC,IAAaC,EAAY,MAAM;AACnC,IAAKL,EAAKvB,CAAI;AAAA,EAChB,GAAG,CAACuB,GAAMvB,CAAI,CAAC,GAET6B,IAAQ7B,EAAK,MAAM;AAAA,CAAI,GACvB8B,IAAS,OAAOD,EAAM,MAAM,EAAE,QAE9BE,IAAYH;AAAA,IAChB,CAACI,OAAyC;AAAA,MACxC,uBAAuB,MAAM;AAC3B,cAAMC,IAAOrB,EAAO,SAAS;AAAA,UAC3B;AAAA,QAAA,GAEIsB,IAAQD,IAAOD,EAAM,QAAQ,CAAC,GAAG,sBAAA,GACjCG,IAAOF,IAAOD,EAAM,MAAM,CAAC,GAAG,sBAAA;AACpC,eAAI,CAACE,KAAS,CAACC,IACN,IAAI,QAAA,IAEN,IAAI;AAAA,UACTD,EAAM;AAAA,UACNA,EAAM;AAAA,UACNA,E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BACnC,gBAAcC;AAAA,oBACd,SAAS,CAAChB,MAAU;AAClB,sBAAAF,EAAgBiB,GAAQf,CAAK;AAAA,oBAC/B;AAAA,oBAEC,UAAAiB;AAAA,kBAAA;AAAA,gBAAA,IAGH,gBAAAL,EAAC,QAAA,EAAK,WAAU,wBAAwB,UAAAK,EAAA,CAAM;AAAA,gBAElD,gBAAAL,EAAC,QAAA,EAAK,WAAU,0BAA0B,eAAQ,IAAA,CAAI;AAAA,cAAA;AAAA,YAAA;AAAA,YAvBjDE;AAAA,UAAA;AAAA,QA0BX,CAAC,EAAA,CACH;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,GACF;AAEJ;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),g=require("react"),le=require("@ant-design/icons"),Ue=require("../../agent/core/usePrimitiveSurface.cjs"),Ve=require("../../hooks/useDevelopAfterLoad.cjs"),Ge=require("../../hooks/useMediaQuery.cjs"),ie=require("./Checkbox.cjs");;/* empty css */const Fe=require("./EmptyState.cjs"),Xe=require("./Pagination.cjs"),ne=require("./Skeleton.cjs"),Ye=require("./selectedRowDetail.cjs"),Je=require("./useColumnWidths.cjs"),Ze=require("../../locale/useStrings.cjs"),E=44,W=32,de=40,Ke="var(--aegis-data-table-pinned-max)",et="(max-width: 768px)",tt='a, button, input, select, textarea, label, [role="button"], [role="link"], [role="checkbox"]';function at(l){if(window.getSelection()?.type==="Range")return!0;const o=l.target;if(!(o instanceof Element))return!1;const f=o.closest(tt);return f!==null&&l.currentTarget.contains(f)}function st(l,o,f){const w=o?.sortValue;if(!w)return l;const j=f==="asc"?1:-1;return l.map((i,n)=>{const h=w(i);return{row:i,index:n,v:typeof h=="number"&&isNaN(h)?null:h}}).sort((i,n)=>{if(i.v===null||n.v===null)return i.v===n.v?i.index-n.index:i.v===null?1:-1;const h=typeof i.v=="number"&&typeof n.v=="number"?i.v-n.v:String(i.v).localeCompare(String(n.v));return h===0?i.index-n.index:h*j}).map(i=>i.row)}function lt({direction:l}){return t.jsxs("svg",{className:"aegis-data-table__sort-icon",viewBox:"0 0 12 12","aria-hidden":"true",children:[t.jsx("path",{className:l==="asc"?"aegis-data-table__sort-mark--on":void 0,d:"M3.5 5L6 2.5 8.5 5"}),t.jsx("path",{className:l==="desc"?"aegis-data-table__sort-mark--on":void 0,d:"M3.5 7L6 9.5 8.5 7"})]})}function it({columns:l,data:o,rowKey:f,ariaLabel:w,loading:j=!1,emptyTitle:i,emptyDescription:n,emptyAction:h,className:ce,framed:oe=!0,density:re="default",header:ue="filled",persistKey:_e,pagination:B,selectable:d=!1,selectedKeys:z,onSelectedKeysChange:H,renderExpanded:Q,expandedKeys:U,defaultExpandedKeys:ge,onExpandedKeysChange:he,renderMobileCard:V,onRowClick:T,stickyFirstColumn:be=!1,stale:G=!1,sort:L,defaultSort:xe,onSortChange:me,surface:fe}){const v=Ze.useStrings(),pe=Ge.useMediaQuery(et),je=g.useId(),b=V!==void 0&&pe,ve=Ve.useDevelopAfterLoad(j),[ye,Ne]=g.useState(xe??null),r=L===void 0?ye:L,F=l.find(e=>e.key===r?.key),$=g.useMemo(()=>st(o,F,r?.direction??"asc"),[o,F,r?.direction]),ke=e=>{const a=e.firstSortDirection??(e.numeric?"desc":"asc"),s={key:e.key,direction:r?.key===e.key?r.direction==="asc"?"desc":"asc":a};L===void 0&&Ne(s),me?.(s)},y=z??[],p=$.map((e,a)=>f(e,a)),O=g.useContext(Ye.SelectedRowDetailContext),X=p.find(e=>y.includes(e)),M=p.filter(e=>y.includes(e)).length,Se=(e,a)=>{H?.(a?[...y,e]:y.filter(s=>s!==e))},Ce=e=>{const a=y.filter(s=>!p.includes(s));H?.(e?[...a,...p]:a)},we=(e,a)=>t.jsx(ie.Checkbox,{checked:e,onChange:a,ariaLabel:v.selectRow}),[Re,qe]=g.useState(ge??[]),x=U??Re,[P,De]=g.useState(x),Y=x.filter(e=>!P.includes(e));Y.length>0&&De([...P,...Y]);const Ee=e=>{const a=x.includes(e)?x.filter(s=>s!==e):[...x,e];U===void 0&&qe(a),he?.(a)},J=g.useRef(null),Z=g.useRef(null),Te=Ue.usePrimitiveSurface(fe,o,"table",Z),u=Q!==void 0,c=T!==void 0,R=(d?E:0)+(u?W:0),Le=c?de:0,S=be&&!b,N=Je.useColumnWidths({columns:l,persistKey:_e,leadWidth:R,trailWidth:Le,firstColumnMax:S?Ke:void 0,tableRef:J}),$e=["aegis-data-table",oe?"aegis-data-table--framed":"",re==="compact"?"aegis-data-table--compact":"",ue==="plain"?"aegis-data-table--plain-header":"",G?"aegis-data-table--stale":"",ce??""].filter(Boolean).join(" "),q=N.sized&&!b,D=q&&N.fillerStyle!==void 0,K=(b?1:l.length)+(D?1:0)+(c?1:0),Oe=K+(d?1:0)+(u?1:0),Me=d?E:0,k=(e,a)=>({className:[`aegis-data-table__${a}`,`aegis-data-table__${e}-cell`,S?`aegis-data-table__${a}--sticky`:""].filter(Boolean).join(" "),style:{width:e==="select"?E:W,left:S?e==="select"?0:Me:void 0}}),I=(e,a,s)=>{const _=`aegis-data-table__${e}`,m=[_];return S&&a===0&&m.push(`${_}--sticky`,`${_}--pinned`),s!==void 0&&(m.push("aegis-data-table__td--tone",`aegis-data-table__td--tone-${s.tone}`),s.step!==void 0&&s.step>1&&m.push(`aegis-data-table__td--step-${String(s.step)}`)),m.join(" ")},ee=e=>e.kind==="actions"||e.numeric===!0?"right":e.align??"left",A=(e,a)=>({textAlign:ee(e),left:S&&a===0?R:void 0}),te=(e,a)=>{const s=["aegis-data-table__cell",`aegis-data-table__cell--${ee(e)}`];return e.numeric&&s.push("aegis-data-table__cell--numeric"),e.kind==="actions"?s.push("aegis-data-table__cell--actions"):(e.truncate??!0)&&s.push("aegis-data-table__cell--truncate"),t.jsx("div",{className:s.join(" "),children:a})},Pe=(e,a)=>b?t.jsx("td",{className:"aegis-data-table__td aegis-data-table__card-cell",children:V(e,a)}):l.map((s,_)=>t.jsx("td",{className:I("td",_,s.cellTone?.(e,a)),style:A(s,_),children:te(s,s.render(e,a))},s.key)),Ie=()=>b?t.jsx("td",{className:"aegis-data-table__td aegis-data-table__card-cell",children:t.jsx(ne.SkeletonText,{lines:2})}):l.map((e,a)=>t.jsx("td",{className:I("td",a),style:A(e,a),children:te(e,t.jsx(ne.Skeleton,{width:"80%",height:"var(--space-3)"}))},e.key)),ae=D&&t.jsx("td",{className:"aegis-data-table__td aegis-data-table__filler","aria-hidden":!0}),Ae=c&&t.jsx("td",{className:"aegis-data-table__td aegis-data-table__chevron-cell","aria-hidden":!0,children:t.jsx(le.RightOutlined,{className:"aegis-data-table__chevron","aria-hidden":!0})}),We=(e,a)=>{const s=x.includes(e);return t.jsx("button",{type:"button",className:"aegis-data-table__toggle","aria-expanded":s,"aria-controls":a,"aria-label":s?v.collapseRow:v.expandRow,onClick:()=>{Ee(e)},children:t.jsx(le.RightOutlined,{className:"aegis-data-table__toggle-icon","aria-hidden":!0})})},se=(e,a,s)=>t.jsxs("tr",{className:e?"aegis-data-table__detail-row aegis-data-table__detail-row--open":"aegis-data-table__detail-row",children:[d&&t.jsx("td",{className:"aegis-data-table__detail-cell"}),u&&t.jsx("td",{className:"aegis-data-table__detail-cell"}),t.jsx("td",{id:s,colSpan:K,className:"aegis-data-table__detail-cell",children:t.jsx("div",{className:"aegis-data-table__detail",style:{left:R,width:`calc(100cqi - ${String(R)}px)`},children:a})})]}),Be=(e,a,s)=>{at(e)||T?.(a,s)},ze=(e,a,s)=>{e.key==="Enter"&&e.target===e.currentTarget&&(e.preventDefault(),T?.(a,s))},He=e=>["aegis-data-table__row",c?"aegis-data-table__row--clickable":"",u?"aegis-data-table__row--expandable":"",e?"aegis-data-table__row--selected":""].filter(Boolean).join(" "),Qe=["aegis-data-table__table",q?"aegis-data-table__table--fixed":"",b?"aegis-data-table__table--cards":""].filter(Boolean).join(" ");return t.jsxs("div",{ref:Z,className:$e,"aria-busy":G||j?!0:void 0,...Te,children:[t.jsx("div",{className:"aegis-data-table__scroll-frame",children:t.jsx("div",{className:"aegis-data-table__scroll",children:t.jsxs("table",{ref:J,"aria-label":w,className:Qe,style:q?N.tableStyle:void 0,children:[q&&t.jsxs("colgroup",{children:[d&&t.jsx("col",{style:{width:E}},"__select"),u&&t.jsx("col",{style:{width:W}},"__toggle"),l.map((e,a)=>{const s=N.widths[a];return t.jsx("col",{"data-column-key":e.key,style:s?{width:s}:void 0},e.key)}),D&&t.jsx("col",{"data-column-filler":!0,style:N.fillerStyle},"__filler"),c&&t.jsx("col",{style:{width:de}},"__chevron")]}),(!b||d)&&t.jsx("thead",{children:t.jsxs("tr",{children:[d&&t.jsx("th",{scope:"col",...k("select","th"),children:t.jsx("span",{className:"aegis-data-table__th-label",children:t.jsx(ie.Checkbox,{checked:p.length>0&&M===p.length,indeterminate:M>0&&M<p.length,onChange:Ce,ariaLabel:v.selectAllRows})})},"__select"),u&&t.jsx("th",{scope:"col",...k("toggle","th")},"__toggle"),b?t.jsx("th",{scope:"col",className:"aegis-data-table__th"}):l.map((e,a)=>t.jsxs("th",{scope:"col","data-column-key":e.key,className:I("th",a),style:A(e,a),"aria-sort":e.sortable?r?.key===e.key?r.direction==="asc"?"ascending":"descending":"none":void 0,children:[e.sortable?t.jsxs("button",{type:"button",className:"aegis-data-table__sort",onClick:()=>{ke(e)},children:[t.jsx("span",{className:"aegis-data-table__th-label",children:e.header}),t.jsx(lt,{direction:r?.key===e.key?r.direction:null})]}):t.jsx("span",{className:"aegis-data-table__th-label",children:e.header}),e.resizable&&t.jsx("span",{"aria-label":v.resizeColumn,className:"aegis-data-table__resizer",...N.handleProps(e)})]},e.key)),D&&t.jsx("th",{scope:"col",className:"aegis-data-table__th aegis-data-table__filler","aria-hidden":!0}),c&&t.jsx("th",{scope:"col",className:"aegis-data-table__th aegis-data-table__chevron-cell","aria-hidden":!0})]})}),t.jsx("tbody",{"data-aegis-develop":ve||void 0,children:j?Array.from({length:5}).map((e,a)=>t.jsxs("tr",{className:"aegis-data-table__row",children:[d&&t.jsx("td",{...k("select","td")},"__select"),u&&t.jsx("td",{...k("toggle","td")},"__toggle"),Ie(),ae,c&&t.jsx("td",{className:"aegis-data-table__td","aria-hidden":!0})]},`sk-${a}`)):$.length===0?t.jsx("tr",{role:"presentation",children:t.jsx("td",{colSpan:Oe,className:"aegis-data-table__empty-cell",children:t.jsx("div",{className:"aegis-data-table__empty",children:t.jsx(Fe.EmptyState,{title:i??v.noData,description:n,action:h})})})}):$.map((e,a)=>{const s=f(e,a),_=`${je}-detail-${String(a)}`,m=y.includes(s);return t.jsxs(g.Fragment,{children:[t.jsxs("tr",{ref:s===X?O?.placeRow:void 0,className:He(m),"aria-selected":d||z!==void 0?m:void 0,tabIndex:c?0:void 0,onClick:c?C=>{Be(C,e,a)}:void 0,onKeyDown:c?C=>{ze(C,e,a)}:void 0,children:[d&&t.jsx("td",{...k("select","td"),children:we(m,C=>{Se(s,C)})}),u&&t.jsx("td",{...k("toggle","td"),children:We(s,_)}),Pe(e,a),ae,Ae]}),s===X&&O?.inline?se(!0,O.inline):null,u&&se(x.includes(s),t.jsx("div",{className:"aegis-data-table__detail-clip",children:t.jsx("div",{className:"aegis-data-table__detail-body",children:(x.includes(s)||P.includes(s))&&Q(e,a)})}),_)]},s)})})]})})}),B&&t.jsx(Xe.Pagination,{...B,pageRowCount:o.length,disabled:j,className:"aegis-data-table__footer"})]})}exports.DataTable=it;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),m=require("react"),ne=require("@ant-design/icons"),Fe=require("../../agent/core/usePrimitiveSurface.cjs"),Xe=require("../../hooks/useDevelopAfterLoad.cjs"),Ye=require("../../hooks/useMediaQuery.cjs"),de=require("./Checkbox.cjs");;/* empty css */const Je=require("./EmptyState.cjs"),Ze=require("./Pagination.cjs"),oe=require("./Skeleton.cjs"),Ke=require("./selectedRowDetail.cjs"),et=require("./useColumnWidths.cjs"),tt=require("../../locale/useStrings.cjs"),E=44,B=32,re=40,at="var(--aegis-data-table-pinned-max)",st="(max-width: 768px)",lt='a, button, input, select, textarea, label, [role="button"], [role="link"], [role="checkbox"]';function it(l){if(window.getSelection()?.type==="Range")return!0;const _=l.target;if(!(_ instanceof Element))return!1;const v=_.closest(lt);return v!==null&&l.currentTarget.contains(v)}function nt(l,_,v){const R=_?.sortValue;if(!R)return l;const y=v==="asc"?1:-1;return l.map((i,d)=>{const x=R(i);return{row:i,index:d,v:typeof x=="number"&&isNaN(x)?null:x}}).sort((i,d)=>{if(i.v===null||d.v===null)return i.v===d.v?i.index-d.index:i.v===null?1:-1;const x=typeof i.v=="number"&&typeof d.v=="number"?i.v-d.v:String(i.v).localeCompare(String(d.v));return x===0?i.index-d.index:x*y}).map(i=>i.row)}function dt({direction:l}){return t.jsxs("svg",{className:"aegis-data-table__sort-icon",viewBox:"0 0 12 12","aria-hidden":"true",children:[t.jsx("path",{className:l==="asc"?"aegis-data-table__sort-mark--on":void 0,d:"M3.5 5L6 2.5 8.5 5"}),t.jsx("path",{className:l==="desc"?"aegis-data-table__sort-mark--on":void 0,d:"M3.5 7L6 9.5 8.5 7"})]})}function ot({columns:l,data:_,rowKey:v,ariaLabel:R,loading:y=!1,emptyTitle:i,emptyDescription:d,emptyAction:x,className:ce,framed:_e=!0,density:ue="default",header:H="filled",appearance:ge="table",rowTone:he,persistKey:be,pagination:z,selectable:o=!1,selectedKeys:Q,onSelectedKeysChange:U,renderExpanded:V,expandedKeys:G,defaultExpandedKeys:me,onExpandedKeysChange:xe,renderMobileCard:F,onRowClick:T,stickyFirstColumn:pe=!1,stale:X=!1,sort:L,defaultSort:fe,onSortChange:ve,surface:je}){const N=tt.useStrings(),ye=Ye.useMediaQuery(st),Ne=m.useId(),n=ge==="blocks",p=F!==void 0&&ye&&!n,ke=Xe.useDevelopAfterLoad(y),[Se,we]=m.useState(fe??null),u=L===void 0?Se:L,Y=l.find(e=>e.key===u?.key),O=m.useMemo(()=>nt(_,Y,u?.direction??"asc"),[_,Y,u?.direction]),Ce=e=>{const a=e.firstSortDirection??(e.numeric?"desc":"asc"),s={key:e.key,direction:u?.key===e.key?u.direction==="asc"?"desc":"asc":a};L===void 0&&we(s),ve?.(s)},k=Q??[],j=O.map((e,a)=>v(e,a)),M=m.useContext(Ke.SelectedRowDetailContext),J=j.find(e=>k.includes(e)),P=j.filter(e=>k.includes(e)).length,Re=(e,a)=>{U?.(a?[...k,e]:k.filter(s=>s!==e))},qe=e=>{const a=k.filter(s=>!j.includes(s));U?.(e?[...a,...j]:a)},De=(e,a)=>t.jsx(de.Checkbox,{checked:e,onChange:a,ariaLabel:N.selectRow}),[$e,Ee]=m.useState(me??[]),f=G??$e,[A,Te]=m.useState(f),Z=f.filter(e=>!A.includes(e));Z.length>0&&Te([...A,...Z]);const Le=e=>{const a=f.includes(e)?f.filter(s=>s!==e):[...f,e];G===void 0&&Ee(a),xe?.(a)},K=m.useRef(null),ee=m.useRef(null),Oe=Fe.usePrimitiveSurface(je,_,"table",ee),g=V!==void 0,r=T!==void 0,q=(o?E:0)+(g?B:0),Me=r?re:0,C=pe&&!p,S=et.useColumnWidths({columns:l,persistKey:be,leadWidth:q,trailWidth:Me,firstColumnMax:C?at:void 0,tableRef:K}),Pe=["aegis-data-table",_e?"aegis-data-table--framed":"",ue==="compact"?"aegis-data-table--compact":"",H==="plain"?"aegis-data-table--plain-header":"",H==="hidden"||n?"aegis-data-table--hidden-header":"",n?"aegis-data-table--blocks":"",X?"aegis-data-table--stale":"",ce??""].filter(Boolean).join(" "),D=S.sized&&!p&&!n,$=D&&S.fillerStyle!==void 0,te=(p?1:l.length)+($?1:0)+(r?1:0),Ae=te+(o?1:0)+(g?1:0),Ie=o?E:0,w=(e,a)=>({className:[`aegis-data-table__${a}`,`aegis-data-table__${e}-cell`,C?`aegis-data-table__${a}--sticky`:""].filter(Boolean).join(" "),style:{width:e==="select"?E:B,left:C?e==="select"?0:Ie:void 0}}),I=(e,a,s)=>{const c=`aegis-data-table__${e}`,h=[c];C&&a===0&&h.push(`${c}--sticky`,`${c}--pinned`);const b=l[a]?.block;return n&&b!==void 0&&b!=="inline"&&h.push(`${c}--${b}`),s!==void 0&&(h.push("aegis-data-table__td--tone",`aegis-data-table__td--tone-${s.tone}`),s.step!==void 0&&s.step>1&&h.push(`aegis-data-table__td--step-${String(s.step)}`)),h.join(" ")},ae=e=>e.kind==="actions"||e.numeric===!0?"right":e.align??"left",W=(e,a)=>({textAlign:ae(e),left:C&&a===0?q:void 0}),se=(e,a)=>{const s=["aegis-data-table__cell",`aegis-data-table__cell--${ae(e)}`];return e.numeric&&s.push("aegis-data-table__cell--numeric"),e.kind==="actions"?s.push("aegis-data-table__cell--actions"):(e.truncate??!0)&&s.push("aegis-data-table__cell--truncate"),t.jsx("div",{className:s.join(" "),children:a})},We=(e,a)=>p?t.jsx("td",{className:"aegis-data-table__td aegis-data-table__card-cell",children:F(e,a)}):l.map((s,c)=>t.jsxs("td",{role:n?"cell":void 0,className:I("td",c,s.cellTone?.(e,a)),style:W(s,c),children:[n&&s.blockLabel?t.jsx("span",{className:"aegis-data-table__block-label","aria-hidden":!0,children:s.header}):null,se(s,s.render(e,a))]},s.key)),Be=()=>p?t.jsx("td",{className:"aegis-data-table__td aegis-data-table__card-cell",children:t.jsx(oe.SkeletonText,{lines:2})}):l.map((e,a)=>t.jsx("td",{className:I("td",a),style:W(e,a),children:se(e,t.jsx(oe.Skeleton,{width:"80%",height:"var(--space-3)"}))},e.key)),le=$&&t.jsx("td",{className:"aegis-data-table__td aegis-data-table__filler","aria-hidden":!0}),He=r&&t.jsx("td",{className:"aegis-data-table__td aegis-data-table__chevron-cell","aria-hidden":!0,children:t.jsx(ne.RightOutlined,{className:"aegis-data-table__chevron","aria-hidden":!0})}),ze=(e,a)=>{const s=f.includes(e);return t.jsx("button",{type:"button",className:"aegis-data-table__toggle","aria-expanded":s,"aria-controls":a,"aria-label":s?N.collapseRow:N.expandRow,onClick:()=>{Le(e)},children:t.jsx(ne.RightOutlined,{className:"aegis-data-table__toggle-icon","aria-hidden":!0})})},ie=(e,a,s)=>t.jsxs("tr",{className:e?"aegis-data-table__detail-row aegis-data-table__detail-row--open":"aegis-data-table__detail-row",children:[o&&t.jsx("td",{className:"aegis-data-table__detail-cell"}),g&&t.jsx("td",{className:"aegis-data-table__detail-cell"}),t.jsx("td",{id:s,colSpan:te,className:"aegis-data-table__detail-cell",children:t.jsx("div",{className:"aegis-data-table__detail",style:{left:q,width:`calc(100cqi - ${String(q)}px)`},children:a})})]}),Qe=(e,a,s)=>{it(e)||T?.(a,s)},Ue=(e,a,s)=>{e.key==="Enter"&&e.target===e.currentTarget&&(e.preventDefault(),T?.(a,s))},Ve=(e,a)=>["aegis-data-table__row",n&&a!==void 0?`aegis-data-table__row--tone-${a}`:"",r?"aegis-data-table__row--clickable":"",g?"aegis-data-table__row--expandable":"",e?"aegis-data-table__row--selected":""].filter(Boolean).join(" "),Ge=["aegis-data-table__table",D?"aegis-data-table__table--fixed":"",p?"aegis-data-table__table--cards":""].filter(Boolean).join(" ");return t.jsxs("div",{ref:ee,className:Pe,"aria-busy":X||y?!0:void 0,...Oe,children:[t.jsx("div",{className:"aegis-data-table__scroll-frame",children:t.jsx("div",{className:"aegis-data-table__scroll",children:t.jsxs("table",{ref:K,role:n?"table":void 0,"aria-label":R,className:Ge,style:D?S.tableStyle:void 0,children:[D&&t.jsxs("colgroup",{children:[o&&t.jsx("col",{style:{width:E}},"__select"),g&&t.jsx("col",{style:{width:B}},"__toggle"),l.map((e,a)=>{const s=S.widths[a];return t.jsx("col",{"data-column-key":e.key,style:s?{width:s}:void 0},e.key)}),$&&t.jsx("col",{"data-column-filler":!0,style:S.fillerStyle},"__filler"),r&&t.jsx("col",{style:{width:re}},"__chevron")]}),(!p||o)&&t.jsx("thead",{role:n?"rowgroup":void 0,children:t.jsxs("tr",{role:n?"row":void 0,children:[o&&t.jsx("th",{scope:"col",...w("select","th"),children:t.jsx("span",{className:"aegis-data-table__th-label",children:t.jsx(de.Checkbox,{checked:j.length>0&&P===j.length,indeterminate:P>0&&P<j.length,onChange:qe,ariaLabel:N.selectAllRows})})},"__select"),g&&t.jsx("th",{scope:"col",...w("toggle","th")},"__toggle"),p?t.jsx("th",{scope:"col",className:"aegis-data-table__th"}):l.map((e,a)=>t.jsxs("th",{scope:"col",role:n?"columnheader":void 0,"data-column-key":e.key,className:I("th",a),style:W(e,a),"aria-sort":e.sortable?u?.key===e.key?u.direction==="asc"?"ascending":"descending":"none":void 0,children:[e.sortable?t.jsxs("button",{type:"button",className:"aegis-data-table__sort",onClick:()=>{Ce(e)},children:[t.jsx("span",{className:"aegis-data-table__th-label",children:e.header}),t.jsx(dt,{direction:u?.key===e.key?u.direction:null})]}):t.jsx("span",{className:e.headerHidden?"aegis-data-table__th-label aegis-data-table__th-label--hidden":"aegis-data-table__th-label",children:e.header}),e.resizable&&t.jsx("span",{"aria-label":N.resizeColumn,className:"aegis-data-table__resizer",...S.handleProps(e)})]},e.key)),$&&t.jsx("th",{scope:"col",className:"aegis-data-table__th aegis-data-table__filler","aria-hidden":!0}),r&&t.jsx("th",{scope:"col",className:"aegis-data-table__th aegis-data-table__chevron-cell","aria-hidden":!0})]})}),t.jsx("tbody",{role:n?"rowgroup":void 0,"data-aegis-develop":ke||void 0,children:y?Array.from({length:5}).map((e,a)=>t.jsxs("tr",{className:"aegis-data-table__row",children:[o&&t.jsx("td",{...w("select","td")},"__select"),g&&t.jsx("td",{...w("toggle","td")},"__toggle"),Be(),le,r&&t.jsx("td",{className:"aegis-data-table__td","aria-hidden":!0})]},`sk-${a}`)):O.length===0?t.jsx("tr",{role:"presentation",children:t.jsx("td",{colSpan:Ae,className:"aegis-data-table__empty-cell",children:t.jsx("div",{className:"aegis-data-table__empty",children:t.jsx(Je.EmptyState,{title:i??N.noData,description:d,action:x})})})}):O.map((e,a)=>{const s=v(e,a),c=`${Ne}-detail-${String(a)}`,h=k.includes(s);return t.jsxs(m.Fragment,{children:[t.jsxs("tr",{ref:s===J?M?.placeRow:void 0,role:n?"row":void 0,className:Ve(h,he?.(e,a)),"aria-selected":o||Q!==void 0?h:void 0,tabIndex:r?0:void 0,onClick:r?b=>{Qe(b,e,a)}:void 0,onKeyDown:r?b=>{Ue(b,e,a)}:void 0,children:[o&&t.jsx("td",{...w("select","td"),children:De(h,b=>{Re(s,b)})}),g&&t.jsx("td",{...w("toggle","td"),children:ze(s,c)}),We(e,a),le,He]}),s===J&&M?.inline?ie(!0,M.inline):null,g&&ie(f.includes(s),t.jsx("div",{className:"aegis-data-table__detail-clip",children:t.jsx("div",{className:"aegis-data-table__detail-body",children:(f.includes(s)||A.includes(s))&&V(e,a)})}),c)]},s)})})]})})}),z&&t.jsx(Ze.Pagination,{...z,pageRowCount:_.length,disabled:y,className:"aegis-data-table__footer"})]})}exports.DataTable=ot;
2
2
  //# sourceMappingURL=DataTable.cjs.map