@wordpress/block-editor 12.11.1 → 12.12.2-next.f8d8eceb.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 (453) hide show
  1. package/CHANGELOG.md +14 -10
  2. package/README.md +35 -3
  3. package/build/components/block-alignment-control/use-available-alignments.js +30 -28
  4. package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
  5. package/build/components/block-controls/hook.js +4 -1
  6. package/build/components/block-controls/hook.js.map +1 -1
  7. package/build/components/block-list/block-outline.native.js +1 -1
  8. package/build/components/block-list/block-outline.native.js.map +1 -1
  9. package/build/components/block-list/block.js +2 -0
  10. package/build/components/block-list/block.js.map +1 -1
  11. package/build/components/block-list/block.native.js +4 -4
  12. package/build/components/block-list/block.native.js.map +1 -1
  13. package/build/components/block-list/layout.js +2 -3
  14. package/build/components/block-list/layout.js.map +1 -1
  15. package/build/components/block-preview/index.js +4 -1
  16. package/build/components/block-preview/index.js.map +1 -1
  17. package/build/components/block-styles/index.js +1 -2
  18. package/build/components/block-styles/index.js.map +1 -1
  19. package/build/components/block-switcher/pattern-transformations-menu.js +2 -4
  20. package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
  21. package/build/components/block-tools/block-contextual-toolbar.js +1 -0
  22. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  23. package/build/components/border-radius-control/index.js +3 -2
  24. package/build/components/border-radius-control/index.js.map +1 -1
  25. package/build/components/color-palette/with-color-context.js +6 -6
  26. package/build/components/color-palette/with-color-context.js.map +1 -1
  27. package/build/components/colors/with-colors.js +2 -8
  28. package/build/components/colors/with-colors.js.map +1 -1
  29. package/build/components/colors-gradients/control.js +6 -7
  30. package/build/components/colors-gradients/control.js.map +1 -1
  31. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -13
  32. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  33. package/build/components/dimensions-tool/index.js +22 -22
  34. package/build/components/dimensions-tool/index.js.map +1 -1
  35. package/build/components/dimensions-tool/scale-tool.js +1 -1
  36. package/build/components/dimensions-tool/scale-tool.js.map +1 -1
  37. package/build/components/font-family/index.js +2 -3
  38. package/build/components/font-family/index.js.map +1 -1
  39. package/build/components/font-sizes/font-size-picker.js +3 -5
  40. package/build/components/font-sizes/font-size-picker.js.map +1 -1
  41. package/build/components/font-sizes/with-font-sizes.js +3 -4
  42. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  43. package/build/components/global-styles/filters-panel.js +7 -8
  44. package/build/components/global-styles/filters-panel.js.map +1 -1
  45. package/build/components/global-styles/image-settings-panel.js +2 -2
  46. package/build/components/global-styles/image-settings-panel.js.map +1 -1
  47. package/build/components/global-styles/typography-panel.js +1 -1
  48. package/build/components/global-styles/typography-panel.js.map +1 -1
  49. package/build/components/gradients/use-gradient.js +2 -5
  50. package/build/components/gradients/use-gradient.js.map +1 -1
  51. package/build/components/height-control/index.js +93 -5
  52. package/build/components/height-control/index.js.map +1 -1
  53. package/build/components/iframe/index.js +9 -1
  54. package/build/components/iframe/index.js.map +1 -1
  55. package/build/components/image-editor/aspect-ratio-dropdown.js +0 -6
  56. package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  57. package/build/components/index.js +9 -2
  58. package/build/components/index.js.map +1 -1
  59. package/build/components/index.native.js +17 -2
  60. package/build/components/index.native.js.map +1 -1
  61. package/build/components/inner-blocks/index.js +2 -2
  62. package/build/components/inner-blocks/index.js.map +1 -1
  63. package/build/components/letter-spacing-control/index.js +3 -3
  64. package/build/components/letter-spacing-control/index.js.map +1 -1
  65. package/build/components/link-control/link-preview.js +5 -2
  66. package/build/components/link-control/link-preview.js.map +1 -1
  67. package/build/components/link-control/search-item.js +11 -0
  68. package/build/components/link-control/search-item.js.map +1 -1
  69. package/build/components/link-control/search-results.js +2 -1
  70. package/build/components/link-control/search-results.js.map +1 -1
  71. package/build/components/link-control/use-internal-value.js +14 -8
  72. package/build/components/link-control/use-internal-value.js.map +1 -1
  73. package/build/components/link-control/use-search-handler.js +10 -5
  74. package/build/components/link-control/use-search-handler.js.map +1 -1
  75. package/build/components/list-view/index.js +6 -5
  76. package/build/components/list-view/index.js.map +1 -1
  77. package/build/components/media-replace-flow/index.js +2 -4
  78. package/build/components/media-replace-flow/index.js.map +1 -1
  79. package/build/components/provider/use-block-sync.js +2 -2
  80. package/build/components/provider/use-block-sync.js.map +1 -1
  81. package/build/components/rich-text/index.js +1 -1
  82. package/build/components/rich-text/index.js.map +1 -1
  83. package/build/components/rich-text/index.native.js +14 -3
  84. package/build/components/rich-text/index.native.js.map +1 -1
  85. package/build/components/rich-text/use-delete.js +1 -1
  86. package/build/components/rich-text/use-delete.js.map +1 -1
  87. package/build/components/rich-text/use-paste-handler.js +25 -22
  88. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  89. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -3
  90. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  91. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +91 -3
  92. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  93. package/build/components/tool-selector/index.js +1 -2
  94. package/build/components/tool-selector/index.js.map +1 -1
  95. package/build/components/unit-control/index.js +3 -3
  96. package/build/components/unit-control/index.js.map +1 -1
  97. package/build/components/use-block-commands/index.js +96 -47
  98. package/build/components/use-block-commands/index.js.map +1 -1
  99. package/build/components/use-settings/index.js +212 -0
  100. package/build/components/use-settings/index.js.map +1 -0
  101. package/build/components/writing-flow/use-arrow-nav.js +4 -0
  102. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  103. package/build/hooks/align.js +51 -35
  104. package/build/hooks/align.js.map +1 -1
  105. package/build/hooks/anchor.js +37 -32
  106. package/build/hooks/anchor.js.map +1 -1
  107. package/build/hooks/background.js +4 -4
  108. package/build/hooks/background.js.map +1 -1
  109. package/build/hooks/block-rename-ui.js +5 -5
  110. package/build/hooks/block-rename-ui.js.map +1 -1
  111. package/build/hooks/{metadata-name.js → block-renaming.js} +3 -7
  112. package/build/hooks/block-renaming.js.map +1 -0
  113. package/build/hooks/color.js +2 -4
  114. package/build/hooks/color.js.map +1 -1
  115. package/build/hooks/custom-class-name.js +28 -21
  116. package/build/hooks/custom-class-name.js.map +1 -1
  117. package/build/hooks/duotone.js +33 -8
  118. package/build/hooks/duotone.js.map +1 -1
  119. package/build/hooks/font-size.js +4 -4
  120. package/build/hooks/font-size.js.map +1 -1
  121. package/build/hooks/index.js +1 -1
  122. package/build/hooks/index.js.map +1 -1
  123. package/build/hooks/layout.js +16 -17
  124. package/build/hooks/layout.js.map +1 -1
  125. package/build/hooks/line-height.js +3 -3
  126. package/build/hooks/line-height.js.map +1 -1
  127. package/build/hooks/metadata.js +6 -27
  128. package/build/hooks/metadata.js.map +1 -1
  129. package/build/hooks/position.js +2 -3
  130. package/build/hooks/position.js.map +1 -1
  131. package/build/hooks/use-color-props.js +3 -11
  132. package/build/hooks/use-color-props.js.map +1 -1
  133. package/build/hooks/utils.js +2 -43
  134. package/build/hooks/utils.js.map +1 -1
  135. package/build/layouts/constrained.js +3 -3
  136. package/build/layouts/constrained.js.map +1 -1
  137. package/build/layouts/grid.js +25 -3
  138. package/build/layouts/grid.js.map +1 -1
  139. package/build/layouts/utils.js +1 -1
  140. package/build/layouts/utils.js.map +1 -1
  141. package/build/lock-unlock.js +1 -1
  142. package/build/lock-unlock.js.map +1 -1
  143. package/build/store/actions.js +13 -5
  144. package/build/store/actions.js.map +1 -1
  145. package/build/utils/object.js +4 -1
  146. package/build/utils/object.js.map +1 -1
  147. package/build/utils/parse-css-unit-to-px.js +20 -0
  148. package/build/utils/parse-css-unit-to-px.js.map +1 -1
  149. package/build/utils/pasting.js +1 -1
  150. package/build/utils/pasting.js.map +1 -1
  151. package/build/utils/transform-styles/index.js +19 -24
  152. package/build/utils/transform-styles/index.js.map +1 -1
  153. package/build-module/components/block-alignment-control/use-available-alignments.js +30 -28
  154. package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
  155. package/build-module/components/block-controls/hook.js +4 -1
  156. package/build-module/components/block-controls/hook.js.map +1 -1
  157. package/build-module/components/block-list/block-outline.native.js +1 -1
  158. package/build-module/components/block-list/block-outline.native.js.map +1 -1
  159. package/build-module/components/block-list/block.js +2 -0
  160. package/build-module/components/block-list/block.js.map +1 -1
  161. package/build-module/components/block-list/block.native.js +4 -4
  162. package/build-module/components/block-list/block.native.js.map +1 -1
  163. package/build-module/components/block-list/layout.js +2 -2
  164. package/build-module/components/block-list/layout.js.map +1 -1
  165. package/build-module/components/block-preview/index.js +4 -1
  166. package/build-module/components/block-preview/index.js.map +1 -1
  167. package/build-module/components/block-styles/index.js +1 -2
  168. package/build-module/components/block-styles/index.js.map +1 -1
  169. package/build-module/components/block-switcher/pattern-transformations-menu.js +2 -4
  170. package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
  171. package/build-module/components/block-tools/block-contextual-toolbar.js +1 -0
  172. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  173. package/build-module/components/border-radius-control/index.js +3 -2
  174. package/build-module/components/border-radius-control/index.js.map +1 -1
  175. package/build-module/components/color-palette/with-color-context.js +6 -5
  176. package/build-module/components/color-palette/with-color-context.js.map +1 -1
  177. package/build-module/components/colors/with-colors.js +2 -7
  178. package/build-module/components/colors/with-colors.js.map +1 -1
  179. package/build-module/components/colors-gradients/control.js +6 -7
  180. package/build-module/components/colors-gradients/control.js.map +1 -1
  181. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -12
  182. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  183. package/build-module/components/dimensions-tool/index.js +22 -22
  184. package/build-module/components/dimensions-tool/index.js.map +1 -1
  185. package/build-module/components/dimensions-tool/scale-tool.js +1 -1
  186. package/build-module/components/dimensions-tool/scale-tool.js.map +1 -1
  187. package/build-module/components/font-family/index.js +2 -2
  188. package/build-module/components/font-family/index.js.map +1 -1
  189. package/build-module/components/font-sizes/font-size-picker.js +3 -4
  190. package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
  191. package/build-module/components/font-sizes/with-font-sizes.js +3 -3
  192. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  193. package/build-module/components/global-styles/filters-panel.js +7 -8
  194. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  195. package/build-module/components/global-styles/image-settings-panel.js +2 -2
  196. package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
  197. package/build-module/components/global-styles/typography-panel.js +1 -1
  198. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  199. package/build-module/components/gradients/use-gradient.js +2 -4
  200. package/build-module/components/gradients/use-gradient.js.map +1 -1
  201. package/build-module/components/height-control/index.js +93 -4
  202. package/build-module/components/height-control/index.js.map +1 -1
  203. package/build-module/components/iframe/index.js +9 -1
  204. package/build-module/components/iframe/index.js.map +1 -1
  205. package/build-module/components/image-editor/aspect-ratio-dropdown.js +0 -6
  206. package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  207. package/build-module/components/index.js +1 -1
  208. package/build-module/components/index.js.map +1 -1
  209. package/build-module/components/index.native.js +2 -1
  210. package/build-module/components/index.native.js.map +1 -1
  211. package/build-module/components/inner-blocks/index.js +2 -2
  212. package/build-module/components/inner-blocks/index.js.map +1 -1
  213. package/build-module/components/letter-spacing-control/index.js +3 -2
  214. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  215. package/build-module/components/link-control/link-preview.js +6 -3
  216. package/build-module/components/link-control/link-preview.js.map +1 -1
  217. package/build-module/components/link-control/search-item.js +12 -1
  218. package/build-module/components/link-control/search-item.js.map +1 -1
  219. package/build-module/components/link-control/search-results.js +2 -1
  220. package/build-module/components/link-control/search-results.js.map +1 -1
  221. package/build-module/components/link-control/use-internal-value.js +14 -9
  222. package/build-module/components/link-control/use-internal-value.js.map +1 -1
  223. package/build-module/components/link-control/use-search-handler.js +10 -5
  224. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  225. package/build-module/components/list-view/index.js +7 -6
  226. package/build-module/components/list-view/index.js.map +1 -1
  227. package/build-module/components/media-replace-flow/index.js +3 -5
  228. package/build-module/components/media-replace-flow/index.js.map +1 -1
  229. package/build-module/components/provider/use-block-sync.js +2 -2
  230. package/build-module/components/provider/use-block-sync.js.map +1 -1
  231. package/build-module/components/rich-text/index.js +1 -1
  232. package/build-module/components/rich-text/index.js.map +1 -1
  233. package/build-module/components/rich-text/index.native.js +15 -4
  234. package/build-module/components/rich-text/index.native.js.map +1 -1
  235. package/build-module/components/rich-text/use-delete.js +1 -1
  236. package/build-module/components/rich-text/use-delete.js.map +1 -1
  237. package/build-module/components/rich-text/use-paste-handler.js +25 -22
  238. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  239. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -2
  240. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  241. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +91 -2
  242. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  243. package/build-module/components/tool-selector/index.js +1 -2
  244. package/build-module/components/tool-selector/index.js.map +1 -1
  245. package/build-module/components/unit-control/index.js +3 -2
  246. package/build-module/components/unit-control/index.js.map +1 -1
  247. package/build-module/components/use-block-commands/index.js +95 -47
  248. package/build-module/components/use-block-commands/index.js.map +1 -1
  249. package/build-module/components/use-settings/index.js +203 -0
  250. package/build-module/components/use-settings/index.js.map +1 -0
  251. package/build-module/components/writing-flow/use-arrow-nav.js +4 -0
  252. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  253. package/build-module/hooks/align.js +51 -35
  254. package/build-module/hooks/align.js.map +1 -1
  255. package/build-module/hooks/anchor.js +37 -32
  256. package/build-module/hooks/anchor.js.map +1 -1
  257. package/build-module/hooks/background.js +4 -4
  258. package/build-module/hooks/background.js.map +1 -1
  259. package/build-module/hooks/block-rename-ui.js +6 -6
  260. package/build-module/hooks/block-rename-ui.js.map +1 -1
  261. package/build-module/hooks/{metadata-name.js → block-renaming.js} +3 -6
  262. package/build-module/hooks/block-renaming.js.map +1 -0
  263. package/build-module/hooks/color.js +2 -4
  264. package/build-module/hooks/color.js.map +1 -1
  265. package/build-module/hooks/custom-class-name.js +28 -21
  266. package/build-module/hooks/custom-class-name.js.map +1 -1
  267. package/build-module/hooks/duotone.js +34 -9
  268. package/build-module/hooks/duotone.js.map +1 -1
  269. package/build-module/hooks/font-size.js +4 -4
  270. package/build-module/hooks/font-size.js.map +1 -1
  271. package/build-module/hooks/index.js +1 -1
  272. package/build-module/hooks/index.js.map +1 -1
  273. package/build-module/hooks/layout.js +16 -17
  274. package/build-module/hooks/layout.js.map +1 -1
  275. package/build-module/hooks/line-height.js +3 -3
  276. package/build-module/hooks/line-height.js.map +1 -1
  277. package/build-module/hooks/metadata.js +6 -25
  278. package/build-module/hooks/metadata.js.map +1 -1
  279. package/build-module/hooks/position.js +2 -3
  280. package/build-module/hooks/position.js.map +1 -1
  281. package/build-module/hooks/use-color-props.js +3 -11
  282. package/build-module/hooks/use-color-props.js.map +1 -1
  283. package/build-module/hooks/utils.js +3 -44
  284. package/build-module/hooks/utils.js.map +1 -1
  285. package/build-module/layouts/constrained.js +3 -2
  286. package/build-module/layouts/constrained.js.map +1 -1
  287. package/build-module/layouts/grid.js +25 -3
  288. package/build-module/layouts/grid.js.map +1 -1
  289. package/build-module/layouts/utils.js +1 -1
  290. package/build-module/layouts/utils.js.map +1 -1
  291. package/build-module/lock-unlock.js +1 -1
  292. package/build-module/lock-unlock.js.map +1 -1
  293. package/build-module/store/actions.js +14 -6
  294. package/build-module/store/actions.js.map +1 -1
  295. package/build-module/utils/object.js +3 -1
  296. package/build-module/utils/object.js.map +1 -1
  297. package/build-module/utils/parse-css-unit-to-px.js +20 -0
  298. package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
  299. package/build-module/utils/pasting.js +1 -1
  300. package/build-module/utils/pasting.js.map +1 -1
  301. package/build-module/utils/transform-styles/index.js +20 -24
  302. package/build-module/utils/transform-styles/index.js.map +1 -1
  303. package/build-style/style-rtl.css +24 -12
  304. package/build-style/style.css +24 -12
  305. package/package.json +36 -34
  306. package/src/components/block-alignment-control/use-available-alignments.js +49 -34
  307. package/src/components/block-controls/hook.js +6 -3
  308. package/src/components/block-list/block-outline.native.js +1 -1
  309. package/src/components/block-list/block.js +2 -0
  310. package/src/components/block-list/block.native.js +4 -4
  311. package/src/components/block-list/layout.js +2 -2
  312. package/src/components/block-preview/index.js +7 -1
  313. package/src/components/block-styles/index.js +1 -4
  314. package/src/components/block-styles/style.scss +1 -1
  315. package/src/components/block-switcher/pattern-transformations-menu.js +1 -4
  316. package/src/components/block-switcher/style.scss +6 -0
  317. package/src/components/block-tools/block-contextual-toolbar.js +1 -0
  318. package/src/components/block-tools/style.scss +0 -1
  319. package/src/components/border-radius-control/index.js +3 -2
  320. package/src/components/color-palette/test/__snapshots__/control.js.snap +3 -1
  321. package/src/components/color-palette/with-color-context.js +9 -9
  322. package/src/components/colors/with-colors.js +6 -7
  323. package/src/components/colors-gradients/control.js +10 -7
  324. package/src/components/colors-gradients/style.scss +4 -2
  325. package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +29 -15
  326. package/src/components/dimensions-tool/index.js +25 -25
  327. package/src/components/dimensions-tool/scale-tool.js +1 -1
  328. package/src/components/font-family/index.js +2 -2
  329. package/src/components/font-sizes/font-size-picker.js +6 -4
  330. package/src/components/font-sizes/with-font-sizes.js +3 -5
  331. package/src/components/global-styles/filters-panel.js +9 -15
  332. package/src/components/global-styles/image-settings-panel.js +2 -2
  333. package/src/components/global-styles/typography-panel.js +1 -1
  334. package/src/components/gradients/use-gradient.js +10 -4
  335. package/src/components/height-control/index.js +53 -4
  336. package/src/components/iframe/index.js +8 -1
  337. package/src/components/image-editor/aspect-ratio-dropdown.js +0 -8
  338. package/src/components/index.js +1 -1
  339. package/src/components/index.native.js +2 -1
  340. package/src/components/inner-blocks/index.js +2 -2
  341. package/src/components/inserter/style.scss +9 -1
  342. package/src/components/letter-spacing-control/index.js +3 -2
  343. package/src/components/link-control/README.md +43 -0
  344. package/src/components/link-control/link-preview.js +11 -5
  345. package/src/components/link-control/search-item.js +14 -0
  346. package/src/components/link-control/search-results.js +1 -0
  347. package/src/components/link-control/style.scss +3 -3
  348. package/src/components/link-control/test/index.js +19 -0
  349. package/src/components/link-control/use-internal-value.js +14 -10
  350. package/src/components/link-control/use-search-handler.js +22 -15
  351. package/src/components/list-view/index.js +13 -3
  352. package/src/components/media-replace-flow/index.js +9 -14
  353. package/src/components/provider/test/use-block-sync.js +1 -1
  354. package/src/components/provider/use-block-sync.js +2 -2
  355. package/src/components/rich-text/index.js +1 -1
  356. package/src/components/rich-text/index.native.js +19 -3
  357. package/src/components/rich-text/use-delete.js +1 -1
  358. package/src/components/rich-text/use-paste-handler.js +27 -24
  359. package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +7 -5
  360. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +25 -2
  361. package/src/components/tool-selector/index.js +1 -1
  362. package/src/components/unit-control/index.js +3 -8
  363. package/src/components/use-block-commands/index.js +93 -47
  364. package/src/components/{use-setting → use-settings}/README.md +9 -10
  365. package/src/components/use-settings/index.js +272 -0
  366. package/src/components/{use-setting → use-settings}/test/index.js +47 -5
  367. package/src/components/writing-flow/use-arrow-nav.js +4 -0
  368. package/src/hooks/align.js +79 -54
  369. package/src/hooks/anchor.js +75 -65
  370. package/src/hooks/background.js +7 -9
  371. package/src/hooks/block-rename-ui.js +5 -14
  372. package/src/hooks/{metadata-name.js → block-renaming.js} +4 -7
  373. package/src/hooks/color.js +7 -4
  374. package/src/hooks/custom-class-name.js +36 -31
  375. package/src/hooks/duotone.js +51 -14
  376. package/src/hooks/font-size.js +4 -4
  377. package/src/hooks/index.js +1 -1
  378. package/src/hooks/layout.js +17 -17
  379. package/src/hooks/line-height.js +3 -3
  380. package/src/hooks/metadata.js +6 -38
  381. package/src/hooks/position.js +5 -3
  382. package/src/hooks/use-color-props.js +21 -14
  383. package/src/hooks/utils.js +90 -43
  384. package/src/layouts/constrained.js +3 -8
  385. package/src/layouts/grid.js +50 -2
  386. package/src/layouts/utils.js +2 -1
  387. package/src/lock-unlock.js +1 -1
  388. package/src/store/actions.js +25 -8
  389. package/src/utils/object.js +4 -1
  390. package/src/utils/parse-css-unit-to-px.js +20 -0
  391. package/src/utils/pasting.js +1 -4
  392. package/src/utils/test/__snapshots__/transform-styles.js.snap +103 -0
  393. package/src/utils/test/pasting.js +12 -19
  394. package/src/utils/test/transform-styles.js +217 -0
  395. package/src/utils/transform-styles/index.js +25 -25
  396. package/build/components/use-setting/index.js +0 -159
  397. package/build/components/use-setting/index.js.map +0 -1
  398. package/build/hooks/metadata-name.js.map +0 -1
  399. package/build/utils/transform-styles/ast/index.js +0 -21
  400. package/build/utils/transform-styles/ast/index.js.map +0 -1
  401. package/build/utils/transform-styles/ast/parse.js +0 -660
  402. package/build/utils/transform-styles/ast/parse.js.map +0 -1
  403. package/build/utils/transform-styles/ast/stringify/compiler.js +0 -52
  404. package/build/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
  405. package/build/utils/transform-styles/ast/stringify/compress.js +0 -178
  406. package/build/utils/transform-styles/ast/stringify/compress.js.map +0 -1
  407. package/build/utils/transform-styles/ast/stringify/identity.js +0 -207
  408. package/build/utils/transform-styles/ast/stringify/identity.js.map +0 -1
  409. package/build/utils/transform-styles/ast/stringify/index.js +0 -36
  410. package/build/utils/transform-styles/ast/stringify/index.js.map +0 -1
  411. package/build/utils/transform-styles/transforms/url-rewrite.js +0 -130
  412. package/build/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
  413. package/build/utils/transform-styles/transforms/wrap.js +0 -59
  414. package/build/utils/transform-styles/transforms/wrap.js.map +0 -1
  415. package/build/utils/transform-styles/traverse.js +0 -37
  416. package/build/utils/transform-styles/traverse.js.map +0 -1
  417. package/build-module/components/use-setting/index.js +0 -152
  418. package/build-module/components/use-setting/index.js.map +0 -1
  419. package/build-module/hooks/metadata-name.js.map +0 -1
  420. package/build-module/utils/transform-styles/ast/index.js +0 -6
  421. package/build-module/utils/transform-styles/ast/index.js.map +0 -1
  422. package/build-module/utils/transform-styles/ast/parse.js +0 -654
  423. package/build-module/utils/transform-styles/ast/parse.js.map +0 -1
  424. package/build-module/utils/transform-styles/ast/stringify/compiler.js +0 -49
  425. package/build-module/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
  426. package/build-module/utils/transform-styles/ast/stringify/compress.js +0 -176
  427. package/build-module/utils/transform-styles/ast/stringify/compress.js.map +0 -1
  428. package/build-module/utils/transform-styles/ast/stringify/identity.js +0 -206
  429. package/build-module/utils/transform-styles/ast/stringify/identity.js.map +0 -1
  430. package/build-module/utils/transform-styles/ast/stringify/index.js +0 -29
  431. package/build-module/utils/transform-styles/ast/stringify/index.js.map +0 -1
  432. package/build-module/utils/transform-styles/transforms/url-rewrite.js +0 -123
  433. package/build-module/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
  434. package/build-module/utils/transform-styles/transforms/wrap.js +0 -52
  435. package/build-module/utils/transform-styles/transforms/wrap.js.map +0 -1
  436. package/build-module/utils/transform-styles/traverse.js +0 -28
  437. package/build-module/utils/transform-styles/traverse.js.map +0 -1
  438. package/src/components/use-setting/index.js +0 -213
  439. package/src/utils/transform-styles/ast/index.js +0 -5
  440. package/src/utils/transform-styles/ast/parse.js +0 -732
  441. package/src/utils/transform-styles/ast/stringify/compiler.js +0 -50
  442. package/src/utils/transform-styles/ast/stringify/compress.js +0 -238
  443. package/src/utils/transform-styles/ast/stringify/identity.js +0 -286
  444. package/src/utils/transform-styles/ast/stringify/index.js +0 -32
  445. package/src/utils/transform-styles/test/__snapshots__/traverse.js.snap +0 -7
  446. package/src/utils/transform-styles/test/traverse.js +0 -24
  447. package/src/utils/transform-styles/transforms/test/__snapshots__/url-rewrite.js.snap +0 -25
  448. package/src/utils/transform-styles/transforms/test/__snapshots__/wrap.js.snap +0 -64
  449. package/src/utils/transform-styles/transforms/test/url-rewrite.js +0 -39
  450. package/src/utils/transform-styles/transforms/test/wrap.js +0 -95
  451. package/src/utils/transform-styles/transforms/url-rewrite.js +0 -139
  452. package/src/utils/transform-styles/transforms/wrap.js +0 -56
  453. package/src/utils/transform-styles/traverse.js +0 -32
@@ -0,0 +1,272 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ __EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE,
6
+ hasBlockSupport,
7
+ } from '@wordpress/blocks';
8
+ import { useSelect } from '@wordpress/data';
9
+ import deprecated from '@wordpress/deprecated';
10
+ import { useMemo } from '@wordpress/element';
11
+ import { applyFilters } from '@wordpress/hooks';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { useBlockEditContext } from '../block-edit';
17
+ import { store as blockEditorStore } from '../../store';
18
+ import { getValueFromObjectPath } from '../../utils/object';
19
+
20
+ const blockedPaths = [
21
+ 'color',
22
+ 'border',
23
+ 'dimensions',
24
+ 'typography',
25
+ 'spacing',
26
+ ];
27
+
28
+ const deprecatedFlags = {
29
+ 'color.palette': ( settings ) => settings.colors,
30
+ 'color.gradients': ( settings ) => settings.gradients,
31
+ 'color.custom': ( settings ) =>
32
+ settings.disableCustomColors === undefined
33
+ ? undefined
34
+ : ! settings.disableCustomColors,
35
+ 'color.customGradient': ( settings ) =>
36
+ settings.disableCustomGradients === undefined
37
+ ? undefined
38
+ : ! settings.disableCustomGradients,
39
+ 'typography.fontSizes': ( settings ) => settings.fontSizes,
40
+ 'typography.customFontSize': ( settings ) =>
41
+ settings.disableCustomFontSizes === undefined
42
+ ? undefined
43
+ : ! settings.disableCustomFontSizes,
44
+ 'typography.lineHeight': ( settings ) => settings.enableCustomLineHeight,
45
+ 'spacing.units': ( settings ) => {
46
+ if ( settings.enableCustomUnits === undefined ) {
47
+ return;
48
+ }
49
+
50
+ if ( settings.enableCustomUnits === true ) {
51
+ return [ 'px', 'em', 'rem', 'vh', 'vw', '%' ];
52
+ }
53
+
54
+ return settings.enableCustomUnits;
55
+ },
56
+ 'spacing.padding': ( settings ) => settings.enableCustomSpacing,
57
+ };
58
+
59
+ const prefixedFlags = {
60
+ /*
61
+ * These were only available in the plugin
62
+ * and can be removed when the minimum WordPress version
63
+ * for the plugin is 5.9.
64
+ */
65
+ 'border.customColor': 'border.color',
66
+ 'border.customStyle': 'border.style',
67
+ 'border.customWidth': 'border.width',
68
+ 'typography.customFontStyle': 'typography.fontStyle',
69
+ 'typography.customFontWeight': 'typography.fontWeight',
70
+ 'typography.customLetterSpacing': 'typography.letterSpacing',
71
+ 'typography.customTextDecorations': 'typography.textDecoration',
72
+ 'typography.customTextTransforms': 'typography.textTransform',
73
+ /*
74
+ * These were part of WordPress 5.8 and we need to keep them.
75
+ */
76
+ 'border.customRadius': 'border.radius',
77
+ 'spacing.customMargin': 'spacing.margin',
78
+ 'spacing.customPadding': 'spacing.padding',
79
+ 'typography.customLineHeight': 'typography.lineHeight',
80
+ };
81
+
82
+ /**
83
+ * Remove `custom` prefixes for flags that did not land in 5.8.
84
+ *
85
+ * This provides continued support for `custom` prefixed properties. It will
86
+ * be removed once third party devs have had sufficient time to update themes,
87
+ * plugins, etc.
88
+ *
89
+ * @see https://github.com/WordPress/gutenberg/pull/34485
90
+ *
91
+ * @param {string} path Path to desired value in settings.
92
+ * @return {string} The value for defined setting.
93
+ */
94
+ const removeCustomPrefixes = ( path ) => {
95
+ return prefixedFlags[ path ] || path;
96
+ };
97
+
98
+ /**
99
+ * For settings like `color.palette`, which have a value that is an object
100
+ * with `default`, `theme`, `custom`, with field values that are arrays of
101
+ * items, merge these three arrays into one and return it. The calculation
102
+ * is memoized so that identical input values produce identical output.
103
+ * @param {Object} value Object to merge
104
+ * @return {Array} Array of merged items
105
+ */
106
+ function mergeOrigins( value ) {
107
+ let result = mergeCache.get( value );
108
+ if ( ! result ) {
109
+ result = [ 'default', 'theme', 'custom' ].flatMap(
110
+ ( key ) => value[ key ] ?? []
111
+ );
112
+ mergeCache.set( value, result );
113
+ }
114
+ return result;
115
+ }
116
+ const mergeCache = new WeakMap();
117
+
118
+ /**
119
+ * Hook that retrieves the given settings for the block instance in use.
120
+ *
121
+ * It looks up the settings first in the block instance hierarchy.
122
+ * If none are found, it'll look them up in the block editor settings.
123
+ *
124
+ * @param {string[]} paths The paths to the settings.
125
+ * @return {any[]} Returns the values defined for the settings.
126
+ * @example
127
+ * ```js
128
+ * const [ fixed, sticky ] = useSettings( 'position.fixed', 'position.sticky' );
129
+ * ```
130
+ */
131
+ export function useSettings( ...paths ) {
132
+ const { name: blockName, clientId = null } = useBlockEditContext();
133
+
134
+ // eslint-disable-next-line react-hooks/exhaustive-deps
135
+ paths = useMemo( () => paths, paths );
136
+
137
+ return useSelect(
138
+ ( select ) => {
139
+ const candidates = clientId
140
+ ? [
141
+ clientId,
142
+ ...select( blockEditorStore ).getBlockParents(
143
+ clientId,
144
+ /* ascending */ true
145
+ ),
146
+ ].filter( ( candidateClientId ) => {
147
+ const candidateBlockName =
148
+ select( blockEditorStore ).getBlockName(
149
+ candidateClientId
150
+ );
151
+ return hasBlockSupport(
152
+ candidateBlockName,
153
+ '__experimentalSettings',
154
+ false
155
+ );
156
+ } )
157
+ : [];
158
+
159
+ return paths.map( ( path ) => {
160
+ if ( blockedPaths.includes( path ) ) {
161
+ // eslint-disable-next-line no-console
162
+ console.warn(
163
+ 'Top level useSetting paths are disabled. Please use a subpath to query the information needed.'
164
+ );
165
+ return undefined;
166
+ }
167
+
168
+ // 0. Allow third parties to filter the block's settings at runtime.
169
+ let result = applyFilters(
170
+ 'blockEditor.useSetting.before',
171
+ undefined,
172
+ path,
173
+ clientId,
174
+ blockName
175
+ );
176
+
177
+ if ( undefined !== result ) {
178
+ return result;
179
+ }
180
+
181
+ const normalizedPath = removeCustomPrefixes( path );
182
+
183
+ // 1. Take settings from the block instance or its ancestors.
184
+ // Start from the current block and work our way up the ancestors.
185
+ for ( const candidateClientId of candidates ) {
186
+ const candidateAtts =
187
+ select( blockEditorStore ).getBlockAttributes(
188
+ candidateClientId
189
+ );
190
+ result =
191
+ getValueFromObjectPath(
192
+ candidateAtts.settings?.blocks?.[ blockName ],
193
+ normalizedPath
194
+ ) ??
195
+ getValueFromObjectPath(
196
+ candidateAtts.settings,
197
+ normalizedPath
198
+ );
199
+ if ( result !== undefined ) {
200
+ // Stop the search for more distant ancestors and move on.
201
+ break;
202
+ }
203
+ }
204
+
205
+ // 2. Fall back to the settings from the block editor store (__experimentalFeatures).
206
+ const settings = select( blockEditorStore ).getSettings();
207
+ if ( result === undefined && blockName ) {
208
+ result = getValueFromObjectPath(
209
+ settings.__experimentalFeatures?.blocks?.[ blockName ],
210
+ normalizedPath
211
+ );
212
+ }
213
+
214
+ if ( result === undefined ) {
215
+ result = getValueFromObjectPath(
216
+ settings.__experimentalFeatures,
217
+ normalizedPath
218
+ );
219
+ }
220
+
221
+ // Return if the setting was found in either the block instance or the store.
222
+ if ( result !== undefined ) {
223
+ if ( PATHS_WITH_MERGE[ normalizedPath ] ) {
224
+ return mergeOrigins( result );
225
+ }
226
+ return result;
227
+ }
228
+
229
+ // 3. Otherwise, use deprecated settings.
230
+ const deprecatedSettingsValue =
231
+ deprecatedFlags[ normalizedPath ]?.( settings );
232
+ if ( deprecatedSettingsValue !== undefined ) {
233
+ return deprecatedSettingsValue;
234
+ }
235
+
236
+ // 4. Fallback for typography.dropCap:
237
+ // This is only necessary to support typography.dropCap.
238
+ // when __experimentalFeatures are not present (core without plugin).
239
+ // To remove when __experimentalFeatures are ported to core.
240
+ return normalizedPath === 'typography.dropCap'
241
+ ? true
242
+ : undefined;
243
+ } );
244
+ },
245
+ [ blockName, clientId, paths ]
246
+ );
247
+ }
248
+
249
+ /**
250
+ * Hook that retrieves the given setting for the block instance in use.
251
+ *
252
+ * It looks up the setting first in the block instance hierarchy.
253
+ * If none is found, it'll look it up in the block editor settings.
254
+ *
255
+ * @param {string} path The path to the setting.
256
+ * @return {any} Returns the value defined for the setting.
257
+ * @deprecated 6.4.0 Use useSettings instead.
258
+ * @example
259
+ * ```js
260
+ * const isEnabled = useSetting( 'typography.dropCap' );
261
+ * ```
262
+ */
263
+ export function useSetting( path ) {
264
+ deprecated( 'wp.blockEditor.useSetting', {
265
+ since: '6.4',
266
+ alternative: 'wp.blockEditor.useSettings',
267
+ note: 'The new useSettings function can retrieve multiple settings at once, with better performance.',
268
+ } );
269
+
270
+ const [ value ] = useSettings( path );
271
+ return value;
272
+ }
@@ -1,16 +1,22 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render } from '@testing-library/react';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
9
  import { addFilter, removeFilter } from '@wordpress/hooks';
5
10
  import { useSelect } from '@wordpress/data';
11
+ import { useEffect } from '@wordpress/element';
6
12
 
7
13
  /**
8
14
  * Internal dependencies
9
15
  */
10
- import useSetting from '..';
16
+ import { useSettings, useSetting } from '..';
11
17
  import * as BlockEditContext from '../../block-edit/context';
12
18
 
13
- // Mock useSelect() functions used by useSetting()
19
+ // Mock useSelect() functions used by useSettings()
14
20
  jest.mock( '@wordpress/data/src/components/use-select' );
15
21
 
16
22
  let selectMock = {};
@@ -38,7 +44,19 @@ const mockCurrentBlockContext = (
38
44
  );
39
45
  };
40
46
 
41
- describe( 'useSetting', () => {
47
+ function runHook( hookCb ) {
48
+ let storedResult;
49
+ function TestHook() {
50
+ const result = hookCb();
51
+ useEffect( () => {
52
+ storedResult = result;
53
+ }, [ result ] );
54
+ }
55
+ render( <TestHook /> );
56
+ return storedResult;
57
+ }
58
+
59
+ describe( 'useSettings', () => {
42
60
  beforeEach( () => {
43
61
  setupSelectMock();
44
62
  mockCurrentBlockContext();
@@ -59,7 +77,8 @@ describe( 'useSetting', () => {
59
77
  name: 'core/test-block',
60
78
  } );
61
79
 
62
- expect( useSetting( 'layout.contentSize' ) ).toBe( '840px' );
80
+ const result = runHook( () => useSettings( 'layout.contentSize' ) );
81
+ expect( result ).toEqual( [ '840px' ] );
63
82
  } );
64
83
 
65
84
  it( 'uses blockEditor.useSetting.before hook override', () => {
@@ -89,11 +108,34 @@ describe( 'useSetting', () => {
89
108
  }
90
109
  );
91
110
 
92
- expect( useSetting( 'layout.contentSize' ) ).toBe( '960px' );
111
+ const result = runHook( () => useSettings( 'layout.contentSize' ) );
112
+ expect( result ).toEqual( [ '960px' ] );
93
113
 
94
114
  removeFilter(
95
115
  'blockEditor.useSetting.before',
96
116
  'test/useSetting.before'
97
117
  );
98
118
  } );
119
+
120
+ it( 'supports also the deprecated useSetting function', () => {
121
+ mockSettings( {
122
+ blocks: {
123
+ 'core/test-block': {
124
+ layout: {
125
+ contentSize: '840px',
126
+ },
127
+ },
128
+ },
129
+ } );
130
+
131
+ mockCurrentBlockContext( {
132
+ name: 'core/test-block',
133
+ } );
134
+
135
+ const result = runHook( () => useSetting( 'layout.contentSize' ) );
136
+ expect( result ).toBe( '840px' );
137
+ expect( console ).toHaveWarnedWith(
138
+ 'wp.blockEditor.useSetting is deprecated since version 6.4. Please use wp.blockEditor.useSettings instead.'
139
+ );
140
+ } );
99
141
  } );
@@ -114,6 +114,10 @@ export function getClosestTabbable(
114
114
  }
115
115
 
116
116
  function isTabCandidate( node ) {
117
+ if ( node.closest( '[inert]' ) ) {
118
+ return;
119
+ }
120
+
117
121
  // Skip if there's only one child that is content editable (and thus a
118
122
  // better candidate).
119
123
  if (
@@ -108,6 +108,50 @@ export function addAttribute( settings ) {
108
108
  return settings;
109
109
  }
110
110
 
111
+ function BlockEditAlignmentToolbarControls( {
112
+ blockName,
113
+ attributes,
114
+ setAttributes,
115
+ } ) {
116
+ // Compute the block valid alignments by taking into account,
117
+ // if the theme supports wide alignments or not and the layout's
118
+ // availble alignments. We do that for conditionally rendering
119
+ // Slot.
120
+ const blockAllowedAlignments = getValidAlignments(
121
+ getBlockSupport( blockName, 'align' ),
122
+ hasBlockSupport( blockName, 'alignWide', true )
123
+ );
124
+
125
+ const validAlignments = useAvailableAlignments(
126
+ blockAllowedAlignments
127
+ ).map( ( { name } ) => name );
128
+ const blockEditingMode = useBlockEditingMode();
129
+ if ( ! validAlignments.length || blockEditingMode !== 'default' ) {
130
+ return null;
131
+ }
132
+
133
+ const updateAlignment = ( nextAlign ) => {
134
+ if ( ! nextAlign ) {
135
+ const blockType = getBlockType( blockName );
136
+ const blockDefaultAlign = blockType?.attributes?.align?.default;
137
+ if ( blockDefaultAlign ) {
138
+ nextAlign = '';
139
+ }
140
+ }
141
+ setAttributes( { align: nextAlign } );
142
+ };
143
+
144
+ return (
145
+ <BlockControls group="block" __experimentalShareWithChildBlocks>
146
+ <BlockAlignmentControl
147
+ value={ attributes.align }
148
+ onChange={ updateAlignment }
149
+ controls={ validAlignments }
150
+ />
151
+ </BlockControls>
152
+ );
153
+ }
154
+
111
155
  /**
112
156
  * Override the default edit UI to include new toolbar controls for block
113
157
  * alignment, if block defines support.
@@ -118,52 +162,45 @@ export function addAttribute( settings ) {
118
162
  */
119
163
  export const withToolbarControls = createHigherOrderComponent(
120
164
  ( BlockEdit ) => ( props ) => {
121
- const blockEdit = <BlockEdit key="edit" { ...props } />;
122
- const { name: blockName } = props;
123
- // Compute the block valid alignments by taking into account,
124
- // if the theme supports wide alignments or not and the layout's
125
- // availble alignments. We do that for conditionally rendering
126
- // Slot.
127
- const blockAllowedAlignments = getValidAlignments(
128
- getBlockSupport( blockName, 'align' ),
129
- hasBlockSupport( blockName, 'alignWide', true )
165
+ const hasAlignmentSupport = hasBlockSupport(
166
+ props.name,
167
+ 'align',
168
+ false
130
169
  );
131
170
 
132
- const validAlignments = useAvailableAlignments(
133
- blockAllowedAlignments
134
- ).map( ( { name } ) => name );
135
- const blockEditingMode = useBlockEditingMode();
136
- if ( ! validAlignments.length || blockEditingMode !== 'default' ) {
137
- return blockEdit;
138
- }
139
-
140
- const updateAlignment = ( nextAlign ) => {
141
- if ( ! nextAlign ) {
142
- const blockType = getBlockType( props.name );
143
- const blockDefaultAlign = blockType?.attributes?.align?.default;
144
- if ( blockDefaultAlign ) {
145
- nextAlign = '';
146
- }
147
- }
148
- props.setAttributes( { align: nextAlign } );
149
- };
150
-
151
171
  return (
152
172
  <>
153
- <BlockControls group="block" __experimentalShareWithChildBlocks>
154
- <BlockAlignmentControl
155
- value={ props.attributes.align }
156
- onChange={ updateAlignment }
157
- controls={ validAlignments }
173
+ { hasAlignmentSupport && (
174
+ <BlockEditAlignmentToolbarControls
175
+ blockName={ props.name }
176
+ attributes={ props.attributes }
177
+ setAttributes={ props.setAttributes }
158
178
  />
159
- </BlockControls>
160
- { blockEdit }
179
+ ) }
180
+ <BlockEdit key="edit" { ...props } />
161
181
  </>
162
182
  );
163
183
  },
164
184
  'withToolbarControls'
165
185
  );
166
186
 
187
+ function BlockListBlockWithDataAlign( { block: BlockListBlock, props } ) {
188
+ const { name, attributes } = props;
189
+ const { align } = attributes;
190
+ const blockAllowedAlignments = getValidAlignments(
191
+ getBlockSupport( name, 'align' ),
192
+ hasBlockSupport( name, 'alignWide', true )
193
+ );
194
+ const validAlignments = useAvailableAlignments( blockAllowedAlignments );
195
+
196
+ let wrapperProps = props.wrapperProps;
197
+ if ( validAlignments.some( ( alignment ) => alignment.name === align ) ) {
198
+ wrapperProps = { ...wrapperProps, 'data-align': align };
199
+ }
200
+
201
+ return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;
202
+ }
203
+
167
204
  /**
168
205
  * Override the default block element to add alignment wrapper props.
169
206
  *
@@ -173,30 +210,18 @@ export const withToolbarControls = createHigherOrderComponent(
173
210
  */
174
211
  export const withDataAlign = createHigherOrderComponent(
175
212
  ( BlockListBlock ) => ( props ) => {
176
- const { name, attributes } = props;
177
- const { align } = attributes;
178
- const blockAllowedAlignments = getValidAlignments(
179
- getBlockSupport( name, 'align' ),
180
- hasBlockSupport( name, 'alignWide', true )
181
- );
182
- const validAlignments = useAvailableAlignments(
183
- blockAllowedAlignments
184
- );
185
-
186
213
  // If an alignment is not assigned, there's no need to go through the
187
214
  // effort to validate or assign its value.
188
- if ( align === undefined ) {
215
+ if ( props.attributes.align === undefined ) {
189
216
  return <BlockListBlock { ...props } />;
190
217
  }
191
218
 
192
- let wrapperProps = props.wrapperProps;
193
- if (
194
- validAlignments.some( ( alignment ) => alignment.name === align )
195
- ) {
196
- wrapperProps = { ...wrapperProps, 'data-align': align };
197
- }
198
-
199
- return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;
219
+ return (
220
+ <BlockListBlockWithDataAlign
221
+ block={ BlockListBlock }
222
+ props={ props }
223
+ />
224
+ );
200
225
  },
201
226
  'withDataAlign'
202
227
  );
@@ -52,6 +52,69 @@ export function addAttribute( settings ) {
52
52
  return settings;
53
53
  }
54
54
 
55
+ function BlockEditAnchorControl( { blockName, attributes, setAttributes } ) {
56
+ const blockEditingMode = useBlockEditingMode();
57
+
58
+ const isWeb = Platform.OS === 'web';
59
+ const textControl = (
60
+ <TextControl
61
+ __nextHasNoMarginBottom
62
+ className="html-anchor-control"
63
+ label={ __( 'HTML anchor' ) }
64
+ help={
65
+ <>
66
+ { __(
67
+ 'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'
68
+ ) }
69
+
70
+ { isWeb && (
71
+ <ExternalLink
72
+ href={ __(
73
+ 'https://wordpress.org/documentation/article/page-jumps/'
74
+ ) }
75
+ >
76
+ { __( 'Learn more about anchors' ) }
77
+ </ExternalLink>
78
+ ) }
79
+ </>
80
+ }
81
+ value={ attributes.anchor || '' }
82
+ placeholder={ ! isWeb ? __( 'Add an anchor' ) : null }
83
+ onChange={ ( nextValue ) => {
84
+ nextValue = nextValue.replace( ANCHOR_REGEX, '-' );
85
+ setAttributes( {
86
+ anchor: nextValue,
87
+ } );
88
+ } }
89
+ autoCapitalize="none"
90
+ autoComplete="off"
91
+ />
92
+ );
93
+
94
+ return (
95
+ <>
96
+ { isWeb && blockEditingMode === 'default' && (
97
+ <InspectorControls group="advanced">
98
+ { textControl }
99
+ </InspectorControls>
100
+ ) }
101
+ { /*
102
+ * We plan to remove scoping anchors to 'core/heading' to support
103
+ * anchors for all eligble blocks. Additionally we plan to explore
104
+ * leveraging InspectorAdvancedControls instead of a custom
105
+ * PanelBody title. https://github.com/WordPress/gutenberg/issues/28363
106
+ */ }
107
+ { ! isWeb && blockName === 'core/heading' && (
108
+ <InspectorControls>
109
+ <PanelBody title={ __( 'Heading settings' ) }>
110
+ { textControl }
111
+ </PanelBody>
112
+ </InspectorControls>
113
+ ) }
114
+ </>
115
+ );
116
+ }
117
+
55
118
  /**
56
119
  * Override the default edit UI to include a new block inspector control for
57
120
  * assigning the anchor ID, if block supports anchor.
@@ -63,72 +126,19 @@ export function addAttribute( settings ) {
63
126
  export const withInspectorControl = createHigherOrderComponent(
64
127
  ( BlockEdit ) => {
65
128
  return ( props ) => {
66
- const hasAnchor = hasBlockSupport( props.name, 'anchor' );
67
- const blockEditingMode = useBlockEditingMode();
68
-
69
- if ( hasAnchor && props.isSelected ) {
70
- const isWeb = Platform.OS === 'web';
71
- const textControl = (
72
- <TextControl
73
- __nextHasNoMarginBottom
74
- className="html-anchor-control"
75
- label={ __( 'HTML anchor' ) }
76
- help={
77
- <>
78
- { __(
79
- 'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'
80
- ) }
81
-
82
- { isWeb && (
83
- <ExternalLink
84
- href={ __(
85
- 'https://wordpress.org/documentation/article/page-jumps/'
86
- ) }
87
- >
88
- { __( 'Learn more about anchors' ) }
89
- </ExternalLink>
90
- ) }
91
- </>
92
- }
93
- value={ props.attributes.anchor || '' }
94
- placeholder={ ! isWeb ? __( 'Add an anchor' ) : null }
95
- onChange={ ( nextValue ) => {
96
- nextValue = nextValue.replace( ANCHOR_REGEX, '-' );
97
- props.setAttributes( {
98
- anchor: nextValue,
99
- } );
100
- } }
101
- autoCapitalize="none"
102
- autoComplete="off"
103
- />
104
- );
105
-
106
- return (
107
- <>
108
- <BlockEdit { ...props } />
109
- { isWeb && blockEditingMode === 'default' && (
110
- <InspectorControls group="advanced">
111
- { textControl }
112
- </InspectorControls>
129
+ return (
130
+ <>
131
+ <BlockEdit { ...props } />
132
+ { props.isSelected &&
133
+ hasBlockSupport( props.name, 'anchor' ) && (
134
+ <BlockEditAnchorControl
135
+ blockName={ props.name }
136
+ attributes={ props.attributes }
137
+ setAttributes={ props.setAttributes }
138
+ />
113
139
  ) }
114
- { /*
115
- * We plan to remove scoping anchors to 'core/heading' to support
116
- * anchors for all eligble blocks. Additionally we plan to explore
117
- * leveraging InspectorAdvancedControls instead of a custom
118
- * PanelBody title. https://github.com/WordPress/gutenberg/issues/28363
119
- */ }
120
- { ! isWeb && props.name === 'core/heading' && (
121
- <InspectorControls>
122
- <PanelBody title={ __( 'Heading settings' ) }>
123
- { textControl }
124
- </PanelBody>
125
- </InspectorControls>
126
- ) }
127
- </>
128
- );
129
- }
130
-
131
- return <BlockEdit { ...props } />;
140
+ </>
141
+ );
132
142
  };
133
143
  },
134
144
  'withInspectorControl'