@koine/next 2.0.0-beta.26 → 2.0.0-beta.28
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/12/DynamicNamespaces.d.ts +1 -1
- package/12/T.d.ts +2 -1
- package/12/createUseLocale.d.ts +2 -0
- package/12/createUseLocale.js +7 -0
- package/12/createUseTo.d.ts +3 -0
- package/12/createUseTo.js +22 -0
- package/12/getT.d.ts +1 -1
- package/12/translationAsOptions.d.ts +1 -1
- package/12/types.d.ts +0 -3
- package/12/types.js +1 -2
- package/12/useT.d.ts +1 -1
- package/config-i18n.d.ts +3 -0
- package/config-i18n.js +12 -5
- package/config.d.ts +1 -3
- package/config.js +8 -12
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +10 -4
- package/typings.d.ts +0 -39
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { TranslateNamespace } from "@koine/i18n";
|
|
1
2
|
import type { DynamicNamespacesProps as BaseDynamicNamespacesProps } from "next-translate";
|
|
2
3
|
import BaseDynamicNamespaces from "next-translate/DynamicNamespaces";
|
|
3
|
-
import type { TranslateNamespace } from "./types-i18n.js";
|
|
4
4
|
export type DynamicNamespacesProps = Omit<BaseDynamicNamespacesProps, "namespaces"> & {
|
|
5
5
|
namespaces: TranslateNamespace[];
|
|
6
6
|
};
|
package/12/T.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TranslateNamespace, TranslationsAllPaths, TranslationsPaths } from "@koine/i18n";
|
|
1
3
|
import type { TransProps } from "next-translate";
|
|
2
|
-
import type { TranslateNamespace, TranslationsAllPaths, TranslationsPaths } from "./types-i18n.js";
|
|
3
4
|
export type TProps<TNamespace extends TranslateNamespace | undefined = undefined> = (Omit<TransProps, "i18nKey" | "ns"> & {
|
|
4
5
|
i18nKey: TranslationsAllPaths;
|
|
5
6
|
}) | (Omit<TransProps, "i18nKey" | "ns"> & {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ToRoute, type ToRouteDynamic, type ToRouteDynamicParams, type ToRouteStatic } from "@koine/i18n";
|
|
2
|
+
export declare const createUseTo: <TLocales extends string[] | readonly string[]>(useLocaleHook: () => TLocales[number], _locales: TLocales, defaultLocale: TLocales[number], hideDefaultLocaleInUrl?: boolean) => () => <TRoute extends ToRoute>(...args: TRoute extends ToRouteDynamic ? [routeId: TRoute, routeParams: ToRouteDynamicParams<TRoute>] : TRoute extends ToRouteStatic ? [routeId: ToRouteStatic] : never) => string;
|
|
3
|
+
export default createUseTo;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { __read } from "tslib";
|
|
3
|
+
import { createTo, } from "@koine/i18n";
|
|
4
|
+
import { useT } from "./useT.js";
|
|
5
|
+
export var createUseTo = function (useLocaleHook, _locales, defaultLocale, hideDefaultLocaleInUrl) {
|
|
6
|
+
return function () {
|
|
7
|
+
var t = useT("~");
|
|
8
|
+
var locale = useLocaleHook();
|
|
9
|
+
var _to = createTo(_locales, defaultLocale, hideDefaultLocaleInUrl);
|
|
10
|
+
return function () {
|
|
11
|
+
var args = [];
|
|
12
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
+
args[_i] = arguments[_i];
|
|
14
|
+
}
|
|
15
|
+
var _a = __read(args, 2), routeId = _a[0], routeParams = _a[1];
|
|
16
|
+
return routeParams
|
|
17
|
+
? _to(locale, t, routeId, routeParams)
|
|
18
|
+
: _to(locale, t, routeId);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export default createUseTo;
|
package/12/getT.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Translate, TranslateNamespace } from "
|
|
1
|
+
import type { Translate, TranslateNamespace } from "@koine/i18n";
|
|
2
2
|
export type GetT = <TNamespace extends TranslateNamespace | undefined = undefined>(locale?: string, namespace?: TNamespace) => Promise<Translate<TNamespace>>;
|
|
3
3
|
export declare const getT: GetT;
|
|
4
4
|
export default getT;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { TranslateLoose } from "@koine/i18n";
|
|
1
2
|
import type { Option } from "@koine/react/types";
|
|
2
|
-
import type { TranslateLoose } from "./types-i18n.js";
|
|
3
3
|
export declare function translationAsOptions(t: TranslateLoose, i18nKey: string): Option[];
|
|
4
4
|
export default translationAsOptions;
|
package/12/types.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "./types-i18n.js";
|
|
2
|
-
export * from "./types-seo.js";
|
|
3
1
|
export type { TProps } from "./T.js";
|
|
4
2
|
export type { GetT } from "./getT.js";
|
|
5
3
|
export type { DynamicNamespacesProps } from "./DynamicNamespaces.js";
|
|
6
4
|
export type { SeoDefaultsProps } from "./SeoDefaults.js";
|
|
7
|
-
export type { ToTranslate, ToStaticRoute, ToDynamicRoute, ToArgs } from "./to.js";
|
package/12/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./types-seo.js";
|
|
1
|
+
export {};
|
package/12/useT.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TranslateDefault, TranslateNamespace, TranslateNamespaced } from "
|
|
1
|
+
import type { TranslateDefault, TranslateNamespace, TranslateNamespaced } from "@koine/i18n";
|
|
2
2
|
export declare function useT(): TranslateDefault;
|
|
3
3
|
export declare function useT<TNamespace extends TranslateNamespace>(namespace: TNamespace): TranslateNamespaced<TNamespace>;
|
|
4
4
|
export default useT;
|
package/config-i18n.d.ts
CHANGED
|
@@ -16,6 +16,9 @@ type RoutesMapRoute = {
|
|
|
16
16
|
pathname: string;
|
|
17
17
|
wildcard?: boolean;
|
|
18
18
|
};
|
|
19
|
+
export declare function orderRoutes(routes: Routes, defaultLocale: Locale): {
|
|
20
|
+
[x: string]: RoutesByLocale;
|
|
21
|
+
};
|
|
19
22
|
export declare function normaliseUrlPathname(pathname?: string): string;
|
|
20
23
|
export declare function toPath(urlOrPathname?: string): string;
|
|
21
24
|
export declare function encodePathname(pathname?: string): string;
|
package/config-i18n.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator } from "tslib";
|
|
1
|
+
import { __assign, __awaiter, __generator, __rest } from "tslib";
|
|
2
2
|
var arrayUniqueByProperties = function (array, keys) {
|
|
3
3
|
return array.filter(function (item, idx, arr) {
|
|
4
4
|
return arr.findIndex(function (itemWith) {
|
|
@@ -6,6 +6,11 @@ var arrayUniqueByProperties = function (array, keys) {
|
|
|
6
6
|
}) === idx;
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
|
+
export function orderRoutes(routes, defaultLocale) {
|
|
10
|
+
var _a;
|
|
11
|
+
var _b = routes, _c = defaultLocale, routesForDefaultLocale = _b[_c], restRoutes = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
12
|
+
return __assign((_a = {}, _a[defaultLocale] = routesForDefaultLocale, _a), restRoutes);
|
|
13
|
+
}
|
|
9
14
|
export function normaliseUrlPathname(pathname) {
|
|
10
15
|
if (pathname === void 0) { pathname = ""; }
|
|
11
16
|
return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
|
|
@@ -130,11 +135,12 @@ export function getPathRedirect(arg) {
|
|
|
130
135
|
}
|
|
131
136
|
export function getRedirects(arg) {
|
|
132
137
|
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, permanent, debug, redirects, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
|
|
138
|
+
var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, permanent, debug, orderedRoutes, redirects, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
|
|
134
139
|
return __generator(this, function (_a) {
|
|
135
140
|
routes = arg.routes, defaultLocale = arg.defaultLocale, hideDefaultLocaleInUrl = arg.hideDefaultLocaleInUrl, localeParam = arg.localeParam, permanent = arg.permanent, debug = arg.debug;
|
|
141
|
+
orderedRoutes = orderRoutes(routes, defaultLocale);
|
|
136
142
|
redirects = [];
|
|
137
|
-
for (locale in
|
|
143
|
+
for (locale in orderedRoutes) {
|
|
138
144
|
routesByLocale = routes[locale];
|
|
139
145
|
routesMap = getRoutesMap({}, routesByLocale);
|
|
140
146
|
for (template in routesMap) {
|
|
@@ -211,11 +217,12 @@ export function getPathRewrite(arg) {
|
|
|
211
217
|
}
|
|
212
218
|
export function getRewrites(arg) {
|
|
213
219
|
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
-
var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, debug, rewrites, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
|
|
220
|
+
var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, debug, orderedRoutes, rewrites, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
|
|
215
221
|
return __generator(this, function (_a) {
|
|
216
222
|
routes = arg.routes, defaultLocale = arg.defaultLocale, hideDefaultLocaleInUrl = arg.hideDefaultLocaleInUrl, localeParam = arg.localeParam, debug = arg.debug;
|
|
223
|
+
orderedRoutes = orderRoutes(routes, defaultLocale);
|
|
217
224
|
rewrites = [];
|
|
218
|
-
for (locale in
|
|
225
|
+
for (locale in orderedRoutes) {
|
|
219
226
|
routesByLocale = routes[locale];
|
|
220
227
|
routesMap = getRoutesMap({}, routesByLocale);
|
|
221
228
|
for (template in routesMap) {
|
package/config.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ import { type ConfigI18nOptions, type Routes } from "./config-i18n.js";
|
|
|
3
3
|
interface KoineNextConfig {
|
|
4
4
|
nx?: boolean;
|
|
5
5
|
svg?: boolean;
|
|
6
|
-
sc?: boolean;
|
|
7
|
-
page?: boolean;
|
|
8
6
|
routes?: Routes;
|
|
9
7
|
permanent?: boolean;
|
|
10
8
|
debug?: boolean;
|
|
@@ -14,7 +12,7 @@ interface KoineNextConfig {
|
|
|
14
12
|
}
|
|
15
13
|
interface MergedConfig extends KoineNextConfig, Omit<NextConfig, "i18n"> {
|
|
16
14
|
}
|
|
17
|
-
export declare function withKoine({ nx, svg,
|
|
15
|
+
export declare function withKoine({ nx, svg, page, routes, permanent, debug, ...custom }?: MergedConfig): NextConfig | {
|
|
18
16
|
redirects(): Promise<import("./config-i18n.js").Redirect[]>;
|
|
19
17
|
rewrites(): Promise<{
|
|
20
18
|
beforeFiles: import("./config-i18n.js").Rewrite[];
|
package/config.js
CHANGED
|
@@ -8,14 +8,14 @@ export function withKoine(_a) {
|
|
|
8
8
|
hideDefaultLocaleInUrl: false,
|
|
9
9
|
},
|
|
10
10
|
}; }
|
|
11
|
-
var _b = _a.nx, nx = _b === void 0 ? true : _b, _c = _a.svg, svg = _c === void 0 ? true : _c,
|
|
12
|
-
var nextConfig = __assign({
|
|
11
|
+
var _b = _a.nx, nx = _b === void 0 ? true : _b, _c = _a.svg, svg = _c === void 0 ? true : _c, page = _a.page, routes = _a.routes, permanent = _a.permanent, debug = _a.debug, custom = __rest(_a, ["nx", "svg", "page", "routes", "permanent", "debug"]);
|
|
12
|
+
var nextConfig = __assign({ eslint: {
|
|
13
13
|
ignoreDuringBuilds: true,
|
|
14
14
|
}, typescript: {
|
|
15
15
|
ignoreBuildErrors: true,
|
|
16
|
-
}, poweredByHeader: false,
|
|
16
|
+
}, poweredByHeader: false, modularizeImports: __assign({ "@koine/api": { transform: "@koine/api/{{member}}" }, "@koine/browser": { transform: "@koine/browser/{{member}}" }, "@koine/dom": { transform: "@koine/dom/{{member}}" }, "@koine/i18n": { transform: "@koine/i18n/{{member}}" }, "@koine/next/?(((\\w*)?/?)*)": {
|
|
17
17
|
transform: "@koine/next/{{ matches.[1] }}/{{member}}",
|
|
18
|
-
}, "@koine/react/?(((\\w*)?/?)*)": {
|
|
18
|
+
}, "@koine/node": { transform: "@koine/node/{{member}}" }, "@koine/react/?(((\\w*)?/?)*)": {
|
|
19
19
|
transform: "@koine/react/{{ matches.[1] }}/{{member}}",
|
|
20
20
|
}, "@koine/utils": { transform: "@koine/utils/{{member}}" } }, (custom["modularizeImports"] || {})), experimental: __assign({ scrollRestoration: true }, (custom["experimental"] || {})) }, custom);
|
|
21
21
|
if (svg) {
|
|
@@ -25,6 +25,7 @@ export function withKoine(_a) {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
+
delete nextConfig["nx"];
|
|
28
29
|
nextConfig.webpack = function (_config, options) {
|
|
29
30
|
var webpackConfig = typeof nextConfig.webpack === "function"
|
|
30
31
|
? nextConfig.webpack(_config, options)
|
|
@@ -51,18 +52,13 @@ export function withKoine(_a) {
|
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
if (sc) {
|
|
55
|
-
nextConfig.compiler = {
|
|
56
|
-
styledComponents: true,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
55
|
if (custom.i18n) {
|
|
60
|
-
var
|
|
56
|
+
var _d = custom.i18n, locales = _d.locales, defaultLocale = _d.defaultLocale, localeParam = _d.localeParam;
|
|
61
57
|
if (localeParam) {
|
|
62
58
|
delete nextConfig.i18n;
|
|
63
59
|
}
|
|
64
60
|
else {
|
|
65
|
-
nextConfig.i18n =
|
|
61
|
+
nextConfig.i18n = { locales: locales, defaultLocale: defaultLocale };
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
64
|
if (routes) {
|
|
@@ -104,8 +100,8 @@ export function withKoine(_a) {
|
|
|
104
100
|
}
|
|
105
101
|
return [2, __assign(__assign({}, customs), { beforeFiles: __spreadArray(__spreadArray([], __read(defaults), false), __read((customs.beforeFiles || [])), false) })];
|
|
106
102
|
case 3: return [2, {
|
|
107
|
-
afterFiles: [],
|
|
108
103
|
beforeFiles: defaults,
|
|
104
|
+
afterFiles: [],
|
|
109
105
|
fallback: [],
|
|
110
106
|
}];
|
|
111
107
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "@koine/next",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/browser": "2.0.0-beta.
|
|
6
|
-
"@koine/react": "2.0.0-beta.
|
|
7
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/browser": "2.0.0-beta.28",
|
|
6
|
+
"@koine/react": "2.0.0-beta.28",
|
|
7
|
+
"@koine/utils": "2.0.0-beta.28"
|
|
8
8
|
},
|
|
9
9
|
"peerDependenciesMeta": {
|
|
10
10
|
"@kuus/yup": {
|
|
@@ -95,6 +95,12 @@
|
|
|
95
95
|
"./12/app/sc": {
|
|
96
96
|
"import": "./12/app/sc/index.js"
|
|
97
97
|
},
|
|
98
|
+
"./12/createUseLocale": {
|
|
99
|
+
"import": "./12/createUseLocale.js"
|
|
100
|
+
},
|
|
101
|
+
"./12/createUseTo": {
|
|
102
|
+
"import": "./12/createUseTo.js"
|
|
103
|
+
},
|
|
98
104
|
"./12/document/Document": {
|
|
99
105
|
"import": "./12/document/Document.js"
|
|
100
106
|
},
|
|
@@ -172,5 +178,5 @@
|
|
|
172
178
|
}
|
|
173
179
|
},
|
|
174
180
|
"peerDependencies": {},
|
|
175
|
-
"version": "2.0.0-beta.
|
|
181
|
+
"version": "2.0.0-beta.28"
|
|
176
182
|
}
|
package/typings.d.ts
CHANGED
|
@@ -11,15 +11,6 @@ declare module "*.svg" {
|
|
|
11
11
|
export default content;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Extend NodeJS `process.env` with variables used by @koine
|
|
16
|
-
*/
|
|
17
|
-
declare namespace NodeJS {
|
|
18
|
-
interface ProcessEnv {
|
|
19
|
-
NEXT_PUBLIC_APP_URL: string;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
14
|
/**
|
|
24
15
|
* Types specifically related to `@koine/next` exposed on the global unique
|
|
25
16
|
* namespace `Koine`. Most of the types here should be prefixed by `Next`, e.g.
|
|
@@ -30,36 +21,6 @@ declare namespace Koine {
|
|
|
30
21
|
* Default SEO data structure expected by the `<Seo>` component's prop `seo`
|
|
31
22
|
*/
|
|
32
23
|
type NextSeo = import("./12/types-seo").SeoData;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Translations dictionary extracted from JSON files.
|
|
36
|
-
* You need to augment this type with something like:
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* declare namespace Koine {
|
|
40
|
-
* interface Translations {
|
|
41
|
-
* "~": typeof import("./locales/en/~.json");
|
|
42
|
-
* "_": typeof import("./locales/en/_.json");
|
|
43
|
-
* "$team": typeof import("./locales/en/$team.json");
|
|
44
|
-
* "home": typeof import("./locales/en/home.json");
|
|
45
|
-
* "Header": typeof import("./locales/en/Header.json");
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* Best to follow a convention to name the files which become the namespaces:
|
|
51
|
-
*
|
|
52
|
-
* - `~`: for app wide **urls** translated definitions
|
|
53
|
-
* - `_`: for app wide **common** translations
|
|
54
|
-
* - `${data}`: dollar prefix for static **data** like arrays, objects, .etc
|
|
55
|
-
* - `{route-name}`: lower cased for **route** specific data
|
|
56
|
-
* - `{ComponentName}`: pascal cased for **components** specific data
|
|
57
|
-
*
|
|
58
|
-
* This works through using [type augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)
|
|
59
|
-
* and [merging interfaces](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces).
|
|
60
|
-
*/
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
62
|
-
interface Translations {}
|
|
63
24
|
}
|
|
64
25
|
|
|
65
26
|
/**
|