@wordpress/block-editor 11.6.0 → 11.7.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 (193) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +4 -0
  3. package/build/components/block-list/block-html.js +1 -3
  4. package/build/components/block-list/block-html.js.map +1 -1
  5. package/build/components/block-preview/auto.js +6 -23
  6. package/build/components/block-preview/auto.js.map +1 -1
  7. package/build/components/editor-styles/index.js +20 -2
  8. package/build/components/editor-styles/index.js.map +1 -1
  9. package/build/components/global-styles/color-panel.js +583 -0
  10. package/build/components/global-styles/color-panel.js.map +1 -0
  11. package/build/components/global-styles/dimensions-panel.js +8 -30
  12. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  13. package/build/components/global-styles/get-block-css-selector.js +129 -0
  14. package/build/components/global-styles/get-block-css-selector.js.map +1 -0
  15. package/build/components/global-styles/hooks.js +53 -1
  16. package/build/components/global-styles/hooks.js.map +1 -1
  17. package/build/components/global-styles/index.js +18 -2
  18. package/build/components/global-styles/index.js.map +1 -1
  19. package/build/components/global-styles/typography-panel.js +9 -35
  20. package/build/components/global-styles/typography-panel.js.map +1 -1
  21. package/build/components/global-styles/use-global-styles-output.js +160 -86
  22. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  23. package/build/components/global-styles/utils.js +2 -1
  24. package/build/components/global-styles/utils.js.map +1 -1
  25. package/build/components/image-size-control/index.js +8 -5
  26. package/build/components/image-size-control/index.js.map +1 -1
  27. package/build/components/inspector-controls-tabs/position-controls-panel.js +43 -7
  28. package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  29. package/build/components/line-height-control/index.js +15 -1
  30. package/build/components/line-height-control/index.js.map +1 -1
  31. package/build/components/list-view/appender.js +105 -0
  32. package/build/components/list-view/appender.js.map +1 -0
  33. package/build/components/list-view/block.js +5 -5
  34. package/build/components/list-view/block.js.map +1 -1
  35. package/build/components/list-view/branch.js +25 -5
  36. package/build/components/list-view/branch.js.map +1 -1
  37. package/build/components/list-view/index.js +37 -13
  38. package/build/components/list-view/index.js.map +1 -1
  39. package/build/components/media-replace-flow/index.js +13 -4
  40. package/build/components/media-replace-flow/index.js.map +1 -1
  41. package/build/components/rich-text/format-edit.js +2 -30
  42. package/build/components/rich-text/format-edit.js.map +1 -1
  43. package/build/components/writing-flow/use-input.js +4 -8
  44. package/build/components/writing-flow/use-input.js.map +1 -1
  45. package/build/hooks/border.js +0 -1
  46. package/build/hooks/border.js.map +1 -1
  47. package/build/hooks/color.js +92 -229
  48. package/build/hooks/color.js.map +1 -1
  49. package/build/hooks/content-lock-ui.js +4 -2
  50. package/build/hooks/content-lock-ui.js.map +1 -1
  51. package/build/hooks/{color-panel.js → contrast-checker.js} +11 -49
  52. package/build/hooks/contrast-checker.js.map +1 -0
  53. package/build/hooks/dimensions.js +0 -1
  54. package/build/hooks/dimensions.js.map +1 -1
  55. package/build/hooks/duotone.js +3 -1
  56. package/build/hooks/duotone.js.map +1 -1
  57. package/build/hooks/position.js +2 -2
  58. package/build/hooks/position.js.map +1 -1
  59. package/build/hooks/style.js +23 -26
  60. package/build/hooks/style.js.map +1 -1
  61. package/build/hooks/typography.js +0 -1
  62. package/build/hooks/typography.js.map +1 -1
  63. package/build/hooks/utils.js +25 -76
  64. package/build/hooks/utils.js.map +1 -1
  65. package/build/layouts/grid.js +165 -0
  66. package/build/layouts/grid.js.map +1 -0
  67. package/build/layouts/index.js +3 -1
  68. package/build/layouts/index.js.map +1 -1
  69. package/build/private-apis.js +4 -1
  70. package/build/private-apis.js.map +1 -1
  71. package/build/utils/object.js +76 -0
  72. package/build/utils/object.js.map +1 -0
  73. package/build-module/components/block-list/block-html.js +1 -3
  74. package/build-module/components/block-list/block-html.js.map +1 -1
  75. package/build-module/components/block-preview/auto.js +6 -22
  76. package/build-module/components/block-preview/auto.js.map +1 -1
  77. package/build-module/components/editor-styles/index.js +19 -2
  78. package/build-module/components/editor-styles/index.js.map +1 -1
  79. package/build-module/components/global-styles/color-panel.js +554 -0
  80. package/build-module/components/global-styles/color-panel.js.map +1 -0
  81. package/build-module/components/global-styles/dimensions-panel.js +7 -30
  82. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  83. package/build-module/components/global-styles/get-block-css-selector.js +120 -0
  84. package/build-module/components/global-styles/get-block-css-selector.js.map +1 -0
  85. package/build-module/components/global-styles/hooks.js +51 -1
  86. package/build-module/components/global-styles/hooks.js.map +1 -1
  87. package/build-module/components/global-styles/index.js +3 -1
  88. package/build-module/components/global-styles/index.js.map +1 -1
  89. package/build-module/components/global-styles/typography-panel.js +8 -35
  90. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  91. package/build-module/components/global-styles/use-global-styles-output.js +161 -87
  92. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  93. package/build-module/components/global-styles/utils.js +2 -1
  94. package/build-module/components/global-styles/utils.js.map +1 -1
  95. package/build-module/components/image-size-control/index.js +8 -5
  96. package/build-module/components/image-size-control/index.js.map +1 -1
  97. package/build-module/components/inspector-controls-tabs/position-controls-panel.js +42 -7
  98. package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  99. package/build-module/components/line-height-control/index.js +15 -1
  100. package/build-module/components/line-height-control/index.js.map +1 -1
  101. package/build-module/components/list-view/appender.js +88 -0
  102. package/build-module/components/list-view/appender.js.map +1 -0
  103. package/build-module/components/list-view/block.js +5 -4
  104. package/build-module/components/list-view/block.js.map +1 -1
  105. package/build-module/components/list-view/branch.js +22 -5
  106. package/build-module/components/list-view/branch.js.map +1 -1
  107. package/build-module/components/list-view/index.js +32 -12
  108. package/build-module/components/list-view/index.js.map +1 -1
  109. package/build-module/components/media-replace-flow/index.js +12 -4
  110. package/build-module/components/media-replace-flow/index.js.map +1 -1
  111. package/build-module/components/rich-text/format-edit.js +3 -31
  112. package/build-module/components/rich-text/format-edit.js.map +1 -1
  113. package/build-module/components/writing-flow/use-input.js +4 -8
  114. package/build-module/components/writing-flow/use-input.js.map +1 -1
  115. package/build-module/hooks/border.js +0 -1
  116. package/build-module/hooks/border.js.map +1 -1
  117. package/build-module/hooks/color.js +90 -232
  118. package/build-module/hooks/color.js.map +1 -1
  119. package/build-module/hooks/content-lock-ui.js +4 -2
  120. package/build-module/hooks/content-lock-ui.js.map +1 -1
  121. package/build-module/hooks/{color-panel.js → contrast-checker.js} +10 -44
  122. package/build-module/hooks/contrast-checker.js.map +1 -0
  123. package/build-module/hooks/dimensions.js +0 -1
  124. package/build-module/hooks/dimensions.js.map +1 -1
  125. package/build-module/hooks/duotone.js +4 -2
  126. package/build-module/hooks/duotone.js.map +1 -1
  127. package/build-module/hooks/position.js +3 -3
  128. package/build-module/hooks/position.js.map +1 -1
  129. package/build-module/hooks/style.js +23 -26
  130. package/build-module/hooks/style.js.map +1 -1
  131. package/build-module/hooks/typography.js +0 -1
  132. package/build-module/hooks/typography.js.map +1 -1
  133. package/build-module/hooks/utils.js +23 -73
  134. package/build-module/hooks/utils.js.map +1 -1
  135. package/build-module/layouts/grid.js +151 -0
  136. package/build-module/layouts/grid.js.map +1 -0
  137. package/build-module/layouts/index.js +2 -1
  138. package/build-module/layouts/index.js.map +1 -1
  139. package/build-module/private-apis.js +3 -1
  140. package/build-module/private-apis.js.map +1 -1
  141. package/build-module/utils/object.js +69 -0
  142. package/build-module/utils/object.js.map +1 -0
  143. package/build-style/style-rtl.css +26 -6
  144. package/build-style/style.css +26 -6
  145. package/package.json +31 -31
  146. package/src/components/block-draggable/content.scss +1 -1
  147. package/src/components/block-list/block-html.js +1 -1
  148. package/src/components/block-preview/auto.js +2 -17
  149. package/src/components/colors-gradients/style.scss +8 -8
  150. package/src/components/editor-styles/index.js +29 -1
  151. package/src/components/global-styles/color-panel.js +706 -0
  152. package/src/components/global-styles/dimensions-panel.js +13 -42
  153. package/src/components/global-styles/get-block-css-selector.js +129 -0
  154. package/src/components/global-styles/hooks.js +80 -0
  155. package/src/components/global-styles/index.js +2 -1
  156. package/src/components/global-styles/test/use-global-styles-output.js +30 -1
  157. package/src/components/global-styles/typography-panel.js +26 -51
  158. package/src/components/global-styles/use-global-styles-output.js +163 -80
  159. package/src/components/global-styles/utils.js +3 -0
  160. package/src/components/image-size-control/index.js +4 -3
  161. package/src/components/image-size-control/test/index.js +2 -2
  162. package/src/components/inner-blocks/README.md +1 -1
  163. package/src/components/inspector-controls-tabs/position-controls-panel.js +40 -9
  164. package/src/components/line-height-control/index.js +10 -1
  165. package/src/components/list-view/appender.js +101 -0
  166. package/src/components/list-view/block.js +5 -4
  167. package/src/components/list-view/branch.js +30 -1
  168. package/src/components/list-view/index.js +43 -10
  169. package/src/components/list-view/style.scss +19 -0
  170. package/src/components/media-replace-flow/index.js +36 -24
  171. package/src/components/media-replace-flow/style.scss +5 -2
  172. package/src/components/rich-text/format-edit.js +2 -32
  173. package/src/components/writing-flow/use-input.js +4 -5
  174. package/src/hooks/border.js +0 -1
  175. package/src/hooks/color.js +120 -296
  176. package/src/hooks/content-lock-ui.js +6 -2
  177. package/src/hooks/{color-panel.js → contrast-checker.js} +10 -46
  178. package/src/hooks/dimensions.js +0 -1
  179. package/src/hooks/duotone.js +8 -5
  180. package/src/hooks/position.js +3 -3
  181. package/src/hooks/style.js +29 -28
  182. package/src/hooks/test/utils.js +0 -104
  183. package/src/hooks/typography.js +0 -1
  184. package/src/hooks/utils.js +27 -70
  185. package/src/layouts/grid.js +172 -0
  186. package/src/layouts/index.js +2 -1
  187. package/src/layouts/test/grid.js +21 -0
  188. package/src/private-apis.js +2 -0
  189. package/src/utils/object.js +69 -0
  190. package/src/utils/test/object.js +107 -0
  191. package/tsconfig.tsbuildinfo +1 -1
  192. package/build/hooks/color-panel.js.map +0 -1
  193. package/build-module/hooks/color-panel.js.map +0 -1
@@ -8,8 +8,7 @@ import classnames from 'classnames';
8
8
  */
9
9
  import { addFilter } from '@wordpress/hooks';
10
10
  import { getBlockSupport } from '@wordpress/blocks';
11
- import { __ } from '@wordpress/i18n';
12
- import { useRef, useEffect, useMemo, Platform } from '@wordpress/element';
11
+ import { useMemo, Platform, useCallback } from '@wordpress/element';
13
12
  import { createHigherOrderComponent } from '@wordpress/compose';
14
13
 
15
14
  /**
@@ -17,22 +16,22 @@ import { createHigherOrderComponent } from '@wordpress/compose';
17
16
  */
18
17
  import {
19
18
  getColorClassName,
20
- getColorObjectByColorValue,
21
19
  getColorObjectByAttributeValues,
22
20
  } from '../components/colors';
23
- import {
24
- __experimentalGetGradientClass,
25
- getGradientValueBySlug,
26
- getGradientSlugByValue,
27
- } from '../components/gradients';
21
+ import { __experimentalGetGradientClass } from '../components/gradients';
28
22
  import {
29
23
  cleanEmptyObject,
30
24
  transformStyles,
31
- immutableSet,
32
25
  shouldSkipSerialization,
26
+ useBlockSettings,
33
27
  } from './utils';
34
- import ColorPanel from './color-panel';
35
28
  import useSetting from '../components/use-setting';
29
+ import InspectorControls from '../components/inspector-controls';
30
+ import {
31
+ useHasColorPanel,
32
+ default as StylesColorPanel,
33
+ } from '../components/global-styles/color-panel';
34
+ import BlockColorContrastChecker from './contrast-checker';
36
35
 
37
36
  export const COLOR_SUPPORT_KEY = 'color';
38
37
 
@@ -83,60 +82,6 @@ const hasTextColorSupport = ( blockType ) => {
83
82
  return colorSupport && colorSupport.text !== false;
84
83
  };
85
84
 
86
- /**
87
- * Clears a single color property from a style object.
88
- *
89
- * @param {Array} path Path to color property to clear within styles object.
90
- * @param {Object} style Block attributes style object.
91
- * @return {Object} Styles with the color property omitted.
92
- */
93
- const clearColorFromStyles = ( path, style ) =>
94
- cleanEmptyObject( immutableSet( style, path, undefined ) );
95
-
96
- /**
97
- * Clears text color related properties from supplied attributes.
98
- *
99
- * @param {Object} attributes Block attributes.
100
- * @return {Object} Update block attributes with text color properties omitted.
101
- */
102
- const resetAllTextFilter = ( attributes ) => ( {
103
- textColor: undefined,
104
- style: clearColorFromStyles( [ 'color', 'text' ], attributes.style ),
105
- } );
106
-
107
- /**
108
- * Clears link color related properties from supplied attributes.
109
- *
110
- * @param {Object} attributes Block attributes.
111
- * @return {Object} Update block attributes with link color properties omitted.
112
- */
113
- const resetAllLinkFilter = ( attributes ) => ( {
114
- style: clearColorFromStyles(
115
- [ 'elements', 'link', 'color', 'text' ],
116
- attributes.style
117
- ),
118
- } );
119
-
120
- /**
121
- * Clears all background color related properties including gradients from
122
- * supplied block attributes.
123
- *
124
- * @param {Object} attributes Block attributes.
125
- * @return {Object} Block attributes with background and gradient omitted.
126
- */
127
- const clearBackgroundAndGradient = ( attributes ) => ( {
128
- backgroundColor: undefined,
129
- gradient: undefined,
130
- style: {
131
- ...attributes.style,
132
- color: {
133
- ...attributes.style?.color,
134
- background: undefined,
135
- gradient: undefined,
136
- },
137
- },
138
- } );
139
-
140
85
  /**
141
86
  * Filters registered block settings, extending attributes to include
142
87
  * `backgroundColor` and `textColor` attribute.
@@ -273,194 +218,112 @@ export function addEditProps( settings ) {
273
218
  return settings;
274
219
  }
275
220
 
276
- const getLinkColorFromAttributeValue = ( colors, value ) => {
277
- const attributeParsed = /var:preset\|color\|(.+)/.exec( value );
278
- if ( attributeParsed && attributeParsed[ 1 ] ) {
279
- return getColorObjectByAttributeValues( colors, attributeParsed[ 1 ] )
280
- .color;
281
- }
282
- return value;
283
- };
284
-
285
- /**
286
- * Inspector control panel containing the color related configuration
287
- *
288
- * @param {Object} props
289
- *
290
- * @return {WPElement} Color edit element.
291
- */
292
- export function ColorEdit( props ) {
293
- const { name: blockName, attributes } = props;
294
- // Some color settings have a special handling for deprecated flags in `useSetting`,
295
- // so we can't unwrap them by doing const { ... } = useSetting('color')
296
- // until https://github.com/WordPress/gutenberg/issues/37094 is fixed.
297
- const userPalette = useSetting( 'color.palette.custom' );
298
- const themePalette = useSetting( 'color.palette.theme' );
299
- const defaultPalette = useSetting( 'color.palette.default' );
300
- const allSolids = useMemo(
301
- () => [
302
- ...( userPalette || [] ),
303
- ...( themePalette || [] ),
304
- ...( defaultPalette || [] ),
305
- ],
306
- [ userPalette, themePalette, defaultPalette ]
307
- );
308
- const userGradientPalette = useSetting( 'color.gradients.custom' );
309
- const themeGradientPalette = useSetting( 'color.gradients.theme' );
310
- const defaultGradientPalette = useSetting( 'color.gradients.default' );
311
- const allGradients = useMemo(
312
- () => [
313
- ...( userGradientPalette || [] ),
314
- ...( themeGradientPalette || [] ),
315
- ...( defaultGradientPalette || [] ),
316
- ],
317
- [ userGradientPalette, themeGradientPalette, defaultGradientPalette ]
318
- );
319
- const areCustomSolidsEnabled = useSetting( 'color.custom' );
320
- const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
321
- const isBackgroundEnabled = useSetting( 'color.background' );
322
- const isLinkEnabled = useSetting( 'color.link' );
323
- const isTextEnabled = useSetting( 'color.text' );
324
-
325
- const solidsEnabled =
326
- areCustomSolidsEnabled || ! themePalette || themePalette?.length > 0;
327
-
328
- const gradientsEnabled =
329
- areCustomGradientsEnabled ||
330
- ! themeGradientPalette ||
331
- themeGradientPalette?.length > 0;
332
-
333
- // Shouldn't be needed but right now the ColorGradientsPanel
334
- // can trigger both onChangeColor and onChangeBackground
335
- // synchronously causing our two callbacks to override changes
336
- // from each other.
337
- const localAttributes = useRef( attributes );
338
- useEffect( () => {
339
- localAttributes.current = attributes;
340
- }, [ attributes ] );
341
-
342
- if ( ! hasColorSupport( blockName ) ) {
343
- return null;
344
- }
345
-
346
- const hasLinkColor =
347
- hasLinkColorSupport( blockName ) && isLinkEnabled && solidsEnabled;
348
- const hasTextColor =
349
- hasTextColorSupport( blockName ) && isTextEnabled && solidsEnabled;
350
- const hasBackgroundColor =
351
- hasBackgroundColorSupport( blockName ) &&
352
- isBackgroundEnabled &&
353
- solidsEnabled;
354
- const hasGradientColor =
355
- hasGradientSupport( blockName ) && gradientsEnabled;
356
-
357
- if (
358
- ! hasLinkColor &&
359
- ! hasTextColor &&
360
- ! hasBackgroundColor &&
361
- ! hasGradientColor
362
- ) {
363
- return null;
364
- }
221
+ function styleToAttributes( style ) {
222
+ const textColorValue = style?.color?.text;
223
+ const textColorSlug = textColorValue?.startsWith( 'var:preset|color|' )
224
+ ? textColorValue.substring( 'var:preset|color|'.length )
225
+ : undefined;
226
+ const backgroundColorValue = style?.color?.background;
227
+ const backgroundColorSlug = backgroundColorValue?.startsWith(
228
+ 'var:preset|color|'
229
+ )
230
+ ? backgroundColorValue.substring( 'var:preset|color|'.length )
231
+ : undefined;
232
+ const gradientValue = style?.color?.gradient;
233
+ const gradientSlug = gradientValue?.startsWith( 'var:preset|gradient|' )
234
+ ? gradientValue.substring( 'var:preset|gradient|'.length )
235
+ : undefined;
236
+ const updatedStyle = { ...style };
237
+ updatedStyle.color = {
238
+ ...updatedStyle.color,
239
+ text: textColorSlug ? undefined : textColorValue,
240
+ background: backgroundColorSlug ? undefined : backgroundColorValue,
241
+ gradient: gradientSlug ? undefined : gradientValue,
242
+ };
243
+ return {
244
+ style: cleanEmptyObject( updatedStyle ),
245
+ textColor: textColorSlug,
246
+ backgroundColor: backgroundColorSlug,
247
+ gradient: gradientSlug,
248
+ };
249
+ }
365
250
 
366
- const { style, textColor, backgroundColor, gradient } = attributes;
367
- let gradientValue;
368
- if ( hasGradientColor && gradient ) {
369
- gradientValue = getGradientValueBySlug( allGradients, gradient );
370
- } else if ( hasGradientColor ) {
371
- gradientValue = style?.color?.gradient;
372
- }
251
+ function attributesToStyle( attributes ) {
252
+ return {
253
+ ...attributes.style,
254
+ color: {
255
+ ...attributes.style?.color,
256
+ text: attributes.textColor
257
+ ? 'var:preset|color|' + attributes.textColor
258
+ : attributes.style?.color?.text,
259
+ background: attributes.backgroundColor
260
+ ? 'var:preset|color|' + attributes.backgroundColor
261
+ : attributes.style?.color?.background,
262
+ gradient: attributes.gradient
263
+ ? 'var:preset|gradient|' + attributes.gradient
264
+ : attributes.style?.color?.gradient,
265
+ },
266
+ };
267
+ }
373
268
 
374
- const onChangeColor = ( name ) => ( value ) => {
375
- const colorObject = getColorObjectByColorValue( allSolids, value );
376
- const attributeName = name + 'Color';
377
- const newStyle = {
378
- ...localAttributes.current.style,
379
- color: {
380
- ...localAttributes.current?.style?.color,
381
- [ name ]: colorObject?.slug ? undefined : value,
382
- },
383
- };
269
+ function ColorInspectorControl( { children, resetAllFilter } ) {
270
+ const attributesResetAllFilter = useCallback(
271
+ ( attributes ) => {
272
+ const existingStyle = attributesToStyle( attributes );
273
+ const updatedStyle = resetAllFilter( existingStyle );
274
+ return {
275
+ ...attributes,
276
+ ...styleToAttributes( updatedStyle ),
277
+ };
278
+ },
279
+ [ resetAllFilter ]
280
+ );
384
281
 
385
- const newNamedColor = colorObject?.slug ? colorObject.slug : undefined;
386
- const newAttributes = {
387
- style: cleanEmptyObject( newStyle ),
388
- [ attributeName ]: newNamedColor,
389
- };
282
+ return (
283
+ <InspectorControls
284
+ group="color"
285
+ resetAllFilter={ attributesResetAllFilter }
286
+ >
287
+ { children }
288
+ </InspectorControls>
289
+ );
290
+ }
390
291
 
391
- props.setAttributes( newAttributes );
392
- localAttributes.current = {
393
- ...localAttributes.current,
394
- ...newAttributes,
395
- };
396
- };
292
+ export function ColorEdit( props ) {
293
+ const { clientId, name, attributes, setAttributes } = props;
294
+ const settings = useBlockSettings( name );
295
+ const isEnabled = useHasColorPanel( settings );
296
+ const value = useMemo( () => {
297
+ return attributesToStyle( {
298
+ style: attributes.style,
299
+ textColor: attributes.textColor,
300
+ backgroundColor: attributes.backgroundColor,
301
+ gradient: attributes.gradient,
302
+ } );
303
+ }, [
304
+ attributes.style,
305
+ attributes.textColor,
306
+ attributes.backgroundColor,
307
+ attributes.gradient,
308
+ ] );
397
309
 
398
- const onChangeGradient = ( value ) => {
399
- const slug = getGradientSlugByValue( allGradients, value );
400
- let newAttributes;
401
- if ( slug ) {
402
- const newStyle = {
403
- ...localAttributes.current?.style,
404
- color: {
405
- ...localAttributes.current?.style?.color,
406
- gradient: undefined,
407
- },
408
- };
409
- newAttributes = {
410
- style: cleanEmptyObject( newStyle ),
411
- gradient: slug,
412
- };
413
- } else {
414
- const newStyle = {
415
- ...localAttributes.current?.style,
416
- color: {
417
- ...localAttributes.current?.style?.color,
418
- gradient: value,
419
- },
420
- };
421
- newAttributes = {
422
- style: cleanEmptyObject( newStyle ),
423
- gradient: undefined,
424
- };
425
- }
426
- props.setAttributes( newAttributes );
427
- localAttributes.current = {
428
- ...localAttributes.current,
429
- ...newAttributes,
430
- };
310
+ const onChange = ( newStyle ) => {
311
+ setAttributes( styleToAttributes( newStyle ) );
431
312
  };
432
313
 
433
- const onChangeLinkColor = ( value ) => {
434
- const colorObject = getColorObjectByColorValue( allSolids, value );
435
- const newLinkColorValue = colorObject?.slug
436
- ? `var:preset|color|${ colorObject.slug }`
437
- : value;
438
-
439
- const newStyle = cleanEmptyObject(
440
- immutableSet(
441
- localAttributes.current?.style,
442
- [ 'elements', 'link', 'color', 'text' ],
443
- newLinkColorValue
444
- )
445
- );
446
- props.setAttributes( { style: newStyle } );
447
- localAttributes.current = {
448
- ...localAttributes.current,
449
- ...{ style: newStyle },
450
- };
451
- };
314
+ if ( ! isEnabled ) {
315
+ return null;
316
+ }
452
317
 
453
- const defaultColorControls = getBlockSupport( props.name, [
318
+ const defaultControls = getBlockSupport( props.name, [
454
319
  COLOR_SUPPORT_KEY,
455
320
  '__experimentalDefaultControls',
456
321
  ] );
457
322
 
458
323
  const enableContrastChecking =
459
324
  Platform.OS === 'web' &&
460
- ! gradient &&
461
- ! style?.color?.gradient &&
462
- hasBackgroundColor &&
463
- ( hasLinkColor || hasTextColor ) &&
325
+ ! value?.color?.gradient &&
326
+ ( settings?.color?.text || settings?.color?.link ) &&
464
327
  // Contrast checking is enabled by default.
465
328
  // Deactivating it requires `enableContrastChecker` to have
466
329
  // an explicit value of `false`.
@@ -471,64 +334,25 @@ export function ColorEdit( props ) {
471
334
  ] );
472
335
 
473
336
  return (
474
- <ColorPanel
475
- enableContrastChecking={ enableContrastChecking }
476
- clientId={ props.clientId }
477
- enableAlpha={ true }
478
- settings={ [
479
- ...( hasTextColor
480
- ? [
481
- {
482
- label: __( 'Text' ),
483
- onColorChange: onChangeColor( 'text' ),
484
- colorValue: getColorObjectByAttributeValues(
485
- allSolids,
486
- textColor,
487
- style?.color?.text
488
- ).color,
489
- isShownByDefault: defaultColorControls?.text,
490
- resetAllFilter: resetAllTextFilter,
491
- },
492
- ]
493
- : [] ),
494
- ...( hasBackgroundColor || hasGradientColor
495
- ? [
496
- {
497
- label: __( 'Background' ),
498
- onColorChange: hasBackgroundColor
499
- ? onChangeColor( 'background' )
500
- : undefined,
501
- colorValue: getColorObjectByAttributeValues(
502
- allSolids,
503
- backgroundColor,
504
- style?.color?.background
505
- ).color,
506
- gradientValue,
507
- onGradientChange: hasGradientColor
508
- ? onChangeGradient
509
- : undefined,
510
- isShownByDefault:
511
- defaultColorControls?.background,
512
- resetAllFilter: clearBackgroundAndGradient,
513
- },
514
- ]
515
- : [] ),
516
- ...( hasLinkColor
517
- ? [
518
- {
519
- label: __( 'Link' ),
520
- onColorChange: onChangeLinkColor,
521
- colorValue: getLinkColorFromAttributeValue(
522
- allSolids,
523
- style?.elements?.link?.color?.text
524
- ),
525
- isShownByDefault: defaultColorControls?.link,
526
- resetAllFilter: resetAllLinkFilter,
527
- },
528
- ]
529
- : [] ),
530
- ] }
531
- />
337
+ <StylesColorPanel
338
+ as={ ColorInspectorControl }
339
+ panelId={ clientId }
340
+ settings={ settings }
341
+ value={ value }
342
+ onChange={ onChange }
343
+ defaultControls={ defaultControls }
344
+ enableContrastChecker={
345
+ false !==
346
+ getBlockSupport( props.name, [
347
+ COLOR_SUPPORT_KEY,
348
+ 'enableContrastChecker',
349
+ ] )
350
+ }
351
+ >
352
+ { enableContrastChecking && (
353
+ <BlockColorContrastChecker clientId={ clientId } />
354
+ ) }
355
+ </StylesColorPanel>
532
356
  );
533
357
  }
534
358
 
@@ -104,9 +104,13 @@ export const withBlockControls = createHigherOrderComponent(
104
104
  return <BlockEdit { ...props } />;
105
105
  }
106
106
 
107
+ const showStopEditingAsBlocks = isEditingAsBlocks && ! isContentLocked;
108
+ const showStartEditingAsBlocks =
109
+ ! isEditingAsBlocks && isContentLocked && props.isSelected;
110
+
107
111
  return (
108
112
  <>
109
- { isEditingAsBlocks && ! isContentLocked && (
113
+ { showStopEditingAsBlocks && (
110
114
  <>
111
115
  <StopEditingAsBlocksOnOutsideSelect
112
116
  clientId={ props.clientId }
@@ -123,7 +127,7 @@ export const withBlockControls = createHigherOrderComponent(
123
127
  </BlockControls>
124
128
  </>
125
129
  ) }
126
- { ! isEditingAsBlocks && isContentLocked && props.isSelected && (
130
+ { showStartEditingAsBlocks && (
127
131
  <BlockSettingsMenuControls>
128
132
  { ( { onClose } ) => (
129
133
  <MenuItem
@@ -6,45 +6,23 @@ import { useState, useEffect } from '@wordpress/element';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';
10
9
  import ContrastChecker from '../components/contrast-checker';
11
- import InspectorControls from '../components/inspector-controls';
12
- import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
13
10
  import { __unstableUseBlockRef as useBlockRef } from '../components/block-list/use-block-props/use-block-refs';
14
11
 
15
12
  function getComputedStyle( node ) {
16
13
  return node.ownerDocument.defaultView.getComputedStyle( node );
17
14
  }
18
15
 
19
- export default function ColorPanel( {
20
- enableAlpha = false,
21
- settings,
22
- clientId,
23
- enableContrastChecking = true,
24
- } ) {
16
+ export default function BlockColorContrastChecker( { clientId } ) {
25
17
  const [ detectedBackgroundColor, setDetectedBackgroundColor ] = useState();
26
18
  const [ detectedColor, setDetectedColor ] = useState();
27
19
  const [ detectedLinkColor, setDetectedLinkColor ] = useState();
28
20
  const ref = useBlockRef( clientId );
29
- const definedColors = settings.filter( ( setting ) => setting?.colorValue );
30
21
 
22
+ // There are so many things that can change the color of a block
23
+ // So we perform this check on every render.
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
31
25
  useEffect( () => {
32
- if ( ! enableContrastChecking ) {
33
- return;
34
- }
35
- if ( ! definedColors.length ) {
36
- if ( detectedBackgroundColor ) {
37
- setDetectedBackgroundColor();
38
- }
39
- if ( detectedColor ) {
40
- setDetectedColor();
41
- }
42
- if ( detectedLinkColor ) {
43
- setDetectedColor();
44
- }
45
- return;
46
- }
47
-
48
26
  if ( ! ref.current ) {
49
27
  return;
50
28
  }
@@ -72,26 +50,12 @@ export default function ColorPanel( {
72
50
  setDetectedBackgroundColor( backgroundColor );
73
51
  } );
74
52
 
75
- const colorGradientSettings = useMultipleOriginColorsAndGradients();
76
-
77
53
  return (
78
- <InspectorControls group="color">
79
- <ColorGradientSettingsDropdown
80
- enableAlpha={ enableAlpha }
81
- panelId={ clientId }
82
- settings={ settings }
83
- __experimentalIsItemGroup={ false }
84
- __experimentalIsRenderedInSidebar
85
- { ...colorGradientSettings }
86
- />
87
- { enableContrastChecking && (
88
- <ContrastChecker
89
- backgroundColor={ detectedBackgroundColor }
90
- textColor={ detectedColor }
91
- enableAlphaChecker={ enableAlpha }
92
- linkColor={ detectedLinkColor }
93
- />
94
- ) }
95
- </InspectorControls>
54
+ <ContrastChecker
55
+ backgroundColor={ detectedBackgroundColor }
56
+ textColor={ detectedColor }
57
+ enableAlphaChecker
58
+ linkColor={ detectedLinkColor }
59
+ />
96
60
  );
97
61
  }
@@ -105,7 +105,6 @@ export function DimensionsPanel( props ) {
105
105
  <StylesDimensionsPanel
106
106
  as={ DimensionsInspectorControl }
107
107
  panelId={ clientId }
108
- name={ name }
109
108
  settings={ settings }
110
109
  value={ value }
111
110
  onChange={ onChange }
@@ -8,7 +8,11 @@ import namesPlugin from 'colord/plugins/names';
8
8
  /**
9
9
  * WordPress dependencies
10
10
  */
11
- import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
11
+ import {
12
+ getBlockSupport,
13
+ getBlockType,
14
+ hasBlockSupport,
15
+ } from '@wordpress/blocks';
12
16
  import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
13
17
  import { addFilter } from '@wordpress/hooks';
14
18
  import { useMemo, useContext, createPortal } from '@wordpress/element';
@@ -269,10 +273,9 @@ function BlockDuotoneStyles( { name, duotoneStyle, id } ) {
269
273
  colors = getColorsFromDuotonePreset( colors, duotonePalette );
270
274
  }
271
275
 
272
- const duotoneSupportSelectors = getBlockSupport(
273
- name,
274
- 'color.__experimentalDuotone'
275
- );
276
+ const duotoneSupportSelectors =
277
+ getBlockType( name ).selectors?.filter?.duotone ||
278
+ getBlockSupport( name, 'color.__experimentalDuotone' );
276
279
 
277
280
  // Extra .editor-styles-wrapper specificity is needed in the editor
278
281
  // since we're not using inline styles to apply the filter. We need to
@@ -6,7 +6,7 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { __, sprintf } from '@wordpress/i18n';
9
+ import { __, _x, sprintf } from '@wordpress/i18n';
10
10
  import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
11
11
  import {
12
12
  BaseControl,
@@ -49,7 +49,7 @@ const DEFAULT_OPTION = {
49
49
  const STICKY_OPTION = {
50
50
  key: 'sticky',
51
51
  value: 'sticky',
52
- name: __( 'Sticky' ),
52
+ name: _x( 'Sticky', 'Name for the value of the CSS position property' ),
53
53
  className: OPTION_CLASSNAME,
54
54
  __experimentalHint: __(
55
55
  'The block will stick to the top of the window instead of scrolling.'
@@ -59,7 +59,7 @@ const STICKY_OPTION = {
59
59
  const FIXED_OPTION = {
60
60
  key: 'fixed',
61
61
  value: 'fixed',
62
- name: __( 'Fixed' ),
62
+ name: _x( 'Fixed', 'Name for the value of the CSS position property' ),
63
63
  className: OPTION_CLASSNAME,
64
64
  __experimentalHint: __(
65
65
  'The block will not move when the page is scrolled.'