@kirill.konshin/next 0.0.1 → 0.0.3

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/.ctirc CHANGED
@@ -1,11 +1,20 @@
1
1
  {
2
- "addNewline": true,
3
- "fileExcludePatterns": [
4
- "*.stories.*",
5
- "*.test.*",
6
- "*.fixture.*"
7
- ],
8
- "verbose": false,
9
- "withoutBackupFile": true,
10
- "withoutComment": true
11
- }
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,16 +1,25 @@
1
1
  vite v7.0.6 building SSR bundle for production...
2
- create succeeded: /home/runner/work/utils/utils/packages/next/src
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!
3
10
  transforming...
4
- ✓ 6 modules transformed.
11
+ ✓ 7 modules transformed.
5
12
  rendering chunks...
6
13
 
7
14
  [vite:dts] Start generate declaration files...
8
- dist/noSSR.js 0.33 kB │ map: 1.38 kB
9
- dist/index.js 0.34 kB │ map: 0.10 kB
15
+ dist/noSSR.js 0.35 kB │ map: 1.52 kB
10
16
  dist/useIsInner.js 0.37 kB │ map: 0.61 kB
17
+ dist/redirect.js 0.38 kB │ map: 0.87 kB
11
18
  dist/measure.js 0.38 kB │ map: 1.04 kB
12
- dist/appLink.js 0.77 kB │ map: 1.58 kB
13
- [vite:dts] Declaration files built in 1575ms.
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.
14
23
 
15
- ✓ built in 2.28s
24
+ ✓ built in 4.61s
16
25
  Updated package.json with exports
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
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/appLink.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { ComponentProps, FC } from 'react';
2
2
  import { default as Link, LinkProps } from 'next/link';
3
- export declare const AppLink: FC<{
3
+ export type AppLinkProps = {
4
4
  children: any;
5
5
  exact?: boolean;
6
6
  activeClassName?: any;
7
- } & LinkProps & ComponentProps<typeof Link>>;
7
+ } & LinkProps & ComponentProps<typeof Link>;
8
+ export declare function useIsLinkActive(): (href: ComponentProps<typeof Link>["href"], exact: boolean) => boolean;
9
+ export declare const AppLink: FC<AppLinkProps>;
8
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,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAI5C,eAAO,MAAM,OAAO,EAAE,EAAE,CACpB;IACI,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,CAyBlC,CAAC"}
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"}
package/dist/appLink.js CHANGED
@@ -1,9 +1,17 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
+ import { memo } from "react";
3
4
  import { usePathname } from "next/navigation";
4
5
  import Link from "next/link";
5
6
  import clsx from "clsx";
6
- const AppLink = function AppLink2({
7
+ 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
+ };
13
+ }
14
+ const AppLink = memo(function AppLink2({
7
15
  href,
8
16
  children,
9
17
  className = "",
@@ -13,22 +21,22 @@ const AppLink = function AppLink2({
13
21
  exact = false,
14
22
  ...props
15
23
  }) {
16
- const pathname = usePathname();
17
- const hrefPath = typeof href === "string" ? href : href.pathname || "/";
24
+ const isActive = useIsLinkActive();
18
25
  return /* @__PURE__ */ jsx(
19
26
  Link,
20
27
  {
21
28
  ...props,
22
29
  href,
23
30
  className: clsx(className, {
24
- [activeClassName]: !exact && pathname.startsWith(hrefPath) || exact && pathname === hrefPath
31
+ [activeClassName]: isActive(href, exact)
25
32
  }),
26
33
  prefetch,
27
34
  children
28
35
  }
29
36
  );
30
- };
37
+ });
31
38
  export {
32
- AppLink
39
+ AppLink,
40
+ useIsLinkActive
33
41
  };
34
42
  //# sourceMappingURL=appLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"appLink.js","sources":["../src/appLink.tsx"],"sourcesContent":["'use client';\n\nimport React, { ComponentProps, FC } from 'react';\nimport { usePathname } from 'next/navigation';\nimport Link, { LinkProps } from 'next/link';\nimport clsx from 'clsx';\n\n//TODO Test this\nexport const AppLink: FC<\n {\n children: any;\n exact?: boolean;\n activeClassName?: any;\n } & LinkProps &\n ComponentProps<typeof Link>\n> = function AppLink({\n href,\n children,\n className = '',\n activeClassName = '',\n prefetch = false, // set explicit default\n exact = false,\n ...props\n}) {\n const pathname = usePathname();\n const hrefPath = typeof href === 'string' ? href : href.pathname || '/';\n\n return (\n <Link\n {...props}\n href={href}\n className={clsx(className, {\n [activeClassName]: (!exact && pathname.startsWith(hrefPath)) || (exact && pathname === hrefPath),\n })}\n prefetch={prefetch}\n >\n {children}\n </Link>\n );\n};\n"],"names":["AppLink"],"mappings":";;;;;AAQO,MAAM,UAOT,SAASA,SAAQ;AAAA,EACjB;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,WAAW;AAAA;AAAA,EACX,QAAQ;AAAA,EACR,GAAG;AACP,GAAG;AACC,QAAM,WAAW,YAAA;AACjB,QAAM,WAAW,OAAO,SAAS,WAAW,OAAO,KAAK,YAAY;AAEpE,SACI;AAAA,IAAC;AAAA,IAAA;AAAA,MACI,GAAG;AAAA,MACJ;AAAA,MACA,WAAW,KAAK,WAAW;AAAA,QACvB,CAAC,eAAe,GAAI,CAAC,SAAS,SAAS,WAAW,QAAQ,KAAO,SAAS,aAAa;AAAA,MAAA,CAC1F;AAAA,MACD;AAAA,MAEC;AAAA,IAAA;AAAA,EAAA;AAGb;"}
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;"}
package/dist/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export * from './appLink';
2
2
  export * from './measure';
3
3
  export * from './noSSR';
4
4
  export * from './redirect';
5
+ export * from './softLink';
5
6
  export * from './useIsInner';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,15 +1,18 @@
1
- import { AppLink } from "./appLink.js";
1
+ import { AppLink, useIsLinkActive } from "./appLink.js";
2
2
  import { isProd, measurer } from "./measure.js";
3
3
  import { NoSSR } from "./noSSR.js";
4
- import "next/navigation";
5
- import "react";
4
+ import { Redirect } from "./redirect.js";
5
+ import { SoftLink } from "./softLink.js";
6
6
  import { useIsIndex, useIsInner } from "./useIsInner.js";
7
7
  export {
8
8
  AppLink,
9
9
  NoSSR,
10
+ Redirect,
11
+ SoftLink,
10
12
  isProd,
11
13
  measurer,
12
14
  useIsIndex,
13
- useIsInner
15
+ useIsInner,
16
+ useIsLinkActive
14
17
  };
15
18
  //# sourceMappingURL=index.js.map
package/dist/measure.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createMeasurer } from "@kirill.konshin/core";
1
+ import { createMeasurer } from "@kirill.konshin/node";
2
2
  import { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from "next/constants";
3
3
  const isProd = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD || process.env.NEXT_PHASE === PHASE_PRODUCTION_SERVER;
4
4
  const measurer = createMeasurer({ colors: isProd });
@@ -1 +1 @@
1
- {"version":3,"file":"measure.js","sources":["../src/measure.ts"],"sourcesContent":["import { createMeasurer } from '@kirill.konshin/core';\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","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;"}
package/dist/noSSR.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { FC, JSX } from 'react';
2
+ export type NoSSRProps = {
3
+ children: any;
4
+ onSSR?: JSX.Element;
5
+ };
2
6
  /**
3
7
  * Prefer using Next.js `dynamic()` import with `ssr: false` because this will also remove import from server bundle.
4
8
  *
@@ -22,8 +26,5 @@ import { FC, JSX } from 'react';
22
26
  * @see https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js
23
27
  * @see https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only
24
28
  */
25
- export declare const NoSSR: FC<{
26
- children: any;
27
- onSSR?: JSX.Element;
28
- }>;
29
+ export declare const NoSSR: FC<NoSSRProps>;
29
30
  //# sourceMappingURL=noSSR.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"noSSR.d.ts","sourceRoot":"","sources":["../src/noSSR.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAE,EAAE,EAAE,GAAG,EAA6B,MAAM,OAAO,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,CAQ5D,CAAC"}
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"}
package/dist/noSSR.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use client";
2
- import { useState, useLayoutEffect } from "react";
3
- const NoSSR = function NoSSR2({ children, onSSR = null }) {
2
+ import { memo, useState, useLayoutEffect } from "react";
3
+ const NoSSR = memo(function NoSSR2({ children, onSSR = null }) {
4
4
  const [canRender, setCanRender] = useState(false);
5
5
  useLayoutEffect(() => {
6
6
  setCanRender(true);
7
7
  }, []);
8
8
  return canRender ? children : onSSR;
9
- };
9
+ });
10
10
  export {
11
11
  NoSSR
12
12
  };
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, JSX, useLayoutEffect, useState } from 'react';\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<{ children: any; onSSR?: JSX.Element }> = function NoSSR({ children, onSSR = null }): any {\n const [canRender, setCanRender] = useState(false);\n\n useLayoutEffect(() => {\n setCanRender(true);\n }, []);\n\n return canRender ? children : onSSR;\n};\n"],"names":["NoSSR"],"mappings":";;AA2BO,MAAM,QAAoD,SAASA,OAAM,EAAE,UAAU,QAAQ,QAAa;AAC7G,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,kBAAgB,MAAM;AAClB,iBAAa,IAAI;AAAA,EACrB,GAAG,CAAA,CAAE;AAEL,SAAO,YAAY,WAAW;AAClC;"}
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,6 +1,11 @@
1
+ import { FC } from 'react';
1
2
  import { LinkProps } from 'next/link';
2
- export default function Redirect({ to, replace }: {
3
+ export type RedirectProps = {
3
4
  to: LinkProps['href'];
4
5
  replace?: LinkProps['replace'];
5
- }): null;
6
+ };
7
+ /**
8
+ * @deprecated
9
+ */
10
+ export declare const Redirect: FC<RedirectProps>;
6
11
  //# sourceMappingURL=redirect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../src/redirect.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE;IAAE,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAAE,QAM1G"}
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"}
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { useRouter } from "next/navigation";
3
+ 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;
10
+ });
11
+ export {
12
+ Redirect
13
+ };
14
+ //# sourceMappingURL=redirect.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,14 @@
1
+ import { default as Link, LinkProps } from 'next/link';
2
+ import { ReactNode } from 'react';
3
+ export type SoftLinkProps = LinkProps & {
4
+ children?: ReactNode;
5
+ };
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
+ export declare const SoftLink: typeof Link;
14
+ //# sourceMappingURL=softLink.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import Link from "next/link";
4
+ 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 });
18
+ });
19
+ export {
20
+ SoftLink
21
+ };
22
+ //# sourceMappingURL=softLink.js.map
@@ -0,0 +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;"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@kirill.konshin/next",
3
3
  "description": "Utilities",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
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": "cti create ./src",
10
+ "build:index": "ctix build",
11
11
  "build:check-types": "attw --pack .",
12
12
  "start": "yarn build --watch",
13
13
  "wait": "wait-on ./dist/index.js",
@@ -19,13 +19,8 @@
19
19
  "storybook:build": "storybook build"
20
20
  },
21
21
  "dependencies": {
22
- "@kirill.konshin/core": "*",
23
- "clsx": "^2.1.1",
24
- "colors": "^1.4.0",
25
- "file-saver": "^2.0.5",
26
- "many-keys-map": "^3.0.3",
27
- "psd": "^3.4.0",
28
- "sharp": "^0.34.3"
22
+ "@kirill.konshin/node": "*",
23
+ "clsx": "^2.1.1"
29
24
  },
30
25
  "devDependencies": {
31
26
  "@kirill.konshin/utils-private": "*",
@@ -59,5 +54,10 @@
59
54
  },
60
55
  "main": "./dist/index.js",
61
56
  "module": "./dist/index.js",
62
- "types": "./dist/index.d.ts"
57
+ "types": "./dist/index.d.ts",
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/kirill-konshin/utils.git",
61
+ "directory": "packages/next"
62
+ }
63
63
  }
package/src/appLink.tsx CHANGED
@@ -1,19 +1,27 @@
1
1
  'use client';
2
2
 
3
- import React, { ComponentProps, FC } from 'react';
3
+ import React, { ComponentProps, FC, memo } from 'react';
4
4
  import { usePathname } from 'next/navigation';
5
5
  import Link, { LinkProps } from 'next/link';
6
6
  import clsx from 'clsx';
7
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
+
8
23
  //TODO Test this
9
- export const AppLink: FC<
10
- {
11
- children: any;
12
- exact?: boolean;
13
- activeClassName?: any;
14
- } & LinkProps &
15
- ComponentProps<typeof Link>
16
- > = function AppLink({
24
+ export const AppLink: FC<AppLinkProps> = memo(function AppLink({
17
25
  href,
18
26
  children,
19
27
  className = '',
@@ -22,19 +30,18 @@ export const AppLink: FC<
22
30
  exact = false,
23
31
  ...props
24
32
  }) {
25
- const pathname = usePathname();
26
- const hrefPath = typeof href === 'string' ? href : href.pathname || '/';
33
+ const isActive = useIsLinkActive();
27
34
 
28
35
  return (
29
36
  <Link
30
37
  {...props}
31
38
  href={href}
32
39
  className={clsx(className, {
33
- [activeClassName]: (!exact && pathname.startsWith(hrefPath)) || (exact && pathname === hrefPath),
40
+ [activeClassName]: isActive(href, exact),
34
41
  })}
35
42
  prefetch={prefetch}
36
43
  >
37
44
  {children}
38
45
  </Link>
39
46
  );
40
- };
47
+ });
package/src/index.ts CHANGED
@@ -2,4 +2,5 @@ export * from './appLink';
2
2
  export * from './measure';
3
3
  export * from './noSSR';
4
4
  export * from './redirect';
5
+ export * from './softLink';
5
6
  export * from './useIsInner';
package/src/measure.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { createMeasurer } from '@kirill.konshin/core';
1
+ import { createMeasurer } from '@kirill.konshin/node';
2
2
  import { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from 'next/constants';
3
3
 
4
4
  export const isProd: boolean =
package/src/noSSR.tsx CHANGED
@@ -1,6 +1,11 @@
1
1
  'use client';
2
2
 
3
- import React, { FC, JSX, useLayoutEffect, useState } from 'react';
3
+ import React, { FC, memo, JSX, useLayoutEffect, useState } from 'react';
4
+
5
+ export type NoSSRProps = {
6
+ children: any;
7
+ onSSR?: JSX.Element;
8
+ };
4
9
 
5
10
  /**
6
11
  * Prefer using Next.js `dynamic()` import with `ssr: false` because this will also remove import from server bundle.
@@ -25,12 +30,13 @@ import React, { FC, JSX, useLayoutEffect, useState } from 'react';
25
30
  * @see https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js
26
31
  * @see https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only
27
32
  */
28
- export const NoSSR: FC<{ children: any; onSSR?: JSX.Element }> = function NoSSR({ children, onSSR = null }): any {
33
+ export const NoSSR: FC<NoSSRProps> = memo(function NoSSR({ children, onSSR = null }): any {
29
34
  const [canRender, setCanRender] = useState(false);
30
35
 
31
36
  useLayoutEffect(() => {
37
+ // eslint-disable-next-line react-hooks/set-state-in-effect
32
38
  setCanRender(true);
33
39
  }, []);
34
40
 
35
41
  return canRender ? children : onSSR;
36
- };
42
+ });
package/src/redirect.tsx CHANGED
@@ -1,13 +1,21 @@
1
1
  'use client';
2
2
 
3
3
  import { useRouter } from 'next/navigation';
4
- import { useEffect } from 'react';
4
+ import { FC, memo, useEffect } from 'react';
5
5
  import type { LinkProps } from 'next/link';
6
6
 
7
- export default function Redirect({ to, replace }: { to: LinkProps['href']; replace?: LinkProps['replace'] }) {
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 }) {
8
16
  const router = useRouter();
9
17
  useEffect(() => {
10
18
  router[replace ? 'replace' : 'push'](to.toString()); //TODO Test this
11
19
  }, [replace, router, to]);
12
20
  return null;
13
- }
21
+ });
@@ -0,0 +1,38 @@
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;