@ichaingo/link 1.3.98 → 1.3.99
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/index.js +38 -67
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,78 +1,49 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
4
|
-
import { usePathname } from "@ichaingo/i18n/navigation";
|
|
5
|
-
import { useLocale } from "next-intl";
|
|
6
|
-
import { useRouter, useSearchParams } from "next/navigation";
|
|
7
|
-
import { useTransition, useMemo } from "react";
|
|
8
|
-
import { useProgressBar } from "@ichaingo/providers/TopProgressBarProvider";
|
|
9
|
-
const
|
|
10
|
-
href,
|
|
11
|
-
isOldProject,
|
|
12
|
-
withLocale =
|
|
13
|
-
baseUrl = "",
|
|
14
|
-
children,
|
|
15
|
-
target = "_self",
|
|
16
|
-
onClick,
|
|
17
|
-
prefetch =
|
|
18
|
-
...
|
|
2
|
+
import { jsx as L } from "react/jsx-runtime";
|
|
3
|
+
import _ from "next/link";
|
|
4
|
+
import { usePathname as W } from "@ichaingo/i18n/navigation";
|
|
5
|
+
import { useLocale as v } from "next-intl";
|
|
6
|
+
import { useRouter as y, useSearchParams as B } from "next/navigation";
|
|
7
|
+
import { useTransition as H, useMemo as S } from "react";
|
|
8
|
+
import { useProgressBar as T } from "@ichaingo/providers/TopProgressBarProvider";
|
|
9
|
+
const z = ({
|
|
10
|
+
href: r,
|
|
11
|
+
isOldProject: c,
|
|
12
|
+
withLocale: m = !0,
|
|
13
|
+
baseUrl: o = "",
|
|
14
|
+
children: p,
|
|
15
|
+
target: i = "_self",
|
|
16
|
+
onClick: a,
|
|
17
|
+
prefetch: l = !1,
|
|
18
|
+
...f
|
|
19
19
|
}) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const searchParams = useSearchParams();
|
|
23
|
-
const [, startTransition] = useTransition();
|
|
24
|
-
const { start } = useProgressBar();
|
|
25
|
-
const locale = useLocale();
|
|
26
|
-
const isExternalLink = (url) => {
|
|
27
|
-
if (baseUrl.includes(".ichaingo.com") || url.includes(".ichaingo.com")) return false;
|
|
28
|
-
if (baseUrl === "" && !/^(https?:\/\/|\/\/)/.test(url)) return false;
|
|
29
|
-
return /^(https?:\/\/|\/\/)/.test(url);
|
|
30
|
-
};
|
|
31
|
-
const isCurrentPage = (url) => {
|
|
32
|
-
return url.replace(`/${locale}`, "") === pathName.replace(`/${locale}`, "") + searchParams.toString();
|
|
33
|
-
};
|
|
34
|
-
const handleClick = (e, href2) => {
|
|
35
|
-
onClick == null ? void 0 : onClick(e);
|
|
36
|
-
e.stopPropagation();
|
|
37
|
-
e.preventDefault();
|
|
38
|
-
if (isCurrentPage(href2)) {
|
|
20
|
+
const d = y(), P = W(), $ = B(), [, g] = H(), { start: k } = T(), e = v(), n = (t) => o.includes(".ichaingo.com") || t.includes(".ichaingo.com") || o === "" && !/^(https?:\/\/|\/\/)/.test(t) ? !1 : /^(https?:\/\/|\/\/)/.test(t), w = (t) => t.replace(`/${e}`, "") === P.replace(`/${e}`, "") + $.toString(), x = (t, s) => {
|
|
21
|
+
if (a == null || a(t), t.stopPropagation(), t.preventDefault(), w(s)) {
|
|
39
22
|
window.location.reload();
|
|
40
23
|
return;
|
|
41
24
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (isExternalLink(href)) return href;
|
|
53
|
-
const localePrefix = `/${locale}`;
|
|
54
|
-
if (href === localePrefix || href.startsWith(`${localePrefix}/`) || !withLocale) {
|
|
55
|
-
return baseUrl + href;
|
|
56
|
-
}
|
|
57
|
-
if (href.startsWith("/")) {
|
|
58
|
-
return `${baseUrl}${localePrefix}${href}`;
|
|
59
|
-
}
|
|
60
|
-
return href;
|
|
61
|
-
}, [href, locale, baseUrl]);
|
|
62
|
-
return /* @__PURE__ */ jsx(
|
|
63
|
-
Link,
|
|
25
|
+
c || n(s) ? window.open(s, i === "_blank" || n(s) ? "_blank" : i) : (k(), g(() => {
|
|
26
|
+
d.push(s);
|
|
27
|
+
}));
|
|
28
|
+
}, u = S(() => {
|
|
29
|
+
if (n(r)) return r;
|
|
30
|
+
const t = `/${e}`;
|
|
31
|
+
return r === t || r.startsWith(`${t}/`) || !m ? o + r : r.startsWith("/") ? `${o}${t}${r}` : r;
|
|
32
|
+
}, [r, e, o]);
|
|
33
|
+
return /* @__PURE__ */ L(
|
|
34
|
+
_,
|
|
64
35
|
{
|
|
65
|
-
suppressHydrationWarning:
|
|
66
|
-
prefetch,
|
|
67
|
-
href:
|
|
68
|
-
target:
|
|
69
|
-
onClick: (
|
|
70
|
-
rel:
|
|
71
|
-
...
|
|
72
|
-
children
|
|
36
|
+
suppressHydrationWarning: !0,
|
|
37
|
+
prefetch: l,
|
|
38
|
+
href: u,
|
|
39
|
+
target: n(r) ? "_blank" : i,
|
|
40
|
+
onClick: (t) => x(t, u),
|
|
41
|
+
rel: n(r) ? "noopener noreferrer" : void 0,
|
|
42
|
+
...f,
|
|
43
|
+
children: p
|
|
73
44
|
}
|
|
74
45
|
);
|
|
75
46
|
};
|
|
76
47
|
export {
|
|
77
|
-
|
|
48
|
+
z as default
|
|
78
49
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ichaingo/link",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.99",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"next": "^15.4.5",
|
|
21
21
|
"next-intl": "^4.3.4",
|
|
22
22
|
"react": "^19.1.0",
|
|
23
|
-
"@ichaingo/
|
|
24
|
-
"@ichaingo/
|
|
23
|
+
"@ichaingo/providers": "1.3.99",
|
|
24
|
+
"@ichaingo/i18n": "1.3.99"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"rollup-plugin-preserve-use-client": "^3.0.1"
|