@koine/next 1.0.8 → 1.0.11
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/Analytics/AnalyticsGoogle.d.ts +0 -0
- package/Analytics/AnalyticsGoogle.js +2 -2
- package/Analytics/index.d.ts +0 -0
- package/Analytics/index.js +0 -0
- package/Analytics/package.json +6 -0
- package/Auth/helpers.d.ts +0 -0
- package/Auth/helpers.js +0 -0
- package/Auth/index.d.ts +0 -0
- package/Auth/index.js +0 -0
- package/Auth/package.json +6 -0
- package/Auth/useLogin.d.ts +1 -1
- package/Auth/useLogin.js +4 -1
- package/Auth/useLoginUrl.d.ts +0 -0
- package/Auth/useLoginUrl.js +0 -0
- package/Auth/useLogout.d.ts +0 -0
- package/Auth/useLogout.js +0 -0
- package/Favicon/Favicon.d.ts +0 -0
- package/Favicon/Favicon.js +1 -1
- package/Favicon/index.d.ts +0 -0
- package/Favicon/index.js +0 -0
- package/Favicon/package.json +6 -0
- package/Forms/index.d.ts +0 -0
- package/Forms/index.js +0 -0
- package/Forms/package.json +6 -0
- package/Forms/useForm.d.ts +0 -0
- package/Forms/useForm.js +8 -4
- package/Forms/useSubmit.d.ts +0 -0
- package/Forms/useSubmit.js +12 -9
- package/Head/Head.d.ts +0 -0
- package/Head/Head.js +0 -0
- package/Head/index.d.ts +0 -0
- package/Head/index.js +0 -0
- package/Head/package.json +6 -0
- package/I18n/I18n.d.ts +3 -7
- package/I18n/I18n.js +2 -14
- package/I18n/index.d.ts +0 -0
- package/I18n/index.js +0 -0
- package/I18n/package.json +6 -0
- package/Img/Img.d.ts +4 -4
- package/Img/Img.js +2 -4
- package/Img/index.d.ts +0 -0
- package/Img/index.js +0 -0
- package/Img/package.json +6 -0
- package/Link/Link.d.ts +4 -3
- package/Link/Link.js +2 -5
- package/Link/index.d.ts +0 -0
- package/Link/index.js +0 -0
- package/Link/package.json +6 -0
- package/NextProgress/NextProgress.d.ts +20 -9
- package/NextProgress/NextProgress.js +2 -3
- package/NextProgress/index.d.ts +2 -1
- package/NextProgress/index.js +1 -1
- package/NextProgress/package.json +6 -0
- package/README.md +0 -0
- package/Seo/Seo.d.ts +0 -0
- package/Seo/Seo.js +0 -0
- package/Seo/SeoDefaults.d.ts +0 -0
- package/Seo/SeoDefaults.js +0 -0
- package/Seo/helpers.d.ts +0 -0
- package/Seo/helpers.js +17 -19
- package/Seo/index.d.ts +0 -0
- package/Seo/index.js +0 -0
- package/Seo/package.json +6 -0
- package/Theme/Theme.d.ts +3 -3
- package/Theme/Theme.js +18 -18
- package/Theme/index.d.ts +0 -0
- package/Theme/index.js +0 -0
- package/Theme/package.json +6 -0
- package/app/AppHead.d.ts +1 -2
- package/app/AppHead.js +2 -2
- package/app/AppMain.d.ts +35 -0
- package/app/AppMain.js +1 -0
- package/app/css/AppMain.d.ts +8 -0
- package/app/{AppMain--vanilla.js → css/AppMain.js} +3 -3
- package/app/css/AppTheme.d.ts +10 -0
- package/app/{AppTheme--vanilla.js → css/AppTheme.js} +3 -3
- package/app/css/auth/index.d.ts +9 -0
- package/app/css/auth/index.js +13 -0
- package/app/css/auth/package.json +6 -0
- package/app/css/index.d.ts +54 -0
- package/app/css/index.js +57 -0
- package/app/css/package.json +6 -0
- package/app/em/AppMain.d.ts +10 -0
- package/app/em/AppMain.js +22 -0
- package/app/{AppTheme--emotion.d.ts → em/AppTheme.d.ts} +3 -3
- package/app/{AppTheme--emotion.js → em/AppTheme.js} +5 -5
- package/app/em/auth/index.d.ts +9 -0
- package/app/em/auth/index.js +13 -0
- package/app/em/auth/package.json +6 -0
- package/app/em/index.d.ts +9 -0
- package/app/em/index.js +12 -0
- package/app/em/package.json +6 -0
- package/app/index.d.ts +1 -10
- package/app/index.js +1 -10
- package/app/package.json +6 -0
- package/app/sc/AppMain.d.ts +10 -0
- package/app/sc/AppMain.js +22 -0
- package/app/sc/AppTheme.d.ts +13 -0
- package/app/sc/AppTheme.js +9 -0
- package/app/sc/auth/index.d.ts +9 -0
- package/app/sc/auth/index.js +13 -0
- package/app/sc/auth/package.json +6 -0
- package/app/sc/index.d.ts +56 -0
- package/app/sc/index.js +59 -0
- package/app/sc/package.json +6 -0
- package/config/index.d.ts +14 -1
- package/config/index.js +68 -38
- package/config/package.json +6 -0
- package/document/Document.d.ts +7 -2
- package/document/Document.js +8 -3
- package/document/css/index.d.ts +22 -0
- package/document/css/index.js +30 -0
- package/document/css/package.json +6 -0
- package/document/em/index.d.ts +16 -0
- package/document/{Document--emotion.js → em/index.js} +24 -11
- package/document/em/package.json +6 -0
- package/document/index.d.ts +2 -4
- package/document/index.js +2 -4
- package/document/package.json +6 -0
- package/document/{Document--sc.d.ts → sc/index.d.ts} +11 -2
- package/document/sc/index.js +44 -0
- package/document/sc/package.json +6 -0
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/node/Analytics/AnalyticsGoogle.js +42 -0
- package/node/Analytics/index.js +4 -0
- package/node/Auth/helpers.js +26 -0
- package/node/Auth/index.js +7 -0
- package/node/Auth/useLogin.js +54 -0
- package/node/Auth/useLoginUrl.js +15 -0
- package/node/Auth/useLogout.js +56 -0
- package/node/Favicon/Favicon.js +9 -0
- package/node/Favicon/index.js +4 -0
- package/node/Forms/index.js +5 -0
- package/node/Forms/useForm.js +41 -0
- package/node/Forms/useSubmit.js +27 -0
- package/node/Head/Head.js +8 -0
- package/node/Head/index.js +4 -0
- package/node/I18n/I18n.js +82 -0
- package/node/I18n/index.js +4 -0
- package/node/Img/Img.js +34 -0
- package/node/Img/index.js +4 -0
- package/node/Link/Link.js +13 -0
- package/node/Link/index.js +4 -0
- package/node/NextProgress/NextProgress.js +41 -0
- package/node/NextProgress/index.js +5 -0
- package/node/Seo/Seo.js +12 -0
- package/node/Seo/SeoDefaults.js +16 -0
- package/node/Seo/helpers.js +115 -0
- package/node/Seo/index.js +15 -0
- package/node/Theme/Theme.js +241 -0
- package/node/Theme/index.js +4 -0
- package/node/app/AppHead.js +10 -0
- package/node/app/AppMain.js +2 -0
- package/node/app/css/AppMain.js +16 -0
- package/node/app/css/AppTheme.js +16 -0
- package/node/app/css/auth/index.js +18 -0
- package/node/app/css/index.js +62 -0
- package/node/app/em/AppMain.js +26 -0
- package/node/app/em/AppTheme.js +22 -0
- package/node/app/em/auth/index.js +18 -0
- package/node/app/em/index.js +17 -0
- package/node/app/index.js +5 -0
- package/node/app/sc/AppMain.js +26 -0
- package/node/app/sc/AppTheme.js +13 -0
- package/node/app/sc/auth/index.js +18 -0
- package/node/app/sc/index.js +64 -0
- package/node/config/index.js +184 -0
- package/node/document/Document.js +24 -0
- package/node/document/css/index.js +35 -0
- package/node/document/em/index.js +73 -0
- package/node/document/index.js +7 -0
- package/node/document/sc/index.js +49 -0
- package/node/index.js +15 -0
- package/node/utils/api.js +38 -0
- package/node/utils/emotion-cache.js +13 -0
- package/node/utils/index.js +32 -0
- package/package.json +17 -25
- package/typings.d.ts +10 -7
- package/utils/api.d.ts +0 -0
- package/utils/api.js +8 -6
- package/utils/emotion-cache.d.ts +0 -0
- package/utils/emotion-cache.js +0 -0
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/utils/package.json +6 -0
- package/app/App--emotion.d.ts +0 -10
- package/app/App--emotion.js +0 -11
- package/app/App--sc.d.ts +0 -10
- package/app/App--sc.js +0 -11
- package/app/App--vanilla.d.ts +0 -10
- package/app/App--vanilla.js +0 -11
- package/app/AppAuth--emotion.d.ts +0 -10
- package/app/AppAuth--emotion.js +0 -12
- package/app/AppAuth--sc.d.ts +0 -10
- package/app/AppAuth--sc.js +0 -12
- package/app/AppMain--emotion.d.ts +0 -34
- package/app/AppMain--emotion.js +0 -27
- package/app/AppMain--sc.d.ts +0 -34
- package/app/AppMain--sc.js +0 -27
- package/app/AppMain--vanilla.d.ts +0 -27
- package/app/AppTheme--sc.d.ts +0 -13
- package/app/AppTheme--sc.js +0 -9
- package/app/AppTheme--vanilla.d.ts +0 -10
- package/app/motion-features.d.ts +0 -2
- package/app/motion-features.js +0 -2
- package/document/Document--emotion.d.ts +0 -5
- package/document/Document--sc.js +0 -33
- package/document/Document--vanilla.d.ts +0 -11
- package/document/Document--vanilla.js +0 -20
- package/index.umd.js +0 -6621
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AppProps } from "next/app";
|
|
2
|
+
import { AppThemeProps } from "./AppTheme";
|
|
3
|
+
import { AppMainProps } from "./AppMain";
|
|
4
|
+
export declare type NextAppProps = AppProps & AppThemeProps & AppMainProps;
|
|
5
|
+
/**
|
|
6
|
+
* App
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { NextApp, NextAppProps } from "@koine/next/app/sc/auth";
|
|
12
|
+
* import { Favicon, AnalyticsGoogle } from "@koine/next";
|
|
13
|
+
* import { theme } from "src/helpers/theme";
|
|
14
|
+
* import { Layout, ProgressOverlay } from "src/components/Layout";
|
|
15
|
+
* // import "@fontsource/myfont/800.css";
|
|
16
|
+
* // import "src/helpers/theme.css";
|
|
17
|
+
*
|
|
18
|
+
* const motion = () => import("@koine/react/m/max").then((m) => m.default);
|
|
19
|
+
*
|
|
20
|
+
* export default function App(props: NextAppProps) {
|
|
21
|
+
* return (
|
|
22
|
+
* <NextApp
|
|
23
|
+
* {...props}
|
|
24
|
+
* Layout={Layout}
|
|
25
|
+
* ProgressOverlay={ProgressOverlay}
|
|
26
|
+
* theme={theme}
|
|
27
|
+
* motion={motion}
|
|
28
|
+
* seo={{
|
|
29
|
+
* titleTemplate: "%s | MyApp",
|
|
30
|
+
* defaultTitle: "MyApp",
|
|
31
|
+
* openGraph: {
|
|
32
|
+
* type: "website",
|
|
33
|
+
* locale: "en_US",
|
|
34
|
+
* url: "https://myapp.com/",
|
|
35
|
+
* site_name: "MyApp",
|
|
36
|
+
* },
|
|
37
|
+
* twitter: {
|
|
38
|
+
* handle: "@MklrNl",
|
|
39
|
+
* site: "@MyApp",
|
|
40
|
+
* cardType: "summary_large_image",
|
|
41
|
+
* },
|
|
42
|
+
* }}
|
|
43
|
+
* pre={
|
|
44
|
+
* <>
|
|
45
|
+
* <AnalyticsGoogle id="UA-xxxxxxxx-x" />
|
|
46
|
+
* <Favicon name="MyApp" color="#000000" />
|
|
47
|
+
* </>
|
|
48
|
+
* }
|
|
49
|
+
* />
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const NextApp: (props: NextAppProps) => JSX.Element;
|
|
56
|
+
export default NextApp;
|
package/app/sc/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { AppHead } from "../AppHead";
|
|
4
|
+
import { AppTheme } from "./AppTheme";
|
|
5
|
+
import { AppMain } from "./AppMain";
|
|
6
|
+
/**
|
|
7
|
+
* App
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { NextApp, NextAppProps } from "@koine/next/app/sc/auth";
|
|
13
|
+
* import { Favicon, AnalyticsGoogle } from "@koine/next";
|
|
14
|
+
* import { theme } from "src/helpers/theme";
|
|
15
|
+
* import { Layout, ProgressOverlay } from "src/components/Layout";
|
|
16
|
+
* // import "@fontsource/myfont/800.css";
|
|
17
|
+
* // import "src/helpers/theme.css";
|
|
18
|
+
*
|
|
19
|
+
* const motion = () => import("@koine/react/m/max").then((m) => m.default);
|
|
20
|
+
*
|
|
21
|
+
* export default function App(props: NextAppProps) {
|
|
22
|
+
* return (
|
|
23
|
+
* <NextApp
|
|
24
|
+
* {...props}
|
|
25
|
+
* Layout={Layout}
|
|
26
|
+
* ProgressOverlay={ProgressOverlay}
|
|
27
|
+
* theme={theme}
|
|
28
|
+
* motion={motion}
|
|
29
|
+
* seo={{
|
|
30
|
+
* titleTemplate: "%s | MyApp",
|
|
31
|
+
* defaultTitle: "MyApp",
|
|
32
|
+
* openGraph: {
|
|
33
|
+
* type: "website",
|
|
34
|
+
* locale: "en_US",
|
|
35
|
+
* url: "https://myapp.com/",
|
|
36
|
+
* site_name: "MyApp",
|
|
37
|
+
* },
|
|
38
|
+
* twitter: {
|
|
39
|
+
* handle: "@MklrNl",
|
|
40
|
+
* site: "@MyApp",
|
|
41
|
+
* cardType: "summary_large_image",
|
|
42
|
+
* },
|
|
43
|
+
* }}
|
|
44
|
+
* pre={
|
|
45
|
+
* <>
|
|
46
|
+
* <AnalyticsGoogle id="UA-xxxxxxxx-x" />
|
|
47
|
+
* <Favicon name="MyApp" color="#000000" />
|
|
48
|
+
* </>
|
|
49
|
+
* }
|
|
50
|
+
* />
|
|
51
|
+
* );
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const NextApp = (props) => {
|
|
57
|
+
return (_jsxs(React.StrictMode, { children: [_jsx(AppHead, {}), _jsx(AppTheme, { ...props, children: _jsx(AppMain, { ...props }) })] }));
|
|
58
|
+
};
|
|
59
|
+
export default NextApp;
|
package/config/index.d.ts
CHANGED
|
@@ -50,9 +50,22 @@ declare type KoineNextConfig = {
|
|
|
50
50
|
svg?: boolean;
|
|
51
51
|
/** @default true Styled components enabled */
|
|
52
52
|
sc?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* When true uses `*.page.ts` or `*.page.tsx` extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory). When `true` it enables the same for `next-translate`
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
page?: boolean;
|
|
53
58
|
};
|
|
54
59
|
/**
|
|
55
60
|
* Get Next.js config with some basic opinionated defaults
|
|
61
|
+
*
|
|
62
|
+
* @param {object} options
|
|
63
|
+
* @property {boolean} [options.nx=false] Nx monorepo setup
|
|
64
|
+
* @property {boolean} [options.svg=false] Svg to react components
|
|
65
|
+
* @property {boolean} [options.sc=false] Styled components enabled
|
|
66
|
+
* @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
|
|
67
|
+
* extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory)
|
|
68
|
+
* and it enables the same for `next-translate`.
|
|
56
69
|
*/
|
|
57
|
-
export declare function withKoine({ nx, svg, sc, ...nextConfig }?: NextConfig & KoineNextConfig): NextConfig;
|
|
70
|
+
export declare function withKoine({ nx, svg, sc, page, ...nextConfig }?: NextConfig & KoineNextConfig): NextConfig;
|
|
58
71
|
export default withKoine;
|
package/config/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter, __rest } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* Normalise pathname
|
|
4
3
|
*
|
|
@@ -44,61 +43,92 @@ export function getPathRewrite(source, destination, dynamic) {
|
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
*/
|
|
47
|
-
export function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
|
|
58
|
-
}
|
|
46
|
+
export async function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }) {
|
|
47
|
+
const redirects = [];
|
|
48
|
+
Object.keys(routes).forEach((page) => {
|
|
49
|
+
const dynamic = dynamicRoutes[page];
|
|
50
|
+
if (routes[page] !== page) {
|
|
51
|
+
if (dynamic) {
|
|
52
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
else {
|
|
55
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
63
58
|
});
|
|
59
|
+
// console.log("redirects", redirects);
|
|
60
|
+
return redirects;
|
|
64
61
|
}
|
|
65
62
|
/**
|
|
66
63
|
*/
|
|
67
|
-
export function getRewrites({ routes, dynamicRoutes, }) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
rewrites.push(getPathRewrite(routes[page], page));
|
|
78
|
-
}
|
|
64
|
+
export async function getRewrites({ routes, dynamicRoutes, }) {
|
|
65
|
+
const rewrites = [];
|
|
66
|
+
Object.keys(routes).forEach((page) => {
|
|
67
|
+
const dynamic = dynamicRoutes[page];
|
|
68
|
+
if (routes[page] !== page) {
|
|
69
|
+
if (dynamic) {
|
|
70
|
+
rewrites.push(getPathRewrite(routes[page], page, true));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
rewrites.push(getPathRewrite(routes[page], page));
|
|
79
74
|
}
|
|
80
|
-
}
|
|
81
|
-
// console.log("rewrites", rewrites);
|
|
82
|
-
return rewrites;
|
|
75
|
+
}
|
|
83
76
|
});
|
|
77
|
+
// console.log("rewrites", rewrites);
|
|
78
|
+
return rewrites;
|
|
84
79
|
}
|
|
85
80
|
/**
|
|
86
81
|
* Get Next.js config with some basic opinionated defaults
|
|
82
|
+
*
|
|
83
|
+
* @param {object} options
|
|
84
|
+
* @property {boolean} [options.nx=false] Nx monorepo setup
|
|
85
|
+
* @property {boolean} [options.svg=false] Svg to react components
|
|
86
|
+
* @property {boolean} [options.sc=false] Styled components enabled
|
|
87
|
+
* @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
|
|
88
|
+
* extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory)
|
|
89
|
+
* and it enables the same for `next-translate`.
|
|
87
90
|
*/
|
|
88
|
-
export function withKoine(
|
|
89
|
-
|
|
90
|
-
nextConfig = Object.assign({
|
|
91
|
+
export function withKoine({ nx = true, svg = true, sc = true, page, ...nextConfig } = {}) {
|
|
92
|
+
nextConfig = {
|
|
91
93
|
// @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
|
|
92
|
-
pageExtensions: ["page.tsx", "page.ts"]
|
|
94
|
+
pageExtensions: page ? ["page.tsx", "page.ts"] : undefined,
|
|
95
|
+
eslint: {
|
|
93
96
|
ignoreDuringBuilds: true, // we have this strict check on each commit
|
|
94
|
-
},
|
|
97
|
+
},
|
|
98
|
+
typescript: {
|
|
95
99
|
ignoreBuildErrors: true, // we have this strict check on each commit
|
|
96
|
-
},
|
|
100
|
+
},
|
|
101
|
+
poweredByHeader: false,
|
|
102
|
+
swcMinify: true,
|
|
103
|
+
experimental: {
|
|
97
104
|
// @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
|
|
98
105
|
// @see critters error https://github.com/vercel/next.js/issues/20742
|
|
99
106
|
// optimizeCss: true,
|
|
100
107
|
// @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
|
|
101
|
-
scrollRestoration: true
|
|
108
|
+
scrollRestoration: true,
|
|
109
|
+
// concurrentFeatures: true,
|
|
110
|
+
// serverComponents: true,
|
|
111
|
+
// reactRoot: true,
|
|
112
|
+
...(nextConfig.experimental || {}),
|
|
113
|
+
// @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
|
|
114
|
+
modularizeImports: {
|
|
115
|
+
...(nextConfig?.experimental?.modularizeImports || {}),
|
|
116
|
+
// FIXME: make these work with the right file/folder structure?
|
|
117
|
+
// "@koine/next/?(((\\w*)?/?)*)": {
|
|
118
|
+
// transform: "@koine/next/{{ matches.[1] }}/{{member}}",
|
|
119
|
+
// },
|
|
120
|
+
// "@koine/react/?(((\\w*)?/?)*)": {
|
|
121
|
+
// transform: "@koine/react/{{ matches.[1] }}/{{member}}",
|
|
122
|
+
// },
|
|
123
|
+
// "@koine/utils/?(((\\w*)?/?)*)": {
|
|
124
|
+
// transform: "@koine/utils/{{ matches.[1] }}/{{member}}",
|
|
125
|
+
// },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
// @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
|
|
129
|
+
// reactStrictMode: false,
|
|
130
|
+
...nextConfig,
|
|
131
|
+
};
|
|
102
132
|
if (svg) {
|
|
103
133
|
if (nx) {
|
|
104
134
|
// @see https://github.com/gregberge/svgr
|
package/document/Document.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import NextDocument from "next/document";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Next Document wrapper for bare projects
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* in your `myapp/pages/_document.tsx`:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* export { Document as default } from "@koine/next/document";
|
|
11
|
+
* ```
|
|
7
12
|
*/
|
|
8
13
|
export declare class Document extends NextDocument {
|
|
9
14
|
render(): JSX.Element;
|
package/document/Document.js
CHANGED
|
@@ -2,13 +2,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import NextDocument, { Html, Head, Main, NextScript } from "next/document";
|
|
3
3
|
import { Meta, NoJs } from "@koine/react";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Next Document wrapper for bare projects
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* in your `myapp/pages/_document.tsx`:
|
|
10
|
+
* ```tsx
|
|
11
|
+
* export { Document as default } from "@koine/next/document";
|
|
12
|
+
* ```
|
|
8
13
|
*/
|
|
9
14
|
export class Document extends NextDocument {
|
|
10
15
|
render() {
|
|
11
16
|
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
12
|
-
return (_jsxs(Html,
|
|
17
|
+
return (_jsxs(Html, { lang: locale || defaultLocale, className: "no-js", children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] }));
|
|
13
18
|
}
|
|
14
19
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
|
|
3
|
+
import { ThemeVanillaValue } from "@koine/react/sc";
|
|
4
|
+
/**
|
|
5
|
+
* Next Document wrapper for `css/tailwind` based projects
|
|
6
|
+
*
|
|
7
|
+
* Uses cookie to manage the current theme
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* in your `myapp/pages/_document.tsx`:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* export { Document as default } from "@koine/next/document/css";
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class Document extends NextDocument {
|
|
17
|
+
static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps & {
|
|
18
|
+
theme: ThemeVanillaValue;
|
|
19
|
+
}>;
|
|
20
|
+
render(): JSX.Element;
|
|
21
|
+
}
|
|
22
|
+
export default Document;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import NextDocument, { Html, Head, Main, NextScript, } from "next/document";
|
|
3
|
+
import { Meta, NoJs } from "@koine/react";
|
|
4
|
+
import { getInitialThemeFromRequest } from "@koine/react/sc"; // FIXME: this should be imported from another entrypoint
|
|
5
|
+
/**
|
|
6
|
+
* Next Document wrapper for `css/tailwind` based projects
|
|
7
|
+
*
|
|
8
|
+
* Uses cookie to manage the current theme
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* in your `myapp/pages/_document.tsx`:
|
|
13
|
+
* ```tsx
|
|
14
|
+
* export { Document as default } from "@koine/next/document/css";
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class Document extends NextDocument {
|
|
18
|
+
static async getInitialProps(ctx) {
|
|
19
|
+
const initialProps = await NextDocument.getInitialProps(ctx);
|
|
20
|
+
return {
|
|
21
|
+
...initialProps,
|
|
22
|
+
theme: getInitialThemeFromRequest(ctx.req?.headers.cookie /* || document?.cookie */ || ""),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
27
|
+
return (_jsxs(Html, { lang: locale || defaultLocale, className: "no-js", children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] }));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export default Document;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument from "next/document";
|
|
3
|
+
/**
|
|
4
|
+
* Next Document wrapper for `emotion` based projects
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* in your `myapp/pages/_document.tsx`:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* export { Document as default } from "@koine/next/document/em";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class Document extends NextDocument {
|
|
14
|
+
render(): JSX.Element;
|
|
15
|
+
}
|
|
16
|
+
export default Document;
|
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
2
|
+
import NextDocument, { Html, Head, Main, NextScript } from "next/document";
|
|
3
|
+
import { Meta, NoJs } from "@koine/react";
|
|
4
4
|
import createEmotionServer from "@emotion/server/create-instance";
|
|
5
|
-
import { createEmotionCache } from "
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { createEmotionCache } from "../../utils/emotion-cache";
|
|
6
|
+
/**
|
|
7
|
+
* Next Document wrapper for `emotion` based projects
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* in your `myapp/pages/_document.tsx`:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* export { Document as default } from "@koine/next/document/em";
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class Document extends NextDocument {
|
|
8
17
|
render() {
|
|
9
18
|
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
10
|
-
return (_jsxs(Html,
|
|
19
|
+
return (_jsxs(Html, { lang: locale || defaultLocale, className: "no-js", children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {}), this.props.emotionStyleTags] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] }));
|
|
11
20
|
}
|
|
12
21
|
}
|
|
13
22
|
// `getInitialProps` belongs to `_document` (instead of `_app`),
|
|
14
23
|
// it's compatible with static-site generation (SSG).
|
|
15
|
-
|
|
24
|
+
Document.getInitialProps = async (ctx) => {
|
|
16
25
|
// Resolution order
|
|
17
26
|
//
|
|
18
27
|
// On the server:
|
|
@@ -41,15 +50,19 @@ DocumentEmotion.getInitialProps = (ctx) => __awaiter(void 0, void 0, void 0, fun
|
|
|
41
50
|
const { extractCriticalToChunks } = createEmotionServer(cache);
|
|
42
51
|
ctx.renderPage = () => originalRenderPage({
|
|
43
52
|
enhanceApp: (App) => function EnhanceApp(props) {
|
|
44
|
-
return _jsx(App,
|
|
53
|
+
return _jsx(App, { emotionCache: cache, ...props });
|
|
45
54
|
},
|
|
46
55
|
});
|
|
47
|
-
const initialProps =
|
|
56
|
+
const initialProps = await Document.getInitialProps(ctx);
|
|
48
57
|
// This is important. It prevents emotion to render invalid HTML.
|
|
49
58
|
// See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
|
|
50
59
|
const emotionStyles = extractCriticalToChunks(initialProps.html);
|
|
51
60
|
const emotionStyleTags = emotionStyles.styles.map((style) => (_jsx("style", { "data-emotion": `${style.key} ${style.ids.join(" ")}`,
|
|
52
61
|
// eslint-disable-next-line react/no-danger
|
|
53
62
|
dangerouslySetInnerHTML: { __html: style.css } }, style.key)));
|
|
54
|
-
return
|
|
55
|
-
|
|
63
|
+
return {
|
|
64
|
+
...initialProps,
|
|
65
|
+
emotionStyleTags,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export default Document;
|
package/document/index.d.ts
CHANGED
package/document/index.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Next Document wrapper for `styled-components` based projects
|
|
5
5
|
*
|
|
6
|
+
* For typescript safety of this component
|
|
6
7
|
* @see https://bit.ly/3ceuF8m
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* in your `myapp/pages/_document.tsx`:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* export { Document as default } from "@koine/next/document/sc";
|
|
14
|
+
* ```
|
|
7
15
|
*/
|
|
8
|
-
export declare class
|
|
16
|
+
export declare class Document extends NextDocument {
|
|
9
17
|
static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps>;
|
|
10
18
|
render(): JSX.Element;
|
|
11
19
|
}
|
|
20
|
+
export default Document;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
/* ? eslint-disable @next/next/no-document-import-in-page */
|
|
4
|
+
import NextDocument, { Html, Head, Main, NextScript, } from "next/document";
|
|
5
|
+
import { Meta, NoJs } from "@koine/react";
|
|
6
|
+
import { ServerStyleSheet } from "styled-components";
|
|
7
|
+
/**
|
|
8
|
+
* Next Document wrapper for `styled-components` based projects
|
|
9
|
+
*
|
|
10
|
+
* For typescript safety of this component
|
|
11
|
+
* @see https://bit.ly/3ceuF8m
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* in your `myapp/pages/_document.tsx`:
|
|
16
|
+
* ```tsx
|
|
17
|
+
* export { Document as default } from "@koine/next/document/sc";
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class Document extends NextDocument {
|
|
21
|
+
static async getInitialProps(ctx) {
|
|
22
|
+
const sheet = new ServerStyleSheet();
|
|
23
|
+
const originalRenderPage = ctx.renderPage;
|
|
24
|
+
try {
|
|
25
|
+
ctx.renderPage = () => originalRenderPage({
|
|
26
|
+
enhanceApp: (App) => (props) => sheet.collectStyles(_jsx(App, { ...props })),
|
|
27
|
+
});
|
|
28
|
+
const initialProps = await NextDocument.getInitialProps(ctx);
|
|
29
|
+
return {
|
|
30
|
+
...initialProps,
|
|
31
|
+
// @ts-expect-error FIXME: have they changed type?
|
|
32
|
+
styles: (_jsxs(React.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
sheet.seal();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
render() {
|
|
40
|
+
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
41
|
+
return (_jsxs(Html, { lang: locale || defaultLocale, className: "no-js", children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] }));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export default Document;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnalyticsGoogle = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const router_1 = require("next/router");
|
|
8
|
+
const script_1 = tslib_1.__importDefault(require("next/script"));
|
|
9
|
+
const utils_1 = require("@koine/utils");
|
|
10
|
+
const AnalyticsGoogle = ({ id }) => {
|
|
11
|
+
const uid = id || process.env["NEXT_PUBLIC_GTM_ID"];
|
|
12
|
+
const { events, asPath, query } = (0, router_1.useRouter)();
|
|
13
|
+
const [ready, setReady] = (0, react_1.useState)(false);
|
|
14
|
+
const [routed, setRouted] = (0, react_1.useState)(false);
|
|
15
|
+
// const [url, setUrl] = useState("");
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
const handleRouteChange = () => {
|
|
18
|
+
setRouted(true);
|
|
19
|
+
};
|
|
20
|
+
events.on("routeChangeComplete", handleRouteChange);
|
|
21
|
+
return () => {
|
|
22
|
+
events.off("routeChangeComplete", handleRouteChange);
|
|
23
|
+
};
|
|
24
|
+
}, [events]);
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
if (routed && ready && asPath) {
|
|
27
|
+
// const search = query;
|
|
28
|
+
(0, utils_1.pageview)(asPath);
|
|
29
|
+
}
|
|
30
|
+
}, [asPath, query, routed, ready]);
|
|
31
|
+
if (!uid) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(script_1.default, { id: "google-tagmanager", src: `https://www.googletagmanager.com/gtag/js?id=${id}`, strategy: "afterInteractive", onLoad: () => setReady(true) }), (0, jsx_runtime_1.jsx)(script_1.default, { id: "google-analytics", strategy: "afterInteractive", children: `
|
|
35
|
+
window.dataLayer = window.dataLayer || [];
|
|
36
|
+
function gtag(){window.dataLayer.push(arguments);}
|
|
37
|
+
gtag('js', new Date());
|
|
38
|
+
|
|
39
|
+
gtag('config', '${id}', { 'send_page_view': false });
|
|
40
|
+
` })] }));
|
|
41
|
+
};
|
|
42
|
+
exports.AnalyticsGoogle = AnalyticsGoogle;
|