@koine/next 1.0.9 → 1.0.10

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 (184) hide show
  1. package/package.json +30 -2
  2. package/Analytics/AnalyticsGoogle.d.ts +0 -5
  3. package/Analytics/AnalyticsGoogle.js +0 -37
  4. package/Analytics/index.d.ts +0 -1
  5. package/Analytics/index.js +0 -1
  6. package/Analytics/package.json +0 -6
  7. package/Auth/helpers.d.ts +0 -17
  8. package/Auth/helpers.js +0 -21
  9. package/Auth/index.d.ts +0 -4
  10. package/Auth/index.js +0 -4
  11. package/Auth/package.json +0 -6
  12. package/Auth/useLogin.d.ts +0 -7
  13. package/Auth/useLogin.js +0 -50
  14. package/Auth/useLoginUrl.d.ts +0 -1
  15. package/Auth/useLoginUrl.js +0 -11
  16. package/Auth/useLogout.d.ts +0 -6
  17. package/Auth/useLogout.js +0 -52
  18. package/Favicon/Favicon.d.ts +0 -3
  19. package/Favicon/Favicon.js +0 -4
  20. package/Favicon/index.d.ts +0 -1
  21. package/Favicon/index.js +0 -1
  22. package/Favicon/package.json +0 -6
  23. package/Forms/index.d.ts +0 -2
  24. package/Forms/index.js +0 -2
  25. package/Forms/package.json +0 -6
  26. package/Forms/useForm.d.ts +0 -32
  27. package/Forms/useForm.js +0 -37
  28. package/Forms/useSubmit.d.ts +0 -24
  29. package/Forms/useSubmit.js +0 -23
  30. package/Head/Head.d.ts +0 -1
  31. package/Head/Head.js +0 -1
  32. package/Head/index.d.ts +0 -1
  33. package/Head/index.js +0 -1
  34. package/Head/package.json +0 -6
  35. package/I18n/I18n.d.ts +0 -44
  36. package/I18n/I18n.js +0 -74
  37. package/I18n/index.d.ts +0 -1
  38. package/I18n/index.js +0 -1
  39. package/I18n/package.json +0 -6
  40. package/Img/Img.d.ts +0 -21
  41. package/Img/Img.js +0 -28
  42. package/Img/index.d.ts +0 -1
  43. package/Img/index.js +0 -1
  44. package/Img/package.json +0 -6
  45. package/Link/Link.d.ts +0 -9
  46. package/Link/Link.js +0 -9
  47. package/Link/index.d.ts +0 -1
  48. package/Link/index.js +0 -1
  49. package/Link/package.json +0 -6
  50. package/NextProgress/NextProgress.d.ts +0 -24
  51. package/NextProgress/NextProgress.js +0 -37
  52. package/NextProgress/index.d.ts +0 -2
  53. package/NextProgress/index.js +0 -1
  54. package/NextProgress/package.json +0 -6
  55. package/Seo/Seo.d.ts +0 -3
  56. package/Seo/Seo.js +0 -8
  57. package/Seo/SeoDefaults.d.ts +0 -3
  58. package/Seo/SeoDefaults.js +0 -12
  59. package/Seo/helpers.d.ts +0 -48
  60. package/Seo/helpers.js +0 -111
  61. package/Seo/index.d.ts +0 -12
  62. package/Seo/index.js +0 -12
  63. package/Seo/package.json +0 -6
  64. package/Theme/Theme.d.ts +0 -46
  65. package/Theme/Theme.js +0 -235
  66. package/Theme/index.d.ts +0 -1
  67. package/Theme/index.js +0 -1
  68. package/Theme/package.json +0 -6
  69. package/app/AppHead.d.ts +0 -2
  70. package/app/AppHead.js +0 -5
  71. package/app/AppMain.d.ts +0 -35
  72. package/app/AppMain.js +0 -1
  73. package/app/css/AppMain.d.ts +0 -8
  74. package/app/css/AppMain.js +0 -11
  75. package/app/css/AppTheme.d.ts +0 -10
  76. package/app/css/AppTheme.js +0 -12
  77. package/app/css/auth/index.d.ts +0 -9
  78. package/app/css/auth/index.js +0 -13
  79. package/app/css/auth/package.json +0 -6
  80. package/app/css/index.d.ts +0 -54
  81. package/app/css/index.js +0 -57
  82. package/app/css/package.json +0 -6
  83. package/app/em/AppMain.d.ts +0 -10
  84. package/app/em/AppMain.js +0 -22
  85. package/app/em/AppTheme.d.ts +0 -15
  86. package/app/em/AppTheme.js +0 -17
  87. package/app/em/auth/index.d.ts +0 -9
  88. package/app/em/auth/index.js +0 -13
  89. package/app/em/auth/package.json +0 -6
  90. package/app/em/index.d.ts +0 -9
  91. package/app/em/index.js +0 -12
  92. package/app/em/package.json +0 -6
  93. package/app/index.d.ts +0 -2
  94. package/app/index.js +0 -2
  95. package/app/package.json +0 -6
  96. package/app/sc/AppMain.d.ts +0 -10
  97. package/app/sc/AppMain.js +0 -22
  98. package/app/sc/AppTheme.d.ts +0 -13
  99. package/app/sc/AppTheme.js +0 -9
  100. package/app/sc/auth/index.d.ts +0 -9
  101. package/app/sc/auth/index.js +0 -13
  102. package/app/sc/auth/package.json +0 -6
  103. package/app/sc/index.d.ts +0 -56
  104. package/app/sc/index.js +0 -59
  105. package/app/sc/package.json +0 -6
  106. package/config/index.d.ts +0 -71
  107. package/config/index.js +0 -174
  108. package/config/package.json +0 -6
  109. package/document/Document.d.ts +0 -15
  110. package/document/Document.js +0 -19
  111. package/document/css/index.d.ts +0 -22
  112. package/document/css/index.js +0 -30
  113. package/document/css/package.json +0 -6
  114. package/document/em/index.d.ts +0 -16
  115. package/document/em/index.js +0 -68
  116. package/document/em/package.json +0 -6
  117. package/document/index.d.ts +0 -2
  118. package/document/index.js +0 -2
  119. package/document/package.json +0 -6
  120. package/document/sc/index.d.ts +0 -20
  121. package/document/sc/index.js +0 -44
  122. package/document/sc/package.json +0 -6
  123. package/index.d.ts +0 -12
  124. package/index.js +0 -12
  125. package/node/Analytics/AnalyticsGoogle.js +0 -42
  126. package/node/Analytics/index.js +0 -4
  127. package/node/Auth/helpers.js +0 -26
  128. package/node/Auth/index.js +0 -7
  129. package/node/Auth/useLogin.js +0 -54
  130. package/node/Auth/useLoginUrl.js +0 -15
  131. package/node/Auth/useLogout.js +0 -56
  132. package/node/Favicon/Favicon.js +0 -9
  133. package/node/Favicon/index.js +0 -4
  134. package/node/Forms/index.js +0 -5
  135. package/node/Forms/useForm.js +0 -41
  136. package/node/Forms/useSubmit.js +0 -27
  137. package/node/Head/Head.js +0 -8
  138. package/node/Head/index.js +0 -4
  139. package/node/I18n/I18n.js +0 -82
  140. package/node/I18n/index.js +0 -4
  141. package/node/Img/Img.js +0 -34
  142. package/node/Img/index.js +0 -4
  143. package/node/Link/Link.js +0 -13
  144. package/node/Link/index.js +0 -4
  145. package/node/NextProgress/NextProgress.js +0 -41
  146. package/node/NextProgress/index.js +0 -5
  147. package/node/Seo/Seo.js +0 -12
  148. package/node/Seo/SeoDefaults.js +0 -16
  149. package/node/Seo/helpers.js +0 -115
  150. package/node/Seo/index.js +0 -15
  151. package/node/Theme/Theme.js +0 -241
  152. package/node/Theme/index.js +0 -4
  153. package/node/app/AppHead.js +0 -10
  154. package/node/app/AppMain.js +0 -2
  155. package/node/app/css/AppMain.js +0 -16
  156. package/node/app/css/AppTheme.js +0 -16
  157. package/node/app/css/auth/index.js +0 -18
  158. package/node/app/css/index.js +0 -62
  159. package/node/app/em/AppMain.js +0 -26
  160. package/node/app/em/AppTheme.js +0 -22
  161. package/node/app/em/auth/index.js +0 -18
  162. package/node/app/em/index.js +0 -17
  163. package/node/app/index.js +0 -5
  164. package/node/app/sc/AppMain.js +0 -26
  165. package/node/app/sc/AppTheme.js +0 -13
  166. package/node/app/sc/auth/index.js +0 -18
  167. package/node/app/sc/index.js +0 -64
  168. package/node/config/index.js +0 -184
  169. package/node/document/Document.js +0 -24
  170. package/node/document/css/index.js +0 -35
  171. package/node/document/em/index.js +0 -73
  172. package/node/document/index.js +0 -7
  173. package/node/document/sc/index.js +0 -49
  174. package/node/index.js +0 -15
  175. package/node/utils/api.js +0 -38
  176. package/node/utils/emotion-cache.js +0 -13
  177. package/node/utils/index.js +0 -32
  178. package/utils/api.d.ts +0 -55
  179. package/utils/api.js +0 -35
  180. package/utils/emotion-cache.d.ts +0 -5
  181. package/utils/emotion-cache.js +0 -8
  182. package/utils/index.d.ts +0 -19
  183. package/utils/index.js +0 -26
  184. package/utils/package.json +0 -6
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NextApp = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importDefault(require("react"));
7
- const react_2 = require("next-auth/react");
8
- const AppHead_1 = require("../../AppHead");
9
- const AppTheme_1 = require("../AppTheme");
10
- const AppMain_1 = require("../AppMain");
11
- /**
12
- * App with authentication provided by `next-auth`
13
- */
14
- const NextApp = (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, { session: props.pageProps.session, children: (0, jsx_runtime_1.jsx)(AppTheme_1.AppTheme, { ...props, children: (0, jsx_runtime_1.jsx)(AppMain_1.AppMain, { ...props }) }) })] }));
16
- };
17
- exports.NextApp = NextApp;
18
- exports.default = exports.NextApp;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NextApp = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importDefault(require("react"));
7
- const AppHead_1 = require("../AppHead");
8
- const AppTheme_1 = require("./AppTheme");
9
- const 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
- const NextApp = (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, { ...props, children: (0, jsx_runtime_1.jsx)(AppMain_1.AppMain, { ...props }) })] }));
62
- };
63
- exports.NextApp = NextApp;
64
- exports.default = exports.NextApp;
@@ -1,184 +0,0 @@
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 = void 0;
4
- /**
5
- * Normalise pathname
6
- *
7
- * From a path like `/some//malformed/path///` it returns `some/malformed/path`
8
- *
9
- * - Removes subsequent slashes
10
- * - Removing initial and ending slashes
11
- */
12
- function normaliseUrlPathname(pathname) {
13
- return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
14
- }
15
- exports.normaliseUrlPathname = normaliseUrlPathname;
16
- /**
17
- * Clean a pathname and encode each part
18
- *
19
- * @see {@link normaliseUrlPathname}
20
- */
21
- function encodePathname(pathname) {
22
- const parts = normaliseUrlPathname(pathname).split("/");
23
- return parts
24
- .filter((part) => !!part)
25
- .map((part) => encodeURIComponent(part))
26
- .join("/");
27
- }
28
- exports.encodePathname = encodePathname;
29
- /**
30
- */
31
- function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
32
- const suffix = dynamic ? `/:slug*` : "";
33
- return {
34
- source: `/${locale}/${encodePathname(localisedPathname)}${suffix}`,
35
- destination: `/${encodePathname(templateName)}${suffix}`,
36
- permanent: Boolean(permanent),
37
- locale: false,
38
- };
39
- }
40
- exports.getPathRedirect = getPathRedirect;
41
- /**
42
- */
43
- function getPathRewrite(source, destination, dynamic) {
44
- const suffix = dynamic ? `/:path*` : "";
45
- return {
46
- source: `/${encodePathname(source)}${suffix}`,
47
- destination: `/${encodePathname(destination)}${suffix}`,
48
- };
49
- }
50
- exports.getPathRewrite = getPathRewrite;
51
- /**
52
- */
53
- async function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }) {
54
- const redirects = [];
55
- Object.keys(routes).forEach((page) => {
56
- const dynamic = dynamicRoutes[page];
57
- if (routes[page] !== page) {
58
- if (dynamic) {
59
- redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
60
- }
61
- else {
62
- redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
63
- }
64
- }
65
- });
66
- // console.log("redirects", redirects);
67
- return redirects;
68
- }
69
- exports.getRedirects = getRedirects;
70
- /**
71
- */
72
- async function getRewrites({ routes, dynamicRoutes, }) {
73
- const rewrites = [];
74
- Object.keys(routes).forEach((page) => {
75
- const dynamic = dynamicRoutes[page];
76
- if (routes[page] !== page) {
77
- if (dynamic) {
78
- rewrites.push(getPathRewrite(routes[page], page, true));
79
- }
80
- else {
81
- rewrites.push(getPathRewrite(routes[page], page));
82
- }
83
- }
84
- });
85
- // console.log("rewrites", rewrites);
86
- return rewrites;
87
- }
88
- exports.getRewrites = getRewrites;
89
- /**
90
- * Get Next.js config with some basic opinionated defaults
91
- *
92
- * @param {object} options
93
- * @property {boolean} [options.nx=false] Nx monorepo setup
94
- * @property {boolean} [options.svg=false] Svg to react components
95
- * @property {boolean} [options.sc=false] Styled components enabled
96
- * @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
97
- * 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)
98
- * and it enables the same for `next-translate`.
99
- */
100
- function withKoine({ nx = true, svg = true, sc = true, page, ...nextConfig } = {}) {
101
- nextConfig = {
102
- // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
103
- pageExtensions: page ? ["page.tsx", "page.ts"] : undefined,
104
- eslint: {
105
- ignoreDuringBuilds: true, // we have this strict check on each commit
106
- },
107
- typescript: {
108
- ignoreBuildErrors: true, // we have this strict check on each commit
109
- },
110
- poweredByHeader: false,
111
- swcMinify: true,
112
- experimental: {
113
- // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
114
- // @see critters error https://github.com/vercel/next.js/issues/20742
115
- // optimizeCss: true,
116
- // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
117
- scrollRestoration: true,
118
- // concurrentFeatures: true,
119
- // serverComponents: true,
120
- // reactRoot: true,
121
- ...(nextConfig.experimental || {}),
122
- // @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
123
- modularizeImports: {
124
- ...(nextConfig?.experimental?.modularizeImports || {}),
125
- // FIXME: make these work with the right file/folder structure?
126
- // "@koine/next/?(((\\w*)?/?)*)": {
127
- // transform: "@koine/next/{{ matches.[1] }}/{{member}}",
128
- // },
129
- // "@koine/react/?(((\\w*)?/?)*)": {
130
- // transform: "@koine/react/{{ matches.[1] }}/{{member}}",
131
- // },
132
- // "@koine/utils/?(((\\w*)?/?)*)": {
133
- // transform: "@koine/utils/{{ matches.[1] }}/{{member}}",
134
- // },
135
- },
136
- },
137
- // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
138
- // reactStrictMode: false,
139
- ...nextConfig,
140
- };
141
- if (svg) {
142
- if (nx) {
143
- // @see https://github.com/gregberge/svgr
144
- nextConfig["nx"] = {
145
- svgr: true,
146
- };
147
- }
148
- else {
149
- nextConfig.webpack = (_config, options) => {
150
- const webpackConfig = typeof nextConfig.webpack === "function"
151
- ? nextConfig.webpack(_config, options)
152
- : _config;
153
- // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
154
- webpackConfig.module.rules.push({
155
- test: /\.svg$/,
156
- use: [
157
- {
158
- loader: "@svgr/webpack",
159
- options: {
160
- svgoConfig: {
161
- plugins: [
162
- {
163
- name: "removeViewBox",
164
- active: false,
165
- },
166
- ],
167
- },
168
- },
169
- },
170
- ],
171
- });
172
- return webpackConfig;
173
- };
174
- }
175
- }
176
- if (sc) {
177
- nextConfig.compiler = {
178
- styledComponents: true,
179
- };
180
- }
181
- return nextConfig;
182
- }
183
- exports.withKoine = withKoine;
184
- exports.default = withKoine;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Document = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const document_1 = tslib_1.__importStar(require("next/document"));
7
- const 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
- class Document extends document_1.default {
19
- render() {
20
- const { locale, defaultLocale } = this.props.__NEXT_DATA__;
21
- return ((0, jsx_runtime_1.jsxs)(document_1.Html, { 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, {})] })] }));
22
- }
23
- }
24
- exports.Document = Document;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Document = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const document_1 = tslib_1.__importStar(require("next/document"));
7
- const react_1 = require("@koine/react");
8
- const 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
- class Document extends document_1.default {
22
- static async getInitialProps(ctx) {
23
- const initialProps = await document_1.default.getInitialProps(ctx);
24
- return {
25
- ...initialProps,
26
- theme: (0, sc_1.getInitialThemeFromRequest)(ctx.req?.headers.cookie /* || document?.cookie */ || ""),
27
- };
28
- }
29
- render() {
30
- const { locale, defaultLocale } = this.props.__NEXT_DATA__;
31
- return ((0, jsx_runtime_1.jsxs)(document_1.Html, { 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, {})] })] }));
32
- }
33
- }
34
- exports.Document = Document;
35
- exports.default = Document;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Document = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const document_1 = tslib_1.__importStar(require("next/document"));
7
- const react_1 = require("@koine/react");
8
- const create_instance_1 = tslib_1.__importDefault(require("@emotion/server/create-instance"));
9
- const 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
- class Document extends document_1.default {
21
- render() {
22
- const { locale, defaultLocale } = this.props.__NEXT_DATA__;
23
- return ((0, jsx_runtime_1.jsxs)(document_1.Html, { 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, {})] })] }));
24
- }
25
- }
26
- exports.Document = Document;
27
- // `getInitialProps` belongs to `_document` (instead of `_app`),
28
- // it's compatible with static-site generation (SSG).
29
- Document.getInitialProps = async (ctx) => {
30
- // Resolution order
31
- //
32
- // On the server:
33
- // 1. app.getInitialProps
34
- // 2. page.getInitialProps
35
- // 3. document.getInitialProps
36
- // 4. app.render
37
- // 5. page.render
38
- // 6. document.render
39
- //
40
- // On the server with error:
41
- // 1. document.getInitialProps
42
- // 2. app.render
43
- // 3. page.render
44
- // 4. document.render
45
- //
46
- // On the client
47
- // 1. app.getInitialProps
48
- // 2. page.getInitialProps
49
- // 3. app.render
50
- // 4. page.render
51
- const originalRenderPage = ctx.renderPage;
52
- // You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
53
- // However, be aware that it can have global side effects.
54
- const cache = (0, emotion_cache_1.createEmotionCache)();
55
- const { extractCriticalToChunks } = (0, create_instance_1.default)(cache);
56
- ctx.renderPage = () => originalRenderPage({
57
- enhanceApp: (App) => function EnhanceApp(props) {
58
- return (0, jsx_runtime_1.jsx)(App, { emotionCache: cache, ...props });
59
- },
60
- });
61
- const initialProps = await Document.getInitialProps(ctx);
62
- // This is important. It prevents emotion to render invalid HTML.
63
- // See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
64
- const emotionStyles = extractCriticalToChunks(initialProps.html);
65
- const emotionStyleTags = emotionStyles.styles.map((style) => ((0, jsx_runtime_1.jsx)("style", { "data-emotion": `${style.key} ${style.ids.join(" ")}`,
66
- // eslint-disable-next-line react/no-danger
67
- dangerouslySetInnerHTML: { __html: style.css } }, style.key)));
68
- return {
69
- ...initialProps,
70
- emotionStyleTags,
71
- };
72
- };
73
- exports.default = Document;
@@ -1,7 +0,0 @@
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; } });
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Document = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importDefault(require("react"));
7
- /* ? eslint-disable @next/next/no-document-import-in-page */
8
- const document_1 = tslib_1.__importStar(require("next/document"));
9
- const react_2 = require("@koine/react");
10
- const 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
- class Document extends document_1.default {
25
- static async getInitialProps(ctx) {
26
- const sheet = new styled_components_1.ServerStyleSheet();
27
- const originalRenderPage = ctx.renderPage;
28
- try {
29
- ctx.renderPage = () => originalRenderPage({
30
- enhanceApp: (App) => (props) => sheet.collectStyles((0, jsx_runtime_1.jsx)(App, { ...props })),
31
- });
32
- const initialProps = await document_1.default.getInitialProps(ctx);
33
- return {
34
- ...initialProps,
35
- // @ts-expect-error FIXME: have they changed type?
36
- styles: ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })),
37
- };
38
- }
39
- finally {
40
- sheet.seal();
41
- }
42
- }
43
- render() {
44
- const { locale, defaultLocale } = this.props.__NEXT_DATA__;
45
- return ((0, jsx_runtime_1.jsxs)(document_1.Html, { 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, {})] })] }));
46
- }
47
- }
48
- exports.Document = Document;
49
- exports.default = Document;
package/node/index.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const 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);
package/node/utils/api.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.api = void 0;
4
- const utils_1 = require("@koine/utils");
5
- exports.api = ["get", "post", "put", "patch", "delete"].reduce((api, method) => {
6
- api[method] = async (endpoint, options = {}) => {
7
- const { json = {}, params, headers = {}, timeout = 10000 } = options;
8
- const requestInit = {
9
- method: method.toUpperCase(),
10
- headers: {
11
- "content-type": "application/json",
12
- ...headers,
13
- },
14
- };
15
- const timeoutNumber = Number(timeout);
16
- let controller;
17
- let timeoutId;
18
- let url = `/api/${endpoint.replace(/^\/*/, "")}`;
19
- if (method !== "get") {
20
- requestInit.body = JSON.stringify(json);
21
- }
22
- if (timeoutNumber > 0) {
23
- controller = new AbortController();
24
- timeoutId = setTimeout(() => controller.abort(), timeoutNumber);
25
- requestInit.signal = controller.signal;
26
- }
27
- if (params) {
28
- url += (0, utils_1.buildUrlQueryString)(params);
29
- }
30
- const response = await fetch(url, requestInit);
31
- if (timeoutId) {
32
- clearTimeout(timeoutId);
33
- }
34
- const result = (await response.json());
35
- return result;
36
- };
37
- return api;
38
- }, {});
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEmotionCache = void 0;
4
- const tslib_1 = require("tslib");
5
- const 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;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.load = exports.getSiteUrl = exports.ONE_DAY = exports.ONE_HOUR = void 0;
4
- const tslib_1 = require("tslib");
5
- const utils_1 = require("@koine/utils");
6
- tslib_1.__exportStar(require("./api"), exports);
7
- exports.ONE_HOUR = 3600;
8
- exports.ONE_DAY = 84000;
9
- /**
10
- * Get site absolute url with the given path
11
- *
12
- * - It uses the `NEXT_PUBLIC_APP_URL` env variable
13
- * - It removes the trailing slashes
14
- */
15
- function getSiteUrl(path = "") {
16
- return (0, utils_1.normaliseUrl)(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
17
- }
18
- exports.getSiteUrl = getSiteUrl;
19
- /**
20
- * Utility to load a component with an optional pre-determined delay.
21
- *
22
- * This was designed to improve anti spam wit async form loading.
23
- *
24
- * @see https://github.com/vercel/next.js/blob/main/packages/next/next-server/lib/dynamic.tsx
25
- * @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
26
- */
27
- function load(component, milliseconds) {
28
- return new Promise((resolve) => {
29
- setTimeout(() => resolve(component), milliseconds);
30
- });
31
- }
32
- exports.load = load;
package/utils/api.d.ts DELETED
@@ -1,55 +0,0 @@
1
- declare type _Response = Response;
2
- export declare namespace KoineApi {
3
- type ResponseSuccesfull = unknown;
4
- type ResponseFailed = unknown;
5
- type ResponseShared<T extends Record<string, unknown> = {}> = T & {
6
- status: _Response["status"];
7
- msg: _Response["statusText"];
8
- };
9
- type Response<Succesfull extends ResponseSuccesfull = ResponseSuccesfull, Failed extends ResponseFailed = ResponseFailed> = {
10
- status: _Response["status"];
11
- msg: _Response["statusText"];
12
- ok: true;
13
- fail?: false;
14
- data: Succesfull;
15
- } | {
16
- status: _Response["status"];
17
- msg: _Response["statusText"];
18
- ok?: false;
19
- fail: true;
20
- data: Failed;
21
- };
22
- /**
23
- * Request options
24
- */
25
- type RequestOptions<TJson = unknown> = {
26
- /**
27
- * JSON request body
28
- *
29
- * @default {}
30
- */
31
- json?: TJson;
32
- /**
33
- * Params will be serialized into a string and appended to the URL
34
- */
35
- params?: Record<string, unknown>;
36
- /**
37
- * Headers will be merged with
38
- * ```
39
- * { "content-type": "application/json" }
40
- * ```
41
- */
42
- headers?: RequestInit["headers"];
43
- /**
44
- * Timeout in `ms`, if `falsy` there is no timeout
45
- *
46
- * @default 10000
47
- */
48
- timeout?: number | false | null;
49
- };
50
- type RequestMethod = "get" | "post" | "put" | "patch" | "delete";
51
- type RequestFn = <Succesfull extends ResponseSuccesfull = unknown, Failed extends ResponseFailed = unknown>(endpoint: string, options?: RequestOptions) => Promise<Response<Succesfull, Failed>>;
52
- type Client = Record<RequestMethod, RequestFn>;
53
- }
54
- export declare const api: KoineApi.Client;
55
- export {};
package/utils/api.js DELETED
@@ -1,35 +0,0 @@
1
- import { buildUrlQueryString } from "@koine/utils";
2
- export const api = ["get", "post", "put", "patch", "delete"].reduce((api, method) => {
3
- api[method] = async (endpoint, options = {}) => {
4
- const { json = {}, params, headers = {}, timeout = 10000 } = options;
5
- const requestInit = {
6
- method: method.toUpperCase(),
7
- headers: {
8
- "content-type": "application/json",
9
- ...headers,
10
- },
11
- };
12
- const timeoutNumber = Number(timeout);
13
- let controller;
14
- let timeoutId;
15
- let url = `/api/${endpoint.replace(/^\/*/, "")}`;
16
- if (method !== "get") {
17
- requestInit.body = JSON.stringify(json);
18
- }
19
- if (timeoutNumber > 0) {
20
- controller = new AbortController();
21
- timeoutId = setTimeout(() => controller.abort(), timeoutNumber);
22
- requestInit.signal = controller.signal;
23
- }
24
- if (params) {
25
- url += buildUrlQueryString(params);
26
- }
27
- const response = await fetch(url, requestInit);
28
- if (timeoutId) {
29
- clearTimeout(timeoutId);
30
- }
31
- const result = (await response.json());
32
- return result;
33
- };
34
- return api;
35
- }, {});
@@ -1,5 +0,0 @@
1
- /**
2
- * prepend: true moves MUI styles to the top of the <head> so they're loaded first.
3
- * It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
4
- */
5
- export declare function createEmotionCache(): import("@emotion/utils").EmotionCache;
@@ -1,8 +0,0 @@
1
- import createCache from "@emotion/cache";
2
- /**
3
- * prepend: true moves MUI styles to the top of the <head> so they're loaded first.
4
- * It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
5
- */
6
- export function createEmotionCache() {
7
- return createCache({ key: "css", prepend: true });
8
- }