@kayord/ui 4.0.2 → 4.0.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.
@@ -12,7 +12,7 @@
12
12
  canChangePageSize?: boolean;
13
13
  }
14
14
 
15
- let { table, canChangePageSize = true }: Props<T> = $props();
15
+ let { table, canChangePageSize = false }: Props<T> = $props();
16
16
 
17
17
  const pagination = $derived(table.atoms.pagination.get());
18
18
  </script>
@@ -24,11 +24,12 @@
24
24
  {table.getFilteredSelectedRowModel().rows.length} of
25
25
  {table.getFilteredRowModel().rows.length} row(s) selected.
26
26
  </p>
27
+ {:else}
28
+ <p>
29
+ {table.getRowModel().rows.length.toLocaleString()}
30
+ of {table.getRowCount().toLocaleString()} rows
31
+ </p>
27
32
  {/if}
28
- <p>
29
- {table.getRowModel().rows.length.toLocaleString()}
30
- of {table.getRowCount().toLocaleString()} rows
31
- </p>
32
33
  </div>
33
34
  <div class="flex items-center gap-6 lg:gap-8">
34
35
  {#if canChangePageSize}
@@ -9,7 +9,7 @@ export declare const decodeSorting: () => {
9
9
  export declare const encodeGlobalFilter: (state: State) => any;
10
10
  export declare const decodeGlobalFilter: () => string | undefined;
11
11
  export declare const encodePageIndex: (state: State) => string;
12
- export declare const decodePageIndex: () => number;
12
+ export declare const decodePageIndex: () => number | undefined;
13
13
  export declare const encodeColumnFilters: (state: State) => string;
14
14
  export declare const decodeColumnFilters: () => {
15
15
  id: string;
@@ -28,8 +28,11 @@ export const encodePageIndex = (state) => {
28
28
  return state.pagination?.pageIndex?.toString() ?? "";
29
29
  };
30
30
  export const decodePageIndex = () => {
31
- const pageIndex = Number(page.url.searchParams.get("page") ?? "0");
32
- return Number.isFinite(pageIndex) ? pageIndex : 0;
31
+ const raw = page.url.searchParams.get("page");
32
+ if (raw == null)
33
+ return undefined;
34
+ const pageIndex = Number(raw);
35
+ return Number.isFinite(pageIndex) ? pageIndex : undefined;
33
36
  };
34
37
  export const encodeColumnFilters = (state) => {
35
38
  return (state.columnFilters
@@ -59,15 +62,16 @@ export const decodeColumnFilters = () => {
59
62
  });
60
63
  };
61
64
  export const decodeTableState = () => {
62
- return {
63
- pagination: {
64
- pageIndex: decodePageIndex(),
65
- pageSize: 10,
66
- },
65
+ const pageIndex = decodePageIndex();
66
+ const state = {
67
67
  sorting: decodeSorting(),
68
68
  columnFilters: decodeColumnFilters(),
69
69
  globalFilter: decodeGlobalFilter(),
70
70
  };
71
+ if (pageIndex !== undefined) {
72
+ state.pagination = { pageIndex, pageSize: 10 };
73
+ }
74
+ return state;
71
75
  };
72
76
  export const encodeTableState = (state, options, searchParams) => {
73
77
  if (searchParams === undefined) {
@@ -34,7 +34,9 @@ export interface TableUrlSyncOptions {
34
34
  *
35
35
  * The table is hydrated from the URL immediately, before the first render, so
36
36
  * row-model auto-resets (which are skipped on their first run) can't clobber
37
- * the URL-backed state.
37
+ * the URL-backed state. URL params override `initialState`; params missing
38
+ * from the URL leave `initialState` in place, and the initial state is then
39
+ * written back to the URL like any other state.
38
40
  *
39
41
  * By default all four params are synced; pass {@link TableUrlSyncOptions} to
40
42
  * enable only a subset, e.g. `useTableUrlSync(table, { pagination: true })`.
@@ -1,5 +1,5 @@
1
1
  import { untrack } from "svelte";
2
- import { beforeNavigate } from "$app/navigation";
2
+ import { afterNavigate, beforeNavigate } from "$app/navigation";
3
3
  import { useSearchParams } from "runed/kit";
4
4
  import { defaultSearchParamSchema } from "./types";
5
5
  import { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, encodeColumnFilters, encodeSorting, } from "./table-search-params";
@@ -17,7 +17,9 @@ import { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting
17
17
  *
18
18
  * The table is hydrated from the URL immediately, before the first render, so
19
19
  * row-model auto-resets (which are skipped on their first run) can't clobber
20
- * the URL-backed state.
20
+ * the URL-backed state. URL params override `initialState`; params missing
21
+ * from the URL leave `initialState` in place, and the initial state is then
22
+ * written back to the URL like any other state.
21
23
  *
22
24
  * By default all four params are synced; pass {@link TableUrlSyncOptions} to
23
25
  * enable only a subset, e.g. `useTableUrlSync(table, { pagination: true })`.
@@ -31,34 +33,61 @@ export function useTableUrlSync(table, options) {
31
33
  ...options,
32
34
  };
33
35
  const params = useSearchParams(defaultSearchParamSchema, { pushHistory: false });
34
- // Hydrate from the URL before the first render. Sorting/filter/data changes
35
- // defer an autoResetPageIndex microtask via the adapter's schedule; row
36
- // models skip auto-resets on their first run, so applying the URL state
37
- // up-front can't be undone by them (a post-mount hydration would be).
38
- if (enabled.globalFilter)
39
- table.setGlobalFilter(decodeGlobalFilter() ?? "");
40
- if (enabled.sorting)
41
- table.setSorting(decodeSorting() ?? []);
42
- if (enabled.pagination)
43
- table.setPageIndex(decodePageIndex());
44
- if (enabled.columnFilters)
45
- table.setColumnFilters(decodeColumnFilters() ?? []);
46
- // When navigating with new sort/search/filter params, snap back to the first page
47
- // unless the target URL explicitly points at a later page.
36
+ // Hydrate from the URL before the first render, but only for params the URL
37
+ // actually carries absent params leave the table's `initialState` in place
38
+ // (the write-back effect below then publishes it to the URL). Sorting/filter/
39
+ // data changes defer an autoResetPageIndex microtask via the adapter's
40
+ // schedule; row models skip auto-resets on their first run, so applying the
41
+ // URL state up-front can't be undone by them (a post-mount hydration would be).
42
+ if (enabled.globalFilter) {
43
+ const globalFilter = decodeGlobalFilter();
44
+ if (globalFilter !== undefined)
45
+ table.setGlobalFilter(globalFilter);
46
+ }
47
+ if (enabled.sorting) {
48
+ const sorting = decodeSorting();
49
+ if (sorting !== undefined)
50
+ table.setSorting(sorting);
51
+ }
52
+ if (enabled.pagination) {
53
+ const pageIndex = decodePageIndex();
54
+ if (pageIndex !== undefined)
55
+ table.setPageIndex(pageIndex);
56
+ }
57
+ if (enabled.columnFilters) {
58
+ const columnFilters = decodeColumnFilters();
59
+ if (columnFilters !== undefined)
60
+ table.setColumnFilters(columnFilters);
61
+ }
62
+ // When navigating with new sort/search/filter params, snap back to the first
63
+ // page unless the target URL explicitly points at a later page. Only same-route
64
+ // query changes count: resetting on a cross-route navigation would mutate state
65
+ // mid-navigation, and the write-back effect below would then issue a competing
66
+ // `goto("?…")` that cancels the in-flight navigation (links off the table page
67
+ // would "do nothing" whenever the table isn't already on page 1).
68
+ let leavePage = false;
48
69
  beforeNavigate((navigation) => {
70
+ const from = navigation.from?.url;
71
+ const to = navigation.to?.url;
72
+ if (!from || !to)
73
+ return;
74
+ if (from.pathname !== to.pathname) {
75
+ leavePage = true;
76
+ return;
77
+ }
49
78
  if (!enabled.pagination)
50
79
  return;
51
- const targetPage = Number(navigation.to?.url.searchParams.get("page") ?? "0");
52
- const queryChanged = (enabled.sorting &&
53
- navigation.from?.url.searchParams.get("sort") != navigation.to?.url.searchParams.get("sort")) ||
54
- (enabled.globalFilter &&
55
- navigation.from?.url.searchParams.get("search") != navigation.to?.url.searchParams.get("search")) ||
56
- (enabled.columnFilters &&
57
- navigation.from?.url.searchParams.get("filter") != navigation.to?.url.searchParams.get("filter"));
80
+ const targetPage = Number(to.searchParams.get("page") ?? "0");
81
+ const queryChanged = (enabled.sorting && from.searchParams.get("sort") != to.searchParams.get("sort")) ||
82
+ (enabled.globalFilter && from.searchParams.get("search") != to.searchParams.get("search")) ||
83
+ (enabled.columnFilters && from.searchParams.get("filter") != to.searchParams.get("filter"));
58
84
  if (queryChanged && (!Number.isFinite(targetPage) || targetPage <= 0)) {
59
85
  table.resetPageIndex();
60
86
  }
61
87
  });
88
+ afterNavigate(() => {
89
+ leavePage = false;
90
+ });
62
91
  // Write atoms back to the URL. Only the enabled atoms are read (and thus
63
92
  // tracked) so the effect doesn't re-run on unrelated state (e.g. row
64
93
  // selection), and disabled params are left untouched in the URL.
@@ -68,6 +97,10 @@ export function useTableUrlSync(table, options) {
68
97
  const sorting = enabled.sorting ? table.atoms.sorting.get() : undefined;
69
98
  const columnFilters = enabled.columnFilters ? table.atoms.columnFilters.get() : undefined;
70
99
  untrack(() => {
100
+ // Skip writes while leaving the route: state mutating mid-navigation
101
+ // (e.g. a debounced filter landing) must not `goto` over the target URL.
102
+ if (leavePage)
103
+ return;
71
104
  if (enabled.globalFilter)
72
105
  params.search = search;
73
106
  if (enabled.pagination && page !== undefined)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "4.0.2",
4
+ "version": "4.0.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/kayordDX/ui.git"
@@ -112,19 +112,19 @@
112
112
  "runed": "^0.37.1",
113
113
  "tailwind-merge": "^3.6.0",
114
114
  "tailwind-variants": "^3.3.1",
115
- "zod": "4.4.3"
115
+ "zod": "4.5.2"
116
116
  },
117
117
  "devDependencies": {
118
118
  "@eslint/compat": "^2.1.0",
119
119
  "@eslint/js": "^10.0.1",
120
120
  "@internationalized/date": "^3.12.3",
121
- "@lucide/svelte": "^1.34.0",
121
+ "@lucide/svelte": "^1.38.0",
122
122
  "@sveltejs/adapter-auto": "^7.0.1",
123
123
  "@sveltejs/kit": "^2.70.3",
124
124
  "@sveltejs/package": "^2.5.8",
125
125
  "@sveltejs/vite-plugin-svelte": "7.3.0",
126
126
  "@tailwindcss/vite": "^4.3.3",
127
- "@tanstack/svelte-table": "^9.1.2",
127
+ "@tanstack/svelte-table": "^9.2.4",
128
128
  "@types/d3-scale": "^4.0.9",
129
129
  "@types/d3-shape": "^3.2.0",
130
130
  "@vitest/browser": "^4.1.11",
@@ -137,7 +137,7 @@
137
137
  "eslint-plugin-svelte": "^3.23.0",
138
138
  "formsnap": "^2.0.1",
139
139
  "globals": "^17.11.0",
140
- "layerchart": "^2.3.0",
140
+ "layerchart": "^2.3.1",
141
141
  "mode-watcher": "^1.1.0",
142
142
  "paneforge": "^1.0.2",
143
143
  "playwright": "^1.62.1",
@@ -145,8 +145,8 @@
145
145
  "prettier-plugin-svelte": "4.1.1",
146
146
  "prettier-plugin-tailwindcss": "^0.8.1",
147
147
  "publint": "^0.3.24",
148
- "shadcn-svelte": "^1.5.0",
149
- "svelte": "^5.56.10",
148
+ "shadcn-svelte": "^1.5.1",
149
+ "svelte": "^5.57.0",
150
150
  "svelte-check": "^4.7.6",
151
151
  "svelte-sonner": "^1.2.1",
152
152
  "sveltekit-superforms": "^2.30.2",
@@ -154,7 +154,7 @@
154
154
  "tslib": "^2.8.1",
155
155
  "tw-animate-css": "1.4.0",
156
156
  "typescript": "^6.0.3",
157
- "typescript-eslint": "^8.68.0",
157
+ "typescript-eslint": "^8.69.0",
158
158
  "vaul-svelte": "1.0.0-next.7",
159
159
  "vite": "^8.2.2",
160
160
  "vitest": "^4.1.11",