@koine/next 1.0.4 → 1.0.9
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 +5 -6
- package/Analytics/AnalyticsGoogle.js +37 -0
- package/Analytics/index.d.ts +1 -1
- package/Analytics/index.js +1 -0
- package/Analytics/package.json +6 -0
- package/Auth/helpers.d.ts +17 -17
- package/Auth/helpers.js +21 -0
- package/Auth/index.d.ts +4 -4
- package/Auth/index.js +4 -0
- package/Auth/package.json +6 -0
- package/Auth/useLogin.d.ts +7 -7
- package/Auth/useLogin.js +50 -0
- package/Auth/useLoginUrl.d.ts +1 -1
- package/Auth/useLoginUrl.js +11 -0
- package/Auth/useLogout.d.ts +6 -6
- package/Auth/useLogout.js +52 -0
- package/Favicon/Favicon.d.ts +3 -4
- package/Favicon/Favicon.js +4 -0
- package/Favicon/index.d.ts +1 -1
- package/Favicon/index.js +1 -0
- package/Favicon/package.json +6 -0
- package/Forms/index.d.ts +2 -2
- package/Forms/index.js +2 -0
- package/Forms/package.json +6 -0
- package/Forms/useForm.d.ts +32 -32
- package/Forms/useForm.js +37 -0
- package/Forms/useSubmit.d.ts +24 -24
- package/Forms/useSubmit.js +23 -0
- package/Head/Head.d.ts +1 -1
- package/Head/Head.js +1 -0
- package/Head/index.d.ts +1 -1
- package/Head/index.js +1 -0
- package/Head/package.json +6 -0
- package/I18n/I18n.d.ts +44 -48
- package/I18n/I18n.js +74 -0
- package/I18n/index.d.ts +1 -1
- package/I18n/index.js +1 -0
- package/I18n/package.json +6 -0
- package/Img/Img.d.ts +21 -21
- package/Img/Img.js +28 -0
- package/Img/index.d.ts +1 -1
- package/Img/index.js +1 -0
- package/Img/package.json +6 -0
- package/Link/Link.d.ts +9 -8
- package/Link/Link.js +9 -0
- package/Link/index.d.ts +1 -1
- package/Link/index.js +1 -0
- package/Link/package.json +6 -0
- package/NextProgress/NextProgress.d.ts +24 -14
- package/NextProgress/NextProgress.js +37 -0
- package/NextProgress/index.d.ts +2 -1
- package/NextProgress/index.js +1 -0
- package/NextProgress/package.json +6 -0
- package/README.md +0 -0
- package/Seo/Seo.d.ts +3 -3
- package/Seo/Seo.js +8 -0
- package/Seo/SeoDefaults.d.ts +3 -3
- package/Seo/SeoDefaults.js +12 -0
- package/Seo/helpers.d.ts +48 -48
- package/Seo/helpers.js +111 -0
- package/Seo/index.d.ts +12 -12
- package/Seo/index.js +12 -0
- package/Seo/package.json +6 -0
- package/Theme/Theme.d.ts +46 -46
- package/Theme/Theme.js +235 -0
- package/Theme/index.d.ts +1 -1
- package/Theme/index.js +1 -0
- package/Theme/package.json +6 -0
- package/app/AppHead.d.ts +2 -3
- package/app/AppHead.js +5 -0
- package/app/AppMain.d.ts +35 -34
- package/app/AppMain.js +1 -0
- package/app/css/AppMain.d.ts +8 -0
- package/app/css/AppMain.js +11 -0
- package/app/css/AppTheme.d.ts +10 -0
- package/app/css/AppTheme.js +12 -0
- 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} +15 -15
- package/app/em/AppTheme.js +17 -0
- 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 +2 -11
- package/app/index.js +2 -0
- 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 +71 -58
- package/config/index.js +174 -0
- package/config/package.json +6 -0
- package/document/Document.d.ts +15 -10
- package/document/Document.js +19 -0
- 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/em/index.js +68 -0
- package/document/em/package.json +6 -0
- package/document/index.d.ts +2 -4
- package/document/index.js +2 -0
- package/document/package.json +6 -0
- package/document/{Document--sc.d.ts → sc/index.d.ts} +20 -11
- package/document/sc/index.js +44 -0
- package/document/sc/package.json +6 -0
- package/index.d.ts +12 -12
- package/index.js +12 -743
- 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 +3 -30
- package/{types.d.ts → typings.d.ts} +10 -7
- package/utils/api.d.ts +55 -55
- package/utils/api.js +35 -0
- package/{document/emotion.d.ts → utils/emotion-cache.d.ts} +5 -5
- package/utils/emotion-cache.js +8 -0
- package/utils/index.d.ts +19 -19
- package/utils/index.js +26 -0
- package/utils/package.json +6 -0
- package/Theme.js +0 -1905
- package/_tslib.js +0 -41
- package/app/App--emotion.d.ts +0 -10
- package/app/App--sc.d.ts +0 -10
- package/app/App--vanilla.d.ts +0 -10
- package/app/AppAuth--emotion.d.ts +0 -10
- package/app/AppAuth--sc.d.ts +0 -10
- package/app/AppMain--vanilla.d.ts +0 -27
- package/app/AppTheme--sc.d.ts +0 -13
- package/app/AppTheme--vanilla.d.ts +0 -10
- package/app/motion-features.d.ts +0 -2
- package/app.js +0 -250
- package/config.js +0 -183
- package/document/Document--emotion.d.ts +0 -5
- package/document/Document--vanilla.d.ts +0 -11
- package/document.js +0 -207
- package/emotion.js +0 -1329
- package/es.object.assign.js +0 -1074
- package/es.string.replace.js +0 -785
- package/es.string.split.js +0 -201
- package/index.esm.js +0 -4600
- package/index.umd.js +0 -4638
- package/motion-features.js +0 -10
package/config/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise pathname
|
|
3
|
+
*
|
|
4
|
+
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
5
|
+
*
|
|
6
|
+
* - Removes subsequent slashes
|
|
7
|
+
* - Removing initial and ending slashes
|
|
8
|
+
*/
|
|
9
|
+
export function normaliseUrlPathname(pathname) {
|
|
10
|
+
return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Clean a pathname and encode each part
|
|
14
|
+
*
|
|
15
|
+
* @see {@link normaliseUrlPathname}
|
|
16
|
+
*/
|
|
17
|
+
export function encodePathname(pathname) {
|
|
18
|
+
const parts = normaliseUrlPathname(pathname).split("/");
|
|
19
|
+
return parts
|
|
20
|
+
.filter((part) => !!part)
|
|
21
|
+
.map((part) => encodeURIComponent(part))
|
|
22
|
+
.join("/");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
*/
|
|
26
|
+
export function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
|
|
27
|
+
const suffix = dynamic ? `/:slug*` : "";
|
|
28
|
+
return {
|
|
29
|
+
source: `/${locale}/${encodePathname(localisedPathname)}${suffix}`,
|
|
30
|
+
destination: `/${encodePathname(templateName)}${suffix}`,
|
|
31
|
+
permanent: Boolean(permanent),
|
|
32
|
+
locale: false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
*/
|
|
37
|
+
export function getPathRewrite(source, destination, dynamic) {
|
|
38
|
+
const suffix = dynamic ? `/:path*` : "";
|
|
39
|
+
return {
|
|
40
|
+
source: `/${encodePathname(source)}${suffix}`,
|
|
41
|
+
destination: `/${encodePathname(destination)}${suffix}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
*/
|
|
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));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// console.log("redirects", redirects);
|
|
60
|
+
return redirects;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
*/
|
|
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));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
// console.log("rewrites", rewrites);
|
|
78
|
+
return rewrites;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
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`.
|
|
90
|
+
*/
|
|
91
|
+
export function withKoine({ nx = true, svg = true, sc = true, page, ...nextConfig } = {}) {
|
|
92
|
+
nextConfig = {
|
|
93
|
+
// @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
|
|
94
|
+
pageExtensions: page ? ["page.tsx", "page.ts"] : undefined,
|
|
95
|
+
eslint: {
|
|
96
|
+
ignoreDuringBuilds: true, // we have this strict check on each commit
|
|
97
|
+
},
|
|
98
|
+
typescript: {
|
|
99
|
+
ignoreBuildErrors: true, // we have this strict check on each commit
|
|
100
|
+
},
|
|
101
|
+
poweredByHeader: false,
|
|
102
|
+
swcMinify: true,
|
|
103
|
+
experimental: {
|
|
104
|
+
// @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
|
|
105
|
+
// @see critters error https://github.com/vercel/next.js/issues/20742
|
|
106
|
+
// optimizeCss: true,
|
|
107
|
+
// @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
|
|
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
|
+
};
|
|
132
|
+
if (svg) {
|
|
133
|
+
if (nx) {
|
|
134
|
+
// @see https://github.com/gregberge/svgr
|
|
135
|
+
nextConfig["nx"] = {
|
|
136
|
+
svgr: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
nextConfig.webpack = (_config, options) => {
|
|
141
|
+
const webpackConfig = typeof nextConfig.webpack === "function"
|
|
142
|
+
? nextConfig.webpack(_config, options)
|
|
143
|
+
: _config;
|
|
144
|
+
// @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
|
|
145
|
+
webpackConfig.module.rules.push({
|
|
146
|
+
test: /\.svg$/,
|
|
147
|
+
use: [
|
|
148
|
+
{
|
|
149
|
+
loader: "@svgr/webpack",
|
|
150
|
+
options: {
|
|
151
|
+
svgoConfig: {
|
|
152
|
+
plugins: [
|
|
153
|
+
{
|
|
154
|
+
name: "removeViewBox",
|
|
155
|
+
active: false,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
});
|
|
163
|
+
return webpackConfig;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (sc) {
|
|
168
|
+
nextConfig.compiler = {
|
|
169
|
+
styledComponents: true,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return nextConfig;
|
|
173
|
+
}
|
|
174
|
+
export default withKoine;
|
package/document/Document.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import NextDocument from "next/document";
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument from "next/document";
|
|
3
|
+
/**
|
|
4
|
+
* Next Document wrapper for bare projects
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* in your `myapp/pages/_document.tsx`:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* export { Document as default } from "@koine/next/document";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class Document extends NextDocument {
|
|
14
|
+
render(): JSX.Element;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Next Document wrapper for bare projects
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* in your `myapp/pages/_document.tsx`:
|
|
10
|
+
* ```tsx
|
|
11
|
+
* export { Document as default } from "@koine/next/document";
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export class Document extends NextDocument {
|
|
15
|
+
render() {
|
|
16
|
+
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
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, {})] })] }));
|
|
18
|
+
}
|
|
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;
|
|
@@ -0,0 +1,68 @@
|
|
|
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 createEmotionServer from "@emotion/server/create-instance";
|
|
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 {
|
|
17
|
+
render() {
|
|
18
|
+
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
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, {})] })] }));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// `getInitialProps` belongs to `_document` (instead of `_app`),
|
|
23
|
+
// it's compatible with static-site generation (SSG).
|
|
24
|
+
Document.getInitialProps = async (ctx) => {
|
|
25
|
+
// Resolution order
|
|
26
|
+
//
|
|
27
|
+
// On the server:
|
|
28
|
+
// 1. app.getInitialProps
|
|
29
|
+
// 2. page.getInitialProps
|
|
30
|
+
// 3. document.getInitialProps
|
|
31
|
+
// 4. app.render
|
|
32
|
+
// 5. page.render
|
|
33
|
+
// 6. document.render
|
|
34
|
+
//
|
|
35
|
+
// On the server with error:
|
|
36
|
+
// 1. document.getInitialProps
|
|
37
|
+
// 2. app.render
|
|
38
|
+
// 3. page.render
|
|
39
|
+
// 4. document.render
|
|
40
|
+
//
|
|
41
|
+
// On the client
|
|
42
|
+
// 1. app.getInitialProps
|
|
43
|
+
// 2. page.getInitialProps
|
|
44
|
+
// 3. app.render
|
|
45
|
+
// 4. page.render
|
|
46
|
+
const originalRenderPage = ctx.renderPage;
|
|
47
|
+
// You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
|
|
48
|
+
// However, be aware that it can have global side effects.
|
|
49
|
+
const cache = createEmotionCache();
|
|
50
|
+
const { extractCriticalToChunks } = createEmotionServer(cache);
|
|
51
|
+
ctx.renderPage = () => originalRenderPage({
|
|
52
|
+
enhanceApp: (App) => function EnhanceApp(props) {
|
|
53
|
+
return _jsx(App, { emotionCache: cache, ...props });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const initialProps = await Document.getInitialProps(ctx);
|
|
57
|
+
// This is important. It prevents emotion to render invalid HTML.
|
|
58
|
+
// See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
|
|
59
|
+
const emotionStyles = extractCriticalToChunks(initialProps.html);
|
|
60
|
+
const emotionStyleTags = emotionStyles.styles.map((style) => (_jsx("style", { "data-emotion": `${style.key} ${style.ids.join(" ")}`,
|
|
61
|
+
// eslint-disable-next-line react/no-danger
|
|
62
|
+
dangerouslySetInnerHTML: { __html: style.css } }, style.key)));
|
|
63
|
+
return {
|
|
64
|
+
...initialProps,
|
|
65
|
+
emotionStyleTags,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export default Document;
|
package/document/index.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
|
|
3
|
+
/**
|
|
4
|
+
* Next Document wrapper for `styled-components` based projects
|
|
5
|
+
*
|
|
6
|
+
* For typescript safety of this component
|
|
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
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class Document extends NextDocument {
|
|
17
|
+
static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps>;
|
|
18
|
+
render(): JSX.Element;
|
|
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
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from "./Analytics";
|
|
2
|
-
export * from "./Auth";
|
|
3
|
-
export * from "./Favicon";
|
|
4
|
-
export * from "./Forms";
|
|
5
|
-
export * from "./Head";
|
|
6
|
-
export * from "./I18n";
|
|
7
|
-
export * from "./Img";
|
|
8
|
-
export * from "./Link";
|
|
9
|
-
export * from "./NextProgress";
|
|
10
|
-
export * from "./Seo";
|
|
11
|
-
export * from "./Theme";
|
|
12
|
-
export * from "./utils";
|
|
1
|
+
export * from "./Analytics";
|
|
2
|
+
export * from "./Auth";
|
|
3
|
+
export * from "./Favicon";
|
|
4
|
+
export * from "./Forms";
|
|
5
|
+
export * from "./Head";
|
|
6
|
+
export * from "./I18n";
|
|
7
|
+
export * from "./Img";
|
|
8
|
+
export * from "./Link";
|
|
9
|
+
export * from "./NextProgress";
|
|
10
|
+
export * from "./Seo";
|
|
11
|
+
export * from "./Theme";
|
|
12
|
+
export * from "./utils";
|