Class VaadinCKEditor
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<String>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<String>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<String>>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>, Serializable
@Tag("vaadin-ckeditor")
@JsModule("./vaadin-ckeditor/vaadin-ckeditor.ts")
@NpmPackage(value="ckeditor5",version="47.4.0") @NpmPackage(value="lit",version="^3.3.2")
public class VaadinCKEditor
extends com.vaadin.flow.component.customfield.CustomField<String>
implements com.vaadin.flow.component.HasAriaLabel
Vaadin CKEditor 5 component.
Modular CKEditor 5 integration with plugin-based customization.
Usage examples:
// Use preset
VaadinCKEditor editor = VaadinCKEditor.create()
.withPreset(CKEditorPreset.STANDARD)
.build();
// Custom plugins (dependencies auto-resolved)
VaadinCKEditor editor = VaadinCKEditor.create()
.withPlugins(CKEditorPlugin.BOLD, CKEditorPlugin.ITALIC, CKEditorPlugin.IMAGE_CAPTION)
.withToolbar("bold", "italic", "|", "insertImage")
.build();
// IMAGE_CAPTION automatically includes IMAGE plugin as dependency
// Customize preset
VaadinCKEditor editor = VaadinCKEditor.create()
.withPreset(CKEditorPreset.BASIC)
.addPlugin(CKEditorPlugin.TABLE)
.withLanguage("zh-cn")
.build();
Dependency Resolution:
The builder automatically resolves plugin dependencies by default. For example, adding IMAGE_CAPTION will automatically include the IMAGE plugin.
// Auto-resolve with recommended plugins for full feature set
VaadinCKEditor editor = VaadinCKEditor.create()
.withPlugins(CKEditorPlugin.IMAGE)
.withDependencyMode(DependencyMode.AUTO_RESOLVE_WITH_RECOMMENDED)
.build();
// Includes IMAGE plus recommended: IMAGE_TOOLBAR, IMAGE_CAPTION, IMAGE_STYLE, IMAGE_RESIZE
// Strict mode - fail if dependencies missing
VaadinCKEditor editor = VaadinCKEditor.create()
.withPlugins(CKEditorPlugin.IMAGE_CAPTION) // Missing IMAGE dependency
.withDependencyMode(DependencyMode.STRICT)
.build(); // Throws IllegalStateException
// Manual mode - no dependency checking
VaadinCKEditor editor = VaadinCKEditor.create()
.withPlugins(CKEditorPlugin.ESSENTIALS, CKEditorPlugin.PARAGRAPH, CKEditorPlugin.BOLD)
.withDependencyMode(DependencyMode.MANUAL)
.build();
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E> -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddAutosaveListener(com.vaadin.flow.component.ComponentEventListener<AutosaveEvent> listener) Add autosave event listener.com.vaadin.flow.shared.RegistrationaddContentChangeListener(com.vaadin.flow.component.ComponentEventListener<ContentChangeEvent> listener) Add content change event listener.com.vaadin.flow.shared.RegistrationaddEditorErrorListener(com.vaadin.flow.component.ComponentEventListener<EditorErrorEvent> listener) Add editor error event listener.com.vaadin.flow.shared.RegistrationaddEditorReadyListener(com.vaadin.flow.component.ComponentEventListener<EditorReadyEvent> listener) Add editor ready event listener.com.vaadin.flow.shared.RegistrationaddFallbackListener(com.vaadin.flow.component.ComponentEventListener<FallbackEvent> listener) Add fallback event listener.booleancancelUpload(String uploadId) Cancel the specified upload task.voidClean up all event listeners.voidclear()Clear editor contentstatic VaadinCKEditorBuildercreate()Create editor builder.protected StringintGet the number of active uploads.intGet character count of content (excluding HTML tags).Get error handler.Get fallback mode.Get HTML sanitizer.getId()Get statistics of registered listeners.Get plain text content (strip HTML tags)Get sanitized HTML (remove dangerous tags)Get sanitized content.Get upload handler.getValue()static StringGet versionintGet word count of content.booleanCheck if there are uploads in progress.voidinsertText(String text) Insert text at cursor positionbooleanCheck if content is empty.booleansanitizeHtml(String html, org.jsoup.safety.Safelist safelist) Sanitize HTML with specified rulesvoidsetAutosaveCallback(Consumer<String> callback) Set autosave callbackvoidsetErrorHandler(ErrorHandler handler) Set error handler.voidSet fallback mode.voidsetGeneralHtmlSupportEnabled(boolean enabled) Enable general HTML supportvoidvoidsetHideToolbar(boolean hide) Set toolbar visibilityvoidsetHtmlSanitizer(HtmlSanitizer sanitizer) Set HTML sanitizer.voidSet editor ID.voidsetMinimapEnabled(boolean enabled) Enable minimap (DECOUPLED type only)protected voidsetModelValue(String value, boolean fromClient) voidsetOverrideCssUrl(String url) Set custom CSS URLprotected voidsetPresentationValue(String value) voidsetReadOnly(boolean readOnly) voidsetReadOnlyWithToolbarAction(boolean readOnly) Enable read-only mode and hide toolbarvoidsetSynchronized(boolean sync) Set synchronous update modevoidsetUploadHandler(UploadHandler handler) Set upload handler.voidvoidstatic VaadinCKEditorwithPreset(CKEditorPreset preset) Quick create editor with presetMethods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, remove, removeThemeVariants, setLabel, updateValueMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, isEmpty, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setVisibleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidationMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, getEmptyValue, getOptionalValue, isEmptyMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isRequiredIndicatorVisible, setRequiredIndicatorVisible
-
Method Details
-
create
-
withPreset
Quick create editor with preset -
generateModelValue
-
setPresentationValue
-
getValue
- Specified by:
getValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>- Overrides:
getValuein classcom.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<String>, String>
-
getSanitizedValue
Get sanitized content. If HtmlSanitizer is set, applies sanitization; otherwise returns original content.- Returns:
- sanitized HTML content
-
setValue
- Specified by:
setValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>- Overrides:
setValuein classcom.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<String>, String>
-
setModelValue
-
setId
Set editor ID. Note: This sets both the Vaadin component ID and the internal editorId property. The editorId is used for frontend component identification.- Overrides:
setIdin classcom.vaadin.flow.component.Component- Parameters:
id- the ID to set, or null to generate a random ID
-
getId
-
setReadOnly
public void setReadOnly(boolean readOnly) - Specified by:
setReadOnlyin interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>- Specified by:
setReadOnlyin interfacecom.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnlyin interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>- Specified by:
isReadOnlyin interfacecom.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>, String>, String>
-
setWidth
- Specified by:
setWidthin interfacecom.vaadin.flow.component.HasSize
-
setHeight
- Specified by:
setHeightin interfacecom.vaadin.flow.component.HasSize
-
setHideToolbar
public void setHideToolbar(boolean hide) Set toolbar visibility -
setReadOnlyWithToolbarAction
public void setReadOnlyWithToolbarAction(boolean readOnly) Enable read-only mode and hide toolbar -
setMinimapEnabled
public void setMinimapEnabled(boolean enabled) Enable minimap (DECOUPLED type only) -
setGeneralHtmlSupportEnabled
public void setGeneralHtmlSupportEnabled(boolean enabled) Enable general HTML support -
setSynchronized
public void setSynchronized(boolean sync) Set synchronous update mode -
setOverrideCssUrl
Set custom CSS URL -
setAutosaveCallback
-
clear
-
insertText
Insert text at cursor position -
getPlainText
Get plain text content (strip HTML tags) -
getSanitizedHtml
Get sanitized HTML (remove dangerous tags) -
sanitizeHtml
-
getCharacterCount
public int getCharacterCount()Get character count of content (excluding HTML tags).- Returns:
- character count
-
getWordCount
public int getWordCount()Get word count of content.- Returns:
- word count
-
isContentEmpty
public boolean isContentEmpty()Check if content is empty.- Returns:
- true if content is empty or contains only whitespace
-
getVersion
Get version -
addEditorReadyListener
public com.vaadin.flow.shared.Registration addEditorReadyListener(com.vaadin.flow.component.ComponentEventListener<EditorReadyEvent> listener) Add editor ready event listener. Fired when the editor is fully initialized and ready to accept user input.Usage example:
editor.addEditorReadyListener(event -> { logger.info("Editor ready in {} ms", event.getInitializationTimeMs()); event.getSource().focus(); });- Parameters:
listener- the event listener- Returns:
- registration object for removing the listener
-
addEditorErrorListener
public com.vaadin.flow.shared.Registration addEditorErrorListener(com.vaadin.flow.component.ComponentEventListener<EditorErrorEvent> listener) Add editor error event listener. Fired when the editor encounters an error.Usage example:
editor.addEditorErrorListener(event -> { EditorError error = event.getError(); if (error.getSeverity() == ErrorSeverity.FATAL) { Notification.show("Editor error: " + error.getMessage(), Notification.Type.ERROR_MESSAGE); } });- Parameters:
listener- the event listener- Returns:
- registration object for removing the listener
-
addAutosaveListener
public com.vaadin.flow.shared.Registration addAutosaveListener(com.vaadin.flow.component.ComponentEventListener<AutosaveEvent> listener) Add autosave event listener. Fired when editor content is auto-saved.- Parameters:
listener- the event listener- Returns:
- registration object for removing the listener
-
addContentChangeListener
public com.vaadin.flow.shared.Registration addContentChangeListener(com.vaadin.flow.component.ComponentEventListener<ContentChangeEvent> listener) Add content change event listener. Fired when editor content changes.- Parameters:
listener- the event listener- Returns:
- registration object for removing the listener
-
addFallbackListener
public com.vaadin.flow.shared.Registration addFallbackListener(com.vaadin.flow.component.ComponentEventListener<FallbackEvent> listener) Add fallback event listener. Fired when the editor triggers fallback mode due to an error.- Parameters:
listener- the event listener- Returns:
- registration object for removing the listener
-
setErrorHandler
Set error handler.- Parameters:
handler- the error handler
-
getErrorHandler
-
setHtmlSanitizer
Set HTML sanitizer.- Parameters:
sanitizer- the HTML sanitizer
-
getHtmlSanitizer
Get HTML sanitizer.- Returns:
- the HTML sanitizer, may be null
-
setUploadHandler
Set upload handler.- Parameters:
handler- the upload handler
-
getUploadHandler
Get upload handler.- Returns:
- the upload handler, may be null
-
setFallbackMode
Set fallback mode.- Parameters:
mode- the fallback mode
-
getFallbackMode
Get fallback mode.- Returns:
- the current fallback mode
-
getListenerStats
Get statistics of registered listeners. Used for debugging and monitoring.- Returns:
- listener statistics
-
cleanupListeners
public void cleanupListeners()Clean up all event listeners. Usually called before component destruction. -
hasActiveUploads
public boolean hasActiveUploads()Check if there are uploads in progress.- Returns:
- true if there are active uploads
-
getActiveUploadCount
public int getActiveUploadCount()Get the number of active uploads.- Returns:
- active upload count
-
cancelUpload
Cancel the specified upload task.- Parameters:
uploadId- the upload ID- Returns:
- true if successfully cancelled
-