@koine/next 1.0.26 → 1.0.29

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/README.md CHANGED
@@ -1 +1,13 @@
1
1
  # @koine/next
2
+
3
+ ## i18n
4
+
5
+ To make typescript work nicely with `useT`, `getT` and `T` make sure to enable [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule) in your `tsconfig.json` file:
6
+
7
+ ```json
8
+ {
9
+ "compilerOptions": {
10
+ "resolveJsonModule": true,
11
+ }
12
+ }
13
+ ```
package/config/index.js CHANGED
@@ -142,7 +142,18 @@ export function withKoine(_a) {
142
142
  // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
143
143
  scrollRestoration: true }, (nextConfig.experimental || {})), {
144
144
  // @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
145
- modularizeImports: __assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }),
145
+ modularizeImports: __assign(__assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})), {
146
+ // FIXME: make these work with the right file/folder structure?
147
+ // "@koine/next/?(((\\w*)?/?)*)": {
148
+ // transform: "@koine/next/{{ matches.[1] }}/{{member}}",
149
+ // },
150
+ // "@koine/react/?(((\\w*)?/?)*)": {
151
+ // transform: "@koine/react/{{ matches.[1] }}/{{member}}",
152
+ // },
153
+ // "@koine/utils/?(((\\w*)?/?)*)": {
154
+ // transform: "@koine/utils/{{ matches.[1] }}/{{member}}",
155
+ // },
156
+ "@koine/utils": { transform: "@koine/utils/{{member}}" } }) }),
146
157
  // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
147
158
  reactStrictMode: true }, nextConfig);
148
159
  if (svg) {
package/i18n/T/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  import type { TransProps } from "next-translate";
2
- import type { /* TranslationsPaths, */ TranslationsAllPaths } from "../useT";
3
- export declare type TProps = Omit<TransProps, "i18nKey" | "ns"> & {
2
+ import type { TranslateNamespace, TranslationsPaths, TranslationsAllPaths } from "../types";
3
+ export declare type TProps<TNamespace extends TranslateNamespace | undefined = undefined> = (Omit<TransProps, "i18nKey" | "ns"> & {
4
4
  i18nKey: TranslationsAllPaths;
5
- };
5
+ }) | (Omit<TransProps, "i18nKey" | "ns"> & {
6
+ ns: TNamespace;
7
+ i18nKey: TranslationsPaths<TNamespace>;
8
+ });
9
+ /**
10
+ * **NOTE**: To make typescript work nicely here make sure to enable
11
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
12
+ * in your `tsconfig.json` file.
13
+ */
6
14
  export declare const T: (props: TProps) => JSX.Element;
package/i18n/T/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import { __assign } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import Trans from "next-translate/Trans";
4
+ /**
5
+ * **NOTE**: To make typescript work nicely here make sure to enable
6
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
7
+ * in your `tsconfig.json` file.
8
+ */
4
9
  export var T = function (props) { return _jsx(Trans, __assign({}, props)); };
@@ -1,3 +1,8 @@
1
- import type { Translate } from "../useT";
2
- export declare type GetT = <TNamespace extends keyof Koine.NextTranslations | undefined>(locale?: string, namespace?: TNamespace) => Promise<Translate<TNamespace>>;
1
+ import type { Translate, TranslateNamespace } from "../types";
2
+ export declare type GetT = <TNamespace extends TranslateNamespace | undefined = undefined>(locale?: string, namespace?: TNamespace) => Promise<Translate<TNamespace>>;
3
+ /**
4
+ * **NOTE**: To make typescript work nicely here make sure to enable
5
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
6
+ * in your `tsconfig.json` file.
7
+ */
3
8
  export declare const getT: GetT;
@@ -1,9 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
2
+ import getTranslation from "next-translate/getT";
2
3
  /**
3
- * @file
4
- *
5
- * About the typescript support for translation strings @see:
6
- * - https://github.com/vinissimus/next-translate/issues/721
4
+ * **NOTE**: To make typescript work nicely here make sure to enable
5
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
6
+ * in your `tsconfig.json` file.
7
7
  */
8
- import getTranslation from "next-translate/getT";
9
8
  export var getT = getTranslation;
package/i18n/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from "./translationAsOptions";
4
4
  export * from "./useDateFormat";
5
5
  export * from "./useLocale";
6
6
  export * from "./useT";
7
+ export * from "./types";
package/i18n/index.js CHANGED
@@ -4,3 +4,4 @@ export * from "./translationAsOptions";
4
4
  export * from "./useDateFormat";
5
5
  export * from "./useLocale";
6
6
  export * from "./useT";
7
+ export * from "./types";
@@ -1,3 +1,3 @@
1
- import type { TranslateLoose } from "../useT";
1
+ import type { TranslateLoose } from "../types";
2
2
  import type { Option } from "@koine/react";
3
3
  export declare function translationAsOptions(t: TranslateLoose, i18nKey: string): Option[];
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Translations dictionary extracted from JSON files.
3
+ * You need to augment this type with something like:
4
+ *
5
+ * ```ts
6
+ * declare namespace Koine {
7
+ * interface NextTranslations {
8
+ * "~": typeof import("./locales/en/~.json");
9
+ * "_": typeof import("./locales/en/_.json");
10
+ * "$team": typeof import("./locales/en/$team.json");
11
+ * "home": typeof import("./locales/en/home.json");
12
+ * "Header": typeof import("./locales/en/Header.json");
13
+ * }
14
+ * }
15
+ * ```
16
+ *
17
+ * An alternative to the use of the extended namespace (that I could not make it
18
+ * to work) is to augment the interface commented here below with module
19
+ * augmentation, something like:
20
+ *
21
+ * ```ts
22
+ * declare module "@koine/next/i18n" {
23
+ * interface TranslationsDictionary {
24
+ * "~": typeof import("./locales/en/~.json");
25
+ * }
26
+ * }
27
+ *```
28
+
29
+ * Best to follow a convention to name the files which become the namespaces:
30
+ *
31
+ * - `~`: for app wide **urls** translated definitions
32
+ * - `_`: for app wide **common** translations
33
+ * - `${data}`: dollar prefix for static **data** like arrays, objects, .etc
34
+ * - `{route-name}`: lower cased for **route** specific data
35
+ * - `{ComponentName}`: pascal cased for **components** specific data
36
+ */
37
+ export declare type TranslationsDictionary = Koine.NextTranslations;
38
+ export declare type TranslateNamespace = Extract<keyof TranslationsDictionary, string>;
39
+ declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : S1 : never;
40
+ export declare type TranslationsPaths<T, TAddRoot extends true | undefined = undefined> = {
41
+ [K in Extract<keyof T, string>]: T[K] extends Array<Record<string, unknown>> ? `${K}` : T[K] extends Record<string, unknown> ? TAddRoot extends true ? `${K}` | Join<K, TranslationsPaths<T[K], TAddRoot>> : Join<K, TranslationsPaths<T[K], TAddRoot>> : T[K] extends Array<string | number | boolean> ? `${K}` : T[K] extends string | number | boolean ? K extends string ? `${K}` : never : never;
42
+ }[Extract<keyof T, string>];
43
+ export declare type TranslationsAllPaths = {
44
+ [N in Extract<keyof TranslationsDictionary, string>]: {
45
+ [K in Extract<keyof TranslationsDictionary[N], string>]: TranslationsDictionary[N][K] extends Array<Record<string, unknown>> ? `${N}:${K}` : TranslationsDictionary[N][K] extends Record<string, unknown> ? `${N}:${K}` | Join<K extends string ? `${N}:${K}` : `${N}:`, TranslationsPaths<TranslationsDictionary[N][K], true>> : TranslationsDictionary[N][K] extends Array<string | number | boolean> ? `${N}:${K}` : TranslationsDictionary[N][K] extends string | number | boolean ? K extends string ? `${N}:${K}` : `${N}:` : never;
46
+ }[Extract<keyof TranslationsDictionary[N], string>];
47
+ }[Extract<keyof TranslationsDictionary, string>];
48
+ /**
49
+ * Query object to populate the returned translated string interpolating data.
50
+ * Unlike in `next-translate` we allow passing just `obj` as a shortcut for
51
+ * `{ returnObjects: true }`. In such case the thrid argument will not exists.
52
+ *
53
+ * TODO: type safe this behaviour of the third argument (options).
54
+ */
55
+ export declare type TranslationQuery = undefined | null | "obj" | {
56
+ [key: string]: string | number | boolean;
57
+ };
58
+ /**
59
+ * Opions of the translate function. Unlike in `next-translate` we allow passing
60
+ * just `obj` as a shortcut for `{ returnObjects: true }`.
61
+ */
62
+ export declare type TranslationOptions = undefined | "obj" | {
63
+ returnObjects?: boolean;
64
+ fallback?: string | string[];
65
+ default?: string;
66
+ };
67
+ /**
68
+ * Translate function which optionally accept a namespace as first argument
69
+ */
70
+ export declare type Translate<TNamespace extends TranslateNamespace | undefined> = TNamespace extends TranslateNamespace ? TranslateNamespaced<TNamespace> : TranslateDefault;
71
+ /**
72
+ * Translate function **without** namespace, it allows to select any of the all
73
+ * available strings in all namespaces.
74
+ */
75
+ export declare type TranslateDefault = <TReturn = string>(s: TranslationsAllPaths, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
76
+ /**
77
+ * Translate function **with** namespace, it allows to select only the all available
78
+ * strings in the given namespace.
79
+ */
80
+ export declare type TranslateNamespaced<TNamespace extends TranslateNamespace> = <TReturn = string>(s: TranslationsPaths<TranslationsDictionary[TNamespace], true>, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
81
+ /**
82
+ * Translate function loose type, to use only in implementations that uses
83
+ * the `t` function indirectly without needng knowledge of the string it needs
84
+ * to output.
85
+ */
86
+ export declare type TranslateLoose = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => string;
87
+ export {};
package/i18n/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -1,50 +1,16 @@
1
- export declare type TranslateNamespace = Extract<keyof Koine.NextTranslations, string>;
2
- declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : S1 : 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], TAddRoot>> : Join<K, TranslationsPaths<T[K], TAddRoot>> : K : 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>> ? `${N}:${K}` : Koine.NextTranslations[N][K] extends Record<string, unknown> ? `${N}:${K}` | Join<K extends string ? `${N}:${K}` : `${N}:`, TranslationsPaths<Koine.NextTranslations[N][K], true>> : Koine.NextTranslations[N][K] extends Array<string | number | boolean> ? `${N}:${K}` : 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>];
1
+ import type { TranslateNamespace, TranslateDefault, TranslateNamespaced } from "../types";
11
2
  /**
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], true>, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
31
- /**
32
- * Wrap `next-translate` useTranslations adding the `obj` second argument shortcut
33
- * and type safety
3
+ * Wrap `next-translate` useTranslations for type safet and adding the `obj`
4
+ * second argument shortcut for `{ returnObjects: true }`
34
5
  *
35
6
  * @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
7
+ *
8
+ * About the typescript support for translation strings see:
9
+ * - https://github.com/vinissimus/next-translate/issues/721
10
+ *
11
+ * **NOTE**: To make typescript work nicely here make sure to enable
12
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
13
+ * in your `tsconfig.json` file.
36
14
  */
37
15
  export declare function useT(): TranslateDefault;
38
16
  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
- */
@@ -1,105 +1,19 @@
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
1
  import { useMemo } from "react";
9
2
  import useTranslation from "next-translate/useTranslation";
10
3
  export function useT(namespace) {
11
4
  var t = useTranslation().t;
12
5
  var tMemoized = useMemo(function () {
13
6
  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
7
+ return t((namespace ? "".concat(namespace, ":").concat(s) : s), q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
17
8
  // ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
18
9
  );
19
10
  };
20
11
  }, [t, namespace]);
21
12
  return tMemoized;
22
13
  }
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
- */
14
+ // Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
15
+ // we might just rewrite it with our custom implementation but the `_context`
16
+ // to use is not exposed by the library...
103
17
  // import { useContext, useMemo } from "react"
104
18
  // import wrapTWithDefaultNs from "next-translate/lib/cjs/wrapTWithDefaultNs";
105
19
  // import I18nContext from "next-translate/lib/cjs/_context";
@@ -152,7 +152,18 @@ function withKoine(_a) {
152
152
  // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
153
153
  scrollRestoration: true }, (nextConfig.experimental || {})), {
154
154
  // @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
155
- modularizeImports: tslib_1.__assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }),
155
+ modularizeImports: tslib_1.__assign(tslib_1.__assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})), {
156
+ // FIXME: make these work with the right file/folder structure?
157
+ // "@koine/next/?(((\\w*)?/?)*)": {
158
+ // transform: "@koine/next/{{ matches.[1] }}/{{member}}",
159
+ // },
160
+ // "@koine/react/?(((\\w*)?/?)*)": {
161
+ // transform: "@koine/react/{{ matches.[1] }}/{{member}}",
162
+ // },
163
+ // "@koine/utils/?(((\\w*)?/?)*)": {
164
+ // transform: "@koine/utils/{{ matches.[1] }}/{{member}}",
165
+ // },
166
+ "@koine/utils": { transform: "@koine/utils/{{member}}" } }) }),
156
167
  // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
157
168
  reactStrictMode: true }, nextConfig);
158
169
  if (svg) {
@@ -4,5 +4,10 @@ exports.T = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var jsx_runtime_1 = require("react/jsx-runtime");
6
6
  var Trans_1 = tslib_1.__importDefault(require("next-translate/Trans"));
7
+ /**
8
+ * **NOTE**: To make typescript work nicely here make sure to enable
9
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
10
+ * in your `tsconfig.json` file.
11
+ */
7
12
  var T = function (props) { return (0, jsx_runtime_1.jsx)(Trans_1.default, tslib_1.__assign({}, props)); };
8
13
  exports.T = T;
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getT = void 0;
5
5
  var tslib_1 = require("tslib");
6
+ var getT_1 = tslib_1.__importDefault(require("next-translate/getT"));
6
7
  /**
7
- * @file
8
- *
9
- * About the typescript support for translation strings @see:
10
- * - https://github.com/vinissimus/next-translate/issues/721
8
+ * **NOTE**: To make typescript work nicely here make sure to enable
9
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
10
+ * in your `tsconfig.json` file.
11
11
  */
12
- var getT_1 = tslib_1.__importDefault(require("next-translate/getT"));
13
12
  exports.getT = getT_1.default;
@@ -7,3 +7,4 @@ tslib_1.__exportStar(require("./translationAsOptions"), exports);
7
7
  tslib_1.__exportStar(require("./useDateFormat"), exports);
8
8
  tslib_1.__exportStar(require("./useLocale"), exports);
9
9
  tslib_1.__exportStar(require("./useT"), exports);
10
+ tslib_1.__exportStar(require("./types"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +1,14 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.useT = void 0;
5
4
  var tslib_1 = require("tslib");
6
- /**
7
- * @file
8
- *
9
- * About the typescript support for translation strings @see:
10
- * - https://github.com/vinissimus/next-translate/issues/721
11
- */
12
5
  var react_1 = require("react");
13
6
  var useTranslation_1 = tslib_1.__importDefault(require("next-translate/useTranslation"));
14
7
  function useT(namespace) {
15
8
  var t = (0, useTranslation_1.default)().t;
16
9
  var tMemoized = (0, react_1.useMemo)(function () {
17
10
  return function (s, q, o) {
18
- return t(
19
- // @ts-expect-error again...
20
- (namespace ? "".concat(namespace, ":").concat(s) : s), q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
11
+ return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
21
12
  // ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
22
13
  );
23
14
  };
@@ -25,86 +16,9 @@ function useT(namespace) {
25
16
  return tMemoized;
26
17
  }
27
18
  exports.useT = useT;
28
- /**
29
- * Using this as generic instead of the interface on the namespace `Koine.NextTranslations`
30
- * generates the typescript warning `Type instantiation is excessively deep and possibly infinite.`
31
- * Its usage is left here and commented out. Maybe we can restore it once we find
32
- * the time to look for a way to avoid the warning
33
- */
34
- // type Translations = { [key: string]: Record<string, unknown> };
35
- // export type TranslationsAllPaths<TTranslations extends Translations> = {
36
- // [N in Extract<keyof TTranslations, string>]: {
37
- // [K in Extract<
38
- // keyof TTranslations[N],
39
- // string
40
- // >]: TTranslations[N][K] extends Array<
41
- // // if we have an array of objects
42
- // Record<string, unknown>
43
- // >
44
- // ? Join<
45
- // K extends string ? `${N}:${K}` : `${N}:`,
46
- // Paths<TTranslations[N][K], true>
47
- // >
48
- // : // if we have an object
49
- // TTranslations[N][K] extends Record<string, unknown>
50
- // ? Join<
51
- // K extends string ? `${N}:${K}` : `${N}:`,
52
- // Paths<TTranslations[N][K], true>
53
- // > /* &
54
- // Record<TTranslations[N][K], object> */
55
- // : // if we have an array of primitives
56
- // TTranslations[N][K] extends Array<string | number | boolean>
57
- // ? Join<
58
- // K extends string ? `${N}:${K}` : `${N}`,
59
- // Paths<TTranslations[N][K], true>
60
- // >
61
- // : // if we have a primitve string/number/boolean
62
- // TTranslations[N][K] extends string | number | boolean
63
- // ? K extends string
64
- // ? `${N}:${K}`
65
- // : `${N}:`
66
- // : ``;
67
- // }[Extract<keyof TTranslations[N], string>];
68
- // }[Extract<keyof TTranslations, string>];
69
- // export type Translate<
70
- // TTranslations extends Translations = Koine.NextTranslations,
71
- // TNamespace extends undefined | keyof TTranslations = undefined
72
- // > = <TReturn extends unknown = string>(
73
- // s: TNamespace extends keyof TTranslations
74
- // ? Paths<TTranslations[TNamespace]>
75
- // : TranslationsAllPaths<TTranslations>,
76
- // q?: TranslationQuery,
77
- // o?: TranslationOptions
78
- // ) => TReturn;
79
- // export function useT<
80
- // TTranslations extends Translations = Koine.NextTranslations,
81
- // TNamespace extends keyof TTranslations | undefined = undefined
82
- // >(namespace?: TNamespace) {
83
- // const t = useTranslation().t;
84
- // const tMemoized = useMemo(
85
- // () =>
86
- // <TReturn extends unknown = string>(
87
- // s: TNamespace extends keyof TTranslations
88
- // ? Paths<TTranslations[TNamespace], true>
89
- // : TranslationsAllPaths<TTranslations>,
90
- // q?: TranslationQuery,
91
- // o?: TranslationOptions
92
- // ) =>
93
- // t(
94
- // namespace ? `${namespace}:${s}` : s,
95
- // q === "obj" ? null : q,
96
- // q === "obj" || o === "obj" ? { returnObjects: true } : o
97
- // // ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
98
- // ) as TReturn,
99
- // [t, namespace]
100
- // );
101
- // return tMemoized;
102
- // }
103
- /**
104
- * Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
105
- * we might just rewrite it with our custom implementation but the `_context`
106
- * to use is not exposed by the library...
107
- */
19
+ // Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
20
+ // we might just rewrite it with our custom implementation but the `_context`
21
+ // to use is not exposed by the library...
108
22
  // import { useContext, useMemo } from "react"
109
23
  // import wrapTWithDefaultNs from "next-translate/lib/cjs/wrapTWithDefaultNs";
110
24
  // import I18nContext from "next-translate/lib/cjs/_context";
package/package.json CHANGED
@@ -7,9 +7,9 @@
7
7
  "peerDependencies": {
8
8
  "react": "^16.8 || ^17 || ^18",
9
9
  "next": "^12.1.6",
10
- "@koine/utils": "1.0.26",
10
+ "@koine/utils": "1.0.29",
11
11
  "framer-motion": "^6.3.10",
12
- "@koine/react": "1.0.26",
12
+ "@koine/react": "1.0.29",
13
13
  "styled-components": "^5.3.5",
14
14
  "@mui/base": "^5.0.0-alpha.83",
15
15
  "react-icons": "^4.4.0",
@@ -20,6 +20,7 @@
20
20
  "yup": "^0.32.11",
21
21
  "react-hook-form": "^7.31.3",
22
22
  "type-fest": "^2.13.0",
23
+ "react-popper": "^2.3.0",
23
24
  "tslib": "^2.4.0",
24
25
  "next-auth": "^4.3.4",
25
26
  "@mui/material": "^5.8.2",
@@ -29,7 +30,7 @@
29
30
  "next-translate": "^1.4.0",
30
31
  "next-seo": "^5.4.0"
31
32
  },
32
- "version": "1.0.26",
33
+ "version": "1.0.29",
33
34
  "module": "./index.js",
34
35
  "types": "./index.d.ts"
35
36
  }
package/typings.d.ts CHANGED
@@ -83,13 +83,8 @@ declare namespace Koine {
83
83
  * - `{ComponentName}`: pascal cased for **components** specific data
84
84
  */
85
85
  interface NextTranslations {
86
- "~": Record<string, string>;
87
- _: Record<string, string>;
86
+ [key: string]: any;
88
87
  }
89
- // interface NextTranslations {
90
- // "~": Record<string, string>;
91
- // _: Record<string, string>;
92
- // }
93
88
  }
94
89
 
95
90
  /**
@@ -97,7 +92,6 @@ declare namespace Koine {
97
92
  * the `koine` ecosystem. For instance Google Analytics globally available
98
93
  * variables.
99
94
  */
100
-
101
- declare const gtag: (
102
- ...args: Record<string, unknown>[]
103
- ) => Record<string, unknown>;
95
+ declare interface Window {
96
+ gtag: (...args: Record<string, unknown>[]) => Record<string, unknown>;
97
+ }
@@ -1,24 +0,0 @@
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,28 +0,0 @@
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/utils/api.d.ts DELETED
@@ -1,55 +0,0 @@
1
- declare type _Response = Response;
2
- export declare namespace KoineApi {
3
- type ResponseSuccesfull = unknown;
4
- type ResponseFailed = unknown;
5
- type ResponseShared<T extends Record<string, unknown> = {}> = T & {
6
- status: _Response["status"];
7
- msg: _Response["statusText"];
8
- };
9
- type Response<Succesfull extends ResponseSuccesfull = ResponseSuccesfull, Failed extends ResponseFailed = ResponseFailed> = {
10
- status: _Response["status"];
11
- msg: _Response["statusText"];
12
- ok: true;
13
- fail?: false;
14
- data: Succesfull;
15
- } | {
16
- status: _Response["status"];
17
- msg: _Response["statusText"];
18
- ok?: false;
19
- fail: true;
20
- data: Failed;
21
- };
22
- /**
23
- * Request options
24
- */
25
- type RequestOptions<TJson = unknown> = {
26
- /**
27
- * JSON request body
28
- *
29
- * @default {}
30
- */
31
- json?: TJson;
32
- /**
33
- * Params will be serialized into a string and appended to the URL
34
- */
35
- params?: Record<string, unknown>;
36
- /**
37
- * Headers will be merged with
38
- * ```
39
- * { "content-type": "application/json" }
40
- * ```
41
- */
42
- headers?: RequestInit["headers"];
43
- /**
44
- * Timeout in `ms`, if `falsy` there is no timeout
45
- *
46
- * @default 10000
47
- */
48
- timeout?: number | false | null;
49
- };
50
- type RequestMethod = "get" | "post" | "put" | "patch" | "delete";
51
- type RequestFn = <Succesfull extends ResponseSuccesfull = unknown, Failed extends ResponseFailed = unknown>(endpoint: string, options?: RequestOptions) => Promise<Response<Succesfull, Failed>>;
52
- type Client = Record<RequestMethod, RequestFn>;
53
- }
54
- export declare const api: KoineApi.Client;
55
- export {};
package/utils/api.js DELETED
@@ -1,44 +0,0 @@
1
- import { __assign, __awaiter, __generator } from "tslib";
2
- import { buildUrlQueryString } from "@koine/utils";
3
- export var api = ["get", "post", "put", "patch", "delete"].reduce(function (api, method) {
4
- api[method] = function (endpoint, options) {
5
- if (options === void 0) { options = {}; }
6
- return __awaiter(void 0, void 0, void 0, function () {
7
- var _a, json, params, _b, headers, _c, timeout, requestInit, timeoutNumber, controller, timeoutId, url, response, result;
8
- return __generator(this, function (_d) {
9
- switch (_d.label) {
10
- case 0:
11
- _a = options.json, json = _a === void 0 ? {} : _a, params = options.params, _b = options.headers, headers = _b === void 0 ? {} : _b, _c = options.timeout, timeout = _c === void 0 ? 10000 : _c;
12
- requestInit = {
13
- method: method.toUpperCase(),
14
- headers: __assign({ "content-type": "application/json" }, headers),
15
- };
16
- timeoutNumber = Number(timeout);
17
- url = "/api/".concat(endpoint.replace(/^\/*/, ""));
18
- if (method !== "get") {
19
- requestInit.body = JSON.stringify(json);
20
- }
21
- if (timeoutNumber > 0) {
22
- controller = new AbortController();
23
- timeoutId = setTimeout(function () { return controller.abort(); }, timeoutNumber);
24
- requestInit.signal = controller.signal;
25
- }
26
- if (params) {
27
- url += buildUrlQueryString(params);
28
- }
29
- return [4 /*yield*/, fetch(url, requestInit)];
30
- case 1:
31
- response = _d.sent();
32
- if (timeoutId) {
33
- clearTimeout(timeoutId);
34
- }
35
- return [4 /*yield*/, response.json()];
36
- case 2:
37
- result = (_d.sent());
38
- return [2 /*return*/, result];
39
- }
40
- });
41
- });
42
- };
43
- return api;
44
- }, {});