[英]Adding Plugins to a Custom Build of CKEditor5 with ReactJS
我正在尝试将插件添加到 CKEditor5 的经典版本中。 我已按照此页面上的说明进行操作: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html
我可以说我已经正确完成了所有操作,因为当我打开sample/index.html
时,一切正常。
现在是时候将这个自定义构建与我的 react 应用程序集成了。
此页面上的说明,“描述”要做什么:
您将在项目旁边的某个位置创建一个新构建,并像包含现有构建之一一样包含它。
它说“包括它,就像你包含在现有版本之一中一样”。 好吧,这就是我包含经典版本的方式:
import React from "react";
import ReactDOM from "react-dom";
import CKEditor from "@ckeditor/ckeditor5-react";
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
import "./styles.css";
function App() {
return (
<div className="App">
<CKEditor
editor={ClassicEditor}
// Other Props
}}
/>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
所以,我会假设我会做这样的事情:
import React from "react";
import ReactDOM from "react-dom";
import CKEditor from "@ckeditor/ckeditor5-react";
import ClassicEditor from './ckeditor/ckeditor'
import "./styles.css";
function App() {
return (
<div className="App">
<CKEditor
editor={ClassicEditor}
// Other Props
/>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
也就是说,只需将import
语句更改为:
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
至
import ClassicEditor from './ckeditor/ckeditor'
使用./ckeditor/ckeditor/
是ckeditor.js
文件,该文件位于我的自定义构建的修改版本的build
文件夹中。
但是,这不起作用。 新的 ckeditor.js 文件中没有导出。 既不是默认导出也不是命名导出。 所以也许我应该像这样导入文件:
import './ckeditor/ckeditor'
但是我如何告诉 React 组件使用哪个编辑器。 有一个editor
prop,它采用要使用的编辑器的名称——即:
<CKEditor
editor={ClassicEditor}
// Other Props
/>
所以我被困住了。 我不知道如何将自定义构建包含到我的反应应用程序中。
有任何想法吗?
谢谢。
CKEditor 团队帮我解决了这个问题。 您可以在此处阅读解决方案: https://github.com/ckeditor/ckeditor5/issues/2072#issuecomment-534987536
The main point was that I needed to publish my customized build as an npm package, install that package on my site and then import the installed package.
一旦我这样做了,一切都很好。
忘记您对自定义 cke4 的了解,然后阅读此内容
自定义 CK5 编辑器的步骤
$ npm build
这不是直截了当的,关于它的文档充其量是不存在的。 我的痛苦是你的收获<3
额外的
在线构建工具让您下载 a.zip,我所做的是用 zip 形式的文件覆盖了我的分叉项目文件。 我构建、上传等。请注意,工具栏的配置位于 sample/index.html 中,如果您不添加它,那么您将看不到您的工具栏。
记住一定要添加工具栏配置!
** 编辑 **
如果你在一个团队中工作,你会想要 go 版本在顶部。
npm install
ckeditor.js
以包含来自sample/index.html
的配置(我将所有内容都放在了Editor.defaultConfig
中)npm build
import ClassicEditor from './online-build/build/ckeditor';
npm build
如果除了您没有工具栏外一切正常,那么您需要重新检查您的配置设置。
干杯!
** 编辑 **
我想添加似乎不太支持的“源代码编辑”插件。 我所做的是手动从ckeditor5 主 git中获取源代码编辑代码(所有插件都列在底部),然后将该代码粘贴到我的项目中并从该文件夹中导入。 这很漂亮,不适合团队但它有效 - 祝你好运
import SourceEditing from './ckeditor5-source-editing/src/sourceediting.js';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.