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 class
Event is fired at the moment of updating the value of theGrapesJs
template. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<GrapesJsBlock>
protected String
protected List<GrapesJsPlugin>
protected GrapesJsSerializer
protected com.vaadin.flow.internal.StateTree.ExecutionRegistration
protected com.vaadin.flow.internal.StateTree.ExecutionRegistration
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBlock
(GrapesJsBlock block) Adds a block to the GrapesJS editor.void
addBlocks
(GrapesJsBlock... blocks) Add array of blocks to the GrapesJS editor.void
addBlocks
(Collection<GrapesJsBlock> blocks) Add collection of blocks to the GrapesJS editor.void
addPlugin
(GrapesJsPlugin plugin) Adds a plugin to the GrapesJS editor.void
addPlugins
(GrapesJsPlugin... plugins) Adds array of the plugins to the GrapesJS editor.void
addPlugins
(Collection<GrapesJsPlugin> plugins) Adds collection of plugins to the GrapesJS editor.com.vaadin.flow.shared.Registration
addValueChangeEventListener
(com.vaadin.flow.component.ComponentEventListener<GrapesJs.GrapesJsValueChangedEvent> listener) Adds a value change listener.protected void
callJsFunction
(String functionName, Serializable... arguments) protected GrapesJsSerializer
protected GrapesJs.GrapesJsValueChangedEvent
createValueChangedEvent
(String oldValue, boolean fromClient) protected String
getValue()
protected void
boolean
Returns whether thisGrapesJs
is in read-only mode or not.protected String
nullToEmptyValue
(String value) protected void
void
removeBlock
(String blockId) Removes the block with passed ID from the GrapesJS editor.void
removeBlocks
(String... blockIds) Removes the collection of blocks with passed IDs from the GrapesJS editor.void
removeBlocks
(Collection<String> blockIds) Removes the collection of blocks with passed IDs from the GrapesJS editor.protected elemental.json.JsonValue
void
runCommand
(String command) Execute command for GrapesJS editor.void
runCommand
(String command, String parameters) Execute command for GrapesJS editor.void
setReadOnly
(boolean readOnly) Sets the read-only mode of thisGrapesJs
to given mode.void
Sets the passed HTML string as template value for the GrapesJS editor.protected void
setValueInternal
(String value, boolean fromClient) void
stopCommand
(String command) Stop the command for GrapesJS editor if stop method was provided.void
stopCommand
(String command, String parameters) Stop the command for GrapesJS editor if stop method was provided.protected void
protected void
updateClientSideBlocks
(com.vaadin.flow.internal.ExecutionContext context) protected void
updateClientSideValue
(com.vaadin.flow.internal.ExecutionContext context) protected void
Methods 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, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods 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, setWidthFull
Methods 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:null
value 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 thisGrapesJs
to given mode. The user can't change the value when in read-only mode.A
GrapesJs
with 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 thisGrapesJs
is in read-only mode or not.- Returns:
false
if the user can modify the value,true
if 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
-