Skip to content
Closed
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import { str } from "./primitives";

export type RawBlock = { __resolveType?: string } & Record<string, unknown>;

/** A block field that's already a JSON string, or an array/object to stringify. */
function jsonStr(value: unknown): string {
return typeof value === "string" ? value : JSON.stringify(value ?? []);
}

/**
* Render a single block as its native, inline-editable representation
* (Notion-style). Common blocks get bespoke editors matched by component
Expand Down Expand Up @@ -141,11 +146,7 @@ export function BlockEditor({
case "CardGroup":
return (
<CardGroupBlock
cards={
typeof block.cards === "string"
? block.cards
: JSON.stringify(block.cards ?? [])
}
cards={jsonStr(block.cards)}
onChange={(cards) => onChange({ ...block, cards })}
/>
);
Expand Down Expand Up @@ -176,16 +177,8 @@ export function BlockEditor({
case "Table":
return (
<TableBlock
headers={
typeof block.headers === "string"
? block.headers
: JSON.stringify(block.headers ?? [])
}
rows={
typeof block.rows === "string"
? block.rows
: JSON.stringify(block.rows ?? [])
}
headers={jsonStr(block.headers)}
rows={jsonStr(block.rows)}
onChange={(next) => onChange({ ...block, ...next })}
/>
);
Expand Down
Loading