@wordpress/block-editor 12.0.0 → 12.1.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 (311) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/build/components/block-controls/slot.js +12 -4
  4. package/build/components/block-controls/slot.js.map +1 -1
  5. package/build/components/block-controls/slot.native.js +10 -1
  6. package/build/components/block-controls/slot.native.js.map +1 -1
  7. package/build/components/block-draggable/index.js +11 -7
  8. package/build/components/block-draggable/index.js.map +1 -1
  9. package/build/components/block-draggable/use-scroll-when-dragging.js +2 -2
  10. package/build/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
  11. package/build/components/block-list/block-invalid-warning.native.js +15 -7
  12. package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
  13. package/build/components/block-list/block-list-item-cell.native.js +15 -2
  14. package/build/components/block-list/block-list-item-cell.native.js.map +1 -1
  15. package/build/components/block-list/block-list-item.native.js +158 -195
  16. package/build/components/block-list/block-list-item.native.js.map +1 -1
  17. package/build/components/block-list/block-outline.native.js +57 -0
  18. package/build/components/block-list/block-outline.native.js.map +1 -0
  19. package/build/components/block-list/block.native.js +343 -299
  20. package/build/components/block-list/block.native.js.map +1 -1
  21. package/build/components/block-list/index.native.js +202 -298
  22. package/build/components/block-list/index.native.js.map +1 -1
  23. package/build/components/block-list/insertion-point.native.js +4 -2
  24. package/build/components/block-list/insertion-point.native.js.map +1 -1
  25. package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
  26. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  27. package/build/components/block-settings-menu/block-settings-dropdown.js +8 -10
  28. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  29. package/build/components/block-settings-menu-controls/index.js +15 -4
  30. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  31. package/build/components/block-tools/block-contextual-toolbar.js +17 -62
  32. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  33. package/build/components/block-tools/selected-block-popover.js +3 -8
  34. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  35. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
  36. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  37. package/build/components/global-styles/advanced-panel.js +86 -0
  38. package/build/components/global-styles/advanced-panel.js.map +1 -0
  39. package/build/components/global-styles/color-panel.js +4 -1
  40. package/build/components/global-styles/color-panel.js.map +1 -1
  41. package/build/components/global-styles/dimensions-panel.js +6 -6
  42. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  43. package/build/components/global-styles/hooks.js +1 -2
  44. package/build/components/global-styles/hooks.js.map +1 -1
  45. package/build/components/global-styles/index.js +24 -0
  46. package/build/components/global-styles/index.js.map +1 -1
  47. package/build/components/global-styles/typography-panel.js +1 -1
  48. package/build/components/global-styles/typography-panel.js.map +1 -1
  49. package/build/components/global-styles/use-global-styles-output.js +27 -4
  50. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  51. package/build/components/global-styles/utils.js +30 -0
  52. package/build/components/global-styles/utils.js.map +1 -1
  53. package/build/components/image-editor/use-save-image.js +24 -8
  54. package/build/components/image-editor/use-save-image.js.map +1 -1
  55. package/build/components/inserter-draggable-blocks/index.js +5 -0
  56. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  57. package/build/components/inspector-controls/fill.js +1 -1
  58. package/build/components/inspector-controls/fill.js.map +1 -1
  59. package/build/components/inspector-controls/fill.native.js +1 -1
  60. package/build/components/inspector-controls/fill.native.js.map +1 -1
  61. package/build/components/inspector-controls/slot.js +3 -6
  62. package/build/components/inspector-controls/slot.js.map +1 -1
  63. package/build/components/inspector-controls/slot.native.js +1 -1
  64. package/build/components/inspector-controls/slot.native.js.map +1 -1
  65. package/build/components/line-height-control/index.js +7 -2
  66. package/build/components/line-height-control/index.js.map +1 -1
  67. package/build/components/link-control/use-internal-input-value.js +9 -8
  68. package/build/components/link-control/use-internal-input-value.js.map +1 -1
  69. package/build/components/list-view/block-contents.js +7 -2
  70. package/build/components/list-view/block-contents.js.map +1 -1
  71. package/build/components/list-view/block-select-button.js +2 -1
  72. package/build/components/list-view/block-select-button.js.map +1 -1
  73. package/build/components/list-view/block.js +4 -4
  74. package/build/components/list-view/block.js.map +1 -1
  75. package/build/components/list-view/index.js +32 -18
  76. package/build/components/list-view/index.js.map +1 -1
  77. package/build/components/list-view/use-list-view-drop-zone.js +163 -11
  78. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  79. package/build/components/media-placeholder/index.js +68 -7
  80. package/build/components/media-placeholder/index.js.map +1 -1
  81. package/build/components/multi-selection-inspector/index.js +2 -2
  82. package/build/components/multi-selection-inspector/index.js.map +1 -1
  83. package/build/components/off-canvas-editor/leaf-more-menu.js +3 -1
  84. package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
  85. package/build/components/preview-options/index.js +6 -1
  86. package/build/components/preview-options/index.js.map +1 -1
  87. package/build/components/spacing-sizes-control/spacing-input-control.js +1 -1
  88. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  89. package/build/components/url-input/index.js +1 -2
  90. package/build/components/url-input/index.js.map +1 -1
  91. package/build/hooks/align.js +1 -1
  92. package/build/hooks/align.js.map +1 -1
  93. package/build/hooks/border.js +1 -1
  94. package/build/hooks/border.js.map +1 -1
  95. package/build/hooks/color.js +1 -1
  96. package/build/hooks/color.js.map +1 -1
  97. package/build/hooks/content-lock-ui.js +8 -12
  98. package/build/hooks/content-lock-ui.js.map +1 -1
  99. package/build/hooks/duotone.js +1 -1
  100. package/build/hooks/duotone.js.map +1 -1
  101. package/build/hooks/index.native.js +8 -0
  102. package/build/hooks/index.native.js.map +1 -1
  103. package/build/hooks/layout.js +2 -2
  104. package/build/hooks/layout.js.map +1 -1
  105. package/build/hooks/position.js +1 -1
  106. package/build/hooks/position.js.map +1 -1
  107. package/build/hooks/style.js +1 -1
  108. package/build/hooks/style.js.map +1 -1
  109. package/build/hooks/use-editor-wrapper-styles.native.js +255 -0
  110. package/build/hooks/use-editor-wrapper-styles.native.js.map +1 -0
  111. package/build/hooks/use-typography-props.js +14 -10
  112. package/build/hooks/use-typography-props.js.map +1 -1
  113. package/build/index.native.js +31 -0
  114. package/build/index.native.js.map +1 -0
  115. package/build/utils/use-should-contextual-toolbar-show.js +16 -12
  116. package/build/utils/use-should-contextual-toolbar-show.js.map +1 -1
  117. package/build-module/components/block-controls/slot.js +11 -4
  118. package/build-module/components/block-controls/slot.js.map +1 -1
  119. package/build-module/components/block-controls/slot.native.js +9 -1
  120. package/build-module/components/block-controls/slot.native.js.map +1 -1
  121. package/build-module/components/block-draggable/index.js +10 -6
  122. package/build-module/components/block-draggable/index.js.map +1 -1
  123. package/build-module/components/block-draggable/use-scroll-when-dragging.js +2 -2
  124. package/build-module/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
  125. package/build-module/components/block-list/block-invalid-warning.native.js +16 -8
  126. package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
  127. package/build-module/components/block-list/block-list-item-cell.native.js +13 -2
  128. package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -1
  129. package/build-module/components/block-list/block-list-item.native.js +160 -190
  130. package/build-module/components/block-list/block-list-item.native.js.map +1 -1
  131. package/build-module/components/block-list/block-outline.native.js +44 -0
  132. package/build-module/components/block-list/block-outline.native.js.map +1 -0
  133. package/build-module/components/block-list/block.native.js +341 -298
  134. package/build-module/components/block-list/block.native.js.map +1 -1
  135. package/build-module/components/block-list/index.native.js +203 -293
  136. package/build-module/components/block-list/index.native.js.map +1 -1
  137. package/build-module/components/block-list/insertion-point.native.js +4 -2
  138. package/build-module/components/block-list/insertion-point.native.js.map +1 -1
  139. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
  140. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  141. package/build-module/components/block-settings-menu/block-settings-dropdown.js +8 -9
  142. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  143. package/build-module/components/block-settings-menu-controls/index.js +13 -5
  144. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  145. package/build-module/components/block-tools/block-contextual-toolbar.js +18 -62
  146. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  147. package/build-module/components/block-tools/selected-block-popover.js +3 -7
  148. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  149. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
  150. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  151. package/build-module/components/global-styles/advanced-panel.js +74 -0
  152. package/build-module/components/global-styles/advanced-panel.js.map +1 -0
  153. package/build-module/components/global-styles/color-panel.js +5 -2
  154. package/build-module/components/global-styles/color-panel.js.map +1 -1
  155. package/build-module/components/global-styles/dimensions-panel.js +6 -6
  156. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  157. package/build-module/components/global-styles/hooks.js +1 -2
  158. package/build-module/components/global-styles/hooks.js.map +1 -1
  159. package/build-module/components/global-styles/index.js +3 -1
  160. package/build-module/components/global-styles/index.js.map +1 -1
  161. package/build-module/components/global-styles/typography-panel.js +1 -1
  162. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  163. package/build-module/components/global-styles/use-global-styles-output.js +25 -4
  164. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  165. package/build-module/components/global-styles/utils.js +25 -0
  166. package/build-module/components/global-styles/utils.js.map +1 -1
  167. package/build-module/components/image-editor/use-save-image.js +24 -8
  168. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  169. package/build-module/components/inserter-draggable-blocks/index.js +4 -0
  170. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  171. package/build-module/components/inspector-controls/fill.js +1 -1
  172. package/build-module/components/inspector-controls/fill.js.map +1 -1
  173. package/build-module/components/inspector-controls/fill.native.js +1 -1
  174. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  175. package/build-module/components/inspector-controls/slot.js +4 -7
  176. package/build-module/components/inspector-controls/slot.js.map +1 -1
  177. package/build-module/components/inspector-controls/slot.native.js +1 -1
  178. package/build-module/components/inspector-controls/slot.native.js.map +1 -1
  179. package/build-module/components/line-height-control/index.js +7 -2
  180. package/build-module/components/line-height-control/index.js.map +1 -1
  181. package/build-module/components/link-control/use-internal-input-value.js +9 -8
  182. package/build-module/components/link-control/use-internal-input-value.js.map +1 -1
  183. package/build-module/components/list-view/block-contents.js +7 -3
  184. package/build-module/components/list-view/block-contents.js.map +1 -1
  185. package/build-module/components/list-view/block-select-button.js +2 -1
  186. package/build-module/components/list-view/block-select-button.js.map +1 -1
  187. package/build-module/components/list-view/block.js +4 -4
  188. package/build-module/components/list-view/block.js.map +1 -1
  189. package/build-module/components/list-view/index.js +32 -18
  190. package/build-module/components/list-view/index.js.map +1 -1
  191. package/build-module/components/list-view/use-list-view-drop-zone.js +160 -11
  192. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  193. package/build-module/components/media-placeholder/index.js +66 -7
  194. package/build-module/components/media-placeholder/index.js.map +1 -1
  195. package/build-module/components/multi-selection-inspector/index.js +2 -2
  196. package/build-module/components/multi-selection-inspector/index.js.map +1 -1
  197. package/build-module/components/off-canvas-editor/leaf-more-menu.js +3 -1
  198. package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
  199. package/build-module/components/preview-options/index.js +7 -2
  200. package/build-module/components/preview-options/index.js.map +1 -1
  201. package/build-module/components/spacing-sizes-control/spacing-input-control.js +1 -1
  202. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  203. package/build-module/components/url-input/index.js +1 -2
  204. package/build-module/components/url-input/index.js.map +1 -1
  205. package/build-module/hooks/align.js +1 -1
  206. package/build-module/hooks/align.js.map +1 -1
  207. package/build-module/hooks/border.js +1 -1
  208. package/build-module/hooks/border.js.map +1 -1
  209. package/build-module/hooks/color.js +1 -1
  210. package/build-module/hooks/color.js.map +1 -1
  211. package/build-module/hooks/content-lock-ui.js +8 -11
  212. package/build-module/hooks/content-lock-ui.js.map +1 -1
  213. package/build-module/hooks/duotone.js +1 -1
  214. package/build-module/hooks/duotone.js.map +1 -1
  215. package/build-module/hooks/index.native.js +1 -0
  216. package/build-module/hooks/index.native.js.map +1 -1
  217. package/build-module/hooks/layout.js +2 -2
  218. package/build-module/hooks/layout.js.map +1 -1
  219. package/build-module/hooks/position.js +1 -1
  220. package/build-module/hooks/position.js.map +1 -1
  221. package/build-module/hooks/style.js +1 -1
  222. package/build-module/hooks/style.js.map +1 -1
  223. package/build-module/hooks/use-editor-wrapper-styles.native.js +242 -0
  224. package/build-module/hooks/use-editor-wrapper-styles.native.js.map +1 -0
  225. package/build-module/hooks/use-typography-props.js +14 -10
  226. package/build-module/hooks/use-typography-props.js.map +1 -1
  227. package/build-module/index.native.js +6 -0
  228. package/build-module/index.native.js.map +1 -0
  229. package/build-module/utils/use-should-contextual-toolbar-show.js +16 -12
  230. package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -1
  231. package/build-style/content-rtl.css +0 -1
  232. package/build-style/content.css +0 -1
  233. package/build-style/style-rtl.css +37 -13
  234. package/build-style/style.css +37 -13
  235. package/package.json +31 -31
  236. package/src/components/block-breadcrumb/style.scss +2 -1
  237. package/src/components/block-controls/slot.js +8 -4
  238. package/src/components/block-controls/slot.native.js +6 -1
  239. package/src/components/block-draggable/index.js +10 -6
  240. package/src/components/block-draggable/use-scroll-when-dragging.js +8 -2
  241. package/src/components/block-list/block-invalid-warning.native.js +17 -9
  242. package/src/components/block-list/block-list-item-cell.native.js +10 -1
  243. package/src/components/block-list/block-list-item.native.js +180 -208
  244. package/src/components/block-list/block-outline.native.js +58 -0
  245. package/src/components/block-list/block.native.js +564 -523
  246. package/src/components/block-list/content.scss +0 -1
  247. package/src/components/block-list/index.native.js +229 -298
  248. package/src/components/block-list/insertion-point.native.js +2 -2
  249. package/src/components/block-list/test/block-invalid-warning.native.js +48 -0
  250. package/src/components/block-list/test/index.native.js +205 -0
  251. package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -1
  252. package/src/components/block-pattern-setup/style.scss +1 -4
  253. package/src/components/block-patterns-list/style.scss +1 -4
  254. package/src/components/block-settings-menu/block-settings-dropdown.js +10 -17
  255. package/src/components/block-settings-menu-controls/index.js +24 -4
  256. package/src/components/block-styles/style.scss +4 -4
  257. package/src/components/block-tools/block-contextual-toolbar.js +28 -62
  258. package/src/components/block-tools/selected-block-popover.js +3 -5
  259. package/src/components/block-tools/style.scss +8 -0
  260. package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +16 -2
  261. package/src/components/global-styles/advanced-panel.js +82 -0
  262. package/src/components/global-styles/color-panel.js +6 -1
  263. package/src/components/global-styles/dimensions-panel.js +6 -6
  264. package/src/components/global-styles/hooks.js +1 -5
  265. package/src/components/global-styles/index.js +6 -1
  266. package/src/components/global-styles/style.scss +14 -0
  267. package/src/components/global-styles/test/utils.js +57 -1
  268. package/src/components/global-styles/typography-panel.js +1 -1
  269. package/src/components/global-styles/use-global-styles-output.js +21 -3
  270. package/src/components/global-styles/utils.js +27 -0
  271. package/src/components/image-editor/use-save-image.js +20 -9
  272. package/src/components/inserter-draggable-blocks/index.js +4 -0
  273. package/src/components/inspector-controls/fill.js +1 -1
  274. package/src/components/inspector-controls/fill.native.js +1 -1
  275. package/src/components/inspector-controls/slot.js +4 -9
  276. package/src/components/inspector-controls/slot.native.js +1 -1
  277. package/src/components/line-height-control/index.js +7 -2
  278. package/src/components/line-height-control/stories/index.js +1 -1
  279. package/src/components/link-control/test/index.js +42 -0
  280. package/src/components/link-control/use-internal-input-value.js +8 -7
  281. package/src/components/list-view/block-contents.js +26 -20
  282. package/src/components/list-view/block-select-button.js +5 -1
  283. package/src/components/list-view/block.js +5 -2
  284. package/src/components/list-view/index.js +26 -14
  285. package/src/components/list-view/style.scss +5 -2
  286. package/src/components/list-view/test/use-list-view-drop-zone.js +88 -12
  287. package/src/components/list-view/use-list-view-drop-zone.js +194 -11
  288. package/src/components/media-placeholder/index.js +74 -1
  289. package/src/components/multi-selection-inspector/index.js +2 -2
  290. package/src/components/off-canvas-editor/leaf-more-menu.js +2 -1
  291. package/src/components/preview-options/index.js +9 -2
  292. package/src/components/spacing-sizes-control/spacing-input-control.js +1 -0
  293. package/src/components/url-input/index.js +1 -2
  294. package/src/hooks/align.js +2 -1
  295. package/src/hooks/border.js +2 -1
  296. package/src/hooks/color.js +2 -1
  297. package/src/hooks/content-lock-ui.js +3 -15
  298. package/src/hooks/duotone.js +1 -0
  299. package/src/hooks/index.native.js +1 -0
  300. package/src/hooks/layout.js +4 -2
  301. package/src/hooks/position.js +2 -1
  302. package/src/hooks/style.js +2 -1
  303. package/src/hooks/test/use-editor-wrapper-styles.native.js +282 -0
  304. package/src/hooks/test/use-typography-props.js +47 -2
  305. package/src/hooks/use-editor-wrapper-styles.native.js +250 -0
  306. package/src/hooks/use-editor-wrapper-styles.native.scss +11 -0
  307. package/src/hooks/use-typography-props.js +10 -11
  308. package/src/index.native.js +6 -0
  309. package/src/utils/use-should-contextual-toolbar-show.js +19 -9
  310. package/tsconfig.json +1 -0
  311. package/tsconfig.tsbuildinfo +1 -1
@@ -39,7 +39,6 @@
39
39
  // so explicit radii set by tools are preserved.
40
40
  &:where(.block-editor-block-list__block.is-multi-selected:not(.is-partially-selected)) {
41
41
  border-radius: $radius-block-ui;
42
- overflow: hidden;
43
42
  }
44
43
 
45
44
  .block-editor-block-list__block.is-multi-selected:not(.is-partially-selected) {
@@ -6,9 +6,8 @@ import { View, Platform, TouchableWithoutFeedback } from 'react-native';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { Component } from '@wordpress/element';
10
- import { withDispatch, withSelect } from '@wordpress/data';
11
- import { compose, withPreferredColorScheme } from '@wordpress/compose';
9
+ import { useRef, useState } from '@wordpress/element';
10
+ import { useSelect, useDispatch } from '@wordpress/data';
12
11
  import { createBlock } from '@wordpress/blocks';
13
12
  import {
14
13
  KeyboardAwareFlatList,
@@ -57,83 +56,117 @@ const getStyles = (
57
56
  return computedStyles;
58
57
  };
59
58
 
60
- export class BlockList extends Component {
61
- constructor() {
62
- super( ...arguments );
63
- this.extraData = {
64
- parentWidth: this.props.parentWidth,
65
- renderFooterAppender: this.props.renderFooterAppender,
66
- renderAppender: this.props.renderAppender,
67
- onDeleteBlock: this.props.onDeleteBlock,
68
- contentStyle: this.props.contentStyle,
69
- };
70
- this.renderItem = this.renderItem.bind( this );
71
- this.renderBlockListFooter = this.renderBlockListFooter.bind( this );
72
- this.scrollViewInnerRef = this.scrollViewInnerRef.bind( this );
73
- this.addBlockToEndOfPost = this.addBlockToEndOfPost.bind( this );
74
- this.shouldFlatListPreventAutomaticScroll =
75
- this.shouldFlatListPreventAutomaticScroll.bind( this );
76
- this.shouldShowInnerBlockAppender =
77
- this.shouldShowInnerBlockAppender.bind( this );
78
- this.renderEmptyList = this.renderEmptyList.bind( this );
79
- this.getExtraData = this.getExtraData.bind( this );
80
- this.getCellRendererComponent =
81
- this.getCellRendererComponent.bind( this );
82
-
83
- this.onLayout = this.onLayout.bind( this );
84
-
85
- this.state = {
86
- blockWidth: this.props.blockWidth || 0,
87
- };
88
- }
59
+ export default function BlockList( {
60
+ blockWidth: initialBlockWidth,
61
+ contentResizeMode,
62
+ contentStyle,
63
+ filterInnerBlocks,
64
+ gridProperties,
65
+ header,
66
+ horizontal,
67
+ horizontalAlignment,
68
+ marginHorizontal = styles.defaultBlock.marginLeft,
69
+ marginVertical = styles.defaultBlock.marginTop,
70
+ onAddBlock,
71
+ onDeleteBlock,
72
+ orientation,
73
+ parentWidth,
74
+ renderAppender,
75
+ renderFooterAppender,
76
+ rootClientId,
77
+ title,
78
+ withFooter = true,
79
+ } ) {
80
+ const {
81
+ blockClientIds,
82
+ blockCount,
83
+ blockInsertionPointIsVisible,
84
+ isReadOnly,
85
+ isRootList,
86
+ isFloatingToolbarVisible,
87
+ isStackedHorizontally,
88
+ maxWidth,
89
+ isRTL,
90
+ } = useSelect(
91
+ ( select ) => {
92
+ const {
93
+ getBlockCount,
94
+ getBlockHierarchyRootClientId,
95
+ getBlockOrder,
96
+ getSelectedBlockClientId,
97
+ isBlockInsertionPointVisible,
98
+ getSettings,
99
+ } = select( blockEditorStore );
89
100
 
90
- addBlockToEndOfPost( newBlock ) {
91
- this.props.insertBlock( newBlock, this.props.blockCount );
92
- }
101
+ const selectedBlockClientId = getSelectedBlockClientId();
102
+ const rootBlockId = getBlockHierarchyRootClientId(
103
+ selectedBlockClientId
104
+ );
93
105
 
94
- scrollViewInnerRef( ref ) {
95
- this.scrollViewRef = ref;
96
- }
106
+ let blockOrder = getBlockOrder( rootClientId );
107
+ // Display only block which fulfill the condition in passed `filterInnerBlocks` function.
108
+ if ( filterInnerBlocks ) {
109
+ blockOrder = filterInnerBlocks( blockOrder );
110
+ }
97
111
 
98
- shouldFlatListPreventAutomaticScroll() {
99
- return this.props.isBlockInsertionPointVisible;
100
- }
112
+ const {
113
+ isRTL: isRTLSetting,
114
+ maxWidth: maxWidthSetting,
115
+ readOnly,
116
+ } = getSettings();
101
117
 
102
- shouldShowInnerBlockAppender() {
103
- const { blockClientIds, renderAppender } = this.props;
104
- return renderAppender && blockClientIds.length > 0;
105
- }
118
+ return {
119
+ blockClientIds: blockOrder,
120
+ blockCount: getBlockCount(),
121
+ blockInsertionPointIsVisible:
122
+ Platform.OS === 'ios' && isBlockInsertionPointVisible(),
123
+ isReadOnly: readOnly,
124
+ isRootList: rootClientId === undefined,
125
+ isFloatingToolbarVisible:
126
+ !! selectedBlockClientId && !! getBlockCount( rootBlockId ),
127
+ isStackedHorizontally: orientation === 'horizontal',
128
+ maxWidth: maxWidthSetting,
129
+ isRTL: isRTLSetting,
130
+ };
131
+ },
132
+ [ filterInnerBlocks, orientation, rootClientId ]
133
+ );
106
134
 
107
- renderEmptyList() {
108
- return (
109
- <EmptyListComponentCompose
110
- rootClientId={ this.props.rootClientId }
111
- renderAppender={ this.props.renderAppender }
112
- renderFooterAppender={ this.props.renderFooterAppender }
113
- />
114
- );
115
- }
135
+ const { insertBlock, clearSelectedBlock } = useDispatch( blockEditorStore );
116
136
 
117
- getExtraData() {
118
- const {
119
- parentWidth,
120
- renderFooterAppender,
121
- onDeleteBlock,
122
- contentStyle,
123
- renderAppender,
124
- gridProperties,
125
- } = this.props;
126
- const { blockWidth } = this.state;
137
+ const extraData = useRef( {
138
+ parentWidth,
139
+ renderFooterAppender,
140
+ renderAppender,
141
+ onDeleteBlock,
142
+ contentStyle,
143
+ } );
144
+
145
+ const [ blockWidth, setBlockWidth ] = useState( initialBlockWidth || 0 );
146
+
147
+ const addBlockToEndOfPost = ( newBlock ) => {
148
+ insertBlock( newBlock, blockCount );
149
+ };
150
+
151
+ const scrollViewRef = useRef( null );
152
+
153
+ const shouldFlatListPreventAutomaticScroll = () =>
154
+ blockInsertionPointIsVisible;
155
+
156
+ const shouldShowInnerBlockAppender = () =>
157
+ renderAppender && blockClientIds.length > 0;
158
+
159
+ const getExtraData = () => {
127
160
  if (
128
- this.extraData.parentWidth !== parentWidth ||
129
- this.extraData.renderFooterAppender !== renderFooterAppender ||
130
- this.extraData.onDeleteBlock !== onDeleteBlock ||
131
- this.extraData.contentStyle !== contentStyle ||
132
- this.extraData.renderAppender !== renderAppender ||
133
- this.extraData.blockWidth !== blockWidth ||
134
- this.extraData.gridProperties !== gridProperties
161
+ extraData.current.parentWidth !== parentWidth ||
162
+ extraData.current.renderFooterAppender !== renderFooterAppender ||
163
+ extraData.current.onDeleteBlock !== onDeleteBlock ||
164
+ extraData.current.contentStyle !== contentStyle ||
165
+ extraData.current.renderAppender !== renderAppender ||
166
+ extraData.current.blockWidth !== blockWidth ||
167
+ extraData.current.gridProperties !== gridProperties
135
168
  ) {
136
- this.extraData = {
169
+ extraData.current = {
137
170
  parentWidth,
138
171
  renderFooterAppender,
139
172
  onDeleteBlock,
@@ -143,80 +176,21 @@ export class BlockList extends Component {
143
176
  gridProperties,
144
177
  };
145
178
  }
146
- return this.extraData;
147
- }
179
+ return extraData.current;
180
+ };
148
181
 
149
- getCellRendererComponent( { children, item, onLayout } ) {
150
- const { rootClientId } = this.props;
151
- return (
152
- <BlockListItemCell
153
- children={ children }
154
- clientId={ item }
155
- onLayout={ onLayout }
156
- rootClientId={ rootClientId }
157
- />
158
- );
159
- }
160
-
161
- onLayout( { nativeEvent } ) {
182
+ const onLayout = ( { nativeEvent } ) => {
162
183
  const { layout } = nativeEvent;
163
- const { blockWidth } = this.state;
164
- const { isRootList, maxWidth } = this.props;
165
184
 
166
185
  const layoutWidth = Math.floor( layout.width );
167
186
  if ( isRootList && blockWidth !== layoutWidth ) {
168
- this.setState( {
169
- blockWidth: Math.min( layoutWidth, maxWidth ),
170
- } );
187
+ setBlockWidth( Math.min( layoutWidth, maxWidth ) );
171
188
  } else if ( ! isRootList && ! blockWidth ) {
172
- this.setState( { blockWidth: Math.min( layoutWidth, maxWidth ) } );
189
+ setBlockWidth( Math.min( layoutWidth, maxWidth ) );
173
190
  }
174
- }
175
-
176
- render() {
177
- const { isRootList, isRTL } = this.props;
178
- // Use of Context to propagate the main scroll ref to its children e.g InnerBlocks.
179
- const blockList = isRootList ? (
180
- <BlockListProvider
181
- value={ {
182
- ...DEFAULT_BLOCK_LIST_CONTEXT,
183
- scrollRef: this.scrollViewRef,
184
- } }
185
- >
186
- <BlockDraggableWrapper isRTL={ isRTL }>
187
- { ( { onScroll } ) => this.renderList( { onScroll } ) }
188
- </BlockDraggableWrapper>
189
- </BlockListProvider>
190
- ) : (
191
- <BlockListConsumer>
192
- { ( { scrollRef } ) =>
193
- this.renderList( {
194
- parentScrollRef: scrollRef,
195
- } )
196
- }
197
- </BlockListConsumer>
198
- );
199
-
200
- return blockList;
201
- }
191
+ };
202
192
 
203
- renderList( extraProps = {} ) {
204
- const {
205
- clearSelectedBlock,
206
- blockClientIds,
207
- title,
208
- header,
209
- isReadOnly,
210
- isRootList,
211
- horizontal,
212
- marginVertical = styles.defaultBlock.marginTop,
213
- marginHorizontal = styles.defaultBlock.marginLeft,
214
- isFloatingToolbarVisible,
215
- isStackedHorizontally,
216
- horizontalAlignment,
217
- contentResizeMode,
218
- blockWidth,
219
- } = this.props;
193
+ const renderList = ( extraProps = {} ) => {
220
194
  const { parentScrollRef, onScroll } = extraProps;
221
195
 
222
196
  const { blockToolbar, headerToolbar, floatingToolbar } = styles;
@@ -245,7 +219,7 @@ export class BlockList extends Component {
245
219
  <View
246
220
  style={ containerStyle }
247
221
  onAccessibilityEscape={ clearSelectedBlock }
248
- onLayout={ this.onLayout }
222
+ onLayout={ onLayout }
249
223
  testID="block-list-wrapper"
250
224
  >
251
225
  <KeyboardAwareFlatList
@@ -254,12 +228,12 @@ export class BlockList extends Component {
254
228
  : {} ) } // Disable clipping on Android to fix focus losing. See https://github.com/wordpress-mobile/gutenberg-mobile/pull/741#issuecomment-472746541
255
229
  accessibilityLabel="block-list"
256
230
  innerRef={ ( ref ) => {
257
- this.scrollViewInnerRef( parentScrollRef || ref );
231
+ scrollViewRef.current = parentScrollRef || ref;
258
232
  } }
259
233
  extraScrollHeight={ extraScrollHeight }
260
234
  keyboardShouldPersistTaps="always"
261
235
  scrollViewStyle={ scrollViewStyle }
262
- extraData={ this.getExtraData() }
236
+ extraData={ getExtraData() }
263
237
  scrollEnabled={ isRootList }
264
238
  contentContainerStyle={ [
265
239
  horizontal && styles.horizontalContentContainer,
@@ -275,18 +249,37 @@ export class BlockList extends Component {
275
249
  ) }
276
250
  data={ blockClientIds }
277
251
  keyExtractor={ identity }
278
- renderItem={ this.renderItem }
279
- CellRendererComponent={ this.getCellRendererComponent }
252
+ listKey={
253
+ rootClientId ? `list-${ rootClientId }` : 'list-root'
254
+ }
255
+ renderItem={ renderItem }
256
+ CellRendererComponent={ BlockListItemCell }
280
257
  shouldPreventAutomaticScroll={
281
- this.shouldFlatListPreventAutomaticScroll
258
+ shouldFlatListPreventAutomaticScroll
282
259
  }
283
260
  title={ title }
284
261
  ListHeaderComponent={ header }
285
- ListEmptyComponent={ ! isReadOnly && this.renderEmptyList }
286
- ListFooterComponent={ this.renderBlockListFooter }
262
+ ListEmptyComponent={
263
+ ! isReadOnly && (
264
+ <EmptyList
265
+ orientation={ orientation }
266
+ rootClientId={ rootClientId }
267
+ renderAppender={ renderAppender }
268
+ renderFooterAppender={ renderFooterAppender }
269
+ />
270
+ )
271
+ }
272
+ ListFooterComponent={
273
+ <Footer
274
+ addBlockToEndOfPost={ addBlockToEndOfPost }
275
+ isReadOnly={ isReadOnly }
276
+ renderFooterAppender={ renderFooterAppender }
277
+ withFooter={ withFooter }
278
+ />
279
+ }
287
280
  onScroll={ onScroll }
288
281
  />
289
- { this.shouldShowInnerBlockAppender() && (
282
+ { shouldShowInnerBlockAppender() && (
290
283
  <View
291
284
  style={ {
292
285
  marginHorizontal:
@@ -295,32 +288,17 @@ export class BlockList extends Component {
295
288
  } }
296
289
  >
297
290
  <BlockListAppender
298
- rootClientId={ this.props.rootClientId }
299
- renderAppender={ this.props.renderAppender }
291
+ rootClientId={ rootClientId }
292
+ renderAppender={ renderAppender }
300
293
  showSeparator
301
294
  />
302
295
  </View>
303
296
  ) }
304
297
  </View>
305
298
  );
306
- }
307
-
308
- renderItem( { item: clientId } ) {
309
- const {
310
- contentResizeMode,
311
- contentStyle,
312
- onAddBlock,
313
- onDeleteBlock,
314
- rootClientId,
315
- isStackedHorizontally,
316
- blockClientIds,
317
- parentWidth,
318
- marginVertical = styles.defaultBlock.marginTop,
319
- marginHorizontal = styles.defaultBlock.marginLeft,
320
- gridProperties,
321
- } = this.props;
322
- const { blockWidth } = this.state;
299
+ };
323
300
 
301
+ const renderItem = ( { item: clientId, index } ) => {
324
302
  // Extracting the grid item properties here to avoid
325
303
  // re-renders in the blockListItem component.
326
304
  const isGridItem = !! gridProperties;
@@ -331,6 +309,7 @@ export class BlockList extends Component {
331
309
  };
332
310
  return (
333
311
  <BlockListItem
312
+ index={ index }
334
313
  isStackedHorizontally={ isStackedHorizontally }
335
314
  rootClientId={ rootClientId }
336
315
  clientId={ clientId }
@@ -341,141 +320,74 @@ export class BlockList extends Component {
341
320
  marginVertical={ marginVertical }
342
321
  marginHorizontal={ marginHorizontal }
343
322
  onDeleteBlock={ onDeleteBlock }
344
- shouldShowInnerBlockAppender={
345
- this.shouldShowInnerBlockAppender
346
- }
323
+ shouldShowInnerBlockAppender={ shouldShowInnerBlockAppender }
347
324
  blockWidth={ blockWidth }
348
325
  isGridItem={ isGridItem }
349
326
  { ...gridItemProps }
350
327
  />
351
328
  );
352
- }
353
-
354
- renderBlockListFooter() {
355
- const paragraphBlock = createBlock( 'core/paragraph' );
356
- const {
357
- isReadOnly,
358
- withFooter = true,
359
- renderFooterAppender,
360
- } = this.props;
361
-
362
- if ( ! isReadOnly && withFooter ) {
363
- return (
364
- <>
365
- <TouchableWithoutFeedback
366
- accessibilityLabel={ __( 'Add paragraph block' ) }
367
- testID={ __( 'Add paragraph block' ) }
368
- onPress={ () => {
369
- this.addBlockToEndOfPost( paragraphBlock );
370
- } }
371
- >
372
- <View style={ styles.blockListFooter } />
373
- </TouchableWithoutFeedback>
374
- </>
375
- );
376
- } else if ( renderFooterAppender ) {
377
- return renderFooterAppender();
378
- }
379
- return null;
380
- }
381
- }
382
-
383
- export default compose( [
384
- withSelect(
385
- ( select, { rootClientId, orientation, filterInnerBlocks } ) => {
386
- const {
387
- getBlockCount,
388
- getBlockHierarchyRootClientId,
389
- getBlockOrder,
390
- getSelectedBlockClientId,
391
- isBlockInsertionPointVisible,
392
- getSettings,
393
- } = select( blockEditorStore );
394
-
395
- const isStackedHorizontally = orientation === 'horizontal';
396
-
397
- const selectedBlockClientId = getSelectedBlockClientId();
398
-
399
- let blockClientIds = getBlockOrder( rootClientId );
400
- // Display only block which fulfill the condition in passed `filterInnerBlocks` function.
401
- if ( filterInnerBlocks ) {
402
- blockClientIds = filterInnerBlocks( blockClientIds );
329
+ };
330
+
331
+ // Use of Context to propagate the main scroll ref to its children e.g InnerBlocks.
332
+ const blockList = isRootList ? (
333
+ <BlockListProvider
334
+ value={ {
335
+ ...DEFAULT_BLOCK_LIST_CONTEXT,
336
+ scrollRef: scrollViewRef.current,
337
+ } }
338
+ >
339
+ <BlockDraggableWrapper isRTL={ isRTL }>
340
+ { ( { onScroll } ) => renderList( { onScroll } ) }
341
+ </BlockDraggableWrapper>
342
+ </BlockListProvider>
343
+ ) : (
344
+ <BlockListConsumer>
345
+ { ( { scrollRef } ) =>
346
+ renderList( {
347
+ parentScrollRef: scrollRef,
348
+ } )
403
349
  }
350
+ </BlockListConsumer>
351
+ );
404
352
 
405
- const { maxWidth } = getSettings();
406
- const isReadOnly = getSettings().readOnly;
407
-
408
- const blockCount = getBlockCount();
409
- const rootBlockId = getBlockHierarchyRootClientId(
410
- selectedBlockClientId
411
- );
412
-
413
- const isFloatingToolbarVisible =
414
- !! selectedBlockClientId && !! getBlockCount( rootBlockId );
415
- const isRTL = getSettings().isRTL;
416
-
417
- return {
418
- blockClientIds,
419
- blockCount,
420
- isBlockInsertionPointVisible:
421
- Platform.OS === 'ios' && isBlockInsertionPointVisible(),
422
- isReadOnly,
423
- isRootList: rootClientId === undefined,
424
- isFloatingToolbarVisible,
425
- isStackedHorizontally,
426
- maxWidth,
427
- isRTL,
428
- };
429
- }
430
- ),
431
- withDispatch( ( dispatch ) => {
432
- const { insertBlock, replaceBlock, clearSelectedBlock } =
433
- dispatch( blockEditorStore );
434
-
435
- return {
436
- clearSelectedBlock,
437
- insertBlock,
438
- replaceBlock,
439
- };
440
- } ),
441
- withPreferredColorScheme,
442
- ] )( BlockList );
443
-
444
- class EmptyListComponent extends Component {
445
- render() {
446
- const {
447
- shouldShowInsertionPoint,
448
- rootClientId,
449
- renderAppender,
450
- renderFooterAppender,
451
- } = this.props;
452
-
453
- if ( renderFooterAppender || renderAppender === false ) {
454
- return null;
455
- }
353
+ return blockList;
354
+ }
456
355
 
356
+ function Footer( {
357
+ addBlockToEndOfPost,
358
+ isReadOnly,
359
+ renderFooterAppender,
360
+ withFooter,
361
+ } ) {
362
+ if ( ! isReadOnly && withFooter ) {
457
363
  return (
458
- <View style={ styles.defaultAppender }>
459
- <ReadableContentView
460
- align={
461
- renderAppender
462
- ? WIDE_ALIGNMENTS.alignments.full
463
- : undefined
464
- }
364
+ <>
365
+ <TouchableWithoutFeedback
366
+ accessibilityLabel={ __( 'Add paragraph block' ) }
367
+ testID={ __( 'Add paragraph block' ) }
368
+ onPress={ () => {
369
+ const paragraphBlock = createBlock( 'core/paragraph' );
370
+ addBlockToEndOfPost( paragraphBlock );
371
+ } }
465
372
  >
466
- <BlockListAppender
467
- rootClientId={ rootClientId }
468
- renderAppender={ renderAppender }
469
- showSeparator={ shouldShowInsertionPoint }
470
- />
471
- </ReadableContentView>
472
- </View>
373
+ <View style={ styles.blockListFooter } />
374
+ </TouchableWithoutFeedback>
375
+ </>
473
376
  );
377
+ } else if ( renderFooterAppender ) {
378
+ return renderFooterAppender();
474
379
  }
380
+
381
+ return null;
475
382
  }
476
383
 
477
- const EmptyListComponentCompose = compose( [
478
- withSelect( ( select, { rootClientId, orientation } ) => {
384
+ function EmptyList( {
385
+ orientation,
386
+ renderAppender,
387
+ renderFooterAppender,
388
+ rootClientId,
389
+ } ) {
390
+ const { shouldShowInsertionPoint } = useSelect( ( select ) => {
479
391
  const {
480
392
  getBlockOrder,
481
393
  getBlockInsertionPoint,
@@ -486,17 +398,36 @@ const EmptyListComponentCompose = compose( [
486
398
  const blockClientIds = getBlockOrder( rootClientId );
487
399
  const insertionPoint = getBlockInsertionPoint();
488
400
  const blockInsertionPointIsVisible = isBlockInsertionPointVisible();
489
- const shouldShowInsertionPoint =
490
- ! isStackedHorizontally &&
491
- blockInsertionPointIsVisible &&
492
- insertionPoint.rootClientId === rootClientId &&
493
- // If list is empty, show the insertion point (via the default appender)
494
- ( blockClientIds.length === 0 ||
495
- // Or if the insertion point is right before the denoted block.
496
- ! blockClientIds[ insertionPoint.index ] );
497
401
 
498
402
  return {
499
- shouldShowInsertionPoint,
403
+ shouldShowInsertionPoint:
404
+ ! isStackedHorizontally &&
405
+ blockInsertionPointIsVisible &&
406
+ insertionPoint.rootClientId === rootClientId &&
407
+ // If list is empty, show the insertion point (via the default appender)
408
+ ( blockClientIds.length === 0 ||
409
+ // Or if the insertion point is right before the denoted block.
410
+ ! blockClientIds[ insertionPoint.index ] ),
500
411
  };
501
- } ),
502
- ] )( EmptyListComponent );
412
+ } );
413
+
414
+ if ( renderFooterAppender || renderAppender === false ) {
415
+ return null;
416
+ }
417
+
418
+ return (
419
+ <View style={ styles.defaultAppender }>
420
+ <ReadableContentView
421
+ align={
422
+ renderAppender ? WIDE_ALIGNMENTS.alignments.full : undefined
423
+ }
424
+ >
425
+ <BlockListAppender
426
+ rootClientId={ rootClientId }
427
+ renderAppender={ renderAppender }
428
+ showSeparator={ shouldShowInsertionPoint }
429
+ />
430
+ </ReadableContentView>
431
+ </View>
432
+ );
433
+ }
@@ -14,7 +14,7 @@ import { withPreferredColorScheme } from '@wordpress/compose';
14
14
  */
15
15
  import styles from './style.scss';
16
16
 
17
- const BlockInsertionPoint = ( { getStylesFromColorScheme } ) => {
17
+ const BlockInsertionPoint = ( { getStylesFromColorScheme, testID } ) => {
18
18
  const lineStyle = getStylesFromColorScheme(
19
19
  styles.lineStyleAddHere,
20
20
  styles.lineStyleAddHereDark
@@ -25,7 +25,7 @@ const BlockInsertionPoint = ( { getStylesFromColorScheme } ) => {
25
25
  );
26
26
 
27
27
  return (
28
- <View style={ styles.containerStyleAddHere }>
28
+ <View style={ styles.containerStyleAddHere } testID={ testID }>
29
29
  <View style={ lineStyle }></View>
30
30
  <Text style={ labelStyle }>{ __( 'ADD BLOCK HERE' ) }</Text>
31
31
  <View style={ lineStyle }></View>