Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): render on left, source on right in preview edit modal (#3230)
Abraham67a9727ed24c
diff --git a/.changeset/edit-modal-render-left.md b/.changeset/edit-modal-render-left.mdnew file mode 100644index 000000000..6b119a238--- /dev/null+++ b/.changeset/edit-modal-render-left.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++The Mermaid and HTML code-preview edit modals now show the live render on the left and the source editor on the right, matching how the reader mentally locates their edit — outcome first, mechanism next. On stacked (mobile-width) viewports the source editor stays on top so the surface the user came to edit is what they land on, and the body scrolls if the two panes exceed the dialog height.diff --git a/packages/app/src/editor/components/CodePreviewEditModal.dom.test.tsx b/packages/app/src/editor/components/CodePreviewEditModal.dom.test.tsxindex f79d3e393..60d61d47a 100644--- a/packages/app/src/editor/components/CodePreviewEditModal.dom.test.tsx+++ b/packages/app/src/editor/components/CodePreviewEditModal.dom.test.tsx@@ -153,6 +153,48 @@ describe('CodePreviewEditModal', () => {expect(saved).toBeNull();});+ test('body opts into md:flex-row-reverse so the preview renders visually left in wide viewports', async () => {+ // Contract pin for the visual pane swap: source stays first in DOM (tab+ // order + stacked-layout on-top position), while `md:flex-row-reverse`+ // moves the preview visually to the left in wide viewports. A DOM-order+ // assertion can't catch a regression to the plain `md:flex-row` shape+ // because DOM order is intentionally unchanged; the classname pin is+ // the load-bearing signal.+ render(+ <Harness+ onSave={() => {+ // no-op — this test asserts layout, not save wiring.+ }}+ renderPreview={(value) => <div data-testid="preview-marker">{value}</div>}+ />,+ );+ const body = await screen.findByTestId('ok-code-preview-edit-modal-body');+ expect(body.className).toContain('md:flex-row-reverse');+ // `overflow-y-auto` + `overscroll-contain` are the paired defenses+ // against the below-`md` stack overflowing `DialogContent`'s clip; pin+ // both so a future refactor that drops one surfaces the regression.+ expect(body.className).toContain('overflow-y-auto');+ expect(body.className).toContain('overscroll-contain');+ });++ test('body drops the row-reverse token when the preview pane is absent', async () => {+ // Without a preview slot the modal collapses to a single-pane source+ // editor — flex-direction should stay column at every width, no visual+ // swap semantics to preserve. Pinned so a future consumer can't+ // accidentally trigger the wide-viewport row layout by wiring the class+ // set unconditionally.+ render(+ <Harness+ onSave={() => {+ // no-op — this test asserts layout, not save wiring.+ }}+ />,+ );+ const body = await screen.findByTestId('ok-code-preview-edit-modal-body');+ expect(body.className).not.toContain('md:flex-row-reverse');+ expect(body.className).not.toContain('md:flex-row');+ });+test('preview-originated edits write back into the draft and commit on Save', async () => {// The Mermaid WYSIWYG canvas in the preview slot commits gestures// through the `setValue` argument; the modal must fold those into thediff --git a/packages/app/src/editor/components/CodePreviewEditModal.tsx b/packages/app/src/editor/components/CodePreviewEditModal.tsxindex 5e88a3c99..ed3032083 100644--- a/packages/app/src/editor/components/CodePreviewEditModal.tsx+++ b/packages/app/src/editor/components/CodePreviewEditModal.tsx@@ -7,11 +7,20 @@* future preview-class nodes (Mermaid, Math) can wire in without* duplicating the dialog + CodeMirror plumbing.*- * Layout: two columns inside a shadcn `<Dialog>`. CodeMirror on the- * left, live preview on the right. The preview consumes a *debounced*- * draft (default 300ms) so heavy preview surfaces (HTML iframe, KaTeX- * lazy load, Mermaid layout) don't thrash on every keystroke. The- * source editor itself stays buttery — debouncing only the preview.+ * Layout: two columns inside a shadcn `<Dialog>`. Live preview visually on+ * the left (the reader's anchor — 'what does this look like?'), CodeMirror+ * source visually on the right (what they're changing). The visual swap is+ * done via `md:flex-row-reverse` rather than JSX order — source stays first+ * in the DOM so keyboard tab order reaches the editor before the preview's+ * own controls (Mermaid pan/zoom toolbar, HTML iframe), and the stacked+ * (below-`md`) layout keeps the editor on top rather than the render.+ * The body is scrollable (`overflow-y-auto`) so when the two `min-h-[260px]`+ * panes stack past `DialogContent`'s clip on short viewports, users can+ * scroll to the second pane instead of losing it below the fold.+ * The preview consumes a *debounced* draft (default 300ms) so heavy preview+ * surfaces (HTML iframe, KaTeX lazy load, Mermaid layout) don't thrash on+ * every keystroke. The source editor itself stays buttery — debouncing only+ * the preview.** Keyboard:* - `Esc` cancels and closes the modal (matches every other shadcn@@ -27,7 +36,7 @@* doc-agnostic.** Preview pane is opt-in: passing `renderPreview` mounts the- * right-hand iframe / KaTeX / Mermaid render; omitting it makes the+ * left-hand iframe / KaTeX / Mermaid render; omitting it makes the* modal a single-pane source editor for nodes where the preview-while-* editing case doesn't apply.*/@@ -374,9 +383,23 @@ export function CodePreviewEditModal({)}</DialogHeader><div- className={`flex min-h-0 flex-1 gap-3 ${previewEnabled ? 'flex-col md:flex-row' : 'flex-col'}`}+ className={`flex min-h-0 flex-1 gap-3 overflow-y-auto overscroll-contain ${previewEnabled ? 'flex-col md:flex-row-reverse' : 'flex-col'}`}data-testid="ok-code-preview-edit-modal-body">+ {/* DOM order below is source-first, preview-second by design:+ - keeps the CodeMirror host ahead of the preview's own tab+ stops (Mermaid pan/zoom toolbar, HTML iframe) so keyboard+ users reach the editor first;+ - the stacked (below-`md`) layout renders the editor on top,+ the render below — the user came here to edit, so putting+ the editor where it can be reached matters more than+ showing the render first;+ - the visual "render on the left" that the shared surface+ promises comes from `md:flex-row-reverse` on the body, not+ from JSX order.+ Shared with every preview-class edit modal (HTML fence,+ Mermaid, future Math etc.) so the split is consistent+ across all of them. */}<divref={setHostRef}className="ok-codepreview-cm min-h-[260px] flex-1 overflow-hidden rounded-md border border-border md:min-h-0"