@wordpress/block-editor 11.8.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 (454) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +16 -4
  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-info-slot-fill/index.js +47 -0
  12. package/build/components/block-info-slot-fill/index.js.map +1 -0
  13. package/build/components/block-inspector/index.js +4 -2
  14. package/build/components/block-inspector/index.js.map +1 -1
  15. package/build/components/block-list/block-invalid-warning.native.js +15 -7
  16. package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
  17. package/build/components/block-list/block-list-item-cell.native.js +15 -2
  18. package/build/components/block-list/block-list-item-cell.native.js.map +1 -1
  19. package/build/components/block-list/block-list-item.native.js +158 -195
  20. package/build/components/block-list/block-list-item.native.js.map +1 -1
  21. package/build/components/block-list/block-outline.native.js +57 -0
  22. package/build/components/block-list/block-outline.native.js.map +1 -0
  23. package/build/components/block-list/block.native.js +343 -300
  24. package/build/components/block-list/block.native.js.map +1 -1
  25. package/build/components/block-list/index.native.js +202 -298
  26. package/build/components/block-list/index.native.js.map +1 -1
  27. package/build/components/block-list/insertion-point.native.js +4 -2
  28. package/build/components/block-list/insertion-point.native.js.map +1 -1
  29. package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
  30. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  31. package/build/components/block-settings-menu/block-settings-dropdown.js +8 -10
  32. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  33. package/build/components/block-settings-menu-controls/index.js +15 -4
  34. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  35. package/build/components/block-toolbar/index.js +2 -1
  36. package/build/components/block-toolbar/index.js.map +1 -1
  37. package/build/components/block-tools/block-contextual-toolbar.js +40 -11
  38. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  39. package/build/components/block-tools/selected-block-popover.js +8 -30
  40. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  41. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
  42. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  43. package/build/components/editor-styles/index.js +4 -3
  44. package/build/components/editor-styles/index.js.map +1 -1
  45. package/build/components/font-sizes/fluid-utils.js +21 -14
  46. package/build/components/font-sizes/fluid-utils.js.map +1 -1
  47. package/build/components/global-styles/advanced-panel.js +86 -0
  48. package/build/components/global-styles/advanced-panel.js.map +1 -0
  49. package/build/components/global-styles/border-panel.js +2 -32
  50. package/build/components/global-styles/border-panel.js.map +1 -1
  51. package/build/components/global-styles/color-panel.js +16 -13
  52. package/build/components/global-styles/color-panel.js.map +1 -1
  53. package/build/components/global-styles/color-panel.native.js +174 -0
  54. package/build/components/global-styles/color-panel.native.js.map +1 -0
  55. package/build/components/global-styles/dimensions-panel.js +12 -12
  56. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  57. package/build/components/global-styles/effects-panel.js +1 -1
  58. package/build/components/global-styles/effects-panel.js.map +1 -1
  59. package/build/components/global-styles/filters-panel.js +78 -14
  60. package/build/components/global-styles/filters-panel.js.map +1 -1
  61. package/build/components/global-styles/hooks.js +1 -2
  62. package/build/components/global-styles/hooks.js.map +1 -1
  63. package/build/components/global-styles/index.js +24 -0
  64. package/build/components/global-styles/index.js.map +1 -1
  65. package/build/components/global-styles/typography-panel.js +10 -10
  66. package/build/components/global-styles/typography-panel.js.map +1 -1
  67. package/build/components/global-styles/use-global-styles-output.js +114 -81
  68. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  69. package/build/components/global-styles/utils.js +30 -0
  70. package/build/components/global-styles/utils.js.map +1 -1
  71. package/build/components/image-editor/use-save-image.js +24 -8
  72. package/build/components/image-editor/use-save-image.js.map +1 -1
  73. package/build/components/index.js +7 -0
  74. package/build/components/index.js.map +1 -1
  75. package/build/components/inserter/block-types-tab.js +12 -7
  76. package/build/components/inserter/block-types-tab.js.map +1 -1
  77. package/build/components/inserter/index.js +2 -1
  78. package/build/components/inserter/index.js.map +1 -1
  79. package/build/components/inserter-draggable-blocks/index.js +5 -0
  80. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  81. package/build/components/inspector-controls/fill.js +1 -1
  82. package/build/components/inspector-controls/fill.js.map +1 -1
  83. package/build/components/inspector-controls/fill.native.js +1 -1
  84. package/build/components/inspector-controls/fill.native.js.map +1 -1
  85. package/build/components/inspector-controls/groups.js +2 -0
  86. package/build/components/inspector-controls/groups.js.map +1 -1
  87. package/build/components/inspector-controls/slot.js +3 -6
  88. package/build/components/inspector-controls/slot.js.map +1 -1
  89. package/build/components/inspector-controls/slot.native.js +1 -1
  90. package/build/components/inspector-controls/slot.native.js.map +1 -1
  91. package/build/components/inspector-controls-tabs/styles-tab.js +2 -0
  92. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  93. package/build/components/line-height-control/index.js +7 -2
  94. package/build/components/line-height-control/index.js.map +1 -1
  95. package/build/components/link-control/use-internal-input-value.js +9 -8
  96. package/build/components/link-control/use-internal-input-value.js.map +1 -1
  97. package/build/components/list-view/block-contents.js +7 -2
  98. package/build/components/list-view/block-contents.js.map +1 -1
  99. package/build/components/list-view/block-select-button.js +9 -3
  100. package/build/components/list-view/block-select-button.js.map +1 -1
  101. package/build/components/list-view/block.js +16 -25
  102. package/build/components/list-view/block.js.map +1 -1
  103. package/build/components/list-view/drop-indicator.js +37 -10
  104. package/build/components/list-view/drop-indicator.js.map +1 -1
  105. package/build/components/list-view/index.js +38 -18
  106. package/build/components/list-view/index.js.map +1 -1
  107. package/build/components/list-view/leaf.js +2 -1
  108. package/build/components/list-view/leaf.js.map +1 -1
  109. package/build/components/list-view/use-block-selection.js +1 -1
  110. package/build/components/list-view/use-block-selection.js.map +1 -1
  111. package/build/components/list-view/use-list-view-drop-zone.js +163 -11
  112. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  113. package/build/components/media-placeholder/index.js +68 -7
  114. package/build/components/media-placeholder/index.js.map +1 -1
  115. package/build/components/media-replace-flow/index.js +5 -5
  116. package/build/components/media-replace-flow/index.js.map +1 -1
  117. package/build/components/multi-selection-inspector/index.js +2 -2
  118. package/build/components/multi-selection-inspector/index.js.map +1 -1
  119. package/build/components/navigable-toolbar/index.js +12 -4
  120. package/build/components/navigable-toolbar/index.js.map +1 -1
  121. package/build/components/off-canvas-editor/appender.js +2 -7
  122. package/build/components/off-canvas-editor/appender.js.map +1 -1
  123. package/build/components/off-canvas-editor/leaf-more-menu.js +3 -1
  124. package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
  125. package/build/components/preview-options/index.js +6 -1
  126. package/build/components/preview-options/index.js.map +1 -1
  127. package/build/components/spacing-sizes-control/spacing-input-control.js +1 -1
  128. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  129. package/build/components/url-input/index.js +1 -2
  130. package/build/components/url-input/index.js.map +1 -1
  131. package/build/hooks/align.js +1 -1
  132. package/build/hooks/align.js.map +1 -1
  133. package/build/hooks/border.js +1 -1
  134. package/build/hooks/border.js.map +1 -1
  135. package/build/hooks/color.js +1 -1
  136. package/build/hooks/color.js.map +1 -1
  137. package/build/hooks/content-lock-ui.js +8 -12
  138. package/build/hooks/content-lock-ui.js.map +1 -1
  139. package/build/hooks/duotone.js +29 -4
  140. package/build/hooks/duotone.js.map +1 -1
  141. package/build/hooks/index.native.js +8 -0
  142. package/build/hooks/index.native.js.map +1 -1
  143. package/build/hooks/layout.js +2 -2
  144. package/build/hooks/layout.js.map +1 -1
  145. package/build/hooks/position.js +1 -1
  146. package/build/hooks/position.js.map +1 -1
  147. package/build/hooks/style.js +1 -1
  148. package/build/hooks/style.js.map +1 -1
  149. package/build/hooks/use-editor-wrapper-styles.native.js +255 -0
  150. package/build/hooks/use-editor-wrapper-styles.native.js.map +1 -0
  151. package/build/hooks/use-typography-props.js +14 -10
  152. package/build/hooks/use-typography-props.js.map +1 -1
  153. package/build/hooks/utils.js +15 -3
  154. package/build/hooks/utils.js.map +1 -1
  155. package/build/index.native.js +31 -0
  156. package/build/index.native.js.map +1 -0
  157. package/build/private-apis.js +10 -1
  158. package/build/private-apis.js.map +1 -1
  159. package/build/store/actions.js +7 -0
  160. package/build/store/actions.js.map +1 -1
  161. package/build/utils/object.js +5 -5
  162. package/build/utils/object.js.map +1 -1
  163. package/build/utils/transform-styles/index.js +2 -2
  164. package/build/utils/transform-styles/index.js.map +1 -1
  165. package/build/utils/use-should-contextual-toolbar-show.js +72 -0
  166. package/build/utils/use-should-contextual-toolbar-show.js.map +1 -0
  167. package/build-module/components/block-controls/slot.js +11 -4
  168. package/build-module/components/block-controls/slot.js.map +1 -1
  169. package/build-module/components/block-controls/slot.native.js +9 -1
  170. package/build-module/components/block-controls/slot.native.js.map +1 -1
  171. package/build-module/components/block-draggable/index.js +10 -6
  172. package/build-module/components/block-draggable/index.js.map +1 -1
  173. package/build-module/components/block-draggable/use-scroll-when-dragging.js +2 -2
  174. package/build-module/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
  175. package/build-module/components/block-info-slot-fill/index.js +34 -0
  176. package/build-module/components/block-info-slot-fill/index.js.map +1 -0
  177. package/build-module/components/block-inspector/index.js +3 -2
  178. package/build-module/components/block-inspector/index.js.map +1 -1
  179. package/build-module/components/block-list/block-invalid-warning.native.js +16 -8
  180. package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
  181. package/build-module/components/block-list/block-list-item-cell.native.js +13 -2
  182. package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -1
  183. package/build-module/components/block-list/block-list-item.native.js +160 -190
  184. package/build-module/components/block-list/block-list-item.native.js.map +1 -1
  185. package/build-module/components/block-list/block-outline.native.js +44 -0
  186. package/build-module/components/block-list/block-outline.native.js.map +1 -0
  187. package/build-module/components/block-list/block.native.js +341 -299
  188. package/build-module/components/block-list/block.native.js.map +1 -1
  189. package/build-module/components/block-list/index.native.js +203 -293
  190. package/build-module/components/block-list/index.native.js.map +1 -1
  191. package/build-module/components/block-list/insertion-point.native.js +4 -2
  192. package/build-module/components/block-list/insertion-point.native.js.map +1 -1
  193. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
  194. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  195. package/build-module/components/block-settings-menu/block-settings-dropdown.js +8 -9
  196. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  197. package/build-module/components/block-settings-menu-controls/index.js +13 -5
  198. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  199. package/build-module/components/block-toolbar/index.js +2 -1
  200. package/build-module/components/block-toolbar/index.js.map +1 -1
  201. package/build-module/components/block-tools/block-contextual-toolbar.js +37 -11
  202. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  203. package/build-module/components/block-tools/selected-block-popover.js +8 -29
  204. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  205. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
  206. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  207. package/build-module/components/editor-styles/index.js +4 -3
  208. package/build-module/components/editor-styles/index.js.map +1 -1
  209. package/build-module/components/font-sizes/fluid-utils.js +21 -14
  210. package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
  211. package/build-module/components/global-styles/advanced-panel.js +74 -0
  212. package/build-module/components/global-styles/advanced-panel.js.map +1 -0
  213. package/build-module/components/global-styles/border-panel.js +2 -32
  214. package/build-module/components/global-styles/border-panel.js.map +1 -1
  215. package/build-module/components/global-styles/color-panel.js +18 -15
  216. package/build-module/components/global-styles/color-panel.js.map +1 -1
  217. package/build-module/components/global-styles/color-panel.native.js +150 -0
  218. package/build-module/components/global-styles/color-panel.native.js.map +1 -0
  219. package/build-module/components/global-styles/dimensions-panel.js +13 -13
  220. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  221. package/build-module/components/global-styles/effects-panel.js +2 -2
  222. package/build-module/components/global-styles/effects-panel.js.map +1 -1
  223. package/build-module/components/global-styles/filters-panel.js +78 -16
  224. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  225. package/build-module/components/global-styles/hooks.js +1 -2
  226. package/build-module/components/global-styles/hooks.js.map +1 -1
  227. package/build-module/components/global-styles/index.js +3 -1
  228. package/build-module/components/global-styles/index.js.map +1 -1
  229. package/build-module/components/global-styles/typography-panel.js +11 -11
  230. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  231. package/build-module/components/global-styles/use-global-styles-output.js +112 -81
  232. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  233. package/build-module/components/global-styles/utils.js +25 -0
  234. package/build-module/components/global-styles/utils.js.map +1 -1
  235. package/build-module/components/image-editor/use-save-image.js +24 -8
  236. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  237. package/build-module/components/index.js +1 -1
  238. package/build-module/components/index.js.map +1 -1
  239. package/build-module/components/inserter/block-types-tab.js +12 -6
  240. package/build-module/components/inserter/block-types-tab.js.map +1 -1
  241. package/build-module/components/inserter/index.js +2 -1
  242. package/build-module/components/inserter/index.js.map +1 -1
  243. package/build-module/components/inserter-draggable-blocks/index.js +4 -0
  244. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  245. package/build-module/components/inspector-controls/fill.js +1 -1
  246. package/build-module/components/inspector-controls/fill.js.map +1 -1
  247. package/build-module/components/inspector-controls/fill.native.js +1 -1
  248. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  249. package/build-module/components/inspector-controls/groups.js +2 -0
  250. package/build-module/components/inspector-controls/groups.js.map +1 -1
  251. package/build-module/components/inspector-controls/slot.js +4 -7
  252. package/build-module/components/inspector-controls/slot.js.map +1 -1
  253. package/build-module/components/inspector-controls/slot.native.js +1 -1
  254. package/build-module/components/inspector-controls/slot.native.js.map +1 -1
  255. package/build-module/components/inspector-controls-tabs/styles-tab.js +2 -0
  256. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  257. package/build-module/components/line-height-control/index.js +7 -2
  258. package/build-module/components/line-height-control/index.js.map +1 -1
  259. package/build-module/components/link-control/use-internal-input-value.js +9 -8
  260. package/build-module/components/link-control/use-internal-input-value.js.map +1 -1
  261. package/build-module/components/list-view/block-contents.js +7 -3
  262. package/build-module/components/list-view/block-contents.js.map +1 -1
  263. package/build-module/components/list-view/block-select-button.js +9 -3
  264. package/build-module/components/list-view/block-select-button.js.map +1 -1
  265. package/build-module/components/list-view/block.js +18 -26
  266. package/build-module/components/list-view/block.js.map +1 -1
  267. package/build-module/components/list-view/drop-indicator.js +36 -10
  268. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  269. package/build-module/components/list-view/index.js +39 -19
  270. package/build-module/components/list-view/index.js.map +1 -1
  271. package/build-module/components/list-view/leaf.js +2 -1
  272. package/build-module/components/list-view/leaf.js.map +1 -1
  273. package/build-module/components/list-view/use-block-selection.js +1 -1
  274. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  275. package/build-module/components/list-view/use-list-view-drop-zone.js +160 -11
  276. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  277. package/build-module/components/media-placeholder/index.js +66 -7
  278. package/build-module/components/media-placeholder/index.js.map +1 -1
  279. package/build-module/components/media-replace-flow/index.js +5 -5
  280. package/build-module/components/media-replace-flow/index.js.map +1 -1
  281. package/build-module/components/multi-selection-inspector/index.js +2 -2
  282. package/build-module/components/multi-selection-inspector/index.js.map +1 -1
  283. package/build-module/components/navigable-toolbar/index.js +12 -4
  284. package/build-module/components/navigable-toolbar/index.js.map +1 -1
  285. package/build-module/components/off-canvas-editor/appender.js +1 -5
  286. package/build-module/components/off-canvas-editor/appender.js.map +1 -1
  287. package/build-module/components/off-canvas-editor/leaf-more-menu.js +3 -1
  288. package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
  289. package/build-module/components/preview-options/index.js +7 -2
  290. package/build-module/components/preview-options/index.js.map +1 -1
  291. package/build-module/components/spacing-sizes-control/spacing-input-control.js +1 -1
  292. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  293. package/build-module/components/url-input/index.js +1 -2
  294. package/build-module/components/url-input/index.js.map +1 -1
  295. package/build-module/hooks/align.js +1 -1
  296. package/build-module/hooks/align.js.map +1 -1
  297. package/build-module/hooks/border.js +1 -1
  298. package/build-module/hooks/border.js.map +1 -1
  299. package/build-module/hooks/color.js +1 -1
  300. package/build-module/hooks/color.js.map +1 -1
  301. package/build-module/hooks/content-lock-ui.js +8 -11
  302. package/build-module/hooks/content-lock-ui.js.map +1 -1
  303. package/build-module/hooks/duotone.js +28 -5
  304. package/build-module/hooks/duotone.js.map +1 -1
  305. package/build-module/hooks/index.native.js +1 -0
  306. package/build-module/hooks/index.native.js.map +1 -1
  307. package/build-module/hooks/layout.js +2 -2
  308. package/build-module/hooks/layout.js.map +1 -1
  309. package/build-module/hooks/position.js +1 -1
  310. package/build-module/hooks/position.js.map +1 -1
  311. package/build-module/hooks/style.js +1 -1
  312. package/build-module/hooks/style.js.map +1 -1
  313. package/build-module/hooks/use-editor-wrapper-styles.native.js +242 -0
  314. package/build-module/hooks/use-editor-wrapper-styles.native.js.map +1 -0
  315. package/build-module/hooks/use-typography-props.js +14 -10
  316. package/build-module/hooks/use-typography-props.js.map +1 -1
  317. package/build-module/hooks/utils.js +16 -4
  318. package/build-module/hooks/utils.js.map +1 -1
  319. package/build-module/index.native.js +6 -0
  320. package/build-module/index.native.js.map +1 -0
  321. package/build-module/private-apis.js +7 -1
  322. package/build-module/private-apis.js.map +1 -1
  323. package/build-module/store/actions.js +7 -0
  324. package/build-module/store/actions.js.map +1 -1
  325. package/build-module/utils/object.js +4 -4
  326. package/build-module/utils/object.js.map +1 -1
  327. package/build-module/utils/transform-styles/index.js +2 -2
  328. package/build-module/utils/transform-styles/index.js.map +1 -1
  329. package/build-module/utils/use-should-contextual-toolbar-show.js +60 -0
  330. package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -0
  331. package/build-style/content-rtl.css +9 -7
  332. package/build-style/content.css +9 -7
  333. package/build-style/style-rtl.css +257 -56
  334. package/build-style/style.css +257 -56
  335. package/package.json +32 -32
  336. package/src/components/block-breadcrumb/style.scss +2 -1
  337. package/src/components/block-controls/slot.js +8 -4
  338. package/src/components/block-controls/slot.native.js +6 -1
  339. package/src/components/block-draggable/index.js +10 -6
  340. package/src/components/block-draggable/use-scroll-when-dragging.js +8 -2
  341. package/src/components/block-info-slot-fill/index.js +24 -0
  342. package/src/components/block-inspector/index.js +3 -0
  343. package/src/components/block-list/block-invalid-warning.native.js +17 -9
  344. package/src/components/block-list/block-list-item-cell.native.js +10 -1
  345. package/src/components/block-list/block-list-item.native.js +180 -208
  346. package/src/components/block-list/block-outline.native.js +58 -0
  347. package/src/components/block-list/block.native.js +564 -524
  348. package/src/components/block-list/content.scss +16 -16
  349. package/src/components/block-list/index.native.js +229 -298
  350. package/src/components/block-list/insertion-point.native.js +2 -2
  351. package/src/components/block-list/test/block-invalid-warning.native.js +48 -0
  352. package/src/components/block-list/test/index.native.js +205 -0
  353. package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -1
  354. package/src/components/block-mobile-toolbar/test/block-actions-menu.native.js +9 -9
  355. package/src/components/block-mover/style.scss +10 -4
  356. package/src/components/block-mover/test/index.native.js +4 -4
  357. package/src/components/block-pattern-setup/style.scss +1 -4
  358. package/src/components/block-patterns-list/style.scss +1 -4
  359. package/src/components/block-settings-menu/block-settings-dropdown.js +10 -17
  360. package/src/components/block-settings-menu-controls/index.js +24 -4
  361. package/src/components/block-styles/style.scss +4 -4
  362. package/src/components/block-toolbar/index.js +4 -3
  363. package/src/components/block-toolbar/style.scss +56 -33
  364. package/src/components/block-tools/block-contextual-toolbar.js +64 -15
  365. package/src/components/block-tools/selected-block-popover.js +11 -46
  366. package/src/components/block-tools/style.scss +165 -3
  367. package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +16 -2
  368. package/src/components/editor-styles/index.js +9 -5
  369. package/src/components/font-sizes/fluid-utils.js +31 -14
  370. package/src/components/font-sizes/test/fluid-utils.js +5 -16
  371. package/src/components/global-styles/advanced-panel.js +82 -0
  372. package/src/components/global-styles/border-panel.js +1 -30
  373. package/src/components/global-styles/color-panel.js +19 -14
  374. package/src/components/global-styles/color-panel.native.js +207 -0
  375. package/src/components/global-styles/dimensions-panel.js +23 -13
  376. package/src/components/global-styles/effects-panel.js +2 -2
  377. package/src/components/global-styles/filters-panel.js +90 -17
  378. package/src/components/global-styles/hooks.js +1 -5
  379. package/src/components/global-styles/index.js +6 -1
  380. package/src/components/global-styles/style.scss +16 -1
  381. package/src/components/global-styles/test/typography-utils.js +63 -22
  382. package/src/components/global-styles/test/use-global-styles-output.js +126 -4
  383. package/src/components/global-styles/test/utils.js +57 -1
  384. package/src/components/global-styles/typography-panel.js +38 -12
  385. package/src/components/global-styles/use-global-styles-output.js +85 -67
  386. package/src/components/global-styles/utils.js +27 -0
  387. package/src/components/image-editor/use-save-image.js +20 -9
  388. package/src/components/index.js +1 -0
  389. package/src/components/inserter/block-types-tab.js +9 -6
  390. package/src/components/inserter/index.js +1 -1
  391. package/src/components/inserter-draggable-blocks/index.js +4 -0
  392. package/src/components/inspector-controls/fill.js +1 -1
  393. package/src/components/inspector-controls/fill.native.js +1 -1
  394. package/src/components/inspector-controls/groups.js +2 -0
  395. package/src/components/inspector-controls/slot.js +4 -9
  396. package/src/components/inspector-controls/slot.native.js +1 -1
  397. package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
  398. package/src/components/line-height-control/index.js +7 -2
  399. package/src/components/line-height-control/stories/index.js +1 -1
  400. package/src/components/link-control/test/index.js +42 -0
  401. package/src/components/link-control/use-internal-input-value.js +8 -7
  402. package/src/components/list-view/block-contents.js +26 -20
  403. package/src/components/list-view/block-select-button.js +11 -2
  404. package/src/components/list-view/block.js +28 -33
  405. package/src/components/list-view/drop-indicator.js +67 -22
  406. package/src/components/list-view/index.js +33 -14
  407. package/src/components/list-view/leaf.js +1 -0
  408. package/src/components/list-view/style.scss +18 -3
  409. package/src/components/list-view/test/use-list-view-drop-zone.js +88 -12
  410. package/src/components/list-view/use-block-selection.js +1 -1
  411. package/src/components/list-view/use-list-view-drop-zone.js +194 -11
  412. package/src/components/media-placeholder/index.js +74 -1
  413. package/src/components/media-replace-flow/README.md +3 -2
  414. package/src/components/media-replace-flow/index.js +4 -5
  415. package/src/components/multi-selection-inspector/index.js +2 -2
  416. package/src/components/navigable-toolbar/index.js +12 -3
  417. package/src/components/off-canvas-editor/appender.js +1 -4
  418. package/src/components/off-canvas-editor/leaf-more-menu.js +2 -1
  419. package/src/components/preview-options/index.js +9 -2
  420. package/src/components/spacing-sizes-control/spacing-input-control.js +1 -0
  421. package/src/components/url-input/index.js +1 -2
  422. package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -3
  423. package/src/hooks/align.js +2 -1
  424. package/src/hooks/border.js +2 -1
  425. package/src/hooks/color.js +2 -1
  426. package/src/hooks/content-lock-ui.js +3 -15
  427. package/src/hooks/duotone.js +47 -25
  428. package/src/hooks/index.native.js +1 -0
  429. package/src/hooks/layout.js +4 -2
  430. package/src/hooks/position.js +2 -1
  431. package/src/hooks/style.js +2 -1
  432. package/src/hooks/test/anchor.js +113 -0
  433. package/src/hooks/test/color.js +0 -9
  434. package/src/hooks/test/use-editor-wrapper-styles.native.js +282 -0
  435. package/src/hooks/test/use-typography-props.js +49 -4
  436. package/src/hooks/test/utils.js +20 -101
  437. package/src/hooks/use-editor-wrapper-styles.native.js +250 -0
  438. package/src/hooks/use-editor-wrapper-styles.native.scss +11 -0
  439. package/src/hooks/use-typography-props.js +10 -11
  440. package/src/hooks/utils.js +20 -3
  441. package/src/index.native.js +6 -0
  442. package/src/private-apis.js +6 -0
  443. package/src/store/actions.js +7 -0
  444. package/src/utils/object.js +4 -4
  445. package/src/utils/test/object.js +21 -21
  446. package/src/utils/transform-styles/index.js +2 -2
  447. package/src/utils/use-should-contextual-toolbar-show.js +85 -0
  448. package/tsconfig.json +2 -0
  449. package/tsconfig.tsbuildinfo +1 -1
  450. package/build/hooks/color-panel.native.js +0 -77
  451. package/build/hooks/color-panel.native.js.map +0 -1
  452. package/build-module/hooks/color-panel.native.js +0 -62
  453. package/build-module/hooks/color-panel.native.js.map +0 -1
  454. package/src/hooks/color-panel.native.js +0 -63
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { View, Text, TouchableWithoutFeedback, Dimensions } from 'react-native';
4
+ import { Pressable, useWindowDimensions, View } from 'react-native';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { Component, createRef, useMemo } from '@wordpress/element';
9
+ import { useCallback, useMemo, useRef, useState } from '@wordpress/element';
10
10
  import {
11
11
  GlobalStylesContext,
12
12
  getMergedGlobalStyles,
@@ -14,51 +14,265 @@ import {
14
14
  alignmentHelpers,
15
15
  useGlobalStyles,
16
16
  } from '@wordpress/components';
17
- import { withDispatch, withSelect } from '@wordpress/data';
18
- import { compose, withPreferredColorScheme } from '@wordpress/compose';
19
17
  import {
20
- getBlockType,
21
18
  __experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,
22
- switchToBlockType,
19
+ getBlockType,
23
20
  getDefaultBlockName,
24
21
  isUnmodifiedBlock,
22
+ isUnmodifiedDefaultBlock,
23
+ switchToBlockType,
25
24
  } from '@wordpress/blocks';
26
- import { useSetting } from '@wordpress/block-editor';
25
+ import {
26
+ useDispatch,
27
+ useSelect,
28
+ withDispatch,
29
+ withSelect,
30
+ } from '@wordpress/data';
31
+ import { compose, ifCondition, pure } from '@wordpress/compose';
27
32
 
28
33
  /**
29
34
  * Internal dependencies
30
35
  */
31
- import styles from './block.scss';
32
36
  import BlockEdit from '../block-edit';
37
+ import BlockDraggable from '../block-draggable';
33
38
  import BlockInvalidWarning from './block-invalid-warning';
34
39
  import BlockMobileToolbar from '../block-mobile-toolbar';
40
+ import BlockOutline from './block-outline';
41
+ import styles from './block.scss';
35
42
  import { store as blockEditorStore } from '../../store';
36
- import BlockDraggable from '../block-draggable';
37
43
  import { useLayout } from './layout';
44
+ import useSetting from '../use-setting';
38
45
 
39
46
  const emptyArray = [];
40
- function BlockForType( {
47
+
48
+ // Helper function to memoize the wrapperProps since getEditWrapperProps always returns a new reference.
49
+ const wrapperPropsCache = new WeakMap();
50
+ const emptyObj = {};
51
+ function getWrapperProps( value, getWrapperPropsFunction ) {
52
+ if ( ! getWrapperPropsFunction ) {
53
+ return emptyObj;
54
+ }
55
+ const cachedValue = wrapperPropsCache.get( value );
56
+ if ( ! cachedValue ) {
57
+ const wrapperProps = getWrapperPropsFunction( value );
58
+ wrapperPropsCache.set( value, wrapperProps );
59
+ return wrapperProps;
60
+ }
61
+ return cachedValue;
62
+ }
63
+
64
+ function BlockWrapper( {
65
+ accessibilityLabel,
66
+ align,
67
+ blockWidth,
68
+ children,
69
+ clientId,
70
+ draggingClientId,
71
+ draggingEnabled,
72
+ isDescendentBlockSelected,
73
+ isParentSelected,
74
+ isSelected,
75
+ isStackedHorizontally,
76
+ isTouchable,
77
+ marginHorizontal,
78
+ marginVertical,
79
+ onDeleteBlock,
80
+ onFocus,
81
+ } ) {
82
+ const { width: screenWidth } = useWindowDimensions();
83
+ const anchorNodeRef = useRef();
84
+ const { isFullWidth } = alignmentHelpers;
85
+ const isScreenWidthEqual = blockWidth === screenWidth;
86
+ const isFullWidthToolbar = isFullWidth( align ) || isScreenWidthEqual;
87
+ const blockWrapperStyles = { flex: 1 };
88
+ const blockWrapperStyle = [
89
+ blockWrapperStyles,
90
+ {
91
+ marginVertical,
92
+ marginHorizontal,
93
+ },
94
+ ];
95
+ const accessible = ! ( isSelected || isDescendentBlockSelected );
96
+
97
+ return (
98
+ <Pressable
99
+ accessibilityLabel={ accessibilityLabel }
100
+ accessibilityRole="button"
101
+ accessible={ accessible }
102
+ disabled={ ! isTouchable }
103
+ onPress={ onFocus }
104
+ style={ blockWrapperStyle }
105
+ >
106
+ <BlockOutline
107
+ isSelected={ isSelected }
108
+ isParentSelected={ isParentSelected }
109
+ screenWidth={ screenWidth }
110
+ />
111
+ <BlockDraggable
112
+ clientId={ clientId }
113
+ draggingClientId={ draggingClientId }
114
+ enabled={ draggingEnabled }
115
+ testID="draggable-trigger-content"
116
+ >
117
+ { children }
118
+ </BlockDraggable>
119
+ <View style={ styles.neutralToolbar } ref={ anchorNodeRef }>
120
+ { isSelected && (
121
+ <BlockMobileToolbar
122
+ anchorNodeRef={ anchorNodeRef.current }
123
+ blockWidth={ blockWidth }
124
+ clientId={ clientId }
125
+ draggingClientId={ draggingClientId }
126
+ isFullWidth={ isFullWidthToolbar }
127
+ isStackedHorizontally={ isStackedHorizontally }
128
+ onDelete={ onDeleteBlock }
129
+ />
130
+ ) }
131
+ </View>
132
+ </Pressable>
133
+ );
134
+ }
135
+
136
+ function BlockListBlock( {
41
137
  attributes,
138
+ blockWidth: blockWrapperWidth,
139
+ canRemove,
42
140
  clientId,
43
141
  contentStyle,
44
- getBlockWidth,
45
- insertBlocksAfter,
142
+ isLocked,
46
143
  isSelected,
47
- onMerge,
144
+ isSelectionEnabled,
145
+ isStackedHorizontally,
146
+ isValid,
147
+ marginHorizontal,
148
+ marginVertical,
48
149
  name,
49
- onBlockFocus,
50
- onChange,
51
150
  onDeleteBlock,
151
+ onInsertBlocksAfter,
152
+ onMerge,
52
153
  onReplace,
53
- parentWidth,
54
154
  parentBlockAlignment,
55
- wrapperProps,
56
- blockWidth,
57
- baseGlobalStyles,
155
+ parentWidth,
156
+ rootClientId,
157
+ setAttributes,
158
+ toggleSelection,
58
159
  } ) {
160
+ const {
161
+ baseGlobalStyles,
162
+ blockType,
163
+ draggingClientId,
164
+ draggingEnabled,
165
+ firstToSelectId,
166
+ isDescendantOfParentSelected,
167
+ isDescendentBlockSelected,
168
+ isParentSelected,
169
+ order,
170
+ } = useSelect(
171
+ ( select ) => {
172
+ const {
173
+ getBlockCount,
174
+ getBlockHierarchyRootClientId,
175
+ getBlockIndex,
176
+ getBlockParents,
177
+ getLowestCommonAncestorWithSelectedBlock,
178
+ getSelectedBlockClientId,
179
+ getSettings,
180
+ hasSelectedInnerBlock,
181
+ } = select( blockEditorStore );
182
+ const currentBlockType = getBlockType( name || 'core/missing' );
183
+ const blockOrder = getBlockIndex( clientId );
184
+ const descendentBlockSelected = hasSelectedInnerBlock(
185
+ clientId,
186
+ true
187
+ );
188
+ const selectedBlockClientId = getSelectedBlockClientId();
189
+
190
+ const parents = getBlockParents( clientId, true );
191
+ const parentSelected =
192
+ // Set false as a default value to prevent re-render when it's changed from null to false.
193
+ ( selectedBlockClientId || false ) &&
194
+ selectedBlockClientId === rootClientId;
195
+
196
+ const selectedParents = clientId ? parents : [];
197
+ const descendantOfParentSelected =
198
+ selectedParents.includes( rootClientId );
199
+ const hasInnerBlocks = getBlockCount( clientId ) > 0;
200
+
201
+ const commonAncestor =
202
+ getLowestCommonAncestorWithSelectedBlock( clientId );
203
+ const commonAncestorIndex = parents.indexOf( commonAncestor ) - 1;
204
+ const firstBlockToSelectId = commonAncestor
205
+ ? parents[ commonAncestorIndex ]
206
+ : parents[ parents.length - 1 ];
207
+
208
+ // For blocks with inner blocks, we only enable the dragging in the nested
209
+ // blocks if any of them are selected. This way we prevent the long-press
210
+ // gesture from being disabled for elements within the block UI.
211
+ const isDraggingEnabled =
212
+ ! hasInnerBlocks || isSelected || ! descendentBlockSelected;
213
+ // Dragging nested blocks is not supported yet. For this reason, the block to be dragged
214
+ // will be the top in the hierarchy.
215
+ const currentDraggingClientId =
216
+ getBlockHierarchyRootClientId( clientId );
217
+
218
+ const globalStylesBaseStyles =
219
+ getSettings()?.__experimentalGlobalStylesBaseStyles;
220
+
221
+ return {
222
+ baseGlobalStyles: globalStylesBaseStyles,
223
+ blockType: currentBlockType,
224
+ draggingClientId: currentDraggingClientId,
225
+ draggingEnabled: isDraggingEnabled,
226
+ firstToSelectId: firstBlockToSelectId,
227
+ isDescendantOfParentSelected: descendantOfParentSelected,
228
+ isDescendentBlockSelected: descendentBlockSelected,
229
+ isParentSelected: parentSelected,
230
+ order: blockOrder,
231
+ };
232
+ },
233
+ [ clientId, isSelected, name, rootClientId ]
234
+ );
235
+ const { removeBlock, selectBlock } = useDispatch( blockEditorStore );
236
+ const initialBlockWidth = blockWrapperWidth - 2 * marginHorizontal;
237
+ const [ blockWidth, setBlockWidth ] = useState( initialBlockWidth );
238
+ const parentLayout = useLayout() || {};
59
239
  const defaultColors = useMobileGlobalStylesColors();
60
- const fontSizes = useSetting( 'typography.fontSizes' ) || emptyArray;
61
240
  const globalStyle = useGlobalStyles();
241
+ const fontSizes = useSetting( 'typography.fontSizes' ) || emptyArray;
242
+
243
+ const onRemove = useCallback(
244
+ () => removeBlock( clientId ),
245
+ [ clientId, removeBlock ]
246
+ );
247
+ const onFocus = useCallback( () => {
248
+ const blockId = firstToSelectId ?? clientId;
249
+ if ( ! isSelected ) {
250
+ selectBlock( blockId );
251
+ }
252
+ }, [ selectBlock, clientId, firstToSelectId, isSelected ] );
253
+
254
+ const onLayout = useCallback(
255
+ ( { nativeEvent } ) => {
256
+ const layoutWidth = Math.floor( nativeEvent.layout.width );
257
+
258
+ if ( ! blockWidth || ! layoutWidth ) {
259
+ return;
260
+ }
261
+
262
+ if ( blockWidth !== layoutWidth ) {
263
+ setBlockWidth( layoutWidth );
264
+ }
265
+ },
266
+ [ blockWidth, setBlockWidth ]
267
+ );
268
+
269
+ // Block level styles.
270
+ const wrapperProps = getWrapperProps(
271
+ attributes,
272
+ blockType.getEditWrapperProps
273
+ );
274
+
275
+ // Inherited styles merged with block level styles.
62
276
  const mergedStyle = useMemo( () => {
63
277
  return getMergedGlobalStyles(
64
278
  baseGlobalStyles,
@@ -69,12 +283,20 @@ function BlockForType( {
69
283
  name,
70
284
  fontSizes
71
285
  );
286
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
287
  }, [
73
- defaultColors,
74
- globalStyle,
75
- // I couldn't simply use attributes and wrapperProps.styles as a dependency because they are almost always a new reference.
76
- // Thanks to the JSON.stringify we check if the value is the same instead of reference.
288
+ // It is crucial to keep the dependencies array minimal to prevent unnecessary calls that could negatively impact performance.
289
+ // JSON.stringify is used for the following purposes:
290
+ // 1. To create a single, comparable value from the globalStyle, wrapperProps.style, and attributes objects. This allows useMemo to
291
+ // efficiently determine if a change has occurred in any of these objects.
292
+ // 2. To filter the attributes object, ensuring that only the relevant attributes (included in
293
+ // GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES) are considered as dependencies. This reduces the likelihood of
294
+ // unnecessary useMemo calls when other, unrelated attributes change.
295
+ // eslint-disable-next-line react-hooks/exhaustive-deps
296
+ JSON.stringify( globalStyle ),
297
+ // eslint-disable-next-line react-hooks/exhaustive-deps
77
298
  JSON.stringify( wrapperProps.style ),
299
+ // eslint-disable-next-line react-hooks/exhaustive-deps
78
300
  JSON.stringify(
79
301
  Object.fromEntries(
80
302
  Object.entries( attributes ?? {} ).filter( ( [ key ] ) =>
@@ -84,503 +306,251 @@ function BlockForType( {
84
306
  ),
85
307
  ] );
86
308
 
87
- const parentLayout = useLayout();
88
-
89
- return (
90
- <GlobalStylesContext.Provider value={ mergedStyle }>
91
- <BlockEdit
92
- name={ name }
93
- isSelected={ isSelected }
94
- attributes={ attributes }
95
- setAttributes={ onChange }
96
- onFocus={ onBlockFocus }
97
- onReplace={ onReplace }
98
- insertBlocksAfter={ insertBlocksAfter }
99
- mergeBlocks={ onMerge }
100
- // Block level styles.
101
- wrapperProps={ wrapperProps }
102
- // Inherited styles merged with block level styles.
103
- style={ mergedStyle }
104
- clientId={ clientId }
105
- parentWidth={ parentWidth }
106
- contentStyle={ contentStyle }
107
- onDeleteBlock={ onDeleteBlock }
108
- blockWidth={ blockWidth }
109
- parentBlockAlignment={ parentBlockAlignment }
110
- __unstableParentLayout={ parentLayout }
111
- />
112
- <View onLayout={ getBlockWidth } />
113
- </GlobalStylesContext.Provider>
309
+ const { align } = attributes;
310
+ const isFocused = isSelected || isDescendentBlockSelected;
311
+ const isTouchable =
312
+ isSelected ||
313
+ isDescendantOfParentSelected ||
314
+ isParentSelected ||
315
+ ! rootClientId;
316
+
317
+ const accessibilityLabel = getAccessibleBlockLabel(
318
+ blockType,
319
+ attributes,
320
+ order + 1
114
321
  );
115
- }
116
-
117
- class BlockListBlock extends Component {
118
- constructor() {
119
- super( ...arguments );
120
-
121
- this.insertBlocksAfter = this.insertBlocksAfter.bind( this );
122
- this.onFocus = this.onFocus.bind( this );
123
- this.getBlockWidth = this.getBlockWidth.bind( this );
124
-
125
- this.state = {
126
- blockWidth: this.props.blockWidth - 2 * this.props.marginHorizontal,
127
- };
128
-
129
- this.anchorNodeRef = createRef();
130
- }
131
-
132
- onFocus() {
133
- const { firstToSelectId, isSelected, onSelect } = this.props;
134
- if ( ! isSelected ) {
135
- onSelect( firstToSelectId );
136
- }
137
- }
138
-
139
- insertBlocksAfter( blocks ) {
140
- this.props.onInsertBlocks( blocks, this.props.order + 1 );
141
-
142
- if ( blocks[ 0 ] ) {
143
- // Focus on the first block inserted.
144
- this.props.onSelect( blocks[ 0 ].clientId );
145
- }
146
- }
147
-
148
- getBlockWidth( { nativeEvent } ) {
149
- const { layout } = nativeEvent;
150
- const { blockWidth } = this.state;
151
- const layoutWidth = Math.floor( layout.width );
152
-
153
- if ( ! blockWidth || ! layoutWidth ) {
154
- return;
155
- }
156
-
157
- if ( blockWidth !== layoutWidth ) {
158
- this.setState( { blockWidth: layoutWidth } );
159
- }
160
- }
161
-
162
- getBlockForType() {
163
- const { blockWidth } = this.state;
164
- return (
165
- <BlockForType
166
- { ...this.props }
167
- onBlockFocus={ this.onFocus }
168
- insertBlocksAfter={ this.insertBlocksAfter }
169
- getBlockWidth={ this.getBlockWidth }
170
- blockWidth={ blockWidth }
171
- />
172
- );
173
- }
174
-
175
- renderBlockTitle() {
176
- return (
177
- <View style={ styles.blockTitle }>
178
- <Text>BlockType: { this.props.name }</Text>
179
- </View>
180
- );
181
- }
182
322
 
183
- render() {
184
- const {
185
- attributes,
186
- blockType,
187
- clientId,
188
- icon,
189
- isSelected,
190
- isValid,
191
- order,
192
- title,
193
- isDimmed,
194
- isTouchable,
195
- onDeleteBlock,
196
- isStackedHorizontally,
197
- isParentSelected,
198
- getStylesFromColorScheme,
199
- marginVertical,
200
- marginHorizontal,
201
- isInnerBlockSelected,
202
- name,
203
- draggingEnabled,
204
- draggingClientId,
205
- } = this.props;
206
-
207
- if ( ! attributes || ! blockType ) {
208
- return null;
209
- }
210
- const { blockWidth } = this.state;
211
- const { align } = attributes;
212
- const accessibilityLabel = getAccessibleBlockLabel(
213
- blockType,
214
- attributes,
215
- order + 1
216
- );
217
- const { isFullWidth, isContainerRelated } = alignmentHelpers;
218
- const isFocused = isSelected || isInnerBlockSelected;
219
- const screenWidth = Math.floor( Dimensions.get( 'window' ).width );
220
- const isScreenWidthEqual = blockWidth === screenWidth;
221
- const isScreenWidthWider = blockWidth < screenWidth;
222
- const isFullWidthToolbar = isFullWidth( align ) || isScreenWidthEqual;
223
-
224
- return (
225
- <TouchableWithoutFeedback
226
- onPress={ this.onFocus }
227
- accessible={ ! isFocused }
228
- accessibilityRole={ 'button' }
229
- disabled={ isFocused }
230
- >
231
- <View
232
- style={ { flex: 1 } }
233
- accessibilityLabel={ accessibilityLabel }
234
- >
235
- <View
236
- pointerEvents={ isTouchable ? 'auto' : 'box-only' }
237
- accessibilityLabel={ accessibilityLabel }
238
- style={ [
239
- { marginVertical, marginHorizontal, flex: 1 },
240
- isDimmed && styles.dimmed,
241
- ] }
242
- >
243
- { isSelected && (
244
- <View
245
- pointerEvents="box-none"
246
- style={ [
247
- styles.solidBorder,
248
- isFullWidth( align ) &&
249
- isScreenWidthWider &&
250
- styles.borderFullWidth,
251
- isFullWidth( align ) &&
252
- isContainerRelated( name ) &&
253
- isScreenWidthWider &&
254
- styles.containerBorderFullWidth,
255
- getStylesFromColorScheme(
256
- styles.solidBorderColor,
257
- styles.solidBorderColorDark
258
- ),
259
- ] }
260
- />
261
- ) }
262
- { isParentSelected && (
263
- <View
264
- style={ [
265
- styles.dashedBorder,
266
- getStylesFromColorScheme(
267
- styles.dashedBorderColor,
268
- styles.dashedBorderColorDark
269
- ),
270
- ] }
271
- />
272
- ) }
273
- <BlockDraggable
323
+ return (
324
+ <BlockWrapper
325
+ accessibilityLabel={ accessibilityLabel }
326
+ align={ align }
327
+ blockWidth={ blockWidth }
328
+ clientId={ clientId }
329
+ draggingClientId={ draggingClientId }
330
+ draggingEnabled={ draggingEnabled }
331
+ isFocused={ isFocused }
332
+ isDescendentBlockSelected={ isDescendentBlockSelected }
333
+ isParentSelected={ isParentSelected }
334
+ isSelected={ isSelected }
335
+ isStackedHorizontally={ isStackedHorizontally }
336
+ isTouchable={ isTouchable }
337
+ marginHorizontal={ marginHorizontal }
338
+ marginVertical={ marginVertical }
339
+ onDeleteBlock={ onDeleteBlock }
340
+ onFocus={ onFocus }
341
+ >
342
+ { () =>
343
+ ! isValid ? (
344
+ <BlockInvalidWarning clientId={ clientId } />
345
+ ) : (
346
+ <GlobalStylesContext.Provider value={ mergedStyle }>
347
+ <BlockEdit
348
+ attributes={ attributes }
349
+ blockWidth={ blockWidth }
274
350
  clientId={ clientId }
275
- draggingClientId={ draggingClientId }
276
- enabled={ draggingEnabled }
277
- testID="draggable-trigger-content"
278
- >
279
- { () =>
280
- isValid ? (
281
- this.getBlockForType()
282
- ) : (
283
- <BlockInvalidWarning
284
- blockTitle={ title }
285
- icon={ icon }
286
- clientId={ clientId }
287
- />
288
- )
351
+ contentStyle={ contentStyle }
352
+ insertBlocksAfter={
353
+ isLocked ? undefined : onInsertBlocksAfter
289
354
  }
290
- </BlockDraggable>
291
- <View
292
- style={ styles.neutralToolbar }
293
- ref={ this.anchorNodeRef }
294
- >
295
- { isSelected && (
296
- <BlockMobileToolbar
297
- clientId={ clientId }
298
- onDelete={ onDeleteBlock }
299
- isStackedHorizontally={
300
- isStackedHorizontally
301
- }
302
- blockWidth={ blockWidth }
303
- anchorNodeRef={ this.anchorNodeRef.current }
304
- isFullWidth={ isFullWidthToolbar }
305
- draggingClientId={ draggingClientId }
306
- />
307
- ) }
308
- </View>
309
- </View>
310
- </View>
311
- </TouchableWithoutFeedback>
312
- );
313
- }
314
- }
315
-
316
- // Helper function to memoize the wrapperProps since getEditWrapperProps always returns a new reference.
317
- const wrapperPropsCache = new WeakMap();
318
- const emptyObj = {};
319
- function getWrapperProps( value, getWrapperPropsFunction ) {
320
- if ( ! getWrapperPropsFunction ) {
321
- return emptyObj;
322
- }
323
- const cachedValue = wrapperPropsCache.get( value );
324
- if ( ! cachedValue ) {
325
- const wrapperProps = getWrapperPropsFunction( value );
326
- wrapperPropsCache.set( value, wrapperProps );
327
- return wrapperProps;
328
- }
329
- return cachedValue;
355
+ isSelected={ isSelected }
356
+ isSelectionEnabled={ isSelectionEnabled }
357
+ mergeBlocks={ canRemove ? onMerge : undefined }
358
+ name={ name }
359
+ onFocus={ onFocus }
360
+ onRemove={ canRemove ? onRemove : undefined }
361
+ onReplace={ canRemove ? onReplace : undefined }
362
+ parentBlockAlignment={ parentBlockAlignment }
363
+ parentWidth={ parentWidth }
364
+ setAttributes={ setAttributes }
365
+ style={ mergedStyle }
366
+ toggleSelection={ toggleSelection }
367
+ __unstableParentLayout={
368
+ Object.keys( parentLayout ).length
369
+ ? parentLayout
370
+ : undefined
371
+ }
372
+ wrapperProps={ wrapperProps }
373
+ />
374
+ <View onLayout={ onLayout } />
375
+ </GlobalStylesContext.Provider>
376
+ )
377
+ }
378
+ </BlockWrapper>
379
+ );
330
380
  }
331
381
 
332
- export default compose( [
333
- withSelect( ( select, { clientId } ) => {
334
- const {
335
- getBlockIndex,
336
- getBlockCount,
337
- getSettings,
338
- isBlockSelected,
339
- getBlock,
340
- getSelectedBlockClientId,
341
- getLowestCommonAncestorWithSelectedBlock,
342
- getBlockParents,
343
- hasSelectedInnerBlock,
344
- getBlockHierarchyRootClientId,
345
- } = select( blockEditorStore );
346
-
347
- const order = getBlockIndex( clientId );
348
- const isSelected = isBlockSelected( clientId );
349
- const isInnerBlockSelected = hasSelectedInnerBlock( clientId );
350
- const block = getBlock( clientId );
351
- const { name, attributes, isValid } = block || {};
352
-
353
- const blockType = getBlockType( name || 'core/missing' );
354
- const title = blockType?.title;
355
- const icon = blockType?.icon;
356
-
357
- const parents = getBlockParents( clientId, true );
358
- const parentId = parents[ 0 ] || '';
359
-
360
- const selectedBlockClientId = getSelectedBlockClientId();
361
-
362
- const commonAncestor =
363
- getLowestCommonAncestorWithSelectedBlock( clientId );
364
- const commonAncestorIndex = parents.indexOf( commonAncestor ) - 1;
365
- const firstToSelectId = commonAncestor
366
- ? parents[ commonAncestorIndex ]
367
- : parents[ parents.length - 1 ];
368
-
369
- const isParentSelected =
370
- // Set false as a default value to prevent re-render when it's changed from null to false.
371
- ( selectedBlockClientId || false ) &&
372
- selectedBlockClientId === parentId;
373
-
374
- const selectedParents = selectedBlockClientId
375
- ? getBlockParents( selectedBlockClientId )
376
- : [];
377
- const isDescendantOfParentSelected =
378
- selectedParents.includes( parentId );
379
- const isTouchable =
380
- isSelected ||
381
- isDescendantOfParentSelected ||
382
- isParentSelected ||
383
- parentId === '';
384
- const baseGlobalStyles =
385
- getSettings()?.__experimentalGlobalStylesBaseStyles;
386
-
387
- const hasInnerBlocks = getBlockCount( clientId ) > 0;
388
- // For blocks with inner blocks, we only enable the dragging in the nested
389
- // blocks if any of them are selected. This way we prevent the long-press
390
- // gesture from being disabled for elements within the block UI.
391
- const draggingEnabled =
392
- ! hasInnerBlocks ||
393
- isSelected ||
394
- ! hasSelectedInnerBlock( clientId, true );
395
- // Dragging nested blocks is not supported yet. For this reason, the block to be dragged
396
- // will be the top in the hierarchy.
397
- const draggingClientId = getBlockHierarchyRootClientId( clientId );
398
-
399
- return {
400
- icon,
401
- name: name || 'core/missing',
402
- order,
403
- title,
404
- attributes,
405
- blockType,
406
- draggingClientId,
407
- draggingEnabled,
408
- isSelected,
409
- isInnerBlockSelected,
410
- isValid,
411
- isParentSelected,
412
- firstToSelectId,
413
- isTouchable,
414
- baseGlobalStyles,
415
- wrapperProps: getWrapperProps(
416
- attributes,
417
- blockType.getEditWrapperProps
418
- ),
419
- };
420
- } ),
421
- withDispatch( ( dispatch, ownProps, registry ) => {
422
- const {
423
- insertBlocks,
424
- mergeBlocks,
425
- replaceBlocks,
426
- selectBlock,
427
- updateBlockAttributes,
428
- moveBlocksToPosition,
429
- removeBlock,
430
- } = dispatch( blockEditorStore );
431
-
432
- return {
433
- onMerge( forward ) {
434
- const { clientId, rootClientId } = ownProps;
435
- const {
436
- getPreviousBlockClientId,
437
- getNextBlockClientId,
438
- getBlock,
439
- getBlockAttributes,
440
- getBlockName,
441
- getBlockOrder,
442
- getBlockIndex,
443
- getBlockRootClientId,
444
- canInsertBlockType,
445
- } = registry.select( blockEditorStore );
446
-
447
- /**
448
- * Moves the block with clientId up one level. If the block type
449
- * cannot be inserted at the new location, it will be attempted to
450
- * convert to the default block type.
451
- *
452
- * @param {string} _clientId The block to move.
453
- * @param {boolean} changeSelection Whether to change the selection
454
- * to the moved block.
455
- */
456
- function moveFirstItemUp( _clientId, changeSelection = true ) {
457
- const targetRootClientId =
458
- getBlockRootClientId( _clientId );
459
- const blockOrder = getBlockOrder( _clientId );
460
- const [ firstClientId ] = blockOrder;
461
-
382
+ const applyWithSelect = withSelect( ( select, { clientId, rootClientId } ) => {
383
+ const {
384
+ isBlockSelected,
385
+ getBlockMode,
386
+ isSelectionEnabled,
387
+ getTemplateLock,
388
+ __unstableGetBlockWithoutInnerBlocks,
389
+ canRemoveBlock,
390
+ canMoveBlock,
391
+ } = select( blockEditorStore );
392
+ const block = __unstableGetBlockWithoutInnerBlocks( clientId );
393
+ const isSelected = isBlockSelected( clientId );
394
+ const templateLock = getTemplateLock( rootClientId );
395
+ const canRemove = canRemoveBlock( clientId, rootClientId );
396
+ const canMove = canMoveBlock( clientId, rootClientId );
397
+
398
+ // The fallback to `{}` is a temporary fix.
399
+ // This function should never be called when a block is not present in
400
+ // the state. It happens now because the order in withSelect rendering
401
+ // is not correct.
402
+ const { name, attributes, isValid } = block || {};
403
+
404
+ // Do not add new properties here, use `useSelect` instead to avoid
405
+ // leaking new props to the public API (editor.BlockListBlock filter).
406
+ return {
407
+ mode: getBlockMode( clientId ),
408
+ isSelectionEnabled: isSelectionEnabled(),
409
+ isLocked: !! templateLock,
410
+ canRemove,
411
+ canMove,
412
+ // Users of the editor.BlockListBlock filter used to be able to
413
+ // access the block prop.
414
+ // Ideally these blocks would rely on the clientId prop only.
415
+ // This is kept for backward compatibility reasons.
416
+ block,
417
+ name,
418
+ attributes,
419
+ isValid,
420
+ isSelected,
421
+ };
422
+ } );
423
+
424
+ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
425
+ const {
426
+ updateBlockAttributes,
427
+ insertBlocks,
428
+ mergeBlocks,
429
+ replaceBlocks,
430
+ toggleSelection,
431
+ __unstableMarkLastChangeAsPersistent,
432
+ moveBlocksToPosition,
433
+ removeBlock,
434
+ } = dispatch( blockEditorStore );
435
+
436
+ // Do not add new properties here, use `useDispatch` instead to avoid
437
+ // leaking new props to the public API (editor.BlockListBlock filter).
438
+ return {
439
+ setAttributes( newAttributes ) {
440
+ const { getMultiSelectedBlockClientIds } =
441
+ registry.select( blockEditorStore );
442
+ const multiSelectedBlockClientIds =
443
+ getMultiSelectedBlockClientIds();
444
+ const { clientId } = ownProps;
445
+ const clientIds = multiSelectedBlockClientIds.length
446
+ ? multiSelectedBlockClientIds
447
+ : [ clientId ];
448
+
449
+ updateBlockAttributes( clientIds, newAttributes );
450
+ },
451
+ onInsertBlocks( blocks, index ) {
452
+ const { rootClientId } = ownProps;
453
+ insertBlocks( blocks, index, rootClientId );
454
+ },
455
+ onInsertBlocksAfter( blocks ) {
456
+ const { clientId, rootClientId } = ownProps;
457
+ const { getBlockIndex } = registry.select( blockEditorStore );
458
+ const index = getBlockIndex( clientId );
459
+ insertBlocks( blocks, index + 1, rootClientId );
460
+ },
461
+ onMerge( forward ) {
462
+ const { clientId, rootClientId } = ownProps;
463
+ const {
464
+ getPreviousBlockClientId,
465
+ getNextBlockClientId,
466
+ getBlock,
467
+ getBlockAttributes,
468
+ getBlockName,
469
+ getBlockOrder,
470
+ getBlockIndex,
471
+ getBlockRootClientId,
472
+ canInsertBlockType,
473
+ } = registry.select( blockEditorStore );
474
+
475
+ /**
476
+ * Moves the block with clientId up one level. If the block type
477
+ * cannot be inserted at the new location, it will be attempted to
478
+ * convert to the default block type.
479
+ *
480
+ * @param {string} _clientId The block to move.
481
+ * @param {boolean} changeSelection Whether to change the selection
482
+ * to the moved block.
483
+ */
484
+ function moveFirstItemUp( _clientId, changeSelection = true ) {
485
+ const targetRootClientId = getBlockRootClientId( _clientId );
486
+ const blockOrder = getBlockOrder( _clientId );
487
+ const [ firstClientId ] = blockOrder;
488
+
489
+ if (
490
+ blockOrder.length === 1 &&
491
+ isUnmodifiedBlock( getBlock( firstClientId ) )
492
+ ) {
493
+ removeBlock( _clientId );
494
+ } else {
462
495
  if (
463
- blockOrder.length === 1 &&
464
- isUnmodifiedBlock( getBlock( firstClientId ) )
496
+ canInsertBlockType(
497
+ getBlockName( firstClientId ),
498
+ targetRootClientId
499
+ )
465
500
  ) {
466
- removeBlock( _clientId );
501
+ moveBlocksToPosition(
502
+ [ firstClientId ],
503
+ _clientId,
504
+ targetRootClientId,
505
+ getBlockIndex( _clientId )
506
+ );
467
507
  } else {
468
- if (
469
- canInsertBlockType(
470
- getBlockName( firstClientId ),
471
- targetRootClientId
472
- )
473
- ) {
474
- moveBlocksToPosition(
475
- [ firstClientId ],
476
- _clientId,
477
- targetRootClientId,
478
- getBlockIndex( _clientId )
479
- );
480
- } else {
481
- const replacement = switchToBlockType(
482
- getBlock( firstClientId ),
483
- getDefaultBlockName()
484
- );
485
-
486
- if ( replacement && replacement.length ) {
487
- registry.batch( () => {
488
- insertBlocks(
489
- replacement,
490
- getBlockIndex( _clientId ),
491
- targetRootClientId,
492
- changeSelection
493
- );
494
- removeBlock( firstClientId, false );
495
- } );
496
- }
497
- }
498
-
499
- if (
500
- ! getBlockOrder( _clientId ).length &&
501
- isUnmodifiedBlock( getBlock( _clientId ) )
502
- ) {
503
- removeBlock( _clientId, false );
504
- }
505
- }
506
- }
507
-
508
- // For `Delete` or forward merge, we should do the exact same thing
509
- // as `Backspace`, but from the other block.
510
- if ( forward ) {
511
- if ( rootClientId ) {
512
- const nextRootClientId =
513
- getNextBlockClientId( rootClientId );
514
-
515
- if ( nextRootClientId ) {
516
- // If there is a block that follows with the same parent
517
- // block name and the same attributes, merge the inner
518
- // blocks.
519
- if (
520
- getBlockName( rootClientId ) ===
521
- getBlockName( nextRootClientId )
522
- ) {
523
- const rootAttributes =
524
- getBlockAttributes( rootClientId );
525
- const previousRootAttributes =
526
- getBlockAttributes( nextRootClientId );
527
-
528
- if (
529
- Object.keys( rootAttributes ).every(
530
- ( key ) =>
531
- rootAttributes[ key ] ===
532
- previousRootAttributes[ key ]
533
- )
534
- ) {
535
- registry.batch( () => {
536
- moveBlocksToPosition(
537
- getBlockOrder( nextRootClientId ),
538
- nextRootClientId,
539
- rootClientId
540
- );
541
- removeBlock( nextRootClientId, false );
542
- } );
543
- return;
544
- }
545
- } else {
546
- mergeBlocks( rootClientId, nextRootClientId );
547
- return;
548
- }
508
+ const replacement = switchToBlockType(
509
+ getBlock( firstClientId ),
510
+ getDefaultBlockName()
511
+ );
512
+
513
+ if ( replacement && replacement.length ) {
514
+ registry.batch( () => {
515
+ insertBlocks(
516
+ replacement,
517
+ getBlockIndex( _clientId ),
518
+ targetRootClientId,
519
+ changeSelection
520
+ );
521
+ removeBlock( firstClientId, false );
522
+ } );
549
523
  }
550
524
  }
551
525
 
552
- const nextBlockClientId = getNextBlockClientId( clientId );
553
-
554
- if ( ! nextBlockClientId ) {
555
- return;
556
- }
557
-
558
- if ( getBlockOrder( nextBlockClientId ).length ) {
559
- moveFirstItemUp( nextBlockClientId, false );
560
- } else {
561
- mergeBlocks( clientId, nextBlockClientId );
526
+ if (
527
+ ! getBlockOrder( _clientId ).length &&
528
+ isUnmodifiedBlock( getBlock( _clientId ) )
529
+ ) {
530
+ removeBlock( _clientId, false );
562
531
  }
563
- } else {
564
- const previousBlockClientId =
565
- getPreviousBlockClientId( clientId );
566
-
567
- if ( previousBlockClientId ) {
568
- mergeBlocks( previousBlockClientId, clientId );
569
- } else if ( rootClientId ) {
570
- const previousRootClientId =
571
- getPreviousBlockClientId( rootClientId );
572
-
573
- // If there is a preceding block with the same parent block
574
- // name and the same attributes, merge the inner blocks.
532
+ }
533
+ }
534
+
535
+ // For `Delete` or forward merge, we should do the exact same thing
536
+ // as `Backspace`, but from the other block.
537
+ if ( forward ) {
538
+ if ( rootClientId ) {
539
+ const nextRootClientId =
540
+ getNextBlockClientId( rootClientId );
541
+
542
+ if ( nextRootClientId ) {
543
+ // If there is a block that follows with the same parent
544
+ // block name and the same attributes, merge the inner
545
+ // blocks.
575
546
  if (
576
- previousRootClientId &&
577
547
  getBlockName( rootClientId ) ===
578
- getBlockName( previousRootClientId )
548
+ getBlockName( nextRootClientId )
579
549
  ) {
580
550
  const rootAttributes =
581
551
  getBlockAttributes( rootClientId );
582
552
  const previousRootAttributes =
583
- getBlockAttributes( previousRootClientId );
553
+ getBlockAttributes( nextRootClientId );
584
554
 
585
555
  if (
586
556
  Object.keys( rootAttributes ).every(
@@ -591,33 +561,103 @@ export default compose( [
591
561
  ) {
592
562
  registry.batch( () => {
593
563
  moveBlocksToPosition(
594
- getBlockOrder( rootClientId ),
595
- rootClientId,
596
- previousRootClientId
564
+ getBlockOrder( nextRootClientId ),
565
+ nextRootClientId,
566
+ rootClientId
597
567
  );
598
- removeBlock( rootClientId, false );
568
+ removeBlock( nextRootClientId, false );
599
569
  } );
600
570
  return;
601
571
  }
572
+ } else {
573
+ mergeBlocks( rootClientId, nextRootClientId );
574
+ return;
602
575
  }
576
+ }
577
+ }
578
+
579
+ const nextBlockClientId = getNextBlockClientId( clientId );
580
+
581
+ if ( ! nextBlockClientId ) {
582
+ return;
583
+ }
584
+
585
+ if ( getBlockOrder( nextBlockClientId ).length ) {
586
+ moveFirstItemUp( nextBlockClientId, false );
587
+ } else {
588
+ mergeBlocks( clientId, nextBlockClientId );
589
+ }
590
+ } else {
591
+ const previousBlockClientId =
592
+ getPreviousBlockClientId( clientId );
593
+
594
+ if ( previousBlockClientId ) {
595
+ mergeBlocks( previousBlockClientId, clientId );
596
+ } else if ( rootClientId ) {
597
+ const previousRootClientId =
598
+ getPreviousBlockClientId( rootClientId );
599
+
600
+ // If there is a preceding block with the same parent block
601
+ // name and the same attributes, merge the inner blocks.
602
+ if (
603
+ previousRootClientId &&
604
+ getBlockName( rootClientId ) ===
605
+ getBlockName( previousRootClientId )
606
+ ) {
607
+ const rootAttributes =
608
+ getBlockAttributes( rootClientId );
609
+ const previousRootAttributes =
610
+ getBlockAttributes( previousRootClientId );
603
611
 
604
- moveFirstItemUp( rootClientId );
612
+ if (
613
+ Object.keys( rootAttributes ).every(
614
+ ( key ) =>
615
+ rootAttributes[ key ] ===
616
+ previousRootAttributes[ key ]
617
+ )
618
+ ) {
619
+ registry.batch( () => {
620
+ moveBlocksToPosition(
621
+ getBlockOrder( rootClientId ),
622
+ rootClientId,
623
+ previousRootClientId
624
+ );
625
+ removeBlock( rootClientId, false );
626
+ } );
627
+ return;
628
+ }
605
629
  }
630
+
631
+ moveFirstItemUp( rootClientId );
606
632
  }
607
- },
608
- onInsertBlocks( blocks, index ) {
609
- insertBlocks( blocks, index, ownProps.rootClientId );
610
- },
611
- onSelect( clientId = ownProps.clientId, initialPosition ) {
612
- selectBlock( clientId, initialPosition );
613
- },
614
- onChange: ( attributes ) => {
615
- updateBlockAttributes( ownProps.clientId, attributes );
616
- },
617
- onReplace( blocks, indexToSelect ) {
618
- replaceBlocks( [ ownProps.clientId ], blocks, indexToSelect );
619
- },
620
- };
621
- } ),
622
- withPreferredColorScheme,
623
- ] )( BlockListBlock );
633
+ }
634
+ },
635
+ onReplace( blocks, indexToSelect, initialPosition ) {
636
+ if (
637
+ blocks.length &&
638
+ ! isUnmodifiedDefaultBlock( blocks[ blocks.length - 1 ] )
639
+ ) {
640
+ __unstableMarkLastChangeAsPersistent();
641
+ }
642
+ replaceBlocks(
643
+ [ ownProps.clientId ],
644
+ blocks,
645
+ indexToSelect,
646
+ initialPosition
647
+ );
648
+ },
649
+ toggleSelection( selectionEnabled ) {
650
+ toggleSelection( selectionEnabled );
651
+ },
652
+ };
653
+ } );
654
+
655
+ export default compose(
656
+ pure,
657
+ applyWithSelect,
658
+ applyWithDispatch,
659
+ // Block is sometimes not mounted at the right time, causing it be undefined
660
+ // see issue for more info
661
+ // https://github.com/WordPress/gutenberg/issues/17013
662
+ ifCondition( ( { block } ) => !! block )
663
+ )( BlockListBlock );