@koine/next 1.0.0 → 1.0.3

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 (67) hide show
  1. package/Analytics/AnalyticsGoogle.d.ts +6 -0
  2. package/Analytics/index.d.ts +1 -0
  3. package/Auth/helpers.d.ts +17 -0
  4. package/Auth/index.d.ts +4 -0
  5. package/Auth/useLogin.d.ts +7 -0
  6. package/Auth/useLoginUrl.d.ts +1 -0
  7. package/Auth/useLogout.d.ts +6 -0
  8. package/Favicon/Favicon.d.ts +4 -0
  9. package/Favicon/index.d.ts +1 -0
  10. package/Forms/index.d.ts +2 -0
  11. package/Forms/useForm.d.ts +32 -0
  12. package/Forms/useSubmit.d.ts +24 -0
  13. package/Head/Head.d.ts +1 -0
  14. package/Head/index.d.ts +1 -0
  15. package/I18n/I18n.d.ts +48 -0
  16. package/I18n/index.d.ts +1 -0
  17. package/Img/Img.d.ts +21 -0
  18. package/Img/index.d.ts +1 -0
  19. package/Link/Link.d.ts +8 -0
  20. package/Link/index.d.ts +1 -0
  21. package/NextProgress/NextProgress.d.ts +14 -0
  22. package/NextProgress/index.d.ts +1 -0
  23. package/Seo/Seo.d.ts +3 -0
  24. package/Seo/SeoDefaults.d.ts +3 -0
  25. package/Seo/helpers.d.ts +48 -0
  26. package/Seo/index.d.ts +12 -0
  27. package/Theme/Theme.d.ts +46 -0
  28. package/Theme/index.d.ts +1 -0
  29. package/Theme.js +1905 -0
  30. package/_tslib.js +41 -0
  31. package/app/App--emotion.d.ts +10 -0
  32. package/app/App--sc.d.ts +10 -0
  33. package/app/App--vanilla.d.ts +10 -0
  34. package/app/AppAuth--emotion.d.ts +10 -0
  35. package/app/AppAuth--sc.d.ts +10 -0
  36. package/app/AppHead.d.ts +3 -0
  37. package/app/AppMain--vanilla.d.ts +27 -0
  38. package/app/AppMain.d.ts +34 -0
  39. package/app/AppTheme--emotion.d.ts +15 -0
  40. package/app/AppTheme--sc.d.ts +13 -0
  41. package/app/AppTheme--vanilla.d.ts +10 -0
  42. package/app/index.d.ts +11 -0
  43. package/app/motion-features.d.ts +2 -0
  44. package/app.js +250 -0
  45. package/config/index.d.ts +58 -0
  46. package/config.js +183 -0
  47. package/document/Document--emotion.d.ts +5 -0
  48. package/document/Document--sc.d.ts +11 -0
  49. package/document/Document--vanilla.d.ts +11 -0
  50. package/document/Document.d.ts +10 -0
  51. package/document/emotion.d.ts +5 -0
  52. package/document/index.d.ts +4 -0
  53. package/document.js +207 -0
  54. package/emotion.js +1329 -0
  55. package/es.object.assign.js +1074 -0
  56. package/es.string.replace.js +785 -0
  57. package/es.string.split.js +201 -0
  58. package/index.d.ts +12 -0
  59. package/index.esm.js +4437 -4406
  60. package/index.js +743 -0
  61. package/index.umd.js +4635 -4623
  62. package/motion-features.js +10 -0
  63. package/package.json +17 -10
  64. package/types.d.ts +91 -0
  65. package/utils/api.d.ts +55 -0
  66. package/utils/index.d.ts +19 -0
  67. package/motion-features.esm.js +0 -2
package/config.js ADDED
@@ -0,0 +1,183 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('./es.string.replace.js');
6
+ require('./es.string.split.js');
7
+ require('./es.object.assign.js');
8
+ var _tslib = require('./_tslib.js');
9
+
10
+ /**
11
+ * Normalise pathname
12
+ *
13
+ * From a path like `/some//malformed/path///` it returns `some/malformed/path`
14
+ *
15
+ * - Removes subsequent slashes
16
+ * - Removing initial and ending slashes
17
+ */
18
+
19
+ function normaliseUrlPathname(pathname) {
20
+ return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
21
+ }
22
+ /**
23
+ * Clean a pathname and encode each part
24
+ *
25
+ * @see {@link normaliseUrlPathname}
26
+ */
27
+
28
+ function encodePathname(pathname) {
29
+ const parts = normaliseUrlPathname(pathname).split("/");
30
+ return parts.filter(part => !!part).map(part => encodeURIComponent(part)).join("/");
31
+ }
32
+ /**
33
+ */
34
+
35
+ function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
36
+ const suffix = dynamic ? `/:slug*` : "";
37
+ return {
38
+ source: `/${locale}/${encodePathname(localisedPathname)}${suffix}`,
39
+ destination: `/${encodePathname(templateName)}${suffix}`,
40
+ permanent: Boolean(permanent),
41
+ locale: false
42
+ };
43
+ }
44
+ /**
45
+ */
46
+
47
+ function getPathRewrite(source, destination, dynamic) {
48
+ const suffix = dynamic ? `/:path*` : "";
49
+ return {
50
+ source: `/${encodePathname(source)}${suffix}`,
51
+ destination: `/${encodePathname(destination)}${suffix}`
52
+ };
53
+ }
54
+ /**
55
+ */
56
+
57
+ function getRedirects({
58
+ defaultLocale,
59
+ routes,
60
+ dynamicRoutes,
61
+ permanent
62
+ }) {
63
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
64
+ const redirects = [];
65
+ Object.keys(routes).forEach(page => {
66
+ const dynamic = dynamicRoutes[page];
67
+
68
+ if (routes[page] !== page) {
69
+ if (dynamic) {
70
+ redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
71
+ } else {
72
+ redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
73
+ }
74
+ }
75
+ }); // console.log("redirects", redirects);
76
+
77
+ return redirects;
78
+ });
79
+ }
80
+ /**
81
+ */
82
+
83
+ function getRewrites({
84
+ routes,
85
+ dynamicRoutes
86
+ }) {
87
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
88
+ const rewrites = [];
89
+ Object.keys(routes).forEach(page => {
90
+ const dynamic = dynamicRoutes[page];
91
+
92
+ if (routes[page] !== page) {
93
+ if (dynamic) {
94
+ rewrites.push(getPathRewrite(routes[page], page, true));
95
+ } else {
96
+ rewrites.push(getPathRewrite(routes[page], page));
97
+ }
98
+ }
99
+ }); // console.log("rewrites", rewrites);
100
+
101
+ return rewrites;
102
+ });
103
+ }
104
+ /**
105
+ * Get Next.js config with some basic opinionated defaults
106
+ */
107
+
108
+ function withKoine(_a = {}) {
109
+ var {
110
+ nx = true,
111
+ svg = true,
112
+ sc = true
113
+ } = _a,
114
+ nextConfig = _tslib.__rest(_a, ["nx", "svg", "sc"]);
115
+
116
+ nextConfig = Object.assign({
117
+ // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
118
+ pageExtensions: ["page.tsx", "page.ts"],
119
+ eslint: {
120
+ ignoreDuringBuilds: true // we have this strict check on each commit
121
+
122
+ },
123
+ typescript: {
124
+ ignoreBuildErrors: true // we have this strict check on each commit
125
+
126
+ },
127
+ poweredByHeader: false,
128
+ swcMinify: true,
129
+ experimental: Object.assign({
130
+ // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
131
+ // @see critters error https://github.com/vercel/next.js/issues/20742
132
+ // optimizeCss: true,
133
+ // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
134
+ scrollRestoration: true
135
+ }, nextConfig.experimental || {})
136
+ }, nextConfig);
137
+
138
+ if (svg) {
139
+ if (nx) {
140
+ // @see https://github.com/gregberge/svgr
141
+ nextConfig["nx"] = {
142
+ svgr: true
143
+ };
144
+ } else {
145
+ nextConfig.webpack = (_config, options) => {
146
+ const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config; // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
147
+
148
+ webpackConfig.module.rules.push({
149
+ test: /\.svg$/,
150
+ use: [{
151
+ loader: "@svgr/webpack",
152
+ options: {
153
+ svgoConfig: {
154
+ plugins: [{
155
+ name: "removeViewBox",
156
+ active: false
157
+ }]
158
+ }
159
+ }
160
+ }]
161
+ });
162
+ return webpackConfig;
163
+ };
164
+ }
165
+ }
166
+
167
+ if (sc) {
168
+ nextConfig.compiler = {
169
+ styledComponents: true
170
+ };
171
+ }
172
+
173
+ return nextConfig;
174
+ }
175
+
176
+ exports["default"] = withKoine;
177
+ exports.encodePathname = encodePathname;
178
+ exports.getPathRedirect = getPathRedirect;
179
+ exports.getPathRewrite = getPathRewrite;
180
+ exports.getRedirects = getRedirects;
181
+ exports.getRewrites = getRewrites;
182
+ exports.normaliseUrlPathname = normaliseUrlPathname;
183
+ exports.withKoine = withKoine;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import Document from "next/document";
3
+ export declare class DocumentEmotion extends Document {
4
+ render(): JSX.Element;
5
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
3
+ /**
4
+ * For typescript safety of this component
5
+ *
6
+ * @see https://bit.ly/3ceuF8m
7
+ */
8
+ export declare class DocumentSc extends NextDocument {
9
+ static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps>;
10
+ render(): JSX.Element;
11
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
3
+ import { ThemeVanillaValue } from "@koine/react";
4
+ /**
5
+ */
6
+ export declare class DocumentVanilla extends NextDocument {
7
+ static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps & {
8
+ theme: ThemeVanillaValue;
9
+ }>;
10
+ render(): JSX.Element;
11
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import NextDocument from "next/document";
3
+ /**
4
+ * For typescript safety of this component
5
+ *
6
+ * @see https://bit.ly/3ceuF8m
7
+ */
8
+ export declare class Document extends NextDocument {
9
+ render(): JSX.Element;
10
+ }
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,4 @@
1
+ export * from "./Document";
2
+ export * from "./Document--emotion";
3
+ export * from "./Document--sc";
4
+ export * from "./Document--vanilla";
package/document.js ADDED
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('./es.object.assign.js');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var NextDocument = require('next/document');
8
+ var react = require('@koine/react');
9
+ var _tslib = require('./_tslib.js');
10
+ var createEmotionServer = require('@emotion/server/create-instance');
11
+ var emotion = require('./emotion.js');
12
+ var styledComponents = require('styled-components');
13
+
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var NextDocument__default = /*#__PURE__*/_interopDefaultLegacy(NextDocument);
17
+ var createEmotionServer__default = /*#__PURE__*/_interopDefaultLegacy(createEmotionServer);
18
+
19
+ /**
20
+ * For typescript safety of this component
21
+ *
22
+ * @see https://bit.ly/3ceuF8m
23
+ */
24
+
25
+ class Document extends NextDocument__default["default"] {
26
+ render() {
27
+ const {
28
+ locale,
29
+ defaultLocale
30
+ } = this.props.__NEXT_DATA__;
31
+ return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
32
+ lang: locale || defaultLocale,
33
+ className: "no-js"
34
+ }, {
35
+ children: [jsxRuntime.jsxs(NextDocument.Head, {
36
+ children: [jsxRuntime.jsx(react.Meta, {}), jsxRuntime.jsx(react.NoJs, {})]
37
+ }), jsxRuntime.jsxs("body", {
38
+ children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
39
+ })]
40
+ }));
41
+ }
42
+
43
+ }
44
+
45
+ class DocumentEmotion extends NextDocument__default["default"] {
46
+ render() {
47
+ const {
48
+ locale,
49
+ defaultLocale
50
+ } = this.props.__NEXT_DATA__;
51
+ return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
52
+ lang: locale || defaultLocale,
53
+ className: "no-js"
54
+ }, {
55
+ children: [jsxRuntime.jsxs(NextDocument.Head, {
56
+ children: [jsxRuntime.jsx(react.NoJs, {}), this.props.emotionStyleTags]
57
+ }), jsxRuntime.jsxs("body", {
58
+ children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
59
+ })]
60
+ }));
61
+ }
62
+
63
+ } // `getInitialProps` belongs to `_document` (instead of `_app`),
64
+ // it's compatible with static-site generation (SSG).
65
+
66
+ DocumentEmotion.getInitialProps = ctx => _tslib.__awaiter(void 0, void 0, void 0, function* () {
67
+ // Resolution order
68
+ //
69
+ // On the server:
70
+ // 1. app.getInitialProps
71
+ // 2. page.getInitialProps
72
+ // 3. document.getInitialProps
73
+ // 4. app.render
74
+ // 5. page.render
75
+ // 6. document.render
76
+ //
77
+ // On the server with error:
78
+ // 1. document.getInitialProps
79
+ // 2. app.render
80
+ // 3. page.render
81
+ // 4. document.render
82
+ //
83
+ // On the client
84
+ // 1. app.getInitialProps
85
+ // 2. page.getInitialProps
86
+ // 3. app.render
87
+ // 4. page.render
88
+ const originalRenderPage = ctx.renderPage; // You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
89
+ // However, be aware that it can have global side effects.
90
+
91
+ const cache = emotion.createEmotionCache();
92
+ const {
93
+ extractCriticalToChunks
94
+ } = createEmotionServer__default["default"](cache);
95
+
96
+ ctx.renderPage = () => originalRenderPage({
97
+ enhanceApp: App => function EnhanceApp(props) {
98
+ return jsxRuntime.jsx(App, Object.assign({
99
+ emotionCache: cache
100
+ }, props));
101
+ }
102
+ });
103
+
104
+ const initialProps = yield NextDocument__default["default"].getInitialProps(ctx); // This is important. It prevents emotion to render invalid HTML.
105
+ // See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
106
+
107
+ const emotionStyles = extractCriticalToChunks(initialProps.html);
108
+ const emotionStyleTags = emotionStyles.styles.map(style => jsxRuntime.jsx("style", {
109
+ "data-emotion": `${style.key} ${style.ids.join(" ")}`,
110
+ // eslint-disable-next-line react/no-danger
111
+ dangerouslySetInnerHTML: {
112
+ __html: style.css
113
+ }
114
+ }, style.key));
115
+ return Object.assign(Object.assign({}, initialProps), {
116
+ emotionStyleTags
117
+ });
118
+ });
119
+
120
+ /**
121
+ * For typescript safety of this component
122
+ *
123
+ * @see https://bit.ly/3ceuF8m
124
+ */
125
+
126
+ class DocumentSc extends NextDocument__default["default"] {
127
+ static getInitialProps(ctx) {
128
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
129
+ const sheet = new styledComponents.ServerStyleSheet();
130
+ const originalRenderPage = ctx.renderPage;
131
+
132
+ try {
133
+ ctx.renderPage = () => originalRenderPage({
134
+ enhanceApp: App => props => sheet.collectStyles(jsxRuntime.jsx(App, Object.assign({}, props)))
135
+ });
136
+
137
+ const initialProps = yield NextDocument__default["default"].getInitialProps(ctx);
138
+ return Object.assign(Object.assign({}, initialProps), {
139
+ styles: jsxRuntime.jsxs(jsxRuntime.Fragment, {
140
+ children: [initialProps.styles, sheet.getStyleElement()]
141
+ })
142
+ });
143
+ } finally {
144
+ sheet.seal();
145
+ }
146
+ });
147
+ }
148
+
149
+ render() {
150
+ const {
151
+ locale,
152
+ defaultLocale
153
+ } = this.props.__NEXT_DATA__;
154
+ return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
155
+ lang: locale || defaultLocale,
156
+ className: "no-js"
157
+ }, {
158
+ children: [jsxRuntime.jsxs(NextDocument.Head, {
159
+ children: [jsxRuntime.jsx(react.Meta, {}), jsxRuntime.jsx(react.NoJs, {})]
160
+ }), jsxRuntime.jsxs("body", {
161
+ children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
162
+ })]
163
+ }));
164
+ }
165
+
166
+ }
167
+
168
+ /**
169
+ */
170
+
171
+ class DocumentVanilla extends NextDocument__default["default"] {
172
+ static getInitialProps(ctx) {
173
+ var _a;
174
+
175
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
176
+ const initialProps = yield NextDocument__default["default"].getInitialProps(ctx);
177
+ return Object.assign(Object.assign({}, initialProps), {
178
+ theme: react.getInitialThemeFromRequest(((_a = ctx.req) === null || _a === void 0 ? void 0 : _a.headers.cookie
179
+ /* || document?.cookie */
180
+ ) || "")
181
+ });
182
+ });
183
+ }
184
+
185
+ render() {
186
+ const {
187
+ locale,
188
+ defaultLocale
189
+ } = this.props.__NEXT_DATA__;
190
+ return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
191
+ lang: locale || defaultLocale,
192
+ className: "no-js"
193
+ }, {
194
+ children: [jsxRuntime.jsxs(NextDocument.Head, {
195
+ children: [jsxRuntime.jsx(react.Meta, {}), jsxRuntime.jsx(react.NoJs, {})]
196
+ }), jsxRuntime.jsxs("body", {
197
+ children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
198
+ })]
199
+ }));
200
+ }
201
+
202
+ }
203
+
204
+ exports.Document = Document;
205
+ exports.DocumentEmotion = DocumentEmotion;
206
+ exports.DocumentSc = DocumentSc;
207
+ exports.DocumentVanilla = DocumentVanilla;