feat: port TechLog Studio editors
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { useRef, useState, type KeyboardEvent } from "react";
|
||||
|
||||
import type { components } from "../../../contracts/studio/generated.ts";
|
||||
import type {
|
||||
WorkingCopy,
|
||||
WorkingCopyInput,
|
||||
} from "../../../contracts/studio/contract.ts";
|
||||
import type { StudioEditorStatus } from "../use-studio.ts";
|
||||
import { CaseFields } from "./case-fields.tsx";
|
||||
import { CommonDocumentFields } from "./common-document-fields.tsx";
|
||||
import { DocumentStatusRail } from "./document-status-rail.tsx";
|
||||
import { InstantPreview } from "./instant-preview.tsx";
|
||||
import { QuestionFields } from "./question-fields.tsx";
|
||||
import { ReferenceFields } from "./reference-fields.tsx";
|
||||
|
||||
type CatalogEntry = components["schemas"]["CatalogEntry"];
|
||||
|
||||
export type DocumentEditorController = {
|
||||
saved: WorkingCopy;
|
||||
draft: WorkingCopyInput;
|
||||
status: StudioEditorStatus;
|
||||
update(patch: Partial<WorkingCopyInput>): void;
|
||||
replace(draft: WorkingCopyInput): void;
|
||||
save?: () => Promise<void>;
|
||||
};
|
||||
|
||||
export function DocumentEditor({ controller, catalog }: { controller: DocumentEditorController; catalog: CatalogEntry[] }) {
|
||||
const [tab, setTab] = useState<"EDIT" | "PREVIEW">("EDIT");
|
||||
const editTab = useRef<HTMLButtonElement>(null);
|
||||
const previewTab = useRef<HTMLButtonElement>(null);
|
||||
const selectTab = (next: "EDIT" | "PREVIEW") => {
|
||||
setTab(next);
|
||||
(next === "EDIT" ? editTab : previewTab).current?.focus();
|
||||
};
|
||||
const keyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
|
||||
let next: "EDIT" | "PREVIEW" | null = null;
|
||||
if (event.key === "ArrowLeft" || event.key === "ArrowRight") next = tab === "EDIT" ? "PREVIEW" : "EDIT";
|
||||
if (event.key === "Home") next = "EDIT";
|
||||
if (event.key === "End") next = "PREVIEW";
|
||||
if (!next) return;
|
||||
event.preventDefault();
|
||||
selectTab(next);
|
||||
};
|
||||
const topics = catalog.filter(({ type }) => type === "TOPIC");
|
||||
const projects = catalog.filter(({ type }) => type === "PROJECT");
|
||||
const relations = catalog.filter(({ type }) => type === "RELATION");
|
||||
const evidence = catalog.filter(({ type }) => type === "EVIDENCE");
|
||||
|
||||
return (
|
||||
<div className="studio-editor-page">
|
||||
<div className="studio-editor-tabs" role="tablist" aria-label="문서 편집 화면">
|
||||
<button id="studio-edit-tab" ref={editTab} type="button" role="tab" aria-selected={tab === "EDIT"} aria-controls="studio-edit-panel" tabIndex={tab === "EDIT" ? 0 : -1} onClick={() => selectTab("EDIT")} onKeyDown={keyDown}>편집</button>
|
||||
<button id="studio-preview-tab" ref={previewTab} type="button" role="tab" aria-selected={tab === "PREVIEW"} aria-controls="studio-preview-panel" tabIndex={tab === "PREVIEW" ? 0 : -1} onClick={() => selectTab("PREVIEW")} onKeyDown={keyDown}>즉시 미리보기</button>
|
||||
</div>
|
||||
<div className="studio-editor-layout">
|
||||
<div className="studio-editor-workspace">
|
||||
<div id="studio-edit-panel" role="tabpanel" aria-labelledby="studio-edit-tab" hidden={tab !== "EDIT"}>
|
||||
<header className="studio-editor-heading">
|
||||
<p className="studio-eyebrow">{controller.draft.kind} · VERSION {controller.saved.version}</p>
|
||||
<h1>문서 편집</h1>
|
||||
<p>{controller.draft.title || "제목 없는 작업본"}</p>
|
||||
</header>
|
||||
<CommonDocumentFields draft={controller.draft} topics={topics} projects={projects} relations={relations} onUpdate={controller.update} />
|
||||
{controller.draft.kind === "CASE"
|
||||
? <CaseFields draft={controller.draft} onChange={controller.replace} />
|
||||
: controller.draft.kind === "REFERENCE"
|
||||
? <ReferenceFields draft={controller.draft} onChange={controller.replace} />
|
||||
: <QuestionFields draft={controller.draft} evidence={evidence} onChange={controller.replace} />}
|
||||
</div>
|
||||
<div id="studio-preview-panel" role="tabpanel" aria-labelledby="studio-preview-tab" hidden={tab !== "PREVIEW"}>
|
||||
<InstantPreview draft={controller.draft} catalog={catalog} />
|
||||
</div>
|
||||
</div>
|
||||
<DocumentStatusRail controller={controller} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user