@argon-router/react 0.2.2 → 0.3.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/README.md +21 -0
- package/dist/index.cjs +16 -15
- package/dist/index.d.ts +19 -1
- package/dist/index.js +396 -584
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ☄️ argon-router/react
|
|
2
|
+
|
|
3
|
+
Router without a headache
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> argon-router is extermely unstable & maybe buggy. DO NOT USE IN PRODUCTION!
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
For additional information, guides and api reference visit [documentation site](https://movpushmov.dev/argon-router/)
|
|
11
|
+
|
|
12
|
+
## Packages
|
|
13
|
+
|
|
14
|
+
- [@argon-router/core](https://www.npmjs.com/package/@argon-router/core)
|
|
15
|
+
- [@argon-router/react](https://www.npmjs.com/package/@argon-router/react)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm i @argon-router/react
|
|
21
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("react"),X=require("effector-react");var L={exports:{}},k={};/**
|
|
2
2
|
* @license React
|
|
3
|
-
* react-jsx-runtime.production.
|
|
3
|
+
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
5
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Ee;function Oe(){if(Ee)return k;Ee=1;var a=Symbol.for("react.transitional.element"),v=Symbol.for("react.fragment");function d(E,i,l){var b=null;if(l!==void 0&&(b=""+l),i.key!==void 0&&(b=""+i.key),"key"in i){l={};for(var g in i)g!=="key"&&(l[g]=i[g])}else l=i;return i=l.ref,{$$typeof:a,type:E,key:b,ref:i!==void 0?i:null,props:l}}return k.Fragment=v,k.jsx=d,k.jsxs=d,k}var O={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
13
|
-
* Copyright (c)
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function ar(e){return""}var we={};function or(e){{var r=me();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
24
|
-
|
|
25
|
-
Check the top-level render call using <`+t+">.")}return r}}function Te(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(we[t])return;we[t]=!0;var n="";e&&e._owner&&e._owner!==X.current&&(n=" It was passed a child from "+P(e._owner.type)+"."),D(e),d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),D(null)}}function Pe(e,r){{if(typeof e!="object")return;if(G(e))for(var t=0;t<e.length;t++){var n=e[t];Z(n)&&Te(n,r)}else if(Z(e))e._store&&(e._store.validated=!0);else if(e){var u=De(e);if(typeof u=="function"&&u!==e.entries)for(var s=u.call(e),o;!(o=s.next()).done;)Z(o.value)&&Te(o.value,r)}}}function ir(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===i||r.$$typeof===w))t=r.propTypes;else return;if(t){var n=P(r);Be(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!H){H=!0;var u=P(r);d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ur(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){D(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),D(null);break}}e.ref!==null&&(D(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}var Oe={};function Se(e,r,t,n,u,s){{var o=Ve(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var p=ar();p?a+=p:a+=me();var l;e===null?l="null":G(e)?l="array":e!==void 0&&e.$$typeof===y?(l="<"+(P(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):l=typeof e,d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",l,a)}var f=nr(e,r,t,u,s);if(f==null)return f;if(o){var _=r.children;if(_!==void 0)if(n)if(G(_)){for(var F=0;F<_.length;F++)Pe(_[F],e);Object.freeze&&Object.freeze(_)}else d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Pe(_,e)}if(I.call(r,"key")){var x=P(e),h=Object.keys(r).filter(function(vr){return vr!=="key"}),Q=h.length>0?"{key: someKey, "+h.join(": ..., ")+": ...}":"{key: someKey}";if(!Oe[x+Q]){var dr=h.length>0?"{"+h.join(": ..., ")+": ...}":"{}";d(`A props object containing a "key" prop is being spread into JSX:
|
|
17
|
+
*/var be;function Se(){return be||(be=1,process.env.NODE_ENV!=="production"&&function(){function a(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===pe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Y:return"Fragment";case Te:return"Portal";case I:return"Profiler";case Z:return"StrictMode";case $:return"Suspense";case U:return"SuspenseList"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case D:return(e.displayName||"Context")+".Provider";case Q:return(e._context.displayName||"Context")+".Consumer";case M:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case W:return r=e.displayName||null,r!==null?r:a(e.type)||"Memo";case V:r=e._payload,e=e._init;try{return a(e(r))}catch{}}return null}function v(e){return""+e}function d(e){try{v(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),v(e)}}function E(){}function i(){if(p===0){te=console.log,oe=console.info,ne=console.warn,ae=console.error,ue=console.group,ie=console.groupCollapsed,se=console.groupEnd;var e={configurable:!0,enumerable:!0,value:E,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}p++}function l(){if(p--,p===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:h({},e,{value:te}),info:h({},e,{value:oe}),warn:h({},e,{value:ne}),error:h({},e,{value:ae}),group:h({},e,{value:ue}),groupCollapsed:h({},e,{value:ie}),groupEnd:h({},e,{value:se})})}0>p&&console.error("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}function b(e){if(z===void 0)try{throw Error()}catch(t){var r=t.stack.trim().match(/\n( *(at )?)/);z=r&&r[1]||"",le=-1<t.stack.indexOf(`
|
|
18
|
+
at`)?" (<anonymous>)":-1<t.stack.indexOf("@")?"@unknown:0:0":""}return`
|
|
19
|
+
`+z+e+le}function g(e,r){if(!e||G)return"";var t=J.get(e);if(t!==void 0)return t;G=!0,t=Error.prepareStackTrace,Error.prepareStackTrace=void 0;var n=null;n=_.H,_.H=null,i();try{var c={DetermineComponentFrameRoot:function(){try{if(r){var y=function(){throw Error()};if(Object.defineProperty(y.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(y,[])}catch(w){var S=w}Reflect.construct(e,[],y)}else{try{y.call()}catch(w){S=w}e.call(y.prototype)}}else{try{throw Error()}catch(w){S=w}(y=e())&&typeof y.catch=="function"&&y.catch(function(){})}}catch(w){if(w&&S&&typeof w.stack=="string")return[w.stack,S.stack]}return[null,null]}};c.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var u=Object.getOwnPropertyDescriptor(c.DetermineComponentFrameRoot,"name");u&&u.configurable&&Object.defineProperty(c.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var o=c.DetermineComponentFrameRoot(),R=o[0],j=o[1];if(R&&j){var f=R.split(`
|
|
20
|
+
`),T=j.split(`
|
|
21
|
+
`);for(o=u=0;u<f.length&&!f[u].includes("DetermineComponentFrameRoot");)u++;for(;o<T.length&&!T[o].includes("DetermineComponentFrameRoot");)o++;if(u===f.length||o===T.length)for(u=f.length-1,o=T.length-1;1<=u&&0<=o&&f[u]!==T[o];)o--;for(;1<=u&&0<=o;u--,o--)if(f[u]!==T[o]){if(u!==1||o!==1)do if(u--,o--,0>o||f[u]!==T[o]){var C=`
|
|
22
|
+
`+f[u].replace(" at new "," at ");return e.displayName&&C.includes("<anonymous>")&&(C=C.replace("<anonymous>",e.displayName)),typeof e=="function"&&J.set(e,C),C}while(1<=u&&0<=o);break}}}finally{G=!1,_.H=n,l(),Error.prepareStackTrace=t}return f=(f=e?e.displayName||e.name:"")?b(f):"",typeof e=="function"&&J.set(e,f),f}function m(e){if(e==null)return"";if(typeof e=="function"){var r=e.prototype;return g(e,!(!r||!r.isReactComponent))}if(typeof e=="string")return b(e);switch(e){case $:return b("Suspense");case U:return b("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case M:return e=g(e.render,!1),e;case W:return m(e.type);case V:r=e._payload,e=e._init;try{return m(e(r))}catch{}}return""}function s(){var e=_.A;return e===null?null:e.getOwner()}function A(e){if(re.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function we(e,r){function t(){ce||(ce=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function xe(){var e=a(this.type);return fe[e]||(fe[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function ye(e,r,t,n,c,u){return t=u.ref,e={$$typeof:P,type:e,key:r,props:u,_owner:c},(t!==void 0?t:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:xe}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function B(e,r,t,n,c,u){if(typeof e=="string"||typeof e=="function"||e===Y||e===I||e===Z||e===$||e===U||e===je||typeof e=="object"&&e!==null&&(e.$$typeof===V||e.$$typeof===W||e.$$typeof===D||e.$$typeof===Q||e.$$typeof===M||e.$$typeof===Ce||e.getModuleId!==void 0)){var o=r.children;if(o!==void 0)if(n)if(q(o)){for(n=0;n<o.length;n++)F(o[n],e);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else F(o,e)}else o="",(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),e===null?n="null":q(e)?n="array":e!==void 0&&e.$$typeof===P?(n="<"+(a(e.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):n=typeof e,console.error("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",n,o);if(re.call(r,"key")){o=a(e);var R=Object.keys(r).filter(function(f){return f!=="key"});n=0<R.length?"{key: someKey, "+R.join(": ..., ")+": ...}":"{key: someKey}",de[o+n]||(R=0<R.length?"{"+R.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
26
23
|
let props = %s;
|
|
27
24
|
<%s {...props} />
|
|
28
25
|
React keys must be passed directly to JSX without using spread:
|
|
29
26
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,
|
|
27
|
+
<%s key={someKey} {...props} />`,n,o,R,o),de[o+n]=!0)}if(o=null,t!==void 0&&(d(t),o=""+t),A(r)&&(d(r.key),o=""+r.key),"key"in r){t={};for(var j in r)j!=="key"&&(t[j]=r[j])}else t=r;return o&&we(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),ye(e,o,u,c,s(),t)}function F(e,r){if(typeof e=="object"&&e&&e.$$typeof!==ke){if(q(e))for(var t=0;t<e.length;t++){var n=e[t];N(n)&&K(n,r)}else if(N(e))e._store&&(e._store.validated=1);else if(e===null||typeof e!="object"?t=null:(t=ee&&e[ee]||e["@@iterator"],t=typeof t=="function"?t:null),typeof t=="function"&&t!==e.entries&&(t=t.call(e),t!==e))for(;!(e=t.next()).done;)N(e.value)&&K(e.value,r)}}function N(e){return typeof e=="object"&&e!==null&&e.$$typeof===P}function K(e,r){if(e._store&&!e._store.validated&&e.key==null&&(e._store.validated=1,r=_e(r),!ve[r])){ve[r]=!0;var t="";e&&e._owner!=null&&e._owner!==s()&&(t=null,typeof e._owner.tag=="number"?t=a(e._owner.type):typeof e._owner.name=="string"&&(t=e._owner.name),t=" It was passed a child from "+t+".");var n=_.getCurrentStack;_.getCurrentStack=function(){var c=m(e.type);return n&&(c+=n()||""),c},console.error('Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',r,t),_.getCurrentStack=n}}function _e(e){var r="",t=s();return t&&(t=a(t.type))&&(r=`
|
|
28
|
+
|
|
29
|
+
Check the render method of \``+t+"`."),r||(e=a(e))&&(r=`
|
|
30
|
+
|
|
31
|
+
Check the top-level render call using <`+e+">."),r}var he=H,P=Symbol.for("react.transitional.element"),Te=Symbol.for("react.portal"),Y=Symbol.for("react.fragment"),Z=Symbol.for("react.strict_mode"),I=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),D=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),$=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),je=Symbol.for("react.offscreen"),ee=Symbol.iterator,pe=Symbol.for("react.client.reference"),_=he.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,re=Object.prototype.hasOwnProperty,h=Object.assign,Ce=Symbol.for("react.client.reference"),q=Array.isArray,p=0,te,oe,ne,ae,ue,ie,se;E.__reactDisabledLog=!0;var z,le,G=!1,J=new(typeof WeakMap=="function"?WeakMap:Map),ke=Symbol.for("react.client.reference"),ce,fe={},de={},ve={};O.Fragment=Y,O.jsx=function(e,r,t,n,c){return B(e,r,t,!1,n,c)},O.jsxs=function(e,r,t,n,c){return B(e,r,t,!0,n,c)}}()),O}process.env.NODE_ENV==="production"?L.exports=Oe():L.exports=Se();var x=L.exports;const ge=H.createContext(null),Ae=a=>x.jsx(ge.Provider,{value:a.router,children:a.children});function me(){const a=H.useContext(ge);if(!a)throw new Error("[useRouter] Router not found. Add RouterProvider in app root");return a}function Re(){return X.useUnit(me())}function Ne(a){const{to:v,params:d,onClick:E,ref:i,...l}=a,{mappedRoutes:b}=me(),g=b.find(({route:s})=>s===v),{onOpen:m}=X.useUnit(v);if(!g){const{internal:s}=v;throw new Error(`[Link] Route with path "${s.path}" not found. Maybe it is not passed into createRouter?`)}return x.jsx("a",{...l,ref:i,href:g.toPath(d??void 0),onClick:s=>{E==null||E(s),!s.defaultPrevented&&(l.target&&l.target!=="_self"||s.metaKey||s.altKey||s.ctrlKey||s.shiftKey||(s.preventDefault(),m({params:d||{}})))}})}const Pe=a=>({...a,view:()=>{const{view:v,layout:d,route:E}=a,{isOpened:i}=X.useUnit(E);return i?d?x.jsx(d,{children:x.jsx(v,{})}):x.jsx(v,{}):null}}),Ye=a=>{const{routes:v,otherwise:d}=a;return()=>{const{activeRoutes:E}=Re(),i=E.reduce((m,s)=>m.filter(A=>A!==s.internal.parent),E),l=v.find(m=>m.route===i.at(-1));if(!l)return d?x.jsx(d,{}):null;const{view:b,layout:g}=l;return g?x.jsx(g,{children:x.jsx(b,{})}):x.jsx(b,{})}};exports.Link=Ne;exports.RouterProvider=Ae;exports.createRouteView=Pe;exports.createRoutesView=Ye;exports.useRouter=Re;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AnchorHTMLAttributes } from 'react';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
3
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
4
|
+
import { Query } from '@argon-router/core';
|
|
4
5
|
import { ReactNode } from 'react';
|
|
6
|
+
import { RefObject } from 'react';
|
|
5
7
|
import { Route } from '@argon-router/core';
|
|
6
8
|
import { Router } from '@argon-router/core';
|
|
7
9
|
|
|
@@ -10,6 +12,7 @@ declare type AnchorProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>
|
|
|
10
12
|
declare type BaseLinkProps<Params> = {
|
|
11
13
|
to: Route<Params>;
|
|
12
14
|
children?: ReactNode;
|
|
15
|
+
ref?: RefObject<HTMLAnchorElement>;
|
|
13
16
|
} & AnchorProps;
|
|
14
17
|
|
|
15
18
|
export declare const createRoutesView: (props: CreateRoutesViewProps) => () => JSX_2.Element | null;
|
|
@@ -50,6 +53,21 @@ declare interface RouterProviderProps {
|
|
|
50
53
|
router: Router;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
export declare function useRouter():
|
|
56
|
+
export declare function useRouter(): {
|
|
57
|
+
query: Query;
|
|
58
|
+
path: string;
|
|
59
|
+
activeRoutes: Route<any>[];
|
|
60
|
+
onBack: () => void;
|
|
61
|
+
onForward: () => void;
|
|
62
|
+
onNavigate: (payload: {
|
|
63
|
+
path: string;
|
|
64
|
+
query: Query;
|
|
65
|
+
replace?: boolean;
|
|
66
|
+
}) => {
|
|
67
|
+
path: string;
|
|
68
|
+
query: Query;
|
|
69
|
+
replace?: boolean;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
54
72
|
|
|
55
73
|
export { }
|