@solidjs/router 1.0.0 → 2.0.0-next.12
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/README.md +606 -697
- package/dist/claims.d.ts +21 -0
- package/dist/claims.js +115 -0
- package/dist/data/action.d.ts +40 -11
- package/dist/data/action.js +303 -101
- package/dist/data/events.d.ts +8 -0
- package/dist/data/events.js +24 -23
- package/dist/data/index.d.ts +2 -4
- package/dist/data/index.js +2 -4
- package/dist/data/query.d.ts +1 -3
- package/dist/data/query.js +39 -22
- package/dist/data/serverForms.d.ts +1 -0
- package/dist/data/serverForms.js +5 -0
- package/dist/fs.d.ts +94 -0
- package/dist/fs.js +51 -0
- package/dist/index.d.ts +24 -3
- package/dist/index.js +1890 -1200
- package/dist/index.jsx +2 -2
- package/dist/lifecycle.d.ts +29 -4
- package/dist/lifecycle.js +40 -37
- package/dist/paths.d.ts +117 -0
- package/dist/paths.js +41 -0
- package/dist/routers/components.d.ts +12 -26
- package/dist/routers/components.jsx +68 -54
- package/dist/routers/factory.d.ts +121 -0
- package/dist/routers/factory.jsx +154 -0
- package/dist/routers/history.d.ts +26 -0
- package/dist/routers/history.js +180 -0
- package/dist/routers/index.d.ts +5 -11
- package/dist/routers/index.js +2 -6
- package/dist/routers/scrollRestoration.d.ts +10 -1
- package/dist/routers/scrollRestoration.js +49 -11
- package/dist/routing.d.ts +96 -52
- package/dist/routing.js +399 -167
- package/dist/server.d.ts +47 -0
- package/dist/server.js +156 -0
- package/dist/types.d.ts +148 -44
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +2 -0
- package/package.json +12 -7
- package/dist/components.d.ts +0 -31
- package/dist/components.jsx +0 -40
- package/dist/data/createAsync.d.ts +0 -32
- package/dist/data/createAsync.js +0 -96
- package/dist/data/response.d.ts +0 -4
- package/dist/data/response.js +0 -42
- package/dist/routers/HashRouter.d.ts +0 -9
- package/dist/routers/HashRouter.js +0 -41
- package/dist/routers/MemoryRouter.d.ts +0 -24
- package/dist/routers/MemoryRouter.js +0 -57
- package/dist/routers/Router.d.ts +0 -17
- package/dist/routers/Router.js +0 -59
- package/dist/routers/StaticRouter.d.ts +0 -6
- package/dist/routers/StaticRouter.js +0 -15
- package/dist/routers/createRouter.d.ts +0 -10
- package/dist/routers/createRouter.js +0 -41
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { type ReconcileOptions } from "solid-js/store";
|
|
2
|
-
/**
|
|
3
|
-
* As `createAsync` and `createAsyncStore` are wrappers for `createResource`,
|
|
4
|
-
* this type allows to support `latest` field for these primitives.
|
|
5
|
-
* It will be removed in the future.
|
|
6
|
-
*/
|
|
7
|
-
export type AccessorWithLatest<T> = {
|
|
8
|
-
(): T;
|
|
9
|
-
latest: T;
|
|
10
|
-
};
|
|
11
|
-
export declare function createAsync<T>(fn: (prev: T) => Promise<T>, options: {
|
|
12
|
-
name?: string;
|
|
13
|
-
initialValue: T;
|
|
14
|
-
deferStream?: boolean;
|
|
15
|
-
}): AccessorWithLatest<T>;
|
|
16
|
-
export declare function createAsync<T>(fn: (prev: T | undefined) => Promise<T>, options?: {
|
|
17
|
-
name?: string;
|
|
18
|
-
initialValue?: T;
|
|
19
|
-
deferStream?: boolean;
|
|
20
|
-
}): AccessorWithLatest<T | undefined>;
|
|
21
|
-
export declare function createAsyncStore<T>(fn: (prev: T) => Promise<T>, options: {
|
|
22
|
-
name?: string;
|
|
23
|
-
initialValue: T;
|
|
24
|
-
deferStream?: boolean;
|
|
25
|
-
reconcile?: ReconcileOptions;
|
|
26
|
-
}): AccessorWithLatest<T>;
|
|
27
|
-
export declare function createAsyncStore<T>(fn: (prev: T | undefined) => Promise<T>, options?: {
|
|
28
|
-
name?: string;
|
|
29
|
-
initialValue?: T;
|
|
30
|
-
deferStream?: boolean;
|
|
31
|
-
reconcile?: ReconcileOptions;
|
|
32
|
-
}): AccessorWithLatest<T | undefined>;
|
package/dist/data/createAsync.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is mock of the eventual Solid 2.0 primitive. It is not fully featured.
|
|
3
|
-
*/
|
|
4
|
-
import { createResource, sharedConfig, untrack, catchError } from "solid-js";
|
|
5
|
-
import { createStore, reconcile, unwrap } from "solid-js/store";
|
|
6
|
-
import { isServer } from "solid-js/web";
|
|
7
|
-
import { setFunctionName } from "../utils.js";
|
|
8
|
-
export function createAsync(fn, options) {
|
|
9
|
-
let resource;
|
|
10
|
-
let prev = () => !resource || resource.state === "unresolved" ? undefined : resource.latest;
|
|
11
|
-
[resource] = createResource(() => subFetch(fn, catchError(() => untrack(prev), () => undefined)), v => v, options);
|
|
12
|
-
const resultAccessor = (() => resource());
|
|
13
|
-
if (options?.name)
|
|
14
|
-
setFunctionName(resultAccessor, options.name);
|
|
15
|
-
Object.defineProperty(resultAccessor, "latest", {
|
|
16
|
-
get() {
|
|
17
|
-
return resource.latest;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return resultAccessor;
|
|
21
|
-
}
|
|
22
|
-
export function createAsyncStore(fn, options = {}) {
|
|
23
|
-
let resource;
|
|
24
|
-
let prev = () => !resource || resource.state === "unresolved"
|
|
25
|
-
? undefined
|
|
26
|
-
: unwrap(resource.latest);
|
|
27
|
-
[resource] = createResource(() => subFetch(fn, catchError(() => untrack(prev), () => undefined)), v => v, {
|
|
28
|
-
...options,
|
|
29
|
-
storage: (init) => createDeepSignal(init, options.reconcile)
|
|
30
|
-
});
|
|
31
|
-
const resultAccessor = (() => resource());
|
|
32
|
-
Object.defineProperty(resultAccessor, "latest", {
|
|
33
|
-
get() {
|
|
34
|
-
return resource.latest;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return resultAccessor;
|
|
38
|
-
}
|
|
39
|
-
function createDeepSignal(value, options) {
|
|
40
|
-
const [store, setStore] = createStore({
|
|
41
|
-
value: structuredClone(value)
|
|
42
|
-
});
|
|
43
|
-
return [
|
|
44
|
-
() => store.value,
|
|
45
|
-
(v) => {
|
|
46
|
-
typeof v === "function" && (v = v());
|
|
47
|
-
setStore("value", reconcile(structuredClone(v), options));
|
|
48
|
-
return store.value;
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
// mock promise while hydrating to prevent fetching
|
|
53
|
-
class MockPromise {
|
|
54
|
-
static all() {
|
|
55
|
-
return new MockPromise();
|
|
56
|
-
}
|
|
57
|
-
static allSettled() {
|
|
58
|
-
return new MockPromise();
|
|
59
|
-
}
|
|
60
|
-
static any() {
|
|
61
|
-
return new MockPromise();
|
|
62
|
-
}
|
|
63
|
-
static race() {
|
|
64
|
-
return new MockPromise();
|
|
65
|
-
}
|
|
66
|
-
static reject() {
|
|
67
|
-
return new MockPromise();
|
|
68
|
-
}
|
|
69
|
-
static resolve() {
|
|
70
|
-
return new MockPromise();
|
|
71
|
-
}
|
|
72
|
-
catch() {
|
|
73
|
-
return new MockPromise();
|
|
74
|
-
}
|
|
75
|
-
then() {
|
|
76
|
-
return new MockPromise();
|
|
77
|
-
}
|
|
78
|
-
finally() {
|
|
79
|
-
return new MockPromise();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function subFetch(fn, prev) {
|
|
83
|
-
if (isServer || !sharedConfig.context)
|
|
84
|
-
return fn(prev);
|
|
85
|
-
const ogFetch = fetch;
|
|
86
|
-
const ogPromise = Promise;
|
|
87
|
-
try {
|
|
88
|
-
window.fetch = () => new MockPromise();
|
|
89
|
-
Promise = MockPromise;
|
|
90
|
-
return fn(prev);
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
window.fetch = ogFetch;
|
|
94
|
-
Promise = ogPromise;
|
|
95
|
-
}
|
|
96
|
-
}
|
package/dist/data/response.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RouterResponseInit, CustomResponse } from "../types.js";
|
|
2
|
-
export declare function redirect(url: string, init?: number | RouterResponseInit): CustomResponse<never>;
|
|
3
|
-
export declare function reload(init?: RouterResponseInit): CustomResponse<never>;
|
|
4
|
-
export declare function json<T>(data: T, init?: RouterResponseInit): CustomResponse<T>;
|
package/dist/data/response.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export function redirect(url, init = 302) {
|
|
2
|
-
let responseInit;
|
|
3
|
-
let revalidate;
|
|
4
|
-
if (typeof init === "number") {
|
|
5
|
-
responseInit = { status: init };
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
({ revalidate, ...responseInit } = init);
|
|
9
|
-
if (typeof responseInit.status === "undefined") {
|
|
10
|
-
responseInit.status = 302;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const headers = new Headers(responseInit.headers);
|
|
14
|
-
headers.set("Location", url);
|
|
15
|
-
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
16
|
-
const response = new Response(null, {
|
|
17
|
-
...responseInit,
|
|
18
|
-
headers: headers
|
|
19
|
-
});
|
|
20
|
-
return response;
|
|
21
|
-
}
|
|
22
|
-
export function reload(init = {}) {
|
|
23
|
-
const { revalidate, ...responseInit } = init;
|
|
24
|
-
const headers = new Headers(responseInit.headers);
|
|
25
|
-
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
26
|
-
return new Response(null, {
|
|
27
|
-
...responseInit,
|
|
28
|
-
headers
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export function json(data, init = {}) {
|
|
32
|
-
const { revalidate, ...responseInit } = init;
|
|
33
|
-
const headers = new Headers(responseInit.headers);
|
|
34
|
-
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
35
|
-
headers.set("Content-Type", "application/json");
|
|
36
|
-
const response = new Response(JSON.stringify(data), {
|
|
37
|
-
...responseInit,
|
|
38
|
-
headers
|
|
39
|
-
});
|
|
40
|
-
response.customBody = () => data;
|
|
41
|
-
return response;
|
|
42
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JSX } from "solid-js";
|
|
2
|
-
import type { BaseRouterProps } from "./components.jsx";
|
|
3
|
-
export declare function hashParser(str: string): string;
|
|
4
|
-
export type HashRouterProps = BaseRouterProps & {
|
|
5
|
-
actionBase?: string;
|
|
6
|
-
explicitLinks?: boolean;
|
|
7
|
-
preload?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare function HashRouter(props: HashRouterProps): JSX.Element;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { setupNativeEvents } from "../data/events.js";
|
|
2
|
-
import { createRouter, scrollToHash, bindEvent } from "./createRouter.js";
|
|
3
|
-
import { createBeforeLeave, keepDepth, notifyIfNotBlocked, saveCurrentDepth } from "../lifecycle.js";
|
|
4
|
-
export function hashParser(str) {
|
|
5
|
-
const to = str.replace(/^.*?#/, "");
|
|
6
|
-
// Hash-only hrefs like `#foo` from plain anchors will come in as `/#foo` whereas a link to
|
|
7
|
-
// `/foo` will be `/#/foo`. Check if the to starts with a `/` and if not append it as a hash
|
|
8
|
-
// to the current path so we can handle these in-page anchors correctly.
|
|
9
|
-
if (!to.startsWith("/")) {
|
|
10
|
-
const [, path = "/"] = window.location.hash.split("#", 2);
|
|
11
|
-
return `${path}#${to}`;
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
}
|
|
15
|
-
export function HashRouter(props) {
|
|
16
|
-
const getSource = () => window.location.hash.slice(1);
|
|
17
|
-
const beforeLeave = createBeforeLeave();
|
|
18
|
-
return createRouter({
|
|
19
|
-
get: getSource,
|
|
20
|
-
set({ value, replace, scroll, state }) {
|
|
21
|
-
if (replace) {
|
|
22
|
-
window.history.replaceState(keepDepth(state), "", "#" + value);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
window.history.pushState(state, "", "#" + value);
|
|
26
|
-
}
|
|
27
|
-
const hashIndex = value.indexOf("#");
|
|
28
|
-
const hash = hashIndex >= 0 ? value.slice(hashIndex + 1) : "";
|
|
29
|
-
scrollToHash(hash, scroll);
|
|
30
|
-
saveCurrentDepth();
|
|
31
|
-
},
|
|
32
|
-
init: notify => bindEvent(window, "hashchange", notifyIfNotBlocked(notify, delta => !beforeLeave.confirm(delta && delta < 0 ? delta : getSource()))),
|
|
33
|
-
create: setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase }),
|
|
34
|
-
utils: {
|
|
35
|
-
go: delta => window.history.go(delta),
|
|
36
|
-
renderPath: path => `#${path}`,
|
|
37
|
-
parsePath: hashParser,
|
|
38
|
-
beforeLeave
|
|
39
|
-
}
|
|
40
|
-
})(props);
|
|
41
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { LocationChange } from "../types.js";
|
|
2
|
-
import type { BaseRouterProps } from "./components.jsx";
|
|
3
|
-
import type { JSX } from "solid-js";
|
|
4
|
-
export type MemoryHistory = {
|
|
5
|
-
get: () => string;
|
|
6
|
-
set: (change: LocationChange) => void;
|
|
7
|
-
go: (delta: number) => void;
|
|
8
|
-
listen: (listener: (value: string) => void) => () => void;
|
|
9
|
-
};
|
|
10
|
-
export declare function createMemoryHistory(): {
|
|
11
|
-
get: () => string;
|
|
12
|
-
set: ({ value, scroll, replace }: LocationChange) => void;
|
|
13
|
-
back: () => void;
|
|
14
|
-
forward: () => void;
|
|
15
|
-
go: (n: number) => void;
|
|
16
|
-
listen: (listener: (value: string) => void) => () => void;
|
|
17
|
-
};
|
|
18
|
-
export type MemoryRouterProps = BaseRouterProps & {
|
|
19
|
-
history?: MemoryHistory;
|
|
20
|
-
actionBase?: string;
|
|
21
|
-
explicitLinks?: boolean;
|
|
22
|
-
preload?: boolean;
|
|
23
|
-
};
|
|
24
|
-
export declare function MemoryRouter(props: MemoryRouterProps): JSX.Element;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createRouter, scrollToHash } from "./createRouter.js";
|
|
2
|
-
import { setupNativeEvents } from "../data/events.js";
|
|
3
|
-
export function createMemoryHistory() {
|
|
4
|
-
const entries = ["/"];
|
|
5
|
-
let index = 0;
|
|
6
|
-
const listeners = [];
|
|
7
|
-
const go = (n) => {
|
|
8
|
-
// https://github.com/remix-run/react-router/blob/682810ca929d0e3c64a76f8d6e465196b7a2ac58/packages/router/history.ts#L245
|
|
9
|
-
index = Math.max(0, Math.min(index + n, entries.length - 1));
|
|
10
|
-
const value = entries[index];
|
|
11
|
-
listeners.forEach(listener => listener(value));
|
|
12
|
-
};
|
|
13
|
-
return {
|
|
14
|
-
get: () => entries[index],
|
|
15
|
-
set: ({ value, scroll, replace }) => {
|
|
16
|
-
if (replace) {
|
|
17
|
-
entries[index] = value;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
entries.splice(index + 1, entries.length - index, value);
|
|
21
|
-
index++;
|
|
22
|
-
}
|
|
23
|
-
listeners.forEach(listener => listener(value));
|
|
24
|
-
setTimeout(() => {
|
|
25
|
-
if (scroll) {
|
|
26
|
-
scrollToHash(value.split("#")[1] || "", true);
|
|
27
|
-
}
|
|
28
|
-
}, 0);
|
|
29
|
-
},
|
|
30
|
-
back: () => {
|
|
31
|
-
go(-1);
|
|
32
|
-
},
|
|
33
|
-
forward: () => {
|
|
34
|
-
go(1);
|
|
35
|
-
},
|
|
36
|
-
go,
|
|
37
|
-
listen: (listener) => {
|
|
38
|
-
listeners.push(listener);
|
|
39
|
-
return () => {
|
|
40
|
-
const index = listeners.indexOf(listener);
|
|
41
|
-
listeners.splice(index, 1);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export function MemoryRouter(props) {
|
|
47
|
-
const memoryHistory = props.history || createMemoryHistory();
|
|
48
|
-
return createRouter({
|
|
49
|
-
get: memoryHistory.get,
|
|
50
|
-
set: memoryHistory.set,
|
|
51
|
-
init: memoryHistory.listen,
|
|
52
|
-
create: setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase }),
|
|
53
|
-
utils: {
|
|
54
|
-
go: memoryHistory.go
|
|
55
|
-
}
|
|
56
|
-
})(props);
|
|
57
|
-
}
|
package/dist/routers/Router.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { BaseRouterProps } from "./components.jsx";
|
|
2
|
-
import type { JSX } from "solid-js";
|
|
3
|
-
export type RouterProps = BaseRouterProps & {
|
|
4
|
-
url?: string;
|
|
5
|
-
actionBase?: string;
|
|
6
|
-
explicitLinks?: boolean;
|
|
7
|
-
preload?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Opt-in explicit scroll restoration for back/forward navigation (read
|
|
10
|
-
* once, not reactive). Sets `history.scrollRestoration = "manual"` and
|
|
11
|
-
* restores saved positions after the navigation settles, replacing the
|
|
12
|
-
* browser heuristic that loses offsets when the destination route forces
|
|
13
|
-
* a layout while rendering (#577).
|
|
14
|
-
*/
|
|
15
|
-
scrollRestoration?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export declare function Router(props: RouterProps): JSX.Element;
|
package/dist/routers/Router.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { isServer } from "solid-js/web";
|
|
2
|
-
import { createRouter, scrollToHash, bindEvent } from "./createRouter.js";
|
|
3
|
-
import { StaticRouter } from "./StaticRouter.js";
|
|
4
|
-
import { setupNativeEvents } from "../data/events.js";
|
|
5
|
-
import { createBeforeLeave, keepDepth, notifyIfNotBlocked, saveCurrentDepth } from "../lifecycle.js";
|
|
6
|
-
import { createScrollRestoration } from "./scrollRestoration.js";
|
|
7
|
-
export function Router(props) {
|
|
8
|
-
if (isServer)
|
|
9
|
-
return StaticRouter(props);
|
|
10
|
-
const restoration = props.scrollRestoration ? createScrollRestoration() : undefined;
|
|
11
|
-
const getSource = () => {
|
|
12
|
-
const url = window.location.pathname + window.location.search;
|
|
13
|
-
const state = window.history.state && window.history.state._depth && Object.keys(window.history.state).length === 1 ? undefined : window.history.state;
|
|
14
|
-
return {
|
|
15
|
-
value: url + window.location.hash,
|
|
16
|
-
state
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
const beforeLeave = createBeforeLeave();
|
|
20
|
-
return createRouter({
|
|
21
|
-
get: getSource,
|
|
22
|
-
set({ value, replace, scroll, state }) {
|
|
23
|
-
if (replace) {
|
|
24
|
-
window.history.replaceState(keepDepth(state), "", value);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
window.history.pushState(state, "", value);
|
|
28
|
-
}
|
|
29
|
-
scrollToHash(decodeURIComponent(window.location.hash.slice(1)), scroll);
|
|
30
|
-
saveCurrentDepth();
|
|
31
|
-
restoration && !replace && restoration.onPush();
|
|
32
|
-
},
|
|
33
|
-
init: notify => {
|
|
34
|
-
const handler = notifyIfNotBlocked(notify, delta => {
|
|
35
|
-
if (delta) {
|
|
36
|
-
return !beforeLeave.confirm(delta);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const s = getSource();
|
|
40
|
-
return !beforeLeave.confirm(s.value, { state: s.state });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return bindEvent(window, "popstate", restoration
|
|
44
|
-
? () => {
|
|
45
|
-
restoration.onPop();
|
|
46
|
-
handler();
|
|
47
|
-
}
|
|
48
|
-
: handler);
|
|
49
|
-
},
|
|
50
|
-
create: router => {
|
|
51
|
-
setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase, transformUrl: props.transformUrl })(router);
|
|
52
|
-
restoration && restoration.create(router);
|
|
53
|
-
},
|
|
54
|
-
utils: {
|
|
55
|
-
go: delta => window.history.go(delta),
|
|
56
|
-
beforeLeave
|
|
57
|
-
}
|
|
58
|
-
})(props);
|
|
59
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getRequestEvent } from "solid-js/web";
|
|
2
|
-
import { createRouterComponent } from "./components.jsx";
|
|
3
|
-
function getPath(url) {
|
|
4
|
-
const u = new URL(url);
|
|
5
|
-
return u.pathname + u.search;
|
|
6
|
-
}
|
|
7
|
-
export function StaticRouter(props) {
|
|
8
|
-
let e;
|
|
9
|
-
const obj = {
|
|
10
|
-
value: props.url || ((e = getRequestEvent()) && getPath(e.request.url)) || "",
|
|
11
|
-
};
|
|
12
|
-
return createRouterComponent({
|
|
13
|
-
signal: [() => obj, next => Object.assign(obj, next)]
|
|
14
|
-
})(props);
|
|
15
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LocationChange, RouterContext, RouterUtils } from "../types.js";
|
|
2
|
-
export declare function createRouter(config: {
|
|
3
|
-
get: () => string | LocationChange;
|
|
4
|
-
set: (next: LocationChange) => void;
|
|
5
|
-
init?: (notify: (value?: string | LocationChange) => void) => () => void;
|
|
6
|
-
create?: (router: RouterContext) => void;
|
|
7
|
-
utils?: Partial<RouterUtils>;
|
|
8
|
-
}): (props: import("./components.jsx").BaseRouterProps) => import("solid-js").JSX.Element;
|
|
9
|
-
export declare function bindEvent(target: EventTarget, type: string, handler: EventListener): () => void;
|
|
10
|
-
export declare function scrollToHash(hash: string, fallbackTop?: boolean): void;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createSignal, onCleanup, sharedConfig } from "solid-js";
|
|
2
|
-
import { createRouterComponent } from "./components.jsx";
|
|
3
|
-
function intercept([value, setValue], get, set) {
|
|
4
|
-
return [get ? () => get(value()) : value, set ? (v) => setValue(set(v)) : setValue];
|
|
5
|
-
}
|
|
6
|
-
export function createRouter(config) {
|
|
7
|
-
let ignore = false;
|
|
8
|
-
const wrap = (value) => (typeof value === "string" ? { value } : value);
|
|
9
|
-
const signal = intercept(createSignal(wrap(config.get()), {
|
|
10
|
-
equals: (a, b) => a.value === b.value && a.state === b.state
|
|
11
|
-
}), undefined, next => {
|
|
12
|
-
!ignore && config.set(next);
|
|
13
|
-
if (sharedConfig.registry && !sharedConfig.done)
|
|
14
|
-
sharedConfig.done = true;
|
|
15
|
-
return next;
|
|
16
|
-
});
|
|
17
|
-
config.init &&
|
|
18
|
-
onCleanup(config.init((value = config.get()) => {
|
|
19
|
-
ignore = true;
|
|
20
|
-
signal[1](wrap(value));
|
|
21
|
-
ignore = false;
|
|
22
|
-
}));
|
|
23
|
-
return createRouterComponent({
|
|
24
|
-
signal,
|
|
25
|
-
create: config.create,
|
|
26
|
-
utils: config.utils
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export function bindEvent(target, type, handler) {
|
|
30
|
-
target.addEventListener(type, handler);
|
|
31
|
-
return () => target.removeEventListener(type, handler);
|
|
32
|
-
}
|
|
33
|
-
export function scrollToHash(hash, fallbackTop) {
|
|
34
|
-
const el = hash && document.getElementById(hash);
|
|
35
|
-
if (el) {
|
|
36
|
-
el.scrollIntoView();
|
|
37
|
-
}
|
|
38
|
-
else if (fallbackTop) {
|
|
39
|
-
window.scrollTo(0, 0);
|
|
40
|
-
}
|
|
41
|
-
}
|