New source found from dndbeyond.com
This commit is contained in:
+1247
-463
File diff suppressed because it is too large
Load Diff
+145
-32
@@ -63,15 +63,6 @@ export type DataResult =
|
||||
| RedirectResult
|
||||
| ErrorResult;
|
||||
|
||||
/**
|
||||
* Result from a loader or action called via dataStrategy
|
||||
*/
|
||||
export interface HandlerResult {
|
||||
type: "data" | "error";
|
||||
result: unknown; // data, Error, Response, DeferredData
|
||||
status?: number;
|
||||
}
|
||||
|
||||
type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
|
||||
type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
|
||||
|
||||
@@ -210,7 +201,7 @@ export interface ShouldRevalidateFunctionArgs {
|
||||
text?: Submission["text"];
|
||||
formData?: Submission["formData"];
|
||||
json?: Submission["json"];
|
||||
unstable_actionStatus?: number;
|
||||
actionStatus?: number;
|
||||
actionResult?: any;
|
||||
defaultShouldRevalidate: boolean;
|
||||
}
|
||||
@@ -242,19 +233,46 @@ export interface DataStrategyMatch
|
||||
resolve: (
|
||||
handlerOverride?: (
|
||||
handler: (ctx?: unknown) => DataFunctionReturnValue
|
||||
) => Promise<HandlerResult>
|
||||
) => Promise<HandlerResult>;
|
||||
) => DataFunctionReturnValue
|
||||
) => Promise<DataStrategyResult>;
|
||||
}
|
||||
|
||||
export interface DataStrategyFunctionArgs<Context = any>
|
||||
extends DataFunctionArgs<Context> {
|
||||
matches: DataStrategyMatch[];
|
||||
fetcherKey: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result from a loader or action called via dataStrategy
|
||||
*/
|
||||
export interface DataStrategyResult {
|
||||
type: "data" | "error";
|
||||
result: unknown; // data, Error, Response, DeferredData, DataWithResponseInit
|
||||
}
|
||||
|
||||
export interface DataStrategyFunction {
|
||||
(args: DataStrategyFunctionArgs): Promise<HandlerResult[]>;
|
||||
(args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
|
||||
}
|
||||
|
||||
export type AgnosticPatchRoutesOnNavigationFunctionArgs<
|
||||
O extends AgnosticRouteObject = AgnosticRouteObject,
|
||||
M extends AgnosticRouteMatch = AgnosticRouteMatch
|
||||
> = {
|
||||
signal: AbortSignal;
|
||||
path: string;
|
||||
matches: M[];
|
||||
fetcherKey: string | undefined;
|
||||
patch: (routeId: string | null, children: O[]) => void;
|
||||
};
|
||||
|
||||
export type AgnosticPatchRoutesOnNavigationFunction<
|
||||
O extends AgnosticRouteObject = AgnosticRouteObject,
|
||||
M extends AgnosticRouteMatch = AgnosticRouteMatch
|
||||
> = (
|
||||
opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>
|
||||
) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* Function provided by the framework-aware layers to set any framework-specific
|
||||
* properties from framework-agnostic properties
|
||||
@@ -444,11 +462,11 @@ function isIndexRoute(
|
||||
export function convertRoutesToDataRoutes(
|
||||
routes: AgnosticRouteObject[],
|
||||
mapRouteProperties: MapRoutePropertiesFunction,
|
||||
parentPath: number[] = [],
|
||||
parentPath: string[] = [],
|
||||
manifest: RouteManifest = {}
|
||||
): AgnosticDataRouteObject[] {
|
||||
return routes.map((route, index) => {
|
||||
let treePath = [...parentPath, index];
|
||||
let treePath = [...parentPath, String(index)];
|
||||
let id = typeof route.id === "string" ? route.id : treePath.join("-");
|
||||
invariant(
|
||||
route.index !== true || !route.children,
|
||||
@@ -494,7 +512,7 @@ export function convertRoutesToDataRoutes(
|
||||
/**
|
||||
* Matches the given routes to a location and returns the match data.
|
||||
*
|
||||
* @see https://reactrouter.com/utils/match-routes
|
||||
* @see https://reactrouter.com/v6/utils/match-routes
|
||||
*/
|
||||
export function matchRoutes<
|
||||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject
|
||||
@@ -502,6 +520,17 @@ export function matchRoutes<
|
||||
routes: RouteObjectType[],
|
||||
locationArg: Partial<Location> | string,
|
||||
basename = "/"
|
||||
): AgnosticRouteMatch<string, RouteObjectType>[] | null {
|
||||
return matchRoutesImpl(routes, locationArg, basename, false);
|
||||
}
|
||||
|
||||
export function matchRoutesImpl<
|
||||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject
|
||||
>(
|
||||
routes: RouteObjectType[],
|
||||
locationArg: Partial<Location> | string,
|
||||
basename: string,
|
||||
allowPartial: boolean
|
||||
): AgnosticRouteMatch<string, RouteObjectType>[] | null {
|
||||
let location =
|
||||
typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
||||
@@ -524,7 +553,11 @@ export function matchRoutes<
|
||||
// should be a safe operation. This avoids needing matchRoutes to be
|
||||
// history-aware.
|
||||
let decoded = decodePath(pathname);
|
||||
matches = matchRouteBranch<string, RouteObjectType>(branches[i], decoded);
|
||||
matches = matchRouteBranch<string, RouteObjectType>(
|
||||
branches[i],
|
||||
decoded,
|
||||
allowPartial
|
||||
);
|
||||
}
|
||||
|
||||
return matches;
|
||||
@@ -615,7 +648,6 @@ function flattenRoutes<
|
||||
`Index routes must not have child routes. Please remove ` +
|
||||
`all child routes from route path "${path}".`
|
||||
);
|
||||
|
||||
flattenRoutes(route.children, branches, routesMeta, path);
|
||||
}
|
||||
|
||||
@@ -768,7 +800,8 @@ function matchRouteBranch<
|
||||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject
|
||||
>(
|
||||
branch: RouteBranch<RouteObjectType>,
|
||||
pathname: string
|
||||
pathname: string,
|
||||
allowPartial = false
|
||||
): AgnosticRouteMatch<ParamKey, RouteObjectType>[] | null {
|
||||
let { routesMeta } = branch;
|
||||
|
||||
@@ -787,12 +820,30 @@ function matchRouteBranch<
|
||||
remainingPathname
|
||||
);
|
||||
|
||||
if (!match) return null;
|
||||
let route = meta.route;
|
||||
|
||||
if (
|
||||
!match &&
|
||||
end &&
|
||||
allowPartial &&
|
||||
!routesMeta[routesMeta.length - 1].route.index
|
||||
) {
|
||||
match = matchPath(
|
||||
{
|
||||
path: meta.relativePath,
|
||||
caseSensitive: meta.caseSensitive,
|
||||
end: false,
|
||||
},
|
||||
remainingPathname
|
||||
);
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object.assign(matchedParams, match.params);
|
||||
|
||||
let route = meta.route;
|
||||
|
||||
matches.push({
|
||||
// TODO: Can this as be avoided?
|
||||
params: matchedParams as Params<ParamKey>,
|
||||
@@ -814,7 +865,7 @@ function matchRouteBranch<
|
||||
/**
|
||||
* Returns a path with params interpolated.
|
||||
*
|
||||
* @see https://reactrouter.com/utils/generate-path
|
||||
* @see https://reactrouter.com/v6/utils/generate-path
|
||||
*/
|
||||
export function generatePath<Path extends string>(
|
||||
originalPath: Path,
|
||||
@@ -920,7 +971,7 @@ type Mutable<T> = {
|
||||
* Performs pattern matching on a URL pathname and returns information about
|
||||
* the match.
|
||||
*
|
||||
* @see https://reactrouter.com/utils/match-path
|
||||
* @see https://reactrouter.com/v6/utils/match-path
|
||||
*/
|
||||
export function matchPath<
|
||||
ParamKey extends ParamParseKey<Path>,
|
||||
@@ -1032,7 +1083,7 @@ function compilePath(
|
||||
return [matcher, params];
|
||||
}
|
||||
|
||||
function decodePath(value: string) {
|
||||
export function decodePath(value: string) {
|
||||
try {
|
||||
return value
|
||||
.split("/")
|
||||
@@ -1077,10 +1128,13 @@ export function stripBasename(
|
||||
return pathname.slice(startIndex) || "/";
|
||||
}
|
||||
|
||||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
||||
export const isAbsoluteUrl = (url: string) => ABSOLUTE_URL_REGEX.test(url);
|
||||
|
||||
/**
|
||||
* Returns a resolved path object relative to the given pathname.
|
||||
*
|
||||
* @see https://reactrouter.com/utils/resolve-path
|
||||
* @see https://reactrouter.com/v6/utils/resolve-path
|
||||
*/
|
||||
export function resolvePath(to: To, fromPathname = "/"): Path {
|
||||
let {
|
||||
@@ -1089,11 +1143,29 @@ export function resolvePath(to: To, fromPathname = "/"): Path {
|
||||
hash = "",
|
||||
} = typeof to === "string" ? parsePath(to) : to;
|
||||
|
||||
let pathname = toPathname
|
||||
? toPathname.startsWith("/")
|
||||
? toPathname
|
||||
: resolvePathname(toPathname, fromPathname)
|
||||
: fromPathname;
|
||||
let pathname: string;
|
||||
if (toPathname) {
|
||||
if (isAbsoluteUrl(toPathname)) {
|
||||
pathname = toPathname;
|
||||
} else {
|
||||
if (toPathname.includes("//")) {
|
||||
let oldPathname = toPathname;
|
||||
toPathname = toPathname.replace(/\/\/+/g, "/");
|
||||
warning(
|
||||
false,
|
||||
`Pathnames cannot have embedded double slashes - normalizing ` +
|
||||
`${oldPathname} -> ${toPathname}`
|
||||
);
|
||||
}
|
||||
if (toPathname.startsWith("/")) {
|
||||
pathname = resolvePathname(toPathname.substring(1), "/");
|
||||
} else {
|
||||
pathname = resolvePathname(toPathname, fromPathname);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pathname = fromPathname;
|
||||
}
|
||||
|
||||
return {
|
||||
pathname,
|
||||
@@ -1178,7 +1250,7 @@ export function getResolveToMatches<
|
||||
// https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
|
||||
if (v7_relativeSplatPath) {
|
||||
return pathMatches.map((match, idx) =>
|
||||
idx === matches.length - 1 ? match.pathname : match.pathnameBase
|
||||
idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1317,6 +1389,9 @@ export type JsonFunction = <Data>(
|
||||
/**
|
||||
* This is a shortcut for creating `application/json` responses. Converts `data`
|
||||
* to JSON and sets the `Content-Type` header.
|
||||
*
|
||||
* @deprecated The `json` method is deprecated in favor of returning raw objects.
|
||||
* This method will be removed in v7.
|
||||
*/
|
||||
export const json: JsonFunction = (data, init = {}) => {
|
||||
let responseInit = typeof init === "number" ? { status: init } : init;
|
||||
@@ -1332,6 +1407,28 @@ export const json: JsonFunction = (data, init = {}) => {
|
||||
});
|
||||
};
|
||||
|
||||
export class DataWithResponseInit<D> {
|
||||
type: string = "DataWithResponseInit";
|
||||
data: D;
|
||||
init: ResponseInit | null;
|
||||
|
||||
constructor(data: D, init?: ResponseInit) {
|
||||
this.data = data;
|
||||
this.init = init || null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create "responses" that contain `status`/`headers` without forcing
|
||||
* serialization into an actual `Response` - used by Remix single fetch
|
||||
*/
|
||||
export function data<D>(data: D, init?: number | ResponseInit) {
|
||||
return new DataWithResponseInit(
|
||||
data,
|
||||
typeof init === "number" ? { status: init } : init
|
||||
);
|
||||
}
|
||||
|
||||
export interface TrackedPromise extends Promise<any> {
|
||||
_tracked?: boolean;
|
||||
_data?: any;
|
||||
@@ -1533,6 +1630,10 @@ export type DeferFunction = (
|
||||
init?: number | ResponseInit
|
||||
) => DeferredData;
|
||||
|
||||
/**
|
||||
* @deprecated The `defer` method is deprecated in favor of returning raw
|
||||
* objects. This method will be removed in v7.
|
||||
*/
|
||||
export const defer: DeferFunction = (data, init = {}) => {
|
||||
let responseInit = typeof init === "number" ? { status: init } : init;
|
||||
|
||||
@@ -1576,6 +1677,18 @@ export const redirectDocument: RedirectFunction = (url, init) => {
|
||||
return response;
|
||||
};
|
||||
|
||||
/**
|
||||
* A redirect response that will perform a `history.replaceState` instead of a
|
||||
* `history.pushState` for client-side navigation redirects.
|
||||
* Sets the status code and the `Location` header.
|
||||
* Defaults to "302 Found".
|
||||
*/
|
||||
export const replace: RedirectFunction = (url, init) => {
|
||||
let response = redirect(url, init);
|
||||
response.headers.set("X-Remix-Replace", "true");
|
||||
return response;
|
||||
};
|
||||
|
||||
export type ErrorResponse = {
|
||||
status: number;
|
||||
statusText: string;
|
||||
|
||||
Reference in New Issue
Block a user