Merge pull request '초기화' (#559) from dev into prd-deploy

Reviewed-on: #559
This commit is contained in:
ysCha 2026-01-08 10:18:14 +09:00
commit dd2ee6385a
3 changed files with 35 additions and 181 deletions

View File

@ -23,8 +23,23 @@ export const CalculatorInput = forwardRef(
}, [ref])
// Sync displayValue with value prop
// useEffect(() => {
// setDisplayValue(value || '0')
// }, [value])
useEffect(() => {
setDisplayValue(value || '0')
const newValue = value || '0'
setDisplayValue(newValue)
// value
const calculator = calculatorRef.current
if (calculator) {
//
calculator.currentOperand = newValue.toString()
calculator.previousOperand = ''
calculator.operation = undefined
setHasOperation(false)
}
}, [value])
//

View File

@ -8,104 +8,6 @@ export default function Angle({ props }) {
const { getMessage } = useMessage()
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 (
<>
<div className="outline-wrap">
@ -130,33 +32,29 @@ export default function Angle({ props }) {
className="input-origin block"
value={angle1}
ref={angle1Ref}
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);
}
onChange={(value) => {
// Calculate the final value first
let finalValue = value;
const numValue = parseInt(value, 10);
if (!isNaN(numValue)) {
const clampedValue = Math.min(180, Math.max(-180, numValue));
finalValue = String(clampedValue);
}
}
// Set state once with the final value
setAngle1(finalValue);
}}
placeholder="45"
onFocus={() => (angle1Ref.current.value = '')}
options={{
allowNegative: true,
allowDecimal: false
allowDecimal: true
}}
/>
</div>
<button
className="reset-btn"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
resetCalculatorValue2()
setAngle1(0)
}}
></button>
</div>
@ -190,11 +88,8 @@ export default function Angle({ props }) {
</div>
<button
className="reset-btn"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
onClick={() => {
setLength1(0)
}}
></button>
</div>

View File

@ -11,44 +11,9 @@ export default function OuterLineWall({ props }) {
const { length1, setLength1, length1Ref, arrow1, setArrow1 } = 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);
}
}
//
useEffect(() => {
const handleKeyDown = (e) => {
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
//
setTimeout(() => {
resetCalculatorValue();
}, 0);
return;
}
//
const keypadVisible = document.querySelector('.keypad-container')
@ -123,58 +88,37 @@ export default function OuterLineWall({ props }) {
}}
/>
</div>
<button
className="reset-btn"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
}}
></button>
<button className="reset-btn" onClick={() => setLength1(0)}></button>
</div>
<div className="outline-form">
<span>{getMessage('modal.cover.outline.arrow')}</span>
<div className="grid-direction">
<button
className={`direction up ${arrow1 === '↑' ? 'act' : ''}`}
onClick={(e) => {
onClick={() => {
setArrow1('↑')
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
}}
></button>
<button
className={`direction down ${arrow1 === '↓' ? 'act' : ''}`}
onClick={(e) => {
onClick={() => {
setArrow1('↓')
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
}}
></button>
<button
className={`direction left ${arrow1 === '←' ? 'act' : ''}`}
onClick={(e) => {
onClick={() => {
setArrow1('←')
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))
e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
}}
></button>
<button
className={`direction right ${arrow1 === '→' ? 'act' : ''}`}
onClick={(e) => {
onClick={() => {
setArrow1('→')
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
e.preventDefault();
e.stopPropagation();
resetCalculatorValue()
}}
></button>
</div>