diff --git a/src/features/tech-log/presentation/studio/components/case-fields.tsx b/src/features/tech-log/presentation/studio/components/case-fields.tsx index bd12b9d..9087b9f 100644 --- a/src/features/tech-log/presentation/studio/components/case-fields.tsx +++ b/src/features/tech-log/presentation/studio/components/case-fields.tsx @@ -6,12 +6,11 @@ import { useStudioAssetGateway } from "../use-studio.ts"; import { buildEvidenceDirective } from "./asset-picker.tsx"; import { AssetPickerDialog, countBodyAssets } from "./asset-picker-dialog.tsx"; import { AssetUploadDialog } from "./asset-upload-dialog.tsx"; -import { MarkdownToolbar } from "./markdown-toolbar.tsx"; import { FieldNotice, type FieldIssue } from "./field-issues.tsx"; +import { MarkdownBlockEditor, type MarkdownBlockEditorHandle } from "./markdown-block-editor.tsx"; type CaseInput = components["schemas"]["CaseInput"]; -/** 이 화면이 자기 칸 아래에 보여 줄 수 있는 경로. */ export const CASE_FIELD_PATHS = [ "/problem", "/conclusion", @@ -27,26 +26,6 @@ const ASSET_KIND_OPTIONS: ReadonlyArray<{ value: AssetKind; label: string }> = [ { value: "ATTACHMENT", label: "첨부파일" }, ]; -/** - * `:::evidence ...` is a block directive, so the parser requires a blank line - * before and after it. Inserting straight into `selectionStart`/`selectionEnd` - * without normalizing the surrounding whitespace would produce a directive - * glued to adjacent text -- a well-formed-looking block that the parser still - * rejects. - */ -function insertAtCursor( - textarea: HTMLTextAreaElement, - directive: string, - commit: (next: string) => void, -) { - const { selectionStart, selectionEnd, value } = textarea; - const prefix = value.slice(0, selectionStart); - const suffix = value.slice(selectionEnd); - const before = prefix.length === 0 || prefix.endsWith("\n\n") ? prefix : `${prefix}\n\n`; - const after = suffix.startsWith("\n") ? suffix : `\n${suffix}`; - commit(`${before}${directive}${after}`); -} - export function CaseFields({ draft, issues, @@ -55,37 +34,21 @@ export function CaseFields({ onAssetUploaded, }: { draft: CaseInput; - /** 마지막 게시 시도가 남긴 지적. 각 칸 아래에는 그 칸의 것만 붙는다. */ issues: readonly FieldIssue[]; onChange(draft: CaseInput): void; - /** - * The editor screen owns the resolution catalog Instant Preview reads, and - * merges what the Picker observes into it -- it never adopts the Picker's - * (searchable, and so narrowable) displayed list wholesale. - */ onAssetsObserved?: (assets: readonly Asset[]) => void; onAssetUploaded?: (asset: Asset) => void; }) { - // Asset UI must use the throwing accessor, not the nullable `assetGateway` - // field directly -- see `use-studio.ts`'s `useStudioAssetGateway` doc. const assetGateway = useStudioAssetGateway(); - const bodyRef = useRef(null); + const bodyEditorRef = useRef(null); const uploadTriggerRef = useRef(null); const [uploadKind, setUploadKind] = useState("IMAGE"); const [uploadOpen, setUploadOpen] = useState(false); const update = (patch: Partial) => onChange({ ...draft, ...patch }); const insertDirective = (directive: string) => { - const textarea = bodyRef.current; - if (!textarea) { - update({ - bodyMarkdown: draft.bodyMarkdown - ? `${draft.bodyMarkdown}\n\n${directive}\n` - : `${directive}\n`, - }); - return; - } - insertAtCursor(textarea, directive, (next) => update({ bodyMarkdown: next })); + if (bodyEditorRef.current) bodyEditorRef.current.insertMarkdown(directive); + else update({ bodyMarkdown: draft.bodyMarkdown ? `${draft.bodyMarkdown}\n\n${directive}` : directive }); }; const closeUpload = () => { @@ -94,37 +57,81 @@ export function CaseFields({ }; return ( -
-

CASE

문제와 검증

-
-