@vueuse/integrations
Version:
Integration wrappers for utility libraries
2 lines (1 loc) • 9.36 kB
JavaScript
(function(y,V,U,n,L,$,k,g,K,X,Y,P,Z,E,x,ee){"use strict";function te(t){var o=Object.create(null);return t&&Object.keys(t).forEach(function(e){if(e!=="default"){var a=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(o,e,a.get?a:{enumerable:!0,get:function(){return t[e]}})}}),o.default=t,Object.freeze(o)}var ne=te($);const ae=U.default||U;function oe(t,o,e={}){const{validateOption:a={},immediate:r=!0,manual:u=!1}=e,l=V.toRef(t),c=n.shallowRef(null),s=n.shallowRef(!0),h=n.shallowRef(!r||u),d=n.computed(()=>{var v;return((v=c.value)==null?void 0:v.errors)||[]}),C=n.computed(()=>{var v;return((v=c.value)==null?void 0:v.fields)||{}}),m=n.computed(()=>new ae(n.toValue(o))),p=async()=>{s.value=!1,h.value=!1;try{await m.value.validate(l.value,a),h.value=!0,c.value=null}catch(v){c.value=v}finally{s.value=!0}return{pass:h.value,errorInfo:c.value,errors:d.value,errorFields:C.value}};u||n.watch([l,m],()=>p(),{immediate:r,deep:!0});const R={isFinished:s,pass:h,errors:d,errorInfo:c,errorFields:C,execute:p};function A(){return new Promise((v,f)=>{V.until(s).toBe(!0).then(()=>v(R)).catch(b=>f(b))})}return{...R,then(v,f){return A().then(v,f)}}}function le(...t){const o=typeof t[0]=="string"?t[0]:void 0,e=typeof o=="string"?1:0,a={immediate:!!e,shallow:!0,abortPrevious:!0};let r={},u=L,l=a;const c=w=>!!w?.request;t.length>0+e&&(c(t[0+e])?u=t[0+e]:r=t[0+e]),t.length>1+e&&c(t[1+e])&&(u=t[1+e]),(t.length===2+e&&!c(t[1+e])||t.length===3+e)&&(l=t[t.length-1]||a);const{shallow:s,onSuccess:h=V.noop,onError:d=V.noop,immediate:C,resetOnExecute:m=!1}=l,p=l.initialData,R=n.shallowRef(),A=(s?n.shallowRef:n.ref)(p),v=n.shallowRef(!1),f=n.shallowRef(!1),b=n.shallowRef(!1),D=n.shallowRef();let S=new AbortController;const F=w=>{v.value||!f.value||(S.abort(w),S=new AbortController,b.value=!0,f.value=!1,v.value=!1)},i=w=>{f.value=w,v.value=!w},_=()=>{m&&(A.value=p)},G=()=>new Promise((w,I)=>{V.until(v).toBe(!0).then(()=>D.value?I(D.value):w(q))}),H={then:(...w)=>G().then(...w),catch:(...w)=>G().catch(...w)};let j=0;const Q=(w=o,I={})=>{D.value=void 0;const J=typeof w=="string"?w:o??I.url;if(J===void 0)return D.value=new L.AxiosError(L.AxiosError.ERR_INVALID_URL),v.value=!0,H;_(),l.abortPrevious!==!1&&F(),i(!0),j+=1;const pe=j;return b.value=!1,u(J,{...r,...typeof w=="object"?w:I,signal:S.signal}).then(O=>{if(b.value)return;R.value=O;const M=O.data;A.value=M,h(M)}).catch(O=>{D.value=O,d(O)}).finally(()=>{var O;(O=l.onFinish)==null||O.call(l),pe===j&&i(!1)}),H};C&&o&&Q();const q={response:R,data:A,error:D,isFinished:v,isLoading:f,cancel:F,isAborted:b,isCanceled:b,abort:F,execute:Q};return{...q,...H}}const N=Object.entries(ne).filter(([t,o])=>typeof o=="function"&&t.endsWith("Case")).reduce((t,[o,e])=>(t[o]=e,t),{});function re(t,o,e){const a=n.computed(()=>{const u=n.toValue(o);if(!N[u])throw new Error(`Invalid change case type "${u}"`);return u});if(typeof t=="function")return n.computed(()=>N[a.value](n.toValue(t),n.toValue(e)));const r=n.ref(t);return n.computed({get(){return N[a.value](r.value,n.toValue(e))},set(u){r.value=u}})}function se(t){const o=new k(t?t.headers.cookie:null);return(e,{doNotParse:a=!1,autoUpdateDependencies:r=!1}={})=>T(e,{doNotParse:a,autoUpdateDependencies:r},o)}function T(t,{doNotParse:o=!1,autoUpdateDependencies:e=!1}={},a=new k){const r=e?[...t||[]]:t;let u=a.getAll({doNotParse:!0});const l=n.shallowRef(0),c=()=>{const s=a.getAll({doNotParse:!0});ue(r||null,s,u)&&l.value++,u=s};return a.addChangeListener(c),V.tryOnScopeDispose(()=>{a.removeChangeListener(c)}),{get:(...s)=>(e&&r&&!r.includes(s[0])&&r.push(s[0]),l.value,a.get(s[0],{doNotParse:o,...s[1]})),getAll:(...s)=>(l.value,a.getAll({doNotParse:o,...s[0]})),set:(...s)=>a.set(...s),remove:(...s)=>a.remove(...s),addChangeListener:(...s)=>a.addChangeListener(...s),removeChangeListener:(...s)=>a.removeChangeListener(...s)}}function ue(t,o,e){if(!t)return!0;for(const a of t)if(o[a]!==e[a])return!0;return!1}function ce(t,o){const e=n.ref();let a=[];const r=g.createEventHook(),u=g.createEventHook(),l=g.createEventHook(),c=g.createEventHook(),s=g.createEventHook(),h=n.shallowRef(!1),d=n.shallowRef(!1),C=n.shallowRef(!1),m=n.shallowRef(!1),p=n.ref({color:"black",size:3,arrowEnd:!1,cornerRadius:0,dasharray:void 0,fill:"transparent",mode:"draw",...o?.brush});n.watch(p,()=>{const i=e.value;i&&(i.brush=p.value,i.mode=p.value.mode)},{deep:!0});const R=()=>{var i;return(i=e.value)==null?void 0:i.undo()},A=()=>{var i;return(i=e.value)==null?void 0:i.redo()},v=()=>{var i;return(i=e.value)==null?void 0:i.clear()},f=()=>{var i;return(i=e.value)==null?void 0:i.cancel()},b=i=>{var _;return(_=e.value)==null?void 0:_.load(i)},D=()=>{var i;return(i=e.value)==null?void 0:i.dump()},S=()=>{var i;a.forEach(_=>_()),(i=e.value)==null||i.unmount()},F=()=>{e.value&&(h.value=e.value.canUndo(),d.value=e.value.canRedo(),C.value=e.value.altPressed,m.value=e.value.shiftPressed)};return n.watch(()=>g.unrefElement(t),i=>{!i||typeof SVGSVGElement>"u"||!(i instanceof SVGSVGElement)||(e.value&&S(),e.value=K.createDrauu({el:i,...o}),F(),a=[e.value.on("canceled",()=>u.trigger()),e.value.on("committed",_=>l.trigger(_)),e.value.on("start",()=>c.trigger()),e.value.on("end",()=>s.trigger()),e.value.on("changed",()=>{F(),r.trigger()})])},{flush:"post"}),V.tryOnScopeDispose(()=>S()),{drauuInstance:e,load:b,dump:D,clear:v,cancel:f,undo:R,redo:A,canUndo:h,canRedo:d,brush:p,onChanged:r.on,onCommitted:l.on,onStart:c.on,onEnd:s.on,onCanceled:u.on}}function ie(t,o={}){let e;const{immediate:a,...r}=o,u=n.shallowRef(!1),l=n.shallowRef(!1),c=m=>e&&e.activate(m),s=m=>e&&e.deactivate(m),h=()=>{e&&(e.pause(),l.value=!0)},d=()=>{e&&(e.unpause(),l.value=!1)},C=n.computed(()=>{const m=n.toValue(t);return g.toArray(m).map(p=>{const R=n.toValue(p);return typeof R=="string"?R:g.unrefElement(R)}).filter(V.notNullish)});return n.watch(C,m=>{if(m.length)if(!e)e=X.createFocusTrap(m,{...r,onActivate(){u.value=!0,o.onActivate&&o.onActivate()},onDeactivate(){u.value=!1,o.onDeactivate&&o.onDeactivate()}}),a&&c();else{const p=e?.active;e?.updateContainerElements(m),!p&&a&&c()}},{flush:"post"}),g.tryOnScopeDispose(()=>s()),{hasFocus:u,isPaused:l,activate:c,deactivate:s,pause:h,unpause:d}}function fe(t,o,e){const a=()=>{var l,c;return new Y((l=n.toValue(o))!=null?l:[],(c=n.toValue(e))==null?void 0:c.fuseOptions)},r=n.ref(a());n.watch(()=>{var l;return(l=n.toValue(e))==null?void 0:l.fuseOptions},()=>{r.value=a()},{deep:!0}),n.watch(()=>n.toValue(o),l=>{r.value.setCollection(l)},{deep:!0});const u=n.computed(()=>{const l=n.toValue(e);if(l?.matchAllWhenSearchEmpty&&!n.toValue(t))return n.toValue(o).map((s,h)=>({item:s,refIndex:h}));const c=l?.resultLimit;return r.value.search(n.toValue(t),c?{limit:c}:void 0)});return{fuse:r,results:u}}function de(t,o,e={}){const{flush:a="pre",deep:r=!0,shallow:u=!1,onError:l=f=>{console.error(f)},writeDefaults:c=!0,serializer:s={read:f=>f,write:f=>f}}=e,h=n.shallowRef(!1),d=(u?n.shallowRef:n.ref)(o),C=n.toValue(o);async function m(){try{const f=await P.get(t);if(f===void 0){if(C!=null&&c){const b=s.write(C);await P.set(t,b)}}else d.value=s.read(f)}catch(f){l(f)}h.value=!0}m();async function p(){try{if(d.value==null)await P.del(t);else{const f=n.toRaw(d.value),b=s.write(f);await P.update(t,()=>b)}}catch(f){l(f)}}const{pause:R,resume:A}=g.watchPausable(d,()=>p(),{flush:a,deep:r});async function v(f){R(),d.value=f,await p(),A()}return{set:v,isFinished:h,data:d}}function ve(t,o={}){const{onError:e,fallbackValue:a=null}=o,r=(c,s)=>{try{return Z.jwtDecode(c,s)}catch(h){return e?.(h),a}},u=n.computed(()=>r(n.toValue(t),{header:!0})),l=n.computed(()=>r(n.toValue(t)));return{header:u,payload:l}}function he(t=null,o){const e=V.toRef(t),a=n.computed({set:u=>u?E.start():E.done(),get:()=>typeof e.value=="number"&&e.value<1});o&&E.configure(o);const r=E.set;return E.set=u=>(e.value=u,r.call(E,u)),n.watchEffect(()=>{typeof e.value=="number"&&V.isClient&&r.call(E,e.value)}),V.tryOnScopeDispose(E.remove),{isLoading:a,progress:e,start:E.start,done:E.done,remove:()=>{e.value=null,E.remove()}}}function me(t,o){const e=V.toRef(t),a=n.shallowRef("");return n.watch(e,async r=>{e.value&&V.isClient&&(a.value=await x.toDataURL(r,o))},{immediate:!0}),a}function we(t,o,e={}){let a;const{document:r=g.defaultDocument,...u}=e,l={onUpdate:d=>{z(o,d.oldIndex,d.newIndex,d)}},c=()=>{const d=typeof t=="string"?r?.querySelector(t):g.unrefElement(t);!d||a!==void 0||(a=new ee(d,{...l,...u}))},s=()=>{a?.destroy(),a=void 0},h=(d,C)=>{if(C!==void 0)a?.option(d,C);else return a?.option(d)};return g.tryOnMounted(c),g.tryOnScopeDispose(s),{stop:s,start:c,option:h}}function B(t,o,e){const a=t.children[e];t.insertBefore(o,a)}function W(t){t.parentNode&&t.parentNode.removeChild(t)}function z(t,o,e,a=null){a!=null&&(W(a.item),B(a.from,a.item,o));const r=n.isRef(t),u=r?[...n.toValue(t)]:n.toValue(t);if(e>=0&&e<u.length){const l=u.splice(o,1)[0];n.nextTick(()=>{u.splice(e,0,l),r&&(t.value=u)})}}y.createCookies=se,y.insertNodeAt=B,y.moveArrayElement=z,y.removeNode=W,y.useAsyncValidator=oe,y.useAxios=le,y.useChangeCase=re,y.useCookies=T,y.useDrauu=ce,y.useFocusTrap=ie,y.useFuse=fe,y.useIDBKeyval=de,y.useJwt=ve,y.useNProgress=he,y.useQRCode=me,y.useSortable=we})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,Vue,axios,changeCase,UniversalCookie,VueUse,Drauu,focusTrap,Fuse,idbKeyval,jwt_decode,nprogress,QRCode,Sortable);