@tanstack/table-core 8.0.0-alpha.82 → 8.0.0-alpha.85

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 (108) hide show
  1. package/build/cjs/aggregationFns.js +50 -51
  2. package/build/cjs/aggregationFns.js.map +1 -1
  3. package/build/cjs/core/cell.js +38 -0
  4. package/build/cjs/core/cell.js.map +1 -0
  5. package/build/cjs/core/column.js +88 -0
  6. package/build/cjs/core/column.js.map +1 -0
  7. package/build/cjs/{features/Headers.js → core/headers.js} +54 -66
  8. package/build/cjs/core/headers.js.map +1 -0
  9. package/build/cjs/core/instance.js +255 -0
  10. package/build/cjs/core/instance.js.map +1 -0
  11. package/build/cjs/core/row.js +77 -0
  12. package/build/cjs/core/row.js.map +1 -0
  13. package/build/cjs/createTable.js +3 -2
  14. package/build/cjs/createTable.js.map +1 -1
  15. package/build/cjs/features/ColumnSizing.js +5 -5
  16. package/build/cjs/features/ColumnSizing.js.map +1 -1
  17. package/build/cjs/features/Expanding.js.map +1 -1
  18. package/build/cjs/features/Filters.js +11 -8
  19. package/build/cjs/features/Filters.js.map +1 -1
  20. package/build/cjs/features/Grouping.js +10 -10
  21. package/build/cjs/features/Grouping.js.map +1 -1
  22. package/build/cjs/features/Ordering.js.map +1 -1
  23. package/build/cjs/features/Pagination.js.map +1 -1
  24. package/build/cjs/features/Pinning.js +17 -11
  25. package/build/cjs/features/Pinning.js.map +1 -1
  26. package/build/cjs/features/RowSelection.js.map +1 -1
  27. package/build/cjs/features/Sorting.js +8 -8
  28. package/build/cjs/features/Sorting.js.map +1 -1
  29. package/build/cjs/features/Visibility.js +3 -3
  30. package/build/cjs/features/Visibility.js.map +1 -1
  31. package/build/cjs/index.js +9 -6
  32. package/build/cjs/index.js.map +1 -1
  33. package/build/cjs/utils/filterRowsUtils.js +23 -21
  34. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  35. package/build/cjs/utils/getCoreRowModel.js +9 -8
  36. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  37. package/build/cjs/utils/getGroupedRowModel.js +13 -20
  38. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  39. package/build/cjs/utils/getSortedRowModel.js +2 -2
  40. package/build/cjs/utils/getSortedRowModel.js.map +1 -1
  41. package/build/esm/index.js +764 -865
  42. package/build/esm/index.js.map +1 -1
  43. package/build/stats-html.html +1 -1
  44. package/build/stats-react.json +404 -381
  45. package/build/types/aggregationFns.d.ts +10 -19
  46. package/build/types/core/cell.d.ts +9 -0
  47. package/build/types/{features/Columns.d.ts → core/column.d.ts} +3 -17
  48. package/build/types/{features/Headers.d.ts → core/headers.d.ts} +26 -11
  49. package/build/types/core/instance.d.ts +57 -0
  50. package/build/types/core/row.d.ts +15 -0
  51. package/build/types/createTable.d.ts +4 -4
  52. package/build/types/features/ColumnSizing.d.ts +2 -1
  53. package/build/types/features/Expanding.d.ts +2 -1
  54. package/build/types/features/Filters.d.ts +2 -3
  55. package/build/types/features/Grouping.d.ts +8 -9
  56. package/build/types/features/Ordering.d.ts +2 -1
  57. package/build/types/features/Pagination.d.ts +2 -1
  58. package/build/types/features/Pinning.d.ts +3 -2
  59. package/build/types/features/RowSelection.d.ts +2 -1
  60. package/build/types/features/Sorting.d.ts +2 -1
  61. package/build/types/features/Visibility.d.ts +2 -1
  62. package/build/types/index.d.ts +4 -2
  63. package/build/types/sortingFns.d.ts +4 -4
  64. package/build/types/types.d.ts +12 -53
  65. package/build/umd/index.development.js +767 -863
  66. package/build/umd/index.development.js.map +1 -1
  67. package/build/umd/index.production.js +1 -1
  68. package/build/umd/index.production.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/aggregationFns.ts +44 -40
  71. package/src/core/cell.ts +47 -0
  72. package/src/core/column.ts +148 -0
  73. package/src/{features/Headers.ts → core/headers.ts} +98 -99
  74. package/src/core/instance.ts +361 -0
  75. package/src/core/row.ts +85 -0
  76. package/src/createTable.ts +7 -4
  77. package/src/features/ColumnSizing.ts +6 -6
  78. package/src/features/Expanding.ts +1 -2
  79. package/src/features/Filters.ts +9 -10
  80. package/src/features/Grouping.ts +20 -22
  81. package/src/features/Ordering.ts +1 -1
  82. package/src/features/Pagination.ts +1 -1
  83. package/src/features/Pinning.ts +18 -9
  84. package/src/features/RowSelection.ts +1 -1
  85. package/src/features/Sorting.ts +10 -10
  86. package/src/features/Visibility.ts +3 -3
  87. package/src/index.ts +4 -8
  88. package/src/types.ts +16 -64
  89. package/src/utils/filterRowsUtils.ts +4 -2
  90. package/src/utils/getCoreRowModel.ts +4 -2
  91. package/src/utils/getGroupedRowModel.ts +14 -22
  92. package/src/utils/getSortedRowModel.ts +2 -2
  93. package/build/cjs/core.js +0 -168
  94. package/build/cjs/core.js.map +0 -1
  95. package/build/cjs/features/Cells.js +0 -101
  96. package/build/cjs/features/Cells.js.map +0 -1
  97. package/build/cjs/features/Columns.js +0 -189
  98. package/build/cjs/features/Columns.js.map +0 -1
  99. package/build/cjs/features/Headers.js.map +0 -1
  100. package/build/cjs/features/Rows.js +0 -94
  101. package/build/cjs/features/Rows.js.map +0 -1
  102. package/build/types/core.d.ts +0 -30
  103. package/build/types/features/Cells.d.ts +0 -13
  104. package/build/types/features/Rows.d.ts +0 -28
  105. package/src/core.ts +0 -246
  106. package/src/features/Cells.ts +0 -128
  107. package/src/features/Columns.ts +0 -289
  108. package/src/features/Rows.ts +0 -142
@@ -1,94 +0,0 @@
1
- /**
2
- * table-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var utils = require('../utils.js');
16
-
17
- //
18
- const Rows = {
19
- // createRow: <TGenerics extends TableGenerics>(
20
- // row: Row<TGenerics>,
21
- // instance: TableInstance<TGenerics>
22
- // ): CellsRow<TGenerics> => {
23
- // return {}
24
- // },
25
- createInstance: instance => {
26
- return {
27
- getRowId: (row, index, parent) => {
28
- var _instance$options$get;
29
-
30
- return (_instance$options$get = instance.options.getRowId == null ? void 0 : instance.options.getRowId(row, index, parent)) != null ? _instance$options$get : "" + (parent ? [parent.id, index].join('.') : index);
31
- },
32
- createRow: (id, original, rowIndex, depth, subRows) => {
33
- let row = {
34
- id,
35
- index: rowIndex,
36
- original,
37
- depth,
38
- valuesCache: {},
39
- getValue: columnId => {
40
- if (row.valuesCache.hasOwnProperty(columnId)) {
41
- return row.valuesCache[columnId];
42
- }
43
-
44
- const column = instance.getColumn(columnId);
45
-
46
- if (!column.accessorFn) {
47
- return undefined;
48
- }
49
-
50
- row.valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
51
- return row.valuesCache[columnId];
52
- },
53
- subRows: subRows != null ? subRows : [],
54
- getLeafRows: () => utils.flattenBy(row.subRows, d => d.subRows)
55
- };
56
-
57
- for (let i = 0; i < instance._features.length; i++) {
58
- const feature = instance._features[i];
59
- Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
60
- }
61
-
62
- return row;
63
- },
64
- getCoreRowModel: () => {
65
- if (!instance._getCoreRowModel) {
66
- instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
67
- }
68
-
69
- return instance._getCoreRowModel();
70
- },
71
- // The final calls start at the bottom of the model,
72
- // expanded rows, which then work their way up
73
- getRowModel: () => {
74
- return instance.getPaginationRowModel();
75
- },
76
- getRow: id => {
77
- const row = instance.getRowModel().rowsById[id];
78
-
79
- if (!row) {
80
- if (process.env.NODE_ENV !== 'production') {
81
- throw new Error("getRow expected an ID, but got " + id);
82
- }
83
-
84
- throw new Error();
85
- }
86
-
87
- return row;
88
- }
89
- };
90
- }
91
- };
92
-
93
- exports.Rows = Rows;
94
- //# sourceMappingURL=Rows.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Rows.js","sources":["../../../src/features/Rows.ts"],"sourcesContent":["import {\n TableGenerics,\n TableInstance,\n Row,\n RowModel,\n RowValues,\n} from '../types'\nimport { flattenBy } from '../utils'\n\nexport type CoreRow<TGenerics extends TableGenerics> = {\n id: string\n index: number\n original?: TGenerics['Row']\n depth: number\n valuesCache: Record<string, any>\n getValue: (columnId: string) => any\n subRows: Row<TGenerics>[]\n getLeafRows: () => Row<TGenerics>[]\n originalSubRows?: TGenerics['Row'][]\n}\n\nexport type RowsOptions<TGenerics extends TableGenerics> = {\n getCoreRowModel: (\n instance: TableInstance<TGenerics>\n ) => () => RowModel<TGenerics>\n getSubRows?: (\n originalRow: TGenerics['Row'],\n index: number\n ) => undefined | TGenerics['Row'][]\n getRowId?: (\n originalRow: TGenerics['Row'],\n index: number,\n parent?: Row<TGenerics>\n ) => string\n}\n\nexport type RowsInstance<TGenerics extends TableGenerics> = {\n getRowId: (\n _: TGenerics['Row'],\n index: number,\n parent?: Row<TGenerics>\n ) => string\n createRow: (\n id: string,\n original: TGenerics['Row'] | undefined,\n rowIndex: number,\n depth: number,\n subRows?: Row<TGenerics>[]\n ) => Row<TGenerics>\n getCoreRowModel: () => RowModel<TGenerics>\n _getCoreRowModel?: () => RowModel<TGenerics>\n getRowModel: () => RowModel<TGenerics>\n getRow: (id: string) => Row<TGenerics>\n}\n\n//\n\nexport const Rows = {\n // createRow: <TGenerics extends TableGenerics>(\n // row: Row<TGenerics>,\n // instance: TableInstance<TGenerics>\n // ): CellsRow<TGenerics> => {\n // return {}\n // },\n\n createInstance: <TGenerics extends TableGenerics>(\n instance: TableInstance<TGenerics>\n ): RowsInstance<TGenerics> => {\n return {\n getRowId: (\n row: TGenerics['Row'],\n index: number,\n parent?: Row<TGenerics>\n ) =>\n instance.options.getRowId?.(row, index, parent) ??\n `${parent ? [parent.id, index].join('.') : index}`,\n createRow: (id, original, rowIndex, depth, subRows) => {\n let row: CoreRow<TGenerics> = {\n id,\n index: rowIndex,\n original,\n depth,\n valuesCache: {},\n getValue: columnId => {\n if (row.valuesCache.hasOwnProperty(columnId)) {\n return row.valuesCache[columnId]\n }\n\n const column = instance.getColumn(columnId)\n\n if (!column.accessorFn) {\n return undefined\n }\n\n row.valuesCache[columnId] = column.accessorFn(\n row.original,\n rowIndex\n )\n\n return row.valuesCache[columnId]\n },\n subRows: subRows ?? [],\n getLeafRows: () => flattenBy(row.subRows, d => d.subRows),\n }\n\n for (let i = 0; i < instance._features.length; i++) {\n const feature = instance._features[i]\n Object.assign(row, feature?.createRow?.(row, instance))\n }\n\n return row as Row<TGenerics>\n },\n\n getCoreRowModel: () => {\n if (!instance._getCoreRowModel) {\n instance._getCoreRowModel = instance.options.getCoreRowModel(instance)\n }\n\n return instance._getCoreRowModel()\n },\n\n // The final calls start at the bottom of the model,\n // expanded rows, which then work their way up\n\n getRowModel: () => {\n return instance.getPaginationRowModel()\n },\n getRow: (id: string) => {\n const row = instance.getRowModel().rowsById[id]\n\n if (!row) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(`getRow expected an ID, but got ${id}`)\n }\n throw new Error()\n }\n\n return row\n },\n }\n },\n}\n"],"names":["Rows","createInstance","instance","getRowId","row","index","parent","options","id","join","createRow","original","rowIndex","depth","subRows","valuesCache","getValue","columnId","hasOwnProperty","column","getColumn","accessorFn","undefined","getLeafRows","flattenBy","d","i","_features","length","feature","Object","assign","getCoreRowModel","_getCoreRowModel","getRowModel","getPaginationRowModel","getRow","rowsById","process","env","NODE_ENV","Error"],"mappings":";;;;;;;;;;;;;;;;AAuDA;AAEO,MAAMA,IAAI,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AAEAC,EAAAA,cAAc,EACZC,QADc,IAEc;AAC5B,IAAO,OAAA;AACLC,MAAAA,QAAQ,EAAE,CACRC,GADQ,EAERC,KAFQ,EAGRC,MAHQ,KAAA;AAAA,QAAA,IAAA,qBAAA,CAAA;;AAAA,QAAA,OAAA,CAAA,qBAAA,GAKRJ,QAAQ,CAACK,OAAT,CAAiBJ,QALT,IAKRD,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,QAAQ,CAACK,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,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,YAAA,MAAM,IAAIC,KAAJ,CAA4CjC,iCAAAA,GAAAA,EAA5C,CAAN,CAAA;AACD,WAAA;;AACD,UAAM,MAAA,IAAIiC,KAAJ,EAAN,CAAA;AACD,SAAA;;AAED,QAAA,OAAOrC,GAAP,CAAA;AACD,OAAA;AAtEI,KAAP,CAAA;AAwED,GAAA;AAnFiB;;;;"}
@@ -1,30 +0,0 @@
1
- import { RequiredKeys } from './utils';
2
- import { Updater, TableOptions, TableState, TableInstance, Renderable, TableFeature, TableGenerics, InitialTableState } from './types';
3
- export declare type CoreTableState = {};
4
- export declare type CoreOptions<TGenerics extends TableGenerics> = {
5
- data: TGenerics['Row'][];
6
- state: Partial<TableState>;
7
- onStateChange: (updater: Updater<TableState>) => void;
8
- render: TGenerics['Renderer'];
9
- debugAll?: boolean;
10
- debugTable?: boolean;
11
- debugHeaders?: boolean;
12
- debugColumns?: boolean;
13
- debugRows?: boolean;
14
- initialState?: InitialTableState;
15
- autoResetAll?: boolean;
16
- mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T;
17
- meta?: TGenerics['TableMeta'];
18
- };
19
- export declare type CoreInstance<TGenerics extends TableGenerics> = {
20
- initialState: TableState;
21
- reset: () => void;
22
- options: RequiredKeys<TableOptions<TGenerics>, 'state'>;
23
- setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void;
24
- getState: () => TableState;
25
- setState: (updater: Updater<TableState>) => void;
26
- _queue: (cb: () => void) => void;
27
- _render: <TProps>(template: Renderable<TGenerics, TProps>, props: TProps) => string | null | TGenerics['Rendered'];
28
- _features: readonly TableFeature[];
29
- };
30
- export declare function createTableInstance<TGenerics extends TableGenerics>(options: TableOptions<TGenerics>): TableInstance<TGenerics>;
@@ -1,13 +0,0 @@
1
- import { Cell, TableGenerics, TableInstance, Row, Column } from '../types';
2
- export declare type CellsRow<TGenerics extends TableGenerics> = {
3
- getAllCells: () => Cell<TGenerics>[];
4
- getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>;
5
- };
6
- export declare type CellsInstance<TGenerics extends TableGenerics> = {
7
- createCell: (row: Row<TGenerics>, column: Column<TGenerics>, columnId: string) => Cell<TGenerics>;
8
- getCell: (rowId: string, columnId: string) => Cell<TGenerics>;
9
- };
10
- export declare const Cells: {
11
- createRow: <TGenerics extends TableGenerics>(row: Row<TGenerics>, instance: TableInstance<TGenerics>) => CellsRow<TGenerics>;
12
- createInstance: <TGenerics_1 extends TableGenerics>(instance: TableInstance<TGenerics_1>) => CellsInstance<TGenerics_1>;
13
- };
@@ -1,28 +0,0 @@
1
- import { TableGenerics, TableInstance, Row, RowModel } from '../types';
2
- export declare type CoreRow<TGenerics extends TableGenerics> = {
3
- id: string;
4
- index: number;
5
- original?: TGenerics['Row'];
6
- depth: number;
7
- valuesCache: Record<string, any>;
8
- getValue: (columnId: string) => any;
9
- subRows: Row<TGenerics>[];
10
- getLeafRows: () => Row<TGenerics>[];
11
- originalSubRows?: TGenerics['Row'][];
12
- };
13
- export declare type RowsOptions<TGenerics extends TableGenerics> = {
14
- getCoreRowModel: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
15
- getSubRows?: (originalRow: TGenerics['Row'], index: number) => undefined | TGenerics['Row'][];
16
- getRowId?: (originalRow: TGenerics['Row'], index: number, parent?: Row<TGenerics>) => string;
17
- };
18
- export declare type RowsInstance<TGenerics extends TableGenerics> = {
19
- getRowId: (_: TGenerics['Row'], index: number, parent?: Row<TGenerics>) => string;
20
- createRow: (id: string, original: TGenerics['Row'] | undefined, rowIndex: number, depth: number, subRows?: Row<TGenerics>[]) => Row<TGenerics>;
21
- getCoreRowModel: () => RowModel<TGenerics>;
22
- _getCoreRowModel?: () => RowModel<TGenerics>;
23
- getRowModel: () => RowModel<TGenerics>;
24
- getRow: (id: string) => Row<TGenerics>;
25
- };
26
- export declare const Rows: {
27
- createInstance: <TGenerics extends TableGenerics>(instance: TableInstance<TGenerics>) => RowsInstance<TGenerics>;
28
- };
package/src/core.ts DELETED
@@ -1,246 +0,0 @@
1
- import { functionalUpdate, RequiredKeys } from './utils'
2
-
3
- import {
4
- Updater,
5
- TableOptions,
6
- TableState,
7
- TableInstance,
8
- Renderable,
9
- TableFeature,
10
- TableGenerics,
11
- InitialTableState,
12
- } from './types'
13
-
14
- import { Columns } from './features/Columns'
15
- import { Rows } from './features/Rows'
16
- import { Cells } from './features/Cells'
17
- import { ColumnSizing } from './features/ColumnSizing'
18
- import { Expanding } from './features/Expanding'
19
- import { Filters } from './features/Filters'
20
- import { Grouping } from './features/Grouping'
21
- import { Ordering } from './features/Ordering'
22
- import { Pagination } from './features/Pagination'
23
- import { Pinning } from './features/Pinning'
24
- import { RowSelection } from './features/RowSelection'
25
- import { Sorting } from './features/Sorting'
26
- import { Visibility } from './features/Visibility'
27
- import { Headers } from './features/Headers'
28
- //
29
-
30
- export type CoreTableState = {
31
- // coreProgress: number
32
- }
33
-
34
- export type CoreOptions<TGenerics extends TableGenerics> = {
35
- data: TGenerics['Row'][]
36
- state: Partial<TableState>
37
- onStateChange: (updater: Updater<TableState>) => void
38
- render: TGenerics['Renderer']
39
- debugAll?: boolean
40
- debugTable?: boolean
41
- debugHeaders?: boolean
42
- debugColumns?: boolean
43
- debugRows?: boolean
44
- initialState?: InitialTableState
45
- autoResetAll?: boolean
46
- mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
47
- meta?: TGenerics['TableMeta']
48
- // keepPreviousData?: boolean
49
- }
50
-
51
- export type CoreInstance<TGenerics extends TableGenerics> = {
52
- // generics: TGenerics
53
- initialState: TableState
54
- reset: () => void
55
- options: RequiredKeys<TableOptions<TGenerics>, 'state'>
56
- setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void
57
- getState: () => TableState
58
- setState: (updater: Updater<TableState>) => void
59
- _queue: (cb: () => void) => void
60
- _render: <TProps>(
61
- template: Renderable<TGenerics, TProps>,
62
- props: TProps
63
- ) => string | null | TGenerics['Rendered']
64
- _features: readonly TableFeature[]
65
- // getOverallProgress: () => number
66
- // getProgressStage: () =>
67
- // | undefined
68
- // | 'coreRowModel'
69
- // | 'filteredRowModel'
70
- // | 'facetedRowModel'
71
- // createBatch: (priority: keyof CoreBatches) => Batch
72
- // init: () => void
73
- // willUpdate: () => void
74
- // destroy: () => void
75
- // batches: CoreBatches
76
- }
77
-
78
- // export type Batch = {
79
- // id: number
80
- // priority: keyof CoreBatches
81
- // tasks: (() => void)[]
82
- // schedule: (cb: () => void) => void
83
- // cancel: () => void
84
- // }
85
-
86
- // type CoreBatches = {
87
- // data: Batch[]
88
- // facets: Batch[]
89
- // }
90
-
91
- export function createTableInstance<TGenerics extends TableGenerics>(
92
- options: TableOptions<TGenerics>
93
- ): TableInstance<TGenerics> {
94
- if (options.debugAll || options.debugTable) {
95
- console.info('Creating Table Instance...')
96
- }
97
-
98
- let instance = {
99
- _features: [
100
- Columns,
101
- Rows,
102
- Cells,
103
- Headers,
104
- Visibility,
105
- Ordering,
106
- Pinning,
107
- Filters,
108
- Sorting,
109
- Grouping,
110
- Expanding,
111
- Pagination,
112
- RowSelection,
113
- ColumnSizing,
114
- ] as const,
115
- } as unknown as CoreInstance<TGenerics>
116
-
117
- const defaultOptions = instance._features.reduce((obj, feature) => {
118
- return Object.assign(obj, feature.getDefaultOptions?.(instance))
119
- }, {}) as TableOptions<TGenerics>
120
-
121
- const mergeOptions = (options: TableOptions<TGenerics>) => {
122
- if (instance.options.mergeOptions) {
123
- return instance.options.mergeOptions(defaultOptions, options)
124
- }
125
-
126
- return {
127
- ...defaultOptions,
128
- ...options,
129
- }
130
- }
131
-
132
- const coreInitialState: CoreTableState = {
133
- // coreProgress: 1,
134
- }
135
-
136
- let initialState = {
137
- ...coreInitialState,
138
- ...(options.initialState ?? {}),
139
- } as TableState
140
-
141
- instance._features.forEach(feature => {
142
- initialState = feature.getInitialState?.(initialState) ?? initialState
143
- })
144
-
145
- const queued: (() => void)[] = []
146
- let queuedTimeout = false
147
-
148
- const midInstance: CoreInstance<TGenerics> = {
149
- ...instance,
150
- // init: () => {
151
- // startWork()
152
- // },
153
- // willUpdate: () => {
154
- // startWork()
155
- // },
156
- // destroy: () => {
157
- // stopWork()
158
- // },
159
- options: {
160
- ...defaultOptions,
161
- ...options,
162
- },
163
- initialState,
164
- _queue: cb => {
165
- queued.push(cb)
166
-
167
- if (!queuedTimeout) {
168
- queuedTimeout = true
169
-
170
- // Schedule a microtask to run the queued callbacks after
171
- // the current call stack (render, etc) has finished.
172
- Promise.resolve()
173
- .then(() => {
174
- while (queued.length) {
175
- queued.shift()!()
176
- }
177
- queuedTimeout = false
178
- })
179
- .catch(error =>
180
- setTimeout(() => {
181
- throw error
182
- })
183
- )
184
- }
185
- },
186
- reset: () => {
187
- instance.setState(instance.initialState)
188
- },
189
- setOptions: updater => {
190
- const newOptions = functionalUpdate(updater, instance.options)
191
- instance.options = mergeOptions(newOptions)
192
- },
193
- _render: (template, props) => {
194
- if (typeof instance.options.render === 'function') {
195
- return instance.options.render(template, props)
196
- }
197
-
198
- if (typeof template === 'function') {
199
- return (template as Function)(props)
200
- }
201
-
202
- return template
203
- },
204
-
205
- getState: () => {
206
- return instance.options.state as TableState
207
- },
208
-
209
- setState: (updater: Updater<TableState>) => {
210
- instance.options.onStateChange?.(updater)
211
- },
212
-
213
- // getOverallProgress: () => {
214
- // const { coreProgress, filtersProgress, facetProgress } =
215
- // instance.getState()
216
-
217
- // return mean(() =>
218
- // [coreProgress, filtersProgress].filter(d => d < 1)
219
- // ) as number
220
- // },
221
- // getProgressStage: () => {
222
- // const { coreProgress, filtersProgress, facetProgress } =
223
- // instance.getState()
224
-
225
- // if (coreProgress < 1) {
226
- // return 'coreRowModel'
227
- // }
228
-
229
- // if (filtersProgress < 1) {
230
- // return 'filteredRowModel'
231
- // }
232
-
233
- // if (Object.values(facetProgress).some(d => d < 1)) {
234
- // return 'facetedRowModel'
235
- // }
236
- // },
237
- }
238
-
239
- instance = Object.assign(instance, midInstance)
240
-
241
- instance._features.forEach(feature => {
242
- return Object.assign(instance, feature.createInstance?.(instance))
243
- })
244
-
245
- return instance as TableInstance<TGenerics>
246
- }
@@ -1,128 +0,0 @@
1
- import {
2
- Cell,
3
- TableGenerics,
4
- TableInstance,
5
- Row,
6
- Column,
7
- CoreCell,
8
- } from '../types'
9
- import { memo } from '../utils'
10
-
11
- export type CellsRow<TGenerics extends TableGenerics> = {
12
- getAllCells: () => Cell<TGenerics>[]
13
- getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
14
- }
15
-
16
- export type CellsInstance<TGenerics extends TableGenerics> = {
17
- createCell: (
18
- row: Row<TGenerics>,
19
- column: Column<TGenerics>,
20
- columnId: string
21
- ) => Cell<TGenerics>
22
- getCell: (rowId: string, columnId: string) => Cell<TGenerics>
23
- }
24
-
25
- //
26
-
27
- export const Cells = {
28
- createRow: <TGenerics extends TableGenerics>(
29
- row: Row<TGenerics>,
30
- instance: TableInstance<TGenerics>
31
- ): CellsRow<TGenerics> => {
32
- return {
33
- getAllCells: memo(
34
- () => [instance.getAllLeafColumns()],
35
- leafColumns => {
36
- return leafColumns.map(column => {
37
- return instance.createCell(row as Row<TGenerics>, column, column.id)
38
- })
39
- },
40
- {
41
- key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
42
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
43
- }
44
- ),
45
-
46
- getAllCellsByColumnId: memo(
47
- () => [row.getAllCells()],
48
- allCells => {
49
- return allCells.reduce((acc, cell) => {
50
- acc[cell.columnId] = cell
51
- return acc
52
- }, {} as Record<string, Cell<TGenerics>>)
53
- },
54
- {
55
- key:
56
- process.env.NODE_ENV === 'production' &&
57
- 'row.getAllCellsByColumnId',
58
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
59
- }
60
- ),
61
- }
62
- },
63
-
64
- createInstance: <TGenerics extends TableGenerics>(
65
- instance: TableInstance<TGenerics>
66
- ): CellsInstance<TGenerics> => {
67
- return {
68
- createCell: (row, column, columnId) => {
69
- const cell: CoreCell<TGenerics> = {
70
- id: `${row.id}_${column.id}`,
71
- rowId: row.id,
72
- columnId,
73
- row,
74
- column,
75
- getValue: () => row.getValue(columnId),
76
- renderCell: () =>
77
- column.cell
78
- ? instance._render(column.cell, {
79
- instance,
80
- column,
81
- row,
82
- cell: cell as Cell<TGenerics>,
83
- getValue: cell.getValue,
84
- })
85
- : null,
86
- }
87
-
88
- instance._features.forEach(feature => {
89
- Object.assign(
90
- cell,
91
- feature.createCell?.(
92
- cell as Cell<TGenerics>,
93
- column,
94
- row as Row<TGenerics>,
95
- instance
96
- )
97
- )
98
- }, {})
99
-
100
- return cell as Cell<TGenerics>
101
- },
102
-
103
- getCell: (rowId: string, columnId: string) => {
104
- const row = instance.getRow(rowId)
105
-
106
- if (!row) {
107
- if (process.env.NODE_ENV !== 'production') {
108
- throw new Error(`[Table] could not find row with id ${rowId}`)
109
- }
110
- throw new Error()
111
- }
112
-
113
- const cell = row.getAllCellsByColumnId()[columnId]
114
-
115
- if (!cell) {
116
- if (process.env.NODE_ENV !== 'production') {
117
- throw new Error(
118
- `[Table] could not find cell ${columnId} in row ${rowId}`
119
- )
120
- }
121
- throw new Error()
122
- }
123
-
124
- return cell
125
- },
126
- }
127
- },
128
- }