@koine/next 1.0.4 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/Analytics/AnalyticsGoogle.d.ts +5 -6
  2. package/Analytics/AnalyticsGoogle.js +37 -0
  3. package/Analytics/index.d.ts +1 -1
  4. package/Analytics/index.js +1 -0
  5. package/Analytics/package.json +6 -0
  6. package/Auth/helpers.d.ts +17 -17
  7. package/Auth/helpers.js +21 -0
  8. package/Auth/index.d.ts +4 -4
  9. package/Auth/index.js +4 -0
  10. package/Auth/package.json +6 -0
  11. package/Auth/useLogin.d.ts +7 -7
  12. package/Auth/useLogin.js +50 -0
  13. package/Auth/useLoginUrl.d.ts +1 -1
  14. package/Auth/useLoginUrl.js +11 -0
  15. package/Auth/useLogout.d.ts +6 -6
  16. package/Auth/useLogout.js +52 -0
  17. package/Favicon/Favicon.d.ts +3 -4
  18. package/Favicon/Favicon.js +4 -0
  19. package/Favicon/index.d.ts +1 -1
  20. package/Favicon/index.js +1 -0
  21. package/Favicon/package.json +6 -0
  22. package/Forms/index.d.ts +2 -2
  23. package/Forms/index.js +2 -0
  24. package/Forms/package.json +6 -0
  25. package/Forms/useForm.d.ts +32 -32
  26. package/Forms/useForm.js +37 -0
  27. package/Forms/useSubmit.d.ts +24 -24
  28. package/Forms/useSubmit.js +23 -0
  29. package/Head/Head.d.ts +1 -1
  30. package/Head/Head.js +1 -0
  31. package/Head/index.d.ts +1 -1
  32. package/Head/index.js +1 -0
  33. package/Head/package.json +6 -0
  34. package/I18n/I18n.d.ts +44 -48
  35. package/I18n/I18n.js +74 -0
  36. package/I18n/index.d.ts +1 -1
  37. package/I18n/index.js +1 -0
  38. package/I18n/package.json +6 -0
  39. package/Img/Img.d.ts +21 -21
  40. package/Img/Img.js +28 -0
  41. package/Img/index.d.ts +1 -1
  42. package/Img/index.js +1 -0
  43. package/Img/package.json +6 -0
  44. package/Link/Link.d.ts +9 -8
  45. package/Link/Link.js +9 -0
  46. package/Link/index.d.ts +1 -1
  47. package/Link/index.js +1 -0
  48. package/Link/package.json +6 -0
  49. package/NextProgress/NextProgress.d.ts +24 -14
  50. package/NextProgress/NextProgress.js +37 -0
  51. package/NextProgress/index.d.ts +2 -1
  52. package/NextProgress/index.js +1 -0
  53. package/NextProgress/package.json +6 -0
  54. package/README.md +0 -0
  55. package/Seo/Seo.d.ts +3 -3
  56. package/Seo/Seo.js +8 -0
  57. package/Seo/SeoDefaults.d.ts +3 -3
  58. package/Seo/SeoDefaults.js +12 -0
  59. package/Seo/helpers.d.ts +48 -48
  60. package/Seo/helpers.js +111 -0
  61. package/Seo/index.d.ts +12 -12
  62. package/Seo/index.js +12 -0
  63. package/Seo/package.json +6 -0
  64. package/Theme/Theme.d.ts +46 -46
  65. package/Theme/Theme.js +235 -0
  66. package/Theme/index.d.ts +1 -1
  67. package/Theme/index.js +1 -0
  68. package/Theme/package.json +6 -0
  69. package/app/AppHead.d.ts +2 -3
  70. package/app/AppHead.js +5 -0
  71. package/app/AppMain.d.ts +35 -34
  72. package/app/AppMain.js +1 -0
  73. package/app/css/AppMain.d.ts +8 -0
  74. package/app/css/AppMain.js +11 -0
  75. package/app/css/AppTheme.d.ts +10 -0
  76. package/app/css/AppTheme.js +12 -0
  77. package/app/css/auth/index.d.ts +9 -0
  78. package/app/css/auth/index.js +13 -0
  79. package/app/css/auth/package.json +6 -0
  80. package/app/css/index.d.ts +54 -0
  81. package/app/css/index.js +57 -0
  82. package/app/css/package.json +6 -0
  83. package/app/em/AppMain.d.ts +10 -0
  84. package/app/em/AppMain.js +22 -0
  85. package/app/{AppTheme--emotion.d.ts → em/AppTheme.d.ts} +15 -15
  86. package/app/em/AppTheme.js +17 -0
  87. package/app/em/auth/index.d.ts +9 -0
  88. package/app/em/auth/index.js +13 -0
  89. package/app/em/auth/package.json +6 -0
  90. package/app/em/index.d.ts +9 -0
  91. package/app/em/index.js +12 -0
  92. package/app/em/package.json +6 -0
  93. package/app/index.d.ts +2 -11
  94. package/app/index.js +2 -0
  95. package/app/package.json +6 -0
  96. package/app/sc/AppMain.d.ts +10 -0
  97. package/app/sc/AppMain.js +22 -0
  98. package/app/sc/AppTheme.d.ts +13 -0
  99. package/app/sc/AppTheme.js +9 -0
  100. package/app/sc/auth/index.d.ts +9 -0
  101. package/app/sc/auth/index.js +13 -0
  102. package/app/sc/auth/package.json +6 -0
  103. package/app/sc/index.d.ts +56 -0
  104. package/app/sc/index.js +59 -0
  105. package/app/sc/package.json +6 -0
  106. package/config/index.d.ts +71 -58
  107. package/config/index.js +174 -0
  108. package/config/package.json +6 -0
  109. package/document/Document.d.ts +15 -10
  110. package/document/Document.js +19 -0
  111. package/document/css/index.d.ts +22 -0
  112. package/document/css/index.js +30 -0
  113. package/document/css/package.json +6 -0
  114. package/document/em/index.d.ts +16 -0
  115. package/document/em/index.js +68 -0
  116. package/document/em/package.json +6 -0
  117. package/document/index.d.ts +2 -4
  118. package/document/index.js +2 -0
  119. package/document/package.json +6 -0
  120. package/document/{Document--sc.d.ts → sc/index.d.ts} +20 -11
  121. package/document/sc/index.js +44 -0
  122. package/document/sc/package.json +6 -0
  123. package/index.d.ts +12 -12
  124. package/index.js +12 -743
  125. package/node/Analytics/AnalyticsGoogle.js +42 -0
  126. package/node/Analytics/index.js +4 -0
  127. package/node/Auth/helpers.js +26 -0
  128. package/node/Auth/index.js +7 -0
  129. package/node/Auth/useLogin.js +54 -0
  130. package/node/Auth/useLoginUrl.js +15 -0
  131. package/node/Auth/useLogout.js +56 -0
  132. package/node/Favicon/Favicon.js +9 -0
  133. package/node/Favicon/index.js +4 -0
  134. package/node/Forms/index.js +5 -0
  135. package/node/Forms/useForm.js +41 -0
  136. package/node/Forms/useSubmit.js +27 -0
  137. package/node/Head/Head.js +8 -0
  138. package/node/Head/index.js +4 -0
  139. package/node/I18n/I18n.js +82 -0
  140. package/node/I18n/index.js +4 -0
  141. package/node/Img/Img.js +34 -0
  142. package/node/Img/index.js +4 -0
  143. package/node/Link/Link.js +13 -0
  144. package/node/Link/index.js +4 -0
  145. package/node/NextProgress/NextProgress.js +41 -0
  146. package/node/NextProgress/index.js +5 -0
  147. package/node/Seo/Seo.js +12 -0
  148. package/node/Seo/SeoDefaults.js +16 -0
  149. package/node/Seo/helpers.js +115 -0
  150. package/node/Seo/index.js +15 -0
  151. package/node/Theme/Theme.js +241 -0
  152. package/node/Theme/index.js +4 -0
  153. package/node/app/AppHead.js +10 -0
  154. package/node/app/AppMain.js +2 -0
  155. package/node/app/css/AppMain.js +16 -0
  156. package/node/app/css/AppTheme.js +16 -0
  157. package/node/app/css/auth/index.js +18 -0
  158. package/node/app/css/index.js +62 -0
  159. package/node/app/em/AppMain.js +26 -0
  160. package/node/app/em/AppTheme.js +22 -0
  161. package/node/app/em/auth/index.js +18 -0
  162. package/node/app/em/index.js +17 -0
  163. package/node/app/index.js +5 -0
  164. package/node/app/sc/AppMain.js +26 -0
  165. package/node/app/sc/AppTheme.js +13 -0
  166. package/node/app/sc/auth/index.js +18 -0
  167. package/node/app/sc/index.js +64 -0
  168. package/node/config/index.js +184 -0
  169. package/node/document/Document.js +24 -0
  170. package/node/document/css/index.js +35 -0
  171. package/node/document/em/index.js +73 -0
  172. package/node/document/index.js +7 -0
  173. package/node/document/sc/index.js +49 -0
  174. package/node/index.js +15 -0
  175. package/node/utils/api.js +38 -0
  176. package/node/utils/emotion-cache.js +13 -0
  177. package/node/utils/index.js +32 -0
  178. package/package.json +3 -30
  179. package/{types.d.ts → typings.d.ts} +10 -7
  180. package/utils/api.d.ts +55 -55
  181. package/utils/api.js +35 -0
  182. package/{document/emotion.d.ts → utils/emotion-cache.d.ts} +5 -5
  183. package/utils/emotion-cache.js +8 -0
  184. package/utils/index.d.ts +19 -19
  185. package/utils/index.js +26 -0
  186. package/utils/package.json +6 -0
  187. package/Theme.js +0 -1905
  188. package/_tslib.js +0 -41
  189. package/app/App--emotion.d.ts +0 -10
  190. package/app/App--sc.d.ts +0 -10
  191. package/app/App--vanilla.d.ts +0 -10
  192. package/app/AppAuth--emotion.d.ts +0 -10
  193. package/app/AppAuth--sc.d.ts +0 -10
  194. package/app/AppMain--vanilla.d.ts +0 -27
  195. package/app/AppTheme--sc.d.ts +0 -13
  196. package/app/AppTheme--vanilla.d.ts +0 -10
  197. package/app/motion-features.d.ts +0 -2
  198. package/app.js +0 -250
  199. package/config.js +0 -183
  200. package/document/Document--emotion.d.ts +0 -5
  201. package/document/Document--vanilla.d.ts +0 -11
  202. package/document.js +0 -207
  203. package/emotion.js +0 -1329
  204. package/es.object.assign.js +0 -1074
  205. package/es.string.replace.js +0 -785
  206. package/es.string.split.js +0 -201
  207. package/index.esm.js +0 -4600
  208. package/index.umd.js +0 -4638
  209. package/motion-features.js +0 -10
@@ -0,0 +1,18 @@
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;
@@ -0,0 +1,64 @@
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;
@@ -0,0 +1,184 @@
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;
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,35 @@
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;
@@ -0,0 +1,73 @@
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;
@@ -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,49 @@
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 ADDED
@@ -0,0 +1,15 @@
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);
@@ -0,0 +1,38 @@
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
+ }, {});
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,32 @@
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/package.json CHANGED
@@ -1,35 +1,8 @@
1
1
  {
2
+ "version": "1.0.9",
2
3
  "name": "@koine/next",
3
4
  "sideEffects": false,
4
- "exports": {
5
- ".": "./index.js",
6
- "./app": "./app.js",
7
- "./config": "./config.js",
8
- "./document": "./document.js"
9
- },
10
- "dependencies": {
11
- "@emotion/styled": "^11.8.1",
12
- "react": ">=17.0.2",
13
- "next": "^12.1.4",
14
- "@koine/utils": "1.0.4",
15
- "next-auth": "^4.3.1",
16
- "framer-motion": "^6.2.9",
17
- "@mui/material": "^5.6.0",
18
- "@emotion/react": "^11.9.0",
19
- "@koine/react": "1.0.4",
20
- "styled-components": "^5.3.5",
21
- "react-hook-form": "^7.29.0",
22
- "@emotion/server": "^11.4.0",
23
- "yup": "^0.32.11",
24
- "@hookform/resolvers": "^2.8.8",
25
- "react-use": "^17.3.2",
26
- "date-fns": "^2.28.0",
27
- "next-translate": "^1.4.0",
28
- "next-seo": "^5.4.0"
29
- },
30
- "version": "1.0.4",
31
- "main": "./index.umd.js",
32
- "module": "./index.esm.js",
5
+ "main": "./node/index.js",
33
6
  "typings": "./index.d.ts",
34
- "peerDependencies": {}
7
+ "module": "./index.js"
35
8
  }
@@ -63,15 +63,18 @@ declare namespace Koine {
63
63
  * type with something like:
64
64
  *
65
65
  * ```ts
66
- * "~": typeof import("./public/locales/en/~.json");
67
- * _: typeof import("./public/locales/en/_.json");
68
- * $team: typeof import("./public/locales/en/$team.json");
69
- * home: typeof import("./public/locales/en/home.json");
70
- * Footer: typeof import("./public/locales/en/Footer.json");
71
- * Header: typeof import("./public/locales/en/Header.json");
66
+ * declare namespace Koine {
67
+ * interface NextTranslations {
68
+ * "~": typeof import("./locales/en/~.json");
69
+ * _: typeof import("./locales/en/_.json");
70
+ * $team: typeof import("./locales/en/$team.json");
71
+ * home: typeof import("./locales/en/home.json");
72
+ * Footer: typeof import("./locales/en/Footer.json");
73
+ * Header: typeof import("./locales/en/Header.json");
74
+ * }
75
+ * }
72
76
  * ```
73
77
  */
74
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
75
78
  interface NextTranslations {
76
79
  /** Convention for app wide `common` translations */
77
80
  _: Record<string, string>;