@koine/next 1.0.8 → 1.0.11
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/Analytics/AnalyticsGoogle.d.ts +0 -0
- package/Analytics/AnalyticsGoogle.js +2 -2
- package/Analytics/index.d.ts +0 -0
- package/Analytics/index.js +0 -0
- package/Analytics/package.json +6 -0
- package/Auth/helpers.d.ts +0 -0
- package/Auth/helpers.js +0 -0
- package/Auth/index.d.ts +0 -0
- package/Auth/index.js +0 -0
- package/Auth/package.json +6 -0
- package/Auth/useLogin.d.ts +1 -1
- package/Auth/useLogin.js +4 -1
- package/Auth/useLoginUrl.d.ts +0 -0
- package/Auth/useLoginUrl.js +0 -0
- package/Auth/useLogout.d.ts +0 -0
- package/Auth/useLogout.js +0 -0
- package/Favicon/Favicon.d.ts +0 -0
- package/Favicon/Favicon.js +1 -1
- package/Favicon/index.d.ts +0 -0
- package/Favicon/index.js +0 -0
- package/Favicon/package.json +6 -0
- package/Forms/index.d.ts +0 -0
- package/Forms/index.js +0 -0
- package/Forms/package.json +6 -0
- package/Forms/useForm.d.ts +0 -0
- package/Forms/useForm.js +8 -4
- package/Forms/useSubmit.d.ts +0 -0
- package/Forms/useSubmit.js +12 -9
- package/Head/Head.d.ts +0 -0
- package/Head/Head.js +0 -0
- package/Head/index.d.ts +0 -0
- package/Head/index.js +0 -0
- package/Head/package.json +6 -0
- package/I18n/I18n.d.ts +3 -7
- package/I18n/I18n.js +2 -14
- package/I18n/index.d.ts +0 -0
- package/I18n/index.js +0 -0
- package/I18n/package.json +6 -0
- package/Img/Img.d.ts +4 -4
- package/Img/Img.js +2 -4
- package/Img/index.d.ts +0 -0
- package/Img/index.js +0 -0
- package/Img/package.json +6 -0
- package/Link/Link.d.ts +4 -3
- package/Link/Link.js +2 -5
- package/Link/index.d.ts +0 -0
- package/Link/index.js +0 -0
- package/Link/package.json +6 -0
- package/NextProgress/NextProgress.d.ts +20 -9
- package/NextProgress/NextProgress.js +2 -3
- package/NextProgress/index.d.ts +2 -1
- package/NextProgress/index.js +1 -1
- package/NextProgress/package.json +6 -0
- package/README.md +0 -0
- package/Seo/Seo.d.ts +0 -0
- package/Seo/Seo.js +0 -0
- package/Seo/SeoDefaults.d.ts +0 -0
- package/Seo/SeoDefaults.js +0 -0
- package/Seo/helpers.d.ts +0 -0
- package/Seo/helpers.js +17 -19
- package/Seo/index.d.ts +0 -0
- package/Seo/index.js +0 -0
- package/Seo/package.json +6 -0
- package/Theme/Theme.d.ts +3 -3
- package/Theme/Theme.js +18 -18
- package/Theme/index.d.ts +0 -0
- package/Theme/index.js +0 -0
- package/Theme/package.json +6 -0
- package/app/AppHead.d.ts +1 -2
- package/app/AppHead.js +2 -2
- package/app/AppMain.d.ts +35 -0
- package/app/AppMain.js +1 -0
- package/app/css/AppMain.d.ts +8 -0
- package/app/{AppMain--vanilla.js → css/AppMain.js} +3 -3
- package/app/css/AppTheme.d.ts +10 -0
- package/app/{AppTheme--vanilla.js → css/AppTheme.js} +3 -3
- package/app/css/auth/index.d.ts +9 -0
- package/app/css/auth/index.js +13 -0
- package/app/css/auth/package.json +6 -0
- package/app/css/index.d.ts +54 -0
- package/app/css/index.js +57 -0
- package/app/css/package.json +6 -0
- package/app/em/AppMain.d.ts +10 -0
- package/app/em/AppMain.js +22 -0
- package/app/{AppTheme--emotion.d.ts → em/AppTheme.d.ts} +3 -3
- package/app/{AppTheme--emotion.js → em/AppTheme.js} +5 -5
- package/app/em/auth/index.d.ts +9 -0
- package/app/em/auth/index.js +13 -0
- package/app/em/auth/package.json +6 -0
- package/app/em/index.d.ts +9 -0
- package/app/em/index.js +12 -0
- package/app/em/package.json +6 -0
- package/app/index.d.ts +1 -10
- package/app/index.js +1 -10
- package/app/package.json +6 -0
- package/app/sc/AppMain.d.ts +10 -0
- package/app/sc/AppMain.js +22 -0
- package/app/sc/AppTheme.d.ts +13 -0
- package/app/sc/AppTheme.js +9 -0
- package/app/sc/auth/index.d.ts +9 -0
- package/app/sc/auth/index.js +13 -0
- package/app/sc/auth/package.json +6 -0
- package/app/sc/index.d.ts +56 -0
- package/app/sc/index.js +59 -0
- package/app/sc/package.json +6 -0
- package/config/index.d.ts +14 -1
- package/config/index.js +68 -38
- package/config/package.json +6 -0
- package/document/Document.d.ts +7 -2
- package/document/Document.js +8 -3
- package/document/css/index.d.ts +22 -0
- package/document/css/index.js +30 -0
- package/document/css/package.json +6 -0
- package/document/em/index.d.ts +16 -0
- package/document/{Document--emotion.js → em/index.js} +24 -11
- package/document/em/package.json +6 -0
- package/document/index.d.ts +2 -4
- package/document/index.js +2 -4
- package/document/package.json +6 -0
- package/document/{Document--sc.d.ts → sc/index.d.ts} +11 -2
- package/document/sc/index.js +44 -0
- package/document/sc/package.json +6 -0
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/node/Analytics/AnalyticsGoogle.js +42 -0
- package/node/Analytics/index.js +4 -0
- package/node/Auth/helpers.js +26 -0
- package/node/Auth/index.js +7 -0
- package/node/Auth/useLogin.js +54 -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 +5 -0
- package/node/Forms/useForm.js +41 -0
- package/node/Forms/useSubmit.js +27 -0
- package/node/Head/Head.js +8 -0
- package/node/Head/index.js +4 -0
- package/node/I18n/I18n.js +82 -0
- package/node/I18n/index.js +4 -0
- package/node/Img/Img.js +34 -0
- package/node/Img/index.js +4 -0
- package/node/Link/Link.js +13 -0
- package/node/Link/index.js +4 -0
- package/node/NextProgress/NextProgress.js +41 -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 +115 -0
- package/node/Seo/index.js +15 -0
- package/node/Theme/Theme.js +241 -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 +16 -0
- package/node/app/css/AppTheme.js +16 -0
- package/node/app/css/auth/index.js +18 -0
- package/node/app/css/index.js +62 -0
- package/node/app/em/AppMain.js +26 -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 +26 -0
- package/node/app/sc/AppTheme.js +13 -0
- package/node/app/sc/auth/index.js +18 -0
- package/node/app/sc/index.js +64 -0
- package/node/config/index.js +184 -0
- package/node/document/Document.js +24 -0
- package/node/document/css/index.js +35 -0
- package/node/document/em/index.js +73 -0
- package/node/document/index.js +7 -0
- package/node/document/sc/index.js +49 -0
- package/node/index.js +15 -0
- package/node/utils/api.js +38 -0
- package/node/utils/emotion-cache.js +13 -0
- package/node/utils/index.js +32 -0
- package/package.json +17 -25
- package/typings.d.ts +10 -7
- package/utils/api.d.ts +0 -0
- package/utils/api.js +8 -6
- package/utils/emotion-cache.d.ts +0 -0
- package/utils/emotion-cache.js +0 -0
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/utils/package.json +6 -0
- package/app/App--emotion.d.ts +0 -10
- package/app/App--emotion.js +0 -11
- package/app/App--sc.d.ts +0 -10
- package/app/App--sc.js +0 -11
- package/app/App--vanilla.d.ts +0 -10
- package/app/App--vanilla.js +0 -11
- package/app/AppAuth--emotion.d.ts +0 -10
- package/app/AppAuth--emotion.js +0 -12
- package/app/AppAuth--sc.d.ts +0 -10
- package/app/AppAuth--sc.js +0 -12
- package/app/AppMain--emotion.d.ts +0 -34
- package/app/AppMain--emotion.js +0 -27
- package/app/AppMain--sc.d.ts +0 -34
- package/app/AppMain--sc.js +0 -27
- package/app/AppMain--vanilla.d.ts +0 -27
- package/app/AppTheme--sc.d.ts +0 -13
- package/app/AppTheme--sc.js +0 -9
- package/app/AppTheme--vanilla.d.ts +0 -10
- package/app/motion-features.d.ts +0 -2
- package/app/motion-features.js +0 -2
- package/document/Document--emotion.d.ts +0 -5
- package/document/Document--sc.js +0 -33
- package/document/Document--vanilla.d.ts +0 -11
- package/document/Document--vanilla.js +0 -20
- package/index.umd.js +0 -6621
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCallbackUrl = exports.getAuthRoutes = exports.AUTH_ROUTES = void 0;
|
|
4
|
+
const 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((map, name) => {
|
|
13
|
+
const routePage = exports.AUTH_ROUTES[name];
|
|
14
|
+
// @ts-expect-error cannot remember
|
|
15
|
+
map[name] = (0, utils_1.isString)(routePage) ? t(`~:${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 = window.location.href) {
|
|
24
|
+
return url.split("callbackUrl=")[1] || "";
|
|
25
|
+
}
|
|
26
|
+
exports.getCallbackUrl = getCallbackUrl;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const 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,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLogin = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const router_1 = require("next/router");
|
|
6
|
+
const react_2 = require("next-auth/react");
|
|
7
|
+
const utils_1 = require("@koine/utils");
|
|
8
|
+
const I18n_1 = require("../I18n");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
10
|
+
function useLogin() {
|
|
11
|
+
const t = (0, I18n_1.useT)();
|
|
12
|
+
const { push } = (0, router_1.useRouter)();
|
|
13
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
14
|
+
const [ok, setOk] = (0, react_1.useState)(false);
|
|
15
|
+
const [fail, setFail] = (0, react_1.useState)(false);
|
|
16
|
+
const submit = (0, react_1.useCallback)((data) => {
|
|
17
|
+
setLoading(true);
|
|
18
|
+
(0, react_2.signIn)("credentials", {
|
|
19
|
+
...data,
|
|
20
|
+
redirect: false,
|
|
21
|
+
})
|
|
22
|
+
// @ts-expect-error FIXME: at some point...
|
|
23
|
+
.then(({ ok }) => {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
setOk(ok);
|
|
26
|
+
setFail(!ok);
|
|
27
|
+
if (ok) {
|
|
28
|
+
const redirectUrl = (0, utils_1.parseURL)((0, helpers_1.getCallbackUrl)());
|
|
29
|
+
const { login, register, profile } = (0, helpers_1.getAuthRoutes)(t);
|
|
30
|
+
if (redirectUrl) {
|
|
31
|
+
const redirectPath = redirectUrl.pathname;
|
|
32
|
+
if (profile &&
|
|
33
|
+
(redirectPath === login || redirectPath === register)) {
|
|
34
|
+
push(profile);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
push(redirectPath + redirectUrl.search);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (profile) {
|
|
41
|
+
push(profile);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}, [t, push]);
|
|
46
|
+
// TODO: useMemo ?
|
|
47
|
+
return {
|
|
48
|
+
submit,
|
|
49
|
+
loading,
|
|
50
|
+
ok,
|
|
51
|
+
fail,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.useLogin = useLogin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLoginUrl = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const I18n_1 = require("../I18n");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
function useLoginUrl() {
|
|
8
|
+
const [currentUrl, setCurrentUrl] = (0, react_1.useState)("");
|
|
9
|
+
const t = (0, I18n_1.useT)();
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
setCurrentUrl(`?callbackUrl=${window.location.href}`);
|
|
12
|
+
}, []);
|
|
13
|
+
return `${(0, helpers_1.getAuthRoutes)(t).login}${currentUrl}`;
|
|
14
|
+
}
|
|
15
|
+
exports.useLoginUrl = useLoginUrl;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLogout = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const router_1 = require("next/router");
|
|
6
|
+
const react_2 = require("next-auth/react");
|
|
7
|
+
const utils_1 = require("@koine/utils");
|
|
8
|
+
const I18n_1 = require("../I18n");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
10
|
+
function useLogout() {
|
|
11
|
+
const t = (0, I18n_1.useT)();
|
|
12
|
+
const { push } = (0, router_1.useRouter)();
|
|
13
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
14
|
+
const [ok, setOk] = (0, react_1.useState)(false);
|
|
15
|
+
const [fail] = (0, react_1.useState)(false);
|
|
16
|
+
const submit = (0, react_1.useCallback)((event) => {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
event.stopPropagation();
|
|
19
|
+
setLoading(true);
|
|
20
|
+
(0, react_2.signOut)({ redirect: false }).then(() => {
|
|
21
|
+
setLoading(false);
|
|
22
|
+
setOk(true);
|
|
23
|
+
const redirectUrl = (0, utils_1.parseURL)((0, helpers_1.getCallbackUrl)());
|
|
24
|
+
const currentUrl = (0, utils_1.parseURL)(window.location.href);
|
|
25
|
+
const { secured } = (0, helpers_1.getAuthRoutes)(t);
|
|
26
|
+
const signin = t("~:/signin");
|
|
27
|
+
const profile = t("~:/profile");
|
|
28
|
+
const targetUrl = redirectUrl || currentUrl;
|
|
29
|
+
let redirect = "";
|
|
30
|
+
if (targetUrl) {
|
|
31
|
+
if (targetUrl.pathname === profile) {
|
|
32
|
+
redirect = signin;
|
|
33
|
+
}
|
|
34
|
+
else if (secured) {
|
|
35
|
+
for (let i = 0; i < secured.length; i++) {
|
|
36
|
+
if (targetUrl.pathname.match(secured[i])) {
|
|
37
|
+
redirect = signin;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (redirect) {
|
|
44
|
+
push(redirect);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}, [t, push]);
|
|
48
|
+
// TODO: useMemo ?
|
|
49
|
+
return {
|
|
50
|
+
submit,
|
|
51
|
+
loading,
|
|
52
|
+
ok,
|
|
53
|
+
fail,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.useLogout = useLogout;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Favicon = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const head_1 = tslib_1.__importDefault(require("next/head"));
|
|
7
|
+
const react_1 = require("@koine/react");
|
|
8
|
+
const Favicon = (props) => ((0, jsx_runtime_1.jsx)(head_1.default, { children: (0, jsx_runtime_1.jsx)(react_1.FaviconTags, { ...props }) }));
|
|
9
|
+
exports.Favicon = Favicon;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useForm = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
+
const yup_1 = require("@hookform/resolvers/yup");
|
|
7
|
+
const I18n_1 = require("../I18n");
|
|
8
|
+
function useForm(
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
schema, i18nNamespace, formProps = {}, debug) {
|
|
11
|
+
const t = (0, I18n_1.useT)(i18nNamespace);
|
|
12
|
+
// const form = _useForm<InferType<ObjectSchema<T, object>>>({
|
|
13
|
+
const form = (0, react_hook_form_1.useForm)({
|
|
14
|
+
// @ts-expect-error FIXME:
|
|
15
|
+
resolver: (0, yup_1.yupResolver)(schema),
|
|
16
|
+
// make the form behave more closer as native:
|
|
17
|
+
// shouldUnregister: true,
|
|
18
|
+
...formProps,
|
|
19
|
+
});
|
|
20
|
+
// const { control, register, setValue } = form;
|
|
21
|
+
// const field = { control, register, setValue, t };
|
|
22
|
+
// if (process.env["NODE_ENV"] !== "production") {
|
|
23
|
+
// if (debug) {
|
|
24
|
+
// console.log(
|
|
25
|
+
// `Form ${i18nNamespace} data`,
|
|
26
|
+
// form.watch(),
|
|
27
|
+
// `errors: `,
|
|
28
|
+
// form.formState.errors
|
|
29
|
+
// );
|
|
30
|
+
// }
|
|
31
|
+
// }
|
|
32
|
+
// if (formProps.mode === "onChange") {
|
|
33
|
+
// return { field, ...form };
|
|
34
|
+
// }
|
|
35
|
+
return (0, react_1.useMemo)(() => {
|
|
36
|
+
const { control, register, setValue } = form;
|
|
37
|
+
const field = { control, register, setValue, t };
|
|
38
|
+
return { field, ...form };
|
|
39
|
+
}, [t, form]);
|
|
40
|
+
}
|
|
41
|
+
exports.useForm = useForm;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSubmit = void 0;
|
|
4
|
+
const react_1 = require("@koine/react");
|
|
5
|
+
const api_1 = require("../utils/api");
|
|
6
|
+
function useSubmit(url, transformData) {
|
|
7
|
+
const [state, submit] = (0, react_1.useAsyncFn)(async (json) => {
|
|
8
|
+
if (transformData)
|
|
9
|
+
json = transformData(json);
|
|
10
|
+
const response = await api_1.api.post(url, {
|
|
11
|
+
json,
|
|
12
|
+
});
|
|
13
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
14
|
+
console.log("[@koine/next] useSubmit response", response);
|
|
15
|
+
}
|
|
16
|
+
return response;
|
|
17
|
+
}, [url, transformData]);
|
|
18
|
+
const { loading, error, value } = state;
|
|
19
|
+
const fail = !loading && (!!error || value?.fail);
|
|
20
|
+
return {
|
|
21
|
+
submit,
|
|
22
|
+
loading,
|
|
23
|
+
...(value || {}),
|
|
24
|
+
fail,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.useSubmit = useSubmit;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Head = void 0;
|
|
7
|
+
var head_1 = require("next/head");
|
|
8
|
+
Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return __importDefault(head_1).default; } });
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="@koine/next/typings" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useDateFormat = exports.translationAsOptions = exports.useT = exports.T = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
7
|
+
/**
|
|
8
|
+
* @file
|
|
9
|
+
*
|
|
10
|
+
* About the typescript support for translation strings @see:
|
|
11
|
+
* - https://github.com/vinissimus/next-translate/issues/721
|
|
12
|
+
*/
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const router_1 = require("next/router");
|
|
15
|
+
const format_1 = tslib_1.__importDefault(require("date-fns/format"));
|
|
16
|
+
const useTranslation_1 = tslib_1.__importDefault(require("next-translate/useTranslation"));
|
|
17
|
+
const react_2 = require("@koine/react");
|
|
18
|
+
var Trans_1 = require("next-translate/Trans");
|
|
19
|
+
Object.defineProperty(exports, "T", { enumerable: true, get: function () { return tslib_1.__importDefault(Trans_1).default; } });
|
|
20
|
+
/**
|
|
21
|
+
* FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
|
|
22
|
+
* problem of untranslated text during page transitions
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
25
|
+
*/
|
|
26
|
+
function useT(namespace) {
|
|
27
|
+
const t = (0, useTranslation_1.default)().t;
|
|
28
|
+
// const typedT = <
|
|
29
|
+
// // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
30
|
+
// R extends unknown = string,
|
|
31
|
+
// // Q extends TranslationQuery = TranslationQuery
|
|
32
|
+
// // O extends TranslationOptions = TranslationOptions
|
|
33
|
+
// >(
|
|
34
|
+
// s: N extends TranslateNamespace
|
|
35
|
+
// ? Paths<Koine.NextTranslations[N]> | AllPaths
|
|
36
|
+
// : AllPaths,
|
|
37
|
+
// q?: TranslationQuery,
|
|
38
|
+
// o?: TranslationOptions
|
|
39
|
+
// ) =>
|
|
40
|
+
// // eslint-disable-next-line
|
|
41
|
+
// t.call(
|
|
42
|
+
// null,
|
|
43
|
+
// namespace ? `${namespace}:${s}` : s,
|
|
44
|
+
// q === "obj" ? null : q,
|
|
45
|
+
// q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
46
|
+
// // ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
|
|
47
|
+
// ) as R;
|
|
48
|
+
// return typedT;
|
|
49
|
+
const tMemoized = (0, react_1.useMemo)(() => (s, q, o) => t(namespace ? `${namespace}:${s}` : s, q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
50
|
+
// ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
|
|
51
|
+
), [t, namespace]);
|
|
52
|
+
// return tMemoized as Translate<N>;
|
|
53
|
+
return tMemoized;
|
|
54
|
+
}
|
|
55
|
+
exports.useT = useT;
|
|
56
|
+
function translationAsOptions(t, i18nKey) {
|
|
57
|
+
const dictionary = t(i18nKey, undefined, {
|
|
58
|
+
returnObjects: true,
|
|
59
|
+
});
|
|
60
|
+
return Object.keys(dictionary).map((key) => ({
|
|
61
|
+
value: key,
|
|
62
|
+
label: dictionary[key],
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
exports.translationAsOptions = translationAsOptions;
|
|
66
|
+
/**
|
|
67
|
+
* Automatically returns the `date-fns/format` function with the right locale
|
|
68
|
+
* passed as option (grabbed from next router value).
|
|
69
|
+
*/
|
|
70
|
+
const useDateFormat = () => {
|
|
71
|
+
const [formatter, setFormatter] = (0, react_1.useState)(() => (...args) => (0, format_1.default)(...args));
|
|
72
|
+
const router = (0, router_1.useRouter)();
|
|
73
|
+
const locale = (0, react_2.useDateLocale)(router.locale);
|
|
74
|
+
(0, react_1.useEffect)(() => {
|
|
75
|
+
if (locale) {
|
|
76
|
+
const newFormatter = (date, _format, options) => (0, format_1.default)(date, _format, { ...(options || {}), locale });
|
|
77
|
+
setFormatter(() => (...args) => newFormatter(...args));
|
|
78
|
+
}
|
|
79
|
+
}, [locale]);
|
|
80
|
+
return formatter;
|
|
81
|
+
};
|
|
82
|
+
exports.useDateFormat = useDateFormat;
|
package/node/Img/Img.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextImgProps = exports.NextImgSmart = exports.NextImg = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const image_1 = tslib_1.__importDefault(require("next/image"));
|
|
8
|
+
exports.NextImg = image_1.default;
|
|
9
|
+
const NextImgSmart = (props) => {
|
|
10
|
+
const [$loaded, setLoaded] = (0, react_1.useState)(false);
|
|
11
|
+
const [$error, setError] = (0, react_1.useState)(false);
|
|
12
|
+
const { nextImgProps, restProps } = getNextImgProps(props);
|
|
13
|
+
const { Wrap } = restProps;
|
|
14
|
+
return nextImgProps.priority ? ((0, jsx_runtime_1.jsx)(image_1.default, { ...nextImgProps })) : ((0, jsx_runtime_1.jsx)(Wrap, { ...restProps, "$loaded": $loaded, "$error": $error, children: (0, jsx_runtime_1.jsx)(image_1.default, { ...nextImgProps, onLoadingComplete: () => setLoaded(true), onError: () => setError(true) }) }));
|
|
15
|
+
};
|
|
16
|
+
exports.NextImgSmart = NextImgSmart;
|
|
17
|
+
function getNextImgProps({ src, alt, layout, blurDataURL, width, height, priority, objectFit, objectPosition, ...restProps }) {
|
|
18
|
+
const nextImgProps = {
|
|
19
|
+
src,
|
|
20
|
+
alt,
|
|
21
|
+
layout,
|
|
22
|
+
blurDataURL,
|
|
23
|
+
width,
|
|
24
|
+
height,
|
|
25
|
+
priority,
|
|
26
|
+
objectFit,
|
|
27
|
+
objectPosition,
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
nextImgProps,
|
|
31
|
+
restProps,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.getNextImgProps = getNextImgProps;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Link = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const link_1 = tslib_1.__importDefault(require("next/link"));
|
|
8
|
+
/**
|
|
9
|
+
* @see https://next.js.org/docs/api-reference/next/link
|
|
10
|
+
*/
|
|
11
|
+
exports.Link = (0, react_1.forwardRef)(function Link({ href, prefetch, replace, scroll, shallow, locale, Link = "span", ...props }, ref) {
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(link_1.default, { href: href, replace: replace, scroll: scroll, shallow: shallow, locale: locale, passHref: true, children: (0, jsx_runtime_1.jsx)(Link, { ref: ref, ...props }) }));
|
|
13
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextProgress = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const router_1 = require("next/router");
|
|
7
|
+
const NextProgress = ({ startAt = 0.3, showOnShallow = true, stopDelayMs = 200, Overlay = "div", }) => {
|
|
8
|
+
const { events } = (0, router_1.useRouter)();
|
|
9
|
+
// const [progress, setProgress] = useState(0);
|
|
10
|
+
const [running, setRunning] = (0, react_1.useState)(false);
|
|
11
|
+
const timer = (0, react_1.useRef)(null);
|
|
12
|
+
const routeChangeStart = (0, react_1.useCallback)((_, { shallow }) => {
|
|
13
|
+
if (!shallow || showOnShallow) {
|
|
14
|
+
// setProgress(startAt);
|
|
15
|
+
setRunning(true);
|
|
16
|
+
}
|
|
17
|
+
}, [showOnShallow]);
|
|
18
|
+
const routeChangeEnd = (0, react_1.useCallback)((_, { shallow }) => {
|
|
19
|
+
if (!shallow || showOnShallow) {
|
|
20
|
+
if (timer.current) {
|
|
21
|
+
clearTimeout(timer.current);
|
|
22
|
+
}
|
|
23
|
+
timer.current = setTimeout(() => {
|
|
24
|
+
// setProgress(100);
|
|
25
|
+
setRunning(false);
|
|
26
|
+
}, stopDelayMs);
|
|
27
|
+
}
|
|
28
|
+
}, [showOnShallow, stopDelayMs, timer]);
|
|
29
|
+
(0, react_1.useEffect)(() => {
|
|
30
|
+
events.on("routeChangeStart", routeChangeStart);
|
|
31
|
+
events.on("routeChangeComplete", routeChangeEnd);
|
|
32
|
+
events.on("routeChangeError", routeChangeEnd);
|
|
33
|
+
return () => {
|
|
34
|
+
events.off("routeChangeStart", routeChangeStart);
|
|
35
|
+
events.off("routeChangeComplete", routeChangeEnd);
|
|
36
|
+
events.off("routeChangeError", routeChangeEnd);
|
|
37
|
+
};
|
|
38
|
+
}, [events, routeChangeStart, routeChangeEnd]);
|
|
39
|
+
return (0, jsx_runtime_1.jsx)(Overlay, { running: running });
|
|
40
|
+
};
|
|
41
|
+
exports.NextProgress = NextProgress;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextProgress = void 0;
|
|
4
|
+
var NextProgress_1 = require("./NextProgress");
|
|
5
|
+
Object.defineProperty(exports, "NextProgress", { enumerable: true, get: function () { return NextProgress_1.NextProgress; } });
|
package/node/Seo/Seo.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Seo = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const head_1 = tslib_1.__importDefault(require("next/head"));
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
const _Seo = (props) => {
|
|
10
|
+
return (0, jsx_runtime_1.jsx)(head_1.default, { children: (0, helpers_1.buildTags)(props) });
|
|
11
|
+
};
|
|
12
|
+
exports.Seo = (0, react_1.memo)(_Seo);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeoDefaults = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const head_1 = tslib_1.__importDefault(require("next/head"));
|
|
8
|
+
// import { useRouter } from "next/router";
|
|
9
|
+
// import { getSiteUrl } from "../utils";
|
|
10
|
+
const helpers_1 = require("./helpers");
|
|
11
|
+
const _SeoDefaults = (props) => {
|
|
12
|
+
// const router = useRouter();
|
|
13
|
+
// props.openGraph.url = getSiteUrl(router.asPath);
|
|
14
|
+
return (0, jsx_runtime_1.jsx)(head_1.default, { children: (0, helpers_1.buildTags)(props) });
|
|
15
|
+
};
|
|
16
|
+
exports.SeoDefaults = (0, react_1.memo)(_SeoDefaults);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTags = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const utils_1 = require("@koine/utils");
|
|
6
|
+
const defaults = {
|
|
7
|
+
tplTitle: "",
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* We do a couple of things in addition while many other are removed.
|
|
11
|
+
*
|
|
12
|
+
* - Add `seo` meta object coming from a CMS probably
|
|
13
|
+
* - Add `ogimage` and `openGraph.image` as single image source
|
|
14
|
+
* - Add `og` alias to define `openGraph`
|
|
15
|
+
* - Add check for `title` equale to `templateTitle` to avoid meta titles like
|
|
16
|
+
* "My site | My site" often happening in homepages
|
|
17
|
+
* - Remove the open graph videos and images
|
|
18
|
+
*
|
|
19
|
+
* - Shorter code
|
|
20
|
+
*
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
const buildTags = ({ seo, hidden, keywords, title = "", titleTemplate, defaultTitle, noindex, nofollow, description, languageAlternates = [], twitter, facebook, openGraph, og: ogAlias, canonical, metaTags, linkTags, } = {}) => {
|
|
24
|
+
const render = [];
|
|
25
|
+
const $names = {};
|
|
26
|
+
const $properties = {};
|
|
27
|
+
if (titleTemplate) {
|
|
28
|
+
defaults.tplTitle = titleTemplate;
|
|
29
|
+
}
|
|
30
|
+
title = title || seo?.title || "";
|
|
31
|
+
if (title) {
|
|
32
|
+
if (defaults.tplTitle && defaults.tplTitle !== title) {
|
|
33
|
+
title = defaults.tplTitle.replace(/%s/g, title);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (defaultTitle) {
|
|
37
|
+
title = defaultTitle;
|
|
38
|
+
}
|
|
39
|
+
if (title) {
|
|
40
|
+
render.push((0, jsx_runtime_1.jsx)("title", { children: title }, "title"));
|
|
41
|
+
$properties["og:title"] = title; // overridden later...
|
|
42
|
+
}
|
|
43
|
+
$names["robots"] = `${noindex || hidden ? "noindex" : "index"},${nofollow || hidden ? "nofollow" : "follow"}`;
|
|
44
|
+
description = description || seo?.description;
|
|
45
|
+
if (description) {
|
|
46
|
+
$names["description"] = description;
|
|
47
|
+
$properties["og:description"] = description; // overridden later...
|
|
48
|
+
}
|
|
49
|
+
keywords = keywords || seo?.keywords;
|
|
50
|
+
if (keywords) {
|
|
51
|
+
$names["keywords"] = (0, utils_1.isArray)(keywords) ? keywords.join(", ") : keywords;
|
|
52
|
+
}
|
|
53
|
+
if (languageAlternates?.length > 0) {
|
|
54
|
+
languageAlternates.forEach((languageAlternate) => {
|
|
55
|
+
render.push((0, jsx_runtime_1.jsx)("link", { rel: "alternate", hrefLang: languageAlternate.hrefLang, href: languageAlternate.href }, `languageAlternate-${languageAlternate.hrefLang}`));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (canonical) {
|
|
59
|
+
render.push((0, jsx_runtime_1.jsx)("link", { rel: "canonical", href: canonical }, "canonical"));
|
|
60
|
+
$properties["og:url"] = canonical;
|
|
61
|
+
}
|
|
62
|
+
if (facebook?.appId)
|
|
63
|
+
$properties["fb:app_id"] = facebook.appId;
|
|
64
|
+
if (twitter) {
|
|
65
|
+
if (twitter.cardType)
|
|
66
|
+
$names["twitter:card"] = twitter.cardType;
|
|
67
|
+
if (twitter.site)
|
|
68
|
+
$names["twitter:site"] = twitter.site;
|
|
69
|
+
if (twitter.handle)
|
|
70
|
+
$names["twitter:creator"] = twitter.handle;
|
|
71
|
+
}
|
|
72
|
+
const og = ogAlias || openGraph;
|
|
73
|
+
if (og?.title)
|
|
74
|
+
$properties["og:title"] = og?.title;
|
|
75
|
+
if (og?.description)
|
|
76
|
+
$properties["og:description"] = og?.description;
|
|
77
|
+
if (og?.url)
|
|
78
|
+
$properties["og:url"] = og.url;
|
|
79
|
+
if (og?.type)
|
|
80
|
+
$properties["og:type"] = og.type.toLowerCase();
|
|
81
|
+
if (og?.locale)
|
|
82
|
+
$properties["og:locale"] = og.locale;
|
|
83
|
+
if (og?.site_name)
|
|
84
|
+
$properties["og:site_name"] = og.site_name;
|
|
85
|
+
const ogimage = og?.image || seo?.ogimage;
|
|
86
|
+
if (ogimage)
|
|
87
|
+
$properties["og:image"] = ogimage;
|
|
88
|
+
Object.keys($names).forEach((key) => {
|
|
89
|
+
render.push((0, jsx_runtime_1.jsx)("meta", { name: key, content: $names[key] }, key));
|
|
90
|
+
});
|
|
91
|
+
Object.keys($properties).forEach((key) => {
|
|
92
|
+
render.push((0, jsx_runtime_1.jsx)("meta", { property: key, content: $properties[key] }, key));
|
|
93
|
+
});
|
|
94
|
+
if (metaTags && metaTags.length > 0) {
|
|
95
|
+
metaTags.forEach((tag) => {
|
|
96
|
+
render.push((0, jsx_runtime_1.jsx)("meta", { ...tag }, `meta:${tag.keyOverride ?? tag.name ?? tag.property ?? tag.httpEquiv}`));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (linkTags?.length) {
|
|
100
|
+
linkTags.forEach((tag) => {
|
|
101
|
+
render.push((0, jsx_runtime_1.jsx)("link", { ...tag }, `link${tag.keyOverride ?? tag.href}${tag.rel}`));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// TODO: alternates and canonical
|
|
105
|
+
// canonical = 'https://www.domain.com/';
|
|
106
|
+
// languageAlternates={[{
|
|
107
|
+
// hrefLang: 'en',
|
|
108
|
+
// href: 'https://www.domain.com/en',
|
|
109
|
+
// }]}
|
|
110
|
+
// <link rel="alternate" hreflang="x-default" href="https://www.domain.com/nl/">
|
|
111
|
+
// <link rel="alternate" hreflang="nl" href="https://www.domain.com/nl/">
|
|
112
|
+
// <link rel="alternate" hreflang="en" href="https://www.domain.com/en/">
|
|
113
|
+
return render;
|
|
114
|
+
};
|
|
115
|
+
exports.buildTags = buildTags;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file
|
|
4
|
+
*
|
|
5
|
+
* Adapted from https://github.com/garmeeh/next-seo
|
|
6
|
+
*
|
|
7
|
+
* See also:
|
|
8
|
+
* - https://github.com/catnose99/next-head-seo
|
|
9
|
+
* - https://nextjs.org/docs/api-reference/next/head
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
13
|
+
tslib_1.__exportStar(require("./helpers"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./Seo"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./SeoDefaults"), exports);
|