@koine/next 1.0.14 → 1.0.17
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/Auth/helpers.d.ts +2 -2
- package/Auth/useLogin.js +1 -1
- package/Auth/useLoginUrl.js +1 -1
- package/Auth/useLogout.js +1 -1
- package/Forms/index.d.ts +0 -1
- package/Forms/index.js +0 -1
- package/Forms/useForm.d.ts +3 -9
- package/Forms/useForm.js +1 -3
- package/i18n/T/index.d.ts +8 -0
- package/i18n/T/index.js +6 -0
- package/i18n/T/package.json +6 -0
- package/i18n/getT/index.d.ts +3 -0
- package/i18n/getT/index.js +9 -0
- package/i18n/getT/package.json +6 -0
- package/i18n/index.d.ts +6 -0
- package/i18n/index.js +6 -0
- package/{I18n → i18n}/package.json +1 -1
- package/i18n/translationAsOptions/index.d.ts +3 -0
- package/i18n/translationAsOptions/index.js +9 -0
- package/i18n/translationAsOptions/package.json +6 -0
- package/i18n/useDateFormat/index.d.ts +6 -0
- package/i18n/useDateFormat/index.js +37 -0
- package/i18n/useDateFormat/package.json +6 -0
- package/i18n/useLocale/index.d.ts +1 -0
- package/i18n/useLocale/index.js +4 -0
- package/i18n/useLocale/package.json +6 -0
- package/i18n/useT/index.d.ts +50 -0
- package/i18n/useT/index.js +115 -0
- package/i18n/useT/package.json +6 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/node/Analytics/AnalyticsGoogle.js +37 -0
- package/node/Analytics/index.js +4 -0
- package/node/Auth/helpers.js +27 -0
- package/node/Auth/index.js +7 -0
- package/node/Auth/useLogin.js +53 -0
- package/node/Auth/useLoginUrl.js +15 -0
- package/node/Auth/useLogout.js +56 -0
- package/node/Favicon/Favicon.js +9 -0
- package/node/Favicon/index.js +4 -0
- package/node/Forms/index.js +4 -0
- package/node/Forms/useForm.js +37 -0
- package/node/Head/Head.js +5 -0
- package/node/Head/index.js +4 -0
- package/node/Img/Img.js +35 -0
- package/node/Img/index.js +4 -0
- package/node/Link/Link.js +14 -0
- package/node/Link/index.js +4 -0
- package/node/NextProgress/NextProgress.js +44 -0
- package/node/NextProgress/index.js +5 -0
- package/node/Seo/Seo.js +12 -0
- package/node/Seo/SeoDefaults.js +16 -0
- package/node/Seo/helpers.js +119 -0
- package/node/Seo/index.js +15 -0
- package/node/Theme/Theme.js +250 -0
- package/node/Theme/index.js +4 -0
- package/node/app/AppHead.js +10 -0
- package/node/app/AppMain.js +2 -0
- package/node/app/css/AppMain.js +17 -0
- package/node/app/css/AppTheme.js +18 -0
- package/node/app/css/auth/index.js +18 -0
- package/node/app/css/index.js +62 -0
- package/node/app/em/AppMain.js +28 -0
- package/node/app/em/AppTheme.js +22 -0
- package/node/app/em/auth/index.js +18 -0
- package/node/app/em/index.js +17 -0
- package/node/app/index.js +5 -0
- package/node/app/sc/AppMain.js +28 -0
- package/node/app/sc/AppTheme.js +15 -0
- package/node/app/sc/auth/index.js +18 -0
- package/node/app/sc/index.js +64 -0
- package/node/config/index.js +201 -0
- package/node/document/Document.js +29 -0
- package/node/document/css/index.js +47 -0
- package/node/document/em/index.js +62 -0
- package/node/document/index.js +7 -0
- package/node/document/sc/index.js +68 -0
- package/node/i18n/T/index.js +10 -0
- package/node/i18n/getT/index.js +13 -0
- package/node/i18n/index.js +9 -0
- package/node/i18n/translationAsOptions/index.js +13 -0
- package/node/i18n/useDateFormat/index.js +41 -0
- package/node/i18n/useLocale/index.js +9 -0
- package/node/i18n/useT/index.js +120 -0
- package/node/index.js +15 -0
- package/node/utils/emotion-cache.js +13 -0
- package/node/utils/index.js +31 -0
- package/package.json +4 -4
- package/typings.d.ts +19 -10
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/I18n/I18n.d.ts +0 -44
- package/I18n/I18n.js +0 -95
- package/I18n/index.d.ts +0 -1
- package/I18n/index.js +0 -1
package/Auth/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TranslateLoose } from "../i18n";
|
|
2
2
|
/**
|
|
3
3
|
* @see next/auth `pages` mapping: https://next-auth.js.org/configuration/pages`
|
|
4
4
|
*/
|
|
@@ -10,7 +10,7 @@ export declare type AuthRoutesMap = {
|
|
|
10
10
|
secured?: RegExp[];
|
|
11
11
|
};
|
|
12
12
|
export declare const AUTH_ROUTES: AuthRoutesMap;
|
|
13
|
-
export declare function getAuthRoutes(t:
|
|
13
|
+
export declare function getAuthRoutes(t: TranslateLoose): AuthRoutesMap;
|
|
14
14
|
/**
|
|
15
15
|
* @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
|
|
16
16
|
*/
|
package/Auth/useLogin.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useState, useCallback } from "react";
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
import { signIn } from "next-auth/react";
|
|
5
5
|
import { parseURL } from "@koine/utils";
|
|
6
|
-
import { useT } from "../
|
|
6
|
+
import { useT } from "../i18n";
|
|
7
7
|
import { getAuthRoutes, getCallbackUrl } from "./helpers";
|
|
8
8
|
export function useLogin() {
|
|
9
9
|
var t = useT();
|
package/Auth/useLoginUrl.js
CHANGED
package/Auth/useLogout.js
CHANGED
|
@@ -2,7 +2,7 @@ import { useState, useCallback } from "react";
|
|
|
2
2
|
import { useRouter } from "next/router";
|
|
3
3
|
import { signOut } from "next-auth/react";
|
|
4
4
|
import { parseURL } from "@koine/utils";
|
|
5
|
-
import { useT } from "../
|
|
5
|
+
import { useT } from "../i18n";
|
|
6
6
|
import { getAuthRoutes, getCallbackUrl } from "./helpers";
|
|
7
7
|
export function useLogout() {
|
|
8
8
|
var t = useT();
|
package/Forms/index.d.ts
CHANGED
package/Forms/index.js
CHANGED
package/Forms/useForm.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { UseFormProps, FieldValues } from "react-hook-form";
|
|
2
2
|
import type { ObjectSchema } from "yup";
|
|
3
|
-
import {
|
|
4
|
-
export declare function useForm<T extends FieldValues>(schema: ObjectSchema<any>,
|
|
3
|
+
import { type TranslateLoose } from "../i18n";
|
|
4
|
+
export declare function useForm<T extends FieldValues>(schema: ObjectSchema<any>, t: TranslateLoose, formProps?: UseFormProps, debug?: boolean): {
|
|
5
5
|
watch: import("react-hook-form").UseFormWatch<T>;
|
|
6
6
|
getValues: import("react-hook-form").UseFormGetValues<T>;
|
|
7
7
|
getFieldState: import("react-hook-form").UseFormGetFieldState<T>;
|
|
@@ -21,12 +21,6 @@ export declare function useForm<T extends FieldValues>(schema: ObjectSchema<any>
|
|
|
21
21
|
control: import("react-hook-form").Control<T, any>;
|
|
22
22
|
register: import("react-hook-form").UseFormRegister<T>;
|
|
23
23
|
setValue: import("react-hook-form").UseFormSetValue<T>;
|
|
24
|
-
t:
|
|
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;
|
|
24
|
+
t: TranslateLoose;
|
|
31
25
|
};
|
|
32
26
|
};
|
package/Forms/useForm.js
CHANGED
|
@@ -2,12 +2,10 @@ import { __assign } from "tslib";
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useForm as _useForm } from "react-hook-form";
|
|
4
4
|
import { yupResolver as resolver } from "@hookform/resolvers/yup";
|
|
5
|
-
import { useT } from "../I18n";
|
|
6
5
|
export function useForm(
|
|
7
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
schema,
|
|
7
|
+
schema, t, formProps, debug) {
|
|
9
8
|
if (formProps === void 0) { formProps = {}; }
|
|
10
|
-
var t = useT(i18nNamespace);
|
|
11
9
|
// const form = _useForm<InferType<ObjectSchema<T, object>>>({
|
|
12
10
|
var form = _useForm(__assign({
|
|
13
11
|
// @ts-expect-error FIXME:
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TransProps } from "next-translate";
|
|
3
|
+
import type { TranslationsPaths, TranslationsAllPaths } from "../useT";
|
|
4
|
+
export declare type TProps<TNamespace extends keyof Koine.NextTranslations | undefined = undefined> = Omit<TransProps, "i18nKey" | "ns"> & {
|
|
5
|
+
i18nKey: TNamespace extends keyof Koine.NextTranslations ? TranslationsPaths<Koine.NextTranslations[TNamespace]> : TranslationsAllPaths;
|
|
6
|
+
ns?: TNamespace;
|
|
7
|
+
};
|
|
8
|
+
export declare function T(props: TProps): JSX.Element;
|
package/i18n/T/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
2
|
+
/**
|
|
3
|
+
* @file
|
|
4
|
+
*
|
|
5
|
+
* About the typescript support for translation strings @see:
|
|
6
|
+
* - https://github.com/vinissimus/next-translate/issues/721
|
|
7
|
+
*/
|
|
8
|
+
import getTranslation from "next-translate/getT";
|
|
9
|
+
export var getT = getTranslation;
|
package/i18n/index.d.ts
ADDED
package/i18n/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
import format from "date-fns/format";
|
|
5
|
+
import { useDateLocale } from "@koine/react";
|
|
6
|
+
/**
|
|
7
|
+
* Automatically returns the `date-fns/format` function with the right locale
|
|
8
|
+
* passed as option (grabbed from next router value).
|
|
9
|
+
*/
|
|
10
|
+
export var useDateFormat = function () {
|
|
11
|
+
var _a = useState(function () {
|
|
12
|
+
return function () {
|
|
13
|
+
var args = [];
|
|
14
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
15
|
+
args[_i] = arguments[_i];
|
|
16
|
+
}
|
|
17
|
+
return format.apply(void 0, args);
|
|
18
|
+
};
|
|
19
|
+
}), formatter = _a[0], setFormatter = _a[1];
|
|
20
|
+
var router = useRouter();
|
|
21
|
+
var locale = useDateLocale(router.locale);
|
|
22
|
+
useEffect(function () {
|
|
23
|
+
if (locale) {
|
|
24
|
+
var newFormatter_1 = function (date, _format, options) { return format(date, _format, __assign(__assign({}, (options || {})), { locale: locale })); };
|
|
25
|
+
setFormatter(function () {
|
|
26
|
+
return function () {
|
|
27
|
+
var args = [];
|
|
28
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
29
|
+
args[_i] = arguments[_i];
|
|
30
|
+
}
|
|
31
|
+
return newFormatter_1.apply(void 0, args);
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}, [locale]);
|
|
36
|
+
return formatter;
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLocale(): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare type TranslateNamespace = Extract<keyof Koine.NextTranslations, string>;
|
|
2
|
+
declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : never : never;
|
|
3
|
+
export declare type TranslationsPaths<T, TAddRoot extends true | undefined = undefined> = {
|
|
4
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? K extends string ? TAddRoot extends true ? `${K}` | Join<K, TranslationsPaths<T[K]>> : Join<K, TranslationsPaths<T[K]>> : Join<K, TranslationsPaths<T[K], TAddRoot>> : K;
|
|
5
|
+
}[keyof T];
|
|
6
|
+
export declare type TranslationsAllPaths = {
|
|
7
|
+
[N in Extract<keyof Koine.NextTranslations, string>]: {
|
|
8
|
+
[K in Extract<keyof Koine.NextTranslations[N], string>]: Koine.NextTranslations[N][K] extends Array<Record<string, unknown>> ? Join<K extends string ? `${N}:${K}` : `${N}:`, TranslationsPaths<Koine.NextTranslations[N][K], true>> : Koine.NextTranslations[N][K] extends Record<string, unknown> ? Join<K extends string ? `${N}:${K}` : `${N}:`, TranslationsPaths<Koine.NextTranslations[N][K], true>> : Koine.NextTranslations[N][K] extends Array<string | number | boolean> ? Join<K extends string ? `${N}:${K}` : `${N}:`, TranslationsPaths<Koine.NextTranslations[N][K], true>> : Koine.NextTranslations[N][K] extends string | number | boolean ? K extends string ? `${N}:${K}` : `${N}:` : ``;
|
|
9
|
+
}[Extract<keyof Koine.NextTranslations[N], string>];
|
|
10
|
+
}[Extract<keyof Koine.NextTranslations, string>];
|
|
11
|
+
/**
|
|
12
|
+
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
13
|
+
*/
|
|
14
|
+
export declare type TranslationQuery = undefined | null | "obj" | {
|
|
15
|
+
[key: string]: string | number | boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
19
|
+
*/
|
|
20
|
+
export declare type TranslationOptions = undefined | "obj" | {
|
|
21
|
+
returnObjects?: boolean;
|
|
22
|
+
fallback?: string | string[];
|
|
23
|
+
default?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare type TranslateLoose = (s: any, // s: string,
|
|
26
|
+
q?: any, // q?: TranslationQuery,
|
|
27
|
+
o?: any) => string;
|
|
28
|
+
export declare type Translate<TNamespace extends keyof Koine.NextTranslations | undefined> = TNamespace extends keyof Koine.NextTranslations ? TranslateNamespaced<TNamespace> : TranslateDefault;
|
|
29
|
+
export declare type TranslateDefault = <TReturn extends unknown = string>(s: TranslationsAllPaths, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
|
|
30
|
+
export declare type TranslateNamespaced<TNamespace extends keyof Koine.NextTranslations> = <TReturn extends unknown = string>(s: TranslationsPaths<Koine.NextTranslations[TNamespace]>, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
|
|
31
|
+
/**
|
|
32
|
+
* Wrap `next-translate` useTranslations adding the `obj` second argument shortcut
|
|
33
|
+
* and type safety
|
|
34
|
+
*
|
|
35
|
+
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
36
|
+
*/
|
|
37
|
+
export declare function useT(): TranslateDefault;
|
|
38
|
+
export declare function useT<TNamespace extends TranslateNamespace>(namespace: TNamespace): TranslateNamespaced<TNamespace>;
|
|
39
|
+
export {};
|
|
40
|
+
/**
|
|
41
|
+
* Using this as generic instead of the interface on the namespace `Koine.NextTranslations`
|
|
42
|
+
* generates the typescript warning `Type instantiation is excessively deep and possibly infinite.`
|
|
43
|
+
* Its usage is left here and commented out. Maybe we can restore it once we find
|
|
44
|
+
* the time to look for a way to avoid the warning
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
|
|
48
|
+
* we might just rewrite it with our custom implementation but the `_context`
|
|
49
|
+
* to use is not exposed by the library...
|
|
50
|
+
*/
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
2
|
+
/**
|
|
3
|
+
* @file
|
|
4
|
+
*
|
|
5
|
+
* About the typescript support for translation strings @see:
|
|
6
|
+
* - https://github.com/vinissimus/next-translate/issues/721
|
|
7
|
+
*/
|
|
8
|
+
import { useMemo } from "react";
|
|
9
|
+
import useTranslation from "next-translate/useTranslation";
|
|
10
|
+
export function useT(namespace) {
|
|
11
|
+
var t = useTranslation().t;
|
|
12
|
+
var tMemoized = useMemo(function () {
|
|
13
|
+
return function (s, q, o) {
|
|
14
|
+
return t(
|
|
15
|
+
// @ts-expect-error again...
|
|
16
|
+
(namespace ? "".concat(namespace, ":").concat(s) : s), q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
17
|
+
// ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
}, [t, namespace]);
|
|
21
|
+
return tMemoized;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Using this as generic instead of the interface on the namespace `Koine.NextTranslations`
|
|
25
|
+
* generates the typescript warning `Type instantiation is excessively deep and possibly infinite.`
|
|
26
|
+
* Its usage is left here and commented out. Maybe we can restore it once we find
|
|
27
|
+
* the time to look for a way to avoid the warning
|
|
28
|
+
*/
|
|
29
|
+
// type Translations = { [key: string]: Record<string, unknown> };
|
|
30
|
+
// export type TranslationsAllPaths<TTranslations extends Translations> = {
|
|
31
|
+
// [N in Extract<keyof TTranslations, string>]: {
|
|
32
|
+
// [K in Extract<
|
|
33
|
+
// keyof TTranslations[N],
|
|
34
|
+
// string
|
|
35
|
+
// >]: TTranslations[N][K] extends Array<
|
|
36
|
+
// // if we have an array of objects
|
|
37
|
+
// Record<string, unknown>
|
|
38
|
+
// >
|
|
39
|
+
// ? Join<
|
|
40
|
+
// K extends string ? `${N}:${K}` : `${N}:`,
|
|
41
|
+
// Paths<TTranslations[N][K], true>
|
|
42
|
+
// >
|
|
43
|
+
// : // if we have an object
|
|
44
|
+
// TTranslations[N][K] extends Record<string, unknown>
|
|
45
|
+
// ? Join<
|
|
46
|
+
// K extends string ? `${N}:${K}` : `${N}:`,
|
|
47
|
+
// Paths<TTranslations[N][K], true>
|
|
48
|
+
// > /* &
|
|
49
|
+
// Record<TTranslations[N][K], object> */
|
|
50
|
+
// : // if we have an array of primitives
|
|
51
|
+
// TTranslations[N][K] extends Array<string | number | boolean>
|
|
52
|
+
// ? Join<
|
|
53
|
+
// K extends string ? `${N}:${K}` : `${N}`,
|
|
54
|
+
// Paths<TTranslations[N][K], true>
|
|
55
|
+
// >
|
|
56
|
+
// : // if we have a primitve string/number/boolean
|
|
57
|
+
// TTranslations[N][K] extends string | number | boolean
|
|
58
|
+
// ? K extends string
|
|
59
|
+
// ? `${N}:${K}`
|
|
60
|
+
// : `${N}:`
|
|
61
|
+
// : ``;
|
|
62
|
+
// }[Extract<keyof TTranslations[N], string>];
|
|
63
|
+
// }[Extract<keyof TTranslations, string>];
|
|
64
|
+
// export type Translate<
|
|
65
|
+
// TTranslations extends Translations = Koine.NextTranslations,
|
|
66
|
+
// TNamespace extends undefined | keyof TTranslations = undefined
|
|
67
|
+
// > = <TReturn extends unknown = string>(
|
|
68
|
+
// s: TNamespace extends keyof TTranslations
|
|
69
|
+
// ? Paths<TTranslations[TNamespace]>
|
|
70
|
+
// : TranslationsAllPaths<TTranslations>,
|
|
71
|
+
// q?: TranslationQuery,
|
|
72
|
+
// o?: TranslationOptions
|
|
73
|
+
// ) => TReturn;
|
|
74
|
+
// export function useT<
|
|
75
|
+
// TTranslations extends Translations = Koine.NextTranslations,
|
|
76
|
+
// TNamespace extends keyof TTranslations | undefined = undefined
|
|
77
|
+
// >(namespace?: TNamespace) {
|
|
78
|
+
// const t = useTranslation().t;
|
|
79
|
+
// const tMemoized = useMemo(
|
|
80
|
+
// () =>
|
|
81
|
+
// <TReturn extends unknown = string>(
|
|
82
|
+
// s: TNamespace extends keyof TTranslations
|
|
83
|
+
// ? Paths<TTranslations[TNamespace], true>
|
|
84
|
+
// : TranslationsAllPaths<TTranslations>,
|
|
85
|
+
// q?: TranslationQuery,
|
|
86
|
+
// o?: TranslationOptions
|
|
87
|
+
// ) =>
|
|
88
|
+
// t(
|
|
89
|
+
// namespace ? `${namespace}:${s}` : s,
|
|
90
|
+
// q === "obj" ? null : q,
|
|
91
|
+
// q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
92
|
+
// // ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
|
|
93
|
+
// ) as TReturn,
|
|
94
|
+
// [t, namespace]
|
|
95
|
+
// );
|
|
96
|
+
// return tMemoized;
|
|
97
|
+
// }
|
|
98
|
+
/**
|
|
99
|
+
* Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
|
|
100
|
+
* we might just rewrite it with our custom implementation but the `_context`
|
|
101
|
+
* to use is not exposed by the library...
|
|
102
|
+
*/
|
|
103
|
+
// import { useContext, useMemo } from "react"
|
|
104
|
+
// import wrapTWithDefaultNs from "next-translate/lib/cjs/wrapTWithDefaultNs";
|
|
105
|
+
// import I18nContext from "next-translate/lib/cjs/_context";
|
|
106
|
+
// export default function useTranslation(defaultNS?: string): I18n {
|
|
107
|
+
// const ctx = useContext(I18nContext)
|
|
108
|
+
// return useMemo(
|
|
109
|
+
// () => ({
|
|
110
|
+
// ...ctx,
|
|
111
|
+
// t: wrapTWithDefaultNs(ctx.t, defaultNS),
|
|
112
|
+
// }),
|
|
113
|
+
// [ctx.lang, defaultNS]
|
|
114
|
+
// )
|
|
115
|
+
// }
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnalyticsGoogle = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var router_1 = require("next/router");
|
|
8
|
+
var script_1 = tslib_1.__importDefault(require("next/script"));
|
|
9
|
+
var utils_1 = require("@koine/utils");
|
|
10
|
+
var AnalyticsGoogle = function (_a) {
|
|
11
|
+
var id = _a.id;
|
|
12
|
+
var uid = id || process.env["NEXT_PUBLIC_GTM_ID"];
|
|
13
|
+
var _b = (0, router_1.useRouter)(), events = _b.events, asPath = _b.asPath, query = _b.query;
|
|
14
|
+
var _c = (0, react_1.useState)(false), ready = _c[0], setReady = _c[1];
|
|
15
|
+
var _d = (0, react_1.useState)(false), routed = _d[0], setRouted = _d[1];
|
|
16
|
+
// const [url, setUrl] = useState("");
|
|
17
|
+
(0, react_1.useEffect)(function () {
|
|
18
|
+
var handleRouteChange = function () {
|
|
19
|
+
setRouted(true);
|
|
20
|
+
};
|
|
21
|
+
events.on("routeChangeComplete", handleRouteChange);
|
|
22
|
+
return function () {
|
|
23
|
+
events.off("routeChangeComplete", handleRouteChange);
|
|
24
|
+
};
|
|
25
|
+
}, [events]);
|
|
26
|
+
(0, react_1.useEffect)(function () {
|
|
27
|
+
if (routed && ready && asPath) {
|
|
28
|
+
// const search = query;
|
|
29
|
+
(0, utils_1.pageview)(asPath);
|
|
30
|
+
}
|
|
31
|
+
}, [asPath, query, routed, ready]);
|
|
32
|
+
if (!uid) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(script_1.default, { id: "google-tagmanager", src: "https://www.googletagmanager.com/gtag/js?id=".concat(id), strategy: "afterInteractive", onLoad: function () { return setReady(true); } }), (0, jsx_runtime_1.jsx)(script_1.default, tslib_1.__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 ") }))] }));
|
|
36
|
+
};
|
|
37
|
+
exports.AnalyticsGoogle = AnalyticsGoogle;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCallbackUrl = exports.getAuthRoutes = exports.AUTH_ROUTES = void 0;
|
|
4
|
+
var utils_1 = require("@koine/utils");
|
|
5
|
+
exports.AUTH_ROUTES = {
|
|
6
|
+
login: process.env["AUTH_ROUTE_LOGIN"],
|
|
7
|
+
profile: process.env["AUTH_ROUTE_PROFILE"],
|
|
8
|
+
register: process.env["AUTH_ROUTE_REGISTER"],
|
|
9
|
+
secured: JSON.parse(process.env["AUTH_ROUTES_SECURED"] || "[]"),
|
|
10
|
+
};
|
|
11
|
+
function getAuthRoutes(t) {
|
|
12
|
+
return Object.keys(exports.AUTH_ROUTES).reduce(function (map, name) {
|
|
13
|
+
var routePage = exports.AUTH_ROUTES[name];
|
|
14
|
+
// @ts-expect-error cannot remember
|
|
15
|
+
map[name] = (0, utils_1.isString)(routePage) ? t("~:".concat(exports.AUTH_ROUTES[name])) : routePage;
|
|
16
|
+
return map;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
exports.getAuthRoutes = getAuthRoutes;
|
|
20
|
+
/**
|
|
21
|
+
* @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
|
|
22
|
+
*/
|
|
23
|
+
function getCallbackUrl(url) {
|
|
24
|
+
if (url === void 0) { url = window.location.href; }
|
|
25
|
+
return url.split("callbackUrl=")[1] || "";
|
|
26
|
+
}
|
|
27
|
+
exports.getCallbackUrl = getCallbackUrl;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./helpers"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./useLogin"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./useLoginUrl"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./useLogout"), exports);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLogin = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var router_1 = require("next/router");
|
|
7
|
+
var react_2 = require("next-auth/react");
|
|
8
|
+
var utils_1 = require("@koine/utils");
|
|
9
|
+
var i18n_1 = require("../i18n");
|
|
10
|
+
var helpers_1 = require("./helpers");
|
|
11
|
+
function useLogin() {
|
|
12
|
+
var t = (0, i18n_1.useT)();
|
|
13
|
+
var push = (0, router_1.useRouter)().push;
|
|
14
|
+
var _a = (0, react_1.useState)(false), loading = _a[0], setLoading = _a[1];
|
|
15
|
+
var _b = (0, react_1.useState)(false), ok = _b[0], setOk = _b[1];
|
|
16
|
+
var _c = (0, react_1.useState)(false), fail = _c[0], setFail = _c[1];
|
|
17
|
+
var submit = (0, react_1.useCallback)(function (data) {
|
|
18
|
+
setLoading(true);
|
|
19
|
+
(0, react_2.signIn)("credentials", tslib_1.__assign(tslib_1.__assign({}, data), { redirect: false }))
|
|
20
|
+
// @ts-expect-error FIXME: at some point...
|
|
21
|
+
.then(function (_a) {
|
|
22
|
+
var ok = _a.ok;
|
|
23
|
+
setLoading(false);
|
|
24
|
+
setOk(ok);
|
|
25
|
+
setFail(!ok);
|
|
26
|
+
if (ok) {
|
|
27
|
+
var redirectUrl = (0, utils_1.parseURL)((0, helpers_1.getCallbackUrl)());
|
|
28
|
+
var _b = (0, helpers_1.getAuthRoutes)(t), login = _b.login, register = _b.register, profile = _b.profile;
|
|
29
|
+
if (redirectUrl) {
|
|
30
|
+
var redirectPath = redirectUrl.pathname;
|
|
31
|
+
if (profile &&
|
|
32
|
+
(redirectPath === login || redirectPath === register)) {
|
|
33
|
+
push(profile);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
push(redirectPath + redirectUrl.search);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (profile) {
|
|
40
|
+
push(profile);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}, [t, push]);
|
|
45
|
+
// TODO: useMemo ?
|
|
46
|
+
return {
|
|
47
|
+
submit: submit,
|
|
48
|
+
loading: loading,
|
|
49
|
+
ok: ok,
|
|
50
|
+
fail: fail,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.useLogin = useLogin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLoginUrl = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var i18n_1 = require("../i18n");
|
|
6
|
+
var helpers_1 = require("./helpers");
|
|
7
|
+
function useLoginUrl() {
|
|
8
|
+
var _a = (0, react_1.useState)(""), currentUrl = _a[0], setCurrentUrl = _a[1];
|
|
9
|
+
var t = (0, i18n_1.useT)();
|
|
10
|
+
(0, react_1.useEffect)(function () {
|
|
11
|
+
setCurrentUrl("?callbackUrl=".concat(window.location.href));
|
|
12
|
+
}, []);
|
|
13
|
+
return "".concat((0, helpers_1.getAuthRoutes)(t).login).concat(currentUrl);
|
|
14
|
+
}
|
|
15
|
+
exports.useLoginUrl = useLoginUrl;
|