@wordpress/editor 13.24.1 → 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 (307) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +1 -1
  3. package/build/components/document-bar/index.js +164 -0
  4. package/build/components/document-bar/index.js.map +1 -0
  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/edit-template-blocks-notification.js +106 -0
  10. package/build/components/editor-canvas/edit-template-blocks-notification.js.map +1 -0
  11. package/build/components/editor-canvas/index.js +298 -0
  12. package/build/components/editor-canvas/index.js.map +1 -0
  13. package/build/components/entities-saved-states/index.js +3 -1
  14. package/build/components/entities-saved-states/index.js.map +1 -1
  15. package/build/components/global-keyboard-shortcuts/index.js +12 -2
  16. package/build/components/global-keyboard-shortcuts/index.js.map +1 -1
  17. package/build/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
  18. package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
  19. package/build/components/index.js +72 -8
  20. package/build/components/index.js.map +1 -1
  21. package/build/components/index.native.js +9 -1
  22. package/build/components/index.native.js.map +1 -1
  23. package/build/components/inserter-sidebar/index.js +77 -0
  24. package/build/components/inserter-sidebar/index.js.map +1 -0
  25. package/build/components/list-view-sidebar/index.js +150 -0
  26. package/build/components/list-view-sidebar/index.js.map +1 -0
  27. package/build/components/list-view-sidebar/list-view-outline.js +28 -0
  28. package/build/components/list-view-sidebar/list-view-outline.js.map +1 -0
  29. package/build/components/offline-status/index.native.js +85 -0
  30. package/build/components/offline-status/index.native.js.map +1 -0
  31. package/build/components/page-attributes/panel.js +63 -0
  32. package/build/components/page-attributes/panel.js.map +1 -0
  33. package/build/components/post-discussion/panel.js +59 -0
  34. package/build/components/post-discussion/panel.js.map +1 -0
  35. package/build/components/post-excerpt/check.js +19 -0
  36. package/build/components/post-excerpt/check.js.map +1 -1
  37. package/build/components/post-excerpt/panel.js +55 -0
  38. package/build/components/post-excerpt/panel.js.map +1 -0
  39. package/build/components/post-excerpt/plugin.js +72 -0
  40. package/build/components/post-excerpt/plugin.js.map +1 -0
  41. package/build/components/post-featured-image/index.js +5 -8
  42. package/build/components/post-featured-image/index.js.map +1 -1
  43. package/build/components/post-featured-image/panel.js +60 -0
  44. package/build/components/post-featured-image/panel.js.map +1 -0
  45. package/build/components/post-last-revision/panel.js +27 -0
  46. package/build/components/post-last-revision/panel.js.map +1 -0
  47. package/build/components/post-publish-button/index.js +1 -0
  48. package/build/components/post-publish-button/index.js.map +1 -1
  49. package/build/components/post-publish-panel/maybe-upload-media.js +2 -4
  50. package/build/components/post-publish-panel/maybe-upload-media.js.map +1 -1
  51. package/build/components/post-saved-state/index.js +13 -8
  52. package/build/components/post-saved-state/index.js.map +1 -1
  53. package/build/components/post-schedule/panel.js +1 -1
  54. package/build/components/post-schedule/panel.js.map +1 -1
  55. package/build/components/post-taxonomies/panel.js +68 -0
  56. package/build/components/post-taxonomies/panel.js.map +1 -0
  57. package/build/components/post-template/block-theme.js +100 -0
  58. package/build/components/post-template/block-theme.js.map +1 -0
  59. package/build/components/post-template/classic-theme.js +171 -0
  60. package/build/components/post-template/classic-theme.js.map +1 -0
  61. package/build/components/post-template/create-new-template-modal.js +98 -0
  62. package/build/components/post-template/create-new-template-modal.js.map +1 -0
  63. package/build/components/post-template/create-new-template.js +55 -0
  64. package/build/components/post-template/create-new-template.js.map +1 -0
  65. package/build/components/post-template/hooks.js +88 -0
  66. package/build/components/post-template/hooks.js.map +1 -0
  67. package/build/components/post-template/panel.js +70 -0
  68. package/build/components/post-template/panel.js.map +1 -0
  69. package/build/components/post-template/reset-default-template.js +48 -0
  70. package/build/components/post-template/reset-default-template.js.map +1 -0
  71. package/build/components/post-template/swap-template-button.js +86 -0
  72. package/build/components/post-template/swap-template-button.js.map +1 -0
  73. package/build/components/post-title/index.native.js +25 -15
  74. package/build/components/post-title/index.native.js.map +1 -1
  75. package/build/components/post-view-link/index.js +58 -0
  76. package/build/components/post-view-link/index.js.map +1 -0
  77. package/build/components/post-visibility/check.js +5 -17
  78. package/build/components/post-visibility/check.js.map +1 -1
  79. package/build/components/preview-dropdown/index.js +118 -0
  80. package/build/components/preview-dropdown/index.js.map +1 -0
  81. package/build/components/provider/index.js +24 -82
  82. package/build/components/provider/index.js.map +1 -1
  83. package/build/components/provider/index.native.js +36 -8
  84. package/build/components/provider/index.native.js.map +1 -1
  85. package/build/components/provider/navigation-block-editing-mode.js +40 -0
  86. package/build/components/provider/navigation-block-editing-mode.js.map +1 -0
  87. package/build/components/provider/use-block-editor-settings.js +38 -15
  88. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  89. package/build/hooks/index.js +1 -0
  90. package/build/hooks/index.js.map +1 -1
  91. package/build/hooks/pattern-partial-syncing.js +49 -0
  92. package/build/hooks/pattern-partial-syncing.js.map +1 -0
  93. package/build/private-apis.js +14 -0
  94. package/build/private-apis.js.map +1 -1
  95. package/build/store/actions.js +161 -13
  96. package/build/store/actions.js.map +1 -1
  97. package/build/store/defaults.js +2 -1
  98. package/build/store/defaults.js.map +1 -1
  99. package/build/store/index.js +5 -0
  100. package/build/store/index.js.map +1 -1
  101. package/build/store/private-actions.js +52 -0
  102. package/build/store/private-actions.js.map +1 -0
  103. package/build/store/private-selectors.js +52 -0
  104. package/build/store/private-selectors.js.map +1 -0
  105. package/build/store/reducer.js +109 -27
  106. package/build/store/reducer.js.map +1 -1
  107. package/build/store/reducer.native.js +0 -1
  108. package/build/store/reducer.native.js.map +1 -1
  109. package/build/store/selectors.js +104 -9
  110. package/build/store/selectors.js.map +1 -1
  111. package/build/utils/media-upload/index.js +8 -2
  112. package/build/utils/media-upload/index.js.map +1 -1
  113. package/build-module/components/document-bar/index.js +156 -0
  114. package/build-module/components/document-bar/index.js.map +1 -0
  115. package/build-module/components/document-outline/index.js +82 -1
  116. package/build-module/components/document-outline/index.js.map +1 -1
  117. package/build-module/components/document-tools/index.js +151 -0
  118. package/build-module/components/document-tools/index.js.map +1 -0
  119. package/build-module/components/editor-canvas/edit-template-blocks-notification.js +100 -0
  120. package/build-module/components/editor-canvas/edit-template-blocks-notification.js.map +1 -0
  121. package/build-module/components/editor-canvas/index.js +289 -0
  122. package/build-module/components/editor-canvas/index.js.map +1 -0
  123. package/build-module/components/entities-saved-states/index.js +3 -1
  124. package/build-module/components/entities-saved-states/index.js.map +1 -1
  125. package/build-module/components/global-keyboard-shortcuts/index.js +12 -2
  126. package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -1
  127. package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
  128. package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
  129. package/build-module/components/index.js +9 -1
  130. package/build-module/components/index.js.map +1 -1
  131. package/build-module/components/index.native.js +1 -0
  132. package/build-module/components/index.native.js.map +1 -1
  133. package/build-module/components/inserter-sidebar/index.js +70 -0
  134. package/build-module/components/inserter-sidebar/index.js.map +1 -0
  135. package/build-module/components/list-view-sidebar/index.js +142 -0
  136. package/build-module/components/list-view-sidebar/index.js.map +1 -0
  137. package/build-module/components/list-view-sidebar/list-view-outline.js +20 -0
  138. package/build-module/components/list-view-sidebar/list-view-outline.js.map +1 -0
  139. package/build-module/components/offline-status/index.native.js +77 -0
  140. package/build-module/components/offline-status/index.native.js.map +1 -0
  141. package/build-module/components/page-attributes/panel.js +53 -0
  142. package/build-module/components/page-attributes/panel.js.map +1 -0
  143. package/build-module/components/post-discussion/panel.js +50 -0
  144. package/build-module/components/post-discussion/panel.js.map +1 -0
  145. package/build-module/components/post-excerpt/check.js +19 -0
  146. package/build-module/components/post-excerpt/check.js.map +1 -1
  147. package/build-module/components/post-excerpt/panel.js +48 -0
  148. package/build-module/components/post-excerpt/panel.js.map +1 -0
  149. package/build-module/components/post-excerpt/plugin.js +64 -0
  150. package/build-module/components/post-excerpt/plugin.js.map +1 -0
  151. package/build-module/components/post-featured-image/index.js +5 -8
  152. package/build-module/components/post-featured-image/index.js.map +1 -1
  153. package/build-module/components/post-featured-image/panel.js +51 -0
  154. package/build-module/components/post-featured-image/panel.js.map +1 -0
  155. package/build-module/components/post-last-revision/panel.js +18 -0
  156. package/build-module/components/post-last-revision/panel.js.map +1 -0
  157. package/build-module/components/post-publish-button/index.js +1 -0
  158. package/build-module/components/post-publish-button/index.js.map +1 -1
  159. package/build-module/components/post-publish-panel/maybe-upload-media.js +2 -4
  160. package/build-module/components/post-publish-panel/maybe-upload-media.js.map +1 -1
  161. package/build-module/components/post-saved-state/index.js +13 -8
  162. package/build-module/components/post-saved-state/index.js.map +1 -1
  163. package/build-module/components/post-schedule/panel.js +1 -1
  164. package/build-module/components/post-schedule/panel.js.map +1 -1
  165. package/build-module/components/post-taxonomies/panel.js +59 -0
  166. package/build-module/components/post-taxonomies/panel.js.map +1 -0
  167. package/build-module/components/post-template/block-theme.js +92 -0
  168. package/build-module/components/post-template/block-theme.js.map +1 -0
  169. package/build-module/components/post-template/classic-theme.js +162 -0
  170. package/build-module/components/post-template/classic-theme.js.map +1 -0
  171. package/build-module/components/post-template/create-new-template-modal.js +91 -0
  172. package/build-module/components/post-template/create-new-template-modal.js.map +1 -0
  173. package/build-module/components/post-template/create-new-template.js +47 -0
  174. package/build-module/components/post-template/create-new-template.js.map +1 -0
  175. package/build-module/components/post-template/hooks.js +78 -0
  176. package/build-module/components/post-template/hooks.js.map +1 -0
  177. package/build-module/components/post-template/panel.js +62 -0
  178. package/build-module/components/post-template/panel.js.map +1 -0
  179. package/build-module/components/post-template/reset-default-template.js +41 -0
  180. package/build-module/components/post-template/reset-default-template.js.map +1 -0
  181. package/build-module/components/post-template/swap-template-button.js +79 -0
  182. package/build-module/components/post-template/swap-template-button.js.map +1 -0
  183. package/build-module/components/post-title/index.native.js +26 -16
  184. package/build-module/components/post-title/index.native.js.map +1 -1
  185. package/build-module/components/post-view-link/index.js +51 -0
  186. package/build-module/components/post-view-link/index.js.map +1 -0
  187. package/build-module/components/post-visibility/check.js +6 -16
  188. package/build-module/components/post-visibility/check.js.map +1 -1
  189. package/build-module/components/preview-dropdown/index.js +110 -0
  190. package/build-module/components/preview-dropdown/index.js.map +1 -0
  191. package/build-module/components/provider/index.js +25 -83
  192. package/build-module/components/provider/index.js.map +1 -1
  193. package/build-module/components/provider/index.native.js +37 -9
  194. package/build-module/components/provider/index.native.js.map +1 -1
  195. package/build-module/components/provider/navigation-block-editing-mode.js +34 -0
  196. package/build-module/components/provider/navigation-block-editing-mode.js.map +1 -0
  197. package/build-module/components/provider/use-block-editor-settings.js +38 -15
  198. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  199. package/build-module/hooks/index.js +1 -0
  200. package/build-module/hooks/index.js.map +1 -1
  201. package/build-module/hooks/pattern-partial-syncing.js +46 -0
  202. package/build-module/hooks/pattern-partial-syncing.js.map +1 -0
  203. package/build-module/private-apis.js +14 -0
  204. package/build-module/private-apis.js.map +1 -1
  205. package/build-module/store/actions.js +147 -9
  206. package/build-module/store/actions.js.map +1 -1
  207. package/build-module/store/defaults.js +2 -1
  208. package/build-module/store/defaults.js.map +1 -1
  209. package/build-module/store/index.js +5 -0
  210. package/build-module/store/index.js.map +1 -1
  211. package/build-module/store/private-actions.js +44 -0
  212. package/build-module/store/private-actions.js.map +1 -0
  213. package/build-module/store/private-selectors.js +43 -0
  214. package/build-module/store/private-selectors.js.map +1 -0
  215. package/build-module/store/reducer.js +103 -26
  216. package/build-module/store/reducer.js.map +1 -1
  217. package/build-module/store/reducer.native.js +1 -2
  218. package/build-module/store/reducer.native.js.map +1 -1
  219. package/build-module/store/selectors.js +93 -6
  220. package/build-module/store/selectors.js.map +1 -1
  221. package/build-module/utils/media-upload/index.js +8 -2
  222. package/build-module/utils/media-upload/index.js.map +1 -1
  223. package/build-style/style-rtl.css +433 -0
  224. package/build-style/style.css +433 -0
  225. package/package.json +32 -31
  226. package/src/components/document-bar/index.js +193 -0
  227. package/src/components/document-bar/style.scss +130 -0
  228. package/src/components/document-outline/index.js +48 -1
  229. package/src/components/document-outline/style.scss +12 -0
  230. package/src/components/document-tools/index.js +177 -0
  231. package/src/components/document-tools/style.scss +98 -0
  232. package/src/components/editor-canvas/edit-template-blocks-notification.js +108 -0
  233. package/src/components/editor-canvas/index.js +386 -0
  234. package/src/components/editor-canvas/style.scss +5 -0
  235. package/src/components/entities-saved-states/index.js +3 -1
  236. package/src/components/entities-saved-states/style.scss +4 -0
  237. package/src/components/global-keyboard-shortcuts/index.js +12 -2
  238. package/src/components/global-keyboard-shortcuts/register-shortcuts.js +10 -0
  239. package/src/components/index.js +9 -1
  240. package/src/components/index.native.js +1 -0
  241. package/src/components/inserter-sidebar/index.js +73 -0
  242. package/src/components/inserter-sidebar/style.scss +22 -0
  243. package/src/components/list-view-sidebar/index.js +169 -0
  244. package/src/components/list-view-sidebar/list-view-outline.js +37 -0
  245. package/src/components/list-view-sidebar/style.scss +84 -0
  246. package/src/components/offline-status/index.native.js +101 -0
  247. package/src/components/offline-status/style.native.scss +28 -0
  248. package/src/components/offline-status/test/index.native.js +108 -0
  249. package/src/components/page-attributes/panel.js +62 -0
  250. package/src/components/post-discussion/panel.js +57 -0
  251. package/src/components/post-excerpt/check.js +18 -0
  252. package/src/components/post-excerpt/panel.js +57 -0
  253. package/src/components/post-excerpt/plugin.js +61 -0
  254. package/src/components/post-excerpt/test/plugin.js +36 -0
  255. package/src/components/post-featured-image/index.js +3 -7
  256. package/src/components/post-featured-image/panel.js +55 -0
  257. package/src/components/post-last-revision/panel.js +22 -0
  258. package/src/components/post-last-revision/style.scss +10 -0
  259. package/src/components/post-publish-button/index.js +1 -0
  260. package/src/components/post-publish-panel/maybe-upload-media.js +3 -8
  261. package/src/components/post-saved-state/index.js +9 -8
  262. package/src/components/post-saved-state/test/__snapshots__/index.js.snap +2 -2
  263. package/src/components/post-schedule/panel.js +1 -1
  264. package/src/components/post-taxonomies/panel.js +66 -0
  265. package/src/components/post-template/block-theme.js +110 -0
  266. package/src/components/post-template/classic-theme.js +213 -0
  267. package/src/components/post-template/create-new-template-modal.js +139 -0
  268. package/src/components/post-template/create-new-template.js +50 -0
  269. package/src/components/post-template/hooks.js +95 -0
  270. package/src/components/post-template/panel.js +66 -0
  271. package/src/components/post-template/reset-default-template.js +43 -0
  272. package/src/components/post-template/style.scss +52 -0
  273. package/src/components/post-template/swap-template-button.js +86 -0
  274. package/src/components/post-title/index.native.js +32 -18
  275. package/src/components/post-title/style.scss +1 -0
  276. package/src/components/post-title/test/__snapshots__/index.native.js.snap +25 -0
  277. package/src/components/post-title/test/index.native.js +78 -0
  278. package/src/components/post-view-link/index.js +47 -0
  279. package/src/components/post-visibility/check.js +10 -15
  280. package/src/components/post-visibility/test/check.js +24 -13
  281. package/src/components/preview-dropdown/index.js +133 -0
  282. package/src/components/preview-dropdown/style.scss +5 -0
  283. package/src/components/provider/index.js +28 -118
  284. package/src/components/provider/index.native.js +55 -14
  285. package/src/components/provider/navigation-block-editing-mode.js +37 -0
  286. package/src/components/provider/use-block-editor-settings.js +42 -17
  287. package/src/hooks/index.js +1 -0
  288. package/src/hooks/pattern-partial-syncing.js +73 -0
  289. package/src/private-apis.js +14 -0
  290. package/src/store/actions.js +160 -9
  291. package/src/store/defaults.js +1 -0
  292. package/src/store/index.js +5 -0
  293. package/src/store/private-actions.js +61 -0
  294. package/src/store/private-selectors.js +51 -0
  295. package/src/store/reducer.js +103 -26
  296. package/src/store/reducer.native.js +0 -2
  297. package/src/store/selectors.js +144 -42
  298. package/src/store/test/actions.js +56 -0
  299. package/src/store/test/reducer.js +98 -0
  300. package/src/store/test/selectors.js +137 -147
  301. package/src/style.scss +7 -0
  302. package/src/utils/media-upload/index.js +9 -2
  303. package/build/components/post-template/index.js +0 -66
  304. package/build/components/post-template/index.js.map +0 -1
  305. package/build-module/components/post-template/index.js +0 -57
  306. package/build-module/components/post-template/index.js.map +0 -1
  307. package/src/components/post-template/index.js +0 -64
@@ -0,0 +1,86 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useMemo, useState, useCallback } from '@wordpress/element';
5
+ import { decodeEntities } from '@wordpress/html-entities';
6
+ import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
7
+ import { MenuItem, Modal } from '@wordpress/components';
8
+ import { __ } from '@wordpress/i18n';
9
+ import { useDispatch } from '@wordpress/data';
10
+ import { store as coreStore } from '@wordpress/core-data';
11
+ import { parse } from '@wordpress/blocks';
12
+ import { useAsyncList } from '@wordpress/compose';
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+ import { useAvailableTemplates, useEditedPostContext } from './hooks';
18
+
19
+ export default function SwapTemplateButton( { onClick } ) {
20
+ const [ showModal, setShowModal ] = useState( false );
21
+ const onClose = useCallback( () => {
22
+ setShowModal( false );
23
+ }, [] );
24
+ const { postType, postId } = useEditedPostContext();
25
+ const availableTemplates = useAvailableTemplates( postType );
26
+ const { editEntityRecord } = useDispatch( coreStore );
27
+ if ( ! availableTemplates?.length ) {
28
+ return null;
29
+ }
30
+ const onTemplateSelect = async ( template ) => {
31
+ editEntityRecord(
32
+ 'postType',
33
+ postType,
34
+ postId,
35
+ { template: template.name },
36
+ { undoIgnore: true }
37
+ );
38
+ onClose(); // Close the template suggestions modal first.
39
+ onClick();
40
+ };
41
+ return (
42
+ <>
43
+ <MenuItem onClick={ () => setShowModal( true ) }>
44
+ { __( 'Swap template' ) }
45
+ </MenuItem>
46
+ { showModal && (
47
+ <Modal
48
+ title={ __( 'Choose a template' ) }
49
+ onRequestClose={ onClose }
50
+ overlayClassName="editor-post-template__swap-template-modal"
51
+ isFullScreen
52
+ >
53
+ <div className="editor-post-template__swap-template-modal-content">
54
+ <TemplatesList
55
+ postType={ postType }
56
+ onSelect={ onTemplateSelect }
57
+ />
58
+ </div>
59
+ </Modal>
60
+ ) }
61
+ </>
62
+ );
63
+ }
64
+
65
+ function TemplatesList( { postType, onSelect } ) {
66
+ const availableTemplates = useAvailableTemplates( postType );
67
+ const templatesAsPatterns = useMemo(
68
+ () =>
69
+ availableTemplates.map( ( template ) => ( {
70
+ name: template.slug,
71
+ blocks: parse( template.content.raw ),
72
+ title: decodeEntities( template.title.rendered ),
73
+ id: template.id,
74
+ } ) ),
75
+ [ availableTemplates ]
76
+ );
77
+ const shownTemplates = useAsyncList( templatesAsPatterns );
78
+ return (
79
+ <BlockPatternsList
80
+ label={ __( 'Templates' ) }
81
+ blockPatterns={ templatesAsPatterns }
82
+ shownPatterns={ shownTemplates }
83
+ onClickPattern={ onSelect }
84
+ />
85
+ );
86
+ }
@@ -7,7 +7,7 @@ import { View } from 'react-native';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { Component } from '@wordpress/element';
10
- import { create, insert } from '@wordpress/rich-text';
10
+ import { create, toHTMLString, insert } from '@wordpress/rich-text';
11
11
  import { decodeEntities } from '@wordpress/html-entities';
12
12
  import { withDispatch, withSelect } from '@wordpress/data';
13
13
  import { withFocusOutside } from '@wordpress/components';
@@ -16,6 +16,7 @@ import { __, sprintf } from '@wordpress/i18n';
16
16
  import { pasteHandler } from '@wordpress/blocks';
17
17
  import { store as blockEditorStore, RichText } from '@wordpress/block-editor';
18
18
  import { store as editorStore } from '@wordpress/editor';
19
+ import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
19
20
 
20
21
  /**
21
22
  * Internal dependencies
@@ -57,7 +58,7 @@ class PostTitle extends Component {
57
58
  this.props.onSelect();
58
59
  }
59
60
 
60
- onPaste( { value, onChange, plainText, html } ) {
61
+ onPaste( { value, plainText, html } ) {
61
62
  const { title, onInsertBlockAfter, onUpdate } = this.props;
62
63
 
63
64
  const content = pasteHandler( {
@@ -65,23 +66,37 @@ class PostTitle extends Component {
65
66
  plainText,
66
67
  } );
67
68
 
68
- if ( content.length ) {
69
- if ( typeof content === 'string' ) {
70
- const valueToInsert = create( { html: content } );
71
- onChange( insert( value, valueToInsert ) );
69
+ if ( ! content.length ) {
70
+ return;
71
+ }
72
+
73
+ if ( typeof content !== 'string' ) {
74
+ const [ firstBlock ] = content;
75
+
76
+ if (
77
+ ! title &&
78
+ ( firstBlock.name === 'core/heading' ||
79
+ firstBlock.name === 'core/paragraph' )
80
+ ) {
81
+ // Strip HTML to avoid unwanted HTML being added to the title.
82
+ // In the majority of cases it is assumed that HTML in the title
83
+ // is undesirable.
84
+ const contentNoHTML = stripHTML(
85
+ firstBlock.attributes.content
86
+ );
87
+ onUpdate( contentNoHTML );
88
+ onInsertBlockAfter( content.slice( 1 ) );
72
89
  } else {
73
- const [ firstBlock ] = content;
74
- if (
75
- ! title &&
76
- ( firstBlock.name === 'core/heading' ||
77
- firstBlock.name === 'core/paragraph' )
78
- ) {
79
- onUpdate( firstBlock.attributes.content );
80
- onInsertBlockAfter( content.slice( 1 ) );
81
- } else {
82
- onInsertBlockAfter( content );
83
- }
90
+ onInsertBlockAfter( content );
84
91
  }
92
+ } else {
93
+ // Strip HTML to avoid unwanted HTML being added to the title.
94
+ // In the majority of cases it is assumed that HTML in the title
95
+ // is undesirable.
96
+ const contentNoHTML = stripHTML( content );
97
+
98
+ const newValue = insert( value, create( { html: contentNoHTML } ) );
99
+ onUpdate( toHTMLString( { value: newValue } ) );
85
100
  }
86
101
  }
87
102
 
@@ -155,7 +170,6 @@ class PostTitle extends Component {
155
170
  tagsToEliminate={ [ 'strong' ] }
156
171
  unstableOnFocus={ this.props.onSelect }
157
172
  onBlur={ this.props.onBlur } // Always assign onBlur as a props.
158
- multiline={ false }
159
173
  style={ titleStyles }
160
174
  styles={ styles }
161
175
  fontSize={ 24 }
@@ -2,4 +2,5 @@
2
2
  .edit-post-text-editor__body .editor-post-title.is-raw-text {
3
3
  margin-bottom: $grid-unit-30;
4
4
  margin-top: 2px; // space for focus outline to appear.
5
+ max-width: none;
5
6
  }
@@ -0,0 +1,25 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`PostTitle does not update title with existing content when pasting HTML 1`] = `
4
+ "<!-- wp:heading -->
5
+ <h2 class="wp-block-heading">Howdy</h2>
6
+ <!-- /wp:heading -->
7
+
8
+ <!-- wp:heading -->
9
+ <h2 class="wp-block-heading">This is a heading.</h2>
10
+ <!-- /wp:heading -->
11
+
12
+ <!-- wp:paragraph -->
13
+ <p>This is a paragraph.</p>
14
+ <!-- /wp:paragraph -->"
15
+ `;
16
+
17
+ exports[`PostTitle populates empty title with first block content when pasting HTML 1`] = `
18
+ "<!-- wp:heading -->
19
+ <h2 class="wp-block-heading">This is a heading.</h2>
20
+ <!-- /wp:heading -->
21
+
22
+ <!-- wp:paragraph -->
23
+ <p>This is a paragraph.</p>
24
+ <!-- /wp:paragraph -->"
25
+ `;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ getEditorTitle,
7
+ initializeEditor,
8
+ pasteIntoRichText,
9
+ selectRangeInRichText,
10
+ screen,
11
+ setupCoreBlocks,
12
+ within,
13
+ } from 'test/helpers';
14
+
15
+ setupCoreBlocks();
16
+
17
+ const HTML_MULTIPLE_TAGS = `<h2>Howdy</h2>
18
+ <h2>This is a heading.</h2>
19
+ <p>This is a paragraph.</p>`;
20
+
21
+ describe( 'PostTitle', () => {
22
+ it( 'populates empty title with first block content when pasting HTML', async () => {
23
+ await initializeEditor( { initialTitle: '' } );
24
+
25
+ const postTitle = within(
26
+ screen.getByTestId( 'post-title' )
27
+ ).getByPlaceholderText( 'Add title' );
28
+ pasteIntoRichText( postTitle, { html: HTML_MULTIPLE_TAGS } );
29
+
30
+ expect( console ).toHaveLogged();
31
+ expect( getEditorTitle() ).toBe( 'Howdy' );
32
+ expect( getEditorHtml() ).toMatchSnapshot();
33
+ } );
34
+
35
+ it( 'does not update title with existing content when pasting HTML', async () => {
36
+ const initialTitle = 'Hello';
37
+ await initializeEditor( { initialTitle } );
38
+
39
+ const postTitle = within(
40
+ screen.getByTestId( 'post-title' )
41
+ ).getByPlaceholderText( 'Add title' );
42
+ selectRangeInRichText( postTitle, 0 );
43
+ pasteIntoRichText( postTitle, { html: HTML_MULTIPLE_TAGS } );
44
+
45
+ expect( console ).toHaveLogged();
46
+ expect( getEditorTitle() ).toBe( initialTitle );
47
+ expect( getEditorHtml() ).toMatchSnapshot();
48
+ } );
49
+
50
+ it( 'updates title with existing content when pasting text', async () => {
51
+ await initializeEditor( { initialTitle: 'World' } );
52
+
53
+ const postTitle = within(
54
+ screen.getByTestId( 'post-title' )
55
+ ).getByPlaceholderText( 'Add title' );
56
+ selectRangeInRichText( postTitle, 0 );
57
+ pasteIntoRichText( postTitle, { text: 'Hello' } );
58
+
59
+ expect( console ).toHaveLogged();
60
+ expect( getEditorTitle() ).toBe( 'HelloWorld' );
61
+ expect( getEditorHtml() ).toBe( '' );
62
+ } );
63
+
64
+ it( 'does not add HTML to title when pasting span tag', async () => {
65
+ const pasteHTML = `<span style="border: 1px solid black">l</span>`;
66
+ await initializeEditor( { initialTitle: 'Helo' } );
67
+
68
+ const postTitle = within(
69
+ screen.getByTestId( 'post-title' )
70
+ ).getByPlaceholderText( 'Add title' );
71
+ selectRangeInRichText( postTitle, 2 );
72
+ pasteIntoRichText( postTitle, { html: pasteHTML } );
73
+
74
+ expect( console ).toHaveLogged();
75
+ expect( getEditorTitle() ).toBe( 'Hello' );
76
+ expect( getEditorHtml() ).toBe( '' );
77
+ } );
78
+ } );
@@ -0,0 +1,47 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { Button } from '@wordpress/components';
6
+ import { external } from '@wordpress/icons';
7
+ import { store as coreStore } from '@wordpress/core-data';
8
+ import { useSelect } from '@wordpress/data';
9
+ import { store as preferencesStore } from '@wordpress/preferences';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import { store as editorStore } from '../../store';
15
+
16
+ export default function PostViewLink() {
17
+ const { hasLoaded, permalink, isPublished, label, showIconLabels } =
18
+ useSelect( ( select ) => {
19
+ // Grab post type to retrieve the view_item label.
20
+ const postTypeSlug = select( editorStore ).getCurrentPostType();
21
+ const postType = select( coreStore ).getPostType( postTypeSlug );
22
+ const { get } = select( preferencesStore );
23
+
24
+ return {
25
+ permalink: select( editorStore ).getPermalink(),
26
+ isPublished: select( editorStore ).isCurrentPostPublished(),
27
+ label: postType?.labels.view_item,
28
+ hasLoaded: !! postType,
29
+ showIconLabels: get( 'core', 'showIconLabels' ),
30
+ };
31
+ }, [] );
32
+
33
+ // Only render the view button if the post is published and has a permalink.
34
+ if ( ! isPublished || ! permalink || ! hasLoaded ) {
35
+ return null;
36
+ }
37
+
38
+ return (
39
+ <Button
40
+ icon={ external }
41
+ label={ label || __( 'View post' ) }
42
+ href={ permalink }
43
+ target="_blank"
44
+ showTooltip={ ! showIconLabels }
45
+ />
46
+ );
47
+ }
@@ -1,26 +1,21 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { compose } from '@wordpress/compose';
5
- import { withSelect } from '@wordpress/data';
4
+ import { useSelect } from '@wordpress/data';
6
5
 
7
6
  /**
8
7
  * Internal dependencies
9
8
  */
10
9
  import { store as editorStore } from '../../store';
11
10
 
12
- export function PostVisibilityCheck( { hasPublishAction, render } ) {
13
- const canEdit = hasPublishAction;
11
+ export default function PostVisibilityCheck( { render } ) {
12
+ const canEdit = useSelect( ( select ) => {
13
+ return (
14
+ select( editorStore ).getCurrentPost()._links?.[
15
+ 'wp:action-publish'
16
+ ] ?? false
17
+ );
18
+ } );
19
+
14
20
  return render( { canEdit } );
15
21
  }
16
-
17
- export default compose( [
18
- withSelect( ( select ) => {
19
- const { getCurrentPost, getCurrentPostType } = select( editorStore );
20
- return {
21
- hasPublishAction:
22
- getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
23
- postType: getCurrentPostType(),
24
- };
25
- } ),
26
- ] )( PostVisibilityCheck );
@@ -3,32 +3,43 @@
3
3
  */
4
4
  import { render, screen } from '@testing-library/react';
5
5
 
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useSelect } from '@wordpress/data';
10
+
11
+ jest.mock( '@wordpress/data/src/components/use-select', () => jest.fn() );
12
+
6
13
  /**
7
14
  * Internal dependencies
8
15
  */
9
- import { PostVisibilityCheck } from '../check';
16
+ import PostVisibilityCheck from '../check';
17
+
18
+ function setupMockSelect( hasPublishAction ) {
19
+ useSelect.mockImplementation( ( mapSelect ) => {
20
+ return mapSelect( () => ( {
21
+ getCurrentPost: () => ( {
22
+ _links: {
23
+ 'wp:action-publish': hasPublishAction,
24
+ },
25
+ } ),
26
+ } ) );
27
+ } );
28
+ }
10
29
 
11
30
  describe( 'PostVisibilityCheck', () => {
12
31
  const renderProp = ( { canEdit } ) => ( canEdit ? 'yes' : 'no' );
13
32
 
14
33
  it( "should not render the edit link if the user doesn't have the right capability", () => {
15
- render(
16
- <PostVisibilityCheck
17
- hasPublishAction={ false }
18
- render={ renderProp }
19
- />
20
- );
34
+ setupMockSelect( false );
35
+ render( <PostVisibilityCheck render={ renderProp } /> );
21
36
  expect( screen.queryByText( 'yes' ) ).not.toBeInTheDocument();
22
37
  expect( screen.getByText( 'no' ) ).toBeVisible();
23
38
  } );
24
39
 
25
40
  it( 'should render if the user has the correct capability', () => {
26
- render(
27
- <PostVisibilityCheck
28
- hasPublishAction={ true }
29
- render={ renderProp }
30
- />
31
- );
41
+ setupMockSelect( true );
42
+ render( <PostVisibilityCheck render={ renderProp } /> );
32
43
  expect( screen.queryByText( 'no' ) ).not.toBeInTheDocument();
33
44
  expect( screen.getByText( 'yes' ) ).toBeVisible();
34
45
  } );
@@ -0,0 +1,133 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useViewportMatch } from '@wordpress/compose';
5
+ import {
6
+ DropdownMenu,
7
+ MenuGroup,
8
+ MenuItem,
9
+ VisuallyHidden,
10
+ Icon,
11
+ } from '@wordpress/components';
12
+ import { __ } from '@wordpress/i18n';
13
+ import { check, desktop, mobile, tablet, external } from '@wordpress/icons';
14
+ import { useSelect, useDispatch } from '@wordpress/data';
15
+ import { store as coreStore } from '@wordpress/core-data';
16
+ import { store as preferencesStore } from '@wordpress/preferences';
17
+
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+ import { store as editorStore } from '../../store';
22
+ import PostPreviewButton from '../post-preview-button';
23
+
24
+ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
25
+ const { deviceType, homeUrl, isTemplate, isViewable, showIconLabels } =
26
+ useSelect( ( select ) => {
27
+ const { getDeviceType, getCurrentPostType } = select( editorStore );
28
+ const { getUnstableBase, getPostType } = select( coreStore );
29
+ const { get } = select( preferencesStore );
30
+ const _currentPostType = getCurrentPostType();
31
+ return {
32
+ deviceType: getDeviceType(),
33
+ homeUrl: getUnstableBase()?.home,
34
+ isTemplate: _currentPostType === 'wp_template',
35
+ isViewable: getPostType( _currentPostType )?.viewable ?? false,
36
+ showIconLabels: get( 'core', 'showIconLabels' ),
37
+ };
38
+ }, [] );
39
+ const { setDeviceType } = useDispatch( editorStore );
40
+ const isMobile = useViewportMatch( 'medium', '<' );
41
+ if ( isMobile ) return null;
42
+
43
+ const popoverProps = {
44
+ placement: 'bottom-end',
45
+ };
46
+ const toggleProps = {
47
+ className: 'editor-preview-dropdown__toggle',
48
+ size: 'compact',
49
+ showTooltip: ! showIconLabels,
50
+ disabled,
51
+ __experimentalIsFocusable: disabled,
52
+ };
53
+ const menuProps = {
54
+ 'aria-label': __( 'View options' ),
55
+ };
56
+
57
+ const deviceIcons = {
58
+ mobile,
59
+ tablet,
60
+ desktop,
61
+ };
62
+
63
+ return (
64
+ <DropdownMenu
65
+ className="editor-preview-dropdown"
66
+ popoverProps={ popoverProps }
67
+ toggleProps={ toggleProps }
68
+ menuProps={ menuProps }
69
+ icon={ deviceIcons[ deviceType.toLowerCase() ] }
70
+ label={ __( 'View' ) }
71
+ disableOpenOnArrowDown={ disabled }
72
+ >
73
+ { ( { onClose } ) => (
74
+ <>
75
+ <MenuGroup>
76
+ <MenuItem
77
+ onClick={ () => setDeviceType( 'Desktop' ) }
78
+ icon={ deviceType === 'Desktop' && check }
79
+ >
80
+ { __( 'Desktop' ) }
81
+ </MenuItem>
82
+ <MenuItem
83
+ onClick={ () => setDeviceType( 'Tablet' ) }
84
+ icon={ deviceType === 'Tablet' && check }
85
+ >
86
+ { __( 'Tablet' ) }
87
+ </MenuItem>
88
+ <MenuItem
89
+ onClick={ () => setDeviceType( 'Mobile' ) }
90
+ icon={ deviceType === 'Mobile' && check }
91
+ >
92
+ { __( 'Mobile' ) }
93
+ </MenuItem>
94
+ </MenuGroup>
95
+ { isTemplate && (
96
+ <MenuGroup>
97
+ <MenuItem
98
+ href={ homeUrl }
99
+ target="_blank"
100
+ icon={ external }
101
+ onClick={ onClose }
102
+ >
103
+ { __( 'View site' ) }
104
+ <VisuallyHidden as="span">
105
+ {
106
+ /* translators: accessibility text */
107
+ __( '(opens in a new tab)' )
108
+ }
109
+ </VisuallyHidden>
110
+ </MenuItem>
111
+ </MenuGroup>
112
+ ) }
113
+ { isViewable && (
114
+ <MenuGroup>
115
+ <PostPreviewButton
116
+ className="editor-preview-dropdown__button-external"
117
+ role="menuitem"
118
+ forceIsAutosaveable={ forceIsAutosaveable }
119
+ textContent={
120
+ <>
121
+ { __( 'Preview in new tab' ) }
122
+ <Icon icon={ external } />
123
+ </>
124
+ }
125
+ onPreview={ onClose }
126
+ />
127
+ </MenuGroup>
128
+ ) }
129
+ </>
130
+ ) }
131
+ </DropdownMenu>
132
+ );
133
+ }
@@ -0,0 +1,5 @@
1
+ .editor-preview-dropdown__button-external {
2
+ width: 100%;
3
+ display: flex;
4
+ justify-content: space-between;
5
+ }