@digigov/nextjs 0.6.3 → 0.6.4-alpha

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.
Files changed (53) hide show
  1. package/.eslintrc.js +3 -0
  2. package/.prettierrc.js +3 -0
  3. package/.rush/temp/package-deps_build.json +21 -0
  4. package/.rush/temp/shrinkwrap-deps.json +334 -0
  5. package/CHANGELOG.json +935 -0
  6. package/{App.js → dist/App.js} +12 -0
  7. package/dist/CHANGELOG.md +255 -0
  8. package/{Document.js → dist/Document.js} +5 -47
  9. package/{Image.js → dist/Image.js} +0 -0
  10. package/{LICENSE → dist/LICENSE} +0 -0
  11. package/{Link.js → dist/Link.js} +0 -0
  12. package/dist/README.md +52 -0
  13. package/{es → dist/es}/App.js +12 -0
  14. package/{es → dist/es}/Document.js +5 -45
  15. package/{es → dist/es}/Image.js +0 -0
  16. package/{es → dist/es}/Link.js +0 -0
  17. package/{es → dist/es}/hooks.js +0 -0
  18. package/{es → dist/es}/i18n.js +0 -0
  19. package/{es → dist/es}/index.js +0 -0
  20. package/{esm → dist/esm}/App.js +12 -0
  21. package/{esm → dist/esm}/Document.js +5 -45
  22. package/{esm → dist/esm}/Image.js +0 -0
  23. package/{esm → dist/esm}/Link.js +0 -0
  24. package/{esm → dist/esm}/hooks.js +0 -0
  25. package/{esm → dist/esm}/i18n.js +0 -0
  26. package/{esm → dist/esm}/index.js +1 -1
  27. package/{hooks.js → dist/hooks.js} +0 -0
  28. package/{i18n.js → dist/i18n.js} +0 -0
  29. package/{index.js → dist/index.js} +0 -0
  30. package/{libs → dist/libs}/nextjs/src/App.d.ts +0 -0
  31. package/{libs → dist/libs}/nextjs/src/Document.d.ts +0 -0
  32. package/{libs → dist/libs}/nextjs/src/Image.d.ts +0 -0
  33. package/{libs → dist/libs}/nextjs/src/Link.d.ts +0 -0
  34. package/{libs → dist/libs}/nextjs/src/hooks.d.ts +0 -0
  35. package/{libs → dist/libs}/nextjs/src/i18n.d.ts +0 -0
  36. package/{libs → dist/libs}/nextjs/src/index.d.ts +0 -0
  37. package/{libs → dist/libs}/ui/src/app/App.d.ts +0 -0
  38. package/{libs → dist/libs}/ui/src/app/i18n.d.ts +0 -0
  39. package/{libs → dist/libs}/ui/src/core/Link/index.d.ts +0 -0
  40. package/{libs → dist/libs}/ui/src/locales/el.d.ts +0 -0
  41. package/{libs-ui → dist/libs-ui}/react-core/src/Base/index.d.ts +0 -0
  42. package/{libs-ui → dist/libs-ui}/react-core/src/Link/index.d.ts +0 -0
  43. package/dist/package.json +26 -0
  44. package/nextjs.build.log +17 -0
  45. package/package.json +38 -25
  46. package/src/App.tsx +61 -0
  47. package/src/Document.tsx +73 -0
  48. package/src/Image.tsx +10 -0
  49. package/src/Link.tsx +33 -0
  50. package/src/hooks.ts +6 -0
  51. package/src/i18n.tsx +18 -0
  52. package/src/index.ts +0 -0
  53. package/tsconfig.json +14 -0
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@digigov/nextjs",
3
+ "version": "0.6.4-alpha",
4
+ "description": "next specific utilities for @digigov apps",
5
+ "author": "GRNET Developers <devs@lists.grnet.gr>",
6
+ "license": "BSD-2-Clause",
7
+ "main": "./index.js",
8
+ "module": "./esm/index.js",
9
+ "publishConfig": {
10
+ "main": "dist/index.js"
11
+ },
12
+ "peerDependencies": {
13
+ "@digigov/ui": "0.26.6-alpha",
14
+ "@material-ui/core": "4.11.3",
15
+ "@material-ui/icons": "4.11.2",
16
+ "clsx": "1.1.1",
17
+ "i18next": "19.1.0",
18
+ "react": "^16.8.0 || ^17.0.0",
19
+ "react-dom": "^16.8.0 || ^17.0.0",
20
+ "next": "10.0.9",
21
+ "react-i18next": "11.3.3"
22
+ },
23
+ "gitHead": "7237a2d58c6b30979837579e51251543aff0c240",
24
+ "private": false,
25
+ "typings": "./index.d.ts"
26
+ }
@@ -0,0 +1,17 @@
1
+ Invoking: digigov build --subpackages
2
+
3
+ Running /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/node_modules/.bin/rimraf dist
4
+ Running /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/node_modules/.bin/tsc --emitDeclarationOnly --outDir dist
5
+ Running /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/node_modules/.bin/babel --config-file /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/babel.config.js src --extensions .tsx,.ts,.js,.jsx --copy-files --out-dir dist/esm
6
+ Successfully compiled 7 files with Babel (1634ms).
7
+ Running /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/node_modules/.bin/babel --config-file /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/babel.config.js src --extensions .tsx,.ts,.js,.jsx --copy-files --out-dir dist/es
8
+ Successfully compiled 7 files with Babel (1260ms).
9
+ Created package.json in /Users/dimitristsironis/grnet/digigov-sdk/libs/nextjs/dist/package.json
10
+ Copied /Users/dimitristsironis/grnet/digigov-sdk/libs/nextjs/CHANGELOG.md to /Users/dimitristsironis/grnet/digigov-sdk/libs/nextjs/dist/CHANGELOG.md
11
+ Copied /Users/dimitristsironis/grnet/digigov-sdk/libs/nextjs/README.md to /Users/dimitristsironis/grnet/digigov-sdk/libs/nextjs/dist/README.md
12
+ Copied /Users/dimitristsironis/grnet/digigov-sdk/LICENSE to /Users/dimitristsironis/grnet/digigov-sdk/libs/nextjs/dist/LICENSE
13
+ Skipped license for ./index.js
14
+ Skipped license for ./umd/digigov-ui.development.js
15
+ Skipped license for ./umd/digigov-ui.production.min.js
16
+ Running /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/node_modules/.bin/babel --config-file /Users/dimitristsironis/grnet/digigov-sdk/tooling/cli-build/babel.config.js src --extensions .tsx,.ts,.js,.jsx --copy-files --out-dir dist
17
+ Successfully compiled 7 files with Babel (1217ms).
package/package.json CHANGED
@@ -1,26 +1,39 @@
1
1
  {
2
- "name": "@digigov/nextjs",
3
- "version": "0.6.3",
4
- "description": "next specific utilities for @digigov apps",
5
- "author": "GRNET Developers <devs@lists.grnet.gr>",
6
- "license": "BSD-2-Clause",
7
- "main": "dist/index.js",
8
- "module": "./esm/index.js",
9
- "publishConfig": {
10
- "main": "dist/index.js"
11
- },
12
- "peerDependencies": {
13
- "@digigov/ui": "0.26.5",
14
- "@material-ui/core": "4.11.3",
15
- "@material-ui/icons": "4.11.2",
16
- "clsx": "1.1.1",
17
- "i18next": "19.1.0",
18
- "react": ">= 16.14.0 <= 18.2.0",
19
- "react-dom": ">= 16.14.0 <= 18.2.0",
20
- "next": "10.0.9",
21
- "react-i18next": "11.3.3"
22
- },
23
- "gitHead": "7237a2d58c6b30979837579e51251543aff0c240",
24
- "private": false,
25
- "typings": "./index.d.ts"
26
- }
2
+ "name": "@digigov/nextjs",
3
+ "version": "0.6.4-alpha",
4
+ "description": "next specific utilities for @digigov apps",
5
+ "author": "GRNET Developers <devs@lists.grnet.gr>",
6
+ "license": "BSD-2-Clause",
7
+ "main": "dist/index.js",
8
+ "module": "src/index.ts",
9
+ "publishConfig": {
10
+ "main": "dist/index.js"
11
+ },
12
+ "peerDependencies": {
13
+ "@digigov/ui": "0.26.6-alpha",
14
+ "@material-ui/core": "4.11.3",
15
+ "@material-ui/icons": "4.11.2",
16
+ "clsx": "1.1.1",
17
+ "i18next": "19.1.0",
18
+ "react": "^16.8.0 || ^17.0.0",
19
+ "react-dom": "^16.8.0 || ^17.0.0",
20
+ "next": "10.0.9",
21
+ "react-i18next": "11.3.3"
22
+ },
23
+ "devDependencies": {
24
+ "@digigov/cli": "0.6.1",
25
+ "@digigov/cli-lint": "0.5.31",
26
+ "@digigov/cli-build": "0.8.2",
27
+ "@digigov/cli-test": "0.7.1",
28
+ "@types/node": "16.6.2",
29
+ "@types/react": "16.9.56",
30
+ "@types/react-dom": "16.9.9",
31
+ "typescript": "4.2.3"
32
+ },
33
+ "gitHead": "7237a2d58c6b30979837579e51251543aff0c240",
34
+ "scripts": {
35
+ "lint": "digigov lint",
36
+ "test": "digigov test",
37
+ "build": "digigov build --subpackages"
38
+ }
39
+ }
package/src/App.tsx ADDED
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+ import App from 'next/app';
3
+ import Head from 'next/head';
4
+ import { LinkProvider } from '@digigov/ui/core/Link';
5
+ import NextLink from '@digigov/nextjs/Link';
6
+ import dynamic from 'next/dynamic';
7
+ import type { AppProps } from '@digigov/ui/app/App';
8
+ import { I18NProvider } from '@digigov/ui/app/i18n';
9
+ import { withTranslation, WithTranslation } from 'react-i18next';
10
+ import { i18n } from 'i18next';
11
+
12
+ const DigiGOVApp = dynamic(() => import('@digigov/ui/app/App'), {
13
+ ssr: false,
14
+ }) as React.FC<AppProps>;
15
+ export interface DigiGOVNextAppProps extends AppProps, WithTranslation {
16
+ children?: React.ReactNode;
17
+ t: (string) => string;
18
+ i18n: i18n;
19
+ }
20
+ class DigiGOVNextApp extends App<DigiGOVNextAppProps> {
21
+ componentDidMount(): void {
22
+ // Remove the server-side injected CSS.
23
+ const jssStyles = document.querySelector('#jss-server-side');
24
+ if (jssStyles && jssStyles.parentElement) {
25
+ jssStyles.parentElement.removeChild(jssStyles);
26
+ }
27
+ this.updateHtmlLang();
28
+ }
29
+
30
+ componentDidUpdate(): void {
31
+ this.updateHtmlLang();
32
+ }
33
+
34
+ updateHtmlLang(): void {
35
+ document.documentElement.lang = this.props.i18n.language;
36
+ }
37
+
38
+ render(): React.ReactElement {
39
+ const { Component, pageProps, t, i18n } = this.props;
40
+ return (
41
+ <I18NProvider
42
+ t={(str) => (typeof str === 'string' ? t(str) : str)}
43
+ i18n={i18n}
44
+ >
45
+ <LinkProvider component={NextLink}>
46
+ <Head>
47
+ <meta
48
+ name="viewport"
49
+ content="minimum-scale=1, initial-scale=1, width=device-width"
50
+ />
51
+ </Head>
52
+ <DigiGOVApp>
53
+ <Component {...pageProps} />
54
+ </DigiGOVApp>
55
+ </LinkProvider>
56
+ </I18NProvider>
57
+ );
58
+ }
59
+ }
60
+ const DigiGOVNextAppWithTranslation = withTranslation()(DigiGOVNextApp);
61
+ export default DigiGOVNextAppWithTranslation;
@@ -0,0 +1,73 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ import React from 'react';
3
+ import Document, { Html, Head, Main, NextScript } from 'next/document';
4
+
5
+ export function Fonts() {
6
+ return (
7
+ <>
8
+ <link
9
+ rel="stylesheet"
10
+ href="https://fonts.googleapis.com/icon?family=Material+Icons"
11
+ />
12
+ <link
13
+ rel="stylesheet"
14
+ href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
15
+ />
16
+ </>
17
+ );
18
+ }
19
+ export default class DigiGOVDocument extends Document {
20
+ render() {
21
+ return (
22
+ <Html>
23
+ <Head>
24
+ <script
25
+ type="text/javascript"
26
+ dangerouslySetInnerHTML={{
27
+ __html: `if (window.document.documentMode) alert('Internet Explorer is not supported. Please use a modern browser!');
28
+ `,
29
+ }}
30
+ ></script>
31
+ {/* PWA primary color */}
32
+ <Fonts />
33
+ </Head>
34
+ <body>
35
+ <Main />
36
+ <NextScript />
37
+ </body>
38
+ </Html>
39
+ );
40
+ }
41
+ }
42
+
43
+ DigiGOVDocument.getInitialProps = async (ctx) => {
44
+ // Resolution order
45
+ //
46
+ // On the server:
47
+ // 1. app.getInitialProps
48
+ // 2. page.getInitialProps
49
+ // 3. document.getInitialProps
50
+ // 4. app.render
51
+ // 5. page.render
52
+ // 6. document.render
53
+ //
54
+ // On the server with error:
55
+ // 1. document.getInitialProps
56
+ // 2. app.render
57
+ // 3. page.render
58
+ // 4. document.render
59
+ //
60
+ // On the client
61
+ // 1. app.getInitialProps
62
+ // 2. page.getInitialProps
63
+ // 3. app.render
64
+ // 4. page.render
65
+
66
+ // Render app and page and get the context of the page with collected side effects.
67
+ const initialProps = await Document.getInitialProps(ctx);
68
+
69
+ return {
70
+ ...initialProps,
71
+ // Styles fragment is rendered after the app and page rendering finish.
72
+ };
73
+ };
package/src/Image.tsx ADDED
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import NextImage, { ImageProps } from 'next/image';
3
+ import { useBasePath } from '@digigov/nextjs/hooks';
4
+
5
+ const Image: React.FC<ImageProps> = ({ src, ...rest }) => {
6
+ const basePathSrc = useBasePath(src);
7
+ return <NextImage src={basePathSrc} {...rest} />;
8
+ };
9
+
10
+ export default Image;
package/src/Link.tsx ADDED
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { LinkProps } from '@digigov/ui/core/Link';
3
+ import Link from 'next/link';
4
+ import CoreLink from '@digigov/react-core/Link';
5
+
6
+ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
7
+ props,
8
+ ref
9
+ ) => {
10
+ const { href, ...other } = props;
11
+ const isExternalLink =
12
+ //check if url has a file extension
13
+ /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') ||
14
+ // or if props has a target or rel
15
+ other.target === '_blank';
16
+
17
+ if (isExternalLink) {
18
+ return (
19
+ <CoreLink ref={ref} href={href || '#'} {...other}>
20
+ {props.children}
21
+ </CoreLink>
22
+ );
23
+ }
24
+ return (
25
+ <Link href={href || '#'} {...other}>
26
+ <CoreLink ref={ref} {...other}>
27
+ {props.children}
28
+ </CoreLink>
29
+ </Link>
30
+ );
31
+ };
32
+
33
+ export default React.forwardRef(NextLink);
package/src/hooks.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { useRouter } from 'next/router';
2
+
3
+ export function useBasePath(src: string): string {
4
+ const router = useRouter();
5
+ return router.basePath + src;
6
+ }
package/src/i18n.tsx ADDED
@@ -0,0 +1,18 @@
1
+ import i18n, { Resource, TFunction } from 'i18next';
2
+ import { initReactI18next } from 'react-i18next';
3
+
4
+ export default function initI18n(
5
+ resources: Resource,
6
+ language = 'el'
7
+ ): Promise<TFunction> {
8
+ return i18n
9
+ .use(initReactI18next) // passes i18n down to react-i18next
10
+ .init({
11
+ resources: resources,
12
+ lng: language,
13
+ keySeparator: '.', // we use keys in form messages.welcome
14
+ interpolation: {
15
+ escapeValue: false, // react already safes from xss
16
+ },
17
+ });
18
+ }
package/src/index.ts ADDED
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "@digigov/cli-build/tsconfig.base",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": [
7
+ "./src"
8
+ ],
9
+ "exclude": [
10
+ "node_modules",
11
+ "dist",
12
+ "*.svg"
13
+ ]
14
+ }