@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
@@ -10,18 +10,9 @@ import {
10
10
  VisuallyHidden,
11
11
  ToggleControl,
12
12
  __experimentalVStack as VStack,
13
- privateApis as componentsPrivateApis,
13
+ CustomSelectControl,
14
14
  } from '@wordpress/components';
15
15
 
16
- /**
17
- * Internal dependencies
18
- */
19
- import { unlock } from '../../lock-unlock';
20
-
21
- const { CustomSelectControlV2Legacy: CustomSelectControl } = unlock(
22
- componentsPrivateApis
23
- );
24
-
25
16
  // So that we illustrate the different formats in the dropdown properly, show a date that is
26
17
  // somwhat recent, has a day greater than 12, and a month with more than three letters.
27
18
  const exampleDate = new Date();
@@ -126,7 +117,7 @@ function NonDefaultControls( { format, onChange } ) {
126
117
  name: __( 'Custom' ),
127
118
  className:
128
119
  'block-editor-date-format-picker__custom-format-select-control__custom-option',
129
- __experimentalHint: __( 'Enter your own date format' ),
120
+ hint: __( 'Enter your own date format' ),
130
121
  };
131
122
 
132
123
  const [ isCustom, setIsCustom ] = useState(
@@ -24,10 +24,14 @@ import { store as blockEditorStore } from '../../store';
24
24
  export const ZWNBSP = '\ufeff';
25
25
 
26
26
  export default function DefaultBlockAppender( { rootClientId } ) {
27
- const { showPrompt, isLocked, placeholder } = useSelect(
27
+ const { showPrompt, isLocked, placeholder, isManualGrid } = useSelect(
28
28
  ( select ) => {
29
- const { getBlockCount, getSettings, getTemplateLock } =
30
- select( blockEditorStore );
29
+ const {
30
+ getBlockCount,
31
+ getSettings,
32
+ getTemplateLock,
33
+ getBlockAttributes,
34
+ } = select( blockEditorStore );
31
35
 
32
36
  const isEmpty = ! getBlockCount( rootClientId );
33
37
  const { bodyPlaceholder } = getSettings();
@@ -36,6 +40,9 @@ export default function DefaultBlockAppender( { rootClientId } ) {
36
40
  showPrompt: isEmpty,
37
41
  isLocked: !! getTemplateLock( rootClientId ),
38
42
  placeholder: bodyPlaceholder,
43
+ isManualGrid:
44
+ getBlockAttributes( rootClientId )?.layout
45
+ ?.isManualPlacement,
39
46
  };
40
47
  },
41
48
  [ rootClientId ]
@@ -43,7 +50,7 @@ export default function DefaultBlockAppender( { rootClientId } ) {
43
50
 
44
51
  const { insertDefaultBlock, startTyping } = useDispatch( blockEditorStore );
45
52
 
46
- if ( isLocked ) {
53
+ if ( isLocked || isManualGrid ) {
47
54
  return null;
48
55
  }
49
56
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { privateApis as componentsPrivateApis } from '@wordpress/components';
4
+ import { CustomSelectControl } from '@wordpress/components';
5
5
  import { useMemo } from '@wordpress/element';
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
 
@@ -9,11 +9,7 @@ import { __, sprintf } from '@wordpress/i18n';
9
9
  * Internal dependencies
10
10
  */
11
11
  import { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';
12
- import { unlock } from '../../lock-unlock';
13
12
 
14
- const { CustomSelectControlV2Legacy: CustomSelectControl } = unlock(
15
- componentsPrivateApis
16
- );
17
13
  /**
18
14
  * Adjusts font appearance field label in case either font styles or weights
19
15
  * are disabled.
@@ -451,6 +451,9 @@ function BackgroundSizeControls( {
451
451
  const positionValue =
452
452
  style?.background?.backgroundPosition ||
453
453
  inheritedValue?.background?.backgroundPosition;
454
+ const attachmentValue =
455
+ style?.background?.backgroundAttachment ||
456
+ inheritedValue?.background?.backgroundAttachment;
454
457
 
455
458
  /*
456
459
  * An `undefined` value is replaced with any supplied
@@ -546,8 +549,17 @@ function BackgroundSizeControls( {
546
549
  )
547
550
  );
548
551
 
552
+ const toggleScrollWithPage = () =>
553
+ onChange(
554
+ setImmutably(
555
+ style,
556
+ [ 'background', 'backgroundAttachment' ],
557
+ attachmentValue === 'fixed' ? 'scroll' : 'fixed'
558
+ )
559
+ );
560
+
549
561
  return (
550
- <VStack spacing={ 3 } className="single-column">
562
+ <VStack spacing={ 4 } className="single-column">
551
563
  <FocalPointPicker
552
564
  __next40pxDefaultSize
553
565
  __nextHasNoMarginBottom
@@ -556,6 +568,14 @@ function BackgroundSizeControls( {
556
568
  value={ backgroundPositionToCoords( positionValue ) }
557
569
  onChange={ updateBackgroundPosition }
558
570
  />
571
+ <ToggleControl
572
+ label={ __( 'Fixed background' ) }
573
+ checked={ attachmentValue === 'fixed' }
574
+ onChange={ toggleScrollWithPage }
575
+ help={ __(
576
+ 'Whether your image should scroll with the page or stay fixed in place.'
577
+ ) }
578
+ />
559
579
  <ToggleGroupControl
560
580
  size="__unstable-large"
561
581
  label={ __( 'Size' ) }
@@ -85,7 +85,11 @@ const VALID_SETTINGS = [
85
85
  ];
86
86
 
87
87
  export const useGlobalStylesReset = () => {
88
- const { user: config, setUserConfig } = useContext( GlobalStylesContext );
88
+ const { user, setUserConfig } = useContext( GlobalStylesContext );
89
+ const config = {
90
+ settings: user.settings,
91
+ styles: user.styles,
92
+ };
89
93
  const canReset = !! config && ! fastDeepEqual( config, EMPTY_CONFIG );
90
94
  return [
91
95
  canReset,
@@ -103,8 +103,13 @@
103
103
  .block-editor-global-styles-background-panel__image-tools-panel-item {
104
104
  border: 1px solid $gray-300;
105
105
  border-radius: 2px;
106
+
106
107
  // Full width. ToolsPanel lays out children in a grid.
107
108
  grid-column: 1 / -1;
109
+
110
+ // Ensure the dropzone is positioned to the size of the item.
111
+ position: relative;
112
+
108
113
  // Since there is no option to skip rendering the drag'n'drop icon in drop
109
114
  // zone, we hide it for now.
110
115
  .components-drop-zone__content-icon {
@@ -192,15 +197,22 @@
192
197
  .components-toggle-control {
193
198
  margin-bottom: 0;
194
199
  }
200
+
195
201
  .components-focal-point-picker-wrapper {
196
202
  background-color: $gray-100;
197
203
  width: 100%;
198
204
  border-radius: $radius-block-ui;
199
205
  border: $border-width solid $gray-300;
200
206
  }
207
+
201
208
  .components-focal-point-picker__media--image {
202
209
  max-height: 180px;
203
210
  }
211
+
212
+ // Override focal picker to avoid a double border.
213
+ .components-focal-point-picker::after {
214
+ content: none;
215
+ }
204
216
  }
205
217
 
206
218
  .block-editor-global-styles-background-panel__hidden-tools-panel-item {
@@ -6,6 +6,8 @@ import {
6
6
  getFluidTypographyOptionsFromSettings,
7
7
  getMergedFontFamiliesAndFontFamilyFaces,
8
8
  findNearestFontWeight,
9
+ findNearestFontStyle,
10
+ findNearestStyleAndWeight,
9
11
  } from '../typography-utils';
10
12
 
11
13
  describe( 'typography utils', () => {
@@ -951,6 +953,329 @@ describe( 'typography utils', () => {
951
953
  );
952
954
  } );
953
955
 
956
+ describe( 'findNearestFontStyle', () => {
957
+ [
958
+ {
959
+ message:
960
+ 'should return empty string when newFontStyleValue is `undefined`',
961
+ availableFontStyles: undefined,
962
+ newFontStyleValue: undefined,
963
+ expected: '',
964
+ },
965
+ {
966
+ message:
967
+ 'should return newFontStyleValue value when availableFontStyles is empty',
968
+ availableFontStyles: [],
969
+ newFontStyleValue: 'italic',
970
+ expected: 'italic',
971
+ },
972
+ {
973
+ message:
974
+ 'should return empty string if there is no new font style available',
975
+ availableFontStyles: [ { name: 'Normal', value: 'normal' } ],
976
+ newFontStyleValue: 'italic',
977
+ expected: '',
978
+ },
979
+ {
980
+ message:
981
+ 'should return empty string if the new font style is invalid',
982
+ availableFontStyles: [
983
+ { name: 'Regular', value: 'normal' },
984
+ { name: 'Italic', value: 'italic' },
985
+ ],
986
+ newFontStyleValue: 'not-valid',
987
+ expected: '',
988
+ },
989
+ {
990
+ message: 'should return italic if oblique is not available',
991
+ availableFontStyles: [
992
+ { name: 'Regular', value: 'normal' },
993
+ { name: 'Italic', value: 'italic' },
994
+ ],
995
+ newFontStyleValue: 'oblique',
996
+ expected: 'italic',
997
+ },
998
+ {
999
+ message: 'should return normal if normal is available',
1000
+ availableFontStyles: [
1001
+ { name: 'Regular', value: 'normal' },
1002
+ { name: 'Italic', value: 'italic' },
1003
+ ],
1004
+ newFontStyleValue: 'normal',
1005
+ expected: 'normal',
1006
+ },
1007
+ ].forEach(
1008
+ ( {
1009
+ message,
1010
+ availableFontStyles,
1011
+ newFontStyleValue,
1012
+ expected,
1013
+ } ) => {
1014
+ it( `${ message }`, () => {
1015
+ expect(
1016
+ findNearestFontStyle(
1017
+ availableFontStyles,
1018
+ newFontStyleValue
1019
+ )
1020
+ ).toEqual( expected );
1021
+ } );
1022
+ }
1023
+ );
1024
+ } );
1025
+
1026
+ describe( 'findNearestStyleAndWeight', () => {
1027
+ [
1028
+ {
1029
+ message: 'should return empty object when all values are empty',
1030
+ fontFamilyFaces: [],
1031
+ fontStyle: undefined,
1032
+ fontWeight: undefined,
1033
+ expected: {},
1034
+ },
1035
+ {
1036
+ message:
1037
+ 'should return original fontStyle and fontWeight when fontFamilyFaces is empty',
1038
+ fontFamilyFaces: [],
1039
+ fontStyle: 'italic',
1040
+ fontWeight: '700',
1041
+ expected: {
1042
+ nearestFontStyle: 'italic',
1043
+ nearestFontWeight: '700',
1044
+ },
1045
+ },
1046
+ {
1047
+ message:
1048
+ 'should return undefined values if both fontStyle and fontWeight are not available',
1049
+ fontFamilyFaces: [
1050
+ {
1051
+ fontFamily: 'ABeeZee',
1052
+ fontStyle: 'italic',
1053
+ fontWeight: '400',
1054
+ src: [
1055
+ 'file:./assets/fonts/esDT31xSG-6AGleN2tCkkJUCGpG-GQ.woff2',
1056
+ ],
1057
+ },
1058
+ ],
1059
+ fontStyle: undefined,
1060
+ fontWeight: undefined,
1061
+ expected: {
1062
+ nearestFontStyle: undefined,
1063
+ nearestFontWeight: undefined,
1064
+ },
1065
+ },
1066
+ {
1067
+ message:
1068
+ 'should return nearest fontStyle and fontWeight for normal/400',
1069
+ fontFamilyFaces: [
1070
+ {
1071
+ fontFamily: 'IBM Plex Mono',
1072
+ fontStyle: 'normal',
1073
+ fontWeight: '400',
1074
+ src: [
1075
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
1076
+ ],
1077
+ },
1078
+ {
1079
+ fontFamily: 'IBM Plex Mono',
1080
+ fontStyle: 'italic',
1081
+ fontWeight: '400',
1082
+ src: [
1083
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2',
1084
+ ],
1085
+ },
1086
+ {
1087
+ fontFamily: 'IBM Plex Mono',
1088
+ fontStyle: 'normal',
1089
+ fontWeight: '700',
1090
+ src: [
1091
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
1092
+ ],
1093
+ },
1094
+ ],
1095
+ fontStyle: 'normal',
1096
+ fontWeight: '400',
1097
+ expected: {
1098
+ nearestFontStyle: 'normal',
1099
+ nearestFontWeight: '400',
1100
+ },
1101
+ },
1102
+ {
1103
+ message:
1104
+ 'should return nearest fontStyle and fontWeight for normal/100',
1105
+ fontFamilyFaces: [
1106
+ {
1107
+ fontFamily: 'IBM Plex Mono',
1108
+ fontStyle: 'normal',
1109
+ fontWeight: '400',
1110
+ src: [
1111
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
1112
+ ],
1113
+ },
1114
+ {
1115
+ fontFamily: 'IBM Plex Mono',
1116
+ fontStyle: 'italic',
1117
+ fontWeight: '400',
1118
+ src: [
1119
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2',
1120
+ ],
1121
+ },
1122
+ {
1123
+ fontFamily: 'IBM Plex Mono',
1124
+ fontStyle: 'normal',
1125
+ fontWeight: '700',
1126
+ src: [
1127
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
1128
+ ],
1129
+ },
1130
+ ],
1131
+ fontStyle: 'normal',
1132
+ fontWeight: '100',
1133
+ expected: {
1134
+ nearestFontStyle: 'normal',
1135
+ nearestFontWeight: '400',
1136
+ },
1137
+ },
1138
+ {
1139
+ message:
1140
+ 'should return nearest fontStyle and fontWeight for italic/900',
1141
+ fontFamilyFaces: [
1142
+ {
1143
+ fontFamily: 'IBM Plex Mono',
1144
+ fontStyle: 'normal',
1145
+ fontWeight: '400',
1146
+ src: [
1147
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
1148
+ ],
1149
+ },
1150
+ {
1151
+ fontFamily: 'IBM Plex Mono',
1152
+ fontStyle: 'italic',
1153
+ fontWeight: '400',
1154
+ src: [
1155
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2',
1156
+ ],
1157
+ },
1158
+ {
1159
+ fontFamily: 'IBM Plex Mono',
1160
+ fontStyle: 'normal',
1161
+ fontWeight: '700',
1162
+ src: [
1163
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
1164
+ ],
1165
+ },
1166
+ ],
1167
+ fontStyle: 'italic',
1168
+ fontWeight: '900',
1169
+ expected: {
1170
+ nearestFontStyle: 'italic',
1171
+ nearestFontWeight: '700',
1172
+ },
1173
+ },
1174
+ {
1175
+ message:
1176
+ 'should return nearest fontStyle and fontWeight for oblique/600',
1177
+ fontFamilyFaces: [
1178
+ {
1179
+ fontFamily: 'IBM Plex Mono',
1180
+ fontStyle: 'normal',
1181
+ fontWeight: '400',
1182
+ src: [
1183
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
1184
+ ],
1185
+ },
1186
+ {
1187
+ fontFamily: 'IBM Plex Mono',
1188
+ fontStyle: 'italic',
1189
+ fontWeight: '700',
1190
+ src: [
1191
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
1192
+ ],
1193
+ },
1194
+ ],
1195
+ fontStyle: 'oblique',
1196
+ fontWeight: '600',
1197
+ expected: {
1198
+ nearestFontStyle: 'italic',
1199
+ nearestFontWeight: '700',
1200
+ },
1201
+ },
1202
+ {
1203
+ message:
1204
+ 'should return nearest fontStyle and fontWeight for 300 font weight and empty font style',
1205
+ fontFamilyFaces: [
1206
+ {
1207
+ fontFamily: 'IBM Plex Mono',
1208
+ fontStyle: 'normal',
1209
+ fontWeight: '400',
1210
+ src: [
1211
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
1212
+ ],
1213
+ },
1214
+ {
1215
+ fontFamily: 'IBM Plex Mono',
1216
+ fontStyle: 'italic',
1217
+ fontWeight: '700',
1218
+ src: [
1219
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
1220
+ ],
1221
+ },
1222
+ ],
1223
+ fontStyle: undefined,
1224
+ fontWeight: '300',
1225
+ expected: {
1226
+ nearestFontStyle: 'normal',
1227
+ nearestFontWeight: '400',
1228
+ },
1229
+ },
1230
+ {
1231
+ message:
1232
+ 'should return nearest fontStyle and fontWeight for oblique font style and empty font weight',
1233
+ fontFamilyFaces: [
1234
+ {
1235
+ fontFamily: 'IBM Plex Mono',
1236
+ fontStyle: 'normal',
1237
+ fontWeight: '400',
1238
+ src: [
1239
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
1240
+ ],
1241
+ },
1242
+ {
1243
+ fontFamily: 'IBM Plex Mono',
1244
+ fontStyle: 'italic',
1245
+ fontWeight: '700',
1246
+ src: [
1247
+ 'file:./assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
1248
+ ],
1249
+ },
1250
+ ],
1251
+ fontStyle: 'oblique',
1252
+ fontWeight: undefined,
1253
+ expected: {
1254
+ nearestFontStyle: 'italic',
1255
+ nearestFontWeight: '400',
1256
+ },
1257
+ },
1258
+ ].forEach(
1259
+ ( {
1260
+ message,
1261
+ fontFamilyFaces,
1262
+ fontStyle,
1263
+ fontWeight,
1264
+ expected,
1265
+ } ) => {
1266
+ it( `${ message }`, () => {
1267
+ expect(
1268
+ findNearestStyleAndWeight(
1269
+ fontFamilyFaces,
1270
+ fontStyle,
1271
+ fontWeight
1272
+ )
1273
+ ).toEqual( expected );
1274
+ } );
1275
+ }
1276
+ );
1277
+ } );
1278
+
954
1279
  describe( 'typography utils', () => {
955
1280
  [
956
1281
  {
@@ -107,6 +107,7 @@ describe( 'global styles renderer', () => {
107
107
  },
108
108
  },
109
109
  selector: ROOT_BLOCK_SELECTOR,
110
+ skipSelectorWrapper: true,
110
111
  },
111
112
  {
112
113
  styles: {
@@ -128,6 +129,7 @@ describe( 'global styles renderer', () => {
128
129
  },
129
130
  },
130
131
  selector: ELEMENTS.link,
132
+ skipSelectorWrapper: true,
131
133
  },
132
134
  {
133
135
  styles: {
@@ -480,7 +482,7 @@ describe( 'global styles renderer', () => {
480
482
  };
481
483
 
482
484
  expect( toStyles( tree, blockSelectors ) ).toEqual(
483
- ':where(body) {margin: 0;}.is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-constrained > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-constrained > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) { max-width: var(--wp--style--global--content-size); margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignwide { max-width: var(--wp--style--global--wide-size); }body .is-layout-flex { display:flex; }.is-layout-flex { flex-wrap: wrap; align-items: center; }.is-layout-flex > :is(*, div) { margin: 0; }body .is-layout-grid { display:grid; }.is-layout-grid > :is(*, div) { margin: 0; }:root :where(body){background-color: red;margin: 10px;padding: 10px;}:root :where(a:where(:not(.wp-element-button))){color: blue;}a:where(:not(.wp-element-button)):hover{color: orange;}a:where(:not(.wp-element-button)):focus{color: orange;}:root :where(h1){font-size: 42px;}:root :where(.wp-block-group){margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}:root :where(h1,h2,h3,h4,h5,h6){color: orange;}:root :where(h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button))){color: hotpink;}h1 a:where(:not(.wp-element-button)):hover,h2 a:where(:not(.wp-element-button)):hover,h3 a:where(:not(.wp-element-button)):hover,h4 a:where(:not(.wp-element-button)):hover,h5 a:where(:not(.wp-element-button)):hover,h6 a:where(:not(.wp-element-button)):hover{color: red;}h1 a:where(:not(.wp-element-button)):focus,h2 a:where(:not(.wp-element-button)):focus,h3 a:where(:not(.wp-element-button)):focus,h4 a:where(:not(.wp-element-button)):focus,h5 a:where(:not(.wp-element-button)):focus,h6 a:where(:not(.wp-element-button)):focus{color: red;}:root :where(.wp-block-image img, .wp-block-image .wp-crop-area){border-radius: 9999px;}:root :where(.wp-block-image){color: red;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.has-white-color{color: var(--wp--preset--color--white) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}h1.has-blue-color,h2.has-blue-color,h3.has-blue-color,h4.has-blue-color,h5.has-blue-color,h6.has-blue-color{color: var(--wp--preset--color--blue) !important;}h1.has-blue-background-color,h2.has-blue-background-color,h3.has-blue-background-color,h4.has-blue-background-color,h5.has-blue-background-color,h6.has-blue-background-color{background-color: var(--wp--preset--color--blue) !important;}h1.has-blue-border-color,h2.has-blue-border-color,h3.has-blue-border-color,h4.has-blue-border-color,h5.has-blue-border-color,h6.has-blue-border-color{border-color: var(--wp--preset--color--blue) !important;}'
485
+ ':where(body) {margin: 0;}.is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-constrained > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-constrained > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) { max-width: var(--wp--style--global--content-size); margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignwide { max-width: var(--wp--style--global--wide-size); }body .is-layout-flex { display:flex; }.is-layout-flex { flex-wrap: wrap; align-items: center; }.is-layout-flex > :is(*, div) { margin: 0; }body .is-layout-grid { display:grid; }.is-layout-grid > :is(*, div) { margin: 0; }body{background-color: red;margin: 10px;padding: 10px;}a:where(:not(.wp-element-button)){color: blue;}:root :where(a:where(:not(.wp-element-button)):hover){color: orange;}:root :where(a:where(:not(.wp-element-button)):focus){color: orange;}h1{font-size: 42px;}:root :where(.wp-block-group){margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}:root :where(h1,h2,h3,h4,h5,h6){color: orange;}:root :where(h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button))){color: hotpink;}:root :where(h1 a:where(:not(.wp-element-button)):hover,h2 a:where(:not(.wp-element-button)):hover,h3 a:where(:not(.wp-element-button)):hover,h4 a:where(:not(.wp-element-button)):hover,h5 a:where(:not(.wp-element-button)):hover,h6 a:where(:not(.wp-element-button)):hover){color: red;}:root :where(h1 a:where(:not(.wp-element-button)):focus,h2 a:where(:not(.wp-element-button)):focus,h3 a:where(:not(.wp-element-button)):focus,h4 a:where(:not(.wp-element-button)):focus,h5 a:where(:not(.wp-element-button)):focus,h6 a:where(:not(.wp-element-button)):focus){color: red;}:root :where(.wp-block-image img, .wp-block-image .wp-crop-area){border-radius: 9999px;}:root :where(.wp-block-image){color: red;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.has-white-color{color: var(--wp--preset--color--white) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}h1.has-blue-color,h2.has-blue-color,h3.has-blue-color,h4.has-blue-color,h5.has-blue-color,h6.has-blue-color{color: var(--wp--preset--color--blue) !important;}h1.has-blue-background-color,h2.has-blue-background-color,h3.has-blue-background-color,h4.has-blue-background-color,h5.has-blue-background-color,h6.has-blue-background-color{background-color: var(--wp--preset--color--blue) !important;}h1.has-blue-border-color,h2.has-blue-border-color,h3.has-blue-border-color,h4.has-blue-border-color,h5.has-blue-border-color,h6.has-blue-border-color{border-color: var(--wp--preset--color--blue) !important;}'
484
486
  );
485
487
  } );
486
488
 
@@ -25,9 +25,8 @@ import { getValueFromVariable, useToolsPanelDropdownMenuProps } from './utils';
25
25
  import { setImmutably } from '../../utils/object';
26
26
  import {
27
27
  getMergedFontFamiliesAndFontFamilyFaces,
28
- findNearestFontWeight,
28
+ findNearestStyleAndWeight,
29
29
  } from './typography-utils';
30
- import { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';
31
30
 
32
31
  const MIN_TEXT_COLUMNS = 1;
33
32
  const MAX_TEXT_COLUMNS = 6;
@@ -236,57 +235,50 @@ export default function TypographyPanel( {
236
235
  const hasFontWeights = settings?.typography?.fontWeight;
237
236
  const fontStyle = decodeValue( inheritedValue?.typography?.fontStyle );
238
237
  const fontWeight = decodeValue( inheritedValue?.typography?.fontWeight );
239
- const setFontAppearance = ( {
240
- fontStyle: newFontStyle,
241
- fontWeight: newFontWeight,
242
- } ) => {
243
- onChange( {
244
- ...value,
245
- typography: {
246
- ...value?.typography,
247
- fontStyle: newFontStyle || undefined,
248
- fontWeight: newFontWeight || undefined,
249
- },
250
- } );
251
- };
238
+ const { nearestFontStyle, nearestFontWeight } = findNearestStyleAndWeight(
239
+ fontFamilyFaces,
240
+ fontStyle,
241
+ fontWeight
242
+ );
243
+ const setFontAppearance = useCallback(
244
+ ( { fontStyle: newFontStyle, fontWeight: newFontWeight } ) => {
245
+ // Only update the font style and weight if they have changed.
246
+ if ( newFontStyle !== fontStyle || newFontWeight !== fontWeight ) {
247
+ onChange( {
248
+ ...value,
249
+ typography: {
250
+ ...value?.typography,
251
+ fontStyle: newFontStyle || undefined,
252
+ fontWeight: newFontWeight || undefined,
253
+ },
254
+ } );
255
+ }
256
+ },
257
+ [ fontStyle, fontWeight, onChange, value ]
258
+ );
252
259
  const hasFontAppearance = () =>
253
260
  !! value?.typography?.fontStyle || !! value?.typography?.fontWeight;
254
- const resetFontAppearance = () => {
261
+ const resetFontAppearance = useCallback( () => {
255
262
  setFontAppearance( {} );
256
- };
263
+ }, [ setFontAppearance ] );
257
264
 
258
- // Check if previous font style and weight values are available in the new font family
265
+ // Check if previous font style and weight values are available in the new font family.
259
266
  useEffect( () => {
260
- const { fontStyles, fontWeights, isSystemFont } =
261
- getFontStylesAndWeights( fontFamilyFaces );
262
- const hasFontStyle = fontStyles?.some(
263
- ( { value: fs } ) => fs === fontStyle
264
- );
265
- const hasFontWeight = fontWeights?.some(
266
- ( { value: fw } ) => fw === fontWeight
267
- );
268
-
269
- // Try to set nearest available font weight
270
- if ( ! hasFontWeight && fontWeight ) {
267
+ if ( nearestFontStyle && nearestFontWeight ) {
271
268
  setFontAppearance( {
272
- fontStyle,
273
- fontWeight: findNearestFontWeight( fontWeights, fontWeight ),
269
+ fontStyle: nearestFontStyle,
270
+ fontWeight: nearestFontWeight,
274
271
  } );
275
- }
276
-
277
- // Set the same weight and style values if the font family is a system font or if both are the same
278
- if ( isSystemFont || ( hasFontStyle && hasFontWeight ) ) {
279
- setFontAppearance( {
280
- fontStyle,
281
- fontWeight,
282
- } );
283
- }
284
-
285
- // Reset font appearance if the font family does not have the selected font style
286
- if ( ! hasFontStyle ) {
272
+ } else {
273
+ // Reset font appearance if there are no available styles or weights.
287
274
  resetFontAppearance();
288
275
  }
289
- }, [ fontFamily ] );
276
+ }, [
277
+ nearestFontStyle,
278
+ nearestFontWeight,
279
+ resetFontAppearance,
280
+ setFontAppearance,
281
+ ] );
290
282
 
291
283
  // Line Height
292
284
  const hasLineHeightEnabled = useHasLineHeightControl( settings );