nuxt-i18n-micro 1.92.0 → 1.94.0
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/dist/client/200.html +9 -9
- package/dist/client/404.html +9 -9
- package/dist/client/_nuxt/{_zkMRV-i.js → BghP2wsD.js} +3 -3
- package/dist/client/_nuxt/{BtwGllwe.js → BhtDXNyb.js} +1 -1
- package/dist/client/_nuxt/{CVvbzfw5.js → BjB9nc_5.js} +1 -1
- package/dist/client/_nuxt/{BMqVQu_u.js → DpQNspb6.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/bd644dea-2454-468d-ba61-8e09f211303a.json +1 -0
- package/dist/client/_nuxt/{entry.BCs9F03n.css → entry.BVfqTszp.css} +1 -1
- package/dist/client/_nuxt/error-404.CdQyF-WE.css +1 -0
- package/dist/client/_nuxt/error-500.CDURyqPT.css +1 -0
- package/dist/client/index.html +9 -9
- package/dist/module.d.mts +2 -1
- package/dist/module.json +3 -3
- package/dist/module.mjs +120 -36
- package/dist/runtime/components/i18n-group.vue +7 -10
- package/dist/runtime/components/i18n-group.vue.d.ts +19 -0
- package/dist/runtime/components/i18n-link.vue +26 -43
- package/dist/runtime/components/i18n-link.vue.d.ts +19 -0
- package/dist/runtime/components/i18n-switcher.vue +93 -143
- package/dist/runtime/components/i18n-switcher.vue.d.ts +62 -0
- package/dist/runtime/components/i18n-t.vue.d.ts +1 -304
- package/dist/runtime/components/locale-redirect.vue +32 -50
- package/dist/runtime/components/locale-redirect.vue.d.ts +2 -0
- package/dist/runtime/composables/useLocaleHead.d.ts +2 -2
- package/dist/runtime/plugins/01.plugin.js +6 -2
- package/dist/runtime/plugins/04.auto-detect.js +4 -1
- package/dist/types.d.mts +8 -2
- package/package.json +24 -27
- package/dist/client/_nuxt/builds/meta/8285b70f-da27-4cee-8115-0317ce43cfa3.json +0 -1
- package/dist/client/_nuxt/error-404.CbefIQ4Z.css +0 -1
- package/dist/client/_nuxt/error-500.Bpd-7vXd.css +0 -1
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -31
- package/dist/types.d.ts +0 -7
- package/dist/utils.d.mts +0 -17
- package/dist/utils.d.ts +0 -17
- package/dist/utils.mjs +0 -64
- /package/{internals.d.ts → internals.d.mts} +0 -0
package/dist/module.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { isPrefixAndDefaultStrategy, isPrefixStrategy, isNoPrefixStrategy, isPre
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
9
9
|
import sirv from 'sirv';
|
|
10
|
-
import { isInternalPath, extractLocaleRoutes, normalizePath, isLocaleDefault, cloneArray, isPageRedirectOnly, removeLeadingSlash, shouldAddLocalePrefix, buildFullPath, buildRouteName, buildFullPathNoPrefix } from './utils.mjs';
|
|
11
10
|
|
|
12
11
|
const DEVTOOLS_UI_PORT = 3030;
|
|
13
12
|
const DEVTOOLS_UI_ROUTE = "/__nuxt-i18n-micro";
|
|
@@ -74,8 +73,7 @@ function setupDevToolsUI(options, resolve2) {
|
|
|
74
73
|
const localesDir = path.join(rootDir, options.translationDir || "locales");
|
|
75
74
|
const pagesDir = path.join(localesDir, "pages");
|
|
76
75
|
const processDirectory = (dir) => {
|
|
77
|
-
if (!fs.existsSync(dir))
|
|
78
|
-
return;
|
|
76
|
+
if (!fs.existsSync(dir)) return;
|
|
79
77
|
fs.readdirSync(dir).forEach((file) => {
|
|
80
78
|
const filePath = path.join(dir, file);
|
|
81
79
|
const stat = fs.lstatSync(filePath);
|
|
@@ -110,6 +108,64 @@ function setupDevToolsUI(options, resolve2) {
|
|
|
110
108
|
});
|
|
111
109
|
}
|
|
112
110
|
|
|
111
|
+
const isInternalPath = (p) => /(?:^|\/)__[^/]+/.test(p);
|
|
112
|
+
function extractLocaleRoutes(content, filePath) {
|
|
113
|
+
const defineMatch = content.match(/\$?\bdefineI18nRoute\s*\(\s*\{[\s\S]*?\}\s*\)/);
|
|
114
|
+
if (defineMatch) {
|
|
115
|
+
const localeRoutesMatch = defineMatch[0].match(/localeRoutes:\s*(\{[\s\S]*?\})/);
|
|
116
|
+
if (localeRoutesMatch && localeRoutesMatch[1]) {
|
|
117
|
+
try {
|
|
118
|
+
const parsedLocaleRoutes = Function('"use strict";return (' + localeRoutesMatch[1] + ")")();
|
|
119
|
+
if (typeof parsedLocaleRoutes === "object" && parsedLocaleRoutes !== null) {
|
|
120
|
+
if (validateDefineI18nRouteConfig(parsedLocaleRoutes)) {
|
|
121
|
+
return parsedLocaleRoutes;
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
console.error("localeRoutes found but it is not a valid object in file:", filePath);
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("Failed to parse localeRoutes:", error, "in file:", filePath);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
function validateDefineI18nRouteConfig(obj) {
|
|
134
|
+
if (typeof obj !== "object") return false;
|
|
135
|
+
for (const routeKey in obj.localeRoutes) {
|
|
136
|
+
if (typeof obj.localeRoutes[routeKey] !== "string") return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
const normalizePath = (routePath) => {
|
|
141
|
+
if (!routePath) {
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
const normalized = path.posix.normalize(routePath).replace(/\/+$/, "");
|
|
145
|
+
return normalized === "." ? "" : normalized;
|
|
146
|
+
};
|
|
147
|
+
const cloneArray = (array) => array.map((item) => ({ ...item }));
|
|
148
|
+
const isPageRedirectOnly = (page) => !!(page.redirect && !page.file);
|
|
149
|
+
const removeLeadingSlash = (routePath) => routePath.startsWith("/") ? routePath.slice(1) : routePath;
|
|
150
|
+
const buildRouteName = (baseName, localeCode, isCustom) => isCustom ? `localized-${baseName}-${localeCode}` : `localized-${baseName}`;
|
|
151
|
+
const shouldAddLocalePrefix = (locale, defaultLocale, addLocalePrefix, includeDefaultLocaleRoute) => addLocalePrefix && !(locale === defaultLocale.code && !includeDefaultLocaleRoute);
|
|
152
|
+
const isLocaleDefault = (locale, defaultLocale, includeDefaultLocaleRoute) => {
|
|
153
|
+
const localeCode = typeof locale === "string" ? locale : locale.code;
|
|
154
|
+
return localeCode === defaultLocale.code && !includeDefaultLocaleRoute;
|
|
155
|
+
};
|
|
156
|
+
const buildFullPath = (locale, basePath, customRegex) => {
|
|
157
|
+
const regexString = normalizeRegex(customRegex?.toString());
|
|
158
|
+
const localeParam = regexString ? regexString : Array.isArray(locale) ? locale.join("|") : locale;
|
|
159
|
+
return normalizePath(path.posix.join("/", `:locale(${localeParam})`, basePath));
|
|
160
|
+
};
|
|
161
|
+
const buildFullPathNoPrefix = (basePath) => {
|
|
162
|
+
return normalizePath(basePath);
|
|
163
|
+
};
|
|
164
|
+
const normalizeRegex = (toNorm) => {
|
|
165
|
+
if (typeof toNorm === "undefined") return void 0;
|
|
166
|
+
return toNorm.startsWith("/") && toNorm.endsWith("/") ? toNorm?.slice(1, -1) : toNorm;
|
|
167
|
+
};
|
|
168
|
+
|
|
113
169
|
const buildRouteNameFromRoute = (name, path2) => {
|
|
114
170
|
return name ?? (path2 ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
|
|
115
171
|
};
|
|
@@ -163,12 +219,11 @@ class PageManager {
|
|
|
163
219
|
if (isPrefixStrategy(this.strategy) && !isCloudflarePages) {
|
|
164
220
|
for (let i = pages.length - 1; i >= 0; i--) {
|
|
165
221
|
const page = pages[i];
|
|
222
|
+
if (!page) continue;
|
|
166
223
|
const pagePath = page.path ?? "";
|
|
167
224
|
const pageName = page.name ?? "";
|
|
168
|
-
if (isInternalPath(pagePath))
|
|
169
|
-
|
|
170
|
-
if (this.globalLocaleRoutes[pageName] === false)
|
|
171
|
-
continue;
|
|
225
|
+
if (isInternalPath(pagePath)) continue;
|
|
226
|
+
if (this.globalLocaleRoutes[pageName] === false) continue;
|
|
172
227
|
if (!/^\/:locale/.test(pagePath) && pagePath !== "/") {
|
|
173
228
|
pages.splice(i, 1);
|
|
174
229
|
}
|
|
@@ -210,16 +265,14 @@ class PageManager {
|
|
|
210
265
|
const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, false, locale.code);
|
|
211
266
|
if (newRoute) {
|
|
212
267
|
additionalRoutes.push(newRoute);
|
|
213
|
-
if (this.noPrefixRedirect)
|
|
214
|
-
page.redirect = newRoute.path;
|
|
268
|
+
if (this.noPrefixRedirect) page.redirect = newRoute.path;
|
|
215
269
|
}
|
|
216
270
|
} else {
|
|
217
271
|
if (isDefaultLocale) {
|
|
218
272
|
page.path = normalizePath(customPath);
|
|
219
273
|
} else {
|
|
220
274
|
const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, false, locale.code);
|
|
221
|
-
if (newRoute)
|
|
222
|
-
additionalRoutes.push(newRoute);
|
|
275
|
+
if (newRoute) additionalRoutes.push(newRoute);
|
|
223
276
|
}
|
|
224
277
|
}
|
|
225
278
|
} else {
|
|
@@ -233,15 +286,13 @@ class PageManager {
|
|
|
233
286
|
});
|
|
234
287
|
}
|
|
235
288
|
localizePage(page, additionalRoutes, customRegex) {
|
|
236
|
-
if (isPageRedirectOnly(page))
|
|
237
|
-
return;
|
|
289
|
+
if (isPageRedirectOnly(page)) return;
|
|
238
290
|
const originalChildren = cloneArray(page.children ?? []);
|
|
239
291
|
const normalizedFullPath = normalizePath(page.path);
|
|
240
292
|
const localeCodesWithoutCustomPaths = this.filterLocaleCodesWithoutCustomPaths(normalizedFullPath);
|
|
241
293
|
if (localeCodesWithoutCustomPaths.length) {
|
|
242
294
|
const newRoute = this.createLocalizedRoute(page, localeCodesWithoutCustomPaths, originalChildren, false, "", customRegex, false, true);
|
|
243
|
-
if (newRoute)
|
|
244
|
-
additionalRoutes.push(newRoute);
|
|
295
|
+
if (newRoute) additionalRoutes.push(newRoute);
|
|
245
296
|
}
|
|
246
297
|
this.addCustomLocalizedRoutes(page, normalizedFullPath, originalChildren, additionalRoutes);
|
|
247
298
|
this.adjustRouteForDefaultLocale(page, originalChildren);
|
|
@@ -285,20 +336,17 @@ class PageManager {
|
|
|
285
336
|
addCustomLocalizedRoutes(page, fullPath, originalChildren, additionalRoutes, customRegex) {
|
|
286
337
|
this.locales.forEach((locale) => {
|
|
287
338
|
const customPath = this.localizedPaths[fullPath]?.[locale.code];
|
|
288
|
-
if (!customPath)
|
|
289
|
-
return;
|
|
339
|
+
if (!customPath) return;
|
|
290
340
|
const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy) || isNoPrefixStrategy(this.strategy));
|
|
291
341
|
if (isDefaultLocale) {
|
|
292
342
|
page.children = this.createLocalizedChildren(originalChildren, "", [locale.code], false);
|
|
293
343
|
} else {
|
|
294
344
|
const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, false, locale.code);
|
|
295
|
-
if (newRoute)
|
|
296
|
-
additionalRoutes.push(newRoute);
|
|
345
|
+
if (newRoute) additionalRoutes.push(newRoute);
|
|
297
346
|
}
|
|
298
347
|
if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
|
|
299
348
|
const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, true, locale.code);
|
|
300
|
-
if (newRoute)
|
|
301
|
-
additionalRoutes.push(newRoute);
|
|
349
|
+
if (newRoute) additionalRoutes.push(newRoute);
|
|
302
350
|
}
|
|
303
351
|
});
|
|
304
352
|
}
|
|
@@ -393,9 +441,11 @@ class PageManager {
|
|
|
393
441
|
}
|
|
394
442
|
createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex, force = false, parentLocale = false) {
|
|
395
443
|
const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex, force);
|
|
396
|
-
if (!routePath || routePath == page.path)
|
|
397
|
-
|
|
398
|
-
const
|
|
444
|
+
if (!routePath || routePath == page.path) return null;
|
|
445
|
+
if (localeCodes.length === 0) return null;
|
|
446
|
+
const firstLocale = localeCodes[0];
|
|
447
|
+
if (!firstLocale) return null;
|
|
448
|
+
const routeName = buildRouteName(buildRouteNameFromRoute(page.name ?? "", page.path ?? ""), firstLocale, isCustom);
|
|
399
449
|
return {
|
|
400
450
|
...page,
|
|
401
451
|
children: this.createLocalizedChildren(originalChildren, page.path, localeCodes, true, false, parentLocale),
|
|
@@ -404,8 +454,7 @@ class PageManager {
|
|
|
404
454
|
};
|
|
405
455
|
}
|
|
406
456
|
buildLocalizedRouteName(baseName, locale, modifyName, forceLocaleSuffixOrCustom = false) {
|
|
407
|
-
if (!modifyName)
|
|
408
|
-
return baseName;
|
|
457
|
+
if (!modifyName) return baseName;
|
|
409
458
|
if (forceLocaleSuffixOrCustom) {
|
|
410
459
|
return `localized-${baseName}-${locale}`;
|
|
411
460
|
}
|
|
@@ -524,7 +573,10 @@ const module = defineNuxtModule({
|
|
|
524
573
|
return null;
|
|
525
574
|
}
|
|
526
575
|
const forms = translation.toString().split("|");
|
|
527
|
-
|
|
576
|
+
if (forms.length === 0) return null;
|
|
577
|
+
const selectedForm = count < forms.length ? forms[count] : forms[forms.length - 1];
|
|
578
|
+
if (!selectedForm) return null;
|
|
579
|
+
return selectedForm.trim().replace("{count}", count.toString());
|
|
528
580
|
},
|
|
529
581
|
customRegexMatcher: void 0
|
|
530
582
|
},
|
|
@@ -652,6 +704,7 @@ const module = defineNuxtModule({
|
|
|
652
704
|
}
|
|
653
705
|
nuxt.hook("pages:resolved", (pages) => {
|
|
654
706
|
const prerenderRoutes = [];
|
|
707
|
+
const routeRules = nuxt.options.routeRules || {};
|
|
655
708
|
const pagesNames = pages.map((page) => page.name).filter((name) => name !== void 0 && (!options.routesLocaleLinks || !options.routesLocaleLinks[name]));
|
|
656
709
|
localeManager.locales.forEach((locale) => {
|
|
657
710
|
if (!options.disablePageLocales) {
|
|
@@ -677,23 +730,32 @@ const module = defineNuxtModule({
|
|
|
677
730
|
pages.push(fallbackRoute);
|
|
678
731
|
}
|
|
679
732
|
if (!isNoPrefixStrategy(options.strategy)) {
|
|
680
|
-
|
|
733
|
+
const nuxtOptions = nuxt.options;
|
|
734
|
+
nuxtOptions.generate = nuxtOptions.generate || {};
|
|
735
|
+
nuxtOptions.generate.routes = Array.isArray(nuxtOptions.generate.routes) ? nuxtOptions.generate.routes : [];
|
|
681
736
|
if (isCloudflarePages) {
|
|
682
737
|
const processPageWithChildren = (page, parentPath = "") => {
|
|
683
|
-
if (!page.path)
|
|
684
|
-
return;
|
|
738
|
+
if (!page.path) return;
|
|
685
739
|
const fullPath = path.posix.normalize(`${parentPath}/${page.path}`);
|
|
686
740
|
if (isInternalPath(fullPath)) {
|
|
687
741
|
return;
|
|
688
742
|
}
|
|
743
|
+
const routeRule = routeRules[fullPath];
|
|
744
|
+
if (routeRule && routeRule.prerender === false) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
689
747
|
const localeSegmentMatch = fullPath.match(/:locale\(([^)]+)\)/);
|
|
690
|
-
if (localeSegmentMatch) {
|
|
748
|
+
if (localeSegmentMatch && localeSegmentMatch[1]) {
|
|
691
749
|
const availableLocales = localeSegmentMatch[1].split("|");
|
|
692
750
|
localeManager.locales.forEach((locale) => {
|
|
693
751
|
const localeCode = locale.code;
|
|
694
752
|
if (availableLocales.includes(localeCode)) {
|
|
695
753
|
let localizedPath = fullPath;
|
|
696
754
|
localizedPath = localizedPath.replace(/:locale\([^)]+\)/, localeCode);
|
|
755
|
+
const localizedRouteRule = routeRules[localizedPath];
|
|
756
|
+
if (localizedRouteRule && localizedRouteRule.prerender === false) {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
697
759
|
if (!isInternalPath(localizedPath)) {
|
|
698
760
|
prerenderRoutes.push(localizedPath);
|
|
699
761
|
}
|
|
@@ -761,14 +823,25 @@ const module = defineNuxtModule({
|
|
|
761
823
|
return;
|
|
762
824
|
}
|
|
763
825
|
const routes = nitroConfig.prerender?.routes || [];
|
|
764
|
-
|
|
765
|
-
|
|
826
|
+
const nuxtOptions = nuxt.options;
|
|
827
|
+
nuxtOptions.generate = nuxtOptions.generate || {};
|
|
828
|
+
nuxtOptions.generate.routes = Array.isArray(nuxtOptions.generate.routes) ? nuxtOptions.generate.routes : [];
|
|
829
|
+
const pages = nuxtOptions.generate.routes || [];
|
|
766
830
|
localeManager.locales.forEach((locale) => {
|
|
767
831
|
const shouldGenerate = locale.code !== defaultLocale || withPrefixStrategy(options.strategy);
|
|
768
832
|
if (shouldGenerate) {
|
|
769
833
|
pages.forEach((page) => {
|
|
770
834
|
if (!/\.[a-z0-9]+$/i.test(page) && !isInternalPath(page)) {
|
|
771
|
-
|
|
835
|
+
const localizedPage = `/${locale.code}${page}`;
|
|
836
|
+
const routeRule = routeRules[page];
|
|
837
|
+
if (routeRule && routeRule.prerender === false) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
const localizedRouteRule = routeRules[localizedPage];
|
|
841
|
+
if (localizedRouteRule && localizedRouteRule.prerender === false) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
routes.push(localizedPage);
|
|
772
845
|
}
|
|
773
846
|
});
|
|
774
847
|
}
|
|
@@ -820,16 +893,27 @@ const module = defineNuxtModule({
|
|
|
820
893
|
});
|
|
821
894
|
routesToRemove.forEach((route) => routesSet.delete(route));
|
|
822
895
|
const additionalRoutes = /* @__PURE__ */ new Set();
|
|
896
|
+
const routeRules = nuxt.options.routeRules || {};
|
|
823
897
|
routesSet.forEach((route) => {
|
|
824
898
|
if (!/\.[a-z0-9]+$/i.test(route) && !isInternalPath(route)) {
|
|
825
899
|
localeManager.locales.forEach((locale) => {
|
|
826
900
|
const shouldGenerate = locale.code !== defaultLocale || withPrefixStrategy(options.strategy);
|
|
827
901
|
if (shouldGenerate) {
|
|
902
|
+
let localizedRoute;
|
|
828
903
|
if (route === "/") {
|
|
829
|
-
|
|
904
|
+
localizedRoute = `/${locale.code}`;
|
|
830
905
|
} else {
|
|
831
|
-
|
|
906
|
+
localizedRoute = `/${locale.code}${route}`;
|
|
907
|
+
}
|
|
908
|
+
const routeRule = routeRules[route];
|
|
909
|
+
if (routeRule && routeRule.prerender === false) {
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
const localizedRouteRule = routeRules[localizedRoute];
|
|
913
|
+
if (localizedRouteRule && localizedRouteRule.prerender === false) {
|
|
914
|
+
return;
|
|
832
915
|
}
|
|
916
|
+
additionalRoutes.add(localizedRoute);
|
|
833
917
|
}
|
|
834
918
|
});
|
|
835
919
|
}
|
|
@@ -8,16 +8,13 @@
|
|
|
8
8
|
</template>
|
|
9
9
|
|
|
10
10
|
<script setup>
|
|
11
|
-
import { useNuxtApp, useRoute } from
|
|
12
|
-
|
|
11
|
+
import { useNuxtApp, useRoute } from "#imports";
|
|
13
12
|
const props = defineProps({
|
|
14
13
|
prefix: { type: String, required: true },
|
|
15
|
-
groupClass: { type: String, default:
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const translate = (key, params = {}) => $t(`${props.prefix}.${key}`, params)
|
|
14
|
+
groupClass: { type: String, default: "" }
|
|
15
|
+
});
|
|
16
|
+
const { $_t } = useNuxtApp();
|
|
17
|
+
const route = useRoute();
|
|
18
|
+
const $t = $_t(route);
|
|
19
|
+
const translate = (key, params = {}) => $t(`${props.prefix}.${key}`, params);
|
|
23
20
|
</script>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
2
|
+
export default _default;
|
|
3
|
+
type __VLS_WithSlots<T, S> = T & (new () => {
|
|
4
|
+
$slots: S;
|
|
5
|
+
});
|
|
6
|
+
declare const __VLS_component: import("vue").DefineComponent<{}, {
|
|
7
|
+
prefix: string;
|
|
8
|
+
groupClass: string;
|
|
9
|
+
$props: {
|
|
10
|
+
readonly prefix?: string | undefined;
|
|
11
|
+
readonly groupClass?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
14
|
+
type __VLS_Slots = {
|
|
15
|
+
default?: ((props: {
|
|
16
|
+
prefix: string;
|
|
17
|
+
t: (key: any, params?: {}) => any;
|
|
18
|
+
}) => any) | undefined;
|
|
19
|
+
};
|
|
@@ -18,57 +18,40 @@
|
|
|
18
18
|
</NuxtLink>
|
|
19
19
|
</template>
|
|
20
20
|
|
|
21
|
-
<script
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
interface Props {
|
|
30
|
-
to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string
|
|
31
|
-
activeStyle?: Partial<CSSStyleValue>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const props = defineProps<Props>()
|
|
35
|
-
const route = useRoute()
|
|
36
|
-
|
|
21
|
+
<script setup>
|
|
22
|
+
import { useNuxtApp, computed, useRoute, useRouter } from "#imports";
|
|
23
|
+
const { $localeRoute } = useNuxtApp();
|
|
24
|
+
const props = defineProps({
|
|
25
|
+
to: { type: [Object, String], required: true },
|
|
26
|
+
activeStyle: { type: Object, required: false }
|
|
27
|
+
});
|
|
28
|
+
const route = useRoute();
|
|
37
29
|
const isExternalLink = computed(() => {
|
|
38
|
-
if (typeof props.to ===
|
|
39
|
-
return /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(props.to)
|
|
30
|
+
if (typeof props.to === "string") {
|
|
31
|
+
return /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(props.to);
|
|
40
32
|
}
|
|
41
|
-
return false
|
|
42
|
-
})
|
|
43
|
-
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
44
35
|
const externalHref = computed(() => {
|
|
45
|
-
if (isExternalLink.value && typeof props.to ===
|
|
36
|
+
if (isExternalLink.value && typeof props.to === "string") {
|
|
46
37
|
if (!/^https?:\/\//.test(props.to)) {
|
|
47
|
-
return `https://${props.to}
|
|
38
|
+
return `https://${props.to}`;
|
|
48
39
|
}
|
|
49
|
-
return props.to
|
|
40
|
+
return props.to;
|
|
50
41
|
}
|
|
51
|
-
return
|
|
52
|
-
})
|
|
53
|
-
|
|
42
|
+
return void 0;
|
|
43
|
+
});
|
|
54
44
|
const isActive = computed(() => {
|
|
55
45
|
if (isExternalLink.value) {
|
|
56
|
-
return false
|
|
46
|
+
return false;
|
|
57
47
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const newPath = $localeRoute(props.to)
|
|
62
|
-
if (typeof newPath === 'string') {
|
|
63
|
-
return route.path === useRouter().resolve(newPath).path
|
|
48
|
+
const newPath = $localeRoute(props.to);
|
|
49
|
+
if (typeof newPath === "string") {
|
|
50
|
+
return route.path === useRouter().resolve(newPath).path;
|
|
64
51
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return isActive.value
|
|
71
|
-
? { ...props.activeStyle }
|
|
72
|
-
: {}
|
|
73
|
-
})
|
|
52
|
+
return route.path === newPath.path;
|
|
53
|
+
});
|
|
54
|
+
const computedStyle = computed(() => {
|
|
55
|
+
return isActive.value ? { ...props.activeStyle } : {};
|
|
56
|
+
});
|
|
74
57
|
</script>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RouteLocationNamedRaw, RouteLocationResolvedGeneric } from 'vue-router';
|
|
2
|
+
interface Props {
|
|
3
|
+
to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string;
|
|
4
|
+
activeStyle?: Partial<CSSStyleValue>;
|
|
5
|
+
}
|
|
6
|
+
declare var __VLS_1: {}, __VLS_8: {};
|
|
7
|
+
type __VLS_Slots = {} & {
|
|
8
|
+
default?: (props: typeof __VLS_1) => any;
|
|
9
|
+
} & {
|
|
10
|
+
default?: (props: typeof __VLS_8) => any;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_component: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
14
|
+
export default _default;
|
|
15
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
16
|
+
new (): {
|
|
17
|
+
$slots: S;
|
|
18
|
+
};
|
|
19
|
+
};
|