@tanstack/svelte-table 8.0.0-beta.2 → 8.0.0-beta.5
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.
- package/build/cjs/svelte-table/src/index.js +6 -2
- package/build/cjs/svelte-table/src/index.js.map +1 -1
- package/build/cjs/svelte-table/src/placeholder.js +24 -0
- package/build/cjs/svelte-table/src/placeholder.js.map +1 -0
- package/build/cjs/svelte-table/src/render-component.js +5 -1
- package/build/cjs/svelte-table/src/render-component.js.map +1 -1
- package/build/cjs/table-core/build/esm/index.js +78 -33
- package/build/cjs/table-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +99 -38
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +76 -44
- package/build/types/placeholder.d.ts +3 -0
- package/build/umd/index.development.js +94 -36
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +10 -2
- package/src/placeholder.ts +15 -0
- package/src/render-component.ts +5 -1
package/build/esm/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { SvelteComponent, init, safe_not_equal, text as text$1,
|
|
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';
|
|
12
12
|
import { readable, get, writable, derived } from 'svelte/store';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -1107,7 +1107,6 @@ const Filters = {
|
|
|
1107
1107
|
},
|
|
1108
1108
|
createColumn: (column, instance) => {
|
|
1109
1109
|
return {
|
|
1110
|
-
filterFn: column.filterFn,
|
|
1111
1110
|
getAutoFilterFn: () => {
|
|
1112
1111
|
const firstRow = instance.getCoreRowModel().flatRows[0];
|
|
1113
1112
|
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
@@ -1138,7 +1137,7 @@ const Filters = {
|
|
|
1138
1137
|
var _ref;
|
|
1139
1138
|
|
|
1140
1139
|
const userFilterFns = instance.options.filterFns;
|
|
1141
|
-
return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
|
|
1140
|
+
return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.columnDef.filterFn]) != null ? _ref : filterFns[column.columnDef.filterFn];
|
|
1142
1141
|
},
|
|
1143
1142
|
getCanFilter: () => {
|
|
1144
1143
|
var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
|
|
@@ -1427,6 +1426,11 @@ const aggregationFns = {
|
|
|
1427
1426
|
const Grouping = {
|
|
1428
1427
|
getDefaultColumnDef: () => {
|
|
1429
1428
|
return {
|
|
1429
|
+
aggregatedCell: props => {
|
|
1430
|
+
var _props$getValue$toStr, _props$getValue;
|
|
1431
|
+
|
|
1432
|
+
return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
|
|
1433
|
+
},
|
|
1430
1434
|
aggregationFn: 'auto'
|
|
1431
1435
|
};
|
|
1432
1436
|
},
|
|
@@ -1487,8 +1491,6 @@ const Grouping = {
|
|
|
1487
1491
|
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
1488
1492
|
return aggregationFns.extent;
|
|
1489
1493
|
}
|
|
1490
|
-
|
|
1491
|
-
return aggregationFns.count;
|
|
1492
1494
|
},
|
|
1493
1495
|
getAggregationFn: () => {
|
|
1494
1496
|
var _ref4;
|
|
@@ -1499,7 +1501,7 @@ const Grouping = {
|
|
|
1499
1501
|
throw new Error();
|
|
1500
1502
|
}
|
|
1501
1503
|
|
|
1502
|
-
return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
|
|
1504
|
+
return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.columnDef.aggregationFn]) != null ? _ref4 : aggregationFns[column.columnDef.aggregationFn];
|
|
1503
1505
|
}
|
|
1504
1506
|
};
|
|
1505
1507
|
},
|
|
@@ -1532,6 +1534,12 @@ const Grouping = {
|
|
|
1532
1534
|
};
|
|
1533
1535
|
},
|
|
1534
1536
|
createCell: (cell, column, row, instance) => {
|
|
1537
|
+
const getRenderValue = () => {
|
|
1538
|
+
var _cell$getValue;
|
|
1539
|
+
|
|
1540
|
+
return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1535
1543
|
return {
|
|
1536
1544
|
getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
1537
1545
|
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
@@ -1541,15 +1549,19 @@ const Grouping = {
|
|
|
1541
1549
|
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
|
|
1542
1550
|
},
|
|
1543
1551
|
renderAggregatedCell: () => {
|
|
1544
|
-
|
|
1552
|
+
if (process.env.NODE_ENV === 'development') {
|
|
1553
|
+
if (!column.columnDef.aggregatedCell) {
|
|
1554
|
+
console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1545
1557
|
|
|
1546
|
-
const template =
|
|
1558
|
+
const template = column.columnDef.aggregatedCell || column.columnDef.cell;
|
|
1547
1559
|
return template ? instance._render(template, {
|
|
1548
1560
|
instance,
|
|
1549
1561
|
column,
|
|
1550
1562
|
row,
|
|
1551
1563
|
cell,
|
|
1552
|
-
getValue:
|
|
1564
|
+
getValue: getRenderValue
|
|
1553
1565
|
}) : null;
|
|
1554
1566
|
}
|
|
1555
1567
|
};
|
|
@@ -2019,11 +2031,11 @@ const RowSelection = {
|
|
|
2019
2031
|
});
|
|
2020
2032
|
},
|
|
2021
2033
|
toggleAllPageRowsSelected: value => instance.setRowSelection(old => {
|
|
2022
|
-
typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
|
|
2034
|
+
const resolvedValue = typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
|
|
2023
2035
|
const rowSelection = { ...old
|
|
2024
2036
|
};
|
|
2025
2037
|
instance.getRowModel().rows.forEach(row => {
|
|
2026
|
-
mutateRowIsSelected(rowSelection, row.id,
|
|
2038
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, instance);
|
|
2027
2039
|
});
|
|
2028
2040
|
return rowSelection;
|
|
2029
2041
|
}),
|
|
@@ -2178,7 +2190,7 @@ const RowSelection = {
|
|
|
2178
2190
|
},
|
|
2179
2191
|
getIsSomePageRowsSelected: () => {
|
|
2180
2192
|
const paginationFlatRows = instance.getPaginationRowModel().flatRows;
|
|
2181
|
-
return instance.getIsAllPageRowsSelected() ? false :
|
|
2193
|
+
return instance.getIsAllPageRowsSelected() ? false : paginationFlatRows.some(d => d.getIsSelected() || d.getIsSomeSelected());
|
|
2182
2194
|
},
|
|
2183
2195
|
getToggleAllRowsSelectedHandler: () => {
|
|
2184
2196
|
return e => {
|
|
@@ -2532,8 +2544,10 @@ const Sorting = {
|
|
|
2532
2544
|
// })
|
|
2533
2545
|
// return
|
|
2534
2546
|
// }
|
|
2547
|
+
// this needs to be outside of instance.setSorting to be in sync with rerender
|
|
2548
|
+
const nextSortingOrder = column.getNextSortingOrder();
|
|
2535
2549
|
instance.setSorting(old => {
|
|
2536
|
-
var
|
|
2550
|
+
var _instance$options$ena, _instance$options$ena2;
|
|
2537
2551
|
|
|
2538
2552
|
// Find any existing sorting for this column
|
|
2539
2553
|
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
@@ -2558,30 +2572,29 @@ const Sorting = {
|
|
|
2558
2572
|
} else {
|
|
2559
2573
|
sortAction = 'replace';
|
|
2560
2574
|
}
|
|
2561
|
-
}
|
|
2575
|
+
} // Handle toggle states that will remove the sorting
|
|
2562
2576
|
|
|
2563
|
-
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
|
|
2564
2577
|
|
|
2565
2578
|
if (sortAction === 'toggle' && ( // Must be toggling
|
|
2566
2579
|
(_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
|
|
2567
2580
|
!hasDescDefined && ( // Must not be setting desc
|
|
2568
|
-
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) &&
|
|
2569
|
-
|
|
2570
|
-
|
|
2581
|
+
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
|
|
2582
|
+
!nextSortingOrder // Finally, detect if it should indeed be removed
|
|
2583
|
+
) {
|
|
2571
2584
|
sortAction = 'remove';
|
|
2572
2585
|
}
|
|
2573
2586
|
|
|
2574
2587
|
if (sortAction === 'replace') {
|
|
2575
2588
|
newSorting = [{
|
|
2576
2589
|
id: column.id,
|
|
2577
|
-
desc: hasDescDefined ? desc :
|
|
2590
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2578
2591
|
}];
|
|
2579
2592
|
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2580
2593
|
var _instance$options$max;
|
|
2581
2594
|
|
|
2582
2595
|
newSorting = [...old, {
|
|
2583
2596
|
id: column.id,
|
|
2584
|
-
desc: hasDescDefined ? desc :
|
|
2597
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2585
2598
|
}]; // Take latest n columns
|
|
2586
2599
|
|
|
2587
2600
|
newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
|
|
@@ -2590,7 +2603,7 @@ const Sorting = {
|
|
|
2590
2603
|
newSorting = old.map(d => {
|
|
2591
2604
|
if (d.id === column.id) {
|
|
2592
2605
|
return { ...d,
|
|
2593
|
-
desc: hasDescDefined ? desc :
|
|
2606
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2594
2607
|
};
|
|
2595
2608
|
}
|
|
2596
2609
|
|
|
@@ -2603,6 +2616,23 @@ const Sorting = {
|
|
|
2603
2616
|
return newSorting;
|
|
2604
2617
|
});
|
|
2605
2618
|
},
|
|
2619
|
+
getNextSortingOrder: () => {
|
|
2620
|
+
var _ref2, _column$columnDef$sor;
|
|
2621
|
+
|
|
2622
|
+
const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
|
|
2623
|
+
const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
|
|
2624
|
+
const isSorted = column.getIsSorted();
|
|
2625
|
+
|
|
2626
|
+
if (!isSorted) {
|
|
2627
|
+
return firstSortDirection;
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
if (isSorted === firstSortDirection) {
|
|
2631
|
+
return isSorted === 'desc' ? 'asc' : 'desc';
|
|
2632
|
+
} else {
|
|
2633
|
+
return false;
|
|
2634
|
+
}
|
|
2635
|
+
},
|
|
2606
2636
|
getCanSort: () => {
|
|
2607
2637
|
var _column$columnDef$ena, _instance$options$ena3;
|
|
2608
2638
|
|
|
@@ -2896,9 +2926,9 @@ function createTableInstance$1(options) {
|
|
|
2896
2926
|
header: props => props.header.column.id,
|
|
2897
2927
|
footer: props => props.header.column.id,
|
|
2898
2928
|
cell: props => {
|
|
2899
|
-
var _props$getValue$toStr, _props$getValue
|
|
2929
|
+
var _props$getValue$toStr, _props$getValue;
|
|
2900
2930
|
|
|
2901
|
-
return (_props$getValue$toStr = (_props$getValue
|
|
2931
|
+
return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
|
|
2902
2932
|
},
|
|
2903
2933
|
...instance._features.reduce((obj, feature) => {
|
|
2904
2934
|
return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
|
|
@@ -3052,6 +3082,12 @@ function createTable$1(_, __, options) {
|
|
|
3052
3082
|
}
|
|
3053
3083
|
|
|
3054
3084
|
function createCell(instance, row, column, columnId) {
|
|
3085
|
+
const getRenderValue = () => {
|
|
3086
|
+
var _cell$getValue;
|
|
3087
|
+
|
|
3088
|
+
return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
|
|
3089
|
+
};
|
|
3090
|
+
|
|
3055
3091
|
const cell = {
|
|
3056
3092
|
id: row.id + "_" + column.id,
|
|
3057
3093
|
row,
|
|
@@ -3063,7 +3099,7 @@ function createCell(instance, row, column, columnId) {
|
|
|
3063
3099
|
column,
|
|
3064
3100
|
row,
|
|
3065
3101
|
cell: cell,
|
|
3066
|
-
getValue:
|
|
3102
|
+
getValue: getRenderValue
|
|
3067
3103
|
}) : null;
|
|
3068
3104
|
}
|
|
3069
3105
|
};
|
|
@@ -3669,11 +3705,6 @@ function getGroupedRowModel() {
|
|
|
3669
3705
|
if (aggregateFn) {
|
|
3670
3706
|
row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
|
|
3671
3707
|
return row._groupingValuesCache[columnId];
|
|
3672
|
-
} else if (column.aggregationFn) {
|
|
3673
|
-
console.info({
|
|
3674
|
-
column
|
|
3675
|
-
});
|
|
3676
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "Table: Invalid column.aggregateType option for column listed above" : '');
|
|
3677
3708
|
}
|
|
3678
3709
|
}
|
|
3679
3710
|
});
|
|
@@ -3797,20 +3828,34 @@ function getPaginationRowModel(opts) {
|
|
|
3797
3828
|
const pageStart = pageSize * pageIndex;
|
|
3798
3829
|
const pageEnd = pageStart + pageSize;
|
|
3799
3830
|
rows = rows.slice(pageStart, pageEnd);
|
|
3831
|
+
let paginatedRowModel;
|
|
3800
3832
|
|
|
3801
3833
|
if (!instance.options.paginateExpandedRows) {
|
|
3802
|
-
|
|
3834
|
+
paginatedRowModel = expandRows({
|
|
3803
3835
|
rows,
|
|
3804
3836
|
flatRows,
|
|
3805
3837
|
rowsById
|
|
3806
3838
|
});
|
|
3839
|
+
} else {
|
|
3840
|
+
paginatedRowModel = {
|
|
3841
|
+
rows,
|
|
3842
|
+
flatRows,
|
|
3843
|
+
rowsById
|
|
3844
|
+
};
|
|
3807
3845
|
}
|
|
3808
3846
|
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3847
|
+
paginatedRowModel.flatRows = [];
|
|
3848
|
+
|
|
3849
|
+
const handleRow = row => {
|
|
3850
|
+
paginatedRowModel.flatRows.push(row);
|
|
3851
|
+
|
|
3852
|
+
if (row.subRows.length) {
|
|
3853
|
+
row.subRows.forEach(handleRow);
|
|
3854
|
+
}
|
|
3813
3855
|
};
|
|
3856
|
+
|
|
3857
|
+
paginatedRowModel.rows.forEach(handleRow);
|
|
3858
|
+
return paginatedRowModel;
|
|
3814
3859
|
}, {
|
|
3815
3860
|
key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
|
|
3816
3861
|
debug: () => {
|
|
@@ -3830,8 +3875,11 @@ function create_fragment$1(ctx) {
|
|
|
3830
3875
|
c() {
|
|
3831
3876
|
t = text$1(/*content*/ ctx[0]);
|
|
3832
3877
|
},
|
|
3878
|
+
l(nodes) {
|
|
3879
|
+
t = claim_text(nodes, /*content*/ ctx[0]);
|
|
3880
|
+
},
|
|
3833
3881
|
m(target, anchor) {
|
|
3834
|
-
|
|
3882
|
+
insert_hydration(target, t, anchor);
|
|
3835
3883
|
},
|
|
3836
3884
|
p(ctx, [dirty]) {
|
|
3837
3885
|
if (dirty & /*content*/ 1) set_data(t, /*content*/ ctx[0]);
|
|
@@ -3854,13 +3902,18 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
3854
3902
|
return [content];
|
|
3855
3903
|
}
|
|
3856
3904
|
|
|
3857
|
-
class Placeholder extends SvelteComponent {
|
|
3905
|
+
class Placeholder$1 extends SvelteComponent {
|
|
3858
3906
|
constructor(options) {
|
|
3859
3907
|
super();
|
|
3860
3908
|
init(this, options, instance, create_fragment$1, safe_not_equal, { content: 0 });
|
|
3861
3909
|
}
|
|
3862
3910
|
}
|
|
3863
3911
|
|
|
3912
|
+
const PlaceholderServer = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
3913
|
+
return "" + escape($$props.content);
|
|
3914
|
+
});
|
|
3915
|
+
var Placeholder = typeof document === 'undefined' ? PlaceholderServer : Placeholder$1;
|
|
3916
|
+
|
|
3864
3917
|
function create_fragment(ctx, Comp, props) {
|
|
3865
3918
|
let c;
|
|
3866
3919
|
let current;
|
|
@@ -3873,6 +3926,10 @@ function create_fragment(ctx, Comp, props) {
|
|
|
3873
3926
|
create_component(c.$$.fragment);
|
|
3874
3927
|
},
|
|
3875
3928
|
|
|
3929
|
+
l(nodes) {
|
|
3930
|
+
claim_component(c.$$.fragment, nodes);
|
|
3931
|
+
},
|
|
3932
|
+
|
|
3876
3933
|
m(target, anchor) {
|
|
3877
3934
|
// @ts-ignore
|
|
3878
3935
|
mount_component(c, target, anchor);
|
|
@@ -3911,7 +3968,7 @@ function renderClient(Comp, props) {
|
|
|
3911
3968
|
|
|
3912
3969
|
function renderServer(Comp, props) {
|
|
3913
3970
|
const WrapperComp = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
3914
|
-
return "" + validate_component(Comp, '
|
|
3971
|
+
return "" + validate_component(Comp, 'TableComponent').$$render($$result, props, {}, {});
|
|
3915
3972
|
});
|
|
3916
3973
|
return WrapperComp;
|
|
3917
3974
|
}
|
|
@@ -3923,7 +3980,10 @@ function isSvelteServerComponent(component) {
|
|
|
3923
3980
|
}
|
|
3924
3981
|
|
|
3925
3982
|
function isSvelteClientComponent(component) {
|
|
3926
|
-
|
|
3983
|
+
var _component$name, _component$name2;
|
|
3984
|
+
|
|
3985
|
+
let isHMR = ('__SVELTE_HMR' in window);
|
|
3986
|
+
return component.prototype instanceof SvelteComponent || isHMR && ((_component$name = component.name) == null ? void 0 : _component$name.startsWith('Proxy<')) && ((_component$name2 = component.name) == null ? void 0 : _component$name2.endsWith('>'));
|
|
3927
3987
|
}
|
|
3928
3988
|
|
|
3929
3989
|
function isSvelteComponent(component) {
|
|
@@ -3977,6 +4037,7 @@ function createTableInstance(table, options) {
|
|
|
3977
4037
|
onStateChange: () => {},
|
|
3978
4038
|
// noop
|
|
3979
4039
|
render,
|
|
4040
|
+
renderFallbackValue: null,
|
|
3980
4041
|
...get(optionsStore)
|
|
3981
4042
|
};
|
|
3982
4043
|
let instance = createTableInstance$1(resolvedOptions);
|