@vueuse/integrations 13.4.0 → 13.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.mts CHANGED
@@ -202,6 +202,8 @@ declare function createCookies(req?: IncomingMessage): (dependencies?: string[]
202
202
  * @param options.doNotParse - don't try parse value as JSON
203
203
  * @param options.autoUpdateDependencies - automatically update watching dependencies
204
204
  * @param cookies - universal-cookie instance
205
+ *
206
+ * @__NO_SIDE_EFFECTS__
205
207
  */
206
208
  declare function useCookies(dependencies?: string[] | null, { doNotParse, autoUpdateDependencies }?: {
207
209
  doNotParse?: boolean | undefined;
@@ -295,7 +297,7 @@ interface UseFocusTrapReturn {
295
297
  *
296
298
  * @see https://vueuse.org/useFocusTrap
297
299
  */
298
- declare function useFocusTrap(target: Arrayable<MaybeRefOrGetter<string> | MaybeComputedElementRef>, options?: UseFocusTrapOptions): UseFocusTrapReturn;
300
+ declare function useFocusTrap(target: MaybeRefOrGetter<Arrayable<MaybeRefOrGetter<string> | MaybeComputedElementRef>>, options?: UseFocusTrapOptions): UseFocusTrapReturn;
299
301
 
300
302
  type FuseOptions<T> = IFuseOptions<T>;
301
303
  interface UseFuseOptions<T> {
@@ -323,7 +325,11 @@ declare function useFuse<DataItem>(search: MaybeRefOrGetter<string>, data: Maybe
323
325
  };
324
326
  type UseFuseReturn = ReturnType<typeof useFuse>;
325
327
 
326
- interface UseIDBOptions extends ConfigurableFlush {
328
+ interface Serializer<T> {
329
+ read: (raw: unknown) => T;
330
+ write: (value: T) => unknown;
331
+ }
332
+ interface UseIDBOptions<T> extends ConfigurableFlush {
327
333
  /**
328
334
  * Watch for deep changes
329
335
  *
@@ -348,6 +354,10 @@ interface UseIDBOptions extends ConfigurableFlush {
348
354
  * @default true
349
355
  */
350
356
  writeDefaults?: boolean;
357
+ /**
358
+ * Custom data serialization
359
+ */
360
+ serializer?: Serializer<T>;
351
361
  }
352
362
  interface UseIDBKeyvalReturn<T> {
353
363
  data: RemovableRef<T>;
@@ -360,7 +370,7 @@ interface UseIDBKeyvalReturn<T> {
360
370
  * @param initialValue
361
371
  * @param options
362
372
  */
363
- declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeRefOrGetter<T>, options?: UseIDBOptions): UseIDBKeyvalReturn<T>;
373
+ declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeRefOrGetter<T>, options?: UseIDBOptions<T>): UseIDBKeyvalReturn<T>;
364
374
 
365
375
  interface UseJwtOptions<Fallback> {
366
376
  /**
package/index.iife.js CHANGED
@@ -209,6 +209,7 @@
209
209
  acc[name] = fn;
210
210
  return acc;
211
211
  }, {});
212
+ // @__NO_SIDE_EFFECTS__
212
213
  function useChangeCase(input, type, options) {
213
214
  const typeRef = vue.computed(() => {
214
215
  const t = vue.toValue(type);
@@ -231,8 +232,9 @@
231
232
 
232
233
  function createCookies(req) {
233
234
  const universalCookie = new Cookie(req ? req.headers.cookie : null);
234
- return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
235
+ return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => /* @__PURE__ */ useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
235
236
  }
237
+ // @__NO_SIDE_EFFECTS__
236
238
  function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}, cookies = new Cookie()) {
237
239
  const watchingDependencies = autoUpdateDependencies ? [...dependencies || []] : dependencies;
238
240
  let previousCookies = cookies.getAll({ doNotParse: true });
@@ -424,21 +426,29 @@
424
426
  (els) => {
425
427
  if (!els.length)
426
428
  return;
427
- trap = focusTrap.createFocusTrap(els, {
428
- ...focusTrapOptions,
429
- onActivate() {
430
- hasFocus.value = true;
431
- if (options.onActivate)
432
- options.onActivate();
433
- },
434
- onDeactivate() {
435
- hasFocus.value = false;
436
- if (options.onDeactivate)
437
- options.onDeactivate();
429
+ if (!trap) {
430
+ trap = focusTrap.createFocusTrap(els, {
431
+ ...focusTrapOptions,
432
+ onActivate() {
433
+ hasFocus.value = true;
434
+ if (options.onActivate)
435
+ options.onActivate();
436
+ },
437
+ onDeactivate() {
438
+ hasFocus.value = false;
439
+ if (options.onDeactivate)
440
+ options.onDeactivate();
441
+ }
442
+ });
443
+ if (immediate)
444
+ activate();
445
+ } else {
446
+ const isActive = trap == null ? void 0 : trap.active;
447
+ trap == null ? void 0 : trap.updateContainerElements(els);
448
+ if (!isActive && immediate) {
449
+ activate();
438
450
  }
439
- });
440
- if (immediate)
441
- activate();
451
+ }
442
452
  },
443
453
  { flush: "post" }
444
454
  );
@@ -500,7 +510,11 @@
500
510
  onError = (e) => {
501
511
  console.error(e);
502
512
  },
503
- writeDefaults = true
513
+ writeDefaults = true,
514
+ serializer = {
515
+ read: (raw) => raw,
516
+ write: (value) => value
517
+ }
504
518
  } = options;
505
519
  const isFinished = vue.shallowRef(false);
506
520
  const data = (shallow ? vue.shallowRef : vue.ref)(initialValue);
@@ -509,10 +523,12 @@
509
523
  try {
510
524
  const rawValue = await idbKeyval.get(key);
511
525
  if (rawValue === void 0) {
512
- if (rawInit !== void 0 && rawInit !== null && writeDefaults)
513
- await idbKeyval.set(key, rawInit);
526
+ if (rawInit !== void 0 && rawInit !== null && writeDefaults) {
527
+ const initValue = serializer.write(rawInit);
528
+ await idbKeyval.set(key, initValue);
529
+ }
514
530
  } else {
515
- data.value = rawValue;
531
+ data.value = serializer.read(rawValue);
516
532
  }
517
533
  } catch (e) {
518
534
  onError(e);
@@ -525,7 +541,9 @@
525
541
  if (data.value == null) {
526
542
  await idbKeyval.del(key);
527
543
  } else {
528
- await idbKeyval.update(key, () => vue.toRaw(data.value));
544
+ const rawValue = vue.toRaw(data.value);
545
+ const serializedValue = serializer.write(rawValue);
546
+ await idbKeyval.update(key, () => serializedValue);
529
547
  }
530
548
  } catch (e) {
531
549
  onError(e);
package/index.iife.min.js CHANGED
@@ -1 +1 @@
1
- (function(w,C,U,n,L,$,k,p,K,X,Y,P,Z,V,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:s=!1}=e,l=C.toRef(t),c=n.shallowRef(null),u=n.shallowRef(!0),d=n.shallowRef(!r||s),v=n.computed(()=>{var i;return((i=c.value)==null?void 0:i.errors)||[]}),g=n.computed(()=>{var i;return((i=c.value)==null?void 0:i.fields)||{}}),h=n.computed(()=>new ae(n.toValue(o))),y=async()=>{u.value=!1,d.value=!1;try{await h.value.validate(l.value,a),d.value=!0,c.value=null}catch(i){c.value=i}finally{u.value=!0}return{pass:d.value,errorInfo:c.value,errors:v.value,errorFields:g.value}};s||n.watch([l,h],()=>y(),{immediate:r,deep:!0});const R={isFinished:u,pass:d,errors:v,errorInfo:c,errorFields:g,execute:y};function E(){return new Promise((i,b)=>{C.until(u).toBe(!0).then(()=>i(R)).catch(A=>b(A))})}return{...R,then(i,b){return E().then(i,b)}}}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={},s=L,l=a;const c=m=>!!m?.request;t.length>0+e&&(c(t[0+e])?s=t[0+e]:r=t[0+e]),t.length>1+e&&c(t[1+e])&&(s=t[1+e]),(t.length===2+e&&!c(t[1+e])||t.length===3+e)&&(l=t[t.length-1]||a);const{shallow:u,onSuccess:d=C.noop,onError:v=C.noop,immediate:g,resetOnExecute:h=!1}=l,y=l.initialData,R=n.shallowRef(),E=(u?n.shallowRef:n.ref)(y),i=n.shallowRef(!1),b=n.shallowRef(!1),A=n.shallowRef(!1),D=n.shallowRef();let S=new AbortController;const F=m=>{i.value||!b.value||(S.abort(m),S=new AbortController,A.value=!0,b.value=!1,i.value=!1)},f=m=>{b.value=m,i.value=!m},_=()=>{h&&(E.value=y)},Q=()=>new Promise((m,I)=>{C.until(i).toBe(!0).then(()=>D.value?I(D.value):m(q))}),H={then:(...m)=>Q().then(...m),catch:(...m)=>Q().catch(...m)};let j=0;const z=(m=o,I={})=>{D.value=void 0;const J=typeof m=="string"?m:o??I.url;if(J===void 0)return D.value=new L.AxiosError(L.AxiosError.ERR_INVALID_URL),i.value=!0,H;_(),l.abortPrevious!==!1&&F(),f(!0),j+=1;const pe=j;return A.value=!1,s(J,{...r,...typeof m=="object"?m:I,signal:S.signal}).then(O=>{if(A.value)return;R.value=O;const M=O.data;E.value=M,d(M)}).catch(O=>{D.value=O,v(O)}).finally(()=>{var O;(O=l.onFinish)==null||O.call(l),pe===j&&f(!1)}),H};g&&o&&z();const q={response:R,data:E,error:D,isFinished:i,isLoading:b,cancel:F,isAborted:A,isCanceled:A,abort:F,execute:z};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 s=n.toValue(o);if(!N[s])throw new Error(`Invalid change case type "${s}"`);return s});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(s){r.value=s}})}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 s=a.getAll({doNotParse:!0});const l=n.shallowRef(0),c=()=>{const u=a.getAll({doNotParse:!0});ue(r||null,u,s)&&l.value++,s=u};return a.addChangeListener(c),C.tryOnScopeDispose(()=>{a.removeChangeListener(c)}),{get:(...u)=>(e&&r&&!r.includes(u[0])&&r.push(u[0]),l.value,a.get(u[0],{doNotParse:o,...u[1]})),getAll:(...u)=>(l.value,a.getAll({doNotParse:o,...u[0]})),set:(...u)=>a.set(...u),remove:(...u)=>a.remove(...u),addChangeListener:(...u)=>a.addChangeListener(...u),removeChangeListener:(...u)=>a.removeChangeListener(...u)}}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=p.createEventHook(),s=p.createEventHook(),l=p.createEventHook(),c=p.createEventHook(),u=p.createEventHook(),d=n.shallowRef(!1),v=n.shallowRef(!1),g=n.shallowRef(!1),h=n.shallowRef(!1),y=n.ref({color:"black",size:3,arrowEnd:!1,cornerRadius:0,dasharray:void 0,fill:"transparent",mode:"draw",...o?.brush});n.watch(y,()=>{const f=e.value;f&&(f.brush=y.value,f.mode=y.value.mode)},{deep:!0});const R=()=>{var f;return(f=e.value)==null?void 0:f.undo()},E=()=>{var f;return(f=e.value)==null?void 0:f.redo()},i=()=>{var f;return(f=e.value)==null?void 0:f.clear()},b=()=>{var f;return(f=e.value)==null?void 0:f.cancel()},A=f=>{var _;return(_=e.value)==null?void 0:_.load(f)},D=()=>{var f;return(f=e.value)==null?void 0:f.dump()},S=()=>{var f;a.forEach(_=>_()),(f=e.value)==null||f.unmount()},F=()=>{e.value&&(d.value=e.value.canUndo(),v.value=e.value.canRedo(),g.value=e.value.altPressed,h.value=e.value.shiftPressed)};return n.watch(()=>p.unrefElement(t),f=>{!f||typeof SVGSVGElement>"u"||!(f instanceof SVGSVGElement)||(e.value&&S(),e.value=K.createDrauu({el:f,...o}),F(),a=[e.value.on("canceled",()=>s.trigger()),e.value.on("committed",_=>l.trigger(_)),e.value.on("start",()=>c.trigger()),e.value.on("end",()=>u.trigger()),e.value.on("changed",()=>{F(),r.trigger()})])},{flush:"post"}),C.tryOnScopeDispose(()=>S()),{drauuInstance:e,load:A,dump:D,clear:i,cancel:b,undo:R,redo:E,canUndo:d,canRedo:v,brush:y,onChanged:r.on,onCommitted:l.on,onStart:c.on,onEnd:u.on,onCanceled:s.on}}function ie(t,o={}){let e;const{immediate:a,...r}=o,s=n.shallowRef(!1),l=n.shallowRef(!1),c=h=>e&&e.activate(h),u=h=>e&&e.deactivate(h),d=()=>{e&&(e.pause(),l.value=!0)},v=()=>{e&&(e.unpause(),l.value=!1)},g=n.computed(()=>{const h=n.toValue(t);return p.toArray(h).map(y=>{const R=n.toValue(y);return typeof R=="string"?R:p.unrefElement(R)}).filter(C.notNullish)});return n.watch(g,h=>{h.length&&(e=X.createFocusTrap(h,{...r,onActivate(){s.value=!0,o.onActivate&&o.onActivate()},onDeactivate(){s.value=!1,o.onDeactivate&&o.onDeactivate()}}),a&&c())},{flush:"post"}),p.tryOnScopeDispose(()=>u()),{hasFocus:s,isPaused:l,activate:c,deactivate:u,pause:d,unpause:v}}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 s=n.computed(()=>{const l=n.toValue(e);if(l?.matchAllWhenSearchEmpty&&!n.toValue(t))return n.toValue(o).map((u,d)=>({item:u,refIndex:d}));const c=l?.resultLimit;return r.value.search(n.toValue(t),c?{limit:c}:void 0)});return{fuse:r,results:s}}function de(t,o,e={}){const{flush:a="pre",deep:r=!0,shallow:s=!1,onError:l=i=>{console.error(i)},writeDefaults:c=!0}=e,u=n.shallowRef(!1),d=(s?n.shallowRef:n.ref)(o),v=n.toValue(o);async function g(){try{const i=await P.get(t);i===void 0?v!=null&&c&&await P.set(t,v):d.value=i}catch(i){l(i)}u.value=!0}g();async function h(){try{d.value==null?await P.del(t):await P.update(t,()=>n.toRaw(d.value))}catch(i){l(i)}}const{pause:y,resume:R}=p.watchPausable(d,()=>h(),{flush:a,deep:r});async function E(i){y(),d.value=i,await h(),R()}return{set:E,isFinished:u,data:d}}function ve(t,o={}){const{onError:e,fallbackValue:a=null}=o,r=(c,u)=>{try{return Z.jwtDecode(c,u)}catch(d){return e?.(d),a}},s=n.computed(()=>r(n.toValue(t),{header:!0})),l=n.computed(()=>r(n.toValue(t)));return{header:s,payload:l}}function he(t=null,o){const e=C.toRef(t),a=n.computed({set:s=>s?V.start():V.done(),get:()=>typeof e.value=="number"&&e.value<1});o&&V.configure(o);const r=V.set;return V.set=s=>(e.value=s,r.call(V,s)),n.watchEffect(()=>{typeof e.value=="number"&&C.isClient&&r.call(V,e.value)}),C.tryOnScopeDispose(V.remove),{isLoading:a,progress:e,start:V.start,done:V.done,remove:()=>{e.value=null,V.remove()}}}function me(t,o){const e=C.toRef(t),a=n.shallowRef("");return n.watch(e,async r=>{e.value&&C.isClient&&(a.value=await x.toDataURL(r,o))},{immediate:!0}),a}function we(t,o,e={}){let a;const{document:r=p.defaultDocument,...s}=e,l={onUpdate:v=>{G(o,v.oldIndex,v.newIndex,v)}},c=()=>{const v=typeof t=="string"?r?.querySelector(t):p.unrefElement(t);!v||a!==void 0||(a=new ee(v,{...l,...s}))},u=()=>{a?.destroy(),a=void 0},d=(v,g)=>{if(g!==void 0)a?.option(v,g);else return a?.option(v)};return p.tryOnMounted(c),p.tryOnScopeDispose(u),{stop:u,start:c,option:d}}function B(t,o,e){const a=t.children[e];t.insertBefore(o,a)}function W(t){t.parentNode&&t.parentNode.removeChild(t)}function G(t,o,e,a=null){a!=null&&(W(a.item),B(a.from,a.item,o));const r=n.isRef(t),s=r?[...n.toValue(t)]:n.toValue(t);if(e>=0&&e<s.length){const l=s.splice(o,1)[0];n.nextTick(()=>{s.splice(e,0,l),r&&(t.value=s)})}}w.createCookies=se,w.insertNodeAt=B,w.moveArrayElement=G,w.removeNode=W,w.useAsyncValidator=oe,w.useAxios=le,w.useChangeCase=re,w.useCookies=T,w.useDrauu=ce,w.useFocusTrap=ie,w.useFuse=fe,w.useIDBKeyval=de,w.useJwt=ve,w.useNProgress=he,w.useQRCode=me,w.useSortable=we})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,Vue,axios,changeCase,UniversalCookie,VueUse,Drauu,focusTrap,Fuse,idbKeyval,jwt_decode,nprogress,QRCode,Sortable);
1
+ (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);
package/index.mjs CHANGED
@@ -203,6 +203,7 @@ const changeCaseTransforms = /* @__PURE__ */ Object.entries(changeCase).filter((
203
203
  acc[name] = fn;
204
204
  return acc;
205
205
  }, {});
206
+ // @__NO_SIDE_EFFECTS__
206
207
  function useChangeCase(input, type, options) {
207
208
  const typeRef = computed(() => {
208
209
  const t = toValue(type);
@@ -225,8 +226,9 @@ function useChangeCase(input, type, options) {
225
226
 
226
227
  function createCookies(req) {
227
228
  const universalCookie = new Cookie(req ? req.headers.cookie : null);
228
- return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
229
+ return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => /* @__PURE__ */ useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
229
230
  }
231
+ // @__NO_SIDE_EFFECTS__
230
232
  function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}, cookies = new Cookie()) {
231
233
  const watchingDependencies = autoUpdateDependencies ? [...dependencies || []] : dependencies;
232
234
  let previousCookies = cookies.getAll({ doNotParse: true });
@@ -418,21 +420,29 @@ function useFocusTrap(target, options = {}) {
418
420
  (els) => {
419
421
  if (!els.length)
420
422
  return;
421
- trap = createFocusTrap(els, {
422
- ...focusTrapOptions,
423
- onActivate() {
424
- hasFocus.value = true;
425
- if (options.onActivate)
426
- options.onActivate();
427
- },
428
- onDeactivate() {
429
- hasFocus.value = false;
430
- if (options.onDeactivate)
431
- options.onDeactivate();
423
+ if (!trap) {
424
+ trap = createFocusTrap(els, {
425
+ ...focusTrapOptions,
426
+ onActivate() {
427
+ hasFocus.value = true;
428
+ if (options.onActivate)
429
+ options.onActivate();
430
+ },
431
+ onDeactivate() {
432
+ hasFocus.value = false;
433
+ if (options.onDeactivate)
434
+ options.onDeactivate();
435
+ }
436
+ });
437
+ if (immediate)
438
+ activate();
439
+ } else {
440
+ const isActive = trap == null ? void 0 : trap.active;
441
+ trap == null ? void 0 : trap.updateContainerElements(els);
442
+ if (!isActive && immediate) {
443
+ activate();
432
444
  }
433
- });
434
- if (immediate)
435
- activate();
445
+ }
436
446
  },
437
447
  { flush: "post" }
438
448
  );
@@ -494,7 +504,11 @@ function useIDBKeyval(key, initialValue, options = {}) {
494
504
  onError = (e) => {
495
505
  console.error(e);
496
506
  },
497
- writeDefaults = true
507
+ writeDefaults = true,
508
+ serializer = {
509
+ read: (raw) => raw,
510
+ write: (value) => value
511
+ }
498
512
  } = options;
499
513
  const isFinished = shallowRef(false);
500
514
  const data = (shallow ? shallowRef : ref)(initialValue);
@@ -503,10 +517,12 @@ function useIDBKeyval(key, initialValue, options = {}) {
503
517
  try {
504
518
  const rawValue = await get(key);
505
519
  if (rawValue === void 0) {
506
- if (rawInit !== void 0 && rawInit !== null && writeDefaults)
507
- await set(key, rawInit);
520
+ if (rawInit !== void 0 && rawInit !== null && writeDefaults) {
521
+ const initValue = serializer.write(rawInit);
522
+ await set(key, initValue);
523
+ }
508
524
  } else {
509
- data.value = rawValue;
525
+ data.value = serializer.read(rawValue);
510
526
  }
511
527
  } catch (e) {
512
528
  onError(e);
@@ -519,7 +535,9 @@ function useIDBKeyval(key, initialValue, options = {}) {
519
535
  if (data.value == null) {
520
536
  await del(key);
521
537
  } else {
522
- await update(key, () => toRaw(data.value));
538
+ const rawValue = toRaw(data.value);
539
+ const serializedValue = serializer.write(rawValue);
540
+ await update(key, () => serializedValue);
523
541
  }
524
542
  } catch (e) {
525
543
  onError(e);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vueuse/integrations",
3
3
  "type": "module",
4
- "version": "13.4.0",
4
+ "version": "13.6.0",
5
5
  "description": "Integration wrappers for utility libraries",
6
6
  "author": "Anthony Fu <https://github.com/antfu>",
7
7
  "license": "MIT",
@@ -62,7 +62,7 @@
62
62
  "nprogress": "^0.2",
63
63
  "qrcode": "^1.5",
64
64
  "sortablejs": "^1",
65
- "universal-cookie": "^7",
65
+ "universal-cookie": "^7 || ^8",
66
66
  "vue": "^3.5.0"
67
67
  },
68
68
  "peerDependenciesMeta": {
@@ -104,15 +104,15 @@
104
104
  }
105
105
  },
106
106
  "dependencies": {
107
- "@vueuse/core": "13.4.0",
108
- "@vueuse/shared": "13.4.0"
107
+ "@vueuse/shared": "13.6.0",
108
+ "@vueuse/core": "13.6.0"
109
109
  },
110
110
  "devDependencies": {
111
111
  "@types/nprogress": "^0.2.3",
112
112
  "@types/qrcode": "^1.5.5",
113
113
  "@types/sortablejs": "^1.15.8",
114
114
  "async-validator": "^4.2.5",
115
- "axios": "^1.10.0",
115
+ "axios": "^1.11.0",
116
116
  "change-case": "^5.4.4",
117
117
  "drauu": "^0.4.3",
118
118
  "focus-trap": "^7.6.5",
@@ -122,7 +122,7 @@
122
122
  "nprogress": "^0.2.0",
123
123
  "qrcode": "^1.5.4",
124
124
  "sortablejs": "^1.15.6",
125
- "universal-cookie": "^7.2.2"
125
+ "universal-cookie": "^8.0.1"
126
126
  },
127
127
  "scripts": {
128
128
  "build": "rollup --config=rollup.config.ts --configPlugin=rollup-plugin-esbuild",
@@ -24,6 +24,7 @@
24
24
  acc[name] = fn;
25
25
  return acc;
26
26
  }, {});
27
+ // @__NO_SIDE_EFFECTS__
27
28
  function useChangeCase(input, type, options) {
28
29
  const typeRef = vue.computed(() => {
29
30
  const t = vue.toValue(type);
package/useChangeCase.mjs CHANGED
@@ -5,6 +5,7 @@ const changeCaseTransforms = /* @__PURE__ */ Object.entries(changeCase).filter((
5
5
  acc[name] = fn;
6
6
  return acc;
7
7
  }, {});
8
+ // @__NO_SIDE_EFFECTS__
8
9
  function useChangeCase(input, type, options) {
9
10
  const typeRef = computed(() => {
10
11
  const t = toValue(type);
package/useCookies.d.mts CHANGED
@@ -32,6 +32,8 @@ declare function createCookies(req?: IncomingMessage): (dependencies?: string[]
32
32
  * @param options.doNotParse - don't try parse value as JSON
33
33
  * @param options.autoUpdateDependencies - automatically update watching dependencies
34
34
  * @param cookies - universal-cookie instance
35
+ *
36
+ * @__NO_SIDE_EFFECTS__
35
37
  */
36
38
  declare function useCookies(dependencies?: string[] | null, { doNotParse, autoUpdateDependencies }?: {
37
39
  doNotParse?: boolean | undefined;
@@ -3,8 +3,9 @@
3
3
 
4
4
  function createCookies(req) {
5
5
  const universalCookie = new Cookie(req ? req.headers.cookie : null);
6
- return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
6
+ return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => /* @__PURE__ */ useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
7
7
  }
8
+ // @__NO_SIDE_EFFECTS__
8
9
  function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}, cookies = new Cookie()) {
9
10
  const watchingDependencies = autoUpdateDependencies ? [...dependencies || []] : dependencies;
10
11
  let previousCookies = cookies.getAll({ doNotParse: true });
package/useCookies.mjs CHANGED
@@ -4,8 +4,9 @@ import { shallowRef } from 'vue';
4
4
 
5
5
  function createCookies(req) {
6
6
  const universalCookie = new Cookie(req ? req.headers.cookie : null);
7
- return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
7
+ return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => /* @__PURE__ */ useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
8
8
  }
9
+ // @__NO_SIDE_EFFECTS__
9
10
  function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}, cookies = new Cookie()) {
10
11
  const watchingDependencies = autoUpdateDependencies ? [...dependencies || []] : dependencies;
11
12
  let previousCookies = cookies.getAll({ doNotParse: true });
@@ -49,7 +49,7 @@ interface UseFocusTrapReturn {
49
49
  *
50
50
  * @see https://vueuse.org/useFocusTrap
51
51
  */
52
- declare function useFocusTrap(target: Arrayable<MaybeRefOrGetter<string> | MaybeComputedElementRef>, options?: UseFocusTrapOptions): UseFocusTrapReturn;
52
+ declare function useFocusTrap(target: MaybeRefOrGetter<Arrayable<MaybeRefOrGetter<string> | MaybeComputedElementRef>>, options?: UseFocusTrapOptions): UseFocusTrapReturn;
53
53
 
54
54
  export { useFocusTrap };
55
55
  export type { UseFocusTrapOptions, UseFocusTrapReturn };
@@ -32,21 +32,29 @@
32
32
  (els) => {
33
33
  if (!els.length)
34
34
  return;
35
- trap = focusTrap.createFocusTrap(els, {
36
- ...focusTrapOptions,
37
- onActivate() {
38
- hasFocus.value = true;
39
- if (options.onActivate)
40
- options.onActivate();
41
- },
42
- onDeactivate() {
43
- hasFocus.value = false;
44
- if (options.onDeactivate)
45
- options.onDeactivate();
35
+ if (!trap) {
36
+ trap = focusTrap.createFocusTrap(els, {
37
+ ...focusTrapOptions,
38
+ onActivate() {
39
+ hasFocus.value = true;
40
+ if (options.onActivate)
41
+ options.onActivate();
42
+ },
43
+ onDeactivate() {
44
+ hasFocus.value = false;
45
+ if (options.onDeactivate)
46
+ options.onDeactivate();
47
+ }
48
+ });
49
+ if (immediate)
50
+ activate();
51
+ } else {
52
+ const isActive = trap == null ? void 0 : trap.active;
53
+ trap == null ? void 0 : trap.updateContainerElements(els);
54
+ if (!isActive && immediate) {
55
+ activate();
46
56
  }
47
- });
48
- if (immediate)
49
- activate();
57
+ }
50
58
  },
51
59
  { flush: "post" }
52
60
  );
@@ -1 +1 @@
1
- (function(l,u,f,p,a){"use strict";function h(v,s={}){let t;const{immediate:V,...d}=s,c=a.shallowRef(!1),n=a.shallowRef(!1),i=e=>t&&t.activate(e),r=e=>t&&t.deactivate(e),m=()=>{t&&(t.pause(),n.value=!0)},T=()=>{t&&(t.unpause(),n.value=!1)},g=a.computed(()=>{const e=a.toValue(v);return u.toArray(e).map(A=>{const o=a.toValue(A);return typeof o=="string"?o:u.unrefElement(o)}).filter(f.notNullish)});return a.watch(g,e=>{e.length&&(t=p.createFocusTrap(e,{...d,onActivate(){c.value=!0,s.onActivate&&s.onActivate()},onDeactivate(){c.value=!1,s.onDeactivate&&s.onDeactivate()}}),V&&i())},{flush:"post"}),u.tryOnScopeDispose(()=>r()),{hasFocus:c,isPaused:n,activate:i,deactivate:r,pause:m,unpause:T}}l.useFocusTrap=h})(this.VueUse=this.VueUse||{},VueUse,VueUse,focusTrap,Vue);
1
+ (function(p,u,v,h,a){"use strict";function d(V,s={}){let e;const{immediate:r,...m}=s,n=a.shallowRef(!1),c=a.shallowRef(!1),i=t=>e&&e.activate(t),f=t=>e&&e.deactivate(t),A=()=>{e&&(e.pause(),c.value=!0)},T=()=>{e&&(e.unpause(),c.value=!1)},g=a.computed(()=>{const t=a.toValue(V);return u.toArray(t).map(o=>{const l=a.toValue(o);return typeof l=="string"?l:u.unrefElement(l)}).filter(v.notNullish)});return a.watch(g,t=>{if(t.length)if(!e)e=h.createFocusTrap(t,{...m,onActivate(){n.value=!0,s.onActivate&&s.onActivate()},onDeactivate(){n.value=!1,s.onDeactivate&&s.onDeactivate()}}),r&&i();else{const o=e?.active;e?.updateContainerElements(t),!o&&r&&i()}},{flush:"post"}),u.tryOnScopeDispose(()=>f()),{hasFocus:n,isPaused:c,activate:i,deactivate:f,pause:A,unpause:T}}p.useFocusTrap=d})(this.VueUse=this.VueUse||{},VueUse,VueUse,focusTrap,Vue);
package/useFocusTrap.mjs CHANGED
@@ -34,21 +34,29 @@ function useFocusTrap(target, options = {}) {
34
34
  (els) => {
35
35
  if (!els.length)
36
36
  return;
37
- trap = createFocusTrap(els, {
38
- ...focusTrapOptions,
39
- onActivate() {
40
- hasFocus.value = true;
41
- if (options.onActivate)
42
- options.onActivate();
43
- },
44
- onDeactivate() {
45
- hasFocus.value = false;
46
- if (options.onDeactivate)
47
- options.onDeactivate();
37
+ if (!trap) {
38
+ trap = createFocusTrap(els, {
39
+ ...focusTrapOptions,
40
+ onActivate() {
41
+ hasFocus.value = true;
42
+ if (options.onActivate)
43
+ options.onActivate();
44
+ },
45
+ onDeactivate() {
46
+ hasFocus.value = false;
47
+ if (options.onDeactivate)
48
+ options.onDeactivate();
49
+ }
50
+ });
51
+ if (immediate)
52
+ activate();
53
+ } else {
54
+ const isActive = trap == null ? void 0 : trap.active;
55
+ trap == null ? void 0 : trap.updateContainerElements(els);
56
+ if (!isActive && immediate) {
57
+ activate();
48
58
  }
49
- });
50
- if (immediate)
51
- activate();
59
+ }
52
60
  },
53
61
  { flush: "post" }
54
62
  );
@@ -1,7 +1,11 @@
1
1
  import { ConfigurableFlush, RemovableRef } from '@vueuse/shared';
2
2
  import { ShallowRef, MaybeRefOrGetter } from 'vue';
3
3
 
4
- interface UseIDBOptions extends ConfigurableFlush {
4
+ interface Serializer<T> {
5
+ read: (raw: unknown) => T;
6
+ write: (value: T) => unknown;
7
+ }
8
+ interface UseIDBOptions<T> extends ConfigurableFlush {
5
9
  /**
6
10
  * Watch for deep changes
7
11
  *
@@ -26,6 +30,10 @@ interface UseIDBOptions extends ConfigurableFlush {
26
30
  * @default true
27
31
  */
28
32
  writeDefaults?: boolean;
33
+ /**
34
+ * Custom data serialization
35
+ */
36
+ serializer?: Serializer<T>;
29
37
  }
30
38
  interface UseIDBKeyvalReturn<T> {
31
39
  data: RemovableRef<T>;
@@ -38,7 +46,7 @@ interface UseIDBKeyvalReturn<T> {
38
46
  * @param initialValue
39
47
  * @param options
40
48
  */
41
- declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeRefOrGetter<T>, options?: UseIDBOptions): UseIDBKeyvalReturn<T>;
49
+ declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeRefOrGetter<T>, options?: UseIDBOptions<T>): UseIDBKeyvalReturn<T>;
42
50
 
43
51
  export { useIDBKeyval };
44
52
  export type { UseIDBKeyvalReturn, UseIDBOptions };
@@ -9,7 +9,11 @@
9
9
  onError = (e) => {
10
10
  console.error(e);
11
11
  },
12
- writeDefaults = true
12
+ writeDefaults = true,
13
+ serializer = {
14
+ read: (raw) => raw,
15
+ write: (value) => value
16
+ }
13
17
  } = options;
14
18
  const isFinished = vue.shallowRef(false);
15
19
  const data = (shallow ? vue.shallowRef : vue.ref)(initialValue);
@@ -18,10 +22,12 @@
18
22
  try {
19
23
  const rawValue = await idbKeyval.get(key);
20
24
  if (rawValue === void 0) {
21
- if (rawInit !== void 0 && rawInit !== null && writeDefaults)
22
- await idbKeyval.set(key, rawInit);
25
+ if (rawInit !== void 0 && rawInit !== null && writeDefaults) {
26
+ const initValue = serializer.write(rawInit);
27
+ await idbKeyval.set(key, initValue);
28
+ }
23
29
  } else {
24
- data.value = rawValue;
30
+ data.value = serializer.read(rawValue);
25
31
  }
26
32
  } catch (e) {
27
33
  onError(e);
@@ -34,7 +40,9 @@
34
40
  if (data.value == null) {
35
41
  await idbKeyval.del(key);
36
42
  } else {
37
- await idbKeyval.update(key, () => vue.toRaw(data.value));
43
+ const rawValue = vue.toRaw(data.value);
44
+ const serializedValue = serializer.write(rawValue);
45
+ await idbKeyval.update(key, () => serializedValue);
38
46
  }
39
47
  } catch (e) {
40
48
  onError(e);
@@ -1 +1 @@
1
- (function(i,f,s,a){"use strict";function w(u,l,h={}){const{flush:d="pre",deep:p=!0,shallow:V=!1,onError:c=e=>{console.error(e)},writeDefaults:D=!0}=h,o=a.shallowRef(!1),t=(V?a.shallowRef:a.ref)(l),n=a.toValue(l);async function v(){try{const e=await s.get(u);e===void 0?n!=null&&D&&await s.set(u,n):t.value=e}catch(e){c(e)}o.value=!0}v();async function r(){try{t.value==null?await s.del(u):await s.update(u,()=>a.toRaw(t.value))}catch(e){c(e)}}const{pause:I,resume:R}=f.watchPausable(t,()=>r(),{flush:d,deep:p});async function U(e){I(),t.value=e,await r(),R()}return{set:U,isFinished:o,data:t}}i.useIDBKeyval=w})(this.VueUse=this.VueUse||{},VueUse,idbKeyval,Vue);
1
+ (function(f,h,s,t){"use strict";function d(r,i,V={}){const{flush:p="pre",deep:D=!0,shallow:v=!1,onError:c=e=>{console.error(e)},writeDefaults:I=!0,serializer:u={read:e=>e,write:e=>e}}=V,o=t.shallowRef(!1),a=(v?t.shallowRef:t.ref)(i),l=t.toValue(i);async function R(){try{const e=await s.get(r);if(e===void 0){if(l!=null&&I){const n=u.write(l);await s.set(r,n)}}else a.value=u.read(e)}catch(e){c(e)}o.value=!0}R();async function w(){try{if(a.value==null)await s.del(r);else{const e=t.toRaw(a.value),n=u.write(e);await s.update(r,()=>n)}}catch(e){c(e)}}const{pause:U,resume:m}=h.watchPausable(a,()=>w(),{flush:p,deep:D});async function y(e){U(),a.value=e,await w(),m()}return{set:y,isFinished:o,data:a}}f.useIDBKeyval=d})(this.VueUse=this.VueUse||{},VueUse,idbKeyval,Vue);
package/useIDBKeyval.mjs CHANGED
@@ -10,7 +10,11 @@ function useIDBKeyval(key, initialValue, options = {}) {
10
10
  onError = (e) => {
11
11
  console.error(e);
12
12
  },
13
- writeDefaults = true
13
+ writeDefaults = true,
14
+ serializer = {
15
+ read: (raw) => raw,
16
+ write: (value) => value
17
+ }
14
18
  } = options;
15
19
  const isFinished = shallowRef(false);
16
20
  const data = (shallow ? shallowRef : ref)(initialValue);
@@ -19,10 +23,12 @@ function useIDBKeyval(key, initialValue, options = {}) {
19
23
  try {
20
24
  const rawValue = await get(key);
21
25
  if (rawValue === void 0) {
22
- if (rawInit !== void 0 && rawInit !== null && writeDefaults)
23
- await set(key, rawInit);
26
+ if (rawInit !== void 0 && rawInit !== null && writeDefaults) {
27
+ const initValue = serializer.write(rawInit);
28
+ await set(key, initValue);
29
+ }
24
30
  } else {
25
- data.value = rawValue;
31
+ data.value = serializer.read(rawValue);
26
32
  }
27
33
  } catch (e) {
28
34
  onError(e);
@@ -35,7 +41,9 @@ function useIDBKeyval(key, initialValue, options = {}) {
35
41
  if (data.value == null) {
36
42
  await del(key);
37
43
  } else {
38
- await update(key, () => toRaw(data.value));
44
+ const rawValue = toRaw(data.value);
45
+ const serializedValue = serializer.write(rawValue);
46
+ await update(key, () => serializedValue);
39
47
  }
40
48
  } catch (e) {
41
49
  onError(e);