@wordpress/block-editor 13.0.3 → 13.0.4

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 (79) hide show
  1. package/build/components/global-styles/background-panel.js +2 -1
  2. package/build/components/global-styles/background-panel.js.map +1 -1
  3. package/build/components/global-styles/border-panel.js +2 -1
  4. package/build/components/global-styles/border-panel.js.map +1 -1
  5. package/build/components/global-styles/color-panel.js +2 -1
  6. package/build/components/global-styles/color-panel.js.map +1 -1
  7. package/build/components/global-styles/dimensions-panel.js +2 -1
  8. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  9. package/build/components/global-styles/filters-panel.js +2 -1
  10. package/build/components/global-styles/filters-panel.js.map +1 -1
  11. package/build/components/global-styles/image-settings-panel.js +2 -1
  12. package/build/components/global-styles/image-settings-panel.js.map +1 -1
  13. package/build/components/global-styles/typography-panel.js +2 -1
  14. package/build/components/global-styles/typography-panel.js.map +1 -1
  15. package/build/components/global-styles/utils.js +17 -7
  16. package/build/components/global-styles/utils.js.map +1 -1
  17. package/build/components/inspector-controls/block-support-tools-panel.js +2 -1
  18. package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  19. package/build/hooks/block-style-variation.js +108 -2
  20. package/build/hooks/block-style-variation.js.map +1 -1
  21. package/build/hooks/duotone.js +16 -11
  22. package/build/hooks/duotone.js.map +1 -1
  23. package/build/hooks/index.js +7 -1
  24. package/build/hooks/index.js.map +1 -1
  25. package/build/hooks/use-bindings-attributes.js +11 -6
  26. package/build/hooks/use-bindings-attributes.js.map +1 -1
  27. package/build/hooks/utils.js +2 -0
  28. package/build/hooks/utils.js.map +1 -1
  29. package/build/private-apis.js +2 -1
  30. package/build/private-apis.js.map +1 -1
  31. package/build-module/components/global-styles/background-panel.js +3 -2
  32. package/build-module/components/global-styles/background-panel.js.map +1 -1
  33. package/build-module/components/global-styles/border-panel.js +3 -2
  34. package/build-module/components/global-styles/border-panel.js.map +1 -1
  35. package/build-module/components/global-styles/color-panel.js +3 -2
  36. package/build-module/components/global-styles/color-panel.js.map +1 -1
  37. package/build-module/components/global-styles/dimensions-panel.js +3 -2
  38. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  39. package/build-module/components/global-styles/filters-panel.js +3 -2
  40. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  41. package/build-module/components/global-styles/image-settings-panel.js +3 -2
  42. package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
  43. package/build-module/components/global-styles/typography-panel.js +3 -2
  44. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  45. package/build-module/components/global-styles/utils.js +15 -6
  46. package/build-module/components/global-styles/utils.js.map +1 -1
  47. package/build-module/components/inspector-controls/block-support-tools-panel.js +3 -2
  48. package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  49. package/build-module/hooks/block-style-variation.js +108 -2
  50. package/build-module/hooks/block-style-variation.js.map +1 -1
  51. package/build-module/hooks/duotone.js +16 -11
  52. package/build-module/hooks/duotone.js.map +1 -1
  53. package/build-module/hooks/index.js +1 -0
  54. package/build-module/hooks/index.js.map +1 -1
  55. package/build-module/hooks/use-bindings-attributes.js +11 -6
  56. package/build-module/hooks/use-bindings-attributes.js.map +1 -1
  57. package/build-module/hooks/utils.js +2 -0
  58. package/build-module/hooks/utils.js.map +1 -1
  59. package/build-module/private-apis.js +3 -2
  60. package/build-module/private-apis.js.map +1 -1
  61. package/build-style/content-rtl.css +1 -0
  62. package/build-style/content.css +1 -0
  63. package/package.json +2 -2
  64. package/src/components/global-styles/background-panel.js +3 -2
  65. package/src/components/global-styles/border-panel.js +3 -2
  66. package/src/components/global-styles/color-panel.js +3 -2
  67. package/src/components/global-styles/dimensions-panel.js +3 -2
  68. package/src/components/global-styles/filters-panel.js +3 -2
  69. package/src/components/global-styles/image-settings-panel.js +3 -2
  70. package/src/components/global-styles/typography-panel.js +3 -2
  71. package/src/components/global-styles/utils.js +17 -6
  72. package/src/components/iframe/content.scss +1 -0
  73. package/src/components/inspector-controls/block-support-tools-panel.js +3 -3
  74. package/src/hooks/block-style-variation.js +124 -2
  75. package/src/hooks/duotone.js +16 -12
  76. package/src/hooks/index.js +1 -0
  77. package/src/hooks/use-bindings-attributes.js +13 -4
  78. package/src/hooks/utils.js +2 -0
  79. package/src/private-apis.js +6 -1
@@ -11,6 +11,7 @@
11
11
  .block-editor-iframe__scale-container {
12
12
  width: 100%;
13
13
  height: 100%;
14
+ display: flex;
14
15
  }
15
16
 
16
17
  .block-editor-iframe__scale-container.is-zoomed-out {
@@ -10,7 +10,7 @@ import { useCallback } from '@wordpress/element';
10
10
  */
11
11
  import { store as blockEditorStore } from '../../store';
12
12
  import { cleanEmptyObject } from '../../hooks/utils';
13
- import { TOOLSPANEL_DROPDOWNMENU_PROPS } from '../global-styles/utils';
13
+ import { useToolsPanelDropdownMenuProps } from '../global-styles/utils';
14
14
 
15
15
  export default function BlockSupportToolsPanel( { children, group, label } ) {
16
16
  const { updateBlockAttributes } = useDispatch( blockEditorStore );
@@ -20,7 +20,7 @@ export default function BlockSupportToolsPanel( { children, group, label } ) {
20
20
  getSelectedBlockClientId,
21
21
  hasMultiSelection,
22
22
  } = useSelect( blockEditorStore );
23
-
23
+ const dropdownMenuProps = useToolsPanelDropdownMenuProps();
24
24
  const panelId = getSelectedBlockClientId();
25
25
  const resetAll = useCallback(
26
26
  ( resetFilters = [] ) => {
@@ -72,7 +72,7 @@ export default function BlockSupportToolsPanel( { children, group, label } ) {
72
72
  shouldRenderPlaceholderItems // Required to maintain fills ordering.
73
73
  __experimentalFirstVisibleItemClass="first"
74
74
  __experimentalLastVisibleItemClass="last"
75
- dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
75
+ dropdownMenuProps={ dropdownMenuProps }
76
76
  >
77
77
  { children }
78
78
  </ToolsPanel>
@@ -16,6 +16,7 @@ import {
16
16
  import { useStyleOverride } from './utils';
17
17
  import { store as blockEditorStore } from '../store';
18
18
  import { globalStylesDataKey } from '../store/private-keys';
19
+ import { unlock } from '../lock-unlock';
19
20
 
20
21
  const VARIATION_PREFIX = 'is-style-';
21
22
 
@@ -59,7 +60,127 @@ function getVariationNameFromClass( className, registeredStyles = [] ) {
59
60
  return null;
60
61
  }
61
62
 
62
- function useBlockSyleVariation( name, variation, clientId ) {
63
+ // A helper component to apply a style override using the useStyleOverride hook.
64
+ function OverrideStyles( { override } ) {
65
+ useStyleOverride( override );
66
+ }
67
+
68
+ /**
69
+ * This component is used to generate new block style variation overrides
70
+ * based on an incoming theme config. If a matching style is found in the config,
71
+ * a new override is created and returned. The overrides can be used in conjunction with
72
+ * useStyleOverride to apply the new styles to the editor. Its use is
73
+ * subject to change.
74
+ *
75
+ * @param {Object} props Props.
76
+ * @param {Object} props.config A global styles object, containing settings and styles.
77
+ * @return {JSX.Element|undefined} An array of new block variation overrides.
78
+ */
79
+ export function __unstableBlockStyleVariationOverridesWithConfig( { config } ) {
80
+ const { getBlockStyles, overrides } = useSelect(
81
+ ( select ) => ( {
82
+ getBlockStyles: select( blocksStore ).getBlockStyles,
83
+ overrides: unlock( select( blockEditorStore ) ).getStyleOverrides(),
84
+ } ),
85
+ []
86
+ );
87
+ const { getBlockName } = useSelect( blockEditorStore );
88
+
89
+ const overridesWithConfig = useMemo( () => {
90
+ if ( ! overrides?.length ) {
91
+ return;
92
+ }
93
+ const newOverrides = [];
94
+ const overriddenClientIds = [];
95
+ for ( const [ , override ] of overrides ) {
96
+ if (
97
+ override?.variation &&
98
+ override?.clientId &&
99
+ /*
100
+ * Because this component overwrites existing style overrides,
101
+ * filter out any overrides that are already present in the store.
102
+ */
103
+ ! overriddenClientIds.includes( override.clientId )
104
+ ) {
105
+ const blockName = getBlockName( override.clientId );
106
+ const configStyles =
107
+ config?.styles?.blocks?.[ blockName ]?.variations?.[
108
+ override.variation
109
+ ];
110
+ if ( configStyles ) {
111
+ const variationConfig = {
112
+ settings: config?.settings,
113
+ // The variation style data is all that is needed to generate
114
+ // the styles for the current application to a block. The variation
115
+ // name is updated to match the instance specific class name.
116
+ styles: {
117
+ blocks: {
118
+ [ blockName ]: {
119
+ variations: {
120
+ [ `${ override.variation }-${ override.clientId }` ]:
121
+ configStyles,
122
+ },
123
+ },
124
+ },
125
+ },
126
+ };
127
+ const blockSelectors = getBlockSelectors(
128
+ getBlockTypes(),
129
+ getBlockStyles,
130
+ override.clientId
131
+ );
132
+ const hasBlockGapSupport = false;
133
+ const hasFallbackGapSupport = true;
134
+ const disableLayoutStyles = true;
135
+ const disableRootPadding = true;
136
+ const variationStyles = toStyles(
137
+ variationConfig,
138
+ blockSelectors,
139
+ hasBlockGapSupport,
140
+ hasFallbackGapSupport,
141
+ disableLayoutStyles,
142
+ disableRootPadding,
143
+ {
144
+ blockGap: false,
145
+ blockStyles: true,
146
+ layoutStyles: false,
147
+ marginReset: false,
148
+ presets: false,
149
+ rootPadding: false,
150
+ variationStyles: true,
151
+ }
152
+ );
153
+ newOverrides.push( {
154
+ id: `${ override.variation }-${ override.clientId }`,
155
+ css: variationStyles,
156
+ __unstableType: 'variation',
157
+ variation: override.variation,
158
+ // The clientId will be stored with the override and used to ensure
159
+ // the order of overrides matches the order of blocks so that the
160
+ // correct CSS cascade is maintained.
161
+ clientId: override.clientId,
162
+ } );
163
+ overriddenClientIds.push( override.clientId );
164
+ }
165
+ }
166
+ }
167
+ return newOverrides;
168
+ }, [ config, overrides, getBlockStyles, getBlockName ] );
169
+
170
+ if ( ! overridesWithConfig || ! overridesWithConfig.length ) {
171
+ return;
172
+ }
173
+
174
+ return (
175
+ <>
176
+ { overridesWithConfig.map( ( override ) => (
177
+ <OverrideStyles key={ override.id } override={ override } />
178
+ ) ) }
179
+ </>
180
+ );
181
+ }
182
+
183
+ function useBlockStyleVariation( name, variation, clientId ) {
63
184
  // Prefer global styles data in GlobalStylesContext, which are available
64
185
  // if in the site editor. Otherwise fall back to whatever is in the
65
186
  // editor settings and available in the post editor.
@@ -112,7 +233,7 @@ function useBlockProps( { name, className, clientId } ) {
112
233
  const variation = getVariationNameFromClass( className, registeredStyles );
113
234
  const variationClass = `${ VARIATION_PREFIX }${ variation }-${ clientId }`;
114
235
 
115
- const { settings, styles } = useBlockSyleVariation(
236
+ const { settings, styles } = useBlockStyleVariation(
116
237
  name,
117
238
  variation,
118
239
  clientId
@@ -157,6 +278,7 @@ function useBlockProps( { name, className, clientId } ) {
157
278
  id: `variation-${ clientId }`,
158
279
  css: variationStyles,
159
280
  __unstableType: 'variation',
281
+ variation,
160
282
  // The clientId will be stored with the override and used to ensure
161
283
  // the order of overrides matches the order of blocks so that the
162
284
  // correct CSS cascade is maintained.
@@ -295,26 +295,30 @@ function useDuotoneStyles( {
295
295
  return;
296
296
  }
297
297
 
298
- // Safari does not always update the duotone filter when the duotone colors
299
- // are changed. When using Safari, force the block element to be repainted by
300
- // the browser to ensure any changes are reflected visually. This logic matches
301
- // that used on the site frontend in `block-supports/duotone.php`.
298
+ // Safari does not always update the duotone filter when the duotone
299
+ // colors are changed. When using Safari, force the block element to be
300
+ // repainted by the browser to ensure any changes are reflected
301
+ // visually. This logic matches that used on the site frontend in
302
+ // `block-supports/duotone.php`.
302
303
  if ( blockElement && isSafari ) {
303
304
  const display = blockElement.style.display;
304
- // Switch to `inline-block` to force a repaint. In the editor, `inline-block`
305
- // is used instead of `none` to ensure that scroll position is not affected,
306
- // as `none` results in the editor scrolling to the top of the block.
305
+ // Switch to `inline-block` to force a repaint. In the editor,
306
+ // `inline-block` is used instead of `none` to ensure that scroll
307
+ // position is not affected, as `none` results in the editor
308
+ // scrolling to the top of the block.
307
309
  blockElement.style.display = 'inline-block';
308
- // Simply accessing el.offsetHeight flushes layout and style
309
- // changes in WebKit without having to wait for setTimeout.
310
+ // Simply accessing el.offsetHeight flushes layout and style changes
311
+ // in WebKit without having to wait for setTimeout.
310
312
  // eslint-disable-next-line no-unused-expressions
311
313
  blockElement.offsetHeight;
312
314
  blockElement.style.display = display;
313
315
  }
314
- }, [ isValidFilter, blockElement ] );
316
+ // `colors` must be a dependency so this effect runs when the colors
317
+ // change in Safari.
318
+ }, [ isValidFilter, blockElement, colors ] );
315
319
  }
316
320
 
317
- function useBlockProps( { name, style } ) {
321
+ function useBlockProps( { clientId, name, style } ) {
318
322
  const id = useInstanceId( useBlockProps );
319
323
  const selector = useMemo( () => {
320
324
  const blockType = getBlockType( name );
@@ -362,7 +366,7 @@ function useBlockProps( { name, style } ) {
362
366
  const shouldRender = selector && attribute;
363
367
 
364
368
  useDuotoneStyles( {
365
- clientId: id,
369
+ clientId,
366
370
  id: filterClass,
367
371
  selector,
368
372
  attribute,
@@ -88,3 +88,4 @@ export { getTypographyClassesAndStyles } from './use-typography-props';
88
88
  export { getGapCSSValue } from './gap';
89
89
  export { useCachedTruthy } from './use-cached-truthy';
90
90
  export { useZoomOut } from './use-zoom-out';
91
+ export { __unstableBlockStyleVariationOverridesWithConfig } from './block-style-variation';
@@ -97,6 +97,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(
97
97
  unlock( select( blocksStore ) ).getAllBlockBindingsSources()
98
98
  );
99
99
  const { name, clientId, context } = props;
100
+ const hasParentPattern = !! props.context[ 'pattern/overrides' ];
100
101
  const hasPatternOverridesDefaultBinding =
101
102
  props.attributes.metadata?.bindings?.[ DEFAULT_ATTRIBUTE ]
102
103
  ?.source === 'core/pattern-overrides';
@@ -216,13 +217,20 @@ export const withBlockBindingSupport = createHigherOrderComponent(
216
217
  }
217
218
  }
218
219
 
219
- // Only apply normal attribute updates to blocks
220
- // that have partial bindings. Currently this is
221
- // only skipped for pattern overrides sources.
222
220
  if (
223
- ! hasPatternOverridesDefaultBinding &&
221
+ // Don't update non-connected attributes if the block is using pattern overrides
222
+ // and the editing is happening while overriding the pattern (not editing the original).
223
+ ! (
224
+ hasPatternOverridesDefaultBinding &&
225
+ hasParentPattern
226
+ ) &&
224
227
  Object.keys( keptAttributes ).length
225
228
  ) {
229
+ // Don't update caption and href until they are supported.
230
+ if ( hasPatternOverridesDefaultBinding ) {
231
+ delete keptAttributes?.caption;
232
+ delete keptAttributes?.href;
233
+ }
226
234
  setAttributes( keptAttributes );
227
235
  }
228
236
  } );
@@ -236,6 +244,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(
236
244
  setAttributes,
237
245
  sources,
238
246
  hasPatternOverridesDefaultBinding,
247
+ hasParentPattern,
239
248
  ]
240
249
  );
241
250
 
@@ -140,6 +140,7 @@ export function useStyleOverride( {
140
140
  css,
141
141
  assets,
142
142
  __unstableType,
143
+ variation,
143
144
  clientId,
144
145
  } = {} ) {
145
146
  const { setStyleOverride, deleteStyleOverride } = unlock(
@@ -159,6 +160,7 @@ export function useStyleOverride( {
159
160
  css,
160
161
  assets,
161
162
  __unstableType,
163
+ variation,
162
164
  clientId,
163
165
  };
164
166
  // Batch updates to style overrides to avoid triggering cascading renders
@@ -20,7 +20,11 @@ import { cleanEmptyObject, useStyleOverride } from './hooks/utils';
20
20
  import BlockQuickNavigation from './components/block-quick-navigation';
21
21
  import { LayoutStyle } from './components/block-list/layout';
22
22
  import { BlockRemovalWarningModal } from './components/block-removal-warning-modal';
23
- import { useLayoutClasses, useLayoutStyles } from './hooks';
23
+ import {
24
+ useLayoutClasses,
25
+ useLayoutStyles,
26
+ __unstableBlockStyleVariationOverridesWithConfig,
27
+ } from './hooks';
24
28
  import DimensionsTool from './components/dimensions-tool';
25
29
  import ResolutionTool from './components/resolution-tool';
26
30
  import TextAlignmentControl from './components/text-alignment-control';
@@ -88,4 +92,5 @@ lock( privateApis, {
88
92
  PrivatePublishDateTimePicker,
89
93
  useSpacingSizes,
90
94
  useBlockDisplayTitle,
95
+ __unstableBlockStyleVariationOverridesWithConfig,
91
96
  } );