Skip to content

Allow discovery of plugin buttons via ae_uibridge #667

Closed

Description

@jbalsas

AlloyEditor supports using CKEditor plugins thanks to the ae_*bridge set of plugins. However, in order to add the buttons to a toolbar, the user needs to figure out how is the particular plugin naming the button, so for instance, in order to use the Paste from Word plugin, one would need to do the following:

var editor = AlloyEditor.editable('editable', {
    extraPlugins: AlloyEditor.Core.ATTRS.extraPlugins.value +',ae_uibridge,ae_buttonbridge,pastefromword,clipboard,dialog,dialogui',
    toolbars: {
        add: {
            buttons: ['table', 'hline', 'image', 'camera', 'PasteFromWord']
        },
        ...
    }
});

Since this is error-prone and forces the user to dig into the plugin code for the exact string, it would be nice to have some kind of API so a user could simply do:

var editor = AlloyEditor.editable('editable', {
    extraPlugins: AlloyEditor.Core.ATTRS.extraPlugins.value +',ae_uibridge,ae_buttonbridge,pastefromword,clipboard,dialog,dialogui',
    toolbars: {
        add: {
            buttons: ['table', 'hline', 'image', 'camera', ...AlloyEditor.getButtonsFor('pastefromword')]
        },
        ...
    }
});

Activity

  1. modified the milestone: 1.3.1 on Jan 9, 2017
  2. jbalsas commented on Jan 13, 2017

    @jbalsas
    ContributorAuthor

    This won't make it in the 1.3.1 milestone. Targeting next release now...

  3. added this to the milestone on Jan 19, 2017
  4. julien commented on Jan 23, 2017

    @julien
    Contributor

    Hi @jbalsas,

    Could you tell me if something like this

    Would be a possible implementation?

    Thanks!

  5. jbalsas commented on Jan 23, 2017

    @jbalsas
    ContributorAuthor

    Hey @julien, thanks for working on this. Unfortunately, I don't think that's a viable implementation. We need these to be dynamic in a way that only available buttons show up and in a way we don't have to manually maintain a plugin list.

    On top of that, there are some plugins exposing more than one ui component. For example the font plugin introduces two buttons Font and FontSize

    The expected behaviour would be:

    // Scenario 1, font plugin is loaded using extraPlugins
    editor.getButtonsFor('font'); // ['Font', 'FontSize']
    // Scenario 2, font plugin is not loaded
    editor.getButtonsFor('font'); // []

    I think the common entry point is https://github.com/liferay/alloy-editor/blob/master/src/ui/react/src/uibridge/uibridge.js#L27-L35, or inside the independent add handlers of every bridge. Plugins registering ui components are necessarily running over those handlers, and if we could identify the calling plugin, then we'd have a dynamic and real map of the available buttons.

  6. julien commented on Jan 24, 2017

    @julien
    Contributor

    Hi @jbalsas you're welcome, and thanks for the pointers I will have a look in that direction.

  7. julien commented on Jan 24, 2017

    @julien
    Contributor

    Hi again @jbalsas,

    So I had a look at https://github.com/liferay/alloy-editor/blob/master/src/ui/react/src/uibridge/uibridge.js#L27-L35 and it was a good starting point.

    I haven't prepared any pr yet, but as I understand we need some kind of "iterator" to go through all the "required" plugins given a plugin name ... (please correct me if I'm wrong)

    I've modified my previous code to look like this

    getButtonFor: function (name) {
        
        function PluginIterator(plugin) {
            this.plugin = plugin;
        }
        
        PluginIterator.prototype.hasNext = function () {
            return this.plugin && this.plugin.requires;
        };
        
        PluginIterator.prototype.next = function () {
            var plugin = CKEDITOR.plugins.get(this.plugin.requires);
            if (plugin) {
                this.plugin = plugin;
            }
            return this.plugin.name;
        };
    
        var plugin = CKEDITOR.plugins.get(name.toLowerCase());
        if (!plugin) {
            return '';
        }
    
        var iterator = new PluginIterator(plugin);
        var requires = [plugin.name];
        while (iterator.hasNext()) {
            requires.push(iterator.next());
        }
        return requires;
    }

    Which would work the following way

    AlloyEditor.getButtonFor('PasteFromWord');
    // output: ["pastefromword", "clipboard", "dialog", "dialogui"]
    
    // or in the case of an unexisting plugin
    
    AlloyEditor.getButtonFor('NoSuchPluginRegistered');
    // output: ''

    The PluginIterator might not be the best name and should probably be placed in another file (or it's own file) rather than being in the getButtonFor function, but tell me if that looks better than previously.

    Thanks!

  8. jbalsas commented on Jan 25, 2017

    @jbalsas
    ContributorAuthor

    Hey @julien, you're overthinking this. Take the font plugin as an example.

    You can see that it will call the editor.ui.addRichCombo method one per registered ui component.

    In there, we already have the buttons names, so we could simply do:

    var pluginName = /plugins\/(.*)\/plugin.js/.exec((new Error().stack))[1];
    
    AlloyEditor.BRIDGE_BUTTONS[pluginName] = AlloyEditor.BRIDGE_BUTTONS[pluginName].push(richComboName);

    Then, you should simply need something like:

    AlloyEditor.getButtonFor = function(pluginName) {
        return AlloyEditor.BRIDGE_BUTTONS[pluginName] || [];
    }

    Now, of course throwing an error to get the plugin name sounds like a very bad idea, so it'd be better to be able to do it in a nicer way :)

  9. removed this from the milestone on Apr 4, 2017
  10. added a commit that references this issue on Apr 5, 2017
    173906a
  11. added this to the milestone on Apr 6, 2017
  12. jbalsas commented on Apr 6, 2017

    @jbalsas
    ContributorAuthor

    I've re-added this to the now 1.4.0 milestone. Based on #718 I'm confident we can land this soon....

  13. added a commit that references this issue on Apr 6, 2017
    86a6e64
  14. 7 remaining items

  15. added 2 commits that reference this issue on Apr 6, 2017
    46f4d2b
    ad79600
  16. added 11 commits that reference this issue on Apr 6, 2017
    0d7058b
    f5a7272
    db5b803
    d923ef0
    9609833
    2504006
    b83f791
    1fdb9b6
    a8fd02e
    357eb01
    cec5660
  17. added a commit that references this issue on Aug 2, 2025
    728d091
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions