@digigov/nextjs 1.0.0-8ae63a77 → 1.0.0-e322b0cc

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/App.js CHANGED
@@ -27,7 +27,7 @@ var _head = _interopRequireDefault(require("next/head"));
27
27
 
28
28
  var _Link = require("@digigov/ui/navigation/Link");
29
29
 
30
- var _Link2 = _interopRequireDefault(require("@digigov/nextjs/Link"));
30
+ var _Link2 = _interopRequireDefault(require("./Link"));
31
31
 
32
32
  var _dynamic = _interopRequireDefault(require("next/dynamic"));
33
33
 
@@ -12,7 +12,7 @@ import React from 'react';
12
12
  import App from 'next/app';
13
13
  import Head from 'next/head';
14
14
  import { LinkProvider } from '@digigov/ui/navigation/Link';
15
- import NextLink from '@digigov/nextjs/Link';
15
+ import NextLink from "./Link";
16
16
  import dynamic from 'next/dynamic';
17
17
  import { I18NProvider } from '@digigov/ui/i18n';
18
18
  import { withTranslation } from 'react-i18next';
package/Image.js CHANGED
@@ -15,7 +15,7 @@ var _react = _interopRequireDefault(require("react"));
15
15
 
16
16
  var _image = _interopRequireDefault(require("next/image"));
17
17
 
18
- var _hooks = require("@digigov/nextjs/hooks");
18
+ var _hooks = require("./hooks");
19
19
 
20
20
  var _excluded = ["src"];
21
21
 
@@ -3,7 +3,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["src"];
4
4
  import React from 'react';
5
5
  import NextImage from 'next/image';
6
- import { useBasePath } from '@digigov/nextjs/hooks';
6
+ import { useBasePath } from "./hooks";
7
7
 
8
8
  var Image = function Image(_ref) {
9
9
  var src = _ref.src,
package/Link.js CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
@@ -11,7 +13,9 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
13
 
12
14
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
15
 
14
- var _react = _interopRequireDefault(require("react"));
16
+ var _react = _interopRequireWildcard(require("react"));
17
+
18
+ var _router = require("next/router");
15
19
 
16
20
  var _link = _interopRequireDefault(require("next/link"));
17
21
 
@@ -19,12 +23,37 @@ var _LinkBase = _interopRequireDefault(require("@digigov/react-core/LinkBase"));
19
23
 
20
24
  var _excluded = ["href"];
21
25
 
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
22
30
  var NextLink = function NextLink(props, ref) {
23
31
  var href = props.href,
24
32
  other = (0, _objectWithoutProperties2["default"])(props, _excluded);
25
33
  var isExternalLink = //check if url has a file extension
26
34
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') || // or if props has a target or rel
27
35
  other.target === '_blank';
36
+ var router = (0, _router.useRouter)();
37
+ (0, _react.useEffect)(function () {
38
+ var path = router.asPath;
39
+
40
+ if (path && path.includes('#')) {
41
+ setTimeout(function () {
42
+ var id = path.replace("#", "");
43
+ var el = window.document.getElementById(id);
44
+ var r = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
45
+
46
+ if (r) {
47
+ var _window$top;
48
+
49
+ (_window$top = window.top) === null || _window$top === void 0 ? void 0 : _window$top.scroll({
50
+ top: scrollY + r.top,
51
+ behavior: "smooth"
52
+ });
53
+ }
54
+ }, 600);
55
+ }
56
+ }, [router.asPath]);
28
57
 
29
58
  if (isExternalLink) {
30
59
  return /*#__PURE__*/_react["default"].createElement(_LinkBase["default"], (0, _extends2["default"])({
@@ -1,7 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["href"];
4
- import React from 'react';
4
+ import React, { useEffect } from 'react';
5
+ import { useRouter } from 'next/router';
5
6
  import Link from 'next/link';
6
7
  import LinkBase from '@digigov/react-core/LinkBase';
7
8
 
@@ -12,6 +13,27 @@ var NextLink = function NextLink(props, ref) {
12
13
  var isExternalLink = //check if url has a file extension
13
14
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') || // or if props has a target or rel
14
15
  other.target === '_blank';
16
+ var router = useRouter();
17
+ useEffect(function () {
18
+ var path = router.asPath;
19
+
20
+ if (path && path.includes('#')) {
21
+ setTimeout(function () {
22
+ var id = path.replace("#", "");
23
+ var el = window.document.getElementById(id);
24
+ var r = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
25
+
26
+ if (r) {
27
+ var _window$top;
28
+
29
+ (_window$top = window.top) === null || _window$top === void 0 ? void 0 : _window$top.scroll({
30
+ top: scrollY + r.top,
31
+ behavior: "smooth"
32
+ });
33
+ }
34
+ }, 600);
35
+ }
36
+ }, [router.asPath]);
15
37
 
16
38
  if (isExternalLink) {
17
39
  return /*#__PURE__*/React.createElement(LinkBase, _extends({
package/es/App.js CHANGED
@@ -12,7 +12,7 @@ import React from 'react';
12
12
  import App from 'next/app';
13
13
  import Head from 'next/head';
14
14
  import { LinkProvider } from '@digigov/ui/navigation/Link';
15
- import NextLink from '@digigov/nextjs/Link';
15
+ import NextLink from "./Link";
16
16
  import dynamic from 'next/dynamic';
17
17
  import { I18NProvider } from '@digigov/ui/i18n';
18
18
  import { withTranslation } from 'react-i18next';
package/es/Image.js CHANGED
@@ -3,7 +3,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["src"];
4
4
  import React from 'react';
5
5
  import NextImage from 'next/image';
6
- import { useBasePath } from '@digigov/nextjs/hooks';
6
+ import { useBasePath } from "./hooks";
7
7
 
8
8
  var Image = function Image(_ref) {
9
9
  var src = _ref.src,
package/es/Link.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["href"];
4
- import React from 'react';
4
+ import React, { useEffect } from 'react';
5
+ import { useRouter } from 'next/router';
5
6
  import Link from 'next/link';
6
7
  import LinkBase from '@digigov/react-core/LinkBase';
7
8
 
@@ -12,6 +13,27 @@ var NextLink = function NextLink(props, ref) {
12
13
  var isExternalLink = //check if url has a file extension
13
14
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') || // or if props has a target or rel
14
15
  other.target === '_blank';
16
+ var router = useRouter();
17
+ useEffect(function () {
18
+ var path = router.asPath;
19
+
20
+ if (path && path.includes('#')) {
21
+ setTimeout(function () {
22
+ var id = path.replace("#", "");
23
+ var el = window.document.getElementById(id);
24
+ var r = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
25
+
26
+ if (r) {
27
+ var _window$top;
28
+
29
+ (_window$top = window.top) === null || _window$top === void 0 ? void 0 : _window$top.scroll({
30
+ top: scrollY + r.top,
31
+ behavior: "smooth"
32
+ });
33
+ }
34
+ }, 600);
35
+ }
36
+ }, [router.asPath]);
15
37
 
16
38
  if (isExternalLink) {
17
39
  return /*#__PURE__*/React.createElement(LinkBase, _extends({
@@ -1,4 +1,4 @@
1
- /** @license Digigov v1.0.0-8ae63a77
1
+ /** @license Digigov v1.0.0-e322b0cc
2
2
  *
3
3
  * This source code is licensed under the BSD-2-Clause license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -5,7 +5,7 @@ export interface I18NContextProps {
5
5
  children?: React.ReactNode;
6
6
  i18n?: any;
7
7
  }
8
- export declare const defaultTranslate: (key: string, context?: Record<string, any> | undefined) => string;
8
+ export declare const defaultTranslate: (key: string, context?: Record<string, any>) => string;
9
9
  export declare const I18NContext: React.Context<I18NContextProps>;
10
10
  export declare const I18NProvider: React.FC<I18NContextProps>;
11
11
  export declare const useTranslation: () => I18NContextProps;
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import LinkBase, { LinkBaseProps } from '@digigov/react-core/LinkBase';
3
3
  export interface LinkComponentContextProps {
4
4
  component: React.ElementType<LinkProps>;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@digigov/nextjs",
3
- "version": "1.0.0-8ae63a77",
3
+ "version": "1.0.0-e322b0cc",
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": "dist/index.js",
8
- "module": "./esm/index.js",
8
+ "module": "./index.mjs",
9
9
  "publishConfig": {
10
10
  "main": "dist/index.js"
11
11
  },
12
12
  "peerDependencies": {
13
- "@digigov/ui": "1.0.0-8ae63a77",
13
+ "@digigov/ui": "1.0.0-e322b0cc",
14
14
  "@material-ui/core": "4.11.3",
15
15
  "@material-ui/icons": "4.11.2",
16
16
  "clsx": "1.1.1",
package/src/Link.tsx CHANGED
@@ -1,5 +1,6 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { LinkProps } from '@digigov/ui/navigation/Link';
3
+ import { useRouter } from 'next/router';
3
4
  import Link from 'next/link';
4
5
  import LinkBase from '@digigov/react-core/LinkBase';
5
6
 
@@ -13,6 +14,24 @@ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
13
14
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') ||
14
15
  // or if props has a target or rel
15
16
  other.target === '_blank';
17
+ const router = useRouter();
18
+
19
+ useEffect(() => {
20
+ const path = router.asPath;
21
+ if (path && path.includes('#')) {
22
+ setTimeout(() => {
23
+ const id = path.replace("#", "")
24
+ const el = window.document.getElementById(id)
25
+ const r = el?.getBoundingClientRect()
26
+ if (r) {
27
+ window.top?.scroll({
28
+ top: scrollY + r.top,
29
+ behavior: "smooth",
30
+ })
31
+ }
32
+ }, 600)
33
+ }
34
+ }, [router.asPath]);
16
35
 
17
36
  if (isExternalLink) {
18
37
  return (
File without changes
File without changes
File without changes