@digigov/nextjs 0.6.1 → 0.6.3-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 (56) 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 +918 -0
  6. package/CHANGELOG.md +8 -1
  7. package/{App.js → dist/App.js} +1 -9
  8. package/dist/CHANGELOG.md +248 -0
  9. package/{Document.js → dist/Document.js} +0 -0
  10. package/{Image.js → dist/Image.js} +0 -0
  11. package/{LICENSE → dist/LICENSE} +0 -0
  12. package/{Link.js → dist/Link.js} +0 -0
  13. package/dist/README.md +52 -0
  14. package/{es → dist/es}/App.js +1 -8
  15. package/{es → dist/es}/Document.js +0 -0
  16. package/{es → dist/es}/Image.js +0 -0
  17. package/{es → dist/es}/Link.js +0 -0
  18. package/{es → dist/es}/hooks.js +0 -0
  19. package/{es → dist/es}/i18n.js +0 -0
  20. package/{es → dist/es}/index.js +0 -0
  21. package/{esm → dist/esm}/App.js +1 -8
  22. package/{esm → dist/esm}/Document.js +0 -0
  23. package/{esm → dist/esm}/Image.js +0 -0
  24. package/{esm → dist/esm}/Link.js +0 -0
  25. package/{esm → dist/esm}/hooks.js +0 -0
  26. package/{esm → dist/esm}/i18n.js +0 -0
  27. package/{esm → dist/esm}/index.js +1 -1
  28. package/{hooks.js → dist/hooks.js} +0 -0
  29. package/{i18n.js → dist/i18n.js} +0 -0
  30. package/{index.js → dist/index.js} +0 -0
  31. package/{libs → dist/libs}/nextjs/src/App.d.ts +0 -2
  32. package/{libs → dist/libs}/nextjs/src/Document.d.ts +0 -0
  33. package/{libs → dist/libs}/nextjs/src/Image.d.ts +0 -0
  34. package/{libs → dist/libs}/nextjs/src/Link.d.ts +0 -0
  35. package/{libs → dist/libs}/nextjs/src/hooks.d.ts +0 -0
  36. package/{libs → dist/libs}/nextjs/src/i18n.d.ts +0 -0
  37. package/{libs → dist/libs}/nextjs/src/index.d.ts +0 -0
  38. package/dist/libs/ui/src/app/App.d.ts +7 -0
  39. package/{libs → dist/libs}/ui/src/app/i18n.d.ts +2 -2
  40. package/{libs → dist/libs}/ui/src/core/Link/index.d.ts +0 -0
  41. package/{libs → dist/libs}/ui/src/locales/el.d.ts +8 -1
  42. package/{libs-ui → dist/libs-ui}/react-core/src/Base/index.d.ts +0 -0
  43. package/{libs-ui → dist/libs-ui}/react-core/src/Link/index.d.ts +0 -0
  44. package/dist/package.json +26 -0
  45. package/nextjs.build.log +17 -0
  46. package/package.json +38 -25
  47. package/src/App.tsx +52 -0
  48. package/src/Document.tsx +86 -0
  49. package/src/Image.tsx +10 -0
  50. package/src/Link.tsx +33 -0
  51. package/src/hooks.ts +6 -0
  52. package/src/i18n.tsx +18 -0
  53. package/src/index.ts +0 -0
  54. package/tsconfig.json +14 -0
  55. package/libs/ui/src/app/App.d.ts +0 -14
  56. package/libs/ui/src/themes/govgr.d.ts +0 -3
package/src/App.tsx ADDED
@@ -0,0 +1,52 @@
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
+ }
28
+
29
+ render(): React.ReactElement {
30
+ const { Component, pageProps, t, i18n } = this.props;
31
+ return (
32
+ <I18NProvider
33
+ t={(str) => (typeof str === 'string' ? t(str) : str)}
34
+ i18n={i18n}
35
+ >
36
+ <LinkProvider component={NextLink}>
37
+ <Head>
38
+ <meta
39
+ name="viewport"
40
+ content="minimum-scale=1, initial-scale=1, width=device-width"
41
+ />
42
+ </Head>
43
+ <DigiGOVApp>
44
+ <Component {...pageProps} />
45
+ </DigiGOVApp>
46
+ </LinkProvider>
47
+ </I18NProvider>
48
+ );
49
+ }
50
+ }
51
+ const DigiGOVNextAppWithTranslation = withTranslation()(DigiGOVNextApp);
52
+ export default DigiGOVNextAppWithTranslation;
@@ -0,0 +1,86 @@
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
+ import { ServerStyleSheets } from '@material-ui/core/styles';
5
+
6
+ export function Fonts() {
7
+ return (
8
+ <>
9
+ <link
10
+ rel="stylesheet"
11
+ href="https://fonts.googleapis.com/icon?family=Material+Icons"
12
+ />
13
+ <link
14
+ rel="stylesheet"
15
+ href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
16
+ />
17
+ </>
18
+ );
19
+ }
20
+ export default class DigiGOVDocument extends Document {
21
+ render() {
22
+ return (
23
+ <Html>
24
+ <Head>
25
+ <script
26
+ type="text/javascript"
27
+ dangerouslySetInnerHTML={{
28
+ __html: `if (window.document.documentMode) alert('Internet Explorer is not supported. Please use a modern browser!');
29
+ `,
30
+ }}
31
+ ></script>
32
+ {/* PWA primary color */}
33
+ <Fonts />
34
+ </Head>
35
+ <body>
36
+ <Main />
37
+ <NextScript />
38
+ </body>
39
+ </Html>
40
+ );
41
+ }
42
+ }
43
+
44
+ DigiGOVDocument.getInitialProps = async (ctx) => {
45
+ // Resolution order
46
+ //
47
+ // On the server:
48
+ // 1. app.getInitialProps
49
+ // 2. page.getInitialProps
50
+ // 3. document.getInitialProps
51
+ // 4. app.render
52
+ // 5. page.render
53
+ // 6. document.render
54
+ //
55
+ // On the server with error:
56
+ // 1. document.getInitialProps
57
+ // 2. app.render
58
+ // 3. page.render
59
+ // 4. document.render
60
+ //
61
+ // On the client
62
+ // 1. app.getInitialProps
63
+ // 2. page.getInitialProps
64
+ // 3. app.render
65
+ // 4. page.render
66
+
67
+ // Render app and page and get the context of the page with collected side effects.
68
+ const sheets = new ServerStyleSheets();
69
+ const originalRenderPage = ctx.renderPage;
70
+
71
+ ctx.renderPage = () =>
72
+ originalRenderPage({
73
+ enhanceApp: (App) => (props) => sheets.collect(<App {...props} />),
74
+ });
75
+
76
+ const initialProps = await Document.getInitialProps(ctx);
77
+
78
+ return {
79
+ ...initialProps,
80
+ // Styles fragment is rendered after the app and page rendering finish.
81
+ styles: [
82
+ ...React.Children.toArray(initialProps.styles),
83
+ sheets.getStyleElement(),
84
+ ],
85
+ };
86
+ };
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
+ }
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { BaseCSSProperties } from '@material-ui/core/styles/withStyles';
3
- import { Theme } from '@material-ui/core/styles';
4
- export declare const useAppStyles: (props?: any) => import("@material-ui/core/styles/withStyles").ClassNameMap<"root">;
5
- export interface AppProps {
6
- theme: Theme;
7
- children?: React.ReactNode;
8
- classes?: {
9
- root: BaseCSSProperties;
10
- };
11
- }
12
- declare const App: React.FC<AppProps>;
13
- export declare const StaticApp: React.FC<AppProps>;
14
- export default App;
@@ -1,3 +0,0 @@
1
- export const PORTAL_URL: "http://34.194.85.187/";
2
- export default theme;
3
- declare let theme: import("@material-ui/core/styles").Theme;