schummar-table 0.3.2 → 0.5.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/assets/tableTheme.0eb513b0.js +215 -0
- package/dist/assets/tableTheme.0eb513b0.js.map +1 -0
- package/dist/assets/tableTheme.65fea986.js +214 -0
- package/dist/assets/tableTheme.65fea986.js.map +1 -0
- package/dist/assets/vendor.a5ec605d.js +2475 -0
- package/dist/assets/vendor.a5ec605d.js.map +1 -0
- package/dist/assets/vendor.c9c3328b.js +2464 -0
- package/dist/assets/vendor.c9c3328b.js.map +1 -0
- package/dist/cjs/mui4Theme.js +7 -0
- package/dist/cjs/mui4Theme.js.map +1 -0
- package/dist/cjs/mui5Theme.js +7 -0
- package/dist/cjs/mui5Theme.js.map +1 -0
- package/dist/cjs/schummar-table.js +1042 -0
- package/dist/cjs/schummar-table.js.map +1 -0
- package/dist/esm/mui4Theme.js +6 -0
- package/dist/esm/mui4Theme.js.map +1 -0
- package/dist/esm/mui5Theme.js +6 -0
- package/dist/esm/mui5Theme.js.map +1 -0
- package/dist/esm/schummar-table.js +1041 -0
- package/dist/esm/schummar-table.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 -1
- 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/types/internalState/tableStateStorage.d.ts +11 -0
- 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/types/misc/queue.d.ts +6 -0
- 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 +78 -38
- 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 -48
- 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/index.js +0 -18
- 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/useTableState.js +0 -62
- package/dist/cjs/misc/csvExport.js +0 -15
- package/dist/cjs/misc/helpers.js +0 -91
- 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 -69
- package/dist/cjs/types.d.ts +0 -134
- 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 -44
- 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/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/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 -8
- package/dist/esm/table.js +0 -63
- package/dist/esm/types.d.ts +0 -134
- package/dist/esm/types.js +0 -1
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
14
|
-
import { throttle } from '../misc/throttle';
|
|
15
|
-
import { useTableContext } from '../table';
|
|
16
|
-
const onAncestorScroll = (x, onScroll) => {
|
|
17
|
-
const find = (x) => (x.parentElement ? [x.parentElement, ...find(x.parentElement)] : [document]);
|
|
18
|
-
const ancestors = find(x);
|
|
19
|
-
for (const ancestor of ancestors) {
|
|
20
|
-
ancestor.addEventListener('scroll', onScroll);
|
|
21
|
-
}
|
|
22
|
-
return () => {
|
|
23
|
-
for (const ancestor of ancestors) {
|
|
24
|
-
ancestor.removeEventListener('scroll', onScroll);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const findScrollRoot = (x) => {
|
|
29
|
-
const parent = x.parentElement;
|
|
30
|
-
if (!parent)
|
|
31
|
-
return document.documentElement;
|
|
32
|
-
if (parent.scrollHeight > parent.clientHeight)
|
|
33
|
-
return parent;
|
|
34
|
-
return findScrollRoot(parent);
|
|
35
|
-
};
|
|
36
|
-
const relativeOffset = (x, y) => {
|
|
37
|
-
if (x.offsetParent === y.offsetParent || !x.offsetParent)
|
|
38
|
-
return x.offsetTop - y.offsetTop;
|
|
39
|
-
if (x.offsetParent instanceof HTMLElement)
|
|
40
|
-
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
41
|
-
return 0;
|
|
42
|
-
};
|
|
43
|
-
export function Virtualized(_a) {
|
|
44
|
-
var _b, _c, _d, _e;
|
|
45
|
-
var { header, children } = _a, props = __rest(_a, ["header", "children"]);
|
|
46
|
-
const state = useTableContext();
|
|
47
|
-
const virtual = state.useState('props.virtual');
|
|
48
|
-
const probeRef = useRef(null);
|
|
49
|
-
const [counter, setCounter] = useState(0);
|
|
50
|
-
const { itemIds = [], from = 0, to, before = 0, after = 0, } = state.useState((state) => {
|
|
51
|
-
var _a;
|
|
52
|
-
const itemIds = state.activeItems.map((item) => item.id);
|
|
53
|
-
const root = probeRef.current && findScrollRoot(probeRef.current);
|
|
54
|
-
if (!state.props.virtual)
|
|
55
|
-
return { itemIds };
|
|
56
|
-
if (!probeRef.current || !root || !document.contains(root))
|
|
57
|
-
return {};
|
|
58
|
-
const { rowHeight, initalRowHeight, overscan = 200, overscanTop, overscanBottom, } = (_a = (state.props.virtual instanceof Object ? state.props.virtual : undefined)) !== null && _a !== void 0 ? _a : {};
|
|
59
|
-
let totalHeight = 0;
|
|
60
|
-
const rowHeights = itemIds.map((itemId, index) => {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
const h = (_b = (_a = rowHeight !== null && rowHeight !== void 0 ? rowHeight : state.rowHeights.get(itemId)) !== null && _a !== void 0 ? _a : initalRowHeight) !== null && _b !== void 0 ? _b : (index === 0 ? 100 : totalHeight / index);
|
|
63
|
-
totalHeight += h;
|
|
64
|
-
return h;
|
|
65
|
-
});
|
|
66
|
-
const probeOffset = relativeOffset(probeRef.current, root);
|
|
67
|
-
const headerHeight = probeRef.current.offsetTop;
|
|
68
|
-
const topOfTable = root.scrollTop - probeOffset + headerHeight;
|
|
69
|
-
const bottomOfTable = topOfTable + root.clientHeight - headerHeight;
|
|
70
|
-
let from = 0, to = itemIds.length, before = 0, after = 0;
|
|
71
|
-
for (const h of rowHeights) {
|
|
72
|
-
if (before + h > topOfTable - (overscanTop !== null && overscanTop !== void 0 ? overscanTop : overscan))
|
|
73
|
-
break;
|
|
74
|
-
from++;
|
|
75
|
-
before += h;
|
|
76
|
-
}
|
|
77
|
-
for (const h of rowHeights.reverse()) {
|
|
78
|
-
if (after + h > totalHeight - bottomOfTable - (overscanBottom !== null && overscanBottom !== void 0 ? overscanBottom : overscan))
|
|
79
|
-
break;
|
|
80
|
-
to--;
|
|
81
|
-
after += h;
|
|
82
|
-
}
|
|
83
|
-
return { itemIds: itemIds.slice(from, to), from, to, before, after };
|
|
84
|
-
}, [probeRef.current, counter]);
|
|
85
|
-
const throttleScroll = (_c = (_b = (typeof virtual === 'boolean' ? undefined : virtual)) === null || _b === void 0 ? void 0 : _b.throttleScroll) !== null && _c !== void 0 ? _c : 500;
|
|
86
|
-
const incCounter = useMemo(() => throttle(() => setCounter((c) => c + 1), throttleScroll), [throttleScroll]);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (!virtual || !probeRef.current)
|
|
89
|
-
return;
|
|
90
|
-
return onAncestorScroll(probeRef.current, incCounter);
|
|
91
|
-
}, [probeRef.current, incCounter]);
|
|
92
|
-
(_e = (_d = state.getState().props).debug) === null || _e === void 0 ? void 0 : _e.call(_d, `Virtualalized render ${from} to ${to}`);
|
|
93
|
-
return (_jsxs("div", Object.assign({}, props, { children: [header, virtual && _jsx("div", { style: { gridColumn: '1 / -1', height: before }, ref: probeRef }, void 0), children(itemIds, from), virtual && _jsx("div", { style: { gridColumn: '1 / -1', height: after } }, void 0)] }), void 0));
|
|
94
|
-
}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { DefaultFilter, DefaultFilterComponent } from './components/defaultFilterComponent';
|
|
2
|
-
export { Filter } from './components/filterComponent';
|
|
3
|
-
export { TextFilter, TextFilterComponent } from './components/textFilterComponent';
|
|
4
|
-
export { termMatch, textMatch } from './misc/textMatch';
|
|
5
|
-
export { ColumnContext, Table, TableContext, useColumnContext, useTableContext } from './table';
|
|
6
|
-
export type { Column, Id, InternalColumn, Rows, Sort, SortDirection, TableProps } from './types';
|
package/dist/esm/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { DefaultFilter, DefaultFilterComponent } from './components/defaultFilterComponent';
|
|
2
|
-
export { TextFilter, TextFilterComponent } from './components/textFilterComponent';
|
|
3
|
-
export { termMatch, textMatch } from './misc/textMatch';
|
|
4
|
-
export { ColumnContext, Table, TableContext, useColumnContext, useTableContext } from './table';
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { castDraft } from 'immer';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import { flatMap, orderBy } from '../misc/helpers';
|
|
4
|
-
export function calcItems(state) {
|
|
5
|
-
useEffect(() => state.addReaction((state) => [
|
|
6
|
-
state.props.items,
|
|
7
|
-
state.props.id,
|
|
8
|
-
state.props.parentId,
|
|
9
|
-
state.props.revealFiltered,
|
|
10
|
-
state.sort,
|
|
11
|
-
state.filters,
|
|
12
|
-
state.activeColumns,
|
|
13
|
-
state.expanded,
|
|
14
|
-
], ([items = [], id, parentId, revealFiltered, sort, filters, activeColumns], draft) => {
|
|
15
|
-
const tableItems = items.map((item) => (Object.assign(Object.assign({}, item), { id: id(item), parentId: parentId === null || parentId === void 0 ? void 0 : parentId(item), children: [] })));
|
|
16
|
-
let sorted;
|
|
17
|
-
if (sort.length === 0) {
|
|
18
|
-
sorted = tableItems;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const selectors = flatMap(sort, (sort) => {
|
|
22
|
-
const column = activeColumns.find((column) => column.id === sort.columnId);
|
|
23
|
-
if (!column)
|
|
24
|
-
return [];
|
|
25
|
-
const sortBy = column.sortBy instanceof Array ? column.sortBy : [column.sortBy];
|
|
26
|
-
return sortBy.map((sortBy) => ({ selector: (item) => sortBy(column.value(item), item), direction: sort.direction }));
|
|
27
|
-
}).filter(Boolean);
|
|
28
|
-
sorted = orderBy(tableItems, selectors.map((x) => x.selector), selectors.map((x) => x.direction));
|
|
29
|
-
}
|
|
30
|
-
const lookup = new Map();
|
|
31
|
-
for (const item of sorted) {
|
|
32
|
-
lookup.set(item.id, item);
|
|
33
|
-
}
|
|
34
|
-
for (const item of sorted) {
|
|
35
|
-
const parent = item.parentId !== undefined ? lookup.get(item.parentId) : undefined;
|
|
36
|
-
parent === null || parent === void 0 ? void 0 : parent.children.push(item);
|
|
37
|
-
}
|
|
38
|
-
const allItems = new Array();
|
|
39
|
-
const allItemsById = new Map();
|
|
40
|
-
const traverse = (items) => {
|
|
41
|
-
for (const item of items) {
|
|
42
|
-
allItems.push(item);
|
|
43
|
-
allItemsById.set(item.id, item);
|
|
44
|
-
traverse(item.children);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
traverse(sorted.filter((item) => item.parentId === undefined));
|
|
48
|
-
const activeItemsById = new Map();
|
|
49
|
-
const activeSet = new Set();
|
|
50
|
-
const activeItems = [...allItems]
|
|
51
|
-
.reverse()
|
|
52
|
-
.filter((item) => {
|
|
53
|
-
let isActive = activeSet.has(item.id);
|
|
54
|
-
isActive || (isActive = activeColumns.every((column) => {
|
|
55
|
-
var _a;
|
|
56
|
-
const filter = filters.get(column.id);
|
|
57
|
-
return (_a = filter === null || filter === void 0 ? void 0 : filter.filter(item)) !== null && _a !== void 0 ? _a : true;
|
|
58
|
-
}));
|
|
59
|
-
if (isActive && item.parentId !== undefined) {
|
|
60
|
-
if (revealFiltered && filters.size > 0) {
|
|
61
|
-
draft.expanded.add(item.parentId);
|
|
62
|
-
}
|
|
63
|
-
else if (!draft.expanded.has(item.parentId)) {
|
|
64
|
-
isActive = false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (isActive && item.parentId !== undefined) {
|
|
68
|
-
activeSet.add(item.parentId);
|
|
69
|
-
}
|
|
70
|
-
if (isActive) {
|
|
71
|
-
activeItemsById.set(item.id, item);
|
|
72
|
-
}
|
|
73
|
-
return isActive;
|
|
74
|
-
})
|
|
75
|
-
.reverse();
|
|
76
|
-
draft.items = castDraft(allItems);
|
|
77
|
-
draft.itemsById = castDraft(allItemsById);
|
|
78
|
-
draft.activeItems = castDraft(activeItems);
|
|
79
|
-
draft.activeItemsById = castDraft(activeItemsById);
|
|
80
|
-
}, { runNow: true }), [state]);
|
|
81
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { useMemo, useRef } from 'react';
|
|
13
|
-
import { asString } from '../misc/helpers';
|
|
14
|
-
const noopParentId = () => undefined;
|
|
15
|
-
export function calcProps(props) {
|
|
16
|
-
const columnCache = useRef(new Map());
|
|
17
|
-
return useMemo(() => {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
let id;
|
|
20
|
-
if (props.id instanceof Function) {
|
|
21
|
-
id = props.id;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
id = (item) => item[props.id];
|
|
25
|
-
}
|
|
26
|
-
let parentId;
|
|
27
|
-
if (props.parentId instanceof Function) {
|
|
28
|
-
parentId = props.parentId;
|
|
29
|
-
}
|
|
30
|
-
else if (typeof props.parentId === 'string') {
|
|
31
|
-
parentId = (item) => item[props.parentId];
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
parentId = noopParentId;
|
|
35
|
-
}
|
|
36
|
-
let inputColumns;
|
|
37
|
-
if (props.columns instanceof Function) {
|
|
38
|
-
inputColumns = props.columns((value, column) => (Object.assign(Object.assign({}, column), { value })));
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
inputColumns = props.columns.map((column) => (Object.assign(Object.assign({}, column), { dependecies: undefined })));
|
|
42
|
-
}
|
|
43
|
-
const newColumnCache = new Map();
|
|
44
|
-
const columns = inputColumns.map(function (_a, index) {
|
|
45
|
-
var _b;
|
|
46
|
-
var { id, header = null, renderCell = asString, exportCell = asString, sortBy = (v) => (typeof v === 'number' || v instanceof Date ? v : String(v)), dependencies = [] } = _a, props = __rest(_a, ["id", "header", "renderCell", "exportCell", "sortBy", "dependencies"]);
|
|
47
|
-
const [depsInCache, columnInCache] = (_b = columnCache.current.get(id !== null && id !== void 0 ? id : index)) !== null && _b !== void 0 ? _b : [];
|
|
48
|
-
let column;
|
|
49
|
-
if (depsInCache &&
|
|
50
|
-
columnInCache &&
|
|
51
|
-
depsInCache.length === dependencies.length &&
|
|
52
|
-
depsInCache.every((x, i) => dependencies[i] === x)) {
|
|
53
|
-
column = columnInCache;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
column = Object.assign({ id: id !== null && id !== void 0 ? id : index, header,
|
|
57
|
-
renderCell,
|
|
58
|
-
exportCell,
|
|
59
|
-
sortBy,
|
|
60
|
-
dependencies }, props);
|
|
61
|
-
}
|
|
62
|
-
newColumnCache.set(id !== null && id !== void 0 ? id : index, [dependencies, column]);
|
|
63
|
-
return column;
|
|
64
|
-
});
|
|
65
|
-
columnCache.current = newColumnCache;
|
|
66
|
-
let copy;
|
|
67
|
-
if (props.enableExport === true || (props.enableExport instanceof Object && props.enableExport.copy === true)) {
|
|
68
|
-
copy = { separator: '\t' };
|
|
69
|
-
}
|
|
70
|
-
else if (props.enableExport && props.enableExport.copy instanceof Object) {
|
|
71
|
-
copy = props.enableExport.copy;
|
|
72
|
-
}
|
|
73
|
-
let download;
|
|
74
|
-
if (props.enableExport === true || (props.enableExport instanceof Object && props.enableExport.download === true)) {
|
|
75
|
-
download = { sepPrefix: true };
|
|
76
|
-
}
|
|
77
|
-
else if (props.enableExport && props.enableExport.download instanceof Object) {
|
|
78
|
-
download = props.enableExport.download;
|
|
79
|
-
}
|
|
80
|
-
const enableExport = { copy, download };
|
|
81
|
-
return Object.assign(Object.assign({}, props), { id,
|
|
82
|
-
parentId,
|
|
83
|
-
columns, enableSelection: (_a = props.enableSelection) !== null && _a !== void 0 ? _a : true, enableColumnSelection: (_b = props.enableColumnSelection) !== null && _b !== void 0 ? _b : true, enableExport });
|
|
84
|
-
}, [props]);
|
|
85
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { intersect } from '../misc/helpers';
|
|
3
|
-
export function cleanupState(state) {
|
|
4
|
-
useEffect(() => state.addReaction((state) => [state.props.columns, state.itemsById, state.activeItemsById, state.activeColumns], ([columns, itemsById, activeItemsById, activeColumns], draft) => {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f;
|
|
6
|
-
const columnIds = new Set(columns.map((column) => column.id));
|
|
7
|
-
const activeColumnIds = new Set(activeColumns.map((column) => column.id));
|
|
8
|
-
// Remove sort entries for non active columns
|
|
9
|
-
const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
|
|
10
|
-
if (newSort.length < draft.sort.length) {
|
|
11
|
-
draft.sort = newSort;
|
|
12
|
-
(_b = (_a = draft.props).onSortChange) === null || _b === void 0 ? void 0 : _b.call(_a, newSort);
|
|
13
|
-
}
|
|
14
|
-
// Remove filters for non active columns
|
|
15
|
-
for (const id of draft.filters.keys()) {
|
|
16
|
-
if (!activeColumnIds.has(id))
|
|
17
|
-
draft.filters.delete(id);
|
|
18
|
-
}
|
|
19
|
-
// Remove hiddenColumns for non existing columns
|
|
20
|
-
for (const id of draft.hiddenColumns.keys()) {
|
|
21
|
-
if (!columnIds.has(id))
|
|
22
|
-
draft.hiddenColumns.delete(id);
|
|
23
|
-
}
|
|
24
|
-
if (draft.props.items) {
|
|
25
|
-
// Remove selection for non active items
|
|
26
|
-
const newSelection = intersect(draft.selection, activeItemsById);
|
|
27
|
-
if (newSelection.size !== draft.selection.size) {
|
|
28
|
-
draft.selection = newSelection;
|
|
29
|
-
(_d = (_c = draft.props).onSelectionChange) === null || _d === void 0 ? void 0 : _d.call(_c, newSelection);
|
|
30
|
-
}
|
|
31
|
-
// Remove expanded for non existing items
|
|
32
|
-
const newExpanded = intersect(draft.expanded, itemsById);
|
|
33
|
-
if (newExpanded.size < draft.expanded.size) {
|
|
34
|
-
draft.expanded = newExpanded;
|
|
35
|
-
(_f = (_e = draft.props).onExpandedChange) === null || _f === void 0 ? void 0 : _f.call(_e, newExpanded);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, { runNow: true }), [state]);
|
|
39
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
export function filterColumns(state) {
|
|
3
|
-
useEffect(() => state.addReaction((state) => [state.props.columns, state.hiddenColumns], ([columns, hiddenColumns], draft) => {
|
|
4
|
-
draft.activeColumns = columns.filter((column) => !hiddenColumns.has(column.id));
|
|
5
|
-
}, { runNow: true }), [state]);
|
|
6
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
export function syncSelections(state) {
|
|
3
|
-
useEffect(() => state.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
|
|
4
|
-
var _a, _b;
|
|
5
|
-
if (!selectSyncChildren)
|
|
6
|
-
return;
|
|
7
|
-
const newSelection = new Set(selection);
|
|
8
|
-
for (const item of activeItems) {
|
|
9
|
-
if (item.parentId !== undefined && newSelection.has(item.parentId)) {
|
|
10
|
-
newSelection.add(item.id);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (newSelection.size !== selection.size) {
|
|
14
|
-
state.selection = newSelection;
|
|
15
|
-
(_b = (_a = state.props).onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(_a, newSelection);
|
|
16
|
-
}
|
|
17
|
-
}, { runNow: true }), [state]);
|
|
18
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { castDraft } from 'immer';
|
|
2
|
-
import { useEffect, useMemo } from 'react';
|
|
3
|
-
import { Store } from 'schummar-state/react';
|
|
4
|
-
import { calcItems } from './calcItems';
|
|
5
|
-
import { calcProps } from './calcProps';
|
|
6
|
-
import { cleanupState } from './cleanupState';
|
|
7
|
-
import { filterColumns } from './filterColumns';
|
|
8
|
-
import { syncSelections } from './syncSelections';
|
|
9
|
-
export function useTableState(_props) {
|
|
10
|
-
const props = calcProps(_props);
|
|
11
|
-
const state = useMemo(() => {
|
|
12
|
-
var _a, _b, _c, _d;
|
|
13
|
-
return new Store({
|
|
14
|
-
props,
|
|
15
|
-
sort: (_a = props.defaultSort) !== null && _a !== void 0 ? _a : [],
|
|
16
|
-
selection: (_b = props.defaultSelection) !== null && _b !== void 0 ? _b : new Set(),
|
|
17
|
-
expanded: (_c = props.defaultExpanded) !== null && _c !== void 0 ? _c : new Set(),
|
|
18
|
-
rowHeights: new Map(),
|
|
19
|
-
filters: (() => {
|
|
20
|
-
const filters = new Map();
|
|
21
|
-
for (const column of props.columns)
|
|
22
|
-
if (column.defaultFilter) {
|
|
23
|
-
filters.set(column.id, column.defaultFilter);
|
|
24
|
-
}
|
|
25
|
-
return filters;
|
|
26
|
-
})(),
|
|
27
|
-
hiddenColumns: (_d = props.defaultHiddenColumns) !== null && _d !== void 0 ? _d : new Set(),
|
|
28
|
-
activeColumns: [],
|
|
29
|
-
items: [],
|
|
30
|
-
itemsById: new Map(),
|
|
31
|
-
activeItems: [],
|
|
32
|
-
activeItemsById: new Map(),
|
|
33
|
-
lastSelectedId: undefined,
|
|
34
|
-
});
|
|
35
|
-
}, []);
|
|
36
|
-
filterColumns(state);
|
|
37
|
-
calcItems(state);
|
|
38
|
-
syncSelections(state);
|
|
39
|
-
cleanupState(state);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
state.update((state) => {
|
|
42
|
-
state.props = castDraft(props);
|
|
43
|
-
if (props.sort)
|
|
44
|
-
state.sort = props.sort;
|
|
45
|
-
if (props.selection)
|
|
46
|
-
state.selection = props.selection;
|
|
47
|
-
if (props.expanded)
|
|
48
|
-
state.expanded = props.expanded;
|
|
49
|
-
if (props.hiddenColumns)
|
|
50
|
-
state.hiddenColumns = props.hiddenColumns;
|
|
51
|
-
for (const column of props.columns) {
|
|
52
|
-
if (column.filter)
|
|
53
|
-
state.filters.set(column.id, column.filter);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}, [state, props]);
|
|
57
|
-
return state;
|
|
58
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function csvExport(data, { sepPrefix, separator = ',', quote = '"', eol = '\n' } = {}) {
|
|
2
|
-
const cells = data.map((line) => line.map((value) => {
|
|
3
|
-
if (typeof value === 'number')
|
|
4
|
-
return String(value);
|
|
5
|
-
if (![separator, quote, eol].some((c) => value.includes(c)))
|
|
6
|
-
return value;
|
|
7
|
-
const clean = value.replace(new RegExp(quote, 'g'), `${quote}${quote}`);
|
|
8
|
-
return `${quote}${clean}${quote}`;
|
|
9
|
-
}));
|
|
10
|
-
return (sepPrefix ? `SEP=${separator}\n` : '') + cells.map((line) => line.join(separator)).join(eol);
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Id, TableItem } from '../types';
|
|
2
|
-
export declare const flatMap: <T, S>(arr: Iterable<T>, flatMap: (t: T) => S[]) => S[];
|
|
3
|
-
export declare const orderBy: <T>(arr: T[], selectors?: ((t: T) => any)[], direction?: ('desc' | 'asc')[]) => T[];
|
|
4
|
-
export declare const uniq: <T>(arr: T[]) => T[];
|
|
5
|
-
export declare const intersect: <T>(a: Iterable<T>, b: {
|
|
6
|
-
has(t: T): boolean;
|
|
7
|
-
}) => Set<T>;
|
|
8
|
-
export declare const getAncestors: <T>(activeItemsById: Map<Id, TableItem<T>>, ...items: TableItem<T>[]) => Set<Id>;
|
|
9
|
-
export declare const getDescendants: <T>(...items: TableItem<T>[]) => Set<Id>;
|
|
10
|
-
export declare const c: (...classNames: (string | Record<string, boolean> | undefined)[]) => string;
|
|
11
|
-
export declare const identity: (x: unknown) => any;
|
|
12
|
-
export declare const asString: (x: unknown) => string;
|
|
13
|
-
export declare const defaultEquals: (a: unknown, b: unknown) => boolean;
|
|
14
|
-
export declare const subStringMatch: (a: string, b: string) => boolean;
|
package/dist/esm/misc/helpers.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export const flatMap = (arr, flatMap) => {
|
|
2
|
-
return [...arr].reduce((out, cur) => out.concat(flatMap(cur)), []);
|
|
3
|
-
};
|
|
4
|
-
export const orderBy = (arr, selectors = [], direction = []) => {
|
|
5
|
-
if (selectors.length === 0)
|
|
6
|
-
selectors = [(t) => t];
|
|
7
|
-
return [...arr].sort((a, b) => {
|
|
8
|
-
var _c, _d;
|
|
9
|
-
for (let i = 0; i < selectors.length; i++) {
|
|
10
|
-
const _a = (_c = selectors[i]) === null || _c === void 0 ? void 0 : _c.call(selectors, a);
|
|
11
|
-
const _b = (_d = selectors[i]) === null || _d === void 0 ? void 0 : _d.call(selectors, b);
|
|
12
|
-
const dir = direction[i] === 'desc' ? -1 : 1;
|
|
13
|
-
if (_a > _b)
|
|
14
|
-
return dir;
|
|
15
|
-
if (_a < _b)
|
|
16
|
-
return -dir;
|
|
17
|
-
}
|
|
18
|
-
return 0;
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
export const uniq = (arr) => {
|
|
22
|
-
const set = new Set();
|
|
23
|
-
for (const t of arr)
|
|
24
|
-
set.add(t);
|
|
25
|
-
return [...set.values()];
|
|
26
|
-
};
|
|
27
|
-
export const intersect = (a, b) => {
|
|
28
|
-
const result = new Set();
|
|
29
|
-
for (const x of a)
|
|
30
|
-
if (b.has(x))
|
|
31
|
-
result.add(x);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
export const getAncestors = (activeItemsById, ...items) => {
|
|
35
|
-
const result = new Set();
|
|
36
|
-
const find = ({ parentId }) => {
|
|
37
|
-
const parent = parentId ? activeItemsById.get(parentId) : undefined;
|
|
38
|
-
if (parent && !result.has(parent.id)) {
|
|
39
|
-
result.add(parent.id);
|
|
40
|
-
find(parent);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
items.forEach(find);
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
export const getDescendants = (...items) => {
|
|
47
|
-
const result = new Set();
|
|
48
|
-
const find = (item) => {
|
|
49
|
-
for (const child of item.children) {
|
|
50
|
-
if (!result.has(child.id)) {
|
|
51
|
-
result.add(child.id);
|
|
52
|
-
find(child);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
items.forEach(find);
|
|
57
|
-
return result;
|
|
58
|
-
};
|
|
59
|
-
export const c = (...classNames) => flatMap(classNames, (item) => {
|
|
60
|
-
if (item === undefined)
|
|
61
|
-
return [];
|
|
62
|
-
if (typeof item === 'string')
|
|
63
|
-
return [item];
|
|
64
|
-
return Object.entries(item)
|
|
65
|
-
.filter(([, predicate]) => predicate)
|
|
66
|
-
.map(([key]) => key);
|
|
67
|
-
}).join(' ');
|
|
68
|
-
export const identity = (x) => x;
|
|
69
|
-
export const asString = (x) => {
|
|
70
|
-
if (x instanceof Array)
|
|
71
|
-
return x.map(asString).join(', ');
|
|
72
|
-
if (x instanceof Object)
|
|
73
|
-
return JSON.stringify(x);
|
|
74
|
-
return String(x !== null && x !== void 0 ? x : '');
|
|
75
|
-
};
|
|
76
|
-
export const defaultEquals = (a, b) => a === b;
|
|
77
|
-
export const subStringMatch = (a, b) => a.toLowerCase().includes(b.toLowerCase());
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const textMatch = (text, query) => {
|
|
2
|
-
text = text.toLowerCase();
|
|
3
|
-
query = query.toLowerCase();
|
|
4
|
-
return query.split(/\s+/).every((part) => termMatch(text, part));
|
|
5
|
-
};
|
|
6
|
-
export const termMatch = (text, query) => {
|
|
7
|
-
let i = 0;
|
|
8
|
-
outer: for (const char of query) {
|
|
9
|
-
for (; i < text.length; i++) {
|
|
10
|
-
if (text[i] === char) {
|
|
11
|
-
i++;
|
|
12
|
-
continue outer;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function throttle<Args extends any[]>(fn: (...args: Args) => void, ms: number): (...args: Args) => void;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function throttle(fn, ms) {
|
|
2
|
-
let last = 0;
|
|
3
|
-
let lastArgs;
|
|
4
|
-
let timeout;
|
|
5
|
-
function run() {
|
|
6
|
-
const args = lastArgs;
|
|
7
|
-
last = Date.now();
|
|
8
|
-
lastArgs = undefined;
|
|
9
|
-
timeout = undefined;
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
11
|
-
fn(...args);
|
|
12
|
-
}
|
|
13
|
-
return function (...args) {
|
|
14
|
-
const now = Date.now();
|
|
15
|
-
lastArgs = args;
|
|
16
|
-
if (timeout) {
|
|
17
|
-
// do nothing
|
|
18
|
-
}
|
|
19
|
-
else if (now < last + ms) {
|
|
20
|
-
timeout = setTimeout(run, last + ms - now);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
run();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
package/dist/esm/table.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Store } from 'schummar-state/react';
|
|
3
|
-
import { Id, InternalTableState, TableProps } from './types';
|
|
4
|
-
export declare const TableContext: React.Context<Store<InternalTableState<any>> | null>;
|
|
5
|
-
export declare const ColumnContext: React.Context<Id | null>;
|
|
6
|
-
export declare function useTableContext<T>(): Store<InternalTableState<T>>;
|
|
7
|
-
export declare function useColumnContext(): Id;
|
|
8
|
-
export declare function Table<T>(props: TableProps<T>): JSX.Element;
|