@wordpress/block-editor 12.14.0 → 12.15.0
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/README.md +1 -1
- package/build/components/block-list/block.native.js +2 -0
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js +1 -1
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +25 -16
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +4 -2
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-patterns-list/index.js +36 -19
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-rename/index.js +28 -0
- package/build/components/block-rename/index.js.map +1 -0
- package/build/components/block-rename/is-empty-string.js +10 -0
- package/build/components/block-rename/is-empty-string.js.map +1 -0
- package/build/components/block-rename/modal.js +87 -0
- package/build/components/block-rename/modal.js.map +1 -0
- package/build/components/block-rename/rename-control.js +74 -0
- package/build/components/block-rename/rename-control.js.map +1 -0
- package/build/components/block-rename/use-block-rename.js +17 -0
- package/build/components/block-rename/use-block-rename.js.map +1 -0
- package/build/components/block-settings-menu/block-settings-dropdown.js +33 -20
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +7 -0
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-toolbar/block-toolbar-menu.native.js +1 -1
- package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
- package/build/components/block-types-list/index.js +6 -2
- package/build/components/block-types-list/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +8 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/global-styles/advanced-panel.js +1 -1
- package/build/components/global-styles/advanced-panel.js.map +1 -1
- package/build/components/image-size-control/index.js +0 -5
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +3 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/warning-max-depth-exceeded.native.js +29 -31
- package/build/components/inner-blocks/warning-max-depth-exceeded.native.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/use-pattern-categories.js +1 -1
- package/build/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/utils.js +3 -4
- package/build/components/inserter/block-patterns-tab/utils.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +2 -1
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter-listbox/index.js +11 -6
- package/build/components/inserter-listbox/index.js.map +1 -1
- package/build/components/inserter-listbox/item.js +24 -23
- package/build/components/inserter-listbox/item.js.map +1 -1
- package/build/components/inserter-listbox/row.js +5 -5
- package/build/components/inserter-listbox/row.js.map +1 -1
- package/build/components/list-view/use-list-view-expand-selected-item.js +2 -3
- package/build/components/list-view/use-list-view-expand-selected-item.js.map +1 -1
- package/build/components/preview-options/index.js +4 -2
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +1 -1
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +34 -3
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/rich-text/use-input-rules.js +30 -1
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +4 -1
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-moving-animation/index.js +2 -1
- package/build/components/use-moving-animation/index.js.map +1 -1
- package/build/components/use-settings/index.js +2 -2
- package/build/components/use-settings/index.js.map +1 -1
- package/build/hooks/block-renaming.js +42 -0
- package/build/hooks/block-renaming.js.map +1 -1
- package/build/hooks/custom-fields.js +53 -48
- package/build/hooks/custom-fields.js.map +1 -1
- package/build/hooks/index.js +0 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +13 -7
- package/build/hooks/layout.js.map +1 -1
- package/build/layouts/constrained.js +4 -3
- package/build/layouts/constrained.js.map +1 -1
- package/build/store/selectors.js +2 -0
- package/build/store/selectors.js.map +1 -1
- package/build/utils/transform-styles/index.js +26 -6
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -0
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +1 -1
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +24 -15
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +4 -2
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +36 -19
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-rename/index.js +4 -0
- package/build-module/components/block-rename/index.js.map +1 -0
- package/build-module/components/block-rename/is-empty-string.js +4 -0
- package/build-module/components/block-rename/is-empty-string.js.map +1 -0
- package/build-module/components/block-rename/modal.js +79 -0
- package/build-module/components/block-rename/modal.js.map +1 -0
- package/build-module/components/block-rename/rename-control.js +66 -0
- package/build-module/components/block-rename/rename-control.js.map +1 -0
- package/build-module/components/block-rename/use-block-rename.js +10 -0
- package/build-module/components/block-rename/use-block-rename.js.map +1 -0
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +34 -21
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +7 -0
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js +1 -1
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
- package/build-module/components/block-types-list/index.js +6 -2
- package/build-module/components/block-types-list/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +8 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/global-styles/advanced-panel.js +1 -1
- package/build-module/components/global-styles/advanced-panel.js.map +1 -1
- package/build-module/components/image-size-control/index.js +0 -5
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +3 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/warning-max-depth-exceeded.native.js +30 -32
- package/build-module/components/inner-blocks/warning-max-depth-exceeded.native.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +4 -4
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js +2 -2
- package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/utils.js +3 -4
- package/build-module/components/inserter/block-patterns-tab/utils.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +2 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter-listbox/index.js +13 -8
- package/build-module/components/inserter-listbox/index.js.map +1 -1
- package/build-module/components/inserter-listbox/item.js +25 -23
- package/build-module/components/inserter-listbox/item.js.map +1 -1
- package/build-module/components/inserter-listbox/row.js +6 -5
- package/build-module/components/inserter-listbox/row.js.map +1 -1
- package/build-module/components/list-view/use-list-view-expand-selected-item.js +2 -3
- package/build-module/components/list-view/use-list-view-expand-selected-item.js.map +1 -1
- package/build-module/components/preview-options/index.js +4 -2
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +1 -1
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +34 -3
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-input-rules.js +31 -2
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +4 -1
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-moving-animation/index.js +2 -1
- package/build-module/components/use-moving-animation/index.js.map +1 -1
- package/build-module/components/use-settings/index.js +2 -2
- package/build-module/components/use-settings/index.js.map +1 -1
- package/build-module/hooks/block-renaming.js +40 -0
- package/build-module/hooks/block-renaming.js.map +1 -1
- package/build-module/hooks/custom-fields.js +53 -48
- package/build-module/hooks/custom-fields.js.map +1 -1
- package/build-module/hooks/index.js +0 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +13 -7
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/layouts/constrained.js +4 -3
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/store/selectors.js +2 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +24 -7
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +6 -6
- package/build-style/content.css +6 -6
- package/build-style/style-rtl.css +10 -5
- package/build-style/style.css +10 -5
- package/package.json +31 -31
- package/src/components/block-list/block.native.js +2 -0
- package/src/components/block-parent-selector/index.js +1 -1
- package/src/components/block-pattern-setup/index.js +38 -22
- package/src/components/block-pattern-setup/setup-toolbar.js +2 -0
- package/src/components/block-pattern-setup/style.scss +4 -1
- package/src/components/block-patterns-list/README.md +4 -4
- package/src/components/block-patterns-list/index.js +60 -34
- package/src/components/block-patterns-list/style.scss +7 -0
- package/src/components/block-rename/index.js +3 -0
- package/src/components/block-rename/is-empty-string.js +3 -0
- package/src/components/block-rename/modal.js +115 -0
- package/src/components/block-rename/rename-control.js +80 -0
- package/src/components/block-rename/use-block-rename.js +10 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +38 -34
- package/src/components/block-settings-menu-controls/index.js +9 -0
- package/src/components/block-toolbar/block-toolbar-menu.native.js +1 -4
- package/src/components/block-types-list/index.js +5 -4
- package/src/components/button-block-appender/content.scss +2 -2
- package/src/components/date-format-picker/index.js +7 -0
- package/src/components/editable-text/README.md +0 -36
- package/src/components/global-styles/advanced-panel.js +1 -1
- package/src/components/image-size-control/index.js +0 -6
- package/src/components/inner-blocks/index.js +6 -2
- package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +57 -33
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +5 -1
- package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +7 -3
- package/src/components/inserter/block-patterns-tab/use-pattern-categories.js +6 -1
- package/src/components/inserter/block-patterns-tab/utils.js +6 -4
- package/src/components/inserter/hooks/use-patterns-state.js +3 -1
- package/src/components/inserter-listbox/index.js +11 -7
- package/src/components/inserter-listbox/item.js +11 -12
- package/src/components/inserter-listbox/row.js +6 -12
- package/src/components/list-view/use-list-view-expand-selected-item.js +7 -8
- package/src/components/plain-text/README.md +0 -28
- package/src/components/preview-options/index.js +2 -0
- package/src/components/rich-text/README.md +0 -58
- package/src/components/rich-text/index.native.js +1 -1
- package/src/components/rich-text/native/index.native.js +45 -2
- package/src/components/rich-text/use-input-rules.js +30 -2
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/src/components/url-input/README.md +1 -74
- package/src/components/use-block-drop-zone/index.js +4 -1
- package/src/components/use-moving-animation/index.js +1 -1
- package/src/components/use-settings/index.js +2 -2
- package/src/components/use-settings/test/index.js +1 -1
- package/src/hooks/block-renaming.js +47 -0
- package/src/hooks/custom-fields.js +68 -65
- package/src/hooks/index.js +0 -1
- package/src/hooks/layout.js +12 -8
- package/src/hooks/test/__snapshots__/align.native.js.snap +5 -5
- package/src/layouts/constrained.js +57 -50
- package/src/store/selectors.js +2 -0
- package/src/style.scss +1 -1
- package/src/utils/test/transform-styles.js +49 -0
- package/src/utils/transform-styles/index.js +39 -13
- package/build/hooks/block-rename-ui.js +0 -167
- package/build/hooks/block-rename-ui.js.map +0 -1
- package/build-module/hooks/block-rename-ui.js +0 -159
- package/build-module/hooks/block-rename-ui.js.map +0 -1
- package/src/hooks/block-rename-ui.js +0 -228
- /package/src/{hooks/block-rename-ui.scss → components/block-rename/style.scss} +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useRef } from '@wordpress/element';
|
|
5
5
|
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
-
import { insert, toHTMLString } from '@wordpress/rich-text';
|
|
6
|
+
import { insert, isCollapsed, toHTMLString } from '@wordpress/rich-text';
|
|
7
7
|
import { getBlockTransforms, findTransform } from '@wordpress/blocks';
|
|
8
8
|
import { useDispatch } from '@wordpress/data';
|
|
9
9
|
|
|
@@ -42,6 +42,34 @@ function findSelection( blocks ) {
|
|
|
42
42
|
return [];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* An input rule that replaces two spaces with an en space, and an en space
|
|
47
|
+
* followed by a space with an em space.
|
|
48
|
+
*
|
|
49
|
+
* @param {Object} value Value to replace spaces in.
|
|
50
|
+
*
|
|
51
|
+
* @return {Object} Value with spaces replaced.
|
|
52
|
+
*/
|
|
53
|
+
function replacePrecedingSpaces( value ) {
|
|
54
|
+
if ( ! isCollapsed( value ) ) {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { text, start } = value;
|
|
59
|
+
const lastTwoCharacters = text.slice( start - 2, start );
|
|
60
|
+
|
|
61
|
+
// Replace two spaces with an em space.
|
|
62
|
+
if ( lastTwoCharacters === ' ' ) {
|
|
63
|
+
return insert( value, '\u2002', start - 2, start );
|
|
64
|
+
}
|
|
65
|
+
// Replace an en space followed by a space with an em space.
|
|
66
|
+
else if ( lastTwoCharacters === '\u2002 ' ) {
|
|
67
|
+
return insert( value, '\u2003', start - 2, start );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
|
|
45
73
|
export function useInputRules( props ) {
|
|
46
74
|
const {
|
|
47
75
|
__unstableMarkLastChangeAsPersistent,
|
|
@@ -122,7 +150,7 @@ export function useInputRules( props ) {
|
|
|
122
150
|
|
|
123
151
|
return accumlator;
|
|
124
152
|
},
|
|
125
|
-
preventEventDiscovery( value )
|
|
153
|
+
preventEventDiscovery( replacePrecedingSpaces( value ) )
|
|
126
154
|
);
|
|
127
155
|
|
|
128
156
|
if ( transformed !== value ) {
|
|
@@ -139,7 +139,7 @@ export default function SpacingInputControl( {
|
|
|
139
139
|
useMemo(
|
|
140
140
|
() => parseQuantityAndUnitFromRawValue( currentValue ),
|
|
141
141
|
[ currentValue ]
|
|
142
|
-
)[ 1 ] || units[ 0 ]
|
|
142
|
+
)[ 1 ] || units[ 0 ]?.value;
|
|
143
143
|
|
|
144
144
|
const setInitialValue = () => {
|
|
145
145
|
if ( value === undefined ) {
|
|
@@ -36,41 +36,6 @@ This prop is passed directly to the `URLInput` component.
|
|
|
36
36
|
|
|
37
37
|
## Example
|
|
38
38
|
|
|
39
|
-
{% codetabs %}
|
|
40
|
-
{% ES5 %}
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
wp.blocks.registerBlockType( /* ... */, {
|
|
44
|
-
// ...
|
|
45
|
-
|
|
46
|
-
attributes: {
|
|
47
|
-
url: {
|
|
48
|
-
type: 'string'
|
|
49
|
-
},
|
|
50
|
-
text: {
|
|
51
|
-
type: 'string'
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
edit: function( props ) {
|
|
56
|
-
return React.createElement( wp.blockEditor.URLInputButton, {
|
|
57
|
-
className: props.className,
|
|
58
|
-
url: props.attributes.url,
|
|
59
|
-
onChange: function( url, post ) {
|
|
60
|
-
props.setAttributes( { url: url, text: (post && post.title) || 'Click here' } );
|
|
61
|
-
}
|
|
62
|
-
} );
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
save: function( props ) {
|
|
66
|
-
return React.createElement( 'a', {
|
|
67
|
-
href: props.attributes.url,
|
|
68
|
-
}, props.attributes.text );
|
|
69
|
-
}
|
|
70
|
-
} );
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
{% ESNext %}
|
|
74
39
|
|
|
75
40
|
```js
|
|
76
41
|
import { registerBlockType } from '@wordpress/blocks';
|
|
@@ -103,7 +68,6 @@ registerBlockType( /* ... */, {
|
|
|
103
68
|
} );
|
|
104
69
|
```
|
|
105
70
|
|
|
106
|
-
{% end %}
|
|
107
71
|
|
|
108
72
|
# `URLInput`
|
|
109
73
|
|
|
@@ -139,7 +103,7 @@ _Required._ Called when the value changes. The second parameter is `null` unless
|
|
|
139
103
|
}
|
|
140
104
|
```
|
|
141
105
|
|
|
142
|
-
### `
|
|
106
|
+
### `onKeyDown`: `( event: KeyboardEvent ) => void`
|
|
143
107
|
|
|
144
108
|
A callback invoked on the keydown event.
|
|
145
109
|
|
|
@@ -172,41 +136,6 @@ Start opting into the new margin-free styles that will become the default in a f
|
|
|
172
136
|
|
|
173
137
|
## Example
|
|
174
138
|
|
|
175
|
-
{% codetabs %}
|
|
176
|
-
{% ES5 %}
|
|
177
|
-
|
|
178
|
-
```js
|
|
179
|
-
wp.blocks.registerBlockType( /* ... */, {
|
|
180
|
-
// ...
|
|
181
|
-
|
|
182
|
-
attributes: {
|
|
183
|
-
url: {
|
|
184
|
-
type: 'string'
|
|
185
|
-
},
|
|
186
|
-
text: {
|
|
187
|
-
type: 'string'
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
edit: function( props ) {
|
|
192
|
-
return React.createElement( wp.blockEditor.URLInput, {
|
|
193
|
-
className: props.className,
|
|
194
|
-
value: props.attributes.url,
|
|
195
|
-
onChange: function( url, post ) {
|
|
196
|
-
props.setAttributes( { url: url, text: (post && post.title) || 'Click here' } );
|
|
197
|
-
}
|
|
198
|
-
} );
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
save: function( props ) {
|
|
202
|
-
return React.createElement( 'a', {
|
|
203
|
-
href: props.attributes.url,
|
|
204
|
-
}, props.attributes.text );
|
|
205
|
-
}
|
|
206
|
-
} );
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
{% ESNext %}
|
|
210
139
|
|
|
211
140
|
```js
|
|
212
141
|
import { registerBlockType } from '@wordpress/blocks';
|
|
@@ -240,5 +169,3 @@ registerBlockType( /* ... */, {
|
|
|
240
169
|
}
|
|
241
170
|
} );
|
|
242
171
|
```
|
|
243
|
-
|
|
244
|
-
{% end %}
|
|
@@ -127,7 +127,8 @@ export function getDropTargetPosition(
|
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* @typedef {Object} WPBlockDropZoneConfig
|
|
130
|
-
* @property {
|
|
130
|
+
* @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.
|
|
131
|
+
* @property {string} rootClientId The root client id for the block list.
|
|
131
132
|
*/
|
|
132
133
|
|
|
133
134
|
/**
|
|
@@ -136,6 +137,7 @@ export function getDropTargetPosition(
|
|
|
136
137
|
* @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.
|
|
137
138
|
*/
|
|
138
139
|
export default function useBlockDropZone( {
|
|
140
|
+
dropZoneElement,
|
|
139
141
|
// An undefined value represents a top-level block. Default to an empty
|
|
140
142
|
// string for this so that `targetRootClientId` can be easily compared to
|
|
141
143
|
// values returned by the `getRootBlockClientId` selector, which also uses
|
|
@@ -235,6 +237,7 @@ export default function useBlockDropZone( {
|
|
|
235
237
|
);
|
|
236
238
|
|
|
237
239
|
return useDropZone( {
|
|
240
|
+
dropZoneElement,
|
|
238
241
|
isDisabled,
|
|
239
242
|
onDrop: onBlockDrop,
|
|
240
243
|
onDragOver( event ) {
|
|
@@ -129,7 +129,7 @@ function useMovingAnimation( {
|
|
|
129
129
|
const finishedMoving = x === 0 && y === 0;
|
|
130
130
|
ref.current.style.transformOrigin = 'center center';
|
|
131
131
|
ref.current.style.transform = finishedMoving
|
|
132
|
-
?
|
|
132
|
+
? null // Set to `null` to explicitly remove the transform.
|
|
133
133
|
: `translate3d(${ x }px,${ y }px,0)`;
|
|
134
134
|
ref.current.style.zIndex = isSelected ? '1' : '';
|
|
135
135
|
|
|
@@ -254,7 +254,7 @@ export function useSettings( ...paths ) {
|
|
|
254
254
|
*
|
|
255
255
|
* @param {string} path The path to the setting.
|
|
256
256
|
* @return {any} Returns the value defined for the setting.
|
|
257
|
-
* @deprecated 6.
|
|
257
|
+
* @deprecated 6.5.0 Use useSettings instead.
|
|
258
258
|
* @example
|
|
259
259
|
* ```js
|
|
260
260
|
* const isEnabled = useSetting( 'typography.dropCap' );
|
|
@@ -262,7 +262,7 @@ export function useSettings( ...paths ) {
|
|
|
262
262
|
*/
|
|
263
263
|
export function useSetting( path ) {
|
|
264
264
|
deprecated( 'wp.blockEditor.useSetting', {
|
|
265
|
-
since: '6.
|
|
265
|
+
since: '6.5',
|
|
266
266
|
alternative: 'wp.blockEditor.useSettings',
|
|
267
267
|
note: 'The new useSettings function can retrieve multiple settings at once, with better performance.',
|
|
268
268
|
} );
|
|
@@ -135,7 +135,7 @@ describe( 'useSettings', () => {
|
|
|
135
135
|
const result = runHook( () => useSetting( 'layout.contentSize' ) );
|
|
136
136
|
expect( result ).toBe( '840px' );
|
|
137
137
|
expect( console ).toHaveWarnedWith(
|
|
138
|
-
'wp.blockEditor.useSetting is deprecated since version 6.
|
|
138
|
+
'wp.blockEditor.useSetting is deprecated since version 6.5. Please use wp.blockEditor.useSettings instead.'
|
|
139
139
|
);
|
|
140
140
|
} );
|
|
141
141
|
} );
|
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { addFilter } from '@wordpress/hooks';
|
|
5
5
|
import { hasBlockSupport } from '@wordpress/blocks';
|
|
6
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
7
|
+
import { __ } from '@wordpress/i18n';
|
|
8
|
+
import { TextControl } from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { InspectorControls } from '../components';
|
|
14
|
+
import { useBlockRename } from '../components/block-rename';
|
|
6
15
|
|
|
7
16
|
/**
|
|
8
17
|
* Filters registered block settings, adding an `__experimentalLabel` callback if one does not already exist.
|
|
@@ -38,6 +47,44 @@ export function addLabelCallback( settings ) {
|
|
|
38
47
|
return settings;
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
export const withBlockRenameControl = createHigherOrderComponent(
|
|
51
|
+
( BlockEdit ) => ( props ) => {
|
|
52
|
+
const { name, attributes, setAttributes, isSelected } = props;
|
|
53
|
+
|
|
54
|
+
const { canRename } = useBlockRename( name );
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
{ isSelected && canRename && (
|
|
59
|
+
<InspectorControls group="advanced">
|
|
60
|
+
<TextControl
|
|
61
|
+
__nextHasNoMarginBottom
|
|
62
|
+
label={ __( 'Block name' ) }
|
|
63
|
+
value={ attributes?.metadata?.name || '' }
|
|
64
|
+
onChange={ ( newName ) => {
|
|
65
|
+
setAttributes( {
|
|
66
|
+
metadata: {
|
|
67
|
+
...attributes?.metadata,
|
|
68
|
+
name: newName,
|
|
69
|
+
},
|
|
70
|
+
} );
|
|
71
|
+
} }
|
|
72
|
+
/>
|
|
73
|
+
</InspectorControls>
|
|
74
|
+
) }
|
|
75
|
+
<BlockEdit key="edit" { ...props } />
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
'withToolbarControls'
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
addFilter(
|
|
83
|
+
'editor.BlockEdit',
|
|
84
|
+
'core/block-rename-ui/with-block-rename-control',
|
|
85
|
+
withBlockRenameControl
|
|
86
|
+
);
|
|
87
|
+
|
|
41
88
|
addFilter(
|
|
42
89
|
'blocks.registerBlockType',
|
|
43
90
|
'core/metadata/addLabelCallback',
|
|
@@ -34,6 +34,65 @@ function addAttribute( settings ) {
|
|
|
34
34
|
return settings;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function CustomFieldsControl( props ) {
|
|
38
|
+
const blockEditingMode = useBlockEditingMode();
|
|
39
|
+
if ( blockEditingMode !== 'default' ) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// If the block is a paragraph or image block, we need to know which
|
|
44
|
+
// attribute to use for the connection. Only the `content` attribute
|
|
45
|
+
// of the paragraph block and the `url` attribute of the image block are supported.
|
|
46
|
+
let attributeName;
|
|
47
|
+
if ( props.name === 'core/paragraph' ) attributeName = 'content';
|
|
48
|
+
if ( props.name === 'core/image' ) attributeName = 'url';
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<InspectorControls>
|
|
52
|
+
<PanelBody title={ __( 'Connections' ) } initialOpen={ true }>
|
|
53
|
+
<TextControl
|
|
54
|
+
__nextHasNoMarginBottom
|
|
55
|
+
autoComplete="off"
|
|
56
|
+
label={ __( 'Custom field meta_key' ) }
|
|
57
|
+
value={
|
|
58
|
+
props.attributes?.connections?.attributes?.[
|
|
59
|
+
attributeName
|
|
60
|
+
]?.value || ''
|
|
61
|
+
}
|
|
62
|
+
onChange={ ( nextValue ) => {
|
|
63
|
+
if ( nextValue === '' ) {
|
|
64
|
+
props.setAttributes( {
|
|
65
|
+
connections: undefined,
|
|
66
|
+
[ attributeName ]: undefined,
|
|
67
|
+
placeholder: undefined,
|
|
68
|
+
} );
|
|
69
|
+
} else {
|
|
70
|
+
props.setAttributes( {
|
|
71
|
+
connections: {
|
|
72
|
+
attributes: {
|
|
73
|
+
// The attributeName will be either `content` or `url`.
|
|
74
|
+
[ attributeName ]: {
|
|
75
|
+
// Source will be variable, could be post_meta, user_meta, term_meta, etc.
|
|
76
|
+
// Could even be a custom source like a social media attribute.
|
|
77
|
+
source: 'meta_fields',
|
|
78
|
+
value: nextValue,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
[ attributeName ]: undefined,
|
|
83
|
+
placeholder: sprintf(
|
|
84
|
+
'This content will be replaced on the frontend by the value of "%s" custom field.',
|
|
85
|
+
nextValue
|
|
86
|
+
),
|
|
87
|
+
} );
|
|
88
|
+
}
|
|
89
|
+
} }
|
|
90
|
+
/>
|
|
91
|
+
</PanelBody>
|
|
92
|
+
</InspectorControls>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
37
96
|
/**
|
|
38
97
|
* Override the default edit UI to include a new block inspector control for
|
|
39
98
|
* assigning a connection to blocks that has support for connections.
|
|
@@ -46,7 +105,6 @@ function addAttribute( settings ) {
|
|
|
46
105
|
*/
|
|
47
106
|
const withCustomFieldsControls = createHigherOrderComponent( ( BlockEdit ) => {
|
|
48
107
|
return ( props ) => {
|
|
49
|
-
const blockEditingMode = useBlockEditingMode();
|
|
50
108
|
const hasCustomFieldsSupport = hasBlockSupport(
|
|
51
109
|
props.name,
|
|
52
110
|
'__experimentalConnections',
|
|
@@ -56,72 +114,17 @@ const withCustomFieldsControls = createHigherOrderComponent( ( BlockEdit ) => {
|
|
|
56
114
|
// Check if the current block is a paragraph or image block.
|
|
57
115
|
// Currently, only these two blocks are supported.
|
|
58
116
|
if ( ! [ 'core/paragraph', 'core/image' ].includes( props.name ) ) {
|
|
59
|
-
return <BlockEdit { ...props } />;
|
|
117
|
+
return <BlockEdit key="edit" { ...props } />;
|
|
60
118
|
}
|
|
61
119
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<>
|
|
72
|
-
<BlockEdit { ...props } />
|
|
73
|
-
{ blockEditingMode === 'default' && (
|
|
74
|
-
<InspectorControls>
|
|
75
|
-
<PanelBody
|
|
76
|
-
title={ __( 'Connections' ) }
|
|
77
|
-
initialOpen={ true }
|
|
78
|
-
>
|
|
79
|
-
<TextControl
|
|
80
|
-
__nextHasNoMarginBottom
|
|
81
|
-
autoComplete="off"
|
|
82
|
-
label={ __( 'Custom field meta_key' ) }
|
|
83
|
-
value={
|
|
84
|
-
props.attributes?.connections
|
|
85
|
-
?.attributes?.[ attributeName ]
|
|
86
|
-
?.value || ''
|
|
87
|
-
}
|
|
88
|
-
onChange={ ( nextValue ) => {
|
|
89
|
-
if ( nextValue === '' ) {
|
|
90
|
-
props.setAttributes( {
|
|
91
|
-
connections: undefined,
|
|
92
|
-
[ attributeName ]: undefined,
|
|
93
|
-
placeholder: undefined,
|
|
94
|
-
} );
|
|
95
|
-
} else {
|
|
96
|
-
props.setAttributes( {
|
|
97
|
-
connections: {
|
|
98
|
-
attributes: {
|
|
99
|
-
// The attributeName will be either `content` or `url`.
|
|
100
|
-
[ attributeName ]: {
|
|
101
|
-
// Source will be variable, could be post_meta, user_meta, term_meta, etc.
|
|
102
|
-
// Could even be a custom source like a social media attribute.
|
|
103
|
-
source: 'meta_fields',
|
|
104
|
-
value: nextValue,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
[ attributeName ]: undefined,
|
|
109
|
-
placeholder: sprintf(
|
|
110
|
-
'This content will be replaced on the frontend by the value of "%s" custom field.',
|
|
111
|
-
nextValue
|
|
112
|
-
),
|
|
113
|
-
} );
|
|
114
|
-
}
|
|
115
|
-
} }
|
|
116
|
-
/>
|
|
117
|
-
</PanelBody>
|
|
118
|
-
</InspectorControls>
|
|
119
|
-
) }
|
|
120
|
-
</>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return <BlockEdit { ...props } />;
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
<BlockEdit key="edit" { ...props } />
|
|
123
|
+
{ hasCustomFieldsSupport && props.isSelected && (
|
|
124
|
+
<CustomFieldsControl { ...props } />
|
|
125
|
+
) }
|
|
126
|
+
</>
|
|
127
|
+
);
|
|
125
128
|
};
|
|
126
129
|
}, 'withCustomFieldsControls' );
|
|
127
130
|
|
package/src/hooks/index.js
CHANGED
package/src/hooks/layout.js
CHANGED
|
@@ -135,10 +135,9 @@ export function useLayoutStyles( blockAttributes = {}, blockName, selector ) {
|
|
|
135
135
|
|
|
136
136
|
function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
|
|
137
137
|
const settings = useBlockSettings( blockName );
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
// Block settings come from theme.json under settings.[blockName].
|
|
139
|
+
const { layout: layoutSettings } = settings;
|
|
140
|
+
// Layout comes from block attributes.
|
|
142
141
|
const { layout } = attributes;
|
|
143
142
|
const [ defaultThemeLayout ] = useSettings( 'layout' );
|
|
144
143
|
const { themeSupportsLayout } = useSelect( ( select ) => {
|
|
@@ -153,17 +152,22 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
|
|
|
153
152
|
return null;
|
|
154
153
|
}
|
|
155
154
|
|
|
155
|
+
// Layout block support comes from the block's block.json.
|
|
156
156
|
const layoutBlockSupport = getBlockSupport(
|
|
157
157
|
blockName,
|
|
158
158
|
layoutBlockSupportKey,
|
|
159
159
|
{}
|
|
160
160
|
);
|
|
161
|
+
const blockSupportAndThemeSettings = {
|
|
162
|
+
...layoutSettings,
|
|
163
|
+
...layoutBlockSupport,
|
|
164
|
+
};
|
|
161
165
|
const {
|
|
162
166
|
allowSwitching,
|
|
163
|
-
allowEditing =
|
|
167
|
+
allowEditing = true,
|
|
164
168
|
allowInheriting = true,
|
|
165
169
|
default: defaultBlockLayout,
|
|
166
|
-
} =
|
|
170
|
+
} = blockSupportAndThemeSettings;
|
|
167
171
|
|
|
168
172
|
if ( ! allowEditing ) {
|
|
169
173
|
return null;
|
|
@@ -260,14 +264,14 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
|
|
|
260
264
|
<layoutType.inspectorControls
|
|
261
265
|
layout={ usedLayout }
|
|
262
266
|
onChange={ onChangeLayout }
|
|
263
|
-
layoutBlockSupport={
|
|
267
|
+
layoutBlockSupport={ blockSupportAndThemeSettings }
|
|
264
268
|
/>
|
|
265
269
|
) }
|
|
266
270
|
{ constrainedType && displayControlsForLegacyLayouts && (
|
|
267
271
|
<constrainedType.inspectorControls
|
|
268
272
|
layout={ usedLayout }
|
|
269
273
|
onChange={ onChangeLayout }
|
|
270
|
-
layoutBlockSupport={
|
|
274
|
+
layoutBlockSupport={ blockSupportAndThemeSettings }
|
|
271
275
|
/>
|
|
272
276
|
) }
|
|
273
277
|
</PanelBody>
|
|
@@ -19,25 +19,25 @@ exports[`Align options for group block sets Wide width option 1`] = `
|
|
|
19
19
|
`;
|
|
20
20
|
|
|
21
21
|
exports[`Align options for media block sets Align center option 1`] = `
|
|
22
|
-
"<!-- wp:image {"
|
|
22
|
+
"<!-- wp:image {"id":1,"sizeSlug":"large","linkDestination":"none","align":"center"} -->
|
|
23
23
|
<figure class="wp-block-image aligncenter size-large"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt="" class="wp-image-1"/></figure>
|
|
24
24
|
<!-- /wp:image -->"
|
|
25
25
|
`;
|
|
26
26
|
|
|
27
27
|
exports[`Align options for media block sets Align left option 1`] = `
|
|
28
|
-
"<!-- wp:image {"
|
|
28
|
+
"<!-- wp:image {"id":1,"sizeSlug":"large","linkDestination":"none","align":"left"} -->
|
|
29
29
|
<figure class="wp-block-image alignleft size-large"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt="" class="wp-image-1"/></figure>
|
|
30
30
|
<!-- /wp:image -->"
|
|
31
31
|
`;
|
|
32
32
|
|
|
33
33
|
exports[`Align options for media block sets Align right option 1`] = `
|
|
34
|
-
"<!-- wp:image {"
|
|
34
|
+
"<!-- wp:image {"id":1,"sizeSlug":"large","linkDestination":"none","align":"right"} -->
|
|
35
35
|
<figure class="wp-block-image alignright size-large"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt="" class="wp-image-1"/></figure>
|
|
36
36
|
<!-- /wp:image -->"
|
|
37
37
|
`;
|
|
38
38
|
|
|
39
39
|
exports[`Align options for media block sets Full width option 1`] = `
|
|
40
|
-
"<!-- wp:image {"
|
|
40
|
+
"<!-- wp:image {"id":1,"sizeSlug":"large","linkDestination":"none","align":"full"} -->
|
|
41
41
|
<figure class="wp-block-image alignfull size-large"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt="" class="wp-image-1"/></figure>
|
|
42
42
|
<!-- /wp:image -->"
|
|
43
43
|
`;
|
|
@@ -49,7 +49,7 @@ exports[`Align options for media block sets None option 1`] = `
|
|
|
49
49
|
`;
|
|
50
50
|
|
|
51
51
|
exports[`Align options for media block sets Wide width option 1`] = `
|
|
52
|
-
"<!-- wp:image {"
|
|
52
|
+
"<!-- wp:image {"id":1,"sizeSlug":"large","linkDestination":"none","align":"wide"} -->
|
|
53
53
|
<figure class="wp-block-image alignwide size-large"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt="" class="wp-image-1"/></figure>
|
|
54
54
|
<!-- /wp:image -->"
|
|
55
55
|
`;
|
|
@@ -36,7 +36,10 @@ export default {
|
|
|
36
36
|
layoutBlockSupport = {},
|
|
37
37
|
} ) {
|
|
38
38
|
const { wideSize, contentSize, justifyContent = 'center' } = layout;
|
|
39
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
allowJustification = true,
|
|
41
|
+
allowCustomContentAndWideSize = true,
|
|
42
|
+
} = layoutBlockSupport;
|
|
40
43
|
const onJustificationChange = ( value ) => {
|
|
41
44
|
onChange( {
|
|
42
45
|
...layout,
|
|
@@ -66,55 +69,59 @@ export default {
|
|
|
66
69
|
} );
|
|
67
70
|
return (
|
|
68
71
|
<>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<
|
|
72
|
-
className="block-editor-hooks__layout-controls-unit
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
className="block-editor-hooks__layout-controls-unit
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
72
|
+
{ allowCustomContentAndWideSize && (
|
|
73
|
+
<>
|
|
74
|
+
<div className="block-editor-hooks__layout-controls">
|
|
75
|
+
<div className="block-editor-hooks__layout-controls-unit">
|
|
76
|
+
<UnitControl
|
|
77
|
+
className="block-editor-hooks__layout-controls-unit-input"
|
|
78
|
+
label={ __( 'Content' ) }
|
|
79
|
+
labelPosition="top"
|
|
80
|
+
__unstableInputWidth="80px"
|
|
81
|
+
value={ contentSize || wideSize || '' }
|
|
82
|
+
onChange={ ( nextWidth ) => {
|
|
83
|
+
nextWidth =
|
|
84
|
+
0 > parseFloat( nextWidth )
|
|
85
|
+
? '0'
|
|
86
|
+
: nextWidth;
|
|
87
|
+
onChange( {
|
|
88
|
+
...layout,
|
|
89
|
+
contentSize: nextWidth,
|
|
90
|
+
} );
|
|
91
|
+
} }
|
|
92
|
+
units={ units }
|
|
93
|
+
/>
|
|
94
|
+
<Icon icon={ positionCenter } />
|
|
95
|
+
</div>
|
|
96
|
+
<div className="block-editor-hooks__layout-controls-unit">
|
|
97
|
+
<UnitControl
|
|
98
|
+
className="block-editor-hooks__layout-controls-unit-input"
|
|
99
|
+
label={ __( 'Wide' ) }
|
|
100
|
+
labelPosition="top"
|
|
101
|
+
__unstableInputWidth="80px"
|
|
102
|
+
value={ wideSize || contentSize || '' }
|
|
103
|
+
onChange={ ( nextWidth ) => {
|
|
104
|
+
nextWidth =
|
|
105
|
+
0 > parseFloat( nextWidth )
|
|
106
|
+
? '0'
|
|
107
|
+
: nextWidth;
|
|
108
|
+
onChange( {
|
|
109
|
+
...layout,
|
|
110
|
+
wideSize: nextWidth,
|
|
111
|
+
} );
|
|
112
|
+
} }
|
|
113
|
+
units={ units }
|
|
114
|
+
/>
|
|
115
|
+
<Icon icon={ stretchWide } />
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
<p className="block-editor-hooks__layout-controls-helptext">
|
|
119
|
+
{ __(
|
|
120
|
+
'Customize the width for all elements that are assigned to the center or wide columns.'
|
|
121
|
+
) }
|
|
122
|
+
</p>
|
|
123
|
+
</>
|
|
124
|
+
) }
|
|
118
125
|
{ allowJustification && (
|
|
119
126
|
<ToggleGroupControl
|
|
120
127
|
__nextHasNoMarginBottom
|