@wordpress/block-editor 12.18.0 → 12.18.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.
- package/build/components/dimensions-tool/aspect-ratio-tool.js +2 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +30 -5
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +10 -9
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +14 -31
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +6 -0
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/rich-text/index.js +1 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +55 -34
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/url-popover/index.js +3 -1
- package/build/components/url-popover/index.js.map +1 -1
- package/build/components/url-popover/link-editor.js +2 -1
- package/build/components/url-popover/link-editor.js.map +1 -1
- package/build/components/url-popover/link-viewer.js +2 -1
- package/build/components/url-popover/link-viewer.js.map +1 -1
- package/build/hooks/dimensions.js +71 -1
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/index.js +2 -8
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +0 -6
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/style.js +3 -0
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +2 -2
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/hooks/use-shadow-props.js +0 -15
- package/build/hooks/use-shadow-props.js.map +1 -1
- package/build/hooks/utils.js +4 -6
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +0 -7
- package/build/index.js.map +1 -1
- package/build/utils/object.js +0 -17
- package/build/utils/object.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +2 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +30 -5
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +10 -9
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +15 -32
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +6 -0
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/rich-text/index.js +1 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +57 -36
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/url-popover/index.js +3 -1
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/components/url-popover/link-editor.js +2 -1
- package/build-module/components/url-popover/link-editor.js.map +1 -1
- package/build-module/components/url-popover/link-viewer.js +2 -1
- package/build-module/components/url-popover/link-viewer.js.map +1 -1
- package/build-module/hooks/dimensions.js +70 -2
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/index.js +3 -2
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -1
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/style.js +3 -0
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +2 -2
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/hooks/use-shadow-props.js +0 -14
- package/build-module/hooks/use-shadow-props.js.map +1 -1
- package/build-module/hooks/utils.js +4 -6
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/utils/object.js +0 -16
- package/build-module/utils/object.js.map +1 -1
- package/build-style/style-rtl.css +48 -31
- package/build-style/style.css +48 -31
- package/package.json +4 -4
- package/src/components/block-canvas/style.scss +2 -2
- package/src/components/dimensions-tool/aspect-ratio-tool.js +4 -1
- package/src/components/global-styles/dimensions-panel.js +50 -1
- package/src/components/global-styles/hooks.js +9 -8
- package/src/components/global-styles/typography-panel.js +13 -45
- package/src/components/global-styles/use-global-styles-output.js +6 -0
- package/src/components/media-replace-flow/style.scss +1 -1
- package/src/components/rich-text/index.js +1 -2
- package/src/components/url-popover/image-url-input-ui.js +86 -37
- package/src/components/url-popover/index.js +2 -0
- package/src/components/url-popover/link-editor.js +1 -0
- package/src/components/url-popover/link-viewer.js +1 -0
- package/src/components/url-popover/style.scss +51 -31
- package/src/hooks/dimensions.js +74 -3
- package/src/hooks/index.js +3 -1
- package/src/hooks/index.native.js +1 -1
- package/src/hooks/style.js +4 -0
- package/src/hooks/use-bindings-attributes.js +2 -5
- package/src/hooks/use-shadow-props.js +0 -14
- package/src/hooks/utils.js +8 -16
- package/src/index.js +0 -1
- package/src/utils/object.js +0 -16
|
@@ -6,15 +6,19 @@ import { useRef, useState } from '@wordpress/element';
|
|
|
6
6
|
import {
|
|
7
7
|
ToolbarButton,
|
|
8
8
|
Button,
|
|
9
|
-
NavigableMenu,
|
|
10
9
|
MenuItem,
|
|
11
10
|
ToggleControl,
|
|
12
11
|
TextControl,
|
|
13
|
-
|
|
14
|
-
Path,
|
|
12
|
+
MenuGroup,
|
|
15
13
|
__experimentalVStack as VStack,
|
|
16
14
|
} from '@wordpress/components';
|
|
17
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
link as linkIcon,
|
|
17
|
+
image,
|
|
18
|
+
page,
|
|
19
|
+
fullscreen,
|
|
20
|
+
linkOff,
|
|
21
|
+
} from '@wordpress/icons';
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* Internal dependencies
|
|
@@ -27,14 +31,6 @@ const LINK_DESTINATION_MEDIA = 'media';
|
|
|
27
31
|
const LINK_DESTINATION_ATTACHMENT = 'attachment';
|
|
28
32
|
const NEW_TAB_REL = [ 'noreferrer', 'noopener' ];
|
|
29
33
|
|
|
30
|
-
const icon = (
|
|
31
|
-
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
32
|
-
<Path d="M0,0h24v24H0V0z" fill="none" />
|
|
33
|
-
<Path d="m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z" />
|
|
34
|
-
<Path d="m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z" />
|
|
35
|
-
</SVG>
|
|
36
|
-
);
|
|
37
|
-
|
|
38
34
|
const ImageURLInputUI = ( {
|
|
39
35
|
linkDestination,
|
|
40
36
|
onChangeUrl,
|
|
@@ -45,6 +41,9 @@ const ImageURLInputUI = ( {
|
|
|
45
41
|
linkTarget,
|
|
46
42
|
linkClass,
|
|
47
43
|
rel,
|
|
44
|
+
showLightboxSetting,
|
|
45
|
+
lightboxEnabled,
|
|
46
|
+
onSetLightbox,
|
|
48
47
|
} ) => {
|
|
49
48
|
const [ isOpen, setIsOpen ] = useState( false );
|
|
50
49
|
// Use internal state instead of a ref to make sure that the component
|
|
@@ -138,6 +137,7 @@ const ImageURLInputUI = ( {
|
|
|
138
137
|
onChangeUrl( {
|
|
139
138
|
href: urlInput,
|
|
140
139
|
linkDestination: selectedDestination,
|
|
140
|
+
lightbox: { enabled: false },
|
|
141
141
|
} );
|
|
142
142
|
}
|
|
143
143
|
stopEditLink();
|
|
@@ -157,22 +157,17 @@ const ImageURLInputUI = ( {
|
|
|
157
157
|
const linkDestinations = [
|
|
158
158
|
{
|
|
159
159
|
linkDestination: LINK_DESTINATION_MEDIA,
|
|
160
|
-
title: __( '
|
|
160
|
+
title: __( 'Link to image file' ),
|
|
161
161
|
url: mediaType === 'image' ? mediaUrl : undefined,
|
|
162
|
-
icon,
|
|
162
|
+
icon: image,
|
|
163
163
|
},
|
|
164
164
|
];
|
|
165
165
|
if ( mediaType === 'image' && mediaLink ) {
|
|
166
166
|
linkDestinations.push( {
|
|
167
167
|
linkDestination: LINK_DESTINATION_ATTACHMENT,
|
|
168
|
-
title: __( '
|
|
168
|
+
title: __( 'Link to attachment page' ),
|
|
169
169
|
url: mediaType === 'image' ? mediaLink : undefined,
|
|
170
|
-
icon:
|
|
171
|
-
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
172
|
-
<Path d="M0 0h24v24H0V0z" fill="none" />
|
|
173
|
-
<Path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
174
|
-
</SVG>
|
|
175
|
-
),
|
|
170
|
+
icon: page,
|
|
176
171
|
} );
|
|
177
172
|
}
|
|
178
173
|
return linkDestinations;
|
|
@@ -225,7 +220,7 @@ const ImageURLInputUI = ( {
|
|
|
225
220
|
/>
|
|
226
221
|
<TextControl
|
|
227
222
|
__nextHasNoMarginBottom
|
|
228
|
-
label={ __( 'Link CSS
|
|
223
|
+
label={ __( 'Link CSS class' ) }
|
|
229
224
|
value={ linkClass || '' }
|
|
230
225
|
onChange={ onSetLinkClass }
|
|
231
226
|
/>
|
|
@@ -233,6 +228,7 @@ const ImageURLInputUI = ( {
|
|
|
233
228
|
);
|
|
234
229
|
|
|
235
230
|
const linkEditorValue = urlInput !== null ? urlInput : url;
|
|
231
|
+
const showLinkEditor = ( ! linkEditorValue && ! lightboxEnabled ) === true;
|
|
236
232
|
|
|
237
233
|
const urlLabel = (
|
|
238
234
|
getLinkDestinations().find(
|
|
@@ -245,7 +241,7 @@ const ImageURLInputUI = ( {
|
|
|
245
241
|
<ToolbarButton
|
|
246
242
|
icon={ linkIcon }
|
|
247
243
|
className="components-toolbar__control"
|
|
248
|
-
label={ url ? __( 'Edit link' ) : __( '
|
|
244
|
+
label={ url ? __( 'Edit link' ) : __( 'Add link' ) }
|
|
249
245
|
aria-expanded={ isOpen }
|
|
250
246
|
onClick={ openLinkUI }
|
|
251
247
|
ref={ setPopoverAnchor }
|
|
@@ -256,14 +252,17 @@ const ImageURLInputUI = ( {
|
|
|
256
252
|
anchor={ popoverAnchor }
|
|
257
253
|
onFocusOutside={ onFocusOutside() }
|
|
258
254
|
onClose={ closeLinkUI }
|
|
259
|
-
renderSettings={
|
|
255
|
+
renderSettings={
|
|
256
|
+
! lightboxEnabled ? () => advancedOptions : null
|
|
257
|
+
}
|
|
260
258
|
additionalControls={
|
|
261
|
-
|
|
262
|
-
<
|
|
259
|
+
showLinkEditor && (
|
|
260
|
+
<MenuGroup>
|
|
263
261
|
{ getLinkDestinations().map( ( link ) => (
|
|
264
262
|
<MenuItem
|
|
265
263
|
key={ link.linkDestination }
|
|
266
264
|
icon={ link.icon }
|
|
265
|
+
iconPosition="left"
|
|
267
266
|
onClick={ () => {
|
|
268
267
|
setUrlInput( null );
|
|
269
268
|
onSetHref( link.url );
|
|
@@ -273,20 +272,45 @@ const ImageURLInputUI = ( {
|
|
|
273
272
|
{ link.title }
|
|
274
273
|
</MenuItem>
|
|
275
274
|
) ) }
|
|
276
|
-
|
|
275
|
+
{ showLightboxSetting && (
|
|
276
|
+
<MenuItem
|
|
277
|
+
key="expand-on-click"
|
|
278
|
+
className="block-editor-url-popover__expand-on-click"
|
|
279
|
+
icon={ fullscreen }
|
|
280
|
+
info={ __(
|
|
281
|
+
'Scale the image with a lightbox effect.'
|
|
282
|
+
) }
|
|
283
|
+
iconPosition="left"
|
|
284
|
+
onClick={ () => {
|
|
285
|
+
setUrlInput( null );
|
|
286
|
+
onChangeUrl( {
|
|
287
|
+
linkDestination:
|
|
288
|
+
LINK_DESTINATION_NONE,
|
|
289
|
+
href: '',
|
|
290
|
+
} );
|
|
291
|
+
onSetLightbox( true );
|
|
292
|
+
stopEditLink();
|
|
293
|
+
} }
|
|
294
|
+
>
|
|
295
|
+
{ __( 'Expand on click' ) }
|
|
296
|
+
</MenuItem>
|
|
297
|
+
) }
|
|
298
|
+
</MenuGroup>
|
|
277
299
|
)
|
|
278
300
|
}
|
|
279
301
|
>
|
|
280
|
-
{ ( ! url || isEditingLink ) && (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
302
|
+
{ ( ! url || isEditingLink ) && ! lightboxEnabled && (
|
|
303
|
+
<>
|
|
304
|
+
<URLPopover.LinkEditor
|
|
305
|
+
className="block-editor-format-toolbar__link-container-content"
|
|
306
|
+
value={ linkEditorValue }
|
|
307
|
+
onChangeInputValue={ setUrlInput }
|
|
308
|
+
onSubmit={ onSubmitLinkChange() }
|
|
309
|
+
autocompleteRef={ autocompleteRef }
|
|
310
|
+
/>
|
|
311
|
+
</>
|
|
288
312
|
) }
|
|
289
|
-
{ url && ! isEditingLink && (
|
|
313
|
+
{ url && ! isEditingLink && ! lightboxEnabled && (
|
|
290
314
|
<>
|
|
291
315
|
<URLPopover.LinkViewer
|
|
292
316
|
className="block-editor-format-toolbar__link-container-content"
|
|
@@ -295,12 +319,37 @@ const ImageURLInputUI = ( {
|
|
|
295
319
|
urlLabel={ urlLabel }
|
|
296
320
|
/>
|
|
297
321
|
<Button
|
|
298
|
-
icon={
|
|
322
|
+
icon={ linkOff }
|
|
299
323
|
label={ __( 'Remove link' ) }
|
|
300
324
|
onClick={ onLinkRemove }
|
|
325
|
+
size="compact"
|
|
301
326
|
/>
|
|
302
327
|
</>
|
|
303
328
|
) }
|
|
329
|
+
{ ! url && ! isEditingLink && lightboxEnabled && (
|
|
330
|
+
<div className="block-editor-url-popover__expand-on-click">
|
|
331
|
+
<div className="fullscreen-icon">
|
|
332
|
+
{ fullscreen }
|
|
333
|
+
</div>
|
|
334
|
+
<div className="text">
|
|
335
|
+
<p>{ __( 'Expand on click' ) }</p>
|
|
336
|
+
<p className="description">
|
|
337
|
+
{ __(
|
|
338
|
+
'Scales the image with a lightbox effect'
|
|
339
|
+
) }
|
|
340
|
+
</p>
|
|
341
|
+
</div>
|
|
342
|
+
<Button
|
|
343
|
+
icon={ linkOff }
|
|
344
|
+
className="remove-link"
|
|
345
|
+
label={ __( 'Disable expand on click' ) }
|
|
346
|
+
onClick={ () => {
|
|
347
|
+
onSetLightbox( false );
|
|
348
|
+
} }
|
|
349
|
+
size="compact"
|
|
350
|
+
/>
|
|
351
|
+
</div>
|
|
352
|
+
) }
|
|
304
353
|
</URLPopover>
|
|
305
354
|
) }
|
|
306
355
|
</>
|
|
@@ -70,6 +70,7 @@ function URLPopover( {
|
|
|
70
70
|
focusOnMount={ focusOnMount }
|
|
71
71
|
placement={ computedPlacement }
|
|
72
72
|
shift
|
|
73
|
+
variant="toolbar"
|
|
73
74
|
{ ...popoverProps }
|
|
74
75
|
>
|
|
75
76
|
<div className="block-editor-url-popover__input-container">
|
|
@@ -82,6 +83,7 @@ function URLPopover( {
|
|
|
82
83
|
label={ __( 'Link settings' ) }
|
|
83
84
|
onClick={ toggleSettingsVisibility }
|
|
84
85
|
aria-expanded={ isSettingsExpanded }
|
|
86
|
+
size="compact"
|
|
85
87
|
/>
|
|
86
88
|
) }
|
|
87
89
|
</div>
|
|
@@ -1,53 +1,39 @@
|
|
|
1
1
|
.block-editor-url-popover__additional-controls {
|
|
2
|
-
border-top: $border-width solid $gray-
|
|
2
|
+
border-top: $border-width solid $gray-900;
|
|
3
|
+
padding: $grid-unit-10 $grid-unit-10;
|
|
3
4
|
}
|
|
4
5
|
|
|
5
|
-
.block-editor-url-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.block-editor-url-popover__additional-controls div[role="menu"] > .components-button {
|
|
10
|
-
padding-left: $grid-unit-15;
|
|
6
|
+
.block-editor-url-popover__input-container {
|
|
7
|
+
padding: $grid-unit-10;
|
|
8
|
+
padding-left: $grid-unit-20;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
.block-editor-url-popover__row {
|
|
14
12
|
display: flex;
|
|
13
|
+
gap: $grid-unit-05;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
// Any children of the popover-row that are not the settings-toggle
|
|
18
17
|
// should take up as much space as possible.
|
|
19
18
|
.block-editor-url-popover__row > :not(.block-editor-url-popover__settings-toggle) {
|
|
20
19
|
flex-grow: 1;
|
|
20
|
+
gap: $grid-unit-05;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
padding:
|
|
23
|
+
.block-editor-url-popover__additional-controls .components-button.has-icon {
|
|
24
|
+
padding-left: $grid-unit-10;
|
|
25
|
+
padding-right: $grid-unit-10;
|
|
26
|
+
height: auto;
|
|
27
|
+
text-align: left;
|
|
26
28
|
|
|
27
29
|
> svg {
|
|
28
|
-
|
|
29
|
-
border-radius: $radius-block-ui;
|
|
30
|
-
height: 30px;
|
|
31
|
-
width: 30px;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
&:not(:disabled):focus {
|
|
35
|
-
box-shadow: none;
|
|
36
|
-
|
|
37
|
-
> svg {
|
|
38
|
-
@include block-toolbar-button-style__focus();
|
|
39
|
-
}
|
|
30
|
+
margin-right: $grid-unit-10;
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
33
|
|
|
43
34
|
.block-editor-url-popover__settings-toggle {
|
|
44
35
|
flex-shrink: 0;
|
|
45
36
|
|
|
46
|
-
// Add a left divider to the toggle button.
|
|
47
|
-
border-radius: 0;
|
|
48
|
-
border-left: $border-width solid $gray-300;
|
|
49
|
-
margin-left: 1px;
|
|
50
|
-
|
|
51
37
|
&[aria-expanded="true"] .dashicon {
|
|
52
38
|
transform: rotate(180deg);
|
|
53
39
|
}
|
|
@@ -56,7 +42,7 @@
|
|
|
56
42
|
.block-editor-url-popover__settings {
|
|
57
43
|
display: block;
|
|
58
44
|
padding: $grid-unit-20;
|
|
59
|
-
border-top: $border-width solid $gray-
|
|
45
|
+
border-top: $border-width solid $gray-900;
|
|
60
46
|
}
|
|
61
47
|
|
|
62
48
|
.block-editor-url-popover__link-editor,
|
|
@@ -65,16 +51,50 @@
|
|
|
65
51
|
}
|
|
66
52
|
|
|
67
53
|
.block-editor-url-popover__link-viewer-url {
|
|
68
|
-
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
69
56
|
flex-grow: 1;
|
|
70
57
|
flex-shrink: 1;
|
|
71
58
|
overflow: hidden;
|
|
72
59
|
text-overflow: ellipsis;
|
|
73
60
|
white-space: nowrap;
|
|
74
|
-
|
|
75
|
-
max-width: 500px;
|
|
61
|
+
margin-right: $grid-unit-10;
|
|
76
62
|
|
|
77
63
|
&.has-invalid-link {
|
|
78
64
|
color: $alert-red;
|
|
79
65
|
}
|
|
80
66
|
}
|
|
67
|
+
|
|
68
|
+
.block-editor-url-popover__expand-on-click {
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
min-width: $modal-min-width;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
white-space: nowrap;
|
|
74
|
+
|
|
75
|
+
.fullscreen-icon {
|
|
76
|
+
padding-right: $grid-unit-05;
|
|
77
|
+
|
|
78
|
+
> svg {
|
|
79
|
+
width: $icon-size;
|
|
80
|
+
height: $icon-size;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.text {
|
|
85
|
+
flex-grow: 1;
|
|
86
|
+
|
|
87
|
+
p {
|
|
88
|
+
margin: 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.description {
|
|
93
|
+
color: $gray-600;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.remove-link {
|
|
97
|
+
margin-right: $grid-unit-10;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
package/src/hooks/dimensions.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
4
|
-
import { useState, useEffect, useCallback } from '@wordpress/element';
|
|
9
|
+
import { Platform, useState, useEffect, useCallback } from '@wordpress/element';
|
|
5
10
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
11
|
import { getBlockSupport } from '@wordpress/blocks';
|
|
7
12
|
import deprecated from '@wordpress/deprecated';
|
|
@@ -18,8 +23,7 @@ import { MarginVisualizer } from './margin';
|
|
|
18
23
|
import { PaddingVisualizer } from './padding';
|
|
19
24
|
import { store as blockEditorStore } from '../store';
|
|
20
25
|
import { unlock } from '../lock-unlock';
|
|
21
|
-
|
|
22
|
-
import { cleanEmptyObject } from './utils';
|
|
26
|
+
import { cleanEmptyObject, shouldSkipSerialization } from './utils';
|
|
23
27
|
|
|
24
28
|
export const DIMENSIONS_SUPPORT_KEY = 'dimensions';
|
|
25
29
|
export const SPACING_SUPPORT_KEY = 'spacing';
|
|
@@ -125,6 +129,73 @@ export function DimensionsPanel( { clientId, name, setAttributes, settings } ) {
|
|
|
125
129
|
);
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Determine whether there is block support for dimensions.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} blockName Block name.
|
|
136
|
+
* @param {string} feature Background image feature to check for.
|
|
137
|
+
*
|
|
138
|
+
* @return {boolean} Whether there is support.
|
|
139
|
+
*/
|
|
140
|
+
export function hasDimensionsSupport( blockName, feature = 'any' ) {
|
|
141
|
+
if ( Platform.OS !== 'web' ) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const support = getBlockSupport( blockName, DIMENSIONS_SUPPORT_KEY );
|
|
146
|
+
|
|
147
|
+
if ( support === true ) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if ( feature === 'any' ) {
|
|
152
|
+
return !! ( support?.aspectRatio || !! support?.minHeight );
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return !! support?.[ feature ];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export default {
|
|
159
|
+
useBlockProps,
|
|
160
|
+
attributeKeys: [ 'minHeight', 'style' ],
|
|
161
|
+
hasSupport( name ) {
|
|
162
|
+
return hasDimensionsSupport( name, 'aspectRatio' );
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
function useBlockProps( { name, minHeight, style } ) {
|
|
167
|
+
if (
|
|
168
|
+
! hasDimensionsSupport( name, 'aspectRatio' ) ||
|
|
169
|
+
shouldSkipSerialization( name, DIMENSIONS_SUPPORT_KEY, 'aspectRatio' )
|
|
170
|
+
) {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const className = classnames( {
|
|
175
|
+
'has-aspect-ratio': !! style?.dimensions?.aspectRatio,
|
|
176
|
+
} );
|
|
177
|
+
|
|
178
|
+
// Allow dimensions-based inline style overrides to override any global styles rules that
|
|
179
|
+
// might be set for the block, and therefore affect the display of the aspect ratio.
|
|
180
|
+
const inlineStyleOverrides = {};
|
|
181
|
+
|
|
182
|
+
// Apply rules to unset incompatible styles.
|
|
183
|
+
// Note that a set `aspectRatio` will win out if both an aspect ratio and a minHeight are set.
|
|
184
|
+
// This is because the aspect ratio is a newer block support, so (in theory) any aspect ratio
|
|
185
|
+
// that is set should be intentional and should override any existing minHeight. The Cover block
|
|
186
|
+
// and dimensions controls have logic that will manually clear the aspect ratio if a minHeight
|
|
187
|
+
// is set.
|
|
188
|
+
if ( style?.dimensions?.aspectRatio ) {
|
|
189
|
+
// To ensure the aspect ratio does not get overridden by `minHeight` unset any existing rule.
|
|
190
|
+
inlineStyleOverrides.minHeight = 'unset';
|
|
191
|
+
} else if ( minHeight || style?.dimensions?.minHeight ) {
|
|
192
|
+
// To ensure the minHeight does not get overridden by `aspectRatio` unset any existing rule.
|
|
193
|
+
inlineStyleOverrides.aspectRatio = 'unset';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return { className, style: inlineStyleOverrides };
|
|
197
|
+
}
|
|
198
|
+
|
|
128
199
|
/**
|
|
129
200
|
* @deprecated
|
|
130
201
|
*/
|
package/src/hooks/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import './generated-class-name';
|
|
|
16
16
|
import style from './style';
|
|
17
17
|
import './settings';
|
|
18
18
|
import color from './color';
|
|
19
|
+
import dimensions from './dimensions';
|
|
19
20
|
import duotone from './duotone';
|
|
20
21
|
import fontFamily from './font-family';
|
|
21
22
|
import fontSize from './font-size';
|
|
@@ -47,6 +48,7 @@ createBlockListBlockFilter( [
|
|
|
47
48
|
align,
|
|
48
49
|
style,
|
|
49
50
|
color,
|
|
51
|
+
dimensions,
|
|
50
52
|
duotone,
|
|
51
53
|
fontFamily,
|
|
52
54
|
fontSize,
|
|
@@ -69,7 +71,7 @@ createBlockSaveFilter( [
|
|
|
69
71
|
export { useCustomSides } from './dimensions';
|
|
70
72
|
export { useLayoutClasses, useLayoutStyles } from './layout';
|
|
71
73
|
export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
|
|
72
|
-
export { getShadowClassesAndStyles
|
|
74
|
+
export { getShadowClassesAndStyles } from './use-shadow-props';
|
|
73
75
|
export { getColorClassesAndStyles, useColorProps } from './use-color-props';
|
|
74
76
|
export { getSpacingClassesAndStyles } from './use-spacing-props';
|
|
75
77
|
export { getTypographyClassesAndStyles } from './use-typography-props';
|
|
@@ -28,7 +28,7 @@ createBlockSaveFilter( [
|
|
|
28
28
|
] );
|
|
29
29
|
|
|
30
30
|
export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
|
|
31
|
-
export { getShadowClassesAndStyles
|
|
31
|
+
export { getShadowClassesAndStyles } from './use-shadow-props';
|
|
32
32
|
export { getColorClassesAndStyles, useColorProps } from './use-color-props';
|
|
33
33
|
export { getSpacingClassesAndStyles } from './use-spacing-props';
|
|
34
34
|
export { useCachedTruthy } from './use-cached-truthy';
|
package/src/hooks/style.js
CHANGED
|
@@ -133,10 +133,14 @@ const skipSerializationPathsEdit = {
|
|
|
133
133
|
*/
|
|
134
134
|
const skipSerializationPathsSave = {
|
|
135
135
|
...skipSerializationPathsEdit,
|
|
136
|
+
[ `${ DIMENSIONS_SUPPORT_KEY }.aspectRatio` ]: [
|
|
137
|
+
`${ DIMENSIONS_SUPPORT_KEY }.aspectRatio`,
|
|
138
|
+
], // Skip serialization of aspect ratio in save mode.
|
|
136
139
|
[ `${ BACKGROUND_SUPPORT_KEY }` ]: [ BACKGROUND_SUPPORT_KEY ], // Skip serialization of background support in save mode.
|
|
137
140
|
};
|
|
138
141
|
|
|
139
142
|
const skipSerializationPathsSaveChecks = {
|
|
143
|
+
[ `${ DIMENSIONS_SUPPORT_KEY }.aspectRatio` ]: true,
|
|
140
144
|
[ `${ BACKGROUND_SUPPORT_KEY }` ]: true,
|
|
141
145
|
};
|
|
142
146
|
|
|
@@ -44,7 +44,7 @@ const createEditFunctionWithBindingsAttribute = () =>
|
|
|
44
44
|
Object.entries( updatedAttributes.metadata.bindings ).forEach(
|
|
45
45
|
( [ attributeName, settings ] ) => {
|
|
46
46
|
const source = getBlockBindingsSource(
|
|
47
|
-
settings.source
|
|
47
|
+
settings.source
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
if ( source ) {
|
|
@@ -52,10 +52,7 @@ const createEditFunctionWithBindingsAttribute = () =>
|
|
|
52
52
|
const {
|
|
53
53
|
placeholder,
|
|
54
54
|
useValue: [ metaValue = null ] = [],
|
|
55
|
-
} = source.useSource(
|
|
56
|
-
props,
|
|
57
|
-
settings.source.attributes
|
|
58
|
-
);
|
|
55
|
+
} = source.useSource( props, settings.args );
|
|
59
56
|
|
|
60
57
|
if ( placeholder && ! metaValue ) {
|
|
61
58
|
// If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.
|
|
@@ -18,20 +18,6 @@ export function getShadowClassesAndStyles( attributes ) {
|
|
|
18
18
|
const shadow = attributes.style?.shadow || '';
|
|
19
19
|
|
|
20
20
|
return {
|
|
21
|
-
className: undefined,
|
|
22
21
|
style: getInlineStyles( { shadow } ),
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Derives the shadow related props for a block from its shadow block support
|
|
28
|
-
* attributes.
|
|
29
|
-
*
|
|
30
|
-
* @param {Object} attributes Block attributes.
|
|
31
|
-
*
|
|
32
|
-
* @return {Object} ClassName & style props from shadow block support.
|
|
33
|
-
*/
|
|
34
|
-
export function useShadowProps( attributes ) {
|
|
35
|
-
const shadowProps = getShadowClassesAndStyles( attributes );
|
|
36
|
-
return shadowProps;
|
|
37
|
-
}
|
package/src/hooks/utils.js
CHANGED
|
@@ -177,10 +177,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
177
177
|
backgroundImage,
|
|
178
178
|
backgroundSize,
|
|
179
179
|
fontFamilies,
|
|
180
|
-
|
|
181
|
-
themeFontSizes,
|
|
182
|
-
defaultFontSizes,
|
|
183
|
-
defaultFontSizesEnabled,
|
|
180
|
+
fontSizes,
|
|
184
181
|
customFontSize,
|
|
185
182
|
fontStyle,
|
|
186
183
|
fontWeight,
|
|
@@ -195,6 +192,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
195
192
|
blockGap,
|
|
196
193
|
spacingSizes,
|
|
197
194
|
units,
|
|
195
|
+
aspectRatio,
|
|
198
196
|
minHeight,
|
|
199
197
|
layout,
|
|
200
198
|
borderColor,
|
|
@@ -226,10 +224,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
226
224
|
'background.backgroundImage',
|
|
227
225
|
'background.backgroundSize',
|
|
228
226
|
'typography.fontFamilies',
|
|
229
|
-
'typography.fontSizes
|
|
230
|
-
'typography.fontSizes.theme',
|
|
231
|
-
'typography.fontSizes.default',
|
|
232
|
-
'typography.defaultFontSizes',
|
|
227
|
+
'typography.fontSizes',
|
|
233
228
|
'typography.customFontSize',
|
|
234
229
|
'typography.fontStyle',
|
|
235
230
|
'typography.fontWeight',
|
|
@@ -244,6 +239,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
244
239
|
'spacing.blockGap',
|
|
245
240
|
'spacing.spacingSizes',
|
|
246
241
|
'spacing.units',
|
|
242
|
+
'dimensions.aspectRatio',
|
|
247
243
|
'dimensions.minHeight',
|
|
248
244
|
'layout',
|
|
249
245
|
'border.color',
|
|
@@ -312,12 +308,9 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
312
308
|
custom: fontFamilies,
|
|
313
309
|
},
|
|
314
310
|
fontSizes: {
|
|
315
|
-
custom:
|
|
316
|
-
theme: themeFontSizes,
|
|
317
|
-
default: defaultFontSizes,
|
|
311
|
+
custom: fontSizes,
|
|
318
312
|
},
|
|
319
313
|
customFontSize,
|
|
320
|
-
defaultFontSizes: defaultFontSizesEnabled,
|
|
321
314
|
fontStyle,
|
|
322
315
|
fontWeight,
|
|
323
316
|
lineHeight,
|
|
@@ -343,6 +336,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
343
336
|
width: borderWidth,
|
|
344
337
|
},
|
|
345
338
|
dimensions: {
|
|
339
|
+
aspectRatio,
|
|
346
340
|
minHeight,
|
|
347
341
|
},
|
|
348
342
|
layout,
|
|
@@ -353,10 +347,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
353
347
|
backgroundImage,
|
|
354
348
|
backgroundSize,
|
|
355
349
|
fontFamilies,
|
|
356
|
-
|
|
357
|
-
themeFontSizes,
|
|
358
|
-
defaultFontSizes,
|
|
359
|
-
defaultFontSizesEnabled,
|
|
350
|
+
fontSizes,
|
|
360
351
|
customFontSize,
|
|
361
352
|
fontStyle,
|
|
362
353
|
fontWeight,
|
|
@@ -371,6 +362,7 @@ export function useBlockSettings( name, parentLayout ) {
|
|
|
371
362
|
blockGap,
|
|
372
363
|
spacingSizes,
|
|
373
364
|
units,
|
|
365
|
+
aspectRatio,
|
|
374
366
|
minHeight,
|
|
375
367
|
layout,
|
|
376
368
|
parentLayout,
|
package/src/index.js
CHANGED
|
@@ -12,7 +12,6 @@ export {
|
|
|
12
12
|
getSpacingClassesAndStyles as __experimentalGetSpacingClassesAndStyles,
|
|
13
13
|
getGapCSSValue as __experimentalGetGapCSSValue,
|
|
14
14
|
getShadowClassesAndStyles as __experimentalGetShadowClassesAndStyles,
|
|
15
|
-
useShadowProps as __experimentalUseShadowProps,
|
|
16
15
|
useCachedTruthy,
|
|
17
16
|
} from './hooks';
|
|
18
17
|
export * from './components';
|
package/src/utils/object.js
CHANGED
|
@@ -49,19 +49,3 @@ export const getValueFromObjectPath = ( object, path, defaultValue ) => {
|
|
|
49
49
|
} );
|
|
50
50
|
return value ?? defaultValue;
|
|
51
51
|
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Helper util to filter out objects with duplicate values for a given property.
|
|
55
|
-
*
|
|
56
|
-
* @param {Object[]} array Array of objects to filter.
|
|
57
|
-
* @param {string} property Property to filter unique values by.
|
|
58
|
-
*
|
|
59
|
-
* @return {Object[]} Array of objects with unique values for the specified property.
|
|
60
|
-
*/
|
|
61
|
-
export function uniqByProperty( array, property ) {
|
|
62
|
-
const seen = new Set();
|
|
63
|
-
return array.filter( ( item ) => {
|
|
64
|
-
const value = item[ property ];
|
|
65
|
-
return seen.has( value ) ? false : seen.add( value );
|
|
66
|
-
} );
|
|
67
|
-
}
|