@sheinx/hooks 3.9.7-beta.1 → 3.9.7-beta.3

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.
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  declare const useDragMock: (props: {
3
3
  onDragStart?: ((e: React.MouseEvent) => void) | undefined;
4
- onDragMove?: ((deltaX: number, deltaY: number) => void) | undefined;
4
+ onDragMove?: ((deltaX: number, deltaY: number, event?: MouseEvent) => void) | undefined;
5
5
  onDragEnd?: ((deltaX: number, deltaY: number) => void) | undefined;
6
6
  }) => {
7
7
  handleMouseDown: (event: React.MouseEvent) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-drag-mock.d.ts","sourceRoot":"","sources":["use-drag-mock.ts"],"names":[],"mappings":"AACA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,QAAA,MAAM,WAAW;uBACG,gBAAgB,KAAK,IAAI;2BACrB,MAAM,UAAU,MAAM,KAAK,IAAI;0BAChC,MAAM,UAAU,MAAM,KAAK,IAAI;;6BA6BpB,gBAAgB;;CAiBjD,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-drag-mock.d.ts","sourceRoot":"","sources":["use-drag-mock.ts"],"names":[],"mappings":"AACA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,QAAA,MAAM,WAAW;uBACG,gBAAgB,KAAK,IAAI;2BACrB,MAAM,UAAU,MAAM,UAAU,UAAU,KAAK,IAAI;0BACpD,MAAM,UAAU,MAAM,KAAK,IAAI;;6BA6BpB,gBAAgB;;CAiBjD,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -31,7 +31,7 @@ var useDragMock = function useDragMock(props) {
31
31
  var deltaY = event.clientY - dragInfo.lastY;
32
32
  dragInfo.lastX = event.clientX;
33
33
  dragInfo.lastY = event.clientY;
34
- (_props$onDragMove = props.onDragMove) === null || _props$onDragMove === void 0 || _props$onDragMove.call(props, deltaX, deltaY);
34
+ (_props$onDragMove = props.onDragMove) === null || _props$onDragMove === void 0 || _props$onDragMove.call(props, deltaX, deltaY, event);
35
35
  });
36
36
  var handleMouseUp = (0, _usePersistFn.usePersistFn)(function (event) {
37
37
  var _props$onDragEnd;
@@ -1 +1 @@
1
- {"version":3,"file":"use-slider.d.ts","sourceRoot":"","sources":["use-slider.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA4CxD,eAAO,MAAM,SAAS;;kCAyEa,gBAAgB;gCAIlB,gBAAgB;8BAKL,gBAAgB;;;;;;;;;;;;;;;;;;;CA8D3D,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"use-slider.d.ts","sourceRoot":"","sources":["use-slider.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA4CxD,eAAO,MAAM,SAAS;;kCAwHa,gBAAgB;gCAIlB,gBAAgB;8BAKL,gBAAgB;;;;;;;;;;;;;;;;;;;CA2E3D,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -85,6 +85,12 @@ var useSlider = exports.useSlider = function useSlider(props) {
85
85
  context.clickLock = false;
86
86
  }, 100);
87
87
  });
88
+ var isDisabled = (0, _usePersistFn.default)(function (value) {
89
+ if (typeof props.disabled === 'function') {
90
+ return props.disabled(value);
91
+ }
92
+ return !!props.disabled;
93
+ });
88
94
  var handleDragEnd = (0, _usePersistFn.default)(function () {
89
95
  lockClick();
90
96
  var start = getValueFromRate(rate[0], scale, step);
@@ -96,20 +102,56 @@ var useSlider = exports.useSlider = function useSlider(props) {
96
102
  props.onChange(end);
97
103
  }
98
104
  });
99
- var handleDragMove = (0, _usePersistFn.default)(function (deltaX, deltaY) {
105
+ var handleDragMove = (0, _usePersistFn.default)(function (deltaX, deltaY, mouseEvent) {
100
106
  setRate(function (r) {
101
107
  var target = trackRef.current;
102
108
  if (!target) return r;
103
109
  var newRate = _toConsumableArray(r);
104
110
  var v = context.dragIndex === 0 ? r[0] : r[1];
105
- var max = props.vertical ? target.clientHeight : target.clientWidth;
106
- var delta = props.vertical ? deltaY * -1 : deltaX * (isReserve ? -1 : 1);
107
- var rate = Math.max(v + delta / max, 0);
111
+ var rate;
112
+
113
+ // If disabled function is used and we have mouse event, use absolute position
114
+ if (typeof props.disabled === 'function' && mouseEvent) {
115
+ var rect = target.getBoundingClientRect();
116
+ var currentIndicatorRate = v;
117
+
118
+ // Calculate mouse position rate
119
+ var mouseRate;
120
+ if (props.vertical) {
121
+ mouseRate = (rect.bottom - mouseEvent.clientY) / rect.height;
122
+ } else {
123
+ mouseRate = isReserve ? (rect.right - mouseEvent.clientX) / rect.width : (mouseEvent.clientX - rect.left) / rect.width;
124
+ }
125
+
126
+ // Only allow movement if mouse crossed the indicator position
127
+ if (mouseRate > currentIndicatorRate) {
128
+ // Mouse is to the right/top, allow moving right/up
129
+ rate = Math.max(Math.min(mouseRate, 1), 0);
130
+ } else if (mouseRate < currentIndicatorRate) {
131
+ // Mouse is to the left/bottom, allow moving left/down
132
+ rate = Math.max(Math.min(mouseRate, 1), 0);
133
+ } else {
134
+ // Mouse is at same position, no change
135
+ return r;
136
+ }
137
+ } else {
138
+ // Normal delta-based movement
139
+ var max = props.vertical ? target.clientHeight : target.clientWidth;
140
+ var delta = props.vertical ? deltaY * -1 : deltaX * (isReserve ? -1 : 1);
141
+ rate = Math.max(v + delta / max, 0);
142
+ }
108
143
  if (rate > 1) {
109
144
  rate = 1;
110
145
  if (typeof props.onIncrease === 'function') props.onIncrease();
111
146
  }
112
147
  newRate[context.dragIndex] = rate;
148
+
149
+ // Check if the new value would be disabled
150
+ var newValue = getValueFromRate(newRate[context.dragIndex], scale, step);
151
+ if (isDisabled(newValue)) {
152
+ // Stay at current position to prevent flickering
153
+ return r;
154
+ }
113
155
  if (newRate[0] > newRate[1]) {
114
156
  context.dragIndex = context.dragIndex === 0 ? 1 : 0;
115
157
  var temp = newRate[0];
@@ -138,6 +180,9 @@ var useSlider = exports.useSlider = function useSlider(props) {
138
180
  var rect = target.getBoundingClientRect();
139
181
  var rate = !props.vertical ? (isReserve ? rect.right - e.clientX : e.clientX - rect.left) / rect.width : (rect.bottom - e.clientY) / rect.height;
140
182
  var value = getValueFromRate(rate, scale, step);
183
+
184
+ // Check if the clicked value would be disabled
185
+ if (isDisabled(value)) return;
141
186
  if (props.range) {
142
187
  var _start = startValue;
143
188
  var _end = endValue;
@@ -174,8 +219,10 @@ var useSlider = exports.useSlider = function useSlider(props) {
174
219
  handleEndMouseDown: handleEndMouseDown,
175
220
  handleTrackClick: handleTrackClick
176
221
  });
177
- var start = dragInfo.isDragging ? rate[0] : getRateFromValue(startValue, scale);
178
- var end = dragInfo.isDragging ? rate[1] : getRateFromValue(endValue, scale);
222
+
223
+ // During dragging, optionally snap to quantized values in discrete mode
224
+ var start = dragInfo.isDragging ? props.discrete ? getRateFromValue(getValueFromRate(rate[0], scale, step), scale) : rate[0] : getRateFromValue(startValue, scale);
225
+ var end = dragInfo.isDragging ? props.discrete ? getRateFromValue(getValueFromRate(rate[1], scale, step), scale) : rate[1] : getRateFromValue(endValue, scale);
179
226
  var innerStyle = getTrackInnerStyle(start, end);
180
227
  return {
181
228
  func: func,
@@ -7,5 +7,7 @@ export interface UseSliderProps<Value extends number | number[]> {
7
7
  vertical: boolean;
8
8
  onIncrease: (() => void) | undefined;
9
9
  direction?: 'ltr' | 'rtl';
10
+ disabled?: boolean | ((value: number) => boolean);
11
+ discrete?: boolean;
10
12
  }
11
13
  //# sourceMappingURL=use-slider.type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-slider.type.d.ts","sourceRoot":"","sources":["use-slider.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE;IAC7D,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACrC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CAC3B"}
1
+ {"version":3,"file":"use-slider.type.d.ts","sourceRoot":"","sources":["use-slider.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE;IAC7D,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACrC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  declare const useDragMock: (props: {
3
3
  onDragStart?: ((e: React.MouseEvent) => void) | undefined;
4
- onDragMove?: ((deltaX: number, deltaY: number) => void) | undefined;
4
+ onDragMove?: ((deltaX: number, deltaY: number, event?: MouseEvent) => void) | undefined;
5
5
  onDragEnd?: ((deltaX: number, deltaY: number) => void) | undefined;
6
6
  }) => {
7
7
  handleMouseDown: (event: React.MouseEvent) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-drag-mock.d.ts","sourceRoot":"","sources":["use-drag-mock.ts"],"names":[],"mappings":"AACA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,QAAA,MAAM,WAAW;uBACG,gBAAgB,KAAK,IAAI;2BACrB,MAAM,UAAU,MAAM,KAAK,IAAI;0BAChC,MAAM,UAAU,MAAM,KAAK,IAAI;;6BA6BpB,gBAAgB;;CAiBjD,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-drag-mock.d.ts","sourceRoot":"","sources":["use-drag-mock.ts"],"names":[],"mappings":"AACA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,QAAA,MAAM,WAAW;uBACG,gBAAgB,KAAK,IAAI;2BACrB,MAAM,UAAU,MAAM,UAAU,UAAU,KAAK,IAAI;0BACpD,MAAM,UAAU,MAAM,KAAK,IAAI;;6BA6BpB,gBAAgB;;CAiBjD,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -25,7 +25,7 @@ var useDragMock = function useDragMock(props) {
25
25
  var deltaY = event.clientY - dragInfo.lastY;
26
26
  dragInfo.lastX = event.clientX;
27
27
  dragInfo.lastY = event.clientY;
28
- (_props$onDragMove = props.onDragMove) === null || _props$onDragMove === void 0 || _props$onDragMove.call(props, deltaX, deltaY);
28
+ (_props$onDragMove = props.onDragMove) === null || _props$onDragMove === void 0 || _props$onDragMove.call(props, deltaX, deltaY, event);
29
29
  });
30
30
  var handleMouseUp = usePersistFn(function (event) {
31
31
  var _props$onDragEnd;
@@ -1 +1 @@
1
- {"version":3,"file":"use-slider.d.ts","sourceRoot":"","sources":["use-slider.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA4CxD,eAAO,MAAM,SAAS;;kCAyEa,gBAAgB;gCAIlB,gBAAgB;8BAKL,gBAAgB;;;;;;;;;;;;;;;;;;;CA8D3D,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"use-slider.d.ts","sourceRoot":"","sources":["use-slider.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA4CxD,eAAO,MAAM,SAAS;;kCAwHa,gBAAgB;gCAIlB,gBAAgB;8BAKL,gBAAgB;;;;;;;;;;;;;;;;;;;CA2E3D,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -78,6 +78,12 @@ export var useSlider = function useSlider(props) {
78
78
  context.clickLock = false;
79
79
  }, 100);
80
80
  });
81
+ var isDisabled = usePersistFn(function (value) {
82
+ if (typeof props.disabled === 'function') {
83
+ return props.disabled(value);
84
+ }
85
+ return !!props.disabled;
86
+ });
81
87
  var handleDragEnd = usePersistFn(function () {
82
88
  lockClick();
83
89
  var start = getValueFromRate(rate[0], scale, step);
@@ -89,20 +95,56 @@ export var useSlider = function useSlider(props) {
89
95
  props.onChange(end);
90
96
  }
91
97
  });
92
- var handleDragMove = usePersistFn(function (deltaX, deltaY) {
98
+ var handleDragMove = usePersistFn(function (deltaX, deltaY, mouseEvent) {
93
99
  setRate(function (r) {
94
100
  var target = trackRef.current;
95
101
  if (!target) return r;
96
102
  var newRate = _toConsumableArray(r);
97
103
  var v = context.dragIndex === 0 ? r[0] : r[1];
98
- var max = props.vertical ? target.clientHeight : target.clientWidth;
99
- var delta = props.vertical ? deltaY * -1 : deltaX * (isReserve ? -1 : 1);
100
- var rate = Math.max(v + delta / max, 0);
104
+ var rate;
105
+
106
+ // If disabled function is used and we have mouse event, use absolute position
107
+ if (typeof props.disabled === 'function' && mouseEvent) {
108
+ var rect = target.getBoundingClientRect();
109
+ var currentIndicatorRate = v;
110
+
111
+ // Calculate mouse position rate
112
+ var mouseRate;
113
+ if (props.vertical) {
114
+ mouseRate = (rect.bottom - mouseEvent.clientY) / rect.height;
115
+ } else {
116
+ mouseRate = isReserve ? (rect.right - mouseEvent.clientX) / rect.width : (mouseEvent.clientX - rect.left) / rect.width;
117
+ }
118
+
119
+ // Only allow movement if mouse crossed the indicator position
120
+ if (mouseRate > currentIndicatorRate) {
121
+ // Mouse is to the right/top, allow moving right/up
122
+ rate = Math.max(Math.min(mouseRate, 1), 0);
123
+ } else if (mouseRate < currentIndicatorRate) {
124
+ // Mouse is to the left/bottom, allow moving left/down
125
+ rate = Math.max(Math.min(mouseRate, 1), 0);
126
+ } else {
127
+ // Mouse is at same position, no change
128
+ return r;
129
+ }
130
+ } else {
131
+ // Normal delta-based movement
132
+ var max = props.vertical ? target.clientHeight : target.clientWidth;
133
+ var delta = props.vertical ? deltaY * -1 : deltaX * (isReserve ? -1 : 1);
134
+ rate = Math.max(v + delta / max, 0);
135
+ }
101
136
  if (rate > 1) {
102
137
  rate = 1;
103
138
  if (typeof props.onIncrease === 'function') props.onIncrease();
104
139
  }
105
140
  newRate[context.dragIndex] = rate;
141
+
142
+ // Check if the new value would be disabled
143
+ var newValue = getValueFromRate(newRate[context.dragIndex], scale, step);
144
+ if (isDisabled(newValue)) {
145
+ // Stay at current position to prevent flickering
146
+ return r;
147
+ }
106
148
  if (newRate[0] > newRate[1]) {
107
149
  context.dragIndex = context.dragIndex === 0 ? 1 : 0;
108
150
  var temp = newRate[0];
@@ -131,6 +173,9 @@ export var useSlider = function useSlider(props) {
131
173
  var rect = target.getBoundingClientRect();
132
174
  var rate = !props.vertical ? (isReserve ? rect.right - e.clientX : e.clientX - rect.left) / rect.width : (rect.bottom - e.clientY) / rect.height;
133
175
  var value = getValueFromRate(rate, scale, step);
176
+
177
+ // Check if the clicked value would be disabled
178
+ if (isDisabled(value)) return;
134
179
  if (props.range) {
135
180
  var _start = startValue;
136
181
  var _end = endValue;
@@ -167,8 +212,10 @@ export var useSlider = function useSlider(props) {
167
212
  handleEndMouseDown: handleEndMouseDown,
168
213
  handleTrackClick: handleTrackClick
169
214
  });
170
- var start = dragInfo.isDragging ? rate[0] : getRateFromValue(startValue, scale);
171
- var end = dragInfo.isDragging ? rate[1] : getRateFromValue(endValue, scale);
215
+
216
+ // During dragging, optionally snap to quantized values in discrete mode
217
+ var start = dragInfo.isDragging ? props.discrete ? getRateFromValue(getValueFromRate(rate[0], scale, step), scale) : rate[0] : getRateFromValue(startValue, scale);
218
+ var end = dragInfo.isDragging ? props.discrete ? getRateFromValue(getValueFromRate(rate[1], scale, step), scale) : rate[1] : getRateFromValue(endValue, scale);
172
219
  var innerStyle = getTrackInnerStyle(start, end);
173
220
  return {
174
221
  func: func,
@@ -7,5 +7,7 @@ export interface UseSliderProps<Value extends number | number[]> {
7
7
  vertical: boolean;
8
8
  onIncrease: (() => void) | undefined;
9
9
  direction?: 'ltr' | 'rtl';
10
+ disabled?: boolean | ((value: number) => boolean);
11
+ discrete?: boolean;
10
12
  }
11
13
  //# sourceMappingURL=use-slider.type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-slider.type.d.ts","sourceRoot":"","sources":["use-slider.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE;IAC7D,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACrC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CAC3B"}
1
+ {"version":3,"file":"use-slider.type.d.ts","sourceRoot":"","sources":["use-slider.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE;IAC7D,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACrC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.9.7-beta.1",
3
+ "version": "3.9.7-beta.3",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",