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 ClassesModifier and TypeClassDescriptionstatic classDeprecated.static classDeprecated.UseVaadinCKEditorBuilder.DependencyModeinstead.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) 添加自动保存事件监听器。com.vaadin.flow.shared.RegistrationaddContentChangeListener(com.vaadin.flow.component.ComponentEventListener<ContentChangeEvent> listener) 添加内容变更事件监听器。com.vaadin.flow.shared.RegistrationaddEditorErrorListener(com.vaadin.flow.component.ComponentEventListener<EditorErrorEvent> listener) 添加编辑器错误事件监听器。com.vaadin.flow.shared.RegistrationaddEditorReadyListener(com.vaadin.flow.component.ComponentEventListener<EditorReadyEvent> listener) 添加编辑器就绪事件监听器。com.vaadin.flow.shared.RegistrationaddFallbackListener(com.vaadin.flow.component.ComponentEventListener<FallbackEvent> listener) 添加降级事件监听器。booleancancelUpload(String uploadId) 取消指定的上传任务void清理所有事件监听器。voidclear()Clear editor contentstatic VaadinCKEditorBuildercreate()Create editor builder.protected Stringint获取活跃上传数量int获取内容字符数(不包含 HTML 标签)获取错误处理器。获取降级模式。获取 HTML 清理器。getId()获取已注册监听器的统计信息。Get plain text content (strip HTML tags)Get sanitized HTML (remove dangerous tags)获取经过清理的内容。获取上传处理器。getValue()static StringGet versionint获取内容单词数boolean检查是否有正在进行的上传voidinsertText(String text) Insert text at cursor positionboolean检查内容是否为空booleansanitizeHtml(String html, org.jsoup.safety.Safelist safelist) Sanitize HTML with specified rulesvoidsetAutosaveCallback(Consumer<String> callback) Set autosave callbackvoidsetErrorHandler(ErrorHandler handler) 设置错误处理器。void设置降级模式。voidsetGeneralHtmlSupportEnabled(boolean enabled) Enable general HTML supportvoidvoidsetHideToolbar(boolean hide) Set toolbar visibilityvoidsetHtmlSanitizer(HtmlSanitizer sanitizer) 设置 HTML 清理器。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) 设置上传处理器。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
获取经过清理的内容。 如果设置了 HtmlSanitizer,则应用清理;否则返回原始内容。- Returns:
- 清理后的 HTML 内容
-
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()获取内容字符数(不包含 HTML 标签)- Returns:
- 字符数
-
getWordCount
public int getWordCount()获取内容单词数- Returns:
- 单词数
-
isContentEmpty
public boolean isContentEmpty()检查内容是否为空- Returns:
- 如果内容为空或只包含空白则返回 true
-
getVersion
Get version -
addEditorReadyListener
public com.vaadin.flow.shared.Registration addEditorReadyListener(com.vaadin.flow.component.ComponentEventListener<EditorReadyEvent> listener) 添加编辑器就绪事件监听器。 当编辑器完全初始化并准备好接受用户输入时触发。使用示例:
editor.addEditorReadyListener(event -> { logger.info("Editor ready in {} ms", event.getInitializationTimeMs()); event.getSource().focus(); });- Parameters:
listener- 事件监听器- Returns:
- 用于移除监听器的注册对象
-
addEditorErrorListener
public com.vaadin.flow.shared.Registration addEditorErrorListener(com.vaadin.flow.component.ComponentEventListener<EditorErrorEvent> listener) 添加编辑器错误事件监听器。 当编辑器遇到错误时触发。使用示例:
editor.addEditorErrorListener(event -> { EditorError error = event.getError(); if (error.getSeverity() == ErrorSeverity.FATAL) { Notification.show("编辑器错误: " + error.getMessage(), Notification.Type.ERROR_MESSAGE); } });- Parameters:
listener- 事件监听器- Returns:
- 用于移除监听器的注册对象
-
addAutosaveListener
public com.vaadin.flow.shared.Registration addAutosaveListener(com.vaadin.flow.component.ComponentEventListener<AutosaveEvent> listener) 添加自动保存事件监听器。 当编辑器内容自动保存时触发。- Parameters:
listener- 事件监听器- Returns:
- 用于移除监听器的注册对象
-
addContentChangeListener
public com.vaadin.flow.shared.Registration addContentChangeListener(com.vaadin.flow.component.ComponentEventListener<ContentChangeEvent> listener) 添加内容变更事件监听器。 当编辑器内容发生变化时触发。- Parameters:
listener- 事件监听器- Returns:
- 用于移除监听器的注册对象
-
addFallbackListener
public com.vaadin.flow.shared.Registration addFallbackListener(com.vaadin.flow.component.ComponentEventListener<FallbackEvent> listener) 添加降级事件监听器。 当编辑器因错误触发降级模式时触发。- Parameters:
listener- 事件监听器- Returns:
- 用于移除监听器的注册对象
-
setErrorHandler
-
getErrorHandler
-
setHtmlSanitizer
-
getHtmlSanitizer
-
setUploadHandler
-
getUploadHandler
-
setFallbackMode
-
getFallbackMode
-
getListenerStats
-
cleanupListeners
public void cleanupListeners()清理所有事件监听器。 通常在组件销毁前调用。 -
hasActiveUploads
public boolean hasActiveUploads()检查是否有正在进行的上传- Returns:
- 是否有活跃上传
-
getActiveUploadCount
public int getActiveUploadCount()获取活跃上传数量- Returns:
- 活跃上传数
-
cancelUpload
-
VaadinCKEditorBuilderdirectly instead.