Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyMCE editor events and transformation APIs #6648

Closed
danielbachhuber opened this issue May 8, 2018 · 11 comments
Closed

TinyMCE editor events and transformation APIs #6648

danielbachhuber opened this issue May 8, 2018 · 11 comments
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@danielbachhuber
Copy link
Member

danielbachhuber commented May 8, 2018

One of the plugins I help create is Tasty Links, which automatically adds links around specific keywords. For example, here is Gutenberg automatically linked to wordpress.org/gutenberg:

image

If you click on a Tasty Link, a custom preview toolbar (based on editor.wp._createToolbar) appears:

image

Notably, this isn't the standard WordPress link UX. The previewed Tasty Links look like links because of a custom editor stylesheet. In reality, they're <span> stripped on save:

image

If I click the "Remove" icon in the preview toolbar, then the <span> is replaced with a HTML comment that is persisted on save:

image

Here's the corresponding JavaScript for my TinyMCE plugin.

In order to recreate the same Tasty Links UX in Gutenberg, I think all I need is:

  • Ability to bind to a click event within Gutenberg.
  • editor.dom equivalent (which supports select(), addClass(), removeClass(), etc).

Related #4658

@danielbachhuber danielbachhuber added [Feature] Extensibility The ability to extend blocks or the editing experience [Type] Help Request Help with setup, implementation, or "How do I?" questions. Backwards Compatibility Issues or PRs that impact backwards compatability labels May 8, 2018
@danielbachhuber
Copy link
Member Author

@azaozz @iseulde Could I get your thoughts on ^ when you have a moment?

@danielbachhuber danielbachhuber added this to the Merge Proposal: Back Compat milestone May 14, 2018
@ellatrix
Copy link
Member

I'm not entirely sure what you're trying to create. So far I understand:

  • You type some words.
  • One keyword that has been typed should be recognised and wrapped in a link?
  • The link should be editable? Or it it fixed?
  • What does the span do? What should be output on the front-end?

@danielbachhuber
Copy link
Member Author

I'm not entirely sure what you're trying to create.

The product launched, so there's more detail available here. In a nutshell, the plugin automatically adds links around specific keywords on the frontend. But in the backend, rather than render the links themselves, the plugin creates a link-like UX around <span> in the editor.

Taking a step back towards Gutenberg, what seems to be missing are APIs equivalent to TinyMCE.activeEditor and TinyMCE.dom.DOMUtils.

Related #3688

@ellatrix
Copy link
Member

I'm hesitant to let plugins use TinyMCE APIs because this might all change. We'll have to create something here to would enable you to create a similar experience. How about adding the links in the content before it loads in the editor? Why does it have to be a span? Just trying to understand it better.

@danielbachhuber
Copy link
Member Author

It has to be a <span> to avoid standard editor behavior around <a>. Specifically, if the <span> preview is removed:

image

Then a HTML comment is added:

image

I'm hesitant to let plugins use TinyMCE APIs because this might all change.

I'm not suggesting we use TinyMCE APIs directly. A reasonable alternative would be to expose named Gutenberg APIs whose underlying implementation can change.

More so though, I'd love to get up to speed on any existing conversation that's been had on this topic.

@ellatrix
Copy link
Member

Okay. It would almost seem ideal if it followed the normal link behaviour where the link would be added on text input only. Then when the user removes it, it just would no longer show up. Might not be what you want though. Not sure atm how else this would be possible without a huge amount of code.

Related: #771.

@mtias
Copy link
Member

mtias commented Jul 19, 2018

Closing to focus on #3688.

@mtias mtias closed this as completed Jul 19, 2018
@gziolo
Copy link
Member

gziolo commented Oct 26, 2018

We have just landed Format API with #10068. It allows registering any format you need. We are still working on a way to give better control which control can be displayed for a given block and documentation. It should be all ready early next week.

I think that most of the functionality described here can be recreated with new API, I'm only not quite sure about HTML comment.

@danielbachhuber
Copy link
Member Author

@gziolo @iseulde The HTML I need to target is this:

<span class="tasty-link" data-tasty-link-href="https://www.bobsredmill.com/">Bob's Red Mill</span>

Is it possible to registerFormat() for span.tasty-link?

@danielbachhuber danielbachhuber added the [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable label Nov 2, 2018
@ellatrix
Copy link
Member

ellatrix commented Nov 16, 2018

@danielbachhuber you can now target it with tagName: 'span' and className: 'tasty-link'. See #11488. Do you need anything else?

@danielbachhuber
Copy link
Member Author

@iseulde Should be good now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants