fix: add support for default field values in editor components (#1616)
This commit is contained in:
parent
db213f4ee1
commit
0d0180966a
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user