@contentful/field-editor-markdown 1.5.1 → 1.5.3

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.
@@ -81,7 +81,8 @@ const styles = {
81
81
  })
82
82
  };
83
83
  function MarkdownEditor(props) {
84
- const [currentValue, setCurrentValue] = _react.useState(props.initialValue ?? '');
84
+ const prevExternalReset = _react.useRef(props.externalReset);
85
+ const [currentValue, setCurrentValue] = _react.useState(props.value ?? '');
85
86
  const [selectedTab, setSelectedTab] = _react.useState('editor');
86
87
  const [editor, setEditor] = _react.useState(null);
87
88
  const [canUploadAssets, setCanUploadAssets] = _react.useState(false);
@@ -108,6 +109,16 @@ function MarkdownEditor(props) {
108
109
  editor,
109
110
  props.disabled
110
111
  ]);
112
+ _react.useEffect(()=>{
113
+ if (props.externalReset !== prevExternalReset.current) {
114
+ prevExternalReset.current = props.externalReset;
115
+ editor?.setContent(props.value ?? '');
116
+ }
117
+ }, [
118
+ props.value,
119
+ props.externalReset,
120
+ editor
121
+ ]);
111
122
  const isActionDisabled = editor === null || props.disabled || selectedTab !== 'editor';
112
123
  const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
113
124
  const actions = _react.useMemo(()=>{
@@ -142,7 +153,7 @@ function MarkdownEditor(props) {
142
153
  disabled: isActionDisabled,
143
154
  direction: direction,
144
155
  onReady: (editor)=>{
145
- editor.setContent(props.initialValue ?? '');
156
+ editor.setContent(props.value ?? '');
146
157
  editor.setReadOnly(props.disabled);
147
158
  setEditor(editor);
148
159
  editor.events.onChange((value)=>{
@@ -172,13 +183,11 @@ function MarkdownEditorConnected(props) {
172
183
  debounce: 300,
173
184
  field: props.sdk.field,
174
185
  isInitiallyDisabled: props.isInitiallyDisabled
175
- }, ({ value , disabled , setValue , externalReset })=>{
176
- return _react.createElement(MarkdownEditor, {
186
+ }, ({ value , disabled , setValue , externalReset })=>_react.createElement(MarkdownEditor, {
177
187
  ...props,
178
- key: `markdown-editor-${externalReset}`,
179
- initialValue: value,
188
+ value: value,
180
189
  disabled: disabled,
181
- saveValueToSDK: setValue
182
- });
183
- });
190
+ saveValueToSDK: setValue,
191
+ externalReset: externalReset
192
+ }));
184
193
  }
@@ -19,7 +19,8 @@ const styles = {
19
19
  })
20
20
  };
21
21
  export function MarkdownEditor(props) {
22
- const [currentValue, setCurrentValue] = React.useState(props.initialValue ?? '');
22
+ const prevExternalReset = React.useRef(props.externalReset);
23
+ const [currentValue, setCurrentValue] = React.useState(props.value ?? '');
23
24
  const [selectedTab, setSelectedTab] = React.useState('editor');
24
25
  const [editor, setEditor] = React.useState(null);
25
26
  const [canUploadAssets, setCanUploadAssets] = React.useState(false);
@@ -46,6 +47,16 @@ export function MarkdownEditor(props) {
46
47
  editor,
47
48
  props.disabled
48
49
  ]);
50
+ React.useEffect(()=>{
51
+ if (props.externalReset !== prevExternalReset.current) {
52
+ prevExternalReset.current = props.externalReset;
53
+ editor?.setContent(props.value ?? '');
54
+ }
55
+ }, [
56
+ props.value,
57
+ props.externalReset,
58
+ editor
59
+ ]);
49
60
  const isActionDisabled = editor === null || props.disabled || selectedTab !== 'editor';
50
61
  const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
51
62
  const actions = React.useMemo(()=>{
@@ -80,7 +91,7 @@ export function MarkdownEditor(props) {
80
91
  disabled: isActionDisabled,
81
92
  direction: direction,
82
93
  onReady: (editor)=>{
83
- editor.setContent(props.initialValue ?? '');
94
+ editor.setContent(props.value ?? '');
84
95
  editor.setReadOnly(props.disabled);
85
96
  setEditor(editor);
86
97
  editor.events.onChange((value)=>{
@@ -110,13 +121,11 @@ export function MarkdownEditorConnected(props) {
110
121
  debounce: 300,
111
122
  field: props.sdk.field,
112
123
  isInitiallyDisabled: props.isInitiallyDisabled
113
- }, ({ value , disabled , setValue , externalReset })=>{
114
- return React.createElement(MarkdownEditor, {
124
+ }, ({ value , disabled , setValue , externalReset })=>React.createElement(MarkdownEditor, {
115
125
  ...props,
116
- key: `markdown-editor-${externalReset}`,
117
- initialValue: value,
126
+ value: value,
118
127
  disabled: disabled,
119
- saveValueToSDK: setValue
120
- });
121
- });
128
+ saveValueToSDK: setValue,
129
+ externalReset: externalReset
130
+ }));
122
131
  }
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { FieldExtensionSDK } from '@contentful/app-sdk';
2
+ import { FieldAppSDK } from '@contentful/app-sdk';
3
3
  import { PreviewComponents } from './types';
4
4
  export interface MarkdownEditorProps {
5
5
  /**
@@ -10,13 +10,14 @@ export interface MarkdownEditorProps {
10
10
  * Minimum height to set for the markdown text area and preview
11
11
  */
12
12
  minHeight?: string | number;
13
- sdk: FieldExtensionSDK;
13
+ sdk: FieldAppSDK;
14
14
  previewComponents?: PreviewComponents;
15
15
  onReady?: Function;
16
16
  }
17
17
  export declare function MarkdownEditor(props: MarkdownEditorProps & {
18
18
  disabled: boolean;
19
- initialValue: string | null | undefined;
19
+ value: string | null | undefined;
20
20
  saveValueToSDK: Function;
21
+ externalReset?: number;
21
22
  }): React.JSX.Element;
22
23
  export declare function MarkdownEditorConnected(props: MarkdownEditorProps): React.JSX.Element;
@@ -1,8 +1,8 @@
1
- import { FieldExtensionSDK } from '@contentful/app-sdk';
1
+ import { FieldAppSDK } from '@contentful/app-sdk';
2
2
  import { Emitter } from 'mitt';
3
3
  export type ReferenceEditorSdkProps = {
4
4
  initialValue?: any;
5
5
  validations?: any;
6
6
  fetchDelay?: number;
7
7
  };
8
- export declare function newReferenceEditorFakeSdk(props?: ReferenceEditorSdkProps): [FieldExtensionSDK, Emitter];
8
+ export declare function newReferenceEditorFakeSdk(props?: ReferenceEditorSdkProps): [FieldAppSDK, Emitter];
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { FieldExtensionSDK } from '@contentful/app-sdk';
2
+ import { FieldAppSDK } from '@contentful/app-sdk';
3
3
  export declare function MarkdownConstraints(props: {
4
- sdk: FieldExtensionSDK;
4
+ sdk: FieldAppSDK;
5
5
  value: string;
6
6
  }): React.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { DialogExtensionSDK, DialogsAPI } from '@contentful/app-sdk';
2
+ import { DialogAppSDK, DialogsAPI } from '@contentful/app-sdk';
3
3
  import { PreviewComponents } from '../types';
4
4
  export type ZenModeResult = {
5
5
  value: string;
@@ -13,7 +13,7 @@ type ZenModeDialogProps = {
13
13
  onClose: (result: ZenModeResult) => void;
14
14
  initialValue: string;
15
15
  locale: string;
16
- sdk: DialogExtensionSDK;
16
+ sdk: DialogAppSDK;
17
17
  previewComponents?: PreviewComponents;
18
18
  };
19
19
  export declare const ZenModeModalDialog: (props: ZenModeDialogProps) => React.JSX.Element;
@@ -1,5 +1,5 @@
1
- import { FieldExtensionSDK, OpenCustomWidgetOptions } from '@contentful/app-sdk';
1
+ import { FieldAppSDK, OpenCustomWidgetOptions } from '@contentful/app-sdk';
2
2
  import { MarkdownDialogsParams, PreviewComponents } from '../types';
3
- export declare const openMarkdownDialog: (sdk: FieldExtensionSDK, previewComponents?: PreviewComponents) => (options: OpenCustomWidgetOptions & {
3
+ export declare const openMarkdownDialog: (sdk: FieldAppSDK, previewComponents?: PreviewComponents) => (options: OpenCustomWidgetOptions & {
4
4
  parameters?: MarkdownDialogsParams;
5
5
  }) => Promise<unknown>;
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
- import { DialogExtensionSDK } from '@contentful/app-sdk';
2
+ import { DialogAppSDK } from '@contentful/app-sdk';
3
3
  import { MarkdownDialogsParams } from '../types';
4
- export declare const renderMarkdownDialog: (sdk: DialogExtensionSDK & {
4
+ export declare const renderMarkdownDialog: (sdk: DialogAppSDK & {
5
5
  parameters: {
6
6
  invocation: MarkdownDialogsParams;
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-markdown",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "@contentful/f36-components": "^4.0.27",
39
39
  "@contentful/f36-icons": "^4.1.0",
40
40
  "@contentful/f36-tokens": "^4.0.0",
41
- "@contentful/field-editor-shared": "^1.4.1",
41
+ "@contentful/field-editor-shared": "^1.4.2",
42
42
  "@types/codemirror": "0.0.109",
43
43
  "codemirror": "^5.65.11",
44
44
  "constate": "^3.2.0",
@@ -51,12 +51,12 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@babel/core": "^7.5.5",
54
- "@contentful/app-sdk": "^4.2.0",
55
- "@contentful/field-editor-test-utils": "^1.4.2"
54
+ "@contentful/app-sdk": "^4.17.1",
55
+ "@contentful/field-editor-test-utils": "^1.4.3"
56
56
  },
57
57
  "peerDependencies": {
58
- "@contentful/app-sdk": "^4.2.0",
58
+ "@contentful/app-sdk": "^4.17.1",
59
59
  "react": ">=16.8.0"
60
60
  },
61
- "gitHead": "0fc8da4aa8ad8603c3adf4bd77b26ba46de11e33"
61
+ "gitHead": "a237d46db90c24005efb544b1f256f86414cbc70"
62
62
  }