@kirill.konshin/next 0.0.3 → 0.0.5

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/appLink.d.ts CHANGED
@@ -5,6 +5,6 @@ export type AppLinkProps = {
5
5
  exact?: boolean;
6
6
  activeClassName?: any;
7
7
  } & LinkProps & ComponentProps<typeof Link>;
8
- export declare function useIsLinkActive(): (href: ComponentProps<typeof Link>["href"], exact: boolean) => boolean;
8
+ export declare function useIsLinkActive(): (href: ComponentProps<typeof Link>['href'], exact: boolean) => boolean;
9
9
  export declare const AppLink: FC<AppLinkProps>;
10
10
  //# sourceMappingURL=appLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"appLink.d.ts","sourceRoot":"","sources":["../src/appLink.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAE,cAAc,EAAE,EAAE,EAAQ,MAAM,OAAO,CAAC;AAExD,OAAO,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG5C,MAAM,MAAM,YAAY,GAAG;IACvB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,GAAG,CAAC;CACzB,GAAG,SAAS,GACT,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC;AAEhC,wBAAgB,eAAe,KAEnB,MAAM,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,OAAO,KAAG,OAAO,CAI9E;AAGD,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,YAAY,CAuBnC,CAAC"}
1
+ {"version":3,"file":"appLink.d.ts","sourceRoot":"","sources":["../src/appLink.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAE,KAAK,cAAc,EAAE,KAAK,EAAE,EAAqB,MAAM,OAAO,CAAC;AAE/E,OAAO,IAAI,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAGjD,MAAM,MAAM,YAAY,GAAG;IACvB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,GAAG,CAAC;CACzB,GAAG,SAAS,GACT,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC;AAEhC,wBAAgB,eAAe,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAUxG;AAGD,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,YAAY,CAuBnC,CAAC"}
package/dist/appLink.js CHANGED
@@ -1,42 +1,28 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { memo } from "react";
2
+ import { memo, useCallback } from "react";
4
3
  import { usePathname } from "next/navigation";
5
4
  import Link from "next/link";
6
5
  import clsx from "clsx";
6
+ import { jsx } from "react/jsx-runtime";
7
+ //#region src/appLink.tsx
7
8
  function useIsLinkActive() {
8
- const pathname = usePathname();
9
- return (href, exact) => {
10
- const hrefPath = typeof href === "string" ? href : href.pathname || "/";
11
- return !exact && pathname.startsWith(hrefPath) || exact && pathname === hrefPath;
12
- };
9
+ const pathname = usePathname();
10
+ return useCallback((href, exact) => {
11
+ const hrefPath = typeof href === "string" ? href : href.pathname || "/";
12
+ return !exact && pathname.startsWith(hrefPath) || exact && pathname === hrefPath;
13
+ }, [pathname]);
13
14
  }
14
- const AppLink = memo(function AppLink2({
15
- href,
16
- children,
17
- className = "",
18
- activeClassName = "",
19
- prefetch = false,
20
- // set explicit default
21
- exact = false,
22
- ...props
23
- }) {
24
- const isActive = useIsLinkActive();
25
- return /* @__PURE__ */ jsx(
26
- Link,
27
- {
28
- ...props,
29
- href,
30
- className: clsx(className, {
31
- [activeClassName]: isActive(href, exact)
32
- }),
33
- prefetch,
34
- children
35
- }
36
- );
15
+ var AppLink = memo(function AppLink({ href, children, className = "", activeClassName = "", prefetch = false, exact = false, ...props }) {
16
+ const isActive = useIsLinkActive();
17
+ return /* @__PURE__ */ jsx(Link, {
18
+ ...props,
19
+ href,
20
+ className: clsx(className, { [activeClassName]: isActive(href, exact) }),
21
+ prefetch,
22
+ children
23
+ });
37
24
  });
38
- export {
39
- AppLink,
40
- useIsLinkActive
41
- };
42
- //# sourceMappingURL=appLink.js.map
25
+ //#endregion
26
+ export { AppLink, useIsLinkActive };
27
+
28
+ //# sourceMappingURL=appLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"appLink.js","sources":["../src/appLink.tsx"],"sourcesContent":["'use client';\n\nimport React, { ComponentProps, FC, memo } from 'react';\nimport { usePathname } from 'next/navigation';\nimport Link, { LinkProps } from 'next/link';\nimport clsx from 'clsx';\n\nexport type AppLinkProps = {\n children: any;\n exact?: boolean;\n activeClassName?: any;\n} & LinkProps &\n ComponentProps<typeof Link>;\n\nexport function useIsLinkActive() {\n const pathname = usePathname();\n return (href: ComponentProps<typeof Link>['href'], exact: boolean): boolean => {\n const hrefPath = typeof href === 'string' ? href : href.pathname || '/';\n return (!exact && pathname.startsWith(hrefPath)) || (exact && pathname === hrefPath);\n };\n}\n\n//TODO Test this\nexport const AppLink: FC<AppLinkProps> = memo(function AppLink({\n href,\n children,\n className = '',\n activeClassName = '',\n prefetch = false, // set explicit default\n exact = false,\n ...props\n}) {\n const isActive = useIsLinkActive();\n\n return (\n <Link\n {...props}\n href={href}\n className={clsx(className, {\n [activeClassName]: isActive(href, exact),\n })}\n prefetch={prefetch}\n >\n {children}\n </Link>\n );\n});\n"],"names":["AppLink"],"mappings":";;;;;;AAcO,SAAS,kBAAkB;AAC9B,QAAM,WAAW,YAAA;AACjB,SAAO,CAAC,MAA2C,UAA4B;AAC3E,UAAM,WAAW,OAAO,SAAS,WAAW,OAAO,KAAK,YAAY;AACpE,WAAQ,CAAC,SAAS,SAAS,WAAW,QAAQ,KAAO,SAAS,aAAa;AAAA,EAC/E;AACJ;AAGO,MAAM,UAA4B,KAAK,SAASA,SAAQ;AAAA,EAC3D;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,WAAW;AAAA;AAAA,EACX,QAAQ;AAAA,EACR,GAAG;AACP,GAAG;AACC,QAAM,WAAW,gBAAA;AAEjB,SACI;AAAA,IAAC;AAAA,IAAA;AAAA,MACI,GAAG;AAAA,MACJ;AAAA,MACA,WAAW,KAAK,WAAW;AAAA,QACvB,CAAC,eAAe,GAAG,SAAS,MAAM,KAAK;AAAA,MAAA,CAC1C;AAAA,MACD;AAAA,MAEC;AAAA,IAAA;AAAA,EAAA;AAGb,CAAC;"}
1
+ {"version":3,"file":"appLink.js","names":[],"sources":["../src/appLink.tsx"],"sourcesContent":["'use client';\n\nimport React, { type ComponentProps, type FC, memo, useCallback } from 'react';\nimport { usePathname } from 'next/navigation';\nimport Link, { type LinkProps } from 'next/link';\nimport clsx from 'clsx';\n\nexport type AppLinkProps = {\n children: any;\n exact?: boolean;\n activeClassName?: any;\n} & LinkProps &\n ComponentProps<typeof Link>;\n\nexport function useIsLinkActive(): (href: ComponentProps<typeof Link>['href'], exact: boolean) => boolean {\n const pathname = usePathname();\n\n return useCallback(\n (href: ComponentProps<typeof Link>['href'], exact: boolean): boolean => {\n const hrefPath = typeof href === 'string' ? href : href.pathname || '/';\n return (!exact && pathname.startsWith(hrefPath)) || (exact && pathname === hrefPath);\n },\n [pathname],\n );\n}\n\n//TODO Test this\nexport const AppLink: FC<AppLinkProps> = memo(function AppLink({\n href,\n children,\n className = '',\n activeClassName = '',\n prefetch = false, // set explicit default\n exact = false,\n ...props\n}) {\n const isActive = useIsLinkActive();\n\n return (\n <Link\n {...props}\n href={href}\n className={clsx(className, {\n [activeClassName]: isActive(href, exact),\n })}\n prefetch={prefetch}\n >\n {children}\n </Link>\n );\n});\n"],"mappings":";;;;;;;AAcA,SAAgB,kBAA0F;CACtG,MAAM,WAAW,YAAY;CAE7B,OAAO,aACF,MAA2C,UAA4B;EACpE,MAAM,WAAW,OAAO,SAAS,WAAW,OAAO,KAAK,YAAY;EACpE,OAAQ,CAAC,SAAS,SAAS,WAAW,QAAQ,KAAO,SAAS,aAAa;CAC/E,GACA,CAAC,QAAQ,CACb;AACJ;AAGA,IAAa,UAA4B,KAAK,SAAS,QAAQ,EAC3D,MACA,UACA,YAAY,IACZ,kBAAkB,IAClB,WAAW,OACX,QAAQ,OACR,GAAG,SACJ;CACC,MAAM,WAAW,gBAAgB;CAEjC,OACI,oBAAC,MAAD;EACI,GAAI;EACE;EACN,WAAW,KAAK,WAAW,GACtB,kBAAkB,SAAS,MAAM,KAAK,EAC3C,CAAC;EACS;EAET;CACC,CAAA;AAEd,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './appLink';
2
- export * from './measure';
3
- export * from './noSSR';
4
- export * from './redirect';
5
- export * from './softLink';
6
- export * from './useIsInner';
1
+ export * from './appLink.js';
2
+ export * from './measure.js';
3
+ export * from './noSSR.js';
4
+ export * from './redirect.js';
5
+ export * from './softLink.js';
6
+ export * from './useIsInner.js';
7
7
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -4,15 +4,4 @@ import { NoSSR } from "./noSSR.js";
4
4
  import { Redirect } from "./redirect.js";
5
5
  import { SoftLink } from "./softLink.js";
6
6
  import { useIsIndex, useIsInner } from "./useIsInner.js";
7
- export {
8
- AppLink,
9
- NoSSR,
10
- Redirect,
11
- SoftLink,
12
- isProd,
13
- measurer,
14
- useIsIndex,
15
- useIsInner,
16
- useIsLinkActive
17
- };
18
- //# sourceMappingURL=index.js.map
7
+ export { AppLink, NoSSR, Redirect, SoftLink, isProd, measurer, useIsIndex, useIsInner, useIsLinkActive };
package/dist/measure.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { createMeasurer } from "@kirill.konshin/node";
2
2
  import { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from "next/constants";
3
- const isProd = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD || process.env.NEXT_PHASE === PHASE_PRODUCTION_SERVER;
4
- const measurer = createMeasurer({ colors: isProd });
5
- export {
6
- isProd,
7
- measurer
8
- };
9
- //# sourceMappingURL=measure.js.map
3
+ //#region src/measure.ts
4
+ var isProd = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD || process.env.NEXT_PHASE === PHASE_PRODUCTION_SERVER;
5
+ var measurer = createMeasurer({ colors: isProd });
6
+ //#endregion
7
+ export { isProd, measurer };
8
+
9
+ //# sourceMappingURL=measure.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"measure.js","sources":["../src/measure.ts"],"sourcesContent":["import { createMeasurer } from '@kirill.konshin/node';\nimport { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from 'next/constants';\n\nexport const isProd: boolean =\n process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD || process.env.NEXT_PHASE === PHASE_PRODUCTION_SERVER;\n\nexport const measurer: {\n measure: (\n what: string,\n step: string,\n supplemental?: string,\n ...args: any[]\n ) => {\n done: (result?: string, ...args2: any[]) => void;\n fail: (result?: string, ...args2: any[]) => void;\n log: (...args2: any[]) => void;\n };\n important: (str: any) => any;\n subject: (str: any) => any;\n arg: (str: any) => any;\n sup: (str: any) => any;\n ok: (str: any) => any;\n err: (str: any) => any;\n} = createMeasurer({ colors: isProd });\n"],"names":[],"mappings":";;AAGO,MAAM,SACT,QAAQ,IAAI,eAAe,0BAA0B,QAAQ,IAAI,eAAe;AAE7E,MAAM,WAiBT,eAAe,EAAE,QAAQ,QAAQ;"}
1
+ {"version":3,"file":"measure.js","names":[],"sources":["../src/measure.ts"],"sourcesContent":["import { createMeasurer } from '@kirill.konshin/node';\nimport { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from 'next/constants';\n\nexport const isProd: boolean =\n process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD || process.env.NEXT_PHASE === PHASE_PRODUCTION_SERVER;\n\nexport const measurer: {\n measure: (\n what: string,\n step: string,\n supplemental?: string,\n ...args: any[]\n ) => {\n done: (result?: string, ...args2: any[]) => void;\n fail: (result?: string, ...args2: any[]) => void;\n log: (...args2: any[]) => void;\n };\n important: (str: any) => any;\n subject: (str: any) => any;\n arg: (str: any) => any;\n sup: (str: any) => any;\n ok: (str: any) => any;\n err: (str: any) => any;\n} = createMeasurer({ colors: isProd });\n"],"mappings":";;;AAGA,IAAa,SACT,QAAQ,IAAI,eAAe,0BAA0B,QAAQ,IAAI,eAAe;AAEpF,IAAa,WAiBT,eAAe,EAAE,QAAQ,OAAO,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"noSSR.d.ts","sourceRoot":"","sources":["../src/noSSR.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAE,EAAE,EAAQ,GAAG,EAA6B,MAAM,OAAO,CAAC;AAExE,MAAM,MAAM,UAAU,GAAG;IACrB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,UAAU,CAS/B,CAAC"}
1
+ {"version":3,"file":"noSSR.d.ts","sourceRoot":"","sources":["../src/noSSR.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,EAAQ,KAAK,GAAG,EAA6B,MAAM,OAAO,CAAC;AAE3E,MAAM,MAAM,UAAU,GAAG;IACrB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,UAAU,CAS/B,CAAC"}
package/dist/noSSR.js CHANGED
@@ -1,13 +1,37 @@
1
1
  "use client";
2
- import { memo, useState, useLayoutEffect } from "react";
3
- const NoSSR = memo(function NoSSR2({ children, onSSR = null }) {
4
- const [canRender, setCanRender] = useState(false);
5
- useLayoutEffect(() => {
6
- setCanRender(true);
7
- }, []);
8
- return canRender ? children : onSSR;
2
+ import { memo, useLayoutEffect, useState } from "react";
3
+ //#region src/noSSR.tsx
4
+ /**
5
+ * Prefer using Next.js `dynamic()` import with `ssr: false` because this will also remove import from server bundle.
6
+ *
7
+ * ```tsx
8
+ * 'use client';
9
+ *
10
+ * import React from 'react';
11
+ * import dynamic from 'next/dynamic';
12
+ *
13
+ * const PageClient = dynamic(() => import('./pageClient'), { ssr: false });
14
+ *
15
+ * export default function Page() {
16
+ * return (
17
+ * <PageClient />
18
+ * );
19
+ * }
20
+ * ```
21
+ *
22
+ * In other cases this component can be used to just prevent server rendering.
23
+ *
24
+ * @see https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js
25
+ * @see https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only
26
+ */
27
+ var NoSSR = memo(function NoSSR({ children, onSSR = null }) {
28
+ const [canRender, setCanRender] = useState(false);
29
+ useLayoutEffect(() => {
30
+ setCanRender(true);
31
+ }, []);
32
+ return canRender ? children : onSSR;
9
33
  });
10
- export {
11
- NoSSR
12
- };
13
- //# sourceMappingURL=noSSR.js.map
34
+ //#endregion
35
+ export { NoSSR };
36
+
37
+ //# sourceMappingURL=noSSR.js.map
package/dist/noSSR.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"noSSR.js","sources":["../src/noSSR.tsx"],"sourcesContent":["'use client';\n\nimport React, { FC, memo, JSX, useLayoutEffect, useState } from 'react';\n\nexport type NoSSRProps = {\n children: any;\n onSSR?: JSX.Element;\n};\n\n/**\n * Prefer using Next.js `dynamic()` import with `ssr: false` because this will also remove import from server bundle.\n *\n * ```tsx\n * 'use client';\n *\n * import React from 'react';\n * import dynamic from 'next/dynamic';\n *\n * const PageClient = dynamic(() => import('./pageClient'), { ssr: false });\n *\n * export default function Page() {\n * return (\n * <PageClient />\n * );\n * }\n * ```\n *\n * In other cases this component can be used to just prevent server rendering.\n *\n * @see https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js\n * @see https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only\n */\nexport const NoSSR: FC<NoSSRProps> = memo(function NoSSR({ children, onSSR = null }): any {\n const [canRender, setCanRender] = useState(false);\n\n useLayoutEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setCanRender(true);\n }, []);\n\n return canRender ? children : onSSR;\n});\n"],"names":["NoSSR"],"mappings":";;AAgCO,MAAM,QAAwB,KAAK,SAASA,OAAM,EAAE,UAAU,QAAQ,QAAa;AACtF,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,kBAAgB,MAAM;AAElB,iBAAa,IAAI;AAAA,EACrB,GAAG,CAAA,CAAE;AAEL,SAAO,YAAY,WAAW;AAClC,CAAC;"}
1
+ {"version":3,"file":"noSSR.js","names":[],"sources":["../src/noSSR.tsx"],"sourcesContent":["/* eslint-disable unicorn/filename-case */\n'use client';\n\nimport { type FC, memo, type JSX, useLayoutEffect, useState } from 'react';\n\nexport type NoSSRProps = {\n children: any;\n onSSR?: JSX.Element;\n};\n\n/**\n * Prefer using Next.js `dynamic()` import with `ssr: false` because this will also remove import from server bundle.\n *\n * ```tsx\n * 'use client';\n *\n * import React from 'react';\n * import dynamic from 'next/dynamic';\n *\n * const PageClient = dynamic(() => import('./pageClient'), { ssr: false });\n *\n * export default function Page() {\n * return (\n * <PageClient />\n * );\n * }\n * ```\n *\n * In other cases this component can be used to just prevent server rendering.\n *\n * @see https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js\n * @see https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only\n */\nexport const NoSSR: FC<NoSSRProps> = memo(function NoSSR({ children, onSSR = null }): any {\n const [canRender, setCanRender] = useState(false);\n\n useLayoutEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setCanRender(true);\n }, []);\n\n return canRender ? children : onSSR;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,QAAwB,KAAK,SAAS,MAAM,EAAE,UAAU,QAAQ,QAAa;CACtF,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,sBAAsB;EAElB,aAAa,IAAI;CACrB,GAAG,CAAC,CAAC;CAEL,OAAO,YAAY,WAAW;AAClC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../src/redirect.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAmB,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,MAAM,aAAa,GAAG;IACxB,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAMrC,CAAC"}
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../src/redirect.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,EAAmB,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,MAAM,aAAa,GAAG;IACxB,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAMrC,CAAC"}
package/dist/redirect.js CHANGED
@@ -1,14 +1,22 @@
1
1
  "use client";
2
- import { useRouter } from "next/navigation";
3
2
  import { memo, useEffect } from "react";
4
- const Redirect = memo(function Redirect2({ to, replace }) {
5
- const router = useRouter();
6
- useEffect(() => {
7
- router[replace ? "replace" : "push"](to.toString());
8
- }, [replace, router, to]);
9
- return null;
3
+ import { useRouter } from "next/navigation";
4
+ //#region src/redirect.tsx
5
+ /**
6
+ * @deprecated
7
+ */
8
+ var Redirect = memo(function Redirect({ to, replace }) {
9
+ const router = useRouter();
10
+ useEffect(() => {
11
+ router[replace ? "replace" : "push"](to.toString());
12
+ }, [
13
+ replace,
14
+ router,
15
+ to
16
+ ]);
17
+ return null;
10
18
  });
11
- export {
12
- Redirect
13
- };
14
- //# sourceMappingURL=redirect.js.map
19
+ //#endregion
20
+ export { Redirect };
21
+
22
+ //# sourceMappingURL=redirect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.js","sources":["../src/redirect.tsx"],"sourcesContent":["'use client';\n\nimport { useRouter } from 'next/navigation';\nimport { FC, memo, useEffect } from 'react';\nimport type { LinkProps } from 'next/link';\n\nexport type RedirectProps = {\n to: LinkProps['href'];\n replace?: LinkProps['replace'];\n};\n\n/**\n * @deprecated\n */\nexport const Redirect: FC<RedirectProps> = memo(function Redirect({ to, replace }) {\n const router = useRouter();\n useEffect(() => {\n router[replace ? 'replace' : 'push'](to.toString()); //TODO Test this\n }, [replace, router, to]);\n return null;\n});\n"],"names":["Redirect"],"mappings":";;;AAcO,MAAM,WAA8B,KAAK,SAASA,UAAS,EAAE,IAAI,WAAW;AAC/E,QAAM,SAAS,UAAA;AACf,YAAU,MAAM;AACZ,WAAO,UAAU,YAAY,MAAM,EAAE,GAAG,UAAU;AAAA,EACtD,GAAG,CAAC,SAAS,QAAQ,EAAE,CAAC;AACxB,SAAO;AACX,CAAC;"}
1
+ {"version":3,"file":"redirect.js","names":[],"sources":["../src/redirect.tsx"],"sourcesContent":["'use client';\n\nimport { useRouter } from 'next/navigation';\nimport { type FC, memo, useEffect } from 'react';\nimport type { LinkProps } from 'next/link';\n\nexport type RedirectProps = {\n to: LinkProps['href'];\n replace?: LinkProps['replace'];\n};\n\n/**\n * @deprecated\n */\nexport const Redirect: FC<RedirectProps> = memo(function Redirect({ to, replace }) {\n const router = useRouter();\n useEffect(() => {\n router[replace ? 'replace' : 'push'](to.toString()); //TODO Test this\n }, [replace, router, to]);\n return null;\n});\n"],"mappings":";;;;;;;AAcA,IAAa,WAA8B,KAAK,SAAS,SAAS,EAAE,IAAI,WAAW;CAC/E,MAAM,SAAS,UAAU;CACzB,gBAAgB;EACZ,OAAO,UAAU,YAAY,OAAO,CAAC,GAAG,SAAS,CAAC;CACtD,GAAG;EAAC;EAAS;EAAQ;CAAE,CAAC;CACxB,OAAO;AACX,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { default as Link, LinkProps } from 'next/link';
2
- import { ReactNode } from 'react';
2
+ import { MouseEventHandler, ReactNode } from 'react';
3
3
  export type SoftLinkProps = LinkProps & {
4
4
  children?: ReactNode;
5
+ onClick?: MouseEventHandler<HTMLAnchorElement>;
5
6
  };
6
7
  /**
7
8
  * Search Params update w/o rerender
@@ -1 +1 @@
1
- {"version":3,"file":"softLink.d.ts","sourceRoot":"","sources":["../src/softLink.tsx"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAc,EAAQ,SAAS,EAAe,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAoBf,OAAO,IAAI,CAAC"}
1
+ {"version":3,"file":"softLink.d.ts","sourceRoot":"","sources":["../src/softLink.tsx"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAc,EAAyB,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAe,MAAM,OAAO,CAAC;AAC1G,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;CAClD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAwBf,OAAO,IAAI,CAAC"}
package/dist/softLink.js CHANGED
@@ -1,22 +1,35 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import Link from "next/link";
4
2
  import { memo, useCallback } from "react";
5
- const SoftLink = memo(function SoftLink2({ href, children, replace, ...props }) {
6
- const onClick = useCallback(
7
- (e) => {
8
- e.preventDefault();
9
- window.history[replace ? "replaceState" : "pushState"](
10
- null,
11
- "",
12
- typeof href === "string" ? href : `${href["pathname"] || ""}?${typeof href["query"] === "string" ? href["query"] : new URLSearchParams(href["query"]).toString()}`
13
- );
14
- },
15
- [href, replace]
16
- );
17
- return /* @__PURE__ */ jsx(Link, { href, ...props, onClick, children });
3
+ import Link from "next/link";
4
+ import { jsx } from "react/jsx-runtime";
5
+ //#region src/softLink.tsx
6
+ /**
7
+ * Search Params update w/o rerender
8
+ *
9
+ * https://nextjs.org/docs/app/api-reference/functions/use-search-params#prerendering
10
+ * https://github.com/vercel/next.js/issues/43691#issuecomment-2078921491
11
+ * https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api
12
+ */
13
+ var SoftLink = memo(function SoftLink({ href, children, replace, onClick, ...props }) {
14
+ const handleClick = useCallback((e) => {
15
+ onClick?.(e);
16
+ if (e.defaultPrevented) return;
17
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;
18
+ e.preventDefault();
19
+ window.history[replace ? "replaceState" : "pushState"](null, "", typeof href === "string" ? href : `${href["pathname"] || ""}?${typeof href["query"] === "string" ? href["query"] : new URLSearchParams(href["query"]).toString()}`);
20
+ }, [
21
+ href,
22
+ replace,
23
+ onClick
24
+ ]);
25
+ return /* @__PURE__ */ jsx(Link, {
26
+ href,
27
+ ...props,
28
+ onClick: handleClick,
29
+ children
30
+ });
18
31
  });
19
- export {
20
- SoftLink
21
- };
22
- //# sourceMappingURL=softLink.js.map
32
+ //#endregion
33
+ export { SoftLink };
34
+
35
+ //# sourceMappingURL=softLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"softLink.js","sources":["../src/softLink.tsx"],"sourcesContent":["'use client';\n\nimport Link from 'next/link';\nimport React, { memo, ReactNode, useCallback } from 'react';\nimport { LinkProps } from 'next/link';\n\nexport type SoftLinkProps = LinkProps & {\n children?: ReactNode;\n};\n\n/**\n * Search Params update w/o rerender\n *\n * https://nextjs.org/docs/app/api-reference/functions/use-search-params#prerendering\n * https://github.com/vercel/next.js/issues/43691#issuecomment-2078921491\n * https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api\n */\nexport const SoftLink = memo<SoftLinkProps>(function SoftLink({ href, children, replace, ...props }) {\n const onClick = useCallback(\n (e) => {\n e.preventDefault();\n window.history[replace ? 'replaceState' : 'pushState'](\n null,\n '',\n typeof href === 'string'\n ? href\n : `${href['pathname'] || ''}?${typeof href['query'] === 'string' ? href['query'] : new URLSearchParams(href['query'] as never).toString()}`,\n );\n },\n [href, replace],\n );\n\n return (\n <Link href={href} {...props} onClick={onClick}>\n {children}\n </Link>\n );\n}) as typeof Link;\n"],"names":["SoftLink"],"mappings":";;;;AAiBO,MAAM,WAAW,KAAoB,SAASA,UAAS,EAAE,MAAM,UAAU,SAAS,GAAG,SAAS;AACjG,QAAM,UAAU;AAAA,IACZ,CAAC,MAAM;AACH,QAAE,eAAA;AACF,aAAO,QAAQ,UAAU,iBAAiB,WAAW;AAAA,QACjD;AAAA,QACA;AAAA,QACA,OAAO,SAAS,WACV,OACA,GAAG,KAAK,UAAU,KAAK,EAAE,IAAI,OAAO,KAAK,OAAO,MAAM,WAAW,KAAK,OAAO,IAAI,IAAI,gBAAgB,KAAK,OAAO,CAAU,EAAE,UAAU;AAAA,MAAA;AAAA,IAErJ;AAAA,IACA,CAAC,MAAM,OAAO;AAAA,EAAA;AAGlB,6BACK,MAAA,EAAK,MAAa,GAAG,OAAO,SACxB,UACL;AAER,CAAC;"}
1
+ {"version":3,"file":"softLink.js","names":[],"sources":["../src/softLink.tsx"],"sourcesContent":["'use client';\n\nimport Link from 'next/link';\nimport React, { memo, type MouseEvent, type MouseEventHandler, type ReactNode, useCallback } from 'react';\nimport { type LinkProps } from 'next/link';\n\nexport type SoftLinkProps = LinkProps & {\n children?: ReactNode;\n onClick?: MouseEventHandler<HTMLAnchorElement>;\n};\n\n/**\n * Search Params update w/o rerender\n *\n * https://nextjs.org/docs/app/api-reference/functions/use-search-params#prerendering\n * https://github.com/vercel/next.js/issues/43691#issuecomment-2078921491\n * https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api\n */\nexport const SoftLink = memo<SoftLinkProps>(function SoftLink({ href, children, replace, onClick, ...props }) {\n const handleClick = useCallback(\n (e: MouseEvent<HTMLAnchorElement>) => {\n onClick?.(e);\n if (e.defaultPrevented) return;\n // new-tab/new-window/modified clicks stay with the browser (next/link defers them too)\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n window.history[replace ? 'replaceState' : 'pushState'](\n null,\n '',\n typeof href === 'string'\n ? href\n : `${href['pathname'] || ''}?${typeof href['query'] === 'string' ? href['query'] : new URLSearchParams(href['query'] as never).toString()}`,\n );\n },\n [href, replace, onClick],\n );\n\n return (\n <Link href={href} {...props} onClick={handleClick}>\n {children}\n </Link>\n );\n}) as typeof Link;\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAa,WAAW,KAAoB,SAAS,SAAS,EAAE,MAAM,UAAU,SAAS,SAAS,GAAG,SAAS;CAC1G,MAAM,cAAc,aACf,MAAqC;EAClC,UAAU,CAAC;EACX,IAAI,EAAE,kBAAkB;EAExB,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,GAAG;EACxE,EAAE,eAAe;EACjB,OAAO,QAAQ,UAAU,iBAAiB,YAAY,CAClD,MACA,IACA,OAAO,SAAS,WACV,OACA,GAAG,KAAK,eAAe,GAAG,GAAG,OAAO,KAAK,aAAa,WAAW,KAAK,WAAW,IAAI,gBAAgB,KAAK,QAAiB,CAAC,CAAC,SAAS,GAChJ;CACJ,GACA;EAAC;EAAM;EAAS;CAAO,CAC3B;CAEA,OACI,oBAAC,MAAD;EAAY;EAAM,GAAI;EAAO,SAAS;EACjC;CACC,CAAA;AAEd,CAAC"}
@@ -1,15 +1,13 @@
1
1
  "use client";
2
2
  import { useSelectedLayoutSegments } from "next/navigation";
3
- const useIsInner = () => {
4
- const pathname = useSelectedLayoutSegments();
5
- return pathname.length > 0;
3
+ //#region src/useIsInner.ts
4
+ var useIsInner = () => {
5
+ return useSelectedLayoutSegments().length > 0;
6
6
  };
7
- const useIsIndex = () => {
8
- const pathname = useSelectedLayoutSegments();
9
- return pathname.length === 0;
7
+ var useIsIndex = () => {
8
+ return useSelectedLayoutSegments().length === 0;
10
9
  };
11
- export {
12
- useIsIndex,
13
- useIsInner
14
- };
15
- //# sourceMappingURL=useIsInner.js.map
10
+ //#endregion
11
+ export { useIsIndex, useIsInner };
12
+
13
+ //# sourceMappingURL=useIsInner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIsInner.js","sources":["../src/useIsInner.ts"],"sourcesContent":["'use client';\n\nimport { useSelectedLayoutSegments } from 'next/navigation';\n\nexport const useIsInner = (): boolean => {\n const pathname = useSelectedLayoutSegments();\n return pathname.length > 0;\n};\n\nexport const useIsIndex = (): boolean => {\n const pathname = useSelectedLayoutSegments();\n return pathname.length === 0;\n};\n"],"names":[],"mappings":";;AAIO,MAAM,aAAa,MAAe;AACrC,QAAM,WAAW,0BAAA;AACjB,SAAO,SAAS,SAAS;AAC7B;AAEO,MAAM,aAAa,MAAe;AACrC,QAAM,WAAW,0BAAA;AACjB,SAAO,SAAS,WAAW;AAC/B;"}
1
+ {"version":3,"file":"useIsInner.js","names":[],"sources":["../src/useIsInner.ts"],"sourcesContent":["'use client';\n\nimport { useSelectedLayoutSegments } from 'next/navigation';\n\nexport const useIsInner = (): boolean => {\n const pathname = useSelectedLayoutSegments();\n return pathname.length > 0;\n};\n\nexport const useIsIndex = (): boolean => {\n const pathname = useSelectedLayoutSegments();\n return pathname.length === 0;\n};\n"],"mappings":";;;AAIA,IAAa,mBAA4B;CAErC,OADiB,0BACV,CAAA,CAAS,SAAS;AAC7B;AAEA,IAAa,mBAA4B;CAErC,OADiB,0BACV,CAAA,CAAS,WAAW;AAC/B"}
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "@kirill.konshin/next",
3
3
  "description": "Utilities",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "----- BUILD -----": "",
8
8
  "clean": "rm -rf dist .tscache tsconfig.tsbuildinfo",
9
9
  "build": "vite build",
10
- "build:index": "ctix build",
11
- "build:check-types": "attw --pack .",
12
10
  "start": "yarn build --watch",
13
11
  "wait": "wait-on ./dist/index.js",
14
12
  "----- TEST -----": "",
15
- "test:disabled": "vitest run --coverage",
13
+ "test": "vitest run --coverage",
16
14
  "test:watch": "vitest watch --coverage",
17
15
  "----- STORYBOOK -----": "",
18
16
  "storybook:start": "storybook dev -p 6006",
@@ -59,5 +57,13 @@
59
57
  "type": "git",
60
58
  "url": "https://github.com/kirill-konshin/utils.git",
61
59
  "directory": "packages/next"
62
- }
60
+ },
61
+ "nx": {
62
+ "tags": [
63
+ "platform:next"
64
+ ]
65
+ },
66
+ "files": [
67
+ "dist"
68
+ ]
63
69
  }
package/.ctirc DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "options": [
3
- {
4
- "mode": "create",
5
- "project": "tsconfig.json",
6
- "include": "src/**/*.{ts,tsx}",
7
- "exclude": [
8
- "**/*.stories.*",
9
- "**/*.test.*",
10
- "**/*.fixture.*"
11
- ],
12
- "startFrom": "src",
13
- "backup": false,
14
- "overwrite": true,
15
- "generationStyle": "default-alias-named-star",
16
- "output": "src",
17
- "verbose": true
18
- }
19
- ]
20
- }
@@ -1,25 +0,0 @@
1
- vite v7.0.6 building SSR bundle for production...
2
- - ctix 'create' mode start, ...
3
- ✔ /home/runner/work/utils/utils/packages/next/tsconfig.json loading complete!
4
- ✔ analysis export statements completed!
5
- - build "index.ts" file start
6
- - output file exists check, ...
7
-
8
-
9
- ✔ ctix 'create' mode complete!
10
- transforming...
11
- ✓ 7 modules transformed.
12
- rendering chunks...
13
-
14
- [vite:dts] Start generate declaration files...
15
- dist/noSSR.js 0.35 kB │ map: 1.52 kB
16
- dist/useIsInner.js 0.37 kB │ map: 0.61 kB
17
- dist/redirect.js 0.38 kB │ map: 0.87 kB
18
- dist/measure.js 0.38 kB │ map: 1.04 kB
19
- dist/index.js 0.44 kB │ map: 0.10 kB
20
- dist/softLink.js 0.72 kB │ map: 1.85 kB
21
- dist/appLink.js 0.96 kB │ map: 1.94 kB
22
- [vite:dts] Declaration files built in 1134ms.
23
-
24
- ✓ built in 4.61s
25
- Updated package.json with exports
package/CHANGELOG.md DELETED
@@ -1,16 +0,0 @@
1
- # @kirill.konshin/next
2
-
3
- ## 0.0.3
4
-
5
- ### Patch Changes
6
-
7
- - Small fixes
8
-
9
- ## 0.0.2
10
-
11
- ### Patch Changes
12
-
13
- - 63fdba8: Agent-assisted refactoring
14
- - 63fdba8: Divided core to browser/node/worker-specific packages, CTIX upgrade, etc.
15
- - Updated dependencies [63fdba8]
16
- - @kirill.konshin/node@0.0.2
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
package/src/appLink.tsx DELETED
@@ -1,47 +0,0 @@
1
- 'use client';
2
-
3
- import React, { ComponentProps, FC, memo } from 'react';
4
- import { usePathname } from 'next/navigation';
5
- import Link, { LinkProps } from 'next/link';
6
- import clsx from 'clsx';
7
-
8
- export type AppLinkProps = {
9
- children: any;
10
- exact?: boolean;
11
- activeClassName?: any;
12
- } & LinkProps &
13
- ComponentProps<typeof Link>;
14
-
15
- export function useIsLinkActive() {
16
- const pathname = usePathname();
17
- return (href: ComponentProps<typeof Link>['href'], exact: boolean): boolean => {
18
- const hrefPath = typeof href === 'string' ? href : href.pathname || '/';
19
- return (!exact && pathname.startsWith(hrefPath)) || (exact && pathname === hrefPath);
20
- };
21
- }
22
-
23
- //TODO Test this
24
- export const AppLink: FC<AppLinkProps> = memo(function AppLink({
25
- href,
26
- children,
27
- className = '',
28
- activeClassName = '',
29
- prefetch = false, // set explicit default
30
- exact = false,
31
- ...props
32
- }) {
33
- const isActive = useIsLinkActive();
34
-
35
- return (
36
- <Link
37
- {...props}
38
- href={href}
39
- className={clsx(className, {
40
- [activeClassName]: isActive(href, exact),
41
- })}
42
- prefetch={prefetch}
43
- >
44
- {children}
45
- </Link>
46
- );
47
- });
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './appLink';
2
- export * from './measure';
3
- export * from './noSSR';
4
- export * from './redirect';
5
- export * from './softLink';
6
- export * from './useIsInner';
package/src/measure.ts DELETED
@@ -1,24 +0,0 @@
1
- import { createMeasurer } from '@kirill.konshin/node';
2
- import { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from 'next/constants';
3
-
4
- export const isProd: boolean =
5
- process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD || process.env.NEXT_PHASE === PHASE_PRODUCTION_SERVER;
6
-
7
- export const measurer: {
8
- measure: (
9
- what: string,
10
- step: string,
11
- supplemental?: string,
12
- ...args: any[]
13
- ) => {
14
- done: (result?: string, ...args2: any[]) => void;
15
- fail: (result?: string, ...args2: any[]) => void;
16
- log: (...args2: any[]) => void;
17
- };
18
- important: (str: any) => any;
19
- subject: (str: any) => any;
20
- arg: (str: any) => any;
21
- sup: (str: any) => any;
22
- ok: (str: any) => any;
23
- err: (str: any) => any;
24
- } = createMeasurer({ colors: isProd });
package/src/noSSR.tsx DELETED
@@ -1,42 +0,0 @@
1
- 'use client';
2
-
3
- import React, { FC, memo, JSX, useLayoutEffect, useState } from 'react';
4
-
5
- export type NoSSRProps = {
6
- children: any;
7
- onSSR?: JSX.Element;
8
- };
9
-
10
- /**
11
- * Prefer using Next.js `dynamic()` import with `ssr: false` because this will also remove import from server bundle.
12
- *
13
- * ```tsx
14
- * 'use client';
15
- *
16
- * import React from 'react';
17
- * import dynamic from 'next/dynamic';
18
- *
19
- * const PageClient = dynamic(() => import('./pageClient'), { ssr: false });
20
- *
21
- * export default function Page() {
22
- * return (
23
- * <PageClient />
24
- * );
25
- * }
26
- * ```
27
- *
28
- * In other cases this component can be used to just prevent server rendering.
29
- *
30
- * @see https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js
31
- * @see https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only
32
- */
33
- export const NoSSR: FC<NoSSRProps> = memo(function NoSSR({ children, onSSR = null }): any {
34
- const [canRender, setCanRender] = useState(false);
35
-
36
- useLayoutEffect(() => {
37
- // eslint-disable-next-line react-hooks/set-state-in-effect
38
- setCanRender(true);
39
- }, []);
40
-
41
- return canRender ? children : onSSR;
42
- });
package/src/redirect.tsx DELETED
@@ -1,21 +0,0 @@
1
- 'use client';
2
-
3
- import { useRouter } from 'next/navigation';
4
- import { FC, memo, useEffect } from 'react';
5
- import type { LinkProps } from 'next/link';
6
-
7
- export type RedirectProps = {
8
- to: LinkProps['href'];
9
- replace?: LinkProps['replace'];
10
- };
11
-
12
- /**
13
- * @deprecated
14
- */
15
- export const Redirect: FC<RedirectProps> = memo(function Redirect({ to, replace }) {
16
- const router = useRouter();
17
- useEffect(() => {
18
- router[replace ? 'replace' : 'push'](to.toString()); //TODO Test this
19
- }, [replace, router, to]);
20
- return null;
21
- });
package/src/softLink.tsx DELETED
@@ -1,38 +0,0 @@
1
- 'use client';
2
-
3
- import Link from 'next/link';
4
- import React, { memo, ReactNode, useCallback } from 'react';
5
- import { LinkProps } from 'next/link';
6
-
7
- export type SoftLinkProps = LinkProps & {
8
- children?: ReactNode;
9
- };
10
-
11
- /**
12
- * Search Params update w/o rerender
13
- *
14
- * https://nextjs.org/docs/app/api-reference/functions/use-search-params#prerendering
15
- * https://github.com/vercel/next.js/issues/43691#issuecomment-2078921491
16
- * https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api
17
- */
18
- export const SoftLink = memo<SoftLinkProps>(function SoftLink({ href, children, replace, ...props }) {
19
- const onClick = useCallback(
20
- (e) => {
21
- e.preventDefault();
22
- window.history[replace ? 'replaceState' : 'pushState'](
23
- null,
24
- '',
25
- typeof href === 'string'
26
- ? href
27
- : `${href['pathname'] || ''}?${typeof href['query'] === 'string' ? href['query'] : new URLSearchParams(href['query'] as never).toString()}`,
28
- );
29
- },
30
- [href, replace],
31
- );
32
-
33
- return (
34
- <Link href={href} {...props} onClick={onClick}>
35
- {children}
36
- </Link>
37
- );
38
- }) as typeof Link;
package/src/useIsInner.ts DELETED
@@ -1,13 +0,0 @@
1
- 'use client';
2
-
3
- import { useSelectedLayoutSegments } from 'next/navigation';
4
-
5
- export const useIsInner = (): boolean => {
6
- const pathname = useSelectedLayoutSegments();
7
- return pathname.length > 0;
8
- };
9
-
10
- export const useIsIndex = (): boolean => {
11
- const pathname = useSelectedLayoutSegments();
12
- return pathname.length === 0;
13
- };
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../utils-private/tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "declarationDir": "dist"
7
- },
8
- "include": ["src"],
9
- "exclude": []
10
- }
package/turbo.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "$schema": "https://turbo.build/schema.json",
3
- "extends": ["//"],
4
- "tasks": {
5
- "build": {
6
- "dependsOn": ["^build"],
7
- "outputs": ["src/**/*/index.ts", "package.json", "dist/**/*"]
8
- }
9
- }
10
- }
package/vite.config.ts DELETED
@@ -1,2 +0,0 @@
1
- import config from '../utils-private/vite.config';
2
- export default config;