@tanstack/react-table 8.0.0-alpha.5 → 8.0.0-alpha.8
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/build/cjs/core.js +19 -11
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +10 -10
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Expanding.js +5 -9
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +3 -3
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +2 -2
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Pagination.js +2 -2
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +2 -2
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/Sorting.js +2 -2
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/utils.js +9 -14
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +54 -55
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +259 -245
- package/build/types/core.d.ts +3 -4
- package/build/types/utils.d.ts +0 -4
- package/build/umd/index.development.js +57 -59
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +7 -1
- package/src/core.tsx +16 -101
- package/src/createTable.tsx +16 -13
- package/src/features/Expanding.ts +5 -3
- package/src/features/Filters.ts +4 -4
- package/src/features/Grouping.ts +1 -1
- package/src/features/Pagination.ts +1 -3
- package/src/features/Pinning.ts +1 -3
- package/src/features/Sorting.ts +1 -1
- package/src/utils.tsx +7 -69
package/build/types/core.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export declare type CoreOptions<TData, TValue, TFilterFns, TSortingFns, TAggrega
|
|
|
14
14
|
autoResetAll?: boolean;
|
|
15
15
|
};
|
|
16
16
|
export declare type TableCore<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
|
|
17
|
-
|
|
17
|
+
subscribe: (cb: () => void) => () => void;
|
|
18
|
+
notify: () => void;
|
|
18
19
|
initialState: TableState;
|
|
19
20
|
internalState: TableState;
|
|
20
21
|
reset: () => void;
|
|
@@ -76,8 +77,6 @@ export declare type CoreColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggre
|
|
|
76
77
|
header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
|
|
77
78
|
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
|
|
78
79
|
}>;
|
|
79
|
-
} & // instance: ReactTable< // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
|
|
80
|
-
{
|
|
81
80
|
__generated: true;
|
|
82
81
|
width?: number;
|
|
83
82
|
minWidth?: number;
|
|
@@ -108,4 +107,4 @@ export declare type CoreColumn<TData, TValue, TFilterFns, TSortingFns, TAggregat
|
|
|
108
107
|
getFlatColumns: () => Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[];
|
|
109
108
|
getLeafColumns: () => Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[];
|
|
110
109
|
};
|
|
111
|
-
export declare function createTableInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(options: Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns
|
|
110
|
+
export declare function createTableInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(options: Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>): ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
|
package/build/types/utils.d.ts
CHANGED
|
@@ -9,9 +9,6 @@ export declare type Updater<TInput, TOutput> = TOutput | DataUpdateFunction<TInp
|
|
|
9
9
|
export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
|
|
10
10
|
export declare function noop(): void;
|
|
11
11
|
export declare function makeStateUpdater(key: keyof TableState, instance: unknown): (updater: Updater<any, any>) => void;
|
|
12
|
-
export declare const safeUseLayoutEffect: typeof React.useLayoutEffect;
|
|
13
|
-
export declare function useMountedLayoutEffect(fn: any, deps: any[]): void;
|
|
14
|
-
export declare function useGetLatest<T>(obj: T): () => T;
|
|
15
12
|
declare type AnyFunction = (...args: any) => any;
|
|
16
13
|
export declare function isFunction<T extends AnyFunction>(d: any): d is T;
|
|
17
14
|
export declare function flattenBy<TNode>(arr: TNode[], getChildren: (item: TNode) => TNode[]): TNode[];
|
|
@@ -22,7 +19,6 @@ export declare function memo<TDeps extends readonly any[], TResult>(getDeps: ()
|
|
|
22
19
|
debug?: boolean;
|
|
23
20
|
onChange?: (result: TResult, previousResult?: TResult) => void;
|
|
24
21
|
}): () => TResult;
|
|
25
|
-
export declare function isPlainObject(o: any): o is Object;
|
|
26
22
|
export declare type Render = typeof flexRender;
|
|
27
23
|
export declare function flexRender<TProps extends {}>(Comp: Renderable<TProps>, props: TProps): React.ReactNode;
|
|
28
24
|
export {};
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
13
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactTable = {}, global.React));
|
|
15
|
-
})(this, (function (exports, React) { 'use strict';
|
|
12
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('use-sync-external-store/shim')) :
|
|
13
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', 'use-sync-external-store/shim'], factory) :
|
|
14
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactTable = {}, global.React, global.shim));
|
|
15
|
+
})(this, (function (exports, React, shim) { 'use strict';
|
|
16
16
|
|
|
17
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
18
|
|
|
@@ -416,9 +416,7 @@
|
|
|
416
416
|
return _extends({}, old, (_extends2 = {}, _extends2[key] = functionalUpdate(updater, old[key]), _extends2));
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
typeof document !== 'undefined' ? React__default["default"].useLayoutEffect : React__default["default"].useEffect;
|
|
419
|
+
}
|
|
422
420
|
function isFunction(d) {
|
|
423
421
|
return d instanceof Function;
|
|
424
422
|
}
|
|
@@ -452,19 +450,17 @@
|
|
|
452
450
|
var result;
|
|
453
451
|
return function () {
|
|
454
452
|
var newDeps = getDeps();
|
|
455
|
-
var
|
|
456
|
-
|
|
457
|
-
var depsChanged = newSerializedDeps.length !== oldSerializedDeps.length || newSerializedDeps.some(function (dep, index) {
|
|
458
|
-
return oldSerializedDeps[index] !== dep;
|
|
453
|
+
var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
|
|
454
|
+
return deps[index] !== dep;
|
|
459
455
|
});
|
|
460
456
|
|
|
461
457
|
if (depsChanged) {
|
|
462
458
|
if (opts != null && opts.debug) {
|
|
463
459
|
console.info(opts == null ? void 0 : opts.key, _extends({
|
|
464
|
-
length:
|
|
465
|
-
},
|
|
466
|
-
if (
|
|
467
|
-
return [index,
|
|
460
|
+
length: deps.length + " -> " + newDeps.length
|
|
461
|
+
}, newDeps.map(function (_, index) {
|
|
462
|
+
if (deps[index] !== newDeps[index]) {
|
|
463
|
+
return [index, deps[index], newDeps[index]];
|
|
468
464
|
}
|
|
469
465
|
|
|
470
466
|
return false;
|
|
@@ -479,15 +475,14 @@
|
|
|
479
475
|
|
|
480
476
|
var oldResult = result;
|
|
481
477
|
result = fn.apply(void 0, newDeps);
|
|
482
|
-
deps =
|
|
478
|
+
deps = newDeps;
|
|
483
479
|
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result, oldResult);
|
|
484
480
|
oldResult = undefined;
|
|
485
481
|
}
|
|
486
482
|
|
|
487
483
|
return result;
|
|
488
484
|
};
|
|
489
|
-
}
|
|
490
|
-
|
|
485
|
+
}
|
|
491
486
|
function flexRender(Comp, props) {
|
|
492
487
|
return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__default["default"].createElement(Comp, props) : Comp;
|
|
493
488
|
}
|
|
@@ -1089,9 +1084,9 @@
|
|
|
1089
1084
|
return (_instance$getState$gr2 = instance.getState().grouping) == null ? void 0 : _instance$getState$gr2.indexOf(columnId);
|
|
1090
1085
|
},
|
|
1091
1086
|
resetGrouping: function resetGrouping() {
|
|
1092
|
-
var _instance$
|
|
1087
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
1093
1088
|
|
|
1094
|
-
instance.setGrouping((_instance$
|
|
1089
|
+
instance.setGrouping((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
|
|
1095
1090
|
},
|
|
1096
1091
|
getToggleGroupingProps: function getToggleGroupingProps(columnId, userProps) {
|
|
1097
1092
|
var column = instance.getColumn(columnId);
|
|
@@ -1314,9 +1309,9 @@
|
|
|
1314
1309
|
return instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater, functionalUpdate(updater, instance.getState().columnPinning));
|
|
1315
1310
|
},
|
|
1316
1311
|
resetColumnPinning: function resetColumnPinning() {
|
|
1317
|
-
var _instance$
|
|
1312
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
1318
1313
|
|
|
1319
|
-
return instance.setColumnPinning((_instance$
|
|
1314
|
+
return instance.setColumnPinning((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnPinning) != null ? _instance$initialStat : {});
|
|
1320
1315
|
},
|
|
1321
1316
|
pinColumn: function pinColumn(columnId, position) {
|
|
1322
1317
|
var column = instance.getColumn(columnId);
|
|
@@ -2398,9 +2393,9 @@
|
|
|
2398
2393
|
});
|
|
2399
2394
|
},
|
|
2400
2395
|
resetColumnFilters: function resetColumnFilters() {
|
|
2401
|
-
var _instance$
|
|
2396
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
2402
2397
|
|
|
2403
|
-
instance.setColumnFilters((_instance$
|
|
2398
|
+
instance.setColumnFilters((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnFilters) != null ? _instance$initialStat : []);
|
|
2404
2399
|
},
|
|
2405
2400
|
getColumnFilteredRowModel: memo(function () {
|
|
2406
2401
|
return [instance.getState().columnFilters, instance.getCoreRowModel(), instance.options.columnFilterRowsFn];
|
|
@@ -2500,7 +2495,7 @@
|
|
|
2500
2495
|
key: 'getGlobalFilteredRowModel',
|
|
2501
2496
|
debug: instance.options.debug,
|
|
2502
2497
|
onChange: function onChange() {
|
|
2503
|
-
|
|
2498
|
+
instance._notifySortingReset();
|
|
2504
2499
|
}
|
|
2505
2500
|
}),
|
|
2506
2501
|
getPreGlobalFilteredRows: function getPreGlobalFilteredRows() {
|
|
@@ -2887,9 +2882,9 @@
|
|
|
2887
2882
|
})) != null ? _instance$getState$so2 : -1;
|
|
2888
2883
|
},
|
|
2889
2884
|
resetSorting: function resetSorting() {
|
|
2890
|
-
var _instance$
|
|
2885
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
2891
2886
|
|
|
2892
|
-
instance.setSorting((_instance$
|
|
2887
|
+
instance.setSorting((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
|
|
2893
2888
|
},
|
|
2894
2889
|
getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
|
|
2895
2890
|
var column = instance.getColumn(columnId);
|
|
@@ -2994,13 +2989,9 @@
|
|
|
2994
2989
|
toggleRowExpanded: function toggleRowExpanded(rowId, expanded) {
|
|
2995
2990
|
if (!rowId) return;
|
|
2996
2991
|
instance.setExpanded(function (old) {
|
|
2997
|
-
var
|
|
2992
|
+
var _expanded;
|
|
2998
2993
|
|
|
2999
|
-
|
|
3000
|
-
old = {};
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
|
-
var exists = old === true ? true : !!((_old = old) != null && _old[rowId]);
|
|
2994
|
+
var exists = old === true ? true : !!(old != null && old[rowId]);
|
|
3004
2995
|
var oldExpanded = {};
|
|
3005
2996
|
|
|
3006
2997
|
if (old === true) {
|
|
@@ -3038,9 +3029,9 @@
|
|
|
3038
3029
|
}
|
|
3039
3030
|
},
|
|
3040
3031
|
resetExpanded: function resetExpanded() {
|
|
3041
|
-
var _instance$
|
|
3032
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
3042
3033
|
|
|
3043
|
-
instance.setExpanded((_instance$
|
|
3034
|
+
instance.setExpanded((_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.expanded) != null ? _instance$initialStat : {});
|
|
3044
3035
|
},
|
|
3045
3036
|
getIsRowExpanded: function getIsRowExpanded(rowId) {
|
|
3046
3037
|
var _instance$options$get;
|
|
@@ -3140,7 +3131,7 @@
|
|
|
3140
3131
|
key: 'getExpandedRowModel',
|
|
3141
3132
|
debug: instance.options.debug,
|
|
3142
3133
|
onChange: function onChange() {
|
|
3143
|
-
|
|
3134
|
+
instance._notifyPageIndexReset();
|
|
3144
3135
|
}
|
|
3145
3136
|
}),
|
|
3146
3137
|
getPreExpandedRows: function getPreExpandedRows() {
|
|
@@ -3568,9 +3559,9 @@
|
|
|
3568
3559
|
instance.setPageIndex(0);
|
|
3569
3560
|
},
|
|
3570
3561
|
resetPageSize: function resetPageSize() {
|
|
3571
|
-
var _instance$
|
|
3562
|
+
var _instance$initialStat2, _instance$initialStat3, _instance$initialStat4;
|
|
3572
3563
|
|
|
3573
|
-
instance.setPageSize((_instance$
|
|
3564
|
+
instance.setPageSize((_instance$initialStat2 = (_instance$initialStat3 = instance.initialState) == null ? void 0 : (_instance$initialStat4 = _instance$initialStat3.pagination) == null ? void 0 : _instance$initialStat4.pageSize) != null ? _instance$initialStat2 : 10);
|
|
3574
3565
|
},
|
|
3575
3566
|
setPageSize: function setPageSize(updater) {
|
|
3576
3567
|
instance.setPagination(function (old) {
|
|
@@ -4210,7 +4201,7 @@
|
|
|
4210
4201
|
});
|
|
4211
4202
|
|
|
4212
4203
|
var features = [Visibility, Ordering, Pinning, Headers, Filters, Sorting, Grouping, Expanding, ColumnSizing, Pagination, RowSelection];
|
|
4213
|
-
function createTableInstance(options
|
|
4204
|
+
function createTableInstance(options) {
|
|
4214
4205
|
var _options$initialState;
|
|
4215
4206
|
|
|
4216
4207
|
if (options.debug) {
|
|
@@ -4218,6 +4209,7 @@
|
|
|
4218
4209
|
}
|
|
4219
4210
|
|
|
4220
4211
|
var instance = {};
|
|
4212
|
+
var listeners = [];
|
|
4221
4213
|
var defaultOptions = features.reduce(function (obj, feature) {
|
|
4222
4214
|
return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
|
|
4223
4215
|
}, {});
|
|
@@ -4235,10 +4227,23 @@
|
|
|
4235
4227
|
return Object.assign(obj, feature.getInitialState == null ? void 0 : feature.getInitialState());
|
|
4236
4228
|
}, {}), (_options$initialState = options.initialState) != null ? _options$initialState : {});
|
|
4237
4229
|
|
|
4238
|
-
var finalInstance = _extends({}, instance,
|
|
4230
|
+
var finalInstance = _extends({}, instance, {
|
|
4231
|
+
subscribe: function subscribe(cb) {
|
|
4232
|
+
listeners.push(cb);
|
|
4233
|
+
return function () {
|
|
4234
|
+
listeners = listeners.filter(function (l) {
|
|
4235
|
+
return l !== cb;
|
|
4236
|
+
});
|
|
4237
|
+
};
|
|
4238
|
+
},
|
|
4239
|
+
notify: function notify() {
|
|
4240
|
+
listeners.forEach(function (l) {
|
|
4241
|
+
return l();
|
|
4242
|
+
});
|
|
4243
|
+
}
|
|
4244
|
+
}, features.reduce(function (obj, feature) {
|
|
4239
4245
|
return Object.assign(obj, feature.getInstance == null ? void 0 : feature.getInstance(instance));
|
|
4240
4246
|
}, {}), {
|
|
4241
|
-
rerender: rerender,
|
|
4242
4247
|
initialState: initialState,
|
|
4243
4248
|
internalState: initialState,
|
|
4244
4249
|
reset: function reset() {
|
|
@@ -4255,11 +4260,7 @@
|
|
|
4255
4260
|
|
|
4256
4261
|
return state;
|
|
4257
4262
|
},
|
|
4258
|
-
setState: function setState(updater
|
|
4259
|
-
if (shouldRerender === void 0) {
|
|
4260
|
-
shouldRerender = true;
|
|
4261
|
-
}
|
|
4262
|
-
|
|
4263
|
+
setState: function setState(updater) {
|
|
4263
4264
|
var onStateChange = instance.options.onStateChange;
|
|
4264
4265
|
var internalState = instance.internalState;
|
|
4265
4266
|
var newState = functionalUpdate(updater, internalState);
|
|
@@ -4270,9 +4271,7 @@
|
|
|
4270
4271
|
return;
|
|
4271
4272
|
}
|
|
4272
4273
|
|
|
4273
|
-
|
|
4274
|
-
instance.rerender();
|
|
4275
|
-
}
|
|
4274
|
+
instance.notify();
|
|
4276
4275
|
},
|
|
4277
4276
|
getDefaultColumn: memo(function () {
|
|
4278
4277
|
return [instance.options.defaultColumn];
|
|
@@ -4775,17 +4774,16 @@
|
|
|
4775
4774
|
throw new Error('Invalid accessor');
|
|
4776
4775
|
},
|
|
4777
4776
|
useTable: function useTable(options) {
|
|
4778
|
-
var
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
if (!instanceRef.current) {
|
|
4784
|
-
instanceRef.current = createTableInstance(options, rerender);
|
|
4785
|
-
}
|
|
4777
|
+
var _React$useState = React__namespace.useState(function () {
|
|
4778
|
+
return createTableInstance(options);
|
|
4779
|
+
}),
|
|
4780
|
+
instance = _React$useState[0];
|
|
4786
4781
|
|
|
4787
|
-
|
|
4788
|
-
|
|
4782
|
+
shim.useSyncExternalStore(instance.subscribe, function () {
|
|
4783
|
+
return instance.internalState;
|
|
4784
|
+
});
|
|
4785
|
+
instance.updateOptions(options);
|
|
4786
|
+
return instance;
|
|
4789
4787
|
},
|
|
4790
4788
|
types: undefined
|
|
4791
4789
|
};
|