2025-09-11 18:38:28 +09:00
|
|
|
"use client";
|
|
|
|
|
|
2025-09-19 12:19:34 +09:00
|
|
|
import React, { useEffect, useState } from "react";
|
2025-09-11 18:38:28 +09:00
|
|
|
import { ComponentRendererProps } from "@/types/component";
|
2025-09-19 12:19:34 +09:00
|
|
|
import { AutoGenerationConfig } from "@/types/screen";
|
2025-09-11 18:38:28 +09:00
|
|
|
import { TextInputConfig } from "./types";
|
2025-09-19 02:15:21 +09:00
|
|
|
import { filterDOMProps } from "@/lib/utils/domPropsFilter";
|
2025-09-19 12:19:34 +09:00
|
|
|
import { AutoGenerationUtils } from "@/lib/utils/autoGeneration";
|
2025-09-11 18:38:28 +09:00
|
|
|
|
|
|
|
|
export interface TextInputComponentProps extends ComponentRendererProps {
|
|
|
|
|
config?: TextInputConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TextInput 컴포넌트
|
|
|
|
|
* text-input 컴포넌트입니다
|
|
|
|
|
*/
|
|
|
|
|
export const TextInputComponent: React.FC<TextInputComponentProps> = ({
|
|
|
|
|
component,
|
|
|
|
|
isDesignMode = false,
|
|
|
|
|
isSelected = false,
|
2025-09-12 14:24:25 +09:00
|
|
|
isInteractive = false,
|
2025-09-11 18:38:28 +09:00
|
|
|
onClick,
|
|
|
|
|
onDragStart,
|
|
|
|
|
onDragEnd,
|
|
|
|
|
config,
|
|
|
|
|
className,
|
|
|
|
|
style,
|
2025-09-12 14:24:25 +09:00
|
|
|
formData,
|
|
|
|
|
onFormDataChange,
|
2025-09-11 18:38:28 +09:00
|
|
|
...props
|
|
|
|
|
}) => {
|
|
|
|
|
// 컴포넌트 설정
|
|
|
|
|
const componentConfig = {
|
|
|
|
|
...config,
|
|
|
|
|
...component.config,
|
|
|
|
|
} as TextInputConfig;
|
|
|
|
|
|
2025-09-19 12:19:34 +09:00
|
|
|
// 자동생성 설정 (props에서 전달받은 값 우선 사용)
|
|
|
|
|
const autoGeneration: AutoGenerationConfig = props.autoGeneration ||
|
|
|
|
|
component.autoGeneration ||
|
|
|
|
|
componentConfig.autoGeneration || {
|
|
|
|
|
type: "none",
|
|
|
|
|
enabled: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 숨김 상태 (props에서 전달받은 값 우선 사용)
|
|
|
|
|
const isHidden = props.hidden !== undefined ? props.hidden : component.hidden || componentConfig.hidden || false;
|
|
|
|
|
|
|
|
|
|
// 자동생성된 값 상태
|
|
|
|
|
const [autoGeneratedValue, setAutoGeneratedValue] = useState<string>("");
|
|
|
|
|
|
|
|
|
|
// 테스트용: 컴포넌트 라벨에 "test"가 포함되면 강제로 UUID 자동생성 활성화
|
|
|
|
|
const testAutoGeneration = component.label?.toLowerCase().includes("test")
|
|
|
|
|
? {
|
|
|
|
|
type: "uuid" as AutoGenerationType,
|
|
|
|
|
enabled: true,
|
|
|
|
|
}
|
|
|
|
|
: autoGeneration;
|
|
|
|
|
|
2025-09-12 14:24:25 +09:00
|
|
|
console.log("🔧 텍스트 입력 컴포넌트 설정:", {
|
|
|
|
|
config,
|
|
|
|
|
componentConfig,
|
|
|
|
|
component: component,
|
2025-09-19 12:19:34 +09:00
|
|
|
autoGeneration,
|
|
|
|
|
testAutoGeneration,
|
|
|
|
|
isTestMode: component.label?.toLowerCase().includes("test"),
|
|
|
|
|
isHidden,
|
|
|
|
|
isInteractive,
|
|
|
|
|
formData,
|
|
|
|
|
columnName: component.columnName,
|
|
|
|
|
currentFormValue: formData?.[component.columnName],
|
|
|
|
|
componentValue: component.value,
|
|
|
|
|
autoGeneratedValue,
|
2025-09-12 14:24:25 +09:00
|
|
|
});
|
|
|
|
|
|
2025-09-19 12:19:34 +09:00
|
|
|
// 자동생성 값 생성 (컴포넌트 마운트 시 또는 폼 데이터 변경 시)
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
console.log("🔄 자동생성 useEffect 실행:", {
|
|
|
|
|
enabled: testAutoGeneration.enabled,
|
|
|
|
|
type: testAutoGeneration.type,
|
|
|
|
|
isInteractive,
|
|
|
|
|
columnName: component.columnName,
|
|
|
|
|
hasFormData: !!formData,
|
|
|
|
|
hasOnFormDataChange: !!onFormDataChange,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (testAutoGeneration.enabled && testAutoGeneration.type !== "none") {
|
|
|
|
|
// 폼 데이터에 이미 값이 있으면 자동생성하지 않음
|
|
|
|
|
const currentFormValue = formData?.[component.columnName];
|
|
|
|
|
const currentComponentValue = component.value;
|
|
|
|
|
|
|
|
|
|
console.log("🔍 자동생성 조건 확인:", {
|
|
|
|
|
currentFormValue,
|
|
|
|
|
currentComponentValue,
|
|
|
|
|
hasCurrentValue: !!(currentFormValue || currentComponentValue),
|
|
|
|
|
autoGeneratedValue,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 자동생성된 값이 없고, 현재 값도 없을 때만 생성
|
|
|
|
|
if (!autoGeneratedValue && !currentFormValue && !currentComponentValue) {
|
|
|
|
|
const generatedValue = AutoGenerationUtils.generateValue(testAutoGeneration, component.columnName);
|
|
|
|
|
console.log("✨ 자동생성된 값:", generatedValue);
|
|
|
|
|
|
|
|
|
|
if (generatedValue) {
|
|
|
|
|
setAutoGeneratedValue(generatedValue);
|
|
|
|
|
|
|
|
|
|
// 폼 데이터에 자동생성된 값 설정 (인터랙티브 모드에서만)
|
|
|
|
|
if (isInteractive && onFormDataChange && component.columnName) {
|
|
|
|
|
console.log("📝 폼 데이터에 자동생성 값 설정:", {
|
|
|
|
|
columnName: component.columnName,
|
|
|
|
|
value: generatedValue,
|
|
|
|
|
});
|
|
|
|
|
onFormDataChange(component.columnName, generatedValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (!autoGeneratedValue && testAutoGeneration.type !== "none") {
|
|
|
|
|
// 디자인 모드에서도 미리보기용 자동생성 값 표시
|
|
|
|
|
const previewValue = AutoGenerationUtils.generatePreviewValue(testAutoGeneration);
|
|
|
|
|
console.log("🎨 디자인 모드 미리보기 값:", previewValue);
|
|
|
|
|
setAutoGeneratedValue(previewValue);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("⏭️ 이미 값이 있어서 자동생성 건너뜀:", {
|
|
|
|
|
hasAutoGenerated: !!autoGeneratedValue,
|
|
|
|
|
hasFormValue: !!currentFormValue,
|
|
|
|
|
hasComponentValue: !!currentComponentValue,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [testAutoGeneration, isInteractive, component.columnName, component.value, formData, onFormDataChange]);
|
|
|
|
|
|
2025-09-11 18:38:28 +09:00
|
|
|
// 스타일 계산 (위치는 RealtimePreviewDynamic에서 처리하므로 제외)
|
|
|
|
|
const componentStyle: React.CSSProperties = {
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
...component.style,
|
|
|
|
|
...style,
|
2025-09-19 12:19:34 +09:00
|
|
|
// 숨김 기능: 디자인 모드에서는 연하게, 실제 화면에서는 완전히 숨김
|
|
|
|
|
...(isHidden && {
|
|
|
|
|
opacity: isDesignMode ? 0.4 : 0,
|
|
|
|
|
backgroundColor: isDesignMode ? "#f3f4f6" : "transparent",
|
|
|
|
|
pointerEvents: isDesignMode ? "auto" : "none",
|
|
|
|
|
display: isDesignMode ? "block" : "none",
|
|
|
|
|
}),
|
2025-09-11 18:38:28 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 디자인 모드 스타일
|
|
|
|
|
if (isDesignMode) {
|
|
|
|
|
componentStyle.border = "1px dashed #cbd5e1";
|
|
|
|
|
componentStyle.borderColor = isSelected ? "#3b82f6" : "#cbd5e1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 이벤트 핸들러
|
|
|
|
|
const handleClick = (e: React.MouseEvent) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onClick?.();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// DOM에 전달하면 안 되는 React-specific props 필터링
|
|
|
|
|
const {
|
|
|
|
|
selectedScreen,
|
|
|
|
|
onZoneComponentDrop,
|
|
|
|
|
onZoneClick,
|
|
|
|
|
componentConfig: _componentConfig,
|
|
|
|
|
component: _component,
|
|
|
|
|
isSelected: _isSelected,
|
|
|
|
|
onClick: _onClick,
|
|
|
|
|
onDragStart: _onDragStart,
|
|
|
|
|
onDragEnd: _onDragEnd,
|
|
|
|
|
size: _size,
|
|
|
|
|
position: _position,
|
|
|
|
|
style: _style,
|
2025-09-12 14:24:25 +09:00
|
|
|
screenId: _screenId,
|
|
|
|
|
tableName: _tableName,
|
|
|
|
|
onRefresh: _onRefresh,
|
|
|
|
|
onClose: _onClose,
|
2025-09-11 18:38:28 +09:00
|
|
|
...domProps
|
|
|
|
|
} = props;
|
|
|
|
|
|
2025-09-19 02:15:21 +09:00
|
|
|
// DOM 안전한 props만 필터링
|
|
|
|
|
const safeDomProps = filterDOMProps(domProps);
|
|
|
|
|
|
2025-09-11 18:38:28 +09:00
|
|
|
return (
|
2025-09-19 02:15:21 +09:00
|
|
|
<div style={componentStyle} className={className} {...safeDomProps}>
|
2025-09-11 18:38:28 +09:00
|
|
|
{/* 라벨 렌더링 */}
|
2025-09-19 02:15:21 +09:00
|
|
|
{component.label && component.style?.labelDisplay !== false && (
|
2025-09-11 18:38:28 +09:00
|
|
|
<label
|
|
|
|
|
style={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "-25px",
|
|
|
|
|
left: "0px",
|
|
|
|
|
fontSize: component.style?.labelFontSize || "14px",
|
|
|
|
|
color: component.style?.labelColor || "#374151",
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{component.label}
|
|
|
|
|
{component.required && <span style={{ color: "#ef4444" }}>*</span>}
|
|
|
|
|
</label>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
2025-09-19 12:19:34 +09:00
|
|
|
value={(() => {
|
|
|
|
|
let displayValue = "";
|
|
|
|
|
|
|
|
|
|
if (isInteractive && formData && component.columnName) {
|
|
|
|
|
// 인터랙티브 모드: formData 우선, 없으면 자동생성 값
|
|
|
|
|
displayValue = formData[component.columnName] || autoGeneratedValue || "";
|
|
|
|
|
} else {
|
|
|
|
|
// 디자인 모드: component.value 우선, 없으면 자동생성 값
|
|
|
|
|
displayValue = component.value || autoGeneratedValue || "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("📄 Input 값 계산:", {
|
|
|
|
|
isInteractive,
|
|
|
|
|
hasFormData: !!formData,
|
|
|
|
|
columnName: component.columnName,
|
|
|
|
|
formDataValue: formData?.[component.columnName],
|
|
|
|
|
componentValue: component.value,
|
|
|
|
|
autoGeneratedValue,
|
|
|
|
|
finalDisplayValue: displayValue,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return displayValue;
|
|
|
|
|
})()}
|
|
|
|
|
placeholder={
|
|
|
|
|
testAutoGeneration.enabled && testAutoGeneration.type !== "none"
|
|
|
|
|
? `자동생성: ${AutoGenerationUtils.getTypeDescription(testAutoGeneration.type)}`
|
|
|
|
|
: componentConfig.placeholder || ""
|
2025-09-12 14:24:25 +09:00
|
|
|
}
|
2025-09-11 18:38:28 +09:00
|
|
|
disabled={componentConfig.disabled || false}
|
|
|
|
|
required={componentConfig.required || false}
|
2025-09-19 12:19:34 +09:00
|
|
|
readOnly={componentConfig.readonly || (testAutoGeneration.enabled && testAutoGeneration.type !== "none")}
|
2025-09-11 18:38:28 +09:00
|
|
|
style={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
border: "1px solid #d1d5db",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
padding: "8px 12px",
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
outline: "none",
|
2025-09-12 14:24:25 +09:00
|
|
|
// isInteractive 모드에서는 사용자 스타일 우선 적용
|
|
|
|
|
...(isInteractive && component.style ? component.style : {}),
|
2025-09-11 18:38:28 +09:00
|
|
|
}}
|
|
|
|
|
onClick={handleClick}
|
|
|
|
|
onDragStart={onDragStart}
|
|
|
|
|
onDragEnd={onDragEnd}
|
|
|
|
|
onChange={(e) => {
|
2025-09-12 14:24:25 +09:00
|
|
|
const newValue = e.target.value;
|
2025-09-19 02:15:21 +09:00
|
|
|
console.log("🎯 TextInputComponent onChange 호출:", {
|
2025-09-18 10:05:50 +09:00
|
|
|
componentId: component.id,
|
|
|
|
|
columnName: component.columnName,
|
|
|
|
|
newValue,
|
|
|
|
|
isInteractive,
|
|
|
|
|
hasOnFormDataChange: !!onFormDataChange,
|
|
|
|
|
hasOnChange: !!props.onChange,
|
|
|
|
|
});
|
2025-09-12 14:24:25 +09:00
|
|
|
|
|
|
|
|
// isInteractive 모드에서는 formData 업데이트
|
|
|
|
|
if (isInteractive && onFormDataChange && component.columnName) {
|
2025-09-18 10:05:50 +09:00
|
|
|
console.log(`📤 TextInputComponent -> onFormDataChange 호출: ${component.columnName} = "${newValue}"`);
|
2025-09-19 02:15:21 +09:00
|
|
|
console.log("🔍 onFormDataChange 함수 정보:", {
|
2025-09-18 10:05:50 +09:00
|
|
|
functionName: onFormDataChange.name,
|
|
|
|
|
functionString: onFormDataChange.toString().substring(0, 200),
|
|
|
|
|
});
|
2025-09-12 14:24:25 +09:00
|
|
|
onFormDataChange(component.columnName, newValue);
|
2025-09-18 10:05:50 +09:00
|
|
|
} else {
|
2025-09-19 02:15:21 +09:00
|
|
|
console.log("❌ TextInputComponent onFormDataChange 조건 미충족:", {
|
2025-09-18 10:05:50 +09:00
|
|
|
isInteractive,
|
|
|
|
|
hasOnFormDataChange: !!onFormDataChange,
|
|
|
|
|
hasColumnName: !!component.columnName,
|
|
|
|
|
});
|
2025-09-12 14:24:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 기존 onChange 핸들러도 호출
|
2025-09-11 18:38:28 +09:00
|
|
|
if (props.onChange) {
|
2025-09-18 10:05:50 +09:00
|
|
|
console.log(`📤 TextInputComponent -> props.onChange 호출: "${newValue}"`);
|
2025-09-12 14:24:25 +09:00
|
|
|
props.onChange(newValue);
|
2025-09-11 18:38:28 +09:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TextInput 래퍼 컴포넌트
|
|
|
|
|
* 추가적인 로직이나 상태 관리가 필요한 경우 사용
|
|
|
|
|
*/
|
|
|
|
|
export const TextInputWrapper: React.FC<TextInputComponentProps> = (props) => {
|
|
|
|
|
return <TextInputComponent {...props} />;
|
|
|
|
|
};
|