@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/Slider.js CHANGED
@@ -1,13 +1,13 @@
1
- import { defineComponent as de, ref as S, shallowRef as T, watch as ve, watchEffect as w, computed as k, isVNode as fe, createVNode as E } from "vue";
2
- import ge from "@v-c/util/dist/isEqual";
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 be } from "./context.js";
6
- import me from "./Handles/index.js";
7
- import he from "./hooks/useDrag.js";
8
- import ye from "./hooks/useOffset.js";
9
- import Ce from "./hooks/useRange.js";
10
- import xe from "./Marks/index.js";
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 Me = /* @__PURE__ */ de({
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 y = S(), R = S(), B = T("ltr");
98
- ve([() => l.reverse, () => l.vertical], ([e, a]) => {
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 = T(0), p = T(100), O = T(1), D = S([]), C = S(l.defaultValue || l.value), n = S([]), r = S(), V = S();
104
- w(() => {
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: x,
122
+ allowCross: C,
113
123
  value: v,
114
124
  count: f
115
- } = l, [s, m, L, P, $] = Ce(e);
125
+ } = l, [s, x, L, P, $] = xe(e);
116
126
  r.value = {
117
127
  rangeEnabled: s,
118
- rangeEditable: m,
128
+ rangeEditable: x,
119
129
  rangeDraggableTrack: L,
120
130
  minCount: P,
121
131
  maxCount: $
122
- }, g.value = isFinite(a) ? a : 0, p.value = isFinite(t) ? t : 100, O.value = o !== null && o <= 0 ? 1 : o;
123
- const q = k(() => typeof i == "boolean" ? i ? O.value : !1 : i >= 0 ? i : !1);
124
- D.value = Object.keys(b || {}).map((h) => {
125
- const c = b?.[h], u = {
126
- value: Number(h)
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" && !fe(c) && ("label" in c || "style" in c) ? (u.style = c.style, u.label = c.label) : u.label = c, u;
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: h
131
- }) => h || typeof h == "number").sort((h, c) => h.value - c.value);
132
- const [M, H] = ye(g.value, p.value, O.value, D.value, x, q.value);
133
- V.value = {
134
- formatValue: M,
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 && (C.value = v);
137
- const ce = k(() => {
138
- const h = C.value === null || C.value === void 0 ? [] : Array.isArray(C.value) ? C.value : [C.value], [c = g.value] = h;
139
- let u = C.value === null ? [] : [c];
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 = [...h], f || C.value === void 0) {
142
- const N = f >= 0 ? f + 1 : 2;
143
- for (u = u.slice(0, N); u.length < N; )
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((N, z) => N - z);
156
+ u.sort((V, z) => V - z);
147
157
  }
148
- return u.forEach((N, z) => {
149
- u[z] = M(N);
158
+ return u.forEach((V, z) => {
159
+ u[z] = T(V);
150
160
  }), u;
151
161
  });
152
- n.value = ce.value;
162
+ n.value = de.value;
153
163
  });
154
- const F = (e) => r.value.rangeEnabled ? e : e[0], A = (e) => {
164
+ const p = (e) => r.value.rangeEnabled ? e : e[0], R = (e) => {
155
165
  const a = [...e].sort((t, o) => t - o);
156
- ge(a, n.value, !0) || d("change", F(a)), C.value = a;
166
+ be(a, n.value, !0) || d("change", p(a)), y.value = a;
157
167
  }, _ = (e) => {
158
- e && y.value?.hideHelp();
159
- const a = F(n.value);
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
- }, ee = (e) => {
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", F(a)), A(a);
175
+ a.splice(e, 1), d("beforeChange", p(a)), R(a);
166
176
  const t = Math.max(0, e - 1);
167
- y.value?.hideHelp(), y.value?.focus(t);
168
- }, [G, ae, le, J, K] = he(R, B, n, g, p, V.value.formatValue, A, _, V.value.offsetValues, r.value.rangeEditable, r.value.minCount), Q = (e, a) => {
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 = p.value - g.value;
181
+ let o = 0, i = 0, b = k.value - g.value;
172
182
  n.value.forEach((f, s) => {
173
- const m = Math.abs(e - f);
174
- m <= b && (b = m, o = s), f < e && (i = s);
183
+ const x = Math.abs(e - f);
184
+ x <= b && (b = x, o = s), f < e && (i = s);
175
185
  });
176
- let x = o;
177
- r.value.rangeEditable && b !== 0 && (!r.value.maxCount || n.value.length < r.value.maxCount) ? (t.splice(i + 1, 0, e), x = i + 1) : t[o] = e, r.value.rangeEnabled && !n.value.length && l.count === void 0 && t.push(e);
178
- const v = F(t);
179
- d("beforeChange", v), A(t), a ? (document.activeElement?.blur?.(), y.value?.focus(x), K(a, x, t)) : (l.onAfterChange && (d("afterChange", v), X(!1, "[vc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.")), d("changeComplete", 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
- }, te = (e) => {
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: x
190
- } = R.value.getBoundingClientRect(), {
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 = (x - v) / a;
213
+ s = (C - v) / a;
204
214
  break;
205
215
  default:
206
216
  s = (v - o) / a;
207
217
  }
208
- const m = g.value + s * (p.value - g.value);
209
- console.log("click", m, V.value.formatValue(m)), Q(V.value.formatValue(m), e);
210
- }, j = S(null), ne = (e, a) => {
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 = V.value.offsetValues(n.value, e, a);
213
- d("beforeChange", F(n.value)), A(t.values), j.value = t.value;
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
- w(() => {
226
+ M(() => {
217
227
  if (j.value !== null) {
218
228
  const e = n.value.indexOf(j.value);
219
- e >= 0 && y.value?.focus(e);
229
+ e >= 0 && h.value?.focus(e);
220
230
  }
221
231
  j.value = null;
222
232
  });
223
- const ue = k(() => r.value.rangeDraggableTrack && O.value === null ? (process.env.NODE_ENV !== "production" && X(!1, "`draggableTrack` is not supported when `step` is `null`."), !1) : r.value.rangeDraggableTrack), U = (e, a) => {
224
- console.log("onStartMove-valueIndex", a), K(e, a), d("beforeChange", F(n.value));
225
- }, re = k(() => G.value !== -1);
226
- w(() => {
227
- if (!re.value) {
228
- const e = n.value.lastIndexOf(ae.value);
229
- y.value?.focus(e);
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 = k(() => [...J.value].sort((e, a) => e - a)), [oe, se] = k(() => r.value.rangeEnabled ? [I.value[0], I.value[I.value.length - 1]] : [g.value, I.value[0]]).value;
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
- y.value?.focus(0);
245
+ h.value?.focus(0);
236
246
  },
237
247
  blur: () => {
238
248
  const {
239
249
  activeElement: e
240
250
  } = document;
241
- R.value?.contains(e) && e?.blur();
251
+ A.value?.contains(e) && e?.blur();
242
252
  }
243
- }), w(() => {
244
- l.autoFocus && y.value?.focus(0);
253
+ }), M(() => {
254
+ l.autoFocus && h.value?.focus(0);
245
255
  });
246
- const ie = k(() => ({
256
+ const ce = S(() => ({
247
257
  min: g,
248
- max: p,
258
+ max: k,
249
259
  direction: B,
250
260
  disabled: l.disabled,
251
261
  keyboard: l.keyboard,
252
- step: O,
262
+ step: E,
253
263
  included: l.included,
254
- includedStart: oe,
255
- includedEnd: se,
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 be(ie.value), () => {
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: x,
285
+ handleStyle: C,
276
286
  railStyle: v,
277
287
  dotStyle: f,
278
288
  activeDotStyle: s,
279
289
  // Decorations
280
- dots: m,
290
+ dots: x,
281
291
  handleRender: L,
282
292
  activeHandleRender: P,
283
293
  // Components
284
294
  track: $,
285
295
  classNames: q,
286
- styles: M
296
+ styles: T
287
297
  } = l;
288
- return E("div", {
289
- ref: R,
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`]: D.value.length
304
+ [`${e}-with-marks`]: O.value.length
295
305
  }),
296
306
  style: Y.style,
297
- onMousedown: te,
307
+ onMousedown: ne,
298
308
  id: a
299
- }, [E("div", {
309
+ }, [N("div", {
300
310
  class: W(`${e}-rail`, q?.rail),
301
311
  style: {
302
312
  ...v,
303
- ...M?.rail
313
+ ...T?.rail
304
314
  }
305
- }, null), $ && E(ke, {
315
+ }, null), $ && N(ke, {
306
316
  prefixCls: e,
307
317
  trackStyle: b,
308
318
  values: n.value,
309
319
  startPoint: i,
310
- onStartMove: ue.value ? U : void 0
311
- }, null), E(Se, {
320
+ onStartMove: re.value ? U : void 0
321
+ }, null), N(Se, {
312
322
  prefixCls: e,
313
- marks: D.value,
314
- dots: m,
323
+ marks: O.value,
324
+ dots: x,
315
325
  style: f,
316
326
  activeStyle: s
317
- }, null), E(me, {
318
- ref: y,
327
+ }, null), N(he, {
328
+ ref: h,
319
329
  prefixCls: e,
320
- handleStyle: x,
330
+ handleStyle: C,
321
331
  values: J.value,
322
332
  draggingIndex: G.value,
323
- draggingDelete: le.value,
333
+ draggingDelete: te.value,
324
334
  onStartMove: U,
325
- onOffsetChange: ne,
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 ? ee : () => {
341
+ onDelete: r.value.rangeEditable ? ae : () => {
332
342
  }
333
- }, null), E(xe, {
343
+ }, null), N(Fe, {
334
344
  prefixCls: e,
335
- marks: D.value,
345
+ marks: O.value,
336
346
  onClick: Q
337
- }, null)]);
347
+ }, ee)]);
338
348
  };
339
349
  }
340
350
  });
341
351
  export {
342
- Me as default
352
+ we as default
343
353
  };
@@ -1 +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=$;
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;
@@ -1,88 +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";
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 M = "targetTouches" in h ? h.targetTouches[0] : h;
7
- return { pageX: M.pageX, pageY: M.pageY };
6
+ const C = "targetTouches" in h ? h.targetTouches[0] : h;
7
+ return { pageX: C.pageX, pageY: C.pageY };
8
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(() => {
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, o, n) => {
15
- o !== void 0 && (Y.value = o), i.value = t;
14
+ const j = (t, n, o) => {
15
+ n !== void 0 && (Y.value = n), i.value = t;
16
16
  let a = t;
17
- n && (a = t.filter((l, e) => e !== c.value)), B(a), O && O({
17
+ o && (a = t.filter((l, e) => e !== c.value)), B(a), O && O({
18
18
  rawValues: t,
19
- deleteIndex: n ? c.value : -1,
19
+ deleteIndex: o ? c.value : -1,
20
20
  draggingIndex: c.value,
21
- draggingValue: o
21
+ draggingValue: n
22
22
  });
23
- }, F = Q(
24
- (t, o, n) => {
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 = o * (X.value - T.value);
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) * o, l = [...i.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, n);
35
+ j(e.values, e.value, o);
36
36
  }
37
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;
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: o,
46
+ draggingIndex: n,
47
47
  draggingValue: l
48
48
  });
49
49
  const V = (d) => {
50
50
  d.preventDefault();
51
- const { pageX: J, pageY: N } = _(d), D = J - e, S = N - s, { width: k, height: P } = h.value.getBoundingClientRect();
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 (M.value) {
53
+ switch (C.value) {
54
54
  case "btt":
55
- L = -S / P, b = D;
55
+ L = -S / P, b = M;
56
56
  break;
57
57
  case "ttb":
58
- L = S / P, b = D;
58
+ L = S / P, b = M;
59
59
  break;
60
60
  case "rtl":
61
- L = -D / k, b = S;
61
+ L = -M / k, b = S;
62
62
  break;
63
63
  default:
64
- L = D / k, b = S;
64
+ L = M / k, b = S;
65
65
  }
66
- u = R ? Math.abs(b) > I && z < i.value.length : !1, C.value = u, F(o, L, u);
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, 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
- }, 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;
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
- n[e] = (n[e] || 0) - 1;
76
+ o[e] = (o[e] || 0) - 1;
77
77
  });
78
78
  const a = R ? 1 : 0;
79
- return Object.values(n).reduce(
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, C, H, G];
84
+ return [c, Y, D, G, F];
85
85
  }
86
86
  export {
87
- oe as default
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/slider",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "description": "",
6
6
  "exports": {
7
7
  ".": {
@@ -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
- console.log('render', renderProps)
216
+
220
217
  const RenderNode = () => render(renderProps)
221
218
  return <RenderNode />
222
219
  }
@@ -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>