如何在 React JS 中配置 Ckeditor 工具栏?

pan*_*ang 1 javascript textarea ckeditor reactjs

我想在React中配置Ckeditor工具栏,但不知道文档中的属性详细信息在哪里。Ckeditor React 集成文档没有帮助,因为它不包含太多信息。

我试过这个:

import CKEditor from "ckeditor4-react"

<CKEditor
          data={this.state.data}
          onChange={this.onEditorChange}
          config={{
            toolbar: [
              ["Bold", "Italic", "Strike Through"],
              [
                "Cut",
                "Copy",
                "Paste",
                "Pasteasplaintext",
                "FormattingStyles",
                "Undo",
                "Redo"
              ],
              ["List", "Indent", "Blocks", "Align", "Bidi", "Paragraph"],
              ["Find", "Selection", "Spellchecker", "Editing"]
            ]
          }}
        />
Run Code Online (Sandbox Code Playgroud)

但是其中一些配置没有出现,因为我在猜测属性。我知道文档中有工具栏配置生成器,但我不知道把它放在 React 的哪里:

CKEDITOR.editorConfig = function( config ) {
    config.toolbarGroups = [
        { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
        { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
        { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
        { name: 'forms', groups: [ 'forms' ] },
        '/',
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
        { name: 'links', groups: [ 'links' ] },
        { name: 'insert', groups: [ 'insert' ] },
        '/',
        { name: 'styles', groups: [ 'styles' ] },
        { name: 'colors', groups: [ 'colors' ] },
        { name: 'tools', groups: [ 'tools' ] },
        { name: 'others', groups: [ 'others' ] },
        { name: 'about', groups: [ 'about' ] }
    ];

    config.removeButtons = 'Source,Save,Templates,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,CopyFormatting,RemoveFormat,CreateDiv,BidiLtr,BidiRtl,Image,Flash,Table,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,About';
};
Run Code Online (Sandbox Code Playgroud)

小智 15

我像这样使用它:

import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

   <CKEditor
        data={input.value}
        editor={ ClassicEditor }
        config={{         
          toolbar: ['heading', '|', 'bold', 'italic', 'blockQuote', 'link', 'numberedList', 'bulletedList', 'imageUpload', 'insertTable',
            'tableColumn', 'tableRow', 'mergeTableCells', 'mediaEmbed', '|', 'undo', 'redo']
        }}     
      />
Run Code Online (Sandbox Code Playgroud)

工具栏选项的完整列表在那里:

*["undo", "redo", "bold", "italic", "blockQuote", "ckfinder", "imageTextAlternative", "imageUpload", "heading", "imageStyle:full", "imageStyle:side", "link", "numberedList", "bulletedList", "mediaEmbed", "insertTable", "tableColumn", "tableRow", "mergeTableCells"]*
Run Code Online (Sandbox Code Playgroud)

  • 你知道如何添加codeBlock插件吗?当我将 `plugins: [codeBlock]` 和 `toolbar: ['codeBlock']` 添加到我的 `config` 项目中时,我收到 `some CKEditor 5 module is dupliced.` 错误。我将插件导入为“import CodeBlock from ''@ckeditor/ckeditor5-code-block/src/codeblock';” (3认同)