@v-c/slider 1.0.1 → 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,16 +1,16 @@
1
- import { defineComponent as de, ref as F, shallowRef as T, watch as ve, watchEffect as w, computed as S, isVNode as fe, createVNode as B } 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";
11
- import Fe from "./Steps/index.js";
12
- import Se from "./Tracks/index.js";
13
- function ke() {
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
+ import Se from "./Steps/index.js";
12
+ import ke from "./Tracks/index.js";
13
+ function pe() {
14
14
  return {
15
15
  prefixCls: {
16
16
  type: String,
@@ -91,25 +91,27 @@ function ke() {
91
91
  onChangeComplete: Function
92
92
  };
93
93
  }
94
- const Me = /* @__PURE__ */ de({
94
+ const we = /* @__PURE__ */ ve({
95
95
  name: "Slider",
96
96
  props: {
97
- ...ke()
97
+ ...pe()
98
98
  },
99
99
  emits: ["focus", "blur", "change", "beforeChange", "afterChange", "changeComplete"],
100
+ slots: Object,
100
101
  setup(l, {
101
102
  attrs: Y,
102
103
  emit: d,
103
- expose: Z
104
+ expose: Z,
105
+ slots: ee
104
106
  }) {
105
- const y = F(), A = F(), E = T("ltr");
106
- ve([() => l.reverse, () => l.vertical], ([e, a]) => {
107
- a ? E.value = e ? "ttb" : "btt" : E.value = e ? "rtl" : "ltr";
107
+ const h = F(), A = F(), B = w("ltr");
108
+ fe([() => l.reverse, () => l.vertical], ([e, a]) => {
109
+ a ? B.value = e ? "ttb" : "btt" : B.value = e ? "rtl" : "ltr";
108
110
  }, {
109
111
  immediate: !0
110
112
  });
111
- const g = T(0), k = T(100), O = T(1), D = F([]), C = F(l.defaultValue || l.value), n = F([]), r = F(), p = F();
112
- 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(() => {
113
115
  const {
114
116
  range: e,
115
117
  min: a,
@@ -117,76 +119,76 @@ const Me = /* @__PURE__ */ de({
117
119
  step: o,
118
120
  pushable: i,
119
121
  marks: b,
120
- allowCross: x,
122
+ allowCross: C,
121
123
  value: v,
122
124
  count: f
123
- } = l, [s, m, L, P, $] = Ce(e);
125
+ } = l, [s, x, L, P, $] = xe(e);
124
126
  r.value = {
125
127
  rangeEnabled: s,
126
- rangeEditable: m,
128
+ rangeEditable: x,
127
129
  rangeDraggableTrack: L,
128
130
  minCount: P,
129
131
  maxCount: $
130
- }, g.value = isFinite(a) ? a : 0, k.value = isFinite(t) ? t : 100, O.value = o !== null && o <= 0 ? 1 : o;
131
- const q = S(() => typeof i == "boolean" ? i ? O.value : !1 : i >= 0 ? i : !1);
132
- D.value = Object.keys(b || {}).map((h) => {
133
- const c = b?.[h], u = {
134
- 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)
135
137
  };
136
- 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;
137
139
  }).filter(({
138
- label: h
139
- }) => h || typeof h == "number").sort((h, c) => h.value - c.value);
140
- const [M, H] = ye(g.value, k.value, O.value, D.value, x, q.value);
141
- p.value = {
142
- 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,
143
145
  offsetValues: H
144
- }, v !== void 0 && (C.value = v);
145
- const ce = S(() => {
146
- const h = C.value === null || C.value === void 0 ? [] : Array.isArray(C.value) ? C.value : [C.value], [c = g.value] = h;
147
- 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];
148
150
  if (s) {
149
- if (u = [...h], f || C.value === void 0) {
150
- const N = f >= 0 ? f + 1 : 2;
151
- 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; )
152
154
  u.push(u[u.length - 1] ?? g.value);
153
155
  }
154
- u.sort((N, z) => N - z);
156
+ u.sort((V, z) => V - z);
155
157
  }
156
- return u.forEach((N, z) => {
157
- u[z] = M(N);
158
+ return u.forEach((V, z) => {
159
+ u[z] = T(V);
158
160
  }), u;
159
161
  });
160
- n.value = ce.value;
162
+ n.value = de.value;
161
163
  });
162
- const V = (e) => r.value.rangeEnabled ? e : e[0], R = (e) => {
164
+ const p = (e) => r.value.rangeEnabled ? e : e[0], R = (e) => {
163
165
  const a = [...e].sort((t, o) => t - o);
164
- ge(a, n.value, !0) || d("change", V(a)), C.value = a;
166
+ be(a, n.value, !0) || d("change", p(a)), y.value = a;
165
167
  }, _ = (e) => {
166
- e && y.value?.hideHelp();
167
- const a = V(n.value);
168
+ e && h.value?.hideHelp();
169
+ const a = p(n.value);
168
170
  l.onAfterChange && (d("afterChange", a), X(!1, "[vc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.")), d("changeComplete", a);
169
- }, ee = (e) => {
171
+ }, ae = (e) => {
170
172
  if (l.disabled || !r.value.rangeEditable || n.value.length <= r.value.minCount)
171
173
  return;
172
174
  const a = [...n.value];
173
- a.splice(e, 1), d("beforeChange", V(a)), R(a);
175
+ a.splice(e, 1), d("beforeChange", p(a)), R(a);
174
176
  const t = Math.max(0, e - 1);
175
- y.value?.hideHelp(), y.value?.focus(t);
176
- }, [G, ae, le, J, K] = he(A, E, n, g, k, p.value.formatValue, R, _, p.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) => {
177
179
  if (!l.disabled) {
178
180
  const t = [...n.value];
179
181
  let o = 0, i = 0, b = k.value - g.value;
180
182
  n.value.forEach((f, s) => {
181
- const m = Math.abs(e - f);
182
- 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);
183
185
  });
184
- let x = o;
185
- 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);
186
- const v = V(t);
187
- d("beforeChange", v), R(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));
188
190
  }
189
- }, te = (e) => {
191
+ }, ne = (e) => {
190
192
  e.preventDefault();
191
193
  const {
192
194
  width: a,
@@ -194,13 +196,13 @@ const Me = /* @__PURE__ */ de({
194
196
  left: o,
195
197
  top: i,
196
198
  bottom: b,
197
- right: x
199
+ right: C
198
200
  } = A.value.getBoundingClientRect(), {
199
201
  clientX: v,
200
202
  clientY: f
201
203
  } = e;
202
204
  let s;
203
- switch (E.value) {
205
+ switch (B.value) {
204
206
  case "btt":
205
207
  s = (b - f) / t;
206
208
  break;
@@ -208,39 +210,39 @@ const Me = /* @__PURE__ */ de({
208
210
  s = (f - i) / t;
209
211
  break;
210
212
  case "rtl":
211
- s = (x - v) / a;
213
+ s = (C - v) / a;
212
214
  break;
213
215
  default:
214
216
  s = (v - o) / a;
215
217
  }
216
- const m = g.value + s * (k.value - g.value);
217
- console.log("click", m, p.value.formatValue(m)), Q(p.value.formatValue(m), e);
218
- }, j = F(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) => {
219
221
  if (!l.disabled) {
220
- const t = p.value.offsetValues(n.value, e, a);
221
- d("beforeChange", V(n.value)), R(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;
222
224
  }
223
225
  };
224
- w(() => {
226
+ M(() => {
225
227
  if (j.value !== null) {
226
228
  const e = n.value.indexOf(j.value);
227
- e >= 0 && y.value?.focus(e);
229
+ e >= 0 && h.value?.focus(e);
228
230
  }
229
231
  j.value = null;
230
232
  });
231
- const ue = S(() => 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) => {
232
- console.log("onStartMove-valueIndex", a), K(e, a), d("beforeChange", V(n.value));
233
- }, re = S(() => G.value !== -1);
234
- w(() => {
235
- if (!re.value) {
236
- const e = n.value.lastIndexOf(ae.value);
237
- 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);
238
240
  }
239
241
  });
240
- const I = S(() => [...J.value].sort((e, a) => e - a)), [oe, se] = S(() => 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;
241
243
  Z({
242
244
  focus: () => {
243
- y.value?.focus(0);
245
+ h.value?.focus(0);
244
246
  },
245
247
  blur: () => {
246
248
  const {
@@ -248,19 +250,19 @@ const Me = /* @__PURE__ */ de({
248
250
  } = document;
249
251
  A.value?.contains(e) && e?.blur();
250
252
  }
251
- }), w(() => {
252
- l.autoFocus && y.value?.focus(0);
253
+ }), M(() => {
254
+ l.autoFocus && h.value?.focus(0);
253
255
  });
254
- const ie = S(() => ({
256
+ const ce = S(() => ({
255
257
  min: g,
256
258
  max: k,
257
- direction: E,
259
+ direction: B,
258
260
  disabled: l.disabled,
259
261
  keyboard: l.keyboard,
260
- step: O,
262
+ step: E,
261
263
  included: l.included,
262
- includedStart: oe,
263
- includedEnd: se,
264
+ includedStart: se,
265
+ includedEnd: ie,
264
266
  range: r.value.rangeEnabled,
265
267
  tabIndex: l.tabIndex,
266
268
  ariaLabelForHandle: l.ariaLabelForHandle,
@@ -270,7 +272,7 @@ const Me = /* @__PURE__ */ de({
270
272
  styles: l.styles || {},
271
273
  classNames: l.classNames || {}
272
274
  }));
273
- return be(ie.value), () => {
275
+ return me(ce.value), () => {
274
276
  const {
275
277
  prefixCls: e = "vc-slider",
276
278
  id: a,
@@ -280,72 +282,72 @@ const Me = /* @__PURE__ */ de({
280
282
  // Style
281
283
  startPoint: i,
282
284
  trackStyle: b,
283
- handleStyle: x,
285
+ handleStyle: C,
284
286
  railStyle: v,
285
287
  dotStyle: f,
286
288
  activeDotStyle: s,
287
289
  // Decorations
288
- dots: m,
290
+ dots: x,
289
291
  handleRender: L,
290
292
  activeHandleRender: P,
291
293
  // Components
292
294
  track: $,
293
295
  classNames: q,
294
- styles: M
296
+ styles: T
295
297
  } = l;
296
- return B("div", {
298
+ return N("div", {
297
299
  ref: A,
298
300
  class: W(e, [Y.class], {
299
301
  [`${e}-disabled`]: t,
300
302
  [`${e}-vertical`]: o,
301
303
  [`${e}-horizontal`]: !o,
302
- [`${e}-with-marks`]: D.value.length
304
+ [`${e}-with-marks`]: O.value.length
303
305
  }),
304
306
  style: Y.style,
305
- onMousedown: te,
307
+ onMousedown: ne,
306
308
  id: a
307
- }, [B("div", {
309
+ }, [N("div", {
308
310
  class: W(`${e}-rail`, q?.rail),
309
311
  style: {
310
312
  ...v,
311
- ...M?.rail
313
+ ...T?.rail
312
314
  }
313
- }, null), $ && B(Se, {
315
+ }, null), $ && N(ke, {
314
316
  prefixCls: e,
315
317
  trackStyle: b,
316
318
  values: n.value,
317
319
  startPoint: i,
318
- onStartMove: ue.value ? U : void 0
319
- }, null), B(Fe, {
320
+ onStartMove: re.value ? U : void 0
321
+ }, null), N(Se, {
320
322
  prefixCls: e,
321
- marks: D.value,
322
- dots: m,
323
+ marks: O.value,
324
+ dots: x,
323
325
  style: f,
324
326
  activeStyle: s
325
- }, null), B(me, {
326
- ref: y,
327
+ }, null), N(he, {
328
+ ref: h,
327
329
  prefixCls: e,
328
- handleStyle: x,
330
+ handleStyle: C,
329
331
  values: J.value,
330
332
  draggingIndex: G.value,
331
- draggingDelete: le.value,
333
+ draggingDelete: te.value,
332
334
  onStartMove: U,
333
- onOffsetChange: ne,
335
+ onOffsetChange: ue,
334
336
  onFocus: (H) => d("focus", H),
335
337
  onBlur: (H) => d("blur", H),
336
338
  handleRender: L,
337
339
  activeHandleRender: P,
338
340
  onChangeComplete: _,
339
- onDelete: r.value.rangeEditable ? ee : () => {
341
+ onDelete: r.value.rangeEditable ? ae : () => {
340
342
  }
341
- }, null), B(xe, {
343
+ }, null), N(Fe, {
342
344
  prefixCls: e,
343
- marks: D.value,
345
+ marks: O.value,
344
346
  onClick: Q
345
- }, null)]);
347
+ }, ee)]);
346
348
  };
347
349
  }
348
350
  });
349
351
  export {
350
- Me as default
352
+ we as default
351
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.1",
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>