@solidjs/router 0.14.9 → 0.14.10
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.
- package/dist/data/action.d.ts +7 -7
- package/dist/data/action.js +3 -1
- package/dist/index.js +16 -4
- package/dist/routing.d.ts +2 -2
- package/dist/types.d.ts +4 -2
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +19 -3
- package/package.json +1 -1
package/dist/data/action.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { JSX } from "solid-js";
|
|
2
2
|
import type { Submission, SubmissionStub, NarrowResponse } from "../types.js";
|
|
3
|
-
export type Action<T extends Array<any>, U> = (T extends [FormData] | [] ? JSX.SerializableAttributeValue : unknown) & ((...vars: T) => Promise<NarrowResponse<U>>) & {
|
|
3
|
+
export type Action<T extends Array<any>, U, V = T> = (T extends [FormData] | [] ? JSX.SerializableAttributeValue : unknown) & ((...vars: T) => Promise<NarrowResponse<U>>) & {
|
|
4
4
|
url: string;
|
|
5
|
-
with<A extends any[], B extends any[]>(this: (this: any, ...args: [...A, ...B]) => Promise<NarrowResponse<U>>, ...args: A): Action<B, U>;
|
|
5
|
+
with<A extends any[], B extends any[]>(this: (this: any, ...args: [...A, ...B]) => Promise<NarrowResponse<U>>, ...args: A): Action<B, U, V>;
|
|
6
6
|
};
|
|
7
|
-
export declare const actions: Map<string, Action<any, any>>;
|
|
8
|
-
export declare function useSubmissions<T extends Array<any>, U>(fn: Action<T, U>, filter?: (
|
|
7
|
+
export declare const actions: Map<string, Action<any, any, any>>;
|
|
8
|
+
export declare function useSubmissions<T extends Array<any>, U, V>(fn: Action<T, U, V>, filter?: (input: V) => boolean): Submission<T, NarrowResponse<U>>[] & {
|
|
9
9
|
pending: boolean;
|
|
10
10
|
};
|
|
11
|
-
export declare function useSubmission<T extends Array<any>, U>(fn: Action<T, U>, filter?: (
|
|
12
|
-
export declare function useAction<T extends Array<any>, U>(action: Action<T, U>): (...args: Parameters<Action<T, U>>) => Promise<NarrowResponse<U>>;
|
|
13
|
-
export declare function action<T extends Array<any>, U = void>(fn: (...args: T) => Promise<U>, name?: string): Action<T, U>;
|
|
11
|
+
export declare function useSubmission<T extends Array<any>, U, V>(fn: Action<T, U, V>, filter?: (input: V) => boolean): Submission<T, NarrowResponse<U>> | SubmissionStub;
|
|
12
|
+
export declare function useAction<T extends Array<any>, U, V>(action: Action<T, U, V>): (...args: Parameters<Action<T, U, V>>) => Promise<NarrowResponse<U>>;
|
|
13
|
+
export declare function action<T extends Array<any>, U = void>(fn: (...args: T) => Promise<U>, name?: string): Action<T, U, T>;
|
package/dist/data/action.js
CHANGED
|
@@ -6,7 +6,7 @@ import { cacheKeyOp, hashKey, revalidate, cache } from "./cache.js";
|
|
|
6
6
|
export const actions = /* #__PURE__ */ new Map();
|
|
7
7
|
export function useSubmissions(fn, filter) {
|
|
8
8
|
const router = useRouter();
|
|
9
|
-
const subs = createMemo(() => router.submissions[0]().filter(s => s.url === fn.
|
|
9
|
+
const subs = createMemo(() => router.submissions[0]().filter(s => s.url === fn.base && (!filter || filter(s.input))));
|
|
10
10
|
return new Proxy([], {
|
|
11
11
|
get(_, property) {
|
|
12
12
|
if (property === $TRACK)
|
|
@@ -83,6 +83,7 @@ export function action(fn, name) {
|
|
|
83
83
|
const url = fn.url ||
|
|
84
84
|
(name && `https://action/${name}`) ||
|
|
85
85
|
(!isServer ? `https://action/${hashString(fn.toString())}` : "");
|
|
86
|
+
mutate.base = url;
|
|
86
87
|
return toAction(mutate, url);
|
|
87
88
|
}
|
|
88
89
|
function toAction(fn, url) {
|
|
@@ -95,6 +96,7 @@ function toAction(fn, url) {
|
|
|
95
96
|
const newFn = function (...passedArgs) {
|
|
96
97
|
return fn.call(this, ...args, ...passedArgs);
|
|
97
98
|
};
|
|
99
|
+
newFn.base = fn.base;
|
|
98
100
|
const uri = new URL(url, mockBase);
|
|
99
101
|
uri.searchParams.set("args", hashKey(args));
|
|
100
102
|
return toAction(newFn, (uri.origin === "https://action" ? uri.origin : "") + uri.pathname + uri.search);
|
package/dist/index.js
CHANGED
|
@@ -111,7 +111,9 @@ function joinPaths(from, to) {
|
|
|
111
111
|
function extractSearchParams(url) {
|
|
112
112
|
const params = {};
|
|
113
113
|
url.searchParams.forEach((value, key) => {
|
|
114
|
-
|
|
114
|
+
if (key in params) {
|
|
115
|
+
if (Array.isArray(params[key])) params[key].push(value);else params[key] = [params[key], value];
|
|
116
|
+
} else params[key] = value;
|
|
115
117
|
});
|
|
116
118
|
return params;
|
|
117
119
|
}
|
|
@@ -197,10 +199,18 @@ function createMemoObject(fn) {
|
|
|
197
199
|
function mergeSearchString(search, params) {
|
|
198
200
|
const merged = new URLSearchParams(search);
|
|
199
201
|
Object.entries(params).forEach(([key, value]) => {
|
|
200
|
-
if (value == null || value === "") {
|
|
202
|
+
if (value == null || value === "" || value instanceof Array && !value.length) {
|
|
201
203
|
merged.delete(key);
|
|
202
204
|
} else {
|
|
203
|
-
|
|
205
|
+
if (value instanceof Array) {
|
|
206
|
+
// Delete all instances of the key before appending
|
|
207
|
+
merged.delete(key);
|
|
208
|
+
value.forEach(v => {
|
|
209
|
+
merged.append(key, String(v));
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
merged.set(key, String(value));
|
|
213
|
+
}
|
|
204
214
|
}
|
|
205
215
|
});
|
|
206
216
|
const s = merged.toString();
|
|
@@ -1056,7 +1066,7 @@ function isPlainObject(obj) {
|
|
|
1056
1066
|
const actions = /* #__PURE__ */new Map();
|
|
1057
1067
|
function useSubmissions(fn, filter) {
|
|
1058
1068
|
const router = useRouter();
|
|
1059
|
-
const subs = createMemo(() => router.submissions[0]().filter(s => s.url === fn.
|
|
1069
|
+
const subs = createMemo(() => router.submissions[0]().filter(s => s.url === fn.base && (!filter || filter(s.input))));
|
|
1060
1070
|
return new Proxy([], {
|
|
1061
1071
|
get(_, property) {
|
|
1062
1072
|
if (property === $TRACK) return subs();
|
|
@@ -1127,6 +1137,7 @@ function action(fn, name) {
|
|
|
1127
1137
|
return p.then(handler(), handler(true));
|
|
1128
1138
|
}
|
|
1129
1139
|
const url = fn.url || name && `https://action/${name}` || (!isServer ? `https://action/${hashString(fn.toString())}` : "");
|
|
1140
|
+
mutate.base = url;
|
|
1130
1141
|
return toAction(mutate, url);
|
|
1131
1142
|
}
|
|
1132
1143
|
function toAction(fn, url) {
|
|
@@ -1138,6 +1149,7 @@ function toAction(fn, url) {
|
|
|
1138
1149
|
const newFn = function (...passedArgs) {
|
|
1139
1150
|
return fn.call(this, ...args, ...passedArgs);
|
|
1140
1151
|
};
|
|
1152
|
+
newFn.base = fn.base;
|
|
1141
1153
|
const uri = new URL(url, mockBase);
|
|
1142
1154
|
uri.searchParams.set("args", hashKey(args));
|
|
1143
1155
|
return toAction(newFn, (uri.origin === "https://action" ? uri.origin : "") + uri.pathname + uri.search);
|
package/dist/routing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX, Accessor } from "solid-js";
|
|
2
|
-
import type { BeforeLeaveEventArgs, Branch, Intent, Location, MatchFilters, NavigateOptions, Navigator, Params, RouteDescription, RouteContext, RouteDefinition, RouteMatch, RouterContext, RouterIntegration,
|
|
2
|
+
import type { BeforeLeaveEventArgs, Branch, Intent, Location, MatchFilters, NavigateOptions, Navigator, Params, RouteDescription, RouteContext, RouteDefinition, RouteMatch, RouterContext, RouterIntegration, SearchParams, SetSearchParams } from "./types.js";
|
|
3
3
|
export declare const RouterContextObj: import("solid-js").Context<RouterContext | undefined>;
|
|
4
4
|
export declare const RouteContextObj: import("solid-js").Context<RouteContext | undefined>;
|
|
5
5
|
export declare const useRouter: () => RouterContext;
|
|
@@ -15,7 +15,7 @@ export declare const usePreloadRoute: () => (url: string | URL, options?: {
|
|
|
15
15
|
export declare const useMatch: <S extends string>(path: () => S, matchFilters?: MatchFilters<S> | undefined) => Accessor<import("./types.js").PathMatch | undefined>;
|
|
16
16
|
export declare const useCurrentMatches: () => () => RouteMatch[];
|
|
17
17
|
export declare const useParams: <T extends Params>() => T;
|
|
18
|
-
export declare const useSearchParams: <T extends
|
|
18
|
+
export declare const useSearchParams: <T extends SearchParams>() => [Partial<T>, (params: SetSearchParams, options?: Partial<NavigateOptions>) => void];
|
|
19
19
|
export declare const useBeforeLeave: (listener: (e: BeforeLeaveEventArgs) => void) => void;
|
|
20
20
|
export declare function createRoutes(routeDef: RouteDefinition, base?: string): RouteDescription[];
|
|
21
21
|
export declare function createBranch(routes: RouteDescription[], index?: number): Branch;
|
package/dist/types.d.ts
CHANGED
|
@@ -22,14 +22,16 @@ declare module "solid-js/web" {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export type Params = Record<string, string>;
|
|
25
|
+
export type SearchParams = Record<string, string | string[]>;
|
|
25
26
|
export type SetParams = Record<string, string | number | boolean | null | undefined>;
|
|
27
|
+
export type SetSearchParams = Record<string, string | string[] | number | number[] | boolean | boolean[] | null | undefined>;
|
|
26
28
|
export interface Path {
|
|
27
29
|
pathname: string;
|
|
28
30
|
search: string;
|
|
29
31
|
hash: string;
|
|
30
32
|
}
|
|
31
33
|
export interface Location<S = unknown> extends Path {
|
|
32
|
-
query:
|
|
34
|
+
query: SearchParams;
|
|
33
35
|
state: Readonly<Partial<S>> | null;
|
|
34
36
|
key: string;
|
|
35
37
|
}
|
|
@@ -127,7 +129,7 @@ export interface RouterUtils {
|
|
|
127
129
|
go(delta: number): void;
|
|
128
130
|
beforeLeave: BeforeLeaveLifecycle;
|
|
129
131
|
paramsWrapper: (getParams: () => Params, branches: () => Branch[]) => Params;
|
|
130
|
-
queryWrapper: (getQuery: () =>
|
|
132
|
+
queryWrapper: (getQuery: () => SearchParams) => SearchParams;
|
|
131
133
|
}
|
|
132
134
|
export interface RouterContext {
|
|
133
135
|
base: RouteContext;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { MatchFilters,
|
|
1
|
+
import type { MatchFilters, PathMatch, RouteDescription, SearchParams, SetSearchParams } from "./types.ts";
|
|
2
2
|
export declare const mockBase = "http://sr";
|
|
3
3
|
export declare function normalizePath(path: string, omitSlash?: boolean): string;
|
|
4
4
|
export declare function resolvePath(base: string, path: string, from?: string): string | undefined;
|
|
5
5
|
export declare function invariant<T>(value: T | null | undefined, message: string): T;
|
|
6
6
|
export declare function joinPaths(from: string, to: string): string;
|
|
7
|
-
export declare function extractSearchParams(url: URL):
|
|
7
|
+
export declare function extractSearchParams(url: URL): SearchParams;
|
|
8
8
|
export declare function createMatcher<S extends string>(path: S, partial?: boolean, matchFilters?: MatchFilters<S>): (location: string) => PathMatch | null;
|
|
9
9
|
export declare function scoreRoute(route: RouteDescription): number;
|
|
10
10
|
export declare function createMemoObject<T extends Record<string | symbol, unknown>>(fn: () => T): T;
|
|
11
|
-
export declare function mergeSearchString(search: string, params:
|
|
11
|
+
export declare function mergeSearchString(search: string, params: SetSearchParams): string;
|
|
12
12
|
export declare function expandOptionals(pattern: string): string[];
|
package/dist/utils.js
CHANGED
|
@@ -36,7 +36,14 @@ export function joinPaths(from, to) {
|
|
|
36
36
|
export function extractSearchParams(url) {
|
|
37
37
|
const params = {};
|
|
38
38
|
url.searchParams.forEach((value, key) => {
|
|
39
|
-
|
|
39
|
+
if (key in params) {
|
|
40
|
+
if (Array.isArray(params[key]))
|
|
41
|
+
params[key].push(value);
|
|
42
|
+
else
|
|
43
|
+
params[key] = [params[key], value];
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
params[key] = value;
|
|
40
47
|
});
|
|
41
48
|
return params;
|
|
42
49
|
}
|
|
@@ -128,11 +135,20 @@ export function createMemoObject(fn) {
|
|
|
128
135
|
export function mergeSearchString(search, params) {
|
|
129
136
|
const merged = new URLSearchParams(search);
|
|
130
137
|
Object.entries(params).forEach(([key, value]) => {
|
|
131
|
-
if (value == null || value === "") {
|
|
138
|
+
if (value == null || value === "" || (value instanceof Array && !value.length)) {
|
|
132
139
|
merged.delete(key);
|
|
133
140
|
}
|
|
134
141
|
else {
|
|
135
|
-
|
|
142
|
+
if (value instanceof Array) {
|
|
143
|
+
// Delete all instances of the key before appending
|
|
144
|
+
merged.delete(key);
|
|
145
|
+
value.forEach(v => {
|
|
146
|
+
merged.append(key, String(v));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
merged.set(key, String(value));
|
|
151
|
+
}
|
|
136
152
|
}
|
|
137
153
|
});
|
|
138
154
|
const s = merged.toString();
|