@hyeonqyu/typed-router-react 1.8.0 → 1.8.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/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import { TypedLinkHrefObject, PartialRouteTree as PartialRouteTree$1, RouteTree
3
3
  export * from '@hyeonqyu/typed-router-core';
4
4
  import * as react_router from 'react-router';
5
5
  import * as react from 'react';
6
- import { ComponentProps, ReactNode } from 'react';
6
+ import { ComponentPropsWithoutRef, ReactNode } from 'react';
7
7
  import { Link } from 'react-router-dom';
8
8
  import * as react_jsx_runtime from 'react/jsx-runtime';
9
9
 
@@ -53,10 +53,9 @@ type ExtractSearchParams<TNode> = TNode extends {
53
53
  } ? TNode['_metadata']['searchParamsSchema']['_output'] : Record<string, unknown>;
54
54
  type GetRouteNode<TRouteTree, TPath extends string> = TPath extends `/${infer First}/${infer Rest}` ? First extends keyof TRouteTree ? GetRouteNode<TRouteTree[First], `/${Rest}`> : never : TPath extends `/${infer Key}` ? Key extends keyof TRouteTree ? TRouteTree[Key] : never : TRouteTree;
55
55
 
56
- type ReactLinkProps = ComponentProps<typeof Link>;
57
- type TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> = Omit<ReactLinkProps, 'to'> & {
56
+ interface TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> extends Omit<ComponentPropsWithoutRef<typeof Link>, 'to'> {
58
57
  to: TPathname | TypedLinkHrefObject<TPathname, TRouteTree>;
59
- };
58
+ }
60
59
 
61
60
  declare const createAppRoutes: <TMetadata extends {
62
61
  component: ReactNode;
@@ -65,7 +64,7 @@ declare const createAppRoutes: <TMetadata extends {
65
64
  children: ReactNode;
66
65
  }) => react_jsx_runtime.JSX.Element;
67
66
  useAppRoutes: () => ResolvedRouteTree$1<TMetadata, TContext, TRouteTree>;
68
- TypedLink: react.ForwardRefExoticComponent<Omit<TypedLinkProps<RoutePathname$1<TMetadata, TContext, TRouteTree>, TRouteTree>, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
67
+ TypedLink: react.ForwardRefExoticComponent<TypedLinkProps<RoutePathname$1<TMetadata, TContext, TRouteTree>, TRouteTree> & react.RefAttributes<HTMLAnchorElement>>;
69
68
  useTypedNavigate: () => <TPath extends RoutePathname$1<TMetadata, TContext, TRouteTree>>(href: TPath, options?: Omit<react_router.NavigateOptions, "searchParams"> & {
70
69
  searchParams?: _hyeonqyu_typed_router_core.ExtractSearchParams<_hyeonqyu_typed_router_core.GetRouteNode<TRouteTree, TPath>> | undefined;
71
70
  }) => void | Promise<void>;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { TypedLinkHrefObject, PartialRouteTree as PartialRouteTree$1, RouteTree
3
3
  export * from '@hyeonqyu/typed-router-core';
4
4
  import * as react_router from 'react-router';
5
5
  import * as react from 'react';
6
- import { ComponentProps, ReactNode } from 'react';
6
+ import { ComponentPropsWithoutRef, ReactNode } from 'react';
7
7
  import { Link } from 'react-router-dom';
8
8
  import * as react_jsx_runtime from 'react/jsx-runtime';
9
9
 
@@ -53,10 +53,9 @@ type ExtractSearchParams<TNode> = TNode extends {
53
53
  } ? TNode['_metadata']['searchParamsSchema']['_output'] : Record<string, unknown>;
54
54
  type GetRouteNode<TRouteTree, TPath extends string> = TPath extends `/${infer First}/${infer Rest}` ? First extends keyof TRouteTree ? GetRouteNode<TRouteTree[First], `/${Rest}`> : never : TPath extends `/${infer Key}` ? Key extends keyof TRouteTree ? TRouteTree[Key] : never : TRouteTree;
55
55
 
56
- type ReactLinkProps = ComponentProps<typeof Link>;
57
- type TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> = Omit<ReactLinkProps, 'to'> & {
56
+ interface TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> extends Omit<ComponentPropsWithoutRef<typeof Link>, 'to'> {
58
57
  to: TPathname | TypedLinkHrefObject<TPathname, TRouteTree>;
59
- };
58
+ }
60
59
 
61
60
  declare const createAppRoutes: <TMetadata extends {
62
61
  component: ReactNode;
@@ -65,7 +64,7 @@ declare const createAppRoutes: <TMetadata extends {
65
64
  children: ReactNode;
66
65
  }) => react_jsx_runtime.JSX.Element;
67
66
  useAppRoutes: () => ResolvedRouteTree$1<TMetadata, TContext, TRouteTree>;
68
- TypedLink: react.ForwardRefExoticComponent<Omit<TypedLinkProps<RoutePathname$1<TMetadata, TContext, TRouteTree>, TRouteTree>, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
67
+ TypedLink: react.ForwardRefExoticComponent<TypedLinkProps<RoutePathname$1<TMetadata, TContext, TRouteTree>, TRouteTree> & react.RefAttributes<HTMLAnchorElement>>;
69
68
  useTypedNavigate: () => <TPath extends RoutePathname$1<TMetadata, TContext, TRouteTree>>(href: TPath, options?: Omit<react_router.NavigateOptions, "searchParams"> & {
70
69
  searchParams?: _hyeonqyu_typed_router_core.ExtractSearchParams<_hyeonqyu_typed_router_core.GetRouteNode<TRouteTree, TPath>> | undefined;
71
70
  }) => void | Promise<void>;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/navigate.hooks.ts","../src/TypedLink.tsx","../src/index.ts"],"names":["replaceDynamicSegments","toSearchParamsString","useNavigate","forwardRef","jsx","Link","buildTypedHref","coreCreateAppRoutes"],"mappings":";;;;;;;;;AAQO,IAAM,sBAAsB,MAA+D;AAChG,EAAA,MAAM,uBAAA,GAA0B,CAAC,IAAA,EAAiB,YAAA,KAAgC;AAChF,IAAA,MAAM,EAAE,QAAA,EAAU,eAAA,EAAgB,GAAIA,sCAAA,CAAuB,MAAgB,YAAY,CAAA;AACzF,IAAA,OAAO,CAAA,EAAG,QAAQ,CAAA,EAAGC,oCAAA,CAAqB,iBAAiB,EAAE,mBAAA,EAAqB,IAAA,EAAM,CAAC,CAAA,CAAA;AAAA,EAC3F,CAAA;AAEA,EAAA,OAAO,MAAM;AACX,IAAA,MAAM,WAAWC,0BAAA,EAAY;AAE7B,IAAA,OAAO,CAA0B,MAAa,OAAA,K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gBAAA;AAAA,MACA,mBAAA;AAAA,MACA,eAAA;AAAA,MACA,mBAAA;AAAA,MACA,SAAA;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,mBAAmB;AAAC;AACtB,KACF;AAAA,EACF,CAAA;AACF","file":"index.js","sourcesContent":["import { replaceDynamicSegments, SearchParams, SearchParamsForPath, toSearchParamsString } from '@hyeonqyu/typed-router-core';\nimport { NavigateOptions, useNavigate } from 'react-router-dom';\n\ntype TypedNavigateOptions<TSearchParams = SearchParams> = Omit<NavigateOptions, 'searchParams'> & {\n /** Custom typed search params */\n searchParams?: TSearchParams;\n};\n\nexport const createTypedNavigate = <TPathname extends string = string, TRouteTree = unknown>() => {\n const getHrefWithSearchParams = (href: TPathname, searchParams?: SearchParams) => {\n const { pathname, remainingParams } = replaceDynamicSegments(href as string, searchParams);\n return `${pathname}${toSearchParamsString(remainingParams, { includeQuestionMark: true })}`;\n };\n\n return () => {\n const navigate = useNavigate();\n\n return <TPath extends TPathname>(href: TPath, options?: TypedNavigateOptions<SearchParamsForPath<TRouteTree, TPath>>) => {\n const finalHref = getHrefWithSearchParams(href, options?.searchParams as SearchParams);\n return navigate(finalHref, options);\n };\n };\n};\n","import { buildTypedHref, type TypedLinkHrefObject, type SearchParams } from '@hyeonqyu/typed-router-core';\nimport { Link } from 'react-router-dom';\nimport type { ComponentProps, ComponentRef } from 'react';\nimport { forwardRef } from 'react';\n\ntype ReactLinkProps = ComponentProps<typeof Link>;\n\nexport type TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> = Omit<ReactLinkProps, 'to'> & {\n to: TPathname | TypedLinkHrefObject<TPathname, TRouteTree>;\n};\n\nexport const createTypedLink = <TPathname extends string = string, TRouteTree = unknown>() => {\n const TypedLink = forwardRef<ComponentRef<typeof Link>, TypedLinkProps<TPathname, TRouteTree>>((props, ref) => {\n const { to, ...restProps } = props;\n\n if (typeof to === 'string') {\n return <Link ref={ref} to={to} {...restProps} />;\n }\n\n const { pathname, searchParams, hash } = to;\n const finalTo = buildTypedHref(pathname as string, searchParams as SearchParams, hash);\n\n return <Link ref={ref} to={finalTo} {...restProps} />;\n });\n\n TypedLink.displayName = 'TypedLink';\n\n return TypedLink;\n};\n","import { type PartialRouteTree, type ResolvedRouteTree, type RoutePathname, type RouteTree } from '@hyeonqyu/typed-router-core';\nimport { createAppRoutes as coreCreateAppRoutes } from '@hyeonqyu/typed-router-core/routes.utils';\nimport { ReactNode } from 'react';\nimport { createTypedNavigate } from './navigate.hooks';\nimport { createTypedLink } from './TypedLink';\n\nexport const createAppRoutes = <TMetadata extends { component: ReactNode }, TContext>() => {\n return <TRouteTree extends PartialRouteTree<TMetadata, TContext>>(appRoutes: TRouteTree & RouteTree<TMetadata, TContext, TRouteTree>) => {\n const { AppRoutesProvider, useAppRoutes, getPathnameFromNode, freezeAppRoutes, useCurrentRouteNode, _types } = coreCreateAppRoutes<\n TMetadata,\n TContext\n >()(appRoutes);\n\n type Pathname = RoutePathname<TMetadata, TContext, TRouteTree>;\n type Routes = ResolvedRouteTree<TMetadata, TContext, TRouteTree>;\n\n const TypedLink = createTypedLink<Pathname, TRouteTree>();\n const useTypedNavigate = createTypedNavigate<Pathname, TRouteTree>();\n\n return {\n AppRoutesProvider,\n useAppRoutes: useAppRoutes as () => Routes,\n TypedLink,\n useTypedNavigate,\n getPathnameFromNode,\n freezeAppRoutes,\n useCurrentRouteNode,\n appRoutes,\n _types: {\n ..._types,\n AppRoutesPathname: {} as Pathname,\n },\n };\n };\n};\n\nexport * from '@hyeonqyu/typed-router-core';\nexport type { TypedLinkProps } from './TypedLink';\n"]}
1
+ {"version":3,"sources":["../src/navigate.hooks.ts","../src/TypedLink.tsx","../src/index.ts"],"names":["replaceDynamicSegments","toSearchParamsString","useNavigate","forwardRef","jsx","Link","buildTypedHref","coreCreateAppRoutes"],"mappings":";;;;;;;;;AAQO,IAAM,sBAAsB,MAA+D;AAChG,EAAA,MAAM,uBAAA,GAA0B,CAAC,IA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IAAM,kBAAkB,MAA4D;AACzF,EAAA,OAAO,CAA2D,SAAA,KAAuE;AACvI,IAAA,MAAM,EAAE,iBAAA,EAAmB,YAAA,EAAc,mBAAA,EAAqB,eAAA,EAAiB,qBAAqB,MAAA,EAAO,GAAIE,4BAAA,EAG7G,CAAE,SAAS,CAAA;AAKb,IAAA,MAAM,YAAY,eAAA,EAAsC;AACxD,IAAA,MAAM,mBAAmB,mBAAA,EAA0C;AAEnE,IAAA,OAAO;AAAA,MACL,iBAAA;AAAA,MACA,YAAA;AAAA,MACA,SAAA;AAAA,MACA,gBAAA;AAAA,MACA,mBAAA;AAAA,MACA,eAAA;AAAA,MACA,mBAAA;AAAA,MACA,SAAA;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,mBAAmB;AAAC;AACtB,KACF;AAAA,EACF,CAAA;AACF","file":"index.js","sourcesContent":["import { replaceDynamicSegments, SearchParams, SearchParamsForPath, toSearchParamsString } from '@hyeonqyu/typed-router-core';\nimport { NavigateOptions, useNavigate } from 'react-router-dom';\n\ntype TypedNavigateOptions<TSearchParams = SearchParams> = Omit<NavigateOptions, 'searchParams'> & {\n /** Custom typed search params */\n searchParams?: TSearchParams;\n};\n\nexport const createTypedNavigate = <TPathname extends string = string, TRouteTree = unknown>() => {\n const getHrefWithSearchParams = (href: TPathname, searchParams?: SearchParams) => {\n const { pathname, remainingParams } = replaceDynamicSegments(href as string, searchParams);\n return `${pathname}${toSearchParamsString(remainingParams, { includeQuestionMark: true })}`;\n };\n\n return () => {\n const navigate = useNavigate();\n\n return <TPath extends TPathname>(href: TPath, options?: TypedNavigateOptions<SearchParamsForPath<TRouteTree, TPath>>) => {\n const finalHref = getHrefWithSearchParams(href, options?.searchParams as SearchParams);\n return navigate(finalHref, options);\n };\n };\n};\n","import { buildTypedHref, type SearchParams, type TypedLinkHrefObject } from '@hyeonqyu/typed-router-core';\nimport type { ComponentPropsWithoutRef, ComponentRef } from 'react';\nimport { forwardRef } from 'react';\nimport { Link } from 'react-router-dom';\n\nexport interface TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> extends Omit<\n ComponentPropsWithoutRef<typeof Link>,\n 'to'\n> {\n to: TPathname | TypedLinkHrefObject<TPathname, TRouteTree>;\n}\n\nexport const createTypedLink = <TPathname extends string = string, TRouteTree = unknown>() => {\n const TypedLink = forwardRef<ComponentRef<typeof Link>, TypedLinkProps<TPathname, TRouteTree>>((props, ref) => {\n const { to, ...restProps } = props;\n\n if (typeof to === 'string') {\n return <Link ref={ref} to={to} {...restProps} />;\n }\n\n const { pathname, searchParams, hash } = to;\n const finalTo = buildTypedHref(pathname as string, searchParams as SearchParams, hash);\n\n return <Link ref={ref} to={finalTo} {...restProps} />;\n });\n\n TypedLink.displayName = 'TypedLink';\n\n return TypedLink;\n};\n","import { type PartialRouteTree, type ResolvedRouteTree, type RoutePathname, type RouteTree } from '@hyeonqyu/typed-router-core';\nimport { createAppRoutes as coreCreateAppRoutes } from '@hyeonqyu/typed-router-core/routes.utils';\nimport { ReactNode } from 'react';\nimport { createTypedNavigate } from './navigate.hooks';\nimport { createTypedLink } from './TypedLink';\n\nexport const createAppRoutes = <TMetadata extends { component: ReactNode }, TContext>() => {\n return <TRouteTree extends PartialRouteTree<TMetadata, TContext>>(appRoutes: TRouteTree & RouteTree<TMetadata, TContext, TRouteTree>) => {\n const { AppRoutesProvider, useAppRoutes, getPathnameFromNode, freezeAppRoutes, useCurrentRouteNode, _types } = coreCreateAppRoutes<\n TMetadata,\n TContext\n >()(appRoutes);\n\n type Pathname = RoutePathname<TMetadata, TContext, TRouteTree>;\n type Routes = ResolvedRouteTree<TMetadata, TContext, TRouteTree>;\n\n const TypedLink = createTypedLink<Pathname, TRouteTree>();\n const useTypedNavigate = createTypedNavigate<Pathname, TRouteTree>();\n\n return {\n AppRoutesProvider,\n useAppRoutes: useAppRoutes as () => Routes,\n TypedLink,\n useTypedNavigate,\n getPathnameFromNode,\n freezeAppRoutes,\n useCurrentRouteNode,\n appRoutes,\n _types: {\n ..._types,\n AppRoutesPathname: {} as Pathname,\n },\n };\n };\n};\n\nexport * from '@hyeonqyu/typed-router-core';\nexport type { TypedLinkProps } from './TypedLink';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/navigate.hooks.ts","../src/TypedLink.tsx","../src/index.ts"],"names":["coreCreateAppRoutes"],"mappings":";;;;;;;;AAQO,IAAM,sBAAsB,MAA+D;AAChG,EAAA,MAAM,uBAAA,GAA0B,CAAC,IAAA,EAAiB,YAAA,KAAgC;AAChF,IAAA,MAAM,EAAE,QAAA,EAAU,eAAA,EAAgB,GAAI,sBAAA,CAAuB,MAAgB,YAAY,CAAA;AACzF,IAAA,OAAO,CAAA,EAAG,QAAQ,CAAA,EAAG,oBAAA,CAAqB,iBAAiB,EAAE,mBAAA,EAAqB,IAAA,EAAM,CAAC,CAAA,CAAA;AAAA,EAC3F,CAAA;AAEA,EAAA,OAAO,MAAM;AACX,IAAA,MAAM,WAAW,WAAA,EAAY;AAE7B,IAAA,OAAO,CAA0B,MAAa,OAAA,KAA2E;AACvH,MAAA,MAAM,SAAA,GAAY,uBAAA,CAAwB,IAAA,EAAM,OAAA,EAAS,YAA4B,CAAA;AACrF,MAAA,OAAO,QAAA,CAAS,WAAW,OAAO,CAAA;AAAA,IACpC,CAAA;AAAA,EACF,CAAA;AACF,CAAA;ACXO,IAAM,kBAAkB,MAA+D;AAC5F,EAAA,MAAM,SAAA,GAAY,UAAA,CAA6E,CAAC,KAAA,EAAO,GAAA,KAAQ;AAC7G,IAAA,MAAM,EAAE,EAAA,EAAI,GAAG,SAAA,EAAU,GAAI,KAAA;AAE7B,IAAA,IAAI,OAAO,OAAO,QAAA,EAAU;AAC1B,MAAA,uBAAO,GAAA,CAAC,IAAA,EAAA,EAAK,GAAA,EAAU,EAAA,EAAS,GAAG,SAAA,EAAW,CAAA;AAAA,IAChD;AAEA,IAAA,MAAM,EAAE,QAAA,EAAU,YAAA,EAAc,IAAA,EAAK,GAAI,EAAA;AACzC,IAAA,MAAM,OAAA,GAAU,cAAA,CAAe,QAAA,EAAoB,YAAA,EAA8B,IAAI,CAAA;AAErF,IAAA,2BAAQ,IAAA,EAAA,EAAK,GAAA,EAAU,EAAA,EAAI,OAAA,EAAU,GAAG,SAAA,EAAW,CAAA;AAAA,EACrD,CAAC,CAAA;AAED,EAAA,SAAA,CAAU,WAAA,GAAc,WAAA;AAExB,EAAA,OAAO,SAAA;AACT,CAAA;ACtBO,IAAM,kBAAkB,MAA4D;AACzF,EAAA,OAAO,CAA2D,SAAA,KAAuE;AACvI,IAAA,MAAM,EAAE,iBAAA,EAAmB,YAAA,EAAc,mBAAA,EAAqB,eAAA,EAAiB,qBAAqB,MAAA,EAAO,GAAIA,iBAAA,EAG7G,CAAE,SAAS,CAAA;AAKb,IAAA,MAAM,YAAY,eAAA,EAAsC;AACxD,IAAA,MAAM,mBAAmB,mBAAA,EAA0C;AAEnE,IAAA,OAAO;AAAA,MACL,iBAAA;AAAA,MACA,YAAA;AAAA,MACA,SAAA;AAAA,MACA,gBAAA;AAAA,MACA,mBAAA;AAAA,MACA,eAAA;AAAA,MACA,mBAAA;AAAA,MACA,SAAA;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,mBAAmB;AAAC;AACtB,KACF;AAAA,EACF,CAAA;AACF","file":"index.mjs","sourcesContent":["import { replaceDynamicSegments, SearchParams, SearchParamsForPath, toSearchParamsString } from '@hyeonqyu/typed-router-core';\nimport { NavigateOptions, useNavigate } from 'react-router-dom';\n\ntype TypedNavigateOptions<TSearchParams = SearchParams> = Omit<NavigateOptions, 'searchParams'> & {\n /** Custom typed search params */\n searchParams?: TSearchParams;\n};\n\nexport const createTypedNavigate = <TPathname extends string = string, TRouteTree = unknown>() => {\n const getHrefWithSearchParams = (href: TPathname, searchParams?: SearchParams) => {\n const { pathname, remainingParams } = replaceDynamicSegments(href as string, searchParams);\n return `${pathname}${toSearchParamsString(remainingParams, { includeQuestionMark: true })}`;\n };\n\n return () => {\n const navigate = useNavigate();\n\n return <TPath extends TPathname>(href: TPath, options?: TypedNavigateOptions<SearchParamsForPath<TRouteTree, TPath>>) => {\n const finalHref = getHrefWithSearchParams(href, options?.searchParams as SearchParams);\n return navigate(finalHref, options);\n };\n };\n};\n","import { buildTypedHref, type TypedLinkHrefObject, type SearchParams } from '@hyeonqyu/typed-router-core';\nimport { Link } from 'react-router-dom';\nimport type { ComponentProps, ComponentRef } from 'react';\nimport { forwardRef } from 'react';\n\ntype ReactLinkProps = ComponentProps<typeof Link>;\n\nexport type TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> = Omit<ReactLinkProps, 'to'> & {\n to: TPathname | TypedLinkHrefObject<TPathname, TRouteTree>;\n};\n\nexport const createTypedLink = <TPathname extends string = string, TRouteTree = unknown>() => {\n const TypedLink = forwardRef<ComponentRef<typeof Link>, TypedLinkProps<TPathname, TRouteTree>>((props, ref) => {\n const { to, ...restProps } = props;\n\n if (typeof to === 'string') {\n return <Link ref={ref} to={to} {...restProps} />;\n }\n\n const { pathname, searchParams, hash } = to;\n const finalTo = buildTypedHref(pathname as string, searchParams as SearchParams, hash);\n\n return <Link ref={ref} to={finalTo} {...restProps} />;\n });\n\n TypedLink.displayName = 'TypedLink';\n\n return TypedLink;\n};\n","import { type PartialRouteTree, type ResolvedRouteTree, type RoutePathname, type RouteTree } from '@hyeonqyu/typed-router-core';\nimport { createAppRoutes as coreCreateAppRoutes } from '@hyeonqyu/typed-router-core/routes.utils';\nimport { ReactNode } from 'react';\nimport { createTypedNavigate } from './navigate.hooks';\nimport { createTypedLink } from './TypedLink';\n\nexport const createAppRoutes = <TMetadata extends { component: ReactNode }, TContext>() => {\n return <TRouteTree extends PartialRouteTree<TMetadata, TContext>>(appRoutes: TRouteTree & RouteTree<TMetadata, TContext, TRouteTree>) => {\n const { AppRoutesProvider, useAppRoutes, getPathnameFromNode, freezeAppRoutes, useCurrentRouteNode, _types } = coreCreateAppRoutes<\n TMetadata,\n TContext\n >()(appRoutes);\n\n type Pathname = RoutePathname<TMetadata, TContext, TRouteTree>;\n type Routes = ResolvedRouteTree<TMetadata, TContext, TRouteTree>;\n\n const TypedLink = createTypedLink<Pathname, TRouteTree>();\n const useTypedNavigate = createTypedNavigate<Pathname, TRouteTree>();\n\n return {\n AppRoutesProvider,\n useAppRoutes: useAppRoutes as () => Routes,\n TypedLink,\n useTypedNavigate,\n getPathnameFromNode,\n freezeAppRoutes,\n useCurrentRouteNode,\n appRoutes,\n _types: {\n ..._types,\n AppRoutesPathname: {} as Pathname,\n },\n };\n };\n};\n\nexport * from '@hyeonqyu/typed-router-core';\nexport type { TypedLinkProps } from './TypedLink';\n"]}
1
+ {"version":3,"sources":["../src/navigate.hooks.ts","../src/TypedLink.tsx","../src/index.ts"],"names":["coreCreateAppRoutes"],"mappings":";;;;;;;;AAQO,IAAM,sBAAsB,MAA+D;AAChG,EAAA,MAAM,uBAAA,GAA0B,CAAC,IAAA,EAAiB,YAAA,KAAgC;AAChF,IAAA,MAAM,EAAE,QAAA,EAAU,eAAA,EAAgB,GAAI,sBAAA,CAAuB,MAAgB,YAAY,CAAA;AACzF,IAAA,OAAO,CAAA,EAAG,QAAQ,CAAA,EAAG,oBAAA,CAAqB,iBAAiB,EAAE,mBAAA,EAAqB,IAAA,EAAM,CAAC,CAAA,CAAA;AAAA,EAC3F,CAAA;AAEA,EAAA,OAAO,MAAM;AACX,IAAA,MAAM,WAAW,WAAA,EAAY;AAE7B,IAAA,OAAO,CAA0B,MAAa,OAAA,KAA2E;AACvH,MAAA,MAAM,SAAA,GAAY,uBAAA,CAAwB,IAAA,EAAM,OAAA,EAAS,YAA4B,CAAA;AACrF,MAAA,OAAO,QAAA,CAAS,WAAW,OAAO,CAAA;AAAA,IACpC,CAAA;AAAA,EACF,CAAA;AACF,CAAA;ACVO,IAAM,kBAAkB,MAA+D;AAC5F,EAAA,MAAM,SAAA,GAAY,UAAA,CAA6E,CAAC,KAAA,EAAO,GAAA,KAAQ;AAC7G,IAAA,MAAM,EAAE,EAAA,EAAI,GAAG,SAAA,EAAU,GAAI,KAAA;AAE7B,IAAA,IAAI,OAAO,OAAO,QAAA,EAAU;AAC1B,MAAA,uBAAO,GAAA,CAAC,IAAA,EAAA,EAAK,GAAA,EAAU,EAAA,EAAS,GAAG,SAAA,EAAW,CAAA;AAAA,IAChD;AAEA,IAAA,MAAM,EAAE,QAAA,EAAU,YAAA,EAAc,IAAA,EAAK,GAAI,EAAA;AACzC,IAAA,MAAM,OAAA,GAAU,cAAA,CAAe,QAAA,EAAoB,YAAA,EAA8B,IAAI,CAAA;AAErF,IAAA,2BAAQ,IAAA,EAAA,EAAK,GAAA,EAAU,EAAA,EAAI,OAAA,EAAU,GAAG,SAAA,EAAW,CAAA;AAAA,EACrD,CAAC,CAAA;AAED,EAAA,SAAA,CAAU,WAAA,GAAc,WAAA;AAExB,EAAA,OAAO,SAAA;AACT,CAAA;ACvBO,IAAM,kBAAkB,MAA4D;AACzF,EAAA,OAAO,CAA2D,SAAA,KAAuE;AACvI,IAAA,MAAM,EAAE,iBAAA,EAAmB,YAAA,EAAc,mBAAA,EAAqB,eAAA,EAAiB,qBAAqB,MAAA,EAAO,GAAIA,iBAAA,EAG7G,CAAE,SAAS,CAAA;AAKb,IAAA,MAAM,YAAY,eAAA,EAAsC;AACxD,IAAA,MAAM,mBAAmB,mBAAA,EAA0C;AAEnE,IAAA,OAAO;AAAA,MACL,iBAAA;AAAA,MACA,YAAA;AAAA,MACA,SAAA;AAAA,MACA,gBAAA;AAAA,MACA,mBAAA;AAAA,MACA,eAAA;AAAA,MACA,mBAAA;AAAA,MACA,SAAA;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,mBAAmB;AAAC;AACtB,KACF;AAAA,EACF,CAAA;AACF","file":"index.mjs","sourcesContent":["import { replaceDynamicSegments, SearchParams, SearchParamsForPath, toSearchParamsString } from '@hyeonqyu/typed-router-core';\nimport { NavigateOptions, useNavigate } from 'react-router-dom';\n\ntype TypedNavigateOptions<TSearchParams = SearchParams> = Omit<NavigateOptions, 'searchParams'> & {\n /** Custom typed search params */\n searchParams?: TSearchParams;\n};\n\nexport const createTypedNavigate = <TPathname extends string = string, TRouteTree = unknown>() => {\n const getHrefWithSearchParams = (href: TPathname, searchParams?: SearchParams) => {\n const { pathname, remainingParams } = replaceDynamicSegments(href as string, searchParams);\n return `${pathname}${toSearchParamsString(remainingParams, { includeQuestionMark: true })}`;\n };\n\n return () => {\n const navigate = useNavigate();\n\n return <TPath extends TPathname>(href: TPath, options?: TypedNavigateOptions<SearchParamsForPath<TRouteTree, TPath>>) => {\n const finalHref = getHrefWithSearchParams(href, options?.searchParams as SearchParams);\n return navigate(finalHref, options);\n };\n };\n};\n","import { buildTypedHref, type SearchParams, type TypedLinkHrefObject } from '@hyeonqyu/typed-router-core';\nimport type { ComponentPropsWithoutRef, ComponentRef } from 'react';\nimport { forwardRef } from 'react';\nimport { Link } from 'react-router-dom';\n\nexport interface TypedLinkProps<TPathname extends string = string, TRouteTree = unknown> extends Omit<\n ComponentPropsWithoutRef<typeof Link>,\n 'to'\n> {\n to: TPathname | TypedLinkHrefObject<TPathname, TRouteTree>;\n}\n\nexport const createTypedLink = <TPathname extends string = string, TRouteTree = unknown>() => {\n const TypedLink = forwardRef<ComponentRef<typeof Link>, TypedLinkProps<TPathname, TRouteTree>>((props, ref) => {\n const { to, ...restProps } = props;\n\n if (typeof to === 'string') {\n return <Link ref={ref} to={to} {...restProps} />;\n }\n\n const { pathname, searchParams, hash } = to;\n const finalTo = buildTypedHref(pathname as string, searchParams as SearchParams, hash);\n\n return <Link ref={ref} to={finalTo} {...restProps} />;\n });\n\n TypedLink.displayName = 'TypedLink';\n\n return TypedLink;\n};\n","import { type PartialRouteTree, type ResolvedRouteTree, type RoutePathname, type RouteTree } from '@hyeonqyu/typed-router-core';\nimport { createAppRoutes as coreCreateAppRoutes } from '@hyeonqyu/typed-router-core/routes.utils';\nimport { ReactNode } from 'react';\nimport { createTypedNavigate } from './navigate.hooks';\nimport { createTypedLink } from './TypedLink';\n\nexport const createAppRoutes = <TMetadata extends { component: ReactNode }, TContext>() => {\n return <TRouteTree extends PartialRouteTree<TMetadata, TContext>>(appRoutes: TRouteTree & RouteTree<TMetadata, TContext, TRouteTree>) => {\n const { AppRoutesProvider, useAppRoutes, getPathnameFromNode, freezeAppRoutes, useCurrentRouteNode, _types } = coreCreateAppRoutes<\n TMetadata,\n TContext\n >()(appRoutes);\n\n type Pathname = RoutePathname<TMetadata, TContext, TRouteTree>;\n type Routes = ResolvedRouteTree<TMetadata, TContext, TRouteTree>;\n\n const TypedLink = createTypedLink<Pathname, TRouteTree>();\n const useTypedNavigate = createTypedNavigate<Pathname, TRouteTree>();\n\n return {\n AppRoutesProvider,\n useAppRoutes: useAppRoutes as () => Routes,\n TypedLink,\n useTypedNavigate,\n getPathnameFromNode,\n freezeAppRoutes,\n useCurrentRouteNode,\n appRoutes,\n _types: {\n ..._types,\n AppRoutesPathname: {} as Pathname,\n },\n };\n };\n};\n\nexport * from '@hyeonqyu/typed-router-core';\nexport type { TypedLinkProps } from './TypedLink';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyeonqyu/typed-router-react",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Type-safe IA-first routing for React Router",
5
5
  "author": "hyeonQyu <dhk0561@naver.com>",
6
6
  "license": "MIT",