@shoplflow/base 0.36.1 → 0.37.1
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/index.cjs +34 -35
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -35
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -6719,13 +6719,13 @@ var generateSteps = (bounds, step, maxSteps = 21) => {
|
|
|
6719
6719
|
var validateRange = ({
|
|
6720
6720
|
min,
|
|
6721
6721
|
max,
|
|
6722
|
-
|
|
6722
|
+
range
|
|
6723
6723
|
}) => {
|
|
6724
|
-
if (
|
|
6725
|
-
throw new Error("
|
|
6724
|
+
if (range.min < min || range.max > max) {
|
|
6725
|
+
throw new Error("range\uAC00 Slider\uC758 \uC804\uCCB4 \uBC94\uC704\uB97C \uBC97\uC5B4\uB0A9\uB2C8\uB2E4.");
|
|
6726
6726
|
}
|
|
6727
|
-
if (
|
|
6728
|
-
throw new Error("
|
|
6727
|
+
if (range.min > range.max) {
|
|
6728
|
+
throw new Error("range\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uD655\uC778\uD574\uC8FC\uC138\uC694.");
|
|
6729
6729
|
}
|
|
6730
6730
|
};
|
|
6731
6731
|
var validateStep = ({ min, max, step }) => {
|
|
@@ -6767,26 +6767,22 @@ var SliderThumbs = ({
|
|
|
6767
6767
|
}
|
|
6768
6768
|
) }, index)) });
|
|
6769
6769
|
};
|
|
6770
|
-
var useSlider = ({ bounds, step,
|
|
6770
|
+
var useSlider = ({ bounds, step, range, handleRange, isDisabled = false }) => {
|
|
6771
6771
|
const { min, max } = bounds;
|
|
6772
|
-
validateRange({ min, max,
|
|
6772
|
+
validateRange({ min, max, range });
|
|
6773
6773
|
validateStep({ min, max, step });
|
|
6774
|
-
const [range, setRange] = React3.useState([defaultRange.min, defaultRange.max]);
|
|
6775
6774
|
const trackRef = React3.useRef(null);
|
|
6776
6775
|
const updateRange = React3.useCallback(
|
|
6777
6776
|
(index, newValue) => {
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
handleRange == null ? void 0 : handleRange({ min: newRange[0], max: newRange[1] });
|
|
6786
|
-
return newRange;
|
|
6787
|
-
});
|
|
6777
|
+
const newRange = [range.min, range.max];
|
|
6778
|
+
if (index === 0) {
|
|
6779
|
+
newRange[0] = Math.min(newValue, newRange[1]);
|
|
6780
|
+
} else if (index === 1) {
|
|
6781
|
+
newRange[1] = Math.max(newValue, newRange[0]);
|
|
6782
|
+
}
|
|
6783
|
+
handleRange == null ? void 0 : handleRange({ min: newRange[0], max: newRange[1] });
|
|
6788
6784
|
},
|
|
6789
|
-
[handleRange]
|
|
6785
|
+
[range, handleRange]
|
|
6790
6786
|
);
|
|
6791
6787
|
const handleMouseDown = React3.useCallback(
|
|
6792
6788
|
(index) => (e) => {
|
|
@@ -6822,8 +6818,8 @@ var useSlider = ({ bounds, step, defaultRange, handleRange, isDisabled = false }
|
|
|
6822
6818
|
const offsetX = e.clientX - rect.left;
|
|
6823
6819
|
const percentage = offsetX / rect.width * 100;
|
|
6824
6820
|
const newValue = getValueFromPercentage(percentage, { min, max }, step);
|
|
6825
|
-
const distanceToStart = Math.abs(getPositionPercentage(0, range, { min, max }) - percentage);
|
|
6826
|
-
const distanceToEnd = Math.abs(getPositionPercentage(1, range, { min, max }) - percentage);
|
|
6821
|
+
const distanceToStart = Math.abs(getPositionPercentage(0, [range.min, range.max], { min, max }) - percentage);
|
|
6822
|
+
const distanceToEnd = Math.abs(getPositionPercentage(1, [range.min, range.max], { min, max }) - percentage);
|
|
6827
6823
|
if (distanceToStart <= distanceToEnd) {
|
|
6828
6824
|
updateRange(0, newValue);
|
|
6829
6825
|
} else {
|
|
@@ -6832,39 +6828,42 @@ var useSlider = ({ bounds, step, defaultRange, handleRange, isDisabled = false }
|
|
|
6832
6828
|
},
|
|
6833
6829
|
[isDisabled, min, max, step, range, updateRange]
|
|
6834
6830
|
);
|
|
6835
|
-
const
|
|
6836
|
-
|
|
6837
|
-
|
|
6831
|
+
const positions = React3.useMemo(() => {
|
|
6832
|
+
const startPosition = getPositionPercentage(0, [range.min, range.max], { min, max });
|
|
6833
|
+
const endPosition = getPositionPercentage(1, [range.min, range.max], { min, max });
|
|
6834
|
+
const width = endPosition - startPosition;
|
|
6835
|
+
return {
|
|
6836
|
+
start: startPosition,
|
|
6837
|
+
end: endPosition,
|
|
6838
|
+
width
|
|
6839
|
+
};
|
|
6840
|
+
}, [range, min, max]);
|
|
6838
6841
|
return {
|
|
6839
|
-
range,
|
|
6842
|
+
selectedRange: [range.min, range.max],
|
|
6840
6843
|
trackRef,
|
|
6841
6844
|
handleMouseDown,
|
|
6842
6845
|
handleClickTrack,
|
|
6843
|
-
positions
|
|
6844
|
-
start: startPosition,
|
|
6845
|
-
end: endPosition,
|
|
6846
|
-
width
|
|
6847
|
-
}
|
|
6846
|
+
positions
|
|
6848
6847
|
};
|
|
6849
6848
|
};
|
|
6850
6849
|
var Slider = ({
|
|
6851
6850
|
min = 0,
|
|
6852
6851
|
max,
|
|
6853
6852
|
step = 1,
|
|
6854
|
-
|
|
6853
|
+
range = { min: 0, max: 0 },
|
|
6855
6854
|
handleRange,
|
|
6856
6855
|
isDisabled = false,
|
|
6857
6856
|
selectedColor = "shopl300"
|
|
6858
6857
|
}) => {
|
|
6859
|
-
const {
|
|
6858
|
+
const { selectedRange, trackRef, handleMouseDown, handleClickTrack, positions } = useSlider({
|
|
6860
6859
|
bounds: { min, max },
|
|
6861
6860
|
step,
|
|
6862
|
-
|
|
6861
|
+
range,
|
|
6863
6862
|
handleRange,
|
|
6864
6863
|
isDisabled
|
|
6865
6864
|
});
|
|
6866
6865
|
return /* @__PURE__ */ jsxRuntime.jsx(SliderContainer, { isDisabled, children: /* @__PURE__ */ jsxRuntime.jsxs(SliderTrack, { ref: trackRef, onClick: handleClickTrack, children: [
|
|
6867
|
-
/* @__PURE__ */ jsxRuntime.jsx(SliderSteps, { bounds: { min, max }, step
|
|
6866
|
+
/* @__PURE__ */ jsxRuntime.jsx(SliderSteps, { bounds: { min, max }, step }),
|
|
6868
6867
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6869
6868
|
SelectedTrack,
|
|
6870
6869
|
{
|
|
@@ -6880,7 +6879,7 @@ var Slider = ({
|
|
|
6880
6879
|
isDisabled,
|
|
6881
6880
|
selectedColor,
|
|
6882
6881
|
onMouseDown: handleMouseDown,
|
|
6883
|
-
values:
|
|
6882
|
+
values: selectedRange
|
|
6884
6883
|
}
|
|
6885
6884
|
)
|
|
6886
6885
|
] }) });
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6692,13 +6692,13 @@ var generateSteps = (bounds, step, maxSteps = 21) => {
|
|
|
6692
6692
|
var validateRange = ({
|
|
6693
6693
|
min,
|
|
6694
6694
|
max,
|
|
6695
|
-
|
|
6695
|
+
range
|
|
6696
6696
|
}) => {
|
|
6697
|
-
if (
|
|
6698
|
-
throw new Error("
|
|
6697
|
+
if (range.min < min || range.max > max) {
|
|
6698
|
+
throw new Error("range\uAC00 Slider\uC758 \uC804\uCCB4 \uBC94\uC704\uB97C \uBC97\uC5B4\uB0A9\uB2C8\uB2E4.");
|
|
6699
6699
|
}
|
|
6700
|
-
if (
|
|
6701
|
-
throw new Error("
|
|
6700
|
+
if (range.min > range.max) {
|
|
6701
|
+
throw new Error("range\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uD655\uC778\uD574\uC8FC\uC138\uC694.");
|
|
6702
6702
|
}
|
|
6703
6703
|
};
|
|
6704
6704
|
var validateStep = ({ min, max, step }) => {
|
|
@@ -6740,26 +6740,22 @@ var SliderThumbs = ({
|
|
|
6740
6740
|
}
|
|
6741
6741
|
) }, index)) });
|
|
6742
6742
|
};
|
|
6743
|
-
var useSlider = ({ bounds, step,
|
|
6743
|
+
var useSlider = ({ bounds, step, range, handleRange, isDisabled = false }) => {
|
|
6744
6744
|
const { min, max } = bounds;
|
|
6745
|
-
validateRange({ min, max,
|
|
6745
|
+
validateRange({ min, max, range });
|
|
6746
6746
|
validateStep({ min, max, step });
|
|
6747
|
-
const [range, setRange] = useState([defaultRange.min, defaultRange.max]);
|
|
6748
6747
|
const trackRef = useRef(null);
|
|
6749
6748
|
const updateRange = useCallback(
|
|
6750
6749
|
(index, newValue) => {
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
handleRange == null ? void 0 : handleRange({ min: newRange[0], max: newRange[1] });
|
|
6759
|
-
return newRange;
|
|
6760
|
-
});
|
|
6750
|
+
const newRange = [range.min, range.max];
|
|
6751
|
+
if (index === 0) {
|
|
6752
|
+
newRange[0] = Math.min(newValue, newRange[1]);
|
|
6753
|
+
} else if (index === 1) {
|
|
6754
|
+
newRange[1] = Math.max(newValue, newRange[0]);
|
|
6755
|
+
}
|
|
6756
|
+
handleRange == null ? void 0 : handleRange({ min: newRange[0], max: newRange[1] });
|
|
6761
6757
|
},
|
|
6762
|
-
[handleRange]
|
|
6758
|
+
[range, handleRange]
|
|
6763
6759
|
);
|
|
6764
6760
|
const handleMouseDown = useCallback(
|
|
6765
6761
|
(index) => (e) => {
|
|
@@ -6795,8 +6791,8 @@ var useSlider = ({ bounds, step, defaultRange, handleRange, isDisabled = false }
|
|
|
6795
6791
|
const offsetX = e.clientX - rect.left;
|
|
6796
6792
|
const percentage = offsetX / rect.width * 100;
|
|
6797
6793
|
const newValue = getValueFromPercentage(percentage, { min, max }, step);
|
|
6798
|
-
const distanceToStart = Math.abs(getPositionPercentage(0, range, { min, max }) - percentage);
|
|
6799
|
-
const distanceToEnd = Math.abs(getPositionPercentage(1, range, { min, max }) - percentage);
|
|
6794
|
+
const distanceToStart = Math.abs(getPositionPercentage(0, [range.min, range.max], { min, max }) - percentage);
|
|
6795
|
+
const distanceToEnd = Math.abs(getPositionPercentage(1, [range.min, range.max], { min, max }) - percentage);
|
|
6800
6796
|
if (distanceToStart <= distanceToEnd) {
|
|
6801
6797
|
updateRange(0, newValue);
|
|
6802
6798
|
} else {
|
|
@@ -6805,39 +6801,42 @@ var useSlider = ({ bounds, step, defaultRange, handleRange, isDisabled = false }
|
|
|
6805
6801
|
},
|
|
6806
6802
|
[isDisabled, min, max, step, range, updateRange]
|
|
6807
6803
|
);
|
|
6808
|
-
const
|
|
6809
|
-
|
|
6810
|
-
|
|
6804
|
+
const positions = useMemo(() => {
|
|
6805
|
+
const startPosition = getPositionPercentage(0, [range.min, range.max], { min, max });
|
|
6806
|
+
const endPosition = getPositionPercentage(1, [range.min, range.max], { min, max });
|
|
6807
|
+
const width = endPosition - startPosition;
|
|
6808
|
+
return {
|
|
6809
|
+
start: startPosition,
|
|
6810
|
+
end: endPosition,
|
|
6811
|
+
width
|
|
6812
|
+
};
|
|
6813
|
+
}, [range, min, max]);
|
|
6811
6814
|
return {
|
|
6812
|
-
range,
|
|
6815
|
+
selectedRange: [range.min, range.max],
|
|
6813
6816
|
trackRef,
|
|
6814
6817
|
handleMouseDown,
|
|
6815
6818
|
handleClickTrack,
|
|
6816
|
-
positions
|
|
6817
|
-
start: startPosition,
|
|
6818
|
-
end: endPosition,
|
|
6819
|
-
width
|
|
6820
|
-
}
|
|
6819
|
+
positions
|
|
6821
6820
|
};
|
|
6822
6821
|
};
|
|
6823
6822
|
var Slider = ({
|
|
6824
6823
|
min = 0,
|
|
6825
6824
|
max,
|
|
6826
6825
|
step = 1,
|
|
6827
|
-
|
|
6826
|
+
range = { min: 0, max: 0 },
|
|
6828
6827
|
handleRange,
|
|
6829
6828
|
isDisabled = false,
|
|
6830
6829
|
selectedColor = "shopl300"
|
|
6831
6830
|
}) => {
|
|
6832
|
-
const {
|
|
6831
|
+
const { selectedRange, trackRef, handleMouseDown, handleClickTrack, positions } = useSlider({
|
|
6833
6832
|
bounds: { min, max },
|
|
6834
6833
|
step,
|
|
6835
|
-
|
|
6834
|
+
range,
|
|
6836
6835
|
handleRange,
|
|
6837
6836
|
isDisabled
|
|
6838
6837
|
});
|
|
6839
6838
|
return /* @__PURE__ */ jsx(SliderContainer, { isDisabled, children: /* @__PURE__ */ jsxs(SliderTrack, { ref: trackRef, onClick: handleClickTrack, children: [
|
|
6840
|
-
/* @__PURE__ */ jsx(SliderSteps, { bounds: { min, max }, step
|
|
6839
|
+
/* @__PURE__ */ jsx(SliderSteps, { bounds: { min, max }, step }),
|
|
6841
6840
|
/* @__PURE__ */ jsx(
|
|
6842
6841
|
SelectedTrack,
|
|
6843
6842
|
{
|
|
@@ -6853,7 +6852,7 @@ var Slider = ({
|
|
|
6853
6852
|
isDisabled,
|
|
6854
6853
|
selectedColor,
|
|
6855
6854
|
onMouseDown: handleMouseDown,
|
|
6856
|
-
values:
|
|
6855
|
+
values: selectedRange
|
|
6857
6856
|
}
|
|
6858
6857
|
)
|
|
6859
6858
|
] }) });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shoplflow/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
"react-dom": "^18.2.0",
|
|
92
92
|
"simplebar-react": "^3.2.6",
|
|
93
93
|
"@shoplflow/hada-assets": "^0.1.3",
|
|
94
|
-
"@shoplflow/
|
|
95
|
-
"@shoplflow/
|
|
94
|
+
"@shoplflow/shopl-assets": "^0.12.4",
|
|
95
|
+
"@shoplflow/utils": "^0.6.5"
|
|
96
96
|
},
|
|
97
97
|
"scripts": {
|
|
98
98
|
"type-check": "tsc --noEmit",
|