path-router-red 0.4.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.
Files changed (94) hide show
  1. package/README.md +427 -0
  2. package/dist/PathRouter/Container/ModalsContainer.d.ts +17 -0
  3. package/dist/PathRouter/Container/ModalsContainer.d.ts.map +1 -0
  4. package/dist/PathRouter/Container/ModalsContainer.js +39 -0
  5. package/dist/PathRouter/Container/ModalsContainer.js.map +1 -0
  6. package/dist/PathRouter/Container/RouterContainer.d.ts +16 -0
  7. package/dist/PathRouter/Container/RouterContainer.d.ts.map +1 -0
  8. package/dist/PathRouter/Container/RouterContainer.js +20 -0
  9. package/dist/PathRouter/Container/RouterContainer.js.map +1 -0
  10. package/dist/PathRouter/Container/index.d.ts +2 -0
  11. package/dist/PathRouter/Container/index.d.ts.map +1 -0
  12. package/dist/PathRouter/Container/index.js +18 -0
  13. package/dist/PathRouter/Container/index.js.map +1 -0
  14. package/dist/PathRouter/NavLink/NavLink.d.ts +40 -0
  15. package/dist/PathRouter/NavLink/NavLink.d.ts.map +1 -0
  16. package/dist/PathRouter/NavLink/NavLink.js +67 -0
  17. package/dist/PathRouter/NavLink/NavLink.js.map +1 -0
  18. package/dist/PathRouter/NavLink/index.d.ts +3 -0
  19. package/dist/PathRouter/NavLink/index.d.ts.map +1 -0
  20. package/dist/PathRouter/NavLink/index.js +6 -0
  21. package/dist/PathRouter/NavLink/index.js.map +1 -0
  22. package/dist/PathRouter/Provider/PathProvider.d.ts +10 -0
  23. package/dist/PathRouter/Provider/PathProvider.d.ts.map +1 -0
  24. package/dist/PathRouter/Provider/PathProvider.js +158 -0
  25. package/dist/PathRouter/Provider/PathProvider.js.map +1 -0
  26. package/dist/PathRouter/Provider/context.d.ts +3 -0
  27. package/dist/PathRouter/Provider/context.d.ts.map +1 -0
  28. package/dist/PathRouter/Provider/context.js +34 -0
  29. package/dist/PathRouter/Provider/context.js.map +1 -0
  30. package/dist/PathRouter/Provider/index.d.ts +3 -0
  31. package/dist/PathRouter/Provider/index.d.ts.map +1 -0
  32. package/dist/PathRouter/Provider/index.js +19 -0
  33. package/dist/PathRouter/Provider/index.js.map +1 -0
  34. package/dist/PathRouter/Provider/usePath.d.ts +15 -0
  35. package/dist/PathRouter/Provider/usePath.d.ts.map +1 -0
  36. package/dist/PathRouter/Provider/usePath.js +22 -0
  37. package/dist/PathRouter/Provider/usePath.js.map +1 -0
  38. package/dist/PathRouter/createPathRouter.d.ts +52 -0
  39. package/dist/PathRouter/createPathRouter.d.ts.map +1 -0
  40. package/dist/PathRouter/createPathRouter.js +72 -0
  41. package/dist/PathRouter/createPathRouter.js.map +1 -0
  42. package/dist/PathRouter/index.d.ts +41 -0
  43. package/dist/PathRouter/index.d.ts.map +1 -0
  44. package/dist/PathRouter/index.js +49 -0
  45. package/dist/PathRouter/index.js.map +1 -0
  46. package/dist/PathRouter/types.d.ts +91 -0
  47. package/dist/PathRouter/types.d.ts.map +1 -0
  48. package/dist/PathRouter/types.js +3 -0
  49. package/dist/PathRouter/types.js.map +1 -0
  50. package/dist/PathRouter/utils/clearSlash.d.ts +8 -0
  51. package/dist/PathRouter/utils/clearSlash.d.ts.map +1 -0
  52. package/dist/PathRouter/utils/clearSlash.js +21 -0
  53. package/dist/PathRouter/utils/clearSlash.js.map +1 -0
  54. package/dist/PathRouter/utils/createRoute.d.ts +16 -0
  55. package/dist/PathRouter/utils/createRoute.d.ts.map +1 -0
  56. package/dist/PathRouter/utils/createRoute.js +36 -0
  57. package/dist/PathRouter/utils/createRoute.js.map +1 -0
  58. package/dist/PathRouter/utils/index.d.ts +5 -0
  59. package/dist/PathRouter/utils/index.d.ts.map +1 -0
  60. package/dist/PathRouter/utils/index.js +21 -0
  61. package/dist/PathRouter/utils/index.js.map +1 -0
  62. package/dist/PathRouter/utils/parseSearch.d.ts +4 -0
  63. package/dist/PathRouter/utils/parseSearch.d.ts.map +1 -0
  64. package/dist/PathRouter/utils/parseSearch.js +15 -0
  65. package/dist/PathRouter/utils/parseSearch.js.map +1 -0
  66. package/dist/PathRouter/utils/setters.d.ts +9 -0
  67. package/dist/PathRouter/utils/setters.d.ts.map +1 -0
  68. package/dist/PathRouter/utils/setters.js +25 -0
  69. package/dist/PathRouter/utils/setters.js.map +1 -0
  70. package/dist/index.d.ts +2 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +18 -0
  73. package/dist/index.js.map +1 -0
  74. package/package.json +32 -0
  75. package/src/PathRouter/Container/ModalsContainer.tsx +92 -0
  76. package/src/PathRouter/Container/RouterContainer.tsx +66 -0
  77. package/src/PathRouter/Container/index.ts +1 -0
  78. package/src/PathRouter/NavLink/NavLink.tsx +146 -0
  79. package/src/PathRouter/NavLink/index.ts +2 -0
  80. package/src/PathRouter/Provider/PathProvider.tsx +220 -0
  81. package/src/PathRouter/Provider/context.ts +33 -0
  82. package/src/PathRouter/Provider/index.ts +2 -0
  83. package/src/PathRouter/Provider/usePath.ts +21 -0
  84. package/src/PathRouter/createPathRouter.tsx +104 -0
  85. package/src/PathRouter/index.ts +79 -0
  86. package/src/PathRouter/readme.md +427 -0
  87. package/src/PathRouter/types.ts +139 -0
  88. package/src/PathRouter/utils/clearSlash.ts +16 -0
  89. package/src/PathRouter/utils/createRoute.ts +53 -0
  90. package/src/PathRouter/utils/index.ts +4 -0
  91. package/src/PathRouter/utils/parseSearch.ts +15 -0
  92. package/src/PathRouter/utils/setters.ts +8 -0
  93. package/src/index.ts +1 -0
  94. package/tsconfig.json +19 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NavLink = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const usePath_1 = require("../Provider/usePath");
7
+ const clearSlash_1 = require("../utils/clearSlash");
8
+ /** Internal — must match the splitter used by `PathProvider`. */
9
+ const modalSplitter = "/modal/";
10
+ const isModifiedEvent = (e) => e.metaKey || e.ctrlKey || e.shiftKey || e.altKey;
11
+ const NavLinkInner = (0, react_1.forwardRef)(({ to, modal, modalBreadCrumbs, replace, navigateOptions, className, activeClassName, onClick, target, children, ...rest }, ref) => {
12
+ const { page, modal: modalCtx } = (0, usePath_1.usePath)();
13
+ /* ── Resolve the canonical href (always a real, shareable URL) ── */
14
+ const targetPagePath = to ? (0, clearSlash_1.clearSlash)(to) : page.path;
15
+ const tail = (modalBreadCrumbs || []).filter(Boolean).join("/");
16
+ const href = (0, clearSlash_1.clearSlash)(modal
17
+ ? `${targetPagePath}${modalSplitter}${modal}${tail ? `/${tail}` : ""}`
18
+ : targetPagePath);
19
+ /* ── Active state ── */
20
+ const isPageActive = !to || page.path === targetPagePath;
21
+ const isModalActive = modal
22
+ ? modalCtx.isOpen && modalCtx.name === modal
23
+ : !modalCtx.isOpen || !to;
24
+ const isActive = (!!to || !!modal) && isPageActive && (modal ? isModalActive : true);
25
+ /* ── Click handler: keep native behaviour for "open in new tab" ── */
26
+ const handleClick = (e) => {
27
+ if (onClick)
28
+ onClick(e);
29
+ if (e.defaultPrevented)
30
+ return;
31
+ // Let the browser do its thing for non-primary buttons, modifier keys,
32
+ // or links explicitly targeted to another window/frame.
33
+ if (e.button !== 0 ||
34
+ isModifiedEvent(e) ||
35
+ (target && target !== "_self")) {
36
+ return;
37
+ }
38
+ // Nothing to navigate to — behave as a regular anchor.
39
+ if (!to && !modal)
40
+ return;
41
+ e.preventDefault();
42
+ const opts = { replace, ...navigateOptions };
43
+ // Single `navigate` call covers both "go to page" and
44
+ // "go to page + open modal" cases — the provider derives
45
+ // the modal state from the resulting pathname.
46
+ page.navigate(href, opts);
47
+ };
48
+ return ((0, jsx_runtime_1.jsx)("a", { ...rest, ref: ref, href: href, target: target, onClick: handleClick, "aria-current": isActive ? "page" : undefined, "data-active": isActive || undefined, className: `${className || ''} ${(isActive && activeClassName) || ''}`, children: children }));
49
+ });
50
+ NavLinkInner.displayName = "NavLink";
51
+ /**
52
+ * Router-aware anchor.
53
+ *
54
+ * Renders a real `<a href>` (so right-click / "open in new tab" / SSR work)
55
+ * and intercepts the primary-button click to call `page.navigate` /
56
+ * open a modal through the `PathRouter` context.
57
+ *
58
+ * ```tsx
59
+ * <NavLink<typeof config> to="add">Add item</NavLink>
60
+ * <NavLink<typeof config> modal="confirm">Open confirm</NavLink>
61
+ * <NavLink<typeof config> to="users" modal="confirm" modalBreadCrumbs={["step-2"]}>
62
+ * Go to users + open confirm at step 2
63
+ * </NavLink>
64
+ * ```
65
+ */
66
+ exports.NavLink = NavLinkInner;
67
+ //# sourceMappingURL=NavLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavLink.js","sourceRoot":"","sources":["../../../src/PathRouter/NavLink/NavLink.tsx"],"names":[],"mappings":";;;;AAAA,iCAMe;AAGf,iDAA8C;AAC9C,oDAAiD;AAOjD,iEAAiE;AACjE,MAAM,aAAa,GAAG,SAAS,CAAC;AAuBhC,MAAM,eAAe,GAAG,CAAC,CAAgC,EAAE,EAAE,CAC3D,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,MAAM,CAAC;AAEnD,MAAM,YAAY,GAAG,IAAA,kBAAU,EAC7B,CACE,EACE,EAAE,EACF,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,EACR,GAAG,IAAI,EACR,EACD,GAAG,EACH,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,iBAAO,GAAE,CAAC;IAE5C,qEAAqE;IACrE,MAAM,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC,IAAA,uBAAU,EAAC,EAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACjE,MAAM,IAAI,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,C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tD,yDAAyD;QACzD,+CAA+C;QAC/C,IAAI,CAAC,QAAQ,CAAC,IAAwB,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC;IAEF,OAAO,CACL,iCACM,IAAI,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,kBACN,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,iBAC9B,QAAQ,IAAI,SAAS,EAClC,SAAS,EAAE,GAAG,SAAS,IAAI,EAAE,IAAI,CAAC,QAAQ,IAAI,eAAe,CAAC,IAAI,EAAE,EAAE,YAErE,QAAQ,GACP,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,YAAY,CAAC,WAAW,GAAG,SAAS,CAAC;AAErC;;;;;;;;;;;;;;GAcG;AACU,QAAA,OAAO,GAAG,YAIO,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { NavLink } from "./NavLink";
2
+ export type { NavLinkProps } from "./NavLink";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/PathRouter/NavLink/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NavLink = void 0;
4
+ var NavLink_1 = require("./NavLink");
5
+ Object.defineProperty(exports, "NavLink", { enumerable: true, get: function () { return NavLink_1.NavLink; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/PathRouter/NavLink/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
@@ -0,0 +1,10 @@
1
+ import { type FC, type ReactNode } from "react";
2
+ export interface PathProviderProps {
3
+ children?: ReactNode;
4
+ }
5
+ /**
6
+ * Wraps the application with `BrowserRouter` and the `PathContext`.
7
+ * Place this near the root of your component tree.
8
+ */
9
+ export declare const PathProvider: FC<PathProviderProps>;
10
+ //# sourceMappingURL=PathProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathProvider.d.ts","sourceRoot":"","sources":["../../../src/PathRouter/Provider/PathProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAC;AAoB7E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AA2LD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAM9C,CAAC"}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathProvider = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_router_dom_1 = require("react-router-dom");
7
+ const clearSlash_1 = require("../utils/clearSlash");
8
+ const parseSearch_1 = require("../utils/parseSearch");
9
+ const context_1 = require("./context");
10
+ const modalSplitter = "/modal/";
11
+ const InnerProvider = ({ children }) => {
12
+ const navigate = (0, react_router_dom_1.useNavigate)();
13
+ const location = (0, react_router_dom_1.useLocation)();
14
+ /** Derive page path & modal state from location.pathname (no extra render cycle). */
15
+ const { pagePath, modalState } = (0, react_1.useMemo)(() => {
16
+ const [rawPagePath, modalPath] = location.pathname.split(modalSplitter);
17
+ const segments = (modalPath || "").split("/").filter(Boolean);
18
+ const name = segments[0];
19
+ const breadCrumbs = segments.slice(1);
20
+ return {
21
+ pagePath: (0, clearSlash_1.clearSlash)(rawPagePath || "/"),
22
+ modalState: {
23
+ name,
24
+ breadCrumbs,
25
+ path: segments.join("/"),
26
+ isOpen: !!name,
27
+ },
28
+ };
29
+ }, [location.pathname]);
30
+ /** Derive search params from location.search. */
31
+ const searchParams = (0, react_1.useMemo)(() => {
32
+ const usp = new URLSearchParams(location.search);
33
+ const out = {};
34
+ for (const [key, value] of usp.entries()) {
35
+ const arr = out[key];
36
+ if (!arr)
37
+ out[key] = [value];
38
+ else
39
+ arr.push(value);
40
+ }
41
+ return out;
42
+ }, [location.search]);
43
+ const setModal = (0, react_1.useCallback)((name, breadCrumbs) => {
44
+ const tail = (breadCrumbs || []).filter(Boolean).join("/");
45
+ const next = (0, clearSlash_1.clearSlash)(`${pagePath}${modalSplitter}${name}${tail ? `/${tail}` : ""}`);
46
+ navigate(next);
47
+ }, [navigate, pagePath]);
48
+ const closeModal = (0, react_1.useCallback)(() => {
49
+ navigate((0, clearSlash_1.clearSlash)(pagePath));
50
+ }, [navigate, pagePath]);
51
+ const setPath = (0, react_1.useCallback)((to, options) => {
52
+ if (typeof to === "string") {
53
+ const next = (0, clearSlash_1.clearSlash)(to);
54
+ if (next === location.pathname)
55
+ return;
56
+ navigate(next, options);
57
+ }
58
+ else {
59
+ if (to.pathname &&
60
+ to.pathname === location.pathname &&
61
+ (to.search ?? "") === location.search &&
62
+ (to.hash ?? "") === location.hash) {
63
+ return;
64
+ }
65
+ navigate({
66
+ ...to,
67
+ pathname: to.pathname ? (0, clearSlash_1.clearSlash)(to.pathname) : to.pathname,
68
+ }, options);
69
+ }
70
+ }, [navigate, location.pathname, location.search, location.hash]);
71
+ const pageNavigate = (0, react_1.useCallback)((path, options) => {
72
+ setPath(path, options);
73
+ }, [setPath]);
74
+ /** Merge: string -> set, array -> append. Preserves hash. */
75
+ const changeSearchParams = (0, react_1.useCallback)((next) => {
76
+ navigate({
77
+ pathname: location.pathname,
78
+ search: (0, parseSearch_1.parseSearchParams)(next, location).toString(),
79
+ hash: location.hash,
80
+ });
81
+ }, [navigate, location]);
82
+ /** Replace fully: each provided key is overwritten with given value(s). */
83
+ const setSearchParams = (0, react_1.useCallback)((next) => {
84
+ const params = new URLSearchParams(location.search);
85
+ Object.entries(next).forEach(([key, value]) => {
86
+ params.delete(key);
87
+ if (typeof value === "string") {
88
+ params.append(key, value);
89
+ }
90
+ else {
91
+ value.forEach((v) => params.append(key, v));
92
+ }
93
+ });
94
+ navigate({
95
+ pathname: location.pathname,
96
+ search: params.toString(),
97
+ hash: location.hash,
98
+ });
99
+ }, [navigate, location]);
100
+ const deleteSearchParams = (0, react_1.useCallback)((key) => {
101
+ const params = new URLSearchParams(location.search);
102
+ params.delete(key);
103
+ navigate({
104
+ pathname: location.pathname,
105
+ search: params.toString(),
106
+ hash: location.hash,
107
+ });
108
+ }, [navigate, location]);
109
+ const clearSearchParams = (0, react_1.useCallback)(() => {
110
+ navigate({
111
+ pathname: location.pathname,
112
+ search: "",
113
+ hash: location.hash,
114
+ });
115
+ }, [navigate, location]);
116
+ const value = (0, react_1.useMemo)(() => ({
117
+ page: {
118
+ path: pagePath,
119
+ navigate: pageNavigate,
120
+ isHavePrevHistory: location.key !== "default",
121
+ },
122
+ modal: {
123
+ ...modalState,
124
+ open: setModal,
125
+ close: closeModal,
126
+ },
127
+ searchParams: {
128
+ params: searchParams,
129
+ change: changeSearchParams,
130
+ set: setSearchParams,
131
+ delete: deleteSearchParams,
132
+ clear: clearSearchParams,
133
+ },
134
+ defaultLocation: location,
135
+ }), [
136
+ pagePath,
137
+ pageNavigate,
138
+ location,
139
+ modalState,
140
+ setModal,
141
+ closeModal,
142
+ searchParams,
143
+ changeSearchParams,
144
+ setSearchParams,
145
+ deleteSearchParams,
146
+ clearSearchParams,
147
+ ]);
148
+ return (0, jsx_runtime_1.jsx)(context_1.PathContext.Provider, { value: value, children: children });
149
+ };
150
+ /**
151
+ * Wraps the application with `BrowserRouter` and the `PathContext`.
152
+ * Place this near the root of your component tree.
153
+ */
154
+ const PathProvider = ({ children }) => {
155
+ return ((0, jsx_runtime_1.jsx)(react_router_dom_1.BrowserRouter, { children: (0, jsx_runtime_1.jsx)(InnerProvider, { children: children }) }));
156
+ };
157
+ exports.PathProvider = PathProvider;
158
+ //# sourceMappingURL=PathProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathProvider.js","sourceRoot":"","sources":["../../../src/PathRouter/Provider/PathProvider.tsx"],"names":[],"mappings":";;;;AAAA,iCAA6E;AAC7E,uDAO0B;AAQ1B,oDAAiD;AACjD,sDAAyD;AACzD,uCAAwC;AAMxC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC,MAAM,aAAa,GAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC5D,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAC;IAE/B,qFAAqF;IACrF,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAA,eAAO,EAGrC,GAAG,EAAE;QACN,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAGrE,CAAC;QAEF,MAAM,QAAQ,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEtC,OAAO;YACL,QAAQ,EAAE,IAAA,uBAAU,EAAC,WAAW,IAAI,GAAG,CAAC;YACxC,UAAU,EAAE;gBACV,IAAI;gBACJ,WAAW;gBACX,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;gBACxB,MAAM,EAAE,CAAC,CAAC,IAAI;aACf;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAExB,iDAAiD;IACjD,MAAM,YAAY,GAAG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AAE;IAClE,OAAO,CACL,uBAAC,gCAAa,cACZ,uBAAC,aAAa,cAAE,QAAQ,GAAiB,GAC3B,CACjB,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB"}
@@ -0,0 +1,3 @@
1
+ import { type PathContextType } from "../types";
2
+ export declare const PathContext: import("react").Context<PathContextType<import("../types").RouterConfig<any, any>>>;
3
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/PathRouter/Provider/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AA+BhD,eAAO,MAAM,WAAW,qFAAgD,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathContext = void 0;
4
+ const react_1 = require("react");
5
+ const defaultValues = {
6
+ page: {
7
+ path: "",
8
+ navigate: () => { },
9
+ isHavePrevHistory: false,
10
+ },
11
+ modal: {
12
+ open: () => { },
13
+ close: () => { },
14
+ path: "",
15
+ breadCrumbs: [],
16
+ isOpen: false,
17
+ },
18
+ searchParams: {
19
+ params: {},
20
+ change: () => { },
21
+ set: () => { },
22
+ clear: () => { },
23
+ delete: () => { },
24
+ },
25
+ defaultLocation: {
26
+ hash: "",
27
+ key: "",
28
+ pathname: "",
29
+ search: "",
30
+ state: {},
31
+ },
32
+ };
33
+ exports.PathContext = (0, react_1.createContext)(defaultValues);
34
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/PathRouter/Provider/context.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AAGtC,MAAM,aAAa,GAAoB;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;QAClB,iBAAiB,EAAE,KAAK;KACzB;IACD,KAAK,EAAE;QACL,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,IAAI,EAAE,EAAE;QACR,WAAW,EAAE,EAAE;QACf,MAAM,EAAE,KAAK;KACd;IACD,YAAY,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;QAChB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;QACb,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;KACjB;IACD,eAAe,EAAE;QACf,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,EAAE;QACP,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE;KACV;CACF,CAAC;AAEW,QAAA,WAAW,GAAG,IAAA,qBAAa,EAAkB,aAAa,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./PathProvider";
2
+ export * from "./usePath";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/PathRouter/Provider/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./PathProvider"), exports);
18
+ __exportStar(require("./usePath"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/PathRouter/Provider/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,4CAA0B"}
@@ -0,0 +1,15 @@
1
+ import type { PathContextType, RouterConfig } from "../types";
2
+ /**
3
+ * Access the router context.
4
+ *
5
+ * Pass `typeof yourConfig` as the generic to get fully typed
6
+ * `page.navigate(...)` and `modal.open(...)` arguments:
7
+ *
8
+ * ```ts
9
+ * const { page, modal } = usePath<typeof config>();
10
+ * page.navigate("add"); // typed
11
+ * modal.open("test"); // typed
12
+ * ```
13
+ */
14
+ export declare const usePath: <C extends RouterConfig<any, any> = RouterConfig<any, any>>() => PathContextType<C>;
15
+ //# sourceMappingURL=usePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePath.d.ts","sourceRoot":"","sources":["../../../src/PathRouter/Provider/usePath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,GAClB,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,OACtD,eAAe,CAAC,CAAC,CAErB,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePath = void 0;
4
+ const react_1 = require("react");
5
+ const context_1 = require("./context");
6
+ /**
7
+ * Access the router context.
8
+ *
9
+ * Pass `typeof yourConfig` as the generic to get fully typed
10
+ * `page.navigate(...)` and `modal.open(...)` arguments:
11
+ *
12
+ * ```ts
13
+ * const { page, modal } = usePath<typeof config>();
14
+ * page.navigate("add"); // typed
15
+ * modal.open("test"); // typed
16
+ * ```
17
+ */
18
+ const usePath = () => {
19
+ return (0, react_1.useContext)(context_1.PathContext);
20
+ };
21
+ exports.usePath = usePath;
22
+ //# sourceMappingURL=usePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePath.js","sourceRoot":"","sources":["../../../src/PathRouter/Provider/usePath.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,uCAAwC;AAGxC;;;;;;;;;;;GAWG;AACI,MAAM,OAAO,GAAG,GAEC,EAAE;IACxB,OAAO,IAAA,kBAAU,EAAC,qBAAW,CAAkC,CAAC;AAClE,CAAC,CAAC;AAJW,QAAA,OAAO,WAIlB"}
@@ -0,0 +1,52 @@
1
+ import React, { type ReactNode, type Ref } from "react";
2
+ import { type NavLinkProps } from "./NavLink";
3
+ import type { ModalNamesOf, ModalWrapperComponent, PathContextType, PathNamesOf, RouterConfig } from "./types";
4
+ /**
5
+ * Bound `PathRouterContainer` props — `config` is captured by the factory,
6
+ * so the consumer only needs to pass presentation-related options.
7
+ */
8
+ export interface BoundPathRouterContainerProps {
9
+ ModalWrapper?: ModalWrapperComponent;
10
+ fallback?: ReactNode;
11
+ }
12
+ export interface BoundNavLinkProps<C extends RouterConfig<any, any>> extends NavLinkProps<C> {
13
+ }
14
+ /**
15
+ * Build a router instance bound to a concrete config.
16
+ *
17
+ * All returned helpers are pre-typed against the supplied config — no need
18
+ * to thread `typeof config` through every call site.
19
+ *
20
+ * ```ts
21
+ * import { setPage, setModal, createPathRouter } from "@/modules/PathRouter";
22
+ *
23
+ * const config = {
24
+ * pages: { home: setPage({ component: Home }) },
25
+ * modals: { test: setModal({ component: TestModal }) },
26
+ * } as const;
27
+ *
28
+ * export const {
29
+ * PathProvider,
30
+ * PathRouterContainer,
31
+ * usePath,
32
+ * NavLink,
33
+ * getPath,
34
+ * getModal,
35
+ * } = createPathRouter(config);
36
+ * ```
37
+ */
38
+ export declare const createPathRouter: <const C extends RouterConfig<any, any>>(config: C) => {
39
+ /** `BrowserRouter` + context provider — does not depend on the config. */
40
+ PathProvider: React.FC<import("./Provider/PathProvider").PathProviderProps>;
41
+ PathRouterContainer: React.FC<BoundPathRouterContainerProps>;
42
+ usePath: () => PathContextType<C>;
43
+ NavLink: (props: BoundNavLinkProps<C> & {
44
+ ref?: Ref<HTMLAnchorElement>;
45
+ }) => React.ReactElement | null;
46
+ getPath: <P extends PathNamesOf<C>>(path: P) => P;
47
+ getModal: <M extends ModalNamesOf<C>>(name: M) => M;
48
+ /** The original config, re-exported for convenience. */
49
+ config: C;
50
+ };
51
+ export type PathRouter<C extends RouterConfig<any, any>> = ReturnType<typeof createPathRouter<C>>;
52
+ //# sourceMappingURL=createPathRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPathRouter.d.ts","sourceRoot":"","sources":["../../src/PathRouter/createPathRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAc,MAAM,OAAO,CAAC;AAKpE,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB,CAChC,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAChC,SAAQ,YAAY,CAAC,CAAC,CAAC;CAAG;AAE5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EACrE,QAAQ,CAAC;IAqCP,0EAA0E;;;mBAlCxD,eAAe,CAAC,CAAC,CAAC;qBAU7B,iBAAiB,CAAC,CAAC,CAAC,GAAG;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAA;KAAE,KAC3D,KAAK,CAAC,YAAY,GAAG,IAAI;cAUb,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAG,CAAC;eAUpC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAG,CAAC;IAUtD,wDAAwD;;CAG3D,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,UAAU,CACnE,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAC3B,CAAC"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPathRouter = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const context_1 = require("./Provider/context");
7
+ const PathProvider_1 = require("./Provider/PathProvider");
8
+ const RouterContainer_1 = require("./Container/RouterContainer");
9
+ const NavLink_1 = require("./NavLink");
10
+ /**
11
+ * Build a router instance bound to a concrete config.
12
+ *
13
+ * All returned helpers are pre-typed against the supplied config — no need
14
+ * to thread `typeof config` through every call site.
15
+ *
16
+ * ```ts
17
+ * import { setPage, setModal, createPathRouter } from "@/modules/PathRouter";
18
+ *
19
+ * const config = {
20
+ * pages: { home: setPage({ component: Home }) },
21
+ * modals: { test: setModal({ component: TestModal }) },
22
+ * } as const;
23
+ *
24
+ * export const {
25
+ * PathProvider,
26
+ * PathRouterContainer,
27
+ * usePath,
28
+ * NavLink,
29
+ * getPath,
30
+ * getModal,
31
+ * } = createPathRouter(config);
32
+ * ```
33
+ */
34
+ const createPathRouter = (config) => {
35
+ /** Typed `usePath` — `page.navigate` / `modal.open` know your routes. */
36
+ const usePath = () => (0, react_1.useContext)(context_1.PathContext);
37
+ /** Container with `config` already injected. */
38
+ const PathRouterContainer = (props) => (0, jsx_runtime_1.jsx)(RouterContainer_1.PathRouterContainer, { config: config, ...props });
39
+ /** Typed `NavLink` — `to` / `modal` are autocompleted from your config. */
40
+ const NavLink = NavLink_1.NavLink;
41
+ /**
42
+ * Identity helper that constrains its argument to a valid page path
43
+ * for this config. Use it where you need a typed path literal:
44
+ *
45
+ * ```ts
46
+ * page.navigate(getPath("home"));
47
+ * ```
48
+ */
49
+ const getPath = (path) => path;
50
+ /**
51
+ * Identity helper that constrains its argument to a valid modal name
52
+ * for this config.
53
+ *
54
+ * ```ts
55
+ * modal.open(getModal("test"));
56
+ * ```
57
+ */
58
+ const getModal = (name) => name;
59
+ return {
60
+ /** `BrowserRouter` + context provider — does not depend on the config. */
61
+ PathProvider: PathProvider_1.PathProvider,
62
+ PathRouterContainer,
63
+ usePath,
64
+ NavLink,
65
+ getPath,
66
+ getModal,
67
+ /** The original config, re-exported for convenience. */
68
+ config,
69
+ };
70
+ };
71
+ exports.createPathRouter = createPathRouter;
72
+ //# sourceMappingURL=createPathRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPathRouter.js","sourceRoot":"","sources":["../../src/PathRouter/createPathRouter.tsx"],"names":[],"mappings":";;;;AAAA,iCAAoE;AAEpE,gDAAiD;AACjD,0DAA2E;AAC3E,iEAA6F;AAC7F,uCAAsE;AAsBtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,gBAAgB,GAAG,CAC9B,MAAS,EACT,EAAE;IACF,yEAAyE;IACzE,MAAM,OAAO,GAAG,GAAuB,EAAE,CACvC,IAAA,kBAAU,EAAC,qBAAW,CAAkC,CAAC;IAE3D,gDAAgD;IAChD,MAAM,mBAAmB,GAA4C,CACnE,KAAK,EACL,EAAE,CAAC,uBAAC,qCAAuB,IAAC,MAAM,EAAE,MAAM,KAAM,KAAK,GAAI,CAAC;IAE5D,2EAA2E;IAC3E,MAAM,OAAO,GAAG,iBAEc,CAAC;IAE/B;;;;;;;OAOG;IACH,MAAM,OAAO,GAAG,CAA2B,IAAO,EAAK,EAAE,CAAC,IAAI,CAAC;IAE/D;;;;;;;OAOG;IACH,MAAM,QAAQ,GAAG,CAA4B,IAAO,EAAK,EAAE,CAAC,IAAI,CAAC;IAEjE,OAAO;QACL,0EAA0E;QAC1E,YAAY,EAAE,2BAAgB;QAC9B,mBAAmB;QACnB,OAAO;QACP,OAAO;QACP,OAAO;QACP,QAAQ;QACR,wDAAwD;QACxD,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAhDW,QAAA,gBAAgB,oBAgD3B"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * PathRouter — public API.
3
+ *
4
+ * Everything that depends on a concrete config is produced by
5
+ * `createPathRouter(config)`. The package itself only exposes:
6
+ *
7
+ * - `setPage` / `setModal` — config builders;
8
+ * - `createPathRouter` — the factory;
9
+ * - `clearSlash` — path normalizer;
10
+ * - generic helper types — must be parametrised with `typeof config`;
11
+ * - plugin / data types — for `ModalWrapper` authors and modal
12
+ * components (`ModalProps`, etc.).
13
+ *
14
+ * `PathProvider`, `PathRouterContainer`, `usePath`, `NavLink`, `getPath`,
15
+ * `getModal` are intentionally **not** re-exported — obtain them from
16
+ * `createPathRouter(config)`.
17
+ *
18
+ * ```ts
19
+ * import { setPage, setModal, createPathRouter } from "@/modules/PathRouter";
20
+ *
21
+ * const config = {
22
+ * pages: { home: setPage({ component: Home }) },
23
+ * modals: { test: setModal({ component: TestModal }) },
24
+ * } as const;
25
+ *
26
+ * export const {
27
+ * PathProvider,
28
+ * PathRouterContainer,
29
+ * usePath,
30
+ * NavLink,
31
+ * getPath,
32
+ * getModal,
33
+ * } = createPathRouter(config);
34
+ * ```
35
+ */
36
+ export { setPage, setModal } from "./utils/setters";
37
+ export { createPathRouter } from "./createPathRouter";
38
+ export type { BoundPathRouterContainerProps, BoundNavLinkProps, PathRouter, } from "./createPathRouter";
39
+ export { clearSlash } from "./utils/clearSlash";
40
+ export type { RouterConfig, PageData, ModalData, ModalProps, PathNamesOf, ModalNamesOf, ModalState, SearchParams, SearchParamsState, ModalWrapperComponent, ModalWrapperProps, ModalWrapperRef, } from "./types";
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/PathRouter/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EACV,6BAA6B,EAC7B,iBAAiB,EACjB,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAYhD,YAAY,EAEV,YAAY,EACZ,QAAQ,EACR,SAAS,EAET,UAAU,EAEV,WAAW,EACX,YAAY,EAEZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EAEjB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,GAChB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * PathRouter — public API.
4
+ *
5
+ * Everything that depends on a concrete config is produced by
6
+ * `createPathRouter(config)`. The package itself only exposes:
7
+ *
8
+ * - `setPage` / `setModal` — config builders;
9
+ * - `createPathRouter` — the factory;
10
+ * - `clearSlash` — path normalizer;
11
+ * - generic helper types — must be parametrised with `typeof config`;
12
+ * - plugin / data types — for `ModalWrapper` authors and modal
13
+ * components (`ModalProps`, etc.).
14
+ *
15
+ * `PathProvider`, `PathRouterContainer`, `usePath`, `NavLink`, `getPath`,
16
+ * `getModal` are intentionally **not** re-exported — obtain them from
17
+ * `createPathRouter(config)`.
18
+ *
19
+ * ```ts
20
+ * import { setPage, setModal, createPathRouter } from "@/modules/PathRouter";
21
+ *
22
+ * const config = {
23
+ * pages: { home: setPage({ component: Home }) },
24
+ * modals: { test: setModal({ component: TestModal }) },
25
+ * } as const;
26
+ *
27
+ * export const {
28
+ * PathProvider,
29
+ * PathRouterContainer,
30
+ * usePath,
31
+ * NavLink,
32
+ * getPath,
33
+ * getModal,
34
+ * } = createPathRouter(config);
35
+ * ```
36
+ */
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.clearSlash = exports.createPathRouter = exports.setModal = exports.setPage = void 0;
39
+ /* Config builders */
40
+ var setters_1 = require("./utils/setters");
41
+ Object.defineProperty(exports, "setPage", { enumerable: true, get: function () { return setters_1.setPage; } });
42
+ Object.defineProperty(exports, "setModal", { enumerable: true, get: function () { return setters_1.setModal; } });
43
+ /* The factory — the only way to get config-bound router pieces */
44
+ var createPathRouter_1 = require("./createPathRouter");
45
+ Object.defineProperty(exports, "createPathRouter", { enumerable: true, get: function () { return createPathRouter_1.createPathRouter; } });
46
+ /* Path normalizer */
47
+ var clearSlash_1 = require("./utils/clearSlash");
48
+ Object.defineProperty(exports, "clearSlash", { enumerable: true, get: function () { return clearSlash_1.clearSlash; } });
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/PathRouter/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,qBAAqB;AACrB,2CAAoD;AAA3C,kGAAA,OAAO,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAE1B,kEAAkE;AAClE,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AAOzB,qBAAqB;AACrB,iDAAgD;AAAvC,wGAAA,UAAU,OAAA"}