@wordpress/block-library 8.5.0 → 8.6.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 (287) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/buttons/edit.native.js +1 -1
  3. package/build/buttons/edit.native.js.map +1 -1
  4. package/build/columns/edit.js +10 -8
  5. package/build/columns/edit.js.map +1 -1
  6. package/build/columns/edit.native.js +1 -1
  7. package/build/columns/edit.native.js.map +1 -1
  8. package/build/comments/edit/placeholder.js +8 -5
  9. package/build/comments/edit/placeholder.js.map +1 -1
  10. package/build/cover/index.js +13 -4
  11. package/build/cover/index.js.map +1 -1
  12. package/build/cover/variations.js +29 -0
  13. package/build/cover/variations.js.map +1 -0
  14. package/build/embed/edit.js +13 -14
  15. package/build/embed/edit.js.map +1 -1
  16. package/build/embed/edit.native.js +18 -14
  17. package/build/embed/edit.native.js.map +1 -1
  18. package/build/embed/util.js +39 -12
  19. package/build/embed/util.js.map +1 -1
  20. package/build/gallery/edit.js +1 -0
  21. package/build/gallery/edit.js.map +1 -1
  22. package/build/latest-posts/edit.js +10 -10
  23. package/build/latest-posts/edit.js.map +1 -1
  24. package/build/latest-posts/edit.native.js +3 -3
  25. package/build/latest-posts/edit.native.js.map +1 -1
  26. package/build/media-text/constants.js +17 -1
  27. package/build/media-text/constants.js.map +1 -1
  28. package/build/media-text/edit.js +7 -19
  29. package/build/media-text/edit.js.map +1 -1
  30. package/build/media-text/edit.native.js +6 -5
  31. package/build/media-text/edit.native.js.map +1 -1
  32. package/build/media-text/transforms.js +32 -44
  33. package/build/media-text/transforms.js.map +1 -1
  34. package/build/navigation/edit/index.js +56 -86
  35. package/build/navigation/edit/index.js.map +1 -1
  36. package/build/navigation/edit/inner-blocks.js +4 -1
  37. package/build/navigation/edit/inner-blocks.js.map +1 -1
  38. package/build/navigation/edit/menu-inspector-controls.js +2 -5
  39. package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
  40. package/build/navigation/edit/navigation-menu-selector.js +26 -22
  41. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  42. package/build/navigation/edit/unsaved-inner-blocks.js +14 -1
  43. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  44. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +2 -4
  45. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  46. package/build/navigation/edit/use-create-navigation-menu.js +1 -1
  47. package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
  48. package/build/navigation/edit/use-navigation-notice.js +1 -1
  49. package/build/navigation/edit/use-navigation-notice.js.map +1 -1
  50. package/build/navigation-link/edit.js +0 -11
  51. package/build/navigation-link/edit.js.map +1 -1
  52. package/build/navigation-link/link-ui.js +0 -1
  53. package/build/navigation-link/link-ui.js.map +1 -1
  54. package/build/navigation-submenu/edit.js +1 -13
  55. package/build/navigation-submenu/edit.js.map +1 -1
  56. package/build/page-list/edit.js +59 -45
  57. package/build/page-list/edit.js.map +1 -1
  58. package/build/page-list-item/edit.js +3 -2
  59. package/build/page-list-item/edit.js.map +1 -1
  60. package/build/post-content/edit.js +6 -1
  61. package/build/post-content/edit.js.map +1 -1
  62. package/build/post-featured-image/dimension-controls.js +0 -6
  63. package/build/post-featured-image/dimension-controls.js.map +1 -1
  64. package/build/post-featured-image/edit.js +1 -1
  65. package/build/post-featured-image/edit.js.map +1 -1
  66. package/build/pullquote/deprecated.js +3 -3
  67. package/build/pullquote/deprecated.js.map +1 -1
  68. package/build/query/edit/query-placeholder.js +3 -2
  69. package/build/query/edit/query-placeholder.js.map +1 -1
  70. package/build/query/utils.js +26 -9
  71. package/build/query/utils.js.map +1 -1
  72. package/build/table/state.js +12 -4
  73. package/build/table/state.js.map +1 -1
  74. package/build/template-part/edit/import-controls.js +4 -24
  75. package/build/template-part/edit/import-controls.js.map +1 -1
  76. package/build/template-part/edit/utils/transformers.js +69 -19
  77. package/build/template-part/edit/utils/transformers.js.map +1 -1
  78. package/build/text-columns/edit.js +3 -7
  79. package/build/text-columns/edit.js.map +1 -1
  80. package/build/text-columns/save.js +11 -13
  81. package/build/text-columns/save.js.map +1 -1
  82. package/build-module/buttons/edit.native.js +1 -1
  83. package/build-module/buttons/edit.native.js.map +1 -1
  84. package/build-module/columns/edit.js +10 -7
  85. package/build-module/columns/edit.js.map +1 -1
  86. package/build-module/columns/edit.native.js +1 -1
  87. package/build-module/columns/edit.native.js.map +1 -1
  88. package/build-module/comments/edit/placeholder.js +9 -5
  89. package/build-module/comments/edit/placeholder.js.map +1 -1
  90. package/build-module/cover/index.js +12 -4
  91. package/build-module/cover/index.js.map +1 -1
  92. package/build-module/cover/variations.js +19 -0
  93. package/build-module/cover/variations.js.map +1 -0
  94. package/build-module/embed/edit.js +14 -15
  95. package/build-module/embed/edit.js.map +1 -1
  96. package/build-module/embed/edit.native.js +19 -15
  97. package/build-module/embed/edit.native.js.map +1 -1
  98. package/build-module/embed/util.js +34 -10
  99. package/build-module/embed/util.js.map +1 -1
  100. package/build-module/gallery/edit.js +1 -0
  101. package/build-module/gallery/edit.js.map +1 -1
  102. package/build-module/latest-posts/edit.js +10 -9
  103. package/build-module/latest-posts/edit.js.map +1 -1
  104. package/build-module/latest-posts/edit.native.js +3 -3
  105. package/build-module/latest-posts/edit.native.js.map +1 -1
  106. package/build-module/media-text/constants.js +10 -0
  107. package/build-module/media-text/constants.js.map +1 -1
  108. package/build-module/media-text/edit.js +2 -14
  109. package/build-module/media-text/edit.js.map +1 -1
  110. package/build-module/media-text/edit.native.js +4 -3
  111. package/build-module/media-text/edit.native.js.map +1 -1
  112. package/build-module/media-text/transforms.js +32 -44
  113. package/build-module/media-text/transforms.js.map +1 -1
  114. package/build-module/navigation/edit/index.js +58 -88
  115. package/build-module/navigation/edit/index.js.map +1 -1
  116. package/build-module/navigation/edit/inner-blocks.js +4 -1
  117. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  118. package/build-module/navigation/edit/menu-inspector-controls.js +2 -5
  119. package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
  120. package/build-module/navigation/edit/navigation-menu-selector.js +25 -22
  121. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  122. package/build-module/navigation/edit/unsaved-inner-blocks.js +14 -1
  123. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  124. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +2 -4
  125. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  126. package/build-module/navigation/edit/use-create-navigation-menu.js +1 -1
  127. package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
  128. package/build-module/navigation/edit/use-navigation-notice.js +1 -1
  129. package/build-module/navigation/edit/use-navigation-notice.js.map +1 -1
  130. package/build-module/navigation-link/edit.js +0 -11
  131. package/build-module/navigation-link/edit.js.map +1 -1
  132. package/build-module/navigation-link/link-ui.js +0 -1
  133. package/build-module/navigation-link/link-ui.js.map +1 -1
  134. package/build-module/navigation-submenu/edit.js +1 -13
  135. package/build-module/navigation-submenu/edit.js.map +1 -1
  136. package/build-module/page-list/edit.js +61 -47
  137. package/build-module/page-list/edit.js.map +1 -1
  138. package/build-module/page-list-item/edit.js +3 -2
  139. package/build-module/page-list-item/edit.js.map +1 -1
  140. package/build-module/post-content/edit.js +6 -1
  141. package/build-module/post-content/edit.js.map +1 -1
  142. package/build-module/post-featured-image/dimension-controls.js +0 -6
  143. package/build-module/post-featured-image/dimension-controls.js.map +1 -1
  144. package/build-module/post-featured-image/edit.js +1 -1
  145. package/build-module/post-featured-image/edit.js.map +1 -1
  146. package/build-module/pullquote/deprecated.js +3 -2
  147. package/build-module/pullquote/deprecated.js.map +1 -1
  148. package/build-module/query/edit/query-placeholder.js +4 -3
  149. package/build-module/query/edit/query-placeholder.js.map +1 -1
  150. package/build-module/query/utils.js +21 -6
  151. package/build-module/query/utils.js.map +1 -1
  152. package/build-module/table/state.js +13 -5
  153. package/build-module/table/state.js.map +1 -1
  154. package/build-module/template-part/edit/import-controls.js +4 -23
  155. package/build-module/template-part/edit/import-controls.js.map +1 -1
  156. package/build-module/template-part/edit/utils/transformers.js +69 -20
  157. package/build-module/template-part/edit/utils/transformers.js.map +1 -1
  158. package/build-module/text-columns/edit.js +3 -6
  159. package/build-module/text-columns/edit.js.map +1 -1
  160. package/build-module/text-columns/save.js +11 -12
  161. package/build-module/text-columns/save.js.map +1 -1
  162. package/build-style/cover/style-rtl.css +11 -5
  163. package/build-style/cover/style.css +11 -5
  164. package/build-style/editor-rtl.css +5 -1
  165. package/build-style/editor.css +5 -1
  166. package/build-style/navigation/editor-rtl.css +1 -1
  167. package/build-style/navigation/editor.css +1 -1
  168. package/build-style/page-list/editor-rtl.css +4 -0
  169. package/build-style/page-list/editor.css +4 -0
  170. package/build-style/post-featured-image/style-rtl.css +1 -0
  171. package/build-style/post-featured-image/style.css +1 -0
  172. package/build-style/style-rtl.css +12 -5
  173. package/build-style/style.css +12 -5
  174. package/package.json +31 -31
  175. package/src/audio/test/__snapshots__/edit.native.js.snap +44 -4
  176. package/src/audio/test/__snapshots__/transforms.native.js.snap +25 -0
  177. package/src/audio/test/transforms.native.js +42 -0
  178. package/src/block/test/__snapshots__/transforms.native.js.snap +15 -0
  179. package/src/block/test/transforms.native.js +40 -0
  180. package/src/buttons/edit.native.js +1 -1
  181. package/src/buttons/test/__snapshots__/transforms.native.js.snap +31 -0
  182. package/src/buttons/test/transforms.native.js +48 -0
  183. package/src/columns/edit.js +28 -17
  184. package/src/columns/edit.native.js +1 -1
  185. package/src/columns/test/__snapshots__/transforms.native.js.snap +61 -0
  186. package/src/columns/test/transforms.native.js +91 -0
  187. package/src/comment-template/index.php +1 -2
  188. package/src/comments/edit/placeholder.js +16 -4
  189. package/src/cover/block.json +9 -3
  190. package/src/cover/index.js +2 -0
  191. package/src/cover/style.scss +16 -7
  192. package/src/cover/test/__snapshots__/transforms.native.js.snap +73 -0
  193. package/src/cover/test/transforms.native.js +112 -0
  194. package/src/cover/variations.js +20 -0
  195. package/src/embed/edit.js +16 -12
  196. package/src/embed/edit.native.js +28 -18
  197. package/src/embed/test/__snapshots__/transforms.native.js.snap +23 -0
  198. package/src/embed/test/index.js +12 -0
  199. package/src/embed/test/transforms.native.js +44 -0
  200. package/src/embed/util.js +29 -8
  201. package/src/file/test/__snapshots__/edit.native.js.snap +18 -2
  202. package/src/file/test/__snapshots__/transforms.native.js.snap +19 -0
  203. package/src/file/test/transforms.native.js +42 -0
  204. package/src/freeform/test/__snapshots__/transforms.native.js.snap +19 -0
  205. package/src/freeform/test/transforms.native.js +39 -0
  206. package/src/gallery/edit.js +3 -0
  207. package/src/gallery/test/__snapshots__/transforms.native.js.snap +53 -0
  208. package/src/gallery/test/transforms.native.js +52 -0
  209. package/src/group/test/__snapshots__/transforms.native.js.snap +35 -0
  210. package/src/group/test/transforms.native.js +75 -0
  211. package/src/heading/test/__snapshots__/transforms.native.js.snap +47 -0
  212. package/src/heading/test/transforms.native.js +46 -0
  213. package/src/image/test/__snapshots__/transforms.native.js.snap +49 -0
  214. package/src/image/test/transforms.native.js +48 -0
  215. package/src/latest-posts/edit.js +11 -16
  216. package/src/latest-posts/edit.native.js +3 -3
  217. package/src/latest-posts/test/__snapshots__/transforms.native.js.snap +15 -0
  218. package/src/latest-posts/test/transforms.native.js +61 -0
  219. package/src/list/test/__snapshots__/transforms.native.js.snap +85 -0
  220. package/src/list/test/transforms.native.js +56 -0
  221. package/src/media-text/constants.js +16 -0
  222. package/src/media-text/edit.js +8 -18
  223. package/src/media-text/edit.native.js +3 -9
  224. package/src/media-text/test/__snapshots__/transforms.native.js.snap +73 -0
  225. package/src/media-text/test/transforms.native.js +112 -0
  226. package/src/media-text/transforms.js +24 -51
  227. package/src/missing/test/__snapshots__/edit.native.js.snap +20 -2
  228. package/src/more/test/__snapshots__/transforms.native.js.snap +19 -0
  229. package/src/more/test/transforms.native.js +42 -0
  230. package/src/navigation/edit/index.js +104 -107
  231. package/src/navigation/edit/inner-blocks.js +3 -0
  232. package/src/navigation/edit/menu-inspector-controls.js +2 -7
  233. package/src/navigation/edit/navigation-menu-selector.js +41 -25
  234. package/src/navigation/edit/unsaved-inner-blocks.js +46 -33
  235. package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +82 -83
  236. package/src/navigation/edit/use-create-navigation-menu.js +1 -1
  237. package/src/navigation/edit/use-navigation-notice.js +1 -1
  238. package/src/navigation/editor.scss +23 -20
  239. package/src/navigation/index.php +18 -39
  240. package/src/navigation-link/edit.js +0 -9
  241. package/src/navigation-link/index.php +5 -8
  242. package/src/navigation-link/link-ui.js +0 -1
  243. package/src/navigation-submenu/edit.js +0 -10
  244. package/src/navigation-submenu/index.php +23 -6
  245. package/src/nextpage/test/__snapshots__/transforms.native.js.snap +19 -0
  246. package/src/nextpage/test/transforms.native.js +42 -0
  247. package/src/page-list/edit.js +78 -44
  248. package/src/page-list/editor.scss +6 -0
  249. package/src/page-list-item/edit.js +2 -3
  250. package/src/paragraph/test/__snapshots__/transforms.native.js.snap +59 -0
  251. package/src/paragraph/test/transforms.native.js +50 -0
  252. package/src/post-content/edit.js +5 -1
  253. package/src/post-excerpt/index.php +1 -2
  254. package/src/post-featured-image/dimension-controls.js +0 -8
  255. package/src/post-featured-image/edit.js +1 -1
  256. package/src/post-featured-image/style.scss +1 -0
  257. package/src/preformatted/test/__snapshots__/transforms.native.js.snap +31 -0
  258. package/src/preformatted/test/transforms.native.js +42 -0
  259. package/src/pullquote/deprecated.js +2 -6
  260. package/src/pullquote/test/__snapshots__/transforms.native.js.snap +47 -0
  261. package/src/pullquote/test/transforms.native.js +46 -0
  262. package/src/query/edit/query-placeholder.js +10 -5
  263. package/src/query/test/utils.js +33 -1
  264. package/src/query/utils.js +19 -6
  265. package/src/quote/test/__snapshots__/transforms.native.js.snap +39 -0
  266. package/src/quote/test/transforms.native.js +67 -0
  267. package/src/search/test/__snapshots__/edit.native.js.snap +11 -1
  268. package/src/search/test/__snapshots__/transforms.native.js.snap +15 -0
  269. package/src/search/test/transforms.native.js +40 -0
  270. package/src/separator/test/__snapshots__/transforms.native.js.snap +19 -0
  271. package/src/separator/test/transforms.native.js +42 -0
  272. package/src/shortcode/test/__snapshots__/transforms.native.js.snap +19 -0
  273. package/src/shortcode/test/transforms.native.js +42 -0
  274. package/src/social-links/test/__snapshots__/transforms.native.js.snap +31 -0
  275. package/src/social-links/test/transforms.native.js +53 -0
  276. package/src/spacer/test/__snapshots__/transforms.native.js.snap +19 -0
  277. package/src/spacer/test/transforms.native.js +42 -0
  278. package/src/table/state.js +8 -17
  279. package/src/template-part/edit/import-controls.js +2 -29
  280. package/src/template-part/edit/utils/transformers.js +96 -19
  281. package/src/text-columns/edit.js +1 -6
  282. package/src/text-columns/save.js +1 -6
  283. package/src/verse/test/__snapshots__/transforms.native.js.snap +25 -0
  284. package/src/verse/test/transforms.native.js +42 -0
  285. package/src/video/test/__snapshots__/transforms.native.js.snap +41 -0
  286. package/src/video/test/transforms.native.js +48 -0
  287. package/tsconfig.tsbuildinfo +1 -1
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { get } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -62,6 +57,24 @@ export const getEntitiesInfo = ( entities ) => {
62
57
  };
63
58
  };
64
59
 
60
+ /**
61
+ * Helper util to return a value from a certain path of the object.
62
+ * Path is specified as a string of properties, separated by dots,
63
+ * for example: "parent.child".
64
+ *
65
+ * @param {Object} object Input object.
66
+ * @param {string} path Path to the object property.
67
+ * @return {*} Value of the object property at the specified path.
68
+ */
69
+ export const getValueFromObjectPath = ( object, path ) => {
70
+ const normalizedPath = path.split( '.' );
71
+ let value = object;
72
+ normalizedPath.forEach( ( fieldName ) => {
73
+ value = value?.[ fieldName ];
74
+ } );
75
+ return value;
76
+ };
77
+
65
78
  /**
66
79
  * Helper util to map records to add a `name` prop from a
67
80
  * provided path, in order to handle all entities in the same
@@ -74,7 +87,7 @@ export const getEntitiesInfo = ( entities ) => {
74
87
  export const mapToIHasNameAndId = ( entities, path ) => {
75
88
  return ( entities || [] ).map( ( entity ) => ( {
76
89
  ...entity,
77
- name: decodeEntities( get( entity, path ) ),
90
+ name: decodeEntities( getValueFromObjectPath( entity, path ) ),
78
91
  } ) );
79
92
  };
80
93
 
@@ -0,0 +1,39 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Quote block transforms to Columns block 1`] = `
4
+ "<!-- wp:columns -->
5
+ <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
6
+ <div class="wp-block-column" style="flex-basis:100%"><!-- wp:quote {"align":"left","className":"is-style-large"} -->
7
+ <blockquote class="wp-block-quote has-text-align-left is-style-large"><!-- wp:paragraph -->
8
+ <p>"This will make running your own blog a viable alternative again."</p>
9
+ <!-- /wp:paragraph --><cite>— <a href="https://twitter.com/azumbrunnen_/status/1019347243084800005">Adrian Zumbrunnen</a></cite></blockquote>
10
+ <!-- /wp:quote --></div>
11
+ <!-- /wp:column --></div>
12
+ <!-- /wp:columns -->"
13
+ `;
14
+
15
+ exports[`Quote block transforms to Group block 1`] = `
16
+ "<!-- wp:group {"layout":{"type":"constrained"}} -->
17
+ <div class="wp-block-group"><!-- wp:quote {"align":"left","className":"is-style-large"} -->
18
+ <blockquote class="wp-block-quote has-text-align-left is-style-large"><!-- wp:paragraph -->
19
+ <p>"This will make running your own blog a viable alternative again."</p>
20
+ <!-- /wp:paragraph --><cite>— <a href="https://twitter.com/azumbrunnen_/status/1019347243084800005">Adrian Zumbrunnen</a></cite></blockquote>
21
+ <!-- /wp:quote --></div>
22
+ <!-- /wp:group -->"
23
+ `;
24
+
25
+ exports[`Quote block transforms to Pullquote block 1`] = `
26
+ "<!-- wp:pullquote -->
27
+ <figure class="wp-block-pullquote"><blockquote><p>"This will make running your own blog a viable alternative again."</p><cite>— <a href="https://twitter.com/azumbrunnen_/status/1019347243084800005">Adrian Zumbrunnen</a></cite></blockquote></figure>
28
+ <!-- /wp:pullquote -->"
29
+ `;
30
+
31
+ exports[`Quote block transforms unwraps content 1`] = `
32
+ "<!-- wp:paragraph -->
33
+ <p>"This will make running your own blog a viable alternative again."</p>
34
+ <!-- /wp:paragraph -->
35
+
36
+ <!-- wp:paragraph -->
37
+ <p>— <a href="https://twitter.com/azumbrunnen_/status/1019347243084800005">Adrian Zumbrunnen</a></p>
38
+ <!-- /wp:paragraph -->"
39
+ `;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ initializeEditor,
7
+ setupCoreBlocks,
8
+ transformBlock,
9
+ getBlock,
10
+ openBlockActionsMenu,
11
+ fireEvent,
12
+ getBlockTransformOptions,
13
+ } from 'test/helpers';
14
+
15
+ const block = 'Quote';
16
+ const initialHtml = `
17
+ <!-- wp:quote {"align":"left","className":"is-style-large"} -->
18
+ <blockquote class="wp-block-quote has-text-align-left is-style-large"><!-- wp:paragraph -->
19
+ <p>"This will make running your own blog a viable alternative again."</p>
20
+ <!-- /wp:paragraph --><cite>— <a href="https://twitter.com/azumbrunnen_/status/1019347243084800005">Adrian Zumbrunnen</a></cite></blockquote>
21
+ <!-- /wp:quote -->`;
22
+
23
+ const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
24
+ const blockTransforms = [ 'Pullquote', ...transformsWithInnerBlocks ];
25
+
26
+ setupCoreBlocks();
27
+
28
+ describe( `${ block } block transforms`, () => {
29
+ test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
30
+ const screen = await initializeEditor( { initialHtml } );
31
+ const newBlock = await transformBlock( screen, block, blockTransform, {
32
+ hasInnerBlocks:
33
+ transformsWithInnerBlocks.includes( blockTransform ),
34
+ } );
35
+ expect( newBlock ).toBeVisible();
36
+ expect( getEditorHtml() ).toMatchSnapshot();
37
+ } );
38
+
39
+ it( 'unwraps content', async () => {
40
+ const screen = await initializeEditor( { initialHtml } );
41
+ const { getByText } = screen;
42
+ fireEvent.press( getBlock( screen, block ) );
43
+
44
+ await openBlockActionsMenu( screen );
45
+ fireEvent.press( getByText( 'Transform block…' ) );
46
+ fireEvent.press( getByText( 'Unwrap' ) );
47
+
48
+ // The first block created is the content of the Paragraph block.
49
+ const paragraph = getBlock( screen, 'Paragraph', 0 );
50
+ expect( paragraph ).toBeVisible();
51
+ // The second block created is the content of the citation element.
52
+ const citation = getBlock( screen, 'Paragraph', 1 );
53
+ expect( citation ).toBeVisible();
54
+
55
+ expect( getEditorHtml() ).toMatchSnapshot();
56
+ } );
57
+
58
+ it( 'matches expected transformation options', async () => {
59
+ const screen = await initializeEditor( { initialHtml } );
60
+ const transformOptions = await getBlockTransformOptions(
61
+ screen,
62
+ block,
63
+ { canUnwrap: true }
64
+ );
65
+ expect( transformOptions ).toHaveLength( blockTransforms.length );
66
+ } );
67
+ } );
@@ -314,7 +314,17 @@ exports[`Search Block renders block with icon button option matches snapshot 1`]
314
314
  ]
315
315
  }
316
316
  >
317
- Svg
317
+ <Svg
318
+ fill="gray"
319
+ height={24}
320
+ onLayout={[Function]}
321
+ style={{}}
322
+ viewBox="0 0 24 24"
323
+ width={24}
324
+ xmlns="http://www.w3.org/2000/svg"
325
+ >
326
+ Path
327
+ </Svg>
318
328
  </View>
319
329
  </View>
320
330
  </View>
@@ -0,0 +1,15 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Search block transforms to Columns block 1`] = `
4
+ "<!-- wp:columns -->
5
+ <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
6
+ <div class="wp-block-column" style="flex-basis:100%"><!-- wp:search {"label":"Search","buttonText":"Search"} /--></div>
7
+ <!-- /wp:column --></div>
8
+ <!-- /wp:columns -->"
9
+ `;
10
+
11
+ exports[`Search block transforms to Group block 1`] = `
12
+ "<!-- wp:group {"layout":{"type":"constrained"}} -->
13
+ <div class="wp-block-group"><!-- wp:search {"label":"Search","buttonText":"Search"} /--></div>
14
+ <!-- /wp:group -->"
15
+ `;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ initializeEditor,
7
+ setupCoreBlocks,
8
+ transformBlock,
9
+ getBlockTransformOptions,
10
+ } from 'test/helpers';
11
+
12
+ const block = 'Search';
13
+ const initialHtml = `
14
+ <!-- wp:search {"label":"Search","buttonText":"Search"} /-->`;
15
+
16
+ const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
17
+ const blockTransforms = [ ...transformsWithInnerBlocks ];
18
+
19
+ setupCoreBlocks();
20
+
21
+ describe( `${ block } block transforms`, () => {
22
+ test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
23
+ const screen = await initializeEditor( { initialHtml } );
24
+ const newBlock = await transformBlock( screen, block, blockTransform, {
25
+ hasInnerBlocks:
26
+ transformsWithInnerBlocks.includes( blockTransform ),
27
+ } );
28
+ expect( newBlock ).toBeVisible();
29
+ expect( getEditorHtml() ).toMatchSnapshot();
30
+ } );
31
+
32
+ it( 'matches expected transformation options', async () => {
33
+ const screen = await initializeEditor( { initialHtml } );
34
+ const transformOptions = await getBlockTransformOptions(
35
+ screen,
36
+ block
37
+ );
38
+ expect( transformOptions ).toHaveLength( blockTransforms.length );
39
+ } );
40
+ } );
@@ -0,0 +1,19 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Separator block transforms to Columns block 1`] = `
4
+ "<!-- wp:columns -->
5
+ <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
6
+ <div class="wp-block-column" style="flex-basis:100%"><!-- wp:separator -->
7
+ <hr class="wp-block-separator has-alpha-channel-opacity"/>
8
+ <!-- /wp:separator --></div>
9
+ <!-- /wp:column --></div>
10
+ <!-- /wp:columns -->"
11
+ `;
12
+
13
+ exports[`Separator block transforms to Group block 1`] = `
14
+ "<!-- wp:group {"layout":{"type":"constrained"}} -->
15
+ <div class="wp-block-group"><!-- wp:separator -->
16
+ <hr class="wp-block-separator has-alpha-channel-opacity"/>
17
+ <!-- /wp:separator --></div>
18
+ <!-- /wp:group -->"
19
+ `;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ initializeEditor,
7
+ setupCoreBlocks,
8
+ transformBlock,
9
+ getBlockTransformOptions,
10
+ } from 'test/helpers';
11
+
12
+ const block = 'Separator';
13
+ const initialHtml = `
14
+ <!-- wp:separator -->
15
+ <hr class="wp-block-separator has-alpha-channel-opacity"/>
16
+ <!-- /wp:separator -->`;
17
+
18
+ const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
19
+ const blockTransforms = [ ...transformsWithInnerBlocks ];
20
+
21
+ setupCoreBlocks();
22
+
23
+ describe( `${ block } block transforms`, () => {
24
+ test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
25
+ const screen = await initializeEditor( { initialHtml } );
26
+ const newBlock = await transformBlock( screen, block, blockTransform, {
27
+ hasInnerBlocks:
28
+ transformsWithInnerBlocks.includes( blockTransform ),
29
+ } );
30
+ expect( newBlock ).toBeVisible();
31
+ expect( getEditorHtml() ).toMatchSnapshot();
32
+ } );
33
+
34
+ it( 'matches expected transformation options', async () => {
35
+ const screen = await initializeEditor( { initialHtml } );
36
+ const transformOptions = await getBlockTransformOptions(
37
+ screen,
38
+ block
39
+ );
40
+ expect( transformOptions ).toHaveLength( blockTransforms.length );
41
+ } );
42
+ } );
@@ -0,0 +1,19 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Shortcode block transforms to Columns block 1`] = `
4
+ "<!-- wp:columns -->
5
+ <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
6
+ <div class="wp-block-column" style="flex-basis:100%"><!-- wp:shortcode -->
7
+ [youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]
8
+ <!-- /wp:shortcode --></div>
9
+ <!-- /wp:column --></div>
10
+ <!-- /wp:columns -->"
11
+ `;
12
+
13
+ exports[`Shortcode block transforms to Group block 1`] = `
14
+ "<!-- wp:group {"layout":{"type":"constrained"}} -->
15
+ <div class="wp-block-group"><!-- wp:shortcode -->
16
+ [youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]
17
+ <!-- /wp:shortcode --></div>
18
+ <!-- /wp:group -->"
19
+ `;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ initializeEditor,
7
+ setupCoreBlocks,
8
+ transformBlock,
9
+ getBlockTransformOptions,
10
+ } from 'test/helpers';
11
+
12
+ const block = 'Shortcode';
13
+ const initialHtml = `
14
+ <!-- wp:shortcode -->
15
+ [youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]
16
+ <!-- /wp:shortcode -->`;
17
+
18
+ const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
19
+ const blockTransforms = [ ...transformsWithInnerBlocks ];
20
+
21
+ setupCoreBlocks();
22
+
23
+ describe( `${ block } block transforms`, () => {
24
+ test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
25
+ const screen = await initializeEditor( { initialHtml } );
26
+ const newBlock = await transformBlock( screen, block, blockTransform, {
27
+ hasInnerBlocks:
28
+ transformsWithInnerBlocks.includes( blockTransform ),
29
+ } );
30
+ expect( newBlock ).toBeVisible();
31
+ expect( getEditorHtml() ).toMatchSnapshot();
32
+ } );
33
+
34
+ it( 'matches expected transformation options', async () => {
35
+ const screen = await initializeEditor( { initialHtml } );
36
+ const transformOptions = await getBlockTransformOptions(
37
+ screen,
38
+ block
39
+ );
40
+ expect( transformOptions ).toHaveLength( blockTransforms.length );
41
+ } );
42
+ } );
@@ -0,0 +1,31 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Social Icons block transforms to Columns block 1`] = `
4
+ "<!-- wp:columns -->
5
+ <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
6
+ <div class="wp-block-column" style="flex-basis:100%"><!-- wp:social-links -->
7
+ <ul class="wp-block-social-links"><!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->
8
+
9
+ <!-- wp:social-link {"service":"facebook"} /-->
10
+
11
+ <!-- wp:social-link {"service":"twitter"} /-->
12
+
13
+ <!-- wp:social-link {"service":"instagram"} /--></ul>
14
+ <!-- /wp:social-links --></div>
15
+ <!-- /wp:column --></div>
16
+ <!-- /wp:columns -->"
17
+ `;
18
+
19
+ exports[`Social Icons block transforms to Group block 1`] = `
20
+ "<!-- wp:group {"layout":{"type":"constrained"}} -->
21
+ <div class="wp-block-group"><!-- wp:social-links -->
22
+ <ul class="wp-block-social-links"><!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->
23
+
24
+ <!-- wp:social-link {"service":"facebook"} /-->
25
+
26
+ <!-- wp:social-link {"service":"twitter"} /-->
27
+
28
+ <!-- wp:social-link {"service":"instagram"} /--></ul>
29
+ <!-- /wp:social-links --></div>
30
+ <!-- /wp:group -->"
31
+ `;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ initializeEditor,
7
+ setupCoreBlocks,
8
+ transformBlock,
9
+ getBlockTransformOptions,
10
+ } from 'test/helpers';
11
+ import { Animated } from 'react-native';
12
+
13
+ const block = 'Social Icons';
14
+ const initialHtml = `
15
+ <!-- wp:social-links -->
16
+ <ul class="wp-block-social-links"><!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->
17
+ <!-- wp:social-link {"service":"facebook"} /-->
18
+ <!-- wp:social-link {"service":"twitter"} /-->
19
+ <!-- wp:social-link {"service":"instagram"} /--></ul>
20
+ <!-- /wp:social-links -->`;
21
+
22
+ const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
23
+ const blockTransforms = [ ...transformsWithInnerBlocks ];
24
+
25
+ setupCoreBlocks();
26
+
27
+ describe( `${ block } block transforms`, () => {
28
+ beforeAll( () => {
29
+ // Mock call to Animated.sequence for animating colors.
30
+ jest.spyOn( Animated, 'sequence' ).mockImplementation( () => ( {
31
+ start: ( cb ) => cb(),
32
+ } ) );
33
+ } );
34
+
35
+ test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
36
+ const screen = await initializeEditor( { initialHtml } );
37
+ const newBlock = await transformBlock( screen, block, blockTransform, {
38
+ hasInnerBlocks:
39
+ transformsWithInnerBlocks.includes( blockTransform ),
40
+ } );
41
+ expect( newBlock ).toBeVisible();
42
+ expect( getEditorHtml() ).toMatchSnapshot();
43
+ } );
44
+
45
+ it( 'matches expected transformation options', async () => {
46
+ const screen = await initializeEditor( { initialHtml } );
47
+ const transformOptions = await getBlockTransformOptions(
48
+ screen,
49
+ block
50
+ );
51
+ expect( transformOptions ).toHaveLength( blockTransforms.length );
52
+ } );
53
+ } );
@@ -0,0 +1,19 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Spacer block transforms to Columns block 1`] = `
4
+ "<!-- wp:columns -->
5
+ <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
6
+ <div class="wp-block-column" style="flex-basis:100%"><!-- wp:spacer -->
7
+ <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
8
+ <!-- /wp:spacer --></div>
9
+ <!-- /wp:column --></div>
10
+ <!-- /wp:columns -->"
11
+ `;
12
+
13
+ exports[`Spacer block transforms to Group block 1`] = `
14
+ "<!-- wp:group {"layout":{"type":"constrained"}} -->
15
+ <div class="wp-block-group"><!-- wp:spacer -->
16
+ <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
17
+ <!-- /wp:spacer --></div>
18
+ <!-- /wp:group -->"
19
+ `;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ getEditorHtml,
6
+ initializeEditor,
7
+ setupCoreBlocks,
8
+ transformBlock,
9
+ getBlockTransformOptions,
10
+ } from 'test/helpers';
11
+
12
+ const block = 'Spacer';
13
+ const initialHtml = `
14
+ <!-- wp:spacer -->
15
+ <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
16
+ <!-- /wp:spacer -->`;
17
+
18
+ const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
19
+ const blockTransforms = [ ...transformsWithInnerBlocks ];
20
+
21
+ setupCoreBlocks();
22
+
23
+ describe( `${ block } block transforms`, () => {
24
+ test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
25
+ const screen = await initializeEditor( { initialHtml } );
26
+ const newBlock = await transformBlock( screen, block, blockTransform, {
27
+ hasInnerBlocks:
28
+ transformsWithInnerBlocks.includes( blockTransform ),
29
+ } );
30
+ expect( newBlock ).toBeVisible();
31
+ expect( getEditorHtml() ).toMatchSnapshot();
32
+ } );
33
+
34
+ it( 'matches expected transformation options', async () => {
35
+ const screen = await initializeEditor( { initialHtml } );
36
+ const transformOptions = await getBlockTransformOptions(
37
+ screen,
38
+ block
39
+ );
40
+ expect( transformOptions ).toHaveLength( blockTransforms.length );
41
+ } );
42
+ } );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { get, mapValues } from 'lodash';
4
+ import { mapValues } from 'lodash';
5
5
 
6
6
  const INHERITED_COLUMN_ATTRIBUTES = [ 'align' ];
7
7
 
@@ -55,13 +55,9 @@ export function getFirstRow( state ) {
55
55
  */
56
56
  export function getCellAttribute( state, cellLocation, attributeName ) {
57
57
  const { sectionName, rowIndex, columnIndex } = cellLocation;
58
- return get( state, [
59
- sectionName,
60
- rowIndex,
61
- 'cells',
62
- columnIndex,
63
- attributeName,
64
- ] );
58
+ return state[ sectionName ]?.[ rowIndex ]?.cells?.[ columnIndex ]?.[
59
+ attributeName
60
+ ];
65
61
  }
66
62
 
67
63
  /**
@@ -158,9 +154,7 @@ export function isCellSelected( cellLocation, selection ) {
158
154
  export function insertRow( state, { sectionName, rowIndex, columnCount } ) {
159
155
  const firstRow = getFirstRow( state );
160
156
  const cellCount =
161
- columnCount === undefined
162
- ? get( firstRow, [ 'cells', 'length' ] )
163
- : columnCount;
157
+ columnCount === undefined ? firstRow?.cells?.length : columnCount;
164
158
 
165
159
  // Bail early if the function cannot determine how many cells to add.
166
160
  if ( ! cellCount ) {
@@ -173,11 +167,8 @@ export function insertRow( state, { sectionName, rowIndex, columnCount } ) {
173
167
  {
174
168
  cells: Array.from( { length: cellCount } ).map(
175
169
  ( _, index ) => {
176
- const firstCellInColumn = get(
177
- firstRow,
178
- [ 'cells', index ],
179
- {}
180
- );
170
+ const firstCellInColumn =
171
+ firstRow?.cells?.[ index ] ?? {};
181
172
 
182
173
  const inheritedAttributes = Object.fromEntries(
183
174
  Object.entries( firstCellInColumn ).filter(
@@ -310,7 +301,7 @@ export function toggleSection( state, sectionName ) {
310
301
  }
311
302
 
312
303
  // Get the length of the first row of the body to use when creating the header.
313
- const columnCount = get( state, [ 'body', 0, 'cells', 'length' ], 1 );
304
+ const columnCount = state.body?.[ 0 ]?.cells?.length ?? 1;
314
305
 
315
306
  // Section doesn't exist, insert an empty row to create the section.
316
307
  return insertRow( state, { sectionName, rowIndex: 0, columnCount } );
@@ -12,10 +12,6 @@ import {
12
12
  __experimentalHStack as HStack,
13
13
  __experimentalSpacer as Spacer,
14
14
  } from '@wordpress/components';
15
- import {
16
- switchToBlockType,
17
- getPossibleBlockTransformations,
18
- } from '@wordpress/blocks';
19
15
  import { store as coreStore } from '@wordpress/core-data';
20
16
  import { store as noticesStore } from '@wordpress/notices';
21
17
 
@@ -110,36 +106,13 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
110
106
  const blocks = widgets.flatMap( ( widget ) => {
111
107
  const block = transformWidgetToBlock( widget );
112
108
 
113
- if ( block.name !== 'core/legacy-widget' ) {
114
- return block;
115
- }
116
-
117
- const transforms = getPossibleBlockTransformations( [
118
- block,
119
- ] ).filter( ( item ) => {
120
- // The block without any transformations can't be a wildcard.
121
- if ( ! item.transforms ) {
122
- return true;
123
- }
124
-
125
- const hasWildCardFrom = item.transforms?.from?.find(
126
- ( from ) => from.blocks && from.blocks.includes( '*' )
127
- );
128
- const hasWildCardTo = item.transforms?.to?.find(
129
- ( to ) => to.blocks && to.blocks.includes( '*' )
130
- );
131
-
132
- return ! hasWildCardFrom && ! hasWildCardTo;
133
- } );
134
-
135
109
  // Skip the block if we have no matching transformations.
136
- if ( ! transforms.length ) {
110
+ if ( ! block ) {
137
111
  skippedWidgets.add( widget.id_base );
138
112
  return [];
139
113
  }
140
114
 
141
- // Try transforming the Legacy Widget into a first matching block.
142
- return switchToBlockType( block, transforms[ 0 ].name );
115
+ return block;
143
116
  } );
144
117
 
145
118
  await createFromBlocks(