Skip to content

Add option to insert content to a new node during creation#454

Draft
fredex42 wants to merge 3 commits intomainfrom
ag/insert-with-content
Draft

Add option to insert content to a new node during creation#454
fredex42 wants to merge 3 commits intomainfrom
ag/insert-with-content

Conversation

@fredex42
Copy link

What does this change?

Provides a new optional argument to RepeaterFieldView.addChildAfter() and RepeaterFieldView.addChildAtEnd().

The old behaviour is kept; that is, if you call field.view.addChildAfter(index) a blank field will still be inserted. However, you can now call field.view.addChildAfter(index, { nodeContent: someNode }) and have that field inserted with the given node.
As a convenience, you can also call field.addChildAfter(index, {textContent: someTextString}) and have a node automatically created for you.

How to test

How can we measure success?

Have we considered potential risks?

Images

Accessibility

@fredex42 fredex42 requested a review from a team as a code owner April 10, 2025 16:58
@fredex42 fredex42 marked this pull request as draft April 10, 2025 16:58
@jonathonherbert
Copy link
Contributor

jonathonherbert commented Apr 15, 2025

This would be a great improvement. Spoken AOB, but to summarise, for a public API the surface area here allows a few footguns:

  • no guarantee the node accepts text
  • no guarantee the node is valid in the repeater context
  • users have to construct the node, meaning users must understand ProseMirror APIs when previously they've been working with data, something this library tries to avoid

Ideally you'd pass the data (typesafely!), and the repeater would handle the translation from data to node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants