Class GrapesJs
java.lang.Object
com.vaadin.flow.component.Component
io.jmix.messagetemplatesflowui.kit.component.GrapesJs
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,Serializable
@Tag("jmix-grapes-js")
@NpmPackage(value="grapesjs",version="0.21.13") @NpmPackage(value="grapesjs-blocks-basic",version="1.0.2") @NpmPackage(value="grapesjs-custom-code",version="1.0.2") @NpmPackage(value="grapesjs-blocks-flexbox",version="1.0.1") @NpmPackage(value="grapesjs-plugin-forms",version="2.0.6") @NpmPackage(value="grapesjs-preset-newsletter",version="1.0.2") @NpmPackage(value="grapesjs-parser-postcss",version="1.0.3") @NpmPackage(value="grapesjs-style-filter",version="1.0.2") @NpmPackage(value="grapesjs-tabs",version="1.0.6") @NpmPackage(value="grapesjs-tooltip",version="0.1.8") @NpmPackage(value="grapesjs-tui-image-editor",version="1.0.2") @NpmPackage(value="grapesjs-preset-webpage",version="1.0.3")
@JsModule("./src/grapesjs/jmix-grapes-js.js")
@CssImport("grapesjs/dist/css/grapes.min.css") @CssImport("./src/grapesjs/jmix-grapes-js.css")
public class GrapesJs
extends com.vaadin.flow.component.Component
implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle
GrapesJS component is used to create HTML templates using a web editor. This implementation is based on
GrapesJS JavaScript library.
The component uses
The component supports
The component uses
GrapesJsBlocks to build a template that can be reused. The component supports
GrapesJsPlugins that can provide additional functionality such
as additional settings, visual appearance or blocks.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEvent is fired at the moment of updating the value of theGrapesJstemplate. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<GrapesJsBlock>protected Stringprotected List<GrapesJsPlugin>protected GrapesJsSerializerprotected com.vaadin.flow.internal.StateTree.ExecutionRegistrationprotected com.vaadin.flow.internal.StateTree.ExecutionRegistration -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBlock(GrapesJsBlock block) Adds a block to the GrapesJS editor.voidaddBlocks(GrapesJsBlock... blocks) Add array of blocks to the GrapesJS editor.voidaddBlocks(Collection<GrapesJsBlock> blocks) Add collection of blocks to the GrapesJS editor.voidaddPlugin(GrapesJsPlugin plugin) Adds a plugin to the GrapesJS editor.voidaddPlugins(GrapesJsPlugin... plugins) Adds array of the plugins to the GrapesJS editor.voidaddPlugins(Collection<GrapesJsPlugin> plugins) Adds collection of plugins to the GrapesJS editor.com.vaadin.flow.shared.RegistrationaddValueChangeEventListener(com.vaadin.flow.component.ComponentEventListener<GrapesJs.GrapesJsValueChangedEvent> listener) Adds a value change listener.protected voidcallJsFunction(String functionName, Serializable... arguments) protected GrapesJsSerializerprotected GrapesJs.GrapesJsValueChangedEventcreateValueChangedEvent(String oldValue, boolean fromClient) protected StringgetValue()protected voidbooleanReturns whether thisGrapesJsis in read-only mode or not.protected StringnullToEmptyValue(String value) protected voidvoidremoveBlock(String blockId) Removes the block with passed ID from the GrapesJS editor.voidremoveBlocks(String... blockIds) Removes the collection of blocks with passed IDs from the GrapesJS editor.voidremoveBlocks(Collection<String> blockIds) Removes the collection of blocks with passed IDs from the GrapesJS editor.protected elemental.json.JsonValuevoidrunCommand(String command) Execute command for GrapesJS editor.voidrunCommand(String command, String parameters) Execute command for GrapesJS editor.voidsetReadOnly(boolean readOnly) Sets the read-only mode of thisGrapesJsto given mode.voidSets the passed HTML string as template value for the GrapesJS editor.protected voidsetValueInternal(String value, boolean fromClient) voidstopCommand(String command) Stop the command for GrapesJS editor if stop method was provided.voidstopCommand(String command, String parameters) Stop the command for GrapesJS editor if stop method was provided.protected voidprotected voidupdateClientSideBlocks(com.vaadin.flow.internal.ExecutionContext context) protected voidupdateClientSideValue(com.vaadin.flow.internal.ExecutionContext context) protected voidMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.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.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Field Details
-
serializer
-
plugins
-
blocks
-
synchronizeBlocksUpdateExecution
protected com.vaadin.flow.internal.StateTree.ExecutionRegistration synchronizeBlocksUpdateExecution -
synchronizeValueUpdateExecution
protected com.vaadin.flow.internal.StateTree.ExecutionRegistration synchronizeValueUpdateExecution -
internalValue
-
-
Constructor Details
-
GrapesJs
public GrapesJs()Creates new instance of GrapesJS editor.
-
-
Method Details
-
initComponent
protected void initComponent() -
getPlugins
- Returns:
- list of added plugins
-
addPlugin
Adds a plugin to the GrapesJS editor. Plugins can only be modified before the client-side of the component is initialized.- Parameters:
plugin- plugin to add
-
addPlugins
Adds collection of plugins to the GrapesJS editor.- Parameters:
plugins- collection of plugins to add
-
addPlugins
Adds array of the plugins to the GrapesJS editor.- Parameters:
plugins- array of plugins to add
-
getBlocks
- Returns:
- list of added blocks
-
addBlock
Adds a block to the GrapesJS editor.- Parameters:
block- block to add
-
addBlocks
Add collection of blocks to the GrapesJS editor.- Parameters:
blocks- collection of blocks to add
-
addBlocks
Add array of blocks to the GrapesJS editor.- Parameters:
blocks- array of blocks to add
-
removeBlock
Removes the block with passed ID from the GrapesJS editor.- Parameters:
blockId- ID of the block to remove
-
removeBlocks
Removes the collection of blocks with passed IDs from the GrapesJS editor.- Parameters:
blockIds- collection of IDs of the blocks to remove
-
removeBlocks
Removes the collection of blocks with passed IDs from the GrapesJS editor.- Parameters:
blockIds- array of IDs of the blocks to remove
-
setValue
Sets the passed HTML string as template value for the GrapesJS editor.
Note:nullvalue will be converted to an empty HTML string (seegetEmptyValue()).- Parameters:
value- HTML string to set
-
getValue
- Returns:
- HTML string from GrapesJS template
-
addValueChangeEventListener
public com.vaadin.flow.shared.Registration addValueChangeEventListener(com.vaadin.flow.component.ComponentEventListener<GrapesJs.GrapesJsValueChangedEvent> listener) Adds a value change listener. The listener is called when the value of GrapesJS is changed either by the user on the client-side or programmatically.- Parameters:
listener- the value change listener, not null- Returns:
- a registration for the listener
-
runCommand
Execute command for GrapesJS editor.- Parameters:
command- command to execute- See Also:
-
runCommand
Execute command for GrapesJS editor.- Parameters:
command- command to executeparameters- parameters for command as a JSON string- See Also:
-
stopCommand
Stop the command for GrapesJS editor if stop method was provided.- Parameters:
command- command to stop- See Also:
-
stopCommand
Stop the command for GrapesJS editor if stop method was provided.- Parameters:
command- command to stopparameters- parameters for command as a JSON string- See Also:
-
setReadOnly
public void setReadOnly(boolean readOnly) Sets the read-only mode of thisGrapesJsto given mode. The user can't change the value when in read-only mode.A
GrapesJswith a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.- Parameters:
readOnly- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
public boolean isReadOnly()Returns whether thisGrapesJsis in read-only mode or not.- Returns:
falseif the user can modify the value,trueif not.
-
requestPlugins
@ClientCallable protected elemental.json.JsonValue requestPlugins() -
setValueInternal
-
onValueChangedDomEvent
-
updateBlocksOnClientSide
protected void updateBlocksOnClientSide() -
updateClientSideBlocks
protected void updateClientSideBlocks(com.vaadin.flow.internal.ExecutionContext context) -
updateValueOnClientSide
protected void updateValueOnClientSide() -
updateClientSideValue
protected void updateClientSideValue(com.vaadin.flow.internal.ExecutionContext context) -
callJsFunction
-
createValueChangedEvent
protected GrapesJs.GrapesJsValueChangedEvent createValueChangedEvent(@Nullable String oldValue, boolean fromClient) -
createSerializer
-
nullToEmptyValue
-
getEmptyValue
-