@wordpress/block-library 6.0.25 → 6.0.26
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/gallery/constants.js +5 -1
- package/build/gallery/constants.js.map +1 -1
- package/build/gallery/transforms.js +8 -2
- package/build/gallery/transforms.js.map +1 -1
- package/build/gallery/utils.js +4 -3
- package/build/gallery/utils.js.map +1 -1
- package/build/heading/edit.js +14 -2
- package/build/heading/edit.js.map +1 -1
- package/build/page-list/edit.js +37 -10
- package/build/page-list/edit.js.map +1 -1
- package/build/post-featured-image/dimension-controls.js +50 -30
- package/build/post-featured-image/dimension-controls.js.map +1 -1
- package/build/post-featured-image/edit.js +4 -2
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/site-logo/edit.js +0 -25
- package/build/site-logo/edit.js.map +1 -1
- package/build/social-links/deprecated.js +1 -62
- package/build/social-links/deprecated.js.map +1 -1
- package/build/social-links/edit.js +1 -1
- package/build/social-links/edit.js.map +1 -1
- package/build/spacer/controls.js +111 -0
- package/build/spacer/controls.js.map +1 -0
- package/build/spacer/controls.native.js +95 -0
- package/build/spacer/controls.native.js.map +1 -0
- package/build/spacer/deprecated.js +53 -0
- package/build/spacer/deprecated.js.map +1 -0
- package/build/spacer/edit.js +111 -82
- package/build/spacer/edit.js.map +1 -1
- package/build/spacer/edit.native.js +76 -0
- package/build/spacer/edit.native.js.map +1 -0
- package/build/spacer/index.js +7 -4
- package/build/spacer/index.js.map +1 -1
- package/build/spacer/save.js +6 -3
- package/build/spacer/save.js.map +1 -1
- package/build-module/gallery/constants.js +2 -0
- package/build-module/gallery/constants.js.map +1 -1
- package/build-module/gallery/transforms.js +8 -2
- package/build-module/gallery/transforms.js.map +1 -1
- package/build-module/gallery/utils.js +5 -4
- package/build-module/gallery/utils.js.map +1 -1
- package/build-module/heading/edit.js +15 -3
- package/build-module/heading/edit.js.map +1 -1
- package/build-module/page-list/edit.js +38 -11
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/post-featured-image/dimension-controls.js +52 -29
- package/build-module/post-featured-image/dimension-controls.js.map +1 -1
- package/build-module/post-featured-image/edit.js +4 -2
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/site-logo/edit.js +0 -25
- package/build-module/site-logo/edit.js.map +1 -1
- package/build-module/social-links/deprecated.js +1 -62
- package/build-module/social-links/deprecated.js.map +1 -1
- package/build-module/social-links/edit.js +1 -1
- package/build-module/social-links/edit.js.map +1 -1
- package/build-module/spacer/controls.js +101 -0
- package/build-module/spacer/controls.js.map +1 -0
- package/build-module/spacer/controls.native.js +82 -0
- package/build-module/spacer/controls.native.js.map +1 -0
- package/build-module/spacer/deprecated.js +44 -0
- package/build-module/spacer/deprecated.js.map +1 -0
- package/build-module/spacer/edit.js +108 -82
- package/build-module/spacer/edit.js.map +1 -1
- package/build-module/spacer/edit.native.js +61 -0
- package/build-module/spacer/edit.native.js.map +1 -0
- package/build-module/spacer/index.js +6 -4
- package/build-module/spacer/index.js.map +1 -1
- package/build-module/spacer/save.js +6 -3
- package/build-module/spacer/save.js.map +1 -1
- package/build-style/common-rtl.css +8 -0
- package/build-style/common.css +8 -0
- package/build-style/cover/style-rtl.css +60 -0
- package/build-style/cover/style.css +60 -0
- package/build-style/editor-rtl.css +8 -7
- package/build-style/editor.css +8 -7
- package/build-style/gallery/style-rtl.css +2 -1
- package/build-style/gallery/style.css +2 -1
- package/build-style/image/style-rtl.css +0 -2
- package/build-style/image/style.css +0 -2
- package/build-style/page-list/editor-rtl.css +4 -0
- package/build-style/page-list/editor.css +4 -0
- package/build-style/post-featured-image/editor-rtl.css +0 -7
- package/build-style/post-featured-image/editor.css +0 -7
- package/build-style/post-template/style-rtl.css +4 -0
- package/build-style/post-template/style.css +4 -0
- package/build-style/spacer/editor-rtl.css +4 -0
- package/build-style/spacer/editor.css +4 -0
- package/build-style/style-rtl.css +74 -3
- package/build-style/style.css +74 -3
- package/package.json +7 -7
- package/src/common.scss +8 -0
- package/src/cover/style.scss +13 -0
- package/src/gallery/constants.js +2 -0
- package/src/gallery/style.scss +4 -1
- package/src/gallery/transforms.js +7 -1
- package/src/gallery/utils.js +7 -3
- package/src/heading/edit.js +18 -5
- package/src/image/style.scss +0 -2
- package/src/page-list/edit.js +47 -9
- package/src/page-list/editor.scss +4 -0
- package/src/page-list/index.php +5 -0
- package/src/post-featured-image/dimension-controls.js +75 -50
- package/src/post-featured-image/edit.js +6 -4
- package/src/post-featured-image/editor.scss +0 -8
- package/src/post-template/style.scss +5 -0
- package/src/search/index.php +6 -4
- package/src/site-logo/edit.js +1 -32
- package/src/site-logo/index.php +1 -1
- package/src/site-title/index.php +0 -1
- package/src/social-links/deprecated.js +0 -59
- package/src/social-links/edit.js +1 -1
- package/src/spacer/block.json +3 -3
- package/src/spacer/controls.js +108 -0
- package/src/spacer/controls.native.js +82 -0
- package/src/spacer/deprecated.js +41 -0
- package/src/spacer/edit.js +127 -113
- package/src/spacer/edit.native.js +68 -0
- package/src/spacer/editor.scss +6 -0
- package/src/spacer/index.js +2 -0
- package/src/spacer/save.js +5 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { InspectorControls, useSetting } from '@wordpress/block-editor';
|
|
6
|
+
import {
|
|
7
|
+
BaseControl,
|
|
8
|
+
PanelBody,
|
|
9
|
+
__experimentalUseCustomUnits as useCustomUnits,
|
|
10
|
+
__experimentalUnitControl as UnitControl,
|
|
11
|
+
} from '@wordpress/components';
|
|
12
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
13
|
+
import { useState } from '@wordpress/element';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
import { MAX_SPACER_SIZE } from './edit';
|
|
19
|
+
|
|
20
|
+
function DimensionInput( { label, onChange, isResizing, value = '' } ) {
|
|
21
|
+
const [ temporaryInput, setTemporaryInput ] = useState( null );
|
|
22
|
+
|
|
23
|
+
const inputId = useInstanceId( UnitControl, 'block-spacer-height-input' );
|
|
24
|
+
|
|
25
|
+
// In most contexts the spacer size cannot meaningfully be set to a
|
|
26
|
+
// percentage, since this is relative to the parent container. This
|
|
27
|
+
// unit is disabled from the UI.
|
|
28
|
+
const availableUnitSettings = (
|
|
29
|
+
useSetting( 'spacing.units' ) || undefined
|
|
30
|
+
)?.filter( ( availableUnit ) => availableUnit !== '%' );
|
|
31
|
+
|
|
32
|
+
const units = useCustomUnits( {
|
|
33
|
+
availableUnits: availableUnitSettings || [
|
|
34
|
+
'px',
|
|
35
|
+
'em',
|
|
36
|
+
'rem',
|
|
37
|
+
'vw',
|
|
38
|
+
'vh',
|
|
39
|
+
],
|
|
40
|
+
defaultValues: { px: '100', em: '10', rem: '10', vw: '10', vh: '25' },
|
|
41
|
+
} );
|
|
42
|
+
|
|
43
|
+
const handleOnChange = ( unprocessedValue ) => {
|
|
44
|
+
setTemporaryInput( null );
|
|
45
|
+
onChange( unprocessedValue );
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleOnBlur = () => {
|
|
49
|
+
if ( temporaryInput !== null ) {
|
|
50
|
+
setTemporaryInput( null );
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const inputValue = temporaryInput !== null ? temporaryInput : value;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<BaseControl label={ label } id={ inputId }>
|
|
58
|
+
<UnitControl
|
|
59
|
+
id={ inputId }
|
|
60
|
+
isResetValueOnUnitChange
|
|
61
|
+
min={ 0 }
|
|
62
|
+
max={ MAX_SPACER_SIZE }
|
|
63
|
+
onBlur={ handleOnBlur }
|
|
64
|
+
onChange={ handleOnChange }
|
|
65
|
+
style={ { maxWidth: 80 } }
|
|
66
|
+
value={ inputValue }
|
|
67
|
+
units={ units }
|
|
68
|
+
// Force the unit to update to `px` when the Spacer is being resized.
|
|
69
|
+
unit={ isResizing ? 'px' : undefined }
|
|
70
|
+
/>
|
|
71
|
+
</BaseControl>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default function SpacerControls( {
|
|
76
|
+
setAttributes,
|
|
77
|
+
orientation,
|
|
78
|
+
height,
|
|
79
|
+
width,
|
|
80
|
+
isResizing,
|
|
81
|
+
} ) {
|
|
82
|
+
return (
|
|
83
|
+
<InspectorControls>
|
|
84
|
+
<PanelBody title={ __( 'Spacer settings' ) }>
|
|
85
|
+
{ orientation === 'horizontal' && (
|
|
86
|
+
<DimensionInput
|
|
87
|
+
label={ __( 'Width' ) }
|
|
88
|
+
value={ width }
|
|
89
|
+
onChange={ ( nextWidth ) =>
|
|
90
|
+
setAttributes( { width: nextWidth } )
|
|
91
|
+
}
|
|
92
|
+
isResizing={ isResizing }
|
|
93
|
+
/>
|
|
94
|
+
) }
|
|
95
|
+
{ orientation !== 'horizontal' && (
|
|
96
|
+
<DimensionInput
|
|
97
|
+
label={ __( 'Height' ) }
|
|
98
|
+
value={ height }
|
|
99
|
+
onChange={ ( nextHeight ) =>
|
|
100
|
+
setAttributes( { height: nextHeight } )
|
|
101
|
+
}
|
|
102
|
+
isResizing={ isResizing }
|
|
103
|
+
/>
|
|
104
|
+
) }
|
|
105
|
+
</PanelBody>
|
|
106
|
+
</InspectorControls>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
PanelBody,
|
|
6
|
+
UnitControl,
|
|
7
|
+
getValueAndUnit,
|
|
8
|
+
__experimentalUseCustomUnits as useCustomUnits,
|
|
9
|
+
} from '@wordpress/components';
|
|
10
|
+
import { useCallback } from '@wordpress/element';
|
|
11
|
+
import { useSetting } from '@wordpress/block-editor';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import styles from './style.scss';
|
|
18
|
+
|
|
19
|
+
const DEFAULT_VALUES = { px: '100', em: '10', rem: '10', vw: '10', vh: '25' };
|
|
20
|
+
|
|
21
|
+
function Controls( { attributes, context, setAttributes } ) {
|
|
22
|
+
const { orientation } = context;
|
|
23
|
+
const label = orientation !== 'horizontal' ? __( 'Height' ) : __( 'Width' );
|
|
24
|
+
|
|
25
|
+
const { height, width } = attributes;
|
|
26
|
+
const { valueToConvert, valueUnit: unit } =
|
|
27
|
+
getValueAndUnit( orientation !== 'horizontal' ? height : width ) || {};
|
|
28
|
+
const value = Number( valueToConvert );
|
|
29
|
+
|
|
30
|
+
const setNewDimensions = ( nextValue, nextUnit ) => {
|
|
31
|
+
const valueWithUnit = `${ nextValue }${ nextUnit }`;
|
|
32
|
+
if ( orientation === 'horizontal' ) {
|
|
33
|
+
setAttributes( { width: valueWithUnit } );
|
|
34
|
+
} else {
|
|
35
|
+
setAttributes( { height: valueWithUnit } );
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleChange = useCallback(
|
|
40
|
+
( nextValue ) => {
|
|
41
|
+
setNewDimensions( nextValue, unit );
|
|
42
|
+
},
|
|
43
|
+
[ height, width ]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const handleUnitChange = useCallback(
|
|
47
|
+
( nextUnit ) => {
|
|
48
|
+
setNewDimensions( value, nextUnit );
|
|
49
|
+
},
|
|
50
|
+
[ height, width ]
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const units = useCustomUnits( {
|
|
54
|
+
availableUnits: useSetting( 'spacing.units' ) || [
|
|
55
|
+
'px',
|
|
56
|
+
'em',
|
|
57
|
+
'rem',
|
|
58
|
+
'vw',
|
|
59
|
+
'vh',
|
|
60
|
+
],
|
|
61
|
+
defaultValues: DEFAULT_VALUES,
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
<PanelBody title={ __( 'Dimensions' ) }>
|
|
67
|
+
<UnitControl
|
|
68
|
+
label={ label }
|
|
69
|
+
min={ 1 }
|
|
70
|
+
value={ value }
|
|
71
|
+
onChange={ handleChange }
|
|
72
|
+
onUnitChange={ handleUnitChange }
|
|
73
|
+
units={ units }
|
|
74
|
+
unit={ unit }
|
|
75
|
+
style={ styles.rangeCellContainer }
|
|
76
|
+
/>
|
|
77
|
+
</PanelBody>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default Controls;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useBlockProps } from '@wordpress/block-editor';
|
|
5
|
+
|
|
6
|
+
const deprecated = [
|
|
7
|
+
{
|
|
8
|
+
attributes: {
|
|
9
|
+
height: {
|
|
10
|
+
type: 'number',
|
|
11
|
+
default: 100,
|
|
12
|
+
},
|
|
13
|
+
width: {
|
|
14
|
+
type: 'number',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
migrate( attributes ) {
|
|
18
|
+
const { height, width } = attributes;
|
|
19
|
+
return {
|
|
20
|
+
...attributes,
|
|
21
|
+
width: width !== undefined ? `${ width }px` : undefined,
|
|
22
|
+
height: height !== undefined ? `${ height }px` : undefined,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
save( { attributes } ) {
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
{ ...useBlockProps.save( {
|
|
29
|
+
style: {
|
|
30
|
+
height: attributes.height,
|
|
31
|
+
width: attributes.width,
|
|
32
|
+
},
|
|
33
|
+
'aria-hidden': true,
|
|
34
|
+
} ) }
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
export default deprecated;
|
package/src/spacer/edit.js
CHANGED
|
@@ -6,23 +6,81 @@ import classnames from 'classnames';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { __ } from '@wordpress/i18n';
|
|
10
9
|
import {
|
|
11
|
-
InspectorControls,
|
|
12
10
|
useBlockProps,
|
|
13
11
|
store as blockEditorStore,
|
|
14
12
|
} from '@wordpress/block-editor';
|
|
15
|
-
import {
|
|
13
|
+
import { ResizableBox } from '@wordpress/components';
|
|
16
14
|
import { compose, withInstanceId } from '@wordpress/compose';
|
|
17
15
|
import { withDispatch } from '@wordpress/data';
|
|
18
16
|
import { useState, useEffect } from '@wordpress/element';
|
|
19
17
|
import { View } from '@wordpress/primitives';
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import SpacerControls from './controls';
|
|
23
|
+
|
|
24
|
+
export const MIN_SPACER_SIZE = 1;
|
|
25
|
+
export const MAX_SPACER_SIZE = 500;
|
|
26
|
+
|
|
27
|
+
const ResizableSpacer = ( {
|
|
28
|
+
orientation,
|
|
29
|
+
onResizeStart,
|
|
30
|
+
onResize,
|
|
31
|
+
onResizeStop,
|
|
32
|
+
isSelected,
|
|
33
|
+
isResizing,
|
|
34
|
+
setIsResizing,
|
|
35
|
+
...props
|
|
36
|
+
} ) => {
|
|
37
|
+
const getCurrentSize = ( elt ) => {
|
|
38
|
+
return orientation === 'horizontal'
|
|
39
|
+
? elt.clientWidth
|
|
40
|
+
: elt.clientHeight;
|
|
41
|
+
};
|
|
23
42
|
|
|
24
|
-
const
|
|
25
|
-
|
|
43
|
+
const getNextVal = ( elt ) => {
|
|
44
|
+
return `${ getCurrentSize( elt ) }px`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ResizableBox
|
|
49
|
+
className={ classnames( 'block-library-spacer__resize-container', {
|
|
50
|
+
'resize-horizontal': orientation === 'horizontal',
|
|
51
|
+
'is-resizing': isResizing,
|
|
52
|
+
'is-selected': isSelected,
|
|
53
|
+
} ) }
|
|
54
|
+
onResizeStart={ ( _event, _direction, elt ) => {
|
|
55
|
+
const nextVal = getNextVal( elt );
|
|
56
|
+
onResizeStart( nextVal );
|
|
57
|
+
onResize( nextVal );
|
|
58
|
+
} }
|
|
59
|
+
onResize={ ( _event, _direction, elt ) => {
|
|
60
|
+
onResize( getNextVal( elt ) );
|
|
61
|
+
if ( ! isResizing ) {
|
|
62
|
+
setIsResizing( true );
|
|
63
|
+
}
|
|
64
|
+
} }
|
|
65
|
+
onResizeStop={ ( _event, _direction, elt ) => {
|
|
66
|
+
const nextVal = Math.min(
|
|
67
|
+
MAX_SPACER_SIZE,
|
|
68
|
+
getCurrentSize( elt )
|
|
69
|
+
);
|
|
70
|
+
onResizeStop( `${ nextVal }px` );
|
|
71
|
+
setIsResizing( false );
|
|
72
|
+
} }
|
|
73
|
+
__experimentalShowTooltip={ true }
|
|
74
|
+
__experimentalTooltipProps={ {
|
|
75
|
+
axis: orientation === 'horizontal' ? 'x' : 'y',
|
|
76
|
+
position: 'corner',
|
|
77
|
+
isVisible: isResizing,
|
|
78
|
+
} }
|
|
79
|
+
showHandle={ isSelected }
|
|
80
|
+
{ ...props }
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
26
84
|
|
|
27
85
|
const SpacerEdit = ( {
|
|
28
86
|
attributes,
|
|
@@ -33,60 +91,41 @@ const SpacerEdit = ( {
|
|
|
33
91
|
context,
|
|
34
92
|
} ) => {
|
|
35
93
|
const { orientation } = context;
|
|
36
|
-
const [ isResizing, setIsResizing ] = useState( false );
|
|
37
94
|
const { height, width } = attributes;
|
|
38
|
-
const updateHeight = ( value ) => {
|
|
39
|
-
setAttributes( {
|
|
40
|
-
height: value,
|
|
41
|
-
} );
|
|
42
|
-
};
|
|
43
|
-
const updateWidth = ( value ) => {
|
|
44
|
-
setAttributes( {
|
|
45
|
-
width: value,
|
|
46
|
-
} );
|
|
47
|
-
};
|
|
48
95
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
96
|
+
const [ isResizing, setIsResizing ] = useState( false );
|
|
97
|
+
const [ temporaryHeight, setTemporaryHeight ] = useState( null );
|
|
98
|
+
const [ temporaryWidth, setTemporaryWidth ] = useState( null );
|
|
53
99
|
|
|
54
|
-
const handleOnVerticalResizeStop = (
|
|
100
|
+
const handleOnVerticalResizeStop = ( newHeight ) => {
|
|
55
101
|
onResizeStop();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
);
|
|
60
|
-
updateHeight( spacerHeight );
|
|
61
|
-
setIsResizing( false );
|
|
102
|
+
|
|
103
|
+
setAttributes( { height: newHeight } );
|
|
104
|
+
setTemporaryHeight( null );
|
|
62
105
|
};
|
|
63
106
|
|
|
64
|
-
const handleOnHorizontalResizeStop = (
|
|
107
|
+
const handleOnHorizontalResizeStop = ( newWidth ) => {
|
|
65
108
|
onResizeStop();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
109
|
+
setAttributes( { width: newWidth } );
|
|
110
|
+
setTemporaryWidth( null );
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const style = {
|
|
114
|
+
height:
|
|
115
|
+
orientation === 'horizontal'
|
|
116
|
+
? 24
|
|
117
|
+
: temporaryHeight || height || undefined,
|
|
118
|
+
width:
|
|
119
|
+
orientation === 'horizontal'
|
|
120
|
+
? temporaryWidth || width || undefined
|
|
121
|
+
: undefined,
|
|
72
122
|
};
|
|
73
123
|
|
|
74
124
|
const resizableBoxWithOrientation = ( blockOrientation ) => {
|
|
75
125
|
if ( blockOrientation === 'horizontal' ) {
|
|
76
126
|
return (
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
'block-library-spacer__resize-container',
|
|
80
|
-
'resize-horizontal',
|
|
81
|
-
{
|
|
82
|
-
'is-selected': isSelected,
|
|
83
|
-
}
|
|
84
|
-
) }
|
|
85
|
-
size={ {
|
|
86
|
-
width,
|
|
87
|
-
height: 24,
|
|
88
|
-
} }
|
|
89
|
-
minWidth={ MIN_SPACER_WIDTH }
|
|
127
|
+
<ResizableSpacer
|
|
128
|
+
minWidth={ MIN_SPACER_SIZE }
|
|
90
129
|
enable={ {
|
|
91
130
|
top: false,
|
|
92
131
|
right: true,
|
|
@@ -97,88 +136,63 @@ const SpacerEdit = ( {
|
|
|
97
136
|
bottomLeft: false,
|
|
98
137
|
topLeft: false,
|
|
99
138
|
} }
|
|
100
|
-
|
|
139
|
+
orientation={ blockOrientation }
|
|
140
|
+
onResizeStart={ onResizeStart }
|
|
141
|
+
onResize={ setTemporaryWidth }
|
|
101
142
|
onResizeStop={ handleOnHorizontalResizeStop }
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
axis: 'x',
|
|
106
|
-
position: 'corner',
|
|
107
|
-
isVisible: isResizing,
|
|
108
|
-
} }
|
|
143
|
+
isSelected={ isSelected }
|
|
144
|
+
isResizing={ isResizing }
|
|
145
|
+
setIsResizing={ setIsResizing }
|
|
109
146
|
/>
|
|
110
147
|
);
|
|
111
148
|
}
|
|
112
149
|
|
|
113
150
|
return (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
onResizeStart={ handleOnResizeStart }
|
|
136
|
-
onResizeStop={ handleOnVerticalResizeStop }
|
|
137
|
-
showHandle={ isSelected }
|
|
138
|
-
__experimentalShowTooltip={ true }
|
|
139
|
-
__experimentalTooltipProps={ {
|
|
140
|
-
axis: 'y',
|
|
141
|
-
position: 'bottom',
|
|
142
|
-
isVisible: isResizing,
|
|
143
|
-
} }
|
|
144
|
-
/>
|
|
151
|
+
<>
|
|
152
|
+
<ResizableSpacer
|
|
153
|
+
enable={ {
|
|
154
|
+
top: false,
|
|
155
|
+
right: false,
|
|
156
|
+
bottom: true,
|
|
157
|
+
left: false,
|
|
158
|
+
topRight: false,
|
|
159
|
+
bottomRight: false,
|
|
160
|
+
bottomLeft: false,
|
|
161
|
+
topLeft: false,
|
|
162
|
+
} }
|
|
163
|
+
orientation={ blockOrientation }
|
|
164
|
+
onResizeStart={ onResizeStart }
|
|
165
|
+
onResize={ setTemporaryHeight }
|
|
166
|
+
onResizeStop={ handleOnVerticalResizeStop }
|
|
167
|
+
isSelected={ isSelected }
|
|
168
|
+
isResizing={ isResizing }
|
|
169
|
+
setIsResizing={ setIsResizing }
|
|
170
|
+
/>
|
|
171
|
+
</>
|
|
145
172
|
);
|
|
146
173
|
};
|
|
147
174
|
|
|
148
175
|
useEffect( () => {
|
|
149
176
|
if ( orientation === 'horizontal' && ! width ) {
|
|
150
|
-
|
|
151
|
-
|
|
177
|
+
setAttributes( {
|
|
178
|
+
height: '0px',
|
|
179
|
+
width: '72px',
|
|
180
|
+
} );
|
|
152
181
|
}
|
|
153
182
|
}, [] );
|
|
154
183
|
|
|
155
184
|
return (
|
|
156
185
|
<>
|
|
157
|
-
<View { ...useBlockProps() }>
|
|
186
|
+
<View { ...useBlockProps( { style } ) }>
|
|
158
187
|
{ resizableBoxWithOrientation( orientation ) }
|
|
159
188
|
</View>
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
value={ width }
|
|
168
|
-
onChange={ updateWidth }
|
|
169
|
-
/>
|
|
170
|
-
) }
|
|
171
|
-
{ orientation !== 'horizontal' && (
|
|
172
|
-
<RangeControl
|
|
173
|
-
label={ __( 'Height in pixels' ) }
|
|
174
|
-
min={ MIN_SPACER_HEIGHT }
|
|
175
|
-
max={ Math.max( MAX_SPACER_HEIGHT, height ) }
|
|
176
|
-
value={ height }
|
|
177
|
-
onChange={ updateHeight }
|
|
178
|
-
/>
|
|
179
|
-
) }
|
|
180
|
-
</PanelBody>
|
|
181
|
-
</InspectorControls>
|
|
189
|
+
<SpacerControls
|
|
190
|
+
setAttributes={ setAttributes }
|
|
191
|
+
height={ temporaryHeight || height }
|
|
192
|
+
width={ temporaryWidth || width }
|
|
193
|
+
orientation={ orientation }
|
|
194
|
+
isResizing={ isResizing }
|
|
195
|
+
/>
|
|
182
196
|
</>
|
|
183
197
|
);
|
|
184
198
|
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useConvertUnitToMobile } from '@wordpress/components';
|
|
10
|
+
import { withPreferredColorScheme } from '@wordpress/compose';
|
|
11
|
+
import { InspectorControls } from '@wordpress/block-editor';
|
|
12
|
+
import { useEffect } from '@wordpress/element';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import Controls from './controls';
|
|
18
|
+
import styles from './editor.native.scss';
|
|
19
|
+
|
|
20
|
+
const Spacer = ( {
|
|
21
|
+
attributes,
|
|
22
|
+
context,
|
|
23
|
+
setAttributes,
|
|
24
|
+
isSelected,
|
|
25
|
+
getStylesFromColorScheme,
|
|
26
|
+
} ) => {
|
|
27
|
+
const { height, width } = attributes;
|
|
28
|
+
|
|
29
|
+
const { orientation } = context;
|
|
30
|
+
const defaultStyle = getStylesFromColorScheme(
|
|
31
|
+
styles.staticSpacer,
|
|
32
|
+
styles.staticDarkSpacer
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
useEffect( () => {
|
|
36
|
+
if ( orientation === 'horizontal' && ! width ) {
|
|
37
|
+
setAttributes( {
|
|
38
|
+
height: '0px',
|
|
39
|
+
width: '72px',
|
|
40
|
+
} );
|
|
41
|
+
}
|
|
42
|
+
}, [] );
|
|
43
|
+
|
|
44
|
+
const convertedHeight = useConvertUnitToMobile( height );
|
|
45
|
+
const convertedWidth = useConvertUnitToMobile( width );
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<View
|
|
49
|
+
style={ [
|
|
50
|
+
defaultStyle,
|
|
51
|
+
isSelected && styles.selectedSpacer,
|
|
52
|
+
{ height: convertedHeight, width: convertedWidth },
|
|
53
|
+
] }
|
|
54
|
+
>
|
|
55
|
+
{ isSelected && (
|
|
56
|
+
<InspectorControls>
|
|
57
|
+
<Controls
|
|
58
|
+
attributes={ attributes }
|
|
59
|
+
context={ context }
|
|
60
|
+
setAttributes={ setAttributes }
|
|
61
|
+
/>
|
|
62
|
+
</InspectorControls>
|
|
63
|
+
) }
|
|
64
|
+
</View>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default withPreferredColorScheme( Spacer );
|
package/src/spacer/editor.scss
CHANGED
|
@@ -28,6 +28,12 @@
|
|
|
28
28
|
.block-library-spacer__resize-container {
|
|
29
29
|
clear: both;
|
|
30
30
|
|
|
31
|
+
&:not(.is-resizing) {
|
|
32
|
+
// Important is used to have higher specificity than the inline style set by re-resizable library.
|
|
33
|
+
height: 100% !important;
|
|
34
|
+
width: 100% !important;
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
// Don't show the horizontal indicator.
|
|
32
38
|
.components-resizable-box__handle::before {
|
|
33
39
|
content: none;
|
package/src/spacer/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { resizeCornerNE as icon } from '@wordpress/icons';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
+
import deprecated from './deprecated';
|
|
9
10
|
import edit from './edit';
|
|
10
11
|
import metadata from './block.json';
|
|
11
12
|
import save from './save';
|
|
@@ -18,4 +19,5 @@ export const settings = {
|
|
|
18
19
|
icon,
|
|
19
20
|
edit,
|
|
20
21
|
save,
|
|
22
|
+
deprecated,
|
|
21
23
|
};
|
package/src/spacer/save.js
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useBlockProps } from '@wordpress/block-editor';
|
|
5
5
|
|
|
6
|
-
export default function save( { attributes } ) {
|
|
6
|
+
export default function save( { attributes: { height, width } } ) {
|
|
7
7
|
return (
|
|
8
8
|
<div
|
|
9
9
|
{ ...useBlockProps.save( {
|
|
10
|
-
style: {
|
|
10
|
+
style: {
|
|
11
|
+
height,
|
|
12
|
+
width,
|
|
13
|
+
},
|
|
11
14
|
'aria-hidden': true,
|
|
12
15
|
} ) }
|
|
13
16
|
/>
|