fix: add support for default field values in editor components (#1616)

This commit is contained in:
Caleb 2018-09-04 11:29:06 -06:00 committed by Shawn Erquhart
parent db213f4ee1
commit 0d0180966a

View File

@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import styled, { cx } from 'react-emotion';
import { get, isEmpty, debounce } from 'lodash';
import { Map } from 'immutable';
import { List } from 'immutable';
import { Value, Document, Block, Text } from 'slate';
import { Editor as Slate } from 'slate-react';
import { slateToMarkdown, markdownToSlate, htmlToSlate } from '../serializers';
@ -142,15 +142,24 @@ export default class Editor extends React.Component {
};
handlePluginAdd = pluginId => {
const { getEditorComponents } = this.props;
const { value } = this.state;
const nodes = [Text.create('')];
const pluginFields = getEditorComponents()
.get(pluginId)
.get('fields', List());
const shortcodeData = pluginFields
.map(field => field.get('default'))
.filter(val => val)
.toMap()
.mapKeys((idx, field) => field.get('name'));
const block = {
object: 'block',
type: 'shortcode',
data: {
shortcode: pluginId,
shortcodeNew: true,
shortcodeData: Map(),
shortcodeData,
},
isVoid: true,
nodes,