diff --git a/custom-definitions/pom.xml b/custom-definitions/pom.xml index 539056f..2e19835 100644 --- a/custom-definitions/pom.xml +++ b/custom-definitions/pom.xml @@ -57,4 +57,22 @@ test + + + + + + src/main/resources + + **/* + + + + src/main/java + + **/*.js + + + + \ No newline at end of file diff --git a/custom-definitions/src/main/java/com/merkle/oss/magnolia/definition/custom/richtext/ExtendedCKEditor5TextField.java b/custom-definitions/src/main/java/com/merkle/oss/magnolia/definition/custom/richtext/ExtendedCKEditor5TextField.java new file mode 100644 index 0000000..d804e15 --- /dev/null +++ b/custom-definitions/src/main/java/com/merkle/oss/magnolia/definition/custom/richtext/ExtendedCKEditor5TextField.java @@ -0,0 +1,40 @@ +package com.merkle.oss.magnolia.definition.custom.richtext; + +import info.magnolia.ui.vaadin.ckeditor.CKEditor5TextField; +import info.magnolia.ui.vaadin.ckeditor.CKEditor5TextFieldState; + +import com.vaadin.annotations.JavaScript; + +/** + * Server side component for the ExtendedCKEditor 5 JavaScript rich-text editor. + */ +@JavaScript({ + //a virtual path, which is redirected to an actual build specified in the microprofile. + //for developing set 'magnolia.ckeditor5.build' microprofile property. + "vaadin://ckeditor5.js", + "extended-ckeditor5-text-field-connector.js" +}) +public class ExtendedCKEditor5TextField extends CKEditor5TextField { + + @Override + protected State getState() { + return (State) super.getState(); + } + + @Override + protected State getState(final boolean markAsDirty) { + return (State) super.getState(markAsDirty); + } + + public void setConfig(final ExtendedCKEditor5TextFieldConfig config) { + getState().extendedConfig = config; + getState().config = config; + } + + /** + * Shared state for the {@link ExtendedCKEditor5TextField}. + */ + public static class State extends CKEditor5TextFieldState { + public ExtendedCKEditor5TextFieldConfig extendedConfig; + } +} diff --git a/custom-definitions/src/main/java/com/merkle/oss/magnolia/definition/custom/richtext/ExtendedCKEditor5TextFieldConfig.java b/custom-definitions/src/main/java/com/merkle/oss/magnolia/definition/custom/richtext/ExtendedCKEditor5TextFieldConfig.java new file mode 100644 index 0000000..6483168 --- /dev/null +++ b/custom-definitions/src/main/java/com/merkle/oss/magnolia/definition/custom/richtext/ExtendedCKEditor5TextFieldConfig.java @@ -0,0 +1,81 @@ +package com.merkle.oss.magnolia.definition.custom.richtext; + +import info.magnolia.ui.vaadin.ckeditor.CKEditor5TextFieldConfig; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.merkle.oss.magnolia.definition.custom.richtext.toolbarbuilder.ToolbarGroup; +import com.merkle.oss.magnolia.definition.custom.richtext.toolbarbuilder.groupbuilder.FontGroupBuilder; + +public class ExtendedCKEditor5TextFieldConfig extends CKEditor5TextFieldConfig { + public final Heading heading; + + public ExtendedCKEditor5TextFieldConfig( + final String licenseKey, + final List toolbarGroups, + final List options + ) { + super(licenseKey); + this.toolbar = new ExtendedToolbar(toolbarGroups, true); + this.heading = new Heading(options); + getToolbarGroup(toolbarGroups, FontGroupBuilder.FontToolbarGroup.class).ifPresent(fontToolbarGroup -> { + this.fontFamily.options = fontToolbarGroup.getFonts(); + this.fontSize.options = fontToolbarGroup.getFontSizes(); + this.fontColor.colors = fontToolbarGroup.getFontColors(); + }); + } + + private Optional getToolbarGroup(final List toolbarGroups, final Class clazz) { + return toolbarGroups.stream() + .filter(clazz::isInstance) + .findFirst() + .map(clazz::cast); + } + + public static class ExtendedToolbar extends Toolbar { + public ExtendedToolbar(final List toolbarGroups, final boolean shouldNotGroupWhenFull) { + super.shouldNotGroupWhenFull = shouldNotGroupWhenFull; + super.items = toolbarGroups.stream().flatMap(group -> + Stream.concat( + group.getItems().stream(), + Stream.of("|") + ) + ).collect(Collectors.toList()); + } + } + + /** + * Represents a heading configuration. + */ + // See implementation here: + // https://github.com/ckeditor/ckeditor5/blob/v41.4.2/packages/ckeditor5-heading/src/utils.ts#L34 + public static class Heading { + public final List