ckeditor 5在读取模式下未禁用自定义插件

发布于 2025-01-31 12:43:43 字数 2040 浏览 3 评论 0原文

现在,我将自定义插件集成到CKEditor 5中。我使用CKEditor 5 文档。 我也有一个自定义的“超级”构建(类似于此示例)。

现在,我的问题是,我的插件将不会在CKEditor读取模式下被禁用(如在按钮处的图像中所示)。 ckeditor documentation 提到这应该是“应该是”默认的“插件 /按钮的行为”。

如果有人知道我出了什么问题,那将是非常感谢的!

这是我自定义插件类的骨架示例。

import { Plugin } from 'ckeditor5/src/core';
import { ButtonView } from 'ckeditor5/src/ui';

import ckeditor5Icon from './icons/insertvariable.svg';

export default class HWInsertVariable extends Plugin {
    static get pluginName() {
        return 'HWInsertVariable';
    }

    init() {
        const that = this;
        const editor = this.editor;
        const model = editor.model;

        let labelTxt = 'Variable einfügen';

        editor.ui.componentFactory.add( 'hwInsertVariableButton', locale => {
            const view = new ButtonView( locale );

            view.set( {
                label: labelTxt,
                icon: ckeditor5Icon,
                tooltip: true,
                affectsData: true
            } );

            this.listenTo( view, 'execute', () => {
                model.change( writer => {
                    that.buttonClicked();
                } );

                editor.editing.view.focus();
            } );

            return view;
        } );
    }

    buttonClicked() {
        //code
    }
}

Right now I'm integrating custom plugins into the ckeditor 5. I created and added plugins using the ckeditor 5 documentation.
I also have a custom "super" build (similar to this example) that I use in my web application.

Now my problem is that my plugins will not be disabled in the ckeditor read mode (as showcased in the image at the button). The ckeditor documentation mentions that this should be the "default" behaviour for plugins / buttons.

If someone has an idea where I'm going wrong that'd be greatly appreciated!

Here is a skeleton example of my custom plugin class.

import { Plugin } from 'ckeditor5/src/core';
import { ButtonView } from 'ckeditor5/src/ui';

import ckeditor5Icon from './icons/insertvariable.svg';

export default class HWInsertVariable extends Plugin {
    static get pluginName() {
        return 'HWInsertVariable';
    }

    init() {
        const that = this;
        const editor = this.editor;
        const model = editor.model;

        let labelTxt = 'Variable einfügen';

        editor.ui.componentFactory.add( 'hwInsertVariableButton', locale => {
            const view = new ButtonView( locale );

            view.set( {
                label: labelTxt,
                icon: ckeditor5Icon,
                tooltip: true,
                affectsData: true
            } );

            this.listenTo( view, 'execute', () => {
                model.change( writer => {
                    that.buttonClicked();
                } );

                editor.editing.view.focus();
            } );

            return view;
        } );
    }

    buttonClicked() {
        //code
    }
}

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2025-02-07 12:43:43

我不确定解决此问题的正确方法是什么,因为我也面临着同样的方法。但是到目前为止,我发现的是,可能会有一种解决这个问题的方法。

查看有关“ 禁用命令”,读取“模式”的文档,并注意CSS类” ck-disabled

如果/我找到了一种工作方式,我将尝试回到这里并发布更好的解决方案


更新:
当我发现我在my_plugin_ui.js中缺少代码部分时,我为我解决了这个问题。

  const command = editor.commands.get('nameOfCommand');

  // Execute the command when the button is clicked (executed).
  buttonView.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');

Im not sure what the correct method to resolve this is, as I also am facing the same. But what I have found so far, is that there might be a hacky way to get around this.

Checkout the docs regarding "disabling commands", "read-only" mode, and notice the CSS class "ck-disabled"

if/when I find a working way, I will try to come back here and post a better solution


Update:
I fixed this for me when I found that I was missing the section of the code in my my_plugin_ui.js where

  const command = editor.commands.get('nameOfCommand');

  // Execute the command when the button is clicked (executed).
  buttonView.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文