@vueuse/integrations 10.0.0-beta.1 → 10.0.0-beta.2

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/index.cjs CHANGED
@@ -39,12 +39,13 @@ const AsyncValidatorSchema = Schema.default || Schema;
39
39
  function useAsyncValidator(value, rules, options = {}) {
40
40
  const {
41
41
  validateOption = {},
42
- immediate = true
42
+ immediate = true,
43
+ manual = false
43
44
  } = options;
44
45
  const valueRef = shared.resolveRef(value);
45
46
  const errorInfo = vueDemi.shallowRef(null);
46
47
  const isFinished = vueDemi.ref(true);
47
- const pass = vueDemi.ref(!immediate);
48
+ const pass = vueDemi.ref(!immediate || manual);
48
49
  const errors = vueDemi.computed(() => {
49
50
  var _a;
50
51
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -73,7 +74,9 @@ function useAsyncValidator(value, rules, options = {}) {
73
74
  errorFields: errorFields.value
74
75
  };
75
76
  };
76
- vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
77
+ if (!manual) {
78
+ vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
79
+ }
77
80
  const shell = {
78
81
  isFinished,
79
82
  pass,
@@ -180,7 +183,11 @@ function useAxios(...args) {
180
183
  var _a;
181
184
  error.value = e;
182
185
  (_a = options.onError) == null ? void 0 : _a.call(options, e);
183
- }).finally(() => loading(false));
186
+ }).finally(() => {
187
+ var _a;
188
+ (_a = options.onFinish) == null ? void 0 : _a.call(options);
189
+ loading(false);
190
+ });
184
191
  return { then };
185
192
  };
186
193
  if (options.immediate && url)
package/index.d.ts CHANGED
@@ -39,7 +39,17 @@ interface UseAsyncValidatorOptions {
39
39
  * @see https://github.com/yiminghe/async-validator#options
40
40
  */
41
41
  validateOption?: ValidateOption;
42
+ /**
43
+ * The validation will be triggered right away for the first time.
44
+ * Only works when `manual` is not set to true.
45
+ *
46
+ * @default true
47
+ */
42
48
  immediate?: boolean;
49
+ /**
50
+ * If set to true, the validation will not be triggered automatically.
51
+ */
52
+ manual?: boolean;
43
53
  }
44
54
  /**
45
55
  * Wrapper for async-validator.
@@ -139,6 +149,10 @@ interface UseAxiosOptions<T = any> {
139
149
  * Callback when success is caught.
140
150
  */
141
151
  onSuccess?: (data: T) => void;
152
+ /**
153
+ * Callback when request is finished.
154
+ */
155
+ onFinish?: () => void;
142
156
  }
143
157
  declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
144
158
  declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
package/index.iife.js CHANGED
@@ -138,12 +138,13 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
138
138
  function useAsyncValidator(value, rules, options = {}) {
139
139
  const {
140
140
  validateOption = {},
141
- immediate = true
141
+ immediate = true,
142
+ manual = false
142
143
  } = options;
143
144
  const valueRef = shared.resolveRef(value);
144
145
  const errorInfo = vueDemi.shallowRef(null);
145
146
  const isFinished = vueDemi.ref(true);
146
- const pass = vueDemi.ref(!immediate);
147
+ const pass = vueDemi.ref(!immediate || manual);
147
148
  const errors = vueDemi.computed(() => {
148
149
  var _a;
149
150
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -172,7 +173,9 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
172
173
  errorFields: errorFields.value
173
174
  };
174
175
  };
175
- vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
176
+ if (!manual) {
177
+ vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
178
+ }
176
179
  const shell = {
177
180
  isFinished,
178
181
  pass,
@@ -279,7 +282,11 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
279
282
  var _a;
280
283
  error.value = e;
281
284
  (_a = options.onError) == null ? void 0 : _a.call(options, e);
282
- }).finally(() => loading(false));
285
+ }).finally(() => {
286
+ var _a;
287
+ (_a = options.onFinish) == null ? void 0 : _a.call(options);
288
+ loading(false);
289
+ });
283
290
  return { then };
284
291
  };
285
292
  if (options.immediate && url)
package/index.iife.min.js CHANGED
@@ -1 +1 @@
1
- var VueDemi=function(l,o,I){if(l.install)return l;if(!o)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),l;if(o.version.slice(0,4)==="2.7."){let p=function(C,E){var w,T={},B={config:o.config,use:o.use.bind(o),mixin:o.mixin.bind(o),component:o.component.bind(o),provide:function(g,S){return T[g]=S,this},directive:function(g,S){return S?(o.directive(g,S),B):o.directive(g)},mount:function(g,S){return w||(w=new o(Object.assign({propsData:E},C,{provide:Object.assign(T,C.provide)})),w.$mount(g,S),w)},unmount:function(){w&&(w.$destroy(),w=void 0)}};return B};var H=p;for(var a in o)l[a]=o[a];l.isVue2=!0,l.isVue3=!1,l.install=function(){},l.Vue=o,l.Vue2=o,l.version=o.version,l.warn=o.util.warn,l.createApp=p}else if(o.version.slice(0,2)==="2.")if(I){for(var a in I)l[a]=I[a];l.isVue2=!0,l.isVue3=!1,l.install=function(){},l.Vue=o,l.Vue2=o,l.version=o.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(o.version.slice(0,2)==="3."){for(var a in o)l[a]=o[a];l.isVue2=!1,l.isVue3=!0,l.install=function(){},l.Vue=o,l.Vue2=void 0,l.version=o.version,l.set=function(p,C,E){return Array.isArray(p)?(p.length=Math.max(p.length,C),p.splice(C,1,E),E):(p[C]=E,E)},l.del=function(p,C){if(Array.isArray(p)){p.splice(C,1);return}delete p[C]}}else console.error("[vue-demi] Vue version "+o.version+" is unsupported.");return l}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(l,o,I,a,H,p,C,E,w,T,B,g,S,b,ve,de){"use strict";var pe=Object.defineProperty,_e=Object.defineProperties,we=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,Oe=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable,W=(t,r,e)=>r in t?pe(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Pe=(t,r)=>{for(var e in r||(r={}))Oe.call(r,e)&&W(t,e,r[e]);if(M)for(var e of M(r))ye.call(r,e)&&W(t,e,r[e]);return t},he=(t,r)=>_e(t,we(r));const me=I.default||I;function ge(t,r,e={}){const{validateOption:n={},immediate:i=!0}=e,v=o.resolveRef(t),s=a.shallowRef(null),d=a.ref(!0),u=a.ref(!i),f=a.computed(()=>{var h;return((h=s.value)==null?void 0:h.errors)||[]}),_=a.computed(()=>{var h;return((h=s.value)==null?void 0:h.fields)||{}}),m=a.computed(()=>new me(o.resolveUnref(r))),P=async()=>{d.value=!1,u.value=!1;try{await m.value.validate(v.value,n),u.value=!0,s.value=null}catch(h){s.value=h}finally{d.value=!0}return{pass:u.value,errorInfo:s.value,errors:f.value,errorFields:_.value}};a.watch([v,m],()=>P(),{immediate:i,deep:!0});const O={isFinished:d,pass:u,errors:f,errorInfo:s,errorFields:_,execute:P};function A(){return new Promise((h,$)=>{o.until(d).toBe(!0).then(()=>h(O)).catch(U=>$(U))})}return he(Pe({},O),{then(h,$){return A().then(h,$)}})}var Ce=Object.defineProperty,be=Object.defineProperties,Ee=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,Se=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable,X=(t,r,e)=>r in t?Ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,z=(t,r)=>{for(var e in r||(r={}))Se.call(r,e)&&X(t,e,r[e]);if(q)for(var e of q(r))$e.call(r,e)&&X(t,e,r[e]);return t},Y=(t,r)=>be(t,Ee(r));function Ae(...t){const r=typeof t[0]=="string"?t[0]:void 0,e=o.isString(r)?1:0;let n={},i=H,v={immediate:!!e,shallow:!0};const s=y=>!!(y==null?void 0:y.request);t.length>0+e&&(s(t[0+e])?i=t[0+e]:n=t[0+e]),t.length>1+e&&s(t[1+e])&&(i=t[1+e]),(t.length===2+e&&!s(t[1+e])||t.length===3+e)&&(v=t[t.length-1]);const d=a.shallowRef(),u=v.shallow?a.shallowRef():a.ref(),f=a.ref(!1),_=a.ref(!1),m=a.ref(!1),P=a.shallowRef(),O=H.CancelToken.source;let A=O();const h=y=>{f.value||!_.value||(A.cancel(y),A=O(),m.value=!0,_.value=!1,f.value=!1)},$=y=>{_.value=y,f.value=!y},U=()=>new Promise((y,c)=>{o.until(f).toBe(!0).then(()=>y(F)).catch(c)}),R=(y,c)=>U().then(y,c),Q=(y=r,c={})=>{P.value=void 0;const j=typeof y=="string"?y:r??c.url;return j===void 0?(P.value=new H.AxiosError(H.AxiosError.ERR_INVALID_URL),f.value=!0,{then:R}):(h(),$(!0),i(j,Y(z(z({},n),typeof y=="object"?y:c),{cancelToken:A.token})).then(N=>{var L;d.value=N;const fe=N.data;u.value=fe,(L=v.onSuccess)==null||L.call(v,fe)}).catch(N=>{var L;P.value=N,(L=v.onError)==null||L.call(v,N)}).finally(()=>$(!1)),{then:R})};v.immediate&&r&&Q();const F={response:d,data:u,error:P,finished:f,loading:_,isFinished:f,isLoading:_,cancel:h,isAborted:m,canceled:m,aborted:m,isCanceled:m,abort:h,execute:Q};return Y(z({},F),{then:R})}var Z=Object.freeze({__proto__:null,camelCase:p.camelCase,capitalCase:p.capitalCase,constantCase:p.constantCase,dotCase:p.dotCase,headerCase:p.headerCase,noCase:p.noCase,paramCase:p.paramCase,pascalCase:p.pascalCase,pathCase:p.pathCase,sentenceCase:p.sentenceCase,snakeCase:p.snakeCase});function je(t,r,e){if(o.isFunction(t))return a.computed(()=>Z[r](o.resolveUnref(t),e));const n=a.ref(t);return a.computed({get(){return Z[r](n.value,e)},set(i){n.value=i}})}var Ie=Object.defineProperty,k=Object.getOwnPropertySymbols,Ue=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,x=(t,r,e)=>r in t?Ie(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,K=(t,r)=>{for(var e in r||(r={}))Ue.call(r,e)&&x(t,e,r[e]);if(k)for(var e of k(r))Re.call(r,e)&&x(t,e,r[e]);return t};function Fe(t){const r=new C(t?t.headers.cookie:null);return(e,{doNotParse:n=!1,autoUpdateDependencies:i=!1}={})=>V(e,{doNotParse:n,autoUpdateDependencies:i},r)}function V(t,{doNotParse:r=!1,autoUpdateDependencies:e=!1}={},n=new C){const i=e?[...t||[]]:t;let v=n.getAll({doNotParse:!0});const s=a.ref(0),d=()=>{const u=n.getAll({doNotParse:!0});Ne(i||null,u,v)&&s.value++,v=u};return n.addChangeListener(d),o.tryOnScopeDispose(()=>{n.removeChangeListener(d)}),{get:(...u)=>(e&&i&&!i.includes(u[0])&&i.push(u[0]),s.value,n.get(u[0],K({doNotParse:r},u[1]))),getAll:(...u)=>(s.value,n.getAll(K({doNotParse:r},u[0]))),set:(...u)=>n.set(...u),remove:(...u)=>n.remove(...u),addChangeListener:(...u)=>n.addChangeListener(...u),removeChangeListener:(...u)=>n.removeChangeListener(...u)}}function Ne(t,r,e){if(!t)return!0;for(const n of t)if(r[n]!==e[n])return!0;return!1}var Le=Object.defineProperty,D=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,ee=(t,r,e)=>r in t?Le(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Be=(t,r)=>{for(var e in r||(r={}))He.call(r,e)&&ee(t,e,r[e]);if(D)for(var e of D(r))Te.call(r,e)&&ee(t,e,r[e]);return t};function Ge(t,r){const e=a.ref();let n=[];const i=w.createEventHook(),v=w.createEventHook(),s=w.createEventHook(),d=w.createEventHook(),u=w.createEventHook(),f=a.ref(!1),_=a.ref(!1),m=a.ref(!1),P=a.ref(!1),O=a.ref({color:"black",size:3,arrowEnd:!1,cornerRadius:0,dasharray:void 0,fill:"transparent",mode:"draw"});a.watch(O,()=>{const c=e.value;c&&(c.brush=O.value,c.mode=O.value.mode)},{deep:!0});const A=()=>{var c;return(c=e.value)==null?void 0:c.undo()},h=()=>{var c;return(c=e.value)==null?void 0:c.redo()},$=()=>{var c;return(c=e.value)==null?void 0:c.clear()},U=()=>{var c;return(c=e.value)==null?void 0:c.cancel()},R=c=>{var j;return(j=e.value)==null?void 0:j.load(c)},Q=()=>{var c;return(c=e.value)==null?void 0:c.dump()},F=()=>{var c;n.forEach(j=>j()),(c=e.value)==null||c.unmount()},y=()=>{e.value&&(f.value=e.value.canUndo(),_.value=e.value.canRedo(),m.value=e.value.altPressed,P.value=e.value.shiftPressed)};return a.watch(()=>w.unrefElement(t),c=>{!c||typeof SVGSVGElement=="undefined"||!(c instanceof SVGSVGElement)||(e.value&&F(),e.value=E.createDrauu(Be({el:c},r)),y(),n=[e.value.on("canceled",()=>v.trigger()),e.value.on("committed",()=>s.trigger()),e.value.on("start",()=>d.trigger()),e.value.on("end",()=>u.trigger()),e.value.on("changed",()=>{y(),i.trigger()})])},{flush:"post"}),o.tryOnScopeDispose(()=>F()),{drauuInstance:e,load:R,dump:Q,clear:$,cancel:U,undo:A,redo:h,canUndo:f,canRedo:_,brush:O,onChanged:i.on,onCommitted:s.on,onStart:d.on,onEnd:u.on,onCanceled:v.on}}var Je=Object.defineProperty,Qe=Object.defineProperties,ze=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,re=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,ne=(t,r,e)=>r in t?Je(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Me=(t,r)=>{for(var e in r||(r={}))re.call(r,e)&&ne(t,e,r[e]);if(G)for(var e of G(r))te.call(r,e)&&ne(t,e,r[e]);return t},We=(t,r)=>Qe(t,ze(r)),qe=(t,r)=>{var e={};for(var n in t)re.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(t!=null&&G)for(var n of G(t))r.indexOf(n)<0&&te.call(t,n)&&(e[n]=t[n]);return e};function Xe(t,r={}){let e;const n=r,{immediate:i}=n,v=qe(n,["immediate"]),s=a.ref(!1),d=a.ref(!1),u=P=>e&&e.activate(P),f=P=>e&&e.deactivate(P),_=()=>{e&&(e.pause(),d.value=!0)},m=()=>{e&&(e.unpause(),d.value=!1)};return a.watch(()=>w.unrefElement(t),P=>{!P||(e=T.createFocusTrap(P,We(Me({},v),{onActivate(){s.value=!0,r.onActivate&&r.onActivate()},onDeactivate(){s.value=!1,r.onDeactivate&&r.onDeactivate()}})),i&&u())},{flush:"post"}),w.tryOnScopeDispose(()=>f()),{hasFocus:s,isPaused:d,activate:u,deactivate:f,pause:_,unpause:m}}function Ye(t,r,e){const n=()=>{var s,d;return new B((s=o.resolveUnref(r))!=null?s:[],(d=o.resolveUnref(e))==null?void 0:d.fuseOptions)},i=a.ref(n());a.watch(()=>{var s;return(s=o.resolveUnref(e))==null?void 0:s.fuseOptions},()=>{i.value=n()},{deep:!0}),a.watch(()=>o.resolveUnref(r),s=>{i.value.setCollection(s)},{deep:!0});const v=a.computed(()=>{const s=o.resolveUnref(e);if((s==null?void 0:s.matchAllWhenSearchEmpty)&&!a.unref(t))return o.resolveUnref(r).map((u,f)=>({item:u,refIndex:f}));const d=s==null?void 0:s.resultLimit;return i.value.search(o.resolveUnref(t),d?{limit:d}:void 0)});return{fuse:i,results:v}}var Ze=Object.defineProperty,oe=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable,ae=(t,r,e)=>r in t?Ze(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Ke=(t,r)=>{for(var e in r||(r={}))ke.call(r,e)&&ae(t,e,r[e]);if(oe)for(var e of oe(r))xe.call(r,e)&&ae(t,e,r[e]);return t};function Ve(t,r,e={}){const{flush:n="pre",deep:i=!0,shallow:v=!1,onError:s=O=>{console.error(O)},writeDefaults:d=!0}=e,u=a.ref(!1),f=(v?a.shallowRef:a.ref)(r),_=o.resolveUnref(r);async function m(){try{const O=await g.get(t);O===void 0?_!=null&&d&&await g.set(t,_):f.value=O}catch(O){s(O)}u.value=!0}m();async function P(){try{f.value==null?await g.del(t):Array.isArray(f.value)?await g.update(t,()=>JSON.parse(JSON.stringify(f.value))):typeof f.value=="object"?await g.update(t,()=>Ke({},f.value)):await g.update(t,()=>f.value)}catch(O){s(O)}}return a.watch(f,()=>P(),{flush:n,deep:i}),{isFinished:u,data:f}}function De(t,r={}){const{onError:e,fallbackValue:n=null}=r,i=(d,u)=>{try{return S(d,u)}catch(f){return e==null||e(f),n}},v=a.computed(()=>i(o.resolveUnref(t),{header:!0})),s=a.computed(()=>i(o.resolveUnref(t)));return{header:v,payload:s}}function er(t=null,r){const e=a.ref(t),n=a.computed({set:v=>v?b.start():b.done(),get:()=>o.isNumber(e.value)&&e.value<1});r&&b.configure(r);const i=b.set;return b.set=v=>(e.value=v,i.call(b,v)),a.watchEffect(()=>{o.isNumber(e.value)&&o.isClient&&i.call(b,e.value)}),o.tryOnScopeDispose(b.remove),{isLoading:n,progress:e,start:b.start,done:b.done,remove:()=>{e.value=null,b.remove()}}}function rr(t,r){const e=o.resolveRef(t),n=a.ref("");return a.watch(e,async i=>{e.value&&o.isClient&&(n.value=await ve.toDataURL(i,r))},{immediate:!0}),n}var tr=Object.defineProperty,J=Object.getOwnPropertySymbols,le=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,ue=(t,r,e)=>r in t?tr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,ie=(t,r)=>{for(var e in r||(r={}))le.call(r,e)&&ue(t,e,r[e]);if(J)for(var e of J(r))se.call(r,e)&&ue(t,e,r[e]);return t},nr=(t,r)=>{var e={};for(var n in t)le.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(t!=null&&J)for(var n of J(t))r.indexOf(n)<0&&se.call(t,n)&&(e[n]=t[n]);return e};function or(t,r,e={}){let n;const i=e,{document:v=w.defaultDocument}=i,s=nr(i,["document"]),d={onUpdate:_=>{ce(r,_.oldIndex,_.newIndex)}},u=()=>{const _=typeof t=="string"?v==null?void 0:v.querySelector(t):w.unrefElement(t);!_||(n=new de(_,ie(ie({},d),s)))},f=()=>n==null?void 0:n.destroy();return w.tryOnMounted(u),w.tryOnScopeDispose(f),{stop:f,start:u}}function ce(t,r,e){const n=w.resolveUnref(t);e>=0&&e<n.length&&n.splice(e,0,n.splice(r,1)[0])}l.createCookies=Fe,l.moveArrayElement=ce,l.useAsyncValidator=ge,l.useAxios=Ae,l.useChangeCase=je,l.useCookies=V,l.useDrauu=Ge,l.useFocusTrap=Xe,l.useFuse=Ye,l.useIDBKeyval=Ve,l.useJwt=De,l.useNProgress=er,l.useQRCode=rr,l.useSortable=or})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,VueDemi,axios,changeCase,UniversalCookie,Drauu,VueUse,focusTrap,Fuse,idbKeyval,jwt_decode,nprogress,QRCode,Sortable);
1
+ var VueDemi=function(l,o,F){if(l.install)return l;if(!o)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),l;if(o.version.slice(0,4)==="2.7."){let p=function(C,E){var w,T={},B={config:o.config,use:o.use.bind(o),mixin:o.mixin.bind(o),component:o.component.bind(o),provide:function(g,S){return T[g]=S,this},directive:function(g,S){return S?(o.directive(g,S),B):o.directive(g)},mount:function(g,S){return w||(w=new o(Object.assign({propsData:E},C,{provide:Object.assign(T,C.provide)})),w.$mount(g,S),w)},unmount:function(){w&&(w.$destroy(),w=void 0)}};return B};var H=p;for(var a in o)l[a]=o[a];l.isVue2=!0,l.isVue3=!1,l.install=function(){},l.Vue=o,l.Vue2=o,l.version=o.version,l.warn=o.util.warn,l.createApp=p}else if(o.version.slice(0,2)==="2.")if(F){for(var a in F)l[a]=F[a];l.isVue2=!0,l.isVue3=!1,l.install=function(){},l.Vue=o,l.Vue2=o,l.version=o.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(o.version.slice(0,2)==="3."){for(var a in o)l[a]=o[a];l.isVue2=!1,l.isVue3=!0,l.install=function(){},l.Vue=o,l.Vue2=void 0,l.version=o.version,l.set=function(p,C,E){return Array.isArray(p)?(p.length=Math.max(p.length,C),p.splice(C,1,E),E):(p[C]=E,E)},l.del=function(p,C){if(Array.isArray(p)){p.splice(C,1);return}delete p[C]}}else console.error("[vue-demi] Vue version "+o.version+" is unsupported.");return l}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(l,o,F,a,H,p,C,E,w,T,B,g,S,b,ve,de){"use strict";var pe=Object.defineProperty,_e=Object.defineProperties,we=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,Oe=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable,W=(t,r,e)=>r in t?pe(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Pe=(t,r)=>{for(var e in r||(r={}))Oe.call(r,e)&&W(t,e,r[e]);if(M)for(var e of M(r))ye.call(r,e)&&W(t,e,r[e]);return t},he=(t,r)=>_e(t,we(r));const me=F.default||F;function ge(t,r,e={}){const{validateOption:n={},immediate:u=!0,manual:f=!1}=e,i=o.resolveRef(t),d=a.shallowRef(null),s=a.ref(!0),c=a.ref(!u||f),_=a.computed(()=>{var h;return((h=d.value)==null?void 0:h.errors)||[]}),m=a.computed(()=>{var h;return((h=d.value)==null?void 0:h.fields)||{}}),P=a.computed(()=>new me(o.resolveUnref(r))),O=async()=>{s.value=!1,c.value=!1;try{await P.value.validate(i.value,n),c.value=!0,d.value=null}catch(h){d.value=h}finally{s.value=!0}return{pass:c.value,errorInfo:d.value,errors:_.value,errorFields:m.value}};f||a.watch([i,P],()=>O(),{immediate:u,deep:!0});const $={isFinished:s,pass:c,errors:_,errorInfo:d,errorFields:m,execute:O};function j(){return new Promise((h,I)=>{o.until(s).toBe(!0).then(()=>h($)).catch(U=>I(U))})}return he(Pe({},$),{then(h,I){return j().then(h,I)}})}var Ce=Object.defineProperty,be=Object.defineProperties,Ee=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,Se=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable,X=(t,r,e)=>r in t?Ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,z=(t,r)=>{for(var e in r||(r={}))Se.call(r,e)&&X(t,e,r[e]);if(q)for(var e of q(r))$e.call(r,e)&&X(t,e,r[e]);return t},Y=(t,r)=>be(t,Ee(r));function Ae(...t){const r=typeof t[0]=="string"?t[0]:void 0,e=o.isString(r)?1:0;let n={},u=H,f={immediate:!!e,shallow:!0};const i=y=>!!(y==null?void 0:y.request);t.length>0+e&&(i(t[0+e])?u=t[0+e]:n=t[0+e]),t.length>1+e&&i(t[1+e])&&(u=t[1+e]),(t.length===2+e&&!i(t[1+e])||t.length===3+e)&&(f=t[t.length-1]);const d=a.shallowRef(),s=f.shallow?a.shallowRef():a.ref(),c=a.ref(!1),_=a.ref(!1),m=a.ref(!1),P=a.shallowRef(),O=H.CancelToken.source;let $=O();const j=y=>{c.value||!_.value||($.cancel(y),$=O(),m.value=!0,_.value=!1,c.value=!1)},h=y=>{_.value=y,c.value=!y},I=()=>new Promise((y,v)=>{o.until(c).toBe(!0).then(()=>y(N)).catch(v)}),U=(y,v)=>I().then(y,v),Q=(y=r,v={})=>{P.value=void 0;const R=typeof y=="string"?y:r??v.url;return R===void 0?(P.value=new H.AxiosError(H.AxiosError.ERR_INVALID_URL),c.value=!0,{then:U}):(j(),h(!0),u(R,Y(z(z({},n),typeof y=="object"?y:v),{cancelToken:$.token})).then(A=>{var L;d.value=A;const fe=A.data;s.value=fe,(L=f.onSuccess)==null||L.call(f,fe)}).catch(A=>{var L;P.value=A,(L=f.onError)==null||L.call(f,A)}).finally(()=>{var A;(A=f.onFinish)==null||A.call(f),h(!1)}),{then:U})};f.immediate&&r&&Q();const N={response:d,data:s,error:P,finished:c,loading:_,isFinished:c,isLoading:_,cancel:j,isAborted:m,canceled:m,aborted:m,isCanceled:m,abort:j,execute:Q};return Y(z({},N),{then:U})}var Z=Object.freeze({__proto__:null,camelCase:p.camelCase,capitalCase:p.capitalCase,constantCase:p.constantCase,dotCase:p.dotCase,headerCase:p.headerCase,noCase:p.noCase,paramCase:p.paramCase,pascalCase:p.pascalCase,pathCase:p.pathCase,sentenceCase:p.sentenceCase,snakeCase:p.snakeCase});function je(t,r,e){if(o.isFunction(t))return a.computed(()=>Z[r](o.resolveUnref(t),e));const n=a.ref(t);return a.computed({get(){return Z[r](n.value,e)},set(u){n.value=u}})}var Ie=Object.defineProperty,k=Object.getOwnPropertySymbols,Ue=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,x=(t,r,e)=>r in t?Ie(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,K=(t,r)=>{for(var e in r||(r={}))Ue.call(r,e)&&x(t,e,r[e]);if(k)for(var e of k(r))Re.call(r,e)&&x(t,e,r[e]);return t};function Fe(t){const r=new C(t?t.headers.cookie:null);return(e,{doNotParse:n=!1,autoUpdateDependencies:u=!1}={})=>V(e,{doNotParse:n,autoUpdateDependencies:u},r)}function V(t,{doNotParse:r=!1,autoUpdateDependencies:e=!1}={},n=new C){const u=e?[...t||[]]:t;let f=n.getAll({doNotParse:!0});const i=a.ref(0),d=()=>{const s=n.getAll({doNotParse:!0});Ne(u||null,s,f)&&i.value++,f=s};return n.addChangeListener(d),o.tryOnScopeDispose(()=>{n.removeChangeListener(d)}),{get:(...s)=>(e&&u&&!u.includes(s[0])&&u.push(s[0]),i.value,n.get(s[0],K({doNotParse:r},s[1]))),getAll:(...s)=>(i.value,n.getAll(K({doNotParse:r},s[0]))),set:(...s)=>n.set(...s),remove:(...s)=>n.remove(...s),addChangeListener:(...s)=>n.addChangeListener(...s),removeChangeListener:(...s)=>n.removeChangeListener(...s)}}function Ne(t,r,e){if(!t)return!0;for(const n of t)if(r[n]!==e[n])return!0;return!1}var Le=Object.defineProperty,D=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,ee=(t,r,e)=>r in t?Le(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Be=(t,r)=>{for(var e in r||(r={}))He.call(r,e)&&ee(t,e,r[e]);if(D)for(var e of D(r))Te.call(r,e)&&ee(t,e,r[e]);return t};function Ge(t,r){const e=a.ref();let n=[];const u=w.createEventHook(),f=w.createEventHook(),i=w.createEventHook(),d=w.createEventHook(),s=w.createEventHook(),c=a.ref(!1),_=a.ref(!1),m=a.ref(!1),P=a.ref(!1),O=a.ref({color:"black",size:3,arrowEnd:!1,cornerRadius:0,dasharray:void 0,fill:"transparent",mode:"draw"});a.watch(O,()=>{const v=e.value;v&&(v.brush=O.value,v.mode=O.value.mode)},{deep:!0});const $=()=>{var v;return(v=e.value)==null?void 0:v.undo()},j=()=>{var v;return(v=e.value)==null?void 0:v.redo()},h=()=>{var v;return(v=e.value)==null?void 0:v.clear()},I=()=>{var v;return(v=e.value)==null?void 0:v.cancel()},U=v=>{var R;return(R=e.value)==null?void 0:R.load(v)},Q=()=>{var v;return(v=e.value)==null?void 0:v.dump()},N=()=>{var v;n.forEach(R=>R()),(v=e.value)==null||v.unmount()},y=()=>{e.value&&(c.value=e.value.canUndo(),_.value=e.value.canRedo(),m.value=e.value.altPressed,P.value=e.value.shiftPressed)};return a.watch(()=>w.unrefElement(t),v=>{!v||typeof SVGSVGElement=="undefined"||!(v instanceof SVGSVGElement)||(e.value&&N(),e.value=E.createDrauu(Be({el:v},r)),y(),n=[e.value.on("canceled",()=>f.trigger()),e.value.on("committed",()=>i.trigger()),e.value.on("start",()=>d.trigger()),e.value.on("end",()=>s.trigger()),e.value.on("changed",()=>{y(),u.trigger()})])},{flush:"post"}),o.tryOnScopeDispose(()=>N()),{drauuInstance:e,load:U,dump:Q,clear:h,cancel:I,undo:$,redo:j,canUndo:c,canRedo:_,brush:O,onChanged:u.on,onCommitted:i.on,onStart:d.on,onEnd:s.on,onCanceled:f.on}}var Je=Object.defineProperty,Qe=Object.defineProperties,ze=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,re=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,ne=(t,r,e)=>r in t?Je(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Me=(t,r)=>{for(var e in r||(r={}))re.call(r,e)&&ne(t,e,r[e]);if(G)for(var e of G(r))te.call(r,e)&&ne(t,e,r[e]);return t},We=(t,r)=>Qe(t,ze(r)),qe=(t,r)=>{var e={};for(var n in t)re.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(t!=null&&G)for(var n of G(t))r.indexOf(n)<0&&te.call(t,n)&&(e[n]=t[n]);return e};function Xe(t,r={}){let e;const n=r,{immediate:u}=n,f=qe(n,["immediate"]),i=a.ref(!1),d=a.ref(!1),s=P=>e&&e.activate(P),c=P=>e&&e.deactivate(P),_=()=>{e&&(e.pause(),d.value=!0)},m=()=>{e&&(e.unpause(),d.value=!1)};return a.watch(()=>w.unrefElement(t),P=>{!P||(e=T.createFocusTrap(P,We(Me({},f),{onActivate(){i.value=!0,r.onActivate&&r.onActivate()},onDeactivate(){i.value=!1,r.onDeactivate&&r.onDeactivate()}})),u&&s())},{flush:"post"}),w.tryOnScopeDispose(()=>c()),{hasFocus:i,isPaused:d,activate:s,deactivate:c,pause:_,unpause:m}}function Ye(t,r,e){const n=()=>{var i,d;return new B((i=o.resolveUnref(r))!=null?i:[],(d=o.resolveUnref(e))==null?void 0:d.fuseOptions)},u=a.ref(n());a.watch(()=>{var i;return(i=o.resolveUnref(e))==null?void 0:i.fuseOptions},()=>{u.value=n()},{deep:!0}),a.watch(()=>o.resolveUnref(r),i=>{u.value.setCollection(i)},{deep:!0});const f=a.computed(()=>{const i=o.resolveUnref(e);if((i==null?void 0:i.matchAllWhenSearchEmpty)&&!a.unref(t))return o.resolveUnref(r).map((s,c)=>({item:s,refIndex:c}));const d=i==null?void 0:i.resultLimit;return u.value.search(o.resolveUnref(t),d?{limit:d}:void 0)});return{fuse:u,results:f}}var Ze=Object.defineProperty,oe=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable,ae=(t,r,e)=>r in t?Ze(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Ke=(t,r)=>{for(var e in r||(r={}))ke.call(r,e)&&ae(t,e,r[e]);if(oe)for(var e of oe(r))xe.call(r,e)&&ae(t,e,r[e]);return t};function Ve(t,r,e={}){const{flush:n="pre",deep:u=!0,shallow:f=!1,onError:i=O=>{console.error(O)},writeDefaults:d=!0}=e,s=a.ref(!1),c=(f?a.shallowRef:a.ref)(r),_=o.resolveUnref(r);async function m(){try{const O=await g.get(t);O===void 0?_!=null&&d&&await g.set(t,_):c.value=O}catch(O){i(O)}s.value=!0}m();async function P(){try{c.value==null?await g.del(t):Array.isArray(c.value)?await g.update(t,()=>JSON.parse(JSON.stringify(c.value))):typeof c.value=="object"?await g.update(t,()=>Ke({},c.value)):await g.update(t,()=>c.value)}catch(O){i(O)}}return a.watch(c,()=>P(),{flush:n,deep:u}),{isFinished:s,data:c}}function De(t,r={}){const{onError:e,fallbackValue:n=null}=r,u=(d,s)=>{try{return S(d,s)}catch(c){return e==null||e(c),n}},f=a.computed(()=>u(o.resolveUnref(t),{header:!0})),i=a.computed(()=>u(o.resolveUnref(t)));return{header:f,payload:i}}function er(t=null,r){const e=a.ref(t),n=a.computed({set:f=>f?b.start():b.done(),get:()=>o.isNumber(e.value)&&e.value<1});r&&b.configure(r);const u=b.set;return b.set=f=>(e.value=f,u.call(b,f)),a.watchEffect(()=>{o.isNumber(e.value)&&o.isClient&&u.call(b,e.value)}),o.tryOnScopeDispose(b.remove),{isLoading:n,progress:e,start:b.start,done:b.done,remove:()=>{e.value=null,b.remove()}}}function rr(t,r){const e=o.resolveRef(t),n=a.ref("");return a.watch(e,async u=>{e.value&&o.isClient&&(n.value=await ve.toDataURL(u,r))},{immediate:!0}),n}var tr=Object.defineProperty,J=Object.getOwnPropertySymbols,le=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,ue=(t,r,e)=>r in t?tr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,ie=(t,r)=>{for(var e in r||(r={}))le.call(r,e)&&ue(t,e,r[e]);if(J)for(var e of J(r))se.call(r,e)&&ue(t,e,r[e]);return t},nr=(t,r)=>{var e={};for(var n in t)le.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(t!=null&&J)for(var n of J(t))r.indexOf(n)<0&&se.call(t,n)&&(e[n]=t[n]);return e};function or(t,r,e={}){let n;const u=e,{document:f=w.defaultDocument}=u,i=nr(u,["document"]),d={onUpdate:_=>{ce(r,_.oldIndex,_.newIndex)}},s=()=>{const _=typeof t=="string"?f==null?void 0:f.querySelector(t):w.unrefElement(t);!_||(n=new de(_,ie(ie({},d),i)))},c=()=>n==null?void 0:n.destroy();return w.tryOnMounted(s),w.tryOnScopeDispose(c),{stop:c,start:s}}function ce(t,r,e){const n=w.resolveUnref(t);e>=0&&e<n.length&&n.splice(e,0,n.splice(r,1)[0])}l.createCookies=Fe,l.moveArrayElement=ce,l.useAsyncValidator=ge,l.useAxios=Ae,l.useChangeCase=je,l.useCookies=V,l.useDrauu=Ge,l.useFocusTrap=Xe,l.useFuse=Ye,l.useIDBKeyval=Ve,l.useJwt=De,l.useNProgress=er,l.useQRCode=rr,l.useSortable=or})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,VueDemi,axios,changeCase,UniversalCookie,Drauu,VueUse,focusTrap,Fuse,idbKeyval,jwt_decode,nprogress,QRCode,Sortable);
package/index.mjs CHANGED
@@ -37,12 +37,13 @@ const AsyncValidatorSchema = Schema.default || Schema;
37
37
  function useAsyncValidator(value, rules, options = {}) {
38
38
  const {
39
39
  validateOption = {},
40
- immediate = true
40
+ immediate = true,
41
+ manual = false
41
42
  } = options;
42
43
  const valueRef = resolveRef(value);
43
44
  const errorInfo = shallowRef(null);
44
45
  const isFinished = ref(true);
45
- const pass = ref(!immediate);
46
+ const pass = ref(!immediate || manual);
46
47
  const errors = computed(() => {
47
48
  var _a;
48
49
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -71,7 +72,9 @@ function useAsyncValidator(value, rules, options = {}) {
71
72
  errorFields: errorFields.value
72
73
  };
73
74
  };
74
- watch([valueRef, validator], () => execute(), { immediate, deep: true });
75
+ if (!manual) {
76
+ watch([valueRef, validator], () => execute(), { immediate, deep: true });
77
+ }
75
78
  const shell = {
76
79
  isFinished,
77
80
  pass,
@@ -178,7 +181,11 @@ function useAxios(...args) {
178
181
  var _a;
179
182
  error.value = e;
180
183
  (_a = options.onError) == null ? void 0 : _a.call(options, e);
181
- }).finally(() => loading(false));
184
+ }).finally(() => {
185
+ var _a;
186
+ (_a = options.onFinish) == null ? void 0 : _a.call(options);
187
+ loading(false);
188
+ });
182
189
  return { then };
183
190
  };
184
191
  if (options.immediate && url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/integrations",
3
- "version": "10.0.0-beta.1",
3
+ "version": "10.0.0-beta.2",
4
4
  "description": "Integration wrappers for utility libraries",
5
5
  "author": "Anthony Fu <https://github.com/antfu>",
6
6
  "license": "MIT",
@@ -161,8 +161,8 @@
161
161
  }
162
162
  },
163
163
  "dependencies": {
164
- "@vueuse/core": "10.0.0-beta.1",
165
- "@vueuse/shared": "10.0.0-beta.1",
164
+ "@vueuse/core": "10.0.0-beta.2",
165
+ "@vueuse/shared": "10.0.0-beta.2",
166
166
  "vue-demi": "*"
167
167
  },
168
168
  "devDependencies": {
@@ -27,12 +27,13 @@ const AsyncValidatorSchema = Schema.default || Schema;
27
27
  function useAsyncValidator(value, rules, options = {}) {
28
28
  const {
29
29
  validateOption = {},
30
- immediate = true
30
+ immediate = true,
31
+ manual = false
31
32
  } = options;
32
33
  const valueRef = shared.resolveRef(value);
33
34
  const errorInfo = vueDemi.shallowRef(null);
34
35
  const isFinished = vueDemi.ref(true);
35
- const pass = vueDemi.ref(!immediate);
36
+ const pass = vueDemi.ref(!immediate || manual);
36
37
  const errors = vueDemi.computed(() => {
37
38
  var _a;
38
39
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -61,7 +62,9 @@ function useAsyncValidator(value, rules, options = {}) {
61
62
  errorFields: errorFields.value
62
63
  };
63
64
  };
64
- vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
65
+ if (!manual) {
66
+ vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
67
+ }
65
68
  const shell = {
66
69
  isFinished,
67
70
  pass,
@@ -25,12 +25,13 @@ const AsyncValidatorSchema = Schema.default || Schema;
25
25
  function useAsyncValidator(value, rules, options = {}) {
26
26
  const {
27
27
  validateOption = {},
28
- immediate = true
28
+ immediate = true,
29
+ manual = false
29
30
  } = options;
30
31
  const valueRef = resolveRef(value);
31
32
  const errorInfo = shallowRef(null);
32
33
  const isFinished = ref(true);
33
- const pass = ref(!immediate);
34
+ const pass = ref(!immediate || manual);
34
35
  const errors = computed(() => {
35
36
  var _a;
36
37
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -59,7 +60,9 @@ function useAsyncValidator(value, rules, options = {}) {
59
60
  errorFields: errorFields.value
60
61
  };
61
62
  };
62
- watch([valueRef, validator], () => execute(), { immediate, deep: true });
63
+ if (!manual) {
64
+ watch([valueRef, validator], () => execute(), { immediate, deep: true });
65
+ }
63
66
  const shell = {
64
67
  isFinished,
65
68
  pass,
@@ -27,12 +27,13 @@ const AsyncValidatorSchema = Schema.default || Schema;
27
27
  function useAsyncValidator(value, rules, options = {}) {
28
28
  const {
29
29
  validateOption = {},
30
- immediate = true
30
+ immediate = true,
31
+ manual = false
31
32
  } = options;
32
33
  const valueRef = shared.resolveRef(value);
33
34
  const errorInfo = vueDemi.shallowRef(null);
34
35
  const isFinished = vueDemi.ref(true);
35
- const pass = vueDemi.ref(!immediate);
36
+ const pass = vueDemi.ref(!immediate || manual);
36
37
  const errors = vueDemi.computed(() => {
37
38
  var _a;
38
39
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -61,7 +62,9 @@ function useAsyncValidator(value, rules, options = {}) {
61
62
  errorFields: errorFields.value
62
63
  };
63
64
  };
64
- vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
65
+ if (!manual) {
66
+ vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
67
+ }
65
68
  const shell = {
66
69
  isFinished,
67
70
  pass,
@@ -25,7 +25,17 @@ interface UseAsyncValidatorOptions {
25
25
  * @see https://github.com/yiminghe/async-validator#options
26
26
  */
27
27
  validateOption?: ValidateOption;
28
+ /**
29
+ * The validation will be triggered right away for the first time.
30
+ * Only works when `manual` is not set to true.
31
+ *
32
+ * @default true
33
+ */
28
34
  immediate?: boolean;
35
+ /**
36
+ * If set to true, the validation will not be triggered automatically.
37
+ */
38
+ manual?: boolean;
29
39
  }
30
40
  /**
31
41
  * Wrapper for async-validator.
@@ -138,12 +138,13 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
138
138
  function useAsyncValidator(value, rules, options = {}) {
139
139
  const {
140
140
  validateOption = {},
141
- immediate = true
141
+ immediate = true,
142
+ manual = false
142
143
  } = options;
143
144
  const valueRef = shared.resolveRef(value);
144
145
  const errorInfo = vueDemi.shallowRef(null);
145
146
  const isFinished = vueDemi.ref(true);
146
- const pass = vueDemi.ref(!immediate);
147
+ const pass = vueDemi.ref(!immediate || manual);
147
148
  const errors = vueDemi.computed(() => {
148
149
  var _a;
149
150
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -172,7 +173,9 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
172
173
  errorFields: errorFields.value
173
174
  };
174
175
  };
175
- vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
176
+ if (!manual) {
177
+ vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
178
+ }
176
179
  const shell = {
177
180
  isFinished,
178
181
  pass,
@@ -1 +1 @@
1
- var VueDemi=function(e,r,v){if(e.install)return e;if(!r)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if(r.version.slice(0,4)==="2.7."){let o=function(i,f){var c,y={},h={config:r.config,use:r.use.bind(r),mixin:r.mixin.bind(r),component:r.component.bind(r),provide:function(u,d){return y[u]=d,this},directive:function(u,d){return d?(r.directive(u,d),h):r.directive(u)},mount:function(u,d){return c||(c=new r(Object.assign({propsData:f},i,{provide:Object.assign(y,i.provide)})),c.$mount(u,d),c)},unmount:function(){c&&(c.$destroy(),c=void 0)}};return h};var x=o;for(var n in r)e[n]=r[n];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=r,e.Vue2=r,e.version=r.version,e.warn=r.util.warn,e.createApp=o}else if(r.version.slice(0,2)==="2.")if(v){for(var n in v)e[n]=v[n];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=r,e.Vue2=r,e.version=r.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(r.version.slice(0,2)==="3."){for(var n in r)e[n]=r[n];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=r,e.Vue2=void 0,e.version=r.version,e.set=function(o,i,f){return Array.isArray(o)?(o.length=Math.max(o.length,i),o.splice(i,1,f),f):(o[i]=f,f)},e.del=function(o,i){if(Array.isArray(o)){o.splice(i,1);return}delete o[i]}}else console.error("[vue-demi] Vue version "+r.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,r,v,n){"use strict";var x=Object.defineProperty,o=Object.defineProperties,i=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,h=(a,t,s)=>t in a?x(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,u=(a,t)=>{for(var s in t||(t={}))c.call(t,s)&&h(a,s,t[s]);if(f)for(var s of f(t))y.call(t,s)&&h(a,s,t[s]);return a},d=(a,t)=>o(a,i(t));const F=v.default||v;function R(a,t,s={}){const{validateOption:E={},immediate:P=!0}=s,b=r.resolveRef(a),p=n.shallowRef(null),_=n.ref(!0),w=n.ref(!P),A=n.computed(()=>{var l;return((l=p.value)==null?void 0:l.errors)||[]}),j=n.computed(()=>{var l;return((l=p.value)==null?void 0:l.fields)||{}}),I=n.computed(()=>new F(r.resolveUnref(t))),g=async()=>{_.value=!1,w.value=!1;try{await I.value.validate(b.value,E),w.value=!0,p.value=null}catch(l){p.value=l}finally{_.value=!0}return{pass:w.value,errorInfo:p.value,errors:A.value,errorFields:j.value}};n.watch([b,I],()=>g(),{immediate:P,deep:!0});const U={isFinished:_,pass:w,errors:A,errorInfo:p,errorFields:j,execute:g};function S(){return new Promise((l,O)=>{r.until(_).toBe(!0).then(()=>l(U)).catch($=>O($))})}return d(u({},U),{then(l,O){return S().then(l,O)}})}e.useAsyncValidator=R})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,VueDemi);
1
+ var VueDemi=function(e,r,v){if(e.install)return e;if(!r)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if(r.version.slice(0,4)==="2.7."){let o=function(i,c){var f,y={},h={config:r.config,use:r.use.bind(r),mixin:r.mixin.bind(r),component:r.component.bind(r),provide:function(u,d){return y[u]=d,this},directive:function(u,d){return d?(r.directive(u,d),h):r.directive(u)},mount:function(u,d){return f||(f=new r(Object.assign({propsData:c},i,{provide:Object.assign(y,i.provide)})),f.$mount(u,d),f)},unmount:function(){f&&(f.$destroy(),f=void 0)}};return h};var F=o;for(var n in r)e[n]=r[n];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=r,e.Vue2=r,e.version=r.version,e.warn=r.util.warn,e.createApp=o}else if(r.version.slice(0,2)==="2.")if(v){for(var n in v)e[n]=v[n];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=r,e.Vue2=r,e.version=r.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(r.version.slice(0,2)==="3."){for(var n in r)e[n]=r[n];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=r,e.Vue2=void 0,e.version=r.version,e.set=function(o,i,c){return Array.isArray(o)?(o.length=Math.max(o.length,i),o.splice(i,1,c),c):(o[i]=c,c)},e.del=function(o,i){if(Array.isArray(o)){o.splice(i,1);return}delete o[i]}}else console.error("[vue-demi] Vue version "+r.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,r,v,n){"use strict";var F=Object.defineProperty,o=Object.defineProperties,i=Object.getOwnPropertyDescriptors,c=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,h=(a,t,s)=>t in a?F(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,u=(a,t)=>{for(var s in t||(t={}))f.call(t,s)&&h(a,s,t[s]);if(c)for(var s of c(t))y.call(t,s)&&h(a,s,t[s]);return a},d=(a,t)=>o(a,i(t));const R=v.default||v;function E(a,t,s={}){const{validateOption:S={},immediate:P=!0,manual:b=!1}=s,A=r.resolveRef(a),p=n.shallowRef(null),_=n.ref(!0),w=n.ref(!P||b),j=n.computed(()=>{var l;return((l=p.value)==null?void 0:l.errors)||[]}),I=n.computed(()=>{var l;return((l=p.value)==null?void 0:l.fields)||{}}),g=n.computed(()=>new R(r.resolveUnref(t))),U=async()=>{_.value=!1,w.value=!1;try{await g.value.validate(A.value,S),w.value=!0,p.value=null}catch(l){p.value=l}finally{_.value=!0}return{pass:w.value,errorInfo:p.value,errors:j.value,errorFields:I.value}};b||n.watch([A,g],()=>U(),{immediate:P,deep:!0});const x={isFinished:_,pass:w,errors:j,errorInfo:p,errorFields:I,execute:U};function $(){return new Promise((l,O)=>{r.until(_).toBe(!0).then(()=>l(x)).catch(B=>O(B))})}return d(u({},x),{then(l,O){return $().then(l,O)}})}e.useAsyncValidator=E})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,VueDemi);
@@ -25,12 +25,13 @@ const AsyncValidatorSchema = Schema.default || Schema;
25
25
  function useAsyncValidator(value, rules, options = {}) {
26
26
  const {
27
27
  validateOption = {},
28
- immediate = true
28
+ immediate = true,
29
+ manual = false
29
30
  } = options;
30
31
  const valueRef = resolveRef(value);
31
32
  const errorInfo = shallowRef(null);
32
33
  const isFinished = ref(true);
33
- const pass = ref(!immediate);
34
+ const pass = ref(!immediate || manual);
34
35
  const errors = computed(() => {
35
36
  var _a;
36
37
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -59,7 +60,9 @@ function useAsyncValidator(value, rules, options = {}) {
59
60
  errorFields: errorFields.value
60
61
  };
61
62
  };
62
- watch([valueRef, validator], () => execute(), { immediate, deep: true });
63
+ if (!manual) {
64
+ watch([valueRef, validator], () => execute(), { immediate, deep: true });
65
+ }
63
66
  const shell = {
64
67
  isFinished,
65
68
  pass,
package/useAxios.cjs CHANGED
@@ -90,7 +90,11 @@ function useAxios(...args) {
90
90
  var _a;
91
91
  error.value = e;
92
92
  (_a = options.onError) == null ? void 0 : _a.call(options, e);
93
- }).finally(() => loading(false));
93
+ }).finally(() => {
94
+ var _a;
95
+ (_a = options.onFinish) == null ? void 0 : _a.call(options);
96
+ loading(false);
97
+ });
94
98
  return { then };
95
99
  };
96
100
  if (options.immediate && url)
package/useAxios.d.ts CHANGED
@@ -91,6 +91,10 @@ interface UseAxiosOptions<T = any> {
91
91
  * Callback when success is caught.
92
92
  */
93
93
  onSuccess?: (data: T) => void;
94
+ /**
95
+ * Callback when request is finished.
96
+ */
97
+ onFinish?: () => void;
94
98
  }
95
99
  declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
96
100
  declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
package/useAxios.iife.js CHANGED
@@ -201,7 +201,11 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
201
201
  var _a;
202
202
  error.value = e;
203
203
  (_a = options.onError) == null ? void 0 : _a.call(options, e);
204
- }).finally(() => loading(false));
204
+ }).finally(() => {
205
+ var _a;
206
+ (_a = options.onFinish) == null ? void 0 : _a.call(options);
207
+ loading(false);
208
+ });
205
209
  return { then };
206
210
  };
207
211
  if (options.immediate && url)
@@ -1 +1 @@
1
- var VueDemi=function(e,n,h){if(e.install)return e;if(!n)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if(n.version.slice(0,4)==="2.7."){let s=function(c,u){var f,O={},w={config:n.config,use:n.use.bind(n),mixin:n.mixin.bind(n),component:n.component.bind(n),provide:function(a,d){return O[a]=d,this},directive:function(a,d){return d?(n.directive(a,d),w):n.directive(a)},mount:function(a,d){return f||(f=new n(Object.assign({propsData:u},c,{provide:Object.assign(O,c.provide)})),f.$mount(a,d),f)},unmount:function(){f&&(f.$destroy(),f=void 0)}};return w};var q=s;for(var l in n)e[l]=n[l];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version,e.warn=n.util.warn,e.createApp=s}else if(n.version.slice(0,2)==="2.")if(h){for(var l in h)e[l]=h[l];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(n.version.slice(0,2)==="3."){for(var l in n)e[l]=n[l];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=n,e.Vue2=void 0,e.version=n.version,e.set=function(s,c,u){return Array.isArray(s)?(s.length=Math.max(s.length,c),s.splice(c,1,u),u):(s[c]=u,u)},e.del=function(s,c){if(Array.isArray(s)){s.splice(c,1);return}delete s[c]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,n,h,l){"use strict";var q=Object.defineProperty,s=Object.defineProperties,c=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,w=(r,t,o)=>t in r?q(r,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[t]=o,a=(r,t)=>{for(var o in t||(t={}))f.call(t,o)&&w(r,o,t[o]);if(u)for(var o of u(t))O.call(t,o)&&w(r,o,t[o]);return r},d=(r,t)=>s(r,c(t));function B(...r){const t=typeof r[0]=="string"?r[0]:void 0,o=h.isString(t)?1:0;let C={},I=l,v={immediate:!!o,shallow:!0};const E=i=>!!(i==null?void 0:i.request);r.length>0+o&&(E(r[0+o])?I=r[0+o]:C=r[0+o]),r.length>1+o&&E(r[1+o])&&(I=r[1+o]),(r.length===2+o&&!E(r[1+o])||r.length===3+o)&&(v=r[r.length-1]);const T=n.shallowRef(),g=v.shallow?n.shallowRef():n.ref(),p=n.ref(!1),b=n.ref(!1),y=n.ref(!1),j=n.shallowRef(),L=l.CancelToken.source;let R=L();const S=i=>{p.value||!b.value||(R.cancel(i),R=L(),y.value=!0,b.value=!1,p.value=!1)},F=i=>{b.value=i,p.value=!i},M=()=>new Promise((i,_)=>{h.until(p).toBe(!0).then(()=>i(U)).catch(_)}),x=(i,_)=>M().then(i,_),N=(i=t,_={})=>{j.value=void 0;const $=typeof i=="string"?i:t??_.url;return $===void 0?(j.value=new l.AxiosError(l.AxiosError.ERR_INVALID_URL),p.value=!0,{then:x}):(S(),F(!0),I($,d(a(a({},C),typeof i=="object"?i:_),{cancelToken:R.token})).then(P=>{var A;T.value=P;const k=P.data;g.value=k,(A=v.onSuccess)==null||A.call(v,k)}).catch(P=>{var A;j.value=P,(A=v.onError)==null||A.call(v,P)}).finally(()=>F(!1)),{then:x})};v.immediate&&t&&N();const U={response:T,data:g,error:j,finished:p,loading:b,isFinished:p,isLoading:b,cancel:S,isAborted:y,canceled:y,aborted:y,isCanceled:y,abort:S,execute:N};return d(a({},U),{then:x})}e.useAxios=B})(this.VueUse=this.VueUse||{},VueDemi,VueUse,axios);
1
+ var VueDemi=function(e,n,_){if(e.install)return e;if(!n)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if(n.version.slice(0,4)==="2.7."){let s=function(c,u){var a,O={},b={config:n.config,use:n.use.bind(n),mixin:n.mixin.bind(n),component:n.component.bind(n),provide:function(f,d){return O[f]=d,this},directive:function(f,d){return d?(n.directive(f,d),b):n.directive(f)},mount:function(f,d){return a||(a=new n(Object.assign({propsData:u},c,{provide:Object.assign(O,c.provide)})),a.$mount(f,d),a)},unmount:function(){a&&(a.$destroy(),a=void 0)}};return b};var q=s;for(var l in n)e[l]=n[l];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version,e.warn=n.util.warn,e.createApp=s}else if(n.version.slice(0,2)==="2.")if(_){for(var l in _)e[l]=_[l];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(n.version.slice(0,2)==="3."){for(var l in n)e[l]=n[l];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=n,e.Vue2=void 0,e.version=n.version,e.set=function(s,c,u){return Array.isArray(s)?(s.length=Math.max(s.length,c),s.splice(c,1,u),u):(s[c]=u,u)},e.del=function(s,c){if(Array.isArray(s)){s.splice(c,1);return}delete s[c]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,n,_,l){"use strict";var q=Object.defineProperty,s=Object.defineProperties,c=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,b=(r,t,o)=>t in r?q(r,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[t]=o,f=(r,t)=>{for(var o in t||(t={}))a.call(t,o)&&b(r,o,t[o]);if(u)for(var o of u(t))O.call(t,o)&&b(r,o,t[o]);return r},d=(r,t)=>s(r,c(t));function B(...r){const t=typeof r[0]=="string"?r[0]:void 0,o=_.isString(t)?1:0;let C={},I=l,v={immediate:!!o,shallow:!0};const E=i=>!!(i==null?void 0:i.request);r.length>0+o&&(E(r[0+o])?I=r[0+o]:C=r[0+o]),r.length>1+o&&E(r[1+o])&&(I=r[1+o]),(r.length===2+o&&!E(r[1+o])||r.length===3+o)&&(v=r[r.length-1]);const T=n.shallowRef(),g=v.shallow?n.shallowRef():n.ref(),h=n.ref(!1),y=n.ref(!1),P=n.ref(!1),j=n.shallowRef(),F=l.CancelToken.source;let R=F();const S=i=>{h.value||!y.value||(R.cancel(i),R=F(),P.value=!0,y.value=!1,h.value=!1)},L=i=>{y.value=i,h.value=!i},M=()=>new Promise((i,w)=>{_.until(h).toBe(!0).then(()=>i(U)).catch(w)}),x=(i,w)=>M().then(i,w),N=(i=t,w={})=>{j.value=void 0;const $=typeof i=="string"?i:t??w.url;return $===void 0?(j.value=new l.AxiosError(l.AxiosError.ERR_INVALID_URL),h.value=!0,{then:x}):(S(),L(!0),I($,d(f(f({},C),typeof i=="object"?i:w),{cancelToken:R.token})).then(p=>{var A;T.value=p;const k=p.data;g.value=k,(A=v.onSuccess)==null||A.call(v,k)}).catch(p=>{var A;j.value=p,(A=v.onError)==null||A.call(v,p)}).finally(()=>{var p;(p=v.onFinish)==null||p.call(v),L(!1)}),{then:x})};v.immediate&&t&&N();const U={response:T,data:g,error:j,finished:h,loading:y,isFinished:h,isLoading:y,cancel:S,isAborted:P,canceled:P,aborted:P,isCanceled:P,abort:S,execute:N};return d(f({},U),{then:x})}e.useAxios=B})(this.VueUse=this.VueUse||{},VueDemi,VueUse,axios);
package/useAxios.mjs CHANGED
@@ -88,7 +88,11 @@ function useAxios(...args) {
88
88
  var _a;
89
89
  error.value = e;
90
90
  (_a = options.onError) == null ? void 0 : _a.call(options, e);
91
- }).finally(() => loading(false));
91
+ }).finally(() => {
92
+ var _a;
93
+ (_a = options.onFinish) == null ? void 0 : _a.call(options);
94
+ loading(false);
95
+ });
92
96
  return { then };
93
97
  };
94
98
  if (options.immediate && url)