compote-ui 0.41.3 → 0.42.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ColumnResizeMode, type Row, type RowData, type SvelteTable, type TableState } from '@tanstack/svelte-table';
|
|
1
|
+
import { type ColumnResizeMode, type ColumnVisibilityState, type Row, type RowData, type SvelteTable, type TableState } from '@tanstack/svelte-table';
|
|
2
2
|
import type { DataTableColumn, DataTableLeafColumn } from './types';
|
|
3
3
|
declare const dataTableFeatures: {
|
|
4
4
|
columnVisibilityFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnVisibilityFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
@@ -24,6 +24,7 @@ export type CreateDataTableOptions<T extends RowData> = {
|
|
|
24
24
|
enableMultiRowSelection?: boolean | ((row: Row<DataTableFeatures, T>) => boolean);
|
|
25
25
|
enableSorting?: boolean;
|
|
26
26
|
debugTable?: boolean;
|
|
27
|
+
onColumnVisibilityChange?: (visibility: ColumnVisibilityState) => void;
|
|
27
28
|
};
|
|
28
29
|
export declare function createTable<T extends RowData>(options: CreateDataTableOptions<T>): SvelteTable<{
|
|
29
30
|
columnVisibilityFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnVisibilityFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { columnVisibilityFeature, columnResizingFeature, columnSizingFeature, columnFilteringFeature, columnFacetingFeature, columnPinningFeature, columnOrderingFeature, createSortedRowModel, createFilteredRowModel, createFacetedRowModel, createFacetedMinMaxValues, createFacetedUniqueValues, createTable as createTanStackTable, filterFns, renderComponent, renderSnippet, rowSelectionFeature, rowSortingFeature, sortFns, tableFeatures } from '@tanstack/svelte-table';
|
|
2
|
+
import { createAtom } from '@tanstack/svelte-store';
|
|
2
3
|
import { useLocaleContext } from '@ark-ui/svelte/locale';
|
|
3
4
|
const dataTableFeatures = tableFeatures({
|
|
4
5
|
columnVisibilityFeature,
|
|
@@ -17,7 +18,14 @@ function oneOfFilterFn(row, columnId, filterValue) {
|
|
|
17
18
|
oneOfFilterFn.autoRemove = (val) => !Array.isArray(val) || val.length === 0;
|
|
18
19
|
export function createTable(options) {
|
|
19
20
|
const localeCtx = useLocaleContext();
|
|
20
|
-
|
|
21
|
+
const initialColumnVisibility = {
|
|
22
|
+
...createColumnVisibility(options.columns),
|
|
23
|
+
...options.initialState?.columnVisibility
|
|
24
|
+
};
|
|
25
|
+
const columnVisibilityAtom = options.onColumnVisibilityChange
|
|
26
|
+
? createAtom(initialColumnVisibility)
|
|
27
|
+
: undefined;
|
|
28
|
+
const table = createTanStackTable({
|
|
21
29
|
_features: dataTableFeatures,
|
|
22
30
|
_rowModels: {
|
|
23
31
|
sortedRowModel: createSortedRowModel(sortFns),
|
|
@@ -38,12 +46,10 @@ export function createTable(options) {
|
|
|
38
46
|
get columns() {
|
|
39
47
|
return createColumns(options.columns, localeCtx);
|
|
40
48
|
},
|
|
49
|
+
...(columnVisibilityAtom ? { atoms: { columnVisibility: columnVisibilityAtom } } : {}),
|
|
41
50
|
initialState: {
|
|
42
51
|
...options.initialState,
|
|
43
|
-
columnVisibility:
|
|
44
|
-
...createColumnVisibility(options.columns),
|
|
45
|
-
...options.initialState?.columnVisibility
|
|
46
|
-
},
|
|
52
|
+
columnVisibility: initialColumnVisibility,
|
|
47
53
|
columnSizing: {
|
|
48
54
|
...createColumnSizing(options.columns),
|
|
49
55
|
...options.initialState?.columnSizing
|
|
@@ -61,6 +67,18 @@ export function createTable(options) {
|
|
|
61
67
|
sorting: state.sorting,
|
|
62
68
|
columnFilters: state.columnFilters
|
|
63
69
|
}));
|
|
70
|
+
if (columnVisibilityAtom && options.onColumnVisibilityChange) {
|
|
71
|
+
const { onColumnVisibilityChange } = options;
|
|
72
|
+
let initialized = false;
|
|
73
|
+
columnVisibilityAtom.subscribe((value) => {
|
|
74
|
+
if (!initialized) {
|
|
75
|
+
initialized = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
onColumnVisibilityChange(value);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return table;
|
|
64
82
|
}
|
|
65
83
|
function createColumnVisibility(columns) {
|
|
66
84
|
return getLeafColumns(columns).reduce((visibility, column) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compote-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev --open",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
12
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
13
13
|
"lint": "prettier --check . && eslint .",
|
|
14
|
-
"format": "prettier --write ."
|
|
14
|
+
"format": "prettier --write .",
|
|
15
|
+
"patch": "npm version patch && npm publish",
|
|
16
|
+
"minor": "npm version minor && npm publish"
|
|
15
17
|
},
|
|
16
18
|
"files": [
|
|
17
19
|
"dist",
|