bj-web-components 0.2.28 → 0.2.30
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.js +1 -51
- package/dist/index.mjs +49 -49
- package/dist/style.css +1 -3744
- package/dist/web/BasicInput/BInput.js +1 -208
- package/dist/web/BasicInput/BInput.mjs +132 -164
- package/dist/web/BasicInput/utils.js +1 -47
- package/dist/web/BasicInput/utils.mjs +28 -38
- package/dist/web/CategoryDropdown/CategoryDropdown.js +1 -307
- package/dist/web/CategoryDropdown/CategoryDropdown.mjs +170 -218
- package/dist/web/CheckBox/BCheckBox.js +1 -116
- package/dist/web/CheckBox/BCheckBox.mjs +70 -86
- package/dist/web/CheckBox/Group.js +1 -73
- package/dist/web/CheckBox/Group.mjs +56 -63
- package/dist/web/CheckBox/context.js +1 -5
- package/dist/web/CheckBox/context.mjs +3 -3
- package/dist/web/CheckBox/index.js +1 -8
- package/dist/web/CheckBox/index.mjs +6 -6
- package/dist/web/Dropdown/BDropdown.js +1 -186
- package/dist/web/Dropdown/BDropdown.mjs +106 -132
- package/dist/web/EmptyInputBox/EmptyInputBox.js +1 -77
- package/dist/web/EmptyInputBox/EmptyInputBox.mjs +48 -52
- package/dist/web/FileCard/FileCard.js +1 -157
- package/dist/web/FileCard/FileCard.mjs +82 -112
- package/dist/web/Icon/Icon.js +1 -9
- package/dist/web/Icon/Icon.mjs +6 -6
- package/dist/web/Input/Input.js +1 -181
- package/dist/web/Input/Input.mjs +113 -122
- package/dist/web/InputNumber/BInputNumber.js +1 -311
- package/dist/web/InputNumber/BInputNumber.mjs +167 -275
- package/dist/web/InputNumber/StepHandler.js +1 -69
- package/dist/web/InputNumber/StepHandler.mjs +32 -38
- package/dist/web/InputNumber/hooks/useCursor.js +1 -40
- package/dist/web/InputNumber/hooks/useCursor.mjs +33 -35
- package/dist/web/InputNumber/hooks/useFrame.js +1 -12
- package/dist/web/InputNumber/hooks/useFrame.mjs +6 -9
- package/dist/web/InputNumber/utils/decimal.js +1 -147
- package/dist/web/InputNumber/utils/decimal.mjs +81 -109
- package/dist/web/Modal/Modal.js +1 -84
- package/dist/web/Modal/Modal.mjs +49 -52
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +1 -232
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +125 -206
- package/dist/web/Pagination/Pagination.js +1 -328
- package/dist/web/Pagination/Pagination.mjs +178 -254
- package/dist/web/ProductField/ProductField.js +1 -272
- package/dist/web/ProductField/ProductField.mjs +143 -190
- package/dist/web/ProductField/arrow-up.svg.js +1 -3
- package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-no.svg.js +1 -3
- package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-ok.svg.js +1 -3
- package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
- package/dist/web/ProductField/no_data_light.svg.js +1 -3
- package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
- package/dist/web/ProductField/search.svg.js +1 -3
- package/dist/web/ProductField/search.svg.mjs +2 -2
- package/dist/web/ProductField/sort.svg.js +1 -3
- package/dist/web/ProductField/sort.svg.mjs +2 -2
- package/dist/web/SkuInputCard/SkuInputCard.js +1 -276
- package/dist/web/SkuInputCard/SkuInputCard.mjs +149 -188
- package/dist/web/SkuInputCard/spin_loading_red.gif.js +1 -3
- package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
- package/dist/web/Switch/Switch.js +1 -70
- package/dist/web/Switch/Switch.mjs +37 -47
- package/dist/web/Table/BTable.js +1 -950
- package/dist/web/Table/BTable.mjs +521 -767
- package/dist/web/Table/Column.js +1 -5
- package/dist/web/Table/Column.mjs +2 -2
- package/dist/web/Table/ColumnGroup.js +1 -5
- package/dist/web/Table/ColumnGroup.mjs +2 -2
- package/dist/web/Table/utils/columns.js +1 -48
- package/dist/web/Table/utils/columns.mjs +30 -35
- package/dist/web/Table/utils/sortFilter.js +1 -84
- package/dist/web/Table/utils/sortFilter.mjs +52 -73
- package/dist/web/Tabs/BTabs.js +1 -150
- package/dist/web/Tabs/BTabs.mjs +98 -118
- package/dist/web/Tabs/TabPane.js +1 -8
- package/dist/web/Tabs/TabPane.mjs +4 -4
- package/dist/web/Tooltip/ConfirmTooltip.js +1 -26
- package/dist/web/Tooltip/ConfirmTooltip.mjs +19 -20
- package/dist/web/Tooltip/ContentTooltip.js +1 -94
- package/dist/web/Tooltip/ContentTooltip.mjs +62 -72
- package/dist/web/Tooltip/ProgressTooltip.js +1 -36
- package/dist/web/Tooltip/ProgressTooltip.mjs +20 -22
- package/dist/web/Tooltip/TooltipWrapper.js +1 -12
- package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
- package/dist/web/Tooltip/useAutoPlacement.js +1 -41
- package/dist/web/Tooltip/useAutoPlacement.mjs +25 -34
- package/dist/web.js +1 -51
- package/dist/web.mjs +49 -49
- package/package.json +1 -1
|
@@ -1,311 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
const react = require("react");
|
|
4
|
-
;/* empty css */
|
|
5
|
-
const useCursor = require("./hooks/useCursor.js");
|
|
6
|
-
const useFrame = require("./hooks/useFrame.js");
|
|
7
|
-
const StepHandler = require("./StepHandler.js");
|
|
8
|
-
const decimal = require("./utils/decimal.js");
|
|
9
|
-
function getDecimalIfValid(value) {
|
|
10
|
-
if (value === void 0 || value === null) return null;
|
|
11
|
-
const decimal$1 = decimal.getDecimal(value);
|
|
12
|
-
return decimal$1.isInvalidate() ? null : decimal$1;
|
|
13
|
-
}
|
|
14
|
-
const BInputNumber = react.forwardRef(function BInputNumber2({
|
|
15
|
-
value,
|
|
16
|
-
defaultValue,
|
|
17
|
-
onChange,
|
|
18
|
-
min,
|
|
19
|
-
max,
|
|
20
|
-
step = 1,
|
|
21
|
-
precision,
|
|
22
|
-
disabled = false,
|
|
23
|
-
readOnly = false,
|
|
24
|
-
placeholder,
|
|
25
|
-
autoFocus,
|
|
26
|
-
size = "middle",
|
|
27
|
-
status,
|
|
28
|
-
bordered = true,
|
|
29
|
-
controls = true,
|
|
30
|
-
keyboard = true,
|
|
31
|
-
changeOnWheel = false,
|
|
32
|
-
changeOnBlur = true,
|
|
33
|
-
addonBefore,
|
|
34
|
-
addonAfter,
|
|
35
|
-
prefix,
|
|
36
|
-
suffix,
|
|
37
|
-
formatter,
|
|
38
|
-
parser,
|
|
39
|
-
decimalSeparator,
|
|
40
|
-
onStep,
|
|
41
|
-
onPressEnter,
|
|
42
|
-
onFocus,
|
|
43
|
-
onBlur,
|
|
44
|
-
id,
|
|
45
|
-
name,
|
|
46
|
-
className,
|
|
47
|
-
style
|
|
48
|
-
}, ref) {
|
|
49
|
-
const inputRef = react.useRef(null);
|
|
50
|
-
const [focused, setFocused] = react.useState(false);
|
|
51
|
-
const userTypingRef = react.useRef(false);
|
|
52
|
-
const compositionRef = react.useRef(false);
|
|
53
|
-
const shiftKeyRef = react.useRef(false);
|
|
54
|
-
const inputValueRef = react.useRef("");
|
|
55
|
-
const [decimalValue, setDecimalValue] = react.useState(() => decimal.getDecimal(value ?? defaultValue));
|
|
56
|
-
const setUncontrolledDecimalValue = (next) => {
|
|
57
|
-
if (value === void 0) setDecimalValue(next);
|
|
58
|
-
};
|
|
59
|
-
const getPrecision = react.useCallback(
|
|
60
|
-
(numStr, userTyping) => {
|
|
61
|
-
if (userTyping) return void 0;
|
|
62
|
-
if (precision !== void 0 && precision >= 0) return precision;
|
|
63
|
-
return Math.max(decimal.getNumberPrecision(numStr), decimal.getNumberPrecision(step));
|
|
64
|
-
},
|
|
65
|
-
[precision, step]
|
|
66
|
-
);
|
|
67
|
-
const mergedParser = react.useCallback(
|
|
68
|
-
(num) => {
|
|
69
|
-
if (parser) return parser(num);
|
|
70
|
-
let parsedStr = num;
|
|
71
|
-
if (decimalSeparator) parsedStr = parsedStr.replace(decimalSeparator, ".");
|
|
72
|
-
return parsedStr.replace(/[^\w.-]+/g, "");
|
|
73
|
-
},
|
|
74
|
-
[parser, decimalSeparator]
|
|
75
|
-
);
|
|
76
|
-
const mergedFormatter = react.useCallback(
|
|
77
|
-
(number, userTyping) => {
|
|
78
|
-
if (formatter) return formatter(number, { userTyping: !!userTyping, input: inputValueRef.current });
|
|
79
|
-
let str = number;
|
|
80
|
-
if (!userTyping) {
|
|
81
|
-
const mergedPrecision = getPrecision(str, userTyping);
|
|
82
|
-
if (decimal.validateNumber(str) && (decimalSeparator || (mergedPrecision ?? -1) >= 0)) {
|
|
83
|
-
str = decimal.toFixed(str, decimalSeparator || ".", mergedPrecision);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return str;
|
|
87
|
-
},
|
|
88
|
-
[formatter, getPrecision, decimalSeparator]
|
|
89
|
-
);
|
|
90
|
-
const [inputValue, setInternalInputValue] = react.useState(() => {
|
|
91
|
-
const initValue = defaultValue ?? value;
|
|
92
|
-
if (decimalValue.isInvalidate() && ["string", "number"].includes(typeof initValue)) {
|
|
93
|
-
return initValue === void 0 || initValue === null || Number.isNaN(initValue) ? "" : String(initValue);
|
|
94
|
-
}
|
|
95
|
-
return mergedFormatter(decimalValue.toString(), false);
|
|
96
|
-
});
|
|
97
|
-
inputValueRef.current = inputValue;
|
|
98
|
-
const setInputValue = (newValue, userTyping) => {
|
|
99
|
-
setInternalInputValue(
|
|
100
|
-
mergedFormatter(newValue.isInvalidate() ? newValue.toString(false) : newValue.toString(!userTyping), userTyping)
|
|
101
|
-
);
|
|
102
|
-
};
|
|
103
|
-
const maxDecimal = react.useMemo(() => getDecimalIfValid(max), [max]);
|
|
104
|
-
const minDecimal = react.useMemo(() => getDecimalIfValid(min), [min]);
|
|
105
|
-
const upDisabled = react.useMemo(() => {
|
|
106
|
-
if (!maxDecimal || decimalValue.isInvalidate()) return false;
|
|
107
|
-
return maxDecimal.lessEquals(decimalValue);
|
|
108
|
-
}, [maxDecimal, decimalValue]);
|
|
109
|
-
const downDisabled = react.useMemo(() => {
|
|
110
|
-
if (!minDecimal || decimalValue.isInvalidate()) return false;
|
|
111
|
-
return decimalValue.lessEquals(minDecimal);
|
|
112
|
-
}, [minDecimal, decimalValue]);
|
|
113
|
-
const [recordCursor] = useCursor(inputRef.current, focused);
|
|
114
|
-
const getRangeValue = (target) => {
|
|
115
|
-
if (maxDecimal && !target.lessEquals(maxDecimal)) return maxDecimal;
|
|
116
|
-
if (minDecimal && !minDecimal.lessEquals(target)) return minDecimal;
|
|
117
|
-
return null;
|
|
118
|
-
};
|
|
119
|
-
const isInRange = (target) => !getRangeValue(target);
|
|
120
|
-
const triggerValueUpdate = (newValue, userTyping) => {
|
|
121
|
-
let updateValue = newValue;
|
|
122
|
-
let isRangeValidate = isInRange(updateValue) || updateValue.isEmpty();
|
|
123
|
-
if (!updateValue.isEmpty() && !userTyping) {
|
|
124
|
-
updateValue = getRangeValue(updateValue) || updateValue;
|
|
125
|
-
isRangeValidate = true;
|
|
126
|
-
}
|
|
127
|
-
if (!readOnly && !disabled && isRangeValidate) {
|
|
128
|
-
const numStr = updateValue.toString();
|
|
129
|
-
const mergedPrecision = getPrecision(numStr, userTyping);
|
|
130
|
-
if (mergedPrecision !== void 0 && mergedPrecision >= 0) {
|
|
131
|
-
updateValue = decimal.getDecimal(decimal.toFixed(numStr, ".", mergedPrecision));
|
|
132
|
-
if (!isInRange(updateValue)) {
|
|
133
|
-
updateValue = decimal.getDecimal(decimal.toFixed(numStr, ".", mergedPrecision, true));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (!updateValue.equals(decimalValue)) {
|
|
137
|
-
setUncontrolledDecimalValue(updateValue);
|
|
138
|
-
onChange == null ? void 0 : onChange(updateValue.isEmpty() ? null : updateValue.toNumber());
|
|
139
|
-
if (value === void 0) setInputValue(updateValue, userTyping);
|
|
140
|
-
}
|
|
141
|
-
return updateValue;
|
|
142
|
-
}
|
|
143
|
-
return decimalValue;
|
|
144
|
-
};
|
|
145
|
-
const onNextFrame = useFrame();
|
|
146
|
-
const collectInputValue = (inputStr) => {
|
|
147
|
-
recordCursor();
|
|
148
|
-
inputValueRef.current = inputStr;
|
|
149
|
-
setInternalInputValue(inputStr);
|
|
150
|
-
if (!compositionRef.current) {
|
|
151
|
-
const finalValue = mergedParser(inputStr);
|
|
152
|
-
const finalDecimal = decimal.getDecimal(finalValue);
|
|
153
|
-
if (!finalDecimal.isNaN()) triggerValueUpdate(finalDecimal, true);
|
|
154
|
-
}
|
|
155
|
-
onNextFrame(() => {
|
|
156
|
-
const nextInputStr = parser ? inputStr : inputStr.replace(/。/g, ".");
|
|
157
|
-
if (nextInputStr !== inputStr) collectInputValue(nextInputStr);
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
const onCompositionStart = () => {
|
|
161
|
-
compositionRef.current = true;
|
|
162
|
-
};
|
|
163
|
-
const onCompositionEnd = (e) => {
|
|
164
|
-
compositionRef.current = false;
|
|
165
|
-
collectInputValue(e.target.value);
|
|
166
|
-
};
|
|
167
|
-
const onInternalInput = (e) => collectInputValue(e.target.value);
|
|
168
|
-
const onInternalStep = (up) => {
|
|
169
|
-
var _a;
|
|
170
|
-
if (up && upDisabled || !up && downDisabled) return;
|
|
171
|
-
userTypingRef.current = false;
|
|
172
|
-
let stepDecimal = decimal.getDecimal(shiftKeyRef.current ? decimal.getDecupleSteps(step) : step);
|
|
173
|
-
if (!up) stepDecimal = stepDecimal.negate();
|
|
174
|
-
const target = (decimalValue.isInvalidate() ? decimal.getDecimal(0) : decimalValue).add(stepDecimal.toString());
|
|
175
|
-
const updatedValue = triggerValueUpdate(target, false);
|
|
176
|
-
onStep == null ? void 0 : onStep(updatedValue.toNumber(), { offset: shiftKeyRef.current ? decimal.getDecupleSteps(step) : step, type: up ? "up" : "down" });
|
|
177
|
-
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
178
|
-
};
|
|
179
|
-
const flushInputValue = (userTyping) => {
|
|
180
|
-
const parsedValue = decimal.getDecimal(mergedParser(inputValue));
|
|
181
|
-
let formatValue;
|
|
182
|
-
if (!parsedValue.isNaN()) {
|
|
183
|
-
formatValue = triggerValueUpdate(parsedValue, userTyping);
|
|
184
|
-
} else {
|
|
185
|
-
formatValue = triggerValueUpdate(decimalValue, userTyping);
|
|
186
|
-
}
|
|
187
|
-
if (value !== void 0) {
|
|
188
|
-
setInputValue(decimalValue, false);
|
|
189
|
-
} else if (!formatValue.isNaN()) {
|
|
190
|
-
setInputValue(formatValue, false);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
const onKeyDown = (event) => {
|
|
194
|
-
const { key, shiftKey } = event;
|
|
195
|
-
userTypingRef.current = true;
|
|
196
|
-
shiftKeyRef.current = shiftKey;
|
|
197
|
-
if (key === "Enter") {
|
|
198
|
-
if (!compositionRef.current) userTypingRef.current = false;
|
|
199
|
-
flushInputValue(false);
|
|
200
|
-
onPressEnter == null ? void 0 : onPressEnter(event);
|
|
201
|
-
}
|
|
202
|
-
if (!keyboard) return;
|
|
203
|
-
if (!compositionRef.current && (key === "ArrowUp" || key === "ArrowDown")) {
|
|
204
|
-
onInternalStep(key === "ArrowUp");
|
|
205
|
-
event.preventDefault();
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
const onKeyUp = () => {
|
|
209
|
-
userTypingRef.current = false;
|
|
210
|
-
shiftKeyRef.current = false;
|
|
211
|
-
};
|
|
212
|
-
const onInternalFocus = (e) => {
|
|
213
|
-
setFocused(true);
|
|
214
|
-
onFocus == null ? void 0 : onFocus(e);
|
|
215
|
-
};
|
|
216
|
-
const onInternalBlur = (e) => {
|
|
217
|
-
if (changeOnBlur) flushInputValue(false);
|
|
218
|
-
setFocused(false);
|
|
219
|
-
userTypingRef.current = false;
|
|
220
|
-
onBlur == null ? void 0 : onBlur(e);
|
|
221
|
-
};
|
|
222
|
-
const prevValueRef = react.useRef(value);
|
|
223
|
-
if (prevValueRef.current !== value) {
|
|
224
|
-
prevValueRef.current = value;
|
|
225
|
-
const newValue = decimal.getDecimal(value);
|
|
226
|
-
if (!newValue.equals(decimalValue)) {
|
|
227
|
-
setDecimalValue(newValue);
|
|
228
|
-
const currentParsedValue = decimal.getDecimal(mergedParser(inputValue));
|
|
229
|
-
if (!newValue.equals(currentParsedValue) || !userTypingRef.current || formatter) {
|
|
230
|
-
setInputValue(newValue, userTypingRef.current);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
const setRefs = (node) => {
|
|
235
|
-
inputRef.current = node;
|
|
236
|
-
if (typeof ref === "function") ref(node);
|
|
237
|
-
else if (ref) ref.current = node;
|
|
238
|
-
};
|
|
239
|
-
const controlsEnabled = !!controls;
|
|
240
|
-
const controlsIcon = typeof controls === "object" ? controls.icon : void 0;
|
|
241
|
-
const outOfRange = !decimalValue.isInvalidate() && !isInRange(decimalValue);
|
|
242
|
-
const rootCls = [
|
|
243
|
-
"bj-input-number",
|
|
244
|
-
`bj-input-number--${size}`,
|
|
245
|
-
focused && "bj-input-number--focused",
|
|
246
|
-
disabled && "bj-input-number--disabled",
|
|
247
|
-
readOnly && "bj-input-number--readonly",
|
|
248
|
-
!bordered && "bj-input-number--borderless",
|
|
249
|
-
status && `bj-input-number--${status}`,
|
|
250
|
-
outOfRange && "bj-input-number--out-of-range",
|
|
251
|
-
controlsEnabled && "bj-input-number--with-controls",
|
|
252
|
-
addonBefore && "bj-input-number--group-left",
|
|
253
|
-
addonAfter && "bj-input-number--group-right"
|
|
254
|
-
].filter(Boolean).join(" ");
|
|
255
|
-
const numberBox = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
256
|
-
"div",
|
|
257
|
-
{
|
|
258
|
-
className: [rootCls, !(addonBefore || addonAfter || prefix || suffix) && className].filter(Boolean).join(" "),
|
|
259
|
-
style: !(addonBefore || addonAfter || prefix || suffix) ? style : void 0,
|
|
260
|
-
onKeyDown,
|
|
261
|
-
onKeyUp,
|
|
262
|
-
children: [
|
|
263
|
-
prefix && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-input-number__prefix", children: prefix }),
|
|
264
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bj-input-number__input-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
265
|
-
"input",
|
|
266
|
-
{
|
|
267
|
-
ref: setRefs,
|
|
268
|
-
id,
|
|
269
|
-
name,
|
|
270
|
-
className: "bj-input-number__input",
|
|
271
|
-
autoComplete: "off",
|
|
272
|
-
role: "spinbutton",
|
|
273
|
-
"aria-valuemin": min,
|
|
274
|
-
"aria-valuemax": max,
|
|
275
|
-
"aria-valuenow": decimalValue.isInvalidate() ? void 0 : decimalValue.toNumber(),
|
|
276
|
-
value: inputValue,
|
|
277
|
-
placeholder,
|
|
278
|
-
disabled,
|
|
279
|
-
readOnly,
|
|
280
|
-
autoFocus,
|
|
281
|
-
onChange: onInternalInput,
|
|
282
|
-
onFocus: onInternalFocus,
|
|
283
|
-
onBlur: onInternalBlur,
|
|
284
|
-
onCompositionStart,
|
|
285
|
-
onCompositionEnd,
|
|
286
|
-
onWheel: changeOnWheel ? (e) => {
|
|
287
|
-
if (!focused) return;
|
|
288
|
-
onInternalStep(e.deltaY < 0);
|
|
289
|
-
} : void 0
|
|
290
|
-
}
|
|
291
|
-
) }),
|
|
292
|
-
suffix && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-input-number__suffix", children: suffix }),
|
|
293
|
-
controlsEnabled && /* @__PURE__ */ jsxRuntime.jsx(StepHandler, { icon: controlsIcon, upDisabled, downDisabled, onStep: onInternalStep })
|
|
294
|
-
]
|
|
295
|
-
}
|
|
296
|
-
);
|
|
297
|
-
if (!addonBefore && !addonAfter) return numberBox;
|
|
298
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
299
|
-
"div",
|
|
300
|
-
{
|
|
301
|
-
className: ["bj-input-number-group", `bj-input-number-group--${size}`, className].filter(Boolean).join(" "),
|
|
302
|
-
style,
|
|
303
|
-
children: [
|
|
304
|
-
addonBefore && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bj-input-number-group__addon", children: addonBefore }),
|
|
305
|
-
numberBox,
|
|
306
|
-
addonAfter && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bj-input-number-group__addon", children: addonAfter })
|
|
307
|
-
]
|
|
308
|
-
}
|
|
309
|
-
);
|
|
310
|
-
});
|
|
311
|
-
module.exports = BInputNumber;
|
|
1
|
+
"use strict";const l=require("react/jsx-runtime"),s=require("react");;/* empty css */const Me=require("./hooks/useCursor.js"),Ue=require("./hooks/useFrame.js"),ke=require("./StepHandler.js"),u=require("./utils/decimal.js");function ae(N){if(N==null)return null;const i=u.getDecimal(N);return i.isInvalidate()?null:i}const Ke=s.forwardRef(function({value:i,defaultValue:Z,onChange:C,min:E,max:F,step:a=1,precision:D,disabled:M=!1,readOnly:U=!1,placeholder:fe,autoFocus:me,size:z="middle",status:B,bordered:be=!0,controls:k=!0,keyboard:de=!0,changeOnWheel:pe=!1,changeOnBlur:ge=!0,addonBefore:f,addonAfter:m,prefix:I,suffix:v,formatter:R,parser:V,decimalSeparator:b,onStep:K,onPressEnter:S,onFocus:$,onBlur:P,id:je,name:Ne,className:O,style:A},q){const H=s.useRef(null),[W,T]=s.useState(!1),c=s.useRef(!1),j=s.useRef(!1),x=s.useRef(!1),Y=s.useRef(""),[r,ee]=s.useState(()=>u.getDecimal(i??Z)),De=e=>{i===void 0&&ee(e)},G=s.useCallback((e,t)=>{if(!t)return D!==void 0&&D>=0?D:Math.max(u.getNumberPrecision(e),u.getNumberPrecision(a))},[D,a]),J=s.useCallback(e=>{if(V)return V(e);let t=e;return b&&(t=t.replace(b,".")),t.replace(/[^\w.-]+/g,"")},[V,b]),te=s.useCallback((e,t)=>{if(R)return R(e,{userTyping:!!t,input:Y.current});let n=e;if(!t){const o=G(n,t);u.validateNumber(n)&&(b||(o??-1)>=0)&&(n=u.toFixed(n,b||".",o))}return n},[R,G,b]),[_,ne]=s.useState(()=>{const e=Z??i;return r.isInvalidate()&&["string","number"].includes(typeof e)?e==null||Number.isNaN(e)?"":String(e):te(r.toString(),!1)});Y.current=_;const h=(e,t)=>{ne(te(e.isInvalidate()?e.toString(!1):e.toString(!t),t))},d=s.useMemo(()=>ae(F),[F]),p=s.useMemo(()=>ae(E),[E]),re=s.useMemo(()=>!d||r.isInvalidate()?!1:d.lessEquals(r),[d,r]),ue=s.useMemo(()=>!p||r.isInvalidate()?!1:r.lessEquals(p),[p,r]),[Ie]=Me(H.current,W),se=e=>d&&!e.lessEquals(d)?d:p&&!p.lessEquals(e)?p:null,L=e=>!se(e),w=(e,t)=>{let n=e,o=L(n)||n.isEmpty();if(!n.isEmpty()&&!t&&(n=se(n)||n,o=!0),!U&&!M&&o){const g=n.toString(),y=G(g,t);return y!==void 0&&y>=0&&(n=u.getDecimal(u.toFixed(g,".",y)),L(n)||(n=u.getDecimal(u.toFixed(g,".",y,!0)))),n.equals(r)||(De(n),C==null||C(n.isEmpty()?null:n.toNumber()),i===void 0&&h(n,t)),n}return r},ve=Ue(),Q=e=>{if(Ie(),Y.current=e,ne(e),!j.current){const t=J(e),n=u.getDecimal(t);n.isNaN()||w(n,!0)}ve(()=>{const t=V?e:e.replace(/。/g,".");t!==e&&Q(t)})},Re=()=>{j.current=!0},Ve=e=>{j.current=!1,Q(e.target.value)},qe=e=>Q(e.target.value),X=e=>{var g;if(e&&re||!e&&ue)return;c.current=!1;let t=u.getDecimal(x.current?u.getDecupleSteps(a):a);e||(t=t.negate());const n=(r.isInvalidate()?u.getDecimal(0):r).add(t.toString()),o=w(n,!1);K==null||K(o.toNumber(),{offset:x.current?u.getDecupleSteps(a):a,type:e?"up":"down"}),(g=H.current)==null||g.focus()},ie=e=>{const t=u.getDecimal(J(_));let n;t.isNaN()?n=w(r,e):n=w(t,e),i!==void 0?h(r,!1):n.isNaN()||h(n,!1)},xe=e=>{const{key:t,shiftKey:n}=e;c.current=!0,x.current=n,t==="Enter"&&(j.current||(c.current=!1),ie(!1),S==null||S(e)),de&&!j.current&&(t==="ArrowUp"||t==="ArrowDown")&&(X(t==="ArrowUp"),e.preventDefault())},_e=()=>{c.current=!1,x.current=!1},he=e=>{T(!0),$==null||$(e)},we=e=>{ge&&ie(!1),T(!1),c.current=!1,P==null||P(e)},le=s.useRef(i);if(le.current!==i){le.current=i;const e=u.getDecimal(i);if(!e.equals(r)){ee(e);const t=u.getDecimal(J(_));(!e.equals(t)||!c.current||R)&&h(e,c.current)}}const ye=e=>{H.current=e,typeof q=="function"?q(e):q&&(q.current=e)},ce=!!k,Ce=typeof k=="object"?k.icon:void 0,Ee=!r.isInvalidate()&&!L(r),Fe=["bj-input-number",`bj-input-number--${z}`,W&&"bj-input-number--focused",M&&"bj-input-number--disabled",U&&"bj-input-number--readonly",!be&&"bj-input-number--borderless",B&&`bj-input-number--${B}`,Ee&&"bj-input-number--out-of-range",ce&&"bj-input-number--with-controls",f&&"bj-input-number--group-left",m&&"bj-input-number--group-right"].filter(Boolean).join(" "),oe=l.jsxs("div",{className:[Fe,!(f||m||I||v)&&O].filter(Boolean).join(" "),style:f||m||I||v?void 0:A,onKeyDown:xe,onKeyUp:_e,children:[I&&l.jsx("span",{className:"bj-input-number__prefix",children:I}),l.jsx("div",{className:"bj-input-number__input-wrap",children:l.jsx("input",{ref:ye,id:je,name:Ne,className:"bj-input-number__input",autoComplete:"off",role:"spinbutton","aria-valuemin":E,"aria-valuemax":F,"aria-valuenow":r.isInvalidate()?void 0:r.toNumber(),value:_,placeholder:fe,disabled:M,readOnly:U,autoFocus:me,onChange:qe,onFocus:he,onBlur:we,onCompositionStart:Re,onCompositionEnd:Ve,onWheel:pe?e=>{W&&X(e.deltaY<0)}:void 0})}),v&&l.jsx("span",{className:"bj-input-number__suffix",children:v}),ce&&l.jsx(ke,{icon:Ce,upDisabled:re,downDisabled:ue,onStep:X})]});return!f&&!m?oe:l.jsxs("div",{className:["bj-input-number-group",`bj-input-number-group--${z}`,O].filter(Boolean).join(" "),style:A,children:[f&&l.jsx("div",{className:"bj-input-number-group__addon",children:f}),oe,m&&l.jsx("div",{className:"bj-input-number-group__addon",children:m})]})});module.exports=Ke;
|