Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1803f4b
Add new block types and update schemas
developjik Nov 24, 2026
22fae95
Update README.md
developjik Nov 24, 2026
5986946
Update server.ts
developjik Nov 24, 2026
8b071fb
Update App.tsx
developjik Nov 24, 2026
891abf9
Update DocPanel.tsx
developjik Nov 24, 2026
a3e3de9
Update storage.ts
developjik Nov 24, 2026
8b5b320
Update main.tsx
developjik Nov 24, 2026
bace5f8
Update doc.ts
developjik Nov 24, 2026
a15d454
Update html.ts
developjik Nov 24, 2026
6826731
Update index.ts
developjik Nov 24, 2026
26df9fe
Update project.ts
developjik Nov 24, 2026
cc2b550
Update transfer.ts
developjik Nov 24, 2026
fc69b1c
Update command.ts
developjik Nov 24, 2026
ecf4503
Update project.ts
developjik Nov 24, 2026
c882865
Update proposal.ts
developjik Nov 24, 2026
0d9848a
Update body.ts
developjik Nov 24, 2026
2c20d09
Update spec.ts
developjik Nov 24, 2026
5141d97
Update mapping.ts
developjik Nov 24, 2026
5b7c67b
Update sqlite-store.ts
developjik Nov 24, 2026
0a23cb9
Update run_all.py
developjik Nov 24, 2026
5cf6a59
Create rich-block.css
developjik Nov 24, 2026
7c1bd45
Create rich-block.ts
developjik Nov 24, 2026
a85bdc9
Create rich.test.ts
developjik Nov 24, 2026
8382ec9
Create rich-blocks.test.ts
developjik Nov 24, 2026
d6c5102
Create run_rich.sh
developjik Nov 24, 2026
570376f
Create w_rich.py
developjik Nov 24, 2026
c78e886
Update mapping.ts
developjik Nov 24, 2026
1d2c0a5
Update rich-blocks.test.ts
developjik Nov 24, 2026
850afe4
Update App.tsx
developjik Nov 24, 2026
8f0b1af
Update project.ts
developjik Nov 24, 2026
8c49874
Update project.ts
developjik Nov 24, 2026
ded8475
Update doc.ts
developjik Nov 24, 2026
a3cf2b6
Update body.ts
developjik Nov 24, 2026
6d0a6c3
Update rich-blocks.test.ts
developjik Nov 24, 2026
97dcf45
Update README.md
developjik Nov 24, 2026
b4d992a
Update storage.test.ts
developjik Nov 24, 2026
11fc6b8
Update rich.test.ts
developjik Nov 24, 2026
580ec3a
Update w_rich.py
developjik Nov 24, 2026
6bf29ce
Update App.tsx
developjik Nov 24, 2026
c556d88
Refactor block data handling with type check
developjik Nov 24, 2026
487d1d4
Add newline at end of transfer.ts
developjik Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,32 @@ screen alias on load. Single-screen downloads keep bundle version 1 and the scre
downloads use bundle version 2 so older single-screen readers reject them instead
of silently collapsing ownership. New readers accept both versions. Images may
appear twice in downloaded bundles; only browser storage compacts the alias.


### Rich document blocks (DEV-118)

The document editor supports paragraph, heading, list, caption, table, code and
figure blocks. Tables have editable cells, a header row toggle and row/column
controls (100 rows, 30 columns maximum). Code has a language label and copy
button. Figures reference the document's own screen image and an optional pin;
alt text is required. They do not upload files or implement DEV-52 state capture.
If that screen has no image, the missing capture is shown explicitly.

`doc.block.create` and `doc.block.update` accept optional `data`: `table` contains
`rows: string[][]` and `header: boolean`; `code` contains `language` and
`lineNumbers`; `figure` contains `screenId`, optional `pinId`, and nonempty `alt`.
Rich data is stored in the existing block `attrs` JSON, without a DB migration. Exports containing rich or unknown blocks use bundle v3
so older readers reject them rather than stripping structured fields.
`block.type` stays open when reading: unknown types retain all fields, use a
read-only fallback in the editor and escaped text in output. SQLite stores their
original payload in attrs with its existing `criteria` carrier type. Editing an
unrelated block does not strip unknown data. Unknown blocks cannot be changed,
reordered, linked or deleted through block commands or proposal adoption.

HTML and Confluence share escaped table/code markup. Confluence figures reference
the uploaded screen overlay attachment rather than embedding data URLs. HTML embeds print CSS
and prints to PDF using the browser, preserving cells, code whitespace and figure
alt captions. It makes no external image requests. Rich blocks are edited directly,
not rewritten by prose AI proposals; pin references never alter code contents.
`test/e2e/run_rich.sh` verifies editor changes, reload, HTML download, PDF rendering
and mobile layout. The full E2E runner includes this as its ninth harness.
3 changes: 2 additions & 1 deletion apps/daemon/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { bundleVersion } from '@spec-studio/protocol';
import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';
import { mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
Expand Down Expand Up @@ -522,7 +523,7 @@ export async function startDaemon(options: DaemonOptions): Promise<Daemon> {
if (req.method !== 'GET') throw new HttpError(405, 'method_not_allowed', 'GET만 허용됩니다.');
const bundle: ProjectBundle = {
format: 'spec-studio.bundle',
version: (project.screens?.length ?? 0) > 1 ? 2 : 1,
version: bundleVersion(project),
exportedAt: now(),
project,
};
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,17 @@ export default function App() {
void runDoc({ type: 'doc.block.update', docId: doc.id, blockId, text });
};

const updateBlockData = (blockId:string,data:import('@spec-studio/protocol').RichBlockData) => {
if(doc!==null && JSON.stringify(doc.blocks.find(b=>b.id===blockId)?.data)!==JSON.stringify(data)) void runDoc({type:'doc.block.update',docId:doc.id,blockId,data});
};
const changeBlockType = (blockId: string, blockType: BlockType) => {
if (doc === null) return;
void runDoc({
type: 'doc.block.update',
docId: doc.id,
blockId,
blockType,
...(blockType==='figure'&&!doc.blocks.find(b=>b.id===blockId)?.data?.figure&&project?.screen?{data:{...doc.blocks.find(b=>b.id===blockId)?.data,figure:{screenId:project.screen.id,alt:project.screen.title}}}:{}),
});
};

Expand Down Expand Up @@ -1632,6 +1636,8 @@ export default function App() {
onAddBlock={addBlock}
onUpdateText={updateBlockText}
onChangeType={changeBlockType}
onUpdateData={updateBlockData}
screens={(project.screens ?? []).filter(s=>s.id===project.screen?.id)}
onDeleteBlock={deleteBlock}
onMoveBlock={moveBlock}
onLinkPin={linkBlockPin}
Expand Down
36 changes: 35 additions & 1 deletion apps/web/src/components/DocPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { proposalQueue, proposalConflicts, proposalIsStale } from '@spec-studio/
import { useEffect, useRef, useState, type FormEvent } from 'react';
import {
BLOCK_TYPES,
isKnownBlockType,
type RichBlockData,
type Screen,
BLOCK_TYPE_LABEL,
PIN_TYPE_LABEL,
type Block,
Expand Down Expand Up @@ -29,6 +32,8 @@ export interface RevertableView {
}

interface DocPanelProps {
screens: Screen[];
onUpdateData: (blockId:string,data:RichBlockData)=>void;
doc: Doc | null;
/** The registry; one tab each, the active one is `doc`. */
docs: Doc[];
Expand Down Expand Up @@ -355,6 +360,8 @@ export function DocPanel(props: DocPanelProps) {
selectedPinId={selectedPinId}
flashed={flash === block.id}
first={index === 0}
screens={props.screens}
onUpdateData={props.onUpdateData}
onUpdateText={props.onUpdateText}
onChangeType={props.onChangeType}
onDelete={props.onDeleteBlock}
Expand Down Expand Up @@ -494,6 +501,8 @@ function truncate(text: string, size = 64): string {
}

interface BlockRowProps {
screens: Screen[];
onUpdateData: (blockId:string,data:RichBlockData)=>void;
block: Block;
position: number;
pins: Pin[];
Expand All @@ -513,7 +522,8 @@ interface BlockRowProps {
}

function BlockRow(props: BlockRowProps) {
const { block, pins, doc, editable } = props;
const { block, pins, doc } = props;
const editable = props.editable && isKnownBlockType(block.type);
const [text, setText] = useState(block.text);
const [linkPin, setLinkPin] = useState('');

Expand Down Expand Up @@ -554,6 +564,7 @@ function BlockRow(props: BlockRowProps) {
onChange={(event) => props.onChangeType(block.id, event.target.value as BlockType)}
data-testid={`block-type-${props.position}`}
>
{!isKnownBlockType(block.type)&&<option value={block.type}>읽기 전용: {block.type}</option>}
{BLOCK_TYPES.map((type) => (
<option key={type} value={type}>
{BLOCK_TYPE_LABEL[type]}
Expand Down Expand Up @@ -604,6 +615,8 @@ function BlockRow(props: BlockRowProps) {
</div>
</div>

{isKnownBlockType(block.type) && ['table','code','figure'].includes(block.type) && <RichBlockEditor block={block} screens={props.screens} pins={pins} editable={editable} onUpdate={(data)=>props.onUpdateData(block.id,data)} />}
{!isKnownBlockType(block.type) && <p className="unknown-block-note">알 수 없는 블록은 수정하지 않고 원본 데이터를 보존합니다.</p>}
<textarea
className="doc-text"
value={text}
Expand Down Expand Up @@ -710,3 +723,24 @@ function BlockRow(props: BlockRowProps) {
</li>
);
}

function RichBlockEditor({block,screens,pins,editable,onUpdate}:{block:Block;screens:Screen[];pins:Pin[];editable:boolean;onUpdate:(data:RichBlockData)=>void}) {
const [data,setData]=useState<RichBlockData>(block.data??{});
useEffect(()=>setData(block.data??{}),[block.id,block.data]);
const change=(value:RichBlockData)=>{setData(value);onUpdate(value)};
if(block.type==='table'){
const table=data.table??{rows:[['',''],['','']],header:true};
const update=(rows:string[][])=>change({...data,table:{...table,rows}});
return <section className="rich-editor" aria-label="표 편집">
<label><input type="checkbox" checked={table.header} disabled={!editable} onChange={e=>change({...data,table:{...table,header:e.target.checked}})} />첫 행은 제목</label>
<div className="rich-table-wrap"><table className="rich-table"><tbody>{table.rows.map((row,r)=><tr key={r}>{row.map((cell,c)=>{const Cell=table.header&&r===0?'th':'td';return <Cell key={c}><input aria-label={`표 ${r+1}행 ${c+1}열`} disabled={!editable} value={cell} onChange={e=>setData({...data,table:{...table,rows:table.rows.map((line,i)=>i===r?line.map((v,j)=>j===c?e.target.value:v):line)}})} onBlur={()=>onUpdate(data)} /></Cell>})}</tr>)}</tbody></table></div>
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
<div className="rich-tools"><button type="button" disabled={!editable||table.rows.length>=100} onClick={()=>update([...table.rows,Array(table.rows[0]?.length??2).fill('')])}>행 추가</button><button type="button" disabled={!editable||(table.rows[0]?.length??0)>=30} onClick={()=>update(table.rows.map(row=>[...row,'']))}>열 추가</button><button type="button" disabled={!editable||table.rows.length<=1} onClick={()=>update(table.rows.slice(0,-1))}>마지막 행 삭제</button><button type="button" disabled={!editable||(table.rows[0]?.length??0)<=1} onClick={()=>update(table.rows.map(row=>row.slice(0,-1)))}>마지막 열 삭제</button></div>
</section>;
}
if(block.type==='code')return <section className="rich-editor"><label>언어 <select aria-label="코드 언어" value={data.code?.language??'text'} disabled={!editable} onChange={e=>change({...data,code:{language:e.target.value,lineNumbers:data.code?.lineNumbers??false}})}>{['text','typescript','javascript','json','html','css','python','sql','bash'].map(s=><option key={s}>{s}</option>)}</select></label><button type="button" onClick={()=>void navigator.clipboard.writeText(block.text).then(()=>window.alert('코드를 복사했습니다.')).catch(()=>window.alert('복사 권한이 없습니다. 아래 코드에서 직접 복사하세요.'))}>코드 복사</button><pre className="rich-code"><code>{block.text}</code></pre></section>;
if(block.type==='figure'){
const figure=data.figure??{screenId:screens[0]?.id??'',alt:''};const screen=screens.find(s=>s.id===figure.screenId);
return <section className="rich-editor"><label>캡처 화면 <select aria-label="그림 캡처 화면" disabled={!editable} value={figure.screenId} onChange={e=>change({...data,figure:{screenId:e.target.value,alt:figure.alt||'화면 캡처'}})}>{screens.map(s=><option key={s.id} value={s.id}>{s.code} · {s.title}</option>)}</select></label><label>연결 핀 <select aria-label="그림 연결 핀" disabled={!editable} value={figure.pinId??''} onChange={e=>{const {pinId,...f}=figure;change({...data,figure:e.target.value?{...f,pinId:e.target.value}:f})}}><option value="">전체 화면</option>{pins.filter(p=>p.screenId===figure.screenId).map(p=><option key={p.id} value={p.id}>#{p.number} {p.title}</option>)}</select></label><label>대체 텍스트(필수)<input aria-label="그림 대체 텍스트" required disabled={!editable} value={figure.alt} onChange={e=>setData({...data,figure:{...figure,alt:e.target.value}})} onBlur={()=>{if(figure.alt.trim())onUpdate(data)}} /></label>{!figure.alt.trim()&&<p role="alert">대체 텍스트를 입력해야 저장됩니다.</p>}{screen?.ref.kind==='image'?<figure><img src={screen.ref.value} alt={figure.alt}/><figcaption>{figure.alt}{figure.pinId?' · 연결 핀 있음':''}</figcaption></figure>:<p>이 화면에는 이미지 캡처가 없습니다.</p>}</section>;
}
return null;
}
1 change: 1 addition & 0 deletions apps/web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
import './styles.css';
import './rich-block.css';
import './proposal-queue.css';

const container = document.getElementById('root');
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/model/storage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { bundleVersion } from '@spec-studio/protocol';
import { normalizeProject } from '@spec-studio/core';
import {
normalizeLegacyProject,
Expand Down Expand Up @@ -58,7 +59,7 @@ export function downloadProject(project: Project): void {

/** The file a person keeps: the project plus what it is and when it left. */
export function bundleOf(project: Project, at = new Date().toISOString()): ProjectBundle {
return { format: 'spec-studio.bundle', version: (project.screens?.length ?? 0) > 1 ? 2 : 1, exportedAt: at, project };
return { format: 'spec-studio.bundle', version: bundleVersion(project), exportedAt: at, project };
}

export function downloadBundle(bundle: ProjectBundle): void {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/rich-block.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions apps/web/test/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ it('exports multi-screen bundles as v2 and reads them without losing screen owne
const bundle=bundleOf(project,at);expect(bundle.version).toBe(2);
ProjectBundleSchema.parse(bundle);const restored=parseBundleFile(JSON.stringify(bundle));expect(restored.project.screens).toHaveLength(2);expect(restored.project.pins.map(p=>[p.screenId,p.number])).toEqual(project.pins.map(p=>[p.screenId,p.number]));
});

it('uses v3 for hidden rich data and preserves opaque nested data on browser import',()=>{
const at='2026-11-19T00:00:00Z';const project=createProject({id:'PRJ_aaaaaaaaaaaa',name:'보존',at});
const base={id:'B_aaaaaaaaaaaa',type:'paragraph',text:'',pinRefs:[],createdAt:at,updatedAt:at};
project.docs=[{id:'D_aaaaaaaaaaaa',title:'문서',rev:0,kind:'spec',deletedAt:null,createdAt:at,updatedAt:at,blocks:[{...base,data:{table:{rows:[['보존']],header:true}}},{...base,id:'B_bbbbbbbbbbbb',type:'future-table',data:{table:{rows:[['확장']],header:true,columnWidths:[120,240]},code:{custom:{x:1}}}}]}];
const bundle=bundleOf(project,at);expect(bundle.version).toBe(3);expect(parseBundleFile(JSON.stringify(bundle)).project.docs[0]!.blocks).toEqual(project.docs[0]!.blocks);
});
23 changes: 17 additions & 6 deletions packages/core/src/doc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
BlockSchema,
isKnownBlockType,
type RichBlockData,
type AiBriefDraft,
type AiDocDraft,
type Block,
Expand Down Expand Up @@ -143,13 +145,15 @@ function newRef(pin: Pin, at: string): BlockPinRef {
export function makeBlock(input: {
id: string;
type: Block['type'];
data?: RichBlockData | undefined;
text: string;
pinRefs?: BlockPinRef[];
at: string;
}): Block {
return BlockSchema.parse({
id: input.id,
type: input.type,
data: input.data,
text: input.text,
pinRefs: input.pinRefs ?? [],
createdAt: input.at,
Expand Down Expand Up @@ -226,16 +230,16 @@ export function buildProposal(input: {
if (touched.has(badge.blockId)) continue;
touched.add(badge.blockId);
const block = findBlock(doc, badge.blockId);
if (block === undefined) continue;
if (block === undefined || !isKnownBlockType(block.type) || ['code','table','figure'].includes(block.type)) continue;
// A pin that vanished loses its citation; a pin that changed keeps it.
const refs = block.pinRefs
.filter((ref) => byId.has(ref.pinId))
.map((ref) => confirmRef(ref, byId.get(ref.pinId) as Pin, input.at));
patches.push({
blockId: block.id,
afterBlockId: null,
before: { type: block.type, text: block.text, pinRefs: block.pinRefs },
after: { type: block.type, text: syncBlockText(block.text, refs, pins), pinRefs: refs },
before: { type: block.type, text: block.text, pinRefs: block.pinRefs, data: block.data },
after: { type: block.type, text: syncBlockText(block.text, refs, pins), pinRefs: refs, data: block.data },
});
}

Expand Down Expand Up @@ -313,6 +317,7 @@ export function buildProposalFromDraft(input: {
'제안이 이 문서에 없는 문단을 가리킵니다. 다시 추출해 주세요.',
);
}
if(!isKnownBlockType(block.type)||['code','table','figure'].includes(block.type)) throw new DomainError('invalid_input','리치 블록은 직접 편집으로 수정하세요');
const kept = block.pinRefs.filter((ref) => byId.has(ref.pinId));
const cited = draftPatch.pins
.map((number) => byNumber.get(number))
Expand All @@ -326,6 +331,7 @@ export function buildProposalFromDraft(input: {
}
const after = {
type: block.type,
data: block.data,
text: syncBlockText(draftPatch.text, refs, pins),
pinRefs: refs,
};
Expand All @@ -337,7 +343,7 @@ export function buildProposalFromDraft(input: {
patches.push({
blockId: block.id,
afterBlockId: null,
before: { type: block.type, text: block.text, pinRefs: block.pinRefs },
before: { type: block.type, text: block.text, pinRefs: block.pinRefs, data: block.data },
after,
});
}
Expand Down Expand Up @@ -439,13 +445,15 @@ export function applyPatches(
const created: string[] = [];
for (const patch of patches) {
const current = blocks.find((block) => block.id === patch.blockId);
if(!isKnownBlockType(patch.after.type)||(current&&!isKnownBlockType(current.type))) throw new DomainError('invalid_input','알 수 없는 블록은 읽기 전용입니다');
if (patch.before === null) {
if (current !== undefined) {
throw new DomainError('invalid_input', '이미 있는 문단을 추가하려 했습니다');
}
const block = makeBlock({
id: patch.blockId,
type: patch.after.type,
data: patch.after.data,
text: patch.after.text,
pinRefs: patch.after.pinRefs,
at,
Expand All @@ -457,7 +465,7 @@ export function applyPatches(
if (current === undefined) throw new DomainError('block_not_found', '문단을 찾지 못했습니다');
blocks = blocks.map((block) =>
block.id === patch.blockId
? { ...block, type: patch.after.type, text: patch.after.text, pinRefs: patch.after.pinRefs, updatedAt: at }
? { ...block, type: patch.after.type, text: patch.after.text, pinRefs: patch.after.pinRefs, data: patch.after.data ?? block.data, updatedAt: at }
: block,
);
}
Expand All @@ -477,6 +485,7 @@ export function snapshotForPatches(doc: Doc, patches: readonly ProposalPatch[]):
blockId: patch.blockId,
existed: true,
type: patch.before.type,
data: patch.before.data,
text: patch.before.text,
pinRefs: patch.before.pinRefs,
index,
Expand Down Expand Up @@ -512,7 +521,9 @@ export function restoreSnapshot(doc: Doc, snapshot: DocSnapshot, at: string): Do
const previous = before.get(entry.blockId);
const restored = BlockSchema.parse({
id: entry.blockId,
...previous,
type: entry.type ?? previous?.type ?? 'paragraph',
data: entry.data ?? previous?.data,
text: entry.text ?? '',
pinRefs: entry.pinRefs ?? [],
createdAt: previous?.createdAt ?? at,
Expand Down Expand Up @@ -561,6 +572,6 @@ export function proposalIsStale(doc: Doc, proposal: Proposal, pins?: readonly Pi
}
const current = findBlock(doc, patch.blockId);
if (patch.before === null) return current !== undefined;
return current === undefined || current.type !== patch.before.type || current.text !== patch.before.text || !sameRefs(current.pinRefs, patch.before.pinRefs);
return current === undefined || current.type !== patch.before.type || current.text !== patch.before.text || JSON.stringify(current.data) !== JSON.stringify(patch.before.data) || !sameRefs(current.pinRefs, patch.before.pinRefs);
});
}
Loading