@koine/next 2.0.0-beta.13 → 2.0.0-beta.130

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 (144) hide show
  1. package/12/AnalyticsGoogle.cjs.js +22 -0
  2. package/12/AnalyticsGoogle.d.ts +1 -2
  3. package/12/AnalyticsGoogle.esm.js +17 -0
  4. package/12/DisableErrorOverlay.cjs.js +15 -0
  5. package/12/DisableErrorOverlay.d.ts +1 -6
  6. package/12/DisableErrorOverlay.esm.js +10 -0
  7. package/12/Seo.d.ts +8 -26
  8. package/12/SeoDefaults.d.ts +3 -4
  9. package/12/seoBuildTags.d.ts +1 -17
  10. package/12/types.d.ts +2 -0
  11. package/12.cjs.d.ts +1 -0
  12. package/12.cjs.default.js +1 -0
  13. package/12.cjs.js +9 -0
  14. package/12.cjs.mjs +2 -0
  15. package/12.d.ts +3 -0
  16. package/12.esm.d.ts +1 -0
  17. package/12.esm.js +2 -0
  18. package/README.md +0 -12
  19. package/ThemeContext.cjs.d.ts +2 -0
  20. package/ThemeContext.cjs.default.js +1 -0
  21. package/ThemeContext.cjs.js +11 -0
  22. package/ThemeContext.cjs.mjs +2 -0
  23. package/ThemeContext.d.ts +10 -0
  24. package/ThemeContext.esm.d.ts +2 -0
  25. package/ThemeContext.esm.js +6 -0
  26. package/ThemeProvider.cjs.d.ts +2 -0
  27. package/ThemeProvider.cjs.default.js +1 -0
  28. package/ThemeProvider.cjs.js +43 -0
  29. package/ThemeProvider.cjs.mjs +2 -0
  30. package/ThemeProvider.d.ts +16 -0
  31. package/ThemeProvider.esm.d.ts +2 -0
  32. package/ThemeProvider.esm.js +38 -0
  33. package/config.cjs.d.ts +1 -0
  34. package/config.cjs.default.js +1 -0
  35. package/config.cjs.js +38 -0
  36. package/config.cjs.mjs +2 -0
  37. package/config.d.ts +14 -0
  38. package/config.esm.d.ts +1 -0
  39. package/config.esm.js +36 -0
  40. package/index.cjs.d.ts +1 -0
  41. package/index.cjs.default.js +1 -0
  42. package/index.cjs.js +13 -0
  43. package/index.cjs.mjs +2 -0
  44. package/index.d.ts +3 -1
  45. package/index.esm.d.ts +1 -0
  46. package/index.esm.js +4 -0
  47. package/load.cjs.d.ts +2 -0
  48. package/load.cjs.default.js +1 -0
  49. package/load.cjs.js +15 -0
  50. package/load.cjs.mjs +2 -0
  51. package/load.d.ts +0 -8
  52. package/load.esm.d.ts +2 -0
  53. package/{load.mjs → load.esm.js} +3 -6
  54. package/package.json +58 -69
  55. package/typings.d.ts +39 -50
  56. package/useTheme.cjs.d.ts +2 -0
  57. package/useTheme.cjs.default.js +1 -0
  58. package/useTheme.cjs.js +13 -0
  59. package/useTheme.cjs.mjs +2 -0
  60. package/useTheme.d.ts +4 -0
  61. package/useTheme.esm.d.ts +2 -0
  62. package/useTheme.esm.js +8 -0
  63. package/12/AnalyticsGoogle.mjs +0 -60
  64. package/12/DisableErrorOverlay.mjs +0 -16
  65. package/12/DynamicNamespaces.d.ts +0 -13
  66. package/12/DynamicNamespaces.mjs +0 -8
  67. package/12/Favicon.d.ts +0 -4
  68. package/12/Favicon.mjs +0 -10
  69. package/12/Link.d.ts +0 -10
  70. package/12/Link.mjs +0 -20
  71. package/12/NextProgress.d.ts +0 -25
  72. package/12/NextProgress.mjs +0 -51
  73. package/12/Seo.mjs +0 -30
  74. package/12/SeoDefaults.mjs +0 -14
  75. package/12/T.d.ts +0 -16
  76. package/12/T.mjs +0 -27
  77. package/12/ThemeContext.d.ts +0 -17
  78. package/12/ThemeContext.mjs +0 -7
  79. package/12/ThemeProvider.d.ts +0 -35
  80. package/12/ThemeProvider.mjs +0 -245
  81. package/12/TransText.d.ts +0 -3
  82. package/12/TransText.mjs +0 -4
  83. package/12/app/AppHead.d.ts +0 -3
  84. package/12/app/AppHead.mjs +0 -12
  85. package/12/app/AppMain.d.ts +0 -35
  86. package/12/app/AppMain.mjs +0 -1
  87. package/12/app/css/AppMain.d.ts +0 -9
  88. package/12/app/css/AppMain.mjs +0 -24
  89. package/12/app/css/AppTheme.d.ts +0 -11
  90. package/12/app/css/AppTheme.mjs +0 -17
  91. package/12/app/css/auth/index.d.ts +0 -11
  92. package/12/app/css/auth/index.mjs +0 -24
  93. package/12/app/css/index.d.ts +0 -54
  94. package/12/app/css/index.mjs +0 -65
  95. package/12/app/index.d.ts +0 -2
  96. package/12/app/index.mjs +0 -2
  97. package/12/app/sc/AppMain.d.ts +0 -11
  98. package/12/app/sc/AppMain.mjs +0 -58
  99. package/12/app/sc/AppTheme.d.ts +0 -14
  100. package/12/app/sc/AppTheme.mjs +0 -16
  101. package/12/app/sc/auth/index.d.ts +0 -11
  102. package/12/app/sc/auth/index.mjs +0 -24
  103. package/12/app/sc/index.d.ts +0 -56
  104. package/12/app/sc/index.mjs +0 -67
  105. package/12/document/Document.d.ts +0 -15
  106. package/12/document/Document.mjs +0 -38
  107. package/12/document/css/index.d.ts +0 -17
  108. package/12/document/css/index.mjs +0 -53
  109. package/12/document/index.d.ts +0 -2
  110. package/12/document/index.mjs +0 -2
  111. package/12/document/sc/index.d.ts +0 -19
  112. package/12/document/sc/index.mjs +0 -65
  113. package/12/getT.d.ts +0 -9
  114. package/12/getT.mjs +0 -8
  115. package/12/index.d.ts +0 -24
  116. package/12/index.mjs +0 -27
  117. package/12/seoBuildTags.mjs +0 -121
  118. package/12/to.d.ts +0 -24
  119. package/12/to.mjs +0 -19
  120. package/12/translationAsOptions.d.ts +0 -3
  121. package/12/translationAsOptions.mjs +0 -9
  122. package/12/types-i18n.d.ts +0 -118
  123. package/12/types-i18n.mjs +0 -12
  124. package/12/types-seo.d.ts +0 -7
  125. package/12/types-seo.mjs +0 -1
  126. package/12/useBackUrl.d.ts +0 -2
  127. package/12/useBackUrl.mjs +0 -28
  128. package/12/useDateFormat.d.ts +0 -7
  129. package/12/useDateFormat.mjs +0 -26
  130. package/12/useForm.d.ts +0 -27
  131. package/12/useForm.mjs +0 -47
  132. package/12/useLocale.d.ts +0 -2
  133. package/12/useLocale.mjs +0 -6
  134. package/12/useT.d.ts +0 -4
  135. package/12/useT.mjs +0 -39
  136. package/12/useTheme.d.ts +0 -7
  137. package/12/useTheme.mjs +0 -7
  138. package/12/useTo.d.ts +0 -3
  139. package/12/useTo.mjs +0 -8
  140. package/config/index.d.ts +0 -160
  141. package/config/index.mjs +0 -315
  142. package/getSiteUrl.d.ts +0 -8
  143. package/getSiteUrl.mjs +0 -10
  144. package/index.mjs +0 -2
package/config/index.mjs DELETED
@@ -1,315 +0,0 @@
1
- /**
2
- * Normalise pathname
3
- *
4
- * From a path like `/some//malformed/path///` it returns `some/malformed/path`
5
- *
6
- * - Removes subsequent slashes
7
- * - Removing initial and ending slashes
8
- * - Returns an empty string `"""` if only slashes are given
9
- */ export function normaliseUrlPathname(pathname = "") {
10
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
11
- // we would instead return a single slash if only slashes are given
12
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
13
- }
14
- /**
15
- * Transform to path any absolute or relative URL
16
- *
17
- * Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
18
- * setup](https://nextjs.org/docs/advanced-features/multi-zones).
19
- *
20
- * From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
21
- *
22
- * @see {@link normaliseUrlPathname}
23
- */ export function toPath(urlOrPathname = "") {
24
- let pathname = "";
25
- try {
26
- const parsed = new URL(urlOrPathname);
27
- pathname = parsed.pathname;
28
- } catch (e) {
29
- pathname = urlOrPathname;
30
- }
31
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
32
- // we would instead return a single slash if only slashes are given
33
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
34
- }
35
- /**
36
- * Clean a pathname and encode each part
37
- *
38
- * @see {@link normaliseUrlPathname}
39
- */ export function encodePathname(pathname = "") {
40
- const parts = normaliseUrlPathname(pathname).split("/");
41
- return parts.filter((part)=>!!part).map((part)=>encodeURIComponent(part)).join("/");
42
- }
43
- /**
44
- * Transform the route translated defintion into a `pathname` and a `template`.
45
- *
46
- * Here we add the wildcard flag maybe found in the pathname to the template
47
- * name too, this is because we do not want to have the wildcard in the JSON
48
- * keys as those are also used to produce links throught the `useTo` hook and
49
- * having asterisks there is a bit cumbersome.
50
- *
51
- * @see https://nextjs.org/docs/messages/invalid-multi-match
52
- */ function transformRoute(route) {
53
- const { pathname: rawPathname, template: rawTemplate } = route;
54
- const pathnameParts = rawPathname.split("/").filter((part)=>!!part);
55
- const templateParts = rawTemplate.split("/").filter((part)=>!!part);
56
- const mapPartsByIdx = {};
57
- const pathname = pathnameParts.map((part)=>{
58
- const hasWildcard = part.endsWith("*");
59
- part = part.replace("*", "");
60
- const isDynamic = part.startsWith("{{") && part.endsWith("}}");
61
- const asValue = isDynamic ? part.match(/{{(.+)}}/)?.[1].trim() ?? "" : part.trim();
62
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
63
- mapPartsByIdx[asValue] = {
64
- isDynamic,
65
- hasWildcard
66
- };
67
- return isDynamic ? `:${asPath}` : asPath;
68
- }).join("/");
69
- const template = templateParts.map((part)=>{
70
- const isDynamic = part.startsWith("[") && part.endsWith("]");
71
- const asValue = isDynamic ? part.match(/\[(.+)\]/)?.[1].trim() ?? "" : part.trim();
72
- const hasWildcard = mapPartsByIdx[asValue]?.hasWildcard;
73
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
74
- return isDynamic ? `:${asPath}` : asPath;
75
- }).join("/");
76
- return {
77
- pathname,
78
- template
79
- };
80
- }
81
- /**
82
- * Get routes map dictionary
83
- */ function getRoutesMap(map = {}, routes, pathnameBuffer = "", templateBuffer = "") {
84
- for(const key in routes){
85
- const pathOrNestedRoutes = routes[key];
86
- const template = `${templateBuffer}/${key}`;
87
- if (typeof pathOrNestedRoutes === "string") {
88
- map[template] = {
89
- template,
90
- pathname: pathOrNestedRoutes,
91
- wildcard: pathOrNestedRoutes.includes("*")
92
- };
93
- } else {
94
- getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
95
- }
96
- }
97
- return map;
98
- }
99
- /**
100
- * Removes `/index` from a template/url path
101
- */ function getWithoutIndex(template) {
102
- return template.replace(/\/index$/, "");
103
- }
104
- /**
105
- * Get path rewrite
106
- */ export function getPathRewrite(route) {
107
- const { pathname, template } = transformRoute(route);
108
- const source = `/${normaliseUrlPathname(pathname)}`;
109
- const destination = `/${normaliseUrlPathname(template)}`;
110
- // console.log(`rewrite pathname "${source}" to template "${destination}"`);
111
- return {
112
- source,
113
- destination: getWithoutIndex(destination)
114
- };
115
- }
116
- /**
117
- * Get path redirect
118
- */ export function getPathRedirect(locale = "", route, permanent) {
119
- const { template, pathname } = transformRoute(route);
120
- const source = `/${normaliseUrlPathname((locale ? `/${locale}/` : "/") + template)}`;
121
- const destination = `/${normaliseUrlPathname(pathname)}`;
122
- // console.log(`redirect template "${source}" to pathname "${destination}"`);
123
- return {
124
- source: getWithoutIndex(source),
125
- destination,
126
- permanent: Boolean(permanent),
127
- locale: false
128
- };
129
- }
130
- /**
131
- */ export async function getRedirects(defaultLocale, routes, permanent, debug) {
132
- const redirects = [];
133
- const routesMap = getRoutesMap({}, routes);
134
- Object.keys(routesMap).forEach((template)=>{
135
- const route = routesMap[template];
136
- // TODO: add option hideDefaultLocaleInUrl?
137
- // this is meant to redirect the URL with the default locale to the same
138
- // url without locale prefix, e.g.: /en/about -> /about (assuming en is the
139
- // defualt locale).
140
- // Actually this redirect seem not to be necessary, probably the i18n routing
141
- // mechanism of next 12 already does this, enabling causes infinite redirects
142
- // if (hideDefaultLocaleInUrl) {
143
- // redirects.push(getPathRedirect(defaultLocale, route, permanent));
144
- // }
145
- if (route.pathname !== getWithoutIndex(template)) {
146
- redirects.push(getPathRedirect("", route, permanent));
147
- }
148
- });
149
- if (debug) console.info("[@koine/next/config:getRedirects]", redirects);
150
- return redirects;
151
- }
152
- /**
153
- */ export async function getRewrites(routes, debug) {
154
- const rewrites = [];
155
- const routesMap = getRoutesMap({}, routes);
156
- Object.keys(routesMap).forEach((template)=>{
157
- const route = routesMap[template];
158
- if (route.pathname !== getWithoutIndex(template)) {
159
- rewrites.push(getPathRewrite(route));
160
- }
161
- });
162
- if (debug) console.info("[@koine/next/config:getRewrites]", rewrites);
163
- return rewrites;
164
- }
165
- /**
166
- * Get Next.js config with some basic opinionated defaults
167
- *
168
- * @param {object} options
169
- * @property {boolean} [options.nx=false] Nx monorepo setup
170
- * @property {boolean} [options.svg=false] Svg to react components
171
- * @property {boolean} [options.sc=false] Styled components enabled
172
- * @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
173
- * extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory)
174
- * and it enables the same for `next-translate`.
175
- */ export function withKoine({ nx = true, svg = true, sc = true, page, routes, permanent, debug, ...custom } = {
176
- i18n: {
177
- locales: [
178
- "en"
179
- ],
180
- defaultLocale: "en"
181
- }
182
- }) {
183
- const nextConfig = {
184
- // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
185
- pageExtensions: page ? [
186
- "page.tsx",
187
- "page.ts"
188
- ] : undefined,
189
- eslint: {
190
- ignoreDuringBuilds: true
191
- },
192
- typescript: {
193
- ignoreBuildErrors: true
194
- },
195
- poweredByHeader: false,
196
- swcMinify: true,
197
- modularizeImports: {
198
- "@koine/api": {
199
- transform: "@koine/api/{{member}}"
200
- },
201
- "@koine/browser": {
202
- transform: "@koine/browser/{{member}}"
203
- },
204
- "@koine/dom": {
205
- transform: "@koine/dom/{{member}}"
206
- },
207
- "@koine/next/?(((\\w*)?/?)*)": {
208
- transform: "@koine/next/{{ matches.[1] }}/{{member}}"
209
- },
210
- "@koine/react/?(((\\w*)?/?)*)": {
211
- transform: "@koine/react/{{ matches.[1] }}/{{member}}"
212
- },
213
- "@koine/utils": {
214
- transform: "@koine/utils/{{member}}"
215
- },
216
- ...custom["modularizeImports"] || {}
217
- },
218
- experimental: {
219
- // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
220
- // @see critters error https://github.com/vercel/next.js/issues/20742
221
- // optimizeCss: true,
222
- // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
223
- scrollRestoration: true,
224
- // concurrentFeatures: true,
225
- // serverComponents: true,
226
- // reactRoot: true,
227
- ...custom["experimental"] || {}
228
- },
229
- // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
230
- // reactStrictMode: true,
231
- ...custom
232
- };
233
- if (svg) {
234
- if (nx) {
235
- // @see https://github.com/gregberge/svgr
236
- nextConfig["nx"] = {
237
- svgr: true
238
- };
239
- } else {
240
- nextConfig.webpack = (_config, options)=>{
241
- const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config;
242
- // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
243
- webpackConfig.module.rules.push({
244
- test: /\.svg$/,
245
- use: [
246
- {
247
- loader: "@svgr/webpack",
248
- options: {
249
- svgoConfig: {
250
- plugins: [
251
- {
252
- name: "removeViewBox",
253
- active: false
254
- }
255
- ]
256
- }
257
- }
258
- }
259
- ]
260
- });
261
- return webpackConfig;
262
- };
263
- }
264
- }
265
- if (sc) {
266
- nextConfig.compiler = {
267
- styledComponents: true
268
- };
269
- }
270
- if (routes) {
271
- // we pass the default values, so we can assert I guess
272
- const defaultLocale = nextConfig?.i18n?.defaultLocale;
273
- return {
274
- ...nextConfig,
275
- async redirects () {
276
- const defaults = await getRedirects(defaultLocale, routes, permanent, debug);
277
- if (nextConfig.redirects) {
278
- const customs = await nextConfig.redirects();
279
- return [
280
- ...defaults,
281
- ...customs
282
- ];
283
- }
284
- return defaults;
285
- },
286
- async rewrites () {
287
- const defaults = await getRewrites(routes, debug);
288
- if (nextConfig.rewrites) {
289
- const customs = await nextConfig.rewrites();
290
- if (Array.isArray(customs)) {
291
- return {
292
- beforeFiles: defaults,
293
- afterFiles: customs,
294
- fallback: []
295
- };
296
- }
297
- return {
298
- ...customs,
299
- beforeFiles: [
300
- ...defaults,
301
- ...customs.beforeFiles || []
302
- ]
303
- };
304
- }
305
- return {
306
- afterFiles: [],
307
- beforeFiles: defaults,
308
- fallback: []
309
- };
310
- }
311
- };
312
- }
313
- return nextConfig;
314
- }
315
- export default withKoine;
package/getSiteUrl.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Get site absolute url with the given path
3
- *
4
- * - It uses the `NEXT_PUBLIC_APP_URL` env variable
5
- * - It removes the trailing slashes
6
- */
7
- export declare function getSiteUrl(path?: string): string;
8
- export default getSiteUrl;
package/getSiteUrl.mjs DELETED
@@ -1,10 +0,0 @@
1
- import normaliseUrl from "@koine/utils/normaliseUrl";
2
- /**
3
- * Get site absolute url with the given path
4
- *
5
- * - It uses the `NEXT_PUBLIC_APP_URL` env variable
6
- * - It removes the trailing slashes
7
- */ export function getSiteUrl(path = "") {
8
- return normaliseUrl(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
9
- }
10
- export default getSiteUrl;
package/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- export { getSiteUrl } from "./getSiteUrl";
2
- export { load } from "./load";