@lincyaw/aegis-ui 0.17.1 → 0.19.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/components/ui/AnchoredPopover.cjs +2 -0
- package/dist/components/ui/AnchoredPopover.cjs.map +1 -0
- package/dist/components/ui/AnchoredPopover.d.ts +49 -0
- package/dist/components/ui/AnchoredPopover.js +144 -0
- package/dist/components/ui/AnchoredPopover.js.map +1 -0
- package/dist/components/ui/Breadcrumb.cjs +1 -1
- package/dist/components/ui/Breadcrumb.cjs.map +1 -1
- package/dist/components/ui/Breadcrumb.d.ts +13 -1
- package/dist/components/ui/Breadcrumb.js +28 -19
- package/dist/components/ui/Breadcrumb.js.map +1 -1
- package/dist/components/ui/CodeBlock.cjs +2 -2
- package/dist/components/ui/CodeBlock.cjs.map +1 -1
- package/dist/components/ui/CodeBlock.d.ts +28 -1
- package/dist/components/ui/CodeBlock.js +94 -36
- package/dist/components/ui/CodeBlock.js.map +1 -1
- package/dist/components/ui/DetailBeside.cjs +1 -1
- package/dist/components/ui/DetailBeside.cjs.map +1 -1
- package/dist/components/ui/DetailBeside.d.ts +38 -9
- package/dist/components/ui/DetailBeside.js +104 -85
- package/dist/components/ui/DetailBeside.js.map +1 -1
- package/dist/components/ui/LineIcon.cjs +2 -0
- package/dist/components/ui/LineIcon.cjs.map +1 -0
- package/dist/components/ui/LineIcon.d.ts +15 -0
- package/dist/components/ui/LineIcon.js +33 -0
- package/dist/components/ui/LineIcon.js.map +1 -0
- package/dist/components/ui/PaneLayout.cjs +2 -0
- package/dist/components/ui/PaneLayout.cjs.map +1 -0
- package/dist/components/ui/PaneLayout.d.ts +33 -0
- package/dist/components/ui/PaneLayout.js +34 -0
- package/dist/components/ui/PaneLayout.js.map +1 -0
- package/dist/components/ui/Quote.cjs +2 -0
- package/dist/components/ui/Quote.cjs.map +1 -0
- package/dist/components/ui/Quote.d.ts +12 -0
- package/dist/components/ui/Quote.js +10 -0
- package/dist/components/ui/Quote.js.map +1 -0
- package/dist/components/ui/SectionDivider.cjs +1 -1
- package/dist/components/ui/SectionDivider.cjs.map +1 -1
- package/dist/components/ui/SectionDivider.d.ts +7 -1
- package/dist/components/ui/SectionDivider.js +9 -7
- package/dist/components/ui/SectionDivider.js.map +1 -1
- package/dist/components/ui/StatusDot.cjs.map +1 -1
- package/dist/components/ui/StatusDot.d.ts +3 -2
- package/dist/components/ui/StatusDot.js.map +1 -1
- package/dist/components/ui/Toolbar.cjs +1 -1
- package/dist/components/ui/Toolbar.cjs.map +1 -1
- package/dist/components/ui/Toolbar.d.ts +10 -1
- package/dist/components/ui/Toolbar.js +17 -7
- package/dist/components/ui/Toolbar.js.map +1 -1
- package/dist/components/ui/index.d.ts +10 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +343 -332
- package/dist/index.js.map +1 -1
- package/dist/layouts/PageWrapper.cjs +1 -1
- package/dist/layouts/PageWrapper.cjs.map +1 -1
- package/dist/layouts/PageWrapper.d.ts +7 -1
- package/dist/layouts/PageWrapper.js +13 -8
- package/dist/layouts/PageWrapper.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.d.ts +1 -1
- package/dist/layouts/shell/AegisShell.js +193 -150
- package/dist/layouts/shell/AegisShell.js.map +1 -1
- package/dist/layouts/shell/ShellMenuToggle.cjs +2 -0
- package/dist/layouts/shell/ShellMenuToggle.cjs.map +1 -0
- package/dist/layouts/shell/ShellMenuToggle.d.ts +8 -0
- package/dist/layouts/shell/ShellMenuToggle.js +23 -0
- package/dist/layouts/shell/ShellMenuToggle.js.map +1 -0
- package/dist/layouts/shell/Sidebar.cjs +1 -1
- package/dist/layouts/shell/Sidebar.cjs.map +1 -1
- package/dist/layouts/shell/Sidebar.d.ts +10 -4
- package/dist/layouts/shell/Sidebar.js +39 -32
- package/dist/layouts/shell/Sidebar.js.map +1 -1
- package/dist/layouts/shell/TopHeader.cjs +1 -1
- package/dist/layouts/shell/TopHeader.cjs.map +1 -1
- package/dist/layouts/shell/TopHeader.d.ts +14 -0
- package/dist/layouts/shell/TopHeader.js +127 -110
- package/dist/layouts/shell/TopHeader.js.map +1 -1
- package/dist/layouts/shell/buildRouteTree.cjs +1 -1
- package/dist/layouts/shell/buildRouteTree.cjs.map +1 -1
- package/dist/layouts/shell/buildRouteTree.js +5 -5
- package/dist/layouts/shell/buildRouteTree.js.map +1 -1
- package/dist/layouts/shell/index.d.ts +1 -0
- package/dist/layouts/shell/shellNavContext.cjs +2 -0
- package/dist/layouts/shell/shellNavContext.cjs.map +1 -0
- package/dist/layouts/shell/shellNavContext.d.ts +8 -0
- package/dist/layouts/shell/shellNavContext.js +6 -0
- package/dist/layouts/shell/shellNavContext.js.map +1 -0
- package/dist/layouts/shell/types.d.ts +21 -0
- package/dist/lib/scrollView.cjs +1 -1
- package/dist/lib/scrollView.cjs.map +1 -1
- package/dist/lib/scrollView.d.ts +6 -0
- package/dist/lib/scrollView.js +26 -17
- package/dist/lib/scrollView.js.map +1 -1
- package/dist/locale/strings.cjs +1 -1
- package/dist/locale/strings.cjs.map +1 -1
- package/dist/locale/strings.d.ts +2 -0
- package/dist/locale/strings.js +7 -5
- package/dist/locale/strings.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),s=require("react"),D=require("react-dom");;/* empty css */const A='a[href], button:not(:disabled), input:not(:disabled):not([type="hidden"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';function M(i,e,c,y,l){const g=window.innerHeight-i.bottom,E=i.top,u=c==="auto"?g>=e.height+l||g>=E?"bottom":"top":c,w=u==="bottom"?i.bottom+l:i.top-l-e.height,h=y==="start"?i.left:i.right-e.width,p=window.innerWidth-e.width-l;return{top:w,left:Math.max(l,Math.min(h,p)),side:u}}function N(i){const e=i.offsetParent;if(!(e instanceof HTMLElement)||e===document.body&&getComputedStyle(e).position==="static")return{top:-window.scrollY,left:-window.scrollX};const c=e.getBoundingClientRect();return{top:c.top+e.clientTop-e.scrollTop,left:c.left+e.clientLeft-e.scrollLeft}}function j({open:i,anchor:e,onClose:c,children:y,placement:l="auto",align:g="start",ariaLabel:E,container:u=null,autoFocus:w=!0,className:h}){const p=s.useRef(null),v=s.useRef(null),[m,L]=s.useState(null),a=i&&e!==null,C=s.useCallback(()=>{const r=p.current;if(!r||!e)return;const t=parseFloat(getComputedStyle(r).getPropertyValue("--anchored-popover-gap")),f=M(e.getBoundingClientRect(),r.getBoundingClientRect(),l,g,Number.isNaN(t)?0:t);if(u===null){L(f);return}const b=N(r);L({...f,top:f.top-b.top,left:f.left-b.left})},[e,l,g,u]);s.useLayoutEffect(()=>{if(!a){L(null);return}C();let r=0;const t=()=>{cancelAnimationFrame(r),r=requestAnimationFrame(C)};return window.addEventListener("scroll",t,!0),window.addEventListener("resize",t),()=>{cancelAnimationFrame(r),window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",t)}},[a,C]);const d=s.useRef({anchor:e,onClose:c});d.current={anchor:e,onClose:c};const R=s.useCallback(()=>{d.current.onClose(),v.current?.focus()},[]);s.useEffect(()=>{if(!a)return;const r=document.activeElement;v.current=r instanceof HTMLElement?r:null;const t=p.current,f=n=>{const{target:o}=n;!(o instanceof Node)||t?.contains(o)||d.current.anchor?.contains?.(o)||d.current.onClose()},b=n=>{if(!t||n.key!=="Tab")return;const o=Array.from(t.querySelectorAll(A)).filter(q=>q.getClientRects().length>0);(n.shiftKey?n.target===t||n.target===o[0]:o.length===0||n.target===o[o.length-1])&&(n.preventDefault(),R())},k=n=>{const{target:o}=n;if(!(!(o instanceof Node)||n.isComposing)){if(n.key==="Tab"&&!n.shiftKey&&t&&!t.contains(o)&&d.current.anchor?.contains?.(o)){n.preventDefault(),v.current=o instanceof HTMLElement?o:null,(t.querySelector(A)??t).focus();return}n.key==="Escape"&&(t?.contains(o)?(n.preventDefault(),n.stopPropagation(),R()):d.current.anchor?.contains?.(o)&&(n.preventDefault(),n.stopPropagation(),d.current.onClose()))}};return document.addEventListener("pointerdown",f,!0),document.addEventListener("keydown",k),t?.addEventListener("keydown",b),()=>{document.removeEventListener("pointerdown",f,!0),document.removeEventListener("keydown",k),t?.removeEventListener("keydown",b)}},[a,R]);const P=m!==null,x=s.useRef(!1);if(s.useEffect(()=>{if(!a){x.current=!1;return}if(!w||!P||x.current)return;x.current=!0;const r=p.current;(r?.querySelector(A)??r)?.focus({preventScroll:!0})},[a,P,w]),!a)return null;const S=["aegis-anchored-popover",u===null?"":"aegis-anchored-popover--contained",m?`aegis-anchored-popover--${m.side}`:"",h??""].filter(Boolean).join(" "),T=m?{top:m.top,left:m.left}:{visibility:"hidden"};return D.createPortal(B.jsx("div",{ref:p,className:S,style:T,role:"dialog","aria-label":E,tabIndex:-1,children:y}),u??document.body)}exports.AnchoredPopover=j;
|
|
2
|
+
//# sourceMappingURL=AnchoredPopover.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnchoredPopover.cjs","sources":["../../../src/components/ui/AnchoredPopover.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport './AnchoredPopover.css';\n\n/**\n * What a popover stands beside: an element, or anything that reports a\n * rectangle in viewport coordinates, such as a range of selected lines.\n */\nexport interface PopoverAnchor {\n getBoundingClientRect: () => DOMRect;\n /** Presses inside the anchor leave the popover open, e.g. to move a selection. */\n contains?: (node: Node) => boolean;\n}\n\nexport interface AnchoredPopoverProps {\n open: boolean;\n anchor: PopoverAnchor | null;\n /** Fired by Escape, a press outside the popover and its anchor, or Tab out of it. */\n onClose: () => void;\n children: ReactNode;\n /**\n * `auto` opens below the anchor and flips above it when there is more\n * room there; `bottom` and `top` keep their side.\n */\n placement?: 'auto' | 'bottom' | 'top';\n /** `start` lines the popover up with the anchor's left edge, `end` with its right. */\n align?: 'start' | 'end';\n /** Accessible name of the popover, which is a non-modal dialog. */\n ariaLabel: string;\n /**\n * The element the popover is drawn in, such as the page's `main`, so it\n * belongs to that landmark; omitted or null means `document.body`. Inside\n * a container the popover is placed in the box of its nearest positioned\n * ancestor and follows the anchor as the container or the page scrolls.\n */\n container?: HTMLElement | null;\n /**\n * Whether opening moves focus into the popover. Turn it off for a popover\n * that opens with the page, such as one over a selection the address\n * names, so it does not take focus on load; Tab from the anchor still\n * enters it.\n */\n autoFocus?: boolean;\n className?: string;\n}\n\nconst TABBABLE =\n 'a[href], button:not(:disabled), input:not(:disabled):not([type=\"hidden\"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])';\n\ninterface Position {\n top: number;\n left: number;\n side: 'top' | 'bottom';\n}\n\nfunction place(\n anchor: DOMRect,\n panel: DOMRect,\n placement: NonNullable<AnchoredPopoverProps['placement']>,\n align: NonNullable<AnchoredPopoverProps['align']>,\n gap: number,\n): Position {\n const below = window.innerHeight - anchor.bottom;\n const above = anchor.top;\n const side =\n placement === 'auto'\n ? below >= panel.height + gap || below >= above\n ? 'bottom'\n : 'top'\n : placement;\n const top =\n side === 'bottom' ? anchor.bottom + gap : anchor.top - gap - panel.height;\n const preferred =\n align === 'start' ? anchor.left : anchor.right - panel.width;\n const maxLeft = window.innerWidth - panel.width - gap;\n return { top, left: Math.max(gap, Math.min(preferred, maxLeft)), side };\n}\n\n/**\n * The viewport position of the box a contained panel is placed in, less\n * that box's scroll: the panel's offset parent, or the document when that\n * is the unpositioned body.\n */\nfunction originOf(panel: HTMLElement): { top: number; left: number } {\n const parent = panel.offsetParent;\n if (\n !(parent instanceof HTMLElement) ||\n (parent === document.body && getComputedStyle(parent).position === 'static')\n ) {\n return { top: -window.scrollY, left: -window.scrollX };\n }\n const box = parent.getBoundingClientRect();\n return {\n top: box.top + parent.clientTop - parent.scrollTop,\n left: box.left + parent.clientLeft - parent.scrollLeft,\n };\n}\n\n/**\n * Arbitrary content in an overlay beside an anchor, e.g. what is known\n * about a selected code range. It follows the anchor as the page scrolls\n * and closes on Escape, a press outside it, or Tab past its last control.\n * Opening moves focus to its first control; Escape and Tab hand focus back\n * to where it was.\n */\nexport function AnchoredPopover({\n open,\n anchor,\n onClose,\n children,\n placement = 'auto',\n align = 'start',\n ariaLabel,\n container = null,\n autoFocus = true,\n className,\n}: AnchoredPopoverProps) {\n const panelRef = useRef<HTMLDivElement>(null);\n const returnFocus = useRef<HTMLElement | null>(null);\n const [position, setPosition] = useState<Position | null>(null);\n const shown = open && anchor !== null;\n\n const update = useCallback(() => {\n const panel = panelRef.current;\n if (!panel || !anchor) {\n return;\n }\n const gap = parseFloat(\n getComputedStyle(panel).getPropertyValue('--anchored-popover-gap'),\n );\n const next = place(\n anchor.getBoundingClientRect(),\n panel.getBoundingClientRect(),\n placement,\n align,\n Number.isNaN(gap) ? 0 : gap,\n );\n if (container === null) {\n setPosition(next);\n return;\n }\n const origin = originOf(panel);\n setPosition({\n ...next,\n top: next.top - origin.top,\n left: next.left - origin.left,\n });\n }, [anchor, placement, align, container]);\n\n useLayoutEffect(() => {\n if (!shown) {\n setPosition(null);\n return undefined;\n }\n update();\n let frame = 0;\n const schedule = (): void => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(update);\n };\n window.addEventListener('scroll', schedule, true);\n window.addEventListener('resize', schedule);\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('scroll', schedule, true);\n window.removeEventListener('resize', schedule);\n };\n }, [shown, update]);\n\n // Read by listeners that live as long as the popover is open.\n const latest = useRef({ anchor, onClose });\n latest.current = { anchor, onClose };\n\n const closeAndReturn = useCallback(() => {\n latest.current.onClose();\n returnFocus.current?.focus();\n }, []);\n\n useEffect(() => {\n if (!shown) {\n return undefined;\n }\n const active = document.activeElement;\n returnFocus.current = active instanceof HTMLElement ? active : null;\n const panel = panelRef.current;\n const onPointerDown = (event: PointerEvent): void => {\n const { target } = event;\n if (!(target instanceof Node) || panel?.contains(target)) {\n return;\n }\n if (latest.current.anchor?.contains?.(target)) {\n return;\n }\n latest.current.onClose();\n };\n const onKeyDown = (event: KeyboardEvent): void => {\n if (!panel) {\n return;\n }\n if (event.key !== 'Tab') {\n return;\n }\n const tabbable = Array.from(\n panel.querySelectorAll<HTMLElement>(TABBABLE),\n ).filter((element) => element.getClientRects().length > 0);\n const atEdge = event.shiftKey\n ? event.target === panel || event.target === tabbable[0]\n : tabbable.length === 0 ||\n event.target === tabbable[tabbable.length - 1];\n if (atEdge) {\n event.preventDefault();\n closeAndReturn();\n }\n };\n // Escape from the popover or its anchor, e.g. a line number just\n // pressed; Tab from the anchor enters the popover, which a portal puts\n // elsewhere in the tab order.\n const onEscape = (event: KeyboardEvent): void => {\n const { target } = event;\n if (!(target instanceof Node) || event.isComposing) {\n return;\n }\n if (\n event.key === 'Tab' &&\n !event.shiftKey &&\n panel &&\n !panel.contains(target) &&\n latest.current.anchor?.contains?.(target)\n ) {\n event.preventDefault();\n returnFocus.current = target instanceof HTMLElement ? target : null;\n (panel.querySelector<HTMLElement>(TABBABLE) ?? panel).focus();\n return;\n }\n if (event.key !== 'Escape') {\n return;\n }\n if (panel?.contains(target)) {\n event.preventDefault();\n event.stopPropagation();\n closeAndReturn();\n } else if (latest.current.anchor?.contains?.(target)) {\n event.preventDefault();\n event.stopPropagation();\n latest.current.onClose();\n }\n };\n document.addEventListener('pointerdown', onPointerDown, true);\n document.addEventListener('keydown', onEscape);\n panel?.addEventListener('keydown', onKeyDown);\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true);\n document.removeEventListener('keydown', onEscape);\n panel?.removeEventListener('keydown', onKeyDown);\n };\n }, [shown, closeAndReturn]);\n\n // Focus moves in once the panel is placed: while hidden it cannot take it.\n const placed = position !== null;\n const focused = useRef(false);\n useEffect(() => {\n if (!shown) {\n focused.current = false;\n return;\n }\n if (!autoFocus || !placed || focused.current) {\n return;\n }\n focused.current = true;\n const panel = panelRef.current;\n (panel?.querySelector<HTMLElement>(TABBABLE) ?? panel)?.focus({\n preventScroll: true,\n });\n }, [shown, placed, autoFocus]);\n\n if (!shown) {\n return null;\n }\n const cls = [\n 'aegis-anchored-popover',\n container === null ? '' : 'aegis-anchored-popover--contained',\n position ? `aegis-anchored-popover--${position.side}` : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const style: CSSProperties = position\n ? { top: position.top, left: position.left }\n : { visibility: 'hidden' };\n return createPortal(\n <div\n ref={panelRef}\n className={cls}\n style={style}\n role=\"dialog\"\n aria-label={ariaLabel}\n tabIndex={-1}\n >\n {children}\n </div>,\n container ?? document.body,\n );\n}\n"],"names":["TABBABLE","place","anchor","panel","placement","align","gap","below","above","side","top","preferred","maxLeft","originOf","parent","box","AnchoredPopover","open","onClose","children","ariaLabel","container","autoFocus","className","panelRef","useRef","returnFocus","position","setPosition","useState","shown","update","useCallback","next","origin","useLayoutEffect","frame","schedule","latest","closeAndReturn","useEffect","active","onPointerDown","event","target","onKeyDown","tabbable","element","onEscape","placed","focused","cls","style","createPortal","jsx"],"mappings":"oMAwDA,MAAMA,EACJ,6JAQF,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACU,CACV,MAAMC,EAAQ,OAAO,YAAcL,EAAO,OACpCM,EAAQN,EAAO,IACfO,EACJL,IAAc,OACVG,GAASJ,EAAM,OAASG,GAAOC,GAASC,EACtC,SACA,MACFJ,EACAM,EACJD,IAAS,SAAWP,EAAO,OAASI,EAAMJ,EAAO,IAAMI,EAAMH,EAAM,OAC/DQ,EACJN,IAAU,QAAUH,EAAO,KAAOA,EAAO,MAAQC,EAAM,MACnDS,EAAU,OAAO,WAAaT,EAAM,MAAQG,EAClD,MAAO,CAAE,IAAAI,EAAK,KAAM,KAAK,IAAIJ,EAAK,KAAK,IAAIK,EAAWC,CAAO,CAAC,E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cAA2BH,CAAQ,GAAKG,IAAQ,MAAM,CAC5D,cAAe,EAAA,CAChB,CACH,EAAG,CAAC2B,EAAOmB,EAAQ3B,CAAS,CAAC,EAEzB,CAACQ,EACH,OAAO,KAET,MAAMqB,EAAM,CACV,yBACA9B,IAAc,KAAO,GAAK,oCAC1BM,EAAW,2BAA2BA,EAAS,IAAI,GAAK,GACxDJ,GAAa,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,EACL6B,EAAuBzB,EACzB,CAAE,IAAKA,EAAS,IAAK,KAAMA,EAAS,IAAA,EACpC,CAAE,WAAY,QAAA,EAClB,OAAO0B,EAAAA,aACLC,EAAAA,IAAC,MAAA,CACC,IAAK9B,EACL,UAAW2B,EACX,MAAAC,EACA,KAAK,SACL,aAAYhC,EACZ,SAAU,GAET,SAAAD,CAAA,CAAA,EAEHE,GAAa,SAAS,IAAA,CAE1B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* What a popover stands beside: an element, or anything that reports a
|
|
4
|
+
* rectangle in viewport coordinates, such as a range of selected lines.
|
|
5
|
+
*/
|
|
6
|
+
export interface PopoverAnchor {
|
|
7
|
+
getBoundingClientRect: () => DOMRect;
|
|
8
|
+
/** Presses inside the anchor leave the popover open, e.g. to move a selection. */
|
|
9
|
+
contains?: (node: Node) => boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface AnchoredPopoverProps {
|
|
12
|
+
open: boolean;
|
|
13
|
+
anchor: PopoverAnchor | null;
|
|
14
|
+
/** Fired by Escape, a press outside the popover and its anchor, or Tab out of it. */
|
|
15
|
+
onClose: () => void;
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* `auto` opens below the anchor and flips above it when there is more
|
|
19
|
+
* room there; `bottom` and `top` keep their side.
|
|
20
|
+
*/
|
|
21
|
+
placement?: 'auto' | 'bottom' | 'top';
|
|
22
|
+
/** `start` lines the popover up with the anchor's left edge, `end` with its right. */
|
|
23
|
+
align?: 'start' | 'end';
|
|
24
|
+
/** Accessible name of the popover, which is a non-modal dialog. */
|
|
25
|
+
ariaLabel: string;
|
|
26
|
+
/**
|
|
27
|
+
* The element the popover is drawn in, such as the page's `main`, so it
|
|
28
|
+
* belongs to that landmark; omitted or null means `document.body`. Inside
|
|
29
|
+
* a container the popover is placed in the box of its nearest positioned
|
|
30
|
+
* ancestor and follows the anchor as the container or the page scrolls.
|
|
31
|
+
*/
|
|
32
|
+
container?: HTMLElement | null;
|
|
33
|
+
/**
|
|
34
|
+
* Whether opening moves focus into the popover. Turn it off for a popover
|
|
35
|
+
* that opens with the page, such as one over a selection the address
|
|
36
|
+
* names, so it does not take focus on load; Tab from the anchor still
|
|
37
|
+
* enters it.
|
|
38
|
+
*/
|
|
39
|
+
autoFocus?: boolean;
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Arbitrary content in an overlay beside an anchor, e.g. what is known
|
|
44
|
+
* about a selected code range. It follows the anchor as the page scrolls
|
|
45
|
+
* and closes on Escape, a press outside it, or Tab past its last control.
|
|
46
|
+
* Opening moves focus to its first control; Escape and Tab hand focus back
|
|
47
|
+
* to where it was.
|
|
48
|
+
*/
|
|
49
|
+
export declare function AnchoredPopover({ open, anchor, onClose, children, placement, align, ariaLabel, container, autoFocus, className, }: AnchoredPopoverProps): import('react').ReactPortal | null;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as M } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as b, useState as q, useCallback as B, useLayoutEffect as F, useEffect as R } from "react";
|
|
3
|
+
import { createPortal as H } from "react-dom";
|
|
4
|
+
/* empty css */
|
|
5
|
+
const k = 'a[href], button:not(:disabled), input:not(:disabled):not([type="hidden"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
6
|
+
function K(i, t, s, y, c) {
|
|
7
|
+
const m = window.innerHeight - i.bottom, E = i.top, l = s === "auto" ? m >= t.height + c || m >= E ? "bottom" : "top" : s, w = l === "bottom" ? i.bottom + c : i.top - c - t.height, h = y === "start" ? i.left : i.right - t.width, f = window.innerWidth - t.width - c;
|
|
8
|
+
return { top: w, left: Math.max(c, Math.min(h, f)), side: l };
|
|
9
|
+
}
|
|
10
|
+
function j(i) {
|
|
11
|
+
const t = i.offsetParent;
|
|
12
|
+
if (!(t instanceof HTMLElement) || t === document.body && getComputedStyle(t).position === "static")
|
|
13
|
+
return { top: -window.scrollY, left: -window.scrollX };
|
|
14
|
+
const s = t.getBoundingClientRect();
|
|
15
|
+
return {
|
|
16
|
+
top: s.top + t.clientTop - t.scrollTop,
|
|
17
|
+
left: s.left + t.clientLeft - t.scrollLeft
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function X({
|
|
21
|
+
open: i,
|
|
22
|
+
anchor: t,
|
|
23
|
+
onClose: s,
|
|
24
|
+
children: y,
|
|
25
|
+
placement: c = "auto",
|
|
26
|
+
align: m = "start",
|
|
27
|
+
ariaLabel: E,
|
|
28
|
+
container: l = null,
|
|
29
|
+
autoFocus: w = !0,
|
|
30
|
+
className: h
|
|
31
|
+
}) {
|
|
32
|
+
const f = b(null), v = b(null), [p, L] = q(null), u = i && t !== null, x = B(() => {
|
|
33
|
+
const r = f.current;
|
|
34
|
+
if (!r || !t)
|
|
35
|
+
return;
|
|
36
|
+
const e = parseFloat(
|
|
37
|
+
getComputedStyle(r).getPropertyValue("--anchored-popover-gap")
|
|
38
|
+
), d = K(
|
|
39
|
+
t.getBoundingClientRect(),
|
|
40
|
+
r.getBoundingClientRect(),
|
|
41
|
+
c,
|
|
42
|
+
m,
|
|
43
|
+
Number.isNaN(e) ? 0 : e
|
|
44
|
+
);
|
|
45
|
+
if (l === null) {
|
|
46
|
+
L(d);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const g = j(r);
|
|
50
|
+
L({
|
|
51
|
+
...d,
|
|
52
|
+
top: d.top - g.top,
|
|
53
|
+
left: d.left - g.left
|
|
54
|
+
});
|
|
55
|
+
}, [t, c, m, l]);
|
|
56
|
+
F(() => {
|
|
57
|
+
if (!u) {
|
|
58
|
+
L(null);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
x();
|
|
62
|
+
let r = 0;
|
|
63
|
+
const e = () => {
|
|
64
|
+
cancelAnimationFrame(r), r = requestAnimationFrame(x);
|
|
65
|
+
};
|
|
66
|
+
return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
|
|
67
|
+
cancelAnimationFrame(r), window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
|
|
68
|
+
};
|
|
69
|
+
}, [u, x]);
|
|
70
|
+
const a = b({ anchor: t, onClose: s });
|
|
71
|
+
a.current = { anchor: t, onClose: s };
|
|
72
|
+
const C = B(() => {
|
|
73
|
+
a.current.onClose(), v.current?.focus();
|
|
74
|
+
}, []);
|
|
75
|
+
R(() => {
|
|
76
|
+
if (!u)
|
|
77
|
+
return;
|
|
78
|
+
const r = document.activeElement;
|
|
79
|
+
v.current = r instanceof HTMLElement ? r : null;
|
|
80
|
+
const e = f.current, d = (n) => {
|
|
81
|
+
const { target: o } = n;
|
|
82
|
+
!(o instanceof Node) || e?.contains(o) || a.current.anchor?.contains?.(o) || a.current.onClose();
|
|
83
|
+
}, g = (n) => {
|
|
84
|
+
if (!e || n.key !== "Tab")
|
|
85
|
+
return;
|
|
86
|
+
const o = Array.from(
|
|
87
|
+
e.querySelectorAll(k)
|
|
88
|
+
).filter((N) => N.getClientRects().length > 0);
|
|
89
|
+
(n.shiftKey ? n.target === e || n.target === o[0] : o.length === 0 || n.target === o[o.length - 1]) && (n.preventDefault(), C());
|
|
90
|
+
}, T = (n) => {
|
|
91
|
+
const { target: o } = n;
|
|
92
|
+
if (!(!(o instanceof Node) || n.isComposing)) {
|
|
93
|
+
if (n.key === "Tab" && !n.shiftKey && e && !e.contains(o) && a.current.anchor?.contains?.(o)) {
|
|
94
|
+
n.preventDefault(), v.current = o instanceof HTMLElement ? o : null, (e.querySelector(k) ?? e).focus();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
n.key === "Escape" && (e?.contains(o) ? (n.preventDefault(), n.stopPropagation(), C()) : a.current.anchor?.contains?.(o) && (n.preventDefault(), n.stopPropagation(), a.current.onClose()));
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return document.addEventListener("pointerdown", d, !0), document.addEventListener("keydown", T), e?.addEventListener("keydown", g), () => {
|
|
101
|
+
document.removeEventListener("pointerdown", d, !0), document.removeEventListener("keydown", T), e?.removeEventListener("keydown", g);
|
|
102
|
+
};
|
|
103
|
+
}, [u, C]);
|
|
104
|
+
const P = p !== null, A = b(!1);
|
|
105
|
+
if (R(() => {
|
|
106
|
+
if (!u) {
|
|
107
|
+
A.current = !1;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (!w || !P || A.current)
|
|
111
|
+
return;
|
|
112
|
+
A.current = !0;
|
|
113
|
+
const r = f.current;
|
|
114
|
+
(r?.querySelector(k) ?? r)?.focus({
|
|
115
|
+
preventScroll: !0
|
|
116
|
+
});
|
|
117
|
+
}, [u, P, w]), !u)
|
|
118
|
+
return null;
|
|
119
|
+
const S = [
|
|
120
|
+
"aegis-anchored-popover",
|
|
121
|
+
l === null ? "" : "aegis-anchored-popover--contained",
|
|
122
|
+
p ? `aegis-anchored-popover--${p.side}` : "",
|
|
123
|
+
h ?? ""
|
|
124
|
+
].filter(Boolean).join(" "), D = p ? { top: p.top, left: p.left } : { visibility: "hidden" };
|
|
125
|
+
return H(
|
|
126
|
+
/* @__PURE__ */ M(
|
|
127
|
+
"div",
|
|
128
|
+
{
|
|
129
|
+
ref: f,
|
|
130
|
+
className: S,
|
|
131
|
+
style: D,
|
|
132
|
+
role: "dialog",
|
|
133
|
+
"aria-label": E,
|
|
134
|
+
tabIndex: -1,
|
|
135
|
+
children: y
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
l ?? document.body
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
X as AnchoredPopover
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=AnchoredPopover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnchoredPopover.js","sources":["../../../src/components/ui/AnchoredPopover.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport './AnchoredPopover.css';\n\n/**\n * What a popover stands beside: an element, or anything that reports a\n * rectangle in viewport coordinates, such as a range of selected lines.\n */\nexport interface PopoverAnchor {\n getBoundingClientRect: () => DOMRect;\n /** Presses inside the anchor leave the popover open, e.g. to move a selection. */\n contains?: (node: Node) => boolean;\n}\n\nexport interface AnchoredPopoverProps {\n open: boolean;\n anchor: PopoverAnchor | null;\n /** Fired by Escape, a press outside the popover and its anchor, or Tab out of it. */\n onClose: () => void;\n children: ReactNode;\n /**\n * `auto` opens below the anchor and flips above it when there is more\n * room there; `bottom` and `top` keep their side.\n */\n placement?: 'auto' | 'bottom' | 'top';\n /** `start` lines the popover up with the anchor's left edge, `end` with its right. */\n align?: 'start' | 'end';\n /** Accessible name of the popover, which is a non-modal dialog. */\n ariaLabel: string;\n /**\n * The element the popover is drawn in, such as the page's `main`, so it\n * belongs to that landmark; omitted or null means `document.body`. Inside\n * a container the popover is placed in the box of its nearest positioned\n * ancestor and follows the anchor as the container or the page scrolls.\n */\n container?: HTMLElement | null;\n /**\n * Whether opening moves focus into the popover. Turn it off for a popover\n * that opens with the page, such as one over a selection the address\n * names, so it does not take focus on load; Tab from the anchor still\n * enters it.\n */\n autoFocus?: boolean;\n className?: string;\n}\n\nconst TABBABLE =\n 'a[href], button:not(:disabled), input:not(:disabled):not([type=\"hidden\"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])';\n\ninterface Position {\n top: number;\n left: number;\n side: 'top' | 'bottom';\n}\n\nfunction place(\n anchor: DOMRect,\n panel: DOMRect,\n placement: NonNullable<AnchoredPopoverProps['placement']>,\n align: NonNullable<AnchoredPopoverProps['align']>,\n gap: number,\n): Position {\n const below = window.innerHeight - anchor.bottom;\n const above = anchor.top;\n const side =\n placement === 'auto'\n ? below >= panel.height + gap || below >= above\n ? 'bottom'\n : 'top'\n : placement;\n const top =\n side === 'bottom' ? anchor.bottom + gap : anchor.top - gap - panel.height;\n const preferred =\n align === 'start' ? anchor.left : anchor.right - panel.width;\n const maxLeft = window.innerWidth - panel.width - gap;\n return { top, left: Math.max(gap, Math.min(preferred, maxLeft)), side };\n}\n\n/**\n * The viewport position of the box a contained panel is placed in, less\n * that box's scroll: the panel's offset parent, or the document when that\n * is the unpositioned body.\n */\nfunction originOf(panel: HTMLElement): { top: number; left: number } {\n const parent = panel.offsetParent;\n if (\n !(parent instanceof HTMLElement) ||\n (parent === document.body && getComputedStyle(parent).position === 'static')\n ) {\n return { top: -window.scrollY, left: -window.scrollX };\n }\n const box = parent.getBoundingClientRect();\n return {\n top: box.top + parent.clientTop - parent.scrollTop,\n left: box.left + parent.clientLeft - parent.scrollLeft,\n };\n}\n\n/**\n * Arbitrary content in an overlay beside an anchor, e.g. what is known\n * about a selected code range. It follows the anchor as the page scrolls\n * and closes on Escape, a press outside it, or Tab past its last control.\n * Opening moves focus to its first control; Escape and Tab hand focus back\n * to where it was.\n */\nexport function AnchoredPopover({\n open,\n anchor,\n onClose,\n children,\n placement = 'auto',\n align = 'start',\n ariaLabel,\n container = null,\n autoFocus = true,\n className,\n}: AnchoredPopoverProps) {\n const panelRef = useRef<HTMLDivElement>(null);\n const returnFocus = useRef<HTMLElement | null>(null);\n const [position, setPosition] = useState<Position | null>(null);\n const shown = open && anchor !== null;\n\n const update = useCallback(() => {\n const panel = panelRef.current;\n if (!panel || !anchor) {\n return;\n }\n const gap = parseFloat(\n getComputedStyle(panel).getPropertyValue('--anchored-popover-gap'),\n );\n const next = place(\n anchor.getBoundingClientRect(),\n panel.getBoundingClientRect(),\n placement,\n align,\n Number.isNaN(gap) ? 0 : gap,\n );\n if (container === null) {\n setPosition(next);\n return;\n }\n const origin = originOf(panel);\n setPosition({\n ...next,\n top: next.top - origin.top,\n left: next.left - origin.left,\n });\n }, [anchor, placement, align, container]);\n\n useLayoutEffect(() => {\n if (!shown) {\n setPosition(null);\n return undefined;\n }\n update();\n let frame = 0;\n const schedule = (): void => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(update);\n };\n window.addEventListener('scroll', schedule, true);\n window.addEventListener('resize', schedule);\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('scroll', schedule, true);\n window.removeEventListener('resize', schedule);\n };\n }, [shown, update]);\n\n // Read by listeners that live as long as the popover is open.\n const latest = useRef({ anchor, onClose });\n latest.current = { anchor, onClose };\n\n const closeAndReturn = useCallback(() => {\n latest.current.onClose();\n returnFocus.current?.focus();\n }, []);\n\n useEffect(() => {\n if (!shown) {\n return undefined;\n }\n const active = document.activeElement;\n returnFocus.current = active instanceof HTMLElement ? active : null;\n const panel = panelRef.current;\n const onPointerDown = (event: PointerEvent): void => {\n const { target } = event;\n if (!(target instanceof Node) || panel?.contains(target)) {\n return;\n }\n if (latest.current.anchor?.contains?.(target)) {\n return;\n }\n latest.current.onClose();\n };\n const onKeyDown = (event: KeyboardEvent): void => {\n if (!panel) {\n return;\n }\n if (event.key !== 'Tab') {\n return;\n }\n const tabbable = Array.from(\n panel.querySelectorAll<HTMLElement>(TABBABLE),\n ).filter((element) => element.getClientRects().length > 0);\n const atEdge = event.shiftKey\n ? event.target === panel || event.target === tabbable[0]\n : tabbable.length === 0 ||\n event.target === tabbable[tabbable.length - 1];\n if (atEdge) {\n event.preventDefault();\n closeAndReturn();\n }\n };\n // Escape from the popover or its anchor, e.g. a line number just\n // pressed; Tab from the anchor enters the popover, which a portal puts\n // elsewhere in the tab order.\n const onEscape = (event: KeyboardEvent): void => {\n const { target } = event;\n if (!(target instanceof Node) || event.isComposing) {\n return;\n }\n if (\n event.key === 'Tab' &&\n !event.shiftKey &&\n panel &&\n !panel.contains(target) &&\n latest.current.anchor?.contains?.(target)\n ) {\n event.preventDefault();\n returnFocus.current = target instanceof HTMLElement ? target : null;\n (panel.querySelector<HTMLElement>(TABBABLE) ?? panel).focus();\n return;\n }\n if (event.key !== 'Escape') {\n return;\n }\n if (panel?.contains(target)) {\n event.preventDefault();\n event.stopPropagation();\n closeAndReturn();\n } else if (latest.current.anchor?.contains?.(target)) {\n event.preventDefault();\n event.stopPropagation();\n latest.current.onClose();\n }\n };\n document.addEventListener('pointerdown', onPointerDown, true);\n document.addEventListener('keydown', onEscape);\n panel?.addEventListener('keydown', onKeyDown);\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true);\n document.removeEventListener('keydown', onEscape);\n panel?.removeEventListener('keydown', onKeyDown);\n };\n }, [shown, closeAndReturn]);\n\n // Focus moves in once the panel is placed: while hidden it cannot take it.\n const placed = position !== null;\n const focused = useRef(false);\n useEffect(() => {\n if (!shown) {\n focused.current = false;\n return;\n }\n if (!autoFocus || !placed || focused.current) {\n return;\n }\n focused.current = true;\n const panel = panelRef.current;\n (panel?.querySelector<HTMLElement>(TABBABLE) ?? panel)?.focus({\n preventScroll: true,\n });\n }, [shown, placed, autoFocus]);\n\n if (!shown) {\n return null;\n }\n const cls = [\n 'aegis-anchored-popover',\n container === null ? '' : 'aegis-anchored-popover--contained',\n position ? `aegis-anchored-popover--${position.side}` : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const style: CSSProperties = position\n ? { top: position.top, left: position.left }\n : { visibility: 'hidden' };\n return createPortal(\n <div\n ref={panelRef}\n className={cls}\n style={style}\n role=\"dialog\"\n aria-label={ariaLabel}\n tabIndex={-1}\n >\n {children}\n </div>,\n container ?? document.body,\n );\n}\n"],"names":["TABBABLE","place","anchor","panel","placement","align","gap","below","above","side","top","preferred","maxLeft","originOf","parent","box","AnchoredPopover","open","onClose","children","ariaLabel","container","autoFocus","className","panelRef","useRef","returnFocus","position","setPosition","useState","shown","update","useCallback","next","origin","useLayoutEffect","frame","schedule","latest","closeAndReturn","useEffect","active","onPointerDown","event","target","onKeyDown","tabbable","element","onEscape","placed","focused","cls","style","createPortal","jsx"],"mappings":";;;;AAwDA,MAAMA,IACJ;AAQF,SAASC,EACPC,GACAC,GACAC,GACAC,GACAC,GACU;AACV,QAAMC,IAAQ,OAAO,cAAcL,EAAO,QACpCM,IAAQN,EAAO,KACfO,IACJL,MAAc,SACVG,KAASJ,EAAM,SAASG,KAAOC,KAASC,IACtC,WACA,QACFJ,GACAM,IACJD,MAAS,WAAWP,EAAO,SAASI,IAAMJ,EAAO,MAAMI,IAAMH,EAAM,QAC/DQ,IACJN,MAAU,UAAUH,EAAO,OAAOA,EAAO,QAAQC,EAAM,OACnDS,IAAU,OAAO,aAAaT,EAAM,QAAQG;AAClD,SAAO,EAAE,KAAAI,GAAK,MAAM,KAAK,IAAIJ,GAAK,KAAK,IAAIK,GAAWC,CAAO,CAAC,GAAG,MAAAH,EAAA;AACnE;AAOA,SAASI,EAASV,GAAmD;AACnE,QAAMW,IAASX,EAAM;AACrB,MACE,EAAEW,aAAkB,gBACnBA,MAAW,SAAS,QAAQ,iBAAiBA,CAAM,EAAE,aAAa;AAEnE,WAAO,EAAE,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,OAAO,QAAA;AAE/C,QAAMC,IAAMD,EAAO,sBAAA;AACnB,SAAO;AAAA,IACL,KAAKC,EAAI,MAAMD,EAAO,YAAYA,EAAO;AAAA,IACzC,MAAMC,EAAI,OAAOD,EAAO,aAAaA,EAAO;AAAA,EAAA;AAEhD;AASO,SAASE,EAAgB;AAAA,EAC9B,MAAAC;AAAA,EACA,QAAAf;AAAA,EACA,SAAAgB;AAAA,EACA,UAAAC;AAAA,EACA,WAAAf,IAAY;AAAA,EACZ,OAAAC,IAAQ;AAAA,EACR,W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A,EAAS,IAAI,KAAK;AAAA,IACxDJ,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,GACL6B,IAAuBzB,IACzB,EAAE,KAAKA,EAAS,KAAK,MAAMA,EAAS,KAAA,IACpC,EAAE,YAAY,SAAA;AAClB,SAAO0B;AAAA,IACL,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK9B;AAAA,QACL,WAAW2B;AAAA,QACX,OAAAC;AAAA,QACA,MAAK;AAAA,QACL,cAAYhC;AAAA,QACZ,UAAU;AAAA,QAET,UAAAD;AAAA,MAAA;AAAA,IAAA;AAAA,IAEHE,KAAa,SAAS;AAAA,EAAA;AAE1B;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");;/* empty css */const h=require("./LineIcon.cjs"),p=require("./linkComponent.cjs"),x=require("../../locale/useStrings.cjs");function j({items:s,className:u,ariaLabel:d,linkComponent:o,variant:n="path"}){const b=x.useStrings(),m=["aegis-breadcrumb",n==="trace"?"aegis-breadcrumb--trace":"",u??""].filter(Boolean).join(" "),_=o??p.DefaultLink,i=s.some(r=>r.current!==void 0);return e.jsx("nav",{"aria-label":d??b.breadcrumb,className:m,children:e.jsx("ol",{className:"aegis-breadcrumb__list",children:s.map((r,t)=>{const c=t===s.length-1,a=i?r.current===!0:c,g=r.to!==void 0&&(i||!c),l=n==="trace"?e.jsxs(e.Fragment,{children:[r.kind!==void 0&&e.jsx("span",{className:"aegis-breadcrumb__kind",children:r.kind}),e.jsx("span",{className:"aegis-breadcrumb__value",children:r.label})]}):r.label;return e.jsxs("li",{className:"aegis-breadcrumb__item",children:[g&&r.to!==void 0?e.jsx(_,{to:r.to,className:a?"aegis-breadcrumb__link aegis-breadcrumb__link--current":"aegis-breadcrumb__link","aria-current":a?"page":void 0,children:l}):e.jsx("span",{className:a?"aegis-breadcrumb__text aegis-breadcrumb__text--current":"aegis-breadcrumb__text","aria-current":a?"page":void 0,children:l}),!c&&(n==="trace"?e.jsx(h.LineIcon,{size:"sm",className:"aegis-breadcrumb__chevron",children:e.jsx("path",{d:"m9 6 6 6-6 6"})}):e.jsx("span",{className:"aegis-breadcrumb__sep","aria-hidden":"true",children:"/"}))]},t)})})})}exports.Breadcrumb=j;
|
|
2
2
|
//# sourceMappingURL=Breadcrumb.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumb.cjs","sources":["../../../src/components/ui/Breadcrumb.tsx"],"sourcesContent":["import { type ReactElement, type ReactNode } from 'react';\n\nimport { useStrings } from '../../locale';\nimport './Breadcrumb.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface BreadcrumbItem {\n label: ReactNode;\n /** Optional destination. If omitted, the item renders as plain text. */\n to?: string;\n /**\n * Marks the item as the current page: `aria-current=\"page\"` and main ink.\n * When no item sets it, the last item is the current page and renders as\n * text. Once any item sets it, every item with `to` renders as a link,\n * the last included, and only the items set to `true` are current, so a\n * trail can end at a page other than the one shown.\n */\n current?: boolean;\n}\n\ninterface BreadcrumbProps {\n items: BreadcrumbItem[];\n className?: string;\n /** Accessible name of the navigation. Defaults to the locale's `breadcrumb`. */\n ariaLabel?: string;\n /**\n * Component used to render linked breadcrumb items. Defaults to an\n * unstyled `<a href>`. Sub-apps using a router should pass their\n * Link adapter here.\n */\n linkComponent?: LinkComponent;\n}\n\nexport function Breadcrumb({\n items,\n className,\n ariaLabel,\n linkComponent,\n}: BreadcrumbProps): ReactElement {\n const strings = useStrings();\n const cls = ['aegis-breadcrumb'
|
|
1
|
+
{"version":3,"file":"Breadcrumb.cjs","sources":["../../../src/components/ui/Breadcrumb.tsx"],"sourcesContent":["import { type ReactElement, type ReactNode } from 'react';\n\nimport { useStrings } from '../../locale';\nimport './Breadcrumb.css';\nimport { LineIcon } from './LineIcon';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface BreadcrumbItem {\n label: ReactNode;\n /** Optional destination. If omitted, the item renders as plain text. */\n to?: string;\n /**\n * Marks the item as the current page: `aria-current=\"page\"` and main ink.\n * When no item sets it, the last item is the current page and renders as\n * text. Once any item sets it, every item with `to` renders as a link,\n * the last included, and only the items set to `true` are current, so a\n * trail can end at a page other than the one shown.\n */\n current?: boolean;\n /**\n * What the item is, e.g. 需求 or 模块, set before its label in the\n * `trace` variant, whose label is then an identifier in the code face.\n */\n kind?: ReactNode;\n}\n\ninterface BreadcrumbProps {\n items: BreadcrumbItem[];\n className?: string;\n /** Accessible name of the navigation. Defaults to the locale's `breadcrumb`. */\n ariaLabel?: string;\n /**\n * Component used to render linked breadcrumb items. Defaults to an\n * unstyled `<a href>`. Sub-apps using a router should pass their\n * Link adapter here.\n */\n linkComponent?: LinkComponent;\n /**\n * `path` is a page trail divided by slashes. `trace` follows one record\n * through related structures: each item a pill of its `kind` and its\n * label, the current one in the brand's soft surface, divided by\n * chevrons.\n */\n variant?: 'path' | 'trace';\n}\n\nexport function Breadcrumb({\n items,\n className,\n ariaLabel,\n linkComponent,\n variant = 'path',\n}: BreadcrumbProps): ReactElement {\n const strings = useStrings();\n const cls = [\n 'aegis-breadcrumb',\n variant === 'trace' ? 'aegis-breadcrumb--trace' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const LinkImpl = linkComponent ?? DefaultLink;\n const explicit = items.some((item) => item.current !== undefined);\n\n return (\n <nav aria-label={ariaLabel ?? strings.breadcrumb} className={cls}>\n <ol className=\"aegis-breadcrumb__list\">\n {items.map((item, idx) => {\n const isLast = idx === items.length - 1;\n const isCurrent = explicit ? item.current === true : isLast;\n const linked = item.to !== undefined && (explicit || !isLast);\n const content =\n variant === 'trace' ? (\n <>\n {item.kind !== undefined && (\n <span className=\"aegis-breadcrumb__kind\">{item.kind}</span>\n )}\n <span className=\"aegis-breadcrumb__value\">{item.label}</span>\n </>\n ) : (\n item.label\n );\n return (\n <li key={idx} className=\"aegis-breadcrumb__item\">\n {linked && item.to !== undefined ? (\n <LinkImpl\n to={item.to}\n className={\n isCurrent\n ? 'aegis-breadcrumb__link aegis-breadcrumb__link--current'\n : 'aegis-breadcrumb__link'\n }\n aria-current={isCurrent ? 'page' : undefined}\n >\n {content}\n </LinkImpl>\n ) : (\n <span\n className={\n isCurrent\n ? 'aegis-breadcrumb__text aegis-breadcrumb__text--current'\n : 'aegis-breadcrumb__text'\n }\n aria-current={isCurrent ? 'page' : undefined}\n >\n {content}\n </span>\n )}\n {!isLast &&\n (variant === 'trace' ? (\n <LineIcon size=\"sm\" className=\"aegis-breadcrumb__chevron\">\n <path d=\"m9 6 6 6-6 6\" />\n </LineIcon>\n ) : (\n <span className=\"aegis-breadcrumb__sep\" aria-hidden=\"true\">\n /\n </span>\n ))}\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"names":["Breadcrumb","items","className","ariaLabel","linkComponent","variant","strings","useStrings","cls","LinkImpl","DefaultLink","explicit","item","jsx","idx","isLast","isCurrent","linked","content","jsxs","Fragment","LineIcon"],"mappings":"iQA8CO,SAASA,EAAW,CACzB,MAAAC,EACA,UAAAC,EACA,UAAAC,EAAA,cACAC,EACA,QAAAC,EAAU,MACZ,EAAkC,CAChC,MAAMC,EAAUC,EAAAA,WAAA,EACVC,EAAM,CACV,mBACAH,IAAY,QAAU,0BAA4B,GAClDH,GAAa,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,EACLO,EAAWL,GAAiBM,EAAAA,YAC5BC,EAAWV,EAAM,KAAMW,GAASA,EAAK,UAAY,MAAS,EAEhE,aACG,MAAA,CAAI,aAAYT,GAAaG,EAAQ,WAAY,UAAWE,EAC3D,SAAAK,EAAAA,IAAC,KAAA,CAAG,UAAU,yBACX,SAAAZ,EAAM,IAAI,CAACW,EAAME,IAAQ,CACxB,MAAMC,EAASD,IAAQb,EAAM,OAAS,EAChCe,EAAYL,EAAWC,EAAK,UAAY,GAAOG,EAC/CE,EAASL,EAAK,KAAO,SAAcD,GAAY,CAACI,GAChDG,EACJb,IAAY,QACVc,EAAAA,KAAAC,EAAAA,SAAA,CACG,SAAA,CAAAR,EAAK,OAAS,QACbC,EAAAA,IAAC,QAAK,UAAU,yBAA0B,WAAK,IAAA,CAAK,EAEtDA,EAAAA,IAAC,OAAA,CAAK,UAAU,0BAA2B,WAAK,KAAA,CAAM,CAAA,CAAA,CACxD,EAEAD,EAAK,MAET,OACEO,EAAAA,KAAC,KAAA,CAAa,UAAU,yBACrB,SAAA,CAAAF,GAAUL,EAAK,KAAO,OACrBC,EAAAA,IAACJ,EAAA,CACC,GAAIG,EAAK,GACT,UACEI,EACI,yDACA,yBAEN,eAAcA,EAAY,OAAS,OAElC,SAAAE,CAAA,CAAA,EAGHL,EAAAA,IAAC,OAAA,CACC,UACEG,EACI,yDACA,yBAEN,eAAcA,EAAY,OAAS,OAElC,SAAAE,CAAA,CAAA,EAGJ,CAACH,IACCV,IAAY,cACVgB,EAAAA,SAAA,CAAS,KAAK,KAAK,UAAU,4BAC5B,SAAAR,EAAAA,IAAC,QAAK,EAAE,cAAA,CAAe,EACzB,EAEAA,EAAAA,IAAC,QAAK,UAAU,wBAAwB,cAAY,OAAO,SAAA,GAAA,CAE3D,EAAA,CAAA,EAjCGC,CAmCT,CAEJ,CAAC,EACH,EACF,CAEJ"}
|
|
@@ -12,6 +12,11 @@ export interface BreadcrumbItem {
|
|
|
12
12
|
* trail can end at a page other than the one shown.
|
|
13
13
|
*/
|
|
14
14
|
current?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* What the item is, e.g. 需求 or 模块, set before its label in the
|
|
17
|
+
* `trace` variant, whose label is then an identifier in the code face.
|
|
18
|
+
*/
|
|
19
|
+
kind?: ReactNode;
|
|
15
20
|
}
|
|
16
21
|
interface BreadcrumbProps {
|
|
17
22
|
items: BreadcrumbItem[];
|
|
@@ -24,6 +29,13 @@ interface BreadcrumbProps {
|
|
|
24
29
|
* Link adapter here.
|
|
25
30
|
*/
|
|
26
31
|
linkComponent?: LinkComponent;
|
|
32
|
+
/**
|
|
33
|
+
* `path` is a page trail divided by slashes. `trace` follows one record
|
|
34
|
+
* through related structures: each item a pill of its `kind` and its
|
|
35
|
+
* label, the current one in the brand's soft surface, divided by
|
|
36
|
+
* chevrons.
|
|
37
|
+
*/
|
|
38
|
+
variant?: 'path' | 'trace';
|
|
27
39
|
}
|
|
28
|
-
export declare function Breadcrumb({ items, className, ariaLabel, linkComponent, }: BreadcrumbProps): ReactElement;
|
|
40
|
+
export declare function Breadcrumb({ items, className, ariaLabel, linkComponent, variant, }: BreadcrumbProps): ReactElement;
|
|
29
41
|
export {};
|
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
import { jsx as e, jsxs as
|
|
1
|
+
import { jsx as e, jsxs as d, Fragment as h } from "react/jsx-runtime";
|
|
2
2
|
/* empty css */
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { LineIcon as k } from "./LineIcon.js";
|
|
4
|
+
import { DefaultLink as N } from "./linkComponent.js";
|
|
5
|
+
import { useStrings as f } from "../../locale/useStrings.js";
|
|
6
|
+
function I({
|
|
7
|
+
items: c,
|
|
8
|
+
className: o,
|
|
9
|
+
ariaLabel: b,
|
|
10
|
+
linkComponent: m,
|
|
11
|
+
variant: s = "path"
|
|
10
12
|
}) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const u = f(), _ = [
|
|
14
|
+
"aegis-breadcrumb",
|
|
15
|
+
s === "trace" ? "aegis-breadcrumb--trace" : "",
|
|
16
|
+
o ?? ""
|
|
17
|
+
].filter(Boolean).join(" "), g = m ?? N, i = c.some((r) => r.current !== void 0);
|
|
18
|
+
return /* @__PURE__ */ e("nav", { "aria-label": b ?? u.breadcrumb, className: _, children: /* @__PURE__ */ e("ol", { className: "aegis-breadcrumb__list", children: c.map((r, t) => {
|
|
19
|
+
const n = t === c.length - 1, a = i ? r.current === !0 : n, p = r.to !== void 0 && (i || !n), l = s === "trace" ? /* @__PURE__ */ d(h, { children: [
|
|
20
|
+
r.kind !== void 0 && /* @__PURE__ */ e("span", { className: "aegis-breadcrumb__kind", children: r.kind }),
|
|
21
|
+
/* @__PURE__ */ e("span", { className: "aegis-breadcrumb__value", children: r.label })
|
|
22
|
+
] }) : r.label;
|
|
23
|
+
return /* @__PURE__ */ d("li", { className: "aegis-breadcrumb__item", children: [
|
|
24
|
+
p && r.to !== void 0 ? /* @__PURE__ */ e(
|
|
25
|
+
g,
|
|
17
26
|
{
|
|
18
27
|
to: r.to,
|
|
19
28
|
className: a ? "aegis-breadcrumb__link aegis-breadcrumb__link--current" : "aegis-breadcrumb__link",
|
|
20
29
|
"aria-current": a ? "page" : void 0,
|
|
21
|
-
children:
|
|
30
|
+
children: l
|
|
22
31
|
}
|
|
23
32
|
) : /* @__PURE__ */ e(
|
|
24
33
|
"span",
|
|
25
34
|
{
|
|
26
35
|
className: a ? "aegis-breadcrumb__text aegis-breadcrumb__text--current" : "aegis-breadcrumb__text",
|
|
27
36
|
"aria-current": a ? "page" : void 0,
|
|
28
|
-
children:
|
|
37
|
+
children: l
|
|
29
38
|
}
|
|
30
39
|
),
|
|
31
|
-
!
|
|
32
|
-
] },
|
|
40
|
+
!n && (s === "trace" ? /* @__PURE__ */ e(k, { size: "sm", className: "aegis-breadcrumb__chevron", children: /* @__PURE__ */ e("path", { d: "m9 6 6 6-6 6" }) }) : /* @__PURE__ */ e("span", { className: "aegis-breadcrumb__sep", "aria-hidden": "true", children: "/" }))
|
|
41
|
+
] }, t);
|
|
33
42
|
}) }) });
|
|
34
43
|
}
|
|
35
44
|
export {
|
|
36
|
-
|
|
45
|
+
I as Breadcrumb
|
|
37
46
|
};
|
|
38
47
|
//# sourceMappingURL=Breadcrumb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumb.js","sources":["../../../src/components/ui/Breadcrumb.tsx"],"sourcesContent":["import { type ReactElement, type ReactNode } from 'react';\n\nimport { useStrings } from '../../locale';\nimport './Breadcrumb.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface BreadcrumbItem {\n label: ReactNode;\n /** Optional destination. If omitted, the item renders as plain text. */\n to?: string;\n /**\n * Marks the item as the current page: `aria-current=\"page\"` and main ink.\n * When no item sets it, the last item is the current page and renders as\n * text. Once any item sets it, every item with `to` renders as a link,\n * the last included, and only the items set to `true` are current, so a\n * trail can end at a page other than the one shown.\n */\n current?: boolean;\n}\n\ninterface BreadcrumbProps {\n items: BreadcrumbItem[];\n className?: string;\n /** Accessible name of the navigation. Defaults to the locale's `breadcrumb`. */\n ariaLabel?: string;\n /**\n * Component used to render linked breadcrumb items. Defaults to an\n * unstyled `<a href>`. Sub-apps using a router should pass their\n * Link adapter here.\n */\n linkComponent?: LinkComponent;\n}\n\nexport function Breadcrumb({\n items,\n className,\n ariaLabel,\n linkComponent,\n}: BreadcrumbProps): ReactElement {\n const strings = useStrings();\n const cls = ['aegis-breadcrumb'
|
|
1
|
+
{"version":3,"file":"Breadcrumb.js","sources":["../../../src/components/ui/Breadcrumb.tsx"],"sourcesContent":["import { type ReactElement, type ReactNode } from 'react';\n\nimport { useStrings } from '../../locale';\nimport './Breadcrumb.css';\nimport { LineIcon } from './LineIcon';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface BreadcrumbItem {\n label: ReactNode;\n /** Optional destination. If omitted, the item renders as plain text. */\n to?: string;\n /**\n * Marks the item as the current page: `aria-current=\"page\"` and main ink.\n * When no item sets it, the last item is the current page and renders as\n * text. Once any item sets it, every item with `to` renders as a link,\n * the last included, and only the items set to `true` are current, so a\n * trail can end at a page other than the one shown.\n */\n current?: boolean;\n /**\n * What the item is, e.g. 需求 or 模块, set before its label in the\n * `trace` variant, whose label is then an identifier in the code face.\n */\n kind?: ReactNode;\n}\n\ninterface BreadcrumbProps {\n items: BreadcrumbItem[];\n className?: string;\n /** Accessible name of the navigation. Defaults to the locale's `breadcrumb`. */\n ariaLabel?: string;\n /**\n * Component used to render linked breadcrumb items. Defaults to an\n * unstyled `<a href>`. Sub-apps using a router should pass their\n * Link adapter here.\n */\n linkComponent?: LinkComponent;\n /**\n * `path` is a page trail divided by slashes. `trace` follows one record\n * through related structures: each item a pill of its `kind` and its\n * label, the current one in the brand's soft surface, divided by\n * chevrons.\n */\n variant?: 'path' | 'trace';\n}\n\nexport function Breadcrumb({\n items,\n className,\n ariaLabel,\n linkComponent,\n variant = 'path',\n}: BreadcrumbProps): ReactElement {\n const strings = useStrings();\n const cls = [\n 'aegis-breadcrumb',\n variant === 'trace' ? 'aegis-breadcrumb--trace' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const LinkImpl = linkComponent ?? DefaultLink;\n const explicit = items.some((item) => item.current !== undefined);\n\n return (\n <nav aria-label={ariaLabel ?? strings.breadcrumb} className={cls}>\n <ol className=\"aegis-breadcrumb__list\">\n {items.map((item, idx) => {\n const isLast = idx === items.length - 1;\n const isCurrent = explicit ? item.current === true : isLast;\n const linked = item.to !== undefined && (explicit || !isLast);\n const content =\n variant === 'trace' ? (\n <>\n {item.kind !== undefined && (\n <span className=\"aegis-breadcrumb__kind\">{item.kind}</span>\n )}\n <span className=\"aegis-breadcrumb__value\">{item.label}</span>\n </>\n ) : (\n item.label\n );\n return (\n <li key={idx} className=\"aegis-breadcrumb__item\">\n {linked && item.to !== undefined ? (\n <LinkImpl\n to={item.to}\n className={\n isCurrent\n ? 'aegis-breadcrumb__link aegis-breadcrumb__link--current'\n : 'aegis-breadcrumb__link'\n }\n aria-current={isCurrent ? 'page' : undefined}\n >\n {content}\n </LinkImpl>\n ) : (\n <span\n className={\n isCurrent\n ? 'aegis-breadcrumb__text aegis-breadcrumb__text--current'\n : 'aegis-breadcrumb__text'\n }\n aria-current={isCurrent ? 'page' : undefined}\n >\n {content}\n </span>\n )}\n {!isLast &&\n (variant === 'trace' ? (\n <LineIcon size=\"sm\" className=\"aegis-breadcrumb__chevron\">\n <path d=\"m9 6 6 6-6 6\" />\n </LineIcon>\n ) : (\n <span className=\"aegis-breadcrumb__sep\" aria-hidden=\"true\">\n /\n </span>\n ))}\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"names":["Breadcrumb","items","className","ariaLabel","linkComponent","variant","strings","useStrings","cls","LinkImpl","DefaultLink","explicit","item","jsx","idx","isLast","isCurrent","linked","content","jsxs","Fragment","LineIcon"],"mappings":";;;;;AA8CO,SAASA,EAAW;AAAA,EACzB,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,SAAAC,IAAU;AACZ,GAAkC;AAChC,QAAMC,IAAUC,EAAA,GACVC,IAAM;AAAA,IACV;AAAA,IACAH,MAAY,UAAU,4BAA4B;AAAA,IAClDH,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,GACLO,IAAWL,KAAiBM,GAC5BC,IAAWV,EAAM,KAAK,CAACW,MAASA,EAAK,YAAY,MAAS;AAEhE,2BACG,OAAA,EAAI,cAAYT,KAAaG,EAAQ,YAAY,WAAWE,GAC3D,UAAA,gBAAAK,EAAC,MAAA,EAAG,WAAU,0BACX,UAAAZ,EAAM,IAAI,CAACW,GAAME,MAAQ;AACxB,UAAMC,IAASD,MAAQb,EAAM,SAAS,GAChCe,IAAYL,IAAWC,EAAK,YAAY,KAAOG,GAC/CE,IAASL,EAAK,OAAO,WAAcD,KAAY,CAACI,IAChDG,IACJb,MAAY,UACV,gBAAAc,EAAAC,GAAA,EACG,UAAA;AAAA,MAAAR,EAAK,SAAS,UACb,gBAAAC,EAAC,UAAK,WAAU,0BAA0B,YAAK,KAAA,CAAK;AAAA,MAEtD,gBAAAA,EAAC,QAAA,EAAK,WAAU,2BAA2B,YAAK,MAAA,CAAM;AAAA,IAAA,EAAA,CACxD,IAEAD,EAAK;AAET,WACE,gBAAAO,EAAC,MAAA,EAAa,WAAU,0BACrB,UAAA;AAAA,MAAAF,KAAUL,EAAK,OAAO,SACrB,gBAAAC;AAAA,QAACJ;AAAA,QAAA;AAAA,UACC,IAAIG,EAAK;AAAA,UACT,WACEI,IACI,2DACA;AAAA,UAEN,gBAAcA,IAAY,SAAS;AAAA,UAElC,UAAAE;AAAA,QAAA;AAAA,MAAA,IAGH,gBAAAL;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WACEG,IACI,2DACA;AAAA,UAEN,gBAAcA,IAAY,SAAS;AAAA,UAElC,UAAAE;AAAA,QAAA;AAAA,MAAA;AAAA,MAGJ,CAACH,MACCV,MAAY,4BACVgB,GAAA,EAAS,MAAK,MAAK,WAAU,6BAC5B,UAAA,gBAAAR,EAAC,UAAK,GAAE,eAAA,CAAe,GACzB,IAEA,gBAAAA,EAAC,UAAK,WAAU,yBAAwB,eAAY,QAAO,UAAA,IAAA,CAE3D;AAAA,IAAA,EAAA,GAjCGC,CAmCT;AAAA,EAEJ,CAAC,GACH,GACF;AAEJ;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`),
|
|
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;
|
|
3
3
|
//# sourceMappingURL=CodeBlock.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.cjs","sources":["../../../src/components/ui/CodeBlock.tsx"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useCopyToClipboard } from '../../hooks/useCopyToClipboard';\nimport { useStrings } from '../../locale';\nimport './CodeBlock.css';\nimport { CopyGlyph } from './CopyGlyph';\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\nexport function CodeBlock({\n code,\n language = 'text',\n showLineNumbers = false,\n maxHeight,\n className,\n surface,\n}: CodeBlockProps) {\n const wrapRef = useRef<HTMLDivElement>(null);\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 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 className=\"aegis-code-block__pre\"\n style={maxHeight === undefined ? undefined : { maxHeight }}\n >\n <code>\n {lines.map((line, i) => (\n <div key={i} className=\"aegis-code-block__line\">\n {showLineNumbers && (\n <span className=\"aegis-code-block__ln\">\n {String(i + 1).padStart(padLen, ' ')}\n </span>\n )}\n <span className=\"aegis-code-block__body\">{line || ' '}</span>\n </div>\n ))}\n </code>\n </pre>\n </div>\n );\n}\n"],"names":["CodeBlock","code","language","showLineNumbers","maxHeight","className","surface","wrapRef","useRef","agentAttrs","usePrimitiveSurface","copied","copy","useCopyToClipboard","strings","useStrings","handleCopy","useCallback","lines","padLen","cls","jsxs","jsx","CopyGlyph","line","i"],"mappings":"yVA2BO,SAASA,EAAU,CACxB,KAAAC,EACA,SAAAC,EAAW,OACX,gBAAAC,EAAkB,GAClB,UAAAC,EACA,UAAAC,EACA,QAAAC,CACF,EAAmB,CACjB,MAAMC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAAaC,EAAAA,oBACjBJ,EACA,CAAE,KAAAL,EAAM,SAAAC,CAAA,EACR,OACAK,CAAA,EAEI,CAAE,OAAAI,EAAQ,KAAAC,GAASC,EAAAA,mBAAmB,IAAI,EAC1CC,EAAUC,EAAAA,WAAA,EAEVC,EAAaC,EAAAA,YAAY,IAAM,CAC9BL,EAAKX,CAAI,CAChB,EAAG,CAACW,EAAMX,CAAI,CAAC,EAETiB,EAAQjB,EAAK,MAAM;AAAA,CAAI,EACvBkB,EAAS,OAAOD,EAAM,MAAM,EAAE,OAE9BE,EAAM,CAAC,mBAAoBf,GAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAE1E,cACG,MAAA,CAAI,IAAKE,EAAS,UAAWa,EAAM,GAAGX,EACrC,SAAA,CAAAY,EAAAA,KAAC,MAAA,CAAI,UAAU,2BACb,SAAA,CAAAC,EAAAA,IAAC,QAAK,UAAU,yBACb,aAAa,OAASR,EAAQ,kBAAoBZ,CAAA,CACrD,EACAmB,EAAAA,KAAC,SAAA,CACC,KAAK,SACL,UAAU,yBACV,QAASL,EACT,aAAYF,EAAQ,gBAEpB,SAAA,CAAAQ,MAACC,EAAAA,WAAU,OAAAZ,EAAgB,EAC1BA,EAASG,EAAQ,OAASA,EAAQ,IAAA,CAAA,CAAA,CACrC,EACF,EACAQ,EAAAA,IAAC,MAAA,CACC,UAAU,wBACV,MAAOlB,IAAc,OAAY,OAAY,CAAE,UAAAA,CAAA,EAE/C,SAAAkB,EAAAA,IAAC,OAAA,CACE,SAAAJ,EAAM,IAAI,CAACM,EAAMC,IAChBJ,EAAAA,KAAC,MAAA,CAAY,UAAU,yBACpB,SAAA,CAAAlB,GACCmB,EAAAA,IAAC,OAAA,CAAK,UAAU,uBACb,SAAA,OAAOG,EAAI,CAAC,EAAE,SAASN,EAAQ,GAAG,CAAA,CACrC,EAEFG,EAAAA,IAAC,OAAA,CAAK,UAAU,yBAA0B,YAAQ,GAAA,CAAI,CAAA,CAAA,EAN9CG,CAOV,CACD,CAAA,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 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,EAAa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OAAA,CACE,SAAAyB,EAAM,IAAI,CAACS,EAAMe,IAAM,CACtB,MAAMC,EAASD,EAAI,EACbE,EAAWP,EAAYM,CAAM,EAC7BE,EAAQ,OAAOF,CAAM,EAAE,SAASxB,EAAQ,GAAG,EACjD,OACEoB,EAAAA,KAAC,MAAA,CAEC,UACEK,EACI,0DACA,yBAGL,SAAA,CAAApC,IACED,EACCiC,EAAAA,IAAC,SAAA,CACC,KAAK,SACL,UAAU,oDACV,aAAY1B,EAAQ,SAAS6B,CAAM,EACnC,eAAcC,EACd,QAAUhB,GAAU,CAClBF,EAAgBiB,EAAQf,CAAK,CAC/B,EAEC,SAAAiB,CAAA,CAAA,EAGHL,EAAAA,IAAC,OAAA,CAAK,UAAU,uBAAwB,SAAAK,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"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { PrimitiveSurface } from '../../agent/core/usePrimitiveSurface';
|
|
2
|
+
import { PopoverAnchor } from './AnchoredPopover';
|
|
3
|
+
/** Lines `start` to `end`, 1-based and inclusive. */
|
|
4
|
+
export interface CodeLineRange {
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
}
|
|
2
8
|
export type CodeBlockSurface = PrimitiveSurface<{
|
|
3
9
|
code: string;
|
|
4
10
|
language: string;
|
|
@@ -12,6 +18,27 @@ interface CodeBlockProps {
|
|
|
12
18
|
maxHeight?: number | string;
|
|
13
19
|
className?: string;
|
|
14
20
|
surface?: CodeBlockSurface;
|
|
21
|
+
/**
|
|
22
|
+
* The selected lines, drawn in the brand's soft surface with a brand rule
|
|
23
|
+
* at their left. Leave it out to let the block keep its own selection.
|
|
24
|
+
*/
|
|
25
|
+
selectedLines?: CodeLineRange | null;
|
|
26
|
+
/**
|
|
27
|
+
* Makes the line numbers buttons that select lines: a press selects its
|
|
28
|
+
* line, Shift extends the range from the last line pressed, and pressing
|
|
29
|
+
* the only selected line clears it. Receives the range and an anchor over
|
|
30
|
+
* its lines, for an `AnchoredPopover`; turns line numbers on.
|
|
31
|
+
*/
|
|
32
|
+
onSelectLines?: (range: CodeLineRange | null, anchor: PopoverAnchor | null) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Receives an anchor over the selected lines as drawn, for an
|
|
35
|
+
* `AnchoredPopover`, whenever the drawn selection changes: on mount, on a
|
|
36
|
+
* press, and when a controlled `selectedLines` changes, such as one read
|
|
37
|
+
* from the page's address. Receives null while no line in the code is
|
|
38
|
+
* selected. The anchor measures the lines each time it is asked, so it
|
|
39
|
+
* follows them as the page scrolls or reflows.
|
|
40
|
+
*/
|
|
41
|
+
onSelectedLinesAnchor?: (anchor: PopoverAnchor | null) => void;
|
|
15
42
|
}
|
|
16
|
-
export declare function CodeBlock({ code, language, showLineNumbers, maxHeight, className, surface, }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare function CodeBlock({ code, language, showLineNumbers, maxHeight, className, surface, selectedLines, onSelectLines, onSelectedLinesAnchor, }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
|
|
17
44
|
export {};
|