@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
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-featured-image/index.js"],"names":["__","sprintf","applyFilters","DropZone","Button","Spinner","ResponsiveWrapper","withNotices","withFilters","isBlobURL","useState","compose","useSelect","withDispatch","withSelect","MediaUpload","MediaUploadCheck","store","blockEditorStore","coreStore","PostFeaturedImageCheck","editorStore","ALLOWED_MEDIA_TYPES","DEFAULT_FEATURE_IMAGE_LABEL","DEFAULT_SET_FEATURE_IMAGE_LABEL","DEFAULT_REMOVE_FEATURE_IMAGE_LABEL","instructions","getMediaDetails","media","postId","defaultSize","id","media_details","sizes","mediaWidth","width","mediaHeight","height","mediaSourceUrl","source_url","fallbackSize","PostFeaturedImage","currentPostId","featuredImageId","onUpdateImage","onRemoveImage","postType","noticeUI","noticeOperations","isLoading","setIsLoading","mediaUpload","select","getSettings","onDropFiles","filesList","allowedTypes","onFileChange","image","url","onError","message","removeAllNotices","createErrorNotice","alt_text","full","file","slug","labels","featured_image","open","set_featured_image","remove_featured_image","applyWithSelect","getMedia","getPostType","getCurrentPostId","getEditedPostAttribute","context","applyWithDispatch","dispatch","editPost","featured_media","onDropImage"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SACCC,QADD,EAECC,MAFD,EAGCC,OAHD,EAIC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uBA,CA1BoC,CAAtC;AA6BA,eAAevE,OAAO,CACrBJ,WADqB,EAErBkE,eAFqB,EAGrBM,iBAHqB,EAIrBvE,WAAW,CAAE,0BAAF,CAJU,CAAP,CAKZiC,iBALY,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { applyFilters } from '@wordpress/hooks';\nimport {\n\tDropZone,\n\tButton,\n\tSpinner,\n\tResponsiveWrapper,\n\twithNotices,\n\twithFilters,\n} from '@wordpress/components';\nimport { isBlobURL } from '@wordpress/blob';\nimport { useState } from '@wordpress/element';\nimport { compose } from '@wordpress/compose';\nimport { useSelect, withDispatch, withSelect } from '@wordpress/data';\nimport {\n\tMediaUpload,\n\tMediaUploadCheck,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostFeaturedImageCheck from './check';\nimport { store as editorStore } from '../../store';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image' ];\n\n// Used when labels from post type were not yet loaded or when they are not present.\nconst DEFAULT_FEATURE_IMAGE_LABEL = __( 'Featured image' );\nconst DEFAULT_SET_FEATURE_IMAGE_LABEL = __( 'Set featured image' );\nconst DEFAULT_REMOVE_FEATURE_IMAGE_LABEL = __( 'Remove image' );\n\nconst instructions = (\n\t<p>\n\t\t{ __(\n\t\t\t'To edit the featured image, you need permission to upload media.'\n\t\t) }\n\t</p>\n);\n\nfunction getMediaDetails( media, postId ) {\n\tif ( ! media ) {\n\t\treturn {};\n\t}\n\n\tconst defaultSize = applyFilters(\n\t\t'editor.PostFeaturedImage.imageSize',\n\t\t'large',\n\t\tmedia.id,\n\t\tpostId\n\t);\n\tif ( defaultSize in ( media?.media_details?.sizes ?? {} ) ) {\n\t\treturn {\n\t\t\tmediaWidth: media.media_details.sizes[ defaultSize ].width,\n\t\t\tmediaHeight: media.media_details.sizes[ defaultSize ].height,\n\t\t\tmediaSourceUrl: media.media_details.sizes[ defaultSize ].source_url,\n\t\t};\n\t}\n\n\t// Use fallbackSize when defaultSize is not available.\n\tconst fallbackSize = applyFilters(\n\t\t'editor.PostFeaturedImage.imageSize',\n\t\t'thumbnail',\n\t\tmedia.id,\n\t\tpostId\n\t);\n\tif ( fallbackSize in ( media?.media_details?.sizes ?? {} ) ) {\n\t\treturn {\n\t\t\tmediaWidth: media.media_details.sizes[ fallbackSize ].width,\n\t\t\tmediaHeight: media.media_details.sizes[ fallbackSize ].height,\n\t\t\tmediaSourceUrl:\n\t\t\t\tmedia.media_details.sizes[ fallbackSize ].source_url,\n\t\t};\n\t}\n\n\t// Use full image size when fallbackSize and defaultSize are not available.\n\treturn {\n\t\tmediaWidth: media.media_details.width,\n\t\tmediaHeight: media.media_details.height,\n\t\tmediaSourceUrl: media.source_url,\n\t};\n}\n\nfunction PostFeaturedImage( {\n\tcurrentPostId,\n\tfeaturedImageId,\n\tonUpdateImage,\n\tonRemoveImage,\n\tmedia,\n\tpostType,\n\tnoticeUI,\n\tnoticeOperations,\n} ) {\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst { mediaWidth, mediaHeight, mediaSourceUrl } = getMediaDetails(\n\t\tmedia,\n\t\tcurrentPostId\n\t);\n\n\tfunction onDropFiles( filesList ) {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\tsetIsLoading( true );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonUpdateImage( image );\n\t\t\t\tsetIsLoading( false );\n\t\t\t},\n\t\t\tonError( message ) {\n\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<PostFeaturedImageCheck>\n\t\t\t{ noticeUI }\n\t\t\t<div className=\"editor-post-featured-image\">\n\t\t\t\t{ media && (\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={ `editor-post-featured-image-${ featuredImageId }-describedby` }\n\t\t\t\t\t\tclassName=\"hidden\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image alt text.\n\t\t\t\t\t\t\t\t__( 'Current image: %s' ),\n\t\t\t\t\t\t\t\tmedia.alt_text\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image filename.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'The current image has no alternative text. The file name is: %s'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tmedia.media_details.sizes?.full?.file ||\n\t\t\t\t\t\t\t\t\tmedia.slug\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<MediaUploadCheck fallback={ instructions }>\n\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\tpostType?.labels?.featured_image ||\n\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t<div className=\"editor-post-featured-image__container\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? 'editor-post-featured-image__toggle'\n\t\t\t\t\t\t\t\t\t\t\t: 'editor-post-featured-image__preview'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Edit or update the image' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: `editor-post-featured-image-${ featuredImageId }-describedby`\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ !! featuredImageId && media && (\n\t\t\t\t\t\t\t\t\t\t<ResponsiveWrapper\n\t\t\t\t\t\t\t\t\t\t\tnaturalWidth={ mediaWidth }\n\t\t\t\t\t\t\t\t\t\t\tnaturalHeight={ mediaHeight }\n\t\t\t\t\t\t\t\t\t\t\tisInline\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\t\t\tsrc={ mediaSourceUrl }\n\t\t\t\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</ResponsiveWrapper>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ isLoading && <Spinner /> }\n\t\t\t\t\t\t\t\t\t{ ! featuredImageId &&\n\t\t\t\t\t\t\t\t\t\t! isLoading &&\n\t\t\t\t\t\t\t\t\t\t( postType?.labels\n\t\t\t\t\t\t\t\t\t\t\t?.set_featured_image ||\n\t\t\t\t\t\t\t\t\t\t\tDEFAULT_SET_FEATURE_IMAGE_LABEL ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onDropFiles } />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tvalue={ featuredImageId }\n\t\t\t\t\t/>\n\t\t\t\t</MediaUploadCheck>\n\t\t\t\t{ !! featuredImageId && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t{ media && (\n\t\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\t\tpostType?.labels?.featured_image ||\n\t\t\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Replace Image' ) }\n\t\t\t\t\t\t\t\t\t</Button>\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\t<Button\n\t\t\t\t\t\t\tonClick={ onRemoveImage }\n\t\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\t\tisDestructive\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ postType?.labels?.remove_featured_image ||\n\t\t\t\t\t\t\t\tDEFAULT_REMOVE_FEATURE_IMAGE_LABEL }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</PostFeaturedImageCheck>\n\t);\n}\n\nconst applyWithSelect = withSelect( ( select ) => {\n\tconst { getMedia, getPostType } = select( coreStore );\n\tconst { getCurrentPostId, getEditedPostAttribute } = select( editorStore );\n\tconst featuredImageId = getEditedPostAttribute( 'featured_media' );\n\n\treturn {\n\t\tmedia: featuredImageId\n\t\t\t? getMedia( featuredImageId, { context: 'view' } )\n\t\t\t: null,\n\t\tcurrentPostId: getCurrentPostId(),\n\t\tpostType: getPostType( getEditedPostAttribute( 'type' ) ),\n\t\tfeaturedImageId,\n\t};\n} );\n\nconst applyWithDispatch = withDispatch(\n\t( dispatch, { noticeOperations }, { select } ) => {\n\t\tconst { editPost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonUpdateImage( image ) {\n\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t},\n\t\t\tonDropImage( filesList ) {\n\t\t\t\tselect( blockEditorStore )\n\t\t\t\t\t.getSettings()\n\t\t\t\t\t.mediaUpload( {\n\t\t\t\t\t\tallowedTypes: [ 'image' ],\n\t\t\t\t\t\tfilesList,\n\t\t\t\t\t\tonFileChange( [ image ] ) {\n\t\t\t\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError( message ) {\n\t\t\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t},\n\t\t\tonRemoveImage() {\n\t\t\t\teditPost( { featured_media: 0 } );\n\t\t\t},\n\t\t};\n\t}\n);\n\nexport default compose(\n\twithNotices,\n\tapplyWithSelect,\n\tapplyWithDispatch,\n\twithFilters( 'editor.PostFeaturedImage' )\n)( PostFeaturedImage );\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-featured-image/index.js"],"names":["__","sprintf","applyFilters","DropZone","Button","Spinner","ResponsiveWrapper","withNotices","withFilters","__experimentalHStack","HStack","isBlobURL","useState","useRef","compose","useSelect","withDispatch","withSelect","MediaUpload","MediaUploadCheck","store","blockEditorStore","coreStore","PostFeaturedImageCheck","editorStore","ALLOWED_MEDIA_TYPES","DEFAULT_FEATURE_IMAGE_LABEL","DEFAULT_SET_FEATURE_IMAGE_LABEL","instructions","getMediaDetails","media","postId","defaultSize","id","media_details","sizes","mediaWidth","width","mediaHeight","height","mediaSourceUrl","source_url","fallbackSize","PostFeaturedImage","currentPostId","featuredImageId","onUpdateImage","onRemoveImage","postType","noticeUI","noticeOperations","toggleRef","isLoading","setIsLoading","mediaUpload","select","getSettings","onDropFiles","filesList","allowedTypes","onFileChange","image","url","onError","message","removeAllNotices","createErrorNotice","alt_text","full","file","slug","labels","featured_image","open","set_featured_image","current","focus","applyWithSelect","getMedia","getPostType","getCurrentPostId","getEditedPostAttribute","context","applyWithDispatch","dispatch","editPost","featured_media","onDropImage"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SACCC,QADD,EAECC,MAFD,EAGCC,OAHD,EAICC,iBAJD,EAKCC,WALD,EAMCC,WAND,EAOCC,oBAAoB,IAAIC,MAPzB,QAQO,uBARP;AASA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,QAAT,EAAmBC,MAAnB,QAAiC,oBAAjC;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,EAAoBC,YAApB,EAAkCC,UAAlC,QAAoD,iBAApD;AACA,SACCC,WADD,EAECC,gBAFD,EAGCC,KAAK,IAAIC,gBAHV,QAIO,yBAJP;AAKA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,sBAAP,MAAmC,SAAnC;AACA,SAASH,KAAK,IAAII,WAAlB,QAAqC,aAArC;AAEA,MAAMC,mBAAmB,GAAG,CAAE,OAAF,CAA5B,C,CAEA;;AACA,MAAMC,2BAA2B,GAAG1B,EAAE,CA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CAAEC,KAAF,CAAY;AACzBwB,UAAAA,QAAQ,CAAE;AAAEC,YAAAA,cAAc,EAAEzB,KAAK,CAAC5B;AAAxB,WAAF,CAAR;AACA,SALY;;AAMb8B,QAAAA,OAAO,CAAEC,OAAF,EAAY;AAClBd,UAAAA,gBAAgB,CAACe,gBAAjB;AACAf,UAAAA,gBAAgB,CAACgB,iBAAjB,CAAoCF,OAApC;AACA;;AATY,OAFf;AAaA,KAlBK;;AAmBNjB,IAAAA,aAAa,GAAG;AACfsC,MAAAA,QAAQ,CAAE;AAAEC,QAAAA,cAAc,EAAE;AAAlB,OAAF,CAAR;AACA;;AArBK,GAAP;AAuBA,CA1BoC,CAAtC;AA6BA,eAAexE,OAAO,CACrBP,WADqB,EAErBsE,eAFqB,EAGrBM,iBAHqB,EAIrB3E,WAAW,CAAE,0BAAF,CAJU,CAAP,CAKZmC,iBALY,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { applyFilters } from '@wordpress/hooks';\nimport {\n\tDropZone,\n\tButton,\n\tSpinner,\n\tResponsiveWrapper,\n\twithNotices,\n\twithFilters,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { isBlobURL } from '@wordpress/blob';\nimport { useState, useRef } from '@wordpress/element';\nimport { compose } from '@wordpress/compose';\nimport { useSelect, withDispatch, withSelect } from '@wordpress/data';\nimport {\n\tMediaUpload,\n\tMediaUploadCheck,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostFeaturedImageCheck from './check';\nimport { store as editorStore } from '../../store';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image' ];\n\n// Used when labels from post type were not yet loaded or when they are not present.\nconst DEFAULT_FEATURE_IMAGE_LABEL = __( 'Featured image' );\nconst DEFAULT_SET_FEATURE_IMAGE_LABEL = __( 'Set featured image' );\n\nconst instructions = (\n\t<p>\n\t\t{ __(\n\t\t\t'To edit the featured image, you need permission to upload media.'\n\t\t) }\n\t</p>\n);\n\nfunction getMediaDetails( media, postId ) {\n\tif ( ! media ) {\n\t\treturn {};\n\t}\n\n\tconst defaultSize = applyFilters(\n\t\t'editor.PostFeaturedImage.imageSize',\n\t\t'large',\n\t\tmedia.id,\n\t\tpostId\n\t);\n\tif ( defaultSize in ( media?.media_details?.sizes ?? {} ) ) {\n\t\treturn {\n\t\t\tmediaWidth: media.media_details.sizes[ defaultSize ].width,\n\t\t\tmediaHeight: media.media_details.sizes[ defaultSize ].height,\n\t\t\tmediaSourceUrl: media.media_details.sizes[ defaultSize ].source_url,\n\t\t};\n\t}\n\n\t// Use fallbackSize when defaultSize is not available.\n\tconst fallbackSize = applyFilters(\n\t\t'editor.PostFeaturedImage.imageSize',\n\t\t'thumbnail',\n\t\tmedia.id,\n\t\tpostId\n\t);\n\tif ( fallbackSize in ( media?.media_details?.sizes ?? {} ) ) {\n\t\treturn {\n\t\t\tmediaWidth: media.media_details.sizes[ fallbackSize ].width,\n\t\t\tmediaHeight: media.media_details.sizes[ fallbackSize ].height,\n\t\t\tmediaSourceUrl:\n\t\t\t\tmedia.media_details.sizes[ fallbackSize ].source_url,\n\t\t};\n\t}\n\n\t// Use full image size when fallbackSize and defaultSize are not available.\n\treturn {\n\t\tmediaWidth: media.media_details.width,\n\t\tmediaHeight: media.media_details.height,\n\t\tmediaSourceUrl: media.source_url,\n\t};\n}\n\nfunction PostFeaturedImage( {\n\tcurrentPostId,\n\tfeaturedImageId,\n\tonUpdateImage,\n\tonRemoveImage,\n\tmedia,\n\tpostType,\n\tnoticeUI,\n\tnoticeOperations,\n} ) {\n\tconst toggleRef = useRef();\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst { mediaWidth, mediaHeight, mediaSourceUrl } = getMediaDetails(\n\t\tmedia,\n\t\tcurrentPostId\n\t);\n\n\tfunction onDropFiles( filesList ) {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\tsetIsLoading( true );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonUpdateImage( image );\n\t\t\t\tsetIsLoading( false );\n\t\t\t},\n\t\t\tonError( message ) {\n\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<PostFeaturedImageCheck>\n\t\t\t{ noticeUI }\n\t\t\t<div className=\"editor-post-featured-image\">\n\t\t\t\t{ media && (\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={ `editor-post-featured-image-${ featuredImageId }-describedby` }\n\t\t\t\t\t\tclassName=\"hidden\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image alt text.\n\t\t\t\t\t\t\t\t__( 'Current image: %s' ),\n\t\t\t\t\t\t\t\tmedia.alt_text\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image filename.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'The current image has no alternative text. The file name is: %s'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tmedia.media_details.sizes?.full?.file ||\n\t\t\t\t\t\t\t\t\tmedia.slug\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<MediaUploadCheck fallback={ instructions }>\n\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\tpostType?.labels?.featured_image ||\n\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t<div className=\"editor-post-featured-image__container\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? 'editor-post-featured-image__toggle'\n\t\t\t\t\t\t\t\t\t\t\t: 'editor-post-featured-image__preview'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Edit or replace the image' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: `editor-post-featured-image-${ featuredImageId }-describedby`\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ !! featuredImageId && media && (\n\t\t\t\t\t\t\t\t\t\t<ResponsiveWrapper\n\t\t\t\t\t\t\t\t\t\t\tnaturalWidth={ mediaWidth }\n\t\t\t\t\t\t\t\t\t\t\tnaturalHeight={ mediaHeight }\n\t\t\t\t\t\t\t\t\t\t\tisInline\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\t\t\tsrc={ mediaSourceUrl }\n\t\t\t\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</ResponsiveWrapper>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ isLoading && <Spinner /> }\n\t\t\t\t\t\t\t\t\t{ ! featuredImageId &&\n\t\t\t\t\t\t\t\t\t\t! isLoading &&\n\t\t\t\t\t\t\t\t\t\t( postType?.labels\n\t\t\t\t\t\t\t\t\t\t\t?.set_featured_image ||\n\t\t\t\t\t\t\t\t\t\t\tDEFAULT_SET_FEATURE_IMAGE_LABEL ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t{ !! featuredImageId && (\n\t\t\t\t\t\t\t\t\t<HStack className=\"editor-post-featured-image__actions\">\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"editor-post-featured-image__action\"\n\t\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\t\t// Prefer that screen readers use the .editor-post-featured-image__preview button.\n\t\t\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Replace' ) }\n\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"editor-post-featured-image__action\"\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tonRemoveImage();\n\t\t\t\t\t\t\t\t\t\t\t\ttoggleRef.current.focus();\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Remove' ) }\n\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onDropFiles } />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tvalue={ featuredImageId }\n\t\t\t\t\t/>\n\t\t\t\t</MediaUploadCheck>\n\t\t\t</div>\n\t\t</PostFeaturedImageCheck>\n\t);\n}\n\nconst applyWithSelect = withSelect( ( select ) => {\n\tconst { getMedia, getPostType } = select( coreStore );\n\tconst { getCurrentPostId, getEditedPostAttribute } = select( editorStore );\n\tconst featuredImageId = getEditedPostAttribute( 'featured_media' );\n\n\treturn {\n\t\tmedia: featuredImageId\n\t\t\t? getMedia( featuredImageId, { context: 'view' } )\n\t\t\t: null,\n\t\tcurrentPostId: getCurrentPostId(),\n\t\tpostType: getPostType( getEditedPostAttribute( 'type' ) ),\n\t\tfeaturedImageId,\n\t};\n} );\n\nconst applyWithDispatch = withDispatch(\n\t( dispatch, { noticeOperations }, { select } ) => {\n\t\tconst { editPost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonUpdateImage( image ) {\n\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t},\n\t\t\tonDropImage( filesList ) {\n\t\t\t\tselect( blockEditorStore )\n\t\t\t\t\t.getSettings()\n\t\t\t\t\t.mediaUpload( {\n\t\t\t\t\t\tallowedTypes: [ 'image' ],\n\t\t\t\t\t\tfilesList,\n\t\t\t\t\t\tonFileChange( [ image ] ) {\n\t\t\t\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError( message ) {\n\t\t\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t},\n\t\t\tonRemoveImage() {\n\t\t\t\teditPost( { featured_media: 0 } );\n\t\t\t},\n\t\t};\n\t}\n);\n\nexport default compose(\n\twithNotices,\n\tapplyWithSelect,\n\tapplyWithDispatch,\n\twithFilters( 'editor.PostFeaturedImage' )\n)( PostFeaturedImage );\n"]}
@@ -19,7 +19,6 @@ import { displayShortcut } from '@wordpress/keycodes';
19
19
  * Internal dependencies
20
20
  */
21
21
 
22
- import PostSwitchToDraftButton from '../post-switch-to-draft-button';
23
22
  import { store as editorStore } from '../../store';
24
23
  /**
25
24
  * Component showing whether the post is saved or not and providing save
@@ -47,10 +46,8 @@ export default function PostSavedState(_ref) {
47
46
  isDirty,
48
47
  isNew,
49
48
  isPending,
50
- isPublished,
51
49
  isSaveable,
52
50
  isSaving,
53
- isScheduled,
54
51
  hasPublishAction
55
52
  } = useSelect(select => {
56
53
  var _getCurrentPost$_link, _getCurrentPost, _getCurrentPost$_link2;
@@ -99,10 +96,6 @@ export default function PostSavedState(_ref) {
99
96
  if (!hasPublishAction && isPending) {
100
97
  return null;
101
98
  }
102
-
103
- if (isPublished || isScheduled) {
104
- return createElement(PostSwitchToDraftButton, null);
105
- }
106
99
  /* translators: button label text should, if possible, be under 16 characters. */
107
100
 
108
101
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-saved-state/index.js"],"names":["classnames","__unstableGetAnimateClassName","getAnimateClassName","Button","usePrevious","useViewportMatch","useDispatch","useSelect","useEffect","useState","__","Icon","check","cloud","cloudUpload","displayShortcut","PostSwitchToDraftButton","store","editorStore","PostSavedState","forceIsDirty","forceIsSaving","showIconLabels","forceSavedMessage","setForceSavedMessage","isLargeViewport","isAutosaving","isDirty","isNew","isPending","isPublished","isSaveable","isSaving","isScheduled","hasPublishAction","select","isEditedPostNew","isCurrentPostPublished","isCurrentPostScheduled","isEditedPostDirty","isSavingPost","isEditedPostSaveable","getCurrentPost","isAutosavingPost","getEditedPostAttribute","_links","savePost","wasSaving","timeoutId","setTimeout","clearTimeout","label","shortLabel","isSaved","isSavedState","isDisabled","text","type","undefined","primary"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;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C,eAAe,CAAC4C,OAAhB,CAAyB,GAAzB;AACpC;AACH;AACA;AACA;AACA;AACA;AA1BE;AA2BC,IAAA,WAAW,MA3BZ;AA4BC,IAAA,OAAO,EAAC,UA5BT;AA6BC,IAAA,IAAI,EAAGlC,eAAe,GAAGiC,SAAH,GAAe5C,WA7BtC,CA8BC;AA9BD;AA+BC,IAAA,KAAK,EAAG0C,IAAI,IAAIL,KA/BjB;AAgCC,qBAAgBI;AAhCjB,KAkCGD,YAAY,IAAI,cAAC,IAAD;AAAM,IAAA,IAAI,EAAGD,OAAO,GAAGzC,KAAH,GAAWC;AAA/B,IAlCnB,EAmCG2C,IAnCH,CADD;AAuCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__unstableGetAnimateClassName as getAnimateClassName,\n\tButton,\n} from '@wordpress/components';\nimport { usePrevious, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, check, cloud, cloudUpload } from '@wordpress/icons';\nimport { displayShortcut } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport PostSwitchToDraftButton from '../post-switch-to-draft-button';\nimport { store as editorStore } from '../../store';\n\n/**\n * Component showing whether the post is saved or not and providing save\n * buttons.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.forceIsDirty Whether to force the post to be marked\n * as dirty.\n * @param {?boolean} props.forceIsSaving Whether to force the post to be marked\n * as being saved.\n * @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons\n * @return {import('@wordpress/element').WPComponent} The component.\n */\nexport default function PostSavedState( {\n\tforceIsDirty,\n\tforceIsSaving,\n\tshowIconLabels = false,\n} ) {\n\tconst [ forceSavedMessage, setForceSavedMessage ] = useState( false );\n\tconst isLargeViewport = useViewportMatch( 'small' );\n\n\tconst {\n\t\tisAutosaving,\n\t\tisDirty,\n\t\tisNew,\n\t\tisPending,\n\t\tisPublished,\n\t\tisSaveable,\n\t\tisSaving,\n\t\tisScheduled,\n\t\thasPublishAction,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tisEditedPostNew,\n\t\t\t\tisCurrentPostPublished,\n\t\t\t\tisCurrentPostScheduled,\n\t\t\t\tisEditedPostDirty,\n\t\t\t\tisSavingPost,\n\t\t\t\tisEditedPostSaveable,\n\t\t\t\tgetCurrentPost,\n\t\t\t\tisAutosavingPost,\n\t\t\t\tgetEditedPostAttribute,\n\t\t\t} = select( editorStore );\n\n\t\t\treturn {\n\t\t\t\tisAutosaving: isAutosavingPost(),\n\t\t\t\tisDirty: forceIsDirty || isEditedPostDirty(),\n\t\t\t\tisNew: isEditedPostNew(),\n\t\t\t\tisPending: 'pending' === getEditedPostAttribute( 'status' ),\n\t\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\t\tisSaving: forceIsSaving || isSavingPost(),\n\t\t\t\tisSaveable: isEditedPostSaveable(),\n\t\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t\t\thasPublishAction:\n\t\t\t\t\tgetCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false,\n\t\t\t};\n\t\t},\n\t\t[ forceIsDirty, forceIsSaving ]\n\t);\n\n\tconst { savePost } = useDispatch( editorStore );\n\n\tconst wasSaving = usePrevious( isSaving );\n\n\tuseEffect( () => {\n\t\tlet timeoutId;\n\n\t\tif ( wasSaving && ! isSaving ) {\n\t\t\tsetForceSavedMessage( true );\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tsetForceSavedMessage( false );\n\t\t\t}, 1000 );\n\t\t}\n\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ isSaving ] );\n\n\t// Once the post has been submitted for review this button\n\t// is not needed for the contributor role.\n\tif ( ! hasPublishAction && isPending ) {\n\t\treturn null;\n\t}\n\n\tif ( isPublished || isScheduled ) {\n\t\treturn <PostSwitchToDraftButton />;\n\t}\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst label = isPending ? __( 'Save as pending' ) : __( 'Save draft' );\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst shortLabel = __( 'Save' );\n\n\tconst isSaved = forceSavedMessage || ( ! isNew && ! isDirty );\n\tconst isSavedState = isSaving || isSaved;\n\tconst isDisabled = isSaving || isSaved || ! isSaveable;\n\n\tlet text;\n\n\tif ( isSaving ) {\n\t\ttext = isAutosaving ? __( 'Autosaving' ) : __( 'Saving' );\n\t} else if ( isSaved ) {\n\t\ttext = __( 'Saved' );\n\t} else if ( isLargeViewport ) {\n\t\ttext = label;\n\t} else if ( showIconLabels ) {\n\t\ttext = shortLabel;\n\t}\n\n\t// Use common Button instance for all saved states so that focus is not\n\t// lost.\n\treturn (\n\t\t<Button\n\t\t\tclassName={\n\t\t\t\tisSaveable || isSaving\n\t\t\t\t\t? classnames( {\n\t\t\t\t\t\t\t'editor-post-save-draft': ! isSavedState,\n\t\t\t\t\t\t\t'editor-post-saved-state': isSavedState,\n\t\t\t\t\t\t\t'is-saving': isSaving,\n\t\t\t\t\t\t\t'is-autosaving': isAutosaving,\n\t\t\t\t\t\t\t'is-saved': isSaved,\n\t\t\t\t\t\t\t[ getAnimateClassName( {\n\t\t\t\t\t\t\t\ttype: 'loading',\n\t\t\t\t\t\t\t} ) ]: isSaving,\n\t\t\t\t\t } )\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tonClick={ isDisabled ? undefined : () => savePost() }\n\t\t\t/*\n\t\t\t * We want the tooltip to show the keyboard shortcut only when the\n\t\t\t * button does something, i.e. when it's not disabled.\n\t\t\t */\n\t\t\tshortcut={ isDisabled ? undefined : displayShortcut.primary( 's' ) }\n\t\t\t/*\n\t\t\t * Displaying the keyboard shortcut conditionally makes the tooltip\n\t\t\t * itself show conditionally. This would trigger a full-rerendering\n\t\t\t * of the button that we want to avoid. By setting `showTooltip`,\n\t\t\t & the tooltip is always rendered even when there's no keyboard shortcut.\n\t\t\t */\n\t\t\tshowTooltip\n\t\t\tvariant=\"tertiary\"\n\t\t\ticon={ isLargeViewport ? undefined : cloudUpload }\n\t\t\t// Make sure the aria-label has always a value, as the default `text` is undefined on small screens.\n\t\t\tlabel={ text || label }\n\t\t\taria-disabled={ isDisabled }\n\t\t>\n\t\t\t{ isSavedState && <Icon icon={ isSaved ? check : cloud } /> }\n\t\t\t{ text }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-saved-state/index.js"],"names":["classnames","__unstableGetAnimateClassName","getAnimateClassName","Button","usePrevious","useViewportMatch","useDispatch","useSelect","useEffect","useState","__","Icon","check","cloud","cloudUpload","displayShortcut","store","editorStore","PostSavedState","forceIsDirty","forceIsSaving","showIconLabels","forceSavedMessage","setForceSavedMessage","isLargeViewport","isAutosaving","isDirty","isNew","isPending","isSaveable","isSaving","hasPublishAction","select","isEditedPostNew","isCurrentPostPublished","isCurrentPostScheduled","isEditedPostDirty","isSavingPost","isEditedPostSaveable","getCurrentPost","isAutosavingPost","getEditedPostAttribute","isPublished","isScheduled","_links","savePost","wasSaving","timeoutId","setTimeout","clearTimeout","label","shortLabel","isSaved","isSavedState","isDisabled","text","type","undefined","primary"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,6BAA6B,IAAIC,mBADlC,EAECC,MAFD,QAGO,uBAHP;AAIA,SAASC,WAAT,EAAsBC,gBAAtB,QAA8C,oBAA9C;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,oBAApC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,IAAT,EAAeC,KAAf,EAAsBC,KAAtB,EAA6BC,WAA7B,QAAgD,kBAAhD;AACA,SAASC,eAAT,QAAgC,qBAAhC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,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AA,IAAI,GAAG7C,EAAE,CAAE,OAAF,CAAT;AACA,GAFM,MAEA,IAAKc,eAAL,EAAuB;AAC7B+B,IAAAA,IAAI,GAAGL,KAAP;AACA,GAFM,MAEA,IAAK7B,cAAL,EAAsB;AAC5BkC,IAAAA,IAAI,GAAGJ,UAAP;AACA,GArFE,CAuFH;AACA;;;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EACRtB,UAAU,IAAIC,QAAd,GACG9B,UAAU,CAAE;AACZ,gCAA0B,CAAEqD,YADhB;AAEZ,iCAA2BA,YAFf;AAGZ,mBAAavB,QAHD;AAIZ,uBAAiBL,YAJL;AAKZ,kBAAY2B,OALA;AAMZ,OAAElD,mBAAmB,CAAE;AACtBsD,QAAAA,IAAI,EAAE;AADgB,OAAF,CAArB,GAEO1B;AARK,KAAF,CADb,GAWG2B,SAbL;AAeC,IAAA,OAAO,EAAGH,UAAU,GAAGG,SAAH,GAAe,MAAMZ,QAAQ;AACjD;AACH;AACA;AACA;AAnBE;AAoBC,IAAA,QAAQ,EAAGS,UAAU,GAAGG,SAAH,GAAe1C,eAAe,CAAC2C,OAAhB,CAAyB,GAAzB;AACpC;AACH;AACA;AACA;AACA;AACA;AA1BE;AA2BC,IAAA,WAAW,MA3BZ;AA4BC,IAAA,OAAO,EAAC,UA5BT;AA6BC,IAAA,IAAI,EAAGlC,eAAe,GAAGiC,SAAH,GAAe3C,WA7BtC,CA8BC;AA9BD;AA+BC,IAAA,KAAK,EAAGyC,IAAI,IAAIL,KA/BjB;AAgCC,qBAAgBI;AAhCjB,KAkCGD,YAAY,IAAI,cAAC,IAAD;AAAM,IAAA,IAAI,EAAGD,OAAO,GAAGxC,KAAH,GAAWC;AAA/B,IAlCnB,EAmCG0C,IAnCH,CADD;AAuCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__unstableGetAnimateClassName as getAnimateClassName,\n\tButton,\n} from '@wordpress/components';\nimport { usePrevious, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, check, cloud, cloudUpload } from '@wordpress/icons';\nimport { displayShortcut } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\n/**\n * Component showing whether the post is saved or not and providing save\n * buttons.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.forceIsDirty Whether to force the post to be marked\n * as dirty.\n * @param {?boolean} props.forceIsSaving Whether to force the post to be marked\n * as being saved.\n * @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons\n * @return {import('@wordpress/element').WPComponent} The component.\n */\nexport default function PostSavedState( {\n\tforceIsDirty,\n\tforceIsSaving,\n\tshowIconLabels = false,\n} ) {\n\tconst [ forceSavedMessage, setForceSavedMessage ] = useState( false );\n\tconst isLargeViewport = useViewportMatch( 'small' );\n\n\tconst {\n\t\tisAutosaving,\n\t\tisDirty,\n\t\tisNew,\n\t\tisPending,\n\t\tisSaveable,\n\t\tisSaving,\n\t\thasPublishAction,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tisEditedPostNew,\n\t\t\t\tisCurrentPostPublished,\n\t\t\t\tisCurrentPostScheduled,\n\t\t\t\tisEditedPostDirty,\n\t\t\t\tisSavingPost,\n\t\t\t\tisEditedPostSaveable,\n\t\t\t\tgetCurrentPost,\n\t\t\t\tisAutosavingPost,\n\t\t\t\tgetEditedPostAttribute,\n\t\t\t} = select( editorStore );\n\n\t\t\treturn {\n\t\t\t\tisAutosaving: isAutosavingPost(),\n\t\t\t\tisDirty: forceIsDirty || isEditedPostDirty(),\n\t\t\t\tisNew: isEditedPostNew(),\n\t\t\t\tisPending: 'pending' === getEditedPostAttribute( 'status' ),\n\t\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\t\tisSaving: forceIsSaving || isSavingPost(),\n\t\t\t\tisSaveable: isEditedPostSaveable(),\n\t\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t\t\thasPublishAction:\n\t\t\t\t\tgetCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false,\n\t\t\t};\n\t\t},\n\t\t[ forceIsDirty, forceIsSaving ]\n\t);\n\n\tconst { savePost } = useDispatch( editorStore );\n\n\tconst wasSaving = usePrevious( isSaving );\n\n\tuseEffect( () => {\n\t\tlet timeoutId;\n\n\t\tif ( wasSaving && ! isSaving ) {\n\t\t\tsetForceSavedMessage( true );\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tsetForceSavedMessage( false );\n\t\t\t}, 1000 );\n\t\t}\n\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ isSaving ] );\n\n\t// Once the post has been submitted for review this button\n\t// is not needed for the contributor role.\n\tif ( ! hasPublishAction && isPending ) {\n\t\treturn null;\n\t}\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst label = isPending ? __( 'Save as pending' ) : __( 'Save draft' );\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst shortLabel = __( 'Save' );\n\n\tconst isSaved = forceSavedMessage || ( ! isNew && ! isDirty );\n\tconst isSavedState = isSaving || isSaved;\n\tconst isDisabled = isSaving || isSaved || ! isSaveable;\n\n\tlet text;\n\n\tif ( isSaving ) {\n\t\ttext = isAutosaving ? __( 'Autosaving' ) : __( 'Saving' );\n\t} else if ( isSaved ) {\n\t\ttext = __( 'Saved' );\n\t} else if ( isLargeViewport ) {\n\t\ttext = label;\n\t} else if ( showIconLabels ) {\n\t\ttext = shortLabel;\n\t}\n\n\t// Use common Button instance for all saved states so that focus is not\n\t// lost.\n\treturn (\n\t\t<Button\n\t\t\tclassName={\n\t\t\t\tisSaveable || isSaving\n\t\t\t\t\t? classnames( {\n\t\t\t\t\t\t\t'editor-post-save-draft': ! isSavedState,\n\t\t\t\t\t\t\t'editor-post-saved-state': isSavedState,\n\t\t\t\t\t\t\t'is-saving': isSaving,\n\t\t\t\t\t\t\t'is-autosaving': isAutosaving,\n\t\t\t\t\t\t\t'is-saved': isSaved,\n\t\t\t\t\t\t\t[ getAnimateClassName( {\n\t\t\t\t\t\t\t\ttype: 'loading',\n\t\t\t\t\t\t\t} ) ]: isSaving,\n\t\t\t\t\t } )\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tonClick={ isDisabled ? undefined : () => savePost() }\n\t\t\t/*\n\t\t\t * We want the tooltip to show the keyboard shortcut only when the\n\t\t\t * button does something, i.e. when it's not disabled.\n\t\t\t */\n\t\t\tshortcut={ isDisabled ? undefined : displayShortcut.primary( 's' ) }\n\t\t\t/*\n\t\t\t * Displaying the keyboard shortcut conditionally makes the tooltip\n\t\t\t * itself show conditionally. This would trigger a full-rerendering\n\t\t\t * of the button that we want to avoid. By setting `showTooltip`,\n\t\t\t & the tooltip is always rendered even when there's no keyboard shortcut.\n\t\t\t */\n\t\t\tshowTooltip\n\t\t\tvariant=\"tertiary\"\n\t\t\ticon={ isLargeViewport ? undefined : cloudUpload }\n\t\t\t// Make sure the aria-label has always a value, as the default `text` is undefined on small screens.\n\t\t\tlabel={ text || label }\n\t\t\taria-disabled={ isDisabled }\n\t\t>\n\t\t\t{ isSavedState && <Icon icon={ isSaved ? check : cloud } /> }\n\t\t\t{ text }\n\t\t</Button>\n\t);\n}\n"]}
@@ -1,12 +1,12 @@
1
- import { createElement, Fragment } from "@wordpress/element";
1
+ import { createElement } from "@wordpress/element";
2
2
 
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
- import { Button, __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
6
+ import { Button, FlexItem, __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
7
7
  import { __ } from '@wordpress/i18n';
8
8
  import { withSelect, withDispatch } from '@wordpress/data';
9
- import { compose, useViewportMatch } from '@wordpress/compose';
9
+ import { compose } from '@wordpress/compose';
10
10
  import { useState } from '@wordpress/element';
11
11
  /**
12
12
  * Internal dependencies
@@ -21,7 +21,6 @@ function PostSwitchToDraftButton(_ref) {
21
21
  isScheduled,
22
22
  onClick
23
23
  } = _ref;
24
- const isMobileViewport = useViewportMatch('small', '<');
25
24
  const [showConfirmDialog, setShowConfirmDialog] = useState(false);
26
25
 
27
26
  if (!isPublished && !isScheduled) {
@@ -41,14 +40,20 @@ function PostSwitchToDraftButton(_ref) {
41
40
  onClick();
42
41
  };
43
42
 
44
- return createElement(Fragment, null, createElement(Button, {
43
+ return createElement(FlexItem, {
44
+ isBlock: true
45
+ }, createElement(Button, {
45
46
  className: "editor-post-switch-to-draft",
46
47
  onClick: () => {
47
48
  setShowConfirmDialog(true);
48
49
  },
49
50
  disabled: isSaving,
50
- variant: "tertiary"
51
- }, isMobileViewport ? __('Draft') : __('Switch to draft')), createElement(ConfirmDialog, {
51
+ variant: "secondary",
52
+ style: {
53
+ width: '100%',
54
+ display: 'block'
55
+ }
56
+ }, __('Switch to draft')), createElement(ConfirmDialog, {
52
57
  isOpen: showConfirmDialog,
53
58
  onConfirm: handleConfirm,
54
59
  onCancel: () => setShowConfirmDialog(false)
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-switch-to-draft-button/index.js"],"names":["Button","__experimentalConfirmDialog","ConfirmDialog","__","withSelect","withDispatch","compose","useViewportMatch","useState","store","editorStore","PostSwitchToDraftButton","isSaving","isPublished","isScheduled","onClick","isMobileViewport","showConfirmDialog","setShowConfirmDialog","alertMessage","handleConfirm","select","isSavingPost","isCurrentPostPublished","isCurrentPostScheduled","dispatch","editPost","savePost","status"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,MADD,EAECC,2BAA2B,IAAIC,aAFhC,QAGO,uBAHP;AAIA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,iBAAzC;AACA,SAASC,OAAT,EAAkBC,gBAAlB,QAA0C,oBAA1C;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA;AACA;AACA;;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;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA,sBAAhB;AAAwCC,IAAAA;AAAxC,MACLH,MAAM,CAAEX,WAAF,CADP;AAEA,SAAO;AACNE,IAAAA,QAAQ,EAAEU,YAAY,EADhB;AAENT,IAAAA,WAAW,EAAEU,sBAAsB,EAF7B;AAGNT,IAAAA,WAAW,EAAEU,sBAAsB;AAH7B,GAAP;AAKA,CARS,CADa,EAUvBnB,YAAY,CAAIoB,QAAF,IAAgB;AAC7B,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAyBF,QAAQ,CAAEf,WAAF,CAAvC;AACA,SAAO;AACNK,IAAAA,OAAO,EAAE,MAAM;AACdW,MAAAA,QAAQ,CAAE;AAAEE,QAAAA,MAAM,EAAE;AAAV,OAAF,CAAR;AACAD,MAAAA,QAAQ;AACR;AAJK,GAAP;AAMA,CARW,CAVW,CAAF,CAAP,CAmBVhB,uBAnBU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose, useViewportMatch } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nfunction PostSwitchToDraftButton( {\n\tisSaving,\n\tisPublished,\n\tisScheduled,\n\tonClick,\n} ) {\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\tconst [ showConfirmDialog, setShowConfirmDialog ] = useState( false );\n\n\tif ( ! isPublished && ! isScheduled ) {\n\t\treturn null;\n\t}\n\n\tlet alertMessage;\n\tif ( isPublished ) {\n\t\talertMessage = __( 'Are you sure you want to unpublish this post?' );\n\t} else if ( isScheduled ) {\n\t\talertMessage = __( 'Are you sure you want to unschedule this post?' );\n\t}\n\n\tconst handleConfirm = () => {\n\t\tsetShowConfirmDialog( false );\n\t\tonClick();\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tclassName=\"editor-post-switch-to-draft\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetShowConfirmDialog( true );\n\t\t\t\t} }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t>\n\t\t\t\t{ isMobileViewport ? __( 'Draft' ) : __( 'Switch to draft' ) }\n\t\t\t</Button>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ showConfirmDialog }\n\t\t\t\tonConfirm={ handleConfirm }\n\t\t\t\tonCancel={ () => setShowConfirmDialog( false ) }\n\t\t\t>\n\t\t\t\t{ alertMessage }\n\t\t\t</ConfirmDialog>\n\t\t</>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\tconst { isSavingPost, isCurrentPostPublished, isCurrentPostScheduled } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\tisSaving: isSavingPost(),\n\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { editPost, savePost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonClick: () => {\n\t\t\t\teditPost( { status: 'draft' } );\n\t\t\t\tsavePost();\n\t\t\t},\n\t\t};\n\t} ),\n] )( PostSwitchToDraftButton );\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-switch-to-draft-button/index.js"],"names":["Button","FlexItem","__experimentalConfirmDialog","ConfirmDialog","__","withSelect","withDispatch","compose","useState","store","editorStore","PostSwitchToDraftButton","isSaving","isPublished","isScheduled","onClick","showConfirmDialog","setShowConfirmDialog","alertMessage","handleConfirm","width","display","select","isSavingPost","isCurrentPostPublished","isCurrentPostScheduled","dispatch","editPost","savePost","status"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,MADD,EAECC,QAFD,EAGCC,2BAA2B,IAAIC,aAHhC,QAIO,u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A,SAAS,EAAGG,aAFb;AAGC,IAAA,QAAQ,EAAG,MAAMF,oBAAoB,CAAE,KAAF;AAHtC,KAKGC,YALH,CAZD,CADD;AAsBA;;AAED,eAAeX,OAAO,CAAE,CACvBF,UAAU,CAAIiB,MAAF,IAAc;AACzB,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA,sBAAhB;AAAwCC,IAAAA;AAAxC,MACLH,MAAM,CAAEZ,WAAF,CADP;AAEA,SAAO;AACNE,IAAAA,QAAQ,EAAEW,YAAY,EADhB;AAENV,IAAAA,WAAW,EAAEW,sBAAsB,EAF7B;AAGNV,IAAAA,WAAW,EAAEW,sBAAsB;AAH7B,GAAP;AAKA,CARS,CADa,EAUvBnB,YAAY,CAAIoB,QAAF,IAAgB;AAC7B,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAyBF,QAAQ,CAAEhB,WAAF,CAAvC;AACA,SAAO;AACNK,IAAAA,OAAO,EAAE,MAAM;AACdY,MAAAA,QAAQ,CAAE;AAAEE,QAAAA,MAAM,EAAE;AAAV,OAAF,CAAR;AACAD,MAAAA,QAAQ;AACR;AAJK,GAAP;AAMA,CARW,CAVW,CAAF,CAAP,CAmBVjB,uBAnBU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tFlexItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nfunction PostSwitchToDraftButton( {\n\tisSaving,\n\tisPublished,\n\tisScheduled,\n\tonClick,\n} ) {\n\tconst [ showConfirmDialog, setShowConfirmDialog ] = useState( false );\n\n\tif ( ! isPublished && ! isScheduled ) {\n\t\treturn null;\n\t}\n\n\tlet alertMessage;\n\tif ( isPublished ) {\n\t\talertMessage = __( 'Are you sure you want to unpublish this post?' );\n\t} else if ( isScheduled ) {\n\t\talertMessage = __( 'Are you sure you want to unschedule this post?' );\n\t}\n\n\tconst handleConfirm = () => {\n\t\tsetShowConfirmDialog( false );\n\t\tonClick();\n\t};\n\n\treturn (\n\t\t<FlexItem isBlock>\n\t\t\t<Button\n\t\t\t\tclassName=\"editor-post-switch-to-draft\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetShowConfirmDialog( true );\n\t\t\t\t} }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tstyle={ { width: '100%', display: 'block' } }\n\t\t\t>\n\t\t\t\t{ __( 'Switch to draft' ) }\n\t\t\t</Button>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ showConfirmDialog }\n\t\t\t\tonConfirm={ handleConfirm }\n\t\t\t\tonCancel={ () => setShowConfirmDialog( false ) }\n\t\t\t>\n\t\t\t\t{ alertMessage }\n\t\t\t</ConfirmDialog>\n\t\t</FlexItem>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\tconst { isSavingPost, isCurrentPostPublished, isCurrentPostScheduled } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\tisSaving: isSavingPost(),\n\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { editPost, savePost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonClick: () => {\n\t\t\t\teditPost( { status: 'draft' } );\n\t\t\t\tsavePost();\n\t\t\t},\n\t\t};\n\t} ),\n] )( PostSwitchToDraftButton );\n"]}
@@ -1,13 +1,8 @@
1
1
  import { createElement } from "@wordpress/element";
2
2
 
3
- /**
4
- * External dependencies
5
- */
6
- import { isEmpty } from 'lodash';
7
3
  /**
8
4
  * WordPress dependencies
9
5
  */
10
-
11
6
  import { __ } from '@wordpress/i18n';
12
7
  import { SelectControl } from '@wordpress/components';
13
8
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -43,7 +38,7 @@ export function PostTemplate() {
43
38
  editPost
44
39
  } = useDispatch(editorStore);
45
40
 
46
- if (!isViewable || isEmpty(availableTemplates)) {
41
+ if (!isViewable || !availableTemplates || !Object.keys(availableTemplates).length) {
47
42
  return null;
48
43
  }
49
44
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-template/index.js"],"names":["isEmpty","__","SelectControl","useSelect","useDispatch","store","coreStore","editorStore","PostTemplate","availableTemplates","selectedTemplate","isViewable","select","getEditedPostAttribute","getEditorSettings","getCurrentPostType","getPostType","viewable","editPost","templateSlug","template","Object","entries","map","templateName","value","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,aAAT,QAA8B,uBAA9B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASD,KAAK,IAAIE,WAAlB,QAAqC,aAArC;AAEA,OAAO,SAASC,YAAT,GAAwB;AAC9B,QAAM;AAAEC,IAAAA,kBAAF;AAAsBC,IAAAA,gBAAtB;AAAwCC,IAAAA;AAAxC,MAAuDR,SAAS,CACnES,MAAF,IAAc;AAAA;;AACb,UAAM;AACLC,MAAAA,sBADK;AAELC,MAAAA,iBAFK;AAGLC,MAAAA;AAHK,QAIFH,MAAM,CAAEL,WAAF,CAJV;AAKA,UAAM;AAAES,MAAAA;AAAF,QAAkBJ,MAAM,CAAEN,SAAF,CAA9B;AAEA,WAAO;AACNI,MAAAA,gBAAgB,EAAEG,sBAAsB,CAAE,UAAF,CADlC;AAENJ,MAAAA,kBAAkB,EAAEK,iBAAiB,GAAGL,kBAFlC;AAGNE,MAAAA,UAAU,2CACTK,WAAW,CAAED,kBAAkB,EAApB,CADF,iDACT,aAAqCE,QAD5B,yEACwC;AAJ5C,KAAP;AAMA,GAfoE,EAgBrE,EAhBqE,CAAtE;AAmBA,QAAM;AAAEC,IAAAA;AAAF,MAAed,WAAW,CAAEG,WAAF,CAAhC;;AAEA,MAAK,CAAEI,UAAF,IAAgBX,OAAO,CAAES,kBAAF,CAA5B,EAAqD;AACpD,WAAO,IAAP;AACA;;AAED,SACC,cAAC,aAAD;AACC,IAAA,uBAAuB,MADxB;AAEC,IAAA,KAAK,EAAGR,EAAE,CAAE,WAAF,CAFX;AAGC,IAAA,KAAK,EAAGS,gBAHT;AAIC,IAAA,QAAQ,EAAKS,YAAF,IAAoB;AAC9BD,MAAAA,QAAQ,CAAE;AACTE,QAAAA,QAAQ,EAAED,YAAY,IAAI;AADjB,OAAF,CAAR;AAGA,KARF;AASC,IAAA,OAAO,EAAGE,MAAM,CAACC,OAAP,CAAgBb,kBAAhB,aAAgBA,kBAAhB,cAAgBA,kBAAhB,GAAsC,EAAtC,EAA2Cc,GAA3C,CACT;AAAA,UAAE,CAAEJ,YAAF,EAAgBK,YAAhB,CAAF;AAAA,aAAwC;AACvCC,QAAAA,KAAK,EAAEN,YADgC;AAEvCO,QAAAA,KAAK,EAAEF;AAFgC,OAAxC;AAAA,KADS;AATX,IADD;AAkBA;AAED,eAAehB,YAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { SelectControl } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function PostTemplate() {\n\tconst { availableTemplates, selectedTemplate, isViewable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedPostAttribute,\n\t\t\t\tgetEditorSettings,\n\t\t\t\tgetCurrentPostType,\n\t\t\t} = select( editorStore );\n\t\t\tconst { getPostType } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tselectedTemplate: getEditedPostAttribute( 'template' ),\n\t\t\t\tavailableTemplates: getEditorSettings().availableTemplates,\n\t\t\t\tisViewable:\n\t\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif ( ! isViewable || isEmpty( availableTemplates ) ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<SelectControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Template:' ) }\n\t\t\tvalue={ selectedTemplate }\n\t\t\tonChange={ ( templateSlug ) => {\n\t\t\t\teditPost( {\n\t\t\t\t\ttemplate: templateSlug || '',\n\t\t\t\t} );\n\t\t\t} }\n\t\t\toptions={ Object.entries( availableTemplates ?? {} ).map(\n\t\t\t\t( [ templateSlug, templateName ] ) => ( {\n\t\t\t\t\tvalue: templateSlug,\n\t\t\t\t\tlabel: templateName,\n\t\t\t\t} )\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default PostTemplate;\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-template/index.js"],"names":["__","SelectControl","useSelect","useDispatch","store","coreStore","editorStore","PostTemplate","availableTemplates","selectedTemplate","isViewable","select","getEditedPostAttribute","getEditorSettings","getCurrentPostType","getPostType","viewable","editPost","Object","keys","length","templateSlug","template","entries","map","templateName","value","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,aAAT,QAA8B,uBAA9B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASD,KAAK,IAAIE,WAAlB,QAAqC,aAArC;AAEA,OAAO,SAASC,YAAT,GAAwB;AAC9B,QAAM;AAAEC,IAAAA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KAAK,EAAEF;AAFgC,OAAxC;AAAA,KADS;AATX,IADD;AAkBA;AAED,eAAelB,YAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { SelectControl } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function PostTemplate() {\n\tconst { availableTemplates, selectedTemplate, isViewable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedPostAttribute,\n\t\t\t\tgetEditorSettings,\n\t\t\t\tgetCurrentPostType,\n\t\t\t} = select( editorStore );\n\t\t\tconst { getPostType } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tselectedTemplate: getEditedPostAttribute( 'template' ),\n\t\t\t\tavailableTemplates: getEditorSettings().availableTemplates,\n\t\t\t\tisViewable:\n\t\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif (\n\t\t! isViewable ||\n\t\t! availableTemplates ||\n\t\t! Object.keys( availableTemplates ).length\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<SelectControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Template:' ) }\n\t\t\tvalue={ selectedTemplate }\n\t\t\tonChange={ ( templateSlug ) => {\n\t\t\t\teditPost( {\n\t\t\t\t\ttemplate: templateSlug || '',\n\t\t\t\t} );\n\t\t\t} }\n\t\t\toptions={ Object.entries( availableTemplates ?? {} ).map(\n\t\t\t\t( [ templateSlug, templateName ] ) => ( {\n\t\t\t\t\tvalue: templateSlug,\n\t\t\t\t\tlabel: templateName,\n\t\t\t\t} )\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default PostTemplate;\n"]}
@@ -28,6 +28,7 @@ class PostTitle extends Component {
28
28
  constructor(props) {
29
29
  super(props);
30
30
  this.setRef = this.setRef.bind(this);
31
+ this.onPaste = this.onPaste.bind(this);
31
32
  }
32
33
 
33
34
  componentDidUpdate(prevProps) {
@@ -59,19 +60,35 @@ class PostTitle extends Component {
59
60
  let {
60
61
  value,
61
62
  onChange,
62
- plainText
63
+ plainText,
64
+ html
63
65
  } = _ref;
66
+ const {
67
+ title,
68
+ onInsertBlockAfter,
69
+ onUpdate
70
+ } = this.props;
64
71
  const content = pasteHandler({
65
- plainText,
66
- mode: 'INLINE',
67
- tagName: 'p'
72
+ HTML: html,
73
+ plainText
68
74
  });
69
75
 
70
- if (typeof content === 'string') {
71
- const valueToInsert = create({
72
- html: content
73
- });
74
- onChange(insert(value, valueToInsert));
76
+ if (content.length) {
77
+ if (typeof content === 'string') {
78
+ const valueToInsert = create({
79
+ html: content
80
+ });
81
+ onChange(insert(value, valueToInsert));
82
+ } else {
83
+ const [firstBlock] = content;
84
+
85
+ if (!title && (firstBlock.name === 'core/heading' || firstBlock.name === 'core/paragraph')) {
86
+ onUpdate(firstBlock.attributes.content);
87
+ onInsertBlockAfter(content.slice(1));
88
+ } else {
89
+ onInsertBlockAfter(content);
90
+ }
91
+ }
75
92
  }
76
93
  }
77
94
 
@@ -170,6 +187,7 @@ export default compose(withSelect(select => {
170
187
  const globalStyles = (_getSettings = getSettings()) === null || _getSettings === void 0 ? void 0 : (_getSettings$__experi = _getSettings.__experimentalGlobalStylesBaseStyles) === null || _getSettings$__experi === void 0 ? void 0 : _getSettings$__experi.color;
171
188
  return {
172
189
  postType: getEditedPostAttribute('type'),
190
+ title: getEditedPostAttribute('title'),
173
191
  isAnyBlockSelected: !!selectedId,
174
192
  isSelected: isPostTitleSelected(),
175
193
  isDimmed: selectionIsNested,
@@ -179,11 +197,13 @@ export default compose(withSelect(select => {
179
197
  const {
180
198
  undo,
181
199
  redo,
182
- togglePostTitleSelection
200
+ togglePostTitleSelection,
201
+ editPost
183
202
  } = dispatch(editorStore);
184
203
  const {
185
204
  clearSelectedBlock,
186
- insertDefaultBlock
205
+ insertDefaultBlock,
206
+ insertBlocks
187
207
  } = dispatch(blockEditorStore);
188
208
  return {
189
209
  onEnterPress() {
@@ -200,6 +220,16 @@ export default compose(withSelect(select => {
200
220
 
201
221
  onUnselect() {
202
222
  togglePostTitleSelection(false);
223
+ },
224
+
225
+ onUpdate(title) {
226
+ editPost({
227
+ title
228
+ });
229
+ },
230
+
231
+ onInsertBlockAfter(blocks) {
232
+ insertBlocks(blocks, 0);
203
233
  }
204
234
 
205
235
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"names":["View","Component","__experimentalRichText","RichText","create","insert","decodeEntities","withDispatch","withSelect","withFocusOutside","withInstanceId","compose","__","sprintf","pasteHandler","store","blockEditorStore","editorStore","styles","PostTitle","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","titleContainer","dimmed","onBlur","onUpdate","onEnterPress","select","isPostTitleSelected","getEditedPostAttribute","getSelectedBlockClientId","getBlockRootClientId","getSettings","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","dispatch","undo","redo","togglePostTitleSelection","clearSelectedBlock","insertDefaultBlock","undefined","onUndo","onRedo"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,cAArB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SACCC,sBAAsB,IAAIC,QAD3B,EAECC,MAFD,EAGCC,MAHD,QAIO,sBAJP;AAKA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,YAAT,EAAuBC,UAAvB,QAAyC,iBAAzC;AACA,SAASC,g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A,SAAO;AACNkD,IAAAA,YAAY,GAAG;AACde,MAAAA,kBAAkB,CAAEC,SAAF,EAAaA,SAAb,EAAwB,CAAxB,CAAlB;AACA,KAHK;;AAINC,IAAAA,MAAM,EAAEN,IAJF;AAKNO,IAAAA,MAAM,EAAEN,IALF;;AAMN3C,IAAAA,QAAQ,GAAG;AACV4C,MAAAA,wBAAwB,CAAE,IAAF,CAAxB;AACAC,MAAAA,kBAAkB;AAClB,KATK;;AAUNlD,IAAAA,UAAU,GAAG;AACZiD,MAAAA,wBAAwB,CAAE,KAAF,CAAxB;AACA;;AAZK,GAAP;AAcA,CArBW,CApBS,EA0CrBrE,cA1CqB,EA2CrBD,gBA3CqB,CAAP,CA4CZU,SA5CY,CAAf","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":["View","Component","__experimentalRichText","RichText","create","insert","decodeEntities","withDispatch","withSelect","withFocusOutside","withInstanceId","compose","__","sprintf","pasteHandler","store","blockEditorStore","editorStore","styles","PostTitle","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","titleContainer","dimmed","onBlur","onEnterPress","select","isPostTitleSelected","getEditedPostAttribute","getSelectedBlockClientId","getBlockRootClientId","getSettings","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","dispatch","undo","redo","togglePostTitleSelection","editPost","clearSelectedBlock","insertDefaultBlock","insertBlocks","undefined","onUndo","onRedo","blocks"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,cAArB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SACCC,sBAAsB,IAAIC,QAD3B,EAECC,MAFD,EAGCC,MAHD,QAIO,sBAJP;AAKA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,YAAT,EAAuBC,UAAvB,QAAyC,iBAAzC;AACA,SAASC,gBAAT,QAAiC,uBAAjC;AACA,SAASC,cAAT,EAAyBC,OAAzB,QAAwC,oBAAxC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASD,KAAK,IAAIE,WAAlB,QAAqC,mBAArC;AAEA;AACA;AACA;;AACA,OAAOC,MAAP,MAAmB,cAAnB;;AAEA,MAAMC,SAAN,SAAwBlB,SAAxB,CAAkC;AACjCmB,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,CA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P,QAAQ,CAAEjE,gBAAF,CADT;AAGA,SAAO;AACNuD,IAAAA,YAAY,GAAG;AACdgB,MAAAA,kBAAkB,CAAEE,SAAF,EAAaA,SAAb,EAAwB,CAAxB,CAAlB;AACA,KAHK;;AAINC,IAAAA,MAAM,EAAER,IAJF;AAKNS,IAAAA,MAAM,EAAER,IALF;;AAMN/C,IAAAA,QAAQ,GAAG;AACVgD,MAAAA,wBAAwB,CAAE,IAAF,CAAxB;AACAE,MAAAA,kBAAkB;AAClB,KATK;;AAUNvD,IAAAA,UAAU,GAAG;AACZqD,MAAAA,wBAAwB,CAAE,KAAF,CAAxB;AACA,KAZK;;AAaNzC,IAAAA,QAAQ,CAAEF,KAAF,EAAU;AACjB4C,MAAAA,QAAQ,CAAE;AAAE5C,QAAAA;AAAF,OAAF,CAAR;AACA,KAfK;;AAgBNC,IAAAA,kBAAkB,CAAEkD,MAAF,EAAW;AAC5BJ,MAAAA,YAAY,CAAEI,MAAF,EAAU,CAAV,CAAZ;AACA;;AAlBK,GAAP;AAoBA,CA3BW,CArBS,EAiDrBlF,cAjDqB,EAkDrBD,gBAlDqB,CAAP,CAmDZU,SAnDY,CAAf","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\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"]}
@@ -1,14 +1,9 @@
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 { isEmpty } from 'lodash';
8
4
  /**
9
5
  * WordPress dependencies
10
6
  */
11
-
12
7
  import { store as blocksStore } from '@wordpress/blocks';
13
8
  import { select as globalSelect, useSelect } from '@wordpress/data';
14
9
  import { useEntityProp } from '@wordpress/core-data';
@@ -72,7 +67,7 @@ const createWithMetaAttributeSource = metaAttributes => createHigherOrderCompone
72
67
  metaAttributes[attributeKey], value];
73
68
  }));
74
69
 
75
- if (!isEmpty(nextMeta)) {
70
+ if (Object.entries(nextMeta).length) {
76
71
  setMeta(nextMeta);
77
72
  }
78
73
 
@@ -106,7 +101,7 @@ function shimAttributeSource(settings) {
106
101
  return [attributeKey, meta];
107
102
  }));
108
103
 
109
- if (!isEmpty(metaAttributes)) {
104
+ if (Object.entries(metaAttributes).length) {
110
105
  settings.edit = createWithMetaAttributeSource(metaAttributes)(settings.edit);
111
106
  }
112
107
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/hooks/custom-sources-backwards-compatibility.js"],"names":["isEmpty","store","blocksStore","select","globalSelect","useSelect","useEntityProp","useMemo","createHigherOrderComponent","addFilter","editorStore","createWithMetaAttributeSource","metaAttributes","BlockEdit","attributes","setAttributes","props","postType","getCurrentPostType","meta","setMeta","mergedAttributes","Object","fromEntries","entries","map","attributeKey","metaKey","nextAttributes","nextMeta","filter","key","value","shimAttributeSource","settings","source","edit","getBlockTypes","name","getBlockType","forEach"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,MAAM,IAAIC,YAAnB,EAAiCC,SAAjC,QAAkD,iBAAlD;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,SAAT,QAA0B,kBAA1B;AAEA;AACA;AACA;;AACA,SAASR,KAAK,IAAIS,WAAlB,QAAqC,UAArC;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,6BAA6B,GAAKC,cAAF,IACrCJ,0BAA0B,CACvBK,SAAF,IACC,QAA+C;AAAA,MAA7C;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,aAAd;AAA6B,OAAGC;AAAhC,GAA6C;AAC9C,QAAMC,QAAQ,GAAGZ,SAAS,CACvBF,MAAF,IAAcA,MAAM,CAAEO,WAAF,CAAN,CAAsBQ,kBAAtB,EADW,EAEzB,EAFyB,CAA1B;AAIA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoBd,aAAa,CACtC,UADsC,EAEtCW,QAFsC,EAGtC,MAHsC,CAAvC;AAMA,QAAMI,gBAAgB,GAAGd,OAAO,CAC/B,OAAQ,EACP,GAAGO,UADI;AAEP,OAAGQ,MAAM,CAACC,WAAP,CACFD,MAAM,CAACE,OAAP,CAA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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,CAAEnB,OAAO,CAAEY,cAAF,CAAd,EAAmC;AAClCsB,IAAAA,QAAQ,CAACE,IAAT,GAAgBzB,6BAA6B,CAAEC,cAAF,CAA7B,CACfsB,QAAQ,CAACE,IADM,CAAhB;AAGA;;AAED,SAAOF,QAAP;AACA;;AAEDzB,SAAS,CACR,0BADQ,EAER,0EAFQ,EAGRwB,mBAHQ,CAAT,C,CAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA7B,YAAY,CAAEF,WAAF,CAAZ,CACEmC,aADF,GAEEZ,GAFF,CAEO;AAAA,MAAE;AAAEa,IAAAA;AAAF,GAAF;AAAA,SAAgBlC,YAAY,CAAEF,WAAF,CAAZ,CAA4BqC,YAA5B,CAA0CD,IAA1C,CAAhB;AAAA,CAFP,EAGEE,OAHF,CAGWP,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":["store","blocksStore","select","globalSelect","useSelect","useEntityProp","useMemo","createHigherOrderComponent","addFilter","editorStore","createWithMetaAttributeSource","metaAttributes","BlockEdit","attributes","setAttributes","props","postType","getCurrentPostType","meta","setMeta","mergedAttributes","Object","fromEntries","entries","map","attributeKey","metaKey","nextAttributes","nextMeta","filter","key","value","length","shimAttributeSource","settings","source","edit","getBlockTypes","name","getBlockType","forEach"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,MAAM,IAAIC,YAAnB,EAAiCC,SAAjC,QAAkD,iBAAlD;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,SAAT,QAA0B,kBAA1B;AAEA;AACA;AACA;;AACA,SAASR,KAAK,IAAIS,WAAlB,QAAqC,UAArC;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,6BAA6B,GAAKC,cAAF,IACrCJ,0BAA0B,CACvBK,SAAF,IACC,QAA+C;AAAA,MAA7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X","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"]}