@koine/next 2.0.0-beta.10 → 2.0.0-beta.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.
Files changed (46) hide show
  1. package/package.json +16 -16
  2. package/12/AnalyticsGoogle.js +0 -79
  3. package/12/DisableErrorOverlay.js +0 -31
  4. package/12/DynamicNamespaces.js +0 -23
  5. package/12/Favicon.js +0 -29
  6. package/12/Link.js +0 -38
  7. package/12/NextProgress.js +0 -69
  8. package/12/Seo.js +0 -29
  9. package/12/SeoDefaults.js +0 -31
  10. package/12/T.js +0 -43
  11. package/12/ThemeContext.js +0 -25
  12. package/12/ThemeProvider.js +0 -256
  13. package/12/TransText.js +0 -23
  14. package/12/app/AppHead.js +0 -31
  15. package/12/app/AppMain.js +0 -6
  16. package/12/app/css/AppMain.js +0 -39
  17. package/12/app/css/AppTheme.js +0 -33
  18. package/12/app/css/auth/index.js +0 -40
  19. package/12/app/css/index.js +0 -36
  20. package/12/app/index.js +0 -7
  21. package/12/app/sc/AppMain.js +0 -70
  22. package/12/app/sc/AppTheme.js +0 -33
  23. package/12/app/sc/auth/index.js +0 -40
  24. package/12/app/sc/index.js +0 -36
  25. package/12/document/Document.js +0 -49
  26. package/12/document/css/index.js +0 -60
  27. package/12/document/index.js +0 -19
  28. package/12/document/sc/index.js +0 -73
  29. package/12/getT.js +0 -23
  30. package/12/index.js +0 -100
  31. package/12/seoBuildTags.js +0 -126
  32. package/12/to.js +0 -31
  33. package/12/translationAsOptions.js +0 -19
  34. package/12/types-i18n.js +0 -15
  35. package/12/types-seo.js +0 -4
  36. package/12/useBackUrl.js +0 -47
  37. package/12/useDateFormat.js +0 -42
  38. package/12/useForm.js +0 -65
  39. package/12/useLocale.js +0 -25
  40. package/12/useT.js +0 -58
  41. package/12/useTheme.js +0 -23
  42. package/12/useTo.js +0 -26
  43. package/config/index.js +0 -317
  44. package/getSiteUrl.js +0 -24
  45. package/index.js +0 -20
  46. package/load.js +0 -31
package/12/useForm.js DELETED
@@ -1,65 +0,0 @@
1
- "use client";
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- useForm: function() {
14
- return useForm;
15
- },
16
- default: function() {
17
- return _default;
18
- }
19
- });
20
- const _yup = require("@hookform/resolvers/yup");
21
- const _react = require("react");
22
- const _reacthookform = require("react-hook-form");
23
- function useForm(// eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- schema, t, formProps = {}, debug) {
25
- // const form = _useForm<InferType<ObjectSchema<T, object>>>({
26
- const form = (0, _reacthookform.useForm)({
27
- // @ts-expect-error FIXME:
28
- resolver: (0, _yup.yupResolver)(schema),
29
- // make the form behave more closer as native:
30
- // shouldUnregister: true,
31
- ...formProps
32
- });
33
- // const { control, register, setValue } = form;
34
- // const field = { control, register, setValue, t };
35
- // if (process.env["NODE_ENV"] !== "production") {
36
- // if (debug) {
37
- // console.info(
38
- // `Form ${i18nNamespace} data`,
39
- // form.watch(),
40
- // `errors: `,
41
- // form.formState.errors
42
- // );
43
- // }
44
- // }
45
- // if (formProps.mode === "onChange") {
46
- // return { field, ...form };
47
- // }
48
- return (0, _react.useMemo)(()=>{
49
- const { control, register, setValue } = form;
50
- const field = {
51
- control,
52
- register,
53
- setValue,
54
- t
55
- };
56
- return {
57
- field,
58
- ...form
59
- };
60
- }, [
61
- t,
62
- form
63
- ]);
64
- }
65
- const _default = useForm;
package/12/useLocale.js DELETED
@@ -1,25 +0,0 @@
1
- "use client";
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- useLocale: function() {
14
- return useLocale;
15
- },
16
- default: function() {
17
- return _default;
18
- }
19
- });
20
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
- const _useTranslation = /*#__PURE__*/ _interop_require_default._(require("next-translate/useTranslation"));
22
- function useLocale() {
23
- return (0, _useTranslation.default)().lang;
24
- }
25
- const _default = useLocale;
package/12/useT.js DELETED
@@ -1,58 +0,0 @@
1
- "use client";
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- useT: function() {
14
- return useT;
15
- },
16
- default: function() {
17
- return _default // Instead of wrapping the `useTranslation` hook from [`next-translate`](https://github.com/vinissimus/next-translate/blob/master/src/useTranslation.tsx)
18
- // we might just rewrite it with our custom implementation but the `_context`
19
- // to use is not exposed by the library...
20
- // import { useContext/* , useMemo */ } from "react"
21
- // // import wrapTWithDefaultNs from "next-translate";
22
- // import I18nContext from "next-translate/context";
23
- // import type { Translate } from "./types-i18n";
24
- // export default function useT(_defaultNS?: string) {
25
- // const ctx = useContext(I18nContext);
26
- // return ctx.t as Translate;
27
- // // return useMemo(
28
- // // () => ({
29
- // // ...ctx,
30
- // // t: wrapTWithDefaultNs(ctx.t, defaultNS),
31
- // // }),
32
- // // [ctx, defaultNS]
33
- // // )
34
- // }
35
- ;
36
- }
37
- });
38
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
39
- const _context = /*#__PURE__*/ _interop_require_default._(require("next-translate/context"));
40
- const _react = require("react");
41
- function useT(namespace) {
42
- const { t } = (0, _react.useContext)(_context.default);
43
- // const t = useTranslation().t;
44
- const tMemoized = (0, _react.useMemo)(()=>function(s, q, o) {
45
- return t(namespace ? `${namespace}:${s}` : `${s}`, q === "obj" || q === "" ? null : q, q === "obj" || o === "obj" ? {
46
- returnObjects: true
47
- } : q === "" || o === "" ? {
48
- fallback: ""
49
- } : o);
50
- // ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
51
- // );
52
- }, [
53
- t,
54
- namespace
55
- ]);
56
- return tMemoized;
57
- }
58
- const _default = useT;
package/12/useTheme.js DELETED
@@ -1,23 +0,0 @@
1
- "use client";
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- useTheme: function() {
14
- return useTheme;
15
- },
16
- default: function() {
17
- return _default;
18
- }
19
- });
20
- const _react = require("react");
21
- const _ThemeContext = require("./ThemeContext");
22
- const useTheme = ()=>(0, _react.useContext)(_ThemeContext.ThemeContext);
23
- const _default = useTheme;
package/12/useTo.js DELETED
@@ -1,26 +0,0 @@
1
- "use client";
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- useTo: function() {
14
- return useTo;
15
- },
16
- default: function() {
17
- return _default;
18
- }
19
- });
20
- const _to = require("./to");
21
- const _useT = require("./useT");
22
- function useTo() {
23
- const t = (0, _useT.useT)("~");
24
- return (...args)=>(0, _to.to)(t, ...args);
25
- }
26
- const _default = useTo;
package/config/index.js DELETED
@@ -1,317 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- normaliseUrlPathname: function() {
13
- return normaliseUrlPathname;
14
- },
15
- toPath: function() {
16
- return toPath;
17
- },
18
- encodePathname: function() {
19
- return encodePathname;
20
- },
21
- getPathRewrite: function() {
22
- return getPathRewrite;
23
- },
24
- getPathRedirect: function() {
25
- return getPathRedirect;
26
- },
27
- getRedirects: function() {
28
- return getRedirects;
29
- },
30
- getRewrites: function() {
31
- return getRewrites;
32
- },
33
- withKoine: function() {
34
- return withKoine;
35
- },
36
- default: function() {
37
- return _default;
38
- }
39
- });
40
- function normaliseUrlPathname(pathname = "") {
41
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
42
- // we would instead return a single slash if only slashes are given
43
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
44
- }
45
- function toPath(urlOrPathname = "") {
46
- let pathname = "";
47
- try {
48
- const parsed = new URL(urlOrPathname);
49
- pathname = parsed.pathname;
50
- } catch (e) {
51
- pathname = urlOrPathname;
52
- }
53
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
54
- // we would instead return a single slash if only slashes are given
55
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
56
- }
57
- function encodePathname(pathname = "") {
58
- const parts = normaliseUrlPathname(pathname).split("/");
59
- return parts.filter((part)=>!!part).map((part)=>encodeURIComponent(part)).join("/");
60
- }
61
- /**
62
- * Transform the route translated defintion into a `pathname` and a `template`.
63
- *
64
- * Here we add the wildcard flag maybe found in the pathname to the template
65
- * name too, this is because we do not want to have the wildcard in the JSON
66
- * keys as those are also used to produce links throught the `useTo` hook and
67
- * having asterisks there is a bit cumbersome.
68
- *
69
- * @see https://nextjs.org/docs/messages/invalid-multi-match
70
- */ function transformRoute(route) {
71
- const { pathname: rawPathname, template: rawTemplate } = route;
72
- const pathnameParts = rawPathname.split("/").filter((part)=>!!part);
73
- const templateParts = rawTemplate.split("/").filter((part)=>!!part);
74
- const mapPartsByIdx = {};
75
- const pathname = pathnameParts.map((part)=>{
76
- const hasWildcard = part.endsWith("*");
77
- part = part.replace("*", "");
78
- const isDynamic = part.startsWith("{{") && part.endsWith("}}");
79
- const asValue = isDynamic ? part.match(/{{(.+)}}/)?.[1].trim() ?? "" : part.trim();
80
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
81
- mapPartsByIdx[asValue] = {
82
- isDynamic,
83
- hasWildcard
84
- };
85
- return isDynamic ? `:${asPath}` : asPath;
86
- }).join("/");
87
- const template = templateParts.map((part)=>{
88
- const isDynamic = part.startsWith("[") && part.endsWith("]");
89
- const asValue = isDynamic ? part.match(/\[(.+)\]/)?.[1].trim() ?? "" : part.trim();
90
- const hasWildcard = mapPartsByIdx[asValue]?.hasWildcard;
91
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
92
- return isDynamic ? `:${asPath}` : asPath;
93
- }).join("/");
94
- return {
95
- pathname,
96
- template
97
- };
98
- }
99
- /**
100
- * Get routes map dictionary
101
- */ function getRoutesMap(map = {}, routes, pathnameBuffer = "", templateBuffer = "") {
102
- for(const key in routes){
103
- const pathOrNestedRoutes = routes[key];
104
- const template = `${templateBuffer}/${key}`;
105
- if (typeof pathOrNestedRoutes === "string") {
106
- map[template] = {
107
- template,
108
- pathname: pathOrNestedRoutes,
109
- wildcard: pathOrNestedRoutes.includes("*")
110
- };
111
- } else {
112
- getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
113
- }
114
- }
115
- return map;
116
- }
117
- /**
118
- * Removes `/index` from a template/url path
119
- */ function getWithoutIndex(template) {
120
- return template.replace(/\/index$/, "");
121
- }
122
- function getPathRewrite(route) {
123
- const { pathname, template } = transformRoute(route);
124
- const source = `/${normaliseUrlPathname(pathname)}`;
125
- const destination = `/${normaliseUrlPathname(template)}`;
126
- // console.log(`rewrite pathname "${source}" to template "${destination}"`);
127
- return {
128
- source,
129
- destination: getWithoutIndex(destination)
130
- };
131
- }
132
- function getPathRedirect(locale = "", route, permanent) {
133
- const { template, pathname } = transformRoute(route);
134
- const source = `/${normaliseUrlPathname((locale ? `/${locale}/` : "/") + template)}`;
135
- const destination = `/${normaliseUrlPathname(pathname)}`;
136
- // console.log(`redirect template "${source}" to pathname "${destination}"`);
137
- return {
138
- source: getWithoutIndex(source),
139
- destination,
140
- permanent: Boolean(permanent),
141
- locale: false
142
- };
143
- }
144
- async function getRedirects(defaultLocale, routes, permanent, debug) {
145
- const redirects = [];
146
- const routesMap = getRoutesMap({}, routes);
147
- Object.keys(routesMap).forEach((template)=>{
148
- const route = routesMap[template];
149
- // TODO: add option hideDefaultLocaleInUrl?
150
- // this is meant to redirect the URL with the default locale to the same
151
- // url without locale prefix, e.g.: /en/about -> /about (assuming en is the
152
- // defualt locale).
153
- // Actually this redirect seem not to be necessary, probably the i18n routing
154
- // mechanism of next 12 already does this, enabling causes infinite redirects
155
- // if (hideDefaultLocaleInUrl) {
156
- // redirects.push(getPathRedirect(defaultLocale, route, permanent));
157
- // }
158
- if (route.pathname !== getWithoutIndex(template)) {
159
- redirects.push(getPathRedirect("", route, permanent));
160
- }
161
- });
162
- if (debug) console.info("[@koine/next/config:getRedirects]", redirects);
163
- return redirects;
164
- }
165
- async function getRewrites(routes, debug) {
166
- const rewrites = [];
167
- const routesMap = getRoutesMap({}, routes);
168
- Object.keys(routesMap).forEach((template)=>{
169
- const route = routesMap[template];
170
- if (route.pathname !== getWithoutIndex(template)) {
171
- rewrites.push(getPathRewrite(route));
172
- }
173
- });
174
- if (debug) console.info("[@koine/next/config:getRewrites]", rewrites);
175
- return rewrites;
176
- }
177
- function withKoine({ nx = true, svg = true, sc = true, page, routes, permanent, debug, ...custom } = {
178
- i18n: {
179
- locales: [
180
- "en"
181
- ],
182
- defaultLocale: "en"
183
- }
184
- }) {
185
- const nextConfig = {
186
- // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
187
- pageExtensions: page ? [
188
- "page.tsx",
189
- "page.ts"
190
- ] : undefined,
191
- eslint: {
192
- ignoreDuringBuilds: true
193
- },
194
- typescript: {
195
- ignoreBuildErrors: true
196
- },
197
- poweredByHeader: false,
198
- swcMinify: true,
199
- modularizeImports: {
200
- "@koine/api": {
201
- transform: "@koine/api/{{member}}"
202
- },
203
- "@koine/browser": {
204
- transform: "@koine/browser/{{member}}"
205
- },
206
- "@koine/dom": {
207
- transform: "@koine/dom/{{member}}"
208
- },
209
- "@koine/next/?(((\\w*)?/?)*)": {
210
- transform: "@koine/next/{{ matches.[1] }}/{{member}}"
211
- },
212
- "@koine/react/?(((\\w*)?/?)*)": {
213
- transform: "@koine/react/{{ matches.[1] }}/{{member}}"
214
- },
215
- "@koine/utils": {
216
- transform: "@koine/utils/{{member}}"
217
- },
218
- ...custom["modularizeImports"] || {}
219
- },
220
- experimental: {
221
- // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
222
- // @see critters error https://github.com/vercel/next.js/issues/20742
223
- // optimizeCss: true,
224
- // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
225
- scrollRestoration: true,
226
- // concurrentFeatures: true,
227
- // serverComponents: true,
228
- // reactRoot: true,
229
- ...custom["experimental"] || {}
230
- },
231
- // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
232
- // reactStrictMode: true,
233
- ...custom
234
- };
235
- if (svg) {
236
- if (nx) {
237
- // @see https://github.com/gregberge/svgr
238
- nextConfig["nx"] = {
239
- svgr: true
240
- };
241
- } else {
242
- nextConfig.webpack = (_config, options)=>{
243
- const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config;
244
- // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
245
- webpackConfig.module.rules.push({
246
- test: /\.svg$/,
247
- use: [
248
- {
249
- loader: "@svgr/webpack",
250
- options: {
251
- svgoConfig: {
252
- plugins: [
253
- {
254
- name: "removeViewBox",
255
- active: false
256
- }
257
- ]
258
- }
259
- }
260
- }
261
- ]
262
- });
263
- return webpackConfig;
264
- };
265
- }
266
- }
267
- if (sc) {
268
- nextConfig.compiler = {
269
- styledComponents: true
270
- };
271
- }
272
- if (routes) {
273
- // we pass the default values, so we can assert I guess
274
- const defaultLocale = nextConfig?.i18n?.defaultLocale;
275
- return {
276
- ...nextConfig,
277
- async redirects () {
278
- const defaults = await getRedirects(defaultLocale, routes, permanent, debug);
279
- if (nextConfig.redirects) {
280
- const customs = await nextConfig.redirects();
281
- return [
282
- ...defaults,
283
- ...customs
284
- ];
285
- }
286
- return defaults;
287
- },
288
- async rewrites () {
289
- const defaults = await getRewrites(routes, debug);
290
- if (nextConfig.rewrites) {
291
- const customs = await nextConfig.rewrites();
292
- if (Array.isArray(customs)) {
293
- return {
294
- beforeFiles: defaults,
295
- afterFiles: customs,
296
- fallback: []
297
- };
298
- }
299
- return {
300
- ...customs,
301
- beforeFiles: [
302
- ...defaults,
303
- ...customs.beforeFiles || []
304
- ]
305
- };
306
- }
307
- return {
308
- afterFiles: [],
309
- beforeFiles: defaults,
310
- fallback: []
311
- };
312
- }
313
- };
314
- }
315
- return nextConfig;
316
- }
317
- const _default = withKoine;
package/getSiteUrl.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- getSiteUrl: function() {
13
- return getSiteUrl;
14
- },
15
- default: function() {
16
- return _default;
17
- }
18
- });
19
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
20
- const _normaliseUrl = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/normaliseUrl"));
21
- function getSiteUrl(path = "") {
22
- return (0, _normaliseUrl.default)(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
23
- }
24
- const _default = getSiteUrl;
package/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- getSiteUrl: function() {
13
- return _getSiteUrl.getSiteUrl;
14
- },
15
- load: function() {
16
- return _load.load;
17
- }
18
- });
19
- const _getSiteUrl = require("./getSiteUrl");
20
- const _load = require("./load");
package/load.js DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * Utility to load a component with an optional pre-determined delay.
3
- *
4
- * This was designed to improve anti spam with async form loading.
5
- *
6
- * @see https://github.com/vercel/next.js/blob/main/packages/next/next-server/lib/dynamic.tsx
7
- * @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
8
- */ "use strict";
9
- Object.defineProperty(exports, "__esModule", {
10
- value: true
11
- });
12
- function _export(target, all) {
13
- for(var name in all)Object.defineProperty(target, name, {
14
- enumerable: true,
15
- get: all[name]
16
- });
17
- }
18
- _export(exports, {
19
- load: function() {
20
- return load;
21
- },
22
- default: function() {
23
- return _default;
24
- }
25
- });
26
- function load(component, milliseconds) {
27
- return new Promise((resolve)=>{
28
- setTimeout(()=>resolve(component), milliseconds);
29
- });
30
- }
31
- const _default = load;