@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.
- package/build/components/global-styles/background-panel.js +2 -1
- package/build/components/global-styles/background-panel.js.map +1 -1
- package/build/components/global-styles/border-panel.js +2 -1
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +2 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +2 -1
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +2 -1
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +2 -1
- package/build/components/global-styles/image-settings-panel.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +2 -1
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/utils.js +17 -7
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +2 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/hooks/block-style-variation.js +108 -2
- package/build/hooks/block-style-variation.js.map +1 -1
- package/build/hooks/duotone.js +16 -11
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +7 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +11 -6
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/hooks/utils.js +2 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +2 -1
- package/build/private-apis.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +3 -2
- package/build-module/components/global-styles/background-panel.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +3 -2
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +3 -2
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +3 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +3 -2
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +3 -2
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +3 -2
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/utils.js +15 -6
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +3 -2
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/hooks/block-style-variation.js +108 -2
- package/build-module/hooks/block-style-variation.js.map +1 -1
- package/build-module/hooks/duotone.js +16 -11
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +11 -6
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/hooks/utils.js +2 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +3 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-style/content-rtl.css +1 -0
- package/build-style/content.css +1 -0
- package/package.json +2 -2
- package/src/components/global-styles/background-panel.js +3 -2
- package/src/components/global-styles/border-panel.js +3 -2
- package/src/components/global-styles/color-panel.js +3 -2
- package/src/components/global-styles/dimensions-panel.js +3 -2
- package/src/components/global-styles/filters-panel.js +3 -2
- package/src/components/global-styles/image-settings-panel.js +3 -2
- package/src/components/global-styles/typography-panel.js +3 -2
- package/src/components/global-styles/utils.js +17 -6
- package/src/components/iframe/content.scss +1 -0
- package/src/components/inspector-controls/block-support-tools-panel.js +3 -3
- package/src/hooks/block-style-variation.js +124 -2
- package/src/hooks/duotone.js +16 -12
- package/src/hooks/index.js +1 -0
- package/src/hooks/use-bindings-attributes.js +13 -4
- package/src/hooks/utils.js +2 -0
- package/src/private-apis.js +6 -1
|
@@ -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 {
|
|
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={
|
|
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
|
-
|
|
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 } =
|
|
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.
|
package/src/hooks/duotone.js
CHANGED
|
@@ -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
|
|
299
|
-
// are changed. When using Safari, force the block element to be
|
|
300
|
-
// the browser to ensure any changes are reflected
|
|
301
|
-
// that used on the site frontend in
|
|
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,
|
|
305
|
-
// is used instead of `none` to ensure that scroll
|
|
306
|
-
// as `none` results in the editor
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
|
369
|
+
clientId,
|
|
366
370
|
id: filterClass,
|
|
367
371
|
selector,
|
|
368
372
|
attribute,
|
package/src/hooks/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
package/src/hooks/utils.js
CHANGED
|
@@ -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
|
package/src/private-apis.js
CHANGED
|
@@ -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 {
|
|
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
|
} );
|