compote-ui 0.42.0 → 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,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,6 +18,13 @@ 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();
21
+ const initialColumnVisibility = {
22
+ ...createColumnVisibility(options.columns),
23
+ ...options.initialState?.columnVisibility
24
+ };
25
+ const columnVisibilityAtom = options.onColumnVisibilityChange
26
+ ? createAtom(initialColumnVisibility)
27
+ : undefined;
20
28
  const table = createTanStackTable({
21
29
  _features: dataTableFeatures,
22
30
  _rowModels: {
@@ -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,13 +67,16 @@ export function createTable(options) {
61
67
  sorting: state.sorting,
62
68
  columnFilters: state.columnFilters
63
69
  }));
64
- if (options.onColumnVisibilityChange) {
70
+ if (columnVisibilityAtom && options.onColumnVisibilityChange) {
65
71
  const { onColumnVisibilityChange } = options;
66
- const orig = table.setColumnVisibility.bind(table);
67
- table.setColumnVisibility = (updater) => {
68
- orig(updater);
69
- onColumnVisibilityChange(table.store.state.columnVisibility);
70
- };
72
+ let initialized = false;
73
+ columnVisibilityAtom.subscribe((value) => {
74
+ if (!initialized) {
75
+ initialized = true;
76
+ return;
77
+ }
78
+ onColumnVisibilityChange(value);
79
+ });
71
80
  }
72
81
  return table;
73
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.42.0",
3
+ "version": "0.42.1",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev --open",