Files
tech-log-frontend/src/features/tech-log/presentation/studio/components/catalog-property-picker.tsx
T
DongHyeonkaandClaude Opus 5 d72eae25ce feat: 바탕화면 수정본의 Studio 편집기 v2~v4 를 얹는다
`~/Desktop/tech-log-frontend` 가 세 번 더 고쳐져 있었다. 소스 열셋이 바뀌고 둘이
새로 생겼다(`markdown-block-editor`, `catalog-property-picker`). 검사 넷도 함께 바뀌었다.

기능이 바뀐 것부터 적는다.

**편집기에서 즉시 미리보기가 빠졌다.** v2 에서 「편집/나란히/미리보기」 모드가 생겼고,
v4 가 그 모드 자체를 없앴다 — 글 쓰는 화면은 하나이고 공개 렌더는 편집기의 두 번째
상태가 아니라는 판단이다. 직전 리뷰의 완료 조건 하나("preview 는 Desktop/Mobile 을
실제로 전환할 수 있다")가 이로써 다시 미적용이 된다. `InstantPreview` 는 파일로 남아
있으나 편집기 어디서도 부르지 않는다.

**본문이 textarea 에서 블록 편집기로 바뀌었다.** 기존 markdown 을 문단·제목·목록·인용·
코드·구분선·raw 로 읽고 같은 `bodyMarkdown` 계약으로 되돌려 쓴다. 읽었다가 그대로 다시
쓰는 왕복이 글을 바꾸면 작성자가 문서를 열어 저장하기만 해도 내용이 상하므로, 이
저장소가 실제로 쓰는 문법(앵커 단 소제목, 이름표 단 코드 울타리, `:::evidence`, 표,
인용, 목록, 구분선)을 하나씩 넣어 왕복을 검사로 고정했다. 빈 줄이 겹친 자리만 한 줄로
접히고 글자는 그대로다 — 그 예외도 검사에 적었다.

Project·Topic 이 검색 가능한 고르개로, 상태가 인라인 알약으로 바뀌었고, 메타데이터는
접히는 속성 면으로 내려갔다.

`useImperativeHandle` 안에서 부르는 `commit` 이 렌더마다 새로 만들어져 lint 가 막았다.
`useCallback` 으로 고정했다 — 바뀌는 것은 `onChange` 하나다.

Node 24 로 게이트 재실행: check:types · lint · test:unit(1829) · test:component(152) ·
test:tech-log(432) 전부 통과.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015c8cBFUaVr7KLVUx6ujz7D
2026-09-16 16:43:37 +09:00

89 lines
3.2 KiB
TypeScript

import { useMemo, useRef, useState } from "react";
import type { components } from "../../../contracts/studio/generated.ts";
type CatalogEntry = components["schemas"]["CatalogEntry"];
/**
* Project/Topic property picker used by the document writing surface.
*
* Native <select> was technically correct but became painful once catalogs grew: authors had to
* scroll a flat list and the control looked like a settings form. This picker keeps the document
* property row compact, then opens a searchable choice surface only when the property is edited.
*/
export function CatalogPropertyPicker({
label,
value,
entries,
emptyLabel,
missingLabel = "목록에 없는 대상",
onChange,
}: {
label: string;
value: string | null | undefined;
entries: readonly CatalogEntry[];
emptyLabel: string;
missingLabel?: string;
onChange(value: string | null): void;
}) {
const detailsRef = useRef<HTMLDetailsElement>(null);
const [query, setQuery] = useState("");
const selected = value ? entries.find((entry) => entry.id === value) : undefined;
const shown = selected?.label ?? (value ? missingLabel : emptyLabel);
const filtered = useMemo(() => {
const needle = query.trim().toLocaleLowerCase();
if (!needle) return entries;
return entries.filter((entry) => entry.label.toLocaleLowerCase().includes(needle));
}, [entries, query]);
const choose = (next: string | null) => {
onChange(next);
setQuery("");
if (detailsRef.current) detailsRef.current.open = false;
};
return (
<details ref={detailsRef} className="studio-catalog-property-picker">
<summary aria-label={label}>
<span data-empty={!value ? "" : undefined} data-missing={value && !selected ? "" : undefined}>{shown}</span>
<span className="studio-catalog-property-picker__chevron" aria-hidden="true">⌄</span>
</summary>
<div className="studio-catalog-property-picker__popover">
<label className="studio-catalog-property-picker__search">
<span className="studio-visually-hidden">{label} 검색</span>
<input
type="search"
value={query}
placeholder={`${label} 검색`}
onChange={(event) => setQuery(event.currentTarget.value)}
/>
</label>
<div className="studio-catalog-property-picker__options" role="listbox" aria-label={`${label} 선택`}>
<button
type="button"
role="option"
aria-selected={!value}
onClick={() => choose(null)}
>
<span>{emptyLabel}</span>
{!value ? <strong aria-hidden="true">✓</strong> : null}
</button>
{filtered.map((entry) => (
<button
key={entry.id}
type="button"
role="option"
aria-selected={entry.id === value}
onClick={() => choose(entry.id)}
>
<span>{entry.label}</span>
{entry.id === value ? <strong aria-hidden="true">✓</strong> : null}
</button>
))}
{filtered.length === 0 ? <p>검색 결과가 없습니다.</p> : null}
</div>
</div>
</details>
);
}