@page-component-object/router-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 David Vega
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ import React, { ReactNode, ReactElement } from 'react';
2
+ import { RouterHistory } from '@page-component-object/core';
3
+
4
+ type HistoryCaptureProps = {
5
+ children: ReactNode;
6
+ onReady: (history: RouterHistory) => void;
7
+ };
8
+ /** Exposes a live `RouterHistory` to test AppManager after mount. */
9
+ declare function HistoryCapture({ children, onReady }: HistoryCaptureProps): React.JSX.Element;
10
+ type MemoryRouterProps = {
11
+ initialEntries?: string[];
12
+ initialIndex?: number;
13
+ };
14
+ type ShallowRouteOptions = {
15
+ routePath?: string;
16
+ wrapLayout?: (children: ReactElement) => ReactNode;
17
+ };
18
+ /** Builds the routed subtree for shallow view renders. */
19
+ declare function buildShallowRouteTree(element: ReactElement, { routePath, wrapLayout }: ShallowRouteOptions): ReactElement;
20
+ type RoutedShellProps = MemoryRouterProps & {
21
+ children: ReactNode;
22
+ onHistoryReady: (history: RouterHistory) => void;
23
+ };
24
+ declare function RoutedShell({ initialEntries, initialIndex, children, onHistoryReady, }: RoutedShellProps): React.JSX.Element;
25
+
26
+ export { HistoryCapture, type HistoryCaptureProps, type MemoryRouterProps, RoutedShell, type RoutedShellProps, type ShallowRouteOptions, buildShallowRouteTree };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // src/index.tsx
2
+ import React from "react";
3
+ import {
4
+ MemoryRouter,
5
+ Route,
6
+ Routes,
7
+ useLocation,
8
+ useNavigate
9
+ } from "react-router-dom";
10
+ import { Fragment, jsx } from "react/jsx-runtime";
11
+ function HistoryCapture({ children, onReady }) {
12
+ const navigate = useNavigate();
13
+ const location = useLocation();
14
+ React.useEffect(() => {
15
+ const routerHistory = {
16
+ get location() {
17
+ return {
18
+ pathname: location.pathname,
19
+ search: location.search,
20
+ hash: location.hash
21
+ };
22
+ },
23
+ push: (path) => {
24
+ void navigate(path);
25
+ }
26
+ };
27
+ onReady(routerHistory);
28
+ }, [navigate, location, onReady]);
29
+ return /* @__PURE__ */ jsx(Fragment, { children });
30
+ }
31
+ function buildShallowRouteTree(element, { routePath, wrapLayout }) {
32
+ if (!routePath) return element;
33
+ const content = wrapLayout ? wrapLayout(element) : element;
34
+ return /* @__PURE__ */ jsx(Routes, { children: /* @__PURE__ */ jsx(Route, { path: routePath, element: /* @__PURE__ */ jsx(Fragment, { children: content }) }) });
35
+ }
36
+ function RoutedShell({
37
+ initialEntries = ["/"],
38
+ initialIndex,
39
+ children,
40
+ onHistoryReady
41
+ }) {
42
+ return /* @__PURE__ */ jsx(MemoryRouter, { initialEntries, initialIndex, children: /* @__PURE__ */ jsx(HistoryCapture, { onReady: onHistoryReady, children }) });
43
+ }
44
+ export {
45
+ HistoryCapture,
46
+ RoutedShell,
47
+ buildShallowRouteTree
48
+ };
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"sourcesContent":["import React, { type ReactElement, type ReactNode } from 'react';\r\n\r\nimport {\r\n MemoryRouter,\r\n Route,\r\n Routes,\r\n useLocation,\r\n useNavigate,\r\n} from 'react-router-dom';\r\n\r\nimport type { RouterHistory } from '@page-component-object/core';\r\n\r\nexport type HistoryCaptureProps = {\r\n children: ReactNode;\r\n onReady: (history: RouterHistory) => void;\r\n};\r\n\r\n/** Exposes a live `RouterHistory` to test AppManager after mount. */\r\nexport function HistoryCapture({ children, onReady }: HistoryCaptureProps) {\r\n const navigate = useNavigate();\r\n const location = useLocation();\r\n\r\n React.useEffect(() => {\r\n const routerHistory: RouterHistory = {\r\n get location() {\r\n return {\r\n pathname: location.pathname,\r\n search: location.search,\r\n hash: location.hash,\r\n };\r\n },\r\n push: (path: string) => {\r\n void navigate(path);\r\n },\r\n };\r\n onReady(routerHistory);\r\n }, [navigate, location, onReady]);\r\n\r\n return <>{children}</>;\r\n}\r\n\r\nexport type MemoryRouterProps = {\r\n initialEntries?: string[];\r\n initialIndex?: number;\r\n};\r\n\r\nexport type ShallowRouteOptions = {\r\n routePath?: string;\r\n wrapLayout?: (children: ReactElement) => ReactNode;\r\n};\r\n\r\n/** Builds the routed subtree for shallow view renders. */\r\nexport function buildShallowRouteTree(\r\n element: ReactElement,\r\n { routePath, wrapLayout }: ShallowRouteOptions,\r\n): ReactElement {\r\n if (!routePath) return element;\r\n\r\n const content = wrapLayout ? wrapLayout(element) : element;\r\n return (\r\n <Routes>\r\n <Route path={routePath} element={<>{content}</>} />\r\n </Routes>\r\n );\r\n}\r\n\r\nexport type RoutedShellProps = MemoryRouterProps & {\r\n children: ReactNode;\r\n onHistoryReady: (history: RouterHistory) => void;\r\n};\r\n\r\nexport function RoutedShell({\r\n initialEntries = ['/'],\r\n initialIndex,\r\n children,\r\n onHistoryReady,\r\n}: RoutedShellProps) {\r\n return (\r\n <MemoryRouter initialEntries={initialEntries} initialIndex={initialIndex}>\r\n <HistoryCapture onReady={onHistoryReady}>{children}</HistoryCapture>\r\n </MemoryRouter>\r\n );\r\n}\r\n"],"mappings":";AAAA,OAAO,WAAkD;AAEzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA8BE;AApBF,SAAS,eAAe,EAAE,UAAU,QAAQ,GAAwB;AACzE,QAAM,WAAW,YAAY;AAC7B,QAAM,WAAW,YAAY;AAE7B,QAAM,UAAU,MAAM;AACpB,UAAM,gBAA+B;AAAA,MACnC,IAAI,WAAW;AACb,eAAO;AAAA,UACL,UAAU,SAAS;AAAA,UACnB,QAAQ,SAAS;AAAA,UACjB,MAAM,SAAS;AAAA,QACjB;AAAA,MACF;AAAA,MACA,MAAM,CAAC,SAAiB;AACtB,aAAK,SAAS,IAAI;AAAA,MACpB;AAAA,IACF;AACA,YAAQ,aAAa;AAAA,EACvB,GAAG,CAAC,UAAU,UAAU,OAAO,CAAC;AAEhC,SAAO,gCAAG,UAAS;AACrB;AAaO,SAAS,sBACd,SACA,EAAE,WAAW,WAAW,GACV;AACd,MAAI,CAAC,UAAW,QAAO;AAEvB,QAAM,UAAU,aAAa,WAAW,OAAO,IAAI;AACnD,SACE,oBAAC,UACC,8BAAC,SAAM,MAAM,WAAW,SAAS,gCAAG,mBAAQ,GAAK,GACnD;AAEJ;AAOO,SAAS,YAAY;AAAA,EAC1B,iBAAiB,CAAC,GAAG;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AACF,GAAqB;AACnB,SACE,oBAAC,gBAAa,gBAAgC,cAC5C,8BAAC,kBAAe,SAAS,gBAAiB,UAAS,GACrD;AAEJ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@page-component-object/router-react",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ }
10
+ },
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "dependencies": {
17
+ "@page-component-object/core": "0.1.0"
18
+ },
19
+ "peerDependencies": {
20
+ "react": "^18.0.0 || ^19.0.0",
21
+ "react-dom": "^18.0.0 || ^19.0.0",
22
+ "react-router-dom": "^6.4.0 || ^7.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/react": "^18.3.18",
26
+ "@types/react-dom": "^18.3.5",
27
+ "react": "^18.3.1",
28
+ "react-dom": "^18.3.1",
29
+ "react-router-dom": "^7.6.2",
30
+ "rimraf": "^6.0.1",
31
+ "tsup": "^8.3.5",
32
+ "typescript": "^5.7.2"
33
+ },
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/dvegap95/page-component-test-object.git",
38
+ "directory": "packages/router-react"
39
+ },
40
+ "homepage": "https://github.com/dvegap95/page-component-test-object#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/dvegap95/page-component-test-object/issues"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "scripts": {
48
+ "build": "tsup",
49
+ "typecheck": "tsc --noEmit",
50
+ "clean": "rimraf dist"
51
+ }
52
+ }