@wordpress/block-editor 14.2.1-next.5368f64a9.0 → 14.3.1
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/CHANGELOG.md +2 -0
- package/build/components/background-image-control/index.js +566 -0
- package/build/components/background-image-control/index.js.map +1 -0
- package/build/components/block-card/index.js +5 -2
- package/build/components/block-card/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js +4 -2
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build/components/global-styles/background-panel.js +20 -545
- package/build/components/global-styles/background-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +3 -0
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/grid/grid-item-resizer.js +2 -2
- package/build/components/grid/grid-item-resizer.js.map +1 -1
- package/build/components/iframe/index.js +1 -0
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +6 -0
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +1 -0
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +2 -4
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/index.js +2 -4
- package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +4 -8
- package/build/components/inserter/media-tab/media-preview.js.map +1 -1
- package/build/components/inserter/media-tab/media-tab.js +2 -4
- package/build/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +2 -4
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter-listbox/item.js +2 -4
- package/build/components/inserter-listbox/item.js.map +1 -1
- package/build/components/link-control/index.js +14 -14
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-input.js +4 -2
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/rich-text/index.js +10 -4
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +8 -9
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/linked-button.js +35 -0
- package/build/components/spacing-sizes-control/linked-button.js.map +1 -0
- package/build/components/spacing-sizes-control/utils.js +3 -2
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/components/url-input/index.js +7 -6
- package/build/components/url-input/index.js.map +1 -1
- package/build/hooks/block-bindings.js +65 -53
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/hooks/block-hooks.js +1 -8
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/store/private-selectors.js +10 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build-module/components/background-image-control/index.js +556 -0
- package/build-module/components/background-image-control/index.js.map +1 -0
- package/build-module/components/block-card/index.js +6 -3
- package/build-module/components/block-card/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js +4 -2
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +22 -546
- package/build-module/components/global-styles/background-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +3 -0
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/grid/grid-item-resizer.js +2 -2
- package/build-module/components/grid/grid-item-resizer.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -0
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +6 -0
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +1 -0
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +2 -4
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/index.js +2 -4
- package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +4 -8
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-tab.js +2 -4
- package/build-module/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +2 -4
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter-listbox/item.js +2 -4
- package/build-module/components/inserter-listbox/item.js.map +1 -1
- package/build-module/components/link-control/index.js +15 -15
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-input.js +4 -2
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/rich-text/index.js +10 -4
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +9 -10
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/linked-button.js +28 -0
- package/build-module/components/spacing-sizes-control/linked-button.js.map +1 -0
- package/build-module/components/spacing-sizes-control/utils.js +3 -2
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/components/url-input/index.js +8 -7
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/hooks/block-bindings.js +65 -53
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/hooks/block-hooks.js +3 -10
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/store/private-selectors.js +10 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-style/style-rtl.css +152 -285
- package/build-style/style.css +152 -285
- package/package.json +32 -32
- package/src/components/background-image-control/index.js +741 -0
- package/src/components/background-image-control/style.scss +170 -0
- package/src/components/background-image-control/test/index.js +47 -0
- package/src/components/block-card/index.js +12 -3
- package/src/components/block-list/use-block-props/use-zoom-out-mode-exit.js +2 -5
- package/src/components/global-styles/background-panel.js +19 -730
- package/src/components/global-styles/dimensions-panel.js +3 -0
- package/src/components/global-styles/style.scss +0 -168
- package/src/components/global-styles/test/background-panel.js +1 -47
- package/src/components/grid/grid-item-resizer.js +2 -2
- package/src/components/image-editor/use-save-image.js +7 -0
- package/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +1 -2
- package/src/components/inserter/block-patterns-tab/index.js +1 -2
- package/src/components/inserter/media-tab/media-preview.js +2 -4
- package/src/components/inserter/media-tab/media-tab.js +1 -2
- package/src/components/inserter/quick-inserter.js +1 -2
- package/src/components/inserter/style.scss +0 -10
- package/src/components/inserter-listbox/item.js +1 -5
- package/src/components/link-control/index.js +19 -14
- package/src/components/link-control/search-input.js +2 -0
- package/src/components/link-control/style.scss +0 -22
- package/src/components/list-view/style.scss +1 -1
- package/src/components/rich-text/index.js +20 -5
- package/src/components/spacing-sizes-control/index.js +10 -13
- package/src/components/spacing-sizes-control/linked-button.js +32 -0
- package/src/components/spacing-sizes-control/test/utils.js +22 -30
- package/src/components/spacing-sizes-control/utils.js +6 -2
- package/src/components/url-input/index.js +5 -4
- package/src/components/url-input/style.scss +3 -26
- package/src/hooks/block-bindings.js +64 -50
- package/src/hooks/block-hooks.js +3 -14
- package/src/hooks/block-hooks.scss +0 -9
- package/src/store/private-selectors.js +9 -0
- package/src/style.scss +1 -0
- package/src/utils/test/transform-styles.js +1 -1
- package/build/components/spacing-sizes-control/sides-dropdown/index.js +0 -86
- package/build/components/spacing-sizes-control/sides-dropdown/index.js.map +0 -1
- package/build-module/components/spacing-sizes-control/sides-dropdown/index.js +0 -81
- package/build-module/components/spacing-sizes-control/sides-dropdown/index.js.map +0 -1
- package/src/components/spacing-sizes-control/sides-dropdown/index.js +0 -91
|
@@ -373,47 +373,39 @@ describe( 'getInitialView', () => {
|
|
|
373
373
|
getInitialView( { top: '1em', right: '10px' }, ALL_SIDES )
|
|
374
374
|
).toBe( VIEWS.custom );
|
|
375
375
|
} );
|
|
376
|
-
it( 'should
|
|
377
|
-
expect( getInitialView( { top: '1em' }, ALL_SIDES ) ).not.toBe(
|
|
378
|
-
VIEWS.custom
|
|
379
|
-
);
|
|
380
|
-
} );
|
|
381
|
-
} );
|
|
382
|
-
|
|
383
|
-
describe( 'Single side view', () => {
|
|
384
|
-
it( 'should return single side when only single side supported', () => {
|
|
385
|
-
expect( getInitialView( { top: '1em' }, [ 'top' ] ) ).toBe(
|
|
386
|
-
VIEWS.top
|
|
387
|
-
);
|
|
388
|
-
} );
|
|
389
|
-
|
|
390
|
-
it( 'should return the single side view if there is only a single side value set and supported sides > 1', () => {
|
|
376
|
+
it( 'should return custom view if there is only a single side value', () => {
|
|
391
377
|
expect( getInitialView( { top: '1em' }, ALL_SIDES ) ).toBe(
|
|
392
|
-
VIEWS.
|
|
393
|
-
);
|
|
394
|
-
expect( getInitialView( { right: '1em' }, ALL_SIDES ) ).toBe(
|
|
395
|
-
VIEWS.right
|
|
396
|
-
);
|
|
397
|
-
expect( getInitialView( { bottom: '1em' }, ALL_SIDES ) ).toBe(
|
|
398
|
-
VIEWS.bottom
|
|
399
|
-
);
|
|
400
|
-
expect( getInitialView( { left: '1em' }, ALL_SIDES ) ).toBe(
|
|
401
|
-
VIEWS.left
|
|
378
|
+
VIEWS.custom
|
|
402
379
|
);
|
|
403
380
|
} );
|
|
404
|
-
it( 'should return
|
|
381
|
+
it( 'should return custom view even if only single side supported', () => {
|
|
405
382
|
expect( getInitialView( { top: '1em' }, [ 'top' ] ) ).toBe(
|
|
406
|
-
VIEWS.
|
|
383
|
+
VIEWS.custom
|
|
407
384
|
);
|
|
408
385
|
expect( getInitialView( { right: '1em' }, [ 'right' ] ) ).toBe(
|
|
409
|
-
VIEWS.
|
|
386
|
+
VIEWS.custom
|
|
410
387
|
);
|
|
411
388
|
expect( getInitialView( { bottom: '1em' }, [ 'bottom' ] ) ).toBe(
|
|
412
|
-
VIEWS.
|
|
389
|
+
VIEWS.custom
|
|
413
390
|
);
|
|
414
391
|
expect( getInitialView( { left: '1em' }, [ 'left' ] ) ).toBe(
|
|
415
|
-
VIEWS.
|
|
392
|
+
VIEWS.custom
|
|
416
393
|
);
|
|
417
394
|
} );
|
|
418
395
|
} );
|
|
396
|
+
|
|
397
|
+
describe( 'Single side view', () => {
|
|
398
|
+
it( 'should return single side when only single side supported and no value defined', () => {
|
|
399
|
+
expect( getInitialView( {}, [ 'top' ] ) ).toBe( VIEWS.top );
|
|
400
|
+
} );
|
|
401
|
+
|
|
402
|
+
it( 'should return single side when only single side supported and has only axial sides', () => {
|
|
403
|
+
expect(
|
|
404
|
+
getInitialView( { top: '1em' }, [ 'horizontal', 'vertical' ] )
|
|
405
|
+
).toBe( VIEWS.top );
|
|
406
|
+
expect(
|
|
407
|
+
getInitialView( { left: '4em' }, [ 'horizontal', 'vertical' ] )
|
|
408
|
+
).toBe( VIEWS.left );
|
|
409
|
+
} );
|
|
410
|
+
} );
|
|
419
411
|
} );
|
|
@@ -363,6 +363,10 @@ export function getInitialView( values = {}, sides ) {
|
|
|
363
363
|
top === bottom && left === right && ( !! top || !! left );
|
|
364
364
|
const hasNoValuesAndBalancedSides =
|
|
365
365
|
! sideValues.length && hasBalancedSidesSupport( sides );
|
|
366
|
+
const hasOnlyAxialSides =
|
|
367
|
+
sides?.includes( 'horizontal' ) &&
|
|
368
|
+
sides?.includes( 'vertical' ) &&
|
|
369
|
+
sides?.length === 2;
|
|
366
370
|
|
|
367
371
|
if (
|
|
368
372
|
hasAxisSupport( sides ) &&
|
|
@@ -371,9 +375,9 @@ export function getInitialView( values = {}, sides ) {
|
|
|
371
375
|
return VIEWS.axial;
|
|
372
376
|
}
|
|
373
377
|
|
|
374
|
-
//
|
|
378
|
+
// Only axial sides are supported and single value defined.
|
|
375
379
|
// - Ensure the side returned is the first side that has a value.
|
|
376
|
-
if ( sideValues.length === 1 ) {
|
|
380
|
+
if ( hasOnlyAxialSides && sideValues.length === 1 ) {
|
|
377
381
|
let side;
|
|
378
382
|
|
|
379
383
|
Object.entries( values ).some( ( [ key, value ] ) => {
|
|
@@ -12,6 +12,7 @@ import { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';
|
|
|
12
12
|
import {
|
|
13
13
|
BaseControl,
|
|
14
14
|
Button,
|
|
15
|
+
__experimentalInputControl as InputControl,
|
|
15
16
|
Spinner,
|
|
16
17
|
withSpokenMessages,
|
|
17
18
|
Popover,
|
|
@@ -234,8 +235,8 @@ class URLInput extends Component {
|
|
|
234
235
|
this.suggestionsRequest = request;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
onChange(
|
|
238
|
-
this.props.onChange(
|
|
238
|
+
onChange( newValue ) {
|
|
239
|
+
this.props.onChange( newValue );
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
onFocus() {
|
|
@@ -448,7 +449,6 @@ class URLInput extends Component {
|
|
|
448
449
|
id: inputId,
|
|
449
450
|
value,
|
|
450
451
|
required: true,
|
|
451
|
-
className: 'block-editor-url-input__input',
|
|
452
452
|
type: 'text',
|
|
453
453
|
onChange: this.onChange,
|
|
454
454
|
onFocus: this.onFocus,
|
|
@@ -464,6 +464,7 @@ class URLInput extends Component {
|
|
|
464
464
|
? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`
|
|
465
465
|
: undefined,
|
|
466
466
|
ref: this.inputRef,
|
|
467
|
+
suffix: this.props.suffix,
|
|
467
468
|
};
|
|
468
469
|
|
|
469
470
|
if ( renderControl ) {
|
|
@@ -472,7 +473,7 @@ class URLInput extends Component {
|
|
|
472
473
|
|
|
473
474
|
return (
|
|
474
475
|
<BaseControl __nextHasNoMarginBottom { ...controlProps }>
|
|
475
|
-
<
|
|
476
|
+
<InputControl { ...inputProps } __next40pxDefaultSize />
|
|
476
477
|
{ loading && <Spinner /> }
|
|
477
478
|
</BaseControl>
|
|
478
479
|
);
|
|
@@ -9,33 +9,14 @@ $input-size: 300px;
|
|
|
9
9
|
position: relative;
|
|
10
10
|
padding: 1px;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
width:
|
|
14
|
-
|
|
15
|
-
width: $input-size;
|
|
16
|
-
}
|
|
17
|
-
padding: $input-padding;
|
|
18
|
-
margin-left: 0;
|
|
19
|
-
margin-right: 0;
|
|
20
|
-
|
|
21
|
-
/* Fonts smaller than 16px causes mobile safari to zoom. */
|
|
22
|
-
font-size: $mobile-text-min-font-size;
|
|
23
|
-
@include break-small {
|
|
24
|
-
font-size: $default-font-size;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
&::-ms-clear {
|
|
28
|
-
display: none;
|
|
29
|
-
}
|
|
12
|
+
@include break-small() {
|
|
13
|
+
min-width: $input-size;
|
|
14
|
+
width: auto;
|
|
30
15
|
}
|
|
31
16
|
|
|
32
17
|
&.is-full-width {
|
|
33
18
|
width: 100%;
|
|
34
19
|
|
|
35
|
-
.block-editor-url-input__input[type="text"] {
|
|
36
|
-
width: 100%;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
20
|
&__suggestions {
|
|
40
21
|
width: 100%;
|
|
41
22
|
}
|
|
@@ -49,10 +30,6 @@ $input-size: 300px;
|
|
|
49
30
|
}
|
|
50
31
|
}
|
|
51
32
|
|
|
52
|
-
.block-editor-url-input__input[type="text"] {
|
|
53
|
-
@include input-control;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
33
|
// Suggestions
|
|
57
34
|
.block-editor-url-input__suggestions {
|
|
58
35
|
max-height: 200px;
|
|
@@ -31,6 +31,8 @@ import { store as blockEditorStore } from '../store';
|
|
|
31
31
|
|
|
32
32
|
const { DropdownMenuV2 } = unlock( componentsPrivateApis );
|
|
33
33
|
|
|
34
|
+
const EMPTY_OBJECT = {};
|
|
35
|
+
|
|
34
36
|
const useToolsPanelDropdownMenuProps = () => {
|
|
35
37
|
const isMobile = useViewportMatch( 'medium', '<' );
|
|
36
38
|
return ! isMobile
|
|
@@ -59,7 +61,7 @@ function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
|
|
|
59
61
|
{ registeredSources[ name ].label }
|
|
60
62
|
</DropdownMenuV2.GroupLabel>
|
|
61
63
|
) }
|
|
62
|
-
{ Object.entries( fields ).map( ( [ key,
|
|
64
|
+
{ Object.entries( fields ).map( ( [ key, args ] ) => (
|
|
63
65
|
<DropdownMenuV2.RadioItem
|
|
64
66
|
key={ key }
|
|
65
67
|
onChange={ () =>
|
|
@@ -75,10 +77,10 @@ function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
|
|
|
75
77
|
checked={ key === currentKey }
|
|
76
78
|
>
|
|
77
79
|
<DropdownMenuV2.ItemLabel>
|
|
78
|
-
{
|
|
80
|
+
{ args?.label }
|
|
79
81
|
</DropdownMenuV2.ItemLabel>
|
|
80
82
|
<DropdownMenuV2.ItemHelpText>
|
|
81
|
-
{ value }
|
|
83
|
+
{ args?.value }
|
|
82
84
|
</DropdownMenuV2.ItemHelpText>
|
|
83
85
|
</DropdownMenuV2.RadioItem>
|
|
84
86
|
) ) }
|
|
@@ -92,13 +94,13 @@ function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
|
|
|
92
94
|
);
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
function BlockBindingsAttribute( { attribute, binding } ) {
|
|
97
|
+
function BlockBindingsAttribute( { attribute, binding, fieldsList } ) {
|
|
96
98
|
const { source: sourceName, args } = binding || {};
|
|
97
99
|
const sourceProps =
|
|
98
100
|
unlock( blocksPrivateApis ).getBlockBindingsSource( sourceName );
|
|
99
101
|
const isSourceInvalid = ! sourceProps;
|
|
100
102
|
return (
|
|
101
|
-
<VStack className="block-editor-bindings__item">
|
|
103
|
+
<VStack className="block-editor-bindings__item" spacing={ 0 }>
|
|
102
104
|
<Text truncate>{ attribute }</Text>
|
|
103
105
|
{ !! binding && (
|
|
104
106
|
<Text
|
|
@@ -108,14 +110,16 @@ function BlockBindingsAttribute( { attribute, binding } ) {
|
|
|
108
110
|
>
|
|
109
111
|
{ isSourceInvalid
|
|
110
112
|
? __( 'Invalid source' )
|
|
111
|
-
: args?.key
|
|
113
|
+
: fieldsList?.[ sourceName ]?.[ args?.key ]?.label ||
|
|
114
|
+
sourceProps?.label ||
|
|
115
|
+
sourceName }
|
|
112
116
|
</Text>
|
|
113
117
|
) }
|
|
114
118
|
</VStack>
|
|
115
119
|
);
|
|
116
120
|
}
|
|
117
121
|
|
|
118
|
-
function ReadOnlyBlockBindingsPanelItems( { bindings } ) {
|
|
122
|
+
function ReadOnlyBlockBindingsPanelItems( { bindings, fieldsList } ) {
|
|
119
123
|
return (
|
|
120
124
|
<>
|
|
121
125
|
{ Object.entries( bindings ).map( ( [ attribute, binding ] ) => (
|
|
@@ -123,6 +127,7 @@ function ReadOnlyBlockBindingsPanelItems( { bindings } ) {
|
|
|
123
127
|
<BlockBindingsAttribute
|
|
124
128
|
attribute={ attribute }
|
|
125
129
|
binding={ binding }
|
|
130
|
+
fieldsList={ fieldsList }
|
|
126
131
|
/>
|
|
127
132
|
</Item>
|
|
128
133
|
) ) }
|
|
@@ -162,6 +167,7 @@ function EditableBlockBindingsPanelItems( {
|
|
|
162
167
|
<BlockBindingsAttribute
|
|
163
168
|
attribute={ attribute }
|
|
164
169
|
binding={ binding }
|
|
170
|
+
fieldsList={ fieldsList }
|
|
165
171
|
/>
|
|
166
172
|
</Item>
|
|
167
173
|
}
|
|
@@ -182,11 +188,60 @@ function EditableBlockBindingsPanelItems( {
|
|
|
182
188
|
export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
183
189
|
const registry = useRegistry();
|
|
184
190
|
const blockContext = useContext( BlockContext );
|
|
185
|
-
const { bindings } = metadata || {};
|
|
186
191
|
const { removeAllBlockBindings } = useBlockBindingsUtils();
|
|
187
192
|
const bindableAttributes = getBindableAttributes( blockName );
|
|
188
193
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
189
194
|
|
|
195
|
+
// `useSelect` is used purposely here to ensure `getFieldsList`
|
|
196
|
+
// is updated whenever there are updates in block context.
|
|
197
|
+
// `source.getFieldsList` may also call a selector via `registry.select`.
|
|
198
|
+
const _fieldsList = {};
|
|
199
|
+
const { fieldsList, canUpdateBlockBindings } = useSelect(
|
|
200
|
+
( select ) => {
|
|
201
|
+
if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
|
|
202
|
+
return EMPTY_OBJECT;
|
|
203
|
+
}
|
|
204
|
+
const { getBlockBindingsSources } = unlock( blocksPrivateApis );
|
|
205
|
+
const registeredSources = getBlockBindingsSources();
|
|
206
|
+
Object.entries( registeredSources ).forEach(
|
|
207
|
+
( [ sourceName, { getFieldsList, usesContext } ] ) => {
|
|
208
|
+
if ( getFieldsList ) {
|
|
209
|
+
// Populate context.
|
|
210
|
+
const context = {};
|
|
211
|
+
if ( usesContext?.length ) {
|
|
212
|
+
for ( const key of usesContext ) {
|
|
213
|
+
context[ key ] = blockContext[ key ];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const sourceList = getFieldsList( {
|
|
217
|
+
registry,
|
|
218
|
+
context,
|
|
219
|
+
} );
|
|
220
|
+
// Only add source if the list is not empty.
|
|
221
|
+
if ( Object.keys( sourceList || {} ).length ) {
|
|
222
|
+
_fieldsList[ sourceName ] = { ...sourceList };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
return {
|
|
228
|
+
fieldsList:
|
|
229
|
+
Object.values( _fieldsList ).length > 0
|
|
230
|
+
? _fieldsList
|
|
231
|
+
: EMPTY_OBJECT,
|
|
232
|
+
canUpdateBlockBindings:
|
|
233
|
+
select( blockEditorStore ).getSettings()
|
|
234
|
+
.canUpdateBlockBindings,
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
[ blockContext, bindableAttributes, registry ]
|
|
238
|
+
);
|
|
239
|
+
// Return early if there are no bindable attributes.
|
|
240
|
+
if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
// Filter bindings to only show bindable attributes and remove pattern overrides.
|
|
244
|
+
const { bindings } = metadata || {};
|
|
190
245
|
const filteredBindings = { ...bindings };
|
|
191
246
|
Object.keys( filteredBindings ).forEach( ( key ) => {
|
|
192
247
|
if (
|
|
@@ -197,48 +252,6 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
197
252
|
}
|
|
198
253
|
} );
|
|
199
254
|
|
|
200
|
-
const { canUpdateBlockBindings } = useSelect( ( select ) => {
|
|
201
|
-
return {
|
|
202
|
-
canUpdateBlockBindings:
|
|
203
|
-
select( blockEditorStore ).getSettings().canUpdateBlockBindings,
|
|
204
|
-
};
|
|
205
|
-
}, [] );
|
|
206
|
-
|
|
207
|
-
if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const fieldsList = {};
|
|
212
|
-
const { getBlockBindingsSources } = unlock( blocksPrivateApis );
|
|
213
|
-
const registeredSources = getBlockBindingsSources();
|
|
214
|
-
Object.entries( registeredSources ).forEach(
|
|
215
|
-
( [ sourceName, { getFieldsList, usesContext } ] ) => {
|
|
216
|
-
if ( getFieldsList ) {
|
|
217
|
-
// Populate context.
|
|
218
|
-
const context = {};
|
|
219
|
-
if ( usesContext?.length ) {
|
|
220
|
-
for ( const key of usesContext ) {
|
|
221
|
-
context[ key ] = blockContext[ key ];
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const sourceList = getFieldsList( {
|
|
225
|
-
registry,
|
|
226
|
-
context,
|
|
227
|
-
} );
|
|
228
|
-
// Only add source if the list is not empty.
|
|
229
|
-
if ( sourceList ) {
|
|
230
|
-
fieldsList[ sourceName ] = { ...sourceList };
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
);
|
|
235
|
-
// Remove empty sources.
|
|
236
|
-
Object.entries( fieldsList ).forEach( ( [ key, value ] ) => {
|
|
237
|
-
if ( ! Object.keys( value ).length ) {
|
|
238
|
-
delete fieldsList[ key ];
|
|
239
|
-
}
|
|
240
|
-
} );
|
|
241
|
-
|
|
242
255
|
// Lock the UI when the user can't update bindings or there are no fields to connect to.
|
|
243
256
|
const readOnly =
|
|
244
257
|
! canUpdateBlockBindings || ! Object.keys( fieldsList ).length;
|
|
@@ -261,6 +274,7 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
261
274
|
{ readOnly ? (
|
|
262
275
|
<ReadOnlyBlockBindingsPanelItems
|
|
263
276
|
bindings={ filteredBindings }
|
|
277
|
+
fieldsList={ fieldsList }
|
|
264
278
|
/>
|
|
265
279
|
) : (
|
|
266
280
|
<EditableBlockBindingsPanelItems
|
package/src/hooks/block-hooks.js
CHANGED
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { Fragment, useMemo } from '@wordpress/element';
|
|
6
|
-
import {
|
|
7
|
-
__experimentalHStack as HStack,
|
|
8
|
-
PanelBody,
|
|
9
|
-
ToggleControl,
|
|
10
|
-
} from '@wordpress/components';
|
|
6
|
+
import { PanelBody, ToggleControl } from '@wordpress/components';
|
|
11
7
|
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
12
8
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Internal dependencies
|
|
16
12
|
*/
|
|
17
|
-
import {
|
|
13
|
+
import { InspectorControls } from '../components';
|
|
18
14
|
import { store as blockEditorStore } from '../store';
|
|
19
15
|
|
|
20
16
|
const EMPTY_OBJECT = {};
|
|
@@ -204,14 +200,7 @@ function BlockHooksControlPure( {
|
|
|
204
200
|
__nextHasNoMarginBottom
|
|
205
201
|
checked={ checked }
|
|
206
202
|
key={ block.title }
|
|
207
|
-
label={
|
|
208
|
-
<HStack justify="flex-start">
|
|
209
|
-
<BlockIcon
|
|
210
|
-
icon={ block.icon }
|
|
211
|
-
/>
|
|
212
|
-
<span>{ block.title }</span>
|
|
213
|
-
</HStack>
|
|
214
|
-
}
|
|
203
|
+
label={ block.title }
|
|
215
204
|
onChange={ () => {
|
|
216
205
|
if ( ! checked ) {
|
|
217
206
|
// Create and insert block.
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
.block-editor-hooks__block-hooks {
|
|
2
|
-
/**
|
|
3
|
-
* Since we're displaying the block icon alongside the block name,
|
|
4
|
-
* we need to right-align the toggle.
|
|
5
|
-
*/
|
|
6
|
-
.components-toggle-control .components-h-stack {
|
|
7
|
-
/* stylelint-disable-next-line declaration-property-value-allowed-list -- This should be refactored to not use the row-reverse value. */
|
|
8
|
-
flex-direction: row-reverse;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
2
|
/**
|
|
12
3
|
* Un-reverse the flex direction for the toggle's label.
|
|
13
4
|
*/
|
|
@@ -548,6 +548,15 @@ export function isZoomOutMode( state ) {
|
|
|
548
548
|
return state.editorMode === 'zoom-out';
|
|
549
549
|
}
|
|
550
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Retrieves the client ID of the block which contains the blocks
|
|
553
|
+
* acting as "sections" in the editor. This is typically the "main content"
|
|
554
|
+
* of the template/post.
|
|
555
|
+
*
|
|
556
|
+
* @param {Object} state Editor state.
|
|
557
|
+
*
|
|
558
|
+
* @return {string|undefined} The section root client ID or undefined if not set.
|
|
559
|
+
*/
|
|
551
560
|
export function getSectionRootClientId( state ) {
|
|
552
561
|
return state.settings?.[ sectionRootClientIdKey ];
|
|
553
562
|
}
|
package/src/style.scss
CHANGED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = SidesDropdown;
|
|
7
|
-
var _components = require("@wordpress/components");
|
|
8
|
-
var _icons = require("@wordpress/icons");
|
|
9
|
-
var _utils = require("../utils");
|
|
10
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
-
/**
|
|
12
|
-
* WordPress dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Internal dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const checkIcon = /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
20
|
-
icon: _icons.check,
|
|
21
|
-
size: 24
|
|
22
|
-
});
|
|
23
|
-
function SidesDropdown({
|
|
24
|
-
label: labelProp,
|
|
25
|
-
onChange,
|
|
26
|
-
sides,
|
|
27
|
-
value
|
|
28
|
-
}) {
|
|
29
|
-
if (!sides || !sides.length) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const supportedItems = (0, _utils.getSupportedMenuItems)(sides);
|
|
33
|
-
const sideIcon = supportedItems[value].icon;
|
|
34
|
-
const {
|
|
35
|
-
custom: customItem,
|
|
36
|
-
...menuItems
|
|
37
|
-
} = supportedItems;
|
|
38
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
39
|
-
icon: sideIcon,
|
|
40
|
-
label: labelProp,
|
|
41
|
-
className: "spacing-sizes-control__dropdown",
|
|
42
|
-
toggleProps: {
|
|
43
|
-
size: 'small'
|
|
44
|
-
},
|
|
45
|
-
children: ({
|
|
46
|
-
onClose
|
|
47
|
-
}) => {
|
|
48
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
49
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuGroup, {
|
|
50
|
-
children: Object.entries(menuItems).map(([slug, {
|
|
51
|
-
label,
|
|
52
|
-
icon
|
|
53
|
-
}]) => {
|
|
54
|
-
const isSelected = value === slug;
|
|
55
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
|
|
56
|
-
icon: icon,
|
|
57
|
-
iconPosition: "left",
|
|
58
|
-
isSelected: isSelected,
|
|
59
|
-
role: "menuitemradio",
|
|
60
|
-
onClick: () => {
|
|
61
|
-
onChange(slug);
|
|
62
|
-
onClose();
|
|
63
|
-
},
|
|
64
|
-
suffix: isSelected ? checkIcon : undefined,
|
|
65
|
-
children: label
|
|
66
|
-
}, slug);
|
|
67
|
-
})
|
|
68
|
-
}), !!customItem && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuGroup, {
|
|
69
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
|
|
70
|
-
icon: customItem.icon,
|
|
71
|
-
iconPosition: "left",
|
|
72
|
-
isSelected: value === _utils.VIEWS.custom,
|
|
73
|
-
role: "menuitemradio",
|
|
74
|
-
onClick: () => {
|
|
75
|
-
onChange(_utils.VIEWS.custom);
|
|
76
|
-
onClose();
|
|
77
|
-
},
|
|
78
|
-
suffix: value === _utils.VIEWS.custom ? checkIcon : undefined,
|
|
79
|
-
children: customItem.label
|
|
80
|
-
})
|
|
81
|
-
})]
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_icons","_utils","_jsxRuntime","checkIcon","jsx","Icon","icon","check","size","SidesDropdown","label","labelProp","onChange","sides","value","length","supportedItems","getSupportedMenuItems","sideIcon","custom","customItem","menuItems","DropdownMenu","className","toggleProps","children","onClose","jsxs","Fragment","MenuGroup","Object","entries","map","slug","isSelected","MenuItem","iconPosition","role","onClick","suffix","undefined","VIEWS"],"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/sides-dropdown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { DropdownMenu, Icon, MenuGroup, MenuItem } from '@wordpress/components';\nimport { check } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getSupportedMenuItems, VIEWS } from '../utils';\n\nconst checkIcon = <Icon icon={ check } size={ 24 } />;\n\nexport default function SidesDropdown( {\n\tlabel: labelProp,\n\tonChange,\n\tsides,\n\tvalue,\n} ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn;\n\t}\n\n\tconst supportedItems = getSupportedMenuItems( sides );\n\tconst sideIcon = supportedItems[ value ].icon;\n\tconst { custom: customItem, ...menuItems } = supportedItems;\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ sideIcon }\n\t\t\tlabel={ labelProp }\n\t\t\tclassName=\"spacing-sizes-control__dropdown\"\n\t\t\ttoggleProps={ { size: 'small' } }\n\t\t>\n\t\t\t{ ( { onClose } ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t{ Object.entries( menuItems ).map(\n\t\t\t\t\t\t\t\t( [ slug, { label, icon } ] ) => {\n\t\t\t\t\t\t\t\t\tconst isSelected = value === slug;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange( slug );\n\t\t\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\tsuffix={\n\t\t\t\t\t\t\t\t\t\t\t\tisSelected\n\t\t\t\t\t\t\t\t\t\t\t\t\t? checkIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t{ !! customItem && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ customItem.icon }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tisSelected={ value === VIEWS.custom }\n\t\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChange( VIEWS.custom );\n\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsuffix={\n\t\t\t\t\t\t\t\t\t\tvalue === VIEWS.custom\n\t\t\t\t\t\t\t\t\t\t\t? checkIcon\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ customItem.label }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t);\n\t\t\t} }\n\t\t</DropdownMenu>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AAAwD,IAAAG,WAAA,GAAAH,OAAA;AATxD;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMI,SAAS,gBAAG,IAAAD,WAAA,CAAAE,GAAA,EAACN,WAAA,CAAAO,IAAI;EAACC,IAAI,EAAGC,YAAO;EAACC,IAAI,EAAG;AAAI,CAAE,CAAC;AAEtC,SAASC,aAAaA,CAAE;EACtCC,KAAK,EAAEC,SAAS;EAChBC,QAAQ;EACRC,KAAK;EACLC;AACD,CAAC,EAAG;EACH,IAAK,CAAED,KAAK,IAAI,CA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ACS,CAAC,EACV,CAAC,CAAEb,UAAU,iBACd,IAAAlB,WAAA,CAAAE,GAAA,EAACN,WAAA,CAAA+B,SAAS;UAAAJ,QAAA,eACT,IAAAvB,WAAA,CAAAE,GAAA,EAACN,WAAA,CAAAqC,QAAQ;YACR7B,IAAI,EAAGc,UAAU,CAACd,IAAM;YACxB8B,YAAY,EAAC,MAAM;YACnBF,UAAU,EAAGpB,KAAK,KAAK2B,YAAK,CAACtB,MAAQ;YACrCkB,IAAI,EAAC,eAAe;YACpBC,OAAO,EAAGA,CAAA,KAAM;cACf1B,QAAQ,CAAE6B,YAAK,CAACtB,MAAO,CAAC;cACxBO,OAAO,CAAC,CAAC;YACV,CAAG;YACHa,MAAM,EACLzB,KAAK,KAAK2B,YAAK,CAACtB,MAAM,GACnBhB,SAAS,GACTqC,SACH;YAAAf,QAAA,EAECL,UAAU,CAACV;UAAK,CACT;QAAC,CACD,CACX;MAAA,CACA,CAAC;IAEL;EAAC,CACY,CAAC;AAEjB","ignoreList":[]}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { DropdownMenu, Icon, MenuGroup, MenuItem } from '@wordpress/components';
|
|
5
|
-
import { check } from '@wordpress/icons';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { getSupportedMenuItems, VIEWS } from '../utils';
|
|
11
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
const checkIcon = /*#__PURE__*/_jsx(Icon, {
|
|
15
|
-
icon: check,
|
|
16
|
-
size: 24
|
|
17
|
-
});
|
|
18
|
-
export default function SidesDropdown({
|
|
19
|
-
label: labelProp,
|
|
20
|
-
onChange,
|
|
21
|
-
sides,
|
|
22
|
-
value
|
|
23
|
-
}) {
|
|
24
|
-
if (!sides || !sides.length) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const supportedItems = getSupportedMenuItems(sides);
|
|
28
|
-
const sideIcon = supportedItems[value].icon;
|
|
29
|
-
const {
|
|
30
|
-
custom: customItem,
|
|
31
|
-
...menuItems
|
|
32
|
-
} = supportedItems;
|
|
33
|
-
return /*#__PURE__*/_jsx(DropdownMenu, {
|
|
34
|
-
icon: sideIcon,
|
|
35
|
-
label: labelProp,
|
|
36
|
-
className: "spacing-sizes-control__dropdown",
|
|
37
|
-
toggleProps: {
|
|
38
|
-
size: 'small'
|
|
39
|
-
},
|
|
40
|
-
children: ({
|
|
41
|
-
onClose
|
|
42
|
-
}) => {
|
|
43
|
-
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
44
|
-
children: [/*#__PURE__*/_jsx(MenuGroup, {
|
|
45
|
-
children: Object.entries(menuItems).map(([slug, {
|
|
46
|
-
label,
|
|
47
|
-
icon
|
|
48
|
-
}]) => {
|
|
49
|
-
const isSelected = value === slug;
|
|
50
|
-
return /*#__PURE__*/_jsx(MenuItem, {
|
|
51
|
-
icon: icon,
|
|
52
|
-
iconPosition: "left",
|
|
53
|
-
isSelected: isSelected,
|
|
54
|
-
role: "menuitemradio",
|
|
55
|
-
onClick: () => {
|
|
56
|
-
onChange(slug);
|
|
57
|
-
onClose();
|
|
58
|
-
},
|
|
59
|
-
suffix: isSelected ? checkIcon : undefined,
|
|
60
|
-
children: label
|
|
61
|
-
}, slug);
|
|
62
|
-
})
|
|
63
|
-
}), !!customItem && /*#__PURE__*/_jsx(MenuGroup, {
|
|
64
|
-
children: /*#__PURE__*/_jsx(MenuItem, {
|
|
65
|
-
icon: customItem.icon,
|
|
66
|
-
iconPosition: "left",
|
|
67
|
-
isSelected: value === VIEWS.custom,
|
|
68
|
-
role: "menuitemradio",
|
|
69
|
-
onClick: () => {
|
|
70
|
-
onChange(VIEWS.custom);
|
|
71
|
-
onClose();
|
|
72
|
-
},
|
|
73
|
-
suffix: value === VIEWS.custom ? checkIcon : undefined,
|
|
74
|
-
children: customItem.label
|
|
75
|
-
})
|
|
76
|
-
})]
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["DropdownMenu","Icon","MenuGroup","MenuItem","check","getSupportedMenuItems","VIEWS","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","checkIcon","icon","size","SidesDropdown","label","labelProp","onChange","sides","value","length","supportedItems","sideIcon","custom","customItem","menuItems","className","toggleProps","children","onClose","Object","entries","map","slug","isSelected","iconPosition","role","onClick","suffix","undefined"],"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/sides-dropdown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { DropdownMenu, Icon, MenuGroup, MenuItem } from '@wordpress/components';\nimport { check } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getSupportedMenuItems, VIEWS } from '../utils';\n\nconst checkIcon = <Icon icon={ check } size={ 24 } />;\n\nexport default function SidesDropdown( {\n\tlabel: labelProp,\n\tonChange,\n\tsides,\n\tvalue,\n} ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn;\n\t}\n\n\tconst supportedItems = getSupportedMenuItems( sides );\n\tconst sideIcon = supportedItems[ value ].icon;\n\tconst { custom: customItem, ...menuItems } = supportedItems;\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ sideIcon }\n\t\t\tlabel={ labelProp }\n\t\t\tclassName=\"spacing-sizes-control__dropdown\"\n\t\t\ttoggleProps={ { size: 'small' } }\n\t\t>\n\t\t\t{ ( { onClose } ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t{ Object.entries( menuItems ).map(\n\t\t\t\t\t\t\t\t( [ slug, { label, icon } ] ) => {\n\t\t\t\t\t\t\t\t\tconst isSelected = value === slug;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange( slug );\n\t\t\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\tsuffix={\n\t\t\t\t\t\t\t\t\t\t\t\tisSelected\n\t\t\t\t\t\t\t\t\t\t\t\t\t? checkIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t{ !! customItem && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ customItem.icon }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tisSelected={ value === VIEWS.custom }\n\t\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChange( VIEWS.custom );\n\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsu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