@kayord/ui 0.16.5 → 0.17.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.
@@ -8,7 +8,7 @@
8
8
  import { ProgressLoading } from "../progress-loading";
9
9
  import FullscreenModeToggle from "./FullscreenModeToggle.svelte";
10
10
  import { cn } from "../../../utils";
11
- import { tableStore } from "./table.svelte";
11
+ import { TableStore } from "./table.svelte";
12
12
  import DataTableHeader from "./DataTableHeader.svelte";
13
13
  import VisibilitySelect from "./VisibilitySelect.svelte";
14
14
 
@@ -46,13 +46,17 @@
46
46
  disableUISorting = false,
47
47
  }: Props<T> = $props();
48
48
 
49
+ const tableStore = new TableStore();
49
50
  const isPaginationEnabled = table.options.getPaginationRowModel !== undefined;
51
+ let end: HTMLElement | undefined = $state();
50
52
  </script>
51
53
 
52
54
  <div
53
55
  class={cn(
54
56
  "w-full",
55
- tableStore.isFullscreen ? "bg-background absolute top-0 left-0 z-10 h-screen transition-all" : "w-full",
57
+ tableStore.isFullscreen
58
+ ? "bg-background b-0 absolute inset-0 top-0 left-0 z-20 overflow-auto p-2 transition-all"
59
+ : "w-full",
56
60
  className
57
61
  )}
58
62
  >
@@ -78,7 +82,7 @@
78
82
  {/if}
79
83
  {#if enableFullscreen}
80
84
  <div>
81
- <FullscreenModeToggle />
85
+ <FullscreenModeToggle bind:isFullscreen={tableStore.isFullscreen} {end} />
82
86
  </div>
83
87
  {/if}
84
88
  </div>
@@ -159,3 +163,5 @@
159
163
  </div>
160
164
  {/if}
161
165
  </div>
166
+
167
+ <div bind:this={end} aria-hidden="true"></div>
@@ -1,7 +1,27 @@
1
1
  <script lang="ts">
2
2
  import Button from "../../ui/button/button.svelte";
3
3
  import { Maximize, Minimize } from "@lucide/svelte";
4
- import { tableStore } from "./table.svelte";
4
+
5
+ interface Props {
6
+ isFullscreen: boolean;
7
+ end?: HTMLElement;
8
+ }
9
+
10
+ let { isFullscreen = $bindable(), end }: Props = $props();
11
+
12
+ $effect.pre(() => {
13
+ if (isFullscreen) {
14
+ document.body.classList.add("overflow-hidden");
15
+ document.body.scrollIntoView({ behavior: "smooth", block: "start" });
16
+ } else {
17
+ if (!end) {
18
+ document.body.classList.remove("overflow-hidden");
19
+ return;
20
+ }
21
+ end.scrollIntoView({ behavior: "smooth", block: "start" });
22
+ document.body.classList.remove("overflow-hidden");
23
+ }
24
+ });
5
25
  </script>
6
26
 
7
27
  <Button
@@ -9,15 +29,10 @@
9
29
  variant="outline"
10
30
  size="sm"
11
31
  onclick={() => {
12
- tableStore.isFullscreen = !tableStore.isFullscreen;
13
- // if ($target == "body") {
14
- // $target = "#tableContent";
15
- // } else {
16
- // $target = "body";
17
- // }
32
+ isFullscreen = !isFullscreen;
18
33
  }}
19
34
  >
20
- {#if tableStore.isFullscreen}
35
+ {#if isFullscreen}
21
36
  <Minimize class="size-5" />
22
37
  {:else}
23
38
  <Maximize class="size-5" />
@@ -1,18 +1,7 @@
1
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
1
+ interface Props {
2
+ isFullscreen: boolean;
3
+ end?: HTMLElement;
13
4
  }
14
- declare const FullscreenModeToggle: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
- [evt: string]: CustomEvent<any>;
16
- }, {}, {}, string>;
17
- type FullscreenModeToggle = InstanceType<typeof FullscreenModeToggle>;
5
+ declare const FullscreenModeToggle: import("svelte").Component<Props, {}, "isFullscreen">;
6
+ type FullscreenModeToggle = ReturnType<typeof FullscreenModeToggle>;
18
7
  export default FullscreenModeToggle;
@@ -5,7 +5,6 @@
5
5
  import DoubleArrowLeft from "@lucide/svelte/icons/arrow-left";
6
6
  import DoubleArrowRight from "@lucide/svelte/icons/arrow-right";
7
7
  import { Select, Button } from "../../..";
8
- import type { ShadTable } from "./shad-table.svelte";
9
8
 
10
9
  interface Props<T> {
11
10
  table: Table<T>;
@@ -1,2 +1,2 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
- export { ShadTable, createShadTable } from "./shad-table.svelte";
2
+ export { createShadTable } from "./shad-table.svelte";
@@ -1,2 +1,2 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
- export { ShadTable, createShadTable } from "./shad-table.svelte";
2
+ export { createShadTable } from "./shad-table.svelte";
@@ -1,4 +1,4 @@
1
- import { type ColumnDef, type RowData, type RowModel, type Table, type TableOptions, type TableState } from "@tanstack/table-core";
1
+ import { type RowData, type RowModel, type Table, type TableOptions, type TableState } from "@tanstack/table-core";
2
2
  interface ShadTableOptions<TData extends RowData> extends Omit<TableOptions<TData>, "getCoreRowModel"> {
3
3
  getCoreRowModel?: (table: Table<any>) => () => RowModel<any>;
4
4
  enablePaging?: boolean;
@@ -6,13 +6,4 @@ interface ShadTableOptions<TData extends RowData> extends Omit<TableOptions<TDat
6
6
  enableRowSelectionUI?: boolean;
7
7
  }
8
8
  export declare function createShadTable<TData extends RowData>(shadOptions: ShadTableOptions<TData>, stateUpdate?: (state: Partial<TableState>) => void): Table<TData>;
9
- export declare class ShadTable<TData extends RowData> {
10
- #private;
11
- columns: ColumnDef<TData>[];
12
- table: Table<TData>;
13
- options: ShadTableOptions<TData>;
14
- constructor(initOptions: ShadTableOptions<TData>, stateUpdate?: (state: Partial<TableState>) => void);
15
- updateOptions(): void;
16
- private features;
17
- }
18
9
  export {};
@@ -1,4 +1,4 @@
1
- import { createTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, } from "@tanstack/table-core";
1
+ import { createTable, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, } from "@tanstack/table-core";
2
2
  import DataTableCheckbox from "./DataTableCheckbox.svelte";
3
3
  import { renderComponent } from "../../ui";
4
4
  export function createShadTable(shadOptions, stateUpdate) {
@@ -13,46 +13,50 @@ export function createShadTable(shadOptions, stateUpdate) {
13
13
  // Sorting
14
14
  if ((options.enableSorting ?? true) && !options.getSortedRowModel) {
15
15
  options.getSortedRowModel = getSortedRowModel();
16
- options.onSortingChange = (updater) => {
17
- if (typeof updater === "function") {
18
- if (options.state?.sorting) {
19
- options.state.sorting = updater(options.state.sorting);
20
- }
21
- else if (state.sorting) {
22
- state.sorting = updater(state.sorting);
23
- }
24
- }
25
- else {
26
- if (options.state?.sorting) {
27
- options.state.sorting = updater;
16
+ if (!options.onSortingChange) {
17
+ options.onSortingChange = (updater) => {
18
+ if (typeof updater === "function") {
19
+ if (options.state?.sorting) {
20
+ options.state.sorting = updater(options.state.sorting);
21
+ }
22
+ else if (state.sorting) {
23
+ state.sorting = updater(state.sorting);
24
+ }
28
25
  }
29
26
  else {
30
- state.sorting = updater;
27
+ if (options.state?.sorting) {
28
+ options.state.sorting = updater;
29
+ }
30
+ else {
31
+ state.sorting = updater;
32
+ }
31
33
  }
32
- }
33
- };
34
+ };
35
+ }
34
36
  }
35
37
  // Paging
36
38
  if ((shadOptions.enablePaging ?? true) && !options.getPaginationRowModel) {
37
39
  options.getPaginationRowModel = getPaginationRowModel();
38
- options.onPaginationChange = (updater) => {
39
- if (typeof updater === "function") {
40
- if (options.state?.pagination) {
41
- options.state.pagination = updater(options.state.pagination);
42
- }
43
- else if (state.pagination) {
44
- state.pagination = updater(state.pagination);
45
- }
46
- }
47
- else {
48
- if (options.state?.pagination) {
49
- options.state.pagination = updater;
40
+ if (!options.onPaginationChange) {
41
+ options.onPaginationChange = (updater) => {
42
+ if (typeof updater === "function") {
43
+ if (options.state?.pagination) {
44
+ options.state.pagination = updater(options.state.pagination);
45
+ }
46
+ else if (state.pagination) {
47
+ state.pagination = updater(state.pagination);
48
+ }
50
49
  }
51
50
  else {
52
- state.pagination = updater;
51
+ if (options.state?.pagination) {
52
+ options.state.pagination = updater;
53
+ }
54
+ else {
55
+ state.pagination = updater;
56
+ }
53
57
  }
54
- }
55
- };
58
+ };
59
+ }
56
60
  }
57
61
  // Row Selection
58
62
  if ((options.enableRowSelection ?? true) && !options.onRowSelectionChange) {
@@ -112,6 +116,55 @@ export function createShadTable(shadOptions, stateUpdate) {
112
116
  }
113
117
  };
114
118
  }
119
+ // Filtering
120
+ if ((options.enableFilters ?? true) && !options.getFilteredRowModel) {
121
+ options.getFilteredRowModel = getFilteredRowModel();
122
+ // Global Filtering
123
+ if (options.enableGlobalFilter ?? false) {
124
+ if (!options.onGlobalFilterChange) {
125
+ options.onGlobalFilterChange = (updater) => {
126
+ if (typeof updater === "function") {
127
+ if (options.state?.globalFilter) {
128
+ options.state.globalFilter = updater(options.state.globalFilter);
129
+ }
130
+ else if (state.globalFilter) {
131
+ state.globalFilter = updater(state.globalFilter);
132
+ }
133
+ }
134
+ else {
135
+ if (options.state?.globalFilter) {
136
+ options.state.globalFilter = updater;
137
+ }
138
+ else {
139
+ state.globalFilter = updater;
140
+ }
141
+ }
142
+ };
143
+ }
144
+ }
145
+ else {
146
+ if (!options.onColumnFiltersChange) {
147
+ options.onColumnFiltersChange = (updater) => {
148
+ if (typeof updater === "function") {
149
+ if (options.state?.columnFilters) {
150
+ options.state.columnFilters = updater(options.state.columnFilters);
151
+ }
152
+ else if (state.columnFilters) {
153
+ state.columnFilters = updater(state.columnFilters);
154
+ }
155
+ }
156
+ else {
157
+ if (options.state?.columnFilters) {
158
+ options.state.columnFilters = updater;
159
+ }
160
+ else {
161
+ state.columnFilters = updater;
162
+ }
163
+ }
164
+ };
165
+ }
166
+ }
167
+ }
115
168
  const resolvedOptions = mergeObjects({
116
169
  state: {},
117
170
  onStateChange() { },
@@ -148,153 +201,6 @@ export function createShadTable(shadOptions, stateUpdate) {
148
201
  }
149
202
  return table;
150
203
  }
151
- export class ShadTable {
152
- columns;
153
- table;
154
- #state = $state({});
155
- #stateUpdate;
156
- options;
157
- constructor(initOptions, stateUpdate) {
158
- if (stateUpdate) {
159
- this.#stateUpdate = stateUpdate;
160
- }
161
- else {
162
- this.#stateUpdate = (state) => {
163
- this.#state = state;
164
- };
165
- }
166
- this.options = initOptions;
167
- if (!this.options.getCoreRowModel) {
168
- this.options.getCoreRowModel = getCoreRowModel();
169
- }
170
- if ((this.options.enablePaging ?? true) == false) {
171
- this.options.manualPagination = true;
172
- }
173
- const plainOptions = this.options;
174
- const resolvedOptions = mergeObjects({
175
- state: {},
176
- onStateChange() { },
177
- renderFallbackValue: null,
178
- mergeOptions: (defaultOptions, options) => {
179
- return mergeObjects(defaultOptions, options);
180
- },
181
- }, plainOptions);
182
- this.table = createTable(resolvedOptions);
183
- this.#state = this.table.initialState;
184
- this.columns = this.options.columns;
185
- this.features();
186
- this.updateOptions();
187
- $effect.pre(() => {
188
- this.updateOptions();
189
- });
190
- $effect(() => {
191
- this.#stateUpdate(this.#state);
192
- });
193
- }
194
- updateOptions() {
195
- this.table.setOptions((prev) => {
196
- return mergeObjects(prev, this.options, {
197
- state: mergeObjects(this.#state, this.options.state || {}),
198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
199
- onStateChange: (updater) => {
200
- if (updater instanceof Function)
201
- this.#state = updater(this.#state);
202
- else
203
- this.#state = mergeObjects(this.#state, updater);
204
- this.options.onStateChange?.(updater);
205
- },
206
- });
207
- });
208
- }
209
- features() {
210
- // Sorting
211
- if ((this.options.enableSorting ?? true) && !this.options.getSortedRowModel) {
212
- this.options.getSortedRowModel = getSortedRowModel();
213
- this.options.onSortingChange = (updater) => {
214
- if (typeof updater === "function") {
215
- if (this.options.state?.sorting) {
216
- this.options.state.sorting = updater(this.options.state.sorting);
217
- }
218
- else if (this.#state.sorting) {
219
- this.#state.sorting = updater(this.#state.sorting);
220
- }
221
- }
222
- else {
223
- if (this.options.state?.sorting) {
224
- this.options.state.sorting = updater;
225
- }
226
- else {
227
- this.#state.sorting = updater;
228
- }
229
- }
230
- };
231
- }
232
- // Paging
233
- if ((this.options.enablePaging ?? true) && !this.options.getPaginationRowModel) {
234
- this.options.getPaginationRowModel = getPaginationRowModel();
235
- this.options.onPaginationChange = (updater) => {
236
- if (typeof updater === "function") {
237
- if (this.options.state?.pagination) {
238
- this.options.state.pagination = updater(this.options.state.pagination);
239
- }
240
- else if (this.#state.pagination) {
241
- this.#state.pagination = updater(this.#state.pagination);
242
- }
243
- }
244
- else {
245
- if (this.options.state?.pagination) {
246
- this.options.state.pagination = updater;
247
- }
248
- else {
249
- this.#state.pagination = updater;
250
- }
251
- }
252
- };
253
- }
254
- // Row Selection
255
- if ((this.options.enableRowSelection ?? true) && !this.options.onRowSelectionChange) {
256
- this.options.onRowSelectionChange = (updater) => {
257
- if (typeof updater === "function") {
258
- if (this.options.state?.rowSelection) {
259
- this.options.state.rowSelection = updater(this.options.state.rowSelection);
260
- }
261
- else if (this.#state.rowSelection) {
262
- this.#state.rowSelection = updater(this.#state.rowSelection);
263
- }
264
- }
265
- else {
266
- if (this.options.state?.rowSelection) {
267
- this.options.state.rowSelection = updater;
268
- }
269
- else {
270
- this.#state.rowSelection = updater;
271
- }
272
- }
273
- };
274
- }
275
- // Column Visibility
276
- if ((this.options.enableVisibility ?? false) && !this.options.onColumnVisibilityChange) {
277
- this.options.onColumnVisibilityChange = (updater) => {
278
- if (typeof updater === "function") {
279
- if (this.options.state?.columnVisibility) {
280
- this.options.state.columnVisibility = updater(this.options.state.columnVisibility);
281
- }
282
- else if (this.#state.columnVisibility) {
283
- this.#state.columnVisibility = updater(this.#state.columnVisibility);
284
- }
285
- }
286
- else {
287
- if (this.options.state?.columnVisibility) {
288
- this.options.state.columnVisibility = updater;
289
- }
290
- else {
291
- this.#state.columnVisibility = updater;
292
- }
293
- }
294
- };
295
- }
296
- }
297
- }
298
204
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
299
205
  function mergeObjects(...sources) {
300
206
  const target = {};
@@ -1,5 +1,3 @@
1
- interface TableStoreProps {
1
+ export declare class TableStore {
2
2
  isFullscreen: boolean;
3
3
  }
4
- export declare let tableStore: TableStoreProps;
5
- export {};
@@ -1,3 +1,3 @@
1
- export let tableStore = $state({
2
- isFullscreen: false,
3
- });
1
+ export class TableStore {
2
+ isFullscreen = $state(false);
3
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "0.16.5",
4
+ "version": "0.17.1",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -34,19 +34,19 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@internationalized/date": "^3.7.0",
37
- "bits-ui": "1.3.14",
37
+ "bits-ui": "1.3.15",
38
38
  "clsx": "^2.1.1",
39
39
  "embla-carousel-svelte": "8.5.2",
40
40
  "formsnap": "2.0.0",
41
41
  "mode-watcher": "^0.5.1",
42
42
  "paneforge": "1.0.0-next.4",
43
43
  "svelte-sonner": "^0.3.28",
44
- "tailwind-merge": "^3.0.2",
44
+ "tailwind-merge": "^3.1.0",
45
45
  "tailwind-variants": "^1.0.0",
46
46
  "vaul-svelte": "1.0.0-next.7"
47
47
  },
48
48
  "devDependencies": {
49
- "@lucide/svelte": "^0.485.0",
49
+ "@lucide/svelte": "^0.486.0",
50
50
  "@sveltejs/adapter-auto": "^5.0.0",
51
51
  "@sveltejs/kit": "^2.20.2",
52
52
  "@sveltejs/package": "^2.3.10",
@@ -54,24 +54,24 @@
54
54
  "@tailwindcss/vite": "^4.0.17",
55
55
  "@testing-library/jest-dom": "^6.6.3",
56
56
  "@testing-library/svelte": "^5.2.7",
57
- "@typescript-eslint/eslint-plugin": "^8.28.0",
58
- "@typescript-eslint/parser": "^8.28.0",
57
+ "@typescript-eslint/eslint-plugin": "^8.29.0",
58
+ "@typescript-eslint/parser": "^8.29.0",
59
59
  "eslint": "^9.23.0",
60
60
  "eslint-config-prettier": "^10.1.1",
61
- "eslint-plugin-svelte": "^3.3.3",
61
+ "eslint-plugin-svelte": "^3.4.1",
62
62
  "happy-dom": "^17.4.4",
63
63
  "prettier": "^3.5.3",
64
64
  "prettier-plugin-svelte": "^3.3.3",
65
65
  "prettier-plugin-tailwindcss": "^0.6.11",
66
66
  "publint": "^0.3.9",
67
- "svelte": "^5.25.3",
67
+ "svelte": "^5.25.5",
68
68
  "svelte-check": "^4.1.5",
69
69
  "tailwindcss": "^4.0.17",
70
70
  "tslib": "^2.8.1",
71
71
  "tw-animate-css": "1.2.5",
72
72
  "typescript": "^5.8.2",
73
- "vite": "^6.2.3",
74
- "vitest": "^3.0.9",
73
+ "vite": "^6.2.4",
74
+ "vitest": "^3.1.1",
75
75
  "zod": "^3.24.2"
76
76
  },
77
77
  "svelte": "./dist/index.js",