rc-input-number
Advanced tools
Comparing version 7.4.0 to 7.4.1
@@ -30,2 +30,3 @@ import { useRef } from 'react'; | ||
} | ||
/** | ||
@@ -32,0 +33,0 @@ * Restore logic: |
import { useRef, useEffect } from 'react'; | ||
import raf from "rc-util/es/raf"; | ||
/** | ||
@@ -4,0 +5,0 @@ * Always trigger latest once when call multiple time |
@@ -1,2 +0,2 @@ | ||
import InputNumber from './InputNumber'; | ||
import InputNumber from "./InputNumber"; | ||
export default InputNumber; |
@@ -13,6 +13,7 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import getMiniDecimal, { toFixed, getNumberPrecision, num2str, validateNumber } from '@rc-component/mini-decimal'; | ||
import StepHandler from './StepHandler'; | ||
import { getDecupleSteps } from './utils/numberUtil'; | ||
import useCursor from './hooks/useCursor'; | ||
import useFrame from './hooks/useFrame'; | ||
import StepHandler from "./StepHandler"; | ||
import { getDecupleSteps } from "./utils/numberUtil"; | ||
import useCursor from "./hooks/useCursor"; | ||
import useFrame from "./hooks/useFrame"; | ||
/** | ||
@@ -77,2 +78,3 @@ * We support `stringMode` which need handle correct type when user call in onChange | ||
var shiftKeyRef = React.useRef(false); | ||
// ============================ Value ============================= | ||
@@ -91,2 +93,3 @@ // Real value control | ||
} | ||
// ====================== Parser & Formatter ====================== | ||
@@ -113,2 +116,3 @@ /** | ||
}, [precision, step]); | ||
// >>> Parser | ||
@@ -124,5 +128,7 @@ var mergedParser = React.useCallback(function (num) { | ||
} | ||
// [Legacy] We still support auto convert `$ 123,456` to `123456` | ||
return parsedStr.replace(/[^\w.-]+/g, ''); | ||
}, [parser, decimalSeparator]); | ||
// >>> Formatter | ||
@@ -138,2 +144,3 @@ var inputValueRef = React.useRef(''); | ||
var str = typeof number === 'number' ? num2str(number) : number; | ||
// User typing will not auto format with precision directly | ||
@@ -150,2 +157,3 @@ if (!userTyping) { | ||
}, [formatter, getPrecision, decimalSeparator]); | ||
// ========================== InputValue ========================== | ||
@@ -172,2 +180,3 @@ /** | ||
inputValueRef.current = inputValue; | ||
// Should always be string | ||
@@ -181,2 +190,3 @@ function setInputValue(newValue, userTyping) { | ||
} | ||
// >>> Max & Min limit | ||
@@ -201,2 +211,3 @@ var maxDecimal = React.useMemo(function () { | ||
}, [minDecimal, decimalValue]); | ||
// Cursor controller | ||
@@ -207,2 +218,3 @@ var _useCursor = useCursor(inputRef.current, focus), | ||
restoreCursor = _useCursor2[1]; | ||
// ============================= Data ============================= | ||
@@ -221,2 +233,3 @@ /** | ||
} | ||
// target < min | ||
@@ -228,2 +241,3 @@ if (minDecimal && !minDecimal.lessEquals(target)) { | ||
}; | ||
/** | ||
@@ -235,2 +249,3 @@ * Check value is in [min, max] range | ||
}; | ||
/** | ||
@@ -243,2 +258,3 @@ * Trigger `onChange` if value validated and not equals of origin. | ||
var isRangeValidate = isInRange(updateValue) || updateValue.isEmpty(); | ||
// Skip align value when trigger value is empty. | ||
@@ -257,2 +273,3 @@ // We just trigger onChange(null) | ||
updateValue = getMiniDecimal(toFixed(numStr, '.', mergedPrecision)); | ||
// When to fixed. The value may out of min & max range. | ||
@@ -264,2 +281,3 @@ // 4 in [0, 3.8] => 3.8 => 4 (toFixed) | ||
} | ||
// Trigger event | ||
@@ -269,2 +287,3 @@ if (!updateValue.equals(decimalValue)) { | ||
onChange === null || onChange === void 0 ? void 0 : onChange(updateValue.isEmpty() ? null : getDecimalValue(stringMode, updateValue)); | ||
// Reformat input if value is not controlled | ||
@@ -279,9 +298,13 @@ if (value === undefined) { | ||
}; | ||
// ========================== User Input ========================== | ||
var onNextPromise = useFrame(); | ||
// >>> Collect input value | ||
var collectInputValue = function collectInputValue(inputStr) { | ||
recordCursor(); | ||
// Update inputValue incase input can not parse as number | ||
setInternalInputValue(inputStr); | ||
// Parse number | ||
@@ -295,4 +318,6 @@ if (!compositionRef.current) { | ||
} | ||
// Trigger onInput later to let user customize value if they want do handle something after onChange | ||
onInput === null || onInput === void 0 ? void 0 : onInput(inputStr); | ||
// optimize for chinese input experience | ||
@@ -310,2 +335,3 @@ // https://github.com/ant-design/ant-design/issues/8196 | ||
}; | ||
// >>> Composition | ||
@@ -319,2 +345,3 @@ var onCompositionStart = function onCompositionStart() { | ||
}; | ||
// >>> Input | ||
@@ -324,2 +351,3 @@ var onInternalInput = function onInternalInput(e) { | ||
}; | ||
// ============================= Step ============================= | ||
@@ -332,2 +360,3 @@ var onInternalStep = function onInternalStep(up) { | ||
} | ||
// Clear typing status since it may caused by up & down key. | ||
@@ -348,2 +377,3 @@ // We should sync with input value. | ||
}; | ||
// ============================ Flush ============================= | ||
@@ -371,2 +401,3 @@ /** | ||
}; | ||
// Solve the issue of the event triggering sequence when entering numbers in chinese input (Safari) | ||
@@ -395,2 +426,3 @@ var onBeforeInput = function onBeforeInput() { | ||
} | ||
// Do step | ||
@@ -406,2 +438,3 @@ if (!compositionRef.current && [KeyCode.UP, KeyCode.DOWN].includes(which)) { | ||
}; | ||
// >>> Focus & Blur | ||
@@ -413,2 +446,3 @@ var onBlur = function onBlur() { | ||
}; | ||
// ========================== Controlled ========================== | ||
@@ -421,2 +455,3 @@ // Input by precision | ||
}, [precision]); | ||
// Input by value | ||
@@ -427,2 +462,3 @@ useLayoutUpdateEffect(function () { | ||
var currentParsedValue = getMiniDecimal(mergedParser(inputValue)); | ||
// When user typing from `1.2` to `1.`, we should not convert to `1` immediately. | ||
@@ -435,2 +471,3 @@ // But let it go if user set `formatter` | ||
}, [value]); | ||
// ============================ Cursor ============================ | ||
@@ -442,2 +479,3 @@ useLayoutUpdateEffect(function () { | ||
}, [inputValue]); | ||
// ============================ Render ============================ | ||
@@ -444,0 +482,0 @@ return /*#__PURE__*/React.createElement("div", { |
@@ -6,3 +6,4 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import classNames from 'classnames'; | ||
import isMobile from "rc-util/es/isMobile"; | ||
import useMobile from "rc-util/es/hooks/useMobile"; | ||
/** | ||
@@ -12,2 +13,3 @@ * When click and hold on a button - the speed of auto changing the value. | ||
var STEP_INTERVAL = 200; | ||
/** | ||
@@ -28,2 +30,3 @@ * When click and hold on a button - the delay before auto changing the value. | ||
onStepRef.current = onStep; | ||
// We will interval update step when hold mouse down | ||
@@ -33,2 +36,3 @@ var onStepMouseDown = function onStepMouseDown(e, up) { | ||
onStepRef.current(up); | ||
// Loop step for interval | ||
@@ -39,2 +43,3 @@ function loopStep() { | ||
} | ||
// First time press will wait some time to trigger loop step update | ||
@@ -49,4 +54,6 @@ stepTimeoutRef.current = setTimeout(loopStep, STEP_DELAY); | ||
}, []); | ||
// ======================= Render ======================= | ||
if (isMobile()) { | ||
var isMobile = useMobile(); | ||
if (isMobile) { | ||
return null; | ||
@@ -53,0 +60,0 @@ } |
@@ -37,2 +37,3 @@ "use strict"; | ||
} | ||
/** | ||
@@ -39,0 +40,0 @@ * Restore logic: |
@@ -86,2 +86,3 @@ "use strict"; | ||
var shiftKeyRef = React.useRef(false); | ||
// ============================ Value ============================= | ||
@@ -100,2 +101,3 @@ // Real value control | ||
} | ||
// ====================== Parser & Formatter ====================== | ||
@@ -122,2 +124,3 @@ /** | ||
}, [precision, step]); | ||
// >>> Parser | ||
@@ -133,5 +136,7 @@ var mergedParser = React.useCallback(function (num) { | ||
} | ||
// [Legacy] We still support auto convert `$ 123,456` to `123456` | ||
return parsedStr.replace(/[^\w.-]+/g, ''); | ||
}, [parser, decimalSeparator]); | ||
// >>> Formatter | ||
@@ -147,2 +152,3 @@ var inputValueRef = React.useRef(''); | ||
var str = typeof number === 'number' ? (0, _miniDecimal.num2str)(number) : number; | ||
// User typing will not auto format with precision directly | ||
@@ -159,2 +165,3 @@ if (!userTyping) { | ||
}, [formatter, getPrecision, decimalSeparator]); | ||
// ========================== InputValue ========================== | ||
@@ -181,2 +188,3 @@ /** | ||
inputValueRef.current = inputValue; | ||
// Should always be string | ||
@@ -190,2 +198,3 @@ function setInputValue(newValue, userTyping) { | ||
} | ||
// >>> Max & Min limit | ||
@@ -210,2 +219,3 @@ var maxDecimal = React.useMemo(function () { | ||
}, [minDecimal, decimalValue]); | ||
// Cursor controller | ||
@@ -216,2 +226,3 @@ var _useCursor = (0, _useCursor3.default)(inputRef.current, focus), | ||
restoreCursor = _useCursor2[1]; | ||
// ============================= Data ============================= | ||
@@ -230,2 +241,3 @@ /** | ||
} | ||
// target < min | ||
@@ -237,2 +249,3 @@ if (minDecimal && !minDecimal.lessEquals(target)) { | ||
}; | ||
/** | ||
@@ -244,2 +257,3 @@ * Check value is in [min, max] range | ||
}; | ||
/** | ||
@@ -252,2 +266,3 @@ * Trigger `onChange` if value validated and not equals of origin. | ||
var isRangeValidate = isInRange(updateValue) || updateValue.isEmpty(); | ||
// Skip align value when trigger value is empty. | ||
@@ -266,2 +281,3 @@ // We just trigger onChange(null) | ||
updateValue = (0, _miniDecimal.default)((0, _miniDecimal.toFixed)(numStr, '.', mergedPrecision)); | ||
// When to fixed. The value may out of min & max range. | ||
@@ -273,2 +289,3 @@ // 4 in [0, 3.8] => 3.8 => 4 (toFixed) | ||
} | ||
// Trigger event | ||
@@ -278,2 +295,3 @@ if (!updateValue.equals(decimalValue)) { | ||
onChange === null || onChange === void 0 ? void 0 : onChange(updateValue.isEmpty() ? null : getDecimalValue(stringMode, updateValue)); | ||
// Reformat input if value is not controlled | ||
@@ -288,9 +306,13 @@ if (value === undefined) { | ||
}; | ||
// ========================== User Input ========================== | ||
var onNextPromise = (0, _useFrame.default)(); | ||
// >>> Collect input value | ||
var collectInputValue = function collectInputValue(inputStr) { | ||
recordCursor(); | ||
// Update inputValue incase input can not parse as number | ||
setInternalInputValue(inputStr); | ||
// Parse number | ||
@@ -304,4 +326,6 @@ if (!compositionRef.current) { | ||
} | ||
// Trigger onInput later to let user customize value if they want do handle something after onChange | ||
onInput === null || onInput === void 0 ? void 0 : onInput(inputStr); | ||
// optimize for chinese input experience | ||
@@ -319,2 +343,3 @@ // https://github.com/ant-design/ant-design/issues/8196 | ||
}; | ||
// >>> Composition | ||
@@ -328,2 +353,3 @@ var onCompositionStart = function onCompositionStart() { | ||
}; | ||
// >>> Input | ||
@@ -333,2 +359,3 @@ var onInternalInput = function onInternalInput(e) { | ||
}; | ||
// ============================= Step ============================= | ||
@@ -341,2 +368,3 @@ var onInternalStep = function onInternalStep(up) { | ||
} | ||
// Clear typing status since it may caused by up & down key. | ||
@@ -357,2 +385,3 @@ // We should sync with input value. | ||
}; | ||
// ============================ Flush ============================= | ||
@@ -380,2 +409,3 @@ /** | ||
}; | ||
// Solve the issue of the event triggering sequence when entering numbers in chinese input (Safari) | ||
@@ -404,2 +434,3 @@ var onBeforeInput = function onBeforeInput() { | ||
} | ||
// Do step | ||
@@ -415,2 +446,3 @@ if (!compositionRef.current && [_KeyCode.default.UP, _KeyCode.default.DOWN].includes(which)) { | ||
}; | ||
// >>> Focus & Blur | ||
@@ -422,2 +454,3 @@ var onBlur = function onBlur() { | ||
}; | ||
// ========================== Controlled ========================== | ||
@@ -430,2 +463,3 @@ // Input by precision | ||
}, [precision]); | ||
// Input by value | ||
@@ -436,2 +470,3 @@ (0, _useLayoutEffect.useLayoutUpdateEffect)(function () { | ||
var currentParsedValue = (0, _miniDecimal.default)(mergedParser(inputValue)); | ||
// When user typing from `1.2` to `1.`, we should not convert to `1` immediately. | ||
@@ -444,2 +479,3 @@ // But let it go if user set `formatter` | ||
}, [value]); | ||
// ============================ Cursor ============================ | ||
@@ -451,2 +487,3 @@ (0, _useLayoutEffect.useLayoutUpdateEffect)(function () { | ||
}, [inputValue]); | ||
// ============================ Render ============================ | ||
@@ -453,0 +490,0 @@ return /*#__PURE__*/React.createElement("div", { |
@@ -13,3 +13,3 @@ "use strict"; | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _isMobile = _interopRequireDefault(require("rc-util/lib/isMobile")); | ||
var _useMobile = _interopRequireDefault(require("rc-util/lib/hooks/useMobile")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -23,2 +23,3 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var STEP_INTERVAL = 200; | ||
/** | ||
@@ -39,2 +40,3 @@ * When click and hold on a button - the delay before auto changing the value. | ||
onStepRef.current = onStep; | ||
// We will interval update step when hold mouse down | ||
@@ -44,2 +46,3 @@ var onStepMouseDown = function onStepMouseDown(e, up) { | ||
onStepRef.current(up); | ||
// Loop step for interval | ||
@@ -50,2 +53,3 @@ function loopStep() { | ||
} | ||
// First time press will wait some time to trigger loop step update | ||
@@ -60,4 +64,6 @@ stepTimeoutRef.current = setTimeout(loopStep, STEP_DELAY); | ||
}, []); | ||
// ======================= Render ======================= | ||
if ((0, _isMobile.default)()) { | ||
var isMobile = (0, _useMobile.default)(); | ||
if (isMobile) { | ||
return null; | ||
@@ -64,0 +70,0 @@ } |
{ | ||
"name": "rc-input-number", | ||
"version": "7.4.0", | ||
"version": "7.4.1", | ||
"description": "React input-number component", | ||
@@ -23,2 +23,3 @@ "keywords": [ | ||
"module": "./es/index", | ||
"types": "./es/index.d.ts", | ||
"files": [ | ||
@@ -30,4 +31,4 @@ "lib", | ||
"scripts": { | ||
"compile": "father-build && lessc assets/index.less assets/index.css", | ||
"coverage": "father test --coverage", | ||
"compile": "father build && lessc assets/index.less assets/index.css", | ||
"coverage": "rc-test --coverage", | ||
"docs:build": "dumi build", | ||
@@ -37,7 +38,14 @@ "docs:deploy": "gh-pages -d docs-dist", | ||
"now-build": "npm run docs:build", | ||
"prepare": "husky install", | ||
"prepublishOnly": "npm run compile && np --yolo --no-publish", | ||
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"", | ||
"start": "dumi dev", | ||
"test": "father test" | ||
"test": "rc-test" | ||
}, | ||
"lint-staged": { | ||
"**/*.{js,jsx,tsx,ts,md,json}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -47,23 +55,28 @@ "@babel/runtime": "^7.10.1", | ||
"classnames": "^2.2.5", | ||
"rc-util": "^5.23.0" | ||
"rc-util": "^5.25.0" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^13.3.0", | ||
"@rc-component/father-plugin": "^1.0.1", | ||
"@swc-node/jest": "^1.5.5", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@types/classnames": "^2.2.9", | ||
"@types/enzyme": "^3.10.8", | ||
"@types/jest": "^29.2.3", | ||
"@types/react": "^17.0.37", | ||
"@types/react-dom": "^17.0.9", | ||
"@types/jest": "^29.2.4", | ||
"@types/react": "^18.0.26", | ||
"@types/react-dom": "^18.0.9", | ||
"@types/responselike": "^1.0.0", | ||
"@umijs/fabric": "^2.0.0", | ||
"cross-env": "^7.0.0", | ||
"dumi": "^1.1.0", | ||
"@umijs/test": "^4.0.36", | ||
"cross-env": "^7.0.3", | ||
"dumi": "^2.0.13", | ||
"eslint": "^7.1.0", | ||
"expect.js": "~0.3.1", | ||
"father": "^2.22.0", | ||
"father-build": "^1.19.1", | ||
"father": "^4.1.1", | ||
"glob": "^7.1.6", | ||
"husky": "^8.0.3", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"less": "^3.12.2", | ||
"lint-staged": "^13.1.2", | ||
"np": "^7.2.0", | ||
"rc-test": "^7.0.14", | ||
"rc-tooltip": "^5.0.2", | ||
@@ -73,3 +86,4 @@ "react": "^18.2.0", | ||
"regenerator-runtime": "^0.13.7", | ||
"typescript": "^4.0.2" | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -76,0 +90,0 @@ "peerDependencies": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
72225
1537
29
1
Updatedrc-util@^5.25.0