@wordpress/block-editor 7.0.4 → 8.0.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 (347) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +31 -0
  3. package/build/components/alignment-control/ui.js +1 -2
  4. package/build/components/alignment-control/ui.js.map +1 -1
  5. package/build/components/block-icon/index.js +5 -1
  6. package/build/components/block-icon/index.js.map +1 -1
  7. package/build/components/block-inspector/index.js +4 -0
  8. package/build/components/block-inspector/index.js.map +1 -1
  9. package/build/components/block-list/index.native.js +1 -1
  10. package/build/components/block-list/index.native.js.map +1 -1
  11. package/build/components/block-list/use-block-props/use-multi-selection.js +21 -8
  12. package/build/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
  13. package/build/components/block-navigation/dropdown.js +0 -1
  14. package/build/components/block-navigation/dropdown.js.map +1 -1
  15. package/build/components/block-patterns-list/index.js +1 -8
  16. package/build/components/block-patterns-list/index.js.map +1 -1
  17. package/build/components/block-settings/container.native.js +5 -2
  18. package/build/components/block-settings/container.native.js.map +1 -1
  19. package/build/components/block-settings-menu/block-settings-dropdown.js +22 -2
  20. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  21. package/build/components/block-styles/preview.native.js +2 -2
  22. package/build/components/block-styles/preview.native.js.map +1 -1
  23. package/build/components/colors-gradients/control.js +8 -47
  24. package/build/components/colors-gradients/control.js.map +1 -1
  25. package/build/components/colors-gradients/panel-color-gradient-settings.js +81 -6
  26. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  27. package/build/components/duotone-control/index.js +5 -2
  28. package/build/components/duotone-control/index.js.map +1 -1
  29. package/build/components/font-appearance-control/index.js +27 -15
  30. package/build/components/font-appearance-control/index.js.map +1 -1
  31. package/build/components/iframe/index.js +1 -1
  32. package/build/components/iframe/index.js.map +1 -1
  33. package/build/components/index.js +20 -2
  34. package/build/components/index.js.map +1 -1
  35. package/build/components/index.native.js +2 -2
  36. package/build/components/index.native.js.map +1 -1
  37. package/build/components/inner-blocks/index.js +5 -4
  38. package/build/components/inner-blocks/index.js.map +1 -1
  39. package/build/components/inner-blocks/index.native.js +4 -3
  40. package/build/components/inner-blocks/index.native.js.map +1 -1
  41. package/build/components/inserter/block-patterns-explorer/explorer.js +62 -0
  42. package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
  43. package/build/components/inserter/block-patterns-explorer/patterns-list.js +111 -0
  44. package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
  45. package/build/components/inserter/block-patterns-explorer/sidebar.js +78 -0
  46. package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
  47. package/build/components/inserter/block-patterns-tab.js +74 -45
  48. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  49. package/build/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
  50. package/build/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
  51. package/build/components/inserter/pattern-panel.js +19 -10
  52. package/build/components/inserter/pattern-panel.js.map +1 -1
  53. package/build/components/inspector-controls/groups.js +3 -1
  54. package/build/components/inspector-controls/groups.js.map +1 -1
  55. package/build/components/letter-spacing-control/index.js +9 -6
  56. package/build/components/letter-spacing-control/index.js.map +1 -1
  57. package/build/components/link-control/index.js +88 -35
  58. package/build/components/link-control/index.js.map +1 -1
  59. package/build/components/link-control/link-preview.js +19 -6
  60. package/build/components/link-control/link-preview.js.map +1 -1
  61. package/build/components/link-control/search-input.js +12 -3
  62. package/build/components/link-control/search-input.js.map +1 -1
  63. package/build/components/list-view/block.js +49 -23
  64. package/build/components/list-view/block.js.map +1 -1
  65. package/build/components/list-view/branch.js +92 -73
  66. package/build/components/list-view/branch.js.map +1 -1
  67. package/build/components/list-view/index.js +39 -16
  68. package/build/components/list-view/index.js.map +1 -1
  69. package/build/components/list-view/leaf.js +1 -1
  70. package/build/components/list-view/leaf.js.map +1 -1
  71. package/build/components/list-view/use-list-view-client-ids.js +8 -58
  72. package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
  73. package/build/components/rich-text/embed-handler-picker.native.js +1 -0
  74. package/build/components/rich-text/embed-handler-picker.native.js.map +1 -1
  75. package/build/components/rich-text/format-edit.js +28 -2
  76. package/build/components/rich-text/format-edit.js.map +1 -1
  77. package/build/components/rich-text/format-toolbar/index.js +2 -1
  78. package/build/components/rich-text/format-toolbar/index.js.map +1 -1
  79. package/build/components/url-input/index.js +11 -4
  80. package/build/components/url-input/index.js.map +1 -1
  81. package/build/components/use-setting/index.js +48 -9
  82. package/build/components/use-setting/index.js.map +1 -1
  83. package/build/hooks/border.js +5 -5
  84. package/build/hooks/border.js.map +1 -1
  85. package/build/hooks/color-panel.js +2 -1
  86. package/build/hooks/color-panel.js.map +1 -1
  87. package/build/hooks/duotone.js +16 -5
  88. package/build/hooks/duotone.js.map +1 -1
  89. package/build/hooks/font-appearance.js +49 -6
  90. package/build/hooks/font-appearance.js.map +1 -1
  91. package/build/hooks/font-family.js +37 -16
  92. package/build/hooks/font-family.js.map +1 -1
  93. package/build/hooks/font-size.js +51 -9
  94. package/build/hooks/font-size.js.map +1 -1
  95. package/build/hooks/index.js +8 -0
  96. package/build/hooks/index.js.map +1 -1
  97. package/build/hooks/index.native.js +8 -0
  98. package/build/hooks/index.native.js.map +1 -1
  99. package/build/hooks/letter-spacing.js +44 -7
  100. package/build/hooks/letter-spacing.js.map +1 -1
  101. package/build/hooks/line-height.js +45 -8
  102. package/build/hooks/line-height.js.map +1 -1
  103. package/build/hooks/margin.js +1 -1
  104. package/build/hooks/margin.js.map +1 -1
  105. package/build/hooks/padding.js +1 -1
  106. package/build/hooks/padding.js.map +1 -1
  107. package/build/hooks/text-decoration.js +42 -6
  108. package/build/hooks/text-decoration.js.map +1 -1
  109. package/build/hooks/text-transform.js +42 -6
  110. package/build/hooks/text-transform.js.map +1 -1
  111. package/build/hooks/typography.js +108 -8
  112. package/build/hooks/typography.js.map +1 -1
  113. package/build/hooks/use-cached-truthy.js +29 -0
  114. package/build/hooks/use-cached-truthy.js.map +1 -0
  115. package/build/index.js +7 -0
  116. package/build/index.js.map +1 -1
  117. package/build/layouts/flex.js +120 -28
  118. package/build/layouts/flex.js.map +1 -1
  119. package/build/store/actions.js +303 -265
  120. package/build/store/actions.js.map +1 -1
  121. package/build/store/index.js +1 -3
  122. package/build/store/index.js.map +1 -1
  123. package/build/store/reducer.js +23 -22
  124. package/build/store/reducer.js.map +1 -1
  125. package/build/store/selectors.js +44 -35
  126. package/build/store/selectors.js.map +1 -1
  127. package/build-module/components/alignment-control/ui.js +1 -2
  128. package/build-module/components/alignment-control/ui.js.map +1 -1
  129. package/build-module/components/block-icon/index.js +5 -1
  130. package/build-module/components/block-icon/index.js.map +1 -1
  131. package/build-module/components/block-inspector/index.js +4 -0
  132. package/build-module/components/block-inspector/index.js.map +1 -1
  133. package/build-module/components/block-list/index.native.js +1 -1
  134. package/build-module/components/block-list/index.native.js.map +1 -1
  135. package/build-module/components/block-list/use-block-props/use-multi-selection.js +21 -8
  136. package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
  137. package/build-module/components/block-navigation/dropdown.js +0 -1
  138. package/build-module/components/block-navigation/dropdown.js.map +1 -1
  139. package/build-module/components/block-patterns-list/index.js +1 -6
  140. package/build-module/components/block-patterns-list/index.js.map +1 -1
  141. package/build-module/components/block-settings/container.native.js +6 -3
  142. package/build-module/components/block-settings/container.native.js.map +1 -1
  143. package/build-module/components/block-settings-menu/block-settings-dropdown.js +24 -4
  144. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  145. package/build-module/components/block-styles/preview.native.js +2 -2
  146. package/build-module/components/block-styles/preview.native.js.map +1 -1
  147. package/build-module/components/colors-gradients/control.js +12 -53
  148. package/build-module/components/colors-gradients/control.js.map +1 -1
  149. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +82 -6
  150. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  151. package/build-module/components/duotone-control/index.js +5 -2
  152. package/build-module/components/duotone-control/index.js.map +1 -1
  153. package/build-module/components/font-appearance-control/index.js +23 -15
  154. package/build-module/components/font-appearance-control/index.js.map +1 -1
  155. package/build-module/components/iframe/index.js +1 -1
  156. package/build-module/components/iframe/index.js.map +1 -1
  157. package/build-module/components/index.js +3 -1
  158. package/build-module/components/index.js.map +1 -1
  159. package/build-module/components/index.native.js +1 -1
  160. package/build-module/components/index.native.js.map +1 -1
  161. package/build-module/components/inner-blocks/index.js +6 -5
  162. package/build-module/components/inner-blocks/index.js.map +1 -1
  163. package/build-module/components/inner-blocks/index.native.js +5 -4
  164. package/build-module/components/inner-blocks/index.native.js.map +1 -1
  165. package/build-module/components/inserter/block-patterns-explorer/explorer.js +50 -0
  166. package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
  167. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +92 -0
  168. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
  169. package/build-module/components/inserter/block-patterns-explorer/sidebar.js +69 -0
  170. package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
  171. package/build-module/components/inserter/block-patterns-tab.js +75 -46
  172. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  173. package/build-module/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
  174. package/build-module/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
  175. package/build-module/components/inserter/pattern-panel.js +21 -13
  176. package/build-module/components/inserter/pattern-panel.js.map +1 -1
  177. package/build-module/components/inspector-controls/groups.js +3 -1
  178. package/build-module/components/inspector-controls/groups.js.map +1 -1
  179. package/build-module/components/letter-spacing-control/index.js +9 -6
  180. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  181. package/build-module/components/link-control/index.js +88 -36
  182. package/build-module/components/link-control/index.js.map +1 -1
  183. package/build-module/components/link-control/link-preview.js +19 -7
  184. package/build-module/components/link-control/link-preview.js.map +1 -1
  185. package/build-module/components/link-control/search-input.js +11 -3
  186. package/build-module/components/link-control/search-input.js.map +1 -1
  187. package/build-module/components/list-view/block.js +49 -24
  188. package/build-module/components/list-view/block.js.map +1 -1
  189. package/build-module/components/list-view/branch.js +92 -73
  190. package/build-module/components/list-view/branch.js.map +1 -1
  191. package/build-module/components/list-view/index.js +41 -18
  192. package/build-module/components/list-view/index.js.map +1 -1
  193. package/build-module/components/list-view/leaf.js +1 -1
  194. package/build-module/components/list-view/leaf.js.map +1 -1
  195. package/build-module/components/list-view/use-list-view-client-ids.js +8 -58
  196. package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
  197. package/build-module/components/rich-text/embed-handler-picker.native.js +1 -0
  198. package/build-module/components/rich-text/embed-handler-picker.native.js.map +1 -1
  199. package/build-module/components/rich-text/format-edit.js +28 -3
  200. package/build-module/components/rich-text/format-edit.js.map +1 -1
  201. package/build-module/components/rich-text/format-toolbar/index.js +2 -1
  202. package/build-module/components/rich-text/format-toolbar/index.js.map +1 -1
  203. package/build-module/components/url-input/index.js +11 -4
  204. package/build-module/components/url-input/index.js.map +1 -1
  205. package/build-module/components/use-setting/index.js +48 -9
  206. package/build-module/components/use-setting/index.js.map +1 -1
  207. package/build-module/hooks/border.js +5 -5
  208. package/build-module/hooks/border.js.map +1 -1
  209. package/build-module/hooks/color-panel.js +2 -1
  210. package/build-module/hooks/color-panel.js.map +1 -1
  211. package/build-module/hooks/duotone.js +16 -5
  212. package/build-module/hooks/duotone.js.map +1 -1
  213. package/build-module/hooks/font-appearance.js +45 -6
  214. package/build-module/hooks/font-appearance.js.map +1 -1
  215. package/build-module/hooks/font-family.js +33 -16
  216. package/build-module/hooks/font-family.js.map +1 -1
  217. package/build-module/hooks/font-size.js +47 -9
  218. package/build-module/hooks/font-size.js.map +1 -1
  219. package/build-module/hooks/index.js +1 -0
  220. package/build-module/hooks/index.js.map +1 -1
  221. package/build-module/hooks/index.native.js +1 -0
  222. package/build-module/hooks/index.native.js.map +1 -1
  223. package/build-module/hooks/letter-spacing.js +40 -7
  224. package/build-module/hooks/letter-spacing.js.map +1 -1
  225. package/build-module/hooks/line-height.js +41 -8
  226. package/build-module/hooks/line-height.js.map +1 -1
  227. package/build-module/hooks/margin.js +1 -1
  228. package/build-module/hooks/margin.js.map +1 -1
  229. package/build-module/hooks/padding.js +1 -1
  230. package/build-module/hooks/padding.js.map +1 -1
  231. package/build-module/hooks/text-decoration.js +38 -6
  232. package/build-module/hooks/text-decoration.js.map +1 -1
  233. package/build-module/hooks/text-transform.js +38 -6
  234. package/build-module/hooks/text-transform.js.map +1 -1
  235. package/build-module/hooks/typography.js +117 -17
  236. package/build-module/hooks/typography.js.map +1 -1
  237. package/build-module/hooks/use-cached-truthy.js +21 -0
  238. package/build-module/hooks/use-cached-truthy.js.map +1 -0
  239. package/build-module/index.js +1 -1
  240. package/build-module/index.js.map +1 -1
  241. package/build-module/layouts/flex.js +124 -32
  242. package/build-module/layouts/flex.js.map +1 -1
  243. package/build-module/store/actions.js +266 -241
  244. package/build-module/store/actions.js.map +1 -1
  245. package/build-module/store/index.js +1 -2
  246. package/build-module/store/index.js.map +1 -1
  247. package/build-module/store/reducer.js +23 -22
  248. package/build-module/store/reducer.js.map +1 -1
  249. package/build-module/store/selectors.js +42 -30
  250. package/build-module/store/selectors.js.map +1 -1
  251. package/build-style/style-rtl.css +160 -57
  252. package/build-style/style.css +160 -57
  253. package/package.json +13 -14
  254. package/src/components/alignment-control/test/__snapshots__/index.js.snap +0 -2
  255. package/src/components/alignment-control/ui.js +1 -4
  256. package/src/components/block-draggable/style.scss +19 -4
  257. package/src/components/block-icon/index.js +4 -1
  258. package/src/components/block-inspector/index.js +5 -0
  259. package/src/components/block-list/index.native.js +1 -1
  260. package/src/components/block-list/use-block-props/use-multi-selection.js +27 -7
  261. package/src/components/block-navigation/dropdown.js +0 -1
  262. package/src/components/block-patterns-list/index.js +1 -8
  263. package/src/components/block-patterns-list/style.scss +22 -12
  264. package/src/components/block-settings/container.native.js +7 -0
  265. package/src/components/block-settings-menu/block-settings-dropdown.js +19 -7
  266. package/src/components/block-styles/preview.native.js +2 -2
  267. package/src/components/block-switcher/test/__snapshots__/index.js.snap +1 -1
  268. package/src/components/color-palette/test/__snapshots__/control.js.snap +88 -63
  269. package/src/components/colors-gradients/control.js +19 -62
  270. package/src/components/colors-gradients/panel-color-gradient-settings.js +76 -6
  271. package/src/components/colors-gradients/style.scss +3 -14
  272. package/src/components/colors-gradients/test/control.js +0 -16
  273. package/src/components/duotone-control/index.js +6 -0
  274. package/src/components/duotone-control/style.scss +27 -12
  275. package/src/components/font-appearance-control/index.js +22 -14
  276. package/src/components/iframe/index.js +1 -1
  277. package/src/components/index.js +3 -4
  278. package/src/components/index.native.js +1 -4
  279. package/src/components/inner-blocks/index.js +4 -4
  280. package/src/components/inner-blocks/index.native.js +7 -4
  281. package/src/components/inserter/block-patterns-explorer/explorer.js +50 -0
  282. package/src/components/inserter/block-patterns-explorer/patterns-list.js +122 -0
  283. package/src/components/inserter/block-patterns-explorer/sidebar.js +73 -0
  284. package/src/components/inserter/block-patterns-tab.js +107 -80
  285. package/src/components/inserter/hooks/use-block-type-impressions.native.js +14 -21
  286. package/src/components/inserter/pattern-panel.js +33 -16
  287. package/src/components/inserter/style.scss +64 -1
  288. package/src/components/inserter/test/block-types-tab.native.js +1 -1
  289. package/src/components/inserter/test/fixtures/index.native.js +12 -0
  290. package/src/components/inspector-controls/groups.js +4 -0
  291. package/src/components/letter-spacing-control/index.js +12 -6
  292. package/src/components/link-control/README.md +7 -0
  293. package/src/components/link-control/index.js +99 -34
  294. package/src/components/link-control/link-preview.js +21 -9
  295. package/src/components/link-control/search-input.js +9 -3
  296. package/src/components/link-control/style.scss +32 -16
  297. package/src/components/link-control/test/index.js +179 -4
  298. package/src/components/list-view/block.js +67 -23
  299. package/src/components/list-view/branch.js +113 -91
  300. package/src/components/list-view/index.js +58 -19
  301. package/src/components/list-view/leaf.js +1 -1
  302. package/src/components/list-view/style.scss +14 -3
  303. package/src/components/list-view/use-list-view-client-ids.js +7 -66
  304. package/src/components/rich-text/embed-handler-picker.native.js +1 -0
  305. package/src/components/rich-text/format-edit.js +36 -2
  306. package/src/components/rich-text/format-toolbar/index.js +3 -0
  307. package/src/components/url-input/index.js +14 -4
  308. package/src/components/use-setting/index.js +49 -11
  309. package/src/hooks/border.js +8 -11
  310. package/src/hooks/color-panel.js +1 -0
  311. package/src/hooks/duotone.js +21 -7
  312. package/src/hooks/font-appearance.js +38 -7
  313. package/src/hooks/font-family.js +29 -13
  314. package/src/hooks/font-size.js +42 -6
  315. package/src/hooks/index.js +1 -0
  316. package/src/hooks/index.native.js +1 -0
  317. package/src/hooks/layout.scss +3 -1
  318. package/src/hooks/letter-spacing.js +35 -7
  319. package/src/hooks/line-height.js +37 -9
  320. package/src/hooks/margin.js +1 -1
  321. package/src/hooks/padding.js +1 -1
  322. package/src/hooks/text-decoration.js +34 -6
  323. package/src/hooks/text-transform.js +34 -6
  324. package/src/hooks/typography.js +165 -15
  325. package/src/hooks/typography.scss +16 -0
  326. package/src/hooks/use-cached-truthy.js +20 -0
  327. package/src/index.js +1 -0
  328. package/src/layouts/flex.js +137 -41
  329. package/src/store/actions.js +223 -391
  330. package/src/store/index.js +1 -2
  331. package/src/store/reducer.js +36 -18
  332. package/src/store/selectors.js +52 -47
  333. package/src/store/test/actions.js +395 -694
  334. package/src/store/test/selectors.js +79 -21
  335. package/src/style.scss +1 -1
  336. package/src/utils/test/parse-css-unit-to-px.js +127 -167
  337. package/build/components/text-decoration-and-transform/index.js +0 -39
  338. package/build/components/text-decoration-and-transform/index.js.map +0 -1
  339. package/build/store/controls.js +0 -44
  340. package/build/store/controls.js.map +0 -1
  341. package/build-module/components/text-decoration-and-transform/index.js +0 -30
  342. package/build-module/components/text-decoration-and-transform/index.js.map +0 -1
  343. package/build-module/store/controls.js +0 -32
  344. package/build-module/store/controls.js.map +0 -1
  345. package/src/components/text-decoration-and-transform/index.js +0 -36
  346. package/src/components/text-decoration-and-transform/style.scss +0 -3
  347. package/src/store/controls.js +0 -39
@@ -1,154 +1,174 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { map, compact } from 'lodash';
4
+ import { compact } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
+ import { memo } from '@wordpress/element';
9
10
  import { AsyncModeProvider } from '@wordpress/data';
10
11
 
11
12
  /**
12
13
  * Internal dependencies
13
14
  */
14
15
  import ListViewBlock from './block';
15
- import ListViewAppender from './appender';
16
- import { isClientIdSelected } from './utils';
17
16
  import { useListViewContext } from './context';
17
+ import { isClientIdSelected } from './utils';
18
+
19
+ /**
20
+ * Given a block, returns the total number of blocks in that subtree. This is used to help determine
21
+ * the list position of a block.
22
+ *
23
+ * When a block is collapsed, we do not count their children as part of that total. In the current drag
24
+ * implementation dragged blocks and their children are not counted.
25
+ *
26
+ * @param {Object} block block tree
27
+ * @param {Object} expandedState state that notes which branches are collapsed
28
+ * @param {Array} draggedClientIds a list of dragged client ids
29
+ * @return {number} block count
30
+ */
31
+ function countBlocks( block, expandedState, draggedClientIds ) {
32
+ const isDragged = draggedClientIds?.includes( block.clientId );
33
+ if ( isDragged ) {
34
+ return 0;
35
+ }
36
+ const isExpanded = expandedState[ block.clientId ] ?? true;
37
+ if ( isExpanded ) {
38
+ return (
39
+ 1 +
40
+ block.innerBlocks.reduce(
41
+ countReducer( expandedState, draggedClientIds ),
42
+ 0
43
+ )
44
+ );
45
+ }
46
+ return 1;
47
+ }
48
+ const countReducer = ( expandedState, draggedClientIds ) => (
49
+ count,
50
+ block
51
+ ) => {
52
+ const isDragged = draggedClientIds?.includes( block.clientId );
53
+ if ( isDragged ) {
54
+ return count;
55
+ }
56
+ const isExpanded = expandedState[ block.clientId ] ?? true;
57
+ if ( isExpanded && block.innerBlocks.length > 0 ) {
58
+ return count + countBlocks( block, expandedState, draggedClientIds );
59
+ }
60
+ return count + 1;
61
+ };
18
62
 
19
- export default function ListViewBranch( props ) {
63
+ function ListViewBranch( props ) {
20
64
  const {
21
65
  blocks,
22
66
  selectBlock,
23
- showAppender,
24
67
  showBlockMovers,
25
68
  showNestedBlocks,
26
- parentBlockClientId,
69
+ selectedClientIds,
27
70
  level = 1,
28
- terminatedLevels = [],
29
- path = [],
71
+ path = '',
30
72
  isBranchSelected = false,
31
- isLastOfBranch = false,
73
+ listPosition = 0,
74
+ fixedListWindow,
32
75
  } = props;
33
76
 
34
77
  const {
35
78
  expandedState,
36
- expand,
37
- collapse,
38
79
  draggedClientIds,
39
- selectedClientIds,
80
+ __experimentalPersistentListViewFeatures,
40
81
  } = useListViewContext();
41
82
 
42
- const isTreeRoot = ! parentBlockClientId;
43
83
  const filteredBlocks = compact( blocks );
44
- const itemHasAppender = ( parentClientId ) =>
45
- showAppender &&
46
- ! isTreeRoot &&
47
- isClientIdSelected( parentClientId, selectedClientIds );
48
- const hasAppender = itemHasAppender( parentBlockClientId );
49
- // Add +1 to the rowCount to take the block appender into account.
50
84
  const blockCount = filteredBlocks.length;
51
- const rowCount = hasAppender ? blockCount + 1 : blockCount;
52
- const appenderPosition = rowCount;
85
+ let nextPosition = listPosition;
53
86
 
54
87
  return (
55
88
  <>
56
- { map( filteredBlocks, ( block, index ) => {
89
+ { filteredBlocks.map( ( block, index ) => {
57
90
  const { clientId, innerBlocks } = block;
91
+
92
+ if ( index > 0 ) {
93
+ nextPosition += countBlocks(
94
+ filteredBlocks[ index - 1 ],
95
+ expandedState,
96
+ draggedClientIds
97
+ );
98
+ }
99
+
100
+ const usesWindowing = __experimentalPersistentListViewFeatures;
101
+
102
+ const { itemInView } = fixedListWindow;
103
+
104
+ const blockInView =
105
+ ! usesWindowing || itemInView( nextPosition );
106
+
58
107
  const position = index + 1;
59
- const isLastRowAtLevel = rowCount === position;
60
- const updatedTerminatedLevels = isLastRowAtLevel
61
- ? [ ...terminatedLevels, level ]
62
- : terminatedLevels;
63
- const updatedPath = [ ...path, position ];
108
+ const updatedPath =
109
+ path.length > 0
110
+ ? `${ path }_${ position }`
111
+ : `${ position }`;
64
112
  const hasNestedBlocks =
65
113
  showNestedBlocks && !! innerBlocks && !! innerBlocks.length;
66
- const hasNestedAppender = itemHasAppender( clientId );
67
- const hasNestedBranch = hasNestedBlocks || hasNestedAppender;
68
-
69
- const isSelected = isClientIdSelected(
70
- clientId,
71
- selectedClientIds
72
- );
73
- const isSelectedBranch =
74
- isBranchSelected || ( isSelected && hasNestedBranch );
75
114
 
76
- // Logic needed to target the last item of a selected branch which might be deeply nested.
77
- // This is currently only needed for styling purposes. See: `.is-last-of-selected-branch`.
78
- const isLastBlock = index === blockCount - 1;
79
- const isLast = isSelected || ( isLastOfBranch && isLastBlock );
80
- const isLastOfSelectedBranch =
81
- isLastOfBranch && ! hasNestedBranch && isLastBlock;
82
-
83
- const isExpanded = hasNestedBranch
115
+ const isExpanded = hasNestedBlocks
84
116
  ? expandedState[ clientId ] ?? true
85
117
  : undefined;
86
118
 
87
- const selectBlockWithClientId = ( event ) => {
88
- event.stopPropagation();
89
- selectBlock( clientId );
90
- };
119
+ const isDragged = !! draggedClientIds?.includes( clientId );
91
120
 
92
- const toggleExpanded = ( event ) => {
93
- event.stopPropagation();
94
- if ( isExpanded === true ) {
95
- collapse( clientId );
96
- } else if ( isExpanded === false ) {
97
- expand( clientId );
98
- }
99
- };
121
+ const showBlock = isDragged || blockInView;
100
122
 
101
123
  // Make updates to the selected or dragged blocks synchronous,
102
124
  // but asynchronous for any other block.
103
- const isDragged = !! draggedClientIds?.includes( clientId );
104
-
125
+ const isSelected = isClientIdSelected(
126
+ clientId,
127
+ selectedClientIds
128
+ );
129
+ const isSelectedBranch =
130
+ isBranchSelected || ( isSelected && hasNestedBlocks );
105
131
  return (
106
132
  <AsyncModeProvider key={ clientId } value={ ! isSelected }>
107
- <ListViewBlock
108
- block={ block }
109
- onClick={ selectBlockWithClientId }
110
- onToggleExpanded={ toggleExpanded }
111
- isDragged={ isDragged }
112
- isSelected={ isSelected }
113
- isBranchSelected={ isSelectedBranch }
114
- isLastOfSelectedBranch={ isLastOfSelectedBranch }
115
- level={ level }
116
- position={ position }
117
- rowCount={ rowCount }
118
- siblingBlockCount={ blockCount }
119
- showBlockMovers={ showBlockMovers }
120
- terminatedLevels={ terminatedLevels }
121
- path={ updatedPath }
122
- isExpanded={ isExpanded }
123
- />
124
- { hasNestedBranch && isExpanded && ! isDragged && (
133
+ { showBlock && (
134
+ <ListViewBlock
135
+ block={ block }
136
+ selectBlock={ selectBlock }
137
+ isSelected={ isSelected }
138
+ isBranchSelected={ isSelectedBranch }
139
+ isDragged={ isDragged }
140
+ level={ level }
141
+ position={ position }
142
+ rowCount={ blockCount }
143
+ siblingBlockCount={ blockCount }
144
+ showBlockMovers={ showBlockMovers }
145
+ path={ updatedPath }
146
+ isExpanded={ isExpanded }
147
+ listPosition={ nextPosition }
148
+ />
149
+ ) }
150
+ { ! showBlock && (
151
+ <tr>
152
+ <td className="block-editor-list-view-placeholder" />
153
+ </tr>
154
+ ) }
155
+ { hasNestedBlocks && isExpanded && ! isDragged && (
125
156
  <ListViewBranch
126
157
  blocks={ innerBlocks }
127
158
  selectBlock={ selectBlock }
128
- isBranchSelected={ isSelectedBranch }
129
- isLastOfBranch={ isLast }
130
- showAppender={ showAppender }
131
159
  showBlockMovers={ showBlockMovers }
132
160
  showNestedBlocks={ showNestedBlocks }
133
- parentBlockClientId={ clientId }
134
161
  level={ level + 1 }
135
- terminatedLevels={ updatedTerminatedLevels }
136
162
  path={ updatedPath }
163
+ listPosition={ nextPosition + 1 }
164
+ fixedListWindow={ fixedListWindow }
165
+ isBranchSelected={ isSelectedBranch }
166
+ selectedClientIds={ selectedClientIds }
137
167
  />
138
168
  ) }
139
169
  </AsyncModeProvider>
140
170
  );
141
171
  } ) }
142
- { hasAppender && (
143
- <ListViewAppender
144
- parentBlockClientId={ parentBlockClientId }
145
- position={ rowCount }
146
- rowCount={ appenderPosition }
147
- level={ level }
148
- terminatedLevels={ terminatedLevels }
149
- path={ [ ...path, appenderPosition ] }
150
- />
151
- ) }
152
172
  </>
153
173
  );
154
174
  }
@@ -156,3 +176,5 @@ export default function ListViewBranch( props ) {
156
176
  ListViewBranch.defaultProps = {
157
177
  selectBlock: () => {},
158
178
  };
179
+
180
+ export default memo( ListViewBranch );
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
-
5
- import { useMergeRefs } from '@wordpress/compose';
4
+ import {
5
+ useMergeRefs,
6
+ __experimentalUseFixedWindowList as useFixedWindowList,
7
+ } from '@wordpress/compose';
6
8
  import { __experimentalTreeGrid as TreeGrid } from '@wordpress/components';
7
- import { AsyncModeProvider, useDispatch } from '@wordpress/data';
9
+ import { AsyncModeProvider, useDispatch, useSelect } from '@wordpress/data';
8
10
  import {
9
11
  useCallback,
10
12
  useEffect,
@@ -46,32 +48,46 @@ const expanded = ( state, action ) => {
46
48
  * @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
47
49
  * @param {Function} props.onSelect Block selection callback.
48
50
  * @param {boolean} props.showNestedBlocks Flag to enable displaying nested blocks.
49
- * @param {boolean} props.showOnlyCurrentHierarchy Flag to limit the list to the current hierarchy of blocks.
51
+ * @param {boolean} props.showBlockMovers Flag to enable block movers
50
52
  * @param {boolean} props.__experimentalFeatures Flag to enable experimental features.
51
53
  * @param {boolean} props.__experimentalPersistentListViewFeatures Flag to enable features for the Persistent List View experiment.
54
+ * @param {boolean} props.__experimentalHideContainerBlockActions Flag to hide actions of top level blocks (like core/widget-area)
52
55
  * @param {Object} ref Forwarded ref
53
56
  */
54
57
  function ListView(
55
58
  {
56
59
  blocks,
57
- showOnlyCurrentHierarchy,
58
60
  onSelect = noop,
59
61
  __experimentalFeatures,
60
62
  __experimentalPersistentListViewFeatures,
63
+ __experimentalHideContainerBlockActions,
64
+ showNestedBlocks,
65
+ showBlockMovers,
61
66
  ...props
62
67
  },
63
68
  ref
64
69
  ) {
65
70
  const {
66
71
  clientIdsTree,
67
- selectedClientIds,
68
72
  draggedClientIds,
69
- } = useListViewClientIds(
70
- blocks,
71
- showOnlyCurrentHierarchy,
72
- __experimentalPersistentListViewFeatures
73
- );
73
+ selectedClientIds,
74
+ } = useListViewClientIds( blocks );
74
75
  const { selectBlock } = useDispatch( blockEditorStore );
76
+ const { visibleBlockCount } = useSelect(
77
+ ( select ) => {
78
+ const { getGlobalBlockCount, getClientIdsOfDescendants } = select(
79
+ blockEditorStore
80
+ );
81
+ const draggedBlockCount =
82
+ draggedClientIds?.length > 0
83
+ ? getClientIdsOfDescendants( draggedClientIds ).length + 1
84
+ : 0;
85
+ return {
86
+ visibleBlockCount: getGlobalBlockCount() - draggedBlockCount,
87
+ };
88
+ },
89
+ [ draggedClientIds ]
90
+ );
75
91
  const selectEditorBlock = useCallback(
76
92
  ( clientId ) => {
77
93
  selectBlock( clientId );
@@ -90,6 +106,19 @@ function ListView(
90
106
  isMounted.current = true;
91
107
  }, [] );
92
108
 
109
+ // List View renders a fixed number of items and relies on each having a fixed item height of 36px.
110
+ // If this value changes, we should also change the itemHeight value set in useFixedWindowList.
111
+ // See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.
112
+ const [ fixedListWindow ] = useFixedWindowList(
113
+ elementRef,
114
+ 36,
115
+ visibleBlockCount,
116
+ {
117
+ useWindowing: __experimentalPersistentListViewFeatures,
118
+ windowOverscan: 40,
119
+ }
120
+ );
121
+
93
122
  const expand = useCallback(
94
123
  ( clientId ) => {
95
124
  if ( ! clientId ) {
@@ -108,20 +137,26 @@ function ListView(
108
137
  },
109
138
  [ setExpandedState ]
110
139
  );
111
- const expandRow = ( row ) => {
112
- expand( row?.dataset?.block );
113
- };
114
- const collapseRow = ( row ) => {
115
- collapse( row?.dataset?.block );
116
- };
140
+ const expandRow = useCallback(
141
+ ( row ) => {
142
+ expand( row?.dataset?.block );
143
+ },
144
+ [ expand ]
145
+ );
146
+ const collapseRow = useCallback(
147
+ ( row ) => {
148
+ collapse( row?.dataset?.block );
149
+ },
150
+ [ collapse ]
151
+ );
117
152
 
118
153
  const contextValue = useMemo(
119
154
  () => ( {
120
155
  __experimentalFeatures,
121
156
  __experimentalPersistentListViewFeatures,
157
+ __experimentalHideContainerBlockActions,
122
158
  isTreeGridMounted: isMounted.current,
123
159
  draggedClientIds,
124
- selectedClientIds,
125
160
  expandedState,
126
161
  expand,
127
162
  collapse,
@@ -129,9 +164,9 @@ function ListView(
129
164
  [
130
165
  __experimentalFeatures,
131
166
  __experimentalPersistentListViewFeatures,
167
+ __experimentalHideContainerBlockActions,
132
168
  isMounted.current,
133
169
  draggedClientIds,
134
- selectedClientIds,
135
170
  expandedState,
136
171
  expand,
137
172
  collapse,
@@ -155,6 +190,10 @@ function ListView(
155
190
  <ListViewBranch
156
191
  blocks={ clientIdsTree }
157
192
  selectBlock={ selectEditorBlock }
193
+ showNestedBlocks={ showNestedBlocks }
194
+ showBlockMovers={ showBlockMovers }
195
+ fixedListWindow={ fixedListWindow }
196
+ selectedClientIds={ selectedClientIds }
158
197
  { ...props }
159
198
  />
160
199
  </ListViewContext.Provider>
@@ -30,7 +30,7 @@ export default function ListViewLeaf( {
30
30
  isSelected,
31
31
  adjustScrolling: false,
32
32
  enableAnimation: true,
33
- triggerAnimationOnChange: path.join( '_' ),
33
+ triggerAnimationOnChange: path,
34
34
  } );
35
35
 
36
36
  return (
@@ -57,14 +57,14 @@
57
57
  &.is-branch-selected:not(.is-selected) .block-editor-list-view-block-contents {
58
58
  border-radius: 0;
59
59
  }
60
- &.is-branch-selected.is-last-of-selected-branch .block-editor-list-view-block-contents {
61
- border-radius: 0 0 2px 2px;
62
- }
63
60
 
64
61
  &.is-dragging {
65
62
  display: none;
66
63
  }
67
64
 
65
+ // List View renders a fixed number of items and relies on each item having a fixed height of 36px.
66
+ // If this value changes, we should also change the itemHeight value set in useFixedWindowList.
67
+ // See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.
68
68
  .block-editor-list-view-block-contents {
69
69
  display: flex;
70
70
  align-items: center;
@@ -115,6 +115,11 @@
115
115
  }
116
116
  }
117
117
  }
118
+ // Fix focus styling width when one row has fewer cells.
119
+ &.has-single-cell .block-editor-list-view-block-contents:focus::after {
120
+ right: 0;
121
+ }
122
+
118
123
  .block-editor-list-view-block__menu:focus {
119
124
  box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
120
125
  z-index: 1;
@@ -355,3 +360,9 @@ $block-navigation-max-indent: 8;
355
360
  box-shadow: none;
356
361
  }
357
362
 
363
+ .block-editor-list-view-placeholder {
364
+ padding: 0;
365
+ margin: 0;
366
+ height: 36px;
367
+ }
368
+
@@ -7,82 +7,23 @@ import { useSelect } from '@wordpress/data';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
- import { isClientIdSelected } from './utils';
11
10
  import { store as blockEditorStore } from '../../store';
12
11
 
13
- const useListViewClientIdsTree = (
14
- blocks,
15
- selectedClientIds,
16
- showOnlyCurrentHierarchy
17
- ) =>
18
- useSelect(
12
+ export default function useListViewClientIds( blocks ) {
13
+ return useSelect(
19
14
  ( select ) => {
20
15
  const {
21
- getBlockHierarchyRootClientId,
22
- __unstableGetClientIdsTree,
23
- __unstableGetClientIdWithClientIdsTree,
24
- } = select( blockEditorStore );
25
-
26
- if ( blocks ) {
27
- return blocks;
28
- }
29
-
30
- const isSingleBlockSelected =
31
- selectedClientIds && ! Array.isArray( selectedClientIds );
32
- if ( ! showOnlyCurrentHierarchy || ! isSingleBlockSelected ) {
33
- return __unstableGetClientIdsTree();
34
- }
35
-
36
- const rootBlock = __unstableGetClientIdWithClientIdsTree(
37
- getBlockHierarchyRootClientId( selectedClientIds )
38
- );
39
- if ( ! rootBlock ) {
40
- return __unstableGetClientIdsTree();
41
- }
42
-
43
- const hasHierarchy =
44
- ! isClientIdSelected( rootBlock.clientId, selectedClientIds ) ||
45
- ( rootBlock.innerBlocks && rootBlock.innerBlocks.length !== 0 );
46
- if ( hasHierarchy ) {
47
- return [ rootBlock ];
48
- }
49
-
50
- return __unstableGetClientIdsTree();
51
- },
52
- [ blocks, selectedClientIds, showOnlyCurrentHierarchy ]
53
- );
54
-
55
- export default function useListViewClientIds(
56
- blocks,
57
- showOnlyCurrentHierarchy,
58
- __experimentalPersistentListViewFeatures
59
- ) {
60
- const { selectedClientIds, draggedClientIds } = useSelect(
61
- ( select ) => {
62
- const {
63
- getSelectedBlockClientId,
64
- getSelectedBlockClientIds,
65
16
  getDraggedBlockClientIds,
17
+ getSelectedBlockClientIds,
18
+ __unstableGetClientIdsTree,
66
19
  } = select( blockEditorStore );
67
20
 
68
- if ( __experimentalPersistentListViewFeatures ) {
69
- return {
70
- selectedClientIds: getSelectedBlockClientIds(),
71
- draggedClientIds: getDraggedBlockClientIds(),
72
- };
73
- }
74
-
75
21
  return {
76
- selectedClientIds: getSelectedBlockClientId(),
22
+ selectedClientIds: getSelectedBlockClientIds(),
77
23
  draggedClientIds: getDraggedBlockClientIds(),
24
+ clientIdsTree: blocks ? blocks : __unstableGetClientIdsTree(),
78
25
  };
79
26
  },
80
- [ __experimentalPersistentListViewFeatures ]
81
- );
82
- const clientIdsTree = useListViewClientIdsTree(
83
- blocks,
84
- selectedClientIds,
85
- showOnlyCurrentHierarchy
27
+ [ blocks ]
86
28
  );
87
- return { clientIdsTree, selectedClientIds, draggedClientIds };
88
29
  }
@@ -58,6 +58,7 @@ const EmbedHandlerPicker = forwardRef( ( {}, ref ) => {
58
58
  ref={ pickerRef }
59
59
  options={ pickerOptions }
60
60
  onChange={ onPickerSelect }
61
+ testID="embed-handler-picker"
61
62
  hideCancelButton
62
63
  leftAlign
63
64
  />
@@ -1,7 +1,15 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { getActiveFormat, getActiveObject } from '@wordpress/rich-text';
4
+ import {
5
+ getActiveFormat,
6
+ getActiveObject,
7
+ isCollapsed,
8
+ } from '@wordpress/rich-text';
9
+ /**
10
+ * External dependencies
11
+ */
12
+ import { find } from 'lodash';
5
13
 
6
14
  export default function FormatEdit( {
7
15
  formatTypes,
@@ -18,11 +26,37 @@ export default function FormatEdit( {
18
26
  }
19
27
 
20
28
  const activeFormat = getActiveFormat( value, name );
21
- const isActive = activeFormat !== undefined;
29
+ let isActive = activeFormat !== undefined;
22
30
  const activeObject = getActiveObject( value );
23
31
  const isObjectActive =
24
32
  activeObject !== undefined && activeObject.type === name;
25
33
 
34
+ // Edge case: un-collapsed link formats.
35
+ // If there is a missing link format at either end of the selection
36
+ // then we shouldn't show the Edit UI because the selection has exceeded
37
+ // the bounds of the link format.
38
+ // Also if the format objects don't match then we're dealing with two separate
39
+ // links so we should not allow the link to be modified over the top.
40
+ if ( name === 'core/link' && ! isCollapsed( value ) ) {
41
+ const formats = value.formats;
42
+
43
+ const linkFormatAtStart = find( formats[ value.start ], {
44
+ type: 'core/link',
45
+ } );
46
+
47
+ const linkFormatAtEnd = find( formats[ value.end - 1 ], {
48
+ type: 'core/link',
49
+ } );
50
+
51
+ if (
52
+ ! linkFormatAtStart ||
53
+ ! linkFormatAtEnd ||
54
+ linkFormatAtStart !== linkFormatAtEnd
55
+ ) {
56
+ isActive = false;
57
+ }
58
+ }
59
+
26
60
  return (
27
61
  <Edit
28
62
  key={ name }
@@ -51,6 +51,9 @@ const FormatToolbar = () => {
51
51
  toggleProps.className,
52
52
  { 'is-pressed': hasActive }
53
53
  ),
54
+ describedBy: __(
55
+ 'Displays more block tools'
56
+ ),
54
57
  } }
55
58
  controls={ orderBy(
56
59
  fills.map( ( [ { props } ] ) => props ),
@@ -60,7 +60,10 @@ class URLInput extends Component {
60
60
 
61
61
  componentDidUpdate( prevProps ) {
62
62
  const { showSuggestions, selectedSuggestion } = this.state;
63
- const { value } = this.props;
63
+ const {
64
+ value,
65
+ __experimentalShowInitialSuggestions = false,
66
+ } = this.props;
64
67
 
65
68
  // only have to worry about scrolling selected suggestion into view
66
69
  // when already expanded
@@ -84,12 +87,19 @@ class URLInput extends Component {
84
87
  }, 100 );
85
88
  }
86
89
 
87
- // Only attempt an update on suggestions if the input value has actually changed.
90
+ // Update suggestions when the value changes
88
91
  if (
89
92
  prevProps.value !== value &&
90
- this.shouldShowInitialSuggestions()
93
+ ! this.props.disableSuggestions &&
94
+ ! this.isUpdatingSuggestions
91
95
  ) {
92
- this.updateSuggestions();
96
+ if ( value?.length ) {
97
+ // If the new value is not empty we need to update with suggestions for it
98
+ this.updateSuggestions( value );
99
+ } else if ( __experimentalShowInitialSuggestions ) {
100
+ // If the new value is empty and we can show initial suggestions, then show initial suggestions
101
+ this.updateSuggestions();
102
+ }
93
103
  }
94
104
  }
95
105