@renr/parcel-rsc-router 1.0.0-alpha.8 → 1.0.0-alpha.9

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.
@@ -1,16 +1,7 @@
1
1
  import { RoutePath } from "./types.mjs";
2
2
  import React, { HTMLAttributeAnchorTarget } from "react";
3
-
4
3
  //#region src/Link.d.ts
5
- declare function Link({
6
- to,
7
- children,
8
- hash,
9
- target,
10
- search,
11
- onClick,
12
- ...props
13
- }: {
4
+ export declare function Link({ to, children, hash, target, search, onClick, ...props }: {
14
5
  to: RoutePath;
15
6
  hash?: string;
16
7
  search?: Record<string, string>;
@@ -19,5 +10,4 @@ declare function Link({
19
10
  target?: HTMLAttributeAnchorTarget;
20
11
  } & React.AnchorHTMLAttributes<HTMLAnchorElement>): React.JSX.Element;
21
12
  //#endregion
22
- export { Link };
23
13
  //# sourceMappingURL=Link.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Link.d.mts","names":[],"sources":["../../src/Link.tsx"],"mappings":";;;;iBAMgB,IAAA,CAAA;EACd,EAAA;EACA,QAAA;EACA,IAAA;EACA,MAAA;EACA,MAAA;EACA,OAAA;EAAA,GACG;AAAA;EAEH,EAAA,EAAI,SAAA;EACJ,IAAA;EACA,MAAA,GAAS,MAAA;EACT,QAAA,EAAU,KAAA,CAAM,SAAA;EAChB,OAAA,IAAW,CAAA,EAAG,KAAA,CAAM,UAAA,CAAW,iBAAA;EAC/B,MAAA,GAAS,yBAAA;AAAA,IACP,KAAA,CAAM,oBAAA,CAAqB,iBAAA,IAAkB,KAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"Link.d.mts","names":[],"sources":["../../src/Link.tsx"],"mappings":";;;wBAMgB,OACd,IACA,UACA,MACA,QACA,QACA,YACG;EAEH,IAAI;EACJ;EACA,SAAS;EACT,UAAU,MAAM;EAChB,WAAW,GAAG,MAAM,WAAW;EAC/B,SAAS;IACP,MAAM,qBAAqB,qBAAkB,MAAA,IAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Link.mjs","names":[],"sources":["../../src/Link.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { type HTMLAttributeAnchorTarget } from \"react\";\nimport { RoutePath } from \"./types.js\";\nimport { useRouter } from \"./Router.js\";\n\nexport function Link({\n to,\n children,\n hash,\n target,\n search,\n onClick,\n ...props\n}: {\n to: RoutePath;\n hash?: string;\n search?: Record<string, string>;\n children: React.ReactNode;\n onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;\n target?: HTMLAttributeAnchorTarget;\n} & React.AnchorHTMLAttributes<HTMLAnchorElement>) {\n const { navigate } = useRouter();\n const href = `${to}${hash ? `#${hash}` : \"\"}${search ? `?${new URLSearchParams(search)}` : \"\"}`;\n\n return (\n <a\n href={href}\n onClick={(e) => {\n if (onClick) {\n onClick(e);\n }\n\n if (\n (!target || target === \"_self\") &&\n e.button === 0 && // left clicks only\n !e.metaKey && // open in new tab (mac)\n !e.ctrlKey && // open in new tab (windows)\n !e.altKey && // download\n !e.shiftKey &&\n !e.defaultPrevented\n ) {\n // Intercept link clicks to perform RSC navigation.\n e.preventDefault();\n navigate(href);\n }\n }}\n {...props}\n >\n {children}\n </a>\n );\n}\n"],"mappings":";;;;AAMA,SAAgB,KAAK,EACnB,IACA,UACA,MACA,QACA,QACA,SACA,GAAG,SAQ8C;CACjD,MAAM,EAAE,aAAa,WAAW;CAChC,MAAM,OAAO,GAAG,KAAK,OAAO,IAAI,SAAS,KAAK,SAAS,IAAI,IAAI,gBAAgB,OAAO,KAAK;CAE3F,OACE,sBAAA,cAAC,KAAD;EACQ;EACN,UAAU,MAAM;GACd,IAAI,SACF,QAAQ,EAAE;GAGZ,KACG,CAAC,UAAU,WAAW,YACvB,EAAE,WAAW,KACb,CAAC,EAAE,WACH,CAAC,EAAE,WACH,CAAC,EAAE,UACH,CAAC,EAAE,YACH,CAAC,EAAE,kBACH;IAEA,EAAE,gBAAgB;IAClB,SAAS,KAAK;;;EAGlB,GAAI;EAGF,EADD,SACC"}
1
+ {"version":3,"file":"Link.mjs","names":[],"sources":["../../src/Link.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { type HTMLAttributeAnchorTarget } from \"react\";\nimport { RoutePath } from \"./types.js\";\nimport { useRouter } from \"./Router.js\";\n\nexport function Link({\n to,\n children,\n hash,\n target,\n search,\n onClick,\n ...props\n}: {\n to: RoutePath;\n hash?: string;\n search?: Record<string, string>;\n children: React.ReactNode;\n onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;\n target?: HTMLAttributeAnchorTarget;\n} & React.AnchorHTMLAttributes<HTMLAnchorElement>) {\n const { navigate } = useRouter();\n const href = `${to}${hash ? `#${hash}` : \"\"}${search ? `?${new URLSearchParams(search)}` : \"\"}`;\n\n return (\n <a\n href={href}\n onClick={(e) => {\n if (onClick) {\n onClick(e);\n }\n\n if (\n (!target || target === \"_self\") &&\n e.button === 0 && // left clicks only\n !e.metaKey && // open in new tab (mac)\n !e.ctrlKey && // open in new tab (windows)\n !e.altKey && // download\n !e.shiftKey &&\n !e.defaultPrevented\n ) {\n // Intercept link clicks to perform RSC navigation.\n e.preventDefault();\n navigate(href);\n }\n }}\n {...props}\n >\n {children}\n </a>\n );\n}\n"],"mappings":";;;;AAMA,SAAgB,KAAK,EACnB,IACA,UACA,MACA,QACA,QACA,SACA,GAAG,SAQ8C;CACjD,MAAM,EAAE,aAAa,UAAU;CAC/B,MAAM,OAAO,GAAG,KAAK,OAAO,IAAI,SAAS,KAAK,SAAS,IAAI,IAAI,gBAAgB,MAAM,MAAM;CAE3F,OACE,sBAAA,cAAC,KAAD;EACQ;EACN,UAAU,MAAM;GACd,IAAI,SACF,QAAQ,CAAC;GAGX,KACG,CAAC,UAAU,WAAW,YACvB,EAAE,WAAW,KACb,CAAC,EAAE,WACH,CAAC,EAAE,WACH,CAAC,EAAE,UACH,CAAC,EAAE,YACH,CAAC,EAAE,kBACH;IAEA,EAAE,eAAe;IACjB,SAAS,IAAI;GACf;EACF;EACA,GAAI;CAGH,GADA,QACA;AAEP"}
@@ -1,25 +1,20 @@
1
1
  import { RouteData } from "./types.mjs";
2
2
  import * as React$1 from "react";
3
-
4
3
  //#region src/Router.d.ts
5
- declare function useRouter(): {
4
+ export declare function useRouter(): {
6
5
  navigate: (to: string) => void;
7
6
  };
8
- declare function useLocation(): Location;
9
- declare function useCurrentRoute(): {
10
- rsc: `${string}.rsc`;
11
- url: string;
7
+ export declare function useLocation(): Location;
8
+ export declare function useCurrentRoute(): {
12
9
  path: string;
13
10
  slug: string;
14
11
  html: `${string}.html`;
12
+ rsc: `${string}.rsc`;
13
+ url: string;
15
14
  } | null;
16
- declare const RouterProvider: ({
17
- children,
18
- routes
19
- }: {
15
+ export declare const RouterProvider: ({ children, routes }: {
20
16
  children: React$1.ReactNode;
21
17
  routes: RouteData[];
22
18
  }) => React$1.JSX.Element;
23
19
  //#endregion
24
- export { RouterProvider, useCurrentRoute, useLocation, useRouter };
25
20
  //# sourceMappingURL=Router.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Router.d.mts","names":[],"sources":["../../src/Router.tsx"],"mappings":";;;;iBAuBgB,SAAA,CAAA;EAAS,QAAA,GAHZ,EAAA;AAAA;AAAA,iBAaG,WAAA,CAAA,GAAW,QAAA;AAAA,iBAQX,eAAA,CAAA;;;;;;;cAeH,cAAA;EAAkB,QAAA;EAAA;AAAA;EAI7B,QAAA,EAAU,OAAA,CAAM,SAAA;EAChB,MAAA,EAAQ,SAAA;AAAA,MACT,OAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"Router.d.mts","names":["React"],"sources":["../../src/Router.tsx"],"mappings":";;;wBAuBgB;EAHJ,WAAC;;wBAaG,eAAW;wBAQX;;;;;;;qBAeH,mBAAc,UAAA;EAIzB,UAAUA,QAAM;EAChB,QAAQ;MACTA,QAAA,IAAA"}
@@ -36,11 +36,12 @@ const ssrSnapshot = {
36
36
  const getSsrSnapshot = () => ssrSnapshot;
37
37
  const RouterProvider = ({ children, routes }) => {
38
38
  const { location, state } = useSyncExternalStore(history.subscribe, history.getSnapshot, getSsrSnapshot);
39
+ const href = location === null || location === void 0 ? void 0 : location.href;
39
40
  const navigate$1 = React$1.useCallback((to) => {
40
41
  var _history$snapshot$sta, _history$snapshot$sta2;
41
- if (!(location === null || location === void 0 ? void 0 : location.href)) throw new Error("Location is not available");
42
- if (location.href === new URL(to, location.href).href) return;
43
- history.replace(location.href, {
42
+ if (!href) throw new Error("Location is not available");
43
+ if (href === new URL(to, href).href) return;
44
+ history.replace(href, {
44
45
  ...history.snapshot.state,
45
46
  key: (_history$snapshot$sta = (_history$snapshot$sta2 = history.snapshot.state) === null || _history$snapshot$sta2 === void 0 ? void 0 : _history$snapshot$sta2.key) !== null && _history$snapshot$sta !== void 0 ? _history$snapshot$sta : Math.random().toString(36).slice(2),
46
47
  scrollX: window.scrollX,
@@ -53,7 +54,7 @@ const RouterProvider = ({ children, routes }) => {
53
54
  scrollY: 0
54
55
  });
55
56
  });
56
- }, [routes, location === null || location === void 0 ? void 0 : location.href]);
57
+ }, [routes, href]);
57
58
  const routerContextValue = React$1.useMemo(() => ({ navigate: navigate$1 }), [navigate$1]);
58
59
  React$1.useEffect(() => {
59
60
  const handlePopState = () => {
@@ -80,6 +81,6 @@ const RouterProvider = ({ children, routes }) => {
80
81
  return /* @__PURE__ */ React$1.createElement(RoutesContext.Provider, { value: routes }, /* @__PURE__ */ React$1.createElement(LocationContext.Provider, { value: location }, /* @__PURE__ */ React$1.createElement(RouterContext.Provider, { value: routerContextValue }, children)));
81
82
  };
82
83
  //#endregion
83
- export { RouterProvider, useCurrentRoute, useLocation, useRouter };
84
+ export { RouterProvider, useCurrentRoute, useLocation, useRouter, useRoutes };
84
85
 
85
86
  //# sourceMappingURL=Router.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Router.mjs","names":["React","navigate","rscNavigate"],"sources":["../../src/Router.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { useSyncExternalStore } from \"react\";\nimport { createHistory } from \"./history.js\";\nimport { navigate as rscNavigate } from \"./rsc.js\";\nimport { RouteData } from \"./types.js\";\nimport { getPathData } from \"./util.js\";\n\nconst RoutesContext = React.createContext<RouteData[] | null>(null);\n\nexport const useRoutes = () => {\n const routes = React.useContext(RoutesContext);\n if (routes === null) {\n throw new Error(\"useRoutes must be used within a RouterProvider\");\n }\n return routes;\n};\n\nconst RouterContext = React.createContext<{\n navigate: (to: string) => void;\n} | null>(null);\n\nexport function useRouter() {\n const context = React.useContext(RouterContext);\n if (context === null) {\n throw new Error(\"useRouter must be used within a RouterProvider\");\n }\n return context;\n}\n\nconst LocationContext = React.createContext<Location | null>(null);\n\nexport function useLocation() {\n const context = React.useContext(LocationContext);\n if (context === null) {\n throw new Error(\"useLocation must be used within a RouterProvider\");\n }\n return context;\n}\n\nexport function useCurrentRoute() {\n const location = useLocation();\n const routes = useRoutes();\n return getPathData(location.pathname, routes);\n}\n\nconst history = createHistory();\n\nconst ssrSnapshot = {\n location: null,\n state: null,\n};\n\nconst getSsrSnapshot = () => ssrSnapshot;\n\nexport const RouterProvider = ({\n children,\n routes,\n}: {\n children: React.ReactNode;\n routes: RouteData[];\n}) => {\n // subscribe to history changes\n const { location, state } = useSyncExternalStore(\n history.subscribe,\n history.getSnapshot,\n getSsrSnapshot\n );\n\n const navigate = React.useCallback(\n (to: string) => {\n if (!location?.href) {\n throw new Error(\"Location is not available\");\n }\n\n if (location.href === new URL(to, location.href).href) {\n return;\n }\n\n // save scroll position for the current entry\n history.replace(location.href, {\n ...history.snapshot.state,\n key: history.snapshot.state?.key ?? Math.random().toString(36).slice(2),\n scrollX: window.scrollX,\n scrollY: window.scrollY,\n });\n\n void rscNavigate(to, routes, (url) => {\n history.push(url, {\n key: Math.random().toString(36).slice(2),\n scrollX: 0,\n scrollY: 0,\n });\n });\n },\n [routes, location?.href]\n );\n\n const routerContextValue = React.useMemo(() => ({ navigate }), [navigate]);\n\n React.useEffect(() => {\n const handlePopState = () => {\n void rscNavigate(\n window.location.pathname,\n routes,\n () => {\n // noop, history is already updated\n },\n { push: false }\n );\n };\n\n window.addEventListener(\"popstate\", handlePopState);\n return () => window.removeEventListener(\"popstate\", handlePopState);\n }, [routes]);\n\n React.useLayoutEffect(() => {\n // hash scrolling takes priority\n if (location?.hash) {\n const element = document.querySelector(location.hash);\n if (element) {\n element.scrollIntoView();\n return;\n }\n }\n\n // otherwise use saved scroll position\n if (state?.scrollY !== undefined) {\n window.scrollTo(state.scrollX, state.scrollY);\n } else {\n window.scrollTo(0, 0);\n }\n }, [location?.pathname, location?.hash, state]);\n\n return (\n <RoutesContext.Provider value={routes}>\n <LocationContext.Provider value={location}>\n <RouterContext.Provider value={routerContextValue}>\n {children}\n </RouterContext.Provider>\n </LocationContext.Provider>\n </RoutesContext.Provider>\n );\n};\n"],"mappings":";;;;;;;AASA,MAAM,gBAAgBA,QAAM,cAAkC,KAAK;AAEnE,MAAa,kBAAkB;CAC7B,MAAM,SAASA,QAAM,WAAW,cAAc;CAC9C,IAAI,WAAW,MACb,MAAM,IAAI,MAAM,iDAAiD;CAEnE,OAAO;;AAGT,MAAM,gBAAgBA,QAAM,cAElB,KAAK;AAEf,SAAgB,YAAY;CAC1B,MAAM,UAAUA,QAAM,WAAW,cAAc;CAC/C,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,iDAAiD;CAEnE,OAAO;;AAGT,MAAM,kBAAkBA,QAAM,cAA+B,KAAK;AAElE,SAAgB,cAAc;CAC5B,MAAM,UAAUA,QAAM,WAAW,gBAAgB;CACjD,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;;AAGT,SAAgB,kBAAkB;CAChC,MAAM,WAAW,aAAa;CAC9B,MAAM,SAAS,WAAW;CAC1B,OAAO,YAAY,SAAS,UAAU,OAAO;;AAG/C,MAAM,UAAU,eAAe;AAE/B,MAAM,cAAc;CAClB,UAAU;CACV,OAAO;CACR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,UAAU,SAAS,cAAc,SAAS,KAAK;GACrD,IAAI,SAAS;IACX,QAAQ,gBAAgB;IACxB;;;EAKJ,KAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAI,MAAO,aAAY,KAAA,GACrB,OAAO,SAAS,MAAM,SAAS,MAAM,QAAQ;OAE7C,OAAO,SAAS,GAAG,EAAE;IAEtB;sDAAC,SAAU;sDAAU,SAAU;EAAM;EAAM,CAAC;CAE/C,OACE,wBAAA,cAAC,cAAc,UAAf,EAAwB,OAAO,QAMN,EALvB,wBAAA,cAAC,gBAAgB,UAAjB,EAA0B,OAAO,UAIN,EAHzB,wBAAA,cAAC,cAAc,UAAf,EAAwB,OAAO,oBAEN,EADtB,SACsB,CACA,CACJ"}
1
+ {"version":3,"file":"Router.mjs","names":["React","navigate","rscNavigate"],"sources":["../../src/Router.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { useSyncExternalStore } from \"react\";\nimport { createHistory } from \"./history.js\";\nimport { navigate as rscNavigate } from \"./rsc.js\";\nimport { RouteData } from \"./types.js\";\nimport { getPathData } from \"./util.js\";\n\nconst RoutesContext = React.createContext<RouteData[] | null>(null);\n\nexport const useRoutes = () => {\n const routes = React.useContext(RoutesContext);\n if (routes === null) {\n throw new Error(\"useRoutes must be used within a RouterProvider\");\n }\n return routes;\n};\n\nconst RouterContext = React.createContext<{\n navigate: (to: string) => void;\n} | null>(null);\n\nexport function useRouter() {\n const context = React.useContext(RouterContext);\n if (context === null) {\n throw new Error(\"useRouter must be used within a RouterProvider\");\n }\n return context;\n}\n\nconst LocationContext = React.createContext<Location | null>(null);\n\nexport function useLocation() {\n const context = React.useContext(LocationContext);\n if (context === null) {\n throw new Error(\"useLocation must be used within a RouterProvider\");\n }\n return context;\n}\n\nexport function useCurrentRoute() {\n const location = useLocation();\n const routes = useRoutes();\n return getPathData(location.pathname, routes);\n}\n\nconst history = createHistory();\n\nconst ssrSnapshot = {\n location: null,\n state: null,\n};\n\nconst getSsrSnapshot = () => ssrSnapshot;\n\nexport const RouterProvider = ({\n children,\n routes,\n}: {\n children: React.ReactNode;\n routes: RouteData[];\n}) => {\n // subscribe to history changes\n const { location, state } = useSyncExternalStore(\n history.subscribe,\n history.getSnapshot,\n getSsrSnapshot\n );\n\n const href = location?.href;\n\n const navigate = React.useCallback(\n (to: string) => {\n if (!href) {\n throw new Error(\"Location is not available\");\n }\n\n if (href === new URL(to, href).href) {\n return;\n }\n\n // save scroll position for the current entry\n history.replace(href, {\n ...history.snapshot.state,\n key: history.snapshot.state?.key ?? Math.random().toString(36).slice(2),\n scrollX: window.scrollX,\n scrollY: window.scrollY,\n });\n\n void rscNavigate(to, routes, (url) => {\n history.push(url, {\n key: Math.random().toString(36).slice(2),\n scrollX: 0,\n scrollY: 0,\n });\n });\n },\n [routes, href]\n );\n\n const routerContextValue = React.useMemo(() => ({ navigate }), [navigate]);\n\n React.useEffect(() => {\n const handlePopState = () => {\n void rscNavigate(\n window.location.pathname,\n routes,\n () => {\n // noop, history is already updated\n },\n { push: false }\n );\n };\n\n window.addEventListener(\"popstate\", handlePopState);\n return () => window.removeEventListener(\"popstate\", handlePopState);\n }, [routes]);\n\n React.useLayoutEffect(() => {\n // hash scrolling takes priority\n if (location?.hash) {\n const element = document.querySelector(location.hash);\n if (element) {\n element.scrollIntoView();\n return;\n }\n }\n\n // otherwise use saved scroll position\n if (state?.scrollY !== undefined) {\n window.scrollTo(state.scrollX, state.scrollY);\n } else {\n window.scrollTo(0, 0);\n }\n }, [location?.pathname, location?.hash, state]);\n\n return (\n <RoutesContext.Provider value={routes}>\n <LocationContext.Provider value={location}>\n <RouterContext.Provider value={routerContextValue}>\n {children}\n </RouterContext.Provider>\n </LocationContext.Provider>\n </RoutesContext.Provider>\n );\n};\n"],"mappings":";;;;;;;AASA,MAAM,gBAAgBA,QAAM,cAAkC,IAAI;AAElE,MAAa,kBAAkB;CAC7B,MAAM,SAASA,QAAM,WAAW,aAAa;CAC7C,IAAI,WAAW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GACpC,QAAQ,KAAK,KAAK;IAChB,KAAK,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;IACvC,SAAS;IACT,SAAS;GACX,CAAC;EACH,CAAC;CACH,GACA,CAAC,QAAQ,IAAI,CACf;CAEA,MAAM,qBAAqBA,QAAM,eAAe,EAAE,UAAA,WAAS,IAAI,CAACC,UAAQ,CAAC;CAEzE,QAAM,gBAAgB;EACpB,MAAM,uBAAuB;GAC3B,SACE,OAAO,SAAS,UAChB,cACM,CAEN,GACA,EAAE,MAAM,MAAM,CAChB;EACF;EAEA,OAAO,iBAAiB,YAAY,cAAc;EAClD,aAAa,OAAO,oBAAoB,YAAY,cAAc;CACpE,GAAG,CAAC,MAAM,CAAC;CAEX,QAAM,sBAAsB;EAE1B,IAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAI,SAAU,MAAM;GAClB,MAAM,UAAU,SAAS,cAAc,SAAS,IAAI;GACpD,IAAI,SAAS;IACX,QAAQ,eAAe;IACvB;GACF;EACF;EAGA,KAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAI,MAAO,aAAY,KAAA,GACrB,OAAO,SAAS,MAAM,SAAS,MAAM,OAAO;OAE5C,OAAO,SAAS,GAAG,CAAC;CAExB,GAAG;EAAC,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAA,SAAU;EAAU,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAA,SAAU;EAAM;CAAK,CAAC;CAE9C,OACE,wBAAA,cAAC,cAAc,UAAf,EAAwB,OAAO,OAMP,GALtB,wBAAA,cAAC,gBAAgB,UAAjB,EAA0B,OAAO,SAIP,GAHxB,wBAAA,cAAC,cAAc,UAAf,EAAwB,OAAO,mBAEP,GADrB,QACqB,CACA,CACJ;AAE5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-entry.mjs","names":[],"sources":["../../src/client-entry.ts"],"sourcesContent":["\"use client-entry\";\n\nimport { hydrate } from \"@parcel/rsc/client\";\n\n//TODO https://github.com/microsoft/TypeScript/issues/42873#issuecomment-1416128545\nexport const updateRoot: ReturnType<typeof hydrate> = hydrate({\n // TODO - can't build due to reading window\n // onHmrReload() {},\n});\n"],"mappings":";;;AAKA,MAAa,aAAyC,QAAQ,EAG7D,CAAC"}
1
+ {"version":3,"file":"client-entry.mjs","names":[],"sources":["../../src/client-entry.ts"],"sourcesContent":["\"use client-entry\";\n\nimport { hydrate } from \"@parcel/rsc/client\";\n\n//TODO https://github.com/microsoft/TypeScript/issues/42873#issuecomment-1416128545\nexport const updateRoot: ReturnType<typeof hydrate> = hydrate({\n // TODO - can't build due to reading window\n // onHmrReload() {},\n});\n"],"mappings":";;;AAKA,MAAa,aAAyC,QAAQ,CAG9D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"history.mjs","names":[],"sources":["../../src/history.ts"],"sourcesContent":["\"use client\";\n\n// basic history management\n\nexport type HistoryState = {\n key: string;\n scrollX: number;\n scrollY: number;\n};\n\nexport function createHistory() {\n const listeners = new Set<() => void>();\n let currentSnapshot: {\n location: Location | null;\n state: HistoryState | null;\n };\n\n const getSnapshot = () => {\n const newSnapshot = {\n location: window.location,\n state: window.history.state as HistoryState | null,\n };\n // Only update currentSnapshot if something actually changed to prevent infinite loops\n if (\n !currentSnapshot ||\n currentSnapshot.location !== newSnapshot.location ||\n currentSnapshot.state !== newSnapshot.state\n ) {\n currentSnapshot = newSnapshot;\n }\n return currentSnapshot;\n };\n\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"popstate\", () => {\n // notify listeners - do it in a microtask to avoid scheduling react updates\n queueMicrotask(() => listeners.forEach((listener) => listener()));\n });\n }\n\n return {\n get snapshot() {\n return getSnapshot();\n },\n\n getSnapshot,\n\n subscribe(this: void, listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n\n push(url: string, state: HistoryState) {\n window.history.pushState(state, \"\", url);\n // notify listeners - do it in a microtask to avoid scheduling react updates\n queueMicrotask(() => listeners.forEach((listener) => listener()));\n },\n\n replace(url: string, state: HistoryState) {\n window.history.replaceState(state, \"\", url);\n // don't notify listeners on replace, as it's for non-navigation changes\n },\n };\n}\n\nexport type BrowserHistory = ReturnType<typeof createHistory>;\n"],"mappings":";;AAUA,SAAgB,gBAAgB;CAC9B,MAAM,4BAAY,IAAI,KAAiB;CACvC,IAAI;CAKJ,MAAM,oBAAoB;EACxB,MAAM,cAAc;GAClB,UAAU,OAAO;GACjB,OAAO,OAAO,QAAQ;GACvB;EAED,IACE,CAAC,mBACD,gBAAgB,aAAa,YAAY,YACzC,gBAAgB,UAAU,YAAY,OAEtC,kBAAkB;EAEpB,OAAO;;CAGT,IAAI,OAAO,WAAW,aACpB,OAAO,iBAAiB,kBAAkB;EAExC,qBAAqB,UAAU,SAAS,aAAa,UAAU,CAAC,CAAC;GACjE;CAGJ,OAAO;EACL,IAAI,WAAW;GACb,OAAO,aAAa;;EAGtB;EAEA,UAAsB,UAAsB;GAC1C,UAAU,IAAI,SAAS;GACvB,aAAa;IACX,UAAU,OAAO,SAAS;;;EAI9B,KAAK,KAAa,OAAqB;GACrC,OAAO,QAAQ,UAAU,OAAO,IAAI,IAAI;GAExC,qBAAqB,UAAU,SAAS,aAAa,UAAU,CAAC,CAAC;;EAGnE,QAAQ,KAAa,OAAqB;GACxC,OAAO,QAAQ,aAAa,OAAO,IAAI,IAAI;;EAG9C"}
1
+ {"version":3,"file":"history.mjs","names":[],"sources":["../../src/history.ts"],"sourcesContent":["\"use client\";\n\n// basic history management\n\nexport type HistoryState = {\n key: string;\n scrollX: number;\n scrollY: number;\n};\n\nexport function createHistory() {\n const listeners = new Set<() => void>();\n let currentSnapshot: {\n location: Location | null;\n state: HistoryState | null;\n };\n\n const getSnapshot = () => {\n const newSnapshot = {\n location: window.location,\n state: window.history.state as HistoryState | null,\n };\n // Only update currentSnapshot if something actually changed to prevent infinite loops\n if (\n !currentSnapshot ||\n currentSnapshot.location !== newSnapshot.location ||\n currentSnapshot.state !== newSnapshot.state\n ) {\n currentSnapshot = newSnapshot;\n }\n return currentSnapshot;\n };\n\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"popstate\", () => {\n // notify listeners - do it in a microtask to avoid scheduling react updates\n queueMicrotask(() => listeners.forEach((listener) => listener()));\n });\n }\n\n return {\n get snapshot() {\n return getSnapshot();\n },\n\n getSnapshot,\n\n subscribe(this: void, listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n\n push(url: string, state: HistoryState) {\n window.history.pushState(state, \"\", url);\n // notify listeners - do it in a microtask to avoid scheduling react updates\n queueMicrotask(() => listeners.forEach((listener) => listener()));\n },\n\n replace(url: string, state: HistoryState) {\n window.history.replaceState(state, \"\", url);\n // don't notify listeners on replace, as it's for non-navigation changes\n },\n };\n}\n\nexport type BrowserHistory = ReturnType<typeof createHistory>;\n"],"mappings":";;AAUA,SAAgB,gBAAgB;CAC9B,MAAM,4BAAY,IAAI,IAAgB;CACtC,IAAI;CAKJ,MAAM,oBAAoB;EACxB,MAAM,cAAc;GAClB,UAAU,OAAO;GACjB,OAAO,OAAO,QAAQ;EACxB;EAEA,IACE,CAAC,mBACD,gBAAgB,aAAa,YAAY,YACzC,gBAAgB,UAAU,YAAY,OAEtC,kBAAkB;EAEpB,OAAO;CACT;CAEA,IAAI,OAAO,WAAW,aACpB,OAAO,iBAAiB,kBAAkB;EAExC,qBAAqB,UAAU,SAAS,aAAa,SAAS,CAAC,CAAC;CAClE,CAAC;CAGH,OAAO;EACL,IAAI,WAAW;GACb,OAAO,YAAY;EACrB;EAEA;EAEA,UAAsB,UAAsB;GAC1C,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EAEA,KAAK,KAAa,OAAqB;GACrC,OAAO,QAAQ,UAAU,OAAO,IAAI,GAAG;GAEvC,qBAAqB,UAAU,SAAS,aAAa,SAAS,CAAC,CAAC;EAClE;EAEA,QAAQ,KAAa,OAAqB;GACxC,OAAO,QAAQ,aAAa,OAAO,IAAI,GAAG;EAE5C;CACF;AACF"}
package/dist/esm/rsc.mjs CHANGED
@@ -16,7 +16,8 @@ async function navigate(pathname, routes, onPush, { push = true } = {}) {
16
16
  }
17
17
  if (path.url === location.pathname) shouldPush = false;
18
18
  try {
19
- updateRoot(await fetchRSCWithPreloadCache(path.rsc), () => {
19
+ const root = await fetchRSCWithPreloadCache(path.rsc);
20
+ updateRoot(root, () => {
20
21
  if (shouldPush) onPush(path.url);
21
22
  });
22
23
  } catch (e) {
@@ -44,6 +45,6 @@ async function fetchRSCWithPreloadCache(url, options) {
44
45
  }
45
46
  const fetchCache = /* @__PURE__ */ new Map();
46
47
  //#endregion
47
- export { navigate };
48
+ export { fetchCache, navigate };
48
49
 
49
50
  //# sourceMappingURL=rsc.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsc.mjs","names":[],"sources":["../../src/rsc.ts"],"sourcesContent":["\"use client\";\n\nimport { type RSCRequestInit, fetchRSC } from \"@parcel/rsc/client\";\nimport { type ReactNode } from \"react\";\nimport { updateRoot } from \"./client-entry.js\";\nimport { RouteData } from \"./types.js\";\nimport { getPathData } from \"./util.js\";\n\n// fetch and push an rsc route\nexport async function navigate(\n pathname: string,\n routes: RouteData[],\n /** callback for a successful navigation (use this to update the history) */\n onPush: (url: string) => void,\n { push = true }: { push?: boolean } = {}\n) {\n console.debug(\"client navigating to:\", pathname);\n\n let shouldPush = push;\n\n const path = getPathData(pathname, routes);\n\n if (!path) {\n console.warn(`No route found for ${pathname}`);\n\n if (routes.some((r) => r.path === \"/404\")) {\n // we have a 404 page, navigate there\n void navigate(\"/404\", routes, () => {\n // show the original not found path (rather than 404) in the URL\n onPush(pathname);\n });\n }\n\n return;\n }\n\n // Don't add to history if we're already on this page\n if (path.url === location.pathname) {\n shouldPush = false;\n }\n\n try {\n const root = await fetchRSCWithPreloadCache<ReactNode>(path.rsc);\n\n updateRoot(root, () => {\n if (shouldPush) {\n onPush(path.url);\n }\n });\n\n // after a successful navigation, we can clear the cache\n // note everything is static currently, we don't need to clear the cache\n // fetchCache.clear();\n } catch (e) {\n console.log(`Error fetching ${path.path} RSC`, e);\n }\n}\n\nasync function fetchRSCWithPreloadCache<T>(\n url: string | URL | Request,\n options?: RSCRequestInit\n): Promise<T> {\n if (fetchCache.has(url)) {\n console.log(\"Cache hit\", url);\n\n return fetchCache.get(url) as Promise<T>;\n }\n\n const promise = fetchRSC<T>(url, options);\n\n fetchCache.set(url, promise);\n\n // keep the cache small, removing the oldest entries\n while (fetchCache.size > 5) {\n const firstKey = fetchCache.keys().next().value;\n\n if (!firstKey) {\n break;\n }\n\n fetchCache.delete(firstKey);\n }\n\n return promise\n .then((data) => {\n return data;\n })\n .catch((error) => {\n fetchCache.delete(url);\n\n throw error;\n });\n}\n\nexport const fetchCache = new Map<string | URL | Request, Promise<unknown>>();\n\nexport async function prefetch(\n pathname: string,\n routes: RouteData[],\n signal?: AbortSignal\n) {\n const path = getPathData(pathname, routes);\n\n if (!path) {\n return;\n }\n\n try {\n await fetchRSCWithPreloadCache<ReactNode>(path.rsc, { signal });\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error fetching ${pathname} RSC`, error);\n\n return;\n }\n\n // don't throw if the signal is aborted - this is expected\n if (signal?.aborted) {\n console.log(signal.reason);\n\n return;\n }\n }\n}\n"],"mappings":";;;;;AASA,eAAsB,SACpB,UACA,QAEA,QACA,EAAE,OAAO,SAA6B,EAAE,EACxC;CACA,QAAQ,MAAM,yBAAyB,SAAS;CAEhD,IAAI,aAAa;CAEjB,MAAM,OAAO,YAAY,UAAU,OAAO;CAE1C,IAAI,CAAC,MAAM;EACT,QAAQ,KAAK,sBAAsB,WAAW;EAE9C,IAAI,OAAO,MAAM,MAAM,EAAE,SAAS,OAAO,EAEvC,SAAc,QAAQ,cAAc;GAElC,OAAO,SAAS;IAChB;EAGJ;;CAIF,IAAI,KAAK,QAAQ,SAAS,UACxB,aAAa;CAGf,IAAI;EAGF,WAAW,MAFQ,yBAAoC,KAAK,IAAI,QAEzC;GACrB,IAAI,YACF,OAAO,KAAK,IAAI;IAElB;UAKK,GAAG;EACV,QAAQ,IAAI,kBAAkB,KAAK,KAAK,OAAO,EAAE;;;AAIrD,eAAe,yBACb,KACA,SACY;CACZ,IAAI,WAAW,IAAI,IAAI,EAAE;EACvB,QAAQ,IAAI,aAAa,IAAI;EAE7B,OAAO,WAAW,IAAI,IAAI;;CAG5B,MAAM,UAAU,SAAY,KAAK,QAAQ;CAEzC,WAAW,IAAI,KAAK,QAAQ;CAG5B,OAAO,WAAW,OAAO,GAAG;EAC1B,MAAM,WAAW,WAAW,MAAM,CAAC,MAAM,CAAC;EAE1C,IAAI,CAAC,UACH;EAGF,WAAW,OAAO,SAAS;;CAG7B,OAAO,QACJ,MAAM,SAAS;EACd,OAAO;GACP,CACD,OAAO,UAAU;EAChB,WAAW,OAAO,IAAI;EAEtB,MAAM;GACN;;AAGN,MAAa,6BAAa,IAAI,KAA+C"}
1
+ {"version":3,"file":"rsc.mjs","names":[],"sources":["../../src/rsc.ts"],"sourcesContent":["\"use client\";\n\nimport { type RSCRequestInit, fetchRSC } from \"@parcel/rsc/client\";\nimport { type ReactNode } from \"react\";\nimport { updateRoot } from \"./client-entry.js\";\nimport { RouteData } from \"./types.js\";\nimport { getPathData } from \"./util.js\";\n\n// fetch and push an rsc route\nexport async function navigate(\n pathname: string,\n routes: RouteData[],\n /** callback for a successful navigation (use this to update the history) */\n onPush: (url: string) => void,\n { push = true }: { push?: boolean } = {}\n) {\n console.debug(\"client navigating to:\", pathname);\n\n let shouldPush = push;\n\n const path = getPathData(pathname, routes);\n\n if (!path) {\n console.warn(`No route found for ${pathname}`);\n\n if (routes.some((r) => r.path === \"/404\")) {\n // we have a 404 page, navigate there\n void navigate(\"/404\", routes, () => {\n // show the original not found path (rather than 404) in the URL\n onPush(pathname);\n });\n }\n\n return;\n }\n\n // Don't add to history if we're already on this page\n if (path.url === location.pathname) {\n shouldPush = false;\n }\n\n try {\n const root = await fetchRSCWithPreloadCache<ReactNode>(path.rsc);\n\n updateRoot(root, () => {\n if (shouldPush) {\n onPush(path.url);\n }\n });\n\n // after a successful navigation, we can clear the cache\n // note everything is static currently, we don't need to clear the cache\n // fetchCache.clear();\n } catch (e) {\n console.log(`Error fetching ${path.path} RSC`, e);\n }\n}\n\nasync function fetchRSCWithPreloadCache<T>(\n url: string | URL | Request,\n options?: RSCRequestInit\n): Promise<T> {\n if (fetchCache.has(url)) {\n console.log(\"Cache hit\", url);\n\n return fetchCache.get(url) as Promise<T>;\n }\n\n const promise = fetchRSC<T>(url, options);\n\n fetchCache.set(url, promise);\n\n // keep the cache small, removing the oldest entries\n while (fetchCache.size > 5) {\n const firstKey = fetchCache.keys().next().value;\n\n if (!firstKey) {\n break;\n }\n\n fetchCache.delete(firstKey);\n }\n\n return promise\n .then((data) => {\n return data;\n })\n .catch((error) => {\n fetchCache.delete(url);\n\n throw error;\n });\n}\n\nexport const fetchCache = new Map<string | URL | Request, Promise<unknown>>();\n\nexport async function prefetch(\n pathname: string,\n routes: RouteData[],\n signal?: AbortSignal\n) {\n const path = getPathData(pathname, routes);\n\n if (!path) {\n return;\n }\n\n try {\n await fetchRSCWithPreloadCache<ReactNode>(path.rsc, { signal });\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error fetching ${pathname} RSC`, error);\n\n return;\n }\n\n // don't throw if the signal is aborted - this is expected\n if (signal?.aborted) {\n console.log(signal.reason);\n\n return;\n }\n }\n}\n"],"mappings":";;;;;AASA,eAAsB,SACpB,UACA,QAEA,QACA,EAAE,OAAO,SAA6B,CAAC,GACvC;CACA,QAAQ,MAAM,yBAAyB,QAAQ;CAE/C,IAAI,aAAa;CAEjB,MAAM,OAAO,YAAY,UAAU,MAAM;CAEzC,IAAI,CAAC,MAAM;EACT,QAAQ,KAAK,sBAAsB,UAAU;EAE7C,IAAI,OAAO,MAAM,MAAM,EAAE,SAAS,MAAM,GAEtC,SAAc,QAAQ,cAAc;GAElC,OAAO,QAAQ;EACjB,CAAC;EAGH;CACF;CAGA,IAAI,KAAK,QAAQ,SAAS,UACxB,aAAa;CAGf,IAAI;EACF,MAAM,OAAO,MAAM,yBAAoC,KAAK,GAAG;EAE/D,WAAW,YAAY;GACrB,IAAI,YACF,OAAO,KAAK,GAAG;EAEnB,CAAC;CAKH,SAAS,GAAG;EACV,QAAQ,IAAI,kBAAkB,KAAK,KAAK,OAAO,CAAC;CAClD;AACF;AAEA,eAAe,yBACb,KACA,SACY;CACZ,IAAI,WAAW,IAAI,GAAG,GAAG;EACvB,QAAQ,IAAI,aAAa,GAAG;EAE5B,OAAO,WAAW,IAAI,GAAG;CAC3B;CAEA,MAAM,UAAU,SAAY,KAAK,OAAO;CAExC,WAAW,IAAI,KAAK,OAAO;CAG3B,OAAO,WAAW,OAAO,GAAG;EAC1B,MAAM,WAAW,WAAW,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;EAE1C,IAAI,CAAC,UACH;EAGF,WAAW,OAAO,QAAQ;CAC5B;CAEA,OAAO,QACJ,MAAM,SAAS;EACd,OAAO;CACT,CAAC,CAAC,CACD,OAAO,UAAU;EAChB,WAAW,OAAO,GAAG;EAErB,MAAM;CACR,CAAC;AACL;AAEA,MAAa,6BAAa,IAAI,IAA8C"}
@@ -1,18 +1,17 @@
1
1
  import { Page, TocNode } from "@parcel/rsc";
2
-
3
2
  //#region src/types.d.ts
4
- declare namespace App {
3
+ export declare namespace App {
5
4
  interface Routes {}
6
5
  }
7
- type RoutePath = keyof App.Routes extends never ? string : keyof App.Routes;
6
+ export type RoutePath = keyof App.Routes extends never ? string : keyof App.Routes;
8
7
  /**
9
8
  * Union of all valid HTML route paths, e.g. "/index.html" | "/components/button.html"
10
9
  */
11
- type RouteHtml = keyof App.Routes extends never ? `${string}.html` : App.Routes[keyof App.Routes]["html"];
12
- type RouteRsc = keyof App.Routes extends never ? `${string}.rsc` : App.Routes[keyof App.Routes]["rsc"];
13
- type RouteData<TPath extends string = RoutePath, THtml extends string = RouteHtml, TRsc extends string = RouteRsc> = Omit<RouteNode<TPath, THtml, TRsc>, "children">;
10
+ export type RouteHtml = keyof App.Routes extends never ? `${string}.html` : App.Routes[keyof App.Routes]["html"];
11
+ export type RouteRsc = keyof App.Routes extends never ? `${string}.rsc` : App.Routes[keyof App.Routes]["rsc"];
12
+ export type RouteData<TPath extends string = RoutePath, THtml extends string = RouteHtml, TRsc extends string = RouteRsc> = Omit<RouteNode<TPath, THtml, TRsc>, "children">;
14
13
  type RoutePathToSlug<T extends string> = T extends `/` ? "index" : T extends `${infer _Prefix}/${infer Slug}` ? RoutePathToSlug<Slug> : T;
15
- interface RouteNode<TPath extends string = RoutePath, THtml extends string = RouteHtml, TRsc extends string = RouteRsc> {
14
+ export interface RouteNode<TPath extends string = RoutePath, THtml extends string = RouteHtml, TRsc extends string = RouteRsc> {
16
15
  children: RouteNode<TPath, THtml, TRsc>[];
17
16
  path: TPath;
18
17
  slug: RoutePathToSlug<TPath>;
@@ -28,10 +27,10 @@ interface Page$1<TUrl extends string = RouteHtml> extends Omit<Page, "url"> {
28
27
  /**
29
28
  * Enhanced PageProps where `pages` and `currentPage` have typed `url`s.
30
29
  */
31
- interface PageProps<TUrl extends string = RouteHtml> {
30
+ export interface PageProps<TUrl extends string = RouteHtml> {
32
31
  pages: Page$1<RouteHtml>[];
33
32
  currentPage: Page$1<TUrl>;
34
33
  }
35
34
  //#endregion
36
- export { App, Page$1 as Page, PageProps, RouteData, RouteHtml, RouteNode, RoutePath, RouteRsc, type TocNode };
35
+ export { Page$1 as Page, type TocNode };
37
36
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/types.ts"],"mappings":";;;kBAIiB,GAAA;EAAA,UACE,MAAA;AAAA;AAAA,KAGP,SAAA,SAAkB,GAAA,CAAI,MAAA,gCAExB,GAAA,CAAI,MAAA;;AAFd;;KAOY,SAAA,SAAkB,GAAA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MAAM;EACN,MAAM,gBAAgB;EACtB,KAAK;EACL,MAAM;;;;;UAMSA,OAAK,sBAAsB,mBAAmB,KAC7DC;EAGA,KAAK;;;;;iBAMU,UAAU,sBAAsB;EAC/C,OAAOD,OAAK;EACZ,aAAaA,OAAK"}
package/dist/esm/util.mjs CHANGED
@@ -5,8 +5,10 @@ const normalizeRoutePath = (path) => {
5
5
  return path;
6
6
  };
7
7
  function getPathData(pathname, routes) {
8
- const normalizedPath = normalizeRoutePath(pathname.startsWith("/") ? pathname : `/${pathname}`);
9
- const routePathName = normalizeRoutePath(new URL(pathname, window.location.origin).pathname);
8
+ const path = pathname.startsWith("/") ? pathname : `/${pathname}`;
9
+ const normalizedPath = normalizeRoutePath(path);
10
+ const url = new URL(pathname, window.location.origin);
11
+ const routePathName = normalizeRoutePath(url.pathname);
10
12
  const route = routes.find((route) => route.path === routePathName);
11
13
  if (!route) return null;
12
14
  return {
@@ -16,6 +18,6 @@ function getPathData(pathname, routes) {
16
18
  };
17
19
  }
18
20
  //#endregion
19
- export { getPathData };
21
+ export { getPathData, normalizeRoutePath };
20
22
 
21
23
  //# sourceMappingURL=util.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.mjs","names":[],"sources":["../../src/util.ts"],"sourcesContent":["\"use client\";\nimport { RouteData } from \"./types.js\";\n\n// remove trailing slashes and index from the path\nexport const normalizeRoutePath = (path: string) => {\n for (const suffix of [\"/\", \"/index\"]) {\n if (path.endsWith(suffix)) {\n return path.slice(0, -suffix.length) || \"/\";\n }\n }\n\n return path;\n};\n\n// convert a path back to a route path\nexport const denormalizeRoutePath = (path: string) => {\n if (path === \"/\") {\n return \"index\";\n }\n\n if (path.startsWith(\"/\")) {\n return path.substring(1);\n }\n\n return path;\n};\n\nexport function getPathData(pathname: string, routes: RouteData[]) {\n const path = pathname.startsWith(\"/\") ? pathname : `/${pathname}`;\n\n // path for the URL (including query string/hash)\n const normalizedPath = normalizeRoutePath(path);\n\n // we want the pathname without the query string/hash to match the route\n const url = new URL(pathname, window.location.origin);\n\n const routePathName = normalizeRoutePath(url.pathname);\n\n const route = routes.find((route) => route.path === routePathName);\n\n if (!route) {\n return null;\n }\n\n return {\n ...route,\n rsc: route.rsc,\n url: normalizedPath,\n };\n}\n"],"mappings":";;AAIA,MAAa,sBAAsB,SAAiB;CAClD,KAAK,MAAM,UAAU,CAAC,KAAK,SAAS,EAClC,IAAI,KAAK,SAAS,OAAO,EACvB,OAAO,KAAK,MAAM,GAAG,CAAC,OAAO,OAAO,IAAI;CAI5C,OAAO;;AAgBT,SAAgB,YAAY,UAAkB,QAAqB;CAIjE,MAAM,iBAAiB,mBAHV,SAAS,WAAW,IAAI,GAAG,WAAW,IAAI,WAGR;CAK/C,MAAM,gBAAgB,mBAAmB,IAFzB,IAAI,UAAU,OAAO,SAAS,OAEF,CAAC,SAAS;CAEtD,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAM,SAAS,cAAc;CAElE,IAAI,CAAC,OACH,OAAO;CAGT,OAAO;EACL,GAAG;EACH,KAAK,MAAM;EACX,KAAK;EACN"}
1
+ {"version":3,"file":"util.mjs","names":[],"sources":["../../src/util.ts"],"sourcesContent":["\"use client\";\nimport { RouteData } from \"./types.js\";\n\n// remove trailing slashes and index from the path\nexport const normalizeRoutePath = (path: string) => {\n for (const suffix of [\"/\", \"/index\"]) {\n if (path.endsWith(suffix)) {\n return path.slice(0, -suffix.length) || \"/\";\n }\n }\n\n return path;\n};\n\n// convert a path back to a route path\nexport const denormalizeRoutePath = (path: string) => {\n if (path === \"/\") {\n return \"index\";\n }\n\n if (path.startsWith(\"/\")) {\n return path.substring(1);\n }\n\n return path;\n};\n\nexport function getPathData(pathname: string, routes: RouteData[]) {\n const path = pathname.startsWith(\"/\") ? pathname : `/${pathname}`;\n\n // path for the URL (including query string/hash)\n const normalizedPath = normalizeRoutePath(path);\n\n // we want the pathname without the query string/hash to match the route\n const url = new URL(pathname, window.location.origin);\n\n const routePathName = normalizeRoutePath(url.pathname);\n\n const route = routes.find((route) => route.path === routePathName);\n\n if (!route) {\n return null;\n }\n\n return {\n ...route,\n rsc: route.rsc,\n url: normalizedPath,\n };\n}\n"],"mappings":";;AAIA,MAAa,sBAAsB,SAAiB;CAClD,KAAK,MAAM,UAAU,CAAC,KAAK,QAAQ,GACjC,IAAI,KAAK,SAAS,MAAM,GACtB,OAAO,KAAK,MAAM,GAAG,CAAC,OAAO,MAAM,KAAK;CAI5C,OAAO;AACT;AAeA,SAAgB,YAAY,UAAkB,QAAqB;CACjE,MAAM,OAAO,SAAS,WAAW,GAAG,IAAI,WAAW,IAAI;CAGvD,MAAM,iBAAiB,mBAAmB,IAAI;CAG9C,MAAM,MAAM,IAAI,IAAI,UAAU,OAAO,SAAS,MAAM;CAEpD,MAAM,gBAAgB,mBAAmB,IAAI,QAAQ;CAErD,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAM,SAAS,aAAa;CAEjE,IAAI,CAAC,OACH,OAAO;CAGT,OAAO;EACL,GAAG;EACH,KAAK,MAAM;EACX,KAAK;CACP;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renr/parcel-rsc-router",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-alpha.9",
4
4
  "author": "Ren Rizzolo",
5
5
  "license": "MIT",
6
6
  "description": "Parcel rsc router",
@@ -29,16 +29,16 @@
29
29
  "react-server-dom-parcel": "^19"
30
30
  },
31
31
  "devDependencies": {
32
- "react": "^19.2.6",
33
- "@types/react": "^19.2.14",
34
- "@parcel/rsc": "^2.16.1"
32
+ "react": "^19.3.0",
33
+ "@types/react": "^19.3.0",
34
+ "@parcel/rsc": "^2.16.4"
35
35
  },
36
36
  "sideEffects": false,
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
40
  "scripts": {
41
- "type-check": "tsgo --noEmit",
41
+ "type-check": "tsc --noEmit",
42
42
  "build": "tsdown"
43
43
  }
44
44
  }