@koine/next 1.0.4 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/Analytics/AnalyticsGoogle.d.ts +5 -6
  2. package/Analytics/AnalyticsGoogle.js +37 -0
  3. package/Analytics/index.d.ts +1 -1
  4. package/Analytics/index.js +1 -0
  5. package/Analytics/package.json +6 -0
  6. package/Auth/helpers.d.ts +17 -17
  7. package/Auth/helpers.js +21 -0
  8. package/Auth/index.d.ts +4 -4
  9. package/Auth/index.js +4 -0
  10. package/Auth/package.json +6 -0
  11. package/Auth/useLogin.d.ts +7 -7
  12. package/Auth/useLogin.js +50 -0
  13. package/Auth/useLoginUrl.d.ts +1 -1
  14. package/Auth/useLoginUrl.js +11 -0
  15. package/Auth/useLogout.d.ts +6 -6
  16. package/Auth/useLogout.js +52 -0
  17. package/Favicon/Favicon.d.ts +3 -4
  18. package/Favicon/Favicon.js +4 -0
  19. package/Favicon/index.d.ts +1 -1
  20. package/Favicon/index.js +1 -0
  21. package/Favicon/package.json +6 -0
  22. package/Forms/index.d.ts +2 -2
  23. package/Forms/index.js +2 -0
  24. package/Forms/package.json +6 -0
  25. package/Forms/useForm.d.ts +32 -32
  26. package/Forms/useForm.js +37 -0
  27. package/Forms/useSubmit.d.ts +24 -24
  28. package/Forms/useSubmit.js +23 -0
  29. package/Head/Head.d.ts +1 -1
  30. package/Head/Head.js +1 -0
  31. package/Head/index.d.ts +1 -1
  32. package/Head/index.js +1 -0
  33. package/Head/package.json +6 -0
  34. package/I18n/I18n.d.ts +44 -48
  35. package/I18n/I18n.js +74 -0
  36. package/I18n/index.d.ts +1 -1
  37. package/I18n/index.js +1 -0
  38. package/I18n/package.json +6 -0
  39. package/Img/Img.d.ts +21 -21
  40. package/Img/Img.js +28 -0
  41. package/Img/index.d.ts +1 -1
  42. package/Img/index.js +1 -0
  43. package/Img/package.json +6 -0
  44. package/Link/Link.d.ts +9 -8
  45. package/Link/Link.js +9 -0
  46. package/Link/index.d.ts +1 -1
  47. package/Link/index.js +1 -0
  48. package/Link/package.json +6 -0
  49. package/NextProgress/NextProgress.d.ts +24 -14
  50. package/NextProgress/NextProgress.js +37 -0
  51. package/NextProgress/index.d.ts +2 -1
  52. package/NextProgress/index.js +1 -0
  53. package/NextProgress/package.json +6 -0
  54. package/README.md +0 -0
  55. package/Seo/Seo.d.ts +3 -3
  56. package/Seo/Seo.js +8 -0
  57. package/Seo/SeoDefaults.d.ts +3 -3
  58. package/Seo/SeoDefaults.js +12 -0
  59. package/Seo/helpers.d.ts +48 -48
  60. package/Seo/helpers.js +111 -0
  61. package/Seo/index.d.ts +12 -12
  62. package/Seo/index.js +12 -0
  63. package/Seo/package.json +6 -0
  64. package/Theme/Theme.d.ts +46 -46
  65. package/Theme/Theme.js +235 -0
  66. package/Theme/index.d.ts +1 -1
  67. package/Theme/index.js +1 -0
  68. package/Theme/package.json +6 -0
  69. package/app/AppHead.d.ts +2 -3
  70. package/app/AppHead.js +5 -0
  71. package/app/AppMain.d.ts +35 -34
  72. package/app/AppMain.js +1 -0
  73. package/app/css/AppMain.d.ts +8 -0
  74. package/app/css/AppMain.js +11 -0
  75. package/app/css/AppTheme.d.ts +10 -0
  76. package/app/css/AppTheme.js +12 -0
  77. package/app/css/auth/index.d.ts +9 -0
  78. package/app/css/auth/index.js +13 -0
  79. package/app/css/auth/package.json +6 -0
  80. package/app/css/index.d.ts +54 -0
  81. package/app/css/index.js +57 -0
  82. package/app/css/package.json +6 -0
  83. package/app/em/AppMain.d.ts +10 -0
  84. package/app/em/AppMain.js +22 -0
  85. package/app/{AppTheme--emotion.d.ts → em/AppTheme.d.ts} +15 -15
  86. package/app/em/AppTheme.js +17 -0
  87. package/app/em/auth/index.d.ts +9 -0
  88. package/app/em/auth/index.js +13 -0
  89. package/app/em/auth/package.json +6 -0
  90. package/app/em/index.d.ts +9 -0
  91. package/app/em/index.js +12 -0
  92. package/app/em/package.json +6 -0
  93. package/app/index.d.ts +2 -11
  94. package/app/index.js +2 -0
  95. package/app/package.json +6 -0
  96. package/app/sc/AppMain.d.ts +10 -0
  97. package/app/sc/AppMain.js +22 -0
  98. package/app/sc/AppTheme.d.ts +13 -0
  99. package/app/sc/AppTheme.js +9 -0
  100. package/app/sc/auth/index.d.ts +9 -0
  101. package/app/sc/auth/index.js +13 -0
  102. package/app/sc/auth/package.json +6 -0
  103. package/app/sc/index.d.ts +56 -0
  104. package/app/sc/index.js +59 -0
  105. package/app/sc/package.json +6 -0
  106. package/config/index.d.ts +71 -58
  107. package/config/index.js +174 -0
  108. package/config/package.json +6 -0
  109. package/document/Document.d.ts +15 -10
  110. package/document/Document.js +19 -0
  111. package/document/css/index.d.ts +22 -0
  112. package/document/css/index.js +30 -0
  113. package/document/css/package.json +6 -0
  114. package/document/em/index.d.ts +16 -0
  115. package/document/em/index.js +68 -0
  116. package/document/em/package.json +6 -0
  117. package/document/index.d.ts +2 -4
  118. package/document/index.js +2 -0
  119. package/document/package.json +6 -0
  120. package/document/{Document--sc.d.ts → sc/index.d.ts} +20 -11
  121. package/document/sc/index.js +44 -0
  122. package/document/sc/package.json +6 -0
  123. package/index.d.ts +12 -12
  124. package/index.js +12 -743
  125. package/node/Analytics/AnalyticsGoogle.js +42 -0
  126. package/node/Analytics/index.js +4 -0
  127. package/node/Auth/helpers.js +26 -0
  128. package/node/Auth/index.js +7 -0
  129. package/node/Auth/useLogin.js +54 -0
  130. package/node/Auth/useLoginUrl.js +15 -0
  131. package/node/Auth/useLogout.js +56 -0
  132. package/node/Favicon/Favicon.js +9 -0
  133. package/node/Favicon/index.js +4 -0
  134. package/node/Forms/index.js +5 -0
  135. package/node/Forms/useForm.js +41 -0
  136. package/node/Forms/useSubmit.js +27 -0
  137. package/node/Head/Head.js +8 -0
  138. package/node/Head/index.js +4 -0
  139. package/node/I18n/I18n.js +82 -0
  140. package/node/I18n/index.js +4 -0
  141. package/node/Img/Img.js +34 -0
  142. package/node/Img/index.js +4 -0
  143. package/node/Link/Link.js +13 -0
  144. package/node/Link/index.js +4 -0
  145. package/node/NextProgress/NextProgress.js +41 -0
  146. package/node/NextProgress/index.js +5 -0
  147. package/node/Seo/Seo.js +12 -0
  148. package/node/Seo/SeoDefaults.js +16 -0
  149. package/node/Seo/helpers.js +115 -0
  150. package/node/Seo/index.js +15 -0
  151. package/node/Theme/Theme.js +241 -0
  152. package/node/Theme/index.js +4 -0
  153. package/node/app/AppHead.js +10 -0
  154. package/node/app/AppMain.js +2 -0
  155. package/node/app/css/AppMain.js +16 -0
  156. package/node/app/css/AppTheme.js +16 -0
  157. package/node/app/css/auth/index.js +18 -0
  158. package/node/app/css/index.js +62 -0
  159. package/node/app/em/AppMain.js +26 -0
  160. package/node/app/em/AppTheme.js +22 -0
  161. package/node/app/em/auth/index.js +18 -0
  162. package/node/app/em/index.js +17 -0
  163. package/node/app/index.js +5 -0
  164. package/node/app/sc/AppMain.js +26 -0
  165. package/node/app/sc/AppTheme.js +13 -0
  166. package/node/app/sc/auth/index.js +18 -0
  167. package/node/app/sc/index.js +64 -0
  168. package/node/config/index.js +184 -0
  169. package/node/document/Document.js +24 -0
  170. package/node/document/css/index.js +35 -0
  171. package/node/document/em/index.js +73 -0
  172. package/node/document/index.js +7 -0
  173. package/node/document/sc/index.js +49 -0
  174. package/node/index.js +15 -0
  175. package/node/utils/api.js +38 -0
  176. package/node/utils/emotion-cache.js +13 -0
  177. package/node/utils/index.js +32 -0
  178. package/package.json +3 -30
  179. package/{types.d.ts → typings.d.ts} +10 -7
  180. package/utils/api.d.ts +55 -55
  181. package/utils/api.js +35 -0
  182. package/{document/emotion.d.ts → utils/emotion-cache.d.ts} +5 -5
  183. package/utils/emotion-cache.js +8 -0
  184. package/utils/index.d.ts +19 -19
  185. package/utils/index.js +26 -0
  186. package/utils/package.json +6 -0
  187. package/Theme.js +0 -1905
  188. package/_tslib.js +0 -41
  189. package/app/App--emotion.d.ts +0 -10
  190. package/app/App--sc.d.ts +0 -10
  191. package/app/App--vanilla.d.ts +0 -10
  192. package/app/AppAuth--emotion.d.ts +0 -10
  193. package/app/AppAuth--sc.d.ts +0 -10
  194. package/app/AppMain--vanilla.d.ts +0 -27
  195. package/app/AppTheme--sc.d.ts +0 -13
  196. package/app/AppTheme--vanilla.d.ts +0 -10
  197. package/app/motion-features.d.ts +0 -2
  198. package/app.js +0 -250
  199. package/config.js +0 -183
  200. package/document/Document--emotion.d.ts +0 -5
  201. package/document/Document--vanilla.d.ts +0 -11
  202. package/document.js +0 -207
  203. package/emotion.js +0 -1329
  204. package/es.object.assign.js +0 -1074
  205. package/es.string.replace.js +0 -785
  206. package/es.string.split.js +0 -201
  207. package/index.esm.js +0 -4600
  208. package/index.umd.js +0 -4638
  209. package/motion-features.js +0 -10
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
- export declare type AnalyticsGoogleProps = {
3
- /** Falls back to `.env` variable `NEXT_PUBLIC_GTM_ID` */
4
- id?: string;
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, { 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
+ };
@@ -1 +1 @@
1
- export * from "./AnalyticsGoogle";
1
+ export * from "./AnalyticsGoogle";
@@ -0,0 +1 @@
1
+ export * from "./AnalyticsGoogle";
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/Analytics/index.js",
5
+ "types": "./index.d.ts"
6
+ }
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;
@@ -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
@@ -0,0 +1,4 @@
1
+ export * from "./helpers";
2
+ export * from "./useLogin";
3
+ export * from "./useLoginUrl";
4
+ export * from "./useLogout";
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/Auth/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -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 extends {} = {}>(): {
3
+ submit: SubmitHandler<LoginForm>;
4
+ loading: boolean;
5
+ ok: boolean;
6
+ fail: boolean;
7
+ };
@@ -0,0 +1,50 @@
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", {
16
+ ...data,
17
+ redirect: false,
18
+ })
19
+ // @ts-expect-error FIXME: at some point...
20
+ .then(({ ok }) => {
21
+ setLoading(false);
22
+ setOk(ok);
23
+ setFail(!ok);
24
+ if (ok) {
25
+ const redirectUrl = parseURL(getCallbackUrl());
26
+ const { login, register, profile } = getAuthRoutes(t);
27
+ if (redirectUrl) {
28
+ const redirectPath = redirectUrl.pathname;
29
+ if (profile &&
30
+ (redirectPath === login || redirectPath === register)) {
31
+ push(profile);
32
+ }
33
+ else {
34
+ push(redirectPath + redirectUrl.search);
35
+ }
36
+ }
37
+ else if (profile) {
38
+ push(profile);
39
+ }
40
+ }
41
+ });
42
+ }, [t, push]);
43
+ // TODO: useMemo ?
44
+ return {
45
+ submit,
46
+ loading,
47
+ ok,
48
+ fail,
49
+ };
50
+ }
@@ -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
+ }
@@ -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
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
- import { FaviconTagsProps } from "@koine/react";
3
- export declare type FaviconProps = FaviconTagsProps;
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;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Head from "next/head";
3
+ import { FaviconTags } from "@koine/react";
4
+ export const Favicon = (props) => (_jsx(Head, { children: _jsx(FaviconTags, { ...props }) }));
@@ -1 +1 @@
1
- export * from "./Favicon";
1
+ export * from "./Favicon";
@@ -0,0 +1 @@
1
+ export * from "./Favicon";
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/Favicon/index.js",
5
+ "types": "./index.d.ts"
6
+ }
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
@@ -0,0 +1,2 @@
1
+ export * from "./useForm";
2
+ export * from "./useSubmit";
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/Forms/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -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
+ };
@@ -0,0 +1,37 @@
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({
11
+ // @ts-expect-error FIXME:
12
+ resolver: resolver(schema),
13
+ // make the form behave more closer as native:
14
+ // shouldUnregister: true,
15
+ ...formProps,
16
+ });
17
+ // const { control, register, setValue } = form;
18
+ // const field = { control, register, setValue, t };
19
+ // if ("production" !== process.env["NODE_ENV"]) {
20
+ // if (debug) {
21
+ // console.log(
22
+ // `Form ${i18nNamespace} data`,
23
+ // form.watch(),
24
+ // `errors: `,
25
+ // form.formState.errors
26
+ // );
27
+ // }
28
+ // }
29
+ // if (formProps.mode === "onChange") {
30
+ // return { field, ...form };
31
+ // }
32
+ return useMemo(() => {
33
+ const { control, register, setValue } = form;
34
+ const field = { control, register, setValue, t };
35
+ return { field, ...form };
36
+ }, [t, form]);
37
+ }
@@ -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,23 @@
1
+ import { useAsyncFn } from "react-use";
2
+ import { api } from "../utils/api";
3
+ export function useSubmit(url, transformData) {
4
+ const [state, submit] = useAsyncFn(async (json) => {
5
+ if (transformData)
6
+ json = transformData(json);
7
+ const response = await api.post(url, {
8
+ json,
9
+ });
10
+ if ("production" !== process.env["NODE_ENV"]) {
11
+ console.log("[@koine/next] useSubmit response", response);
12
+ }
13
+ return response;
14
+ }, [url, transformData]);
15
+ const { loading, error, value } = state;
16
+ const fail = !loading && (!!error || value?.fail);
17
+ return {
18
+ submit,
19
+ loading,
20
+ ...(value || {}),
21
+ fail,
22
+ };
23
+ }
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";
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/Head/index.js",
5
+ "types": "./index.d.ts"
6
+ }