셀선택시 프롬프트 창에 자동 입력 완료

This commit is contained in:
sheetEasy AI Team
2025-06-25 16:18:23 +09:00
parent 5712c40ec9
commit 17d17511f5
6 changed files with 458 additions and 146 deletions

View File

@@ -15,6 +15,13 @@ import { UniverUIPlugin } from "@univerjs/ui";
import { cn } from "../../lib/utils";
import LuckyExcel from "@zwight/luckyexcel";
import PromptInput from "./PromptInput";
import { useAppStore } from "../../stores/useAppStore";
import { rangeToAddress } from "../../utils/cellUtils";
import { CellSelectionHandler } from "../../utils/cellSelectionHandler";
// Facade API imports - 공식 문서 방식 (필요한 기능만 선택적 import)
import "@univerjs/sheets/facade";
import "@univerjs/sheets-ui/facade";
// 언어팩 import
import DesignEnUS from "@univerjs/design/locale/en-US";
@@ -279,85 +286,99 @@ const TestSheetViewer: React.FC = () => {
const fileInputRef = useRef<HTMLInputElement>(null);
const mountedRef = useRef<boolean>(false);
const [isInitialized, setIsInitialized] = useState(false);
const [isInitialized, setIsInitialized] = useState<boolean>(false);
const [showUploadOverlay, setShowUploadOverlay] = useState(true);
const [isDragOver, setIsDragOver] = useState(false);
const [isProcessing, setIsProcessing] = useState(false);
const [currentFile, setCurrentFile] = useState<File | null>(null);
const [prompt, setPrompt] = useState("");
const appStore = useAppStore();
// CellSelectionHandler 인스턴스 생성
const cellSelectionHandler = useRef(new CellSelectionHandler());
// Univer 초기화 함수
const initializeUniver = useCallback(async (workbookData?: any) => {
if (!containerRef.current || !mountedRef.current) {
console.error("❌ 컨테이너가 준비되지 않았습니다!");
return;
}
try {
console.log("🚀 Univer 초기화 시작");
// 전역 인스턴스 생성 또는 재사용
const univer = await UniverseManager.createInstance(containerRef.current);
// 기본 워크북 데이터
const defaultWorkbook = {
id: `workbook-${Date.now()}`,
locale: LocaleType.EN_US,
name: "Sample Workbook",
sheetOrder: ["sheet-01"],
sheets: {
"sheet-01": {
type: 0,
id: "sheet-01",
name: "Sheet1",
tabColor: "",
hidden: 0,
rowCount: 100,
columnCount: 20,
zoomRatio: 1,
scrollTop: 0,
scrollLeft: 0,
defaultColumnWidth: 93,
defaultRowHeight: 27,
cellData: {},
rowData: {},
columnData: {},
showGridlines: 1,
rowHeader: { width: 46, hidden: 0 },
columnHeader: { height: 20, hidden: 0 },
selections: ["A1"],
rightToLeft: 0,
},
},
};
const workbookToUse = workbookData || defaultWorkbook;
// 기존 워크북 정리 (API 호환성 고려)
try {
const existingUnits =
(univer as any).getUnitsForType?.(UniverInstanceType.UNIVER_SHEET) ||
[];
for (const unit of existingUnits) {
(univer as any).disposeUnit?.(unit.getUnitId());
}
} catch (error) {
console.log(" 기존 워크북 정리 시 오류 (무시 가능):", error);
const initializeUniver = useCallback(
async (workbookData?: any) => {
if (!containerRef.current || !mountedRef.current) {
console.error("❌ 컨테이너가 준비되지 않았습니다!");
return;
}
// 새 워크북 생성
const workbook = univer.createUnit(
UniverInstanceType.UNIVER_SHEET,
workbookToUse,
);
try {
console.log("🚀 Univer 초기화 시작");
console.log("✅ 워크북 생성 완료:", workbook?.getUnitId());
setIsInitialized(true);
} catch (error) {
console.error("❌ Univer 초기화 실패:", error);
setIsInitialized(false);
}
}, []);
// 전역 인스턴스 생성 또는 재사용
const univer = await UniverseManager.createInstance(
containerRef.current,
);
// 기본 워크북 데이터
const defaultWorkbook = {
id: `workbook-${Date.now()}`,
locale: LocaleType.EN_US,
name: "Sample Workbook",
sheetOrder: ["sheet-01"],
sheets: {
"sheet-01": {
type: 0,
id: "sheet-01",
name: "Sheet1",
tabColor: "",
hidden: 0,
rowCount: 100,
columnCount: 20,
zoomRatio: 1,
scrollTop: 0,
scrollLeft: 0,
defaultColumnWidth: 93,
defaultRowHeight: 27,
cellData: {},
rowData: {},
columnData: {},
showGridlines: 1,
rowHeader: { width: 46, hidden: 0 },
columnHeader: { height: 20, hidden: 0 },
selections: ["A1"],
rightToLeft: 0,
},
},
};
const workbookToUse = workbookData || defaultWorkbook;
// 기존 워크북 정리 (API 호환성 고려)
try {
const existingUnits =
(univer as any).getUnitsForType?.(
UniverInstanceType.UNIVER_SHEET,
) || [];
for (const unit of existingUnits) {
(univer as any).disposeUnit?.(unit.getUnitId());
}
} catch (error) {
console.log(" 기존 워크북 정리 시 오류 (무시 가능):", error);
}
// 새 워크북 생성
const workbook = univer.createUnit(
UniverInstanceType.UNIVER_SHEET,
workbookToUse,
);
console.log("✅ 워크북 생성 완료:", workbook?.getUnitId());
setIsInitialized(true);
// 셀 선택 핸들러 초기화 - SRP에 맞춰 별도 클래스로 분리
cellSelectionHandler.current.initialize(univer);
} catch (error) {
console.error("❌ Univer 초기화 실패:", error);
setIsInitialized(false);
}
},
[appStore],
);
// 파일 처리 함수
const processFile = useCallback(
@@ -431,7 +452,7 @@ const TestSheetViewer: React.FC = () => {
console.log("✅ 파일 처리 완료");
}
},
[isProcessing, initializeUniver],
[initializeUniver],
);
// 파일 입력 변경 처리
@@ -559,6 +580,16 @@ const TestSheetViewer: React.FC = () => {
};
}, []);
// 컴포넌트 언마운트 시 리소스 정리
useEffect(() => {
return () => {
// 셀 선택 핸들러 정리
if (cellSelectionHandler.current.isActive()) {
cellSelectionHandler.current.dispose();
}
};
}, []);
return (
<div className="w-full h-screen flex flex-col relative">
{/* 헤더 */}