@lincyaw/aegis-ui 0.16.0 → 0.17.1
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/DetailBeside.cjs +1 -1
- package/dist/components/ui/DetailBeside.cjs.map +1 -1
- package/dist/components/ui/DetailBeside.d.ts +9 -7
- package/dist/components/ui/DetailBeside.js +54 -50
- package/dist/components/ui/DetailBeside.js.map +1 -1
- package/dist/components/ui/TreeTable.cjs +2 -0
- package/dist/components/ui/TreeTable.cjs.map +1 -0
- package/dist/components/ui/TreeTable.d.ts +70 -0
- package/dist/components/ui/TreeTable.js +263 -0
- package/dist/components/ui/TreeTable.js.map +1 -0
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +82 -80
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),e=require("react"),L=require("../../hooks/useIsomorphicLayoutEffect.cjs"),Q=require("../../hooks/useMediaQuery.cjs"),M=require("../../lib/scrollView.cjs");;/* empty css */const N=require("./selectedRowDetail.cjs"),A="(max-width: 768px)",O=e.createContext(null);function $(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),e=require("react"),L=require("../../hooks/useIsomorphicLayoutEffect.cjs"),Q=require("../../hooks/useMediaQuery.cjs"),M=require("../../lib/scrollView.cjs");;/* empty css */const N=require("./selectedRowDetail.cjs"),A="(max-width: 768px)",O=e.createContext(null);function $(u,l,f,g,o){const p=o.top+g,a=u.top<p?u.top-p:Math.max(u.bottom-o.bottom,0);return Math.max(a,l+f-o.bottom)}function z({boxRef:u}){const l=e.useContext(O);return c.jsx("div",{ref:u,className:"aegis-detail-beside__inline",role:"group",children:l})}function F({columns:u,detail:l,children:f,revealKey:g,scrollContainer:o=null,className:p}){const a=Q.useMediaQuery(A),[P,x]=e.useState(!1),C=e.useRef(null),y=e.useRef(null),v=e.useRef(null),d=e.useRef(null),R=e.useRef(!1),E=e.useRef(0),w=e.useRef(g),j=e.useRef(void 0),B=e.useRef({children:f,detail:l}),i=e.useCallback(()=>{const t=d.current,s=v.current,r=y.current;if(t===null){r?.style.removeProperty("height");return}if(s===null)return;const n=t.getBoundingClientRect();if(r===null)s.style.setProperty("--aegis-detail-beside-row-height",`${String(n.height)}px`);else{const m=r.getBoundingClientRect().top;r.style.height=`${String(Math.max(n.top-m,0))}px`}},[]),h=e.useCallback(()=>{i();const t=d.current,s=v.current;if(t===null||s===null)return;const r=t.getBoundingClientRect(),n=y.current,m=$(r,n===null?r.bottom:n.getBoundingClientRect().top,s.getBoundingClientRect().height,parseFloat(getComputedStyle(s).scrollMarginTop),M.viewBoundsOf(o)),D=M.scrollerOf(o);Math.abs(m)>=1&&D.scrollBy({top:m,behavior:"instant"}),E.current=D.scrollTop},[i,o]),b=e.useCallback(()=>{j.current=w.current,R.current=!0,x(!0),queueMicrotask(()=>{h(),x(!1)})},[h]),S=e.useCallback(t=>{const s=t!==d.current;d.current=t,t===null?(R.current=!1,x(!1),i()):j.current!==w.current?b():(s&&(R.current=!1),i())},[i,b]),_=e.useCallback(()=>{x(!0)},[]);L.useIsomorphicLayoutEffect(()=>{const t=B.current.children!==f||B.current.detail!==l;B.current={children:f,detail:l},w.current=g,j.current!==g&&d.current!==null?b():(t&&(R.current=!1),i())}),L.useIsomorphicLayoutEffect(()=>{const t=C.current;if(t===null)return;const s=new ResizeObserver(()=>{R.current?h():i()});for(const n of a?[t]:[t,v.current])n!==null&&s.observe(n);const r=n=>{n.target instanceof Node&&d.current?.contains(n.target)&&b()};return t.addEventListener("click",r),()=>{s.disconnect(),t.removeEventListener("click",r)}},[a,i,h,b]),e.useEffect(()=>{const t=M.scrollerOf(o),s=o??window,r=()=>{Math.abs(t.scrollTop-E.current)>=1&&(R.current=!1)};return s.addEventListener("scroll",r,{passive:!0}),()=>{s.removeEventListener("scroll",r)}},[o]);const k=e.useMemo(()=>a?c.jsx(z,{boxRef:v}):null,[a]),I=e.useMemo(()=>({placeRow:S,awaitRow:_,inline:k}),[S,_,k]),q=c.jsx(N.SelectedRowDetailContext.Provider,{value:null,children:l}),T=["aegis-detail-beside",p??""].filter(Boolean).join(" ");return c.jsx(N.SelectedRowDetailContext.Provider,{value:I,children:c.jsx(O.Provider,{value:q,children:c.jsxs("div",{className:T,style:{"--aegis-detail-beside-columns":u},"aria-busy":P||void 0,children:[c.jsx("div",{ref:C,className:"aegis-detail-beside__list",children:f}),!a&&c.jsxs("div",{className:"aegis-detail-beside__side",children:[c.jsx("div",{ref:y}),c.jsx("div",{ref:v,className:"aegis-detail-beside__detail",children:q})]})]})})})}exports.DetailBeside=F;
|
|
2
2
|
//# sourceMappingURL=DetailBeside.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetailBeside.cjs","sources":["../../../src/components/ui/DetailBeside.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n type RefObject,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport {\n type ViewBounds,\n scrollerOf,\n viewBoundsOf,\n} from '../../lib/scrollView';\nimport './DetailBeside.css';\nimport {\n type SelectedRowDetail,\n SelectedRowDetailContext,\n} from './selectedRowDetail';\n\nexport interface DetailBesideProps {\n /**\n * `grid-template-columns` of the list and the detail above 768 px, e.g.\n * `'3fr 2fr'`.\n */\n columns: string;\n /**\n * The selected item's detail: one element, such as a `Panel` titled with\n * the item's name. It is never taller than the view, so a long Panel\n * scrolls its body. Render it anew from the host's data whenever that\n * data changes: that render tells DetailBeside the change was new data,\n * so the page stays where it is. A detail that fetches its own data and\n * redraws without this host rendering leaves the page following the row,\n * and its next change of size scrolls the page.\n */\n detail: ReactNode;\n /**\n * The list: a `TraceTree`, `FileTree`, `DataTable` or `ServiceMap`, in a\n * Panel say. The detail follows the row it draws selected. Like\n * `detail`, render it anew from the host's data whenever that data\n * changes, so the page stays where it is on new data; a list that fetches\n * its own data and redraws without this host rendering leaves the page\n * following the row, and its next change of size scrolls the page.\n */\n children: ReactNode;\n /**\n * The selection as the page's address names it, or null where the\n * address names none and the list shows a default. It changes only by\n * the viewer's doing: a click, a key, a link, back or forward. The page\n * scrolls to the selected row when this changes, and on the first\n * placement after mount; a row that comes into place for new data, such\n * as a default the data moved, is only levelled with.\n */\n revealKey: string | null;\n /** The element that scrolls the page; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\nconst NARROW_QUERY = '(max-width: 768px)';\n\n/**\n * The detail as the inline slot draws it. It is kept out of the context the\n * lists read, so a new detail re-renders the slot and not the list.\n */\nconst DetailContext = createContext<ReactNode>(null);\n\n/**\n * How far to scroll so the row is in the view, clear of the `inset` at the\n * view's top, and the detail, whose top can rise no higher than `ceiling`,\n * fits above the view's bottom.\n */\nfunction revealDistance(\n row: DOMRect,\n ceiling: number,\n height: number,\n inset: number,\n view: ViewBounds,\n): number {\n const top = view.top + inset;\n const toRow =\n row.top < top ? row.top - top : Math.max(row.bottom - view.bottom, 0);\n return Math.max(toRow, ceiling + height - view.bottom);\n}\n\n/** The detail right after the selected row, at 768 px and below. */\nfunction InlineDetail({ boxRef }: { boxRef: RefObject<HTMLDivElement> }) {\n const detail = useContext(DetailContext);\n return (\n <div ref={boxRef} className=\"aegis-detail-beside__inline\" role=\"group\">\n {detail}\n </div>\n );\n}\n\n/**\n * A tree, table or map with the selected item's detail beside it. Above\n * 768 px the detail stands in a column on the right, level with the\n * selected row: when the row is too low for it, its bottom meets the\n * view's bottom, and while the page scrolls it stays in the view below\n * the header. At 768 px and below the list draws the detail right after\n * the selected row, the rows that follow under it; a map draws it over\n * the map, under the node. When the page opens with a selection,\n * `revealKey` changes or the viewer clicks the selected row, the page\n * scrolls at once, as little as it takes to show the row and the detail\n * whole, and again whenever the list or the detail changes size, until the\n * viewer scrolls or the host renders a new list or detail. Any other\n * placement, such as new data moving the selection or the rows, levels\n * the detail with its row by the same rule and leaves the page where it\n * is; the browser's scroll anchoring can still move it when rows arrive\n * above the view, unless the host sets `overflow-anchor: none` on its\n * scroller. The wrapper is `aria-busy` while a selected row it reveals is\n * still on its way.\n */\nexport function DetailBeside({\n columns,\n detail,\n children,\n revealKey,\n scrollContainer = null,\n className,\n}: DetailBesideProps) {\n const narrow = useMediaQuery(NARROW_QUERY);\n const [busy, setBusy] = useState(false);\n const listRef = useRef<HTMLDivElement>(null);\n const spacerRef = useRef<HTMLDivElement>(null);\n const detailRef = useRef<HTMLDivElement>(null);\n const rowRef = useRef<HTMLElement | null>(null);\n /** Whether the page is still where the last reveal left it. */\n const followRef = useRef(false);\n const revealedAtRef = useRef(0);\n /** The latest render's revealKey, and the last reveal's: undefined before the first. */\n const revealKeyRef = useRef(revealKey);\n const revealedKeyRef = useRef<string | null | undefined>(undefined);\n /** The latest render's list and detail, which change when the host renders them anew. */\n const shownRef = useRef({ children, detail });\n\n /**\n * Sets the detail level with the row: above 768 px through the spacer's\n * height, at and below by telling the inline detail how tall the row is.\n */\n const place = useCallback(() => {\n const row = rowRef.current;\n const box = detailRef.current;\n if (row === null || box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n const spacer = spacerRef.current;\n if (spacer === null) {\n box.style.setProperty(\n '--aegis-detail-beside-row-height',\n `${String(rowBox.height)}px`,\n );\n } else {\n const top = spacer.getBoundingClientRect().top;\n spacer.style.height = `${String(Math.max(rowBox.top - top, 0))}px`;\n }\n }, []);\n\n /** Places the row and scrolls as little as it takes to show it and its detail whole. */\n const reveal = useCallback(() => {\n place();\n const row = rowRef.current;\n const box = detailRef.current;\n if (row === null || box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n const spacer = spacerRef.current;\n const distance = revealDistance(\n rowBox,\n spacer === null ? rowBox.bottom : spacer.getBoundingClientRect().top,\n box.getBoundingClientRect().height,\n parseFloat(getComputedStyle(box).scrollMarginTop),\n viewBoundsOf(scrollContainer),\n );\n const scroller = scrollerOf(scrollContainer);\n if (Math.abs(distance) >= 1) {\n scroller.scrollBy({ top: distance, behavior: 'instant' });\n }\n revealedAtRef.current = scroller.scrollTop;\n }, [place, scrollContainer]);\n\n // A list places its row while React attaches refs, before the detail's\n // own ref is in and before the re-renders its layout effects ask for,\n // so the reveal waits for the commit to finish.\n const revealSoon = useCallback(() => {\n revealedKeyRef.current = revealKeyRef.current;\n followRef.current = true;\n setBusy(true);\n queueMicrotask(() => {\n reveal();\n setBusy(false);\n });\n }, [reveal]);\n\n // A row placed while a reveal is due is revealed; any other is levelled\n // with, and a new one ends following.\n const placeRow = useCallback(\n (row: HTMLElement | null) => {\n const fresh = row !== rowRef.current;\n rowRef.current = row;\n if (row === null) {\n followRef.current = false;\n setBusy(false);\n } else if (revealedKeyRef.current !== revealKeyRef.current) {\n revealSoon();\n } else {\n if (fresh) {\n followRef.current = false;\n }\n place();\n }\n },\n [place, revealSoon],\n );\n\n const awaitRow = useCallback(() => {\n setBusy(true);\n }, []);\n\n // Runs after the lists have placed their rows in this commit, so a new\n // revealKey reveals the row it selects. A render by the host without one\n // ends following.\n useIsomorphicLayoutEffect(() => {\n const rendered =\n shownRef.current.children !== children ||\n shownRef.current.detail !== detail;\n shownRef.current = { children, detail };\n revealKeyRef.current = revealKey;\n if (revealedKeyRef.current !== revealKey && rowRef.current !== null) {\n revealSoon();\n } else {\n if (rendered) {\n followRef.current = false;\n }\n place();\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const list = listRef.current;\n if (list === null) {\n return undefined;\n }\n const observer = new ResizeObserver(() => {\n if (followRef.current) {\n reveal();\n } else {\n place();\n }\n });\n // At 768 px and below the detail lies inside the list.\n for (const box of narrow ? [list] : [list, detailRef.current]) {\n if (box !== null) {\n observer.observe(box);\n }\n }\n const activate = (event: MouseEvent): void => {\n if (\n event.target instanceof Node &&\n rowRef.current?.contains(event.target)\n ) {\n revealSoon();\n }\n };\n list.addEventListener('click', activate);\n return () => {\n observer.disconnect();\n list.removeEventListener('click', activate);\n };\n }, [narrow, place, reveal, revealSoon]);\n\n useEffect(() => {\n const scroller = scrollerOf(scrollContainer);\n const target = scrollContainer ?? window;\n const scrolled = (): void => {\n if (Math.abs(scroller.scrollTop - revealedAtRef.current) >= 1) {\n followRef.current = false;\n }\n };\n target.addEventListener('scroll', scrolled, { passive: true });\n return () => {\n target.removeEventListener('scroll', scrolled);\n };\n }, [scrollContainer]);\n\n const inline = useMemo(\n () => (narrow ? <InlineDetail boxRef={detailRef} /> : null),\n [narrow],\n );\n const slot = useMemo(\n (): SelectedRowDetail => ({ placeRow, awaitRow, inline }),\n [placeRow, awaitRow, inline],\n );\n const isolated = (\n <SelectedRowDetailContext.Provider value={null}>\n {detail}\n </SelectedRowDetailContext.Provider>\n );\n\n const cls = ['aegis-detail-beside', className ?? '']\n .filter(Boolean)\n .join(' ');\n\n return (\n <SelectedRowDetailContext.Provider value={slot}>\n <DetailContext.Provider value={isolated}>\n <div\n className={cls}\n style={{ '--aegis-detail-beside-columns': columns } as CSSProperties}\n aria-busy={busy || undefined}\n >\n <div ref={listRef} className=\"aegis-detail-beside__list\">\n {children}\n </div>\n {!narrow && (\n <div className=\"aegis-detail-beside__side\">\n <div ref={spacerRef} />\n <div ref={detailRef} className=\"aegis-detail-beside__detail\">\n {isolated}\n </div>\n </div>\n )}\n </div>\n </DetailContext.Provider>\n </SelectedRowDetailContext.Provider>\n );\n}\n"],"names":["NARROW_QUERY","DetailContext","createContext","revealDistance","row","ceiling","height","inset","view","top","toRow","InlineDetail","boxRef","detail","useContext","jsx","DetailBeside","columns","children","revealKey","scrollContainer","className","narrow","useMediaQuery","busy","setBusy","useState","listRef","useRef","spacerRef","detailRef","rowRef","followRef","revealedAtRef","revealKeyRef","revealedKeyRef","shownRef","place","useCallback","box","rowBox","spacer","reveal","distance","viewBoundsOf","scroller","scrollerOf","revealSoon","placeRow","fresh","awaitRow","useIsomorphicLayoutEffect","rendered","list","observer","activate","event","useEffect","target","scrolled","inline","useMemo","slot","isolated","SelectedRowDetailContext","cls","jsxs"],"mappings":"6VAiEMA,EAAe,qBAMfC,EAAgBC,EAAAA,cAAyB,IAAI,EAOnD,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACQ,CACR,MAAMC,EAAMD,EAAK,IAAMD,EACjBG,EACJN,EAAI,IAAMK,EAAML,EAAI,IAAMK,EAAM,KAAK,IAAIL,EAAI,OAASI,EAAK,OAAQ,CAAC,EACtE,OAAO,KAAK,IAAIE,EAAOL,EAAUC,EAASE,EAAK,MAAM,CACvD,CAGA,SAASG,EAAa,CAAE,OAAAC,GAAiD,CACvE,MAAMC,EAASC,EAAAA,WAAWb,CAAa,EACvC,OACEc,MAAC,OAAI,IAAKH,EAAQ,UAAU,8BAA8B,KAAK,QAC5D,SAAAC,CAAA,CACH,CAEJ,CAqBO,SAASG,EAAa,CAC3B,QAAAC,EACA,OAAAJ,EACA,SAAAK,EACA,UAAAC,EACA,gBAAAC,EAAkB,KAClB,UAAAC,CACF,EAAsB,CACpB,MAAMC,EAASC,EAAAA,cAAcvB,CAAY,EACnC,CAACwB,EAAMC,CAAO,EAAIC,EAAAA,SAAS,EAAK,EAChCC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAAYD,EAAAA,OAAuB,IAAI,EACvCE,EAAYF,EAAAA,OAAuB,IAAI,EACvCG,EAASH,EAAAA,OAA2B,IAAI,EAExCI,EAAYJ,EAAAA,OAAO,EAAK,EACxBK,EAAgBL,EAAAA,OAAO,CAAC,EAExBM,EAAeN,EAAAA,OAAOT,CAAS,EAC/BgB,EAAiBP,EAAAA,OAAkC,MAAS,EAE5DQ,EAAWR,EAAAA,OAAO,CAAE,SAAAV,EAAU,OAAAL,EAAQ,EAMtCwB,E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DetailBeside.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n type RefObject,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport {\n type ViewBounds,\n scrollerOf,\n viewBoundsOf,\n} from '../../lib/scrollView';\nimport './DetailBeside.css';\nimport {\n type SelectedRowDetail,\n SelectedRowDetailContext,\n} from './selectedRowDetail';\n\nexport interface DetailBesideProps {\n /**\n * `grid-template-columns` of the list and the detail above 768 px, e.g.\n * `'3fr 2fr'`.\n */\n columns: string;\n /**\n * The selected item's detail: one element, such as a `Panel` titled with\n * the item's name. It is never taller than the view, so a long Panel\n * scrolls its body. Render it anew from the host's data whenever that\n * data changes: that render tells DetailBeside the change was new data,\n * so the page stays where it is. A detail that fetches its own data and\n * redraws without this host rendering leaves the page following the row,\n * and its next change of size scrolls the page.\n */\n detail: ReactNode;\n /**\n * The list: a `TraceTree`, `FileTree`, `DataTable`, `TreeTable` or\n * `ServiceMap`, in a Panel say. The detail follows the row it draws\n * selected. Like `detail`, render it anew from the host's data whenever\n * that data changes, so the page stays where it is on new data; a list\n * that fetches its own data and redraws without this host rendering\n * leaves the page following the row, and its next change of size scrolls\n * the page.\n */\n children: ReactNode;\n /**\n * The selection as the page's address names it, or null where the\n * address names none and the list shows a default. It changes only by\n * the viewer's doing: a click, a key, a link, back or forward. The page\n * scrolls to the selected row when this changes, and on the first\n * placement after mount; a row that comes into place for new data, such\n * as a default the data moved, is only levelled with.\n */\n revealKey: string | null;\n /** The element that scrolls the page; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\nconst NARROW_QUERY = '(max-width: 768px)';\n\n/**\n * The detail as the inline slot draws it. It is kept out of the context the\n * lists read, so a new detail re-renders the slot and not the list.\n */\nconst DetailContext = createContext<ReactNode>(null);\n\n/**\n * How far to scroll so the row is in the view, clear of the `inset` at the\n * view's top, and the detail, whose top can rise no higher than `ceiling`,\n * fits above the view's bottom.\n */\nfunction revealDistance(\n row: DOMRect,\n ceiling: number,\n height: number,\n inset: number,\n view: ViewBounds,\n): number {\n const top = view.top + inset;\n const toRow =\n row.top < top ? row.top - top : Math.max(row.bottom - view.bottom, 0);\n return Math.max(toRow, ceiling + height - view.bottom);\n}\n\n/** The detail right after the selected row, at 768 px and below. */\nfunction InlineDetail({ boxRef }: { boxRef: RefObject<HTMLDivElement> }) {\n const detail = useContext(DetailContext);\n return (\n <div ref={boxRef} className=\"aegis-detail-beside__inline\" role=\"group\">\n {detail}\n </div>\n );\n}\n\n/**\n * A tree, table or map with the selected item's detail beside it. Above\n * 768 px the detail stands in a column on the right, level with the\n * selected row: when the row is too low for it, its bottom meets the\n * view's bottom, and while the page scrolls it stays in the view below\n * the header; while the list draws no row selected, it stands at the\n * column's top. At 768 px and below the list draws the detail right after\n * the selected row, the rows that follow under it; a map draws it over\n * the map, under the node. When the page opens with a selection,\n * `revealKey` changes or the viewer clicks the selected row, the page\n * scrolls at once, as little as it takes to show the row and the detail\n * whole, and again whenever the list or the detail changes size, until the\n * viewer scrolls or the host renders a new list or detail. Any other\n * placement, such as new data moving the selection or the rows, levels\n * the detail with its row by the same rule and leaves the page where it\n * is; the browser's scroll anchoring can still move it when rows arrive\n * above the view, unless the host sets `overflow-anchor: none` on its\n * scroller. The wrapper is `aria-busy` while a selected row it reveals is\n * still on its way.\n */\nexport function DetailBeside({\n columns,\n detail,\n children,\n revealKey,\n scrollContainer = null,\n className,\n}: DetailBesideProps) {\n const narrow = useMediaQuery(NARROW_QUERY);\n const [busy, setBusy] = useState(false);\n const listRef = useRef<HTMLDivElement>(null);\n const spacerRef = useRef<HTMLDivElement>(null);\n const detailRef = useRef<HTMLDivElement>(null);\n const rowRef = useRef<HTMLElement | null>(null);\n /** Whether the page is still where the last reveal left it. */\n const followRef = useRef(false);\n const revealedAtRef = useRef(0);\n /** The latest render's revealKey, and the last reveal's: undefined before the first. */\n const revealKeyRef = useRef(revealKey);\n const revealedKeyRef = useRef<string | null | undefined>(undefined);\n /** The latest render's list and detail, which change when the host renders them anew. */\n const shownRef = useRef({ children, detail });\n\n /**\n * Sets the detail level with the row: above 768 px through the spacer's\n * height, at and below by telling the inline detail how tall the row is.\n * While the list draws no row selected, such as when a filter or a closed\n * parent hides it, the detail stands at the top of its column.\n */\n const place = useCallback(() => {\n const row = rowRef.current;\n const box = detailRef.current;\n const spacer = spacerRef.current;\n if (row === null) {\n spacer?.style.removeProperty('height');\n return;\n }\n if (box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n if (spacer === null) {\n box.style.setProperty(\n '--aegis-detail-beside-row-height',\n `${String(rowBox.height)}px`,\n );\n } else {\n const top = spacer.getBoundingClientRect().top;\n spacer.style.height = `${String(Math.max(rowBox.top - top, 0))}px`;\n }\n }, []);\n\n /** Places the row and scrolls as little as it takes to show it and its detail whole. */\n const reveal = useCallback(() => {\n place();\n const row = rowRef.current;\n const box = detailRef.current;\n if (row === null || box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n const spacer = spacerRef.current;\n const distance = revealDistance(\n rowBox,\n spacer === null ? rowBox.bottom : spacer.getBoundingClientRect().top,\n box.getBoundingClientRect().height,\n parseFloat(getComputedStyle(box).scrollMarginTop),\n viewBoundsOf(scrollContainer),\n );\n const scroller = scrollerOf(scrollContainer);\n if (Math.abs(distance) >= 1) {\n scroller.scrollBy({ top: distance, behavior: 'instant' });\n }\n revealedAtRef.current = scroller.scrollTop;\n }, [place, scrollContainer]);\n\n // A list places its row while React attaches refs, before the detail's\n // own ref is in and before the re-renders its layout effects ask for,\n // so the reveal waits for the commit to finish.\n const revealSoon = useCallback(() => {\n revealedKeyRef.current = revealKeyRef.current;\n followRef.current = true;\n setBusy(true);\n queueMicrotask(() => {\n reveal();\n setBusy(false);\n });\n }, [reveal]);\n\n // A row placed while a reveal is due is revealed; any other is levelled\n // with, and a new one ends following.\n const placeRow = useCallback(\n (row: HTMLElement | null) => {\n const fresh = row !== rowRef.current;\n rowRef.current = row;\n if (row === null) {\n followRef.current = false;\n setBusy(false);\n place();\n } else if (revealedKeyRef.current !== revealKeyRef.current) {\n revealSoon();\n } else {\n if (fresh) {\n followRef.current = false;\n }\n place();\n }\n },\n [place, revealSoon],\n );\n\n const awaitRow = useCallback(() => {\n setBusy(true);\n }, []);\n\n // Runs after the lists have placed their rows in this commit, so a new\n // revealKey reveals the row it selects. A render by the host without one\n // ends following.\n useIsomorphicLayoutEffect(() => {\n const rendered =\n shownRef.current.children !== children ||\n shownRef.current.detail !== detail;\n shownRef.current = { children, detail };\n revealKeyRef.current = revealKey;\n if (revealedKeyRef.current !== revealKey && rowRef.current !== null) {\n revealSoon();\n } else {\n if (rendered) {\n followRef.current = false;\n }\n place();\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const list = listRef.current;\n if (list === null) {\n return undefined;\n }\n const observer = new ResizeObserver(() => {\n if (followRef.current) {\n reveal();\n } else {\n place();\n }\n });\n // At 768 px and below the detail lies inside the list.\n for (const box of narrow ? [list] : [list, detailRef.current]) {\n if (box !== null) {\n observer.observe(box);\n }\n }\n const activate = (event: MouseEvent): void => {\n if (\n event.target instanceof Node &&\n rowRef.current?.contains(event.target)\n ) {\n revealSoon();\n }\n };\n list.addEventListener('click', activate);\n return () => {\n observer.disconnect();\n list.removeEventListener('click', activate);\n };\n }, [narrow, place, reveal, revealSoon]);\n\n useEffect(() => {\n const scroller = scrollerOf(scrollContainer);\n const target = scrollContainer ?? window;\n const scrolled = (): void => {\n if (Math.abs(scroller.scrollTop - revealedAtRef.current) >= 1) {\n followRef.current = false;\n }\n };\n target.addEventListener('scroll', scrolled, { passive: true });\n return () => {\n target.removeEventListener('scroll', scrolled);\n };\n }, [scrollContainer]);\n\n const inline = useMemo(\n () => (narrow ? <InlineDetail boxRef={detailRef} /> : null),\n [narrow],\n );\n const slot = useMemo(\n (): SelectedRowDetail => ({ placeRow, awaitRow, inline }),\n [placeRow, awaitRow, inline],\n );\n const isolated = (\n <SelectedRowDetailContext.Provider value={null}>\n {detail}\n </SelectedRowDetailContext.Provider>\n );\n\n const cls = ['aegis-detail-beside', className ?? '']\n .filter(Boolean)\n .join(' ');\n\n return (\n <SelectedRowDetailContext.Provider value={slot}>\n <DetailContext.Provider value={isolated}>\n <div\n className={cls}\n style={{ '--aegis-detail-beside-columns': columns } as CSSProperties}\n aria-busy={busy || undefined}\n >\n <div ref={listRef} className=\"aegis-detail-beside__list\">\n {children}\n </div>\n {!narrow && (\n <div className=\"aegis-detail-beside__side\">\n <div ref={spacerRef} />\n <div ref={detailRef} className=\"aegis-detail-beside__detail\">\n {isolated}\n </div>\n </div>\n )}\n </div>\n </DetailContext.Provider>\n </SelectedRowDetailContext.Provider>\n );\n}\n"],"names":["NARROW_QUERY","DetailContext","createContext","revealDistance","row","ceiling","height","inset","view","top","toRow","InlineDetail","boxRef","detail","useContext","jsx","DetailBeside","columns","children","revealKey","scrollContainer","className","narrow","useMediaQuery","busy","setBusy","useState","listRef","useRef","spacerRef","detailRef","rowRef","followRef","revealedAtRef","revealKeyRef","revealedKeyRef","shownRef","place","useCallback","box","spacer","rowBox","reveal","distance","viewBoundsOf","scroller","scrollerOf","revealSoon","placeRow","fresh","awaitRow","useIsomorphicLayoutEffect","rendered","list","observer","activate","event","useEffect","target","scrolled","inline","useMemo","slot","isolated","SelectedRowDetailContext","cls","jsxs"],"mappings":"6VAkEMA,EAAe,qBAMfC,EAAgBC,EAAAA,cAAyB,IAAI,EAOnD,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACQ,CACR,MAAMC,EAAMD,EAAK,IAAMD,EACjBG,EACJN,EAAI,IAAMK,EAAML,EAAI,IAAMK,EAAM,KAAK,IAAIL,EAAI,OAASI,EAAK,OAAQ,CAAC,EACtE,OAAO,KAAK,IAAIE,EAAOL,EAAUC,EAASE,EAAK,MAAM,CACvD,CAGA,SAASG,EAAa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UE,EAAUU,CAAM,CAAA,EAEvBG,EACJhD,MAACiD,EAAAA,yBAAyB,SAAzB,CAAkC,MAAO,KACvC,SAAAnD,EACH,EAGIoD,EAAM,CAAC,sBAAuB5C,GAAa,EAAE,EAChD,OAAO,OAAO,EACd,KAAK,GAAG,EAEX,OACEN,EAAAA,IAACiD,EAAAA,yBAAyB,SAAzB,CAAkC,MAAOF,EACxC,SAAA/C,EAAAA,IAACd,EAAc,SAAd,CAAuB,MAAO8D,EAC7B,SAAAG,EAAAA,KAAC,MAAA,CACC,UAAWD,EACX,MAAO,CAAE,gCAAiChD,CAAA,EAC1C,YAAWO,GAAQ,OAEnB,SAAA,CAAAT,EAAAA,IAAC,MAAA,CAAI,IAAKY,EAAS,UAAU,4BAC1B,SAAAT,EACH,EACC,CAACI,GACA4C,EAAAA,KAAC,MAAA,CAAI,UAAU,4BACb,SAAA,CAAAnD,EAAAA,IAAC,MAAA,CAAI,IAAKc,CAAA,CAAW,QACpB,MAAA,CAAI,IAAKC,EAAW,UAAU,8BAC5B,SAAAiC,CAAA,CACH,CAAA,CAAA,CACF,CAAA,CAAA,CAAA,EAGN,CAAA,CACF,CAEJ"}
|
|
@@ -16,12 +16,13 @@ export interface DetailBesideProps {
|
|
|
16
16
|
*/
|
|
17
17
|
detail: ReactNode;
|
|
18
18
|
/**
|
|
19
|
-
* The list: a `TraceTree`, `FileTree`, `DataTable` or
|
|
20
|
-
* Panel say. The detail follows the row it draws
|
|
21
|
-
* `detail`, render it anew from the host's data whenever
|
|
22
|
-
* changes, so the page stays where it is on new data; a list
|
|
23
|
-
* its own data and redraws without this host rendering
|
|
24
|
-
* following the row, and its next change of size scrolls
|
|
19
|
+
* The list: a `TraceTree`, `FileTree`, `DataTable`, `TreeTable` or
|
|
20
|
+
* `ServiceMap`, in a Panel say. The detail follows the row it draws
|
|
21
|
+
* selected. Like `detail`, render it anew from the host's data whenever
|
|
22
|
+
* that data changes, so the page stays where it is on new data; a list
|
|
23
|
+
* that fetches its own data and redraws without this host rendering
|
|
24
|
+
* leaves the page following the row, and its next change of size scrolls
|
|
25
|
+
* the page.
|
|
25
26
|
*/
|
|
26
27
|
children: ReactNode;
|
|
27
28
|
/**
|
|
@@ -42,7 +43,8 @@ export interface DetailBesideProps {
|
|
|
42
43
|
* 768 px the detail stands in a column on the right, level with the
|
|
43
44
|
* selected row: when the row is too low for it, its bottom meets the
|
|
44
45
|
* view's bottom, and while the page scrolls it stays in the view below
|
|
45
|
-
* the header
|
|
46
|
+
* the header; while the list draws no row selected, it stands at the
|
|
47
|
+
* column's top. At 768 px and below the list draws the detail right after
|
|
46
48
|
* the selected row, the rows that follow under it; a map draws it over
|
|
47
49
|
* the map, under the node. When the page opens with a selection,
|
|
48
50
|
* `revealKey` changes or the viewer clicks the selected row, the page
|
|
@@ -1,86 +1,90 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as z, useRef as s, useCallback as
|
|
1
|
+
import { jsx as i, jsxs as k } from "react/jsx-runtime";
|
|
2
|
+
import { useState as z, useRef as s, useCallback as h, useEffect as F, useMemo as O, useContext as U, createContext as W } from "react";
|
|
3
3
|
import { useIsomorphicLayoutEffect as j } from "../../hooks/useIsomorphicLayoutEffect.js";
|
|
4
4
|
import { useMediaQuery as Y } from "../../hooks/useMediaQuery.js";
|
|
5
5
|
import { viewBoundsOf as G, scrollerOf as T } from "../../lib/scrollView.js";
|
|
6
6
|
/* empty css */
|
|
7
7
|
import { SelectedRowDetailContext as A } from "./selectedRowDetail.js";
|
|
8
8
|
const H = "(max-width: 768px)", I = W(null);
|
|
9
|
-
function J(
|
|
10
|
-
const
|
|
11
|
-
return Math.max(
|
|
9
|
+
function J(u, c, f, m, o) {
|
|
10
|
+
const b = o.top + m, a = u.top < b ? u.top - b : Math.max(u.bottom - o.bottom, 0);
|
|
11
|
+
return Math.max(a, c + f - o.bottom);
|
|
12
12
|
}
|
|
13
|
-
function K({ boxRef:
|
|
13
|
+
function K({ boxRef: u }) {
|
|
14
14
|
const c = U(I);
|
|
15
|
-
return /* @__PURE__ */
|
|
15
|
+
return /* @__PURE__ */ i("div", { ref: u, className: "aegis-detail-beside__inline", role: "group", children: c });
|
|
16
16
|
}
|
|
17
17
|
function oe({
|
|
18
|
-
columns:
|
|
18
|
+
columns: u,
|
|
19
19
|
detail: c,
|
|
20
|
-
children:
|
|
20
|
+
children: f,
|
|
21
21
|
revealKey: m,
|
|
22
22
|
scrollContainer: o = null,
|
|
23
|
-
className:
|
|
23
|
+
className: b
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
26
|
-
const e =
|
|
27
|
-
if (e === null
|
|
25
|
+
const a = Y(H), [Q, R] = z(!1), E = s(null), y = s(null), g = s(null), d = s(null), p = s(!1), N = s(0), B = s(m), M = s(void 0), _ = s({ children: f, detail: c }), l = h(() => {
|
|
26
|
+
const e = d.current, t = g.current, r = y.current;
|
|
27
|
+
if (e === null) {
|
|
28
|
+
r?.style.removeProperty("height");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (t === null)
|
|
28
32
|
return;
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
33
|
+
const n = e.getBoundingClientRect();
|
|
34
|
+
if (r === null)
|
|
31
35
|
t.style.setProperty(
|
|
32
36
|
"--aegis-detail-beside-row-height",
|
|
33
|
-
`${String(
|
|
37
|
+
`${String(n.height)}px`
|
|
34
38
|
);
|
|
35
39
|
else {
|
|
36
|
-
const w =
|
|
37
|
-
|
|
40
|
+
const w = r.getBoundingClientRect().top;
|
|
41
|
+
r.style.height = `${String(Math.max(n.top - w, 0))}px`;
|
|
38
42
|
}
|
|
39
|
-
}, []), x =
|
|
40
|
-
|
|
41
|
-
const e =
|
|
43
|
+
}, []), x = h(() => {
|
|
44
|
+
l();
|
|
45
|
+
const e = d.current, t = g.current;
|
|
42
46
|
if (e === null || t === null)
|
|
43
47
|
return;
|
|
44
|
-
const r = e.getBoundingClientRect(), n =
|
|
48
|
+
const r = e.getBoundingClientRect(), n = y.current, w = J(
|
|
45
49
|
r,
|
|
46
50
|
n === null ? r.bottom : n.getBoundingClientRect().top,
|
|
47
51
|
t.getBoundingClientRect().height,
|
|
48
52
|
parseFloat(getComputedStyle(t).scrollMarginTop),
|
|
49
53
|
G(o)
|
|
50
|
-
),
|
|
51
|
-
Math.abs(w) >= 1 &&
|
|
52
|
-
}, [
|
|
53
|
-
M.current =
|
|
54
|
-
x(),
|
|
54
|
+
), P = T(o);
|
|
55
|
+
Math.abs(w) >= 1 && P.scrollBy({ top: w, behavior: "instant" }), N.current = P.scrollTop;
|
|
56
|
+
}, [l, o]), v = h(() => {
|
|
57
|
+
M.current = B.current, p.current = !0, R(!0), queueMicrotask(() => {
|
|
58
|
+
x(), R(!1);
|
|
55
59
|
});
|
|
56
|
-
}, [x]), C =
|
|
60
|
+
}, [x]), C = h(
|
|
57
61
|
(e) => {
|
|
58
|
-
const t = e !==
|
|
59
|
-
|
|
62
|
+
const t = e !== d.current;
|
|
63
|
+
d.current = e, e === null ? (p.current = !1, R(!1), l()) : M.current !== B.current ? v() : (t && (p.current = !1), l());
|
|
60
64
|
},
|
|
61
|
-
[
|
|
62
|
-
), S =
|
|
63
|
-
|
|
65
|
+
[l, v]
|
|
66
|
+
), S = h(() => {
|
|
67
|
+
R(!0);
|
|
64
68
|
}, []);
|
|
65
69
|
j(() => {
|
|
66
|
-
const e = _.current.children !==
|
|
67
|
-
_.current = { children:
|
|
70
|
+
const e = _.current.children !== f || _.current.detail !== c;
|
|
71
|
+
_.current = { children: f, detail: c }, B.current = m, M.current !== m && d.current !== null ? v() : (e && (p.current = !1), l());
|
|
68
72
|
}), j(() => {
|
|
69
73
|
const e = E.current;
|
|
70
74
|
if (e === null)
|
|
71
75
|
return;
|
|
72
76
|
const t = new ResizeObserver(() => {
|
|
73
|
-
p.current ? x() :
|
|
77
|
+
p.current ? x() : l();
|
|
74
78
|
});
|
|
75
|
-
for (const n of
|
|
79
|
+
for (const n of a ? [e] : [e, g.current])
|
|
76
80
|
n !== null && t.observe(n);
|
|
77
81
|
const r = (n) => {
|
|
78
|
-
n.target instanceof Node &&
|
|
82
|
+
n.target instanceof Node && d.current?.contains(n.target) && v();
|
|
79
83
|
};
|
|
80
84
|
return e.addEventListener("click", r), () => {
|
|
81
85
|
t.disconnect(), e.removeEventListener("click", r);
|
|
82
86
|
};
|
|
83
|
-
}, [
|
|
87
|
+
}, [a, l, x, v]), F(() => {
|
|
84
88
|
const e = T(o), t = o ?? window, r = () => {
|
|
85
89
|
Math.abs(e.scrollTop - N.current) >= 1 && (p.current = !1);
|
|
86
90
|
};
|
|
@@ -88,24 +92,24 @@ function oe({
|
|
|
88
92
|
t.removeEventListener("scroll", r);
|
|
89
93
|
};
|
|
90
94
|
}, [o]);
|
|
91
|
-
const D =
|
|
92
|
-
() =>
|
|
93
|
-
[
|
|
94
|
-
), $ =
|
|
95
|
+
const D = O(
|
|
96
|
+
() => a ? /* @__PURE__ */ i(K, { boxRef: g }) : null,
|
|
97
|
+
[a]
|
|
98
|
+
), $ = O(
|
|
95
99
|
() => ({ placeRow: C, awaitRow: S, inline: D }),
|
|
96
100
|
[C, S, D]
|
|
97
|
-
), L = /* @__PURE__ */
|
|
98
|
-
return /* @__PURE__ */
|
|
101
|
+
), L = /* @__PURE__ */ i(A.Provider, { value: null, children: c }), q = ["aegis-detail-beside", b ?? ""].filter(Boolean).join(" ");
|
|
102
|
+
return /* @__PURE__ */ i(A.Provider, { value: $, children: /* @__PURE__ */ i(I.Provider, { value: L, children: /* @__PURE__ */ k(
|
|
99
103
|
"div",
|
|
100
104
|
{
|
|
101
105
|
className: q,
|
|
102
|
-
style: { "--aegis-detail-beside-columns":
|
|
106
|
+
style: { "--aegis-detail-beside-columns": u },
|
|
103
107
|
"aria-busy": Q || void 0,
|
|
104
108
|
children: [
|
|
105
|
-
/* @__PURE__ */
|
|
106
|
-
!
|
|
107
|
-
/* @__PURE__ */
|
|
108
|
-
/* @__PURE__ */
|
|
109
|
+
/* @__PURE__ */ i("div", { ref: E, className: "aegis-detail-beside__list", children: f }),
|
|
110
|
+
!a && /* @__PURE__ */ k("div", { className: "aegis-detail-beside__side", children: [
|
|
111
|
+
/* @__PURE__ */ i("div", { ref: y }),
|
|
112
|
+
/* @__PURE__ */ i("div", { ref: g, className: "aegis-detail-beside__detail", children: L })
|
|
109
113
|
] })
|
|
110
114
|
]
|
|
111
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetailBeside.js","sources":["../../../src/components/ui/DetailBeside.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n type RefObject,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport {\n type ViewBounds,\n scrollerOf,\n viewBoundsOf,\n} from '../../lib/scrollView';\nimport './DetailBeside.css';\nimport {\n type SelectedRowDetail,\n SelectedRowDetailContext,\n} from './selectedRowDetail';\n\nexport interface DetailBesideProps {\n /**\n * `grid-template-columns` of the list and the detail above 768 px, e.g.\n * `'3fr 2fr'`.\n */\n columns: string;\n /**\n * The selected item's detail: one element, such as a `Panel` titled with\n * the item's name. It is never taller than the view, so a long Panel\n * scrolls its body. Render it anew from the host's data whenever that\n * data changes: that render tells DetailBeside the change was new data,\n * so the page stays where it is. A detail that fetches its own data and\n * redraws without this host rendering leaves the page following the row,\n * and its next change of size scrolls the page.\n */\n detail: ReactNode;\n /**\n * The list: a `TraceTree`, `FileTree`, `DataTable` or `ServiceMap`, in a\n * Panel say. The detail follows the row it draws selected. Like\n * `detail`, render it anew from the host's data whenever that data\n * changes, so the page stays where it is on new data; a list that fetches\n * its own data and redraws without this host rendering leaves the page\n * following the row, and its next change of size scrolls the page.\n */\n children: ReactNode;\n /**\n * The selection as the page's address names it, or null where the\n * address names none and the list shows a default. It changes only by\n * the viewer's doing: a click, a key, a link, back or forward. The page\n * scrolls to the selected row when this changes, and on the first\n * placement after mount; a row that comes into place for new data, such\n * as a default the data moved, is only levelled with.\n */\n revealKey: string | null;\n /** The element that scrolls the page; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\nconst NARROW_QUERY = '(max-width: 768px)';\n\n/**\n * The detail as the inline slot draws it. It is kept out of the context the\n * lists read, so a new detail re-renders the slot and not the list.\n */\nconst DetailContext = createContext<ReactNode>(null);\n\n/**\n * How far to scroll so the row is in the view, clear of the `inset` at the\n * view's top, and the detail, whose top can rise no higher than `ceiling`,\n * fits above the view's bottom.\n */\nfunction revealDistance(\n row: DOMRect,\n ceiling: number,\n height: number,\n inset: number,\n view: ViewBounds,\n): number {\n const top = view.top + inset;\n const toRow =\n row.top < top ? row.top - top : Math.max(row.bottom - view.bottom, 0);\n return Math.max(toRow, ceiling + height - view.bottom);\n}\n\n/** The detail right after the selected row, at 768 px and below. */\nfunction InlineDetail({ boxRef }: { boxRef: RefObject<HTMLDivElement> }) {\n const detail = useContext(DetailContext);\n return (\n <div ref={boxRef} className=\"aegis-detail-beside__inline\" role=\"group\">\n {detail}\n </div>\n );\n}\n\n/**\n * A tree, table or map with the selected item's detail beside it. Above\n * 768 px the detail stands in a column on the right, level with the\n * selected row: when the row is too low for it, its bottom meets the\n * view's bottom, and while the page scrolls it stays in the view below\n * the header. At 768 px and below the list draws the detail right after\n * the selected row, the rows that follow under it; a map draws it over\n * the map, under the node. When the page opens with a selection,\n * `revealKey` changes or the viewer clicks the selected row, the page\n * scrolls at once, as little as it takes to show the row and the detail\n * whole, and again whenever the list or the detail changes size, until the\n * viewer scrolls or the host renders a new list or detail. Any other\n * placement, such as new data moving the selection or the rows, levels\n * the detail with its row by the same rule and leaves the page where it\n * is; the browser's scroll anchoring can still move it when rows arrive\n * above the view, unless the host sets `overflow-anchor: none` on its\n * scroller. The wrapper is `aria-busy` while a selected row it reveals is\n * still on its way.\n */\nexport function DetailBeside({\n columns,\n detail,\n children,\n revealKey,\n scrollContainer = null,\n className,\n}: DetailBesideProps) {\n const narrow = useMediaQuery(NARROW_QUERY);\n const [busy, setBusy] = useState(false);\n const listRef = useRef<HTMLDivElement>(null);\n const spacerRef = useRef<HTMLDivElement>(null);\n const detailRef = useRef<HTMLDivElement>(null);\n const rowRef = useRef<HTMLElement | null>(null);\n /** Whether the page is still where the last reveal left it. */\n const followRef = useRef(false);\n const revealedAtRef = useRef(0);\n /** The latest render's revealKey, and the last reveal's: undefined before the first. */\n const revealKeyRef = useRef(revealKey);\n const revealedKeyRef = useRef<string | null | undefined>(undefined);\n /** The latest render's list and detail, which change when the host renders them anew. */\n const shownRef = useRef({ children, detail });\n\n /**\n * Sets the detail level with the row: above 768 px through the spacer's\n * height, at and below by telling the inline detail how tall the row is.\n */\n const place = useCallback(() => {\n const row = rowRef.current;\n const box = detailRef.current;\n if (row === null || box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n const spacer = spacerRef.current;\n if (spacer === null) {\n box.style.setProperty(\n '--aegis-detail-beside-row-height',\n `${String(rowBox.height)}px`,\n );\n } else {\n const top = spacer.getBoundingClientRect().top;\n spacer.style.height = `${String(Math.max(rowBox.top - top, 0))}px`;\n }\n }, []);\n\n /** Places the row and scrolls as little as it takes to show it and its detail whole. */\n const reveal = useCallback(() => {\n place();\n const row = rowRef.current;\n const box = detailRef.current;\n if (row === null || box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n const spacer = spacerRef.current;\n const distance = revealDistance(\n rowBox,\n spacer === null ? rowBox.bottom : spacer.getBoundingClientRect().top,\n box.getBoundingClientRect().height,\n parseFloat(getComputedStyle(box).scrollMarginTop),\n viewBoundsOf(scrollContainer),\n );\n const scroller = scrollerOf(scrollContainer);\n if (Math.abs(distance) >= 1) {\n scroller.scrollBy({ top: distance, behavior: 'instant' });\n }\n revealedAtRef.current = scroller.scrollTop;\n }, [place, scrollContainer]);\n\n // A list places its row while React attaches refs, before the detail's\n // own ref is in and before the re-renders its layout effects ask for,\n // so the reveal waits for the commit to finish.\n const revealSoon = useCallback(() => {\n revealedKeyRef.current = revealKeyRef.current;\n followRef.current = true;\n setBusy(true);\n queueMicrotask(() => {\n reveal();\n setBusy(false);\n });\n }, [reveal]);\n\n // A row placed while a reveal is due is revealed; any other is levelled\n // with, and a new one ends following.\n const placeRow = useCallback(\n (row: HTMLElement | null) => {\n const fresh = row !== rowRef.current;\n rowRef.current = row;\n if (row === null) {\n followRef.current = false;\n setBusy(false);\n } else if (revealedKeyRef.current !== revealKeyRef.current) {\n revealSoon();\n } else {\n if (fresh) {\n followRef.current = false;\n }\n place();\n }\n },\n [place, revealSoon],\n );\n\n const awaitRow = useCallback(() => {\n setBusy(true);\n }, []);\n\n // Runs after the lists have placed their rows in this commit, so a new\n // revealKey reveals the row it selects. A render by the host without one\n // ends following.\n useIsomorphicLayoutEffect(() => {\n const rendered =\n shownRef.current.children !== children ||\n shownRef.current.detail !== detail;\n shownRef.current = { children, detail };\n revealKeyRef.current = revealKey;\n if (revealedKeyRef.current !== revealKey && rowRef.current !== null) {\n revealSoon();\n } else {\n if (rendered) {\n followRef.current = false;\n }\n place();\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const list = listRef.current;\n if (list === null) {\n return undefined;\n }\n const observer = new ResizeObserver(() => {\n if (followRef.current) {\n reveal();\n } else {\n place();\n }\n });\n // At 768 px and below the detail lies inside the list.\n for (const box of narrow ? [list] : [list, detailRef.current]) {\n if (box !== null) {\n observer.observe(box);\n }\n }\n const activate = (event: MouseEvent): void => {\n if (\n event.target instanceof Node &&\n rowRef.current?.contains(event.target)\n ) {\n revealSoon();\n }\n };\n list.addEventListener('click', activate);\n return () => {\n observer.disconnect();\n list.removeEventListener('click', activate);\n };\n }, [narrow, place, reveal, revealSoon]);\n\n useEffect(() => {\n const scroller = scrollerOf(scrollContainer);\n const target = scrollContainer ?? window;\n const scrolled = (): void => {\n if (Math.abs(scroller.scrollTop - revealedAtRef.current) >= 1) {\n followRef.current = false;\n }\n };\n target.addEventListener('scroll', scrolled, { passive: true });\n return () => {\n target.removeEventListener('scroll', scrolled);\n };\n }, [scrollContainer]);\n\n const inline = useMemo(\n () => (narrow ? <InlineDetail boxRef={detailRef} /> : null),\n [narrow],\n );\n const slot = useMemo(\n (): SelectedRowDetail => ({ placeRow, awaitRow, inline }),\n [placeRow, awaitRow, inline],\n );\n const isolated = (\n <SelectedRowDetailContext.Provider value={null}>\n {detail}\n </SelectedRowDetailContext.Provider>\n );\n\n const cls = ['aegis-detail-beside', className ?? '']\n .filter(Boolean)\n .join(' ');\n\n return (\n <SelectedRowDetailContext.Provider value={slot}>\n <DetailContext.Provider value={isolated}>\n <div\n className={cls}\n style={{ '--aegis-detail-beside-columns': columns } as CSSProperties}\n aria-busy={busy || undefined}\n >\n <div ref={listRef} className=\"aegis-detail-beside__list\">\n {children}\n </div>\n {!narrow && (\n <div className=\"aegis-detail-beside__side\">\n <div ref={spacerRef} />\n <div ref={detailRef} className=\"aegis-detail-beside__detail\">\n {isolated}\n </div>\n </div>\n )}\n </div>\n </DetailContext.Provider>\n </SelectedRowDetailContext.Provider>\n );\n}\n"],"names":["NARROW_QUERY","DetailContext","createContext","revealDistance","row","ceiling","height","inset","view","top","toRow","InlineDetail","boxRef","detail","useContext","jsx","DetailBeside","columns","children","revealKey","scrollContainer","className","narrow","useMediaQuery","busy","setBusy","useState","listRef","useRef","spacerRef","detailRef","rowRef","followRef","revealedAtRef","revealKeyRef","revealedKeyRef","shownRef","place","useCallback","box","rowBox","spacer","reveal","distance","viewBoundsOf","scroller","scrollerOf","revealSoon","placeRow","fresh","awaitRow","useIsomorphicLayoutEffect","rendered","list","observer","activate","event","useEffect","target","scrolled","inline","useMemo","slot","isolated","SelectedRowDetailContext","cls","jsxs"],"mappings":";;;;;;;AAiEA,MAAMA,IAAe,sBAMfC,IAAgBC,EAAyB,IAAI;AAOnD,SAASC,EACPC,GACAC,GACAC,GACAC,GACAC,GACQ;AACR,QAAMC,IAAMD,EAAK,MAAMD,GACjB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;AAAA,IAC/C;AAAA,EACF,GAAG,CAACvC,CAAe,CAAC;AAEpB,QAAMwC,IAASC;AAAA,IACb,MAAOvC,IAAS,gBAAAP,EAACJ,GAAA,EAAa,QAAQmB,GAAW,IAAK;AAAA,IACtD,CAACR,CAAM;AAAA,EAAA,GAEHwC,IAAOD;AAAA,IACX,OAA0B,EAAE,UAAAb,GAAU,UAAAE,GAAU,QAAAU;IAChD,CAACZ,GAAUE,GAAUU,CAAM;AAAA,EAAA,GAEvBG,IACJ,gBAAAhD,EAACiD,EAAyB,UAAzB,EAAkC,OAAO,MACvC,UAAAnD,GACH,GAGIoD,IAAM,CAAC,uBAAuB5C,KAAa,EAAE,EAChD,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,SACE,gBAAAN,EAACiD,EAAyB,UAAzB,EAAkC,OAAOF,GACxC,UAAA,gBAAA/C,EAACd,EAAc,UAAd,EAAuB,OAAO8D,GAC7B,UAAA,gBAAAG;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWD;AAAA,MACX,OAAO,EAAE,iCAAiChD,EAAA;AAAA,MAC1C,aAAWO,KAAQ;AAAA,MAEnB,UAAA;AAAA,QAAA,gBAAAT,EAAC,OAAA,EAAI,KAAKY,GAAS,WAAU,6BAC1B,UAAAT,GACH;AAAA,QACC,CAACI,KACA,gBAAA4C,EAAC,OAAA,EAAI,WAAU,6BACb,UAAA;AAAA,UAAA,gBAAAnD,EAAC,OAAA,EAAI,KAAKc,EAAA,CAAW;AAAA,4BACpB,OAAA,EAAI,KAAKC,GAAW,WAAU,+BAC5B,UAAAiC,EAAA,CACH;AAAA,QAAA,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAGN,EAAA,CACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"DetailBeside.js","sources":["../../../src/components/ui/DetailBeside.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n type RefObject,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport {\n type ViewBounds,\n scrollerOf,\n viewBoundsOf,\n} from '../../lib/scrollView';\nimport './DetailBeside.css';\nimport {\n type SelectedRowDetail,\n SelectedRowDetailContext,\n} from './selectedRowDetail';\n\nexport interface DetailBesideProps {\n /**\n * `grid-template-columns` of the list and the detail above 768 px, e.g.\n * `'3fr 2fr'`.\n */\n columns: string;\n /**\n * The selected item's detail: one element, such as a `Panel` titled with\n * the item's name. It is never taller than the view, so a long Panel\n * scrolls its body. Render it anew from the host's data whenever that\n * data changes: that render tells DetailBeside the change was new data,\n * so the page stays where it is. A detail that fetches its own data and\n * redraws without this host rendering leaves the page following the row,\n * and its next change of size scrolls the page.\n */\n detail: ReactNode;\n /**\n * The list: a `TraceTree`, `FileTree`, `DataTable`, `TreeTable` or\n * `ServiceMap`, in a Panel say. The detail follows the row it draws\n * selected. Like `detail`, render it anew from the host's data whenever\n * that data changes, so the page stays where it is on new data; a list\n * that fetches its own data and redraws without this host rendering\n * leaves the page following the row, and its next change of size scrolls\n * the page.\n */\n children: ReactNode;\n /**\n * The selection as the page's address names it, or null where the\n * address names none and the list shows a default. It changes only by\n * the viewer's doing: a click, a key, a link, back or forward. The page\n * scrolls to the selected row when this changes, and on the first\n * placement after mount; a row that comes into place for new data, such\n * as a default the data moved, is only levelled with.\n */\n revealKey: string | null;\n /** The element that scrolls the page; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\nconst NARROW_QUERY = '(max-width: 768px)';\n\n/**\n * The detail as the inline slot draws it. It is kept out of the context the\n * lists read, so a new detail re-renders the slot and not the list.\n */\nconst DetailContext = createContext<ReactNode>(null);\n\n/**\n * How far to scroll so the row is in the view, clear of the `inset` at the\n * view's top, and the detail, whose top can rise no higher than `ceiling`,\n * fits above the view's bottom.\n */\nfunction revealDistance(\n row: DOMRect,\n ceiling: number,\n height: number,\n inset: number,\n view: ViewBounds,\n): number {\n const top = view.top + inset;\n const toRow =\n row.top < top ? row.top - top : Math.max(row.bottom - view.bottom, 0);\n return Math.max(toRow, ceiling + height - view.bottom);\n}\n\n/** The detail right after the selected row, at 768 px and below. */\nfunction InlineDetail({ boxRef }: { boxRef: RefObject<HTMLDivElement> }) {\n const detail = useContext(DetailContext);\n return (\n <div ref={boxRef} className=\"aegis-detail-beside__inline\" role=\"group\">\n {detail}\n </div>\n );\n}\n\n/**\n * A tree, table or map with the selected item's detail beside it. Above\n * 768 px the detail stands in a column on the right, level with the\n * selected row: when the row is too low for it, its bottom meets the\n * view's bottom, and while the page scrolls it stays in the view below\n * the header; while the list draws no row selected, it stands at the\n * column's top. At 768 px and below the list draws the detail right after\n * the selected row, the rows that follow under it; a map draws it over\n * the map, under the node. When the page opens with a selection,\n * `revealKey` changes or the viewer clicks the selected row, the page\n * scrolls at once, as little as it takes to show the row and the detail\n * whole, and again whenever the list or the detail changes size, until the\n * viewer scrolls or the host renders a new list or detail. Any other\n * placement, such as new data moving the selection or the rows, levels\n * the detail with its row by the same rule and leaves the page where it\n * is; the browser's scroll anchoring can still move it when rows arrive\n * above the view, unless the host sets `overflow-anchor: none` on its\n * scroller. The wrapper is `aria-busy` while a selected row it reveals is\n * still on its way.\n */\nexport function DetailBeside({\n columns,\n detail,\n children,\n revealKey,\n scrollContainer = null,\n className,\n}: DetailBesideProps) {\n const narrow = useMediaQuery(NARROW_QUERY);\n const [busy, setBusy] = useState(false);\n const listRef = useRef<HTMLDivElement>(null);\n const spacerRef = useRef<HTMLDivElement>(null);\n const detailRef = useRef<HTMLDivElement>(null);\n const rowRef = useRef<HTMLElement | null>(null);\n /** Whether the page is still where the last reveal left it. */\n const followRef = useRef(false);\n const revealedAtRef = useRef(0);\n /** The latest render's revealKey, and the last reveal's: undefined before the first. */\n const revealKeyRef = useRef(revealKey);\n const revealedKeyRef = useRef<string | null | undefined>(undefined);\n /** The latest render's list and detail, which change when the host renders them anew. */\n const shownRef = useRef({ children, detail });\n\n /**\n * Sets the detail level with the row: above 768 px through the spacer's\n * height, at and below by telling the inline detail how tall the row is.\n * While the list draws no row selected, such as when a filter or a closed\n * parent hides it, the detail stands at the top of its column.\n */\n const place = useCallback(() => {\n const row = rowRef.current;\n const box = detailRef.current;\n const spacer = spacerRef.current;\n if (row === null) {\n spacer?.style.removeProperty('height');\n return;\n }\n if (box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n if (spacer === null) {\n box.style.setProperty(\n '--aegis-detail-beside-row-height',\n `${String(rowBox.height)}px`,\n );\n } else {\n const top = spacer.getBoundingClientRect().top;\n spacer.style.height = `${String(Math.max(rowBox.top - top, 0))}px`;\n }\n }, []);\n\n /** Places the row and scrolls as little as it takes to show it and its detail whole. */\n const reveal = useCallback(() => {\n place();\n const row = rowRef.current;\n const box = detailRef.current;\n if (row === null || box === null) {\n return;\n }\n const rowBox = row.getBoundingClientRect();\n const spacer = spacerRef.current;\n const distance = revealDistance(\n rowBox,\n spacer === null ? rowBox.bottom : spacer.getBoundingClientRect().top,\n box.getBoundingClientRect().height,\n parseFloat(getComputedStyle(box).scrollMarginTop),\n viewBoundsOf(scrollContainer),\n );\n const scroller = scrollerOf(scrollContainer);\n if (Math.abs(distance) >= 1) {\n scroller.scrollBy({ top: distance, behavior: 'instant' });\n }\n revealedAtRef.current = scroller.scrollTop;\n }, [place, scrollContainer]);\n\n // A list places its row while React attaches refs, before the detail's\n // own ref is in and before the re-renders its layout effects ask for,\n // so the reveal waits for the commit to finish.\n const revealSoon = useCallback(() => {\n revealedKeyRef.current = revealKeyRef.current;\n followRef.current = true;\n setBusy(true);\n queueMicrotask(() => {\n reveal();\n setBusy(false);\n });\n }, [reveal]);\n\n // A row placed while a reveal is due is revealed; any other is levelled\n // with, and a new one ends following.\n const placeRow = useCallback(\n (row: HTMLElement | null) => {\n const fresh = row !== rowRef.current;\n rowRef.current = row;\n if (row === null) {\n followRef.current = false;\n setBusy(false);\n place();\n } else if (revealedKeyRef.current !== revealKeyRef.current) {\n revealSoon();\n } else {\n if (fresh) {\n followRef.current = false;\n }\n place();\n }\n },\n [place, revealSoon],\n );\n\n const awaitRow = useCallback(() => {\n setBusy(true);\n }, []);\n\n // Runs after the lists have placed their rows in this commit, so a new\n // revealKey reveals the row it selects. A render by the host without one\n // ends following.\n useIsomorphicLayoutEffect(() => {\n const rendered =\n shownRef.current.children !== children ||\n shownRef.current.detail !== detail;\n shownRef.current = { children, detail };\n revealKeyRef.current = revealKey;\n if (revealedKeyRef.current !== revealKey && rowRef.current !== null) {\n revealSoon();\n } else {\n if (rendered) {\n followRef.current = false;\n }\n place();\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const list = listRef.current;\n if (list === null) {\n return undefined;\n }\n const observer = new ResizeObserver(() => {\n if (followRef.current) {\n reveal();\n } else {\n place();\n }\n });\n // At 768 px and below the detail lies inside the list.\n for (const box of narrow ? [list] : [list, detailRef.current]) {\n if (box !== null) {\n observer.observe(box);\n }\n }\n const activate = (event: MouseEvent): void => {\n if (\n event.target instanceof Node &&\n rowRef.current?.contains(event.target)\n ) {\n revealSoon();\n }\n };\n list.addEventListener('click', activate);\n return () => {\n observer.disconnect();\n list.removeEventListener('click', activate);\n };\n }, [narrow, place, reveal, revealSoon]);\n\n useEffect(() => {\n const scroller = scrollerOf(scrollContainer);\n const target = scrollContainer ?? window;\n const scrolled = (): void => {\n if (Math.abs(scroller.scrollTop - revealedAtRef.current) >= 1) {\n followRef.current = false;\n }\n };\n target.addEventListener('scroll', scrolled, { passive: true });\n return () => {\n target.removeEventListener('scroll', scrolled);\n };\n }, [scrollContainer]);\n\n const inline = useMemo(\n () => (narrow ? <InlineDetail boxRef={detailRef} /> : null),\n [narrow],\n );\n const slot = useMemo(\n (): SelectedRowDetail => ({ placeRow, awaitRow, inline }),\n [placeRow, awaitRow, inline],\n );\n const isolated = (\n <SelectedRowDetailContext.Provider value={null}>\n {detail}\n </SelectedRowDetailContext.Provider>\n );\n\n const cls = ['aegis-detail-beside', className ?? '']\n .filter(Boolean)\n .join(' ');\n\n return (\n <SelectedRowDetailContext.Provider value={slot}>\n <DetailContext.Provider value={isolated}>\n <div\n className={cls}\n style={{ '--aegis-detail-beside-columns': columns } as CSSProperties}\n aria-busy={busy || undefined}\n >\n <div ref={listRef} className=\"aegis-detail-beside__list\">\n {children}\n </div>\n {!narrow && (\n <div className=\"aegis-detail-beside__side\">\n <div ref={spacerRef} />\n <div ref={detailRef} className=\"aegis-detail-beside__detail\">\n {isolated}\n </div>\n </div>\n )}\n </div>\n </DetailContext.Provider>\n </SelectedRowDetailContext.Provider>\n );\n}\n"],"names":["NARROW_QUERY","DetailContext","createContext","revealDistance","row","ceiling","height","inset","view","top","toRow","InlineDetail","boxRef","detail","useContext","jsx","DetailBeside","columns","children","revealKey","scrollContainer","className","narrow","useMediaQuery","busy","setBusy","useState","listRef","useRef","spacerRef","detailRef","rowRef","followRef","revealedAtRef","revealKeyRef","revealedKeyRef","shownRef","place","useCallback","box","spacer","rowBox","reveal","distance","viewBoundsOf","scroller","scrollerOf","revealSoon","placeRow","fresh","awaitRow","useIsomorphicLayoutEffect","rendered","list","observer","activate","event","useEffect","target","scrolled","inline","useMemo","slot","isolated","SelectedRowDetailContext","cls","jsxs"],"mappings":";;;;;;;AAkEA,MAAMA,IAAe,sBAMfC,IAAgBC,EAAyB,IAAI;AAOnD,SAASC,EACPC,GACAC,GACAC,GACAC,GACAC,GACQ;AACR,QAAMC,IAAMD,EAAK,MAAMD,GACjBG,IACJN,EAAI,MAAMK,IAAML,EAAI,MAAMK,IAAM,KAAK,IAAIL,EAAI,SAASI,EAAK,QAAQ,CAAC;AACtE,SAAO,KAAK,IAAIE,GAAOL,IAAUC,IAASE,EAAK,MAAM;AACvD;AAGA,SAASG,EAAa,EAAE,QAAAC,KAAiD;AACvE,QAAMC,IAASC,EAAWb,CAAa;AACvC,SACE,gBAAAc,EAAC,SAAI,KAAKH,G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OD;AAAA,IACX,OAA0B,EAAE,UAAAb,GAAU,UAAAE,GAAU,QAAAU;IAChD,CAACZ,GAAUE,GAAUU,CAAM;AAAA,EAAA,GAEvBG,IACJ,gBAAAhD,EAACiD,EAAyB,UAAzB,EAAkC,OAAO,MACvC,UAAAnD,GACH,GAGIoD,IAAM,CAAC,uBAAuB5C,KAAa,EAAE,EAChD,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,SACE,gBAAAN,EAACiD,EAAyB,UAAzB,EAAkC,OAAOF,GACxC,UAAA,gBAAA/C,EAACd,EAAc,UAAd,EAAuB,OAAO8D,GAC7B,UAAA,gBAAAG;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWD;AAAA,MACX,OAAO,EAAE,iCAAiChD,EAAA;AAAA,MAC1C,aAAWO,KAAQ;AAAA,MAEnB,UAAA;AAAA,QAAA,gBAAAT,EAAC,OAAA,EAAI,KAAKY,GAAS,WAAU,6BAC1B,UAAAT,GACH;AAAA,QACC,CAACI,KACA,gBAAA4C,EAAC,OAAA,EAAI,WAAU,6BACb,UAAA;AAAA,UAAA,gBAAAnD,EAAC,OAAA,EAAI,KAAKc,EAAA,CAAW;AAAA,4BACpB,OAAA,EAAI,KAAKC,GAAW,WAAU,+BAC5B,UAAAiC,EAAA,CACH;AAAA,QAAA,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAGN,EAAA,CACF;AAEJ;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),_=require("react"),Y=require("@ant-design/icons"),G=require("../../hooks/useMediaQuery.cjs"),J=require("./EmptyState.cjs");;/* empty css */const X=require("./selectedRowDetail.cjs"),Z=require("../../locale/useStrings.cjs"),ee="(max-width: 768px)",T="data-aegis-tree-table-row",te="data-aegis-tree-table-caret",re='a, button, input, select, textarea, label, [role="button"], [role="link"], [role="checkbox"]';function se(r){return r===void 0?"minmax(0, 1fr)":typeof r=="number"?`${String(r)}px`:r}function q(r,i,a,o,h=[]){for(const l of r){const c=a(l);if(c===i)return h;const d=q(o(l)??[],i,a,o,[...h,c]);if(d.length>0)return d}return[]}function I(r,i,a,o,h=null,l=0,c=[]){return r.forEach((d,f)=>{const g=a(d),m=o(d)??[];c.push({row:d,key:g,parentKey:h,depth:l,position:f+1,siblings:r.length,hasChildren:m.length>0}),m.length>0&&i.has(g)&&I(m,i,a,o,g,l+1,c)}),c}function ae(r,i){if(window.getSelection()?.type==="Range")return!0;const a=r.closest(re);return a!==null&&i.contains(a)}function ne({row:r,rowKey:i,depth:a,position:o,siblings:h,hasChildren:l,expanded:c,selectable:d,selected:f,tabbable:g,folded:m,columns:R,placeRow:v}){const N={expanded:l&&c},A=["aegis-tree-table__row",d?"aegis-tree-table__row--selectable":"",f?"aegis-tree-table__row--selected":""].filter(Boolean).join(" ");return n.jsx("div",{ref:v,className:A,role:"row","data-aegis-tree-table-row":i,"aria-level":a+1,"aria-posinset":o,"aria-setsize":h,"aria-expanded":l?c:void 0,"aria-selected":d?f:void 0,tabIndex:g?0:-1,style:{"--aegis-tree-table-depth":a},children:R.map((b,p)=>{const w=["aegis-tree-table__cell",p===0?"aegis-tree-table__cell--tree":"",b.numeric?"aegis-tree-table__cell--numeric":"",b.truncate?"aegis-tree-table__cell--truncate":""].filter(Boolean).join(" ");return n.jsxs("div",{className:w,role:"gridcell",children:[p===0&&n.jsx("span",{className:"aegis-tree-table__caret","aria-hidden":"true","data-aegis-tree-table-caret":l?"":void 0,children:l&&n.jsx(Y.RightOutlined,{className:"aegis-tree-table__chevron"})}),m&&p>0&&n.jsx("span",{className:"aegis-tree-table__label",children:b.header}),n.jsx("div",{className:"aegis-tree-table__content",children:b.render(r,N)})]},b.key)})})}const ie=_.memo(ne);function le({columns:r,data:i,rowKey:a,getSubRows:o,ariaLabel:h,expandedKeys:l,defaultExpandedKeys:c=[],onExpandedKeysChange:d,selectedKey:f,onSelect:g,emptyTitle:m,emptyDescription:R,framed:v=!0,className:N}){const A=Z.useStrings(),b=G.useMediaQuery(ee),p=_.useContext(X.SelectedRowDetailContext),w=_.useRef(null),x=f??null,[D,O]=_.useState(()=>[...c,...x===null?[]:q(i,x,a,o)]),[B,F]=_.useState(x);x!==B&&(F(x),x!==null&&O([...new Set([...D,...q(i,x,a,o)])]));const j=l??D,E=_.useMemo(()=>new Set(j),[j]),u=I(i,E,a,o),[K,L]=_.useState(),M=[K,f].find(e=>u.some(t=>t.key===e))??u[0]?.key,U=g!==void 0||f!==void 0,C=(e,t)=>{const s=t?[...j,e]:j.filter(y=>y!==e);l===void 0&&O(s),d?.(s)},S=e=>{if(!(e instanceof Element))return-1;const t=e.closest(`[${T}]`);if(t===null||t.parentElement!==w.current)return-1;const s=t.getAttribute(T);return u.findIndex(y=>y.key===s)},k=e=>{const t=w.current?.querySelectorAll(`:scope > [${T}]`).item(e);t instanceof HTMLElement&&t.focus()},$=e=>{const t=S(e.target);if(t<0||!(e.target instanceof Element))return;const s=u[t];e.target.closest(`[${te}]`)!==null?C(s.key,!E.has(s.key)):ae(e.target,e.currentTarget)||g?.(s.row)},Q=e=>{const t=S(e.target);if(t<0||!(e.target instanceof Element)||!e.target.hasAttribute(T))return;const s=u[t],y=s.hasChildren&&E.has(s.key);switch(e.key){case"ArrowDown":k(t+1);break;case"ArrowUp":k(t-1);break;case"Home":k(0);break;case"End":k(u.length-1);break;case"ArrowRight":y?k(t+1):s.hasChildren&&C(s.key,!0);break;case"ArrowLeft":if(y)C(s.key,!1);else if(s.parentKey!==null){const{parentKey:V}=s;k(u.findIndex(W=>W.key===V))}break;case"Enter":case" ":g?.(s.row);break;default:return}e.preventDefault()},H=e=>{const t=S(e.target);t>=0&&e.target.hasAttribute(T)&&L(u[t].key)},z=["aegis-tree-table",v?"aegis-tree-table--framed":"",b?"aegis-tree-table--folded":"",N??""].filter(Boolean).join(" "),P={"--aegis-tree-table-columns":r.map(e=>se(e.width)).join(" ")};return n.jsxs("div",{className:z,style:P,children:[n.jsxs("div",{ref:w,className:"aegis-tree-table__grid",role:"treegrid","aria-label":h,tabIndex:-1,onClick:$,onKeyDown:Q,onFocus:H,children:[!b&&n.jsx("div",{className:"aegis-tree-table__head",role:"row",children:r.map(e=>n.jsx("div",{className:e.numeric?"aegis-tree-table__th aegis-tree-table__th--numeric":"aegis-tree-table__th",role:"columnheader",children:e.header},e.key))}),u.map(e=>{const t=f===e.key;return n.jsxs(_.Fragment,{children:[n.jsx(ie,{row:e.row,rowKey:e.key,depth:e.depth,position:e.position,siblings:e.siblings,hasChildren:e.hasChildren,expanded:E.has(e.key),selectable:U,selected:t,tabbable:e.key===M,folded:b,columns:r,placeRow:t?p?.placeRow:void 0}),t&&p?.inline?n.jsx("div",{className:"aegis-tree-table__inline",role:"row",children:n.jsx("div",{role:"gridcell",children:p.inline})}):null]},e.key)})]}),u.length===0&&n.jsx(J.EmptyState,{title:m??A.noData,description:R})]})}exports.TreeTable=le;
|
|
2
|
+
//# sourceMappingURL=TreeTable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeTable.cjs","sources":["../../../src/components/ui/TreeTable.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FocusEvent,\n Fragment,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n memo,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport { useStrings } from '../../locale';\nimport { EmptyState } from './EmptyState';\nimport './TreeTable.css';\nimport { SelectedRowDetailContext } from './selectedRowDetail';\n\n/** What a cell can know of its row beyond the row itself. */\nexport interface TreeTableRowState {\n /** The row has children and they are shown. */\n expanded: boolean;\n}\n\nexport interface TreeTableColumn<T> {\n key: string;\n header: ReactNode;\n /**\n * The column's track in the grid every row shares: a number of px, or any\n * `grid-template-columns` track such as `'minmax(0, 2fr)'`. Default\n * `minmax(0, 1fr)`. Rows never measure their cells, so a long cell wraps\n * or truncates instead of widening its column.\n */\n width?: number | string;\n /** Number column: header and cells right-aligned, figures in tabular widths. */\n numeric?: boolean;\n /** Cuts the cell off with an ellipsis on one line instead of wrapping it. */\n truncate?: boolean;\n render: (row: T, state: TreeTableRowState) => ReactNode;\n}\n\nexport interface TreeTableProps<T> {\n /**\n * The columns; the first draws each row's indent and expand caret. Keep\n * the array the same between renders, e.g. from `useMemo`, so a large\n * tree redraws only the rows that change.\n */\n columns: Array<TreeTableColumn<T>>;\n /** The top-level rows, in the order they are drawn. */\n data: T[];\n rowKey: (row: T) => string;\n /** A row's children in the order they are drawn; empty or undefined for a leaf. */\n getSubRows: (row: T) => T[] | undefined;\n /** The table's accessible name. */\n ariaLabel: string;\n /** The open rows. Omit it to let the table track them. */\n expandedKeys?: string[];\n /** Rows open on first render when `expandedKeys` is omitted. */\n defaultExpandedKeys?: string[];\n /** Called with the open rows whenever one opens or closes. */\n onExpandedKeysChange?: (keys: string[]) => void;\n /**\n * The selected row: `aria-selected`, drawn selected, and followed by an\n * enclosing `DetailBeside`. Whenever it changes, the rows above it open,\n * unless `expandedKeys` controls them.\n */\n selectedKey?: string | null;\n /** Called with a row when it is clicked or activated with Enter or Space. */\n onSelect?: (row: T) => void;\n emptyTitle?: string;\n emptyDescription?: string;\n /**\n * Draws the table as its own card, as `DataTable` does. Default true.\n * Pass false where a container already frames it.\n */\n framed?: boolean;\n className?: string;\n}\n\ninterface VisibleRow<T> {\n row: T;\n key: string;\n parentKey: string | null;\n depth: number;\n /** 1-based position among its siblings. */\n position: number;\n siblings: number;\n hasChildren: boolean;\n}\n\nconst FOLDED_QUERY = '(max-width: 768px)';\nconst ROW_ATTRIBUTE = 'data-aegis-tree-table-row';\nconst CARET_ATTRIBUTE = 'data-aegis-tree-table-caret';\nconst CONTROL_SELECTOR =\n 'a, button, input, select, textarea, label, [role=\"button\"], [role=\"link\"], [role=\"checkbox\"]';\n\nfunction track(width: number | string | undefined): string {\n if (width === undefined) {\n return 'minmax(0, 1fr)';\n }\n return typeof width === 'number' ? `${String(width)}px` : width;\n}\n\n/** The keys of the rows above the row `key`, outermost first; empty when no row has it. */\nfunction ancestorKeys<T>(\n rows: T[],\n key: string,\n rowKey: (row: T) => string,\n getSubRows: (row: T) => T[] | undefined,\n above: string[] = [],\n): string[] {\n for (const row of rows) {\n const own = rowKey(row);\n if (own === key) {\n return above;\n }\n const found = ancestorKeys(getSubRows(row) ?? [], key, rowKey, getSubRows, [\n ...above,\n own,\n ]);\n if (found.length > 0) {\n return found;\n }\n }\n return [];\n}\n\nfunction visibleRows<T>(\n rows: T[],\n open: ReadonlySet<string>,\n rowKey: (row: T) => string,\n getSubRows: (row: T) => T[] | undefined,\n parentKey: string | null = null,\n depth = 0,\n out: Array<VisibleRow<T>> = [],\n): Array<VisibleRow<T>> {\n rows.forEach((row, index) => {\n const key = rowKey(row);\n const children = getSubRows(row) ?? [];\n out.push({\n row,\n key,\n parentKey,\n depth,\n position: index + 1,\n siblings: rows.length,\n hasChildren: children.length > 0,\n });\n if (children.length > 0 && open.has(key)) {\n visibleRows(children, open, rowKey, getSubRows, key, depth + 1, out);\n }\n });\n return out;\n}\n\n/** True when the click belongs to a control inside the row, or ends a text selection. */\nfunction isOwnedByControl(target: Element, row: Element): boolean {\n if (window.getSelection()?.type === 'Range') {\n return true;\n }\n const control = target.closest(CONTROL_SELECTOR);\n return control !== null && row.contains(control);\n}\n\ninterface TreeTableRowProps<T> {\n row: T;\n rowKey: string;\n depth: number;\n position: number;\n siblings: number;\n hasChildren: boolean;\n expanded: boolean;\n selectable: boolean;\n selected: boolean;\n tabbable: boolean;\n folded: boolean;\n columns: Array<TreeTableColumn<T>>;\n placeRow: ((row: HTMLElement | null) => void) | undefined;\n}\n\nfunction TreeTableRowView<T>({\n row,\n rowKey,\n depth,\n position,\n siblings,\n hasChildren,\n expanded,\n selectable,\n selected,\n tabbable,\n folded,\n columns,\n placeRow,\n}: TreeTableRowProps<T>): ReactElement {\n const state: TreeTableRowState = { expanded: hasChildren && expanded };\n const cls = [\n 'aegis-tree-table__row',\n selectable ? 'aegis-tree-table__row--selectable' : '',\n selected ? 'aegis-tree-table__row--selected' : '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <div\n ref={placeRow}\n className={cls}\n role=\"row\"\n data-aegis-tree-table-row={rowKey}\n aria-level={depth + 1}\n aria-posinset={position}\n aria-setsize={siblings}\n aria-expanded={hasChildren ? expanded : undefined}\n aria-selected={selectable ? selected : undefined}\n tabIndex={tabbable ? 0 : -1}\n style={{ '--aegis-tree-table-depth': depth } as CSSProperties}\n >\n {columns.map((column, index) => {\n const cellCls = [\n 'aegis-tree-table__cell',\n index === 0 ? 'aegis-tree-table__cell--tree' : '',\n column.numeric ? 'aegis-tree-table__cell--numeric' : '',\n column.truncate ? 'aegis-tree-table__cell--truncate' : '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <div key={column.key} className={cellCls} role=\"gridcell\">\n {index === 0 && (\n <span\n className=\"aegis-tree-table__caret\"\n aria-hidden=\"true\"\n data-aegis-tree-table-caret={hasChildren ? '' : undefined}\n >\n {hasChildren && (\n <RightOutlined className=\"aegis-tree-table__chevron\" />\n )}\n </span>\n )}\n {folded && index > 0 && (\n <span className=\"aegis-tree-table__label\">{column.header}</span>\n )}\n <div className=\"aegis-tree-table__content\">\n {column.render(row, state)}\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n\nconst TreeTableRow = memo(TreeTableRowView) as typeof TreeTableRowView;\n\n/**\n * A table whose rows form a tree: each row's first cell carries its indent\n * and a caret that opens its children, and every row shares the columns.\n * For assistive technology it is a treegrid with one tab stop: ↑ ↓ Home\n * End move between rows, → opens a row or moves into it, ← closes it or\n * moves to its parent, and Enter or Space selects. At 768 px and below each\n * row folds: its first cell on top, the other cells under it, each named by\n * its header, and a cell that draws nothing left out. Inside a\n * `DetailBeside` the selected row carries the detail.\n */\nexport function TreeTable<T>({\n columns,\n data,\n rowKey,\n getSubRows,\n ariaLabel,\n expandedKeys,\n defaultExpandedKeys = [],\n onExpandedKeysChange,\n selectedKey,\n onSelect,\n emptyTitle,\n emptyDescription,\n framed = true,\n className,\n}: TreeTableProps<T>) {\n const strings = useStrings();\n const folded = useMediaQuery(FOLDED_QUERY);\n const selection = useContext(SelectedRowDetailContext);\n const gridRef = useRef<HTMLDivElement>(null);\n const revealTarget = selectedKey ?? null;\n const [trackedKeys, setTrackedKeys] = useState<string[]>(() => [\n ...defaultExpandedKeys,\n ...(revealTarget === null\n ? []\n : ancestorKeys(data, revealTarget, rowKey, getSubRows)),\n ]);\n const [revealedKey, setRevealedKey] = useState(revealTarget);\n if (revealTarget !== revealedKey) {\n setRevealedKey(revealTarget);\n if (revealTarget !== null) {\n setTrackedKeys([\n ...new Set([\n ...trackedKeys,\n ...ancestorKeys(data, revealTarget, rowKey, getSubRows),\n ]),\n ]);\n }\n }\n const openKeys = expandedKeys ?? trackedKeys;\n const open = useMemo(() => new Set(openKeys), [openKeys]);\n const rows = visibleRows(data, open, rowKey, getSubRows);\n const [focusedKey, setFocusedKey] = useState<string>();\n const tabStop =\n [focusedKey, selectedKey].find((key) =>\n rows.some((entry) => entry.key === key),\n ) ?? rows[0]?.key;\n const selectable = onSelect !== undefined || selectedKey !== undefined;\n\n const setExpanded = (key: string, value: boolean): void => {\n const next = value\n ? [...openKeys, key]\n : openKeys.filter((item) => item !== key);\n if (expandedKeys === undefined) {\n setTrackedKeys(next);\n }\n onExpandedKeysChange?.(next);\n };\n\n /** The index of the table's own row an event came from; -1 for anything else, such as a detail among the rows. */\n const rowIndexOf = (target: EventTarget): number => {\n if (!(target instanceof Element)) {\n return -1;\n }\n const element = target.closest(`[${ROW_ATTRIBUTE}]`);\n if (element === null || element.parentElement !== gridRef.current) {\n return -1;\n }\n const key = element.getAttribute(ROW_ATTRIBUTE);\n return rows.findIndex((entry) => entry.key === key);\n };\n\n const focusRow = (index: number): void => {\n const element = gridRef.current\n ?.querySelectorAll(`:scope > [${ROW_ATTRIBUTE}]`)\n .item(index);\n if (element instanceof HTMLElement) {\n element.focus();\n }\n };\n\n const handleClick = (event: MouseEvent<HTMLDivElement>): void => {\n const index = rowIndexOf(event.target);\n if (index < 0 || !(event.target instanceof Element)) {\n return;\n }\n const entry = rows[index];\n if (event.target.closest(`[${CARET_ATTRIBUTE}]`) !== null) {\n setExpanded(entry.key, !open.has(entry.key));\n } else if (!isOwnedByControl(event.target, event.currentTarget)) {\n onSelect?.(entry.row);\n }\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n const index = rowIndexOf(event.target);\n // Keys typed into a control inside a row stay the control's.\n if (\n index < 0 ||\n !(event.target instanceof Element) ||\n !event.target.hasAttribute(ROW_ATTRIBUTE)\n ) {\n return;\n }\n const entry = rows[index];\n const expanded = entry.hasChildren && open.has(entry.key);\n switch (event.key) {\n case 'ArrowDown':\n focusRow(index + 1);\n break;\n case 'ArrowUp':\n focusRow(index - 1);\n break;\n case 'Home':\n focusRow(0);\n break;\n case 'End':\n focusRow(rows.length - 1);\n break;\n case 'ArrowRight':\n if (expanded) {\n focusRow(index + 1);\n } else if (entry.hasChildren) {\n setExpanded(entry.key, true);\n }\n break;\n case 'ArrowLeft':\n if (expanded) {\n setExpanded(entry.key, false);\n } else if (entry.parentKey !== null) {\n const { parentKey } = entry;\n focusRow(rows.findIndex((each) => each.key === parentKey));\n }\n break;\n case 'Enter':\n case ' ':\n onSelect?.(entry.row);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const handleFocus = (event: FocusEvent<HTMLDivElement>): void => {\n const index = rowIndexOf(event.target);\n if (index >= 0 && event.target.hasAttribute(ROW_ATTRIBUTE)) {\n setFocusedKey(rows[index].key);\n }\n };\n\n const cls = [\n 'aegis-tree-table',\n framed ? 'aegis-tree-table--framed' : '',\n folded ? 'aegis-tree-table--folded' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const style = {\n '--aegis-tree-table-columns': columns\n .map((column) => track(column.width))\n .join(' '),\n } as CSSProperties;\n\n return (\n <div className={cls} style={style}>\n <div\n ref={gridRef}\n className=\"aegis-tree-table__grid\"\n role=\"treegrid\"\n aria-label={ariaLabel}\n tabIndex={-1}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n >\n {!folded && (\n <div className=\"aegis-tree-table__head\" role=\"row\">\n {columns.map((column) => (\n <div\n key={column.key}\n className={\n column.numeric\n ? 'aegis-tree-table__th aegis-tree-table__th--numeric'\n : 'aegis-tree-table__th'\n }\n role=\"columnheader\"\n >\n {column.header}\n </div>\n ))}\n </div>\n )}\n {rows.map((entry) => {\n const selected = selectedKey === entry.key;\n return (\n <Fragment key={entry.key}>\n <TreeTableRow\n row={entry.row}\n rowKey={entry.key}\n depth={entry.depth}\n position={entry.position}\n siblings={entry.siblings}\n hasChildren={entry.hasChildren}\n expanded={open.has(entry.key)}\n selectable={selectable}\n selected={selected}\n tabbable={entry.key === tabStop}\n folded={folded}\n columns={columns}\n placeRow={selected ? selection?.placeRow : undefined}\n />\n {selected && selection?.inline ? (\n <div className=\"aegis-tree-table__inline\" role=\"row\">\n <div role=\"gridcell\">{selection.inline}</div>\n </div>\n ) : null}\n </Fragment>\n );\n })}\n </div>\n {rows.length === 0 && (\n <EmptyState\n title={emptyTitle ?? strings.noData}\n description={emptyDescription}\n />\n )}\n </div>\n );\n}\n"],"names":["FOLDED_QUERY","ROW_ATTRIBUTE","CARET_ATTRIBUTE","CONTROL_SELECTOR","track","width","ancestorKeys","rows","key","rowKey","getSubRows","above","row","own","found","visibleRows","open","parentKey","depth","out","index","children","isOwnedByControl","target","control","TreeTableRowView","position","siblings","hasChildren","expanded","selectable","selected","tabbable","folded","columns","placeRow","state","cls","jsx","column","cellCls","jsxs","RightOutlined","TreeTableRow","memo","TreeTable","data","ariaLabel","expandedKeys","defaultExpandedKeys","onExpandedKeysChange","selectedKey","onSelect","emptyTitle","emptyDescription","framed","className","strings","useStrings","useMediaQuery","selection","useContext","SelectedRowDetailContext","gridRef","useRef","revealTarget","trackedKeys","setTrackedKeys","useState","revealedKey","setRevealedKey","openKeys","useMemo","focusedKey","setFocusedKey","tabStop","entry","setExpanded","value","next","item","rowIndexOf","element","focusRow","handleClick","event","handleKeyDown","each","handleFocus","style","Fragment","EmptyState"],"mappings":"mWA+FMA,GAAe,qBACfC,EAAgB,4BAChBC,GAAkB,8BAClBC,GACJ,+FAEF,SAASC,GAAMC,EAA4C,CACzD,OAAIA,IAAU,OACL,iBAEF,OAAOA,GAAU,SAAW,GAAG,OAAOA,CAAK,CAAC,KAAOA,CAC5D,CAGA,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EAAkB,GACR,CACV,UAAWC,KAAOL,EAAM,CACtB,MAAMM,EAAMJ,EAAOG,CAAG,EACtB,GAAIC,IAAQL,EACV,OAAOG,EAET,MAAMG,EAAQR,EAAaI,EAAWE,CAAG,GAAK,GAAIJ,EAAKC,EAAQC,EAAY,CACzE,GAAGC,EACHE,CAAA,CACD,EACD,GAAIC,EAAM,OAAS,EACjB,OAAOA,CAEX,CACA,MAAO,CAAA,CACT,CAEA,SAASC,EACPR,EACAS,EACAP,EACAC,EACAO,EAA2B,KAC3BC,EAAQ,EACRC,EAA4B,CAAA,EACN,CACtB,OAAAZ,EAAK,QAAQ,CAACK,EAAKQ,IAAU,CAC3B,MAAMZ,EAAMC,EAAOG,CAAG,EAChBS,EAAWX,EAAWE,CAAG,GAAK,CAAA,EACpCO,EAAI,KAAK,CACP,IAAAP,EACA,IAAAJ,EACA,UAAAS,EACA,MAAAC,EACA,SAAUE,EAAQ,EAClB,SAAUb,EAAK,OACf,YAAac,EAAS,OAAS,CAAA,CAChC,EACGA,EAAS,OAAS,GAAKL,EAAK,IAAIR,CAAG,GACrCO,EAAYM,EAAUL,EAAMP,EAAQC,EAAYF,EAAKU,EAAQ,EAAGC,CAAG,CAEvE,CAAC,EACMA,CACT,CAGA,SAASG,GAAiBC,EAAiBX,EAAuB,CAChE,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AU,yBACV,KAAK,WACL,aAAYhB,EACZ,SAAU,GACV,QAASqC,EACT,UAAWE,EACX,QAASE,EAER,SAAA,CAAA,CAACvD,GACAK,EAAAA,IAAC,MAAA,CAAI,UAAU,yBAAyB,KAAK,MAC1C,SAAAJ,EAAQ,IAAKK,GACZD,EAAAA,IAAC,MAAA,CAEC,UACEC,EAAO,QACH,qDACA,uBAEN,KAAK,eAEJ,SAAAA,EAAO,MAAA,EARHA,EAAO,GAAA,CAUf,EACH,EAEDhC,EAAK,IAAKqE,GAAU,CACnB,MAAM7C,EAAWoB,IAAgByB,EAAM,IACvC,cACGc,WAAA,CACC,SAAA,CAAApD,EAAAA,IAACK,GAAA,CACC,IAAKiC,EAAM,IACX,OAAQA,EAAM,IACd,MAAOA,EAAM,MACb,SAAUA,EAAM,SAChB,SAAUA,EAAM,SAChB,YAAaA,EAAM,YACnB,SAAU5D,EAAK,IAAI4D,EAAM,GAAG,EAC5B,WAAA9C,EACA,SAAAC,EACA,SAAU6C,EAAM,MAAQD,EACxB,OAAA1C,EACA,QAAAC,EACA,SAAUH,EAAW6B,GAAW,SAAW,MAAA,CAAA,EAE5C7B,GAAY6B,GAAW,OACtBtB,EAAAA,IAAC,MAAA,CAAI,UAAU,2BAA2B,KAAK,MAC7C,SAAAA,MAAC,OAAI,KAAK,WAAY,SAAAsB,EAAU,OAAO,EACzC,EACE,IAAA,CAAA,EApBSgB,EAAM,GAqBrB,CAEJ,CAAC,CAAA,CAAA,CAAA,EAEFrE,EAAK,SAAW,GACf+B,EAAAA,IAACqD,EAAAA,WAAA,CACC,MAAOtC,GAAcI,EAAQ,OAC7B,YAAaH,CAAA,CAAA,CACf,EAEJ,CAEJ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
/** What a cell can know of its row beyond the row itself. */
|
|
3
|
+
export interface TreeTableRowState {
|
|
4
|
+
/** The row has children and they are shown. */
|
|
5
|
+
expanded: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface TreeTableColumn<T> {
|
|
8
|
+
key: string;
|
|
9
|
+
header: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* The column's track in the grid every row shares: a number of px, or any
|
|
12
|
+
* `grid-template-columns` track such as `'minmax(0, 2fr)'`. Default
|
|
13
|
+
* `minmax(0, 1fr)`. Rows never measure their cells, so a long cell wraps
|
|
14
|
+
* or truncates instead of widening its column.
|
|
15
|
+
*/
|
|
16
|
+
width?: number | string;
|
|
17
|
+
/** Number column: header and cells right-aligned, figures in tabular widths. */
|
|
18
|
+
numeric?: boolean;
|
|
19
|
+
/** Cuts the cell off with an ellipsis on one line instead of wrapping it. */
|
|
20
|
+
truncate?: boolean;
|
|
21
|
+
render: (row: T, state: TreeTableRowState) => ReactNode;
|
|
22
|
+
}
|
|
23
|
+
export interface TreeTableProps<T> {
|
|
24
|
+
/**
|
|
25
|
+
* The columns; the first draws each row's indent and expand caret. Keep
|
|
26
|
+
* the array the same between renders, e.g. from `useMemo`, so a large
|
|
27
|
+
* tree redraws only the rows that change.
|
|
28
|
+
*/
|
|
29
|
+
columns: Array<TreeTableColumn<T>>;
|
|
30
|
+
/** The top-level rows, in the order they are drawn. */
|
|
31
|
+
data: T[];
|
|
32
|
+
rowKey: (row: T) => string;
|
|
33
|
+
/** A row's children in the order they are drawn; empty or undefined for a leaf. */
|
|
34
|
+
getSubRows: (row: T) => T[] | undefined;
|
|
35
|
+
/** The table's accessible name. */
|
|
36
|
+
ariaLabel: string;
|
|
37
|
+
/** The open rows. Omit it to let the table track them. */
|
|
38
|
+
expandedKeys?: string[];
|
|
39
|
+
/** Rows open on first render when `expandedKeys` is omitted. */
|
|
40
|
+
defaultExpandedKeys?: string[];
|
|
41
|
+
/** Called with the open rows whenever one opens or closes. */
|
|
42
|
+
onExpandedKeysChange?: (keys: string[]) => void;
|
|
43
|
+
/**
|
|
44
|
+
* The selected row: `aria-selected`, drawn selected, and followed by an
|
|
45
|
+
* enclosing `DetailBeside`. Whenever it changes, the rows above it open,
|
|
46
|
+
* unless `expandedKeys` controls them.
|
|
47
|
+
*/
|
|
48
|
+
selectedKey?: string | null;
|
|
49
|
+
/** Called with a row when it is clicked or activated with Enter or Space. */
|
|
50
|
+
onSelect?: (row: T) => void;
|
|
51
|
+
emptyTitle?: string;
|
|
52
|
+
emptyDescription?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Draws the table as its own card, as `DataTable` does. Default true.
|
|
55
|
+
* Pass false where a container already frames it.
|
|
56
|
+
*/
|
|
57
|
+
framed?: boolean;
|
|
58
|
+
className?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A table whose rows form a tree: each row's first cell carries its indent
|
|
62
|
+
* and a caret that opens its children, and every row shares the columns.
|
|
63
|
+
* For assistive technology it is a treegrid with one tab stop: ↑ ↓ Home
|
|
64
|
+
* End move between rows, → opens a row or moves into it, ← closes it or
|
|
65
|
+
* moves to its parent, and Enter or Space selects. At 768 px and below each
|
|
66
|
+
* row folds: its first cell on top, the other cells under it, each named by
|
|
67
|
+
* its header, and a cell that draws nothing left out. Inside a
|
|
68
|
+
* `DetailBeside` the selected row carries the detail.
|
|
69
|
+
*/
|
|
70
|
+
export declare function TreeTable<T>({ columns, data, rowKey, getSubRows, ariaLabel, expandedKeys, defaultExpandedKeys, onExpandedKeysChange, selectedKey, onSelect, emptyTitle, emptyDescription, framed, className, }: TreeTableProps<T>): import("react/jsx-runtime").JSX.Element;
|