@wordpress/editor 13.25.0 → 13.26.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 (223) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.md +1 -1
  3. package/build/components/document-bar/index.js +19 -7
  4. package/build/components/document-bar/index.js.map +1 -1
  5. package/build/components/document-outline/index.js +82 -1
  6. package/build/components/document-outline/index.js.map +1 -1
  7. package/build/components/document-tools/index.js +160 -0
  8. package/build/components/document-tools/index.js.map +1 -0
  9. package/build/components/editor-canvas/index.js +10 -4
  10. package/build/components/editor-canvas/index.js.map +1 -1
  11. package/build/components/entities-saved-states/index.js +3 -1
  12. package/build/components/entities-saved-states/index.js.map +1 -1
  13. package/build/components/global-keyboard-shortcuts/index.js +12 -2
  14. package/build/components/global-keyboard-shortcuts/index.js.map +1 -1
  15. package/build/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
  16. package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
  17. package/build/components/index.js +56 -8
  18. package/build/components/index.js.map +1 -1
  19. package/build/components/index.native.js +9 -1
  20. package/build/components/index.native.js.map +1 -1
  21. package/build/components/inserter-sidebar/index.js +77 -0
  22. package/build/components/inserter-sidebar/index.js.map +1 -0
  23. package/build/components/list-view-sidebar/index.js +150 -0
  24. package/build/components/list-view-sidebar/index.js.map +1 -0
  25. package/build/components/list-view-sidebar/list-view-outline.js +28 -0
  26. package/build/components/list-view-sidebar/list-view-outline.js.map +1 -0
  27. package/build/components/offline-status/index.native.js +85 -0
  28. package/build/components/offline-status/index.native.js.map +1 -0
  29. package/build/components/page-attributes/panel.js +63 -0
  30. package/build/components/page-attributes/panel.js.map +1 -0
  31. package/build/components/post-discussion/panel.js +59 -0
  32. package/build/components/post-discussion/panel.js.map +1 -0
  33. package/build/components/post-excerpt/check.js +19 -0
  34. package/build/components/post-excerpt/check.js.map +1 -1
  35. package/build/components/post-excerpt/panel.js +55 -0
  36. package/build/components/post-excerpt/panel.js.map +1 -0
  37. package/build/components/post-excerpt/plugin.js +72 -0
  38. package/build/components/post-excerpt/plugin.js.map +1 -0
  39. package/build/components/post-featured-image/index.js +5 -8
  40. package/build/components/post-featured-image/index.js.map +1 -1
  41. package/build/components/post-featured-image/panel.js +60 -0
  42. package/build/components/post-featured-image/panel.js.map +1 -0
  43. package/build/components/post-last-revision/panel.js +27 -0
  44. package/build/components/post-last-revision/panel.js.map +1 -0
  45. package/build/components/post-saved-state/index.js +12 -8
  46. package/build/components/post-saved-state/index.js.map +1 -1
  47. package/build/components/post-taxonomies/panel.js +68 -0
  48. package/build/components/post-taxonomies/panel.js.map +1 -0
  49. package/build/components/post-template/block-theme.js +2 -1
  50. package/build/components/post-template/block-theme.js.map +1 -1
  51. package/build/components/post-template/hooks.js +6 -6
  52. package/build/components/post-template/hooks.js.map +1 -1
  53. package/build/components/post-template/panel.js +1 -2
  54. package/build/components/post-template/panel.js.map +1 -1
  55. package/build/components/post-template/swap-template-button.js +4 -2
  56. package/build/components/post-template/swap-template-button.js.map +1 -1
  57. package/build/components/post-title/index.native.js +25 -14
  58. package/build/components/post-title/index.native.js.map +1 -1
  59. package/build/components/post-view-link/index.js +58 -0
  60. package/build/components/post-view-link/index.js.map +1 -0
  61. package/build/components/post-visibility/check.js +5 -17
  62. package/build/components/post-visibility/check.js.map +1 -1
  63. package/build/components/preview-dropdown/index.js +8 -3
  64. package/build/components/preview-dropdown/index.js.map +1 -1
  65. package/build/components/provider/index.native.js +19 -0
  66. package/build/components/provider/index.native.js.map +1 -1
  67. package/build/components/provider/use-block-editor-settings.js +29 -5
  68. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  69. package/build/private-apis.js +10 -0
  70. package/build/private-apis.js.map +1 -1
  71. package/build/store/actions.js +102 -2
  72. package/build/store/actions.js.map +1 -1
  73. package/build/store/index.js +2 -0
  74. package/build/store/index.js.map +1 -1
  75. package/build/store/private-selectors.js +52 -0
  76. package/build/store/private-selectors.js.map +1 -0
  77. package/build/store/reducer.js +78 -1
  78. package/build/store/reducer.js.map +1 -1
  79. package/build/store/selectors.js +76 -2
  80. package/build/store/selectors.js.map +1 -1
  81. package/build/utils/media-upload/index.js +8 -2
  82. package/build/utils/media-upload/index.js.map +1 -1
  83. package/build-module/components/document-bar/index.js +19 -7
  84. package/build-module/components/document-bar/index.js.map +1 -1
  85. package/build-module/components/document-outline/index.js +82 -1
  86. package/build-module/components/document-outline/index.js.map +1 -1
  87. package/build-module/components/document-tools/index.js +151 -0
  88. package/build-module/components/document-tools/index.js.map +1 -0
  89. package/build-module/components/editor-canvas/index.js +10 -4
  90. package/build-module/components/editor-canvas/index.js.map +1 -1
  91. package/build-module/components/entities-saved-states/index.js +3 -1
  92. package/build-module/components/entities-saved-states/index.js.map +1 -1
  93. package/build-module/components/global-keyboard-shortcuts/index.js +12 -2
  94. package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -1
  95. package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
  96. package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
  97. package/build-module/components/index.js +6 -0
  98. package/build-module/components/index.js.map +1 -1
  99. package/build-module/components/index.native.js +1 -0
  100. package/build-module/components/index.native.js.map +1 -1
  101. package/build-module/components/inserter-sidebar/index.js +70 -0
  102. package/build-module/components/inserter-sidebar/index.js.map +1 -0
  103. package/build-module/components/list-view-sidebar/index.js +142 -0
  104. package/build-module/components/list-view-sidebar/index.js.map +1 -0
  105. package/build-module/components/list-view-sidebar/list-view-outline.js +20 -0
  106. package/build-module/components/list-view-sidebar/list-view-outline.js.map +1 -0
  107. package/build-module/components/offline-status/index.native.js +77 -0
  108. package/build-module/components/offline-status/index.native.js.map +1 -0
  109. package/build-module/components/page-attributes/panel.js +53 -0
  110. package/build-module/components/page-attributes/panel.js.map +1 -0
  111. package/build-module/components/post-discussion/panel.js +50 -0
  112. package/build-module/components/post-discussion/panel.js.map +1 -0
  113. package/build-module/components/post-excerpt/check.js +19 -0
  114. package/build-module/components/post-excerpt/check.js.map +1 -1
  115. package/build-module/components/post-excerpt/panel.js +48 -0
  116. package/build-module/components/post-excerpt/panel.js.map +1 -0
  117. package/build-module/components/post-excerpt/plugin.js +64 -0
  118. package/build-module/components/post-excerpt/plugin.js.map +1 -0
  119. package/build-module/components/post-featured-image/index.js +5 -8
  120. package/build-module/components/post-featured-image/index.js.map +1 -1
  121. package/build-module/components/post-featured-image/panel.js +51 -0
  122. package/build-module/components/post-featured-image/panel.js.map +1 -0
  123. package/build-module/components/post-last-revision/panel.js +18 -0
  124. package/build-module/components/post-last-revision/panel.js.map +1 -0
  125. package/build-module/components/post-saved-state/index.js +12 -8
  126. package/build-module/components/post-saved-state/index.js.map +1 -1
  127. package/build-module/components/post-taxonomies/panel.js +59 -0
  128. package/build-module/components/post-taxonomies/panel.js.map +1 -0
  129. package/build-module/components/post-template/block-theme.js +2 -1
  130. package/build-module/components/post-template/block-theme.js.map +1 -1
  131. package/build-module/components/post-template/hooks.js +6 -6
  132. package/build-module/components/post-template/hooks.js.map +1 -1
  133. package/build-module/components/post-template/panel.js +1 -2
  134. package/build-module/components/post-template/panel.js.map +1 -1
  135. package/build-module/components/post-template/swap-template-button.js +4 -2
  136. package/build-module/components/post-template/swap-template-button.js.map +1 -1
  137. package/build-module/components/post-title/index.native.js +26 -15
  138. package/build-module/components/post-title/index.native.js.map +1 -1
  139. package/build-module/components/post-view-link/index.js +51 -0
  140. package/build-module/components/post-view-link/index.js.map +1 -0
  141. package/build-module/components/post-visibility/check.js +6 -16
  142. package/build-module/components/post-visibility/check.js.map +1 -1
  143. package/build-module/components/preview-dropdown/index.js +8 -3
  144. package/build-module/components/preview-dropdown/index.js.map +1 -1
  145. package/build-module/components/provider/index.native.js +19 -0
  146. package/build-module/components/provider/index.native.js.map +1 -1
  147. package/build-module/components/provider/use-block-editor-settings.js +29 -5
  148. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  149. package/build-module/private-apis.js +10 -0
  150. package/build-module/private-apis.js.map +1 -1
  151. package/build-module/store/actions.js +94 -0
  152. package/build-module/store/actions.js.map +1 -1
  153. package/build-module/store/index.js +2 -0
  154. package/build-module/store/index.js.map +1 -1
  155. package/build-module/store/private-selectors.js +43 -0
  156. package/build-module/store/private-selectors.js.map +1 -0
  157. package/build-module/store/reducer.js +74 -1
  158. package/build-module/store/reducer.js.map +1 -1
  159. package/build-module/store/selectors.js +67 -0
  160. package/build-module/store/selectors.js.map +1 -1
  161. package/build-module/utils/media-upload/index.js +8 -2
  162. package/build-module/utils/media-upload/index.js.map +1 -1
  163. package/build-style/style-rtl.css +251 -0
  164. package/build-style/style.css +251 -0
  165. package/package.json +32 -32
  166. package/src/components/document-bar/index.js +39 -28
  167. package/src/components/document-outline/index.js +48 -1
  168. package/src/components/document-outline/style.scss +12 -0
  169. package/src/components/document-tools/index.js +177 -0
  170. package/src/components/document-tools/style.scss +98 -0
  171. package/src/components/editor-canvas/index.js +12 -7
  172. package/src/components/editor-canvas/style.scss +5 -0
  173. package/src/components/entities-saved-states/index.js +3 -1
  174. package/src/components/entities-saved-states/style.scss +4 -0
  175. package/src/components/global-keyboard-shortcuts/index.js +12 -2
  176. package/src/components/global-keyboard-shortcuts/register-shortcuts.js +10 -0
  177. package/src/components/index.js +6 -0
  178. package/src/components/index.native.js +1 -0
  179. package/src/components/inserter-sidebar/index.js +73 -0
  180. package/src/components/inserter-sidebar/style.scss +22 -0
  181. package/src/components/list-view-sidebar/index.js +169 -0
  182. package/src/components/list-view-sidebar/list-view-outline.js +37 -0
  183. package/src/components/list-view-sidebar/style.scss +84 -0
  184. package/src/components/offline-status/index.native.js +101 -0
  185. package/src/components/offline-status/style.native.scss +28 -0
  186. package/src/components/offline-status/test/index.native.js +108 -0
  187. package/src/components/page-attributes/panel.js +62 -0
  188. package/src/components/post-discussion/panel.js +57 -0
  189. package/src/components/post-excerpt/check.js +18 -0
  190. package/src/components/post-excerpt/panel.js +57 -0
  191. package/src/components/post-excerpt/plugin.js +61 -0
  192. package/src/components/post-excerpt/test/plugin.js +36 -0
  193. package/src/components/post-featured-image/index.js +3 -7
  194. package/src/components/post-featured-image/panel.js +55 -0
  195. package/src/components/post-last-revision/panel.js +22 -0
  196. package/src/components/post-last-revision/style.scss +10 -0
  197. package/src/components/post-saved-state/index.js +8 -8
  198. package/src/components/post-taxonomies/panel.js +66 -0
  199. package/src/components/post-template/block-theme.js +2 -1
  200. package/src/components/post-template/hooks.js +6 -6
  201. package/src/components/post-template/panel.js +1 -2
  202. package/src/components/post-template/swap-template-button.js +7 -4
  203. package/src/components/post-title/index.native.js +32 -17
  204. package/src/components/post-title/style.scss +1 -0
  205. package/src/components/post-title/test/__snapshots__/index.native.js.snap +25 -0
  206. package/src/components/post-title/test/index.native.js +78 -0
  207. package/src/components/post-view-link/index.js +47 -0
  208. package/src/components/post-visibility/check.js +10 -15
  209. package/src/components/post-visibility/test/check.js +24 -13
  210. package/src/components/preview-dropdown/index.js +7 -10
  211. package/src/components/provider/index.native.js +29 -2
  212. package/src/components/provider/use-block-editor-settings.js +36 -8
  213. package/src/private-apis.js +10 -0
  214. package/src/store/actions.js +109 -0
  215. package/src/store/index.js +2 -0
  216. package/src/store/private-selectors.js +51 -0
  217. package/src/store/reducer.js +72 -0
  218. package/src/store/selectors.js +80 -0
  219. package/src/store/test/actions.js +56 -0
  220. package/src/store/test/reducer.js +98 -0
  221. package/src/store/test/selectors.js +49 -0
  222. package/src/style.scss +4 -0
  223. package/src/utils/media-upload/index.js +9 -2
@@ -54,16 +54,16 @@ function useAllowSwitchingTemplates() {
54
54
  return !isPostsPage && !isFrontPage;
55
55
  }, [postId, postType]);
56
56
  }
57
- function useTemplates() {
57
+ function useTemplates(postType) {
58
58
  return (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', 'wp_template', {
59
59
  per_page: -1,
60
- post_type: 'page'
61
- }), []);
60
+ post_type: postType
61
+ }), [postType]);
62
62
  }
63
- function useAvailableTemplates() {
63
+ function useAvailableTemplates(postType) {
64
64
  const currentTemplateSlug = useCurrentTemplateSlug();
65
65
  const allowSwitchingTemplate = useAllowSwitchingTemplates();
66
- const templates = useTemplates();
66
+ const templates = useTemplates(postType);
67
67
  return (0, _element.useMemo)(() => allowSwitchingTemplate && templates?.filter(template => template.is_custom && template.slug !== currentTemplateSlug && !!template.content.raw // Skip empty templates.
68
68
  ), [templates, currentTemplateSlug, allowSwitchingTemplate]);
69
69
  }
@@ -72,7 +72,7 @@ function useCurrentTemplateSlug() {
72
72
  postType,
73
73
  postId
74
74
  } = useEditedPostContext();
75
- const templates = useTemplates();
75
+ const templates = useTemplates(postType);
76
76
  const entityTemplate = (0, _data.useSelect)(select => {
77
77
  const post = select(_coreData.store).getEditedEntityRecord('postType', postType, postId);
78
78
  return post?.template;
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_element","_coreData","_store","useEditedPostContext","useSelect","select","getCurrentPostId","getCurrentPostType","editorStore","postId","postType","useAllowSwitchingTemplates","getEntityRecord","getEntityRecords","coreStore","siteSettings","templates","per_page","isPostsPage","page_for_posts","isFrontPage","page_on_front","some","slug","useTemplates","post_type","useAvailableTemplates","currentTemplateSlug","useCurrentTemplateSlug","allowSwitchingTemplate","useMemo","filter","template","is_custom","content","raw","entityTemplate","post","getEditedEntityRecord","find"],"sources":["@wordpress/editor/src/components/post-template/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function useEditedPostContext() {\n\treturn useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getCurrentPostType } = select( editorStore );\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\tpostType: getCurrentPostType(),\n\t\t};\n\t}, [] );\n}\nexport function useAllowSwitchingTemplates() {\n\tconst { postType, postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEntityRecords } = select( coreStore );\n\t\t\tconst siteSettings = getEntityRecord( 'root', 'site' );\n\t\t\tconst templates = getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\t\t\tconst isPostsPage = +postId === siteSettings?.page_for_posts;\n\t\t\t// If current page is set front page or posts page, we also need\n\t\t\t// to check if the current theme has a template for it. If not\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' &&\n\t\t\t\t+postId === siteSettings?.page_on_front &&\n\t\t\t\ttemplates?.some( ( { slug } ) => slug === 'front-page' );\n\t\t\treturn ! isPostsPage && ! isFrontPage;\n\t\t},\n\t\t[ postId, postType ]\n\t);\n}\n\nfunction useTemplates() {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: 'page',\n\t\t\t} ),\n\t\t[]\n\t);\n}\n\nexport function useAvailableTemplates() {\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst templates = useTemplates();\n\treturn useMemo(\n\t\t() =>\n\t\t\tallowSwitchingTemplate &&\n\t\t\ttemplates?.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== currentTemplateSlug &&\n\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t),\n\t\t[ templates, currentTemplateSlug, allowSwitchingTemplate ]\n\t);\n}\n\nexport function useCurrentTemplateSlug() {\n\tconst { postType, postId } = useEditedPostContext();\n\tconst templates = useTemplates();\n\tconst entityTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\treturn post?.template;\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\tif ( ! entityTemplate ) {\n\t\treturn;\n\t}\n\t// If a page has a `template` set and is not included in the list\n\t// of the theme's templates, do not return it, in order to resolve\n\t// to the current theme's default template.\n\treturn templates?.find( ( template ) => template.slug === entityTemplate )\n\t\t?.slug;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGO,SAASI,oBAAoBA,CAAA,EAAG;EACtC,OAAO,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC/B,MAAM;MAAEC,gBAAgB;MAAEC;IAAmB,CAAC,GAAGF,MAAM,CAAEG,YAAY,CAAC;IACtE,OAAO;MACNC,MAAM,EAAEH,gBAAgB,CAAC,CAAC;MAC1BI,QAAQ,EAAEH,kBAAkB,CAAC;IAC9B,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR;AACO,SAASI,0BAA0BA,CAAA,EAAG;EAC5C,MAAM;IAAED,QAAQ;IAAED;EAAO,CAAC,GAAGN,oBAAoB,CAAC,CAAC;EACnD,OAAO,IAAAC,eAAS,EACbC,MAAM,IAAM;IACb,MAAM;MAAEO,eAAe;MAAEC;IAAiB,CAAC,GAAGR,MAAM,CAAES,eAAU,CAAC;IACjE,MAAMC,YAAY,GAAGH,eAAe,CAAE,MAAM,EAAE,MAAO,CAAC;IACtD,MAAMI,SAAS,GAAGH,gBAAgB,CAAE,UAAU,EAAE,aAAa,EAAE;MAC9DI,QAAQ,EAAE,CAAC;IACZ,CAAE,CAAC;IACH,MAAMC,WAAW,GAAG,CAACT,MAAM,KAAKM,YAAY,EAAEI,cAAc;IAC5D;IACA;IACA,MAAMC,WAAW,GAChBV,QAAQ,KAAK,MAAM,IACnB,CAACD,MAAM,KAAKM,YAAY,EAAEM,aAAa,IACvCL,SAAS,EAA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QAAQ;EACtB,CAAC,EACD,CAAEtB,QAAQ,EAAED,MAAM,CACnB,CAAC;EAED,IAAK,CAAE2B,cAAc,EAAG;IACvB;EACD;EACA;EACA;EACA;EACA,OAAOpB,SAAS,EAAEuB,IAAI,CAAIP,QAAQ,IAAMA,QAAQ,CAACT,IAAI,KAAKa,cAAe,CAAC,EACvEb,IAAI;AACR"}
1
+ {"version":3,"names":["_data","require","_element","_coreData","_store","useEditedPostContext","useSelect","select","getCurrentPostId","getCurrentPostType","editorStore","postId","postType","useAllowSwitchingTemplates","getEntityRecord","getEntityRecords","coreStore","siteSettings","templates","per_page","isPostsPage","page_for_posts","isFrontPage","page_on_front","some","slug","useTemplates","post_type","useAvailableTemplates","currentTemplateSlug","useCurrentTemplateSlug","allowSwitchingTemplate","useMemo","filter","template","is_custom","content","raw","entityTemplate","post","getEditedEntityRecord","find"],"sources":["@wordpress/editor/src/components/post-template/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function useEditedPostContext() {\n\treturn useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getCurrentPostType } = select( editorStore );\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\tpostType: getCurrentPostType(),\n\t\t};\n\t}, [] );\n}\nexport function useAllowSwitchingTemplates() {\n\tconst { postType, postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEntityRecords } = select( coreStore );\n\t\t\tconst siteSettings = getEntityRecord( 'root', 'site' );\n\t\t\tconst templates = getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\t\t\tconst isPostsPage = +postId === siteSettings?.page_for_posts;\n\t\t\t// If current page is set front page or posts page, we also need\n\t\t\t// to check if the current theme has a template for it. If not\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' &&\n\t\t\t\t+postId === siteSettings?.page_on_front &&\n\t\t\t\ttemplates?.some( ( { slug } ) => slug === 'front-page' );\n\t\t\treturn ! isPostsPage && ! isFrontPage;\n\t\t},\n\t\t[ postId, postType ]\n\t);\n}\n\nfunction useTemplates( postType ) {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: postType,\n\t\t\t} ),\n\t\t[ postType ]\n\t);\n}\n\nexport function useAvailableTemplates( postType ) {\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst templates = useTemplates( postType );\n\treturn useMemo(\n\t\t() =>\n\t\t\tallowSwitchingTemplate &&\n\t\t\ttemplates?.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== currentTemplateSlug &&\n\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t),\n\t\t[ templates, currentTemplateSlug, allowSwitchingTemplate ]\n\t);\n}\n\nexport function useCurrentTemplateSlug() {\n\tconst { postType, postId } = useEditedPostContext();\n\tconst templates = useTemplates( postType );\n\tconst entityTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\treturn post?.template;\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\tif ( ! entityTemplate ) {\n\t\treturn;\n\t}\n\t// If a page has a `template` set and is not included in the list\n\t// of the theme's templates, do not return it, in order to resolve\n\t// to the current theme's default template.\n\treturn templates?.find( ( template ) => template.slug === entityTemplate )\n\t\t?.slug;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAA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AAI,KAAKa,cAAe,CAAC,EACvEb,IAAI;AACR"}
@@ -35,8 +35,7 @@ function PostTemplatePanel() {
35
35
  isBlockTheme: getEditorSettings().__unstableIsBlockBasedTheme
36
36
  };
37
37
  }, []);
38
- const isVisible = true;
39
- (0, _data.useSelect)(select => {
38
+ const isVisible = (0, _data.useSelect)(select => {
40
39
  var _select$canUser;
41
40
  const postTypeSlug = select(_store.store).getCurrentPostType();
42
41
  const postType = select(_coreData.store).getPostType(postTypeSlug);
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_i18n","_coreData","_store","_classicTheme","_interopRequireDefault","_blockTheme","_postPanelRow","PostTemplatePanel","templateId","isBlockTheme","useSelect","select","getCurrentTemplateId","getEditorSettings","editorStore","__unstableIsBlockBasedTheme","isVisible","_select$canUser","postTypeSlug","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","_react","createElement","default","label","__","id"],"sources":["@wordpress/editor/src/components/post-template/panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport ClassicThemeControl from './classic-theme';\nimport BlockThemeControl from './block-theme';\nimport PostPanelRow from '../post-panel-row';\n\nexport default function PostTemplatePanel() {\n\tconst { templateId, isBlockTheme } = useSelect( ( select ) => {\n\t\tconst { getCurrentTemplateId, getEditorSettings } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\ttemplateId: getCurrentTemplateId(),\n\t\t\tisBlockTheme: getEditorSettings().__unstableIsBlockBasedTheme,\n\t\t};\n\t}, [] );\n\n\tconst isVisible = true;\n\tuseSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isBlockTheme && isVisible ) {\n\t\treturn (\n\t\t\t<PostPanelRow label={ __( 'Template' ) }>\n\t\t\t\t<ClassicThemeControl />\n\t\t\t</PostPanelRow>\n\t\t);\n\t}\n\n\tif ( isBlockTheme && !! templateId ) {\n\t\treturn (\n\t\t\t<PostPanelRow label={ __( 'Template' ) }>\n\t\t\t\t<BlockThemeControl id={ templateId } />\n\t\t\t</PostPanelRow>\n\t\t);\n\t}\n\treturn null;\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,aAAA,GAAAF,sBAAA,CAAAL,OAAA;AAbA;AACA;AACA;;AAKA;AACA;AACA;;AAMe,SAASQ,iBAAiBA,CAAA,EAAG;EAC3C,MAAM;IAAEC,UAAU;IAAEC;EAAa,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC7D,MAAM;MAAEC,oBAAoB;MAAEC;IAAkB,CAAC,GAChDF,MAAM,CAAEG,YAAY,CAAC;IACtB,OAAO;MACNN,UAAU,EAAEI,oBAAoB,CAAC,CAAC;MAClCH,YAAY,EAAEI,iB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,EAAG;IACpC,OACC,IAAAyB,MAAA,CAAAC,aAAA,EAAC5B,aAAA,CAAA6B,OAAY;MAACC,KAAK,EAAG,IAAAC,QAAE,EAAE,UAAW;IAAG,GACvC,IAAAJ,MAAA,CAAAC,aAAA,EAAC7B,WAAA,CAAA8B,OAAiB;MAACG,EAAE,EAAG9B;IAAY,CAAE,CACzB,CAAC;EAEjB;EACA,OAAO,IAAI;AACZ"}
1
+ {"version":3,"names":["_data","require","_i18n","_coreData","_store","_classicTheme","_interopRequireDefault","_blockTheme","_postPanelRow","PostTemplatePanel","templateId","isBlockTheme","useSelect","select","getCurrentTemplateId","getEditorSettings","editorStore","__unstableIsBlockBasedTheme","isVisible","_select$canUser","postTypeSlug","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","_react","createElement","default","label","__","id"],"sources":["@wordpress/editor/src/components/post-template/panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport ClassicThemeControl from './classic-theme';\nimport BlockThemeControl from './block-theme';\nimport PostPanelRow from '../post-panel-row';\n\nexport default function PostTemplatePanel() {\n\tconst { templateId, isBlockTheme } = useSelect( ( select ) => {\n\t\tconst { getCurrentTemplateId, getEditorSettings } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\ttemplateId: getCurrentTemplateId(),\n\t\t\tisBlockTheme: getEditorSettings().__unstableIsBlockBasedTheme,\n\t\t};\n\t}, [] );\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isBlockTheme && isVisible ) {\n\t\treturn (\n\t\t\t<PostPanelRow label={ __( 'Template' ) }>\n\t\t\t\t<ClassicThemeControl />\n\t\t\t</PostPanelRow>\n\t\t);\n\t}\n\n\tif ( isBlockTheme && !! templateId ) {\n\t\treturn (\n\t\t\t<PostPanelRow label={ __( 'Template' ) }>\n\t\t\t\t<BlockThemeControl id={ templateId } />\n\t\t\t</PostPanelRow>\n\t\t);\n\t}\n\treturn null;\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,aAAA,GAAAF,sBAAA,CAAAL,OAAA;AAbA;AACA;AACA;;AAKA;AACA;AACA;;AAMe,SAASQ,iBAAiBA,CAAA,EAAG;EAC3C,MAAM;IAAEC,UAAU;IAAEC;EAAa,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC7D,MAAM;MAAEC,oBAAoB;MAAEC;IAAkB,CAAC,GAChDF,MAAM,CAAEG,YAAY,CAAC;IACtB,OAAO;MACNN,UAAU,EAAEI,oBAAoB,CAAC,CAAC;MAClCH,YAAY,EAAEI,iBAAiB,CAAC,CAAC,CAACE;IACnC,CAAC;EACF,CAAC,EAAE,EAAG,CAA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;MAACC,KAAK,EAAG,IAAAC,QAAE,EAAE,UAAW;IAAG,GACvC,IAAAJ,MAAA,CAAAC,aAAA,EAAC7B,WAAA,CAAA8B,OAAiB;MAACG,EAAE,EAAG9B;IAAY,CAAE,CACzB,CAAC;EAEjB;EACA,OAAO,IAAI;AACZ"}
@@ -27,7 +27,6 @@ function SwapTemplateButton({
27
27
  onClick
28
28
  }) {
29
29
  const [showModal, setShowModal] = (0, _element.useState)(false);
30
- const availableTemplates = (0, _hooks.useAvailableTemplates)();
31
30
  const onClose = (0, _element.useCallback)(() => {
32
31
  setShowModal(false);
33
32
  }, []);
@@ -35,6 +34,7 @@ function SwapTemplateButton({
35
34
  postType,
36
35
  postId
37
36
  } = (0, _hooks.useEditedPostContext)();
37
+ const availableTemplates = (0, _hooks.useAvailableTemplates)(postType);
38
38
  const {
39
39
  editEntityRecord
40
40
  } = (0, _data.useDispatch)(_coreData.store);
@@ -60,13 +60,15 @@ function SwapTemplateButton({
60
60
  }, (0, _react.createElement)("div", {
61
61
  className: "editor-post-template__swap-template-modal-content"
62
62
  }, (0, _react.createElement)(TemplatesList, {
63
+ postType: postType,
63
64
  onSelect: onTemplateSelect
64
65
  }))));
65
66
  }
66
67
  function TemplatesList({
68
+ postType,
67
69
  onSelect
68
70
  }) {
69
- const availableTemplates = (0, _hooks.useAvailableTemplates)();
71
+ const availableTemplates = (0, _hooks.useAvailableTemplates)(postType);
70
72
  const templatesAsPatterns = (0, _element.useMemo)(() => availableTemplates.map(template => ({
71
73
  name: template.slug,
72
74
  blocks: (0, _blocks.parse)(template.content.raw),
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_htmlEntities","_blockEditor","_components","_i18n","_data","_coreData","_blocks","_compose","_hooks","SwapTemplateButton","onClick","showModal","setShowModal","useState","availableTemplates","useAvailableTemplates","onClose","useCallback","postType","postId","useEditedPostContext","editEntityRecord","useDispatch","coreStore","length","onTemplateSelect","template","name","undoIgnore","_react","createElement","Fragment","MenuItem","__","Modal","title","onRequestClose","overlayClassName","isFullScreen","className","TemplatesList","onSelect","templatesAsPatterns","useMemo","map","slug","blocks","parse","content","raw","decodeEntities","rendered","id","shownTemplates","useAsyncList","__experimentalBlockPatternsList","label","blockPatterns","shownPatterns","onClickPattern"],"sources":["@wordpress/editor/src/components/post-template/swap-template-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState, useCallback } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport { MenuItem, Modal } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { parse } from '@wordpress/blocks';\nimport { useAsyncList } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useAvailableTemplates, useEditedPostContext } from './hooks';\n\nexport default function SwapTemplateButton( { onClick } ) {\n\tconst [ showModal, setShowModal ] = useState( false );\n\tconst availableTemplates = useAvailableTemplates();\n\tconst onClose = useCallback( () => {\n\t\tsetShowModal( false );\n\t}, [] );\n\tconst { postType, postId } = useEditedPostContext();\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\tif ( ! availableTemplates?.length ) {\n\t\treturn null;\n\t}\n\tconst onTemplateSelect = async ( template ) => {\n\t\teditEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId,\n\t\t\t{ template: template.name },\n\t\t\t{ undoIgnore: true }\n\t\t);\n\t\tonClose(); // Close the template suggestions modal first.\n\t\tonClick();\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem onClick={ () => setShowModal( true ) }>\n\t\t\t\t{ __( 'Swap template' ) }\n\t\t\t</MenuItem>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ onClose }\n\t\t\t\t\toverlayClassName=\"editor-post-template__swap-template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"editor-post-template__swap-template-modal-content\">\n\t\t\t\t\t\t<TemplatesList onSelect={ onTemplateSelect } />\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction TemplatesList( { onSelect } ) {\n\tconst availableTemplates = useAvailableTemplates();\n\tconst templatesAsPatterns = useMemo(\n\t\t() =>\n\t\t\tavailableTemplates.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) ),\n\t\t[ availableTemplates ]\n\t);\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\treturn (\n\t\t<BlockPatternsList\n\t\t\tlabel={ __( 'Templates' ) }\n\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\tshownPatterns={ shownTemplates }\n\t\t\tonClickPattern={ onSelect }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AAhBA;AACA;AACA;;AAWA;AACA;AACA;;AAGe,SAASU,kBAAkBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EACzD,MAAM,CAAEC,SAAS,EAAEC,YAAY,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EACrD,MAAMC,kBAAkB,GAAG,IAAAC,4BAAqB,EAAC,CAAC;EAClD,M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AAS,CAAC,EAAG;EACtC,MAAM3B,kBAAkB,GAAG,IAAAC,4BAAqB,EAAC,CAAC;EAClD,MAAM2B,mBAAmB,GAAG,IAAAC,gBAAO,EAClC,MACC7B,kBAAkB,CAAC8B,GAAG,CAAIlB,QAAQ,KAAQ;IACzCC,IAAI,EAAED,QAAQ,CAACmB,IAAI;IACnBC,MAAM,EAAE,IAAAC,aAAK,EAAErB,QAAQ,CAACsB,OAAO,CAACC,GAAI,CAAC;IACrCd,KAAK,EAAE,IAAAe,4BAAc,EAAExB,QAAQ,CAACS,KAAK,CAACgB,QAAS,CAAC;IAChDC,EAAE,EAAE1B,QAAQ,CAAC0B;EACd,CAAC,CAAG,CAAC,EACN,CAAEtC,kBAAkB,CACrB,CAAC;EACD,MAAMuC,cAAc,GAAG,IAAAC,qBAAY,EAAEZ,mBAAoB,CAAC;EAC1D,OACC,IAAAb,MAAA,CAAAC,aAAA,EAAC7B,YAAA,CAAAsD,+BAAiB;IACjBC,KAAK,EAAG,IAAAvB,QAAE,EAAE,WAAY,CAAG;IAC3BwB,aAAa,EAAGf,mBAAqB;IACrCgB,aAAa,EAAGL,cAAgB;IAChCM,cAAc,EAAGlB;EAAU,CAC3B,CAAC;AAEJ"}
1
+ {"version":3,"names":["_element","require","_htmlEntities","_blockEditor","_components","_i18n","_data","_coreData","_blocks","_compose","_hooks","SwapTemplateButton","onClick","showModal","setShowModal","useState","onClose","useCallback","postType","postId","useEditedPostContext","availableTemplates","useAvailableTemplates","editEntityRecord","useDispatch","coreStore","length","onTemplateSelect","template","name","undoIgnore","_react","createElement","Fragment","MenuItem","__","Modal","title","onRequestClose","overlayClassName","isFullScreen","className","TemplatesList","onSelect","templatesAsPatterns","useMemo","map","slug","blocks","parse","content","raw","decodeEntities","rendered","id","shownTemplates","useAsyncList","__experimentalBlockPatternsList","label","blockPatterns","shownPatterns","onClickPattern"],"sources":["@wordpress/editor/src/components/post-template/swap-template-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState, useCallback } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport { MenuItem, Modal } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { parse } from '@wordpress/blocks';\nimport { useAsyncList } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useAvailableTemplates, useEditedPostContext } from './hooks';\n\nexport default function SwapTemplateButton( { onClick } ) {\n\tconst [ showModal, setShowModal ] = useState( false );\n\tconst onClose = useCallback( () => {\n\t\tsetShowModal( false );\n\t}, [] );\n\tconst { postType, postId } = useEditedPostContext();\n\tconst availableTemplates = useAvailableTemplates( postType );\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\tif ( ! availableTemplates?.length ) {\n\t\treturn null;\n\t}\n\tconst onTemplateSelect = async ( template ) => {\n\t\teditEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId,\n\t\t\t{ template: template.name },\n\t\t\t{ undoIgnore: true }\n\t\t);\n\t\tonClose(); // Close the template suggestions modal first.\n\t\tonClick();\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem onClick={ () => setShowModal( true ) }>\n\t\t\t\t{ __( 'Swap template' ) }\n\t\t\t</MenuItem>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ onClose }\n\t\t\t\t\toverlayClassName=\"editor-post-template__swap-template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"editor-post-template__swap-template-modal-content\">\n\t\t\t\t\t\t<TemplatesList\n\t\t\t\t\t\t\tpostType={ postType }\n\t\t\t\t\t\t\tonSelect={ onTemplateSelect }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction TemplatesList( { postType, onSelect } ) {\n\tconst availableTemplates = useAvailableTemplates( postType );\n\tconst templatesAsPatterns = useMemo(\n\t\t() =>\n\t\t\tavailableTemplates.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) ),\n\t\t[ availableTemplates ]\n\t);\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\treturn (\n\t\t<BlockPatternsList\n\t\t\tlabel={ __( 'Templates' ) }\n\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\tshownPatterns={ shownTemplates }\n\t\t\tonClickPattern={ onSelect }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AAhBA;AACA;AACA;;AAWA;AACA;AACA;;AAGe,SAASU,kBAAkBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EACzD,MAAM,CAAEC,SAAS,EAAEC,YAAY,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EACrD,MAAMC,OAAO,GAAG,IAAAC,oBAAW,EAAE,MAAM;IAClCH,YAAY,CAAE,KAAM,CAAC;EACtB,CAAC,EAAE,EAAG,CAAC;EACP,MAAM;IAAEI,QAAQ;IAAEC;EAAO,CAAC,GAAG,IAAAC,2BAAoB,EAAC,CAAC;EACnD,MAAMC,kBAAkB,GAA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AAmB,GAAG,IAAAC,gBAAO,EAClC,MACCxB,kBAAkB,CAACyB,GAAG,CAAIlB,QAAQ,KAAQ;IACzCC,IAAI,EAAED,QAAQ,CAACmB,IAAI;IACnBC,MAAM,EAAE,IAAAC,aAAK,EAAErB,QAAQ,CAACsB,OAAO,CAACC,GAAI,CAAC;IACrCd,KAAK,EAAE,IAAAe,4BAAc,EAAExB,QAAQ,CAACS,KAAK,CAACgB,QAAS,CAAC;IAChDC,EAAE,EAAE1B,QAAQ,CAAC0B;EACd,CAAC,CAAG,CAAC,EACN,CAAEjC,kBAAkB,CACrB,CAAC;EACD,MAAMkC,cAAc,GAAG,IAAAC,qBAAY,EAAEZ,mBAAoB,CAAC;EAC1D,OACC,IAAAb,MAAA,CAAAC,aAAA,EAAC7B,YAAA,CAAAsD,+BAAiB;IACjBC,KAAK,EAAG,IAAAvB,QAAE,EAAE,WAAY,CAAG;IAC3BwB,aAAa,EAAGf,mBAAqB;IACrCgB,aAAa,EAAGL,cAAgB;IAChCM,cAAc,EAAGlB;EAAU,CAC3B,CAAC;AAEJ"}
@@ -17,6 +17,7 @@ var _i18n = require("@wordpress/i18n");
17
17
  var _blocks = require("@wordpress/blocks");
18
18
  var _blockEditor = require("@wordpress/block-editor");
19
19
  var _editor = require("@wordpress/editor");
20
+ var _dom = require("@wordpress/dom");
20
21
  var _style = _interopRequireDefault(require("./style.scss"));
21
22
  /**
22
23
  * External dependencies
@@ -58,7 +59,6 @@ class PostTitle extends _element.Component {
58
59
  }
59
60
  onPaste({
60
61
  value,
61
- onChange,
62
62
  plainText,
63
63
  html
64
64
  }) {
@@ -71,21 +71,32 @@ class PostTitle extends _element.Component {
71
71
  HTML: html,
72
72
  plainText
73
73
  });
74
- if (content.length) {
75
- if (typeof content === 'string') {
76
- const valueToInsert = (0, _richText.create)({
77
- html: content
78
- });
79
- onChange((0, _richText.insert)(value, valueToInsert));
74
+ if (!content.length) {
75
+ return;
76
+ }
77
+ if (typeof content !== 'string') {
78
+ const [firstBlock] = content;
79
+ if (!title && (firstBlock.name === 'core/heading' || firstBlock.name === 'core/paragraph')) {
80
+ // Strip HTML to avoid unwanted HTML being added to the title.
81
+ // In the majority of cases it is assumed that HTML in the title
82
+ // is undesirable.
83
+ const contentNoHTML = (0, _dom.__unstableStripHTML)(firstBlock.attributes.content);
84
+ onUpdate(contentNoHTML);
85
+ onInsertBlockAfter(content.slice(1));
80
86
  } else {
81
- const [firstBlock] = content;
82
- if (!title && (firstBlock.name === 'core/heading' || firstBlock.name === 'core/paragraph')) {
83
- onUpdate(firstBlock.attributes.content);
84
- onInsertBlockAfter(content.slice(1));
85
- } else {
86
- onInsertBlockAfter(content);
87
- }
87
+ onInsertBlockAfter(content);
88
88
  }
89
+ } else {
90
+ // Strip HTML to avoid unwanted HTML being added to the title.
91
+ // In the majority of cases it is assumed that HTML in the title
92
+ // is undesirable.
93
+ const contentNoHTML = (0, _dom.__unstableStripHTML)(content);
94
+ const newValue = (0, _richText.insert)(value, (0, _richText.create)({
95
+ html: contentNoHTML
96
+ }));
97
+ onUpdate((0, _richText.toHTMLString)({
98
+ value: newValue
99
+ }));
89
100
  }
90
101
  }
91
102
  setRef(richText) {
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_element","_richText","_htmlEntities","_data","_components","_compose","_i18n","_blocks","_blockEditor","_editor","_style","_interopRequireDefault","PostTitle","Component","constructor","props","setRef","bind","onPaste","componentDidUpdate","prevProps","isSelected","isAnyBlockSelected","richTextRef","blur","onUnselect","componentDidMount","innerRef","handleFocusOutside","focus","onSelect","value","onChange","plainText","html","title","onInsertBlockAfter","onUpdate","content","pasteHandler","HTML","length","valueToInsert","create","insert","firstBlock","name","attributes","slice","richText","getTitle","postType","__","sprintf","render","placeholder","style","focusedBorderColor","borderStyle","isDimmed","globalStyles","decodedPlaceholder","decodeEntities","borderColor","titleStyles","text","color","placeholderColor","_react","createElement","View","testID","styles","titleContainer","dimmed","accessible","accessibilityLabel","accessibilityHint","RichText","Raw","tagName","tagsToEliminate","unstableOnFocus","onBlur","fontSize","lineHeight","fontWeight","deleteEnter","onSelectionChange","onEnter","onEnterPress","disableEditingMenu","__unstableIsSelected","__unstableOnCreateUndoLevel","_default","compose","withSelect","select","isPostTitleSelected","getEditedPostAttribute","editorStore","getSelectedBlockClientId","getBlockRootClientId","getSettings","blockEditorStore","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","withDispatch","dispatch","undo","redo","togglePostTitleSelection","editPost","clearSelectedBlock","insertDefaultBlock","insertBlocks","undefined","onUndo","onRedo","blocks","withInstanceId","withFocusOutside","exports","default"],"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { create, insert } 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, RichText } 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.Raw\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\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/>\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 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AAEoF,MAAM,EAAG;MAC5BJ,YAAY,CAAEI,MAAM,EAAE,CAAE,CAAC;IAC1B;EACD,CAAC;AACF,CAAE,CAAC,EACHC,uBAAc,EACdC,4BACD,CAAC,CAAE9G,SAAU,CAAC;AAAA+G,OAAA,CAAAC,OAAA,GAAA9B,QAAA"}
1
+ {"version":3,"names":["_reactNative","require","_element","_richText","_htmlEntities","_data","_components","_compose","_i18n","_blocks","_blockEditor","_editor","_dom","_style","_interopRequireDefault","PostTitle","Component","constructor","props","setRef","bind","onPaste","componentDidUpdate","prevProps","isSelected","isAnyBlockSelected","richTextRef","blur","onUnselect","componentDidMount","innerRef","handleFocusOutside","focus","onSelect","value","plainText","html","title","onInsertBlockAfter","onUpdate","content","pasteHandler","HTML","length","firstBlock","name","contentNoHTML","stripHTML","attributes","slice","newValue","insert","create","toHTMLString","richText","getTitle","postType","__","sprintf","render","placeholder","style","focusedBorderColor","borderStyle","isDimmed","globalStyles","decodedPlaceholder","decodeEntities","borderColor","titleStyles","text","color","placeholderColor","_react","createElement","View","testID","styles","titleContainer","dimmed","accessible","accessibilityLabel","accessibilityHint","RichText","Raw","tagName","tagsToEliminate","unstableOnFocus","onBlur","fontSize","lineHeight","fontWeight","deleteEnter","onChange","onSelectionChange","onEnter","onEnterPress","disableEditingMenu","__unstableIsSelected","__unstableOnCreateUndoLevel","_default","compose","withSelect","select","isPostTitleSelected","getEditedPostAttribute","editorStore","getSelectedBlockClientId","getBlockRootClientId","getSettings","blockEditorStore","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","withDispatch","dispatch","undo","redo","togglePostTitleSelection","editPost","clearSelectedBlock","insertDefaultBlock","insertBlocks","undefined","onUndo","onRedo","blocks","withInstanceId","withFocusOutside","exports","default"],"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { create, toHTMLString, insert } 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, RichText } from '@wordpress/block-editor';\nimport { store as editorStore } from '@wordpress/editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\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, 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\treturn;\n\t\t}\n\n\t\tif ( typeof content !== 'string' ) {\n\t\t\tconst [ firstBlock ] = content;\n\n\t\t\tif (\n\t\t\t\t! title &&\n\t\t\t\t( firstBlock.name === 'core/heading' ||\n\t\t\t\t\tfirstBlock.name === 'core/paragraph' )\n\t\t\t) {\n\t\t\t\t// Strip HTML to avoid unwanted HTML being added to the title.\n\t\t\t\t// In the majority of cases it is assumed that HTML in the title\n\t\t\t\t// is undesirable.\n\t\t\t\tconst contentNoHTML = stripHTML(\n\t\t\t\t\tfirstBlock.attributes.content\n\t\t\t\t);\n\t\t\t\tonUpdate( contentNoHTML );\n\t\t\t\tonInsertBlockAfter( content.slice( 1 ) );\n\t\t\t} else {\n\t\t\t\tonInsertBlockAfter( content );\n\t\t\t}\n\t\t} else {\n\t\t\t// Strip HTML to avoid unwanted HTML being added to the title.\n\t\t\t// In the majority of cases it is assumed that HTML in the title\n\t\t\t// is undesirable.\n\t\t\tconst contentNoHTML = stripHTML( content );\n\n\t\t\tconst newValue = insert( value, create( { html: contentNoHTML } ) );\n\t\t\tonUpdate( toHTMLString( { value: newValue } ) );\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.Raw\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\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/>\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"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;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CAAE,CAAC;IACtB,CAAC;IACDC,kBAAkBA,CAAEwF,MAAM,EAAG;MAC5BJ,YAAY,CAAEI,MAAM,EAAE,CAAE,CAAC;IAC1B;EACD,CAAC;AACF,CAAE,CAAC,EACHC,uBAAc,EACdC,4BACD,CAAC,CAAEjH,SAAU,CAAC;AAAAkH,OAAA,CAAAC,OAAA,GAAA9B,QAAA"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = PostViewLink;
7
+ var _react = require("react");
8
+ var _i18n = require("@wordpress/i18n");
9
+ var _components = require("@wordpress/components");
10
+ var _icons = require("@wordpress/icons");
11
+ var _coreData = require("@wordpress/core-data");
12
+ var _data = require("@wordpress/data");
13
+ var _preferences = require("@wordpress/preferences");
14
+ var _store = require("../../store");
15
+ /**
16
+ * WordPress dependencies
17
+ */
18
+
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+
23
+ function PostViewLink() {
24
+ const {
25
+ hasLoaded,
26
+ permalink,
27
+ isPublished,
28
+ label,
29
+ showIconLabels
30
+ } = (0, _data.useSelect)(select => {
31
+ // Grab post type to retrieve the view_item label.
32
+ const postTypeSlug = select(_store.store).getCurrentPostType();
33
+ const postType = select(_coreData.store).getPostType(postTypeSlug);
34
+ const {
35
+ get
36
+ } = select(_preferences.store);
37
+ return {
38
+ permalink: select(_store.store).getPermalink(),
39
+ isPublished: select(_store.store).isCurrentPostPublished(),
40
+ label: postType?.labels.view_item,
41
+ hasLoaded: !!postType,
42
+ showIconLabels: get('core', 'showIconLabels')
43
+ };
44
+ }, []);
45
+
46
+ // Only render the view button if the post is published and has a permalink.
47
+ if (!isPublished || !permalink || !hasLoaded) {
48
+ return null;
49
+ }
50
+ return (0, _react.createElement)(_components.Button, {
51
+ icon: _icons.external,
52
+ label: label || (0, _i18n.__)('View post'),
53
+ href: permalink,
54
+ target: "_blank",
55
+ showTooltip: !showIconLabels
56
+ });
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_components","_icons","_coreData","_data","_preferences","_store","PostViewLink","hasLoaded","permalink","isPublished","label","showIconLabels","useSelect","select","postTypeSlug","editorStore","getCurrentPostType","postType","coreStore","getPostType","get","preferencesStore","getPermalink","isCurrentPostPublished","labels","view_item","_react","createElement","Button","icon","external","__","href","target","showTooltip"],"sources":["@wordpress/editor/src/components/post-view-link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { external } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostViewLink() {\n\tconst { hasLoaded, permalink, isPublished, label, showIconLabels } =\n\t\tuseSelect( ( select ) => {\n\t\t\t// Grab post type to retrieve the view_item label.\n\t\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\t\tconst { get } = select( preferencesStore );\n\n\t\t\treturn {\n\t\t\t\tpermalink: select( editorStore ).getPermalink(),\n\t\t\t\tisPublished: select( editorStore ).isCurrentPostPublished(),\n\t\t\t\tlabel: postType?.labels.view_item,\n\t\t\t\thasLoaded: !! postType,\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t}, [] );\n\n\t// Only render the view button if the post is published and has a permalink.\n\tif ( ! isPublished || ! permalink || ! hasLoaded ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\ticon={ external }\n\t\t\tlabel={ label || __( 'View post' ) }\n\t\t\thref={ permalink }\n\t\t\ttarget=\"_blank\"\n\t\t\tshowTooltip={ ! showIconLabels }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,K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;IACpCC,IAAI,EAAGxB,SAAW;IAClByB,MAAM,EAAC,QAAQ;IACfC,WAAW,EAAG,CAAEvB;EAAgB,CAChC,CAAC;AAEJ"}
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.PostVisibilityCheck = PostVisibilityCheck;
7
- exports.default = void 0;
8
- var _compose = require("@wordpress/compose");
6
+ exports.default = PostVisibilityCheck;
9
7
  var _data = require("@wordpress/data");
10
8
  var _store = require("../../store");
11
9
  /**
@@ -17,24 +15,14 @@ var _store = require("../../store");
17
15
  */
18
16
 
19
17
  function PostVisibilityCheck({
20
- hasPublishAction,
21
18
  render
22
19
  }) {
23
- const canEdit = hasPublishAction;
20
+ const canEdit = (0, _data.useSelect)(select => {
21
+ var _select$getCurrentPos;
22
+ return (_select$getCurrentPos = select(_store.store).getCurrentPost()._links?.['wp:action-publish']) !== null && _select$getCurrentPos !== void 0 ? _select$getCurrentPos : false;
23
+ });
24
24
  return render({
25
25
  canEdit
26
26
  });
27
27
  }
28
- var _default = (0, _compose.compose)([(0, _data.withSelect)(select => {
29
- var _getCurrentPost$_link;
30
- const {
31
- getCurrentPost,
32
- getCurrentPostType
33
- } = select(_store.store);
34
- return {
35
- hasPublishAction: (_getCurrentPost$_link = getCurrentPost()._links?.['wp:action-publish']) !== null && _getCurrentPost$_link !== void 0 ? _getCurrentPost$_link : false,
36
- postType: getCurrentPostType()
37
- };
38
- })])(PostVisibilityCheck);
39
- exports.default = _default;
40
28
  //# sourceMappingURL=check.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_compose","require","_data","_store","PostVisibilityCheck","hasPublishAction","render","canEdit","_default","compose","withSelect","select","_getCurrentPost$_link","getCurrentPost","getCurrentPostType","editorStore","_links","postType","exports","default"],"sources":["@wordpress/editor/src/components/post-visibility/check.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function PostVisibilityCheck( { hasPublishAction, render } ) {\n\tconst canEdit = hasPublishAction;\n\treturn render( { canEdit } );\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\tconst { getCurrentPost, getCurrentPostType } = select( editorStore );\n\t\treturn {\n\t\t\thasPublishAction:\n\t\t\t\tgetCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,\n\t\t\tpostType: getCurrentPostType(),\n\t\t};\n\t} ),\n] )( PostVisibilityCheck );\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGO,SAASG,mBAAmBA,CAAE;EAAEC,gBAAgB;EAAEC;AAAO,CAAC,EAAG;EACnE,MAAMC,OAAO,GAAGF,gBAAgB;EAChC,OAAOC,MAAM,CAAE;IAAEC;EAAQ,CAAE,CAAC;AAC7B;AAAC,IAAAC,QAAA,GAEc,IAAAC,gBAAO,EAAE,CACvB,IAAAC,gBAAU,EAAIC,MAAM,IAAM;EAAA,IAAAC,qBAAA;EACzB,MAAM;IAAEC,cAAc;IAAEC;EAAmB,CAAC,GAAGH,MAAM,CAAEI,YAAY,CAAC;EACpE,OAAO;IACNV,gBAAgB,GAAAO,qBAAA,GACfC,cAAc,CAAC,CAAC,CAACG,MAAM,GAAI,mBAAmB,CAAE,cAAAJ,qBAAA,cAAAA,qBAAA,GAAI,KAAK;IAC1DK,QAAQ,EAAEH,kBAAkB,CAAC;EAC9B,CAAC;AACF,CAAE,CAAC,CACF,CAAC,CAAEV,mBAAoB,CAAC;AAAAc,OAAA,CAAAC,OAAA,GAAAX,QAAA"}
1
+ {"version":3,"names":["_data","require","_store","PostVisibilityCheck","render","canEdit","useSelect","select","_select$getCurrentPos","editorStore","getCurrentPost","_links"],"sources":["@wordpress/editor/src/components/post-visibility/check.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostVisibilityCheck( { render } ) {\n\tconst canEdit = useSelect( ( select ) => {\n\t\treturn (\n\t\t\tselect( editorStore ).getCurrentPost()._links?.[\n\t\t\t\t'wp:action-publish'\n\t\t\t] ?? false\n\t\t);\n\t} );\n\n\treturn render( { canEdit } );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGe,SAASE,mBAAmBA,CAAE;EAAEC;AAAO,CAAC,EAAG;EACzD,MAAMC,OAAO,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAAA,IAAAC,qBAAA;IACxC,QAAAA,qBAAA,GACCD,MAAM,CAAEE,YAAY,CAAC,CAACC,cAAc,CAAC,CAAC,CAACC,MAAM,GAC5C,mBAAmB,CACnB,cAAAH,qBAAA,cAAAA,qBAAA,GAAI,KAAK;EAEZ,CAAE,CAAC;EAEH,OAAOJ,MAAM,CAAE;IAAEC;EAAQ,CAAE,CAAC;AAC7B"}
@@ -12,6 +12,7 @@ var _i18n = require("@wordpress/i18n");
12
12
  var _icons = require("@wordpress/icons");
13
13
  var _data = require("@wordpress/data");
14
14
  var _coreData = require("@wordpress/core-data");
15
+ var _preferences = require("@wordpress/preferences");
15
16
  var _store = require("../../store");
16
17
  var _postPreviewButton = _interopRequireDefault(require("../post-preview-button"));
17
18
  /**
@@ -23,7 +24,6 @@ var _postPreviewButton = _interopRequireDefault(require("../post-preview-button"
23
24
  */
24
25
 
25
26
  function PreviewDropdown({
26
- showIconLabels,
27
27
  forceIsAutosaveable,
28
28
  disabled
29
29
  }) {
@@ -31,7 +31,8 @@ function PreviewDropdown({
31
31
  deviceType,
32
32
  homeUrl,
33
33
  isTemplate,
34
- isViewable
34
+ isViewable,
35
+ showIconLabels
35
36
  } = (0, _data.useSelect)(select => {
36
37
  var _getPostType$viewable;
37
38
  const {
@@ -42,12 +43,16 @@ function PreviewDropdown({
42
43
  getUnstableBase,
43
44
  getPostType
44
45
  } = select(_coreData.store);
46
+ const {
47
+ get
48
+ } = select(_preferences.store);
45
49
  const _currentPostType = getCurrentPostType();
46
50
  return {
47
51
  deviceType: getDeviceType(),
48
52
  homeUrl: getUnstableBase()?.home,
49
53
  isTemplate: _currentPostType === 'wp_template',
50
- isViewable: (_getPostType$viewable = getPostType(_currentPostType)?.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false
54
+ isViewable: (_getPostType$viewable = getPostType(_currentPostType)?.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false,
55
+ showIconLabels: get('core', 'showIconLabels')
51
56
  };
52
57
  }, []);
53
58
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["_compose","require","_components","_i18n","_icons","_data","_coreData","_store","_postPreviewButton","_interopRequireDefault","PreviewDropdown","showIconLabels","forceIsAutosaveable","disabled","deviceType","homeUrl","isTemplate","isViewable","useSelect","select","_getPostType$viewable","getDeviceType","getCurrentPostType","editorStore","getUnstableBase","getPostType","coreStore","_currentPostType","home","viewable","setDeviceType","useDispatch","isMobile","useViewportMatch","popoverProps","placement","toggleProps","className","size","showTooltip","__experimentalIsFocusable","menuProps","__","deviceIcons","mobile","tablet","desktop","_react","createElement","DropdownMenu","icon","toLowerCase","label","disableOpenOnArrowDown","onClose","Fragment","MenuGroup","MenuItem","onClick","check","href","target","external","VisuallyHidden","as","default","role","textContent","Icon","onPreview"],"sources":["@wordpress/editor/src/components/preview-dropdown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tVisuallyHidden,\n\tIcon,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { check, desktop, mobile, tablet, external } from '@wordpress/icons';\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';\nimport PostPreviewButton from '../post-preview-button';\n\nexport default function PreviewDropdown( {\n\tshowIconLabels,\n\tforceIsAutosaveable,\n\tdisabled,\n} ) {\n\tconst { deviceType, homeUrl, isTemplate, isViewable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getDeviceType, getCurrentPostType } = select( editorStore );\n\t\t\tconst { getUnstableBase, getPostType } = select( coreStore );\n\t\t\tconst _currentPostType = getCurrentPostType();\n\t\t\treturn {\n\t\t\t\tdeviceType: getDeviceType(),\n\t\t\t\thomeUrl: getUnstableBase()?.home,\n\t\t\t\tisTemplate: _currentPostType === 'wp_template',\n\t\t\t\tisViewable: getPostType( _currentPostType )?.viewable ?? false,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { setDeviceType } = useDispatch( editorStore );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tif ( isMobile ) return null;\n\n\tconst popoverProps = {\n\t\tplacement: 'bottom-end',\n\t};\n\tconst toggleProps = {\n\t\tclassName: 'editor-preview-dropdown__toggle',\n\t\tsize: 'compact',\n\t\tshowTooltip: ! showIconLabels,\n\t\tdisabled,\n\t\t__experimentalIsFocusable: disabled,\n\t};\n\tconst menuProps = {\n\t\t'aria-label': __( 'View options' ),\n\t};\n\n\tconst deviceIcons = {\n\t\tmobile,\n\t\ttablet,\n\t\tdesktop,\n\t};\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"editor-preview-dropdown\"\n\t\t\tpopoverProps={ popoverProps }\n\t\t\ttoggleProps={ toggleProps }\n\t\t\tmenuProps={ menuProps }\n\t\t\ticon={ deviceIcons[ deviceType.toLowerCase() ] }\n\t\t\tlabel={ __( 'View' ) }\n\t\t\tdisableOpenOnArrowDown={ disabled }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Desktop' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Desktop' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Desktop' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Tablet' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Tablet' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Tablet' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Mobile' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Mobile' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Mobile' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t{ isTemplate && (\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\thref={ homeUrl }\n\t\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\t\ticon={ external }\n\t\t\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'View site' ) }\n\t\t\t\t\t\t\t\t<VisuallyHidden as=\"span\">\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t/* translators: accessibility text */\n\t\t\t\t\t\t\t\t\t\t__( '(opens in a new tab)' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isViewable && (\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<PostPreviewButton\n\t\t\t\t\t\t\t\tclassName=\"editor-preview-dropdown__button-external\"\n\t\t\t\t\t\t\t\trole=\"menuitem\"\n\t\t\t\t\t\t\t\tforceIsAutosaveable={ forceIsAutosaveable }\n\t\t\t\t\t\t\t\ttextContent={\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Preview in new tab' ) }\n\t\t\t\t\t\t\t\t\t\t<Icon icon={ external } />\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\tonPreview={ onClose }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAOA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAKA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,kBAAA,GAAAC,sBAAA,CAAAR,OAAA;AApBA;AACA;AACA;;AAcA;AACA;AACA;;AAIe,SAASS,eAAeA,CAAE;EACxCC,cAAc;EACdC,mBAAmB;EACnBC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC,UAAU;IAAEC,OAAO;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAG,IAAAC,eAAS,EAC9DC,MAAM,IAAM;IAAA,IAAAC,qBAAA;IACb,MAAM;MAAEC,aAAa;MAAEC;IAAmB,CAAC,GAAGH,MAAM,CAAEI,YAAY,CAAC;IACnE,MAAM;MAAEC,eAAe;MAAEC;IAAY,CAAC,GAAGN,MAAM,CAAEO,eAAU,CAAC;IAC5D,MAAMC,gBAAgB,GAAGL,kBAAkB,CAAC,C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,EACCzB,UAAU,IACX,IAAA8B,MAAA,CAAAC,aAAA,EAAC9C,WAAA,CAAAsD,SAAS,QACT,IAAAT,MAAA,CAAAC,aAAA,EAACxC,kBAAA,CAAAyD,OAAiB;IACjB5B,SAAS,EAAC,0CAA0C;IACpD6B,IAAI,EAAC,UAAU;IACftD,mBAAmB,EAAGA,mBAAqB;IAC3CuD,WAAW,EACV,IAAApB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAQ,QAAA,QACG,IAAAb,QAAE,EAAE,oBAAqB,CAAC,EAC5B,IAAAK,MAAA,CAAAC,aAAA,EAAC9C,WAAA,CAAAkE,IAAI;MAAClB,IAAI,EAAGY;IAAU,CAAE,CACxB,CACF;IACDO,SAAS,EAAGf;EAAS,CACrB,CACS,CAEX,CAEU,CAAC;AAEjB"}
1
+ {"version":3,"names":["_compose","require","_components","_i18n","_icons","_data","_coreData","_preferences","_store","_postPreviewButton","_interopRequireDefault","PreviewDropdown","forceIsAutosaveable","disabled","deviceType","homeUrl","isTemplate","isViewable","showIconLabels","useSelect","select","_getPostType$viewable","getDeviceType","getCurrentPostType","editorStore","getUnstableBase","getPostType","coreStore","get","preferencesStore","_currentPostType","home","viewable","setDeviceType","useDispatch","isMobile","useViewportMatch","popoverProps","placement","toggleProps","className","size","showTooltip","__experimentalIsFocusable","menuProps","__","deviceIcons","mobile","tablet","desktop","_react","createElement","DropdownMenu","icon","toLowerCase","label","disableOpenOnArrowDown","onClose","Fragment","MenuGroup","MenuItem","onClick","check","href","target","external","VisuallyHidden","as","default","role","textContent","Icon","onPreview"],"sources":["@wordpress/editor/src/components/preview-dropdown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tVisuallyHidden,\n\tIcon,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { check, desktop, mobile, tablet, external } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport PostPreviewButton from '../post-preview-button';\n\nexport default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {\n\tconst { deviceType, homeUrl, isTemplate, isViewable, showIconLabels } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getDeviceType, getCurrentPostType } = select( editorStore );\n\t\t\tconst { getUnstableBase, getPostType } = select( coreStore );\n\t\t\tconst { get } = select( preferencesStore );\n\t\t\tconst _currentPostType = getCurrentPostType();\n\t\t\treturn {\n\t\t\t\tdeviceType: getDeviceType(),\n\t\t\t\thomeUrl: getUnstableBase()?.home,\n\t\t\t\tisTemplate: _currentPostType === 'wp_template',\n\t\t\t\tisViewable: getPostType( _currentPostType )?.viewable ?? false,\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t}, [] );\n\tconst { setDeviceType } = useDispatch( editorStore );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tif ( isMobile ) return null;\n\n\tconst popoverProps = {\n\t\tplacement: 'bottom-end',\n\t};\n\tconst toggleProps = {\n\t\tclassName: 'editor-preview-dropdown__toggle',\n\t\tsize: 'compact',\n\t\tshowTooltip: ! showIconLabels,\n\t\tdisabled,\n\t\t__experimentalIsFocusable: disabled,\n\t};\n\tconst menuProps = {\n\t\t'aria-label': __( 'View options' ),\n\t};\n\n\tconst deviceIcons = {\n\t\tmobile,\n\t\ttablet,\n\t\tdesktop,\n\t};\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"editor-preview-dropdown\"\n\t\t\tpopoverProps={ popoverProps }\n\t\t\ttoggleProps={ toggleProps }\n\t\t\tmenuProps={ menuProps }\n\t\t\ticon={ deviceIcons[ deviceType.toLowerCase() ] }\n\t\t\tlabel={ __( 'View' ) }\n\t\t\tdisableOpenOnArrowDown={ disabled }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Desktop' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Desktop' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Desktop' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Tablet' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Tablet' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Tablet' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Mobile' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Mobile' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Mobile' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t{ isTemplate && (\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\thref={ homeUrl }\n\t\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\t\ticon={ external }\n\t\t\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'View site' ) }\n\t\t\t\t\t\t\t\t<VisuallyHidden as=\"span\">\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t/* translators: accessibility text */\n\t\t\t\t\t\t\t\t\t\t__( '(opens in a new tab)' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isViewable && (\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<PostPreviewButton\n\t\t\t\t\t\t\t\tclassName=\"editor-preview-dropdown__button-external\"\n\t\t\t\t\t\t\t\trole=\"menuitem\"\n\t\t\t\t\t\t\t\tforceIsAutosaveable={ forceIsAutosaveable }\n\t\t\t\t\t\t\t\ttextContent={\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Preview in new tab' ) }\n\t\t\t\t\t\t\t\t\t\t<Icon icon={ external } />\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\tonPreview={ onClose }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAOA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAC,sBAAA,CAAAT,OAAA;AArBA;AACA;AACA;;AAeA;AACA;AACA;;AAIe,SAASU,eAAeA,CAAE;EAAEC,mBAAmB;EAAEC;AAAS,CAAC,EAAG;EAC5E,MAAM;IAAEC,UAAU;IAAEC,OAAO;IAAEC,UAAU;IAAEC,UAAU;IAAEC;EAAe,CAAC,GACpE,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAAA,IAAAC,qBAAA;IACxB,MAAM;MAAEC,aAAa;MAAEC;IAAmB,CAAC,GAAGH,MAAM,CAAEI,YAAY,CAAC;IACnE,MAAM;MAAEC,eAAe;MAAEC;IAAY,C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OAAO,EAAGJ;EAAS,GAEjB,IAAAZ,QAAE,EAAE,WAAY,CAAC,EACnB,IAAAK,MAAA,CAAAC,aAAA,EAACjD,WAAA,CAAAgE,cAAc;IAACC,EAAE,EAAC;EAAM,GAEvB;EACA,IAAAtB,QAAE,EAAE,sBAAuB,CAEb,CACP,CACA,CACX,EACC5B,UAAU,IACX,IAAAiC,MAAA,CAAAC,aAAA,EAACjD,WAAA,CAAAyD,SAAS,QACT,IAAAT,MAAA,CAAAC,aAAA,EAAC1C,kBAAA,CAAA2D,OAAiB;IACjB5B,SAAS,EAAC,0CAA0C;IACpD6B,IAAI,EAAC,UAAU;IACfzD,mBAAmB,EAAGA,mBAAqB;IAC3C0D,WAAW,EACV,IAAApB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAQ,QAAA,QACG,IAAAb,QAAE,EAAE,oBAAqB,CAAC,EAC5B,IAAAK,MAAA,CAAAC,aAAA,EAACjD,WAAA,CAAAqE,IAAI;MAAClB,IAAI,EAAGY;IAAU,CAAE,CACxB,CACF;IACDO,SAAS,EAAGf;EAAS,CACrB,CACS,CAEX,CAEU,CAAC;AAEjB"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.ExperimentalEditorProvider = void 0;
8
8
  var _react = require("react");
9
+ var _reactNative = require("react-native");
9
10
  var _memize = _interopRequireDefault(require("memize"));
10
11
  var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
11
12
  var _reactNativeBridge = _interopRequireWildcard(require("@wordpress/react-native-bridge"));
@@ -66,6 +67,7 @@ class NativeEditorProvider extends _element.Component {
66
67
  this.post = this.props.post;
67
68
  this.props.addEntities(postTypeEntities);
68
69
  this.props.receiveEntityRecords('postType', this.post.type, this.post);
70
+ this.onHardwareBackPress = this.onHardwareBackPress.bind(this);
69
71
  this.getEditorSettings = (0, _memize.default)((settings, capabilities) => ({
70
72
  ...settings,
71
73
  capabilities
@@ -141,6 +143,7 @@ class NativeEditorProvider extends _element.Component {
141
143
  isHelpVisible: true
142
144
  });
143
145
  });
146
+ this.hardwareBackPressListener = _reactNative.BackHandler.addEventListener('hardwareBackPress', this.onHardwareBackPress);
144
147
 
145
148
  // Request current block impressions from native app.
146
149
  (0, _reactNativeBridge.requestBlockTypeImpressions)(storedImpressions => {
@@ -194,6 +197,9 @@ class NativeEditorProvider extends _element.Component {
194
197
  if (this.subscriptionParentShowEditorHelp) {
195
198
  this.subscriptionParentShowEditorHelp.remove();
196
199
  }
200
+ if (this.hardwareBackPressListener) {
201
+ this.hardwareBackPressListener.remove();
202
+ }
197
203
  }
198
204
  getThemeColors({
199
205
  rawStyles,
@@ -218,6 +224,17 @@ class NativeEditorProvider extends _element.Component {
218
224
  _reactNativeBridge.default.editorDidMount(unsupportedBlockNames);
219
225
  }
220
226
  }
227
+ onHardwareBackPress() {
228
+ const {
229
+ clearSelectedBlock,
230
+ selectedBlockIndex
231
+ } = this.props;
232
+ if (selectedBlockIndex !== -1) {
233
+ clearSelectedBlock();
234
+ return true;
235
+ }
236
+ return false;
237
+ }
221
238
  serializeToNativeAction() {
222
239
  const title = this.props.title;
223
240
  let html;
@@ -329,6 +346,7 @@ const ComposedNativeProvider = (0, _compose.compose)([(0, _data.withSelect)(sele
329
346
  updateEditorSettings
330
347
  } = dispatch(_editor.store);
331
348
  const {
349
+ clearSelectedBlock,
332
350
  updateSettings,
333
351
  insertBlock,
334
352
  replaceBlock
@@ -351,6 +369,7 @@ const ComposedNativeProvider = (0, _compose.compose)([(0, _data.withSelect)(sele
351
369
  insertBlock,
352
370
  createSuccessNotice,
353
371
  createErrorNotice,
372
+ clearSelectedBlock,
354
373
  editTitle(title) {
355
374
  editPost({
356
375
  title