Skip to content

Commit

Permalink
Add enhancedRichText
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Feb 20, 2024
1 parent 7329025 commit e19e11c
Show file tree
Hide file tree
Showing 14 changed files with 757 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.merkle.oss.magnolia.definition.custom.richtext;

import com.merkle.oss.magnolia.definition.custom.richtext.toolbarbuilder.RichTextToolbarConfig;
import info.magnolia.ui.field.RichTextFieldDefinition;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class ExtendedRichTextDefinition extends RichTextFieldDefinition {
@Nullable
private String formatTags;
@Nullable
private String customStyleSet;
@Nullable
private String customTemplates;
@Nullable
private String templates;
@Nullable
private String extraAllowedContent;
@Nullable
private String contentCss;
@Nullable
private String enterMode;
private boolean forceAsPlainText;
private boolean pasteFromWordRemoveFontStyles;
private boolean pasteFromWordPromptCleanup;
@Nullable
private String bodyClass;
@Nullable
private RichTextToolbarConfig toolbarConfig;
private Map<String, String> extraConfig = Collections.emptyMap();
private Map<String, String> externalPlugins = Collections.emptyMap();

public ExtendedRichTextDefinition() {
setFactoryClass(ExtendedRichTextFactory.class);
}

public Optional<RichTextToolbarConfig> getToolbarConfig() {
return Optional.ofNullable(toolbarConfig);
}

public void setToolbarConfig(RichTextToolbarConfig toolbarConfig) {
this.toolbarConfig = toolbarConfig;
}

public Optional<String> getFormatTags() {
return Optional.ofNullable(formatTags);
}

public void setFormatTags(final String formatTags) {
this.formatTags = formatTags;
}

public Optional<String> getCustomStyleSet() {
return Optional.ofNullable(customStyleSet);
}

public void setCustomStyleSet(final String customStyleSet) {
this.customStyleSet = customStyleSet;
}

public Optional<String> getCustomTemplates() {
return Optional.ofNullable(customTemplates);
}

public void setCustomTemplates(final String customTemplates) {
this.customTemplates = customTemplates;
}

public Optional<String> getTemplates() {
return Optional.ofNullable(templates);
}

public void setTemplates(final String templates) {
this.templates = templates;
}

public Optional<String> getExtraAllowedContent() {
return Optional.ofNullable(extraAllowedContent);
}

public void setExtraAllowedContent(final String extraAllowedContent) {
this.extraAllowedContent = extraAllowedContent;
}

public Optional<String> getContentCss() {
return Optional.ofNullable(contentCss);
}

public void setContentCss(final String contentCss) {
this.contentCss = contentCss;
}

public Optional<String> getEnterMode() {
return Optional.ofNullable(enterMode);
}

public void setEnterMode(final String enterMode) {
this.enterMode = enterMode;
}

public boolean isForceAsPlainText() {
return forceAsPlainText;
}

public void setForceAsPlainText(final boolean forceAsPlainText) {
this.forceAsPlainText = forceAsPlainText;
}

public boolean isPasteFromWordRemoveFontStyles() {
return pasteFromWordRemoveFontStyles;
}

public void setPasteFromWordRemoveFontStyles(boolean pasteFromWordRemoveFontStyles) {
this.pasteFromWordRemoveFontStyles = pasteFromWordRemoveFontStyles;
}

public boolean isPasteFromWordPromptCleanup() {
return pasteFromWordPromptCleanup;
}

public void setPasteFromWordPromptCleanup(boolean pasteFromWordPromptCleanup) {
this.pasteFromWordPromptCleanup = pasteFromWordPromptCleanup;
}

public Optional<String> getBodyClass() {
return Optional.ofNullable(bodyClass);
}

public void setBodyClass(final String bodyClass) {
this.bodyClass = bodyClass;
}

public void setExtraConfig(final Map<String, String> extraConfig) {
this.extraConfig = extraConfig;
}

public Map<String, String> getExtraConfig() {
return extraConfig;
}

public void setExternalPlugins(final Map<String, String> externalPlugins) {
this.externalPlugins = externalPlugins;
}

public Map<String, String> getExternalPlugins() {
return externalPlugins;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package com.merkle.oss.magnolia.definition.custom.richtext;

import com.merkle.oss.magnolia.definition.builder.simple.AbstractConfiguredFieldDefinitionBuilder;
import com.merkle.oss.magnolia.definition.custom.richtext.toolbarbuilder.RichTextToolbarConfig;

import javax.annotation.Nullable;
import java.util.*;

public class ExtendedRichTextDefinitionBuilder extends AbstractConfiguredFieldDefinitionBuilder<String, ExtendedRichTextDefinition, ExtendedRichTextDefinitionBuilder> {
@Nullable
private Boolean tables;
@Nullable
private String formatTags;
@Nullable
private String customStyleSet;
@Nullable
private String customTemplates;
@Nullable
private String useTemplate;
@Nullable
private String colors;
@Nullable
private Boolean source;
@Nullable
private String enterMode;
@Nullable
private Boolean images;
@Nullable
private Boolean alignment;
@Nullable
private String configFileJs;
@Nullable
private String contentCss;
@Nullable
private String extraAllowedContent;
@Nullable
private Boolean forcePlainText;
@Nullable
private Boolean pasteFromWordRemoveFontStyles;
@Nullable
private Boolean pasteFromWordPromptCleanup;
@Nullable
private String bodyClass;
@Nullable
private Integer height;
@Nullable
private RichTextToolbarConfig toolbarConfig;
private final Map<String, String> extraConfig = new HashMap<>();
private final Map<String, String> externalPlugins = new HashMap<>();

public ExtendedRichTextDefinitionBuilder() {
super(ExtendedRichTextDefinition::new);
}

public ExtendedRichTextDefinitionBuilder tables(final boolean tables) {
this.tables = tables;
return self();
}

public ExtendedRichTextDefinitionBuilder formatTags(final String formatTags) {
this.formatTags = formatTags;
return self();
}

public ExtendedRichTextDefinitionBuilder customStyleSet(final String customStyleSet) {
this.customStyleSet = customStyleSet;
return self();
}

public ExtendedRichTextDefinitionBuilder customTemplates(final String customTemplates) {
this.customTemplates = customTemplates;
return self();
}

public ExtendedRichTextDefinitionBuilder useTemplate(final String useTemplate) {
this.useTemplate = useTemplate;
return self();
}

public ExtendedRichTextDefinitionBuilder setColors(final String colors) {
this.colors = colors;
return self();
}

public ExtendedRichTextDefinitionBuilder showSourceButton(final boolean sourceButton) {
this.source = sourceButton;
return self();
}

public ExtendedRichTextDefinitionBuilder enterMode(final String enterMode) {
this.enterMode = enterMode;
return self();
}

public ExtendedRichTextDefinitionBuilder images(final boolean images) {
this.images = images;
return self();
}

public ExtendedRichTextDefinitionBuilder alignment(final boolean alignment) {
this.alignment = alignment;
return self();
}

public ExtendedRichTextDefinitionBuilder setConfigJsFile(final String configJsFile) {
this.configFileJs = configJsFile;
return self();
}

public ExtendedRichTextDefinitionBuilder extraAllowedContent(final String extraAllowedContent) {
this.extraAllowedContent = extraAllowedContent;
return self();
}

public ExtendedRichTextDefinitionBuilder contentCss(final String contentCss) {
this.contentCss = contentCss;
return self();
}

public ExtendedRichTextDefinitionBuilder forceAsPlainText(final boolean forcePlainText) {
this.forcePlainText = forcePlainText;
return self();
}

public ExtendedRichTextDefinitionBuilder pasteFromWordRemoveFontStyles(final boolean pasteFromWordRemoveFontStyles) {
this.pasteFromWordRemoveFontStyles = pasteFromWordRemoveFontStyles;
return self();
}

public ExtendedRichTextDefinitionBuilder pasteFromWordPromptCleanup(final boolean pasteFromWordPromptCleanup) {
this.pasteFromWordPromptCleanup = pasteFromWordPromptCleanup;
return self();
}

public ExtendedRichTextDefinitionBuilder bodyClass(final String bodyClass) {
this.bodyClass = bodyClass;
return self();
}

public ExtendedRichTextDefinitionBuilder height(final int height) {
this.height = height;
return self();
}

public ExtendedRichTextDefinitionBuilder toolbarConfig(final RichTextToolbarConfig toolbarConfig) {
this.toolbarConfig = toolbarConfig;
return self();
}

public ExtendedRichTextDefinitionBuilder externalPlugin(final String name, final String source) {
this.externalPlugins.put(name, source);
return self();
}

public ExtendedRichTextDefinitionBuilder extraConfig(final String name, final String value) {
this.extraConfig.put(name, value);
return self();
}

public ExtendedRichTextDefinition build(String name) {
final ExtendedRichTextDefinition definition = super.build(name);
Optional.ofNullable(tables).ifPresent(definition::setTables);
Optional.ofNullable(formatTags).ifPresent(definition::setFormatTags);
Optional.ofNullable(customStyleSet).ifPresent(definition::setCustomStyleSet);
Optional.ofNullable(customTemplates).ifPresent(definition::setCustomTemplates);
Optional.ofNullable(useTemplate).ifPresent(definition::setTemplates);
Optional.ofNullable(colors).ifPresent(definition::setColors);
Optional.ofNullable(source).ifPresent(definition::setSource);
Optional.ofNullable(enterMode).ifPresent(definition::setEnterMode);
Optional.ofNullable(images).ifPresent(definition::setImages);
Optional.ofNullable(alignment).ifPresent(definition::setAlignment);
Optional.ofNullable(configFileJs).ifPresent(definition::setConfigJsFile);
Optional.ofNullable(contentCss).ifPresent(definition::setContentCss);
Optional.ofNullable(extraAllowedContent).ifPresent(definition::setExtraAllowedContent);
Optional.ofNullable(forcePlainText).ifPresent(definition::setForceAsPlainText);
Optional.ofNullable(pasteFromWordPromptCleanup).ifPresent(definition::setPasteFromWordPromptCleanup);
Optional.ofNullable(pasteFromWordRemoveFontStyles).ifPresent(definition::setPasteFromWordRemoveFontStyles);
Optional.ofNullable(bodyClass).ifPresent(definition::setBodyClass);
Optional.ofNullable(toolbarConfig).ifPresent(definition::setToolbarConfig);
Optional.ofNullable(height).ifPresent(definition::setHeight);
definition.setExternalPlugins(externalPlugins);
definition.setExtraConfig(extraConfig);
return definition;
}
}
Loading

0 comments on commit e19e11c

Please sign in to comment.