@dbcdk/react-components 0.0.95 → 0.0.97
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/alert/Alert.d.ts +13 -0
- package/dist/components/forms/input/Input.d.ts +2 -1
- package/dist/components/forms/input-container/InputContainer.d.ts +3 -1
- package/dist/components/forms/text-area/Textarea.d.ts +1 -1
- package/dist/components/stack/Stack.d.ts +11 -3
- package/dist/components/table/Table.d.ts +1 -1
- package/dist/components/table/Table.types.d.ts +3 -0
- package/dist/components/table/components/TableHeader.d.ts +2 -1
- package/dist/index.cjs +12750 -0
- package/dist/index.css +7149 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12641 -78
- package/dist/tanstack.cjs +2674 -0
- package/dist/tanstack.css +1267 -0
- package/dist/tanstack.js +2650 -3
- package/dist/themes/dbc.css +3 -0
- package/dist/themes/forfatterweb.css +2 -0
- package/package.json +11 -10
- package/dist/assets/logo.js +0 -2
- package/dist/components/__stories__/_data/table.d.ts +0 -15
- package/dist/components/__stories__/_data/table.js +0 -55
- package/dist/components/__stories__/_data/tabs.d.ts +0 -9
- package/dist/components/__stories__/_data/tabs.js +0 -31
- package/dist/components/__stories__/story-components/Colors.d.ts +0 -11
- package/dist/components/__stories__/story-components/Colors.js +0 -96
- package/dist/components/__stories__/story-components/Colors.module.css +0 -27
- package/dist/components/__stories__/story-components/ComponentSizes.d.ts +0 -2
- package/dist/components/__stories__/story-components/ComponentSizes.js +0 -26
- package/dist/components/__stories__/story-components/Elevation.d.ts +0 -2
- package/dist/components/__stories__/story-components/Elevation.js +0 -49
- package/dist/components/__stories__/story-components/Flex.d.ts +0 -2
- package/dist/components/__stories__/story-components/Flex.js +0 -177
- package/dist/components/__stories__/story-components/Flex.module.css +0 -317
- package/dist/components/__stories__/story-components/Spacing.d.ts +0 -6
- package/dist/components/__stories__/story-components/Spacing.js +0 -76
- package/dist/components/__stories__/story-components/Spacing.module.css +0 -154
- package/dist/components/accordion/Accordion.js +0 -70
- package/dist/components/accordion/Accordion.module.css +0 -28
- package/dist/components/accordion/components/AccordionRow.js +0 -53
- package/dist/components/accordion/components/AccordionRow.module.css +0 -90
- package/dist/components/app-header/AppHeader.js +0 -5
- package/dist/components/app-header/AppHeader.module.css +0 -74
- package/dist/components/attribute-chip/AttributeChip.js +0 -5
- package/dist/components/attribute-chip/AttributeChip.module.css +0 -65
- package/dist/components/avatar/Avatar.js +0 -48
- package/dist/components/avatar/Avatar.module.css +0 -91
- package/dist/components/breadcrumbs/Breadcrumbs.js +0 -6
- package/dist/components/breadcrumbs/Breadcrumbs.module.css +0 -80
- package/dist/components/button/Button.js +0 -81
- package/dist/components/button/Button.module.css +0 -249
- package/dist/components/button-select/ButtonSelect.js +0 -7
- package/dist/components/button-select/ButtonSelect.module.css +0 -40
- package/dist/components/card/Card.js +0 -71
- package/dist/components/card/Card.module.css +0 -160
- package/dist/components/card/components/CardMeta.js +0 -26
- package/dist/components/card/components/CardMeta.module.css +0 -55
- package/dist/components/card-container/CardContainer.js +0 -6
- package/dist/components/card-container/CardContainer.module.css +0 -61
- package/dist/components/chip/Chip.js +0 -31
- package/dist/components/chip/Chip.module.css +0 -236
- package/dist/components/circle/Circle.js +0 -5
- package/dist/components/circle/Circle.module.css +0 -128
- package/dist/components/clear-button/ClearButton.js +0 -13
- package/dist/components/clear-button/ClearButton.module.css +0 -26
- package/dist/components/code-block/CodeBlock.js +0 -58
- package/dist/components/code-block/CodeBlock.module.css +0 -124
- package/dist/components/copy-button/CopyButton.js +0 -78
- package/dist/components/copy-button/CopyButton.module.css +0 -22
- package/dist/components/datetime-picker/DateTimePicker.js +0 -403
- package/dist/components/datetime-picker/DateTimePicker.module.css +0 -155
- package/dist/components/datetime-picker/dateTimeHelpers.js +0 -248
- package/dist/components/divider/Divider.js +0 -12
- package/dist/components/filter-field/FilterField.js +0 -191
- package/dist/components/filter-field/FilterField.module.css +0 -379
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.js +0 -52
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.module.css +0 -59
- package/dist/components/forms/checkbox/Checkbox.js +0 -26
- package/dist/components/forms/checkbox/Checkbox.module.css +0 -99
- package/dist/components/forms/checkbox-group/CheckboxGroup.js +0 -75
- package/dist/components/forms/checkbox-group/CheckboxGroup.module.css +0 -115
- package/dist/components/forms/form-select/FormSelect.js +0 -86
- package/dist/components/forms/form-select/FormSelect.module.css +0 -236
- package/dist/components/forms/input/Input.js +0 -77
- package/dist/components/forms/input/Input.module.css +0 -468
- package/dist/components/forms/input-container/InputContainer.js +0 -15
- package/dist/components/forms/input-container/InputContainer.module.css +0 -56
- package/dist/components/forms/multi-select/MultiSelect.js +0 -122
- package/dist/components/forms/radio-buttons/RadioButton.js +0 -26
- package/dist/components/forms/radio-buttons/RadioButtonGroup.js +0 -19
- package/dist/components/forms/radio-buttons/RadioButtons.module.css +0 -118
- package/dist/components/forms/select/Select.js +0 -185
- package/dist/components/forms/select/Select.module.css +0 -32
- package/dist/components/forms/text-area/Textarea.js +0 -47
- package/dist/components/forms/text-area/Textarea.module.css +0 -70
- package/dist/components/forms/typeahead/Typeahead.js +0 -668
- package/dist/components/forms/typeahead/Typeahead.module.css +0 -38
- package/dist/components/grid/Grid.js +0 -23
- package/dist/components/grid/Grid.module.css +0 -35
- package/dist/components/headline/CollapsibleHeadline.js +0 -29
- package/dist/components/headline/Headline.js +0 -26
- package/dist/components/headline/Headline.module.css +0 -165
- package/dist/components/hyperlink/Hyperlink.js +0 -40
- package/dist/components/hyperlink/Hyperlink.module.css +0 -107
- package/dist/components/icon/Icon.js +0 -14
- package/dist/components/icon/Icon.module.css +0 -36
- package/dist/components/interval-select/IntervalSelect.js +0 -99
- package/dist/components/json-viewer/HighlightedText.js +0 -6
- package/dist/components/json-viewer/JsonNode.js +0 -30
- package/dist/components/json-viewer/JsonViewer.js +0 -68
- package/dist/components/json-viewer/JsonViewer.module.css +0 -346
- package/dist/components/json-viewer/types.js +0 -1
- package/dist/components/json-viewer/useClipboardStatus.js +0 -11
- package/dist/components/json-viewer/utils.js +0 -125
- package/dist/components/menu/Menu.js +0 -165
- package/dist/components/menu/Menu.module.css +0 -211
- package/dist/components/meta-bar/MetaBar.js +0 -9
- package/dist/components/meta-bar/MetaBar.module.css +0 -27
- package/dist/components/nav-bar/NavBar.js +0 -29
- package/dist/components/nav-bar/NavBar.module.css +0 -200
- package/dist/components/overlay/fade-overlay/FadeOverlay.js +0 -8
- package/dist/components/overlay/fade-overlay/FadeOverlay.module.css +0 -54
- package/dist/components/overlay/modal/Modal.js +0 -115
- package/dist/components/overlay/modal/Modal.module.css +0 -109
- package/dist/components/overlay/modal/provider/ModalProvider.js +0 -73
- package/dist/components/overlay/side-panel/SidePanel.js +0 -83
- package/dist/components/overlay/side-panel/SidePanel.module.css +0 -177
- package/dist/components/overlay/side-panel/useSidePanel.js +0 -11
- package/dist/components/overlay/tooltip/Tooltip.js +0 -17
- package/dist/components/overlay/tooltip/Tooltip.module.css +0 -104
- package/dist/components/overlay/tooltip/TooltipProvider.js +0 -255
- package/dist/components/overlay/tooltip/useTooltipTrigger.js +0 -118
- package/dist/components/page/Page.js +0 -11
- package/dist/components/page/Page.module.css +0 -76
- package/dist/components/page-layout/PageLayout.js +0 -76
- package/dist/components/page-layout/PageLayout.module.css +0 -236
- package/dist/components/page-layout/components/layout-footer/LayoutFooter.js +0 -27
- package/dist/components/page-layout/components/layout-footer/LayoutFooter.module.css +0 -89
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.js +0 -14
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.module.css +0 -84
- package/dist/components/pagination/Pagination.js +0 -56
- package/dist/components/pagination/Pagination.module.css +0 -25
- package/dist/components/panel/Panel.js +0 -7
- package/dist/components/panel/Panel.module.css +0 -29
- package/dist/components/popover/Popover.js +0 -257
- package/dist/components/popover/Popover.module.css +0 -54
- package/dist/components/search-box/SearchBox.js +0 -170
- package/dist/components/search-box/SearchBox.module.css +0 -21
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +0 -48
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +0 -167
- package/dist/components/sidebar/Sidebar.js +0 -6
- package/dist/components/sidebar/components/SidebarItem.js +0 -8
- package/dist/components/sidebar/components/SidebarItem.module.css +0 -0
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +0 -63
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +0 -29
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +0 -153
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +0 -260
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +0 -18
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +0 -106
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +0 -26
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.module.css +0 -20
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +0 -30
- package/dist/components/sidebar/providers/SidebarProvider.js +0 -229
- package/dist/components/skeleton-loader/SkeletonLoader.js +0 -73
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +0 -13
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +0 -51
- package/dist/components/split-button/SplitButton.js +0 -10
- package/dist/components/split-button/SplitButton.module.css +0 -32
- package/dist/components/split-pane/SplitPane.js +0 -107
- package/dist/components/split-pane/SplitPane.module.css +0 -111
- package/dist/components/split-pane/provider/SplitPaneContext.js +0 -124
- package/dist/components/stack/Stack.js +0 -19
- package/dist/components/state-page/StatePage.js +0 -20
- package/dist/components/state-page/StatePage.module.css +0 -9
- package/dist/components/state-page/empty.js +0 -2
- package/dist/components/state-page/error.js +0 -2
- package/dist/components/state-page/notFound.js +0 -2
- package/dist/components/sticky-footer-layout/StickyFooterLayout.js +0 -64
- package/dist/components/table/Table.js +0 -50
- package/dist/components/table/Table.module.css +0 -536
- package/dist/components/table/Table.types.js +0 -1
- package/dist/components/table/TanstackTable.js +0 -111
- package/dist/components/table/components/TableBody.js +0 -10
- package/dist/components/table/components/TableHeader.js +0 -7
- package/dist/components/table/components/TableHeaderCell.js +0 -24
- package/dist/components/table/components/TableLoadingBody.js +0 -26
- package/dist/components/table/components/TablePagination.js +0 -1
- package/dist/components/table/components/TableRow.js +0 -54
- package/dist/components/table/components/TableSelectionCell.js +0 -16
- package/dist/components/table/components/column-resizer/ColumnResizer.js +0 -5
- package/dist/components/table/components/column-resizer/ColumnResizer.module.css +0 -22
- package/dist/components/table/components/empty-state/EmptyState.js +0 -23
- package/dist/components/table/components/empty-state/EmptyState.module.css +0 -4
- package/dist/components/table/components/table-settings/TableSettings.js +0 -63
- package/dist/components/table/hooks/useTableRowInteractions.js +0 -30
- package/dist/components/table/table.classes.js +0 -23
- package/dist/components/table/table.utils.js +0 -47
- package/dist/components/table/tanstackTable.utils.js +0 -175
- package/dist/components/tabs/Tabs.js +0 -125
- package/dist/components/tabs/Tabs.module.css +0 -204
- package/dist/components/theme-button/ThemeButton.js +0 -23
- package/dist/components/toast/Toast.js +0 -20
- package/dist/components/toast/Toast.module.css +0 -161
- package/dist/components/toast/provider/ToastProvider.js +0 -70
- package/dist/components/user-display/UserDisplay.js +0 -6
- package/dist/components/user-display/UserDisplay.module.css +0 -25
- package/dist/constants/severity.js +0 -24
- package/dist/constants/severity.types.js +0 -1
- package/dist/constants/sizes.js +0 -7
- package/dist/hooks/useDeviceSize.js +0 -32
- package/dist/hooks/useListNavigation.js +0 -234
- package/dist/hooks/usePagination.js +0 -140
- package/dist/hooks/useSorting.js +0 -118
- package/dist/hooks/useTableData.js +0 -45
- package/dist/hooks/useTableSelection.js +0 -164
- package/dist/hooks/useTableSettings.js +0 -71
- package/dist/hooks/useTheme.js +0 -66
- package/dist/hooks/useTimeDuration.js +0 -68
- package/dist/hooks/useViewportFill.js +0 -77
- package/dist/styles/animation.js +0 -5
- package/dist/styles/themes/types.js +0 -1
- package/dist/types/a11y-props.types.js +0 -1
- package/dist/types/sizes.types.js +0 -1
- package/dist/utils/arrays/nested-filtering.js +0 -48
- package/dist/utils/date/formatDate.js +0 -51
- package/dist/utils/localStorage.utils.js +0 -78
- package/dist/utils/text/get-highlighted-segments.js +0 -46
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { TableHeaderCell } from './TableHeaderCell';
|
|
3
|
-
import { TableSelectionCell } from './TableSelectionCell';
|
|
4
|
-
import styles from '../Table.module.css';
|
|
5
|
-
export function TableHeader({ columns, hasSelection, selectionMode, allRowsSelected, onSelectAllRows, sortById, sortDirection, onSortChange, headerExtras, }) {
|
|
6
|
-
return (_jsx("thead", { className: styles.header, children: _jsxs("tr", { className: styles.headerRow, children: [hasSelection ? (_jsx(TableSelectionCell, { isHeader: true, multiple: selectionMode === 'multiple', checked: allRowsSelected, onToggle: checked => onSelectAllRows === null || onSelectAllRows === void 0 ? void 0 : onSelectAllRows(checked) })) : null, columns.map((column, index) => (_jsx(TableHeaderCell, { column: column, index: index, sortById: sortById, sortDirection: sortDirection, onSortChange: onSortChange, extraContent: headerExtras === null || headerExtras === void 0 ? void 0 : headerExtras({ column, index }) }, column.id)))] }) }));
|
|
7
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ArrowDown, ArrowUp } from 'lucide-react';
|
|
3
|
-
import { cx, getAlignValue, getDividerClass, getHeaderAlignClasses } from '../table.classes';
|
|
4
|
-
import styles from '../Table.module.css';
|
|
5
|
-
import { getAriaSort, getHeaderLabel, getNextSortDirection, isActiveSort, shouldToggleOnKey, } from '../table.utils';
|
|
6
|
-
export function TableHeaderCell({ column, index, sortById, sortDirection, onSortChange, extraContent, }) {
|
|
7
|
-
const active = isActiveSort(sortById, column.id);
|
|
8
|
-
const ariaSort = getAriaSort(column.sortable, active, sortDirection !== null && sortDirection !== void 0 ? sortDirection : null);
|
|
9
|
-
const align = getAlignValue(column);
|
|
10
|
-
const dividerClass = getDividerClass(column);
|
|
11
|
-
const alignClasses = getHeaderAlignClasses(align);
|
|
12
|
-
const handleToggleSort = () => {
|
|
13
|
-
if (!column.sortable || !onSortChange)
|
|
14
|
-
return;
|
|
15
|
-
const nextDirection = getNextSortDirection(column.sortable, active, sortDirection !== null && sortDirection !== void 0 ? sortDirection : null);
|
|
16
|
-
onSortChange(column, nextDirection);
|
|
17
|
-
};
|
|
18
|
-
return (_jsxs("th", { className: cx(styles.headerCell, dividerClass), scope: "col", "aria-sort": ariaSort, "data-align": align, "data-divider": column.divider, "data-column-index": index, children: [_jsx("div", { className: alignClasses.inner, children: _jsx("div", { className: alignClasses.main, children: column.sortable ? (_jsxs("button", { type: "button", className: alignClasses.button, onClick: handleToggleSort, onKeyDown: e => {
|
|
19
|
-
if (!shouldToggleOnKey(e.key))
|
|
20
|
-
return;
|
|
21
|
-
e.preventDefault();
|
|
22
|
-
handleToggleSort();
|
|
23
|
-
}, children: [_jsx("span", { className: alignClasses.label, children: getHeaderLabel(column.header) }), _jsxs("span", { className: styles.sortIndicator, "aria-hidden": "true", children: [active && sortDirection === 'asc' && _jsx(ArrowUp, {}), active && sortDirection === 'desc' && _jsx(ArrowDown, {}), !active && _jsx(ArrowDown, { className: styles.inActiveSort })] })] })) : (_jsx("span", { className: alignClasses.label, children: getHeaderLabel(column.header) })) }) }), extraContent != null ? _jsx("div", { className: styles.thOverlayExtras, children: extraContent }) : null] }, column.id));
|
|
24
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { SkeletonLoaderItem } from '../../../components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem';
|
|
3
|
-
import { cx } from '../table.classes';
|
|
4
|
-
import styles from '../Table.module.css';
|
|
5
|
-
function getColumnWidth(column) {
|
|
6
|
-
// If column.width is defined and less than 150px, use 100%
|
|
7
|
-
if (typeof column.width === 'number' && column.width < 150) {
|
|
8
|
-
return '100%';
|
|
9
|
-
}
|
|
10
|
-
if (typeof column.width === 'string' && column.width.endsWith('px')) {
|
|
11
|
-
const px = parseInt(column.width, 10);
|
|
12
|
-
if (!isNaN(px) && px < 150) {
|
|
13
|
-
return '100%';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Otherwise, random between 50% and 90%
|
|
17
|
-
const percent = Math.floor(Math.random() * (90 - 50 + 1)) + 50;
|
|
18
|
-
return `${percent}%`;
|
|
19
|
-
}
|
|
20
|
-
export function TableLoadingBody({ rows, columns, hasSelection }) {
|
|
21
|
-
const widths = Array.from({ length: rows }, () => columns.map(getColumnWidth));
|
|
22
|
-
return (_jsx("tbody", { className: styles.body, children: Array.from({ length: rows }).map((_, rowIndex) => (_jsxs("tr", { className: styles.row, children: [hasSelection ? (_jsx("td", { className: cx(styles.cell, styles.selectionCell), children: _jsx("div", { className: styles.cellContent, children: _jsx(SkeletonLoaderItem, { height: 20, width: 20 }) }) })) : null, columns.map((column, columnIndex) => {
|
|
23
|
-
var _a;
|
|
24
|
-
return (_jsx("td", { className: cx(styles.cell, column.divider === 'left' && styles.dividerLeft, column.divider === 'right' && styles.dividerRight), "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', "data-divider": column.divider, children: _jsx("div", { className: styles.cellContent, children: _jsx("div", { className: styles.cellValueEllipsis, children: _jsx(SkeletonLoaderItem, { height: 16, width: widths[rowIndex][columnIndex] }) }) }) }, column.id));
|
|
25
|
-
})] }, `loading-row-${rowIndex}`))) }));
|
|
26
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Checkbox } from '../../../components/forms/checkbox/Checkbox';
|
|
3
|
-
import { RadioButton } from '../../../components/forms/radio-buttons/RadioButton';
|
|
4
|
-
import { SeverityBorderColor } from '../../../constants/severity';
|
|
5
|
-
import { useTableRowInteractions } from '../hooks/useTableRowInteractions';
|
|
6
|
-
import { cx } from '../table.classes';
|
|
7
|
-
import styles from '../Table.module.css';
|
|
8
|
-
import { getCellDisplayValue, shouldAllowWrap } from '../table.utils';
|
|
9
|
-
export function TableRow({ row, rowId, columns, selectedRows, hasSelection, selectionMode, selectionInputName, viewMode, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, }) {
|
|
10
|
-
var _a;
|
|
11
|
-
const isSelected = (_a = selectedRows === null || selectedRows === void 0 ? void 0 : selectedRows.has(rowId)) !== null && _a !== void 0 ? _a : false;
|
|
12
|
-
const rowSeverity = getRowSeverity === null || getRowSeverity === void 0 ? void 0 : getRowSeverity(row);
|
|
13
|
-
const canSelect = Boolean(selectedRows && onRowSelect);
|
|
14
|
-
const { handleRowClick, handleRowKeyDown } = useTableRowInteractions({
|
|
15
|
-
row,
|
|
16
|
-
rowId,
|
|
17
|
-
isSelected,
|
|
18
|
-
canSelect,
|
|
19
|
-
onRowClick,
|
|
20
|
-
onRowSelect,
|
|
21
|
-
});
|
|
22
|
-
return (_jsxs("tr", { className: cx(styles.row, onRowClick && styles.clickableRow, isSelected && styles.selectedRow, rowSeverity && styles.severity), style: {
|
|
23
|
-
['--row-severity-color']: rowSeverity
|
|
24
|
-
? SeverityBorderColor[rowSeverity]
|
|
25
|
-
: undefined,
|
|
26
|
-
}, tabIndex: onRowClick ? 0 : -1, onKeyDown: handleRowKeyDown, onMouseEnter: () => onRowMouseEnter === null || onRowMouseEnter === void 0 ? void 0 : onRowMouseEnter(row), onClick: handleRowClick, children: [hasSelection ? (_jsx("td", { className: cx(styles.cell, styles.selectionCell), "data-selection-control": "true", children: _jsx("div", { className: styles.selectionHitArea, "data-selection-control": "true", onClick: e => {
|
|
27
|
-
if (e.target !== e.currentTarget)
|
|
28
|
-
return;
|
|
29
|
-
e.stopPropagation();
|
|
30
|
-
onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(rowId, !isSelected);
|
|
31
|
-
}, children: _jsx("div", { className: styles.selectionControlWrap, "data-selection-control": "true", onMouseDown: e => {
|
|
32
|
-
if (selectionMode !== 'single' || !isSelected)
|
|
33
|
-
return;
|
|
34
|
-
e.preventDefault();
|
|
35
|
-
}, onClick: e => {
|
|
36
|
-
e.stopPropagation();
|
|
37
|
-
if (selectionMode === 'single' && isSelected) {
|
|
38
|
-
e.preventDefault();
|
|
39
|
-
onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(rowId, false);
|
|
40
|
-
}
|
|
41
|
-
}, children: selectionMode === 'single' ? (_jsx(RadioButton, { noContainer: true, name: selectionInputName, value: String(rowId), checked: isSelected, size: "sm", variant: "primary", onChange: (_value, e) => {
|
|
42
|
-
e.stopPropagation();
|
|
43
|
-
onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(rowId, true);
|
|
44
|
-
} })) : (_jsx(Checkbox, { noContainer: true, variant: "primary", checked: isSelected, size: "sm", onChange: (checked, e) => {
|
|
45
|
-
e.stopPropagation();
|
|
46
|
-
onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(rowId, checked);
|
|
47
|
-
} })) }) }) })) : null, columns.map(column => {
|
|
48
|
-
var _a, _b, _c, _d;
|
|
49
|
-
const allowWrap = shouldAllowWrap(column.allowWrap, isSelected, viewMode);
|
|
50
|
-
const allowOverflow = column.allowOverflow;
|
|
51
|
-
const cellValue = getCellDisplayValue(row, column);
|
|
52
|
-
return (_jsx("td", { className: cx(styles.cell, allowWrap ? styles.allowWrap : styles.nowrap, column.divider === 'left' && styles.dividerLeft, column.divider === 'right' && styles.dividerRight), "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', "data-vertical-align": (_b = column.verticalAlign) !== null && _b !== void 0 ? _b : 'top', "data-divider": column.divider, children: _jsx("div", { className: styles.cellContent, "data-align": (_c = column.align) !== null && _c !== void 0 ? _c : 'left', "data-vertical-align": (_d = column.verticalAlign) !== null && _d !== void 0 ? _d : 'top', children: allowWrap || allowOverflow ? (cellValue) : (_jsx("div", { className: styles.cellValueEllipsis, children: cellValue })) }) }, column.id));
|
|
53
|
-
})] }));
|
|
54
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Checkbox } from '../../../components/forms/checkbox/Checkbox';
|
|
3
|
-
import { cx } from '../table.classes';
|
|
4
|
-
import styles from '../Table.module.css';
|
|
5
|
-
export function TableSelectionCell({ checked, isHeader, multiple, onToggle }) {
|
|
6
|
-
const Tag = isHeader ? 'th' : 'td';
|
|
7
|
-
return (_jsx(Tag, { className: cx(styles.headerCell, styles.selectionCell), scope: isHeader ? 'col' : undefined, onClick: e => {
|
|
8
|
-
if (isHeader && !multiple)
|
|
9
|
-
return;
|
|
10
|
-
e.stopPropagation();
|
|
11
|
-
onToggle(!checked, e);
|
|
12
|
-
}, children: isHeader && !multiple ? null : (_jsx("div", { className: styles.selectionHitArea, children: _jsx(Checkbox, { noContainer: true, size: "sm", variant: "primary", checked: checked, onChange: (nextChecked, e) => {
|
|
13
|
-
e.stopPropagation();
|
|
14
|
-
onToggle(nextChecked, e);
|
|
15
|
-
} }) })) }));
|
|
16
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import styles from './ColumnResizer.module.css';
|
|
4
|
-
const ColumnResizer = ({ id, handler }) => (_jsx("span", { className: styles.resizer, "data-resizer": "true", onMouseDown: handler, onTouchStart: handler, role: "separator", "aria-orientation": "vertical", "aria-label": `Resize ${id}` }));
|
|
5
|
-
export default ColumnResizer;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
.resizer {
|
|
2
|
-
position: absolute;
|
|
3
|
-
right: 0;
|
|
4
|
-
top: 0;
|
|
5
|
-
height: 100%;
|
|
6
|
-
width: 10px;
|
|
7
|
-
cursor: col-resize;
|
|
8
|
-
user-select: none;
|
|
9
|
-
touch-action: none;
|
|
10
|
-
z-index: 20;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.resizer::after {
|
|
14
|
-
content: '';
|
|
15
|
-
position: absolute;
|
|
16
|
-
right: 0;
|
|
17
|
-
width: 1px; /* visual thickness */
|
|
18
|
-
height: 60%;
|
|
19
|
-
top: 50%;
|
|
20
|
-
transform: translateY(-50%);
|
|
21
|
-
background-color: var(--opac-bg-default);
|
|
22
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ArrowLeft } from 'lucide-react';
|
|
3
|
-
const defaultEmptyConfig = {
|
|
4
|
-
enabled: true,
|
|
5
|
-
title: 'Ingen resultater',
|
|
6
|
-
description: _jsx("span", { children: "Ingen data at vise." }),
|
|
7
|
-
showBack: false,
|
|
8
|
-
showRefresh: false,
|
|
9
|
-
showClearFilters: true,
|
|
10
|
-
backLabel: (_jsxs(_Fragment, { children: [_jsx(ArrowLeft, { size: 16 }), "Tilbage"] })),
|
|
11
|
-
refreshLabel: _jsx(_Fragment, { children: "Indl\u00E6s igen" }),
|
|
12
|
-
clearFiltersLabel: _jsx(_Fragment, { children: "Nulstil alle filtre" }),
|
|
13
|
-
className: 'dbc-flex dbc-flex-column dbc-items-start dbc-justify-start dbc-text-left dbc-gap-sm dbc-py-lg',
|
|
14
|
-
};
|
|
15
|
-
export function TableEmptyState({ config }) {
|
|
16
|
-
const merged = {
|
|
17
|
-
...defaultEmptyConfig,
|
|
18
|
-
...(config !== null && config !== void 0 ? config : {}),
|
|
19
|
-
};
|
|
20
|
-
if (!merged.enabled)
|
|
21
|
-
return null;
|
|
22
|
-
return (_jsxs("div", { className: "dbc-flex dbc-flex-column dbc-gap-md dbc-pt-sm dbc-pb-sm", children: [_jsx("span", { className: "dbc-text-sm dbc-muted-text", children: merged.description }), merged.actions ? _jsx("span", { className: "dbc-flex dbc-gap-sm", children: merged.actions }) : null] }));
|
|
23
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { ListChevronsDownUp, Settings } from 'lucide-react';
|
|
4
|
-
import { useMemo } from 'react';
|
|
5
|
-
import { Button } from '../../../button/Button';
|
|
6
|
-
import { Menu } from '../../../menu/Menu';
|
|
7
|
-
import { Popover } from '../../../popover/Popover';
|
|
8
|
-
export function TableSettings({ viewMode, handleChangeViewMode, columns = [], visibleColumnIds = [], onVisibleColumnIdsChange, columnsLabel = 'Kolonner', allPresetLabel = 'Alle', standardPresetLabel = 'Standard', buttonSize = 'sm', additionalSettings, }) {
|
|
9
|
-
const handleViewModeChange = (mode, close) => {
|
|
10
|
-
handleChangeViewMode(mode === 'wrapped' ? 'compact' : 'wrapped');
|
|
11
|
-
close === null || close === void 0 ? void 0 : close();
|
|
12
|
-
};
|
|
13
|
-
const hideableColumns = useMemo(() => columns.filter(c => c.enableHiding !== false), [columns]);
|
|
14
|
-
const allPresetIds = useMemo(() => hideableColumns.map(c => c.id), [hideableColumns]);
|
|
15
|
-
const standardPresetIds = useMemo(() => hideableColumns.filter(c => { var _a; return ((_a = c.meta) === null || _a === void 0 ? void 0 : _a.hidden) !== true; }).map(c => c.id), [hideableColumns]);
|
|
16
|
-
const visibleSet = useMemo(() => new Set(visibleColumnIds), [visibleColumnIds]);
|
|
17
|
-
const visibleCount = useMemo(() => {
|
|
18
|
-
return hideableColumns.reduce((acc, c) => { var _a; return acc + (visibleSet.has((_a = c.id) !== null && _a !== void 0 ? _a : '') ? 1 : 0); }, 0);
|
|
19
|
-
}, [hideableColumns, visibleSet]);
|
|
20
|
-
const setVisibleIds = (nextIds) => {
|
|
21
|
-
if (!onVisibleColumnIdsChange)
|
|
22
|
-
return;
|
|
23
|
-
const safe = nextIds.length > 0 ? nextIds : standardPresetIds.length > 0 ? standardPresetIds : allPresetIds;
|
|
24
|
-
onVisibleColumnIdsChange(safe.filter((id) => typeof id === 'string' && Boolean(id)));
|
|
25
|
-
};
|
|
26
|
-
const toggleColumn = (id, nextVisible) => {
|
|
27
|
-
const next = new Set(visibleColumnIds);
|
|
28
|
-
if (nextVisible)
|
|
29
|
-
next.add(id);
|
|
30
|
-
else
|
|
31
|
-
next.delete(id);
|
|
32
|
-
setVisibleIds(Array.from(next));
|
|
33
|
-
};
|
|
34
|
-
const isAllActive = useMemo(() => {
|
|
35
|
-
if (!hideableColumns.length)
|
|
36
|
-
return false;
|
|
37
|
-
return hideableColumns.every(c => c.id && visibleSet.has(c.id));
|
|
38
|
-
}, [hideableColumns, visibleSet]);
|
|
39
|
-
const isStandardActive = useMemo(() => {
|
|
40
|
-
if (!hideableColumns.length)
|
|
41
|
-
return false;
|
|
42
|
-
const std = new Set(standardPresetIds);
|
|
43
|
-
return hideableColumns.every(c => c.id && visibleSet.has(c.id) === std.has(c.id));
|
|
44
|
-
}, [hideableColumns, visibleSet, standardPresetIds]);
|
|
45
|
-
// Required by your RadioButton component
|
|
46
|
-
const presetRadioName = 'table-columns-preset';
|
|
47
|
-
return (_jsx(Popover, { trigger: (onClick, icon) => (_jsxs(Button, { size: buttonSize, onClick: onClick, type: "button", children: [_jsx(Settings, {}), icon] })), children: close => (_jsxs(Menu, { children: [additionalSettings === null || additionalSettings === void 0 ? void 0 : additionalSettings(close), _jsx(Menu.Item, { active: viewMode === 'wrapped', children: _jsxs("button", { type: "button", onClick: () => handleViewModeChange(viewMode, close), children: [_jsx(ListChevronsDownUp, {}), "Ombryd tekst"] }) }), hideableColumns.length > 0 && onVisibleColumnIdsChange ? (_jsxs(_Fragment, { children: [_jsx(Menu.Separator, {}), _jsx("div", { style: { padding: '6px 10px', fontSize: 12, opacity: 0.7 }, children: columnsLabel }), _jsx(Menu.RadioItem, { name: presetRadioName, value: "all", checked: isAllActive, label: allPresetLabel, onValueChange: () => {
|
|
48
|
-
setVisibleIds(allPresetIds.filter((id) => typeof id === 'string' && Boolean(id)));
|
|
49
|
-
close === null || close === void 0 ? void 0 : close();
|
|
50
|
-
} }), _jsx(Menu.RadioItem, { name: presetRadioName, value: "standard", checked: isStandardActive, label: standardPresetLabel, onValueChange: () => {
|
|
51
|
-
setVisibleIds(standardPresetIds.filter((id) => typeof id === 'string' && Boolean(id)));
|
|
52
|
-
close === null || close === void 0 ? void 0 : close();
|
|
53
|
-
} }), _jsx(Menu.Separator, {}), hideableColumns.map(col => {
|
|
54
|
-
const isVisible = col.id ? visibleSet.has(col.id) : false;
|
|
55
|
-
const disableUncheckingLast = isVisible && visibleCount <= 1;
|
|
56
|
-
const label = col.header;
|
|
57
|
-
return (_jsx(Menu.CheckItem, { checked: isVisible, disabled: disableUncheckingLast, label: label, onCheckedChange: nextChecked => {
|
|
58
|
-
if (disableUncheckingLast)
|
|
59
|
-
return;
|
|
60
|
-
toggleColumn(col.id, nextChecked);
|
|
61
|
-
} }, col.id));
|
|
62
|
-
})] })) : null] })) }));
|
|
63
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { isModifierClick, shouldToggleOnKey } from '../table.utils';
|
|
3
|
-
export function useTableRowInteractions({ row, rowId, isSelected, canSelect, onRowClick, onRowSelect, }) {
|
|
4
|
-
const handleRowClick = useCallback((e) => {
|
|
5
|
-
var _a;
|
|
6
|
-
const target = e.target;
|
|
7
|
-
if ((_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '[data-selection-control="true"]')) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (isModifierClick(e) && canSelect) {
|
|
11
|
-
e.preventDefault();
|
|
12
|
-
e.stopPropagation();
|
|
13
|
-
onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(rowId, !isSelected);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(row);
|
|
17
|
-
}, [canSelect, isSelected, onRowClick, onRowSelect, row, rowId]);
|
|
18
|
-
const handleRowKeyDown = useCallback((e) => {
|
|
19
|
-
if (!onRowClick)
|
|
20
|
-
return;
|
|
21
|
-
if (!shouldToggleOnKey(e.key))
|
|
22
|
-
return;
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
onRowClick(row);
|
|
25
|
-
}, [onRowClick, row]);
|
|
26
|
-
return {
|
|
27
|
-
handleRowClick,
|
|
28
|
-
handleRowKeyDown,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import styles from './Table.module.css';
|
|
2
|
-
export function cx(...values) {
|
|
3
|
-
return values.filter(Boolean).join(' ');
|
|
4
|
-
}
|
|
5
|
-
export function getDividerClass(column) {
|
|
6
|
-
if (column.divider === 'left')
|
|
7
|
-
return styles.dividerLeft;
|
|
8
|
-
if (column.divider === 'right')
|
|
9
|
-
return styles.dividerRight;
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
export function getAlignValue(column) {
|
|
13
|
-
var _a;
|
|
14
|
-
return (_a = column.align) !== null && _a !== void 0 ? _a : 'left';
|
|
15
|
-
}
|
|
16
|
-
export function getHeaderAlignClasses(align) {
|
|
17
|
-
return {
|
|
18
|
-
inner: cx(styles.thInner, align === 'right' && styles.thInnerRight, align === 'center' && styles.thInnerCenter),
|
|
19
|
-
main: cx(styles.thMain, align === 'right' && styles.thMainRight, align === 'center' && styles.thMainCenter),
|
|
20
|
-
button: cx(styles.thButton, align === 'right' && styles.thButtonRight, align === 'center' && styles.thButtonCenter),
|
|
21
|
-
label: cx(styles.thLabel, align === 'right' && styles.thLabelRight, align === 'center' && styles.thLabelCenter),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export const SELECTION_COLUMN_PX = 40;
|
|
2
|
-
export const DEFAULT_COLUMN_PX = 150;
|
|
3
|
-
export function getVisibleColumns(columns) {
|
|
4
|
-
return columns.filter(column => !column.hidden);
|
|
5
|
-
}
|
|
6
|
-
export function getHeaderLabel(header) {
|
|
7
|
-
return typeof header === 'function' ? header() : header;
|
|
8
|
-
}
|
|
9
|
-
export function isActiveSort(sortById, columnId) {
|
|
10
|
-
return sortById === columnId;
|
|
11
|
-
}
|
|
12
|
-
export function getAriaSort(sortable, active, direction) {
|
|
13
|
-
if (!sortable || !active || !direction)
|
|
14
|
-
return 'none';
|
|
15
|
-
return direction === 'asc' ? 'ascending' : 'descending';
|
|
16
|
-
}
|
|
17
|
-
export function getNextSortDirection(sortable, active, currentDirection) {
|
|
18
|
-
if (!sortable)
|
|
19
|
-
return null;
|
|
20
|
-
if (!active)
|
|
21
|
-
return 'asc';
|
|
22
|
-
if (currentDirection === 'asc')
|
|
23
|
-
return 'desc';
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
export function shouldToggleOnKey(key) {
|
|
27
|
-
return key === 'Enter' || key === ' ';
|
|
28
|
-
}
|
|
29
|
-
export function isModifierClick(e) {
|
|
30
|
-
return Boolean(e.metaKey || e.ctrlKey);
|
|
31
|
-
}
|
|
32
|
-
export function shouldAllowWrap(columnAllowWrap, isRowSelected, viewMode) {
|
|
33
|
-
return Boolean(columnAllowWrap || isRowSelected || viewMode === 'wrapped');
|
|
34
|
-
}
|
|
35
|
-
export function getCellDisplayValue(row, column) {
|
|
36
|
-
var _a;
|
|
37
|
-
const empty = (_a = column.emptyPlaceholder) !== null && _a !== void 0 ? _a : '';
|
|
38
|
-
if (column.render) {
|
|
39
|
-
const rendered = column.render(row);
|
|
40
|
-
return rendered !== null && rendered !== void 0 ? rendered : empty;
|
|
41
|
-
}
|
|
42
|
-
if (column.accessor) {
|
|
43
|
-
const value = row[column.accessor];
|
|
44
|
-
return value !== null && value !== void 0 ? value : empty;
|
|
45
|
-
}
|
|
46
|
-
return empty;
|
|
47
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX } from './table.utils';
|
|
2
|
-
export function getColumnId(def, index) {
|
|
3
|
-
const d = def;
|
|
4
|
-
if (d.id != null && String(d.id).length > 0)
|
|
5
|
-
return String(d.id);
|
|
6
|
-
if (d.accessorKey != null && String(d.accessorKey).length > 0)
|
|
7
|
-
return String(d.accessorKey);
|
|
8
|
-
return `col_${index}`;
|
|
9
|
-
}
|
|
10
|
-
export function buildColumnVisibilityFromVisibleIds(defs, visibleColumnIds) {
|
|
11
|
-
if (!(visibleColumnIds === null || visibleColumnIds === void 0 ? void 0 : visibleColumnIds.length))
|
|
12
|
-
return {};
|
|
13
|
-
const visible = new Set(visibleColumnIds);
|
|
14
|
-
const next = {};
|
|
15
|
-
defs.forEach((def, index) => {
|
|
16
|
-
const id = getColumnId(def, index);
|
|
17
|
-
next[id] = visible.has(id);
|
|
18
|
-
});
|
|
19
|
-
return next;
|
|
20
|
-
}
|
|
21
|
-
export function mapDefsToColumnItems(defs, columnVisibility, resolvedLayout = {}) {
|
|
22
|
-
return defs.map((def, index) => {
|
|
23
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
24
|
-
const id = getColumnId(def, index);
|
|
25
|
-
const accessorKey = def.accessorKey;
|
|
26
|
-
const accessorFn = def.accessorFn;
|
|
27
|
-
const cell = def.cell;
|
|
28
|
-
const meta = ((_a = def.meta) !== null && _a !== void 0 ? _a : {});
|
|
29
|
-
let render;
|
|
30
|
-
if (typeof cell === 'function') {
|
|
31
|
-
render = (row) => cell({
|
|
32
|
-
row: { original: row },
|
|
33
|
-
getValue: () => accessorKey != null
|
|
34
|
-
? row[accessorKey]
|
|
35
|
-
: accessorFn
|
|
36
|
-
? accessorFn(row)
|
|
37
|
-
: undefined,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
else if (accessorFn) {
|
|
41
|
-
render = (row) => accessorFn(row);
|
|
42
|
-
}
|
|
43
|
-
else if (accessorKey != null) {
|
|
44
|
-
render = (row) => row[accessorKey];
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
render = () => null;
|
|
48
|
-
}
|
|
49
|
-
const isVisible = (_b = columnVisibility[id]) !== null && _b !== void 0 ? _b : true;
|
|
50
|
-
return {
|
|
51
|
-
id,
|
|
52
|
-
header: def.header,
|
|
53
|
-
accessor: accessorKey,
|
|
54
|
-
sortable: (_c = def.enableSorting) !== null && _c !== void 0 ? _c : !!accessorKey,
|
|
55
|
-
render,
|
|
56
|
-
hidden: !isVisible,
|
|
57
|
-
width: (_d = resolvedLayout[id]) === null || _d === void 0 ? void 0 : _d.width,
|
|
58
|
-
align: meta.align,
|
|
59
|
-
verticalAlign: meta.verticalAlign,
|
|
60
|
-
emptyPlaceholder: (_e = meta.emptyPlaceholder) !== null && _e !== void 0 ? _e : '-',
|
|
61
|
-
allowWrap: (_f = meta.allowWrap) !== null && _f !== void 0 ? _f : false,
|
|
62
|
-
severity: meta.severity,
|
|
63
|
-
divider: meta.divider,
|
|
64
|
-
allowOverflow: (_g = meta.allowOverflow) !== null && _g !== void 0 ? _g : false,
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
export function sortingEqual(a, b) {
|
|
69
|
-
const A = a === null || a === void 0 ? void 0 : a[0];
|
|
70
|
-
const B = b === null || b === void 0 ? void 0 : b[0];
|
|
71
|
-
if (!A && !B)
|
|
72
|
-
return true;
|
|
73
|
-
if (!A || !B)
|
|
74
|
-
return false;
|
|
75
|
-
return A.id === B.id && A.desc === B.desc;
|
|
76
|
-
}
|
|
77
|
-
export function getSortPropsFromSorting(sorting) {
|
|
78
|
-
const s = sorting === null || sorting === void 0 ? void 0 : sorting[0];
|
|
79
|
-
return {
|
|
80
|
-
sortById: s === null || s === void 0 ? void 0 : s.id,
|
|
81
|
-
sortDirection: s ? (s.desc ? 'desc' : 'asc') : null,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function clamp(value, min, max) {
|
|
85
|
-
const lowerBounded = Math.max(min, value);
|
|
86
|
-
if (max == null || !Number.isFinite(max))
|
|
87
|
-
return lowerBounded;
|
|
88
|
-
return Math.min(lowerBounded, max);
|
|
89
|
-
}
|
|
90
|
-
function toIntegerTrackWidths(tracks, targetWidth) {
|
|
91
|
-
const floored = tracks.map(track => ({
|
|
92
|
-
id: track.id,
|
|
93
|
-
width: Math.floor(track.width),
|
|
94
|
-
fraction: track.width - Math.floor(track.width),
|
|
95
|
-
}));
|
|
96
|
-
const baseTotal = floored.reduce((sum, track) => sum + track.width, 0);
|
|
97
|
-
let remainder = Math.max(0, targetWidth - baseTotal);
|
|
98
|
-
floored
|
|
99
|
-
.slice()
|
|
100
|
-
.sort((a, b) => b.fraction - a.fraction)
|
|
101
|
-
.forEach(track => {
|
|
102
|
-
if (remainder <= 0)
|
|
103
|
-
return;
|
|
104
|
-
track.width += 1;
|
|
105
|
-
remainder -= 1;
|
|
106
|
-
});
|
|
107
|
-
return Object.fromEntries(floored.map(track => [track.id, track.width]));
|
|
108
|
-
}
|
|
109
|
-
export function buildDistributedColumnWidths(args) {
|
|
110
|
-
const { table, hasSelection, defaultMinPx, columnSizing, availableWidth } = args;
|
|
111
|
-
const leaf = table.getVisibleLeafColumns();
|
|
112
|
-
const selectionWidth = hasSelection ? SELECTION_COLUMN_PX : 0;
|
|
113
|
-
const tracks = leaf.map((c) => {
|
|
114
|
-
var _a, _b, _c, _d;
|
|
115
|
-
const def = c.columnDef;
|
|
116
|
-
const meta = ((_a = def.meta) !== null && _a !== void 0 ? _a : {});
|
|
117
|
-
const min = Math.max(1, Number((_b = def.minSize) !== null && _b !== void 0 ? _b : defaultMinPx));
|
|
118
|
-
const max = def.maxSize != null ? Math.max(min, Number(def.maxSize)) : undefined;
|
|
119
|
-
const resizedPxRaw = columnSizing[c.id];
|
|
120
|
-
const resizedPx = resizedPxRaw != null ? Math.round(clamp(Number(resizedPxRaw), min, max)) : undefined;
|
|
121
|
-
if (resizedPx != null) {
|
|
122
|
-
return {
|
|
123
|
-
id: c.id,
|
|
124
|
-
width: resizedPx,
|
|
125
|
-
weight: 0,
|
|
126
|
-
max: resizedPx,
|
|
127
|
-
fixed: true,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
const rawWeight = Number((_d = (_c = meta.weight) !== null && _c !== void 0 ? _c : def.size) !== null && _d !== void 0 ? _d : DEFAULT_COLUMN_PX);
|
|
131
|
-
const weight = Number.isFinite(rawWeight) && rawWeight > 0 ? rawWeight : DEFAULT_COLUMN_PX;
|
|
132
|
-
return {
|
|
133
|
-
id: c.id,
|
|
134
|
-
width: min,
|
|
135
|
-
weight,
|
|
136
|
-
max,
|
|
137
|
-
fixed: false,
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
const fixedWidth = selectionWidth + tracks.reduce((sum, track) => sum + track.width, 0);
|
|
141
|
-
let remaining = Math.max(0, availableWidth - fixedWidth);
|
|
142
|
-
let active = tracks.filter(track => !track.fixed && (track.max == null || track.width < track.max));
|
|
143
|
-
while (remaining > 0.5 && active.length > 0) {
|
|
144
|
-
const totalWeight = active.reduce((sum, track) => sum + track.weight, 0);
|
|
145
|
-
if (totalWeight <= 0)
|
|
146
|
-
break;
|
|
147
|
-
let consumed = 0;
|
|
148
|
-
const nextActive = [];
|
|
149
|
-
for (const track of active) {
|
|
150
|
-
const share = (remaining * track.weight) / totalWeight;
|
|
151
|
-
const maxGrow = track.max == null ? share : Math.max(0, track.max - track.width);
|
|
152
|
-
const growth = Math.min(share, maxGrow);
|
|
153
|
-
track.width += growth;
|
|
154
|
-
consumed += growth;
|
|
155
|
-
if (track.max == null || track.width < track.max - 0.5) {
|
|
156
|
-
nextActive.push(track);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (consumed <= 0.5)
|
|
160
|
-
break;
|
|
161
|
-
remaining -= consumed;
|
|
162
|
-
active = nextActive;
|
|
163
|
-
}
|
|
164
|
-
const floatTrackTotal = tracks.reduce((sum, track) => sum + track.width, 0);
|
|
165
|
-
const targetTrackWidth = floatTrackTotal <= availableWidth - selectionWidth
|
|
166
|
-
? Math.floor(floatTrackTotal)
|
|
167
|
-
: Math.ceil(floatTrackTotal);
|
|
168
|
-
const widths = toIntegerTrackWidths(tracks, targetTrackWidth);
|
|
169
|
-
const totalWidth = selectionWidth + Object.values(widths).reduce((sum, width) => sum + width, 0);
|
|
170
|
-
return {
|
|
171
|
-
selectionWidth: hasSelection ? SELECTION_COLUMN_PX : undefined,
|
|
172
|
-
widths,
|
|
173
|
-
totalWidth,
|
|
174
|
-
};
|
|
175
|
-
}
|