@vueuse/integrations 13.9.0 → 14.0.0-alpha.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/dist/index.d.ts +473 -0
- package/dist/index.iife.js +772 -0
- package/dist/index.iife.min.js +1 -0
- package/dist/index.js +731 -0
- package/dist/useAsyncValidator/component.d.ts +19 -0
- package/dist/useAsyncValidator/component.js +20 -0
- package/dist/useAsyncValidator.d.ts +48 -0
- package/dist/useAsyncValidator.iife.js +99 -0
- package/dist/useAsyncValidator.iife.min.js +1 -0
- package/dist/useAsyncValidator.js +73 -0
- package/{useAxios.d.mts → dist/useAxios.d.ts} +86 -86
- package/dist/useAxios.iife.js +150 -0
- package/dist/useAxios.iife.min.js +1 -0
- package/dist/useAxios.js +124 -0
- package/{useChangeCase.d.mts → dist/useChangeCase.d.ts} +7 -9
- package/dist/useChangeCase.iife.js +61 -0
- package/dist/useChangeCase.iife.min.js +1 -0
- package/dist/useChangeCase.js +35 -0
- package/dist/useCookies.d.ts +64 -0
- package/dist/useCookies.iife.js +104 -0
- package/dist/useCookies.iife.min.js +1 -0
- package/dist/useCookies.js +77 -0
- package/dist/useDrauu.d.ts +33 -0
- package/dist/useDrauu.iife.js +146 -0
- package/dist/useDrauu.iife.min.js +1 -0
- package/dist/useDrauu.js +120 -0
- package/dist/useFocusTrap/component.d.ts +21 -0
- package/dist/useFocusTrap/component.js +17 -0
- package/dist/useFocusTrap.d.ts +55 -0
- package/dist/useFocusTrap.iife.js +97 -0
- package/dist/useFocusTrap.iife.min.js +1 -0
- package/dist/useFocusTrap.js +71 -0
- package/dist/useFuse.d.ts +33 -0
- package/dist/useFuse.iife.js +62 -0
- package/dist/useFuse.iife.min.js +1 -0
- package/dist/useFuse.js +36 -0
- package/dist/useIDBKeyval.d.ts +52 -0
- package/dist/useIDBKeyval.iife.js +93 -0
- package/dist/useIDBKeyval.iife.min.js +1 -0
- package/dist/useIDBKeyval.js +67 -0
- package/dist/useJwt.d.ts +28 -0
- package/dist/useJwt.iife.js +55 -0
- package/dist/useJwt.iife.min.js +1 -0
- package/dist/useJwt.js +29 -0
- package/dist/useNProgress.d.ts +21 -0
- package/dist/useNProgress.iife.js +66 -0
- package/dist/useNProgress.iife.min.js +1 -0
- package/dist/useNProgress.js +40 -0
- package/dist/useQRCode.d.ts +16 -0
- package/dist/useQRCode.iife.js +49 -0
- package/dist/useQRCode.iife.min.js +1 -0
- package/dist/useQRCode.js +23 -0
- package/dist/useSortable/component.d.ts +18 -0
- package/dist/useSortable/component.js +23 -0
- package/{useSortable.d.mts → dist/useSortable.d.ts} +20 -20
- package/dist/useSortable.iife.js +107 -0
- package/dist/useSortable.iife.min.js +1 -0
- package/dist/useSortable.js +78 -0
- package/package.json +27 -29
- package/index.d.mts +0 -458
- package/index.iife.js +0 -708
- package/index.iife.min.js +0 -1
- package/index.mjs +0 -685
- package/useAsyncValidator/component.d.mts +0 -27
- package/useAsyncValidator/component.mjs +0 -87
- package/useAsyncValidator.d.mts +0 -48
- package/useAsyncValidator.iife.js +0 -73
- package/useAsyncValidator.iife.min.js +0 -1
- package/useAsyncValidator.mjs +0 -72
- package/useAxios.iife.js +0 -124
- package/useAxios.iife.min.js +0 -1
- package/useAxios.mjs +0 -123
- package/useChangeCase.iife.js +0 -50
- package/useChangeCase.iife.min.js +0 -1
- package/useChangeCase.mjs +0 -29
- package/useCookies.d.mts +0 -56
- package/useCookies.iife.js +0 -64
- package/useCookies.iife.min.js +0 -1
- package/useCookies.mjs +0 -62
- package/useDrauu.d.mts +0 -33
- package/useDrauu.iife.js +0 -114
- package/useDrauu.iife.min.js +0 -1
- package/useDrauu.mjs +0 -114
- package/useFocusTrap/component.d.mts +0 -18
- package/useFocusTrap/component.mjs +0 -31
- package/useFocusTrap.d.mts +0 -55
- package/useFocusTrap.iife.js +0 -74
- package/useFocusTrap.iife.min.js +0 -1
- package/useFocusTrap.mjs +0 -74
- package/useFuse.d.mts +0 -33
- package/useFuse.iife.js +0 -45
- package/useFuse.iife.min.js +0 -1
- package/useFuse.mjs +0 -43
- package/useIDBKeyval.d.mts +0 -52
- package/useIDBKeyval.iife.js +0 -70
- package/useIDBKeyval.iife.min.js +0 -1
- package/useIDBKeyval.mjs +0 -69
- package/useJwt.d.mts +0 -28
- package/useJwt.iife.js +0 -27
- package/useJwt.iife.min.js +0 -1
- package/useJwt.mjs +0 -25
- package/useNProgress.d.mts +0 -21
- package/useNProgress.iife.js +0 -36
- package/useNProgress.iife.min.js +0 -1
- package/useNProgress.mjs +0 -35
- package/useQRCode.d.mts +0 -14
- package/useQRCode.iife.js +0 -20
- package/useQRCode.iife.min.js +0 -1
- package/useQRCode.mjs +0 -19
- package/useSortable/component.d.mts +0 -40
- package/useSortable/component.mjs +0 -89
- package/useSortable.iife.js +0 -66
- package/useSortable.iife.min.js +0 -1
- package/useSortable.mjs +0 -62
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UseAsyncValidatorOptions, UseAsyncValidatorReturn } from "@vueuse/integrations/useAsyncValidator";
|
|
2
|
+
import * as vue0 from "vue";
|
|
3
|
+
import { Reactive, SlotsType } from "vue";
|
|
4
|
+
import { Rules } from "async-validator";
|
|
5
|
+
|
|
6
|
+
//#region useAsyncValidator/component.d.ts
|
|
7
|
+
interface UseAsyncValidatorProps {
|
|
8
|
+
form: Record<string, any>;
|
|
9
|
+
rules: Rules;
|
|
10
|
+
options?: UseAsyncValidatorOptions;
|
|
11
|
+
}
|
|
12
|
+
interface UseAsyncValidatorSlots {
|
|
13
|
+
default: (data: Reactive<UseAsyncValidatorReturn>) => any;
|
|
14
|
+
}
|
|
15
|
+
declare const UseAsyncValidator: vue0.DefineSetupFnComponent<UseAsyncValidatorProps, Record<string, never>, SlotsType<UseAsyncValidatorSlots>, UseAsyncValidatorProps & {
|
|
16
|
+
[x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
|
|
17
|
+
}, vue0.PublicProps>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { UseAsyncValidator, UseAsyncValidatorProps };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useAsyncValidator } from "@vueuse/integrations/useAsyncValidator";
|
|
2
|
+
import { defineComponent, reactive } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region useAsyncValidator/component.ts
|
|
5
|
+
const UseAsyncValidator = /* @__PURE__ */ defineComponent((props, { slots }) => {
|
|
6
|
+
const data = reactive(useAsyncValidator(props.form, props.rules));
|
|
7
|
+
return () => {
|
|
8
|
+
if (slots.default) return slots.default(data);
|
|
9
|
+
};
|
|
10
|
+
}, {
|
|
11
|
+
name: "UseAsyncValidator",
|
|
12
|
+
props: [
|
|
13
|
+
"form",
|
|
14
|
+
"options",
|
|
15
|
+
"rules"
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { UseAsyncValidator };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Rules, ValidateError, ValidateOption } from "async-validator";
|
|
2
|
+
import { ComputedRef, MaybeRefOrGetter, ShallowRef } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region useAsyncValidator/index.d.ts
|
|
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: ShallowRef<boolean>;
|
|
17
|
+
isFinished: ShallowRef<boolean>;
|
|
18
|
+
errors: ComputedRef<AsyncValidatorError['errors'] | undefined>;
|
|
19
|
+
errorInfo: ShallowRef<AsyncValidatorError | null>;
|
|
20
|
+
errorFields: ComputedRef<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
|
+
//#endregion
|
|
48
|
+
export { AsyncValidatorError, UseAsyncValidatorExecuteReturn, UseAsyncValidatorOptions, UseAsyncValidatorReturn, useAsyncValidator };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
(function(exports, __vueuse_shared, async_validator, vue) {
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
__vueuse_shared = __toESM(__vueuse_shared);
|
|
27
|
+
async_validator = __toESM(async_validator);
|
|
28
|
+
vue = __toESM(vue);
|
|
29
|
+
|
|
30
|
+
//#region useAsyncValidator/index.ts
|
|
31
|
+
const AsyncValidatorSchema = async_validator.default.default || async_validator.default;
|
|
32
|
+
/**
|
|
33
|
+
* Wrapper for async-validator.
|
|
34
|
+
*
|
|
35
|
+
* @see https://vueuse.org/useAsyncValidator
|
|
36
|
+
* @see https://github.com/yiminghe/async-validator
|
|
37
|
+
*/
|
|
38
|
+
function useAsyncValidator(value, rules, options = {}) {
|
|
39
|
+
const { validateOption = {}, immediate = true, manual = false } = options;
|
|
40
|
+
const valueRef = (0, __vueuse_shared.toRef)(value);
|
|
41
|
+
const errorInfo = (0, vue.shallowRef)(null);
|
|
42
|
+
const isFinished = (0, vue.shallowRef)(true);
|
|
43
|
+
const pass = (0, vue.shallowRef)(!immediate || manual);
|
|
44
|
+
const errors = (0, vue.computed)(() => {
|
|
45
|
+
var _errorInfo$value;
|
|
46
|
+
return ((_errorInfo$value = errorInfo.value) === null || _errorInfo$value === void 0 ? void 0 : _errorInfo$value.errors) || [];
|
|
47
|
+
});
|
|
48
|
+
const errorFields = (0, vue.computed)(() => {
|
|
49
|
+
var _errorInfo$value2;
|
|
50
|
+
return ((_errorInfo$value2 = errorInfo.value) === null || _errorInfo$value2 === void 0 ? void 0 : _errorInfo$value2.fields) || {};
|
|
51
|
+
});
|
|
52
|
+
const validator = (0, vue.computed)(() => new AsyncValidatorSchema((0, vue.toValue)(rules)));
|
|
53
|
+
const execute = async () => {
|
|
54
|
+
isFinished.value = false;
|
|
55
|
+
pass.value = false;
|
|
56
|
+
try {
|
|
57
|
+
await validator.value.validate(valueRef.value, validateOption);
|
|
58
|
+
pass.value = true;
|
|
59
|
+
errorInfo.value = null;
|
|
60
|
+
} catch (err) {
|
|
61
|
+
errorInfo.value = err;
|
|
62
|
+
} finally {
|
|
63
|
+
isFinished.value = true;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
pass: pass.value,
|
|
67
|
+
errorInfo: errorInfo.value,
|
|
68
|
+
errors: errors.value,
|
|
69
|
+
errorFields: errorFields.value
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
if (!manual) (0, vue.watch)([valueRef, validator], () => execute(), {
|
|
73
|
+
immediate,
|
|
74
|
+
deep: true
|
|
75
|
+
});
|
|
76
|
+
const shell = {
|
|
77
|
+
isFinished,
|
|
78
|
+
pass,
|
|
79
|
+
errors,
|
|
80
|
+
errorInfo,
|
|
81
|
+
errorFields,
|
|
82
|
+
execute
|
|
83
|
+
};
|
|
84
|
+
function waitUntilFinished() {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
(0, __vueuse_shared.until)(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...shell,
|
|
91
|
+
then(onFulfilled, onRejected) {
|
|
92
|
+
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
exports.useAsyncValidator = useAsyncValidator;
|
|
99
|
+
})(this.VueUse = this.VueUse || {}, VueUse, AsyncValidator, Vue);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(exports,t,n,r){var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e));t=d(t),n=d(n),r=d(r);let f=n.default.default||n.default;function p(e,n,i={}){let{validateOption:a={},immediate:o=!0,manual:s=!1}=i,c=(0,t.toRef)(e),l=(0,r.shallowRef)(null),u=(0,r.shallowRef)(!0),d=(0,r.shallowRef)(!o||s),p=(0,r.computed)(()=>{var e;return((e=l.value)==null?void 0:e.errors)||[]}),m=(0,r.computed)(()=>{var e;return((e=l.value)==null?void 0:e.fields)||{}}),h=(0,r.computed)(()=>new f((0,r.toValue)(n))),g=async()=>{u.value=!1,d.value=!1;try{await h.value.validate(c.value,a),d.value=!0,l.value=null}catch(e){l.value=e}finally{u.value=!0}return{pass:d.value,errorInfo:l.value,errors:p.value,errorFields:m.value}};s||(0,r.watch)([c,h],()=>g(),{immediate:o,deep:!0});let _={isFinished:u,pass:d,errors:p,errorInfo:l,errorFields:m,execute:g};function v(){return new Promise((e,n)=>{(0,t.until)(u).toBe(!0).then(()=>e(_)).catch(e=>n(e))})}return{..._,then(e,t){return v().then(e,t)}}}exports.useAsyncValidator=p})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,Vue);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { toRef, until } from "@vueuse/shared";
|
|
2
|
+
import Schema from "async-validator";
|
|
3
|
+
import { computed, shallowRef, toValue, watch } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region useAsyncValidator/index.ts
|
|
6
|
+
const AsyncValidatorSchema = Schema.default || Schema;
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper for async-validator.
|
|
9
|
+
*
|
|
10
|
+
* @see https://vueuse.org/useAsyncValidator
|
|
11
|
+
* @see https://github.com/yiminghe/async-validator
|
|
12
|
+
*/
|
|
13
|
+
function useAsyncValidator(value, rules, options = {}) {
|
|
14
|
+
const { validateOption = {}, immediate = true, manual = false } = options;
|
|
15
|
+
const valueRef = toRef(value);
|
|
16
|
+
const errorInfo = shallowRef(null);
|
|
17
|
+
const isFinished = shallowRef(true);
|
|
18
|
+
const pass = shallowRef(!immediate || manual);
|
|
19
|
+
const errors = computed(() => {
|
|
20
|
+
var _errorInfo$value;
|
|
21
|
+
return ((_errorInfo$value = errorInfo.value) === null || _errorInfo$value === void 0 ? void 0 : _errorInfo$value.errors) || [];
|
|
22
|
+
});
|
|
23
|
+
const errorFields = computed(() => {
|
|
24
|
+
var _errorInfo$value2;
|
|
25
|
+
return ((_errorInfo$value2 = errorInfo.value) === null || _errorInfo$value2 === void 0 ? void 0 : _errorInfo$value2.fields) || {};
|
|
26
|
+
});
|
|
27
|
+
const validator = computed(() => new AsyncValidatorSchema(toValue(rules)));
|
|
28
|
+
const execute = async () => {
|
|
29
|
+
isFinished.value = false;
|
|
30
|
+
pass.value = false;
|
|
31
|
+
try {
|
|
32
|
+
await validator.value.validate(valueRef.value, validateOption);
|
|
33
|
+
pass.value = true;
|
|
34
|
+
errorInfo.value = null;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
errorInfo.value = err;
|
|
37
|
+
} finally {
|
|
38
|
+
isFinished.value = true;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
pass: pass.value,
|
|
42
|
+
errorInfo: errorInfo.value,
|
|
43
|
+
errors: errors.value,
|
|
44
|
+
errorFields: errorFields.value
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
if (!manual) watch([valueRef, validator], () => execute(), {
|
|
48
|
+
immediate,
|
|
49
|
+
deep: true
|
|
50
|
+
});
|
|
51
|
+
const shell = {
|
|
52
|
+
isFinished,
|
|
53
|
+
pass,
|
|
54
|
+
errors,
|
|
55
|
+
errorInfo,
|
|
56
|
+
errorFields,
|
|
57
|
+
execute
|
|
58
|
+
};
|
|
59
|
+
function waitUntilFinished() {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
...shell,
|
|
66
|
+
then(onFulfilled, onRejected) {
|
|
67
|
+
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { useAsyncValidator };
|
|
@@ -1,96 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
+
import { Ref, ShallowRef } from "vue";
|
|
3
3
|
|
|
4
|
+
//#region useAxios/index.d.ts
|
|
4
5
|
interface UseAxiosReturn<T, R = AxiosResponse<T>, _D = any, O extends UseAxiosOptions = UseAxiosOptions<T>> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Axios Response
|
|
8
|
+
*/
|
|
9
|
+
response: ShallowRef<R | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* Axios response data
|
|
12
|
+
*/
|
|
13
|
+
data: O extends UseAxiosOptionsWithInitialData<T> ? Ref<T> : Ref<T | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Indicates if the request has finished
|
|
16
|
+
*/
|
|
17
|
+
isFinished: Ref<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Indicates if the request is currently loading
|
|
20
|
+
*/
|
|
21
|
+
isLoading: Ref<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Indicates if the request was canceled
|
|
24
|
+
*/
|
|
25
|
+
isAborted: Ref<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Any errors that may have occurred
|
|
28
|
+
*/
|
|
29
|
+
error: ShallowRef<unknown | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Aborts the current request
|
|
32
|
+
*/
|
|
33
|
+
abort: (message?: string | undefined) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Alias to `abort`
|
|
36
|
+
*/
|
|
37
|
+
cancel: (message?: string | undefined) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Alias to `isAborted`
|
|
40
|
+
*/
|
|
41
|
+
isCanceled: Ref<boolean>;
|
|
41
42
|
}
|
|
42
43
|
interface StrictUseAxiosReturn<T, R, D, O extends UseAxiosOptions = UseAxiosOptions<T>> extends UseAxiosReturn<T, R, D, O> {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Manually call the axios request
|
|
46
|
+
*/
|
|
47
|
+
execute: (url?: string | AxiosRequestConfig<D>, config?: AxiosRequestConfig<D>) => Promise<StrictUseAxiosReturn<T, R, D, O>>;
|
|
47
48
|
}
|
|
48
49
|
interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Manually call the axios request
|
|
52
|
+
*/
|
|
53
|
+
execute: (url: string, config?: AxiosRequestConfig<D>) => Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
53
54
|
}
|
|
54
55
|
interface UseAxiosOptionsBase<T = any> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Will automatically run axios request when `useAxios` is used
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
immediate?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Use shallowRef.
|
|
63
|
+
*
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
shallow?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Abort previous request when a new request is made.
|
|
69
|
+
*
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
abortPrevious?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Callback when error is caught.
|
|
75
|
+
*/
|
|
76
|
+
onError?: (e: unknown) => void;
|
|
77
|
+
/**
|
|
78
|
+
* Callback when success is caught.
|
|
79
|
+
*/
|
|
80
|
+
onSuccess?: (data: T) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the state to initialState before executing the promise.
|
|
83
|
+
*/
|
|
84
|
+
resetOnExecute?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Callback when request is finished.
|
|
87
|
+
*/
|
|
88
|
+
onFinish?: () => void;
|
|
88
89
|
}
|
|
89
90
|
interface UseAxiosOptionsWithInitialData<T> extends UseAxiosOptionsBase<T> {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Initial data
|
|
93
|
+
*/
|
|
94
|
+
initialData: T;
|
|
94
95
|
}
|
|
95
96
|
type UseAxiosOptions<T = any> = UseAxiosOptionsBase<T> | UseAxiosOptionsWithInitialData<T>;
|
|
96
97
|
declare function useAxios<T = any, R = AxiosResponse<T>, D = any, O extends UseAxiosOptionsWithInitialData<T> = UseAxiosOptionsWithInitialData<T>>(url: string, config?: AxiosRequestConfig<D>, options?: O): StrictUseAxiosReturn<T, R, D, O> & Promise<StrictUseAxiosReturn<T, R, D, O>>;
|
|
@@ -102,6 +103,5 @@ declare function useAxios<T = any, R = AxiosResponse<T>, D = any, O extends UseA
|
|
|
102
103
|
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
103
104
|
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
104
105
|
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & Promise<EasyUseAxiosReturn<T, R, D>>;
|
|
105
|
-
|
|
106
|
-
export { useAxios };
|
|
107
|
-
export type { EasyUseAxiosReturn, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosOptionsBase, UseAxiosOptionsWithInitialData, UseAxiosReturn };
|
|
106
|
+
//#endregion
|
|
107
|
+
export { EasyUseAxiosReturn, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosOptionsBase, UseAxiosOptionsWithInitialData, UseAxiosReturn, useAxios };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
(function(exports, __vueuse_shared, axios, vue) {
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
__vueuse_shared = __toESM(__vueuse_shared);
|
|
27
|
+
axios = __toESM(axios);
|
|
28
|
+
vue = __toESM(vue);
|
|
29
|
+
|
|
30
|
+
//#region useAxios/index.ts
|
|
31
|
+
/**
|
|
32
|
+
* Wrapper for axios.
|
|
33
|
+
*
|
|
34
|
+
* @see https://vueuse.org/useAxios
|
|
35
|
+
*/
|
|
36
|
+
function useAxios(...args) {
|
|
37
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
38
|
+
const argsPlaceholder = typeof url === "string" ? 1 : 0;
|
|
39
|
+
const defaultOptions = {
|
|
40
|
+
immediate: !!argsPlaceholder,
|
|
41
|
+
shallow: true,
|
|
42
|
+
abortPrevious: true
|
|
43
|
+
};
|
|
44
|
+
let defaultConfig = {};
|
|
45
|
+
let instance = axios.default;
|
|
46
|
+
let options = defaultOptions;
|
|
47
|
+
const isAxiosInstance = (val) => !!(val === null || val === void 0 ? void 0 : val.request);
|
|
48
|
+
if (args.length > 0 + argsPlaceholder)
|
|
49
|
+
/**
|
|
50
|
+
* Unable to use `instanceof` here because of (https://github.com/axios/axios/issues/737)
|
|
51
|
+
* so instead we are checking if there is a `request` on the object to see if it is an
|
|
52
|
+
* axios instance
|
|
53
|
+
*/
|
|
54
|
+
if (isAxiosInstance(args[0 + argsPlaceholder])) instance = args[0 + argsPlaceholder];
|
|
55
|
+
else defaultConfig = args[0 + argsPlaceholder];
|
|
56
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
57
|
+
if (isAxiosInstance(args[1 + argsPlaceholder])) instance = args[1 + argsPlaceholder];
|
|
58
|
+
}
|
|
59
|
+
if (args.length === 2 + argsPlaceholder && !isAxiosInstance(args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder) options = args[args.length - 1] || defaultOptions;
|
|
60
|
+
const { shallow, onSuccess = __vueuse_shared.noop, onError = __vueuse_shared.noop, immediate, resetOnExecute = false } = options;
|
|
61
|
+
const initialData = options.initialData;
|
|
62
|
+
const response = (0, vue.shallowRef)();
|
|
63
|
+
const data = (shallow ? vue.shallowRef : vue.ref)(initialData);
|
|
64
|
+
const isFinished = (0, vue.shallowRef)(false);
|
|
65
|
+
const isLoading = (0, vue.shallowRef)(false);
|
|
66
|
+
const isAborted = (0, vue.shallowRef)(false);
|
|
67
|
+
const error = (0, vue.shallowRef)();
|
|
68
|
+
let abortController = new AbortController();
|
|
69
|
+
const abort = (message) => {
|
|
70
|
+
if (isFinished.value || !isLoading.value) return;
|
|
71
|
+
abortController.abort(message);
|
|
72
|
+
abortController = new AbortController();
|
|
73
|
+
isAborted.value = true;
|
|
74
|
+
isLoading.value = false;
|
|
75
|
+
isFinished.value = false;
|
|
76
|
+
};
|
|
77
|
+
const loading = (loading$1) => {
|
|
78
|
+
isLoading.value = loading$1;
|
|
79
|
+
isFinished.value = !loading$1;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Reset data to initialData
|
|
83
|
+
*/
|
|
84
|
+
const resetData = () => {
|
|
85
|
+
if (resetOnExecute) data.value = initialData;
|
|
86
|
+
};
|
|
87
|
+
const waitUntilFinished = () => new Promise((resolve, reject) => {
|
|
88
|
+
(0, __vueuse_shared.until)(isFinished).toBe(true).then(() => error.value ? reject(error.value) : resolve(result));
|
|
89
|
+
});
|
|
90
|
+
const promise = {
|
|
91
|
+
then: (...args$1) => waitUntilFinished().then(...args$1),
|
|
92
|
+
catch: (...args$1) => waitUntilFinished().catch(...args$1)
|
|
93
|
+
};
|
|
94
|
+
let executeCounter = 0;
|
|
95
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
96
|
+
error.value = void 0;
|
|
97
|
+
const _url = typeof executeUrl === "string" ? executeUrl : url !== null && url !== void 0 ? url : config.url;
|
|
98
|
+
if (_url === void 0) {
|
|
99
|
+
error.value = new axios.AxiosError(axios.AxiosError.ERR_INVALID_URL);
|
|
100
|
+
isFinished.value = true;
|
|
101
|
+
return promise;
|
|
102
|
+
}
|
|
103
|
+
resetData();
|
|
104
|
+
if (options.abortPrevious !== false) abort();
|
|
105
|
+
loading(true);
|
|
106
|
+
executeCounter += 1;
|
|
107
|
+
const currentExecuteCounter = executeCounter;
|
|
108
|
+
isAborted.value = false;
|
|
109
|
+
instance(_url, {
|
|
110
|
+
...defaultConfig,
|
|
111
|
+
...typeof executeUrl === "object" ? executeUrl : config,
|
|
112
|
+
signal: abortController.signal
|
|
113
|
+
}).then((r) => {
|
|
114
|
+
if (isAborted.value) return;
|
|
115
|
+
response.value = r;
|
|
116
|
+
const result$1 = r.data;
|
|
117
|
+
data.value = result$1;
|
|
118
|
+
onSuccess(result$1);
|
|
119
|
+
}).catch((e) => {
|
|
120
|
+
error.value = e;
|
|
121
|
+
onError(e);
|
|
122
|
+
}).finally(() => {
|
|
123
|
+
var _options$onFinish;
|
|
124
|
+
(_options$onFinish = options.onFinish) === null || _options$onFinish === void 0 || _options$onFinish.call(options);
|
|
125
|
+
if (currentExecuteCounter === executeCounter) loading(false);
|
|
126
|
+
});
|
|
127
|
+
return promise;
|
|
128
|
+
};
|
|
129
|
+
if (immediate && url) execute();
|
|
130
|
+
const result = {
|
|
131
|
+
response,
|
|
132
|
+
data,
|
|
133
|
+
error,
|
|
134
|
+
isFinished,
|
|
135
|
+
isLoading,
|
|
136
|
+
cancel: abort,
|
|
137
|
+
isAborted,
|
|
138
|
+
isCanceled: isAborted,
|
|
139
|
+
abort,
|
|
140
|
+
execute
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
...result,
|
|
144
|
+
...promise
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
exports.useAxios = useAxios;
|
|
150
|
+
})(this.VueUse = this.VueUse || {}, VueUse, axios, Vue);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(exports,t,n,r){var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e));t=d(t),n=d(n),r=d(r);function f(...e){let i=typeof e[0]==`string`?e[0]:void 0,a=typeof i==`string`?1:0,o={immediate:!!a,shallow:!0,abortPrevious:!0},s={},c=n.default,l=o,u=e=>!!(e!=null&&e.request);e.length>0+a&&(u(e[0+a])?c=e[0+a]:s=e[0+a]),e.length>1+a&&u(e[1+a])&&(c=e[1+a]),(e.length===2+a&&!u(e[1+a])||e.length===3+a)&&(l=e[e.length-1]||o);let{shallow:d,onSuccess:f=t.noop,onError:p=t.noop,immediate:m,resetOnExecute:h=!1}=l,g=l.initialData,_=(0,r.shallowRef)(),v=(d?r.shallowRef:r.ref)(g),y=(0,r.shallowRef)(!1),b=(0,r.shallowRef)(!1),x=(0,r.shallowRef)(!1),S=(0,r.shallowRef)(),C=new AbortController,w=e=>{y.value||!b.value||(C.abort(e),C=new AbortController,x.value=!0,b.value=!1,y.value=!1)},T=e=>{b.value=e,y.value=!e},E=()=>{h&&(v.value=g)},D=()=>new Promise((e,n)=>{(0,t.until)(y).toBe(!0).then(()=>S.value?n(S.value):e(j))}),O={then:(...e)=>D().then(...e),catch:(...e)=>D().catch(...e)},k=0,A=(e=i,t={})=>{S.value=void 0;let r=typeof e==`string`?e:i==null?t.url:i;if(r===void 0)return S.value=new n.AxiosError(n.AxiosError.ERR_INVALID_URL),y.value=!0,O;E(),l.abortPrevious!==!1&&w(),T(!0),k+=1;let a=k;return x.value=!1,c(r,{...s,...typeof e==`object`?e:t,signal:C.signal}).then(e=>{if(x.value)return;_.value=e;let t=e.data;v.value=t,f(t)}).catch(e=>{S.value=e,p(e)}).finally(()=>{var e;(e=l.onFinish)==null||e.call(l),a===k&&T(!1)}),O};m&&i&&A();let j={response:_,data:v,error:S,isFinished:y,isLoading:b,cancel:w,isAborted:x,isCanceled:x,abort:w,execute:A};return{...j,...O}}exports.useAxios=f})(this.VueUse=this.VueUse||{},VueUse,axios,Vue);
|