@kayord/ui 0.14.8 → 0.14.9

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,6 +1,4 @@
1
- import { createSvelteTable } from "../../ui";
2
1
  import { createTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, } from "@tanstack/table-core";
3
- import { State } from "./state.svelte";
4
2
  export const createShadTable = (options) => {
5
3
  // Set the default getCoreRowModel
6
4
  if (!options.getCoreRowModel) {
@@ -16,7 +14,7 @@ export const createShadTable = (options) => {
16
14
  },
17
15
  }, plainOptions);
18
16
  const table = createTable(resolvedOptions);
19
- const state = new State(options.state ?? {});
17
+ let state = $state(table.initialState);
20
18
  function updateOptions() {
21
19
  table.setOptions((prev) => {
22
20
  return mergeObjects(prev, options, {
@@ -24,9 +22,9 @@ export const createShadTable = (options) => {
24
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
23
  onStateChange: (updater) => {
26
24
  if (updater instanceof Function)
27
- state.value = updater(state);
25
+ state = updater(state);
28
26
  else
29
- state.value = mergeObjects(state, updater);
27
+ state = mergeObjects(state, updater);
30
28
  options.onStateChange?.(updater);
31
29
  },
32
30
  });
@@ -40,8 +38,8 @@ export const createShadTable = (options) => {
40
38
  if (options.state?.sorting) {
41
39
  options.state.sorting = updater(options.state.sorting);
42
40
  }
43
- else if (state.value.sorting) {
44
- state.value.sorting = updater(state.value.sorting);
41
+ else if (state.sorting) {
42
+ state.sorting = updater(state.sorting);
45
43
  }
46
44
  }
47
45
  else {
@@ -49,7 +47,7 @@ export const createShadTable = (options) => {
49
47
  options.state.sorting = updater;
50
48
  }
51
49
  else {
52
- state.value.sorting = updater;
50
+ state.sorting = updater;
53
51
  }
54
52
  }
55
53
  };
@@ -62,8 +60,8 @@ export const createShadTable = (options) => {
62
60
  if (options.state?.pagination) {
63
61
  options.state.pagination = updater(options.state.pagination);
64
62
  }
65
- else if (state.value.pagination) {
66
- state.value.pagination = updater(state.value.pagination);
63
+ else if (state.pagination) {
64
+ state.pagination = updater(state.pagination);
67
65
  }
68
66
  }
69
67
  else {
@@ -71,7 +69,7 @@ export const createShadTable = (options) => {
71
69
  options.state.pagination = updater;
72
70
  }
73
71
  else {
74
- state.value.pagination = updater;
72
+ state.pagination = updater;
75
73
  }
76
74
  }
77
75
  };
@@ -83,8 +81,8 @@ export const createShadTable = (options) => {
83
81
  if (options.state?.rowSelection) {
84
82
  options.state.rowSelection = updater(options.state.rowSelection);
85
83
  }
86
- else if (state.value.rowSelection) {
87
- state.value.rowSelection = updater(state.value.rowSelection);
84
+ else if (state.rowSelection) {
85
+ state.rowSelection = updater(state.rowSelection);
88
86
  }
89
87
  }
90
88
  else {
@@ -92,7 +90,7 @@ export const createShadTable = (options) => {
92
90
  options.state.rowSelection = updater;
93
91
  }
94
92
  else {
95
- state.value.rowSelection = updater;
93
+ state.rowSelection = updater;
96
94
  }
97
95
  }
98
96
  };
@@ -104,8 +102,8 @@ export const createShadTable = (options) => {
104
102
  if (options.state?.columnVisibility) {
105
103
  options.state.columnVisibility = updater(options.state.columnVisibility);
106
104
  }
107
- else if (state.value.columnVisibility) {
108
- state.value.columnVisibility = updater(state.value.columnVisibility);
105
+ else if (state.columnVisibility) {
106
+ state.columnVisibility = updater(state.columnVisibility);
109
107
  }
110
108
  }
111
109
  else {
@@ -113,18 +111,16 @@ export const createShadTable = (options) => {
113
111
  options.state.columnVisibility = updater;
114
112
  }
115
113
  else {
116
- state.value.columnVisibility = updater;
114
+ state.columnVisibility = updater;
117
115
  }
118
116
  }
119
117
  };
120
118
  }
121
- options.state = state.value;
122
119
  updateOptions();
123
120
  $effect.pre(() => {
124
121
  updateOptions();
125
122
  });
126
- const tableOptions = options;
127
- return createSvelteTable(tableOptions);
123
+ return table;
128
124
  };
129
125
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
126
  function mergeObjects(...sources) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "0.14.8",
4
+ "version": "0.14.9",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -64,7 +64,7 @@
64
64
  "prettier-plugin-svelte": "^3.3.3",
65
65
  "prettier-plugin-tailwindcss": "^0.6.11",
66
66
  "publint": "^0.3.8",
67
- "svelte": "^5.22.4",
67
+ "svelte": "^5.22.5",
68
68
  "svelte-check": "^4.1.4",
69
69
  "tailwindcss": "^4.0.10",
70
70
  "tslib": "^2.8.1",
@@ -1,5 +0,0 @@
1
- import type { TableState } from "@tanstack/table-core";
2
- export declare class State {
3
- value: Partial<TableState>;
4
- constructor(initState: Partial<TableState>);
5
- }
@@ -1,21 +0,0 @@
1
- export class State {
2
- value = $state({});
3
- constructor(initState) {
4
- if (!initState.sorting) {
5
- initState.sorting = [];
6
- }
7
- if (!initState.pagination) {
8
- initState.pagination = { pageIndex: 0, pageSize: 10 };
9
- }
10
- if (!initState.columnVisibility) {
11
- initState.columnVisibility = {};
12
- }
13
- if (!initState.rowSelection) {
14
- initState.rowSelection = {};
15
- }
16
- if (!initState.columnVisibility) {
17
- initState.columnVisibility = {};
18
- }
19
- this.value = initState;
20
- }
21
- }