Skip to content

Replace the WYSIWYG editor with TipTap#10196

Merged
alecslupu merged 323 commits intodecidim:developfrom
mainio:feature/tiptap-editor
May 25, 2023
Merged

Replace the WYSIWYG editor with TipTap#10196
alecslupu merged 323 commits intodecidim:developfrom
mainio:feature/tiptap-editor

Conversation

@ahukkanen
Copy link
Copy Markdown
Contributor

@ahukkanen ahukkanen commented Dec 29, 2022

🎩 What? Why?

This PR implements the TipTap editor for Decidim.

This is feature complete and works both in the legacy design (admin panel) as well as in the redesign (you need to test it locally not to break staging, instructions below).

Can be tested at (use default seed credentials):
https://tiptap.decidimqa.mainiotech.fi/

📌 Related Issues

Here are also some issues we have had in the past with Quill that should be confirmed to be fixed when testing this:

Testing

  • Clone this branch, create the development app (you may need to regenerate it as packages have changed)
  • In another window, open try.decidim.org
  • Go to admin panel in both versions
  • Find a view with WYSIWYG editor
  • Try it out
  • Compare that we have all functionality available that we used to have with Quill

Currently there does not seem to be any redesigned view yet with the editor (e.g. new proposal / new meeting / new initiative / etc.) but you can test it locally under the redesign by adding it to some page, e.g. at the static page view as follows:

          <!-- Add this BELOW the <div class="editor-content mt-6">...</div> wrapper -->
          <div class="mt-6">
            <%= decidim_form_for(Decidim::StaticPage.new, url: "") do |form| %>
              <%= form.editor(:content) %>
            <% end %>
          </div>

And if you want to test the full toolbar with the video embed and image embed functionality, replace the line with form.editor with this (note that you need to be logged in for the image embedding to work because of the permissions set for the image upload endpoint):

<%= form.editor(:content, toolbar: "full") %>

Note that this PR already includes E2E tests (system tests) for testing the editor functionality under both, the legacy design as well as the redesign.

Extra features

The new editor also comes with some extra features that you can test:

  • Automatically formatting pasted content
    • Try pasting a YouTube URL, e.g. https://www.youtube.com/watch?v=f6JMgJAQ2tc
    • Try pasting markdown content, e.g. **this should appear as bold**
  • Markdown shortcuts
    • Try writing e.g. a heading to the editor, start the text with ## + SPACE and continue writing your heading
    • Try writing e.g. a bold to the editor, write double stars ** followed by some text and then again double stars **
  • Character counter
    • You can try it at the participant side, e.g. when submitting a new proposal
  • Hastags support, try e.g. with new proposal
  • Mentions support (right now we do not have any WYSIWYG editor in Decidim that supports mentions but the support is built to the editor)
  • Double clicking existing embedded content (images or videos) to edit them

📷 Screenshots

Participant editor with demonstration of the available controls

Participant WYSIWYG

Admin editor with extra controls

Admin editor view

Link dialog

WYSIWYG link dialog

Image dialog

WYSIWYG image dialog

Video dialog

WYSIWYG video dialog

Supports YouTube and Vimeo by default or any arbitrary service as long as they provide embeddable video URLs.

Image resizing support

As in the old editor, we have image resizing support also in the new editor.

WYSIWYG image resizing

Redesigned editor

Redesigned WYSIWYG

Link dialog (redesigned)

WYSIWYG link dialog (redesigned)

Image dialog (redesigned)

WYSIWYG image dialog (redesigned)

Video dialog (redesigned)

WYSIWYG video dialog (redesigned)

The image upload response handling was not always returning a
promise which caused inconsistent behavior across browsers.
- In order to control the editor styling while the modal dialogs
  are open, add a new dialog extension that stores the dialog state
  for the editor itself
- Refactor the image extension to move the custom node view for
  image resizing to its own file
In order to maintain consistency for the structuring of the code,
move other extensions to a folder stucture after the image
extension required its own folder.
The `img` element's src can also get the hostname prepended to it
when the previous check would not work. Updated to check if the
actual node attribute has changed.
As the generated editor HTML changed, the expectation also needs
to be changed.
In case the editor container contains the classes to indicate
these features are needed, only add those extensions in that
case.
The editor implements its own hashtags and mentions functionality
which is why we do not need to attach tribute to the editors.
@ahukkanen ahukkanen requested a review from a team April 28, 2023 13:46
@ahukkanen
Copy link
Copy Markdown
Contributor Author

ahukkanen commented Apr 28, 2023

@decidim/maintainers This is now finally ready for technical review after the current editor toolbar issues have been resolved at develop and the changes have been reflected to this branch.

Meanwhile we have been waiting to merge this, we have also received a stable release last month for Tiptap version 2 🥳:
https://tiptap.dev/blog/tiptap-release-day

I have also updated the Tiptap to the stable version.

EDIT: Staging/QA environment has also been updated with the latest code.

@andreslucena
Copy link
Copy Markdown
Member

Meanwhile we have been waiting to merge this, we have also received a stable release last month for Tiptap version 2 🥳 :
tiptap.dev/blog/tiptap-release-day

I have also updated the Tiptap to the stable version.

Great news!! 👏🏽 👏🏽

EDIT: Staging/QA environment has also been updated with the latest code.

@carolromero could you give it an eye? Thanks!

Copy link
Copy Markdown
Contributor

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial Reviewed, I have a quill related issue while upgrading.

@carolromero
Copy link
Copy Markdown
Member

@carolromero could you give it an eye? Thanks!

I took a look and everything seems to be fine 👍

@ahukkanen ahukkanen requested a review from alecslupu May 23, 2023 07:31
Copy link
Copy Markdown
Contributor

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per documentation, the task bin/rails decidim:upgrade:migrate_wysiwyg_content should migrate all the content . However, when i run the task, i get the following error:

ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "admin_terms_of_use_body" does not exist
LINE 1: ...cidim_organizations"."welcome_notification_body", "admin_ter...
                                                             ^
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:48:in `block in convert_model_data'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:47:in `convert_model_data'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:32:in `block in update_records_batches'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:31:in `each_with_index'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:31:in `update_records_batches'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:80:in `block in update_models'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:79:in `each'
/code/decidim/decidim-core/lib/decidim/upgrade/wysiwyg_migrator.rb:79:in `update_models'
/code/decidim/decidim-core/lib/tasks/upgrade/decidim_migrate_wysiwyg_content.rake:53:in `block (3 levels) in <main>'
/code/bin/rails:5:in `<top (required)>'
/code/bin/spring:10:in `block in <top (required)>'
/code/bin/spring:7:in `<top (required)>'

It seems that in the task ( decidim:upgrade:register_wysiwyg_migration) the old field name ( admin_terms_of_use_body ) is being used. As per change done in #10614, the field should be renamed to admin_terms_of_service_body.

After this change is being made, all should be ok from my end.

@ahukkanen ahukkanen requested a review from alecslupu May 24, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from QuillJS to Tiptap Editor Relative links are handled as external links in WYSIWYG

6 participants