wagtail: Copy and paste (or move) StreamField blocks into different pages/fields.
Is your proposal related to a problem?
There is currently a “Duplicate” which allows duplicating content of a StreamField blocks into the same hierarchy. It would be nice if it was possible to “copy” a StreamField block data into another page… Or extract it from a page into a snippet. obviously the target StreamField would have to support the same block types.
I often have the problem that a user worked on some content for a while and I later want to introduce a different nesting or extract it into a separate snippet. Right now the only solution would be to manually recreate all the content. I guess I could just extract the JSON data from the database. But it would be nice if there would be a UI.
Describe the solution you’d like
In addition to a “Duplicate” button a “Copy” button which would copy the json data from one field, and allows to paste it into a different StreamField which has the same blocks configuration.
Working on this
Assigned to @thibaudcolas. This requires a fair bit of UI expertise. The block chooser itself is built with React. View our contributing guidelines, add a comment to the issue once you’re ready to start.
Tasks
- Complete feedback process in #12354
- Final decision between modern Clipboard API and execCommand (1h)
- Implement a first UX prototype with basic copy-paste support (3h)
- Review overlap with client-side validation rules (block counts min/max, possibly required blocks) (1h)
- Implement production-ready version with UX changes and SF data model (8h)
- Release notes (TBC feature sponsor?) (1h)
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 6
- Comments: 26 (16 by maintainers)
+1 It’s really frustrating to have to copy all the content between blocks when the hierarchy of a page changes. It’d also work if you could in the UI do something where you drag a block around or have a dropdown to select a new parent block.
Can I work on this?
Ref this discussion about the broader UI and design implications of adding copy-paste drag-and-drop to StreamField: https://github.com/wagtail/wagtail/discussions/12354
“Partial preservation of the contents” has my vote 👍
Yes, that is what I mean.
The paragraph to paragraph would work because both the block type (
'paragraph') and block class (blocks.RichTextBlock()) in the source and target area are the same.'heading'and'sub_heading'sound the same, but are different.The rule “it is the same class, it should accept the data” will not work. Because:
For example:
Copy
headingfrom streamfield A into B, what should happen? Will the heading be converted into a quote block? Will the heading become a copyright block? I think streamfield B should not accept the pasted data.Note, there is a big difference between:
Point 1, will create the new block and populate the data (this is what the OP asks). This requires the exact same blocks in source and target streamfields.
Point 2, the class of the target block is already known. This might give more options… Maybe text based blocks could accept each others data? But this wouldn’t be that different to just copy/paste the fields contents. And, this is a slippery slope too: SteamBlocks and StructBlocks are complex data structures, and pasting into them will lead to the same issues as with point 1.
@thibaudcolas, I’m not sure how common it is to define multiple text blocks, but I’m confident that projects can have blocks with identical signatures.
For example, the following seems valid:
And the template
In my projects, it is common to subclass Wagtail-supplied blocks and only override the template. These blocks store the same data but render differently, which is somewhat related to the example above.
I believe that introspection of blocks to determine compatibility would be unnecessarily complex and unpredictable. Most content editors likely just want to copy a block from field A to field B and expect it to retain the same type (or be discarded if it’s not compatible). Copying and pasting data while automatically changing the block type seems problematic. For instance, you can’t put the data from heading into copyright just because they are both text-based—it doesn’t make sense.
For these reasons, I would expect the copy-paste feature to respect both the block type (heading, copyright, quote) and the block class (CharBlock). Any mismatch should result in the data being discarded.
I’m neutral on the feedback suggestion.
This might seem strict, but it’s at least very clear and aligns with Draftail’s behavior. Most of the projects I work on are very consistent in type/block combinations across various StreamFields, so I believe requiring some consistency on streamfield definitions to make copy/paste work, is a small thing to ask (from integrators).
I agree. We definitely need a way to drag and drop streamfields on the same page and copy them to other pages.
Is there any progress on this issue? This feature would be very useful!