@wordpress/edit-site 5.2.0 → 5.3.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 (374) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/add-new-template/add-custom-generic-template-modal.js +8 -10
  3. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/add-custom-template-modal.js +0 -1
  5. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  6. package/build/components/add-new-template/new-template-part.js +5 -29
  7. package/build/components/add-new-template/new-template-part.js.map +1 -1
  8. package/build/components/add-new-template/utils.js +1 -9
  9. package/build/components/add-new-template/utils.js.map +1 -1
  10. package/build/components/app/index.js +2 -7
  11. package/build/components/app/index.js.map +1 -1
  12. package/build/components/block-editor/index.js +13 -11
  13. package/build/components/block-editor/index.js.map +1 -1
  14. package/build/components/block-editor/inserter-media-categories.js +237 -0
  15. package/build/components/block-editor/inserter-media-categories.js.map +1 -0
  16. package/build/components/canvas-spinner/index.js +20 -0
  17. package/build/components/canvas-spinner/index.js.map +1 -0
  18. package/build/components/create-template-part-modal/index.js +4 -2
  19. package/build/components/create-template-part-modal/index.js.map +1 -1
  20. package/build/components/editor/index.js +4 -2
  21. package/build/components/editor/index.js.map +1 -1
  22. package/build/components/error-boundary/index.js +2 -12
  23. package/build/components/error-boundary/index.js.map +1 -1
  24. package/build/components/error-boundary/warning.js +5 -28
  25. package/build/components/error-boundary/warning.js.map +1 -1
  26. package/build/components/global-styles/block-preview-panel.js +2 -2
  27. package/build/components/global-styles/block-preview-panel.js.map +1 -1
  28. package/build/components/global-styles/border-panel.js +17 -9
  29. package/build/components/global-styles/border-panel.js.map +1 -1
  30. package/build/components/global-styles/color-palette-panel.js +13 -7
  31. package/build/components/global-styles/color-palette-panel.js.map +1 -1
  32. package/build/components/global-styles/context-menu.js +39 -4
  33. package/build/components/global-styles/context-menu.js.map +1 -1
  34. package/build/components/global-styles/custom-css.js +65 -14
  35. package/build/components/global-styles/custom-css.js.map +1 -1
  36. package/build/components/global-styles/dimensions-panel.js +49 -31
  37. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  38. package/build/components/global-styles/global-styles-provider.js +13 -3
  39. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  40. package/build/components/global-styles/gradients-palette-panel.js +17 -11
  41. package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
  42. package/build/components/global-styles/hooks.js +21 -142
  43. package/build/components/global-styles/hooks.js.map +1 -1
  44. package/build/components/global-styles/index.js +0 -28
  45. package/build/components/global-styles/index.js.map +1 -1
  46. package/build/components/global-styles/palette.js +11 -4
  47. package/build/components/global-styles/palette.js.map +1 -1
  48. package/build/components/global-styles/preview.js +18 -15
  49. package/build/components/global-styles/preview.js.map +1 -1
  50. package/build/components/global-styles/screen-background-color.js +27 -13
  51. package/build/components/global-styles/screen-background-color.js.map +1 -1
  52. package/build/components/global-styles/screen-border.js +10 -4
  53. package/build/components/global-styles/screen-border.js.map +1 -1
  54. package/build/components/global-styles/screen-button-color.js +16 -9
  55. package/build/components/global-styles/screen-button-color.js.map +1 -1
  56. package/build/components/global-styles/screen-colors.js +43 -34
  57. package/build/components/global-styles/screen-colors.js.map +1 -1
  58. package/build/components/global-styles/screen-css.js +20 -8
  59. package/build/components/global-styles/screen-css.js.map +1 -1
  60. package/build/components/global-styles/screen-heading-color.js +23 -16
  61. package/build/components/global-styles/screen-heading-color.js.map +1 -1
  62. package/build/components/global-styles/screen-layout.js +3 -3
  63. package/build/components/global-styles/screen-layout.js.map +1 -1
  64. package/build/components/global-styles/screen-link-color.js +18 -11
  65. package/build/components/global-styles/screen-link-color.js.map +1 -1
  66. package/build/components/global-styles/screen-root.js +25 -9
  67. package/build/components/global-styles/screen-root.js.map +1 -1
  68. package/build/components/global-styles/screen-style-variations.js +8 -4
  69. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  70. package/build/components/global-styles/screen-text-color.js +14 -7
  71. package/build/components/global-styles/screen-text-color.js.map +1 -1
  72. package/build/components/global-styles/screen-typography.js +18 -12
  73. package/build/components/global-styles/screen-typography.js.map +1 -1
  74. package/build/components/global-styles/shadow-panel.js +196 -0
  75. package/build/components/global-styles/shadow-panel.js.map +1 -0
  76. package/build/components/global-styles/typography-panel.js +43 -29
  77. package/build/components/global-styles/typography-panel.js.map +1 -1
  78. package/build/components/global-styles/typography-preview.js +19 -9
  79. package/build/components/global-styles/typography-preview.js.map +1 -1
  80. package/build/components/global-styles/ui.js +85 -34
  81. package/build/components/global-styles/ui.js.map +1 -1
  82. package/build/components/global-styles/utils.js +5 -334
  83. package/build/components/global-styles/utils.js.map +1 -1
  84. package/build/components/global-styles-renderer/index.js +7 -5
  85. package/build/components/global-styles-renderer/index.js.map +1 -1
  86. package/build/components/header-edit-mode/document-actions/index.js +2 -2
  87. package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
  88. package/build/components/keyboard-shortcut-help-modal/index.js +0 -1
  89. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  90. package/build/components/layout/index.js +6 -8
  91. package/build/components/layout/index.js.map +1 -1
  92. package/build/components/list/actions/rename-menu-item.js +8 -11
  93. package/build/components/list/actions/rename-menu-item.js.map +1 -1
  94. package/build/components/{sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js → navigation-inspector/index.js} +1 -2
  95. package/build/components/navigation-inspector/index.js.map +1 -0
  96. package/build/components/{sidebar-edit-mode/navigation-menu-sidebar → navigation-inspector}/navigation-menu.js +13 -15
  97. package/build/components/navigation-inspector/navigation-menu.js.map +1 -0
  98. package/build/components/sidebar/index.js +3 -1
  99. package/build/components/sidebar/index.js.map +1 -1
  100. package/build/components/sidebar-edit-mode/global-styles-sidebar.js +3 -18
  101. package/build/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -1
  102. package/build/components/sidebar-edit-mode/index.js +1 -14
  103. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  104. package/build/components/sidebar-navigation-screen/index.js +3 -2
  105. package/build/components/sidebar-navigation-screen/index.js.map +1 -1
  106. package/build/components/sidebar-navigation-screen-main/index.js +23 -1
  107. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  108. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +35 -0
  109. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -0
  110. package/build/components/sidebar-navigation-screen-templates/index.js +3 -8
  111. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  112. package/build/components/site-hub/index.js +2 -2
  113. package/build/components/site-hub/index.js.map +1 -1
  114. package/build/components/site-icon/index.js +1 -1
  115. package/build/components/site-icon/index.js.map +1 -1
  116. package/build/components/style-book/index.js +7 -4
  117. package/build/components/style-book/index.js.map +1 -1
  118. package/build/components/template-part-converter/convert-to-template-part.js +5 -9
  119. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  120. package/build/experiments.js +19 -0
  121. package/build/experiments.js.map +1 -0
  122. package/build/hooks/push-changes-to-global-styles/index.js +65 -6
  123. package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
  124. package/build/index.js +53 -60
  125. package/build/index.js.map +1 -1
  126. package/build/store/selectors.js +7 -27
  127. package/build/store/selectors.js.map +1 -1
  128. package/build/store/utils.js +77 -0
  129. package/build/store/utils.js.map +1 -0
  130. package/build/utils/template-part-create.js +71 -0
  131. package/build/utils/template-part-create.js.map +1 -0
  132. package/build-module/components/add-new-template/add-custom-generic-template-modal.js +9 -11
  133. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -1
  134. package/build-module/components/add-new-template/add-custom-template-modal.js +0 -1
  135. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  136. package/build-module/components/add-new-template/new-template-part.js +4 -27
  137. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  138. package/build-module/components/add-new-template/utils.js +0 -5
  139. package/build-module/components/add-new-template/utils.js.map +1 -1
  140. package/build-module/components/app/index.js +2 -7
  141. package/build-module/components/app/index.js.map +1 -1
  142. package/build-module/components/block-editor/index.js +14 -12
  143. package/build-module/components/block-editor/index.js.map +1 -1
  144. package/build-module/components/block-editor/inserter-media-categories.js +225 -0
  145. package/build-module/components/block-editor/inserter-media-categories.js.map +1 -0
  146. package/build-module/components/canvas-spinner/index.js +12 -0
  147. package/build-module/components/canvas-spinner/index.js.map +1 -0
  148. package/build-module/components/create-template-part-modal/index.js +5 -3
  149. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  150. package/build-module/components/editor/index.js +3 -2
  151. package/build-module/components/editor/index.js.map +1 -1
  152. package/build-module/components/error-boundary/index.js +2 -12
  153. package/build-module/components/error-boundary/index.js.map +1 -1
  154. package/build-module/components/error-boundary/warning.js +5 -28
  155. package/build-module/components/error-boundary/warning.js.map +1 -1
  156. package/build-module/components/global-styles/block-preview-panel.js +2 -2
  157. package/build-module/components/global-styles/block-preview-panel.js.map +1 -1
  158. package/build-module/components/global-styles/border-panel.js +17 -11
  159. package/build-module/components/global-styles/border-panel.js.map +1 -1
  160. package/build-module/components/global-styles/color-palette-panel.js +11 -7
  161. package/build-module/components/global-styles/color-palette-panel.js.map +1 -1
  162. package/build-module/components/global-styles/context-menu.js +40 -8
  163. package/build-module/components/global-styles/context-menu.js.map +1 -1
  164. package/build-module/components/global-styles/custom-css.js +61 -15
  165. package/build-module/components/global-styles/custom-css.js.map +1 -1
  166. package/build-module/components/global-styles/dimensions-panel.js +49 -32
  167. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  168. package/build-module/components/global-styles/global-styles-provider.js +7 -2
  169. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  170. package/build-module/components/global-styles/gradients-palette-panel.js +15 -11
  171. package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
  172. package/build-module/components/global-styles/hooks.js +23 -134
  173. package/build-module/components/global-styles/hooks.js.map +1 -1
  174. package/build-module/components/global-styles/index.js +0 -2
  175. package/build-module/components/global-styles/index.js.map +1 -1
  176. package/build-module/components/global-styles/palette.js +10 -5
  177. package/build-module/components/global-styles/palette.js.map +1 -1
  178. package/build-module/components/global-styles/preview.js +18 -14
  179. package/build-module/components/global-styles/preview.js.map +1 -1
  180. package/build-module/components/global-styles/screen-background-color.js +26 -15
  181. package/build-module/components/global-styles/screen-background-color.js.map +1 -1
  182. package/build-module/components/global-styles/screen-border.js +10 -5
  183. package/build-module/components/global-styles/screen-border.js.map +1 -1
  184. package/build-module/components/global-styles/screen-button-color.js +16 -11
  185. package/build-module/components/global-styles/screen-button-color.js.map +1 -1
  186. package/build-module/components/global-styles/screen-colors.js +43 -37
  187. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  188. package/build-module/components/global-styles/screen-css.js +21 -9
  189. package/build-module/components/global-styles/screen-css.js.map +1 -1
  190. package/build-module/components/global-styles/screen-heading-color.js +23 -18
  191. package/build-module/components/global-styles/screen-heading-color.js.map +1 -1
  192. package/build-module/components/global-styles/screen-layout.js +4 -4
  193. package/build-module/components/global-styles/screen-layout.js.map +1 -1
  194. package/build-module/components/global-styles/screen-link-color.js +18 -13
  195. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  196. package/build-module/components/global-styles/screen-root.js +23 -9
  197. package/build-module/components/global-styles/screen-root.js.map +1 -1
  198. package/build-module/components/global-styles/screen-style-variations.js +5 -2
  199. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  200. package/build-module/components/global-styles/screen-text-color.js +14 -9
  201. package/build-module/components/global-styles/screen-text-color.js.map +1 -1
  202. package/build-module/components/global-styles/screen-typography.js +16 -12
  203. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  204. package/build-module/components/global-styles/shadow-panel.js +177 -0
  205. package/build-module/components/global-styles/shadow-panel.js.map +1 -0
  206. package/build-module/components/global-styles/typography-panel.js +43 -31
  207. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  208. package/build-module/components/global-styles/typography-preview.js +17 -9
  209. package/build-module/components/global-styles/typography-preview.js.map +1 -1
  210. package/build-module/components/global-styles/ui.js +80 -35
  211. package/build-module/components/global-styles/ui.js.map +1 -1
  212. package/build-module/components/global-styles/utils.js +4 -319
  213. package/build-module/components/global-styles/utils.js.map +1 -1
  214. package/build-module/components/global-styles-renderer/index.js +5 -5
  215. package/build-module/components/global-styles-renderer/index.js.map +1 -1
  216. package/build-module/components/header-edit-mode/document-actions/index.js +2 -2
  217. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
  218. package/build-module/components/keyboard-shortcut-help-modal/index.js +0 -1
  219. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  220. package/build-module/components/layout/index.js +6 -8
  221. package/build-module/components/layout/index.js.map +1 -1
  222. package/build-module/components/list/actions/rename-menu-item.js +9 -12
  223. package/build-module/components/list/actions/rename-menu-item.js.map +1 -1
  224. package/build-module/components/{sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js → navigation-inspector/index.js} +1 -2
  225. package/build-module/components/navigation-inspector/index.js.map +1 -0
  226. package/build-module/components/{sidebar-edit-mode/navigation-menu-sidebar → navigation-inspector}/navigation-menu.js +13 -16
  227. package/build-module/components/navigation-inspector/navigation-menu.js.map +1 -0
  228. package/build-module/components/sidebar/index.js +2 -1
  229. package/build-module/components/sidebar/index.js.map +1 -1
  230. package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js +6 -21
  231. package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -1
  232. package/build-module/components/sidebar-edit-mode/index.js +1 -13
  233. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  234. package/build-module/components/sidebar-navigation-screen/index.js +3 -2
  235. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
  236. package/build-module/components/sidebar-navigation-screen-main/index.js +22 -2
  237. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  238. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +23 -0
  239. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -0
  240. package/build-module/components/sidebar-navigation-screen-templates/index.js +4 -9
  241. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  242. package/build-module/components/site-hub/index.js +2 -2
  243. package/build-module/components/site-hub/index.js.map +1 -1
  244. package/build-module/components/site-icon/index.js +1 -1
  245. package/build-module/components/site-icon/index.js.map +1 -1
  246. package/build-module/components/style-book/index.js +8 -5
  247. package/build-module/components/style-book/index.js.map +1 -1
  248. package/build-module/components/template-part-converter/convert-to-template-part.js +5 -9
  249. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  250. package/build-module/experiments.js +9 -0
  251. package/build-module/experiments.js.map +1 -0
  252. package/build-module/hooks/push-changes-to-global-styles/index.js +62 -3
  253. package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
  254. package/build-module/index.js +52 -60
  255. package/build-module/index.js.map +1 -1
  256. package/build-module/store/selectors.js +6 -26
  257. package/build-module/store/selectors.js.map +1 -1
  258. package/build-module/store/utils.js +66 -0
  259. package/build-module/store/utils.js.map +1 -0
  260. package/build-module/utils/template-part-create.js +53 -0
  261. package/build-module/utils/template-part-create.js.map +1 -0
  262. package/build-style/style-rtl.css +314 -216
  263. package/build-style/style.css +314 -216
  264. package/package.json +32 -30
  265. package/src/components/add-new-template/add-custom-generic-template-modal.js +20 -28
  266. package/src/components/add-new-template/add-custom-template-modal.js +0 -1
  267. package/src/components/add-new-template/new-template-part.js +11 -32
  268. package/src/components/add-new-template/style.scss +0 -4
  269. package/src/components/add-new-template/utils.js +0 -14
  270. package/src/components/app/index.js +2 -2
  271. package/src/components/block-editor/index.js +12 -25
  272. package/src/components/block-editor/inserter-media-categories.js +247 -0
  273. package/src/components/block-editor/style.scss +19 -7
  274. package/src/components/canvas-spinner/index.js +12 -0
  275. package/src/components/canvas-spinner/style.scss +7 -0
  276. package/src/components/create-template-part-modal/index.js +75 -67
  277. package/src/components/create-template-part-modal/style.scss +0 -10
  278. package/src/components/editor/index.js +4 -2
  279. package/src/components/error-boundary/index.js +2 -10
  280. package/src/components/error-boundary/warning.js +6 -35
  281. package/src/components/global-styles/README.md +1 -75
  282. package/src/components/global-styles/block-preview-panel.js +2 -2
  283. package/src/components/global-styles/border-panel.js +19 -17
  284. package/src/components/global-styles/color-palette-panel.js +10 -7
  285. package/src/components/global-styles/context-menu.js +114 -44
  286. package/src/components/global-styles/custom-css.js +76 -19
  287. package/src/components/global-styles/dimensions-panel.js +46 -36
  288. package/src/components/global-styles/global-styles-provider.js +6 -2
  289. package/src/components/global-styles/gradients-palette-panel.js +17 -11
  290. package/src/components/global-styles/hooks.js +31 -155
  291. package/src/components/global-styles/index.js +0 -2
  292. package/src/components/global-styles/palette.js +9 -5
  293. package/src/components/global-styles/preview.js +19 -13
  294. package/src/components/global-styles/screen-background-color.js +37 -21
  295. package/src/components/global-styles/screen-border.js +10 -5
  296. package/src/components/global-styles/screen-button-color.js +21 -19
  297. package/src/components/global-styles/screen-colors.js +48 -65
  298. package/src/components/global-styles/screen-css.js +30 -14
  299. package/src/components/global-styles/screen-heading-color.js +32 -27
  300. package/src/components/global-styles/screen-layout.js +4 -7
  301. package/src/components/global-styles/screen-link-color.js +26 -26
  302. package/src/components/global-styles/screen-root.js +24 -9
  303. package/src/components/global-styles/screen-style-variations.js +7 -2
  304. package/src/components/global-styles/screen-text-color.js +15 -19
  305. package/src/components/global-styles/screen-typography.js +27 -12
  306. package/src/components/global-styles/shadow-panel.js +174 -0
  307. package/src/components/global-styles/style.scss +85 -1
  308. package/src/components/global-styles/typography-panel.js +60 -48
  309. package/src/components/global-styles/typography-preview.js +28 -9
  310. package/src/components/global-styles/ui.js +78 -53
  311. package/src/components/global-styles/utils.js +4 -371
  312. package/src/components/global-styles-renderer/index.js +3 -4
  313. package/src/components/header-edit-mode/document-actions/index.js +1 -1
  314. package/src/components/keyboard-shortcut-help-modal/index.js +0 -1
  315. package/src/components/layout/index.js +9 -2
  316. package/src/components/layout/style.scss +4 -5
  317. package/src/components/list/actions/rename-menu-item.js +14 -23
  318. package/src/components/list/style.scss +0 -4
  319. package/src/components/{sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js → navigation-inspector/index.js} +1 -4
  320. package/src/components/{sidebar-edit-mode/navigation-menu-sidebar → navigation-inspector}/navigation-menu.js +10 -12
  321. package/src/components/{sidebar-edit-mode/navigation-menu-sidebar → navigation-inspector}/style.scss +0 -17
  322. package/src/components/sidebar/index.js +2 -0
  323. package/src/components/sidebar-edit-mode/global-styles-sidebar.js +8 -32
  324. package/src/components/sidebar-edit-mode/index.js +0 -11
  325. package/src/components/sidebar-edit-mode/settings-header/style.scss +8 -0
  326. package/src/components/sidebar-navigation-item/style.scss +28 -3
  327. package/src/components/sidebar-navigation-screen/index.js +4 -3
  328. package/src/components/sidebar-navigation-screen/style.scss +2 -0
  329. package/src/components/sidebar-navigation-screen-main/index.js +23 -1
  330. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +25 -0
  331. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +12 -0
  332. package/src/components/sidebar-navigation-screen-templates/index.js +12 -19
  333. package/src/components/site-hub/index.js +1 -1
  334. package/src/components/site-hub/style.scss +7 -1
  335. package/src/components/site-icon/index.js +1 -1
  336. package/src/components/site-icon/style.scss +2 -2
  337. package/src/components/style-book/index.js +10 -5
  338. package/src/components/template-part-converter/convert-to-template-part.js +12 -10
  339. package/src/experiments.js +10 -0
  340. package/src/hooks/push-changes-to-global-styles/index.js +63 -5
  341. package/src/index.js +51 -59
  342. package/src/store/selectors.js +6 -26
  343. package/src/store/test/utils.js +181 -0
  344. package/src/store/utils.js +69 -0
  345. package/src/style.scss +4 -2
  346. package/src/utils/template-part-create.js +62 -0
  347. package/src/utils/test/template-part-create.js +63 -0
  348. package/build/components/global-styles/context.js +0 -22
  349. package/build/components/global-styles/context.js.map +0 -1
  350. package/build/components/global-styles/typography-utils.js +0 -92
  351. package/build/components/global-styles/typography-utils.js.map +0 -1
  352. package/build/components/global-styles/use-global-styles-output.js +0 -943
  353. package/build/components/global-styles/use-global-styles-output.js.map +0 -1
  354. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/index.js +0 -42
  355. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/index.js.map +0 -1
  356. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +0 -1
  357. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +0 -1
  358. package/build-module/components/global-styles/context.js +0 -12
  359. package/build-module/components/global-styles/context.js.map +0 -1
  360. package/build-module/components/global-styles/typography-utils.js +0 -84
  361. package/build-module/components/global-styles/typography-utils.js.map +0 -1
  362. package/build-module/components/global-styles/use-global-styles-output.js +0 -901
  363. package/build-module/components/global-styles/use-global-styles-output.js.map +0 -1
  364. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/index.js +0 -28
  365. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/index.js.map +0 -1
  366. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +0 -1
  367. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +0 -1
  368. package/src/components/global-styles/context.js +0 -15
  369. package/src/components/global-styles/test/typography-utils.js +0 -393
  370. package/src/components/global-styles/test/use-global-styles-output.js +0 -814
  371. package/src/components/global-styles/test/utils.js +0 -206
  372. package/src/components/global-styles/typography-utils.js +0 -87
  373. package/src/components/global-styles/use-global-styles-output.js +0 -1059
  374. package/src/components/sidebar-edit-mode/navigation-menu-sidebar/index.js +0 -37
@@ -1,1059 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { get, isEmpty, kebabCase, set } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import {
10
- __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,
11
- __EXPERIMENTAL_ELEMENTS as ELEMENTS,
12
- getBlockTypes,
13
- store as blocksStore,
14
- } from '@wordpress/blocks';
15
- import { useSelect } from '@wordpress/data';
16
- import { useContext, useMemo } from '@wordpress/element';
17
- import { getCSSRules } from '@wordpress/style-engine';
18
- import {
19
- __unstablePresetDuotoneFilter as PresetDuotoneFilter,
20
- __experimentalGetGapCSSValue as getGapCSSValue,
21
- store as blockEditorStore,
22
- } from '@wordpress/block-editor';
23
-
24
- /**
25
- * Internal dependencies
26
- */
27
- import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
28
- import { getTypographyFontSizeValue } from './typography-utils';
29
- import { GlobalStylesContext } from './context';
30
- import { useSetting } from './hooks';
31
-
32
- // List of block support features that can have their related styles
33
- // generated under their own feature level selector rather than the block's.
34
- const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
35
- __experimentalBorder: 'border',
36
- color: 'color',
37
- spacing: 'spacing',
38
- typography: 'typography',
39
- };
40
-
41
- function compileStyleValue( uncompiledValue ) {
42
- const VARIABLE_REFERENCE_PREFIX = 'var:';
43
- const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
44
- const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
45
-
46
- if ( uncompiledValue?.startsWith?.( VARIABLE_REFERENCE_PREFIX ) ) {
47
- const variable = uncompiledValue
48
- .slice( VARIABLE_REFERENCE_PREFIX.length )
49
- .split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
50
- .join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );
51
- return `var(--wp--${ variable })`;
52
- }
53
- return uncompiledValue;
54
- }
55
-
56
- /**
57
- * Transform given preset tree into a set of style declarations.
58
- *
59
- * @param {Object} blockPresets
60
- * @param {Object} mergedSettings Merged theme.json settings.
61
- *
62
- * @return {Array<Object>} An array of style declarations.
63
- */
64
- function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
65
- return PRESET_METADATA.reduce(
66
- ( declarations, { path, valueKey, valueFunc, cssVarInfix } ) => {
67
- const presetByOrigin = get( blockPresets, path, [] );
68
- [ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
69
- if ( presetByOrigin[ origin ] ) {
70
- presetByOrigin[ origin ].forEach( ( value ) => {
71
- if ( valueKey && ! valueFunc ) {
72
- declarations.push(
73
- `--wp--preset--${ cssVarInfix }--${ kebabCase(
74
- value.slug
75
- ) }: ${ value[ valueKey ] }`
76
- );
77
- } else if (
78
- valueFunc &&
79
- typeof valueFunc === 'function'
80
- ) {
81
- declarations.push(
82
- `--wp--preset--${ cssVarInfix }--${ kebabCase(
83
- value.slug
84
- ) }: ${ valueFunc( value, mergedSettings ) }`
85
- );
86
- }
87
- } );
88
- }
89
- } );
90
-
91
- return declarations;
92
- },
93
- []
94
- );
95
- }
96
-
97
- /**
98
- * Transform given preset tree into a set of preset class declarations.
99
- *
100
- * @param {string} blockSelector
101
- * @param {Object} blockPresets
102
- * @return {string} CSS declarations for the preset classes.
103
- */
104
- function getPresetsClasses( blockSelector, blockPresets = {} ) {
105
- return PRESET_METADATA.reduce(
106
- ( declarations, { path, cssVarInfix, classes } ) => {
107
- if ( ! classes ) {
108
- return declarations;
109
- }
110
-
111
- const presetByOrigin = get( blockPresets, path, [] );
112
- [ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
113
- if ( presetByOrigin[ origin ] ) {
114
- presetByOrigin[ origin ].forEach( ( { slug } ) => {
115
- classes.forEach( ( { classSuffix, propertyName } ) => {
116
- const classSelectorToUse = `.has-${ kebabCase(
117
- slug
118
- ) }-${ classSuffix }`;
119
- const selectorToUse = blockSelector
120
- .split( ',' ) // Selector can be "h1, h2, h3"
121
- .map(
122
- ( selector ) =>
123
- `${ selector }${ classSelectorToUse }`
124
- )
125
- .join( ',' );
126
- const value = `var(--wp--preset--${ cssVarInfix }--${ kebabCase(
127
- slug
128
- ) })`;
129
- declarations += `${ selectorToUse }{${ propertyName }: ${ value } !important;}`;
130
- } );
131
- } );
132
- }
133
- } );
134
- return declarations;
135
- },
136
- ''
137
- );
138
- }
139
-
140
- function getPresetsSvgFilters( blockPresets = {} ) {
141
- return PRESET_METADATA.filter(
142
- // Duotone are the only type of filters for now.
143
- ( metadata ) => metadata.path.at( -1 ) === 'duotone'
144
- ).flatMap( ( metadata ) => {
145
- const presetByOrigin = get( blockPresets, metadata.path, {} );
146
- return [ 'default', 'theme' ]
147
- .filter( ( origin ) => presetByOrigin[ origin ] )
148
- .flatMap( ( origin ) =>
149
- presetByOrigin[ origin ].map( ( preset ) => (
150
- <PresetDuotoneFilter
151
- preset={ preset }
152
- key={ preset.slug }
153
- />
154
- ) )
155
- );
156
- } );
157
- }
158
-
159
- function flattenTree( input = {}, prefix, token ) {
160
- let result = [];
161
- Object.keys( input ).forEach( ( key ) => {
162
- const newKey = prefix + kebabCase( key.replace( '/', '-' ) );
163
- const newLeaf = input[ key ];
164
-
165
- if ( newLeaf instanceof Object ) {
166
- const newPrefix = newKey + token;
167
- result = [ ...result, ...flattenTree( newLeaf, newPrefix, token ) ];
168
- } else {
169
- result.push( `${ newKey }: ${ newLeaf }` );
170
- }
171
- } );
172
- return result;
173
- }
174
-
175
- /**
176
- * Gets variation selector string from feature selector.
177
- *
178
- * @param {string} featureSelector The feature selector.
179
- *
180
- * @param {string} styleVariationSelector The style variation selector.
181
- * @return {string} Combined selector string.
182
- *
183
- */
184
- function concatFeatureVariationSelectorString(
185
- featureSelector,
186
- styleVariationSelector
187
- ) {
188
- const featureSelectors = featureSelector.split( ',' );
189
- const combinedSelectors = [];
190
- featureSelectors.forEach( ( selector ) => {
191
- combinedSelectors.push(
192
- `${ styleVariationSelector.trim() }${ selector.trim() }`
193
- );
194
- } );
195
- return combinedSelectors.join( ', ' );
196
- }
197
-
198
- /**
199
- * Transform given style tree into a set of style declarations.
200
- *
201
- * @param {Object} blockStyles Block styles.
202
- *
203
- * @param {string} selector The selector these declarations should attach to.
204
- *
205
- * @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
206
- *
207
- * @param {Object} tree A theme.json tree containing layout definitions.
208
- *
209
- * @return {Array} An array of style declarations.
210
- */
211
- export function getStylesDeclarations(
212
- blockStyles = {},
213
- selector = '',
214
- useRootPaddingAlign,
215
- tree = {}
216
- ) {
217
- const isRoot = ROOT_BLOCK_SELECTOR === selector;
218
- const output = Object.entries( STYLE_PROPERTY ).reduce(
219
- (
220
- declarations,
221
- [ key, { value, properties, useEngine, rootOnly } ]
222
- ) => {
223
- if ( rootOnly && ! isRoot ) {
224
- return declarations;
225
- }
226
- const pathToValue = value;
227
- if ( pathToValue[ 0 ] === 'elements' || useEngine ) {
228
- return declarations;
229
- }
230
-
231
- const styleValue = get( blockStyles, pathToValue );
232
-
233
- // Root-level padding styles don't currently support strings with CSS shorthand values.
234
- // This may change: https://github.com/WordPress/gutenberg/issues/40132.
235
- if (
236
- key === '--wp--style--root--padding' &&
237
- ( typeof styleValue === 'string' || ! useRootPaddingAlign )
238
- ) {
239
- return declarations;
240
- }
241
-
242
- if ( !! properties && typeof styleValue !== 'string' ) {
243
- Object.entries( properties ).forEach( ( entry ) => {
244
- const [ name, prop ] = entry;
245
-
246
- if ( ! get( styleValue, [ prop ], false ) ) {
247
- // Do not create a declaration
248
- // for sub-properties that don't have any value.
249
- return;
250
- }
251
-
252
- const cssProperty = name.startsWith( '--' )
253
- ? name
254
- : kebabCase( name );
255
- declarations.push(
256
- `${ cssProperty }: ${ compileStyleValue(
257
- get( styleValue, [ prop ] )
258
- ) }`
259
- );
260
- } );
261
- } else if ( get( blockStyles, pathToValue, false ) ) {
262
- const cssProperty = key.startsWith( '--' )
263
- ? key
264
- : kebabCase( key );
265
- declarations.push(
266
- `${ cssProperty }: ${ compileStyleValue(
267
- get( blockStyles, pathToValue )
268
- ) }`
269
- );
270
- }
271
-
272
- return declarations;
273
- },
274
- []
275
- );
276
-
277
- // The goal is to move everything to server side generated engine styles
278
- // This is temporary as we absorb more and more styles into the engine.
279
- const extraRules = getCSSRules( blockStyles );
280
- extraRules.forEach( ( rule ) => {
281
- // Don't output padding properties if padding variables are set.
282
- if (
283
- isRoot &&
284
- useRootPaddingAlign &&
285
- rule.key.startsWith( 'padding' )
286
- ) {
287
- return;
288
- }
289
- const cssProperty = rule.key.startsWith( '--' )
290
- ? rule.key
291
- : kebabCase( rule.key );
292
-
293
- let ruleValue = rule.value;
294
- if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
295
- const refPath = ruleValue.ref.split( '.' );
296
- ruleValue = get( tree, refPath );
297
- // Presence of another ref indicates a reference to another dynamic value.
298
- // Pointing to another dynamic value is not supported.
299
- if ( ! ruleValue || !! ruleValue?.ref ) {
300
- return;
301
- }
302
- }
303
-
304
- // Calculate fluid typography rules where available.
305
- if ( cssProperty === 'font-size' ) {
306
- /*
307
- * getTypographyFontSizeValue() will check
308
- * if fluid typography has been activated and also
309
- * whether the incoming value can be converted to a fluid value.
310
- * Values that already have a "clamp()" function will not pass the test,
311
- * and therefore the original $value will be returned.
312
- */
313
- ruleValue = getTypographyFontSizeValue(
314
- { size: ruleValue },
315
- tree?.settings?.typography
316
- );
317
- }
318
-
319
- output.push( `${ cssProperty }: ${ ruleValue }` );
320
- } );
321
-
322
- return output;
323
- }
324
-
325
- /**
326
- * Get generated CSS for layout styles by looking up layout definitions provided
327
- * in theme.json, and outputting common layout styles, and specific blockGap values.
328
- *
329
- * @param {Object} props
330
- * @param {Object} props.tree A theme.json tree containing layout definitions.
331
- * @param {Object} props.style A style object containing spacing values.
332
- * @param {string} props.selector Selector used to group together layout styling rules.
333
- * @param {boolean} props.hasBlockGapSupport Whether or not the theme opts-in to blockGap support.
334
- * @param {boolean} props.hasFallbackGapSupport Whether or not the theme allows fallback gap styles.
335
- * @param {?string} props.fallbackGapValue An optional fallback gap value if no real gap value is available.
336
- * @return {string} Generated CSS rules for the layout styles.
337
- */
338
- export function getLayoutStyles( {
339
- tree,
340
- style,
341
- selector,
342
- hasBlockGapSupport,
343
- hasFallbackGapSupport,
344
- fallbackGapValue,
345
- } ) {
346
- let ruleset = '';
347
- let gapValue = hasBlockGapSupport
348
- ? getGapCSSValue( style?.spacing?.blockGap )
349
- : '';
350
-
351
- // Ensure a fallback gap value for the root layout definitions,
352
- // and use a fallback value if one is provided for the current block.
353
- if ( hasFallbackGapSupport ) {
354
- if ( selector === ROOT_BLOCK_SELECTOR ) {
355
- gapValue = ! gapValue ? '0.5em' : gapValue;
356
- } else if ( ! hasBlockGapSupport && fallbackGapValue ) {
357
- gapValue = fallbackGapValue;
358
- }
359
- }
360
-
361
- if ( gapValue && tree?.settings?.layout?.definitions ) {
362
- Object.values( tree.settings.layout.definitions ).forEach(
363
- ( { className, name, spacingStyles } ) => {
364
- // Allow outputting fallback gap styles for flex layout type when block gap support isn't available.
365
- if ( ! hasBlockGapSupport && 'flex' !== name ) {
366
- return;
367
- }
368
-
369
- if ( spacingStyles?.length ) {
370
- spacingStyles.forEach( ( spacingStyle ) => {
371
- const declarations = [];
372
-
373
- if ( spacingStyle.rules ) {
374
- Object.entries( spacingStyle.rules ).forEach(
375
- ( [ cssProperty, cssValue ] ) => {
376
- declarations.push(
377
- `${ cssProperty }: ${
378
- cssValue ? cssValue : gapValue
379
- }`
380
- );
381
- }
382
- );
383
- }
384
-
385
- if ( declarations.length ) {
386
- let combinedSelector = '';
387
-
388
- if ( ! hasBlockGapSupport ) {
389
- // For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
390
- combinedSelector =
391
- selector === ROOT_BLOCK_SELECTOR
392
- ? `:where(.${ className }${
393
- spacingStyle?.selector || ''
394
- })`
395
- : `:where(${ selector }.${ className }${
396
- spacingStyle?.selector || ''
397
- })`;
398
- } else {
399
- combinedSelector =
400
- selector === ROOT_BLOCK_SELECTOR
401
- ? `${ selector } .${ className }${
402
- spacingStyle?.selector || ''
403
- }`
404
- : `${ selector }.${ className }${
405
- spacingStyle?.selector || ''
406
- }`;
407
- }
408
- ruleset += `${ combinedSelector } { ${ declarations.join(
409
- '; '
410
- ) }; }`;
411
- }
412
- } );
413
- }
414
- }
415
- );
416
- // For backwards compatibility, ensure the legacy block gap CSS variable is still available.
417
- if ( selector === ROOT_BLOCK_SELECTOR && hasBlockGapSupport ) {
418
- ruleset += `${ selector } { --wp--style--block-gap: ${ gapValue }; }`;
419
- }
420
- }
421
-
422
- // Output base styles
423
- if (
424
- selector === ROOT_BLOCK_SELECTOR &&
425
- tree?.settings?.layout?.definitions
426
- ) {
427
- const validDisplayModes = [ 'block', 'flex', 'grid' ];
428
- Object.values( tree.settings.layout.definitions ).forEach(
429
- ( { className, displayMode, baseStyles } ) => {
430
- if (
431
- displayMode &&
432
- validDisplayModes.includes( displayMode )
433
- ) {
434
- ruleset += `${ selector } .${ className } { display:${ displayMode }; }`;
435
- }
436
-
437
- if ( baseStyles?.length ) {
438
- baseStyles.forEach( ( baseStyle ) => {
439
- const declarations = [];
440
-
441
- if ( baseStyle.rules ) {
442
- Object.entries( baseStyle.rules ).forEach(
443
- ( [ cssProperty, cssValue ] ) => {
444
- declarations.push(
445
- `${ cssProperty }: ${ cssValue }`
446
- );
447
- }
448
- );
449
- }
450
-
451
- if ( declarations.length ) {
452
- const combinedSelector = `${ selector } .${ className }${
453
- baseStyle?.selector || ''
454
- }`;
455
- ruleset += `${ combinedSelector } { ${ declarations.join(
456
- '; '
457
- ) }; }`;
458
- }
459
- } );
460
- }
461
- }
462
- );
463
- }
464
-
465
- return ruleset;
466
- }
467
-
468
- export const getNodesWithStyles = ( tree, blockSelectors ) => {
469
- const nodes = [];
470
-
471
- if ( ! tree?.styles ) {
472
- return nodes;
473
- }
474
-
475
- const pickStyleKeys = ( treeToPickFrom ) =>
476
- Object.fromEntries(
477
- Object.entries( treeToPickFrom ?? {} ).filter( ( [ key ] ) =>
478
- [
479
- 'border',
480
- 'color',
481
- 'dimensions',
482
- 'spacing',
483
- 'typography',
484
- 'filter',
485
- 'outline',
486
- 'shadow',
487
- ].includes( key )
488
- )
489
- );
490
-
491
- // Top-level.
492
- const styles = pickStyleKeys( tree.styles );
493
- if ( !! styles ) {
494
- nodes.push( {
495
- styles,
496
- selector: ROOT_BLOCK_SELECTOR,
497
- } );
498
- }
499
-
500
- Object.entries( ELEMENTS ).forEach( ( [ name, selector ] ) => {
501
- if ( !! tree.styles?.elements[ name ] ) {
502
- nodes.push( {
503
- styles: tree.styles?.elements[ name ],
504
- selector,
505
- } );
506
- }
507
- } );
508
-
509
- // Iterate over blocks: they can have styles & elements.
510
- Object.entries( tree.styles?.blocks ?? {} ).forEach(
511
- ( [ blockName, node ] ) => {
512
- const blockStyles = pickStyleKeys( node );
513
-
514
- if ( node?.variations ) {
515
- const variations = {};
516
- Object.keys( node.variations ).forEach( ( variation ) => {
517
- variations[ variation ] = pickStyleKeys(
518
- node.variations[ variation ]
519
- );
520
- } );
521
- blockStyles.variations = variations;
522
- }
523
- if (
524
- !! blockStyles &&
525
- !! blockSelectors?.[ blockName ]?.selector
526
- ) {
527
- nodes.push( {
528
- duotoneSelector:
529
- blockSelectors[ blockName ].duotoneSelector,
530
- fallbackGapValue:
531
- blockSelectors[ blockName ].fallbackGapValue,
532
- hasLayoutSupport:
533
- blockSelectors[ blockName ].hasLayoutSupport,
534
- selector: blockSelectors[ blockName ].selector,
535
- styles: blockStyles,
536
- featureSelectors:
537
- blockSelectors[ blockName ].featureSelectors,
538
- styleVariationSelectors:
539
- blockSelectors[ blockName ].styleVariationSelectors,
540
- } );
541
- }
542
-
543
- Object.entries( node?.elements ?? {} ).forEach(
544
- ( [ elementName, value ] ) => {
545
- if (
546
- !! value &&
547
- !! blockSelectors?.[ blockName ] &&
548
- !! ELEMENTS?.[ elementName ]
549
- ) {
550
- nodes.push( {
551
- styles: value,
552
- selector: blockSelectors[ blockName ].selector
553
- .split( ',' )
554
- .map( ( sel ) => {
555
- const elementSelectors =
556
- ELEMENTS[ elementName ].split( ',' );
557
- return elementSelectors.map(
558
- ( elementSelector ) =>
559
- sel + ' ' + elementSelector
560
- );
561
- } )
562
- .join( ',' ),
563
- } );
564
- }
565
- }
566
- );
567
- }
568
- );
569
-
570
- return nodes;
571
- };
572
-
573
- export const getNodesWithSettings = ( tree, blockSelectors ) => {
574
- const nodes = [];
575
-
576
- if ( ! tree?.settings ) {
577
- return nodes;
578
- }
579
-
580
- const pickPresets = ( treeToPickFrom ) => {
581
- const presets = {};
582
- PRESET_METADATA.forEach( ( { path } ) => {
583
- const value = get( treeToPickFrom, path, false );
584
- if ( value !== false ) {
585
- set( presets, path, value );
586
- }
587
- } );
588
- return presets;
589
- };
590
-
591
- // Top-level.
592
- const presets = pickPresets( tree.settings );
593
- const custom = tree.settings?.custom;
594
- if ( ! isEmpty( presets ) || !! custom ) {
595
- nodes.push( {
596
- presets,
597
- custom,
598
- selector: ROOT_BLOCK_SELECTOR,
599
- } );
600
- }
601
-
602
- // Blocks.
603
- Object.entries( tree.settings?.blocks ?? {} ).forEach(
604
- ( [ blockName, node ] ) => {
605
- const blockPresets = pickPresets( node );
606
- const blockCustom = node.custom;
607
- if ( ! isEmpty( blockPresets ) || !! blockCustom ) {
608
- nodes.push( {
609
- presets: blockPresets,
610
- custom: blockCustom,
611
- selector: blockSelectors[ blockName ].selector,
612
- } );
613
- }
614
- }
615
- );
616
-
617
- return nodes;
618
- };
619
-
620
- export const toCustomProperties = ( tree, blockSelectors ) => {
621
- const settings = getNodesWithSettings( tree, blockSelectors );
622
- let ruleset = '';
623
- settings.forEach( ( { presets, custom, selector } ) => {
624
- const declarations = getPresetsDeclarations( presets, tree?.settings );
625
- const customProps = flattenTree( custom, '--wp--custom--', '--' );
626
- if ( customProps.length > 0 ) {
627
- declarations.push( ...customProps );
628
- }
629
-
630
- if ( declarations.length > 0 ) {
631
- ruleset = ruleset + `${ selector }{${ declarations.join( ';' ) };}`;
632
- }
633
- } );
634
-
635
- return ruleset;
636
- };
637
-
638
- export const toStyles = (
639
- tree,
640
- blockSelectors,
641
- hasBlockGapSupport,
642
- hasFallbackGapSupport,
643
- disableLayoutStyles = false
644
- ) => {
645
- const nodesWithStyles = getNodesWithStyles( tree, blockSelectors );
646
- const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
647
- const useRootPaddingAlign = tree?.settings?.useRootPaddingAwareAlignments;
648
- const { contentSize, wideSize } = tree?.settings?.layout || {};
649
-
650
- /*
651
- * Reset default browser margin on the root body element.
652
- * This is set on the root selector **before** generating the ruleset
653
- * from the `theme.json`. This is to ensure that if the `theme.json` declares
654
- * `margin` in its `spacing` declaration for the `body` element then these
655
- * user-generated values take precedence in the CSS cascade.
656
- * @link https://github.com/WordPress/gutenberg/issues/36147.
657
- */
658
- let ruleset = 'body {margin: 0;';
659
-
660
- if ( contentSize ) {
661
- ruleset += ` --wp--style--global--content-size: ${ contentSize };`;
662
- }
663
-
664
- if ( wideSize ) {
665
- ruleset += ` --wp--style--global--wide-size: ${ wideSize };`;
666
- }
667
-
668
- if ( useRootPaddingAlign ) {
669
- ruleset += `padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) }
670
- .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
671
- .has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; }
672
- .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }
673
- .has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }
674
- .has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
675
- .has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0;`;
676
- }
677
-
678
- ruleset += '}';
679
-
680
- nodesWithStyles.forEach(
681
- ( {
682
- selector,
683
- duotoneSelector,
684
- styles,
685
- fallbackGapValue,
686
- hasLayoutSupport,
687
- featureSelectors,
688
- styleVariationSelectors,
689
- } ) => {
690
- // Process styles for block support features with custom feature level
691
- // CSS selectors set.
692
- if ( featureSelectors ) {
693
- Object.entries( featureSelectors ).forEach(
694
- ( [ featureName, featureSelector ] ) => {
695
- if ( styles?.[ featureName ] ) {
696
- const featureStyles = {
697
- [ featureName ]: styles[ featureName ],
698
- };
699
- const featureDeclarations =
700
- getStylesDeclarations( featureStyles );
701
- delete styles[ featureName ];
702
-
703
- if ( !! featureDeclarations.length ) {
704
- ruleset =
705
- ruleset +
706
- `${ featureSelector }{${ featureDeclarations.join(
707
- ';'
708
- ) } }`;
709
- }
710
- }
711
- }
712
- );
713
- }
714
-
715
- if ( styleVariationSelectors ) {
716
- Object.entries( styleVariationSelectors ).forEach(
717
- ( [ styleVariationName, styleVariationSelector ] ) => {
718
- if ( styles?.variations?.[ styleVariationName ] ) {
719
- // If the block uses any custom selectors for block support, add those first.
720
- if ( featureSelectors ) {
721
- Object.entries( featureSelectors ).forEach(
722
- ( [ featureName, featureSelector ] ) => {
723
- if (
724
- styles?.variations?.[
725
- styleVariationName
726
- ]?.[ featureName ]
727
- ) {
728
- const featureStyles = {
729
- [ featureName ]:
730
- styles.variations[
731
- styleVariationName
732
- ][ featureName ],
733
- };
734
- const featureDeclarations =
735
- getStylesDeclarations(
736
- featureStyles
737
- );
738
- delete styles.variations[
739
- styleVariationName
740
- ][ featureName ];
741
-
742
- if (
743
- !! featureDeclarations.length
744
- ) {
745
- ruleset =
746
- ruleset +
747
- `${ concatFeatureVariationSelectorString(
748
- featureSelector,
749
- styleVariationSelector
750
- ) }{${ featureDeclarations.join(
751
- ';'
752
- ) } }`;
753
- }
754
- }
755
- }
756
- );
757
- }
758
- // Otherwise add regular selectors.
759
- const styleVariationDeclarations =
760
- getStylesDeclarations(
761
- styles?.variations?.[ styleVariationName ],
762
- styleVariationSelector,
763
- useRootPaddingAlign,
764
- tree
765
- );
766
- if ( !! styleVariationDeclarations.length ) {
767
- ruleset =
768
- ruleset +
769
- `${ styleVariationSelector }{${ styleVariationDeclarations.join(
770
- ';'
771
- ) }}`;
772
- }
773
- }
774
- }
775
- );
776
- }
777
-
778
- const duotoneStyles = {};
779
- if ( styles?.filter ) {
780
- duotoneStyles.filter = styles.filter;
781
- delete styles.filter;
782
- }
783
-
784
- // Process duotone styles (they use color.__experimentalDuotone selector).
785
- if ( duotoneSelector ) {
786
- const duotoneDeclarations =
787
- getStylesDeclarations( duotoneStyles );
788
- if ( duotoneDeclarations.length > 0 ) {
789
- ruleset =
790
- ruleset +
791
- `${ duotoneSelector }{${ duotoneDeclarations.join(
792
- ';'
793
- ) };}`;
794
- }
795
- }
796
-
797
- // Process blockGap and layout styles.
798
- if (
799
- ! disableLayoutStyles &&
800
- ( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport )
801
- ) {
802
- ruleset += getLayoutStyles( {
803
- tree,
804
- style: styles,
805
- selector,
806
- hasBlockGapSupport,
807
- hasFallbackGapSupport,
808
- fallbackGapValue,
809
- } );
810
- }
811
-
812
- // Process the remaining block styles (they use either normal block class or __experimentalSelector).
813
- const declarations = getStylesDeclarations(
814
- styles,
815
- selector,
816
- useRootPaddingAlign,
817
- tree
818
- );
819
- if ( declarations?.length ) {
820
- ruleset =
821
- ruleset + `${ selector }{${ declarations.join( ';' ) };}`;
822
- }
823
-
824
- // Check for pseudo selector in `styles` and handle separately.
825
- const pseudoSelectorStyles = Object.entries( styles ).filter(
826
- ( [ key ] ) => key.startsWith( ':' )
827
- );
828
-
829
- if ( pseudoSelectorStyles?.length ) {
830
- pseudoSelectorStyles.forEach(
831
- ( [ pseudoKey, pseudoStyle ] ) => {
832
- const pseudoDeclarations =
833
- getStylesDeclarations( pseudoStyle );
834
-
835
- if ( ! pseudoDeclarations?.length ) {
836
- return;
837
- }
838
-
839
- // `selector` maybe provided in a form
840
- // where block level selectors have sub element
841
- // selectors appended to them as a comma separated
842
- // string.
843
- // e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
844
- // Split and append pseudo selector to create
845
- // the proper rules to target the elements.
846
- const _selector = selector
847
- .split( ',' )
848
- .map( ( sel ) => sel + pseudoKey )
849
- .join( ',' );
850
-
851
- const pseudoRule = `${ _selector }{${ pseudoDeclarations.join(
852
- ';'
853
- ) };}`;
854
-
855
- ruleset = ruleset + pseudoRule;
856
- }
857
- );
858
- }
859
- }
860
- );
861
-
862
- /* Add alignment / layout styles */
863
- ruleset =
864
- ruleset +
865
- '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
866
- ruleset =
867
- ruleset +
868
- '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
869
- ruleset =
870
- ruleset +
871
- '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
872
-
873
- if ( hasBlockGapSupport ) {
874
- // Use fallback of `0.5em` just in case, however if there is blockGap support, there should nearly always be a real value.
875
- const gapValue =
876
- getGapCSSValue( tree?.styles?.spacing?.blockGap ) || '0.5em';
877
- ruleset =
878
- ruleset +
879
- '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
880
- ruleset =
881
- ruleset +
882
- `.wp-site-blocks > * + * { margin-block-start: ${ gapValue }; }`;
883
- }
884
-
885
- nodesWithSettings.forEach( ( { selector, presets } ) => {
886
- if ( ROOT_BLOCK_SELECTOR === selector ) {
887
- // Do not add extra specificity for top-level classes.
888
- selector = '';
889
- }
890
-
891
- const classes = getPresetsClasses( selector, presets );
892
- if ( ! isEmpty( classes ) ) {
893
- ruleset = ruleset + classes;
894
- }
895
- } );
896
-
897
- return ruleset;
898
- };
899
-
900
- export function toSvgFilters( tree, blockSelectors ) {
901
- const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
902
- return nodesWithSettings.flatMap( ( { presets } ) => {
903
- return getPresetsSvgFilters( presets );
904
- } );
905
- }
906
-
907
- export const getBlockSelectors = ( blockTypes, getBlockStyles ) => {
908
- const result = {};
909
- blockTypes.forEach( ( blockType ) => {
910
- const name = blockType.name;
911
- const selector =
912
- blockType?.supports?.__experimentalSelector ??
913
- '.wp-block-' + name.replace( 'core/', '' ).replace( '/', '-' );
914
- const duotoneSelector =
915
- blockType?.supports?.color?.__experimentalDuotone ?? null;
916
- const hasLayoutSupport = !! blockType?.supports?.__experimentalLayout;
917
- const fallbackGapValue =
918
- blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
919
-
920
- const blockStyleVariations = getBlockStyles( name );
921
- const styleVariationSelectors = {};
922
- if ( blockStyleVariations?.length ) {
923
- blockStyleVariations.forEach( ( variation ) => {
924
- const styleVariationSelector = `.is-style-${ variation.name }${ selector }`;
925
- styleVariationSelectors[ variation.name ] =
926
- styleVariationSelector;
927
- } );
928
- }
929
- // For each block support feature add any custom selectors.
930
- const featureSelectors = {};
931
- Object.entries( BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS ).forEach(
932
- ( [ featureKey, featureName ] ) => {
933
- const featureSelector =
934
- blockType?.supports?.[ featureKey ]?.__experimentalSelector;
935
-
936
- if ( featureSelector ) {
937
- featureSelectors[ featureName ] = scopeSelector(
938
- selector,
939
- featureSelector
940
- );
941
- }
942
- }
943
- );
944
-
945
- result[ name ] = {
946
- duotoneSelector,
947
- fallbackGapValue,
948
- featureSelectors: Object.keys( featureSelectors ).length
949
- ? featureSelectors
950
- : undefined,
951
- hasLayoutSupport,
952
- name,
953
- selector,
954
- styleVariationSelectors: Object.keys( styleVariationSelectors )
955
- .length
956
- ? styleVariationSelectors
957
- : undefined,
958
- };
959
- } );
960
-
961
- return result;
962
- };
963
-
964
- /**
965
- * If there is a separator block whose color is defined in theme.json via background,
966
- * update the separator color to the same value by using border color.
967
- *
968
- * @param {Object} config Theme.json configuration file object.
969
- * @return {Object} configTheme.json configuration file object updated.
970
- */
971
- function updateConfigWithSeparator( config ) {
972
- const needsSeparatorStyleUpdate =
973
- config.styles?.blocks[ 'core/separator' ] &&
974
- config.styles?.blocks[ 'core/separator' ].color?.background &&
975
- ! config.styles?.blocks[ 'core/separator' ].color?.text &&
976
- ! config.styles?.blocks[ 'core/separator' ].border?.color;
977
- if ( needsSeparatorStyleUpdate ) {
978
- return {
979
- ...config,
980
- styles: {
981
- ...config.styles,
982
- blocks: {
983
- ...config.styles.blocks,
984
- 'core/separator': {
985
- ...config.styles.blocks[ 'core/separator' ],
986
- color: {
987
- ...config.styles.blocks[ 'core/separator' ].color,
988
- text: config.styles?.blocks[ 'core/separator' ]
989
- .color.background,
990
- },
991
- },
992
- },
993
- },
994
- };
995
- }
996
- return config;
997
- }
998
-
999
- export function useGlobalStylesOutput() {
1000
- let { merged: mergedConfig } = useContext( GlobalStylesContext );
1001
-
1002
- const [ blockGap ] = useSetting( 'spacing.blockGap' );
1003
- const hasBlockGapSupport = blockGap !== null;
1004
- const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
1005
- const disableLayoutStyles = useSelect( ( select ) => {
1006
- const { getSettings } = select( blockEditorStore );
1007
- return !! getSettings().disableLayoutStyles;
1008
- } );
1009
-
1010
- const getBlockStyles = useSelect( ( select ) => {
1011
- return select( blocksStore ).getBlockStyles;
1012
- }, [] );
1013
-
1014
- return useMemo( () => {
1015
- if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
1016
- return [];
1017
- }
1018
- mergedConfig = updateConfigWithSeparator( mergedConfig );
1019
- const blockSelectors = getBlockSelectors(
1020
- getBlockTypes(),
1021
- getBlockStyles
1022
- );
1023
- const customProperties = toCustomProperties(
1024
- mergedConfig,
1025
- blockSelectors
1026
- );
1027
- const globalStyles = toStyles(
1028
- mergedConfig,
1029
- blockSelectors,
1030
- hasBlockGapSupport,
1031
- hasFallbackGapSupport,
1032
- disableLayoutStyles
1033
- );
1034
-
1035
- const filters = toSvgFilters( mergedConfig, blockSelectors );
1036
- const stylesheets = [
1037
- {
1038
- css: customProperties,
1039
- isGlobalStyles: true,
1040
- },
1041
- {
1042
- css: globalStyles,
1043
- isGlobalStyles: true,
1044
- },
1045
- // Load custom CSS in own stylesheet so that any invalid CSS entered in the input won't break all the global styles in the editor.
1046
- {
1047
- css: mergedConfig.styles.css ?? '',
1048
- isGlobalStyles: true,
1049
- },
1050
- ];
1051
-
1052
- return [ stylesheets, mergedConfig.settings, filters ];
1053
- }, [
1054
- hasBlockGapSupport,
1055
- hasFallbackGapSupport,
1056
- mergedConfig,
1057
- disableLayoutStyles,
1058
- ] );
1059
- }