@digigov/nextjs 1.1.5-b19b7fe2 → 1.1.5-c6d0b3b8
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/Link/index.js +11 -16
- package/Link.js.map +2 -2
- package/cjs/Link/index.js +9 -14
- package/cjs/Link.js.map +3 -3
- package/index.js +1 -1
- package/package.json +3 -3
- package/src/Link.tsx +14 -19
package/Link/index.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
|
-
import
|
|
2
|
+
import NextRouterLink from "next/link";
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
|
-
import {
|
|
4
|
+
import { Link } from "@digigov/ui/navigation/Link";
|
|
5
5
|
const NextLink = (props, ref) => {
|
|
6
|
-
const { href, ...other } = props;
|
|
7
|
-
const isExternalLink = (
|
|
8
|
-
//check if url has a file extension or starts with mailto
|
|
9
|
-
/^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || "") || // or if props has a target or rel
|
|
10
|
-
other.target === "_blank"
|
|
11
|
-
);
|
|
6
|
+
const { href, as, ...other } = props;
|
|
7
|
+
const isExternalLink = /^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || "") || other.target === "_blank";
|
|
12
8
|
const router = useRouter();
|
|
13
9
|
useEffect(() => {
|
|
14
10
|
const path = router.asPath;
|
|
15
|
-
if (path
|
|
11
|
+
if (path.includes("#")) {
|
|
16
12
|
setTimeout(() => {
|
|
17
13
|
const id = path.replace("#", "");
|
|
18
|
-
const el =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
top: scrollY + r.top,
|
|
14
|
+
const el = document.getElementById(id);
|
|
15
|
+
if (el) {
|
|
16
|
+
window.scroll({
|
|
17
|
+
top: scrollY + el.getBoundingClientRect().top,
|
|
23
18
|
behavior: "smooth"
|
|
24
19
|
});
|
|
25
20
|
}
|
|
@@ -27,9 +22,9 @@ const NextLink = (props, ref) => {
|
|
|
27
22
|
}
|
|
28
23
|
}, [router.asPath]);
|
|
29
24
|
if (isExternalLink) {
|
|
30
|
-
return /* @__PURE__ */ React.createElement(
|
|
25
|
+
return /* @__PURE__ */ React.createElement(Link, { ref, href: href || "#", ...other }, props.children);
|
|
31
26
|
}
|
|
32
|
-
return /* @__PURE__ */ React.createElement(
|
|
27
|
+
return /* @__PURE__ */ React.createElement(NextRouterLink, { href: href || "#", as: void 0, ...other }, /* @__PURE__ */ React.createElement(Link, { ref, ...other, as }, props.children));
|
|
33
28
|
};
|
|
34
29
|
var Link_default = React.forwardRef(NextLink);
|
|
35
30
|
export {
|
package/Link.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Link.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useEffect } from 'react';\nimport
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,iBAAiB;AACjC,OAAO,
|
|
4
|
+
"sourcesContent": ["import React, { useEffect } from 'react';\nimport NextRouterLink from 'next/link';\nimport { useRouter } from 'next/router';\nimport { Link, LinkProps } from '@digigov/ui/navigation/Link';\n\nconst NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (\n props,\n ref\n) => {\n const { href, as, ...other } = props;\n const isExternalLink =\n /^(?:[a-z]+:)?\\/\\/|\\.pdf|\\.docx?|\\.xlsx?|^mailto:/i.test(href || '') ||\n other.target === '_blank';\n\n const router = useRouter();\n\n useEffect(() => {\n const path = router.asPath;\n if (path.includes('#')) {\n setTimeout(() => {\n const id = path.replace('#', '');\n const el = document.getElementById(id);\n if (el) {\n window.scroll({\n top: scrollY + el.getBoundingClientRect().top,\n behavior: 'smooth',\n });\n }\n }, 600);\n }\n }, [router.asPath]);\n\n if (isExternalLink) {\n return (\n <Link ref={ref} href={href || '#'} {...other}>\n {props.children}\n </Link>\n );\n }\n\n return (\n <NextRouterLink href={href || '#'} as={undefined} {...other}>\n <Link ref={ref} {...other} as={as}>\n {props.children}\n </Link>\n </NextRouterLink>\n );\n};\n\nexport default React.forwardRef(NextLink);\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,iBAAiB;AACjC,OAAO,oBAAoB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,YAAuB;AAEhC,MAAM,WAAyE,CAC7E,OACA,QACG;AACH,QAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;AAC/B,QAAM,iBACJ,oDAAoD,KAAK,QAAQ,EAAE,KACnE,MAAM,WAAW;AAEnB,QAAM,SAAS,UAAU;AAEzB,YAAU,MAAM;AACd,UAAM,OAAO,OAAO;AACpB,QAAI,KAAK,SAAS,GAAG,GAAG;AACtB,iBAAW,MAAM;AACf,cAAM,KAAK,KAAK,QAAQ,KAAK,EAAE;AAC/B,cAAM,KAAK,SAAS,eAAe,EAAE;AACrC,YAAI,IAAI;AACN,iBAAO,OAAO;AAAA,YACZ,KAAK,UAAU,GAAG,sBAAsB,EAAE;AAAA,YAC1C,UAAU;AAAA,UACZ,CAAC;AAAA,QACH;AAAA,MACF,GAAG,GAAG;AAAA,IACR;AAAA,EACF,GAAG,CAAC,OAAO,MAAM,CAAC;AAElB,MAAI,gBAAgB;AAClB,WACE,oCAAC,QAAK,KAAU,MAAM,QAAQ,KAAM,GAAG,SACpC,MAAM,QACT;AAAA,EAEJ;AAEA,SACE,oCAAC,kBAAe,MAAM,QAAQ,KAAK,IAAI,QAAY,GAAG,SACpD,oCAAC,QAAK,KAAW,GAAG,OAAO,MACxB,MAAM,QACT,CACF;AAEJ;AAEA,IAAO,eAAQ,MAAM,WAAW,QAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/cjs/Link/index.js
CHANGED
|
@@ -35,23 +35,18 @@ var import_link = __toESM(require("next/link"));
|
|
|
35
35
|
var import_router = require("next/router");
|
|
36
36
|
var import_Link = require("@digigov/ui/navigation/Link");
|
|
37
37
|
const NextLink = (props, ref) => {
|
|
38
|
-
const { href, ...other } = props;
|
|
39
|
-
const isExternalLink = (
|
|
40
|
-
//check if url has a file extension or starts with mailto
|
|
41
|
-
/^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || "") || // or if props has a target or rel
|
|
42
|
-
other.target === "_blank"
|
|
43
|
-
);
|
|
38
|
+
const { href, as, ...other } = props;
|
|
39
|
+
const isExternalLink = /^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || "") || other.target === "_blank";
|
|
44
40
|
const router = (0, import_router.useRouter)();
|
|
45
41
|
(0, import_react.useEffect)(() => {
|
|
46
42
|
const path = router.asPath;
|
|
47
|
-
if (path
|
|
43
|
+
if (path.includes("#")) {
|
|
48
44
|
setTimeout(() => {
|
|
49
45
|
const id = path.replace("#", "");
|
|
50
|
-
const el =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
top: scrollY + r.top,
|
|
46
|
+
const el = document.getElementById(id);
|
|
47
|
+
if (el) {
|
|
48
|
+
window.scroll({
|
|
49
|
+
top: scrollY + el.getBoundingClientRect().top,
|
|
55
50
|
behavior: "smooth"
|
|
56
51
|
});
|
|
57
52
|
}
|
|
@@ -59,9 +54,9 @@ const NextLink = (props, ref) => {
|
|
|
59
54
|
}
|
|
60
55
|
}, [router.asPath]);
|
|
61
56
|
if (isExternalLink) {
|
|
62
|
-
return /* @__PURE__ */ import_react.default.createElement(import_Link.
|
|
57
|
+
return /* @__PURE__ */ import_react.default.createElement(import_Link.Link, { ref, href: href || "#", ...other }, props.children);
|
|
63
58
|
}
|
|
64
|
-
return /* @__PURE__ */ import_react.default.createElement(import_link.default, { href: href || "#", ...other }, /* @__PURE__ */ import_react.default.createElement(import_Link.
|
|
59
|
+
return /* @__PURE__ */ import_react.default.createElement(import_link.default, { href: href || "#", as: void 0, ...other }, /* @__PURE__ */ import_react.default.createElement(import_Link.Link, { ref, ...other, as }, props.children));
|
|
65
60
|
};
|
|
66
61
|
var Link_default = import_react.default.forwardRef(NextLink);
|
|
67
62
|
//# sourceMappingURL=Link.js.map
|
package/cjs/Link.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Link.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useEffect } from 'react';\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,
|
|
6
|
-
"names": ["React", "
|
|
4
|
+
"sourcesContent": ["import React, { useEffect } from 'react';\nimport NextRouterLink from 'next/link';\nimport { useRouter } from 'next/router';\nimport { Link, LinkProps } from '@digigov/ui/navigation/Link';\n\nconst NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (\n props,\n ref\n) => {\n const { href, as, ...other } = props;\n const isExternalLink =\n /^(?:[a-z]+:)?\\/\\/|\\.pdf|\\.docx?|\\.xlsx?|^mailto:/i.test(href || '') ||\n other.target === '_blank';\n\n const router = useRouter();\n\n useEffect(() => {\n const path = router.asPath;\n if (path.includes('#')) {\n setTimeout(() => {\n const id = path.replace('#', '');\n const el = document.getElementById(id);\n if (el) {\n window.scroll({\n top: scrollY + el.getBoundingClientRect().top,\n behavior: 'smooth',\n });\n }\n }, 600);\n }\n }, [router.asPath]);\n\n if (isExternalLink) {\n return (\n <Link ref={ref} href={href || '#'} {...other}>\n {props.children}\n </Link>\n );\n }\n\n return (\n <NextRouterLink href={href || '#'} as={undefined} {...other}>\n <Link ref={ref} {...other} as={as}>\n {props.children}\n </Link>\n </NextRouterLink>\n );\n};\n\nexport default React.forwardRef(NextLink);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,kBAA2B;AAC3B,oBAA0B;AAC1B,kBAAgC;AAEhC,MAAM,WAAyE,CAC7E,OACA,QACG;AACH,QAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;AAC/B,QAAM,iBACJ,oDAAoD,KAAK,QAAQ,EAAE,KACnE,MAAM,WAAW;AAEnB,QAAM,aAAS,yBAAU;AAEzB,8BAAU,MAAM;AACd,UAAM,OAAO,OAAO;AACpB,QAAI,KAAK,SAAS,GAAG,GAAG;AACtB,iBAAW,MAAM;AACf,cAAM,KAAK,KAAK,QAAQ,KAAK,EAAE;AAC/B,cAAM,KAAK,SAAS,eAAe,EAAE;AACrC,YAAI,IAAI;AACN,iBAAO,OAAO;AAAA,YACZ,KAAK,UAAU,GAAG,sBAAsB,EAAE;AAAA,YAC1C,UAAU;AAAA,UACZ,CAAC;AAAA,QACH;AAAA,MACF,GAAG,GAAG;AAAA,IACR;AAAA,EACF,GAAG,CAAC,OAAO,MAAM,CAAC;AAElB,MAAI,gBAAgB;AAClB,WACE,6BAAAA,QAAA,cAAC,oBAAK,KAAU,MAAM,QAAQ,KAAM,GAAG,SACpC,MAAM,QACT;AAAA,EAEJ;AAEA,SACE,6BAAAA,QAAA,cAAC,YAAAC,SAAA,EAAe,MAAM,QAAQ,KAAK,IAAI,QAAY,GAAG,SACpD,6BAAAD,QAAA,cAAC,oBAAK,KAAW,GAAG,OAAO,MACxB,MAAM,QACT,CACF;AAEJ;AAEA,IAAO,eAAQ,aAAAA,QAAM,WAAW,QAAQ;",
|
|
6
|
+
"names": ["React", "NextRouterLink"]
|
|
7
7
|
}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/nextjs",
|
|
3
|
-
"version": "1.1.5-
|
|
3
|
+
"version": "1.1.5-c6d0b3b8",
|
|
4
4
|
"description": "next specific utilities for @digigov apps",
|
|
5
5
|
"author": "GRNET Developers <devs@lists.grnet.gr>",
|
|
6
6
|
"license": "BSD-2-Clause",
|
|
7
7
|
"main": "./cjs/index.js",
|
|
8
8
|
"module": "./index.js",
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"@digigov/ui": "2.0.0-
|
|
11
|
-
"@digigov/react-core": "2.0.0-
|
|
10
|
+
"@digigov/ui": "2.0.0-c6d0b3b8",
|
|
11
|
+
"@digigov/react-core": "2.0.0-c6d0b3b8",
|
|
12
12
|
"clsx": "1.1.1",
|
|
13
13
|
"i18next": "19.1.0",
|
|
14
14
|
"react": ">=16.8.0 <19.0.0",
|
package/src/Link.tsx
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import NextRouterLink from 'next/link';
|
|
3
3
|
import { useRouter } from 'next/router';
|
|
4
|
-
import {
|
|
5
|
-
import { LinkProps } from '@digigov/ui/navigation/Link';
|
|
4
|
+
import { Link, LinkProps } from '@digigov/ui/navigation/Link';
|
|
6
5
|
|
|
7
6
|
const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
8
7
|
props,
|
|
9
8
|
ref
|
|
10
9
|
) => {
|
|
11
|
-
const { href, ...other } = props;
|
|
12
|
-
|
|
10
|
+
const { href, as, ...other } = props;
|
|
13
11
|
const isExternalLink =
|
|
14
|
-
//check if url has a file extension or starts with mailto
|
|
15
12
|
/^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || '') ||
|
|
16
|
-
// or if props has a target or rel
|
|
17
13
|
other.target === '_blank';
|
|
18
14
|
|
|
19
15
|
const router = useRouter();
|
|
20
16
|
|
|
21
17
|
useEffect(() => {
|
|
22
18
|
const path = router.asPath;
|
|
23
|
-
if (path
|
|
19
|
+
if (path.includes('#')) {
|
|
24
20
|
setTimeout(() => {
|
|
25
21
|
const id = path.replace('#', '');
|
|
26
|
-
const el =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
top: scrollY + r.top,
|
|
22
|
+
const el = document.getElementById(id);
|
|
23
|
+
if (el) {
|
|
24
|
+
window.scroll({
|
|
25
|
+
top: scrollY + el.getBoundingClientRect().top,
|
|
31
26
|
behavior: 'smooth',
|
|
32
27
|
});
|
|
33
28
|
}
|
|
@@ -37,18 +32,18 @@ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
|
37
32
|
|
|
38
33
|
if (isExternalLink) {
|
|
39
34
|
return (
|
|
40
|
-
<
|
|
35
|
+
<Link ref={ref} href={href || '#'} {...other}>
|
|
41
36
|
{props.children}
|
|
42
|
-
</
|
|
37
|
+
</Link>
|
|
43
38
|
);
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
return (
|
|
47
|
-
<
|
|
48
|
-
<
|
|
42
|
+
<NextRouterLink href={href || '#'} as={undefined} {...other}>
|
|
43
|
+
<Link ref={ref} {...other} as={as}>
|
|
49
44
|
{props.children}
|
|
50
|
-
</
|
|
51
|
-
</
|
|
45
|
+
</Link>
|
|
46
|
+
</NextRouterLink>
|
|
52
47
|
);
|
|
53
48
|
};
|
|
54
49
|
|