@vueuse/integrations 10.2.1 → 10.4.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.cjs +62 -214
- package/index.d.cts +427 -0
- package/index.d.mts +427 -0
- package/index.d.ts +8 -18
- package/index.iife.js +62 -214
- package/index.iife.min.js +1 -1
- package/index.mjs +64 -216
- package/package.json +10 -26
- package/useAsyncValidator/component.cjs +5 -29
- package/useAsyncValidator/component.d.cts +27 -0
- package/useAsyncValidator/component.d.mts +27 -0
- package/useAsyncValidator/component.mjs +5 -29
- package/useAsyncValidator.cjs +5 -29
- package/useAsyncValidator.d.cts +48 -0
- package/useAsyncValidator.d.mts +48 -0
- package/useAsyncValidator.d.ts +1 -1
- package/useAsyncValidator.iife.js +5 -29
- package/useAsyncValidator.iife.min.js +1 -1
- package/useAsyncValidator.mjs +5 -29
- package/useAxios.cjs +8 -25
- package/useAxios.d.cts +94 -0
- package/useAxios.d.mts +94 -0
- package/useAxios.d.ts +1 -1
- package/useAxios.iife.js +8 -25
- package/useAxios.iife.min.js +1 -1
- package/useAxios.mjs +8 -25
- package/useChangeCase.d.cts +24 -0
- package/useChangeCase.d.mts +24 -0
- package/useChangeCase.d.ts +2 -14
- package/useCookies.cjs +2 -18
- package/useCookies.d.cts +54 -0
- package/useCookies.d.mts +54 -0
- package/useCookies.iife.js +2 -18
- package/useCookies.iife.min.js +1 -1
- package/useCookies.mjs +2 -18
- package/useDrauu.cjs +8 -43
- package/useDrauu.d.cts +32 -0
- package/useDrauu.d.mts +32 -0
- package/useDrauu.d.ts +1 -1
- package/useDrauu.iife.js +8 -43
- package/useDrauu.iife.min.js +1 -1
- package/useDrauu.mjs +8 -43
- package/useFocusTrap/component.d.cts +17 -0
- package/useFocusTrap/component.d.mts +17 -0
- package/useFocusTrap/component.d.ts +1 -1
- package/useFocusTrap.cjs +4 -34
- package/useFocusTrap.d.cts +57 -0
- package/useFocusTrap.d.mts +57 -0
- package/useFocusTrap.d.ts +1 -1
- package/useFocusTrap.iife.js +4 -34
- package/useFocusTrap.iife.min.js +1 -1
- package/useFocusTrap.mjs +4 -34
- package/useFuse.cjs +5 -9
- package/useFuse.d.cts +25 -0
- package/useFuse.d.mts +25 -0
- package/useFuse.d.ts +1 -1
- package/useFuse.iife.js +5 -9
- package/useFuse.iife.min.js +1 -1
- package/useFuse.mjs +5 -9
- package/useIDBKeyval.cjs +17 -19
- package/useIDBKeyval.d.cts +43 -0
- package/useIDBKeyval.d.mts +43 -0
- package/useIDBKeyval.d.ts +8 -6
- package/useIDBKeyval.iife.js +18 -21
- package/useIDBKeyval.iife.min.js +1 -1
- package/useIDBKeyval.mjs +18 -20
- package/useJwt.cjs +1 -1
- package/useJwt.d.cts +29 -0
- package/useJwt.d.mts +29 -0
- package/useJwt.d.ts +1 -1
- package/useJwt.iife.js +1 -1
- package/useJwt.iife.min.js +1 -1
- package/useJwt.mjs +1 -1
- package/useNProgress.d.cts +20 -0
- package/useNProgress.d.mts +20 -0
- package/useNProgress.d.ts +1 -1
- package/useQRCode.d.cts +14 -0
- package/useQRCode.d.mts +14 -0
- package/useSortable/component.cjs +13 -36
- package/useSortable/component.d.cts +40 -0
- package/useSortable/component.d.mts +40 -0
- package/useSortable/component.mjs +14 -37
- package/useSortable.cjs +13 -36
- package/useSortable.d.cts +26 -0
- package/useSortable.d.mts +26 -0
- package/useSortable.d.ts +1 -1
- package/useSortable.iife.js +13 -36
- package/useSortable.iife.min.js +1 -1
- package/useSortable.mjs +14 -37
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as vue_demi from 'vue-demi';
|
|
2
|
+
import { PropType } from 'vue-demi';
|
|
3
|
+
import { Rules } from 'async-validator';
|
|
4
|
+
|
|
5
|
+
declare const UseAsyncValidator: vue_demi.DefineComponent<{
|
|
6
|
+
form: {
|
|
7
|
+
type: PropType<Record<string, any>>;
|
|
8
|
+
required: true;
|
|
9
|
+
};
|
|
10
|
+
rules: {
|
|
11
|
+
type: PropType<Rules>;
|
|
12
|
+
required: true;
|
|
13
|
+
};
|
|
14
|
+
}, () => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}>[] | undefined, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
17
|
+
form: {
|
|
18
|
+
type: PropType<Record<string, any>>;
|
|
19
|
+
required: true;
|
|
20
|
+
};
|
|
21
|
+
rules: {
|
|
22
|
+
type: PropType<Rules>;
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
}>>, {}, {}>;
|
|
26
|
+
|
|
27
|
+
export { UseAsyncValidator };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as vue_demi from 'vue-demi';
|
|
2
|
+
import { PropType } from 'vue-demi';
|
|
3
|
+
import { Rules } from 'async-validator';
|
|
4
|
+
|
|
5
|
+
declare const UseAsyncValidator: vue_demi.DefineComponent<{
|
|
6
|
+
form: {
|
|
7
|
+
type: PropType<Record<string, any>>;
|
|
8
|
+
required: true;
|
|
9
|
+
};
|
|
10
|
+
rules: {
|
|
11
|
+
type: PropType<Rules>;
|
|
12
|
+
required: true;
|
|
13
|
+
};
|
|
14
|
+
}, () => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}>[] | undefined, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
17
|
+
form: {
|
|
18
|
+
type: PropType<Record<string, any>>;
|
|
19
|
+
required: true;
|
|
20
|
+
};
|
|
21
|
+
rules: {
|
|
22
|
+
type: PropType<Rules>;
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
}>>, {}, {}>;
|
|
26
|
+
|
|
27
|
+
export { UseAsyncValidator };
|
|
@@ -2,25 +2,6 @@ import { shallowRef, ref, computed, watch, defineComponent, reactive } from 'vue
|
|
|
2
2
|
import { toRef, toValue, until } from '@vueuse/shared';
|
|
3
3
|
import Schema from 'async-validator';
|
|
4
4
|
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defProps = Object.defineProperties;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
5
|
const AsyncValidatorSchema = Schema.default || Schema;
|
|
25
6
|
function useAsyncValidator(value, rules, options = {}) {
|
|
26
7
|
const {
|
|
@@ -32,14 +13,8 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
32
13
|
const errorInfo = shallowRef(null);
|
|
33
14
|
const isFinished = ref(true);
|
|
34
15
|
const pass = ref(!immediate || manual);
|
|
35
|
-
const errors = computed(() =>
|
|
36
|
-
|
|
37
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
|
|
38
|
-
});
|
|
39
|
-
const errorFields = computed(() => {
|
|
40
|
-
var _a;
|
|
41
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.fields) || {};
|
|
42
|
-
});
|
|
16
|
+
const errors = computed(() => errorInfo.value?.errors || []);
|
|
17
|
+
const errorFields = computed(() => errorInfo.value?.fields || {});
|
|
43
18
|
const validator = computed(() => new AsyncValidatorSchema(toValue(rules)));
|
|
44
19
|
const execute = async () => {
|
|
45
20
|
isFinished.value = false;
|
|
@@ -80,11 +55,12 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
80
55
|
until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
81
56
|
});
|
|
82
57
|
}
|
|
83
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
...shell,
|
|
84
60
|
then(onFulfilled, onRejected) {
|
|
85
61
|
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
86
62
|
}
|
|
87
|
-
}
|
|
63
|
+
};
|
|
88
64
|
}
|
|
89
65
|
|
|
90
66
|
const UseAsyncValidator = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
package/useAsyncValidator.cjs
CHANGED
|
@@ -4,25 +4,6 @@ var shared = require('@vueuse/shared');
|
|
|
4
4
|
var Schema = require('async-validator');
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defProps = Object.defineProperties;
|
|
9
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
7
|
const AsyncValidatorSchema = Schema.default || Schema;
|
|
27
8
|
function useAsyncValidator(value, rules, options = {}) {
|
|
28
9
|
const {
|
|
@@ -34,14 +15,8 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
34
15
|
const errorInfo = vueDemi.shallowRef(null);
|
|
35
16
|
const isFinished = vueDemi.ref(true);
|
|
36
17
|
const pass = vueDemi.ref(!immediate || manual);
|
|
37
|
-
const errors = vueDemi.computed(() =>
|
|
38
|
-
|
|
39
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
|
|
40
|
-
});
|
|
41
|
-
const errorFields = vueDemi.computed(() => {
|
|
42
|
-
var _a;
|
|
43
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.fields) || {};
|
|
44
|
-
});
|
|
18
|
+
const errors = vueDemi.computed(() => errorInfo.value?.errors || []);
|
|
19
|
+
const errorFields = vueDemi.computed(() => errorInfo.value?.fields || {});
|
|
45
20
|
const validator = vueDemi.computed(() => new AsyncValidatorSchema(shared.toValue(rules)));
|
|
46
21
|
const execute = async () => {
|
|
47
22
|
isFinished.value = false;
|
|
@@ -82,11 +57,12 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
82
57
|
shared.until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
83
58
|
});
|
|
84
59
|
}
|
|
85
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
...shell,
|
|
86
62
|
then(onFulfilled, onRejected) {
|
|
87
63
|
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
88
64
|
}
|
|
89
|
-
}
|
|
65
|
+
};
|
|
90
66
|
}
|
|
91
67
|
|
|
92
68
|
exports.useAsyncValidator = useAsyncValidator;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from '@vueuse/shared';
|
|
2
|
+
import { ValidateError, ValidateOption, Rules } from 'async-validator';
|
|
3
|
+
import { Ref } from 'vue-demi';
|
|
4
|
+
|
|
5
|
+
type AsyncValidatorError = Error & {
|
|
6
|
+
errors: ValidateError[];
|
|
7
|
+
fields: Record<string, ValidateError[]>;
|
|
8
|
+
};
|
|
9
|
+
interface UseAsyncValidatorExecuteReturn {
|
|
10
|
+
pass: boolean;
|
|
11
|
+
errors: AsyncValidatorError['errors'] | undefined;
|
|
12
|
+
errorInfo: AsyncValidatorError | null;
|
|
13
|
+
errorFields: AsyncValidatorError['fields'] | undefined;
|
|
14
|
+
}
|
|
15
|
+
interface UseAsyncValidatorReturn {
|
|
16
|
+
pass: Ref<boolean>;
|
|
17
|
+
isFinished: Ref<boolean>;
|
|
18
|
+
errors: Ref<AsyncValidatorError['errors'] | undefined>;
|
|
19
|
+
errorInfo: Ref<AsyncValidatorError | null>;
|
|
20
|
+
errorFields: Ref<AsyncValidatorError['fields'] | undefined>;
|
|
21
|
+
execute: () => Promise<UseAsyncValidatorExecuteReturn>;
|
|
22
|
+
}
|
|
23
|
+
interface UseAsyncValidatorOptions {
|
|
24
|
+
/**
|
|
25
|
+
* @see https://github.com/yiminghe/async-validator#options
|
|
26
|
+
*/
|
|
27
|
+
validateOption?: ValidateOption;
|
|
28
|
+
/**
|
|
29
|
+
* The validation will be triggered right away for the first time.
|
|
30
|
+
* Only works when `manual` is not set to true.
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
immediate?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* If set to true, the validation will not be triggered automatically.
|
|
37
|
+
*/
|
|
38
|
+
manual?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wrapper for async-validator.
|
|
42
|
+
*
|
|
43
|
+
* @see https://vueuse.org/useAsyncValidator
|
|
44
|
+
* @see https://github.com/yiminghe/async-validator
|
|
45
|
+
*/
|
|
46
|
+
declare function useAsyncValidator(value: MaybeRefOrGetter<Record<string, any>>, rules: MaybeRefOrGetter<Rules>, options?: UseAsyncValidatorOptions): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>;
|
|
47
|
+
|
|
48
|
+
export { type AsyncValidatorError, type UseAsyncValidatorExecuteReturn, type UseAsyncValidatorOptions, type UseAsyncValidatorReturn, useAsyncValidator };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from '@vueuse/shared';
|
|
2
|
+
import { ValidateError, ValidateOption, Rules } from 'async-validator';
|
|
3
|
+
import { Ref } from 'vue-demi';
|
|
4
|
+
|
|
5
|
+
type AsyncValidatorError = Error & {
|
|
6
|
+
errors: ValidateError[];
|
|
7
|
+
fields: Record<string, ValidateError[]>;
|
|
8
|
+
};
|
|
9
|
+
interface UseAsyncValidatorExecuteReturn {
|
|
10
|
+
pass: boolean;
|
|
11
|
+
errors: AsyncValidatorError['errors'] | undefined;
|
|
12
|
+
errorInfo: AsyncValidatorError | null;
|
|
13
|
+
errorFields: AsyncValidatorError['fields'] | undefined;
|
|
14
|
+
}
|
|
15
|
+
interface UseAsyncValidatorReturn {
|
|
16
|
+
pass: Ref<boolean>;
|
|
17
|
+
isFinished: Ref<boolean>;
|
|
18
|
+
errors: Ref<AsyncValidatorError['errors'] | undefined>;
|
|
19
|
+
errorInfo: Ref<AsyncValidatorError | null>;
|
|
20
|
+
errorFields: Ref<AsyncValidatorError['fields'] | undefined>;
|
|
21
|
+
execute: () => Promise<UseAsyncValidatorExecuteReturn>;
|
|
22
|
+
}
|
|
23
|
+
interface UseAsyncValidatorOptions {
|
|
24
|
+
/**
|
|
25
|
+
* @see https://github.com/yiminghe/async-validator#options
|
|
26
|
+
*/
|
|
27
|
+
validateOption?: ValidateOption;
|
|
28
|
+
/**
|
|
29
|
+
* The validation will be triggered right away for the first time.
|
|
30
|
+
* Only works when `manual` is not set to true.
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
immediate?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* If set to true, the validation will not be triggered automatically.
|
|
37
|
+
*/
|
|
38
|
+
manual?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wrapper for async-validator.
|
|
42
|
+
*
|
|
43
|
+
* @see https://vueuse.org/useAsyncValidator
|
|
44
|
+
* @see https://github.com/yiminghe/async-validator
|
|
45
|
+
*/
|
|
46
|
+
declare function useAsyncValidator(value: MaybeRefOrGetter<Record<string, any>>, rules: MaybeRefOrGetter<Rules>, options?: UseAsyncValidatorOptions): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>;
|
|
47
|
+
|
|
48
|
+
export { type AsyncValidatorError, type UseAsyncValidatorExecuteReturn, type UseAsyncValidatorOptions, type UseAsyncValidatorReturn, useAsyncValidator };
|
package/useAsyncValidator.d.ts
CHANGED
|
@@ -45,4 +45,4 @@ interface UseAsyncValidatorOptions {
|
|
|
45
45
|
*/
|
|
46
46
|
declare function useAsyncValidator(value: MaybeRefOrGetter<Record<string, any>>, rules: MaybeRefOrGetter<Rules>, options?: UseAsyncValidatorOptions): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>;
|
|
47
47
|
|
|
48
|
-
export { AsyncValidatorError, UseAsyncValidatorExecuteReturn, UseAsyncValidatorOptions, UseAsyncValidatorReturn, useAsyncValidator };
|
|
48
|
+
export { type AsyncValidatorError, type UseAsyncValidatorExecuteReturn, type UseAsyncValidatorOptions, type UseAsyncValidatorReturn, useAsyncValidator };
|
|
@@ -117,25 +117,6 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
|
117
117
|
;(function (exports, shared, Schema, vueDemi) {
|
|
118
118
|
'use strict';
|
|
119
119
|
|
|
120
|
-
var __defProp = Object.defineProperty;
|
|
121
|
-
var __defProps = Object.defineProperties;
|
|
122
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
123
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
124
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
125
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
126
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
127
|
-
var __spreadValues = (a, b) => {
|
|
128
|
-
for (var prop in b || (b = {}))
|
|
129
|
-
if (__hasOwnProp.call(b, prop))
|
|
130
|
-
__defNormalProp(a, prop, b[prop]);
|
|
131
|
-
if (__getOwnPropSymbols)
|
|
132
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
133
|
-
if (__propIsEnum.call(b, prop))
|
|
134
|
-
__defNormalProp(a, prop, b[prop]);
|
|
135
|
-
}
|
|
136
|
-
return a;
|
|
137
|
-
};
|
|
138
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
139
120
|
const AsyncValidatorSchema = Schema.default || Schema;
|
|
140
121
|
function useAsyncValidator(value, rules, options = {}) {
|
|
141
122
|
const {
|
|
@@ -147,14 +128,8 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
|
147
128
|
const errorInfo = vueDemi.shallowRef(null);
|
|
148
129
|
const isFinished = vueDemi.ref(true);
|
|
149
130
|
const pass = vueDemi.ref(!immediate || manual);
|
|
150
|
-
const errors = vueDemi.computed(() =>
|
|
151
|
-
|
|
152
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
|
|
153
|
-
});
|
|
154
|
-
const errorFields = vueDemi.computed(() => {
|
|
155
|
-
var _a;
|
|
156
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.fields) || {};
|
|
157
|
-
});
|
|
131
|
+
const errors = vueDemi.computed(() => errorInfo.value?.errors || []);
|
|
132
|
+
const errorFields = vueDemi.computed(() => errorInfo.value?.fields || {});
|
|
158
133
|
const validator = vueDemi.computed(() => new AsyncValidatorSchema(shared.toValue(rules)));
|
|
159
134
|
const execute = async () => {
|
|
160
135
|
isFinished.value = false;
|
|
@@ -195,11 +170,12 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
|
195
170
|
shared.until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
196
171
|
});
|
|
197
172
|
}
|
|
198
|
-
return
|
|
173
|
+
return {
|
|
174
|
+
...shell,
|
|
199
175
|
then(onFulfilled, onRejected) {
|
|
200
176
|
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
201
177
|
}
|
|
202
|
-
}
|
|
178
|
+
};
|
|
203
179
|
}
|
|
204
180
|
|
|
205
181
|
exports.useAsyncValidator = useAsyncValidator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(r,
|
|
1
|
+
var VueDemi=function(n,r,c){if(n.install)return n;if(!r)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(r.version.slice(0,4)==="2.7."){let e=function(s,l){var o,v={},u={config:r.config,use:r.use.bind(r),mixin:r.mixin.bind(r),component:r.component.bind(r),provide:function(i,a){return v[i]=a,this},directive:function(i,a){return a?(r.directive(i,a),u):r.directive(i)},mount:function(i,a){return o||(o=new r(Object.assign({propsData:l},s,{provide:Object.assign(v,s.provide)})),o.$mount(i,a),o)},unmount:function(){o&&(o.$destroy(),o=void 0)}};return u};var A=e;for(var t in r)n[t]=r[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=r,n.Vue2=r,n.version=r.version,n.warn=r.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=e}else if(r.version.slice(0,2)==="2.")if(c){for(var t in c)n[t]=c[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=r,n.Vue2=r,n.version=r.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(r.version.slice(0,2)==="3."){for(var t in r)n[t]=r[t];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=r,n.Vue2=void 0,n.version=r.version,n.set=function(e,s,l){return Array.isArray(e)?(e.length=Math.max(e.length,s),e.splice(s,1,l),l):(e[s]=l,l)},n.del=function(e,s){if(Array.isArray(e)){e.splice(s,1);return}delete e[s]}}else console.error("[vue-demi] Vue version "+r.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,r,c,t){"use strict";const A=c.default||c;function e(s,l,o={}){const{validateOption:v={},immediate:u=!0,manual:i=!1}=o,a=r.toRef(s),f=t.shallowRef(null),p=t.ref(!0),h=t.ref(!u||i),b=t.computed(()=>f.value?.errors||[]),w=t.computed(()=>f.value?.fields||{}),I=t.computed(()=>new A(r.toValue(l))),x=async()=>{p.value=!1,h.value=!1;try{await I.value.validate(a.value,v),h.value=!0,f.value=null}catch(d){f.value=d}finally{p.value=!0}return{pass:h.value,errorInfo:f.value,errors:b.value,errorFields:w.value}};i||t.watch([a,I],()=>x(),{immediate:u,deep:!0});const C={isFinished:p,pass:h,errors:b,errorInfo:f,errorFields:w,execute:x};function j(){return new Promise((d,y)=>{r.until(p).toBe(!0).then(()=>d(C)).catch(F=>y(F))})}return{...C,then(d,y){return j().then(d,y)}}}n.useAsyncValidator=e})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,VueDemi);
|
package/useAsyncValidator.mjs
CHANGED
|
@@ -2,25 +2,6 @@ import { toRef, toValue, until } from '@vueuse/shared';
|
|
|
2
2
|
import Schema from 'async-validator';
|
|
3
3
|
import { shallowRef, ref, computed, watch } from 'vue-demi';
|
|
4
4
|
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defProps = Object.defineProperties;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
5
|
const AsyncValidatorSchema = Schema.default || Schema;
|
|
25
6
|
function useAsyncValidator(value, rules, options = {}) {
|
|
26
7
|
const {
|
|
@@ -32,14 +13,8 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
32
13
|
const errorInfo = shallowRef(null);
|
|
33
14
|
const isFinished = ref(true);
|
|
34
15
|
const pass = ref(!immediate || manual);
|
|
35
|
-
const errors = computed(() =>
|
|
36
|
-
|
|
37
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.errors) || [];
|
|
38
|
-
});
|
|
39
|
-
const errorFields = computed(() => {
|
|
40
|
-
var _a;
|
|
41
|
-
return ((_a = errorInfo.value) == null ? void 0 : _a.fields) || {};
|
|
42
|
-
});
|
|
16
|
+
const errors = computed(() => errorInfo.value?.errors || []);
|
|
17
|
+
const errorFields = computed(() => errorInfo.value?.fields || {});
|
|
43
18
|
const validator = computed(() => new AsyncValidatorSchema(toValue(rules)));
|
|
44
19
|
const execute = async () => {
|
|
45
20
|
isFinished.value = false;
|
|
@@ -80,11 +55,12 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
80
55
|
until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
81
56
|
});
|
|
82
57
|
}
|
|
83
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
...shell,
|
|
84
60
|
then(onFulfilled, onRejected) {
|
|
85
61
|
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
86
62
|
}
|
|
87
|
-
}
|
|
63
|
+
};
|
|
88
64
|
}
|
|
89
65
|
|
|
90
66
|
export { useAsyncValidator };
|
package/useAxios.cjs
CHANGED
|
@@ -4,25 +4,6 @@ var vueDemi = require('vue-demi');
|
|
|
4
4
|
var shared = require('@vueuse/shared');
|
|
5
5
|
var axios = require('axios');
|
|
6
6
|
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defProps = Object.defineProperties;
|
|
9
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
7
|
function useAxios(...args) {
|
|
27
8
|
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
28
9
|
const argsPlaceholder = typeof url === "string" ? 1 : 0;
|
|
@@ -32,7 +13,7 @@ function useAxios(...args) {
|
|
|
32
13
|
immediate: !!argsPlaceholder,
|
|
33
14
|
shallow: true
|
|
34
15
|
};
|
|
35
|
-
const isAxiosInstance = (val) => !!
|
|
16
|
+
const isAxiosInstance = (val) => !!val?.request;
|
|
36
17
|
if (args.length > 0 + argsPlaceholder) {
|
|
37
18
|
if (isAxiosInstance(args[0 + argsPlaceholder]))
|
|
38
19
|
instance = args[0 + argsPlaceholder];
|
|
@@ -88,7 +69,7 @@ function useAxios(...args) {
|
|
|
88
69
|
let executeCounter = 0;
|
|
89
70
|
const execute = (executeUrl = url, config = {}) => {
|
|
90
71
|
error.value = void 0;
|
|
91
|
-
const _url = typeof executeUrl === "string" ? executeUrl : url
|
|
72
|
+
const _url = typeof executeUrl === "string" ? executeUrl : url ?? config.url;
|
|
92
73
|
if (_url === void 0) {
|
|
93
74
|
error.value = new axios.AxiosError(axios.AxiosError.ERR_INVALID_URL);
|
|
94
75
|
isFinished.value = true;
|
|
@@ -99,7 +80,7 @@ function useAxios(...args) {
|
|
|
99
80
|
loading(true);
|
|
100
81
|
executeCounter += 1;
|
|
101
82
|
const currentExecuteCounter = executeCounter;
|
|
102
|
-
instance(_url,
|
|
83
|
+
instance(_url, { ...defaultConfig, ...typeof executeUrl === "object" ? executeUrl : config, cancelToken: cancelToken.token }).then((r) => {
|
|
103
84
|
response.value = r;
|
|
104
85
|
const result2 = r.data;
|
|
105
86
|
data.value = result2;
|
|
@@ -108,8 +89,7 @@ function useAxios(...args) {
|
|
|
108
89
|
error.value = e;
|
|
109
90
|
onError(e);
|
|
110
91
|
}).finally(() => {
|
|
111
|
-
|
|
112
|
-
(_a = options.onFinish) == null ? void 0 : _a.call(options);
|
|
92
|
+
options.onFinish?.();
|
|
113
93
|
if (currentExecuteCounter === executeCounter)
|
|
114
94
|
loading(false);
|
|
115
95
|
});
|
|
@@ -129,7 +109,10 @@ function useAxios(...args) {
|
|
|
129
109
|
abort,
|
|
130
110
|
execute
|
|
131
111
|
};
|
|
132
|
-
return
|
|
112
|
+
return {
|
|
113
|
+
...result,
|
|
114
|
+
...promise
|
|
115
|
+
};
|
|
133
116
|
}
|
|
134
117
|
|
|
135
118
|
exports.useAxios = useAxios;
|
package/useAxios.d.cts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ShallowRef, Ref } from 'vue-demi';
|
|
2
|
+
import { AxiosResponse, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
3
|
+
|
|
4
|
+
interface UseAxiosReturn<T, R = AxiosResponse<T>, _D = any> {
|
|
5
|
+
/**
|
|
6
|
+
* Axios Response
|
|
7
|
+
*/
|
|
8
|
+
response: ShallowRef<R | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Axios response data
|
|
11
|
+
*/
|
|
12
|
+
data: Ref<T | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Indicates if the request has finished
|
|
15
|
+
*/
|
|
16
|
+
isFinished: Ref<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Indicates if the request is currently loading
|
|
19
|
+
*/
|
|
20
|
+
isLoading: Ref<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates if the request was canceled
|
|
23
|
+
*/
|
|
24
|
+
isAborted: Ref<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Any errors that may have occurred
|
|
27
|
+
*/
|
|
28
|
+
error: ShallowRef<unknown | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Aborts the current request
|
|
31
|
+
*/
|
|
32
|
+
abort: (message?: string | undefined) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Alias to `abort`
|
|
35
|
+
*/
|
|
36
|
+
cancel: (message?: string | undefined) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Alias to `isAborted`
|
|
39
|
+
*/
|
|
40
|
+
isCanceled: Ref<boolean>;
|
|
41
|
+
}
|
|
42
|
+
interface StrictUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
|
|
43
|
+
/**
|
|
44
|
+
* Manually call the axios request
|
|
45
|
+
*/
|
|
46
|
+
execute: (url?: string | AxiosRequestConfig<D>, config?: AxiosRequestConfig<D>) => Promise<StrictUseAxiosReturn<T, R, D>>;
|
|
47
|
+
}
|
|
48
|
+
interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
|
|
49
|
+
/**
|
|
50
|
+
* Manually call the axios request
|
|
51
|
+
*/
|
|
52
|
+
execute: (url: string, config?: AxiosRequestConfig<D>) => Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
53
|
+
}
|
|
54
|
+
interface UseAxiosOptions<T = any> {
|
|
55
|
+
/**
|
|
56
|
+
* Will automatically run axios request when `useAxios` is used
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
immediate?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Use shallowRef.
|
|
62
|
+
*
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
shallow?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Callback when error is caught.
|
|
68
|
+
*/
|
|
69
|
+
onError?: (e: unknown) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Callback when success is caught.
|
|
72
|
+
*/
|
|
73
|
+
onSuccess?: (data: T) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Initial data to use
|
|
76
|
+
*/
|
|
77
|
+
initialData?: T;
|
|
78
|
+
/**
|
|
79
|
+
* Sets the state to initialState before executing the promise.
|
|
80
|
+
*/
|
|
81
|
+
resetOnExecute?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Callback when request is finished.
|
|
84
|
+
*/
|
|
85
|
+
onFinish?: () => void;
|
|
86
|
+
}
|
|
87
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & Promise<StrictUseAxiosReturn<T, R, D>>;
|
|
88
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & Promise<StrictUseAxiosReturn<T, R, D>>;
|
|
89
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config: AxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & Promise<StrictUseAxiosReturn<T, R, D>>;
|
|
90
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
91
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
92
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
93
|
+
|
|
94
|
+
export { type EasyUseAxiosReturn, type StrictUseAxiosReturn, type UseAxiosOptions, type UseAxiosReturn, useAxios };
|