umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.36k stars 2.64k forks source link

[BUG]: Include types for TinyMCE #16678

Open enkelmedia opened 3 months ago

enkelmedia commented 3 months ago

When building a tinyMcePlugin the editor complains about the return type:

image

So I figured I'll provide strongly typed objects but it seems like the types are not included in the @umbraco-cms/backoffice package?

image

Is this by intension and what would be the right workaround?

enkelmedia commented 3 months ago

Hmm,

Looks like TinyMCE is using this internally as some kind of "bridge" https://www.npmjs.com/package/@ephox/bridge

After

npm i -D @ephox/bridge

I can do:

import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
import { TinyMcePluginArguments, UmbTinyMcePluginBase } from '@umbraco-cms/backoffice/tiny-mce';
import { MYMCE_TOOLBARITEM_ALIAS } from './manifest';
import type { NestedMenuItemContents } from '@ephox/bridge/lib/main/ts/ephox/bridge/api/Menu';

export default class MyMceEditorPlugin extends UmbTinyMcePluginBase {
    constructor(args: TinyMcePluginArguments) {
        super(args);

        const localize = new UmbLocalizationController(args.host);

        this.editor.ui.registry.addMenuButton(MYMCE_TOOLBARITEM_ALIAS, {
            text: 'Fields',

            fetch: (callback) => {

                let arrMenuItems :NestedMenuItemContents[] = [
                    {
                        type: 'nestedmenuitem',
                        text: localize.term('buttons_somethingElse'),
                        getSubmenuItems: ()=> [
                            {
                                type : 'menuitem',
                                text: 'Nested Option 1',
                                onAction: () => {
                                    this.editor.insertContent('Testing');
                                }
                            }
                        ]
                    }
                ];

                callback(arrMenuItems);
            }

        });
    }
}

I guess that it's not needed to include all of this in the cms-package, but maybe provide a note in the documentation.

Feel free to close this issue or keep it for reference until docs are updated.

github-actions[bot] commented 5 days ago

Hi there @enkelmedia!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face: