@koine/next 1.0.10 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/Analytics/AnalyticsGoogle.d.ts +5 -0
  2. package/Analytics/AnalyticsGoogle.js +33 -0
  3. package/Analytics/index.d.ts +1 -0
  4. package/Analytics/index.js +1 -0
  5. package/Analytics/package.json +6 -0
  6. package/Auth/helpers.d.ts +17 -0
  7. package/Auth/helpers.js +22 -0
  8. package/Auth/index.d.ts +4 -0
  9. package/Auth/index.js +4 -0
  10. package/Auth/package.json +6 -0
  11. package/Auth/useLogin.d.ts +7 -0
  12. package/Auth/useLogin.js +49 -0
  13. package/Auth/useLoginUrl.d.ts +1 -0
  14. package/Auth/useLoginUrl.js +11 -0
  15. package/Auth/useLogout.d.ts +6 -0
  16. package/Auth/useLogout.js +52 -0
  17. package/Favicon/Favicon.d.ts +3 -0
  18. package/Favicon/Favicon.js +5 -0
  19. package/Favicon/index.d.ts +1 -0
  20. package/Favicon/index.js +1 -0
  21. package/Favicon/package.json +6 -0
  22. package/Forms/index.d.ts +2 -0
  23. package/Forms/index.js +2 -0
  24. package/Forms/package.json +6 -0
  25. package/Forms/useForm.d.ts +32 -0
  26. package/Forms/useForm.js +35 -0
  27. package/Forms/useSubmit.d.ts +24 -0
  28. package/Forms/useSubmit.js +28 -0
  29. package/Head/Head.d.ts +1 -0
  30. package/Head/Head.js +1 -0
  31. package/Head/index.d.ts +1 -0
  32. package/Head/index.js +1 -0
  33. package/Head/package.json +6 -0
  34. package/I18n/I18n.d.ts +44 -0
  35. package/I18n/I18n.js +95 -0
  36. package/I18n/index.d.ts +1 -0
  37. package/I18n/index.js +1 -0
  38. package/I18n/package.json +6 -0
  39. package/Img/Img.d.ts +21 -0
  40. package/Img/Img.js +30 -0
  41. package/Img/index.d.ts +1 -0
  42. package/Img/index.js +1 -0
  43. package/Img/package.json +6 -0
  44. package/Link/Link.d.ts +9 -0
  45. package/Link/Link.js +11 -0
  46. package/Link/index.d.ts +1 -0
  47. package/Link/index.js +1 -0
  48. package/Link/package.json +6 -0
  49. package/NextProgress/NextProgress.d.ts +24 -0
  50. package/NextProgress/NextProgress.js +40 -0
  51. package/NextProgress/index.d.ts +2 -0
  52. package/NextProgress/index.js +1 -0
  53. package/NextProgress/package.json +6 -0
  54. package/Seo/Seo.d.ts +3 -0
  55. package/Seo/Seo.js +8 -0
  56. package/Seo/SeoDefaults.d.ts +3 -0
  57. package/Seo/SeoDefaults.js +12 -0
  58. package/Seo/helpers.d.ts +48 -0
  59. package/Seo/helpers.js +115 -0
  60. package/Seo/index.d.ts +12 -0
  61. package/Seo/index.js +12 -0
  62. package/Seo/package.json +6 -0
  63. package/Theme/Theme.d.ts +46 -0
  64. package/Theme/Theme.js +245 -0
  65. package/Theme/index.d.ts +1 -0
  66. package/Theme/index.js +1 -0
  67. package/Theme/package.json +6 -0
  68. package/app/AppHead.d.ts +2 -0
  69. package/app/AppHead.js +5 -0
  70. package/app/AppMain.d.ts +35 -0
  71. package/app/AppMain.js +1 -0
  72. package/app/css/AppMain.d.ts +8 -0
  73. package/app/css/AppMain.js +13 -0
  74. package/app/css/AppTheme.d.ts +10 -0
  75. package/app/css/AppTheme.js +14 -0
  76. package/app/css/auth/index.d.ts +9 -0
  77. package/app/css/auth/index.js +14 -0
  78. package/app/css/auth/package.json +6 -0
  79. package/app/css/index.d.ts +54 -0
  80. package/app/css/index.js +58 -0
  81. package/app/css/package.json +6 -0
  82. package/app/em/AppMain.d.ts +10 -0
  83. package/app/em/AppMain.js +24 -0
  84. package/app/em/AppTheme.d.ts +15 -0
  85. package/app/em/AppTheme.js +18 -0
  86. package/app/em/auth/index.d.ts +9 -0
  87. package/app/em/auth/index.js +14 -0
  88. package/app/em/auth/package.json +6 -0
  89. package/app/em/index.d.ts +9 -0
  90. package/app/em/index.js +13 -0
  91. package/app/em/package.json +6 -0
  92. package/app/index.d.ts +2 -0
  93. package/app/index.js +2 -0
  94. package/app/package.json +6 -0
  95. package/app/sc/AppMain.d.ts +10 -0
  96. package/app/sc/AppMain.js +24 -0
  97. package/app/sc/AppTheme.d.ts +13 -0
  98. package/app/sc/AppTheme.js +11 -0
  99. package/app/sc/auth/index.d.ts +9 -0
  100. package/app/sc/auth/index.js +14 -0
  101. package/app/sc/auth/package.json +6 -0
  102. package/app/sc/index.d.ts +56 -0
  103. package/app/sc/index.js +60 -0
  104. package/app/sc/package.json +6 -0
  105. package/config/index.d.ts +84 -0
  106. package/config/index.js +190 -0
  107. package/config/package.json +6 -0
  108. package/document/Document.d.ts +15 -0
  109. package/document/Document.js +26 -0
  110. package/document/css/index.d.ts +22 -0
  111. package/document/css/index.js +44 -0
  112. package/document/css/package.json +6 -0
  113. package/document/em/index.d.ts +16 -0
  114. package/document/em/index.js +59 -0
  115. package/document/em/package.json +6 -0
  116. package/document/index.d.ts +2 -0
  117. package/document/index.js +2 -0
  118. package/document/package.json +6 -0
  119. package/document/sc/index.d.ts +20 -0
  120. package/document/sc/index.js +65 -0
  121. package/document/sc/package.json +6 -0
  122. package/index.d.ts +12 -0
  123. package/index.js +12 -0
  124. package/package.json +11 -13
  125. package/utils/api.d.ts +55 -0
  126. package/utils/api.js +44 -0
  127. package/utils/emotion-cache.d.ts +5 -0
  128. package/utils/emotion-cache.js +8 -0
  129. package/utils/index.d.ts +19 -0
  130. package/utils/index.js +27 -0
  131. package/utils/package.json +6 -0
@@ -0,0 +1,5 @@
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,33 @@
1
+ import { __assign } from "tslib";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState, useEffect } from "react";
4
+ import { useRouter } from "next/router";
5
+ import Script from "next/script";
6
+ import { pageview } from "@koine/utils";
7
+ export var AnalyticsGoogle = function (_a) {
8
+ var id = _a.id;
9
+ var uid = id || process.env["NEXT_PUBLIC_GTM_ID"];
10
+ var _b = useRouter(), events = _b.events, asPath = _b.asPath, query = _b.query;
11
+ var _c = useState(false), ready = _c[0], setReady = _c[1];
12
+ var _d = useState(false), routed = _d[0], setRouted = _d[1];
13
+ // const [url, setUrl] = useState("");
14
+ useEffect(function () {
15
+ var handleRouteChange = function () {
16
+ setRouted(true);
17
+ };
18
+ events.on("routeChangeComplete", handleRouteChange);
19
+ return function () {
20
+ events.off("routeChangeComplete", handleRouteChange);
21
+ };
22
+ }, [events]);
23
+ useEffect(function () {
24
+ if (routed && ready && asPath) {
25
+ // const search = query;
26
+ pageview(asPath);
27
+ }
28
+ }, [asPath, query, routed, ready]);
29
+ if (!uid) {
30
+ return null;
31
+ }
32
+ return (_jsxs(_Fragment, { children: [_jsx(Script, { id: "google-tagmanager", src: "https://www.googletagmanager.com/gtag/js?id=".concat(id), strategy: "afterInteractive", onLoad: function () { return setReady(true); } }), _jsx(Script, __assign({ id: "google-analytics", strategy: "afterInteractive" }, { children: "\n window.dataLayer = window.dataLayer || [];\n function gtag(){window.dataLayer.push(arguments);}\n gtag('js', new Date());\n\n gtag('config', '".concat(id, "', { 'send_page_view': false });\n ") }))] }));
33
+ };
@@ -0,0 +1 @@
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
+ }
@@ -0,0 +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;
@@ -0,0 +1,22 @@
1
+ import { isString } from "@koine/utils";
2
+ export var 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(function (map, name) {
10
+ var routePage = AUTH_ROUTES[name];
11
+ // @ts-expect-error cannot remember
12
+ map[name] = isString(routePage) ? t("~:".concat(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) {
20
+ if (url === void 0) { url = window.location.href; }
21
+ return url.split("callbackUrl=")[1] || "";
22
+ }
@@ -0,0 +1,4 @@
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
+ }
@@ -0,0 +1,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,49 @@
1
+ import { __assign } from "tslib";
2
+ import { useState, useCallback } from "react";
3
+ import { useRouter } from "next/router";
4
+ import { signIn } from "next-auth/react";
5
+ import { parseURL } from "@koine/utils";
6
+ import { useT } from "../I18n";
7
+ import { getAuthRoutes, getCallbackUrl } from "./helpers";
8
+ export function useLogin() {
9
+ var t = useT();
10
+ var push = useRouter().push;
11
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
12
+ var _b = useState(false), ok = _b[0], setOk = _b[1];
13
+ var _c = useState(false), fail = _c[0], setFail = _c[1];
14
+ var submit = useCallback(function (data) {
15
+ setLoading(true);
16
+ signIn("credentials", __assign(__assign({}, data), { redirect: false }))
17
+ // @ts-expect-error FIXME: at some point...
18
+ .then(function (_a) {
19
+ var ok = _a.ok;
20
+ setLoading(false);
21
+ setOk(ok);
22
+ setFail(!ok);
23
+ if (ok) {
24
+ var redirectUrl = parseURL(getCallbackUrl());
25
+ var _b = getAuthRoutes(t), login = _b.login, register = _b.register, profile = _b.profile;
26
+ if (redirectUrl) {
27
+ var redirectPath = redirectUrl.pathname;
28
+ if (profile &&
29
+ (redirectPath === login || redirectPath === register)) {
30
+ push(profile);
31
+ }
32
+ else {
33
+ push(redirectPath + redirectUrl.search);
34
+ }
35
+ }
36
+ else if (profile) {
37
+ push(profile);
38
+ }
39
+ }
40
+ });
41
+ }, [t, push]);
42
+ // TODO: useMemo ?
43
+ return {
44
+ submit: submit,
45
+ loading: loading,
46
+ ok: ok,
47
+ fail: fail,
48
+ };
49
+ }
@@ -0,0 +1 @@
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
+ var _a = useState(""), currentUrl = _a[0], setCurrentUrl = _a[1];
6
+ var t = useT();
7
+ useEffect(function () {
8
+ setCurrentUrl("?callbackUrl=".concat(window.location.href));
9
+ }, []);
10
+ return "".concat(getAuthRoutes(t).login).concat(currentUrl);
11
+ }
@@ -0,0 +1,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
+ var t = useT();
9
+ var push = useRouter().push;
10
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
11
+ var _b = useState(false), ok = _b[0], setOk = _b[1];
12
+ var fail = useState(false)[0];
13
+ var submit = useCallback(function (event) {
14
+ event.preventDefault();
15
+ event.stopPropagation();
16
+ setLoading(true);
17
+ signOut({ redirect: false }).then(function () {
18
+ setLoading(false);
19
+ setOk(true);
20
+ var redirectUrl = parseURL(getCallbackUrl());
21
+ var currentUrl = parseURL(window.location.href);
22
+ var secured = getAuthRoutes(t).secured;
23
+ var signin = t("~:/signin");
24
+ var profile = t("~:/profile");
25
+ var targetUrl = redirectUrl || currentUrl;
26
+ var redirect = "";
27
+ if (targetUrl) {
28
+ if (targetUrl.pathname === profile) {
29
+ redirect = signin;
30
+ }
31
+ else if (secured) {
32
+ for (var 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: submit,
48
+ loading: loading,
49
+ ok: ok,
50
+ fail: fail,
51
+ };
52
+ }
@@ -0,0 +1,3 @@
1
+ import { FaviconTagsProps } from "@koine/react";
2
+ export declare type FaviconProps = FaviconTagsProps;
3
+ export declare const Favicon: (props: FaviconTagsProps) => JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { __assign } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import Head from "next/head";
4
+ import { FaviconTags } from "@koine/react";
5
+ export var Favicon = function (props) { return (_jsx(Head, { children: _jsx(FaviconTags, __assign({}, props)) })); };
@@ -0,0 +1 @@
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
+ }
@@ -0,0 +1,2 @@
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
+ }
@@ -0,0 +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
+ };
@@ -0,0 +1,35 @@
1
+ import { __assign } from "tslib";
2
+ import { useMemo } from "react";
3
+ import { useForm as _useForm } from "react-hook-form";
4
+ import { yupResolver as resolver } from "@hookform/resolvers/yup";
5
+ import { useT } from "../I18n";
6
+ export function useForm(
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ schema, i18nNamespace, formProps, debug) {
9
+ if (formProps === void 0) { formProps = {}; }
10
+ var t = useT(i18nNamespace);
11
+ // const form = _useForm<InferType<ObjectSchema<T, object>>>({
12
+ var form = _useForm(__assign({
13
+ // @ts-expect-error FIXME:
14
+ resolver: resolver(schema) }, formProps));
15
+ // const { control, register, setValue } = form;
16
+ // const field = { control, register, setValue, t };
17
+ // if (process.env["NODE_ENV"] !== "production") {
18
+ // if (debug) {
19
+ // console.log(
20
+ // `Form ${i18nNamespace} data`,
21
+ // form.watch(),
22
+ // `errors: `,
23
+ // form.formState.errors
24
+ // );
25
+ // }
26
+ // }
27
+ // if (formProps.mode === "onChange") {
28
+ // return { field, ...form };
29
+ // }
30
+ return useMemo(function () {
31
+ var control = form.control, register = form.register, setValue = form.setValue;
32
+ var field = { control: control, register: register, setValue: setValue, t: t };
33
+ return __assign({ field: field }, form);
34
+ }, [t, form]);
35
+ }
@@ -0,0 +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
+ });
@@ -0,0 +1,28 @@
1
+ import { __assign, __awaiter, __generator } from "tslib";
2
+ import { useAsyncFn } from "@koine/react";
3
+ import { api } from "../utils/api";
4
+ export function useSubmit(url, transformData) {
5
+ var _this = this;
6
+ var _a = useAsyncFn(function (json) { return __awaiter(_this, void 0, void 0, function () {
7
+ var response;
8
+ return __generator(this, function (_a) {
9
+ switch (_a.label) {
10
+ case 0:
11
+ if (transformData)
12
+ json = transformData(json);
13
+ return [4 /*yield*/, api.post(url, {
14
+ json: json,
15
+ })];
16
+ case 1:
17
+ response = _a.sent();
18
+ if (process.env["NODE_ENV"] !== "production") {
19
+ console.log("[@koine/next] useSubmit response", response);
20
+ }
21
+ return [2 /*return*/, response];
22
+ }
23
+ });
24
+ }); }, [url, transformData]), state = _a[0], submit = _a[1];
25
+ var loading = state.loading, error = state.error, value = state.value;
26
+ var fail = !loading && (!!error || (value === null || value === void 0 ? void 0 : value.fail));
27
+ return __assign(__assign({ submit: submit, loading: loading }, (value || {})), { fail: fail });
28
+ }
package/Head/Head.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as Head } from "next/head";
package/Head/Head.js ADDED
@@ -0,0 +1 @@
1
+ export { default as Head } from "next/head";
@@ -0,0 +1 @@
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
+ }
package/I18n/I18n.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ /// <reference types="@koine/next/typings" />
2
+ import format from "date-fns/format";
3
+ import type { Option } from "@koine/react";
4
+ export { default as T } from "next-translate/Trans";
5
+ declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : never : never;
6
+ declare type Paths<T> = {
7
+ [K in keyof T]: T[K] extends Record<string, unknown> ? Join<K, Paths<T[K]>> : K;
8
+ }[keyof T];
9
+ export declare type AllPaths = {
10
+ [N in keyof Koine.NextTranslations]: {
11
+ [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]>> & Record<Koine.NextTranslations[N][K], object> : 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}:` : ``;
12
+ }[keyof Koine.NextTranslations[N]];
13
+ }[keyof Koine.NextTranslations];
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<N extends undefined | keyof Koine.NextTranslations = undefined> = <R extends unknown = string>(s: N extends TranslateNamespace ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: TranslationQuery, o?: TranslationOptions) => 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
+ export declare function translationAsOptions(t: TranslateLoose, i18nKey: string): Option[];
40
+ /**
41
+ * Automatically returns the `date-fns/format` function with the right locale
42
+ * passed as option (grabbed from next router value).
43
+ */
44
+ export declare const useDateFormat: () => typeof format;
package/I18n/I18n.js ADDED
@@ -0,0 +1,95 @@
1
+ /// <reference types="@koine/next/typings" />
2
+ import { __assign } from "tslib";
3
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
4
+ /**
5
+ * @file
6
+ *
7
+ * About the typescript support for translation strings @see:
8
+ * - https://github.com/vinissimus/next-translate/issues/721
9
+ */
10
+ import { useEffect, useState, useMemo } from "react";
11
+ import { useRouter } from "next/router";
12
+ import format from "date-fns/format";
13
+ import useTranslation from "next-translate/useTranslation";
14
+ import { useDateLocale } from "@koine/react";
15
+ export { default as T } from "next-translate/Trans";
16
+ /**
17
+ * FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
18
+ * problem of untranslated text during page transitions
19
+ *
20
+ * @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
21
+ */
22
+ export function useT(namespace) {
23
+ var t = useTranslation().t;
24
+ // const typedT = <
25
+ // // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
26
+ // R extends unknown = string,
27
+ // // Q extends TranslationQuery = TranslationQuery
28
+ // // O extends TranslationOptions = TranslationOptions
29
+ // >(
30
+ // s: N extends TranslateNamespace
31
+ // ? Paths<Koine.NextTranslations[N]> | AllPaths
32
+ // : AllPaths,
33
+ // q?: TranslationQuery,
34
+ // o?: TranslationOptions
35
+ // ) =>
36
+ // // eslint-disable-next-line
37
+ // t.call(
38
+ // null,
39
+ // namespace ? `${namespace}:${s}` : s,
40
+ // q === "obj" ? null : q,
41
+ // q === "obj" || o === "obj" ? { returnObjects: true } : o
42
+ // // ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
43
+ // ) as R;
44
+ // return typedT;
45
+ var tMemoized = useMemo(function () {
46
+ return function (s, q, o) {
47
+ return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
48
+ // ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
49
+ );
50
+ };
51
+ }, [t, namespace]);
52
+ // return tMemoized as Translate<N>;
53
+ return tMemoized;
54
+ }
55
+ export function translationAsOptions(t, i18nKey) {
56
+ var dictionary = t(i18nKey, undefined, {
57
+ returnObjects: true,
58
+ });
59
+ return Object.keys(dictionary).map(function (key) { return ({
60
+ value: key,
61
+ label: dictionary[key],
62
+ }); });
63
+ }
64
+ /**
65
+ * Automatically returns the `date-fns/format` function with the right locale
66
+ * passed as option (grabbed from next router value).
67
+ */
68
+ export var useDateFormat = function () {
69
+ var _a = useState(function () {
70
+ return function () {
71
+ var args = [];
72
+ for (var _i = 0; _i < arguments.length; _i++) {
73
+ args[_i] = arguments[_i];
74
+ }
75
+ return format.apply(void 0, args);
76
+ };
77
+ }), formatter = _a[0], setFormatter = _a[1];
78
+ var router = useRouter();
79
+ var locale = useDateLocale(router.locale);
80
+ useEffect(function () {
81
+ if (locale) {
82
+ var newFormatter_1 = function (date, _format, options) { return format(date, _format, __assign(__assign({}, (options || {})), { locale: locale })); };
83
+ setFormatter(function () {
84
+ return function () {
85
+ var args = [];
86
+ for (var _i = 0; _i < arguments.length; _i++) {
87
+ args[_i] = arguments[_i];
88
+ }
89
+ return newFormatter_1.apply(void 0, args);
90
+ };
91
+ });
92
+ }
93
+ }, [locale]);
94
+ return formatter;
95
+ };
@@ -0,0 +1 @@
1
+ export * from "./I18n";
package/I18n/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./I18n";
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/I18n/index.js",
5
+ "types": "./index.d.ts"
6
+ }
package/Img/Img.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import NextImage, { ImageProps, StaticImageData } from "next/image";
3
+ import type { KoineImgSmartProps, KoineImgSmartWrapProps } from "@koine/react";
4
+ interface StaticRequire {
5
+ default: StaticImageData;
6
+ }
7
+ declare type StaticImport = StaticRequire | StaticImageData;
8
+ export declare type NextImgProps = Omit<React.ComponentPropsWithoutRef<"img">, "src"> & Omit<ImageProps, "src"> & {
9
+ src: string | StaticImport;
10
+ };
11
+ export declare const NextImg: typeof NextImage;
12
+ export declare type NextImgSmartWrapProps = KoineImgSmartWrapProps;
13
+ export declare type NextImgSmartProps = KoineImgSmartProps & NextImgProps;
14
+ export declare const NextImgSmart: (props: NextImgSmartProps) => JSX.Element;
15
+ export declare function getNextImgProps<T>({ src, alt, layout, blurDataURL, width, height, priority, objectFit, objectPosition, ...restProps }: T & NextImgProps): {
16
+ nextImgProps: NextImgProps;
17
+ restProps: Omit<T & Omit<Pick<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "key" | keyof React.ImgHTMLAttributes<HTMLImageElement>>, "src"> & Omit<ImageProps, "src"> & {
18
+ src: string | StaticImport;
19
+ }, "src" | "alt" | "height" | "width" | "layout" | "priority" | "blurDataURL" | "objectFit" | "objectPosition">;
20
+ };
21
+ export {};