我们正在尝试将 CKEditor 5 实施到我们的应用程序中,并且我们在处理文档方面遇到了一些困难。

我们想禁用拖放到编辑区域的事件或以某种方式控制它。有这样的活动吗?

我们正在尝试editor.model.document.on('clipboardInput')editor.model.document.on('dragover')没有任何运气。这些事件不会被触发。


您需要在视图层而不是模型上监听 和dragover事件drop

我准备了一个简单的函数,可以作为插件加载到 CKEditor 5 中,从而取消这些事件:

/**
 * Cancel the `drop` and `dragover` events.
 *
 * @param {module:core/editor/editor~Editor} editor
 */
function cancelDropEvents( editor ) {
    // High priority means that the callbacks below will be called before other CKEditor's plugins.

    editor.editing.view.document.on( 'drop', ( evt, data ) => {
        // Stop executing next callbacks.
        evt.stop();

        // Prevent the default event action.
        data.preventDefault();
    }, { priority: 'high' } );

    editor.editing.view.document.on( 'dragover', ( evt, data ) => {
        evt.stop();
        data.preventDefault();
    }, { priority: 'high' } );
}

你可以在线查看它是如何工作的——https ://jsfiddle.net/pomek/qz0o9ku0/