@kirill.konshin/next 0.0.3 → 0.0.4
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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +6 -0
- package/dist/appLink.d.ts +1 -1
- package/dist/appLink.d.ts.map +1 -1
- package/dist/appLink.js +8 -5
- package/dist/appLink.js.map +1 -1
- package/package.json +1 -1
- package/src/appLink.tsx +10 -6
package/.turbo/turbo-build.log
CHANGED
|
@@ -18,8 +18,8 @@ rendering chunks...
|
|
|
18
18
|
[2mdist/[22m[36mmeasure.js [39m[1m[2m0.38 kB[22m[1m[22m[2m │ map: 1.04 kB[22m
|
|
19
19
|
[2mdist/[22m[36mindex.js [39m[1m[2m0.44 kB[22m[1m[22m[2m │ map: 0.10 kB[22m
|
|
20
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[
|
|
22
|
-
[vite:dts] Declaration files built in
|
|
21
|
+
[2mdist/[22m[36mappLink.js [39m[1m[2m1.02 kB[22m[1m[22m[2m │ map: 2.14 kB[22m
|
|
22
|
+
[vite:dts] Declaration files built in 1481ms.
|
|
23
23
|
|
|
24
|
-
[32m✓ built in
|
|
24
|
+
[32m✓ built in 6.03s[39m
|
|
25
25
|
Updated package.json with exports
|
package/CHANGELOG.md
CHANGED
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,cAAc,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;AAE9E,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,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,15 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { memo } from "react";
|
|
3
|
+
import { memo, useCallback } from "react";
|
|
4
4
|
import { usePathname } from "next/navigation";
|
|
5
5
|
import Link from "next/link";
|
|
6
6
|
import clsx from "clsx";
|
|
7
7
|
function useIsLinkActive() {
|
|
8
8
|
const pathname = usePathname();
|
|
9
|
-
return (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
return useCallback(
|
|
10
|
+
(href, exact) => {
|
|
11
|
+
const hrefPath = typeof href === "string" ? href : href.pathname || "/";
|
|
12
|
+
return !exact && pathname.startsWith(hrefPath) || exact && pathname === hrefPath;
|
|
13
|
+
},
|
|
14
|
+
[pathname]
|
|
15
|
+
);
|
|
13
16
|
}
|
|
14
17
|
const AppLink = memo(function AppLink2({
|
|
15
18
|
href,
|
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","sources":["../src/appLink.tsx"],"sourcesContent":["'use client';\n\nimport React, { ComponentProps, FC, memo, useCallback, useMemo } 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(): (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"],"names":["AppLink"],"mappings":";;;;;;AAcO,SAAS,kBAA0F;AACtG,QAAM,WAAW,YAAA;AAEjB,SAAO;AAAA,IACH,CAAC,MAA2C,UAA4B;AACpE,YAAM,WAAW,OAAO,SAAS,WAAW,OAAO,KAAK,YAAY;AACpE,aAAQ,CAAC,SAAS,SAAS,WAAW,QAAQ,KAAO,SAAS,aAAa;AAAA,IAC/E;AAAA,IACA,CAAC,QAAQ;AAAA,EAAA;AAEjB;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;"}
|
package/package.json
CHANGED
package/src/appLink.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { ComponentProps, FC, memo } from 'react';
|
|
3
|
+
import React, { ComponentProps, FC, memo, useCallback, useMemo } from 'react';
|
|
4
4
|
import { usePathname } from 'next/navigation';
|
|
5
5
|
import Link, { LinkProps } from 'next/link';
|
|
6
6
|
import clsx from 'clsx';
|
|
@@ -12,12 +12,16 @@ export type AppLinkProps = {
|
|
|
12
12
|
} & LinkProps &
|
|
13
13
|
ComponentProps<typeof Link>;
|
|
14
14
|
|
|
15
|
-
export function useIsLinkActive() {
|
|
15
|
+
export function useIsLinkActive(): (href: ComponentProps<typeof Link>['href'], exact: boolean) => boolean {
|
|
16
16
|
const pathname = usePathname();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
|
|
18
|
+
return useCallback(
|
|
19
|
+
(href: ComponentProps<typeof Link>['href'], exact: boolean): boolean => {
|
|
20
|
+
const hrefPath = typeof href === 'string' ? href : href.pathname || '/';
|
|
21
|
+
return (!exact && pathname.startsWith(hrefPath)) || (exact && pathname === hrefPath);
|
|
22
|
+
},
|
|
23
|
+
[pathname],
|
|
24
|
+
);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
//TODO Test this
|