@koine/next 1.0.5 → 1.0.8
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 +5 -6
- package/Analytics/AnalyticsGoogle.js +37 -0
- package/Analytics/index.d.ts +1 -1
- package/Analytics/index.js +1 -0
- package/Auth/helpers.d.ts +17 -17
- package/Auth/helpers.js +21 -0
- package/Auth/index.d.ts +4 -4
- package/Auth/index.js +4 -0
- package/Auth/useLogin.d.ts +7 -7
- package/Auth/useLogin.js +47 -0
- package/Auth/useLoginUrl.d.ts +1 -1
- package/Auth/useLoginUrl.js +11 -0
- package/Auth/useLogout.d.ts +6 -6
- package/Auth/useLogout.js +52 -0
- package/Favicon/Favicon.d.ts +3 -4
- package/Favicon/Favicon.js +4 -0
- package/Favicon/index.d.ts +1 -1
- package/Favicon/index.js +1 -0
- package/Forms/index.d.ts +2 -2
- package/Forms/index.js +2 -0
- package/Forms/useForm.d.ts +32 -32
- package/Forms/useForm.js +33 -0
- package/Forms/useSubmit.d.ts +24 -24
- package/Forms/useSubmit.js +20 -0
- package/Head/Head.d.ts +1 -1
- package/Head/Head.js +1 -0
- package/Head/index.d.ts +1 -1
- package/Head/index.js +1 -0
- package/I18n/I18n.d.ts +48 -48
- package/I18n/I18n.js +86 -0
- package/I18n/index.d.ts +1 -1
- package/I18n/index.js +1 -0
- package/Img/Img.d.ts +21 -21
- package/Img/Img.js +30 -0
- package/Img/index.d.ts +1 -1
- package/Img/index.js +1 -0
- package/Link/Link.d.ts +8 -8
- package/Link/Link.js +12 -0
- package/Link/index.d.ts +1 -1
- package/Link/index.js +1 -0
- package/NextProgress/NextProgress.d.ts +13 -14
- package/NextProgress/NextProgress.js +38 -0
- package/NextProgress/index.d.ts +1 -1
- package/NextProgress/index.js +1 -0
- package/Seo/Seo.d.ts +3 -3
- package/Seo/Seo.js +8 -0
- package/Seo/SeoDefaults.d.ts +3 -3
- package/Seo/SeoDefaults.js +12 -0
- package/Seo/helpers.d.ts +48 -48
- package/Seo/helpers.js +113 -0
- package/Seo/index.d.ts +12 -12
- package/Seo/index.js +12 -0
- package/Theme/Theme.d.ts +46 -46
- package/Theme/Theme.js +235 -0
- package/Theme/index.d.ts +1 -1
- package/Theme/index.js +1 -0
- package/app/App--emotion.d.ts +10 -10
- package/app/App--emotion.js +11 -0
- package/app/App--sc.d.ts +10 -10
- package/app/App--sc.js +11 -0
- package/app/App--vanilla.d.ts +10 -10
- package/app/App--vanilla.js +11 -0
- package/app/AppAuth--emotion.d.ts +10 -10
- package/app/AppAuth--emotion.js +12 -0
- package/app/AppAuth--sc.d.ts +10 -10
- package/app/AppAuth--sc.js +12 -0
- package/app/AppHead.d.ts +3 -3
- package/app/AppHead.js +5 -0
- package/app/{AppMain.d.ts → AppMain--emotion.d.ts} +34 -34
- package/app/AppMain--emotion.js +27 -0
- package/app/AppMain--sc.d.ts +34 -0
- package/app/AppMain--sc.js +27 -0
- package/app/AppMain--vanilla.d.ts +27 -27
- package/app/AppMain--vanilla.js +11 -0
- package/app/AppTheme--emotion.d.ts +15 -15
- package/app/AppTheme--emotion.js +17 -0
- package/app/AppTheme--sc.d.ts +13 -13
- package/app/AppTheme--sc.js +9 -0
- package/app/AppTheme--vanilla.d.ts +10 -10
- package/app/AppTheme--vanilla.js +12 -0
- package/app/index.d.ts +11 -11
- package/app/index.js +11 -0
- package/app/motion-features.d.ts +2 -2
- package/app/motion-features.js +2 -0
- package/config/index.d.ts +58 -58
- package/config/index.js +144 -0
- package/document/Document--emotion.d.ts +5 -5
- package/document/Document--emotion.js +55 -0
- package/document/Document--sc.d.ts +11 -11
- package/document/Document--sc.js +33 -0
- package/document/Document--vanilla.d.ts +11 -11
- package/document/Document--vanilla.js +20 -0
- package/document/Document.d.ts +10 -10
- package/document/Document.js +14 -0
- package/document/index.d.ts +4 -4
- package/document/index.js +4 -0
- package/index.d.ts +15 -12
- package/index.js +15 -743
- package/index.umd.js +2061 -78
- package/package.json +26 -20
- package/{types.d.ts → typings.d.ts} +0 -0
- package/utils/api.d.ts +55 -55
- package/utils/api.js +33 -0
- package/{document/emotion.d.ts → utils/emotion-cache.d.ts} +5 -5
- package/utils/emotion-cache.js +8 -0
- package/utils/index.d.ts +20 -19
- package/utils/index.js +27 -0
- package/Theme.cjs.js +0 -1905
- package/_tslib.cjs.js +0 -41
- package/app.js +0 -256
- package/config.js +0 -183
- package/document.js +0 -207
- package/emotion.cjs.js +0 -1329
- package/es.object.assign.cjs.js +0 -1074
- package/es.string.replace.cjs.js +0 -785
- package/es.string.split.cjs.js +0 -201
- package/index.esm.js +0 -4600
- package/motion-features.cjs.js +0 -10
package/index.js
CHANGED
|
@@ -1,743 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var useTranslation = require('next-translate/useTranslation');
|
|
17
|
-
var react = require('@koine/react');
|
|
18
|
-
var Trans = require('next-translate/Trans');
|
|
19
|
-
var Head = require('next/head');
|
|
20
|
-
var reactHookForm = require('react-hook-form');
|
|
21
|
-
var yup = require('@hookform/resolvers/yup');
|
|
22
|
-
var _tslib = require('./_tslib.cjs.js');
|
|
23
|
-
var reactUse = require('react-use');
|
|
24
|
-
var NextImage = require('next/image');
|
|
25
|
-
var NextLink = require('next/link');
|
|
26
|
-
|
|
27
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
28
|
-
|
|
29
|
-
var Script__default = /*#__PURE__*/_interopDefaultLegacy(Script);
|
|
30
|
-
var format__default = /*#__PURE__*/_interopDefaultLegacy(format);
|
|
31
|
-
var useTranslation__default = /*#__PURE__*/_interopDefaultLegacy(useTranslation);
|
|
32
|
-
var Trans__default = /*#__PURE__*/_interopDefaultLegacy(Trans);
|
|
33
|
-
var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
|
|
34
|
-
var NextImage__default = /*#__PURE__*/_interopDefaultLegacy(NextImage);
|
|
35
|
-
var NextLink__default = /*#__PURE__*/_interopDefaultLegacy(NextLink);
|
|
36
|
-
|
|
37
|
-
const AnalyticsGoogle = ({
|
|
38
|
-
id
|
|
39
|
-
}) => {
|
|
40
|
-
const uid = id || process.env["NEXT_PUBLIC_GTM_ID"];
|
|
41
|
-
const {
|
|
42
|
-
events,
|
|
43
|
-
asPath,
|
|
44
|
-
query
|
|
45
|
-
} = router.useRouter();
|
|
46
|
-
const [ready, setReady] = React.useState(false);
|
|
47
|
-
const [routed, setRouted] = React.useState(false); // const [url, setUrl] = useState("");
|
|
48
|
-
|
|
49
|
-
React.useEffect(() => {
|
|
50
|
-
const handleRouteChange = () => {
|
|
51
|
-
setRouted(true);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
events.on("routeChangeComplete", handleRouteChange);
|
|
55
|
-
return () => {
|
|
56
|
-
events.off("routeChangeComplete", handleRouteChange);
|
|
57
|
-
};
|
|
58
|
-
}, [events]);
|
|
59
|
-
React.useEffect(() => {
|
|
60
|
-
if (routed && ready && asPath) {
|
|
61
|
-
// const search = query;
|
|
62
|
-
utils.pageview(asPath);
|
|
63
|
-
}
|
|
64
|
-
}, [asPath, query, routed, ready]);
|
|
65
|
-
|
|
66
|
-
if (!uid) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
71
|
-
children: [jsxRuntime.jsx(Script__default["default"], {
|
|
72
|
-
id: "google-tagmanager",
|
|
73
|
-
src: `https://www.googletagmanager.com/gtag/js?id=${id}`,
|
|
74
|
-
strategy: "afterInteractive",
|
|
75
|
-
onLoad: () => setReady(true)
|
|
76
|
-
}), jsxRuntime.jsx(Script__default["default"], Object.assign({
|
|
77
|
-
id: "google-analytics",
|
|
78
|
-
strategy: "afterInteractive"
|
|
79
|
-
}, {
|
|
80
|
-
children: `
|
|
81
|
-
window.dataLayer = window.dataLayer || [];
|
|
82
|
-
function gtag(){window.dataLayer.push(arguments);}
|
|
83
|
-
gtag('js', new Date());
|
|
84
|
-
|
|
85
|
-
gtag('config', '${id}', { 'send_page_view': false });
|
|
86
|
-
`
|
|
87
|
-
}))]
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var global = es_object_assign.global;
|
|
92
|
-
var aCallable = es_object_assign.aCallable;
|
|
93
|
-
var toObject = es_object_assign.toObject;
|
|
94
|
-
var IndexedObject = es_object_assign.indexedObject;
|
|
95
|
-
var lengthOfArrayLike = es_object_assign.lengthOfArrayLike;
|
|
96
|
-
|
|
97
|
-
var TypeError = global.TypeError;
|
|
98
|
-
|
|
99
|
-
// `Array.prototype.{ reduce, reduceRight }` methods implementation
|
|
100
|
-
var createMethod = function (IS_RIGHT) {
|
|
101
|
-
return function (that, callbackfn, argumentsLength, memo) {
|
|
102
|
-
aCallable(callbackfn);
|
|
103
|
-
var O = toObject(that);
|
|
104
|
-
var self = IndexedObject(O);
|
|
105
|
-
var length = lengthOfArrayLike(O);
|
|
106
|
-
var index = IS_RIGHT ? length - 1 : 0;
|
|
107
|
-
var i = IS_RIGHT ? -1 : 1;
|
|
108
|
-
if (argumentsLength < 2) while (true) {
|
|
109
|
-
if (index in self) {
|
|
110
|
-
memo = self[index];
|
|
111
|
-
index += i;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
index += i;
|
|
115
|
-
if (IS_RIGHT ? index < 0 : length <= index) {
|
|
116
|
-
throw TypeError('Reduce of empty array with no initial value');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (;IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {
|
|
120
|
-
memo = callbackfn(memo, self[index], index, O);
|
|
121
|
-
}
|
|
122
|
-
return memo;
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
var arrayReduce = {
|
|
127
|
-
// `Array.prototype.reduce` method
|
|
128
|
-
// https://tc39.es/ecma262/#sec-array.prototype.reduce
|
|
129
|
-
left: createMethod(false),
|
|
130
|
-
// `Array.prototype.reduceRight` method
|
|
131
|
-
// https://tc39.es/ecma262/#sec-array.prototype.reduceright
|
|
132
|
-
right: createMethod(true)
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
var fails = es_object_assign.fails;
|
|
136
|
-
|
|
137
|
-
var arrayMethodIsStrict$1 = function (METHOD_NAME, argument) {
|
|
138
|
-
var method = [][METHOD_NAME];
|
|
139
|
-
return !!method && fails(function () {
|
|
140
|
-
// eslint-disable-next-line no-useless-call -- required for testing
|
|
141
|
-
method.call(null, argument || function () { return 1; }, 1);
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
var $ = es_object_assign._export;
|
|
146
|
-
var $reduce = arrayReduce.left;
|
|
147
|
-
var arrayMethodIsStrict = arrayMethodIsStrict$1;
|
|
148
|
-
var CHROME_VERSION = es_object_assign.engineV8Version;
|
|
149
|
-
var IS_NODE = Theme.engineIsNode;
|
|
150
|
-
|
|
151
|
-
var STRICT_METHOD = arrayMethodIsStrict('reduce');
|
|
152
|
-
// Chrome 80-82 has a critical bug
|
|
153
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=1049982
|
|
154
|
-
var CHROME_BUG = !IS_NODE && CHROME_VERSION > 79 && CHROME_VERSION < 83;
|
|
155
|
-
|
|
156
|
-
// `Array.prototype.reduce` method
|
|
157
|
-
// https://tc39.es/ecma262/#sec-array.prototype.reduce
|
|
158
|
-
$({ target: 'Array', proto: true, forced: !STRICT_METHOD || CHROME_BUG }, {
|
|
159
|
-
reduce: function reduce(callbackfn /* , initialValue */) {
|
|
160
|
-
var length = arguments.length;
|
|
161
|
-
return $reduce(this, callbackfn, length, length > 1 ? arguments[1] : undefined);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const AUTH_ROUTES = {
|
|
166
|
-
login: process.env["AUTH_ROUTE_LOGIN"],
|
|
167
|
-
profile: process.env["AUTH_ROUTE_PROFILE"],
|
|
168
|
-
register: process.env["AUTH_ROUTE_REGISTER"],
|
|
169
|
-
secured: JSON.parse(process.env["AUTH_ROUTES_SECURED"] || "[]")
|
|
170
|
-
};
|
|
171
|
-
function getAuthRoutes(t) {
|
|
172
|
-
return Object.keys(AUTH_ROUTES).reduce((map, name) => {
|
|
173
|
-
const routePage = AUTH_ROUTES[name]; // @ts-expect-error cannot remember
|
|
174
|
-
|
|
175
|
-
map[name] = utils.isString(routePage) ? t(`~:${AUTH_ROUTES[name]}`) : routePage;
|
|
176
|
-
return map;
|
|
177
|
-
}, {});
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* @param url e.g. "http://localhost:3000/signin?callbackUrl=http://localhost:3000/profile"
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
function getCallbackUrl(url = window.location.href) {
|
|
184
|
-
return url.split("callbackUrl=")[1] || "";
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// `SameValue` abstract operation
|
|
188
|
-
// https://tc39.es/ecma262/#sec-samevalue
|
|
189
|
-
// eslint-disable-next-line es/no-object-is -- safe
|
|
190
|
-
var sameValue$1 = Object.is || function is(x, y) {
|
|
191
|
-
// eslint-disable-next-line no-self-compare -- NaN check
|
|
192
|
-
return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
var call$1 = es_object_assign.functionCall;
|
|
196
|
-
var fixRegExpWellKnownSymbolLogic$1 = es_string_replace.fixRegexpWellKnownSymbolLogic;
|
|
197
|
-
var anObject$1 = es_object_assign.anObject;
|
|
198
|
-
var requireObjectCoercible$1 = es_object_assign.requireObjectCoercible;
|
|
199
|
-
var sameValue = sameValue$1;
|
|
200
|
-
var toString$1 = es_string_replace.toString;
|
|
201
|
-
var getMethod$1 = es_object_assign.getMethod;
|
|
202
|
-
var regExpExec$1 = es_string_replace.regexpExecAbstract;
|
|
203
|
-
|
|
204
|
-
// @@search logic
|
|
205
|
-
fixRegExpWellKnownSymbolLogic$1('search', function (SEARCH, nativeSearch, maybeCallNative) {
|
|
206
|
-
return [
|
|
207
|
-
// `String.prototype.search` method
|
|
208
|
-
// https://tc39.es/ecma262/#sec-string.prototype.search
|
|
209
|
-
function search(regexp) {
|
|
210
|
-
var O = requireObjectCoercible$1(this);
|
|
211
|
-
var searcher = regexp == undefined ? undefined : getMethod$1(regexp, SEARCH);
|
|
212
|
-
return searcher ? call$1(searcher, regexp, O) : new RegExp(regexp)[SEARCH](toString$1(O));
|
|
213
|
-
},
|
|
214
|
-
// `RegExp.prototype[@@search]` method
|
|
215
|
-
// https://tc39.es/ecma262/#sec-regexp.prototype-@@search
|
|
216
|
-
function (string) {
|
|
217
|
-
var rx = anObject$1(this);
|
|
218
|
-
var S = toString$1(string);
|
|
219
|
-
var res = maybeCallNative(nativeSearch, rx, S);
|
|
220
|
-
|
|
221
|
-
if (res.done) return res.value;
|
|
222
|
-
|
|
223
|
-
var previousLastIndex = rx.lastIndex;
|
|
224
|
-
if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
|
|
225
|
-
var result = regExpExec$1(rx, S);
|
|
226
|
-
if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
|
|
227
|
-
return result === null ? -1 : result.index;
|
|
228
|
-
}
|
|
229
|
-
];
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* FIXME: the use of `useMemo` is a hopefully-temporary solution to fix the FOUC
|
|
234
|
-
* problem of untranslated text during page transitions
|
|
235
|
-
*
|
|
236
|
-
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
function useT(namespace) {
|
|
240
|
-
const t = useTranslation__default["default"]().t; // const typedT = <
|
|
241
|
-
// // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
242
|
-
// R extends unknown = string,
|
|
243
|
-
// // Q extends TranslationQuery = TranslationQuery
|
|
244
|
-
// // O extends TranslationOptions = TranslationOptions
|
|
245
|
-
// >(
|
|
246
|
-
// s: N extends TranslateNamespace
|
|
247
|
-
// ? Paths<Koine.NextTranslations[N]> | AllPaths
|
|
248
|
-
// : AllPaths,
|
|
249
|
-
// q?: TranslationQuery,
|
|
250
|
-
// o?: TranslationOptions
|
|
251
|
-
// ) =>
|
|
252
|
-
// // eslint-disable-next-line
|
|
253
|
-
// t.call(
|
|
254
|
-
// null,
|
|
255
|
-
// namespace ? `${namespace}:${s}` : s,
|
|
256
|
-
// q === "obj" ? null : q,
|
|
257
|
-
// q === "obj" || o === "obj" ? { returnObjects: true } : o
|
|
258
|
-
// // ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
|
|
259
|
-
// ) as R;
|
|
260
|
-
// return typedT;
|
|
261
|
-
|
|
262
|
-
const tMemoized = React.useMemo(() => (s, q, o) => t(namespace ? `${namespace}:${s}` : s, q === "obj" ? null : q, q === "obj" || o === "obj" ? {
|
|
263
|
-
returnObjects: true
|
|
264
|
-
} : o // ) as R extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : R;
|
|
265
|
-
), [t, namespace]); // return tMemoized as Translate<N>;
|
|
266
|
-
|
|
267
|
-
return tMemoized;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* @deprecated Not sure whether this will ever be useful
|
|
271
|
-
*/
|
|
272
|
-
|
|
273
|
-
function useLooseT(namespace) {
|
|
274
|
-
const {
|
|
275
|
-
t
|
|
276
|
-
} = useTranslation__default["default"](namespace); // return t;
|
|
277
|
-
|
|
278
|
-
const tMemoized = React.useMemo(() => t, [t]);
|
|
279
|
-
return tMemoized;
|
|
280
|
-
}
|
|
281
|
-
function translationAsOptions(t, i18nKey) {
|
|
282
|
-
const dictionary = t(i18nKey, undefined, {
|
|
283
|
-
returnObjects: true
|
|
284
|
-
});
|
|
285
|
-
return Object.keys(dictionary).map(key => ({
|
|
286
|
-
value: key,
|
|
287
|
-
label: dictionary[key]
|
|
288
|
-
}));
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Automatically returns the `date-fns/format` function with the right locale
|
|
292
|
-
* passed as option (grabbed from next router value).
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
const useDateFormat = () => {
|
|
296
|
-
const [formatter, setFormatter] = React.useState(() => (...args) => format__default["default"](...args));
|
|
297
|
-
const router$1 = router.useRouter();
|
|
298
|
-
const locale = react.useDateLocale(router$1.locale);
|
|
299
|
-
React.useEffect(() => {
|
|
300
|
-
if (locale) {
|
|
301
|
-
const newFormatter = (date, _format, options) => format__default["default"](date, _format, Object.assign(Object.assign({}, options || {}), {
|
|
302
|
-
locale
|
|
303
|
-
}));
|
|
304
|
-
|
|
305
|
-
setFormatter(() => (...args) => newFormatter(...args));
|
|
306
|
-
}
|
|
307
|
-
}, [locale]);
|
|
308
|
-
return formatter;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
function useLogin() {
|
|
312
|
-
const t = useT();
|
|
313
|
-
const {
|
|
314
|
-
push
|
|
315
|
-
} = router.useRouter();
|
|
316
|
-
const [loading, setLoading] = React.useState(false);
|
|
317
|
-
const [ok, setOk] = React.useState(false);
|
|
318
|
-
const [fail, setFail] = React.useState(false);
|
|
319
|
-
const submit = React.useCallback(data => {
|
|
320
|
-
setLoading(true);
|
|
321
|
-
react$1.signIn("credentials", Object.assign(Object.assign({}, data), {
|
|
322
|
-
redirect: false
|
|
323
|
-
})) // @ts-expect-error FIXME: at some point...
|
|
324
|
-
.then(({
|
|
325
|
-
ok
|
|
326
|
-
}) => {
|
|
327
|
-
setLoading(false);
|
|
328
|
-
setOk(ok);
|
|
329
|
-
setFail(!ok);
|
|
330
|
-
|
|
331
|
-
if (ok) {
|
|
332
|
-
const redirectUrl = utils.parseURL(getCallbackUrl());
|
|
333
|
-
const {
|
|
334
|
-
login,
|
|
335
|
-
register,
|
|
336
|
-
profile
|
|
337
|
-
} = getAuthRoutes(t);
|
|
338
|
-
|
|
339
|
-
if (redirectUrl) {
|
|
340
|
-
const redirectPath = redirectUrl.pathname;
|
|
341
|
-
|
|
342
|
-
if (profile && (redirectPath === login || redirectPath === register)) {
|
|
343
|
-
push(profile);
|
|
344
|
-
} else {
|
|
345
|
-
push(redirectPath + redirectUrl.search);
|
|
346
|
-
}
|
|
347
|
-
} else if (profile) {
|
|
348
|
-
push(profile);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}, [t, push]); // TODO: useMemo ?
|
|
353
|
-
|
|
354
|
-
return {
|
|
355
|
-
submit,
|
|
356
|
-
loading,
|
|
357
|
-
ok,
|
|
358
|
-
fail
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function useLoginUrl() {
|
|
363
|
-
const [currentUrl, setCurrentUrl] = React.useState("");
|
|
364
|
-
const t = useT();
|
|
365
|
-
React.useEffect(() => {
|
|
366
|
-
setCurrentUrl(`?callbackUrl=${window.location.href}`);
|
|
367
|
-
}, []);
|
|
368
|
-
return `${getAuthRoutes(t).login}${currentUrl}`;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
var call = es_object_assign.functionCall;
|
|
372
|
-
var fixRegExpWellKnownSymbolLogic = es_string_replace.fixRegexpWellKnownSymbolLogic;
|
|
373
|
-
var anObject = es_object_assign.anObject;
|
|
374
|
-
var toLength = es_object_assign.toLength;
|
|
375
|
-
var toString = es_string_replace.toString;
|
|
376
|
-
var requireObjectCoercible = es_object_assign.requireObjectCoercible;
|
|
377
|
-
var getMethod = es_object_assign.getMethod;
|
|
378
|
-
var advanceStringIndex = es_string_replace.advanceStringIndex;
|
|
379
|
-
var regExpExec = es_string_replace.regexpExecAbstract;
|
|
380
|
-
|
|
381
|
-
// @@match logic
|
|
382
|
-
fixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {
|
|
383
|
-
return [
|
|
384
|
-
// `String.prototype.match` method
|
|
385
|
-
// https://tc39.es/ecma262/#sec-string.prototype.match
|
|
386
|
-
function match(regexp) {
|
|
387
|
-
var O = requireObjectCoercible(this);
|
|
388
|
-
var matcher = regexp == undefined ? undefined : getMethod(regexp, MATCH);
|
|
389
|
-
return matcher ? call(matcher, regexp, O) : new RegExp(regexp)[MATCH](toString(O));
|
|
390
|
-
},
|
|
391
|
-
// `RegExp.prototype[@@match]` method
|
|
392
|
-
// https://tc39.es/ecma262/#sec-regexp.prototype-@@match
|
|
393
|
-
function (string) {
|
|
394
|
-
var rx = anObject(this);
|
|
395
|
-
var S = toString(string);
|
|
396
|
-
var res = maybeCallNative(nativeMatch, rx, S);
|
|
397
|
-
|
|
398
|
-
if (res.done) return res.value;
|
|
399
|
-
|
|
400
|
-
if (!rx.global) return regExpExec(rx, S);
|
|
401
|
-
|
|
402
|
-
var fullUnicode = rx.unicode;
|
|
403
|
-
rx.lastIndex = 0;
|
|
404
|
-
var A = [];
|
|
405
|
-
var n = 0;
|
|
406
|
-
var result;
|
|
407
|
-
while ((result = regExpExec(rx, S)) !== null) {
|
|
408
|
-
var matchStr = toString(result[0]);
|
|
409
|
-
A[n] = matchStr;
|
|
410
|
-
if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
|
|
411
|
-
n++;
|
|
412
|
-
}
|
|
413
|
-
return n === 0 ? null : A;
|
|
414
|
-
}
|
|
415
|
-
];
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
function useLogout() {
|
|
419
|
-
const t = useT();
|
|
420
|
-
const {
|
|
421
|
-
push
|
|
422
|
-
} = router.useRouter();
|
|
423
|
-
const [loading, setLoading] = React.useState(false);
|
|
424
|
-
const [ok, setOk] = React.useState(false);
|
|
425
|
-
const [fail] = React.useState(false);
|
|
426
|
-
const submit = React.useCallback(event => {
|
|
427
|
-
event.preventDefault();
|
|
428
|
-
event.stopPropagation();
|
|
429
|
-
setLoading(true);
|
|
430
|
-
react$1.signOut({
|
|
431
|
-
redirect: false
|
|
432
|
-
}).then(() => {
|
|
433
|
-
setLoading(false);
|
|
434
|
-
setOk(true);
|
|
435
|
-
const redirectUrl = utils.parseURL(getCallbackUrl());
|
|
436
|
-
const currentUrl = utils.parseURL(window.location.href);
|
|
437
|
-
const {
|
|
438
|
-
secured
|
|
439
|
-
} = getAuthRoutes(t);
|
|
440
|
-
const signin = t("~:/signin");
|
|
441
|
-
const profile = t("~:/profile");
|
|
442
|
-
const targetUrl = redirectUrl || currentUrl;
|
|
443
|
-
let redirect = "";
|
|
444
|
-
|
|
445
|
-
if (targetUrl) {
|
|
446
|
-
if (targetUrl.pathname === profile) {
|
|
447
|
-
redirect = signin;
|
|
448
|
-
} else if (secured) {
|
|
449
|
-
for (let i = 0; i < secured.length; i++) {
|
|
450
|
-
if (targetUrl.pathname.match(secured[i])) {
|
|
451
|
-
redirect = signin;
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (redirect) {
|
|
459
|
-
push(redirect);
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
}, [t, push]); // TODO: useMemo ?
|
|
463
|
-
|
|
464
|
-
return {
|
|
465
|
-
submit,
|
|
466
|
-
loading,
|
|
467
|
-
ok,
|
|
468
|
-
fail
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const Favicon = props => jsxRuntime.jsx(Head__default["default"], {
|
|
473
|
-
children: jsxRuntime.jsx(react.FaviconTags, Object.assign({}, props))
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
function useForm( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
477
|
-
schema, i18nNamespace, formProps = {}, debug) {
|
|
478
|
-
const t = useT(i18nNamespace); // const form = _useForm<InferType<ObjectSchema<T, object>>>({
|
|
479
|
-
|
|
480
|
-
const form = reactHookForm.useForm(Object.assign({
|
|
481
|
-
// @ts-expect-error FIXME:
|
|
482
|
-
resolver: yup.yupResolver(schema)
|
|
483
|
-
}, formProps)); // const { control, register, setValue } = form;
|
|
484
|
-
// const field = { control, register, setValue, t };
|
|
485
|
-
// if ("production" !== process.env["NODE_ENV"]) {
|
|
486
|
-
// if (debug) {
|
|
487
|
-
// console.log(
|
|
488
|
-
// `Form ${i18nNamespace} data`,
|
|
489
|
-
// form.watch(),
|
|
490
|
-
// `errors: `,
|
|
491
|
-
// form.formState.errors
|
|
492
|
-
// );
|
|
493
|
-
// }
|
|
494
|
-
// }
|
|
495
|
-
// if (formProps.mode === "onChange") {
|
|
496
|
-
// return { field, ...form };
|
|
497
|
-
// }
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return React.useMemo(() => {
|
|
501
|
-
const {
|
|
502
|
-
control,
|
|
503
|
-
register,
|
|
504
|
-
setValue
|
|
505
|
-
} = form;
|
|
506
|
-
const field = {
|
|
507
|
-
control,
|
|
508
|
-
register,
|
|
509
|
-
setValue,
|
|
510
|
-
t
|
|
511
|
-
};
|
|
512
|
-
return Object.assign({
|
|
513
|
-
field
|
|
514
|
-
}, form);
|
|
515
|
-
}, [t, form]);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
const api = ["get", "post", "put", "patch", "delete"].reduce((api, method) => {
|
|
519
|
-
api[method] = (endpoint, options = {}) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
520
|
-
const {
|
|
521
|
-
json = {},
|
|
522
|
-
params,
|
|
523
|
-
headers = {},
|
|
524
|
-
timeout = 10000
|
|
525
|
-
} = options;
|
|
526
|
-
const requestInit = {
|
|
527
|
-
method: method.toUpperCase(),
|
|
528
|
-
headers: Object.assign({
|
|
529
|
-
"content-type": "application/json"
|
|
530
|
-
}, headers)
|
|
531
|
-
};
|
|
532
|
-
const timeoutNumber = Number(timeout);
|
|
533
|
-
let controller;
|
|
534
|
-
let timeoutId;
|
|
535
|
-
let url = `/api/${endpoint.replace(/^\/*/, "")}`;
|
|
536
|
-
|
|
537
|
-
if (method !== "get") {
|
|
538
|
-
requestInit.body = JSON.stringify(json);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if (timeoutNumber > 0) {
|
|
542
|
-
controller = new AbortController();
|
|
543
|
-
timeoutId = setTimeout(() => controller.abort(), timeoutNumber);
|
|
544
|
-
requestInit.signal = controller.signal;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (params) {
|
|
548
|
-
url += utils.buildUrlQueryString(params);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const response = yield fetch(url, requestInit);
|
|
552
|
-
|
|
553
|
-
if (timeoutId) {
|
|
554
|
-
clearTimeout(timeoutId);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
const result = yield response.json();
|
|
558
|
-
return result;
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
return api;
|
|
562
|
-
}, {});
|
|
563
|
-
|
|
564
|
-
function useSubmit(url, transformData) {
|
|
565
|
-
const [state, submit] = reactUse.useAsyncFn(json => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
566
|
-
if (transformData) json = transformData(json);
|
|
567
|
-
const response = yield api.post(url, {
|
|
568
|
-
json
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
if ("production" !== process.env["NODE_ENV"]) {
|
|
572
|
-
console.log("[@koine/next] useSubmit response", response);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
return response;
|
|
576
|
-
}), [url, transformData]);
|
|
577
|
-
const {
|
|
578
|
-
loading,
|
|
579
|
-
error,
|
|
580
|
-
value
|
|
581
|
-
} = state;
|
|
582
|
-
const fail = !loading && (!!error || (value === null || value === void 0 ? void 0 : value.fail));
|
|
583
|
-
return Object.assign(Object.assign({
|
|
584
|
-
submit,
|
|
585
|
-
loading
|
|
586
|
-
}, value || {}), {
|
|
587
|
-
fail
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
const NextImg = NextImage__default["default"];
|
|
592
|
-
const NextImgSmart = props => {
|
|
593
|
-
const [$loaded, setLoaded] = React.useState(false);
|
|
594
|
-
const [$error, setError] = React.useState(false);
|
|
595
|
-
const {
|
|
596
|
-
nextImgProps,
|
|
597
|
-
restProps
|
|
598
|
-
} = getNextImgProps(props);
|
|
599
|
-
const {
|
|
600
|
-
Wrap
|
|
601
|
-
} = restProps;
|
|
602
|
-
return nextImgProps.priority ? jsxRuntime.jsx(NextImage__default["default"], Object.assign({}, nextImgProps)) : jsxRuntime.jsx(Wrap, Object.assign({}, restProps, {
|
|
603
|
-
"$loaded": $loaded,
|
|
604
|
-
"$error": $error
|
|
605
|
-
}, {
|
|
606
|
-
children: jsxRuntime.jsx(NextImage__default["default"], Object.assign({}, nextImgProps, {
|
|
607
|
-
onLoadingComplete: () => setLoaded(true),
|
|
608
|
-
onError: () => setError(true)
|
|
609
|
-
}))
|
|
610
|
-
}));
|
|
611
|
-
};
|
|
612
|
-
function getNextImgProps(_a) {
|
|
613
|
-
var {
|
|
614
|
-
src,
|
|
615
|
-
alt,
|
|
616
|
-
layout,
|
|
617
|
-
blurDataURL,
|
|
618
|
-
width,
|
|
619
|
-
height,
|
|
620
|
-
priority,
|
|
621
|
-
objectFit,
|
|
622
|
-
objectPosition
|
|
623
|
-
} = _a,
|
|
624
|
-
restProps = _tslib.__rest(_a, ["src", "alt", "layout", "blurDataURL", "width", "height", "priority", "objectFit", "objectPosition"]);
|
|
625
|
-
|
|
626
|
-
const nextImgProps = {
|
|
627
|
-
src,
|
|
628
|
-
alt,
|
|
629
|
-
layout,
|
|
630
|
-
blurDataURL,
|
|
631
|
-
width,
|
|
632
|
-
height,
|
|
633
|
-
priority,
|
|
634
|
-
objectFit,
|
|
635
|
-
objectPosition
|
|
636
|
-
};
|
|
637
|
-
return {
|
|
638
|
-
nextImgProps,
|
|
639
|
-
restProps
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* @see https://next.js.org/docs/api-reference/next/link
|
|
645
|
-
*/
|
|
646
|
-
|
|
647
|
-
const Link = /*#__PURE__*/React.forwardRef(function Link(_a, ref) {
|
|
648
|
-
var {
|
|
649
|
-
href,
|
|
650
|
-
prefetch,
|
|
651
|
-
replace,
|
|
652
|
-
scroll,
|
|
653
|
-
shallow,
|
|
654
|
-
locale
|
|
655
|
-
} = _a,
|
|
656
|
-
props = _tslib.__rest(_a, ["href", "prefetch", "replace", "scroll", "shallow", "locale"]);
|
|
657
|
-
|
|
658
|
-
return jsxRuntime.jsx(NextLink__default["default"], Object.assign({
|
|
659
|
-
href: href,
|
|
660
|
-
replace: replace,
|
|
661
|
-
scroll: scroll,
|
|
662
|
-
shallow: shallow,
|
|
663
|
-
locale: locale,
|
|
664
|
-
passHref: true
|
|
665
|
-
}, {
|
|
666
|
-
children: jsxRuntime.jsx(react.KoineLink, Object.assign({
|
|
667
|
-
ref: ref
|
|
668
|
-
}, props))
|
|
669
|
-
}));
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
const _Seo = props => {
|
|
673
|
-
return jsxRuntime.jsx(Head__default["default"], {
|
|
674
|
-
children: Theme.buildTags(props)
|
|
675
|
-
});
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
const Seo = /*#__PURE__*/React.memo(_Seo);
|
|
679
|
-
|
|
680
|
-
const ONE_HOUR = 3600;
|
|
681
|
-
const ONE_DAY = 84000;
|
|
682
|
-
/**
|
|
683
|
-
* Get site absolute url with the given path
|
|
684
|
-
*
|
|
685
|
-
* - It uses the `NEXT_PUBLIC_APP_URL` env variable
|
|
686
|
-
* - It removes the trailing slashes
|
|
687
|
-
*/
|
|
688
|
-
|
|
689
|
-
function getSiteUrl(path = "") {
|
|
690
|
-
return utils.normaliseUrl(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* Utility to load a component with an optional pre-determined delay.
|
|
694
|
-
*
|
|
695
|
-
* This was designed to improve anti spam wit async form loading.
|
|
696
|
-
*
|
|
697
|
-
* @see https://github.com/vercel/next.js/blob/main/packages/next/next-server/lib/dynamic.tsx
|
|
698
|
-
* @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
|
|
699
|
-
*/
|
|
700
|
-
|
|
701
|
-
function load(component, milliseconds) {
|
|
702
|
-
return new Promise(resolve => {
|
|
703
|
-
setTimeout(() => resolve(component), milliseconds);
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
exports.NextProgress = Theme.NextProgress;
|
|
708
|
-
exports.SeoDefaults = Theme.SeoDefaults;
|
|
709
|
-
exports.ThemeProvider = Theme.ThemeProvider;
|
|
710
|
-
exports.buildTags = Theme.buildTags;
|
|
711
|
-
exports.useTheme = Theme.useTheme;
|
|
712
|
-
Object.defineProperty(exports, 'T', {
|
|
713
|
-
enumerable: true,
|
|
714
|
-
get: function () { return Trans__default["default"]; }
|
|
715
|
-
});
|
|
716
|
-
Object.defineProperty(exports, 'Head', {
|
|
717
|
-
enumerable: true,
|
|
718
|
-
get: function () { return Head__default["default"]; }
|
|
719
|
-
});
|
|
720
|
-
exports.AUTH_ROUTES = AUTH_ROUTES;
|
|
721
|
-
exports.AnalyticsGoogle = AnalyticsGoogle;
|
|
722
|
-
exports.Favicon = Favicon;
|
|
723
|
-
exports.Link = Link;
|
|
724
|
-
exports.NextImg = NextImg;
|
|
725
|
-
exports.NextImgSmart = NextImgSmart;
|
|
726
|
-
exports.ONE_DAY = ONE_DAY;
|
|
727
|
-
exports.ONE_HOUR = ONE_HOUR;
|
|
728
|
-
exports.Seo = Seo;
|
|
729
|
-
exports.api = api;
|
|
730
|
-
exports.getAuthRoutes = getAuthRoutes;
|
|
731
|
-
exports.getCallbackUrl = getCallbackUrl;
|
|
732
|
-
exports.getNextImgProps = getNextImgProps;
|
|
733
|
-
exports.getSiteUrl = getSiteUrl;
|
|
734
|
-
exports.load = load;
|
|
735
|
-
exports.translationAsOptions = translationAsOptions;
|
|
736
|
-
exports.useDateFormat = useDateFormat;
|
|
737
|
-
exports.useForm = useForm;
|
|
738
|
-
exports.useLogin = useLogin;
|
|
739
|
-
exports.useLoginUrl = useLoginUrl;
|
|
740
|
-
exports.useLogout = useLogout;
|
|
741
|
-
exports.useLooseT = useLooseT;
|
|
742
|
-
exports.useSubmit = useSubmit;
|
|
743
|
-
exports.useT = useT;
|
|
1
|
+
export * from "./Analytics";
|
|
2
|
+
export * from "./Auth";
|
|
3
|
+
export * from "./Favicon";
|
|
4
|
+
export * from "./Forms";
|
|
5
|
+
export * from "./Head";
|
|
6
|
+
export * from "./I18n";
|
|
7
|
+
export * from "./Img";
|
|
8
|
+
export * from "./Link";
|
|
9
|
+
export * from "./NextProgress";
|
|
10
|
+
export * from "./Seo";
|
|
11
|
+
export * from "./Theme";
|
|
12
|
+
export * from "./utils";
|
|
13
|
+
export * from "./app";
|
|
14
|
+
export * from "./config";
|
|
15
|
+
export * from "./document";
|