@wordpress/block-editor 14.3.5 → 14.3.6
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/README.md +4 -0
- package/build/components/block-list/block.js +0 -3
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -4
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js +9 -12
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build/components/iframe/index.js +6 -1
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/menu.js +3 -0
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/tool-selector/index.js +5 -1
- package/build/components/tool-selector/index.js.map +1 -1
- package/build/components/use-resize-canvas/index.js +1 -2
- package/build/components/use-resize-canvas/index.js.map +1 -1
- package/build/hooks/grid-visualizer.js +13 -11
- package/build/hooks/grid-visualizer.js.map +1 -1
- package/build/hooks/layout-child.js +41 -3
- package/build/hooks/layout-child.js.map +1 -1
- package/build/private-apis.js +2 -0
- package/build/private-apis.js.map +1 -1
- package/build/utils/block-bindings.js +9 -6
- package/build/utils/block-bindings.js.map +1 -1
- package/build-module/components/block-list/block.js +0 -3
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -4
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js +9 -12
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -1
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/menu.js +3 -0
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/tool-selector/index.js +5 -1
- package/build-module/components/tool-selector/index.js.map +1 -1
- package/build-module/components/use-resize-canvas/index.js +1 -2
- package/build-module/components/use-resize-canvas/index.js.map +1 -1
- package/build-module/hooks/grid-visualizer.js +13 -11
- package/build-module/hooks/grid-visualizer.js.map +1 -1
- package/build-module/hooks/layout-child.js +41 -3
- package/build-module/hooks/layout-child.js.map +1 -1
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/utils/block-bindings.js +9 -6
- package/build-module/utils/block-bindings.js.map +1 -1
- package/build-style/content-rtl.css +6 -7
- package/build-style/content.css +6 -7
- package/build-style/style-rtl.css +9 -1
- package/build-style/style.css +9 -1
- package/package.json +5 -5
- package/src/components/block-list/block.js +0 -3
- package/src/components/block-list/use-block-props/index.js +1 -2
- package/src/components/block-list/use-block-props/use-zoom-out-mode-exit.js +19 -11
- package/src/components/iframe/content.scss +7 -8
- package/src/components/iframe/index.js +7 -1
- package/src/components/iframe/style.scss +17 -0
- package/src/components/inserter/menu.js +5 -0
- package/src/components/list-view/style.scss +9 -0
- package/src/components/tool-selector/index.js +5 -2
- package/src/components/use-resize-canvas/index.js +1 -3
- package/src/hooks/grid-visualizer.js +23 -9
- package/src/hooks/layout-child.js +48 -3
- package/src/private-apis.js +2 -0
- package/src/utils/block-bindings.js +9 -6
- package/src/utils/test/use-block-bindings-utils.js +174 -0
package/src/private-apis.js
CHANGED
|
@@ -32,6 +32,7 @@ import { usesContextKey } from './components/rich-text/format-edit';
|
|
|
32
32
|
import { ExperimentalBlockCanvas } from './components/block-canvas';
|
|
33
33
|
import { getDuotoneFilter } from './components/duotone/utils';
|
|
34
34
|
import { useFlashEditableBlocks } from './components/use-flash-editable-blocks';
|
|
35
|
+
import { useZoomOutModeExit } from './components/block-list/use-block-props/use-zoom-out-mode-exit';
|
|
35
36
|
import {
|
|
36
37
|
selectBlockPatternsKey,
|
|
37
38
|
reusableBlocksSelectKey,
|
|
@@ -78,6 +79,7 @@ lock( privateApis, {
|
|
|
78
79
|
TextAlignmentControl,
|
|
79
80
|
usesContextKey,
|
|
80
81
|
useFlashEditableBlocks,
|
|
82
|
+
useZoomOutModeExit,
|
|
81
83
|
globalStylesDataKey,
|
|
82
84
|
globalStylesLinksDataKey,
|
|
83
85
|
selectBlockPatternsKey,
|
|
@@ -30,6 +30,8 @@ function isObjectEmpty( object ) {
|
|
|
30
30
|
* - `updateBlockBindings`: Updates the value of the bindings connected to block attributes. It can be used to remove a specific binding by setting the value to `undefined`.
|
|
31
31
|
* - `removeAllBlockBindings`: Removes the bindings property of the `metadata` attribute.
|
|
32
32
|
*
|
|
33
|
+
* @param {?string} clientId Optional block client ID. If not set, it will use the current block client ID from the context.
|
|
34
|
+
*
|
|
33
35
|
* @return {?WPBlockBindingsUtils} Object containing the block bindings utils.
|
|
34
36
|
*
|
|
35
37
|
* @example
|
|
@@ -60,8 +62,9 @@ function isObjectEmpty( object ) {
|
|
|
60
62
|
* removeAllBlockBindings();
|
|
61
63
|
* ```
|
|
62
64
|
*/
|
|
63
|
-
export function useBlockBindingsUtils() {
|
|
64
|
-
const { clientId } = useBlockEditContext();
|
|
65
|
+
export function useBlockBindingsUtils( clientId ) {
|
|
66
|
+
const { clientId: contextClientId } = useBlockEditContext();
|
|
67
|
+
const blockClientId = clientId || contextClientId;
|
|
65
68
|
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
66
69
|
const { getBlockAttributes } = useRegistry().select( blockEditorStore );
|
|
67
70
|
|
|
@@ -96,7 +99,7 @@ export function useBlockBindingsUtils() {
|
|
|
96
99
|
*/
|
|
97
100
|
const updateBlockBindings = ( bindings ) => {
|
|
98
101
|
const { metadata: { bindings: currentBindings, ...metadata } = {} } =
|
|
99
|
-
getBlockAttributes(
|
|
102
|
+
getBlockAttributes( blockClientId );
|
|
100
103
|
const newBindings = { ...currentBindings };
|
|
101
104
|
|
|
102
105
|
Object.entries( bindings ).forEach( ( [ attribute, binding ] ) => {
|
|
@@ -116,7 +119,7 @@ export function useBlockBindingsUtils() {
|
|
|
116
119
|
delete newMetadata.bindings;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
updateBlockAttributes(
|
|
122
|
+
updateBlockAttributes( blockClientId, {
|
|
120
123
|
metadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,
|
|
121
124
|
} );
|
|
122
125
|
};
|
|
@@ -134,8 +137,8 @@ export function useBlockBindingsUtils() {
|
|
|
134
137
|
*/
|
|
135
138
|
const removeAllBlockBindings = () => {
|
|
136
139
|
const { metadata: { bindings, ...metadata } = {} } =
|
|
137
|
-
getBlockAttributes(
|
|
138
|
-
updateBlockAttributes(
|
|
140
|
+
getBlockAttributes( blockClientId );
|
|
141
|
+
updateBlockAttributes( blockClientId, {
|
|
139
142
|
metadata: isObjectEmpty( metadata ) ? undefined : metadata,
|
|
140
143
|
} );
|
|
141
144
|
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { renderHook } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
10
|
+
import { dispatch, select } from '@wordpress/data';
|
|
11
|
+
import {
|
|
12
|
+
createBlock,
|
|
13
|
+
getBlockTypes,
|
|
14
|
+
unregisterBlockType,
|
|
15
|
+
} from '@wordpress/blocks';
|
|
16
|
+
import { registerCoreBlocks } from '@wordpress/block-library';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import { useBlockBindingsUtils } from '../';
|
|
22
|
+
|
|
23
|
+
describe( 'useBlockBindingsUtils', () => {
|
|
24
|
+
beforeAll( () => {
|
|
25
|
+
// Register all core blocks
|
|
26
|
+
registerCoreBlocks();
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
let clientId;
|
|
30
|
+
beforeEach( async () => {
|
|
31
|
+
const block = createBlock( 'core/paragraph', {
|
|
32
|
+
metadata: {
|
|
33
|
+
name: 'Block name',
|
|
34
|
+
bindings: {
|
|
35
|
+
prop1: {
|
|
36
|
+
source: 'core/post-meta',
|
|
37
|
+
args: {
|
|
38
|
+
key: 'initial_key',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
prop2: {
|
|
42
|
+
source: 'core/post-meta',
|
|
43
|
+
args: {
|
|
44
|
+
key: 'initial_key',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
} );
|
|
50
|
+
await dispatch( blockEditorStore ).resetBlocks( [ block ] );
|
|
51
|
+
clientId = block.clientId;
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
afterAll( () => {
|
|
55
|
+
// Remove blocks after all tests.
|
|
56
|
+
dispatch( blockEditorStore ).resetBlocks( [] );
|
|
57
|
+
|
|
58
|
+
// Clean up registered blocks
|
|
59
|
+
getBlockTypes().forEach( ( block ) => {
|
|
60
|
+
unregisterBlockType( block.name );
|
|
61
|
+
} );
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
it( 'should be possible to update just one connection', async () => {
|
|
65
|
+
renderHook( () => {
|
|
66
|
+
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
67
|
+
updateBlockBindings( {
|
|
68
|
+
prop1: {
|
|
69
|
+
source: 'core/post-meta',
|
|
70
|
+
args: {
|
|
71
|
+
key: 'new_key',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
} );
|
|
75
|
+
} );
|
|
76
|
+
const { metadata } =
|
|
77
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
78
|
+
expect( metadata ).toMatchObject( {
|
|
79
|
+
// Other metadata properties shouldn't change.
|
|
80
|
+
name: 'Block name',
|
|
81
|
+
bindings: {
|
|
82
|
+
prop1: {
|
|
83
|
+
source: 'core/post-meta',
|
|
84
|
+
args: {
|
|
85
|
+
key: 'new_key',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
prop2: {
|
|
89
|
+
source: 'core/post-meta',
|
|
90
|
+
args: {
|
|
91
|
+
key: 'initial_key',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
} );
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
it( 'should be possible to update multiple connections at once', async () => {
|
|
99
|
+
renderHook( () => {
|
|
100
|
+
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
101
|
+
updateBlockBindings( {
|
|
102
|
+
prop1: {
|
|
103
|
+
source: 'core/post-meta',
|
|
104
|
+
args: {
|
|
105
|
+
key: 'new_key',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
prop2: {
|
|
109
|
+
source: 'core/post-meta',
|
|
110
|
+
args: {
|
|
111
|
+
key: 'new_key',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
} );
|
|
115
|
+
} );
|
|
116
|
+
const { metadata } =
|
|
117
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
118
|
+
expect( metadata ).toMatchObject( {
|
|
119
|
+
// Other metadata properties shouldn't change.
|
|
120
|
+
name: 'Block name',
|
|
121
|
+
bindings: {
|
|
122
|
+
prop1: {
|
|
123
|
+
source: 'core/post-meta',
|
|
124
|
+
args: {
|
|
125
|
+
key: 'new_key',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
prop2: {
|
|
129
|
+
source: 'core/post-meta',
|
|
130
|
+
args: {
|
|
131
|
+
key: 'new_key',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
} );
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
it( 'should be possible to remove connections', async () => {
|
|
139
|
+
renderHook( () => {
|
|
140
|
+
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
141
|
+
updateBlockBindings( {
|
|
142
|
+
prop2: undefined,
|
|
143
|
+
} );
|
|
144
|
+
} );
|
|
145
|
+
const { metadata } =
|
|
146
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
147
|
+
expect( metadata ).toMatchObject( {
|
|
148
|
+
// Other metadata properties shouldn't change.
|
|
149
|
+
name: 'Block name',
|
|
150
|
+
bindings: {
|
|
151
|
+
prop1: {
|
|
152
|
+
source: 'core/post-meta',
|
|
153
|
+
args: {
|
|
154
|
+
key: 'initial_key',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
} );
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
it( 'should be possible to remove all connections', async () => {
|
|
162
|
+
renderHook( () => {
|
|
163
|
+
const { removeAllBlockBindings } =
|
|
164
|
+
useBlockBindingsUtils( clientId );
|
|
165
|
+
removeAllBlockBindings();
|
|
166
|
+
} );
|
|
167
|
+
const { metadata } =
|
|
168
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
169
|
+
expect( metadata ).toMatchObject( {
|
|
170
|
+
// Other metadata properties shouldn't change.
|
|
171
|
+
name: 'Block name',
|
|
172
|
+
} );
|
|
173
|
+
} );
|
|
174
|
+
} );
|