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.
- package/CHANGELOG.md +10 -0
- package/dist/decap-cms-widget-markdown.js +4 -4
- package/dist/decap-cms-widget-markdown.js.LICENSE.txt +1 -1
- package/dist/decap-cms-widget-markdown.js.map +1 -1
- package/dist/esm/MarkdownControl/index.js +14 -2
- package/dist/esm/MarkdownControl/plugins/html/withHtml.js +1 -1
- package/dist/esm/MarkdownControl/plugins/shortcodes/insertShortcode.js +1 -1
- package/dist/esm/MarkdownControl/renderers.js +19 -19
- package/dist/esm/serializers/index.js +19 -3
- package/dist/esm/serializers/remarkRehypeShortcodes.js +26 -3
- package/package.json +4 -3
- package/src/MarkdownControl/index.js +13 -2
- package/src/MarkdownControl/plugins/html/withHtml.js +1 -1
- package/src/MarkdownControl/plugins/shortcodes/insertShortcode.js +1 -2
- package/src/MarkdownControl/renderers.js +1 -1
- package/src/serializers/__tests__/index.spec.js +15 -0
- package/src/serializers/index.js +19 -1
- package/src/serializers/remarkRehypeShortcodes.js +32 -3
|
@@ -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:
|
|
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
|
|
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
|
|
@@ -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')).
|
|
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,
|