@vueuse/integrations 9.3.1 → 9.5.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 +1 -0
- package/index.cjs +134 -71
- package/index.d.ts +30 -2
- package/index.iife.js +135 -73
- package/index.iife.min.js +1 -1
- package/index.mjs +134 -72
- package/package.json +13 -3
- package/useIDBKeyval.cjs +68 -0
- package/useIDBKeyval.d.ts +31 -0
- package/useIDBKeyval.iife.js +181 -0
- package/useIDBKeyval.iife.min.js +1 -0
- package/useIDBKeyval.mjs +66 -0
package/index.mjs
CHANGED
|
@@ -8,25 +8,26 @@ import { createDrauu } from 'drauu';
|
|
|
8
8
|
import { createEventHook, unrefElement, tryOnScopeDispose as tryOnScopeDispose$1 } from '@vueuse/core';
|
|
9
9
|
import { createFocusTrap } from 'focus-trap';
|
|
10
10
|
import Fuse from 'fuse.js';
|
|
11
|
+
import { get, set, del, update } from 'idb-keyval';
|
|
11
12
|
import jwt_decode from 'jwt-decode';
|
|
12
13
|
import nprogress from 'nprogress';
|
|
13
14
|
import QRCode from 'qrcode';
|
|
14
15
|
|
|
15
|
-
var __defProp$
|
|
16
|
+
var __defProp$5 = Object.defineProperty;
|
|
16
17
|
var __defProps$2 = Object.defineProperties;
|
|
17
18
|
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
18
|
-
var __getOwnPropSymbols$
|
|
19
|
-
var __hasOwnProp$
|
|
20
|
-
var __propIsEnum$
|
|
21
|
-
var __defNormalProp$
|
|
22
|
-
var __spreadValues$
|
|
19
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
20
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
21
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
22
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
23
|
+
var __spreadValues$5 = (a, b) => {
|
|
23
24
|
for (var prop in b || (b = {}))
|
|
24
|
-
if (__hasOwnProp$
|
|
25
|
-
__defNormalProp$
|
|
26
|
-
if (__getOwnPropSymbols$
|
|
27
|
-
for (var prop of __getOwnPropSymbols$
|
|
28
|
-
if (__propIsEnum$
|
|
29
|
-
__defNormalProp$
|
|
25
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
26
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
27
|
+
if (__getOwnPropSymbols$5)
|
|
28
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
29
|
+
if (__propIsEnum$5.call(b, prop))
|
|
30
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
30
31
|
}
|
|
31
32
|
return a;
|
|
32
33
|
};
|
|
@@ -70,28 +71,28 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
70
71
|
until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
|
-
return __spreadProps$2(__spreadValues$
|
|
74
|
+
return __spreadProps$2(__spreadValues$5({}, shell), {
|
|
74
75
|
then(onFulfilled, onRejected) {
|
|
75
76
|
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
var __defProp$
|
|
81
|
+
var __defProp$4 = Object.defineProperty;
|
|
81
82
|
var __defProps$1 = Object.defineProperties;
|
|
82
83
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
83
|
-
var __getOwnPropSymbols$
|
|
84
|
-
var __hasOwnProp$
|
|
85
|
-
var __propIsEnum$
|
|
86
|
-
var __defNormalProp$
|
|
87
|
-
var __spreadValues$
|
|
84
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
85
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
86
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
87
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
88
|
+
var __spreadValues$4 = (a, b) => {
|
|
88
89
|
for (var prop in b || (b = {}))
|
|
89
|
-
if (__hasOwnProp$
|
|
90
|
-
__defNormalProp$
|
|
91
|
-
if (__getOwnPropSymbols$
|
|
92
|
-
for (var prop of __getOwnPropSymbols$
|
|
93
|
-
if (__propIsEnum$
|
|
94
|
-
__defNormalProp$
|
|
90
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
91
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
92
|
+
if (__getOwnPropSymbols$4)
|
|
93
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
94
|
+
if (__propIsEnum$4.call(b, prop))
|
|
95
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
95
96
|
}
|
|
96
97
|
return a;
|
|
97
98
|
};
|
|
@@ -142,7 +143,7 @@ function useAxios(...args) {
|
|
|
142
143
|
error.value = void 0;
|
|
143
144
|
const _url = typeof executeUrl === "string" ? executeUrl : url != null ? url : "";
|
|
144
145
|
loading(true);
|
|
145
|
-
instance(_url, __spreadProps$1(__spreadValues$
|
|
146
|
+
instance(_url, __spreadProps$1(__spreadValues$4(__spreadValues$4({}, defaultConfig), typeof executeUrl === "object" ? executeUrl : config), { cancelToken: cancelToken.token })).then((r) => {
|
|
146
147
|
response.value = r;
|
|
147
148
|
data.value = r.data;
|
|
148
149
|
}).catch((e) => {
|
|
@@ -168,7 +169,7 @@ function useAxios(...args) {
|
|
|
168
169
|
abort,
|
|
169
170
|
execute
|
|
170
171
|
};
|
|
171
|
-
return __spreadProps$1(__spreadValues$
|
|
172
|
+
return __spreadProps$1(__spreadValues$4({}, result), {
|
|
172
173
|
then
|
|
173
174
|
});
|
|
174
175
|
}
|
|
@@ -202,19 +203,19 @@ function useChangeCase(input, type, options) {
|
|
|
202
203
|
});
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
var __defProp$
|
|
206
|
-
var __getOwnPropSymbols$
|
|
207
|
-
var __hasOwnProp$
|
|
208
|
-
var __propIsEnum$
|
|
209
|
-
var __defNormalProp$
|
|
210
|
-
var __spreadValues$
|
|
206
|
+
var __defProp$3 = Object.defineProperty;
|
|
207
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
208
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
209
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
210
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
211
|
+
var __spreadValues$3 = (a, b) => {
|
|
211
212
|
for (var prop in b || (b = {}))
|
|
212
|
-
if (__hasOwnProp$
|
|
213
|
-
__defNormalProp$
|
|
214
|
-
if (__getOwnPropSymbols$
|
|
215
|
-
for (var prop of __getOwnPropSymbols$
|
|
216
|
-
if (__propIsEnum$
|
|
217
|
-
__defNormalProp$
|
|
213
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
214
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
215
|
+
if (__getOwnPropSymbols$3)
|
|
216
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
217
|
+
if (__propIsEnum$3.call(b, prop))
|
|
218
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
218
219
|
}
|
|
219
220
|
return a;
|
|
220
221
|
};
|
|
@@ -241,11 +242,11 @@ function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies =
|
|
|
241
242
|
if (autoUpdateDependencies && watchingDependencies && !watchingDependencies.includes(args[0]))
|
|
242
243
|
watchingDependencies.push(args[0]);
|
|
243
244
|
touches.value;
|
|
244
|
-
return cookies.get(args[0], __spreadValues$
|
|
245
|
+
return cookies.get(args[0], __spreadValues$3({ doNotParse }, args[1]));
|
|
245
246
|
},
|
|
246
247
|
getAll: (...args) => {
|
|
247
248
|
touches.value;
|
|
248
|
-
return cookies.getAll(__spreadValues$
|
|
249
|
+
return cookies.getAll(__spreadValues$3({ doNotParse }, args[0]));
|
|
249
250
|
},
|
|
250
251
|
set: (...args) => cookies.set(...args),
|
|
251
252
|
remove: (...args) => cookies.remove(...args),
|
|
@@ -263,19 +264,19 @@ function shouldUpdate(dependencies, newCookies, oldCookies) {
|
|
|
263
264
|
return false;
|
|
264
265
|
}
|
|
265
266
|
|
|
266
|
-
var __defProp$
|
|
267
|
-
var __getOwnPropSymbols$
|
|
268
|
-
var __hasOwnProp$
|
|
269
|
-
var __propIsEnum$
|
|
270
|
-
var __defNormalProp$
|
|
271
|
-
var __spreadValues$
|
|
267
|
+
var __defProp$2 = Object.defineProperty;
|
|
268
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
269
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
270
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
271
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
272
|
+
var __spreadValues$2 = (a, b) => {
|
|
272
273
|
for (var prop in b || (b = {}))
|
|
273
|
-
if (__hasOwnProp$
|
|
274
|
-
__defNormalProp$
|
|
275
|
-
if (__getOwnPropSymbols$
|
|
276
|
-
for (var prop of __getOwnPropSymbols$
|
|
277
|
-
if (__propIsEnum$
|
|
278
|
-
__defNormalProp$
|
|
274
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
275
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
276
|
+
if (__getOwnPropSymbols$2)
|
|
277
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
278
|
+
if (__propIsEnum$2.call(b, prop))
|
|
279
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
279
280
|
}
|
|
280
281
|
return a;
|
|
281
282
|
};
|
|
@@ -349,7 +350,7 @@ function useDrauu(target, options) {
|
|
|
349
350
|
return;
|
|
350
351
|
if (drauuInstance.value)
|
|
351
352
|
cleanup();
|
|
352
|
-
drauuInstance.value = createDrauu(__spreadValues$
|
|
353
|
+
drauuInstance.value = createDrauu(__spreadValues$2({ el }, options));
|
|
353
354
|
syncStatus();
|
|
354
355
|
disposables = [
|
|
355
356
|
drauuInstance.value.on("canceled", () => onCanceledHook.trigger()),
|
|
@@ -382,21 +383,21 @@ function useDrauu(target, options) {
|
|
|
382
383
|
};
|
|
383
384
|
}
|
|
384
385
|
|
|
385
|
-
var __defProp = Object.defineProperty;
|
|
386
|
+
var __defProp$1 = Object.defineProperty;
|
|
386
387
|
var __defProps = Object.defineProperties;
|
|
387
388
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
388
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
389
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
390
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
391
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
392
|
-
var __spreadValues = (a, b) => {
|
|
389
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
390
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
391
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
392
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
393
|
+
var __spreadValues$1 = (a, b) => {
|
|
393
394
|
for (var prop in b || (b = {}))
|
|
394
|
-
if (__hasOwnProp.call(b, prop))
|
|
395
|
-
__defNormalProp(a, prop, b[prop]);
|
|
396
|
-
if (__getOwnPropSymbols)
|
|
397
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
398
|
-
if (__propIsEnum.call(b, prop))
|
|
399
|
-
__defNormalProp(a, prop, b[prop]);
|
|
395
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
396
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
397
|
+
if (__getOwnPropSymbols$1)
|
|
398
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
399
|
+
if (__propIsEnum$1.call(b, prop))
|
|
400
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
400
401
|
}
|
|
401
402
|
return a;
|
|
402
403
|
};
|
|
@@ -404,11 +405,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
404
405
|
var __objRest = (source, exclude) => {
|
|
405
406
|
var target = {};
|
|
406
407
|
for (var prop in source)
|
|
407
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
408
|
+
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
408
409
|
target[prop] = source[prop];
|
|
409
|
-
if (source != null && __getOwnPropSymbols)
|
|
410
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
411
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
410
|
+
if (source != null && __getOwnPropSymbols$1)
|
|
411
|
+
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
412
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
412
413
|
target[prop] = source[prop];
|
|
413
414
|
}
|
|
414
415
|
return target;
|
|
@@ -435,7 +436,7 @@ function useFocusTrap(target, options = {}) {
|
|
|
435
436
|
watch(() => unrefElement(target), (el) => {
|
|
436
437
|
if (!el)
|
|
437
438
|
return;
|
|
438
|
-
trap = createFocusTrap(el, __spreadProps(__spreadValues({}, focusTrapOptions), {
|
|
439
|
+
trap = createFocusTrap(el, __spreadProps(__spreadValues$1({}, focusTrapOptions), {
|
|
439
440
|
onActivate() {
|
|
440
441
|
hasFocus.value = true;
|
|
441
442
|
if (options.onActivate)
|
|
@@ -489,6 +490,67 @@ function useFuse(search, data, options) {
|
|
|
489
490
|
};
|
|
490
491
|
}
|
|
491
492
|
|
|
493
|
+
var __defProp = Object.defineProperty;
|
|
494
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
495
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
496
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
497
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
498
|
+
var __spreadValues = (a, b) => {
|
|
499
|
+
for (var prop in b || (b = {}))
|
|
500
|
+
if (__hasOwnProp.call(b, prop))
|
|
501
|
+
__defNormalProp(a, prop, b[prop]);
|
|
502
|
+
if (__getOwnPropSymbols)
|
|
503
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
504
|
+
if (__propIsEnum.call(b, prop))
|
|
505
|
+
__defNormalProp(a, prop, b[prop]);
|
|
506
|
+
}
|
|
507
|
+
return a;
|
|
508
|
+
};
|
|
509
|
+
function useIDBKeyval(key, initialValue, options = {}) {
|
|
510
|
+
const {
|
|
511
|
+
flush = "pre",
|
|
512
|
+
deep = true,
|
|
513
|
+
shallow,
|
|
514
|
+
onError = (e) => {
|
|
515
|
+
console.error(e);
|
|
516
|
+
}
|
|
517
|
+
} = options;
|
|
518
|
+
const data = (shallow ? shallowRef : ref)(initialValue);
|
|
519
|
+
const rawInit = resolveUnref(initialValue);
|
|
520
|
+
async function read() {
|
|
521
|
+
try {
|
|
522
|
+
const rawValue = await get(key);
|
|
523
|
+
if (rawValue === void 0) {
|
|
524
|
+
if (rawInit)
|
|
525
|
+
set(key, rawInit);
|
|
526
|
+
} else {
|
|
527
|
+
data.value = rawValue;
|
|
528
|
+
}
|
|
529
|
+
} catch (e) {
|
|
530
|
+
onError(e);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
read();
|
|
534
|
+
async function write() {
|
|
535
|
+
try {
|
|
536
|
+
if (data.value == null) {
|
|
537
|
+
await del(key);
|
|
538
|
+
} else {
|
|
539
|
+
if (Array.isArray(data.value))
|
|
540
|
+
await update(key, () => JSON.parse(JSON.stringify(data.value)));
|
|
541
|
+
else if (typeof data.value === "object")
|
|
542
|
+
await update(key, () => __spreadValues({}, data.value));
|
|
543
|
+
else
|
|
544
|
+
await update(key, () => data.value);
|
|
545
|
+
}
|
|
546
|
+
} catch (e) {
|
|
547
|
+
onError(e);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
watch(data, () => write(), { flush, deep });
|
|
551
|
+
return data;
|
|
552
|
+
}
|
|
553
|
+
|
|
492
554
|
function useJwt(encodedJwt, options = {}) {
|
|
493
555
|
const {
|
|
494
556
|
onError,
|
|
@@ -550,4 +612,4 @@ function useQRCode(text, options) {
|
|
|
550
612
|
return result;
|
|
551
613
|
}
|
|
552
614
|
|
|
553
|
-
export { createCookies, useAsyncValidator, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useJwt, useNProgress, useQRCode };
|
|
615
|
+
export { createCookies, useAsyncValidator, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useIDBKeyval, useJwt, useNProgress, useQRCode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/integrations",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"description": "Integration wrappers for utility libraries",
|
|
5
5
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -86,6 +86,11 @@
|
|
|
86
86
|
"types": "./useAsyncValidator/component.d.ts",
|
|
87
87
|
"require": "./useAsyncValidator/component.cjs",
|
|
88
88
|
"import": "./useAsyncValidator/component.mjs"
|
|
89
|
+
},
|
|
90
|
+
"./useIDBKeyval": {
|
|
91
|
+
"types": "./useIDBKeyval.d.ts",
|
|
92
|
+
"require": "./useIDBKeyval.cjs",
|
|
93
|
+
"import": "./useIDBKeyval.mjs"
|
|
89
94
|
}
|
|
90
95
|
},
|
|
91
96
|
"main": "./index.cjs",
|
|
@@ -100,6 +105,7 @@
|
|
|
100
105
|
"drauu": "*",
|
|
101
106
|
"focus-trap": "*",
|
|
102
107
|
"fuse.js": "*",
|
|
108
|
+
"idb-keyval": "*",
|
|
103
109
|
"jwt-decode": "*",
|
|
104
110
|
"nprogress": "*",
|
|
105
111
|
"qrcode": "*",
|
|
@@ -124,6 +130,9 @@
|
|
|
124
130
|
"fuse.js": {
|
|
125
131
|
"optional": true
|
|
126
132
|
},
|
|
133
|
+
"idb-keyval": {
|
|
134
|
+
"optional": true
|
|
135
|
+
},
|
|
127
136
|
"jwt-decode": {
|
|
128
137
|
"optional": true
|
|
129
138
|
},
|
|
@@ -138,8 +147,8 @@
|
|
|
138
147
|
}
|
|
139
148
|
},
|
|
140
149
|
"dependencies": {
|
|
141
|
-
"@vueuse/core": "9.
|
|
142
|
-
"@vueuse/shared": "9.
|
|
150
|
+
"@vueuse/core": "9.5.0",
|
|
151
|
+
"@vueuse/shared": "9.5.0",
|
|
143
152
|
"vue-demi": "*"
|
|
144
153
|
},
|
|
145
154
|
"devDependencies": {
|
|
@@ -151,6 +160,7 @@
|
|
|
151
160
|
"drauu": "^0.3.2",
|
|
152
161
|
"focus-trap": "^7.0.0",
|
|
153
162
|
"fuse.js": "^6.6.2",
|
|
163
|
+
"idb-keyval": "^6.2.0",
|
|
154
164
|
"jwt-decode": "^3.1.2",
|
|
155
165
|
"nprogress": "^0.2.0",
|
|
156
166
|
"qrcode": "^1.5.1",
|
package/useIDBKeyval.cjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var shared = require('@vueuse/shared');
|
|
4
|
+
var vueDemi = require('vue-demi');
|
|
5
|
+
var idbKeyval = require('idb-keyval');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
function useIDBKeyval(key, initialValue, options = {}) {
|
|
24
|
+
const {
|
|
25
|
+
flush = "pre",
|
|
26
|
+
deep = true,
|
|
27
|
+
shallow,
|
|
28
|
+
onError = (e) => {
|
|
29
|
+
console.error(e);
|
|
30
|
+
}
|
|
31
|
+
} = options;
|
|
32
|
+
const data = (shallow ? vueDemi.shallowRef : vueDemi.ref)(initialValue);
|
|
33
|
+
const rawInit = shared.resolveUnref(initialValue);
|
|
34
|
+
async function read() {
|
|
35
|
+
try {
|
|
36
|
+
const rawValue = await idbKeyval.get(key);
|
|
37
|
+
if (rawValue === void 0) {
|
|
38
|
+
if (rawInit)
|
|
39
|
+
idbKeyval.set(key, rawInit);
|
|
40
|
+
} else {
|
|
41
|
+
data.value = rawValue;
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
onError(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
read();
|
|
48
|
+
async function write() {
|
|
49
|
+
try {
|
|
50
|
+
if (data.value == null) {
|
|
51
|
+
await idbKeyval.del(key);
|
|
52
|
+
} else {
|
|
53
|
+
if (Array.isArray(data.value))
|
|
54
|
+
await idbKeyval.update(key, () => JSON.parse(JSON.stringify(data.value)));
|
|
55
|
+
else if (typeof data.value === "object")
|
|
56
|
+
await idbKeyval.update(key, () => __spreadValues({}, data.value));
|
|
57
|
+
else
|
|
58
|
+
await idbKeyval.update(key, () => data.value);
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
onError(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
vueDemi.watch(data, () => write(), { flush, deep });
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.useIDBKeyval = useIDBKeyval;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ConfigurableFlush, MaybeComputedRef, RemovableRef } from '@vueuse/shared';
|
|
2
|
+
|
|
3
|
+
interface UseIDBOptions extends ConfigurableFlush {
|
|
4
|
+
/**
|
|
5
|
+
* Watch for deep changes
|
|
6
|
+
*
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
deep?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* On error callback
|
|
12
|
+
*
|
|
13
|
+
* Default log error to `console.error`
|
|
14
|
+
*/
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Use shallow ref as reference
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
shallow?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param key
|
|
26
|
+
* @param initialValue
|
|
27
|
+
* @param options
|
|
28
|
+
*/
|
|
29
|
+
declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeComputedRef<T>, options?: UseIDBOptions): RemovableRef<T>;
|
|
30
|
+
|
|
31
|
+
export { UseIDBOptions, useIDBKeyval };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
2
|
+
if (VueDemi.install) {
|
|
3
|
+
return VueDemi
|
|
4
|
+
}
|
|
5
|
+
if (!Vue) {
|
|
6
|
+
console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
|
|
7
|
+
return VueDemi
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Vue 2.7
|
|
11
|
+
if (Vue.version.slice(0, 4) === '2.7.') {
|
|
12
|
+
for (var key in Vue) {
|
|
13
|
+
VueDemi[key] = Vue[key]
|
|
14
|
+
}
|
|
15
|
+
VueDemi.isVue2 = true
|
|
16
|
+
VueDemi.isVue3 = false
|
|
17
|
+
VueDemi.install = function () {}
|
|
18
|
+
VueDemi.Vue = Vue
|
|
19
|
+
VueDemi.Vue2 = Vue
|
|
20
|
+
VueDemi.version = Vue.version
|
|
21
|
+
VueDemi.warn = Vue.util.warn
|
|
22
|
+
function createApp(rootComponent, rootProps) {
|
|
23
|
+
var vm
|
|
24
|
+
var provide = {}
|
|
25
|
+
var app = {
|
|
26
|
+
config: Vue.config,
|
|
27
|
+
use: Vue.use.bind(Vue),
|
|
28
|
+
mixin: Vue.mixin.bind(Vue),
|
|
29
|
+
component: Vue.component.bind(Vue),
|
|
30
|
+
provide: function (key, value) {
|
|
31
|
+
provide[key] = value
|
|
32
|
+
return this
|
|
33
|
+
},
|
|
34
|
+
directive: function (name, dir) {
|
|
35
|
+
if (dir) {
|
|
36
|
+
Vue.directive(name, dir)
|
|
37
|
+
return app
|
|
38
|
+
} else {
|
|
39
|
+
return Vue.directive(name)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
mount: function (el, hydrating) {
|
|
43
|
+
if (!vm) {
|
|
44
|
+
vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
|
|
45
|
+
vm.$mount(el, hydrating)
|
|
46
|
+
return vm
|
|
47
|
+
} else {
|
|
48
|
+
return vm
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
unmount: function () {
|
|
52
|
+
if (vm) {
|
|
53
|
+
vm.$destroy()
|
|
54
|
+
vm = undefined
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
return app
|
|
59
|
+
}
|
|
60
|
+
VueDemi.createApp = createApp
|
|
61
|
+
}
|
|
62
|
+
// Vue 2.6.x
|
|
63
|
+
else if (Vue.version.slice(0, 2) === '2.') {
|
|
64
|
+
if (VueCompositionAPI) {
|
|
65
|
+
for (var key in VueCompositionAPI) {
|
|
66
|
+
VueDemi[key] = VueCompositionAPI[key]
|
|
67
|
+
}
|
|
68
|
+
VueDemi.isVue2 = true
|
|
69
|
+
VueDemi.isVue3 = false
|
|
70
|
+
VueDemi.install = function () {}
|
|
71
|
+
VueDemi.Vue = Vue
|
|
72
|
+
VueDemi.Vue2 = Vue
|
|
73
|
+
VueDemi.version = Vue.version
|
|
74
|
+
} else {
|
|
75
|
+
console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Vue 3
|
|
79
|
+
else if (Vue.version.slice(0, 2) === '3.') {
|
|
80
|
+
for (var key in Vue) {
|
|
81
|
+
VueDemi[key] = Vue[key]
|
|
82
|
+
}
|
|
83
|
+
VueDemi.isVue2 = false
|
|
84
|
+
VueDemi.isVue3 = true
|
|
85
|
+
VueDemi.install = function () {}
|
|
86
|
+
VueDemi.Vue = Vue
|
|
87
|
+
VueDemi.Vue2 = undefined
|
|
88
|
+
VueDemi.version = Vue.version
|
|
89
|
+
VueDemi.set = function (target, key, val) {
|
|
90
|
+
if (Array.isArray(target)) {
|
|
91
|
+
target.length = Math.max(target.length, key)
|
|
92
|
+
target.splice(key, 1, val)
|
|
93
|
+
return val
|
|
94
|
+
}
|
|
95
|
+
target[key] = val
|
|
96
|
+
return val
|
|
97
|
+
}
|
|
98
|
+
VueDemi.del = function (target, key) {
|
|
99
|
+
if (Array.isArray(target)) {
|
|
100
|
+
target.splice(key, 1)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
delete target[key]
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
|
|
107
|
+
}
|
|
108
|
+
return VueDemi
|
|
109
|
+
})(
|
|
110
|
+
(this.VueDemi = this.VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
|
|
111
|
+
this.Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
|
|
112
|
+
this.VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
|
|
113
|
+
);
|
|
114
|
+
;
|
|
115
|
+
;(function (exports, shared, vueDemi, idbKeyval) {
|
|
116
|
+
'use strict';
|
|
117
|
+
|
|
118
|
+
var __defProp = Object.defineProperty;
|
|
119
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
120
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
121
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
122
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
123
|
+
var __spreadValues = (a, b) => {
|
|
124
|
+
for (var prop in b || (b = {}))
|
|
125
|
+
if (__hasOwnProp.call(b, prop))
|
|
126
|
+
__defNormalProp(a, prop, b[prop]);
|
|
127
|
+
if (__getOwnPropSymbols)
|
|
128
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
129
|
+
if (__propIsEnum.call(b, prop))
|
|
130
|
+
__defNormalProp(a, prop, b[prop]);
|
|
131
|
+
}
|
|
132
|
+
return a;
|
|
133
|
+
};
|
|
134
|
+
function useIDBKeyval(key, initialValue, options = {}) {
|
|
135
|
+
const {
|
|
136
|
+
flush = "pre",
|
|
137
|
+
deep = true,
|
|
138
|
+
shallow,
|
|
139
|
+
onError = (e) => {
|
|
140
|
+
console.error(e);
|
|
141
|
+
}
|
|
142
|
+
} = options;
|
|
143
|
+
const data = (shallow ? vueDemi.shallowRef : vueDemi.ref)(initialValue);
|
|
144
|
+
const rawInit = shared.resolveUnref(initialValue);
|
|
145
|
+
async function read() {
|
|
146
|
+
try {
|
|
147
|
+
const rawValue = await idbKeyval.get(key);
|
|
148
|
+
if (rawValue === void 0) {
|
|
149
|
+
if (rawInit)
|
|
150
|
+
idbKeyval.set(key, rawInit);
|
|
151
|
+
} else {
|
|
152
|
+
data.value = rawValue;
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
onError(e);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
read();
|
|
159
|
+
async function write() {
|
|
160
|
+
try {
|
|
161
|
+
if (data.value == null) {
|
|
162
|
+
await idbKeyval.del(key);
|
|
163
|
+
} else {
|
|
164
|
+
if (Array.isArray(data.value))
|
|
165
|
+
await idbKeyval.update(key, () => JSON.parse(JSON.stringify(data.value)));
|
|
166
|
+
else if (typeof data.value === "object")
|
|
167
|
+
await idbKeyval.update(key, () => __spreadValues({}, data.value));
|
|
168
|
+
else
|
|
169
|
+
await idbKeyval.update(key, () => data.value);
|
|
170
|
+
}
|
|
171
|
+
} catch (e) {
|
|
172
|
+
onError(e);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
vueDemi.watch(data, () => write(), { flush, deep });
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
exports.useIDBKeyval = useIDBKeyval;
|
|
180
|
+
|
|
181
|
+
})(this.VueUse = this.VueUse || {}, VueUse, VueDemi, idbKeyval);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var VueDemi=function(r,n,p){if(r.install)return r;if(!n)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),r;if(n.version.slice(0,4)==="2.7."){let s=function(a,c){var f,d={},v={config:n.config,use:n.use.bind(n),mixin:n.mixin.bind(n),component:n.component.bind(n),provide:function(e,t){return d[e]=t,this},directive:function(e,t){return t?(n.directive(e,t),v):n.directive(e)},mount:function(e,t){return f||(f=new n(Object.assign({propsData:c},a,{provide:Object.assign(d,a.provide)})),f.$mount(e,t),f)},unmount:function(){f&&(f.$destroy(),f=void 0)}};return v};var y=s;for(var o in n)r[o]=n[o];r.isVue2=!0,r.isVue3=!1,r.install=function(){},r.Vue=n,r.Vue2=n,r.version=n.version,r.warn=n.util.warn,r.createApp=s}else if(n.version.slice(0,2)==="2.")if(p){for(var o in p)r[o]=p[o];r.isVue2=!0,r.isVue3=!1,r.install=function(){},r.Vue=n,r.Vue2=n,r.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 o in n)r[o]=n[o];r.isVue2=!1,r.isVue3=!0,r.install=function(){},r.Vue=n,r.Vue2=void 0,r.version=n.version,r.set=function(s,a,c){return Array.isArray(s)?(s.length=Math.max(s.length,a),s.splice(a,1,c),c):(s[a]=c,c)},r.del=function(s,a){if(Array.isArray(s)){s.splice(a,1);return}delete s[a]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");return r}(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(r,n,p,o){"use strict";var y=Object.defineProperty,s=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable,f=(e,t,i)=>t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,d=(e,t)=>{for(var i in t||(t={}))a.call(t,i)&&f(e,i,t[i]);if(s)for(var i of s(t))c.call(t,i)&&f(e,i,t[i]);return e};function v(e,t,i={}){const{flush:O="pre",deep:_=!0,shallow:A,onError:w=u=>{console.error(u)}}=i,l=(A?p.shallowRef:p.ref)(t),h=n.resolveUnref(t);async function P(){try{const u=await o.get(e);u===void 0?h&&o.set(e,h):l.value=u}catch(u){w(u)}}P();async function b(){try{l.value==null?await o.del(e):Array.isArray(l.value)?await o.update(e,()=>JSON.parse(JSON.stringify(l.value))):typeof l.value=="object"?await o.update(e,()=>d({},l.value)):await o.update(e,()=>l.value)}catch(u){w(u)}}return p.watch(l,()=>b(),{flush:O,deep:_}),l}r.useIDBKeyval=v})(this.VueUse=this.VueUse||{},VueUse,VueDemi,idbKeyval);
|