@tanstack/table-core 8.0.0-alpha.9 → 8.0.0-beta.0
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/aggregationFns.js +120 -0
- package/build/cjs/aggregationFns.js.map +1 -0
- package/build/cjs/core/cell.js +40 -0
- package/build/cjs/core/cell.js.map +1 -0
- package/build/cjs/core/column.js +88 -0
- package/build/cjs/core/column.js.map +1 -0
- package/build/cjs/core/headers.js +403 -0
- package/build/cjs/core/headers.js.map +1 -0
- package/build/cjs/core/instance.js +255 -0
- package/build/cjs/core/instance.js.map +1 -0
- package/build/cjs/core/row.js +77 -0
- package/build/cjs/core/row.js.map +1 -0
- package/build/cjs/createTable.js +36 -29
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +157 -189
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +103 -155
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +155 -304
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +97 -157
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +30 -41
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +102 -105
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +131 -89
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +138 -267
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +82 -167
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +69 -115
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +107 -0
- package/build/cjs/filterFns.js.map +1 -0
- package/build/cjs/index.js +36 -23
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/sortingFns.js +124 -0
- package/build/cjs/sortingFns.js.map +1 -0
- package/build/cjs/utils/filterRowsUtils.js +117 -0
- package/build/cjs/utils/filterRowsUtils.js.map +1 -0
- package/build/cjs/utils/getCoreRowModel.js +79 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +57 -0
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js +54 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
- package/build/cjs/utils/getFacetedRowModel.js +50 -0
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
- package/build/cjs/utils/getFilteredRowModel.js +139 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +161 -0
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
- package/build/cjs/utils/getPaginationRowModel.js +61 -0
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
- package/build/cjs/utils/getSortedRowModel.js +110 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +38 -107
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2976 -3853
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +586 -408
- package/build/types/aggregationFns.d.ts +13 -0
- package/build/types/core/cell.d.ts +9 -0
- package/build/types/core/column.d.ts +40 -0
- package/build/types/core/headers.d.ts +46 -0
- package/build/types/core/instance.d.ts +57 -0
- package/build/types/core/row.d.ts +15 -0
- package/build/types/createTable.d.ts +47 -26
- package/build/types/features/ColumnSizing.d.ts +32 -44
- package/build/types/features/Expanding.d.ts +15 -26
- package/build/types/features/Filters.d.ts +64 -63
- package/build/types/features/Grouping.d.ts +32 -46
- package/build/types/features/Ordering.d.ts +7 -10
- package/build/types/features/Pagination.d.ts +16 -15
- package/build/types/features/Pinning.d.ts +16 -17
- package/build/types/features/RowSelection.d.ts +13 -33
- package/build/types/features/Sorting.d.ts +25 -44
- package/build/types/features/Visibility.d.ts +16 -25
- package/build/types/filterFns.d.ts +13 -0
- package/build/types/index.d.ts +16 -10
- package/build/types/sortingFns.d.ts +11 -0
- package/build/types/types.d.ts +37 -122
- package/build/types/utils/filterRowsUtils.d.ts +4 -0
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getExpandedRowModel.d.ts +7 -0
- package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
- package/build/types/utils/getFacetedRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
- package/build/types/utils/getFilteredRowModel.d.ts +2 -0
- package/build/types/utils/getGroupedRowModel.d.ts +2 -0
- package/build/types/utils/getPaginationRowModel.d.ts +4 -0
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +7 -11
- package/build/umd/index.development.js +3024 -3893
- 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 +9 -10
- package/src/.DS_Store +0 -0
- package/src/aggregationFns.ts +123 -0
- package/src/core/cell.ts +48 -0
- package/src/core/column.ts +147 -0
- package/src/core/headers.ts +575 -0
- package/src/core/instance.ts +361 -0
- package/src/core/row.ts +85 -0
- package/src/createTable.ts +188 -0
- package/src/features/ColumnSizing.ts +170 -185
- package/src/features/Expanding.ts +122 -194
- package/src/features/Filters.ts +301 -381
- package/src/features/Grouping.ts +160 -220
- package/src/features/Ordering.ts +24 -25
- package/src/features/Pagination.ts +90 -73
- package/src/features/Pinning.ts +186 -63
- package/src/features/RowSelection.ts +107 -245
- package/src/features/Sorting.ts +127 -225
- package/src/features/Visibility.ts +116 -132
- package/src/filterFns.ts +135 -0
- package/src/index.ts +29 -0
- package/src/{sortTypes.ts → sortingFns.ts} +63 -85
- package/src/types.ts +62 -168
- package/src/utils/filterRowsUtils.ts +112 -0
- package/src/utils/getCoreRowModel.ts +84 -0
- package/src/utils/getExpandedRowModel.ts +54 -0
- package/src/utils/getFacetedMinMaxValues.ts +40 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/getFilteredRowModel.ts +159 -0
- package/src/utils/getGroupedRowModel.ts +175 -0
- package/src/utils/getPaginationRowModel.ts +48 -0
- package/src/utils/getSortedRowModel.ts +116 -0
- package/src/utils.ts +126 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -630
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/features/Headers.d.ts +0 -43
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -137
- package/src/features/Headers.ts +0 -747
- package/src/filterTypes.ts +0 -188
- package/src/index.tsx +0 -23
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
package/build/cjs/utils.js
CHANGED
|
@@ -12,24 +12,17 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
16
|
-
var React = require('react');
|
|
17
|
-
|
|
18
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
21
|
-
|
|
22
15
|
function functionalUpdate(updater, input) {
|
|
23
16
|
return typeof updater === 'function' ? updater(input) : updater;
|
|
24
17
|
}
|
|
25
18
|
function noop() {//
|
|
26
19
|
}
|
|
27
20
|
function makeStateUpdater(key, instance) {
|
|
28
|
-
return
|
|
29
|
-
instance.setState(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
return updater => {
|
|
22
|
+
instance.setState(old => {
|
|
23
|
+
return { ...old,
|
|
24
|
+
[key]: functionalUpdate(updater, old[key])
|
|
25
|
+
};
|
|
33
26
|
});
|
|
34
27
|
};
|
|
35
28
|
}
|
|
@@ -37,12 +30,12 @@ function isFunction(d) {
|
|
|
37
30
|
return d instanceof Function;
|
|
38
31
|
}
|
|
39
32
|
function flattenBy(arr, getChildren) {
|
|
40
|
-
|
|
33
|
+
const flat = [];
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
subArr.forEach(
|
|
35
|
+
const recurse = subArr => {
|
|
36
|
+
subArr.forEach(item => {
|
|
44
37
|
flat.push(item);
|
|
45
|
-
|
|
38
|
+
const children = getChildren(item);
|
|
46
39
|
|
|
47
40
|
if (children != null && children.length) {
|
|
48
41
|
recurse(children);
|
|
@@ -53,115 +46,53 @@ function flattenBy(arr, getChildren) {
|
|
|
53
46
|
recurse(arr);
|
|
54
47
|
return flat;
|
|
55
48
|
}
|
|
56
|
-
// @ts-ignore // Just rely on the type, not the implementation
|
|
57
|
-
var propGetter = function propGetter(initial, getter) {
|
|
58
|
-
if (isFunction(getter)) {
|
|
59
|
-
return getter(initial);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return _rollupPluginBabelHelpers["extends"]({}, initial, getter != null ? getter : {});
|
|
63
|
-
};
|
|
64
49
|
function memo(getDeps, fn, opts) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
if (opts.key && opts.debug) depTime =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var oldResult = result;
|
|
77
|
-
var resultTime;
|
|
78
|
-
if (opts.key && opts.debug) resultTime = performance.now();
|
|
79
|
-
result = fn.apply(void 0, newDeps);
|
|
80
|
-
deps = newDeps;
|
|
81
|
-
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result, oldResult);
|
|
82
|
-
|
|
83
|
-
if (opts.key && opts.debug) {
|
|
84
|
-
if (opts != null && opts.debug()) {
|
|
85
|
-
var depEndTime = Math.round((performance.now() - depTime) * 100) / 100;
|
|
86
|
-
var resultEndTime = Math.round((performance.now() - resultTime) * 100) / 100;
|
|
87
|
-
var resultFpsPercentage = resultEndTime / 16;
|
|
50
|
+
let deps = [];
|
|
51
|
+
let result;
|
|
52
|
+
return () => {
|
|
53
|
+
let depTime;
|
|
54
|
+
if (opts.key && opts.debug) depTime = Date.now();
|
|
55
|
+
const newDeps = getDeps();
|
|
56
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
57
|
+
|
|
58
|
+
if (!depsChanged) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
88
61
|
|
|
89
|
-
|
|
90
|
-
|
|
62
|
+
deps = newDeps;
|
|
63
|
+
let resultTime;
|
|
64
|
+
if (opts.key && opts.debug) resultTime = Date.now();
|
|
65
|
+
result = fn(...newDeps);
|
|
66
|
+
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
91
67
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
68
|
+
if (opts.key && opts.debug) {
|
|
69
|
+
if (opts != null && opts.debug()) {
|
|
70
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
71
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
72
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
95
73
|
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
const pad = (str, num) => {
|
|
75
|
+
str = String(str);
|
|
98
76
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
if (deps[index] !== newDeps[index]) {
|
|
103
|
-
return [index, deps[index], newDeps[index]];
|
|
104
|
-
}
|
|
77
|
+
while (str.length < num) {
|
|
78
|
+
str = ' ' + str;
|
|
79
|
+
}
|
|
105
80
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var _extends3;
|
|
81
|
+
return str;
|
|
82
|
+
};
|
|
109
83
|
|
|
110
|
-
|
|
111
|
-
b = _ref[1];
|
|
112
|
-
return _rollupPluginBabelHelpers["extends"]({}, accu, (_extends3 = {}, _extends3[a] = b, _extends3));
|
|
113
|
-
}, {}), {
|
|
114
|
-
parent: parent
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
84
|
+
console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key);
|
|
117
85
|
}
|
|
118
|
-
|
|
119
|
-
oldResult = undefined;
|
|
120
86
|
}
|
|
121
87
|
|
|
122
88
|
return result;
|
|
123
89
|
};
|
|
124
90
|
}
|
|
125
|
-
function flexRender(Comp, props) {
|
|
126
|
-
return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__default["default"].createElement(Comp, props) : Comp;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function isReactComponent(component) {
|
|
130
|
-
return isClassComponent(component) || typeof component === 'function' || isExoticComponent(component);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function isClassComponent(component) {
|
|
134
|
-
return typeof component === 'function' && function () {
|
|
135
|
-
var proto = Object.getPrototypeOf(component);
|
|
136
|
-
return proto.prototype && proto.prototype.isReactComponent;
|
|
137
|
-
}();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function isExoticComponent(component) {
|
|
141
|
-
return typeof component === 'object' && typeof component.$$typeof === 'symbol' && ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description);
|
|
142
|
-
} // export function hashString(str: string, seed = 0): string {
|
|
143
|
-
// let h1 = 0xdeadbeef ^ seed,
|
|
144
|
-
// h2 = 0x41c6ce57 ^ seed
|
|
145
|
-
// for (let i = 0, ch; i < str.length; i++) {
|
|
146
|
-
// ch = str.charCodeAt(i)
|
|
147
|
-
// h1 = Math.imul(h1 ^ ch, 2654435761)
|
|
148
|
-
// h2 = Math.imul(h2 ^ ch, 1597334677)
|
|
149
|
-
// }
|
|
150
|
-
// h1 =
|
|
151
|
-
// Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
|
|
152
|
-
// Math.imul(h2 ^ (h2 >>> 13), 3266489909)
|
|
153
|
-
// h2 =
|
|
154
|
-
// Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
|
|
155
|
-
// Math.imul(h1 ^ (h1 >>> 13), 3266489909)
|
|
156
|
-
// return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
|
|
157
|
-
// }
|
|
158
91
|
|
|
159
92
|
exports.flattenBy = flattenBy;
|
|
160
|
-
exports.flexRender = flexRender;
|
|
161
93
|
exports.functionalUpdate = functionalUpdate;
|
|
162
94
|
exports.isFunction = isFunction;
|
|
163
95
|
exports.makeStateUpdater = makeStateUpdater;
|
|
164
96
|
exports.memo = memo;
|
|
165
97
|
exports.noop = noop;
|
|
166
|
-
exports.propGetter = propGetter;
|
|
167
98
|
//# sourceMappingURL=utils.js.map
|
package/build/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.tsx"],"sourcesContent":["import React from 'react'\nimport {\n Getter,\n NoInfer,\n PropGetterValue,\n Renderable,\n TableState,\n Updater,\n} from './types'\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type Overwrite<T, U> = Omit<T, keyof U> & U\n\nexport type DataUpdateFunction<T> = (input: T) => T\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as DataUpdateFunction<T>)(input)\n : updater\n}\n\nexport function noop() {\n //\n}\n\nexport function makeStateUpdater(key: keyof TableState, instance: unknown) {\n return (updater: Updater<any>) => {\n ;(instance as any).setState(<TTableState,>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n })\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function flattenBy<TNode>(\n arr: TNode[],\n getChildren: (item: TNode) => TNode[]\n) {\n const flat: TNode[] = []\n\n const recurse = (subArr: TNode[]) => {\n subArr.forEach(item => {\n flat.push(item)\n const children = getChildren(item)\n if (children?.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\ntype PropGetterImpl = <TBaseProps, TGetter extends Getter<TBaseProps>>(\n initial: TBaseProps,\n userProps?: TGetter\n) => PropGetterValue<TBaseProps, TGetter>\n\n// @ts-ignore // Just rely on the type, not the implementation\nexport const propGetter: PropGetterImpl = (initial, getter) => {\n if (isFunction(getter)) {\n return getter(initial)\n }\n\n return {\n ...initial,\n ...(getter ?? {}),\n }\n}\n\nexport function memo<TDeps extends readonly any[], TResult>(\n getDeps: () => [...TDeps],\n fn: (...args: NoInfer<[...TDeps]>) => TResult,\n opts: {\n key: string\n debug?: () => any\n onChange?: (result: TResult, previousResult?: TResult) => void\n }\n): () => TResult {\n let deps: any[] = []\n let result: TResult | undefined\n\n return () => {\n let depTime: number\n if (opts.key && opts.debug) depTime = performance.now()\n\n const newDeps = getDeps()\n\n const depsChanged =\n newDeps.length !== deps.length ||\n newDeps.some((dep: any, index: number) => deps[index] !== dep)\n\n if (depsChanged) {\n let oldResult = result\n let resultTime: number\n if (opts.key && opts.debug) resultTime = performance.now()\n result = fn(...newDeps)\n deps = newDeps\n opts?.onChange?.(result, oldResult)\n\n if (opts.key && opts.debug) {\n if (opts?.debug()) {\n const depEndTime =\n Math.round((performance.now() - depTime!) * 100) / 100\n const resultEndTime =\n Math.round((performance.now() - resultTime!) * 100) / 100\n const resultFpsPercentage = resultEndTime / 16\n\n const pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n }\n\n console.info(\n `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,\n `\n font-size: .6rem;\n font-weight: bold;\n color: hsl(${Math.max(\n 0,\n Math.min(120 - 120 * resultFpsPercentage, 120)\n )}deg 100% 31%);`,\n opts?.key,\n {\n length: `${deps.length} -> ${newDeps.length}`,\n ...newDeps\n .map((_, index) => {\n if (deps[index] !== newDeps[index]) {\n return [index, deps[index], newDeps[index]]\n }\n\n return false\n })\n .filter(Boolean)\n .reduce(\n (accu, [a, b]: any) => ({\n ...accu,\n [a]: b,\n }),\n {}\n ),\n parent,\n }\n )\n }\n }\n\n oldResult = undefined\n }\n\n return result!\n }\n}\n\nexport type Render = typeof flexRender\n\nexport function flexRender<TProps extends {}>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode {\n return !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp\n}\n\nfunction isReactComponent(component: unknown): component is React.FC {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isReactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)\n )\n}\n\n// export function hashString(str: string, seed = 0): string {\n// let h1 = 0xdeadbeef ^ seed,\n// h2 = 0x41c6ce57 ^ seed\n// for (let i = 0, ch; i < str.length; i++) {\n// ch = str.charCodeAt(i)\n// h1 = Math.imul(h1 ^ ch, 2654435761)\n// h2 = Math.imul(h2 ^ ch, 1597334677)\n// }\n// h1 =\n// Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^\n// Math.imul(h2 ^ (h2 >>> 13), 3266489909)\n// h2 =\n// Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^\n// Math.imul(h1 ^ (h1 >>> 13), 3266489909)\n// return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()\n// }\n"],"names":["functionalUpdate","updater","input","noop","makeStateUpdater","key","instance","setState","old","isFunction","d","Function","flattenBy","arr","getChildren","flat","recurse","subArr","forEach","item","push","children","length","propGetter","initial","getter","memo","getDeps","fn","opts","deps","result","depTime","debug","performance","now","newDeps","depsChanged","some","dep","index","oldResult","resultTime","onChange","depEndTime","Math","round","resultEndTime","resultFpsPercentage","pad","str","num","String","console","info","max","min","map","_","filter","Boolean","reduce","accu","a","b","parent","undefined","flexRender","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBO,SAASA,gBAAT,CAA6BC,OAA7B,EAAkDC,KAAlD,EAA+D;AACpE,SAAO,OAAOD,OAAP,KAAmB,UAAnB,GACFA,OAAD,CAAmCC,KAAnC,CADG,GAEHD,OAFJ;AAGD;AAEM,SAASE,IAAT,GAAgB;AAEtB;AAEM,SAASC,gBAAT,CAA0BC,GAA1B,EAAiDC,QAAjD,EAAoE;AACzE,SAAO,UAACL,OAAD,EAA2B;AAC9BK,IAAAA,QAAD,CAAkBC,QAAlB,CAA2B,UAAeC,GAAf,EAAoC;AAAA;;AAC9D,sDACKA,GADL,6BAEGH,GAFH,IAESL,gBAAgB,CAACC,OAAD,EAAWO,GAAD,CAAaH,GAAb,CAAV,CAFzB;AAID,KALA;AAMF,GAPD;AAQD;AAIM,SAASI,UAAT,CAA2CC,CAA3C,EAA2D;AAChE,SAAOA,CAAC,YAAYC,QAApB;AACD;AAEM,SAASC,SAAT,CACLC,GADK,EAELC,WAFK,EAGL;AACA,MAAMC,IAAa,GAAG,EAAtB;;AAEA,MAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,MAAD,EAAqB;AACnCA,IAAAA,MAAM,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P,KAAqB,QAArB,IACA,OAAOA,SAAS,CAACO,QAAjB,KAA8B,QAD9B,IAEA,CAAC,YAAD,EAAe,mBAAf,EAAoCC,QAApC,CAA6CR,SAAS,CAACO,QAAV,CAAmBE,WAAhE,CAHF;AAKD;AAGD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { NoInfer, TableState, Updater } from './types'\n\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type Overwrite<T, U extends { [TKey in keyof T]?: any }> = Omit<\n T,\n keyof U\n> &\n U\n\nexport type IfDefined<T, N> = 0 extends 1 & T ? N : T extends {} ? T : N\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (input: T) => T)(input)\n : updater\n}\n\nexport function noop() {\n //\n}\n\nexport function makeStateUpdater(key: keyof TableState, instance: unknown) {\n return (updater: Updater<any>) => {\n ;(instance as any).setState(<TTableState>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n })\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function flattenBy<TNode>(\n arr: TNode[],\n getChildren: (item: TNode) => TNode[]\n) {\n const flat: TNode[] = []\n\n const recurse = (subArr: TNode[]) => {\n subArr.forEach(item => {\n flat.push(item)\n const children = getChildren(item)\n if (children?.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport function memo<TDeps extends readonly any[], TResult>(\n getDeps: () => [...TDeps],\n fn: (...args: NoInfer<[...TDeps]>) => TResult,\n opts: {\n key: any\n debug?: () => any\n onChange?: (result: TResult) => void\n }\n): () => TResult {\n let deps: any[] = []\n let result: TResult | undefined\n\n return () => {\n let depTime: number\n if (opts.key && opts.debug) depTime = Date.now()\n\n const newDeps = getDeps()\n\n const depsChanged =\n newDeps.length !== deps.length ||\n newDeps.some((dep: any, index: number) => deps[index] !== dep)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n let resultTime: number\n if (opts.key && opts.debug) resultTime = Date.now()\n\n result = fn(...newDeps)\n opts?.onChange?.(result)\n\n if (opts.key && opts.debug) {\n if (opts?.debug()) {\n const depEndTime = Math.round((Date.now() - depTime!) * 100) / 100\n const resultEndTime = Math.round((Date.now() - resultTime!) * 100) / 100\n const resultFpsPercentage = resultEndTime / 16\n\n const pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n }\n\n console.info(\n `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,\n `\n font-size: .6rem;\n font-weight: bold;\n color: hsl(${Math.max(\n 0,\n Math.min(120 - 120 * resultFpsPercentage, 120)\n )}deg 100% 31%);`,\n opts?.key\n )\n }\n }\n\n return result!\n }\n}\n"],"names":["functionalUpdate","updater","input","noop","makeStateUpdater","key","instance","setState","old","isFunction","d","Function","flattenBy","arr","getChildren","flat","recurse","subArr","forEach","item","push","children","length","memo","getDeps","fn","opts","deps","result","depTime","debug","Date","now","newDeps","depsChanged","some","dep","index","resultTime","onChange","depEndTime","Math","round","resultEndTime","resultFpsPercentage","pad","str","num","String","console","info","max","min"],"mappings":";;;;;;;;;;;;;;AAaO,SAASA,gBAAT,CAA6BC,OAA7B,EAAkDC,KAAlD,EAA+D;AACpE,EAAO,OAAA,OAAOD,OAAP,KAAmB,UAAnB,GACFA,OAAD,CAA6BC,KAA7B,CADG,GAEHD,OAFJ,CAAA;AAGD,CAAA;AAEM,SAASE,IAAT,GAAgB;AAEtB,CAAA;AAEM,SAASC,gBAAT,CAA0BC,GAA1B,EAAiDC,QAAjD,EAAoE;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