@wordpress/block-editor 8.1.0 → 8.1.2

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 (145) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +7 -5
  3. package/build/components/block-inspector/index.js +7 -0
  4. package/build/components/block-inspector/index.js.map +1 -1
  5. package/build/components/block-preview/auto.js +3 -1
  6. package/build/components/block-preview/auto.js.map +1 -1
  7. package/build/components/colors-gradients/tools-panel-color-dropdown.js +89 -0
  8. package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +1 -0
  9. package/build/components/contrast-checker/index.js +75 -64
  10. package/build/components/contrast-checker/index.js.map +1 -1
  11. package/build/components/index.js +9 -9
  12. package/build/components/index.js.map +1 -1
  13. package/build/components/index.native.js +9 -0
  14. package/build/components/index.native.js.map +1 -1
  15. package/build/components/inserter/search-items.js +3 -1
  16. package/build/components/inserter/search-items.js.map +1 -1
  17. package/build/components/inspector-controls/block-support-tools-panel.js +3 -1
  18. package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  19. package/build/components/inspector-controls/groups.js +2 -0
  20. package/build/components/inspector-controls/groups.js.map +1 -1
  21. package/build/components/line-height-control/index.native.js +3 -2
  22. package/build/components/line-height-control/index.native.js.map +1 -1
  23. package/build/components/link-control/link-preview.js +5 -2
  24. package/build/components/link-control/link-preview.js.map +1 -1
  25. package/build/components/list-view/block-contents.js +3 -1
  26. package/build/components/list-view/block-contents.js.map +1 -1
  27. package/build/components/list-view/block-select-button.js +4 -2
  28. package/build/components/list-view/block-select-button.js.map +1 -1
  29. package/build/components/list-view/block.js +2 -1
  30. package/build/components/list-view/block.js.map +1 -1
  31. package/build/components/media-placeholder/index.js +1 -11
  32. package/build/components/media-placeholder/index.js.map +1 -1
  33. package/build/components/media-replace-flow/index.native.js +13 -0
  34. package/build/components/media-replace-flow/index.native.js.map +1 -0
  35. package/build/components/rich-text/index.js +2 -1
  36. package/build/components/rich-text/index.js.map +1 -1
  37. package/build/components/rich-text/index.native.js +2 -1
  38. package/build/components/rich-text/index.native.js.map +1 -1
  39. package/build/components/rich-text/use-paste-handler.js +14 -5
  40. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  41. package/build/components/rich-text/utils.js +2 -1
  42. package/build/components/rich-text/utils.js.map +1 -1
  43. package/build/hooks/border-color.js +1 -1
  44. package/build/hooks/border-color.js.map +1 -1
  45. package/build/hooks/color-panel.js +23 -17
  46. package/build/hooks/color-panel.js.map +1 -1
  47. package/build/hooks/color.js +176 -10
  48. package/build/hooks/color.js.map +1 -1
  49. package/build/hooks/font-size.js +14 -0
  50. package/build/hooks/font-size.js.map +1 -1
  51. package/build/hooks/typography.native.js +2 -4
  52. package/build/hooks/typography.native.js.map +1 -1
  53. package/build/hooks/utils.js +55 -0
  54. package/build/hooks/utils.js.map +1 -1
  55. package/build-module/components/block-inspector/index.js +7 -0
  56. package/build-module/components/block-inspector/index.js.map +1 -1
  57. package/build-module/components/block-preview/auto.js +3 -1
  58. package/build-module/components/block-preview/auto.js.map +1 -1
  59. package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +75 -0
  60. package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +1 -0
  61. package/build-module/components/contrast-checker/index.js +75 -65
  62. package/build-module/components/contrast-checker/index.js.map +1 -1
  63. package/build-module/components/index.js +1 -1
  64. package/build-module/components/index.js.map +1 -1
  65. package/build-module/components/index.native.js +1 -0
  66. package/build-module/components/index.native.js.map +1 -1
  67. package/build-module/components/inserter/search-items.js +3 -1
  68. package/build-module/components/inserter/search-items.js.map +1 -1
  69. package/build-module/components/inspector-controls/block-support-tools-panel.js +3 -1
  70. package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  71. package/build-module/components/inspector-controls/groups.js +2 -0
  72. package/build-module/components/inspector-controls/groups.js.map +1 -1
  73. package/build-module/components/line-height-control/index.native.js +3 -2
  74. package/build-module/components/line-height-control/index.native.js.map +1 -1
  75. package/build-module/components/link-control/link-preview.js +5 -2
  76. package/build-module/components/link-control/link-preview.js.map +1 -1
  77. package/build-module/components/list-view/block-contents.js +3 -1
  78. package/build-module/components/list-view/block-contents.js.map +1 -1
  79. package/build-module/components/list-view/block-select-button.js +4 -2
  80. package/build-module/components/list-view/block-select-button.js.map +1 -1
  81. package/build-module/components/list-view/block.js +2 -1
  82. package/build-module/components/list-view/block.js.map +1 -1
  83. package/build-module/components/media-placeholder/index.js +1 -10
  84. package/build-module/components/media-placeholder/index.js.map +1 -1
  85. package/build-module/components/media-replace-flow/index.native.js +4 -0
  86. package/build-module/components/media-replace-flow/index.native.js.map +1 -0
  87. package/build-module/components/rich-text/index.js +2 -1
  88. package/build-module/components/rich-text/index.js.map +1 -1
  89. package/build-module/components/rich-text/index.native.js +2 -1
  90. package/build-module/components/rich-text/index.native.js.map +1 -1
  91. package/build-module/components/rich-text/use-paste-handler.js +14 -5
  92. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  93. package/build-module/components/rich-text/utils.js +2 -1
  94. package/build-module/components/rich-text/utils.js.map +1 -1
  95. package/build-module/hooks/border-color.js +1 -1
  96. package/build-module/hooks/border-color.js.map +1 -1
  97. package/build-module/hooks/color-panel.js +22 -15
  98. package/build-module/hooks/color-panel.js.map +1 -1
  99. package/build-module/hooks/color.js +174 -11
  100. package/build-module/hooks/color.js.map +1 -1
  101. package/build-module/hooks/font-size.js +12 -1
  102. package/build-module/hooks/font-size.js.map +1 -1
  103. package/build-module/hooks/typography.native.js +2 -4
  104. package/build-module/hooks/typography.native.js.map +1 -1
  105. package/build-module/hooks/utils.js +52 -1
  106. package/build-module/hooks/utils.js.map +1 -1
  107. package/build-style/style-rtl.css +71 -9
  108. package/build-style/style.css +71 -9
  109. package/package.json +26 -30
  110. package/src/components/block-inspector/index.js +9 -0
  111. package/src/components/block-preview/auto.js +3 -0
  112. package/src/components/color-palette/test/__snapshots__/control.js.snap +0 -1
  113. package/src/components/colors-gradients/tools-panel-color-dropdown.js +85 -0
  114. package/src/components/contrast-checker/index.js +102 -87
  115. package/src/components/contrast-checker/test/index.js +176 -7
  116. package/src/components/index.js +1 -1
  117. package/src/components/index.native.js +1 -0
  118. package/src/components/inserter/search-items.js +3 -1
  119. package/src/components/inspector-controls/block-support-tools-panel.js +2 -0
  120. package/src/components/inspector-controls/groups.js +2 -0
  121. package/src/components/line-height-control/index.native.js +2 -1
  122. package/src/components/link-control/link-preview.js +2 -1
  123. package/src/components/link-control/style.scss +3 -9
  124. package/src/components/list-view/block-contents.js +2 -0
  125. package/src/components/list-view/block-select-button.js +2 -0
  126. package/src/components/list-view/block.js +1 -0
  127. package/src/components/media-placeholder/index.js +1 -10
  128. package/src/components/media-replace-flow/index.native.js +3 -0
  129. package/src/components/rich-text/index.js +1 -0
  130. package/src/components/rich-text/index.native.js +1 -0
  131. package/src/components/rich-text/use-paste-handler.js +16 -3
  132. package/src/components/rich-text/utils.js +1 -0
  133. package/src/hooks/border-color.js +1 -1
  134. package/src/hooks/color-panel.js +24 -21
  135. package/src/hooks/color.js +177 -8
  136. package/src/hooks/color.scss +85 -0
  137. package/src/hooks/font-size.js +29 -1
  138. package/src/hooks/typography.native.js +1 -3
  139. package/src/hooks/utils.js +69 -1
  140. package/src/style.scss +1 -0
  141. package/build/components/preserve-scroll-in-reorder/index.js +0 -22
  142. package/build/components/preserve-scroll-in-reorder/index.js.map +0 -1
  143. package/build-module/components/preserve-scroll-in-reorder/index.js +0 -12
  144. package/build-module/components/preserve-scroll-in-reorder/index.js.map +0 -1
  145. package/src/components/preserve-scroll-in-reorder/index.js +0 -12
@@ -2,7 +2,7 @@
2
2
  * External dependencies
3
3
  */
4
4
  import classnames from 'classnames';
5
- import { isObject, setWith, clone } from 'lodash';
5
+ import { isObject } from 'lodash';
6
6
 
7
7
  /**
8
8
  * WordPress dependencies
@@ -26,7 +26,7 @@ import {
26
26
  getGradientValueBySlug,
27
27
  getGradientSlugByValue,
28
28
  } from '../components/gradients';
29
- import { cleanEmptyObject } from './utils';
29
+ import { cleanEmptyObject, transformStyles, immutableSet } from './utils';
30
30
  import ColorPanel from './color-panel';
31
31
  import useSetting from '../components/use-setting';
32
32
 
@@ -77,6 +77,125 @@ const hasTextColorSupport = ( blockType ) => {
77
77
  return colorSupport && colorSupport.text !== false;
78
78
  };
79
79
 
80
+ /**
81
+ * Checks whether a color has been set either with a named preset color in
82
+ * a top level block attribute or as a custom value within the style attribute
83
+ * object.
84
+ *
85
+ * @param {string} name Name of the color to check.
86
+ * @return {boolean} Whether or not a color has a value.
87
+ */
88
+ const hasColor = ( name ) => ( props ) => {
89
+ if ( name === 'background' ) {
90
+ return (
91
+ !! props.attributes.backgroundColor ||
92
+ !! props.attributes.style?.color?.background ||
93
+ !! props.attributes.gradient ||
94
+ !! props.attributes.style?.color?.gradient
95
+ );
96
+ }
97
+
98
+ if ( name === 'link' ) {
99
+ return !! props.attributes.style?.elements?.link?.color?.text;
100
+ }
101
+
102
+ return (
103
+ !! props.attributes[ `${ name }Color` ] ||
104
+ !! props.attributes.style?.color?.[ name ]
105
+ );
106
+ };
107
+
108
+ /**
109
+ * Clears a single color property from a style object.
110
+ *
111
+ * @param {Array} path Path to color property to clear within styles object.
112
+ * @param {Object} style Block attributes style object.
113
+ * @return {Object} Styles with the color property omitted.
114
+ */
115
+ const clearColorFromStyles = ( path, style ) =>
116
+ cleanEmptyObject( immutableSet( style, path, undefined ) );
117
+
118
+ /**
119
+ * Resets the block attributes for text color.
120
+ *
121
+ * @param {Object} props Current block props.
122
+ * @param {Object} props.attributes Block attributes.
123
+ * @param {Function} props.setAttributes Block's setAttributes prop used to apply reset.
124
+ */
125
+ const resetTextColor = ( { attributes, setAttributes } ) => {
126
+ setAttributes( {
127
+ textColor: undefined,
128
+ style: clearColorFromStyles( [ 'color', 'text' ], attributes.style ),
129
+ } );
130
+ };
131
+
132
+ /**
133
+ * Clears text color related properties from supplied attributes.
134
+ *
135
+ * @param {Object} attributes Block attributes.
136
+ * @return {Object} Update block attributes with text color properties omitted.
137
+ */
138
+ const resetAllTextFilter = ( attributes ) => ( {
139
+ textColor: undefined,
140
+ style: clearColorFromStyles( [ 'color', 'text' ], attributes.style ),
141
+ } );
142
+
143
+ /**
144
+ * Resets the block attributes for link color.
145
+ *
146
+ * @param {Object} props Current block props.
147
+ * @param {Object} props.attributes Block attributes.
148
+ * @param {Function} props.setAttributes Block's setAttributes prop used to apply reset.
149
+ */
150
+ const resetLinkColor = ( { attributes, setAttributes } ) => {
151
+ const path = [ 'elements', 'link', 'color', 'text' ];
152
+ setAttributes( { style: clearColorFromStyles( path, attributes.style ) } );
153
+ };
154
+
155
+ /**
156
+ * Clears link color related properties from supplied attributes.
157
+ *
158
+ * @param {Object} attributes Block attributes.
159
+ * @return {Object} Update block attributes with link color properties omitted.
160
+ */
161
+ const resetAllLinkFilter = ( attributes ) => ( {
162
+ style: clearColorFromStyles(
163
+ [ 'elements', 'link', 'color', 'text' ],
164
+ attributes.style
165
+ ),
166
+ } );
167
+
168
+ /**
169
+ * Clears all background color related properties including gradients from
170
+ * supplied block attributes.
171
+ *
172
+ * @param {Object} attributes Block attributes.
173
+ * @return {Object} Block attributes with background and gradient omitted.
174
+ */
175
+ const clearBackgroundAndGradient = ( attributes ) => ( {
176
+ backgroundColor: undefined,
177
+ gradient: undefined,
178
+ style: {
179
+ ...attributes.style,
180
+ color: {
181
+ ...attributes.style?.color,
182
+ background: undefined,
183
+ gradient: undefined,
184
+ },
185
+ },
186
+ } );
187
+
188
+ /**
189
+ * Resets the block attributes for both background color and gradient.
190
+ *
191
+ * @param {Object} props Current block props.
192
+ * @param {Object} props.attributes Block attributes.
193
+ * @param {Function} props.setAttributes Block's setAttributes prop used to apply reset.
194
+ */
195
+ const resetBackgroundAndGradient = ( { attributes, setAttributes } ) => {
196
+ setAttributes( clearBackgroundAndGradient( attributes ) );
197
+ };
198
+
80
199
  /**
81
200
  * Filters registered block settings, extending attributes to include
82
201
  * `backgroundColor` and `textColor` attribute.
@@ -136,7 +255,7 @@ export function addSaveProps( props, blockType, attributes ) {
136
255
 
137
256
  const hasGradient = hasGradientSupport( blockType );
138
257
 
139
- // I'd have prefered to avoid the "style" attribute usage here
258
+ // I'd have preferred to avoid the "style" attribute usage here
140
259
  const { backgroundColor, textColor, gradient, style } = attributes;
141
260
 
142
261
  const backgroundClass = getColorClassName(
@@ -168,7 +287,7 @@ export function addSaveProps( props, blockType, attributes ) {
168
287
  }
169
288
 
170
289
  /**
171
- * Filters registered block settings to extand the block edit wrapper
290
+ * Filters registered block settings to extend the block edit wrapper
172
291
  * to apply the desired styles and classnames properly.
173
292
  *
174
293
  * @param {Object} settings Original block settings.
@@ -203,10 +322,6 @@ const getLinkColorFromAttributeValue = ( colors, value ) => {
203
322
  return value;
204
323
  };
205
324
 
206
- function immutableSet( object, path, value ) {
207
- return setWith( object ? clone( object ) : {}, path, value, clone );
208
- }
209
-
210
325
  /**
211
326
  * Inspector control panel containing the color related configuration
212
327
  *
@@ -374,6 +489,11 @@ export function ColorEdit( props ) {
374
489
  const enableContrastChecking =
375
490
  Platform.OS === 'web' && ! gradient && ! style?.color?.gradient;
376
491
 
492
+ const defaultColorControls = getBlockSupport( props.name, [
493
+ COLOR_SUPPORT_KEY,
494
+ '__experimentalDefaultControls',
495
+ ] );
496
+
377
497
  return (
378
498
  <ColorPanel
379
499
  enableContrastChecking={ enableContrastChecking }
@@ -390,6 +510,10 @@ export function ColorEdit( props ) {
390
510
  textColor,
391
511
  style?.color?.text
392
512
  ).color,
513
+ isShownByDefault: defaultColorControls?.text,
514
+ hasValue: () => hasColor( 'text' )( props ),
515
+ onDeselect: () => resetTextColor( props ),
516
+ resetAllFilter: resetAllTextFilter,
393
517
  },
394
518
  ]
395
519
  : [] ),
@@ -409,6 +533,13 @@ export function ColorEdit( props ) {
409
533
  onGradientChange: hasGradientColor
410
534
  ? onChangeGradient
411
535
  : undefined,
536
+ isShownByDefault:
537
+ defaultColorControls?.background,
538
+ hasValue: () =>
539
+ hasColor( 'background' )( props ),
540
+ onDeselect: () =>
541
+ resetBackgroundAndGradient( props ),
542
+ resetAllFilter: clearBackgroundAndGradient,
412
543
  },
413
544
  ]
414
545
  : [] ),
@@ -423,6 +554,10 @@ export function ColorEdit( props ) {
423
554
  ),
424
555
  clearable: !! style?.elements?.link?.color
425
556
  ?.text,
557
+ isShownByDefault: defaultColorControls?.link,
558
+ hasValue: () => hasColor( 'link' )( props ),
559
+ onDeselect: () => resetLinkColor( props ),
560
+ resetAllFilter: resetAllLinkFilter,
426
561
  },
427
562
  ]
428
563
  : [] ),
@@ -485,6 +620,34 @@ export const withColorPaletteStyles = createHigherOrderComponent(
485
620
  }
486
621
  );
487
622
 
623
+ const MIGRATION_PATHS = {
624
+ linkColor: [ [ 'style', 'elements', 'link', 'color', 'text' ] ],
625
+ textColor: [ [ 'textColor' ], [ 'style', 'color', 'text' ] ],
626
+ backgroundColor: [
627
+ [ 'backgroundColor' ],
628
+ [ 'style', 'color', 'background' ],
629
+ ],
630
+ gradient: [ [ 'gradient' ], [ 'style', 'color', 'gradient' ] ],
631
+ };
632
+
633
+ export function addTransforms( result, source, index, results ) {
634
+ const destinationBlockType = result.name;
635
+ const activeSupports = {
636
+ linkColor: hasLinkColorSupport( destinationBlockType ),
637
+ textColor: hasTextColorSupport( destinationBlockType ),
638
+ backgroundColor: hasBackgroundColorSupport( destinationBlockType ),
639
+ gradient: hasGradientSupport( destinationBlockType ),
640
+ };
641
+ return transformStyles(
642
+ activeSupports,
643
+ MIGRATION_PATHS,
644
+ result,
645
+ source,
646
+ index,
647
+ results
648
+ );
649
+ }
650
+
488
651
  addFilter(
489
652
  'blocks.registerBlockType',
490
653
  'core/color/addAttribute',
@@ -508,3 +671,9 @@ addFilter(
508
671
  'core/color/with-color-palette-styles',
509
672
  withColorPaletteStyles
510
673
  );
674
+
675
+ addFilter(
676
+ 'blocks.switchToBlockType.transformedBlock',
677
+ 'core/color/addTransforms',
678
+ addTransforms
679
+ );
@@ -0,0 +1,85 @@
1
+ .color-block-support-panel {
2
+ .block-editor-contrast-checker {
3
+ /**
4
+ * Contrast checkers are forced to the bottom of the panel so all
5
+ * injected color controls can appear as a single item group without
6
+ * the contrast checkers suddenly appearing between items.
7
+ */
8
+ order: 9999;
9
+ grid-column: span 2;
10
+ margin-top: $grid-unit-20;
11
+
12
+ .components-notice__content {
13
+ margin-right: 0;
14
+ }
15
+ }
16
+
17
+ /* Increased specificity required to remove the slot wrapper's row gap */
18
+ &#{&} {
19
+ .color-block-support-panel__inner-wrapper {
20
+ row-gap: 0;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * The following styles replicate the separated border of the
26
+ * `ItemGroup` component but allows for hidden items. This is because
27
+ * to maintain the order of `ToolsPanel` controls, each `ToolsPanelItem`
28
+ * must at least render a placeholder which would otherwise interfere
29
+ * with the `:last-child` styles.
30
+ */
31
+ .block-editor-tools-panel-color-gradient-settings__item {
32
+ padding: 0;
33
+
34
+ // Border styles.
35
+ border-left: 1px solid rgba(0, 0, 0, 0.1);
36
+ border-right: 1px solid rgba(0, 0, 0, 0.1);
37
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
38
+
39
+ &.first {
40
+ border-top-left-radius: 2px;
41
+ border-top-right-radius: 2px;
42
+ border-top: 1px solid rgba(0, 0, 0, 0.1);
43
+ }
44
+
45
+ &.last {
46
+ border-bottom-left-radius: 2px;
47
+ border-bottom-right-radius: 2px;
48
+ }
49
+
50
+ > div,
51
+ > div > button {
52
+ border-radius: inherit;
53
+ }
54
+ }
55
+
56
+ .block-editor-panel-color-gradient-settings__color-indicator {
57
+ // Show a diagonal line (crossed out) for empty swatches.
58
+ background: linear-gradient(-45deg, transparent 48%, $gray-300 48%, $gray-300 52%, transparent 52%);
59
+ }
60
+
61
+ /**
62
+ * The following few styles fix the layout and spacing for the due to the
63
+ * introduced wrapper element by the `Item` component.
64
+ */
65
+ .block-editor-tools-panel-color-dropdown {
66
+ display: block;
67
+ padding: 0;
68
+
69
+ > button {
70
+ height: 46px;
71
+
72
+ &.is-open {
73
+ background: $gray-100;
74
+ color: var(--wp-admin-theme-color);
75
+ }
76
+ }
77
+ }
78
+
79
+ .color-block-support-panel__item-group {
80
+ > div {
81
+ grid-column: span 2;
82
+ border-radius: inherit;
83
+ }
84
+ }
85
+ }
@@ -15,7 +15,7 @@ import {
15
15
  getFontSizeObjectByValue,
16
16
  FontSizePicker,
17
17
  } from '../components/font-sizes';
18
- import { cleanEmptyObject } from './utils';
18
+ import { cleanEmptyObject, transformStyles } from './utils';
19
19
  import useSetting from '../components/use-setting';
20
20
 
21
21
  export const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';
@@ -255,6 +255,28 @@ const withFontSizeInlineStyles = createHigherOrderComponent(
255
255
  'withFontSizeInlineStyles'
256
256
  );
257
257
 
258
+ const MIGRATION_PATHS = {
259
+ fontSize: [ [ 'fontSize' ], [ 'style', 'typography', 'fontSize' ] ],
260
+ };
261
+
262
+ export function addTransforms( result, source, index, results ) {
263
+ const destinationBlockType = result.name;
264
+ const activeSupports = {
265
+ fontSize: hasBlockSupport(
266
+ destinationBlockType,
267
+ FONT_SIZE_SUPPORT_KEY
268
+ ),
269
+ };
270
+ return transformStyles(
271
+ activeSupports,
272
+ MIGRATION_PATHS,
273
+ result,
274
+ source,
275
+ index,
276
+ results
277
+ );
278
+ }
279
+
258
280
  addFilter(
259
281
  'blocks.registerBlockType',
260
282
  'core/font/addAttribute',
@@ -274,3 +296,9 @@ addFilter(
274
296
  'core/font-size/with-font-size-inline-styles',
275
297
  withFontSizeInlineStyles
276
298
  );
299
+
300
+ addFilter(
301
+ 'blocks.switchToBlockType.transformedBlock',
302
+ 'core/font-size/addTransforms',
303
+ addTransforms
304
+ );
@@ -34,9 +34,7 @@ export function TypographyPanel( props ) {
34
34
  const isDisabled = useIsTypographyDisabled( props );
35
35
  const isSupported = hasTypographySupport( props.name );
36
36
 
37
- // only enable TypographyPanel for development
38
- // eslint-disable-next-line no-undef
39
- if ( isDisabled || ! isSupported || ! __DEV__ ) return null;
37
+ if ( isDisabled || ! isSupported ) return null;
40
38
 
41
39
  return (
42
40
  <InspectorControls>
@@ -1,7 +1,18 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { pickBy, isEmpty, isObject, identity, mapValues } from 'lodash';
4
+ import {
5
+ pickBy,
6
+ isEmpty,
7
+ isObject,
8
+ identity,
9
+ mapValues,
10
+ forEach,
11
+ get,
12
+ setWith,
13
+ clone,
14
+ every,
15
+ } from 'lodash';
5
16
 
6
17
  /**
7
18
  * Removed falsy values from nested object.
@@ -19,3 +30,60 @@ export const cleanEmptyObject = ( object ) => {
19
30
  );
20
31
  return isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;
21
32
  };
33
+
34
+ export function immutableSet( object, path, value ) {
35
+ return setWith( object ? clone( object ) : {}, path, value, clone );
36
+ }
37
+
38
+ export function transformStyles(
39
+ activeSupports,
40
+ migrationPaths,
41
+ result,
42
+ source,
43
+ index,
44
+ results
45
+ ) {
46
+ // If there are no active supports return early.
47
+ if ( every( activeSupports, ( isActive ) => ! isActive ) ) {
48
+ return result;
49
+ }
50
+ // If the condition verifies we are probably in the presence of a wrapping transform
51
+ // e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.
52
+ if ( results.length === 1 && result.innerBlocks.length === source.length ) {
53
+ return result;
54
+ }
55
+ // For cases where we have a transform from one block to multiple blocks
56
+ // or multiple blocks to one block we apply the styles of the first source block
57
+ // to the result(s).
58
+ let referenceBlockAttributes = source[ 0 ]?.attributes;
59
+ // If we are in presence of transform between more than one block in the source
60
+ // that has more than one block in the result
61
+ // we apply the styles on source N to the result N,
62
+ // if source N does not exists we do nothing.
63
+ if ( results.length > 1 && source.length > 1 ) {
64
+ if ( source[ index ] ) {
65
+ referenceBlockAttributes = source[ index ]?.attributes;
66
+ } else {
67
+ return result;
68
+ }
69
+ }
70
+ let returnBlock = result;
71
+ forEach( activeSupports, ( isActive, support ) => {
72
+ if ( isActive ) {
73
+ migrationPaths[ support ].forEach( ( path ) => {
74
+ const styleValue = get( referenceBlockAttributes, path );
75
+ if ( styleValue ) {
76
+ returnBlock = {
77
+ ...returnBlock,
78
+ attributes: immutableSet(
79
+ returnBlock.attributes,
80
+ path,
81
+ styleValue
82
+ ),
83
+ };
84
+ }
85
+ } );
86
+ }
87
+ } );
88
+ return returnBlock;
89
+ }
package/src/style.scss CHANGED
@@ -57,6 +57,7 @@
57
57
  @import "./hooks/border.scss";
58
58
  @import "./hooks/dimensions.scss";
59
59
  @import "./hooks/typography.scss";
60
+ @import "./hooks/color.scss";
60
61
 
61
62
  @import "./components/block-toolbar/style.scss";
62
63
  @import "./components/inserter/style.scss";
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = PreserveScrollInReorder;
9
-
10
- var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
11
-
12
- /**
13
- * WordPress dependencies
14
- */
15
- function PreserveScrollInReorder() {
16
- (0, _deprecated.default)('PreserveScrollInReorder component', {
17
- since: '5.4',
18
- hint: 'This behavior is now built-in the block list'
19
- });
20
- return null;
21
- }
22
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/preserve-scroll-in-reorder/index.js"],"names":["PreserveScrollInReorder","since","hint"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,uBAAT,GAAmC;AACjD,2BAAY,mCAAZ,EAAiD;AAChDC,IAAAA,KAAK,EAAE,KADyC;AAEhDC,IAAAA,IAAI,EAAE;AAF0C,GAAjD;AAIA,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\nexport default function PreserveScrollInReorder() {\n\tdeprecated( 'PreserveScrollInReorder component', {\n\t\tsince: '5.4',\n\t\thint: 'This behavior is now built-in the block list',\n\t} );\n\treturn null;\n}\n"]}
@@ -1,12 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import deprecated from '@wordpress/deprecated';
5
- export default function PreserveScrollInReorder() {
6
- deprecated('PreserveScrollInReorder component', {
7
- since: '5.4',
8
- hint: 'This behavior is now built-in the block list'
9
- });
10
- return null;
11
- }
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/preserve-scroll-in-reorder/index.js"],"names":["deprecated","PreserveScrollInReorder","since","hint"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA,eAAe,SAASC,uBAAT,GAAmC;AACjDD,EAAAA,UAAU,CAAE,mCAAF,EAAuC;AAChDE,IAAAA,KAAK,EAAE,KADyC;AAEhDC,IAAAA,IAAI,EAAE;AAF0C,GAAvC,CAAV;AAIA,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\nexport default function PreserveScrollInReorder() {\n\tdeprecated( 'PreserveScrollInReorder component', {\n\t\tsince: '5.4',\n\t\thint: 'This behavior is now built-in the block list',\n\t} );\n\treturn null;\n}\n"]}
@@ -1,12 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import deprecated from '@wordpress/deprecated';
5
-
6
- export default function PreserveScrollInReorder() {
7
- deprecated( 'PreserveScrollInReorder component', {
8
- since: '5.4',
9
- hint: 'This behavior is now built-in the block list',
10
- } );
11
- return null;
12
- }