restructure project, add claudemd
This commit is contained in:
9
web/runtime/@solidjs/router/dist/routers/HashRouter.d.ts
vendored
Normal file
9
web/runtime/@solidjs/router/dist/routers/HashRouter.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { JSX } from "solid-js";
|
||||
import type { BaseRouterProps } from "./components.js";
|
||||
export declare function hashParser(str: string): string;
|
||||
export type HashRouterProps = BaseRouterProps & {
|
||||
actionBase?: string;
|
||||
explicitLinks?: boolean;
|
||||
preload?: boolean;
|
||||
};
|
||||
export declare function HashRouter(props: HashRouterProps): JSX.Element;
|
||||
41
web/runtime/@solidjs/router/dist/routers/HashRouter.js
vendored
Normal file
41
web/runtime/@solidjs/router/dist/routers/HashRouter.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { setupNativeEvents } from "../data/events.js";
|
||||
import { createRouter, scrollToHash, bindEvent } from "./createRouter.js";
|
||||
import { createBeforeLeave, keepDepth, notifyIfNotBlocked, saveCurrentDepth } from "../lifecycle.js";
|
||||
export function hashParser(str) {
|
||||
const to = str.replace(/^.*?#/, "");
|
||||
// Hash-only hrefs like `#foo` from plain anchors will come in as `/#foo` whereas a link to
|
||||
// `/foo` will be `/#/foo`. Check if the to starts with a `/` and if not append it as a hash
|
||||
// to the current path so we can handle these in-page anchors correctly.
|
||||
if (!to.startsWith("/")) {
|
||||
const [, path = "/"] = window.location.hash.split("#", 2);
|
||||
return `${path}#${to}`;
|
||||
}
|
||||
return to;
|
||||
}
|
||||
export function HashRouter(props) {
|
||||
const getSource = () => window.location.hash.slice(1);
|
||||
const beforeLeave = createBeforeLeave();
|
||||
return createRouter({
|
||||
get: getSource,
|
||||
set({ value, replace, scroll, state }) {
|
||||
if (replace) {
|
||||
window.history.replaceState(keepDepth(state), "", "#" + value);
|
||||
}
|
||||
else {
|
||||
window.history.pushState(state, "", "#" + value);
|
||||
}
|
||||
const hashIndex = value.indexOf("#");
|
||||
const hash = hashIndex >= 0 ? value.slice(hashIndex + 1) : "";
|
||||
scrollToHash(hash, scroll);
|
||||
saveCurrentDepth();
|
||||
},
|
||||
init: notify => bindEvent(window, "hashchange", notifyIfNotBlocked(notify, delta => !beforeLeave.confirm(delta && delta < 0 ? delta : getSource()))),
|
||||
create: setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase }),
|
||||
utils: {
|
||||
go: delta => window.history.go(delta),
|
||||
renderPath: path => `#${path}`,
|
||||
parsePath: hashParser,
|
||||
beforeLeave
|
||||
}
|
||||
})(props);
|
||||
}
|
||||
24
web/runtime/@solidjs/router/dist/routers/MemoryRouter.d.ts
vendored
Normal file
24
web/runtime/@solidjs/router/dist/routers/MemoryRouter.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { LocationChange } from "../types.js";
|
||||
import type { BaseRouterProps } from "./components.js";
|
||||
import type { JSX } from "solid-js";
|
||||
export type MemoryHistory = {
|
||||
get: () => string;
|
||||
set: (change: LocationChange) => void;
|
||||
go: (delta: number) => void;
|
||||
listen: (listener: (value: string) => void) => () => void;
|
||||
};
|
||||
export declare function createMemoryHistory(): {
|
||||
get: () => string;
|
||||
set: ({ value, scroll, replace }: LocationChange) => void;
|
||||
back: () => void;
|
||||
forward: () => void;
|
||||
go: (n: number) => void;
|
||||
listen: (listener: (value: string) => void) => () => void;
|
||||
};
|
||||
export type MemoryRouterProps = BaseRouterProps & {
|
||||
history?: MemoryHistory;
|
||||
actionBase?: string;
|
||||
explicitLinks?: boolean;
|
||||
preload?: boolean;
|
||||
};
|
||||
export declare function MemoryRouter(props: MemoryRouterProps): JSX.Element;
|
||||
57
web/runtime/@solidjs/router/dist/routers/MemoryRouter.js
vendored
Normal file
57
web/runtime/@solidjs/router/dist/routers/MemoryRouter.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import { createRouter, scrollToHash } from "./createRouter.js";
|
||||
import { setupNativeEvents } from "../data/events.js";
|
||||
export function createMemoryHistory() {
|
||||
const entries = ["/"];
|
||||
let index = 0;
|
||||
const listeners = [];
|
||||
const go = (n) => {
|
||||
// https://github.com/remix-run/react-router/blob/682810ca929d0e3c64a76f8d6e465196b7a2ac58/packages/router/history.ts#L245
|
||||
index = Math.max(0, Math.min(index + n, entries.length - 1));
|
||||
const value = entries[index];
|
||||
listeners.forEach(listener => listener(value));
|
||||
};
|
||||
return {
|
||||
get: () => entries[index],
|
||||
set: ({ value, scroll, replace }) => {
|
||||
if (replace) {
|
||||
entries[index] = value;
|
||||
}
|
||||
else {
|
||||
entries.splice(index + 1, entries.length - index, value);
|
||||
index++;
|
||||
}
|
||||
listeners.forEach(listener => listener(value));
|
||||
setTimeout(() => {
|
||||
if (scroll) {
|
||||
scrollToHash(value.split("#")[1] || "", true);
|
||||
}
|
||||
}, 0);
|
||||
},
|
||||
back: () => {
|
||||
go(-1);
|
||||
},
|
||||
forward: () => {
|
||||
go(1);
|
||||
},
|
||||
go,
|
||||
listen: (listener) => {
|
||||
listeners.push(listener);
|
||||
return () => {
|
||||
const index = listeners.indexOf(listener);
|
||||
listeners.splice(index, 1);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
export function MemoryRouter(props) {
|
||||
const memoryHistory = props.history || createMemoryHistory();
|
||||
return createRouter({
|
||||
get: memoryHistory.get,
|
||||
set: memoryHistory.set,
|
||||
init: memoryHistory.listen,
|
||||
create: setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase }),
|
||||
utils: {
|
||||
go: memoryHistory.go
|
||||
}
|
||||
})(props);
|
||||
}
|
||||
9
web/runtime/@solidjs/router/dist/routers/Router.d.ts
vendored
Normal file
9
web/runtime/@solidjs/router/dist/routers/Router.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { BaseRouterProps } from "./components.js";
|
||||
import type { JSX } from "solid-js";
|
||||
export type RouterProps = BaseRouterProps & {
|
||||
url?: string;
|
||||
actionBase?: string;
|
||||
explicitLinks?: boolean;
|
||||
preload?: boolean;
|
||||
};
|
||||
export declare function Router(props: RouterProps): JSX.Element;
|
||||
45
web/runtime/@solidjs/router/dist/routers/Router.js
vendored
Normal file
45
web/runtime/@solidjs/router/dist/routers/Router.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import { isServer } from "solid-js/web";
|
||||
import { createRouter, scrollToHash, bindEvent } from "./createRouter.js";
|
||||
import { StaticRouter } from "./StaticRouter.js";
|
||||
import { setupNativeEvents } from "../data/events.js";
|
||||
import { createBeforeLeave, keepDepth, notifyIfNotBlocked, saveCurrentDepth } from "../lifecycle.js";
|
||||
export function Router(props) {
|
||||
if (isServer)
|
||||
return StaticRouter(props);
|
||||
const getSource = () => {
|
||||
const url = window.location.pathname.replace(/^\/+/, "/") + window.location.search;
|
||||
const state = window.history.state && window.history.state._depth && Object.keys(window.history.state).length === 1 ? undefined : window.history.state;
|
||||
return {
|
||||
value: url + window.location.hash,
|
||||
state
|
||||
};
|
||||
};
|
||||
const beforeLeave = createBeforeLeave();
|
||||
return createRouter({
|
||||
get: getSource,
|
||||
set({ value, replace, scroll, state }) {
|
||||
if (replace) {
|
||||
window.history.replaceState(keepDepth(state), "", value);
|
||||
}
|
||||
else {
|
||||
window.history.pushState(state, "", value);
|
||||
}
|
||||
scrollToHash(decodeURIComponent(window.location.hash.slice(1)), scroll);
|
||||
saveCurrentDepth();
|
||||
},
|
||||
init: notify => bindEvent(window, "popstate", notifyIfNotBlocked(notify, delta => {
|
||||
if (delta) {
|
||||
return !beforeLeave.confirm(delta);
|
||||
}
|
||||
else {
|
||||
const s = getSource();
|
||||
return !beforeLeave.confirm(s.value, { state: s.state });
|
||||
}
|
||||
})),
|
||||
create: setupNativeEvents({ preload: props.preload, explicitLinks: props.explicitLinks, actionBase: props.actionBase, transformUrl: props.transformUrl }),
|
||||
utils: {
|
||||
go: delta => window.history.go(delta),
|
||||
beforeLeave
|
||||
}
|
||||
})(props);
|
||||
}
|
||||
6
web/runtime/@solidjs/router/dist/routers/StaticRouter.d.ts
vendored
Normal file
6
web/runtime/@solidjs/router/dist/routers/StaticRouter.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type BaseRouterProps } from "./components.js";
|
||||
import type { JSX } from "solid-js";
|
||||
export type StaticRouterProps = BaseRouterProps & {
|
||||
url?: string;
|
||||
};
|
||||
export declare function StaticRouter(props: StaticRouterProps): JSX.Element;
|
||||
15
web/runtime/@solidjs/router/dist/routers/StaticRouter.js
vendored
Normal file
15
web/runtime/@solidjs/router/dist/routers/StaticRouter.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import { createRouterComponent } from "./components.js";
|
||||
function getPath(url) {
|
||||
const u = new URL(url);
|
||||
return u.pathname + u.search;
|
||||
}
|
||||
export function StaticRouter(props) {
|
||||
let e;
|
||||
const obj = {
|
||||
value: props.url || ((e = getRequestEvent()) && getPath(e.request.url)) || "",
|
||||
};
|
||||
return createRouterComponent({
|
||||
signal: [() => obj, next => Object.assign(obj, next)]
|
||||
})(props);
|
||||
}
|
||||
27
web/runtime/@solidjs/router/dist/routers/components.d.ts
vendored
Normal file
27
web/runtime/@solidjs/router/dist/routers/components.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { Component, JSX } from "solid-js";
|
||||
import type { MatchFilters, RouteDefinition, RoutePreloadFunc, RouterIntegration, RouteSectionProps } from "../types.js";
|
||||
export type BaseRouterProps = {
|
||||
base?: string;
|
||||
/**
|
||||
* A component that wraps the content of every route.
|
||||
*/
|
||||
root?: Component<RouteSectionProps>;
|
||||
rootPreload?: RoutePreloadFunc;
|
||||
singleFlight?: boolean;
|
||||
children?: JSX.Element | RouteDefinition | RouteDefinition[];
|
||||
transformUrl?: (url: string) => string;
|
||||
/** @deprecated use rootPreload */
|
||||
rootLoad?: RoutePreloadFunc;
|
||||
};
|
||||
export declare const createRouterComponent: (router: RouterIntegration) => (props: BaseRouterProps) => JSX.Element;
|
||||
export type RouteProps<S extends string, T = unknown> = {
|
||||
path?: S | S[];
|
||||
children?: JSX.Element;
|
||||
preload?: RoutePreloadFunc<T>;
|
||||
matchFilters?: MatchFilters<S>;
|
||||
component?: Component<RouteSectionProps<T>>;
|
||||
info?: Record<string, any>;
|
||||
/** @deprecated use preload */
|
||||
load?: RoutePreloadFunc<T>;
|
||||
};
|
||||
export declare const Route: <S extends string, T = unknown>(props: RouteProps<S, T>) => JSX.Element;
|
||||
118
web/runtime/@solidjs/router/dist/routers/components.jsx
vendored
Normal file
118
web/runtime/@solidjs/router/dist/routers/components.jsx
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
/*@refresh skip*/
|
||||
import { children, createMemo, createRoot, getOwner, mergeProps, on, Show, untrack } from "solid-js";
|
||||
import { getRequestEvent, isServer } from "solid-js/web";
|
||||
import { createBranches, createRouteContext, createRouterContext, getIntent, getRouteMatches, RouteContextObj, RouterContextObj, setInPreloadFn } from "../routing.js";
|
||||
export const createRouterComponent = (router) => (props) => {
|
||||
const { base } = props;
|
||||
const routeDefs = children(() => props.children);
|
||||
const branches = createMemo(() => createBranches(routeDefs(), props.base || ""));
|
||||
let context;
|
||||
const routerState = createRouterContext(router, branches, () => context, {
|
||||
base,
|
||||
singleFlight: props.singleFlight,
|
||||
transformUrl: props.transformUrl,
|
||||
});
|
||||
router.create && router.create(routerState);
|
||||
return (<RouterContextObj.Provider value={routerState}>
|
||||
<Root routerState={routerState} root={props.root} preload={props.rootPreload || props.rootLoad}>
|
||||
{(context = getOwner()) && null}
|
||||
<Routes routerState={routerState} branches={branches()}/>
|
||||
</Root>
|
||||
</RouterContextObj.Provider>);
|
||||
};
|
||||
function Root(props) {
|
||||
const location = props.routerState.location;
|
||||
const params = props.routerState.params;
|
||||
const data = createMemo(() => props.preload &&
|
||||
untrack(() => {
|
||||
setInPreloadFn(true);
|
||||
props.preload({ params, location, intent: getIntent() || "initial" });
|
||||
setInPreloadFn(false);
|
||||
}));
|
||||
return (<Show when={props.root} keyed fallback={props.children}>
|
||||
{Root => (<Root params={params} location={location} data={data()}>
|
||||
{props.children}
|
||||
</Root>)}
|
||||
</Show>);
|
||||
}
|
||||
function Routes(props) {
|
||||
if (isServer) {
|
||||
const e = getRequestEvent();
|
||||
if (e && e.router && e.router.dataOnly) {
|
||||
dataOnly(e, props.routerState, props.branches);
|
||||
return;
|
||||
}
|
||||
e &&
|
||||
((e.router || (e.router = {})).matches ||
|
||||
(e.router.matches = props.routerState.matches().map(({ route, path, params }) => ({
|
||||
path: route.originalPath,
|
||||
pattern: route.pattern,
|
||||
match: path,
|
||||
params,
|
||||
info: route.info
|
||||
}))));
|
||||
}
|
||||
const disposers = [];
|
||||
let root;
|
||||
const routeStates = createMemo(on(props.routerState.matches, (nextMatches, prevMatches, prev) => {
|
||||
let equal = prevMatches && nextMatches.length === prevMatches.length;
|
||||
const next = [];
|
||||
for (let i = 0, len = nextMatches.length; i < len; i++) {
|
||||
const prevMatch = prevMatches && prevMatches[i];
|
||||
const nextMatch = nextMatches[i];
|
||||
if (prev && prevMatch && nextMatch.route.key === prevMatch.route.key) {
|
||||
next[i] = prev[i];
|
||||
}
|
||||
else {
|
||||
equal = false;
|
||||
if (disposers[i]) {
|
||||
disposers[i]();
|
||||
}
|
||||
createRoot(dispose => {
|
||||
disposers[i] = dispose;
|
||||
next[i] = createRouteContext(props.routerState, next[i - 1] || props.routerState.base, createOutlet(() => routeStates()[i + 1]), () => {
|
||||
const routeMatches = props.routerState.matches();
|
||||
return routeMatches[i] ?? routeMatches[0];
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
disposers.splice(nextMatches.length).forEach(dispose => dispose());
|
||||
if (prev && equal) {
|
||||
return prev;
|
||||
}
|
||||
root = next[0];
|
||||
return next;
|
||||
}));
|
||||
return createOutlet(() => routeStates() && root)();
|
||||
}
|
||||
const createOutlet = (child) => {
|
||||
return () => (<Show when={child()} keyed>
|
||||
{child => <RouteContextObj.Provider value={child}>{child.outlet()}</RouteContextObj.Provider>}
|
||||
</Show>);
|
||||
};
|
||||
export const Route = (props) => {
|
||||
const childRoutes = children(() => props.children);
|
||||
return mergeProps(props, {
|
||||
get children() {
|
||||
return childRoutes();
|
||||
}
|
||||
});
|
||||
};
|
||||
// for data only mode with single flight mutations
|
||||
function dataOnly(event, routerState, branches) {
|
||||
const url = new URL(event.request.url);
|
||||
const prevMatches = getRouteMatches(branches, new URL(event.router.previousUrl || event.request.url).pathname);
|
||||
const matches = getRouteMatches(branches, url.pathname);
|
||||
for (let match = 0; match < matches.length; match++) {
|
||||
if (!prevMatches[match] || matches[match].route !== prevMatches[match].route)
|
||||
event.router.dataOnly = true;
|
||||
const { route, params } = matches[match];
|
||||
route.preload &&
|
||||
route.preload({
|
||||
params,
|
||||
location: routerState.location,
|
||||
intent: "preload"
|
||||
});
|
||||
}
|
||||
}
|
||||
10
web/runtime/@solidjs/router/dist/routers/createRouter.d.ts
vendored
Normal file
10
web/runtime/@solidjs/router/dist/routers/createRouter.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { LocationChange, RouterContext, RouterUtils } from "../types.js";
|
||||
export declare function createRouter(config: {
|
||||
get: () => string | LocationChange;
|
||||
set: (next: LocationChange) => void;
|
||||
init?: (notify: (value?: string | LocationChange) => void) => () => void;
|
||||
create?: (router: RouterContext) => void;
|
||||
utils?: Partial<RouterUtils>;
|
||||
}): (props: import("./components.js").BaseRouterProps) => import("solid-js").JSX.Element;
|
||||
export declare function bindEvent(target: EventTarget, type: string, handler: EventListener): () => void;
|
||||
export declare function scrollToHash(hash: string, fallbackTop?: boolean): void;
|
||||
41
web/runtime/@solidjs/router/dist/routers/createRouter.js
vendored
Normal file
41
web/runtime/@solidjs/router/dist/routers/createRouter.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { createSignal, onCleanup, sharedConfig } from "solid-js";
|
||||
import { createRouterComponent } from "./components.js";
|
||||
function intercept([value, setValue], get, set) {
|
||||
return [get ? () => get(value()) : value, set ? (v) => setValue(set(v)) : setValue];
|
||||
}
|
||||
export function createRouter(config) {
|
||||
let ignore = false;
|
||||
const wrap = (value) => (typeof value === "string" ? { value } : value);
|
||||
const signal = intercept(createSignal(wrap(config.get()), {
|
||||
equals: (a, b) => a.value === b.value && a.state === b.state
|
||||
}), undefined, next => {
|
||||
!ignore && config.set(next);
|
||||
if (sharedConfig.registry && !sharedConfig.done)
|
||||
sharedConfig.done = true;
|
||||
return next;
|
||||
});
|
||||
config.init &&
|
||||
onCleanup(config.init((value = config.get()) => {
|
||||
ignore = true;
|
||||
signal[1](wrap(value));
|
||||
ignore = false;
|
||||
}));
|
||||
return createRouterComponent({
|
||||
signal,
|
||||
create: config.create,
|
||||
utils: config.utils
|
||||
});
|
||||
}
|
||||
export function bindEvent(target, type, handler) {
|
||||
target.addEventListener(type, handler);
|
||||
return () => target.removeEventListener(type, handler);
|
||||
}
|
||||
export function scrollToHash(hash, fallbackTop) {
|
||||
const el = hash && document.getElementById(hash);
|
||||
if (el) {
|
||||
el.scrollIntoView();
|
||||
}
|
||||
else if (fallbackTop) {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
11
web/runtime/@solidjs/router/dist/routers/index.d.ts
vendored
Normal file
11
web/runtime/@solidjs/router/dist/routers/index.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export { Route } from "./components.js";
|
||||
export type { BaseRouterProps, RouteProps } from "./components.js";
|
||||
export { createRouter } from "./createRouter.js";
|
||||
export { Router } from "./Router.js";
|
||||
export type { RouterProps } from "./Router.js";
|
||||
export { HashRouter } from "./HashRouter.js";
|
||||
export type { HashRouterProps } from "./HashRouter.js";
|
||||
export { MemoryRouter, createMemoryHistory } from "./MemoryRouter.js";
|
||||
export type { MemoryRouterProps, MemoryHistory } from "./MemoryRouter.js";
|
||||
export { StaticRouter } from "./StaticRouter.js";
|
||||
export type { StaticRouterProps } from "./StaticRouter.js";
|
||||
6
web/runtime/@solidjs/router/dist/routers/index.js
vendored
Normal file
6
web/runtime/@solidjs/router/dist/routers/index.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export { Route } from "./components.js";
|
||||
export { createRouter } from "./createRouter.js";
|
||||
export { Router } from "./Router.js";
|
||||
export { HashRouter } from "./HashRouter.js";
|
||||
export { MemoryRouter, createMemoryHistory } from "./MemoryRouter.js";
|
||||
export { StaticRouter } from "./StaticRouter.js";
|
||||
Reference in New Issue
Block a user