@vueuse/integrations 9.4.0 → 9.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/README.md CHANGED
@@ -21,6 +21,7 @@ npm i <b>@vueuse/integrations</b>
21
21
  - [`useDrauu`](https://vueuse.org/integrations/useDrauu/) — reactive instance for [drauu](https://github.com/antfu/drauu)
22
22
  - [`useFocusTrap`](https://vueuse.org/integrations/useFocusTrap/) — reactive wrapper for [`focus-trap`](https://github.com/focus-trap/focus-trap)
23
23
  - [`useFuse`](https://vueuse.org/integrations/useFuse/) — easily implement fuzzy search using a composable with [Fuse.js](https://github.com/krisk/fuse)
24
+ - [`useIDBKeyval`](https://vueuse.org/integrations/useIDBKeyval/) — wrapper for [`idb-keyval`](https://www.npmjs.com/package/idb-keyval)
24
25
  - [`useJwt`](https://vueuse.org/integrations/useJwt/) — wrapper for [`jwt-decode`](https://github.com/auth0/jwt-decode)
25
26
  - [`useNProgress`](https://vueuse.org/integrations/useNProgress/) — reactive wrapper for [`nprogress`](https://github.com/rstacruz/nprogress)
26
27
  - [`useQRCode`](https://vueuse.org/integrations/useQRCode/) — wrapper for [`qrcode`](https://github.com/soldair/node-qrcode)
package/index.cjs CHANGED
@@ -10,25 +10,26 @@ var drauu = require('drauu');
10
10
  var core = require('@vueuse/core');
11
11
  var focusTrap = require('focus-trap');
12
12
  var Fuse = require('fuse.js');
13
+ var idbKeyval = require('idb-keyval');
13
14
  var jwt_decode = require('jwt-decode');
14
15
  var nprogress = require('nprogress');
15
16
  var QRCode = require('qrcode');
16
17
 
17
- var __defProp$4 = Object.defineProperty;
18
+ var __defProp$5 = Object.defineProperty;
18
19
  var __defProps$2 = Object.defineProperties;
19
20
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
20
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
21
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
22
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
23
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
24
- var __spreadValues$4 = (a, b) => {
21
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
22
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
23
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
24
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
25
+ var __spreadValues$5 = (a, b) => {
25
26
  for (var prop in b || (b = {}))
26
- if (__hasOwnProp$4.call(b, prop))
27
- __defNormalProp$4(a, prop, b[prop]);
28
- if (__getOwnPropSymbols$4)
29
- for (var prop of __getOwnPropSymbols$4(b)) {
30
- if (__propIsEnum$4.call(b, prop))
31
- __defNormalProp$4(a, prop, b[prop]);
27
+ if (__hasOwnProp$5.call(b, prop))
28
+ __defNormalProp$5(a, prop, b[prop]);
29
+ if (__getOwnPropSymbols$5)
30
+ for (var prop of __getOwnPropSymbols$5(b)) {
31
+ if (__propIsEnum$5.call(b, prop))
32
+ __defNormalProp$5(a, prop, b[prop]);
32
33
  }
33
34
  return a;
34
35
  };
@@ -72,28 +73,28 @@ function useAsyncValidator(value, rules, options = {}) {
72
73
  shared.until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
73
74
  });
74
75
  }
75
- return __spreadProps$2(__spreadValues$4({}, shell), {
76
+ return __spreadProps$2(__spreadValues$5({}, shell), {
76
77
  then(onFulfilled, onRejected) {
77
78
  return waitUntilFinished().then(onFulfilled, onRejected);
78
79
  }
79
80
  });
80
81
  }
81
82
 
82
- var __defProp$3 = Object.defineProperty;
83
+ var __defProp$4 = Object.defineProperty;
83
84
  var __defProps$1 = Object.defineProperties;
84
85
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
85
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
86
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
87
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
88
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
89
- var __spreadValues$3 = (a, b) => {
86
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
87
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
88
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
89
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
90
+ var __spreadValues$4 = (a, b) => {
90
91
  for (var prop in b || (b = {}))
91
- if (__hasOwnProp$3.call(b, prop))
92
- __defNormalProp$3(a, prop, b[prop]);
93
- if (__getOwnPropSymbols$3)
94
- for (var prop of __getOwnPropSymbols$3(b)) {
95
- if (__propIsEnum$3.call(b, prop))
96
- __defNormalProp$3(a, prop, b[prop]);
92
+ if (__hasOwnProp$4.call(b, prop))
93
+ __defNormalProp$4(a, prop, b[prop]);
94
+ if (__getOwnPropSymbols$4)
95
+ for (var prop of __getOwnPropSymbols$4(b)) {
96
+ if (__propIsEnum$4.call(b, prop))
97
+ __defNormalProp$4(a, prop, b[prop]);
97
98
  }
98
99
  return a;
99
100
  };
@@ -144,7 +145,7 @@ function useAxios(...args) {
144
145
  error.value = void 0;
145
146
  const _url = typeof executeUrl === "string" ? executeUrl : url != null ? url : "";
146
147
  loading(true);
147
- instance(_url, __spreadProps$1(__spreadValues$3(__spreadValues$3({}, defaultConfig), typeof executeUrl === "object" ? executeUrl : config), { cancelToken: cancelToken.token })).then((r) => {
148
+ instance(_url, __spreadProps$1(__spreadValues$4(__spreadValues$4({}, defaultConfig), typeof executeUrl === "object" ? executeUrl : config), { cancelToken: cancelToken.token })).then((r) => {
148
149
  response.value = r;
149
150
  data.value = r.data;
150
151
  }).catch((e) => {
@@ -170,7 +171,7 @@ function useAxios(...args) {
170
171
  abort,
171
172
  execute
172
173
  };
173
- return __spreadProps$1(__spreadValues$3({}, result), {
174
+ return __spreadProps$1(__spreadValues$4({}, result), {
174
175
  then
175
176
  });
176
177
  }
@@ -204,19 +205,19 @@ function useChangeCase(input, type, options) {
204
205
  });
205
206
  }
206
207
 
207
- var __defProp$2 = Object.defineProperty;
208
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
209
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
210
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
211
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
212
- var __spreadValues$2 = (a, b) => {
208
+ var __defProp$3 = Object.defineProperty;
209
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
210
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
211
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
212
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
213
+ var __spreadValues$3 = (a, b) => {
213
214
  for (var prop in b || (b = {}))
214
- if (__hasOwnProp$2.call(b, prop))
215
- __defNormalProp$2(a, prop, b[prop]);
216
- if (__getOwnPropSymbols$2)
217
- for (var prop of __getOwnPropSymbols$2(b)) {
218
- if (__propIsEnum$2.call(b, prop))
219
- __defNormalProp$2(a, prop, b[prop]);
215
+ if (__hasOwnProp$3.call(b, prop))
216
+ __defNormalProp$3(a, prop, b[prop]);
217
+ if (__getOwnPropSymbols$3)
218
+ for (var prop of __getOwnPropSymbols$3(b)) {
219
+ if (__propIsEnum$3.call(b, prop))
220
+ __defNormalProp$3(a, prop, b[prop]);
220
221
  }
221
222
  return a;
222
223
  };
@@ -243,11 +244,11 @@ function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies =
243
244
  if (autoUpdateDependencies && watchingDependencies && !watchingDependencies.includes(args[0]))
244
245
  watchingDependencies.push(args[0]);
245
246
  touches.value;
246
- return cookies.get(args[0], __spreadValues$2({ doNotParse }, args[1]));
247
+ return cookies.get(args[0], __spreadValues$3({ doNotParse }, args[1]));
247
248
  },
248
249
  getAll: (...args) => {
249
250
  touches.value;
250
- return cookies.getAll(__spreadValues$2({ doNotParse }, args[0]));
251
+ return cookies.getAll(__spreadValues$3({ doNotParse }, args[0]));
251
252
  },
252
253
  set: (...args) => cookies.set(...args),
253
254
  remove: (...args) => cookies.remove(...args),
@@ -265,19 +266,19 @@ function shouldUpdate(dependencies, newCookies, oldCookies) {
265
266
  return false;
266
267
  }
267
268
 
268
- var __defProp$1 = Object.defineProperty;
269
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
270
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
271
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
272
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
273
- var __spreadValues$1 = (a, b) => {
269
+ var __defProp$2 = Object.defineProperty;
270
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
271
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
272
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
273
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
274
+ var __spreadValues$2 = (a, b) => {
274
275
  for (var prop in b || (b = {}))
275
- if (__hasOwnProp$1.call(b, prop))
276
- __defNormalProp$1(a, prop, b[prop]);
277
- if (__getOwnPropSymbols$1)
278
- for (var prop of __getOwnPropSymbols$1(b)) {
279
- if (__propIsEnum$1.call(b, prop))
280
- __defNormalProp$1(a, prop, b[prop]);
276
+ if (__hasOwnProp$2.call(b, prop))
277
+ __defNormalProp$2(a, prop, b[prop]);
278
+ if (__getOwnPropSymbols$2)
279
+ for (var prop of __getOwnPropSymbols$2(b)) {
280
+ if (__propIsEnum$2.call(b, prop))
281
+ __defNormalProp$2(a, prop, b[prop]);
281
282
  }
282
283
  return a;
283
284
  };
@@ -351,7 +352,7 @@ function useDrauu(target, options) {
351
352
  return;
352
353
  if (drauuInstance.value)
353
354
  cleanup();
354
- drauuInstance.value = drauu.createDrauu(__spreadValues$1({ el }, options));
355
+ drauuInstance.value = drauu.createDrauu(__spreadValues$2({ el }, options));
355
356
  syncStatus();
356
357
  disposables = [
357
358
  drauuInstance.value.on("canceled", () => onCanceledHook.trigger()),
@@ -384,21 +385,21 @@ function useDrauu(target, options) {
384
385
  };
385
386
  }
386
387
 
387
- var __defProp = Object.defineProperty;
388
+ var __defProp$1 = Object.defineProperty;
388
389
  var __defProps = Object.defineProperties;
389
390
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
390
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
391
- var __hasOwnProp = Object.prototype.hasOwnProperty;
392
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
393
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
394
- var __spreadValues = (a, b) => {
391
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
392
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
393
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
394
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
+ var __spreadValues$1 = (a, b) => {
395
396
  for (var prop in b || (b = {}))
396
- if (__hasOwnProp.call(b, prop))
397
- __defNormalProp(a, prop, b[prop]);
398
- if (__getOwnPropSymbols)
399
- for (var prop of __getOwnPropSymbols(b)) {
400
- if (__propIsEnum.call(b, prop))
401
- __defNormalProp(a, prop, b[prop]);
397
+ if (__hasOwnProp$1.call(b, prop))
398
+ __defNormalProp$1(a, prop, b[prop]);
399
+ if (__getOwnPropSymbols$1)
400
+ for (var prop of __getOwnPropSymbols$1(b)) {
401
+ if (__propIsEnum$1.call(b, prop))
402
+ __defNormalProp$1(a, prop, b[prop]);
402
403
  }
403
404
  return a;
404
405
  };
@@ -406,11 +407,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
406
407
  var __objRest = (source, exclude) => {
407
408
  var target = {};
408
409
  for (var prop in source)
409
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
410
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
410
411
  target[prop] = source[prop];
411
- if (source != null && __getOwnPropSymbols)
412
- for (var prop of __getOwnPropSymbols(source)) {
413
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
412
+ if (source != null && __getOwnPropSymbols$1)
413
+ for (var prop of __getOwnPropSymbols$1(source)) {
414
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
414
415
  target[prop] = source[prop];
415
416
  }
416
417
  return target;
@@ -437,7 +438,7 @@ function useFocusTrap(target, options = {}) {
437
438
  vueDemi.watch(() => core.unrefElement(target), (el) => {
438
439
  if (!el)
439
440
  return;
440
- trap = focusTrap.createFocusTrap(el, __spreadProps(__spreadValues({}, focusTrapOptions), {
441
+ trap = focusTrap.createFocusTrap(el, __spreadProps(__spreadValues$1({}, focusTrapOptions), {
441
442
  onActivate() {
442
443
  hasFocus.value = true;
443
444
  if (options.onActivate)
@@ -491,6 +492,67 @@ function useFuse(search, data, options) {
491
492
  };
492
493
  }
493
494
 
495
+ var __defProp = Object.defineProperty;
496
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
497
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
498
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
499
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
500
+ var __spreadValues = (a, b) => {
501
+ for (var prop in b || (b = {}))
502
+ if (__hasOwnProp.call(b, prop))
503
+ __defNormalProp(a, prop, b[prop]);
504
+ if (__getOwnPropSymbols)
505
+ for (var prop of __getOwnPropSymbols(b)) {
506
+ if (__propIsEnum.call(b, prop))
507
+ __defNormalProp(a, prop, b[prop]);
508
+ }
509
+ return a;
510
+ };
511
+ function useIDBKeyval(key, initialValue, options = {}) {
512
+ const {
513
+ flush = "pre",
514
+ deep = true,
515
+ shallow,
516
+ onError = (e) => {
517
+ console.error(e);
518
+ }
519
+ } = options;
520
+ const data = (shallow ? vueDemi.shallowRef : vueDemi.ref)(initialValue);
521
+ const rawInit = shared.resolveUnref(initialValue);
522
+ async function read() {
523
+ try {
524
+ const rawValue = await idbKeyval.get(key);
525
+ if (rawValue === void 0) {
526
+ if (rawInit !== void 0 && rawInit !== null)
527
+ await idbKeyval.set(key, rawInit);
528
+ } else {
529
+ data.value = rawValue;
530
+ }
531
+ } catch (e) {
532
+ onError(e);
533
+ }
534
+ }
535
+ read();
536
+ async function write() {
537
+ try {
538
+ if (data.value == null) {
539
+ await idbKeyval.del(key);
540
+ } else {
541
+ if (Array.isArray(data.value))
542
+ await idbKeyval.update(key, () => JSON.parse(JSON.stringify(data.value)));
543
+ else if (typeof data.value === "object")
544
+ await idbKeyval.update(key, () => __spreadValues({}, data.value));
545
+ else
546
+ await idbKeyval.update(key, () => data.value);
547
+ }
548
+ } catch (e) {
549
+ onError(e);
550
+ }
551
+ }
552
+ vueDemi.watch(data, () => write(), { flush, deep });
553
+ return data;
554
+ }
555
+
494
556
  function useJwt(encodedJwt, options = {}) {
495
557
  const {
496
558
  onError,
@@ -560,6 +622,7 @@ exports.useCookies = useCookies;
560
622
  exports.useDrauu = useDrauu;
561
623
  exports.useFocusTrap = useFocusTrap;
562
624
  exports.useFuse = useFuse;
625
+ exports.useIDBKeyval = useIDBKeyval;
563
626
  exports.useJwt = useJwt;
564
627
  exports.useNProgress = useNProgress;
565
628
  exports.useQRCode = useQRCode;
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MaybeComputedRef, MaybeRef } from '@vueuse/shared';
1
+ import { MaybeComputedRef, MaybeRef, ConfigurableFlush, RemovableRef } from '@vueuse/shared';
2
2
  import { ValidateError, ValidateOption, Rules } from 'async-validator';
3
3
  import * as vue_demi from 'vue-demi';
4
4
  import { Ref, ShallowRef, WritableComputedRef, ComputedRef } from 'vue-demi';
@@ -308,6 +308,34 @@ declare function useFuse<DataItem>(search: MaybeComputedRef<string>, data: Maybe
308
308
  };
309
309
  declare type UseFuseReturn = ReturnType<typeof useFuse>;
310
310
 
311
+ interface UseIDBOptions extends ConfigurableFlush {
312
+ /**
313
+ * Watch for deep changes
314
+ *
315
+ * @default true
316
+ */
317
+ deep?: boolean;
318
+ /**
319
+ * On error callback
320
+ *
321
+ * Default log error to `console.error`
322
+ */
323
+ onError?: (error: unknown) => void;
324
+ /**
325
+ * Use shallow ref as reference
326
+ *
327
+ * @default false
328
+ */
329
+ shallow?: boolean;
330
+ }
331
+ /**
332
+ *
333
+ * @param key
334
+ * @param initialValue
335
+ * @param options
336
+ */
337
+ declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeComputedRef<T>, options?: UseIDBOptions): RemovableRef<T>;
338
+
311
339
  interface UseJwtOptions<Fallback> {
312
340
  /**
313
341
  * Value returned when encounter error on decoding
@@ -356,4 +384,4 @@ declare type UseNProgressReturn = ReturnType<typeof useNProgress>;
356
384
  */
357
385
  declare function useQRCode(text: MaybeComputedRef<string>, options?: QRCode.QRCodeToDataURLOptions): vue_demi.Ref<string>;
358
386
 
359
- export { AsyncValidatorError, ChangeCaseType, EasyUseAxiosReturn, FuseOptions, StrictUseAxiosReturn, UseAsyncValidatorOptions, UseAsyncValidatorReturn, UseAxiosOptions, UseAxiosReturn, UseDrauuOptions, UseDrauuReturn, UseFocusTrapOptions, UseFocusTrapReturn, UseFuseOptions, UseFuseReturn, UseJwtOptions, UseJwtReturn, UseNProgressOptions, UseNProgressReturn, createCookies, useAsyncValidator, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useJwt, useNProgress, useQRCode };
387
+ export { AsyncValidatorError, ChangeCaseType, EasyUseAxiosReturn, FuseOptions, StrictUseAxiosReturn, UseAsyncValidatorOptions, UseAsyncValidatorReturn, UseAxiosOptions, UseAxiosReturn, UseDrauuOptions, UseDrauuReturn, UseFocusTrapOptions, UseFocusTrapReturn, UseFuseOptions, UseFuseReturn, UseIDBOptions, UseJwtOptions, UseJwtReturn, UseNProgressOptions, UseNProgressReturn, createCookies, useAsyncValidator, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useIDBKeyval, useJwt, useNProgress, useQRCode };