-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
actions.js
319 lines (298 loc) · 8.71 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
/**
* Internal dependencies
*/
import { processBlockType } from './process-block-type';
/** @typedef {import('../api/registration').WPBlockVariation} WPBlockVariation */
/** @typedef {import('../api/registration').WPBlockType} WPBlockType */
/** @typedef {import('./reducer').WPBlockCategory} WPBlockCategory */
/**
* Returns an action object used in signalling that block types have been added.
* Ignored from documentation as the recommended usage for this action through registerBlockType from @wordpress/blocks.
*
* @ignore
*
* @param {WPBlockType|WPBlockType[]} blockTypes Object or array of objects representing blocks to added.
*
*
* @return {Object} Action object.
*/
export function addBlockTypes( blockTypes ) {
return {
type: 'ADD_BLOCK_TYPES',
blockTypes: Array.isArray( blockTypes ) ? blockTypes : [ blockTypes ],
};
}
/**
* Signals that all block types should be computed again.
* It uses stored unprocessed block types and all the most recent list of registered filters.
*
* It addresses the issue where third party block filters get registered after third party blocks. A sample sequence:
* 1. Filter A.
* 2. Block B.
* 3. Block C.
* 4. Filter D.
* 5. Filter E.
* 6. Block F.
* 7. Filter G.
* In this scenario some filters would not get applied for all blocks because they are registered too late.
*/
export function reapplyBlockTypeFilters() {
return ( { dispatch, select } ) => {
const processedBlockTypes = [];
for ( const [ name, settings ] of Object.entries(
select.getUnprocessedBlockTypes()
) ) {
const result = dispatch( processBlockType( name, settings ) );
if ( result ) {
processedBlockTypes.push( result );
}
}
if ( ! processedBlockTypes.length ) {
return;
}
dispatch.addBlockTypes( processedBlockTypes );
};
}
export function __experimentalReapplyBlockFilters() {
deprecated(
'wp.data.dispatch( "core/blocks" ).__experimentalReapplyBlockFilters',
{
since: '6.4',
alternative: 'reapplyBlockFilters',
}
);
return reapplyBlockTypeFilters();
}
/**
* Returns an action object used to remove a registered block type.
* Ignored from documentation as the recommended usage for this action through unregisterBlockType from @wordpress/blocks.
*
* @ignore
*
* @param {string|string[]} names Block name or array of block names to be removed.
*
*
* @return {Object} Action object.
*/
export function removeBlockTypes( names ) {
return {
type: 'REMOVE_BLOCK_TYPES',
names: Array.isArray( names ) ? names : [ names ],
};
}
/**
* Returns an action object used in signalling that new block styles have been added.
* Ignored from documentation as the recommended usage for this action through registerBlockStyle from @wordpress/blocks.
*
* @param {string|Array} blockNames Block names to register new styles for.
* @param {Array|Object} styles Block style object or array of block style objects.
*
* @ignore
*
* @return {Object} Action object.
*/
export function addBlockStyles( blockNames, styles ) {
return {
type: 'ADD_BLOCK_STYLES',
styles: Array.isArray( styles ) ? styles : [ styles ],
blockNames: Array.isArray( blockNames ) ? blockNames : [ blockNames ],
};
}
/**
* Returns an action object used in signalling that block styles have been removed.
* Ignored from documentation as the recommended usage for this action through unregisterBlockStyle from @wordpress/blocks.
*
* @ignore
*
* @param {string} blockName Block name.
* @param {Array|string} styleNames Block style names or array of block style names.
*
* @return {Object} Action object.
*/
export function removeBlockStyles( blockName, styleNames ) {
return {
type: 'REMOVE_BLOCK_STYLES',
styleNames: Array.isArray( styleNames ) ? styleNames : [ styleNames ],
blockName,
};
}
/**
* Returns an action object used in signalling that new block variations have been added.
* Ignored from documentation as the recommended usage for this action through registerBlockVariation from @wordpress/blocks.
*
* @ignore
*
* @param {string} blockName Block name.
* @param {WPBlockVariation|WPBlockVariation[]} variations Block variations.
*
* @return {Object} Action object.
*/
export function addBlockVariations( blockName, variations ) {
return {
type: 'ADD_BLOCK_VARIATIONS',
variations: Array.isArray( variations ) ? variations : [ variations ],
blockName,
};
}
/**
* Returns an action object used in signalling that block variations have been removed.
* Ignored from documentation as the recommended usage for this action through unregisterBlockVariation from @wordpress/blocks.
*
* @ignore
*
* @param {string} blockName Block name.
* @param {string|string[]} variationNames Block variation names.
*
* @return {Object} Action object.
*/
export function removeBlockVariations( blockName, variationNames ) {
return {
type: 'REMOVE_BLOCK_VARIATIONS',
variationNames: Array.isArray( variationNames )
? variationNames
: [ variationNames ],
blockName,
};
}
/**
* Returns an action object used to set the default block name.
* Ignored from documentation as the recommended usage for this action through setDefaultBlockName from @wordpress/blocks.
*
* @ignore
*
* @param {string} name Block name.
*
* @return {Object} Action object.
*/
export function setDefaultBlockName( name ) {
return {
type: 'SET_DEFAULT_BLOCK_NAME',
name,
};
}
/**
* Returns an action object used to set the name of the block used as a fallback
* for non-block content.
* Ignored from documentation as the recommended usage for this action through setFreeformContentHandlerName from @wordpress/blocks.
*
* @ignore
*
* @param {string} name Block name.
*
* @return {Object} Action object.
*/
export function setFreeformFallbackBlockName( name ) {
return {
type: 'SET_FREEFORM_FALLBACK_BLOCK_NAME',
name,
};
}
/**
* Returns an action object used to set the name of the block used as a fallback
* for unregistered blocks.
* Ignored from documentation as the recommended usage for this action through setUnregisteredTypeHandlerName from @wordpress/blocks.
*
* @ignore
*
* @param {string} name Block name.
*
* @return {Object} Action object.
*/
export function setUnregisteredFallbackBlockName( name ) {
return {
type: 'SET_UNREGISTERED_FALLBACK_BLOCK_NAME',
name,
};
}
/**
* Returns an action object used to set the name of the block used
* when grouping other blocks
* eg: in "Group/Ungroup" interactions
* Ignored from documentation as the recommended usage for this action through setGroupingBlockName from @wordpress/blocks.
*
* @ignore
*
* @param {string} name Block name.
*
* @return {Object} Action object.
*/
export function setGroupingBlockName( name ) {
return {
type: 'SET_GROUPING_BLOCK_NAME',
name,
};
}
/**
* Returns an action object used to set block categories.
* Ignored from documentation as the recommended usage for this action through setCategories from @wordpress/blocks.
*
* @ignore
*
* @param {WPBlockCategory[]} categories Block categories.
*
* @return {Object} Action object.
*/
export function setCategories( categories ) {
return {
type: 'SET_CATEGORIES',
categories,
};
}
/**
* Returns an action object used to update a category.
* Ignored from documentation as the recommended usage for this action through updateCategory from @wordpress/blocks.
*
* @ignore
*
* @param {string} slug Block category slug.
* @param {Object} category Object containing the category properties that should be updated.
*
* @return {Object} Action object.
*/
export function updateCategory( slug, category ) {
return {
type: 'UPDATE_CATEGORY',
slug,
category,
};
}
/**
* Returns an action object used to add block collections
* Ignored from documentation as the recommended usage for this action through registerBlockCollection from @wordpress/blocks.
*
* @ignore
*
* @param {string} namespace The namespace of the blocks to put in the collection
* @param {string} title The title to display in the block inserter
* @param {Object} icon (optional) The icon to display in the block inserter
*
* @return {Object} Action object.
*/
export function addBlockCollection( namespace, title, icon ) {
return {
type: 'ADD_BLOCK_COLLECTION',
namespace,
title,
icon,
};
}
/**
* Returns an action object used to remove block collections
* Ignored from documentation as the recommended usage for this action through unregisterBlockCollection from @wordpress/blocks.
*
* @ignore
*
* @param {string} namespace The namespace of the blocks to put in the collection
*
* @return {Object} Action object.
*/
export function removeBlockCollection( namespace ) {
return {
type: 'REMOVE_BLOCK_COLLECTION',
namespace,
};
}