@v-c/slider 1.0.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/LICENSE +21 -0
- package/dist/Handles/Handle.cjs +1 -0
- package/dist/Handles/Handle.d.ts +107 -0
- package/dist/Handles/Handle.js +203 -0
- package/dist/Handles/index.cjs +1 -0
- package/dist/Handles/index.d.ts +98 -0
- package/dist/Handles/index.js +117 -0
- package/dist/Marks/Mark.cjs +1 -0
- package/dist/Marks/Mark.d.ts +9 -0
- package/dist/Marks/Mark.js +39 -0
- package/dist/Marks/index.cjs +1 -0
- package/dist/Marks/index.d.ts +15 -0
- package/dist/Marks/index.js +31 -0
- package/dist/Slider.cjs +1 -0
- package/dist/Slider.d.ts +253 -0
- package/dist/Slider.js +343 -0
- package/dist/Steps/Dot.cjs +1 -0
- package/dist/Steps/Dot.d.ts +9 -0
- package/dist/Steps/Dot.js +38 -0
- package/dist/Steps/index.cjs +1 -0
- package/dist/Steps/index.d.ts +11 -0
- package/dist/Steps/index.js +41 -0
- package/dist/Tracks/Track.cjs +1 -0
- package/dist/Tracks/Track.d.ts +61 -0
- package/dist/Tracks/Track.js +82 -0
- package/dist/Tracks/index.cjs +1 -0
- package/dist/Tracks/index.d.ts +47 -0
- package/dist/Tracks/index.js +83 -0
- package/dist/context.cjs +1 -0
- package/dist/context.d.ts +51 -0
- package/dist/context.js +27 -0
- package/dist/hooks/useDrag.cjs +1 -0
- package/dist/hooks/useDrag.d.ts +11 -0
- package/dist/hooks/useDrag.js +88 -0
- package/dist/hooks/useOffset.cjs +1 -0
- package/dist/hooks/useOffset.d.ts +10 -0
- package/dist/hooks/useOffset.js +98 -0
- package/dist/hooks/useRange.cjs +1 -0
- package/dist/hooks/useRange.d.ts +8 -0
- package/dist/hooks/useRange.js +10 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/interface.cjs +1 -0
- package/dist/interface.d.ts +7 -0
- package/dist/interface.js +1 -0
- package/dist/util.cjs +1 -0
- package/dist/util.d.ts +6 -0
- package/dist/util.js +29 -0
- package/docs/TooltipSlider.tsx +94 -0
- package/docs/assets/anim.less +63 -0
- package/docs/assets/bootstrap.less +163 -0
- package/docs/assets/index.less +337 -0
- package/docs/debug.vue +60 -0
- package/docs/editable.vue +59 -0
- package/docs/handle.vue +45 -0
- package/docs/marks.vue +85 -0
- package/docs/multiple.vue +54 -0
- package/docs/range.vue +211 -0
- package/docs/slider.stories.vue +45 -0
- package/docs/sliderDemo.vue +267 -0
- package/docs/vertical.vue +122 -0
- package/package.json +35 -0
- package/src/Handles/Handle.tsx +226 -0
- package/src/Handles/index.tsx +124 -0
- package/src/Marks/Mark.tsx +40 -0
- package/src/Marks/index.tsx +40 -0
- package/src/Slider.tsx +582 -0
- package/src/Steps/Dot.tsx +40 -0
- package/src/Steps/index.tsx +54 -0
- package/src/Tracks/Track.tsx +89 -0
- package/src/Tracks/index.tsx +92 -0
- package/src/context.ts +65 -0
- package/src/hooks/useDrag.ts +244 -0
- package/src/hooks/useOffset.ts +264 -0
- package/src/hooks/useRange.ts +24 -0
- package/src/index.ts +8 -0
- package/src/interface.ts +17 -0
- package/src/util.ts +41 -0
- package/vite.config.ts +18 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("vue"),h=require("classnames"),M=require("../context.cjs"),d=require("../util.cjs"),q=c.defineComponent({name:"Track",props:{prefixCls:{type:String,required:!0},replaceCls:{type:String},start:{type:Number,required:!0},end:{type:Number,required:!0},index:{type:Number,default:()=>null},onStartMove:{type:Function}},setup(a,{attrs:f}){const{direction:v,min:s,max:o,disabled:b,range:p,classNames:g}=M.useInjectSlider(),S=r=>{!b&&a.onStartMove&&a.onStartMove(r,-1)},e={};return()=>{const{prefixCls:r,index:l,onStartMove:u,replaceCls:$,start:m,end:y}=a,t=d.getOffset(m,s.value,o.value),n=d.getOffset(y,s.value,o.value),i=`${r}-track`,k=$||h(i,{[`${i}-${l+1}`]:l!==null&&p,[`${r}-track-draggable`]:u},g.track);switch(v.value){case"rtl":e.right=`${t*100}%`,e.width=`${n*100-t*100}%`;break;case"btt":e.bottom=`${t*100}%`,e.height=`${n*100-t*100}%`;break;case"ttb":e.top=`${t*100}%`,e.height=`${n*100-t*100}%`;break;default:e.left=`${t*100}%`,e.width=`${n*100-t*100}%`}return c.createVNode("div",{class:k,style:{...e,...f.style},onMousedown:u?S:void 0},null)}}});exports.default=q;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PropType } from 'vue';
|
|
2
|
+
import { OnStartMove } from '../interface';
|
|
3
|
+
export interface TrackProps {
|
|
4
|
+
prefixCls: string;
|
|
5
|
+
/** Replace with origin prefix concat className */
|
|
6
|
+
replaceCls?: string;
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
index: number;
|
|
10
|
+
onStartMove?: OnStartMove;
|
|
11
|
+
}
|
|
12
|
+
declare const Track: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
13
|
+
prefixCls: {
|
|
14
|
+
type: StringConstructor;
|
|
15
|
+
required: true;
|
|
16
|
+
};
|
|
17
|
+
replaceCls: {
|
|
18
|
+
type: StringConstructor;
|
|
19
|
+
};
|
|
20
|
+
start: {
|
|
21
|
+
type: NumberConstructor;
|
|
22
|
+
required: true;
|
|
23
|
+
};
|
|
24
|
+
end: {
|
|
25
|
+
type: NumberConstructor;
|
|
26
|
+
required: true;
|
|
27
|
+
};
|
|
28
|
+
index: {
|
|
29
|
+
type: NumberConstructor;
|
|
30
|
+
default: () => null;
|
|
31
|
+
};
|
|
32
|
+
onStartMove: {
|
|
33
|
+
type: PropType<OnStartMove>;
|
|
34
|
+
};
|
|
35
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
36
|
+
prefixCls: {
|
|
37
|
+
type: StringConstructor;
|
|
38
|
+
required: true;
|
|
39
|
+
};
|
|
40
|
+
replaceCls: {
|
|
41
|
+
type: StringConstructor;
|
|
42
|
+
};
|
|
43
|
+
start: {
|
|
44
|
+
type: NumberConstructor;
|
|
45
|
+
required: true;
|
|
46
|
+
};
|
|
47
|
+
end: {
|
|
48
|
+
type: NumberConstructor;
|
|
49
|
+
required: true;
|
|
50
|
+
};
|
|
51
|
+
index: {
|
|
52
|
+
type: NumberConstructor;
|
|
53
|
+
default: () => null;
|
|
54
|
+
};
|
|
55
|
+
onStartMove: {
|
|
56
|
+
type: PropType<OnStartMove>;
|
|
57
|
+
};
|
|
58
|
+
}>> & Readonly<{}>, {
|
|
59
|
+
index: number;
|
|
60
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
61
|
+
export default Track;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { defineComponent as y, createVNode as h } from "vue";
|
|
2
|
+
import x from "classnames";
|
|
3
|
+
import { useInjectSlider as C } from "../context.js";
|
|
4
|
+
import { getOffset as u } from "../util.js";
|
|
5
|
+
const I = /* @__PURE__ */ y({
|
|
6
|
+
name: "Track",
|
|
7
|
+
props: {
|
|
8
|
+
prefixCls: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: !0
|
|
11
|
+
},
|
|
12
|
+
replaceCls: {
|
|
13
|
+
type: String
|
|
14
|
+
},
|
|
15
|
+
start: {
|
|
16
|
+
type: Number,
|
|
17
|
+
required: !0
|
|
18
|
+
},
|
|
19
|
+
end: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: !0
|
|
22
|
+
},
|
|
23
|
+
index: {
|
|
24
|
+
type: Number,
|
|
25
|
+
default: () => null
|
|
26
|
+
},
|
|
27
|
+
onStartMove: {
|
|
28
|
+
type: Function
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
setup(n, {
|
|
32
|
+
attrs: d
|
|
33
|
+
}) {
|
|
34
|
+
const {
|
|
35
|
+
direction: f,
|
|
36
|
+
min: o,
|
|
37
|
+
max: s,
|
|
38
|
+
disabled: m,
|
|
39
|
+
range: p,
|
|
40
|
+
classNames: $
|
|
41
|
+
} = C(), b = (r) => {
|
|
42
|
+
!m && n.onStartMove && n.onStartMove(r, -1);
|
|
43
|
+
}, e = {};
|
|
44
|
+
return () => {
|
|
45
|
+
const {
|
|
46
|
+
prefixCls: r,
|
|
47
|
+
index: l,
|
|
48
|
+
onStartMove: i,
|
|
49
|
+
replaceCls: v,
|
|
50
|
+
start: S,
|
|
51
|
+
end: g
|
|
52
|
+
} = n, t = u(S, o.value, s.value), a = u(g, o.value, s.value), c = `${r}-track`, k = v || x(c, {
|
|
53
|
+
[`${c}-${l + 1}`]: l !== null && p,
|
|
54
|
+
[`${r}-track-draggable`]: i
|
|
55
|
+
}, $.track);
|
|
56
|
+
switch (f.value) {
|
|
57
|
+
case "rtl":
|
|
58
|
+
e.right = `${t * 100}%`, e.width = `${a * 100 - t * 100}%`;
|
|
59
|
+
break;
|
|
60
|
+
case "btt":
|
|
61
|
+
e.bottom = `${t * 100}%`, e.height = `${a * 100 - t * 100}%`;
|
|
62
|
+
break;
|
|
63
|
+
case "ttb":
|
|
64
|
+
e.top = `${t * 100}%`, e.height = `${a * 100 - t * 100}%`;
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
e.left = `${t * 100}%`, e.width = `${a * 100 - t * 100}%`;
|
|
68
|
+
}
|
|
69
|
+
return h("div", {
|
|
70
|
+
class: k,
|
|
71
|
+
style: {
|
|
72
|
+
...e,
|
|
73
|
+
...d.style
|
|
74
|
+
},
|
|
75
|
+
onMousedown: i ? b : void 0
|
|
76
|
+
}, null);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export {
|
|
81
|
+
I as default
|
|
82
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("vue"),f=require("classnames"),k=require("../context.cjs"),y=require("../util.cjs"),i=require("./Track.cjs"),m=r.defineComponent({name:"Tracks",props:{prefixCls:{type:String,required:!0},trackStyle:{type:[Object,Array]},values:{type:Array,required:!0},onStartMove:{type:Function},startPoint:{type:Number}},setup(e){const{included:o,range:d,min:v,styles:u,classNames:c}=k.useInjectSlider(),a=r.computed(()=>{if(!d){if(e.values.length===0)return[];const t=e.startPoint??v.value,n=e.values[0];return[{start:Math.min(t,n),end:Math.max(t,n)}]}const l=[];for(let t=0;t<e.values.length-1;t+=1)l.push({start:e.values[t],end:e.values[t+1]});return l});return()=>{if(!o)return null;const l=a.value?.length&&(c.tracks||u.tracks)?r.createVNode(i.default,{index:0,prefixCls:e.prefixCls,start:a.value[0].start,end:a.value[a.value.length-1].end,replaceCls:f(c.tracks,`${e.prefixCls}-tracks`),style:u.tracks},null):null;return r.createVNode(r.Fragment,null,[l,a.value.map(({start:t,end:n},s)=>r.createVNode(i.default,{index:s,prefixCls:e.prefixCls,style:{...y.getIndex(e.trackStyle,s),...u?.track},start:t,end:n,key:s,onStartMove:e.onStartMove},null))])}}});exports.default=m;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CSSProperties, PropType } from 'vue';
|
|
2
|
+
import { OnStartMove } from '../interface';
|
|
3
|
+
export interface TrackProps {
|
|
4
|
+
prefixCls: string;
|
|
5
|
+
style?: CSSProperties | CSSProperties[];
|
|
6
|
+
values: number[];
|
|
7
|
+
onStartMove?: OnStartMove;
|
|
8
|
+
startPoint?: number;
|
|
9
|
+
}
|
|
10
|
+
declare const Tracks: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
11
|
+
prefixCls: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
trackStyle: {
|
|
16
|
+
type: PropType<CSSProperties | CSSProperties[]>;
|
|
17
|
+
};
|
|
18
|
+
values: {
|
|
19
|
+
type: PropType<number[]>;
|
|
20
|
+
required: true;
|
|
21
|
+
};
|
|
22
|
+
onStartMove: {
|
|
23
|
+
type: PropType<OnStartMove>;
|
|
24
|
+
};
|
|
25
|
+
startPoint: {
|
|
26
|
+
type: NumberConstructor;
|
|
27
|
+
};
|
|
28
|
+
}>, () => import("vue/jsx-runtime").JSX.Element | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
29
|
+
prefixCls: {
|
|
30
|
+
type: StringConstructor;
|
|
31
|
+
required: true;
|
|
32
|
+
};
|
|
33
|
+
trackStyle: {
|
|
34
|
+
type: PropType<CSSProperties | CSSProperties[]>;
|
|
35
|
+
};
|
|
36
|
+
values: {
|
|
37
|
+
type: PropType<number[]>;
|
|
38
|
+
required: true;
|
|
39
|
+
};
|
|
40
|
+
onStartMove: {
|
|
41
|
+
type: PropType<OnStartMove>;
|
|
42
|
+
};
|
|
43
|
+
startPoint: {
|
|
44
|
+
type: NumberConstructor;
|
|
45
|
+
};
|
|
46
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
47
|
+
export default Tracks;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defineComponent as f, computed as v, createVNode as u, Fragment as k } from "vue";
|
|
2
|
+
import y from "classnames";
|
|
3
|
+
import { useInjectSlider as x } from "../context.js";
|
|
4
|
+
import { getIndex as g } from "../util.js";
|
|
5
|
+
import i from "./Track.js";
|
|
6
|
+
const N = /* @__PURE__ */ f({
|
|
7
|
+
name: "Tracks",
|
|
8
|
+
props: {
|
|
9
|
+
prefixCls: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: !0
|
|
12
|
+
},
|
|
13
|
+
trackStyle: {
|
|
14
|
+
type: [Object, Array]
|
|
15
|
+
},
|
|
16
|
+
values: {
|
|
17
|
+
type: Array,
|
|
18
|
+
required: !0
|
|
19
|
+
},
|
|
20
|
+
onStartMove: {
|
|
21
|
+
type: Function
|
|
22
|
+
},
|
|
23
|
+
startPoint: {
|
|
24
|
+
type: Number
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
setup(t) {
|
|
28
|
+
const {
|
|
29
|
+
included: o,
|
|
30
|
+
range: m,
|
|
31
|
+
min: d,
|
|
32
|
+
styles: n,
|
|
33
|
+
classNames: c
|
|
34
|
+
} = x(), r = v(() => {
|
|
35
|
+
if (!m) {
|
|
36
|
+
if (t.values.length === 0)
|
|
37
|
+
return [];
|
|
38
|
+
const e = t.startPoint ?? d.value, l = t.values[0];
|
|
39
|
+
return [{
|
|
40
|
+
start: Math.min(e, l),
|
|
41
|
+
end: Math.max(e, l)
|
|
42
|
+
}];
|
|
43
|
+
}
|
|
44
|
+
const a = [];
|
|
45
|
+
for (let e = 0; e < t.values.length - 1; e += 1)
|
|
46
|
+
a.push({
|
|
47
|
+
start: t.values[e],
|
|
48
|
+
end: t.values[e + 1]
|
|
49
|
+
});
|
|
50
|
+
return a;
|
|
51
|
+
});
|
|
52
|
+
return () => {
|
|
53
|
+
if (!o)
|
|
54
|
+
return null;
|
|
55
|
+
const a = r.value?.length && (c.tracks || n.tracks) ? u(i, {
|
|
56
|
+
index: 0,
|
|
57
|
+
prefixCls: t.prefixCls,
|
|
58
|
+
start: r.value[0].start,
|
|
59
|
+
end: r.value[r.value.length - 1].end,
|
|
60
|
+
replaceCls: y(c.tracks, `${t.prefixCls}-tracks`),
|
|
61
|
+
style: n.tracks
|
|
62
|
+
}, null) : null;
|
|
63
|
+
return u(k, null, [a, r.value.map(({
|
|
64
|
+
start: e,
|
|
65
|
+
end: l
|
|
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
|
+
}
|
|
80
|
+
});
|
|
81
|
+
export {
|
|
82
|
+
N as default
|
|
83
|
+
};
|
package/dist/context.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=Symbol("SliderContext"),l={min:0,max:0,direction:"ltr",step:1,includedStart:0,includedEnd:0,tabIndex:0,keyboard:!0,styles:{},classNames:{}};function o(n){e.provide(t,n)}function r(){return e.inject(t)}const d=Symbol("UnstableContext"),i={};exports.UnstableContextKey=d;exports.defaultSliderContextValue=l;exports.defaultUnstableContextValue=i;exports.useInjectSlider=r;exports.useProviderSliderContext=o;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { InjectionKey, ShallowRef } from 'vue';
|
|
2
|
+
import { AriaValueFormat, Direction, SliderClassNames, SliderStyles } from './interface';
|
|
3
|
+
export interface SliderContextProps {
|
|
4
|
+
min: ShallowRef<number>;
|
|
5
|
+
max: ShallowRef<number>;
|
|
6
|
+
includedStart: number;
|
|
7
|
+
includedEnd: number;
|
|
8
|
+
direction: ShallowRef<Direction>;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
keyboard?: boolean;
|
|
11
|
+
included?: boolean;
|
|
12
|
+
step: ShallowRef<number | null>;
|
|
13
|
+
range?: boolean;
|
|
14
|
+
tabIndex: number | number[];
|
|
15
|
+
ariaLabelForHandle?: string | string[];
|
|
16
|
+
ariaLabelledByForHandle?: string | string[];
|
|
17
|
+
ariaRequired?: boolean;
|
|
18
|
+
ariaValueTextFormatterForHandle?: AriaValueFormat | AriaValueFormat[];
|
|
19
|
+
classNames: SliderClassNames;
|
|
20
|
+
styles: SliderStyles;
|
|
21
|
+
}
|
|
22
|
+
export declare const defaultSliderContextValue: {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
direction: string;
|
|
26
|
+
step: number;
|
|
27
|
+
includedStart: number;
|
|
28
|
+
includedEnd: number;
|
|
29
|
+
tabIndex: number;
|
|
30
|
+
keyboard: boolean;
|
|
31
|
+
styles: {};
|
|
32
|
+
classNames: {};
|
|
33
|
+
};
|
|
34
|
+
export declare function useProviderSliderContext(ctx: SliderContextProps): void;
|
|
35
|
+
export declare function useInjectSlider(): SliderContextProps;
|
|
36
|
+
export interface UnstableContextProps {
|
|
37
|
+
onDragStart?: (info: {
|
|
38
|
+
rawValues: number[];
|
|
39
|
+
draggingIndex: number;
|
|
40
|
+
draggingValue: number;
|
|
41
|
+
}) => void;
|
|
42
|
+
onDragChange?: (info: {
|
|
43
|
+
rawValues: number[];
|
|
44
|
+
deleteIndex: number;
|
|
45
|
+
draggingIndex: number;
|
|
46
|
+
draggingValue: number;
|
|
47
|
+
}) => void;
|
|
48
|
+
}
|
|
49
|
+
/** @private NOT PROMISE AVAILABLE. DO NOT USE IN PRODUCTION. */
|
|
50
|
+
export declare const UnstableContextKey: InjectionKey<UnstableContextProps>;
|
|
51
|
+
export declare const defaultUnstableContextValue: UnstableContextProps;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { provide as n, inject as o } from "vue";
|
|
2
|
+
const e = Symbol("SliderContext"), r = {
|
|
3
|
+
min: 0,
|
|
4
|
+
max: 0,
|
|
5
|
+
direction: "ltr",
|
|
6
|
+
step: 1,
|
|
7
|
+
includedStart: 0,
|
|
8
|
+
includedEnd: 0,
|
|
9
|
+
tabIndex: 0,
|
|
10
|
+
keyboard: !0,
|
|
11
|
+
styles: {},
|
|
12
|
+
classNames: {}
|
|
13
|
+
};
|
|
14
|
+
function d(t) {
|
|
15
|
+
n(e, t);
|
|
16
|
+
}
|
|
17
|
+
function i() {
|
|
18
|
+
return o(e);
|
|
19
|
+
}
|
|
20
|
+
const s = Symbol("UnstableContext"), a = {};
|
|
21
|
+
export {
|
|
22
|
+
s as UnstableContextKey,
|
|
23
|
+
r as defaultSliderContextValue,
|
|
24
|
+
a as defaultUnstableContextValue,
|
|
25
|
+
i as useInjectSlider,
|
|
26
|
+
d as useProviderSliderContext
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const W=require("@v-c/util/dist/hooks/useEvent"),l=require("vue"),q=require("../context.cjs"),Z=130;function P(h){const L="targetTouches"in h?h.targetTouches[0]:h;return{pageX:L.pageX,pageY:L.pageY}}function $(h,L,f,T,X,y,B,K,z,O,A){const Y=l.ref(null),c=l.ref(-1),C=l.ref(!1),i=l.ref(f.value),g=l.ref(f.value),p=l.ref(null),E=l.ref(null),v=l.ref(null),F=l.inject(q.UnstableContextKey,q.defaultUnstableContextValue),{onDragStart:R,onDragChange:U}=F;c.value===-1&&(i.value=f.value),l.onUnmounted(()=>{document.removeEventListener("mousemove",p.value),document.removeEventListener("mouseup",E.value),v.value&&(v.value.removeEventListener("touchmove",p.value),v.value.removeEventListener("touchend",E.value))});const j=(t,n,o)=>{n!==void 0&&(Y.value=n),i.value=t;let a=t;o&&(a=t.filter((s,e)=>e!==c.value)),B(a),U&&U({rawValues:t,deleteIndex:o?c.value:-1,draggingIndex:c.value,draggingValue:n})},G=W((t,n,o)=>{if(t===-1){const a=g.value[0],s=g.value[g.value.length-1],e=T.value-a,r=X.value-s;let u=n*(X.value-T.value);u=Math.max(u,e),u=Math.min(u,r),u=y(a+u)-a;const d=g.value.map(m=>m+u);j(d)}else{const a=(X.value-T.value)*n,s=[...i.value];s[t]=g.value[t];const e=z(s,a,t,"dist");j(e.values,e.value,o)}}),H=(t,n,o)=>{t.stopPropagation(),console.log("onStartMove",n);const a=o||f.value,s=a[n];c.value=n,Y.value=s,g.value=a,i.value=a,C.value=!1;const{pageX:e,pageY:r}=P(t);let u=!1;R&&R({rawValues:a,draggingIndex:n,draggingValue:s});const b=m=>{m.preventDefault();const{pageX:N,pageY:Q}=P(m),D=N-e,S=Q-r,{width:_,height:k}=h.value.getBoundingClientRect();let M,V;switch(L.value){case"btt":M=-S/k,V=D;break;case"ttb":M=S/k,V=D;break;case"rtl":M=-D/_,V=S;break;default:M=D/_,V=S}u=O?Math.abs(V)>Z&&A<i.value.length:!1,C.value=u,G(n,M,u)},d=m=>{m.preventDefault(),document.removeEventListener("mouseup",d),document.removeEventListener("mousemove",b),v.value&&(v.value.removeEventListener("touchmove",p.value),v.value.removeEventListener("touchend",E.value)),p.value=null,E.value=null,v.value=null,K(u),c.value=-1,C.value=!1};document.addEventListener("mouseup",d),document.addEventListener("mousemove",b),t.currentTarget.addEventListener("touchend",d),t.currentTarget.addEventListener("touchmove",b),p.value=b,E.value=d,v.value=t.currentTarget},J=l.computed(()=>{const t=[...f.value].sort((e,r)=>e-r),n=[...i.value].sort((e,r)=>e-r),o={};n.forEach(e=>{o[e]=(o[e]||0)+1}),t.forEach(e=>{o[e]=(o[e]||0)-1});const a=O?1:0;return Object.values(o).reduce((e,r)=>e+Math.abs(r),0)<=a?i.value:f.value});return[c,Y,C,J,H]}exports.default=$;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ref, ShallowRef } from 'vue';
|
|
2
|
+
import { Direction, OnStartMove } from '../interface';
|
|
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, triggerChange: (values: number[]) => void, finishChange: (draggingDelete: boolean) => void, offsetValues: OffsetValues, editable: boolean, minCount: number): [
|
|
5
|
+
draggingIndex: Ref<number>,
|
|
6
|
+
draggingValue: Ref<number>,
|
|
7
|
+
draggingDelete: Ref<boolean>,
|
|
8
|
+
returnValues: Ref<number[]>,
|
|
9
|
+
onStartMove: OnStartMove
|
|
10
|
+
];
|
|
11
|
+
export default useDrag;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Q from "@v-c/util/dist/hooks/useEvent";
|
|
2
|
+
import { ref as r, inject as W, onUnmounted as Z, computed as $ } from "vue";
|
|
3
|
+
import { UnstableContextKey as w, defaultUnstableContextValue as x } from "../context.js";
|
|
4
|
+
const I = 130;
|
|
5
|
+
function _(h) {
|
|
6
|
+
const M = "targetTouches" in h ? h.targetTouches[0] : h;
|
|
7
|
+
return { pageX: M.pageX, pageY: M.pageY };
|
|
8
|
+
}
|
|
9
|
+
function oe(h, M, f, T, X, y, B, K, q, R, z) {
|
|
10
|
+
const Y = r(null), c = r(-1), C = r(!1), i = r(f.value), g = r(f.value), p = r(null), E = r(null), v = r(null), A = W(w, x), { onDragStart: U, onDragChange: O } = A;
|
|
11
|
+
c.value === -1 && (i.value = f.value), Z(() => {
|
|
12
|
+
document.removeEventListener("mousemove", p.value), document.removeEventListener("mouseup", E.value), v.value && (v.value.removeEventListener("touchmove", p.value), v.value.removeEventListener("touchend", E.value));
|
|
13
|
+
});
|
|
14
|
+
const j = (t, o, n) => {
|
|
15
|
+
o !== void 0 && (Y.value = o), i.value = t;
|
|
16
|
+
let a = t;
|
|
17
|
+
n && (a = t.filter((l, e) => e !== c.value)), B(a), O && O({
|
|
18
|
+
rawValues: t,
|
|
19
|
+
deleteIndex: n ? c.value : -1,
|
|
20
|
+
draggingIndex: c.value,
|
|
21
|
+
draggingValue: o
|
|
22
|
+
});
|
|
23
|
+
}, F = Q(
|
|
24
|
+
(t, o, n) => {
|
|
25
|
+
if (t === -1) {
|
|
26
|
+
const a = g.value[0], l = g.value[g.value.length - 1], e = T.value - a, s = X.value - l;
|
|
27
|
+
let u = o * (X.value - T.value);
|
|
28
|
+
u = Math.max(u, e), u = Math.min(u, s), u = y(a + u) - a;
|
|
29
|
+
const m = g.value.map((d) => d + u);
|
|
30
|
+
j(m);
|
|
31
|
+
} else {
|
|
32
|
+
const a = (X.value - T.value) * o, l = [...i.value];
|
|
33
|
+
l[t] = g.value[t];
|
|
34
|
+
const e = q(l, a, t, "dist");
|
|
35
|
+
j(e.values, e.value, n);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
), G = (t, o, n) => {
|
|
39
|
+
t.stopPropagation(), console.log("onStartMove", o);
|
|
40
|
+
const a = n || f.value, l = a[o];
|
|
41
|
+
c.value = o, Y.value = l, g.value = a, i.value = a, C.value = !1;
|
|
42
|
+
const { pageX: e, pageY: s } = _(t);
|
|
43
|
+
let u = !1;
|
|
44
|
+
U && U({
|
|
45
|
+
rawValues: a,
|
|
46
|
+
draggingIndex: o,
|
|
47
|
+
draggingValue: l
|
|
48
|
+
});
|
|
49
|
+
const V = (d) => {
|
|
50
|
+
d.preventDefault();
|
|
51
|
+
const { pageX: J, pageY: N } = _(d), D = J - e, S = N - s, { width: k, height: P } = h.value.getBoundingClientRect();
|
|
52
|
+
let L, b;
|
|
53
|
+
switch (M.value) {
|
|
54
|
+
case "btt":
|
|
55
|
+
L = -S / P, b = D;
|
|
56
|
+
break;
|
|
57
|
+
case "ttb":
|
|
58
|
+
L = S / P, b = D;
|
|
59
|
+
break;
|
|
60
|
+
case "rtl":
|
|
61
|
+
L = -D / k, b = S;
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
L = D / k, b = S;
|
|
65
|
+
}
|
|
66
|
+
u = R ? Math.abs(b) > I && z < i.value.length : !1, C.value = u, F(o, L, u);
|
|
67
|
+
}, m = (d) => {
|
|
68
|
+
d.preventDefault(), document.removeEventListener("mouseup", m), document.removeEventListener("mousemove", V), v.value && (v.value.removeEventListener("touchmove", p.value), v.value.removeEventListener("touchend", E.value)), p.value = null, E.value = null, v.value = null, K(u), c.value = -1, C.value = !1;
|
|
69
|
+
};
|
|
70
|
+
document.addEventListener("mouseup", m), document.addEventListener("mousemove", V), t.currentTarget.addEventListener("touchend", m), t.currentTarget.addEventListener("touchmove", V), p.value = V, E.value = m, v.value = t.currentTarget;
|
|
71
|
+
}, H = $(() => {
|
|
72
|
+
const t = [...f.value].sort((e, s) => e - s), o = [...i.value].sort((e, s) => e - s), n = {};
|
|
73
|
+
o.forEach((e) => {
|
|
74
|
+
n[e] = (n[e] || 0) + 1;
|
|
75
|
+
}), t.forEach((e) => {
|
|
76
|
+
n[e] = (n[e] || 0) - 1;
|
|
77
|
+
});
|
|
78
|
+
const a = R ? 1 : 0;
|
|
79
|
+
return Object.values(n).reduce(
|
|
80
|
+
(e, s) => e + Math.abs(s),
|
|
81
|
+
0
|
|
82
|
+
) <= a ? i.value : f.value;
|
|
83
|
+
});
|
|
84
|
+
return [c, Y, C, H, G];
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
oe as default
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("vue");function P(c,a,f,D,O,g){const w=m.computed(()=>n=>Math.max(c,Math.min(a,n))).value,V=m.computed(()=>n=>{if(f!==null){const l=c+Math.round((w(n)-c)/f)*f,u=r=>(String(r).split(".")[1]||"").length,o=Math.max(u(f),u(a),u(c)),t=Number(l.toFixed(o));return c<=t&&t<=a?t:null}return null}).value,y=m.computed(()=>n=>{const l=w(n),u=D.map(r=>r.value);f!==null&&u.push(V(n)),u.push(c,a);let o=u[0],t=a-c;return u.forEach(r=>{const h=Math.abs(l-r);h<=t&&(o=r,t=h)}),o}).value,b=(n,l,u,o="unit")=>{if(typeof l=="number"){let t;const r=n[u],h=r+l;let e=[];D.forEach(s=>{e.push(s.value)}),e.push(c,a),e.push(V(r));const i=l>0?1:-1;o==="unit"?e.push(V(r+i*f)):e.push(V(h)),e=e.filter(s=>s!==null).filter(s=>l<0?s<=r:s>=r),o==="unit"&&(e=e.filter(s=>s!==r));const S=o==="unit"?r:h;t=e[0];let E=Math.abs(t-S);if(e.forEach(s=>{const N=Math.abs(s-S);N<E&&(t=s,E=N)}),t===void 0)return l<0?c:a;if(o==="dist")return t;if(Math.abs(l)>1){const s=[...n];return s[u]=t,b(s,l-i,u,o)}return t}else{if(l==="min")return c;if(l==="max")return a}},M=(n,l,u,o="unit")=>{const t=n[u],r=b(n,l,u,o);return{value:r,changed:r!==t}},p=n=>g===null&&n===0||typeof g=="number"&&n<g;return[y,(n,l,u,o="unit")=>{const t=n.map(y),r=t[u],h=b(t,l,u,o);if(t[u]=h,O){if(typeof g=="number"||g===null){for(let e=u+1;e<t.length;e+=1){let i=!0;for(;p(t[e]-t[e-1])&&i;)({value:t[e],changed:i}=M(t,1,e))}for(let e=u;e>0;e-=1){let i=!0;for(;p(t[e]-t[e-1])&&i;)({value:t[e-1],changed:i}=M(t,-1,e-1))}for(let e=t.length-1;e>0;e-=1){let i=!0;for(;p(t[e]-t[e-1])&&i;)({value:t[e-1],changed:i}=M(t,-1,e-1))}for(let e=0;e<t.length-1;e+=1){let i=!0;for(;p(t[e+1]-t[e])&&i;)({value:t[e+1],changed:i}=M(t,1,e+1))}}}else{const e=g||0;u>0&&t[u-1]!==r&&(t[u]=Math.max(t[u],t[u-1]+e)),u<t.length-1&&t[u+1]!==r&&(t[u]=Math.min(t[u],t[u+1]-e))}return{value:t[u],values:t}}]}exports.default=P;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InternalMarkObj } from '../Marks';
|
|
2
|
+
/** Format value align with step & marks */
|
|
3
|
+
type FormatValue = (value: number) => number;
|
|
4
|
+
type OffsetMode = 'unit' | 'dist';
|
|
5
|
+
export type OffsetValues = (values: number[], offset: number | 'min' | 'max', valueIndex: number, mode?: OffsetMode) => {
|
|
6
|
+
value: number;
|
|
7
|
+
values: number[];
|
|
8
|
+
};
|
|
9
|
+
export default function useOffset(min: number, max: number, step: number, markList: InternalMarkObj[], allowCross: boolean, pushable: false | number): [FormatValue, OffsetValues];
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { computed as m } from "vue";
|
|
2
|
+
function P(c, a, f, w, C, V) {
|
|
3
|
+
const b = m(() => (n) => Math.max(c, Math.min(a, n))).value, g = m(() => (n) => {
|
|
4
|
+
if (f !== null) {
|
|
5
|
+
const l = c + Math.round((b(n) - c) / f) * f, r = (u) => (String(u).split(".")[1] || "").length, i = Math.max(r(f), r(a), r(c)), t = Number(l.toFixed(i));
|
|
6
|
+
return c <= t && t <= a ? t : null;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}).value, y = m(() => (n) => {
|
|
10
|
+
const l = b(n), r = w.map((u) => u.value);
|
|
11
|
+
f !== null && r.push(g(n)), r.push(c, a);
|
|
12
|
+
let i = r[0], t = a - c;
|
|
13
|
+
return r.forEach((u) => {
|
|
14
|
+
const h = Math.abs(l - u);
|
|
15
|
+
h <= t && (i = u, t = h);
|
|
16
|
+
}), i;
|
|
17
|
+
}).value, D = (n, l, r, i = "unit") => {
|
|
18
|
+
if (typeof l == "number") {
|
|
19
|
+
let t;
|
|
20
|
+
const u = n[r], h = u + l;
|
|
21
|
+
let e = [];
|
|
22
|
+
w.forEach((s) => {
|
|
23
|
+
e.push(s.value);
|
|
24
|
+
}), e.push(c, a), e.push(g(u));
|
|
25
|
+
const o = l > 0 ? 1 : -1;
|
|
26
|
+
i === "unit" ? e.push(g(u + o * f)) : e.push(g(h)), e = e.filter((s) => s !== null).filter((s) => l < 0 ? s <= u : s >= u), i === "unit" && (e = e.filter((s) => s !== u));
|
|
27
|
+
const E = i === "unit" ? u : h;
|
|
28
|
+
t = e[0];
|
|
29
|
+
let N = Math.abs(t - E);
|
|
30
|
+
if (e.forEach((s) => {
|
|
31
|
+
const S = Math.abs(s - E);
|
|
32
|
+
S < N && (t = s, N = S);
|
|
33
|
+
}), t === void 0)
|
|
34
|
+
return l < 0 ? c : a;
|
|
35
|
+
if (i === "dist")
|
|
36
|
+
return t;
|
|
37
|
+
if (Math.abs(l) > 1) {
|
|
38
|
+
const s = [...n];
|
|
39
|
+
return s[r] = t, D(s, l - o, r, i);
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
} else {
|
|
43
|
+
if (l === "min")
|
|
44
|
+
return c;
|
|
45
|
+
if (l === "max")
|
|
46
|
+
return a;
|
|
47
|
+
}
|
|
48
|
+
}, p = (n, l, r, i = "unit") => {
|
|
49
|
+
const t = n[r], u = D(n, l, r, i);
|
|
50
|
+
return {
|
|
51
|
+
value: u,
|
|
52
|
+
changed: u !== t
|
|
53
|
+
};
|
|
54
|
+
}, M = (n) => V === null && n === 0 || typeof V == "number" && n < V;
|
|
55
|
+
return [y, (n, l, r, i = "unit") => {
|
|
56
|
+
const t = n.map(y), u = t[r], h = D(t, l, r, i);
|
|
57
|
+
if (t[r] = h, C) {
|
|
58
|
+
if (typeof V == "number" || V === null) {
|
|
59
|
+
for (let e = r + 1; e < t.length; e += 1) {
|
|
60
|
+
let o = !0;
|
|
61
|
+
for (; M(t[e] - t[e - 1]) && o; )
|
|
62
|
+
({ value: t[e], changed: o } = p(t, 1, e));
|
|
63
|
+
}
|
|
64
|
+
for (let e = r; e > 0; e -= 1) {
|
|
65
|
+
let o = !0;
|
|
66
|
+
for (; M(t[e] - t[e - 1]) && o; )
|
|
67
|
+
({ value: t[e - 1], changed: o } = p(t, -1, e - 1));
|
|
68
|
+
}
|
|
69
|
+
for (let e = t.length - 1; e > 0; e -= 1) {
|
|
70
|
+
let o = !0;
|
|
71
|
+
for (; M(t[e] - t[e - 1]) && o; )
|
|
72
|
+
({ value: t[e - 1], changed: o } = p(t, -1, e - 1));
|
|
73
|
+
}
|
|
74
|
+
for (let e = 0; e < t.length - 1; e += 1) {
|
|
75
|
+
let o = !0;
|
|
76
|
+
for (; M(t[e + 1] - t[e]) && o; )
|
|
77
|
+
({ value: t[e + 1], changed: o } = p(t, 1, e + 1));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
const e = V || 0;
|
|
82
|
+
r > 0 && t[r - 1] !== u && (t[r] = Math.max(
|
|
83
|
+
t[r],
|
|
84
|
+
t[r - 1] + e
|
|
85
|
+
)), r < t.length - 1 && t[r + 1] !== u && (t[r] = Math.min(
|
|
86
|
+
t[r],
|
|
87
|
+
t[r + 1] - e
|
|
88
|
+
));
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
value: t[r],
|
|
92
|
+
values: t
|
|
93
|
+
};
|
|
94
|
+
}];
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
P as default
|
|
98
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("@v-c/util/dist/warning");function i(e){if(e===!0||!e)return[!!e,!1,!1,0];const{editable:t=!1,draggableTrack:r=!1,minCount:a,maxCount:n}=e;return process.env.NODE_ENV!=="production"&&u.warning(!t||!r,"`editable` can not work with `draggableTrack`."),[!0,t,!t&&r,a||0,n]}exports.default=i;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { warning as o } from "@v-c/util/dist/warning";
|
|
2
|
+
function u(e) {
|
|
3
|
+
if (e === !0 || !e)
|
|
4
|
+
return [!!e, !1, !1, 0];
|
|
5
|
+
const { editable: t = !1, draggableTrack: a = !1, minCount: r, maxCount: n } = e;
|
|
6
|
+
return process.env.NODE_ENV !== "production" && o(!t || !a, "`editable` can not work with `draggableTrack`."), [!0, t, !t && a, r || 0, n];
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
u as default
|
|
10
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./Slider.cjs");exports.default=e.default;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CSSProperties } from 'vue';
|
|
2
|
+
export type Direction = 'rtl' | 'ltr' | 'ttb' | 'btt';
|
|
3
|
+
export type OnStartMove = (e: MouseEvent | TouchEvent, valueIndex: number, startValues?: number[]) => void;
|
|
4
|
+
export type AriaValueFormat = (value: number) => string;
|
|
5
|
+
export type SemanticName = 'tracks' | 'track' | 'rail' | 'handle';
|
|
6
|
+
export type SliderClassNames = Partial<Record<SemanticName, string>>;
|
|
7
|
+
export type SliderStyles = Partial<Record<SemanticName, CSSProperties>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/util.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e,r,a){return(e-r)/(a-r)}function f(e,r,a,s){const n=o(r,a,s),t={};switch(e){case"rtl":t.right=`${n*100}%`,t.transform="translateX(50%)";break;case"btt":t.bottom=`${n*100}%`,t.transform="translateY(50%)";break;case"ttb":t.top=`${n*100}%`,t.transform="translateY(-50%)";break;default:t.left=`${n*100}%`,t.transform="translateX(-50%)";break}return t}function i(e,r){return Array.isArray(e)?e[r]:e}exports.getDirectionStyle=f;exports.getIndex=i;exports.getOffset=o;
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CSSProperties } from 'vue';
|
|
2
|
+
import { Direction } from './interface';
|
|
3
|
+
export declare function getOffset(value: number, min: number, max: number): number;
|
|
4
|
+
export declare function getDirectionStyle(direction: Direction, value: number, min: number, max: number): CSSProperties;
|
|
5
|
+
/** Return index value if is list or return value directly */
|
|
6
|
+
export declare function getIndex<T>(value: T | T[], index: number): T;
|