@perses-dev/components 0.55.1 → 0.56.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AlignSelector/AlignSelector.js +115 -25
- package/dist/AlignSelector/AlignSelector.js.map +1 -1
- package/dist/CodeEditor/CodeEditor.d.ts +19 -0
- package/dist/CodeEditor/CodeEditor.d.ts.map +1 -0
- package/dist/CodeEditor/CodeEditor.js +122 -0
- package/dist/CodeEditor/CodeEditor.js.map +1 -0
- package/dist/ColorPicker/ColorPicker.js +153 -61
- package/dist/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js +147 -52
- package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +144 -41
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/DensitySelector/DensitySelector.js +53 -20
- package/dist/DensitySelector/DensitySelector.js.map +1 -1
- package/dist/Dialog/Dialog.d.ts +3 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +202 -49
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js +79 -27
- package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/DragAndDrop/DragAndDropList.js +184 -113
- package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
- package/dist/DragAndDrop/DragButton.js +131 -52
- package/dist/DragAndDrop/DragButton.js.map +1 -1
- package/dist/DragAndDrop/DropIndicator.js +51 -26
- package/dist/DragAndDrop/DropIndicator.js.map +1 -1
- package/dist/Drawer/Drawer.js +75 -15
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/EChart/EChart.js +179 -90
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/ErrorAlert.js +14 -4
- package/dist/ErrorAlert.js.map +1 -1
- package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js +463 -190
- package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js.map +1 -1
- package/dist/FontSizeSelector/FontSizeSelector.js +82 -50
- package/dist/FontSizeSelector/FontSizeSelector.js.map +1 -1
- package/dist/FormEditor/FormActions.js +88 -14
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.js +246 -99
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.js +90 -25
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +105 -42
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/JSONEditor.d.ts +2 -6
- package/dist/JSONEditor.d.ts.map +1 -1
- package/dist/JSONEditor.js +24 -37
- package/dist/JSONEditor.js.map +1 -1
- package/dist/Legend/CompactLegend.js +77 -27
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.js +184 -82
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/LegendColorBadge.js +54 -9
- package/dist/Legend/LegendColorBadge.js.map +1 -1
- package/dist/Legend/ListLegend.js +46 -16
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.js +184 -48
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +90 -48
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +2 -2
- package/dist/Legend/legend-model.d.ts.map +1 -1
- package/dist/Legend/legend-model.js.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.js +148 -67
- package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
- package/dist/ModeSelector/ModeSelector.js +61 -19
- package/dist/ModeSelector/ModeSelector.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +20 -9
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +130 -54
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +17 -6
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +76 -28
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
- package/dist/Overlay/Overlay.js +71 -27
- package/dist/Overlay/Overlay.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +96 -38
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/RepeatGrid/RepeatGrid.js +117 -45
- package/dist/RepeatGrid/RepeatGrid.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +99 -38
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
- package/dist/SortSelector/SortSelector.js +51 -18
- package/dist/SortSelector/SortSelector.js.map +1 -1
- package/dist/SortSelector/SortSelectorButtons.js +109 -25
- package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
- package/dist/Table/InnerTable.js +46 -15
- package/dist/Table/InnerTable.js.map +1 -1
- package/dist/Table/Table.d.ts +3 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +410 -158
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableBody.js +15 -4
- package/dist/Table/TableBody.js.map +1 -1
- package/dist/Table/TableCell.js +294 -107
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +101 -32
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableFoot.js +15 -4
- package/dist/Table/TableFoot.js.map +1 -1
- package/dist/Table/TableHead.js +15 -4
- package/dist/Table/TableHead.js.map +1 -1
- package/dist/Table/TableHeaderCell.js +119 -62
- package/dist/Table/TableHeaderCell.js.map +1 -1
- package/dist/Table/TableRow.js +33 -9
- package/dist/Table/TableRow.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +5 -4
- package/dist/Table/TableToolbar.d.ts.map +1 -1
- package/dist/Table/TableToolbar.js +172 -100
- package/dist/Table/TableToolbar.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts +11 -11
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +442 -204
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +27 -7
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +6 -5
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.js +57 -32
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -1
- package/dist/Table/hooks/useTableKeyboardNav.js +115 -74
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +86 -69
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +44 -15
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +33 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +137 -47
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +341 -174
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +368 -162
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +580 -210
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +189 -65
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +168 -78
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js +38 -11
- package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +229 -72
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +73 -27
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +221 -121
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +44 -38
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeZoneSelector.js +131 -36
- package/dist/TimeZoneSelector.js.map +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js +18 -7
- package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js +830 -334
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +252 -90
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js +170 -59
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js +800 -322
- package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js +218 -91
- package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
- package/dist/YAMLEditor/YAMLEditor.d.ts +12 -0
- package/dist/YAMLEditor/YAMLEditor.d.ts.map +1 -0
- package/dist/YAMLEditor/YAMLEditor.js +41 -0
- package/dist/YAMLEditor/YAMLEditor.js.map +1 -0
- package/dist/YAMLEditor/index.d.ts +2 -0
- package/dist/YAMLEditor/index.d.ts.map +1 -0
- package/dist/YAMLEditor/index.js +15 -0
- package/dist/YAMLEditor/index.js.map +1 -0
- package/dist/YAMLEditor/yaml-utils.d.ts +11 -0
- package/dist/YAMLEditor/yaml-utils.d.ts.map +1 -0
- package/dist/YAMLEditor/yaml-utils.js +52 -0
- package/dist/YAMLEditor/yaml-utils.js.map +1 -0
- package/dist/YAxisLabel.js +64 -20
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/context/ChartsProvider.js +32 -16
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/context/ItemActionsProvider.js +110 -61
- package/dist/context/ItemActionsProvider.js.map +1 -1
- package/dist/context/SelectionProvider.js +170 -66
- package/dist/context/SelectionProvider.js.map +1 -1
- package/dist/context/SnackbarProvider.js +101 -44
- package/dist/context/SnackbarProvider.js.map +1 -1
- package/dist/context/TimeZoneProvider.js +35 -14
- package/dist/context/TimeZoneProvider.js.map +1 -1
- package/dist/controls/TextField.js +86 -25
- package/dist/controls/TextField.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/browser-storage.js +64 -34
- package/dist/utils/browser-storage.js.map +1 -1
- package/package.json +15 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';\nimport type { Column, ColumnSizingInfoState, ColumnSizingState, HeaderGroup, Row } from '@tanstack/react-table';\nimport { flexRender } from '@tanstack/react-table';\nimport type { ReactElement } from 'react';\nimport { forwardRef, useMemo, useRef } from 'react';\nimport type { TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { TableVirtuoso } from 'react-virtuoso';\n\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\nimport { InnerTable } from './InnerTable';\nimport type { TableCellConfigs, TableProps, TableRowEventOpts } from './model/table-model';\nimport { TableBody } from './TableBody';\nimport type { TableCellProps } from './TableCell';\nimport { TableCell } from './TableCell';\nimport { TableFoot } from './TableFoot';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableRow } from './TableRow';\nimport type { TableToolbarProps } from './TableToolbar';\nimport { TableToolbar } from './TableToolbar';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\ntype TableContext<TableData> = {\n width: number | string;\n density: VirtualizedTableProps<TableData>['density'];\n onTableKeyDown: React.KeyboardEventHandler<HTMLTableElement>;\n onTableBlur: React.FocusEventHandler<HTMLTableElement>;\n onRowClick: VirtualizedTableProps<TableData>['onRowClick'];\n onRowMouseOver: VirtualizedTableProps<TableData>['onRowMouseOver'];\n onRowMouseOut: VirtualizedTableProps<TableData>['onRowMouseOut'];\n};\n\n// Defined outside VirtualizedTable so the object reference is stable and\n// TableVirtuoso never remounts its internal components due to a changed prop.\n// Props that vary per-render are passed via the `context` prop instead.\nconst VirtuosoTableComponents: TableComponents<Row<unknown>, TableContext<unknown>> = {\n Scroller: forwardRef(({ context: _, ...props }, ref) => <VirtualizedTableContainer {...props} ref={ref} />),\n Table: ({ context, ...props }): ReactElement => (\n <InnerTable\n {...props}\n width={context.width}\n density={context.density}\n onKeyDown={context.onTableKeyDown}\n onBlur={context.onTableBlur}\n />\n ),\n TableHead: forwardRef(({ context: _, ...props }, ref) => <TableHead {...props} ref={ref} />),\n TableFoot: forwardRef(({ context: _, ...props }, ref) => <TableFoot {...props} ref={ref} />),\n TableRow: ({ item, context, ...props }): ReactElement | null => {\n if (!item) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: item.id, index: item.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => context.onRowClick(e, item.id)}\n density={context.density}\n onMouseOver={(e) => {\n context.onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n context.onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody: forwardRef(({ context: _, ...props }, ref) => <TableBody {...props} ref={ref} />),\n};\n\nexport type VirtualizedTableProps<TableData> = Required<\n Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnHeight' | 'defaultColumnWidth'>\n> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n columnSizing: ColumnSizingState;\n columnSizingInfo: ColumnSizingInfoState;\n cellConfigs?: TableCellConfigs;\n rowCount: number;\n toolbarConfig: Pick<\n TableToolbarProps<TableData>,\n | 'isSearchEnabled'\n | 'globalFilter'\n | 'onGlobalFilterChange'\n | 'isColumnFilterEnabled'\n | 'columns'\n | 'columnFilterMenuMaxHeight'\n | 'isExpandAllEnabled'\n | 'isAllExpanded'\n | 'onExpandAllChange'\n >;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n defaultColumnWidth,\n defaultColumnHeight,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n rows,\n columns,\n headers,\n cellConfigs,\n pagination,\n onPaginationChange,\n rowCount,\n toolbarConfig,\n}: VirtualizedTableProps<TableData>): ReactElement {\n 'use no memo'; // TanStack Table row and column getters read mutable state behind stable identities.\n\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const tableContext: TableContext<TableData> = useMemo(\n () => ({\n width,\n density,\n onTableKeyDown: keyboardNav.onTableKeyDown,\n onTableBlur: keyboardNav.onTableBlur,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n }),\n [width, density, keyboardNav.onTableKeyDown, keyboardNav.onTableBlur, onRowClick, onRowMouseOver, onRowMouseOut],\n );\n\n const handleChangePage = (_event: React.MouseEvent<HTMLButtonElement> | null, newPage: number): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ ...pagination, pageIndex: newPage });\n };\n\n const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ pageIndex: 0, pageSize: parseInt(event.target.value, 10) });\n };\n\n /**\n * Instead of calling `column.getSize()` on every render for every header\n * and especially every data cell (very expensive),\n * we calculate all column sizes once per render at the root table level\n * and pass the column sizes down as CSS variables to the <table> element.\n */\n const columnSizeVars: { [key: string]: number } = {};\n headers.forEach((headerGroup) => {\n headerGroup.headers\n .filter((header) => header.column.getCanResize())\n .forEach((header) => {\n columnSizeVars[`--header-${header.id}-size`] = header.getSize();\n columnSizeVars[`--col-${header.column.id}-size`] = header.column.getSize();\n });\n });\n\n return (\n <Box style={{ width, height, ...columnSizeVars }}>\n <TableToolbar {...toolbarConfig} width={width} />\n <TableVirtuoso\n ref={virtuosoRef}\n data={rows}\n components={VirtuosoTableComponents as TableComponents<Row<TableData>, TableContext<TableData>>}\n context={tableContext}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={\n header.column.getCanResize()\n ? `calc(var(--header-${header?.id}-size) * 1px)`\n : column.getSize() || defaultColumnWidth\n }\n defaultColumnHeight={defaultColumnHeight}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n resizeConfig={\n header.column.getCanResize()\n ? {\n resizeHandler: header.getResizeHandler(),\n resetSizeHandler: header.column.resetSize,\n isResizing: header.column.getIsResizing(),\n }\n : undefined\n }\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n fixedFooterContent={\n pagination\n ? (): ReactElement => (\n <MuiTableRow sx={{ backgroundColor: (theme) => theme.palette.background.default }}>\n <TablePagination\n colSpan={columns.length}\n count={rowCount}\n page={pagination.pageIndex}\n rowsPerPage={pagination.pageSize}\n onPageChange={handleChangePage}\n onRowsPerPageChange={handleChangeRowsPerPage}\n />\n </MuiTableRow>\n )\n : undefined\n }\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellConfig = cellConfigs?.[cellContext.cell.id];\n\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;\n\n /*\n IMPORTANT:\n If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)\n Components have no access to any context (Which is intentional and correct)\n We may want to add parameters to a link from neighboring cells in the future as well.\n If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)\n */\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n /* this has been specifically added for the data link,\n therefore, non string and numeric values should be excluded\n */\n const adjacentCellsValuesMap = Object.entries(row.original as Record<string, unknown>)\n ?.filter(([_, value]) => ['string', 'number'].includes(typeof value))\n .reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: String(value),\n }),\n {},\n );\n\n return (\n <TableCell\n key={cell.id}\n data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\n width={\n cell.column.getCanResize()\n ? `calc(var(--col-${cell.column.id}-size) * 1px)`\n : cell.column.getSize() || defaultColumnWidth\n }\n defaultColumnHeight={defaultColumnHeight}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n dataLink={cell.column.columnDef.meta?.dataLink}\n adjacentCellsValuesMap={adjacentCellsValuesMap}\n >\n {cellConfig?.text || cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["Box","TablePagination","TableRow","MuiTableRow","flexRender","forwardRef","useMemo","useRef","TableVirtuoso","useVirtualizedTableKeyboardNav","InnerTable","TableBody","TableCell","TableFoot","TableHead","TableHeaderCell","TableToolbar","VirtualizedTableContainer","VirtuosoTableComponents","Scroller","context","_","props","ref","Table","width","density","onKeyDown","onTableKeyDown","onBlur","onTableBlur","item","rowEventOpts","id","index","onClick","e","onRowClick","onMouseOver","onRowMouseOver","onMouseOut","onRowMouseOut","VirtualizedTable","height","defaultColumnWidth","defaultColumnHeight","rows","columns","headers","cellConfigs","pagination","onPaginationChange","rowCount","toolbarConfig","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","tableContext","handleChangePage","_event","newPage","pageIndex","handleChangeRowsPerPage","event","pageSize","parseInt","target","value","columnSizeVars","forEach","headerGroup","filter","header","getCanResize","getSize","style","data","components","rangeChanged","fixedHeaderContent","map","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","resizeConfig","resizeHandler","getResizeHandler","resetSizeHandler","resetSize","isResizing","getIsResizing","getContext","fixedFooterContent","sx","backgroundColor","theme","palette","background","default","colSpan","count","page","rowsPerPage","onPageChange","onRowsPerPageChange","itemContent","getVisibleCells","cell","cells","cellContext","cellConfig","cellRenderFn","cellContent","cellDescriptionDef","cellDescription","adjacentCellsValuesMap","Object","entries","original","includes","reduce","acc","key","String","data-testid","title","text","color","textColor","dataLink"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,EAAEC,eAAe,EAAEC,YAAYC,WAAW,QAAQ,gBAAgB;AAE9E,SAASC,UAAU,QAAQ,wBAAwB;AAEnD,SAASC,UAAU,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAEpD,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,SAASC,8BAA8B,QAAQ,4CAAyC;AACxF,SAASC,UAAU,QAAQ,kBAAe;AAE1C,SAASC,SAAS,QAAQ,iBAAc;AAExC,SAASC,SAAS,QAAQ,iBAAc;AACxC,SAASC,SAAS,QAAQ,iBAAc;AACxC,SAASC,SAAS,QAAQ,iBAAc;AACxC,SAASC,eAAe,QAAQ,uBAAoB;AACpD,SAASb,QAAQ,QAAQ,gBAAa;AAEtC,SAASc,YAAY,QAAQ,oBAAiB;AAC9C,SAASC,yBAAyB,QAAQ,iCAA8B;AAiBxE,yEAAyE;AACzE,8EAA8E;AAC9E,wEAAwE;AACxE,MAAMC,0BAAgF;IACpFC,wBAAUd,WAAW,CAAC,EAAEe,SAASC,CAAC,EAAE,GAAGC,OAAO,EAAEC,oBAAQ,KAACN;YAA2B,GAAGK,KAAK;YAAEC,KAAKA;;IACnGC,OAAO,CAAC,EAAEJ,OAAO,EAAE,GAAGE,OAAO,iBAC3B,KAACZ;YACE,GAAGY,KAAK;YACTG,OAAOL,QAAQK,KAAK;YACpBC,SAASN,QA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MtD,YAAYuD,WAAW,CAACnB;gCAC9CoB,eAAerB,MAAM;gCACrBsB,cAActB,MAAM+C,MAAM/E,MAAM,GAAG;gCACnCgD,aAAaA;gCACbkD,OAAOjB,YAAYkB,aAAa1D;gCAChCwB,iBAAiBgB,YAAYhB,mBAAmBxB;gCAChD2D,UAAUtB,KAAKxE,MAAM,CAACuC,SAAS,CAACC,IAAI,EAAEsD;gCACtCd,wBAAwBA;0CAEvBL,YAAYgB,QAAQd;+BArBhBL,KAAK7G,EAAE;wBAwBlB;;gBAGN;;;;AAIR"}
|
|
1
|
+
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';\nimport type { ReactTable, Row, RowData } from '@tanstack/react-table';\nimport { flexRender } from '@tanstack/react-table';\nimport type { ReactElement } from 'react';\nimport { forwardRef, useMemo, useRef } from 'react';\nimport type { TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { TableVirtuoso } from 'react-virtuoso';\n\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\nimport { InnerTable } from './InnerTable';\nimport type { TableCellConfigs, TableFeatures, TableProps, TableRowEventOpts } from './model/table-model';\nimport { TableBody } from './TableBody';\nimport type { TableCellProps } from './TableCell';\nimport { TableCell } from './TableCell';\nimport { TableFoot } from './TableFoot';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableRow } from './TableRow';\nimport type { TableToolbarProps } from './TableToolbar';\nimport { TableToolbar } from './TableToolbar';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\ntype TableContext<TableData extends RowData> = {\n width: number | string;\n density: VirtualizedTableProps<TableData>['density'];\n onTableKeyDown: React.KeyboardEventHandler<HTMLTableElement>;\n onTableBlur: React.FocusEventHandler<HTMLTableElement>;\n onRowClick: VirtualizedTableProps<TableData>['onRowClick'];\n onRowMouseOver: VirtualizedTableProps<TableData>['onRowMouseOver'];\n onRowMouseOut: VirtualizedTableProps<TableData>['onRowMouseOut'];\n};\n\n// Defined outside VirtualizedTable so the object reference is stable and\n// TableVirtuoso never remounts its internal components due to a changed prop.\n// Props that vary per-render are passed via the `context` prop instead.\nconst VirtuosoTableComponents: TableComponents<Row<TableFeatures, RowData>, TableContext<RowData>> = {\n Scroller: forwardRef(({ context: _, ...props }, ref) => <VirtualizedTableContainer {...props} ref={ref} />),\n Table: ({ context, ...props }): ReactElement => (\n <InnerTable\n {...props}\n width={context.width}\n density={context.density}\n onKeyDown={context.onTableKeyDown}\n onBlur={context.onTableBlur}\n />\n ),\n TableHead: forwardRef(({ context: _, ...props }, ref) => <TableHead {...props} ref={ref} />),\n TableFoot: forwardRef(({ context: _, ...props }, ref) => <TableFoot {...props} ref={ref} />),\n TableRow: ({ item, context, ...props }): ReactElement | null => {\n if (!item) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: item.id, index: item.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => context.onRowClick(e, item)}\n density={context.density}\n onMouseOver={(e) => {\n context.onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n context.onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody: forwardRef(({ context: _, ...props }, ref) => <TableBody {...props} ref={ref} />),\n};\n\nexport type VirtualizedTableProps<TableData extends RowData> = Required<\n Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnHeight' | 'defaultColumnWidth'>\n> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, row: Row<TableFeatures, TableData>) => void;\n /**\n * The value returned by `useTable`. Its identity changes whenever table\n * state or options change, unlike the row, column, and header objects it\n * returns, which keep their identities across state changes.\n */\n table: ReactTable<TableFeatures, TableData>;\n cellConfigs?: TableCellConfigs;\n toolbarConfig: Pick<\n TableToolbarProps<TableData>,\n | 'isSearchEnabled'\n | 'globalFilter'\n | 'onGlobalFilterChange'\n | 'isColumnFilterEnabled'\n | 'columns'\n | 'columnFilterMenuMaxHeight'\n | 'isExpandAllEnabled'\n | 'isAllExpanded'\n | 'onExpandAllChange'\n >;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData extends RowData>({\n width,\n height,\n density,\n defaultColumnWidth,\n defaultColumnHeight,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n table,\n cellConfigs,\n pagination,\n onPaginationChange,\n toolbarConfig,\n}: VirtualizedTableProps<TableData>): ReactElement {\n // Rows, columns, and headers keep their identities when table state such as\n // selection, sorting, or sizing changes. Anything that reads that state\n // through their methods must call `table` directly in the same expression or\n // callback, so the React Compiler invalidates it whenever `table` changes.\n const rows = table.getRowModel().rows;\n const columnCount = table.getVisibleFlatColumns().length;\n\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columnCount,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const tableContext: TableContext<TableData> = useMemo(\n () => ({\n width,\n density,\n onTableKeyDown: keyboardNav.onTableKeyDown,\n onTableBlur: keyboardNav.onTableBlur,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n }),\n [width, density, keyboardNav.onTableKeyDown, keyboardNav.onTableBlur, onRowClick, onRowMouseOver, onRowMouseOut],\n );\n\n const handleChangePage = (_event: React.MouseEvent<HTMLButtonElement> | null, newPage: number): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ ...pagination, pageIndex: newPage });\n };\n\n const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ pageIndex: 0, pageSize: parseInt(event.target.value, 10) });\n };\n\n /**\n * Instead of calling `column.getSize()` on every render for every header\n * and especially every data cell (very expensive),\n * we calculate all column sizes once per render at the root table level\n * and pass the column sizes down as CSS variables to the <table> element.\n */\n const columnSizeVars: { [key: string]: number } = {};\n table.getHeaderGroups().forEach((headerGroup) => {\n headerGroup.headers\n .filter((header) => header.column.getCanResize())\n .forEach((header) => {\n columnSizeVars[`--header-${header.id}-size`] = header.getSize();\n columnSizeVars[`--col-${header.column.id}-size`] = header.column.getSize();\n });\n });\n\n return (\n <Box style={{ width, height, ...columnSizeVars }}>\n <TableToolbar {...toolbarConfig} width={width} />\n <TableVirtuoso\n ref={virtuosoRef}\n data={rows}\n components={VirtuosoTableComponents as TableComponents<Row<TableFeatures, TableData>, TableContext<TableData>>}\n context={tableContext}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {table.getHeaderGroups().map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={\n header.column.getCanResize()\n ? `calc(var(--header-${header?.id}-size) * 1px)`\n : column.getSize() || defaultColumnWidth\n }\n defaultColumnHeight={defaultColumnHeight}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n resizeConfig={\n header.column.getCanResize()\n ? {\n resizeHandler: header.getResizeHandler(),\n resetSizeHandler: () => header.column.resetSize(),\n isResizing: header.column.getIsResizing(),\n }\n : undefined\n }\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n fixedFooterContent={\n pagination\n ? (): ReactElement => (\n <MuiTableRow sx={{ backgroundColor: (theme) => theme.palette.background.default }}>\n <TablePagination\n colSpan={table.getVisibleFlatColumns().length}\n count={table.getRowCount()}\n page={pagination.pageIndex}\n rowsPerPage={pagination.pageSize}\n onPageChange={handleChangePage}\n onRowsPerPageChange={handleChangeRowsPerPage}\n />\n </MuiTableRow>\n )\n : undefined\n }\n itemContent={(index) => {\n const row = table.getRowModel().rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellConfig = cellConfigs?.[cellContext.cell.id];\n\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;\n\n /*\n IMPORTANT:\n If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)\n Components have no access to any context (Which is intentional and correct)\n We may want to add parameters to a link from neighboring cells in the future as well.\n If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)\n */\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n /* this has been specifically added for the data link,\n therefore, non string and numeric values should be excluded\n */\n const adjacentCellsValuesMap = Object.entries(row.original as Record<string, unknown>)\n ?.filter(([_, value]) => ['string', 'number'].includes(typeof value))\n .reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: String(value),\n }),\n {},\n );\n\n return (\n <TableCell\n key={cell.id}\n data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\n width={\n cell.column.getCanResize()\n ? `calc(var(--col-${cell.column.id}-size) * 1px)`\n : cell.column.getSize() || defaultColumnWidth\n }\n defaultColumnHeight={defaultColumnHeight}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n dataLink={cell.column.columnDef.meta?.dataLink}\n adjacentCellsValuesMap={adjacentCellsValuesMap}\n >\n {cellConfig?.text || cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["Box","TablePagination","TableRow","MuiTableRow","flexRender","forwardRef","useRef","TableVirtuoso","useVirtualizedTableKeyboardNav","InnerTable","TableBody","TableCell","TableFoot","TableHead","TableHeaderCell","TableToolbar","VirtualizedTableContainer","VirtuosoTableComponents","Scroller","Table","context","props","width","density","onKeyDown","onTableKeyDown","onBlur","onTableBlur","item","rowEventOpts","id","index","onClick","e","onRowClick","onMouseOver","onRowMouseOver","onMouseOut","onRowMouseOut"],"mappings":";;AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,EAAEC,eAAe,EAAEC,YAAYC,WAAW,QAAQ,gBAAgB;AAE9E,SAASC,UAAU,QAAQ,wBAAwB;AAEnD,SAASC,UAAU,EAAWC,MAAM,QAAQ,QAAQ;AAEpD,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,SAASC,8BAA8B,QAAQ,4CAAyC;AACxF,SAASC,UAAU,QAAQ,kBAAe;AAE1C,SAASC,SAAS,QAAQ,iBAAc;AAExC,SAASC,SAAS,QAAQ,iBAAc;AACxC,SAASC,SAAS,QAAQ,iBAAc;AACxC,SAASC,SAAS,QAAQ,iBAAc;AACxC,SAASC,eAAe,QAAQ,uBAAoB;AACpD,SAASZ,QAAQ,QAAQ,gBAAa;AAEtC,SAASa,YAAY,QAAQ,oBAAiB;AAC9C,SAASC,yBAAyB,QAAQ,iCAA8B;AAiBxE,yEAAyE;AACzE,8EAA8E;AAC9E,wEAAwE;AACxE,MAAMC,0BAA+F;IACnGC,wBAAUb,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;IACrBc,OAAO,CAAC,EAAEC,OAAO,EAAE,GAAQ,AAALC,OAAO,iBAC3B,KAACZ;YACE,GAAGY,KAAK;YACTC,OAAOF,QAAQE,KAAK;YACpBC,SAASH,QAAQG,OAAO;YACxBC,WAAWJ,QAAQK,cAAc;YACjCC,QAAQN,QAAQO,WAAW;;IAG/Bd,yBAAWR,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;IACtBO,yBAAWP,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;IACtBH,UAAU,CAAC,EAAE0B,IAAI,EAAER,OAAO,EAAE,GAAQ,AAALC,OAAO;QACpC,IAAI,CAACO,MAAM;YACT,OAAO;QACT;QAEA,MAAMC,eAAkC;YAAEC,IAAIF,KAAKE,EAAE;YAAEC,OAAOH,KAAKG,KAAK;QAAC;QAEzE,qBACE,KAAC7B;YACE,GAAGmB,KAAK;YACTW,SAAS,CAACC,IAAMb,QAAQc,UAAU,CAACD,GAAGL;YACtCL,SAASH,QAAQG,OAAO;YACxBY,aAAa,CAACF;gBACZb,QAAQgB,cAAc,GAAGH,GAAGJ;YAC9B;YACAQ,YAAY,CAACJ;gBACXb,QAAQkB,aAAa,GAAGL,GAAGJ;YAC7B;;IAGN;IACAnB,yBAAWL,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;AACxB;AA4BA,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO"}
|
|
@@ -11,18 +11,38 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { c as _c } from "react-compiler-runtime";
|
|
14
15
|
import { TableContainer as MuiTableContainer } from "@mui/material";
|
|
15
16
|
import { forwardRef } from "react";
|
|
16
17
|
import { combineSx } from "../utils/combine-sx.js";
|
|
17
18
|
export const VirtualizedTableContainer = /*#__PURE__*/ forwardRef(function VirtualizedTableContainer(props, ref) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
sx: combineSx({
|
|
19
|
+
const $ = _c(6);
|
|
20
|
+
let t0;
|
|
21
|
+
if ($[0] !== props.sx) {
|
|
22
|
+
t0 = combineSx({
|
|
23
23
|
flexGrow: 1
|
|
24
|
-
}, props.sx)
|
|
25
|
-
|
|
24
|
+
}, props.sx);
|
|
25
|
+
$[0] = props.sx;
|
|
26
|
+
$[1] = t0;
|
|
27
|
+
} else {
|
|
28
|
+
t0 = $[1];
|
|
29
|
+
}
|
|
30
|
+
let t1;
|
|
31
|
+
if ($[2] !== props || $[3] !== ref || $[4] !== t0) {
|
|
32
|
+
t1 = /*#__PURE__*/ _jsx(MuiTableContainer, {
|
|
33
|
+
...props,
|
|
34
|
+
tabIndex: -1,
|
|
35
|
+
ref: ref,
|
|
36
|
+
sx: t0
|
|
37
|
+
});
|
|
38
|
+
$[2] = props;
|
|
39
|
+
$[3] = ref;
|
|
40
|
+
$[4] = t0;
|
|
41
|
+
$[5] = t1;
|
|
42
|
+
} else {
|
|
43
|
+
t1 = $[5];
|
|
44
|
+
}
|
|
45
|
+
return t1;
|
|
26
46
|
});
|
|
27
47
|
|
|
28
48
|
//# sourceMappingURL=VirtualizedTableContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/VirtualizedTableContainer.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { TableContainerProps as MuiTableContainerProps } from '@mui/material';\nimport { TableContainer as MuiTableContainer } from '@mui/material';\nimport { forwardRef } from 'react';\n\nimport { combineSx } from '../utils/combine-sx';\n\ntype VirtualizedTableContainerProps = MuiTableContainerProps;\n\nexport const VirtualizedTableContainer = forwardRef<HTMLDivElement, VirtualizedTableContainerProps>(\n function VirtualizedTableContainer(props, ref) {\n return <MuiTableContainer {...props} tabIndex={-1} ref={ref} sx={combineSx({ flexGrow: 1 }, props.sx)} />;\n },\n);\n"],"names":["TableContainer","MuiTableContainer","forwardRef","combineSx","VirtualizedTableContainer"
|
|
1
|
+
{"version":3,"sources":["../../src/Table/VirtualizedTableContainer.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { TableContainerProps as MuiTableContainerProps } from '@mui/material';\nimport { TableContainer as MuiTableContainer } from '@mui/material';\nimport { forwardRef } from 'react';\n\nimport { combineSx } from '../utils/combine-sx';\n\ntype VirtualizedTableContainerProps = MuiTableContainerProps;\n\nexport const VirtualizedTableContainer = forwardRef<HTMLDivElement, VirtualizedTableContainerProps>(\n function VirtualizedTableContainer(props, ref) {\n return <MuiTableContainer {...props} tabIndex={-1} ref={ref} sx={combineSx({ flexGrow: 1 }, props.sx)} />;\n },\n);\n"],"names":["TableContainer","MuiTableContainer","forwardRef","combineSx","VirtualizedTableContainer"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAGjC,SAASA,kBAAkBC,iBAAiB,QAAQ,gBAAgB;AACpE,SAASC,UAAU,QAAQ,QAAQ;AAEnC,SAASC,SAAS,QAAQ,yBAAsB;AAIhD,OAAO,MAAMC,0CAA4BF,WACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGA"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { FuzzyMatchThreshold } from '@perses-dev/components';
|
|
2
|
-
import type { ExpandedState, TableOptions } from '@tanstack/react-table';
|
|
2
|
+
import type { ExpandedState, RowData, TableOptions } from '@tanstack/react-table';
|
|
3
3
|
import type { SetStateAction } from 'react';
|
|
4
|
-
|
|
4
|
+
import type { TableFeatures } from '../model/table-model';
|
|
5
|
+
export interface UseFuzzySearchResult<TableData extends RowData> {
|
|
5
6
|
globalFilter: string;
|
|
6
7
|
setGlobalFilter: (value: string) => void;
|
|
7
|
-
fuzzySearchOptions: Pick<TableOptions<TableData>, '
|
|
8
|
+
fuzzySearchOptions: Pick<TableOptions<TableFeatures, TableData>, 'globalFilterFn' | 'filterFromLeafRows' | 'onGlobalFilterChange'>;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
|
-
* Returns fuzzy search state and the corresponding `
|
|
11
|
+
* Returns fuzzy search state and the corresponding `useTable` options.
|
|
11
12
|
* Filter options are disabled when `showSearch` is falsy.
|
|
12
13
|
*/
|
|
13
|
-
export declare function useFuzzySearch<TableData>(isSearchEnabled: boolean | undefined, threshold: FuzzyMatchThreshold, expanded: ExpandedState, setExpanded: (value: SetStateAction<ExpandedState>) => void): UseFuzzySearchResult<TableData>;
|
|
14
|
+
export declare function useFuzzySearch<TableData extends RowData>(isSearchEnabled: boolean | undefined, threshold: FuzzyMatchThreshold, expanded: ExpandedState, setExpanded: (value: SetStateAction<ExpandedState>) => void): UseFuzzySearchResult<TableData>;
|
|
14
15
|
//# sourceMappingURL=useFuzzySearch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFuzzySearch.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAY,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"useFuzzySearch.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAY,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE5F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAU1D,MAAM,WAAW,oBAAoB,CAAC,SAAS,SAAS,OAAO;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,kBAAkB,EAAE,IAAI,CACtB,YAAY,CAAC,aAAa,EAAE,SAAS,CAAC,EACtC,gBAAgB,GAAG,oBAAoB,GAAG,sBAAsB,CACjE,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,SAAS,OAAO,EACtD,eAAe,EAAE,OAAO,GAAG,SAAS,EACpC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,aAAa,EACvB,WAAW,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,IAAI,GAC1D,oBAAoB,CAAC,SAAS,CAAC,CA4BjC"}
|
|
@@ -10,53 +10,78 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
import { c as _c } from "react-compiler-runtime";
|
|
13
14
|
import { rankings, rankItem } from "@tanstack/match-sorter-utils";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
15
|
+
import { tableOptions } from "@tanstack/react-table";
|
|
16
|
+
import { useState } from "react";
|
|
16
17
|
const getFuzzyFilterFunction = (threshold)=>(row, columnId, value, addMeta)=>{
|
|
17
18
|
const itemRank = rankItem(row.getValue(columnId), value, {
|
|
18
19
|
threshold: rankings[threshold]
|
|
19
20
|
});
|
|
20
|
-
addMeta({
|
|
21
|
+
addMeta?.({
|
|
21
22
|
itemRank
|
|
22
23
|
});
|
|
23
24
|
return itemRank.passed;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
|
-
* Returns fuzzy search state and the corresponding `
|
|
27
|
+
* Returns fuzzy search state and the corresponding `useTable` options.
|
|
27
28
|
* Filter options are disabled when `showSearch` is falsy.
|
|
28
29
|
*/ export function useFuzzySearch(isSearchEnabled, threshold, expanded, setExpanded) {
|
|
29
|
-
const
|
|
30
|
+
const $ = _c(12);
|
|
31
|
+
const [globalFilter, setGlobalFilter] = useState("");
|
|
30
32
|
const [prevExpandedState, setPrevExpandedState] = useState(expanded);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
let t0;
|
|
34
|
+
if ($[0] !== expanded || $[1] !== prevExpandedState || $[2] !== setExpanded) {
|
|
35
|
+
t0 = (value)=>{
|
|
36
|
+
setGlobalFilter((prev)=>{
|
|
37
|
+
if (!prev) {
|
|
38
|
+
setPrevExpandedState(expanded);
|
|
39
|
+
setExpanded(true);
|
|
40
|
+
} else {
|
|
41
|
+
if (prev && !value) {
|
|
42
|
+
setExpanded(prevExpandedState);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
$[0] = expanded;
|
|
49
|
+
$[1] = prevExpandedState;
|
|
50
|
+
$[2] = setExpanded;
|
|
51
|
+
$[3] = t0;
|
|
52
|
+
} else {
|
|
53
|
+
t0 = $[3];
|
|
54
|
+
}
|
|
55
|
+
const handleGlobalFilterChange = t0;
|
|
56
|
+
let t1;
|
|
57
|
+
if ($[4] !== handleGlobalFilterChange || $[5] !== isSearchEnabled || $[6] !== threshold) {
|
|
58
|
+
t1 = tableOptions({
|
|
59
|
+
globalFilterFn: isSearchEnabled ? getFuzzyFilterFunction(threshold) : undefined,
|
|
56
60
|
filterFromLeafRows: isSearchEnabled,
|
|
57
61
|
onGlobalFilterChange: handleGlobalFilterChange
|
|
58
|
-
}
|
|
59
|
-
|
|
62
|
+
});
|
|
63
|
+
$[4] = handleGlobalFilterChange;
|
|
64
|
+
$[5] = isSearchEnabled;
|
|
65
|
+
$[6] = threshold;
|
|
66
|
+
$[7] = t1;
|
|
67
|
+
} else {
|
|
68
|
+
t1 = $[7];
|
|
69
|
+
}
|
|
70
|
+
let t2;
|
|
71
|
+
if ($[8] !== globalFilter || $[9] !== handleGlobalFilterChange || $[10] !== t1) {
|
|
72
|
+
t2 = {
|
|
73
|
+
globalFilter,
|
|
74
|
+
setGlobalFilter: handleGlobalFilterChange,
|
|
75
|
+
fuzzySearchOptions: t1
|
|
76
|
+
};
|
|
77
|
+
$[8] = globalFilter;
|
|
78
|
+
$[9] = handleGlobalFilterChange;
|
|
79
|
+
$[10] = t1;
|
|
80
|
+
$[11] = t2;
|
|
81
|
+
} else {
|
|
82
|
+
t2 = $[11];
|
|
83
|
+
}
|
|
84
|
+
return t2;
|
|
60
85
|
}
|
|
61
86
|
|
|
62
87
|
//# sourceMappingURL=useFuzzySearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { FuzzyMatchThreshold } from '@perses-dev/components';\nimport { rankings, rankItem } from '@tanstack/match-sorter-utils';\nimport type { ExpandedState, FilterFn, TableOptions } from '@tanstack/react-table';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { FuzzyMatchThreshold } from '@perses-dev/components';\nimport { rankings, rankItem } from '@tanstack/match-sorter-utils';\nimport type { ExpandedState, FilterFn, RowData, TableOptions } from '@tanstack/react-table';\nimport { tableOptions } from '@tanstack/react-table';\nimport type { SetStateAction } from 'react';\nimport { useCallback, useState } from 'react';\n\nimport type { TableFeatures } from '../model/table-model';\n\nconst getFuzzyFilterFunction =\n <TableData extends RowData>(threshold: FuzzyMatchThreshold): FilterFn<TableFeatures, TableData> =>\n (row, columnId, value, addMeta) => {\n const itemRank = rankItem(row.getValue(columnId), value, { threshold: rankings[threshold] });\n addMeta?.({ itemRank });\n return itemRank.passed;\n };\n\nexport interface UseFuzzySearchResult<TableData extends RowData> {\n globalFilter: string;\n setGlobalFilter: (value: string) => void;\n fuzzySearchOptions: Pick<\n TableOptions<TableFeatures, TableData>,\n 'globalFilterFn' | 'filterFromLeafRows' | 'onGlobalFilterChange'\n >;\n}\n\n/**\n * Returns fuzzy search state and the corresponding `useTable` options.\n * Filter options are disabled when `showSearch` is falsy.\n */\nexport function useFuzzySearch<TableData extends RowData>(\n isSearchEnabled: boolean | undefined,\n threshold: FuzzyMatchThreshold,\n expanded: ExpandedState,\n setExpanded: (value: SetStateAction<ExpandedState>) => void,\n): UseFuzzySearchResult<TableData> {\n const [globalFilter, setGlobalFilter] = useState('');\n const [prevExpandedState, setPrevExpandedState] = useState<ExpandedState>(expanded);\n\n // expand all rows when a search query is entered, and restore previous expansion state when the query is cleared\n const handleGlobalFilterChange = useCallback(\n (value: string): void => {\n setGlobalFilter((prev) => {\n if (!prev) {\n setPrevExpandedState(expanded);\n setExpanded(true);\n } else if (prev && !value) {\n setExpanded(prevExpandedState);\n }\n return value;\n });\n },\n [expanded, prevExpandedState, setExpanded],\n );\n return {\n globalFilter,\n setGlobalFilter: handleGlobalFilterChange,\n fuzzySearchOptions: tableOptions<TableFeatures, TableData>({\n globalFilterFn: isSearchEnabled ? getFuzzyFilterFunction<TableData>(threshold) : undefined,\n filterFromLeafRows: isSearchEnabled,\n onGlobalFilterChange: handleGlobalFilterChange,\n }),\n };\n}\n"],"names":["rankings","rankItem","tableOptions","useState","getFuzzyFilterFunction","threshold","row","columnId","value","addMeta","itemRank","getValue","passed"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,QAAQ,EAAEC,QAAQ,QAAQ,+BAA+B;AAElE,SAASC,YAAY,QAAQ,wBAAwB;AAErD,SAAsBC,QAAQ,QAAQ,QAAQ;AAI9C,MAAMC,yBACJ,CAA4BC,YAC5B,CAACC,KAAKC,UAAUC,OAAOC;QACrB,MAAMC,WAAWT,SAASK,IAAIK,QAAQ,CAACJ,WAAWC,OAAO;YAAEH,WAAWL,QAASK,CAAAA,UAAS,AAAC;QAAC;QAC1FI,UAAU;YAAEC;QAAS;QACrB,OAAOA,SAASE,MAAM;IACxB;AAWF;;;CAGC,GACD,OAAO"}
|
|
@@ -10,16 +10,17 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import {
|
|
13
|
+
import { c as _c } from "react-compiler-runtime";
|
|
14
|
+
import { useState } from "react";
|
|
14
15
|
const DEFAULT_ACTIVE_CELL = {
|
|
15
16
|
row: 0,
|
|
16
17
|
column: 0
|
|
17
18
|
};
|
|
18
19
|
const ARROW_KEYS = new Set([
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
"ArrowRight",
|
|
21
|
+
"ArrowLeft",
|
|
22
|
+
"ArrowUp",
|
|
23
|
+
"ArrowDown"
|
|
23
24
|
]);
|
|
24
25
|
function isArrowKey(key) {
|
|
25
26
|
return ARROW_KEYS.has(key);
|
|
@@ -29,77 +30,117 @@ function isArrowKey(key) {
|
|
|
29
30
|
* to be wrapped by implementation-specific tables to account for differences
|
|
30
31
|
* like pagination, infinite scroll, and virtualization. See `useVirtualizedKeyboardNav`
|
|
31
32
|
* for an example.
|
|
32
|
-
*/ export function useTableKeyboardNav(
|
|
33
|
+
*/ export function useTableKeyboardNav(t0) {
|
|
34
|
+
const $ = _c(13);
|
|
35
|
+
const { maxRows, maxColumns, onActiveCellChange } = t0;
|
|
33
36
|
const [activeCell, setActiveCell] = useState(DEFAULT_ACTIVE_CELL);
|
|
34
37
|
const [isActive, setIsActive] = useState(false);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
38
|
+
let t1;
|
|
39
|
+
if ($[0] !== activeCell || $[1] !== isActive) {
|
|
40
|
+
t1 = (cellPosition)=>{
|
|
41
|
+
if (cellPosition.column === activeCell.column && cellPosition.row === activeCell.row && isActive) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setIsActive(true);
|
|
45
|
+
setActiveCell(cellPosition);
|
|
46
|
+
};
|
|
47
|
+
$[0] = activeCell;
|
|
48
|
+
$[1] = isActive;
|
|
49
|
+
$[2] = t1;
|
|
50
|
+
} else {
|
|
51
|
+
t1 = $[2];
|
|
52
|
+
}
|
|
53
|
+
const handleCellFocus = t1;
|
|
54
|
+
let t2;
|
|
55
|
+
if ($[3] !== maxColumns || $[4] !== maxRows || $[5] !== onActiveCellChange) {
|
|
56
|
+
t2 = (e)=>{
|
|
57
|
+
const key = e.key;
|
|
58
|
+
if (isArrowKey(key) || key === "Home" || key === "End" || key === "PageDown" || key === "PageUp") {
|
|
59
|
+
setActiveCell((curActiveCell)=>{
|
|
60
|
+
let nextRow = curActiveCell.row;
|
|
61
|
+
let nextColumn = curActiveCell.column;
|
|
62
|
+
if (key === "ArrowRight" && nextColumn < maxColumns - 1) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
nextColumn = nextColumn + 1;
|
|
65
|
+
} else {
|
|
66
|
+
if (key === "ArrowLeft" && nextColumn > 0) {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
nextColumn = nextColumn - 1;
|
|
69
|
+
} else {
|
|
70
|
+
if (key === "ArrowDown" && nextRow < maxRows - 1) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
nextRow = nextRow + 1;
|
|
73
|
+
} else {
|
|
74
|
+
if (key === "ArrowUp" && nextRow > 0) {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
nextRow = nextRow - 1;
|
|
77
|
+
} else {
|
|
78
|
+
if (key === "Home") {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
nextRow = 0;
|
|
81
|
+
nextColumn = 0;
|
|
82
|
+
} else {
|
|
83
|
+
if (key === "End") {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
nextRow = maxRows - 1;
|
|
86
|
+
nextColumn = maxColumns - 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const defaultNewPosition = {
|
|
94
|
+
column: nextColumn,
|
|
95
|
+
row: nextRow
|
|
96
|
+
};
|
|
97
|
+
const newPosition = onActiveCellChange?.(e, curActiveCell, defaultNewPosition) || defaultNewPosition;
|
|
98
|
+
if (newPosition.row === curActiveCell.row && newPosition.column === curActiveCell.column) {
|
|
99
|
+
return curActiveCell;
|
|
100
|
+
}
|
|
101
|
+
return newPosition;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
$[3] = maxColumns;
|
|
106
|
+
$[4] = maxRows;
|
|
107
|
+
$[5] = onActiveCellChange;
|
|
108
|
+
$[6] = t2;
|
|
109
|
+
} else {
|
|
110
|
+
t2 = $[6];
|
|
111
|
+
}
|
|
112
|
+
const handleKeyDown = t2;
|
|
113
|
+
let t3;
|
|
114
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
115
|
+
t3 = (e_0)=>{
|
|
116
|
+
if (!e_0.currentTarget.contains(e_0.relatedTarget)) {
|
|
117
|
+
setIsActive(false);
|
|
118
|
+
setActiveCell(DEFAULT_ACTIVE_CELL);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
$[7] = t3;
|
|
122
|
+
} else {
|
|
123
|
+
t3 = $[7];
|
|
124
|
+
}
|
|
125
|
+
const handleTableBlur = t3;
|
|
126
|
+
let t4;
|
|
127
|
+
if ($[8] !== activeCell || $[9] !== handleCellFocus || $[10] !== handleKeyDown || $[11] !== isActive) {
|
|
128
|
+
t4 = {
|
|
129
|
+
activeCell,
|
|
130
|
+
isActive,
|
|
131
|
+
onTableKeyDown: handleKeyDown,
|
|
132
|
+
onCellFocus: handleCellFocus,
|
|
133
|
+
onTableBlur: handleTableBlur
|
|
134
|
+
};
|
|
135
|
+
$[8] = activeCell;
|
|
136
|
+
$[9] = handleCellFocus;
|
|
137
|
+
$[10] = handleKeyDown;
|
|
138
|
+
$[11] = isActive;
|
|
139
|
+
$[12] = t4;
|
|
140
|
+
} else {
|
|
141
|
+
t4 = $[12];
|
|
142
|
+
}
|
|
143
|
+
return t4;
|
|
103
144
|
}
|
|
104
145
|
|
|
105
146
|
//# sourceMappingURL=useTableKeyboardNav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Table/hooks/useTableKeyboardNav.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { FocusEventHandler, KeyboardEventHandler } from 'react';\nimport { useCallback, useState } from 'react';\n\nexport interface UseTableKeyboardNavProps {\n maxRows: number;\n maxColumns: number;\n\n /**\n * Function used to modify the active table cell based on the keyboard event,\n * the current position, and the default recommended next position (this value\n * will be `undefined` in cases where there is no default handler like `PageUp`\n * and `PageDown`). This can be used to modify the next position that will be\n * used and/or to handle side effects related to the new position (e.g.\n * pagination, scrolling the active cell into view).\n */\n onActiveCellChange?: (\n e: React.KeyboardEvent<HTMLTableElement>,\n currentActiveCell: TableCellPosition,\n defaultNextActiveCell: TableCellPosition | undefined,\n ) => TableCellPosition | undefined;\n}\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nconst DEFAULT_ACTIVE_CELL: TableCellPosition = {\n row: 0,\n column: 0,\n};\n\nconst ARROW_KEYS = new Set(['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown']);\n\nfunction isArrowKey(key: string): boolean {\n return ARROW_KEYS.has(key);\n}\n\n/**\n * Hook for managing keyboard navigation for table components. It is intended\n * to be wrapped by implementation-specific tables to account for differences\n * like pagination, infinite scroll, and virtualization. See `useVirtualizedKeyboardNav`\n * for an example.\n */\nexport function useTableKeyboardNav({ maxRows, maxColumns, onActiveCellChange }: UseTableKeyboardNavProps): {\n activeCell: TableCellPosition;\n isActive: boolean;\n onTableKeyDown: KeyboardEventHandler<HTMLTableElement>;\n onCellFocus: (cellPosition: TableCellPosition) => void;\n onTableBlur: FocusEventHandler<HTMLTableElement>;\n} {\n const [activeCell, setActiveCell] = useState<TableCellPosition>(DEFAULT_ACTIVE_CELL);\n const [isActive, setIsActive] = useState(false);\n\n const handleCellFocus = (cellPosition: TableCellPosition): void => {\n if (cellPosition.column === activeCell.column && cellPosition.row === activeCell.row && isActive) {\n return;\n }\n setIsActive(true);\n setActiveCell(cellPosition);\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLTableElement> = useCallback(\n (e) => {\n // Including some of the basic a11y keyboard interaction patterns from:\n // https://www.w3.org/WAI/ARIA/apg/patterns/grid/\n // TODO: add other keyboard combos.\n const key = e.key;\n\n if (isArrowKey(key) || key === 'Home' || key === 'End' || key === 'PageDown' || key === 'PageUp') {\n setActiveCell((curActiveCell) => {\n let nextRow: number = curActiveCell.row;\n let nextColumn: number = curActiveCell.column;\n\n if (key === 'ArrowRight' && nextColumn < maxColumns - 1) {\n e.preventDefault();\n nextColumn += 1;\n } else if (key === 'ArrowLeft' && nextColumn > 0) {\n e.preventDefault();\n nextColumn -= 1;\n } else if (key === 'ArrowDown' && nextRow < maxRows - 1) {\n e.preventDefault();\n nextRow += 1;\n } else if (key === 'ArrowUp' && nextRow > 0) {\n e.preventDefault();\n nextRow -= 1;\n } else if (key === 'Home') {\n e.preventDefault();\n nextRow = 0;\n nextColumn = 0;\n } else if (key === 'End') {\n e.preventDefault();\n nextRow = maxRows - 1;\n nextColumn = maxColumns - 1;\n }\n\n const defaultNewPosition = { column: nextColumn, row: nextRow };\n\n const newPosition = onActiveCellChange?.(e, curActiveCell, defaultNewPosition) || defaultNewPosition;\n\n if (newPosition.row === curActiveCell.row && newPosition.column === curActiveCell.column) {\n // Return original to avoid creating a new object if nothing\n // changed.\n return curActiveCell;\n }\n\n return newPosition;\n });\n }\n },\n [maxColumns, maxRows, onActiveCellChange],\n );\n\n const handleTableBlur: FocusEventHandler<HTMLTableElement> = useCallback((e) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n setIsActive(false);\n setActiveCell(DEFAULT_ACTIVE_CELL);\n }\n }, []);\n\n return {\n activeCell,\n isActive,\n onTableKeyDown: handleKeyDown,\n onCellFocus: handleCellFocus,\n onTableBlur: handleTableBlur,\n };\n}\n"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../src/Table/hooks/useTableKeyboardNav.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { FocusEventHandler, KeyboardEventHandler } from 'react';\nimport { useCallback, useState } from 'react';\n\nexport interface UseTableKeyboardNavProps {\n maxRows: number;\n maxColumns: number;\n\n /**\n * Function used to modify the active table cell based on the keyboard event,\n * the current position, and the default recommended next position (this value\n * will be `undefined` in cases where there is no default handler like `PageUp`\n * and `PageDown`). This can be used to modify the next position that will be\n * used and/or to handle side effects related to the new position (e.g.\n * pagination, scrolling the active cell into view).\n */\n onActiveCellChange?: (\n e: React.KeyboardEvent<HTMLTableElement>,\n currentActiveCell: TableCellPosition,\n defaultNextActiveCell: TableCellPosition | undefined,\n ) => TableCellPosition | undefined;\n}\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nconst DEFAULT_ACTIVE_CELL: TableCellPosition = {\n row: 0,\n column: 0,\n};\n\nconst ARROW_KEYS = new Set(['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown']);\n\nfunction isArrowKey(key: string): boolean {\n return ARROW_KEYS.has(key);\n}\n\n/**\n * Hook for managing keyboard navigation for table components. It is intended\n * to be wrapped by implementation-specific tables to account for differences\n * like pagination, infinite scroll, and virtualization. See `useVirtualizedKeyboardNav`\n * for an example.\n */\nexport function useTableKeyboardNav({ maxRows, maxColumns, onActiveCellChange }: UseTableKeyboardNavProps): {\n activeCell: TableCellPosition;\n isActive: boolean;\n onTableKeyDown: KeyboardEventHandler<HTMLTableElement>;\n onCellFocus: (cellPosition: TableCellPosition) => void;\n onTableBlur: FocusEventHandler<HTMLTableElement>;\n} {\n const [activeCell, setActiveCell] = useState<TableCellPosition>(DEFAULT_ACTIVE_CELL);\n const [isActive, setIsActive] = useState(false);\n\n const handleCellFocus = (cellPosition: TableCellPosition): void => {\n if (cellPosition.column === activeCell.column && cellPosition.row === activeCell.row && isActive) {\n return;\n }\n setIsActive(true);\n setActiveCell(cellPosition);\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLTableElement> = useCallback(\n (e) => {\n // Including some of the basic a11y keyboard interaction patterns from:\n // https://www.w3.org/WAI/ARIA/apg/patterns/grid/\n // TODO: add other keyboard combos.\n const key = e.key;\n\n if (isArrowKey(key) || key === 'Home' || key === 'End' || key === 'PageDown' || key === 'PageUp') {\n setActiveCell((curActiveCell) => {\n let nextRow: number = curActiveCell.row;\n let nextColumn: number = curActiveCell.column;\n\n if (key === 'ArrowRight' && nextColumn < maxColumns - 1) {\n e.preventDefault();\n nextColumn += 1;\n } else if (key === 'ArrowLeft' && nextColumn > 0) {\n e.preventDefault();\n nextColumn -= 1;\n } else if (key === 'ArrowDown' && nextRow < maxRows - 1) {\n e.preventDefault();\n nextRow += 1;\n } else if (key === 'ArrowUp' && nextRow > 0) {\n e.preventDefault();\n nextRow -= 1;\n } else if (key === 'Home') {\n e.preventDefault();\n nextRow = 0;\n nextColumn = 0;\n } else if (key === 'End') {\n e.preventDefault();\n nextRow = maxRows - 1;\n nextColumn = maxColumns - 1;\n }\n\n const defaultNewPosition = { column: nextColumn, row: nextRow };\n\n const newPosition = onActiveCellChange?.(e, curActiveCell, defaultNewPosition) || defaultNewPosition;\n\n if (newPosition.row === curActiveCell.row && newPosition.column === curActiveCell.column) {\n // Return original to avoid creating a new object if nothing\n // changed.\n return curActiveCell;\n }\n\n return newPosition;\n });\n }\n },\n [maxColumns, maxRows, onActiveCellChange],\n );\n\n const handleTableBlur: FocusEventHandler<HTMLTableElement> = useCallback((e) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n setIsActive(false);\n setActiveCell(DEFAULT_ACTIVE_CELL);\n }\n }, []);\n\n return {\n activeCell,\n isActive,\n onTableKeyDown: handleKeyDown,\n onCellFocus: handleCellFocus,\n onTableBlur: handleTableBlur,\n };\n}\n"],"names":["useState","DEFAULT_ACTIVE_CELL","row","column","ARROW_KEYS","Set","isArrowKey","key","has"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAAsBA,QAAQ,QAAQ,QAAQ;AA0B9C,MAAMC,sBAAyC;IAC7CC,KAAK;IACLC,QAAQ;AACV;AAEA,MAAMC,aAAa,IAAIC,IAAI;IAAC;IAAc;IAAa;IAAW;CAAY;AAE9E,SAASC,WAAWC,GAAG;IACrB,OAAOH,WAAWI,GAAG,CAACD;AACxB;AAEA;;;;;CAKC,GACD,OAAO"}
|
|
@@ -6,7 +6,7 @@ interface UseVirtualizedTableKeyboardNavProps extends Omit<UseTableKeyboardNavPr
|
|
|
6
6
|
startIndex: number;
|
|
7
7
|
endIndex: number;
|
|
8
8
|
}>;
|
|
9
|
-
virtualTable: RefObject<TableVirtuosoHandle>;
|
|
9
|
+
virtualTable: RefObject<TableVirtuosoHandle | null>;
|
|
10
10
|
maxRows: number;
|
|
11
11
|
maxColumns: number;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualizedTableKeyboardNav.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useVirtualizedTableKeyboardNav.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAA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