@tanstack/svelte-table 8.0.0-alpha.86 → 8.0.0-alpha.89

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.
@@ -2669,7 +2669,7 @@ var drawChart = (function (exports) {
2669
2669
  </script>
2670
2670
  <script>
2671
2671
  /*<!--*/
2672
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages","children":[{"name":"table-core/build/esm/index.js","uid":"74a1-163"},{"name":"svelte-table/src","children":[{"uid":"74a1-165","name":"placeholder.svelte"},{"uid":"74a1-167","name":"render-component.ts"},{"uid":"74a1-169","name":"index.ts"}]}]}]}],"isRoot":true},"nodeParts":{"74a1-163":{"renderedLength":137360,"gzipLength":23349,"brotliLength":0,"mainUid":"74a1-162"},"74a1-165":{"renderedLength":925,"gzipLength":444,"brotliLength":0,"mainUid":"74a1-164"},"74a1-167":{"renderedLength":1365,"gzipLength":519,"brotliLength":0,"mainUid":"74a1-166"},"74a1-169":{"renderedLength":2729,"gzipLength":868,"brotliLength":0,"mainUid":"74a1-168"}},"nodeMetas":{"74a1-162":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"74a1-163"},"imported":[],"importedBy":[{"uid":"74a1-168"}]},"74a1-164":{"id":"/packages/svelte-table/src/placeholder.svelte","moduleParts":{"index.production.js":"74a1-165"},"imported":[{"uid":"74a1-170"}],"importedBy":[{"uid":"74a1-168"}]},"74a1-166":{"id":"/packages/svelte-table/src/render-component.ts","moduleParts":{"index.production.js":"74a1-167"},"imported":[{"uid":"74a1-170"}],"importedBy":[{"uid":"74a1-168"}]},"74a1-168":{"id":"/packages/svelte-table/src/index.ts","moduleParts":{"index.production.js":"74a1-169"},"imported":[{"uid":"74a1-162"},{"uid":"74a1-164"},{"uid":"74a1-170"},{"uid":"74a1-171"},{"uid":"74a1-166"}],"importedBy":[],"isEntry":true},"74a1-170":{"id":"svelte/internal","moduleParts":{},"imported":[],"importedBy":[{"uid":"74a1-168"},{"uid":"74a1-164"},{"uid":"74a1-166"}],"isExternal":true},"74a1-171":{"id":"svelte/store","moduleParts":{},"imported":[],"importedBy":[{"uid":"74a1-168"}],"isExternal":true}},"env":{"rollup":"2.70.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
2672
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages","children":[{"name":"table-core/build/esm/index.js","uid":"756b-163"},{"name":"svelte-table/src","children":[{"uid":"756b-165","name":"placeholder.svelte"},{"uid":"756b-167","name":"render-component.ts"},{"uid":"756b-169","name":"index.ts"}]}]}]}],"isRoot":true},"nodeParts":{"756b-163":{"renderedLength":137944,"gzipLength":23474,"brotliLength":0,"mainUid":"756b-162"},"756b-165":{"renderedLength":925,"gzipLength":444,"brotliLength":0,"mainUid":"756b-164"},"756b-167":{"renderedLength":1365,"gzipLength":519,"brotliLength":0,"mainUid":"756b-166"},"756b-169":{"renderedLength":2729,"gzipLength":868,"brotliLength":0,"mainUid":"756b-168"}},"nodeMetas":{"756b-162":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"756b-163"},"imported":[],"importedBy":[{"uid":"756b-168"}]},"756b-164":{"id":"/packages/svelte-table/src/placeholder.svelte","moduleParts":{"index.production.js":"756b-165"},"imported":[{"uid":"756b-170"}],"importedBy":[{"uid":"756b-168"}]},"756b-166":{"id":"/packages/svelte-table/src/render-component.ts","moduleParts":{"index.production.js":"756b-167"},"imported":[{"uid":"756b-170"}],"importedBy":[{"uid":"756b-168"}]},"756b-168":{"id":"/packages/svelte-table/src/index.ts","moduleParts":{"index.production.js":"756b-169"},"imported":[{"uid":"756b-162"},{"uid":"756b-164"},{"uid":"756b-170"},{"uid":"756b-171"},{"uid":"756b-166"}],"importedBy":[],"isEntry":true},"756b-170":{"id":"svelte/internal","moduleParts":{},"imported":[],"importedBy":[{"uid":"756b-168"},{"uid":"756b-164"},{"uid":"756b-166"}],"isExternal":true},"756b-171":{"id":"svelte/store","moduleParts":{},"imported":[],"importedBy":[{"uid":"756b-168"}],"isExternal":true}},"env":{"rollup":"2.70.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
2673
2673
 
2674
2674
  const run = () => {
2675
2675
  const width = window.innerWidth;
@@ -11,21 +11,21 @@
11
11
  "children": [
12
12
  {
13
13
  "name": "table-core/build/esm/index.js",
14
- "uid": "74a1-173"
14
+ "uid": "756b-173"
15
15
  },
16
16
  {
17
17
  "name": "svelte-table/src",
18
18
  "children": [
19
19
  {
20
- "uid": "74a1-175",
20
+ "uid": "756b-175",
21
21
  "name": "placeholder.svelte"
22
22
  },
23
23
  {
24
- "uid": "74a1-177",
24
+ "uid": "756b-177",
25
25
  "name": "render-component.ts"
26
26
  },
27
27
  {
28
- "uid": "74a1-179",
28
+ "uid": "756b-179",
29
29
  "name": "index.ts"
30
30
  }
31
31
  ]
@@ -38,125 +38,125 @@
38
38
  "isRoot": true
39
39
  },
40
40
  "nodeParts": {
41
- "74a1-173": {
42
- "renderedLength": 137360,
43
- "gzipLength": 23349,
41
+ "756b-173": {
42
+ "renderedLength": 137944,
43
+ "gzipLength": 23474,
44
44
  "brotliLength": 0,
45
- "mainUid": "74a1-172"
45
+ "mainUid": "756b-172"
46
46
  },
47
- "74a1-175": {
47
+ "756b-175": {
48
48
  "renderedLength": 925,
49
49
  "gzipLength": 444,
50
50
  "brotliLength": 0,
51
- "mainUid": "74a1-174"
51
+ "mainUid": "756b-174"
52
52
  },
53
- "74a1-177": {
53
+ "756b-177": {
54
54
  "renderedLength": 1365,
55
55
  "gzipLength": 519,
56
56
  "brotliLength": 0,
57
- "mainUid": "74a1-176"
57
+ "mainUid": "756b-176"
58
58
  },
59
- "74a1-179": {
59
+ "756b-179": {
60
60
  "renderedLength": 2729,
61
61
  "gzipLength": 868,
62
62
  "brotliLength": 0,
63
- "mainUid": "74a1-178"
63
+ "mainUid": "756b-178"
64
64
  }
65
65
  },
66
66
  "nodeMetas": {
67
- "74a1-172": {
67
+ "756b-172": {
68
68
  "id": "/packages/table-core/build/esm/index.js",
69
69
  "moduleParts": {
70
- "index.production.js": "74a1-173"
70
+ "index.production.js": "756b-173"
71
71
  },
72
72
  "imported": [],
73
73
  "importedBy": [
74
74
  {
75
- "uid": "74a1-178"
75
+ "uid": "756b-178"
76
76
  }
77
77
  ]
78
78
  },
79
- "74a1-174": {
79
+ "756b-174": {
80
80
  "id": "/packages/svelte-table/src/placeholder.svelte",
81
81
  "moduleParts": {
82
- "index.production.js": "74a1-175"
82
+ "index.production.js": "756b-175"
83
83
  },
84
84
  "imported": [
85
85
  {
86
- "uid": "74a1-180"
86
+ "uid": "756b-180"
87
87
  }
88
88
  ],
89
89
  "importedBy": [
90
90
  {
91
- "uid": "74a1-178"
91
+ "uid": "756b-178"
92
92
  }
93
93
  ]
94
94
  },
95
- "74a1-176": {
95
+ "756b-176": {
96
96
  "id": "/packages/svelte-table/src/render-component.ts",
97
97
  "moduleParts": {
98
- "index.production.js": "74a1-177"
98
+ "index.production.js": "756b-177"
99
99
  },
100
100
  "imported": [
101
101
  {
102
- "uid": "74a1-180"
102
+ "uid": "756b-180"
103
103
  }
104
104
  ],
105
105
  "importedBy": [
106
106
  {
107
- "uid": "74a1-178"
107
+ "uid": "756b-178"
108
108
  }
109
109
  ]
110
110
  },
111
- "74a1-178": {
111
+ "756b-178": {
112
112
  "id": "/packages/svelte-table/src/index.ts",
113
113
  "moduleParts": {
114
- "index.production.js": "74a1-179"
114
+ "index.production.js": "756b-179"
115
115
  },
116
116
  "imported": [
117
117
  {
118
- "uid": "74a1-172"
118
+ "uid": "756b-172"
119
119
  },
120
120
  {
121
- "uid": "74a1-174"
121
+ "uid": "756b-174"
122
122
  },
123
123
  {
124
- "uid": "74a1-180"
124
+ "uid": "756b-180"
125
125
  },
126
126
  {
127
- "uid": "74a1-181"
127
+ "uid": "756b-181"
128
128
  },
129
129
  {
130
- "uid": "74a1-176"
130
+ "uid": "756b-176"
131
131
  }
132
132
  ],
133
133
  "importedBy": [],
134
134
  "isEntry": true
135
135
  },
136
- "74a1-180": {
136
+ "756b-180": {
137
137
  "id": "svelte/internal",
138
138
  "moduleParts": {},
139
139
  "imported": [],
140
140
  "importedBy": [
141
141
  {
142
- "uid": "74a1-178"
142
+ "uid": "756b-178"
143
143
  },
144
144
  {
145
- "uid": "74a1-174"
145
+ "uid": "756b-174"
146
146
  },
147
147
  {
148
- "uid": "74a1-176"
148
+ "uid": "756b-176"
149
149
  }
150
150
  ],
151
151
  "isExternal": true
152
152
  },
153
- "74a1-181": {
153
+ "756b-181": {
154
154
  "id": "svelte/store",
155
155
  "moduleParts": {},
156
156
  "imported": [],
157
157
  "importedBy": [
158
158
  {
159
- "uid": "74a1-178"
159
+ "uid": "756b-178"
160
160
  }
161
161
  ],
162
162
  "isExternal": true
@@ -124,7 +124,7 @@
124
124
  }
125
125
  }
126
126
 
127
- let column = { ...columnDef,
127
+ let column = {
128
128
  id: "" + id,
129
129
  accessorFn,
130
130
  parent: parent,
@@ -888,8 +888,12 @@
888
888
  getIsAllRowsExpanded: () => {
889
889
  const expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
890
890
 
891
- if (expanded === true) {
892
- return true;
891
+ if (typeof expanded === 'boolean') {
892
+ return expanded === true;
893
+ }
894
+
895
+ if (!Object.keys(expanded).length) {
896
+ return false;
893
897
  } // If any row is not expanded, return false
894
898
 
895
899
 
@@ -2344,21 +2348,54 @@
2344
2348
  }
2345
2349
 
2346
2350
  const reSplitAlphaNumeric = /([0-9]+)/gm;
2347
- const sortingFns = {
2348
- alphanumeric,
2349
- alphanumericCaseSensitive,
2350
- text,
2351
- textCaseSensitive,
2352
- datetime,
2353
- basic
2354
- };
2355
2351
 
2356
- function alphanumeric(rowA, rowB, columnId) {
2352
+ const alphanumeric = (rowA, rowB, columnId) => {
2357
2353
  return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2358
- }
2354
+ };
2359
2355
 
2360
- function alphanumericCaseSensitive(rowA, rowB, columnId) {
2356
+ const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
2361
2357
  return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2358
+ }; // The text filter is more basic (less numeric support)
2359
+ // but is much faster
2360
+
2361
+
2362
+ const text = (rowA, rowB, columnId) => {
2363
+ return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2364
+ }; // The text filter is more basic (less numeric support)
2365
+ // but is much faster
2366
+
2367
+
2368
+ const textCaseSensitive = (rowA, rowB, columnId) => {
2369
+ return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2370
+ };
2371
+
2372
+ const datetime = (rowA, rowB, columnId) => {
2373
+ return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2374
+ };
2375
+
2376
+ const basic = (rowA, rowB, columnId) => {
2377
+ return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2378
+ }; // Utils
2379
+
2380
+
2381
+ function compareBasic(a, b) {
2382
+ return a === b ? 0 : a > b ? 1 : -1;
2383
+ }
2384
+
2385
+ function toString(a) {
2386
+ if (typeof a === 'number') {
2387
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
2388
+ return '';
2389
+ }
2390
+
2391
+ return String(a);
2392
+ }
2393
+
2394
+ if (typeof a === 'string') {
2395
+ return a;
2396
+ }
2397
+
2398
+ return '';
2362
2399
  } // Mixed sorting is slow, but very inclusive of many edge cases.
2363
2400
  // It handles numbers, mixed alphanumeric combinations, and even
2364
2401
  // null, undefined, and Infinity
@@ -2405,48 +2442,17 @@
2405
2442
  }
2406
2443
 
2407
2444
  return a.length - b.length;
2408
- } // The text filter is more basic (less numeric support)
2409
- // but is much faster
2410
-
2411
-
2412
- function text(rowA, rowB, columnId) {
2413
- return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2414
- } // The text filter is more basic (less numeric support)
2415
- // but is much faster
2416
-
2417
-
2418
- function textCaseSensitive(rowA, rowB, columnId) {
2419
- return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2420
- }
2421
-
2422
- function datetime(rowA, rowB, columnId) {
2423
- return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2424
- }
2425
-
2426
- function basic(rowA, rowB, columnId) {
2427
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2428
- } // Utils
2429
-
2430
-
2431
- function compareBasic(a, b) {
2432
- return a === b ? 0 : a > b ? 1 : -1;
2433
- }
2445
+ } // Exports
2434
2446
 
2435
- function toString(a) {
2436
- if (typeof a === 'number') {
2437
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2438
- return '';
2439
- }
2440
-
2441
- return String(a);
2442
- }
2443
2447
 
2444
- if (typeof a === 'string') {
2445
- return a;
2446
- }
2447
-
2448
- return '';
2449
- }
2448
+ const sortingFns = {
2449
+ alphanumeric,
2450
+ alphanumericCaseSensitive,
2451
+ text,
2452
+ textCaseSensitive,
2453
+ datetime,
2454
+ basic
2455
+ };
2450
2456
 
2451
2457
  //
2452
2458
  const Sorting = {
@@ -2527,8 +2533,10 @@
2527
2533
  // })
2528
2534
  // return
2529
2535
  // }
2536
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2537
+ const nextSortingOrder = column.getNextSortingOrder();
2530
2538
  instance.setSorting(old => {
2531
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2539
+ var _instance$options$ena, _instance$options$ena2;
2532
2540
 
2533
2541
  // Find any existing sorting for this column
2534
2542
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2553,30 +2561,29 @@
2553
2561
  } else {
2554
2562
  sortAction = 'replace';
2555
2563
  }
2556
- }
2564
+ } // Handle toggle states that will remove the sorting
2557
2565
 
2558
- const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc'; // Handle toggle states that will remove the sorting
2559
2566
 
2560
2567
  if (sortAction === 'toggle' && ( // Must be toggling
2561
2568
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2562
2569
  !hasDescDefined && ( // Must not be setting desc
2563
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2564
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2565
- ? !sortDescFirst : sortDescFirst)) {
2570
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2571
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2572
+ ) {
2566
2573
  sortAction = 'remove';
2567
2574
  }
2568
2575
 
2569
2576
  if (sortAction === 'replace') {
2570
2577
  newSorting = [{
2571
2578
  id: column.id,
2572
- desc: hasDescDefined ? desc : !!sortDescFirst
2579
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2573
2580
  }];
2574
2581
  } else if (sortAction === 'add' && old != null && old.length) {
2575
2582
  var _instance$options$max;
2576
2583
 
2577
2584
  newSorting = [...old, {
2578
2585
  id: column.id,
2579
- desc: hasDescDefined ? desc : !!sortDescFirst
2586
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2580
2587
  }]; // Take latest n columns
2581
2588
 
2582
2589
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2585,7 +2592,7 @@
2585
2592
  newSorting = old.map(d => {
2586
2593
  if (d.id === column.id) {
2587
2594
  return { ...d,
2588
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2595
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2589
2596
  };
2590
2597
  }
2591
2598
 
@@ -2598,6 +2605,23 @@
2598
2605
  return newSorting;
2599
2606
  });
2600
2607
  },
2608
+ getNextSortingOrder: () => {
2609
+ var _ref2, _column$columnDef$sor;
2610
+
2611
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2612
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2613
+ const isSorted = column.getIsSorted();
2614
+
2615
+ if (!isSorted) {
2616
+ return firstSortDirection;
2617
+ }
2618
+
2619
+ if (isSorted === firstSortDirection) {
2620
+ return isSorted === 'desc' ? 'asc' : 'desc';
2621
+ } else {
2622
+ return false;
2623
+ }
2624
+ },
2601
2625
  getCanSort: () => {
2602
2626
  var _column$columnDef$ena, _instance$options$ena3;
2603
2627
 
@@ -2698,8 +2722,8 @@
2698
2722
  },
2699
2723
  createRow: (row, instance) => {
2700
2724
  return {
2701
- _getAllVisibleCells: memo(() => [row.getAllCells().filter(cell => cell.column.getIsVisible()).map(d => d.id).join('_')], _ => {
2702
- return row.getAllCells().filter(cell => cell.column.getIsVisible());
2725
+ _getAllVisibleCells: memo(() => [row.getAllCells(), instance.getState().columnVisibility], cells => {
2726
+ return cells.filter(cell => cell.column.getIsVisible());
2703
2727
  }, {
2704
2728
  key: "development" === 'production' ,
2705
2729
  debug: () => {
@@ -3050,13 +3074,15 @@
3050
3074
  row,
3051
3075
  column,
3052
3076
  getValue: () => row.getValue(columnId),
3053
- renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
3054
- instance,
3055
- column,
3056
- row,
3057
- cell: cell,
3058
- getValue: cell.getValue
3059
- }) : null
3077
+ renderCell: () => {
3078
+ return column.columnDef.cell ? instance._render(column.columnDef.cell, {
3079
+ instance,
3080
+ column,
3081
+ row,
3082
+ cell: cell,
3083
+ getValue: cell.getValue
3084
+ }) : null;
3085
+ }
3060
3086
  };
3061
3087
 
3062
3088
  instance._features.forEach(feature => {
@@ -3131,27 +3157,23 @@
3131
3157
  flatRows: [],
3132
3158
  rowsById: {}
3133
3159
  };
3134
- let rows;
3135
- let row;
3136
- let originalRow;
3137
3160
 
3138
3161
  const accessRows = function (originalRows, depth, parent) {
3139
3162
  if (depth === void 0) {
3140
3163
  depth = 0;
3141
3164
  }
3142
3165
 
3143
- rows = [];
3166
+ const rows = [];
3144
3167
 
3145
3168
  for (let i = 0; i < originalRows.length; i++) {
3146
- originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3169
+ // This could be an expensive check at scale, so we should move it somewhere else, but where?
3147
3170
  // if (!id) {
3148
3171
  // if ("development" !== 'production') {
3149
3172
  // throw new Error(`getRowId expected an ID, but got ${id}`)
3150
3173
  // }
3151
3174
  // }
3152
3175
  // Make the row
3153
-
3154
- row = createRow(instance, instance._getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3176
+ const row = createRow(instance, instance._getRowId(originalRows[i], i, parent), originalRows[i], i, depth); // Keep track of every row in a flat array
3155
3177
 
3156
3178
  rowModel.flatRows.push(row); // Also keep track of every row by its ID
3157
3179
 
@@ -3162,7 +3184,7 @@
3162
3184
  if (instance.options.getSubRows) {
3163
3185
  var _row$originalSubRows;
3164
3186
 
3165
- row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3187
+ row.originalSubRows = instance.options.getSubRows(originalRows[i], i); // Then recursively access them
3166
3188
 
3167
3189
  if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3168
3190
  row.subRows = accessRows(row.originalSubRows, depth + 1, row);