@wordpress/editor 13.8.0 → 13.10.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/entities-saved-states/index.js +59 -13
  3. package/build/components/entities-saved-states/index.js.map +1 -1
  4. package/build/components/post-featured-image/index.js +24 -29
  5. package/build/components/post-featured-image/index.js.map +1 -1
  6. package/build/components/post-saved-state/index.js +0 -8
  7. package/build/components/post-saved-state/index.js.map +1 -1
  8. package/build/components/post-switch-to-draft-button/index.js +9 -4
  9. package/build/components/post-switch-to-draft-button/index.js.map +1 -1
  10. package/build/components/post-template/index.js +1 -7
  11. package/build/components/post-template/index.js.map +1 -1
  12. package/build/components/post-title/index.native.js +41 -11
  13. package/build/components/post-title/index.native.js.map +1 -1
  14. package/build/hooks/custom-sources-backwards-compatibility.js +2 -8
  15. package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
  16. package/build-module/components/entities-saved-states/index.js +60 -13
  17. package/build-module/components/entities-saved-states/index.js.map +1 -1
  18. package/build-module/components/post-featured-image/index.js +26 -32
  19. package/build-module/components/post-featured-image/index.js.map +1 -1
  20. package/build-module/components/post-saved-state/index.js +0 -7
  21. package/build-module/components/post-saved-state/index.js.map +1 -1
  22. package/build-module/components/post-switch-to-draft-button/index.js +12 -7
  23. package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
  24. package/build-module/components/post-template/index.js +1 -6
  25. package/build-module/components/post-template/index.js.map +1 -1
  26. package/build-module/components/post-title/index.native.js +41 -11
  27. package/build-module/components/post-title/index.native.js.map +1 -1
  28. package/build-module/hooks/custom-sources-backwards-compatibility.js +2 -7
  29. package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
  30. package/build-style/style-rtl.css +37 -15
  31. package/build-style/style.css +37 -15
  32. package/package.json +31 -32
  33. package/src/components/entities-saved-states/index.js +65 -21
  34. package/src/components/post-featured-image/index.js +26 -35
  35. package/src/components/post-featured-image/style.scss +38 -14
  36. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +3 -1
  37. package/src/components/post-saved-state/index.js +0 -7
  38. package/src/components/post-saved-state/test/__snapshots__/index.js.snap +0 -9
  39. package/src/components/post-saved-state/test/index.js +0 -10
  40. package/src/components/post-switch-to-draft-button/index.js +7 -6
  41. package/src/components/post-taxonomies/style.scss +4 -4
  42. package/src/components/post-template/index.js +5 -6
  43. package/src/components/post-title/index.native.js +31 -8
  44. package/src/components/post-trash/style.scss +1 -3
  45. package/src/hooks/custom-sources-backwards-compatibility.js +2 -7
@@ -46,6 +46,7 @@ class PostTitle extends _element.Component {
46
46
  constructor(props) {
47
47
  super(props);
48
48
  this.setRef = this.setRef.bind(this);
49
+ this.onPaste = this.onPaste.bind(this);
49
50
  }
50
51
 
51
52
  componentDidUpdate(prevProps) {
@@ -77,19 +78,35 @@ class PostTitle extends _element.Component {
77
78
  let {
78
79
  value,
79
80
  onChange,
80
- plainText
81
+ plainText,
82
+ html
81
83
  } = _ref;
84
+ const {
85
+ title,
86
+ onInsertBlockAfter,
87
+ onUpdate
88
+ } = this.props;
82
89
  const content = (0, _blocks.pasteHandler)({
83
- plainText,
84
- mode: 'INLINE',
85
- tagName: 'p'
90
+ HTML: html,
91
+ plainText
86
92
  });
87
93
 
88
- if (typeof content === 'string') {
89
- const valueToInsert = (0, _richText.create)({
90
- html: content
91
- });
92
- onChange((0, _richText.insert)(value, valueToInsert));
94
+ if (content.length) {
95
+ if (typeof content === 'string') {
96
+ const valueToInsert = (0, _richText.create)({
97
+ html: content
98
+ });
99
+ onChange((0, _richText.insert)(value, valueToInsert));
100
+ } else {
101
+ const [firstBlock] = content;
102
+
103
+ if (!title && (firstBlock.name === 'core/heading' || firstBlock.name === 'core/paragraph')) {
104
+ onUpdate(firstBlock.attributes.content);
105
+ onInsertBlockAfter(content.slice(1));
106
+ } else {
107
+ onInsertBlockAfter(content);
108
+ }
109
+ }
93
110
  }
94
111
  }
95
112
 
@@ -188,6 +205,7 @@ var _default = (0, _compose.compose)((0, _data.withSelect)(select => {
188
205
  const globalStyles = (_getSettings = getSettings()) === null || _getSettings === void 0 ? void 0 : (_getSettings$__experi = _getSettings.__experimentalGlobalStylesBaseStyles) === null || _getSettings$__experi === void 0 ? void 0 : _getSettings$__experi.color;
189
206
  return {
190
207
  postType: getEditedPostAttribute('type'),
208
+ title: getEditedPostAttribute('title'),
191
209
  isAnyBlockSelected: !!selectedId,
192
210
  isSelected: isPostTitleSelected(),
193
211
  isDimmed: selectionIsNested,
@@ -197,11 +215,13 @@ var _default = (0, _compose.compose)((0, _data.withSelect)(select => {
197
215
  const {
198
216
  undo,
199
217
  redo,
200
- togglePostTitleSelection
218
+ togglePostTitleSelection,
219
+ editPost
201
220
  } = dispatch(_editor.store);
202
221
  const {
203
222
  clearSelectedBlock,
204
- insertDefaultBlock
223
+ insertDefaultBlock,
224
+ insertBlocks
205
225
  } = dispatch(_blockEditor.store);
206
226
  return {
207
227
  onEnterPress() {
@@ -218,6 +238,16 @@ var _default = (0, _compose.compose)((0, _data.withSelect)(select => {
218
238
 
219
239
  onUnselect() {
220
240
  togglePostTitleSelection(false);
241
+ },
242
+
243
+ onUpdate(title) {
244
+ editPost({
245
+ title
246
+ });
247
+ },
248
+
249
+ onInsertBlockAfter(blocks) {
250
+ insertBlocks(blocks, 0);
221
251
  }
222
252
 
223
253
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"names":["PostTitle","Component","constructor","props","setRef","bind","componentDidUpdate","prevProps","isSelected","isAnyBlockSelected","richTextRef","blur","onUnselect","componentDidMount","innerRef","handleFocusOutside","focus","onSelect","onPaste","value","onChange","plainText","content","mode","tagName","valueToInsert","html","richText","getTitle","title","postType","render","placeholder","style","focusedBorderColor","borderStyle","isDimmed","globalStyles","decodedPlaceholder","borderColor","titleStyles","text","color","placeholderColor","styles","titleContainer","dimmed","onBlur","onUpdate","onEnterPress","select","isPostTitleSelected","getEditedPostAttribute","editorStore","getSelectedBlockClientId","getBlockRootClientId","getSettings","blockEditorStore","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","dispatch","undo","redo","togglePostTitleSelection","clearSelectedBlock","insertDefaultBlock","undefined","onUndo","onRedo","withInstanceId","withFocusOutside"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AA1BA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AAGA,MAAMA,SAAN,SAAwBC,kBAAxB,CAAkC;AACjCC,EAAAA,WAAW,CAAEC,KAAF,EAAU;AACpB,UAAOA,KAAP;AAEA,SAAKC,MAAL,GAAc,KAAKA,MAAL,CAAYC,IAAZ,CAAkB,IAAlB,CAAd;AACA;;AACDC,EAAAA,kBAAkB,CAAEC,SAAF,EAAc;AAC/B;AACA,QACC,KAAKJ,KAAL,CAAWK,UAAX,IACA,CAAED,SAAS,CAACE,kBADZ,IAEA,KAAKN,KAAL,CAAWM,kBAHZ,EAIE;AACD,UAAK,KAAKC,WAAV,EAAwB;AACvB,aAAKA,WAAL,CAAiBC,IAAjB;AACA;;AACD,WAAKR,KAAL,CAAWS,UAAX;AACA;AACD;;AAEDC,EAAAA,iBAAiB,GAAG;AACnB,QAAK,KAAKV,KAAL,CAAWW,QAAhB,EAA2B;AAC1B,WAAKX,KAAL,CAAWW,QAAX,CAAqB,IAArB;AACA;AACD;;AAEDC,EAAAA,kBAAkB,GAAG;AACpB,SAAKZ,KAAL,CAAWS,UAAX;AACA;;AAEDI,EAAAA,KAAK,GAAG;AACP,SAAKb,KAAL,CAAWc,QAAX;AACA;;AAEDC,EAAAA,OAAO,OAAmC;AAAA,QAAjC;AAAEC,MAAAA,KAAF;AAASC,MAAAA,QAAT;AAAmBC,MAAAA;AAAnB,KAAiC;AACzC,UAAMC,OAAO,GAAG,0BAAc;AAC7BD,MAAAA,SAD6B;AAE7BE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B,CAAlB;AACA,KAHK;;AAINC,IAAAA,MAAM,EAAEN,IAJF;AAKNO,IAAAA,MAAM,EAAEN,IALF;;AAMN9C,IAAAA,QAAQ,GAAG;AACV+C,MAAAA,wBAAwB,CAAE,IAAF,CAAxB;AACAC,MAAAA,kBAAkB;AAClB,KATK;;AAUNrD,IAAAA,UAAU,GAAG;AACZoD,MAAAA,wBAAwB,CAAE,KAAF,CAAxB;AACA;;AAZK,GAAP;AAcA,CArBD,CApBc,EA0CdM,uBA1Cc,EA2CdC,4BA3Cc,EA4CZvE,SA5CY,C","sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport {\n\t__experimentalRichText as RichText,\n\tcreate,\n\tinsert,\n} from '@wordpress/rich-text';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { withDispatch, withSelect } from '@wordpress/data';\nimport { withFocusOutside } from '@wordpress/components';\nimport { withInstanceId, compose } from '@wordpress/compose';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { pasteHandler } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nclass PostTitle extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.setRef = this.setRef.bind( this );\n\t}\n\tcomponentDidUpdate( prevProps ) {\n\t\t// Unselect if any other block is selected and blur the RichText.\n\t\tif (\n\t\t\tthis.props.isSelected &&\n\t\t\t! prevProps.isAnyBlockSelected &&\n\t\t\tthis.props.isAnyBlockSelected\n\t\t) {\n\t\t\tif ( this.richTextRef ) {\n\t\t\t\tthis.richTextRef.blur();\n\t\t\t}\n\t\t\tthis.props.onUnselect();\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.props.innerRef ) {\n\t\t\tthis.props.innerRef( this );\n\t\t}\n\t}\n\n\thandleFocusOutside() {\n\t\tthis.props.onUnselect();\n\t}\n\n\tfocus() {\n\t\tthis.props.onSelect();\n\t}\n\n\tonPaste( { value, onChange, plainText } ) {\n\t\tconst content = pasteHandler( {\n\t\t\tplainText,\n\t\t\tmode: 'INLINE',\n\t\t\ttagName: 'p',\n\t\t} );\n\n\t\tif ( typeof content === 'string' ) {\n\t\t\tconst valueToInsert = create( { html: content } );\n\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t}\n\t}\n\n\tsetRef( richText ) {\n\t\tthis.richTextRef = richText;\n\t}\n\n\tgetTitle( title, postType ) {\n\t\tif ( 'page' === postType ) {\n\t\t\treturn ! title\n\t\t\t\t? /* translators: accessibility text. empty page title. */\n\t\t\t\t __( 'Page title. Empty' )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: text content of the page title. */\n\t\t\t\t\t\t__( 'Page title. %s' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t );\n\t\t}\n\n\t\treturn ! title\n\t\t\t? /* translators: accessibility text. empty post title. */\n\t\t\t __( 'Post title. Empty' )\n\t\t\t: sprintf(\n\t\t\t\t\t/* translators: accessibility text. %s: text content of the post title. */\n\t\t\t\t\t__( 'Post title. %s' ),\n\t\t\t\t\ttitle\n\t\t\t );\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tplaceholder,\n\t\t\tstyle,\n\t\t\ttitle,\n\t\t\tfocusedBorderColor,\n\t\t\tborderStyle,\n\t\t\tisDimmed,\n\t\t\tpostType,\n\t\t\tglobalStyles,\n\t\t} = this.props;\n\n\t\tconst decodedPlaceholder = decodeEntities( placeholder );\n\t\tconst borderColor = this.props.isSelected\n\t\t\t? focusedBorderColor\n\t\t\t: 'transparent';\n\t\tconst titleStyles = {\n\t\t\t...style,\n\t\t\t...( globalStyles?.text && {\n\t\t\t\tcolor: globalStyles.text,\n\t\t\t\tplaceholderColor: globalStyles.text,\n\t\t\t} ),\n\t\t};\n\n\t\treturn (\n\t\t\t<View\n\t\t\t\ttestID=\"post-title\"\n\t\t\t\tstyle={ [\n\t\t\t\t\tstyles.titleContainer,\n\t\t\t\t\tborderStyle,\n\t\t\t\t\t{ borderColor },\n\t\t\t\t\tisDimmed && styles.dimmed,\n\t\t\t\t] }\n\t\t\t\taccessible={ ! this.props.isSelected }\n\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\taccessibilityHint={ __( 'Updates the title.' ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\tsetRef={ this.setRef }\n\t\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\t\ttagName={ 'p' }\n\t\t\t\t\ttagsToEliminate={ [ 'strong' ] }\n\t\t\t\t\tunstableOnFocus={ this.props.onSelect }\n\t\t\t\t\tonBlur={ this.props.onBlur } // Always assign onBlur as a props.\n\t\t\t\t\tmultiline={ false }\n\t\t\t\t\tstyle={ titleStyles }\n\t\t\t\t\tstyles={ styles }\n\t\t\t\t\tfontSize={ 24 }\n\t\t\t\t\tlineHeight={ 1 }\n\t\t\t\t\tfontWeight={ 'bold' }\n\t\t\t\t\tdeleteEnter={ true }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tthis.props.onUpdate( value );\n\t\t\t\t\t} }\n\t\t\t\t\tonPaste={ this.onPaste }\n\t\t\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonSelectionChange={ () => {} }\n\t\t\t\t\tonEnter={ this.props.onEnterPress }\n\t\t\t\t\tdisableEditingMenu={ true }\n\t\t\t\t\t__unstableIsSelected={ this.props.isSelected }\n\t\t\t\t\t__unstableOnCreateUndoLevel={ () => {} }\n\t\t\t\t></RichText>\n\t\t\t</View>\n\t\t);\n\t}\n}\n\nexport default compose(\n\twithSelect( ( select ) => {\n\t\tconst { isPostTitleSelected, getEditedPostAttribute } =\n\t\t\tselect( editorStore );\n\t\tconst { getSelectedBlockClientId, getBlockRootClientId, getSettings } =\n\t\t\tselect( blockEditorStore );\n\n\t\tconst selectedId = getSelectedBlockClientId();\n\t\tconst selectionIsNested = !! getBlockRootClientId( selectedId );\n\t\tconst globalStyles =\n\t\t\tgetSettings()?.__experimentalGlobalStylesBaseStyles?.color;\n\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\tisAnyBlockSelected: !! selectedId,\n\t\t\tisSelected: isPostTitleSelected(),\n\t\t\tisDimmed: selectionIsNested,\n\t\t\tglobalStyles,\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { undo, redo, togglePostTitleSelection } =\n\t\t\tdispatch( editorStore );\n\n\t\tconst { clearSelectedBlock, insertDefaultBlock } =\n\t\t\tdispatch( blockEditorStore );\n\n\t\treturn {\n\t\t\tonEnterPress() {\n\t\t\t\tinsertDefaultBlock( undefined, undefined, 0 );\n\t\t\t},\n\t\t\tonUndo: undo,\n\t\t\tonRedo: redo,\n\t\t\tonSelect() {\n\t\t\t\ttogglePostTitleSelection( true );\n\t\t\t\tclearSelectedBlock();\n\t\t\t},\n\t\t\tonUnselect() {\n\t\t\t\ttogglePostTitleSelection( false );\n\t\t\t},\n\t\t};\n\t} ),\n\twithInstanceId,\n\twithFocusOutside\n)( PostTitle );\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"names":["PostTitle","Component","constructor","props","setRef","bind","onPaste","componentDidUpdate","prevProps","isSelected","isAnyBlockSelected","richTextRef","blur","onUnselect","componentDidMount","innerRef","handleFocusOutside","focus","onSelect","value","onChange","plainText","html","title","onInsertBlockAfter","onUpdate","content","HTML","length","valueToInsert","firstBlock","name","attributes","slice","richText","getTitle","postType","render","placeholder","style","focusedBorderColor","borderStyle","isDimmed","globalStyles","decodedPlaceholder","borderColor","titleStyles","text","color","placeholderColor","styles","titleContainer","dimmed","onBlur","onEnterPress","select","isPostTitleSelected","getEditedPostAttribute","editorStore","getSelectedBlockClientId","getBlockRootClientId","getSettings","blockEditorStore","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","dispatch","undo","redo","togglePostTitleSelection","editPost","clearSelectedBlock","insertDefaultBlock","insertBlocks","undefined","onUndo","onRedo","blocks","withInstanceId","withFocusOutside"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AA1BA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AAGA,MAAMA,SAAN,SAAwBC,kBAAxB,CAAkC;AACjCC,EAAAA,WAAW,CAAEC,KAAF,EAAU;AACpB,UAAOA,KAAP;AAEA,SAAKC,MAAL,GAAc,KAAKA,MAAL,CAAYC,IAAZ,CAAkB,IAAlB,CAAd;AACA,SAAKC,OAAL,GAAe,KAAKA,OAAL,CAAaD,IAAb,CAAmB,IAAnB,CAAf;AACA;;AACDE,EAAAA,kBAAkB,CAAEC,SAAF,EAAc;AAC/B;AACA,QACC,KAAKL,KAAL,CAAWM,UAAX,IACA,CAAED,SAAS,CAACE,kBADZ,IAEA,KAAKP,KAAL,CAAWO,kBAHZ,EAIE;AACD,UAAK,KAAKC,WAAV,EAAwB;AACvB,aAAKA,WAAL,CAAiBC,IAAjB;AACA;;AACD,WAAKT,KAAL,CAAWU,UAAX;AACA;AACD;;AAEDC,EAAAA,iBAAiB,GAAG;AACnB,QAAK,KAAKX,KAAL,CAAWY,QAAhB,EAA2B;AAC1B,WAAKZ,KAAL,CAAWY,QAAX,CAAqB,IAArB;AACA;AACD;;AAEDC,EAAAA,kBAAkB,GAAG;AACpB,SAAKb,KAAL,CAAWU,UAAX;AACA;;AAEDI,EAAAA,KAAK,GAAG;AACP,SAAKd,KAAL,CAAWe,QAAX;AACA;;AAEDZ,EAAAA,OAAO,OAAyC;AAAA,QAAvC;AAAEa,MAAAA,KAAF;AAASC,MAAAA,QAAT;AAAmBC,MAAAA,SAAnB;AAA8BC,MAAAA;AAA9B,KAAuC;AAC/C,UAAM;AAAEC,MAA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encies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport {\n\t__experimentalRichText as RichText,\n\tcreate,\n\tinsert,\n} from '@wordpress/rich-text';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { withDispatch, withSelect } from '@wordpress/data';\nimport { withFocusOutside } from '@wordpress/components';\nimport { withInstanceId, compose } from '@wordpress/compose';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { pasteHandler } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nclass PostTitle extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.setRef = this.setRef.bind( this );\n\t\tthis.onPaste = this.onPaste.bind( this );\n\t}\n\tcomponentDidUpdate( prevProps ) {\n\t\t// Unselect if any other block is selected and blur the RichText.\n\t\tif (\n\t\t\tthis.props.isSelected &&\n\t\t\t! prevProps.isAnyBlockSelected &&\n\t\t\tthis.props.isAnyBlockSelected\n\t\t) {\n\t\t\tif ( this.richTextRef ) {\n\t\t\t\tthis.richTextRef.blur();\n\t\t\t}\n\t\t\tthis.props.onUnselect();\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.props.innerRef ) {\n\t\t\tthis.props.innerRef( this );\n\t\t}\n\t}\n\n\thandleFocusOutside() {\n\t\tthis.props.onUnselect();\n\t}\n\n\tfocus() {\n\t\tthis.props.onSelect();\n\t}\n\n\tonPaste( { value, onChange, plainText, html } ) {\n\t\tconst { title, onInsertBlockAfter, onUpdate } = this.props;\n\n\t\tconst content = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t} );\n\n\t\tif ( content.length ) {\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tconst valueToInsert = create( { html: content } );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else {\n\t\t\t\tconst [ firstBlock ] = content;\n\t\t\t\tif (\n\t\t\t\t\t! title &&\n\t\t\t\t\t( firstBlock.name === 'core/heading' ||\n\t\t\t\t\t\tfirstBlock.name === 'core/paragraph' )\n\t\t\t\t) {\n\t\t\t\t\tonUpdate( firstBlock.attributes.content );\n\t\t\t\t\tonInsertBlockAfter( content.slice( 1 ) );\n\t\t\t\t} else {\n\t\t\t\t\tonInsertBlockAfter( content );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tsetRef( richText ) {\n\t\tthis.richTextRef = richText;\n\t}\n\n\tgetTitle( title, postType ) {\n\t\tif ( 'page' === postType ) {\n\t\t\treturn ! title\n\t\t\t\t? /* translators: accessibility text. empty page title. */\n\t\t\t\t __( 'Page title. Empty' )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: text content of the page title. */\n\t\t\t\t\t\t__( 'Page title. %s' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t );\n\t\t}\n\n\t\treturn ! title\n\t\t\t? /* translators: accessibility text. empty post title. */\n\t\t\t __( 'Post title. Empty' )\n\t\t\t: sprintf(\n\t\t\t\t\t/* translators: accessibility text. %s: text content of the post title. */\n\t\t\t\t\t__( 'Post title. %s' ),\n\t\t\t\t\ttitle\n\t\t\t );\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tplaceholder,\n\t\t\tstyle,\n\t\t\ttitle,\n\t\t\tfocusedBorderColor,\n\t\t\tborderStyle,\n\t\t\tisDimmed,\n\t\t\tpostType,\n\t\t\tglobalStyles,\n\t\t} = this.props;\n\n\t\tconst decodedPlaceholder = decodeEntities( placeholder );\n\t\tconst borderColor = this.props.isSelected\n\t\t\t? focusedBorderColor\n\t\t\t: 'transparent';\n\t\tconst titleStyles = {\n\t\t\t...style,\n\t\t\t...( globalStyles?.text && {\n\t\t\t\tcolor: globalStyles.text,\n\t\t\t\tplaceholderColor: globalStyles.text,\n\t\t\t} ),\n\t\t};\n\n\t\treturn (\n\t\t\t<View\n\t\t\t\ttestID=\"post-title\"\n\t\t\t\tstyle={ [\n\t\t\t\t\tstyles.titleContainer,\n\t\t\t\t\tborderStyle,\n\t\t\t\t\t{ borderColor },\n\t\t\t\t\tisDimmed && styles.dimmed,\n\t\t\t\t] }\n\t\t\t\taccessible={ ! this.props.isSelected }\n\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\taccessibilityHint={ __( 'Updates the title.' ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\tsetRef={ this.setRef }\n\t\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\t\ttagName={ 'p' }\n\t\t\t\t\ttagsToEliminate={ [ 'strong' ] }\n\t\t\t\t\tunstableOnFocus={ this.props.onSelect }\n\t\t\t\t\tonBlur={ this.props.onBlur } // Always assign onBlur as a props.\n\t\t\t\t\tmultiline={ false }\n\t\t\t\t\tstyle={ titleStyles }\n\t\t\t\t\tstyles={ styles }\n\t\t\t\t\tfontSize={ 24 }\n\t\t\t\t\tlineHeight={ 1 }\n\t\t\t\t\tfontWeight={ 'bold' }\n\t\t\t\t\tdeleteEnter={ true }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tthis.props.onUpdate( value );\n\t\t\t\t\t} }\n\t\t\t\t\tonPaste={ this.onPaste }\n\t\t\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonSelectionChange={ () => {} }\n\t\t\t\t\tonEnter={ this.props.onEnterPress }\n\t\t\t\t\tdisableEditingMenu={ true }\n\t\t\t\t\t__unstableIsSelected={ this.props.isSelected }\n\t\t\t\t\t__unstableOnCreateUndoLevel={ () => {} }\n\t\t\t\t></RichText>\n\t\t\t</View>\n\t\t);\n\t}\n}\n\nexport default compose(\n\twithSelect( ( select ) => {\n\t\tconst { isPostTitleSelected, getEditedPostAttribute } =\n\t\t\tselect( editorStore );\n\t\tconst { getSelectedBlockClientId, getBlockRootClientId, getSettings } =\n\t\t\tselect( blockEditorStore );\n\n\t\tconst selectedId = getSelectedBlockClientId();\n\t\tconst selectionIsNested = !! getBlockRootClientId( selectedId );\n\t\tconst globalStyles =\n\t\t\tgetSettings()?.__experimentalGlobalStylesBaseStyles?.color;\n\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tisAnyBlockSelected: !! selectedId,\n\t\t\tisSelected: isPostTitleSelected(),\n\t\t\tisDimmed: selectionIsNested,\n\t\t\tglobalStyles,\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { undo, redo, togglePostTitleSelection, editPost } =\n\t\t\tdispatch( editorStore );\n\n\t\tconst { clearSelectedBlock, insertDefaultBlock, insertBlocks } =\n\t\t\tdispatch( blockEditorStore );\n\n\t\treturn {\n\t\t\tonEnterPress() {\n\t\t\t\tinsertDefaultBlock( undefined, undefined, 0 );\n\t\t\t},\n\t\t\tonUndo: undo,\n\t\t\tonRedo: redo,\n\t\t\tonSelect() {\n\t\t\t\ttogglePostTitleSelection( true );\n\t\t\t\tclearSelectedBlock();\n\t\t\t},\n\t\t\tonUnselect() {\n\t\t\t\ttogglePostTitleSelection( false );\n\t\t\t},\n\t\t\tonUpdate( title ) {\n\t\t\t\teditPost( { title } );\n\t\t\t},\n\t\t\tonInsertBlockAfter( blocks ) {\n\t\t\t\tinsertBlocks( blocks, 0 );\n\t\t\t},\n\t\t};\n\t} ),\n\twithInstanceId,\n\twithFocusOutside\n)( PostTitle );\n"]}
@@ -6,8 +6,6 @@ var _element = require("@wordpress/element");
6
6
 
7
7
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
8
 
9
- var _lodash = require("lodash");
10
-
11
9
  var _blocks = require("@wordpress/blocks");
12
10
 
13
11
  var _data = require("@wordpress/data");
@@ -20,10 +18,6 @@ var _hooks = require("@wordpress/hooks");
20
18
 
21
19
  var _store = require("../store");
22
20
 
23
- /**
24
- * External dependencies
25
- */
26
-
27
21
  /**
28
22
  * WordPress dependencies
29
23
  */
@@ -83,7 +77,7 @@ const createWithMetaAttributeSource = metaAttributes => (0, _compose.createHighe
83
77
  metaAttributes[attributeKey], value];
84
78
  }));
85
79
 
86
- if (!(0, _lodash.isEmpty)(nextMeta)) {
80
+ if (Object.entries(nextMeta).length) {
87
81
  setMeta(nextMeta);
88
82
  }
89
83
 
@@ -117,7 +111,7 @@ function shimAttributeSource(settings) {
117
111
  return [attributeKey, meta];
118
112
  }));
119
113
 
120
- if (!(0, _lodash.isEmpty)(metaAttributes)) {
114
+ if (Object.entries(metaAttributes).length) {
121
115
  settings.edit = createWithMetaAttributeSource(metaAttributes)(settings.edit);
122
116
  }
123
117
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/hooks/custom-sources-backwards-compatibility.js"],"names":["createWithMetaAttributeSource","metaAttributes","BlockEdit","attributes","setAttributes","props","postType","select","editorStore","getCurrentPostType","meta","setMeta","mergedAttributes","Object","fromEntries","entries","map","attributeKey","metaKey","nextAttributes","nextMeta","filter","key","value","shimAttributeSource","settings","source","edit","blocksStore","getBlockTypes","name","getBlockType","forEach"],"mappings":";;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAGA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,6BAA6B,GAAKC,cAAF,IACrC,yCACGC,SAAF,IACC,QAA+C;AAAA,MAA7C;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,aAAd;AAA6B,OAAGC;AAAhC,GAA6C;AAC9C,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,kBAAtB,EADE,EAEhB,EAFgB,CAAjB;AAIA,Q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;AACxC;AACA,QAAMxB,cAAc,GAAGY,MAAM,CAACC,WAAP,CACtBD,MAAM,CAACE,OAAP,yBAAgBU,QAAQ,CAACtB,UAAzB,uEAAuC,EAAvC,EACEkB,MADF,CACU;AAAA,QAAE,GAAI;AAAEK,MAAAA;AAAF,KAAJ,CAAF;AAAA,WAAwBA,MAAM,KAAK,MAAnC;AAAA,GADV,EAEEV,GAFF,CAEO;AAAA,QAAE,CAAEC,YAAF,EAAgB;AAAEP,MAAAA;AAAF,KAAhB,CAAF;AAAA,WAAkC,CAAEO,YAAF,EAAgBP,IAAhB,CAAlC;AAAA,GAFP,CADsB,CAAvB;;AAKA,MAAK,CAAE,qBAAST,cAAT,CAAP,EAAmC;AAClCwB,IAAAA,QAAQ,CAACE,IAAT,GAAgB3B,6BAA6B,CAAEC,cAAF,CAA7B,CACfwB,QAAQ,CAACE,IADM,CAAhB;AAGA;;AAED,SAAOF,QAAP;AACA;;AAED,sBACC,0BADD,EAEC,0EAFD,EAGCD,mBAHD,E,CAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,kBAAcI,aAAd,EACEC,aADF,GAEEb,GAFF,CAEO;AAAA,MAAE;AAAEc,IAAAA;AAAF,GAAF;AAAA,SAAgB,kBAAcF,aAAd,EAA4BG,YAA5B,CAA0CD,IAA1C,CAAhB;AAAA,CAFP,EAGEE,OAHF,CAGWR,mBAHX","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { select as globalSelect, useSelect } from '@wordpress/data';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Object whose keys are the names of block attributes, where each value\n * represents the meta key to which the block attribute is intended to save.\n *\n * @see https://developer.wordpress.org/reference/functions/register_meta/\n *\n * @typedef {Object<string,string>} WPMetaAttributeMapping\n */\n\n/**\n * Given a mapping of attribute names (meta source attributes) to their\n * associated meta key, returns a higher order component that overrides its\n * `attributes` and `setAttributes` props to sync any changes with the edited\n * post's meta keys.\n *\n * @param {WPMetaAttributeMapping} metaAttributes Meta attribute mapping.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\nconst createWithMetaAttributeSource = ( metaAttributes ) =>\n\tcreateHigherOrderComponent(\n\t\t( BlockEdit ) =>\n\t\t\t( { attributes, setAttributes, ...props } ) => {\n\t\t\t\tconst postType = useSelect(\n\t\t\t\t\t( select ) => select( editorStore ).getCurrentPostType(),\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tconst [ meta, setMeta ] = useEntityProp(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\t'meta'\n\t\t\t\t);\n\n\t\t\t\tconst mergedAttributes = useMemo(\n\t\t\t\t\t() => ( {\n\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( metaAttributes ).map(\n\t\t\t\t\t\t\t\t( [ attributeKey, metaKey ] ) => [\n\t\t\t\t\t\t\t\t\tattributeKey,\n\t\t\t\t\t\t\t\t\tmeta[ metaKey ],\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} ),\n\t\t\t\t\t[ attributes, meta ]\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<BlockEdit\n\t\t\t\t\t\tattributes={ mergedAttributes }\n\t\t\t\t\t\tsetAttributes={ ( nextAttributes ) => {\n\t\t\t\t\t\t\tconst nextMeta = Object.fromEntries(\n\t\t\t\t\t\t\t\tObject.entries( nextAttributes ?? {} )\n\t\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t\t// Filter to intersection of keys between the updated\n\t\t\t\t\t\t\t\t\t\t// attributes and those with an associated meta key.\n\t\t\t\t\t\t\t\t\t\t( [ key ] ) => key in metaAttributes\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.map( ( [ attributeKey, value ] ) => [\n\t\t\t\t\t\t\t\t\t\t// Rename the keys to the expected meta key name.\n\t\t\t\t\t\t\t\t\t\tmetaAttributes[ attributeKey ],\n\t\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( ! isEmpty( nextMeta ) ) {\n\t\t\t\t\t\t\t\tsetMeta( nextMeta );\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t},\n\t\t'withMetaAttributeSource'\n\t);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade meta-sourced attributes to use the post's meta entity property.\n *\n * @param {WPBlockSettings} settings Registered block settings.\n *\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings ) {\n\t/** @type {WPMetaAttributeMapping} */\n\tconst metaAttributes = Object.fromEntries(\n\t\tObject.entries( settings.attributes ?? {} )\n\t\t\t.filter( ( [ , { source } ] ) => source === 'meta' )\n\t\t\t.map( ( [ attributeKey, { meta } ] ) => [ attributeKey, meta ] )\n\t);\n\tif ( ! isEmpty( metaAttributes ) ) {\n\t\tsettings.edit = createWithMetaAttributeSource( metaAttributes )(\n\t\t\tsettings.edit\n\t\t);\n\t}\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n\n// The above filter will only capture blocks registered after the filter was\n// added. There may already be blocks registered by this point, and those must\n// be updated to apply the shim.\n//\n// The following implementation achieves this, albeit with a couple caveats:\n// - Only blocks registered on the global store will be modified.\n// - The block settings are directly mutated, since there is currently no\n// mechanism to update an existing block registration. This is the reason for\n// `getBlockType` separate from `getBlockTypes`, since the latter returns a\n// _copy_ of the block registration (i.e. the mutation would not affect the\n// actual registered block settings).\n//\n// `getBlockTypes` or `getBlockType` implementation could change in the future\n// in regards to creating settings clones, but the corresponding end-to-end\n// tests for meta blocks should cover against any potential regressions.\n//\n// In the future, we could support updating block settings, at which point this\n// implementation could use that mechanism instead.\nglobalSelect( blocksStore )\n\t.getBlockTypes()\n\t.map( ( { name } ) => globalSelect( blocksStore ).getBlockType( name ) )\n\t.forEach( shimAttributeSource );\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/hooks/custom-sources-backwards-compatibility.js"],"names":["createWithMetaAttributeSource","metaAttributes","BlockEdit","attributes","setAttributes","props","postType","select","editorStore","getCurrentPostType","meta","setMeta","mergedAttributes","Object","fromEntries","entries","map","attributeKey","metaKey","nextAttributes","nextMeta","filter","key","value","length","shimAttributeSource","settings","source","edit","blocksStore","getBlockTypes","name","getBlockType","forEach"],"mappings":";;;;AAMA;;;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;AAbA;AACA;AACA;;AAQA;AACA;AACA;;AAGA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,6BAA6B,GAAKC,cAAF,IACrC,yCACGC,SAAF,IACC,QAA+C;AAAA,MAA7C;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,aAAd;AAA6B,OAAGC;AAAhC,GAA6C;AAC9C,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,kBAAt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AACA;AACA;;;AACA,SAASoB,mBAAT,CAA8BC,QAA9B,EAAyC;AAAA;;AACxC;AACA,QAAMzB,cAAc,GAAGY,MAAM,CAACC,WAAP,CACtBD,MAAM,CAACE,OAAP,yBAAgBW,QAAQ,CAACvB,UAAzB,uEAAuC,EAAvC,EACEkB,MADF,CACU;AAAA,QAAE,GAAI;AAAEM,MAAAA;AAAF,KAAJ,CAAF;AAAA,WAAwBA,MAAM,KAAK,MAAnC;AAAA,GADV,EAEEX,GAFF,CAEO;AAAA,QAAE,CAAEC,YAAF,EAAgB;AAAEP,MAAAA;AAAF,KAAhB,CAAF;AAAA,WAAkC,CAAEO,YAAF,EAAgBP,IAAhB,CAAlC;AAAA,GAFP,CADsB,CAAvB;;AAKA,MAAKG,MAAM,CAACE,OAAP,CAAgBd,cAAhB,EAAiCuB,MAAtC,EAA+C;AAC9CE,IAAAA,QAAQ,CAACE,IAAT,GAAgB5B,6BAA6B,CAAEC,cAAF,CAA7B,CACfyB,QAAQ,CAACE,IADM,CAAhB;AAGA;;AAED,SAAOF,QAAP;AACA;;AAED,sBACC,0BADD,EAEC,0EAFD,EAGCD,mBAHD,E,CAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,kBAAcI,aAAd,EACEC,aADF,GAEEd,GAFF,CAEO;AAAA,MAAE;AAAEe,IAAAA;AAAF,GAAF;AAAA,SAAgB,kBAAcF,aAAd,EAA4BG,YAA5B,CAA0CD,IAA1C,CAAhB;AAAA,CAFP,EAGEE,OAHF,CAGWR,mBAHX","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { select as globalSelect, useSelect } from '@wordpress/data';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Object whose keys are the names of block attributes, where each value\n * represents the meta key to which the block attribute is intended to save.\n *\n * @see https://developer.wordpress.org/reference/functions/register_meta/\n *\n * @typedef {Object<string,string>} WPMetaAttributeMapping\n */\n\n/**\n * Given a mapping of attribute names (meta source attributes) to their\n * associated meta key, returns a higher order component that overrides its\n * `attributes` and `setAttributes` props to sync any changes with the edited\n * post's meta keys.\n *\n * @param {WPMetaAttributeMapping} metaAttributes Meta attribute mapping.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\nconst createWithMetaAttributeSource = ( metaAttributes ) =>\n\tcreateHigherOrderComponent(\n\t\t( BlockEdit ) =>\n\t\t\t( { attributes, setAttributes, ...props } ) => {\n\t\t\t\tconst postType = useSelect(\n\t\t\t\t\t( select ) => select( editorStore ).getCurrentPostType(),\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tconst [ meta, setMeta ] = useEntityProp(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\t'meta'\n\t\t\t\t);\n\n\t\t\t\tconst mergedAttributes = useMemo(\n\t\t\t\t\t() => ( {\n\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( metaAttributes ).map(\n\t\t\t\t\t\t\t\t( [ attributeKey, metaKey ] ) => [\n\t\t\t\t\t\t\t\t\tattributeKey,\n\t\t\t\t\t\t\t\t\tmeta[ metaKey ],\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} ),\n\t\t\t\t\t[ attributes, meta ]\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<BlockEdit\n\t\t\t\t\t\tattributes={ mergedAttributes }\n\t\t\t\t\t\tsetAttributes={ ( nextAttributes ) => {\n\t\t\t\t\t\t\tconst nextMeta = Object.fromEntries(\n\t\t\t\t\t\t\t\tObject.entries( nextAttributes ?? {} )\n\t\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t\t// Filter to intersection of keys between the updated\n\t\t\t\t\t\t\t\t\t\t// attributes and those with an associated meta key.\n\t\t\t\t\t\t\t\t\t\t( [ key ] ) => key in metaAttributes\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.map( ( [ attributeKey, value ] ) => [\n\t\t\t\t\t\t\t\t\t\t// Rename the keys to the expected meta key name.\n\t\t\t\t\t\t\t\t\t\tmetaAttributes[ attributeKey ],\n\t\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( Object.entries( nextMeta ).length ) {\n\t\t\t\t\t\t\t\tsetMeta( nextMeta );\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t},\n\t\t'withMetaAttributeSource'\n\t);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade meta-sourced attributes to use the post's meta entity property.\n *\n * @param {WPBlockSettings} settings Registered block settings.\n *\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings ) {\n\t/** @type {WPMetaAttributeMapping} */\n\tconst metaAttributes = Object.fromEntries(\n\t\tObject.entries( settings.attributes ?? {} )\n\t\t\t.filter( ( [ , { source } ] ) => source === 'meta' )\n\t\t\t.map( ( [ attributeKey, { meta } ] ) => [ attributeKey, meta ] )\n\t);\n\tif ( Object.entries( metaAttributes ).length ) {\n\t\tsettings.edit = createWithMetaAttributeSource( metaAttributes )(\n\t\t\tsettings.edit\n\t\t);\n\t}\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n\n// The above filter will only capture blocks registered after the filter was\n// added. There may already be blocks registered by this point, and those must\n// be updated to apply the shim.\n//\n// The following implementation achieves this, albeit with a couple caveats:\n// - Only blocks registered on the global store will be modified.\n// - The block settings are directly mutated, since there is currently no\n// mechanism to update an existing block registration. This is the reason for\n// `getBlockType` separate from `getBlockTypes`, since the latter returns a\n// _copy_ of the block registration (i.e. the mutation would not affect the\n// actual registered block settings).\n//\n// `getBlockTypes` or `getBlockType` implementation could change in the future\n// in regards to creating settings clones, but the corresponding end-to-end\n// tests for meta blocks should cover against any potential regressions.\n//\n// In the future, we could support updating block settings, at which point this\n// implementation could use that mechanism instead.\nglobalSelect( blocksStore )\n\t.getBlockTypes()\n\t.map( ( { name } ) => globalSelect( blocksStore ).getBlockType( name ) )\n\t.forEach( shimAttributeSource );\n"]}
@@ -1,22 +1,18 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { createElement } from "@wordpress/element";
3
3
 
4
- /**
5
- * External dependencies
6
- */
7
- import { groupBy } from 'lodash';
8
4
  /**
9
5
  * WordPress dependencies
10
6
  */
11
-
12
7
  import { Button, Flex, FlexItem } from '@wordpress/components';
13
- import { __ } from '@wordpress/i18n';
8
+ import { __, sprintf } from '@wordpress/i18n';
14
9
  import { useSelect, useDispatch } from '@wordpress/data';
15
10
  import { useState, useCallback, useRef } from '@wordpress/element';
16
11
  import { store as coreStore } from '@wordpress/core-data';
17
12
  import { store as blockEditorStore } from '@wordpress/block-editor';
18
13
  import { __experimentalUseDialog as useDialog } from '@wordpress/compose';
19
14
  import { store as noticesStore } from '@wordpress/notices';
15
+ import { getQueryArg } from '@wordpress/url';
20
16
  /**
21
17
  * Internal dependencies
22
18
  */
@@ -34,11 +30,37 @@ const PUBLISH_ON_SAVE_ENTITIES = [{
34
30
  kind: 'postType',
35
31
  name: 'wp_navigation'
36
32
  }];
33
+
34
+ function identity(values) {
35
+ return values;
36
+ }
37
+
38
+ function isPreviewingTheme() {
39
+ var _window;
40
+
41
+ return ((_window = window) === null || _window === void 0 ? void 0 : _window.__experimentalEnableThemePreviews) && getQueryArg(window.location.href, 'theme_preview') !== undefined;
42
+ }
43
+
44
+ function currentlyPreviewingTheme() {
45
+ if (isPreviewingTheme()) {
46
+ return getQueryArg(window.location.href, 'theme_preview');
47
+ }
48
+
49
+ return null;
50
+ }
51
+
37
52
  export default function EntitiesSavedStates(_ref) {
53
+ var _theme$name;
54
+
38
55
  let {
39
- close
56
+ close,
57
+ onSave = identity
40
58
  } = _ref;
41
59
  const saveButtonRef = useRef();
60
+ const {
61
+ getTheme
62
+ } = useSelect(coreStore);
63
+ const theme = getTheme(currentlyPreviewingTheme());
42
64
  const {
43
65
  dirtyEntityRecords
44
66
  } = useSelect(select => {
@@ -76,7 +98,18 @@ export default function EntitiesSavedStates(_ref) {
76
98
  createErrorNotice
77
99
  } = useDispatch(noticesStore); // To group entities by type.
78
100
 
79
- const partitionedSavables = groupBy(dirtyEntityRecords, 'name'); // Sort entity groups.
101
+ const partitionedSavables = dirtyEntityRecords.reduce((acc, record) => {
102
+ const {
103
+ name
104
+ } = record;
105
+
106
+ if (!acc[name]) {
107
+ acc[name] = [];
108
+ }
109
+
110
+ acc[name].push(record);
111
+ return acc;
112
+ }, {}); // Sort entity groups.
80
113
 
81
114
  const {
82
115
  site: siteSavables,
@@ -108,7 +141,7 @@ export default function EntitiesSavedStates(_ref) {
108
141
  }
109
142
  };
110
143
 
111
- const saveCheckedEntities = () => {
144
+ const saveCheckedEntitiesAndActivate = () => {
112
145
  const entitiesToSave = dirtyEntityRecords.filter(_ref3 => {
113
146
  let {
114
147
  kind,
@@ -149,6 +182,8 @@ export default function EntitiesSavedStates(_ref) {
149
182
  __unstableMarkLastChangeAsPersistent();
150
183
 
151
184
  Promise.all(pendingSavedRecords).then(values => {
185
+ return onSave(values);
186
+ }).then(values => {
152
187
  if (values.some(value => typeof value === 'undefined')) {
153
188
  createErrorNotice(__('Saving failed.'));
154
189
  } else {
@@ -165,6 +200,18 @@ export default function EntitiesSavedStates(_ref) {
165
200
  const [saveDialogRef, saveDialogProps] = useDialog({
166
201
  onClose: () => dismissPanel()
167
202
  });
203
+ const isDirty = dirtyEntityRecords.length - unselectedEntities.length > 0;
204
+ const activateSaveEnabled = isPreviewingTheme() || isDirty;
205
+ let activateSaveLabel;
206
+
207
+ if (isPreviewingTheme() && isDirty) {
208
+ activateSaveLabel = __('Activate & Save');
209
+ } else if (isPreviewingTheme()) {
210
+ activateSaveLabel = __('Activate');
211
+ } else {
212
+ activateSaveLabel = __('Save');
213
+ }
214
+
168
215
  return createElement("div", _extends({
169
216
  ref: saveDialogRef
170
217
  }, saveDialogProps, {
@@ -177,17 +224,17 @@ export default function EntitiesSavedStates(_ref) {
177
224
  as: Button,
178
225
  ref: saveButtonRef,
179
226
  variant: "primary",
180
- disabled: dirtyEntityRecords.length - unselectedEntities.length === 0,
181
- onClick: saveCheckedEntities,
227
+ disabled: !activateSaveEnabled,
228
+ onClick: saveCheckedEntitiesAndActivate,
182
229
  className: "editor-entities-saved-states__save-button"
183
- }, __('Save')), createElement(FlexItem, {
230
+ }, activateSaveLabel), createElement(FlexItem, {
184
231
  isBlock: true,
185
232
  as: Button,
186
233
  variant: "secondary",
187
234
  onClick: dismissPanel
188
235
  }, __('Cancel'))), createElement("div", {
189
236
  className: "entities-saved-states__text-prompt"
190
- }, createElement("strong", null, __('Are you ready to save?')), createElement("p", null, __('The following changes have been made to your site, templates, and content.'))), sortedPartitionedSavables.map(list => {
237
+ }, createElement("strong", null, __('Are you ready to save?')), isPreviewingTheme() && createElement("p", null, sprintf('Saving your changes will change your active theme to %1$s.', theme === null || theme === void 0 ? void 0 : (_theme$name = theme.name) === null || _theme$name === void 0 ? void 0 : _theme$name.rendered)), isDirty && createElement("p", null, __('The following changes have been made to your site, templates, and content.'))), sortedPartitionedSavables.map(list => {
191
238
  return createElement(EntityTypeList, {
192
239
  key: list[0].name,
193
240
  list: list,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/entities-saved-states/index.js"],"names":["groupBy","Button","Flex","FlexItem","__","useSelect","useDispatch","useState","useCallback","useRef","store","coreStore","blockEditorStore","__experimentalUseDialog","useDialog","noticesStore","EntityTypeList","TRANSLATED_SITE_PROPERTIES","title","description","site_logo","site_icon","show_on_front","page_on_front","PUBLISH_ON_SAVE_ENTITIES","kind","name","EntitiesSavedStates","close","saveButtonRef","dirtyEntityRecords","select","dirtyRecords","__experimentalGetDirtyEntityRecords","dirtyRecordsWithoutSite","filter","record","siteEdits","getEntityRecordEdits","siteEditsAsEntities","property","push","dirtyRecordsWithSiteItems","editEntityRecord","saveEditedEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","__unstableMarkLastChangeAsPersistent","createSuccessNotice","createErrorNotice","partitionedSavables","site","siteSavables","wp_template","templateSavables","wp_template_part","templatePartSavables","contentSavables","sortedPartitionedSavables","Object","values","Array","isArray","unselectedEntities","_setUnselectedEntities","setUnselectedEntities","checked","key","elt","saveCheckedEntities","entitiesToSave","some","siteItemsToSave","pendingSavedRecords","forEach","typeToPublish","status","length","undefined","Promise","all","then","value","type","catch","error","dismissPanel","saveDialogRef","saveDialogProps","onClose","map","list"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,QAAuC,uBAAvC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,EAAmBC,WAAnB,EAAgCC,MAAhC,QAA8C,oBAA9C;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASD,KAAK,IAAIE,gBAAlB,QAA0C,yBAA1C;AACA,SAASC,uBAAuB,IAAIC,SAApC,QA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;AAGC,MAAA,UAAU,EAAGL,YAHd;AAIC,MAAA,kBAAkB,EAAGvB,kBAJtB;AAKC,MAAA,qBAAqB,EAAGE;AALzB,MADD;AASA,GAVC,CAxCH,CADD;AAsDA","sourcesContent":["/**\n * External dependencies\n */\nimport { groupBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Flex, FlexItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState, useCallback, useRef } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { __experimentalUseDialog as useDialog } from '@wordpress/compose';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport EntityTypeList from './entity-type-list';\n\nconst TRANSLATED_SITE_PROPERTIES = {\n\ttitle: __( 'Title' ),\n\tdescription: __( 'Tagline' ),\n\tsite_logo: __( 'Logo' ),\n\tsite_icon: __( 'Icon' ),\n\tshow_on_front: __( 'Show on front' ),\n\tpage_on_front: __( 'Page on front' ),\n};\n\nconst PUBLISH_ON_SAVE_ENTITIES = [\n\t{\n\t\tkind: 'postType',\n\t\tname: 'wp_navigation',\n\t},\n];\n\nexport default function EntitiesSavedStates( { close } ) {\n\tconst saveButtonRef = useRef();\n\tconst { dirtyEntityRecords } = useSelect( ( select ) => {\n\t\tconst dirtyRecords =\n\t\t\tselect( coreStore ).__experimentalGetDirtyEntityRecords();\n\n\t\t// Remove site object and decouple into its edited pieces.\n\t\tconst dirtyRecordsWithoutSite = dirtyRecords.filter(\n\t\t\t( record ) => ! ( record.kind === 'root' && record.name === 'site' )\n\t\t);\n\n\t\tconst siteEdits = select( coreStore ).getEntityRecordEdits(\n\t\t\t'root',\n\t\t\t'site'\n\t\t);\n\n\t\tconst siteEditsAsEntities = [];\n\t\tfor ( const property in siteEdits ) {\n\t\t\tsiteEditsAsEntities.push( {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t\ttitle: TRANSLATED_SITE_PROPERTIES[ property ] || property,\n\t\t\t\tproperty,\n\t\t\t} );\n\t\t}\n\t\tconst dirtyRecordsWithSiteItems = [\n\t\t\t...dirtyRecordsWithoutSite,\n\t\t\t...siteEditsAsEntities,\n\t\t];\n\n\t\treturn {\n\t\t\tdirtyEntityRecords: dirtyRecordsWithSiteItems,\n\t\t};\n\t}, [] );\n\tconst {\n\t\teditEntityRecord,\n\t\tsaveEditedEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\n\tconst { __unstableMarkLastChangeAsPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\t// To group entities by type.\n\tconst partitionedSavables = groupBy( dirtyEntityRecords, 'name' );\n\n\t// Sort entity groups.\n\tconst {\n\t\tsite: siteSavables,\n\t\twp_template: templateSavables,\n\t\twp_template_part: templatePartSavables,\n\t\t...contentSavables\n\t} = partitionedSavables;\n\tconst sortedPartitionedSavables = [\n\t\tsiteSavables,\n\t\ttemplateSavables,\n\t\ttemplatePartSavables,\n\t\t...Object.values( contentSavables ),\n\t].filter( Array.isArray );\n\n\t// Unchecked entities to be ignored by save function.\n\tconst [ unselectedEntities, _setUnselectedEntities ] = useState( [] );\n\n\tconst setUnselectedEntities = (\n\t\t{ kind, name, key, property },\n\t\tchecked\n\t) => {\n\t\tif ( checked ) {\n\t\t\t_setUnselectedEntities(\n\t\t\t\tunselectedEntities.filter(\n\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\telt.kind !== kind ||\n\t\t\t\t\t\telt.name !== name ||\n\t\t\t\t\t\telt.key !== key ||\n\t\t\t\t\t\telt.property !== property\n\t\t\t\t)\n\t\t\t);\n\t\t} else {\n\t\t\t_setUnselectedEntities( [\n\t\t\t\t...unselectedEntities,\n\t\t\t\t{ kind, name, key, property },\n\t\t\t] );\n\t\t}\n\t};\n\n\tconst saveCheckedEntities = () => {\n\t\tconst entitiesToSave = dirtyEntityRecords.filter(\n\t\t\t( { kind, name, key, property } ) => {\n\t\t\t\treturn ! unselectedEntities.some(\n\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\telt.kind === kind &&\n\t\t\t\t\t\telt.name === name &&\n\t\t\t\t\t\telt.key === key &&\n\t\t\t\t\t\telt.property === property\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\n\t\tclose( entitiesToSave );\n\n\t\tconst siteItemsToSave = [];\n\t\tconst pendingSavedRecords = [];\n\t\tentitiesToSave.forEach( ( { kind, name, key, property } ) => {\n\t\t\tif ( 'root' === kind && 'site' === name ) {\n\t\t\t\tsiteItemsToSave.push( property );\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\tPUBLISH_ON_SAVE_ENTITIES.some(\n\t\t\t\t\t\t( typeToPublish ) =>\n\t\t\t\t\t\t\ttypeToPublish.kind === kind &&\n\t\t\t\t\t\t\ttypeToPublish.name === name\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\teditEntityRecord( kind, name, key, { status: 'publish' } );\n\t\t\t\t}\n\n\t\t\t\tpendingSavedRecords.push(\n\t\t\t\t\tsaveEditedEntityRecord( kind, name, key )\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\t\tif ( siteItemsToSave.length ) {\n\t\t\tpendingSavedRecords.push(\n\t\t\t\tsaveSpecifiedEntityEdits(\n\t\t\t\t\t'root',\n\t\t\t\t\t'site',\n\t\t\t\t\tundefined,\n\t\t\t\t\tsiteItemsToSave\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t__unstableMarkLastChangeAsPersistent();\n\n\t\tPromise.all( pendingSavedRecords )\n\t\t\t.then( ( values ) => {\n\t\t\t\tif (\n\t\t\t\t\tvalues.some( ( value ) => typeof value === 'undefined' )\n\t\t\t\t) {\n\t\t\t\t\tcreateErrorNotice( __( 'Saving failed.' ) );\n\t\t\t\t} else {\n\t\t\t\t\tcreateSuccessNotice( __( 'Site updated.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) =>\n\t\t\t\tcreateErrorNotice( `${ __( 'Saving failed.' ) } ${ error }` )\n\t\t\t);\n\t};\n\n\t// Explicitly define this with no argument passed. Using `close` on\n\t// its own will use the event object in place of the expected saved entities.\n\tconst dismissPanel = useCallback( () => close(), [ close ] );\n\n\tconst [ saveDialogRef, saveDialogProps ] = useDialog( {\n\t\tonClose: () => dismissPanel(),\n\t} );\n\n\treturn (\n\t\t<div\n\t\t\tref={ saveDialogRef }\n\t\t\t{ ...saveDialogProps }\n\t\t\tclassName=\"entities-saved-states__panel\"\n\t\t>\n\t\t\t<Flex className=\"entities-saved-states__panel-header\" gap={ 2 }>\n\t\t\t\t<FlexItem\n\t\t\t\t\tisBlock\n\t\t\t\t\tas={ Button }\n\t\t\t\t\tref={ saveButtonRef }\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\tdisabled={\n\t\t\t\t\t\tdirtyEntityRecords.length -\n\t\t\t\t\t\t\tunselectedEntities.length ===\n\t\t\t\t\t\t0\n\t\t\t\t\t}\n\t\t\t\t\tonClick={ saveCheckedEntities }\n\t\t\t\t\tclassName=\"editor-entities-saved-states__save-button\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem\n\t\t\t\t\tisBlock\n\t\t\t\t\tas={ Button }\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tonClick={ dismissPanel }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\n\t\t\t<div className=\"entities-saved-states__text-prompt\">\n\t\t\t\t<strong>{ __( 'Are you ready to save?' ) }</strong>\n\t\t\t\t<p>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'The following changes have been made to your site, templates, and content.'\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t</div>\n\n\t\t\t{ sortedPartitionedSavables.map( ( list ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<EntityTypeList\n\t\t\t\t\t\tkey={ list[ 0 ].name }\n\t\t\t\t\t\tlist={ list }\n\t\t\t\t\t\tclosePanel={ dismissPanel }\n\t\t\t\t\t\tunselectedEntities={ unselectedEntities }\n\t\t\t\t\t\tsetUnselectedEntities={ setUnselectedEntities }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</div>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/entities-saved-states/index.js"],"names":["Button","Flex","FlexItem","__","sprintf","useSelect","useDispatch","useState","useCallback","useRef","store","coreStore","blockEditorStore","__experimentalUseDialog","useDialog","noticesStore","getQueryArg","EntityTypeList","TRANSLATED_SITE_PROPERTIES","title","description","site_logo","site_icon","show_on_front","page_on_front","PUBLISH_ON_SAVE_ENTITIES","kind","name","identity","values","isPreviewingTheme","window","__experimentalEnableThemePreviews","location","href","undefined","currentlyPreviewingTheme","EntitiesSavedStates","close","onSave","saveButtonRef","getTheme","theme","dirtyEntityRecords","select","dirtyRecords","__experimentalGetDirtyEntityRecords","dirtyRecordsWithoutSite","filter","record","siteEdits","getEntityRecordEdits","siteEditsAsEntities","property","push","dirtyRecordsWithSiteItems","editEntityRecord","saveEditedEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","__unstableMarkLastChangeAsPersistent","createSuccessNotice","createErrorNotice","partitionedSavables","reduce","acc","site","siteSavables","wp_template","templateSavables","wp_template_part","templatePartSavables","contentSavables","sortedPartitionedSavables","Object","Array","isArray","unselectedEntities","_setUnselectedEntities","setUnselectedEntities","checked","key","elt","saveCheckedEntitiesAndActivate","entitiesToSave","some","siteItemsToSave","pendingSavedRecords","forEach","typeToPublish","status","length","Promise","all","then","value","type","catch","error","dismissPanel","saveDialogRef","saveDialogProps","onClose","isDirty","activateSaveEnabled","activateSaveLabel","rendered","map","list"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,QAAuC,uBAAvC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,EAAmBC,WAAnB,EAAgCC,MAAhC,QAA8C,oBAA9C;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASD,KAAK,IAAIE,gBAAlB,QAA0C,yBAA1C;AACA,SAASC,uBAAuB,IAAIC,SAApC,QAAqD,oBAArD;AACA,SAASJ,KAAK,IAAIK,YAAlB,QAAsC,oBAAtC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AAEA,MAAMC,0BAA0B,GAAG;AAClCC,EAAAA,KAAK,EAAEhB,EAAE,CAAE,OAAF,CADyB;AAElCiB,EAAAA,WAAW,EAAEjB,EAAE,CAAE,SAAF,CAFmB;AAGlCkB,EAAAA,SAAS,EAAElB,EAAE,CAAE,MAAF,CAHqB;AAIlCmB,EAAAA,SAAS,EAAEnB,EAAE,CAAE,MAAF,CAJqB;AAKlCoB,EAAAA,aAAa,EAAEpB,EAAE,CAAE,eAAF,CALiB;AAMlCqB,EAAAA,aAAa,EAAErB,EAAE,CAAE,eAAF;AANiB,CAAnC;AASA,MAAMsB,wBAAwB,GAAG,CAChC;AACCC,EAAAA,IAAI,EAAE,UADP;AAECC,EAAAA,IAAI,EAAE;AAFP,CADgC,CAAjC;;AAOA,SAASC,QAAT,CAAmBC,MAAnB,EAA4B;AAC3B,SAAOA,MAAP;AACA;;AAED,SAASC,iBAAT,GAA6B;AAAA;;AAC5B,SACC,YAAAC,MAAM,UAAN,0CAAQC,iCAAR,KACAhB,WAAW,CAAEe,MAAM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P;AAIC,IAAA,OAAO,EAAC,SAJT;AAKC,IAAA,QAAQ,EAAG,CAAEgE,mBALd;AAMC,IAAA,OAAO,EAAGrB,8BANX;AAOC,IAAA,SAAS,EAAC;AAPX,KASGsB,iBATH,CADD,EAYC,cAAC,QAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,EAAE,EAAGzG,MAFN;AAGC,IAAA,OAAO,EAAC,WAHT;AAIC,IAAA,OAAO,EAAGmG;AAJX,KAMGhG,EAAE,CAAE,QAAF,CANL,CAZD,CALD,EA2BC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,8BAAUA,EAAE,CAAE,wBAAF,CAAZ,CADD,EAEG2B,iBAAiB,MAClB,yBACG1B,OAAO,CACR,6DADQ,EAERsC,KAFQ,aAERA,KAFQ,sCAERA,KAAK,CAAEf,IAFC,gDAER,YAAa+E,QAFL,CADV,CAHF,EAUGH,OAAO,IACR,yBACGpG,EAAE,CACH,4EADG,CADL,CAXF,CA3BD,EA8CGsE,yBAAyB,CAACkC,GAA1B,CAAiCC,IAAF,IAAY;AAC5C,WACC,cAAC,cAAD;AACC,MAAA,GAAG,EAAGA,IAAI,CAAE,CAAF,CAAJ,CAAUjF,IADjB;AAEC,MAAA,IAAI,EAAGiF,IAFR;AAGC,MAAA,UAAU,EAAGT,YAHd;AAIC,MAAA,kBAAkB,EAAGtB,kBAJtB;AAKC,MAAA,qBAAqB,EAAGE;AALzB,MADD;AASA,GAVC,CA9CH,CADD;AA4DA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button, Flex, FlexItem } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState, useCallback, useRef } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { __experimentalUseDialog as useDialog } from '@wordpress/compose';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getQueryArg } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport EntityTypeList from './entity-type-list';\n\nconst TRANSLATED_SITE_PROPERTIES = {\n\ttitle: __( 'Title' ),\n\tdescription: __( 'Tagline' ),\n\tsite_logo: __( 'Logo' ),\n\tsite_icon: __( 'Icon' ),\n\tshow_on_front: __( 'Show on front' ),\n\tpage_on_front: __( 'Page on front' ),\n};\n\nconst PUBLISH_ON_SAVE_ENTITIES = [\n\t{\n\t\tkind: 'postType',\n\t\tname: 'wp_navigation',\n\t},\n];\n\nfunction identity( values ) {\n\treturn values;\n}\n\nfunction isPreviewingTheme() {\n\treturn (\n\t\twindow?.__experimentalEnableThemePreviews &&\n\t\tgetQueryArg( window.location.href, 'theme_preview' ) !== undefined\n\t);\n}\n\nfunction currentlyPreviewingTheme() {\n\tif ( isPreviewingTheme() ) {\n\t\treturn getQueryArg( window.location.href, 'theme_preview' );\n\t}\n\treturn null;\n}\n\nexport default function EntitiesSavedStates( { close, onSave = identity } ) {\n\tconst saveButtonRef = useRef();\n\tconst { getTheme } = useSelect( coreStore );\n\tconst theme = getTheme( currentlyPreviewingTheme() );\n\tconst { dirtyEntityRecords } = useSelect( ( select ) => {\n\t\tconst dirtyRecords =\n\t\t\tselect( coreStore ).__experimentalGetDirtyEntityRecords();\n\n\t\t// Remove site object and decouple into its edited pieces.\n\t\tconst dirtyRecordsWithoutSite = dirtyRecords.filter(\n\t\t\t( record ) => ! ( record.kind === 'root' && record.name === 'site' )\n\t\t);\n\n\t\tconst siteEdits = select( coreStore ).getEntityRecordEdits(\n\t\t\t'root',\n\t\t\t'site'\n\t\t);\n\n\t\tconst siteEditsAsEntities = [];\n\t\tfor ( const property in siteEdits ) {\n\t\t\tsiteEditsAsEntities.push( {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t\ttitle: TRANSLATED_SITE_PROPERTIES[ property ] || property,\n\t\t\t\tproperty,\n\t\t\t} );\n\t\t}\n\t\tconst dirtyRecordsWithSiteItems = [\n\t\t\t...dirtyRecordsWithoutSite,\n\t\t\t...siteEditsAsEntities,\n\t\t];\n\n\t\treturn {\n\t\t\tdirtyEntityRecords: dirtyRecordsWithSiteItems,\n\t\t};\n\t}, [] );\n\tconst {\n\t\teditEntityRecord,\n\t\tsaveEditedEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\n\tconst { __unstableMarkLastChangeAsPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\t// To group entities by type.\n\tconst partitionedSavables = dirtyEntityRecords.reduce( ( acc, record ) => {\n\t\tconst { name } = record;\n\t\tif ( ! acc[ name ] ) {\n\t\t\tacc[ name ] = [];\n\t\t}\n\t\tacc[ name ].push( record );\n\t\treturn acc;\n\t}, {} );\n\n\t// Sort entity groups.\n\tconst {\n\t\tsite: siteSavables,\n\t\twp_template: templateSavables,\n\t\twp_template_part: templatePartSavables,\n\t\t...contentSavables\n\t} = partitionedSavables;\n\tconst sortedPartitionedSavables = [\n\t\tsiteSavables,\n\t\ttemplateSavables,\n\t\ttemplatePartSavables,\n\t\t...Object.values( contentSavables ),\n\t].filter( Array.isArray );\n\n\t// Unchecked entities to be ignored by save function.\n\tconst [ unselectedEntities, _setUnselectedEntities ] = useState( [] );\n\n\tconst setUnselectedEntities = (\n\t\t{ kind, name, key, property },\n\t\tchecked\n\t) => {\n\t\tif ( checked ) {\n\t\t\t_setUnselectedEntities(\n\t\t\t\tunselectedEntities.filter(\n\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\telt.kind !== kind ||\n\t\t\t\t\t\telt.name !== name ||\n\t\t\t\t\t\telt.key !== key ||\n\t\t\t\t\t\telt.property !== property\n\t\t\t\t)\n\t\t\t);\n\t\t} else {\n\t\t\t_setUnselectedEntities( [\n\t\t\t\t...unselectedEntities,\n\t\t\t\t{ kind, name, key, property },\n\t\t\t] );\n\t\t}\n\t};\n\n\tconst saveCheckedEntitiesAndActivate = () => {\n\t\tconst entitiesToSave = dirtyEntityRecords.filter(\n\t\t\t( { kind, name, key, property } ) => {\n\t\t\t\treturn ! unselectedEntities.some(\n\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\telt.kind === kind &&\n\t\t\t\t\t\telt.name === name &&\n\t\t\t\t\t\telt.key === key &&\n\t\t\t\t\t\telt.property === property\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\n\t\tclose( entitiesToSave );\n\n\t\tconst siteItemsToSave = [];\n\t\tconst pendingSavedRecords = [];\n\t\tentitiesToSave.forEach( ( { kind, name, key, property } ) => {\n\t\t\tif ( 'root' === kind && 'site' === name ) {\n\t\t\t\tsiteItemsToSave.push( property );\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\tPUBLISH_ON_SAVE_ENTITIES.some(\n\t\t\t\t\t\t( typeToPublish ) =>\n\t\t\t\t\t\t\ttypeToPublish.kind === kind &&\n\t\t\t\t\t\t\ttypeToPublish.name === name\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\teditEntityRecord( kind, name, key, { status: 'publish' } );\n\t\t\t\t}\n\n\t\t\t\tpendingSavedRecords.push(\n\t\t\t\t\tsaveEditedEntityRecord( kind, name, key )\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\t\tif ( siteItemsToSave.length ) {\n\t\t\tpendingSavedRecords.push(\n\t\t\t\tsaveSpecifiedEntityEdits(\n\t\t\t\t\t'root',\n\t\t\t\t\t'site',\n\t\t\t\t\tundefined,\n\t\t\t\t\tsiteItemsToSave\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t__unstableMarkLastChangeAsPersistent();\n\n\t\tPromise.all( pendingSavedRecords )\n\t\t\t.then( ( values ) => {\n\t\t\t\treturn onSave( values );\n\t\t\t} )\n\t\t\t.then( ( values ) => {\n\t\t\t\tif (\n\t\t\t\t\tvalues.some( ( value ) => typeof value === 'undefined' )\n\t\t\t\t) {\n\t\t\t\t\tcreateErrorNotice( __( 'Saving failed.' ) );\n\t\t\t\t} else {\n\t\t\t\t\tcreateSuccessNotice( __( 'Site updated.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) =>\n\t\t\t\tcreateErrorNotice( `${ __( 'Saving failed.' ) } ${ error }` )\n\t\t\t);\n\t};\n\n\t// Explicitly define this with no argument passed. Using `close` on\n\t// its own will use the event object in place of the expected saved entities.\n\tconst dismissPanel = useCallback( () => close(), [ close ] );\n\n\tconst [ saveDialogRef, saveDialogProps ] = useDialog( {\n\t\tonClose: () => dismissPanel(),\n\t} );\n\n\tconst isDirty = dirtyEntityRecords.length - unselectedEntities.length > 0;\n\tconst activateSaveEnabled = isPreviewingTheme() || isDirty;\n\n\tlet activateSaveLabel;\n\tif ( isPreviewingTheme() && isDirty ) {\n\t\tactivateSaveLabel = __( 'Activate & Save' );\n\t} else if ( isPreviewingTheme() ) {\n\t\tactivateSaveLabel = __( 'Activate' );\n\t} else {\n\t\tactivateSaveLabel = __( 'Save' );\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ saveDialogRef }\n\t\t\t{ ...saveDialogProps }\n\t\t\tclassName=\"entities-saved-states__panel\"\n\t\t>\n\t\t\t<Flex className=\"entities-saved-states__panel-header\" gap={ 2 }>\n\t\t\t\t<FlexItem\n\t\t\t\t\tisBlock\n\t\t\t\t\tas={ Button }\n\t\t\t\t\tref={ saveButtonRef }\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\tdisabled={ ! activateSaveEnabled }\n\t\t\t\t\tonClick={ saveCheckedEntitiesAndActivate }\n\t\t\t\t\tclassName=\"editor-entities-saved-states__save-button\"\n\t\t\t\t>\n\t\t\t\t\t{ activateSaveLabel }\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem\n\t\t\t\t\tisBlock\n\t\t\t\t\tas={ Button }\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tonClick={ dismissPanel }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\n\t\t\t<div className=\"entities-saved-states__text-prompt\">\n\t\t\t\t<strong>{ __( 'Are you ready to save?' ) }</strong>\n\t\t\t\t{ isPreviewingTheme() && (\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t'Saving your changes will change your active theme to %1$s.',\n\t\t\t\t\t\t\ttheme?.name?.rendered\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t\t{ isDirty && (\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'The following changes have been made to your site, templates, and content.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\n\t\t\t{ sortedPartitionedSavables.map( ( list ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<EntityTypeList\n\t\t\t\t\t\tkey={ list[ 0 ].name }\n\t\t\t\t\t\tlist={ list }\n\t\t\t\t\t\tclosePanel={ dismissPanel }\n\t\t\t\t\t\tunselectedEntities={ unselectedEntities }\n\t\t\t\t\t\tsetUnselectedEntities={ setUnselectedEntities }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</div>\n\t);\n}\n"]}
@@ -5,9 +5,9 @@ import { createElement } from "@wordpress/element";
5
5
  */
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
  import { applyFilters } from '@wordpress/hooks';
8
- import { DropZone, Button, Spinner, ResponsiveWrapper, withNotices, withFilters } from '@wordpress/components';
8
+ import { DropZone, Button, Spinner, ResponsiveWrapper, withNotices, withFilters, __experimentalHStack as HStack } from '@wordpress/components';
9
9
  import { isBlobURL } from '@wordpress/blob';
10
- import { useState } from '@wordpress/element';
10
+ import { useState, useRef } from '@wordpress/element';
11
11
  import { compose } from '@wordpress/compose';
12
12
  import { useSelect, withDispatch, withSelect } from '@wordpress/data';
13
13
  import { MediaUpload, MediaUploadCheck, store as blockEditorStore } from '@wordpress/block-editor';
@@ -24,8 +24,6 @@ const DEFAULT_FEATURE_IMAGE_LABEL = __('Featured image');
24
24
 
25
25
  const DEFAULT_SET_FEATURE_IMAGE_LABEL = __('Set featured image');
26
26
 
27
- const DEFAULT_REMOVE_FEATURE_IMAGE_LABEL = __('Remove image');
28
-
29
27
  const instructions = createElement("p", null, __('To edit the featured image, you need permission to upload media.'));
30
28
 
31
29
  function getMediaDetails(media, postId) {
@@ -65,7 +63,7 @@ function getMediaDetails(media, postId) {
65
63
  }
66
64
 
67
65
  function PostFeaturedImage(_ref) {
68
- var _media$media_details$3, _media$media_details$4, _postType$labels, _postType$labels3, _postType$labels4;
66
+ var _media$media_details$3, _media$media_details$4, _postType$labels;
69
67
 
70
68
  let {
71
69
  currentPostId,
@@ -77,6 +75,7 @@ function PostFeaturedImage(_ref) {
77
75
  noticeUI,
78
76
  noticeOperations
79
77
  } = _ref;
78
+ const toggleRef = useRef();
80
79
  const [isLoading, setIsLoading] = useState(false);
81
80
  const mediaUpload = useSelect(select => {
82
81
  return select(blockEditorStore).getSettings().mediaUpload;
@@ -136,9 +135,10 @@ function PostFeaturedImage(_ref) {
136
135
  return createElement("div", {
137
136
  className: "editor-post-featured-image__container"
138
137
  }, createElement(Button, {
138
+ ref: toggleRef,
139
139
  className: !featuredImageId ? 'editor-post-featured-image__toggle' : 'editor-post-featured-image__preview',
140
140
  onClick: open,
141
- "aria-label": !featuredImageId ? null : __('Edit or update the image'),
141
+ "aria-label": !featuredImageId ? null : __('Edit or replace the image'),
142
142
  "aria-describedby": !featuredImageId ? null : `editor-post-featured-image-${featuredImageId}-describedby`
143
143
  }, !!featuredImageId && media && createElement(ResponsiveWrapper, {
144
144
  naturalWidth: mediaWidth,
@@ -147,31 +147,25 @@ function PostFeaturedImage(_ref) {
147
147
  }, createElement("img", {
148
148
  src: mediaSourceUrl,
149
149
  alt: ""
150
- })), isLoading && createElement(Spinner, null), !featuredImageId && !isLoading && ((postType === null || postType === void 0 ? void 0 : (_postType$labels2 = postType.labels) === null || _postType$labels2 === void 0 ? void 0 : _postType$labels2.set_featured_image) || DEFAULT_SET_FEATURE_IMAGE_LABEL)), createElement(DropZone, {
150
+ })), isLoading && createElement(Spinner, null), !featuredImageId && !isLoading && ((postType === null || postType === void 0 ? void 0 : (_postType$labels2 = postType.labels) === null || _postType$labels2 === void 0 ? void 0 : _postType$labels2.set_featured_image) || DEFAULT_SET_FEATURE_IMAGE_LABEL)), !!featuredImageId && createElement(HStack, {
151
+ className: "editor-post-featured-image__actions"
152
+ }, createElement(Button, {
153
+ className: "editor-post-featured-image__action",
154
+ onClick: open // Prefer that screen readers use the .editor-post-featured-image__preview button.
155
+ ,
156
+ "aria-hidden": "true"
157
+ }, __('Replace')), createElement(Button, {
158
+ className: "editor-post-featured-image__action",
159
+ onClick: () => {
160
+ onRemoveImage();
161
+ toggleRef.current.focus();
162
+ }
163
+ }, __('Remove'))), createElement(DropZone, {
151
164
  onFilesDrop: onDropFiles
152
165
  }));
153
166
  },
154
167
  value: featuredImageId
155
- })), !!featuredImageId && createElement(MediaUploadCheck, null, media && createElement(MediaUpload, {
156
- title: (postType === null || postType === void 0 ? void 0 : (_postType$labels3 = postType.labels) === null || _postType$labels3 === void 0 ? void 0 : _postType$labels3.featured_image) || DEFAULT_FEATURE_IMAGE_LABEL,
157
- onSelect: onUpdateImage,
158
- unstableFeaturedImageFlow: true,
159
- allowedTypes: ALLOWED_MEDIA_TYPES,
160
- modalClass: "editor-post-featured-image__media-modal",
161
- render: _ref4 => {
162
- let {
163
- open
164
- } = _ref4;
165
- return createElement(Button, {
166
- onClick: open,
167
- variant: "secondary"
168
- }, __('Replace Image'));
169
- }
170
- }), createElement(Button, {
171
- onClick: onRemoveImage,
172
- variant: "link",
173
- isDestructive: true
174
- }, (postType === null || postType === void 0 ? void 0 : (_postType$labels4 = postType.labels) === null || _postType$labels4 === void 0 ? void 0 : _postType$labels4.remove_featured_image) || DEFAULT_REMOVE_FEATURE_IMAGE_LABEL))));
168
+ }))));
175
169
  }
176
170
 
177
171
  const applyWithSelect = withSelect(select => {
@@ -193,13 +187,13 @@ const applyWithSelect = withSelect(select => {
193
187
  featuredImageId
194
188
  };
195
189
  });
196
- const applyWithDispatch = withDispatch((dispatch, _ref5, _ref6) => {
190
+ const applyWithDispatch = withDispatch((dispatch, _ref4, _ref5) => {
197
191
  let {
198
192
  noticeOperations
199
- } = _ref5;
193
+ } = _ref4;
200
194
  let {
201
195
  select
202
- } = _ref6;
196
+ } = _ref5;
203
197
  const {
204
198
  editPost
205
199
  } = dispatch(editorStore);
@@ -215,8 +209,8 @@ const applyWithDispatch = withDispatch((dispatch, _ref5, _ref6) => {
215
209
  allowedTypes: ['image'],
216
210
  filesList,
217
211
 
218
- onFileChange(_ref7) {
219
- let [image] = _ref7;
212
+ onFileChange(_ref6) {
213
+ let [image] = _ref6;
220
214
  editPost({
221
215
  featured_media: image.id
222
216
  });