[DEV-13852] Refactoring - Allow custom rendering of placeholders #574
+77
−108
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.
The main idea behind this refactoring is to simplify the rendering of placeholders, allowing full control over the contents of the placeholders as soon as they're clicked and to also improve the developer experience when adding or modifying the existing UI. Since a lot of the placeholder code will now be part of the consumer codebase, we don't have to release new versions of the editor when doing copy changes for example.
I chose the
GalleryBookmarkPlaceholderElement
as a proof of concept since it also contains the site switcher. The plan is (if we agree to it) to rework the remaining "search input" placeholders and then eventually rework the regular "input" placeholders as well.The interface has been simplified into sort of a "headless" approach, so now the consumer only needs to provide a
renderPlaceholder
function that will receive different props based on the required logic.This allows full control over the UI and also allows usage of consumer code's UI components instead of having to rely on the UI components present (or not present) in the editor. This way, we can get rid of things like
invalidateSuggestions
etc. that were more of a band-aid to the current solution rather than a proper fix.In this case, the gallery bookmark placeholder rendering function will receive props like
onSelect
(when an option is selected) andonRemove
(when we want to remove the placeholder).For example, the
onSelect
callback expects a promise that will resolve to an object containing theOEmbedInfo
of a given gallery, so we no longer need to providefetchOembed
to the editor and we can do all of this outside in the app.You can see how the new approach is implemented in https://github.com/prezly/prezly/pull/15756.
Please also read the comment below and provide your thoughts on this approach.