[as] feat: 웹기안기 '열기' 기능 추가(개발용)
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Download, Fullscreen, Save } from "lucide-react";
|
import { useId } from "react";
|
||||||
|
|
||||||
import { Button } from "@common/components";
|
import { Download, FolderOpen, Fullscreen, Save } from "lucide-react";
|
||||||
|
|
||||||
|
import { Button, cn } from "@common/components";
|
||||||
|
|
||||||
|
const WEBHYP_DEV_MODE = process.env.NEXT_PUBLIC_WEBHYP_DEV_MODE === "true";
|
||||||
|
|
||||||
interface HangulGiangiToolbarProps {
|
interface HangulGiangiToolbarProps {
|
||||||
isBusy?: boolean;
|
isBusy?: boolean;
|
||||||
canSave?: boolean;
|
canSave?: boolean;
|
||||||
|
onOpen: (file: File) => void;
|
||||||
onSave: () => void;
|
onSave: () => void;
|
||||||
onDownload: () => void;
|
onDownload: () => void;
|
||||||
onFullscreen: () => void;
|
onFullscreen: () => void;
|
||||||
@@ -15,12 +20,51 @@ interface HangulGiangiToolbarProps {
|
|||||||
function HangulGiangiToolbar({
|
function HangulGiangiToolbar({
|
||||||
isBusy = false,
|
isBusy = false,
|
||||||
canSave = true,
|
canSave = true,
|
||||||
|
onOpen,
|
||||||
onSave,
|
onSave,
|
||||||
onDownload,
|
onDownload,
|
||||||
onFullscreen,
|
onFullscreen,
|
||||||
}: HangulGiangiToolbarProps) {
|
}: HangulGiangiToolbarProps) {
|
||||||
|
const openInputId = useId();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full flex-nowrap items-center gap-2 border-b border-border bg-background p-3">
|
<div className="flex w-full flex-nowrap items-center gap-2 border-b border-border bg-background p-3">
|
||||||
|
{WEBHYP_DEV_MODE && (
|
||||||
|
<label
|
||||||
|
htmlFor={openInputId}
|
||||||
|
className={cn("cursor-pointer", isBusy && "pointer-events-none")}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
id={openInputId}
|
||||||
|
type="file"
|
||||||
|
accept=".hwpx,application/haansofthwpx"
|
||||||
|
disabled={isBusy}
|
||||||
|
className="peer sr-only"
|
||||||
|
aria-label="열기"
|
||||||
|
onChange={(event) => {
|
||||||
|
const file = event.target.files?.[0];
|
||||||
|
if (file) onOpen(file);
|
||||||
|
event.target.value = "";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
color="white"
|
||||||
|
size="sm"
|
||||||
|
disabled={isBusy}
|
||||||
|
className={cn(
|
||||||
|
"peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-2",
|
||||||
|
isBusy && "pointer-events-none opacity-50",
|
||||||
|
)}
|
||||||
|
asChild
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<FolderOpen className="!size-5" />
|
||||||
|
열기
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
{canSave && (
|
{canSave && (
|
||||||
<Button type="button" color="white" size="sm" disabled={isBusy} onClick={onSave}>
|
<Button type="button" color="white" size="sm" disabled={isBusy} onClick={onSave}>
|
||||||
<Save className="!size-5" />
|
<Save className="!size-5" />
|
||||||
|
|||||||
@@ -70,43 +70,46 @@ function HangulGiangi({
|
|||||||
return () => window.clearInterval(timer);
|
return () => window.clearInterval(timer);
|
||||||
}, [isCtrlReady, onReady]);
|
}, [isCtrlReady, onReady]);
|
||||||
|
|
||||||
const handleOpen = useCallback(() => {
|
const openHwpxBlob = useCallback(
|
||||||
const ctrl = resolveHwpCtrl(iframeRef.current, isCtrlReady);
|
(blob: Blob, fileName: string) => {
|
||||||
if (!ctrl) return;
|
const ctrl = resolveHwpCtrl(iframeRef.current, isCtrlReady);
|
||||||
|
if (!ctrl) return;
|
||||||
|
|
||||||
setIsBusy(true);
|
setIsBusy(true);
|
||||||
openingDocumentKeyRef.current = documentKey;
|
openingDocumentKeyRef.current = documentKey;
|
||||||
attemptedDocumentKeyRef.current = documentKey;
|
attemptedDocumentKeyRef.current = documentKey;
|
||||||
try {
|
try {
|
||||||
const documentFile = new File([documentBlob], documentFileName, {
|
const documentFile = new File([blob], fileName, {
|
||||||
type: HWPX_CONTENT_TYPE,
|
type: HWPX_CONTENT_TYPE,
|
||||||
});
|
});
|
||||||
const isAccepted = ctrl.Open(
|
const isAccepted = ctrl.Open(
|
||||||
documentFile,
|
documentFile,
|
||||||
"HWPX",
|
"HWPX",
|
||||||
"",
|
"",
|
||||||
(result) => {
|
(result) => {
|
||||||
const callbackDocumentKey = getCallbackDocumentKey(result.CallbackUserData, documentKey);
|
const callbackDocumentKey = getCallbackDocumentKey(result.CallbackUserData, documentKey);
|
||||||
if (openingDocumentKeyRef.current !== callbackDocumentKey) return;
|
if (openingDocumentKeyRef.current !== callbackDocumentKey) return;
|
||||||
|
|
||||||
openingDocumentKeyRef.current = null;
|
openingDocumentKeyRef.current = null;
|
||||||
setIsBusy(false);
|
setIsBusy(false);
|
||||||
if (!result.result) return;
|
if (!result.result) return;
|
||||||
|
|
||||||
openedDocumentKeyRef.current = callbackDocumentKey;
|
openedDocumentKeyRef.current = callbackDocumentKey;
|
||||||
},
|
},
|
||||||
{ documentKey } satisfies DocumentCallbackUserData,
|
{ documentKey } satisfies DocumentCallbackUserData,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isAccepted) return;
|
if (isAccepted) return;
|
||||||
|
|
||||||
openingDocumentKeyRef.current = null;
|
openingDocumentKeyRef.current = null;
|
||||||
setIsBusy(false);
|
setIsBusy(false);
|
||||||
} catch {
|
} catch {
|
||||||
openingDocumentKeyRef.current = null;
|
openingDocumentKeyRef.current = null;
|
||||||
setIsBusy(false);
|
setIsBusy(false);
|
||||||
}
|
}
|
||||||
}, [documentBlob, documentFileName, documentKey, isCtrlReady]);
|
},
|
||||||
|
[documentKey, isCtrlReady],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
@@ -117,8 +120,19 @@ function HangulGiangi({
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleOpen();
|
openHwpxBlob(documentBlob, documentFileName);
|
||||||
}, [documentKey, handleOpen, isCtrlReady]);
|
}, [documentBlob, documentFileName, documentKey, isCtrlReady, openHwpxBlob]);
|
||||||
|
|
||||||
|
const handleToolbarOpen = useCallback(
|
||||||
|
(file: File) => {
|
||||||
|
if (!file.name.toLowerCase().endsWith(".hwpx")) {
|
||||||
|
alert("HWPX 파일만 열 수 있습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
openHwpxBlob(file, file.name);
|
||||||
|
},
|
||||||
|
[openHwpxBlob],
|
||||||
|
);
|
||||||
|
|
||||||
const handleSave = useCallback(() => {
|
const handleSave = useCallback(() => {
|
||||||
const ctrl = resolveHwpCtrl(iframeRef.current, isCtrlReady);
|
const ctrl = resolveHwpCtrl(iframeRef.current, isCtrlReady);
|
||||||
@@ -185,6 +199,7 @@ function HangulGiangi({
|
|||||||
<HangulGiangiToolbar
|
<HangulGiangiToolbar
|
||||||
isBusy={isBusy || !isCtrlReady}
|
isBusy={isBusy || !isCtrlReady}
|
||||||
canSave={canSave}
|
canSave={canSave}
|
||||||
|
onOpen={handleToolbarOpen}
|
||||||
onSave={handleSave}
|
onSave={handleSave}
|
||||||
onDownload={handleDownload}
|
onDownload={handleDownload}
|
||||||
onFullscreen={handleFullscreen}
|
onFullscreen={handleFullscreen}
|
||||||
|
|||||||
Reference in New Issue
Block a user