schummar-table 0.4.0 → 0.5.0-beta-2
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/cjs/index.js +3800 -16
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mui4Theme.js +96 -0
- package/dist/cjs/mui4Theme.js.map +1 -0
- package/dist/cjs/mui5Theme.js +100 -0
- package/dist/cjs/mui5Theme.js.map +1 -0
- package/dist/es/index.js +3783 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/mui4Theme.js +92 -0
- package/dist/es/mui4Theme.js.map +1 -0
- package/dist/es/mui5Theme.js +96 -0
- package/dist/es/mui5Theme.js.map +1 -0
- package/dist/tableTheme.js +1990 -0
- package/dist/tableTheme.js.map +1 -0
- package/dist/{cjs → types}/components/cell.d.ts +1 -1
- package/dist/types/components/columnHeader.d.ts +7 -0
- package/dist/{cjs → types}/components/columnSelection.d.ts +0 -0
- package/dist/types/components/dateFilter.d.ts +8 -0
- package/dist/types/components/datePicker.d.ts +16 -0
- package/dist/types/components/expandControl.d.ts +6 -0
- package/dist/{cjs → types}/components/export.d.ts +0 -0
- package/dist/types/components/filterControl.d.ts +2 -0
- package/dist/types/components/formControlLabel.d.ts +5 -0
- package/dist/types/components/resizeHandle.d.ts +1 -0
- package/dist/{cjs → types}/components/row.d.ts +1 -1
- package/dist/{cjs → types}/components/selectComponent.d.ts +0 -0
- package/dist/types/components/selectFilter.d.ts +8 -0
- package/dist/{cjs → types}/components/sortComponent.d.ts +0 -0
- package/dist/types/components/spinnner.d.ts +3 -0
- package/dist/{cjs → types/components}/table.d.ts +1 -4
- package/dist/types/components/textFilter.d.ts +5 -0
- package/dist/{cjs → types}/components/virtualized.d.ts +0 -0
- package/dist/types/hooks/useFilter.d.ts +5 -0
- package/dist/types/hooks/useTheme.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/{cjs → types}/internalState/calcItems.d.ts +0 -0
- package/dist/{cjs → types}/internalState/calcProps.d.ts +0 -0
- package/dist/{cjs → types}/internalState/cleanupState.d.ts +0 -0
- package/dist/{cjs → types}/internalState/filterColumns.d.ts +0 -0
- package/dist/{cjs → types}/internalState/syncSelections.d.ts +0 -0
- package/dist/{cjs → types}/internalState/tableStateStorage.d.ts +1 -1
- package/dist/{cjs → types}/internalState/useTableState.d.ts +0 -0
- package/dist/{cjs → types}/misc/csvExport.d.ts +0 -0
- package/dist/types/misc/debounce.d.ts +4 -0
- package/dist/types/misc/deepPartial.d.ts +3 -0
- package/dist/{cjs → types}/misc/helpers.d.ts +2 -1
- package/dist/{cjs → types}/misc/queue.d.ts +1 -1
- package/dist/{cjs → types}/misc/textMatch.d.ts +0 -0
- package/dist/types/misc/throttle.d.ts +4 -0
- package/dist/types/theme/defaultClasses.d.ts +15 -0
- package/dist/types/theme/defaultColors.d.ts +2 -0
- package/dist/types/theme/defaultIcons.d.ts +2 -0
- package/dist/types/theme/defaultTexts.d.ts +2 -0
- package/dist/types/theme/defaultTheme/badge.d.ts +2 -0
- package/dist/types/theme/defaultTheme/button.d.ts +2 -0
- package/dist/types/theme/defaultTheme/checkbox.d.ts +2 -0
- package/dist/types/theme/defaultTheme/iconButton.d.ts +2 -0
- package/dist/types/theme/defaultTheme/index.d.ts +2 -0
- package/dist/types/theme/defaultTheme/popover.d.ts +4 -0
- package/dist/types/theme/defaultTheme/textField.d.ts +2 -0
- package/dist/types/theme/mui4Theme/index.d.ts +8 -0
- package/dist/types/theme/mui5Theme/index.d.ts +8 -0
- package/dist/types/theme/tableTheme.d.ts +11 -0
- package/dist/types/theme/useCssVariables.d.ts +9 -0
- package/dist/types/types.d.ts +285 -0
- package/package.json +76 -37
- package/dist/cjs/components/cell.js +0 -31
- package/dist/cjs/components/columnSelection.js +0 -37
- package/dist/cjs/components/defaultFilterComponent.d.ts +0 -22
- package/dist/cjs/components/defaultFilterComponent.js +0 -91
- package/dist/cjs/components/expandComponent.d.ts +0 -5
- package/dist/cjs/components/expandComponent.js +0 -38
- package/dist/cjs/components/export.js +0 -48
- package/dist/cjs/components/filterComponent.d.ts +0 -5
- package/dist/cjs/components/filterComponent.js +0 -25
- package/dist/cjs/components/row.js +0 -51
- package/dist/cjs/components/selectComponent.js +0 -61
- package/dist/cjs/components/sortComponent.js +0 -52
- package/dist/cjs/components/textFilterComponent.d.ts +0 -11
- package/dist/cjs/components/textFilterComponent.js +0 -70
- package/dist/cjs/components/useCommonClasses.d.ts +0 -1
- package/dist/cjs/components/useCommonClasses.js +0 -49
- package/dist/cjs/components/virtualized.js +0 -98
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/internalState/calcItems.js +0 -85
- package/dist/cjs/internalState/calcProps.js +0 -89
- package/dist/cjs/internalState/cleanupState.js +0 -43
- package/dist/cjs/internalState/filterColumns.js +0 -10
- package/dist/cjs/internalState/syncSelections.js +0 -22
- package/dist/cjs/internalState/tableStateStorage.js +0 -74
- package/dist/cjs/internalState/useTableState.js +0 -62
- package/dist/cjs/misc/csvExport.js +0 -15
- package/dist/cjs/misc/helpers.js +0 -91
- package/dist/cjs/misc/queue.js +0 -42
- package/dist/cjs/misc/textMatch.js +0 -23
- package/dist/cjs/misc/throttle.d.ts +0 -1
- package/dist/cjs/misc/throttle.js +0 -30
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/table.js +0 -80
- package/dist/cjs/types.d.ts +0 -146
- package/dist/cjs/types.js +0 -2
- package/dist/esm/components/cell.d.ts +0 -6
- package/dist/esm/components/cell.js +0 -28
- package/dist/esm/components/columnSelection.d.ts +0 -2
- package/dist/esm/components/columnSelection.js +0 -33
- package/dist/esm/components/defaultFilterComponent.d.ts +0 -22
- package/dist/esm/components/defaultFilterComponent.js +0 -86
- package/dist/esm/components/expandComponent.d.ts +0 -5
- package/dist/esm/components/expandComponent.js +0 -34
- package/dist/esm/components/export.d.ts +0 -2
- package/dist/esm/components/export.js +0 -44
- package/dist/esm/components/filterComponent.d.ts +0 -5
- package/dist/esm/components/filterComponent.js +0 -21
- package/dist/esm/components/row.d.ts +0 -7
- package/dist/esm/components/row.js +0 -47
- package/dist/esm/components/selectComponent.d.ts +0 -5
- package/dist/esm/components/selectComponent.js +0 -57
- package/dist/esm/components/sortComponent.d.ts +0 -4
- package/dist/esm/components/sortComponent.js +0 -48
- package/dist/esm/components/textFilterComponent.d.ts +0 -11
- package/dist/esm/components/textFilterComponent.js +0 -65
- package/dist/esm/components/useCommonClasses.d.ts +0 -1
- package/dist/esm/components/useCommonClasses.js +0 -46
- package/dist/esm/components/virtualized.d.ts +0 -6
- package/dist/esm/components/virtualized.js +0 -94
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.js +0 -4
- package/dist/esm/internalState/calcItems.d.ts +0 -3
- package/dist/esm/internalState/calcItems.js +0 -81
- package/dist/esm/internalState/calcProps.d.ts +0 -2
- package/dist/esm/internalState/calcProps.js +0 -85
- package/dist/esm/internalState/cleanupState.d.ts +0 -3
- package/dist/esm/internalState/cleanupState.js +0 -39
- package/dist/esm/internalState/filterColumns.d.ts +0 -3
- package/dist/esm/internalState/filterColumns.js +0 -6
- package/dist/esm/internalState/syncSelections.d.ts +0 -3
- package/dist/esm/internalState/syncSelections.js +0 -18
- package/dist/esm/internalState/tableStateStorage.d.ts +0 -11
- package/dist/esm/internalState/tableStateStorage.js +0 -70
- package/dist/esm/internalState/useTableState.d.ts +0 -3
- package/dist/esm/internalState/useTableState.js +0 -58
- package/dist/esm/misc/csvExport.d.ts +0 -7
- package/dist/esm/misc/csvExport.js +0 -11
- package/dist/esm/misc/helpers.d.ts +0 -14
- package/dist/esm/misc/helpers.js +0 -77
- package/dist/esm/misc/queue.d.ts +0 -6
- package/dist/esm/misc/queue.js +0 -38
- package/dist/esm/misc/textMatch.d.ts +0 -2
- package/dist/esm/misc/textMatch.js +0 -18
- package/dist/esm/misc/throttle.d.ts +0 -1
- package/dist/esm/misc/throttle.js +0 -26
- package/dist/esm/table.d.ts +0 -11
- package/dist/esm/table.js +0 -73
- package/dist/esm/types.d.ts +0 -146
- package/dist/esm/types.js +0 -1
package/dist/cjs/table.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Table = exports.configureTables = exports.useColumnContext = exports.useTableContext = exports.ColumnContext = exports.TableContext = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const columnSelection_1 = require("./components/columnSelection");
|
|
7
|
-
const export_1 = require("./components/export");
|
|
8
|
-
const filterComponent_1 = require("./components/filterComponent");
|
|
9
|
-
const row_1 = require("./components/row");
|
|
10
|
-
const selectComponent_1 = require("./components/selectComponent");
|
|
11
|
-
const sortComponent_1 = require("./components/sortComponent");
|
|
12
|
-
const useCommonClasses_1 = require("./components/useCommonClasses");
|
|
13
|
-
const virtualized_1 = require("./components/virtualized");
|
|
14
|
-
const tableStateStorage_1 = require("./internalState/tableStateStorage");
|
|
15
|
-
const useTableState_1 = require("./internalState/useTableState");
|
|
16
|
-
const helpers_1 = require("./misc/helpers");
|
|
17
|
-
exports.TableContext = (0, react_1.createContext)(null);
|
|
18
|
-
exports.ColumnContext = (0, react_1.createContext)(null);
|
|
19
|
-
function useTableContext() {
|
|
20
|
-
const value = (0, react_1.useContext)(exports.TableContext);
|
|
21
|
-
if (!value)
|
|
22
|
-
throw Error('No table context available');
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
exports.useTableContext = useTableContext;
|
|
26
|
-
function useColumnContext() {
|
|
27
|
-
const value = (0, react_1.useContext)(exports.ColumnContext);
|
|
28
|
-
if (value === null)
|
|
29
|
-
throw Error('No column context available');
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
exports.useColumnContext = useColumnContext;
|
|
33
|
-
let defaultProps = {};
|
|
34
|
-
function configureTables(props) {
|
|
35
|
-
defaultProps = props;
|
|
36
|
-
}
|
|
37
|
-
exports.configureTables = configureTables;
|
|
38
|
-
function mergeProps(props) {
|
|
39
|
-
return Object.assign(Object.assign({}, props), { text: Object.assign(Object.assign({}, defaultProps.text), props.text), classes: Object.assign(Object.assign({}, defaultProps.classes), props.classes) });
|
|
40
|
-
}
|
|
41
|
-
function Table(props) {
|
|
42
|
-
var _a, _b;
|
|
43
|
-
props = mergeProps(props);
|
|
44
|
-
const state = (0, useTableState_1.useTableState)(props);
|
|
45
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render table');
|
|
46
|
-
return ((0, jsx_runtime_1.jsx)(exports.TableContext.Provider, Object.assign({ value: state }, { children: (0, jsx_runtime_1.jsx)(TableInner, {}, void 0) }), void 0));
|
|
47
|
-
}
|
|
48
|
-
exports.Table = Table;
|
|
49
|
-
const TableInner = (0, react_1.memo)(function TableInner() {
|
|
50
|
-
var _a, _b;
|
|
51
|
-
(0, tableStateStorage_1.useTableStateStorage)();
|
|
52
|
-
const commonClasses = (0, useCommonClasses_1.useCommonClasses)();
|
|
53
|
-
const state = useTableContext();
|
|
54
|
-
const fullWidth = state.useState('props.fullWidth');
|
|
55
|
-
const activeColumns = state.useState((state) => state.activeColumns.map((column) => ({
|
|
56
|
-
id: column.id,
|
|
57
|
-
width: column.width,
|
|
58
|
-
classes: column.classes,
|
|
59
|
-
header: column.header,
|
|
60
|
-
})));
|
|
61
|
-
const defaultWidth = state.useState('props.defaultWidth');
|
|
62
|
-
const classes = state.useState('props.classes');
|
|
63
|
-
const stickyHeader = state.useState('props.stickyHeader');
|
|
64
|
-
const enableSelection = state.useState('props.enableSelection');
|
|
65
|
-
const enableColumnSelection = state.useState('props.enableColumnSelection');
|
|
66
|
-
const enableExport = state.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
67
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render table inner');
|
|
68
|
-
return ((0, jsx_runtime_1.jsx)(virtualized_1.Virtualized, Object.assign({ className: (0, helpers_1.c)(commonClasses.table, classes === null || classes === void 0 ? void 0 : classes.table), style: {
|
|
69
|
-
gridTemplateColumns: [
|
|
70
|
-
//
|
|
71
|
-
fullWidth === 'right' || fullWidth === true ? 'auto' : '0',
|
|
72
|
-
'max-content',
|
|
73
|
-
...activeColumns.map((column) => { var _a, _b; return (_b = (_a = column.width) !== null && _a !== void 0 ? _a : defaultWidth) !== null && _b !== void 0 ? _b : 'max-content'; }),
|
|
74
|
-
fullWidth === 'left' || fullWidth === true ? 'auto' : '0',
|
|
75
|
-
].join(' '),
|
|
76
|
-
}, header: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: (0, helpers_1.c)(commonClasses.headerFill, { [commonClasses.sticky]: !!stickyHeader }, classes === null || classes === void 0 ? void 0 : classes.headerCell) }, void 0), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, helpers_1.c)(commonClasses.headerCell, { [commonClasses.sticky]: !!stickyHeader }, classes === null || classes === void 0 ? void 0 : classes.headerCell) }, { children: [enableSelection && (0, jsx_runtime_1.jsx)(selectComponent_1.SelectComponent, {}, void 0), enableColumnSelection && (0, jsx_runtime_1.jsx)(columnSelection_1.ColumnSelection, {}, void 0), enableExport && (0, jsx_runtime_1.jsx)(export_1.Export, {}, void 0)] }), void 0), activeColumns.map((column) => {
|
|
77
|
-
var _a;
|
|
78
|
-
return ((0, jsx_runtime_1.jsx)(exports.ColumnContext.Provider, Object.assign({ value: column.id }, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, helpers_1.c)(commonClasses.headerCell, { [commonClasses.sticky]: !!stickyHeader }, classes === null || classes === void 0 ? void 0 : classes.headerCell, (_a = column.classes) === null || _a === void 0 ? void 0 : _a.headerCell) }, { children: [(0, jsx_runtime_1.jsx)(sortComponent_1.SortComponent, { children: column.header }, void 0), (0, jsx_runtime_1.jsx)(filterComponent_1.FilterComponent, {}, void 0)] }), column.id) }), column.id));
|
|
79
|
-
}), (0, jsx_runtime_1.jsx)("div", { className: (0, helpers_1.c)(commonClasses.headerFill, { [commonClasses.sticky]: !!stickyHeader }, classes === null || classes === void 0 ? void 0 : classes.headerCell) }, void 0)] }, void 0) }, { children: (itemIds, startIndex) => itemIds.map((itemId, index) => (0, jsx_runtime_1.jsx)(row_1.Row, { itemId: itemId, rowIndex: startIndex + index }, itemId)) }), void 0));
|
|
80
|
-
});
|
package/dist/cjs/types.d.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
import { Filter } from './components/filterComponent';
|
|
3
|
-
import { CsvExportOptions } from './misc/csvExport';
|
|
4
|
-
import { TableStateStorage } from './internalState/tableStateStorage';
|
|
5
|
-
export declare type Sort = {
|
|
6
|
-
columnId: string | number;
|
|
7
|
-
direction: SortDirection;
|
|
8
|
-
};
|
|
9
|
-
export declare type SortDirection = 'asc' | 'desc';
|
|
10
|
-
export declare type Id = string | number;
|
|
11
|
-
export declare type KeyOfType<T, S> = {
|
|
12
|
-
[K in keyof T]: T[K] extends S ? K : never;
|
|
13
|
-
}[keyof T];
|
|
14
|
-
export declare type TableProps<T> = {
|
|
15
|
-
items?: T[];
|
|
16
|
-
id: ((item: T) => Id) | KeyOfType<T, Id>;
|
|
17
|
-
parentId?: ((item: T) => Id | undefined) | KeyOfType<T, Id | undefined>;
|
|
18
|
-
hasDeferredChildren?: (item: T) => boolean;
|
|
19
|
-
columns: Column<T, any>[] | ((col: <V>(value: (item: T) => V, column: Omit<Column<T, V>, 'value'>) => Column<T, V>) => Column<T, any>[]);
|
|
20
|
-
rowAction?: ReactNode | ((item: T, index: number) => ReactNode);
|
|
21
|
-
defaultSort?: Sort[];
|
|
22
|
-
sort?: Sort[];
|
|
23
|
-
onSortChange?: (sort: Sort[]) => void;
|
|
24
|
-
defaultSelection?: Set<Id>;
|
|
25
|
-
selection?: Set<Id>;
|
|
26
|
-
onSelectionChange?: (selection: Set<Id>) => void;
|
|
27
|
-
selectSyncChildren?: boolean;
|
|
28
|
-
revealFiltered?: boolean;
|
|
29
|
-
defaultExpanded?: Set<Id>;
|
|
30
|
-
expanded?: Set<Id>;
|
|
31
|
-
onExpandedChange?: (expanded: Set<Id>) => void;
|
|
32
|
-
expandOnlyOne?: boolean;
|
|
33
|
-
defaultHiddenColumns?: Set<Id>;
|
|
34
|
-
hiddenColumns?: Set<Id>;
|
|
35
|
-
onHiddenColumnsChange?: (hiddenColumns: Set<Id>) => void;
|
|
36
|
-
defaultWidth?: string;
|
|
37
|
-
fullWidth?: boolean | 'left' | 'right';
|
|
38
|
-
stickyHeader?: boolean;
|
|
39
|
-
virtual?: boolean | {
|
|
40
|
-
rowHeight?: number;
|
|
41
|
-
initalRowHeight?: number;
|
|
42
|
-
throttleScroll?: number;
|
|
43
|
-
overscan?: number;
|
|
44
|
-
overscanBottom?: number;
|
|
45
|
-
overscanTop?: number;
|
|
46
|
-
};
|
|
47
|
-
text?: {
|
|
48
|
-
deselectAll?: ReactNode;
|
|
49
|
-
exportTitle?: ReactNode;
|
|
50
|
-
exportCopy?: ReactNode;
|
|
51
|
-
exportDownload?: ReactNode;
|
|
52
|
-
};
|
|
53
|
-
classes?: {
|
|
54
|
-
table?: string;
|
|
55
|
-
headerCell?: string;
|
|
56
|
-
cell?: string | ((item: T, index: number) => string | undefined);
|
|
57
|
-
evenCell?: string;
|
|
58
|
-
oddCell?: string;
|
|
59
|
-
};
|
|
60
|
-
wrapCell?: (cell: ReactNode, item: T) => ReactNode;
|
|
61
|
-
debug?: (...output: any) => void;
|
|
62
|
-
enableSelection?: boolean;
|
|
63
|
-
enableColumnSelection?: boolean;
|
|
64
|
-
enableExport?: boolean | {
|
|
65
|
-
copy?: boolean | CsvExportOptions;
|
|
66
|
-
download?: boolean | CsvExportOptions;
|
|
67
|
-
};
|
|
68
|
-
storeState?: {
|
|
69
|
-
storage: TableStateStorage;
|
|
70
|
-
id?: string;
|
|
71
|
-
include?: {
|
|
72
|
-
sort?: boolean;
|
|
73
|
-
selection?: boolean;
|
|
74
|
-
expanded?: boolean;
|
|
75
|
-
hiddenColumns?: boolean;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
export declare type InternalTableProps<T> = Omit<TableProps<T>, 'id' | 'parentId' | 'columns' | 'enableSelection' | 'enableColumnSelection' | 'enableExport'> & {
|
|
80
|
-
id: (item: T) => Id;
|
|
81
|
-
parentId?: (item: T) => Id | undefined;
|
|
82
|
-
columns: InternalColumn<T, unknown>[];
|
|
83
|
-
enableSelection: boolean;
|
|
84
|
-
enableColumnSelection: boolean;
|
|
85
|
-
enableExport: {
|
|
86
|
-
copy?: CsvExportOptions;
|
|
87
|
-
download?: CsvExportOptions;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
export declare type TableItem<T = unknown> = T & {
|
|
91
|
-
id: Id;
|
|
92
|
-
parentId?: Id;
|
|
93
|
-
children: TableItem<T>[];
|
|
94
|
-
};
|
|
95
|
-
export declare type Column<T, V> = {
|
|
96
|
-
id?: string;
|
|
97
|
-
header?: ReactNode;
|
|
98
|
-
value: (item: T) => V;
|
|
99
|
-
renderCell?: (value: V, item: T) => ReactNode;
|
|
100
|
-
exportCell?: (value: V, item: T) => string | number;
|
|
101
|
-
sortBy?: ((value: V, item: T) => unknown) | ((value: V) => unknown)[];
|
|
102
|
-
filterComponent?: ReactNode;
|
|
103
|
-
defaultFilter?: Filter<V>;
|
|
104
|
-
filter?: Filter<V>;
|
|
105
|
-
onFilterChange?: (filter?: Filter<T>) => void;
|
|
106
|
-
cannotHide?: boolean;
|
|
107
|
-
width?: string;
|
|
108
|
-
justifyContent?: CSSProperties['justifyContent'];
|
|
109
|
-
classes?: {
|
|
110
|
-
headerCell?: string;
|
|
111
|
-
cell?: string | ((item: T, index: number) => string | undefined);
|
|
112
|
-
evenCell?: string;
|
|
113
|
-
oddCell?: string;
|
|
114
|
-
};
|
|
115
|
-
/** If the column definition changes, supply parameters that it depends on. If not set, the column will not update */
|
|
116
|
-
dependencies?: any[];
|
|
117
|
-
};
|
|
118
|
-
export declare type InternalColumn<T, V> = Required<Omit<Column<T, V>, 'id'> & {
|
|
119
|
-
id: Id;
|
|
120
|
-
}, 'header' | 'stringValue' | 'sortBy' | 'renderValue' | 'renderCell' | 'exportCell'>;
|
|
121
|
-
declare type Required<T, S> = T & {
|
|
122
|
-
[P in keyof T as P extends S ? P : never]-?: T[P];
|
|
123
|
-
};
|
|
124
|
-
export declare type Rows<T, V> = [{
|
|
125
|
-
value: V;
|
|
126
|
-
item: T;
|
|
127
|
-
}, ...{
|
|
128
|
-
value: V;
|
|
129
|
-
item: T;
|
|
130
|
-
}[]];
|
|
131
|
-
export declare type InternalTableState<T> = {
|
|
132
|
-
props: InternalTableProps<T>;
|
|
133
|
-
sort: Sort[];
|
|
134
|
-
selection: Set<Id>;
|
|
135
|
-
expanded: Set<Id>;
|
|
136
|
-
rowHeights: Map<Id, number>;
|
|
137
|
-
filters: Map<Id, Filter<unknown> | undefined>;
|
|
138
|
-
hiddenColumns: Set<Id>;
|
|
139
|
-
activeColumns: InternalColumn<T, unknown>[];
|
|
140
|
-
items: TableItem<T>[];
|
|
141
|
-
itemsById: Map<Id, TableItem<T>>;
|
|
142
|
-
activeItems: TableItem<T>[];
|
|
143
|
-
activeItemsById: Map<Id, TableItem<T>>;
|
|
144
|
-
lastSelectedId?: Id;
|
|
145
|
-
};
|
|
146
|
-
export {};
|
package/dist/cjs/types.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { useColumnContext, useTableContext } from '..';
|
|
4
|
-
import { c } from '../misc/helpers';
|
|
5
|
-
import { calcClassName } from './row';
|
|
6
|
-
import { useCommonClasses } from './useCommonClasses';
|
|
7
|
-
export const Cell = memo(function Cell({ itemId, rowIndex }) {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
const commonClasses = useCommonClasses();
|
|
10
|
-
const state = useTableContext();
|
|
11
|
-
const columnId = useColumnContext();
|
|
12
|
-
const column = state.useState((state) => state.activeColumns.find((column) => column.id === columnId), [columnId]);
|
|
13
|
-
const item = state.useState((state) => state.activeItemsById.get(itemId), [itemId]);
|
|
14
|
-
const classes = state.useState('props.classes');
|
|
15
|
-
let wrapCell = state.useState('props.wrapCell');
|
|
16
|
-
if (!column || !item)
|
|
17
|
-
return null;
|
|
18
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render cell', itemId, columnId);
|
|
19
|
-
const className = c(calcClassName(classes, item, rowIndex), calcClassName(column === null || column === void 0 ? void 0 : column.classes, item, rowIndex));
|
|
20
|
-
const content = column.renderCell(column.value(item), item);
|
|
21
|
-
if (!wrapCell && typeof content === 'string') {
|
|
22
|
-
wrapCell = (content) => (_jsx("div", Object.assign({ className: c(commonClasses.cell, className) }, { children: _jsx("span", Object.assign({ className: c(commonClasses.text) }, { children: content }), void 0) }), void 0));
|
|
23
|
-
}
|
|
24
|
-
else if (!wrapCell) {
|
|
25
|
-
wrapCell = (content) => _jsx("div", Object.assign({ className: c(commonClasses.cell, className) }, { children: content }), void 0);
|
|
26
|
-
}
|
|
27
|
-
return _jsx(_Fragment, { children: wrapCell(content, item) }, void 0);
|
|
28
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Checkbox, FormControlLabel, IconButton, makeStyles, Popover } from '@material-ui/core';
|
|
3
|
-
import { Settings } from '@material-ui/icons';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { useTableContext } from '../table';
|
|
6
|
-
const useClasses = makeStyles((theme) => ({
|
|
7
|
-
list: {
|
|
8
|
-
padding: theme.spacing(2),
|
|
9
|
-
display: 'grid',
|
|
10
|
-
},
|
|
11
|
-
}));
|
|
12
|
-
export function ColumnSelection() {
|
|
13
|
-
const classes = useClasses();
|
|
14
|
-
const [anchor, setAnchor] = useState(null);
|
|
15
|
-
const state = useTableContext();
|
|
16
|
-
const columns = state.useState('props.columns');
|
|
17
|
-
const hiddenColumns = state.useState('hiddenColumns');
|
|
18
|
-
const toggle = (column) => {
|
|
19
|
-
const { props: { hiddenColumns: controlledHiddenColumns, onHiddenColumnsChange }, } = state.getState();
|
|
20
|
-
const newValue = new Set(hiddenColumns);
|
|
21
|
-
if (hiddenColumns.has(column.id))
|
|
22
|
-
newValue.delete(column.id);
|
|
23
|
-
else
|
|
24
|
-
newValue.add(column.id);
|
|
25
|
-
if (!controlledHiddenColumns) {
|
|
26
|
-
state.update((state) => {
|
|
27
|
-
state.hiddenColumns = newValue;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
onHiddenColumnsChange === null || onHiddenColumnsChange === void 0 ? void 0 : onHiddenColumnsChange(newValue);
|
|
31
|
-
};
|
|
32
|
-
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ color: "inherit", size: "small", onClick: (e) => setAnchor(e.currentTarget) }, { children: _jsx(Settings, {}, void 0) }), void 0), _jsx(Popover, Object.assign({ open: !!anchor, onClose: () => setAnchor(null), anchorEl: anchor, anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'left' } }, { children: _jsx("div", Object.assign({ className: classes.list }, { children: columns.map((column) => (_jsx(FormControlLabel, { control: _jsx(Checkbox, { checked: !hiddenColumns.has(column.id), onChange: () => toggle(column), disabled: column.cannotHide }, void 0), label: column.header }, column.id))) }), void 0) }), void 0)] }, void 0));
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { Filter } from './filterComponent';
|
|
3
|
-
export declare class DefaultFilter<T, O> implements Filter<T> {
|
|
4
|
-
readonly values: Set<O>;
|
|
5
|
-
readonly filter: (item: T) => boolean;
|
|
6
|
-
constructor(values: Set<O>, filter: (item: T) => boolean);
|
|
7
|
-
}
|
|
8
|
-
declare type UnwrapArray<O> = O extends Array<infer S> ? S : O;
|
|
9
|
-
export declare function DefaultFilterComponent<V>(props: {
|
|
10
|
-
options?: UnwrapArray<V>[];
|
|
11
|
-
compare?: (a: UnwrapArray<V>, b: UnwrapArray<V>) => boolean;
|
|
12
|
-
stringValue?: (value: UnwrapArray<V>) => string;
|
|
13
|
-
render?: (value: UnwrapArray<V>) => ReactNode;
|
|
14
|
-
}): JSX.Element;
|
|
15
|
-
export declare function DefaultFilterComponent<T, V, O>(props: {
|
|
16
|
-
filterBy?: (value: V, item: T) => O | O[];
|
|
17
|
-
options?: O[];
|
|
18
|
-
compare?: (a: O, b: O) => boolean;
|
|
19
|
-
stringValue?: (value: O) => string;
|
|
20
|
-
render?: (value: O) => ReactNode;
|
|
21
|
-
}): JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, Checkbox, FormControlLabel, IconButton, makeStyles, TextField } from '@material-ui/core';
|
|
3
|
-
import { Clear, Search } from '@material-ui/icons';
|
|
4
|
-
import { useCallback, useState } from 'react';
|
|
5
|
-
import { asString, defaultEquals, flatMap, orderBy, uniq } from '../misc/helpers';
|
|
6
|
-
import { useColumnContext, useTableContext } from '../table';
|
|
7
|
-
export class DefaultFilter {
|
|
8
|
-
constructor(values, filter) {
|
|
9
|
-
this.values = values;
|
|
10
|
-
this.filter = filter;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const useClasses = makeStyles((theme) => ({
|
|
14
|
-
view: {
|
|
15
|
-
padding: theme.spacing(2),
|
|
16
|
-
display: 'grid',
|
|
17
|
-
'& > :first-child': {
|
|
18
|
-
marginBottom: theme.spacing(2),
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
22
|
-
export function DefaultFilterComponent({ filterBy: _filterBy, options: _options, compare = defaultEquals, stringValue = asString, render = stringValue, }) {
|
|
23
|
-
var _a;
|
|
24
|
-
const classes = useClasses();
|
|
25
|
-
const state = useTableContext();
|
|
26
|
-
const columnId = useColumnContext();
|
|
27
|
-
const filterBy = useCallback((value, item) => {
|
|
28
|
-
const values = _filterBy ? _filterBy(value, item) : value;
|
|
29
|
-
return values instanceof Array ? values : [values];
|
|
30
|
-
}, [_filterBy]);
|
|
31
|
-
const { text, options, filter } = state.useState((state) => {
|
|
32
|
-
const column = state.activeColumns.find((column) => column.id === columnId);
|
|
33
|
-
const _filter = state.filters.get(columnId);
|
|
34
|
-
const filter = _filter instanceof DefaultFilter ? _filter : undefined;
|
|
35
|
-
let options = _options !== null && _options !== void 0 ? _options : orderBy(uniq(flatMap(state.items, (item) => (column ? filterBy(column.value(item), item) : []))));
|
|
36
|
-
if (filter)
|
|
37
|
-
options = options.concat([...filter.values].filter((value) => !options.includes(value)));
|
|
38
|
-
return { text: state.props.text, options, filter };
|
|
39
|
-
}, [_options, columnId, filterBy]);
|
|
40
|
-
const [input, setInput] = useState('');
|
|
41
|
-
const filtered = options.filter((option) => !input || stringValue(option).toLowerCase().includes(input.toLowerCase()));
|
|
42
|
-
function toggle(value) {
|
|
43
|
-
var _a;
|
|
44
|
-
const column = state.getState().activeColumns.find((column) => column.id === columnId);
|
|
45
|
-
if (!column)
|
|
46
|
-
return;
|
|
47
|
-
const newValues = new Set(filter === null || filter === void 0 ? void 0 : filter.values);
|
|
48
|
-
if (newValues === null || newValues === void 0 ? void 0 : newValues.has(value))
|
|
49
|
-
newValues.delete(value);
|
|
50
|
-
else
|
|
51
|
-
newValues === null || newValues === void 0 ? void 0 : newValues.add(value);
|
|
52
|
-
const newFilter = newValues.size === 0
|
|
53
|
-
? undefined
|
|
54
|
-
: new DefaultFilter(newValues, (item) => {
|
|
55
|
-
const itemValues = filterBy(column.value(item), item);
|
|
56
|
-
return [...newValues].some((value) => itemValues.some((itemValue) => compare(value, itemValue)));
|
|
57
|
-
});
|
|
58
|
-
if (!column.filter) {
|
|
59
|
-
state.update((state) => {
|
|
60
|
-
if (newFilter)
|
|
61
|
-
state.filters.set(column.id, newFilter);
|
|
62
|
-
else
|
|
63
|
-
state.filters.delete(column.id);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
(_a = column.onFilterChange) === null || _a === void 0 ? void 0 : _a.call(column, newFilter);
|
|
67
|
-
}
|
|
68
|
-
function deselectAll() {
|
|
69
|
-
var _a;
|
|
70
|
-
const column = state.getState().activeColumns.find((column) => column.id === columnId);
|
|
71
|
-
if (!column)
|
|
72
|
-
return;
|
|
73
|
-
if (!column.filter) {
|
|
74
|
-
state.update((state) => {
|
|
75
|
-
state.filters.delete(column.id);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
(_a = column.onFilterChange) === null || _a === void 0 ? void 0 : _a.call(column);
|
|
79
|
-
}
|
|
80
|
-
return (_jsxs("div", Object.assign({ className: classes.view }, { children: [_jsx(TextField, { value: input, onChange: (e) => setInput(e.target.value), InputProps: {
|
|
81
|
-
endAdornment: input ? (_jsx(IconButton, Object.assign({ onClick: () => setInput('') }, { children: _jsx(Clear, {}, void 0) }), void 0)) : (_jsx(Search, {}, void 0)),
|
|
82
|
-
} }, void 0), _jsx(Button, Object.assign({ variant: "outlined", onClick: deselectAll, disabled: !filter }, { children: (_a = text === null || text === void 0 ? void 0 : text.deselectAll) !== null && _a !== void 0 ? _a : 'Deselect all' }), void 0), filtered.map((value, index) => {
|
|
83
|
-
var _a;
|
|
84
|
-
return (_jsx(FormControlLabel, { control: _jsx(Checkbox, { checked: (_a = filter === null || filter === void 0 ? void 0 : filter.values.has(value)) !== null && _a !== void 0 ? _a : false, onChange: () => toggle(value) }, void 0), label: render(value) }, index));
|
|
85
|
-
})] }), void 0));
|
|
86
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { IconButton } from '@material-ui/core';
|
|
3
|
-
import { ChevronRight } from '@material-ui/icons';
|
|
4
|
-
import { getAncestors } from '../misc/helpers';
|
|
5
|
-
import { useTableContext } from '../table';
|
|
6
|
-
export function ExpandComponent({ itemId }) {
|
|
7
|
-
const state = useTableContext();
|
|
8
|
-
const isExpanded = state.useState((state) => state.expanded.has(itemId), [itemId]);
|
|
9
|
-
function toggle() {
|
|
10
|
-
const { props: { expanded: controlledExpanded, expandOnlyOne, onExpandedChange }, expanded, activeItemsById, } = state.getState();
|
|
11
|
-
const newExpanded = new Set(expanded);
|
|
12
|
-
if (expandOnlyOne)
|
|
13
|
-
newExpanded.clear();
|
|
14
|
-
if (isExpanded)
|
|
15
|
-
newExpanded.delete(itemId);
|
|
16
|
-
else {
|
|
17
|
-
newExpanded.add(itemId);
|
|
18
|
-
const item = activeItemsById.get(itemId);
|
|
19
|
-
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
20
|
-
newExpanded.add(ancestor);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
onExpandedChange === null || onExpandedChange === void 0 ? void 0 : onExpandedChange(newExpanded);
|
|
24
|
-
if (!controlledExpanded) {
|
|
25
|
-
state.update((state) => {
|
|
26
|
-
state.expanded = newExpanded;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return (_jsx(IconButton, Object.assign({ size: "small", onClick: toggle }, { children: _jsx(ChevronRight, { style: {
|
|
31
|
-
transition: 'all 500ms',
|
|
32
|
-
transform: isExpanded ? 'rotate3d(0, 0, 1, 90deg)' : 'none',
|
|
33
|
-
} }, void 0) }), void 0));
|
|
34
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Button, IconButton, makeStyles, Popover, Typography } from '@material-ui/core';
|
|
3
|
-
import { AssignmentReturn, CloudDownload } from '@material-ui/icons';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { csvExport } from '../misc/csvExport';
|
|
6
|
-
import { useTableContext } from '../table';
|
|
7
|
-
const useClasses = makeStyles((theme) => ({
|
|
8
|
-
dialog: {
|
|
9
|
-
padding: theme.spacing(2),
|
|
10
|
-
display: 'grid',
|
|
11
|
-
justifyItems: 'stretch',
|
|
12
|
-
'& > *': {
|
|
13
|
-
justifyContent: 'start',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
export function Export() {
|
|
18
|
-
const classes = useClasses();
|
|
19
|
-
const [anchor, setAnchor] = useState(null);
|
|
20
|
-
const state = useTableContext();
|
|
21
|
-
const textTitle = state.useState('props.text.exportTitle');
|
|
22
|
-
const textCopy = state.useState('props.text.exportCopy');
|
|
23
|
-
const textDownload = state.useState('props.text.exportDownload');
|
|
24
|
-
const generate = (options) => {
|
|
25
|
-
const { activeColumns, activeItems } = state.getState();
|
|
26
|
-
const data = [
|
|
27
|
-
activeColumns.map((column) => String(column.id)),
|
|
28
|
-
...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item), item))),
|
|
29
|
-
];
|
|
30
|
-
return csvExport(data, options);
|
|
31
|
-
};
|
|
32
|
-
const copy = () => {
|
|
33
|
-
navigator.clipboard.writeText(generate(state.getState().props.enableExport.copy));
|
|
34
|
-
};
|
|
35
|
-
const download = () => {
|
|
36
|
-
const a = document.createElement('a');
|
|
37
|
-
a.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(generate(state.getState().props.enableExport.download));
|
|
38
|
-
a.download = 'export.csv';
|
|
39
|
-
document.body.appendChild(a);
|
|
40
|
-
a.click();
|
|
41
|
-
document.body.removeChild(a);
|
|
42
|
-
};
|
|
43
|
-
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ color: "inherit", size: "small", onClick: (e) => setAnchor(e.currentTarget) }, { children: _jsx(CloudDownload, {}, void 0) }), void 0), _jsx(Popover, Object.assign({ open: !!anchor, onClose: () => setAnchor(null), anchorEl: anchor, anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'left' } }, { children: _jsxs("div", Object.assign({ className: classes.dialog }, { children: [_jsx(Typography, Object.assign({ variant: "caption" }, { children: textTitle !== null && textTitle !== void 0 ? textTitle : 'Export' }), void 0), _jsx(Button, Object.assign({ startIcon: _jsx(AssignmentReturn, {}, void 0), fullWidth: true, onClick: copy }, { children: textCopy !== null && textCopy !== void 0 ? textCopy : 'In die Zwischenablage' }), void 0), _jsx(Button, Object.assign({ startIcon: _jsx(CloudDownload, {}, void 0), fullWidth: true, onClick: download }, { children: textDownload !== null && textDownload !== void 0 ? textDownload : 'Herunterladen' }), void 0)] }), void 0) }), void 0)] }, void 0));
|
|
44
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { IconButton, makeStyles, Popover } from '@material-ui/core';
|
|
3
|
-
import { ArrowDropDown, FilterList } from '@material-ui/icons';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { useColumnContext, useTableContext } from '../table';
|
|
6
|
-
const useClasses = makeStyles((theme) => ({
|
|
7
|
-
active: {
|
|
8
|
-
background: theme.palette.primary.main,
|
|
9
|
-
},
|
|
10
|
-
}));
|
|
11
|
-
export function FilterComponent() {
|
|
12
|
-
const state = useTableContext();
|
|
13
|
-
const columnId = useColumnContext();
|
|
14
|
-
const classes = useClasses();
|
|
15
|
-
const isActive = state.useState((state) => !!state.filters.get(columnId), [columnId]);
|
|
16
|
-
const filterComponent = state.useState((state) => { var _a; return (_a = state.activeColumns.find((column) => column.id === columnId)) === null || _a === void 0 ? void 0 : _a.filterComponent; });
|
|
17
|
-
const [anchor, setAnchor] = useState(null);
|
|
18
|
-
if (!filterComponent)
|
|
19
|
-
return null;
|
|
20
|
-
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ size: "small", color: "inherit", onClick: (e) => setAnchor(e.currentTarget), className: isActive ? classes.active : undefined }, { children: isActive ? _jsx(FilterList, {}, void 0) : _jsx(ArrowDropDown, {}, void 0) }), void 0), _jsx(Popover, Object.assign({ open: !!anchor, onClose: () => setAnchor(null), anchorEl: anchor, anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'center' } }, { children: filterComponent }), void 0)] }, void 0));
|
|
21
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Id, InternalColumn } from '../types';
|
|
3
|
-
export declare function calcClassName<T>(classes: InternalColumn<any, any>['classes'] | undefined, item: T, index: number): string;
|
|
4
|
-
export declare const Row: React.MemoExoticComponent<(<T>({ itemId, rowIndex }: {
|
|
5
|
-
itemId: Id;
|
|
6
|
-
rowIndex: number;
|
|
7
|
-
}) => JSX.Element | null)>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useEffect, useRef } from 'react';
|
|
3
|
-
import { c, getAncestors } from '../misc/helpers';
|
|
4
|
-
import { ColumnContext, useTableContext } from '../table';
|
|
5
|
-
import { Cell } from './cell';
|
|
6
|
-
import { ExpandComponent } from './expandComponent';
|
|
7
|
-
import { SelectComponent } from './selectComponent';
|
|
8
|
-
import { useCommonClasses } from './useCommonClasses';
|
|
9
|
-
export function calcClassName(classes, item, index) {
|
|
10
|
-
return c((classes === null || classes === void 0 ? void 0 : classes.cell) instanceof Function ? classes.cell(item, index) : classes === null || classes === void 0 ? void 0 : classes.cell, (classes === null || classes === void 0 ? void 0 : classes.evenCell) === undefined ? undefined : { [classes.evenCell]: index % 2 === 0 }, (classes === null || classes === void 0 ? void 0 : classes.oddCell) === undefined ? undefined : { [classes.oddCell]: index % 2 === 1 });
|
|
11
|
-
}
|
|
12
|
-
export const Row = memo(function Row({ itemId, rowIndex }) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const commonClasses = useCommonClasses();
|
|
15
|
-
const state = useTableContext();
|
|
16
|
-
const divRef = useRef(null);
|
|
17
|
-
const { className, indent, hasChildren, hasDeferredChildren, columnIds, enableSelection, rowAction } = state.useState((state) => {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
const item = state.activeItemsById.get(itemId);
|
|
20
|
-
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
21
|
-
return {
|
|
22
|
-
className: calcClassName(state.props.classes, item, index),
|
|
23
|
-
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
24
|
-
hasChildren: !!(item === null || item === void 0 ? void 0 : item.children.length),
|
|
25
|
-
hasDeferredChildren: item && ((_b = (_a = state.props).hasDeferredChildren) === null || _b === void 0 ? void 0 : _b.call(_a, item)),
|
|
26
|
-
columnIds: state.activeColumns.map((column) => column.id),
|
|
27
|
-
enableSelection: state.props.enableSelection,
|
|
28
|
-
rowAction: state.props.rowAction instanceof Function ? (item ? state.props.rowAction(item, index) : null) : state.props.rowAction,
|
|
29
|
-
};
|
|
30
|
-
}, [itemId]);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
const div = divRef.current;
|
|
33
|
-
if (!div)
|
|
34
|
-
return;
|
|
35
|
-
const o = new ResizeObserver(() => {
|
|
36
|
-
if (!document.contains(div))
|
|
37
|
-
return;
|
|
38
|
-
state.update((state) => {
|
|
39
|
-
state.rowHeights.set(itemId, div.offsetHeight);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
o.observe(div);
|
|
43
|
-
return () => o.disconnect();
|
|
44
|
-
}, [divRef.current]);
|
|
45
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render row', itemId);
|
|
46
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: c(commonClasses.cellFill, className), ref: divRef }, void 0), _jsxs("div", Object.assign({ className: c(commonClasses.cell, commonClasses.firstCell, className) }, { children: [_jsx("div", { style: { width: indent * 20 } }, void 0), enableSelection && _jsx(SelectComponent, { itemId: itemId }, void 0), (hasChildren || hasDeferredChildren) && _jsx(ExpandComponent, { itemId: itemId }, void 0), rowAction] }), void 0), columnIds.map((columnId) => (_jsx(ColumnContext.Provider, Object.assign({ value: columnId }, { children: _jsx(Cell, { itemId: itemId, rowIndex: rowIndex }, void 0) }), columnId))), _jsx("div", { className: c(commonClasses.cellFill, className) }, void 0)] }, void 0));
|
|
47
|
-
});
|