feat: visual editing (click-to-edit) #7374
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new visual editing mode that allows users to click directly on content in the preview pane to edit fields, like in Storyblok or TinaCMS. This works for preview widgets as well as for custom full-page preview templates.
The preview templates themselves don't need to do anything in order to support this feature. This is made possible by using @vercel/stega to invisibly encode information about the origin of the values directly in the rendered text.
visual-editing.mov
The new visual editing mode is offered as an alternative to scroll sync, providing a more direct way to interact with content. When enabled, scroll sync is automatically disabled to prevent interference.
Note: Currently, all strings get encoded. It would probably make sense to allow fields to opt-out of this behavior, so that things like dates or URLs which might get further processed don't break. I left this out as the change set is already quite big and the feature as a whole is already opt-in.
Technical Details
This PR builds on top of a major refactoring (60040b8) that simplified widget reference handling, which was already in place for validation purposes.
These foundational changes were necessary to implement reliable field focusing and scrolling behavior.
Test plan
Enable visual editing for a collection in the config by adding:
editor.visualEditing: true to your collection configuration
Create or edit a post with markdown content
Click on any text in the preview pane
Verify that:
Test with custom widgets and preview templates:
Checklist
Please add a
x
inside each checkbox:A picture of a cute animal (not mandatory but encouraged)
🐨