@kayord/ui 4.0.2 → 4.0.3
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,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";
|
|
@@ -43,22 +43,35 @@ export function useTableUrlSync(table, options) {
|
|
|
43
43
|
table.setPageIndex(decodePageIndex());
|
|
44
44
|
if (enabled.columnFilters)
|
|
45
45
|
table.setColumnFilters(decodeColumnFilters() ?? []);
|
|
46
|
-
// When navigating with new sort/search/filter params, snap back to the first
|
|
47
|
-
// unless the target URL explicitly points at a later page.
|
|
46
|
+
// When navigating with new sort/search/filter params, snap back to the first
|
|
47
|
+
// page unless the target URL explicitly points at a later page. Only same-route
|
|
48
|
+
// query changes count: resetting on a cross-route navigation would mutate state
|
|
49
|
+
// mid-navigation, and the write-back effect below would then issue a competing
|
|
50
|
+
// `goto("?…")` that cancels the in-flight navigation (links off the table page
|
|
51
|
+
// would "do nothing" whenever the table isn't already on page 1).
|
|
52
|
+
let leavePage = false;
|
|
48
53
|
beforeNavigate((navigation) => {
|
|
54
|
+
const from = navigation.from?.url;
|
|
55
|
+
const to = navigation.to?.url;
|
|
56
|
+
if (!from || !to)
|
|
57
|
+
return;
|
|
58
|
+
if (from.pathname !== to.pathname) {
|
|
59
|
+
leavePage = true;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
49
62
|
if (!enabled.pagination)
|
|
50
63
|
return;
|
|
51
|
-
const targetPage = Number(
|
|
52
|
-
const queryChanged = (enabled.sorting &&
|
|
53
|
-
|
|
54
|
-
(enabled.
|
|
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"));
|
|
64
|
+
const targetPage = Number(to.searchParams.get("page") ?? "0");
|
|
65
|
+
const queryChanged = (enabled.sorting && from.searchParams.get("sort") != to.searchParams.get("sort")) ||
|
|
66
|
+
(enabled.globalFilter && from.searchParams.get("search") != to.searchParams.get("search")) ||
|
|
67
|
+
(enabled.columnFilters && from.searchParams.get("filter") != to.searchParams.get("filter"));
|
|
58
68
|
if (queryChanged && (!Number.isFinite(targetPage) || targetPage <= 0)) {
|
|
59
69
|
table.resetPageIndex();
|
|
60
70
|
}
|
|
61
71
|
});
|
|
72
|
+
afterNavigate(() => {
|
|
73
|
+
leavePage = false;
|
|
74
|
+
});
|
|
62
75
|
// Write atoms back to the URL. Only the enabled atoms are read (and thus
|
|
63
76
|
// tracked) so the effect doesn't re-run on unrelated state (e.g. row
|
|
64
77
|
// selection), and disabled params are left untouched in the URL.
|
|
@@ -68,6 +81,10 @@ export function useTableUrlSync(table, options) {
|
|
|
68
81
|
const sorting = enabled.sorting ? table.atoms.sorting.get() : undefined;
|
|
69
82
|
const columnFilters = enabled.columnFilters ? table.atoms.columnFilters.get() : undefined;
|
|
70
83
|
untrack(() => {
|
|
84
|
+
// Skip writes while leaving the route: state mutating mid-navigation
|
|
85
|
+
// (e.g. a debounced filter landing) must not `goto` over the target URL.
|
|
86
|
+
if (leavePage)
|
|
87
|
+
return;
|
|
71
88
|
if (enabled.globalFilter)
|
|
72
89
|
params.search = search;
|
|
73
90
|
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.
|
|
4
|
+
"version": "4.0.3",
|
|
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.
|
|
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.
|
|
121
|
+
"@lucide/svelte": "^1.37.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.
|
|
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.
|
|
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.
|
|
149
|
-
"svelte": "^5.
|
|
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",
|