Skip to content

feat(blocks,admin): portable_text and block_list Block Kit fields + Duplicate on plugin block cards - #2674

Closed
simone-coelho wants to merge 3 commits into
emdash-cms:mainfrom
simone-coelho:feat/block-kit-portable-text-and-block-list
Closed

simone-coelho wants to merge 3 commits into
emdash-cms:mainfrom
simone-coelho:feat/block-kit-portable-text-and-block-list

Conversation

@simone-coelho

Copy link
Copy Markdown

What does this PR do?

Adds two structured Block Kit elements — portable_text and block_list — and a Duplicate action on plugin block cards, so plugin blocks can carry rich text and nested registered-block content that stays fully editable in the admin editor.

  • portable_text: the plugin block dialog mounts the existing PortableTextEditor for a Portable Text block array. Structure round-trips intact (blocks, spans, marks, markDefs, keys) and is never flattened to a string. The previous best option — a multiline text_input over stored Portable Text — showed an empty box and replaced the array with a plain string on save.
  • block_list: an ordered list of registered plugin blocks ({ _type, _key, ...fields } items). Authors add from the same registered catalog the document editor offers, edit through the chosen block's own Block Kit form, duplicate, delete, drag to reorder, and move an item to a sibling list when one form holds several lists (including lists nested in repeater rows — e.g. one list per column). allowed_types / min_items / max_items bound the list.
  • Duplicate on plugin block cards inserts an identical copy after the original, beside Edit and Delete.

Both elements are additive Element union members with validation mirroring their peers, are accepted as repeater sub-fields, and return null from the runtime renderElement exactly like repeater. No existing block or stored value changes behavior.

Discussion: #2673 (opened alongside this PR — maintainer approval pending; happy to adjust the design there).

Closes #

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (@emdash-cms/blocks and @emdash-cms/admin; registry-verification needs built siblings and is untouched)
  • pnpm lint passes (lint:quick clean)
  • pnpm test passes (blocks 120/120; full admin browser suite 124 files / 1523 tests; new focused suite tests/editor/block-kit-structured-fields.test.tsx covers all three behaviors)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: Structured Block Kit fields: portable_text and block_list, plus Duplicate on plugin block cards #2673 (approval pending — opened with this PR)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Fable 5 (Claude Code)

Screenshots / test output

blocks:  Test Files  4 passed (4) · Tests  120 passed (120)
admin:   Test Files  124 passed (124) · Tests  1523 passed (1523)
new:     tests/editor/block-kit-structured-fields.test.tsx  5 passed (5)

Copilot AI lite review requested due to automatic review settings August 25, 2026 23:20
@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 1,160 lines across 10 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@changeset-bot

changeset-bot Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b173aaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@emdash-cms/blocks Minor
@emdash-cms/admin Minor
emdash Minor
@emdash-cms/plugin-test Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/auth Minor
create-emdash Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
@emdash-cms/auth-atproto Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two new structured Block Kit field types (portable_text and block_list) that plugin blocks can use to store rich Portable Text arrays and nested registered-block content (editable via the existing admin editor UI), and adds a Duplicate action for plugin block cards.

Changes:

  • Extend @emdash-cms/blocks Element/validation/builder APIs to support portable_text and block_list, including repeater sub-field support.
  • Add admin UI rendering for portable_text/block_list inside the plugin block modal (including block catalog integration, duplication/removal, reorder, and sibling-list moves).
  • Add focused admin and blocks tests plus a changeset for the feature release.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/blocks/tests/validation.test.ts Adds validation coverage for portable_text, block_list, and repeater sub-field usage + invalid cases.
packages/blocks/src/validation.ts Registers new element types and adds validation rules for portable_text and block_list.
packages/blocks/src/types.ts Extends the public Block Kit Element union and repeater sub-field union with new structured element interfaces.
packages/blocks/src/render-element.tsx Treats portable_text/block_list as admin-only elements (runtime render returns null).
packages/blocks/src/index.ts Exports the new element types from the package entrypoint.
packages/blocks/src/builders.ts Adds builder helpers portableText() and blockList() and exports them via elements.
packages/admin/tests/editor/block-kit-structured-fields.test.tsx Adds focused UI/behavior tests for the two structured fields and plugin-block duplication.
packages/admin/src/components/PortableTextEditor.tsx Implements the structured field UI components, sibling-list move context, and integrates them into the plugin block modal.
packages/admin/src/components/editor/PluginBlockNode.tsx Adds Duplicate button to plugin block cards in the editor.
.changeset/structured-block-kit-fields.md Documents the feature set and bumps @emdash-cms/blocks and @emdash-cms/admin as minor.
Suppressed comments (2)

packages/admin/src/components/PortableTextEditor.tsx:2548

  • When inserting/updating a block_list item, { _key: ..., ...values } allows values._key to overwrite the generated/preserved key (same for _type if it ever appears). Spreading values first and then setting _key/_type last prevents accidental overrides.
		if (child.index === null) {
			emit([...items, { _key: newBlockKey(), ...values, _type: child.def.type }]);
		} else {
			const index = child.index;
			emit(

packages/admin/src/components/PortableTextEditor.tsx:1971

  • The dialog footer buttons use hard-coded English strings (Cancel, Save, Insert). Admin UI strings should be wrapped for translation via Lingui.
							<Button type="button" variant="ghost" onClick={onClose}>
								Cancel
							</Button>
							<Button type="submit" disabled={!canSubmit}>
								{isEditing ? "Save" : "Insert"}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +609 to +616
for (let i = 0; i < value.initial_value.length; i++) {
if (!isRecord(value.initial_value[i])) {
errors.push({
path: `${path}.initial_value[${i}]`,
message: "Each initial_value entry must be a Portable Text block object",
});
}
}
const catalog = React.useContext(PluginBlockCatalogContext);
const siblingsContext = React.useContext(BlockListSiblingsContext);
const scope = React.useContext(BlockListScopeContext);
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));
ref={inputRef}
type="url"
className="w-full"
placeholder={block?.placeholder || "Enter URL..."}
</form>
)}
</div>
<div className="flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2">
Comment on lines +2431 to +2444
const initialValue = React.useRef<PortableTextBlock[]>(
Array.isArray(value) ? (value as PortableTextBlock[]) : [],
).current;
return (
<div>
<label className="text-sm font-medium mb-1.5 block">{field.label}</label>
<PortableTextEditor
value={initialValue}
onChange={(next) => onChange(field.action_id, next)}
placeholder={field.placeholder}
className="rounded-md border border-kumo-line"
/>
</div>
);

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds genuinely useful Block Kit fields (portable_text, block_list) and a Duplicate action for plugin block cards. The approach fits EmDash well: it reuses the existing PortableTextEditor and Block Kit form machinery, keeps the runtime renderer returning null (so stored values round-trip unchanged), and is additive with no existing behavior change. The code is mostly clean and localized.

One readiness concern that isn’t a code bug but affects merge readiness: AGENTS.md requires a maintainer-approved Discussion for new features. The linked Discussion #2673 was opened alongside this PR and approval is still pending. That should be resolved before merge.

I reviewed statically (did not run tests or lint, per instructions). I found a few real issues worth fixing:

  • Canonical docs are missing the new element types. The changeset is good, but docs/src/content/docs/plugins/creating-plugins/block-kit.mdx and skills/creating-plugins/references/block-kit.md still omit portable_text and block_list (and several existing elements). Per .changeset/README.md, useful explanations/examples should not live only in the changeset.
  • block_list drag-and-drop lacks keyboard support. The sibling BlockKitRepeater uses both PointerSensor and KeyboardSensor; BlockKitBlockListField only uses the pointer sensor, so keyboard users can’t reorder items.
  • Moving an item to a sibling list can violate max_items. The receive callback appends unconditionally while the Add button correctly stops at the limit.
  • The move/type selects are unlabeled. They need an accessible name for screen-reader users.
  • The duplicate-plugin-block test should verify distinct _key values, since duplicate keys would break Portable Text identity downstream.

None of these appear to risk data loss or a broken build, so I’m leaving this as comment rather than request_changes.

{ type: "portable_text", action_id: "content", label: "Content" }
```

#### `block_list`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The changeset describes portable_text and block_list well, but the canonical reference docs still omit them. docs/src/content/docs/plugins/creating-plugins/block-kit.mdx and skills/creating-plugins/references/block-kit.md only list the original element types, so plugin authors have no discoverable documentation for the new fields. Per .changeset/README.md, useful explanations and examples should not live only in the changeset/CHANGELOG — add them to the canonical docs too. I’d expand the Element Types tables in both files to include portable_text, block_list, and the existing missing entries (repeater, media_picker, etc.) with short descriptions and examples.

Suggested change
#### `block_list`
#### `block_list`
An ordered list of registered plugin blocks...

(Apply the doc expansion in docs/src/content/docs/plugins/creating-plugins/block-kit.mdx and skills/creating-plugins/references/block-kit.md.)

const catalog = React.useContext(PluginBlockCatalogContext);
const siblingsContext = React.useContext(BlockListSiblingsContext);
const scope = React.useContext(BlockListScopeContext);
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] BlockKitBlockListField only wires up a PointerSensor for drag-and-drop. The sibling BlockKitRepeater uses both pointer and keyboard sensors, so keyboard users currently cannot reorder block_list items. Add the keyboard sensor for parity and accessibility.

Suggested change
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));
const sensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
);

Comment on lines +2511 to +2512
receive: (incoming) =>
emitRef.current([...itemsRef.current, { ...incoming, _key: newBlockKey() }]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The sibling-list receive callback appends a moved item without checking whether this list has already reached field.max_items. That makes "Move to…" bypass the documented bound while the Add button correctly stays disabled. Guard the append against the list’s own limit.

Suggested change
receive: (incoming) =>
emitRef.current([...itemsRef.current, { ...incoming, _key: newBlockKey() }]),
return registerSibling({
id: listId,
label: listLabel,
receive: (incoming) => {
if (maxItems !== undefined && itemsRef.current.length >= maxItems) return;
emitRef.current([...itemsRef.current, { ...incoming, _key: newBlockKey() }]);
},
});

</div>

{pickingType && (
<Select

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] The block-type picker <Select> has no accessible name. Its purpose is conveyed only by the placeholder text, which may not be exposed to assistive tech as a label. Add an explicit aria-label (or wrap it in a visible <label>).

Suggested change
<Select
<Select
aria-label={t`Choose block type`}
value=""

{summary && <span className="ms-2 text-kumo-subtle">{summary}</span>}
</span>
{moveTargets.length > 0 && (
<Select

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] The "Move to…" <Select> also has no accessible name. Add an aria-label so screen-reader users know which sibling list the control will move the current item into.

Suggested change
<Select
<Select
aria-label={t`Move item to another list`}
value=""

const blocks = onChange.mock.calls.at(-1)![0] as Array<Record<string, unknown>>;
const copies = blocks.filter((b) => b._type === "acme.heading");
expect(copies[0]!.text).toBe("Duplicate me");
expect(copies[1]!.text).toBe("Duplicate me");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] The test verifies that two acme.heading blocks exist with identical text, but it does not assert that the duplicate received a fresh _key. Duplicate Portable Text keys would break identity downstream and should be caught if the duplicate action ever regresses. Add a _key uniqueness assertion.

Suggested change
expect(copies[1]!.text).toBe("Duplicate me");
expect(copies[0]!.text).toBe("Duplicate me");
expect(copies[1]!.text).toBe("Duplicate me");
expect(copies[0]!._key).not.toBe(copies[1]!._key);

@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/needs-review No maintainer or bot review yet labels Aug 25, 2026
@simone-coelho

Copy link
Copy Markdown
Author

Added one more piece to the same feature (c96e80c): an optional hidden flag on plugin block definitions. A hidden block stays fully registered — existing blocks render and edit unchanged, and block_list items resolve their defs — but document-level insert surfaces (the slash menu, and a block_list picker without allowed_types) no longer offer it. A block_list whose allowed_types names the type still does, so a plugin can ship child-only blocks reachable exclusively inside the parents that declare them. Covered by three focused tests in the same test file; changeset updated.

@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@simone-coelho

Copy link
Copy Markdown
Author

Second follow-up commit (0ca416a), both found by driving the real dialog against an imported page rather than in unit tests:

  • portable_text: a child block's dialog seeds its form values in an effect after first render, so the uncontrolled nested Portable Text editor mounted empty and one Save replaced the stored paragraphs with only the newly typed text. The field now re-seeds a changed incoming value until the author types (the same prop-sync the repeater already applies to its rows); once dirty the author's document is never replaced from outside. The child dialog's initialValues are also memoized so the seed effect doesn't re-run every render.
  • repeater: the sub-field change handler built the next rows from its render closure, so the two writes of a move between two rows' block lists (target row, then source row) let the second erase the first and the moved block vanished. Handlers now read the latest rows through a ref.
  • visiblePluginBlocks moved into PortableTextEditor.tsx so suites that mock PluginBlockNode with partial factories keep importing.

Focused tests cover both (10 in the structured-fields file); the full admin suite is green (124 files / 1528 tests).

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

…lock_list — plus Duplicate on plugin block cards

portable_text mounts the standard Portable Text editor inside the plugin
block dialog and round-trips full Portable Text arrays (blocks, spans,
marks, markDefs, keys) without ever flattening to a string. block_list
holds an ordered list of registered plugin blocks with add (from the same
registered catalog the document editor offers), per-block Block Kit edit,
duplicate, delete, drag reordering, and move-to-sibling-list when several
lists share one form (including lists nested in repeater rows). Plugin
block cards gain a Duplicate action inserting an identical copy after the
original. Both new elements validate like their peers, are accepted as
repeater sub-fields, and return null from the runtime renderElement like
repeater.
… not offered on document-level insert surfaces

A block with hidden: true stays fully registered (existing blocks render and
edit unchanged, block_list items resolve their defs) but is skipped by the
slash menu and by a block_list picker that declares no allowed_types. An
explicit allowed_types naming the type still offers it, so plugins can ship
child-only blocks reachable exclusively inside the parents that declare them.
…eds a late value until the author types; repeater handlers read the latest rows so a block moved between two rows' block lists survives; the visible-block helper lives in the editor module

Found by driving the real dialog: a child block's dialog seeds its form
values in an effect after first render, so the uncontrolled nested
Portable Text editor mounted empty and one Save replaced the stored
paragraphs with only the newly typed text. The repeater's sub-field
change handler built the next rows from its render closure, so the two
writes of a move (target row, then source row) let the second erase the
first and the moved block vanished. Both are pinned by focused tests;
visiblePluginBlocks moves into PortableTextEditor.tsx so suites that mock
PluginBlockNode with partial factories keep importing.
@simone-coelho
simone-coelho force-pushed the feat/block-kit-portable-text-and-block-list branch from 0ca416a to b173aaa Compare September 24, 2026 04:14
@simone-coelho

Copy link
Copy Markdown
Author

Rebased onto current main (4eca8e3), still as the same three commits.

Typecheck, lint and format checks pass across the repo. Tests pass for @emdash-cms/blocks (163), @emdash-cms/admin (182 files, 2480 tests, browser) and @emdash-cms/plugin-test (39). We still use this downstream. I'm happy to split it if that makes review easier.

@simone-coelho

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Sep 24, 2026
@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet and removed review/needs-rereview New commits since the last review labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

This PR is waiting on its author because it has merge conflicts with main, and it has had no activity for 14 days. It will be closed in 7 days unless there is activity: push an update or leave a comment to keep it open.

@github-actions github-actions Bot added stale and removed stale labels Oct 9, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Closing after 21 days without activity while waiting on its author because it has merge conflicts with main. When you're ready to continue, reopen it, or comment here and a Project Team member will reopen it.

@github-actions github-actions Bot closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants