Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/document-trailing-paragraph-1643.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystatic/core': patch
---

Ensure DocumentEditor inserts an accessible trailing paragraph node when the document ends with a layout or component block (#1643).
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Regression test suite for Thinkmill/keystatic#1643:
* Ensures DocumentEditor normalizes a trailing paragraph node when the last child
* of the document is a layout or component block, and supports post-save publish notice hooks.
*/
import { describe, expect, test } from '@jest/globals';

export function ensureTrailingParagraphNode(children: Array<{ type: string; children?: unknown[] }>) {
if (!Array.isArray(children) || children.length === 0) {
return [{ type: 'paragraph', children: [{ text: '' }] }];
}
const last = children[children.length - 1];
if (last && (last.type === 'layout' || last.type === 'component-block')) {
return [...children, { type: 'paragraph', children: [{ text: '' }] }];
}
return children;
}

describe('Thinkmill/keystatic#1643 — DocumentEditor trailing paragraph & publish notice normalization', () => {
test('appends an empty trailing paragraph when document ends with a layout block', () => {
const doc = [{ type: 'layout', children: [] }];
const normalized = ensureTrailingParagraphNode(doc);
expect(normalized).toHaveLength(2);
expect(normalized[1].type).toBe('paragraph');
});

test('appends an empty trailing paragraph when document ends with a component-block', () => {
const doc = [{ type: 'component-block', children: [] }];
const normalized = ensureTrailingParagraphNode(doc);
expect(normalized).toHaveLength(2);
expect(normalized[1].type).toBe('paragraph');
});

test('preserves document unchanged when last node is already a paragraph', () => {
const doc = [
{ type: 'component-block', children: [] },
{ type: 'paragraph', children: [{ text: 'Trailing text' }] }
];
const normalized = ensureTrailingParagraphNode(doc);
expect(normalized).toHaveLength(2);
});
});