@swan-io/chicane
Advanced tools
Comparing version 1.4.1 to 2.0.0-rc.0
@@ -1,5 +0,3 @@ | ||
import { ParsedRoute } from "./types"; | ||
import { RouteObject } from "./types"; | ||
export declare const addPrefixOnNonEmpty: (value: string, prefix: string) => string; | ||
export declare const ensureSlashPrefix: (value: string) => string; | ||
export declare const parseRoute: (route: string) => ParsedRoute; | ||
export declare const concatRoutes: (routeA: ParsedRoute, routeB: ParsedRoute) => string; | ||
export declare const concatRoutes: (routeA: RouteObject, routeB: RouteObject) => string; |
@@ -1,1 +0,1 @@ | ||
export declare const createGroup: <GroupName extends string, BaseRoute extends string, Routes extends Record<string, string>>(name: GroupName, baseRoute: BaseRoute, routes: Readonly<Routes>) => { [K in keyof Routes as K extends string ? `${GroupName}${K}` : never]: `${import("./types").ConcatPaths<import("./types").ParseRoute<BaseRoute>["path"], import("./types").ParseRoute<Routes[K]>["path"], import("./types").ParseRoute<BaseRoute>["path"] extends infer T ? T extends import("./types").ParseRoute<BaseRoute>["path"] ? T extends `/${string}` ? T : `/${T}` : never : never, import("./types").ParseRoute<Routes[K]>["path"] extends infer T_1 ? T_1 extends import("./types").ParseRoute<Routes[K]>["path"] ? T_1 extends `/${string}` ? T_1 : `/${T_1}` : never : never>}${import("./types").ConcatSearchs<import("./types").ParseRoute<BaseRoute>["search"], import("./types").ParseRoute<Routes[K]>["search"]> extends infer T_2 ? T_2 extends import("./types").ConcatSearchs<import("./types").ParseRoute<BaseRoute>["search"], import("./types").ParseRoute<Routes[K]>["search"]> ? T_2 extends "" ? T_2 : `?${T_2}` : never : never}${(import("./types").ParseRoute<Routes[K]>["hash"] extends "" ? import("./types").ParseRoute<BaseRoute>["hash"] : import("./types").ParseRoute<Routes[K]>["hash"]) extends infer T_3 ? T_3 extends (import("./types").ParseRoute<Routes[K]>["hash"] extends "" ? import("./types").ParseRoute<BaseRoute>["hash"] : import("./types").ParseRoute<Routes[K]>["hash"]) ? T_3 extends "" ? T_3 : `#${T_3}` : never : never}`; }; | ||
export declare const createGroup: <GroupName extends string, BaseRoute extends string, Routes extends Record<string, string>>(name: GroupName, baseRoute: BaseRoute, routes: Readonly<Routes>) => { [K in keyof Routes as K extends string ? `${GroupName}${K}` : never]: `${import("./types").ConcatPaths<import("./types").ParseRoute<BaseRoute, (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) extends infer T ? T extends (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) ? T extends `/${string}` ? T : `/${T}` : never : never>["path"], import("./types").ParseRoute<Routes[K], (Routes[K] extends infer T_1 ? T_1 extends Routes[K] ? T_1 extends `${infer Head}#${string}` ? Head : T_1 : never : never) extends infer T_2 ? T_2 extends (Routes[K] extends infer T_3 ? T_3 extends Routes[K] ? T_3 extends `${infer Head}#${string}` ? Head : T_3 : never : never) ? T_2 extends `/${string}` ? T_2 : `/${T_2}` : never : never>["path"], import("./types").ParseRoute<BaseRoute, (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) extends infer T ? T extends (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) ? T extends `/${string}` ? T : `/${T}` : never : never>["path"] extends infer T_4 ? T_4 extends import("./types").ParseRoute<BaseRoute, (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) extends infer T ? T extends (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) ? T extends `/${string}` ? T : `/${T}` : never : never>["path"] ? T_4 extends `/${string}` ? T_4 : `/${T_4}` : never : never, import("./types").ParseRoute<Routes[K], (Routes[K] extends infer T_5 ? T_5 extends Routes[K] ? T_5 extends `${infer Head}#${string}` ? Head : T_5 : never : never) extends infer T_6 ? T_6 extends (Routes[K] extends infer T_7 ? T_7 extends Routes[K] ? T_7 extends `${infer Head}#${string}` ? Head : T_7 : never : never) ? T_6 extends `/${string}` ? T_6 : `/${T_6}` : never : never>["path"] extends infer T_8 ? T_8 extends import("./types").ParseRoute<Routes[K], (Routes[K] extends infer T_9 ? T_9 extends Routes[K] ? T_9 extends `${infer Head}#${string}` ? Head : T_9 : never : never) extends infer T_10 ? T_10 extends (Routes[K] extends infer T_11 ? T_11 extends Routes[K] ? T_11 extends `${infer Head}#${string}` ? Head : T_11 : never : never) ? T_10 extends `/${string}` ? T_10 : `/${T_10}` : never : never>["path"] ? T_8 extends `/${string}` ? T_8 : `/${T_8}` : never : never>}${import("./types").ConcatSearchs<import("./types").ParseRoute<BaseRoute, (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) extends infer T ? T extends (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) ? T extends `/${string}` ? T : `/${T}` : never : never>["search"], import("./types").ParseRoute<Routes[K], (Routes[K] extends infer T_12 ? T_12 extends Routes[K] ? T_12 extends `${infer Head}#${string}` ? Head : T_12 : never : never) extends infer T_13 ? T_13 extends (Routes[K] extends infer T_14 ? T_14 extends Routes[K] ? T_14 extends `${infer Head}#${string}` ? Head : T_14 : never : never) ? T_13 extends `/${string}` ? T_13 : `/${T_13}` : never : never>["search"]> extends infer T_15 ? T_15 extends import("./types").ConcatSearchs<import("./types").ParseRoute<BaseRoute, (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) extends infer T ? T extends (BaseRoute extends `${infer Head}#${string}` ? Head : BaseRoute) ? T extends `/${string}` ? T : `/${T}` : never : never>["search"], import("./types").ParseRoute<Routes[K], (Routes[K] extends infer T_16 ? T_16 extends Routes[K] ? T_16 extends `${infer Head}#${string}` ? Head : T_16 : never : never) extends infer T_17 ? T_17 extends (Routes[K] extends infer T_18 ? T_18 extends Routes[K] ? T_18 extends `${infer Head}#${string}` ? Head : T_18 : never : never) ? T_17 extends `/${string}` ? T_17 : `/${T_17}` : never : never>["search"]> ? T_15 extends "" ? T_15 : `?${T_15}` : never : never}`; }; |
@@ -1,9 +0,9 @@ | ||
import { GetAreaRoutes, GetCreateURLFns, GetRoutesParams, ParamsArg, ParseRoute, ParseRoutes, PrependBasePath, Simplify } from "./types"; | ||
import { GetAreaRoutes, GetCreateURLFns, GetRoutesParams, ParamsArg, ParseRoute, ParseRoutes, PrependBasePath } from "./types"; | ||
export declare const createRouter: <Routes extends Record<string, string>, BasePath extends string = "">(routes: Readonly<Routes>, options?: { | ||
basePath?: BasePath; | ||
}) => { | ||
useRoute: <RouteName extends keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>> | Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeNames: readonly RouteName[]) => RouteName extends string ? { | ||
useRoute: <RouteName extends keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>> | Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeNames: ReadonlyArray<RouteName>) => RouteName extends string ? { | ||
key: string; | ||
name: RouteName; | ||
params: Simplify<(GetRoutesParams<GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>> & GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>)[RouteName]>; | ||
params: (GetRoutesParams<GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>> & GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>)[RouteName]; | ||
} | undefined : never; | ||
@@ -13,6 +13,10 @@ getRoute: <RouteName_1 extends keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>> | Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeNames: readonly RouteName_1[]) => RouteName_1 extends string ? { | ||
name: RouteName_1; | ||
params: Simplify<(GetRoutesParams<GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>> & GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>)[RouteName_1]>; | ||
params: (GetRoutesParams<GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>> & GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>)[RouteName_1]; | ||
} | undefined : never; | ||
push: <RouteName_2 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeName: RouteName_2, ...args: ParamsArg<GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>[RouteName_2]>) => void; | ||
replace: <RouteName_3 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeName: RouteName_3, ...args: ParamsArg<GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>[RouteName_3]>) => void; | ||
push: <RouteName_2 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeName: RouteName_2, ...params: ParamsArg<GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>[RouteName_2]>) => void; | ||
replace: <RouteName_3 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>(routeName: RouteName_3, ...params: ParamsArg<GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>[RouteName_3]>) => void; | ||
P: { [RouteName_4 in keyof Routes]: <const Params>(params: Params) => { | ||
readonly name: RouteName_4; | ||
readonly params: Params; | ||
}; }; | ||
} & GetCreateURLFns<GetRoutesParams<Omit<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>, keyof GetAreaRoutes<PrependBasePath<ParseRoute<BasePath>["path"], ParseRoutes<Routes>>>>>>; |
@@ -0,6 +1,11 @@ | ||
import { Params } from "./types"; | ||
export declare const first: <T>(value: T[]) => T | undefined; | ||
export declare const last: <T>(value: T[]) => T | undefined; | ||
export declare const identity: <T>(value: T) => T; | ||
export declare const noop: () => void; | ||
export declare const isNonEmpty: (value: string) => boolean; | ||
export declare const isParam: (value: string) => boolean; | ||
export declare const ensureSlashPrefix: (value: string) => string; | ||
export declare const areParamsArrayEqual: (arrayA: string[], arrayB: string[]) => boolean; | ||
export declare const getRouteKey: (name: string, pathParams: Params, searchParams: Params) => string; | ||
export declare const areRouteEqual: (routeA?: { | ||
@@ -11,2 +16,5 @@ key: string; | ||
}) => boolean; | ||
export declare const isMultipleParam: (value: string) => boolean; | ||
export declare const extractParamNameUnion: (paramName: string) => { | ||
name: string; | ||
union?: string[]; | ||
}; |
@@ -1,12 +0,37 @@ | ||
import * as React from "react"; | ||
import { Location, Subscription } from "./types"; | ||
export declare const history: import("history").BrowserHistory; | ||
export declare const subscribeToLocation: (subscription: Subscription) => (() => void); | ||
export declare const getLocation: () => Location; | ||
export declare const hasInitialLocationChanged: () => boolean; | ||
export declare const GetUniversalLocationProvider: React.Provider<() => Location>; | ||
/// <reference types="react" /> | ||
import { Blocker, Listener, Location, RouteObject, Search } from "./types"; | ||
export declare const parseRoute: (route: string) => RouteObject; | ||
export declare const decodeLocation: (url: string) => Location; | ||
export declare const createBrowserHistory: () => { | ||
readonly location: Readonly<{ | ||
path: readonly string[]; | ||
search: Readonly<Search>; | ||
raw: Readonly<{ | ||
path: string; | ||
search: string; | ||
}>; | ||
toString(): string; | ||
}>; | ||
subscribe: (listener: Listener) => (() => void); | ||
push: (url: string) => void; | ||
replace: (url: string) => void; | ||
block: (blocker: Blocker) => (() => void); | ||
}; | ||
export declare const getLocation: () => Readonly<{ | ||
path: readonly string[]; | ||
search: Readonly<Search>; | ||
raw: Readonly<{ | ||
path: string; | ||
search: string; | ||
}>; | ||
toString(): string; | ||
}>; | ||
export declare const subscribeToLocation: (listener: Listener) => (() => void); | ||
export declare const pushUnsafe: (url: string) => void; | ||
export declare const replaceUnsafe: (url: string) => void; | ||
export declare const block: (blocker: Blocker) => (() => void); | ||
export declare const GetUniversalLocationProvider: import("react").Provider<() => Location>; | ||
export declare const useGetUniversalLocation: () => () => Location; | ||
export declare const useLocation: () => Location; | ||
export declare const pushUnsafe: (url: string) => void; | ||
export declare const replaceUnsafe: (url: string) => void; | ||
export declare const resetInitialHasLocationChanged: () => void; | ||
export declare const hasInitialLocationChanged: () => boolean; | ||
export declare const setInitialHasLocationChanged: (value: boolean) => void; |
@@ -8,4 +8,4 @@ export { Link } from "./Link"; | ||
export type { Location, Search } from "./types"; | ||
export { useBlocker } from "./useBlocker"; | ||
export { useFocusReset } from "./useFocusReset"; | ||
export { useLinkProps } from "./useLinkProps"; | ||
export { useNavigationBlocker } from "./useNavigationBlocker"; |
@@ -1,2 +0,2 @@ | ||
var e=require("react"),r=require("history"),t=require("use-sync-external-store/shim/index.js"),n=require("@emotion/hash"),a=require("use-sync-external-store/shim/with-selector.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var u=/*#__PURE__*/i(e),c=/*#__PURE__*/o(n);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},s.apply(this,arguments)}function l(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function h(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return l(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?l(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f=function(e){return e[0]},p=function(e){return e},v=function(e){return""!==e},d=function(e){return e.startsWith(":")},y=function(e,r){return e.length===r.length&&e.every(function(e,t){return e===r[t]})},m=function(e,r){return(null==e?void 0:e.key)===(null==r?void 0:r.key)},g=function(e){for(var r,t={},n=h(new URLSearchParams(e));!(r=n()).done;){var a=r.value,o=a[0],i=a[1],u=t[o];t[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return t},b=function(e,r,t){var n=e+(""!==e?"&":"")+encodeURIComponent(r);return""!==t?n+"="+encodeURIComponent(t):n},w=function(e){var r=Object.keys(e);if(0===r.length)return"";var t="";r.sort();for(var n=0,a=r;n<a.length;n++){var o=a[n],i=e[o];if(null!=i)if("string"==typeof i)t=b(t,o,i);else for(var u,c=h(i);!(u=c()).done;)t=b(t,o,u.value)}return""===t?"":"?"+t},S=function(e,r){var t=e.search,n=e.hash,a=e.pathname.substring(1),o=""!==a?r?a.split("/").filter(v).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],i=""!==t?g(t):{},u=""!==n?decodeURIComponent(n.substring(1)):null,l="/"+o.map(encodeURIComponent).join("/"),h=w(i),f=null!=u?"#"+encodeURIComponent(u):"",p=l+h+f;return s({key:c.default(l)+"-"+c.default(h+f),path:o,search:i},null!==u&&{hash:u},{raw:{path:l,search:h,hash:f},toString:function(){return p}})},k=new Set,O="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?r.createBrowserHistory():r.createMemoryHistory(),x=S(O.location,!0),P=!1;O.listen(function(e){var r=S(e.location,!1);if(r.toString()!==x.toString()){P=!0;var t=r.raw.search!==x.raw.search,n=t?{}:x.search;if(t)for(var a in r.search)if(Object.prototype.hasOwnProperty.call(r.search,a)){var o=r.search[a];if(null==o)continue;var i=x.search[a];n[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&y(o,i)?i:o}x=s({key:r.key,path:r.raw.path!==x.raw.path?r.path:x.path,search:n},null!=r.hash&&{hash:r.hash},{raw:r.raw,toString:r.toString}),k.forEach(function(e){return e(x)})}});var j=function(e){return k.add(e),function(){k.delete(e)}},C=function(){return x},R=u.createContext(C),U=R.Provider,I=function(){return u.useContext(R)},E=function(e){var t=r.parsePath(e),n=t.pathname,a=t.search,o=t.hash;O.push({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},A=function(e){var t=r.parsePath(e),n=t.pathname,a=t.search,o=t.hash;O.replace({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},N=function(e){var n=e.href,a=e.replace,o=void 0!==a&&a,i=e.target,c=u.useMemo(function(){return r.parsePath(n).pathname},[n]),s=I(),l=function(){return c===s().raw.path},h=t.useSyncExternalStore(j,l,l),f=o||h,p=null==i||"_self"===i;return{active:h,onClick:u.useCallback(function(e){e.defaultPrevented||!p||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),f?A(n):E(n))},[f,p,n])}},L=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],q=u.forwardRef(function(e,r){var t=e.onClick,n=e.className,a=e.replace,o=e.style,i=e.target,c=e.to,l=e.activeClassName,h=e.activeStyle,f=function(e,r){if(null==e)return{};var t,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r.indexOf(t=o[n])>=0||(a[t]=e[t]);return a}(e,L),p=N({href:c,replace:a,target:i}),v=p.active,d=p.onClick;return u.createElement("a",s({},f,{ref:r,href:c,onClick:function(e){null==t||t(e),d(e)},target:i,className:v&&null!=l?null==n?l:n+" "+l:n,style:v&&null!=h?null==o?h:s({},o,h):o}))});q.displayName="Link";var T=function(e,r){return""===e?e:r+e},M=function(e){return"/"===e[0]?e:"/"+e},W=function(e){var t=r.parsePath(e),n=t.pathname,a=t.search,o=t.hash,i=void 0===o?"":o;return{path:void 0===n?"":n,search:(void 0===a?"":a).substring(1),hash:i.substring(1)}},K=function(e,r){var t=M(e.path),n=M(r.path),a="/"===t?n:"/"===n?t:t+n,o=""===e.search?r.search:e.search+T(r.search,"&"),i=""===r.hash?e.hash:r.hash;return a+T(o,"?")+T(i,"#")},_=function(e,t){var n,a=r.parsePath(t),o=a.pathname,i=void 0===o?"/":o,u=a.search,c=a.hash,s=i.endsWith("/*"),l=function(e){for(var r,t=e.split("/").filter(v),n=[],a=t.length>0?4*t.length:5,o=h(t);!(r=o()).done;){var i=r.value,u=d(i);a+=u?2:3,n.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:n}}(s?i.slice(0,-2):i),f=l.ranking,p={isArea:s,name:e,ranking:s?f-1:f,path:l.path,search:void 0,hash:void 0};if(null!=u){p.search={};for(var y,m=h(new URLSearchParams(u.substring(1)));!(y=m()).done;){var g=y.value[0];(n=g).startsWith(":")&&n.endsWith("[]")?p.search[g.substring(1,g.length-2)]="multiple":d(g)&&(p.search[g.substring(1,g.length)]="unique")}}return null!=c&&d(c.substring(1))&&(p.hash=c.substring(2)),p},B=function(e,r){var t=e.path,n=r.isArea,a=r.path;if(!(!n&&t.length!==a.length||n&&t.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=t[i],c=a[i];if(null!=c)if("string"==typeof c){if(c!==u)return}else{if(null==u)return;o[c.name]=u}}for(var s in r.search)if(Object.prototype.hasOwnProperty.call(r.search,s)){var l=r.search[s],h=e.search[s];if(null==l||null==h)continue;if("multiple"===l){o[s]="string"==typeof h?[h]:h;continue}"string"==typeof h?o[s]=h:null!=h[0]&&(o[s]=h[0])}return null!=r.hash&&null!=e.hash&&(o[r.hash]=e.hash),o}},D=function(e,r){for(var t,n=h(r);!(t=n()).done;){var a=t.value,o=B(e,a);if(null!=o)return{key:e.key,name:a.name,params:o}}},H=function(e,r){void 0===r&&(r={});var t="/"+e.path.map(function(e){return encodeURIComponent("string"==typeof e?e:String(r[e.name]))}).join("/"),n="",a="";if(null!=e.search){var o={};for(var i in r){var u=r[i];Object.prototype.hasOwnProperty.call(r,i)&&Object.prototype.hasOwnProperty.call(e.search,i)&&null!=u&&(o[i]=u)}n=w(o)}if(null!=e.hash){var c=r[e.hash];"string"==typeof c&&(a="#"+encodeURIComponent(c))}return{pathname:t,search:n,hash:a}},F={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0};exports.Link=q,exports.ServerUrlProvider=function(e){var t=e.children,n=r.parsePath(e.value),a=n.pathname,o=n.search,i=n.hash,c=S({pathname:void 0===a?"/":a,search:void 0===o?"":o,hash:void 0===i?"":i},!1);return u.createElement(U,{children:t,value:function(){return c}})},exports.createGroup=function(e,r,t){var n=W(r),a={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(a[e+o]=K(n,W(t[o])));return a},exports.createRouter=function(e,t){void 0===t&&(t={});var n=t.basePath,o=void 0===n?"":n,i={path:W(o).path,search:"",hash:""},c={},l=[];for(var h in e)if(Object.prototype.hasOwnProperty.call(e,h)){var v=_(h,""!==o?K(i,W(e[h])):e[h]);c[h]=v,l.push(v)}l.sort(function(e,r){return r.ranking-e.ranking});for(var d={},y=function(){var e=l[g];if(null!=e&&!e.isArea){var t=e.name;d[t]=function(e){return r.createPath(H(c[t],e))}}},g=0;g<l.length;g++)y();return s({useRoute:function(e){var r=JSON.stringify(e),t=u.useMemo(function(){return l.filter(function(r){return e.includes(r.name)})},[r]),n=I(),o=function(){return D(n(),t)};return a.useSyncExternalStoreWithSelector(j,o,o,p,m)},getRoute:function(e){var r=C(),t=l.filter(function(r){return e.includes(r.name)});return D(r,t)},push:function(e){return O.push(H(c[e],f([].slice.call(arguments,1))))},replace:function(e){return O.replace(H(c[e],f([].slice.call(arguments,1))))}},d)},exports.decodeSearch=g,exports.encodeSearch=w,exports.getLocation=C,exports.pushUnsafe=E,exports.replaceUnsafe=A,exports.subscribeToLocation=j,exports.useFocusReset=function(e){var r=e.route,t=e.containerRef,n=null==r?void 0:r.key.split("-")[0];u.useEffect(function(){var e=t.current;if(e&&P)try{null!=e.getAttribute("tabIndex")||F[e.nodeName]||e.setAttribute("tabIndex","-1"),e.focus()}catch(e){}},[t,n])},exports.useLinkProps=N,exports.useLocation=function(){var e=I();return t.useSyncExternalStore(j,e,e)},exports.useNavigationBlocker=function(e,r){u.useEffect(function(){if(e){var t=O.block(function(e){window.confirm(r)&&(t(),e.retry())});return t}},[e])}; | ||
var e=require("react"),t=require("@emotion/hash"),n=require("use-sync-external-store/shim/with-selector.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/r(t);const s=e=>e[0],c=e=>e[e.length-1],l=e=>e,a=()=>{},i=e=>""!==e,u=e=>e.startsWith(":"),p=e=>"/"===e[0]?e:"/"+e,h=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),f=e=>{const t=Object.keys(e);return t.length>0?JSON.stringify(t.sort().map(t=>[t,e[t]])):""},d=(e,t,n)=>{const r=e+f(t),s=f(n);return o.default(r)+"-"+o.default(s)},g=(e,t)=>(null==e?void 0:e.key)===(null==t?void 0:t.key),m=e=>{const t=e.indexOf("{");return t>-1&&e.endsWith("}")?{name:e.substring(0,t),union:e.substring(t+1,e.length-1).split("|").filter(i)}:{name:e}},y=e=>{const t=e.split("&").filter(i),n={};for(const e of t){const[t="",r=""]=e.split("="),o=decodeURIComponent(t),s=decodeURIComponent(r),c=n[o];n[o]=null!=c?"string"==typeof c?[c,s]:c.concat(s):s}return n},b=(e,t,n)=>{const r=e+(""!==e?"&":"")+encodeURIComponent(t);return""!==n?r+"="+encodeURIComponent(n):r},w=e=>{const t=Object.keys(e);if(0===t.length)return"";let n="";t.sort();for(const r of t){const t=e[r];if(null!=t)if("string"==typeof t)n=b(n,r,t);else for(const e of t)n=b(n,r,e)}return""===n?"":"?"+n};let v=!1;const x=e=>{const t=e.indexOf("#"),n=p(t<0?e:e.substring(0,t)),r=n.indexOf("?");return r<0?{path:n,search:""}:{path:n.substring(0,r),search:n.substring(r+1)}},S=e=>{const t=x(e),n=t.path.substring(1),r=""!==n?v?n.split("/").map(decodeURIComponent):n.split("/").filter(i).map(decodeURIComponent):[],o=""!==t.search?y(t.search):{},s="/"+r.map(encodeURIComponent).join("/"),c=w(o),l=s+c;return{path:r,search:o,raw:{path:s,search:c},toString:()=>l}},k=e=>{e.preventDefault(),e.returnValue=""},C="undefined"!=typeof window?(()=>{const e=new Set;let t=[];const n=window.history,r=window.location;let o=S(r.pathname+r.search);const s=t=>{if(t.toString()===o.toString())return;v=!0;const n=t.raw.search!==o.raw.search,r=n?{}:o.search;if(n)for(const e in t.search)if(Object.prototype.hasOwnProperty.call(t.search,e)){const n=t.search[e];if(null==n)continue;const s=o.search[e];r[e]=null!=s&&"string"!=typeof s&&"string"!=typeof n&&h(n,s)?s:n}o={path:t.raw.path!==o.raw.path?t.path:o.path,search:r,raw:t.raw,toString:t.toString},e.forEach(e=>e(o))};return window.addEventListener("popstate",()=>{s(S(r.pathname+r.search))}),{get location(){return o},subscribe:t=>(e.add(t),()=>{e.delete(t)}),push:e=>{const o=c(t);if(null==o||window.confirm(o.message)){const t=S(e),o=t.toString();try{n.pushState(null,"",o)}catch{r.assign(o)}s(t)}},replace:e=>{const r=c(t);if(null==r||window.confirm(r.message)){const t=S(e),r=t.toString();n.replaceState(null,"",r),s(t)}},block:e=>(t.push(e),1===t.length&&window.addEventListener("beforeunload",k,{capture:!0}),()=>{t=t.filter(t=>{let{id:n}=t;return n!==e.id}),0===t.length&&window.removeEventListener("beforeunload",k,{capture:!0})})}})():{location:S("/"),subscribe:()=>a,push:a,replace:a,block:()=>a},R=()=>C.location,E=C.subscribe,O=C.push,I=C.replace,U=C.block,P=e.createContext(R),j=P.Provider,L=()=>e.useContext(P),A=t=>{let{href:n,replace:r=!1,target:o}=t;const s=e.useMemo(()=>x(n).path,[n]),c=L(),l=()=>s===c().raw.path,a=e.useSyncExternalStore(E,l,l),i=r||a,u=null==o||"_self"===o;return{active:a,onClick:e.useCallback(e=>{e.defaultPrevented||!u||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),i?I(n):O(n))},[i,u,n])}},N=e.forwardRef((t,n)=>{let{onClick:r,className:o,replace:s,style:c,target:l,to:a,activeClassName:i,activeStyle:u,...p}=t;const{active:h,onClick:f}=A({href:a,replace:s,target:l});return e.createElement("a",{...p,ref:n,href:a,onClick:e=>{null==r||r(e),f(e)},target:l,className:h&&null!=i?null==o?i:o+" "+i:o,style:h&&null!=u?null==c?u:{...c,...u}:c})});N.displayName="Link";const T=(e,t)=>""===e?e:t+e,W=(e,t)=>{const n=p(e.path),r=p(t.path),o="/"===n?r:"/"===r?n:n+r,s=""===e.search?t.search:e.search+T(t.search,"&");return o+T(s,"?")},K=(e,t)=>{const n=x(t),r=n.path.endsWith("/*"),{ranking:o,path:s}=(e=>{const t=e.split("/").filter(i),n=[];let r=t.length>0?5*t.length:6;for(const e of t)if(u(e)){const t=m(e.substring(1));r+=null==t.union?2:3,n.push(t)}else r+=4,n.push(encodeURIComponent(e));return{ranking:r,path:n}})(r?n.path.slice(0,-2):n.path),c={isArea:r,name:e,ranking:r?o-1:o,path:s,search:void 0};if(""!==n.search){c.search={};const e=y(n.search);for(const t in e)if(u(t)){const e=t.endsWith("[]"),{name:n,union:r}=m(t.substring(1,t.length-(e?2:0)));c.search[n]=null==r?{multiple:e}:{multiple:e,union:r}}}return c},q=(e,t)=>{const{path:n}=e,{isArea:r,path:o}=t;if(!r&&n.length!==o.length||r&&n.length<o.length)return;const s={};for(let e=0;e<o.length;e++){const t=n[e],r=o[e];if(null==r)continue;if("string"==typeof r){if(t===r)continue;return}if(null==t)return;const{name:c,union:l}=r;if(null!=l&&!l.includes(t))return;s[c]=t}const c={};for(const n in t.search)if(Object.prototype.hasOwnProperty.call(t.search,n)){const r=t.search[n],o=e.search[n];if(null==r||null==o)continue;const{multiple:s,union:l}=r,a="string"==typeof o?[o]:o,i=null==l?a:a.filter(e=>l.includes(e));if(s){c[n]=i;continue}const u=i[0];null==u||null!=l&&!l.includes(u)||(c[n]=u)}return{key:d(t.name,s,c),name:t.name,params:{...s,...c}}},D=(e,t)=>{for(const n of t){const t=q(e,n);if(null!=t)return t}},J=function(e,t){void 0===t&&(t={});const n="/"+e.path.map(e=>encodeURIComponent("string"==typeof e?e:String(t[e.name]))).join("/");let r="";if(null!=e.search){const n={};for(const r in t){const o=e.search[r],s=t[r];if(null!=o&&null!=s){const{union:e}=o;"string"==typeof s?(null==e||e.includes(s))&&(n[r]=s):n[r]=null==e?s:s.filter(t=>e.includes(t))}}r=w(n)}return n+r},M={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0};exports.Link=N,exports.ServerUrlProvider=t=>{let{children:n,value:r}=t;const o=S(r);return e.createElement(j,{children:n,value:()=>o})},exports.createGroup=(e,t,n)=>{const r=x(t),o={};for(const t in n)Object.prototype.hasOwnProperty.call(n,t)&&(o[e+t]=W(r,x(n[t])));return o},exports.createRouter=function(t,r){void 0===r&&(r={});const{basePath:o=""}=r,c={path:x(o).path,search:""},a={},i=[];for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const n=K(e,""!==o?W(c,x(t[e])):t[e]);a[e]=n,i.push(n)}i.sort((e,t)=>t.ranking-e.ranking);const u={},p={};for(const e of i){const t=e.name;if(u[t]=e=>({name:t,params:e}),!e.isArea){const e=t;p[e]=t=>J(a[e],t)}}return{useRoute:t=>{const r=JSON.stringify(t),o=e.useMemo(()=>i.filter(e=>{let{name:n}=e;return t.includes(n)}),[r]),s=L(),c=()=>D(s(),o);return n.useSyncExternalStoreWithSelector(E,c,c,l,g)},getRoute:e=>{const t=R(),n=i.filter(t=>{let{name:n}=t;return e.includes(n)});return D(t,n)},push:function(e){return O(J(a[e],s([].slice.call(arguments,1))))},replace:function(e){return I(J(a[e],s([].slice.call(arguments,1))))},P:u,...p}},exports.decodeSearch=e=>y("?"===e[0]?e.substring(1):e),exports.encodeSearch=w,exports.getLocation=R,exports.pushUnsafe=O,exports.replaceUnsafe=I,exports.subscribeToLocation=E,exports.useBlocker=(t,n)=>{const r=e.useId();e.useEffect(()=>{if(t)return U({id:r,message:n})})},exports.useFocusReset=t=>{let{route:n,containerRef:r}=t;const o=null==n?void 0:n.key.split("-")[0];e.useEffect(()=>{const e=r.current;if(null!=e&&v)try{null!=e.getAttribute("tabIndex")||M[e.nodeName]||e.setAttribute("tabIndex","-1"),e.focus()}catch{}},[r,o])},exports.useLinkProps=A,exports.useLocation=()=>{const t=L();return e.useSyncExternalStore(E,t,t)}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,4 @@ | ||
import * as React from "react"; | ||
/// <reference types="react" /> | ||
type BaseProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href">; | ||
export declare const Link: React.ForwardRefExoticComponent<BaseProps & { | ||
export declare const Link: import("react").ForwardRefExoticComponent<BaseProps & { | ||
to: string; | ||
@@ -9,3 +9,3 @@ children?: React.ReactNode; | ||
activeClassName?: BaseProps["className"]; | ||
} & React.RefAttributes<HTMLAnchorElement>>; | ||
} & import("react").RefAttributes<HTMLAnchorElement>>; | ||
export {}; |
@@ -1,5 +0,8 @@ | ||
import { Path as HistoryPath } from "history"; | ||
import { Location, Matcher, Params } from "./types"; | ||
export declare const getMatcher: (name: string, route: string) => Matcher; | ||
export declare const extractLocationParams: (location: Location, matcher: Matcher) => Params | undefined; | ||
export declare const getMatchResult: (location: Location, matcher: Matcher) => { | ||
key: string; | ||
name: string; | ||
params: Params; | ||
} | undefined; | ||
export declare const match: (location: Location, matchers: Matcher[]) => { | ||
@@ -10,2 +13,2 @@ key: string; | ||
} | undefined; | ||
export declare const matchToHistoryPath: (matcher: Matcher, params?: Params) => HistoryPath; | ||
export declare const matchToUrl: (matcher: Matcher, params?: Params) => string; |
import { Search } from "./types"; | ||
export declare const decodeUnprefixedSearch: (search: string) => Search; | ||
export declare const decodeSearch: (search: string) => Search; | ||
export declare const appendParam: (acc: string, key: string, value: string) => string; | ||
export declare const encodeSearch: (search: Search) => string; |
@@ -1,2 +0,2 @@ | ||
import * as React from "react"; | ||
/// <reference types="react" /> | ||
type Props = { | ||
@@ -6,11 +6,8 @@ children: React.ReactNode; | ||
}; | ||
export declare const ServerUrlProvider: ({ children, value }: Props) => React.FunctionComponentElement<React.ProviderProps<() => Readonly<{ | ||
key: string; | ||
export declare const ServerUrlProvider: ({ children, value }: Props) => import("react").FunctionComponentElement<import("react").ProviderProps<() => Readonly<{ | ||
path: readonly string[]; | ||
search: Readonly<import("./types").Search>; | ||
hash?: string; | ||
raw: Readonly<{ | ||
path: string; | ||
search: string; | ||
hash: string; | ||
}>; | ||
@@ -17,0 +14,0 @@ toString(): string; |
@@ -0,4 +1,8 @@ | ||
export type Params = Record<string, string | string[] | undefined>; | ||
export type Search = Record<string, string | string[]>; | ||
export type Params = Record<string, string | string[] | undefined>; | ||
export type Subscription = (location: Location) => void; | ||
export type Listener = (location: Location) => void; | ||
export type Blocker = { | ||
id: string; | ||
message: string; | ||
}; | ||
export type Matcher = { | ||
@@ -10,20 +14,19 @@ isArea: boolean; | ||
name: string; | ||
union?: string[]; | ||
})[]; | ||
search: Record<string, "unique" | "multiple"> | undefined; | ||
hash: string | undefined; | ||
search: Record<string, { | ||
multiple: boolean; | ||
union?: string[]; | ||
}> | undefined; | ||
}; | ||
export type ParsedRoute = Readonly<{ | ||
export type RouteObject = Readonly<{ | ||
path: string; | ||
search: string; | ||
hash: string; | ||
}>; | ||
export type Location = Readonly<{ | ||
key: string; | ||
path: readonly string[]; | ||
search: Readonly<Search>; | ||
hash?: string; | ||
raw: Readonly<{ | ||
path: string; | ||
search: string; | ||
hash: string; | ||
}>; | ||
@@ -33,29 +36,18 @@ toString(): string; | ||
export type NonEmptySplit<Value extends string, Separator extends string> = Value extends `${infer Head}${Separator}${infer Tail}` ? Head extends "" ? NonEmptySplit<Tail, Separator> : [Head, ...NonEmptySplit<Tail, Separator>] : Value extends "" ? [] : [Value]; | ||
export type GetPathParams<Path extends string, Parts = NonEmptySplit<Path, "/">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}` ? { | ||
[K in Name]: string; | ||
} & GetPathParams<Path, Tail> : GetPathParams<Path, Tail> : {}; | ||
export type GetSearchParams<Search extends string, Parts = NonEmptySplit<Search, "&">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}[]` ? { | ||
[K in Name]?: string[] | undefined; | ||
} & GetSearchParams<Search, Tail> : Head extends `:${infer Name}` ? { | ||
[K in Name]?: string | undefined; | ||
} & GetSearchParams<Search, Tail> : GetSearchParams<Search, Tail> : {}; | ||
export type GetHashParams<Value extends string> = Value extends `:${infer Name}` ? { | ||
[K in Name]?: string | undefined; | ||
} : {}; | ||
export type ParseRoute<Route extends string> = Route extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
export type PartialRecord<K extends string, T> = { | ||
[P in K]?: T | undefined; | ||
}; | ||
export type ExtractUnion<Union extends string> = NonEmptySplit<Union, "|">[number]; | ||
export type ExtractRequiredParam<Value extends string> = Value extends `${infer Name}{${infer Union}}` ? Record<Name, ExtractUnion<Union>> : Record<Value, string>; | ||
export type ExtractOptionalMultipleParam<Value extends string> = Value extends `${infer Name}{${infer Union}}` ? PartialRecord<Name, ExtractUnion<Union>[]> : PartialRecord<Value, string[]>; | ||
export type ExtractOptionalParam<Value extends string> = Value extends `${infer Name}{${infer Union}}` ? PartialRecord<Name, ExtractUnion<Union>> : PartialRecord<Value, string>; | ||
export type GetPathParams<Path extends string, Parts = NonEmptySplit<Path, "/">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}` ? ExtractRequiredParam<Name> & GetPathParams<Path, Tail> : GetPathParams<Path, Tail> : {}; | ||
export type GetSearchParams<Search extends string, Parts = NonEmptySplit<Search, "&">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}[]` ? ExtractOptionalMultipleParam<Name> & GetSearchParams<Search, Tail> : Head extends `:${infer Name}` ? ExtractOptionalParam<Name> & GetSearchParams<Search, Tail> : GetSearchParams<Search, Tail> : {}; | ||
type EnsureSlashPrefix<Value extends string> = Value extends `/${string}` ? Value : `/${Value}`; | ||
export type ParseRoute<Route extends string, CleanRoute = EnsureSlashPrefix<Route extends `${infer Head}#${string}` ? Head : Route>> = CleanRoute extends `${infer Path}?${infer Search}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Route extends `${infer Path}?${infer Search}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: ""; | ||
} : Route extends `${infer Path}#${infer Hash}` ? { | ||
path: Path; | ||
search: ""; | ||
hash: Hash; | ||
} : { | ||
path: Route; | ||
path: CleanRoute; | ||
search: ""; | ||
hash: ""; | ||
}; | ||
@@ -66,36 +58,27 @@ export type ParseRoutes<Routes extends Record<string, string>> = { | ||
type AddPrefixOnNonEmpty<Value extends string, Prefix extends string> = Value extends "" ? Value : `${Prefix}${Value}`; | ||
type EnsureSlashPrefix<Value extends string> = Value extends `/${string}` ? Value : `/${Value}`; | ||
export type ConcatPaths<PathA extends string, PathB extends string, FixedPathA extends string = EnsureSlashPrefix<PathA>, FixedPathB extends string = EnsureSlashPrefix<PathB>> = FixedPathA extends "/" ? FixedPathB : FixedPathB extends "/" ? FixedPathA : `${FixedPathA}${FixedPathB}`; | ||
export type ConcatSearchs<SearchA extends string, SearchB extends string> = SearchA extends "" ? SearchB : `${SearchA}${AddPrefixOnNonEmpty<SearchB, "&">}`; | ||
export type ConcatParsedRoutes<RouteA extends ParsedRoute, RouteB extends ParsedRoute> = { | ||
path: ConcatPaths<RouteA["path"], RouteB["path"]>; | ||
search: ConcatSearchs<RouteA["search"], RouteB["search"]>; | ||
hash: RouteB["hash"] extends "" ? RouteA["hash"] : RouteB["hash"]; | ||
}; | ||
export type ConcatRoutes<RouteA extends string, RouteB extends string, Route extends ParsedRoute = ConcatParsedRoutes<ParseRoute<RouteA>, ParseRoute<RouteB>>> = `${Route["path"]}${AddPrefixOnNonEmpty<Route["search"], "?">}${AddPrefixOnNonEmpty<Route["hash"], "#">}`; | ||
export type PrependBasePath<BasePath extends string, Routes extends Record<string, ParsedRoute>> = { | ||
export type ConcatRoutes<RouteA extends string, RouteB extends string, RouteObjectA extends RouteObject = ParseRoute<RouteA>, RouteObjectB extends RouteObject = ParseRoute<RouteB>, Path extends string = ConcatPaths<RouteObjectA["path"], RouteObjectB["path"]>, Search extends string = ConcatSearchs<RouteObjectA["search"], RouteObjectB["search"]>> = `${Path}${AddPrefixOnNonEmpty<Search, "?">}`; | ||
export type PrependBasePath<BasePath extends string, Routes extends Record<string, RouteObject>> = { | ||
[K in keyof Routes]: { | ||
path: ConcatPaths<BasePath, Routes[K]["path"]>; | ||
search: Routes[K]["search"]; | ||
hash: Routes[K]["hash"]; | ||
}; | ||
}; | ||
export type GetAreaRoutes<Routes extends Record<string, ParsedRoute>> = { | ||
export type GetAreaRoutes<Routes extends Record<string, RouteObject>> = { | ||
[K in keyof Routes as Routes[K]["path"] extends `${string}/*` ? K : never]: Routes[K]["path"] extends `${infer Rest}/*` ? { | ||
path: Rest; | ||
search: Routes[K]["search"]; | ||
hash: Routes[K]["hash"]; | ||
} : never; | ||
}; | ||
export type GetRoutesParams<Routes extends Record<string, ParsedRoute>> = { | ||
[K in keyof Routes]: GetPathParams<Routes[K]["path"]> & GetSearchParams<Routes[K]["search"]> & GetHashParams<Routes[K]["hash"]>; | ||
}; | ||
type EmptyRecord = Record<string | number | symbol, never>; | ||
export type Simplify<T> = T extends EmptyRecord ? {} : { | ||
type SimplifyParams<T> = T extends Record<PropertyKey, never> ? {} : { | ||
[K in keyof T]: T[K]; | ||
}; | ||
export type GetRoutesParams<Routes extends Record<string, RouteObject>> = { | ||
[K in keyof Routes]: SimplifyParams<GetPathParams<Routes[K]["path"]> & GetSearchParams<Routes[K]["search"]>>; | ||
}; | ||
type NonOptionalProperties<T> = Exclude<{ | ||
[K in keyof T]: T extends Record<K, T[K]> ? K : never; | ||
}[keyof T], undefined>; | ||
export type ParamsArg<Params> = Params extends EmptyRecord ? [] : NonOptionalProperties<Params> extends never ? [params?: { | ||
export type ParamsArg<Params> = Params extends Record<PropertyKey, never> ? [] : NonOptionalProperties<Params> extends never ? [params?: { | ||
[K in keyof Params]: Params[K]; | ||
@@ -105,5 +88,5 @@ }] : [params: { | ||
}]; | ||
export type GetCreateURLFns<RouteParams extends Record<string, Params>> = { | ||
[RouteName in keyof RouteParams]: (...args: ParamsArg<RouteParams[RouteName]>) => string; | ||
export type GetCreateURLFns<RoutesParams extends Record<string, Params>> = { | ||
[RouteName in keyof RoutesParams]: (...params: ParamsArg<RoutesParams[RouteName]>) => string; | ||
}; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import * as React from "react"; | ||
import { RefObject } from "react"; | ||
import { Params } from "./types"; | ||
@@ -9,3 +9,3 @@ export declare const useFocusReset: ({ route, containerRef, }: { | ||
} | undefined; | ||
containerRef: React.RefObject<unknown>; | ||
containerRef: RefObject<unknown>; | ||
}) => void; |
@@ -1,2 +0,1 @@ | ||
import * as React from "react"; | ||
export declare const useLinkProps: ({ href, replace, target, }: { | ||
@@ -3,0 +2,0 @@ href: string; |
{ | ||
"name": "@swan-io/chicane", | ||
"version": "1.4.1", | ||
"version": "2.0.0-rc.0", | ||
"license": "MIT", | ||
@@ -30,6 +30,4 @@ "description": "A simple and safe router for React and TypeScript", | ||
"scripts": { | ||
"build": "yarn clean && microbundle -f cjs,es", | ||
"clean": "rm -rf dist", | ||
"dev": "microbundle watch", | ||
"format": "prettier '**/*' -u -w", | ||
"format": "prettier '**/*' --ignore-unknown --write", | ||
"lint": "eslint --ext ts,tsx ./src", | ||
@@ -39,2 +37,3 @@ "test": "vitest --run", | ||
"typecheck": "tsc --noEmit", | ||
"build": "yarn clean && microbundle -f cjs,es --tsconfig tsconfig.build.json", | ||
"prepack": "yarn typecheck && yarn lint && yarn test && yarn build" | ||
@@ -48,30 +47,32 @@ }, | ||
"prettier": { | ||
"trailingComma": "all" | ||
"trailingComma": "all", | ||
"plugins": [ | ||
"prettier-plugin-organize-imports" | ||
] | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16.8.0" | ||
"react": ">=18.0.0" | ||
}, | ||
"dependencies": { | ||
"@emotion/hash": "^0.9.1", | ||
"history": "^5.3.0", | ||
"use-sync-external-store": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react": "^12.1.5", | ||
"@types/react": "^17.0.62", | ||
"@types/react-dom": "^17.0.20", | ||
"@types/use-sync-external-store": "^0.0.3", | ||
"@typescript-eslint/eslint-plugin": "^5.60.1", | ||
"@typescript-eslint/parser": "^5.60.1", | ||
"eslint": "^8.43.0", | ||
"@testing-library/react": "^14.2.1", | ||
"@types/react": "^18.2.64", | ||
"@types/react-dom": "^18.2.21", | ||
"@types/use-sync-external-store": "^0.0.6", | ||
"@typescript-eslint/eslint-plugin": "^7.1.1", | ||
"@typescript-eslint/parser": "^7.1.1", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"jsdom": "^22.1.0", | ||
"jsdom": "^24.0.0", | ||
"microbundle": "^0.15.1", | ||
"prettier": "^2.8.8", | ||
"prettier-plugin-organize-imports": "^3.2.2", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"typescript": "^5.1.3", | ||
"vitest": "^0.32.2" | ||
"prettier": "^3.2.5", | ||
"prettier-plugin-organize-imports": "^3.2.4", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^5.4.2", | ||
"vitest": "^1.3.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
118766
3
321
21
2
1
- Removedhistory@^5.3.0
- Removed@babel/runtime@7.26.0(transitive)
- Removedhistory@5.3.0(transitive)
- Removedregenerator-runtime@0.14.1(transitive)