dev #556

Merged
ysCha merged 7 commits from dev into dev-deploy 2026-01-07 17:53:14 +09:00
Showing only changes of commit a5dc5caaf3 - Show all commits

View File

@ -2,11 +2,110 @@ import Image from 'next/image'
import { useMessage } from '@/hooks/useMessage' import { useMessage } from '@/hooks/useMessage'
import { normalizeDecimalLimit, normalizeDigits } from '@/util/input-utils' import { normalizeDecimalLimit, normalizeDigits } from '@/util/input-utils'
import { CalculatorInput } from '@/components/common/input/CalcInput' import { CalculatorInput } from '@/components/common/input/CalcInput'
import { useEffect } from 'react'
export default function Angle({ props }) { export default function Angle({ props }) {
const { getMessage } = useMessage() const { getMessage } = useMessage()
const { angle1, setAngle1, angle1Ref, length1, setLength1, length1Ref } = props const { angle1, setAngle1, angle1Ref, length1, setLength1, length1Ref } = props
const resetCalculatorValue = () => {
// 1. 0
setLength1(0);
if (length1Ref.current) {
// 2. input UI
length1Ref.current.focus();
length1Ref.current.value = '';
// 3. UI
setTimeout(() => {
const acButton = document.querySelector('.keypad-btn.ac, .btn-ac') ||
Array.from(document.querySelectorAll('button')).find(el => el.textContent === 'AC');
if (acButton) {
acButton.click();
} else {
// input Enter/Escape
length1Ref.current.dispatchEvent(new Event('input', { bubbles: true }));
}
// ()
length1Ref.current.focus();
}, 10);
}
}
const resetCalculatorValue2 = () => {
// 1. 0
setAngle1(0);
if (angle1Ref.current) {
// 2. input UI
angle1Ref.current.focus();
angle1Ref.current.value = '';
// 3. UI
setTimeout(() => {
const acButton = document.querySelector('.keypad-btn.ac, .btn-ac') ||
Array.from(document.querySelectorAll('button')).find(el => el.textContent === 'AC');
if (acButton) {
acButton.click();
} else {
// input Enter/Escape
angle1Ref.current.dispatchEvent(new Event('input', { bubbles: true }));
}
// ()
angle1Ref.current.focus();
}, 10);
}
}
//
useEffect(() => {
const handleKeyDown = (e) => {
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
//
setTimeout(() => {
resetCalculatorValue();
}, 0);
return;
}
//
const keypadVisible = document.querySelector('.keypad-container')
//
if (keypadVisible) {
return
}
// input
if (document.activeElement && document.activeElement.classList.contains('calculator-input')) {
return
}
//
if (e.key === 'Enter') {
// (useOuterLineWall.js )
return
}
// input
if (/^[0-9+\-*\/=.]$/.test(e.key) || e.key === 'Backspace' || e.key === 'Delete') {
const calcInput = document.querySelector('.calculator-input')
if (calcInput) {
// preventDefault
calcInput.focus()
calcInput.click()
}
}
}
// capture: true
document.addEventListener('keydown', handleKeyDown, { capture: true })
return () => document.removeEventListener('keydown', handleKeyDown, { capture: true })
}, [])
return ( return (
<> <>
<div className="outline-wrap"> <div className="outline-wrap">
@ -31,19 +130,33 @@ export default function Angle({ props }) {
className="input-origin block" className="input-origin block"
value={angle1} value={angle1}
ref={angle1Ref} ref={angle1Ref}
onChange={(value) => setAngle1(value)} onChange={(value) => {setAngle1(value)
// Convert to number and ensure it's within -180 to 180 range
const numValue = parseInt(value, 10);
if (!isNaN(numValue)) {
const clampedValue = Math.min(180, Math.max(-180, numValue));
setAngle1(String(clampedValue));
} else {
setAngle1(value);
}
}
}
placeholder="45" placeholder="45"
onFocus={() => (angle1Ref.current.value = '')} onFocus={() => (angle1Ref.current.value = '')}
options={{ options={{
allowNegative: false, allowNegative: true,
allowDecimal: true allowDecimal: false
}} }}
/> />
</div> </div>
<button <button
className="reset-btn" className="reset-btn"
onClick={(e) => { onClick={(e) => {
setAngle1(0) e.preventDefault();
e.stopPropagation();
resetCalculatorValue2()
}} }}
></button> ></button>
</div> </div>
@ -77,8 +190,11 @@ export default function Angle({ props }) {
</div> </div>
<button <button
className="reset-btn" className="reset-btn"
onClick={() => { onClick={(e) => {
setLength1(0) e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
}} }}
></button> ></button>
</div> </div>