@ni/nimble-components 15.5.3 → 15.5.5
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/all-components-bundle.js +3081 -1
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +2604 -2204
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/esm/table/index.d.ts +14 -1
- package/dist/esm/table/index.js +94 -0
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/table/styles.js +22 -0
- package/dist/esm/table/styles.js.map +1 -1
- package/dist/esm/table/template.d.ts +1 -1
- package/dist/esm/table/template.js +22 -2
- package/dist/esm/table/template.js.map +1 -1
- package/dist/esm/table/types.d.ts +18 -0
- package/dist/esm/table/types.js +2 -0
- package/dist/esm/table/types.js.map +1 -0
- package/package.json +2 -1
|
@@ -21674,17 +21674,3097 @@
|
|
|
21674
21674
|
});
|
|
21675
21675
|
DesignSystem.getOrCreate().withPrefix('nimble').register(nimbleTabPanel());
|
|
21676
21676
|
|
|
21677
|
+
/**
|
|
21678
|
+
* table-core
|
|
21679
|
+
*
|
|
21680
|
+
* Copyright (c) TanStack
|
|
21681
|
+
*
|
|
21682
|
+
* This source code is licensed under the MIT license found in the
|
|
21683
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
21684
|
+
*
|
|
21685
|
+
* @license MIT
|
|
21686
|
+
*/
|
|
21687
|
+
// Is this type a tuple?
|
|
21688
|
+
|
|
21689
|
+
// If this type is a tuple, what indices are allowed?
|
|
21690
|
+
|
|
21691
|
+
///
|
|
21692
|
+
|
|
21693
|
+
function functionalUpdate(updater, input) {
|
|
21694
|
+
return typeof updater === 'function' ? updater(input) : updater;
|
|
21695
|
+
}
|
|
21696
|
+
function makeStateUpdater(key, instance) {
|
|
21697
|
+
return updater => {
|
|
21698
|
+
instance.setState(old => {
|
|
21699
|
+
return {
|
|
21700
|
+
...old,
|
|
21701
|
+
[key]: functionalUpdate(updater, old[key])
|
|
21702
|
+
};
|
|
21703
|
+
});
|
|
21704
|
+
};
|
|
21705
|
+
}
|
|
21706
|
+
function isFunction(d) {
|
|
21707
|
+
return d instanceof Function;
|
|
21708
|
+
}
|
|
21709
|
+
function flattenBy(arr, getChildren) {
|
|
21710
|
+
const flat = [];
|
|
21711
|
+
const recurse = subArr => {
|
|
21712
|
+
subArr.forEach(item => {
|
|
21713
|
+
flat.push(item);
|
|
21714
|
+
const children = getChildren(item);
|
|
21715
|
+
if (children != null && children.length) {
|
|
21716
|
+
recurse(children);
|
|
21717
|
+
}
|
|
21718
|
+
});
|
|
21719
|
+
};
|
|
21720
|
+
recurse(arr);
|
|
21721
|
+
return flat;
|
|
21722
|
+
}
|
|
21723
|
+
function memo(getDeps, fn, opts) {
|
|
21724
|
+
let deps = [];
|
|
21725
|
+
let result;
|
|
21726
|
+
return () => {
|
|
21727
|
+
let depTime;
|
|
21728
|
+
if (opts.key && opts.debug) depTime = Date.now();
|
|
21729
|
+
const newDeps = getDeps();
|
|
21730
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
21731
|
+
if (!depsChanged) {
|
|
21732
|
+
return result;
|
|
21733
|
+
}
|
|
21734
|
+
deps = newDeps;
|
|
21735
|
+
let resultTime;
|
|
21736
|
+
if (opts.key && opts.debug) resultTime = Date.now();
|
|
21737
|
+
result = fn(...newDeps);
|
|
21738
|
+
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
21739
|
+
if (opts.key && opts.debug) {
|
|
21740
|
+
if (opts != null && opts.debug()) {
|
|
21741
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
21742
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
21743
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
21744
|
+
const pad = (str, num) => {
|
|
21745
|
+
str = String(str);
|
|
21746
|
+
while (str.length < num) {
|
|
21747
|
+
str = ' ' + str;
|
|
21748
|
+
}
|
|
21749
|
+
return str;
|
|
21750
|
+
};
|
|
21751
|
+
console.info(`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
|
|
21752
|
+
font-size: .6rem;
|
|
21753
|
+
font-weight: bold;
|
|
21754
|
+
color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
|
|
21755
|
+
}
|
|
21756
|
+
}
|
|
21757
|
+
return result;
|
|
21758
|
+
};
|
|
21759
|
+
}
|
|
21760
|
+
|
|
21761
|
+
function createColumn(table, columnDef, depth, parent) {
|
|
21762
|
+
var _ref, _resolvedColumnDef$id;
|
|
21763
|
+
const defaultColumn = table._getDefaultColumnDef();
|
|
21764
|
+
const resolvedColumnDef = {
|
|
21765
|
+
...defaultColumn,
|
|
21766
|
+
...columnDef
|
|
21767
|
+
};
|
|
21768
|
+
const accessorKey = resolvedColumnDef.accessorKey;
|
|
21769
|
+
let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? accessorKey.replace('.', '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
|
|
21770
|
+
let accessorFn;
|
|
21771
|
+
if (resolvedColumnDef.accessorFn) {
|
|
21772
|
+
accessorFn = resolvedColumnDef.accessorFn;
|
|
21773
|
+
} else if (accessorKey) {
|
|
21774
|
+
// Support deep accessor keys
|
|
21775
|
+
if (accessorKey.includes('.')) {
|
|
21776
|
+
accessorFn = originalRow => {
|
|
21777
|
+
let result = originalRow;
|
|
21778
|
+
for (const key of accessorKey.split('.')) {
|
|
21779
|
+
result = result[key];
|
|
21780
|
+
if (process.env.NODE_ENV !== 'production' && result === undefined) {
|
|
21781
|
+
throw new Error(`"${key}" in deeply nested key "${accessorKey}" returned undefined.`);
|
|
21782
|
+
}
|
|
21783
|
+
}
|
|
21784
|
+
return result;
|
|
21785
|
+
};
|
|
21786
|
+
} else {
|
|
21787
|
+
accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
|
|
21788
|
+
}
|
|
21789
|
+
}
|
|
21790
|
+
if (!id) {
|
|
21791
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
21792
|
+
throw new Error(resolvedColumnDef.accessorFn ? `Columns require an id when using an accessorFn` : `Columns require an id when using a non-string header`);
|
|
21793
|
+
}
|
|
21794
|
+
throw new Error();
|
|
21795
|
+
}
|
|
21796
|
+
let column = {
|
|
21797
|
+
id: `${String(id)}`,
|
|
21798
|
+
accessorFn,
|
|
21799
|
+
parent: parent,
|
|
21800
|
+
depth,
|
|
21801
|
+
columnDef: resolvedColumnDef,
|
|
21802
|
+
columns: [],
|
|
21803
|
+
getFlatColumns: memo(() => [true], () => {
|
|
21804
|
+
var _column$columns;
|
|
21805
|
+
return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
|
|
21806
|
+
}, {
|
|
21807
|
+
key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
|
|
21808
|
+
debug: () => {
|
|
21809
|
+
var _table$options$debugA;
|
|
21810
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugColumns;
|
|
21811
|
+
}
|
|
21812
|
+
}),
|
|
21813
|
+
getLeafColumns: memo(() => [table._getOrderColumnsFn()], orderColumns => {
|
|
21814
|
+
var _column$columns2;
|
|
21815
|
+
if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
|
|
21816
|
+
let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
|
|
21817
|
+
return orderColumns(leafColumns);
|
|
21818
|
+
}
|
|
21819
|
+
return [column];
|
|
21820
|
+
}, {
|
|
21821
|
+
key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
|
|
21822
|
+
debug: () => {
|
|
21823
|
+
var _table$options$debugA2;
|
|
21824
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugColumns;
|
|
21825
|
+
}
|
|
21826
|
+
})
|
|
21827
|
+
};
|
|
21828
|
+
column = table._features.reduce((obj, feature) => {
|
|
21829
|
+
return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, table));
|
|
21830
|
+
}, column);
|
|
21831
|
+
|
|
21832
|
+
// Yes, we have to convert table to uknown, because we know more than the compiler here.
|
|
21833
|
+
return column;
|
|
21834
|
+
}
|
|
21835
|
+
|
|
21836
|
+
//
|
|
21837
|
+
|
|
21838
|
+
function createHeader(table, column, options) {
|
|
21839
|
+
var _options$id;
|
|
21840
|
+
const id = (_options$id = options.id) != null ? _options$id : column.id;
|
|
21841
|
+
let header = {
|
|
21842
|
+
id,
|
|
21843
|
+
column,
|
|
21844
|
+
index: options.index,
|
|
21845
|
+
isPlaceholder: !!options.isPlaceholder,
|
|
21846
|
+
placeholderId: options.placeholderId,
|
|
21847
|
+
depth: options.depth,
|
|
21848
|
+
subHeaders: [],
|
|
21849
|
+
colSpan: 0,
|
|
21850
|
+
rowSpan: 0,
|
|
21851
|
+
headerGroup: null,
|
|
21852
|
+
getLeafHeaders: () => {
|
|
21853
|
+
const leafHeaders = [];
|
|
21854
|
+
const recurseHeader = h => {
|
|
21855
|
+
if (h.subHeaders && h.subHeaders.length) {
|
|
21856
|
+
h.subHeaders.map(recurseHeader);
|
|
21857
|
+
}
|
|
21858
|
+
leafHeaders.push(h);
|
|
21859
|
+
};
|
|
21860
|
+
recurseHeader(header);
|
|
21861
|
+
return leafHeaders;
|
|
21862
|
+
},
|
|
21863
|
+
getContext: () => ({
|
|
21864
|
+
table,
|
|
21865
|
+
header: header,
|
|
21866
|
+
column
|
|
21867
|
+
})
|
|
21868
|
+
};
|
|
21869
|
+
table._features.forEach(feature => {
|
|
21870
|
+
Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, table));
|
|
21871
|
+
});
|
|
21872
|
+
return header;
|
|
21873
|
+
}
|
|
21874
|
+
const Headers = {
|
|
21875
|
+
createTable: table => {
|
|
21876
|
+
return {
|
|
21877
|
+
// Header Groups
|
|
21878
|
+
|
|
21879
|
+
getHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
21880
|
+
var _left$map$filter, _right$map$filter;
|
|
21881
|
+
const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
|
|
21882
|
+
const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
|
|
21883
|
+
const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
|
|
21884
|
+
const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], table);
|
|
21885
|
+
return headerGroups;
|
|
21886
|
+
}, {
|
|
21887
|
+
key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
|
|
21888
|
+
debug: () => {
|
|
21889
|
+
var _table$options$debugA;
|
|
21890
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugHeaders;
|
|
21891
|
+
}
|
|
21892
|
+
}),
|
|
21893
|
+
getCenterHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
21894
|
+
leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
|
|
21895
|
+
return buildHeaderGroups(allColumns, leafColumns, table, 'center');
|
|
21896
|
+
}, {
|
|
21897
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
|
|
21898
|
+
debug: () => {
|
|
21899
|
+
var _table$options$debugA2;
|
|
21900
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugHeaders;
|
|
21901
|
+
}
|
|
21902
|
+
}),
|
|
21903
|
+
getLeftHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left], (allColumns, leafColumns, left) => {
|
|
21904
|
+
var _left$map$filter2;
|
|
21905
|
+
const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
|
|
21906
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left');
|
|
21907
|
+
}, {
|
|
21908
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
|
|
21909
|
+
debug: () => {
|
|
21910
|
+
var _table$options$debugA3;
|
|
21911
|
+
return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugHeaders;
|
|
21912
|
+
}
|
|
21913
|
+
}),
|
|
21914
|
+
getRightHeaderGroups: memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.right], (allColumns, leafColumns, right) => {
|
|
21915
|
+
var _right$map$filter2;
|
|
21916
|
+
const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
|
|
21917
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right');
|
|
21918
|
+
}, {
|
|
21919
|
+
key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
|
|
21920
|
+
debug: () => {
|
|
21921
|
+
var _table$options$debugA4;
|
|
21922
|
+
return (_table$options$debugA4 = table.options.debugAll) != null ? _table$options$debugA4 : table.options.debugHeaders;
|
|
21923
|
+
}
|
|
21924
|
+
}),
|
|
21925
|
+
// Footer Groups
|
|
21926
|
+
|
|
21927
|
+
getFooterGroups: memo(() => [table.getHeaderGroups()], headerGroups => {
|
|
21928
|
+
return [...headerGroups].reverse();
|
|
21929
|
+
}, {
|
|
21930
|
+
key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
|
|
21931
|
+
debug: () => {
|
|
21932
|
+
var _table$options$debugA5;
|
|
21933
|
+
return (_table$options$debugA5 = table.options.debugAll) != null ? _table$options$debugA5 : table.options.debugHeaders;
|
|
21934
|
+
}
|
|
21935
|
+
}),
|
|
21936
|
+
getLeftFooterGroups: memo(() => [table.getLeftHeaderGroups()], headerGroups => {
|
|
21937
|
+
return [...headerGroups].reverse();
|
|
21938
|
+
}, {
|
|
21939
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
|
|
21940
|
+
debug: () => {
|
|
21941
|
+
var _table$options$debugA6;
|
|
21942
|
+
return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugHeaders;
|
|
21943
|
+
}
|
|
21944
|
+
}),
|
|
21945
|
+
getCenterFooterGroups: memo(() => [table.getCenterHeaderGroups()], headerGroups => {
|
|
21946
|
+
return [...headerGroups].reverse();
|
|
21947
|
+
}, {
|
|
21948
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
|
|
21949
|
+
debug: () => {
|
|
21950
|
+
var _table$options$debugA7;
|
|
21951
|
+
return (_table$options$debugA7 = table.options.debugAll) != null ? _table$options$debugA7 : table.options.debugHeaders;
|
|
21952
|
+
}
|
|
21953
|
+
}),
|
|
21954
|
+
getRightFooterGroups: memo(() => [table.getRightHeaderGroups()], headerGroups => {
|
|
21955
|
+
return [...headerGroups].reverse();
|
|
21956
|
+
}, {
|
|
21957
|
+
key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
|
|
21958
|
+
debug: () => {
|
|
21959
|
+
var _table$options$debugA8;
|
|
21960
|
+
return (_table$options$debugA8 = table.options.debugAll) != null ? _table$options$debugA8 : table.options.debugHeaders;
|
|
21961
|
+
}
|
|
21962
|
+
}),
|
|
21963
|
+
// Flat Headers
|
|
21964
|
+
|
|
21965
|
+
getFlatHeaders: memo(() => [table.getHeaderGroups()], headerGroups => {
|
|
21966
|
+
return headerGroups.map(headerGroup => {
|
|
21967
|
+
return headerGroup.headers;
|
|
21968
|
+
}).flat();
|
|
21969
|
+
}, {
|
|
21970
|
+
key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
|
|
21971
|
+
debug: () => {
|
|
21972
|
+
var _table$options$debugA9;
|
|
21973
|
+
return (_table$options$debugA9 = table.options.debugAll) != null ? _table$options$debugA9 : table.options.debugHeaders;
|
|
21974
|
+
}
|
|
21975
|
+
}),
|
|
21976
|
+
getLeftFlatHeaders: memo(() => [table.getLeftHeaderGroups()], left => {
|
|
21977
|
+
return left.map(headerGroup => {
|
|
21978
|
+
return headerGroup.headers;
|
|
21979
|
+
}).flat();
|
|
21980
|
+
}, {
|
|
21981
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
|
|
21982
|
+
debug: () => {
|
|
21983
|
+
var _table$options$debugA10;
|
|
21984
|
+
return (_table$options$debugA10 = table.options.debugAll) != null ? _table$options$debugA10 : table.options.debugHeaders;
|
|
21985
|
+
}
|
|
21986
|
+
}),
|
|
21987
|
+
getCenterFlatHeaders: memo(() => [table.getCenterHeaderGroups()], left => {
|
|
21988
|
+
return left.map(headerGroup => {
|
|
21989
|
+
return headerGroup.headers;
|
|
21990
|
+
}).flat();
|
|
21991
|
+
}, {
|
|
21992
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
|
|
21993
|
+
debug: () => {
|
|
21994
|
+
var _table$options$debugA11;
|
|
21995
|
+
return (_table$options$debugA11 = table.options.debugAll) != null ? _table$options$debugA11 : table.options.debugHeaders;
|
|
21996
|
+
}
|
|
21997
|
+
}),
|
|
21998
|
+
getRightFlatHeaders: memo(() => [table.getRightHeaderGroups()], left => {
|
|
21999
|
+
return left.map(headerGroup => {
|
|
22000
|
+
return headerGroup.headers;
|
|
22001
|
+
}).flat();
|
|
22002
|
+
}, {
|
|
22003
|
+
key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
|
|
22004
|
+
debug: () => {
|
|
22005
|
+
var _table$options$debugA12;
|
|
22006
|
+
return (_table$options$debugA12 = table.options.debugAll) != null ? _table$options$debugA12 : table.options.debugHeaders;
|
|
22007
|
+
}
|
|
22008
|
+
}),
|
|
22009
|
+
// Leaf Headers
|
|
22010
|
+
|
|
22011
|
+
getCenterLeafHeaders: memo(() => [table.getCenterFlatHeaders()], flatHeaders => {
|
|
22012
|
+
return flatHeaders.filter(header => {
|
|
22013
|
+
var _header$subHeaders;
|
|
22014
|
+
return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
|
|
22015
|
+
});
|
|
22016
|
+
}, {
|
|
22017
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
|
|
22018
|
+
debug: () => {
|
|
22019
|
+
var _table$options$debugA13;
|
|
22020
|
+
return (_table$options$debugA13 = table.options.debugAll) != null ? _table$options$debugA13 : table.options.debugHeaders;
|
|
22021
|
+
}
|
|
22022
|
+
}),
|
|
22023
|
+
getLeftLeafHeaders: memo(() => [table.getLeftFlatHeaders()], flatHeaders => {
|
|
22024
|
+
return flatHeaders.filter(header => {
|
|
22025
|
+
var _header$subHeaders2;
|
|
22026
|
+
return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
|
|
22027
|
+
});
|
|
22028
|
+
}, {
|
|
22029
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
|
|
22030
|
+
debug: () => {
|
|
22031
|
+
var _table$options$debugA14;
|
|
22032
|
+
return (_table$options$debugA14 = table.options.debugAll) != null ? _table$options$debugA14 : table.options.debugHeaders;
|
|
22033
|
+
}
|
|
22034
|
+
}),
|
|
22035
|
+
getRightLeafHeaders: memo(() => [table.getRightFlatHeaders()], flatHeaders => {
|
|
22036
|
+
return flatHeaders.filter(header => {
|
|
22037
|
+
var _header$subHeaders3;
|
|
22038
|
+
return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
|
|
22039
|
+
});
|
|
22040
|
+
}, {
|
|
22041
|
+
key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
|
|
22042
|
+
debug: () => {
|
|
22043
|
+
var _table$options$debugA15;
|
|
22044
|
+
return (_table$options$debugA15 = table.options.debugAll) != null ? _table$options$debugA15 : table.options.debugHeaders;
|
|
22045
|
+
}
|
|
22046
|
+
}),
|
|
22047
|
+
getLeafHeaders: memo(() => [table.getLeftHeaderGroups(), table.getCenterHeaderGroups(), table.getRightHeaderGroups()], (left, center, right) => {
|
|
22048
|
+
var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
|
|
22049
|
+
return [...((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : []), ...((_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : []), ...((_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : [])].map(header => {
|
|
22050
|
+
return header.getLeafHeaders();
|
|
22051
|
+
}).flat();
|
|
22052
|
+
}, {
|
|
22053
|
+
key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
|
|
22054
|
+
debug: () => {
|
|
22055
|
+
var _table$options$debugA16;
|
|
22056
|
+
return (_table$options$debugA16 = table.options.debugAll) != null ? _table$options$debugA16 : table.options.debugHeaders;
|
|
22057
|
+
}
|
|
22058
|
+
})
|
|
22059
|
+
};
|
|
22060
|
+
}
|
|
22061
|
+
};
|
|
22062
|
+
function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
|
|
22063
|
+
var _headerGroups$0$heade, _headerGroups$;
|
|
22064
|
+
// Find the max depth of the columns:
|
|
22065
|
+
// build the leaf column row
|
|
22066
|
+
// build each buffer row going up
|
|
22067
|
+
// placeholder for non-existent level
|
|
22068
|
+
// real column for existing level
|
|
22069
|
+
|
|
22070
|
+
let maxDepth = 0;
|
|
22071
|
+
const findMaxDepth = function (columns, depth) {
|
|
22072
|
+
if (depth === void 0) {
|
|
22073
|
+
depth = 1;
|
|
22074
|
+
}
|
|
22075
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
22076
|
+
columns.filter(column => column.getIsVisible()).forEach(column => {
|
|
22077
|
+
var _column$columns;
|
|
22078
|
+
if ((_column$columns = column.columns) != null && _column$columns.length) {
|
|
22079
|
+
findMaxDepth(column.columns, depth + 1);
|
|
22080
|
+
}
|
|
22081
|
+
}, 0);
|
|
22082
|
+
};
|
|
22083
|
+
findMaxDepth(allColumns);
|
|
22084
|
+
let headerGroups = [];
|
|
22085
|
+
const createHeaderGroup = (headersToGroup, depth) => {
|
|
22086
|
+
// The header group we are creating
|
|
22087
|
+
const headerGroup = {
|
|
22088
|
+
depth,
|
|
22089
|
+
id: [headerFamily, `${depth}`].filter(Boolean).join('_'),
|
|
22090
|
+
headers: []
|
|
22091
|
+
};
|
|
22092
|
+
|
|
22093
|
+
// The parent columns we're going to scan next
|
|
22094
|
+
const pendingParentHeaders = [];
|
|
22095
|
+
|
|
22096
|
+
// Scan each column for parents
|
|
22097
|
+
headersToGroup.forEach(headerToGroup => {
|
|
22098
|
+
// What is the latest (last) parent column?
|
|
22099
|
+
|
|
22100
|
+
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
|
|
22101
|
+
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
|
|
22102
|
+
let column;
|
|
22103
|
+
let isPlaceholder = false;
|
|
22104
|
+
if (isLeafHeader && headerToGroup.column.parent) {
|
|
22105
|
+
// The parent header is new
|
|
22106
|
+
column = headerToGroup.column.parent;
|
|
22107
|
+
} else {
|
|
22108
|
+
// The parent header is repeated
|
|
22109
|
+
column = headerToGroup.column;
|
|
22110
|
+
isPlaceholder = true;
|
|
22111
|
+
}
|
|
22112
|
+
if (latestPendingParentHeader && (latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
|
|
22113
|
+
// This column is repeated. Add it as a sub header to the next batch
|
|
22114
|
+
latestPendingParentHeader.subHeaders.push(headerToGroup);
|
|
22115
|
+
} else {
|
|
22116
|
+
// This is a new header. Let's create it
|
|
22117
|
+
const header = createHeader(table, column, {
|
|
22118
|
+
id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
|
|
22119
|
+
isPlaceholder,
|
|
22120
|
+
placeholderId: isPlaceholder ? `${pendingParentHeaders.filter(d => d.column === column).length}` : undefined,
|
|
22121
|
+
depth,
|
|
22122
|
+
index: pendingParentHeaders.length
|
|
22123
|
+
});
|
|
22124
|
+
|
|
22125
|
+
// Add the headerToGroup as a subHeader of the new header
|
|
22126
|
+
header.subHeaders.push(headerToGroup);
|
|
22127
|
+
// Add the new header to the pendingParentHeaders to get grouped
|
|
22128
|
+
// in the next batch
|
|
22129
|
+
pendingParentHeaders.push(header);
|
|
22130
|
+
}
|
|
22131
|
+
headerGroup.headers.push(headerToGroup);
|
|
22132
|
+
headerToGroup.headerGroup = headerGroup;
|
|
22133
|
+
});
|
|
22134
|
+
headerGroups.push(headerGroup);
|
|
22135
|
+
if (depth > 0) {
|
|
22136
|
+
createHeaderGroup(pendingParentHeaders, depth - 1);
|
|
22137
|
+
}
|
|
22138
|
+
};
|
|
22139
|
+
const bottomHeaders = columnsToGroup.map((column, index) => createHeader(table, column, {
|
|
22140
|
+
depth: maxDepth,
|
|
22141
|
+
index
|
|
22142
|
+
}));
|
|
22143
|
+
createHeaderGroup(bottomHeaders, maxDepth - 1);
|
|
22144
|
+
headerGroups.reverse();
|
|
22145
|
+
|
|
22146
|
+
// headerGroups = headerGroups.filter(headerGroup => {
|
|
22147
|
+
// return !headerGroup.headers.every(header => header.isPlaceholder)
|
|
22148
|
+
// })
|
|
22149
|
+
|
|
22150
|
+
const recurseHeadersForSpans = headers => {
|
|
22151
|
+
const filteredHeaders = headers.filter(header => header.column.getIsVisible());
|
|
22152
|
+
return filteredHeaders.map(header => {
|
|
22153
|
+
let colSpan = 0;
|
|
22154
|
+
let rowSpan = 0;
|
|
22155
|
+
let childRowSpans = [0];
|
|
22156
|
+
if (header.subHeaders && header.subHeaders.length) {
|
|
22157
|
+
childRowSpans = [];
|
|
22158
|
+
recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
|
|
22159
|
+
let {
|
|
22160
|
+
colSpan: childColSpan,
|
|
22161
|
+
rowSpan: childRowSpan
|
|
22162
|
+
} = _ref;
|
|
22163
|
+
colSpan += childColSpan;
|
|
22164
|
+
childRowSpans.push(childRowSpan);
|
|
22165
|
+
});
|
|
22166
|
+
} else {
|
|
22167
|
+
colSpan = 1;
|
|
22168
|
+
}
|
|
22169
|
+
const minChildRowSpan = Math.min(...childRowSpans);
|
|
22170
|
+
rowSpan = rowSpan + minChildRowSpan;
|
|
22171
|
+
header.colSpan = colSpan;
|
|
22172
|
+
header.rowSpan = rowSpan;
|
|
22173
|
+
return {
|
|
22174
|
+
colSpan,
|
|
22175
|
+
rowSpan
|
|
22176
|
+
};
|
|
22177
|
+
});
|
|
22178
|
+
};
|
|
22179
|
+
recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
|
|
22180
|
+
return headerGroups;
|
|
22181
|
+
}
|
|
22182
|
+
|
|
22183
|
+
//
|
|
22184
|
+
|
|
22185
|
+
const defaultColumnSizing = {
|
|
22186
|
+
size: 150,
|
|
22187
|
+
minSize: 20,
|
|
22188
|
+
maxSize: Number.MAX_SAFE_INTEGER
|
|
22189
|
+
};
|
|
22190
|
+
const getDefaultColumnSizingInfoState = () => ({
|
|
22191
|
+
startOffset: null,
|
|
22192
|
+
startSize: null,
|
|
22193
|
+
deltaOffset: null,
|
|
22194
|
+
deltaPercentage: null,
|
|
22195
|
+
isResizingColumn: false,
|
|
22196
|
+
columnSizingStart: []
|
|
22197
|
+
});
|
|
22198
|
+
const ColumnSizing = {
|
|
22199
|
+
getDefaultColumnDef: () => {
|
|
22200
|
+
return defaultColumnSizing;
|
|
22201
|
+
},
|
|
22202
|
+
getInitialState: state => {
|
|
22203
|
+
return {
|
|
22204
|
+
columnSizing: {},
|
|
22205
|
+
columnSizingInfo: getDefaultColumnSizingInfoState(),
|
|
22206
|
+
...state
|
|
22207
|
+
};
|
|
22208
|
+
},
|
|
22209
|
+
getDefaultOptions: table => {
|
|
22210
|
+
return {
|
|
22211
|
+
columnResizeMode: 'onEnd',
|
|
22212
|
+
onColumnSizingChange: makeStateUpdater('columnSizing', table),
|
|
22213
|
+
onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table)
|
|
22214
|
+
};
|
|
22215
|
+
},
|
|
22216
|
+
createColumn: (column, table) => {
|
|
22217
|
+
return {
|
|
22218
|
+
getSize: () => {
|
|
22219
|
+
var _column$columnDef$min, _ref, _column$columnDef$max;
|
|
22220
|
+
const columnSize = table.getState().columnSizing[column.id];
|
|
22221
|
+
return Math.min(Math.max((_column$columnDef$min = column.columnDef.minSize) != null ? _column$columnDef$min : defaultColumnSizing.minSize, (_ref = columnSize != null ? columnSize : column.columnDef.size) != null ? _ref : defaultColumnSizing.size), (_column$columnDef$max = column.columnDef.maxSize) != null ? _column$columnDef$max : defaultColumnSizing.maxSize);
|
|
22222
|
+
},
|
|
22223
|
+
getStart: position => {
|
|
22224
|
+
const columns = !position ? table.getVisibleLeafColumns() : position === 'left' ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
|
|
22225
|
+
const index = columns.findIndex(d => d.id === column.id);
|
|
22226
|
+
if (index > 0) {
|
|
22227
|
+
const prevSiblingColumn = columns[index - 1];
|
|
22228
|
+
return prevSiblingColumn.getStart(position) + prevSiblingColumn.getSize();
|
|
22229
|
+
}
|
|
22230
|
+
return 0;
|
|
22231
|
+
},
|
|
22232
|
+
resetSize: () => {
|
|
22233
|
+
table.setColumnSizing(_ref2 => {
|
|
22234
|
+
let {
|
|
22235
|
+
[column.id]: _,
|
|
22236
|
+
...rest
|
|
22237
|
+
} = _ref2;
|
|
22238
|
+
return rest;
|
|
22239
|
+
});
|
|
22240
|
+
},
|
|
22241
|
+
getCanResize: () => {
|
|
22242
|
+
var _column$columnDef$ena, _table$options$enable;
|
|
22243
|
+
return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnResizing) != null ? _table$options$enable : true);
|
|
22244
|
+
},
|
|
22245
|
+
getIsResizing: () => {
|
|
22246
|
+
return table.getState().columnSizingInfo.isResizingColumn === column.id;
|
|
22247
|
+
}
|
|
22248
|
+
};
|
|
22249
|
+
},
|
|
22250
|
+
createHeader: (header, table) => {
|
|
22251
|
+
return {
|
|
22252
|
+
getSize: () => {
|
|
22253
|
+
let sum = 0;
|
|
22254
|
+
const recurse = header => {
|
|
22255
|
+
if (header.subHeaders.length) {
|
|
22256
|
+
header.subHeaders.forEach(recurse);
|
|
22257
|
+
} else {
|
|
22258
|
+
var _header$column$getSiz;
|
|
22259
|
+
sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
|
|
22260
|
+
}
|
|
22261
|
+
};
|
|
22262
|
+
recurse(header);
|
|
22263
|
+
return sum;
|
|
22264
|
+
},
|
|
22265
|
+
getStart: () => {
|
|
22266
|
+
if (header.index > 0) {
|
|
22267
|
+
const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
|
|
22268
|
+
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
|
|
22269
|
+
}
|
|
22270
|
+
return 0;
|
|
22271
|
+
},
|
|
22272
|
+
getResizeHandler: () => {
|
|
22273
|
+
const column = table.getColumn(header.column.id);
|
|
22274
|
+
const canResize = column.getCanResize();
|
|
22275
|
+
return e => {
|
|
22276
|
+
if (!canResize) {
|
|
22277
|
+
return;
|
|
22278
|
+
}
|
|
22279
|
+
e.persist == null ? void 0 : e.persist();
|
|
22280
|
+
if (isTouchStartEvent(e)) {
|
|
22281
|
+
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
22282
|
+
if (e.touches && e.touches.length > 1) {
|
|
22283
|
+
return;
|
|
22284
|
+
}
|
|
22285
|
+
}
|
|
22286
|
+
const startSize = header.getSize();
|
|
22287
|
+
const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
|
|
22288
|
+
const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
|
|
22289
|
+
const updateOffset = (eventType, clientXPos) => {
|
|
22290
|
+
if (typeof clientXPos !== 'number') {
|
|
22291
|
+
return;
|
|
22292
|
+
}
|
|
22293
|
+
let newColumnSizing = {};
|
|
22294
|
+
table.setColumnSizingInfo(old => {
|
|
22295
|
+
var _old$startOffset, _old$startSize;
|
|
22296
|
+
const deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
|
|
22297
|
+
const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
|
|
22298
|
+
old.columnSizingStart.forEach(_ref3 => {
|
|
22299
|
+
let [columnId, headerSize] = _ref3;
|
|
22300
|
+
newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
|
|
22301
|
+
});
|
|
22302
|
+
return {
|
|
22303
|
+
...old,
|
|
22304
|
+
deltaOffset,
|
|
22305
|
+
deltaPercentage
|
|
22306
|
+
};
|
|
22307
|
+
});
|
|
22308
|
+
if (table.options.columnResizeMode === 'onChange' || eventType === 'end') {
|
|
22309
|
+
table.setColumnSizing(old => ({
|
|
22310
|
+
...old,
|
|
22311
|
+
...newColumnSizing
|
|
22312
|
+
}));
|
|
22313
|
+
}
|
|
22314
|
+
};
|
|
22315
|
+
const onMove = clientXPos => updateOffset('move', clientXPos);
|
|
22316
|
+
const onEnd = clientXPos => {
|
|
22317
|
+
updateOffset('end', clientXPos);
|
|
22318
|
+
table.setColumnSizingInfo(old => ({
|
|
22319
|
+
...old,
|
|
22320
|
+
isResizingColumn: false,
|
|
22321
|
+
startOffset: null,
|
|
22322
|
+
startSize: null,
|
|
22323
|
+
deltaOffset: null,
|
|
22324
|
+
deltaPercentage: null,
|
|
22325
|
+
columnSizingStart: []
|
|
22326
|
+
}));
|
|
22327
|
+
};
|
|
22328
|
+
const mouseEvents = {
|
|
22329
|
+
moveHandler: e => onMove(e.clientX),
|
|
22330
|
+
upHandler: e => {
|
|
22331
|
+
document.removeEventListener('mousemove', mouseEvents.moveHandler);
|
|
22332
|
+
document.removeEventListener('mouseup', mouseEvents.upHandler);
|
|
22333
|
+
onEnd(e.clientX);
|
|
22334
|
+
}
|
|
22335
|
+
};
|
|
22336
|
+
const touchEvents = {
|
|
22337
|
+
moveHandler: e => {
|
|
22338
|
+
if (e.cancelable) {
|
|
22339
|
+
e.preventDefault();
|
|
22340
|
+
e.stopPropagation();
|
|
22341
|
+
}
|
|
22342
|
+
onMove(e.touches[0].clientX);
|
|
22343
|
+
return false;
|
|
22344
|
+
},
|
|
22345
|
+
upHandler: e => {
|
|
22346
|
+
var _e$touches$;
|
|
22347
|
+
document.removeEventListener('touchmove', touchEvents.moveHandler);
|
|
22348
|
+
document.removeEventListener('touchend', touchEvents.upHandler);
|
|
22349
|
+
if (e.cancelable) {
|
|
22350
|
+
e.preventDefault();
|
|
22351
|
+
e.stopPropagation();
|
|
22352
|
+
}
|
|
22353
|
+
onEnd((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.clientX);
|
|
22354
|
+
}
|
|
22355
|
+
};
|
|
22356
|
+
const passiveIfSupported = passiveEventSupported() ? {
|
|
22357
|
+
passive: false
|
|
22358
|
+
} : false;
|
|
22359
|
+
if (isTouchStartEvent(e)) {
|
|
22360
|
+
document.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
|
|
22361
|
+
document.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
|
|
22362
|
+
} else {
|
|
22363
|
+
document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
|
|
22364
|
+
document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
|
|
22365
|
+
}
|
|
22366
|
+
table.setColumnSizingInfo(old => ({
|
|
22367
|
+
...old,
|
|
22368
|
+
startOffset: clientX,
|
|
22369
|
+
startSize,
|
|
22370
|
+
deltaOffset: 0,
|
|
22371
|
+
deltaPercentage: 0,
|
|
22372
|
+
columnSizingStart,
|
|
22373
|
+
isResizingColumn: column.id
|
|
22374
|
+
}));
|
|
22375
|
+
};
|
|
22376
|
+
}
|
|
22377
|
+
};
|
|
22378
|
+
},
|
|
22379
|
+
createTable: table => {
|
|
22380
|
+
return {
|
|
22381
|
+
setColumnSizing: updater => table.options.onColumnSizingChange == null ? void 0 : table.options.onColumnSizingChange(updater),
|
|
22382
|
+
setColumnSizingInfo: updater => table.options.onColumnSizingInfoChange == null ? void 0 : table.options.onColumnSizingInfoChange(updater),
|
|
22383
|
+
resetColumnSizing: defaultState => {
|
|
22384
|
+
var _table$initialState$c;
|
|
22385
|
+
table.setColumnSizing(defaultState ? {} : (_table$initialState$c = table.initialState.columnSizing) != null ? _table$initialState$c : {});
|
|
22386
|
+
},
|
|
22387
|
+
resetHeaderSizeInfo: defaultState => {
|
|
22388
|
+
var _table$initialState$c2;
|
|
22389
|
+
table.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_table$initialState$c2 = table.initialState.columnSizingInfo) != null ? _table$initialState$c2 : getDefaultColumnSizingInfoState());
|
|
22390
|
+
},
|
|
22391
|
+
getTotalSize: () => {
|
|
22392
|
+
var _table$getHeaderGroup, _table$getHeaderGroup2;
|
|
22393
|
+
return (_table$getHeaderGroup = (_table$getHeaderGroup2 = table.getHeaderGroups()[0]) == null ? void 0 : _table$getHeaderGroup2.headers.reduce((sum, header) => {
|
|
22394
|
+
return sum + header.getSize();
|
|
22395
|
+
}, 0)) != null ? _table$getHeaderGroup : 0;
|
|
22396
|
+
},
|
|
22397
|
+
getLeftTotalSize: () => {
|
|
22398
|
+
var _table$getLeftHeaderG, _table$getLeftHeaderG2;
|
|
22399
|
+
return (_table$getLeftHeaderG = (_table$getLeftHeaderG2 = table.getLeftHeaderGroups()[0]) == null ? void 0 : _table$getLeftHeaderG2.headers.reduce((sum, header) => {
|
|
22400
|
+
return sum + header.getSize();
|
|
22401
|
+
}, 0)) != null ? _table$getLeftHeaderG : 0;
|
|
22402
|
+
},
|
|
22403
|
+
getCenterTotalSize: () => {
|
|
22404
|
+
var _table$getCenterHeade, _table$getCenterHeade2;
|
|
22405
|
+
return (_table$getCenterHeade = (_table$getCenterHeade2 = table.getCenterHeaderGroups()[0]) == null ? void 0 : _table$getCenterHeade2.headers.reduce((sum, header) => {
|
|
22406
|
+
return sum + header.getSize();
|
|
22407
|
+
}, 0)) != null ? _table$getCenterHeade : 0;
|
|
22408
|
+
},
|
|
22409
|
+
getRightTotalSize: () => {
|
|
22410
|
+
var _table$getRightHeader, _table$getRightHeader2;
|
|
22411
|
+
return (_table$getRightHeader = (_table$getRightHeader2 = table.getRightHeaderGroups()[0]) == null ? void 0 : _table$getRightHeader2.headers.reduce((sum, header) => {
|
|
22412
|
+
return sum + header.getSize();
|
|
22413
|
+
}, 0)) != null ? _table$getRightHeader : 0;
|
|
22414
|
+
}
|
|
22415
|
+
};
|
|
22416
|
+
}
|
|
22417
|
+
};
|
|
22418
|
+
let passiveSupported = null;
|
|
22419
|
+
function passiveEventSupported() {
|
|
22420
|
+
if (typeof passiveSupported === 'boolean') return passiveSupported;
|
|
22421
|
+
let supported = false;
|
|
22422
|
+
try {
|
|
22423
|
+
const options = {
|
|
22424
|
+
get passive() {
|
|
22425
|
+
supported = true;
|
|
22426
|
+
return false;
|
|
22427
|
+
}
|
|
22428
|
+
};
|
|
22429
|
+
const noop = () => {};
|
|
22430
|
+
window.addEventListener('test', noop, options);
|
|
22431
|
+
window.removeEventListener('test', noop);
|
|
22432
|
+
} catch (err) {
|
|
22433
|
+
supported = false;
|
|
22434
|
+
}
|
|
22435
|
+
passiveSupported = supported;
|
|
22436
|
+
return passiveSupported;
|
|
22437
|
+
}
|
|
22438
|
+
function isTouchStartEvent(e) {
|
|
22439
|
+
return e.type === 'touchstart';
|
|
22440
|
+
}
|
|
22441
|
+
|
|
22442
|
+
//
|
|
22443
|
+
|
|
22444
|
+
const Expanding = {
|
|
22445
|
+
getInitialState: state => {
|
|
22446
|
+
return {
|
|
22447
|
+
expanded: {},
|
|
22448
|
+
...state
|
|
22449
|
+
};
|
|
22450
|
+
},
|
|
22451
|
+
getDefaultOptions: table => {
|
|
22452
|
+
return {
|
|
22453
|
+
onExpandedChange: makeStateUpdater('expanded', table),
|
|
22454
|
+
paginateExpandedRows: true
|
|
22455
|
+
};
|
|
22456
|
+
},
|
|
22457
|
+
createTable: table => {
|
|
22458
|
+
let registered = false;
|
|
22459
|
+
let queued = false;
|
|
22460
|
+
return {
|
|
22461
|
+
_autoResetExpanded: () => {
|
|
22462
|
+
var _ref, _table$options$autoRe;
|
|
22463
|
+
if (!registered) {
|
|
22464
|
+
table._queue(() => {
|
|
22465
|
+
registered = true;
|
|
22466
|
+
});
|
|
22467
|
+
return;
|
|
22468
|
+
}
|
|
22469
|
+
if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetExpanded) != null ? _ref : !table.options.manualExpanding) {
|
|
22470
|
+
if (queued) return;
|
|
22471
|
+
queued = true;
|
|
22472
|
+
table._queue(() => {
|
|
22473
|
+
table.resetExpanded();
|
|
22474
|
+
queued = false;
|
|
22475
|
+
});
|
|
22476
|
+
}
|
|
22477
|
+
},
|
|
22478
|
+
setExpanded: updater => table.options.onExpandedChange == null ? void 0 : table.options.onExpandedChange(updater),
|
|
22479
|
+
toggleAllRowsExpanded: expanded => {
|
|
22480
|
+
if (expanded != null ? expanded : !table.getIsAllRowsExpanded()) {
|
|
22481
|
+
table.setExpanded(true);
|
|
22482
|
+
} else {
|
|
22483
|
+
table.setExpanded({});
|
|
22484
|
+
}
|
|
22485
|
+
},
|
|
22486
|
+
resetExpanded: defaultState => {
|
|
22487
|
+
var _table$initialState$e, _table$initialState;
|
|
22488
|
+
table.setExpanded(defaultState ? {} : (_table$initialState$e = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.expanded) != null ? _table$initialState$e : {});
|
|
22489
|
+
},
|
|
22490
|
+
getCanSomeRowsExpand: () => {
|
|
22491
|
+
return table.getRowModel().flatRows.some(row => row.getCanExpand());
|
|
22492
|
+
},
|
|
22493
|
+
getToggleAllRowsExpandedHandler: () => {
|
|
22494
|
+
return e => {
|
|
22495
|
+
e.persist == null ? void 0 : e.persist();
|
|
22496
|
+
table.toggleAllRowsExpanded();
|
|
22497
|
+
};
|
|
22498
|
+
},
|
|
22499
|
+
getIsSomeRowsExpanded: () => {
|
|
22500
|
+
const expanded = table.getState().expanded;
|
|
22501
|
+
return expanded === true || Object.values(expanded).some(Boolean);
|
|
22502
|
+
},
|
|
22503
|
+
getIsAllRowsExpanded: () => {
|
|
22504
|
+
const expanded = table.getState().expanded;
|
|
22505
|
+
|
|
22506
|
+
// If expanded is true, save some cycles and return true
|
|
22507
|
+
if (typeof expanded === 'boolean') {
|
|
22508
|
+
return expanded === true;
|
|
22509
|
+
}
|
|
22510
|
+
if (!Object.keys(expanded).length) {
|
|
22511
|
+
return false;
|
|
22512
|
+
}
|
|
22513
|
+
|
|
22514
|
+
// If any row is not expanded, return false
|
|
22515
|
+
if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
|
|
22516
|
+
return false;
|
|
22517
|
+
}
|
|
22518
|
+
|
|
22519
|
+
// They must all be expanded :shrug:
|
|
22520
|
+
return true;
|
|
22521
|
+
},
|
|
22522
|
+
getExpandedDepth: () => {
|
|
22523
|
+
let maxDepth = 0;
|
|
22524
|
+
const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
|
|
22525
|
+
rowIds.forEach(id => {
|
|
22526
|
+
const splitId = id.split('.');
|
|
22527
|
+
maxDepth = Math.max(maxDepth, splitId.length);
|
|
22528
|
+
});
|
|
22529
|
+
return maxDepth;
|
|
22530
|
+
},
|
|
22531
|
+
getPreExpandedRowModel: () => table.getSortedRowModel(),
|
|
22532
|
+
getExpandedRowModel: () => {
|
|
22533
|
+
if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
|
|
22534
|
+
table._getExpandedRowModel = table.options.getExpandedRowModel(table);
|
|
22535
|
+
}
|
|
22536
|
+
if (table.options.manualExpanding || !table._getExpandedRowModel) {
|
|
22537
|
+
return table.getPreExpandedRowModel();
|
|
22538
|
+
}
|
|
22539
|
+
return table._getExpandedRowModel();
|
|
22540
|
+
}
|
|
22541
|
+
};
|
|
22542
|
+
},
|
|
22543
|
+
createRow: (row, table) => {
|
|
22544
|
+
return {
|
|
22545
|
+
toggleExpanded: expanded => {
|
|
22546
|
+
table.setExpanded(old => {
|
|
22547
|
+
var _expanded;
|
|
22548
|
+
const exists = old === true ? true : !!(old != null && old[row.id]);
|
|
22549
|
+
let oldExpanded = {};
|
|
22550
|
+
if (old === true) {
|
|
22551
|
+
Object.keys(table.getRowModel().rowsById).forEach(rowId => {
|
|
22552
|
+
oldExpanded[rowId] = true;
|
|
22553
|
+
});
|
|
22554
|
+
} else {
|
|
22555
|
+
oldExpanded = old;
|
|
22556
|
+
}
|
|
22557
|
+
expanded = (_expanded = expanded) != null ? _expanded : !exists;
|
|
22558
|
+
if (!exists && expanded) {
|
|
22559
|
+
return {
|
|
22560
|
+
...oldExpanded,
|
|
22561
|
+
[row.id]: true
|
|
22562
|
+
};
|
|
22563
|
+
}
|
|
22564
|
+
if (exists && !expanded) {
|
|
22565
|
+
const {
|
|
22566
|
+
[row.id]: _,
|
|
22567
|
+
...rest
|
|
22568
|
+
} = oldExpanded;
|
|
22569
|
+
return rest;
|
|
22570
|
+
}
|
|
22571
|
+
return old;
|
|
22572
|
+
});
|
|
22573
|
+
},
|
|
22574
|
+
getIsExpanded: () => {
|
|
22575
|
+
var _table$options$getIsR;
|
|
22576
|
+
const expanded = table.getState().expanded;
|
|
22577
|
+
return !!((_table$options$getIsR = table.options.getIsRowExpanded == null ? void 0 : table.options.getIsRowExpanded(row)) != null ? _table$options$getIsR : expanded === true || (expanded == null ? void 0 : expanded[row.id]));
|
|
22578
|
+
},
|
|
22579
|
+
getCanExpand: () => {
|
|
22580
|
+
var _table$options$getRow, _table$options$enable, _row$subRows;
|
|
22581
|
+
return (_table$options$getRow = table.options.getRowCanExpand == null ? void 0 : table.options.getRowCanExpand(row)) != null ? _table$options$getRow : ((_table$options$enable = table.options.enableExpanding) != null ? _table$options$enable : true) && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
|
|
22582
|
+
},
|
|
22583
|
+
getToggleExpandedHandler: () => {
|
|
22584
|
+
const canExpand = row.getCanExpand();
|
|
22585
|
+
return () => {
|
|
22586
|
+
if (!canExpand) return;
|
|
22587
|
+
row.toggleExpanded();
|
|
22588
|
+
};
|
|
22589
|
+
}
|
|
22590
|
+
};
|
|
22591
|
+
}
|
|
22592
|
+
};
|
|
22593
|
+
|
|
22594
|
+
const includesString = (row, columnId, filterValue) => {
|
|
22595
|
+
var _row$getValue;
|
|
22596
|
+
const search = filterValue.toLowerCase();
|
|
22597
|
+
return Boolean((_row$getValue = row.getValue(columnId)) == null ? void 0 : _row$getValue.toLowerCase().includes(search));
|
|
22598
|
+
};
|
|
22599
|
+
includesString.autoRemove = val => testFalsey(val);
|
|
22600
|
+
const includesStringSensitive = (row, columnId, filterValue) => {
|
|
22601
|
+
var _row$getValue2;
|
|
22602
|
+
return Boolean((_row$getValue2 = row.getValue(columnId)) == null ? void 0 : _row$getValue2.includes(filterValue));
|
|
22603
|
+
};
|
|
22604
|
+
includesStringSensitive.autoRemove = val => testFalsey(val);
|
|
22605
|
+
const equalsString = (row, columnId, filterValue) => {
|
|
22606
|
+
var _row$getValue3;
|
|
22607
|
+
return ((_row$getValue3 = row.getValue(columnId)) == null ? void 0 : _row$getValue3.toLowerCase()) === filterValue.toLowerCase();
|
|
22608
|
+
};
|
|
22609
|
+
equalsString.autoRemove = val => testFalsey(val);
|
|
22610
|
+
const arrIncludes = (row, columnId, filterValue) => {
|
|
22611
|
+
var _row$getValue4;
|
|
22612
|
+
return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
|
|
22613
|
+
};
|
|
22614
|
+
arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
22615
|
+
const arrIncludesAll = (row, columnId, filterValue) => {
|
|
22616
|
+
return !filterValue.some(val => {
|
|
22617
|
+
var _row$getValue5;
|
|
22618
|
+
return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
|
|
22619
|
+
});
|
|
22620
|
+
};
|
|
22621
|
+
arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
22622
|
+
const arrIncludesSome = (row, columnId, filterValue) => {
|
|
22623
|
+
return filterValue.some(val => {
|
|
22624
|
+
var _row$getValue6;
|
|
22625
|
+
return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
|
|
22626
|
+
});
|
|
22627
|
+
};
|
|
22628
|
+
arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
22629
|
+
const equals = (row, columnId, filterValue) => {
|
|
22630
|
+
return row.getValue(columnId) === filterValue;
|
|
22631
|
+
};
|
|
22632
|
+
equals.autoRemove = val => testFalsey(val);
|
|
22633
|
+
const weakEquals = (row, columnId, filterValue) => {
|
|
22634
|
+
return row.getValue(columnId) == filterValue;
|
|
22635
|
+
};
|
|
22636
|
+
weakEquals.autoRemove = val => testFalsey(val);
|
|
22637
|
+
const inNumberRange = (row, columnId, filterValue) => {
|
|
22638
|
+
let [min, max] = filterValue;
|
|
22639
|
+
const rowValue = row.getValue(columnId);
|
|
22640
|
+
return rowValue >= min && rowValue <= max;
|
|
22641
|
+
};
|
|
22642
|
+
inNumberRange.resolveFilterValue = val => {
|
|
22643
|
+
let [unsafeMin, unsafeMax] = val;
|
|
22644
|
+
let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
|
|
22645
|
+
let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
|
|
22646
|
+
let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
|
|
22647
|
+
let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
|
|
22648
|
+
if (min > max) {
|
|
22649
|
+
const temp = min;
|
|
22650
|
+
min = max;
|
|
22651
|
+
max = temp;
|
|
22652
|
+
}
|
|
22653
|
+
return [min, max];
|
|
22654
|
+
};
|
|
22655
|
+
inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
|
|
22656
|
+
|
|
22657
|
+
// Export
|
|
22658
|
+
|
|
22659
|
+
const filterFns = {
|
|
22660
|
+
includesString,
|
|
22661
|
+
includesStringSensitive,
|
|
22662
|
+
equalsString,
|
|
22663
|
+
arrIncludes,
|
|
22664
|
+
arrIncludesAll,
|
|
22665
|
+
arrIncludesSome,
|
|
22666
|
+
equals,
|
|
22667
|
+
weakEquals,
|
|
22668
|
+
inNumberRange
|
|
22669
|
+
};
|
|
22670
|
+
// Utils
|
|
22671
|
+
|
|
22672
|
+
function testFalsey(val) {
|
|
22673
|
+
return val === undefined || val === null || val === '';
|
|
22674
|
+
}
|
|
22675
|
+
|
|
22676
|
+
//
|
|
22677
|
+
|
|
22678
|
+
const Filters = {
|
|
22679
|
+
getDefaultColumnDef: () => {
|
|
22680
|
+
return {
|
|
22681
|
+
filterFn: 'auto'
|
|
22682
|
+
};
|
|
22683
|
+
},
|
|
22684
|
+
getInitialState: state => {
|
|
22685
|
+
return {
|
|
22686
|
+
columnFilters: [],
|
|
22687
|
+
globalFilter: undefined,
|
|
22688
|
+
// filtersProgress: 1,
|
|
22689
|
+
// facetProgress: {},
|
|
22690
|
+
...state
|
|
22691
|
+
};
|
|
22692
|
+
},
|
|
22693
|
+
getDefaultOptions: table => {
|
|
22694
|
+
return {
|
|
22695
|
+
onColumnFiltersChange: makeStateUpdater('columnFilters', table),
|
|
22696
|
+
onGlobalFilterChange: makeStateUpdater('globalFilter', table),
|
|
22697
|
+
filterFromLeafRows: false,
|
|
22698
|
+
maxLeafRowFilterDepth: 100,
|
|
22699
|
+
globalFilterFn: 'auto',
|
|
22700
|
+
getColumnCanGlobalFilter: column => {
|
|
22701
|
+
var _table$getCoreRowMode, _table$getCoreRowMode2;
|
|
22702
|
+
const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null ? void 0 : (_table$getCoreRowMode2 = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode2.getValue();
|
|
22703
|
+
return typeof value === 'string' || typeof value === 'number';
|
|
22704
|
+
}
|
|
22705
|
+
};
|
|
22706
|
+
},
|
|
22707
|
+
createColumn: (column, table) => {
|
|
22708
|
+
return {
|
|
22709
|
+
getAutoFilterFn: () => {
|
|
22710
|
+
const firstRow = table.getCoreRowModel().flatRows[0];
|
|
22711
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
22712
|
+
if (typeof value === 'string') {
|
|
22713
|
+
return filterFns.includesString;
|
|
22714
|
+
}
|
|
22715
|
+
if (typeof value === 'number') {
|
|
22716
|
+
return filterFns.inNumberRange;
|
|
22717
|
+
}
|
|
22718
|
+
if (typeof value === 'boolean') {
|
|
22719
|
+
return filterFns.equals;
|
|
22720
|
+
}
|
|
22721
|
+
if (value !== null && typeof value === 'object') {
|
|
22722
|
+
return filterFns.equals;
|
|
22723
|
+
}
|
|
22724
|
+
if (Array.isArray(value)) {
|
|
22725
|
+
return filterFns.arrIncludes;
|
|
22726
|
+
}
|
|
22727
|
+
return filterFns.weakEquals;
|
|
22728
|
+
},
|
|
22729
|
+
getFilterFn: () => {
|
|
22730
|
+
var _table$options$filter, _table$options$filter2;
|
|
22731
|
+
return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn()
|
|
22732
|
+
// @ts-ignore
|
|
22733
|
+
: (_table$options$filter = (_table$options$filter2 = table.options.filterFns) == null ? void 0 : _table$options$filter2[column.columnDef.filterFn]) != null ? _table$options$filter : filterFns[column.columnDef.filterFn];
|
|
22734
|
+
},
|
|
22735
|
+
getCanFilter: () => {
|
|
22736
|
+
var _column$columnDef$ena, _table$options$enable, _table$options$enable2;
|
|
22737
|
+
return ((_column$columnDef$ena = column.columnDef.enableColumnFilter) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnFilters) != null ? _table$options$enable : true) && ((_table$options$enable2 = table.options.enableFilters) != null ? _table$options$enable2 : true) && !!column.accessorFn;
|
|
22738
|
+
},
|
|
22739
|
+
getCanGlobalFilter: () => {
|
|
22740
|
+
var _column$columnDef$ena2, _table$options$enable3, _table$options$enable4, _table$options$getCol;
|
|
22741
|
+
return ((_column$columnDef$ena2 = column.columnDef.enableGlobalFilter) != null ? _column$columnDef$ena2 : true) && ((_table$options$enable3 = table.options.enableGlobalFilter) != null ? _table$options$enable3 : true) && ((_table$options$enable4 = table.options.enableFilters) != null ? _table$options$enable4 : true) && ((_table$options$getCol = table.options.getColumnCanGlobalFilter == null ? void 0 : table.options.getColumnCanGlobalFilter(column)) != null ? _table$options$getCol : true) && !!column.accessorFn;
|
|
22742
|
+
},
|
|
22743
|
+
getIsFiltered: () => column.getFilterIndex() > -1,
|
|
22744
|
+
getFilterValue: () => {
|
|
22745
|
+
var _table$getState$colum, _table$getState$colum2;
|
|
22746
|
+
return (_table$getState$colum = table.getState().columnFilters) == null ? void 0 : (_table$getState$colum2 = _table$getState$colum.find(d => d.id === column.id)) == null ? void 0 : _table$getState$colum2.value;
|
|
22747
|
+
},
|
|
22748
|
+
getFilterIndex: () => {
|
|
22749
|
+
var _table$getState$colum3, _table$getState$colum4;
|
|
22750
|
+
return (_table$getState$colum3 = (_table$getState$colum4 = table.getState().columnFilters) == null ? void 0 : _table$getState$colum4.findIndex(d => d.id === column.id)) != null ? _table$getState$colum3 : -1;
|
|
22751
|
+
},
|
|
22752
|
+
setFilterValue: value => {
|
|
22753
|
+
table.setColumnFilters(old => {
|
|
22754
|
+
const filterFn = column.getFilterFn();
|
|
22755
|
+
const previousfilter = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
22756
|
+
const newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined);
|
|
22757
|
+
|
|
22758
|
+
//
|
|
22759
|
+
if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
|
|
22760
|
+
var _old$filter;
|
|
22761
|
+
return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
|
|
22762
|
+
}
|
|
22763
|
+
const newFilterObj = {
|
|
22764
|
+
id: column.id,
|
|
22765
|
+
value: newFilter
|
|
22766
|
+
};
|
|
22767
|
+
if (previousfilter) {
|
|
22768
|
+
var _old$map;
|
|
22769
|
+
return (_old$map = old == null ? void 0 : old.map(d => {
|
|
22770
|
+
if (d.id === column.id) {
|
|
22771
|
+
return newFilterObj;
|
|
22772
|
+
}
|
|
22773
|
+
return d;
|
|
22774
|
+
})) != null ? _old$map : [];
|
|
22775
|
+
}
|
|
22776
|
+
if (old != null && old.length) {
|
|
22777
|
+
return [...old, newFilterObj];
|
|
22778
|
+
}
|
|
22779
|
+
return [newFilterObj];
|
|
22780
|
+
});
|
|
22781
|
+
},
|
|
22782
|
+
_getFacetedRowModel: table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id),
|
|
22783
|
+
getFacetedRowModel: () => {
|
|
22784
|
+
if (!column._getFacetedRowModel) {
|
|
22785
|
+
return table.getPreFilteredRowModel();
|
|
22786
|
+
}
|
|
22787
|
+
return column._getFacetedRowModel();
|
|
22788
|
+
},
|
|
22789
|
+
_getFacetedUniqueValues: table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id),
|
|
22790
|
+
getFacetedUniqueValues: () => {
|
|
22791
|
+
if (!column._getFacetedUniqueValues) {
|
|
22792
|
+
return new Map();
|
|
22793
|
+
}
|
|
22794
|
+
return column._getFacetedUniqueValues();
|
|
22795
|
+
},
|
|
22796
|
+
_getFacetedMinMaxValues: table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id),
|
|
22797
|
+
getFacetedMinMaxValues: () => {
|
|
22798
|
+
if (!column._getFacetedMinMaxValues) {
|
|
22799
|
+
return undefined;
|
|
22800
|
+
}
|
|
22801
|
+
return column._getFacetedMinMaxValues();
|
|
22802
|
+
}
|
|
22803
|
+
// () => [column.getFacetedRowModel()],
|
|
22804
|
+
// facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
|
|
22805
|
+
};
|
|
22806
|
+
},
|
|
22807
|
+
|
|
22808
|
+
createRow: (row, table) => {
|
|
22809
|
+
return {
|
|
22810
|
+
columnFilters: {},
|
|
22811
|
+
columnFiltersMeta: {}
|
|
22812
|
+
};
|
|
22813
|
+
},
|
|
22814
|
+
createTable: table => {
|
|
22815
|
+
return {
|
|
22816
|
+
getGlobalAutoFilterFn: () => {
|
|
22817
|
+
return filterFns.includesString;
|
|
22818
|
+
},
|
|
22819
|
+
getGlobalFilterFn: () => {
|
|
22820
|
+
var _table$options$filter3, _table$options$filter4;
|
|
22821
|
+
const {
|
|
22822
|
+
globalFilterFn: globalFilterFn
|
|
22823
|
+
} = table.options;
|
|
22824
|
+
return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? table.getGlobalAutoFilterFn()
|
|
22825
|
+
// @ts-ignore
|
|
22826
|
+
: (_table$options$filter3 = (_table$options$filter4 = table.options.filterFns) == null ? void 0 : _table$options$filter4[globalFilterFn]) != null ? _table$options$filter3 : filterFns[globalFilterFn];
|
|
22827
|
+
},
|
|
22828
|
+
setColumnFilters: updater => {
|
|
22829
|
+
const leafColumns = table.getAllLeafColumns();
|
|
22830
|
+
const updateFn = old => {
|
|
22831
|
+
var _functionalUpdate;
|
|
22832
|
+
return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
|
|
22833
|
+
const column = leafColumns.find(d => d.id === filter.id);
|
|
22834
|
+
if (column) {
|
|
22835
|
+
const filterFn = column.getFilterFn();
|
|
22836
|
+
if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
|
|
22837
|
+
return false;
|
|
22838
|
+
}
|
|
22839
|
+
}
|
|
22840
|
+
return true;
|
|
22841
|
+
});
|
|
22842
|
+
};
|
|
22843
|
+
table.options.onColumnFiltersChange == null ? void 0 : table.options.onColumnFiltersChange(updateFn);
|
|
22844
|
+
},
|
|
22845
|
+
setGlobalFilter: updater => {
|
|
22846
|
+
table.options.onGlobalFilterChange == null ? void 0 : table.options.onGlobalFilterChange(updater);
|
|
22847
|
+
},
|
|
22848
|
+
resetGlobalFilter: defaultState => {
|
|
22849
|
+
table.setGlobalFilter(defaultState ? undefined : table.initialState.globalFilter);
|
|
22850
|
+
},
|
|
22851
|
+
resetColumnFilters: defaultState => {
|
|
22852
|
+
var _table$initialState$c, _table$initialState;
|
|
22853
|
+
table.setColumnFilters(defaultState ? [] : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) != null ? _table$initialState$c : []);
|
|
22854
|
+
},
|
|
22855
|
+
getPreFilteredRowModel: () => table.getCoreRowModel(),
|
|
22856
|
+
getFilteredRowModel: () => {
|
|
22857
|
+
if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
|
|
22858
|
+
table._getFilteredRowModel = table.options.getFilteredRowModel(table);
|
|
22859
|
+
}
|
|
22860
|
+
if (table.options.manualFiltering || !table._getFilteredRowModel) {
|
|
22861
|
+
return table.getPreFilteredRowModel();
|
|
22862
|
+
}
|
|
22863
|
+
return table._getFilteredRowModel();
|
|
22864
|
+
},
|
|
22865
|
+
_getGlobalFacetedRowModel: table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, '__global__'),
|
|
22866
|
+
getGlobalFacetedRowModel: () => {
|
|
22867
|
+
if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
|
|
22868
|
+
return table.getPreFilteredRowModel();
|
|
22869
|
+
}
|
|
22870
|
+
return table._getGlobalFacetedRowModel();
|
|
22871
|
+
},
|
|
22872
|
+
_getGlobalFacetedUniqueValues: table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, '__global__'),
|
|
22873
|
+
getGlobalFacetedUniqueValues: () => {
|
|
22874
|
+
if (!table._getGlobalFacetedUniqueValues) {
|
|
22875
|
+
return new Map();
|
|
22876
|
+
}
|
|
22877
|
+
return table._getGlobalFacetedUniqueValues();
|
|
22878
|
+
},
|
|
22879
|
+
_getGlobalFacetedMinMaxValues: table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, '__global__'),
|
|
22880
|
+
getGlobalFacetedMinMaxValues: () => {
|
|
22881
|
+
if (!table._getGlobalFacetedMinMaxValues) {
|
|
22882
|
+
return;
|
|
22883
|
+
}
|
|
22884
|
+
return table._getGlobalFacetedMinMaxValues();
|
|
22885
|
+
}
|
|
22886
|
+
};
|
|
22887
|
+
}
|
|
22888
|
+
};
|
|
22889
|
+
function shouldAutoRemoveFilter(filterFn, value, column) {
|
|
22890
|
+
return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
|
|
22891
|
+
}
|
|
22892
|
+
|
|
22893
|
+
const sum = (columnId, _leafRows, childRows) => {
|
|
22894
|
+
// It's faster to just add the aggregations together instead of
|
|
22895
|
+
// process leaf nodes individually
|
|
22896
|
+
return childRows.reduce((sum, next) => {
|
|
22897
|
+
const nextValue = next.getValue(columnId);
|
|
22898
|
+
return sum + (typeof nextValue === 'number' ? nextValue : 0);
|
|
22899
|
+
}, 0);
|
|
22900
|
+
};
|
|
22901
|
+
const min = (columnId, _leafRows, childRows) => {
|
|
22902
|
+
let min;
|
|
22903
|
+
childRows.forEach(row => {
|
|
22904
|
+
const value = row.getValue(columnId);
|
|
22905
|
+
if (value != null && (min > value || min === undefined && value >= value)) {
|
|
22906
|
+
min = value;
|
|
22907
|
+
}
|
|
22908
|
+
});
|
|
22909
|
+
return min;
|
|
22910
|
+
};
|
|
22911
|
+
const max = (columnId, _leafRows, childRows) => {
|
|
22912
|
+
let max;
|
|
22913
|
+
childRows.forEach(row => {
|
|
22914
|
+
const value = row.getValue(columnId);
|
|
22915
|
+
if (value != null && (max < value || max === undefined && value >= value)) {
|
|
22916
|
+
max = value;
|
|
22917
|
+
}
|
|
22918
|
+
});
|
|
22919
|
+
return max;
|
|
22920
|
+
};
|
|
22921
|
+
const extent = (columnId, _leafRows, childRows) => {
|
|
22922
|
+
let min;
|
|
22923
|
+
let max;
|
|
22924
|
+
childRows.forEach(row => {
|
|
22925
|
+
const value = row.getValue(columnId);
|
|
22926
|
+
if (value != null) {
|
|
22927
|
+
if (min === undefined) {
|
|
22928
|
+
if (value >= value) min = max = value;
|
|
22929
|
+
} else {
|
|
22930
|
+
if (min > value) min = value;
|
|
22931
|
+
if (max < value) max = value;
|
|
22932
|
+
}
|
|
22933
|
+
}
|
|
22934
|
+
});
|
|
22935
|
+
return [min, max];
|
|
22936
|
+
};
|
|
22937
|
+
const mean = (columnId, leafRows) => {
|
|
22938
|
+
let count = 0;
|
|
22939
|
+
let sum = 0;
|
|
22940
|
+
leafRows.forEach(row => {
|
|
22941
|
+
let value = row.getValue(columnId);
|
|
22942
|
+
if (value != null && (value = +value) >= value) {
|
|
22943
|
+
++count, sum += value;
|
|
22944
|
+
}
|
|
22945
|
+
});
|
|
22946
|
+
if (count) return sum / count;
|
|
22947
|
+
return;
|
|
22948
|
+
};
|
|
22949
|
+
const median = (columnId, leafRows) => {
|
|
22950
|
+
if (!leafRows.length) {
|
|
22951
|
+
return;
|
|
22952
|
+
}
|
|
22953
|
+
let min = 0;
|
|
22954
|
+
let max = 0;
|
|
22955
|
+
leafRows.forEach(row => {
|
|
22956
|
+
let value = row.getValue(columnId);
|
|
22957
|
+
if (typeof value === 'number') {
|
|
22958
|
+
min = Math.min(min, value);
|
|
22959
|
+
max = Math.max(max, value);
|
|
22960
|
+
}
|
|
22961
|
+
});
|
|
22962
|
+
return (min + max) / 2;
|
|
22963
|
+
};
|
|
22964
|
+
const unique = (columnId, leafRows) => {
|
|
22965
|
+
return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
|
|
22966
|
+
};
|
|
22967
|
+
const uniqueCount = (columnId, leafRows) => {
|
|
22968
|
+
return new Set(leafRows.map(d => d.getValue(columnId))).size;
|
|
22969
|
+
};
|
|
22970
|
+
const count = (_columnId, leafRows) => {
|
|
22971
|
+
return leafRows.length;
|
|
22972
|
+
};
|
|
22973
|
+
const aggregationFns = {
|
|
22974
|
+
sum,
|
|
22975
|
+
min,
|
|
22976
|
+
max,
|
|
22977
|
+
extent,
|
|
22978
|
+
mean,
|
|
22979
|
+
median,
|
|
22980
|
+
unique,
|
|
22981
|
+
uniqueCount,
|
|
22982
|
+
count
|
|
22983
|
+
};
|
|
22984
|
+
|
|
22985
|
+
//
|
|
22986
|
+
|
|
22987
|
+
const Grouping = {
|
|
22988
|
+
getDefaultColumnDef: () => {
|
|
22989
|
+
return {
|
|
22990
|
+
aggregatedCell: props => {
|
|
22991
|
+
var _toString, _props$getValue;
|
|
22992
|
+
return (_toString = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _toString : null;
|
|
22993
|
+
},
|
|
22994
|
+
aggregationFn: 'auto'
|
|
22995
|
+
};
|
|
22996
|
+
},
|
|
22997
|
+
getInitialState: state => {
|
|
22998
|
+
return {
|
|
22999
|
+
grouping: [],
|
|
23000
|
+
...state
|
|
23001
|
+
};
|
|
23002
|
+
},
|
|
23003
|
+
getDefaultOptions: table => {
|
|
23004
|
+
return {
|
|
23005
|
+
onGroupingChange: makeStateUpdater('grouping', table),
|
|
23006
|
+
groupedColumnMode: 'reorder'
|
|
23007
|
+
};
|
|
23008
|
+
},
|
|
23009
|
+
createColumn: (column, table) => {
|
|
23010
|
+
return {
|
|
23011
|
+
toggleGrouping: () => {
|
|
23012
|
+
table.setGrouping(old => {
|
|
23013
|
+
// Find any existing grouping for this column
|
|
23014
|
+
if (old != null && old.includes(column.id)) {
|
|
23015
|
+
return old.filter(d => d !== column.id);
|
|
23016
|
+
}
|
|
23017
|
+
return [...(old != null ? old : []), column.id];
|
|
23018
|
+
});
|
|
23019
|
+
},
|
|
23020
|
+
getCanGroup: () => {
|
|
23021
|
+
var _ref, _ref2, _ref3, _column$columnDef$ena;
|
|
23022
|
+
return (_ref = (_ref2 = (_ref3 = (_column$columnDef$ena = column.columnDef.enableGrouping) != null ? _column$columnDef$ena : true) != null ? _ref3 : table.options.enableGrouping) != null ? _ref2 : true) != null ? _ref : !!column.accessorFn;
|
|
23023
|
+
},
|
|
23024
|
+
getIsGrouped: () => {
|
|
23025
|
+
var _table$getState$group;
|
|
23026
|
+
return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
|
|
23027
|
+
},
|
|
23028
|
+
getGroupedIndex: () => {
|
|
23029
|
+
var _table$getState$group2;
|
|
23030
|
+
return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
|
|
23031
|
+
},
|
|
23032
|
+
getToggleGroupingHandler: () => {
|
|
23033
|
+
const canGroup = column.getCanGroup();
|
|
23034
|
+
return () => {
|
|
23035
|
+
if (!canGroup) return;
|
|
23036
|
+
column.toggleGrouping();
|
|
23037
|
+
};
|
|
23038
|
+
},
|
|
23039
|
+
getAutoAggregationFn: () => {
|
|
23040
|
+
const firstRow = table.getCoreRowModel().flatRows[0];
|
|
23041
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
23042
|
+
if (typeof value === 'number') {
|
|
23043
|
+
return aggregationFns.sum;
|
|
23044
|
+
}
|
|
23045
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
23046
|
+
return aggregationFns.extent;
|
|
23047
|
+
}
|
|
23048
|
+
},
|
|
23049
|
+
getAggregationFn: () => {
|
|
23050
|
+
var _table$options$aggreg, _table$options$aggreg2;
|
|
23051
|
+
if (!column) {
|
|
23052
|
+
throw new Error();
|
|
23053
|
+
}
|
|
23054
|
+
return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_table$options$aggreg = (_table$options$aggreg2 = table.options.aggregationFns) == null ? void 0 : _table$options$aggreg2[column.columnDef.aggregationFn]) != null ? _table$options$aggreg : aggregationFns[column.columnDef.aggregationFn];
|
|
23055
|
+
}
|
|
23056
|
+
};
|
|
23057
|
+
},
|
|
23058
|
+
createTable: table => {
|
|
23059
|
+
return {
|
|
23060
|
+
setGrouping: updater => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater),
|
|
23061
|
+
resetGrouping: defaultState => {
|
|
23062
|
+
var _table$initialState$g, _table$initialState;
|
|
23063
|
+
table.setGrouping(defaultState ? [] : (_table$initialState$g = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) != null ? _table$initialState$g : []);
|
|
23064
|
+
},
|
|
23065
|
+
getPreGroupedRowModel: () => table.getFilteredRowModel(),
|
|
23066
|
+
getGroupedRowModel: () => {
|
|
23067
|
+
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
|
|
23068
|
+
table._getGroupedRowModel = table.options.getGroupedRowModel(table);
|
|
23069
|
+
}
|
|
23070
|
+
if (table.options.manualGrouping || !table._getGroupedRowModel) {
|
|
23071
|
+
return table.getPreGroupedRowModel();
|
|
23072
|
+
}
|
|
23073
|
+
return table._getGroupedRowModel();
|
|
23074
|
+
}
|
|
23075
|
+
};
|
|
23076
|
+
},
|
|
23077
|
+
createRow: row => {
|
|
23078
|
+
return {
|
|
23079
|
+
getIsGrouped: () => !!row.groupingColumnId,
|
|
23080
|
+
_groupingValuesCache: {}
|
|
23081
|
+
};
|
|
23082
|
+
},
|
|
23083
|
+
createCell: (cell, column, row, table) => {
|
|
23084
|
+
return {
|
|
23085
|
+
getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
23086
|
+
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
23087
|
+
getIsAggregated: () => {
|
|
23088
|
+
var _row$subRows;
|
|
23089
|
+
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
|
|
23090
|
+
}
|
|
23091
|
+
};
|
|
23092
|
+
}
|
|
23093
|
+
};
|
|
23094
|
+
function orderColumns(leafColumns, grouping, groupedColumnMode) {
|
|
23095
|
+
if (!(grouping != null && grouping.length) || !groupedColumnMode) {
|
|
23096
|
+
return leafColumns;
|
|
23097
|
+
}
|
|
23098
|
+
const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
|
|
23099
|
+
if (groupedColumnMode === 'remove') {
|
|
23100
|
+
return nonGroupingColumns;
|
|
23101
|
+
}
|
|
23102
|
+
const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
|
|
23103
|
+
return [...groupingColumns, ...nonGroupingColumns];
|
|
23104
|
+
}
|
|
23105
|
+
|
|
23106
|
+
//
|
|
23107
|
+
|
|
23108
|
+
const Ordering = {
|
|
23109
|
+
getInitialState: state => {
|
|
23110
|
+
return {
|
|
23111
|
+
columnOrder: [],
|
|
23112
|
+
...state
|
|
23113
|
+
};
|
|
23114
|
+
},
|
|
23115
|
+
getDefaultOptions: table => {
|
|
23116
|
+
return {
|
|
23117
|
+
onColumnOrderChange: makeStateUpdater('columnOrder', table)
|
|
23118
|
+
};
|
|
23119
|
+
},
|
|
23120
|
+
createTable: table => {
|
|
23121
|
+
return {
|
|
23122
|
+
setColumnOrder: updater => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater),
|
|
23123
|
+
resetColumnOrder: defaultState => {
|
|
23124
|
+
var _table$initialState$c;
|
|
23125
|
+
table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
|
|
23126
|
+
},
|
|
23127
|
+
_getOrderColumnsFn: memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
|
|
23128
|
+
// Sort grouped columns to the start of the column list
|
|
23129
|
+
// before the headers are built
|
|
23130
|
+
let orderedColumns = [];
|
|
23131
|
+
|
|
23132
|
+
// If there is no order, return the normal columns
|
|
23133
|
+
if (!(columnOrder != null && columnOrder.length)) {
|
|
23134
|
+
orderedColumns = columns;
|
|
23135
|
+
} else {
|
|
23136
|
+
const columnOrderCopy = [...columnOrder];
|
|
23137
|
+
|
|
23138
|
+
// If there is an order, make a copy of the columns
|
|
23139
|
+
const columnsCopy = [...columns];
|
|
23140
|
+
|
|
23141
|
+
// And make a new ordered array of the columns
|
|
23142
|
+
|
|
23143
|
+
// Loop over the columns and place them in order into the new array
|
|
23144
|
+
while (columnsCopy.length && columnOrderCopy.length) {
|
|
23145
|
+
const targetColumnId = columnOrderCopy.shift();
|
|
23146
|
+
const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
|
|
23147
|
+
if (foundIndex > -1) {
|
|
23148
|
+
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
|
|
23149
|
+
}
|
|
23150
|
+
}
|
|
23151
|
+
|
|
23152
|
+
// If there are any columns left, add them to the end
|
|
23153
|
+
orderedColumns = [...orderedColumns, ...columnsCopy];
|
|
23154
|
+
}
|
|
23155
|
+
return orderColumns(orderedColumns, grouping, groupedColumnMode);
|
|
23156
|
+
}, {
|
|
23157
|
+
key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn'
|
|
23158
|
+
// debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
23159
|
+
})
|
|
23160
|
+
};
|
|
23161
|
+
}
|
|
23162
|
+
};
|
|
23163
|
+
|
|
23164
|
+
//
|
|
23165
|
+
|
|
23166
|
+
const defaultPageIndex = 0;
|
|
23167
|
+
const defaultPageSize = 10;
|
|
23168
|
+
const getDefaultPaginationState = () => ({
|
|
23169
|
+
pageIndex: defaultPageIndex,
|
|
23170
|
+
pageSize: defaultPageSize
|
|
23171
|
+
});
|
|
23172
|
+
const Pagination = {
|
|
23173
|
+
getInitialState: state => {
|
|
23174
|
+
return {
|
|
23175
|
+
...state,
|
|
23176
|
+
pagination: {
|
|
23177
|
+
...getDefaultPaginationState(),
|
|
23178
|
+
...(state == null ? void 0 : state.pagination)
|
|
23179
|
+
}
|
|
23180
|
+
};
|
|
23181
|
+
},
|
|
23182
|
+
getDefaultOptions: table => {
|
|
23183
|
+
return {
|
|
23184
|
+
onPaginationChange: makeStateUpdater('pagination', table)
|
|
23185
|
+
};
|
|
23186
|
+
},
|
|
23187
|
+
createTable: table => {
|
|
23188
|
+
let registered = false;
|
|
23189
|
+
let queued = false;
|
|
23190
|
+
return {
|
|
23191
|
+
_autoResetPageIndex: () => {
|
|
23192
|
+
var _ref, _table$options$autoRe;
|
|
23193
|
+
if (!registered) {
|
|
23194
|
+
table._queue(() => {
|
|
23195
|
+
registered = true;
|
|
23196
|
+
});
|
|
23197
|
+
return;
|
|
23198
|
+
}
|
|
23199
|
+
if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetPageIndex) != null ? _ref : !table.options.manualPagination) {
|
|
23200
|
+
if (queued) return;
|
|
23201
|
+
queued = true;
|
|
23202
|
+
table._queue(() => {
|
|
23203
|
+
table.resetPageIndex();
|
|
23204
|
+
queued = false;
|
|
23205
|
+
});
|
|
23206
|
+
}
|
|
23207
|
+
},
|
|
23208
|
+
setPagination: updater => {
|
|
23209
|
+
const safeUpdater = old => {
|
|
23210
|
+
let newState = functionalUpdate(updater, old);
|
|
23211
|
+
return newState;
|
|
23212
|
+
};
|
|
23213
|
+
return table.options.onPaginationChange == null ? void 0 : table.options.onPaginationChange(safeUpdater);
|
|
23214
|
+
},
|
|
23215
|
+
resetPagination: defaultState => {
|
|
23216
|
+
var _table$initialState$p;
|
|
23217
|
+
table.setPagination(defaultState ? getDefaultPaginationState() : (_table$initialState$p = table.initialState.pagination) != null ? _table$initialState$p : getDefaultPaginationState());
|
|
23218
|
+
},
|
|
23219
|
+
setPageIndex: updater => {
|
|
23220
|
+
table.setPagination(old => {
|
|
23221
|
+
let pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
23222
|
+
const maxPageIndex = typeof table.options.pageCount === 'undefined' || table.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : table.options.pageCount - 1;
|
|
23223
|
+
pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex));
|
|
23224
|
+
return {
|
|
23225
|
+
...old,
|
|
23226
|
+
pageIndex
|
|
23227
|
+
};
|
|
23228
|
+
});
|
|
23229
|
+
},
|
|
23230
|
+
resetPageIndex: defaultState => {
|
|
23231
|
+
var _table$initialState$p2, _table$initialState, _table$initialState$p3;
|
|
23232
|
+
table.setPageIndex(defaultState ? defaultPageIndex : (_table$initialState$p2 = (_table$initialState = table.initialState) == null ? void 0 : (_table$initialState$p3 = _table$initialState.pagination) == null ? void 0 : _table$initialState$p3.pageIndex) != null ? _table$initialState$p2 : defaultPageIndex);
|
|
23233
|
+
},
|
|
23234
|
+
resetPageSize: defaultState => {
|
|
23235
|
+
var _table$initialState$p4, _table$initialState2, _table$initialState2$;
|
|
23236
|
+
table.setPageSize(defaultState ? defaultPageSize : (_table$initialState$p4 = (_table$initialState2 = table.initialState) == null ? void 0 : (_table$initialState2$ = _table$initialState2.pagination) == null ? void 0 : _table$initialState2$.pageSize) != null ? _table$initialState$p4 : defaultPageSize);
|
|
23237
|
+
},
|
|
23238
|
+
setPageSize: updater => {
|
|
23239
|
+
table.setPagination(old => {
|
|
23240
|
+
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
|
|
23241
|
+
const topRowIndex = old.pageSize * old.pageIndex;
|
|
23242
|
+
const pageIndex = Math.floor(topRowIndex / pageSize);
|
|
23243
|
+
return {
|
|
23244
|
+
...old,
|
|
23245
|
+
pageIndex,
|
|
23246
|
+
pageSize
|
|
23247
|
+
};
|
|
23248
|
+
});
|
|
23249
|
+
},
|
|
23250
|
+
setPageCount: updater => table.setPagination(old => {
|
|
23251
|
+
var _table$options$pageCo;
|
|
23252
|
+
let newPageCount = functionalUpdate(updater, (_table$options$pageCo = table.options.pageCount) != null ? _table$options$pageCo : -1);
|
|
23253
|
+
if (typeof newPageCount === 'number') {
|
|
23254
|
+
newPageCount = Math.max(-1, newPageCount);
|
|
23255
|
+
}
|
|
23256
|
+
return {
|
|
23257
|
+
...old,
|
|
23258
|
+
pageCount: newPageCount
|
|
23259
|
+
};
|
|
23260
|
+
}),
|
|
23261
|
+
getPageOptions: memo(() => [table.getPageCount()], pageCount => {
|
|
23262
|
+
let pageOptions = [];
|
|
23263
|
+
if (pageCount && pageCount > 0) {
|
|
23264
|
+
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
|
|
23265
|
+
}
|
|
23266
|
+
return pageOptions;
|
|
23267
|
+
}, {
|
|
23268
|
+
key: process.env.NODE_ENV === 'development' && 'getPageOptions',
|
|
23269
|
+
debug: () => {
|
|
23270
|
+
var _table$options$debugA;
|
|
23271
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugTable;
|
|
23272
|
+
}
|
|
23273
|
+
}),
|
|
23274
|
+
getCanPreviousPage: () => table.getState().pagination.pageIndex > 0,
|
|
23275
|
+
getCanNextPage: () => {
|
|
23276
|
+
const {
|
|
23277
|
+
pageIndex
|
|
23278
|
+
} = table.getState().pagination;
|
|
23279
|
+
const pageCount = table.getPageCount();
|
|
23280
|
+
if (pageCount === -1) {
|
|
23281
|
+
return true;
|
|
23282
|
+
}
|
|
23283
|
+
if (pageCount === 0) {
|
|
23284
|
+
return false;
|
|
23285
|
+
}
|
|
23286
|
+
return pageIndex < pageCount - 1;
|
|
23287
|
+
},
|
|
23288
|
+
previousPage: () => {
|
|
23289
|
+
return table.setPageIndex(old => old - 1);
|
|
23290
|
+
},
|
|
23291
|
+
nextPage: () => {
|
|
23292
|
+
return table.setPageIndex(old => {
|
|
23293
|
+
return old + 1;
|
|
23294
|
+
});
|
|
23295
|
+
},
|
|
23296
|
+
getPrePaginationRowModel: () => table.getExpandedRowModel(),
|
|
23297
|
+
getPaginationRowModel: () => {
|
|
23298
|
+
if (!table._getPaginationRowModel && table.options.getPaginationRowModel) {
|
|
23299
|
+
table._getPaginationRowModel = table.options.getPaginationRowModel(table);
|
|
23300
|
+
}
|
|
23301
|
+
if (table.options.manualPagination || !table._getPaginationRowModel) {
|
|
23302
|
+
return table.getPrePaginationRowModel();
|
|
23303
|
+
}
|
|
23304
|
+
return table._getPaginationRowModel();
|
|
23305
|
+
},
|
|
23306
|
+
getPageCount: () => {
|
|
23307
|
+
var _table$options$pageCo2;
|
|
23308
|
+
return (_table$options$pageCo2 = table.options.pageCount) != null ? _table$options$pageCo2 : Math.ceil(table.getPrePaginationRowModel().rows.length / table.getState().pagination.pageSize);
|
|
23309
|
+
}
|
|
23310
|
+
};
|
|
23311
|
+
}
|
|
23312
|
+
};
|
|
23313
|
+
|
|
23314
|
+
//
|
|
23315
|
+
|
|
23316
|
+
const getDefaultPinningState = () => ({
|
|
23317
|
+
left: [],
|
|
23318
|
+
right: []
|
|
23319
|
+
});
|
|
23320
|
+
const Pinning = {
|
|
23321
|
+
getInitialState: state => {
|
|
23322
|
+
return {
|
|
23323
|
+
columnPinning: getDefaultPinningState(),
|
|
23324
|
+
...state
|
|
23325
|
+
};
|
|
23326
|
+
},
|
|
23327
|
+
getDefaultOptions: table => {
|
|
23328
|
+
return {
|
|
23329
|
+
onColumnPinningChange: makeStateUpdater('columnPinning', table)
|
|
23330
|
+
};
|
|
23331
|
+
},
|
|
23332
|
+
createColumn: (column, table) => {
|
|
23333
|
+
return {
|
|
23334
|
+
pin: position => {
|
|
23335
|
+
const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
|
|
23336
|
+
table.setColumnPinning(old => {
|
|
23337
|
+
var _old$left3, _old$right3;
|
|
23338
|
+
if (position === 'right') {
|
|
23339
|
+
var _old$left, _old$right;
|
|
23340
|
+
return {
|
|
23341
|
+
left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
|
|
23342
|
+
right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
|
|
23343
|
+
};
|
|
23344
|
+
}
|
|
23345
|
+
if (position === 'left') {
|
|
23346
|
+
var _old$left2, _old$right2;
|
|
23347
|
+
return {
|
|
23348
|
+
left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
|
|
23349
|
+
right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
|
|
23350
|
+
};
|
|
23351
|
+
}
|
|
23352
|
+
return {
|
|
23353
|
+
left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
|
|
23354
|
+
right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
|
|
23355
|
+
};
|
|
23356
|
+
});
|
|
23357
|
+
},
|
|
23358
|
+
getCanPin: () => {
|
|
23359
|
+
const leafColumns = column.getLeafColumns();
|
|
23360
|
+
return leafColumns.some(d => {
|
|
23361
|
+
var _d$columnDef$enablePi, _table$options$enable;
|
|
23362
|
+
return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_table$options$enable = table.options.enablePinning) != null ? _table$options$enable : true);
|
|
23363
|
+
});
|
|
23364
|
+
},
|
|
23365
|
+
getIsPinned: () => {
|
|
23366
|
+
const leafColumnIds = column.getLeafColumns().map(d => d.id);
|
|
23367
|
+
const {
|
|
23368
|
+
left,
|
|
23369
|
+
right
|
|
23370
|
+
} = table.getState().columnPinning;
|
|
23371
|
+
const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
|
|
23372
|
+
const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
|
|
23373
|
+
return isLeft ? 'left' : isRight ? 'right' : false;
|
|
23374
|
+
},
|
|
23375
|
+
getPinnedIndex: () => {
|
|
23376
|
+
var _table$getState$colum, _table$getState$colum2, _table$getState$colum3;
|
|
23377
|
+
const position = column.getIsPinned();
|
|
23378
|
+
return position ? (_table$getState$colum = (_table$getState$colum2 = table.getState().columnPinning) == null ? void 0 : (_table$getState$colum3 = _table$getState$colum2[position]) == null ? void 0 : _table$getState$colum3.indexOf(column.id)) != null ? _table$getState$colum : -1 : 0;
|
|
23379
|
+
}
|
|
23380
|
+
};
|
|
23381
|
+
},
|
|
23382
|
+
createRow: (row, table) => {
|
|
23383
|
+
return {
|
|
23384
|
+
getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
|
|
23385
|
+
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
23386
|
+
return allCells.filter(d => !leftAndRight.includes(d.column.id));
|
|
23387
|
+
}, {
|
|
23388
|
+
key: process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
|
|
23389
|
+
debug: () => {
|
|
23390
|
+
var _table$options$debugA;
|
|
23391
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
|
|
23392
|
+
}
|
|
23393
|
+
}),
|
|
23394
|
+
getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left,,], (allCells, left) => {
|
|
23395
|
+
const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
|
|
23396
|
+
...d,
|
|
23397
|
+
position: 'left'
|
|
23398
|
+
}));
|
|
23399
|
+
return cells;
|
|
23400
|
+
}, {
|
|
23401
|
+
key: process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
|
|
23402
|
+
debug: () => {
|
|
23403
|
+
var _table$options$debugA2;
|
|
23404
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
|
|
23405
|
+
}
|
|
23406
|
+
}),
|
|
23407
|
+
getRightVisibleCells: memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
|
|
23408
|
+
const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
|
|
23409
|
+
...d,
|
|
23410
|
+
position: 'right'
|
|
23411
|
+
}));
|
|
23412
|
+
return cells;
|
|
23413
|
+
}, {
|
|
23414
|
+
key: process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
|
|
23415
|
+
debug: () => {
|
|
23416
|
+
var _table$options$debugA3;
|
|
23417
|
+
return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugRows;
|
|
23418
|
+
}
|
|
23419
|
+
})
|
|
23420
|
+
};
|
|
23421
|
+
},
|
|
23422
|
+
createTable: table => {
|
|
23423
|
+
return {
|
|
23424
|
+
setColumnPinning: updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater),
|
|
23425
|
+
resetColumnPinning: defaultState => {
|
|
23426
|
+
var _table$initialState$c, _table$initialState;
|
|
23427
|
+
return table.setColumnPinning(defaultState ? getDefaultPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultPinningState());
|
|
23428
|
+
},
|
|
23429
|
+
getIsSomeColumnsPinned: position => {
|
|
23430
|
+
var _pinningState$positio;
|
|
23431
|
+
const pinningState = table.getState().columnPinning;
|
|
23432
|
+
if (!position) {
|
|
23433
|
+
var _pinningState$left, _pinningState$right;
|
|
23434
|
+
return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
|
|
23435
|
+
}
|
|
23436
|
+
return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
|
|
23437
|
+
},
|
|
23438
|
+
getLeftLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
|
|
23439
|
+
return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
|
|
23440
|
+
}, {
|
|
23441
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
|
|
23442
|
+
debug: () => {
|
|
23443
|
+
var _table$options$debugA4;
|
|
23444
|
+
return (_table$options$debugA4 = table.options.debugAll) != null ? _table$options$debugA4 : table.options.debugColumns;
|
|
23445
|
+
}
|
|
23446
|
+
}),
|
|
23447
|
+
getRightLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
|
|
23448
|
+
return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
|
|
23449
|
+
}, {
|
|
23450
|
+
key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
|
|
23451
|
+
debug: () => {
|
|
23452
|
+
var _table$options$debugA5;
|
|
23453
|
+
return (_table$options$debugA5 = table.options.debugAll) != null ? _table$options$debugA5 : table.options.debugColumns;
|
|
23454
|
+
}
|
|
23455
|
+
}),
|
|
23456
|
+
getCenterLeafColumns: memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
|
|
23457
|
+
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
23458
|
+
return allColumns.filter(d => !leftAndRight.includes(d.id));
|
|
23459
|
+
}, {
|
|
23460
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
|
|
23461
|
+
debug: () => {
|
|
23462
|
+
var _table$options$debugA6;
|
|
23463
|
+
return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugColumns;
|
|
23464
|
+
}
|
|
23465
|
+
})
|
|
23466
|
+
};
|
|
23467
|
+
}
|
|
23468
|
+
};
|
|
23469
|
+
|
|
23470
|
+
//
|
|
23471
|
+
|
|
23472
|
+
const RowSelection = {
|
|
23473
|
+
getInitialState: state => {
|
|
23474
|
+
return {
|
|
23475
|
+
rowSelection: {},
|
|
23476
|
+
...state
|
|
23477
|
+
};
|
|
23478
|
+
},
|
|
23479
|
+
getDefaultOptions: table => {
|
|
23480
|
+
return {
|
|
23481
|
+
onRowSelectionChange: makeStateUpdater('rowSelection', table),
|
|
23482
|
+
enableRowSelection: true,
|
|
23483
|
+
enableMultiRowSelection: true,
|
|
23484
|
+
enableSubRowSelection: true
|
|
23485
|
+
// enableGroupingRowSelection: false,
|
|
23486
|
+
// isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
|
|
23487
|
+
// isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
|
|
23488
|
+
};
|
|
23489
|
+
},
|
|
23490
|
+
|
|
23491
|
+
createTable: table => {
|
|
23492
|
+
return {
|
|
23493
|
+
setRowSelection: updater => table.options.onRowSelectionChange == null ? void 0 : table.options.onRowSelectionChange(updater),
|
|
23494
|
+
resetRowSelection: defaultState => {
|
|
23495
|
+
var _table$initialState$r;
|
|
23496
|
+
return table.setRowSelection(defaultState ? {} : (_table$initialState$r = table.initialState.rowSelection) != null ? _table$initialState$r : {});
|
|
23497
|
+
},
|
|
23498
|
+
toggleAllRowsSelected: value => {
|
|
23499
|
+
table.setRowSelection(old => {
|
|
23500
|
+
value = typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected();
|
|
23501
|
+
const rowSelection = {
|
|
23502
|
+
...old
|
|
23503
|
+
};
|
|
23504
|
+
const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
|
|
23505
|
+
|
|
23506
|
+
// We don't use `mutateRowIsSelected` here for performance reasons.
|
|
23507
|
+
// All of the rows are flat already, so it wouldn't be worth it
|
|
23508
|
+
if (value) {
|
|
23509
|
+
preGroupedFlatRows.forEach(row => {
|
|
23510
|
+
if (!row.getCanSelect()) {
|
|
23511
|
+
return;
|
|
23512
|
+
}
|
|
23513
|
+
rowSelection[row.id] = true;
|
|
23514
|
+
});
|
|
23515
|
+
} else {
|
|
23516
|
+
preGroupedFlatRows.forEach(row => {
|
|
23517
|
+
delete rowSelection[row.id];
|
|
23518
|
+
});
|
|
23519
|
+
}
|
|
23520
|
+
return rowSelection;
|
|
23521
|
+
});
|
|
23522
|
+
},
|
|
23523
|
+
toggleAllPageRowsSelected: value => table.setRowSelection(old => {
|
|
23524
|
+
const resolvedValue = typeof value !== 'undefined' ? value : !table.getIsAllPageRowsSelected();
|
|
23525
|
+
const rowSelection = {
|
|
23526
|
+
...old
|
|
23527
|
+
};
|
|
23528
|
+
table.getRowModel().rows.forEach(row => {
|
|
23529
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, table);
|
|
23530
|
+
});
|
|
23531
|
+
return rowSelection;
|
|
23532
|
+
}),
|
|
23533
|
+
// addRowSelectionRange: rowId => {
|
|
23534
|
+
// const {
|
|
23535
|
+
// rows,
|
|
23536
|
+
// rowsById,
|
|
23537
|
+
// options: { selectGroupingRows, selectSubRows },
|
|
23538
|
+
// } = table
|
|
23539
|
+
|
|
23540
|
+
// const findSelectedRow = (rows: Row[]) => {
|
|
23541
|
+
// let found
|
|
23542
|
+
// rows.find(d => {
|
|
23543
|
+
// if (d.getIsSelected()) {
|
|
23544
|
+
// found = d
|
|
23545
|
+
// return true
|
|
23546
|
+
// }
|
|
23547
|
+
// const subFound = findSelectedRow(d.subRows || [])
|
|
23548
|
+
// if (subFound) {
|
|
23549
|
+
// found = subFound
|
|
23550
|
+
// return true
|
|
23551
|
+
// }
|
|
23552
|
+
// return false
|
|
23553
|
+
// })
|
|
23554
|
+
// return found
|
|
23555
|
+
// }
|
|
23556
|
+
|
|
23557
|
+
// const firstRow = findSelectedRow(rows) || rows[0]
|
|
23558
|
+
// const lastRow = rowsById[rowId]
|
|
23559
|
+
|
|
23560
|
+
// let include = false
|
|
23561
|
+
// const selectedRowIds = {}
|
|
23562
|
+
|
|
23563
|
+
// const addRow = (row: Row) => {
|
|
23564
|
+
// mutateRowIsSelected(selectedRowIds, row.id, true, {
|
|
23565
|
+
// rowsById,
|
|
23566
|
+
// selectGroupingRows: selectGroupingRows!,
|
|
23567
|
+
// selectSubRows: selectSubRows!,
|
|
23568
|
+
// })
|
|
23569
|
+
// }
|
|
23570
|
+
|
|
23571
|
+
// table.rows.forEach(row => {
|
|
23572
|
+
// const isFirstRow = row.id === firstRow.id
|
|
23573
|
+
// const isLastRow = row.id === lastRow.id
|
|
23574
|
+
|
|
23575
|
+
// if (isFirstRow || isLastRow) {
|
|
23576
|
+
// if (!include) {
|
|
23577
|
+
// include = true
|
|
23578
|
+
// } else if (include) {
|
|
23579
|
+
// addRow(row)
|
|
23580
|
+
// include = false
|
|
23581
|
+
// }
|
|
23582
|
+
// }
|
|
23583
|
+
|
|
23584
|
+
// if (include) {
|
|
23585
|
+
// addRow(row)
|
|
23586
|
+
// }
|
|
23587
|
+
// })
|
|
23588
|
+
|
|
23589
|
+
// table.setRowSelection(selectedRowIds)
|
|
23590
|
+
// },
|
|
23591
|
+
getPreSelectedRowModel: () => table.getCoreRowModel(),
|
|
23592
|
+
getSelectedRowModel: memo(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
|
|
23593
|
+
if (!Object.keys(rowSelection).length) {
|
|
23594
|
+
return {
|
|
23595
|
+
rows: [],
|
|
23596
|
+
flatRows: [],
|
|
23597
|
+
rowsById: {}
|
|
23598
|
+
};
|
|
23599
|
+
}
|
|
23600
|
+
return selectRowsFn(table, rowModel);
|
|
23601
|
+
}, {
|
|
23602
|
+
key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
|
|
23603
|
+
debug: () => {
|
|
23604
|
+
var _table$options$debugA;
|
|
23605
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugTable;
|
|
23606
|
+
}
|
|
23607
|
+
}),
|
|
23608
|
+
getFilteredSelectedRowModel: memo(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
|
|
23609
|
+
if (!Object.keys(rowSelection).length) {
|
|
23610
|
+
return {
|
|
23611
|
+
rows: [],
|
|
23612
|
+
flatRows: [],
|
|
23613
|
+
rowsById: {}
|
|
23614
|
+
};
|
|
23615
|
+
}
|
|
23616
|
+
return selectRowsFn(table, rowModel);
|
|
23617
|
+
}, {
|
|
23618
|
+
key: process.env.NODE_ENV === 'production' && 'getFilteredSelectedRowModel',
|
|
23619
|
+
debug: () => {
|
|
23620
|
+
var _table$options$debugA2;
|
|
23621
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugTable;
|
|
23622
|
+
}
|
|
23623
|
+
}),
|
|
23624
|
+
getGroupedSelectedRowModel: memo(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
|
|
23625
|
+
if (!Object.keys(rowSelection).length) {
|
|
23626
|
+
return {
|
|
23627
|
+
rows: [],
|
|
23628
|
+
flatRows: [],
|
|
23629
|
+
rowsById: {}
|
|
23630
|
+
};
|
|
23631
|
+
}
|
|
23632
|
+
return selectRowsFn(table, rowModel);
|
|
23633
|
+
}, {
|
|
23634
|
+
key: process.env.NODE_ENV === 'production' && 'getGroupedSelectedRowModel',
|
|
23635
|
+
debug: () => {
|
|
23636
|
+
var _table$options$debugA3;
|
|
23637
|
+
return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugTable;
|
|
23638
|
+
}
|
|
23639
|
+
}),
|
|
23640
|
+
///
|
|
23641
|
+
|
|
23642
|
+
// getGroupingRowCanSelect: rowId => {
|
|
23643
|
+
// const row = table.getRow(rowId)
|
|
23644
|
+
|
|
23645
|
+
// if (!row) {
|
|
23646
|
+
// throw new Error()
|
|
23647
|
+
// }
|
|
23648
|
+
|
|
23649
|
+
// if (typeof table.options.enableGroupingRowSelection === 'function') {
|
|
23650
|
+
// return table.options.enableGroupingRowSelection(row)
|
|
23651
|
+
// }
|
|
23652
|
+
|
|
23653
|
+
// return table.options.enableGroupingRowSelection ?? false
|
|
23654
|
+
// },
|
|
23655
|
+
|
|
23656
|
+
getIsAllRowsSelected: () => {
|
|
23657
|
+
const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
|
|
23658
|
+
const {
|
|
23659
|
+
rowSelection
|
|
23660
|
+
} = table.getState();
|
|
23661
|
+
let isAllRowsSelected = Boolean(preGroupedFlatRows.length && Object.keys(rowSelection).length);
|
|
23662
|
+
if (isAllRowsSelected) {
|
|
23663
|
+
if (preGroupedFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
|
|
23664
|
+
isAllRowsSelected = false;
|
|
23665
|
+
}
|
|
23666
|
+
}
|
|
23667
|
+
return isAllRowsSelected;
|
|
23668
|
+
},
|
|
23669
|
+
getIsAllPageRowsSelected: () => {
|
|
23670
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows;
|
|
23671
|
+
const {
|
|
23672
|
+
rowSelection
|
|
23673
|
+
} = table.getState();
|
|
23674
|
+
let isAllPageRowsSelected = !!paginationFlatRows.length;
|
|
23675
|
+
if (isAllPageRowsSelected && paginationFlatRows.some(row => !rowSelection[row.id])) {
|
|
23676
|
+
isAllPageRowsSelected = false;
|
|
23677
|
+
}
|
|
23678
|
+
return isAllPageRowsSelected;
|
|
23679
|
+
},
|
|
23680
|
+
getIsSomeRowsSelected: () => {
|
|
23681
|
+
var _table$getState$rowSe;
|
|
23682
|
+
const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
|
|
23683
|
+
return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
|
|
23684
|
+
},
|
|
23685
|
+
getIsSomePageRowsSelected: () => {
|
|
23686
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows;
|
|
23687
|
+
return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.some(d => d.getIsSelected() || d.getIsSomeSelected());
|
|
23688
|
+
},
|
|
23689
|
+
getToggleAllRowsSelectedHandler: () => {
|
|
23690
|
+
return e => {
|
|
23691
|
+
table.toggleAllRowsSelected(e.target.checked);
|
|
23692
|
+
};
|
|
23693
|
+
},
|
|
23694
|
+
getToggleAllPageRowsSelectedHandler: () => {
|
|
23695
|
+
return e => {
|
|
23696
|
+
table.toggleAllPageRowsSelected(e.target.checked);
|
|
23697
|
+
};
|
|
23698
|
+
}
|
|
23699
|
+
};
|
|
23700
|
+
},
|
|
23701
|
+
createRow: (row, table) => {
|
|
23702
|
+
return {
|
|
23703
|
+
toggleSelected: value => {
|
|
23704
|
+
const isSelected = row.getIsSelected();
|
|
23705
|
+
table.setRowSelection(old => {
|
|
23706
|
+
value = typeof value !== 'undefined' ? value : !isSelected;
|
|
23707
|
+
if (isSelected === value) {
|
|
23708
|
+
return old;
|
|
23709
|
+
}
|
|
23710
|
+
const selectedRowIds = {
|
|
23711
|
+
...old
|
|
23712
|
+
};
|
|
23713
|
+
mutateRowIsSelected(selectedRowIds, row.id, value, table);
|
|
23714
|
+
return selectedRowIds;
|
|
23715
|
+
});
|
|
23716
|
+
},
|
|
23717
|
+
getIsSelected: () => {
|
|
23718
|
+
const {
|
|
23719
|
+
rowSelection
|
|
23720
|
+
} = table.getState();
|
|
23721
|
+
return isRowSelected(row, rowSelection);
|
|
23722
|
+
},
|
|
23723
|
+
getIsSomeSelected: () => {
|
|
23724
|
+
const {
|
|
23725
|
+
rowSelection
|
|
23726
|
+
} = table.getState();
|
|
23727
|
+
return isSubRowSelected(row, rowSelection) === 'some';
|
|
23728
|
+
},
|
|
23729
|
+
getIsAllSubRowsSelected: () => {
|
|
23730
|
+
const {
|
|
23731
|
+
rowSelection
|
|
23732
|
+
} = table.getState();
|
|
23733
|
+
return isSubRowSelected(row, rowSelection) === 'all';
|
|
23734
|
+
},
|
|
23735
|
+
getCanSelect: () => {
|
|
23736
|
+
var _table$options$enable;
|
|
23737
|
+
if (typeof table.options.enableRowSelection === 'function') {
|
|
23738
|
+
return table.options.enableRowSelection(row);
|
|
23739
|
+
}
|
|
23740
|
+
return (_table$options$enable = table.options.enableRowSelection) != null ? _table$options$enable : true;
|
|
23741
|
+
},
|
|
23742
|
+
getCanSelectSubRows: () => {
|
|
23743
|
+
var _table$options$enable2;
|
|
23744
|
+
if (typeof table.options.enableSubRowSelection === 'function') {
|
|
23745
|
+
return table.options.enableSubRowSelection(row);
|
|
23746
|
+
}
|
|
23747
|
+
return (_table$options$enable2 = table.options.enableSubRowSelection) != null ? _table$options$enable2 : true;
|
|
23748
|
+
},
|
|
23749
|
+
getCanMultiSelect: () => {
|
|
23750
|
+
var _table$options$enable3;
|
|
23751
|
+
if (typeof table.options.enableMultiRowSelection === 'function') {
|
|
23752
|
+
return table.options.enableMultiRowSelection(row);
|
|
23753
|
+
}
|
|
23754
|
+
return (_table$options$enable3 = table.options.enableMultiRowSelection) != null ? _table$options$enable3 : true;
|
|
23755
|
+
},
|
|
23756
|
+
getToggleSelectedHandler: () => {
|
|
23757
|
+
const canSelect = row.getCanSelect();
|
|
23758
|
+
return e => {
|
|
23759
|
+
var _target;
|
|
23760
|
+
if (!canSelect) return;
|
|
23761
|
+
row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
|
|
23762
|
+
};
|
|
23763
|
+
}
|
|
23764
|
+
};
|
|
23765
|
+
}
|
|
23766
|
+
};
|
|
23767
|
+
const mutateRowIsSelected = (selectedRowIds, id, value, table) => {
|
|
23768
|
+
var _row$subRows;
|
|
23769
|
+
const row = table.getRow(id);
|
|
23770
|
+
|
|
23771
|
+
// const isGrouped = row.getIsGrouped()
|
|
23772
|
+
|
|
23773
|
+
// if ( // TODO: enforce grouping row selection rules
|
|
23774
|
+
// !isGrouped ||
|
|
23775
|
+
// (isGrouped && table.options.enableGroupingRowSelection)
|
|
23776
|
+
// ) {
|
|
23777
|
+
if (value) {
|
|
23778
|
+
if (!row.getCanMultiSelect()) {
|
|
23779
|
+
Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
|
|
23780
|
+
}
|
|
23781
|
+
if (row.getCanSelect()) {
|
|
23782
|
+
selectedRowIds[id] = true;
|
|
23783
|
+
}
|
|
23784
|
+
} else {
|
|
23785
|
+
delete selectedRowIds[id];
|
|
23786
|
+
}
|
|
23787
|
+
// }
|
|
23788
|
+
|
|
23789
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
|
|
23790
|
+
row.subRows.forEach(row => mutateRowIsSelected(selectedRowIds, row.id, value, table));
|
|
23791
|
+
}
|
|
23792
|
+
};
|
|
23793
|
+
function selectRowsFn(table, rowModel) {
|
|
23794
|
+
const rowSelection = table.getState().rowSelection;
|
|
23795
|
+
const newSelectedFlatRows = [];
|
|
23796
|
+
const newSelectedRowsById = {};
|
|
23797
|
+
|
|
23798
|
+
// Filters top level and nested rows
|
|
23799
|
+
const recurseRows = function (rows, depth) {
|
|
23800
|
+
return rows.map(row => {
|
|
23801
|
+
var _row$subRows2;
|
|
23802
|
+
const isSelected = isRowSelected(row, rowSelection);
|
|
23803
|
+
if (isSelected) {
|
|
23804
|
+
newSelectedFlatRows.push(row);
|
|
23805
|
+
newSelectedRowsById[row.id] = row;
|
|
23806
|
+
}
|
|
23807
|
+
if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
|
|
23808
|
+
row = {
|
|
23809
|
+
...row,
|
|
23810
|
+
subRows: recurseRows(row.subRows)
|
|
23811
|
+
};
|
|
23812
|
+
}
|
|
23813
|
+
if (isSelected) {
|
|
23814
|
+
return row;
|
|
23815
|
+
}
|
|
23816
|
+
}).filter(Boolean);
|
|
23817
|
+
};
|
|
23818
|
+
return {
|
|
23819
|
+
rows: recurseRows(rowModel.rows),
|
|
23820
|
+
flatRows: newSelectedFlatRows,
|
|
23821
|
+
rowsById: newSelectedRowsById
|
|
23822
|
+
};
|
|
23823
|
+
}
|
|
23824
|
+
function isRowSelected(row, selection) {
|
|
23825
|
+
var _selection$row$id;
|
|
23826
|
+
return (_selection$row$id = selection[row.id]) != null ? _selection$row$id : false;
|
|
23827
|
+
}
|
|
23828
|
+
function isSubRowSelected(row, selection, table) {
|
|
23829
|
+
if (row.subRows && row.subRows.length) {
|
|
23830
|
+
let allChildrenSelected = true;
|
|
23831
|
+
let someSelected = false;
|
|
23832
|
+
row.subRows.forEach(subRow => {
|
|
23833
|
+
// Bail out early if we know both of these
|
|
23834
|
+
if (someSelected && !allChildrenSelected) {
|
|
23835
|
+
return;
|
|
23836
|
+
}
|
|
23837
|
+
if (isRowSelected(subRow, selection)) {
|
|
23838
|
+
someSelected = true;
|
|
23839
|
+
} else {
|
|
23840
|
+
allChildrenSelected = false;
|
|
23841
|
+
}
|
|
23842
|
+
});
|
|
23843
|
+
return allChildrenSelected ? 'all' : someSelected ? 'some' : false;
|
|
23844
|
+
}
|
|
23845
|
+
return false;
|
|
23846
|
+
}
|
|
23847
|
+
|
|
23848
|
+
const reSplitAlphaNumeric = /([0-9]+)/gm;
|
|
23849
|
+
const alphanumeric = (rowA, rowB, columnId) => {
|
|
23850
|
+
return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
|
|
23851
|
+
};
|
|
23852
|
+
const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
|
|
23853
|
+
return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
|
|
23854
|
+
};
|
|
23855
|
+
|
|
23856
|
+
// The text filter is more basic (less numeric support)
|
|
23857
|
+
// but is much faster
|
|
23858
|
+
const text = (rowA, rowB, columnId) => {
|
|
23859
|
+
return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
|
|
23860
|
+
};
|
|
23861
|
+
|
|
23862
|
+
// The text filter is more basic (less numeric support)
|
|
23863
|
+
// but is much faster
|
|
23864
|
+
const textCaseSensitive = (rowA, rowB, columnId) => {
|
|
23865
|
+
return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
|
|
23866
|
+
};
|
|
23867
|
+
const datetime = (rowA, rowB, columnId) => {
|
|
23868
|
+
const a = rowA.getValue(columnId);
|
|
23869
|
+
const b = rowB.getValue(columnId);
|
|
23870
|
+
|
|
23871
|
+
// Can handle nullish values
|
|
23872
|
+
// Use > and < because == (and ===) doesn't work with
|
|
23873
|
+
// Date objects (would require calling getTime()).
|
|
23874
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
23875
|
+
};
|
|
23876
|
+
const basic = (rowA, rowB, columnId) => {
|
|
23877
|
+
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
|
|
23878
|
+
};
|
|
23879
|
+
|
|
23880
|
+
// Utils
|
|
23881
|
+
|
|
23882
|
+
function compareBasic(a, b) {
|
|
23883
|
+
return a === b ? 0 : a > b ? 1 : -1;
|
|
23884
|
+
}
|
|
23885
|
+
function toString(a) {
|
|
23886
|
+
if (typeof a === 'number') {
|
|
23887
|
+
if (isNaN(a) || a === Infinity || a === -Infinity) {
|
|
23888
|
+
return '';
|
|
23889
|
+
}
|
|
23890
|
+
return String(a);
|
|
23891
|
+
}
|
|
23892
|
+
if (typeof a === 'string') {
|
|
23893
|
+
return a;
|
|
23894
|
+
}
|
|
23895
|
+
return '';
|
|
23896
|
+
}
|
|
23897
|
+
|
|
23898
|
+
// Mixed sorting is slow, but very inclusive of many edge cases.
|
|
23899
|
+
// It handles numbers, mixed alphanumeric combinations, and even
|
|
23900
|
+
// null, undefined, and Infinity
|
|
23901
|
+
function compareAlphanumeric(aStr, bStr) {
|
|
23902
|
+
// Split on number groups, but keep the delimiter
|
|
23903
|
+
// Then remove falsey split values
|
|
23904
|
+
const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
|
|
23905
|
+
const b = bStr.split(reSplitAlphaNumeric).filter(Boolean);
|
|
23906
|
+
|
|
23907
|
+
// While
|
|
23908
|
+
while (a.length && b.length) {
|
|
23909
|
+
const aa = a.shift();
|
|
23910
|
+
const bb = b.shift();
|
|
23911
|
+
const an = parseInt(aa, 10);
|
|
23912
|
+
const bn = parseInt(bb, 10);
|
|
23913
|
+
const combo = [an, bn].sort();
|
|
23914
|
+
|
|
23915
|
+
// Both are string
|
|
23916
|
+
if (isNaN(combo[0])) {
|
|
23917
|
+
if (aa > bb) {
|
|
23918
|
+
return 1;
|
|
23919
|
+
}
|
|
23920
|
+
if (bb > aa) {
|
|
23921
|
+
return -1;
|
|
23922
|
+
}
|
|
23923
|
+
continue;
|
|
23924
|
+
}
|
|
23925
|
+
|
|
23926
|
+
// One is a string, one is a number
|
|
23927
|
+
if (isNaN(combo[1])) {
|
|
23928
|
+
return isNaN(an) ? -1 : 1;
|
|
23929
|
+
}
|
|
23930
|
+
|
|
23931
|
+
// Both are numbers
|
|
23932
|
+
if (an > bn) {
|
|
23933
|
+
return 1;
|
|
23934
|
+
}
|
|
23935
|
+
if (bn > an) {
|
|
23936
|
+
return -1;
|
|
23937
|
+
}
|
|
23938
|
+
}
|
|
23939
|
+
return a.length - b.length;
|
|
23940
|
+
}
|
|
23941
|
+
|
|
23942
|
+
// Exports
|
|
23943
|
+
|
|
23944
|
+
const sortingFns = {
|
|
23945
|
+
alphanumeric,
|
|
23946
|
+
alphanumericCaseSensitive,
|
|
23947
|
+
text,
|
|
23948
|
+
textCaseSensitive,
|
|
23949
|
+
datetime,
|
|
23950
|
+
basic
|
|
23951
|
+
};
|
|
23952
|
+
|
|
23953
|
+
//
|
|
23954
|
+
|
|
23955
|
+
const Sorting = {
|
|
23956
|
+
getInitialState: state => {
|
|
23957
|
+
return {
|
|
23958
|
+
sorting: [],
|
|
23959
|
+
...state
|
|
23960
|
+
};
|
|
23961
|
+
},
|
|
23962
|
+
getDefaultColumnDef: () => {
|
|
23963
|
+
return {
|
|
23964
|
+
sortingFn: 'auto'
|
|
23965
|
+
};
|
|
23966
|
+
},
|
|
23967
|
+
getDefaultOptions: table => {
|
|
23968
|
+
return {
|
|
23969
|
+
onSortingChange: makeStateUpdater('sorting', table),
|
|
23970
|
+
isMultiSortEvent: e => {
|
|
23971
|
+
return e.shiftKey;
|
|
23972
|
+
}
|
|
23973
|
+
};
|
|
23974
|
+
},
|
|
23975
|
+
createColumn: (column, table) => {
|
|
23976
|
+
return {
|
|
23977
|
+
getAutoSortingFn: () => {
|
|
23978
|
+
const firstRows = table.getFilteredRowModel().flatRows.slice(10);
|
|
23979
|
+
let isString = false;
|
|
23980
|
+
for (const row of firstRows) {
|
|
23981
|
+
const value = row == null ? void 0 : row.getValue(column.id);
|
|
23982
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
23983
|
+
return sortingFns.datetime;
|
|
23984
|
+
}
|
|
23985
|
+
if (typeof value === 'string') {
|
|
23986
|
+
isString = true;
|
|
23987
|
+
if (value.split(reSplitAlphaNumeric).length > 1) {
|
|
23988
|
+
return sortingFns.alphanumeric;
|
|
23989
|
+
}
|
|
23990
|
+
}
|
|
23991
|
+
}
|
|
23992
|
+
if (isString) {
|
|
23993
|
+
return sortingFns.text;
|
|
23994
|
+
}
|
|
23995
|
+
return sortingFns.basic;
|
|
23996
|
+
},
|
|
23997
|
+
getAutoSortDir: () => {
|
|
23998
|
+
const firstRow = table.getFilteredRowModel().flatRows[0];
|
|
23999
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
24000
|
+
if (typeof value === 'string') {
|
|
24001
|
+
return 'asc';
|
|
24002
|
+
}
|
|
24003
|
+
return 'desc';
|
|
24004
|
+
},
|
|
24005
|
+
getSortingFn: () => {
|
|
24006
|
+
var _table$options$sortin, _table$options$sortin2;
|
|
24007
|
+
if (!column) {
|
|
24008
|
+
throw new Error();
|
|
24009
|
+
}
|
|
24010
|
+
return isFunction(column.columnDef.sortingFn) ? column.columnDef.sortingFn : column.columnDef.sortingFn === 'auto' ? column.getAutoSortingFn() : (_table$options$sortin = (_table$options$sortin2 = table.options.sortingFns) == null ? void 0 : _table$options$sortin2[column.columnDef.sortingFn]) != null ? _table$options$sortin : sortingFns[column.columnDef.sortingFn];
|
|
24011
|
+
},
|
|
24012
|
+
toggleSorting: (desc, multi) => {
|
|
24013
|
+
// if (column.columns.length) {
|
|
24014
|
+
// column.columns.forEach((c, i) => {
|
|
24015
|
+
// if (c.id) {
|
|
24016
|
+
// table.toggleColumnSorting(c.id, undefined, multi || !!i)
|
|
24017
|
+
// }
|
|
24018
|
+
// })
|
|
24019
|
+
// return
|
|
24020
|
+
// }
|
|
24021
|
+
|
|
24022
|
+
// this needs to be outside of table.setSorting to be in sync with rerender
|
|
24023
|
+
const nextSortingOrder = column.getNextSortingOrder();
|
|
24024
|
+
const hasManualValue = typeof desc !== 'undefined' && desc !== null;
|
|
24025
|
+
table.setSorting(old => {
|
|
24026
|
+
// Find any existing sorting for this column
|
|
24027
|
+
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
24028
|
+
const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
|
|
24029
|
+
let newSorting = [];
|
|
24030
|
+
|
|
24031
|
+
// What should we do with this sort action?
|
|
24032
|
+
let sortAction;
|
|
24033
|
+
let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc';
|
|
24034
|
+
|
|
24035
|
+
// Multi-mode
|
|
24036
|
+
if (old != null && old.length && column.getCanMultiSort() && multi) {
|
|
24037
|
+
if (existingSorting) {
|
|
24038
|
+
sortAction = 'toggle';
|
|
24039
|
+
} else {
|
|
24040
|
+
sortAction = 'add';
|
|
24041
|
+
}
|
|
24042
|
+
} else {
|
|
24043
|
+
// Normal mode
|
|
24044
|
+
if (old != null && old.length && existingIndex !== old.length - 1) {
|
|
24045
|
+
sortAction = 'replace';
|
|
24046
|
+
} else if (existingSorting) {
|
|
24047
|
+
sortAction = 'toggle';
|
|
24048
|
+
} else {
|
|
24049
|
+
sortAction = 'replace';
|
|
24050
|
+
}
|
|
24051
|
+
}
|
|
24052
|
+
|
|
24053
|
+
// Handle toggle states that will remove the sorting
|
|
24054
|
+
if (sortAction === 'toggle') {
|
|
24055
|
+
// If we are "actually" toggling (not a manual set value), should we remove the sorting?
|
|
24056
|
+
if (!hasManualValue) {
|
|
24057
|
+
// Is our intention to remove?
|
|
24058
|
+
if (!nextSortingOrder) {
|
|
24059
|
+
sortAction = 'remove';
|
|
24060
|
+
}
|
|
24061
|
+
}
|
|
24062
|
+
}
|
|
24063
|
+
if (sortAction === 'add') {
|
|
24064
|
+
var _table$options$maxMul;
|
|
24065
|
+
newSorting = [...old, {
|
|
24066
|
+
id: column.id,
|
|
24067
|
+
desc: nextDesc
|
|
24068
|
+
}];
|
|
24069
|
+
// Take latest n columns
|
|
24070
|
+
newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
|
|
24071
|
+
} else if (sortAction === 'toggle') {
|
|
24072
|
+
// This flips (or sets) the
|
|
24073
|
+
newSorting = old.map(d => {
|
|
24074
|
+
if (d.id === column.id) {
|
|
24075
|
+
return {
|
|
24076
|
+
...d,
|
|
24077
|
+
desc: nextDesc
|
|
24078
|
+
};
|
|
24079
|
+
}
|
|
24080
|
+
return d;
|
|
24081
|
+
});
|
|
24082
|
+
} else if (sortAction === 'remove') {
|
|
24083
|
+
newSorting = old.filter(d => d.id !== column.id);
|
|
24084
|
+
} else {
|
|
24085
|
+
newSorting = [{
|
|
24086
|
+
id: column.id,
|
|
24087
|
+
desc: nextDesc
|
|
24088
|
+
}];
|
|
24089
|
+
}
|
|
24090
|
+
return newSorting;
|
|
24091
|
+
});
|
|
24092
|
+
},
|
|
24093
|
+
getFirstSortDir: () => {
|
|
24094
|
+
var _ref, _column$columnDef$sor;
|
|
24095
|
+
const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
|
|
24096
|
+
return sortDescFirst ? 'desc' : 'asc';
|
|
24097
|
+
},
|
|
24098
|
+
getNextSortingOrder: multi => {
|
|
24099
|
+
var _table$options$enable, _table$options$enable2;
|
|
24100
|
+
const firstSortDirection = column.getFirstSortDir();
|
|
24101
|
+
const isSorted = column.getIsSorted();
|
|
24102
|
+
if (!isSorted) {
|
|
24103
|
+
return firstSortDirection;
|
|
24104
|
+
}
|
|
24105
|
+
if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && (
|
|
24106
|
+
// If enableSortRemove, enable in general
|
|
24107
|
+
multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
|
|
24108
|
+
) {
|
|
24109
|
+
return false;
|
|
24110
|
+
}
|
|
24111
|
+
return isSorted === 'desc' ? 'asc' : 'desc';
|
|
24112
|
+
},
|
|
24113
|
+
getCanSort: () => {
|
|
24114
|
+
var _column$columnDef$ena, _table$options$enable3;
|
|
24115
|
+
return ((_column$columnDef$ena = column.columnDef.enableSorting) != null ? _column$columnDef$ena : true) && ((_table$options$enable3 = table.options.enableSorting) != null ? _table$options$enable3 : true) && !!column.accessorFn;
|
|
24116
|
+
},
|
|
24117
|
+
getCanMultiSort: () => {
|
|
24118
|
+
var _ref2, _column$columnDef$ena2;
|
|
24119
|
+
return (_ref2 = (_column$columnDef$ena2 = column.columnDef.enableMultiSort) != null ? _column$columnDef$ena2 : table.options.enableMultiSort) != null ? _ref2 : !!column.accessorFn;
|
|
24120
|
+
},
|
|
24121
|
+
getIsSorted: () => {
|
|
24122
|
+
var _table$getState$sorti;
|
|
24123
|
+
const columnSort = (_table$getState$sorti = table.getState().sorting) == null ? void 0 : _table$getState$sorti.find(d => d.id === column.id);
|
|
24124
|
+
return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
|
|
24125
|
+
},
|
|
24126
|
+
getSortIndex: () => {
|
|
24127
|
+
var _table$getState$sorti2, _table$getState$sorti3;
|
|
24128
|
+
return (_table$getState$sorti2 = (_table$getState$sorti3 = table.getState().sorting) == null ? void 0 : _table$getState$sorti3.findIndex(d => d.id === column.id)) != null ? _table$getState$sorti2 : -1;
|
|
24129
|
+
},
|
|
24130
|
+
clearSorting: () => {
|
|
24131
|
+
//clear sorting for just 1 column
|
|
24132
|
+
table.setSorting(old => old != null && old.length ? old.filter(d => d.id !== column.id) : []);
|
|
24133
|
+
},
|
|
24134
|
+
getToggleSortingHandler: () => {
|
|
24135
|
+
const canSort = column.getCanSort();
|
|
24136
|
+
return e => {
|
|
24137
|
+
if (!canSort) return;
|
|
24138
|
+
e.persist == null ? void 0 : e.persist();
|
|
24139
|
+
column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? table.options.isMultiSortEvent == null ? void 0 : table.options.isMultiSortEvent(e) : false);
|
|
24140
|
+
};
|
|
24141
|
+
}
|
|
24142
|
+
};
|
|
24143
|
+
},
|
|
24144
|
+
createTable: table => {
|
|
24145
|
+
return {
|
|
24146
|
+
setSorting: updater => table.options.onSortingChange == null ? void 0 : table.options.onSortingChange(updater),
|
|
24147
|
+
resetSorting: defaultState => {
|
|
24148
|
+
var _table$initialState$s, _table$initialState;
|
|
24149
|
+
table.setSorting(defaultState ? [] : (_table$initialState$s = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.sorting) != null ? _table$initialState$s : []);
|
|
24150
|
+
},
|
|
24151
|
+
getPreSortedRowModel: () => table.getGroupedRowModel(),
|
|
24152
|
+
getSortedRowModel: () => {
|
|
24153
|
+
if (!table._getSortedRowModel && table.options.getSortedRowModel) {
|
|
24154
|
+
table._getSortedRowModel = table.options.getSortedRowModel(table);
|
|
24155
|
+
}
|
|
24156
|
+
if (table.options.manualSorting || !table._getSortedRowModel) {
|
|
24157
|
+
return table.getPreSortedRowModel();
|
|
24158
|
+
}
|
|
24159
|
+
return table._getSortedRowModel();
|
|
24160
|
+
}
|
|
24161
|
+
};
|
|
24162
|
+
}
|
|
24163
|
+
};
|
|
24164
|
+
|
|
24165
|
+
//
|
|
24166
|
+
|
|
24167
|
+
const Visibility = {
|
|
24168
|
+
getInitialState: state => {
|
|
24169
|
+
return {
|
|
24170
|
+
columnVisibility: {},
|
|
24171
|
+
...state
|
|
24172
|
+
};
|
|
24173
|
+
},
|
|
24174
|
+
getDefaultOptions: table => {
|
|
24175
|
+
return {
|
|
24176
|
+
onColumnVisibilityChange: makeStateUpdater('columnVisibility', table)
|
|
24177
|
+
};
|
|
24178
|
+
},
|
|
24179
|
+
createColumn: (column, table) => {
|
|
24180
|
+
return {
|
|
24181
|
+
toggleVisibility: value => {
|
|
24182
|
+
if (column.getCanHide()) {
|
|
24183
|
+
table.setColumnVisibility(old => ({
|
|
24184
|
+
...old,
|
|
24185
|
+
[column.id]: value != null ? value : !column.getIsVisible()
|
|
24186
|
+
}));
|
|
24187
|
+
}
|
|
24188
|
+
},
|
|
24189
|
+
getIsVisible: () => {
|
|
24190
|
+
var _table$getState$colum, _table$getState$colum2;
|
|
24191
|
+
return (_table$getState$colum = (_table$getState$colum2 = table.getState().columnVisibility) == null ? void 0 : _table$getState$colum2[column.id]) != null ? _table$getState$colum : true;
|
|
24192
|
+
},
|
|
24193
|
+
getCanHide: () => {
|
|
24194
|
+
var _column$columnDef$ena, _table$options$enable;
|
|
24195
|
+
return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableHiding) != null ? _table$options$enable : true);
|
|
24196
|
+
},
|
|
24197
|
+
getToggleVisibilityHandler: () => {
|
|
24198
|
+
return e => {
|
|
24199
|
+
column.toggleVisibility == null ? void 0 : column.toggleVisibility(e.target.checked);
|
|
24200
|
+
};
|
|
24201
|
+
}
|
|
24202
|
+
};
|
|
24203
|
+
},
|
|
24204
|
+
createRow: (row, table) => {
|
|
24205
|
+
return {
|
|
24206
|
+
_getAllVisibleCells: memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
|
|
24207
|
+
return cells.filter(cell => cell.column.getIsVisible());
|
|
24208
|
+
}, {
|
|
24209
|
+
key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
|
|
24210
|
+
debug: () => {
|
|
24211
|
+
var _table$options$debugA;
|
|
24212
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
|
|
24213
|
+
}
|
|
24214
|
+
}),
|
|
24215
|
+
getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
|
|
24216
|
+
key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
|
|
24217
|
+
debug: () => {
|
|
24218
|
+
var _table$options$debugA2;
|
|
24219
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
|
|
24220
|
+
}
|
|
24221
|
+
})
|
|
24222
|
+
};
|
|
24223
|
+
},
|
|
24224
|
+
createTable: table => {
|
|
24225
|
+
const makeVisibleColumnsMethod = (key, getColumns) => {
|
|
24226
|
+
return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
|
|
24227
|
+
return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
|
|
24228
|
+
}, {
|
|
24229
|
+
key,
|
|
24230
|
+
debug: () => {
|
|
24231
|
+
var _table$options$debugA3;
|
|
24232
|
+
return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugColumns;
|
|
24233
|
+
}
|
|
24234
|
+
});
|
|
24235
|
+
};
|
|
24236
|
+
return {
|
|
24237
|
+
getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => table.getAllFlatColumns()),
|
|
24238
|
+
getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => table.getAllLeafColumns()),
|
|
24239
|
+
getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => table.getLeftLeafColumns()),
|
|
24240
|
+
getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => table.getRightLeafColumns()),
|
|
24241
|
+
getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => table.getCenterLeafColumns()),
|
|
24242
|
+
setColumnVisibility: updater => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater),
|
|
24243
|
+
resetColumnVisibility: defaultState => {
|
|
24244
|
+
var _table$initialState$c;
|
|
24245
|
+
table.setColumnVisibility(defaultState ? {} : (_table$initialState$c = table.initialState.columnVisibility) != null ? _table$initialState$c : {});
|
|
24246
|
+
},
|
|
24247
|
+
toggleAllColumnsVisible: value => {
|
|
24248
|
+
var _value;
|
|
24249
|
+
value = (_value = value) != null ? _value : !table.getIsAllColumnsVisible();
|
|
24250
|
+
table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
|
|
24251
|
+
...obj,
|
|
24252
|
+
[column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
|
|
24253
|
+
}), {}));
|
|
24254
|
+
},
|
|
24255
|
+
getIsAllColumnsVisible: () => !table.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
|
|
24256
|
+
getIsSomeColumnsVisible: () => table.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
|
|
24257
|
+
getToggleAllColumnsVisibilityHandler: () => {
|
|
24258
|
+
return e => {
|
|
24259
|
+
var _target;
|
|
24260
|
+
table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
|
|
24261
|
+
};
|
|
24262
|
+
}
|
|
24263
|
+
};
|
|
24264
|
+
}
|
|
24265
|
+
};
|
|
24266
|
+
|
|
24267
|
+
const features = [Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing];
|
|
24268
|
+
|
|
24269
|
+
//
|
|
24270
|
+
|
|
24271
|
+
function createTable(options) {
|
|
24272
|
+
var _options$initialState;
|
|
24273
|
+
if (options.debugAll || options.debugTable) {
|
|
24274
|
+
console.info('Creating Table Instance...');
|
|
24275
|
+
}
|
|
24276
|
+
let table = {
|
|
24277
|
+
_features: features
|
|
24278
|
+
};
|
|
24279
|
+
const defaultOptions = table._features.reduce((obj, feature) => {
|
|
24280
|
+
return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(table));
|
|
24281
|
+
}, {});
|
|
24282
|
+
const mergeOptions = options => {
|
|
24283
|
+
if (table.options.mergeOptions) {
|
|
24284
|
+
return table.options.mergeOptions(defaultOptions, options);
|
|
24285
|
+
}
|
|
24286
|
+
return {
|
|
24287
|
+
...defaultOptions,
|
|
24288
|
+
...options
|
|
24289
|
+
};
|
|
24290
|
+
};
|
|
24291
|
+
const coreInitialState = {};
|
|
24292
|
+
let initialState = {
|
|
24293
|
+
...coreInitialState,
|
|
24294
|
+
...((_options$initialState = options.initialState) != null ? _options$initialState : {})
|
|
24295
|
+
};
|
|
24296
|
+
table._features.forEach(feature => {
|
|
24297
|
+
var _feature$getInitialSt;
|
|
24298
|
+
initialState = (_feature$getInitialSt = feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) != null ? _feature$getInitialSt : initialState;
|
|
24299
|
+
});
|
|
24300
|
+
const queued = [];
|
|
24301
|
+
let queuedTimeout = false;
|
|
24302
|
+
const coreInstance = {
|
|
24303
|
+
_features: features,
|
|
24304
|
+
options: {
|
|
24305
|
+
...defaultOptions,
|
|
24306
|
+
...options
|
|
24307
|
+
},
|
|
24308
|
+
initialState,
|
|
24309
|
+
_queue: cb => {
|
|
24310
|
+
queued.push(cb);
|
|
24311
|
+
if (!queuedTimeout) {
|
|
24312
|
+
queuedTimeout = true;
|
|
24313
|
+
|
|
24314
|
+
// Schedule a microtask to run the queued callbacks after
|
|
24315
|
+
// the current call stack (render, etc) has finished.
|
|
24316
|
+
Promise.resolve().then(() => {
|
|
24317
|
+
while (queued.length) {
|
|
24318
|
+
queued.shift()();
|
|
24319
|
+
}
|
|
24320
|
+
queuedTimeout = false;
|
|
24321
|
+
}).catch(error => setTimeout(() => {
|
|
24322
|
+
throw error;
|
|
24323
|
+
}));
|
|
24324
|
+
}
|
|
24325
|
+
},
|
|
24326
|
+
reset: () => {
|
|
24327
|
+
table.setState(table.initialState);
|
|
24328
|
+
},
|
|
24329
|
+
setOptions: updater => {
|
|
24330
|
+
const newOptions = functionalUpdate(updater, table.options);
|
|
24331
|
+
table.options = mergeOptions(newOptions);
|
|
24332
|
+
},
|
|
24333
|
+
getState: () => {
|
|
24334
|
+
return table.options.state;
|
|
24335
|
+
},
|
|
24336
|
+
setState: updater => {
|
|
24337
|
+
table.options.onStateChange == null ? void 0 : table.options.onStateChange(updater);
|
|
24338
|
+
},
|
|
24339
|
+
_getRowId: (row, index, parent) => {
|
|
24340
|
+
var _table$options$getRow;
|
|
24341
|
+
return (_table$options$getRow = table.options.getRowId == null ? void 0 : table.options.getRowId(row, index, parent)) != null ? _table$options$getRow : `${parent ? [parent.id, index].join('.') : index}`;
|
|
24342
|
+
},
|
|
24343
|
+
getCoreRowModel: () => {
|
|
24344
|
+
if (!table._getCoreRowModel) {
|
|
24345
|
+
table._getCoreRowModel = table.options.getCoreRowModel(table);
|
|
24346
|
+
}
|
|
24347
|
+
return table._getCoreRowModel();
|
|
24348
|
+
},
|
|
24349
|
+
// The final calls start at the bottom of the model,
|
|
24350
|
+
// expanded rows, which then work their way up
|
|
24351
|
+
|
|
24352
|
+
getRowModel: () => {
|
|
24353
|
+
return table.getPaginationRowModel();
|
|
24354
|
+
},
|
|
24355
|
+
getRow: id => {
|
|
24356
|
+
const row = table.getRowModel().rowsById[id];
|
|
24357
|
+
if (!row) {
|
|
24358
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
24359
|
+
throw new Error(`getRow expected an ID, but got ${id}`);
|
|
24360
|
+
}
|
|
24361
|
+
throw new Error();
|
|
24362
|
+
}
|
|
24363
|
+
return row;
|
|
24364
|
+
},
|
|
24365
|
+
_getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
|
|
24366
|
+
var _defaultColumn;
|
|
24367
|
+
defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
|
|
24368
|
+
return {
|
|
24369
|
+
header: props => {
|
|
24370
|
+
const resolvedColumnDef = props.header.column.columnDef;
|
|
24371
|
+
if (resolvedColumnDef.accessorKey) {
|
|
24372
|
+
return resolvedColumnDef.accessorKey;
|
|
24373
|
+
}
|
|
24374
|
+
if (resolvedColumnDef.accessorFn) {
|
|
24375
|
+
return resolvedColumnDef.id;
|
|
24376
|
+
}
|
|
24377
|
+
return null;
|
|
24378
|
+
},
|
|
24379
|
+
// footer: props => props.header.column.id,
|
|
24380
|
+
cell: props => {
|
|
24381
|
+
var _props$renderValue$to, _props$renderValue;
|
|
24382
|
+
return (_props$renderValue$to = (_props$renderValue = props.renderValue()) == null ? void 0 : _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) != null ? _props$renderValue$to : null;
|
|
24383
|
+
},
|
|
24384
|
+
...table._features.reduce((obj, feature) => {
|
|
24385
|
+
return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
|
|
24386
|
+
}, {}),
|
|
24387
|
+
...defaultColumn
|
|
24388
|
+
};
|
|
24389
|
+
}, {
|
|
24390
|
+
debug: () => {
|
|
24391
|
+
var _table$options$debugA;
|
|
24392
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugColumns;
|
|
24393
|
+
},
|
|
24394
|
+
key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
|
|
24395
|
+
}),
|
|
24396
|
+
_getColumnDefs: () => table.options.columns,
|
|
24397
|
+
getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
|
|
24398
|
+
const recurseColumns = function (columnDefs, parent, depth) {
|
|
24399
|
+
if (depth === void 0) {
|
|
24400
|
+
depth = 0;
|
|
24401
|
+
}
|
|
24402
|
+
return columnDefs.map(columnDef => {
|
|
24403
|
+
const column = createColumn(table, columnDef, depth, parent);
|
|
24404
|
+
const groupingColumnDef = columnDef;
|
|
24405
|
+
column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
|
|
24406
|
+
return column;
|
|
24407
|
+
});
|
|
24408
|
+
};
|
|
24409
|
+
return recurseColumns(columnDefs);
|
|
24410
|
+
}, {
|
|
24411
|
+
key: process.env.NODE_ENV === 'development' && 'getAllColumns',
|
|
24412
|
+
debug: () => {
|
|
24413
|
+
var _table$options$debugA2;
|
|
24414
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugColumns;
|
|
24415
|
+
}
|
|
24416
|
+
}),
|
|
24417
|
+
getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
|
|
24418
|
+
return allColumns.flatMap(column => {
|
|
24419
|
+
return column.getFlatColumns();
|
|
24420
|
+
});
|
|
24421
|
+
}, {
|
|
24422
|
+
key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
|
|
24423
|
+
debug: () => {
|
|
24424
|
+
var _table$options$debugA3;
|
|
24425
|
+
return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugColumns;
|
|
24426
|
+
}
|
|
24427
|
+
}),
|
|
24428
|
+
_getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
|
|
24429
|
+
return flatColumns.reduce((acc, column) => {
|
|
24430
|
+
acc[column.id] = column;
|
|
24431
|
+
return acc;
|
|
24432
|
+
}, {});
|
|
24433
|
+
}, {
|
|
24434
|
+
key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
|
|
24435
|
+
debug: () => {
|
|
24436
|
+
var _table$options$debugA4;
|
|
24437
|
+
return (_table$options$debugA4 = table.options.debugAll) != null ? _table$options$debugA4 : table.options.debugColumns;
|
|
24438
|
+
}
|
|
24439
|
+
}),
|
|
24440
|
+
getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
|
|
24441
|
+
let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
|
|
24442
|
+
return orderColumns(leafColumns);
|
|
24443
|
+
}, {
|
|
24444
|
+
key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
|
|
24445
|
+
debug: () => {
|
|
24446
|
+
var _table$options$debugA5;
|
|
24447
|
+
return (_table$options$debugA5 = table.options.debugAll) != null ? _table$options$debugA5 : table.options.debugColumns;
|
|
24448
|
+
}
|
|
24449
|
+
}),
|
|
24450
|
+
getColumn: columnId => {
|
|
24451
|
+
const column = table._getAllFlatColumnsById()[columnId];
|
|
24452
|
+
if (!column) {
|
|
24453
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
24454
|
+
console.warn(`[Table] Column with id ${columnId} does not exist.`);
|
|
24455
|
+
}
|
|
24456
|
+
throw new Error();
|
|
24457
|
+
}
|
|
24458
|
+
return column;
|
|
24459
|
+
}
|
|
24460
|
+
};
|
|
24461
|
+
Object.assign(table, coreInstance);
|
|
24462
|
+
table._features.forEach(feature => {
|
|
24463
|
+
return Object.assign(table, feature.createTable == null ? void 0 : feature.createTable(table));
|
|
24464
|
+
});
|
|
24465
|
+
return table;
|
|
24466
|
+
}
|
|
24467
|
+
|
|
24468
|
+
function createCell(table, row, column, columnId) {
|
|
24469
|
+
const getRenderValue = () => {
|
|
24470
|
+
var _cell$getValue;
|
|
24471
|
+
return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : table.options.renderFallbackValue;
|
|
24472
|
+
};
|
|
24473
|
+
const cell = {
|
|
24474
|
+
id: `${row.id}_${column.id}`,
|
|
24475
|
+
row,
|
|
24476
|
+
column,
|
|
24477
|
+
getValue: () => row.getValue(columnId),
|
|
24478
|
+
renderValue: getRenderValue,
|
|
24479
|
+
getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
|
|
24480
|
+
table,
|
|
24481
|
+
column,
|
|
24482
|
+
row,
|
|
24483
|
+
cell: cell,
|
|
24484
|
+
getValue: cell.getValue,
|
|
24485
|
+
renderValue: cell.renderValue
|
|
24486
|
+
}), {
|
|
24487
|
+
key: process.env.NODE_ENV === 'development' && 'cell.getContext',
|
|
24488
|
+
debug: () => table.options.debugAll
|
|
24489
|
+
})
|
|
24490
|
+
};
|
|
24491
|
+
table._features.forEach(feature => {
|
|
24492
|
+
Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, table));
|
|
24493
|
+
}, {});
|
|
24494
|
+
return cell;
|
|
24495
|
+
}
|
|
24496
|
+
|
|
24497
|
+
const createRow = (table, id, original, rowIndex, depth, subRows) => {
|
|
24498
|
+
let row = {
|
|
24499
|
+
id,
|
|
24500
|
+
index: rowIndex,
|
|
24501
|
+
original,
|
|
24502
|
+
depth,
|
|
24503
|
+
_valuesCache: {},
|
|
24504
|
+
_uniqueValuesCache: {},
|
|
24505
|
+
getValue: columnId => {
|
|
24506
|
+
if (row._valuesCache.hasOwnProperty(columnId)) {
|
|
24507
|
+
return row._valuesCache[columnId];
|
|
24508
|
+
}
|
|
24509
|
+
const column = table.getColumn(columnId);
|
|
24510
|
+
if (!column.accessorFn) {
|
|
24511
|
+
return undefined;
|
|
24512
|
+
}
|
|
24513
|
+
row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
|
|
24514
|
+
return row._valuesCache[columnId];
|
|
24515
|
+
},
|
|
24516
|
+
getUniqueValues: columnId => {
|
|
24517
|
+
if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
|
|
24518
|
+
return row._uniqueValuesCache[columnId];
|
|
24519
|
+
}
|
|
24520
|
+
const column = table.getColumn(columnId);
|
|
24521
|
+
if (!column.accessorFn) {
|
|
24522
|
+
return undefined;
|
|
24523
|
+
}
|
|
24524
|
+
if (!column.columnDef.getUniqueValues) {
|
|
24525
|
+
row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
|
|
24526
|
+
return row._uniqueValuesCache[columnId];
|
|
24527
|
+
}
|
|
24528
|
+
row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
|
|
24529
|
+
return row._uniqueValuesCache[columnId];
|
|
24530
|
+
},
|
|
24531
|
+
renderValue: columnId => {
|
|
24532
|
+
var _row$getValue;
|
|
24533
|
+
return (_row$getValue = row.getValue(columnId)) != null ? _row$getValue : table.options.renderFallbackValue;
|
|
24534
|
+
},
|
|
24535
|
+
subRows: subRows != null ? subRows : [],
|
|
24536
|
+
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
24537
|
+
getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
|
|
24538
|
+
return leafColumns.map(column => {
|
|
24539
|
+
return createCell(table, row, column, column.id);
|
|
24540
|
+
});
|
|
24541
|
+
}, {
|
|
24542
|
+
key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
|
|
24543
|
+
debug: () => {
|
|
24544
|
+
var _table$options$debugA;
|
|
24545
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
|
|
24546
|
+
}
|
|
24547
|
+
}),
|
|
24548
|
+
_getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
|
|
24549
|
+
return allCells.reduce((acc, cell) => {
|
|
24550
|
+
acc[cell.column.id] = cell;
|
|
24551
|
+
return acc;
|
|
24552
|
+
}, {});
|
|
24553
|
+
}, {
|
|
24554
|
+
key: process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
|
|
24555
|
+
debug: () => {
|
|
24556
|
+
var _table$options$debugA2;
|
|
24557
|
+
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
|
|
24558
|
+
}
|
|
24559
|
+
})
|
|
24560
|
+
};
|
|
24561
|
+
for (let i = 0; i < table._features.length; i++) {
|
|
24562
|
+
const feature = table._features[i];
|
|
24563
|
+
Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, table));
|
|
24564
|
+
}
|
|
24565
|
+
return row;
|
|
24566
|
+
};
|
|
24567
|
+
|
|
24568
|
+
function getCoreRowModel() {
|
|
24569
|
+
return table => memo(() => [table.options.data], data => {
|
|
24570
|
+
const rowModel = {
|
|
24571
|
+
rows: [],
|
|
24572
|
+
flatRows: [],
|
|
24573
|
+
rowsById: {}
|
|
24574
|
+
};
|
|
24575
|
+
const accessRows = function (originalRows, depth, parent) {
|
|
24576
|
+
if (depth === void 0) {
|
|
24577
|
+
depth = 0;
|
|
24578
|
+
}
|
|
24579
|
+
const rows = [];
|
|
24580
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
24581
|
+
// This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
24582
|
+
// if (!id) {
|
|
24583
|
+
// if (process.env.NODE_ENV !== 'production') {
|
|
24584
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
24585
|
+
// }
|
|
24586
|
+
// }
|
|
24587
|
+
|
|
24588
|
+
// Make the row
|
|
24589
|
+
const row = createRow(table, table._getRowId(originalRows[i], i, parent), originalRows[i], i, depth);
|
|
24590
|
+
|
|
24591
|
+
// Keep track of every row in a flat array
|
|
24592
|
+
rowModel.flatRows.push(row);
|
|
24593
|
+
// Also keep track of every row by its ID
|
|
24594
|
+
rowModel.rowsById[row.id] = row;
|
|
24595
|
+
// Push table row into parent
|
|
24596
|
+
rows.push(row);
|
|
24597
|
+
|
|
24598
|
+
// Get the original subrows
|
|
24599
|
+
if (table.options.getSubRows) {
|
|
24600
|
+
var _row$originalSubRows;
|
|
24601
|
+
row.originalSubRows = table.options.getSubRows(originalRows[i], i);
|
|
24602
|
+
|
|
24603
|
+
// Then recursively access them
|
|
24604
|
+
if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
|
|
24605
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row);
|
|
24606
|
+
}
|
|
24607
|
+
}
|
|
24608
|
+
}
|
|
24609
|
+
return rows;
|
|
24610
|
+
};
|
|
24611
|
+
rowModel.rows = accessRows(data);
|
|
24612
|
+
return rowModel;
|
|
24613
|
+
}, {
|
|
24614
|
+
key: process.env.NODE_ENV === 'development' && 'getRowModel',
|
|
24615
|
+
debug: () => {
|
|
24616
|
+
var _table$options$debugA;
|
|
24617
|
+
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugTable;
|
|
24618
|
+
},
|
|
24619
|
+
onChange: () => {
|
|
24620
|
+
table._autoResetPageIndex();
|
|
24621
|
+
}
|
|
24622
|
+
});
|
|
24623
|
+
}
|
|
24624
|
+
|
|
21677
24625
|
const styles$9 = css `
|
|
21678
24626
|
${display('flex')}
|
|
24627
|
+
|
|
24628
|
+
.table-container {
|
|
24629
|
+
width: 100%;
|
|
24630
|
+
height: 100%;
|
|
24631
|
+
font: ${bodyFont};
|
|
24632
|
+
color: ${bodyFontColor};
|
|
24633
|
+
}
|
|
24634
|
+
|
|
24635
|
+
.table-header {
|
|
24636
|
+
display: flex;
|
|
24637
|
+
flex-direction: row;
|
|
24638
|
+
}
|
|
24639
|
+
|
|
24640
|
+
.table-row {
|
|
24641
|
+
display: flex;
|
|
24642
|
+
flex-direction: row;
|
|
24643
|
+
}
|
|
24644
|
+
|
|
24645
|
+
.table-cell {
|
|
24646
|
+
flex: 1;
|
|
24647
|
+
}
|
|
21679
24648
|
`;
|
|
21680
24649
|
|
|
21681
|
-
|
|
24650
|
+
// prettier-ignore
|
|
24651
|
+
const template$3 = html `
|
|
24652
|
+
<template>
|
|
24653
|
+
<div class="table-container">
|
|
24654
|
+
<div class="table-header">
|
|
24655
|
+
${repeat(x => x.columnHeaders, html `
|
|
24656
|
+
<span class="table-cell">${x => x}</span>
|
|
24657
|
+
`)}
|
|
24658
|
+
</div>
|
|
24659
|
+
<div class="table-viewport">
|
|
24660
|
+
${repeat(x => x.tableData, html `
|
|
24661
|
+
<div class="table-row">
|
|
24662
|
+
${repeat(x => x, html `
|
|
24663
|
+
<span class="table-cell">${x => x}</span>
|
|
24664
|
+
`)}
|
|
24665
|
+
</div>
|
|
24666
|
+
`)}
|
|
24667
|
+
</div>
|
|
24668
|
+
</div>
|
|
24669
|
+
</template>
|
|
24670
|
+
`;
|
|
21682
24671
|
|
|
21683
24672
|
/**
|
|
21684
24673
|
* A nimble-styled table.
|
|
21685
24674
|
*/
|
|
21686
24675
|
class Table extends FoundationElement {
|
|
24676
|
+
constructor() {
|
|
24677
|
+
super();
|
|
24678
|
+
this.data = [];
|
|
24679
|
+
// TODO: Temporarily expose the table data as arrays of strings.
|
|
24680
|
+
this.tableData = [];
|
|
24681
|
+
// TODO: Temporarily expose the column headers as a string array.
|
|
24682
|
+
this.columnHeaders = [];
|
|
24683
|
+
this.tableInitialized = false;
|
|
24684
|
+
this.update = (state) => {
|
|
24685
|
+
this.table.setOptions(prev => ({
|
|
24686
|
+
...prev,
|
|
24687
|
+
...this.options,
|
|
24688
|
+
state,
|
|
24689
|
+
onStateChange: (updater) => {
|
|
24690
|
+
const updatedState = typeof updater === 'function'
|
|
24691
|
+
? updater(state)
|
|
24692
|
+
: updater;
|
|
24693
|
+
this.update(updatedState);
|
|
24694
|
+
}
|
|
24695
|
+
}));
|
|
24696
|
+
};
|
|
24697
|
+
this.options = {
|
|
24698
|
+
data: [],
|
|
24699
|
+
onStateChange: (_) => { },
|
|
24700
|
+
getCoreRowModel: getCoreRowModel(),
|
|
24701
|
+
columns: [],
|
|
24702
|
+
state: {},
|
|
24703
|
+
renderFallbackValue: null,
|
|
24704
|
+
autoResetAll: false
|
|
24705
|
+
};
|
|
24706
|
+
this.table = createTable(this.options);
|
|
24707
|
+
this.tableInitialized = true;
|
|
24708
|
+
}
|
|
24709
|
+
dataChanged(prev, next) {
|
|
24710
|
+
if ((!prev || prev.length === 0) && next && next.length > 0) {
|
|
24711
|
+
this.generateColumns();
|
|
24712
|
+
}
|
|
24713
|
+
// Ignore any updates that occur prior to the TanStack table being initialized.
|
|
24714
|
+
if (this.tableInitialized) {
|
|
24715
|
+
this.updateTableOptions({ data: this.data });
|
|
24716
|
+
this.refreshRows();
|
|
24717
|
+
}
|
|
24718
|
+
}
|
|
24719
|
+
// TODO: For now, assume all cells can be rendered as strings. Ultimately, the data
|
|
24720
|
+
// should be passed to nimble-row elements to use the view template from a column definition.
|
|
24721
|
+
refreshRows() {
|
|
24722
|
+
const tableData = [];
|
|
24723
|
+
const rows = this.table.getRowModel().rows;
|
|
24724
|
+
for (const row of rows) {
|
|
24725
|
+
const rowArray = [];
|
|
24726
|
+
for (const cell of row.getVisibleCells()) {
|
|
24727
|
+
const cellValue = cell.getValue();
|
|
24728
|
+
const stringValue = cellValue == null ? '' : cellValue.toString();
|
|
24729
|
+
rowArray.push(stringValue);
|
|
24730
|
+
}
|
|
24731
|
+
tableData.push(rowArray);
|
|
24732
|
+
}
|
|
24733
|
+
this.tableData = tableData;
|
|
24734
|
+
}
|
|
24735
|
+
updateTableOptions(updatedOptions) {
|
|
24736
|
+
this.options = { ...this.options, ...updatedOptions };
|
|
24737
|
+
this.update(this.table.initialState);
|
|
24738
|
+
}
|
|
24739
|
+
// Temporarily auto-detect the keys in TData to make columns.
|
|
24740
|
+
// TODO: Remove this logic when another way to specify columns is provided.
|
|
24741
|
+
generateColumns() {
|
|
24742
|
+
if (this.data.length === 0) {
|
|
24743
|
+
return;
|
|
24744
|
+
}
|
|
24745
|
+
const firstItem = this.data[0];
|
|
24746
|
+
const keys = Object.keys(firstItem);
|
|
24747
|
+
const generatedColumns = keys.map(key => {
|
|
24748
|
+
const columnDef = {
|
|
24749
|
+
id: key,
|
|
24750
|
+
accessorKey: key,
|
|
24751
|
+
header: key
|
|
24752
|
+
};
|
|
24753
|
+
return columnDef;
|
|
24754
|
+
});
|
|
24755
|
+
this.updateTableOptions({ columns: generatedColumns });
|
|
24756
|
+
this.columnHeaders = generatedColumns.map(x => x.header);
|
|
24757
|
+
}
|
|
21687
24758
|
}
|
|
24759
|
+
__decorate([
|
|
24760
|
+
observable
|
|
24761
|
+
], Table.prototype, "data", void 0);
|
|
24762
|
+
__decorate([
|
|
24763
|
+
observable
|
|
24764
|
+
], Table.prototype, "tableData", void 0);
|
|
24765
|
+
__decorate([
|
|
24766
|
+
observable
|
|
24767
|
+
], Table.prototype, "columnHeaders", void 0);
|
|
21688
24768
|
const nimbleTable = Table.compose({
|
|
21689
24769
|
baseName: 'table',
|
|
21690
24770
|
template: template$3,
|