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.
Files changed (155) hide show
  1. package/dist/cjs/index.js +3800 -16
  2. package/dist/cjs/index.js.map +1 -0
  3. package/dist/cjs/mui4Theme.js +96 -0
  4. package/dist/cjs/mui4Theme.js.map +1 -0
  5. package/dist/cjs/mui5Theme.js +100 -0
  6. package/dist/cjs/mui5Theme.js.map +1 -0
  7. package/dist/es/index.js +3783 -0
  8. package/dist/es/index.js.map +1 -0
  9. package/dist/es/mui4Theme.js +92 -0
  10. package/dist/es/mui4Theme.js.map +1 -0
  11. package/dist/es/mui5Theme.js +96 -0
  12. package/dist/es/mui5Theme.js.map +1 -0
  13. package/dist/tableTheme.js +1990 -0
  14. package/dist/tableTheme.js.map +1 -0
  15. package/dist/{cjs → types}/components/cell.d.ts +1 -1
  16. package/dist/types/components/columnHeader.d.ts +7 -0
  17. package/dist/{cjs → types}/components/columnSelection.d.ts +0 -0
  18. package/dist/types/components/dateFilter.d.ts +8 -0
  19. package/dist/types/components/datePicker.d.ts +16 -0
  20. package/dist/types/components/expandControl.d.ts +6 -0
  21. package/dist/{cjs → types}/components/export.d.ts +0 -0
  22. package/dist/types/components/filterControl.d.ts +2 -0
  23. package/dist/types/components/formControlLabel.d.ts +5 -0
  24. package/dist/types/components/resizeHandle.d.ts +1 -0
  25. package/dist/{cjs → types}/components/row.d.ts +1 -1
  26. package/dist/{cjs → types}/components/selectComponent.d.ts +0 -0
  27. package/dist/types/components/selectFilter.d.ts +8 -0
  28. package/dist/{cjs → types}/components/sortComponent.d.ts +0 -0
  29. package/dist/types/components/spinnner.d.ts +3 -0
  30. package/dist/{cjs → types/components}/table.d.ts +1 -4
  31. package/dist/types/components/textFilter.d.ts +5 -0
  32. package/dist/{cjs → types}/components/virtualized.d.ts +0 -0
  33. package/dist/types/hooks/useFilter.d.ts +5 -0
  34. package/dist/types/hooks/useTheme.d.ts +1 -0
  35. package/dist/types/index.d.ts +10 -0
  36. package/dist/{cjs → types}/internalState/calcItems.d.ts +0 -0
  37. package/dist/{cjs → types}/internalState/calcProps.d.ts +0 -0
  38. package/dist/{cjs → types}/internalState/cleanupState.d.ts +0 -0
  39. package/dist/{cjs → types}/internalState/filterColumns.d.ts +0 -0
  40. package/dist/{cjs → types}/internalState/syncSelections.d.ts +0 -0
  41. package/dist/{cjs → types}/internalState/tableStateStorage.d.ts +1 -1
  42. package/dist/{cjs → types}/internalState/useTableState.d.ts +0 -0
  43. package/dist/{cjs → types}/misc/csvExport.d.ts +0 -0
  44. package/dist/types/misc/debounce.d.ts +4 -0
  45. package/dist/types/misc/deepPartial.d.ts +3 -0
  46. package/dist/{cjs → types}/misc/helpers.d.ts +2 -1
  47. package/dist/{cjs → types}/misc/queue.d.ts +1 -1
  48. package/dist/{cjs → types}/misc/textMatch.d.ts +0 -0
  49. package/dist/types/misc/throttle.d.ts +4 -0
  50. package/dist/types/theme/defaultClasses.d.ts +15 -0
  51. package/dist/types/theme/defaultColors.d.ts +2 -0
  52. package/dist/types/theme/defaultIcons.d.ts +2 -0
  53. package/dist/types/theme/defaultTexts.d.ts +2 -0
  54. package/dist/types/theme/defaultTheme/badge.d.ts +2 -0
  55. package/dist/types/theme/defaultTheme/button.d.ts +2 -0
  56. package/dist/types/theme/defaultTheme/checkbox.d.ts +2 -0
  57. package/dist/types/theme/defaultTheme/iconButton.d.ts +2 -0
  58. package/dist/types/theme/defaultTheme/index.d.ts +2 -0
  59. package/dist/types/theme/defaultTheme/popover.d.ts +4 -0
  60. package/dist/types/theme/defaultTheme/textField.d.ts +2 -0
  61. package/dist/types/theme/mui4Theme/index.d.ts +8 -0
  62. package/dist/types/theme/mui5Theme/index.d.ts +8 -0
  63. package/dist/types/theme/tableTheme.d.ts +11 -0
  64. package/dist/types/theme/useCssVariables.d.ts +9 -0
  65. package/dist/types/types.d.ts +285 -0
  66. package/package.json +76 -37
  67. package/dist/cjs/components/cell.js +0 -31
  68. package/dist/cjs/components/columnSelection.js +0 -37
  69. package/dist/cjs/components/defaultFilterComponent.d.ts +0 -22
  70. package/dist/cjs/components/defaultFilterComponent.js +0 -91
  71. package/dist/cjs/components/expandComponent.d.ts +0 -5
  72. package/dist/cjs/components/expandComponent.js +0 -38
  73. package/dist/cjs/components/export.js +0 -48
  74. package/dist/cjs/components/filterComponent.d.ts +0 -5
  75. package/dist/cjs/components/filterComponent.js +0 -25
  76. package/dist/cjs/components/row.js +0 -51
  77. package/dist/cjs/components/selectComponent.js +0 -61
  78. package/dist/cjs/components/sortComponent.js +0 -52
  79. package/dist/cjs/components/textFilterComponent.d.ts +0 -11
  80. package/dist/cjs/components/textFilterComponent.js +0 -70
  81. package/dist/cjs/components/useCommonClasses.d.ts +0 -1
  82. package/dist/cjs/components/useCommonClasses.js +0 -49
  83. package/dist/cjs/components/virtualized.js +0 -98
  84. package/dist/cjs/index.d.ts +0 -6
  85. package/dist/cjs/internalState/calcItems.js +0 -85
  86. package/dist/cjs/internalState/calcProps.js +0 -89
  87. package/dist/cjs/internalState/cleanupState.js +0 -43
  88. package/dist/cjs/internalState/filterColumns.js +0 -10
  89. package/dist/cjs/internalState/syncSelections.js +0 -22
  90. package/dist/cjs/internalState/tableStateStorage.js +0 -74
  91. package/dist/cjs/internalState/useTableState.js +0 -62
  92. package/dist/cjs/misc/csvExport.js +0 -15
  93. package/dist/cjs/misc/helpers.js +0 -91
  94. package/dist/cjs/misc/queue.js +0 -42
  95. package/dist/cjs/misc/textMatch.js +0 -23
  96. package/dist/cjs/misc/throttle.d.ts +0 -1
  97. package/dist/cjs/misc/throttle.js +0 -30
  98. package/dist/cjs/package.json +0 -1
  99. package/dist/cjs/table.js +0 -80
  100. package/dist/cjs/types.d.ts +0 -146
  101. package/dist/cjs/types.js +0 -2
  102. package/dist/esm/components/cell.d.ts +0 -6
  103. package/dist/esm/components/cell.js +0 -28
  104. package/dist/esm/components/columnSelection.d.ts +0 -2
  105. package/dist/esm/components/columnSelection.js +0 -33
  106. package/dist/esm/components/defaultFilterComponent.d.ts +0 -22
  107. package/dist/esm/components/defaultFilterComponent.js +0 -86
  108. package/dist/esm/components/expandComponent.d.ts +0 -5
  109. package/dist/esm/components/expandComponent.js +0 -34
  110. package/dist/esm/components/export.d.ts +0 -2
  111. package/dist/esm/components/export.js +0 -44
  112. package/dist/esm/components/filterComponent.d.ts +0 -5
  113. package/dist/esm/components/filterComponent.js +0 -21
  114. package/dist/esm/components/row.d.ts +0 -7
  115. package/dist/esm/components/row.js +0 -47
  116. package/dist/esm/components/selectComponent.d.ts +0 -5
  117. package/dist/esm/components/selectComponent.js +0 -57
  118. package/dist/esm/components/sortComponent.d.ts +0 -4
  119. package/dist/esm/components/sortComponent.js +0 -48
  120. package/dist/esm/components/textFilterComponent.d.ts +0 -11
  121. package/dist/esm/components/textFilterComponent.js +0 -65
  122. package/dist/esm/components/useCommonClasses.d.ts +0 -1
  123. package/dist/esm/components/useCommonClasses.js +0 -46
  124. package/dist/esm/components/virtualized.d.ts +0 -6
  125. package/dist/esm/components/virtualized.js +0 -94
  126. package/dist/esm/index.d.ts +0 -6
  127. package/dist/esm/index.js +0 -4
  128. package/dist/esm/internalState/calcItems.d.ts +0 -3
  129. package/dist/esm/internalState/calcItems.js +0 -81
  130. package/dist/esm/internalState/calcProps.d.ts +0 -2
  131. package/dist/esm/internalState/calcProps.js +0 -85
  132. package/dist/esm/internalState/cleanupState.d.ts +0 -3
  133. package/dist/esm/internalState/cleanupState.js +0 -39
  134. package/dist/esm/internalState/filterColumns.d.ts +0 -3
  135. package/dist/esm/internalState/filterColumns.js +0 -6
  136. package/dist/esm/internalState/syncSelections.d.ts +0 -3
  137. package/dist/esm/internalState/syncSelections.js +0 -18
  138. package/dist/esm/internalState/tableStateStorage.d.ts +0 -11
  139. package/dist/esm/internalState/tableStateStorage.js +0 -70
  140. package/dist/esm/internalState/useTableState.d.ts +0 -3
  141. package/dist/esm/internalState/useTableState.js +0 -58
  142. package/dist/esm/misc/csvExport.d.ts +0 -7
  143. package/dist/esm/misc/csvExport.js +0 -11
  144. package/dist/esm/misc/helpers.d.ts +0 -14
  145. package/dist/esm/misc/helpers.js +0 -77
  146. package/dist/esm/misc/queue.d.ts +0 -6
  147. package/dist/esm/misc/queue.js +0 -38
  148. package/dist/esm/misc/textMatch.d.ts +0 -2
  149. package/dist/esm/misc/textMatch.js +0 -18
  150. package/dist/esm/misc/throttle.d.ts +0 -1
  151. package/dist/esm/misc/throttle.js +0 -26
  152. package/dist/esm/table.d.ts +0 -11
  153. package/dist/esm/table.js +0 -73
  154. package/dist/esm/types.d.ts +0 -146
  155. package/dist/esm/types.js +0 -1
@@ -1,57 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Checkbox, makeStyles } from '@material-ui/core';
3
- import { getAncestors, getDescendants } from '../misc/helpers';
4
- import { useTableContext } from '../table';
5
- const useClasses = makeStyles({
6
- justifiedCheckbox: {
7
- justifySelf: 'start',
8
- color: 'inherit',
9
- },
10
- });
11
- export function SelectComponent({ itemId }) {
12
- const classes = useClasses();
13
- const state = useTableContext();
14
- const isSelected = state.useState((state) => {
15
- const itemIds = itemId ? [itemId] : [...state.activeItemsById.keys()];
16
- return state.activeItemsById.size > 0 && itemIds.every((itemId) => state.selection.has(itemId));
17
- }, [itemId]);
18
- function toggle(e) {
19
- const mouseEvent = e.nativeEvent;
20
- const { activeItems, activeItemsById, lastSelectedId, selection, props: { selectSyncChildren, selection: controlledSelection, onSelectionChange }, } = state.getState();
21
- let range;
22
- if (mouseEvent.shiftKey && itemId) {
23
- const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
24
- const b = activeItems.findIndex((item) => item.id === itemId);
25
- range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
26
- }
27
- else {
28
- const item = itemId ? activeItemsById.get(itemId) : undefined;
29
- range = item ? [item] : activeItems;
30
- }
31
- const newSelection = new Set(selection);
32
- for (const item of range) {
33
- if (isSelected)
34
- newSelection.delete(item.id);
35
- else
36
- newSelection.add(item.id);
37
- }
38
- if (selectSyncChildren && isSelected) {
39
- for (const ancestor of getAncestors(activeItemsById, ...range)) {
40
- newSelection.delete(ancestor);
41
- }
42
- for (const descendant of getDescendants(...range)) {
43
- newSelection.delete(descendant);
44
- }
45
- }
46
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelection);
47
- if (!controlledSelection) {
48
- state.update((state) => {
49
- state.selection = newSelection;
50
- });
51
- }
52
- state.update((state) => {
53
- state.lastSelectedId = itemId;
54
- });
55
- }
56
- return _jsx(Checkbox, { className: classes.justifiedCheckbox, checked: isSelected, onChange: toggle }, void 0);
57
- }
@@ -1,4 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export declare function SortComponent<T>({ children }: {
3
- children: ReactNode;
4
- }): JSX.Element;
@@ -1,48 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Badge, makeStyles } from '@material-ui/core';
3
- import { ArrowDownward, ArrowUpward } from '@material-ui/icons';
4
- import { useColumnContext, useTableContext } from '../table';
5
- const useClasses = makeStyles({
6
- sortView: {
7
- userSelect: 'none',
8
- display: 'grid',
9
- gridTemplateColumns: 'minmax(0, 1fr) max-content',
10
- alignItems: 'center',
11
- cursor: 'pointer',
12
- '& > div': {
13
- overflow: 'hidden',
14
- textOverflow: 'ellipsis',
15
- },
16
- },
17
- empty: {
18
- width: 20,
19
- },
20
- });
21
- export function SortComponent({ children }) {
22
- const classes = useClasses();
23
- const state = useTableContext();
24
- const columnId = useColumnContext();
25
- const { direction, index } = state.useState((state) => {
26
- var _a, _b;
27
- const index = (_a = state.sort.findIndex((s) => s.columnId === columnId)) !== null && _a !== void 0 ? _a : -1;
28
- return {
29
- direction: (_b = state.sort[index]) === null || _b === void 0 ? void 0 : _b.direction,
30
- index: index >= 0 ? index + 1 : undefined,
31
- };
32
- });
33
- function toggle(e) {
34
- const { props: { sort: controlledSort, onSortChange }, } = state.getState();
35
- const newDirection = direction === 'asc' ? 'desc' : 'asc';
36
- const newSort = (e.getModifierState('Control') ? state.getState().sort.filter((s) => s.columnId !== columnId) : []).concat({
37
- columnId,
38
- direction: newDirection,
39
- });
40
- onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange(newSort);
41
- if (!controlledSort) {
42
- state.update((state) => {
43
- state.sort = newSort;
44
- });
45
- }
46
- }
47
- return (_jsxs("div", Object.assign({ className: classes.sortView, onClick: toggle }, { children: [_jsx("div", { children: children }, void 0), _jsx(Badge, Object.assign({ badgeContent: index }, { children: direction === 'asc' ? (_jsx(ArrowUpward, { fontSize: "small" }, void 0)) : direction === 'desc' ? (_jsx(ArrowDownward, { fontSize: "small" }, void 0)) : (_jsx("div", { className: classes.empty }, void 0)) }), void 0)] }), void 0));
48
- }
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { Filter } from './filterComponent';
3
- export declare class TextFilter<T> implements Filter<T> {
4
- readonly query: string;
5
- readonly filter: (item: T) => boolean;
6
- constructor(query: string, filter: (item: T) => boolean);
7
- }
8
- export declare function TextFilterComponent<T, V>({ filterBy, compare, }: {
9
- filterBy?: (value: V, item: T) => string;
10
- compare?: (a: string, b: string) => boolean;
11
- }): JSX.Element;
@@ -1,65 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { IconButton, makeStyles, TextField } from '@material-ui/core';
3
- import { Clear, Search } from '@material-ui/icons';
4
- import { useEffect, useState } from 'react';
5
- import { asString } from '../misc/helpers';
6
- import { textMatch } from '../misc/textMatch';
7
- import { useColumnContext, useTableContext } from '../table';
8
- export class TextFilter {
9
- constructor(query, filter) {
10
- this.query = query;
11
- this.filter = filter;
12
- }
13
- }
14
- const useClasses = makeStyles((theme) => ({
15
- view: {
16
- padding: theme.spacing(2),
17
- display: 'grid',
18
- '& > :first-child': {
19
- marginBottom: theme.spacing(2),
20
- },
21
- },
22
- }));
23
- export function TextFilterComponent({ filterBy = asString, compare = textMatch, }) {
24
- var _a;
25
- const classes = useClasses();
26
- const state = useTableContext();
27
- const columnId = useColumnContext();
28
- const _filter = state.useState((state) => {
29
- var _a;
30
- const column = state.activeColumns.find((column) => column.id === columnId);
31
- return (_a = state.filters.get(columnId)) !== null && _a !== void 0 ? _a : column === null || column === void 0 ? void 0 : column.defaultFilter;
32
- }, [columnId]);
33
- const filter = _filter instanceof TextFilter ? _filter : undefined;
34
- const [input, setInput] = useState();
35
- useEffect(() => {
36
- if (input === undefined)
37
- return;
38
- const handle = setTimeout(() => {
39
- var _a;
40
- const column = state.getState().activeColumns.find((column) => column.id === columnId);
41
- if (!column)
42
- return;
43
- const newFilter = input
44
- ? new TextFilter(input, (item) => {
45
- const itemValue = filterBy(column.value(item), item);
46
- return compare(itemValue, input);
47
- })
48
- : undefined;
49
- if (!column.filter) {
50
- state.update((state) => {
51
- if (newFilter)
52
- state.filters.set(column.id, newFilter);
53
- else
54
- state.filters.delete(column.id);
55
- });
56
- }
57
- (_a = column.onFilterChange) === null || _a === void 0 ? void 0 : _a.call(column, newFilter);
58
- setInput(undefined);
59
- }, 500);
60
- return () => clearTimeout(handle);
61
- }, [input]);
62
- return (_jsx("div", Object.assign({ className: classes.view }, { children: _jsx(TextField, { value: (_a = input !== null && input !== void 0 ? input : filter === null || filter === void 0 ? void 0 : filter.query) !== null && _a !== void 0 ? _a : '', onChange: (e) => setInput(e.target.value), InputProps: {
63
- endAdornment: (filter === null || filter === void 0 ? void 0 : filter.query) ? (_jsx(IconButton, Object.assign({ onClick: () => setInput('') }, { children: _jsx(Clear, {}, void 0) }), void 0)) : (_jsx(Search, {}, void 0)),
64
- } }, void 0) }), void 0));
65
- }
@@ -1 +0,0 @@
1
- export declare const useCommonClasses: (props?: any) => import("@material-ui/styles").ClassNameMap<"table" | "text" | "cell" | "sticky" | "headerCell" | "cellFill" | "firstCell" | "headerFill" | "deferredPlaceholder">;
@@ -1,46 +0,0 @@
1
- import { makeStyles } from '@material-ui/core';
2
- const cell = (theme) => ({
3
- padding: theme.spacing(0.1, 1),
4
- display: 'flex',
5
- alignItems: 'center',
6
- borderBottom: `1px solid ${theme.palette.grey[200]}`,
7
- whiteSpace: 'nowrap',
8
- overflow: 'hidden',
9
- });
10
- export const useCommonClasses = makeStyles((theme) => ({
11
- table: {
12
- position: 'relative',
13
- display: 'grid',
14
- },
15
- cell: cell(theme),
16
- cellFill: {
17
- borderBottom: `1px solid ${theme.palette.grey[200]}`,
18
- },
19
- headerCell: Object.assign(Object.assign({}, cell(theme)), { borderBottom: `2px solid ${theme.palette.grey[400]}`, gridTemplateColumns: 'minmax(0, 1fr) max-content', background: theme.palette.common.white, '&:not(:first-child)': {
20
- borderLeft: `1px solid ${theme.palette.background.default}`,
21
- } }),
22
- firstCell: {
23
- justifyContent: 'start',
24
- },
25
- sticky: {
26
- position: 'sticky',
27
- top: 0,
28
- zIndex: 1,
29
- },
30
- headerFill: {
31
- borderBottom: `3px solid ${theme.palette.grey[200]}`,
32
- background: theme.palette.common.white,
33
- },
34
- deferredPlaceholder: {
35
- padding: theme.spacing(1),
36
- borderBottom: `1px solid ${theme.palette.grey[200]}`,
37
- gridColumn: '1 / -1',
38
- display: 'grid',
39
- justifyContent: 'center',
40
- },
41
- text: {
42
- minWidth: 0,
43
- overflow: 'hidden',
44
- textOverflow: 'ellipsis',
45
- },
46
- }));
@@ -1,6 +0,0 @@
1
- import { HTMLProps, ReactNode } from 'react';
2
- import { Id } from '../types';
3
- export declare function Virtualized<T>({ header, children, ...props }: {
4
- header: ReactNode;
5
- children: (itemIds: Id[], startIndex: number) => ReactNode;
6
- } & HTMLProps<HTMLDivElement>): JSX.Element;
@@ -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
- }
@@ -1,6 +0,0 @@
1
- export { DefaultFilter, DefaultFilterComponent } from './components/defaultFilterComponent';
2
- export type { 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,3 +0,0 @@
1
- import { Store } from 'schummar-state/react';
2
- import { InternalTableState } from '../types';
3
- export declare function calcItems<T>(state: Store<InternalTableState<T>>): void;
@@ -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,2 +0,0 @@
1
- import { InternalTableProps, TableProps } from '../types';
2
- export declare function calcProps<T>(props: TableProps<T>): InternalTableProps<T>;
@@ -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,3 +0,0 @@
1
- import { Store } from 'schummar-state/react';
2
- import { InternalTableState } from '../types';
3
- export declare function cleanupState<T>(state: Store<InternalTableState<T>>): void;
@@ -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,3 +0,0 @@
1
- import { Store } from 'schummar-state/react';
2
- import { InternalTableState } from '../types';
3
- export declare function filterColumns<T>(state: Store<InternalTableState<T>>): void;
@@ -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,3 +0,0 @@
1
- import { Store } from 'schummar-state/react';
2
- import { InternalTableState } from '../types';
3
- export declare function syncSelections<T>(state: Store<InternalTableState<T>>): void;
@@ -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,11 +0,0 @@
1
- export declare type TableStateStorage = {
2
- getItem: (key: string) => string | null | Promise<string | null>;
3
- setItem: (key: string, value: string) => unknown | Promise<unknown>;
4
- removeItem: (key: string) => unknown | Promise<unknown>;
5
- } & ({
6
- keys: () => string[] | Promise<string[]>;
7
- } | {
8
- length: number | (() => number | Promise<number>);
9
- key: (keyIndex: number) => string | null | Promise<string | null>;
10
- });
11
- export declare function useTableStateStorage(): void;