@easyv/react-components 0.0.13 → 0.0.15
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/Color/Preview.d.ts +8 -0
- package/dist/Color/Preview.js +78 -0
- package/dist/Color/Preview.less +48 -0
- package/dist/Color/index.d.ts +2 -0
- package/dist/Color/index.js +69 -0
- package/dist/Color/interface.d.ts +5 -0
- package/dist/Color/interface.js +1 -0
- package/dist/ColorPicker/Panel.d.ts +11 -0
- package/dist/ColorPicker/Panel.js +50 -0
- package/dist/ColorPicker/Panel.less +159 -0
- package/dist/ColorPicker/index.d.ts +9 -3
- package/dist/ColorPicker/index.js +266 -44
- package/dist/ColorPicker/index.less +194 -132
- package/dist/ColorPicker/utils.d.ts +16 -6
- package/dist/ColorPicker/utils.js +86 -40
- package/dist/Input/index.js +15 -14
- package/dist/InputNumber/PointDrag.d.ts +13 -0
- package/dist/InputNumber/PointDrag.js +107 -0
- package/dist/InputNumber/index.d.ts +3 -1
- package/dist/InputNumber/index.js +183 -1
- package/dist/InputNumber/index.less +93 -0
- package/dist/InputNumber/interface.d.ts +6 -1
- package/dist/InputNumber/util.d.ts +8 -0
- package/dist/InputNumber/util.js +31 -0
- package/dist/RangeColor/Panel.d.ts +9 -0
- package/dist/RangeColor/Panel.js +187 -0
- package/dist/RangeColor/Panel.less +0 -0
- package/dist/RangeColor/Points.d.ts +2 -0
- package/dist/RangeColor/Points.js +88 -0
- package/dist/RangeColor/index.d.ts +3 -0
- package/dist/RangeColor/index.js +76 -0
- package/dist/RangeColor/index.less +49 -0
- package/dist/RangeColor/interface.d.ts +8 -0
- package/dist/RangeColor/interface.js +1 -0
- package/dist/SpaceModal/index.d.ts +5 -0
- package/dist/SpaceModal/index.js +19 -0
- package/dist/SpaceModal/index.less +5 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useClickOutside.d.ts +1 -0
- package/dist/hooks/useClickOutside.js +16 -0
- package/dist/hooks/useEventListener.d.ts +1 -0
- package/dist/hooks/useEventListener.js +18 -0
- package/dist/index.css +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/package.json +2 -2
- package/dist/ColorPicker/ColorPreview.d.ts +0 -19
- package/dist/ColorPicker/ColorPreview.js +0 -27
- package/dist/ColorPicker/ColorPreview.less +0 -5
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
export declare function resolveColor(color: string): {
|
|
2
|
+
r?: undefined;
|
|
3
|
+
g?: undefined;
|
|
4
|
+
b?: undefined;
|
|
5
|
+
a?: undefined;
|
|
6
|
+
hex?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
r: any;
|
|
9
|
+
g: any;
|
|
10
|
+
b: any;
|
|
11
|
+
a: any;
|
|
12
|
+
hex: string;
|
|
13
|
+
};
|
|
1
14
|
export declare function toHex(x: any): string;
|
|
2
|
-
export declare function transformColor(color:
|
|
3
|
-
export declare function getBackgroundAccordingColor(color: any, fixedAngle
|
|
15
|
+
export declare function transformColor(color: any, a: any): string | undefined;
|
|
16
|
+
export declare function getBackgroundAccordingColor(color: any, fixedAngle?: number): {
|
|
4
17
|
backgroundImage: string;
|
|
5
18
|
background?: undefined;
|
|
6
19
|
} | {
|
|
7
20
|
background: any;
|
|
8
21
|
backgroundImage?: undefined;
|
|
9
22
|
} | undefined;
|
|
10
|
-
export declare function getMiddleColor(colors:
|
|
11
|
-
color: string;
|
|
12
|
-
offset: number;
|
|
13
|
-
}[], offset: number): string;
|
|
23
|
+
export declare function getMiddleColor(colors: any, offset: any): any;
|
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
|
|
2
|
+
export function resolveColor(color) {
|
|
3
|
+
if (!color || typeof color !== 'string') {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// 转为小写并去除空格
|
|
8
|
+
color = color.toLowerCase().replace(/\s+/g, '');
|
|
9
|
+
var hexReg = /^#([0-9|a-f]{3}|[0-9|a-f]{6})$/;
|
|
10
|
+
var rgbReg = /^(rgb\(\d+,\d+,\d+\)|rgba\(\d+,\d+,\d+,(\d+)?(\.)?(\d+)?\))$/;
|
|
11
|
+
// const rgbReg1 = /^(rgb\(\d+,\d+,\d+\)|rgba\((\d+)?(\.)?(\d+)?,(\d+)?(\.)?(\d+)?,(\d+)?(\.)?(\d+)?,(\d+)?(\.)?(\d+)?\))$/;
|
|
12
|
+
|
|
13
|
+
var r, g, b, a;
|
|
14
|
+
if (hexReg.test(color)) {
|
|
15
|
+
if (color.length === 4) {
|
|
16
|
+
r = parseInt(color.slice(1, 2) + color.slice(1, 2), 16);
|
|
17
|
+
g = parseInt(color.slice(2, 3) + color.slice(2, 3), 16);
|
|
18
|
+
b = parseInt(color.slice(3, 4) + color.slice(3, 4), 16);
|
|
19
|
+
} else {
|
|
20
|
+
r = parseInt(color.slice(1, 3), 16);
|
|
21
|
+
g = parseInt(color.slice(3, 5), 16);
|
|
22
|
+
b = parseInt(color.slice(5, 7), 16);
|
|
23
|
+
}
|
|
24
|
+
a = 1;
|
|
25
|
+
} else if (rgbReg.test(color)) {
|
|
26
|
+
var colors = color.replace(/rgba|rgb|\(|\)/g, '').split(',');
|
|
27
|
+
r = Number(colors[0]);
|
|
28
|
+
g = Number(colors[1]);
|
|
29
|
+
b = Number(colors[2]);
|
|
30
|
+
a = colors.length === 4 ? Number(colors[3]) : 1;
|
|
31
|
+
} else {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// return { r: Math.floor(r), g: Math.floor(g), b: Math.floor(b), a, hex: `#${toHex(r)}${toHex(g)}${toHex(b)}` };
|
|
36
|
+
return {
|
|
37
|
+
r: r,
|
|
38
|
+
g: g,
|
|
39
|
+
b: b,
|
|
40
|
+
a: a,
|
|
41
|
+
hex: "#".concat(toHex(r)).concat(toHex(g)).concat(toHex(b))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
3
44
|
export function toHex(x) {
|
|
4
45
|
return ('0' + parseInt(x).toString(16)).slice(-2);
|
|
5
46
|
}
|
|
6
47
|
export function transformColor(color, a) {
|
|
7
|
-
var
|
|
8
|
-
r =
|
|
9
|
-
g =
|
|
10
|
-
b =
|
|
11
|
-
|
|
12
|
-
return a === 1 ?
|
|
48
|
+
var _resolveColor = resolveColor(color),
|
|
49
|
+
r = _resolveColor.r,
|
|
50
|
+
g = _resolveColor.g,
|
|
51
|
+
b = _resolveColor.b,
|
|
52
|
+
hex = _resolveColor.hex;
|
|
53
|
+
return a === 1 ? hex : "RGBA(".concat(r, ",").concat(g, ",").concat(b, ",").concat(a, ")");
|
|
13
54
|
}
|
|
14
55
|
export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
15
56
|
if (typeof color === 'string') {
|
|
@@ -22,19 +63,19 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
22
63
|
return a.offset - b.offset;
|
|
23
64
|
});
|
|
24
65
|
var colors = rebaseStops.map(function (item, index) {
|
|
25
|
-
var
|
|
26
|
-
r =
|
|
27
|
-
g =
|
|
28
|
-
b =
|
|
29
|
-
a =
|
|
66
|
+
var _resolveColor2 = resolveColor(item.color),
|
|
67
|
+
r = _resolveColor2.r,
|
|
68
|
+
g = _resolveColor2.g,
|
|
69
|
+
b = _resolveColor2.b,
|
|
70
|
+
a = _resolveColor2.a;
|
|
30
71
|
if (a === 1 || index === rebaseStops.length - 1) {
|
|
31
72
|
return "".concat(item.color, " ").concat(item.offset, "%");
|
|
32
73
|
} else {
|
|
33
|
-
var
|
|
34
|
-
nextR =
|
|
35
|
-
nextG =
|
|
36
|
-
nextB =
|
|
37
|
-
nextA =
|
|
74
|
+
var _resolveColor3 = resolveColor(rebaseStops[index + 1].color),
|
|
75
|
+
nextR = _resolveColor3.r,
|
|
76
|
+
nextG = _resolveColor3.g,
|
|
77
|
+
nextB = _resolveColor3.b,
|
|
78
|
+
nextA = _resolveColor3.a;
|
|
38
79
|
var stepOpacity = (nextA - a) / 5;
|
|
39
80
|
var stepOffset = (rebaseStops[index + 1].offset - item.offset) / 5;
|
|
40
81
|
var stepR = (nextR - r) / 5;
|
|
@@ -76,19 +117,19 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
76
117
|
return a.offset - b.offset;
|
|
77
118
|
});
|
|
78
119
|
var _colors = _rebaseStops.map(function (item, index) {
|
|
79
|
-
var
|
|
80
|
-
r =
|
|
81
|
-
g =
|
|
82
|
-
b =
|
|
83
|
-
a =
|
|
120
|
+
var _resolveColor4 = resolveColor(item.color),
|
|
121
|
+
r = _resolveColor4.r,
|
|
122
|
+
g = _resolveColor4.g,
|
|
123
|
+
b = _resolveColor4.b,
|
|
124
|
+
a = _resolveColor4.a;
|
|
84
125
|
if (a === 1 || index === _rebaseStops.length - 1) {
|
|
85
126
|
return "".concat(transformColor(item.color, a * opacity), " ").concat(item.offset, "%");
|
|
86
127
|
} else {
|
|
87
|
-
var
|
|
88
|
-
nextR =
|
|
89
|
-
nextG =
|
|
90
|
-
nextB =
|
|
91
|
-
nextA =
|
|
128
|
+
var _resolveColor5 = resolveColor(_rebaseStops[index + 1].color),
|
|
129
|
+
nextR = _resolveColor5.r,
|
|
130
|
+
nextG = _resolveColor5.g,
|
|
131
|
+
nextB = _resolveColor5.b,
|
|
132
|
+
nextA = _resolveColor5.a;
|
|
92
133
|
var stepOpacity = (nextA - a) / 5;
|
|
93
134
|
var stepOffset = (_rebaseStops[index + 1].offset - item.offset) / 5;
|
|
94
135
|
var stepR = (nextR - r) / 5;
|
|
@@ -102,7 +143,7 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
102
143
|
}
|
|
103
144
|
});
|
|
104
145
|
return {
|
|
105
|
-
backgroundImage: "linear-gradient(".concat(fixedAngle
|
|
146
|
+
backgroundImage: "linear-gradient(".concat(fixedAngle != undefined ? fixedAngle : angle, "deg, ").concat(_colors.join(','), ")")
|
|
106
147
|
};
|
|
107
148
|
} else {
|
|
108
149
|
return {
|
|
@@ -112,8 +153,7 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
112
153
|
}
|
|
113
154
|
}
|
|
114
155
|
export function getMiddleColor(colors, offset) {
|
|
115
|
-
var leftColor;
|
|
116
|
-
var rightColor;
|
|
156
|
+
var leftColor, rightColor;
|
|
117
157
|
var leftColors = colors.filter(function (d) {
|
|
118
158
|
return d.offset < offset;
|
|
119
159
|
});
|
|
@@ -138,16 +178,22 @@ export function getMiddleColor(colors, offset) {
|
|
|
138
178
|
if (!rightColor) {
|
|
139
179
|
return leftColor.color;
|
|
140
180
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
181
|
+
|
|
182
|
+
// console.log(leftColor, rightColor, leftColors, rightColors, '计算color');
|
|
183
|
+
|
|
184
|
+
var _resolveColor6 = resolveColor(leftColor.color),
|
|
185
|
+
leftR = _resolveColor6.r,
|
|
186
|
+
leftG = _resolveColor6.g,
|
|
187
|
+
leftB = _resolveColor6.b,
|
|
188
|
+
leftA = _resolveColor6.a;
|
|
189
|
+
var _resolveColor7 = resolveColor(rightColor.color),
|
|
190
|
+
rightR = _resolveColor7.r,
|
|
191
|
+
rightG = _resolveColor7.g,
|
|
192
|
+
rightB = _resolveColor7.b,
|
|
193
|
+
rightA = _resolveColor7.a;
|
|
194
|
+
|
|
195
|
+
// console.log(resolveColor(leftColor.color), resolveColor(rightColor.color), '计算color');
|
|
196
|
+
|
|
151
197
|
var newR = Math.round((rightR - leftR) / (rightColor.offset - leftColor.offset) * (offset - leftColor.offset) + leftR);
|
|
152
198
|
var newG = Math.round((rightG - leftG) / (rightColor.offset - leftColor.offset) * (offset - leftColor.offset) + leftG);
|
|
153
199
|
var newB = Math.round((rightB - leftB) / (rightColor.offset - leftColor.offset) * (offset - leftColor.offset) + leftB);
|
package/dist/Input/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
var _excluded = ["value", "defaultValue", "enableEmpty", "autoSelect", "changeOnBlur", "onPressEnter", "onFocus"],
|
|
2
|
+
var _excluded = ["value", "defaultValue", "enableEmpty", "autoSelect", "changeOnBlur", "onPressEnter", "onFocus", "onBlur", "onChange"],
|
|
3
3
|
_excluded2 = ["onSearch"];
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -20,6 +20,7 @@ import { SearchCircleOutlined } from '@easyv/react-icons';
|
|
|
20
20
|
import "./index.less";
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
22
|
var XInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
23
|
+
var _halfControlledProps;
|
|
23
24
|
var value = props.value,
|
|
24
25
|
defaultValue = props.defaultValue,
|
|
25
26
|
enableEmpty = props.enableEmpty,
|
|
@@ -27,9 +28,9 @@ var XInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
27
28
|
changeOnBlur = props.changeOnBlur,
|
|
28
29
|
onPressEnter = props.onPressEnter,
|
|
29
30
|
onFocus = props.onFocus,
|
|
31
|
+
onBlur = props.onBlur,
|
|
32
|
+
onChange = props.onChange,
|
|
30
33
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
31
|
-
var onBlur = restProps.onBlur,
|
|
32
|
-
onChange = restProps.onChange;
|
|
33
34
|
|
|
34
35
|
// 用于 changeOnBlur 为 true 的模式,组件内存储,在失焦的时候,提交这个值
|
|
35
36
|
var _useState = useState('value' in props ? value : defaultValue),
|
|
@@ -77,20 +78,20 @@ var XInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
77
78
|
}
|
|
78
79
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
79
80
|
}, [value, onBlur]);
|
|
80
|
-
var halfControlledProps = {
|
|
81
|
-
|
|
82
|
-
onChange: handleChange,
|
|
83
|
-
onBlur: handleBlur
|
|
84
|
-
};
|
|
85
|
-
return /*#__PURE__*/_jsx(Input, _objectSpread({
|
|
81
|
+
var halfControlledProps = (_halfControlledProps = {}, _defineProperty(_halfControlledProps, 'value' in props ? 'value' : 'defaultValue', localValue), _defineProperty(_halfControlledProps, "onChange", handleChange), _defineProperty(_halfControlledProps, "onBlur", handleBlur), _halfControlledProps);
|
|
82
|
+
return /*#__PURE__*/_jsx(Input, _objectSpread(_objectSpread({
|
|
86
83
|
ref: ref,
|
|
87
84
|
onPressEnter: handlePressEnter,
|
|
88
85
|
onFocus: handleFocus
|
|
89
|
-
}, changeOnBlur ? halfControlledProps : 'value' in props ?
|
|
90
|
-
value: value
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
86
|
+
}, changeOnBlur ? halfControlledProps : 'value' in props ? {
|
|
87
|
+
value: value,
|
|
88
|
+
onBlur: onBlur,
|
|
89
|
+
onChange: onChange
|
|
90
|
+
} : {
|
|
91
|
+
defaultValue: defaultValue,
|
|
92
|
+
onBlur: onBlur,
|
|
93
|
+
onChange: onChange
|
|
94
|
+
}), restProps));
|
|
94
95
|
});
|
|
95
96
|
var InputSearch = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
96
97
|
var onSearch = _ref.onSearch,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface PointDragProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
onMoveStart?: () => void;
|
|
5
|
+
onMove?: ({ movementX }: {
|
|
6
|
+
movementX: number;
|
|
7
|
+
}) => void;
|
|
8
|
+
onMoveEnd?: ({ movementX }: {
|
|
9
|
+
movementX: number;
|
|
10
|
+
}) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function PointerDrag({ children, onMoveStart, onMove, onMoveEnd, }: PointDragProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import React, { Fragment, cloneElement, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
export function PointerDrag(_ref) {
|
|
11
|
+
var children = _ref.children,
|
|
12
|
+
onMoveStart = _ref.onMoveStart,
|
|
13
|
+
onMove = _ref.onMove,
|
|
14
|
+
onMoveEnd = _ref.onMoveEnd;
|
|
15
|
+
var _useState = useState(false),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
dragging = _useState2[0],
|
|
18
|
+
setDrag = _useState2[1];
|
|
19
|
+
var _useState3 = useState({
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 0
|
|
22
|
+
}),
|
|
23
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
24
|
+
position = _useState4[0],
|
|
25
|
+
setPosition = _useState4[1];
|
|
26
|
+
var windowSize = useMemo(function () {
|
|
27
|
+
return {
|
|
28
|
+
width: document.body.clientWidth,
|
|
29
|
+
height: document.body.clientHeight
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
var moveDistance = useRef(0);
|
|
33
|
+
var onMouseDown = function onMouseDown(e) {
|
|
34
|
+
e.target.requestPointerLock();
|
|
35
|
+
setPosition({
|
|
36
|
+
x: e.clientX,
|
|
37
|
+
y: e.clientY
|
|
38
|
+
});
|
|
39
|
+
setDrag(true);
|
|
40
|
+
moveDistance.current = 0;
|
|
41
|
+
onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart();
|
|
42
|
+
};
|
|
43
|
+
var _onMouseMove = function onMouseMove(e) {
|
|
44
|
+
if (dragging) {
|
|
45
|
+
setPosition(function (prev) {
|
|
46
|
+
var nextX = prev.x + e.movementX;
|
|
47
|
+
nextX = nextX + 10 * windowSize.width % windowSize.width;
|
|
48
|
+
return {
|
|
49
|
+
x: nextX,
|
|
50
|
+
y: prev.y
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
// 记录移动距离
|
|
54
|
+
moveDistance.current = moveDistance.current + e.movementX;
|
|
55
|
+
onMove === null || onMove === void 0 ? void 0 : onMove({
|
|
56
|
+
movementX: moveDistance.current
|
|
57
|
+
});
|
|
58
|
+
} else if (Math.abs(e.movementX) >= 1 && e.buttons) {
|
|
59
|
+
onMouseDown(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var onMouseUp = function onMouseUp() {
|
|
63
|
+
if (dragging) {
|
|
64
|
+
document.exitPointerLock();
|
|
65
|
+
setDrag(false);
|
|
66
|
+
onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
67
|
+
movementX: moveDistance.current
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var arrow = /*#__PURE__*/_jsx("svg", {
|
|
72
|
+
width: 46,
|
|
73
|
+
height: 15,
|
|
74
|
+
style: {
|
|
75
|
+
position: 'fixed',
|
|
76
|
+
left: position.x,
|
|
77
|
+
top: position.y,
|
|
78
|
+
width: 46,
|
|
79
|
+
height: 15,
|
|
80
|
+
zIndex: 1,
|
|
81
|
+
transform: 'translate(-50%, -50%)'
|
|
82
|
+
},
|
|
83
|
+
children: /*#__PURE__*/_jsxs("g", {
|
|
84
|
+
transform: "translate(2 3)",
|
|
85
|
+
children: [/*#__PURE__*/_jsx("path", {
|
|
86
|
+
fillRule: "evenodd",
|
|
87
|
+
d: "M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z",
|
|
88
|
+
stroke: "#fafafa",
|
|
89
|
+
style: {
|
|
90
|
+
strokeWidth: 2
|
|
91
|
+
}
|
|
92
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
93
|
+
fillRule: "evenodd",
|
|
94
|
+
d: "M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z"
|
|
95
|
+
})]
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
return /*#__PURE__*/_jsxs(Fragment, {
|
|
99
|
+
children: [children && /*#__PURE__*/cloneElement(children, {
|
|
100
|
+
onMouseMove: function onMouseMove(e) {
|
|
101
|
+
e.persist();
|
|
102
|
+
_onMouseMove(e);
|
|
103
|
+
},
|
|
104
|
+
onMouseUp: onMouseUp
|
|
105
|
+
}), dragging && arrow]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { InputNumberProps } from './interface';
|
|
2
3
|
import './index.less';
|
|
4
|
+
declare const InputNumber: import("react").ForwardRefExoticComponent<InputNumberProps & import("react").RefAttributes<unknown>>;
|
|
3
5
|
export default InputNumber;
|
|
4
6
|
export type * from './interface';
|
|
@@ -1,3 +1,185 @@
|
|
|
1
|
-
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _excluded = ["min", "max", "step", "precision", "value", "defaultValue", "prefix", "suffix", "hideControl", "onChange"];
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
17
|
+
import { DownOutlined, UpOutlined } from '@easyv/react-icons';
|
|
18
|
+
import Input from "../Input";
|
|
19
|
+
import { getSafeValue, evaluateExpression } from "./util";
|
|
20
|
+
import { PointerDrag } from "./PointDrag";
|
|
2
21
|
import "./index.less";
|
|
22
|
+
import classNames from 'classnames';
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
|
+
var valueRegx = /^[0-9().+\-*/]+$/;
|
|
26
|
+
var InputNumber = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
27
|
+
var min = props.min,
|
|
28
|
+
max = props.max,
|
|
29
|
+
_props$step = props.step,
|
|
30
|
+
step = _props$step === void 0 ? 1 : _props$step,
|
|
31
|
+
precision = props.precision,
|
|
32
|
+
value = props.value,
|
|
33
|
+
defaultValue = props.defaultValue,
|
|
34
|
+
prefix = props.prefix,
|
|
35
|
+
suffix = props.suffix,
|
|
36
|
+
hideControl = props.hideControl,
|
|
37
|
+
onChange = props.onChange,
|
|
38
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
39
|
+
var getPropsValue = function getPropsValue() {
|
|
40
|
+
if ('value' in props) {
|
|
41
|
+
return value === undefined ? value : value.toString();
|
|
42
|
+
} else {
|
|
43
|
+
return defaultValue === undefined ? defaultValue : defaultValue.toString();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var _useState = useState(getPropsValue),
|
|
47
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
48
|
+
localValue = _useState2[0],
|
|
49
|
+
setLocalValue = _useState2[1];
|
|
50
|
+
|
|
51
|
+
// 给拖拽滑动改变数值使用
|
|
52
|
+
var dragRef = useRef(false);
|
|
53
|
+
var originValue = useRef();
|
|
54
|
+
useEffect(function () {
|
|
55
|
+
// 拖拽过程中禁止更新
|
|
56
|
+
if (!dragRef.current && value !== localValue) {
|
|
57
|
+
setLocalValue(getPropsValue());
|
|
58
|
+
}
|
|
59
|
+
}, [value]);
|
|
60
|
+
|
|
61
|
+
// 只允许输入数字和(.+-*/)
|
|
62
|
+
var handleChange = useCallback(function (value) {
|
|
63
|
+
if (value === '' || valueRegx.test(value)) {
|
|
64
|
+
setLocalValue(value);
|
|
65
|
+
}
|
|
66
|
+
}, []);
|
|
67
|
+
var handleBlur = function handleBlur() {
|
|
68
|
+
if (localValue !== undefined) {
|
|
69
|
+
var result = evaluateExpression(localValue);
|
|
70
|
+
if (isNaN(result)) {
|
|
71
|
+
setLocalValue(getPropsValue());
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
result = getSafeValue(result, {
|
|
75
|
+
min: min,
|
|
76
|
+
max: max,
|
|
77
|
+
precision: precision
|
|
78
|
+
});
|
|
79
|
+
setLocalValue(result.toString());
|
|
80
|
+
if (result !== value) {
|
|
81
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(result);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var handleMoveStart = function handleMoveStart() {
|
|
86
|
+
dragRef.current = true;
|
|
87
|
+
var initValue = getPropsValue();
|
|
88
|
+
originValue.current = initValue === undefined ? undefined : isNaN(Number(initValue)) ? undefined : Number(initValue);
|
|
89
|
+
};
|
|
90
|
+
var handlePointMove = function handlePointMove(_ref) {
|
|
91
|
+
var movementX = _ref.movementX;
|
|
92
|
+
var initNumberValue = originValue.current;
|
|
93
|
+
if (initNumberValue === undefined) {
|
|
94
|
+
initNumberValue = 0;
|
|
95
|
+
}
|
|
96
|
+
var result = initNumberValue + Math.floor(movementX / 2) * step;
|
|
97
|
+
result = getSafeValue(result, {
|
|
98
|
+
min: min,
|
|
99
|
+
max: max,
|
|
100
|
+
precision: precision
|
|
101
|
+
});
|
|
102
|
+
setLocalValue(result.toString());
|
|
103
|
+
if (result !== originValue.current) {
|
|
104
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(result);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var handlePointMoveEnd = function handlePointMoveEnd() {
|
|
108
|
+
dragRef.current = false;
|
|
109
|
+
};
|
|
110
|
+
var handleCountUp = function handleCountUp() {
|
|
111
|
+
if (props.disabled) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var result = localValue === undefined ? 0 : isNaN(Number(localValue)) ? 0 : Number(localValue);
|
|
115
|
+
result += step;
|
|
116
|
+
result = getSafeValue(result, {
|
|
117
|
+
min: min,
|
|
118
|
+
max: max,
|
|
119
|
+
precision: precision
|
|
120
|
+
});
|
|
121
|
+
setLocalValue(result.toString());
|
|
122
|
+
if (result !== value) {
|
|
123
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(result);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var handleCountDown = function handleCountDown() {
|
|
127
|
+
if (props.disabled) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
var result = localValue === undefined ? 0 : isNaN(Number(localValue)) ? 0 : Number(localValue);
|
|
131
|
+
result -= step;
|
|
132
|
+
result = getSafeValue(result, {
|
|
133
|
+
min: min,
|
|
134
|
+
max: max,
|
|
135
|
+
precision: precision
|
|
136
|
+
});
|
|
137
|
+
setLocalValue(result.toString());
|
|
138
|
+
if (result !== value) {
|
|
139
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(result);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return /*#__PURE__*/_jsx(Input, _objectSpread({
|
|
143
|
+
autoSelect: true,
|
|
144
|
+
ref: ref,
|
|
145
|
+
className: "arco-input-number",
|
|
146
|
+
onChange: handleChange,
|
|
147
|
+
onBlur: handleBlur,
|
|
148
|
+
value: localValue,
|
|
149
|
+
prefix: !props.disabled && !props.readOnly ? /*#__PURE__*/_jsx(PointerDrag, {
|
|
150
|
+
onMoveStart: handleMoveStart,
|
|
151
|
+
onMove: handlePointMove,
|
|
152
|
+
onMoveEnd: handlePointMoveEnd,
|
|
153
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
154
|
+
className: "arco-input-number-prefix-inner",
|
|
155
|
+
children: prefix
|
|
156
|
+
})
|
|
157
|
+
}) : /*#__PURE__*/_jsx("span", {
|
|
158
|
+
className: "arco-input-number-prefix-inner",
|
|
159
|
+
children: prefix
|
|
160
|
+
}),
|
|
161
|
+
suffix: /*#__PURE__*/_jsxs("div", {
|
|
162
|
+
className: "arco-input-number-suffix-inner",
|
|
163
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
164
|
+
className: "arco-input-number-suffix-icon",
|
|
165
|
+
children: suffix
|
|
166
|
+
}), !hideControl && !props.disabled && !props.readOnly && /*#__PURE__*/_jsxs("div", {
|
|
167
|
+
className: "arco-input-number-step",
|
|
168
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
169
|
+
className: classNames('arco-input-number-handle-up', {
|
|
170
|
+
'arco-input-number-handle-disabled': localValue !== undefined && max !== undefined && +localValue >= max
|
|
171
|
+
}),
|
|
172
|
+
onClick: handleCountUp,
|
|
173
|
+
children: /*#__PURE__*/_jsx(UpOutlined, {})
|
|
174
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
175
|
+
className: classNames('arco-input-number-handle-down', {
|
|
176
|
+
'arco-input-number-handle-disabled': localValue !== undefined && min !== undefined && +localValue <= min
|
|
177
|
+
}),
|
|
178
|
+
onClick: handleCountDown,
|
|
179
|
+
children: /*#__PURE__*/_jsx(DownOutlined, {})
|
|
180
|
+
})]
|
|
181
|
+
})]
|
|
182
|
+
})
|
|
183
|
+
}, restProps));
|
|
184
|
+
});
|
|
3
185
|
export default InputNumber;
|