kopia lustrzana https://github.com/wagtail/wagtail
Fix Draftail icon wrapping happening even if there is no icon
rodzic
8ab8592b40
commit
d8489574d3
|
@ -11,12 +11,22 @@ import EmbedBlock from './blocks/EmbedBlock';
|
|||
|
||||
import registry from './registry';
|
||||
|
||||
const wrapWagtailIcon = type => {
|
||||
if (type.icon) {
|
||||
return Object.assign(type, {
|
||||
icon: <Icon name={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: <Icon name={type.icon} />,
|
||||
}));
|
||||
blockTypes = options.blockTypes.map(wrapWagtailIcon);
|
||||
}
|
||||
|
||||
if (options && options.inlineStyles) {
|
||||
inlineStyles = options.inlineStyles.map(type => Object.assign(type, {
|
||||
icon: <Icon name={type.icon} />,
|
||||
}));
|
||||
inlineStyles = options.inlineStyles.map(wrapWagtailIcon);
|
||||
}
|
||||
|
||||
if (options && options.entityTypes) {
|
||||
entityTypes = options.entityTypes.map(type => Object.assign(type, {
|
||||
icon: <Icon name={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 = (
|
||||
<DraftailEditor
|
||||
|
@ -74,12 +82,15 @@ registry.registerBlocks({
|
|||
EmbedBlock,
|
||||
});
|
||||
|
||||
const draftail = Object.assign({
|
||||
initEditor: initEditor,
|
||||
// Expose basic React methods for basic needs
|
||||
// TODO Expose React as global as part of Wagtail vendor file instead of doing this.
|
||||
// createClass: React.createClass,
|
||||
// createElement: React.createElement,
|
||||
}, registry);
|
||||
const draftail = Object.assign(
|
||||
{
|
||||
initEditor: initEditor,
|
||||
// Expose basic React methods for basic needs
|
||||
// TODO Expose React as global as part of Wagtail vendor file instead of doing this.
|
||||
// createClass: React.createClass,
|
||||
// createElement: React.createElement,
|
||||
},
|
||||
registry,
|
||||
);
|
||||
|
||||
export default draftail;
|
||||
|
|
Ładowanie…
Reference in New Issue