@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
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export declare const AnalyticsGoogle: ({ id }: AnalyticsGoogleProps) => JSX.Element | null;
|
|
1
|
+
export declare type AnalyticsGoogleProps = {
|
|
2
|
+
/** Falls back to `.env` variable `NEXT_PUBLIC_GTM_ID` */
|
|
3
|
+
id?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const AnalyticsGoogle: ({ id }: AnalyticsGoogleProps) => JSX.Element | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
import Script from "next/script";
|
|
5
|
+
import { pageview } from "@koine/utils";
|
|
6
|
+
export const AnalyticsGoogle = ({ id }) => {
|
|
7
|
+
const uid = id || process.env["NEXT_PUBLIC_GTM_ID"];
|
|
8
|
+
const { events, asPath, query } = useRouter();
|
|
9
|
+
const [ready, setReady] = useState(false);
|
|
10
|
+
const [routed, setRouted] = useState(false);
|
|
11
|
+
// const [url, setUrl] = useState("");
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const handleRouteChange = () => {
|
|
14
|
+
setRouted(true);
|
|
15
|
+
};
|
|
16
|
+
events.on("routeChangeComplete", handleRouteChange);
|
|
17
|
+
return () => {
|
|
18
|
+
events.off("routeChangeComplete", handleRouteChange);
|
|
19
|
+
};
|
|
20
|
+
}, [events]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (routed && ready && asPath) {
|
|
23
|
+
// const search = query;
|
|
24
|
+
pageview(asPath);
|
|
25
|
+
}
|
|
26
|
+
}, [asPath, query, routed, ready]);
|
|
27
|
+
if (!uid) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsx(Script, { id: "google-tagmanager", src: `https://www.googletagmanager.com/gtag/js?id=${id}`, strategy: "afterInteractive", onLoad: () => setReady(true) }), _jsx(Script, Object.assign({ id: "google-analytics", strategy: "afterInteractive" }, { children: `
|
|
31
|
+
window.dataLayer = window.dataLayer || [];
|
|
32
|
+
function gtag(){window.dataLayer.push(arguments);}
|
|
33
|
+
gtag('js', new Date());
|
|
34
|
+
|
|
35
|
+
gtag('config', '${id}', { 'send_page_view': false });
|
|
36
|
+
` }))] }));
|
|
37
|
+
};
|
package/Analytics/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./AnalyticsGoogle";
|
|
1
|
+
export * from "./AnalyticsGoogle";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AnalyticsGoogle";
|
package/Auth/helpers.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { Translate } from "../I18n";
|
|
2
|
-
/**
|
|
3
|
-
* @see next/auth `pages` mapping: https://next-auth.js.org/configuration/pages`
|
|
4
|
-
*/
|
|
5
|
-
export declare type AuthRoutesMap = {
|
|
6
|
-
login?: string;
|
|
7
|
-
profile?: string;
|
|
8
|
-
register?: string;
|
|
9
|
-
/** Array of regexes to match pathnames of protected routes */
|
|
10
|
-
secured?: RegExp[];
|
|
11
|
-
};
|
|
12
|
-
export declare const AUTH_ROUTES: AuthRoutesMap;
|
|
13
|
-
export declare function getAuthRoutes(t: Translate): AuthRoutesMap;
|
|
14
|
-
/**
|
|
15
|
-
* @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
|
|
16
|
-
*/
|
|
17
|
-
export declare function getCallbackUrl(url?: string): string;
|
|
1
|
+
import type { Translate } from "../I18n";
|
|
2
|
+
/**
|
|
3
|
+
* @see next/auth `pages` mapping: https://next-auth.js.org/configuration/pages`
|
|
4
|
+
*/
|
|
5
|
+
export declare type AuthRoutesMap = {
|
|
6
|
+
login?: string;
|
|
7
|
+
profile?: string;
|
|
8
|
+
register?: string;
|
|
9
|
+
/** Array of regexes to match pathnames of protected routes */
|
|
10
|
+
secured?: RegExp[];
|
|
11
|
+
};
|
|
12
|
+
export declare const AUTH_ROUTES: AuthRoutesMap;
|
|
13
|
+
export declare function getAuthRoutes(t: Translate): AuthRoutesMap;
|
|
14
|
+
/**
|
|
15
|
+
* @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
|
|
16
|
+
*/
|
|
17
|
+
export declare function getCallbackUrl(url?: string): string;
|
package/Auth/helpers.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isString } from "@koine/utils";
|
|
2
|
+
export const AUTH_ROUTES = {
|
|
3
|
+
login: process.env["AUTH_ROUTE_LOGIN"],
|
|
4
|
+
profile: process.env["AUTH_ROUTE_PROFILE"],
|
|
5
|
+
register: process.env["AUTH_ROUTE_REGISTER"],
|
|
6
|
+
secured: JSON.parse(process.env["AUTH_ROUTES_SECURED"] || "[]"),
|
|
7
|
+
};
|
|
8
|
+
export function getAuthRoutes(t) {
|
|
9
|
+
return Object.keys(AUTH_ROUTES).reduce((map, name) => {
|
|
10
|
+
const routePage = AUTH_ROUTES[name];
|
|
11
|
+
// @ts-expect-error cannot remember
|
|
12
|
+
map[name] = isString(routePage) ? t(`~:${AUTH_ROUTES[name]}`) : routePage;
|
|
13
|
+
return map;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
|
|
18
|
+
*/
|
|
19
|
+
export function getCallbackUrl(url = window.location.href) {
|
|
20
|
+
return url.split("callbackUrl=")[1] || "";
|
|
21
|
+
}
|
package/Auth/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./helpers";
|
|
2
|
-
export * from "./useLogin";
|
|
3
|
-
export * from "./useLoginUrl";
|
|
4
|
-
export * from "./useLogout";
|
|
1
|
+
export * from "./helpers";
|
|
2
|
+
export * from "./useLogin";
|
|
3
|
+
export * from "./useLoginUrl";
|
|
4
|
+
export * from "./useLogout";
|
package/Auth/index.js
ADDED
package/Auth/useLogin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SubmitHandler } from "react-hook-form";
|
|
2
|
-
export declare function useLogin<LoginForm = {}>(): {
|
|
3
|
-
submit: SubmitHandler<LoginForm>;
|
|
4
|
-
loading: boolean;
|
|
5
|
-
ok: boolean;
|
|
6
|
-
fail: boolean;
|
|
7
|
-
};
|
|
1
|
+
import { SubmitHandler } from "react-hook-form";
|
|
2
|
+
export declare function useLogin<LoginForm = {}>(): {
|
|
3
|
+
submit: SubmitHandler<LoginForm>;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
ok: boolean;
|
|
6
|
+
fail: boolean;
|
|
7
|
+
};
|
package/Auth/useLogin.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { useRouter } from "next/router";
|
|
3
|
+
import { signIn } from "next-auth/react";
|
|
4
|
+
import { parseURL } from "@koine/utils";
|
|
5
|
+
import { useT } from "../I18n";
|
|
6
|
+
import { getAuthRoutes, getCallbackUrl } from "./helpers";
|
|
7
|
+
export function useLogin() {
|
|
8
|
+
const t = useT();
|
|
9
|
+
const { push } = useRouter();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [ok, setOk] = useState(false);
|
|
12
|
+
const [fail, setFail] = useState(false);
|
|
13
|
+
const submit = useCallback((data) => {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
signIn("credentials", Object.assign(Object.assign({}, data), { redirect: false }))
|
|
16
|
+
// @ts-expect-error FIXME: at some point...
|
|
17
|
+
.then(({ ok }) => {
|
|
18
|
+
setLoading(false);
|
|
19
|
+
setOk(ok);
|
|
20
|
+
setFail(!ok);
|
|
21
|
+
if (ok) {
|
|
22
|
+
const redirectUrl = parseURL(getCallbackUrl());
|
|
23
|
+
const { login, register, profile } = getAuthRoutes(t);
|
|
24
|
+
if (redirectUrl) {
|
|
25
|
+
const redirectPath = redirectUrl.pathname;
|
|
26
|
+
if (profile &&
|
|
27
|
+
(redirectPath === login || redirectPath === register)) {
|
|
28
|
+
push(profile);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
push(redirectPath + redirectUrl.search);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (profile) {
|
|
35
|
+
push(profile);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}, [t, push]);
|
|
40
|
+
// TODO: useMemo ?
|
|
41
|
+
return {
|
|
42
|
+
submit,
|
|
43
|
+
loading,
|
|
44
|
+
ok,
|
|
45
|
+
fail,
|
|
46
|
+
};
|
|
47
|
+
}
|
package/Auth/useLoginUrl.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useLoginUrl(): string;
|
|
1
|
+
export declare function useLoginUrl(): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useT } from "../I18n";
|
|
3
|
+
import { getAuthRoutes } from "./helpers";
|
|
4
|
+
export function useLoginUrl() {
|
|
5
|
+
const [currentUrl, setCurrentUrl] = useState("");
|
|
6
|
+
const t = useT();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
setCurrentUrl(`?callbackUrl=${window.location.href}`);
|
|
9
|
+
}, []);
|
|
10
|
+
return `${getAuthRoutes(t).login}${currentUrl}`;
|
|
11
|
+
}
|
package/Auth/useLogout.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare function useLogout(): {
|
|
2
|
-
submit: (event: React.SyntheticEvent<HTMLFormElement>) => void;
|
|
3
|
-
loading: boolean;
|
|
4
|
-
ok: boolean;
|
|
5
|
-
fail: boolean;
|
|
6
|
-
};
|
|
1
|
+
export declare function useLogout(): {
|
|
2
|
+
submit: (event: React.SyntheticEvent<HTMLFormElement>) => void;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
ok: boolean;
|
|
5
|
+
fail: boolean;
|
|
6
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { useRouter } from "next/router";
|
|
3
|
+
import { signOut } from "next-auth/react";
|
|
4
|
+
import { parseURL } from "@koine/utils";
|
|
5
|
+
import { useT } from "../I18n";
|
|
6
|
+
import { getAuthRoutes, getCallbackUrl } from "./helpers";
|
|
7
|
+
export function useLogout() {
|
|
8
|
+
const t = useT();
|
|
9
|
+
const { push } = useRouter();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [ok, setOk] = useState(false);
|
|
12
|
+
const [fail] = useState(false);
|
|
13
|
+
const submit = useCallback((event) => {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
event.stopPropagation();
|
|
16
|
+
setLoading(true);
|
|
17
|
+
signOut({ redirect: false }).then(() => {
|
|
18
|
+
setLoading(false);
|
|
19
|
+
setOk(true);
|
|
20
|
+
const redirectUrl = parseURL(getCallbackUrl());
|
|
21
|
+
const currentUrl = parseURL(window.location.href);
|
|
22
|
+
const { secured } = getAuthRoutes(t);
|
|
23
|
+
const signin = t("~:/signin");
|
|
24
|
+
const profile = t("~:/profile");
|
|
25
|
+
const targetUrl = redirectUrl || currentUrl;
|
|
26
|
+
let redirect = "";
|
|
27
|
+
if (targetUrl) {
|
|
28
|
+
if (targetUrl.pathname === profile) {
|
|
29
|
+
redirect = signin;
|
|
30
|
+
}
|
|
31
|
+
else if (secured) {
|
|
32
|
+
for (let i = 0; i < secured.length; i++) {
|
|
33
|
+
if (targetUrl.pathname.match(secured[i])) {
|
|
34
|
+
redirect = signin;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (redirect) {
|
|
41
|
+
push(redirect);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}, [t, push]);
|
|
45
|
+
// TODO: useMemo ?
|
|
46
|
+
return {
|
|
47
|
+
submit,
|
|
48
|
+
loading,
|
|
49
|
+
ok,
|
|
50
|
+
fail,
|
|
51
|
+
};
|
|
52
|
+
}
|
package/Favicon/Favicon.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export declare const Favicon: (props: FaviconTagsProps) => JSX.Element;
|
|
1
|
+
import { FaviconTagsProps } from "@koine/react";
|
|
2
|
+
export declare type FaviconProps = FaviconTagsProps;
|
|
3
|
+
export declare const Favicon: (props: FaviconTagsProps) => JSX.Element;
|
package/Favicon/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Favicon";
|
|
1
|
+
export * from "./Favicon";
|
package/Favicon/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Favicon";
|
package/Forms/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./useForm";
|
|
2
|
-
export * from "./useSubmit";
|
|
1
|
+
export * from "./useForm";
|
|
2
|
+
export * from "./useSubmit";
|
package/Forms/index.js
ADDED
package/Forms/useForm.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type { UseFormProps, FieldValues } from "react-hook-form";
|
|
2
|
-
import type { ObjectSchema } from "yup";
|
|
3
|
-
import { TranslateNamespace } from "../I18n";
|
|
4
|
-
export declare function useForm<T extends FieldValues>(schema: ObjectSchema<any>, i18nNamespace: TranslateNamespace, formProps?: UseFormProps, debug?: boolean): {
|
|
5
|
-
watch: import("react-hook-form").UseFormWatch<T>;
|
|
6
|
-
getValues: import("react-hook-form").UseFormGetValues<T>;
|
|
7
|
-
getFieldState: import("react-hook-form").UseFormGetFieldState<T>;
|
|
8
|
-
setError: import("react-hook-form").UseFormSetError<T>;
|
|
9
|
-
clearErrors: import("react-hook-form").UseFormClearErrors<T>;
|
|
10
|
-
setValue: import("react-hook-form").UseFormSetValue<T>;
|
|
11
|
-
trigger: import("react-hook-form").UseFormTrigger<T>;
|
|
12
|
-
formState: import("react-hook-form").FormState<T>;
|
|
13
|
-
resetField: import("react-hook-form").UseFormResetField<T>;
|
|
14
|
-
reset: import("react-hook-form").UseFormReset<T>;
|
|
15
|
-
handleSubmit: import("react-hook-form").UseFormHandleSubmit<T>;
|
|
16
|
-
unregister: import("react-hook-form").UseFormUnregister<T>;
|
|
17
|
-
control: import("react-hook-form").Control<T, any>;
|
|
18
|
-
register: import("react-hook-form").UseFormRegister<T>;
|
|
19
|
-
setFocus: import("react-hook-form").UseFormSetFocus<T>;
|
|
20
|
-
field: {
|
|
21
|
-
control: import("react-hook-form").Control<T, any>;
|
|
22
|
-
register: import("react-hook-form").UseFormRegister<T>;
|
|
23
|
-
setValue: import("react-hook-form").UseFormSetValue<T>;
|
|
24
|
-
t: <R extends unknown = string>(s: string, q?: "obj" | {
|
|
25
|
-
[key: string]: string | number | boolean;
|
|
26
|
-
} | null | undefined, o?: "obj" | {
|
|
27
|
-
returnObjects?: boolean | undefined;
|
|
28
|
-
fallback?: string | string[] | undefined;
|
|
29
|
-
default?: string | undefined;
|
|
30
|
-
} | undefined) => R;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
1
|
+
import type { UseFormProps, FieldValues } from "react-hook-form";
|
|
2
|
+
import type { ObjectSchema } from "yup";
|
|
3
|
+
import { TranslateNamespace } from "../I18n";
|
|
4
|
+
export declare function useForm<T extends FieldValues>(schema: ObjectSchema<any>, i18nNamespace: TranslateNamespace, formProps?: UseFormProps, debug?: boolean): {
|
|
5
|
+
watch: import("react-hook-form").UseFormWatch<T>;
|
|
6
|
+
getValues: import("react-hook-form").UseFormGetValues<T>;
|
|
7
|
+
getFieldState: import("react-hook-form").UseFormGetFieldState<T>;
|
|
8
|
+
setError: import("react-hook-form").UseFormSetError<T>;
|
|
9
|
+
clearErrors: import("react-hook-form").UseFormClearErrors<T>;
|
|
10
|
+
setValue: import("react-hook-form").UseFormSetValue<T>;
|
|
11
|
+
trigger: import("react-hook-form").UseFormTrigger<T>;
|
|
12
|
+
formState: import("react-hook-form").FormState<T>;
|
|
13
|
+
resetField: import("react-hook-form").UseFormResetField<T>;
|
|
14
|
+
reset: import("react-hook-form").UseFormReset<T>;
|
|
15
|
+
handleSubmit: import("react-hook-form").UseFormHandleSubmit<T>;
|
|
16
|
+
unregister: import("react-hook-form").UseFormUnregister<T>;
|
|
17
|
+
control: import("react-hook-form").Control<T, any>;
|
|
18
|
+
register: import("react-hook-form").UseFormRegister<T>;
|
|
19
|
+
setFocus: import("react-hook-form").UseFormSetFocus<T>;
|
|
20
|
+
field: {
|
|
21
|
+
control: import("react-hook-form").Control<T, any>;
|
|
22
|
+
register: import("react-hook-form").UseFormRegister<T>;
|
|
23
|
+
setValue: import("react-hook-form").UseFormSetValue<T>;
|
|
24
|
+
t: <R extends unknown = string>(s: string, q?: "obj" | {
|
|
25
|
+
[key: string]: string | number | boolean;
|
|
26
|
+
} | null | undefined, o?: "obj" | {
|
|
27
|
+
returnObjects?: boolean | undefined;
|
|
28
|
+
fallback?: string | string[] | undefined;
|
|
29
|
+
default?: string | undefined;
|
|
30
|
+
} | undefined) => R;
|
|
31
|
+
};
|
|
32
|
+
};
|
package/Forms/useForm.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useForm as _useForm } from "react-hook-form";
|
|
3
|
+
import { yupResolver as resolver } from "@hookform/resolvers/yup";
|
|
4
|
+
import { useT } from "../I18n";
|
|
5
|
+
export function useForm(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
schema, i18nNamespace, formProps = {}, debug) {
|
|
8
|
+
const t = useT(i18nNamespace);
|
|
9
|
+
// const form = _useForm<InferType<ObjectSchema<T, object>>>({
|
|
10
|
+
const form = _useForm(Object.assign({
|
|
11
|
+
// @ts-expect-error FIXME:
|
|
12
|
+
resolver: resolver(schema) }, formProps));
|
|
13
|
+
// const { control, register, setValue } = form;
|
|
14
|
+
// const field = { control, register, setValue, t };
|
|
15
|
+
// if ("production" !== process.env["NODE_ENV"]) {
|
|
16
|
+
// if (debug) {
|
|
17
|
+
// console.log(
|
|
18
|
+
// `Form ${i18nNamespace} data`,
|
|
19
|
+
// form.watch(),
|
|
20
|
+
// `errors: `,
|
|
21
|
+
// form.formState.errors
|
|
22
|
+
// );
|
|
23
|
+
// }
|
|
24
|
+
// }
|
|
25
|
+
// if (formProps.mode === "onChange") {
|
|
26
|
+
// return { field, ...form };
|
|
27
|
+
// }
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
const { control, register, setValue } = form;
|
|
30
|
+
const field = { control, register, setValue, t };
|
|
31
|
+
return Object.assign({ field }, form);
|
|
32
|
+
}, [t, form]);
|
|
33
|
+
}
|
package/Forms/useSubmit.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { UnpackNestedValue } from "react-hook-form";
|
|
2
|
-
import { KoineApi } from "../utils/api";
|
|
3
|
-
export declare function useSubmit<RequestBody extends {}, ResponseSuccesfull extends KoineApi.ResponseSuccesfull = {}, ResponseFailed extends KoineApi.ResponseFailed = Record<keyof RequestBody, string | string[]>>(url: string, transformData?: (json: UnpackNestedValue<RequestBody>) => any): {
|
|
4
|
-
submit: (json: any) => Promise<KoineApi.Response<ResponseSuccesfull, ResponseFailed>>;
|
|
5
|
-
loading: boolean;
|
|
6
|
-
} & {
|
|
7
|
-
status: number;
|
|
8
|
-
msg: string;
|
|
9
|
-
} & ({
|
|
10
|
-
ok?: boolean | undefined;
|
|
11
|
-
fail?: boolean | undefined;
|
|
12
|
-
loading: true;
|
|
13
|
-
data?: undefined;
|
|
14
|
-
} | {
|
|
15
|
-
ok: true;
|
|
16
|
-
fail?: false | undefined;
|
|
17
|
-
loading?: false | undefined;
|
|
18
|
-
data: ResponseSuccesfull;
|
|
19
|
-
} | {
|
|
20
|
-
ok?: false | undefined;
|
|
21
|
-
fail: true;
|
|
22
|
-
loading?: false | undefined;
|
|
23
|
-
data: ResponseFailed;
|
|
24
|
-
});
|
|
1
|
+
import type { UnpackNestedValue } from "react-hook-form";
|
|
2
|
+
import { KoineApi } from "../utils/api";
|
|
3
|
+
export declare function useSubmit<RequestBody extends {}, ResponseSuccesfull extends KoineApi.ResponseSuccesfull = {}, ResponseFailed extends KoineApi.ResponseFailed = Record<keyof RequestBody, string | string[]>>(url: string, transformData?: (json: UnpackNestedValue<RequestBody>) => any): {
|
|
4
|
+
submit: (json: any) => Promise<KoineApi.Response<ResponseSuccesfull, ResponseFailed>>;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
} & {
|
|
7
|
+
status: number;
|
|
8
|
+
msg: string;
|
|
9
|
+
} & ({
|
|
10
|
+
ok?: boolean | undefined;
|
|
11
|
+
fail?: boolean | undefined;
|
|
12
|
+
loading: true;
|
|
13
|
+
data?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
ok: true;
|
|
16
|
+
fail?: false | undefined;
|
|
17
|
+
loading?: false | undefined;
|
|
18
|
+
data: ResponseSuccesfull;
|
|
19
|
+
} | {
|
|
20
|
+
ok?: false | undefined;
|
|
21
|
+
fail: true;
|
|
22
|
+
loading?: false | undefined;
|
|
23
|
+
data: ResponseFailed;
|
|
24
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { useAsyncFn } from "react-use";
|
|
3
|
+
import { api } from "../utils/api";
|
|
4
|
+
export function useSubmit(url, transformData) {
|
|
5
|
+
const [state, submit] = useAsyncFn((json) => __awaiter(this, void 0, void 0, function* () {
|
|
6
|
+
if (transformData)
|
|
7
|
+
json = transformData(json);
|
|
8
|
+
const response = yield api.post(url, {
|
|
9
|
+
json,
|
|
10
|
+
});
|
|
11
|
+
if ("production" !== process.env["NODE_ENV"]) {
|
|
12
|
+
console.log("[@koine/next] useSubmit response", response);
|
|
13
|
+
}
|
|
14
|
+
return response;
|
|
15
|
+
}), [url, transformData]);
|
|
16
|
+
const { loading, error, value } = state;
|
|
17
|
+
const fail = !loading && (!!error || (value === null || value === void 0 ? void 0 : value.fail));
|
|
18
|
+
return Object.assign(Object.assign({ submit,
|
|
19
|
+
loading }, (value || {})), { fail });
|
|
20
|
+
}
|
package/Head/Head.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as Head } from "next/head";
|
|
1
|
+
export { default as Head } from "next/head";
|
package/Head/Head.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Head } from "next/head";
|
package/Head/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Head";
|
|
1
|
+
export * from "./Head";
|
package/Head/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Head";
|
package/I18n/I18n.d.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import format from "date-fns/format";
|
|
2
|
-
import { Option } from "@koine/react";
|
|
3
|
-
export { default as T } from "next-translate/Trans";
|
|
4
|
-
declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : never : never;
|
|
5
|
-
declare type Paths<T> = {
|
|
6
|
-
[K in keyof T]: T[K] extends Record<string, unknown> ? Join<K, Paths<T[K]>> : K;
|
|
7
|
-
}[keyof T];
|
|
8
|
-
export declare type AllPaths = {
|
|
9
|
-
[N in keyof Koine.NextTranslations]: {
|
|
10
|
-
[K in keyof Koine.NextTranslations[N]]: Koine.NextTranslations[N][K] extends Array<Record<string, unknown>> ? Join<K extends string ? `${N}:${K}` : `${N}:`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends Record<string, unknown> ? Join<K extends string ? `${N}:${K}` : `${N}:`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends Array<string | number | boolean> ? Join<K extends string ? `${N}:${K}` : `${N}`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends string | number | boolean ? K extends string ? `${N}:${K}` : `${N}:` : ``;
|
|
11
|
-
}[keyof Koine.NextTranslations[N]];
|
|
12
|
-
}[keyof Koine.NextTranslations];
|
|
13
|
-
declare type TranslateReturn<Q extends TranslationQuery, O extends TranslationOptions> = string;
|
|
14
|
-
/**
|
|
15
|
-
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
16
|
-
*/
|
|
17
|
-
declare type TranslationQuery = undefined | null | "obj" | {
|
|
18
|
-
[key: string]: string | number | boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
22
|
-
*/
|
|
23
|
-
declare type TranslationOptions = undefined | "obj" | {
|
|
24
|
-
returnObjects?: boolean;
|
|
25
|
-
fallback?: string | string[];
|
|
26
|
-
default?: string;
|
|
27
|
-
};
|
|
28
|
-
export declare type TranslateNamespace = keyof Koine.NextTranslations;
|
|
29
|
-
export declare type TranslateKey = AllPaths;
|
|
30
|
-
export declare type Translate<R extends unknown = string, N extends undefined | keyof Koine.NextTranslations = undefined, Q extends TranslationQuery = undefined, O extends TranslationOptions = undefined> = (s: N extends keyof Koine.NextTranslations ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: Q, o?: O) => R extends undefined | unknown ? TranslateReturn<Q, O> : R;
|
|
31
|
-
export declare type TranslateLoose = (s: any, q?: any, o?: any) => string;
|
|
32
|
-
/**
|
|
33
|
-
* FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
|
|
34
|
-
* problem of untranslated text during page transitions
|
|
35
|
-
*
|
|
36
|
-
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
37
|
-
*/
|
|
38
|
-
export declare function useT<N extends TranslateNamespace | undefined>(namespace?: N): <R extends unknown = string>(s: N extends TranslateNamespace ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: TranslationQuery, o?: TranslationOptions) => R;
|
|
39
|
-
/**
|
|
40
|
-
* @deprecated Not sure whether this will ever be useful
|
|
41
|
-
*/
|
|
42
|
-
export declare function useLooseT(namespace?: string): import("next-translate").Translate;
|
|
43
|
-
export declare function translationAsOptions(t: TranslateLoose, i18nKey: string): Option[];
|
|
44
|
-
/**
|
|
45
|
-
* Automatically returns the `date-fns/format` function with the right locale
|
|
46
|
-
* passed as option (grabbed from next router value).
|
|
47
|
-
*/
|
|
48
|
-
export declare const useDateFormat: () => typeof format;
|
|
1
|
+
import format from "date-fns/format";
|
|
2
|
+
import type { Option } from "@koine/react";
|
|
3
|
+
export { default as T } from "next-translate/Trans";
|
|
4
|
+
declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : never : never;
|
|
5
|
+
declare type Paths<T> = {
|
|
6
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? Join<K, Paths<T[K]>> : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
export declare type AllPaths = {
|
|
9
|
+
[N in keyof Koine.NextTranslations]: {
|
|
10
|
+
[K in keyof Koine.NextTranslations[N]]: Koine.NextTranslations[N][K] extends Array<Record<string, unknown>> ? Join<K extends string ? `${N}:${K}` : `${N}:`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends Record<string, unknown> ? Join<K extends string ? `${N}:${K}` : `${N}:`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends Array<string | number | boolean> ? Join<K extends string ? `${N}:${K}` : `${N}`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends string | number | boolean ? K extends string ? `${N}:${K}` : `${N}:` : ``;
|
|
11
|
+
}[keyof Koine.NextTranslations[N]];
|
|
12
|
+
}[keyof Koine.NextTranslations];
|
|
13
|
+
declare type TranslateReturn<Q extends TranslationQuery, O extends TranslationOptions> = string;
|
|
14
|
+
/**
|
|
15
|
+
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
16
|
+
*/
|
|
17
|
+
declare type TranslationQuery = undefined | null | "obj" | {
|
|
18
|
+
[key: string]: string | number | boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
22
|
+
*/
|
|
23
|
+
declare type TranslationOptions = undefined | "obj" | {
|
|
24
|
+
returnObjects?: boolean;
|
|
25
|
+
fallback?: string | string[];
|
|
26
|
+
default?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare type TranslateNamespace = keyof Koine.NextTranslations;
|
|
29
|
+
export declare type TranslateKey = AllPaths;
|
|
30
|
+
export declare type Translate<R extends unknown = string, N extends undefined | keyof Koine.NextTranslations = undefined, Q extends TranslationQuery = undefined, O extends TranslationOptions = undefined> = (s: N extends keyof Koine.NextTranslations ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: Q, o?: O) => R extends undefined | unknown ? TranslateReturn<Q, O> : R;
|
|
31
|
+
export declare type TranslateLoose = (s: any, q?: any, o?: any) => string;
|
|
32
|
+
/**
|
|
33
|
+
* FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
|
|
34
|
+
* problem of untranslated text during page transitions
|
|
35
|
+
*
|
|
36
|
+
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
37
|
+
*/
|
|
38
|
+
export declare function useT<N extends TranslateNamespace | undefined>(namespace?: N): <R extends unknown = string>(s: N extends TranslateNamespace ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: TranslationQuery, o?: TranslationOptions) => R;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Not sure whether this will ever be useful
|
|
41
|
+
*/
|
|
42
|
+
export declare function useLooseT(namespace?: string): import("next-translate").Translate;
|
|
43
|
+
export declare function translationAsOptions(t: TranslateLoose, i18nKey: string): Option[];
|
|
44
|
+
/**
|
|
45
|
+
* Automatically returns the `date-fns/format` function with the right locale
|
|
46
|
+
* passed as option (grabbed from next router value).
|
|
47
|
+
*/
|
|
48
|
+
export declare const useDateFormat: () => typeof format;
|