@azure-net/kit 6.0.0-next.4 → 6.0.0-next.6
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.
|
@@ -19,5 +19,5 @@ export interface QueryController<T extends Record<string, unknown>> {
|
|
|
19
19
|
getInitial: () => T;
|
|
20
20
|
createEffect: (callback: EffectCallback, dependencies?: readonly QueryPath<T>[]) => void;
|
|
21
21
|
}
|
|
22
|
-
export declare const createQuery: <T extends Record<string, unknown>>(initialValue: T, options?: CreateQueryOptions<T>) => QueryController<T>;
|
|
22
|
+
export declare const createQuery: <T extends Record<string, unknown>>(initialValue: T | (() => T), options?: CreateQueryOptions<T>) => QueryController<T>;
|
|
23
23
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { goto } from '$app/navigation';
|
|
2
2
|
import { page } from '$app/state';
|
|
3
|
+
import { untrack } from 'svelte';
|
|
3
4
|
import { createEffect } from '../effect/Effect.svelte.js';
|
|
4
5
|
import { cloneStateValue } from '../shared/cloneStateValue.js';
|
|
5
6
|
import { fromSearchParams, toSearchParams } from './SearchParamsSync.js';
|
|
@@ -53,14 +54,15 @@ const createDeepDependency = (read) => {
|
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
56
|
export const createQuery = (initialValue, options) => {
|
|
56
|
-
|
|
57
|
+
// Capture defaults once; reset restores this snapshot rather than rerunning the initializer.
|
|
58
|
+
const baseInitial = untrack(() => cloneStateValue(typeof initialValue === 'function' ? initialValue() : initialValue));
|
|
57
59
|
const searchParamsSync = options?.syncWithSearchParams;
|
|
58
60
|
const syncSettings = typeof searchParamsSync === 'object' ? searchParamsSync : undefined;
|
|
59
61
|
const syncEnabled = Boolean(searchParamsSync);
|
|
60
62
|
const parseSearchParams = syncSettings?.fromSearchParams ?? (fromSearchParams);
|
|
61
63
|
const serializeSearchParams = syncSettings?.toSearchParams ?? (toSearchParams);
|
|
62
64
|
const parsedInitial = syncEnabled
|
|
63
|
-
? parseSearchParams(new URLSearchParams(page.url.searchParams.toString()), cloneStateValue(baseInitial))
|
|
65
|
+
? parseSearchParams(new URLSearchParams((page.shallow?.url ?? page.url).searchParams.toString()), cloneStateValue(baseInitial))
|
|
64
66
|
: undefined;
|
|
65
67
|
let data = $state(parsedInitial ? { ...cloneStateValue(baseInitial), ...cloneStateValue(parsedInitial) } : cloneStateValue(baseInitial));
|
|
66
68
|
const reset = () => {
|
|
@@ -94,13 +96,17 @@ export const createQuery = (initialValue, options) => {
|
|
|
94
96
|
if (nextParams.toString() === initialParams.toString())
|
|
95
97
|
return;
|
|
96
98
|
}
|
|
97
|
-
const
|
|
99
|
+
const currentUrl = page.shallow?.url ?? page.url;
|
|
100
|
+
const url = new URL(currentUrl.href);
|
|
98
101
|
for (const key of managedKeys)
|
|
99
102
|
url.searchParams.delete(key);
|
|
100
103
|
for (const [key, value] of nextParams)
|
|
101
104
|
url.searchParams.append(key, value);
|
|
102
|
-
if (url.search !==
|
|
103
|
-
|
|
105
|
+
if (url.search !== currentUrl.search) {
|
|
106
|
+
void goto(url, { state: page.state, shallow: true, replace: true, reset: false }).catch((error) => {
|
|
107
|
+
console.error('[createQuery] Failed to synchronize search parameters', error);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
104
110
|
}, [createDeepDependency(() => data)]);
|
|
105
111
|
}
|
|
106
112
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-net/kit",
|
|
3
|
-
"version": "6.0.0-next.
|
|
3
|
+
"version": "6.0.0-next.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Pixel1917",
|
|
6
6
|
"description": "Universal toolkit and library collection, developed as part of the Azure-net ecosystem",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"utils"
|
|
113
113
|
],
|
|
114
114
|
"dependencies": {
|
|
115
|
-
"@azure-net/tools": "^2.
|
|
115
|
+
"@azure-net/tools": "^2.1.0"
|
|
116
116
|
},
|
|
117
117
|
"imports": {
|
|
118
118
|
"#lib": "./src/lib/index.ts",
|