@lincyaw/aegis-ui 0.17.0 → 0.18.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 +35 -0
- package/dist/components/ui/AnchoredPopover.js +118 -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 +19 -1
- package/dist/components/ui/CodeBlock.js +86 -36
- package/dist/components/ui/CodeBlock.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 +9 -1
- 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/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 S=require("react/jsx-runtime"),s=require("react"),B=require("react-dom");;/* empty css */const P='a[href], button:not(:disabled), input:not(:disabled):not([type="hidden"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';function D(i,r,f,g,c){const p=window.innerHeight-i.bottom,w=i.top,m=f==="auto"?p>=r.height+c||p>=w?"bottom":"top":f,l=m==="bottom"?i.bottom+c:i.top-c-r.height,b=g==="start"?i.left:i.right-r.width,u=window.innerWidth-r.width-c;return{top:l,left:Math.max(c,Math.min(b,u)),side:m}}function N({open:i,anchor:r,onClose:f,children:g,placement:c="auto",align:p="start",ariaLabel:w,className:m}){const l=s.useRef(null),b=s.useRef(null),[u,h]=s.useState(null),a=i&&r!==null,v=s.useCallback(()=>{const n=l.current;if(!n||!r)return;const t=parseFloat(getComputedStyle(n).getPropertyValue("--anchored-popover-gap"));h(D(r.getBoundingClientRect(),n.getBoundingClientRect(),c,p,Number.isNaN(t)?0:t))},[r,c,p]);s.useLayoutEffect(()=>{if(!a){h(null);return}v();let n=0;const t=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(v)};return window.addEventListener("scroll",t,!0),window.addEventListener("resize",t),()=>{cancelAnimationFrame(n),window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",t)}},[a,v]);const d=s.useRef({anchor:r,onClose:f});d.current={anchor:r,onClose:f};const y=s.useCallback(()=>{d.current.onClose(),b.current?.focus()},[]);s.useEffect(()=>{if(!a)return;const n=document.activeElement;b.current=n instanceof HTMLElement?n:null;const t=l.current,A=e=>{const{target:o}=e;!(o instanceof Node)||t?.contains(o)||d.current.anchor?.contains?.(o)||d.current.onClose()},R=e=>{if(!t||e.key!=="Tab")return;const o=Array.from(t.querySelectorAll(P)).filter(q=>q.getClientRects().length>0);(e.shiftKey?e.target===t||e.target===o[0]:o.length===0||e.target===o[o.length-1])&&(e.preventDefault(),y())},C=e=>{const{target:o}=e;e.key!=="Escape"||e.isComposing||o instanceof Node&&(t?.contains(o)?(e.preventDefault(),e.stopPropagation(),y()):d.current.anchor?.contains?.(o)&&(e.preventDefault(),e.stopPropagation(),d.current.onClose()))};return document.addEventListener("pointerdown",A,!0),document.addEventListener("keydown",C),t?.addEventListener("keydown",R),()=>{document.removeEventListener("pointerdown",A,!0),document.removeEventListener("keydown",C),t?.removeEventListener("keydown",R)}},[a,y]);const L=u!==null,E=s.useRef(!1);if(s.useEffect(()=>{if(!a){E.current=!1;return}if(!L||E.current)return;E.current=!0;const n=l.current;(n?.querySelector(P)??n)?.focus({preventScroll:!0})},[a,L]),!a)return null;const k=["aegis-anchored-popover",u?`aegis-anchored-popover--${u.side}`:"",m??""].filter(Boolean).join(" "),x=u?{top:u.top,left:u.left}:{visibility:"hidden"};return B.createPortal(S.jsx("div",{ref:l,className:k,style:x,role:"dialog","aria-label":w,tabIndex:-1,children:g}),document.body)}exports.AnchoredPopover=N;
|
|
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 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 * 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 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 setPosition(\n place(\n anchor.getBoundingClientRect(),\n panel.getBoundingClientRect(),\n placement,\n align,\n Number.isNaN(gap) ? 0 : gap,\n ),\n );\n }, [anchor, placement, align]);\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 pressed.\n const onEscape = (event: KeyboardEvent): void => {\n const { target } = event;\n if (event.key !== 'Escape' || event.isComposing) {\n return;\n }\n if (!(target instanceof Node)) {\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 (!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]);\n\n if (!shown) {\n return null;\n }\n const cls = [\n 'aegis-anchored-popover',\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 document.body,\n );\n}\n"],"names":["TABBABLE","place","anchor","panel","placement","align","gap","below","above","side","top","preferred","maxLeft","AnchoredPopover","open","onClose","children","ariaLabel","className","panelRef","useRef","returnFocus","position","setPosition","useState","shown","update","useCallback","useLayoutEffect","frame","schedule","latest","closeAndReturn","useEffect","active","onPointerDown","event","target","onKeyDown","tabbable","element","onEscape","placed","focused","cls","style","createPortal","jsx"],"mappings":"oMA0CA,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,EAAG,KAAAH,CAAA,CACnE,CASO,SAASI,EAAgB,CAC9B,KAAAC,EACA,OAAAZ,EACA,QAAAa,EACA,SAAAC,EACA,UAAAZ,EAAY,OACZ,MAAAC,EAAQ,QACR,UAAAY,EACA,UAAAC,CACF,EAAyB,CACvB,MAAMC,EAAWC,EAAAA,OAAuB,IAAI,EACtCC,EAAcD,EAAAA,OAA2B,IAAI,EAC7C,CAACE,EAAUC,CAAW,EAAIC,EAAAA,SAA0B,IAAI,EACxDC,EAAQX,GAAQZ,IAAW,KAE3BwB,EAASC,EAAAA,YAAY,IAAM,CAC/B,MAAMxB,EAAQgB,EAAS,QACvB,GAAI,CAAChB,GAAS,CAACD,EACb,OAEF,MAAMI,EAAM,WACV,iBAAiBH,CAAK,EAAE,iBA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AEd,CAACjB,EACH,OAAO,KAET,MAAMmB,EAAM,CACV,yBACAtB,EAAW,2BAA2BA,EAAS,IAAI,GAAK,GACxDJ,GAAa,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,EACL2B,EAAuBvB,EACzB,CAAE,IAAKA,EAAS,IAAK,KAAMA,EAAS,IAAA,EACpC,CAAE,WAAY,QAAA,EAClB,OAAOwB,EAAAA,aACLC,EAAAA,IAAC,MAAA,CACC,IAAK5B,EACL,UAAWyB,EACX,MAAAC,EACA,KAAK,SACL,aAAY5B,EACZ,SAAU,GAET,SAAAD,CAAA,CAAA,EAEH,SAAS,IAAA,CAEb"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Arbitrary content in an overlay beside an anchor, e.g. what is known
|
|
30
|
+
* about a selected code range. It follows the anchor as the page scrolls
|
|
31
|
+
* and closes on Escape, a press outside it, or Tab past its last control.
|
|
32
|
+
* Opening moves focus to its first control; Escape and Tab hand focus back
|
|
33
|
+
* to where it was.
|
|
34
|
+
*/
|
|
35
|
+
export declare function AnchoredPopover({ open, anchor, onClose, children, placement, align, ariaLabel, className, }: AnchoredPopoverProps): import('react').ReactPortal | null;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as g, useState as S, useCallback as k, useLayoutEffect as q, useEffect as P } from "react";
|
|
3
|
+
import { createPortal as M } from "react-dom";
|
|
4
|
+
/* empty css */
|
|
5
|
+
const B = 'a[href], button:not(:disabled), input:not(:disabled):not([type="hidden"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
6
|
+
function T(i, r, d, w, s) {
|
|
7
|
+
const f = window.innerHeight - i.bottom, b = i.top, p = d === "auto" ? f >= r.height + s || f >= b ? "bottom" : "top" : d, a = p === "bottom" ? i.bottom + s : i.top - s - r.height, m = w === "start" ? i.left : i.right - r.width, c = window.innerWidth - r.width - s;
|
|
8
|
+
return { top: a, left: Math.max(s, Math.min(m, c)), side: p };
|
|
9
|
+
}
|
|
10
|
+
function V({
|
|
11
|
+
open: i,
|
|
12
|
+
anchor: r,
|
|
13
|
+
onClose: d,
|
|
14
|
+
children: w,
|
|
15
|
+
placement: s = "auto",
|
|
16
|
+
align: f = "start",
|
|
17
|
+
ariaLabel: b,
|
|
18
|
+
className: p
|
|
19
|
+
}) {
|
|
20
|
+
const a = g(null), m = g(null), [c, h] = S(null), u = i && r !== null, v = k(() => {
|
|
21
|
+
const n = a.current;
|
|
22
|
+
if (!n || !r)
|
|
23
|
+
return;
|
|
24
|
+
const e = parseFloat(
|
|
25
|
+
getComputedStyle(n).getPropertyValue("--anchored-popover-gap")
|
|
26
|
+
);
|
|
27
|
+
h(
|
|
28
|
+
T(
|
|
29
|
+
r.getBoundingClientRect(),
|
|
30
|
+
n.getBoundingClientRect(),
|
|
31
|
+
s,
|
|
32
|
+
f,
|
|
33
|
+
Number.isNaN(e) ? 0 : e
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
}, [r, s, f]);
|
|
37
|
+
q(() => {
|
|
38
|
+
if (!u) {
|
|
39
|
+
h(null);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
v();
|
|
43
|
+
let n = 0;
|
|
44
|
+
const e = () => {
|
|
45
|
+
cancelAnimationFrame(n), n = requestAnimationFrame(v);
|
|
46
|
+
};
|
|
47
|
+
return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
|
|
48
|
+
cancelAnimationFrame(n), window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
|
|
49
|
+
};
|
|
50
|
+
}, [u, v]);
|
|
51
|
+
const l = g({ anchor: r, onClose: d });
|
|
52
|
+
l.current = { anchor: r, onClose: d };
|
|
53
|
+
const E = k(() => {
|
|
54
|
+
l.current.onClose(), m.current?.focus();
|
|
55
|
+
}, []);
|
|
56
|
+
P(() => {
|
|
57
|
+
if (!u)
|
|
58
|
+
return;
|
|
59
|
+
const n = document.activeElement;
|
|
60
|
+
m.current = n instanceof HTMLElement ? n : null;
|
|
61
|
+
const e = a.current, A = (t) => {
|
|
62
|
+
const { target: o } = t;
|
|
63
|
+
!(o instanceof Node) || e?.contains(o) || l.current.anchor?.contains?.(o) || l.current.onClose();
|
|
64
|
+
}, x = (t) => {
|
|
65
|
+
if (!e || t.key !== "Tab")
|
|
66
|
+
return;
|
|
67
|
+
const o = Array.from(
|
|
68
|
+
e.querySelectorAll(B)
|
|
69
|
+
).filter((D) => D.getClientRects().length > 0);
|
|
70
|
+
(t.shiftKey ? t.target === e || t.target === o[0] : o.length === 0 || t.target === o[o.length - 1]) && (t.preventDefault(), E());
|
|
71
|
+
}, C = (t) => {
|
|
72
|
+
const { target: o } = t;
|
|
73
|
+
t.key !== "Escape" || t.isComposing || o instanceof Node && (e?.contains(o) ? (t.preventDefault(), t.stopPropagation(), E()) : l.current.anchor?.contains?.(o) && (t.preventDefault(), t.stopPropagation(), l.current.onClose()));
|
|
74
|
+
};
|
|
75
|
+
return document.addEventListener("pointerdown", A, !0), document.addEventListener("keydown", C), e?.addEventListener("keydown", x), () => {
|
|
76
|
+
document.removeEventListener("pointerdown", A, !0), document.removeEventListener("keydown", C), e?.removeEventListener("keydown", x);
|
|
77
|
+
};
|
|
78
|
+
}, [u, E]);
|
|
79
|
+
const L = c !== null, y = g(!1);
|
|
80
|
+
if (P(() => {
|
|
81
|
+
if (!u) {
|
|
82
|
+
y.current = !1;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!L || y.current)
|
|
86
|
+
return;
|
|
87
|
+
y.current = !0;
|
|
88
|
+
const n = a.current;
|
|
89
|
+
(n?.querySelector(B) ?? n)?.focus({
|
|
90
|
+
preventScroll: !0
|
|
91
|
+
});
|
|
92
|
+
}, [u, L]), !u)
|
|
93
|
+
return null;
|
|
94
|
+
const N = [
|
|
95
|
+
"aegis-anchored-popover",
|
|
96
|
+
c ? `aegis-anchored-popover--${c.side}` : "",
|
|
97
|
+
p ?? ""
|
|
98
|
+
].filter(Boolean).join(" "), R = c ? { top: c.top, left: c.left } : { visibility: "hidden" };
|
|
99
|
+
return M(
|
|
100
|
+
/* @__PURE__ */ F(
|
|
101
|
+
"div",
|
|
102
|
+
{
|
|
103
|
+
ref: a,
|
|
104
|
+
className: N,
|
|
105
|
+
style: R,
|
|
106
|
+
role: "dialog",
|
|
107
|
+
"aria-label": b,
|
|
108
|
+
tabIndex: -1,
|
|
109
|
+
children: w
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
document.body
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
V as AnchoredPopover
|
|
117
|
+
};
|
|
118
|
+
//# 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 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 * 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 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 setPosition(\n place(\n anchor.getBoundingClientRect(),\n panel.getBoundingClientRect(),\n placement,\n align,\n Number.isNaN(gap) ? 0 : gap,\n ),\n );\n }, [anchor, placement, align]);\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 pressed.\n const onEscape = (event: KeyboardEvent): void => {\n const { target } = event;\n if (event.key !== 'Escape' || event.isComposing) {\n return;\n }\n if (!(target instanceof Node)) {\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 (!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]);\n\n if (!shown) {\n return null;\n }\n const cls = [\n 'aegis-anchored-popover',\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 document.body,\n );\n}\n"],"names":["TABBABLE","place","anchor","panel","placement","align","gap","below","above","side","top","preferred","maxLeft","AnchoredPopover","open","onClose","children","ariaLabel","className","panelRef","useRef","returnFocus","position","setPosition","useState","shown","update","useCallback","useLayoutEffect","frame","schedule","latest","closeAndReturn","useEffect","active","onPointerDown","event","target","onKeyDown","tabbable","element","onEscape","placed","focused","cls","style","createPortal","jsx"],"mappings":";;;;AA0CA,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;AASO,SAASI,EAAgB;AAAA,EAC9B,MAAAC;AAAA,EACA,QAAAZ;AAAA,EACA,SAAAa;AAAA,EACA,UAAAC;AAAA,EACA,WAAAZ,IAAY;AAAA,EACZ,OAAAC,IAAQ;AAAA,EACR,WAAAY;AAAA,EACA,WAAAC;AACF,GAAyB;AACvB,QAAMC,IAAWC,EAAuB,IAAI,GACtCC,IAAcD,EAA2B,IAAI,GAC7C,CAACE,GAAUC,CAAW,IAAIC,EAA0B,IAAI,GACxDC,IAAQX,KAAQZ,MAAW,MAE3BwB,IAASC,EAAY,MAAM;AAC/B,UAAMxB,IAAQgB,EAAS;AACv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AU,MAAM;AACd,QAAI,CAACR,GAAO;AACV,MAAAkB,EAAQ,UAAU;AAClB;AAAA,IACF;AACA,QAAI,CAACD,KAAUC,EAAQ;AACrB;AAEF,IAAAA,EAAQ,UAAU;AAClB,UAAMxC,IAAQgB,EAAS;AACvB,KAAChB,GAAO,cAA2BH,CAAQ,KAAKG,IAAQ,MAAM;AAAA,MAC5D,eAAe;AAAA,IAAA,CAChB;AAAA,EACH,GAAG,CAACsB,GAAOiB,CAAM,CAAC,GAEd,CAACjB;AACH,WAAO;AAET,QAAMmB,IAAM;AAAA,IACV;AAAA,IACAtB,IAAW,2BAA2BA,EAAS,IAAI,KAAK;AAAA,IACxDJ,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,GACL2B,IAAuBvB,IACzB,EAAE,KAAKA,EAAS,KAAK,MAAMA,EAAS,KAAA,IACpC,EAAE,YAAY,SAAA;AAClB,SAAOwB;AAAA,IACL,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK5B;AAAA,QACL,WAAWyB;AAAA,QACX,OAAAC;AAAA,QACA,MAAK;AAAA,QACL,cAAY5B;AAAA,QACZ,UAAU;AAAA,QAET,UAAAD;AAAA,MAAA;AAAA,IAAA;AAAA,IAEH,SAAS;AAAA,EAAA;AAEb;"}
|
|
@@ -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,EAC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AC,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,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exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),c=require("react"),A=require("../../agent/core/usePrimitiveSurface.cjs"),D=require("../../hooks/useCopyToClipboard.cjs");;/* empty css */const G=require("./CopyGlyph.cjs"),F=require("../../locale/useStrings.cjs");function K({code:i,language:d="text",showLineNumbers:x=!1,maxHeight:b,className:j,surface:v,selectedLines:g,onSelectLines:u}){const _=c.useRef(null),p=c.useRef(null),f=c.useRef(null),[S,R]=c.useState(null),l=g===void 0?S:g,h=u!==void 0,N=x||h,q=A.usePrimitiveSurface(v,{code:i,language:d},"code",_),{copied:y,copy:k}=D.useCopyToClipboard(1500),a=F.useStrings(),w=c.useCallback(()=>{k(i)},[k,i]),m=i.split(`
|
|
2
|
+
`),B=String(m.length).length,C=c.useCallback(s=>({getBoundingClientRect:()=>{const n=p.current?.querySelectorAll(".aegis-code-block__line"),e=n?.[s.start-1]?.getBoundingClientRect(),r=n?.[s.end-1]?.getBoundingClientRect();return!e||!r?new DOMRect:new DOMRect(e.left,e.top,e.width,r.bottom-e.top)},contains:n=>p.current?.contains(n)??!1}),[]),M=c.useCallback((s,n)=>{const e=n.shiftKey?f.current:null,o=l?.start===s&&l.end===s&&e===null?null:e===null?{start:s,end:s}:{start:Math.min(e,s),end:Math.max(e,s)};e===null&&(f.current=o?s:null),R(o),u?.(o,o?C(o):null)},[l,u,C]),T=c.useMemo(()=>l?s=>s>=l.start&&s<=l.end:()=>!1,[l]),O=["aegis-code-block",j??""].filter(Boolean).join(" ");return t.jsxs("div",{ref:_,className:O,...q,children:[t.jsxs("div",{className:"aegis-code-block__header",children:[t.jsx("span",{className:"aegis-code-block__lang",children:d==="text"?a.plainTextLanguage:d}),t.jsxs("button",{type:"button",className:"aegis-code-block__copy",onClick:w,"aria-label":a.copyToClipboard,children:[t.jsx(G.CopyGlyph,{copied:y}),y?a.copied:a.copy]})]}),t.jsx("pre",{ref:p,className:"aegis-code-block__pre",style:b===void 0?void 0:{maxHeight:b},children:t.jsx("code",{children:m.map((s,n)=>{const e=n+1,r=T(e),o=String(e).padStart(B," ");return t.jsxs("div",{className:r?"aegis-code-block__line aegis-code-block__line--selected":"aegis-code-block__line",children:[N&&(h?t.jsx("button",{type:"button",className:"aegis-code-block__ln aegis-code-block__ln--button","aria-label":a.codeLine(e),"aria-pressed":r,onClick:P=>{M(e,P)},children:o}):t.jsx("span",{className:"aegis-code-block__ln",children:o})),t.jsx("span",{className:"aegis-code-block__body",children:s||" "})]},n)})})})]})}exports.CodeBlock=K;
|
|
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
|
|
1
|
+
{"version":3,"file":"CodeBlock.cjs","sources":["../../../src/components/ui/CodeBlock.tsx"],"sourcesContent":["import { type MouseEvent, useCallback, useMemo, useRef, useState } 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\nexport function CodeBlock({\n code,\n language = 'text',\n showLineNumbers = false,\n maxHeight,\n className,\n surface,\n selectedLines,\n onSelectLines,\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 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","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","selectedSet","useMemo","cls","jsxs","jsx","CopyGlyph","i","number","selected","label"],"mappings":"yVAiDO,SAASA,EAAU,CACxB,KAAAC,EACA,SAAAC,EAAW,OACX,gBAAAC,EAAkB,GAClB,UAAAC,EACA,UAAAC,EACA,QAAAC,EACA,cAAAC,EACA,cAAAC,CACF,EAAmB,CACjB,MAAMC,EAAUC,EAAAA,O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KAAK,SACL,UAAU,oDACV,aAAYrB,EAAQ,SAASwB,CAAM,EACnC,eAAcC,EACd,QAAUX,GAAU,CAClBF,EAAgBY,EAAQV,CAAK,CAC/B,EAEC,SAAAY,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,18 @@ 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;
|
|
15
33
|
}
|
|
16
|
-
export declare function CodeBlock({ code, language, showLineNumbers, maxHeight, className, surface, }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export declare function CodeBlock({ code, language, showLineNumbers, maxHeight, className, surface, selectedLines, onSelectLines, }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
|
|
17
35
|
export {};
|