@v-c/slider 1.0.0 → 1.0.2
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 +1 -1
- package/dist/Handles/Handle.js +50 -50
- package/dist/Marks/index.cjs +1 -1
- package/dist/Marks/index.js +23 -22
- package/dist/Slider.cjs +1 -1
- package/dist/Slider.d.ts +39 -12
- package/dist/Slider.js +118 -108
- package/dist/hooks/useDrag.cjs +1 -1
- package/dist/hooks/useDrag.js +39 -39
- package/docs/marks.vue +10 -1
- package/package.json +1 -1
- package/src/Handles/Handle.tsx +1 -4
- package/src/Marks/index.tsx +2 -2
- package/src/Slider.tsx +593 -582
- package/src/hooks/useDrag.ts +0 -1
package/dist/Slider.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import
|
|
1
|
+
import { defineComponent as ve, ref as F, shallowRef as w, watch as fe, watchEffect as M, computed as S, isVNode as ge, createVNode as N } from "vue";
|
|
2
|
+
import be from "@v-c/util/dist/isEqual";
|
|
3
3
|
import X from "@v-c/util/dist/warning";
|
|
4
4
|
import W from "classnames";
|
|
5
|
-
import { useProviderSliderContext as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
5
|
+
import { useProviderSliderContext as me } from "./context.js";
|
|
6
|
+
import he from "./Handles/index.js";
|
|
7
|
+
import ye from "./hooks/useDrag.js";
|
|
8
|
+
import Ce from "./hooks/useOffset.js";
|
|
9
|
+
import xe from "./hooks/useRange.js";
|
|
10
|
+
import Fe from "./Marks/index.js";
|
|
11
11
|
import Se from "./Steps/index.js";
|
|
12
12
|
import ke from "./Tracks/index.js";
|
|
13
13
|
function pe() {
|
|
@@ -80,28 +80,38 @@ function pe() {
|
|
|
80
80
|
ariaLabelForHandle: [String, Array],
|
|
81
81
|
ariaLabelledByForHandle: [String, Array],
|
|
82
82
|
ariaRequired: Boolean,
|
|
83
|
-
ariaValueTextFormatterForHandle: [Function, Array]
|
|
83
|
+
ariaValueTextFormatterForHandle: [Function, Array],
|
|
84
|
+
onFocus: Function,
|
|
85
|
+
onBlur: Function,
|
|
86
|
+
onChange: Function,
|
|
87
|
+
/** @deprecated It's always better to use `onChange` instead */
|
|
88
|
+
onBeforeChange: Function,
|
|
89
|
+
/** @deprecated Use `onChangeComplete` instead */
|
|
90
|
+
onAfterChange: Function,
|
|
91
|
+
onChangeComplete: Function
|
|
84
92
|
};
|
|
85
93
|
}
|
|
86
|
-
const
|
|
94
|
+
const we = /* @__PURE__ */ ve({
|
|
87
95
|
name: "Slider",
|
|
88
96
|
props: {
|
|
89
97
|
...pe()
|
|
90
98
|
},
|
|
91
99
|
emits: ["focus", "blur", "change", "beforeChange", "afterChange", "changeComplete"],
|
|
100
|
+
slots: Object,
|
|
92
101
|
setup(l, {
|
|
93
102
|
attrs: Y,
|
|
94
103
|
emit: d,
|
|
95
|
-
expose: Z
|
|
104
|
+
expose: Z,
|
|
105
|
+
slots: ee
|
|
96
106
|
}) {
|
|
97
|
-
const
|
|
98
|
-
|
|
107
|
+
const h = F(), A = F(), B = w("ltr");
|
|
108
|
+
fe([() => l.reverse, () => l.vertical], ([e, a]) => {
|
|
99
109
|
a ? B.value = e ? "ttb" : "btt" : B.value = e ? "rtl" : "ltr";
|
|
100
110
|
}, {
|
|
101
111
|
immediate: !0
|
|
102
112
|
});
|
|
103
|
-
const g =
|
|
104
|
-
|
|
113
|
+
const g = w(0), k = w(100), E = w(1), O = F([]), y = F(l.defaultValue || l.value), n = F([]), r = F(), D = F();
|
|
114
|
+
M(() => {
|
|
105
115
|
const {
|
|
106
116
|
range: e,
|
|
107
117
|
min: a,
|
|
@@ -109,76 +119,76 @@ const Me = /* @__PURE__ */ de({
|
|
|
109
119
|
step: o,
|
|
110
120
|
pushable: i,
|
|
111
121
|
marks: b,
|
|
112
|
-
allowCross:
|
|
122
|
+
allowCross: C,
|
|
113
123
|
value: v,
|
|
114
124
|
count: f
|
|
115
|
-
} = l, [s,
|
|
125
|
+
} = l, [s, x, L, P, $] = xe(e);
|
|
116
126
|
r.value = {
|
|
117
127
|
rangeEnabled: s,
|
|
118
|
-
rangeEditable:
|
|
128
|
+
rangeEditable: x,
|
|
119
129
|
rangeDraggableTrack: L,
|
|
120
130
|
minCount: P,
|
|
121
131
|
maxCount: $
|
|
122
|
-
}, g.value = isFinite(a) ? a : 0,
|
|
123
|
-
const q =
|
|
124
|
-
|
|
125
|
-
const c = b?.[
|
|
126
|
-
value: Number(
|
|
132
|
+
}, g.value = isFinite(a) ? a : 0, k.value = isFinite(t) ? t : 100, E.value = o !== null && o <= 0 ? 1 : o;
|
|
133
|
+
const q = S(() => typeof i == "boolean" ? i ? E.value : !1 : i >= 0 ? i : !1);
|
|
134
|
+
O.value = Object.keys(b || {}).map((m) => {
|
|
135
|
+
const c = b?.[m], u = {
|
|
136
|
+
value: Number(m)
|
|
127
137
|
};
|
|
128
|
-
return c && typeof c == "object" && !
|
|
138
|
+
return c && typeof c == "object" && !ge(c) && ("label" in c || "style" in c) ? (u.style = c.style, u.label = c.label) : u.label = c, u;
|
|
129
139
|
}).filter(({
|
|
130
|
-
label:
|
|
131
|
-
}) =>
|
|
132
|
-
const [
|
|
133
|
-
|
|
134
|
-
formatValue:
|
|
140
|
+
label: m
|
|
141
|
+
}) => m || typeof m == "number").sort((m, c) => m.value - c.value);
|
|
142
|
+
const [T, H] = Ce(g.value, k.value, E.value, O.value, C, q.value);
|
|
143
|
+
D.value = {
|
|
144
|
+
formatValue: T,
|
|
135
145
|
offsetValues: H
|
|
136
|
-
}, v !== void 0 && (
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
let u =
|
|
146
|
+
}, v !== void 0 && (y.value = v);
|
|
147
|
+
const de = S(() => {
|
|
148
|
+
const m = y.value === null || y.value === void 0 ? [] : Array.isArray(y.value) ? y.value : [y.value], [c = g.value] = m;
|
|
149
|
+
let u = y.value === null ? [] : [c];
|
|
140
150
|
if (s) {
|
|
141
|
-
if (u = [...
|
|
142
|
-
const
|
|
143
|
-
for (u = u.slice(0,
|
|
151
|
+
if (u = [...m], f || y.value === void 0) {
|
|
152
|
+
const V = f >= 0 ? f + 1 : 2;
|
|
153
|
+
for (u = u.slice(0, V); u.length < V; )
|
|
144
154
|
u.push(u[u.length - 1] ?? g.value);
|
|
145
155
|
}
|
|
146
|
-
u.sort((
|
|
156
|
+
u.sort((V, z) => V - z);
|
|
147
157
|
}
|
|
148
|
-
return u.forEach((
|
|
149
|
-
u[z] =
|
|
158
|
+
return u.forEach((V, z) => {
|
|
159
|
+
u[z] = T(V);
|
|
150
160
|
}), u;
|
|
151
161
|
});
|
|
152
|
-
n.value =
|
|
162
|
+
n.value = de.value;
|
|
153
163
|
});
|
|
154
|
-
const
|
|
164
|
+
const p = (e) => r.value.rangeEnabled ? e : e[0], R = (e) => {
|
|
155
165
|
const a = [...e].sort((t, o) => t - o);
|
|
156
|
-
|
|
166
|
+
be(a, n.value, !0) || d("change", p(a)), y.value = a;
|
|
157
167
|
}, _ = (e) => {
|
|
158
|
-
e &&
|
|
159
|
-
const a =
|
|
168
|
+
e && h.value?.hideHelp();
|
|
169
|
+
const a = p(n.value);
|
|
160
170
|
l.onAfterChange && (d("afterChange", a), X(!1, "[vc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.")), d("changeComplete", a);
|
|
161
|
-
},
|
|
171
|
+
}, ae = (e) => {
|
|
162
172
|
if (l.disabled || !r.value.rangeEditable || n.value.length <= r.value.minCount)
|
|
163
173
|
return;
|
|
164
174
|
const a = [...n.value];
|
|
165
|
-
a.splice(e, 1), d("beforeChange",
|
|
175
|
+
a.splice(e, 1), d("beforeChange", p(a)), R(a);
|
|
166
176
|
const t = Math.max(0, e - 1);
|
|
167
|
-
|
|
168
|
-
}, [G,
|
|
177
|
+
h.value?.hideHelp(), h.value?.focus(t);
|
|
178
|
+
}, [G, le, te, J, K] = ye(A, B, n, g, k, D.value.formatValue, R, _, D.value.offsetValues, r.value.rangeEditable, r.value.minCount), Q = (e, a) => {
|
|
169
179
|
if (!l.disabled) {
|
|
170
180
|
const t = [...n.value];
|
|
171
|
-
let o = 0, i = 0, b =
|
|
181
|
+
let o = 0, i = 0, b = k.value - g.value;
|
|
172
182
|
n.value.forEach((f, s) => {
|
|
173
|
-
const
|
|
174
|
-
|
|
183
|
+
const x = Math.abs(e - f);
|
|
184
|
+
x <= b && (b = x, o = s), f < e && (i = s);
|
|
175
185
|
});
|
|
176
|
-
let
|
|
177
|
-
r.value.rangeEditable && b !== 0 && (!r.value.maxCount || n.value.length < r.value.maxCount) ? (t.splice(i + 1, 0, e),
|
|
178
|
-
const v =
|
|
179
|
-
d("beforeChange", v),
|
|
186
|
+
let C = o;
|
|
187
|
+
r.value.rangeEditable && b !== 0 && (!r.value.maxCount || n.value.length < r.value.maxCount) ? (t.splice(i + 1, 0, e), C = i + 1) : t[o] = e, r.value.rangeEnabled && !n.value.length && l.count === void 0 && t.push(e);
|
|
188
|
+
const v = p(t);
|
|
189
|
+
d("beforeChange", v), R(t), a ? (document.activeElement?.blur?.(), h.value?.focus(C), K(a, C, t)) : (l.onAfterChange && (d("afterChange", v), X(!1, "[vc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.")), d("changeComplete", v));
|
|
180
190
|
}
|
|
181
|
-
},
|
|
191
|
+
}, ne = (e) => {
|
|
182
192
|
e.preventDefault();
|
|
183
193
|
const {
|
|
184
194
|
width: a,
|
|
@@ -186,8 +196,8 @@ const Me = /* @__PURE__ */ de({
|
|
|
186
196
|
left: o,
|
|
187
197
|
top: i,
|
|
188
198
|
bottom: b,
|
|
189
|
-
right:
|
|
190
|
-
} =
|
|
199
|
+
right: C
|
|
200
|
+
} = A.value.getBoundingClientRect(), {
|
|
191
201
|
clientX: v,
|
|
192
202
|
clientY: f
|
|
193
203
|
} = e;
|
|
@@ -200,59 +210,59 @@ const Me = /* @__PURE__ */ de({
|
|
|
200
210
|
s = (f - i) / t;
|
|
201
211
|
break;
|
|
202
212
|
case "rtl":
|
|
203
|
-
s = (
|
|
213
|
+
s = (C - v) / a;
|
|
204
214
|
break;
|
|
205
215
|
default:
|
|
206
216
|
s = (v - o) / a;
|
|
207
217
|
}
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
}, j =
|
|
218
|
+
const x = g.value + s * (k.value - g.value);
|
|
219
|
+
Q(D.value.formatValue(x), e);
|
|
220
|
+
}, j = F(null), ue = (e, a) => {
|
|
211
221
|
if (!l.disabled) {
|
|
212
|
-
const t =
|
|
213
|
-
d("beforeChange",
|
|
222
|
+
const t = D.value.offsetValues(n.value, e, a);
|
|
223
|
+
d("beforeChange", p(n.value)), R(t.values), j.value = t.value;
|
|
214
224
|
}
|
|
215
225
|
};
|
|
216
|
-
|
|
226
|
+
M(() => {
|
|
217
227
|
if (j.value !== null) {
|
|
218
228
|
const e = n.value.indexOf(j.value);
|
|
219
|
-
e >= 0 &&
|
|
229
|
+
e >= 0 && h.value?.focus(e);
|
|
220
230
|
}
|
|
221
231
|
j.value = null;
|
|
222
232
|
});
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
},
|
|
226
|
-
|
|
227
|
-
if (!
|
|
228
|
-
const e = n.value.lastIndexOf(
|
|
229
|
-
|
|
233
|
+
const re = S(() => r.value.rangeDraggableTrack && E.value === null ? (process.env.NODE_ENV !== "production" && X(!1, "`draggableTrack` is not supported when `step` is `null`."), !1) : r.value.rangeDraggableTrack), U = (e, a) => {
|
|
234
|
+
K(e, a), d("beforeChange", p(n.value));
|
|
235
|
+
}, oe = S(() => G.value !== -1);
|
|
236
|
+
M(() => {
|
|
237
|
+
if (!oe.value) {
|
|
238
|
+
const e = n.value.lastIndexOf(le.value);
|
|
239
|
+
h.value?.focus(e);
|
|
230
240
|
}
|
|
231
241
|
});
|
|
232
|
-
const I =
|
|
242
|
+
const I = S(() => [...J.value].sort((e, a) => e - a)), [se, ie] = S(() => r.value.rangeEnabled ? [I.value[0], I.value[I.value.length - 1]] : [g.value, I.value[0]]).value;
|
|
233
243
|
Z({
|
|
234
244
|
focus: () => {
|
|
235
|
-
|
|
245
|
+
h.value?.focus(0);
|
|
236
246
|
},
|
|
237
247
|
blur: () => {
|
|
238
248
|
const {
|
|
239
249
|
activeElement: e
|
|
240
250
|
} = document;
|
|
241
|
-
|
|
251
|
+
A.value?.contains(e) && e?.blur();
|
|
242
252
|
}
|
|
243
|
-
}),
|
|
244
|
-
l.autoFocus &&
|
|
253
|
+
}), M(() => {
|
|
254
|
+
l.autoFocus && h.value?.focus(0);
|
|
245
255
|
});
|
|
246
|
-
const
|
|
256
|
+
const ce = S(() => ({
|
|
247
257
|
min: g,
|
|
248
|
-
max:
|
|
258
|
+
max: k,
|
|
249
259
|
direction: B,
|
|
250
260
|
disabled: l.disabled,
|
|
251
261
|
keyboard: l.keyboard,
|
|
252
|
-
step:
|
|
262
|
+
step: E,
|
|
253
263
|
included: l.included,
|
|
254
|
-
includedStart:
|
|
255
|
-
includedEnd:
|
|
264
|
+
includedStart: se,
|
|
265
|
+
includedEnd: ie,
|
|
256
266
|
range: r.value.rangeEnabled,
|
|
257
267
|
tabIndex: l.tabIndex,
|
|
258
268
|
ariaLabelForHandle: l.ariaLabelForHandle,
|
|
@@ -262,7 +272,7 @@ const Me = /* @__PURE__ */ de({
|
|
|
262
272
|
styles: l.styles || {},
|
|
263
273
|
classNames: l.classNames || {}
|
|
264
274
|
}));
|
|
265
|
-
return
|
|
275
|
+
return me(ce.value), () => {
|
|
266
276
|
const {
|
|
267
277
|
prefixCls: e = "vc-slider",
|
|
268
278
|
id: a,
|
|
@@ -272,72 +282,72 @@ const Me = /* @__PURE__ */ de({
|
|
|
272
282
|
// Style
|
|
273
283
|
startPoint: i,
|
|
274
284
|
trackStyle: b,
|
|
275
|
-
handleStyle:
|
|
285
|
+
handleStyle: C,
|
|
276
286
|
railStyle: v,
|
|
277
287
|
dotStyle: f,
|
|
278
288
|
activeDotStyle: s,
|
|
279
289
|
// Decorations
|
|
280
|
-
dots:
|
|
290
|
+
dots: x,
|
|
281
291
|
handleRender: L,
|
|
282
292
|
activeHandleRender: P,
|
|
283
293
|
// Components
|
|
284
294
|
track: $,
|
|
285
295
|
classNames: q,
|
|
286
|
-
styles:
|
|
296
|
+
styles: T
|
|
287
297
|
} = l;
|
|
288
|
-
return
|
|
289
|
-
ref:
|
|
298
|
+
return N("div", {
|
|
299
|
+
ref: A,
|
|
290
300
|
class: W(e, [Y.class], {
|
|
291
301
|
[`${e}-disabled`]: t,
|
|
292
302
|
[`${e}-vertical`]: o,
|
|
293
303
|
[`${e}-horizontal`]: !o,
|
|
294
|
-
[`${e}-with-marks`]:
|
|
304
|
+
[`${e}-with-marks`]: O.value.length
|
|
295
305
|
}),
|
|
296
306
|
style: Y.style,
|
|
297
|
-
onMousedown:
|
|
307
|
+
onMousedown: ne,
|
|
298
308
|
id: a
|
|
299
|
-
}, [
|
|
309
|
+
}, [N("div", {
|
|
300
310
|
class: W(`${e}-rail`, q?.rail),
|
|
301
311
|
style: {
|
|
302
312
|
...v,
|
|
303
|
-
...
|
|
313
|
+
...T?.rail
|
|
304
314
|
}
|
|
305
|
-
}, null), $ &&
|
|
315
|
+
}, null), $ && N(ke, {
|
|
306
316
|
prefixCls: e,
|
|
307
317
|
trackStyle: b,
|
|
308
318
|
values: n.value,
|
|
309
319
|
startPoint: i,
|
|
310
|
-
onStartMove:
|
|
311
|
-
}, null),
|
|
320
|
+
onStartMove: re.value ? U : void 0
|
|
321
|
+
}, null), N(Se, {
|
|
312
322
|
prefixCls: e,
|
|
313
|
-
marks:
|
|
314
|
-
dots:
|
|
323
|
+
marks: O.value,
|
|
324
|
+
dots: x,
|
|
315
325
|
style: f,
|
|
316
326
|
activeStyle: s
|
|
317
|
-
}, null),
|
|
318
|
-
ref:
|
|
327
|
+
}, null), N(he, {
|
|
328
|
+
ref: h,
|
|
319
329
|
prefixCls: e,
|
|
320
|
-
handleStyle:
|
|
330
|
+
handleStyle: C,
|
|
321
331
|
values: J.value,
|
|
322
332
|
draggingIndex: G.value,
|
|
323
|
-
draggingDelete:
|
|
333
|
+
draggingDelete: te.value,
|
|
324
334
|
onStartMove: U,
|
|
325
|
-
onOffsetChange:
|
|
335
|
+
onOffsetChange: ue,
|
|
326
336
|
onFocus: (H) => d("focus", H),
|
|
327
337
|
onBlur: (H) => d("blur", H),
|
|
328
338
|
handleRender: L,
|
|
329
339
|
activeHandleRender: P,
|
|
330
340
|
onChangeComplete: _,
|
|
331
|
-
onDelete: r.value.rangeEditable ?
|
|
341
|
+
onDelete: r.value.rangeEditable ? ae : () => {
|
|
332
342
|
}
|
|
333
|
-
}, null),
|
|
343
|
+
}, null), N(Fe, {
|
|
334
344
|
prefixCls: e,
|
|
335
|
-
marks:
|
|
345
|
+
marks: O.value,
|
|
336
346
|
onClick: Q
|
|
337
|
-
},
|
|
347
|
+
}, ee)]);
|
|
338
348
|
};
|
|
339
349
|
}
|
|
340
350
|
});
|
|
341
351
|
export {
|
|
342
|
-
|
|
352
|
+
we as default
|
|
343
353
|
};
|
package/dist/hooks/useDrag.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Q=require("@v-c/util/dist/hooks/useEvent"),l=require("vue"),q=require("../context.cjs"),W=130;function P(h){const M="targetTouches"in h?h.targetTouches[0]:h;return{pageX:M.pageX,pageY:M.pageY}}function Z(h,M,f,T,X,y,B,K,x,O,z){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),A=l.inject(q.UnstableContextKey,q.defaultUnstableContextValue),{onDragStart:R,onDragChange:U}=A;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,u,n)=>{u!==void 0&&(Y.value=u),i.value=t;let a=t;n&&(a=t.filter((s,e)=>e!==c.value)),B(a),U&&U({rawValues:t,deleteIndex:n?c.value:-1,draggingIndex:c.value,draggingValue:u})},F=Q((t,u,n)=>{if(t===-1){const a=g.value[0],s=g.value[g.value.length-1],e=T.value-a,r=X.value-s;let o=u*(X.value-T.value);o=Math.max(o,e),o=Math.min(o,r),o=y(a+o)-a;const d=g.value.map(m=>m+o);j(d)}else{const a=(X.value-T.value)*u,s=[...i.value];s[t]=g.value[t];const e=x(s,a,t,"dist");j(e.values,e.value,n)}}),G=(t,u,n)=>{t.stopPropagation();const a=n||f.value,s=a[u];c.value=u,Y.value=s,g.value=a,i.value=a,C.value=!1;const{pageX:e,pageY:r}=P(t);let o=!1;R&&R({rawValues:a,draggingIndex:u,draggingValue:s});const b=m=>{m.preventDefault();const{pageX:J,pageY:N}=P(m),D=J-e,S=N-r,{width:_,height:k}=h.value.getBoundingClientRect();let V,L;switch(M.value){case"btt":V=-S/k,L=D;break;case"ttb":V=S/k,L=D;break;case"rtl":V=-D/_,L=S;break;default:V=D/_,L=S}o=O?Math.abs(L)>W&&z<i.value.length:!1,C.value=o,F(u,V,o)},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(o),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},H=l.computed(()=>{const t=[...f.value].sort((e,r)=>e-r),u=[...i.value].sort((e,r)=>e-r),n={};u.forEach(e=>{n[e]=(n[e]||0)+1}),t.forEach(e=>{n[e]=(n[e]||0)-1});const a=O?1:0;return Object.values(n).reduce((e,r)=>e+Math.abs(r),0)<=a?i.value:f.value});return[c,Y,C,H,G]}exports.default=Z;
|
package/dist/hooks/useDrag.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ref as r, inject as
|
|
3
|
-
import { UnstableContextKey as
|
|
1
|
+
import N from "@v-c/util/dist/hooks/useEvent";
|
|
2
|
+
import { ref as r, inject as Q, onUnmounted as W, computed as Z } from "vue";
|
|
3
|
+
import { UnstableContextKey as $, defaultUnstableContextValue as w } from "../context.js";
|
|
4
4
|
const I = 130;
|
|
5
5
|
function _(h) {
|
|
6
|
-
const
|
|
7
|
-
return { pageX:
|
|
6
|
+
const C = "targetTouches" in h ? h.targetTouches[0] : h;
|
|
7
|
+
return { pageX: C.pageX, pageY: C.pageY };
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const Y = r(null), c = r(-1),
|
|
11
|
-
c.value === -1 && (i.value = f.value),
|
|
9
|
+
function ne(h, C, f, T, X, y, B, K, q, R, x) {
|
|
10
|
+
const Y = r(null), c = r(-1), D = r(!1), i = r(f.value), g = r(f.value), p = r(null), E = r(null), v = r(null), z = Q($, w), { onDragStart: U, onDragChange: O } = z;
|
|
11
|
+
c.value === -1 && (i.value = f.value), W(() => {
|
|
12
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
13
|
});
|
|
14
|
-
const j = (t,
|
|
15
|
-
|
|
14
|
+
const j = (t, n, o) => {
|
|
15
|
+
n !== void 0 && (Y.value = n), i.value = t;
|
|
16
16
|
let a = t;
|
|
17
|
-
|
|
17
|
+
o && (a = t.filter((l, e) => e !== c.value)), B(a), O && O({
|
|
18
18
|
rawValues: t,
|
|
19
|
-
deleteIndex:
|
|
19
|
+
deleteIndex: o ? c.value : -1,
|
|
20
20
|
draggingIndex: c.value,
|
|
21
|
-
draggingValue:
|
|
21
|
+
draggingValue: n
|
|
22
22
|
});
|
|
23
|
-
},
|
|
24
|
-
(t,
|
|
23
|
+
}, A = N(
|
|
24
|
+
(t, n, o) => {
|
|
25
25
|
if (t === -1) {
|
|
26
26
|
const a = g.value[0], l = g.value[g.value.length - 1], e = T.value - a, s = X.value - l;
|
|
27
|
-
let u =
|
|
27
|
+
let u = n * (X.value - T.value);
|
|
28
28
|
u = Math.max(u, e), u = Math.min(u, s), u = y(a + u) - a;
|
|
29
29
|
const m = g.value.map((d) => d + u);
|
|
30
30
|
j(m);
|
|
31
31
|
} else {
|
|
32
|
-
const a = (X.value - T.value) *
|
|
32
|
+
const a = (X.value - T.value) * n, l = [...i.value];
|
|
33
33
|
l[t] = g.value[t];
|
|
34
34
|
const e = q(l, a, t, "dist");
|
|
35
|
-
j(e.values, e.value,
|
|
35
|
+
j(e.values, e.value, o);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
),
|
|
39
|
-
t.stopPropagation()
|
|
40
|
-
const a =
|
|
41
|
-
c.value =
|
|
38
|
+
), F = (t, n, o) => {
|
|
39
|
+
t.stopPropagation();
|
|
40
|
+
const a = o || f.value, l = a[n];
|
|
41
|
+
c.value = n, Y.value = l, g.value = a, i.value = a, D.value = !1;
|
|
42
42
|
const { pageX: e, pageY: s } = _(t);
|
|
43
43
|
let u = !1;
|
|
44
44
|
U && U({
|
|
45
45
|
rawValues: a,
|
|
46
|
-
draggingIndex:
|
|
46
|
+
draggingIndex: n,
|
|
47
47
|
draggingValue: l
|
|
48
48
|
});
|
|
49
49
|
const V = (d) => {
|
|
50
50
|
d.preventDefault();
|
|
51
|
-
const { pageX:
|
|
51
|
+
const { pageX: H, pageY: J } = _(d), M = H - e, S = J - s, { width: k, height: P } = h.value.getBoundingClientRect();
|
|
52
52
|
let L, b;
|
|
53
|
-
switch (
|
|
53
|
+
switch (C.value) {
|
|
54
54
|
case "btt":
|
|
55
|
-
L = -S / P, b =
|
|
55
|
+
L = -S / P, b = M;
|
|
56
56
|
break;
|
|
57
57
|
case "ttb":
|
|
58
|
-
L = S / P, b =
|
|
58
|
+
L = S / P, b = M;
|
|
59
59
|
break;
|
|
60
60
|
case "rtl":
|
|
61
|
-
L = -
|
|
61
|
+
L = -M / k, b = S;
|
|
62
62
|
break;
|
|
63
63
|
default:
|
|
64
|
-
L =
|
|
64
|
+
L = M / k, b = S;
|
|
65
65
|
}
|
|
66
|
-
u = R ? Math.abs(b) > I &&
|
|
66
|
+
u = R ? Math.abs(b) > I && x < i.value.length : !1, D.value = u, A(n, L, u);
|
|
67
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,
|
|
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, D.value = !1;
|
|
69
69
|
};
|
|
70
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
|
-
},
|
|
72
|
-
const t = [...f.value].sort((e, s) => e - s),
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
}, G = Z(() => {
|
|
72
|
+
const t = [...f.value].sort((e, s) => e - s), n = [...i.value].sort((e, s) => e - s), o = {};
|
|
73
|
+
n.forEach((e) => {
|
|
74
|
+
o[e] = (o[e] || 0) + 1;
|
|
75
75
|
}), t.forEach((e) => {
|
|
76
|
-
|
|
76
|
+
o[e] = (o[e] || 0) - 1;
|
|
77
77
|
});
|
|
78
78
|
const a = R ? 1 : 0;
|
|
79
|
-
return Object.values(
|
|
79
|
+
return Object.values(o).reduce(
|
|
80
80
|
(e, s) => e + Math.abs(s),
|
|
81
81
|
0
|
|
82
82
|
) <= a ? i.value : f.value;
|
|
83
83
|
});
|
|
84
|
-
return [c, Y,
|
|
84
|
+
return [c, Y, D, G, F];
|
|
85
85
|
}
|
|
86
86
|
export {
|
|
87
|
-
|
|
87
|
+
ne as default
|
|
88
88
|
};
|
package/docs/marks.vue
CHANGED
|
@@ -37,7 +37,16 @@ function log(value) {
|
|
|
37
37
|
:default-value="20"
|
|
38
38
|
@change="log"
|
|
39
39
|
@change-complete="(v) => console.log('AfterChange', v)"
|
|
40
|
-
|
|
40
|
+
>
|
|
41
|
+
<template #mark="{ point, label }">
|
|
42
|
+
<template v-if="point === 100">
|
|
43
|
+
<strong>{{ label }}</strong>
|
|
44
|
+
</template>
|
|
45
|
+
<template v-else>
|
|
46
|
+
{{ label }}
|
|
47
|
+
</template>
|
|
48
|
+
</template>
|
|
49
|
+
</Slider>
|
|
41
50
|
</div>
|
|
42
51
|
|
|
43
52
|
<div :style="style">
|
package/package.json
CHANGED
package/src/Handles/Handle.tsx
CHANGED
|
@@ -47,19 +47,16 @@ export default defineComponent({
|
|
|
47
47
|
|
|
48
48
|
// ============================ Events ============================
|
|
49
49
|
const onInternalStartMove = (e: MouseEvent | TouchEvent) => {
|
|
50
|
-
console.log('emit-start')
|
|
51
50
|
if (!disabled) {
|
|
52
51
|
emit('startMove', e, props.valueIndex)
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
const onInternalFocus = (e: FocusEvent) => {
|
|
57
|
-
console.log('emit-focus')
|
|
58
56
|
emit('focus', e, props.valueIndex)
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
const onInternalMouseEnter = (e: MouseEvent) => {
|
|
62
|
-
console.log('emit-enter')
|
|
63
60
|
emit('mouseenter', e, props.valueIndex)
|
|
64
61
|
}
|
|
65
62
|
|
|
@@ -216,7 +213,7 @@ export default defineComponent({
|
|
|
216
213
|
draggingDelete,
|
|
217
214
|
node: handleNode,
|
|
218
215
|
}
|
|
219
|
-
|
|
216
|
+
|
|
220
217
|
const RenderNode = () => render(renderProps)
|
|
221
218
|
return <RenderNode />
|
|
222
219
|
}
|
package/src/Marks/index.tsx
CHANGED
|
@@ -16,7 +16,7 @@ export interface MarksProps {
|
|
|
16
16
|
onClick?: (value: number) => void
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const Marks: FunctionalComponent<MarksProps> = (props, { emit }) => {
|
|
19
|
+
const Marks: FunctionalComponent<MarksProps> = (props, { emit, slots }) => {
|
|
20
20
|
const { prefixCls, marks = [] } = props
|
|
21
21
|
|
|
22
22
|
const markPrefixCls = `${prefixCls}-mark`
|
|
@@ -30,7 +30,7 @@ const Marks: FunctionalComponent<MarksProps> = (props, { emit }) => {
|
|
|
30
30
|
<div class={markPrefixCls}>
|
|
31
31
|
{marks.map(({ value, style, label }) => (
|
|
32
32
|
<Mark key={value} prefixCls={markPrefixCls} style={style} value={value} onClick={() => emit('click', value)}>
|
|
33
|
-
{label}
|
|
33
|
+
{slots.mark?.({ point: value, label }) || label}
|
|
34
34
|
</Mark>
|
|
35
35
|
))}
|
|
36
36
|
</div>
|