vue-i18n-routing
Advanced tools
Comparing version 0.0.0-3801eb7 to 0.0.0-3f1b961
@@ -1,5 +0,5 @@ | ||
"use strict";var W=Object.defineProperty,k=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var O=(e,t,a)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,F=(e,t)=>{for(var a in t||(t={}))y.call(t,a)&&O(e,a,t[a]);if(b)for(var a of b(t))D.call(t,a)&&O(e,a,t[a]);return e},P=(e,t)=>k(e,H(t));var V=(e,t)=>{var a={};for(var r in e)y.call(e,r)&&t.indexOf(r)<0&&(a[r]=e[r]);if(e!=null&&b)for(var r of b(e))t.indexOf(r)<0&&D.call(e,r)&&(a[r]=e[r]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var m=require("vue-demi"),A=require("@intlify/vue-router-bridge"),Y=require("@intlify/vue-i18n-bridge");function J(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var K=J(A);/*! | ||
"use strict";var Q=Object.defineProperty,Z=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var C=(e,t,a)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,P=(e,t)=>{for(var a in t||(t={}))w.call(t,a)&&C(e,a,t[a]);if(y)for(var a of y(t))z.call(t,a)&&C(e,a,t[a]);return e},O=(e,t)=>Z(e,ee(t));var X=(e,t)=>{var a={};for(var o in e)w.call(e,o)&&t.indexOf(o)<0&&(a[o]=e[o]);if(e!=null&&y)for(var o of y(e))t.indexOf(o)<0&&z.call(e,o)&&(a[o]=e[o]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var h=require("vue-demi"),D=require("@intlify/vue-router-bridge"),te=require("@intlify/vue-i18n-bridge");function ae(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var oe=ae(D);/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const U=Object.assign,T=e=>typeof e=="string",Q=e=>typeof e=="symbol";function Z(e){e=e||[];const t=[];for(const a of e)T(a)?t.push({code:a}):t.push(a);return t}function I(e,t){return m.isRef(e.locale)&&t==="composition"}function w(e){return"global"in e&&"mode"in e}function z(e){return w(e)?I(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function ee(e,t){w(e)?I(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:m.isRef(e.locale)&&(e.locale.value=t)}function te(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function ae(e={}){const t=Y.useI18n(),a=A.useRouter(),r=A.useRoute(),R=e.defaultLocaleRouteNameSuffix||a.__defaultLocaleRouteNameSuffix,g=e.defaultLocale||a.__defaultLocale,_=e.routesNameSeparator||a.__routesNameSeparator,L=e.strategy||a.__strategy;function s(o){const c=o!=null?o:m.isRef(r)?r.value:r;return c.name?C(c.name).split(_)[0]:void 0}function h(o,c){let l=C(o)+(L==="no_prefix"?"":_+c);return c===g&&L==="prefix_and_default"&&(l+=_+R),l}function n(o,c){const l=c||z(t);let f=o;T(o)&&(o[0]==="/"?f={path:o}:f={name:o});let u=U({},f);if(u.path&&!u.name){const d=a.resolve(u),v=m.isVue2?d.route:d,E=s(v);T(E)&&(u={name:h(E,l),params:v.params,query:v.query,hash:v.hash})}else{u.name=h(u.name,l);const{params:d}=u;d&&d["0"]===void 0&&d.pathMatch&&(d["0"]=d.pathMatch)}const S=a.resolve(u);return(m.isVue2?S.route.name:S.name)?S:a.resolve(o)}function p(o,c){const l=n(o,c);return l==null?"":m.isVue2?l.route.redirectedFrom||l.route.fullPath:l.redirectedFrom||l.fullPath}function x(o,c){const l=n(o,c);return l==null?void 0:m.isVue2?l.route:l}function $(o,c){const l=n(o,c);return l==null?void 0:m.isVue2?l.location:l.href}function i(o){const c=s();if(!c)return"";const v=m.isVue2&&m.isRef(r)?r.value:r,{params:l}=v,f=V(v,["params"]),u={},S=U({},f,{name:c,params:P(F(F({},l),u),{0:l.pathMatch})}),d=p(S,o);return console.log("switchLocalePath",t.locale.value,o,d),d}return{getRouteBaseName:s,localePath:p,localeRoute:x,localeLocation:$,switchLocalePath:i}}function C(e){return T(e)?e:Q(e)?e.toString():"(null)"}const oe={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},X="",M=oe.PREFIX_EXCEPT_DEFAULT,j=!1,q="___",G="default";function B(e,{defaultLocale:t=X,strategy:a=M,trailingSlash:r=j,routesNameSeparator:R=q,defaultLocaleRouteNameSuffix:g=G,includeUprefixedFallback:_=!1,locales:L=[]}={}){if(a==="no_prefix")return e;const s=L.map(n=>T(n)?n:n.code);function h(n,p,x=!1,$=!1){return n.redirect&&(!n.component||!n.file)?[n]:p.reduce((o,c)=>{const{name:l}=n;let{path:f}=n;const u=F({},n);l&&(u.name=`${l}${R}${c}`),n.children&&(u.children=n.children.reduce((E,N)=>[...E,...h(N,[c],!0,$)],[]));const S=c===t;if(S&&a==="prefix_and_default")if(x)x&&$&&l&&(u.name+=`${R}${g}`);else{const E=P(F({},u),{path:f});if(l&&(E.name=`${u.name}${R}${g}`),n.children){E.children=[];for(const N of n.children)E.children=E.children.concat(h(N,[c],!0,!0))}o.push(E)}const d=x&&!f.startsWith("/"),v=!d&&!(S&&a==="prefix_except_default");return v&&(f=`/${c}${f}`),f&&(f=te(f,r,d)),v&&S&&a==="prefix"&&_&&o.push(F({},n)),u.path=f,o.push(u),o},[])}return e.reduce((n,p)=>[...n,...h(p,s||[])],[])}function le(e,{locales:t=[]}={}){if(!I(e.global,e.mode))throw new Error("TODO:");const a=m.ref(t);e.global.locales=m.computed(()=>a.value),console.log("... extends i18n done")}function ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function re(e,t,a){const r=`(${e.join("|")})`,R=`(?:${t}${a})?`,g=new RegExp(`${t}${r}${R}$`,"i"),_=ne(e);return s=>{if(s.name){const n=(T(s.name)?s.name:s.name.toString()).match(g);if(n&&n.length>1)return n[1]}else if(s.path){const h=s.path.match(_);if(h&&h.length>1)return h[1]}return""}}function ce(e){var t,a,r,R,g,_,L,s;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:X,e.strategy=(r=e.strategy)!=null?r:M,e.trailingSlash=(R=e.trailingSlash)!=null?R:j,e.routesNameSeparator=(g=e.routesNameSeparator)!=null?g:q,e.defaultLocaleRouteNameSuffix=(_=e.defaultLocaleRouteNameSuffix)!=null?_:G,e.locales=(L=e.locales)!=null?L:[],e.routes=(s=e.routes)!=null?s:[],e}function ue(e,t={}){const{version:a,defaultLocale:r,locales:R,strategy:g,trailingSlash:_,routesNameSeparator:L,defaultLocaleRouteNameSuffix:s,routes:h}=ce(t),n=Z(R),p=n.map(o=>o.code),x=re(p,L,s);le(e,{locales:n});const $=B(h,{locales:R,defaultLocale:r,strategy:g,trailingSlash:_,routesNameSeparator:L,defaultLocaleRouteNameSuffix:s});t.routes=$;let i=null;if(m.isVue3&&a===4)i=A.createRouter(t);else if(m.isVue2&&a===3)i=new K.default(t);else throw new Error("TODO:");return i.__defaultLocale=r,i.__localeCodes=p,i.__strategy=g,i.__trailingSlash=_,i.__routesNameSeparator=L,i.__defaultLocaleRouteNameSuffix=s,i.beforeEach((o,c,l)=>{console.log("beforeEach",o,c);const f=z(e),u=x(o)||f||r||"";console.log("currentLocale",f,"finalLocale",u),f!==u&&ee(e,u),l()}),console.log("create router",i),i}const se="0.0.0";exports.VERSION=se;exports.createRouter=ue;exports.localizeRoutes=B;exports.useI18nRouting=ae; | ||
*/const M=Object.assign,I=e=>typeof e=="string",le=e=>typeof e=="symbol";function ne(e){e=e||[];const t=[];for(const a of e)I(a)?t.push({code:a}):t.push(a);return t}function V(e,t){return h.isRef(e.locale)&&t==="composition"}function j(e){return"global"in e&&"mode"in e}function q(e){return j(e)?V(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function re(e,t){j(e)?V(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:h.isRef(e.locale)&&(e.locale.value=t)}function ce(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function G(e){return I(e)?e:le(e)?e.toString():"(null)"}function B(e,t,{defaultLocale:a,strategy:o,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i}){let s=G(e)+(o==="no_prefix"?"":u+t);return t===a&&o==="prefix_and_default"&&(s+=u+i),s}function ue(e={}){var d,L,E,p,m,_,A;const t=(d=e.i18n)!=null?d:te.useI18n(),a=(L=e.router)!=null?L:D.useRouter(),o=(E=e.route)!=null?E:D.useRoute(),u=(p=e.defaultLocaleRouteNameSuffix)!=null?p:a.__defaultLocaleRouteNameSuffix,i=(m=e.defaultLocale)!=null?m:a.__defaultLocale,s=(_=e.routesNameSeparator)!=null?_:a.__routesNameSeparator,g=(A=e.strategy)!=null?A:a.__strategy;function c(r){const f=r!=null?r:h.isRef(o)?o.value:o;return f.name?G(f.name).split(s)[0]:null}function R(r,f){const n=f||q(t);let x=r;I(r)&&(r[0]==="/"?x={path:r}:x={name:r});let S=M({},x);if(S.path&&!S.name){const v=a.resolve(S),T=h.isVue2?v.route:v,U=c(T);I(U)&&(S={name:B(U,n,{defaultLocale:i,strategy:g,routesNameSeparator:s,defaultLocaleRouteNameSuffix:u}),params:T.params,query:T.query,hash:T.hash})}else{S.name=B(S.name,n,{defaultLocale:i,strategy:g,routesNameSeparator:s,defaultLocaleRouteNameSuffix:u});const{params:v}=S;v&&v["0"]===void 0&&v.pathMatch&&(v["0"]=v.pathMatch)}const N=a.resolve(S);return(h.isVue2?N.route.name:N.name)?N:a.resolve(r)}function l(r,f){const n=R(r,f);return n==null?"":h.isVue2?n.route.redirectedFrom||n.route.fullPath:n.redirectedFrom||n.fullPath}function $(r,f){const n=R(r,f);return n==null?void 0:h.isVue2?n.route:n}function F(r,f){const n=R(r,f);return n==null?void 0:h.isVue2?n.location:n}function b(r){const f=c();if(!f)return"";const T=h.isVue2&&h.isRef(o)?o.value:o,{params:n}=T,x=X(T,["params"]),S={},N=M({},x,{name:f,params:O(P(P({},n),S),{0:n.pathMatch})}),v=l(N,r);return console.log("switchLocalePath",t.locale.value,r,v),v}return{getRouteBaseName:c,localePath:l,localeRoute:$,localeLocation:F,switchLocalePath:b}}const se={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},W="",k=se.PREFIX_EXCEPT_DEFAULT,H=!1,Y="___",J="default";function K(e,{defaultLocale:t=W,strategy:a=k,trailingSlash:o=H,routesNameSeparator:u=Y,defaultLocaleRouteNameSuffix:i=J,includeUprefixedFallback:s=!1,locales:g=[]}={}){if(a==="no_prefix")return e;const c=g.map(l=>I(l)?l:l.code);function R(l,$,F=!1,b=!1){return l.redirect&&(!l.component||!l.file)?[l]:$.reduce((L,E)=>{const{name:p}=l;let{path:m}=l;const _=P({},l);p&&(_.name=`${p}${u}${E}`),l.children&&(_.children=l.children.reduce((n,x)=>[...n,...R(x,[E],!0,b)],[]));const A=E===t;if(A&&a==="prefix_and_default")if(F)F&&b&&p&&(_.name+=`${u}${i}`);else{const n=O(P({},_),{path:m});if(p&&(n.name=`${_.name}${u}${i}`),l.children){n.children=[];for(const x of l.children)n.children=n.children.concat(R(x,[E],!0,!0))}L.push(n)}const r=F&&!m.startsWith("/"),f=!r&&!(A&&a==="prefix_except_default");return f&&(m=`/${E}${m}`),m&&(m=ce(m,o,r)),f&&A&&a==="prefix"&&s&&L.push(P({},l)),_.path=m,L.push(_),L},[])}return e.reduce((l,$)=>[...l,...R($,c||[])],[])}function fe(e,{locales:t=[]}={}){if(!V(e.global,e.mode))throw new Error("TODO:");const a=h.ref(t);e.global.locales=h.computed(()=>a.value),console.log("... extends i18n done")}function ie(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function de(e,t,a){const o=`(${e.join("|")})`,u=`(?:${t}${a})?`,i=new RegExp(`${t}${o}${u}$`,"i"),s=ie(e);return c=>{if(c.name){const l=(I(c.name)?c.name:c.name.toString()).match(i);if(l&&l.length>1)return l[1]}else if(c.path){const R=c.path.match(s);if(R&&R.length>1)return R[1]}return""}}function me(e){var t,a,o,u,i,s,g,c;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:W,e.strategy=(o=e.strategy)!=null?o:k,e.trailingSlash=(u=e.trailingSlash)!=null?u:H,e.routesNameSeparator=(i=e.routesNameSeparator)!=null?i:Y,e.defaultLocaleRouteNameSuffix=(s=e.defaultLocaleRouteNameSuffix)!=null?s:J,e.locales=(g=e.locales)!=null?g:[],e.routes=(c=e.routes)!=null?c:[],e}function Re(e,t={}){const{version:a,defaultLocale:o,locales:u,strategy:i,trailingSlash:s,routesNameSeparator:g,defaultLocaleRouteNameSuffix:c,routes:R}=me(t),l=ne(u),$=l.map(L=>L.code),F=de($,g,c);fe(e,{locales:l});const b=K(R,{locales:u,defaultLocale:o,strategy:i,trailingSlash:s,routesNameSeparator:g,defaultLocaleRouteNameSuffix:c});t.routes=b;let d=null;if(h.isVue3&&a===4)d=D.createRouter(t);else if(h.isVue2&&a===3)d=new oe.default(t);else throw new Error("TODO:");return d.__defaultLocale=o,d.__localeCodes=$,d.__strategy=i,d.__trailingSlash=s,d.__routesNameSeparator=g,d.__defaultLocaleRouteNameSuffix=c,d.beforeEach((L,E,p)=>{console.log("beforeEach",L,E);const m=q(e),_=F(L)||m||o||"";console.log("currentLocale",m,"finalLocale",_),m!==_&&re(e,_),p()}),console.log("create router",d),d}const _e="0.0.0";exports.VERSION=_e;exports.createRouter=Re;exports.localizeRoutes=K;exports.useI18nRouting=ue; |
import type { I18n } from '@intlify/vue-i18n-bridge'; | ||
import { Locale } from '@intlify/vue-i18n-bridge'; | ||
import type { Location as Location_2 } from '@intlify/vue-router-bridge'; | ||
import type { RawLocation } from '@intlify/vue-router-bridge'; | ||
import type { Route as Route_2 } from '@intlify/vue-router-bridge'; | ||
import type { RouteConfig } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocation } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationRaw } from '@intlify/vue-router-bridge'; | ||
import type { Router } from '@intlify/vue-router-bridge'; | ||
import type { RouterOptions } from '@intlify/vue-router-bridge'; | ||
import { useI18n } from '@intlify/vue-i18n-bridge'; | ||
import { useRoute } from '@intlify/vue-router-bridge'; | ||
import { useRouter } from '@intlify/vue-router-bridge'; | ||
import type { VueRouter } from '@intlify/vue-router-bridge'; | ||
@@ -33,10 +40,14 @@ | ||
export declare interface I18nRouting { | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string; | ||
localePath(route: any, locale?: Locale): string; | ||
localeRoute(route: any, locale?: Locale): any; | ||
localeLocation(route: any, locale?: Locale): any; | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string | null; | ||
localePath(route: RawLocation | RouteLocationRaw, locale?: Locale): string; | ||
localeRoute(route: RawLocation | RouteLocationRaw, locale?: Locale): Route_2 | ReturnType<Router['resolve']>; | ||
localeLocation(route: RawLocation | RouteLocationRaw, locale?: Locale): Location_2 | RouteLocation; | ||
switchLocalePath(locale: Locale): void; | ||
} | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'>; | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'> & { | ||
route?: ReturnType<typeof useRoute>; | ||
router?: ReturnType<typeof useRouter>; | ||
i18n?: ReturnType<typeof useI18n>; | ||
}; | ||
@@ -43,0 +54,0 @@ /** |
@@ -78,14 +78,30 @@ var __defProp = Object.defineProperty; | ||
} | ||
function getRouteName(routeName) { | ||
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)"; | ||
} | ||
function getLocaleRouteName(routeName, locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}) { | ||
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale); | ||
if (locale === defaultLocale && strategy === "prefix_and_default") { | ||
name += routesNameSeparator + defaultLocaleRouteNameSuffix; | ||
} | ||
return name; | ||
} | ||
function useI18nRouting(options = {}) { | ||
const $i18n = useI18n(); | ||
const $router = useRouter(); | ||
const $route = useRoute(); | ||
const defaultLocaleRouteNameSuffix = options.defaultLocaleRouteNameSuffix || $router.__defaultLocaleRouteNameSuffix; | ||
const defaultLocale = options.defaultLocale || $router.__defaultLocale; | ||
const routesNameSeparator = options.routesNameSeparator || $router.__routesNameSeparator; | ||
const strategy = options.strategy || $router.__strategy; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const $i18n = (_a = options.i18n) != null ? _a : useI18n(); | ||
const $router = (_b = options.router) != null ? _b : useRouter(); | ||
const $route = (_c = options.route) != null ? _c : useRoute(); | ||
const defaultLocaleRouteNameSuffix = (_d = options.defaultLocaleRouteNameSuffix) != null ? _d : $router.__defaultLocaleRouteNameSuffix; | ||
const defaultLocale = (_e = options.defaultLocale) != null ? _e : $router.__defaultLocale; | ||
const routesNameSeparator = (_f = options.routesNameSeparator) != null ? _f : $router.__routesNameSeparator; | ||
const strategy = (_g = options.strategy) != null ? _g : $router.__strategy; | ||
function getRouteBaseName(givenRoute) { | ||
const route = givenRoute != null ? givenRoute : isRef($route) ? $route.value : $route; | ||
if (!route.name) { | ||
return; | ||
return null; | ||
} | ||
@@ -95,9 +111,2 @@ const name = getRouteName(route.name); | ||
} | ||
function getLocaleRouteName(routeName, locale) { | ||
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale); | ||
if (locale === defaultLocale && strategy === "prefix_and_default") { | ||
name += routesNameSeparator + defaultLocaleRouteNameSuffix; | ||
} | ||
return name; | ||
} | ||
function resolveRoute(route, locale) { | ||
@@ -120,3 +129,8 @@ const _locale = locale || getLocale($i18n); | ||
localizedRoute = { | ||
name: getLocaleRouteName(resolvedRouteName, _locale), | ||
name: getLocaleRouteName(resolvedRouteName, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}), | ||
params: resolvedRoute2.params, | ||
@@ -128,3 +142,8 @@ query: resolvedRoute2.query, | ||
} else { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale); | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
const { params } = localizedRoute; | ||
@@ -151,3 +170,3 @@ if (params && params["0"] === void 0 && params.pathMatch) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved.href; | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved; | ||
} | ||
@@ -159,3 +178,3 @@ function switchLocalePath(locale) { | ||
} | ||
const _a = isVue2 && isRef($route) ? $route.value : $route, { params } = _a, routeCopy = __objRest(_a, ["params"]); | ||
const _a2 = isVue2 && isRef($route) ? $route.value : $route, { params } = _a2, routeCopy = __objRest(_a2, ["params"]); | ||
const langSwitchParams = {}; | ||
@@ -180,5 +199,2 @@ const baseRoute = assign({}, routeCopy, { | ||
} | ||
function getRouteName(routeName) { | ||
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)"; | ||
} | ||
const STRATEGIES = { | ||
@@ -185,0 +201,0 @@ PREFIX: "prefix", |
@@ -1,5 +0,5 @@ | ||
var ue=Object.defineProperty,se=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var k=(r,t,f)=>t in r?ue(r,t,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[t]=f,P=(r,t)=>{for(var f in t||(t={}))D.call(t,f)&&k(r,f,t[f]);if(b)for(var f of b(t))W.call(t,f)&&k(r,f,t[f]);return r},v=(r,t)=>se(r,fe(t));var B=(r,t)=>{var f={};for(var p in r)D.call(r,p)&&t.indexOf(p)<0&&(f[p]=r[p]);if(r!=null&&b)for(var p of b(r))t.indexOf(p)<0&&W.call(r,p)&&(f[p]=r[p]);return f};var VueI18nRouting=function(r,t,f,p){"use strict";function H(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var Y=H(f);/*! | ||
var he=Object.defineProperty,Re=Object.defineProperties;var me=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var Q=(c,a,s)=>a in c?he(c,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):c[a]=s,y=(c,a)=>{for(var s in a||(a={}))J.call(a,s)&&Q(c,s,a[s]);if(U)for(var s of U(a))K.call(a,s)&&Q(c,s,a[s]);return c},z=(c,a)=>Re(c,me(a));var Z=(c,a)=>{var s={};for(var p in c)J.call(c,p)&&a.indexOf(p)<0&&(s[p]=c[p]);if(c!=null&&U)for(var p of U(c))a.indexOf(p)<0&&K.call(c,p)&&(s[p]=c[p]);return s};var VueI18nRouting=function(c,a,s,p){"use strict";function ee(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var te=ee(s);/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const V=Object.assign,I=e=>typeof e=="string",J=e=>typeof e=="symbol";function K(e){e=e||[];const l=[];for(const c of e)I(c)?l.push({code:c}):l.push(c);return l}function y(e,l){return t.isRef(e.locale)&&l==="composition"}function U(e){return"global"in e&&"mode"in e}function w(e){return U(e)?y(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Q(e,l){U(e)?y(e.global,e.mode)?e.global.locale.value=l:e.global.locale=l:t.isRef(e.locale)&&(e.locale.value=l)}function Z(e,l,c){return e.replace(/\/+$/,"")+(l?"/":"")||(c?"":"/")}function ee(e={}){const l=p.useI18n(),c=f.useRouter(),_=f.useRoute(),m=e.defaultLocaleRouteNameSuffix||c.__defaultLocaleRouteNameSuffix,E=e.defaultLocale||c.__defaultLocale,g=e.routesNameSeparator||c.__routesNameSeparator,S=e.strategy||c.__strategy;function i(a){const u=a!=null?a:t.isRef(_)?_.value:_;return u.name?z(u.name).split(g)[0]:void 0}function L(a,u){let o=z(a)+(S==="no_prefix"?"":g+u);return u===E&&S==="prefix_and_default"&&(o+=g+m),o}function n(a,u){const o=u||w(l);let d=a;I(a)&&(a[0]==="/"?d={path:a}:d={name:a});let s=V({},d);if(s.path&&!s.name){const R=c.resolve(s),$=t.isVue2?R.route:R,F=i($);I(F)&&(s={name:L(F,o),params:$.params,query:$.query,hash:$.hash})}else{s.name=L(s.name,o);const{params:R}=s;R&&R["0"]===void 0&&R.pathMatch&&(R["0"]=R.pathMatch)}const x=c.resolve(s);return(t.isVue2?x.route.name:x.name)?x:c.resolve(a)}function T(a,u){const o=n(a,u);return o==null?"":t.isVue2?o.route.redirectedFrom||o.route.fullPath:o.redirectedFrom||o.fullPath}function A(a,u){const o=n(a,u);return o==null?void 0:t.isVue2?o.route:o}function N(a,u){const o=n(a,u);return o==null?void 0:t.isVue2?o.location:o.href}function h(a){const u=i();if(!u)return"";const $=t.isVue2&&t.isRef(_)?_.value:_,{params:o}=$,d=B($,["params"]),s={},x=V({},d,{name:u,params:v(P(P({},o),s),{0:o.pathMatch})}),R=T(x,a);return console.log("switchLocalePath",l.locale.value,a,R),R}return{getRouteBaseName:i,localePath:T,localeRoute:A,localeLocation:N,switchLocalePath:h}}function z(e){return I(e)?e:J(e)?e.toString():"(null)"}const te={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},C="",X=te.PREFIX_EXCEPT_DEFAULT,M=!1,j="___",G="default";function q(e,{defaultLocale:l=C,strategy:c=X,trailingSlash:_=M,routesNameSeparator:m=j,defaultLocaleRouteNameSuffix:E=G,includeUprefixedFallback:g=!1,locales:S=[]}={}){if(c==="no_prefix")return e;const i=S.map(n=>I(n)?n:n.code);function L(n,T,A=!1,N=!1){return n.redirect&&(!n.component||!n.file)?[n]:T.reduce((a,u)=>{const{name:o}=n;let{path:d}=n;const s=P({},n);o&&(s.name=`${o}${m}${u}`),n.children&&(s.children=n.children.reduce((F,O)=>[...F,...L(O,[u],!0,N)],[]));const x=u===l;if(x&&c==="prefix_and_default")if(A)A&&N&&o&&(s.name+=`${m}${E}`);else{const F=v(P({},s),{path:d});if(o&&(F.name=`${s.name}${m}${E}`),n.children){F.children=[];for(const O of n.children)F.children=F.children.concat(L(O,[u],!0,!0))}a.push(F)}const R=A&&!d.startsWith("/"),$=!R&&!(x&&c==="prefix_except_default");return $&&(d=`/${u}${d}`),d&&(d=Z(d,_,R)),$&&x&&c==="prefix"&&g&&a.push(P({},n)),s.path=d,a.push(s),a},[])}return e.reduce((n,T)=>[...n,...L(T,i||[])],[])}function ae(e,{locales:l=[]}={}){if(!y(e.global,e.mode))throw new Error("TODO:");const c=t.ref(l);e.global.locales=t.computed(()=>c.value),console.log("... extends i18n done")}function oe(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function le(e,l,c){const _=`(${e.join("|")})`,m=`(?:${l}${c})?`,E=new RegExp(`${l}${_}${m}$`,"i"),g=oe(e);return i=>{if(i.name){const n=(I(i.name)?i.name:i.name.toString()).match(E);if(n&&n.length>1)return n[1]}else if(i.path){const L=i.path.match(g);if(L&&L.length>1)return L[1]}return""}}function ne(e){var l,c,_,m,E,g,S,i;return e.version=(l=e.version)!=null?l:4,e.defaultLocale=(c=e.defaultLocale)!=null?c:C,e.strategy=(_=e.strategy)!=null?_:X,e.trailingSlash=(m=e.trailingSlash)!=null?m:M,e.routesNameSeparator=(E=e.routesNameSeparator)!=null?E:j,e.defaultLocaleRouteNameSuffix=(g=e.defaultLocaleRouteNameSuffix)!=null?g:G,e.locales=(S=e.locales)!=null?S:[],e.routes=(i=e.routes)!=null?i:[],e}function ce(e,l={}){const{version:c,defaultLocale:_,locales:m,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:i,routes:L}=ne(l),n=K(m),T=n.map(a=>a.code),A=le(T,S,i);ae(e,{locales:n});const N=q(L,{locales:m,defaultLocale:_,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:i});l.routes=N;let h=null;if(t.isVue3&&c===4)h=f.createRouter(l);else if(t.isVue2&&c===3)h=new Y.default(l);else throw new Error("TODO:");return h.__defaultLocale=_,h.__localeCodes=T,h.__strategy=E,h.__trailingSlash=g,h.__routesNameSeparator=S,h.__defaultLocaleRouteNameSuffix=i,h.beforeEach((a,u,o)=>{console.log("beforeEach",a,u);const d=w(e),s=A(a)||d||_||"";console.log("currentLocale",d,"finalLocale",s),d!==s&&Q(e,s),o()}),console.log("create router",h),h}const re="0.0.0";return r.VERSION=re,r.createRouter=ce,r.localizeRoutes=q,r.useI18nRouting=ee,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module",r}({},VueDemi,VueRouter,VueI18n); | ||
*/const C=Object.assign,b=e=>typeof e=="string",ae=e=>typeof e=="symbol";function oe(e){e=e||[];const t=[];for(const o of e)b(o)?t.push({code:o}):t.push(o);return t}function w(e,t){return a.isRef(e.locale)&&t==="composition"}function X(e){return"global"in e&&"mode"in e}function M(e){return X(e)?w(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function le(e,t){X(e)?w(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:a.isRef(e.locale)&&(e.locale.value=t)}function ne(e,t,o){return e.replace(/\/+$/,"")+(t?"/":"")||(o?"":"/")}function j(e){return b(e)?e:ae(e)?e.toString():"(null)"}function G(e,t,{defaultLocale:o,strategy:u,routesNameSeparator:i,defaultLocaleRouteNameSuffix:h}){let d=j(e)+(u==="no_prefix"?"":i+t);return t===o&&u==="prefix_and_default"&&(d+=i+h),d}function ce(e={}){var R,S,F,x,m,L,v;const t=(R=e.i18n)!=null?R:p.useI18n(),o=(S=e.router)!=null?S:s.useRouter(),u=(F=e.route)!=null?F:s.useRoute(),i=(x=e.defaultLocaleRouteNameSuffix)!=null?x:o.__defaultLocaleRouteNameSuffix,h=(m=e.defaultLocale)!=null?m:o.__defaultLocale,d=(L=e.routesNameSeparator)!=null?L:o.__routesNameSeparator,E=(v=e.strategy)!=null?v:o.__strategy;function f(r){const _=r!=null?r:a.isRef(u)?u.value:u;return _.name?j(_.name).split(d)[0]:null}function g(r,_){const n=_||M(t);let A=r;b(r)&&(r[0]==="/"?A={path:r}:A={name:r});let T=C({},A);if(T.path&&!T.name){const $=o.resolve(T),N=a.isVue2?$.route:$,Y=f(N);b(Y)&&(T={name:G(Y,n,{defaultLocale:h,strategy:E,routesNameSeparator:d,defaultLocaleRouteNameSuffix:i}),params:N.params,query:N.query,hash:N.hash})}else{T.name=G(T.name,n,{defaultLocale:h,strategy:E,routesNameSeparator:d,defaultLocaleRouteNameSuffix:i});const{params:$}=T;$&&$["0"]===void 0&&$.pathMatch&&($["0"]=$.pathMatch)}const V=o.resolve(T);return(a.isVue2?V.route.name:V.name)?V:o.resolve(r)}function l(r,_){const n=g(r,_);return n==null?"":a.isVue2?n.route.redirectedFrom||n.route.fullPath:n.redirectedFrom||n.fullPath}function I(r,_){const n=g(r,_);return n==null?void 0:a.isVue2?n.route:n}function P(r,_){const n=g(r,_);return n==null?void 0:a.isVue2?n.location:n}function O(r){const _=f();if(!_)return"";const N=a.isVue2&&a.isRef(u)?u.value:u,{params:n}=N,A=Z(N,["params"]),T={},V=C({},A,{name:_,params:z(y(y({},n),T),{0:n.pathMatch})}),$=l(V,r);return console.log("switchLocalePath",t.locale.value,r,$),$}return{getRouteBaseName:f,localePath:l,localeRoute:I,localeLocation:P,switchLocalePath:O}}const re={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},q="",D=re.PREFIX_EXCEPT_DEFAULT,W=!1,k="___",B="default";function H(e,{defaultLocale:t=q,strategy:o=D,trailingSlash:u=W,routesNameSeparator:i=k,defaultLocaleRouteNameSuffix:h=B,includeUprefixedFallback:d=!1,locales:E=[]}={}){if(o==="no_prefix")return e;const f=E.map(l=>b(l)?l:l.code);function g(l,I,P=!1,O=!1){return l.redirect&&(!l.component||!l.file)?[l]:I.reduce((S,F)=>{const{name:x}=l;let{path:m}=l;const L=y({},l);x&&(L.name=`${x}${i}${F}`),l.children&&(L.children=l.children.reduce((n,A)=>[...n,...g(A,[F],!0,O)],[]));const v=F===t;if(v&&o==="prefix_and_default")if(P)P&&O&&x&&(L.name+=`${i}${h}`);else{const n=z(y({},L),{path:m});if(x&&(n.name=`${L.name}${i}${h}`),l.children){n.children=[];for(const A of l.children)n.children=n.children.concat(g(A,[F],!0,!0))}S.push(n)}const r=P&&!m.startsWith("/"),_=!r&&!(v&&o==="prefix_except_default");return _&&(m=`/${F}${m}`),m&&(m=ne(m,u,r)),_&&v&&o==="prefix"&&d&&S.push(y({},l)),L.path=m,S.push(L),S},[])}return e.reduce((l,I)=>[...l,...g(I,f||[])],[])}function ue(e,{locales:t=[]}={}){if(!w(e.global,e.mode))throw new Error("TODO:");const o=a.ref(t);e.global.locales=a.computed(()=>o.value),console.log("... extends i18n done")}function se(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function fe(e,t,o){const u=`(${e.join("|")})`,i=`(?:${t}${o})?`,h=new RegExp(`${t}${u}${i}$`,"i"),d=se(e);return f=>{if(f.name){const l=(b(f.name)?f.name:f.name.toString()).match(h);if(l&&l.length>1)return l[1]}else if(f.path){const g=f.path.match(d);if(g&&g.length>1)return g[1]}return""}}function ie(e){var t,o,u,i,h,d,E,f;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(o=e.defaultLocale)!=null?o:q,e.strategy=(u=e.strategy)!=null?u:D,e.trailingSlash=(i=e.trailingSlash)!=null?i:W,e.routesNameSeparator=(h=e.routesNameSeparator)!=null?h:k,e.defaultLocaleRouteNameSuffix=(d=e.defaultLocaleRouteNameSuffix)!=null?d:B,e.locales=(E=e.locales)!=null?E:[],e.routes=(f=e.routes)!=null?f:[],e}function de(e,t={}){const{version:o,defaultLocale:u,locales:i,strategy:h,trailingSlash:d,routesNameSeparator:E,defaultLocaleRouteNameSuffix:f,routes:g}=ie(t),l=oe(i),I=l.map(S=>S.code),P=fe(I,E,f);ue(e,{locales:l});const O=H(g,{locales:i,defaultLocale:u,strategy:h,trailingSlash:d,routesNameSeparator:E,defaultLocaleRouteNameSuffix:f});t.routes=O;let R=null;if(a.isVue3&&o===4)R=s.createRouter(t);else if(a.isVue2&&o===3)R=new te.default(t);else throw new Error("TODO:");return R.__defaultLocale=u,R.__localeCodes=I,R.__strategy=h,R.__trailingSlash=d,R.__routesNameSeparator=E,R.__defaultLocaleRouteNameSuffix=f,R.beforeEach((S,F,x)=>{console.log("beforeEach",S,F);const m=M(e),L=P(S)||m||u||"";console.log("currentLocale",m,"finalLocale",L),m!==L&&le(e,L),x()}),console.log("create router",R),R}const _e="0.0.0";return c.VERSION=_e,c.createRouter=de,c.localizeRoutes=H,c.useI18nRouting=ce,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module",c}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-3801eb7", | ||
"version": "0.0.0-3f1b961", | ||
"dependencies": { | ||
@@ -6,0 +6,0 @@ "@intlify/shared": "beta", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38089
613
0