@tanstack/react-table 8.0.0-alpha.5 → 8.0.0-alpha.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -78
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/index.js +98 -17
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +38 -4716
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +29 -779
  9. package/build/types/index.d.ts +10 -8
  10. package/build/umd/index.development.js +50 -4722
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +1 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +4 -1
  15. package/src/index.tsx +104 -8
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -552
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -108
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/ColumnSizing.js +0 -317
  23. package/build/cjs/features/ColumnSizing.js.map +0 -1
  24. package/build/cjs/features/Expanding.js +0 -255
  25. package/build/cjs/features/Expanding.js.map +0 -1
  26. package/build/cjs/features/Filters.js +0 -445
  27. package/build/cjs/features/Filters.js.map +0 -1
  28. package/build/cjs/features/Grouping.js +0 -249
  29. package/build/cjs/features/Grouping.js.map +0 -1
  30. package/build/cjs/features/Headers.js +0 -549
  31. package/build/cjs/features/Headers.js.map +0 -1
  32. package/build/cjs/features/Ordering.js +0 -86
  33. package/build/cjs/features/Ordering.js.map +0 -1
  34. package/build/cjs/features/Pagination.js +0 -198
  35. package/build/cjs/features/Pagination.js.map +0 -1
  36. package/build/cjs/features/Pinning.js +0 -149
  37. package/build/cjs/features/Pinning.js.map +0 -1
  38. package/build/cjs/features/RowSelection.js +0 -541
  39. package/build/cjs/features/RowSelection.js.map +0 -1
  40. package/build/cjs/features/Sorting.js +0 -327
  41. package/build/cjs/features/Sorting.js.map +0 -1
  42. package/build/cjs/features/Visibility.js +0 -166
  43. package/build/cjs/features/Visibility.js.map +0 -1
  44. package/build/cjs/filterTypes.js +0 -172
  45. package/build/cjs/filterTypes.js.map +0 -1
  46. package/build/cjs/sortTypes.js +0 -122
  47. package/build/cjs/sortTypes.js.map +0 -1
  48. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  49. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  50. package/build/cjs/utils/expandRowsFn.js +0 -38
  51. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  52. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  53. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  54. package/build/cjs/utils/groupRowsFn.js +0 -155
  55. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  56. package/build/cjs/utils/paginateRowsFn.js +0 -44
  57. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  58. package/build/cjs/utils/sortRowsFn.js +0 -94
  59. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  60. package/build/cjs/utils.js +0 -146
  61. package/build/cjs/utils.js.map +0 -1
  62. package/build/types/aggregationTypes.d.ts +0 -22
  63. package/build/types/core.d.ts +0 -111
  64. package/build/types/createTable.d.ts +0 -52
  65. package/build/types/features/ColumnSizing.d.ts +0 -67
  66. package/build/types/features/Expanding.d.ts +0 -53
  67. package/build/types/features/Filters.d.ts +0 -98
  68. package/build/types/features/Grouping.d.ts +0 -82
  69. package/build/types/features/Headers.d.ts +0 -41
  70. package/build/types/features/Ordering.d.ts +0 -19
  71. package/build/types/features/Pagination.d.ts +0 -44
  72. package/build/types/features/Pinning.d.ts +0 -39
  73. package/build/types/features/RowSelection.d.ts +0 -66
  74. package/build/types/features/Sorting.d.ts +0 -78
  75. package/build/types/features/Visibility.d.ts +0 -47
  76. package/build/types/filterTypes.d.ts +0 -50
  77. package/build/types/sortTypes.d.ts +0 -18
  78. package/build/types/types.d.ts +0 -127
  79. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  80. package/build/types/utils/expandRowsFn.d.ts +0 -2
  81. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  82. package/build/types/utils/groupRowsFn.d.ts +0 -2
  83. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  84. package/build/types/utils/sortRowsFn.d.ts +0 -2
  85. package/build/types/utils.d.ts +0 -28
  86. package/src/aggregationTypes.ts +0 -115
  87. package/src/core.tsx +0 -1181
  88. package/src/createTable.tsx +0 -241
  89. package/src/features/ColumnSizing.ts +0 -453
  90. package/src/features/Expanding.ts +0 -404
  91. package/src/features/Filters.ts +0 -762
  92. package/src/features/Grouping.ts +0 -466
  93. package/src/features/Headers.ts +0 -912
  94. package/src/features/Ordering.ts +0 -133
  95. package/src/features/Pagination.ts +0 -327
  96. package/src/features/Pinning.ts +0 -200
  97. package/src/features/RowSelection.ts +0 -831
  98. package/src/features/Sorting.ts +0 -547
  99. package/src/features/Visibility.ts +0 -279
  100. package/src/filterTypes.ts +0 -251
  101. package/src/sortTypes.ts +0 -159
  102. package/src/types.ts +0 -331
  103. package/src/utils/columnFilterRowsFn.ts +0 -155
  104. package/src/utils/expandRowsFn.ts +0 -50
  105. package/src/utils/globalFilterRowsFn.ts +0 -122
  106. package/src/utils/groupRowsFn.ts +0 -194
  107. package/src/utils/paginateRowsFn.ts +0 -34
  108. package/src/utils/sortRowsFn.ts +0 -115
  109. package/src/utils.tsx +0 -257
@@ -1,194 +0,0 @@
1
- import { ReactTable, Row, RowModel } from '../types'
2
- import { flattenBy } from '../utils'
3
-
4
- export function groupRowsFn<
5
- TData,
6
- TValue,
7
- TFilterFns,
8
- TSortingFns,
9
- TAggregationFns
10
- >(
11
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
12
- sortedRowModel: RowModel<
13
- TData,
14
- TValue,
15
- TFilterFns,
16
- TSortingFns,
17
- TAggregationFns
18
- >
19
- ): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
20
- const groupingState = instance.getState().grouping
21
- // Filter the grouping list down to columns that exist
22
- const existingGrouping = groupingState.filter(columnId =>
23
- instance.getColumn(columnId)
24
- )
25
-
26
- // Find the columns that can or are aggregating
27
- // Uses each column to aggregate rows into a single value
28
- const aggregateRowsToValues = (
29
- leafRows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[],
30
- groupedRows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[],
31
- depth: number
32
- ) => {
33
- const values: Record<string, unknown> = {}
34
-
35
- instance.getAllLeafColumns().forEach(column => {
36
- // Don't aggregate columns that are in the grouping
37
- if (existingGrouping.includes(column.id)) {
38
- values[column.id] = groupedRows[0]
39
- ? groupedRows[0].values[column.id]
40
- : null
41
- return
42
- }
43
-
44
- // Aggregate the values
45
- const aggregateFn = instance.getColumnAggregationFn(column.id)
46
-
47
- if (aggregateFn) {
48
- // Get the columnValues to aggregate
49
- const groupedValues = groupedRows.map(row => row.values[column.id])
50
-
51
- // Get the columnValues to aggregate
52
- const leafValues = leafRows.map(row => {
53
- let columnValue = row.values[column.id]
54
-
55
- if (!depth && column.aggregateValue) {
56
- columnValue = column.aggregateValue(columnValue)
57
- }
58
-
59
- return columnValue
60
- })
61
-
62
- values[column.id] = aggregateFn(leafValues, groupedValues)
63
- } else if (column.aggregationType) {
64
- console.info({ column })
65
- throw new Error(
66
- process.env.NODE_ENV !== 'production'
67
- ? `React Table: Invalid column.aggregateType option for column listed above`
68
- : ''
69
- )
70
- } else {
71
- values[column.id] = null
72
- }
73
- })
74
-
75
- return values
76
- }
77
-
78
- const groupedFlatRows: Row<
79
- TData,
80
- TValue,
81
- TFilterFns,
82
- TSortingFns,
83
- TAggregationFns
84
- >[] = []
85
- const groupedRowsById: Record<
86
- string,
87
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
88
- > = {}
89
- // const onlyGroupedFlatRows: Row[] = [];
90
- // const onlyGroupedRowsById: Record<RowId, Row> = {};
91
- // const nonGroupedFlatRows: Row[] = [];
92
- // const nonGroupedRowsById: Record<RowId, Row> = {};
93
-
94
- // Recursively group the data
95
- const groupUpRecursively = (
96
- rows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[],
97
- depth = 0,
98
- parentId: string
99
- ) => {
100
- // This is the last level, just return the rows
101
- if (depth === existingGrouping.length) {
102
- return rows
103
- }
104
-
105
- const columnId = existingGrouping[depth]!
106
-
107
- // Group the rows together for this level
108
- const rowGroupsMap = groupBy(rows, columnId)
109
-
110
- // Peform aggregations for each group
111
- const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(
112
- ([groupingValue, groupedRows], index) => {
113
- let id = `${columnId}:${groupingValue}`
114
- id = parentId ? `${parentId}>${id}` : id
115
-
116
- // First, Recurse to group sub rows before aggregation
117
- const subRows = groupUpRecursively(groupedRows, depth + 1, id)
118
-
119
- // Flatten the leaf rows of the rows in this group
120
- const leafRows = depth
121
- ? flattenBy(groupedRows, row => row.leafRows)
122
- : groupedRows
123
-
124
- const values = aggregateRowsToValues(leafRows, groupedRows, depth)
125
-
126
- const row = instance.createRow(id, undefined, index, depth, values)
127
-
128
- Object.assign(row, {
129
- groupingColumnId: columnId,
130
- groupingValue,
131
- subRows,
132
- leafRows,
133
- })
134
-
135
- subRows.forEach(subRow => {
136
- groupedFlatRows.push(subRow)
137
- groupedRowsById[subRow.id] = subRow
138
- // if (subRow.getIsGrouped?.()) {
139
- // onlyGroupedFlatRows.push(subRow);
140
- // onlyGroupedRowsById[subRow.id] = subRow;
141
- // } else {
142
- // nonGroupedFlatRows.push(subRow);
143
- // nonGroupedRowsById[subRow.id] = subRow;
144
- // }
145
- })
146
-
147
- return row
148
- }
149
- )
150
-
151
- return aggregatedGroupedRows
152
- }
153
-
154
- const groupedRows = groupUpRecursively(sortedRowModel.rows, 0, '')
155
-
156
- groupedRows.forEach(subRow => {
157
- groupedFlatRows.push(subRow)
158
- groupedRowsById[subRow.id] = subRow
159
- // if (subRow.getIsGrouped?.()) {
160
- // onlyGroupedFlatRows.push(subRow);
161
- // onlyGroupedRowsById[subRow.id] = subRow;
162
- // } else {
163
- // nonGroupedFlatRows.push(subRow);
164
- // nonGroupedRowsById[subRow.id] = subRow;
165
- // }
166
- })
167
-
168
- return {
169
- rows: groupedRows,
170
- flatRows: groupedFlatRows,
171
- rowsById: groupedRowsById,
172
- }
173
- }
174
-
175
- function groupBy<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(
176
- rows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[],
177
- columnId: string
178
- ) {
179
- const groupMap = new Map<
180
- any,
181
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
182
- >()
183
-
184
- return rows.reduce((map, row) => {
185
- const resKey = `${row.values[columnId]}`
186
- const previous = map.get(resKey)
187
- if (!previous) {
188
- map.set(resKey, [row])
189
- } else {
190
- map.set(resKey, [...previous, row])
191
- }
192
- return map
193
- }, groupMap)
194
- }
@@ -1,34 +0,0 @@
1
- import { ReactTable, RowModel } from '../types'
2
- import { expandRowsFn } from './expandRowsFn'
3
-
4
- export function paginateRowsFn<
5
- TData,
6
- TValue,
7
- TFilterFns,
8
- TSortingFns,
9
- TAggregationFns
10
- >(
11
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
12
- rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
13
- ): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
14
- const { pageSize, pageIndex } = instance.getState().pagination
15
- let { rows, flatRows, rowsById } = rowModel
16
- const pageStart = pageSize * pageIndex
17
- const pageEnd = pageStart + pageSize
18
-
19
- rows = rows.slice(pageStart, pageEnd)
20
-
21
- if (!instance.options.paginateExpandedRows) {
22
- return expandRowsFn(instance, {
23
- rows,
24
- flatRows,
25
- rowsById,
26
- })
27
- }
28
-
29
- return {
30
- rows,
31
- flatRows,
32
- rowsById,
33
- }
34
- }
@@ -1,115 +0,0 @@
1
- import { ReactTable, Row, RowModel } from '../types'
2
- import { SortingFn } from '../features/Sorting'
3
-
4
- export function sortRowsFn<
5
- TData,
6
- TValue,
7
- TFilterFns,
8
- TSortingFns,
9
- TAggregationFns
10
- >(
11
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
12
- rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
13
- ): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
14
- const sortingState = instance.getState().sorting
15
-
16
- const sortedFlatRows: Row<
17
- TData,
18
- TValue,
19
- TFilterFns,
20
- TSortingFns,
21
- TAggregationFns
22
- >[] = []
23
-
24
- // Filter out sortings that correspond to non existing columns
25
- const availableSorting = sortingState.filter(sort =>
26
- instance.getColumnCanSort(sort.id)
27
- )
28
-
29
- const columnInfoById: Record<
30
- string,
31
- {
32
- sortUndefined?: false | -1 | 1
33
- invertSorting?: boolean
34
- sortingFn: SortingFn<
35
- TData,
36
- TValue,
37
- TFilterFns,
38
- TSortingFns,
39
- TAggregationFns
40
- >
41
- }
42
- > = {}
43
-
44
- availableSorting.forEach(sortEntry => {
45
- const column = instance.getColumn(sortEntry.id)!
46
-
47
- columnInfoById[sortEntry.id] = {
48
- sortUndefined: column.sortUndefined,
49
- invertSorting: column.invertSorting,
50
- sortingFn: instance.getColumnSortingFn(sortEntry.id)!,
51
- }
52
- })
53
-
54
- const sortData = (
55
- rows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
56
- ) => {
57
- // This will also perform a stable sorting using the row index
58
- // if needed.
59
- const sortedData = rows.slice()
60
-
61
- sortedData.sort((rowA, rowB) => {
62
- for (let i = 0; i < availableSorting.length; i += 1) {
63
- const sortEntry = availableSorting[i]!
64
- const columnInfo = columnInfoById[sortEntry.id]!
65
- const isDesc = sortEntry?.desc ?? false
66
-
67
- if (columnInfo.sortUndefined) {
68
- const aValue = rowA.values[sortEntry.id]
69
- const bValue = rowB.values[sortEntry.id]
70
-
71
- const aUndefined = typeof aValue === 'undefined'
72
- const bUndefined = typeof bValue === 'undefined'
73
-
74
- if (aUndefined || bUndefined) {
75
- return aUndefined && bUndefined ? 0 : aUndefined ? 1 : -1
76
- }
77
- }
78
-
79
- // This function should always return in ascending order
80
- let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
81
-
82
- if (sortInt !== 0) {
83
- if (isDesc) {
84
- sortInt *= -1
85
- }
86
-
87
- if (columnInfo.invertSorting) {
88
- sortInt *= -1
89
- }
90
-
91
- return sortInt
92
- }
93
- }
94
-
95
- return rowA.index - rowB.index
96
- })
97
-
98
- // If there are sub-rows, sort them
99
- sortedData.forEach(row => {
100
- sortedFlatRows.push(row)
101
- if (!row.subRows || row.subRows.length <= 1) {
102
- return
103
- }
104
- row.subRows = sortData(row.subRows)
105
- })
106
-
107
- return sortedData
108
- }
109
-
110
- return {
111
- rows: sortData(rowModel.rows),
112
- flatRows: sortedFlatRows,
113
- rowsById: rowModel.rowsById,
114
- }
115
- }
package/src/utils.tsx DELETED
@@ -1,257 +0,0 @@
1
- import React from 'react'
2
- import {
3
- Getter,
4
- NoInfer,
5
- PropGetterValue,
6
- Renderable,
7
- TableState,
8
- } from './types'
9
-
10
- export type IsAny<T> = 0 extends 1 & T ? true : false
11
- export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
12
- export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
13
- Required<Pick<T, K>>
14
- export type Overwrite<T, U> = Omit<T, keyof U> & U
15
-
16
- export type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput
17
-
18
- export type Updater<TInput, TOutput> =
19
- | TOutput
20
- | DataUpdateFunction<TInput, TOutput>
21
-
22
- export function functionalUpdate<TInput, TOutput = TInput>(
23
- updater: Updater<TInput, TOutput>,
24
- input: TInput
25
- ): TOutput {
26
- return typeof updater === 'function'
27
- ? (updater as DataUpdateFunction<TInput, TOutput>)(input)
28
- : updater
29
- }
30
-
31
- export function noop() {
32
- //
33
- }
34
-
35
- export function makeStateUpdater(key: keyof TableState, instance: unknown) {
36
- return (updater: Updater<any, any>) => {
37
- ;(instance as any).setState(<TTableState,>(old: TTableState) => {
38
- return {
39
- ...old,
40
- [key]: functionalUpdate(updater, (old as any)[key]),
41
- }
42
- })
43
- }
44
- }
45
-
46
- // SSR has issues with useLayoutEffect still, so use useEffect during SSR
47
- export const safeUseLayoutEffect =
48
- typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
49
-
50
- export function useMountedLayoutEffect(fn: any, deps: any[]) {
51
- const mountedRef = React.useRef(false)
52
-
53
- safeUseLayoutEffect(() => {
54
- if (mountedRef.current) {
55
- fn()
56
- }
57
- mountedRef.current = true
58
- // eslint-disable-next-line
59
- }, deps)
60
- }
61
-
62
- export function useGetLatest<T>(obj: T): () => T {
63
- const ref = React.useRef<T>()
64
- ref.current = obj
65
-
66
- return React.useCallback(() => ref.current!, [])
67
- }
68
-
69
- type AnyFunction = (...args: any) => any
70
-
71
- export function isFunction<T extends AnyFunction>(d: any): d is T {
72
- return d instanceof Function
73
- }
74
-
75
- export function flattenBy<TNode>(
76
- arr: TNode[],
77
- getChildren: (item: TNode) => TNode[]
78
- ) {
79
- const flat: TNode[] = []
80
-
81
- const recurse = (subArr: TNode[]) => {
82
- subArr.forEach(item => {
83
- flat.push(item)
84
- const children = getChildren(item)
85
- if (children?.length) {
86
- recurse(children)
87
- }
88
- })
89
- }
90
-
91
- recurse(arr)
92
-
93
- return flat
94
- }
95
-
96
- type PropGetterImpl = <TBaseProps, TGetter extends Getter<TBaseProps>>(
97
- initial: TBaseProps,
98
- userProps?: TGetter
99
- ) => PropGetterValue<TBaseProps, TGetter>
100
-
101
- // @ts-ignore // Just rely on the type, not the implementation
102
- export const propGetter: PropGetterImpl = (initial, getter) => {
103
- if (isFunction(getter)) {
104
- return getter(initial)
105
- }
106
-
107
- return {
108
- ...initial,
109
- ...(getter ?? {}),
110
- }
111
- }
112
-
113
- export function memo<TDeps extends readonly any[], TResult>(
114
- getDeps: () => [...TDeps],
115
- fn: (...args: NoInfer<[...TDeps]>) => TResult,
116
- opts: {
117
- key: string
118
- debug?: boolean
119
- onChange?: (result: TResult, previousResult?: TResult) => void
120
- }
121
- ): () => TResult {
122
- let deps: any[] = []
123
- let result: TResult | undefined
124
-
125
- return () => {
126
- const newDeps = getDeps()
127
- const newSerializedDeps = newDeps
128
- const oldSerializedDeps = deps
129
-
130
- const depsChanged =
131
- newSerializedDeps.length !== oldSerializedDeps.length ||
132
- newSerializedDeps.some(
133
- (dep: any, index: number) => oldSerializedDeps[index] !== dep
134
- )
135
-
136
- if (depsChanged) {
137
- if (opts?.debug) {
138
- console.info(opts?.key, {
139
- length: `${oldSerializedDeps.length} -> ${newSerializedDeps.length}`,
140
- ...newSerializedDeps
141
- .map((_, index) => {
142
- if (oldSerializedDeps[index] !== newSerializedDeps[index]) {
143
- return [
144
- index,
145
- oldSerializedDeps[index],
146
- newSerializedDeps[index],
147
- ]
148
- }
149
-
150
- return false
151
- })
152
- .filter(Boolean)
153
- .reduce(
154
- (accu, curr: any) => ({
155
- ...accu,
156
- [curr[0]]: curr.slice(1),
157
- }),
158
- {}
159
- ),
160
- parent,
161
- })
162
- }
163
-
164
- let oldResult = result
165
- result = fn(...newDeps)
166
- deps = newSerializedDeps
167
- opts?.onChange?.(result, oldResult)
168
-
169
- oldResult = undefined
170
- }
171
-
172
- return result!
173
- }
174
- }
175
-
176
- // Copied from: https://github.com/jonschlinkert/is-plain-object
177
- export function isPlainObject(o: any): o is Object {
178
- if (!hasObjectPrototype(o)) {
179
- return false
180
- }
181
-
182
- // If has modified constructor
183
- const ctor = o.constructor
184
- if (typeof ctor === 'undefined') {
185
- return true
186
- }
187
-
188
- // If has modified prototype
189
- const prot = ctor.prototype
190
- if (!hasObjectPrototype(prot)) {
191
- return false
192
- }
193
-
194
- // If constructor does not have an Object-specific method
195
- if (!prot.hasOwnProperty('isPrototypeOf')) {
196
- return false
197
- }
198
-
199
- // Most likely a plain Object
200
- return true
201
- }
202
-
203
- function hasObjectPrototype(o: any): boolean {
204
- return Object.prototype.toString.call(o) === '[object Object]'
205
- }
206
-
207
- export type Render = typeof flexRender
208
-
209
- export function flexRender<TProps extends {}>(
210
- Comp: Renderable<TProps>,
211
- props: TProps
212
- ): React.ReactNode {
213
- return !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
214
- }
215
-
216
- function isReactComponent(component: unknown): component is React.FC {
217
- return (
218
- isClassComponent(component) ||
219
- typeof component === 'function' ||
220
- isExoticComponent(component)
221
- )
222
- }
223
-
224
- function isClassComponent(component: any) {
225
- return (
226
- typeof component === 'function' &&
227
- (() => {
228
- const proto = Object.getPrototypeOf(component)
229
- return proto.prototype && proto.prototype.isReactComponent
230
- })()
231
- )
232
- }
233
-
234
- function isExoticComponent(component: any) {
235
- return (
236
- typeof component === 'object' &&
237
- typeof component.$$typeof === 'symbol' &&
238
- ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
239
- )
240
- }
241
-
242
- // export function hashString(str: string, seed = 0): string {
243
- // let h1 = 0xdeadbeef ^ seed,
244
- // h2 = 0x41c6ce57 ^ seed
245
- // for (let i = 0, ch; i < str.length; i++) {
246
- // ch = str.charCodeAt(i)
247
- // h1 = Math.imul(h1 ^ ch, 2654435761)
248
- // h2 = Math.imul(h2 ^ ch, 1597334677)
249
- // }
250
- // h1 =
251
- // Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
252
- // Math.imul(h2 ^ (h2 >>> 13), 3266489909)
253
- // h2 =
254
- // Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
255
- // Math.imul(h1 ^ (h1 >>> 13), 3266489909)
256
- // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
257
- // }