@lincyaw/aegis-ui 0.12.0 → 0.13.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/DataTable.cjs +1 -1
- package/dist/components/ui/DataTable.cjs.map +1 -1
- package/dist/components/ui/DataTable.js +205 -207
- package/dist/components/ui/DataTable.js.map +1 -1
- package/dist/components/ui/DetailBeside.cjs +2 -0
- package/dist/components/ui/DetailBeside.cjs.map +1 -0
- package/dist/components/ui/DetailBeside.d.ts +37 -0
- package/dist/components/ui/DetailBeside.js +113 -0
- package/dist/components/ui/DetailBeside.js.map +1 -0
- package/dist/components/ui/FileTree.cjs +1 -1
- package/dist/components/ui/FileTree.cjs.map +1 -1
- package/dist/components/ui/FileTree.js +118 -111
- package/dist/components/ui/FileTree.js.map +1 -1
- package/dist/components/ui/ServiceMap.cjs +1 -1
- package/dist/components/ui/ServiceMap.cjs.map +1 -1
- package/dist/components/ui/ServiceMap.js +305 -262
- package/dist/components/ui/ServiceMap.js.map +1 -1
- package/dist/components/ui/TraceTree.cjs +1 -1
- package/dist/components/ui/TraceTree.cjs.map +1 -1
- package/dist/components/ui/TraceTree.js +182 -178
- package/dist/components/ui/TraceTree.js.map +1 -1
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/selectedRowDetail.cjs +2 -0
- package/dist/components/ui/selectedRowDetail.cjs.map +1 -0
- package/dist/components/ui/selectedRowDetail.d.ts +25 -0
- package/dist/components/ui/selectedRowDetail.js +8 -0
- package/dist/components/ui/selectedRowDetail.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +259 -257
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTable.js","sources":["../../../src/components/ui/DataTable.tsx"],"sourcesContent":["import {\n type CSSProperties,\n Fragment,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useDevelopAfterLoad } from '../../hooks/useDevelopAfterLoad';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport { useStrings } from '../../locale';\nimport { Checkbox } from './Checkbox';\nimport './DataTable.css';\nimport { EmptyState } from './EmptyState';\nimport { Pagination, type PaginationProps } from './Pagination';\nimport { Skeleton, SkeletonText } from './Skeleton';\nimport { useColumnWidths } from './useColumnWidths';\n\nexport type DataTableSurface<T> = PrimitiveSurface<T[]>;\n\n/** Background wash of one cell, e.g. a step on a pass-rate scale. */\nexport interface DataTableCellTone {\n tone: 'success' | 'info' | 'caution' | 'warning';\n /**\n * 1 (default) is the tone's soft background; each step up mixes in more\n * of the tone's accent, to 5.\n */\n step?: 1 | 2 | 3 | 4 | 5;\n}\n\nexport interface DataTableColumn<T> {\n key: string;\n header: ReactNode;\n /** Initial column width. Number → px, string → as-is (e.g. '20%'). */\n width?: number | string;\n /** Minimum width during resize / when content squeezes. Default 60px. */\n minWidth?: number;\n /** Maximum width during resize. */\n maxWidth?: number;\n align?: 'left' | 'center' | 'right';\n /**\n * Whether the cell should ellipsis-truncate long content. Default true.\n * Set false for action cells, chip rows, links and other focusable content\n * (the clip cuts off their focus ring), or anything with non-text content\n * that should keep its natural width without being clipped.\n */\n truncate?: boolean;\n /**\n * Gives the header a resize handle on its right edge, dragged with the\n * pointer or moved with the arrow keys. Default false.\n */\n resizable?: boolean;\n /**\n * `'actions'` lays the cell out as a right-aligned, gapped, wrapping row of\n * controls — return them straight from `render`. Overrides `align` and\n * `truncate`.\n */\n kind?: 'actions';\n /**\n * Number column: header and cells right-aligned, figures in\n * `--font-numeric` with tabular widths so digits and decimal points line\n * up. Overrides `align`.\n */\n numeric?: boolean;\n /** Washes a cell's background in a tone. Table rows only, not mobile cards. */\n cellTone?: (row: T, index: number) => DataTableCellTone | undefined;\n /**\n * Makes the header a sort control. With `sortValue` the table orders\n * the rows itself; without it the host orders `data` (for instance the\n * server, from a URL parameter) and the header only shows the state.\n */\n sortable?: boolean;\n /** The value the table sorts this column by; `null` sorts last either way. */\n sortValue?: (row: T) => number | string | null;\n /** The direction of a first click. Defaults to `desc` for numeric columns, `asc` otherwise. */\n firstSortDirection?: DataTableSortDirection;\n render: (row: T, index: number) => ReactNode;\n}\n\nexport type DataTableSortDirection = 'asc' | 'desc';\n\nexport interface DataTableSort {\n key: string;\n direction: DataTableSortDirection;\n}\n\n/**\n * Server-side pagination: `data` is the current page, never sliced here.\n * The table supplies the page's row count and disables the pager while\n * loading.\n */\nexport type DataTablePagination = Pick<\n PaginationProps,\n 'page' | 'pageSize' | 'total' | 'onChange' | 'pageSizeOptions'\n>;\n\ninterface DataTableProps<T> {\n columns: Array<DataTableColumn<T>>;\n data: T[];\n rowKey: (row: T, index: number) => string | number;\n /** The table's accessible name. */\n ariaLabel?: string;\n /** Draws skeleton rows, and marks the table busy. */\n loading?: boolean;\n emptyTitle?: string;\n emptyDescription?: string;\n emptyAction?: ReactNode;\n className?: string;\n /**\n * Draws the table as its own card: `--radius-lg`, hairline border and\n * resting shadow, with the header flush with the top and clipped by the\n * radius. Default true. Pass false where a container already frames the\n * table, e.g. a titled `Panel padded={false}`, a dialog or an expanded row.\n */\n framed?: boolean;\n /**\n * When set, resized column widths are persisted to localStorage under\n * `aegis-data-table:<persistKey>`. Use a stable key per table.\n */\n persistKey?: string;\n /** Renders a footer with page navigation under the table. */\n pagination?: DataTablePagination;\n /** Adds a leading checkbox column and drives `selectedKeys`. */\n selectable?: boolean;\n /**\n * The selected rows: `aria-selected` and drawn selected. Without\n * `selectable` there is no checkbox column, e.g. for the row whose\n * details show beside the table.\n */\n selectedKeys?: Array<string | number>;\n onSelectedKeysChange?: (keys: Array<string | number>) => void;\n /**\n * Makes rows expandable: a leading column of chevron toggles, and this\n * content full-width under each expanded row.\n */\n renderExpanded?: (row: T, index: number) => ReactNode;\n /** Controlled expanded row keys. Omit to let the table track them. */\n expandedKeys?: Array<string | number>;\n /** Rows expanded on mount when `expandedKeys` is omitted. */\n defaultExpandedKeys?: Array<string | number>;\n onExpandedKeysChange?: (keys: Array<string | number>) => void;\n /**\n * At ≤768 px, renders each row through this instead of the columns, as a\n * stacked list with no sideways scroll. Selection, expansion, row clicks,\n * loading, empty state and pagination keep working.\n */\n renderMobileCard?: (row: T, index: number) => ReactNode;\n /**\n * Makes rows clickable: pointer cursor, a muted hover background, a\n * trailing chevron, and Enter on a focused row. Links, buttons and form\n * controls inside a cell keep their own behaviour.\n */\n onRowClick?: (row: T, index: number) => void;\n /**\n * Keeps the first column (with the selection and expansion columns) in\n * view while the other columns scroll sideways. The first column takes\n * at most 40% of the table's visible width, truncating past it.\n */\n stickyFirstColumn?: boolean;\n /**\n * The rows are out of date, e.g. the previous page while the next one\n * loads: they stay in place, dimmed, and the table is marked busy.\n */\n stale?: boolean;\n /**\n * The sorted column and direction. Omit to let the table track it,\n * starting from `defaultSort`. Row indices passed to `render`,\n * `cellTone` and the other callbacks count in the sorted order.\n */\n sort?: DataTableSort | null;\n defaultSort?: DataTableSort;\n /** Called with the sort a header click asks for. */\n onSortChange?: (sort: DataTableSort) => void;\n surface?: DataTableSurface<T>;\n}\n\nconst SELECTION_WIDTH = 44;\nconst TOGGLE_WIDTH = 32;\nconst CHEVRON_WIDTH = 40;\n/** The widest a pinned first column renders; DataTable.css sets the share. */\nconst PINNED_MAX = 'var(--aegis-data-table-pinned-max)';\nconst MOBILE_QUERY = '(max-width: 768px)';\nconst CONTROL_SELECTOR =\n 'a, button, input, select, textarea, label, [role=\"button\"], [role=\"link\"], [role=\"checkbox\"]';\n\n/** True when the click belongs to a control inside the row, or ends a text selection. */\nfunction isOwnedByControl(event: MouseEvent<HTMLElement>): boolean {\n if (window.getSelection()?.type === 'Range') {\n return true;\n }\n const target = event.target;\n if (!(target instanceof Element)) {\n return false;\n }\n const control = target.closest(CONTROL_SELECTOR);\n return control !== null && event.currentTarget.contains(control);\n}\n\n/**\n * The rows ordered by `column`'s sort value, ties and nulls (last in\n * either direction) keeping their order; unchanged when the column has no\n * sort value, because then the host ordered them.\n */\nfunction sortRows<T>(\n data: T[],\n column: DataTableColumn<T> | undefined,\n direction: DataTableSortDirection,\n): T[] {\n const value = column?.sortValue;\n if (!value) {\n return data;\n }\n const sign = direction === 'asc' ? 1 : -1;\n return data\n .map((row, index) => {\n const v = value(row);\n return { row, index, v: typeof v === 'number' && isNaN(v) ? null : v };\n })\n .sort((a, b) => {\n if (a.v === null || b.v === null) {\n return a.v === b.v ? a.index - b.index : a.v === null ? 1 : -1;\n }\n const order =\n typeof a.v === 'number' && typeof b.v === 'number'\n ? a.v - b.v\n : String(a.v).localeCompare(String(b.v));\n return order === 0 ? a.index - b.index : order * sign;\n })\n .map((entry) => entry.row);\n}\n\nfunction SortIcon({\n direction,\n}: {\n direction: DataTableSortDirection | null;\n}): ReactNode {\n return (\n <svg\n className=\"aegis-data-table__sort-icon\"\n viewBox=\"0 0 12 12\"\n aria-hidden=\"true\"\n >\n <path\n className={\n direction === 'asc' ? 'aegis-data-table__sort-mark--on' : undefined\n }\n d=\"M3.5 5L6 2.5 8.5 5\"\n />\n <path\n className={\n direction === 'desc' ? 'aegis-data-table__sort-mark--on' : undefined\n }\n d=\"M3.5 7L6 9.5 8.5 7\"\n />\n </svg>\n );\n}\n\nexport function DataTable<T>({\n columns,\n data,\n rowKey,\n ariaLabel,\n loading = false,\n emptyTitle,\n emptyDescription,\n emptyAction,\n className,\n framed = true,\n persistKey,\n pagination,\n selectable = false,\n selectedKeys,\n onSelectedKeysChange,\n renderExpanded,\n expandedKeys,\n defaultExpandedKeys,\n onExpandedKeysChange,\n renderMobileCard,\n onRowClick,\n stickyFirstColumn = false,\n stale = false,\n sort,\n defaultSort,\n onSortChange,\n surface,\n}: DataTableProps<T>) {\n const strings = useStrings();\n const isMobile = useMediaQuery(MOBILE_QUERY);\n const detailIdPrefix = useId();\n const cardMode = renderMobileCard !== undefined && isMobile;\n const develop = useDevelopAfterLoad(loading);\n\n const [uncontrolledSort, setUncontrolledSort] =\n useState<DataTableSort | null>(defaultSort ?? null);\n const activeSort = sort === undefined ? uncontrolledSort : sort;\n const sortColumn = columns.find((col) => col.key === activeSort?.key);\n const rows = useMemo(\n () => sortRows(data, sortColumn, activeSort?.direction ?? 'asc'),\n [data, sortColumn, activeSort?.direction],\n );\n const requestSort = (col: DataTableColumn<T>): void => {\n const first: DataTableSortDirection =\n col.firstSortDirection ?? (col.numeric ? 'desc' : 'asc');\n const next: DataTableSort = {\n key: col.key,\n direction:\n activeSort?.key === col.key\n ? activeSort.direction === 'asc'\n ? 'desc'\n : 'asc'\n : first,\n };\n if (sort === undefined) {\n setUncontrolledSort(next);\n }\n onSortChange?.(next);\n };\n\n const selected = selectedKeys ?? [];\n const keys = rows.map((row, index) => rowKey(row, index));\n const selectedCount = keys.filter((key) => selected.includes(key)).length;\n const toggleRow = (key: string | number, checked: boolean): void => {\n onSelectedKeysChange?.(\n checked ? [...selected, key] : selected.filter((item) => item !== key),\n );\n };\n // Selections on other pages survive toggling the rows of this page.\n const togglePage = (checked: boolean): void => {\n const others = selected.filter((key) => !keys.includes(key));\n onSelectedKeysChange?.(checked ? [...others, ...keys] : others);\n };\n const selectionCell = (\n checked: boolean,\n onToggle: (next: boolean) => void,\n ) => (\n <Checkbox\n checked={checked}\n onChange={onToggle}\n ariaLabel={strings.selectRow}\n />\n );\n\n const [uncontrolledExpanded, setUncontrolledExpanded] = useState<\n Array<string | number>\n >(defaultExpandedKeys ?? []);\n const expanded = expandedKeys ?? uncontrolledExpanded;\n // A row's detail mounts the first time it opens and stays mounted, so\n // collapsing can animate instead of dropping the content at once.\n const [visited, setVisited] = useState(expanded);\n const unvisited = expanded.filter((key) => !visited.includes(key));\n if (unvisited.length > 0) {\n setVisited([...visited, ...unvisited]);\n }\n const toggleExpanded = (key: string | number): void => {\n const next = expanded.includes(key)\n ? expanded.filter((item) => item !== key)\n : [...expanded, key];\n if (expandedKeys === undefined) {\n setUncontrolledExpanded(next);\n }\n onExpandedKeysChange?.(next);\n };\n\n const tableRef = useRef<HTMLTableElement>(null);\n const wrapRef = useRef<HTMLDivElement>(null);\n\n const agentAttrs = usePrimitiveSurface(surface, data, 'table', wrapRef);\n const expandable = renderExpanded !== undefined;\n const clickable = onRowClick !== undefined;\n const leadWidth =\n (selectable ? SELECTION_WIDTH : 0) + (expandable ? TOGGLE_WIDTH : 0);\n const trailWidth = clickable ? CHEVRON_WIDTH : 0;\n const sticky = stickyFirstColumn && !cardMode;\n\n const columnWidths = useColumnWidths({\n columns,\n persistKey,\n leadWidth,\n trailWidth,\n firstColumnMax: sticky ? PINNED_MAX : undefined,\n tableRef,\n });\n\n const cls = [\n 'aegis-data-table',\n framed ? 'aegis-data-table--framed' : '',\n stale ? 'aegis-data-table--stale' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const fixedLayout = columnWidths.sized && !cardMode;\n const filler = fixedLayout && columnWidths.fillerStyle !== undefined;\n const bodyColumnCount =\n (cardMode ? 1 : columns.length) + (filler ? 1 : 0) + (clickable ? 1 : 0);\n const columnCount =\n bodyColumnCount + (selectable ? 1 : 0) + (expandable ? 1 : 0);\n const toggleLeft = selectable ? SELECTION_WIDTH : 0;\n\n /** Props of a leading selection or toggle cell, fixed in width so the sticky offsets line up. */\n const leadCellProps = (lead: 'select' | 'toggle', cell: 'th' | 'td') => ({\n className: [\n `aegis-data-table__${cell}`,\n `aegis-data-table__${lead}-cell`,\n sticky ? `aegis-data-table__${cell}--sticky` : '',\n ]\n .filter(Boolean)\n .join(' '),\n style: {\n width: lead === 'select' ? SELECTION_WIDTH : TOGGLE_WIDTH,\n left: sticky ? (lead === 'select' ? 0 : toggleLeft) : undefined,\n },\n });\n\n /** Classes of a header or body cell of data column `colIndex`. */\n const cellClass = (\n cell: 'th' | 'td',\n colIndex: number,\n tone?: DataTableCellTone,\n ): string => {\n const block = `aegis-data-table__${cell}`;\n const classes = [block];\n if (sticky && colIndex === 0) {\n classes.push(`${block}--sticky`, `${block}--pinned`);\n }\n if (tone !== undefined) {\n classes.push(\n 'aegis-data-table__td--tone',\n `aegis-data-table__td--tone-${tone.tone}`,\n );\n if (tone.step !== undefined && tone.step > 1) {\n classes.push(`aegis-data-table__td--step-${String(tone.step)}`);\n }\n }\n return classes.join(' ');\n };\n\n const columnAlign = (col: DataTableColumn<T>) =>\n col.kind === 'actions' || col.numeric === true\n ? 'right'\n : (col.align ?? 'left');\n\n const cellStyle = (\n col: DataTableColumn<T>,\n colIndex: number,\n ): CSSProperties => ({\n textAlign: columnAlign(col),\n left: sticky && colIndex === 0 ? leadWidth : undefined,\n });\n\n const renderCellContent = (col: DataTableColumn<T>, node: ReactNode) => {\n const classes = [\n 'aegis-data-table__cell',\n `aegis-data-table__cell--${columnAlign(col)}`,\n ];\n if (col.numeric) {\n classes.push('aegis-data-table__cell--numeric');\n }\n if (col.kind === 'actions') {\n classes.push('aegis-data-table__cell--actions');\n } else if (col.truncate ?? true) {\n classes.push('aegis-data-table__cell--truncate');\n }\n return <div className={classes.join(' ')}>{node}</div>;\n };\n\n const renderRowCells = (row: T, idx: number) =>\n cardMode ? (\n <td className=\"aegis-data-table__td aegis-data-table__card-cell\">\n {renderMobileCard(row, idx)}\n </td>\n ) : (\n columns.map((col, colIndex) => (\n <td\n key={col.key}\n className={cellClass('td', colIndex, col.cellTone?.(row, idx))}\n style={cellStyle(col, colIndex)}\n >\n {renderCellContent(col, col.render(row, idx))}\n </td>\n ))\n );\n\n const renderSkeletonCells = () =>\n cardMode ? (\n <td className=\"aegis-data-table__td aegis-data-table__card-cell\">\n <SkeletonText lines={2} />\n </td>\n ) : (\n columns.map((col, colIndex) => (\n <td\n key={col.key}\n className={cellClass('td', colIndex)}\n style={cellStyle(col, colIndex)}\n >\n {renderCellContent(\n col,\n <Skeleton width=\"80%\" height=\"var(--space-3)\" />,\n )}\n </td>\n ))\n );\n\n const fillerCell = filler && (\n <td className=\"aegis-data-table__td aegis-data-table__filler\" aria-hidden />\n );\n\n // The row itself takes the click, so the chevron column is not read.\n const chevronCell = clickable && (\n <td\n className=\"aegis-data-table__td aegis-data-table__chevron-cell\"\n aria-hidden\n >\n <RightOutlined className=\"aegis-data-table__chevron\" aria-hidden />\n </td>\n );\n\n const renderToggle = (key: string | number, detailId: string) => {\n const open = expanded.includes(key);\n return (\n <button\n type=\"button\"\n className=\"aegis-data-table__toggle\"\n aria-expanded={open}\n aria-controls={detailId}\n aria-label={open ? strings.collapseRow : strings.expandRow}\n onClick={() => {\n toggleExpanded(key);\n }}\n >\n <RightOutlined className=\"aegis-data-table__toggle-icon\" aria-hidden />\n </button>\n );\n };\n\n const renderDetailRow = (\n row: T,\n idx: number,\n key: string | number,\n detailId: string,\n render: (row: T, index: number) => ReactNode,\n ) => {\n const open = expanded.includes(key);\n return (\n <tr\n className={\n open\n ? 'aegis-data-table__detail-row aegis-data-table__detail-row--open'\n : 'aegis-data-table__detail-row'\n }\n >\n {selectable && <td className=\"aegis-data-table__detail-cell\" />}\n <td className=\"aegis-data-table__detail-cell\" />\n <td\n id={detailId}\n colSpan={bodyColumnCount}\n className=\"aegis-data-table__detail-cell\"\n >\n <div\n className=\"aegis-data-table__detail\"\n style={{\n left: leadWidth,\n width: `calc(100cqi - ${String(leadWidth)}px)`,\n }}\n >\n <div className=\"aegis-data-table__detail-clip\">\n <div className=\"aegis-data-table__detail-body\">\n {(open || visited.includes(key)) && render(row, idx)}\n </div>\n </div>\n </div>\n </td>\n </tr>\n );\n };\n\n const handleRowClick = (\n event: MouseEvent<HTMLTableRowElement>,\n row: T,\n idx: number,\n ): void => {\n if (!isOwnedByControl(event)) {\n onRowClick?.(row, idx);\n }\n };\n\n const handleRowKeyDown = (\n event: KeyboardEvent<HTMLTableRowElement>,\n row: T,\n idx: number,\n ): void => {\n if (event.key === 'Enter' && event.target === event.currentTarget) {\n event.preventDefault();\n onRowClick?.(row, idx);\n }\n };\n\n const rowClass = (isSelected: boolean): string =>\n [\n 'aegis-data-table__row',\n clickable ? 'aegis-data-table__row--clickable' : '',\n expandable ? 'aegis-data-table__row--expandable' : '',\n isSelected ? 'aegis-data-table__row--selected' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const tableClass = [\n 'aegis-data-table__table',\n fixedLayout ? 'aegis-data-table__table--fixed' : '',\n cardMode ? 'aegis-data-table__table--cards' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div\n ref={wrapRef}\n className={cls}\n aria-busy={stale || loading ? true : undefined}\n {...agentAttrs}\n >\n <div className=\"aegis-data-table__scroll-frame\">\n <div className=\"aegis-data-table__scroll\">\n <table\n ref={tableRef}\n aria-label={ariaLabel}\n className={tableClass}\n style={fixedLayout ? columnWidths.tableStyle : undefined}\n >\n {fixedLayout && (\n <colgroup>\n {selectable && (\n <col key=\"__select\" style={{ width: SELECTION_WIDTH }} />\n )}\n {expandable && (\n <col key=\"__toggle\" style={{ width: TOGGLE_WIDTH }} />\n )}\n {columns.map((col, i) => {\n const width = columnWidths.widths[i];\n return (\n <col\n key={col.key}\n data-column-key={col.key}\n style={width ? { width } : undefined}\n />\n );\n })}\n {filler && (\n <col\n key=\"__filler\"\n data-column-filler\n style={columnWidths.fillerStyle}\n />\n )}\n {clickable && (\n <col key=\"__chevron\" style={{ width: CHEVRON_WIDTH }} />\n )}\n </colgroup>\n )}\n {(!cardMode || selectable) && (\n <thead>\n <tr>\n {selectable && (\n <th\n key=\"__select\"\n scope=\"col\"\n {...leadCellProps('select', 'th')}\n >\n <span className=\"aegis-data-table__th-label\">\n <Checkbox\n checked={\n keys.length > 0 && selectedCount === keys.length\n }\n indeterminate={\n selectedCount > 0 && selectedCount < keys.length\n }\n onChange={togglePage}\n ariaLabel={strings.selectAllRows}\n />\n </span>\n </th>\n )}\n {expandable && (\n <th\n key=\"__toggle\"\n scope=\"col\"\n {...leadCellProps('toggle', 'th')}\n />\n )}\n {cardMode ? (\n <th scope=\"col\" className=\"aegis-data-table__th\" />\n ) : (\n columns.map((col, i) => (\n <th\n key={col.key}\n scope=\"col\"\n data-column-key={col.key}\n className={cellClass('th', i)}\n style={cellStyle(col, i)}\n aria-sort={\n col.sortable\n ? activeSort?.key === col.key\n ? activeSort.direction === 'asc'\n ? 'ascending'\n : 'descending'\n : 'none'\n : undefined\n }\n >\n {col.sortable ? (\n <button\n type=\"button\"\n className=\"aegis-data-table__sort\"\n onClick={() => {\n requestSort(col);\n }}\n >\n <span className=\"aegis-data-table__th-label\">\n {col.header}\n </span>\n <SortIcon\n direction={\n activeSort?.key === col.key\n ? activeSort.direction\n : null\n }\n />\n </button>\n ) : (\n <span className=\"aegis-data-table__th-label\">\n {col.header}\n </span>\n )}\n {col.resizable && (\n <span\n aria-label={strings.resizeColumn}\n className=\"aegis-data-table__resizer\"\n {...columnWidths.handleProps(col)}\n />\n )}\n </th>\n ))\n )}\n {filler && (\n <th\n scope=\"col\"\n className=\"aegis-data-table__th aegis-data-table__filler\"\n aria-hidden\n />\n )}\n {clickable && (\n <th\n scope=\"col\"\n className=\"aegis-data-table__th aegis-data-table__chevron-cell\"\n aria-hidden\n />\n )}\n </tr>\n </thead>\n )}\n <tbody data-aegis-develop={develop || undefined}>\n {loading ? (\n Array.from({ length: 5 }).map((_, i) => (\n <tr key={`sk-${i}`} className=\"aegis-data-table__row\">\n {selectable && (\n <td key=\"__select\" {...leadCellProps('select', 'td')} />\n )}\n {expandable && (\n <td key=\"__toggle\" {...leadCellProps('toggle', 'td')} />\n )}\n {renderSkeletonCells()}\n {fillerCell}\n {clickable && (\n <td className=\"aegis-data-table__td\" aria-hidden />\n )}\n </tr>\n ))\n ) : rows.length === 0 ? (\n // Not a data row, so an empty table has no rows to read.\n <tr role=\"presentation\">\n <td\n colSpan={columnCount}\n className=\"aegis-data-table__empty-cell\"\n >\n <div className=\"aegis-data-table__empty\">\n <EmptyState\n title={emptyTitle ?? strings.noData}\n description={emptyDescription}\n action={emptyAction}\n />\n </div>\n </td>\n </tr>\n ) : (\n rows.map((row, idx) => {\n const key = rowKey(row, idx);\n const detailId = `${detailIdPrefix}-detail-${String(idx)}`;\n const isSelected = selected.includes(key);\n return (\n <Fragment key={key}>\n <tr\n className={rowClass(isSelected)}\n aria-selected={\n selectable || selectedKeys !== undefined\n ? isSelected\n : undefined\n }\n tabIndex={clickable ? 0 : undefined}\n onClick={\n clickable\n ? (event) => {\n handleRowClick(event, row, idx);\n }\n : undefined\n }\n onKeyDown={\n clickable\n ? (event) => {\n handleRowKeyDown(event, row, idx);\n }\n : undefined\n }\n >\n {selectable && (\n <td {...leadCellProps('select', 'td')}>\n {selectionCell(isSelected, (checked) => {\n toggleRow(key, checked);\n })}\n </td>\n )}\n {expandable && (\n <td {...leadCellProps('toggle', 'td')}>\n {renderToggle(key, detailId)}\n </td>\n )}\n {renderRowCells(row, idx)}\n {fillerCell}\n {chevronCell}\n </tr>\n {expandable &&\n renderDetailRow(\n row,\n idx,\n key,\n detailId,\n renderExpanded,\n )}\n </Fragment>\n );\n })\n )}\n </tbody>\n </table>\n </div>\n </div>\n {pagination && (\n <Pagination\n {...pagination}\n pageRowCount={data.length}\n disabled={loading}\n className=\"aegis-data-table__footer\"\n />\n )}\n </div>\n );\n}\n"],"names":["SELECTION_WIDTH","TOGGLE_WIDTH","CHEVRON_WIDTH","PINNED_MAX","MOBILE_QUERY","CONTROL_SELECTOR","isOwnedByControl","event","target","control","sortRows","data","column","direction","value","sign","row","index","v","a","b","order","entry","SortIcon","jsxs","jsx","DataTable","columns","rowKey","ariaLabel","loading","emptyTitle","emptyDescription","emptyAction","className","framed","persistKey","pagination","selectable","selectedKeys","onSelectedKeysChange","renderExpanded","expandedKeys","defaultExpandedKeys","onExpandedKeysChange","renderMobileCard","onRowClick","stickyFirstColumn","stale","sort","defaultSort","onSortChange","surface","strings","useStrings","isMobile","useMediaQuery","detailIdPrefix","useId","cardMode","develop","useDevelopAfterLoad","uncontrolledSort","setUncontrolledSort","useState","activeSort","sortColumn","col","rows","useMemo","requestSort","first","next","selected","keys","selectedCount","key","toggleRow","checked","item","togglePage","others","selectionCell","onToggle","Checkbox","uncontrolledExpanded","setUncontrolledExpanded","expanded","visited","setVisited","unvisited","toggleExpanded","tableRef","useRef","wrapRef","agentAttrs","usePrimitiveSurface","expandable","clickable","leadWidth","trailWidth","sticky","columnWidths","useColumnWidths","cls","fixedLayout","filler","bodyColumnCount","columnCount","toggleLeft","leadCellProps","lead","cell","cellClass","colIndex","tone","block","classes","columnAlign","cellStyle","renderCellContent","node","renderRowCells","idx","renderSkeletonCells","SkeletonText","Skeleton","fillerCell","chevronCell","RightOutlined","renderToggle","detailId","open","renderDetailRow","render","handleRowClick","handleRowKeyDown","rowClass","isSelected","tableClass","i","width","_","EmptyState","Fragment","Pagination"],"mappings":";;;;;;;;;;;;;AA0LA,MAAMA,IAAkB,IAClBC,IAAe,IACfC,KAAgB,IAEhBC,KAAa,sCACbC,KAAe,sBACfC,KACJ;AAGF,SAASC,GAAiBC,GAAyC;AACjE,MAAI,OAAO,gBAAgB,SAAS;AAClC,WAAO;AAET,QAAMC,IAASD,EAAM;AACrB,MAAI,EAAEC,aAAkB;AACtB,WAAO;AAET,QAAMC,IAAUD,EAAO,QAAQH,EAAgB;AAC/C,SAAOI,MAAY,QAAQF,EAAM,cAAc,SAASE,CAAO;AACjE;AAOA,SAASC,GACPC,GACAC,GACAC,GACK;AACL,QAAMC,IAAQF,GAAQ;AACtB,MAAI,CAACE;AACH,WAAOH;AAET,QAAMI,IAAOF,MAAc,QAAQ,IAAI;AACvC,SAAOF,EACJ,IAAI,CAACK,GAAKC,MAAU;AACnB,UAAMC,IAAIJ,EAAME,CAAG;AACnB,WAAO,EAAE,KAAAA,GAAK,OAAAC,GAAO,GAAG,OAAOC,KAAM,YAAY,MAAMA,CAAC,IAAI,OAAOA,EAAA;AAAA,EACrE,CAAC,EACA,KAAK,CAACC,GAAGC,MAAM;AACd,QAAID,EAAE,MAAM,QA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BI;AAAA,wBACAC;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAEF/B,KACCoC;AAAA,oBACErH;AAAA,oBACA2G;AAAA,oBACA/C;AAAA,oBACAuD;AAAA,oBACA1F;AAAA,kBAAA;AAAA,gBACF,EAAA,GA/CWmC,CAgDf;AAAA,cAEJ,CAAC,EAAA,CAEL;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA,GAEJ,EAAA,CACF;AAAA,QACCvC,KACC,gBAAAZ;AAAA,UAACwH;AAAA,UAAA;AAAA,YACE,GAAG5G;AAAA,YACJ,cAAc1B,EAAK;AAAA,YACnB,UAAUmB;AAAA,YACV,WAAU;AAAA,UAAA;AAAA,QAAA;AAAA,MACZ;AAAA,IAAA;AAAA,EAAA;AAIR;"}
|
|
1
|
+
{"version":3,"file":"DataTable.js","sources":["../../../src/components/ui/DataTable.tsx"],"sourcesContent":["import {\n type CSSProperties,\n Fragment,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n useContext,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { useDevelopAfterLoad } from '../../hooks/useDevelopAfterLoad';\nimport { useMediaQuery } from '../../hooks/useMediaQuery';\nimport { useStrings } from '../../locale';\nimport { Checkbox } from './Checkbox';\nimport './DataTable.css';\nimport { EmptyState } from './EmptyState';\nimport { Pagination, type PaginationProps } from './Pagination';\nimport { Skeleton, SkeletonText } from './Skeleton';\nimport { SelectedRowDetailContext } from './selectedRowDetail';\nimport { useColumnWidths } from './useColumnWidths';\n\nexport type DataTableSurface<T> = PrimitiveSurface<T[]>;\n\n/** Background wash of one cell, e.g. a step on a pass-rate scale. */\nexport interface DataTableCellTone {\n tone: 'success' | 'info' | 'caution' | 'warning';\n /**\n * 1 (default) is the tone's soft background; each step up mixes in more\n * of the tone's accent, to 5.\n */\n step?: 1 | 2 | 3 | 4 | 5;\n}\n\nexport interface DataTableColumn<T> {\n key: string;\n header: ReactNode;\n /** Initial column width. Number → px, string → as-is (e.g. '20%'). */\n width?: number | string;\n /** Minimum width during resize / when content squeezes. Default 60px. */\n minWidth?: number;\n /** Maximum width during resize. */\n maxWidth?: number;\n align?: 'left' | 'center' | 'right';\n /**\n * Whether the cell should ellipsis-truncate long content. Default true.\n * Set false for action cells, chip rows, links and other focusable content\n * (the clip cuts off their focus ring), or anything with non-text content\n * that should keep its natural width without being clipped.\n */\n truncate?: boolean;\n /**\n * Gives the header a resize handle on its right edge, dragged with the\n * pointer or moved with the arrow keys. Default false.\n */\n resizable?: boolean;\n /**\n * `'actions'` lays the cell out as a right-aligned, gapped, wrapping row of\n * controls — return them straight from `render`. Overrides `align` and\n * `truncate`.\n */\n kind?: 'actions';\n /**\n * Number column: header and cells right-aligned, figures in\n * `--font-numeric` with tabular widths so digits and decimal points line\n * up. Overrides `align`.\n */\n numeric?: boolean;\n /** Washes a cell's background in a tone. Table rows only, not mobile cards. */\n cellTone?: (row: T, index: number) => DataTableCellTone | undefined;\n /**\n * Makes the header a sort control. With `sortValue` the table orders\n * the rows itself; without it the host orders `data` (for instance the\n * server, from a URL parameter) and the header only shows the state.\n */\n sortable?: boolean;\n /** The value the table sorts this column by; `null` sorts last either way. */\n sortValue?: (row: T) => number | string | null;\n /** The direction of a first click. Defaults to `desc` for numeric columns, `asc` otherwise. */\n firstSortDirection?: DataTableSortDirection;\n render: (row: T, index: number) => ReactNode;\n}\n\nexport type DataTableSortDirection = 'asc' | 'desc';\n\nexport interface DataTableSort {\n key: string;\n direction: DataTableSortDirection;\n}\n\n/**\n * Server-side pagination: `data` is the current page, never sliced here.\n * The table supplies the page's row count and disables the pager while\n * loading.\n */\nexport type DataTablePagination = Pick<\n PaginationProps,\n 'page' | 'pageSize' | 'total' | 'onChange' | 'pageSizeOptions'\n>;\n\ninterface DataTableProps<T> {\n columns: Array<DataTableColumn<T>>;\n data: T[];\n rowKey: (row: T, index: number) => string | number;\n /** The table's accessible name. */\n ariaLabel?: string;\n /** Draws skeleton rows, and marks the table busy. */\n loading?: boolean;\n emptyTitle?: string;\n emptyDescription?: string;\n emptyAction?: ReactNode;\n className?: string;\n /**\n * Draws the table as its own card: `--radius-lg`, hairline border and\n * resting shadow, with the header flush with the top and clipped by the\n * radius. Default true. Pass false where a container already frames the\n * table, e.g. a titled `Panel padded={false}`, a dialog or an expanded row.\n */\n framed?: boolean;\n /**\n * When set, resized column widths are persisted to localStorage under\n * `aegis-data-table:<persistKey>`. Use a stable key per table.\n */\n persistKey?: string;\n /** Renders a footer with page navigation under the table. */\n pagination?: DataTablePagination;\n /** Adds a leading checkbox column and drives `selectedKeys`. */\n selectable?: boolean;\n /**\n * The selected rows: `aria-selected` and drawn selected. Without\n * `selectable` there is no checkbox column, e.g. for the row whose\n * details show beside the table.\n */\n selectedKeys?: Array<string | number>;\n onSelectedKeysChange?: (keys: Array<string | number>) => void;\n /**\n * Makes rows expandable: a leading column of chevron toggles, and this\n * content full-width under each expanded row.\n */\n renderExpanded?: (row: T, index: number) => ReactNode;\n /** Controlled expanded row keys. Omit to let the table track them. */\n expandedKeys?: Array<string | number>;\n /** Rows expanded on mount when `expandedKeys` is omitted. */\n defaultExpandedKeys?: Array<string | number>;\n onExpandedKeysChange?: (keys: Array<string | number>) => void;\n /**\n * At ≤768 px, renders each row through this instead of the columns, as a\n * stacked list with no sideways scroll. Selection, expansion, row clicks,\n * loading, empty state and pagination keep working.\n */\n renderMobileCard?: (row: T, index: number) => ReactNode;\n /**\n * Makes rows clickable: pointer cursor, a muted hover background, a\n * trailing chevron, and Enter on a focused row. Links, buttons and form\n * controls inside a cell keep their own behaviour.\n */\n onRowClick?: (row: T, index: number) => void;\n /**\n * Keeps the first column (with the selection and expansion columns) in\n * view while the other columns scroll sideways. The first column takes\n * at most 40% of the table's visible width, truncating past it.\n */\n stickyFirstColumn?: boolean;\n /**\n * The rows are out of date, e.g. the previous page while the next one\n * loads: they stay in place, dimmed, and the table is marked busy.\n */\n stale?: boolean;\n /**\n * The sorted column and direction. Omit to let the table track it,\n * starting from `defaultSort`. Row indices passed to `render`,\n * `cellTone` and the other callbacks count in the sorted order.\n */\n sort?: DataTableSort | null;\n defaultSort?: DataTableSort;\n /** Called with the sort a header click asks for. */\n onSortChange?: (sort: DataTableSort) => void;\n surface?: DataTableSurface<T>;\n}\n\nconst SELECTION_WIDTH = 44;\nconst TOGGLE_WIDTH = 32;\nconst CHEVRON_WIDTH = 40;\n/** The widest a pinned first column renders; DataTable.css sets the share. */\nconst PINNED_MAX = 'var(--aegis-data-table-pinned-max)';\nconst MOBILE_QUERY = '(max-width: 768px)';\nconst CONTROL_SELECTOR =\n 'a, button, input, select, textarea, label, [role=\"button\"], [role=\"link\"], [role=\"checkbox\"]';\n\n/** True when the click belongs to a control inside the row, or ends a text selection. */\nfunction isOwnedByControl(event: MouseEvent<HTMLElement>): boolean {\n if (window.getSelection()?.type === 'Range') {\n return true;\n }\n const target = event.target;\n if (!(target instanceof Element)) {\n return false;\n }\n const control = target.closest(CONTROL_SELECTOR);\n return control !== null && event.currentTarget.contains(control);\n}\n\n/**\n * The rows ordered by `column`'s sort value, ties and nulls (last in\n * either direction) keeping their order; unchanged when the column has no\n * sort value, because then the host ordered them.\n */\nfunction sortRows<T>(\n data: T[],\n column: DataTableColumn<T> | undefined,\n direction: DataTableSortDirection,\n): T[] {\n const value = column?.sortValue;\n if (!value) {\n return data;\n }\n const sign = direction === 'asc' ? 1 : -1;\n return data\n .map((row, index) => {\n const v = value(row);\n return { row, index, v: typeof v === 'number' && isNaN(v) ? null : v };\n })\n .sort((a, b) => {\n if (a.v === null || b.v === null) {\n return a.v === b.v ? a.index - b.index : a.v === null ? 1 : -1;\n }\n const order =\n typeof a.v === 'number' && typeof b.v === 'number'\n ? a.v - b.v\n : String(a.v).localeCompare(String(b.v));\n return order === 0 ? a.index - b.index : order * sign;\n })\n .map((entry) => entry.row);\n}\n\nfunction SortIcon({\n direction,\n}: {\n direction: DataTableSortDirection | null;\n}): ReactNode {\n return (\n <svg\n className=\"aegis-data-table__sort-icon\"\n viewBox=\"0 0 12 12\"\n aria-hidden=\"true\"\n >\n <path\n className={\n direction === 'asc' ? 'aegis-data-table__sort-mark--on' : undefined\n }\n d=\"M3.5 5L6 2.5 8.5 5\"\n />\n <path\n className={\n direction === 'desc' ? 'aegis-data-table__sort-mark--on' : undefined\n }\n d=\"M3.5 7L6 9.5 8.5 7\"\n />\n </svg>\n );\n}\n\nexport function DataTable<T>({\n columns,\n data,\n rowKey,\n ariaLabel,\n loading = false,\n emptyTitle,\n emptyDescription,\n emptyAction,\n className,\n framed = true,\n persistKey,\n pagination,\n selectable = false,\n selectedKeys,\n onSelectedKeysChange,\n renderExpanded,\n expandedKeys,\n defaultExpandedKeys,\n onExpandedKeysChange,\n renderMobileCard,\n onRowClick,\n stickyFirstColumn = false,\n stale = false,\n sort,\n defaultSort,\n onSortChange,\n surface,\n}: DataTableProps<T>) {\n const strings = useStrings();\n const isMobile = useMediaQuery(MOBILE_QUERY);\n const detailIdPrefix = useId();\n const cardMode = renderMobileCard !== undefined && isMobile;\n const develop = useDevelopAfterLoad(loading);\n\n const [uncontrolledSort, setUncontrolledSort] =\n useState<DataTableSort | null>(defaultSort ?? null);\n const activeSort = sort === undefined ? uncontrolledSort : sort;\n const sortColumn = columns.find((col) => col.key === activeSort?.key);\n const rows = useMemo(\n () => sortRows(data, sortColumn, activeSort?.direction ?? 'asc'),\n [data, sortColumn, activeSort?.direction],\n );\n const requestSort = (col: DataTableColumn<T>): void => {\n const first: DataTableSortDirection =\n col.firstSortDirection ?? (col.numeric ? 'desc' : 'asc');\n const next: DataTableSort = {\n key: col.key,\n direction:\n activeSort?.key === col.key\n ? activeSort.direction === 'asc'\n ? 'desc'\n : 'asc'\n : first,\n };\n if (sort === undefined) {\n setUncontrolledSort(next);\n }\n onSortChange?.(next);\n };\n\n const selected = selectedKeys ?? [];\n const keys = rows.map((row, index) => rowKey(row, index));\n const selection = useContext(SelectedRowDetailContext);\n // A DetailBeside follows the first selected row on the page.\n const detailKey = keys.find((key) => selected.includes(key));\n const selectedCount = keys.filter((key) => selected.includes(key)).length;\n const toggleRow = (key: string | number, checked: boolean): void => {\n onSelectedKeysChange?.(\n checked ? [...selected, key] : selected.filter((item) => item !== key),\n );\n };\n // Selections on other pages survive toggling the rows of this page.\n const togglePage = (checked: boolean): void => {\n const others = selected.filter((key) => !keys.includes(key));\n onSelectedKeysChange?.(checked ? [...others, ...keys] : others);\n };\n const selectionCell = (\n checked: boolean,\n onToggle: (next: boolean) => void,\n ) => (\n <Checkbox\n checked={checked}\n onChange={onToggle}\n ariaLabel={strings.selectRow}\n />\n );\n\n const [uncontrolledExpanded, setUncontrolledExpanded] = useState<\n Array<string | number>\n >(defaultExpandedKeys ?? []);\n const expanded = expandedKeys ?? uncontrolledExpanded;\n // A row's detail mounts the first time it opens and stays mounted, so\n // collapsing can animate instead of dropping the content at once.\n const [visited, setVisited] = useState(expanded);\n const unvisited = expanded.filter((key) => !visited.includes(key));\n if (unvisited.length > 0) {\n setVisited([...visited, ...unvisited]);\n }\n const toggleExpanded = (key: string | number): void => {\n const next = expanded.includes(key)\n ? expanded.filter((item) => item !== key)\n : [...expanded, key];\n if (expandedKeys === undefined) {\n setUncontrolledExpanded(next);\n }\n onExpandedKeysChange?.(next);\n };\n\n const tableRef = useRef<HTMLTableElement>(null);\n const wrapRef = useRef<HTMLDivElement>(null);\n\n const agentAttrs = usePrimitiveSurface(surface, data, 'table', wrapRef);\n const expandable = renderExpanded !== undefined;\n const clickable = onRowClick !== undefined;\n const leadWidth =\n (selectable ? SELECTION_WIDTH : 0) + (expandable ? TOGGLE_WIDTH : 0);\n const trailWidth = clickable ? CHEVRON_WIDTH : 0;\n const sticky = stickyFirstColumn && !cardMode;\n\n const columnWidths = useColumnWidths({\n columns,\n persistKey,\n leadWidth,\n trailWidth,\n firstColumnMax: sticky ? PINNED_MAX : undefined,\n tableRef,\n });\n\n const cls = [\n 'aegis-data-table',\n framed ? 'aegis-data-table--framed' : '',\n stale ? 'aegis-data-table--stale' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const fixedLayout = columnWidths.sized && !cardMode;\n const filler = fixedLayout && columnWidths.fillerStyle !== undefined;\n const bodyColumnCount =\n (cardMode ? 1 : columns.length) + (filler ? 1 : 0) + (clickable ? 1 : 0);\n const columnCount =\n bodyColumnCount + (selectable ? 1 : 0) + (expandable ? 1 : 0);\n const toggleLeft = selectable ? SELECTION_WIDTH : 0;\n\n /** Props of a leading selection or toggle cell, fixed in width so the sticky offsets line up. */\n const leadCellProps = (lead: 'select' | 'toggle', cell: 'th' | 'td') => ({\n className: [\n `aegis-data-table__${cell}`,\n `aegis-data-table__${lead}-cell`,\n sticky ? `aegis-data-table__${cell}--sticky` : '',\n ]\n .filter(Boolean)\n .join(' '),\n style: {\n width: lead === 'select' ? SELECTION_WIDTH : TOGGLE_WIDTH,\n left: sticky ? (lead === 'select' ? 0 : toggleLeft) : undefined,\n },\n });\n\n /** Classes of a header or body cell of data column `colIndex`. */\n const cellClass = (\n cell: 'th' | 'td',\n colIndex: number,\n tone?: DataTableCellTone,\n ): string => {\n const block = `aegis-data-table__${cell}`;\n const classes = [block];\n if (sticky && colIndex === 0) {\n classes.push(`${block}--sticky`, `${block}--pinned`);\n }\n if (tone !== undefined) {\n classes.push(\n 'aegis-data-table__td--tone',\n `aegis-data-table__td--tone-${tone.tone}`,\n );\n if (tone.step !== undefined && tone.step > 1) {\n classes.push(`aegis-data-table__td--step-${String(tone.step)}`);\n }\n }\n return classes.join(' ');\n };\n\n const columnAlign = (col: DataTableColumn<T>) =>\n col.kind === 'actions' || col.numeric === true\n ? 'right'\n : (col.align ?? 'left');\n\n const cellStyle = (\n col: DataTableColumn<T>,\n colIndex: number,\n ): CSSProperties => ({\n textAlign: columnAlign(col),\n left: sticky && colIndex === 0 ? leadWidth : undefined,\n });\n\n const renderCellContent = (col: DataTableColumn<T>, node: ReactNode) => {\n const classes = [\n 'aegis-data-table__cell',\n `aegis-data-table__cell--${columnAlign(col)}`,\n ];\n if (col.numeric) {\n classes.push('aegis-data-table__cell--numeric');\n }\n if (col.kind === 'actions') {\n classes.push('aegis-data-table__cell--actions');\n } else if (col.truncate ?? true) {\n classes.push('aegis-data-table__cell--truncate');\n }\n return <div className={classes.join(' ')}>{node}</div>;\n };\n\n const renderRowCells = (row: T, idx: number) =>\n cardMode ? (\n <td className=\"aegis-data-table__td aegis-data-table__card-cell\">\n {renderMobileCard(row, idx)}\n </td>\n ) : (\n columns.map((col, colIndex) => (\n <td\n key={col.key}\n className={cellClass('td', colIndex, col.cellTone?.(row, idx))}\n style={cellStyle(col, colIndex)}\n >\n {renderCellContent(col, col.render(row, idx))}\n </td>\n ))\n );\n\n const renderSkeletonCells = () =>\n cardMode ? (\n <td className=\"aegis-data-table__td aegis-data-table__card-cell\">\n <SkeletonText lines={2} />\n </td>\n ) : (\n columns.map((col, colIndex) => (\n <td\n key={col.key}\n className={cellClass('td', colIndex)}\n style={cellStyle(col, colIndex)}\n >\n {renderCellContent(\n col,\n <Skeleton width=\"80%\" height=\"var(--space-3)\" />,\n )}\n </td>\n ))\n );\n\n const fillerCell = filler && (\n <td className=\"aegis-data-table__td aegis-data-table__filler\" aria-hidden />\n );\n\n // The row itself takes the click, so the chevron column is not read.\n const chevronCell = clickable && (\n <td\n className=\"aegis-data-table__td aegis-data-table__chevron-cell\"\n aria-hidden\n >\n <RightOutlined className=\"aegis-data-table__chevron\" aria-hidden />\n </td>\n );\n\n const renderToggle = (key: string | number, detailId: string) => {\n const open = expanded.includes(key);\n return (\n <button\n type=\"button\"\n className=\"aegis-data-table__toggle\"\n aria-expanded={open}\n aria-controls={detailId}\n aria-label={open ? strings.collapseRow : strings.expandRow}\n onClick={() => {\n toggleExpanded(key);\n }}\n >\n <RightOutlined className=\"aegis-data-table__toggle-icon\" aria-hidden />\n </button>\n );\n };\n\n /** A full-width row under a data row, holding a row's expanded content or the selection's detail. */\n const renderDetailRow = (\n open: boolean,\n content: ReactNode,\n detailId?: string,\n ) => (\n <tr\n className={\n open\n ? 'aegis-data-table__detail-row aegis-data-table__detail-row--open'\n : 'aegis-data-table__detail-row'\n }\n >\n {selectable && <td className=\"aegis-data-table__detail-cell\" />}\n {expandable && <td className=\"aegis-data-table__detail-cell\" />}\n <td\n id={detailId}\n colSpan={bodyColumnCount}\n className=\"aegis-data-table__detail-cell\"\n >\n <div\n className=\"aegis-data-table__detail\"\n style={{\n left: leadWidth,\n width: `calc(100cqi - ${String(leadWidth)}px)`,\n }}\n >\n {content}\n </div>\n </td>\n </tr>\n );\n\n const handleRowClick = (\n event: MouseEvent<HTMLTableRowElement>,\n row: T,\n idx: number,\n ): void => {\n if (!isOwnedByControl(event)) {\n onRowClick?.(row, idx);\n }\n };\n\n const handleRowKeyDown = (\n event: KeyboardEvent<HTMLTableRowElement>,\n row: T,\n idx: number,\n ): void => {\n if (event.key === 'Enter' && event.target === event.currentTarget) {\n event.preventDefault();\n onRowClick?.(row, idx);\n }\n };\n\n const rowClass = (isSelected: boolean): string =>\n [\n 'aegis-data-table__row',\n clickable ? 'aegis-data-table__row--clickable' : '',\n expandable ? 'aegis-data-table__row--expandable' : '',\n isSelected ? 'aegis-data-table__row--selected' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const tableClass = [\n 'aegis-data-table__table',\n fixedLayout ? 'aegis-data-table__table--fixed' : '',\n cardMode ? 'aegis-data-table__table--cards' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div\n ref={wrapRef}\n className={cls}\n aria-busy={stale || loading ? true : undefined}\n {...agentAttrs}\n >\n <div className=\"aegis-data-table__scroll-frame\">\n <div className=\"aegis-data-table__scroll\">\n <table\n ref={tableRef}\n aria-label={ariaLabel}\n className={tableClass}\n style={fixedLayout ? columnWidths.tableStyle : undefined}\n >\n {fixedLayout && (\n <colgroup>\n {selectable && (\n <col key=\"__select\" style={{ width: SELECTION_WIDTH }} />\n )}\n {expandable && (\n <col key=\"__toggle\" style={{ width: TOGGLE_WIDTH }} />\n )}\n {columns.map((col, i) => {\n const width = columnWidths.widths[i];\n return (\n <col\n key={col.key}\n data-column-key={col.key}\n style={width ? { width } : undefined}\n />\n );\n })}\n {filler && (\n <col\n key=\"__filler\"\n data-column-filler\n style={columnWidths.fillerStyle}\n />\n )}\n {clickable && (\n <col key=\"__chevron\" style={{ width: CHEVRON_WIDTH }} />\n )}\n </colgroup>\n )}\n {(!cardMode || selectable) && (\n <thead>\n <tr>\n {selectable && (\n <th\n key=\"__select\"\n scope=\"col\"\n {...leadCellProps('select', 'th')}\n >\n <span className=\"aegis-data-table__th-label\">\n <Checkbox\n checked={\n keys.length > 0 && selectedCount === keys.length\n }\n indeterminate={\n selectedCount > 0 && selectedCount < keys.length\n }\n onChange={togglePage}\n ariaLabel={strings.selectAllRows}\n />\n </span>\n </th>\n )}\n {expandable && (\n <th\n key=\"__toggle\"\n scope=\"col\"\n {...leadCellProps('toggle', 'th')}\n />\n )}\n {cardMode ? (\n <th scope=\"col\" className=\"aegis-data-table__th\" />\n ) : (\n columns.map((col, i) => (\n <th\n key={col.key}\n scope=\"col\"\n data-column-key={col.key}\n className={cellClass('th', i)}\n style={cellStyle(col, i)}\n aria-sort={\n col.sortable\n ? activeSort?.key === col.key\n ? activeSort.direction === 'asc'\n ? 'ascending'\n : 'descending'\n : 'none'\n : undefined\n }\n >\n {col.sortable ? (\n <button\n type=\"button\"\n className=\"aegis-data-table__sort\"\n onClick={() => {\n requestSort(col);\n }}\n >\n <span className=\"aegis-data-table__th-label\">\n {col.header}\n </span>\n <SortIcon\n direction={\n activeSort?.key === col.key\n ? activeSort.direction\n : null\n }\n />\n </button>\n ) : (\n <span className=\"aegis-data-table__th-label\">\n {col.header}\n </span>\n )}\n {col.resizable && (\n <span\n aria-label={strings.resizeColumn}\n className=\"aegis-data-table__resizer\"\n {...columnWidths.handleProps(col)}\n />\n )}\n </th>\n ))\n )}\n {filler && (\n <th\n scope=\"col\"\n className=\"aegis-data-table__th aegis-data-table__filler\"\n aria-hidden\n />\n )}\n {clickable && (\n <th\n scope=\"col\"\n className=\"aegis-data-table__th aegis-data-table__chevron-cell\"\n aria-hidden\n />\n )}\n </tr>\n </thead>\n )}\n <tbody data-aegis-develop={develop || undefined}>\n {loading ? (\n Array.from({ length: 5 }).map((_, i) => (\n <tr key={`sk-${i}`} className=\"aegis-data-table__row\">\n {selectable && (\n <td key=\"__select\" {...leadCellProps('select', 'td')} />\n )}\n {expandable && (\n <td key=\"__toggle\" {...leadCellProps('toggle', 'td')} />\n )}\n {renderSkeletonCells()}\n {fillerCell}\n {clickable && (\n <td className=\"aegis-data-table__td\" aria-hidden />\n )}\n </tr>\n ))\n ) : rows.length === 0 ? (\n // Not a data row, so an empty table has no rows to read.\n <tr role=\"presentation\">\n <td\n colSpan={columnCount}\n className=\"aegis-data-table__empty-cell\"\n >\n <div className=\"aegis-data-table__empty\">\n <EmptyState\n title={emptyTitle ?? strings.noData}\n description={emptyDescription}\n action={emptyAction}\n />\n </div>\n </td>\n </tr>\n ) : (\n rows.map((row, idx) => {\n const key = rowKey(row, idx);\n const detailId = `${detailIdPrefix}-detail-${String(idx)}`;\n const isSelected = selected.includes(key);\n return (\n <Fragment key={key}>\n <tr\n ref={\n key === detailKey ? selection?.placeRow : undefined\n }\n className={rowClass(isSelected)}\n aria-selected={\n selectable || selectedKeys !== undefined\n ? isSelected\n : undefined\n }\n tabIndex={clickable ? 0 : undefined}\n onClick={\n clickable\n ? (event) => {\n handleRowClick(event, row, idx);\n }\n : undefined\n }\n onKeyDown={\n clickable\n ? (event) => {\n handleRowKeyDown(event, row, idx);\n }\n : undefined\n }\n >\n {selectable && (\n <td {...leadCellProps('select', 'td')}>\n {selectionCell(isSelected, (checked) => {\n toggleRow(key, checked);\n })}\n </td>\n )}\n {expandable && (\n <td {...leadCellProps('toggle', 'td')}>\n {renderToggle(key, detailId)}\n </td>\n )}\n {renderRowCells(row, idx)}\n {fillerCell}\n {chevronCell}\n </tr>\n {key === detailKey && selection?.inline\n ? renderDetailRow(true, selection.inline)\n : null}\n {expandable &&\n renderDetailRow(\n expanded.includes(key),\n <div className=\"aegis-data-table__detail-clip\">\n <div className=\"aegis-data-table__detail-body\">\n {(expanded.includes(key) ||\n visited.includes(key)) &&\n renderExpanded(row, idx)}\n </div>\n </div>,\n detailId,\n )}\n </Fragment>\n );\n })\n )}\n </tbody>\n </table>\n </div>\n </div>\n {pagination && (\n <Pagination\n {...pagination}\n pageRowCount={data.length}\n disabled={loading}\n className=\"aegis-data-table__footer\"\n />\n )}\n </div>\n );\n}\n"],"names":["SELECTION_WIDTH","TOGGLE_WIDTH","CHEVRON_WIDTH","PINNED_MAX","MOBILE_QUERY","CONTROL_SELECTOR","isOwnedByControl","event","target","control","sortRows","data","column","direction","value","sign","row","index","v","a","b","order","entry","SortIcon","jsxs","jsx","DataTable","columns","rowKey","ariaLabel","loading","emptyTitle","emptyDescription","emptyAction","className","framed","persistKey","pagination","selectable","selectedKeys","onSelectedKeysChange","renderExpanded","expandedKeys","defaultExpandedKeys","onExpandedKeysChange","renderMobileCard","onRowClick","stickyFirstColumn","stale","sort","defaultSort","onSortChange","surface","strings","useStrings","isMobile","useMediaQuery","detailIdPrefix","useId","cardMode","develop","useDevelopAfterLoad","uncontrolledSort","setUncontrolledSort","useState","activeSort","sortColumn","col","rows","useMemo","requestSort","first","next","selected","keys","selection","useContext","SelectedRowDetailContext","detailKey","key","selectedCount","toggleRow","checked","item","togglePage","others","selectionCell","onToggle","Checkbox","uncontrolledExpanded","setUncontrolledExpanded","expanded","visited","setVisited","unvisited","toggleExpanded","tableRef","useRef","wrapRef","agentAttrs","usePrimitiveSurface","expandable","clickable","leadWidth","trailWidth","sticky","columnWidths","useColumnWidths","cls","fixedLayout","filler","bodyColumnCount","columnCount","toggleLeft","leadCellProps","lead","cell","cellClass","colIndex","tone","block","classes","columnAlign","cellStyle","renderCellContent","node","renderRowCells","idx","renderSkeletonCells","SkeletonText","Skeleton","fillerCell","chevronCell","RightOutlined","renderToggle","detailId","open","renderDetailRow","content","handleRowClick","handleRowKeyDown","rowClass","isSelected","tableClass","i","width","_","EmptyState","Fragment","Pagination"],"mappings":";;;;;;;;;;;;;;AA4LA,MAAMA,IAAkB,IAClBC,IAAe,IACfC,KAAgB,IAEhBC,KAAa,sCACbC,KAAe,sBACfC,KACJ;AAGF,SAASC,GAAiBC,GAAyC;AACjE,MAAI,OAAO,gBAAgB,SAAS;AAClC,WAAO;AAET,QAAMC,IAASD,EAAM;AACrB,MAAI,EAAEC,aAAkB;AACtB,WAAO;AAET,QAAMC,IAAUD,EAAO,QAAQH,EAAgB;AAC/C,SAAOI,MAAY,QAAQF,EAAM,cAAc,SAASE,CAAO;AACjE;AAOA,SAASC,GACPC,GACAC,GACAC,GACK;AACL,QAAMC,IAAQF,GAAQ;AACtB,MAAI,CAACE;AACH,WAAOH;AAET,QAAMI,IAAOF,MAAc,QAAQ,IAAI;AACvC,SAAOF,EACJ,IAAI,CAACK,GAAKC,MAAU;AACnB,UAAMC,IAAIJ,EAAME,CAAG;AACnB,WAAO,EAAE,KAAAA,GAAK,OAAAC,GAAO,GAAG,OAAOC,KAAM,YAAY,MAAMA,CAAC,IAAI,OAAOA,EAAA;AAAA,EACrE,CAAC,EACA,KAAK,CAACC,GAAGC,MAAM;AACd,QAAID,EAAE,MAAM,QAAQC,EAAE,MAAM;AAC1B,aAAOD,EAAE,MAAMC,EAAE,IAAID,EAAE,QAAQC,EAAE,QAAQD,EAAE,MAAM,OAAO,IAAI;AAE9D,UAAME,IACJ,OAAOF,EAAE,KAAM,YAAY,OAAOC,EAAE,KAAM,WACtCD,EAAE,IAAIC,EAAE,IACR,OAAOD,EAAE,CAAC,EAAE,cAAc,OAAOC,EAAE,CAAC,CAAC;AAC3C,WAAOC,MAAU,IAAIF,EAAE,QAAQC,EAAE,QAAQC,IAAQN;AAAA,EACnD,CAAC,EACA,IAAI,CAAC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BACF,EAAA,GAzDWxD,CA0Df;AAAA,cAEJ,CAAC,EAAA,CAEL;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA,GAEJ,EAAA,CACF;AAAA,QACC1C,KACC,gBAAAZ;AAAA,UAAC4H;AAAA,UAAA;AAAA,YACE,GAAGhH;AAAA,YACJ,cAAc1B,EAAK;AAAA,YACnB,UAAUmB;AAAA,YACV,WAAU;AAAA,UAAA;AAAA,QAAA;AAAA,MACZ;AAAA,IAAA;AAAA,EAAA;AAIR;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),k=require("../../hooks/useIsomorphicLayoutEffect.cjs"),O=require("../../hooks/useMediaQuery.cjs"),w=require("../../lib/scrollView.cjs");;/* empty css */const q=require("./selectedRowDetail.cjs"),P="(max-width: 768px)",D=t.createContext(null);function I(i,a,h,r,d){const c=d.top+r,m=i.top<c?i.top-c:Math.max(i.bottom-d.bottom,0);return Math.max(m,a+h-d.bottom)}function T({boxRef:i}){const a=t.useContext(D);return l.jsx("div",{ref:i,className:"aegis-detail-beside__inline",role:"group",children:a})}function Q({columns:i,detail:a,children:h,scrollContainer:r=null,className:d}){const c=O.useMediaQuery(P),[m,b]=t.useState(!1),j=t.useRef(null),y=t.useRef(null),f=t.useRef(null),g=t.useRef(null),v=t.useRef(!1),B=t.useRef(0),u=t.useCallback(()=>{const e=g.current,s=f.current;if(e===null||s===null)return;const o=e.getBoundingClientRect(),n=y.current;if(n===null)s.style.setProperty("--aegis-detail-beside-row-height",`${String(o.height)}px`);else{const R=n.getBoundingClientRect().top;n.style.height=`${String(Math.max(o.top-R,0))}px`}},[]),p=t.useCallback(()=>{u();const e=g.current,s=f.current;if(e===null||s===null)return;const o=e.getBoundingClientRect(),n=y.current,R=I(o,n===null?o.bottom:n.getBoundingClientRect().top,s.getBoundingClientRect().height,parseFloat(getComputedStyle(s).scrollMarginTop),w.viewBoundsOf(r)),_=w.scrollerOf(r);Math.abs(R)>=1&&_.scrollBy({top:R,behavior:"instant"}),B.current=_.scrollTop},[u,r]),x=t.useCallback(()=>{v.current=!0,b(!0),queueMicrotask(()=>{p(),b(!1)})},[p]),M=t.useCallback(e=>{const s=e!==null&&e===g.current;g.current=e,s?u():e===null?(v.current=!1,b(!1)):x()},[u,x]),C=t.useCallback(()=>{b(!0)},[]);k.useIsomorphicLayoutEffect(u),k.useIsomorphicLayoutEffect(()=>{const e=j.current;if(e===null)return;const s=new ResizeObserver(()=>{v.current?p():u()});for(const n of c?[e]:[e,f.current])n!==null&&s.observe(n);const o=n=>{n.target instanceof Node&&g.current?.contains(n.target)&&x()};return e.addEventListener("click",o),()=>{s.disconnect(),e.removeEventListener("click",o)}},[c,u,p,x]),t.useEffect(()=>{const e=w.scrollerOf(r),s=r??window,o=()=>{Math.abs(e.scrollTop-B.current)>=1&&(v.current=!1)};return s.addEventListener("scroll",o,{passive:!0}),()=>{s.removeEventListener("scroll",o)}},[r]);const E=t.useMemo(()=>c?l.jsx(T,{boxRef:f}):null,[c]),L=t.useMemo(()=>({placeRow:M,awaitRow:C,inline:E}),[M,C,E]),S=l.jsx(q.SelectedRowDetailContext.Provider,{value:null,children:a}),N=["aegis-detail-beside",d??""].filter(Boolean).join(" ");return l.jsx(q.SelectedRowDetailContext.Provider,{value:L,children:l.jsx(D.Provider,{value:S,children:l.jsxs("div",{className:N,style:{"--aegis-detail-beside-columns":i},"aria-busy":m||void 0,children:[l.jsx("div",{ref:j,className:"aegis-detail-beside__list",children:h}),!c&&l.jsxs("div",{className:"aegis-detail-beside__side",children:[l.jsx("div",{ref:y}),l.jsx("div",{ref:f,className:"aegis-detail-beside__detail",children:S})]})]})})})}exports.DetailBeside=Q;
|
|
2
|
+
//# sourceMappingURL=DetailBeside.cjs.map
|
|
@@ -0,0 +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.\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.\n */\n children: ReactNode;\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, the\n * selection changes or the selected row is clicked, the page scrolls at\n * once, as little as it takes to show the row and the detail whole, and\n * again whenever the list or the detail changes size, until the viewer\n * scrolls. The wrapper is `aria-busy` while the selected row is still on\n * its way.\n */\nexport function DetailBeside({\n columns,\n detail,\n children,\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\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 followRef.current = true;\n setBusy(true);\n queueMicrotask(() => {\n reveal();\n setBusy(false);\n });\n }, [reveal]);\n\n const placeRow = useCallback(\n (row: HTMLElement | null) => {\n const moved = row !== null && row === rowRef.current;\n rowRef.current = row;\n if (moved) {\n place();\n } else if (row === null) {\n followRef.current = false;\n setBusy(false);\n } else {\n revealSoon();\n }\n },\n [place, revealSoon],\n );\n\n const awaitRow = useCallback(() => {\n setBusy(true);\n }, []);\n\n useIsomorphicLayoutEffect(place);\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","scrollContainer","className","narrow","useMediaQuery","busy","setBusy","useState","listRef","useRef","spacerRef","detailRef","rowRef","followRef","revealedAtRef","place","useCallback","box","rowBox","spacer","reveal","distance","viewBoundsOf","scroller","scrollerOf","revealSoon","placeRow","moved","awaitRow","useIsomorphicLayoutEffect","list","observer","activate","event","useEffect","target","scrolled","inline","useMemo","slot","isolated","SelectedRowDetailContext","cls","jsxs"],"mappings":"6VAgDMA,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,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EAAAA,IAAC,MAAA,CAAI,IAAKa,CAAA,CAAW,QACpB,MAAA,CAAI,IAAKC,EAAW,UAAU,8BAC5B,SAAA6B,CAAA,CACH,CAAA,CAAA,CACF,CAAA,CAAA,CAAA,EAGN,CAAA,CACF,CAEJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface DetailBesideProps {
|
|
3
|
+
/**
|
|
4
|
+
* `grid-template-columns` of the list and the detail above 768 px, e.g.
|
|
5
|
+
* `'3fr 2fr'`.
|
|
6
|
+
*/
|
|
7
|
+
columns: string;
|
|
8
|
+
/**
|
|
9
|
+
* The selected item's detail: one element, such as a `Panel` titled with
|
|
10
|
+
* the item's name. It is never taller than the view, so a long Panel
|
|
11
|
+
* scrolls its body.
|
|
12
|
+
*/
|
|
13
|
+
detail: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The list: a `TraceTree`, `FileTree`, `DataTable` or `ServiceMap`, in a
|
|
16
|
+
* Panel say. The detail follows the row it draws selected.
|
|
17
|
+
*/
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
/** The element that scrolls the page; omitted or null means the viewport. */
|
|
20
|
+
scrollContainer?: HTMLElement | null;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A tree, table or map with the selected item's detail beside it. Above
|
|
25
|
+
* 768 px the detail stands in a column on the right, level with the
|
|
26
|
+
* selected row: when the row is too low for it, its bottom meets the
|
|
27
|
+
* view's bottom, and while the page scrolls it stays in the view below
|
|
28
|
+
* the header. At 768 px and below the list draws the detail right after
|
|
29
|
+
* the selected row, the rows that follow under it; a map draws it over
|
|
30
|
+
* the map, under the node. When the page opens with a selection, the
|
|
31
|
+
* selection changes or the selected row is clicked, the page scrolls at
|
|
32
|
+
* once, as little as it takes to show the row and the detail whole, and
|
|
33
|
+
* again whenever the list or the detail changes size, until the viewer
|
|
34
|
+
* scrolls. The wrapper is `aria-busy` while the selected row is still on
|
|
35
|
+
* its way.
|
|
36
|
+
*/
|
|
37
|
+
export declare function DetailBeside({ columns, detail, children, scrollContainer, className, }: DetailBesideProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as l, jsxs as D } from "react/jsx-runtime";
|
|
2
|
+
import { useState as I, useRef as a, useCallback as m, useEffect as Q, useMemo as L, useContext as $, createContext as q } from "react";
|
|
3
|
+
import { useIsomorphicLayoutEffect as k } from "../../hooks/useIsomorphicLayoutEffect.js";
|
|
4
|
+
import { useMediaQuery as z } from "../../hooks/useMediaQuery.js";
|
|
5
|
+
import { viewBoundsOf as F, scrollerOf as O } from "../../lib/scrollView.js";
|
|
6
|
+
/* empty css */
|
|
7
|
+
import { SelectedRowDetailContext as P } from "./selectedRowDetail.js";
|
|
8
|
+
const U = "(max-width: 768px)", j = q(null);
|
|
9
|
+
function W(i, u, x, s, d) {
|
|
10
|
+
const r = d.top + s, B = i.top < r ? i.top - r : Math.max(i.bottom - d.bottom, 0);
|
|
11
|
+
return Math.max(B, u + x - d.bottom);
|
|
12
|
+
}
|
|
13
|
+
function Y({ boxRef: i }) {
|
|
14
|
+
const u = $(j);
|
|
15
|
+
return /* @__PURE__ */ l("div", { ref: i, className: "aegis-detail-beside__inline", role: "group", children: u });
|
|
16
|
+
}
|
|
17
|
+
function ee({
|
|
18
|
+
columns: i,
|
|
19
|
+
detail: u,
|
|
20
|
+
children: x,
|
|
21
|
+
scrollContainer: s = null,
|
|
22
|
+
className: d
|
|
23
|
+
}) {
|
|
24
|
+
const r = z(U), [B, g] = I(!1), y = a(null), w = a(null), f = a(null), p = a(null), v = a(!1), M = a(0), c = m(() => {
|
|
25
|
+
const e = p.current, t = f.current;
|
|
26
|
+
if (e === null || t === null)
|
|
27
|
+
return;
|
|
28
|
+
const o = e.getBoundingClientRect(), n = w.current;
|
|
29
|
+
if (n === null)
|
|
30
|
+
t.style.setProperty(
|
|
31
|
+
"--aegis-detail-beside-row-height",
|
|
32
|
+
`${String(o.height)}px`
|
|
33
|
+
);
|
|
34
|
+
else {
|
|
35
|
+
const R = n.getBoundingClientRect().top;
|
|
36
|
+
n.style.height = `${String(Math.max(o.top - R, 0))}px`;
|
|
37
|
+
}
|
|
38
|
+
}, []), b = m(() => {
|
|
39
|
+
c();
|
|
40
|
+
const e = p.current, t = f.current;
|
|
41
|
+
if (e === null || t === null)
|
|
42
|
+
return;
|
|
43
|
+
const o = e.getBoundingClientRect(), n = w.current, R = W(
|
|
44
|
+
o,
|
|
45
|
+
n === null ? o.bottom : n.getBoundingClientRect().top,
|
|
46
|
+
t.getBoundingClientRect().height,
|
|
47
|
+
parseFloat(getComputedStyle(t).scrollMarginTop),
|
|
48
|
+
F(s)
|
|
49
|
+
), S = O(s);
|
|
50
|
+
Math.abs(R) >= 1 && S.scrollBy({ top: R, behavior: "instant" }), M.current = S.scrollTop;
|
|
51
|
+
}, [c, s]), h = m(() => {
|
|
52
|
+
v.current = !0, g(!0), queueMicrotask(() => {
|
|
53
|
+
b(), g(!1);
|
|
54
|
+
});
|
|
55
|
+
}, [b]), _ = m(
|
|
56
|
+
(e) => {
|
|
57
|
+
const t = e !== null && e === p.current;
|
|
58
|
+
p.current = e, t ? c() : e === null ? (v.current = !1, g(!1)) : h();
|
|
59
|
+
},
|
|
60
|
+
[c, h]
|
|
61
|
+
), E = m(() => {
|
|
62
|
+
g(!0);
|
|
63
|
+
}, []);
|
|
64
|
+
k(c), k(() => {
|
|
65
|
+
const e = y.current;
|
|
66
|
+
if (e === null)
|
|
67
|
+
return;
|
|
68
|
+
const t = new ResizeObserver(() => {
|
|
69
|
+
v.current ? b() : c();
|
|
70
|
+
});
|
|
71
|
+
for (const n of r ? [e] : [e, f.current])
|
|
72
|
+
n !== null && t.observe(n);
|
|
73
|
+
const o = (n) => {
|
|
74
|
+
n.target instanceof Node && p.current?.contains(n.target) && h();
|
|
75
|
+
};
|
|
76
|
+
return e.addEventListener("click", o), () => {
|
|
77
|
+
t.disconnect(), e.removeEventListener("click", o);
|
|
78
|
+
};
|
|
79
|
+
}, [r, c, b, h]), Q(() => {
|
|
80
|
+
const e = O(s), t = s ?? window, o = () => {
|
|
81
|
+
Math.abs(e.scrollTop - M.current) >= 1 && (v.current = !1);
|
|
82
|
+
};
|
|
83
|
+
return t.addEventListener("scroll", o, { passive: !0 }), () => {
|
|
84
|
+
t.removeEventListener("scroll", o);
|
|
85
|
+
};
|
|
86
|
+
}, [s]);
|
|
87
|
+
const N = L(
|
|
88
|
+
() => r ? /* @__PURE__ */ l(Y, { boxRef: f }) : null,
|
|
89
|
+
[r]
|
|
90
|
+
), T = L(
|
|
91
|
+
() => ({ placeRow: _, awaitRow: E, inline: N }),
|
|
92
|
+
[_, E, N]
|
|
93
|
+
), C = /* @__PURE__ */ l(P.Provider, { value: null, children: u }), A = ["aegis-detail-beside", d ?? ""].filter(Boolean).join(" ");
|
|
94
|
+
return /* @__PURE__ */ l(P.Provider, { value: T, children: /* @__PURE__ */ l(j.Provider, { value: C, children: /* @__PURE__ */ D(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
className: A,
|
|
98
|
+
style: { "--aegis-detail-beside-columns": i },
|
|
99
|
+
"aria-busy": B || void 0,
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ l("div", { ref: y, className: "aegis-detail-beside__list", children: x }),
|
|
102
|
+
!r && /* @__PURE__ */ D("div", { className: "aegis-detail-beside__side", children: [
|
|
103
|
+
/* @__PURE__ */ l("div", { ref: w }),
|
|
104
|
+
/* @__PURE__ */ l("div", { ref: f, className: "aegis-detail-beside__detail", children: C })
|
|
105
|
+
] })
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
) }) });
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
ee as DetailBeside
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=DetailBeside.js.map
|
|
@@ -0,0 +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.\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.\n */\n children: ReactNode;\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, the\n * selection changes or the selected row is clicked, the page scrolls at\n * once, as little as it takes to show the row and the detail whole, and\n * again whenever the list or the detail changes size, until the viewer\n * scrolls. The wrapper is `aria-busy` while the selected row is still on\n * its way.\n */\nexport function DetailBeside({\n columns,\n detail,\n children,\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\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 followRef.current = true;\n setBusy(true);\n queueMicrotask(() => {\n reveal();\n setBusy(false);\n });\n }, [reveal]);\n\n const placeRow = useCallback(\n (row: HTMLElement | null) => {\n const moved = row !== null && row === rowRef.current;\n rowRef.current = row;\n if (moved) {\n place();\n } else if (row === null) {\n followRef.current = false;\n setBusy(false);\n } else {\n revealSoon();\n }\n },\n [place, revealSoon],\n );\n\n const awaitRow = useCallback(() => {\n setBusy(true);\n }, []);\n\n useIsomorphicLayoutEffect(place);\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","scrollContainer","className","narrow","useMediaQuery","busy","setBusy","useState","listRef","useRef","spacerRef","detailRef","rowRef","followRef","revealedAtRef","place","useCallback","box","rowBox","spacer","reveal","distance","viewBoundsOf","scroller","scrollerOf","revealSoon","placeRow","moved","awaitRow","useIsomorphicLayoutEffect","list","observer","activate","event","useEffect","target","scrolled","inline","useMemo","slot","isolated","SelectedRowDetailContext","cls","jsxs"],"mappings":";;;;;;;AAgDA,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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AAAA,MACC,WAAWD;AAAA,MACX,OAAO,EAAE,iCAAiC3C,EAAA;AAAA,MAC1C,aAAWM,KAAQ;AAAA,MAEnB,UAAA;AAAA,QAAA,gBAAAR,EAAC,OAAA,EAAI,KAAKW,GAAS,WAAU,6BAC1B,UAAAR,GACH;AAAA,QACC,CAACG,KACA,gBAAAwC,EAAC,OAAA,EAAI,WAAU,6BACb,UAAA;AAAA,UAAA,gBAAA9C,EAAC,OAAA,EAAI,KAAKa,EAAA,CAAW;AAAA,4BACpB,OAAA,EAAI,KAAKC,GAAW,WAAU,+BAC5B,UAAA6B,EAAA,CACH;AAAA,QAAA,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAGN,EAAA,CACF;AAEJ;"}
|
|
@@ -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 i=require("react/jsx-runtime"),l=require("react"),P=require("@ant-design/icons");;/* empty css */const W=require("./selectedRowDetail.cjs");function X(c){const r=[],t=new Map;for(const s of c){const o=s.path.split("/");let f=r,u;for(const[w,_]of o.slice(0,-1).entries()){const g=`${u?.path??""}${_}/`;let d=t.get(g);d===void 0&&(d={kind:"directory",path:g,name:`${_}/`,depth:w,parentPath:u?.path,children:[],files:[]},t.set(g,d),f.push(d)),d.files.push(s),u=d,f=d.children}f.push({kind:"file",path:s.path,name:s.path.slice(s.path.lastIndexOf("/")+1),label:s.label,depth:o.length-1,parentPath:u?.path,note:s.note})}return r}function H(c,r,t=[]){const s=[...c.filter(o=>o.kind==="directory"),...c.filter(o=>o.kind==="file")];return s.forEach((o,f)=>{t.push({entry:o,position:f+1,setSize:s.length}),o.kind==="directory"&&r.has(o.path)&&H(o.children,r,t)}),t}function z(c){const r=c.split("/").slice(0,-1);return r.map((t,s)=>`${r.slice(0,s+1).join("/")}/`)}function Y({files:c,ariaLabel:r,selectedPath:t,onSelect:s,fileHref:o,fileTarget:f,expandedPaths:u,defaultExpandedPaths:w=[],onExpandedPathsChange:_,directoryNote:g,className:d}){const $=l.useId(),S=l.useContext(W.SelectedRowDetailContext),q=l.useMemo(()=>X(c),[c]),[E,I]=l.useState(()=>[...w,...z(t??"")]),[K,B]=l.useState(t);t!==K&&(B(t),I([...new Set([...E,...z(t??"")])]));const j=u??E,k=l.useMemo(()=>new Set(j),[j]),[L,U]=l.useState(),M=l.useRef(null),v=l.useMemo(()=>H(q,k),[q,k]),G=[L,t].find(e=>v.some(n=>n.entry.path===e))??v[0]?.entry.path,R=(e,n)=>{const a=n?[...j,e]:j.filter(p=>p!==e);u===void 0&&I(a),_?.(a)},b=e=>{const n=M.current?.querySelectorAll(':scope > [role="treeitem"], :scope > li > [role="treeitem"]').item(e);n instanceof HTMLElement&&n.focus()},F=e=>{e.kind==="directory"?R(e.path,!k.has(e.path)):s?.(e.path)},J=(e,n,a,p)=>{const h=a.kind==="directory"&&k.has(a.path);switch(e.key){case"ArrowDown":b(n+1);break;case"ArrowUp":b(n-1);break;case"Home":b(0);break;case"End":b(v.length-1);break;case"ArrowRight":h?b(n+1):a.kind==="directory"&&R(a.path,!0);break;case"ArrowLeft":if(h)R(a.path,!1);else if(a.parentPath!==void 0){const{parentPath:m}=a;b(v.findIndex(x=>x.entry.path===m))}break;case"Enter":if(p)return;F(a);break;case" ":p?e.currentTarget.click():F(a);break;default:return}e.preventDefault()},Q=["aegis-file-tree",d??""].filter(Boolean).join(" ");return i.jsx("ul",{ref:M,className:Q,role:"tree","aria-label":r,children:v.map(({entry:e,position:n,setSize:a},p)=>{const h=e.kind==="directory",m=!h&&e.path===t,x=h?g?g(e.path,e.files):String(e.files.length):e.note,N=`${$}-name-${String(p)}`,A=`${$}-note-${String(p)}`,D=h?void 0:o?.(e.path),O={className:m?"aegis-file-tree__item aegis-file-tree__item--selected":"aegis-file-tree__item",style:{"--aegis-file-tree-depth":e.depth},"aria-labelledby":N,"aria-describedby":x===void 0?void 0:A,"aria-level":e.depth+1,"aria-setsize":a,"aria-posinset":n,"aria-expanded":h?k.has(e.path):void 0,tabIndex:e.path===G?0:-1,onClick:()=>{F(e)},onKeyDown:V=>{J(V,p,e,D!==void 0)},onFocus:()=>{U(e.path)}},T=i.jsxs(i.Fragment,{children:[h?i.jsxs(i.Fragment,{children:[i.jsx(P.RightOutlined,{className:"aegis-file-tree__chevron","aria-hidden":!0}),i.jsx(P.FolderOutlined,{className:"aegis-file-tree__icon","aria-hidden":!0})]}):i.jsx(P.FileOutlined,{className:"aegis-file-tree__icon","aria-hidden":!0}),i.jsx("span",{id:N,className:"aegis-file-tree__name",title:e.path,children:e.kind==="file"?e.label??e.name:e.name}),x!==void 0&&i.jsx("span",{id:A,className:"aegis-file-tree__note",children:x})]}),C=m?S?.placeRow:void 0;return i.jsxs(l.Fragment,{children:[D===void 0?i.jsx("li",{ref:C,role:"treeitem","aria-selected":h?void 0:m,...O,children:T}):i.jsx("li",{role:"none",children:i.jsx("a",{ref:C,role:"treeitem","aria-selected":m,href:D,target:f,rel:f==="_blank"?"noopener noreferrer":void 0,...O,children:T})}),m&&S?.inline?i.jsx("li",{role:"none",children:S.inline}):null]},e.path)})})}exports.FileTree=Y;
|
|
2
2
|
//# sourceMappingURL=FileTree.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileTree.cjs","sources":["../../../src/components/ui/FileTree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { FileOutlined, FolderOutlined, RightOutlined } from '@ant-design/icons';\n\nimport './FileTree.css';\n\nexport interface FileTreeFile {\n /** Path from the tree root with `/` between segments, e.g. `tests/grading.toml`. */\n path: string;\n /** Shown in place of the file name, e.g. a note's name without `.md`. The row's title keeps the path. */\n label?: ReactNode;\n /** Trailing note, typically the file size. It is the row's accessible description, not part of its name. */\n note?: ReactNode;\n}\n\nexport interface FileTreeProps {\n files: FileTreeFile[];\n /** Accessible name of the tree. */\n ariaLabel: string;\n /**\n * Path of the selected file. Whenever it changes, the directories above\n * it open, unless `expandedPaths` controls them.\n */\n selectedPath?: string;\n /** Called with a file's path when it is clicked or activated with Enter or Space. */\n onSelect?: (path: string) => void;\n /**\n * A file's URL. With it each file row is a link, so the browser's own\n * link actions (open in a new tab, copy the address) work on it, and\n * opening the row follows the link as well as calling `onSelect`.\n */\n fileHref?: (path: string) => string;\n /** Where file links open, e.g. `_blank`. */\n fileTarget?: string;\n /** Open directories, each written with a trailing `/`, e.g. `tests/`. Omit it to let the tree track them. */\n expandedPaths?: string[];\n /** Directories open on first render when `expandedPaths` is omitted. */\n defaultExpandedPaths?: string[];\n /** Called with the open directories whenever one opens or closes. */\n onExpandedPathsChange?: (paths: string[]) => void;\n /**\n * A directory's trailing note, from its path (with a trailing `/`) and\n * every file below it at any depth, e.g. how many of them changed. Return\n * `undefined` for no note. Default: the number of files.\n */\n directoryNote?: (path: string, files: FileTreeFile[]) => ReactNode;\n className?: string;\n}\n\ninterface DirectoryEntry {\n kind: 'directory';\n /** The directory's path with a trailing `/`, e.g. `tests/cases/`. */\n path: string;\n name: string;\n depth: number;\n parentPath?: string;\n children: Entry[];\n /** Every file below the directory, at any depth. */\n files: FileTreeFile[];\n}\n\ninterface FileEntry {\n kind: 'file';\n path: string;\n name: string;\n label?: ReactNode;\n depth: number;\n parentPath?: string;\n note?: ReactNode;\n}\n\ntype Entry = DirectoryEntry | FileEntry;\n\ninterface Row {\n entry: Entry;\n position: number;\n setSize: number;\n}\n\nfunction buildEntries(files: FileTreeFile[]): Entry[] {\n const roots: Entry[] = [];\n const directories = new Map<string, DirectoryEntry>();\n for (const file of files) {\n const segments = file.path.split('/');\n let siblings = roots;\n let parent: DirectoryEntry | undefined;\n for (const [depth, segment] of segments.slice(0, -1).entries()) {\n const path = `${parent?.path ?? ''}${segment}/`;\n let directory = directories.get(path);\n if (directory === undefined) {\n directory = {\n kind: 'directory',\n path,\n name: `${segment}/`,\n depth,\n parentPath: parent?.path,\n children: [],\n files: [],\n };\n directories.set(path, directory);\n siblings.push(directory);\n }\n directory.files.push(file);\n parent = directory;\n siblings = directory.children;\n }\n siblings.push({\n kind: 'file',\n path: file.path,\n name: file.path.slice(file.path.lastIndexOf('/') + 1),\n label: file.label,\n depth: segments.length - 1,\n parentPath: parent?.path,\n note: file.note,\n });\n }\n return roots;\n}\n\n/** Rows of the open part of the tree; each level lists its directories before its files. */\nfunction visibleRows(\n entries: Entry[],\n expanded: ReadonlySet<string>,\n rows: Row[] = [],\n): Row[] {\n const ordered = [\n ...entries.filter((entry) => entry.kind === 'directory'),\n ...entries.filter((entry) => entry.kind === 'file'),\n ];\n ordered.forEach((entry, index) => {\n rows.push({ entry, position: index + 1, setSize: ordered.length });\n if (entry.kind === 'directory' && expanded.has(entry.path)) {\n visibleRows(entry.children, expanded, rows);\n }\n });\n return rows;\n}\n\nfunction ancestorPaths(path: string): string[] {\n const segments = path.split('/').slice(0, -1);\n return segments.map(\n (_, index) => `${segments.slice(0, index + 1).join('/')}/`,\n );\n}\n\nexport function FileTree({\n files,\n ariaLabel,\n selectedPath,\n onSelect,\n fileHref,\n fileTarget,\n expandedPaths,\n defaultExpandedPaths = [],\n onExpandedPathsChange,\n directoryNote,\n className,\n}: FileTreeProps) {\n const idPrefix = useId();\n const entries = useMemo(() => buildEntries(files), [files]);\n const [trackedPaths, setTrackedPaths] = useState<string[]>(() => [\n ...defaultExpandedPaths,\n ...ancestorPaths(selectedPath ?? ''),\n ]);\n const [revealedPath, setRevealedPath] = useState(selectedPath);\n if (selectedPath !== revealedPath) {\n setRevealedPath(selectedPath);\n setTrackedPaths([\n ...new Set([...trackedPaths, ...ancestorPaths(selectedPath ?? '')]),\n ]);\n }\n const openPaths = expandedPaths ?? trackedPaths;\n const expanded = useMemo(() => new Set(openPaths), [openPaths]);\n const [focusedPath, setFocusedPath] = useState<string>();\n const listRef = useRef<HTMLUListElement>(null);\n const rows = useMemo(\n () => visibleRows(entries, expanded),\n [entries, expanded],\n );\n const tabStop =\n [focusedPath, selectedPath].find((path) =>\n rows.some((row) => row.entry.path === path),\n ) ?? rows[0]?.entry.path;\n\n const setDirectoryExpanded = (path: string, open: boolean): void => {\n const next = open\n ? [...openPaths, path]\n : openPaths.filter((item) => item !== path);\n if (expandedPaths === undefined) {\n setTrackedPaths(next);\n }\n onExpandedPathsChange?.(next);\n };\n\n const focusRow = (index: number): void => {\n const item = listRef.current\n ?.querySelectorAll('[role=\"treeitem\"]')\n .item(index);\n if (item instanceof HTMLElement) {\n item.focus();\n }\n };\n\n const activate = (entry: Entry): void => {\n if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, !expanded.has(entry.path));\n } else {\n onSelect?.(entry.path);\n }\n };\n\n const handleKeyDown = (\n event: KeyboardEvent<HTMLElement>,\n index: number,\n entry: Entry,\n isLink: boolean,\n ): void => {\n const open = entry.kind === 'directory' && expanded.has(entry.path);\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 (open) {\n focusRow(index + 1);\n } else if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, true);\n }\n break;\n case 'ArrowLeft':\n if (open) {\n setDirectoryExpanded(entry.path, false);\n } else if (entry.parentPath !== undefined) {\n const { parentPath } = entry;\n focusRow(rows.findIndex((row) => row.entry.path === parentPath));\n }\n break;\n case 'Enter':\n // A link's own Enter follows it and clicks it, which activates it.\n if (isLink) {\n return;\n }\n activate(entry);\n break;\n case ' ':\n if (isLink) {\n event.currentTarget.click();\n } else {\n activate(entry);\n }\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const cls = ['aegis-file-tree', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <ul ref={listRef} className={cls} role=\"tree\" aria-label={ariaLabel}>\n {rows.map(({ entry, position, setSize }, index) => {\n const isDirectory = entry.kind === 'directory';\n const selected = !isDirectory && entry.path === selectedPath;\n const note = !isDirectory\n ? entry.note\n : directoryNote\n ? directoryNote(entry.path, entry.files)\n : String(entry.files.length);\n const nameId = `${idPrefix}-name-${String(index)}`;\n const noteId = `${idPrefix}-note-${String(index)}`;\n const href = isDirectory ? undefined : fileHref?.(entry.path);\n const itemProps: HTMLAttributes<HTMLElement> = {\n className: selected\n ? 'aegis-file-tree__item aegis-file-tree__item--selected'\n : 'aegis-file-tree__item',\n style: { '--aegis-file-tree-depth': entry.depth } as CSSProperties,\n 'aria-labelledby': nameId,\n 'aria-describedby': note === undefined ? undefined : noteId,\n 'aria-level': entry.depth + 1,\n 'aria-setsize': setSize,\n 'aria-posinset': position,\n 'aria-expanded': isDirectory ? expanded.has(entry.path) : undefined,\n tabIndex: entry.path === tabStop ? 0 : -1,\n onClick: () => {\n activate(entry);\n },\n onKeyDown: (event) => {\n handleKeyDown(event, index, entry, href !== undefined);\n },\n onFocus: () => {\n setFocusedPath(entry.path);\n },\n };\n const content = (\n <>\n {isDirectory ? (\n <>\n <RightOutlined\n className=\"aegis-file-tree__chevron\"\n aria-hidden\n />\n <FolderOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n </>\n ) : (\n <FileOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n )}\n <span\n id={nameId}\n className=\"aegis-file-tree__name\"\n title={entry.path}\n >\n {entry.kind === 'file' ? (entry.label ?? entry.name) : entry.name}\n </span>\n {note !== undefined && (\n <span id={noteId} className=\"aegis-file-tree__note\">\n {note}\n </span>\n )}\n </>\n );\n return href === undefined ? (\n <li\n key={entry.path}\n role=\"treeitem\"\n aria-selected={isDirectory ? undefined : selected}\n {...itemProps}\n >\n {content}\n </li>\n ) : (\n <li key={entry.path} role=\"none\">\n <a\n role=\"treeitem\"\n aria-selected={selected}\n href={href}\n target={fileTarget}\n rel={fileTarget === '_blank' ? 'noopener noreferrer' : undefined}\n {...itemProps}\n >\n {content}\n </a>\n </li>\n );\n })}\n </ul>\n );\n}\n"],"names":["buildEntries","files","roots","directories","file","segments","siblings","parent","depth","segment","path","directory","visibleRows","entries","expanded","rows","ordered","entry","index","ancestorPaths","_","FileTree","ariaLabel","selectedPath","onSelect","fileHref","fileTarget","expandedPaths","defaultExpandedPaths","onExpandedPathsChange","directoryNote","className","idPrefix","useId","useMemo","trackedPaths","setTrackedPaths","useState","revealedPath","setRevealedPath","openPaths","focusedPath","setFocusedPath","listRef","useRef","tabStop","row","setDirectoryExpanded","open","next","item","focusRow","activate","handleKeyDown","event","isLink","parentPath","cls","position","setSize","isDirectory","selected","note","nameId","noteId","href","itemProps","content","jsxs","Fragment","jsx","RightOutlined","FolderOutlined","FileOutlined"],"mappings":"qMAwFA,SAASA,EAAaC,EAAgC,CACpD,MAAMC,EAAiB,CAAA,EACjBC,MAAkB,IACxB,UAAWC,KAAQH,EAAO,CACxB,MAAMI,EAAWD,EAAK,KAAK,MAAM,GAAG,EACpC,IAAIE,EAAWJ,EACXK,EACJ,SAAW,CAACC,EAAOC,CAAO,IAAKJ,EAAS,MAAM,EAAG,EAAE,EAAE,UAAW,CAC9D,MAAMK,EAAO,GAAGH,GAAQ,MAAQ,EAAE,GAAGE,CAAO,IAC5C,IAAIE,EAAYR,EAAY,IAAIO,CAAI,EAChCC,IAAc,SAChBA,EAAY,CACV,KAAM,YACN,KAAAD,EACA,KAAM,GAAGD,CAAO,IAChB,MAAAD,EACA,WAAYD,GAAQ,KACpB,SAAU,CAAA,EACV,MAAO,CAAA,CAAC,EAEVJ,EAAY,IAAIO,EAAMC,CAAS,EAC/BL,EAAS,KAAKK,CAAS,GAEzBA,EAAU,MAAM,KAAKP,CAAI,EACzBG,EAASI,EACTL,EAAWK,EAAU,QACvB,CACAL,EAAS,KAAK,CACZ,KAAM,OACN,KAAMF,EAAK,KACX,KAAMA,EAAK,KAAK,MAAMA,EAAK,KAAK,YAAY,GAAG,EAAI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sBAAwB,OACtD,GAAGwC,EAEH,SAAAC,CAAA,CAAA,CACH,EAVOlD,EAAM,IAWf,CAEJ,CAAC,CAAA,CACH,CAEJ"}
|
|
1
|
+
{"version":3,"file":"FileTree.cjs","sources":["../../../src/components/ui/FileTree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n Fragment,\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n useContext,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { FileOutlined, FolderOutlined, RightOutlined } from '@ant-design/icons';\n\nimport './FileTree.css';\nimport { SelectedRowDetailContext } from './selectedRowDetail';\n\nexport interface FileTreeFile {\n /** Path from the tree root with `/` between segments, e.g. `tests/grading.toml`. */\n path: string;\n /** Shown in place of the file name, e.g. a note's name without `.md`. The row's title keeps the path. */\n label?: ReactNode;\n /** Trailing note, typically the file size. It is the row's accessible description, not part of its name. */\n note?: ReactNode;\n}\n\nexport interface FileTreeProps {\n files: FileTreeFile[];\n /** Accessible name of the tree. */\n ariaLabel: string;\n /**\n * Path of the selected file. Whenever it changes, the directories above\n * it open, unless `expandedPaths` controls them.\n */\n selectedPath?: string;\n /** Called with a file's path when it is clicked or activated with Enter or Space. */\n onSelect?: (path: string) => void;\n /**\n * A file's URL. With it each file row is a link, so the browser's own\n * link actions (open in a new tab, copy the address) work on it, and\n * opening the row follows the link as well as calling `onSelect`.\n */\n fileHref?: (path: string) => string;\n /** Where file links open, e.g. `_blank`. */\n fileTarget?: string;\n /** Open directories, each written with a trailing `/`, e.g. `tests/`. Omit it to let the tree track them. */\n expandedPaths?: string[];\n /** Directories open on first render when `expandedPaths` is omitted. */\n defaultExpandedPaths?: string[];\n /** Called with the open directories whenever one opens or closes. */\n onExpandedPathsChange?: (paths: string[]) => void;\n /**\n * A directory's trailing note, from its path (with a trailing `/`) and\n * every file below it at any depth, e.g. how many of them changed. Return\n * `undefined` for no note. Default: the number of files.\n */\n directoryNote?: (path: string, files: FileTreeFile[]) => ReactNode;\n className?: string;\n}\n\ninterface DirectoryEntry {\n kind: 'directory';\n /** The directory's path with a trailing `/`, e.g. `tests/cases/`. */\n path: string;\n name: string;\n depth: number;\n parentPath?: string;\n children: Entry[];\n /** Every file below the directory, at any depth. */\n files: FileTreeFile[];\n}\n\ninterface FileEntry {\n kind: 'file';\n path: string;\n name: string;\n label?: ReactNode;\n depth: number;\n parentPath?: string;\n note?: ReactNode;\n}\n\ntype Entry = DirectoryEntry | FileEntry;\n\ninterface Row {\n entry: Entry;\n position: number;\n setSize: number;\n}\n\nfunction buildEntries(files: FileTreeFile[]): Entry[] {\n const roots: Entry[] = [];\n const directories = new Map<string, DirectoryEntry>();\n for (const file of files) {\n const segments = file.path.split('/');\n let siblings = roots;\n let parent: DirectoryEntry | undefined;\n for (const [depth, segment] of segments.slice(0, -1).entries()) {\n const path = `${parent?.path ?? ''}${segment}/`;\n let directory = directories.get(path);\n if (directory === undefined) {\n directory = {\n kind: 'directory',\n path,\n name: `${segment}/`,\n depth,\n parentPath: parent?.path,\n children: [],\n files: [],\n };\n directories.set(path, directory);\n siblings.push(directory);\n }\n directory.files.push(file);\n parent = directory;\n siblings = directory.children;\n }\n siblings.push({\n kind: 'file',\n path: file.path,\n name: file.path.slice(file.path.lastIndexOf('/') + 1),\n label: file.label,\n depth: segments.length - 1,\n parentPath: parent?.path,\n note: file.note,\n });\n }\n return roots;\n}\n\n/** Rows of the open part of the tree; each level lists its directories before its files. */\nfunction visibleRows(\n entries: Entry[],\n expanded: ReadonlySet<string>,\n rows: Row[] = [],\n): Row[] {\n const ordered = [\n ...entries.filter((entry) => entry.kind === 'directory'),\n ...entries.filter((entry) => entry.kind === 'file'),\n ];\n ordered.forEach((entry, index) => {\n rows.push({ entry, position: index + 1, setSize: ordered.length });\n if (entry.kind === 'directory' && expanded.has(entry.path)) {\n visibleRows(entry.children, expanded, rows);\n }\n });\n return rows;\n}\n\nfunction ancestorPaths(path: string): string[] {\n const segments = path.split('/').slice(0, -1);\n return segments.map(\n (_, index) => `${segments.slice(0, index + 1).join('/')}/`,\n );\n}\n\nexport function FileTree({\n files,\n ariaLabel,\n selectedPath,\n onSelect,\n fileHref,\n fileTarget,\n expandedPaths,\n defaultExpandedPaths = [],\n onExpandedPathsChange,\n directoryNote,\n className,\n}: FileTreeProps) {\n const idPrefix = useId();\n const selection = useContext(SelectedRowDetailContext);\n const entries = useMemo(() => buildEntries(files), [files]);\n const [trackedPaths, setTrackedPaths] = useState<string[]>(() => [\n ...defaultExpandedPaths,\n ...ancestorPaths(selectedPath ?? ''),\n ]);\n const [revealedPath, setRevealedPath] = useState(selectedPath);\n if (selectedPath !== revealedPath) {\n setRevealedPath(selectedPath);\n setTrackedPaths([\n ...new Set([...trackedPaths, ...ancestorPaths(selectedPath ?? '')]),\n ]);\n }\n const openPaths = expandedPaths ?? trackedPaths;\n const expanded = useMemo(() => new Set(openPaths), [openPaths]);\n const [focusedPath, setFocusedPath] = useState<string>();\n const listRef = useRef<HTMLUListElement>(null);\n const rows = useMemo(\n () => visibleRows(entries, expanded),\n [entries, expanded],\n );\n const tabStop =\n [focusedPath, selectedPath].find((path) =>\n rows.some((row) => row.entry.path === path),\n ) ?? rows[0]?.entry.path;\n\n const setDirectoryExpanded = (path: string, open: boolean): void => {\n const next = open\n ? [...openPaths, path]\n : openPaths.filter((item) => item !== path);\n if (expandedPaths === undefined) {\n setTrackedPaths(next);\n }\n onExpandedPathsChange?.(next);\n };\n\n const focusRow = (index: number): void => {\n // Only the tree's own rows: a detail drawn among them may hold a tree.\n const item = listRef.current\n ?.querySelectorAll(\n ':scope > [role=\"treeitem\"], :scope > li > [role=\"treeitem\"]',\n )\n .item(index);\n if (item instanceof HTMLElement) {\n item.focus();\n }\n };\n\n const activate = (entry: Entry): void => {\n if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, !expanded.has(entry.path));\n } else {\n onSelect?.(entry.path);\n }\n };\n\n const handleKeyDown = (\n event: KeyboardEvent<HTMLElement>,\n index: number,\n entry: Entry,\n isLink: boolean,\n ): void => {\n const open = entry.kind === 'directory' && expanded.has(entry.path);\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 (open) {\n focusRow(index + 1);\n } else if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, true);\n }\n break;\n case 'ArrowLeft':\n if (open) {\n setDirectoryExpanded(entry.path, false);\n } else if (entry.parentPath !== undefined) {\n const { parentPath } = entry;\n focusRow(rows.findIndex((row) => row.entry.path === parentPath));\n }\n break;\n case 'Enter':\n // A link's own Enter follows it and clicks it, which activates it.\n if (isLink) {\n return;\n }\n activate(entry);\n break;\n case ' ':\n if (isLink) {\n event.currentTarget.click();\n } else {\n activate(entry);\n }\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const cls = ['aegis-file-tree', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <ul ref={listRef} className={cls} role=\"tree\" aria-label={ariaLabel}>\n {rows.map(({ entry, position, setSize }, index) => {\n const isDirectory = entry.kind === 'directory';\n const selected = !isDirectory && entry.path === selectedPath;\n const note = !isDirectory\n ? entry.note\n : directoryNote\n ? directoryNote(entry.path, entry.files)\n : String(entry.files.length);\n const nameId = `${idPrefix}-name-${String(index)}`;\n const noteId = `${idPrefix}-note-${String(index)}`;\n const href = isDirectory ? undefined : fileHref?.(entry.path);\n const itemProps: HTMLAttributes<HTMLElement> = {\n className: selected\n ? 'aegis-file-tree__item aegis-file-tree__item--selected'\n : 'aegis-file-tree__item',\n style: { '--aegis-file-tree-depth': entry.depth } as CSSProperties,\n 'aria-labelledby': nameId,\n 'aria-describedby': note === undefined ? undefined : noteId,\n 'aria-level': entry.depth + 1,\n 'aria-setsize': setSize,\n 'aria-posinset': position,\n 'aria-expanded': isDirectory ? expanded.has(entry.path) : undefined,\n tabIndex: entry.path === tabStop ? 0 : -1,\n onClick: () => {\n activate(entry);\n },\n onKeyDown: (event) => {\n handleKeyDown(event, index, entry, href !== undefined);\n },\n onFocus: () => {\n setFocusedPath(entry.path);\n },\n };\n const content = (\n <>\n {isDirectory ? (\n <>\n <RightOutlined\n className=\"aegis-file-tree__chevron\"\n aria-hidden\n />\n <FolderOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n </>\n ) : (\n <FileOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n )}\n <span\n id={nameId}\n className=\"aegis-file-tree__name\"\n title={entry.path}\n >\n {entry.kind === 'file' ? (entry.label ?? entry.name) : entry.name}\n </span>\n {note !== undefined && (\n <span id={noteId} className=\"aegis-file-tree__note\">\n {note}\n </span>\n )}\n </>\n );\n const rowRef = selected ? selection?.placeRow : undefined;\n return (\n <Fragment key={entry.path}>\n {href === undefined ? (\n <li\n ref={rowRef}\n role=\"treeitem\"\n aria-selected={isDirectory ? undefined : selected}\n {...itemProps}\n >\n {content}\n </li>\n ) : (\n <li role=\"none\">\n <a\n ref={rowRef}\n role=\"treeitem\"\n aria-selected={selected}\n href={href}\n target={fileTarget}\n rel={\n fileTarget === '_blank' ? 'noopener noreferrer' : undefined\n }\n {...itemProps}\n >\n {content}\n </a>\n </li>\n )}\n {selected && selection?.inline ? (\n <li role=\"none\">{selection.inline}</li>\n ) : null}\n </Fragment>\n );\n })}\n </ul>\n );\n}\n"],"names":["buildEntries","files","roots","directories","file","segments","siblings","parent","depth","segment","path","directory","visibleRows","entries","expanded","rows","ordered","entry","index","ancestorPaths","_","FileTree","ariaLabel","selectedPath","onSelect","fileHref","fileTarget","expandedPaths","defaultExpandedPaths","onExpandedPathsChange","directoryNote","className","idPrefix","useId","selection","useContext","SelectedRowDetailContext","useMemo","trackedPaths","setTrackedPaths","useState","revealedPath","setRevealedPath","openPaths","focusedPath","setFocusedPath","listRef","useRef","tabStop","row","setDirectoryExpanded","open","next","item","focusRow","activate","handleKeyDown","event","isLink","parentPath","cls","position","setSize","isDirectory","selected","note","name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