@wordpress/block-editor 15.6.1 → 15.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +2 -2
- package/build/hooks/allowed-blocks.js +50 -1
- package/build/hooks/allowed-blocks.js.map +2 -2
- package/build/hooks/block-bindings.js +6 -2
- package/build/hooks/block-bindings.js.map +2 -2
- package/build/hooks/fit-text.js +24 -3
- package/build/hooks/fit-text.js.map +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +2 -2
- package/build-module/hooks/allowed-blocks.js +49 -1
- package/build-module/hooks/allowed-blocks.js.map +2 -2
- package/build-module/hooks/block-bindings.js +6 -2
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/fit-text.js +24 -3
- package/build-module/hooks/fit-text.js.map +2 -2
- package/package.json +2 -2
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/hooks/allowed-blocks.js +89 -1
- package/src/hooks/block-bindings.js +6 -2
- package/src/hooks/fit-text.js +37 -5
- package/src/hooks/test/allowed-blocks.js +278 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
getBlockTypes,
|
|
6
|
+
registerBlockType,
|
|
7
|
+
unregisterBlockType,
|
|
8
|
+
} from '@wordpress/blocks';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { addTransforms } from '../allowed-blocks';
|
|
14
|
+
|
|
15
|
+
describe( 'allowedBlocks', () => {
|
|
16
|
+
afterEach( () => {
|
|
17
|
+
getBlockTypes().forEach( ( block ) => {
|
|
18
|
+
unregisterBlockType( block.name );
|
|
19
|
+
} );
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
describe( 'addTransforms()', () => {
|
|
23
|
+
it( 'should not preserve allowedBlocks in wrapping transforms', () => {
|
|
24
|
+
registerBlockType( 'core/bar', {
|
|
25
|
+
title: 'Bar',
|
|
26
|
+
supports: { allowedBlocks: true },
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
const source = [
|
|
30
|
+
{
|
|
31
|
+
name: 'core/foo',
|
|
32
|
+
attributes: {
|
|
33
|
+
allowedBlocks: [ 'core/paragraph', 'core/heading' ],
|
|
34
|
+
},
|
|
35
|
+
innerBlocks: [],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'core/foo',
|
|
39
|
+
attributes: { allowedBlocks: [ 'core/paragraph' ] },
|
|
40
|
+
innerBlocks: [],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
const result = {
|
|
44
|
+
name: 'core/bar',
|
|
45
|
+
attributes: {},
|
|
46
|
+
innerBlocks: source,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
50
|
+
|
|
51
|
+
expect( transformed.attributes.allowedBlocks ).toBeUndefined();
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
it( 'should not preserve allowedBlocks in one-to-many transforms', () => {
|
|
55
|
+
registerBlockType( 'core/bar', {
|
|
56
|
+
title: 'Bar',
|
|
57
|
+
supports: { allowedBlocks: true },
|
|
58
|
+
} );
|
|
59
|
+
|
|
60
|
+
const source = [
|
|
61
|
+
{
|
|
62
|
+
name: 'core/foo',
|
|
63
|
+
attributes: {
|
|
64
|
+
allowedBlocks: [ 'core/paragraph', 'core/heading' ],
|
|
65
|
+
},
|
|
66
|
+
innerBlocks: [],
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
const results = [
|
|
70
|
+
{ name: 'core/bar', attributes: {}, innerBlocks: [] },
|
|
71
|
+
{ name: 'core/bar', attributes: {}, innerBlocks: [] },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const transformed = addTransforms(
|
|
75
|
+
results[ 0 ],
|
|
76
|
+
source,
|
|
77
|
+
0,
|
|
78
|
+
results
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect( transformed.attributes.allowedBlocks ).toBeUndefined();
|
|
82
|
+
} );
|
|
83
|
+
|
|
84
|
+
it( 'should not preserve allowedBlocks in many-to-one transforms', () => {
|
|
85
|
+
registerBlockType( 'core/bar', {
|
|
86
|
+
title: 'Bar',
|
|
87
|
+
supports: { allowedBlocks: true },
|
|
88
|
+
} );
|
|
89
|
+
|
|
90
|
+
const source = [
|
|
91
|
+
{
|
|
92
|
+
name: 'core/foo',
|
|
93
|
+
attributes: {
|
|
94
|
+
allowedBlocks: [ 'core/paragraph', 'core/heading' ],
|
|
95
|
+
},
|
|
96
|
+
innerBlocks: [],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'core/foo',
|
|
100
|
+
attributes: { allowedBlocks: [ 'core/paragraph' ] },
|
|
101
|
+
innerBlocks: [],
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
const result = {
|
|
105
|
+
name: 'core/bar',
|
|
106
|
+
attributes: {},
|
|
107
|
+
innerBlocks: [],
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
111
|
+
|
|
112
|
+
expect( transformed.attributes.allowedBlocks ).toBeUndefined();
|
|
113
|
+
} );
|
|
114
|
+
|
|
115
|
+
it( 'should not preserve allowedBlocks in many-to-many transforms with different counts', () => {
|
|
116
|
+
registerBlockType( 'core/bar', {
|
|
117
|
+
title: 'Bar',
|
|
118
|
+
supports: { allowedBlocks: true },
|
|
119
|
+
} );
|
|
120
|
+
|
|
121
|
+
const source = [
|
|
122
|
+
{
|
|
123
|
+
name: 'core/foo',
|
|
124
|
+
attributes: {
|
|
125
|
+
allowedBlocks: [ 'core/paragraph', 'core/heading' ],
|
|
126
|
+
},
|
|
127
|
+
innerBlocks: [],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'core/foo',
|
|
131
|
+
attributes: { allowedBlocks: [ 'core/paragraph' ] },
|
|
132
|
+
innerBlocks: [],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'core/foo',
|
|
136
|
+
attributes: { allowedBlocks: [ 'core/heading' ] },
|
|
137
|
+
innerBlocks: [],
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
const results = [
|
|
141
|
+
{ name: 'core/bar', attributes: {}, innerBlocks: [] },
|
|
142
|
+
{ name: 'core/bar', attributes: {}, innerBlocks: [] },
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const [ firstTransformed, secondTransformed ] = results.map(
|
|
146
|
+
( result, index ) =>
|
|
147
|
+
addTransforms( result, source, index, results )
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
expect( firstTransformed.attributes.allowedBlocks ).toBeUndefined();
|
|
151
|
+
expect(
|
|
152
|
+
secondTransformed.attributes.allowedBlocks
|
|
153
|
+
).toBeUndefined();
|
|
154
|
+
} );
|
|
155
|
+
|
|
156
|
+
it( 'should preserve allowedBlocks in many-to-many transforms with same counts', () => {
|
|
157
|
+
registerBlockType( 'core/bar', {
|
|
158
|
+
title: 'Bar',
|
|
159
|
+
supports: { allowedBlocks: true },
|
|
160
|
+
} );
|
|
161
|
+
|
|
162
|
+
const source = [
|
|
163
|
+
{
|
|
164
|
+
name: 'core/foo',
|
|
165
|
+
attributes: {
|
|
166
|
+
allowedBlocks: [ 'core/image', 'core/heading' ],
|
|
167
|
+
},
|
|
168
|
+
innerBlocks: [],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: 'core/foo',
|
|
172
|
+
attributes: { allowedBlocks: [ 'core/paragraph' ] },
|
|
173
|
+
innerBlocks: [],
|
|
174
|
+
},
|
|
175
|
+
];
|
|
176
|
+
const results = [
|
|
177
|
+
{ name: 'core/bar', attributes: {}, innerBlocks: [] },
|
|
178
|
+
{ name: 'core/bar', attributes: {}, innerBlocks: [] },
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const [ firstTransformed, secondTransformed ] = results.map(
|
|
182
|
+
( result, index ) =>
|
|
183
|
+
addTransforms( result, source, index, results )
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
expect( firstTransformed.attributes.allowedBlocks ).toEqual( [
|
|
187
|
+
'core/image',
|
|
188
|
+
'core/heading',
|
|
189
|
+
] );
|
|
190
|
+
expect( secondTransformed.attributes.allowedBlocks ).toEqual( [
|
|
191
|
+
'core/paragraph',
|
|
192
|
+
] );
|
|
193
|
+
} );
|
|
194
|
+
|
|
195
|
+
it( "should filter allowedBlocks based on destination block's allowedBlocks", () => {
|
|
196
|
+
registerBlockType( 'core/bar', {
|
|
197
|
+
title: 'Bar',
|
|
198
|
+
supports: { allowedBlocks: true },
|
|
199
|
+
allowedBlocks: [ 'core/paragraph' ],
|
|
200
|
+
} );
|
|
201
|
+
|
|
202
|
+
const source = [
|
|
203
|
+
{
|
|
204
|
+
name: 'core/foo',
|
|
205
|
+
attributes: {
|
|
206
|
+
allowedBlocks: [
|
|
207
|
+
'core/paragraph',
|
|
208
|
+
'core/heading',
|
|
209
|
+
'core/image',
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
innerBlocks: [],
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
const result = {
|
|
216
|
+
name: 'core/bar',
|
|
217
|
+
attributes: {},
|
|
218
|
+
innerBlocks: [],
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
222
|
+
|
|
223
|
+
expect( transformed.attributes.allowedBlocks ).toEqual( [
|
|
224
|
+
'core/paragraph',
|
|
225
|
+
] );
|
|
226
|
+
} );
|
|
227
|
+
|
|
228
|
+
it( 'should not override existing allowedBlocks in target block', () => {
|
|
229
|
+
registerBlockType( 'core/bar', {
|
|
230
|
+
title: 'Bar',
|
|
231
|
+
supports: { allowedBlocks: true },
|
|
232
|
+
} );
|
|
233
|
+
|
|
234
|
+
const source = [
|
|
235
|
+
{
|
|
236
|
+
name: 'core/foo',
|
|
237
|
+
attributes: { allowedBlocks: [ 'core/paragraph' ] },
|
|
238
|
+
innerBlocks: [],
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
const result = {
|
|
242
|
+
name: 'core/bar',
|
|
243
|
+
attributes: { allowedBlocks: [ 'core/heading' ] },
|
|
244
|
+
innerBlocks: [],
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
248
|
+
|
|
249
|
+
expect( transformed.attributes.allowedBlocks ).toEqual( [
|
|
250
|
+
'core/heading',
|
|
251
|
+
] );
|
|
252
|
+
} );
|
|
253
|
+
|
|
254
|
+
it( 'should not preserve allowedBlocks when target block does not support allowedBlocks', () => {
|
|
255
|
+
registerBlockType( 'core/bar', {
|
|
256
|
+
title: 'Bar',
|
|
257
|
+
} );
|
|
258
|
+
|
|
259
|
+
const source = [
|
|
260
|
+
{
|
|
261
|
+
name: 'core/foo',
|
|
262
|
+
attributes: {
|
|
263
|
+
allowedBlocks: [ 'core/paragraph', 'core/heading' ],
|
|
264
|
+
},
|
|
265
|
+
innerBlocks: [],
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
const result = {
|
|
269
|
+
name: 'core/bar',
|
|
270
|
+
attributes: {},
|
|
271
|
+
innerBlocks: [],
|
|
272
|
+
};
|
|
273
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
274
|
+
|
|
275
|
+
expect( transformed.attributes.allowedBlocks ).toBeUndefined();
|
|
276
|
+
} );
|
|
277
|
+
} );
|
|
278
|
+
} );
|