@koine/next 1.0.14 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Auth/helpers.d.ts +2 -2
- package/Auth/useLogin.js +1 -1
- package/Auth/useLoginUrl.js +1 -1
- package/Auth/useLogout.js +1 -1
- package/Forms/index.d.ts +0 -1
- package/Forms/index.js +0 -1
- package/Forms/useForm.d.ts +3 -9
- package/Forms/useForm.js +1 -3
- package/i18n/T/index.d.ts +8 -0
- package/i18n/T/index.js +6 -0
- package/i18n/T/package.json +6 -0
- package/i18n/getT/index.d.ts +3 -0
- package/i18n/getT/index.js +9 -0
- package/i18n/getT/package.json +6 -0
- package/i18n/index.d.ts +6 -0
- package/i18n/index.js +6 -0
- package/{I18n → i18n}/package.json +1 -1
- package/i18n/translationAsOptions/index.d.ts +3 -0
- package/i18n/translationAsOptions/index.js +9 -0
- package/i18n/translationAsOptions/package.json +6 -0
- package/i18n/useDateFormat/index.d.ts +6 -0
- package/i18n/useDateFormat/index.js +37 -0
- package/i18n/useDateFormat/package.json +6 -0
- package/i18n/useLocale/index.d.ts +1 -0
- package/i18n/useLocale/index.js +4 -0
- package/i18n/useLocale/package.json +6 -0
- package/i18n/useT/index.d.ts +50 -0
- package/i18n/useT/index.js +115 -0
- package/i18n/useT/package.json +6 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/node/Analytics/AnalyticsGoogle.js +37 -0
- package/node/Analytics/index.js +4 -0
- package/node/Auth/helpers.js +27 -0
- package/node/Auth/index.js +7 -0
- package/node/Auth/useLogin.js +53 -0
- package/node/Auth/useLoginUrl.js +15 -0
- package/node/Auth/useLogout.js +56 -0
- package/node/Favicon/Favicon.js +9 -0
- package/node/Favicon/index.js +4 -0
- package/node/Forms/index.js +4 -0
- package/node/Forms/useForm.js +37 -0
- package/node/Head/Head.js +5 -0
- package/node/Head/index.js +4 -0
- package/node/Img/Img.js +35 -0
- package/node/Img/index.js +4 -0
- package/node/Link/Link.js +14 -0
- package/node/Link/index.js +4 -0
- package/node/NextProgress/NextProgress.js +44 -0
- package/node/NextProgress/index.js +5 -0
- package/node/Seo/Seo.js +12 -0
- package/node/Seo/SeoDefaults.js +16 -0
- package/node/Seo/helpers.js +119 -0
- package/node/Seo/index.js +15 -0
- package/node/Theme/Theme.js +250 -0
- package/node/Theme/index.js +4 -0
- package/node/app/AppHead.js +10 -0
- package/node/app/AppMain.js +2 -0
- package/node/app/css/AppMain.js +17 -0
- package/node/app/css/AppTheme.js +18 -0
- package/node/app/css/auth/index.js +18 -0
- package/node/app/css/index.js +62 -0
- package/node/app/em/AppMain.js +28 -0
- package/node/app/em/AppTheme.js +22 -0
- package/node/app/em/auth/index.js +18 -0
- package/node/app/em/index.js +17 -0
- package/node/app/index.js +5 -0
- package/node/app/sc/AppMain.js +28 -0
- package/node/app/sc/AppTheme.js +15 -0
- package/node/app/sc/auth/index.js +18 -0
- package/node/app/sc/index.js +64 -0
- package/node/config/index.js +201 -0
- package/node/document/Document.js +29 -0
- package/node/document/css/index.js +47 -0
- package/node/document/em/index.js +62 -0
- package/node/document/index.js +7 -0
- package/node/document/sc/index.js +68 -0
- package/node/i18n/T/index.js +10 -0
- package/node/i18n/getT/index.js +13 -0
- package/node/i18n/index.js +9 -0
- package/node/i18n/translationAsOptions/index.js +13 -0
- package/node/i18n/useDateFormat/index.js +41 -0
- package/node/i18n/useLocale/index.js +9 -0
- package/node/i18n/useT/index.js +120 -0
- package/node/index.js +15 -0
- package/node/utils/emotion-cache.js +13 -0
- package/node/utils/index.js +31 -0
- package/package.json +4 -4
- package/typings.d.ts +19 -10
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/I18n/I18n.d.ts +0 -44
- package/I18n/I18n.js +0 -95
- package/I18n/index.d.ts +0 -1
- package/I18n/index.js +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var document_1 = tslib_1.__importStar(require("next/document"));
|
|
7
|
+
var react_1 = require("@koine/react");
|
|
8
|
+
var create_instance_1 = tslib_1.__importDefault(require("@emotion/server/create-instance"));
|
|
9
|
+
var emotion_cache_1 = require("../../utils/emotion-cache");
|
|
10
|
+
/**
|
|
11
|
+
* Next Document wrapper for `emotion` based projects
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* in your `myapp/pages/_document.tsx`:
|
|
16
|
+
* ```tsx
|
|
17
|
+
* export { Document as default } from "@koine/next/document/em";
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
var Document = /** @class */ (function (_super) {
|
|
21
|
+
tslib_1.__extends(Document, _super);
|
|
22
|
+
function Document() {
|
|
23
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
}
|
|
25
|
+
Document.prototype.render = function () {
|
|
26
|
+
var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
27
|
+
return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_1.Meta, {}), (0, jsx_runtime_1.jsx)(react_1.NoJs, {}), this.props.emotionStyleTags] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
|
|
28
|
+
};
|
|
29
|
+
return Document;
|
|
30
|
+
}(document_1.default));
|
|
31
|
+
exports.Document = Document;
|
|
32
|
+
// `getInitialProps` belongs to `_document` (instead of `_app`),
|
|
33
|
+
// it's compatible with static-site generation (SSG).
|
|
34
|
+
Document.getInitialProps = function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
35
|
+
var originalRenderPage, cache, extractCriticalToChunks, initialProps, emotionStyles, emotionStyleTags;
|
|
36
|
+
return tslib_1.__generator(this, function (_a) {
|
|
37
|
+
switch (_a.label) {
|
|
38
|
+
case 0:
|
|
39
|
+
originalRenderPage = ctx.renderPage;
|
|
40
|
+
cache = (0, emotion_cache_1.createEmotionCache)();
|
|
41
|
+
extractCriticalToChunks = (0, create_instance_1.default)(cache).extractCriticalToChunks;
|
|
42
|
+
ctx.renderPage = function () {
|
|
43
|
+
return originalRenderPage({
|
|
44
|
+
enhanceApp: function (App) {
|
|
45
|
+
return function EnhanceApp(props) {
|
|
46
|
+
return (0, jsx_runtime_1.jsx)(App, tslib_1.__assign({ emotionCache: cache }, props));
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return [4 /*yield*/, Document.getInitialProps(ctx)];
|
|
52
|
+
case 1:
|
|
53
|
+
initialProps = _a.sent();
|
|
54
|
+
emotionStyles = extractCriticalToChunks(initialProps.html);
|
|
55
|
+
emotionStyleTags = emotionStyles.styles.map(function (style) { return ((0, jsx_runtime_1.jsx)("style", { "data-emotion": "".concat(style.key, " ").concat(style.ids.join(" ")),
|
|
56
|
+
// eslint-disable-next-line react/no-danger
|
|
57
|
+
dangerouslySetInnerHTML: { __html: style.css } }, style.key)); });
|
|
58
|
+
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), { emotionStyleTags: emotionStyleTags })];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}); };
|
|
62
|
+
exports.default = Document;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.Document = void 0;
|
|
4
|
+
var Document_1 = require("./Document");
|
|
5
|
+
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return Document_1.Document; } });
|
|
6
|
+
var Document_2 = require("./Document");
|
|
7
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return Document_2.Document; } });
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
/* ? eslint-disable @next/next/no-document-import-in-page */
|
|
8
|
+
var document_1 = tslib_1.__importStar(require("next/document"));
|
|
9
|
+
var react_2 = require("@koine/react");
|
|
10
|
+
var styled_components_1 = require("styled-components");
|
|
11
|
+
/**
|
|
12
|
+
* Next Document wrapper for `styled-components` based projects
|
|
13
|
+
*
|
|
14
|
+
* For typescript safety of this component
|
|
15
|
+
* @see https://bit.ly/3ceuF8m
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* in your `myapp/pages/_document.tsx`:
|
|
20
|
+
* ```tsx
|
|
21
|
+
* export { Document as default } from "@koine/next/document/sc";
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var Document = /** @class */ (function (_super) {
|
|
25
|
+
tslib_1.__extends(Document, _super);
|
|
26
|
+
function Document() {
|
|
27
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
28
|
+
}
|
|
29
|
+
Document.getInitialProps = function (ctx) {
|
|
30
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
31
|
+
var sheet, originalRenderPage, initialProps;
|
|
32
|
+
return tslib_1.__generator(this, function (_a) {
|
|
33
|
+
switch (_a.label) {
|
|
34
|
+
case 0:
|
|
35
|
+
sheet = new styled_components_1.ServerStyleSheet();
|
|
36
|
+
originalRenderPage = ctx.renderPage;
|
|
37
|
+
_a.label = 1;
|
|
38
|
+
case 1:
|
|
39
|
+
_a.trys.push([1, , 3, 4]);
|
|
40
|
+
ctx.renderPage = function () {
|
|
41
|
+
return originalRenderPage({
|
|
42
|
+
enhanceApp: function (App) { return function (props) {
|
|
43
|
+
return sheet.collectStyles((0, jsx_runtime_1.jsx)(App, tslib_1.__assign({}, props)));
|
|
44
|
+
}; },
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return [4 /*yield*/, document_1.default.getInitialProps(ctx)];
|
|
48
|
+
case 2:
|
|
49
|
+
initialProps = _a.sent();
|
|
50
|
+
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), {
|
|
51
|
+
// @ts-expect-error FIXME: have they changed type?
|
|
52
|
+
styles: ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })) })];
|
|
53
|
+
case 3:
|
|
54
|
+
sheet.seal();
|
|
55
|
+
return [7 /*endfinally*/];
|
|
56
|
+
case 4: return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
Document.prototype.render = function () {
|
|
62
|
+
var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
63
|
+
return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_2.Meta, {}), (0, jsx_runtime_1.jsx)(react_2.NoJs, {})] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
|
|
64
|
+
};
|
|
65
|
+
return Document;
|
|
66
|
+
}(document_1.default));
|
|
67
|
+
exports.Document = Document;
|
|
68
|
+
exports.default = Document;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.T = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var Trans_1 = tslib_1.__importDefault(require("next-translate/Trans"));
|
|
7
|
+
function T(props) {
|
|
8
|
+
return (0, jsx_runtime_1.jsx)(Trans_1.default, tslib_1.__assign({}, props));
|
|
9
|
+
}
|
|
10
|
+
exports.T = T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getT = void 0;
|
|
5
|
+
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
|
+
var getT_1 = tslib_1.__importDefault(require("next-translate/getT"));
|
|
13
|
+
exports.getT = getT_1.default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./getT"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./T"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./translationAsOptions"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./useDateFormat"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useLocale"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./useT"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translationAsOptions = void 0;
|
|
4
|
+
function translationAsOptions(t, i18nKey) {
|
|
5
|
+
var dictionary = t(i18nKey, undefined, {
|
|
6
|
+
returnObjects: true,
|
|
7
|
+
});
|
|
8
|
+
return Object.keys(dictionary).map(function (key) { return ({
|
|
9
|
+
value: key,
|
|
10
|
+
label: dictionary[key],
|
|
11
|
+
}); });
|
|
12
|
+
}
|
|
13
|
+
exports.translationAsOptions = translationAsOptions;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDateFormat = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var router_1 = require("next/router");
|
|
7
|
+
var format_1 = tslib_1.__importDefault(require("date-fns/format"));
|
|
8
|
+
var react_2 = require("@koine/react");
|
|
9
|
+
/**
|
|
10
|
+
* Automatically returns the `date-fns/format` function with the right locale
|
|
11
|
+
* passed as option (grabbed from next router value).
|
|
12
|
+
*/
|
|
13
|
+
var useDateFormat = function () {
|
|
14
|
+
var _a = (0, react_1.useState)(function () {
|
|
15
|
+
return function () {
|
|
16
|
+
var args = [];
|
|
17
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
+
args[_i] = arguments[_i];
|
|
19
|
+
}
|
|
20
|
+
return format_1.default.apply(void 0, args);
|
|
21
|
+
};
|
|
22
|
+
}), formatter = _a[0], setFormatter = _a[1];
|
|
23
|
+
var router = (0, router_1.useRouter)();
|
|
24
|
+
var locale = (0, react_2.useDateLocale)(router.locale);
|
|
25
|
+
(0, react_1.useEffect)(function () {
|
|
26
|
+
if (locale) {
|
|
27
|
+
var newFormatter_1 = function (date, _format, options) { return (0, format_1.default)(date, _format, tslib_1.__assign(tslib_1.__assign({}, (options || {})), { locale: locale })); };
|
|
28
|
+
setFormatter(function () {
|
|
29
|
+
return function () {
|
|
30
|
+
var args = [];
|
|
31
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
32
|
+
args[_i] = arguments[_i];
|
|
33
|
+
}
|
|
34
|
+
return newFormatter_1.apply(void 0, args);
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, [locale]);
|
|
39
|
+
return formatter;
|
|
40
|
+
};
|
|
41
|
+
exports.useDateFormat = useDateFormat;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocale = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var useTranslation_1 = tslib_1.__importDefault(require("next-translate/useTranslation"));
|
|
6
|
+
function useLocale() {
|
|
7
|
+
return (0, useTranslation_1.default)().lang;
|
|
8
|
+
}
|
|
9
|
+
exports.useLocale = useLocale;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useT = void 0;
|
|
5
|
+
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
|
+
var react_1 = require("react");
|
|
13
|
+
var useTranslation_1 = tslib_1.__importDefault(require("next-translate/useTranslation"));
|
|
14
|
+
function useT(namespace) {
|
|
15
|
+
var t = (0, useTranslation_1.default)().t;
|
|
16
|
+
var tMemoized = (0, react_1.useMemo)(function () {
|
|
17
|
+
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
|
|
21
|
+
// ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
}, [t, namespace]);
|
|
25
|
+
return tMemoized;
|
|
26
|
+
}
|
|
27
|
+
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
|
+
*/
|
|
108
|
+
// import { useContext, useMemo } from "react"
|
|
109
|
+
// import wrapTWithDefaultNs from "next-translate/lib/cjs/wrapTWithDefaultNs";
|
|
110
|
+
// import I18nContext from "next-translate/lib/cjs/_context";
|
|
111
|
+
// export default function useTranslation(defaultNS?: string): I18n {
|
|
112
|
+
// const ctx = useContext(I18nContext)
|
|
113
|
+
// return useMemo(
|
|
114
|
+
// () => ({
|
|
115
|
+
// ...ctx,
|
|
116
|
+
// t: wrapTWithDefaultNs(ctx.t, defaultNS),
|
|
117
|
+
// }),
|
|
118
|
+
// [ctx.lang, defaultNS]
|
|
119
|
+
// )
|
|
120
|
+
// }
|
package/node/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./Analytics"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./Auth"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./Favicon"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./Forms"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./Head"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./i18n"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./Img"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./Link"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./NextProgress"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./Seo"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./Theme"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmotionCache = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var cache_1 = tslib_1.__importDefault(require("@emotion/cache"));
|
|
6
|
+
/**
|
|
7
|
+
* prepend: true moves MUI styles to the top of the <head> so they're loaded first.
|
|
8
|
+
* It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
|
|
9
|
+
*/
|
|
10
|
+
function createEmotionCache() {
|
|
11
|
+
return (0, cache_1.default)({ key: "css", prepend: true });
|
|
12
|
+
}
|
|
13
|
+
exports.createEmotionCache = createEmotionCache;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.load = exports.getSiteUrl = exports.ONE_DAY = exports.ONE_HOUR = void 0;
|
|
4
|
+
var utils_1 = require("@koine/utils");
|
|
5
|
+
exports.ONE_HOUR = 3600;
|
|
6
|
+
exports.ONE_DAY = 84000;
|
|
7
|
+
/**
|
|
8
|
+
* Get site absolute url with the given path
|
|
9
|
+
*
|
|
10
|
+
* - It uses the `NEXT_PUBLIC_APP_URL` env variable
|
|
11
|
+
* - It removes the trailing slashes
|
|
12
|
+
*/
|
|
13
|
+
function getSiteUrl(path) {
|
|
14
|
+
if (path === void 0) { path = ""; }
|
|
15
|
+
return (0, utils_1.normaliseUrl)("".concat(process.env["NEXT_PUBLIC_APP_URL"], "/").concat(path));
|
|
16
|
+
}
|
|
17
|
+
exports.getSiteUrl = getSiteUrl;
|
|
18
|
+
/**
|
|
19
|
+
* Utility to load a component with an optional pre-determined delay.
|
|
20
|
+
*
|
|
21
|
+
* This was designed to improve anti spam wit async form loading.
|
|
22
|
+
*
|
|
23
|
+
* @see https://github.com/vercel/next.js/blob/main/packages/next/next-server/lib/dynamic.tsx
|
|
24
|
+
* @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
|
|
25
|
+
*/
|
|
26
|
+
function load(component, milliseconds) {
|
|
27
|
+
return new Promise(function (resolve) {
|
|
28
|
+
setTimeout(function () { return resolve(component); }, milliseconds);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.load = load;
|
package/package.json
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"react": "^16.8 || ^17 || ^18",
|
|
8
8
|
"next": "^12.1.6",
|
|
9
|
-
"@koine/utils": "1.0.
|
|
9
|
+
"@koine/utils": "1.0.17",
|
|
10
10
|
"framer-motion": "^6.3.4",
|
|
11
|
-
"@koine/react": "1.0.
|
|
11
|
+
"@koine/react": "1.0.17",
|
|
12
12
|
"styled-components": "^5.3.5",
|
|
13
13
|
"@mui/base": "^5.0.0-alpha.82",
|
|
14
14
|
"react-icons": "^4.3.1",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"next-seo": "^5.4.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {},
|
|
32
|
+
"version": "1.0.17",
|
|
32
33
|
"module": "./index.js",
|
|
33
|
-
"types": "./index.d.ts"
|
|
34
|
-
"version": "1.0.14"
|
|
34
|
+
"types": "./index.d.ts"
|
|
35
35
|
}
|
package/typings.d.ts
CHANGED
|
@@ -59,28 +59,37 @@ declare namespace Koine {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Translations dictionary extracted from JSON files.
|
|
63
|
-
* type with something like:
|
|
62
|
+
* Translations dictionary extracted from JSON files.
|
|
63
|
+
* You need to augment this type with something like:
|
|
64
64
|
*
|
|
65
65
|
* ```ts
|
|
66
66
|
* declare namespace Koine {
|
|
67
67
|
* interface NextTranslations {
|
|
68
68
|
* "~": typeof import("./locales/en/~.json");
|
|
69
|
-
* _: typeof import("./locales/en/_.json");
|
|
70
|
-
* $team: typeof import("./locales/en/$team.json");
|
|
71
|
-
* home: typeof import("./locales/en/home.json");
|
|
72
|
-
*
|
|
73
|
-
* Header: typeof import("./locales/en/Header.json");
|
|
69
|
+
* "_": typeof import("./locales/en/_.json");
|
|
70
|
+
* "$team": typeof import("./locales/en/$team.json");
|
|
71
|
+
* "home": typeof import("./locales/en/home.json");
|
|
72
|
+
* "Header": typeof import("./locales/en/Header.json");
|
|
74
73
|
* }
|
|
75
74
|
* }
|
|
76
75
|
* ```
|
|
76
|
+
*
|
|
77
|
+
* Best to follow a convention to name the files which become the namespaces:
|
|
78
|
+
*
|
|
79
|
+
* - `~`: for app wide **urls** translated definitions
|
|
80
|
+
* - `_`: for app wide **common** translations
|
|
81
|
+
* - `${data}`: dollar prefix for static **data** like arrays, objects, .etc
|
|
82
|
+
* - `{route-name}`: lower cased for **route** specific data
|
|
83
|
+
* - `{ComponentName}`: pascal cased for **components** specific data
|
|
77
84
|
*/
|
|
78
85
|
interface NextTranslations {
|
|
79
|
-
/** Convention for app wide `common` translations */
|
|
80
|
-
_: Record<string, string>;
|
|
81
|
-
/** Convention for app wide `routes` translated definitions */
|
|
82
86
|
"~": Record<string, string>;
|
|
87
|
+
_: Record<string, string>;
|
|
83
88
|
}
|
|
89
|
+
// interface NextTranslations {
|
|
90
|
+
// "~": Record<string, string>;
|
|
91
|
+
// _: Record<string, string>;
|
|
92
|
+
// }
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
/**
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
package/I18n/I18n.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/// <reference types="@koine/next/typings" />
|
|
2
|
-
import format from "date-fns/format";
|
|
3
|
-
import type { Option } from "@koine/react";
|
|
4
|
-
export { default as T } from "next-translate/Trans";
|
|
5
|
-
declare type Join<S1, S2> = S1 extends string ? S2 extends string ? `${S1}.${S2}` : never : never;
|
|
6
|
-
declare type Paths<T> = {
|
|
7
|
-
[K in keyof T]: T[K] extends Record<string, unknown> ? Join<K, Paths<T[K]>> : K;
|
|
8
|
-
}[keyof T];
|
|
9
|
-
export declare type AllPaths = {
|
|
10
|
-
[N in keyof Koine.NextTranslations]: {
|
|
11
|
-
[K in keyof Koine.NextTranslations[N]]: Koine.NextTranslations[N][K] extends Array<Record<string, unknown>> ? Join<K extends string ? `${N}:${K}` : `${N}:`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends Record<string, unknown> ? Join<K extends string ? `${N}:${K}` : `${N}:`, Paths<Koine.NextTranslations[N][K]>> & Record<Koine.NextTranslations[N][K], object> : Koine.NextTranslations[N][K] extends Array<string | number | boolean> ? Join<K extends string ? `${N}:${K}` : `${N}`, Paths<Koine.NextTranslations[N][K]>> : Koine.NextTranslations[N][K] extends string | number | boolean ? K extends string ? `${N}:${K}` : `${N}:` : ``;
|
|
12
|
-
}[keyof Koine.NextTranslations[N]];
|
|
13
|
-
}[keyof Koine.NextTranslations];
|
|
14
|
-
/**
|
|
15
|
-
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
16
|
-
*/
|
|
17
|
-
declare type TranslationQuery = undefined | null | "obj" | {
|
|
18
|
-
[key: string]: string | number | boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Passing just `obj` is a shortcut for `{ returnObjects: true }`
|
|
22
|
-
*/
|
|
23
|
-
declare type TranslationOptions = undefined | "obj" | {
|
|
24
|
-
returnObjects?: boolean;
|
|
25
|
-
fallback?: string | string[];
|
|
26
|
-
default?: string;
|
|
27
|
-
};
|
|
28
|
-
export declare type TranslateNamespace = keyof Koine.NextTranslations;
|
|
29
|
-
export declare type TranslateKey = AllPaths;
|
|
30
|
-
export declare type Translate<N extends undefined | keyof Koine.NextTranslations = undefined> = <R extends unknown = string>(s: N extends TranslateNamespace ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: TranslationQuery, o?: TranslationOptions) => R;
|
|
31
|
-
export declare type TranslateLoose = (s: any, q?: any, o?: any) => string;
|
|
32
|
-
/**
|
|
33
|
-
* FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
|
|
34
|
-
* problem of untranslated text during page transitions
|
|
35
|
-
*
|
|
36
|
-
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
37
|
-
*/
|
|
38
|
-
export declare function useT<N extends TranslateNamespace | undefined>(namespace?: N): <R extends unknown = string>(s: N extends TranslateNamespace ? Paths<Koine.NextTranslations[N]> | AllPaths : AllPaths, q?: TranslationQuery, o?: TranslationOptions) => R;
|
|
39
|
-
export declare function translationAsOptions(t: TranslateLoose, i18nKey: string): Option[];
|
|
40
|
-
/**
|
|
41
|
-
* Automatically returns the `date-fns/format` function with the right locale
|
|
42
|
-
* passed as option (grabbed from next router value).
|
|
43
|
-
*/
|
|
44
|
-
export declare const useDateFormat: () => typeof format;
|
package/I18n/I18n.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/// <reference types="@koine/next/typings" />
|
|
2
|
-
import { __assign } from "tslib";
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
4
|
-
/**
|
|
5
|
-
* @file
|
|
6
|
-
*
|
|
7
|
-
* About the typescript support for translation strings @see:
|
|
8
|
-
* - https://github.com/vinissimus/next-translate/issues/721
|
|
9
|
-
*/
|
|
10
|
-
import { useEffect, useState, useMemo } from "react";
|
|
11
|
-
import { useRouter } from "next/router";
|
|
12
|
-
import format from "date-fns/format";
|
|
13
|
-
import useTranslation from "next-translate/useTranslation";
|
|
14
|
-
import { useDateLocale } from "@koine/react";
|
|
15
|
-
export { default as T } from "next-translate/Trans";
|
|
16
|
-
/**
|
|
17
|
-
* FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
|
|
18
|
-
* problem of untranslated text during page transitions
|
|
19
|
-
*
|
|
20
|
-
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
21
|
-
*/
|
|
22
|
-
export function useT(namespace) {
|
|
23
|
-
var t = useTranslation().t;
|
|
24
|
-
// const typedT = <
|
|
25
|
-
// // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
26
|
-
// R extends unknown = string,
|
|
27
|
-
// // Q extends TranslationQuery = TranslationQuery
|
|
28
|
-
// // O extends TranslationOptions = TranslationOptions
|
|
29
|
-
// >(
|
|
30
|
-
// s: N extends TranslateNamespace
|
|
31
|
-
// ? Paths<Koine.NextTranslations[N]> | AllPaths
|
|
32
|
-
// : AllPaths,
|
|
33
|
-
// q?: TranslationQuery,
|
|
34
|
-
// o?: TranslationOptions
|
|
35
|
-
// ) =>
|
|
36
|
-
// // eslint-disable-next-line
|
|
37
|
-
// t.call(
|
|
38
|
-
// null,
|
|
39
|
-
// namespace ? `${namespace}:${s}` : s,
|
|
40
|
-
// q === "obj" ? null : q,
|
|
41
|
-
// q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
42
|
-
// // ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
|
|
43
|
-
// ) as R;
|
|
44
|
-
// return typedT;
|
|
45
|
-
var tMemoized = useMemo(function () {
|
|
46
|
-
return function (s, q, o) {
|
|
47
|
-
return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" ? null : q, q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
48
|
-
// ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
}, [t, namespace]);
|
|
52
|
-
// return tMemoized as Translate<N>;
|
|
53
|
-
return tMemoized;
|
|
54
|
-
}
|
|
55
|
-
export function translationAsOptions(t, i18nKey) {
|
|
56
|
-
var dictionary = t(i18nKey, undefined, {
|
|
57
|
-
returnObjects: true,
|
|
58
|
-
});
|
|
59
|
-
return Object.keys(dictionary).map(function (key) { return ({
|
|
60
|
-
value: key,
|
|
61
|
-
label: dictionary[key],
|
|
62
|
-
}); });
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Automatically returns the `date-fns/format` function with the right locale
|
|
66
|
-
* passed as option (grabbed from next router value).
|
|
67
|
-
*/
|
|
68
|
-
export var useDateFormat = function () {
|
|
69
|
-
var _a = useState(function () {
|
|
70
|
-
return function () {
|
|
71
|
-
var args = [];
|
|
72
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
73
|
-
args[_i] = arguments[_i];
|
|
74
|
-
}
|
|
75
|
-
return format.apply(void 0, args);
|
|
76
|
-
};
|
|
77
|
-
}), formatter = _a[0], setFormatter = _a[1];
|
|
78
|
-
var router = useRouter();
|
|
79
|
-
var locale = useDateLocale(router.locale);
|
|
80
|
-
useEffect(function () {
|
|
81
|
-
if (locale) {
|
|
82
|
-
var newFormatter_1 = function (date, _format, options) { return format(date, _format, __assign(__assign({}, (options || {})), { locale: locale })); };
|
|
83
|
-
setFormatter(function () {
|
|
84
|
-
return function () {
|
|
85
|
-
var args = [];
|
|
86
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
87
|
-
args[_i] = arguments[_i];
|
|
88
|
-
}
|
|
89
|
-
return newFormatter_1.apply(void 0, args);
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}, [locale]);
|
|
94
|
-
return formatter;
|
|
95
|
-
};
|
package/I18n/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./I18n";
|
package/I18n/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./I18n";
|