@koine/next 2.0.0-beta.2 → 2.0.0-beta.21
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/AnalyticsGoogle.d.ts +0 -1
- package/12/AnalyticsGoogle.js +15 -21
- package/12/DisableErrorOverlay.d.ts +0 -5
- package/12/DisableErrorOverlay.js +5 -15
- package/12/DynamicNamespaces.d.ts +2 -7
- package/12/DynamicNamespaces.js +3 -12
- package/12/Favicon.d.ts +0 -0
- package/12/Favicon.js +6 -10
- package/12/Link.d.ts +1 -4
- package/12/Link.js +8 -14
- package/12/NextProgress.d.ts +1 -4
- package/12/NextProgress.js +13 -19
- package/12/Seo.d.ts +2 -26
- package/12/Seo.js +6 -33
- package/12/SeoDefaults.d.ts +1 -4
- package/12/SeoDefaults.js +6 -16
- package/12/T.d.ts +1 -7
- package/12/T.js +6 -15
- package/12/TransText.d.ts +0 -0
- package/12/TransText.js +3 -7
- package/12/app/AppHead.d.ts +0 -0
- package/12/app/AppHead.js +5 -10
- package/12/app/AppMain.d.ts +4 -22
- package/12/app/AppMain.js +1 -2
- package/12/app/css/AppMain.d.ts +1 -6
- package/12/app/css/AppMain.js +7 -16
- package/12/app/css/AppTheme.d.ts +2 -5
- package/12/app/css/AppTheme.js +5 -16
- package/12/app/css/auth/index.d.ts +2 -5
- package/12/app/css/auth/index.js +9 -16
- package/12/app/css/index.d.ts +2 -50
- package/12/app/css/index.js +8 -60
- package/12/app/index.d.ts +2 -2
- package/12/app/index.js +2 -5
- package/12/app/sc/AppMain.d.ts +1 -8
- package/12/app/sc/AppMain.js +12 -23
- package/12/app/sc/AppTheme.d.ts +1 -7
- package/12/app/sc/AppTheme.js +6 -13
- package/12/app/sc/auth/index.d.ts +2 -5
- package/12/app/sc/auth/index.js +9 -16
- package/12/app/sc/index.d.ts +2 -52
- package/12/app/sc/index.js +8 -62
- package/12/document/Document.d.ts +0 -10
- package/12/document/Document.js +11 -24
- package/12/document/css/index.d.ts +0 -12
- package/12/document/css/index.js +11 -38
- package/12/document/index.d.ts +2 -2
- package/12/document/index.js +2 -7
- package/12/document/sc/index.d.ts +0 -13
- package/12/document/sc/index.js +21 -38
- package/12/getT.d.ts +1 -6
- package/12/getT.js +3 -13
- package/12/index.d.ts +3 -24
- package/12/index.js +3 -52
- package/12/seoBuildTags.d.ts +2 -17
- package/12/seoBuildTags.js +15 -43
- package/12/to.d.ts +1 -11
- package/12/to.js +4 -14
- package/12/translationAsOptions.d.ts +2 -1
- package/12/translationAsOptions.js +2 -5
- package/12/types-i18n.d.ts +0 -87
- package/12/types-i18n.js +1 -14
- package/12/types-seo.d.ts +0 -0
- package/12/types-seo.js +1 -2
- package/12/types.d.ts +7 -0
- package/12/types.js +2 -0
- package/12/useBackUrl.d.ts +0 -0
- package/12/useBackUrl.js +11 -20
- package/12/useDateFormat.d.ts +0 -4
- package/12/useDateFormat.js +15 -23
- package/12/useForm.d.ts +2 -2
- package/12/useForm.js +9 -33
- package/12/useLocale.d.ts +0 -0
- package/12/useLocale.js +4 -9
- package/12/useT.d.ts +1 -1
- package/12/useT.js +6 -33
- package/12/useTo.d.ts +1 -1
- package/12/useTo.js +7 -11
- package/ThemeContext.d.ts +11 -0
- package/{12/ThemeContext.mjs → ThemeContext.js} +0 -1
- package/ThemeProvider.d.ts +17 -0
- package/{12/ThemeProvider.mjs → ThemeProvider.js} +11 -42
- package/config-i18n.d.ts +52 -0
- package/config-i18n.js +251 -0
- package/config.d.ts +109 -0
- package/config.js +118 -0
- package/getSiteUrl.d.ts +0 -6
- package/getSiteUrl.js +4 -15
- package/index.d.ts +5 -2
- package/index.js +5 -7
- package/load.d.ts +0 -8
- package/load.js +2 -14
- package/package.json +159 -39
- package/useTheme.d.ts +4 -0
- package/{12/useTheme.mjs → useTheme.js} +1 -4
- package/12/AnalyticsGoogle.mjs +0 -34
- package/12/DisableErrorOverlay.mjs +0 -13
- package/12/DynamicNamespaces.mjs +0 -9
- package/12/Favicon.mjs +0 -6
- package/12/Link.mjs +0 -12
- package/12/NextProgress.mjs +0 -42
- package/12/Seo.mjs +0 -29
- package/12/SeoDefaults.mjs +0 -12
- package/12/T.mjs +0 -13
- package/12/ThemeContext.d.ts +0 -17
- package/12/ThemeContext.js +0 -10
- package/12/ThemeProvider.d.ts +0 -35
- package/12/ThemeProvider.js +0 -239
- package/12/TransText.mjs +0 -4
- package/12/app/AppHead.mjs +0 -6
- package/12/app/AppMain.mjs +0 -1
- package/12/app/css/AppMain.mjs +0 -14
- package/12/app/css/AppTheme.mjs +0 -14
- package/12/app/css/auth/index.mjs +0 -13
- package/12/app/css/auth/package.json +0 -6
- package/12/app/css/index.mjs +0 -57
- package/12/app/css/package.json +0 -6
- package/12/app/index.mjs +0 -2
- package/12/app/package.json +0 -6
- package/12/app/sc/AppMain.mjs +0 -25
- package/12/app/sc/AppTheme.mjs +0 -11
- package/12/app/sc/auth/index.mjs +0 -13
- package/12/app/sc/auth/package.json +0 -6
- package/12/app/sc/index.mjs +0 -59
- package/12/app/sc/package.json +0 -6
- package/12/document/Document.mjs +0 -28
- package/12/document/css/index.mjs +0 -45
- package/12/document/css/package.json +0 -6
- package/12/document/index.mjs +0 -2
- package/12/document/package.json +0 -6
- package/12/document/sc/index.mjs +0 -64
- package/12/document/sc/package.json +0 -6
- package/12/getT.mjs +0 -10
- package/12/index.mjs +0 -27
- package/12/package.json +0 -6
- package/12/seoBuildTags.mjs +0 -117
- package/12/to.mjs +0 -25
- package/12/translationAsOptions.mjs +0 -9
- package/12/types-i18n.mjs +0 -13
- package/12/types-seo.mjs +0 -1
- package/12/useBackUrl.mjs +0 -28
- package/12/useDateFormat.mjs +0 -39
- package/12/useForm.mjs +0 -35
- package/12/useLocale.mjs +0 -6
- package/12/useT.mjs +0 -21
- package/12/useTheme.d.ts +0 -7
- package/12/useTheme.js +0 -12
- package/12/useTo.mjs +0 -15
- package/README.md +0 -13
- package/config/index.d.ts +0 -160
- package/config/index.js +0 -343
- package/config/index.mjs +0 -332
- package/config/package.json +0 -6
- package/getSiteUrl.mjs +0 -12
- package/index.mjs +0 -2
- package/load.mjs +0 -14
package/12/useBackUrl.js
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var createStorage_1 = tslib_1.__importDefault(require("@koine/browser/createStorage"));
|
|
9
|
-
var back = (0, createStorage_1.default)({
|
|
2
|
+
import { __read } from "tslib";
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { createStorage } from "@koine/browser";
|
|
6
|
+
var back = createStorage({
|
|
10
7
|
lastUrl: "",
|
|
11
8
|
});
|
|
12
|
-
function useBackUrl() {
|
|
13
|
-
var asPath =
|
|
14
|
-
var calledOnce =
|
|
15
|
-
var _a = (
|
|
16
|
-
|
|
17
|
-
(0, react_1.useEffect)(function () {
|
|
9
|
+
export function useBackUrl() {
|
|
10
|
+
var asPath = useRouter().asPath;
|
|
11
|
+
var calledOnce = useRef(false);
|
|
12
|
+
var _a = __read(useState(), 2), backUrl = _a[0], setBackUrl = _a[1];
|
|
13
|
+
useEffect(function () {
|
|
18
14
|
if (calledOnce.current) {
|
|
19
15
|
return;
|
|
20
16
|
}
|
|
21
17
|
var prevLastUrl = back.get("lastUrl");
|
|
22
|
-
// console.log("useBackUrl: prevLastUrl", prevLastUrl);
|
|
23
|
-
// first set it to use on a link, set to undefined if the previous URL
|
|
24
|
-
// is the same as the current one
|
|
25
18
|
setBackUrl(asPath === prevLastUrl || !prevLastUrl ? undefined : prevLastUrl);
|
|
26
|
-
// then update the local storage
|
|
27
19
|
back.set("lastUrl", asPath);
|
|
28
20
|
calledOnce.current = true;
|
|
29
21
|
});
|
|
30
22
|
return backUrl;
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
exports.default = useBackUrl;
|
|
24
|
+
export default useBackUrl;
|
package/12/useDateFormat.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import format from "date-fns/format";
|
|
2
|
-
/**
|
|
3
|
-
* Automatically returns the `date-fns/format` function with the right locale
|
|
4
|
-
* passed as option (grabbed from next router value).
|
|
5
|
-
*/
|
|
6
2
|
export declare const useDateFormat: () => typeof format;
|
|
7
3
|
export default useDateFormat;
|
package/12/useDateFormat.js
CHANGED
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* Automatically returns the `date-fns/format` function with the right locale
|
|
12
|
-
* passed as option (grabbed from next router value).
|
|
13
|
-
*/
|
|
14
|
-
var useDateFormat = function () {
|
|
15
|
-
var _a = (0, react_1.useState)(function () {
|
|
2
|
+
import { __assign, __read, __spreadArray } from "tslib";
|
|
3
|
+
import format from "date-fns/format";
|
|
4
|
+
import { useRouter } from "next/router";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { useDateLocale } from "@koine/react";
|
|
7
|
+
export var useDateFormat = function () {
|
|
8
|
+
var _a = __read(useState(function () {
|
|
16
9
|
return function () {
|
|
17
10
|
var args = [];
|
|
18
11
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
12
|
args[_i] = arguments[_i];
|
|
20
13
|
}
|
|
21
|
-
return
|
|
14
|
+
return format.apply(void 0, __spreadArray([], __read(args), false));
|
|
22
15
|
};
|
|
23
|
-
}), formatter = _a[0], setFormatter = _a[1];
|
|
24
|
-
var router =
|
|
25
|
-
var locale = (
|
|
26
|
-
|
|
16
|
+
}), 2), formatter = _a[0], setFormatter = _a[1];
|
|
17
|
+
var router = useRouter();
|
|
18
|
+
var locale = useDateLocale(router.locale);
|
|
19
|
+
useEffect(function () {
|
|
27
20
|
if (locale) {
|
|
28
|
-
var newFormatter_1 = function (date, _format, options) { return (
|
|
21
|
+
var newFormatter_1 = function (date, _format, options) { return format(date, _format, __assign(__assign({}, (options || {})), { locale: locale })); };
|
|
29
22
|
setFormatter(function () {
|
|
30
23
|
return function () {
|
|
31
24
|
var args = [];
|
|
32
25
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
26
|
args[_i] = arguments[_i];
|
|
34
27
|
}
|
|
35
|
-
return newFormatter_1.apply(void 0, args);
|
|
28
|
+
return newFormatter_1.apply(void 0, __spreadArray([], __read(args), false));
|
|
36
29
|
};
|
|
37
30
|
});
|
|
38
31
|
}
|
|
39
32
|
}, [locale]);
|
|
40
33
|
return formatter;
|
|
41
34
|
};
|
|
42
|
-
|
|
43
|
-
exports.default = exports.useDateFormat;
|
|
35
|
+
export default useDateFormat;
|
package/12/useForm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { UseFormProps, FieldValues } from "react-hook-form";
|
|
2
1
|
import type { ObjectSchema } from "@kuus/yup";
|
|
3
|
-
import {
|
|
2
|
+
import type { FieldValues, UseFormProps } from "react-hook-form";
|
|
3
|
+
import { type TranslateLoose } from "./types-i18n.js";
|
|
4
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>;
|
package/12/useForm.js
CHANGED
|
@@ -1,39 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var yup_1 = require("@hookform/resolvers/yup");
|
|
9
|
-
function useForm(
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
schema, t, formProps, debug) {
|
|
2
|
+
import { __assign } from "tslib";
|
|
3
|
+
import { yupResolver as resolver } from "@hookform/resolvers/yup";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { useForm as _useForm } from "react-hook-form";
|
|
6
|
+
export function useForm(schema, t, formProps, debug) {
|
|
12
7
|
if (formProps === void 0) { formProps = {}; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// @ts-expect-error FIXME:
|
|
16
|
-
resolver: (0, yup_1.yupResolver)(schema) }, formProps));
|
|
17
|
-
// const { control, register, setValue } = form;
|
|
18
|
-
// const field = { control, register, setValue, t };
|
|
19
|
-
// if (process.env["NODE_ENV"] !== "production") {
|
|
20
|
-
// if (debug) {
|
|
21
|
-
// console.info(
|
|
22
|
-
// `Form ${i18nNamespace} data`,
|
|
23
|
-
// form.watch(),
|
|
24
|
-
// `errors: `,
|
|
25
|
-
// form.formState.errors
|
|
26
|
-
// );
|
|
27
|
-
// }
|
|
28
|
-
// }
|
|
29
|
-
// if (formProps.mode === "onChange") {
|
|
30
|
-
// return { field, ...form };
|
|
31
|
-
// }
|
|
32
|
-
return (0, react_1.useMemo)(function () {
|
|
8
|
+
var form = _useForm(__assign({ resolver: resolver(schema) }, formProps));
|
|
9
|
+
return useMemo(function () {
|
|
33
10
|
var control = form.control, register = form.register, setValue = form.setValue;
|
|
34
11
|
var field = { control: control, register: register, setValue: setValue, t: t };
|
|
35
|
-
return
|
|
12
|
+
return __assign({ field: field }, form);
|
|
36
13
|
}, [t, form]);
|
|
37
14
|
}
|
|
38
|
-
|
|
39
|
-
exports.default = useForm;
|
|
15
|
+
export default useForm;
|
package/12/useLocale.d.ts
CHANGED
|
File without changes
|
package/12/useLocale.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var useTranslation_1 = tslib_1.__importDefault(require("next-translate/useTranslation"));
|
|
7
|
-
function useLocale() {
|
|
8
|
-
return (0, useTranslation_1.default)().lang;
|
|
2
|
+
import useTranslation from "next-translate/useTranslation";
|
|
3
|
+
export function useLocale() {
|
|
4
|
+
return useTranslation().lang;
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
exports.default = useLocale;
|
|
6
|
+
export default useLocale;
|
package/12/useT.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TranslateDefault, TranslateNamespace, TranslateNamespaced } from "./types-i18n.js";
|
|
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/12/useT.js
CHANGED
|
@@ -1,44 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
var context_1 = tslib_1.__importDefault(require("next-translate/context"));
|
|
9
|
-
function useT(namespace) {
|
|
10
|
-
var t = (0, react_1.useContext)(context_1.default).t;
|
|
11
|
-
// const t = useTranslation().t;
|
|
12
|
-
var tMemoized = (0, react_1.useMemo)(function () {
|
|
2
|
+
import I18nContext from "next-translate/context";
|
|
3
|
+
import { useContext, useMemo } from "react";
|
|
4
|
+
export function useT(namespace) {
|
|
5
|
+
var t = useContext(I18nContext).t;
|
|
6
|
+
var tMemoized = useMemo(function () {
|
|
13
7
|
return function (s, q, o) {
|
|
14
8
|
return t(namespace ? "".concat(namespace, ":").concat(s) : "".concat(s), q === "obj" || q === "" ? null : q, q === "obj" || o === "obj"
|
|
15
9
|
? { returnObjects: true }
|
|
16
10
|
: q === "" || o === ""
|
|
17
11
|
? { fallback: "" }
|
|
18
12
|
: o);
|
|
19
|
-
// ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
|
|
20
|
-
// );
|
|
21
13
|
};
|
|
22
14
|
}, [t, namespace]);
|
|
23
15
|
return tMemoized;
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
exports.default = useT;
|
|
27
|
-
// Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
|
|
28
|
-
// we might just rewrite it with our custom implementation but the `_context`
|
|
29
|
-
// to use is not exposed by the library...
|
|
30
|
-
// import { useContext/* , useMemo */ } from "react"
|
|
31
|
-
// // import wrapTWithDefaultNs from "next-translate";
|
|
32
|
-
// import I18nContext from "next-translate/context";
|
|
33
|
-
// import type { Translate } from "./types-i18n";
|
|
34
|
-
// export default function useT(_defaultNS?: string) {
|
|
35
|
-
// const ctx = useContext(I18nContext);
|
|
36
|
-
// return ctx.t as Translate;
|
|
37
|
-
// // return useMemo(
|
|
38
|
-
// // () => ({
|
|
39
|
-
// // ...ctx,
|
|
40
|
-
// // t: wrapTWithDefaultNs(ctx.t, defaultNS),
|
|
41
|
-
// // }),
|
|
42
|
-
// // [ctx, defaultNS]
|
|
43
|
-
// // )
|
|
44
|
-
// }
|
|
17
|
+
export default useT;
|
package/12/useTo.d.ts
CHANGED
package/12/useTo.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
function useTo() {
|
|
9
|
-
var t = (0, useT_1.useT)("~");
|
|
2
|
+
import { __read, __spreadArray } from "tslib";
|
|
3
|
+
import { to } from "./to.js";
|
|
4
|
+
import { useT } from "./useT.js";
|
|
5
|
+
export function useTo() {
|
|
6
|
+
var t = useT("~");
|
|
10
7
|
return function () {
|
|
11
8
|
var args = [];
|
|
12
9
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
10
|
args[_i] = arguments[_i];
|
|
14
11
|
}
|
|
15
|
-
return
|
|
12
|
+
return to.apply(void 0, __spreadArray([t], __read(args), false));
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
exports.default = useTo;
|
|
15
|
+
export default useTo;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type ThemeContextProps = {
|
|
3
|
+
themes: string[];
|
|
4
|
+
forcedTheme?: string;
|
|
5
|
+
setTheme: (theme: string) => void;
|
|
6
|
+
theme?: string;
|
|
7
|
+
resolvedTheme?: string;
|
|
8
|
+
systemTheme?: "dark" | "light";
|
|
9
|
+
};
|
|
10
|
+
export declare const ThemeContext: import("react").Context<ThemeContextProps>;
|
|
11
|
+
export default ThemeContext;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type ValueObject = {
|
|
3
|
+
[themeName: string]: string;
|
|
4
|
+
};
|
|
5
|
+
export type ThemeProviderProps = React.PropsWithChildren<{
|
|
6
|
+
themes?: string[];
|
|
7
|
+
forcedTheme?: string;
|
|
8
|
+
enableSystem?: boolean;
|
|
9
|
+
disableTransitionOnChange?: boolean;
|
|
10
|
+
enableColorScheme?: boolean;
|
|
11
|
+
defaultTheme?: string;
|
|
12
|
+
attribute?: string | "class";
|
|
13
|
+
value?: ValueObject;
|
|
14
|
+
nonce?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const ThemeProvider: ({ forcedTheme, disableTransitionOnChange, enableSystem, enableColorScheme, themes, defaultTheme, attribute, value, children, nonce, }: ThemeProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export default ThemeProvider;
|
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { __spreadArray } from "tslib";
|
|
2
|
+
import { __read, __spreadArray } from "tslib";
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { useCallback, useEffect, useState, memo } from "react";
|
|
5
4
|
import NextScript from "next/script";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
5
|
+
import { memo, useCallback, useEffect, useState } from "react";
|
|
6
|
+
import { isServer } from "@koine/utils";
|
|
7
|
+
import { ThemeContext } from "./ThemeContext.js";
|
|
8
8
|
var colorSchemes = ["light", "dark"];
|
|
9
9
|
var MEDIA = "(prefers-color-scheme: dark)";
|
|
10
10
|
var THEME_STORAGE_KEY = "theme";
|
|
11
|
-
/**
|
|
12
|
-
* @borrows [next-themes](https://github.com/pacocoursey/next-themes)
|
|
13
|
-
*
|
|
14
|
-
* Differences:
|
|
15
|
-
*
|
|
16
|
-
* - enableColorScheme: `false` by default (instead of `true`), this plays more
|
|
17
|
-
* nicely with tailwind `dark` class mode as dark theme is supposed to be only
|
|
18
|
-
* controlled by tailwind modifiers
|
|
19
|
-
*/
|
|
20
11
|
export var ThemeProvider = function (_a) {
|
|
21
12
|
var forcedTheme = _a.forcedTheme, _b = _a.disableTransitionOnChange, disableTransitionOnChange = _b === void 0 ? false : _b, _c = _a.enableSystem, enableSystem = _c === void 0 ? true : _c, enableColorScheme = _a.enableColorScheme, _d = _a.themes, themes = _d === void 0 ? ["light", "dark"] : _d, _e = _a.defaultTheme, defaultTheme = _e === void 0 ? enableSystem ? "system" : "light" : _e, _f = _a.attribute, attribute = _f === void 0 ? "data-theme" : _f, value = _a.value, children = _a.children, nonce = _a.nonce;
|
|
22
|
-
var _g = useState(function () {
|
|
13
|
+
var _g = __read(useState(function () {
|
|
23
14
|
return getTheme(THEME_STORAGE_KEY, defaultTheme);
|
|
24
|
-
}), theme = _g[0], setThemeState = _g[1];
|
|
25
|
-
var _h = useState(function () {
|
|
15
|
+
}), 2), theme = _g[0], setThemeState = _g[1];
|
|
16
|
+
var _h = __read(useState(function () {
|
|
26
17
|
return getTheme(THEME_STORAGE_KEY);
|
|
27
|
-
}), resolvedTheme = _h[0], setResolvedTheme = _h[1];
|
|
18
|
+
}), 2), resolvedTheme = _h[0], setResolvedTheme = _h[1];
|
|
28
19
|
var attrs = !value ? themes : Object.values(value);
|
|
29
20
|
var applyTheme = useCallback(function (theme) {
|
|
30
21
|
var _a;
|
|
31
22
|
var resolved = theme;
|
|
32
23
|
if (isServer || !resolved)
|
|
33
24
|
return;
|
|
34
|
-
// If theme is system, resolve it before setting theme
|
|
35
25
|
if (theme === "system" && enableSystem) {
|
|
36
26
|
resolved = getSystemTheme();
|
|
37
27
|
}
|
|
@@ -39,7 +29,7 @@ export var ThemeProvider = function (_a) {
|
|
|
39
29
|
var enable = disableTransitionOnChange ? disableAnimation() : null;
|
|
40
30
|
var d = document.documentElement;
|
|
41
31
|
if (attribute === "class") {
|
|
42
|
-
(_a = d.classList).remove.apply(_a, attrs);
|
|
32
|
+
(_a = d.classList).remove.apply(_a, __spreadArray([], __read(attrs), false));
|
|
43
33
|
if (name)
|
|
44
34
|
d.classList.add(name);
|
|
45
35
|
}
|
|
@@ -72,12 +62,10 @@ export var ThemeProvider = function (_a) {
|
|
|
72
62
|
]);
|
|
73
63
|
var setTheme = useCallback(function (theme) {
|
|
74
64
|
setThemeState(theme);
|
|
75
|
-
// Save to storage
|
|
76
65
|
try {
|
|
77
66
|
localStorage.setItem(THEME_STORAGE_KEY, theme);
|
|
78
67
|
}
|
|
79
68
|
catch (e) {
|
|
80
|
-
// Unsupported
|
|
81
69
|
}
|
|
82
70
|
}, []);
|
|
83
71
|
var handleMediaQuery = useCallback(function (e) {
|
|
@@ -87,28 +75,23 @@ export var ThemeProvider = function (_a) {
|
|
|
87
75
|
applyTheme("system");
|
|
88
76
|
}
|
|
89
77
|
}, [theme, enableSystem, forcedTheme, applyTheme]);
|
|
90
|
-
// Always listen to System preference
|
|
91
78
|
useEffect(function () {
|
|
92
79
|
var media = window.matchMedia(MEDIA);
|
|
93
|
-
// Intentionally use deprecated listener methods to support iOS & old browsers
|
|
94
80
|
media.addListener(handleMediaQuery);
|
|
95
81
|
handleMediaQuery(media);
|
|
96
82
|
return function () { return media.removeListener(handleMediaQuery); };
|
|
97
83
|
}, [handleMediaQuery]);
|
|
98
|
-
// localStorage event handling
|
|
99
84
|
useEffect(function () {
|
|
100
85
|
var handleStorage = function (e) {
|
|
101
86
|
if (e.key !== THEME_STORAGE_KEY) {
|
|
102
87
|
return;
|
|
103
88
|
}
|
|
104
|
-
// If default theme set, use it if localstorage === null (happens on local storage manual deletion)
|
|
105
89
|
var theme = e.newValue || defaultTheme;
|
|
106
90
|
setTheme(theme);
|
|
107
91
|
};
|
|
108
92
|
window.addEventListener("storage", handleStorage);
|
|
109
93
|
return function () { return window.removeEventListener("storage", handleStorage); };
|
|
110
94
|
}, [defaultTheme, setTheme]);
|
|
111
|
-
// Whenever theme or forcedTheme changes, apply it
|
|
112
95
|
useEffect(function () {
|
|
113
96
|
applyTheme(forcedTheme !== null && forcedTheme !== void 0 ? forcedTheme : theme);
|
|
114
97
|
}, [applyTheme, forcedTheme, theme]);
|
|
@@ -117,14 +100,13 @@ export var ThemeProvider = function (_a) {
|
|
|
117
100
|
setTheme: setTheme,
|
|
118
101
|
forcedTheme: forcedTheme,
|
|
119
102
|
resolvedTheme: theme === "system" ? resolvedTheme : theme,
|
|
120
|
-
themes: enableSystem ? __spreadArray(__spreadArray([], themes,
|
|
103
|
+
themes: enableSystem ? __spreadArray(__spreadArray([], __read(themes), false), ["system"], false) : themes,
|
|
121
104
|
systemTheme: (enableSystem ? resolvedTheme : undefined),
|
|
122
105
|
}, children: [_jsx(ThemeScript, { forcedTheme: forcedTheme, disableTransitionOnChange: disableTransitionOnChange, enableSystem: enableSystem, enableColorScheme: enableColorScheme, themes: themes, defaultTheme: defaultTheme, attribute: attribute, value: value, children: children, attrs: attrs, nonce: nonce }), children] }));
|
|
123
106
|
};
|
|
124
107
|
var ThemeScript = memo(function (_a) {
|
|
125
108
|
var forcedTheme = _a.forcedTheme, attribute = _a.attribute, enableSystem = _a.enableSystem, enableColorScheme = _a.enableColorScheme, defaultTheme = _a.defaultTheme, value = _a.value, attrs = _a.attrs, nonce = _a.nonce;
|
|
126
109
|
var defaultSystem = defaultTheme === "system";
|
|
127
|
-
// Code-golfing the amount of characters in the script
|
|
128
110
|
var optimization = (function () {
|
|
129
111
|
var removeClasses = "d.remove(".concat(attrs
|
|
130
112
|
.map(function (t) { return "'".concat(t, "'"); })
|
|
@@ -151,9 +133,6 @@ var ThemeScript = memo(function (_a) {
|
|
|
151
133
|
var resolvedName = value ? value[name] : name;
|
|
152
134
|
var val = literal ? name + "|| ''" : "'".concat(resolvedName, "'");
|
|
153
135
|
var text = "";
|
|
154
|
-
// MUCH faster to set colorScheme alongside HTML attribute/class
|
|
155
|
-
// as it only incurs 1 style recalculation rather than 2
|
|
156
|
-
// This can save over 250ms of work for pages with big DOM
|
|
157
136
|
if (enableColorScheme &&
|
|
158
137
|
setColorScheme &&
|
|
159
138
|
!literal &&
|
|
@@ -186,16 +165,9 @@ var ThemeScript = memo(function (_a) {
|
|
|
186
165
|
}
|
|
187
166
|
return "!function(){try{".concat(optimization, "var e=localStorage.getItem(\"").concat(THEME_STORAGE_KEY, "\");if(e){").concat(value ? "var x=".concat(JSON.stringify(value), ";") : "").concat(updateDOM(value ? "x[e]" : "e", true), "}else{").concat(updateDOM(defaultTheme, false, false), ";}").concat(fallbackColorScheme, "}catch(t){}}();");
|
|
188
167
|
})();
|
|
189
|
-
// We MUST use next/script's `beforeInteractive` strategy to avoid flashing on load.
|
|
190
|
-
// However, it only accepts the `src` prop, not `dangerouslySetInnerHTML` or `children`
|
|
191
|
-
// But our script cannot be external because it changes at runtime based on React props
|
|
192
|
-
// so we trick next/script by passing `src` as a base64 JS script
|
|
193
168
|
var encodedScript = "data:text/javascript;base64,".concat(encodeBase64(scriptSrc));
|
|
194
169
|
return (_jsx(NextScript, { id: "next-theme-script", strategy: "beforeInteractive", src: encodedScript, nonce: nonce }));
|
|
195
|
-
},
|
|
196
|
-
// Never re-render this component
|
|
197
|
-
function () { return true; });
|
|
198
|
-
// Helpers
|
|
170
|
+
}, function () { return true; });
|
|
199
171
|
var getTheme = function (key, fallback) {
|
|
200
172
|
if (isServer)
|
|
201
173
|
return undefined;
|
|
@@ -204,7 +176,6 @@ var getTheme = function (key, fallback) {
|
|
|
204
176
|
theme = localStorage.getItem(key) || undefined;
|
|
205
177
|
}
|
|
206
178
|
catch (e) {
|
|
207
|
-
// Unsupported
|
|
208
179
|
}
|
|
209
180
|
return theme || fallback;
|
|
210
181
|
};
|
|
@@ -214,9 +185,7 @@ var disableAnimation = function () {
|
|
|
214
185
|
css.appendChild(d.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}"));
|
|
215
186
|
d.head.appendChild(css);
|
|
216
187
|
return function () {
|
|
217
|
-
// Force restyle
|
|
218
188
|
(function () { return window.getComputedStyle(d.body); })();
|
|
219
|
-
// Wait for next tick before removing
|
|
220
189
|
setTimeout(function () {
|
|
221
190
|
d.head.removeChild(css);
|
|
222
191
|
}, 1);
|
package/config-i18n.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Redirect as _Redirect, Rewrite as _Rewrite } from "next/dist/lib/load-custom-routes";
|
|
2
|
+
export type Redirect = Omit<_Redirect, "locale"> & {
|
|
3
|
+
locale?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type Rewrite = Omit<_Rewrite, "locale"> & {
|
|
6
|
+
locale?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type Route = string | {
|
|
9
|
+
[key: string]: Route | string;
|
|
10
|
+
};
|
|
11
|
+
type RoutesByLocale = Record<string, Route>;
|
|
12
|
+
export type Locale = string;
|
|
13
|
+
export type Routes = Record<Locale, RoutesByLocale>;
|
|
14
|
+
type RoutesMapRoute = {
|
|
15
|
+
template: string;
|
|
16
|
+
pathname: string;
|
|
17
|
+
wildcard?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function normaliseUrlPathname(pathname?: string): string;
|
|
20
|
+
export declare function toPath(urlOrPathname?: string): string;
|
|
21
|
+
export declare function encodePathname(pathname?: string): string;
|
|
22
|
+
export declare function getRoutesOfDefaultLocale(routes: Routes | RoutesByLocale, defaultLocale?: Locale): RoutesByLocale;
|
|
23
|
+
export type ConfigI18nOptions = {
|
|
24
|
+
locales: Locale[];
|
|
25
|
+
defaultLocale: Locale;
|
|
26
|
+
hideDefaultLocaleInUrl?: boolean;
|
|
27
|
+
localeParam?: string;
|
|
28
|
+
};
|
|
29
|
+
type Options = ConfigI18nOptions & {
|
|
30
|
+
routes: Routes;
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
permanent?: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare function getPathRedirect(arg: Pick<GetRedirectsOptions, "localeParam" | "permanent"> & {
|
|
35
|
+
localeSource?: Locale;
|
|
36
|
+
localeDestination?: Locale;
|
|
37
|
+
route: RoutesMapRoute;
|
|
38
|
+
usePathnameAsSource?: boolean;
|
|
39
|
+
}): Redirect | undefined;
|
|
40
|
+
type GetRedirectsOptions = Options;
|
|
41
|
+
export declare function getRedirects(arg: GetRedirectsOptions): Promise<Redirect[]>;
|
|
42
|
+
export declare function getPathRewrite(arg: Pick<GetRewritesOptions, "localeParam"> & {
|
|
43
|
+
localeSource?: Locale;
|
|
44
|
+
localeDestination?: Locale;
|
|
45
|
+
route: RoutesMapRoute;
|
|
46
|
+
}): {
|
|
47
|
+
source: string;
|
|
48
|
+
destination: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
type GetRewritesOptions = Options;
|
|
51
|
+
export declare function getRewrites(arg: GetRewritesOptions): Promise<Rewrite[]>;
|
|
52
|
+
export {};
|