prosemirror-elements icon indicating copy to clipboard operation
prosemirror-elements copied to clipboard

Add option to insert content to a new node during creation

Open fredex42 opened this issue 9 months ago • 1 comments

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 avatar Apr 10 '25 16:04 fredex42

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.

jonathonherbert avatar Apr 15 '25 10:04 jonathonherbert