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