@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 +1 -1
- package/dist/appLink.d.ts.map +1 -1
- package/dist/appLink.js +21 -35
- package/dist/appLink.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -12
- package/dist/measure.js +7 -7
- package/dist/measure.js.map +1 -1
- package/dist/noSSR.d.ts.map +1 -1
- package/dist/noSSR.js +35 -11
- package/dist/noSSR.js.map +1 -1
- package/dist/redirect.d.ts.map +1 -1
- package/dist/redirect.js +19 -11
- package/dist/redirect.js.map +1 -1
- package/dist/softLink.d.ts +2 -1
- package/dist/softLink.d.ts.map +1 -1
- package/dist/softLink.js +32 -19
- package/dist/softLink.js.map +1 -1
- package/dist/useIsInner.js +9 -11
- package/dist/useIsInner.js.map +1 -1
- package/package.json +11 -5
- package/.ctirc +0 -20
- package/.turbo/turbo-build.log +0 -25
- package/CHANGELOG.md +0 -16
- package/dist/index.js.map +0 -1
- package/src/appLink.tsx +0 -47
- package/src/index.ts +0 -6
- package/src/measure.ts +0 -24
- package/src/noSSR.tsx +0 -42
- package/src/redirect.tsx +0 -21
- package/src/softLink.tsx +0 -38
- package/src/useIsInner.ts +0 -13
- package/tsconfig.json +0 -10
- package/turbo.json +0 -10
- package/vite.config.ts +0 -2
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>[
|
|
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
|
package/dist/appLink.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appLink.d.ts","sourceRoot":"","sources":["../src/appLink.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAE,cAAc,EAAE,EAAE,
|
|
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 {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//# sourceMappingURL=appLink.js.map
|
|
25
|
+
//#endregion
|
|
26
|
+
export { AppLink, useIsLinkActive };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=appLink.js.map
|
package/dist/appLink.js.map
CHANGED
|
@@ -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
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
package/dist/measure.js.map
CHANGED
|
@@ -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"],"
|
|
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"}
|
package/dist/noSSR.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noSSR.d.ts","sourceRoot":"","sources":["../src/noSSR.tsx"],"names":[],"mappings":"
|
|
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,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
|
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"}
|
package/dist/redirect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../src/redirect.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAmB,MAAM,OAAO,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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=redirect.js.map
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Redirect };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=redirect.js.map
|
package/dist/redirect.js.map
CHANGED
|
@@ -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"],"
|
|
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"}
|
package/dist/softLink.d.ts
CHANGED
|
@@ -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
|
package/dist/softLink.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"softLink.d.ts","sourceRoot":"","sources":["../src/softLink.tsx"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAc,
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=softLink.js.map
|
|
32
|
+
//#endregion
|
|
33
|
+
export { SoftLink };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=softLink.js.map
|
package/dist/softLink.js.map
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/useIsInner.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useSelectedLayoutSegments } from "next/navigation";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
//#region src/useIsInner.ts
|
|
4
|
+
var useIsInner = () => {
|
|
5
|
+
return useSelectedLayoutSegments().length > 0;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return pathname.length === 0;
|
|
7
|
+
var useIsIndex = () => {
|
|
8
|
+
return useSelectedLayoutSegments().length === 0;
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=useIsInner.js.map
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useIsIndex, useIsInner };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=useIsInner.js.map
|
package/dist/useIsInner.js.map
CHANGED
|
@@ -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"],"
|
|
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.
|
|
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
|
|
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
|
-
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
[36mvite v7.0.6 [32mbuilding SSR bundle for production...[36m[39m
|
|
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
|
-
[32m✓[39m 7 modules transformed.
|
|
12
|
-
rendering chunks...
|
|
13
|
-
|
|
14
|
-
[vite:dts] Start generate declaration files...
|
|
15
|
-
[2mdist/[22m[36mnoSSR.js [39m[1m[2m0.35 kB[22m[1m[22m[2m │ map: 1.52 kB[22m
|
|
16
|
-
[2mdist/[22m[36museIsInner.js [39m[1m[2m0.37 kB[22m[1m[22m[2m │ map: 0.61 kB[22m
|
|
17
|
-
[2mdist/[22m[36mredirect.js [39m[1m[2m0.38 kB[22m[1m[22m[2m │ map: 0.87 kB[22m
|
|
18
|
-
[2mdist/[22m[36mmeasure.js [39m[1m[2m0.38 kB[22m[1m[22m[2m │ map: 1.04 kB[22m
|
|
19
|
-
[2mdist/[22m[36mindex.js [39m[1m[2m0.44 kB[22m[1m[22m[2m │ map: 0.10 kB[22m
|
|
20
|
-
[2mdist/[22m[36msoftLink.js [39m[1m[2m0.72 kB[22m[1m[22m[2m │ map: 1.85 kB[22m
|
|
21
|
-
[2mdist/[22m[36mappLink.js [39m[1m[2m0.96 kB[22m[1m[22m[2m │ map: 1.94 kB[22m
|
|
22
|
-
[vite:dts] Declaration files built in 1134ms.
|
|
23
|
-
|
|
24
|
-
[32m✓ built in 4.61s[39m
|
|
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
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
package/turbo.json
DELETED
package/vite.config.ts
DELETED