@wordpress/editor 14.33.3 → 14.34.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 (301) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/collab-sidebar/comment-author-info.js +26 -14
  3. package/build/components/collab-sidebar/comment-author-info.js.map +2 -2
  4. package/build/components/document-bar/index.js +16 -3
  5. package/build/components/document-bar/index.js.map +2 -2
  6. package/build/components/editor/index.js +23 -4
  7. package/build/components/editor/index.js.map +3 -3
  8. package/build/components/editor-interface/index.js +15 -10
  9. package/build/components/editor-interface/index.js.map +3 -3
  10. package/build/components/entities-saved-states/entity-type-list.js +19 -15
  11. package/build/components/entities-saved-states/entity-type-list.js.map +3 -3
  12. package/build/components/global-styles/block-link.js +70 -0
  13. package/build/components/global-styles/block-link.js.map +7 -0
  14. package/build/components/global-styles/header.js +54 -0
  15. package/build/components/global-styles/header.js.map +7 -0
  16. package/build/components/global-styles/hooks.js +176 -0
  17. package/build/components/global-styles/hooks.js.map +7 -0
  18. package/build/components/global-styles/index.js +138 -0
  19. package/build/components/global-styles/index.js.map +7 -0
  20. package/build/components/global-styles/menu.js +95 -0
  21. package/build/components/global-styles/menu.js.map +7 -0
  22. package/build/components/global-styles-provider/index.js +3 -49
  23. package/build/components/global-styles-provider/index.js.map +3 -3
  24. package/build/components/global-styles-renderer/index.js +55 -0
  25. package/build/components/global-styles-renderer/index.js.map +7 -0
  26. package/build/components/global-styles-sidebar/default-sidebar.js +66 -0
  27. package/build/components/global-styles-sidebar/default-sidebar.js.map +7 -0
  28. package/build/components/global-styles-sidebar/index.js +182 -0
  29. package/build/components/global-styles-sidebar/index.js.map +7 -0
  30. package/build/components/global-styles-sidebar/welcome-guide-image.js +37 -0
  31. package/build/components/global-styles-sidebar/welcome-guide-image.js.map +7 -0
  32. package/build/components/global-styles-sidebar/welcome-guide.js +143 -0
  33. package/build/components/global-styles-sidebar/welcome-guide.js.map +7 -0
  34. package/build/components/header/index.js +12 -9
  35. package/build/components/header/index.js.map +2 -2
  36. package/build/components/post-featured-image/index.js +32 -1
  37. package/build/components/post-featured-image/index.js.map +3 -3
  38. package/build/components/provider/index.js +0 -2
  39. package/build/components/provider/index.js.map +3 -3
  40. package/build/components/style-book/categories.js +86 -0
  41. package/build/components/style-book/categories.js.map +7 -0
  42. package/build/components/style-book/color-examples.js +64 -0
  43. package/build/components/style-book/color-examples.js.map +7 -0
  44. package/build/components/style-book/constants.js +319 -0
  45. package/build/components/style-book/constants.js.map +7 -0
  46. package/build/components/style-book/duotone-examples.js +68 -0
  47. package/build/components/style-book/duotone-examples.js.map +7 -0
  48. package/build/components/style-book/examples.js +237 -0
  49. package/build/components/style-book/examples.js.map +7 -0
  50. package/build/components/style-book/index.js +627 -0
  51. package/build/components/style-book/index.js.map +7 -0
  52. package/build/components/style-book/types.js +17 -0
  53. package/build/components/style-book/types.js.map +7 -0
  54. package/build/components/styles-canvas/index.js +138 -0
  55. package/build/components/styles-canvas/index.js.map +7 -0
  56. package/build/components/styles-canvas/revisions.js +121 -0
  57. package/build/components/styles-canvas/revisions.js.map +7 -0
  58. package/build/components/styles-canvas/style-book.js +68 -0
  59. package/build/components/styles-canvas/style-book.js.map +7 -0
  60. package/build/components/visual-editor/index.js +4 -3
  61. package/build/components/visual-editor/index.js.map +2 -2
  62. package/build/dataviews/fields/content-preview/content-preview-view.js.map +2 -2
  63. package/build/hooks/index.js +1 -0
  64. package/build/hooks/index.js.map +2 -2
  65. package/build/hooks/media-upload.js +15 -4
  66. package/build/hooks/media-upload.js.map +3 -3
  67. package/build/hooks/push-changes-to-global-styles/index.js +322 -0
  68. package/build/hooks/push-changes-to-global-styles/index.js.map +7 -0
  69. package/build/hooks/use-global-styles-output.js +74 -0
  70. package/build/hooks/use-global-styles-output.js.map +7 -0
  71. package/build/private-apis.js +10 -5
  72. package/build/private-apis.js.map +3 -3
  73. package/build/store/private-actions.js +23 -0
  74. package/build/store/private-actions.js.map +2 -2
  75. package/build/store/private-selectors.js +10 -0
  76. package/build/store/private-selectors.js.map +2 -2
  77. package/build/store/reducer.js +24 -0
  78. package/build/store/reducer.js.map +2 -2
  79. package/build/{components/editor-interface/content-slot-fill.js → utils/set-nested-value.js} +24 -10
  80. package/build/utils/set-nested-value.js.map +7 -0
  81. package/build-module/components/collab-sidebar/comment-author-info.js +26 -14
  82. package/build-module/components/collab-sidebar/comment-author-info.js.map +2 -2
  83. package/build-module/components/document-bar/index.js +16 -3
  84. package/build-module/components/document-bar/index.js.map +2 -2
  85. package/build-module/components/editor/index.js +23 -4
  86. package/build-module/components/editor/index.js.map +2 -2
  87. package/build-module/components/editor-interface/index.js +15 -10
  88. package/build-module/components/editor-interface/index.js.map +2 -2
  89. package/build-module/components/entities-saved-states/entity-type-list.js +18 -14
  90. package/build-module/components/entities-saved-states/entity-type-list.js.map +2 -2
  91. package/build-module/components/global-styles/block-link.js +46 -0
  92. package/build-module/components/global-styles/block-link.js.map +7 -0
  93. package/build-module/components/global-styles/header.js +41 -0
  94. package/build-module/components/global-styles/header.js.map +7 -0
  95. package/build-module/components/global-styles/hooks.js +154 -0
  96. package/build-module/components/global-styles/hooks.js.map +7 -0
  97. package/build-module/components/global-styles/index.js +112 -0
  98. package/build-module/components/global-styles/index.js.map +7 -0
  99. package/build-module/components/global-styles/menu.js +71 -0
  100. package/build-module/components/global-styles/menu.js.map +7 -0
  101. package/build-module/components/global-styles-provider/index.js +3 -37
  102. package/build-module/components/global-styles-provider/index.js.map +2 -2
  103. package/build-module/components/global-styles-renderer/index.js +31 -0
  104. package/build-module/components/global-styles-renderer/index.js.map +7 -0
  105. package/build-module/components/global-styles-sidebar/default-sidebar.js +49 -0
  106. package/build-module/components/global-styles-sidebar/default-sidebar.js.map +7 -0
  107. package/build-module/components/global-styles-sidebar/index.js +152 -0
  108. package/build-module/components/global-styles-sidebar/index.js.map +7 -0
  109. package/build-module/components/global-styles-sidebar/welcome-guide-image.js +17 -0
  110. package/build-module/components/global-styles-sidebar/welcome-guide-image.js.map +7 -0
  111. package/build-module/components/global-styles-sidebar/welcome-guide.js +113 -0
  112. package/build-module/components/global-styles-sidebar/welcome-guide.js.map +7 -0
  113. package/build-module/components/header/index.js +12 -9
  114. package/build-module/components/header/index.js.map +2 -2
  115. package/build-module/components/post-featured-image/index.js +35 -3
  116. package/build-module/components/post-featured-image/index.js.map +2 -2
  117. package/build-module/components/provider/index.js +0 -2
  118. package/build-module/components/provider/index.js.map +2 -2
  119. package/build-module/components/style-book/categories.js +64 -0
  120. package/build-module/components/style-book/categories.js.map +7 -0
  121. package/build-module/components/style-book/color-examples.js +37 -0
  122. package/build-module/components/style-book/color-examples.js.map +7 -0
  123. package/build-module/components/style-book/constants.js +290 -0
  124. package/build-module/components/style-book/constants.js.map +7 -0
  125. package/build-module/components/style-book/duotone-examples.js +48 -0
  126. package/build-module/components/style-book/duotone-examples.js.map +7 -0
  127. package/build-module/components/style-book/examples.js +208 -0
  128. package/build-module/components/style-book/examples.js.map +7 -0
  129. package/build-module/components/style-book/index.js +618 -0
  130. package/build-module/components/style-book/index.js.map +7 -0
  131. package/build-module/components/style-book/types.js +1 -0
  132. package/build-module/components/style-book/types.js.map +7 -0
  133. package/build-module/components/styles-canvas/index.js +104 -0
  134. package/build-module/components/styles-canvas/index.js.map +7 -0
  135. package/build-module/components/styles-canvas/revisions.js +107 -0
  136. package/build-module/components/styles-canvas/revisions.js.map +7 -0
  137. package/build-module/components/styles-canvas/style-book.js +38 -0
  138. package/build-module/components/styles-canvas/style-book.js.map +7 -0
  139. package/build-module/components/visual-editor/index.js +4 -3
  140. package/build-module/components/visual-editor/index.js.map +2 -2
  141. package/build-module/dataviews/fields/content-preview/content-preview-view.js.map +2 -2
  142. package/build-module/hooks/index.js +1 -0
  143. package/build-module/hooks/index.js.map +2 -2
  144. package/build-module/hooks/media-upload.js +19 -5
  145. package/build-module/hooks/media-upload.js.map +2 -2
  146. package/build-module/hooks/push-changes-to-global-styles/index.js +309 -0
  147. package/build-module/hooks/push-changes-to-global-styles/index.js.map +7 -0
  148. package/build-module/hooks/use-global-styles-output.js +49 -0
  149. package/build-module/hooks/use-global-styles-output.js.map +7 -0
  150. package/build-module/private-apis.js +10 -8
  151. package/build-module/private-apis.js.map +2 -2
  152. package/build-module/store/private-actions.js +20 -0
  153. package/build-module/store/private-actions.js.map +2 -2
  154. package/build-module/store/private-selectors.js +8 -0
  155. package/build-module/store/private-selectors.js.map +2 -2
  156. package/build-module/store/reducer.js +22 -0
  157. package/build-module/store/reducer.js.map +2 -2
  158. package/build-module/utils/set-nested-value.js +23 -0
  159. package/build-module/utils/set-nested-value.js.map +7 -0
  160. package/build-style/style-rtl.css +3017 -11
  161. package/build-style/style.css +3018 -11
  162. package/build-types/components/collab-sidebar/comment-author-info.d.ts +5 -16
  163. package/build-types/components/collab-sidebar/comment-author-info.d.ts.map +1 -1
  164. package/build-types/components/document-bar/index.d.ts +2 -2
  165. package/build-types/components/document-bar/index.d.ts.map +1 -1
  166. package/build-types/components/editor/index.d.ts.map +1 -1
  167. package/build-types/components/editor-interface/index.d.ts +1 -3
  168. package/build-types/components/editor-interface/index.d.ts.map +1 -1
  169. package/build-types/components/entities-saved-states/entity-type-list.d.ts.map +1 -1
  170. package/build-types/components/global-styles/block-link.d.ts +12 -0
  171. package/build-types/components/global-styles/block-link.d.ts.map +1 -0
  172. package/build-types/components/global-styles/header.d.ts +7 -0
  173. package/build-types/components/global-styles/header.d.ts.map +1 -0
  174. package/build-types/components/global-styles/hooks.d.ts +24 -0
  175. package/build-types/components/global-styles/hooks.d.ts.map +1 -0
  176. package/build-types/components/global-styles/index.d.ts +6 -0
  177. package/build-types/components/global-styles/index.d.ts.map +1 -0
  178. package/build-types/components/global-styles/menu.d.ts +13 -0
  179. package/build-types/components/global-styles/menu.d.ts.map +1 -0
  180. package/build-types/components/global-styles-provider/index.d.ts +1 -5
  181. package/build-types/components/global-styles-provider/index.d.ts.map +1 -1
  182. package/build-types/components/global-styles-renderer/index.d.ts +4 -0
  183. package/build-types/components/global-styles-renderer/index.d.ts.map +1 -0
  184. package/build-types/components/global-styles-sidebar/default-sidebar.d.ts +13 -0
  185. package/build-types/components/global-styles-sidebar/default-sidebar.d.ts.map +1 -0
  186. package/build-types/components/global-styles-sidebar/index.d.ts +2 -0
  187. package/build-types/components/global-styles-sidebar/index.d.ts.map +1 -0
  188. package/build-types/components/global-styles-sidebar/welcome-guide-image.d.ts +5 -0
  189. package/build-types/components/global-styles-sidebar/welcome-guide-image.d.ts.map +1 -0
  190. package/build-types/components/global-styles-sidebar/welcome-guide.d.ts +2 -0
  191. package/build-types/components/global-styles-sidebar/welcome-guide.d.ts.map +1 -0
  192. package/build-types/components/header/index.d.ts +1 -3
  193. package/build-types/components/header/index.d.ts.map +1 -1
  194. package/build-types/components/provider/index.d.ts.map +1 -1
  195. package/build-types/components/style-book/categories.d.ts +18 -0
  196. package/build-types/components/style-book/categories.d.ts.map +1 -0
  197. package/build-types/components/style-book/color-examples.d.ts +7 -0
  198. package/build-types/components/style-book/color-examples.d.ts.map +1 -0
  199. package/build-types/components/style-book/constants.d.ts +11 -0
  200. package/build-types/components/style-book/constants.d.ts.map +1 -0
  201. package/build-types/components/style-book/duotone-examples.d.ts +9 -0
  202. package/build-types/components/style-book/duotone-examples.d.ts.map +1 -0
  203. package/build-types/components/style-book/examples.d.ts +12 -0
  204. package/build-types/components/style-book/examples.d.ts.map +1 -0
  205. package/build-types/components/style-book/index.d.ts +31 -0
  206. package/build-types/components/style-book/index.d.ts.map +1 -0
  207. package/build-types/components/style-book/types.d.ts +72 -0
  208. package/build-types/components/style-book/types.d.ts.map +1 -0
  209. package/build-types/components/styles-canvas/index.d.ts +16 -0
  210. package/build-types/components/styles-canvas/index.d.ts.map +1 -0
  211. package/build-types/components/styles-canvas/revisions.d.ts +5 -0
  212. package/build-types/components/styles-canvas/revisions.d.ts.map +1 -0
  213. package/build-types/components/styles-canvas/style-book.d.ts +6 -0
  214. package/build-types/components/styles-canvas/style-book.d.ts.map +1 -0
  215. package/build-types/components/visual-editor/index.d.ts +1 -2
  216. package/build-types/components/visual-editor/index.d.ts.map +1 -1
  217. package/build-types/dataviews/fields/content-preview/content-preview-view.d.ts.map +1 -1
  218. package/build-types/hooks/push-changes-to-global-styles/index.d.ts +2 -0
  219. package/build-types/hooks/push-changes-to-global-styles/index.d.ts.map +1 -0
  220. package/build-types/hooks/use-global-styles-output.d.ts +18 -0
  221. package/build-types/hooks/use-global-styles-output.d.ts.map +1 -0
  222. package/build-types/private-apis.d.ts.map +1 -1
  223. package/build-types/store/private-actions.d.ts +20 -0
  224. package/build-types/store/private-actions.d.ts.map +1 -1
  225. package/build-types/store/private-selectors.d.ts +14 -0
  226. package/build-types/store/private-selectors.d.ts.map +1 -1
  227. package/build-types/store/reducer.d.ts +20 -0
  228. package/build-types/store/reducer.d.ts.map +1 -1
  229. package/build-types/utils/set-nested-value.d.ts +20 -0
  230. package/build-types/utils/set-nested-value.d.ts.map +1 -0
  231. package/package.json +40 -40
  232. package/src/components/collab-sidebar/comment-author-info.js +32 -25
  233. package/src/components/collab-sidebar/style.scss +1 -1
  234. package/src/components/document-bar/index.js +18 -3
  235. package/src/components/editor/index.js +25 -1
  236. package/src/components/editor-help/style.scss +1 -1
  237. package/src/components/editor-interface/index.js +40 -39
  238. package/src/components/entities-saved-states/entity-type-list.js +19 -17
  239. package/src/components/global-styles/block-link.js +65 -0
  240. package/src/components/global-styles/header.js +48 -0
  241. package/src/components/global-styles/hooks.js +216 -0
  242. package/src/components/global-styles/index.js +125 -0
  243. package/src/components/global-styles/menu.js +101 -0
  244. package/src/components/global-styles/style.scss +11 -0
  245. package/src/components/global-styles-provider/index.js +3 -45
  246. package/src/components/global-styles-renderer/index.js +39 -0
  247. package/src/components/global-styles-sidebar/default-sidebar.js +46 -0
  248. package/src/components/global-styles-sidebar/index.js +177 -0
  249. package/src/components/global-styles-sidebar/style.scss +119 -0
  250. package/src/components/global-styles-sidebar/welcome-guide-image.js +11 -0
  251. package/src/components/global-styles-sidebar/welcome-guide.js +136 -0
  252. package/src/components/header/index.js +11 -6
  253. package/src/components/post-featured-image/index.js +44 -1
  254. package/src/components/post-last-revision/style.scss +1 -1
  255. package/src/components/post-panel-row/style.scss +1 -0
  256. package/src/components/post-publish-panel/style.scss +1 -1
  257. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +2 -2
  258. package/src/components/provider/index.js +0 -2
  259. package/src/components/style-book/categories.ts +97 -0
  260. package/src/components/style-book/color-examples.tsx +56 -0
  261. package/src/components/style-book/constants.ts +308 -0
  262. package/src/components/style-book/duotone-examples.tsx +56 -0
  263. package/src/components/style-book/examples.tsx +273 -0
  264. package/src/components/style-book/index.js +794 -0
  265. package/src/components/style-book/style.scss +44 -0
  266. package/src/components/style-book/test/categories.js +166 -0
  267. package/src/components/style-book/types.ts +80 -0
  268. package/src/components/styles-canvas/index.js +126 -0
  269. package/src/components/styles-canvas/revisions.js +144 -0
  270. package/src/components/styles-canvas/style-book.js +57 -0
  271. package/src/components/styles-canvas/style.scss +40 -0
  272. package/src/components/visual-editor/index.js +2 -1
  273. package/src/dataviews/fields/content-preview/content-preview-view.tsx +2 -0
  274. package/src/hooks/index.js +1 -0
  275. package/src/hooks/media-upload.js +25 -5
  276. package/src/hooks/push-changes-to-global-styles/index.js +391 -0
  277. package/src/hooks/push-changes-to-global-styles/style.scss +4 -0
  278. package/src/hooks/use-global-styles-output.js +76 -0
  279. package/src/private-apis.js +10 -8
  280. package/src/store/private-actions.js +37 -0
  281. package/src/store/private-selectors.js +20 -0
  282. package/src/store/reducer.js +36 -0
  283. package/src/style.scss +7 -1
  284. package/src/utils/set-nested-value.js +39 -0
  285. package/tsconfig.json +3 -0
  286. package/tsconfig.tsbuildinfo +1 -1
  287. package/build/components/block-settings-menu/content-only-settings-menu.js +0 -186
  288. package/build/components/block-settings-menu/content-only-settings-menu.js.map +0 -7
  289. package/build/components/editor-interface/content-slot-fill.js.map +0 -7
  290. package/build-module/components/block-settings-menu/content-only-settings-menu.js +0 -161
  291. package/build-module/components/block-settings-menu/content-only-settings-menu.js.map +0 -7
  292. package/build-module/components/editor-interface/content-slot-fill.js +0 -9
  293. package/build-module/components/editor-interface/content-slot-fill.js.map +0 -7
  294. package/build-types/components/block-settings-menu/content-only-settings-menu.d.ts +0 -2
  295. package/build-types/components/block-settings-menu/content-only-settings-menu.d.ts.map +0 -1
  296. package/build-types/components/editor-interface/content-slot-fill.d.ts +0 -14
  297. package/build-types/components/editor-interface/content-slot-fill.d.ts.map +0 -1
  298. package/src/components/block-settings-menu/content-only-settings-menu.js +0 -185
  299. package/src/components/block-settings-menu/content-only-settings-menu.native.js +0 -4
  300. package/src/components/block-settings-menu/style.scss +0 -6
  301. package/src/components/editor-interface/content-slot-fill.js +0 -10
@@ -0,0 +1,65 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { useEffect } from '@wordpress/element';
6
+ import { store as blockEditorStore } from '@wordpress/block-editor';
7
+ import { usePrevious } from '@wordpress/compose';
8
+
9
+ /**
10
+ * Auto-navigate to block styles when a block is selected in the canvas.
11
+ *
12
+ * @param {Object} props
13
+ * @param {string} props.path Current navigation path.
14
+ * @param {Function} props.onPathChange Callback to change the navigation path.
15
+ */
16
+ export function GlobalStylesBlockLink( { path, onPathChange } ) {
17
+ const { selectedBlockName, selectedBlockClientId } = useSelect(
18
+ ( select ) => {
19
+ const { getSelectedBlockClientId, getBlockName } =
20
+ select( blockEditorStore );
21
+ const clientId = getSelectedBlockClientId();
22
+ return {
23
+ selectedBlockName: getBlockName( clientId ),
24
+ selectedBlockClientId: clientId,
25
+ };
26
+ },
27
+ []
28
+ );
29
+
30
+ // const blockHasGlobalStyles = useBlockHasGlobalStyles( selectedBlockName );
31
+ const blockHasGlobalStyles = true;
32
+ const previousBlockClientId = usePrevious( selectedBlockClientId );
33
+
34
+ // When we're in the `Blocks` screen enable deep linking to the selected block.
35
+ useEffect( () => {
36
+ // Only navigate when block selection changes, not when path changes
37
+ if ( selectedBlockClientId === previousBlockClientId ) {
38
+ return;
39
+ }
40
+ if ( ! selectedBlockClientId || ! blockHasGlobalStyles ) {
41
+ return;
42
+ }
43
+ if (
44
+ ! path ||
45
+ ( path !== '/blocks' && ! path.startsWith( '/blocks/' ) )
46
+ ) {
47
+ return;
48
+ }
49
+ const newPath = '/blocks/' + encodeURIComponent( selectedBlockName );
50
+ // Avoid navigating to the same path. This can happen when selecting
51
+ // a new block of the same type.
52
+ if ( newPath !== path ) {
53
+ onPathChange?.( newPath );
54
+ }
55
+ }, [
56
+ selectedBlockClientId,
57
+ previousBlockClientId,
58
+ selectedBlockName,
59
+ blockHasGlobalStyles,
60
+ path,
61
+ onPathChange,
62
+ ] );
63
+
64
+ return null;
65
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ __experimentalHStack as HStack,
6
+ __experimentalVStack as VStack,
7
+ __experimentalSpacer as Spacer,
8
+ __experimentalHeading as Heading,
9
+ __experimentalView as View,
10
+ Navigator,
11
+ } from '@wordpress/components';
12
+ import { isRTL, __ } from '@wordpress/i18n';
13
+ import { chevronRight, chevronLeft } from '@wordpress/icons';
14
+
15
+ function ScreenHeader( { title, description, onBack } ) {
16
+ return (
17
+ <VStack spacing={ 0 }>
18
+ <View>
19
+ <Spacer marginBottom={ 0 } paddingX={ 4 } paddingY={ 3 }>
20
+ <HStack spacing={ 2 }>
21
+ <Navigator.BackButton
22
+ icon={ isRTL() ? chevronRight : chevronLeft }
23
+ size="small"
24
+ label={ __( 'Back' ) }
25
+ onClick={ onBack }
26
+ />
27
+ <Spacer>
28
+ <Heading
29
+ className="editor-global-styles-header"
30
+ level={ 2 }
31
+ size={ 13 }
32
+ >
33
+ { title }
34
+ </Heading>
35
+ </Spacer>
36
+ </HStack>
37
+ </Spacer>
38
+ </View>
39
+ { description && (
40
+ <p className="editor-global-styles-header__description">
41
+ { description }
42
+ </p>
43
+ ) }
44
+ </VStack>
45
+ );
46
+ }
47
+
48
+ export default ScreenHeader;
@@ -0,0 +1,216 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useMemo, useCallback } from '@wordpress/element';
5
+ import {
6
+ mergeGlobalStyles,
7
+ getStyle,
8
+ getSetting,
9
+ } from '@wordpress/global-styles-engine';
10
+ import { store as coreStore } from '@wordpress/core-data';
11
+ import { useSelect, useDispatch } from '@wordpress/data';
12
+ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+ import { unlock } from '../../lock-unlock';
18
+
19
+ const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
20
+
21
+ /**
22
+ * Hook to fetch and manage user global styles config
23
+ */
24
+ function useGlobalStylesUserConfig() {
25
+ const { globalStylesId, isReady, settings, styles, _links } = useSelect(
26
+ ( select ) => {
27
+ const {
28
+ getEntityRecord,
29
+ getEditedEntityRecord,
30
+ hasFinishedResolution,
31
+ canUser,
32
+ } = select( coreStore );
33
+ const _globalStylesId =
34
+ select( coreStore ).__experimentalGetCurrentGlobalStylesId();
35
+
36
+ let record;
37
+
38
+ const userCanEditGlobalStyles = _globalStylesId
39
+ ? canUser( 'update', {
40
+ kind: 'root',
41
+ name: 'globalStyles',
42
+ id: _globalStylesId,
43
+ } )
44
+ : null;
45
+
46
+ if (
47
+ _globalStylesId &&
48
+ typeof userCanEditGlobalStyles === 'boolean'
49
+ ) {
50
+ if ( userCanEditGlobalStyles ) {
51
+ record = getEditedEntityRecord(
52
+ 'root',
53
+ 'globalStyles',
54
+ _globalStylesId
55
+ );
56
+ } else {
57
+ record = getEntityRecord(
58
+ 'root',
59
+ 'globalStyles',
60
+ _globalStylesId,
61
+ { context: 'view' }
62
+ );
63
+ }
64
+ }
65
+
66
+ let hasResolved = false;
67
+ if (
68
+ hasFinishedResolution(
69
+ '__experimentalGetCurrentGlobalStylesId'
70
+ )
71
+ ) {
72
+ if ( _globalStylesId ) {
73
+ hasResolved = userCanEditGlobalStyles
74
+ ? hasFinishedResolution( 'getEditedEntityRecord', [
75
+ 'root',
76
+ 'globalStyles',
77
+ _globalStylesId,
78
+ ] )
79
+ : hasFinishedResolution( 'getEntityRecord', [
80
+ 'root',
81
+ 'globalStyles',
82
+ _globalStylesId,
83
+ { context: 'view' },
84
+ ] );
85
+ } else {
86
+ hasResolved = true;
87
+ }
88
+ }
89
+
90
+ return {
91
+ globalStylesId: _globalStylesId,
92
+ isReady: hasResolved,
93
+ settings: record?.settings,
94
+ styles: record?.styles,
95
+ _links: record?._links,
96
+ };
97
+ },
98
+ []
99
+ );
100
+
101
+ const { getEditedEntityRecord } = useSelect( coreStore );
102
+ const { editEntityRecord } = useDispatch( coreStore );
103
+
104
+ const config = useMemo( () => {
105
+ return {
106
+ settings: settings ?? {},
107
+ styles: styles ?? {},
108
+ _links: _links ?? {},
109
+ };
110
+ }, [ settings, styles, _links ] );
111
+
112
+ const setConfig = useCallback(
113
+ ( callbackOrObject, options = {} ) => {
114
+ const record = getEditedEntityRecord(
115
+ 'root',
116
+ 'globalStyles',
117
+ globalStylesId
118
+ );
119
+
120
+ const currentConfig = {
121
+ styles: record?.styles ?? {},
122
+ settings: record?.settings ?? {},
123
+ _links: record?._links ?? {},
124
+ };
125
+
126
+ const updatedConfig =
127
+ typeof callbackOrObject === 'function'
128
+ ? callbackOrObject( currentConfig )
129
+ : callbackOrObject;
130
+
131
+ editEntityRecord(
132
+ 'root',
133
+ 'globalStyles',
134
+ globalStylesId,
135
+ {
136
+ styles: cleanEmptyObject( updatedConfig.styles ) || {},
137
+ settings: cleanEmptyObject( updatedConfig.settings ) || {},
138
+ _links: cleanEmptyObject( updatedConfig._links ) || {},
139
+ },
140
+ options
141
+ );
142
+ },
143
+ [ globalStylesId, editEntityRecord, getEditedEntityRecord ]
144
+ );
145
+
146
+ return [ isReady, config, setConfig ];
147
+ }
148
+
149
+ /**
150
+ * Hook to fetch base/theme global styles config
151
+ */
152
+ function useGlobalStylesBaseConfig() {
153
+ const baseConfig = useSelect(
154
+ ( select ) =>
155
+ select( coreStore ).__experimentalGetCurrentThemeBaseGlobalStyles(),
156
+ []
157
+ );
158
+ return [ !! baseConfig, baseConfig ];
159
+ }
160
+
161
+ /**
162
+ * Hook to get merged global styles configuration
163
+ *
164
+ * @return {Object} Object containing merged, base, user configs and setUser function
165
+ * { merged, base, user, setUser }
166
+ */
167
+ export function useGlobalStyles() {
168
+ const [ isUserConfigReady, userConfig, setUserConfig ] =
169
+ useGlobalStylesUserConfig();
170
+ const [ isBaseConfigReady, baseConfig ] = useGlobalStylesBaseConfig();
171
+
172
+ const merged = useMemo( () => {
173
+ if ( ! isUserConfigReady || ! isBaseConfigReady ) {
174
+ return {};
175
+ }
176
+ return mergeGlobalStyles( baseConfig || {}, userConfig );
177
+ }, [ isUserConfigReady, isBaseConfigReady, baseConfig, userConfig ] );
178
+
179
+ return {
180
+ merged,
181
+ base: baseConfig || {},
182
+ user: userConfig,
183
+ setUser: setUserConfig,
184
+ isReady: isUserConfigReady && isBaseConfigReady,
185
+ };
186
+ }
187
+
188
+ /**
189
+ * Hook to get a style value from global styles
190
+ *
191
+ * @param {string} path Style path (e.g., 'color.background')
192
+ * @param {string} blockName Optional block name
193
+ * @return {*} Style value
194
+ */
195
+ export function useStyle( path, blockName ) {
196
+ const { merged } = useGlobalStyles();
197
+ return useMemo(
198
+ () => getStyle( merged, path, blockName ),
199
+ [ merged, path, blockName ]
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Hook to get a setting value from global styles
205
+ *
206
+ * @param {string} path Setting path (e.g., 'spacing.blockGap')
207
+ * @param {string} blockName Optional block name
208
+ * @return {*} Setting value
209
+ */
210
+ export function useSetting( path, blockName ) {
211
+ const { merged } = useGlobalStyles();
212
+ return useMemo(
213
+ () => getSetting( merged, path, blockName ),
214
+ [ merged, path, blockName ]
215
+ );
216
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store as coreStore } from '@wordpress/core-data';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { useMemo } from '@wordpress/element';
7
+ import { GlobalStylesUI } from '@wordpress/global-styles-ui';
8
+ import { uploadMedia } from '@wordpress/media-utils';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import { store as editorStore } from '../../store';
14
+ import { GlobalStylesBlockLink } from './block-link';
15
+ import { useGlobalStyles } from './hooks';
16
+
17
+ /**
18
+ * Hook to fetch server CSS and settings for BlockEditorProvider that are not Global Styles.
19
+ */
20
+ function useServerData() {
21
+ const {
22
+ styles,
23
+ __unstableResolvedAssets,
24
+ colors,
25
+ gradients,
26
+ __experimentalDiscussionSettings,
27
+ mediaUploadHandler,
28
+ fontLibraryEnabled,
29
+ } = useSelect( ( select ) => {
30
+ const { getEditorSettings } = select( editorStore );
31
+ const { canUser } = select( coreStore );
32
+ const editorSettings = getEditorSettings();
33
+
34
+ const canUserUploadMedia = canUser( 'create', {
35
+ kind: 'root',
36
+ name: 'media',
37
+ } );
38
+
39
+ return {
40
+ styles: editorSettings?.styles || [],
41
+ __unstableResolvedAssets:
42
+ editorSettings?.__unstableResolvedAssets || {},
43
+ colors: editorSettings?.colors || [],
44
+ gradients: editorSettings?.gradients || [],
45
+ __experimentalDiscussionSettings:
46
+ editorSettings?.__experimentalDiscussionSettings,
47
+ mediaUploadHandler: canUserUploadMedia ? uploadMedia : undefined,
48
+ fontLibraryEnabled: editorSettings?.fontLibraryEnabled ?? true,
49
+ };
50
+ }, [] );
51
+
52
+ // Filter out global styles to get only server-provided styles
53
+ const serverCSS = useMemo( () => {
54
+ if ( ! styles ) {
55
+ return [];
56
+ }
57
+ return styles.filter( ( style ) => ! style.isGlobalStyles );
58
+ }, [ styles ] );
59
+
60
+ // Create server settings object
61
+ const serverSettings = useMemo( () => {
62
+ return {
63
+ __unstableResolvedAssets,
64
+ settings: {
65
+ color: {
66
+ palette: {
67
+ theme: colors,
68
+ },
69
+ gradients: {
70
+ theme: gradients,
71
+ },
72
+ duotone: {
73
+ theme: [],
74
+ },
75
+ },
76
+ },
77
+ __experimentalDiscussionSettings,
78
+ mediaUpload: mediaUploadHandler,
79
+ };
80
+ }, [
81
+ __unstableResolvedAssets,
82
+ colors,
83
+ gradients,
84
+ __experimentalDiscussionSettings,
85
+ mediaUploadHandler,
86
+ ] );
87
+
88
+ return { serverCSS, serverSettings, fontLibraryEnabled };
89
+ }
90
+
91
+ export default function GlobalStylesUIWrapper( { path, onPathChange } ) {
92
+ const {
93
+ user: userConfig,
94
+ base: baseConfig,
95
+ setUser: setUserConfig,
96
+ isReady,
97
+ } = useGlobalStyles();
98
+ const { serverCSS, serverSettings, fontLibraryEnabled } = useServerData();
99
+
100
+ // Show loading state while data is being fetched
101
+ if ( ! isReady ) {
102
+ return null;
103
+ }
104
+
105
+ return (
106
+ <>
107
+ <GlobalStylesUI
108
+ value={ userConfig }
109
+ baseValue={ baseConfig || {} }
110
+ onChange={ setUserConfig }
111
+ path={ path }
112
+ onPathChange={ onPathChange }
113
+ fontLibraryEnabled={ fontLibraryEnabled }
114
+ serverCSS={ serverCSS }
115
+ serverSettings={ serverSettings }
116
+ />
117
+ <GlobalStylesBlockLink
118
+ path={ path }
119
+ onPathChange={ onPathChange }
120
+ />
121
+ </>
122
+ );
123
+ }
124
+
125
+ export { useGlobalStyles, useStyle, useSetting } from './hooks';
@@ -0,0 +1,101 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
5
+ import { useSelect, useDispatch } from '@wordpress/data';
6
+ import { __ } from '@wordpress/i18n';
7
+ import { store as preferencesStore } from '@wordpress/preferences';
8
+ import { moreVertical } from '@wordpress/icons';
9
+ import { store as coreStore } from '@wordpress/core-data';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import { useGlobalStyles } from './hooks';
15
+
16
+ /**
17
+ * Action menu with Reset, Welcome Guide, and Additional CSS.
18
+ *
19
+ * @param {Object} props Component props.
20
+ * @param {boolean} props.hideWelcomeGuide Whether to hide the Welcome Guide option.
21
+ * @param {Function} props.onChangePath Callback for navigation to different paths (e.g., '/css').
22
+ * @return {JSX.Element} The Global Styles Action Menu component.
23
+ */
24
+ export function GlobalStylesActionMenu( {
25
+ hideWelcomeGuide = false,
26
+ onChangePath,
27
+ } ) {
28
+ const { user, setUser } = useGlobalStyles();
29
+
30
+ // Check if there are user customizations that can be reset
31
+ const canReset =
32
+ !! user &&
33
+ ( Object.keys( user?.styles ?? {} ).length > 0 ||
34
+ Object.keys( user?.settings ?? {} ).length > 0 );
35
+
36
+ // Reset function to clear all user customizations
37
+ const onReset = () => {
38
+ setUser( { styles: {}, settings: {} } );
39
+ };
40
+ const { toggle } = useDispatch( preferencesStore );
41
+ const { canEditCSS } = useSelect( ( select ) => {
42
+ const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
43
+ select( coreStore );
44
+
45
+ const globalStylesId = __experimentalGetCurrentGlobalStylesId();
46
+ const globalStyles = globalStylesId
47
+ ? getEntityRecord( 'root', 'globalStyles', globalStylesId )
48
+ : undefined;
49
+
50
+ return {
51
+ canEditCSS: !! globalStyles?._links?.[ 'wp:action-edit-css' ],
52
+ };
53
+ }, [] );
54
+ const loadCustomCSS = () => {
55
+ onChangePath( '/css' );
56
+ };
57
+
58
+ return (
59
+ <DropdownMenu
60
+ icon={ moreVertical }
61
+ label={ __( 'More' ) }
62
+ toggleProps={ { size: 'compact' } }
63
+ >
64
+ { ( { onClose } ) => (
65
+ <>
66
+ <MenuGroup>
67
+ { canEditCSS && (
68
+ <MenuItem onClick={ loadCustomCSS }>
69
+ { __( 'Additional CSS' ) }
70
+ </MenuItem>
71
+ ) }
72
+ { ! hideWelcomeGuide && (
73
+ <MenuItem
74
+ onClick={ () => {
75
+ toggle(
76
+ 'core/edit-site',
77
+ 'welcomeGuideStyles'
78
+ );
79
+ onClose();
80
+ } }
81
+ >
82
+ { __( 'Welcome Guide' ) }
83
+ </MenuItem>
84
+ ) }
85
+ </MenuGroup>
86
+ <MenuGroup>
87
+ <MenuItem
88
+ onClick={ () => {
89
+ onReset();
90
+ onClose();
91
+ } }
92
+ disabled={ ! canReset }
93
+ >
94
+ { __( 'Reset styles' ) }
95
+ </MenuItem>
96
+ </MenuGroup>
97
+ </>
98
+ ) }
99
+ </DropdownMenu>
100
+ );
101
+ }
@@ -0,0 +1,11 @@
1
+ @use "@wordpress/base-styles/colors" as *;
2
+ @use "@wordpress/base-styles/variables" as *;
3
+
4
+ .editor-global-styles-header__description {
5
+ padding: 0 $grid-unit-20;
6
+ }
7
+
8
+ .editor-global-styles-header {
9
+ // Need to override the too specific bottom margin for complementary areas.
10
+ margin-bottom: 0 !important;
11
+ }
@@ -1,9 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import deepmerge from 'deepmerge';
5
- import { isPlainObject } from 'is-plain-object';
6
-
7
1
  /**
8
2
  * WordPress dependencies
9
3
  */
@@ -11,37 +5,14 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
11
5
  import { store as coreStore } from '@wordpress/core-data';
12
6
  import { useSelect, useDispatch } from '@wordpress/data';
13
7
  import { useMemo, useCallback } from '@wordpress/element';
8
+ import { mergeGlobalStyles } from '@wordpress/global-styles-engine';
14
9
 
15
10
  /**
16
11
  * Internal dependencies
17
12
  */
18
13
  import { unlock } from '../../lock-unlock';
19
14
 
20
- const { GlobalStylesContext, cleanEmptyObject } = unlock(
21
- blockEditorPrivateApis
22
- );
23
-
24
- export function mergeBaseAndUserConfigs( base, user ) {
25
- return deepmerge( base, user, {
26
- /*
27
- * We only pass as arrays the presets,
28
- * in which case we want the new array of values
29
- * to override the old array (no merging).
30
- */
31
- isMergeableObject: isPlainObject,
32
- /*
33
- * Exceptions to the above rule.
34
- * Background images should be replaced, not merged,
35
- * as they themselves are specific object definitions for the style.
36
- */
37
- customMerge: ( key ) => {
38
- if ( key === 'backgroundImage' ) {
39
- return ( baseConfig, userConfig ) => userConfig;
40
- }
41
- return undefined;
42
- },
43
- } );
44
- }
15
+ const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
45
16
 
46
17
  function useGlobalStylesUserConfig() {
47
18
  const { globalStylesId, isReady, settings, styles, _links } = useSelect(
@@ -212,7 +183,7 @@ export function useGlobalStylesContext() {
212
183
  return {};
213
184
  }
214
185
 
215
- return mergeBaseAndUserConfigs( baseConfig, userConfig );
186
+ return mergeGlobalStyles( baseConfig, userConfig );
216
187
  }, [ userConfig, baseConfig ] );
217
188
 
218
189
  const context = useMemo( () => {
@@ -234,16 +205,3 @@ export function useGlobalStylesContext() {
234
205
 
235
206
  return context;
236
207
  }
237
-
238
- export function GlobalStylesProvider( { children } ) {
239
- const context = useGlobalStylesContext();
240
- if ( ! context.isReady ) {
241
- return null;
242
- }
243
-
244
- return (
245
- <GlobalStylesContext.Provider value={ context }>
246
- { children }
247
- </GlobalStylesContext.Provider>
248
- );
249
- }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect } from '@wordpress/element';
5
+ import { useSelect, useDispatch } from '@wordpress/data';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { store as editorStore } from '../../store';
11
+ import { useGlobalStylesOutput } from '../../hooks/use-global-styles-output';
12
+
13
+ function useGlobalStylesRenderer( disableRootPadding ) {
14
+ const [ styles, settings ] = useGlobalStylesOutput( disableRootPadding );
15
+ const { getEditorSettings } = useSelect( editorStore );
16
+ const { updateEditorSettings } = useDispatch( editorStore );
17
+
18
+ useEffect( () => {
19
+ if ( ! styles || ! settings ) {
20
+ return;
21
+ }
22
+
23
+ const currentStoreSettings = getEditorSettings();
24
+ const nonGlobalStyles = Object.values(
25
+ currentStoreSettings.styles ?? []
26
+ ).filter( ( style ) => ! style.isGlobalStyles );
27
+ updateEditorSettings( {
28
+ ...currentStoreSettings,
29
+ styles: [ ...nonGlobalStyles, ...styles ],
30
+ __experimentalFeatures: settings,
31
+ } );
32
+ }, [ styles, settings, updateEditorSettings, getEditorSettings ] );
33
+ }
34
+
35
+ export function GlobalStylesRenderer( { disableRootPadding } ) {
36
+ useGlobalStylesRenderer( disableRootPadding );
37
+
38
+ return null;
39
+ }