re-enable shortcode insertion via toolbar
This commit is contained in:
@ -397,6 +397,23 @@ export default class Editor extends Component {
|
|||||||
schema: {
|
schema: {
|
||||||
nodes: NODE_COMPONENTS,
|
nodes: NODE_COMPONENTS,
|
||||||
marks: MARK_COMPONENTS,
|
marks: MARK_COMPONENTS,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
match: object => object.kind === 'document',
|
||||||
|
validate: doc => {
|
||||||
|
const hasBlocks = !doc.getBlocks().isEmpty();
|
||||||
|
return hasBlocks ? null : {};
|
||||||
|
},
|
||||||
|
normalize: transform => {
|
||||||
|
const block = SlateBlock.create({
|
||||||
|
type: 'paragraph',
|
||||||
|
nodes: [SlateText.createFromString('')],
|
||||||
|
});
|
||||||
|
const { key } = transform.state.document;
|
||||||
|
return transform.insertNodeByKey(key, 0, block).focus();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
};
|
};
|
||||||
@ -504,11 +521,15 @@ export default class Editor extends Component {
|
|||||||
command(this.view.state, this.handleAction);
|
command(this.view.state, this.handleAction);
|
||||||
};
|
};
|
||||||
|
|
||||||
handlePluginSubmit = (plugin, data) => {
|
handlePluginSubmit = (plugin, shortcodeData) => {
|
||||||
const { editorState } = this.state;
|
const { editorState } = this.state;
|
||||||
const markdown = plugin.toBlock(data.toJS());
|
const data = {
|
||||||
const html = markdownToHtml(markdown);
|
shortcode: plugin.id,
|
||||||
const block = serializer.deserialize(html).document.getBlocks().first();
|
shortcodeValue: plugin.toBlock(shortcodeData.toJS()),
|
||||||
|
shortcodeData,
|
||||||
|
};
|
||||||
|
const nodes = [SlateText.createFromString('')];
|
||||||
|
const block = { kind: 'block', type: 'shortcode', data, isVoid: true, nodes };
|
||||||
const resolvedState = editorState.transform().insertBlock(block).apply();
|
const resolvedState = editorState.transform().insertBlock(block).apply();
|
||||||
this.ref.onChange(resolvedState);
|
this.ref.onChange(resolvedState);
|
||||||
this.setState({ editorState: resolvedState });
|
this.setState({ editorState: resolvedState });
|
||||||
|
Reference in New Issue
Block a user