@solidjs/router 0.17.0-next.5 → 1.0.0-next.7
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 +526 -716
- package/dist/claims.d.ts +21 -0
- package/dist/claims.js +108 -0
- package/dist/data/action.d.ts +28 -1
- package/dist/data/action.js +184 -43
- package/dist/data/events.d.ts +8 -0
- package/dist/data/events.js +23 -22
- package/dist/data/flash.d.ts +21 -0
- package/dist/data/flash.js +78 -0
- package/dist/data/flashCookie.d.ts +7 -0
- package/dist/data/flashCookie.js +20 -0
- package/dist/data/query.js +11 -4
- package/dist/data/serverForms.d.ts +1 -0
- package/dist/data/serverForms.js +5 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1381 -686
- 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 +10 -21
- package/dist/routers/components.jsx +29 -44
- package/dist/routers/factory.d.ts +45 -0
- package/dist/routers/factory.jsx +143 -0
- package/dist/routers/history.d.ts +24 -0
- package/dist/routers/history.js +180 -0
- package/dist/routers/index.d.ts +4 -11
- package/dist/routers/index.js +2 -6
- package/dist/routing.d.ts +80 -44
- package/dist/routing.js +303 -107
- package/dist/server.d.ts +75 -0
- package/dist/server.js +264 -0
- package/dist/types.d.ts +75 -6
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +2 -0
- package/package.json +10 -8
- package/dist/components.d.ts +0 -31
- package/dist/components.jsx +0 -46
- 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 -9
- package/dist/routers/Router.js +0 -45
- 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 -40
|
@@ -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,9 +0,0 @@
|
|
|
1
|
-
import type { BaseRouterProps } from "./components.jsx";
|
|
2
|
-
import type { JSX } from "@solidjs/web";
|
|
3
|
-
export type RouterProps = BaseRouterProps & {
|
|
4
|
-
url?: string;
|
|
5
|
-
actionBase?: string;
|
|
6
|
-
explicitLinks?: boolean;
|
|
7
|
-
preload?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare function Router(props: RouterProps): JSX.Element;
|
package/dist/routers/Router.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { isServer } from "@solidjs/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
|
-
export function Router(props) {
|
|
7
|
-
if (isServer)
|
|
8
|
-
return StaticRouter(props);
|
|
9
|
-
const getSource = () => {
|
|
10
|
-
const url = window.location.pathname + window.location.search;
|
|
11
|
-
const state = window.history.state && window.history.state._depth && Object.keys(window.history.state).length === 1 ? undefined : window.history.state;
|
|
12
|
-
return {
|
|
13
|
-
value: url + window.location.hash,
|
|
14
|
-
state
|
|
15
|
-
};
|
|
16
|
-
};
|
|
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
|
-
scrollToHash(decodeURIComponent(window.location.hash.slice(1)), scroll);
|
|
28
|
-
saveCurrentDepth();
|
|
29
|
-
},
|
|
30
|
-
init: notify => bindEvent(window, "popstate", notifyIfNotBlocked(notify, delta => {
|
|
31
|
-
if (delta) {
|
|
32
|
-
return !beforeLeave.confirm(delta);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
const s = getSource();
|
|
36
|
-
return !beforeLeave.confirm(s.value, { state: s.state });
|
|
37
|
-
}
|
|
38
|
-
})),
|
|
39
|
-
create: setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase, transformUrl: props.transformUrl }),
|
|
40
|
-
utils: {
|
|
41
|
-
go: delta => window.history.go(delta),
|
|
42
|
-
beforeLeave
|
|
43
|
-
}
|
|
44
|
-
})(props);
|
|
45
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getRequestEvent } from "@solidjs/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("@solidjs/web").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,40 +0,0 @@
|
|
|
1
|
-
import { createSignal, onCleanup, sharedConfig } from "solid-js";
|
|
2
|
-
import { createRouterComponent } from "./components.jsx";
|
|
3
|
-
export function createRouter(config) {
|
|
4
|
-
let ignore = false;
|
|
5
|
-
const wrap = (value) => (typeof value === "string" ? { value } : value);
|
|
6
|
-
const [read, write] = createSignal(wrap(config.get()), {
|
|
7
|
-
equals: (a, b) => a.value === b.value && a.state === b.state,
|
|
8
|
-
ownedWrite: true
|
|
9
|
-
});
|
|
10
|
-
const signal = [read, (next) => {
|
|
11
|
-
!ignore && config.set(next);
|
|
12
|
-
if (sharedConfig.registry && !sharedConfig.done)
|
|
13
|
-
sharedConfig.done = true;
|
|
14
|
-
write(next);
|
|
15
|
-
}];
|
|
16
|
-
config.init &&
|
|
17
|
-
onCleanup(config.init((value = config.get()) => {
|
|
18
|
-
ignore = true;
|
|
19
|
-
signal[1](wrap(value));
|
|
20
|
-
ignore = false;
|
|
21
|
-
}));
|
|
22
|
-
return createRouterComponent({
|
|
23
|
-
signal,
|
|
24
|
-
create: config.create,
|
|
25
|
-
utils: config.utils
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
export function bindEvent(target, type, handler) {
|
|
29
|
-
target.addEventListener(type, handler);
|
|
30
|
-
return () => target.removeEventListener(type, handler);
|
|
31
|
-
}
|
|
32
|
-
export function scrollToHash(hash, fallbackTop) {
|
|
33
|
-
const el = hash && document.getElementById(hash);
|
|
34
|
-
if (el) {
|
|
35
|
-
el.scrollIntoView();
|
|
36
|
-
}
|
|
37
|
-
else if (fallbackTop) {
|
|
38
|
-
window.scrollTo(0, 0);
|
|
39
|
-
}
|
|
40
|
-
}
|