CKEditor5 Online Builder无法渲染 – React版本

huangapple go评论80阅读模式
英文:

CKEditor5 Online Builder Failed to Render - React Version

问题

我试图在我的React 18应用程序中使用CKEditor5的在线构建器来渲染编辑器,但在我放入我的代码后,编辑器没有渲染,并且在控制台中我看到了以下错误。

ckeditor.tsx:156 TypeError: Cannot read properties of undefined (reading 'create')
    at to._createEditor (ckeditor.tsx:169:1)
    at Vr._creator (ckeditor.tsx:133:1)
    at editorwatchdog.js:115:1
    at async to._initializeEditor (ckeditor.tsx:151:1)
    at async to.componentDidMount (ckeditor.tsx:102:1)

我遵循了将下载的CKEditor5文件夹放在项目的根目录中的说明。以下是将编辑器集成到React组件中的我的代码:

import { CKEditor } from '@ckeditor/ckeditor5-react';
import { Editor } from 'ckeditor5-custom-build/build/ckeditor';

const DashboardPage = () => {
  return (
    <>
      <div className='card'>
        <div className='card-body'>

          {/* 开始::编辑器 */}
          <div className='mx-auto'>
            <CKEditor
              editor={Editor}
              data="<p>Hello from CKEditor 5!</p>"
              onReady={editor => {
                // 您可以存储“editor”并在需要时使用它。
                console.log('Editor is ready to use!', editor);
              }}
              onChange={(event, editor) => {
                // const data = editor.getData();
                // console.log({ event, editor, data });
              }}
              onBlur={(event, editor) => {
                console.log('Blur.', editor);
              }}
              onFocus={(event, editor) => {
                console.log('Focus.', editor);
              }}
            />
            {/* 结束::编辑器 */}
          </div>
        </div>
      </div>
    </>
  )
}

这些是使用的CKEditor5版本:

"@ckeditor/ckeditor5-build-balloon": "^38.0.1",
"@ckeditor/ckeditor5-react": "^6.0.0",
"ckeditor5-custom-build": "file:./ckeditor5",

问题在于,我尝试了预构建的classicballoon版本的CKEditor5,它们都在页面上很好地渲染。我做错了什么?

英文:

I was trying to use the CKEditor5's online builder to render the editor in my React 18 app but after I put my code in, the editor did not render and in the console, I saw the following error.

ckeditor.tsx:156  TypeError: Cannot read properties of undefined (reading &#39;create&#39;)
    at to._createEditor (ckeditor.tsx:169:1)
    at Vr._creator (ckeditor.tsx:133:1)
    at editorwatchdog.js:115:1
    at async to._initializeEditor (ckeditor.tsx:151:1)
    at async to.componentDidMount (ckeditor.tsx:102:1) 

I followed the instruction to put the downloaded CKEditor5 folder in the root directory of my project. The following is my code to integrate the editor into the React component,

import { CKEditor } from &#39;@ckeditor/ckeditor5-react&#39;
import { Editor } from &#39;ckeditor5-custom-build/build/ckeditor&#39;;


const DashboardPage = () =&gt; {
  return (
    &lt;&gt;
      &lt;div className=&#39;card&#39;&gt;
        &lt;div className=&#39;card-body&#39;&gt;

          {/* begin::Editor */}
          &lt;div className=&#39;mx-auto&#39;&gt;
            &lt;CKEditor
              editor={Editor}
              data=&quot;&lt;p&gt;Hello from CKEditor 5!&lt;/p&gt;&quot;
              onReady={editor =&gt; {
                // You can store the &quot;editor&quot; and use when it is needed.
                console.log(&#39;Editor is ready to use!&#39;, editor);
              }}
              onChange={(event, editor) =&gt; {
                // const data = editor.getData();
                // console.log({ event, editor, data });
              }}
              onBlur={(event, editor) =&gt; {
                console.log(&#39;Blur.&#39;, editor);
              }}
              onFocus={(event, editor) =&gt; {
                console.log(&#39;Focus.&#39;, editor);
              }
              }
            /&gt;
            {/* end::Editor */}
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/&gt;
  )
}

These are the versions of the CKEditor5 used,

&quot;@ckeditor/ckeditor5-build-balloon&quot;: &quot;^38.0.1&quot;,
&quot;@ckeditor/ckeditor5-react&quot;: &quot;^6.0.0&quot;,
&quot;ckeditor5-custom-build&quot;: &quot;file:./ckeditor5&quot;,

The thing is that I tried the prebuilt classic, balloon versions of CKEditor5 they all render nicely in the page. What did I do wrong?

答案1

得分: 1

我尝试研究了这个CKEditor 5在线构建器。正如他们在文档中提到的:

如果你想使用CKEditor 5在线构建器,请确保未选择看门狗功能。React集成已经将看门狗功能集成到核心中。

你可以尝试下面的代码片段:

<CKEditor
	editor={Editor}
    data="&lt;p&gt;来自CKEditor 5的问候!&lt;/p&gt;"
	watchdogConfig={ { crashNumberLimit: 10 } } //尝试添加这个`watchdogConfig`功能
...
/>

更多参考,请查看示例示例

希望这有所帮助!

英文:

I tried to research this CKEditor 5 online builder. As they mentioned in their docs:

> If you want to use the CKEditor 5 online builder, make sure that the watchdog feature is not selected. The React integration comes with the watchdog feature already integrated into the core.

You could try the below snippet:

&lt;CKEditor
		editor={Editor}
        data=&quot;&lt;p&gt;Hello from CKEditor 5!&lt;/p&gt;&quot;
		watchdogConfig={ { crashNumberLimit: 10 } } //try to add this `watchdogConfig` feature
...
/&gt;

For more reference, this is a sample example.

Hope this helps!

答案2

得分: 0

无论如何,我意识到了导致问题的真正原因 - 我yarn安装了多个预构建的编辑器,例如BalloonEditorClassicEditor,还有我的在线构建的编辑器,以某种方式它们不能共存,因此导致了错误。

将这个信息分享给其他人参考 CKEditor5 Online Builder无法渲染 – React版本

英文:

Anyway I realised the real issue causing the problem - I yarn installed multiple prebuilt editors e.g., BalloonEditor and ClassicEditor along with my online built editor and somehow they cannot exist together hence causing the error.

Putting this out there for others' reference CKEditor5 Online Builder无法渲染 – React版本

huangapple
  • 本文由 发表于 2023年6月22日 11:21:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528410.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定