@koine/next 1.0.10 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Analytics/AnalyticsGoogle.d.ts +5 -0
- package/Analytics/AnalyticsGoogle.js +33 -0
- package/Analytics/index.d.ts +1 -0
- package/Analytics/index.js +1 -0
- package/Analytics/package.json +6 -0
- package/Auth/helpers.d.ts +17 -0
- package/Auth/helpers.js +22 -0
- package/Auth/index.d.ts +4 -0
- package/Auth/index.js +4 -0
- package/Auth/package.json +6 -0
- package/Auth/useLogin.d.ts +7 -0
- package/Auth/useLogin.js +49 -0
- package/Auth/useLoginUrl.d.ts +1 -0
- package/Auth/useLoginUrl.js +11 -0
- package/Auth/useLogout.d.ts +6 -0
- package/Auth/useLogout.js +52 -0
- package/Favicon/Favicon.d.ts +3 -0
- package/Favicon/Favicon.js +5 -0
- package/Favicon/index.d.ts +1 -0
- package/Favicon/index.js +1 -0
- package/Favicon/package.json +6 -0
- package/Forms/index.d.ts +2 -0
- package/Forms/index.js +2 -0
- package/Forms/package.json +6 -0
- package/Forms/useForm.d.ts +32 -0
- package/Forms/useForm.js +35 -0
- package/Forms/useSubmit.d.ts +24 -0
- package/Forms/useSubmit.js +28 -0
- package/Head/Head.d.ts +1 -0
- package/Head/Head.js +1 -0
- package/Head/index.d.ts +1 -0
- package/Head/index.js +1 -0
- package/Head/package.json +6 -0
- package/I18n/I18n.d.ts +44 -0
- package/I18n/I18n.js +95 -0
- package/I18n/index.d.ts +1 -0
- package/I18n/index.js +1 -0
- package/I18n/package.json +6 -0
- package/Img/Img.d.ts +21 -0
- package/Img/Img.js +30 -0
- package/Img/index.d.ts +1 -0
- package/Img/index.js +1 -0
- package/Img/package.json +6 -0
- package/Link/Link.d.ts +9 -0
- package/Link/Link.js +11 -0
- package/Link/index.d.ts +1 -0
- package/Link/index.js +1 -0
- package/Link/package.json +6 -0
- package/NextProgress/NextProgress.d.ts +24 -0
- package/NextProgress/NextProgress.js +40 -0
- package/NextProgress/index.d.ts +2 -0
- package/NextProgress/index.js +1 -0
- package/NextProgress/package.json +6 -0
- package/Seo/Seo.d.ts +3 -0
- package/Seo/Seo.js +8 -0
- package/Seo/SeoDefaults.d.ts +3 -0
- package/Seo/SeoDefaults.js +12 -0
- package/Seo/helpers.d.ts +48 -0
- package/Seo/helpers.js +115 -0
- package/Seo/index.d.ts +12 -0
- package/Seo/index.js +12 -0
- package/Seo/package.json +6 -0
- package/Theme/Theme.d.ts +46 -0
- package/Theme/Theme.js +245 -0
- package/Theme/index.d.ts +1 -0
- package/Theme/index.js +1 -0
- package/Theme/package.json +6 -0
- package/app/AppHead.d.ts +2 -0
- package/app/AppHead.js +5 -0
- package/app/AppMain.d.ts +35 -0
- package/app/AppMain.js +1 -0
- package/app/css/AppMain.d.ts +8 -0
- package/app/css/AppMain.js +13 -0
- package/app/css/AppTheme.d.ts +10 -0
- package/app/css/AppTheme.js +14 -0
- package/app/css/auth/index.d.ts +9 -0
- package/app/css/auth/index.js +14 -0
- package/app/css/auth/package.json +6 -0
- package/app/css/index.d.ts +54 -0
- package/app/css/index.js +58 -0
- package/app/css/package.json +6 -0
- package/app/em/AppMain.d.ts +10 -0
- package/app/em/AppMain.js +24 -0
- package/app/em/AppTheme.d.ts +15 -0
- package/app/em/AppTheme.js +18 -0
- package/app/em/auth/index.d.ts +9 -0
- package/app/em/auth/index.js +14 -0
- package/app/em/auth/package.json +6 -0
- package/app/em/index.d.ts +9 -0
- package/app/em/index.js +13 -0
- package/app/em/package.json +6 -0
- package/app/index.d.ts +2 -0
- package/app/index.js +2 -0
- package/app/package.json +6 -0
- package/app/sc/AppMain.d.ts +10 -0
- package/app/sc/AppMain.js +24 -0
- package/app/sc/AppTheme.d.ts +13 -0
- package/app/sc/AppTheme.js +11 -0
- package/app/sc/auth/index.d.ts +9 -0
- package/app/sc/auth/index.js +14 -0
- package/app/sc/auth/package.json +6 -0
- package/app/sc/index.d.ts +56 -0
- package/app/sc/index.js +60 -0
- package/app/sc/package.json +6 -0
- package/config/index.d.ts +84 -0
- package/config/index.js +190 -0
- package/config/package.json +6 -0
- package/document/Document.d.ts +15 -0
- package/document/Document.js +26 -0
- package/document/css/index.d.ts +22 -0
- package/document/css/index.js +44 -0
- package/document/css/package.json +6 -0
- package/document/em/index.d.ts +16 -0
- package/document/em/index.js +59 -0
- package/document/em/package.json +6 -0
- package/document/index.d.ts +2 -0
- package/document/index.js +2 -0
- package/document/package.json +6 -0
- package/document/sc/index.d.ts +20 -0
- package/document/sc/index.js +65 -0
- package/document/sc/package.json +6 -0
- package/index.d.ts +12 -0
- package/index.js +12 -0
- package/package.json +11 -13
- package/utils/api.d.ts +55 -0
- package/utils/api.js +44 -0
- package/utils/emotion-cache.d.ts +5 -0
- package/utils/emotion-cache.js +8 -0
- package/utils/index.d.ts +19 -0
- package/utils/index.js +27 -0
- package/utils/package.json +6 -0
package/app/index.d.ts
ADDED
package/app/index.js
ADDED
package/app/package.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppMainBaseProps, AppMainFramerProps } from "../AppMain";
|
|
2
|
+
export declare type AppMainProps = AppMainBaseProps & AppMainFramerProps;
|
|
3
|
+
/**
|
|
4
|
+
* App main
|
|
5
|
+
*
|
|
6
|
+
* It implies a setup for `styled-components` and `framer-motion` libraries.
|
|
7
|
+
*
|
|
8
|
+
* About the page transition [wallis' blog post](https://wallis.dev/blog/nextjs-page-transitions-with-framer-motion)
|
|
9
|
+
*/
|
|
10
|
+
export declare const AppMain: ({ Component, pageProps, Layout, ProgressOverlay, seo, motion, transition, pre, post, }: AppMainProps) => JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
|
+
import { useRouter } from "next/router";
|
|
5
|
+
import { AnimatePresence, m } from "framer-motion";
|
|
6
|
+
import { MotionProvider } from "@koine/react/m";
|
|
7
|
+
import { SeoDefaults } from "../../Seo";
|
|
8
|
+
import { NextProgress } from "../../NextProgress";
|
|
9
|
+
/**
|
|
10
|
+
* App main
|
|
11
|
+
*
|
|
12
|
+
* It implies a setup for `styled-components` and `framer-motion` libraries.
|
|
13
|
+
*
|
|
14
|
+
* About the page transition [wallis' blog post](https://wallis.dev/blog/nextjs-page-transitions-with-framer-motion)
|
|
15
|
+
*/
|
|
16
|
+
export var AppMain = function (_a) {
|
|
17
|
+
var Component = _a.Component, pageProps = _a.pageProps, Layout = _a.Layout, ProgressOverlay = _a.ProgressOverlay, seo = _a.seo, motion = _a.motion, _b = _a.transition, transition = _b === void 0 ? {
|
|
18
|
+
initial: { opacity: 0 },
|
|
19
|
+
animate: { opacity: 1 },
|
|
20
|
+
exit: { opacity: 0 },
|
|
21
|
+
} : _b, pre = _a.pre, post = _a.post;
|
|
22
|
+
var pathname = useRouter().pathname;
|
|
23
|
+
return (_jsxs(_Fragment, { children: [_jsx(SeoDefaults, __assign({}, seo)), pre, _jsxs(MotionProvider, __assign({ features: motion }, { children: [ProgressOverlay && _jsx(NextProgress, { Overlay: ProgressOverlay }), _jsx(Layout, { children: _jsx(AnimatePresence, __assign({ exitBeforeEnter: true, initial: false }, { children: _jsx(m.div, __assign({}, transition, { children: _createElement(Component, __assign({}, pageProps, { key: pathname })) }), pathname) })) })] })), post] }));
|
|
24
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
+
import { Theme } from "@koine/react/sc";
|
|
4
|
+
export declare type AppThemeProps = React.PropsWithChildren<NextAppProps & {
|
|
5
|
+
/**
|
|
6
|
+
* A theme object
|
|
7
|
+
*/
|
|
8
|
+
theme: Theme;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* App theme with `styled-components`
|
|
12
|
+
*/
|
|
13
|
+
export declare const AppTheme: ({ theme, children }: AppThemeProps) => JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { StylesGlobal } from "@koine/react/sc";
|
|
5
|
+
/**
|
|
6
|
+
* App theme with `styled-components`
|
|
7
|
+
*/
|
|
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] })));
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AppProps } from "next/app";
|
|
2
|
+
import { AppThemeProps } from "../AppTheme";
|
|
3
|
+
import { AppMainProps } from "../AppMain";
|
|
4
|
+
export declare type NextAppProps = AppProps & AppThemeProps & AppMainProps;
|
|
5
|
+
/**
|
|
6
|
+
* App with authentication provided by `next-auth`
|
|
7
|
+
*/
|
|
8
|
+
export declare const NextApp: (props: NextAppProps) => JSX.Element;
|
|
9
|
+
export default NextApp;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { SessionProvider } from "next-auth/react";
|
|
5
|
+
import { AppHead } from "../../AppHead";
|
|
6
|
+
import { AppTheme } from "../AppTheme";
|
|
7
|
+
import { AppMain } from "../AppMain";
|
|
8
|
+
/**
|
|
9
|
+
* App with authentication provided by `next-auth`
|
|
10
|
+
*/
|
|
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)) })) }))] }));
|
|
13
|
+
};
|
|
14
|
+
export default NextApp;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AppProps } from "next/app";
|
|
2
|
+
import { AppThemeProps } from "./AppTheme";
|
|
3
|
+
import { AppMainProps } from "./AppMain";
|
|
4
|
+
export declare type NextAppProps = AppProps & AppThemeProps & AppMainProps;
|
|
5
|
+
/**
|
|
6
|
+
* App
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { NextApp, NextAppProps } from "@koine/next/app/sc/auth";
|
|
12
|
+
* import { Favicon, AnalyticsGoogle } from "@koine/next";
|
|
13
|
+
* import { theme } from "src/helpers/theme";
|
|
14
|
+
* import { Layout, ProgressOverlay } from "src/components/Layout";
|
|
15
|
+
* // import "@fontsource/myfont/800.css";
|
|
16
|
+
* // import "src/helpers/theme.css";
|
|
17
|
+
*
|
|
18
|
+
* const motion = () => import("@koine/react/m/max").then((m) => m.default);
|
|
19
|
+
*
|
|
20
|
+
* export default function App(props: NextAppProps) {
|
|
21
|
+
* return (
|
|
22
|
+
* <NextApp
|
|
23
|
+
* {...props}
|
|
24
|
+
* Layout={Layout}
|
|
25
|
+
* ProgressOverlay={ProgressOverlay}
|
|
26
|
+
* theme={theme}
|
|
27
|
+
* motion={motion}
|
|
28
|
+
* seo={{
|
|
29
|
+
* titleTemplate: "%s | MyApp",
|
|
30
|
+
* defaultTitle: "MyApp",
|
|
31
|
+
* openGraph: {
|
|
32
|
+
* type: "website",
|
|
33
|
+
* locale: "en_US",
|
|
34
|
+
* url: "https://myapp.com/",
|
|
35
|
+
* site_name: "MyApp",
|
|
36
|
+
* },
|
|
37
|
+
* twitter: {
|
|
38
|
+
* handle: "@MklrNl",
|
|
39
|
+
* site: "@MyApp",
|
|
40
|
+
* cardType: "summary_large_image",
|
|
41
|
+
* },
|
|
42
|
+
* }}
|
|
43
|
+
* pre={
|
|
44
|
+
* <>
|
|
45
|
+
* <AnalyticsGoogle id="UA-xxxxxxxx-x" />
|
|
46
|
+
* <Favicon name="MyApp" color="#000000" />
|
|
47
|
+
* </>
|
|
48
|
+
* }
|
|
49
|
+
* />
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const NextApp: (props: NextAppProps) => JSX.Element;
|
|
56
|
+
export default NextApp;
|
package/app/sc/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { AppHead } from "../AppHead";
|
|
5
|
+
import { AppTheme } from "./AppTheme";
|
|
6
|
+
import { AppMain } from "./AppMain";
|
|
7
|
+
/**
|
|
8
|
+
* App
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { NextApp, NextAppProps } from "@koine/next/app/sc/auth";
|
|
14
|
+
* import { Favicon, AnalyticsGoogle } from "@koine/next";
|
|
15
|
+
* import { theme } from "src/helpers/theme";
|
|
16
|
+
* import { Layout, ProgressOverlay } from "src/components/Layout";
|
|
17
|
+
* // import "@fontsource/myfont/800.css";
|
|
18
|
+
* // import "src/helpers/theme.css";
|
|
19
|
+
*
|
|
20
|
+
* const motion = () => import("@koine/react/m/max").then((m) => m.default);
|
|
21
|
+
*
|
|
22
|
+
* export default function App(props: NextAppProps) {
|
|
23
|
+
* return (
|
|
24
|
+
* <NextApp
|
|
25
|
+
* {...props}
|
|
26
|
+
* Layout={Layout}
|
|
27
|
+
* ProgressOverlay={ProgressOverlay}
|
|
28
|
+
* theme={theme}
|
|
29
|
+
* motion={motion}
|
|
30
|
+
* seo={{
|
|
31
|
+
* titleTemplate: "%s | MyApp",
|
|
32
|
+
* defaultTitle: "MyApp",
|
|
33
|
+
* openGraph: {
|
|
34
|
+
* type: "website",
|
|
35
|
+
* locale: "en_US",
|
|
36
|
+
* url: "https://myapp.com/",
|
|
37
|
+
* site_name: "MyApp",
|
|
38
|
+
* },
|
|
39
|
+
* twitter: {
|
|
40
|
+
* handle: "@MklrNl",
|
|
41
|
+
* site: "@MyApp",
|
|
42
|
+
* cardType: "summary_large_image",
|
|
43
|
+
* },
|
|
44
|
+
* }}
|
|
45
|
+
* pre={
|
|
46
|
+
* <>
|
|
47
|
+
* <AnalyticsGoogle id="UA-xxxxxxxx-x" />
|
|
48
|
+
* <Favicon name="MyApp" color="#000000" />
|
|
49
|
+
* </>
|
|
50
|
+
* }
|
|
51
|
+
* />
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export var NextApp = function (props) {
|
|
58
|
+
return (_jsxs(React.StrictMode, { children: [_jsx(AppHead, {}), _jsx(AppTheme, __assign({}, props, { children: _jsx(AppMain, __assign({}, props)) }))] }));
|
|
59
|
+
};
|
|
60
|
+
export default NextApp;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { NextConfig } from "next";
|
|
2
|
+
import type { Redirect, Rewrite } from "next/dist/lib/load-custom-routes";
|
|
3
|
+
/**
|
|
4
|
+
* Transform to path any absolute or relative URL
|
|
5
|
+
*
|
|
6
|
+
* Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
|
|
7
|
+
* setup](https://nextjs.org/docs/advanced-features/multi-zones).
|
|
8
|
+
*
|
|
9
|
+
* From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
|
|
10
|
+
*
|
|
11
|
+
* - just get the pathname form an absolute URL (if that is given)
|
|
12
|
+
* - Removes subsequent slashes
|
|
13
|
+
* - Removing initial and ending slashes
|
|
14
|
+
*/
|
|
15
|
+
export declare function toPath(urlOrPathname?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Normalise pathname
|
|
18
|
+
*
|
|
19
|
+
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
20
|
+
*
|
|
21
|
+
* - Removes subsequent slashes
|
|
22
|
+
* - Removing initial and ending slashes
|
|
23
|
+
*/
|
|
24
|
+
export declare function normaliseUrlPathname(pathname: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Clean a pathname and encode each part
|
|
27
|
+
*
|
|
28
|
+
* @see {@link normaliseUrlPathname}
|
|
29
|
+
*/
|
|
30
|
+
export declare function encodePathname(pathname: string): string;
|
|
31
|
+
/**
|
|
32
|
+
*/
|
|
33
|
+
export declare function getPathRedirect(locale: string, localisedPathname: string, templateName: string, dynamic?: boolean, permanent?: boolean): {
|
|
34
|
+
source: string;
|
|
35
|
+
destination: string;
|
|
36
|
+
permanent: boolean;
|
|
37
|
+
locale: false;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
*/
|
|
41
|
+
export declare function getPathRewrite(source: string, destination: string, dynamic?: boolean): {
|
|
42
|
+
source: string;
|
|
43
|
+
destination: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
*/
|
|
47
|
+
export declare function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }: {
|
|
48
|
+
defaultLocale: string;
|
|
49
|
+
routes: Record<string, string>;
|
|
50
|
+
dynamicRoutes: Record<string, boolean>;
|
|
51
|
+
permanent?: boolean;
|
|
52
|
+
}): Promise<Redirect[]>;
|
|
53
|
+
/**
|
|
54
|
+
*/
|
|
55
|
+
export declare function getRewrites({ routes, dynamicRoutes, }: {
|
|
56
|
+
routes: Record<string, string>;
|
|
57
|
+
dynamicRoutes: Record<string, boolean>;
|
|
58
|
+
}): Promise<Rewrite[]>;
|
|
59
|
+
declare type KoineNextConfig = {
|
|
60
|
+
/** @default true Nx monorepo setup */
|
|
61
|
+
nx?: boolean;
|
|
62
|
+
/** @default true Svg to react components */
|
|
63
|
+
svg?: boolean;
|
|
64
|
+
/** @default true Styled components enabled */
|
|
65
|
+
sc?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* When true uses `*.page.ts` or `*.page.tsx` 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). When `true` it enables the same for `next-translate`
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
page?: boolean;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Get Next.js config with some basic opinionated defaults
|
|
74
|
+
*
|
|
75
|
+
* @param {object} options
|
|
76
|
+
* @property {boolean} [options.nx=false] Nx monorepo setup
|
|
77
|
+
* @property {boolean} [options.svg=false] Svg to react components
|
|
78
|
+
* @property {boolean} [options.sc=false] Styled components enabled
|
|
79
|
+
* @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
|
|
80
|
+
* 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)
|
|
81
|
+
* and it enables the same for `next-translate`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function withKoine({ nx, svg, sc, page, ...nextConfig }?: NextConfig & KoineNextConfig): NextConfig;
|
|
84
|
+
export default withKoine;
|
package/config/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator, __rest } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Transform to path any absolute or relative URL
|
|
4
|
+
*
|
|
5
|
+
* Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
|
|
6
|
+
* setup](https://nextjs.org/docs/advanced-features/multi-zones).
|
|
7
|
+
*
|
|
8
|
+
* From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
|
|
9
|
+
*
|
|
10
|
+
* - just get the pathname form an absolute URL (if that is given)
|
|
11
|
+
* - Removes subsequent slashes
|
|
12
|
+
* - Removing initial and ending slashes
|
|
13
|
+
*/
|
|
14
|
+
export function toPath(urlOrPathname) {
|
|
15
|
+
if (urlOrPathname === void 0) { urlOrPathname = ""; }
|
|
16
|
+
var pathname = "";
|
|
17
|
+
try {
|
|
18
|
+
var parsed = new URL(urlOrPathname);
|
|
19
|
+
pathname = parsed.pathname;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
pathname = urlOrPathname;
|
|
23
|
+
}
|
|
24
|
+
return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalise pathname
|
|
28
|
+
*
|
|
29
|
+
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
30
|
+
*
|
|
31
|
+
* - Removes subsequent slashes
|
|
32
|
+
* - Removing initial and ending slashes
|
|
33
|
+
*/
|
|
34
|
+
export function normaliseUrlPathname(pathname) {
|
|
35
|
+
return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Clean a pathname and encode each part
|
|
39
|
+
*
|
|
40
|
+
* @see {@link normaliseUrlPathname}
|
|
41
|
+
*/
|
|
42
|
+
export function encodePathname(pathname) {
|
|
43
|
+
var parts = normaliseUrlPathname(pathname).split("/");
|
|
44
|
+
return parts
|
|
45
|
+
.filter(function (part) { return !!part; })
|
|
46
|
+
.map(function (part) { return encodeURIComponent(part); })
|
|
47
|
+
.join("/");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
*/
|
|
51
|
+
export function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
|
|
52
|
+
var suffix = dynamic ? "/:slug*" : "";
|
|
53
|
+
return {
|
|
54
|
+
source: "/".concat(locale, "/").concat(encodePathname(localisedPathname)).concat(suffix),
|
|
55
|
+
destination: "/".concat(encodePathname(templateName)).concat(suffix),
|
|
56
|
+
permanent: Boolean(permanent),
|
|
57
|
+
locale: false,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
*/
|
|
62
|
+
export function getPathRewrite(source, destination, dynamic) {
|
|
63
|
+
var suffix = dynamic ? "/:path*" : "";
|
|
64
|
+
return {
|
|
65
|
+
source: "/".concat(encodePathname(source)).concat(suffix),
|
|
66
|
+
destination: "/".concat(encodePathname(destination)).concat(suffix),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
*/
|
|
71
|
+
export function getRedirects(_a) {
|
|
72
|
+
var defaultLocale = _a.defaultLocale, routes = _a.routes, dynamicRoutes = _a.dynamicRoutes, permanent = _a.permanent;
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
var redirects;
|
|
75
|
+
return __generator(this, function (_b) {
|
|
76
|
+
redirects = [];
|
|
77
|
+
Object.keys(routes).forEach(function (page) {
|
|
78
|
+
var dynamic = dynamicRoutes[page];
|
|
79
|
+
if (routes[page] !== page) {
|
|
80
|
+
if (dynamic) {
|
|
81
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
// console.log("redirects", redirects);
|
|
89
|
+
return [2 /*return*/, redirects];
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
*/
|
|
95
|
+
export function getRewrites(_a) {
|
|
96
|
+
var routes = _a.routes, dynamicRoutes = _a.dynamicRoutes;
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var rewrites;
|
|
99
|
+
return __generator(this, function (_b) {
|
|
100
|
+
rewrites = [];
|
|
101
|
+
Object.keys(routes).forEach(function (page) {
|
|
102
|
+
var dynamic = dynamicRoutes[page];
|
|
103
|
+
if (routes[page] !== page) {
|
|
104
|
+
if (dynamic) {
|
|
105
|
+
rewrites.push(getPathRewrite(routes[page], page, true));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
rewrites.push(getPathRewrite(routes[page], page));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
// console.log("rewrites", rewrites);
|
|
113
|
+
return [2 /*return*/, rewrites];
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get Next.js config with some basic opinionated defaults
|
|
119
|
+
*
|
|
120
|
+
* @param {object} options
|
|
121
|
+
* @property {boolean} [options.nx=false] Nx monorepo setup
|
|
122
|
+
* @property {boolean} [options.svg=false] Svg to react components
|
|
123
|
+
* @property {boolean} [options.sc=false] Styled components enabled
|
|
124
|
+
* @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
|
|
125
|
+
* 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)
|
|
126
|
+
* and it enables the same for `next-translate`.
|
|
127
|
+
*/
|
|
128
|
+
export function withKoine(_a) {
|
|
129
|
+
var _b;
|
|
130
|
+
if (_a === void 0) { _a = {}; }
|
|
131
|
+
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"]);
|
|
132
|
+
nextConfig = __assign({
|
|
133
|
+
// @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
|
|
134
|
+
pageExtensions: page ? ["page.tsx", "page.ts"] : undefined, eslint: {
|
|
135
|
+
ignoreDuringBuilds: true, // we have this strict check on each commit
|
|
136
|
+
}, typescript: {
|
|
137
|
+
ignoreBuildErrors: true, // we have this strict check on each commit
|
|
138
|
+
}, poweredByHeader: false, swcMinify: true, experimental: __assign(__assign({
|
|
139
|
+
// @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
|
|
140
|
+
// @see critters error https://github.com/vercel/next.js/issues/20742
|
|
141
|
+
// optimizeCss: true,
|
|
142
|
+
// @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
|
|
143
|
+
scrollRestoration: true }, (nextConfig.experimental || {})), {
|
|
144
|
+
// @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
|
|
145
|
+
modularizeImports: __assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }),
|
|
146
|
+
// @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
|
|
147
|
+
reactStrictMode: true }, nextConfig);
|
|
148
|
+
if (svg) {
|
|
149
|
+
if (nx) {
|
|
150
|
+
// @see https://github.com/gregberge/svgr
|
|
151
|
+
nextConfig["nx"] = {
|
|
152
|
+
svgr: true,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
nextConfig.webpack = function (_config, options) {
|
|
157
|
+
var webpackConfig = typeof nextConfig.webpack === "function"
|
|
158
|
+
? nextConfig.webpack(_config, options)
|
|
159
|
+
: _config;
|
|
160
|
+
// @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
|
|
161
|
+
webpackConfig.module.rules.push({
|
|
162
|
+
test: /\.svg$/,
|
|
163
|
+
use: [
|
|
164
|
+
{
|
|
165
|
+
loader: "@svgr/webpack",
|
|
166
|
+
options: {
|
|
167
|
+
svgoConfig: {
|
|
168
|
+
plugins: [
|
|
169
|
+
{
|
|
170
|
+
name: "removeViewBox",
|
|
171
|
+
active: false,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
return webpackConfig;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (sc) {
|
|
184
|
+
nextConfig.compiler = {
|
|
185
|
+
styledComponents: true,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return nextConfig;
|
|
189
|
+
}
|
|
190
|
+
export default withKoine;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument from "next/document";
|
|
3
|
+
/**
|
|
4
|
+
* Next Document wrapper for bare projects
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* in your `myapp/pages/_document.tsx`:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* export { Document as default } from "@koine/next/document";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class Document extends NextDocument {
|
|
14
|
+
render(): JSX.Element;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __assign, __extends } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import NextDocument, { Html, Head, Main, NextScript } from "next/document";
|
|
4
|
+
import { Meta, NoJs } from "@koine/react";
|
|
5
|
+
/**
|
|
6
|
+
* Next Document wrapper for bare projects
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* in your `myapp/pages/_document.tsx`:
|
|
11
|
+
* ```tsx
|
|
12
|
+
* export { Document as default } from "@koine/next/document";
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
var Document = /** @class */ (function (_super) {
|
|
16
|
+
__extends(Document, _super);
|
|
17
|
+
function Document() {
|
|
18
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument, { DocumentContext, DocumentInitialProps } from "next/document";
|
|
3
|
+
import { ThemeVanillaValue } from "@koine/react/sc";
|
|
4
|
+
/**
|
|
5
|
+
* Next Document wrapper for `css/tailwind` based projects
|
|
6
|
+
*
|
|
7
|
+
* Uses cookie to manage the current theme
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* in your `myapp/pages/_document.tsx`:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* export { Document as default } from "@koine/next/document/css";
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class Document extends NextDocument {
|
|
17
|
+
static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps & {
|
|
18
|
+
theme: ThemeVanillaValue;
|
|
19
|
+
}>;
|
|
20
|
+
render(): JSX.Element;
|
|
21
|
+
}
|
|
22
|
+
export default Document;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __assign, __awaiter, __extends, __generator } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import NextDocument, { Html, Head, Main, NextScript, } from "next/document";
|
|
4
|
+
import { Meta, NoJs } from "@koine/react";
|
|
5
|
+
import { getInitialThemeFromRequest } from "@koine/react/sc"; // FIXME: this should be imported from another entrypoint
|
|
6
|
+
/**
|
|
7
|
+
* Next Document wrapper for `css/tailwind` based projects
|
|
8
|
+
*
|
|
9
|
+
* Uses cookie to manage the current theme
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* in your `myapp/pages/_document.tsx`:
|
|
14
|
+
* ```tsx
|
|
15
|
+
* export { Document as default } from "@koine/next/document/css";
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var Document = /** @class */ (function (_super) {
|
|
19
|
+
__extends(Document, _super);
|
|
20
|
+
function Document() {
|
|
21
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
22
|
+
}
|
|
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 };
|
|
44
|
+
export default Document;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import NextDocument from "next/document";
|
|
3
|
+
/**
|
|
4
|
+
* Next Document wrapper for `emotion` based projects
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* in your `myapp/pages/_document.tsx`:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* export { Document as default } from "@koine/next/document/em";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class Document extends NextDocument {
|
|
14
|
+
render(): JSX.Element;
|
|
15
|
+
}
|
|
16
|
+
export default Document;
|