What is @ckeditor/ckeditor5-widget?
@ckeditor/ckeditor5-widget is a package that provides the base functionality for creating and managing widgets in CKEditor 5. Widgets are special types of content that can be edited and manipulated as a single unit, such as images, tables, or custom blocks.
What are @ckeditor/ckeditor5-widget's main functionalities?
Creating a Simple Widget
This code demonstrates how to create a simple widget in CKEditor 5. It registers a new model element 'simpleWidget' and sets up the necessary conversions for upcasting, data downcasting, and editing downcasting.
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
class SimpleWidget extends Plugin {
init() {
const editor = this.editor;
editor.model.schema.register('simpleWidget', {
isObject: true,
allowWhere: '$block'
});
editor.conversion.for('upcast').elementToElement({
model: 'simpleWidget',
view: 'div'
});
editor.conversion.for('dataDowncast').elementToElement({
model: 'simpleWidget',
view: 'div'
});
editor.conversion.for('editingDowncast').elementToElement({
model: 'simpleWidget',
view: (modelElement, viewWriter) => {
const div = viewWriter.createContainerElement('div');
return toWidget(div, viewWriter);
}
});
}
}
export default SimpleWidget;
Custom Widget with Editable Content
This code demonstrates how to create a custom widget with editable content. It registers a new model element 'customWidget' and sets up the necessary conversions. The widget contains an inner editable element, allowing users to edit its content directly.
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { toWidget, toWidgetEditable } from '@ckeditor/ckeditor5-widget/src/utils';
class CustomWidget extends Plugin {
init() {
const editor = this.editor;
editor.model.schema.register('customWidget', {
isObject: true,
allowWhere: '$block',
allowContentOf: '$root'
});
editor.conversion.for('upcast').elementToElement({
model: 'customWidget',
view: 'div'
});
editor.conversion.for('dataDowncast').elementToElement({
model: 'customWidget',
view: 'div'
});
editor.conversion.for('editingDowncast').elementToElement({
model: 'customWidget',
view: (modelElement, viewWriter) => {
const div = viewWriter.createContainerElement('div');
const innerEditable = viewWriter.createEditableElement('div');
viewWriter.insert(viewWriter.createPositionAt(div, 0), innerEditable);
return toWidget(div, viewWriter, { label: 'custom widget' });
}
});
}
}
export default CustomWidget;
Other packages similar to @ckeditor/ckeditor5-widget
quill
Quill is a modern WYSIWYG editor built for compatibility and extensibility. It provides a rich API for creating custom content and widgets, similar to CKEditor 5's widget system. However, Quill's approach to customization and its API differ significantly from CKEditor 5.
draft-js
Draft.js is a JavaScript rich text editor framework, built for React. It allows developers to create complex editors with custom content blocks and widgets. While it offers similar functionality to CKEditor 5 widgets, it is tightly integrated with React and has a different architecture.
prosemirror
ProseMirror is a toolkit for building rich text editors with a focus on extensibility and customizability. It provides a robust API for creating custom content and widgets, similar to CKEditor 5. ProseMirror's approach is more low-level, offering greater control but requiring more effort to implement complex features.
43.3.0 (October 29, 2024)
We are happy to announce the release of CKEditor 5 v43.3.0.
Release highlights
Performance improvements
We have improved how the editor handles the document structure by making it more reliable and efficient to access specific elements and verify their positions.
- Node index and offset caching: The
Node
and NodeList
elements now cache index and offset values, reducing the need for recalculations and significantly boosting overall performance during model operations. - Selection range validation: The newly implemented
Position#isValid()
method is also utilized to better validate selection ranges, ensuring more consistent behavior in various editing scenarios. - Performance improvements in numbers: The editor now loads content between 3x and, in some cases, up to 6x faster, depending on the type and size of the content. For instance, where a specific 200-page document previously took almost 25 seconds to load, the time has now been reduced to just 3.5 seconds.
We’re committed to ongoing performance enhancements, so you can expect even faster, smoother experience in future updates.
Export to Word watermark support
A new configuration option has been added to include a watermark when exporting documents to Word, providing additional flexibility in document branding and protection.
Notable bug fixes and improvements
- Suggestions retention on revision restore: Suggestions are no longer lost in specific cases when restoring revisions with changes from multiple users. The revision tracking process has been improved to ensure that all operations, including markers, are handled and saved correctly during synchronization. This fix resolves issues where markers were previously not retained, ensuring consistent data handling in collaborative editing scenarios.
- Action dropdown visibility fix: Resolved an issue where the action dropdown remained hidden after permission changes on comments. The dropdown now properly reflects updated permissions, allowing users to interact with the available actions seamlessly.
- AI command enhancements:
- Custom AI Commands are now correctly applied to individual dropdowns when only one group of comments is present, instead of the entire group.
- Empty comment groups no longer render, improving UI clarity.
- Fixed an issue where nested AI command menus would close unexpectedly when used within a balloon toolbar, preventing unintended behavior during selection.
Features
- engine: Introduced the
getChildAtOffset()
method for model.Element
and model.DocumentFragment
. (commit) - engine: Introduced the
Position#isValid()
method to check whether the position exists in the current model tree. (commit) - export-word: Added a configuration setting for adding a watermark to generated documents.
- revision-history: Introduced the
RevisionTracker#getRevisionDocumentData()
and RevisionTracker#getRevisionRootsAttributes()
methods to the public scope of the editor API. You can use them to retrieve document data saved with the revision. - utils: Made
FocusTracker
extendable with other FocusTracker
instances to allow logical focus tracking across separate DOM sub-trees (see #17277). (commit)
Bug fixes
- ai: Empty AI Assistant command groups should not render in the UI.
- ai: The AI Assistant command list should be flat when only one command group is available.
- comments: Fixed an issue where the action dropdown remained hidden when permissions allowing actions on a comment changed.
- engine: The content of an inline object should be handled as a flow root so whitespaces should be trimmed as the content of an inline object element is inside a block element. Closes #17199. (commit)
- image: Handle existing picture element correctly on
sources
downcast. (commit) - link: No longer crash editor after removing link from image when
LinkConfig#addTargetToExternalLinks: true
is set. Closes https://github.com/ckeditor/ckeditor5/issues/17252. (commit) - list-multi-level: Multi-level lists should display correctly in RTL mode for Decoupled Editor.
- pagination: Improved pagination of large tables that are followed by block elements.
- revision-history: Suggestions are no longer lost in some scenarios when restoring revisions in real-time collaboration.
- ui: The dropdown menu component should not cause editor blur if used in a
BalloonToolbar
while the user hovers a nested menu. Closes #17277. (commit) - ui: Made the page unscrollable while the modal is visible. Closes #17093. (commit)
Other changes
- engine: Node index and offset related values are now cached in model
Node
and NodeList
to improve performance. (commit) - link: Exported link and unlink icons from the
ckeditor5-link
package. Closes #17304. (commit) - ui: Disabled dragging support for modal windows in the
Dialog
plugin. Closes #17290. (commit) - ui: Disabled positioning restrictions for modal windows caused by
config.ui.viewportOffset
. Closes #17290. (commit)
Released packages
Check out the Versioning policy guide for more information.
<details>
<summary>Released packages (summary)</summary>
Releases containing new features:
Other releases:
</details>