@digigov/nextjs 0.6.5 → 0.6.6
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/.eslintrc.js +3 -0
- package/.prettierrc.js +3 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/package-deps_build.json +21 -0
- package/.rush/temp/shrinkwrap-deps.json +334 -0
- package/CHANGELOG.json +990 -0
- package/CHANGELOG.md +8 -1
- package/{App.js → dist/App.js} +0 -0
- package/dist/CHANGELOG.md +275 -0
- package/{Document.js → dist/Document.js} +0 -0
- package/{Image.js → dist/Image.js} +0 -0
- package/{LICENSE → dist/LICENSE} +0 -0
- package/{Link.js → dist/Link.js} +3 -3
- package/dist/README.md +52 -0
- package/{es → dist/es}/App.js +0 -0
- package/{es → dist/es}/Document.js +0 -0
- package/{es → dist/es}/Image.js +0 -0
- package/{esm → dist/es}/Link.js +3 -3
- package/{es → dist/es}/hooks.js +0 -0
- package/{es → dist/es}/i18n.js +0 -0
- package/{es → dist/es}/index.js +0 -0
- package/{esm → dist/esm}/App.js +0 -0
- package/{esm → dist/esm}/Document.js +0 -0
- package/{esm → dist/esm}/Image.js +0 -0
- package/{es → dist/esm}/Link.js +3 -3
- package/{esm → dist/esm}/hooks.js +0 -0
- package/{esm → dist/esm}/i18n.js +0 -0
- package/{esm → dist/esm}/index.js +1 -1
- package/{hooks.js → dist/hooks.js} +0 -0
- package/{i18n.js → dist/i18n.js} +0 -0
- package/{index.js → dist/index.js} +0 -0
- package/{libs → dist/libs}/nextjs/src/App.d.ts +0 -0
- package/{libs → dist/libs}/nextjs/src/Document.d.ts +0 -0
- package/{libs → dist/libs}/nextjs/src/Image.d.ts +0 -0
- package/{libs → dist/libs}/nextjs/src/Link.d.ts +0 -0
- package/{libs → dist/libs}/nextjs/src/hooks.d.ts +0 -0
- package/{libs → dist/libs}/nextjs/src/i18n.d.ts +0 -0
- package/{libs → dist/libs}/nextjs/src/index.d.ts +0 -0
- package/{libs → dist/libs}/ui/src/app/App.d.ts +0 -0
- package/{libs → dist/libs}/ui/src/app/i18n.d.ts +0 -0
- package/{libs → dist/libs}/ui/src/core/Link/index.d.ts +3 -3
- package/{libs → dist/libs}/ui/src/locales/el.d.ts +0 -0
- package/{libs-ui → dist/libs-ui}/react-core/src/Base/index.d.ts +0 -0
- package/dist/libs-ui/react-core/src/LinkBase/index.d.ts +14 -0
- package/dist/package.json +26 -0
- package/nextjs.build.log +16 -0
- package/package.json +37 -24
- package/src/App.tsx +61 -0
- package/src/Document.tsx +73 -0
- package/src/Image.tsx +10 -0
- package/src/Link.tsx +33 -0
- package/src/hooks.ts +6 -0
- package/src/i18n.tsx +18 -0
- package/src/index.ts +0 -0
- package/tsconfig.json +14 -0
- package/libs-ui/react-core/src/Link/index.d.ts +0 -14
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;
|
package/src/Document.tsx
ADDED
|
@@ -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 LinkBase from '@digigov/react-core/LinkBase';
|
|
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
|
+
<LinkBase ref={ref} href={href || '#'} {...other}>
|
|
20
|
+
{props.children}
|
|
21
|
+
</LinkBase>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return (
|
|
25
|
+
<Link href={href || '#'} {...other}>
|
|
26
|
+
<LinkBase ref={ref} {...other}>
|
|
27
|
+
{props.children}
|
|
28
|
+
</LinkBase>
|
|
29
|
+
</Link>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default React.forwardRef(NextLink);
|
package/src/hooks.ts
ADDED
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
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { BaseProps } from '@digigov/react-core/Base';
|
|
3
|
-
export interface LinkProps extends BaseProps<'a'> {
|
|
4
|
-
/**
|
|
5
|
-
* underline is optional. The default value is 'true'.
|
|
6
|
-
* Make it 'false' only if the context tells the user that the text is a link, even without the underline.
|
|
7
|
-
*/
|
|
8
|
-
underline?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* This component defines a hyperlink, which is used to link from one page to another.
|
|
12
|
-
*/
|
|
13
|
-
export declare const Link: React.ForwardRefExoticComponent<Pick<LinkProps, "slot" | "style" | "title" | "as" | "className" | "color" | "id" | "lang" | "media" | "target" | "type" | "role" | "tabIndex" | "href" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "translate" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "download" | "hrefLang" | "ping" | "rel" | "referrerPolicy" | "margin" | "marginTop" | "marginBottom" | "marginLeft" | "marginRight" | "padding" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "printHidden" | "underline"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
14
|
-
export default Link;
|