@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.
@@ -18,8 +18,8 @@ rendering chunks...
18
18
  dist/measure.js 0.38 kB │ map: 1.04 kB
19
19
  dist/index.js 0.44 kB │ map: 0.10 kB
20
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.
21
+ dist/appLink.js 1.02 kB │ map: 2.14 kB
22
+ [vite:dts] Declaration files built in 1481ms.
23
23
 
24
- ✓ built in 4.61s
24
+ ✓ built in 6.03s
25
25
  Updated package.json with exports
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @kirill.konshin/next
2
2
 
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Minor fixes
8
+
3
9
  ## 0.0.3
4
10
 
5
11
  ### Patch Changes
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,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 (href, exact) => {
10
- const hrefPath = typeof href === "string" ? href : href.pathname || "/";
11
- return !exact && pathname.startsWith(hrefPath) || exact && pathname === hrefPath;
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,
@@ -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","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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kirill.konshin/next",
3
3
  "description": "Utilities",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "----- BUILD -----": "",
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
- 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
- };
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