@vueuse/integrations 13.9.0 → 14.0.0-alpha.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/package.json +3 -3
- package/useAsyncValidator/component.d.mts +14 -22
- package/useAsyncValidator/component.mjs +13 -78
- package/useFocusTrap/component.d.mts +15 -11
- package/useFocusTrap/component.mjs +12 -24
- package/useSortable/component.d.mts +14 -36
- package/useSortable/component.mjs +16 -80
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/integrations",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "14.0.0-alpha.0",
|
|
5
5
|
"description": "Integration wrappers for utility libraries",
|
|
6
6
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@vueuse/core": "
|
|
108
|
-
"@vueuse/shared": "
|
|
107
|
+
"@vueuse/core": "14.0.0-alpha.0",
|
|
108
|
+
"@vueuse/shared": "14.0.0-alpha.0"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@types/nprogress": "^0.2.3",
|
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { SlotsType, Reactive } from 'vue';
|
|
3
|
+
import { UseAsyncValidatorOptions, UseAsyncValidatorReturn } from '@vueuse/integrations/useAsyncValidator';
|
|
3
4
|
import { Rules } from 'async-validator';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
form:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
17
|
-
form: {
|
|
18
|
-
type: PropType<Record<string, any>>;
|
|
19
|
-
required: true;
|
|
20
|
-
};
|
|
21
|
-
rules: {
|
|
22
|
-
type: PropType<Rules>;
|
|
23
|
-
required: true;
|
|
24
|
-
};
|
|
25
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
6
|
+
interface UseAsyncValidatorProps {
|
|
7
|
+
form: Record<string, any>;
|
|
8
|
+
rules: Rules;
|
|
9
|
+
options?: UseAsyncValidatorOptions;
|
|
10
|
+
}
|
|
11
|
+
interface UseAsyncValidatorSlots {
|
|
12
|
+
default: (data: Reactive<UseAsyncValidatorReturn>) => any;
|
|
13
|
+
}
|
|
14
|
+
declare const UseAsyncValidator: vue.DefineSetupFnComponent<UseAsyncValidatorProps, Record<string, never>, SlotsType<UseAsyncValidatorSlots>, UseAsyncValidatorProps & {
|
|
15
|
+
[x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
|
|
16
|
+
}, vue.PublicProps>;
|
|
26
17
|
|
|
27
18
|
export { UseAsyncValidator };
|
|
19
|
+
export type { UseAsyncValidatorProps };
|
|
@@ -1,87 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import Schema from 'async-validator';
|
|
1
|
+
import { useAsyncValidator } from '@vueuse/integrations/useAsyncValidator';
|
|
2
|
+
import { defineComponent, reactive } from 'vue';
|
|
4
3
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
validateOption = {},
|
|
9
|
-
immediate = true,
|
|
10
|
-
manual = false
|
|
11
|
-
} = options;
|
|
12
|
-
const valueRef = toRef(value);
|
|
13
|
-
const errorInfo = shallowRef(null);
|
|
14
|
-
const isFinished = shallowRef(true);
|
|
15
|
-
const pass = shallowRef(!immediate || manual);
|
|
16
|
-
const errors = computed(() => errorInfo.value?.errors || []);
|
|
17
|
-
const errorFields = computed(() => errorInfo.value?.fields || {});
|
|
18
|
-
const validator = computed(() => new AsyncValidatorSchema(toValue(rules)));
|
|
19
|
-
const execute = async () => {
|
|
20
|
-
isFinished.value = false;
|
|
21
|
-
pass.value = false;
|
|
22
|
-
try {
|
|
23
|
-
await validator.value.validate(valueRef.value, validateOption);
|
|
24
|
-
pass.value = true;
|
|
25
|
-
errorInfo.value = null;
|
|
26
|
-
} catch (err) {
|
|
27
|
-
errorInfo.value = err;
|
|
28
|
-
} finally {
|
|
29
|
-
isFinished.value = true;
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
pass: pass.value,
|
|
33
|
-
errorInfo: errorInfo.value,
|
|
34
|
-
errors: errors.value,
|
|
35
|
-
errorFields: errorFields.value
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
if (!manual) {
|
|
39
|
-
watch(
|
|
40
|
-
[valueRef, validator],
|
|
41
|
-
() => execute(),
|
|
42
|
-
{ immediate, deep: true }
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
const shell = {
|
|
46
|
-
isFinished,
|
|
47
|
-
pass,
|
|
48
|
-
errors,
|
|
49
|
-
errorInfo,
|
|
50
|
-
errorFields,
|
|
51
|
-
execute
|
|
52
|
-
};
|
|
53
|
-
function waitUntilFinished() {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
until(isFinished).toBe(true).then(() => resolve(shell)).catch((error) => reject(error));
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
...shell,
|
|
60
|
-
then(onFulfilled, onRejected) {
|
|
61
|
-
return waitUntilFinished().then(onFulfilled, onRejected);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const UseAsyncValidator = /* @__PURE__ */ defineComponent({
|
|
67
|
-
name: "UseAsyncValidator",
|
|
68
|
-
props: {
|
|
69
|
-
form: {
|
|
70
|
-
type: Object,
|
|
71
|
-
required: true
|
|
72
|
-
},
|
|
73
|
-
rules: {
|
|
74
|
-
type: Object,
|
|
75
|
-
required: true
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
setup(props, { slots }) {
|
|
4
|
+
const UseAsyncValidator = /* @__PURE__ */ defineComponent(
|
|
5
|
+
(props, { slots }) => {
|
|
79
6
|
const data = reactive(useAsyncValidator(props.form, props.rules));
|
|
80
7
|
return () => {
|
|
81
8
|
if (slots.default)
|
|
82
9
|
return slots.default(data);
|
|
83
10
|
};
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "UseAsyncValidator",
|
|
14
|
+
props: [
|
|
15
|
+
"form",
|
|
16
|
+
"options",
|
|
17
|
+
"rules"
|
|
18
|
+
]
|
|
84
19
|
}
|
|
85
|
-
|
|
20
|
+
);
|
|
86
21
|
|
|
87
22
|
export { UseAsyncValidator };
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
+
import { SlotsType, Reactive } from 'vue';
|
|
2
3
|
import { RenderableComponent } from '@vueuse/core';
|
|
3
|
-
import {
|
|
4
|
+
import { UseFocusTrapOptions, UseFocusTrapReturn } from '@vueuse/integrations/useFocusTrap';
|
|
4
5
|
|
|
5
|
-
interface
|
|
6
|
-
/**
|
|
7
|
-
* Immediately activate the trap
|
|
8
|
-
*/
|
|
9
|
-
immediate?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface ComponentUseFocusTrapOptions extends RenderableComponent {
|
|
6
|
+
interface UseFocusTrapProps extends RenderableComponent {
|
|
13
7
|
options?: UseFocusTrapOptions;
|
|
14
8
|
}
|
|
15
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
interface ComponentUseFocusTrapOptions extends UseFocusTrapProps {
|
|
13
|
+
}
|
|
14
|
+
interface UseFocusTrapSlots {
|
|
15
|
+
default: (data: Reactive<UseFocusTrapReturn>) => any;
|
|
16
|
+
}
|
|
17
|
+
declare const UseFocusTrap: vue.DefineSetupFnComponent<UseFocusTrapProps, Record<string, never>, SlotsType<UseFocusTrapSlots>, UseFocusTrapProps & {
|
|
18
|
+
[x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
|
|
19
|
+
}, vue.PublicProps>;
|
|
16
20
|
|
|
17
21
|
export { UseFocusTrap };
|
|
18
|
-
export type { ComponentUseFocusTrapOptions };
|
|
22
|
+
export type { ComponentUseFocusTrapOptions, UseFocusTrapProps };
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { defineComponent, ref, watch, onScopeDispose, h } from 'vue';
|
|
1
|
+
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap';
|
|
2
|
+
import { defineComponent, shallowRef, reactive, h } from 'vue';
|
|
4
3
|
|
|
5
|
-
const UseFocusTrap = /* @__PURE__ */ defineComponent(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let trap;
|
|
10
|
-
const target = ref();
|
|
11
|
-
const activate = () => trap && trap.activate();
|
|
12
|
-
const deactivate = () => trap && trap.deactivate();
|
|
13
|
-
watch(
|
|
14
|
-
() => unrefElement(target),
|
|
15
|
-
(el) => {
|
|
16
|
-
if (!el)
|
|
17
|
-
return;
|
|
18
|
-
trap = createFocusTrap(el, props.options || {});
|
|
19
|
-
activate();
|
|
20
|
-
},
|
|
21
|
-
{ flush: "post" }
|
|
22
|
-
);
|
|
23
|
-
onScopeDispose(() => deactivate());
|
|
4
|
+
const UseFocusTrap = /* @__PURE__ */ defineComponent(
|
|
5
|
+
(props, { slots }) => {
|
|
6
|
+
const target = shallowRef();
|
|
7
|
+
const data = reactive(useFocusTrap(target, props.options));
|
|
24
8
|
return () => {
|
|
25
9
|
if (slots.default)
|
|
26
|
-
return h(props.as || "div", { ref: target }, slots.default());
|
|
10
|
+
return h(props.as || "div", { ref: target }, slots.default(data));
|
|
27
11
|
};
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "UseFocusTrap",
|
|
15
|
+
props: ["as", "options"]
|
|
28
16
|
}
|
|
29
|
-
|
|
17
|
+
);
|
|
30
18
|
|
|
31
19
|
export { UseFocusTrap };
|
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { SlotsType, Reactive } from 'vue';
|
|
3
|
+
import { RenderableComponent } from '@vueuse/core';
|
|
4
|
+
import { UseSortableOptions, UseSortableReturn } from '@vueuse/integrations/useSortable';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
options: {
|
|
18
|
-
type: PropType<UseSortableOptions>;
|
|
19
|
-
required: true;
|
|
20
|
-
};
|
|
21
|
-
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
}> | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
24
|
-
modelValue: {
|
|
25
|
-
type: PropType<any[]>;
|
|
26
|
-
required: true;
|
|
27
|
-
};
|
|
28
|
-
tag: {
|
|
29
|
-
type: StringConstructor;
|
|
30
|
-
default: string;
|
|
31
|
-
};
|
|
32
|
-
options: {
|
|
33
|
-
type: PropType<UseSortableOptions>;
|
|
34
|
-
required: true;
|
|
35
|
-
};
|
|
36
|
-
}>> & Readonly<{}>, {
|
|
37
|
-
tag: string;
|
|
38
|
-
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
6
|
+
interface UseSortableProps extends RenderableComponent {
|
|
7
|
+
modelValue: any[];
|
|
8
|
+
options?: UseSortableOptions;
|
|
9
|
+
}
|
|
10
|
+
interface UseSortableSlots {
|
|
11
|
+
default: (data: Reactive<UseSortableReturn>) => any;
|
|
12
|
+
}
|
|
13
|
+
declare const UseSortable: vue.DefineSetupFnComponent<UseSortableProps, Record<string, never>, SlotsType<UseSortableSlots>, UseSortableProps & {
|
|
14
|
+
[x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
|
|
15
|
+
}, vue.PublicProps>;
|
|
39
16
|
|
|
40
17
|
export { UseSortable };
|
|
18
|
+
export type { UseSortableProps };
|
|
@@ -1,89 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { useVModel } from '@vueuse/core';
|
|
2
|
+
import { useSortable } from '@vueuse/integrations/useSortable';
|
|
3
|
+
import { defineComponent, shallowRef, reactive, h } from 'vue';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { document = defaultDocument, ...resetOptions } = options;
|
|
8
|
-
const defaultOptions = {
|
|
9
|
-
onUpdate: (e) => {
|
|
10
|
-
moveArrayElement(list, e.oldIndex, e.newIndex, e);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const start = () => {
|
|
14
|
-
const target = typeof el === "string" ? document?.querySelector(el) : unrefElement(el);
|
|
15
|
-
if (!target || sortable !== void 0)
|
|
16
|
-
return;
|
|
17
|
-
sortable = new Sortable(target, { ...defaultOptions, ...resetOptions });
|
|
18
|
-
};
|
|
19
|
-
const stop = () => {
|
|
20
|
-
sortable?.destroy();
|
|
21
|
-
sortable = void 0;
|
|
22
|
-
};
|
|
23
|
-
const option = (name, value) => {
|
|
24
|
-
if (value !== void 0)
|
|
25
|
-
sortable?.option(name, value);
|
|
26
|
-
else
|
|
27
|
-
return sortable?.option(name);
|
|
28
|
-
};
|
|
29
|
-
tryOnMounted(start);
|
|
30
|
-
tryOnScopeDispose(stop);
|
|
31
|
-
return {
|
|
32
|
-
stop,
|
|
33
|
-
start,
|
|
34
|
-
option
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function insertNodeAt(parentElement, element, index) {
|
|
38
|
-
const refElement = parentElement.children[index];
|
|
39
|
-
parentElement.insertBefore(element, refElement);
|
|
40
|
-
}
|
|
41
|
-
function removeNode(node) {
|
|
42
|
-
if (node.parentNode)
|
|
43
|
-
node.parentNode.removeChild(node);
|
|
44
|
-
}
|
|
45
|
-
function moveArrayElement(list, from, to, e = null) {
|
|
46
|
-
if (e != null) {
|
|
47
|
-
removeNode(e.item);
|
|
48
|
-
insertNodeAt(e.from, e.item, from);
|
|
49
|
-
}
|
|
50
|
-
const _valueIsRef = isRef(list);
|
|
51
|
-
const array = _valueIsRef ? [...toValue(list)] : toValue(list);
|
|
52
|
-
if (to >= 0 && to < array.length) {
|
|
53
|
-
const element = array.splice(from, 1)[0];
|
|
54
|
-
nextTick(() => {
|
|
55
|
-
array.splice(to, 0, element);
|
|
56
|
-
if (_valueIsRef)
|
|
57
|
-
list.value = array;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const UseSortable = /* @__PURE__ */ defineComponent({
|
|
63
|
-
name: "UseSortable",
|
|
64
|
-
props: {
|
|
65
|
-
modelValue: {
|
|
66
|
-
type: Array,
|
|
67
|
-
required: true
|
|
68
|
-
},
|
|
69
|
-
tag: {
|
|
70
|
-
type: String,
|
|
71
|
-
default: "div"
|
|
72
|
-
},
|
|
73
|
-
options: {
|
|
74
|
-
type: Object,
|
|
75
|
-
required: true
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
setup(props, { slots }) {
|
|
5
|
+
const UseSortable = /* @__PURE__ */ defineComponent(
|
|
6
|
+
(props, { slots }) => {
|
|
79
7
|
const list = useVModel(props, "modelValue");
|
|
80
|
-
const target =
|
|
8
|
+
const target = shallowRef();
|
|
81
9
|
const data = reactive(useSortable(target, list, props.options));
|
|
82
10
|
return () => {
|
|
83
11
|
if (slots.default)
|
|
84
|
-
return h(props.
|
|
12
|
+
return h(props.as || "div", { ref: target }, slots.default(data));
|
|
85
13
|
};
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "UseSortable",
|
|
17
|
+
props: [
|
|
18
|
+
"as",
|
|
19
|
+
"modelValue",
|
|
20
|
+
"options"
|
|
21
|
+
]
|
|
86
22
|
}
|
|
87
|
-
|
|
23
|
+
);
|
|
88
24
|
|
|
89
25
|
export { UseSortable };
|