@atoms-studio/composables
Advanced tools
Comparing version 0.0.0-6bbbfdc to 0.0.0-a11ca3e
@@ -1,18 +0,2 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
import { computed, inject } from "vue"; | ||
import { computed } from "vue"; | ||
const useURL = (to, base) => { | ||
@@ -48,74 +32,2 @@ if (!base) { | ||
}; | ||
/*! | ||
* vue-router v4.0.13 | ||
* (c) 2022 Eduardo San Martin Morote | ||
* @license MIT | ||
*/ | ||
const hasSymbol = typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol"; | ||
const PolySymbol = (name) => hasSymbol ? Symbol(name) : "_vr_" + name; | ||
const routerKey = /* @__PURE__ */ PolySymbol("r"); | ||
const routeLocationKey = /* @__PURE__ */ PolySymbol("rl"); | ||
var NavigationType; | ||
(function(NavigationType2) { | ||
NavigationType2["pop"] = "pop"; | ||
NavigationType2["push"] = "push"; | ||
})(NavigationType || (NavigationType = {})); | ||
var NavigationDirection; | ||
(function(NavigationDirection2) { | ||
NavigationDirection2["back"] = "back"; | ||
NavigationDirection2["forward"] = "forward"; | ||
NavigationDirection2["unknown"] = ""; | ||
})(NavigationDirection || (NavigationDirection = {})); | ||
var NavigationFailureType; | ||
(function(NavigationFailureType2) { | ||
NavigationFailureType2[NavigationFailureType2["aborted"] = 4] = "aborted"; | ||
NavigationFailureType2[NavigationFailureType2["cancelled"] = 8] = "cancelled"; | ||
NavigationFailureType2[NavigationFailureType2["duplicated"] = 16] = "duplicated"; | ||
})(NavigationFailureType || (NavigationFailureType = {})); | ||
function useRouter() { | ||
return inject(routerKey); | ||
} | ||
function useRoute() { | ||
return inject(routeLocationKey); | ||
} | ||
const useRouteState = (configOrKeys) => { | ||
const route = useRoute(); | ||
const router = useRouter(); | ||
let config; | ||
if (Array.isArray(configOrKeys)) { | ||
config = configOrKeys.reduce((acc, key) => { | ||
acc[key] = { | ||
get: (value) => value, | ||
set: (value) => value | ||
}; | ||
return acc; | ||
}, {}); | ||
} else { | ||
config = configOrKeys; | ||
} | ||
const stateKeys = Object.keys(config); | ||
const state = computed(() => { | ||
const result = {}; | ||
for (const stateKey of stateKeys) { | ||
const queryValue = route.query[stateKey]; | ||
const stateValue = config[stateKey].get(queryValue); | ||
result[stateKey] = stateValue; | ||
} | ||
return result; | ||
}); | ||
const updateState = (partialState) => { | ||
const newState = __spreadValues(__spreadValues({}, state.value), partialState); | ||
const newQuery = {}; | ||
for (const stateKey of stateKeys) { | ||
const stateValue = newState[stateKey]; | ||
const queryValue = config[stateKey].set(stateValue); | ||
newQuery[stateKey] = queryValue; | ||
} | ||
return router.replace({ query: __spreadValues(__spreadValues({}, route.query), newQuery) }); | ||
}; | ||
return { | ||
state, | ||
updateState | ||
}; | ||
}; | ||
export { useRouteState, useURL }; | ||
export { useURL }; |
@@ -1,5 +0,1 @@ | ||
var M=Object.defineProperty;var w=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;var q=(o,t,u)=>t in o?M(o,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):o[t]=u,i=(o,t)=>{for(var u in t||(t={}))U.call(t,u)&&q(o,u,t[u]);if(w)for(var u of w(t))g.call(t,u)&&q(o,u,t[u]);return o};(function(o,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(o=typeof globalThis!="undefined"?globalThis:o||self,t(o.MyLib={},o.Vue))})(this,function(o,t){"use strict";const u=(e,l)=>{if(!l)throw new Error("Base is required");const a=t.computed(()=>e.value==="#"),r=t.computed(()=>typeof e.value=="string"?new URL(e.value,l):null),d=t.computed(()=>{var n;return((n=r.value)==null?void 0:n.origin)||""}),y=t.computed(()=>{var n;return a.value?"#":((n=r.value)==null?void 0:n.pathname)||""}),h=t.computed(()=>a.value||r.value!==null&&d.value!==l);return{url:r,origin:d,path:y,isExternal:h,isDummy:a}};/*! | ||
* vue-router v4.0.13 | ||
* (c) 2022 Eduardo San Martin Morote | ||
* @license MIT | ||
*/const R=typeof Symbol=="function"&&typeof Symbol.toStringTag=="symbol",p=e=>R?Symbol(e):"_vr_"+e,j=p("r"),v=p("rl");var m;(function(e){e.pop="pop",e.push="push"})(m||(m={}));var S;(function(e){e.back="back",e.forward="forward",e.unknown=""})(S||(S={}));var b;(function(e){e[e.aborted=4]="aborted",e[e.cancelled=8]="cancelled",e[e.duplicated=16]="duplicated"})(b||(b={}));function L(){return t.inject(j)}function V(){return t.inject(v)}const k=e=>{const l=V(),a=L();let r;Array.isArray(e)?r=e.reduce((n,c)=>(n[c]={get:s=>s,set:s=>s},n),{}):r=e;const d=Object.keys(r),y=t.computed(()=>{const n={};for(const c of d){const s=l.query[c],f=r[c].get(s);n[c]=f}return n});return{state:y,updateState:n=>{const c=i(i({},y.value),n),s={};for(const f of d){const _=c[f],K=r[f].set(_);s[f]=K}return a.replace({query:i(i({},l.query),s)})}}};o.useRouteState=k,o.useURL=u,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"}); | ||
(function(u,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(u=typeof globalThis!="undefined"?globalThis:u||self,e(u.MyLib={},u.Vue))})(this,function(u,e){"use strict";const s=(i,o)=>{if(!o)throw new Error("Base is required");const r=e.computed(()=>i.value==="#"),t=e.computed(()=>typeof i.value=="string"?new URL(i.value,o):null),l=e.computed(()=>{var n;return((n=t.value)==null?void 0:n.origin)||""}),d=e.computed(()=>{var n;return r.value?"#":((n=t.value)==null?void 0:n.pathname)||""}),c=e.computed(()=>r.value||t.value!==null&&l.value!==o);return{url:t,origin:l,path:d,isExternal:c,isDummy:r}};u.useURL=s,Object.defineProperty(u,"__esModule",{value:!0}),u[Symbol.toStringTag]="Module"}); |
export { useURL } from './useURL'; | ||
export { useRouteState } from './useRouteState'; |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.0-6bbbfdc", | ||
"version": "0.0.0-a11ca3e", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "files": [ |
3817
6
45