backdrop-contrib / tinymce

Integration for the TinyMCE editor in Backdrop CMS
https://backdropcms.org/project/tinymce
GNU General Public License v2.0
2 stars 1 forks source link

Icon API: icons via backdrop_add_icon() aren't available in editor content #102

Open indigoxela opened 1 month ago

indigoxela commented 1 month ago

Maybe an edge case, maybe not...

Icon definitions attached to pages are unknown in the editor iframe. Should they be available?

Example use-case: a theme defines some styles for a tag that needs an icon URL for a mask. The CSS can get attached, but the definitions for icon URLs aren't, as that's a js setting.

Need to think this over a bit.

indigoxela commented 1 month ago

A quick experiment... this would only require some lines of code in tinymce-integration.js, as TinyMCE has an option for that - content_style. Fancy.

      if (Backdrop.settings.icons) {
        let inlineStyle = ':root{';
        for (const [key, value] of Object.entries(Backdrop.settings.icons)) {
          inlineStyle += '--icon-' + key + ':url(' + value + ');';
        }
        inlineStyle += '}';
        options.content_style = inlineStyle;
      }

It works! But the question's still: does it make sense to add that?

indigoxela commented 1 month ago

My PR provides a "bridge" between main page and iframe, by attaching the icon definitions from one as TinyMCE option for the other.

It might still be an edge case, but isn't much overhead, either.