@wordpress/editor 12.5.3 → 12.5.6
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/build/components/post-text-editor/index.js +11 -0
- package/build/components/post-text-editor/index.js.map +1 -1
- package/build-module/components/post-text-editor/index.js +12 -1
- package/build-module/components/post-text-editor/index.js.map +1 -1
- package/package.json +9 -9
- package/src/components/post-text-editor/index.js +14 -1
|
@@ -43,6 +43,7 @@ function PostTextEditor() {
|
|
|
43
43
|
const [value, setValue] = (0, _element.useState)(postContent);
|
|
44
44
|
const [isDirty, setIsDirty] = (0, _element.useState)(false);
|
|
45
45
|
const instanceId = (0, _compose.useInstanceId)(PostTextEditor);
|
|
46
|
+
const valueRef = (0, _element.useRef)();
|
|
46
47
|
|
|
47
48
|
if (!isDirty && value !== postContent) {
|
|
48
49
|
setValue(postContent);
|
|
@@ -83,6 +84,16 @@ function PostTextEditor() {
|
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
|
|
87
|
+
(0, _element.useEffect)(() => {
|
|
88
|
+
valueRef.current = value;
|
|
89
|
+
}, [value]); // Ensure changes aren't lost when component unmounts.
|
|
90
|
+
|
|
91
|
+
(0, _element.useEffect)(() => {
|
|
92
|
+
return () => {
|
|
93
|
+
const blocks = (0, _blocks.parse)(valueRef.current);
|
|
94
|
+
resetEditorBlocks(blocks);
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
86
97
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.VisuallyHidden, {
|
|
87
98
|
as: "label",
|
|
88
99
|
htmlFor: `post-content-${instanceId}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["PostTextEditor","postContent","select","editorStore","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","onChange","event","newValue","target","content","stopEditing","blocks"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAMC,WAAW,GAAG,qBACjBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,oBAAtB,EADK,EAEnB,EAFmB,CAApB;AAKA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAkC,uBAAaH,YAAb,CAAxC;AAEA,QAAM,CAAEI,KAAF,EAASC,QAAT,IAAsB,uBAAUP,WAAV,CAA5B;AACA,QAAM,CAAEQ,OAAF,EAAWC,UAAX,IAA0B,uBAAU,KAAV,CAAhC;AACA,QAAMC,UAAU,GAAG,4BAAeX,cAAf,CAAnB;;AAEA,MAAK,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["PostTextEditor","postContent","select","editorStore","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","valueRef","onChange","event","newValue","target","content","stopEditing","blocks","current"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAMC,WAAW,GAAG,qBACjBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,oBAAtB,EADK,EAEnB,EAFmB,CAApB;AAKA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAkC,uBAAaH,YAAb,CAAxC;AAEA,QAAM,CAAEI,KAAF,EAASC,QAAT,IAAsB,uBAAUP,WAAV,CAA5B;AACA,QAAM,CAAEQ,OAAF,EAAWC,UAAX,IAA0B,uBAAU,KAAV,CAAhC;AACA,QAAMC,UAAU,GAAG,4BAAeX,cAAf,CAAnB;AACA,QAAMY,QAAQ,GAAG,sBA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KC,IAAA,MAAM,EAAGK,WALV;AAMC,IAAA,SAAS,EAAC,yBANX;AAOC,IAAA,EAAE,EAAI,gBAAgBP,UAAY,EAPnC;AAQC,IAAA,WAAW,EAAG,cAAI,iCAAJ;AARf,IAPD,CADD;AAoBA","sourcesContent":["/**\n * External dependencies\n */\nimport Textarea from 'react-autosize-textarea';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { parse } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { VisuallyHidden } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostTextEditor() {\n\tconst postContent = useSelect(\n\t\t( select ) => select( editorStore ).getEditedPostContent(),\n\t\t[]\n\t);\n\n\tconst { editPost, resetEditorBlocks } = useDispatch( editorStore );\n\n\tconst [ value, setValue ] = useState( postContent );\n\tconst [ isDirty, setIsDirty ] = useState( false );\n\tconst instanceId = useInstanceId( PostTextEditor );\n\tconst valueRef = useRef();\n\n\tif ( ! isDirty && value !== postContent ) {\n\t\tsetValue( postContent );\n\t}\n\n\t/**\n\t * Handles a textarea change event to notify the onChange prop callback and\n\t * reflect the new value in the component's own state. This marks the start\n\t * of the user's edits, if not already changed, preventing future props\n\t * changes to value from replacing the rendered value. This is expected to\n\t * be followed by a reset to dirty state via `stopEditing`.\n\t *\n\t * @see stopEditing\n\t *\n\t * @param {Event} event Change event.\n\t */\n\tconst onChange = ( event ) => {\n\t\tconst newValue = event.target.value;\n\t\teditPost( { content: newValue } );\n\t\tsetValue( newValue );\n\t\tsetIsDirty( true );\n\t};\n\n\t/**\n\t * Function called when the user has completed their edits, responsible for\n\t * ensuring that changes, if made, are surfaced to the onPersist prop\n\t * callback and resetting dirty state.\n\t */\n\tconst stopEditing = () => {\n\t\tif ( isDirty ) {\n\t\t\tconst blocks = parse( value );\n\t\t\tresetEditorBlocks( blocks );\n\t\t\tsetIsDirty( false );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tvalueRef.current = value;\n\t}, [ value ] );\n\n\t// Ensure changes aren't lost when component unmounts.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tconst blocks = parse( valueRef.current );\n\t\t\tresetEditorBlocks( blocks );\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<VisuallyHidden\n\t\t\t\tas=\"label\"\n\t\t\t\thtmlFor={ `post-content-${ instanceId }` }\n\t\t\t>\n\t\t\t\t{ __( 'Type text or HTML' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Textarea\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tdir=\"auto\"\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonBlur={ stopEditing }\n\t\t\t\tclassName=\"editor-post-text-editor\"\n\t\t\t\tid={ `post-content-${ instanceId }` }\n\t\t\t\tplaceholder={ __( 'Start writing with text or HTML' ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import Textarea from 'react-autosize-textarea';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
|
-
import { useState } from '@wordpress/element';
|
|
12
|
+
import { useEffect, useState, useRef } from '@wordpress/element';
|
|
13
13
|
import { parse } from '@wordpress/blocks';
|
|
14
14
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
15
15
|
import { useInstanceId } from '@wordpress/compose';
|
|
@@ -28,6 +28,7 @@ export default function PostTextEditor() {
|
|
|
28
28
|
const [value, setValue] = useState(postContent);
|
|
29
29
|
const [isDirty, setIsDirty] = useState(false);
|
|
30
30
|
const instanceId = useInstanceId(PostTextEditor);
|
|
31
|
+
const valueRef = useRef();
|
|
31
32
|
|
|
32
33
|
if (!isDirty && value !== postContent) {
|
|
33
34
|
setValue(postContent);
|
|
@@ -68,6 +69,16 @@ export default function PostTextEditor() {
|
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
valueRef.current = value;
|
|
74
|
+
}, [value]); // Ensure changes aren't lost when component unmounts.
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
return () => {
|
|
78
|
+
const blocks = parse(valueRef.current);
|
|
79
|
+
resetEditorBlocks(blocks);
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
71
82
|
return createElement(Fragment, null, createElement(VisuallyHidden, {
|
|
72
83
|
as: "label",
|
|
73
84
|
htmlFor: `post-content-${instanceId}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["Textarea","__","useState","parse","useDispatch","useSelect","useInstanceId","VisuallyHidden","store","editorStore","PostTextEditor","postContent","select","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","onChange","event","newValue","target","content","stopEditing","blocks"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,yBAArB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["Textarea","__","useEffect","useState","useRef","parse","useDispatch","useSelect","useInstanceId","VisuallyHidden","store","editorStore","PostTextEditor","postContent","select","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","valueRef","onChange","event","newValue","target","content","stopEditing","blocks","current"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,yBAArB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,EAAoBC,QAApB,EAA8BC,MAA9B,QAA4C,oBAA5C;AACA,SAASC,KAAT,QAAsB,mBAAtB;AACA,SAASC,WAAT,EAAsBC,SA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ACAT,MAAAA,UAAU,CAAE,KAAF,CAAV;AACA;AACD,GAND;;AAQAnB,EAAAA,SAAS,CAAE,MAAM;AAChBqB,IAAAA,QAAQ,CAACQ,OAAT,GAAmBb,KAAnB;AACA,GAFQ,EAEN,CAAEA,KAAF,CAFM,CAAT,CAhDwC,CAoDxC;;AACAhB,EAAAA,SAAS,CAAE,MAAM;AAChB,WAAO,MAAM;AACZ,YAAM4B,MAAM,GAAGzB,KAAK,CAAEkB,QAAQ,CAACQ,OAAX,CAApB;AACAd,MAAAA,iBAAiB,CAAEa,MAAF,CAAjB;AACA,KAHD;AAIA,GALQ,EAKN,EALM,CAAT;AAOA,SACC,8BACC,cAAC,cAAD;AACC,IAAA,EAAE,EAAC,OADJ;AAEC,IAAA,OAAO,EAAI,gBAAgBR,UAAY;AAFxC,KAIGrB,EAAE,CAAE,mBAAF,CAJL,CADD,EAOC,cAAC,QAAD;AACC,IAAA,YAAY,EAAC,KADd;AAEC,IAAA,GAAG,EAAC,MAFL;AAGC,IAAA,KAAK,EAAGiB,KAHT;AAIC,IAAA,QAAQ,EAAGM,QAJZ;AAKC,IAAA,MAAM,EAAGK,WALV;AAMC,IAAA,SAAS,EAAC,yBANX;AAOC,IAAA,EAAE,EAAI,gBAAgBP,UAAY,EAPnC;AAQC,IAAA,WAAW,EAAGrB,EAAE,CAAE,iCAAF;AARjB,IAPD,CADD;AAoBA","sourcesContent":["/**\n * External dependencies\n */\nimport Textarea from 'react-autosize-textarea';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { parse } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { VisuallyHidden } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostTextEditor() {\n\tconst postContent = useSelect(\n\t\t( select ) => select( editorStore ).getEditedPostContent(),\n\t\t[]\n\t);\n\n\tconst { editPost, resetEditorBlocks } = useDispatch( editorStore );\n\n\tconst [ value, setValue ] = useState( postContent );\n\tconst [ isDirty, setIsDirty ] = useState( false );\n\tconst instanceId = useInstanceId( PostTextEditor );\n\tconst valueRef = useRef();\n\n\tif ( ! isDirty && value !== postContent ) {\n\t\tsetValue( postContent );\n\t}\n\n\t/**\n\t * Handles a textarea change event to notify the onChange prop callback and\n\t * reflect the new value in the component's own state. This marks the start\n\t * of the user's edits, if not already changed, preventing future props\n\t * changes to value from replacing the rendered value. This is expected to\n\t * be followed by a reset to dirty state via `stopEditing`.\n\t *\n\t * @see stopEditing\n\t *\n\t * @param {Event} event Change event.\n\t */\n\tconst onChange = ( event ) => {\n\t\tconst newValue = event.target.value;\n\t\teditPost( { content: newValue } );\n\t\tsetValue( newValue );\n\t\tsetIsDirty( true );\n\t};\n\n\t/**\n\t * Function called when the user has completed their edits, responsible for\n\t * ensuring that changes, if made, are surfaced to the onPersist prop\n\t * callback and resetting dirty state.\n\t */\n\tconst stopEditing = () => {\n\t\tif ( isDirty ) {\n\t\t\tconst blocks = parse( value );\n\t\t\tresetEditorBlocks( blocks );\n\t\t\tsetIsDirty( false );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tvalueRef.current = value;\n\t}, [ value ] );\n\n\t// Ensure changes aren't lost when component unmounts.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tconst blocks = parse( valueRef.current );\n\t\t\tresetEditorBlocks( blocks );\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<VisuallyHidden\n\t\t\t\tas=\"label\"\n\t\t\t\thtmlFor={ `post-content-${ instanceId }` }\n\t\t\t>\n\t\t\t\t{ __( 'Type text or HTML' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Textarea\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tdir=\"auto\"\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonBlur={ stopEditing }\n\t\t\t\tclassName=\"editor-post-text-editor\"\n\t\t\t\tid={ `post-content-${ instanceId }` }\n\t\t\t\tplaceholder={ __( 'Start writing with text or HTML' ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/editor",
|
|
3
|
-
"version": "12.5.
|
|
3
|
+
"version": "12.5.6",
|
|
4
4
|
"description": "Enhanced block editor for WordPress posts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"@babel/runtime": "^7.16.0",
|
|
34
34
|
"@wordpress/a11y": "^3.6.1",
|
|
35
35
|
"@wordpress/api-fetch": "^6.3.1",
|
|
36
|
-
"@wordpress/block-editor": "^8.5.
|
|
36
|
+
"@wordpress/block-editor": "^8.5.6",
|
|
37
37
|
"@wordpress/blocks": "^11.5.3",
|
|
38
|
-
"@wordpress/components": "^19.8.
|
|
38
|
+
"@wordpress/components": "^19.8.4",
|
|
39
39
|
"@wordpress/compose": "^5.4.1",
|
|
40
|
-
"@wordpress/core-data": "^4.4.
|
|
40
|
+
"@wordpress/core-data": "^4.4.5",
|
|
41
41
|
"@wordpress/data": "^6.6.1",
|
|
42
42
|
"@wordpress/date": "^4.6.1",
|
|
43
43
|
"@wordpress/deprecated": "^3.6.1",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"@wordpress/keycodes": "^3.6.1",
|
|
51
51
|
"@wordpress/media-utils": "^3.4.1",
|
|
52
52
|
"@wordpress/notices": "^3.6.1",
|
|
53
|
-
"@wordpress/preferences": "^1.2.
|
|
54
|
-
"@wordpress/reusable-blocks": "^3.4.
|
|
55
|
-
"@wordpress/rich-text": "^5.4.
|
|
56
|
-
"@wordpress/server-side-render": "^3.4.
|
|
53
|
+
"@wordpress/preferences": "^1.2.4",
|
|
54
|
+
"@wordpress/reusable-blocks": "^3.4.6",
|
|
55
|
+
"@wordpress/rich-text": "^5.4.2",
|
|
56
|
+
"@wordpress/server-side-render": "^3.4.5",
|
|
57
57
|
"@wordpress/url": "^3.7.1",
|
|
58
58
|
"@wordpress/wordcount": "^3.6.1",
|
|
59
59
|
"classnames": "^2.3.1",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "89fbea298119228eea3ebdc8d30e87033a497f43"
|
|
73
73
|
}
|
|
@@ -7,7 +7,7 @@ import Textarea from 'react-autosize-textarea';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
|
-
import { useState } from '@wordpress/element';
|
|
10
|
+
import { useEffect, useState, useRef } from '@wordpress/element';
|
|
11
11
|
import { parse } from '@wordpress/blocks';
|
|
12
12
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
13
13
|
import { useInstanceId } from '@wordpress/compose';
|
|
@@ -29,6 +29,7 @@ export default function PostTextEditor() {
|
|
|
29
29
|
const [ value, setValue ] = useState( postContent );
|
|
30
30
|
const [ isDirty, setIsDirty ] = useState( false );
|
|
31
31
|
const instanceId = useInstanceId( PostTextEditor );
|
|
32
|
+
const valueRef = useRef();
|
|
32
33
|
|
|
33
34
|
if ( ! isDirty && value !== postContent ) {
|
|
34
35
|
setValue( postContent );
|
|
@@ -65,6 +66,18 @@ export default function PostTextEditor() {
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
|
|
69
|
+
useEffect( () => {
|
|
70
|
+
valueRef.current = value;
|
|
71
|
+
}, [ value ] );
|
|
72
|
+
|
|
73
|
+
// Ensure changes aren't lost when component unmounts.
|
|
74
|
+
useEffect( () => {
|
|
75
|
+
return () => {
|
|
76
|
+
const blocks = parse( valueRef.current );
|
|
77
|
+
resetEditorBlocks( blocks );
|
|
78
|
+
};
|
|
79
|
+
}, [] );
|
|
80
|
+
|
|
68
81
|
return (
|
|
69
82
|
<>
|
|
70
83
|
<VisuallyHidden
|