diff --git a/client/src/components/Draftail/index.js b/client/src/components/Draftail/index.js
index e726fa5784..2eaec3a32f 100644
--- a/client/src/components/Draftail/index.js
+++ b/client/src/components/Draftail/index.js
@@ -11,12 +11,22 @@ import EmbedBlock from './blocks/EmbedBlock';
import registry from './registry';
+const wrapWagtailIcon = type => {
+ if (type.icon) {
+ return Object.assign(type, {
+ icon: ,
+ });
+ }
+
+ return type;
+}
+
export const initEditor = (fieldName, options = {}) => {
const field = document.querySelector(`[name="${fieldName}"]`);
const editorWrapper = document.createElement('div');
field.parentNode.appendChild(editorWrapper);
- const serialiseInputValue = (rawContentState) => {
+ const serialiseInputValue = rawContentState => {
// TODO Remove default {} when finishing https://github.com/springload/wagtaildraftail/issues/32.
field.value = JSON.stringify(rawContentState || {});
};
@@ -26,30 +36,28 @@ export const initEditor = (fieldName, options = {}) => {
let entityTypes;
if (options && options.blockTypes) {
- blockTypes = options.blockTypes.map(type => Object.assign(type, {
- icon: ,
- }));
+ blockTypes = options.blockTypes.map(wrapWagtailIcon);
}
if (options && options.inlineStyles) {
- inlineStyles = options.inlineStyles.map(type => Object.assign(type, {
- icon: ,
- }));
+ inlineStyles = options.inlineStyles.map(wrapWagtailIcon);
}
if (options && options.entityTypes) {
- entityTypes = options.entityTypes.map(type => Object.assign(type, {
- icon: ,
- source: registry.getSource(type.source),
- strategy: registry.getStrategy(type.type) || null,
- decorator: registry.getDecorator(type.decorator),
- block: registry.getBlock(type.block),
- }));
+ entityTypes = options.entityTypes.map(wrapWagtailIcon).map(type =>
+ Object.assign(type, {
+ source: registry.getSource(type.source),
+ strategy: registry.getStrategy(type.type) || null,
+ decorator: registry.getDecorator(type.decorator),
+ block: registry.getBlock(type.block),
+ }),
+ );
}
const fieldValue = JSON.parse(field.value);
// TODO Remove default null when finishing https://github.com/springload/wagtaildraftail/issues/32.
- const rawContentState = fieldValue && Object.keys(fieldValue).length === 0 ? null : fieldValue;
+ const rawContentState =
+ fieldValue && Object.keys(fieldValue).length === 0 ? null : fieldValue;
const editor = (