@tanstack/react-table 8.2.6 → 8.3.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.
@@ -102,6 +102,7 @@ exports.Visibility = index.Visibility;
102
102
  exports.aggregationFns = index.aggregationFns;
103
103
  exports.buildHeaderGroups = index.buildHeaderGroups;
104
104
  exports.createColumn = index.createColumn;
105
+ exports.createColumnHelper = index.createColumnHelper;
105
106
  exports.createRow = index.createRow;
106
107
  exports.createTable = index.createTable;
107
108
  exports.defaultColumnSizing = index.defaultColumnSizing;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n TableOptions,\n TableOptionsResolved,\n RowData,\n createTable,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>\n\n//\n\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\nfunction isReactComponent<TProps>(\n component: unknown\n): component is React.ComponentType<TProps> {\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\nexport function useReactTable<TData extends RowData>(\n options: TableOptions<TData>\n) {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TData> = {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table and store it in state\n const [tableRef] = React.useState(() => ({\n current: createTable<TData>(resolvedOptions),\n }))\n\n // By default, manage table state here using the table's initial state\n const [state, setState] = React.useState(() => tableRef.current.initialState)\n\n // Compose the default state above with any user state. This will allow the user\n // to only control a subset of the state if desired.\n tableRef.current.setOptions(prev => ({\n ...prev,\n ...options,\n state: {\n ...state,\n ...options.state,\n },\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: updater => {\n setState(updater)\n options.onStateChange?.(updater)\n },\n }))\n\n return tableRef.current\n}\n"],"names":["flexRender","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","useReactTable","options","resolvedOptions","state","onStateChange","renderFallbackValue","tableRef","useState","current","createTable","setState","initialState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AAEO,SAASA,UAAT,CACLC,IADK,EAELC,KAFK,EAG0B;AAC/B,EAAA,OAAO,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAASF,IAAT,CAAhB,gBACpBG,+BAAC,IAAD,EAAUF,KAAV,CADoB,GAGpBD,IAHF,CAAA;AAKD,CAAA;;AAED,SAASE,gBAAT,CACEE,SADF,EAE4C;AAC1C,EAAA,OACEC,gBAAgB,CAACD,SAAD,CAAhB,IACA,OAAOA,SAAP,KAAqB,UADrB,IAEAE,iBAAiB,CAACF,SAAD,CAHnB,CAAA;AAKD,CAAA;;AAED,SAASC,gBAAT,CAA0BD,SAA1B,EAA0C;AACxC,EAAA,OACE,OAAOA,SAAP,KAAqB,UAArB,IACA,CAAC,MAAM;AACL,IAAA,MAAMG,KAAK,GAAGC,MAAM,CAACC,cAAP,CAAsBL,SAAtB,CAAd,CAAA;IACA,OAAOG,KAAK,CAACG,SAAN,IAAmBH,KAAK,CAACG,SAAN,CAAgBR,gBAA1C,CAAA;AACD,GAHD,GAFF,CAAA;AAOD,CAAA;;AAED,SAASI,iBAAT,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n TableOptions,\n TableOptionsResolved,\n RowData,\n createTable,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>\n\n//\n\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\nfunction isReactComponent<TProps>(\n component: unknown\n): component is React.ComponentType<TProps> {\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\nexport function useReactTable<TData extends RowData>(\n options: TableOptions<TData>\n) {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TData> = {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table and store it in state\n const [tableRef] = React.useState(() => ({\n current: createTable<TData>(resolvedOptions),\n }))\n\n // By default, manage table state here using the table's initial state\n const [state, setState] = React.useState(() => tableRef.current.initialState)\n\n // Compose the default state above with any user state. This will allow the user\n // to only control a subset of the state if desired.\n tableRef.current.setOptions(prev => ({\n ...prev,\n ...options,\n state: {\n ...state,\n ...options.state,\n },\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: updater => {\n setState(updater)\n options.onStateChange?.(updater)\n },\n }))\n\n return tableRef.current\n}\n"],"names":["flexRender","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","useReactTable","options","resolvedOptions","state","onStateChange","renderFallbackValue","tableRef","useState","current","createTable","setState","initialState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AAEO,SAASA,UAAT,CACLC,IADK,EAELC,KAFK,EAG0B;AAC/B,EAAA,OAAO,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAASF,IAAT,CAAhB,gBACpBG,+BAAC,IAAD,EAAUF,KAAV,CADoB,GAGpBD,IAHF,CAAA;AAKD,CAAA;;AAED,SAASE,gBAAT,CACEE,SADF,EAE4C;AAC1C,EAAA,OACEC,gBAAgB,CAACD,SAAD,CAAhB,IACA,OAAOA,SAAP,KAAqB,UADrB,IAEAE,iBAAiB,CAACF,SAAD,CAHnB,CAAA;AAKD,CAAA;;AAED,SAASC,gBAAT,CAA0BD,SAA1B,EAA0C;AACxC,EAAA,OACE,OAAOA,SAAP,KAAqB,UAArB,IACA,CAAC,MAAM;AACL,IAAA,MAAMG,KAAK,GAAGC,MAAM,CAACC,cAAP,CAAsBL,SAAtB,CAAd,CAAA;IACA,OAAOG,KAAK,CAACG,SAAN,IAAmBH,KAAK,CAACG,SAAN,CAAgBR,gBAA1C,CAAA;AACD,GAHD,GAFF,CAAA;AAOD,CAAA;;AAED,SAASI,iBAAT,CAA2BF,SAA3B,EAA2C;EACzC,OACE,OAAOA,SAAP,KAAqB,QAArB,IACA,OAAOA,SAAS,CAACO,QAAjB,KAA8B,QAD9B,IAEA,CAAC,YAAD,EAAe,mBAAf,CAAA,CAAoCC,QAApC,CAA6CR,SAAS,CAACO,QAAV,CAAmBE,WAAhE,CAHF,CAAA;AAKD,CAAA;;AAEM,SAASC,aAAT,CACLC,OADK,EAEL;AACA;AACA,EAAA,MAAMC,eAA4C,GAAG;AACnDC,IAAAA,KAAK,EAAE,EAD4C;AACxC;IACXC,aAAa,EAAE,MAAM,EAF8B;AAE1B;AACzBC,IAAAA,mBAAmB,EAAE,IAH8B;IAInD,GAAGJ,OAAAA;AAJgD,GAArD,CAFA;;AAUA,EAAA,MAAM,CAACK,QAAD,CAAA,GAAajB,gBAAK,CAACkB,QAAN,CAAe,OAAO;IACvCC,OAAO,EAAEC,iBAAW,CAAQP,eAAR,CAAA;GADY,CAAf,CAAnB,CAVA;;AAeA,EAAA,MAAM,CAACC,KAAD,EAAQO,QAAR,CAAA,GAAoBrB,gBAAK,CAACkB,QAAN,CAAe,MAAMD,QAAQ,CAACE,OAAT,CAAiBG,YAAtC,CAA1B,CAfA;AAkBA;;EACAL,QAAQ,CAACE,OAAT,CAAiBI,UAAjB,CAA4BC,IAAI,KAAK,EACnC,GAAGA,IADgC;AAEnC,IAAA,GAAGZ,OAFgC;IAGnCE,KAAK,EAAE,EACL,GAAGA,KADE;AAEL,MAAA,GAAGF,OAAO,CAACE,KAAAA;KALsB;AAOnC;AACA;IACAC,aAAa,EAAEU,OAAO,IAAI;MACxBJ,QAAQ,CAACI,OAAD,CAAR,CAAA;AACAb,MAAAA,OAAO,CAACG,aAAR,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAH,OAAO,CAACG,aAAR,CAAwBU,OAAxB,CAAA,CAAA;AACD,KAAA;AAZkC,GAAL,CAAhC,CAAA,CAAA;EAeA,OAAOR,QAAQ,CAACE,OAAhB,CAAA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -22,6 +22,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
22
22
  *
23
23
  * @license MIT
24
24
  */
25
+ // Is this type a tuple?
26
+ // If this type is a tuple, what indices are allowed?
27
+ ///
25
28
  function functionalUpdate(updater, input) {
26
29
  return typeof updater === 'function' ? updater(input) : updater;
27
30
  }
@@ -107,13 +110,27 @@ function createColumn(table, columnDef, depth, parent) {
107
110
  const resolvedColumnDef = { ...defaultColumn,
108
111
  ...columnDef
109
112
  };
110
- let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : resolvedColumnDef.accessorKey) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
113
+ const accessorKey = resolvedColumnDef.accessorKey;
114
+ let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? accessorKey.replace('.', '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
111
115
  let accessorFn;
112
116
 
113
117
  if (resolvedColumnDef.accessorFn) {
114
118
  accessorFn = resolvedColumnDef.accessorFn;
115
- } else if (resolvedColumnDef.accessorKey) {
116
- accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
119
+ } else if (accessorKey) {
120
+ // Support deep accessor keys
121
+ if (accessorKey.includes('.')) {
122
+ accessorFn = originalRow => {
123
+ let result = originalRow;
124
+
125
+ for (const key of accessorKey.split('.')) {
126
+ result = result[key];
127
+ }
128
+
129
+ return result;
130
+ };
131
+ } else {
132
+ accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
133
+ }
117
134
  }
118
135
 
119
136
  if (!id) {
@@ -3103,6 +3120,52 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
3103
3120
  return row;
3104
3121
  };
3105
3122
 
3123
+ // type Person = {
3124
+ // firstName: string
3125
+ // lastName: string
3126
+ // age: number
3127
+ // visits: number
3128
+ // status: string
3129
+ // progress: number
3130
+ // nested: {
3131
+ // foo: [
3132
+ // {
3133
+ // bar: 'bar'
3134
+ // }
3135
+ // ]
3136
+ // bar: { subBar: boolean }[]
3137
+ // baz: {
3138
+ // foo: 'foo'
3139
+ // bar: {
3140
+ // baz: 'baz'
3141
+ // }
3142
+ // }
3143
+ // }
3144
+ // }
3145
+ // const test: DeepKeys<Person> = 'nested.foo.0.bar'
3146
+ // const test2: DeepKeys<Person> = 'nested.bar'
3147
+ // const helper = createColumnHelper<Person>()
3148
+ // helper.accessor('nested.foo', {
3149
+ // cell: info => info.getValue(),
3150
+ // })
3151
+ // helper.accessor('nested.foo.0.bar', {
3152
+ // cell: info => info.getValue(),
3153
+ // })
3154
+ // helper.accessor('nested.bar', {
3155
+ // cell: info => info.getValue(),
3156
+ // })
3157
+ function createColumnHelper() {
3158
+ return {
3159
+ accessor: (accessor, column) => {
3160
+ return typeof accessor === 'function' ? { ...column,
3161
+ accessorFn: accessor
3162
+ } : { ...column,
3163
+ accessorKey: accessor
3164
+ };
3165
+ }
3166
+ };
3167
+ }
3168
+
3106
3169
  function getCoreRowModel() {
3107
3170
  return table => memo(() => [table.options.data], data => {
3108
3171
  const rowModel = {
@@ -3812,6 +3875,7 @@ exports.Visibility = Visibility;
3812
3875
  exports.aggregationFns = aggregationFns;
3813
3876
  exports.buildHeaderGroups = buildHeaderGroups;
3814
3877
  exports.createColumn = createColumn;
3878
+ exports.createColumnHelper = createColumnHelper;
3815
3879
  exports.createRow = createRow;
3816
3880
  exports.createTable = createTable;
3817
3881
  exports.defaultColumnSizing = defaultColumnSizing;