Compare commits
No commits in common. "112212170b6571fd4ec09d813617dd5fd1f16cab" and "441800fc1c95976c6f3e1df8816896315c0c4b62" have entirely different histories.
112212170b
...
441800fc1c
@ -22,7 +22,7 @@ import { stuffSearchState } from '@/store/stuffAtom'
|
|||||||
import { QcastContext } from '@/app/QcastProvider'
|
import { QcastContext } from '@/app/QcastProvider'
|
||||||
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
|
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
|
||||||
import { useSwal } from '@/hooks/useSwal'
|
import { useSwal } from '@/hooks/useSwal'
|
||||||
import { sanitizeIntegerInputEvent } from '@/util/input-utils'
|
import { sanitizeDecimalInputEvent} from '@/util/input-utils'
|
||||||
|
|
||||||
export default function StuffDetail() {
|
export default function StuffDetail() {
|
||||||
const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState)
|
const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState)
|
||||||
|
|||||||
@ -24,38 +24,15 @@ export const onlyNumberWithDotInputChange = (e, callback) => {
|
|||||||
// Number normalization utilities
|
// Number normalization utilities
|
||||||
// =============================
|
// =============================
|
||||||
// 1) Normalize any string to NFKC and keep only ASCII digits 0-9.
|
// 1) Normalize any string to NFKC and keep only ASCII digits 0-9.
|
||||||
// 1) Normalize any string to keep only ASCII digits 0-9
|
|
||||||
export function normalizeDigits(value) {
|
export function normalizeDigits(value) {
|
||||||
if (value == null) return '';
|
return String(value ?? '').normalize('NFKC').replace(/[^0-9]/g, '')
|
||||||
|
|
||||||
// First convert full-width numbers to half-width
|
|
||||||
const str = String(value).replace(/[0-9]/g, s =>
|
|
||||||
String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Then remove all non-digit characters
|
|
||||||
return str.replace(/\D/g, '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) Normalize decimal numbers (allow one dot)
|
// 2) Normalize decimal numbers (allow one dot).
|
||||||
export function normalizeDecimal(value) {
|
export function normalizeDecimal(value) {
|
||||||
if (value == null) return '';
|
const s = String(value ?? '').normalize('NFKC').replace(/[^0-9.]/g, '')
|
||||||
|
const [head, ...rest] = s.split('.')
|
||||||
// Convert full-width numbers and dot to half-width
|
return rest.length ? `${head}.${rest.join('').replace(/\./g, '')}` : head
|
||||||
let str = String(value).replace(/[0-9.]/g, s =>
|
|
||||||
s === '.' ? '.' : String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle multiple dots by keeping only the first one
|
|
||||||
const parts = str.split('.');
|
|
||||||
if (parts.length > 1) {
|
|
||||||
str = parts[0] + '.' + parts.slice(1).join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove any remaining non-digit and non-dot characters
|
|
||||||
// and ensure only one dot remains
|
|
||||||
return str.replace(/[^\d.]/g, '')
|
|
||||||
.replace(/^(\d*\.\d*).*$/, '$1');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2-1) Limit fractional digits for decimal numbers. Default to 2 digits.
|
// 2-1) Limit fractional digits for decimal numbers. Default to 2 digits.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user