@tanstack/svelte-table 8.2.5 → 8.3.1

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { SvelteComponent, init, safe_not_equal, text as text$1, claim_text, insert_hydration, set_data, noop as noop$1, detach, create_ssr_component, escape, create_component, claim_component, mount_component, transition_in, transition_out, destroy_component, validate_component } from 'svelte/internal';
11
+ import { SvelteComponent, init, safe_not_equal, text as text$1, claim_text, insert_hydration, set_data, noop as noop$1, detach, create_ssr_component, escape, validate_component, create_component, claim_component, mount_component, transition_in, transition_out, destroy_component } from 'svelte/internal';
12
12
  import { readable, get, writable, derived } from 'svelte/store';
13
13
 
14
14
  /**
@@ -21,6 +21,9 @@ import { readable, get, writable, derived } from 'svelte/store';
21
21
  *
22
22
  * @license MIT
23
23
  */
24
+ // Is this type a tuple?
25
+ // If this type is a tuple, what indices are allowed?
26
+ ///
24
27
  function functionalUpdate(updater, input) {
25
28
  return typeof updater === 'function' ? updater(input) : updater;
26
29
  }
@@ -106,13 +109,27 @@ function createColumn(table, columnDef, depth, parent) {
106
109
  const resolvedColumnDef = { ...defaultColumn,
107
110
  ...columnDef
108
111
  };
109
- let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : resolvedColumnDef.accessorKey) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
112
+ const accessorKey = resolvedColumnDef.accessorKey;
113
+ let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? accessorKey.replace('.', '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
110
114
  let accessorFn;
111
115
 
112
116
  if (resolvedColumnDef.accessorFn) {
113
117
  accessorFn = resolvedColumnDef.accessorFn;
114
- } else if (resolvedColumnDef.accessorKey) {
115
- accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
118
+ } else if (accessorKey) {
119
+ // Support deep accessor keys
120
+ if (accessorKey.includes('.')) {
121
+ accessorFn = originalRow => {
122
+ let result = originalRow;
123
+
124
+ for (const key of accessorKey.split('.')) {
125
+ result = result[key];
126
+ }
127
+
128
+ return result;
129
+ };
130
+ } else {
131
+ accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
132
+ }
116
133
  }
117
134
 
118
135
  if (!id) {
@@ -1108,7 +1125,7 @@ const Filters = {
1108
1125
  var _table$getCoreRowMode, _table$getCoreRowMode2;
1109
1126
 
1110
1127
  const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null ? void 0 : (_table$getCoreRowMode2 = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode2.getValue();
1111
- return typeof value === 'string';
1128
+ return typeof value === 'string' || typeof value === 'number';
1112
1129
  }
1113
1130
  };
1114
1131
  },
@@ -2140,7 +2157,7 @@ const RowSelection = {
2140
2157
  let isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
2141
2158
 
2142
2159
  if (isAllRowsSelected) {
2143
- if (preFilteredFlatRows.some(row => !rowSelection[row.id])) {
2160
+ if (preFilteredFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
2144
2161
  isAllRowsSelected = false;
2145
2162
  }
2146
2163
  }
@@ -2163,7 +2180,8 @@ const RowSelection = {
2163
2180
  getIsSomeRowsSelected: () => {
2164
2181
  var _table$getState$rowSe;
2165
2182
 
2166
- return !table.getIsAllRowsSelected() && !!Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2183
+ const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2184
+ return totalSelected < table.getCoreRowModel().flatRows.length;
2167
2185
  },
2168
2186
  getIsSomePageRowsSelected: () => {
2169
2187
  const paginationFlatRows = table.getPaginationRowModel().flatRows;
@@ -3102,6 +3120,52 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
3102
3120
  return row;
3103
3121
  };
3104
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
+
3105
3169
  function getCoreRowModel() {
3106
3170
  return table => memo(() => [table.options.data], data => {
3107
3171
  const rowModel = {
@@ -4005,5 +4069,5 @@ function createSvelteTable(options) {
4005
4069
  return tableReadable;
4006
4070
  }
4007
4071
 
4008
- export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createSvelteTable, createTable, defaultColumnSizing, expandRows, filterFns, flattenBy, flexRender, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, isSubRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, renderComponent, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
4072
+ export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createColumnHelper, createRow, createSvelteTable, createTable, defaultColumnSizing, expandRows, filterFns, flattenBy, flexRender, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, isSubRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, renderComponent, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
4009
4073
  //# sourceMappingURL=index.js.map