@koine/next 1.0.3 → 1.0.8
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 -6
- package/Analytics/AnalyticsGoogle.js +37 -0
- package/Analytics/index.d.ts +1 -1
- package/Analytics/index.js +1 -0
- package/Auth/helpers.d.ts +17 -17
- package/Auth/helpers.js +21 -0
- package/Auth/index.d.ts +4 -4
- package/Auth/index.js +4 -0
- package/Auth/useLogin.d.ts +7 -7
- package/Auth/useLogin.js +47 -0
- package/Auth/useLoginUrl.d.ts +1 -1
- package/Auth/useLoginUrl.js +11 -0
- package/Auth/useLogout.d.ts +6 -6
- package/Auth/useLogout.js +52 -0
- package/Favicon/Favicon.d.ts +3 -4
- package/Favicon/Favicon.js +4 -0
- package/Favicon/index.d.ts +1 -1
- package/Favicon/index.js +1 -0
- package/Forms/index.d.ts +2 -2
- package/Forms/index.js +2 -0
- package/Forms/useForm.d.ts +32 -32
- package/Forms/useForm.js +33 -0
- package/Forms/useSubmit.d.ts +24 -24
- package/Forms/useSubmit.js +20 -0
- package/Head/Head.d.ts +1 -1
- package/Head/Head.js +1 -0
- package/Head/index.d.ts +1 -1
- package/Head/index.js +1 -0
- package/I18n/I18n.d.ts +48 -48
- package/I18n/I18n.js +86 -0
- package/I18n/index.d.ts +1 -1
- package/I18n/index.js +1 -0
- package/Img/Img.d.ts +21 -21
- package/Img/Img.js +30 -0
- package/Img/index.d.ts +1 -1
- package/Img/index.js +1 -0
- package/Link/Link.d.ts +8 -8
- package/Link/Link.js +12 -0
- package/Link/index.d.ts +1 -1
- package/Link/index.js +1 -0
- package/NextProgress/NextProgress.d.ts +13 -14
- package/NextProgress/NextProgress.js +38 -0
- package/NextProgress/index.d.ts +1 -1
- package/NextProgress/index.js +1 -0
- package/Seo/Seo.d.ts +3 -3
- package/Seo/Seo.js +8 -0
- package/Seo/SeoDefaults.d.ts +3 -3
- package/Seo/SeoDefaults.js +12 -0
- package/Seo/helpers.d.ts +48 -48
- package/Seo/helpers.js +113 -0
- package/Seo/index.d.ts +12 -12
- package/Seo/index.js +12 -0
- package/Theme/Theme.d.ts +46 -46
- package/Theme/Theme.js +235 -0
- package/Theme/index.d.ts +1 -1
- package/Theme/index.js +1 -0
- package/app/App--emotion.d.ts +10 -10
- package/app/App--emotion.js +11 -0
- package/app/App--sc.d.ts +10 -10
- package/app/App--sc.js +11 -0
- package/app/App--vanilla.d.ts +10 -10
- package/app/App--vanilla.js +11 -0
- package/app/AppAuth--emotion.d.ts +10 -10
- package/app/AppAuth--emotion.js +12 -0
- package/app/AppAuth--sc.d.ts +10 -10
- package/app/AppAuth--sc.js +12 -0
- package/app/AppHead.d.ts +3 -3
- package/app/AppHead.js +5 -0
- package/app/{AppMain.d.ts → AppMain--emotion.d.ts} +34 -34
- package/app/AppMain--emotion.js +27 -0
- package/app/AppMain--sc.d.ts +34 -0
- package/app/AppMain--sc.js +27 -0
- package/app/AppMain--vanilla.d.ts +27 -27
- package/app/AppMain--vanilla.js +11 -0
- package/app/AppTheme--emotion.d.ts +15 -15
- package/app/AppTheme--emotion.js +17 -0
- package/app/AppTheme--sc.d.ts +13 -13
- package/app/AppTheme--sc.js +9 -0
- package/app/AppTheme--vanilla.d.ts +10 -10
- package/app/AppTheme--vanilla.js +12 -0
- package/app/index.d.ts +11 -11
- package/app/index.js +11 -0
- package/app/motion-features.d.ts +2 -2
- package/app/motion-features.js +2 -0
- package/config/index.d.ts +58 -58
- package/config/index.js +144 -0
- package/document/Document--emotion.d.ts +5 -5
- package/document/Document--emotion.js +55 -0
- package/document/Document--sc.d.ts +11 -11
- package/document/Document--sc.js +33 -0
- package/document/Document--vanilla.d.ts +11 -11
- package/document/Document--vanilla.js +20 -0
- package/document/Document.d.ts +10 -10
- package/document/Document.js +14 -0
- package/document/index.d.ts +4 -4
- package/document/index.js +4 -0
- package/index.d.ts +15 -12
- package/index.js +15 -743
- package/index.umd.js +2061 -78
- package/package.json +27 -21
- package/{types.d.ts → typings.d.ts} +0 -0
- package/utils/api.d.ts +55 -55
- package/utils/api.js +33 -0
- package/{document/emotion.d.ts → utils/emotion-cache.d.ts} +5 -5
- package/utils/emotion-cache.js +8 -0
- package/utils/index.d.ts +20 -19
- package/utils/index.js +27 -0
- package/Theme.js +0 -1905
- package/_tslib.js +0 -41
- package/app.js +0 -250
- package/config.js +0 -183
- package/document.js +0 -207
- package/emotion.js +0 -1329
- package/es.object.assign.js +0 -1074
- package/es.string.replace.js +0 -785
- package/es.string.split.js +0 -201
- package/index.esm.js +0 -4600
- package/motion-features.js +0 -10
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
import { AnimatePresence, LazyMotion, m } from "framer-motion";
|
|
5
|
+
import { SeoDefaults } from "../Seo";
|
|
6
|
+
import { NextProgress } from "../NextProgress";
|
|
7
|
+
/**
|
|
8
|
+
* @see https://www.framer.com/docs/guide-reduce-bundle-size/
|
|
9
|
+
*/
|
|
10
|
+
const loadMotionFeatures = () => import("./motion-features").then((m) => m.default);
|
|
11
|
+
/**
|
|
12
|
+
* App main
|
|
13
|
+
*
|
|
14
|
+
* It implies a setup for `styled-components` and `framer-motion` libraries.
|
|
15
|
+
*
|
|
16
|
+
* About the page transition [wallis' blog post](https://wallis.dev/blog/nextjs-page-transitions-with-framer-motion)
|
|
17
|
+
*/
|
|
18
|
+
export const AppMainSc = ({ Component, pageProps, Layout,
|
|
19
|
+
// theme,
|
|
20
|
+
seo, transition = {
|
|
21
|
+
initial: { opacity: 0 },
|
|
22
|
+
animate: { opacity: 1 },
|
|
23
|
+
exit: { opacity: 0 },
|
|
24
|
+
}, pre, post, }) => {
|
|
25
|
+
const { pathname } = useRouter();
|
|
26
|
+
return (_jsxs(_Fragment, { children: [_jsx(SeoDefaults, Object.assign({}, seo)), pre, _jsxs(LazyMotion, Object.assign({ features: loadMotionFeatures }, { children: [_jsx(NextProgress, {}), _jsx(Layout, { children: _jsx(AnimatePresence, Object.assign({ exitBeforeEnter: true, initial: false }, { children: _jsx(m.div, Object.assign({}, transition, { children: _createElement(Component, Object.assign({}, pageProps, { key: pathname })) }), pathname) })) })] })), post] }));
|
|
27
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
-
import { SeoDefaultsProps } from "../Seo";
|
|
4
|
-
export declare type AppMainVanillaProps = NextAppProps & {
|
|
5
|
-
/**
|
|
6
|
-
* A wrapping layout component
|
|
7
|
-
*/
|
|
8
|
-
Layout: React.FC<Record<string, unknown>>;
|
|
9
|
-
/**
|
|
10
|
-
* Seo site wide default configuration
|
|
11
|
-
*/
|
|
12
|
-
seo?: SeoDefaultsProps;
|
|
13
|
-
/**
|
|
14
|
-
* JSX to render just after SEO
|
|
15
|
-
*/
|
|
16
|
-
pre?: React.ReactNode;
|
|
17
|
-
/**
|
|
18
|
-
* JSX to render just at the end of the markup
|
|
19
|
-
*/
|
|
20
|
-
post?: React.ReactNode;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* App main
|
|
24
|
-
*
|
|
25
|
-
* It does not imply any specific styling or animation solution
|
|
26
|
-
*/
|
|
27
|
-
export declare const AppMainVanilla: React.FC<AppMainVanillaProps>;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
+
import { SeoDefaultsProps } from "../Seo";
|
|
4
|
+
export declare type AppMainVanillaProps = NextAppProps & {
|
|
5
|
+
/**
|
|
6
|
+
* A wrapping layout component
|
|
7
|
+
*/
|
|
8
|
+
Layout: React.FC<Record<string, unknown>>;
|
|
9
|
+
/**
|
|
10
|
+
* Seo site wide default configuration
|
|
11
|
+
*/
|
|
12
|
+
seo?: SeoDefaultsProps;
|
|
13
|
+
/**
|
|
14
|
+
* JSX to render just after SEO
|
|
15
|
+
*/
|
|
16
|
+
pre?: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* JSX to render just at the end of the markup
|
|
19
|
+
*/
|
|
20
|
+
post?: React.ReactNode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* App main
|
|
24
|
+
*
|
|
25
|
+
* It does not imply any specific styling or animation solution
|
|
26
|
+
*/
|
|
27
|
+
export declare const AppMainVanilla: React.FC<AppMainVanillaProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { SeoDefaults } from "../Seo";
|
|
4
|
+
/**
|
|
5
|
+
* App main
|
|
6
|
+
*
|
|
7
|
+
* It does not imply any specific styling or animation solution
|
|
8
|
+
*/
|
|
9
|
+
export const AppMainVanilla = ({ Component, pageProps, Layout, seo, pre, post, }) => {
|
|
10
|
+
return (_jsxs(React.Fragment, { children: [_jsx(SeoDefaults, Object.assign({}, seo)), pre, _jsx(Layout, { children: _jsx(Component, Object.assign({}, pageProps)) }), post] }));
|
|
11
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
-
import { Theme } from "@mui/material/styles";
|
|
4
|
-
import { EmotionCache } from "@emotion/react";
|
|
5
|
-
export declare type AppThemeEmotionProps = NextAppProps & {
|
|
6
|
-
emotionCache?: EmotionCache;
|
|
7
|
-
/**
|
|
8
|
-
* A theme object
|
|
9
|
-
*/
|
|
10
|
-
theme: Theme;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* App theme with `emotion` (good for `@mui`)s
|
|
14
|
-
*/
|
|
15
|
-
export declare const AppThemeEmotion: React.FC<AppThemeEmotionProps>;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
+
import { Theme } from "@mui/material/styles";
|
|
4
|
+
import { EmotionCache } from "@emotion/react";
|
|
5
|
+
export declare type AppThemeEmotionProps = NextAppProps & {
|
|
6
|
+
emotionCache?: EmotionCache;
|
|
7
|
+
/**
|
|
8
|
+
* A theme object
|
|
9
|
+
*/
|
|
10
|
+
theme: Theme;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* App theme with `emotion` (good for `@mui`)s
|
|
14
|
+
*/
|
|
15
|
+
export declare const AppThemeEmotion: React.FC<AppThemeEmotionProps>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeProvider } from "@mui/material/styles";
|
|
3
|
+
import { CacheProvider } from "@emotion/react";
|
|
4
|
+
import CssBaseline from "@mui/material/CssBaseline";
|
|
5
|
+
import { Global, css } from "@emotion/react";
|
|
6
|
+
import { stylesGlobal } from "@koine/react";
|
|
7
|
+
import { createEmotionCache } from "../utils/emotion-cache";
|
|
8
|
+
// client-side cache, shared for the whole session of the user in the browser.
|
|
9
|
+
const clientSideEmotionCache = createEmotionCache();
|
|
10
|
+
/**
|
|
11
|
+
* App theme with `emotion` (good for `@mui`)s
|
|
12
|
+
*/
|
|
13
|
+
export const AppThemeEmotion = ({ emotionCache = clientSideEmotionCache, theme, children, }) => {
|
|
14
|
+
return (_jsx(CacheProvider, Object.assign({ value: emotionCache }, { children: _jsxs(ThemeProvider, Object.assign({ theme: theme }, { children: [_jsx(CssBaseline, {}), _jsx(Global, { styles: css `
|
|
15
|
+
${stylesGlobal}
|
|
16
|
+
` }), children] })) })));
|
|
17
|
+
};
|
package/app/AppTheme--sc.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
-
import { Theme } from "@koine/react";
|
|
4
|
-
export declare type AppThemeScProps = NextAppProps & {
|
|
5
|
-
/**
|
|
6
|
-
* A theme object
|
|
7
|
-
*/
|
|
8
|
-
theme: Theme;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* App theme with `styled-components`
|
|
12
|
-
*/
|
|
13
|
-
export declare const AppThemeSc: React.FC<AppThemeScProps>;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
+
import { Theme } from "@koine/react";
|
|
4
|
+
export declare type AppThemeScProps = NextAppProps & {
|
|
5
|
+
/**
|
|
6
|
+
* A theme object
|
|
7
|
+
*/
|
|
8
|
+
theme: Theme;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* App theme with `styled-components`
|
|
12
|
+
*/
|
|
13
|
+
export declare const AppThemeSc: React.FC<AppThemeScProps>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import { StylesGlobal } from "@koine/react";
|
|
4
|
+
/**
|
|
5
|
+
* App theme with `styled-components`
|
|
6
|
+
*/
|
|
7
|
+
export const AppThemeSc = ({ theme, children }) => {
|
|
8
|
+
return (_jsxs(ThemeProvider, Object.assign({ theme: theme }, { children: [_jsx(StylesGlobal, {}), children] })));
|
|
9
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
-
import { ThemeProviderProps } from "../Theme";
|
|
4
|
-
export declare type AppThemeVanillaProps = NextAppProps & {
|
|
5
|
-
theme: ThemeProviderProps["defaultTheme"];
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* App theme with vanilla class based theme (good for `tailwindcss`)
|
|
9
|
-
*/
|
|
10
|
-
export declare const AppThemeVanilla: React.FC<AppThemeVanillaProps>;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AppProps as NextAppProps } from "next/app";
|
|
3
|
+
import { ThemeProviderProps } from "../Theme";
|
|
4
|
+
export declare type AppThemeVanillaProps = NextAppProps & {
|
|
5
|
+
theme: ThemeProviderProps["defaultTheme"];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* App theme with vanilla class based theme (good for `tailwindcss`)
|
|
9
|
+
*/
|
|
10
|
+
export declare const AppThemeVanilla: React.FC<AppThemeVanillaProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// import { ThemeVanillaProvider, ThemeVanillaValue } from "@koine/react";
|
|
3
|
+
import { ThemeProvider } from "../Theme";
|
|
4
|
+
/**
|
|
5
|
+
* App theme with vanilla class based theme (good for `tailwindcss`)
|
|
6
|
+
*/
|
|
7
|
+
export const AppThemeVanilla = ({ theme, children, }) => {
|
|
8
|
+
// return (
|
|
9
|
+
// <ThemeVanillaProvider initialTheme={theme}>{children}</ThemeVanillaProvider>
|
|
10
|
+
// );
|
|
11
|
+
return (_jsx(ThemeProvider, Object.assign({ defaultTheme: theme, attribute: "class" }, { children: children })));
|
|
12
|
+
};
|
package/app/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from "./App--emotion";
|
|
2
|
-
export * from "./App--sc";
|
|
3
|
-
export * from "./App--vanilla";
|
|
4
|
-
export * from "./AppAuth--emotion";
|
|
5
|
-
export * from "./AppAuth--sc";
|
|
6
|
-
export * from "./AppHead";
|
|
7
|
-
export * from "./AppMain";
|
|
8
|
-
export * from "./AppMain--vanilla";
|
|
9
|
-
export * from "./AppTheme--emotion";
|
|
10
|
-
export * from "./AppTheme--sc";
|
|
11
|
-
export * from "./AppTheme--vanilla";
|
|
1
|
+
export * from "./App--emotion";
|
|
2
|
+
export * from "./App--sc";
|
|
3
|
+
export * from "./App--vanilla";
|
|
4
|
+
export * from "./AppAuth--emotion";
|
|
5
|
+
export * from "./AppAuth--sc";
|
|
6
|
+
export * from "./AppHead";
|
|
7
|
+
export * from "./AppMain--sc";
|
|
8
|
+
export * from "./AppMain--vanilla";
|
|
9
|
+
export * from "./AppTheme--emotion";
|
|
10
|
+
export * from "./AppTheme--sc";
|
|
11
|
+
export * from "./AppTheme--vanilla";
|
package/app/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./App--emotion";
|
|
2
|
+
export * from "./App--sc";
|
|
3
|
+
export * from "./App--vanilla";
|
|
4
|
+
export * from "./AppAuth--emotion";
|
|
5
|
+
export * from "./AppAuth--sc";
|
|
6
|
+
export * from "./AppHead";
|
|
7
|
+
export * from "./AppMain--sc";
|
|
8
|
+
export * from "./AppMain--vanilla";
|
|
9
|
+
export * from "./AppTheme--emotion";
|
|
10
|
+
export * from "./AppTheme--sc";
|
|
11
|
+
export * from "./AppTheme--vanilla";
|
package/app/motion-features.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { domMax } from "framer-motion";
|
|
2
|
-
export default domMax;
|
|
1
|
+
import { domMax } from "framer-motion";
|
|
2
|
+
export default domMax;
|
package/config/index.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import type { NextConfig } from "next";
|
|
2
|
-
import type { Redirect, Rewrite } from "next/dist/lib/load-custom-routes";
|
|
3
|
-
/**
|
|
4
|
-
* Normalise pathname
|
|
5
|
-
*
|
|
6
|
-
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
7
|
-
*
|
|
8
|
-
* - Removes subsequent slashes
|
|
9
|
-
* - Removing initial and ending slashes
|
|
10
|
-
*/
|
|
11
|
-
export declare function normaliseUrlPathname(pathname: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Clean a pathname and encode each part
|
|
14
|
-
*
|
|
15
|
-
* @see {@link normaliseUrlPathname}
|
|
16
|
-
*/
|
|
17
|
-
export declare function encodePathname(pathname: string): string;
|
|
18
|
-
/**
|
|
19
|
-
*/
|
|
20
|
-
export declare function getPathRedirect(locale: string, localisedPathname: string, templateName: string, dynamic?: boolean, permanent?: boolean): {
|
|
21
|
-
source: string;
|
|
22
|
-
destination: string;
|
|
23
|
-
permanent: boolean;
|
|
24
|
-
locale: false;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
*/
|
|
28
|
-
export declare function getPathRewrite(source: string, destination: string, dynamic?: boolean): {
|
|
29
|
-
source: string;
|
|
30
|
-
destination: string;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
*/
|
|
34
|
-
export declare function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }: {
|
|
35
|
-
defaultLocale: string;
|
|
36
|
-
routes: Record<string, string>;
|
|
37
|
-
dynamicRoutes: Record<string, boolean>;
|
|
38
|
-
permanent?: boolean;
|
|
39
|
-
}): Promise<Redirect[]>;
|
|
40
|
-
/**
|
|
41
|
-
*/
|
|
42
|
-
export declare function getRewrites({ routes, dynamicRoutes, }: {
|
|
43
|
-
routes: Record<string, string>;
|
|
44
|
-
dynamicRoutes: Record<string, boolean>;
|
|
45
|
-
}): Promise<Rewrite[]>;
|
|
46
|
-
declare type KoineNextConfig = {
|
|
47
|
-
/** @default true Nx monorepo setup */
|
|
48
|
-
nx?: boolean;
|
|
49
|
-
/** @default true Svg to react components */
|
|
50
|
-
svg?: boolean;
|
|
51
|
-
/** @default true Styled components enabled */
|
|
52
|
-
sc?: boolean;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Get Next.js config with some basic opinionated defaults
|
|
56
|
-
*/
|
|
57
|
-
export declare function withKoine({ nx, svg, sc, ...nextConfig }?: NextConfig & KoineNextConfig): NextConfig;
|
|
58
|
-
export default withKoine;
|
|
1
|
+
import type { NextConfig } from "next";
|
|
2
|
+
import type { Redirect, Rewrite } from "next/dist/lib/load-custom-routes";
|
|
3
|
+
/**
|
|
4
|
+
* Normalise pathname
|
|
5
|
+
*
|
|
6
|
+
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
7
|
+
*
|
|
8
|
+
* - Removes subsequent slashes
|
|
9
|
+
* - Removing initial and ending slashes
|
|
10
|
+
*/
|
|
11
|
+
export declare function normaliseUrlPathname(pathname: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Clean a pathname and encode each part
|
|
14
|
+
*
|
|
15
|
+
* @see {@link normaliseUrlPathname}
|
|
16
|
+
*/
|
|
17
|
+
export declare function encodePathname(pathname: string): string;
|
|
18
|
+
/**
|
|
19
|
+
*/
|
|
20
|
+
export declare function getPathRedirect(locale: string, localisedPathname: string, templateName: string, dynamic?: boolean, permanent?: boolean): {
|
|
21
|
+
source: string;
|
|
22
|
+
destination: string;
|
|
23
|
+
permanent: boolean;
|
|
24
|
+
locale: false;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
*/
|
|
28
|
+
export declare function getPathRewrite(source: string, destination: string, dynamic?: boolean): {
|
|
29
|
+
source: string;
|
|
30
|
+
destination: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
*/
|
|
34
|
+
export declare function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }: {
|
|
35
|
+
defaultLocale: string;
|
|
36
|
+
routes: Record<string, string>;
|
|
37
|
+
dynamicRoutes: Record<string, boolean>;
|
|
38
|
+
permanent?: boolean;
|
|
39
|
+
}): Promise<Redirect[]>;
|
|
40
|
+
/**
|
|
41
|
+
*/
|
|
42
|
+
export declare function getRewrites({ routes, dynamicRoutes, }: {
|
|
43
|
+
routes: Record<string, string>;
|
|
44
|
+
dynamicRoutes: Record<string, boolean>;
|
|
45
|
+
}): Promise<Rewrite[]>;
|
|
46
|
+
declare type KoineNextConfig = {
|
|
47
|
+
/** @default true Nx monorepo setup */
|
|
48
|
+
nx?: boolean;
|
|
49
|
+
/** @default true Svg to react components */
|
|
50
|
+
svg?: boolean;
|
|
51
|
+
/** @default true Styled components enabled */
|
|
52
|
+
sc?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Get Next.js config with some basic opinionated defaults
|
|
56
|
+
*/
|
|
57
|
+
export declare function withKoine({ nx, svg, sc, ...nextConfig }?: NextConfig & KoineNextConfig): NextConfig;
|
|
58
|
+
export default withKoine;
|
package/config/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Normalise pathname
|
|
4
|
+
*
|
|
5
|
+
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
6
|
+
*
|
|
7
|
+
* - Removes subsequent slashes
|
|
8
|
+
* - Removing initial and ending slashes
|
|
9
|
+
*/
|
|
10
|
+
export function normaliseUrlPathname(pathname) {
|
|
11
|
+
return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Clean a pathname and encode each part
|
|
15
|
+
*
|
|
16
|
+
* @see {@link normaliseUrlPathname}
|
|
17
|
+
*/
|
|
18
|
+
export function encodePathname(pathname) {
|
|
19
|
+
const parts = normaliseUrlPathname(pathname).split("/");
|
|
20
|
+
return parts
|
|
21
|
+
.filter((part) => !!part)
|
|
22
|
+
.map((part) => encodeURIComponent(part))
|
|
23
|
+
.join("/");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*/
|
|
27
|
+
export function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
|
|
28
|
+
const suffix = dynamic ? `/:slug*` : "";
|
|
29
|
+
return {
|
|
30
|
+
source: `/${locale}/${encodePathname(localisedPathname)}${suffix}`,
|
|
31
|
+
destination: `/${encodePathname(templateName)}${suffix}`,
|
|
32
|
+
permanent: Boolean(permanent),
|
|
33
|
+
locale: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
*/
|
|
38
|
+
export function getPathRewrite(source, destination, dynamic) {
|
|
39
|
+
const suffix = dynamic ? `/:path*` : "";
|
|
40
|
+
return {
|
|
41
|
+
source: `/${encodePathname(source)}${suffix}`,
|
|
42
|
+
destination: `/${encodePathname(destination)}${suffix}`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
*/
|
|
47
|
+
export function getRedirects({ defaultLocale, routes, dynamicRoutes, permanent, }) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const redirects = [];
|
|
50
|
+
Object.keys(routes).forEach((page) => {
|
|
51
|
+
const dynamic = dynamicRoutes[page];
|
|
52
|
+
if (routes[page] !== page) {
|
|
53
|
+
if (dynamic) {
|
|
54
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// console.log("redirects", redirects);
|
|
62
|
+
return redirects;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
*/
|
|
67
|
+
export function getRewrites({ routes, dynamicRoutes, }) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const rewrites = [];
|
|
70
|
+
Object.keys(routes).forEach((page) => {
|
|
71
|
+
const dynamic = dynamicRoutes[page];
|
|
72
|
+
if (routes[page] !== page) {
|
|
73
|
+
if (dynamic) {
|
|
74
|
+
rewrites.push(getPathRewrite(routes[page], page, true));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
rewrites.push(getPathRewrite(routes[page], page));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// console.log("rewrites", rewrites);
|
|
82
|
+
return rewrites;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get Next.js config with some basic opinionated defaults
|
|
87
|
+
*/
|
|
88
|
+
export function withKoine(_a = {}) {
|
|
89
|
+
var { nx = true, svg = true, sc = true } = _a, nextConfig = __rest(_a, ["nx", "svg", "sc"]);
|
|
90
|
+
nextConfig = Object.assign({
|
|
91
|
+
// @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
|
|
92
|
+
pageExtensions: ["page.tsx", "page.ts"], eslint: {
|
|
93
|
+
ignoreDuringBuilds: true, // we have this strict check on each commit
|
|
94
|
+
}, typescript: {
|
|
95
|
+
ignoreBuildErrors: true, // we have this strict check on each commit
|
|
96
|
+
}, poweredByHeader: false, swcMinify: true, experimental: Object.assign({
|
|
97
|
+
// @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
|
|
98
|
+
// @see critters error https://github.com/vercel/next.js/issues/20742
|
|
99
|
+
// optimizeCss: true,
|
|
100
|
+
// @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
|
|
101
|
+
scrollRestoration: true }, (nextConfig.experimental || {})) }, nextConfig);
|
|
102
|
+
if (svg) {
|
|
103
|
+
if (nx) {
|
|
104
|
+
// @see https://github.com/gregberge/svgr
|
|
105
|
+
nextConfig["nx"] = {
|
|
106
|
+
svgr: true,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
nextConfig.webpack = (_config, options) => {
|
|
111
|
+
const webpackConfig = typeof nextConfig.webpack === "function"
|
|
112
|
+
? nextConfig.webpack(_config, options)
|
|
113
|
+
: _config;
|
|
114
|
+
// @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
|
|
115
|
+
webpackConfig.module.rules.push({
|
|
116
|
+
test: /\.svg$/,
|
|
117
|
+
use: [
|
|
118
|
+
{
|
|
119
|
+
loader: "@svgr/webpack",
|
|
120
|
+
options: {
|
|
121
|
+
svgoConfig: {
|
|
122
|
+
plugins: [
|
|
123
|
+
{
|
|
124
|
+
name: "removeViewBox",
|
|
125
|
+
active: false,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
return webpackConfig;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (sc) {
|
|
138
|
+
nextConfig.compiler = {
|
|
139
|
+
styledComponents: true,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return nextConfig;
|
|
143
|
+
}
|
|
144
|
+
export default withKoine;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import Document from "next/document";
|
|
3
|
-
export declare class DocumentEmotion extends Document {
|
|
4
|
-
render(): JSX.Element;
|
|
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,55 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import Document, { Html, Head, Main, NextScript } from "next/document";
|
|
4
|
+
import createEmotionServer from "@emotion/server/create-instance";
|
|
5
|
+
import { createEmotionCache } from "../utils/emotion-cache";
|
|
6
|
+
import { NoJs } from "@koine/react";
|
|
7
|
+
export class DocumentEmotion extends Document {
|
|
8
|
+
render() {
|
|
9
|
+
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
10
|
+
return (_jsxs(Html, Object.assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [_jsxs(Head, { children: [_jsx(NoJs, {}), this.props.emotionStyleTags] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] })));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// `getInitialProps` belongs to `_document` (instead of `_app`),
|
|
14
|
+
// it's compatible with static-site generation (SSG).
|
|
15
|
+
DocumentEmotion.getInitialProps = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
// Resolution order
|
|
17
|
+
//
|
|
18
|
+
// On the server:
|
|
19
|
+
// 1. app.getInitialProps
|
|
20
|
+
// 2. page.getInitialProps
|
|
21
|
+
// 3. document.getInitialProps
|
|
22
|
+
// 4. app.render
|
|
23
|
+
// 5. page.render
|
|
24
|
+
// 6. document.render
|
|
25
|
+
//
|
|
26
|
+
// On the server with error:
|
|
27
|
+
// 1. document.getInitialProps
|
|
28
|
+
// 2. app.render
|
|
29
|
+
// 3. page.render
|
|
30
|
+
// 4. document.render
|
|
31
|
+
//
|
|
32
|
+
// On the client
|
|
33
|
+
// 1. app.getInitialProps
|
|
34
|
+
// 2. page.getInitialProps
|
|
35
|
+
// 3. app.render
|
|
36
|
+
// 4. page.render
|
|
37
|
+
const originalRenderPage = ctx.renderPage;
|
|
38
|
+
// You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
|
|
39
|
+
// However, be aware that it can have global side effects.
|
|
40
|
+
const cache = createEmotionCache();
|
|
41
|
+
const { extractCriticalToChunks } = createEmotionServer(cache);
|
|
42
|
+
ctx.renderPage = () => originalRenderPage({
|
|
43
|
+
enhanceApp: (App) => function EnhanceApp(props) {
|
|
44
|
+
return _jsx(App, Object.assign({ emotionCache: cache }, props));
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const initialProps = yield Document.getInitialProps(ctx);
|
|
48
|
+
// This is important. It prevents emotion to render invalid HTML.
|
|
49
|
+
// See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
|
|
50
|
+
const emotionStyles = extractCriticalToChunks(initialProps.html);
|
|
51
|
+
const emotionStyleTags = emotionStyles.styles.map((style) => (_jsx("style", { "data-emotion": `${style.key} ${style.ids.join(" ")}`,
|
|
52
|
+
// eslint-disable-next-line react/no-danger
|
|
53
|
+
dangerouslySetInnerHTML: { __html: style.css } }, style.key)));
|
|
54
|
+
return Object.assign(Object.assign({}, initialProps), { emotionStyleTags });
|
|
55
|
+
});
|
|
@@ -1,11 +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
|
-
}
|
|
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,33 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/* ? eslint-disable @next/next/no-document-import-in-page */
|
|
4
|
+
import NextDocument, { Html, Head, Main, NextScript, } from "next/document";
|
|
5
|
+
import { ServerStyleSheet } from "styled-components";
|
|
6
|
+
import { Meta, NoJs } from "@koine/react";
|
|
7
|
+
/**
|
|
8
|
+
* For typescript safety of this component
|
|
9
|
+
*
|
|
10
|
+
* @see https://bit.ly/3ceuF8m
|
|
11
|
+
*/
|
|
12
|
+
export class DocumentSc extends NextDocument {
|
|
13
|
+
static getInitialProps(ctx) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const sheet = new ServerStyleSheet();
|
|
16
|
+
const originalRenderPage = ctx.renderPage;
|
|
17
|
+
try {
|
|
18
|
+
ctx.renderPage = () => originalRenderPage({
|
|
19
|
+
enhanceApp: (App) => (props) => sheet.collectStyles(_jsx(App, Object.assign({}, props))),
|
|
20
|
+
});
|
|
21
|
+
const initialProps = yield NextDocument.getInitialProps(ctx);
|
|
22
|
+
return Object.assign(Object.assign({}, initialProps), { styles: (_jsxs(_Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })) });
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
sheet.seal();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
render() {
|
|
30
|
+
const { locale, defaultLocale } = this.props.__NEXT_DATA__;
|
|
31
|
+
return (_jsxs(Html, Object.assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [_jsxs(Head, { children: [_jsx(Meta, {}), _jsx(NoJs, {})] }), _jsxs("body", { children: [_jsx(Main, {}), _jsx(NextScript, {})] })] })));
|
|
32
|
+
}
|
|
33
|
+
}
|