@real-router/react 0.28.0 → 0.28.1
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/dist/cjs/ink.d.ts.map +1 -1
- package/dist/cjs/ink.js +1 -1
- package/dist/cjs/ink.js.map +1 -1
- package/dist/esm/ink.d.mts.map +1 -1
- package/dist/esm/ink.mjs +1 -1
- package/dist/esm/ink.mjs.map +1 -1
- package/package.json +3 -3
package/dist/cjs/ink.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ink.d.ts","names":[],"sources":["../../src/ink-types.ts","../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"mappings":";;;;;;;UAGiB,YAAA,WAAuB,MAAA,GAAS,MAAA;EAC/C,SAAA;EACA,WAAA,GAAc,CAAA;EACd,YAAA,GAAe,iBAAA;EACf,YAAA;EACA,iBAAA;EACA,QAAA,GAAW,SAAA;EACX,KAAA;EACA,WAAA;EACA,UAAA;EACA,OAAA;EACA,aAAA;EACA,YAAA;EACA,EAAA;EACA,SAAA;EACA,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,MAAA,EAAQ,MAAA;EACR,QAAA,GAAW,SAAS;AAAA;;;
|
|
1
|
+
{"version":3,"file":"ink.d.ts","names":[],"sources":["../../src/ink-types.ts","../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"mappings":";;;;;;;UAGiB,YAAA,WAAuB,MAAA,GAAS,MAAA;EAC/C,SAAA;EACA,WAAA,GAAc,CAAA;EACd,YAAA,GAAe,iBAAA;EACf,YAAA;EACA,iBAAA;EACA,QAAA,GAAW,SAAA;EACX,KAAA;EACA,WAAA;EACA,UAAA;EACA,OAAA;EACA,aAAA;EACA,YAAA;EACA,EAAA;EACA,SAAA;EACA,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,MAAA,EAAQ,MAAA;EACR,QAAA,GAAW,SAAS;AAAA;;;cC8HT,OAAA,EAAS,EAAE,CAAC,YAAA;;;cChJZ,iBAAA,EAAmB,EAAE,CAAC,sBAAA"}
|
package/dist/cjs/ink.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useRoute-D2vAzKWM.js"),t=require("./RouterProvider-C4LfJ83g.js");let n=require("react"),r=require("react/jsx-runtime"),i=require("ink");function a(e,t,n,r,i){return e?n??r??i:t?r??i:i}function o(e,n){return e.routeName===n.routeName&&e.activeStrict===n.activeStrict&&e.ignoreQueryParams===n.ignoreQueryParams&&e.color===n.color&&e.activeColor===n.activeColor&&e.focusColor===n.focusColor&&e.inverse===n.inverse&&e.activeInverse===n.activeInverse&&e.focusInverse===n.focusInverse&&e.id===n.id&&e.autoFocus===n.autoFocus&&e.onSelect===n.onSelect&&e.children===n.children&&t.u(e.routeParams,n.routeParams)&&t.u(e.routeOptions,n.routeOptions)}const s=(0,n.memo)(({routeName:n,routeParams:o,routeOptions:s=e.n,activeStrict:c=!1,ignoreQueryParams:l=!0,color:u,activeColor:d,focusColor:f,inverse:p,activeInverse:m,focusInverse:h,id:g,autoFocus:_,onSelect:v,children:y})=>{let b=t.p(),{isFocused:x}=(0,i.useFocus)({...g!==void 0&&{id:g},..._!==void 0&&{autoFocus:_}}),S=t.o(n,o,c,l),C=o??e.r;(0,i.useInput)((e,t)=>{t.return
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useRoute-D2vAzKWM.js"),t=require("./RouterProvider-C4LfJ83g.js");let n=require("react"),r=require("react/jsx-runtime"),i=require("ink");function a(e,t,n,r,i){return e?n??r??i:t?r??i:i}function o(e,n){return e.routeName===n.routeName&&e.activeStrict===n.activeStrict&&e.ignoreQueryParams===n.ignoreQueryParams&&e.color===n.color&&e.activeColor===n.activeColor&&e.focusColor===n.focusColor&&e.inverse===n.inverse&&e.activeInverse===n.activeInverse&&e.focusInverse===n.focusInverse&&e.id===n.id&&e.autoFocus===n.autoFocus&&e.onSelect===n.onSelect&&e.children===n.children&&t.u(e.routeParams,n.routeParams)&&t.u(e.routeOptions,n.routeOptions)}const s=(0,n.memo)(({routeName:n,routeParams:o,routeOptions:s=e.n,activeStrict:c=!1,ignoreQueryParams:l=!0,color:u,activeColor:d,focusColor:f,inverse:p,activeInverse:m,focusInverse:h,id:g,autoFocus:_,onSelect:v,children:y})=>{let b=t.p(),{isFocused:x}=(0,i.useFocus)({...g!==void 0&&{id:g},..._!==void 0&&{autoFocus:_}}),S=t.o(n,o,c,l),C=o??e.r;(0,i.useInput)((e,t)=>{if(t.return){try{v?.()}catch(e){console.error(`[real-router] InkLink onSelect threw; proceeding with navigation.`,e)}b.navigate(n,C,s).catch(()=>{})}},{isActive:x});let w=a(x,S,f,d,u),T=a(x,S,h,m,p),E={};return w!==void 0&&(E.color=w),T!==void 0&&(E.inverse=T),(0,r.jsx)(i.Text,{...E,children:y})},o);s.displayName=`InkLink`;const c=({router:e,children:n})=>(0,r.jsx)(t.t,{router:e,children:n});exports.InkLink=s,exports.InkRouterProvider=c,exports.RouterErrorBoundary=t.a,exports.useNavigator=t.i,exports.useRoute=e.t,exports.useRouteNode=t.f,exports.useRouteUtils=t.r,exports.useRouter=t.p,exports.useRouterTransition=t.n;
|
|
2
2
|
//# sourceMappingURL=ink.js.map
|
package/dist/cjs/ink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ink.js","names":["shallowEqual","EMPTY_OPTIONS","useRouter","useIsActiveRoute","EMPTY_PARAMS","Text","RouterProvider"],"sources":["../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"sourcesContent":["import { Text, useFocus, useInput } from \"ink\";\nimport { memo } from \"react\";\n\nimport { EMPTY_OPTIONS, EMPTY_PARAMS } from \"../constants\";\nimport { shallowEqual } from \"../dom-utils\";\nimport { useIsActiveRoute } from \"../hooks/useIsActiveRoute\";\nimport { useRouter } from \"../hooks/useRouter\";\n\nimport type { InkLinkProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\n/**\n * Pick the most specific value across focus / active / base priority.\n * Focus wins over active; active wins over base. Each layer falls through\n * to the next when its value is undefined, matching the original explicit\n * if/else cascade for both `color` and `inverse`.\n */\nfunction pickPriority<T>(\n isFocused: boolean,\n isRouteActive: boolean,\n focusValue: T | undefined,\n activeValue: T | undefined,\n baseValue: T | undefined,\n): T | undefined {\n if (isFocused) {\n return focusValue ?? activeValue ?? baseValue;\n }\n\n if (isRouteActive) {\n return activeValue ?? baseValue;\n }\n\n return baseValue;\n}\n\nfunction areInkLinkPropsEqual(\n prev: Readonly<InkLinkProps>,\n next: Readonly<InkLinkProps>,\n): boolean {\n return (\n prev.routeName === next.routeName &&\n prev.activeStrict === next.activeStrict &&\n prev.ignoreQueryParams === next.ignoreQueryParams &&\n prev.color === next.color &&\n prev.activeColor === next.activeColor &&\n prev.focusColor === next.focusColor &&\n prev.inverse === next.inverse &&\n prev.activeInverse === next.activeInverse &&\n prev.focusInverse === next.focusInverse &&\n prev.id === next.id &&\n prev.autoFocus === next.autoFocus &&\n prev.onSelect === next.onSelect &&\n prev.children === next.children &&\n shallowEqual(prev.routeParams, next.routeParams) &&\n shallowEqual(prev.routeOptions, next.routeOptions)\n );\n}\n\nconst InkLinkImpl: FC<InkLinkProps> = ({\n routeName,\n routeParams,\n routeOptions = EMPTY_OPTIONS,\n activeStrict = false,\n ignoreQueryParams = true,\n color,\n activeColor,\n focusColor,\n inverse,\n activeInverse,\n focusInverse,\n id,\n autoFocus,\n onSelect,\n children,\n}) => {\n const router = useRouter();\n const { isFocused } = useFocus({\n ...(id !== undefined && { id }),\n ...(autoFocus !== undefined && { autoFocus }),\n });\n\n // Pass `routeParams` straight through (possibly `undefined`) so a no-params\n // `<InkLink>` and a manual `useIsActiveRoute(routeName)` share ONE cached\n // active-route source — `createActiveRouteSource` keys `undefined` as \"\" but\n // EMPTY_PARAMS ({}) as \"{}\", so defaulting before the call would split the\n // same question into a second eager subscription (#776).\n const isRouteActive = useIsActiveRoute(\n routeName,\n routeParams,\n activeStrict,\n ignoreQueryParams,\n );\n\n // Navigation needs a concrete params object — default here only.\n const paramsForNav = routeParams ?? EMPTY_PARAMS;\n\n // No useCallback: `useInput` consumes the handler via its own internal\n // ref; a stable identity provides no cache-bail-out benefit here. Same\n // reasoning as Link's handleClick.\n useInput(\n (_input, key) => {\n if (key.return) {\n onSelect?.();\n router.navigate(routeName, paramsForNav, routeOptions).catch(() => {});\n }\n },\n { isActive: isFocused },\n );\n\n const finalColor = pickPriority(\n isFocused,\n isRouteActive,\n focusColor,\n activeColor,\n color,\n );\n const finalInverse = pickPriority(\n isFocused,\n isRouteActive,\n focusInverse,\n activeInverse,\n inverse,\n );\n\n const textProps: { color?: string; inverse?: boolean } = {};\n\n if (finalColor !== undefined) {\n textProps.color = finalColor;\n }\n\n if (finalInverse !== undefined) {\n textProps.inverse = finalInverse;\n }\n\n return <Text {...textProps}>{children}</Text>;\n};\n\nexport const InkLink: FC<InkLinkProps> = memo(\n InkLinkImpl,\n areInkLinkPropsEqual,\n);\n\nInkLink.displayName = \"InkLink\";\n","import { RouterProvider } from \"../RouterProvider\";\n\nimport type { InkRouterProviderProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\nexport const InkRouterProvider: FC<InkRouterProviderProps> = ({\n router,\n children,\n}) => <RouterProvider router={router}>{children}</RouterProvider>;\n"],"mappings":"8NAiBA,SAAS,EACP,EACA,EACA,EACA,EACA,EACe,CASf,OARI,EACK,GAAc,GAAe,EAGlC,EACK,GAAe,EAGjB,CACT,CAEA,SAAS,EACP,EACA,EACS,CACT,OACE,EAAK,YAAc,EAAK,WACxB,EAAK,eAAiB,EAAK,cAC3B,EAAK,oBAAsB,EAAK,mBAChC,EAAK,QAAU,EAAK,OACpB,EAAK,cAAgB,EAAK,aAC1B,EAAK,aAAe,EAAK,YACzB,EAAK,UAAY,EAAK,SACtB,EAAK,gBAAkB,EAAK,eAC5B,EAAK,eAAiB,EAAK,cAC3B,EAAK,KAAO,EAAK,IACjB,EAAK,YAAc,EAAK,WACxB,EAAK,WAAa,EAAK,UACvB,EAAK,WAAa,EAAK,UACvBA,EAAAA,EAAa,EAAK,YAAa,EAAK,WAAW,GAC/CA,EAAAA,EAAa,EAAK,aAAc,EAAK,YAAY,CAErD,
|
|
1
|
+
{"version":3,"file":"ink.js","names":["shallowEqual","EMPTY_OPTIONS","useRouter","useIsActiveRoute","EMPTY_PARAMS","Text","RouterProvider"],"sources":["../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"sourcesContent":["import { Text, useFocus, useInput } from \"ink\";\nimport { memo } from \"react\";\n\nimport { EMPTY_OPTIONS, EMPTY_PARAMS } from \"../constants\";\nimport { shallowEqual } from \"../dom-utils\";\nimport { useIsActiveRoute } from \"../hooks/useIsActiveRoute\";\nimport { useRouter } from \"../hooks/useRouter\";\n\nimport type { InkLinkProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\n/**\n * Pick the most specific value across focus / active / base priority.\n * Focus wins over active; active wins over base. Each layer falls through\n * to the next when its value is undefined, matching the original explicit\n * if/else cascade for both `color` and `inverse`.\n */\nfunction pickPriority<T>(\n isFocused: boolean,\n isRouteActive: boolean,\n focusValue: T | undefined,\n activeValue: T | undefined,\n baseValue: T | undefined,\n): T | undefined {\n if (isFocused) {\n return focusValue ?? activeValue ?? baseValue;\n }\n\n if (isRouteActive) {\n return activeValue ?? baseValue;\n }\n\n return baseValue;\n}\n\nfunction areInkLinkPropsEqual(\n prev: Readonly<InkLinkProps>,\n next: Readonly<InkLinkProps>,\n): boolean {\n return (\n prev.routeName === next.routeName &&\n prev.activeStrict === next.activeStrict &&\n prev.ignoreQueryParams === next.ignoreQueryParams &&\n prev.color === next.color &&\n prev.activeColor === next.activeColor &&\n prev.focusColor === next.focusColor &&\n prev.inverse === next.inverse &&\n prev.activeInverse === next.activeInverse &&\n prev.focusInverse === next.focusInverse &&\n prev.id === next.id &&\n prev.autoFocus === next.autoFocus &&\n prev.onSelect === next.onSelect &&\n prev.children === next.children &&\n shallowEqual(prev.routeParams, next.routeParams) &&\n shallowEqual(prev.routeOptions, next.routeOptions)\n );\n}\n\nconst InkLinkImpl: FC<InkLinkProps> = ({\n routeName,\n routeParams,\n routeOptions = EMPTY_OPTIONS,\n activeStrict = false,\n ignoreQueryParams = true,\n color,\n activeColor,\n focusColor,\n inverse,\n activeInverse,\n focusInverse,\n id,\n autoFocus,\n onSelect,\n children,\n}) => {\n const router = useRouter();\n const { isFocused } = useFocus({\n ...(id !== undefined && { id }),\n ...(autoFocus !== undefined && { autoFocus }),\n });\n\n // Pass `routeParams` straight through (possibly `undefined`) so a no-params\n // `<InkLink>` and a manual `useIsActiveRoute(routeName)` share ONE cached\n // active-route source — `createActiveRouteSource` keys `undefined` as \"\" but\n // EMPTY_PARAMS ({}) as \"{}\", so defaulting before the call would split the\n // same question into a second eager subscription (#776).\n const isRouteActive = useIsActiveRoute(\n routeName,\n routeParams,\n activeStrict,\n ignoreQueryParams,\n );\n\n // Navigation needs a concrete params object — default here only.\n const paramsForNav = routeParams ?? EMPTY_PARAMS;\n\n // No useCallback: `useInput` consumes the handler via its own internal\n // ref; a stable identity provides no cache-bail-out benefit here. Same\n // reasoning as Link's handleClick.\n useInput(\n (_input, key) => {\n if (key.return) {\n // Isolate a throwing `onSelect`: unlike the DOM `<Link>` (where the\n // browser contains event-listener exceptions), an uncaught throw here\n // escapes into ink's stdin handler → `uncaughtException` crashes a real\n // CLI, and it also swallows the navigation below. Log and still\n // navigate — mirrors `route-announcer`'s consumer-callback isolation.\n try {\n onSelect?.();\n } catch (error) {\n console.error(\n \"[real-router] InkLink onSelect threw; proceeding with navigation.\",\n error,\n );\n }\n router.navigate(routeName, paramsForNav, routeOptions).catch(() => {});\n }\n },\n { isActive: isFocused },\n );\n\n const finalColor = pickPriority(\n isFocused,\n isRouteActive,\n focusColor,\n activeColor,\n color,\n );\n const finalInverse = pickPriority(\n isFocused,\n isRouteActive,\n focusInverse,\n activeInverse,\n inverse,\n );\n\n const textProps: { color?: string; inverse?: boolean } = {};\n\n if (finalColor !== undefined) {\n textProps.color = finalColor;\n }\n\n if (finalInverse !== undefined) {\n textProps.inverse = finalInverse;\n }\n\n return <Text {...textProps}>{children}</Text>;\n};\n\nexport const InkLink: FC<InkLinkProps> = memo(\n InkLinkImpl,\n areInkLinkPropsEqual,\n);\n\nInkLink.displayName = \"InkLink\";\n","import { RouterProvider } from \"../RouterProvider\";\n\nimport type { InkRouterProviderProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\nexport const InkRouterProvider: FC<InkRouterProviderProps> = ({\n router,\n children,\n}) => <RouterProvider router={router}>{children}</RouterProvider>;\n"],"mappings":"8NAiBA,SAAS,EACP,EACA,EACA,EACA,EACA,EACe,CASf,OARI,EACK,GAAc,GAAe,EAGlC,EACK,GAAe,EAGjB,CACT,CAEA,SAAS,EACP,EACA,EACS,CACT,OACE,EAAK,YAAc,EAAK,WACxB,EAAK,eAAiB,EAAK,cAC3B,EAAK,oBAAsB,EAAK,mBAChC,EAAK,QAAU,EAAK,OACpB,EAAK,cAAgB,EAAK,aAC1B,EAAK,aAAe,EAAK,YACzB,EAAK,UAAY,EAAK,SACtB,EAAK,gBAAkB,EAAK,eAC5B,EAAK,eAAiB,EAAK,cAC3B,EAAK,KAAO,EAAK,IACjB,EAAK,YAAc,EAAK,WACxB,EAAK,WAAa,EAAK,UACvB,EAAK,WAAa,EAAK,UACvBA,EAAAA,EAAa,EAAK,YAAa,EAAK,WAAW,GAC/CA,EAAAA,EAAa,EAAK,aAAc,EAAK,YAAY,CAErD,CA6FA,MAAa,GAAA,EAAA,EAAA,KAAA,EA3F0B,CACrC,YACA,cACA,eAAeC,EAAAA,EACf,eAAe,GACf,oBAAoB,GACpB,QACA,cACA,aACA,UACA,gBACA,eACA,KACA,YACA,WACA,cACI,CACJ,IAAM,EAASC,EAAAA,EAAU,EACnB,CAAE,cAAA,EAAA,EAAA,SAAA,CAAuB,CAC7B,GAAI,IAAO,IAAA,IAAa,CAAE,IAAG,EAC7B,GAAI,IAAc,IAAA,IAAa,CAAE,WAAU,CAC7C,CAAC,EAOK,EAAgBC,EAAAA,EACpB,EACA,EACA,EACA,CACF,EAGM,EAAe,GAAeC,EAAAA,GAKpC,EAAA,EAAA,SAAA,EACG,EAAQ,IAAQ,CACf,GAAI,EAAI,OAAQ,CAMd,GAAI,CACF,IAAW,CACb,OAAS,EAAO,CACd,QAAQ,MACN,oEACA,CACF,CACF,CACA,EAAO,SAAS,EAAW,EAAc,CAAY,CAAC,CAAC,UAAY,CAAC,CAAC,CACvE,CACF,EACA,CAAE,SAAU,CAAU,CACxB,EAEA,IAAM,EAAa,EACjB,EACA,EACA,EACA,EACA,CACF,EACM,EAAe,EACnB,EACA,EACA,EACA,EACA,CACF,EAEM,EAAmD,CAAC,EAU1D,OARI,IAAe,IAAA,KACjB,EAAU,MAAQ,GAGhB,IAAiB,IAAA,KACnB,EAAU,QAAU,IAGf,EAAA,EAAA,IAAA,CAACC,EAAAA,KAAD,CAAM,GAAI,EAAY,UAAe,CAAA,CAC9C,EAIE,CACF,EAEA,EAAQ,YAAc,UCrJtB,MAAa,GAAiD,CAC5D,SACA,eACI,EAAA,EAAA,IAAA,CAACC,EAAAA,EAAD,CAAwB,SAAS,UAAyB,CAAA"}
|
package/dist/esm/ink.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ink.d.mts","names":[],"sources":["../../src/ink-types.ts","../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"mappings":";;;;;;;UAGiB,YAAA,WAAuB,MAAA,GAAS,MAAA;EAC/C,SAAA;EACA,WAAA,GAAc,CAAA;EACd,YAAA,GAAe,iBAAA;EACf,YAAA;EACA,iBAAA;EACA,QAAA,GAAW,SAAA;EACX,KAAA;EACA,WAAA;EACA,UAAA;EACA,OAAA;EACA,aAAA;EACA,YAAA;EACA,EAAA;EACA,SAAA;EACA,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,MAAA,EAAQ,MAAA;EACR,QAAA,GAAW,SAAS;AAAA;;;
|
|
1
|
+
{"version":3,"file":"ink.d.mts","names":[],"sources":["../../src/ink-types.ts","../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"mappings":";;;;;;;UAGiB,YAAA,WAAuB,MAAA,GAAS,MAAA;EAC/C,SAAA;EACA,WAAA,GAAc,CAAA;EACd,YAAA,GAAe,iBAAA;EACf,YAAA;EACA,iBAAA;EACA,QAAA,GAAW,SAAA;EACX,KAAA;EACA,WAAA;EACA,UAAA;EACA,OAAA;EACA,aAAA;EACA,YAAA;EACA,EAAA;EACA,SAAA;EACA,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,MAAA,EAAQ,MAAA;EACR,QAAA,GAAW,SAAS;AAAA;;;cC8HT,OAAA,EAAS,EAAE,CAAC,YAAA;;;cChJZ,iBAAA,EAAmB,EAAE,CAAC,sBAAA"}
|
package/dist/esm/ink.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./useRoute-5MF3j-9P.mjs";import{a as r,f as i,i as a,n as o,o as s,p as c,r as l,t as u,u as d}from"./RouterProvider-DttQ5zhF.mjs";import{memo as f}from"react";import{jsx as p}from"react/jsx-runtime";import{Text as m,useFocus as h,useInput as g}from"ink";function _(e,t,n,r,i){return e?n??r??i:t?r??i:i}function v(e,t){return e.routeName===t.routeName&&e.activeStrict===t.activeStrict&&e.ignoreQueryParams===t.ignoreQueryParams&&e.color===t.color&&e.activeColor===t.activeColor&&e.focusColor===t.focusColor&&e.inverse===t.inverse&&e.activeInverse===t.activeInverse&&e.focusInverse===t.focusInverse&&e.id===t.id&&e.autoFocus===t.autoFocus&&e.onSelect===t.onSelect&&e.children===t.children&&d(e.routeParams,t.routeParams)&&d(e.routeOptions,t.routeOptions)}const y=f(({routeName:n,routeParams:r,routeOptions:i=e,activeStrict:a=!1,ignoreQueryParams:o=!0,color:l,activeColor:u,focusColor:d,inverse:f,activeInverse:v,focusInverse:y,id:b,autoFocus:x,onSelect:S,children:C})=>{let w=c(),{isFocused:T}=h({...b!==void 0&&{id:b},...x!==void 0&&{autoFocus:x}}),E=s(n,r,a,o),D=r??t;g((e,t)=>{t.return
|
|
1
|
+
import{n as e,r as t,t as n}from"./useRoute-5MF3j-9P.mjs";import{a as r,f as i,i as a,n as o,o as s,p as c,r as l,t as u,u as d}from"./RouterProvider-DttQ5zhF.mjs";import{memo as f}from"react";import{jsx as p}from"react/jsx-runtime";import{Text as m,useFocus as h,useInput as g}from"ink";function _(e,t,n,r,i){return e?n??r??i:t?r??i:i}function v(e,t){return e.routeName===t.routeName&&e.activeStrict===t.activeStrict&&e.ignoreQueryParams===t.ignoreQueryParams&&e.color===t.color&&e.activeColor===t.activeColor&&e.focusColor===t.focusColor&&e.inverse===t.inverse&&e.activeInverse===t.activeInverse&&e.focusInverse===t.focusInverse&&e.id===t.id&&e.autoFocus===t.autoFocus&&e.onSelect===t.onSelect&&e.children===t.children&&d(e.routeParams,t.routeParams)&&d(e.routeOptions,t.routeOptions)}const y=f(({routeName:n,routeParams:r,routeOptions:i=e,activeStrict:a=!1,ignoreQueryParams:o=!0,color:l,activeColor:u,focusColor:d,inverse:f,activeInverse:v,focusInverse:y,id:b,autoFocus:x,onSelect:S,children:C})=>{let w=c(),{isFocused:T}=h({...b!==void 0&&{id:b},...x!==void 0&&{autoFocus:x}}),E=s(n,r,a,o),D=r??t;g((e,t)=>{if(t.return){try{S?.()}catch(e){console.error(`[real-router] InkLink onSelect threw; proceeding with navigation.`,e)}w.navigate(n,D,i).catch(()=>{})}},{isActive:T});let O=_(T,E,d,u,l),k=_(T,E,y,v,f),A={};return O!==void 0&&(A.color=O),k!==void 0&&(A.inverse=k),p(m,{...A,children:C})},v);y.displayName=`InkLink`;const b=({router:e,children:t})=>p(u,{router:e,children:t});export{y as InkLink,b as InkRouterProvider,r as RouterErrorBoundary,a as useNavigator,n as useRoute,i as useRouteNode,l as useRouteUtils,c as useRouter,o as useRouterTransition};
|
|
2
2
|
//# sourceMappingURL=ink.mjs.map
|
package/dist/esm/ink.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ink.mjs","names":[],"sources":["../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"sourcesContent":["import { Text, useFocus, useInput } from \"ink\";\nimport { memo } from \"react\";\n\nimport { EMPTY_OPTIONS, EMPTY_PARAMS } from \"../constants\";\nimport { shallowEqual } from \"../dom-utils\";\nimport { useIsActiveRoute } from \"../hooks/useIsActiveRoute\";\nimport { useRouter } from \"../hooks/useRouter\";\n\nimport type { InkLinkProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\n/**\n * Pick the most specific value across focus / active / base priority.\n * Focus wins over active; active wins over base. Each layer falls through\n * to the next when its value is undefined, matching the original explicit\n * if/else cascade for both `color` and `inverse`.\n */\nfunction pickPriority<T>(\n isFocused: boolean,\n isRouteActive: boolean,\n focusValue: T | undefined,\n activeValue: T | undefined,\n baseValue: T | undefined,\n): T | undefined {\n if (isFocused) {\n return focusValue ?? activeValue ?? baseValue;\n }\n\n if (isRouteActive) {\n return activeValue ?? baseValue;\n }\n\n return baseValue;\n}\n\nfunction areInkLinkPropsEqual(\n prev: Readonly<InkLinkProps>,\n next: Readonly<InkLinkProps>,\n): boolean {\n return (\n prev.routeName === next.routeName &&\n prev.activeStrict === next.activeStrict &&\n prev.ignoreQueryParams === next.ignoreQueryParams &&\n prev.color === next.color &&\n prev.activeColor === next.activeColor &&\n prev.focusColor === next.focusColor &&\n prev.inverse === next.inverse &&\n prev.activeInverse === next.activeInverse &&\n prev.focusInverse === next.focusInverse &&\n prev.id === next.id &&\n prev.autoFocus === next.autoFocus &&\n prev.onSelect === next.onSelect &&\n prev.children === next.children &&\n shallowEqual(prev.routeParams, next.routeParams) &&\n shallowEqual(prev.routeOptions, next.routeOptions)\n );\n}\n\nconst InkLinkImpl: FC<InkLinkProps> = ({\n routeName,\n routeParams,\n routeOptions = EMPTY_OPTIONS,\n activeStrict = false,\n ignoreQueryParams = true,\n color,\n activeColor,\n focusColor,\n inverse,\n activeInverse,\n focusInverse,\n id,\n autoFocus,\n onSelect,\n children,\n}) => {\n const router = useRouter();\n const { isFocused } = useFocus({\n ...(id !== undefined && { id }),\n ...(autoFocus !== undefined && { autoFocus }),\n });\n\n // Pass `routeParams` straight through (possibly `undefined`) so a no-params\n // `<InkLink>` and a manual `useIsActiveRoute(routeName)` share ONE cached\n // active-route source — `createActiveRouteSource` keys `undefined` as \"\" but\n // EMPTY_PARAMS ({}) as \"{}\", so defaulting before the call would split the\n // same question into a second eager subscription (#776).\n const isRouteActive = useIsActiveRoute(\n routeName,\n routeParams,\n activeStrict,\n ignoreQueryParams,\n );\n\n // Navigation needs a concrete params object — default here only.\n const paramsForNav = routeParams ?? EMPTY_PARAMS;\n\n // No useCallback: `useInput` consumes the handler via its own internal\n // ref; a stable identity provides no cache-bail-out benefit here. Same\n // reasoning as Link's handleClick.\n useInput(\n (_input, key) => {\n if (key.return) {\n onSelect?.();\n router.navigate(routeName, paramsForNav, routeOptions).catch(() => {});\n }\n },\n { isActive: isFocused },\n );\n\n const finalColor = pickPriority(\n isFocused,\n isRouteActive,\n focusColor,\n activeColor,\n color,\n );\n const finalInverse = pickPriority(\n isFocused,\n isRouteActive,\n focusInverse,\n activeInverse,\n inverse,\n );\n\n const textProps: { color?: string; inverse?: boolean } = {};\n\n if (finalColor !== undefined) {\n textProps.color = finalColor;\n }\n\n if (finalInverse !== undefined) {\n textProps.inverse = finalInverse;\n }\n\n return <Text {...textProps}>{children}</Text>;\n};\n\nexport const InkLink: FC<InkLinkProps> = memo(\n InkLinkImpl,\n areInkLinkPropsEqual,\n);\n\nInkLink.displayName = \"InkLink\";\n","import { RouterProvider } from \"../RouterProvider\";\n\nimport type { InkRouterProviderProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\nexport const InkRouterProvider: FC<InkRouterProviderProps> = ({\n router,\n children,\n}) => <RouterProvider router={router}>{children}</RouterProvider>;\n"],"mappings":"gSAiBA,SAAS,EACP,EACA,EACA,EACA,EACA,EACe,CASf,OARI,EACK,GAAc,GAAe,EAGlC,EACK,GAAe,EAGjB,CACT,CAEA,SAAS,EACP,EACA,EACS,CACT,OACE,EAAK,YAAc,EAAK,WACxB,EAAK,eAAiB,EAAK,cAC3B,EAAK,oBAAsB,EAAK,mBAChC,EAAK,QAAU,EAAK,OACpB,EAAK,cAAgB,EAAK,aAC1B,EAAK,aAAe,EAAK,YACzB,EAAK,UAAY,EAAK,SACtB,EAAK,gBAAkB,EAAK,eAC5B,EAAK,eAAiB,EAAK,cAC3B,EAAK,KAAO,EAAK,IACjB,EAAK,YAAc,EAAK,WACxB,EAAK,WAAa,EAAK,UACvB,EAAK,WAAa,EAAK,UACvB,EAAa,EAAK,YAAa,EAAK,WAAW,GAC/C,EAAa,EAAK,aAAc,EAAK,YAAY,CAErD,
|
|
1
|
+
{"version":3,"file":"ink.mjs","names":[],"sources":["../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"sourcesContent":["import { Text, useFocus, useInput } from \"ink\";\nimport { memo } from \"react\";\n\nimport { EMPTY_OPTIONS, EMPTY_PARAMS } from \"../constants\";\nimport { shallowEqual } from \"../dom-utils\";\nimport { useIsActiveRoute } from \"../hooks/useIsActiveRoute\";\nimport { useRouter } from \"../hooks/useRouter\";\n\nimport type { InkLinkProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\n/**\n * Pick the most specific value across focus / active / base priority.\n * Focus wins over active; active wins over base. Each layer falls through\n * to the next when its value is undefined, matching the original explicit\n * if/else cascade for both `color` and `inverse`.\n */\nfunction pickPriority<T>(\n isFocused: boolean,\n isRouteActive: boolean,\n focusValue: T | undefined,\n activeValue: T | undefined,\n baseValue: T | undefined,\n): T | undefined {\n if (isFocused) {\n return focusValue ?? activeValue ?? baseValue;\n }\n\n if (isRouteActive) {\n return activeValue ?? baseValue;\n }\n\n return baseValue;\n}\n\nfunction areInkLinkPropsEqual(\n prev: Readonly<InkLinkProps>,\n next: Readonly<InkLinkProps>,\n): boolean {\n return (\n prev.routeName === next.routeName &&\n prev.activeStrict === next.activeStrict &&\n prev.ignoreQueryParams === next.ignoreQueryParams &&\n prev.color === next.color &&\n prev.activeColor === next.activeColor &&\n prev.focusColor === next.focusColor &&\n prev.inverse === next.inverse &&\n prev.activeInverse === next.activeInverse &&\n prev.focusInverse === next.focusInverse &&\n prev.id === next.id &&\n prev.autoFocus === next.autoFocus &&\n prev.onSelect === next.onSelect &&\n prev.children === next.children &&\n shallowEqual(prev.routeParams, next.routeParams) &&\n shallowEqual(prev.routeOptions, next.routeOptions)\n );\n}\n\nconst InkLinkImpl: FC<InkLinkProps> = ({\n routeName,\n routeParams,\n routeOptions = EMPTY_OPTIONS,\n activeStrict = false,\n ignoreQueryParams = true,\n color,\n activeColor,\n focusColor,\n inverse,\n activeInverse,\n focusInverse,\n id,\n autoFocus,\n onSelect,\n children,\n}) => {\n const router = useRouter();\n const { isFocused } = useFocus({\n ...(id !== undefined && { id }),\n ...(autoFocus !== undefined && { autoFocus }),\n });\n\n // Pass `routeParams` straight through (possibly `undefined`) so a no-params\n // `<InkLink>` and a manual `useIsActiveRoute(routeName)` share ONE cached\n // active-route source — `createActiveRouteSource` keys `undefined` as \"\" but\n // EMPTY_PARAMS ({}) as \"{}\", so defaulting before the call would split the\n // same question into a second eager subscription (#776).\n const isRouteActive = useIsActiveRoute(\n routeName,\n routeParams,\n activeStrict,\n ignoreQueryParams,\n );\n\n // Navigation needs a concrete params object — default here only.\n const paramsForNav = routeParams ?? EMPTY_PARAMS;\n\n // No useCallback: `useInput` consumes the handler via its own internal\n // ref; a stable identity provides no cache-bail-out benefit here. Same\n // reasoning as Link's handleClick.\n useInput(\n (_input, key) => {\n if (key.return) {\n // Isolate a throwing `onSelect`: unlike the DOM `<Link>` (where the\n // browser contains event-listener exceptions), an uncaught throw here\n // escapes into ink's stdin handler → `uncaughtException` crashes a real\n // CLI, and it also swallows the navigation below. Log and still\n // navigate — mirrors `route-announcer`'s consumer-callback isolation.\n try {\n onSelect?.();\n } catch (error) {\n console.error(\n \"[real-router] InkLink onSelect threw; proceeding with navigation.\",\n error,\n );\n }\n router.navigate(routeName, paramsForNav, routeOptions).catch(() => {});\n }\n },\n { isActive: isFocused },\n );\n\n const finalColor = pickPriority(\n isFocused,\n isRouteActive,\n focusColor,\n activeColor,\n color,\n );\n const finalInverse = pickPriority(\n isFocused,\n isRouteActive,\n focusInverse,\n activeInverse,\n inverse,\n );\n\n const textProps: { color?: string; inverse?: boolean } = {};\n\n if (finalColor !== undefined) {\n textProps.color = finalColor;\n }\n\n if (finalInverse !== undefined) {\n textProps.inverse = finalInverse;\n }\n\n return <Text {...textProps}>{children}</Text>;\n};\n\nexport const InkLink: FC<InkLinkProps> = memo(\n InkLinkImpl,\n areInkLinkPropsEqual,\n);\n\nInkLink.displayName = \"InkLink\";\n","import { RouterProvider } from \"../RouterProvider\";\n\nimport type { InkRouterProviderProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\nexport const InkRouterProvider: FC<InkRouterProviderProps> = ({\n router,\n children,\n}) => <RouterProvider router={router}>{children}</RouterProvider>;\n"],"mappings":"gSAiBA,SAAS,EACP,EACA,EACA,EACA,EACA,EACe,CASf,OARI,EACK,GAAc,GAAe,EAGlC,EACK,GAAe,EAGjB,CACT,CAEA,SAAS,EACP,EACA,EACS,CACT,OACE,EAAK,YAAc,EAAK,WACxB,EAAK,eAAiB,EAAK,cAC3B,EAAK,oBAAsB,EAAK,mBAChC,EAAK,QAAU,EAAK,OACpB,EAAK,cAAgB,EAAK,aAC1B,EAAK,aAAe,EAAK,YACzB,EAAK,UAAY,EAAK,SACtB,EAAK,gBAAkB,EAAK,eAC5B,EAAK,eAAiB,EAAK,cAC3B,EAAK,KAAO,EAAK,IACjB,EAAK,YAAc,EAAK,WACxB,EAAK,WAAa,EAAK,UACvB,EAAK,WAAa,EAAK,UACvB,EAAa,EAAK,YAAa,EAAK,WAAW,GAC/C,EAAa,EAAK,aAAc,EAAK,YAAY,CAErD,CA6FA,MAAa,EAA4B,GA3FF,CACrC,YACA,cACA,eAAe,EACf,eAAe,GACf,oBAAoB,GACpB,QACA,cACA,aACA,UACA,gBACA,eACA,KACA,YACA,WACA,cACI,CACJ,IAAM,EAAS,EAAU,EACnB,CAAE,aAAc,EAAS,CAC7B,GAAI,IAAO,IAAA,IAAa,CAAE,IAAG,EAC7B,GAAI,IAAc,IAAA,IAAa,CAAE,WAAU,CAC7C,CAAC,EAOK,EAAgB,EACpB,EACA,EACA,EACA,CACF,EAGM,EAAe,GAAe,EAKpC,GACG,EAAQ,IAAQ,CACf,GAAI,EAAI,OAAQ,CAMd,GAAI,CACF,IAAW,CACb,OAAS,EAAO,CACd,QAAQ,MACN,oEACA,CACF,CACF,CACA,EAAO,SAAS,EAAW,EAAc,CAAY,CAAC,CAAC,UAAY,CAAC,CAAC,CACvE,CACF,EACA,CAAE,SAAU,CAAU,CACxB,EAEA,IAAM,EAAa,EACjB,EACA,EACA,EACA,EACA,CACF,EACM,EAAe,EACnB,EACA,EACA,EACA,EACA,CACF,EAEM,EAAmD,CAAC,EAU1D,OARI,IAAe,IAAA,KACjB,EAAU,MAAQ,GAGhB,IAAiB,IAAA,KACnB,EAAU,QAAU,GAGf,EAAC,EAAD,CAAM,GAAI,EAAY,UAAe,CAAA,CAC9C,EAIE,CACF,EAEA,EAAQ,YAAc,UCrJtB,MAAa,GAAiD,CAC5D,SACA,cACI,EAAC,EAAD,CAAwB,SAAS,UAAyB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/react",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "React integration for Real-Router",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"sideEffects": false,
|
|
119
119
|
"dependencies": {
|
|
120
120
|
"@real-router/core": "^0.62.3",
|
|
121
|
-
"@real-router/
|
|
122
|
-
"@real-router/
|
|
121
|
+
"@real-router/sources": "^0.10.1",
|
|
122
|
+
"@real-router/route-utils": "^0.2.5"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
125
|
"@testing-library/dom": "10.4.1",
|