fix(editor-components): fix default value processing (#1848)
This commit is contained in:
parent
9856b7e03c
commit
a0cfa1a92f
@ -145,25 +145,32 @@ export default class Editor extends React.Component {
|
|||||||
const { getEditorComponents } = this.props;
|
const { getEditorComponents } = this.props;
|
||||||
const { value } = this.state;
|
const { value } = this.state;
|
||||||
const nodes = [Text.create('')];
|
const nodes = [Text.create('')];
|
||||||
const pluginFields = getEditorComponents()
|
|
||||||
.get(pluginId)
|
/**
|
||||||
.get('fields', List());
|
* Get default values for plugin fields.
|
||||||
const shortcodeData = pluginFields
|
*/
|
||||||
.map(field => field.get('default'))
|
const pluginFields = getEditorComponents().getIn([pluginId, 'fields'], List());
|
||||||
.filter(val => val)
|
const defaultValues = pluginFields
|
||||||
.toMap()
|
.toMap()
|
||||||
.mapKeys((idx, field) => field.get('name'));
|
.mapKeys((_, field) => field.get('name'))
|
||||||
|
.filter(field => field.has('default'))
|
||||||
|
.map(field => field.get('default'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new shortcode block with default values set.
|
||||||
|
*/
|
||||||
const block = {
|
const block = {
|
||||||
object: 'block',
|
object: 'block',
|
||||||
type: 'shortcode',
|
type: 'shortcode',
|
||||||
data: {
|
data: {
|
||||||
shortcode: pluginId,
|
shortcode: pluginId,
|
||||||
shortcodeNew: true,
|
shortcodeNew: true,
|
||||||
shortcodeData,
|
shortcodeData: defaultValues,
|
||||||
},
|
},
|
||||||
isVoid: true,
|
isVoid: true,
|
||||||
nodes,
|
nodes,
|
||||||
};
|
};
|
||||||
|
|
||||||
let change = value.change();
|
let change = value.change();
|
||||||
const { focusBlock } = change.value;
|
const { focusBlock } = change.value;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user