@v-c/input-number 1.0.7 → 1.1.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/InputNumber.d.ts +7 -1
- package/dist/InputNumber.js +70 -6
- package/dist/StepHandler.d.ts +1 -1
- package/package.json +3 -3
package/dist/InputNumber.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ValueType } from '@v-c/mini-decimal';
|
|
2
2
|
import { InputFocusOptions } from '@v-c/util/dist/Dom/focus';
|
|
3
3
|
export type { ValueType };
|
|
4
|
-
type SemanticName = 'root' | 'actions' | 'input' | 'action' | 'prefix' | 'suffix';
|
|
4
|
+
type SemanticName = 'root' | 'actions' | 'input' | 'action' | 'prefix' | 'suffix' | 'clear';
|
|
5
5
|
export interface InputNumberProps<T extends ValueType = ValueType> {
|
|
6
6
|
mode?: 'input' | 'spinner';
|
|
7
7
|
prefixCls?: string;
|
|
@@ -19,6 +19,11 @@ export interface InputNumberProps<T extends ValueType = ValueType> {
|
|
|
19
19
|
readOnly?: boolean;
|
|
20
20
|
prefix?: any;
|
|
21
21
|
suffix?: any;
|
|
22
|
+
allowClear?: boolean | {
|
|
23
|
+
clearIcon?: any;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
label?: string;
|
|
26
|
+
};
|
|
22
27
|
upHandler?: any;
|
|
23
28
|
downHandler?: any;
|
|
24
29
|
keyboard?: boolean;
|
|
@@ -33,6 +38,7 @@ export interface InputNumberProps<T extends ValueType = ValueType> {
|
|
|
33
38
|
decimalSeparator?: string;
|
|
34
39
|
onInput?: (text: string) => void;
|
|
35
40
|
onChange?: (value: T | null) => void;
|
|
41
|
+
onClear?: () => void;
|
|
36
42
|
onPressEnter?: (e: KeyboardEvent) => void;
|
|
37
43
|
onStep?: (value: T, info: {
|
|
38
44
|
offset: ValueType;
|
package/dist/InputNumber.js
CHANGED
|
@@ -4,7 +4,7 @@ import StepHandler_default from "./StepHandler.js";
|
|
|
4
4
|
import { getDecupleSteps } from "./utils/numberUtil.js";
|
|
5
5
|
import { computed, createVNode, defineComponent, isVNode, mergeDefaults, mergeProps, shallowRef, watch, watchEffect } from "vue";
|
|
6
6
|
import getMiniDecimal, { getNumberPrecision, num2str, toFixed, validateNumber } from "@v-c/mini-decimal";
|
|
7
|
-
import { clsx } from "@v-c/util";
|
|
7
|
+
import { clsx, isVueRenderable } from "@v-c/util";
|
|
8
8
|
import { triggerFocus } from "@v-c/util/dist/Dom/focus";
|
|
9
9
|
import { KeyCodeStr } from "@v-c/util/dist/KeyCode";
|
|
10
10
|
import omit from "@v-c/util/dist/omit";
|
|
@@ -77,6 +77,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
77
77
|
};
|
|
78
78
|
const inputValue = shallowRef("");
|
|
79
79
|
const inputValueRef = shallowRef("");
|
|
80
|
+
let inputValueUpdateId = 0;
|
|
80
81
|
const mergedFormatter = (number, userTyping) => {
|
|
81
82
|
if (props.formatter) return props.formatter(number, {
|
|
82
83
|
userTyping,
|
|
@@ -159,15 +160,19 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
159
160
|
};
|
|
160
161
|
const onNextPromise = useFrame_default();
|
|
161
162
|
const collectInputValue = (inputStr) => {
|
|
163
|
+
inputValueUpdateId += 1;
|
|
164
|
+
const currentUpdateId = inputValueUpdateId;
|
|
162
165
|
recordCursor();
|
|
163
166
|
inputValueRef.value = inputStr;
|
|
164
167
|
inputValue.value = inputStr;
|
|
165
168
|
if (!compositionRef.value) {
|
|
166
|
-
const
|
|
169
|
+
const finalValue = mergedParser(inputStr);
|
|
170
|
+
const finalDecimal = getMiniDecimal(finalValue);
|
|
167
171
|
if (!finalDecimal.isNaN()) triggerValueUpdate(finalDecimal, true);
|
|
168
172
|
}
|
|
169
173
|
props.onInput?.(inputStr);
|
|
170
174
|
onNextPromise(() => {
|
|
175
|
+
if (currentUpdateId !== inputValueUpdateId) return;
|
|
171
176
|
let nextInputStr = inputStr;
|
|
172
177
|
if (!props.parser) nextInputStr = inputStr.replace(/。/g, ".");
|
|
173
178
|
if (nextInputStr !== inputStr) collectInputValue(nextInputStr);
|
|
@@ -274,6 +279,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
274
279
|
}
|
|
275
280
|
});
|
|
276
281
|
const onBlur = (e) => {
|
|
282
|
+
if (e.relatedTarget instanceof Node && rootRef.value?.contains(e.relatedTarget)) return;
|
|
277
283
|
if (props.changeOnBlur ?? true) flushInputValue(false);
|
|
278
284
|
focus.value = false;
|
|
279
285
|
userTypingRef.value = false;
|
|
@@ -291,6 +297,26 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
291
297
|
}
|
|
292
298
|
props.onMouseDown?.(event);
|
|
293
299
|
};
|
|
300
|
+
const onClearKeyDown = (event) => {
|
|
301
|
+
const isStepKey = [
|
|
302
|
+
"Up",
|
|
303
|
+
"ArrowUp",
|
|
304
|
+
"Down",
|
|
305
|
+
"ArrowDown"
|
|
306
|
+
].includes(event.key);
|
|
307
|
+
if (event.key === KeyCodeStr.Enter || props.keyboard !== false && isStepKey) event.stopPropagation();
|
|
308
|
+
};
|
|
309
|
+
const onClearClick = () => {
|
|
310
|
+
userTypingRef.value = false;
|
|
311
|
+
inputValueRef.value = "";
|
|
312
|
+
inputValueUpdateId += 1;
|
|
313
|
+
const emptyValue = getMiniDecimal(null);
|
|
314
|
+
if (props.value !== void 0) setInputValue(decimalValue.value, false);
|
|
315
|
+
else if (decimalValue.value.isEmpty()) setInputValue(emptyValue, false);
|
|
316
|
+
inputRef.value?.focus();
|
|
317
|
+
triggerValueUpdate(emptyValue, false);
|
|
318
|
+
props.onClear?.();
|
|
319
|
+
};
|
|
294
320
|
watch([
|
|
295
321
|
() => props.precision,
|
|
296
322
|
() => props.formatter,
|
|
@@ -308,7 +334,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
308
334
|
if (props.formatter) restoreCursor();
|
|
309
335
|
}, { flush: "post" });
|
|
310
336
|
return () => {
|
|
311
|
-
const { prefixCls = defaults.prefixCls, classNames, styles, step = defaults.step, disabled, readOnly, controls = defaults.controls, mode = defaults.mode, placeholder } = props;
|
|
337
|
+
const { prefixCls = defaults.prefixCls, classNames, styles, step = defaults.step, disabled, readOnly, controls = defaults.controls, mode = defaults.mode, placeholder, allowClear } = props;
|
|
312
338
|
const mergedPrefixCls = prefixCls || defaults.prefixCls;
|
|
313
339
|
const { class: className, style, ...restAttrs } = attrs;
|
|
314
340
|
const mergedClassName = props.className || className;
|
|
@@ -321,6 +347,23 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
321
347
|
const suffixNode = slots.suffix?.() ?? props.suffix;
|
|
322
348
|
const upNode = slots.upHandler?.() ?? props.upHandler;
|
|
323
349
|
const downNode = slots.downHandler?.() ?? props.downHandler;
|
|
350
|
+
const clearConfig = allowClear && typeof allowClear === "object" ? allowClear : { disabled: allowClear !== true };
|
|
351
|
+
const showClear = !disabled && !readOnly && clearConfig.disabled !== true && String(inputValue.value).length > 0;
|
|
352
|
+
const hasSuffix = isVueRenderable(suffixNode);
|
|
353
|
+
const clearIconCls = `${mergedPrefixCls}-clear-icon`;
|
|
354
|
+
const clearNode = allowClear && createVNode("button", {
|
|
355
|
+
"type": "button",
|
|
356
|
+
"aria-label": clearConfig.label ?? "Clear",
|
|
357
|
+
"disabled": !showClear,
|
|
358
|
+
"class": clsx(clearIconCls, {
|
|
359
|
+
[`${clearIconCls}-hidden`]: !showClear,
|
|
360
|
+
[`${clearIconCls}-has-suffix`]: hasSuffix
|
|
361
|
+
}, classNames?.clear),
|
|
362
|
+
"style": styles?.clear,
|
|
363
|
+
"onMousedown": (event) => event.preventDefault(),
|
|
364
|
+
"onKeydown": onClearKeyDown,
|
|
365
|
+
"onClick": onClearClick
|
|
366
|
+
}, [slots.clearIcon?.() ?? clearConfig.clearIcon ?? "✖"]);
|
|
324
367
|
const upHandlerNode = createVNode(StepHandler_default, {
|
|
325
368
|
"prefixCls": mergedPrefixCls,
|
|
326
369
|
"action": "up",
|
|
@@ -345,6 +388,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
345
388
|
"value",
|
|
346
389
|
"prefix",
|
|
347
390
|
"suffix",
|
|
391
|
+
"allowClear",
|
|
348
392
|
"upHandler",
|
|
349
393
|
"downHandler",
|
|
350
394
|
"keyboard",
|
|
@@ -356,6 +400,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
356
400
|
"precision",
|
|
357
401
|
"decimalSeparator",
|
|
358
402
|
"onChange",
|
|
403
|
+
"onClear",
|
|
359
404
|
"onInput",
|
|
360
405
|
"onPressEnter",
|
|
361
406
|
"onStep",
|
|
@@ -408,7 +453,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
408
453
|
}
|
|
409
454
|
}, [
|
|
410
455
|
mode === "spinner" && controls && downHandlerNode,
|
|
411
|
-
|
|
456
|
+
isVueRenderable(prefixNode) && createVNode("div", {
|
|
412
457
|
"class": clsx(`${mergedPrefixCls}-prefix`, classNames?.prefix),
|
|
413
458
|
"style": styles?.prefix
|
|
414
459
|
}, [prefixNode]),
|
|
@@ -435,10 +480,10 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
435
480
|
"onCompositionend": onCompositionEnd,
|
|
436
481
|
"onBeforeinput": onBeforeInput
|
|
437
482
|
}, inputAttrs), null),
|
|
438
|
-
|
|
483
|
+
(allowClear || hasSuffix) && createVNode("div", {
|
|
439
484
|
"class": clsx(`${mergedPrefixCls}-suffix`, classNames?.suffix),
|
|
440
485
|
"style": styles?.suffix
|
|
441
|
-
}, [suffixNode]),
|
|
486
|
+
}, [clearNode, suffixNode]),
|
|
442
487
|
mode === "spinner" && controls && upHandlerNode,
|
|
443
488
|
mode === "input" && controls && createVNode("div", {
|
|
444
489
|
"class": clsx(`${mergedPrefixCls}-actions`, classNames?.actions),
|
|
@@ -482,22 +527,31 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
482
527
|
default: void 0
|
|
483
528
|
},
|
|
484
529
|
min: {
|
|
530
|
+
type: [String, Number],
|
|
485
531
|
required: false,
|
|
486
532
|
default: void 0
|
|
487
533
|
},
|
|
488
534
|
max: {
|
|
535
|
+
type: [String, Number],
|
|
489
536
|
required: false,
|
|
490
537
|
default: void 0
|
|
491
538
|
},
|
|
492
539
|
step: {
|
|
540
|
+
type: [String, Number],
|
|
493
541
|
required: false,
|
|
494
542
|
default: void 0
|
|
495
543
|
},
|
|
496
544
|
defaultValue: {
|
|
545
|
+
type: [String, Number],
|
|
497
546
|
required: false,
|
|
498
547
|
default: void 0
|
|
499
548
|
},
|
|
500
549
|
value: {
|
|
550
|
+
type: [
|
|
551
|
+
String,
|
|
552
|
+
Number,
|
|
553
|
+
null
|
|
554
|
+
],
|
|
501
555
|
required: false,
|
|
502
556
|
default: void 0
|
|
503
557
|
},
|
|
@@ -519,6 +573,11 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
519
573
|
required: false,
|
|
520
574
|
default: void 0
|
|
521
575
|
},
|
|
576
|
+
allowClear: {
|
|
577
|
+
type: [Boolean, Object],
|
|
578
|
+
required: false,
|
|
579
|
+
default: void 0
|
|
580
|
+
},
|
|
522
581
|
upHandler: {
|
|
523
582
|
required: false,
|
|
524
583
|
default: void 0
|
|
@@ -572,6 +631,11 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
|
|
|
572
631
|
required: false,
|
|
573
632
|
default: void 0
|
|
574
633
|
},
|
|
634
|
+
onClear: {
|
|
635
|
+
type: Function,
|
|
636
|
+
required: false,
|
|
637
|
+
default: void 0
|
|
638
|
+
},
|
|
575
639
|
onPressEnter: {
|
|
576
640
|
type: Function,
|
|
577
641
|
required: false,
|
package/dist/StepHandler.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
26
26
|
type: FunctionConstructor;
|
|
27
27
|
required: true;
|
|
28
28
|
};
|
|
29
|
-
}>, () => import(
|
|
29
|
+
}>, () => import('vue/jsx-runtime').JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "step"[], "step", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
30
30
|
prefixCls: {
|
|
31
31
|
type: StringConstructor;
|
|
32
32
|
required: true;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/input-number",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/antdv-next/vue-components/tree/next/packages/input-number",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"vue": "^3.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@v-c/input": "^1.1.
|
|
33
|
+
"@v-c/input": "^1.1.2",
|
|
34
34
|
"@v-c/mini-decimal": "^1.0.1",
|
|
35
|
-
"@v-c/util": "^1.
|
|
35
|
+
"@v-c/util": "^1.3.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "vite build",
|