matteocontrini I just add a look, and we could definitely improve the extensibility there.
First the few things I noticed:
Multiple core extensions don't expose their objects via compat
, so this means third-party extensions have no way to extend their inner components. For the markdown extension it means MarkdownToolbar
can't be extended for example. I also checked the lock extension and noticed the same thing, no inner component can be extended.
The second extensibility issue here is that the markdown toolbar children aren't inserted via an ItemList, so extending is even more complicated.
To do it in beta 10, there are two options.
The first is completely replacing the toolbar, either by forking the extension, or removing then pushing a new toolbar from your own extension (or extend.php
). Basically running this code again but with changes.
The second option is to remove only what we don't want, and this can be achieved like this:
import {extend} from 'flarum/extend';
import TextEditor from 'flarum/components/TextEditor';
app.initializers.add('remove-image-markdown-toolbar', () => {
extend(TextEditor.prototype, 'toolbarItems', function(items) {
if (items.has('markdown')) {
const markdown = items.get('markdown');
const imageElementIndex = markdown.props.children.findIndex(child => child.props.icon === 'fas fa-image');
if (imageElementIndex !== -1) {
markdown.props.children.splice(imageElementIndex, 1);
}
}
});
}, -100); // A low priority to run after the markdown extension