From 0d0180966a5773b32046db0739761de0352bb8b3 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 4 Sep 2018 11:29:06 -0600 Subject: [PATCH] fix: add support for default field values in editor components (#1616) --- .../src/MarkdownControl/VisualEditor.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js b/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js index deef342e..db118930 100644 --- a/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js +++ b/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js @@ -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,