@wordpress/block-editor 12.12.0 → 12.13.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 (287) hide show
  1. package/CHANGELOG.md +12 -10
  2. package/README.md +35 -3
  3. package/build/components/block-alignment-control/use-available-alignments.js +30 -28
  4. package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
  5. package/build/components/block-list/block.native.js +4 -4
  6. package/build/components/block-list/block.native.js.map +1 -1
  7. package/build/components/block-list/layout.js +2 -3
  8. package/build/components/block-list/layout.js.map +1 -1
  9. package/build/components/border-radius-control/index.js +3 -2
  10. package/build/components/border-radius-control/index.js.map +1 -1
  11. package/build/components/color-palette/with-color-context.js +6 -6
  12. package/build/components/color-palette/with-color-context.js.map +1 -1
  13. package/build/components/colors/with-colors.js +2 -8
  14. package/build/components/colors/with-colors.js.map +1 -1
  15. package/build/components/colors-gradients/control.js +6 -7
  16. package/build/components/colors-gradients/control.js.map +1 -1
  17. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -13
  18. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  19. package/build/components/font-family/index.js +2 -3
  20. package/build/components/font-family/index.js.map +1 -1
  21. package/build/components/font-sizes/font-size-picker.js +3 -5
  22. package/build/components/font-sizes/font-size-picker.js.map +1 -1
  23. package/build/components/font-sizes/with-font-sizes.js +3 -4
  24. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  25. package/build/components/global-styles/filters-panel.js +7 -8
  26. package/build/components/global-styles/filters-panel.js.map +1 -1
  27. package/build/components/global-styles/image-settings-panel.js +2 -2
  28. package/build/components/global-styles/image-settings-panel.js.map +1 -1
  29. package/build/components/global-styles/typography-panel.js +1 -1
  30. package/build/components/global-styles/typography-panel.js.map +1 -1
  31. package/build/components/gradients/use-gradient.js +2 -5
  32. package/build/components/gradients/use-gradient.js.map +1 -1
  33. package/build/components/height-control/index.js +3 -3
  34. package/build/components/height-control/index.js.map +1 -1
  35. package/build/components/index.js +9 -2
  36. package/build/components/index.js.map +1 -1
  37. package/build/components/index.native.js +9 -2
  38. package/build/components/index.native.js.map +1 -1
  39. package/build/components/inner-blocks/index.js +2 -2
  40. package/build/components/inner-blocks/index.js.map +1 -1
  41. package/build/components/letter-spacing-control/index.js +3 -3
  42. package/build/components/letter-spacing-control/index.js.map +1 -1
  43. package/build/components/link-control/search-item.js +11 -0
  44. package/build/components/link-control/search-item.js.map +1 -1
  45. package/build/components/link-control/search-results.js +2 -1
  46. package/build/components/link-control/search-results.js.map +1 -1
  47. package/build/components/link-control/use-search-handler.js +10 -5
  48. package/build/components/link-control/use-search-handler.js.map +1 -1
  49. package/build/components/resizable-box-popover/index.js +1 -1
  50. package/build/components/resizable-box-popover/index.js.map +1 -1
  51. package/build/components/rich-text/index.js +1 -1
  52. package/build/components/rich-text/index.js.map +1 -1
  53. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -3
  54. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  55. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -3
  56. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  57. package/build/components/unit-control/index.js +3 -3
  58. package/build/components/unit-control/index.js.map +1 -1
  59. package/build/components/use-block-commands/index.js +6 -1
  60. package/build/components/use-block-commands/index.js.map +1 -1
  61. package/build/components/use-settings/index.js +212 -0
  62. package/build/components/use-settings/index.js.map +1 -0
  63. package/build/hooks/align.js +51 -35
  64. package/build/hooks/align.js.map +1 -1
  65. package/build/hooks/anchor.js +37 -32
  66. package/build/hooks/anchor.js.map +1 -1
  67. package/build/hooks/background.js +4 -4
  68. package/build/hooks/background.js.map +1 -1
  69. package/build/hooks/color.js +2 -4
  70. package/build/hooks/color.js.map +1 -1
  71. package/build/hooks/duotone.js +10 -9
  72. package/build/hooks/duotone.js.map +1 -1
  73. package/build/hooks/font-size.js +4 -4
  74. package/build/hooks/font-size.js.map +1 -1
  75. package/build/hooks/layout.js +10 -11
  76. package/build/hooks/layout.js.map +1 -1
  77. package/build/hooks/line-height.js +3 -3
  78. package/build/hooks/line-height.js.map +1 -1
  79. package/build/hooks/position.js +2 -3
  80. package/build/hooks/position.js.map +1 -1
  81. package/build/hooks/use-color-props.js +3 -11
  82. package/build/hooks/use-color-props.js.map +1 -1
  83. package/build/hooks/utils.js +1 -42
  84. package/build/hooks/utils.js.map +1 -1
  85. package/build/layouts/constrained.js +3 -3
  86. package/build/layouts/constrained.js.map +1 -1
  87. package/build/utils/object.js +4 -1
  88. package/build/utils/object.js.map +1 -1
  89. package/build/utils/transform-styles/index.js +19 -24
  90. package/build/utils/transform-styles/index.js.map +1 -1
  91. package/build-module/components/block-alignment-control/use-available-alignments.js +30 -28
  92. package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
  93. package/build-module/components/block-list/block.native.js +4 -4
  94. package/build-module/components/block-list/block.native.js.map +1 -1
  95. package/build-module/components/block-list/layout.js +2 -2
  96. package/build-module/components/block-list/layout.js.map +1 -1
  97. package/build-module/components/border-radius-control/index.js +3 -2
  98. package/build-module/components/border-radius-control/index.js.map +1 -1
  99. package/build-module/components/color-palette/with-color-context.js +6 -5
  100. package/build-module/components/color-palette/with-color-context.js.map +1 -1
  101. package/build-module/components/colors/with-colors.js +2 -7
  102. package/build-module/components/colors/with-colors.js.map +1 -1
  103. package/build-module/components/colors-gradients/control.js +6 -7
  104. package/build-module/components/colors-gradients/control.js.map +1 -1
  105. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -12
  106. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  107. package/build-module/components/font-family/index.js +2 -2
  108. package/build-module/components/font-family/index.js.map +1 -1
  109. package/build-module/components/font-sizes/font-size-picker.js +3 -4
  110. package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
  111. package/build-module/components/font-sizes/with-font-sizes.js +3 -3
  112. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  113. package/build-module/components/global-styles/filters-panel.js +7 -8
  114. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  115. package/build-module/components/global-styles/image-settings-panel.js +2 -2
  116. package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
  117. package/build-module/components/global-styles/typography-panel.js +1 -1
  118. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  119. package/build-module/components/gradients/use-gradient.js +2 -4
  120. package/build-module/components/gradients/use-gradient.js.map +1 -1
  121. package/build-module/components/height-control/index.js +3 -2
  122. package/build-module/components/height-control/index.js.map +1 -1
  123. package/build-module/components/index.js +1 -1
  124. package/build-module/components/index.js.map +1 -1
  125. package/build-module/components/index.native.js +1 -1
  126. package/build-module/components/index.native.js.map +1 -1
  127. package/build-module/components/inner-blocks/index.js +2 -2
  128. package/build-module/components/inner-blocks/index.js.map +1 -1
  129. package/build-module/components/letter-spacing-control/index.js +3 -2
  130. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  131. package/build-module/components/link-control/search-item.js +12 -1
  132. package/build-module/components/link-control/search-item.js.map +1 -1
  133. package/build-module/components/link-control/search-results.js +2 -1
  134. package/build-module/components/link-control/search-results.js.map +1 -1
  135. package/build-module/components/link-control/use-search-handler.js +10 -5
  136. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  137. package/build-module/components/resizable-box-popover/index.js +1 -1
  138. package/build-module/components/resizable-box-popover/index.js.map +1 -1
  139. package/build-module/components/rich-text/index.js +1 -1
  140. package/build-module/components/rich-text/index.js.map +1 -1
  141. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -2
  142. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  143. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -2
  144. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  145. package/build-module/components/unit-control/index.js +3 -2
  146. package/build-module/components/unit-control/index.js.map +1 -1
  147. package/build-module/components/use-block-commands/index.js +5 -1
  148. package/build-module/components/use-block-commands/index.js.map +1 -1
  149. package/build-module/components/use-settings/index.js +203 -0
  150. package/build-module/components/use-settings/index.js.map +1 -0
  151. package/build-module/hooks/align.js +51 -35
  152. package/build-module/hooks/align.js.map +1 -1
  153. package/build-module/hooks/anchor.js +37 -32
  154. package/build-module/hooks/anchor.js.map +1 -1
  155. package/build-module/hooks/background.js +4 -4
  156. package/build-module/hooks/background.js.map +1 -1
  157. package/build-module/hooks/color.js +2 -4
  158. package/build-module/hooks/color.js.map +1 -1
  159. package/build-module/hooks/duotone.js +11 -10
  160. package/build-module/hooks/duotone.js.map +1 -1
  161. package/build-module/hooks/font-size.js +4 -4
  162. package/build-module/hooks/font-size.js.map +1 -1
  163. package/build-module/hooks/layout.js +10 -11
  164. package/build-module/hooks/layout.js.map +1 -1
  165. package/build-module/hooks/line-height.js +3 -3
  166. package/build-module/hooks/line-height.js.map +1 -1
  167. package/build-module/hooks/position.js +2 -3
  168. package/build-module/hooks/position.js.map +1 -1
  169. package/build-module/hooks/use-color-props.js +3 -11
  170. package/build-module/hooks/use-color-props.js.map +1 -1
  171. package/build-module/hooks/utils.js +2 -43
  172. package/build-module/hooks/utils.js.map +1 -1
  173. package/build-module/layouts/constrained.js +3 -2
  174. package/build-module/layouts/constrained.js.map +1 -1
  175. package/build-module/utils/object.js +3 -1
  176. package/build-module/utils/object.js.map +1 -1
  177. package/build-module/utils/transform-styles/index.js +20 -24
  178. package/build-module/utils/transform-styles/index.js.map +1 -1
  179. package/build-style/style-rtl.css +13 -6
  180. package/build-style/style.css +13 -6
  181. package/package.json +36 -34
  182. package/src/components/block-alignment-control/use-available-alignments.js +49 -34
  183. package/src/components/block-list/block.native.js +4 -4
  184. package/src/components/block-list/layout.js +2 -2
  185. package/src/components/block-styles/style.scss +1 -1
  186. package/src/components/border-radius-control/index.js +3 -2
  187. package/src/components/color-palette/with-color-context.js +9 -9
  188. package/src/components/colors/with-colors.js +6 -7
  189. package/src/components/colors-gradients/control.js +10 -7
  190. package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +29 -15
  191. package/src/components/font-family/index.js +2 -2
  192. package/src/components/font-sizes/font-size-picker.js +6 -4
  193. package/src/components/font-sizes/with-font-sizes.js +3 -5
  194. package/src/components/global-styles/filters-panel.js +9 -15
  195. package/src/components/global-styles/image-settings-panel.js +2 -2
  196. package/src/components/global-styles/typography-panel.js +1 -1
  197. package/src/components/gradients/use-gradient.js +10 -4
  198. package/src/components/height-control/index.js +3 -2
  199. package/src/components/index.js +1 -1
  200. package/src/components/index.native.js +1 -1
  201. package/src/components/inner-blocks/index.js +2 -2
  202. package/src/components/inserter/style.scss +9 -1
  203. package/src/components/letter-spacing-control/index.js +3 -2
  204. package/src/components/link-control/search-item.js +14 -0
  205. package/src/components/link-control/search-results.js +1 -0
  206. package/src/components/link-control/use-search-handler.js +22 -15
  207. package/src/components/resizable-box-popover/index.js +1 -1
  208. package/src/components/rich-text/index.js +1 -1
  209. package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +7 -5
  210. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -2
  211. package/src/components/unit-control/index.js +3 -8
  212. package/src/components/use-block-commands/index.js +2 -1
  213. package/src/components/{use-setting → use-settings}/README.md +9 -10
  214. package/src/components/use-settings/index.js +272 -0
  215. package/src/components/{use-setting → use-settings}/test/index.js +47 -5
  216. package/src/hooks/align.js +79 -54
  217. package/src/hooks/anchor.js +75 -65
  218. package/src/hooks/background.js +7 -9
  219. package/src/hooks/color.js +7 -4
  220. package/src/hooks/duotone.js +24 -19
  221. package/src/hooks/font-size.js +4 -4
  222. package/src/hooks/layout.js +11 -11
  223. package/src/hooks/line-height.js +3 -3
  224. package/src/hooks/position.js +5 -3
  225. package/src/hooks/use-color-props.js +21 -14
  226. package/src/hooks/utils.js +88 -43
  227. package/src/layouts/constrained.js +3 -8
  228. package/src/utils/object.js +4 -1
  229. package/src/utils/test/__snapshots__/transform-styles.js.snap +103 -0
  230. package/src/utils/test/transform-styles.js +217 -0
  231. package/src/utils/transform-styles/index.js +25 -25
  232. package/build/components/use-setting/index.js +0 -161
  233. package/build/components/use-setting/index.js.map +0 -1
  234. package/build/utils/transform-styles/ast/index.js +0 -21
  235. package/build/utils/transform-styles/ast/index.js.map +0 -1
  236. package/build/utils/transform-styles/ast/parse.js +0 -660
  237. package/build/utils/transform-styles/ast/parse.js.map +0 -1
  238. package/build/utils/transform-styles/ast/stringify/compiler.js +0 -52
  239. package/build/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
  240. package/build/utils/transform-styles/ast/stringify/compress.js +0 -178
  241. package/build/utils/transform-styles/ast/stringify/compress.js.map +0 -1
  242. package/build/utils/transform-styles/ast/stringify/identity.js +0 -207
  243. package/build/utils/transform-styles/ast/stringify/identity.js.map +0 -1
  244. package/build/utils/transform-styles/ast/stringify/index.js +0 -36
  245. package/build/utils/transform-styles/ast/stringify/index.js.map +0 -1
  246. package/build/utils/transform-styles/transforms/url-rewrite.js +0 -130
  247. package/build/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
  248. package/build/utils/transform-styles/transforms/wrap.js +0 -59
  249. package/build/utils/transform-styles/transforms/wrap.js.map +0 -1
  250. package/build/utils/transform-styles/traverse.js +0 -37
  251. package/build/utils/transform-styles/traverse.js.map +0 -1
  252. package/build-module/components/use-setting/index.js +0 -154
  253. package/build-module/components/use-setting/index.js.map +0 -1
  254. package/build-module/utils/transform-styles/ast/index.js +0 -6
  255. package/build-module/utils/transform-styles/ast/index.js.map +0 -1
  256. package/build-module/utils/transform-styles/ast/parse.js +0 -654
  257. package/build-module/utils/transform-styles/ast/parse.js.map +0 -1
  258. package/build-module/utils/transform-styles/ast/stringify/compiler.js +0 -49
  259. package/build-module/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
  260. package/build-module/utils/transform-styles/ast/stringify/compress.js +0 -176
  261. package/build-module/utils/transform-styles/ast/stringify/compress.js.map +0 -1
  262. package/build-module/utils/transform-styles/ast/stringify/identity.js +0 -206
  263. package/build-module/utils/transform-styles/ast/stringify/identity.js.map +0 -1
  264. package/build-module/utils/transform-styles/ast/stringify/index.js +0 -29
  265. package/build-module/utils/transform-styles/ast/stringify/index.js.map +0 -1
  266. package/build-module/utils/transform-styles/transforms/url-rewrite.js +0 -123
  267. package/build-module/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
  268. package/build-module/utils/transform-styles/transforms/wrap.js +0 -52
  269. package/build-module/utils/transform-styles/transforms/wrap.js.map +0 -1
  270. package/build-module/utils/transform-styles/traverse.js +0 -28
  271. package/build-module/utils/transform-styles/traverse.js.map +0 -1
  272. package/src/components/use-setting/index.js +0 -218
  273. package/src/utils/transform-styles/ast/index.js +0 -5
  274. package/src/utils/transform-styles/ast/parse.js +0 -732
  275. package/src/utils/transform-styles/ast/stringify/compiler.js +0 -50
  276. package/src/utils/transform-styles/ast/stringify/compress.js +0 -238
  277. package/src/utils/transform-styles/ast/stringify/identity.js +0 -286
  278. package/src/utils/transform-styles/ast/stringify/index.js +0 -32
  279. package/src/utils/transform-styles/test/__snapshots__/traverse.js.snap +0 -7
  280. package/src/utils/transform-styles/test/traverse.js +0 -24
  281. package/src/utils/transform-styles/transforms/test/__snapshots__/url-rewrite.js.snap +0 -25
  282. package/src/utils/transform-styles/transforms/test/__snapshots__/wrap.js.snap +0 -64
  283. package/src/utils/transform-styles/transforms/test/url-rewrite.js +0 -39
  284. package/src/utils/transform-styles/transforms/test/wrap.js +0 -95
  285. package/src/utils/transform-styles/transforms/url-rewrite.js +0 -139
  286. package/src/utils/transform-styles/transforms/wrap.js +0 -56
  287. package/src/utils/transform-styles/traverse.js +0 -32
@@ -29,7 +29,7 @@ import { getFilename } from '@wordpress/url';
29
29
  */
30
30
  import InspectorControls from '../components/inspector-controls';
31
31
  import MediaReplaceFlow from '../components/media-replace-flow';
32
- import useSetting from '../components/use-setting';
32
+ import { useSettings } from '../components/use-settings';
33
33
  import { cleanEmptyObject } from './utils';
34
34
  import { store as blockEditorStore } from '../store';
35
35
 
@@ -281,19 +281,17 @@ function BackgroundImagePanelItem( props ) {
281
281
  }
282
282
 
283
283
  export function BackgroundImagePanel( props ) {
284
- const isBackgroundImageSupported =
285
- useSetting( 'background.backgroundImage' ) &&
286
- hasBackgroundSupport( props.name, 'backgroundImage' );
287
-
288
- if ( ! isBackgroundImageSupported ) {
284
+ const [ backgroundImage ] = useSettings( 'background.backgroundImage' );
285
+ if (
286
+ ! backgroundImage ||
287
+ ! hasBackgroundSupport( props.name, 'backgroundImage' )
288
+ ) {
289
289
  return null;
290
290
  }
291
291
 
292
292
  return (
293
293
  <InspectorControls group="background">
294
- { isBackgroundImageSupported && (
295
- <BackgroundImagePanelItem { ...props } />
296
- ) }
294
+ <BackgroundImagePanelItem { ...props } />
297
295
  </InspectorControls>
298
296
  );
299
297
  }
@@ -25,7 +25,7 @@ import {
25
25
  shouldSkipSerialization,
26
26
  useBlockSettings,
27
27
  } from './utils';
28
- import useSetting from '../components/use-setting';
28
+ import { useSettings } from '../components/use-settings';
29
29
  import InspectorControls from '../components/inspector-controls';
30
30
  import {
31
31
  useHasColorPanel,
@@ -368,9 +368,12 @@ export const withColorPaletteStyles = createHigherOrderComponent(
368
368
  ( BlockListBlock ) => ( props ) => {
369
369
  const { name, attributes } = props;
370
370
  const { backgroundColor, textColor } = attributes;
371
- const userPalette = useSetting( 'color.palette.custom' );
372
- const themePalette = useSetting( 'color.palette.theme' );
373
- const defaultPalette = useSetting( 'color.palette.default' );
371
+ const [ userPalette, themePalette, defaultPalette ] = useSettings(
372
+ 'color.palette.custom',
373
+ 'color.palette.theme',
374
+ 'color.palette.default'
375
+ );
376
+
374
377
  const colors = useMemo(
375
378
  () => [
376
379
  ...( userPalette || [] ),
@@ -25,7 +25,7 @@ import {
25
25
  BlockControls,
26
26
  InspectorControls,
27
27
  __experimentalDuotoneControl as DuotoneControl,
28
- useSetting,
28
+ useSettings,
29
29
  } from '../components';
30
30
  import {
31
31
  getDuotoneFilter,
@@ -56,20 +56,20 @@ const isSafari =
56
56
  extend( [ namesPlugin ] );
57
57
 
58
58
  function useMultiOriginPresets( { presetSetting, defaultSetting } ) {
59
- const disableDefault = ! useSetting( defaultSetting );
60
- const userPresets =
61
- useSetting( `${ presetSetting }.custom` ) || EMPTY_ARRAY;
62
- const themePresets =
63
- useSetting( `${ presetSetting }.theme` ) || EMPTY_ARRAY;
64
- const defaultPresets =
65
- useSetting( `${ presetSetting }.default` ) || EMPTY_ARRAY;
59
+ const [ enableDefault, userPresets, themePresets, defaultPresets ] =
60
+ useSettings(
61
+ defaultSetting,
62
+ `${ presetSetting }.custom`,
63
+ `${ presetSetting }.theme`,
64
+ `${ presetSetting }.default`
65
+ );
66
66
  return useMemo(
67
67
  () => [
68
- ...userPresets,
69
- ...themePresets,
70
- ...( disableDefault ? EMPTY_ARRAY : defaultPresets ),
68
+ ...( userPresets || EMPTY_ARRAY ),
69
+ ...( themePresets || EMPTY_ARRAY ),
70
+ ...( ( enableDefault && defaultPresets ) || EMPTY_ARRAY ),
71
71
  ],
72
- [ disableDefault, userPresets, themePresets, defaultPresets ]
72
+ [ enableDefault, userPresets, themePresets, defaultPresets ]
73
73
  );
74
74
  }
75
75
 
@@ -102,6 +102,7 @@ function DuotonePanel( { attributes, setAttributes, name } ) {
102
102
  const style = attributes?.style;
103
103
  const duotoneStyle = style?.color?.duotone;
104
104
  const settings = useBlockSettings( name );
105
+ const blockEditingMode = useBlockEditingMode();
105
106
 
106
107
  const duotonePalette = useMultiOriginPresets( {
107
108
  presetSetting: 'color.duotone',
@@ -111,15 +112,23 @@ function DuotonePanel( { attributes, setAttributes, name } ) {
111
112
  presetSetting: 'color.palette',
112
113
  defaultSetting: 'color.defaultPalette',
113
114
  } );
114
- const disableCustomColors = ! useSetting( 'color.custom' );
115
+ const [ enableCustomColors, enableCustomDuotone ] = useSettings(
116
+ 'color.custom',
117
+ 'color.customDuotone'
118
+ );
119
+ const disableCustomColors = ! enableCustomColors;
115
120
  const disableCustomDuotone =
116
- ! useSetting( 'color.customDuotone' ) ||
121
+ ! enableCustomDuotone ||
117
122
  ( colorPalette?.length === 0 && disableCustomColors );
118
123
 
119
124
  if ( duotonePalette?.length === 0 && disableCustomDuotone ) {
120
125
  return null;
121
126
  }
122
127
 
128
+ if ( blockEditingMode !== 'default' ) {
129
+ return null;
130
+ }
131
+
123
132
  const duotonePresetOrColors = ! Array.isArray( duotoneStyle )
124
133
  ? getColorsFromDuotonePreset( duotoneStyle, duotonePalette )
125
134
  : duotoneStyle;
@@ -215,17 +224,13 @@ const withDuotoneControls = createHigherOrderComponent(
215
224
  'filter.duotone'
216
225
  );
217
226
 
218
- const blockEditingMode = useBlockEditingMode();
219
-
220
227
  // CAUTION: code added before this line will be executed
221
228
  // for all blocks, not just those that support duotone. Code added
222
229
  // above this line should be carefully evaluated for its impact on
223
230
  // performance.
224
231
  return (
225
232
  <>
226
- { hasDuotoneSupport && blockEditingMode === 'default' && (
227
- <DuotonePanel { ...props } />
228
- ) }
233
+ { hasDuotoneSupport && <DuotonePanel { ...props } /> }
229
234
  <BlockEdit { ...props } />
230
235
  </>
231
236
  );
@@ -22,7 +22,7 @@ import {
22
22
  transformStyles,
23
23
  shouldSkipSerialization,
24
24
  } from './utils';
25
- import useSetting from '../components/use-setting';
25
+ import { useSettings } from '../components/use-settings';
26
26
  import { store as blockEditorStore } from '../store';
27
27
  import {
28
28
  getTypographyFontSizeValue,
@@ -122,7 +122,7 @@ export function FontSizeEdit( props ) {
122
122
  attributes: { fontSize, style },
123
123
  setAttributes,
124
124
  } = props;
125
- const fontSizes = useSetting( 'typography.fontSizes' );
125
+ const [ fontSizes ] = useSettings( 'typography.fontSizes' );
126
126
 
127
127
  const onChange = ( value ) => {
128
128
  const fontSizeSlug = getFontSizeObjectByValue( fontSizes, value ).slug;
@@ -167,7 +167,7 @@ export function FontSizeEdit( props ) {
167
167
  * @return {boolean} Whether setting is disabled.
168
168
  */
169
169
  export function useIsFontSizeDisabled( { name: blockName } = {} ) {
170
- const fontSizes = useSetting( 'typography.fontSizes' );
170
+ const [ fontSizes ] = useSettings( 'typography.fontSizes' );
171
171
  const hasFontSizes = !! fontSizes?.length;
172
172
 
173
173
  return (
@@ -186,7 +186,7 @@ export function useIsFontSizeDisabled( { name: blockName } = {} ) {
186
186
  */
187
187
  const withFontSizeInlineStyles = createHigherOrderComponent(
188
188
  ( BlockListBlock ) => ( props ) => {
189
- const fontSizes = useSetting( 'typography.fontSizes' );
189
+ const [ fontSizes ] = useSettings( 'typography.fontSizes' );
190
190
  const {
191
191
  name: blockName,
192
192
  attributes: { fontSize, style },
@@ -24,7 +24,7 @@ import { useEffect } from '@wordpress/element';
24
24
  */
25
25
  import { store as blockEditorStore } from '../store';
26
26
  import { InspectorControls } from '../components';
27
- import useSetting from '../components/use-setting';
27
+ import { useSettings } from '../components/use-settings';
28
28
  import { getLayoutType, getLayoutTypes } from '../layouts';
29
29
  import { useBlockEditingMode } from '../components/block-editing-mode';
30
30
  import { LAYOUT_DEFINITIONS } from '../layouts/definitions';
@@ -123,7 +123,7 @@ export function useLayoutStyles( blockAttributes = {}, blockName, selector ) {
123
123
  ? { ...layout, type: 'constrained' }
124
124
  : layout || {};
125
125
  const fullLayoutType = getLayoutType( usedLayout?.type || 'default' );
126
- const blockGapSupport = useSetting( 'spacing.blockGap' );
126
+ const [ blockGapSupport ] = useSettings( 'spacing.blockGap' );
127
127
  const hasBlockGapSupport = blockGapSupport !== null;
128
128
  const css = fullLayoutType?.getLayoutStyle?.( {
129
129
  blockName,
@@ -142,7 +142,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
142
142
  } = settings;
143
143
 
144
144
  const { layout } = attributes;
145
- const defaultThemeLayout = useSetting( 'layout' );
145
+ const [ defaultThemeLayout ] = useSettings( 'layout' );
146
146
  const { themeSupportsLayout } = useSelect( ( select ) => {
147
147
  const { getSettings } = select( blockEditorStore );
148
148
  return {
@@ -151,6 +151,10 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
151
151
  }, [] );
152
152
  const blockEditingMode = useBlockEditingMode();
153
153
 
154
+ if ( blockEditingMode !== 'default' ) {
155
+ return null;
156
+ }
157
+
154
158
  const layoutBlockSupport = getBlockSupport(
155
159
  blockName,
156
160
  layoutBlockSupportKey,
@@ -270,7 +274,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
270
274
  ) }
271
275
  </PanelBody>
272
276
  </InspectorControls>
273
- { ! inherit && blockEditingMode === 'default' && layoutType && (
277
+ { ! inherit && layoutType && (
274
278
  <layoutType.toolBarControls
275
279
  layout={ usedLayout }
276
280
  onChange={ onChangeLayout }
@@ -331,14 +335,10 @@ export function addAttribute( settings ) {
331
335
  */
332
336
  export const withInspectorControls = createHigherOrderComponent(
333
337
  ( BlockEdit ) => ( props ) => {
334
- const { name: blockName } = props;
335
- const supportLayout = hasLayoutBlockSupport( blockName );
338
+ const supportLayout = hasLayoutBlockSupport( props.name );
336
339
 
337
- const blockEditingMode = useBlockEditingMode();
338
340
  return [
339
- supportLayout && blockEditingMode === 'default' && (
340
- <LayoutPanel key="layout" { ...props } />
341
- ),
341
+ supportLayout && <LayoutPanel key="layout" { ...props } />,
342
342
  <BlockEdit key="edit" { ...props } />,
343
343
  ];
344
344
  },
@@ -375,7 +375,7 @@ export const withLayoutStyles = createHigherOrderComponent(
375
375
  : null;
376
376
  // Higher specificity to override defaults from theme.json.
377
377
  const selector = `.wp-container-${ id }.wp-container-${ id }`;
378
- const blockGapSupport = useSetting( 'spacing.blockGap' );
378
+ const [ blockGapSupport ] = useSettings( 'spacing.blockGap' );
379
379
  const hasBlockGapSupport = blockGapSupport !== null;
380
380
 
381
381
  // Get CSS string for the current layout type.
@@ -8,7 +8,7 @@ import { hasBlockSupport } from '@wordpress/blocks';
8
8
  */
9
9
  import LineHeightControl from '../components/line-height-control';
10
10
  import { cleanEmptyObject } from './utils';
11
- import useSetting from '../components/use-setting';
11
+ import { useSettings } from '../components/use-settings';
12
12
 
13
13
  export const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
14
14
 
@@ -54,9 +54,9 @@ export function LineHeightEdit( props ) {
54
54
  * @return {boolean} Whether setting is disabled.
55
55
  */
56
56
  export function useIsLineHeightDisabled( { name: blockName } = {} ) {
57
- const isDisabled = ! useSetting( 'typography.lineHeight' );
57
+ const [ isEnabled ] = useSettings( 'typography.lineHeight' );
58
58
 
59
59
  return (
60
- ! hasBlockSupport( blockName, LINE_HEIGHT_SUPPORT_KEY ) || isDisabled
60
+ ! isEnabled || ! hasBlockSupport( blockName, LINE_HEIGHT_SUPPORT_KEY )
61
61
  );
62
62
  }
@@ -26,7 +26,7 @@ import { addFilter } from '@wordpress/hooks';
26
26
  * Internal dependencies
27
27
  */
28
28
  import BlockList from '../components/block-list';
29
- import useSetting from '../components/use-setting';
29
+ import { useSettings } from '../components/use-settings';
30
30
  import InspectorControls from '../components/inspector-controls';
31
31
  import useBlockDisplayInformation from '../components/use-block-display-information';
32
32
  import { cleanEmptyObject } from './utils';
@@ -197,8 +197,10 @@ export function resetPosition( { attributes = {}, setAttributes } ) {
197
197
  * @return {boolean} Whether padding setting is disabled.
198
198
  */
199
199
  export function useIsPositionDisabled( { name: blockName } = {} ) {
200
- const allowFixed = useSetting( 'position.fixed' );
201
- const allowSticky = useSetting( 'position.sticky' );
200
+ const [ allowFixed, allowSticky ] = useSettings(
201
+ 'position.fixed',
202
+ 'position.sticky'
203
+ );
202
204
  const isDisabled = ! allowFixed && ! allowSticky;
203
205
 
204
206
  return ! hasPositionSupport( blockName ) || isDisabled;
@@ -20,7 +20,7 @@ import {
20
20
  __experimentalGetGradientClass,
21
21
  getGradientValueBySlug,
22
22
  } from '../components/gradients';
23
- import useSetting from '../components/use-setting';
23
+ import { useSettings } from '../components/use-settings';
24
24
 
25
25
  // The code in this file has largely been lifted from the color block support
26
26
  // hook.
@@ -73,8 +73,6 @@ export function getColorClassesAndStyles( attributes ) {
73
73
  };
74
74
  }
75
75
 
76
- const EMPTY_OBJECT = {};
77
-
78
76
  /**
79
77
  * Determines the color related props for a block derived from its color block
80
78
  * support attributes.
@@ -89,13 +87,22 @@ const EMPTY_OBJECT = {};
89
87
  export function useColorProps( attributes ) {
90
88
  const { backgroundColor, textColor, gradient } = attributes;
91
89
 
92
- // Some color settings have a special handling for deprecated flags in `useSetting`,
93
- // so we can't unwrap them by doing const { ... } = useSetting('color')
94
- // until https://github.com/WordPress/gutenberg/issues/37094 is fixed.
95
- const userPalette = useSetting( 'color.palette.custom' );
96
- const themePalette = useSetting( 'color.palette.theme' );
97
- const defaultPalette = useSetting( 'color.palette.default' );
98
- const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
90
+ const [
91
+ userPalette,
92
+ themePalette,
93
+ defaultPalette,
94
+ userGradients,
95
+ themeGradients,
96
+ defaultGradients,
97
+ ] = useSettings(
98
+ 'color.palette.custom',
99
+ 'color.palette.theme',
100
+ 'color.palette.default',
101
+ 'color.gradients.custom',
102
+ 'color.gradients.theme',
103
+ 'color.gradients.default'
104
+ );
105
+
99
106
  const colors = useMemo(
100
107
  () => [
101
108
  ...( userPalette || [] ),
@@ -106,11 +113,11 @@ export function useColorProps( attributes ) {
106
113
  );
107
114
  const gradients = useMemo(
108
115
  () => [
109
- ...( gradientsPerOrigin?.custom || [] ),
110
- ...( gradientsPerOrigin?.theme || [] ),
111
- ...( gradientsPerOrigin?.default || [] ),
116
+ ...( userGradients || [] ),
117
+ ...( themeGradients || [] ),
118
+ ...( defaultGradients || [] ),
112
119
  ],
113
- [ gradientsPerOrigin ]
120
+ [ userGradients, themeGradients, defaultGradients ]
114
121
  );
115
122
 
116
123
  const colorProps = getColorClassesAndStyles( attributes );
@@ -7,7 +7,7 @@ import { useMemo } from '@wordpress/element';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
- import { useSetting } from '../components';
10
+ import { useSettings } from '../components';
11
11
  import { useSettingsForBlockElement } from '../components/global-styles/hooks';
12
12
  import { getValueFromObjectPath, setImmutably } from '../utils/object';
13
13
 
@@ -126,48 +126,93 @@ export function shouldSkipSerialization( blockType, featureSet, feature ) {
126
126
  * @return {Object} Settings object.
127
127
  */
128
128
  export function useBlockSettings( name, parentLayout ) {
129
- const fontFamilies = useSetting( 'typography.fontFamilies' );
130
- const fontSizes = useSetting( 'typography.fontSizes' );
131
- const customFontSize = useSetting( 'typography.customFontSize' );
132
- const fontStyle = useSetting( 'typography.fontStyle' );
133
- const fontWeight = useSetting( 'typography.fontWeight' );
134
- const lineHeight = useSetting( 'typography.lineHeight' );
135
- const textColumns = useSetting( 'typography.textColumns' );
136
- const textDecoration = useSetting( 'typography.textDecoration' );
137
- const writingMode = useSetting( 'typography.writingMode' );
138
- const textTransform = useSetting( 'typography.textTransform' );
139
- const letterSpacing = useSetting( 'typography.letterSpacing' );
140
- const padding = useSetting( 'spacing.padding' );
141
- const margin = useSetting( 'spacing.margin' );
142
- const blockGap = useSetting( 'spacing.blockGap' );
143
- const spacingSizes = useSetting( 'spacing.spacingSizes' );
144
- const units = useSetting( 'spacing.units' );
145
- const minHeight = useSetting( 'dimensions.minHeight' );
146
- const layout = useSetting( 'layout' );
147
- const borderColor = useSetting( 'border.color' );
148
- const borderRadius = useSetting( 'border.radius' );
149
- const borderStyle = useSetting( 'border.style' );
150
- const borderWidth = useSetting( 'border.width' );
151
- const customColorsEnabled = useSetting( 'color.custom' );
152
- const customColors = useSetting( 'color.palette.custom' );
153
- const customDuotone = useSetting( 'color.customDuotone' );
154
- const themeColors = useSetting( 'color.palette.theme' );
155
- const defaultColors = useSetting( 'color.palette.default' );
156
- const defaultPalette = useSetting( 'color.defaultPalette' );
157
- const defaultDuotone = useSetting( 'color.defaultDuotone' );
158
- const userDuotonePalette = useSetting( 'color.duotone.custom' );
159
- const themeDuotonePalette = useSetting( 'color.duotone.theme' );
160
- const defaultDuotonePalette = useSetting( 'color.duotone.default' );
161
- const userGradientPalette = useSetting( 'color.gradients.custom' );
162
- const themeGradientPalette = useSetting( 'color.gradients.theme' );
163
- const defaultGradientPalette = useSetting( 'color.gradients.default' );
164
- const defaultGradients = useSetting( 'color.defaultGradients' );
165
- const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
166
- const isBackgroundEnabled = useSetting( 'color.background' );
167
- const isLinkEnabled = useSetting( 'color.link' );
168
- const isTextEnabled = useSetting( 'color.text' );
169
- const isHeadingEnabled = useSetting( 'color.heading' );
170
- const isButtonEnabled = useSetting( 'color.button' );
129
+ const [
130
+ fontFamilies,
131
+ fontSizes,
132
+ customFontSize,
133
+ fontStyle,
134
+ fontWeight,
135
+ lineHeight,
136
+ textColumns,
137
+ textDecoration,
138
+ writingMode,
139
+ textTransform,
140
+ letterSpacing,
141
+ padding,
142
+ margin,
143
+ blockGap,
144
+ spacingSizes,
145
+ units,
146
+ minHeight,
147
+ layout,
148
+ borderColor,
149
+ borderRadius,
150
+ borderStyle,
151
+ borderWidth,
152
+ customColorsEnabled,
153
+ customColors,
154
+ customDuotone,
155
+ themeColors,
156
+ defaultColors,
157
+ defaultPalette,
158
+ defaultDuotone,
159
+ userDuotonePalette,
160
+ themeDuotonePalette,
161
+ defaultDuotonePalette,
162
+ userGradientPalette,
163
+ themeGradientPalette,
164
+ defaultGradientPalette,
165
+ defaultGradients,
166
+ areCustomGradientsEnabled,
167
+ isBackgroundEnabled,
168
+ isLinkEnabled,
169
+ isTextEnabled,
170
+ isHeadingEnabled,
171
+ isButtonEnabled,
172
+ ] = useSettings(
173
+ 'typography.fontFamilies',
174
+ 'typography.fontSizes',
175
+ 'typography.customFontSize',
176
+ 'typography.fontStyle',
177
+ 'typography.fontWeight',
178
+ 'typography.lineHeight',
179
+ 'typography.textColumns',
180
+ 'typography.textDecoration',
181
+ 'typography.writingMode',
182
+ 'typography.textTransform',
183
+ 'typography.letterSpacing',
184
+ 'spacing.padding',
185
+ 'spacing.margin',
186
+ 'spacing.blockGap',
187
+ 'spacing.spacingSizes',
188
+ 'spacing.units',
189
+ 'dimensions.minHeight',
190
+ 'layout',
191
+ 'border.color',
192
+ 'border.radius',
193
+ 'border.style',
194
+ 'border.width',
195
+ 'color.custom',
196
+ 'color.palette.custom',
197
+ 'color.customDuotone',
198
+ 'color.palette.theme',
199
+ 'color.palette.default',
200
+ 'color.defaultPalette',
201
+ 'color.defaultDuotone',
202
+ 'color.duotone.custom',
203
+ 'color.duotone.theme',
204
+ 'color.duotone.default',
205
+ 'color.gradients.custom',
206
+ 'color.gradients.theme',
207
+ 'color.gradients.default',
208
+ 'color.defaultGradients',
209
+ 'color.customGradient',
210
+ 'color.background',
211
+ 'color.link',
212
+ 'color.text',
213
+ 'color.heading',
214
+ 'color.button'
215
+ );
171
216
 
172
217
  const rawSettings = useMemo( () => {
173
218
  return {
@@ -21,7 +21,7 @@ import { getCSSRules } from '@wordpress/style-engine';
21
21
  /**
22
22
  * Internal dependencies
23
23
  */
24
- import useSetting from '../components/use-setting';
24
+ import { useSettings } from '../components/use-settings';
25
25
  import { appendSelectors, getBlockGapCSS, getAlignmentsInfo } from './utils';
26
26
  import { getGapCSSValue } from '../hooks/gap';
27
27
  import { shouldSkipSerialization } from '../hooks/utils';
@@ -60,14 +60,9 @@ export default {
60
60
  label: __( 'Justify items right' ),
61
61
  },
62
62
  ];
63
+ const [ availableUnits ] = useSettings( 'spacing.units' );
63
64
  const units = useCustomUnits( {
64
- availableUnits: useSetting( 'spacing.units' ) || [
65
- '%',
66
- 'px',
67
- 'em',
68
- 'rem',
69
- 'vw',
70
- ],
65
+ availableUnits: availableUnits || [ '%', 'px', 'em', 'rem', 'vw' ],
71
66
  } );
72
67
  return (
73
68
  <>
@@ -2,6 +2,7 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { paramCase } from 'change-case';
5
+ import memoize from 'memize';
5
6
 
6
7
  /**
7
8
  * Converts a path to an array of its fragments.
@@ -112,6 +113,8 @@ export function setImmutably( object, path, value ) {
112
113
  return newObject;
113
114
  }
114
115
 
116
+ const stringToPath = memoize( ( path ) => path.split( '.' ) );
117
+
115
118
  /**
116
119
  * Helper util to return a value from a certain path of the object.
117
120
  * Path is specified as either:
@@ -125,7 +128,7 @@ export function setImmutably( object, path, value ) {
125
128
  * @return {*} Value of the object property at the specified path.
126
129
  */
127
130
  export const getValueFromObjectPath = ( object, path, defaultValue ) => {
128
- const normalizedPath = Array.isArray( path ) ? path : path.split( '.' );
131
+ const normalizedPath = Array.isArray( path ) ? path : stringToPath( path );
129
132
  let value = object;
130
133
  normalizedPath.forEach( ( fieldName ) => {
131
134
  value = value?.[ fieldName ];
@@ -0,0 +1,103 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`transformStyles URL rewrite should not replace absolute paths 1`] = `
4
+ [
5
+ "h1 { background: url(/images/test.png); }",
6
+ ]
7
+ `;
8
+
9
+ exports[`transformStyles URL rewrite should not replace remote paths 1`] = `
10
+ [
11
+ "h1 { background: url(http://wp.org/images/test.png); }",
12
+ ]
13
+ `;
14
+
15
+ exports[`transformStyles URL rewrite should replace complex relative paths 1`] = `
16
+ [
17
+ "h1 { background: url(http://wp-site.local/themes/gut/images/test.png); }",
18
+ ]
19
+ `;
20
+
21
+ exports[`transformStyles URL rewrite should rewrite relative paths 1`] = `
22
+ [
23
+ "h1 { background: url(http://wp-site.local/themes/gut/css/images/test.png); }",
24
+ ]
25
+ `;
26
+
27
+ exports[`transformStyles selector wrap should ignore font-face selectors 1`] = `
28
+ [
29
+ "
30
+ @font-face {
31
+ font-family: myFirstFont;
32
+ src: url(sansation_light.woff);
33
+ }",
34
+ ]
35
+ `;
36
+
37
+ exports[`transformStyles selector wrap should ignore keyframes 1`] = `
38
+ [
39
+ "
40
+ @keyframes edit-post__fade-in-animation {
41
+ from {
42
+ opacity: 0;
43
+ }
44
+ }",
45
+ ]
46
+ `;
47
+
48
+ exports[`transformStyles selector wrap should ignore selectors 1`] = `
49
+ [
50
+ ".my-namespace h1, body { color: red; }",
51
+ ]
52
+ `;
53
+
54
+ exports[`transformStyles selector wrap should not double wrap selectors 1`] = `
55
+ [
56
+ " .my-namespace h1, .my-namespace .red { color: red; }",
57
+ ]
58
+ `;
59
+
60
+ exports[`transformStyles selector wrap should replace :root selectors 1`] = `
61
+ [
62
+ "
63
+ .my-namespace {
64
+ --my-color: #ff0000;
65
+ }",
66
+ ]
67
+ `;
68
+
69
+ exports[`transformStyles selector wrap should replace root tags 1`] = `
70
+ [
71
+ ".my-namespace, .my-namespace h1 { color: red; }",
72
+ ]
73
+ `;
74
+
75
+ exports[`transformStyles selector wrap should wrap multiple selectors 1`] = `
76
+ [
77
+ ".my-namespace h1, .my-namespace h2 { color: red; }",
78
+ ]
79
+ `;
80
+
81
+ exports[`transformStyles selector wrap should wrap regular selectors 1`] = `
82
+ [
83
+ ".my-namespace h1 { color: red; }",
84
+ ]
85
+ `;
86
+
87
+ exports[`transformStyles selector wrap should wrap selectors inside container queries 1`] = `
88
+ [
89
+ "
90
+ @container (width > 400px) {
91
+ .my-namespace h1 { color: red; }
92
+ }",
93
+ ]
94
+ `;
95
+
96
+ exports[`transformStyles should not break with data urls 1`] = `
97
+ [
98
+ ".wp-block-group {
99
+ background-image: url("data:image/svg+xml,%3Csvg%3E.b%7Bclip-path:url(test);%7D%3C/svg%3E");
100
+ color: red !important;
101
+ }",
102
+ ]
103
+ `;