@vueuse/integrations 9.13.0 → 10.0.0-beta.1

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
@@ -25,6 +25,7 @@ npm i <b>@vueuse/integrations</b>
25
25
  - [`useJwt`](https://vueuse.org/integrations/useJwt/) — wrapper for [`jwt-decode`](https://github.com/auth0/jwt-decode)
26
26
  - [`useNProgress`](https://vueuse.org/integrations/useNProgress/) — reactive wrapper for [`nprogress`](https://github.com/rstacruz/nprogress)
27
27
  - [`useQRCode`](https://vueuse.org/integrations/useQRCode/) — wrapper for [`qrcode`](https://github.com/soldair/node-qrcode)
28
+ - [`useSortable`](https://vueuse.org/integrations/useSortable/) — wrapper for [`sortable`](https://github.com/SortableJS/Sortable)
28
29
 
29
30
 
30
31
  <!--FUNCTIONS_LIST_ENDS-->
package/index.cjs CHANGED
@@ -14,31 +14,37 @@ var idbKeyval = require('idb-keyval');
14
14
  var jwt_decode = require('jwt-decode');
15
15
  var nprogress = require('nprogress');
16
16
  var QRCode = require('qrcode');
17
+ var Sortable = require('sortablejs');
17
18
 
18
- var __defProp$5 = Object.defineProperty;
19
+ var __defProp$6 = Object.defineProperty;
19
20
  var __defProps$2 = Object.defineProperties;
20
21
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
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) => {
22
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
23
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
24
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
25
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
+ var __spreadValues$6 = (a, b) => {
26
27
  for (var prop in b || (b = {}))
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]);
28
+ if (__hasOwnProp$6.call(b, prop))
29
+ __defNormalProp$6(a, prop, b[prop]);
30
+ if (__getOwnPropSymbols$6)
31
+ for (var prop of __getOwnPropSymbols$6(b)) {
32
+ if (__propIsEnum$6.call(b, prop))
33
+ __defNormalProp$6(a, prop, b[prop]);
33
34
  }
34
35
  return a;
35
36
  };
36
37
  var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
37
- const AsyncValidatorSchema = Schema || Schema.default;
38
+ const AsyncValidatorSchema = Schema.default || Schema;
38
39
  function useAsyncValidator(value, rules, options = {}) {
39
- const errorInfo = vueDemi.ref();
40
- const isFinished = vueDemi.ref(false);
41
- const pass = vueDemi.ref(false);
40
+ const {
41
+ validateOption = {},
42
+ immediate = true
43
+ } = options;
44
+ const valueRef = shared.resolveRef(value);
45
+ const errorInfo = vueDemi.shallowRef(null);
46
+ const isFinished = vueDemi.ref(true);
47
+ const pass = vueDemi.ref(!immediate);
42
48
  const errors = vueDemi.computed(() => {
43
49
  var _a;
44
50
  return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
@@ -47,13 +53,12 @@ function useAsyncValidator(value, rules, options = {}) {
47
53
  var _a;
48
54
  return ((_a = errorInfo.value) == null ? void 0 : _a.fields) || {};
49
55
  });
50
- const { validateOption = {} } = options;
51
- vueDemi.watchEffect(async () => {
56
+ const validator = vueDemi.computed(() => new AsyncValidatorSchema(shared.resolveUnref(rules)));
57
+ const execute = async () => {
52
58
  isFinished.value = false;
53
59
  pass.value = false;
54
- const validator = new AsyncValidatorSchema(shared.resolveUnref(rules));
55
60
  try {
56
- await validator.validate(shared.resolveUnref(value), validateOption);
61
+ await validator.value.validate(valueRef.value, validateOption);
57
62
  pass.value = true;
58
63
  errorInfo.value = null;
59
64
  } catch (err) {
@@ -61,41 +66,49 @@ function useAsyncValidator(value, rules, options = {}) {
61
66
  } finally {
62
67
  isFinished.value = true;
63
68
  }
64
- });
69
+ return {
70
+ pass: pass.value,
71
+ errorInfo: errorInfo.value,
72
+ errors: errors.value,
73
+ errorFields: errorFields.value
74
+ };
75
+ };
76
+ vueDemi.watch([valueRef, validator], () => execute(), { immediate, deep: true });
65
77
  const shell = {
66
- pass,
67
78
  isFinished,
68
- errorInfo,
79
+ pass,
69
80
  errors,
70
- errorFields
81
+ errorInfo,
82
+ errorFields,
83
+ execute
71
84
  };
72
85
  function waitUntilFinished() {
73
86
  return new Promise((resolve, reject) => {
74
87
  shared.until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
75
88
  });
76
89
  }
77
- return __spreadProps$2(__spreadValues$5({}, shell), {
90
+ return __spreadProps$2(__spreadValues$6({}, shell), {
78
91
  then(onFulfilled, onRejected) {
79
92
  return waitUntilFinished().then(onFulfilled, onRejected);
80
93
  }
81
94
  });
82
95
  }
83
96
 
84
- var __defProp$4 = Object.defineProperty;
97
+ var __defProp$5 = Object.defineProperty;
85
98
  var __defProps$1 = Object.defineProperties;
86
99
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
87
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
88
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
89
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
90
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
91
- var __spreadValues$4 = (a, b) => {
100
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
101
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
102
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
103
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
104
+ var __spreadValues$5 = (a, b) => {
92
105
  for (var prop in b || (b = {}))
93
- if (__hasOwnProp$4.call(b, prop))
94
- __defNormalProp$4(a, prop, b[prop]);
95
- if (__getOwnPropSymbols$4)
96
- for (var prop of __getOwnPropSymbols$4(b)) {
97
- if (__propIsEnum$4.call(b, prop))
98
- __defNormalProp$4(a, prop, b[prop]);
106
+ if (__hasOwnProp$5.call(b, prop))
107
+ __defNormalProp$5(a, prop, b[prop]);
108
+ if (__getOwnPropSymbols$5)
109
+ for (var prop of __getOwnPropSymbols$5(b)) {
110
+ if (__propIsEnum$5.call(b, prop))
111
+ __defNormalProp$5(a, prop, b[prop]);
99
112
  }
100
113
  return a;
101
114
  };
@@ -105,7 +118,10 @@ function useAxios(...args) {
105
118
  const argsPlaceholder = shared.isString(url) ? 1 : 0;
106
119
  let defaultConfig = {};
107
120
  let instance = axios;
108
- let options = { immediate: !!argsPlaceholder, shallow: true };
121
+ let options = {
122
+ immediate: !!argsPlaceholder,
123
+ shallow: true
124
+ };
109
125
  const isAxiosInstance = (val) => !!(val == null ? void 0 : val.request);
110
126
  if (args.length > 0 + argsPlaceholder) {
111
127
  if (isAxiosInstance(args[0 + argsPlaceholder]))
@@ -154,7 +170,7 @@ function useAxios(...args) {
154
170
  }
155
171
  abort();
156
172
  loading(true);
157
- instance(_url, __spreadProps$1(__spreadValues$4(__spreadValues$4({}, defaultConfig), typeof executeUrl === "object" ? executeUrl : config), { cancelToken: cancelToken.token })).then((r) => {
173
+ instance(_url, __spreadProps$1(__spreadValues$5(__spreadValues$5({}, defaultConfig), typeof executeUrl === "object" ? executeUrl : config), { cancelToken: cancelToken.token })).then((r) => {
158
174
  var _a;
159
175
  response.value = r;
160
176
  const result2 = r.data;
@@ -185,7 +201,7 @@ function useAxios(...args) {
185
201
  abort,
186
202
  execute
187
203
  };
188
- return __spreadProps$1(__spreadValues$4({}, result), {
204
+ return __spreadProps$1(__spreadValues$5({}, result), {
189
205
  then
190
206
  });
191
207
  }
@@ -219,19 +235,19 @@ function useChangeCase(input, type, options) {
219
235
  });
220
236
  }
221
237
 
222
- var __defProp$3 = Object.defineProperty;
223
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
224
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
225
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
226
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
227
- var __spreadValues$3 = (a, b) => {
238
+ var __defProp$4 = Object.defineProperty;
239
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
240
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
241
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
242
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
243
+ var __spreadValues$4 = (a, b) => {
228
244
  for (var prop in b || (b = {}))
229
- if (__hasOwnProp$3.call(b, prop))
230
- __defNormalProp$3(a, prop, b[prop]);
231
- if (__getOwnPropSymbols$3)
232
- for (var prop of __getOwnPropSymbols$3(b)) {
233
- if (__propIsEnum$3.call(b, prop))
234
- __defNormalProp$3(a, prop, b[prop]);
245
+ if (__hasOwnProp$4.call(b, prop))
246
+ __defNormalProp$4(a, prop, b[prop]);
247
+ if (__getOwnPropSymbols$4)
248
+ for (var prop of __getOwnPropSymbols$4(b)) {
249
+ if (__propIsEnum$4.call(b, prop))
250
+ __defNormalProp$4(a, prop, b[prop]);
235
251
  }
236
252
  return a;
237
253
  };
@@ -258,11 +274,11 @@ function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies =
258
274
  if (autoUpdateDependencies && watchingDependencies && !watchingDependencies.includes(args[0]))
259
275
  watchingDependencies.push(args[0]);
260
276
  touches.value;
261
- return cookies.get(args[0], __spreadValues$3({ doNotParse }, args[1]));
277
+ return cookies.get(args[0], __spreadValues$4({ doNotParse }, args[1]));
262
278
  },
263
279
  getAll: (...args) => {
264
280
  touches.value;
265
- return cookies.getAll(__spreadValues$3({ doNotParse }, args[0]));
281
+ return cookies.getAll(__spreadValues$4({ doNotParse }, args[0]));
266
282
  },
267
283
  set: (...args) => cookies.set(...args),
268
284
  remove: (...args) => cookies.remove(...args),
@@ -280,19 +296,19 @@ function shouldUpdate(dependencies, newCookies, oldCookies) {
280
296
  return false;
281
297
  }
282
298
 
283
- var __defProp$2 = Object.defineProperty;
284
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
285
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
286
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
287
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
288
- var __spreadValues$2 = (a, b) => {
299
+ var __defProp$3 = Object.defineProperty;
300
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
301
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
302
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
303
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
304
+ var __spreadValues$3 = (a, b) => {
289
305
  for (var prop in b || (b = {}))
290
- if (__hasOwnProp$2.call(b, prop))
291
- __defNormalProp$2(a, prop, b[prop]);
292
- if (__getOwnPropSymbols$2)
293
- for (var prop of __getOwnPropSymbols$2(b)) {
294
- if (__propIsEnum$2.call(b, prop))
295
- __defNormalProp$2(a, prop, b[prop]);
306
+ if (__hasOwnProp$3.call(b, prop))
307
+ __defNormalProp$3(a, prop, b[prop]);
308
+ if (__getOwnPropSymbols$3)
309
+ for (var prop of __getOwnPropSymbols$3(b)) {
310
+ if (__propIsEnum$3.call(b, prop))
311
+ __defNormalProp$3(a, prop, b[prop]);
296
312
  }
297
313
  return a;
298
314
  };
@@ -366,7 +382,7 @@ function useDrauu(target, options) {
366
382
  return;
367
383
  if (drauuInstance.value)
368
384
  cleanup();
369
- drauuInstance.value = drauu.createDrauu(__spreadValues$2({ el }, options));
385
+ drauuInstance.value = drauu.createDrauu(__spreadValues$3({ el }, options));
370
386
  syncStatus();
371
387
  disposables = [
372
388
  drauuInstance.value.on("canceled", () => onCanceledHook.trigger()),
@@ -399,40 +415,40 @@ function useDrauu(target, options) {
399
415
  };
400
416
  }
401
417
 
402
- var __defProp$1 = Object.defineProperty;
418
+ var __defProp$2 = Object.defineProperty;
403
419
  var __defProps = Object.defineProperties;
404
420
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
405
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
406
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
407
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
408
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
409
- var __spreadValues$1 = (a, b) => {
421
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
422
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
423
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
424
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
425
+ var __spreadValues$2 = (a, b) => {
410
426
  for (var prop in b || (b = {}))
411
- if (__hasOwnProp$1.call(b, prop))
412
- __defNormalProp$1(a, prop, b[prop]);
413
- if (__getOwnPropSymbols$1)
414
- for (var prop of __getOwnPropSymbols$1(b)) {
415
- if (__propIsEnum$1.call(b, prop))
416
- __defNormalProp$1(a, prop, b[prop]);
427
+ if (__hasOwnProp$2.call(b, prop))
428
+ __defNormalProp$2(a, prop, b[prop]);
429
+ if (__getOwnPropSymbols$2)
430
+ for (var prop of __getOwnPropSymbols$2(b)) {
431
+ if (__propIsEnum$2.call(b, prop))
432
+ __defNormalProp$2(a, prop, b[prop]);
417
433
  }
418
434
  return a;
419
435
  };
420
436
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
421
- var __objRest = (source, exclude) => {
437
+ var __objRest$1 = (source, exclude) => {
422
438
  var target = {};
423
439
  for (var prop in source)
424
- if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
440
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
425
441
  target[prop] = source[prop];
426
- if (source != null && __getOwnPropSymbols$1)
427
- for (var prop of __getOwnPropSymbols$1(source)) {
428
- if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
442
+ if (source != null && __getOwnPropSymbols$2)
443
+ for (var prop of __getOwnPropSymbols$2(source)) {
444
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
429
445
  target[prop] = source[prop];
430
446
  }
431
447
  return target;
432
448
  };
433
449
  function useFocusTrap(target, options = {}) {
434
450
  let trap;
435
- const _a = options, { immediate } = _a, focusTrapOptions = __objRest(_a, ["immediate"]);
451
+ const _a = options, { immediate } = _a, focusTrapOptions = __objRest$1(_a, ["immediate"]);
436
452
  const hasFocus = vueDemi.ref(false);
437
453
  const isPaused = vueDemi.ref(false);
438
454
  const activate = (opts) => trap && trap.activate(opts);
@@ -452,7 +468,7 @@ function useFocusTrap(target, options = {}) {
452
468
  vueDemi.watch(() => core.unrefElement(target), (el) => {
453
469
  if (!el)
454
470
  return;
455
- trap = focusTrap.createFocusTrap(el, __spreadProps(__spreadValues$1({}, focusTrapOptions), {
471
+ trap = focusTrap.createFocusTrap(el, __spreadProps(__spreadValues$2({}, focusTrapOptions), {
456
472
  onActivate() {
457
473
  hasFocus.value = true;
458
474
  if (options.onActivate)
@@ -506,19 +522,19 @@ function useFuse(search, data, options) {
506
522
  };
507
523
  }
508
524
 
509
- var __defProp = Object.defineProperty;
510
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
511
- var __hasOwnProp = Object.prototype.hasOwnProperty;
512
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
513
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
514
- var __spreadValues = (a, b) => {
525
+ var __defProp$1 = Object.defineProperty;
526
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
527
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
528
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
529
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
530
+ var __spreadValues$1 = (a, b) => {
515
531
  for (var prop in b || (b = {}))
516
- if (__hasOwnProp.call(b, prop))
517
- __defNormalProp(a, prop, b[prop]);
518
- if (__getOwnPropSymbols)
519
- for (var prop of __getOwnPropSymbols(b)) {
520
- if (__propIsEnum.call(b, prop))
521
- __defNormalProp(a, prop, b[prop]);
532
+ if (__hasOwnProp$1.call(b, prop))
533
+ __defNormalProp$1(a, prop, b[prop]);
534
+ if (__getOwnPropSymbols$1)
535
+ for (var prop of __getOwnPropSymbols$1(b)) {
536
+ if (__propIsEnum$1.call(b, prop))
537
+ __defNormalProp$1(a, prop, b[prop]);
522
538
  }
523
539
  return a;
524
540
  };
@@ -526,18 +542,20 @@ function useIDBKeyval(key, initialValue, options = {}) {
526
542
  const {
527
543
  flush = "pre",
528
544
  deep = true,
529
- shallow,
545
+ shallow = false,
530
546
  onError = (e) => {
531
547
  console.error(e);
532
- }
548
+ },
549
+ writeDefaults = true
533
550
  } = options;
551
+ const isFinished = vueDemi.ref(false);
534
552
  const data = (shallow ? vueDemi.shallowRef : vueDemi.ref)(initialValue);
535
553
  const rawInit = shared.resolveUnref(initialValue);
536
554
  async function read() {
537
555
  try {
538
556
  const rawValue = await idbKeyval.get(key);
539
557
  if (rawValue === void 0) {
540
- if (rawInit !== void 0 && rawInit !== null)
558
+ if (rawInit !== void 0 && rawInit !== null && writeDefaults)
541
559
  await idbKeyval.set(key, rawInit);
542
560
  } else {
543
561
  data.value = rawValue;
@@ -545,6 +563,7 @@ function useIDBKeyval(key, initialValue, options = {}) {
545
563
  } catch (e) {
546
564
  onError(e);
547
565
  }
566
+ isFinished.value = true;
548
567
  }
549
568
  read();
550
569
  async function write() {
@@ -555,7 +574,7 @@ function useIDBKeyval(key, initialValue, options = {}) {
555
574
  if (Array.isArray(data.value))
556
575
  await idbKeyval.update(key, () => JSON.parse(JSON.stringify(data.value)));
557
576
  else if (typeof data.value === "object")
558
- await idbKeyval.update(key, () => __spreadValues({}, data.value));
577
+ await idbKeyval.update(key, () => __spreadValues$1({}, data.value));
559
578
  else
560
579
  await idbKeyval.update(key, () => data.value);
561
580
  }
@@ -564,7 +583,7 @@ function useIDBKeyval(key, initialValue, options = {}) {
564
583
  }
565
584
  }
566
585
  vueDemi.watch(data, () => write(), { flush, deep });
567
- return data;
586
+ return { isFinished, data };
568
587
  }
569
588
 
570
589
  function useJwt(encodedJwt, options = {}) {
@@ -628,7 +647,61 @@ function useQRCode(text, options) {
628
647
  return result;
629
648
  }
630
649
 
650
+ var __defProp = Object.defineProperty;
651
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
652
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
653
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
654
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
655
+ var __spreadValues = (a, b) => {
656
+ for (var prop in b || (b = {}))
657
+ if (__hasOwnProp.call(b, prop))
658
+ __defNormalProp(a, prop, b[prop]);
659
+ if (__getOwnPropSymbols)
660
+ for (var prop of __getOwnPropSymbols(b)) {
661
+ if (__propIsEnum.call(b, prop))
662
+ __defNormalProp(a, prop, b[prop]);
663
+ }
664
+ return a;
665
+ };
666
+ var __objRest = (source, exclude) => {
667
+ var target = {};
668
+ for (var prop in source)
669
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
670
+ target[prop] = source[prop];
671
+ if (source != null && __getOwnPropSymbols)
672
+ for (var prop of __getOwnPropSymbols(source)) {
673
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
674
+ target[prop] = source[prop];
675
+ }
676
+ return target;
677
+ };
678
+ function useSortable(el, list, options = {}) {
679
+ let sortable;
680
+ const _a = options, { document = core.defaultDocument } = _a, resetOptions = __objRest(_a, ["document"]);
681
+ const defaultOptions = {
682
+ onUpdate: (e) => {
683
+ moveArrayElement(list, e.oldIndex, e.newIndex);
684
+ }
685
+ };
686
+ const start = () => {
687
+ const target = typeof el === "string" ? document == null ? void 0 : document.querySelector(el) : core.unrefElement(el);
688
+ if (!target)
689
+ return;
690
+ sortable = new Sortable(target, __spreadValues(__spreadValues({}, defaultOptions), resetOptions));
691
+ };
692
+ const stop = () => sortable == null ? void 0 : sortable.destroy();
693
+ core.tryOnMounted(start);
694
+ core.tryOnScopeDispose(stop);
695
+ return { stop, start };
696
+ }
697
+ function moveArrayElement(list, from, to) {
698
+ const array = core.resolveUnref(list);
699
+ if (to >= 0 && to < array.length)
700
+ array.splice(to, 0, array.splice(from, 1)[0]);
701
+ }
702
+
631
703
  exports.createCookies = createCookies;
704
+ exports.moveArrayElement = moveArrayElement;
632
705
  exports.useAsyncValidator = useAsyncValidator;
633
706
  exports.useAxios = useAxios;
634
707
  exports.useChangeCase = useChangeCase;
@@ -640,3 +713,4 @@ exports.useIDBKeyval = useIDBKeyval;
640
713
  exports.useJwt = useJwt;
641
714
  exports.useNProgress = useNProgress;
642
715
  exports.useQRCode = useQRCode;
716
+ exports.useSortable = useSortable;
package/index.d.ts CHANGED
@@ -2,35 +2,44 @@ import { MaybeComputedRef, MaybeRef, ConfigurableFlush, RemovableRef } from '@vu
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';
5
- import { AxiosResponse, AxiosError, RawAxiosRequestConfig, AxiosInstance } from 'axios';
5
+ import { AxiosResponse, AxiosRequestConfig, AxiosInstance } from 'axios';
6
6
  import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase, Options } from 'change-case';
7
7
  import * as universal_cookie from 'universal-cookie';
8
8
  import universal_cookie__default from 'universal-cookie';
9
- import { IncomingMessage } from 'http';
9
+ import { IncomingMessage } from 'node:http';
10
10
  import { Options as Options$1, Drauu, Brush } from 'drauu';
11
- import { EventHookOn, MaybeComputedElementRef, Fn, MaybeElementRef } from '@vueuse/core';
11
+ import { EventHookOn, MaybeComputedElementRef, Fn, MaybeElementRef, ConfigurableDocument, MaybeComputedRef as MaybeComputedRef$1 } from '@vueuse/core';
12
12
  import { Options as Options$2, ActivateOptions, DeactivateOptions } from 'focus-trap';
13
13
  import Fuse from 'fuse.js';
14
14
  import { JwtPayload, JwtHeader } from 'jwt-decode';
15
15
  import nprogress, { NProgressOptions } from 'nprogress';
16
16
  import QRCode from 'qrcode';
17
+ import { Options as Options$3 } from 'sortablejs';
17
18
 
18
19
  type AsyncValidatorError = Error & {
19
20
  errors: ValidateError[];
20
21
  fields: Record<string, ValidateError[]>;
21
22
  };
23
+ interface UseAsyncValidatorExecuteReturn {
24
+ pass: boolean;
25
+ errors: AsyncValidatorError['errors'] | undefined;
26
+ errorInfo: AsyncValidatorError | null;
27
+ errorFields: AsyncValidatorError['fields'] | undefined;
28
+ }
22
29
  interface UseAsyncValidatorReturn {
23
30
  pass: Ref<boolean>;
24
- errorInfo: Ref<AsyncValidatorError | null>;
25
31
  isFinished: Ref<boolean>;
26
32
  errors: Ref<AsyncValidatorError['errors'] | undefined>;
33
+ errorInfo: Ref<AsyncValidatorError | null>;
27
34
  errorFields: Ref<AsyncValidatorError['fields'] | undefined>;
35
+ execute: () => Promise<UseAsyncValidatorExecuteReturn>;
28
36
  }
29
37
  interface UseAsyncValidatorOptions {
30
38
  /**
31
39
  * @see https://github.com/yiminghe/async-validator#options
32
40
  */
33
41
  validateOption?: ValidateOption;
42
+ immediate?: boolean;
34
43
  }
35
44
  /**
36
45
  * Wrapper for async-validator.
@@ -40,7 +49,7 @@ interface UseAsyncValidatorOptions {
40
49
  */
41
50
  declare function useAsyncValidator(value: MaybeComputedRef<Record<string, any>>, rules: MaybeComputedRef<Rules>, options?: UseAsyncValidatorOptions): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>;
42
51
 
43
- interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
52
+ interface UseAxiosReturn<T, R = AxiosResponse<T>, _D = any> {
44
53
  /**
45
54
  * Axios Response
46
55
  */
@@ -64,7 +73,7 @@ interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
64
73
  /**
65
74
  * Any errors that may have occurred
66
75
  */
67
- error: ShallowRef<AxiosError<T, D> | undefined>;
76
+ error: ShallowRef<unknown | undefined>;
68
77
  /**
69
78
  * Aborts the current request
70
79
  */
@@ -102,13 +111,13 @@ interface StrictUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
102
111
  /**
103
112
  * Manually call the axios request
104
113
  */
105
- execute: (url?: string | RawAxiosRequestConfig<D>, config?: RawAxiosRequestConfig<D>) => PromiseLike<StrictUseAxiosReturn<T, R, D>>;
114
+ execute: (url?: string | AxiosRequestConfig<D>, config?: AxiosRequestConfig<D>) => PromiseLike<StrictUseAxiosReturn<T, R, D>>;
106
115
  }
107
116
  interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
108
117
  /**
109
118
  * Manually call the axios request
110
119
  */
111
- execute: (url: string, config?: RawAxiosRequestConfig<D>) => PromiseLike<EasyUseAxiosReturn<T, R, D>>;
120
+ execute: (url: string, config?: AxiosRequestConfig<D>) => PromiseLike<EasyUseAxiosReturn<T, R, D>>;
112
121
  }
113
122
  interface UseAxiosOptions<T = any> {
114
123
  /**
@@ -131,12 +140,12 @@ interface UseAxiosOptions<T = any> {
131
140
  */
132
141
  onSuccess?: (data: T) => void;
133
142
  }
134
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
135
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
136
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config: RawAxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
137
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
143
+ 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
+ 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>>;
145
+ declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config: AxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
146
+ declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
138
147
  declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
139
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
148
+ declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
140
149
 
141
150
  declare const changeCase_camelCase: typeof camelCase;
142
151
  declare const changeCase_capitalCase: typeof capitalCase;
@@ -335,6 +344,12 @@ interface UseIDBOptions extends ConfigurableFlush {
335
344
  * @default false
336
345
  */
337
346
  shallow?: boolean;
347
+ /**
348
+ * Write the default value to the storage when it does not exist
349
+ *
350
+ * @default true
351
+ */
352
+ writeDefaults?: boolean;
338
353
  }
339
354
  /**
340
355
  *
@@ -342,7 +357,10 @@ interface UseIDBOptions extends ConfigurableFlush {
342
357
  * @param initialValue
343
358
  * @param options
344
359
  */
345
- declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeComputedRef<T>, options?: UseIDBOptions): RemovableRef<T>;
360
+ declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeComputedRef<T>, options?: UseIDBOptions): {
361
+ data: RemovableRef<T>;
362
+ isFinished: Ref<boolean>;
363
+ };
346
364
 
347
365
  interface UseJwtOptions<Fallback> {
348
366
  /**
@@ -392,4 +410,19 @@ type UseNProgressReturn = ReturnType<typeof useNProgress>;
392
410
  */
393
411
  declare function useQRCode(text: MaybeComputedRef<string>, options?: QRCode.QRCodeToDataURLOptions): vue_demi.Ref<string>;
394
412
 
395
- 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 };
413
+ interface UseSortableReturn {
414
+ /**
415
+ * start sortable instance
416
+ */
417
+ start: () => void;
418
+ /**
419
+ * destroy sortable instance
420
+ */
421
+ stop: () => void;
422
+ }
423
+ type UseSortableOptions = Options$3 & ConfigurableDocument;
424
+ declare function useSortable<T>(selector: string, list: MaybeComputedRef$1<T[]>, options?: UseSortableOptions): UseSortableReturn;
425
+ declare function useSortable<T>(el: MaybeComputedRef$1<HTMLElement | null | undefined>, list: MaybeComputedRef$1<T[]>, options?: UseSortableOptions): UseSortableReturn;
426
+ declare function moveArrayElement<T>(list: MaybeComputedRef$1<T[]>, from: number, to: number): void;
427
+
428
+ export { AsyncValidatorError, ChangeCaseType, EasyUseAxiosReturn, FuseOptions, StrictUseAxiosReturn, UseAsyncValidatorExecuteReturn, UseAsyncValidatorOptions, UseAsyncValidatorReturn, UseAxiosOptions, UseAxiosReturn, UseDrauuOptions, UseDrauuReturn, UseFocusTrapOptions, UseFocusTrapReturn, UseFuseOptions, UseFuseReturn, UseIDBOptions, UseJwtOptions, UseJwtReturn, UseNProgressOptions, UseNProgressReturn, UseSortableOptions, UseSortableReturn, createCookies, moveArrayElement, useAsyncValidator, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useIDBKeyval, useJwt, useNProgress, useQRCode, useSortable };