decap-cms-widget-markdown 3.7.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,13 +39,24 @@ export default class MarkdownControl extends React.Component {
39
39
  const preferredMode = localStorage.getItem(MODE_STORAGE_KEY) ?? 'rich_text';
40
40
  _getEditorComponents = props.getEditorComponents;
41
41
  this.state = {
42
- mode: this.getAllowedModes().indexOf(preferredMode) !== -1 ? preferredMode : this.getAllowedModes()[0],
42
+ mode:
43
+ // When used inside a container/shortcode editor component, default to
44
+ // raw mode — the widget type already implies the editing surface.
45
+ props.isEditorComponent ? 'raw' : this.getAllowedModes().indexOf(preferredMode) !== -1 ? preferredMode : this.getAllowedModes()[0],
43
46
  pendingFocus: false
44
47
  };
45
48
  }
46
49
  componentDidMount() {
47
50
  // Manually validate PropTypes - React 19 breaking change
48
51
  PropTypes.checkPropTypes(MarkdownControl.propTypes, this.props, 'prop', 'MarkdownControl');
52
+
53
+ // Ensure containerised widgets start in the correct mode even if the
54
+ // constructor ran before the prop was available (e.g. HMR / late prop).
55
+ if (this.props.isEditorComponent && this.state.mode !== 'raw') {
56
+ this.setState({
57
+ mode: 'raw'
58
+ });
59
+ }
49
60
  }
50
61
  handleMode = mode => {
51
62
  this.setState({
@@ -84,7 +95,8 @@ export default class MarkdownControl extends React.Component {
84
95
  mode,
85
96
  pendingFocus
86
97
  } = this.state;
87
- const isShowModeToggle = this.getAllowedModes().length > 1;
98
+ const isEditorComponent = this.props.isEditorComponent;
99
+ const isShowModeToggle = this.getAllowedModes().length > 1 && !isEditorComponent;
88
100
  const visualEditor = ___EmotionJSX("div", {
89
101
  className: "cms-editor-visual",
90
102
  ref: this.processRef
@@ -82,7 +82,7 @@ const INLINE_STYLES = {
82
82
  };
83
83
  function deserialize(el) {
84
84
  if (el.nodeType === 3) {
85
- return el.textContent;
85
+ return el.textContent.replace(/(\r)?\n/g, '');
86
86
  } else if (el.nodeType !== 1) {
87
87
  return null;
88
88
  } else if (el.nodeName === 'BR') {
@@ -1,7 +1,7 @@
1
1
  import { Transforms } from 'slate';
2
2
  import isCursorInEmptyParagraph from './locations/isCursorInEmptyParagraph';
3
3
  function insertShortcode(editor, pluginConfig) {
4
- const defaultValues = pluginConfig.fields.toMap().mapKeys((_, field) => field.get('name')).filter(field => field.has('default')).map(field => field.get('default'));
4
+ const defaultValues = pluginConfig.fields.toMap().mapKeys((_, field) => field.get('name')).map(field => field.get('default', ''));
5
5
  const nodeData = {
6
6
  type: 'shortcode',
7
7
  id: pluginConfig.id,