@v-c/input-number 0.0.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/LICENSE +21 -0
- package/dist/InputNumber.cjs +693 -0
- package/dist/InputNumber.d.ts +67 -0
- package/dist/InputNumber.js +688 -0
- package/dist/StepHandler.cjs +78 -0
- package/dist/StepHandler.d.ts +55 -0
- package/dist/StepHandler.js +75 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/useCursor.cjs +39 -0
- package/dist/hooks/useCursor.d.ts +5 -0
- package/dist/hooks/useCursor.js +36 -0
- package/dist/hooks/useFrame.cjs +19 -0
- package/dist/hooks/useFrame.d.ts +5 -0
- package/dist/hooks/useFrame.js +16 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/utils/numberUtil.cjs +8 -0
- package/dist/utils/numberUtil.d.ts +1 -0
- package/dist/utils/numberUtil.js +7 -0
- package/package.json +37 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_util = require("@v-c/util");
|
|
5
|
+
let __v_c_util_dist_raf = require("@v-c/util/dist/raf");
|
|
6
|
+
__v_c_util_dist_raf = require_rolldown_runtime.__toESM(__v_c_util_dist_raf);
|
|
7
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
8
|
+
var STEP_INTERVAL = 200;
|
|
9
|
+
var STEP_DELAY = 600;
|
|
10
|
+
var StepHandler_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
11
|
+
name: "StepHandler",
|
|
12
|
+
props: {
|
|
13
|
+
prefixCls: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
action: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
disabled: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: false
|
|
24
|
+
},
|
|
25
|
+
className: String,
|
|
26
|
+
style: Object,
|
|
27
|
+
onStep: {
|
|
28
|
+
type: Function,
|
|
29
|
+
required: true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
slots: Object,
|
|
33
|
+
emits: ["step"],
|
|
34
|
+
setup(props, { slots, emit }) {
|
|
35
|
+
const stepTimeoutRef = (0, vue.ref)(null);
|
|
36
|
+
const frameIds = (0, vue.ref)([]);
|
|
37
|
+
const onStopStep = () => {
|
|
38
|
+
clearTimeout(stepTimeoutRef.value);
|
|
39
|
+
};
|
|
40
|
+
const onStepMouseDown = (e, up) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
onStopStep();
|
|
43
|
+
emit("step", up, "handler");
|
|
44
|
+
function loopStep() {
|
|
45
|
+
emit("step", up, "handler");
|
|
46
|
+
stepTimeoutRef.value = setTimeout(loopStep, STEP_INTERVAL);
|
|
47
|
+
}
|
|
48
|
+
stepTimeoutRef.value = setTimeout(loopStep, STEP_DELAY);
|
|
49
|
+
};
|
|
50
|
+
(0, vue.onUnmounted)(() => {
|
|
51
|
+
onStopStep();
|
|
52
|
+
frameIds.value.forEach((id) => __v_c_util_dist_raf.default.cancel(id));
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
const { prefixCls, action, disabled, className, style } = props;
|
|
56
|
+
const isUpAction = action === "up";
|
|
57
|
+
const actionClassName = `${prefixCls}-action`;
|
|
58
|
+
const mergedClassName = (0, __v_c_util.classNames)(actionClassName, `${actionClassName}-${action}`, { [`${actionClassName}-${action}-disabled`]: disabled }, className);
|
|
59
|
+
const safeOnStopStep = () => frameIds.value.push((0, __v_c_util_dist_raf.default)(onStopStep));
|
|
60
|
+
const children = (0, __v_c_util_dist_props_util.filterEmpty)(slots?.default?.());
|
|
61
|
+
return (0, vue.createVNode)("span", {
|
|
62
|
+
"unselectable": "on",
|
|
63
|
+
"role": "button",
|
|
64
|
+
"onMouseup": safeOnStopStep,
|
|
65
|
+
"onMouseleave": safeOnStopStep,
|
|
66
|
+
"onMousedown": (e) => onStepMouseDown(e, isUpAction),
|
|
67
|
+
"aria-label": isUpAction ? "Increase Value" : "Decrease Value",
|
|
68
|
+
"aria-disabled": disabled,
|
|
69
|
+
"class": mergedClassName,
|
|
70
|
+
"style": style
|
|
71
|
+
}, [children.length > 0 ? children : (0, vue.createVNode)("span", {
|
|
72
|
+
"unselectable": "on",
|
|
73
|
+
"class": `${prefixCls}-action-${action}-inner`
|
|
74
|
+
}, null)]);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
exports.default = StepHandler_default;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SlotsType } from 'vue';
|
|
2
|
+
export interface StepHandlerProps {
|
|
3
|
+
prefixCls: string;
|
|
4
|
+
action: 'up' | 'down';
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: any;
|
|
8
|
+
onStep: (up: boolean, emitter: 'handler' | 'keyboard' | 'wheel') => void;
|
|
9
|
+
}
|
|
10
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
11
|
+
prefixCls: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
action: {
|
|
16
|
+
type: () => "up" | "down";
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
disabled: {
|
|
20
|
+
type: BooleanConstructor;
|
|
21
|
+
default: boolean;
|
|
22
|
+
};
|
|
23
|
+
className: StringConstructor;
|
|
24
|
+
style: ObjectConstructor;
|
|
25
|
+
onStep: {
|
|
26
|
+
type: FunctionConstructor;
|
|
27
|
+
required: true;
|
|
28
|
+
};
|
|
29
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "step"[], "step", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
30
|
+
prefixCls: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
required: true;
|
|
33
|
+
};
|
|
34
|
+
action: {
|
|
35
|
+
type: () => "up" | "down";
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
disabled: {
|
|
39
|
+
type: BooleanConstructor;
|
|
40
|
+
default: boolean;
|
|
41
|
+
};
|
|
42
|
+
className: StringConstructor;
|
|
43
|
+
style: ObjectConstructor;
|
|
44
|
+
onStep: {
|
|
45
|
+
type: FunctionConstructor;
|
|
46
|
+
required: true;
|
|
47
|
+
};
|
|
48
|
+
}>> & Readonly<{
|
|
49
|
+
onStep?: ((...args: any[]) => any) | undefined;
|
|
50
|
+
}>, {
|
|
51
|
+
disabled: boolean;
|
|
52
|
+
}, SlotsType<{
|
|
53
|
+
default?: any;
|
|
54
|
+
}>, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
55
|
+
export default _default;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createVNode, defineComponent, onUnmounted, ref } from "vue";
|
|
2
|
+
import { classNames } from "@v-c/util";
|
|
3
|
+
import raf from "@v-c/util/dist/raf";
|
|
4
|
+
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
5
|
+
var STEP_INTERVAL = 200;
|
|
6
|
+
var STEP_DELAY = 600;
|
|
7
|
+
var StepHandler_default = /* @__PURE__ */ defineComponent({
|
|
8
|
+
name: "StepHandler",
|
|
9
|
+
props: {
|
|
10
|
+
prefixCls: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true
|
|
13
|
+
},
|
|
14
|
+
action: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
disabled: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
default: false
|
|
21
|
+
},
|
|
22
|
+
className: String,
|
|
23
|
+
style: Object,
|
|
24
|
+
onStep: {
|
|
25
|
+
type: Function,
|
|
26
|
+
required: true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
slots: Object,
|
|
30
|
+
emits: ["step"],
|
|
31
|
+
setup(props, { slots, emit }) {
|
|
32
|
+
const stepTimeoutRef = ref(null);
|
|
33
|
+
const frameIds = ref([]);
|
|
34
|
+
const onStopStep = () => {
|
|
35
|
+
clearTimeout(stepTimeoutRef.value);
|
|
36
|
+
};
|
|
37
|
+
const onStepMouseDown = (e, up) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
onStopStep();
|
|
40
|
+
emit("step", up, "handler");
|
|
41
|
+
function loopStep() {
|
|
42
|
+
emit("step", up, "handler");
|
|
43
|
+
stepTimeoutRef.value = setTimeout(loopStep, STEP_INTERVAL);
|
|
44
|
+
}
|
|
45
|
+
stepTimeoutRef.value = setTimeout(loopStep, STEP_DELAY);
|
|
46
|
+
};
|
|
47
|
+
onUnmounted(() => {
|
|
48
|
+
onStopStep();
|
|
49
|
+
frameIds.value.forEach((id) => raf.cancel(id));
|
|
50
|
+
});
|
|
51
|
+
return () => {
|
|
52
|
+
const { prefixCls, action, disabled, className, style } = props;
|
|
53
|
+
const isUpAction = action === "up";
|
|
54
|
+
const actionClassName = `${prefixCls}-action`;
|
|
55
|
+
const mergedClassName = classNames(actionClassName, `${actionClassName}-${action}`, { [`${actionClassName}-${action}-disabled`]: disabled }, className);
|
|
56
|
+
const safeOnStopStep = () => frameIds.value.push(raf(onStopStep));
|
|
57
|
+
const children = filterEmpty(slots?.default?.());
|
|
58
|
+
return createVNode("span", {
|
|
59
|
+
"unselectable": "on",
|
|
60
|
+
"role": "button",
|
|
61
|
+
"onMouseup": safeOnStopStep,
|
|
62
|
+
"onMouseleave": safeOnStopStep,
|
|
63
|
+
"onMousedown": (e) => onStepMouseDown(e, isUpAction),
|
|
64
|
+
"aria-label": isUpAction ? "Increase Value" : "Decrease Value",
|
|
65
|
+
"aria-disabled": disabled,
|
|
66
|
+
"class": mergedClassName,
|
|
67
|
+
"style": style
|
|
68
|
+
}, [children.length > 0 ? children : createVNode("span", {
|
|
69
|
+
"unselectable": "on",
|
|
70
|
+
"class": `${prefixCls}-action-${action}-inner`
|
|
71
|
+
}, null)]);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
export { StepHandler_default as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
+
key = keys[i];
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: ((k) => from[k]).bind(null, key),
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
value: mod,
|
|
19
|
+
enumerable: true
|
|
20
|
+
}) : target, mod));
|
|
21
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_util_dist_warning = require("@v-c/util/dist/warning");
|
|
5
|
+
__v_c_util_dist_warning = require_rolldown_runtime.__toESM(__v_c_util_dist_warning);
|
|
6
|
+
function useCursor(input, focused) {
|
|
7
|
+
const selectionRef = (0, vue.ref)(null);
|
|
8
|
+
function recordCursor() {
|
|
9
|
+
try {
|
|
10
|
+
const { selectionStart: start, selectionEnd: end, value } = input;
|
|
11
|
+
selectionRef.value = {
|
|
12
|
+
start,
|
|
13
|
+
end,
|
|
14
|
+
value,
|
|
15
|
+
beforeTxt: value.substring(0, start),
|
|
16
|
+
afterTxt: value.substring(end)
|
|
17
|
+
};
|
|
18
|
+
} catch (e) {}
|
|
19
|
+
}
|
|
20
|
+
function restoreCursor() {
|
|
21
|
+
if (input && selectionRef.value && focused) try {
|
|
22
|
+
const { value } = input;
|
|
23
|
+
const { beforeTxt, afterTxt, start } = selectionRef.value;
|
|
24
|
+
let startPos = value.length;
|
|
25
|
+
if (beforeTxt && value.startsWith(beforeTxt)) startPos = beforeTxt.length;
|
|
26
|
+
else if (afterTxt && value.endsWith(afterTxt)) startPos = value.length - selectionRef.value.afterTxt.length;
|
|
27
|
+
else {
|
|
28
|
+
const beforeLastChar = beforeTxt[start - 1];
|
|
29
|
+
const newIndex = value.indexOf(beforeLastChar, start - 1);
|
|
30
|
+
if (newIndex !== -1) startPos = newIndex + 1;
|
|
31
|
+
}
|
|
32
|
+
input.setSelectionRange(startPos, startPos);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
(0, __v_c_util_dist_warning.default)(false, `Something warning of cursor restore. Please fire issue about this: ${e.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [recordCursor, restoreCursor];
|
|
38
|
+
}
|
|
39
|
+
exports.default = useCursor;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import warning from "@v-c/util/dist/warning";
|
|
3
|
+
function useCursor(input, focused) {
|
|
4
|
+
const selectionRef = ref(null);
|
|
5
|
+
function recordCursor() {
|
|
6
|
+
try {
|
|
7
|
+
const { selectionStart: start, selectionEnd: end, value } = input;
|
|
8
|
+
selectionRef.value = {
|
|
9
|
+
start,
|
|
10
|
+
end,
|
|
11
|
+
value,
|
|
12
|
+
beforeTxt: value.substring(0, start),
|
|
13
|
+
afterTxt: value.substring(end)
|
|
14
|
+
};
|
|
15
|
+
} catch (e) {}
|
|
16
|
+
}
|
|
17
|
+
function restoreCursor() {
|
|
18
|
+
if (input && selectionRef.value && focused) try {
|
|
19
|
+
const { value } = input;
|
|
20
|
+
const { beforeTxt, afterTxt, start } = selectionRef.value;
|
|
21
|
+
let startPos = value.length;
|
|
22
|
+
if (beforeTxt && value.startsWith(beforeTxt)) startPos = beforeTxt.length;
|
|
23
|
+
else if (afterTxt && value.endsWith(afterTxt)) startPos = value.length - selectionRef.value.afterTxt.length;
|
|
24
|
+
else {
|
|
25
|
+
const beforeLastChar = beforeTxt[start - 1];
|
|
26
|
+
const newIndex = value.indexOf(beforeLastChar, start - 1);
|
|
27
|
+
if (newIndex !== -1) startPos = newIndex + 1;
|
|
28
|
+
}
|
|
29
|
+
input.setSelectionRange(startPos, startPos);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
warning(false, `Something warning of cursor restore. Please fire issue about this: ${e.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return [recordCursor, restoreCursor];
|
|
35
|
+
}
|
|
36
|
+
export { useCursor as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_util_dist_raf = require("@v-c/util/dist/raf");
|
|
5
|
+
__v_c_util_dist_raf = require_rolldown_runtime.__toESM(__v_c_util_dist_raf);
|
|
6
|
+
var useFrame_default = () => {
|
|
7
|
+
const idRef = (0, vue.ref)(0);
|
|
8
|
+
const cleanUp = () => {
|
|
9
|
+
__v_c_util_dist_raf.default.cancel(idRef.value);
|
|
10
|
+
};
|
|
11
|
+
(0, vue.onUnmounted)(cleanUp);
|
|
12
|
+
return (callback) => {
|
|
13
|
+
cleanUp();
|
|
14
|
+
idRef.value = (0, __v_c_util_dist_raf.default)(() => {
|
|
15
|
+
callback();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.default = useFrame_default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { onUnmounted, ref } from "vue";
|
|
2
|
+
import raf from "@v-c/util/dist/raf";
|
|
3
|
+
var useFrame_default = () => {
|
|
4
|
+
const idRef = ref(0);
|
|
5
|
+
const cleanUp = () => {
|
|
6
|
+
raf.cancel(idRef.value);
|
|
7
|
+
};
|
|
8
|
+
onUnmounted(cleanUp);
|
|
9
|
+
return (callback) => {
|
|
10
|
+
cleanUp();
|
|
11
|
+
idRef.value = raf(() => {
|
|
12
|
+
callback();
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export { useFrame_default as default };
|
package/dist/index.cjs
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
2
|
+
let __v_c_mini_decimal = require("@v-c/mini-decimal");
|
|
3
|
+
function getDecupleSteps(step) {
|
|
4
|
+
const stepStr = typeof step === "number" ? (0, __v_c_mini_decimal.num2str)(step) : (0, __v_c_mini_decimal.trimNumber)(step).fullStr;
|
|
5
|
+
if (!stepStr.includes(".")) return `${step}0`;
|
|
6
|
+
return (0, __v_c_mini_decimal.trimNumber)(stepStr.replace(/(\d)\.(\d)/g, "$1$2.")).fullStr;
|
|
7
|
+
}
|
|
8
|
+
exports.getDecupleSteps = getDecupleSteps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDecupleSteps(step: string | number): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { num2str, trimNumber } from "@v-c/mini-decimal";
|
|
2
|
+
function getDecupleSteps(step) {
|
|
3
|
+
const stepStr = typeof step === "number" ? num2str(step) : trimNumber(step).fullStr;
|
|
4
|
+
if (!stepStr.includes(".")) return `${step}0`;
|
|
5
|
+
return trimNumber(stepStr.replace(/(\d)\.(\d)/g, "$1$2.")).fullStr;
|
|
6
|
+
}
|
|
7
|
+
export { getDecupleSteps };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-c/input-number",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./dist/*": "./dist/*",
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"vue": "^3.0.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@v-c/input": "0.0.1",
|
|
28
|
+
"@v-c/util": "0.0.18",
|
|
29
|
+
"@v-c/mini-decimal": "0.0.2"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "vite build",
|
|
33
|
+
"prepublish": "pnpm build",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"bump": "bumpp --release patch"
|
|
36
|
+
}
|
|
37
|
+
}
|