@v-c/slider 1.0.2 → 1.0.4
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/Handles/Handle.cjs +195 -1
- package/dist/Handles/Handle.d.ts +17 -5
- package/dist/Handles/Handle.js +191 -202
- package/dist/Handles/index.cjs +108 -1
- package/dist/Handles/index.d.ts +20 -4
- package/dist/Handles/index.js +105 -116
- package/dist/Marks/Mark.cjs +51 -1
- package/dist/Marks/Mark.d.ts +2 -2
- package/dist/Marks/Mark.js +48 -39
- package/dist/Marks/index.cjs +39 -1
- package/dist/Marks/index.d.ts +2 -2
- package/dist/Marks/index.js +36 -32
- package/dist/Slider.cjs +569 -1
- package/dist/Slider.d.ts +60 -263
- package/dist/Slider.js +563 -352
- package/dist/Steps/Dot.cjs +52 -1
- package/dist/Steps/Dot.d.ts +2 -2
- package/dist/Steps/Dot.js +49 -38
- package/dist/Steps/index.cjs +64 -1
- package/dist/Steps/index.d.ts +2 -2
- package/dist/Steps/index.js +61 -41
- package/dist/Tracks/Track.cjs +74 -1
- package/dist/Tracks/Track.js +70 -81
- package/dist/Tracks/index.cjs +70 -1
- package/dist/Tracks/index.js +66 -82
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/context.cjs +39 -1
- package/dist/context.d.ts +13 -7
- package/dist/context.js +29 -24
- package/dist/hooks/useDrag.cjs +160 -1
- package/dist/hooks/useDrag.d.ts +2 -2
- package/dist/hooks/useDrag.js +155 -86
- package/dist/hooks/useOffset.cjs +124 -1
- package/dist/hooks/useOffset.d.ts +2 -1
- package/dist/hooks/useOffset.js +122 -97
- package/dist/hooks/useRange.cjs +21 -1
- package/dist/hooks/useRange.js +18 -9
- package/dist/index.cjs +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/dist/interface.cjs +0 -1
- package/dist/interface.js +0 -1
- package/dist/util.cjs +32 -1
- package/dist/util.js +27 -26
- package/package.json +18 -10
- package/docs/TooltipSlider.tsx +0 -94
- package/docs/assets/anim.less +0 -63
- package/docs/assets/bootstrap.less +0 -163
- package/docs/assets/index.less +0 -337
- package/docs/debug.vue +0 -60
- package/docs/editable.vue +0 -59
- package/docs/handle.vue +0 -45
- package/docs/marks.vue +0 -94
- package/docs/multiple.vue +0 -54
- package/docs/range.vue +0 -211
- package/docs/slider.stories.vue +0 -45
- package/docs/sliderDemo.vue +0 -267
- package/docs/vertical.vue +0 -122
- package/src/Handles/Handle.tsx +0 -223
- package/src/Handles/index.tsx +0 -124
- package/src/Marks/Mark.tsx +0 -40
- package/src/Marks/index.tsx +0 -40
- package/src/Slider.tsx +0 -593
- package/src/Steps/Dot.tsx +0 -40
- package/src/Steps/index.tsx +0 -54
- package/src/Tracks/Track.tsx +0 -89
- package/src/Tracks/index.tsx +0 -92
- package/src/context.ts +0 -65
- package/src/hooks/useDrag.ts +0 -243
- package/src/hooks/useOffset.ts +0 -264
- package/src/hooks/useRange.ts +0 -24
- package/src/index.ts +0 -8
- package/src/interface.ts +0 -17
- package/src/util.ts +0 -41
- package/vite.config.ts +0 -18
- package/vitest.config.ts +0 -11
package/dist/Tracks/index.js
CHANGED
|
@@ -1,83 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, s) => u(i, {
|
|
67
|
-
index: s,
|
|
68
|
-
prefixCls: t.prefixCls,
|
|
69
|
-
style: {
|
|
70
|
-
...g(t.trackStyle, s),
|
|
71
|
-
...n?.track
|
|
72
|
-
},
|
|
73
|
-
start: e,
|
|
74
|
-
end: l,
|
|
75
|
-
key: s,
|
|
76
|
-
onStartMove: t.onStartMove
|
|
77
|
-
}, null))]);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
1
|
+
import { useInjectSlider } from "../context.js";
|
|
2
|
+
import { getIndex } from "../util.js";
|
|
3
|
+
import Track_default from "./Track.js";
|
|
4
|
+
import { Fragment, computed, createVNode, defineComponent } from "vue";
|
|
5
|
+
import { classNames } from "@v-c/util";
|
|
6
|
+
var Tracks_default = /* @__PURE__ */ defineComponent({
|
|
7
|
+
name: "Tracks",
|
|
8
|
+
props: {
|
|
9
|
+
prefixCls: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
trackStyle: { type: [Object, Array] },
|
|
14
|
+
values: {
|
|
15
|
+
type: Array,
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
onStartMove: { type: Function },
|
|
19
|
+
startPoint: { type: Number }
|
|
20
|
+
},
|
|
21
|
+
setup(props) {
|
|
22
|
+
const sliderContext = useInjectSlider();
|
|
23
|
+
const trackList = computed(() => {
|
|
24
|
+
const range = sliderContext.value.range;
|
|
25
|
+
const min = sliderContext.value.min;
|
|
26
|
+
if (!range) {
|
|
27
|
+
if (props.values.length === 0) return [];
|
|
28
|
+
const startValue = props.startPoint ?? min;
|
|
29
|
+
const endValue = props.values[0];
|
|
30
|
+
return [{
|
|
31
|
+
start: Math.min(startValue, endValue),
|
|
32
|
+
end: Math.max(startValue, endValue)
|
|
33
|
+
}];
|
|
34
|
+
}
|
|
35
|
+
const list = [];
|
|
36
|
+
for (let i = 0; i < props.values.length - 1; i += 1) list.push({
|
|
37
|
+
start: props.values[i],
|
|
38
|
+
end: props.values[i + 1]
|
|
39
|
+
});
|
|
40
|
+
return list;
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
if (!sliderContext.value.included) return null;
|
|
44
|
+
const { classNames: classNames$1, styles } = sliderContext.value;
|
|
45
|
+
return createVNode(Fragment, null, [trackList.value?.length && (classNames$1.tracks || styles.tracks) ? createVNode(Track_default, {
|
|
46
|
+
"index": 0,
|
|
47
|
+
"prefixCls": props.prefixCls,
|
|
48
|
+
"start": trackList.value[0].start,
|
|
49
|
+
"end": trackList.value[trackList.value.length - 1].end,
|
|
50
|
+
"replaceCls": classNames(classNames$1.tracks, `${props.prefixCls}-tracks`),
|
|
51
|
+
"style": styles.tracks
|
|
52
|
+
}, null) : null, trackList.value.map(({ start, end }, index) => createVNode(Track_default, {
|
|
53
|
+
"index": index,
|
|
54
|
+
"prefixCls": props.prefixCls,
|
|
55
|
+
"style": {
|
|
56
|
+
...getIndex(props.trackStyle, index),
|
|
57
|
+
...styles?.track
|
|
58
|
+
},
|
|
59
|
+
"start": start,
|
|
60
|
+
"end": end,
|
|
61
|
+
"key": index,
|
|
62
|
+
"onStartMove": props.onStartMove
|
|
63
|
+
}, null))]);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
80
66
|
});
|
|
81
|
-
export {
|
|
82
|
-
N as default
|
|
83
|
-
};
|
|
67
|
+
export { Tracks_default as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
+
key = keys[i];
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: ((k) => from[k]).bind(null, key),
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
value: mod,
|
|
19
|
+
enumerable: true
|
|
20
|
+
}) : target, mod));
|
|
21
|
+
exports.__toESM = __toESM;
|
package/dist/context.cjs
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
2
|
+
let vue = require("vue");
|
|
3
|
+
var SliderContextKey = Symbol("SliderContext");
|
|
4
|
+
const defaultSliderContextValue = {
|
|
5
|
+
min: 0,
|
|
6
|
+
max: 0,
|
|
7
|
+
direction: "ltr",
|
|
8
|
+
step: 1,
|
|
9
|
+
includedStart: 0,
|
|
10
|
+
includedEnd: 0,
|
|
11
|
+
tabIndex: 0,
|
|
12
|
+
keyboard: true,
|
|
13
|
+
styles: {},
|
|
14
|
+
classNames: {}
|
|
15
|
+
};
|
|
16
|
+
function useProviderSliderContext(ctx) {
|
|
17
|
+
(0, vue.provide)(SliderContextKey, ctx);
|
|
18
|
+
}
|
|
19
|
+
function useInjectSlider() {
|
|
20
|
+
return (0, vue.inject)(SliderContextKey, (0, vue.ref)({}));
|
|
21
|
+
}
|
|
22
|
+
const UnstableContextKey = Symbol("UnstableContext");
|
|
23
|
+
const defaultUnstableContextValue = {};
|
|
24
|
+
const UnstableProvider = (0, vue.defineComponent)((props, { slots }) => {
|
|
25
|
+
(0, vue.provide)(UnstableContextKey, props.value);
|
|
26
|
+
return () => {
|
|
27
|
+
return slots?.default?.();
|
|
28
|
+
};
|
|
29
|
+
}, { props: ["value"] });
|
|
30
|
+
function useUnstableContext() {
|
|
31
|
+
return (0, vue.inject)(UnstableContextKey, {});
|
|
32
|
+
}
|
|
33
|
+
exports.UnstableContextKey = UnstableContextKey;
|
|
34
|
+
exports.UnstableProvider = UnstableProvider;
|
|
35
|
+
exports.defaultSliderContextValue = defaultSliderContextValue;
|
|
36
|
+
exports.defaultUnstableContextValue = defaultUnstableContextValue;
|
|
37
|
+
exports.useInjectSlider = useInjectSlider;
|
|
38
|
+
exports.useProviderSliderContext = useProviderSliderContext;
|
|
39
|
+
exports.useUnstableContext = useUnstableContext;
|
package/dist/context.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { InjectionKey,
|
|
1
|
+
import { InjectionKey, Ref } from 'vue';
|
|
2
2
|
import { AriaValueFormat, Direction, SliderClassNames, SliderStyles } from './interface';
|
|
3
3
|
export interface SliderContextProps {
|
|
4
|
-
min:
|
|
5
|
-
max:
|
|
4
|
+
min: number;
|
|
5
|
+
max: number;
|
|
6
6
|
includedStart: number;
|
|
7
7
|
includedEnd: number;
|
|
8
|
-
direction:
|
|
8
|
+
direction: Direction;
|
|
9
9
|
disabled?: boolean;
|
|
10
10
|
keyboard?: boolean;
|
|
11
11
|
included?: boolean;
|
|
12
|
-
step:
|
|
12
|
+
step: number | null;
|
|
13
13
|
range?: boolean;
|
|
14
14
|
tabIndex: number | number[];
|
|
15
15
|
ariaLabelForHandle?: string | string[];
|
|
@@ -31,8 +31,8 @@ export declare const defaultSliderContextValue: {
|
|
|
31
31
|
styles: {};
|
|
32
32
|
classNames: {};
|
|
33
33
|
};
|
|
34
|
-
export declare function useProviderSliderContext(ctx: SliderContextProps): void;
|
|
35
|
-
export declare function useInjectSlider(): SliderContextProps
|
|
34
|
+
export declare function useProviderSliderContext(ctx: Ref<SliderContextProps>): void;
|
|
35
|
+
export declare function useInjectSlider(): Ref<SliderContextProps>;
|
|
36
36
|
export interface UnstableContextProps {
|
|
37
37
|
onDragStart?: (info: {
|
|
38
38
|
rawValues: number[];
|
|
@@ -49,3 +49,9 @@ export interface UnstableContextProps {
|
|
|
49
49
|
/** @private NOT PROMISE AVAILABLE. DO NOT USE IN PRODUCTION. */
|
|
50
50
|
export declare const UnstableContextKey: InjectionKey<UnstableContextProps>;
|
|
51
51
|
export declare const defaultUnstableContextValue: UnstableContextProps;
|
|
52
|
+
export declare const UnstableProvider: import('vue').DefineSetupFnComponent<{
|
|
53
|
+
value: any;
|
|
54
|
+
}, {}, {}, {
|
|
55
|
+
value: any;
|
|
56
|
+
} & {}, import('vue').PublicProps>;
|
|
57
|
+
export declare function useUnstableContext(): UnstableContextProps;
|
package/dist/context.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { defineComponent, inject, provide, ref } from "vue";
|
|
2
|
+
var SliderContextKey = Symbol("SliderContext");
|
|
3
|
+
const defaultSliderContextValue = {
|
|
4
|
+
min: 0,
|
|
5
|
+
max: 0,
|
|
6
|
+
direction: "ltr",
|
|
7
|
+
step: 1,
|
|
8
|
+
includedStart: 0,
|
|
9
|
+
includedEnd: 0,
|
|
10
|
+
tabIndex: 0,
|
|
11
|
+
keyboard: true,
|
|
12
|
+
styles: {},
|
|
13
|
+
classNames: {}
|
|
13
14
|
};
|
|
14
|
-
function
|
|
15
|
-
|
|
15
|
+
function useProviderSliderContext(ctx) {
|
|
16
|
+
provide(SliderContextKey, ctx);
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
18
|
+
function useInjectSlider() {
|
|
19
|
+
return inject(SliderContextKey, ref({}));
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
const UnstableContextKey = Symbol("UnstableContext");
|
|
22
|
+
const defaultUnstableContextValue = {};
|
|
23
|
+
const UnstableProvider = defineComponent((props, { slots }) => {
|
|
24
|
+
provide(UnstableContextKey, props.value);
|
|
25
|
+
return () => {
|
|
26
|
+
return slots?.default?.();
|
|
27
|
+
};
|
|
28
|
+
}, { props: ["value"] });
|
|
29
|
+
function useUnstableContext() {
|
|
30
|
+
return inject(UnstableContextKey, {});
|
|
31
|
+
}
|
|
32
|
+
export { UnstableContextKey, UnstableProvider, defaultSliderContextValue, defaultUnstableContextValue, useInjectSlider, useProviderSliderContext, useUnstableContext };
|
package/dist/hooks/useDrag.cjs
CHANGED
|
@@ -1 +1,160 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_context = require("../context.cjs");
|
|
4
|
+
let vue = require("vue");
|
|
5
|
+
let __v_c_util_dist_hooks_useEvent = require("@v-c/util/dist/hooks/useEvent");
|
|
6
|
+
__v_c_util_dist_hooks_useEvent = require_rolldown_runtime.__toESM(__v_c_util_dist_hooks_useEvent);
|
|
7
|
+
var REMOVE_DIST = 130;
|
|
8
|
+
function getPosition(e) {
|
|
9
|
+
const obj = "targetTouches" in e ? e.targetTouches[0] : e;
|
|
10
|
+
return {
|
|
11
|
+
pageX: obj.pageX,
|
|
12
|
+
pageY: obj.pageY
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function useDrag(containerRef, direction, rawValues, min, max, formatValue, triggerChange, finishChange, offsetValues, editable, minCount) {
|
|
16
|
+
const draggingValue = (0, vue.ref)(null);
|
|
17
|
+
const draggingIndex = (0, vue.ref)(-1);
|
|
18
|
+
const draggingDelete = (0, vue.ref)(false);
|
|
19
|
+
const cacheValues = (0, vue.ref)(rawValues.value);
|
|
20
|
+
const originValues = (0, vue.ref)(rawValues.value);
|
|
21
|
+
const mouseMoveEventRef = (0, vue.ref)(null);
|
|
22
|
+
const mouseUpEventRef = (0, vue.ref)(null);
|
|
23
|
+
const touchEventTargetRef = (0, vue.ref)(null);
|
|
24
|
+
const { onDragStart, onDragChange } = (0, vue.inject)(require_context.UnstableContextKey, require_context.defaultUnstableContextValue);
|
|
25
|
+
(0, vue.watch)(rawValues, (val) => {
|
|
26
|
+
if (draggingIndex.value === -1) {
|
|
27
|
+
cacheValues.value = [...val];
|
|
28
|
+
originValues.value = [...val];
|
|
29
|
+
}
|
|
30
|
+
}, { immediate: true });
|
|
31
|
+
(0, vue.onUnmounted)(() => {
|
|
32
|
+
document.removeEventListener("mousemove", mouseMoveEventRef.value);
|
|
33
|
+
document.removeEventListener("mouseup", mouseUpEventRef.value);
|
|
34
|
+
if (touchEventTargetRef.value) {
|
|
35
|
+
touchEventTargetRef.value.removeEventListener("touchmove", mouseMoveEventRef.value);
|
|
36
|
+
touchEventTargetRef.value.removeEventListener("touchend", mouseUpEventRef.value);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const flushValues = (nextValues, nextValue, deleteMark) => {
|
|
40
|
+
if (nextValue !== void 0) draggingValue.value = nextValue;
|
|
41
|
+
cacheValues.value = nextValues;
|
|
42
|
+
let changeValues = nextValues;
|
|
43
|
+
if (deleteMark) changeValues = nextValues.filter((_, i) => i !== draggingIndex.value);
|
|
44
|
+
triggerChange(changeValues);
|
|
45
|
+
if (onDragChange) onDragChange({
|
|
46
|
+
rawValues: nextValues,
|
|
47
|
+
deleteIndex: deleteMark ? draggingIndex.value : -1,
|
|
48
|
+
draggingIndex: draggingIndex.value,
|
|
49
|
+
draggingValue: nextValue
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const updateCacheValue = (0, __v_c_util_dist_hooks_useEvent.default)((valueIndex, offsetPercent, deleteMark) => {
|
|
53
|
+
if (valueIndex === -1) {
|
|
54
|
+
const startValue = originValues.value[0];
|
|
55
|
+
const endValue = originValues.value[originValues.value.length - 1];
|
|
56
|
+
const maxStartOffset = min.value - startValue;
|
|
57
|
+
const maxEndOffset = max.value - endValue;
|
|
58
|
+
let offset = offsetPercent * (max.value - min.value);
|
|
59
|
+
offset = Math.max(offset, maxStartOffset);
|
|
60
|
+
offset = Math.min(offset, maxEndOffset);
|
|
61
|
+
offset = formatValue.value(startValue + offset) - startValue;
|
|
62
|
+
flushValues(originValues.value.map((val) => val + offset));
|
|
63
|
+
} else {
|
|
64
|
+
const offsetDist = (max.value - min.value) * offsetPercent;
|
|
65
|
+
const cloneValues = [...cacheValues.value];
|
|
66
|
+
cloneValues[valueIndex] = originValues.value[valueIndex];
|
|
67
|
+
const next = offsetValues.value(cloneValues, offsetDist, valueIndex, "dist");
|
|
68
|
+
flushValues(next.values, next.value, deleteMark);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const onStartMove = (e, valueIndex, startValues) => {
|
|
72
|
+
e.stopPropagation();
|
|
73
|
+
const initialValues = startValues || rawValues.value;
|
|
74
|
+
const originValue = initialValues[valueIndex];
|
|
75
|
+
draggingIndex.value = valueIndex;
|
|
76
|
+
draggingValue.value = originValue;
|
|
77
|
+
originValues.value = initialValues;
|
|
78
|
+
cacheValues.value = initialValues;
|
|
79
|
+
draggingDelete.value = false;
|
|
80
|
+
const { pageX: startX, pageY: startY } = getPosition(e);
|
|
81
|
+
let deleteMark = false;
|
|
82
|
+
if (onDragStart) onDragStart({
|
|
83
|
+
rawValues: initialValues,
|
|
84
|
+
draggingIndex: valueIndex,
|
|
85
|
+
draggingValue: originValue
|
|
86
|
+
});
|
|
87
|
+
const onMouseMove = (event) => {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
const { pageX: moveX, pageY: moveY } = getPosition(event);
|
|
90
|
+
const offsetX = moveX - startX;
|
|
91
|
+
const offsetY = moveY - startY;
|
|
92
|
+
const { width, height } = containerRef.value.getBoundingClientRect();
|
|
93
|
+
let offSetPercent;
|
|
94
|
+
let removeDist;
|
|
95
|
+
switch (direction.value) {
|
|
96
|
+
case "btt":
|
|
97
|
+
offSetPercent = -offsetY / height;
|
|
98
|
+
removeDist = offsetX;
|
|
99
|
+
break;
|
|
100
|
+
case "ttb":
|
|
101
|
+
offSetPercent = offsetY / height;
|
|
102
|
+
removeDist = offsetX;
|
|
103
|
+
break;
|
|
104
|
+
case "rtl":
|
|
105
|
+
offSetPercent = -offsetX / width;
|
|
106
|
+
removeDist = offsetY;
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
offSetPercent = offsetX / width;
|
|
110
|
+
removeDist = offsetY;
|
|
111
|
+
}
|
|
112
|
+
deleteMark = editable.value ? Math.abs(removeDist) > REMOVE_DIST && minCount.value < cacheValues.value.length : false;
|
|
113
|
+
draggingDelete.value = deleteMark;
|
|
114
|
+
updateCacheValue(valueIndex, offSetPercent, deleteMark);
|
|
115
|
+
};
|
|
116
|
+
const onMouseUp = (event) => {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
document.removeEventListener("mouseup", onMouseUp);
|
|
119
|
+
document.removeEventListener("mousemove", onMouseMove);
|
|
120
|
+
if (touchEventTargetRef.value) {
|
|
121
|
+
touchEventTargetRef.value.removeEventListener("touchmove", mouseMoveEventRef.value);
|
|
122
|
+
touchEventTargetRef.value.removeEventListener("touchend", mouseUpEventRef.value);
|
|
123
|
+
}
|
|
124
|
+
mouseMoveEventRef.value = null;
|
|
125
|
+
mouseUpEventRef.value = null;
|
|
126
|
+
touchEventTargetRef.value = null;
|
|
127
|
+
finishChange(deleteMark);
|
|
128
|
+
draggingIndex.value = -1;
|
|
129
|
+
draggingDelete.value = false;
|
|
130
|
+
};
|
|
131
|
+
document.addEventListener("mouseup", onMouseUp);
|
|
132
|
+
document.addEventListener("mousemove", onMouseMove);
|
|
133
|
+
e.currentTarget.addEventListener("touchend", onMouseUp);
|
|
134
|
+
e.currentTarget.addEventListener("touchmove", onMouseMove);
|
|
135
|
+
mouseMoveEventRef.value = onMouseMove;
|
|
136
|
+
mouseUpEventRef.value = onMouseUp;
|
|
137
|
+
touchEventTargetRef.value = e.currentTarget;
|
|
138
|
+
};
|
|
139
|
+
return [
|
|
140
|
+
draggingIndex,
|
|
141
|
+
draggingValue,
|
|
142
|
+
draggingDelete,
|
|
143
|
+
(0, vue.computed)(() => {
|
|
144
|
+
const sourceValues = [...rawValues.value].sort((a, b) => a - b);
|
|
145
|
+
const targetValues = [...cacheValues.value].sort((a, b) => a - b);
|
|
146
|
+
const counts = {};
|
|
147
|
+
targetValues.forEach((val) => {
|
|
148
|
+
counts[val] = (counts[val] || 0) + 1;
|
|
149
|
+
});
|
|
150
|
+
sourceValues.forEach((val) => {
|
|
151
|
+
counts[val] = (counts[val] || 0) - 1;
|
|
152
|
+
});
|
|
153
|
+
const maxDiffCount = editable.value ? 1 : 0;
|
|
154
|
+
return Object.values(counts).reduce((prev, next) => prev + Math.abs(next), 0) <= maxDiffCount ? cacheValues.value : rawValues.value;
|
|
155
|
+
}),
|
|
156
|
+
onStartMove
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
var useDrag_default = useDrag;
|
|
160
|
+
exports.default = useDrag_default;
|
package/dist/hooks/useDrag.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Ref, ShallowRef } from 'vue';
|
|
1
|
+
import { ComputedRef, Ref, ShallowRef } from 'vue';
|
|
2
2
|
import { Direction, OnStartMove } from '../interface';
|
|
3
3
|
import { OffsetValues } from './useOffset';
|
|
4
|
-
declare function useDrag(containerRef: Ref<HTMLDivElement>, direction: ShallowRef<Direction>, rawValues: Ref<number[]>, min: ShallowRef<number>, max: ShallowRef<number>, formatValue: (value: number) => number
|
|
4
|
+
declare function useDrag(containerRef: Ref<HTMLDivElement>, direction: ShallowRef<Direction> | ComputedRef<Direction>, rawValues: Ref<number[]>, min: ShallowRef<number> | ComputedRef<number>, max: ShallowRef<number> | ComputedRef<number>, formatValue: Ref<(value: number) => number> | ComputedRef<(value: number) => number>, triggerChange: (values: number[]) => void, finishChange: (draggingDelete: boolean) => void, offsetValues: Ref<OffsetValues> | ComputedRef<OffsetValues>, editable: ShallowRef<boolean> | ComputedRef<boolean>, minCount: ShallowRef<number> | ComputedRef<number>): [
|
|
5
5
|
draggingIndex: Ref<number>,
|
|
6
6
|
draggingValue: Ref<number>,
|
|
7
7
|
draggingDelete: Ref<boolean>,
|