@koine/next 1.0.9 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/Analytics/AnalyticsGoogle.js +12 -16
  2. package/Auth/helpers.js +6 -5
  3. package/Auth/useLogin.js +17 -18
  4. package/Auth/useLoginUrl.js +5 -5
  5. package/Auth/useLogout.js +19 -19
  6. package/Favicon/Favicon.js +2 -1
  7. package/Forms/useForm.js +11 -13
  8. package/Forms/useSubmit.js +24 -19
  9. package/I18n/I18n.js +35 -14
  10. package/Img/Img.js +22 -20
  11. package/Link/Link.js +4 -2
  12. package/NextProgress/NextProgress.js +12 -9
  13. package/Seo/Seo.js +2 -2
  14. package/Seo/SeoDefaults.js +2 -2
  15. package/Seo/helpers.js +34 -30
  16. package/Theme/Theme.js +98 -88
  17. package/app/AppHead.js +1 -1
  18. package/app/css/AppMain.js +4 -2
  19. package/app/css/AppTheme.js +4 -2
  20. package/app/css/auth/index.js +3 -2
  21. package/app/css/index.js +3 -2
  22. package/app/em/AppMain.js +9 -7
  23. package/app/em/AppTheme.js +6 -5
  24. package/app/em/auth/index.js +3 -2
  25. package/app/em/index.js +3 -2
  26. package/app/sc/AppMain.js +9 -7
  27. package/app/sc/AppTheme.js +4 -2
  28. package/app/sc/auth/index.js +3 -2
  29. package/app/sc/index.js +3 -2
  30. package/config/index.js +62 -72
  31. package/document/Document.js +12 -5
  32. package/document/css/index.js +26 -12
  33. package/document/em/index.js +39 -48
  34. package/document/sc/index.js +44 -23
  35. package/node/Analytics/AnalyticsGoogle.js +17 -22
  36. package/node/Analytics/index.js +1 -1
  37. package/node/Auth/helpers.js +6 -5
  38. package/node/Auth/index.js +1 -1
  39. package/node/Auth/useLogin.js +23 -24
  40. package/node/Auth/useLoginUrl.js +8 -8
  41. package/node/Auth/useLogout.js +25 -25
  42. package/node/Favicon/Favicon.js +5 -5
  43. package/node/Favicon/index.js +1 -1
  44. package/node/Forms/index.js +1 -1
  45. package/node/Forms/useForm.js +15 -17
  46. package/node/Forms/useSubmit.js +25 -20
  47. package/node/Head/index.js +1 -1
  48. package/node/I18n/I18n.js +40 -20
  49. package/node/I18n/index.js +1 -1
  50. package/node/Img/Img.js +24 -23
  51. package/node/Img/index.js +1 -1
  52. package/node/Link/Link.js +7 -6
  53. package/node/Link/index.js +1 -1
  54. package/node/NextProgress/NextProgress.js +15 -12
  55. package/node/Seo/Seo.js +6 -6
  56. package/node/Seo/SeoDefaults.js +6 -6
  57. package/node/Seo/helpers.js +36 -32
  58. package/node/Seo/index.js +1 -1
  59. package/node/Theme/Theme.js +102 -93
  60. package/node/Theme/index.js +1 -1
  61. package/node/app/AppHead.js +4 -4
  62. package/node/app/css/AppMain.js +7 -6
  63. package/node/app/css/AppTheme.js +6 -4
  64. package/node/app/css/auth/index.js +9 -9
  65. package/node/app/css/index.js +8 -8
  66. package/node/app/em/AppMain.js +16 -14
  67. package/node/app/em/AppTheme.js +13 -13
  68. package/node/app/em/auth/index.js +9 -9
  69. package/node/app/em/index.js +8 -8
  70. package/node/app/index.js +1 -1
  71. package/node/app/sc/AppMain.js +16 -14
  72. package/node/app/sc/AppTheme.js +7 -5
  73. package/node/app/sc/auth/index.js +9 -9
  74. package/node/app/sc/index.js +8 -8
  75. package/node/config/index.js +62 -72
  76. package/node/document/Document.js +14 -9
  77. package/node/document/css/index.js +29 -17
  78. package/node/document/em/index.js +43 -54
  79. package/node/document/sc/index.js +48 -29
  80. package/node/index.js +1 -1
  81. package/node/utils/api.js +41 -32
  82. package/node/utils/emotion-cache.js +2 -2
  83. package/node/utils/index.js +7 -6
  84. package/package.json +28 -2
  85. package/utils/api.js +40 -31
  86. package/utils/index.js +7 -6
@@ -1,9 +1,11 @@
1
+ import { __assign } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { ThemeProvider } from "styled-components";
3
4
  import { StylesGlobal } from "@koine/react/sc";
4
5
  /**
5
6
  * App theme with `styled-components`
6
7
  */
7
- export const AppTheme = ({ theme, children }) => {
8
- return (_jsxs(ThemeProvider, { theme: theme, children: [_jsx(StylesGlobal, {}), children] }));
8
+ export var AppTheme = function (_a) {
9
+ var theme = _a.theme, children = _a.children;
10
+ return (_jsxs(ThemeProvider, __assign({ theme: theme }, { children: [_jsx(StylesGlobal, {}), children] })));
9
11
  };
@@ -1,3 +1,4 @@
1
+ import { __assign } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import React from "react";
3
4
  import { SessionProvider } from "next-auth/react";
@@ -7,7 +8,7 @@ import { AppMain } from "../AppMain";
7
8
  /**
8
9
  * App with authentication provided by `next-auth`
9
10
  */
10
- export const NextApp = (props) => {
11
- return (_jsxs(React.StrictMode, { children: [_jsx(AppHead, {}), _jsx(SessionProvider, { session: props.pageProps.session, children: _jsx(AppTheme, { ...props, children: _jsx(AppMain, { ...props }) }) })] }));
11
+ export var NextApp = function (props) {
12
+ return (_jsxs(React.StrictMode, { children: [_jsx(AppHead, {}), _jsx(SessionProvider, __assign({ session: props.pageProps.session }, { children: _jsx(AppTheme, __assign({}, props, { children: _jsx(AppMain, __assign({}, props)) })) }))] }));
12
13
  };
13
14
  export default NextApp;
package/app/sc/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { __assign } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import React from "react";
3
4
  import { AppHead } from "../AppHead";
@@ -53,7 +54,7 @@ import { AppMain } from "./AppMain";
53
54
  *
54
55
  * ```
55
56
  */
56
- export const NextApp = (props) => {
57
- return (_jsxs(React.StrictMode, { children: [_jsx(AppHead, {}), _jsx(AppTheme, { ...props, children: _jsx(AppMain, { ...props }) })] }));
57
+ export var NextApp = function (props) {
58
+ return (_jsxs(React.StrictMode, { children: [_jsx(AppHead, {}), _jsx(AppTheme, __assign({}, props, { children: _jsx(AppMain, __assign({}, props)) }))] }));
58
59
  };
59
60
  export default NextApp;
package/config/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { __assign, __awaiter, __generator, __rest } from "tslib";
1
2
  /**
2
3
  * Normalise pathname
3
4
  *
@@ -15,19 +16,19 @@ export function normaliseUrlPathname(pathname) {
15
16
  * @see {@link normaliseUrlPathname}
16
17
  */
17
18
  export function encodePathname(pathname) {
18
- const parts = normaliseUrlPathname(pathname).split("/");
19
+ var parts = normaliseUrlPathname(pathname).split("/");
19
20
  return parts
20
- .filter((part) => !!part)
21
- .map((part) => encodeURIComponent(part))
21
+ .filter(function (part) { return !!part; })
22
+ .map(function (part) { return encodeURIComponent(part); })
22
23
  .join("/");
23
24
  }
24
25
  /**
25
26
  */
26
27
  export function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
27
- const suffix = dynamic ? `/:slug*` : "";
28
+ var suffix = dynamic ? "/:slug*" : "";
28
29
  return {
29
- source: `/${locale}/${encodePathname(localisedPathname)}${suffix}`,
30
- destination: `/${encodePathname(templateName)}${suffix}`,
30
+ source: "/".concat(locale, "/").concat(encodePathname(localisedPathname)).concat(suffix),
31
+ destination: "/".concat(encodePathname(templateName)).concat(suffix),
31
32
  permanent: Boolean(permanent),
32
33
  locale: false,
33
34
  };
@@ -35,47 +36,59 @@ export function getPathRedirect(locale, localisedPathname, templateName, dynamic
35
36
  /**
36
37
  */
37
38
  export function getPathRewrite(source, destination, dynamic) {
38
- const suffix = dynamic ? `/:path*` : "";
39
+ var suffix = dynamic ? "/:path*" : "";
39
40
  return {
40
- source: `/${encodePathname(source)}${suffix}`,
41
- destination: `/${encodePathname(destination)}${suffix}`,
41
+ source: "/".concat(encodePathname(source)).concat(suffix),
42
+ destination: "/".concat(encodePathname(destination)).concat(suffix),
42
43
  };
43
44
  }
44
45
  /**
45
46
  */
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
- }
47
+ export function getRedirects(_a) {
48
+ var defaultLocale = _a.defaultLocale, routes = _a.routes, dynamicRoutes = _a.dynamicRoutes, permanent = _a.permanent;
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var redirects;
51
+ return __generator(this, function (_b) {
52
+ redirects = [];
53
+ Object.keys(routes).forEach(function (page) {
54
+ var dynamic = dynamicRoutes[page];
55
+ if (routes[page] !== page) {
56
+ if (dynamic) {
57
+ redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
58
+ }
59
+ else {
60
+ redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
61
+ }
62
+ }
63
+ });
64
+ // console.log("redirects", redirects);
65
+ return [2 /*return*/, redirects];
66
+ });
58
67
  });
59
- // console.log("redirects", redirects);
60
- return redirects;
61
68
  }
62
69
  /**
63
70
  */
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
- }
71
+ export function getRewrites(_a) {
72
+ var routes = _a.routes, dynamicRoutes = _a.dynamicRoutes;
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var rewrites;
75
+ return __generator(this, function (_b) {
76
+ rewrites = [];
77
+ Object.keys(routes).forEach(function (page) {
78
+ var dynamic = dynamicRoutes[page];
79
+ if (routes[page] !== page) {
80
+ if (dynamic) {
81
+ rewrites.push(getPathRewrite(routes[page], page, true));
82
+ }
83
+ else {
84
+ rewrites.push(getPathRewrite(routes[page], page));
85
+ }
86
+ }
87
+ });
88
+ // console.log("rewrites", rewrites);
89
+ return [2 /*return*/, rewrites];
90
+ });
76
91
  });
77
- // console.log("rewrites", rewrites);
78
- return rewrites;
79
92
  }
80
93
  /**
81
94
  * Get Next.js config with some basic opinionated defaults
@@ -88,47 +101,24 @@ export async function getRewrites({ routes, dynamicRoutes, }) {
88
101
  * 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
102
  * and it enables the same for `next-translate`.
90
103
  */
91
- export function withKoine({ nx = true, svg = true, sc = true, page, ...nextConfig } = {}) {
92
- nextConfig = {
104
+ export function withKoine(_a) {
105
+ var _b;
106
+ if (_a === void 0) { _a = {}; }
107
+ 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 = __rest(_a, ["nx", "svg", "sc", "page"]);
108
+ nextConfig = __assign({
93
109
  // @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: {
110
+ pageExtensions: page ? ["page.tsx", "page.ts"] : undefined, eslint: {
96
111
  ignoreDuringBuilds: true, // we have this strict check on each commit
97
- },
98
- typescript: {
112
+ }, typescript: {
99
113
  ignoreBuildErrors: true, // we have this strict check on each commit
100
- },
101
- poweredByHeader: false,
102
- swcMinify: true,
103
- experimental: {
114
+ }, poweredByHeader: false, swcMinify: true, experimental: __assign(__assign({
104
115
  // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
105
116
  // @see critters error https://github.com/vercel/next.js/issues/20742
106
117
  // optimizeCss: true,
107
118
  // @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 || {}),
119
+ scrollRestoration: true }, (nextConfig.experimental || {})), {
113
120
  // @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
- };
121
+ modularizeImports: __assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }) }, nextConfig);
132
122
  if (svg) {
133
123
  if (nx) {
134
124
  // @see https://github.com/gregberge/svgr
@@ -137,8 +127,8 @@ export function withKoine({ nx = true, svg = true, sc = true, page, ...nextConfi
137
127
  };
138
128
  }
139
129
  else {
140
- nextConfig.webpack = (_config, options) => {
141
- const webpackConfig = typeof nextConfig.webpack === "function"
130
+ nextConfig.webpack = function (_config, options) {
131
+ var webpackConfig = typeof nextConfig.webpack === "function"
142
132
  ? nextConfig.webpack(_config, options)
143
133
  : _config;
144
134
  // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
@@ -1,3 +1,4 @@
1
+ import { __assign, __extends } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import NextDocument, { Html, Head, Main, NextScript } from "next/document";
3
4
  import { Meta, NoJs } from "@koine/react";
@@ -11,9 +12,15 @@ import { Meta, NoJs } from "@koine/react";
11
12
  * export { Document as default } from "@koine/next/document";
12
13
  * ```
13
14
  */
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, {})] })] }));
15
+ var Document = /** @class */ (function (_super) {
16
+ __extends(Document, _super);
17
+ function Document() {
18
+ return _super !== null && _super.apply(this, arguments) || this;
18
19
  }
19
- }
20
+ Document.prototype.render = function () {
21
+ var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
22
+ return (_jsxs(Html, __assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] })));
23
+ };
24
+ return Document;
25
+ }(NextDocument));
26
+ export { Document };
@@ -1,3 +1,4 @@
1
+ import { __assign, __awaiter, __extends, __generator } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import NextDocument, { Html, Head, Main, NextScript, } from "next/document";
3
4
  import { Meta, NoJs } from "@koine/react";
@@ -14,17 +15,30 @@ import { getInitialThemeFromRequest } from "@koine/react/sc"; // FIXME: this sho
14
15
  * export { Document as default } from "@koine/next/document/css";
15
16
  * ```
16
17
  */
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
- };
18
+ var Document = /** @class */ (function (_super) {
19
+ __extends(Document, _super);
20
+ function Document() {
21
+ return _super !== null && _super.apply(this, arguments) || this;
24
22
  }
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
- }
23
+ Document.getInitialProps = function (ctx) {
24
+ var _a;
25
+ return __awaiter(this, void 0, void 0, function () {
26
+ var initialProps;
27
+ return __generator(this, function (_b) {
28
+ switch (_b.label) {
29
+ case 0: return [4 /*yield*/, NextDocument.getInitialProps(ctx)];
30
+ case 1:
31
+ initialProps = _b.sent();
32
+ return [2 /*return*/, __assign(__assign({}, initialProps), { theme: getInitialThemeFromRequest(((_a = ctx.req) === null || _a === void 0 ? void 0 : _a.headers.cookie /* || document?.cookie */) || "") })];
33
+ }
34
+ });
35
+ });
36
+ };
37
+ Document.prototype.render = function () {
38
+ var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
39
+ return (_jsxs(Html, __assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] })));
40
+ };
41
+ return Document;
42
+ }(NextDocument));
43
+ export { Document };
30
44
  export default Document;
@@ -1,3 +1,4 @@
1
+ import { __assign, __awaiter, __extends, __generator } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import NextDocument, { Html, Head, Main, NextScript } from "next/document";
3
4
  import { Meta, NoJs } from "@koine/react";
@@ -13,56 +14,46 @@ import { createEmotionCache } from "../../utils/emotion-cache";
13
14
  * export { Document as default } from "@koine/next/document/em";
14
15
  * ```
15
16
  */
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, {})] })] }));
17
+ var Document = /** @class */ (function (_super) {
18
+ __extends(Document, _super);
19
+ function Document() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
20
21
  }
21
- }
22
+ Document.prototype.render = function () {
23
+ var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
24
+ return (_jsxs(Html, __assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {}), this.props.emotionStyleTags] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] })));
25
+ };
26
+ return Document;
27
+ }(NextDocument));
28
+ export { Document };
22
29
  // `getInitialProps` belongs to `_document` (instead of `_app`),
23
30
  // 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
- },
31
+ Document.getInitialProps = function (ctx) { return __awaiter(void 0, void 0, void 0, function () {
32
+ var originalRenderPage, cache, extractCriticalToChunks, initialProps, emotionStyles, emotionStyleTags;
33
+ return __generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0:
36
+ originalRenderPage = ctx.renderPage;
37
+ cache = createEmotionCache();
38
+ extractCriticalToChunks = createEmotionServer(cache).extractCriticalToChunks;
39
+ ctx.renderPage = function () {
40
+ return originalRenderPage({
41
+ enhanceApp: function (App) {
42
+ return function EnhanceApp(props) {
43
+ return _jsx(App, __assign({ emotionCache: cache }, props));
44
+ };
45
+ },
46
+ });
47
+ };
48
+ return [4 /*yield*/, Document.getInitialProps(ctx)];
49
+ case 1:
50
+ initialProps = _a.sent();
51
+ emotionStyles = extractCriticalToChunks(initialProps.html);
52
+ emotionStyleTags = emotionStyles.styles.map(function (style) { return (_jsx("style", { "data-emotion": "".concat(style.key, " ").concat(style.ids.join(" ")),
53
+ // eslint-disable-next-line react/no-danger
54
+ dangerouslySetInnerHTML: { __html: style.css } }, style.key)); });
55
+ return [2 /*return*/, __assign(__assign({}, initialProps), { emotionStyleTags: emotionStyleTags })];
56
+ }
55
57
  });
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
- };
58
+ }); };
68
59
  export default Document;
@@ -1,3 +1,4 @@
1
+ import { __assign, __awaiter, __extends, __generator } from "tslib";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import React from "react";
3
4
  /* ? eslint-disable @next/next/no-document-import-in-page */
@@ -17,28 +18,48 @@ import { ServerStyleSheet } from "styled-components";
17
18
  * export { Document as default } from "@koine/next/document/sc";
18
19
  * ```
19
20
  */
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, {})] })] }));
21
+ var Document = /** @class */ (function (_super) {
22
+ __extends(Document, _super);
23
+ function Document() {
24
+ return _super !== null && _super.apply(this, arguments) || this;
42
25
  }
43
- }
26
+ Document.getInitialProps = function (ctx) {
27
+ return __awaiter(this, void 0, void 0, function () {
28
+ var sheet, originalRenderPage, initialProps;
29
+ return __generator(this, function (_a) {
30
+ switch (_a.label) {
31
+ case 0:
32
+ sheet = new ServerStyleSheet();
33
+ originalRenderPage = ctx.renderPage;
34
+ _a.label = 1;
35
+ case 1:
36
+ _a.trys.push([1, , 3, 4]);
37
+ ctx.renderPage = function () {
38
+ return originalRenderPage({
39
+ enhanceApp: function (App) { return function (props) {
40
+ return sheet.collectStyles(_jsx(App, __assign({}, props)));
41
+ }; },
42
+ });
43
+ };
44
+ return [4 /*yield*/, NextDocument.getInitialProps(ctx)];
45
+ case 2:
46
+ initialProps = _a.sent();
47
+ return [2 /*return*/, __assign(__assign({}, initialProps), {
48
+ // @ts-expect-error FIXME: have they changed type?
49
+ styles: (_jsxs(React.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })) })];
50
+ case 3:
51
+ sheet.seal();
52
+ return [7 /*endfinally*/];
53
+ case 4: return [2 /*return*/];
54
+ }
55
+ });
56
+ });
57
+ };
58
+ Document.prototype.render = function () {
59
+ var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
60
+ return (_jsxs(Html, __assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] })));
61
+ };
62
+ return Document;
63
+ }(NextDocument));
64
+ export { Document };
44
65
  export default Document;
@@ -1,28 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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);
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ var react_1 = require("react");
7
+ var router_1 = require("next/router");
8
+ var script_1 = tslib_1.__importDefault(require("next/script"));
9
+ var utils_1 = require("@koine/utils");
10
+ var AnalyticsGoogle = function (_a) {
11
+ var id = _a.id;
12
+ var uid = id || process.env["NEXT_PUBLIC_GTM_ID"];
13
+ var _b = (0, router_1.useRouter)(), events = _b.events, asPath = _b.asPath, query = _b.query;
14
+ var _c = (0, react_1.useState)(false), ready = _c[0], setReady = _c[1];
15
+ var _d = (0, react_1.useState)(false), routed = _d[0], setRouted = _d[1];
15
16
  // const [url, setUrl] = useState("");
16
- (0, react_1.useEffect)(() => {
17
- const handleRouteChange = () => {
17
+ (0, react_1.useEffect)(function () {
18
+ var handleRouteChange = function () {
18
19
  setRouted(true);
19
20
  };
20
21
  events.on("routeChangeComplete", handleRouteChange);
21
- return () => {
22
+ return function () {
22
23
  events.off("routeChangeComplete", handleRouteChange);
23
24
  };
24
25
  }, [events]);
25
- (0, react_1.useEffect)(() => {
26
+ (0, react_1.useEffect)(function () {
26
27
  if (routed && ready && asPath) {
27
28
  // const search = query;
28
29
  (0, utils_1.pageview)(asPath);
@@ -31,12 +32,6 @@ const AnalyticsGoogle = ({ id }) => {
31
32
  if (!uid) {
32
33
  return null;
33
34
  }
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
- ` })] }));
35
+ 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=".concat(id), strategy: "afterInteractive", onLoad: function () { return setReady(true); } }), (0, jsx_runtime_1.jsx)(script_1.default, tslib_1.__assign({ id: "google-analytics", strategy: "afterInteractive" }, { children: "\n window.dataLayer = window.dataLayer || [];\n function gtag(){window.dataLayer.push(arguments);}\n gtag('js', new Date());\n\n gtag('config', '".concat(id, "', { 'send_page_view': false });\n ") }))] }));
41
36
  };
42
37
  exports.AnalyticsGoogle = AnalyticsGoogle;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
3
+ var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./AnalyticsGoogle"), exports);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCallbackUrl = exports.getAuthRoutes = exports.AUTH_ROUTES = void 0;
4
- const utils_1 = require("@koine/utils");
4
+ var utils_1 = require("@koine/utils");
5
5
  exports.AUTH_ROUTES = {
6
6
  login: process.env["AUTH_ROUTE_LOGIN"],
7
7
  profile: process.env["AUTH_ROUTE_PROFILE"],
@@ -9,10 +9,10 @@ exports.AUTH_ROUTES = {
9
9
  secured: JSON.parse(process.env["AUTH_ROUTES_SECURED"] || "[]"),
10
10
  };
11
11
  function getAuthRoutes(t) {
12
- return Object.keys(exports.AUTH_ROUTES).reduce((map, name) => {
13
- const routePage = exports.AUTH_ROUTES[name];
12
+ return Object.keys(exports.AUTH_ROUTES).reduce(function (map, name) {
13
+ var routePage = exports.AUTH_ROUTES[name];
14
14
  // @ts-expect-error cannot remember
15
- map[name] = (0, utils_1.isString)(routePage) ? t(`~:${exports.AUTH_ROUTES[name]}`) : routePage;
15
+ map[name] = (0, utils_1.isString)(routePage) ? t("~:".concat(exports.AUTH_ROUTES[name])) : routePage;
16
16
  return map;
17
17
  }, {});
18
18
  }
@@ -20,7 +20,8 @@ exports.getAuthRoutes = getAuthRoutes;
20
20
  /**
21
21
  * @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
22
22
  */
23
- function getCallbackUrl(url = window.location.href) {
23
+ function getCallbackUrl(url) {
24
+ if (url === void 0) { url = window.location.href; }
24
25
  return url.split("callbackUrl=")[1] || "";
25
26
  }
26
27
  exports.getCallbackUrl = getCallbackUrl;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
3
+ var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./helpers"), exports);
5
5
  tslib_1.__exportStar(require("./useLogin"), exports);
6
6
  tslib_1.__exportStar(require("./useLoginUrl"), exports);