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
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { useEffect } from 'react';
|
|
11
|
-
import { useTableContext } from '..';
|
|
12
|
-
import { Queue } from '../misc/queue';
|
|
13
|
-
const KEYS = ['sort', 'selection', 'expanded', 'hiddenColumns'];
|
|
14
|
-
export function useTableStateStorage() {
|
|
15
|
-
const state = useTableContext();
|
|
16
|
-
// On mount: load
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const { storeState, debug } = state.getState().props;
|
|
19
|
-
if (!storeState)
|
|
20
|
-
return;
|
|
21
|
-
let isCanceled = false;
|
|
22
|
-
const q = new Queue();
|
|
23
|
-
q.run(() => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
try {
|
|
25
|
-
const { storage, id = 'table', include } = storeState;
|
|
26
|
-
const json = yield storage.getItem(`${id}_state`);
|
|
27
|
-
if (isCanceled || !json)
|
|
28
|
-
return;
|
|
29
|
-
const data = JSON.parse(json);
|
|
30
|
-
state.update((state) => {
|
|
31
|
-
for (const key of KEYS) {
|
|
32
|
-
if (!include || include[key]) {
|
|
33
|
-
const value = key === 'sort' ? data.sort : new Set(data[key]);
|
|
34
|
-
state[key] = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
catch (e) {
|
|
40
|
-
debug === null || debug === void 0 ? void 0 : debug('Failed to load table state:', e);
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
43
|
-
state.subscribe((state) => {
|
|
44
|
-
if (!state.props.storeState)
|
|
45
|
-
return;
|
|
46
|
-
const data = {};
|
|
47
|
-
for (const key of KEYS) {
|
|
48
|
-
if (!state.props.storeState.include || state.props.storeState.include[key]) {
|
|
49
|
-
const value = key === 'sort' ? state.sort : Array.from(state[key]);
|
|
50
|
-
data[key] = value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
storage: state.props.storeState.storage,
|
|
55
|
-
id: state.props.storeState.id,
|
|
56
|
-
data,
|
|
57
|
-
};
|
|
58
|
-
}, (props) => {
|
|
59
|
-
if (!props)
|
|
60
|
-
return;
|
|
61
|
-
const { storage, id = 'table', data } = props;
|
|
62
|
-
q.run(() => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
yield storage.setItem(`${id}_state`, JSON.stringify(data));
|
|
64
|
-
}));
|
|
65
|
-
});
|
|
66
|
-
return () => {
|
|
67
|
-
isCanceled = true;
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
}
|
|
@@ -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());
|
package/dist/esm/misc/queue.d.ts
DELETED
package/dist/esm/misc/queue.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export class Queue {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.q = new Array();
|
|
13
|
-
this.isRunning = false;
|
|
14
|
-
}
|
|
15
|
-
run(job) {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
this.q.push({ job, resolve, reject });
|
|
18
|
-
if (!this.isRunning)
|
|
19
|
-
this.start();
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
start() {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
this.isRunning = true;
|
|
25
|
-
let next;
|
|
26
|
-
while ((next = this.q.shift())) {
|
|
27
|
-
try {
|
|
28
|
-
const result = yield next.job();
|
|
29
|
-
next.resolve(result);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
next.reject(e);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
this.isRunning = false;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -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,11 +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
|
-
declare let defaultProps: Pick<TableProps<unknown>, 'text' | 'classes'>;
|
|
9
|
-
export declare function configureTables(props: typeof defaultProps): void;
|
|
10
|
-
export declare function Table<T>(props: TableProps<T>): JSX.Element;
|
|
11
|
-
export {};
|
package/dist/esm/table.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, memo, useContext } from 'react';
|
|
3
|
-
import { ColumnSelection } from './components/columnSelection';
|
|
4
|
-
import { Export } from './components/export';
|
|
5
|
-
import { FilterComponent } from './components/filterComponent';
|
|
6
|
-
import { Row } from './components/row';
|
|
7
|
-
import { SelectComponent } from './components/selectComponent';
|
|
8
|
-
import { SortComponent } from './components/sortComponent';
|
|
9
|
-
import { useCommonClasses } from './components/useCommonClasses';
|
|
10
|
-
import { Virtualized } from './components/virtualized';
|
|
11
|
-
import { useTableStateStorage } from './internalState/tableStateStorage';
|
|
12
|
-
import { useTableState } from './internalState/useTableState';
|
|
13
|
-
import { c } from './misc/helpers';
|
|
14
|
-
export const TableContext = createContext(null);
|
|
15
|
-
export const ColumnContext = createContext(null);
|
|
16
|
-
export function useTableContext() {
|
|
17
|
-
const value = useContext(TableContext);
|
|
18
|
-
if (!value)
|
|
19
|
-
throw Error('No table context available');
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
export function useColumnContext() {
|
|
23
|
-
const value = useContext(ColumnContext);
|
|
24
|
-
if (value === null)
|
|
25
|
-
throw Error('No column context available');
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
let defaultProps = {};
|
|
29
|
-
export function configureTables(props) {
|
|
30
|
-
defaultProps = props;
|
|
31
|
-
}
|
|
32
|
-
function mergeProps(props) {
|
|
33
|
-
return Object.assign(Object.assign({}, props), { text: Object.assign(Object.assign({}, defaultProps.text), props.text), classes: Object.assign(Object.assign({}, defaultProps.classes), props.classes) });
|
|
34
|
-
}
|
|
35
|
-
export function Table(props) {
|
|
36
|
-
var _a, _b;
|
|
37
|
-
props = mergeProps(props);
|
|
38
|
-
const state = useTableState(props);
|
|
39
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render table');
|
|
40
|
-
return (_jsx(TableContext.Provider, Object.assign({ value: state }, { children: _jsx(TableInner, {}, void 0) }), void 0));
|
|
41
|
-
}
|
|
42
|
-
const TableInner = memo(function TableInner() {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
useTableStateStorage();
|
|
45
|
-
const commonClasses = useCommonClasses();
|
|
46
|
-
const state = useTableContext();
|
|
47
|
-
const fullWidth = state.useState('props.fullWidth');
|
|
48
|
-
const activeColumns = state.useState((state) => state.activeColumns.map((column) => ({
|
|
49
|
-
id: column.id,
|
|
50
|
-
width: column.width,
|
|
51
|
-
classes: column.classes,
|
|
52
|
-
header: column.header,
|
|
53
|
-
})));
|
|
54
|
-
const defaultWidth = state.useState('props.defaultWidth');
|
|
55
|
-
const classes = state.useState('props.classes');
|
|
56
|
-
const stickyHeader = state.useState('props.stickyHeader');
|
|
57
|
-
const enableSelection = state.useState('props.enableSelection');
|
|
58
|
-
const enableColumnSelection = state.useState('props.enableColumnSelection');
|
|
59
|
-
const enableExport = state.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
60
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render table inner');
|
|
61
|
-
return (_jsx(Virtualized, Object.assign({ className: c(commonClasses.table, classes === null || classes === void 0 ? void 0 : classes.table), style: {
|
|
62
|
-
gridTemplateColumns: [
|
|
63
|
-
//
|
|
64
|
-
fullWidth === 'right' || fullWidth === true ? 'auto' : '0',
|
|
65
|
-
'max-content',
|
|
66
|
-
...activeColumns.map((column) => { var _a, _b; return (_b = (_a = column.width) !== null && _a !== void 0 ? _a : defaultWidth) !== null && _b !== void 0 ? _b : 'max-content'; }),
|
|
67
|
-
fullWidth === 'left' || fullWidth === true ? 'auto' : '0',
|
|
68
|
-
].join(' '),
|
|
69
|
-
}, header: _jsxs(_Fragment, { children: [_jsx("div", { className: c(commonClasses.headerFill, { [commonClasses.sticky]: !!stickyHeader }, classes === null || classes === void 0 ? void 0 : classes.headerCell) }, void 0), _jsxs("div", Object.assign({ className: c(commonClasses.headerCell, { [commonClasses.sticky]: !!stickyHeader }, classes === null || classes === void 0 ? void 0 : classes.headerCell) }, { children: [enableSelection && _jsx(SelectComponent, {}, void 0), enableColumnSelection && _jsx(ColumnSelection, {}, void 0), enableExport && _jsx(Export, {}, void 0)] }), void 0), activeColumns.map((column) => {
|
|
70
|
-
var _a;
|
|
71
|
-
return (_jsx(ColumnContext.Provider, Object.assign({ value: column.id }, { children: _jsxs("div", Object.assign({ className: 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: [_jsx(SortComponent, { children: column.header }, void 0), _jsx(FilterComponent, {}, void 0)] }), column.id) }), column.id));
|
|
72
|
-
}), _jsx("div", { className: 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) => _jsx(Row, { itemId: itemId, rowIndex: startIndex + index }, itemId)) }), void 0));
|
|
73
|
-
});
|
package/dist/esm/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/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|