What is @ckeditor/ckeditor5-react?
@ckeditor/ckeditor5-react is a React component that integrates CKEditor 5, a modern JavaScript rich text editor, into React applications. It provides a rich set of features for creating and editing content, including text formatting, image and media embedding, and collaborative editing.
What are @ckeditor/ckeditor5-react's main functionalities?
Basic Usage
This code demonstrates the basic usage of the @ckeditor/ckeditor5-react package. It imports the CKEditor component and the ClassicEditor build, then renders the editor with some initial data and event handlers for ready, change, blur, and focus events.
import React from 'react';
import { CKEditor } from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
function App() {
return (
<div className="App">
<h2>Using CKEditor 5 with React</h2>
<CKEditor
editor={ ClassicEditor }
data="<p>Hello from CKEditor 5!</p>"
onReady={ 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>
);
}
export default App;
Custom Configuration
This code demonstrates how to use a custom configuration with the CKEditor component. The editorConfiguration object specifies a custom toolbar and heading options, which are then passed to the CKEditor component via the config prop.
import React from 'react';
import { CKEditor } from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
function App() {
const editorConfiguration = {
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
{ model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' }
]
}
};
return (
<div className="App">
<h2>Using CKEditor 5 with Custom Configuration</h2>
<CKEditor
editor={ ClassicEditor }
config={ editorConfiguration }
data="<p>Custom configuration example.</p>"
/>
</div>
);
}
export default App;
Using Plugins
This code demonstrates how to use plugins with the CKEditor component. The Alignment plugin is imported and added to the ClassicEditor build. The editorConfiguration object includes the alignment options, which are then passed to the CKEditor component via the config prop.
import React from 'react';
import { CKEditor } from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
ClassicEditor.builtinPlugins.push( Alignment );
function App() {
const editorConfiguration = {
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'alignment', 'bulletedList', 'numberedList', 'blockQuote' ],
alignment: {
options: [ 'left', 'center', 'right', 'justify' ]
}
};
return (
<div className="App">
<h2>Using CKEditor 5 with Plugins</h2>
<CKEditor
editor={ ClassicEditor }
config={ editorConfiguration }
data="<p>Plugin example with text alignment.</p>"
/>
</div>
);
}
export default App;
Other packages similar to @ckeditor/ckeditor5-react
react-quill
React-Quill is a React component for Quill, a powerful rich text editor. It offers a similar set of features to CKEditor, including text formatting, image embedding, and custom themes. However, Quill's API and customization options differ from CKEditor, and it may have a different set of plugins and extensions.
draft-js
Draft.js is a JavaScript rich text editor framework developed by Facebook. It provides a set of tools for building rich text editors with React. Unlike CKEditor, Draft.js is more of a low-level framework, offering more control and customization options but requiring more effort to implement common features.
slate
Slate is a completely customizable framework for building rich text editors. It provides a set of tools and plugins for creating complex editors with React. Slate offers more flexibility and control compared to CKEditor, but it also requires more effort to set up and configure.
CKEditor 5 rich text editor component for React
Official CKEditor 5 rich text editor component for React.
See the "Rich text editor component for React" guide in the CKEditor 5 documentation to learn more:
Contributing
After cloning this repository, install necessary dependencies:
npm install
Executing tests
Before starting tests execution, you need to build the package. You can use npm run build
in order to build the production-ready version
or npm run develop
which produces a development version with attached watcher for all sources files.
npm run test -- [additional options]
npm t -- [additional options]
The command accepts the following options:
--coverage
(-c
) – Whether to generate the code coverage.--source-map
(-s
) – Whether to attach the source maps.--watch
(-w
) – Whether to watch test files.--reporter
(-r
) – Reporter for Karma (default: mocha
, can be changed to dots
).--browsers
(-b
) – Browsers that will be used to run tests (default: Chrome
, available: Firefox
, BrowserStack_Edge
and BrowserStack_Safari
).
Note: If you would like to use the BrowserStack_*
browser, you need to specify the BROWSER_STACK_USERNAME
and BROWSER_STACK_ACCESS_KEY
as
an environment variable, e.g.:
BROWSER_STACK_USERNAME=[...] BROWSER_STACK_ACCESS_KEY=[...] npm t -- -b BrowserStack_Edge,BrowserStack_Safari -c
Building the package
Build a minified version of the package that is ready to publish:
npm run build
Releasing package
Changelog
Before starting the release process, you need to generate the changelog:
npm run changelog
Publishing
After generating the changelog, you are able to release the package.
First, you need to bump the version:
npm run release:bump-version
You can also use the --dry-run
option in order to see what this task does.
After bumping the version, you can publish the changes:
npm run release:publish
As in the previous task, the --dry-run
option is also available.
Note: Only the dist/
directory will be published.
License
Licensed under the terms of GNU General Public License Version 2 or later. For full details about the license, please check the LICENSE.md file.