@koine/next 1.0.13 → 1.0.16
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/Forms/index.d.ts +0 -1
- package/Forms/index.js +0 -1
- package/node/Analytics/AnalyticsGoogle.js +37 -0
- package/node/Analytics/index.js +4 -0
- package/node/Auth/helpers.js +27 -0
- package/node/Auth/index.js +7 -0
- package/node/Auth/useLogin.js +53 -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 +4 -0
- package/node/Forms/useForm.js +39 -0
- package/node/Head/Head.js +5 -0
- package/node/Head/index.js +4 -0
- package/node/I18n/I18n.js +102 -0
- package/node/I18n/index.js +4 -0
- package/node/Img/Img.js +35 -0
- package/node/Img/index.js +4 -0
- package/node/Link/Link.js +14 -0
- package/node/Link/index.js +4 -0
- package/node/NextProgress/NextProgress.js +44 -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 +119 -0
- package/node/Seo/index.js +15 -0
- package/node/Theme/Theme.js +250 -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 +17 -0
- package/node/app/css/AppTheme.js +18 -0
- package/node/app/css/auth/index.js +18 -0
- package/node/app/css/index.js +62 -0
- package/node/app/em/AppMain.js +28 -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 +28 -0
- package/node/app/sc/AppTheme.js +15 -0
- package/node/app/sc/auth/index.js +18 -0
- package/node/app/sc/index.js +64 -0
- package/node/config/index.js +201 -0
- package/node/document/Document.js +29 -0
- package/node/document/css/index.js +47 -0
- package/node/document/em/index.js +62 -0
- package/node/document/index.js +7 -0
- package/node/document/sc/index.js +68 -0
- package/node/index.js +15 -0
- package/node/utils/emotion-cache.js +13 -0
- package/node/utils/index.js +31 -0
- package/package.json +3 -2
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppTheme = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var styled_components_1 = require("styled-components");
|
|
7
|
+
var sc_1 = require("@koine/react/sc");
|
|
8
|
+
/**
|
|
9
|
+
* App theme with `styled-components`
|
|
10
|
+
*/
|
|
11
|
+
var AppTheme = function (_a) {
|
|
12
|
+
var theme = _a.theme, children = _a.children;
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)(styled_components_1.ThemeProvider, tslib_1.__assign({ theme: theme }, { children: [(0, jsx_runtime_1.jsx)(sc_1.StylesGlobal, {}), children] })));
|
|
14
|
+
};
|
|
15
|
+
exports.AppTheme = AppTheme;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextApp = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
var react_2 = require("next-auth/react");
|
|
8
|
+
var AppHead_1 = require("../../AppHead");
|
|
9
|
+
var AppTheme_1 = require("../AppTheme");
|
|
10
|
+
var AppMain_1 = require("../AppMain");
|
|
11
|
+
/**
|
|
12
|
+
* App with authentication provided by `next-auth`
|
|
13
|
+
*/
|
|
14
|
+
var NextApp = function (props) {
|
|
15
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.default.StrictMode, { children: [(0, jsx_runtime_1.jsx)(AppHead_1.AppHead, {}), (0, jsx_runtime_1.jsx)(react_2.SessionProvider, tslib_1.__assign({ session: props.pageProps.session }, { children: (0, jsx_runtime_1.jsx)(AppTheme_1.AppTheme, tslib_1.__assign({}, props, { children: (0, jsx_runtime_1.jsx)(AppMain_1.AppMain, tslib_1.__assign({}, props)) })) }))] }));
|
|
16
|
+
};
|
|
17
|
+
exports.NextApp = NextApp;
|
|
18
|
+
exports.default = exports.NextApp;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextApp = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
var AppHead_1 = require("../AppHead");
|
|
8
|
+
var AppTheme_1 = require("./AppTheme");
|
|
9
|
+
var AppMain_1 = require("./AppMain");
|
|
10
|
+
/**
|
|
11
|
+
* App
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { NextApp, NextAppProps } from "@koine/next/app/sc/auth";
|
|
17
|
+
* import { Favicon, AnalyticsGoogle } from "@koine/next";
|
|
18
|
+
* import { theme } from "src/helpers/theme";
|
|
19
|
+
* import { Layout, ProgressOverlay } from "src/components/Layout";
|
|
20
|
+
* // import "@fontsource/myfont/800.css";
|
|
21
|
+
* // import "src/helpers/theme.css";
|
|
22
|
+
*
|
|
23
|
+
* const motion = () => import("@koine/react/m/max").then((m) => m.default);
|
|
24
|
+
*
|
|
25
|
+
* export default function App(props: NextAppProps) {
|
|
26
|
+
* return (
|
|
27
|
+
* <NextApp
|
|
28
|
+
* {...props}
|
|
29
|
+
* Layout={Layout}
|
|
30
|
+
* ProgressOverlay={ProgressOverlay}
|
|
31
|
+
* theme={theme}
|
|
32
|
+
* motion={motion}
|
|
33
|
+
* seo={{
|
|
34
|
+
* titleTemplate: "%s | MyApp",
|
|
35
|
+
* defaultTitle: "MyApp",
|
|
36
|
+
* openGraph: {
|
|
37
|
+
* type: "website",
|
|
38
|
+
* locale: "en_US",
|
|
39
|
+
* url: "https://myapp.com/",
|
|
40
|
+
* site_name: "MyApp",
|
|
41
|
+
* },
|
|
42
|
+
* twitter: {
|
|
43
|
+
* handle: "@MklrNl",
|
|
44
|
+
* site: "@MyApp",
|
|
45
|
+
* cardType: "summary_large_image",
|
|
46
|
+
* },
|
|
47
|
+
* }}
|
|
48
|
+
* pre={
|
|
49
|
+
* <>
|
|
50
|
+
* <AnalyticsGoogle id="UA-xxxxxxxx-x" />
|
|
51
|
+
* <Favicon name="MyApp" color="#000000" />
|
|
52
|
+
* </>
|
|
53
|
+
* }
|
|
54
|
+
* />
|
|
55
|
+
* );
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
var NextApp = function (props) {
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.default.StrictMode, { children: [(0, jsx_runtime_1.jsx)(AppHead_1.AppHead, {}), (0, jsx_runtime_1.jsx)(AppTheme_1.AppTheme, tslib_1.__assign({}, props, { children: (0, jsx_runtime_1.jsx)(AppMain_1.AppMain, tslib_1.__assign({}, props)) }))] }));
|
|
62
|
+
};
|
|
63
|
+
exports.NextApp = NextApp;
|
|
64
|
+
exports.default = exports.NextApp;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withKoine = exports.getRewrites = exports.getRedirects = exports.getPathRewrite = exports.getPathRedirect = exports.encodePathname = exports.normaliseUrlPathname = exports.toPath = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Transform to path any absolute or relative URL
|
|
7
|
+
*
|
|
8
|
+
* Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
|
|
9
|
+
* setup](https://nextjs.org/docs/advanced-features/multi-zones).
|
|
10
|
+
*
|
|
11
|
+
* From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
|
|
12
|
+
*
|
|
13
|
+
* - just get the pathname form an absolute URL (if that is given)
|
|
14
|
+
* - Removes subsequent slashes
|
|
15
|
+
* - Removing initial and ending slashes
|
|
16
|
+
*/
|
|
17
|
+
function toPath(urlOrPathname) {
|
|
18
|
+
if (urlOrPathname === void 0) { urlOrPathname = ""; }
|
|
19
|
+
var pathname = "";
|
|
20
|
+
try {
|
|
21
|
+
var parsed = new URL(urlOrPathname);
|
|
22
|
+
pathname = parsed.pathname;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
pathname = urlOrPathname;
|
|
26
|
+
}
|
|
27
|
+
return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
28
|
+
}
|
|
29
|
+
exports.toPath = toPath;
|
|
30
|
+
/**
|
|
31
|
+
* Normalise pathname
|
|
32
|
+
*
|
|
33
|
+
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
34
|
+
*
|
|
35
|
+
* - Removes subsequent slashes
|
|
36
|
+
* - Removing initial and ending slashes
|
|
37
|
+
*/
|
|
38
|
+
function normaliseUrlPathname(pathname) {
|
|
39
|
+
return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
40
|
+
}
|
|
41
|
+
exports.normaliseUrlPathname = normaliseUrlPathname;
|
|
42
|
+
/**
|
|
43
|
+
* Clean a pathname and encode each part
|
|
44
|
+
*
|
|
45
|
+
* @see {@link normaliseUrlPathname}
|
|
46
|
+
*/
|
|
47
|
+
function encodePathname(pathname) {
|
|
48
|
+
var parts = normaliseUrlPathname(pathname).split("/");
|
|
49
|
+
return parts
|
|
50
|
+
.filter(function (part) { return !!part; })
|
|
51
|
+
.map(function (part) { return encodeURIComponent(part); })
|
|
52
|
+
.join("/");
|
|
53
|
+
}
|
|
54
|
+
exports.encodePathname = encodePathname;
|
|
55
|
+
/**
|
|
56
|
+
*/
|
|
57
|
+
function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
|
|
58
|
+
var suffix = dynamic ? "/:slug*" : "";
|
|
59
|
+
return {
|
|
60
|
+
source: "/".concat(locale, "/").concat(encodePathname(localisedPathname)).concat(suffix),
|
|
61
|
+
destination: "/".concat(encodePathname(templateName)).concat(suffix),
|
|
62
|
+
permanent: Boolean(permanent),
|
|
63
|
+
locale: false,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.getPathRedirect = getPathRedirect;
|
|
67
|
+
/**
|
|
68
|
+
*/
|
|
69
|
+
function getPathRewrite(source, destination, dynamic) {
|
|
70
|
+
var suffix = dynamic ? "/:path*" : "";
|
|
71
|
+
return {
|
|
72
|
+
source: "/".concat(encodePathname(source)).concat(suffix),
|
|
73
|
+
destination: "/".concat(encodePathname(destination)).concat(suffix),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.getPathRewrite = getPathRewrite;
|
|
77
|
+
/**
|
|
78
|
+
*/
|
|
79
|
+
function getRedirects(_a) {
|
|
80
|
+
var defaultLocale = _a.defaultLocale, routes = _a.routes, dynamicRoutes = _a.dynamicRoutes, permanent = _a.permanent;
|
|
81
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
82
|
+
var redirects;
|
|
83
|
+
return tslib_1.__generator(this, function (_b) {
|
|
84
|
+
redirects = [];
|
|
85
|
+
Object.keys(routes).forEach(function (page) {
|
|
86
|
+
var dynamic = dynamicRoutes[page];
|
|
87
|
+
if (routes[page] !== page) {
|
|
88
|
+
if (dynamic) {
|
|
89
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
// console.log("redirects", redirects);
|
|
97
|
+
return [2 /*return*/, redirects];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.getRedirects = getRedirects;
|
|
102
|
+
/**
|
|
103
|
+
*/
|
|
104
|
+
function getRewrites(_a) {
|
|
105
|
+
var routes = _a.routes, dynamicRoutes = _a.dynamicRoutes;
|
|
106
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var rewrites;
|
|
108
|
+
return tslib_1.__generator(this, function (_b) {
|
|
109
|
+
rewrites = [];
|
|
110
|
+
Object.keys(routes).forEach(function (page) {
|
|
111
|
+
var dynamic = dynamicRoutes[page];
|
|
112
|
+
if (routes[page] !== page) {
|
|
113
|
+
if (dynamic) {
|
|
114
|
+
rewrites.push(getPathRewrite(routes[page], page, true));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
rewrites.push(getPathRewrite(routes[page], page));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
// console.log("rewrites", rewrites);
|
|
122
|
+
return [2 /*return*/, rewrites];
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.getRewrites = getRewrites;
|
|
127
|
+
/**
|
|
128
|
+
* Get Next.js config with some basic opinionated defaults
|
|
129
|
+
*
|
|
130
|
+
* @param {object} options
|
|
131
|
+
* @property {boolean} [options.nx=false] Nx monorepo setup
|
|
132
|
+
* @property {boolean} [options.svg=false] Svg to react components
|
|
133
|
+
* @property {boolean} [options.sc=false] Styled components enabled
|
|
134
|
+
* @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
|
|
135
|
+
* 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)
|
|
136
|
+
* and it enables the same for `next-translate`.
|
|
137
|
+
*/
|
|
138
|
+
function withKoine(_a) {
|
|
139
|
+
var _b;
|
|
140
|
+
if (_a === void 0) { _a = {}; }
|
|
141
|
+
var _c = _a.nx, nx = _c === void 0 ? true : _c, _d = _a.svg, svg = _d === void 0 ? true : _d, _e = _a.sc, sc = _e === void 0 ? true : _e, page = _a.page, nextConfig = tslib_1.__rest(_a, ["nx", "svg", "sc", "page"]);
|
|
142
|
+
nextConfig = tslib_1.__assign({
|
|
143
|
+
// @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
|
|
144
|
+
pageExtensions: page ? ["page.tsx", "page.ts"] : undefined, eslint: {
|
|
145
|
+
ignoreDuringBuilds: true, // we have this strict check on each commit
|
|
146
|
+
}, typescript: {
|
|
147
|
+
ignoreBuildErrors: true, // we have this strict check on each commit
|
|
148
|
+
}, poweredByHeader: false, swcMinify: true, experimental: tslib_1.__assign(tslib_1.__assign({
|
|
149
|
+
// @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
|
|
150
|
+
// @see critters error https://github.com/vercel/next.js/issues/20742
|
|
151
|
+
// optimizeCss: true,
|
|
152
|
+
// @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
|
|
153
|
+
scrollRestoration: true }, (nextConfig.experimental || {})), {
|
|
154
|
+
// @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
|
|
155
|
+
modularizeImports: tslib_1.__assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }),
|
|
156
|
+
// @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
|
|
157
|
+
reactStrictMode: true }, nextConfig);
|
|
158
|
+
if (svg) {
|
|
159
|
+
if (nx) {
|
|
160
|
+
// @see https://github.com/gregberge/svgr
|
|
161
|
+
nextConfig["nx"] = {
|
|
162
|
+
svgr: true,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
nextConfig.webpack = function (_config, options) {
|
|
167
|
+
var webpackConfig = typeof nextConfig.webpack === "function"
|
|
168
|
+
? nextConfig.webpack(_config, options)
|
|
169
|
+
: _config;
|
|
170
|
+
// @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
|
|
171
|
+
webpackConfig.module.rules.push({
|
|
172
|
+
test: /\.svg$/,
|
|
173
|
+
use: [
|
|
174
|
+
{
|
|
175
|
+
loader: "@svgr/webpack",
|
|
176
|
+
options: {
|
|
177
|
+
svgoConfig: {
|
|
178
|
+
plugins: [
|
|
179
|
+
{
|
|
180
|
+
name: "removeViewBox",
|
|
181
|
+
active: false,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
return webpackConfig;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (sc) {
|
|
194
|
+
nextConfig.compiler = {
|
|
195
|
+
styledComponents: true,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return nextConfig;
|
|
199
|
+
}
|
|
200
|
+
exports.withKoine = withKoine;
|
|
201
|
+
exports.default = withKoine;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var document_1 = tslib_1.__importStar(require("next/document"));
|
|
7
|
+
var react_1 = require("@koine/react");
|
|
8
|
+
/**
|
|
9
|
+
* Next Document wrapper for bare projects
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* in your `myapp/pages/_document.tsx`:
|
|
14
|
+
* ```tsx
|
|
15
|
+
* export { Document as default } from "@koine/next/document";
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var Document = /** @class */ (function (_super) {
|
|
19
|
+
tslib_1.__extends(Document, _super);
|
|
20
|
+
function Document() {
|
|
21
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
22
|
+
}
|
|
23
|
+
Document.prototype.render = function () {
|
|
24
|
+
var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_1.Meta, {}), (0, jsx_runtime_1.jsx)(react_1.NoJs, {})] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
|
|
26
|
+
};
|
|
27
|
+
return Document;
|
|
28
|
+
}(document_1.default));
|
|
29
|
+
exports.Document = Document;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var document_1 = tslib_1.__importStar(require("next/document"));
|
|
7
|
+
var react_1 = require("@koine/react");
|
|
8
|
+
var sc_1 = require("@koine/react/sc"); // FIXME: this should be imported from another entrypoint
|
|
9
|
+
/**
|
|
10
|
+
* Next Document wrapper for `css/tailwind` based projects
|
|
11
|
+
*
|
|
12
|
+
* Uses cookie to manage the current theme
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* in your `myapp/pages/_document.tsx`:
|
|
17
|
+
* ```tsx
|
|
18
|
+
* export { Document as default } from "@koine/next/document/css";
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
var Document = /** @class */ (function (_super) {
|
|
22
|
+
tslib_1.__extends(Document, _super);
|
|
23
|
+
function Document() {
|
|
24
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
25
|
+
}
|
|
26
|
+
Document.getInitialProps = function (ctx) {
|
|
27
|
+
var _a;
|
|
28
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
29
|
+
var initialProps;
|
|
30
|
+
return tslib_1.__generator(this, function (_b) {
|
|
31
|
+
switch (_b.label) {
|
|
32
|
+
case 0: return [4 /*yield*/, document_1.default.getInitialProps(ctx)];
|
|
33
|
+
case 1:
|
|
34
|
+
initialProps = _b.sent();
|
|
35
|
+
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), { theme: (0, sc_1.getInitialThemeFromRequest)(((_a = ctx.req) === null || _a === void 0 ? void 0 : _a.headers.cookie /* || document?.cookie */) || "") })];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
Document.prototype.render = function () {
|
|
41
|
+
var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
42
|
+
return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_1.Meta, {}), (0, jsx_runtime_1.jsx)(react_1.NoJs, {})] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
|
|
43
|
+
};
|
|
44
|
+
return Document;
|
|
45
|
+
}(document_1.default));
|
|
46
|
+
exports.Document = Document;
|
|
47
|
+
exports.default = Document;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var document_1 = tslib_1.__importStar(require("next/document"));
|
|
7
|
+
var react_1 = require("@koine/react");
|
|
8
|
+
var create_instance_1 = tslib_1.__importDefault(require("@emotion/server/create-instance"));
|
|
9
|
+
var emotion_cache_1 = require("../../utils/emotion-cache");
|
|
10
|
+
/**
|
|
11
|
+
* Next Document wrapper for `emotion` based projects
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* in your `myapp/pages/_document.tsx`:
|
|
16
|
+
* ```tsx
|
|
17
|
+
* export { Document as default } from "@koine/next/document/em";
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
var Document = /** @class */ (function (_super) {
|
|
21
|
+
tslib_1.__extends(Document, _super);
|
|
22
|
+
function Document() {
|
|
23
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
}
|
|
25
|
+
Document.prototype.render = function () {
|
|
26
|
+
var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
27
|
+
return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_1.Meta, {}), (0, jsx_runtime_1.jsx)(react_1.NoJs, {}), this.props.emotionStyleTags] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
|
|
28
|
+
};
|
|
29
|
+
return Document;
|
|
30
|
+
}(document_1.default));
|
|
31
|
+
exports.Document = Document;
|
|
32
|
+
// `getInitialProps` belongs to `_document` (instead of `_app`),
|
|
33
|
+
// it's compatible with static-site generation (SSG).
|
|
34
|
+
Document.getInitialProps = function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
35
|
+
var originalRenderPage, cache, extractCriticalToChunks, initialProps, emotionStyles, emotionStyleTags;
|
|
36
|
+
return tslib_1.__generator(this, function (_a) {
|
|
37
|
+
switch (_a.label) {
|
|
38
|
+
case 0:
|
|
39
|
+
originalRenderPage = ctx.renderPage;
|
|
40
|
+
cache = (0, emotion_cache_1.createEmotionCache)();
|
|
41
|
+
extractCriticalToChunks = (0, create_instance_1.default)(cache).extractCriticalToChunks;
|
|
42
|
+
ctx.renderPage = function () {
|
|
43
|
+
return originalRenderPage({
|
|
44
|
+
enhanceApp: function (App) {
|
|
45
|
+
return function EnhanceApp(props) {
|
|
46
|
+
return (0, jsx_runtime_1.jsx)(App, tslib_1.__assign({ emotionCache: cache }, props));
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return [4 /*yield*/, Document.getInitialProps(ctx)];
|
|
52
|
+
case 1:
|
|
53
|
+
initialProps = _a.sent();
|
|
54
|
+
emotionStyles = extractCriticalToChunks(initialProps.html);
|
|
55
|
+
emotionStyleTags = emotionStyles.styles.map(function (style) { return ((0, jsx_runtime_1.jsx)("style", { "data-emotion": "".concat(style.key, " ").concat(style.ids.join(" ")),
|
|
56
|
+
// eslint-disable-next-line react/no-danger
|
|
57
|
+
dangerouslySetInnerHTML: { __html: style.css } }, style.key)); });
|
|
58
|
+
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), { emotionStyleTags: emotionStyleTags })];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}); };
|
|
62
|
+
exports.default = Document;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.Document = void 0;
|
|
4
|
+
var Document_1 = require("./Document");
|
|
5
|
+
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return Document_1.Document; } });
|
|
6
|
+
var Document_2 = require("./Document");
|
|
7
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return Document_2.Document; } });
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
/* ? eslint-disable @next/next/no-document-import-in-page */
|
|
8
|
+
var document_1 = tslib_1.__importStar(require("next/document"));
|
|
9
|
+
var react_2 = require("@koine/react");
|
|
10
|
+
var styled_components_1 = require("styled-components");
|
|
11
|
+
/**
|
|
12
|
+
* Next Document wrapper for `styled-components` based projects
|
|
13
|
+
*
|
|
14
|
+
* For typescript safety of this component
|
|
15
|
+
* @see https://bit.ly/3ceuF8m
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* in your `myapp/pages/_document.tsx`:
|
|
20
|
+
* ```tsx
|
|
21
|
+
* export { Document as default } from "@koine/next/document/sc";
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var Document = /** @class */ (function (_super) {
|
|
25
|
+
tslib_1.__extends(Document, _super);
|
|
26
|
+
function Document() {
|
|
27
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
28
|
+
}
|
|
29
|
+
Document.getInitialProps = function (ctx) {
|
|
30
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
31
|
+
var sheet, originalRenderPage, initialProps;
|
|
32
|
+
return tslib_1.__generator(this, function (_a) {
|
|
33
|
+
switch (_a.label) {
|
|
34
|
+
case 0:
|
|
35
|
+
sheet = new styled_components_1.ServerStyleSheet();
|
|
36
|
+
originalRenderPage = ctx.renderPage;
|
|
37
|
+
_a.label = 1;
|
|
38
|
+
case 1:
|
|
39
|
+
_a.trys.push([1, , 3, 4]);
|
|
40
|
+
ctx.renderPage = function () {
|
|
41
|
+
return originalRenderPage({
|
|
42
|
+
enhanceApp: function (App) { return function (props) {
|
|
43
|
+
return sheet.collectStyles((0, jsx_runtime_1.jsx)(App, tslib_1.__assign({}, props)));
|
|
44
|
+
}; },
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return [4 /*yield*/, document_1.default.getInitialProps(ctx)];
|
|
48
|
+
case 2:
|
|
49
|
+
initialProps = _a.sent();
|
|
50
|
+
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), {
|
|
51
|
+
// @ts-expect-error FIXME: have they changed type?
|
|
52
|
+
styles: ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })) })];
|
|
53
|
+
case 3:
|
|
54
|
+
sheet.seal();
|
|
55
|
+
return [7 /*endfinally*/];
|
|
56
|
+
case 4: return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
Document.prototype.render = function () {
|
|
62
|
+
var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
63
|
+
return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_2.Meta, {}), (0, jsx_runtime_1.jsx)(react_2.NoJs, {})] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
|
|
64
|
+
};
|
|
65
|
+
return Document;
|
|
66
|
+
}(document_1.default));
|
|
67
|
+
exports.Document = Document;
|
|
68
|
+
exports.default = Document;
|
package/node/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./Analytics"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./Auth"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./Favicon"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./Forms"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./Head"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./I18n"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./Img"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./Link"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./NextProgress"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./Seo"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./Theme"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmotionCache = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var cache_1 = tslib_1.__importDefault(require("@emotion/cache"));
|
|
6
|
+
/**
|
|
7
|
+
* prepend: true moves MUI styles to the top of the <head> so they're loaded first.
|
|
8
|
+
* It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
|
|
9
|
+
*/
|
|
10
|
+
function createEmotionCache() {
|
|
11
|
+
return (0, cache_1.default)({ key: "css", prepend: true });
|
|
12
|
+
}
|
|
13
|
+
exports.createEmotionCache = createEmotionCache;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.load = exports.getSiteUrl = exports.ONE_DAY = exports.ONE_HOUR = void 0;
|
|
4
|
+
var utils_1 = require("@koine/utils");
|
|
5
|
+
exports.ONE_HOUR = 3600;
|
|
6
|
+
exports.ONE_DAY = 84000;
|
|
7
|
+
/**
|
|
8
|
+
* Get site absolute url with the given path
|
|
9
|
+
*
|
|
10
|
+
* - It uses the `NEXT_PUBLIC_APP_URL` env variable
|
|
11
|
+
* - It removes the trailing slashes
|
|
12
|
+
*/
|
|
13
|
+
function getSiteUrl(path) {
|
|
14
|
+
if (path === void 0) { path = ""; }
|
|
15
|
+
return (0, utils_1.normaliseUrl)("".concat(process.env["NEXT_PUBLIC_APP_URL"], "/").concat(path));
|
|
16
|
+
}
|
|
17
|
+
exports.getSiteUrl = getSiteUrl;
|
|
18
|
+
/**
|
|
19
|
+
* Utility to load a component with an optional pre-determined delay.
|
|
20
|
+
*
|
|
21
|
+
* This was designed to improve anti spam wit async form loading.
|
|
22
|
+
*
|
|
23
|
+
* @see https://github.com/vercel/next.js/blob/main/packages/next/next-server/lib/dynamic.tsx
|
|
24
|
+
* @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
|
|
25
|
+
*/
|
|
26
|
+
function load(component, milliseconds) {
|
|
27
|
+
return new Promise(function (resolve) {
|
|
28
|
+
setTimeout(function () { return resolve(component); }, milliseconds);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.load = load;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koine/next",
|
|
3
|
-
"version": "1.0.13",
|
|
4
3
|
"sideEffects": false,
|
|
5
4
|
"main": "./node/index.js",
|
|
6
5
|
"typings": "./index.d.ts",
|
|
7
6
|
"dependencies": {
|
|
8
7
|
"react": "^16.8 || ^17 || ^18",
|
|
9
8
|
"next": "^12.1.6",
|
|
10
|
-
"@koine/utils": "1.0.
|
|
9
|
+
"@koine/utils": "1.0.16",
|
|
11
10
|
"framer-motion": "^6.3.4",
|
|
11
|
+
"@koine/react": "1.0.16",
|
|
12
12
|
"styled-components": "^5.3.5",
|
|
13
13
|
"@mui/base": "^5.0.0-alpha.82",
|
|
14
14
|
"react-icons": "^4.3.1",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"next-seo": "^5.4.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {},
|
|
32
|
+
"version": "1.0.16",
|
|
32
33
|
"module": "./index.js",
|
|
33
34
|
"types": "./index.d.ts"
|
|
34
35
|
}
|
package/utils/index.d.ts
CHANGED