@wordpress/block-editor 13.3.0 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +0 -4
  3. package/build/components/alignment-control/ui.js +2 -2
  4. package/build/components/alignment-control/ui.js.map +1 -1
  5. package/build/components/block-alignment-control/ui.js +1 -1
  6. package/build/components/block-alignment-control/ui.js.map +1 -1
  7. package/build/components/block-alignment-control/ui.native.js +1 -1
  8. package/build/components/block-alignment-control/ui.native.js.map +1 -1
  9. package/build/components/block-inspector/index.js +6 -3
  10. package/build/components/block-inspector/index.js.map +1 -1
  11. package/build/components/block-list/use-block-props/index.js +3 -1
  12. package/build/components/block-list/use-block-props/index.js.map +1 -1
  13. package/build/components/block-list/use-block-props/use-block-refs.js +9 -2
  14. package/build/components/block-list/use-block-props/use-block-refs.js.map +1 -1
  15. package/build/components/block-list/use-block-props/use-is-hovered.js +25 -9
  16. package/build/components/block-list/use-block-props/use-is-hovered.js.map +1 -1
  17. package/build/components/block-list/use-in-between-inserter.js +3 -2
  18. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  19. package/build/components/block-lock/modal.js +2 -0
  20. package/build/components/block-lock/modal.js.map +1 -1
  21. package/build/components/block-removal-warning-modal/index.js +2 -0
  22. package/build/components/block-removal-warning-modal/index.js.map +1 -1
  23. package/build/components/block-switcher/index.js +1 -1
  24. package/build/components/block-switcher/index.js.map +1 -1
  25. package/build/components/block-switcher/pattern-transformations-menu.js +11 -12
  26. package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
  27. package/build/components/block-switcher/preview-block-popover.js +20 -17
  28. package/build/components/block-switcher/preview-block-popover.js.map +1 -1
  29. package/build/components/block-toolbar/shuffle.js +5 -2
  30. package/build/components/block-toolbar/shuffle.js.map +1 -1
  31. package/build/components/block-tools/use-show-block-tools.js +7 -8
  32. package/build/components/block-tools/use-show-block-tools.js.map +1 -1
  33. package/build/components/block-tools/zoom-out-mode-inserter-button.js +45 -0
  34. package/build/components/block-tools/zoom-out-mode-inserter-button.js.map +1 -0
  35. package/build/components/block-tools/zoom-out-mode-inserters.js +27 -27
  36. package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
  37. package/build/components/block-tools/zoom-out-popover.js +2 -1
  38. package/build/components/block-tools/zoom-out-popover.js.map +1 -1
  39. package/build/components/block-tools/zoom-out-toolbar.js +1 -1
  40. package/build/components/block-tools/zoom-out-toolbar.js.map +1 -1
  41. package/build/components/date-format-picker/index.js +2 -11
  42. package/build/components/date-format-picker/index.js.map +1 -1
  43. package/build/components/default-block-appender/index.js +7 -4
  44. package/build/components/default-block-appender/index.js.map +1 -1
  45. package/build/components/font-appearance-control/index.js +2 -7
  46. package/build/components/font-appearance-control/index.js.map +1 -1
  47. package/build/components/global-styles/background-panel.js +8 -1
  48. package/build/components/global-styles/background-panel.js.map +1 -1
  49. package/build/components/global-styles/hooks.js +5 -1
  50. package/build/components/global-styles/hooks.js.map +1 -1
  51. package/build/components/global-styles/typography-panel.js +26 -43
  52. package/build/components/global-styles/typography-panel.js.map +1 -1
  53. package/build/components/global-styles/typography-utils.js +78 -7
  54. package/build/components/global-styles/typography-utils.js.map +1 -1
  55. package/build/components/global-styles/use-global-styles-output.js +24 -5
  56. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  57. package/build/components/grid/grid-item-movers.js +89 -44
  58. package/build/components/grid/grid-item-movers.js.map +1 -1
  59. package/build/components/grid/grid-visualizer.js +1 -1
  60. package/build/components/grid/grid-visualizer.js.map +1 -1
  61. package/build/components/grid/use-grid-layout-sync.js +40 -28
  62. package/build/components/grid/use-grid-layout-sync.js.map +1 -1
  63. package/build/components/index.js +1 -9
  64. package/build/components/index.js.map +1 -1
  65. package/build/components/inner-blocks/index.js +1 -1
  66. package/build/components/inner-blocks/index.js.map +1 -1
  67. package/build/components/inserter/block-patterns-tab/patterns-filter.js +20 -23
  68. package/build/components/inserter/block-patterns-tab/patterns-filter.js.map +1 -1
  69. package/build/components/inserter/media-tab/media-panel.js +1 -0
  70. package/build/components/inserter/media-tab/media-panel.js.map +1 -1
  71. package/build/components/inserter/menu.js +1 -1
  72. package/build/components/inserter/menu.js.map +1 -1
  73. package/build/components/inserter/preview-panel.js +20 -3
  74. package/build/components/inserter/preview-panel.js.map +1 -1
  75. package/build/components/inserter-draggable-blocks/index.js +10 -3
  76. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  77. package/build/components/inspector-controls-tabs/settings-tab.js +1 -2
  78. package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
  79. package/build/components/list-view/block-select-button.js +2 -6
  80. package/build/components/list-view/block-select-button.js.map +1 -1
  81. package/build/components/list-view/block.js +2 -2
  82. package/build/components/list-view/block.js.map +1 -1
  83. package/build/components/list-view/utils.js +3 -1
  84. package/build/components/list-view/utils.js.map +1 -1
  85. package/build/components/rich-text/format-toolbar/index.js +1 -1
  86. package/build/components/rich-text/format-toolbar/index.js.map +1 -1
  87. package/build/components/rich-text/index.js +1 -1
  88. package/build/components/rich-text/index.js.map +1 -1
  89. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +4 -2
  90. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  91. package/build/components/url-popover/image-url-input-ui.js +3 -3
  92. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  93. package/build/hooks/grid-visualizer.js +5 -8
  94. package/build/hooks/grid-visualizer.js.map +1 -1
  95. package/build/hooks/layout-child.js +9 -2
  96. package/build/hooks/layout-child.js.map +1 -1
  97. package/build/hooks/position.js +3 -7
  98. package/build/hooks/position.js.map +1 -1
  99. package/build/hooks/use-bindings-attributes.js +81 -50
  100. package/build/hooks/use-bindings-attributes.js.map +1 -1
  101. package/build/layouts/constrained.js +6 -2
  102. package/build/layouts/constrained.js.map +1 -1
  103. package/build/layouts/grid.js +2 -0
  104. package/build/layouts/grid.js.map +1 -1
  105. package/build/private-apis.js +0 -3
  106. package/build/private-apis.js.map +1 -1
  107. package/build/store/actions.js +18 -1
  108. package/build/store/actions.js.map +1 -1
  109. package/build/store/reducer.js +19 -1
  110. package/build/store/reducer.js.map +1 -1
  111. package/build/store/selectors.js +13 -1
  112. package/build/store/selectors.js.map +1 -1
  113. package/build-module/components/alignment-control/ui.js +2 -2
  114. package/build-module/components/alignment-control/ui.js.map +1 -1
  115. package/build-module/components/block-alignment-control/ui.js +1 -1
  116. package/build-module/components/block-alignment-control/ui.js.map +1 -1
  117. package/build-module/components/block-alignment-control/ui.native.js +1 -1
  118. package/build-module/components/block-alignment-control/ui.native.js.map +1 -1
  119. package/build-module/components/block-inspector/index.js +6 -3
  120. package/build-module/components/block-inspector/index.js.map +1 -1
  121. package/build-module/components/block-list/use-block-props/index.js +3 -1
  122. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  123. package/build-module/components/block-list/use-block-props/use-block-refs.js +11 -4
  124. package/build-module/components/block-list/use-block-props/use-block-refs.js.map +1 -1
  125. package/build-module/components/block-list/use-block-props/use-is-hovered.js +26 -9
  126. package/build-module/components/block-list/use-block-props/use-is-hovered.js.map +1 -1
  127. package/build-module/components/block-list/use-in-between-inserter.js +3 -2
  128. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  129. package/build-module/components/block-lock/modal.js +2 -0
  130. package/build-module/components/block-lock/modal.js.map +1 -1
  131. package/build-module/components/block-removal-warning-modal/index.js +2 -0
  132. package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
  133. package/build-module/components/block-switcher/index.js +1 -1
  134. package/build-module/components/block-switcher/index.js.map +1 -1
  135. package/build-module/components/block-switcher/pattern-transformations-menu.js +12 -13
  136. package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
  137. package/build-module/components/block-switcher/preview-block-popover.js +20 -17
  138. package/build-module/components/block-switcher/preview-block-popover.js.map +1 -1
  139. package/build-module/components/block-toolbar/shuffle.js +5 -2
  140. package/build-module/components/block-toolbar/shuffle.js.map +1 -1
  141. package/build-module/components/block-tools/use-show-block-tools.js +7 -8
  142. package/build-module/components/block-tools/use-show-block-tools.js.map +1 -1
  143. package/build-module/components/block-tools/zoom-out-mode-inserter-button.js +37 -0
  144. package/build-module/components/block-tools/zoom-out-mode-inserter-button.js.map +1 -0
  145. package/build-module/components/block-tools/zoom-out-mode-inserters.js +28 -28
  146. package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
  147. package/build-module/components/block-tools/zoom-out-popover.js +2 -1
  148. package/build-module/components/block-tools/zoom-out-popover.js.map +1 -1
  149. package/build-module/components/block-tools/zoom-out-toolbar.js +1 -1
  150. package/build-module/components/block-tools/zoom-out-toolbar.js.map +1 -1
  151. package/build-module/components/date-format-picker/index.js +4 -12
  152. package/build-module/components/date-format-picker/index.js.map +1 -1
  153. package/build-module/components/default-block-appender/index.js +7 -4
  154. package/build-module/components/default-block-appender/index.js.map +1 -1
  155. package/build-module/components/font-appearance-control/index.js +3 -6
  156. package/build-module/components/font-appearance-control/index.js.map +1 -1
  157. package/build-module/components/global-styles/background-panel.js +8 -1
  158. package/build-module/components/global-styles/background-panel.js.map +1 -1
  159. package/build-module/components/global-styles/hooks.js +5 -1
  160. package/build-module/components/global-styles/hooks.js.map +1 -1
  161. package/build-module/components/global-styles/typography-panel.js +27 -44
  162. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  163. package/build-module/components/global-styles/typography-utils.js +76 -7
  164. package/build-module/components/global-styles/typography-utils.js.map +1 -1
  165. package/build-module/components/global-styles/use-global-styles-output.js +24 -5
  166. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  167. package/build-module/components/grid/grid-item-movers.js +92 -46
  168. package/build-module/components/grid/grid-item-movers.js.map +1 -1
  169. package/build-module/components/grid/grid-visualizer.js +1 -1
  170. package/build-module/components/grid/grid-visualizer.js.map +1 -1
  171. package/build-module/components/grid/use-grid-layout-sync.js +41 -29
  172. package/build-module/components/grid/use-grid-layout-sync.js.map +1 -1
  173. package/build-module/components/index.js +0 -5
  174. package/build-module/components/index.js.map +1 -1
  175. package/build-module/components/inner-blocks/index.js +1 -1
  176. package/build-module/components/inner-blocks/index.js.map +1 -1
  177. package/build-module/components/inserter/block-patterns-tab/patterns-filter.js +20 -23
  178. package/build-module/components/inserter/block-patterns-tab/patterns-filter.js.map +1 -1
  179. package/build-module/components/inserter/media-tab/media-panel.js +1 -0
  180. package/build-module/components/inserter/media-tab/media-panel.js.map +1 -1
  181. package/build-module/components/inserter/menu.js +1 -1
  182. package/build-module/components/inserter/menu.js.map +1 -1
  183. package/build-module/components/inserter/preview-panel.js +20 -3
  184. package/build-module/components/inserter/preview-panel.js.map +1 -1
  185. package/build-module/components/inserter-draggable-blocks/index.js +10 -3
  186. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  187. package/build-module/components/inspector-controls-tabs/settings-tab.js +1 -2
  188. package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
  189. package/build-module/components/list-view/block-select-button.js +3 -7
  190. package/build-module/components/list-view/block-select-button.js.map +1 -1
  191. package/build-module/components/list-view/block.js +2 -2
  192. package/build-module/components/list-view/block.js.map +1 -1
  193. package/build-module/components/list-view/utils.js +3 -1
  194. package/build-module/components/list-view/utils.js.map +1 -1
  195. package/build-module/components/rich-text/format-toolbar/index.js +1 -1
  196. package/build-module/components/rich-text/format-toolbar/index.js.map +1 -1
  197. package/build-module/components/rich-text/index.js +1 -1
  198. package/build-module/components/rich-text/index.js.map +1 -1
  199. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +4 -2
  200. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  201. package/build-module/components/url-popover/image-url-input-ui.js +3 -3
  202. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  203. package/build-module/hooks/grid-visualizer.js +5 -8
  204. package/build-module/hooks/grid-visualizer.js.map +1 -1
  205. package/build-module/hooks/layout-child.js +9 -2
  206. package/build-module/hooks/layout-child.js.map +1 -1
  207. package/build-module/hooks/position.js +3 -7
  208. package/build-module/hooks/position.js.map +1 -1
  209. package/build-module/hooks/use-bindings-attributes.js +81 -51
  210. package/build-module/hooks/use-bindings-attributes.js.map +1 -1
  211. package/build-module/layouts/constrained.js +6 -2
  212. package/build-module/layouts/constrained.js.map +1 -1
  213. package/build-module/layouts/grid.js +2 -0
  214. package/build-module/layouts/grid.js.map +1 -1
  215. package/build-module/private-apis.js +0 -3
  216. package/build-module/private-apis.js.map +1 -1
  217. package/build-module/store/actions.js +15 -0
  218. package/build-module/store/actions.js.map +1 -1
  219. package/build-module/store/reducer.js +18 -1
  220. package/build-module/store/reducer.js.map +1 -1
  221. package/build-module/store/selectors.js +10 -0
  222. package/build-module/store/selectors.js.map +1 -1
  223. package/build-style/content-rtl.css +6 -6
  224. package/build-style/content.css +6 -6
  225. package/build-style/style-rtl.css +167 -103
  226. package/build-style/style.css +167 -103
  227. package/build-types/components/block-context/index.d.ts +2 -2
  228. package/build-types/components/block-context/index.d.ts.map +1 -1
  229. package/build-types/utils/dom.d.ts.map +1 -1
  230. package/package.json +31 -31
  231. package/src/components/alignment-control/ui.js +2 -2
  232. package/src/components/block-alignment-control/ui.js +1 -1
  233. package/src/components/block-alignment-control/ui.native.js +1 -1
  234. package/src/components/block-context/README.md +4 -4
  235. package/src/components/block-inspector/index.js +8 -4
  236. package/src/components/block-list/content.scss +2 -16
  237. package/src/components/block-list/use-block-props/index.js +1 -1
  238. package/src/components/block-list/use-block-props/use-block-refs.js +19 -3
  239. package/src/components/block-list/use-block-props/use-is-hovered.js +26 -11
  240. package/src/components/block-list/use-in-between-inserter.js +5 -1
  241. package/src/components/block-lock/modal.js +10 -2
  242. package/src/components/block-lock/style.scss +4 -8
  243. package/src/components/block-patterns-paging/style.scss +0 -23
  244. package/src/components/block-removal-warning-modal/index.js +10 -2
  245. package/src/components/block-switcher/index.js +1 -1
  246. package/src/components/block-switcher/pattern-transformations-menu.js +17 -15
  247. package/src/components/block-switcher/preview-block-popover.js +20 -14
  248. package/src/components/block-switcher/style.scss +8 -17
  249. package/src/components/block-toolbar/shuffle.js +8 -1
  250. package/src/components/block-tools/style.scss +8 -0
  251. package/src/components/block-tools/use-show-block-tools.js +12 -9
  252. package/src/components/block-tools/zoom-out-mode-inserter-button.js +47 -0
  253. package/src/components/block-tools/zoom-out-mode-inserters.js +43 -33
  254. package/src/components/block-tools/zoom-out-popover.js +1 -0
  255. package/src/components/block-tools/zoom-out-toolbar.js +1 -1
  256. package/src/components/date-format-picker/index.js +2 -11
  257. package/src/components/default-block-appender/index.js +11 -4
  258. package/src/components/font-appearance-control/index.js +1 -5
  259. package/src/components/global-styles/background-panel.js +21 -1
  260. package/src/components/global-styles/hooks.js +5 -1
  261. package/src/components/global-styles/style.scss +12 -0
  262. package/src/components/global-styles/test/typography-utils.js +325 -0
  263. package/src/components/global-styles/test/use-global-styles-output.js +3 -1
  264. package/src/components/global-styles/typography-panel.js +36 -44
  265. package/src/components/global-styles/typography-utils.js +103 -7
  266. package/src/components/global-styles/use-global-styles-output.js +22 -2
  267. package/src/components/grid/grid-item-movers.js +139 -69
  268. package/src/components/grid/grid-visualizer.js +1 -1
  269. package/src/components/grid/style.scss +114 -0
  270. package/src/components/grid/use-grid-layout-sync.js +66 -27
  271. package/src/components/iframe/content.scss +1 -1
  272. package/src/components/index.js +0 -5
  273. package/src/components/inner-blocks/index.js +4 -1
  274. package/src/components/inserter/block-patterns-tab/patterns-filter.js +40 -44
  275. package/src/components/inserter/media-tab/media-panel.js +1 -0
  276. package/src/components/inserter/menu.js +1 -1
  277. package/src/components/inserter/preview-panel.js +27 -4
  278. package/src/components/inserter/style.scss +57 -43
  279. package/src/components/inserter-draggable-blocks/index.js +11 -3
  280. package/src/components/inspector-controls-tabs/settings-tab.js +0 -2
  281. package/src/components/inspector-controls-tabs/style.scss +0 -21
  282. package/src/components/list-view/block-select-button.js +3 -13
  283. package/src/components/list-view/block.js +10 -3
  284. package/src/components/list-view/style.scss +2 -1
  285. package/src/components/list-view/utils.js +13 -2
  286. package/src/components/rich-text/format-toolbar/index.js +1 -1
  287. package/src/components/rich-text/index.js +1 -1
  288. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -1
  289. package/src/components/url-popover/image-url-input-ui.js +3 -3
  290. package/src/components/url-popover/style.scss +1 -0
  291. package/src/hooks/grid-visualizer.js +5 -7
  292. package/src/hooks/layout-child.js +12 -3
  293. package/src/hooks/position.js +3 -13
  294. package/src/hooks/use-bindings-attributes.js +89 -59
  295. package/src/layouts/constrained.js +10 -2
  296. package/src/layouts/grid.js +2 -0
  297. package/src/private-apis.js +0 -6
  298. package/src/store/actions.js +15 -0
  299. package/src/store/reducer.js +18 -0
  300. package/src/store/selectors.js +10 -0
  301. package/tsconfig.tsbuildinfo +1 -1
  302. package/build/components/inserter/reusable-block-rename-hint.js +0 -71
  303. package/build/components/inserter/reusable-block-rename-hint.js.map +0 -1
  304. package/build/components/inspector-controls-tabs/settings-tab-hint.js +0 -53
  305. package/build/components/inspector-controls-tabs/settings-tab-hint.js.map +0 -1
  306. package/build-module/components/inserter/reusable-block-rename-hint.js +0 -64
  307. package/build-module/components/inserter/reusable-block-rename-hint.js.map +0 -1
  308. package/build-module/components/inspector-controls-tabs/settings-tab-hint.js +0 -47
  309. package/build-module/components/inspector-controls-tabs/settings-tab-hint.js.map +0 -1
  310. package/src/components/inserter/reusable-block-rename-hint.js +0 -69
  311. package/src/components/inspector-controls-tabs/settings-tab-hint.js +0 -52
@@ -11,6 +11,7 @@ import {
11
11
  getComputedFluidTypographyValue,
12
12
  getTypographyValueAndUnit,
13
13
  } from '../font-sizes/fluid-utils';
14
+ import { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';
14
15
 
15
16
  /**
16
17
  * @typedef {Object} FluidPreset
@@ -127,9 +128,9 @@ export function getFluidTypographyOptionsFromSettings( settings ) {
127
128
  * Returns an object of merged font families and the font faces from the selected font family
128
129
  * based on the theme.json settings object and the currently selected font family.
129
130
  *
130
- * @param {Object} settings Theme.json settings
131
- * @param {string} selectedFontFamily Decoded font family string
132
- * @return {Object} Merged font families and font faces from the selected font family
131
+ * @param {Object} settings Theme.json settings.
132
+ * @param {string} selectedFontFamily Decoded font family string.
133
+ * @return {Object} Merged font families and font faces from the selected font family.
133
134
  */
134
135
  export function getMergedFontFamiliesAndFontFamilyFaces(
135
136
  settings,
@@ -153,11 +154,10 @@ export function getMergedFontFamiliesAndFontFamilyFaces(
153
154
  * Returns the nearest font weight value from the available font weight list based on the new font weight.
154
155
  * The nearest font weight is the one with the smallest difference from the new font weight.
155
156
  *
156
- * @param {Array} availableFontWeights Array of available font weights
157
- * @param {string} newFontWeightValue New font weight value
158
- * @return {string} Nearest font weight
157
+ * @param {Array} availableFontWeights Array of available font weights.
158
+ * @param {string} newFontWeightValue New font weight value.
159
+ * @return {string} Nearest font weight.
159
160
  */
160
-
161
161
  export function findNearestFontWeight(
162
162
  availableFontWeights,
163
163
  newFontWeightValue
@@ -185,3 +185,99 @@ export function findNearestFontWeight(
185
185
 
186
186
  return nearestFontWeight;
187
187
  }
188
+
189
+ /**
190
+ * Returns the nearest font style based on the new font style.
191
+ * Defaults to an empty string if the new font style is not valid or available.
192
+ *
193
+ * @param {Array} availableFontStyles Array of available font weights.
194
+ * @param {string} newFontStyleValue New font style value.
195
+ * @return {string} Nearest font style or an empty string.
196
+ */
197
+ export function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {
198
+ if ( typeof newFontStyleValue !== 'string' || ! newFontStyleValue ) {
199
+ return '';
200
+ }
201
+
202
+ const validStyles = [ 'normal', 'italic', 'oblique' ];
203
+ if ( ! validStyles.includes( newFontStyleValue ) ) {
204
+ return '';
205
+ }
206
+
207
+ if (
208
+ ! availableFontStyles ||
209
+ availableFontStyles.length === 0 ||
210
+ availableFontStyles.find(
211
+ ( style ) => style.value === newFontStyleValue
212
+ )
213
+ ) {
214
+ return newFontStyleValue;
215
+ }
216
+
217
+ if (
218
+ newFontStyleValue === 'oblique' &&
219
+ ! availableFontStyles.find( ( style ) => style.value === 'oblique' )
220
+ ) {
221
+ return 'italic';
222
+ }
223
+
224
+ return '';
225
+ }
226
+
227
+ /**
228
+ * Returns the nearest font style and weight based on the available font family faces and the new font style and weight.
229
+ *
230
+ * @param {Array} fontFamilyFaces Array of available font family faces.
231
+ * @param {string} fontStyle New font style. Defaults to previous value.
232
+ * @param {string} fontWeight New font weight. Defaults to previous value.
233
+ * @return {Object} Nearest font style and font weight.
234
+ */
235
+ export function findNearestStyleAndWeight(
236
+ fontFamilyFaces,
237
+ fontStyle,
238
+ fontWeight
239
+ ) {
240
+ let nearestFontStyle = fontStyle;
241
+ let nearestFontWeight = fontWeight;
242
+
243
+ const { fontStyles, fontWeights, combinedStyleAndWeightOptions } =
244
+ getFontStylesAndWeights( fontFamilyFaces );
245
+
246
+ // Check if the new font style and weight are available in the font family faces.
247
+ const hasFontStyle = fontStyles?.some(
248
+ ( { value: fs } ) => fs === fontStyle
249
+ );
250
+ const hasFontWeight = fontWeights?.some(
251
+ ( { value: fw } ) => fw === fontWeight
252
+ );
253
+
254
+ if ( ! hasFontStyle ) {
255
+ /*
256
+ * Default to italic if oblique is not available.
257
+ * Or find the nearest font style based on the nearest font weight.
258
+ */
259
+ nearestFontStyle = fontStyle
260
+ ? findNearestFontStyle( fontStyles, fontStyle )
261
+ : combinedStyleAndWeightOptions?.find(
262
+ ( option ) =>
263
+ option.style.fontWeight ===
264
+ findNearestFontWeight( fontWeights, fontWeight )
265
+ )?.style?.fontStyle;
266
+ }
267
+
268
+ if ( ! hasFontWeight ) {
269
+ /*
270
+ * Find the nearest font weight based on available weights.
271
+ * Or find the nearest font weight based on the nearest font style.
272
+ */
273
+ nearestFontWeight = fontWeight
274
+ ? findNearestFontWeight( fontWeights, fontWeight )
275
+ : combinedStyleAndWeightOptions?.find(
276
+ ( option ) =>
277
+ option.style.fontStyle ===
278
+ ( nearestFontStyle || fontStyle )
279
+ )?.style?.fontWeight;
280
+ }
281
+
282
+ return { nearestFontStyle, nearestFontWeight };
283
+ }
@@ -38,6 +38,12 @@ import { getValueFromObjectPath, setImmutably } from '../../utils/object';
38
38
  import { unlock } from '../../lock-unlock';
39
39
  import { setThemeFileUris } from './theme-file-uri-utils';
40
40
 
41
+ // Elements that rely on class names in their selectors.
42
+ const ELEMENT_CLASS_NAMES = {
43
+ button: 'wp-element-button',
44
+ caption: 'wp-element-caption',
45
+ };
46
+
41
47
  // List of block support features that can have their related styles
42
48
  // generated under their own feature level selector rather than the block's.
43
49
  const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
@@ -643,6 +649,9 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
643
649
  nodes.push( {
644
650
  styles,
645
651
  selector: ROOT_BLOCK_SELECTOR,
652
+ // Root selector (body) styles should not be wrapped in `:root where()` to keep
653
+ // specificity at (0,0,1) and maintain backwards compatibility.
654
+ skipSelectorWrapper: true,
646
655
  } );
647
656
  }
648
657
 
@@ -651,6 +660,9 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
651
660
  nodes.push( {
652
661
  styles: tree.styles?.elements?.[ name ],
653
662
  selector,
663
+ // Top level elements that don't use a class name should not receive the
664
+ // `:root :where()` wrapper to maintain backwards compatibility.
665
+ skipSelectorWrapper: ! ELEMENT_CLASS_NAMES[ name ],
654
666
  } );
655
667
  }
656
668
  } );
@@ -957,6 +969,7 @@ export const toStyles = (
957
969
  hasLayoutSupport,
958
970
  featureSelectors,
959
971
  styleVariationSelectors,
972
+ skipSelectorWrapper,
960
973
  } ) => {
961
974
  // Process styles for block support features with custom feature level
962
975
  // CSS selectors set.
@@ -1015,7 +1028,10 @@ export const toStyles = (
1015
1028
  disableRootPadding
1016
1029
  );
1017
1030
  if ( styleDeclarations?.length ) {
1018
- ruleset += `:root :where(${ selector }){${ styleDeclarations.join(
1031
+ const generalSelector = skipSelectorWrapper
1032
+ ? selector
1033
+ : `:root :where(${ selector })`;
1034
+ ruleset += `${ generalSelector }{${ styleDeclarations.join(
1019
1035
  ';'
1020
1036
  ) };}`;
1021
1037
  }
@@ -1109,7 +1125,11 @@ export const toStyles = (
1109
1125
  .map( ( sel ) => sel + pseudoKey )
1110
1126
  .join( ',' );
1111
1127
 
1112
- const pseudoRule = `${ _selector }{${ pseudoDeclarations.join(
1128
+ // As pseudo classes such as :hover, :focus etc. have class-level
1129
+ // specificity, they must use the `:root :where()` wrapper. This.
1130
+ // caps the specificity at `0-1-0` to allow proper nesting of variations
1131
+ // and block type element styles.
1132
+ const pseudoRule = `:root :where(${ _selector }){${ pseudoDeclarations.join(
1113
1133
  ';'
1114
1134
  ) };}`;
1115
1135
 
@@ -1,10 +1,25 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
9
  import { __ } from '@wordpress/i18n';
5
- import { ToolbarButton } from '@wordpress/components';
6
- import { arrowLeft, arrowUp, arrowDown, arrowRight } from '@wordpress/icons';
10
+ import {
11
+ VisuallyHidden,
12
+ ToolbarButton,
13
+ ToolbarGroup,
14
+ } from '@wordpress/components';
15
+ import {
16
+ chevronLeft,
17
+ chevronUp,
18
+ chevronDown,
19
+ chevronRight,
20
+ } from '@wordpress/icons';
7
21
  import { useDispatch } from '@wordpress/data';
22
+ import { useInstanceId } from '@wordpress/compose';
8
23
 
9
24
  /**
10
25
  * Internal dependencies
@@ -39,74 +54,129 @@ export function GridItemMovers( {
39
54
 
40
55
  return (
41
56
  <BlockControls group="parent">
57
+ <ToolbarGroup className="block-editor-grid-item-mover__move-button-container">
58
+ <GridItemMover
59
+ className="is-left-button"
60
+ icon={ chevronLeft }
61
+ label={ __( 'Move left' ) }
62
+ description={ __( 'Move left' ) }
63
+ isDisabled={ columnStart <= 1 }
64
+ onClick={ () => {
65
+ onChange( {
66
+ columnStart: columnStart - 1,
67
+ } );
68
+ __unstableMarkNextChangeAsNotPersistent();
69
+ moveBlocksToPosition(
70
+ [ blockClientId ],
71
+ gridClientId,
72
+ gridClientId,
73
+ getNumberOfBlocksBeforeCell(
74
+ columnStart - 1,
75
+ rowStart
76
+ )
77
+ );
78
+ } }
79
+ />
80
+ <div className="block-editor-grid-item-mover__move-vertical-button-container">
81
+ <GridItemMover
82
+ className="is-up-button"
83
+ icon={ chevronUp }
84
+ label={ __( 'Move up' ) }
85
+ description={ __( 'Move up' ) }
86
+ isDisabled={ rowStart <= 1 }
87
+ onClick={ () => {
88
+ onChange( {
89
+ rowStart: rowStart - 1,
90
+ } );
91
+ __unstableMarkNextChangeAsNotPersistent();
92
+ moveBlocksToPosition(
93
+ [ blockClientId ],
94
+ gridClientId,
95
+ gridClientId,
96
+ getNumberOfBlocksBeforeCell(
97
+ columnStart,
98
+ rowStart - 1
99
+ )
100
+ );
101
+ } }
102
+ />
103
+ <GridItemMover
104
+ className="is-down-button"
105
+ icon={ chevronDown }
106
+ label={ __( 'Move down' ) }
107
+ description={ __( 'Move down' ) }
108
+ isDisabled={ rowCount && rowEnd >= rowCount }
109
+ onClick={ () => {
110
+ onChange( {
111
+ rowStart: rowStart + 1,
112
+ } );
113
+ __unstableMarkNextChangeAsNotPersistent();
114
+ moveBlocksToPosition(
115
+ [ blockClientId ],
116
+ gridClientId,
117
+ gridClientId,
118
+ getNumberOfBlocksBeforeCell(
119
+ columnStart,
120
+ rowStart + 1
121
+ )
122
+ );
123
+ } }
124
+ />
125
+ </div>
126
+ <GridItemMover
127
+ className="is-right-button"
128
+ icon={ chevronRight }
129
+ label={ __( 'Move right' ) }
130
+ description={ __( 'Move right' ) }
131
+ isDisabled={ columnCount && columnEnd >= columnCount }
132
+ onClick={ () => {
133
+ onChange( {
134
+ columnStart: columnStart + 1,
135
+ } );
136
+ __unstableMarkNextChangeAsNotPersistent();
137
+ moveBlocksToPosition(
138
+ [ blockClientId ],
139
+ gridClientId,
140
+ gridClientId,
141
+ getNumberOfBlocksBeforeCell(
142
+ columnStart + 1,
143
+ rowStart
144
+ )
145
+ );
146
+ } }
147
+ />
148
+ </ToolbarGroup>
149
+ </BlockControls>
150
+ );
151
+ }
152
+
153
+ function GridItemMover( {
154
+ className,
155
+ icon,
156
+ label,
157
+ isDisabled,
158
+ onClick,
159
+ description,
160
+ } ) {
161
+ const instanceId = useInstanceId( GridItemMover );
162
+ const descriptionId = `block-editor-grid-item-mover-button__description-${ instanceId }`;
163
+ return (
164
+ <>
42
165
  <ToolbarButton
43
- icon={ arrowUp }
44
- label={ __( 'Move block up' ) }
45
- disabled={ rowStart <= 1 }
46
- onClick={ () => {
47
- onChange( {
48
- rowStart: rowStart - 1,
49
- } );
50
- __unstableMarkNextChangeAsNotPersistent();
51
- moveBlocksToPosition(
52
- [ blockClientId ],
53
- gridClientId,
54
- gridClientId,
55
- getNumberOfBlocksBeforeCell( columnStart, rowStart - 1 )
56
- );
57
- } }
58
- />
59
- <ToolbarButton
60
- icon={ arrowDown }
61
- label={ __( 'Move block down' ) }
62
- disabled={ rowCount && rowEnd >= rowCount }
63
- onClick={ () => {
64
- onChange( {
65
- rowStart: rowStart + 1,
66
- } );
67
- __unstableMarkNextChangeAsNotPersistent();
68
- moveBlocksToPosition(
69
- [ blockClientId ],
70
- gridClientId,
71
- gridClientId,
72
- getNumberOfBlocksBeforeCell( columnStart, rowStart + 1 )
73
- );
74
- } }
75
- />
76
- <ToolbarButton
77
- icon={ arrowLeft }
78
- label={ __( 'Move block left' ) }
79
- disabled={ columnStart <= 1 }
80
- onClick={ () => {
81
- onChange( {
82
- columnStart: columnStart - 1,
83
- } );
84
- __unstableMarkNextChangeAsNotPersistent();
85
- moveBlocksToPosition(
86
- [ blockClientId ],
87
- gridClientId,
88
- gridClientId,
89
- getNumberOfBlocksBeforeCell( columnStart - 1, rowStart )
90
- );
91
- } }
92
- />
93
- <ToolbarButton
94
- icon={ arrowRight }
95
- label={ __( 'Move block right' ) }
96
- disabled={ columnCount && columnEnd >= columnCount }
97
- onClick={ () => {
98
- onChange( {
99
- columnStart: columnStart + 1,
100
- } );
101
- __unstableMarkNextChangeAsNotPersistent();
102
- moveBlocksToPosition(
103
- [ blockClientId ],
104
- gridClientId,
105
- gridClientId,
106
- getNumberOfBlocksBeforeCell( columnStart + 1, rowStart )
107
- );
108
- } }
166
+ className={ clsx(
167
+ 'block-editor-grid-item-mover-button',
168
+ className
169
+ ) }
170
+ icon={ icon }
171
+ label={ label }
172
+ aria-describedby={ descriptionId }
173
+ onClick={ isDisabled ? null : onClick }
174
+ disabled={ isDisabled }
175
+ accessibleWhenDisabled
109
176
  />
110
- </BlockControls>
177
+ <VisuallyHidden id={ descriptionId }>
178
+ { description }
179
+ </VisuallyHidden>
180
+ </>
111
181
  );
112
182
  }
@@ -89,7 +89,7 @@ const GridVisualizerGrid = forwardRef(
89
89
  'is-dropping-allowed': isDroppingAllowed,
90
90
  } ) }
91
91
  clientId={ gridClientId }
92
- __unstablePopoverSlot="block-toolbar"
92
+ __unstablePopoverSlot="__unstable-block-tools-after"
93
93
  >
94
94
  <div
95
95
  ref={ ref }
@@ -96,3 +96,117 @@
96
96
  }
97
97
  }
98
98
 
99
+ .block-editor-grid-item-mover__move-button-container {
100
+ display: flex;
101
+ padding: 0;
102
+ border: none;
103
+ justify-content: center;
104
+
105
+ .block-editor-grid-item-mover-button {
106
+ width: $block-toolbar-height * 0.5;
107
+ min-width: 0 !important; // overrides default button width.
108
+ overflow: hidden;
109
+ padding-left: 0;
110
+ padding-right: 0;
111
+
112
+ svg {
113
+ min-width: $grid-unit-30;
114
+ }
115
+
116
+ // Focus and toggle pseudo elements.
117
+ &::before {
118
+ content: "";
119
+ position: absolute;
120
+ display: block;
121
+ border-radius: $radius-block-ui;
122
+ height: $grid-unit-40;
123
+
124
+ // Position the focus rectangle.
125
+ left: $grid-unit-10;
126
+ right: $grid-unit-10;
127
+ z-index: -1;
128
+
129
+ // Animate in.
130
+ animation: components-button__appear-animation 0.1s ease;
131
+ animation-fill-mode: forwards;
132
+ @include reduce-motion("animation");
133
+ }
134
+
135
+ // Don't show the focus inherited by the Button component.
136
+ &:focus,
137
+ &:focus:enabled,
138
+ &:focus::before {
139
+ box-shadow: none;
140
+ outline: none;
141
+ }
142
+
143
+ &:focus-visible::before {
144
+ @include block-toolbar-button-style__focus();
145
+ }
146
+ }
147
+ }
148
+
149
+
150
+ .block-editor-grid-item-mover__move-vertical-button-container {
151
+ display: flex;
152
+ position: relative;
153
+ @include break-small() {
154
+ flex-direction: column;
155
+ justify-content: space-around;
156
+
157
+ > .block-editor-grid-item-mover-button.block-editor-grid-item-mover-button {
158
+ height: $block-toolbar-height * 0.5 - $grid-unit-05;
159
+ width: 100%;
160
+ min-width: 0 !important; // overrides default button width.
161
+
162
+ // Focus style.
163
+ &::before {
164
+ height: calc(100% - 4px);
165
+ }
166
+ }
167
+
168
+ .block-editor-grid-item-mover-button.is-up-button svg,
169
+ .block-editor-grid-item-mover-button.is-down-button svg {
170
+ flex-shrink: 0;
171
+ height: $block-toolbar-height * 0.5 - $grid-unit-05;
172
+ }
173
+ }
174
+ }
175
+
176
+ .show-icon-labels {
177
+
178
+ .block-editor-grid-item-mover-button.block-editor-grid-item-mover-button.is-left-button {
179
+ border-right: 1px solid $gray-700;
180
+ padding-right: 12px;
181
+ }
182
+
183
+ .block-editor-grid-item-mover-button.block-editor-grid-item-mover-button.is-right-button {
184
+ border-left: 1px solid $gray-700;
185
+ padding-left: 12px;
186
+ }
187
+
188
+
189
+ .block-editor-grid-item-mover__move-vertical-button-container {
190
+ &::before {
191
+ @include break-small() {
192
+ content: "";
193
+ height: $border-width;
194
+ width: 100%;
195
+ background: $gray-200;
196
+ position: absolute;
197
+ top: 50%;
198
+ left: 50%;
199
+ // With Top toolbar enabled, this separator has a smaller width. Translating the
200
+ // X axis allows to make the separator always centered regardless of its width.
201
+ transform: translate(-50%, 0);
202
+ margin-top: -$border-width * 0.5;
203
+ }
204
+
205
+ @include break-medium {
206
+ background: $gray-900;
207
+ }
208
+ }
209
+ }
210
+
211
+ }
212
+