-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathactions.js
580 lines (531 loc) · 12.4 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
/**
* External Dependencies
*/
import uuid from 'uuid/v4';
import { partial, castArray } from 'lodash';
/**
* Returns an action object used in signalling that editor has initialized with
* the specified post object and editor settings.
*
* @param {Object} post Post object
* @param {Object} settings Editor settings object
* @return {Object} Action object
*/
export function setupEditor( post, settings ) {
return {
type: 'SETUP_EDITOR',
post,
settings,
};
}
/**
* Returns an action object used in signalling that the latest version of the
* post has been received, either by initialization or save.
*
* @param {Object} post Post object
* @return {Object} Action object
*/
export function resetPost( post ) {
return {
type: 'RESET_POST',
post,
};
}
/**
* Returns an action object used in signalling that editor has initialized as a
* new post with specified edits which should be considered non-dirtying.
*
* @param {Object} edits Edited attributes object
* @return {Object} Action object
*/
export function setupNewPost( edits ) {
return {
type: 'SETUP_NEW_POST',
edits,
};
}
/**
* Returns an action object used in signalling that blocks state should be
* reset to the specified array of blocks, taking precedence over any other
* content reflected as an edit in state.
*
* @param {Array} blocks Array of blocks
* @return {Object} Action object
*/
export function resetBlocks( blocks ) {
return {
type: 'RESET_BLOCKS',
blocks,
};
}
/**
* Returns an action object used in signalling that the block attributes with the
* specified UID has been updated.
*
* @param {String} uid Block UID
* @param {Object} attributes Block attributes to be merged
* @return {Object} Action object
*/
export function updateBlockAttributes( uid, attributes ) {
return {
type: 'UPDATE_BLOCK_ATTRIBUTES',
uid,
attributes,
};
}
/**
* Returns an action object used in signalling that the block with the
* specified UID has been updated.
*
* @param {String} uid Block UID
* @param {Object} updates Block attributes to be merged
* @return {Object} Action object
*/
export function updateBlock( uid, updates ) {
return {
type: 'UPDATE_BLOCK',
uid,
updates,
};
}
export function focusBlock( uid, config ) {
return {
type: 'UPDATE_FOCUS',
uid,
config,
};
}
export function selectBlock( uid ) {
return {
type: 'SELECT_BLOCK',
uid,
};
}
export function startMultiSelect() {
return {
type: 'START_MULTI_SELECT',
};
}
export function stopMultiSelect() {
return {
type: 'STOP_MULTI_SELECT',
};
}
export function multiSelect( start, end ) {
return {
type: 'MULTI_SELECT',
start,
end,
};
}
export function clearSelectedBlock() {
return {
type: 'CLEAR_SELECTED_BLOCK',
};
}
/**
* Returns an action object signalling that a blocks should be replaced with
* one or more replacement blocks.
*
* @param {(String|String[])} uids Block UID(s) to replace
* @param {(Object|Object[])} blocks Replacement block(s)
* @return {Object} Action object
*/
export function replaceBlocks( uids, blocks ) {
return {
type: 'REPLACE_BLOCKS',
uids: castArray( uids ),
blocks: castArray( blocks ),
};
}
/**
* Returns an action object signalling that a single block should be replaced
* with one or more replacement blocks.
*
* @param {(String|String[])} uid Block UID(s) to replace
* @param {(Object|Object[])} block Replacement block(s)
* @return {Object} Action object
*/
export function replaceBlock( uid, block ) {
return replaceBlocks( uid, block );
}
export function insertBlock( block, position ) {
return insertBlocks( [ block ], position );
}
export function insertBlocks( blocks, position ) {
return {
type: 'INSERT_BLOCKS',
blocks: castArray( blocks ),
position,
};
}
export function showInsertionPoint() {
return {
type: 'SHOW_INSERTION_POINT',
};
}
export function hideInsertionPoint() {
return {
type: 'HIDE_INSERTION_POINT',
};
}
/**
* Returns an action object used in signalling that block insertion should
* occur at the specified block index position.
*
* @param {Number} position Position at which to insert
* @return {Object} Action object
*/
export function setBlockInsertionPoint( position ) {
return {
type: 'SET_BLOCK_INSERTION_POINT',
position,
};
}
/**
* Returns an action object used in signalling that the block insertion point
* should be reset.
*
* @return {Object} Action object
*/
export function clearBlockInsertionPoint() {
return {
type: 'CLEAR_BLOCK_INSERTION_POINT',
};
}
export function editPost( edits ) {
return {
type: 'EDIT_POST',
edits,
};
}
export function savePost() {
return {
type: 'REQUEST_POST_UPDATE',
};
}
export function trashPost( postId, postType ) {
return {
type: 'TRASH_POST',
postId,
postType,
};
}
export function mergeBlocks( blockA, blockB ) {
return {
type: 'MERGE_BLOCKS',
blocks: [ blockA, blockB ],
};
}
/**
* Returns an action object used in signalling that the post should autosave.
*
* @return {Object} Action object
*/
export function autosave() {
return {
type: 'AUTOSAVE',
};
}
/**
* Returns an action object used in signalling that undo history should
* restore last popped state.
*
* @return {Object} Action object
*/
export function redo() {
return { type: 'REDO' };
}
/**
* Returns an action object used in signalling that undo history should pop.
*
* @return {Object} Action object
*/
export function undo() {
return { type: 'UNDO' };
}
/**
* Returns an action object used in signalling that the blocks
* corresponding to the specified UID set are to be removed.
*
* @param {String[]} uids Block UIDs
* @return {Object} Action object
*/
export function removeBlocks( uids ) {
return {
type: 'REMOVE_BLOCKS',
uids,
};
}
/**
* Returns an action object used in signalling that the block with the
* specified UID is to be removed.
*
* @param {String} uid Block UID
* @return {Object} Action object
*/
export function removeBlock( uid ) {
return removeBlocks( [ uid ] );
}
/**
* Returns an action object used to toggle the block editing mode (visual/html)
*
* @param {String} uid Block UID
* @return {Object} Action object
*/
export function toggleBlockMode( uid ) {
return {
type: 'TOGGLE_BLOCK_MODE',
uid,
};
}
/**
* Returns an action object used in signalling that the user has begun to type.
*
* @return {Object} Action object
*/
export function startTyping() {
return {
type: 'START_TYPING',
};
}
/**
* Returns an action object used in signalling that the user has stopped typing.
*
* @return {Object} Action object
*/
export function stopTyping() {
return {
type: 'STOP_TYPING',
};
}
/**
* Returns an action object used in signalling that the user toggled the sidebar
*
* @return {Object} Action object
*/
export function toggleSidebar() {
return {
type: 'TOGGLE_SIDEBAR',
};
}
/**
* Returns an action object used in signalling that the user switched the active sidebar tab panel
*
* @param {String} panel The panel name
* @return {Object} Action object
*/
export function setActivePanel( panel ) {
return {
type: 'SET_ACTIVE_PANEL',
panel,
};
}
/**
* Returns an action object used in signalling that the user toggled a sidebar panel
*
* @param {String} panel The panel name
* @return {Object} Action object
*/
export function toggleSidebarPanel( panel ) {
return {
type: 'TOGGLE_SIDEBAR_PANEL',
panel,
};
}
/**
* Returns an action object used to create a notice
*
* @param {String} status The notice status
* @param {WPElement} content The notice content
* @param {?Object} options The notice options. Available options:
* `id` (string; default auto-generated)
* `isDismissible` (boolean; default `true`)
*
* @return {Object} Action object
*/
export function createNotice( status, content, options = {} ) {
const {
id = uuid(),
isDismissible = true,
} = options;
return {
type: 'CREATE_NOTICE',
notice: {
id,
status,
content,
isDismissible,
},
};
}
/**
* Returns an action object used to remove a notice
*
* @param {String} id The notice id
*
* @return {Object} Action object
*/
export function removeNotice( id ) {
return {
type: 'REMOVE_NOTICE',
noticeId: id,
};
}
/**
* Returns an action object used to check the state of meta boxes at a location.
*
* This should only be fired once to initialize meta box state. If a meta box
* area is empty, this will set the store state to indicate that React should
* not render the meta box area.
*
* Example: metaBoxes = { side: true, normal: false }
* This indicates that the sidebar has a meta box but the normal area does not.
*
* @param {Object} metaBoxes Whether meta box locations are active.
*
* @return {Object} Action object
*/
export function initializeMetaBoxState( metaBoxes ) {
return {
type: 'INITIALIZE_META_BOX_STATE',
metaBoxes,
};
}
/**
* Returns an action object used to signify that a meta box finished reloading.
*
* @param {String} location Location of meta box: 'normal', 'side'.
*
* @return {Object} Action object
*/
export function handleMetaBoxReload( location ) {
return {
type: 'HANDLE_META_BOX_RELOAD',
location,
};
}
/**
* Returns an action object used to signify that a meta box finished loading.
*
* @param {String} location Location of meta box: 'normal', 'side'.
*
* @return {Object} Action object
*/
export function metaBoxLoaded( location ) {
return {
type: 'META_BOX_LOADED',
location,
};
}
/**
* Returns an action object used to request meta box update.
*
* @param {Array} locations Locations of meta boxes: ['normal', 'side' ].
*
* @return {Object} Action object
*/
export function requestMetaBoxUpdates( locations ) {
return {
type: 'REQUEST_META_BOX_UPDATES',
locations,
};
}
/**
* Returns an action object used to set meta box state changed.
*
* @param {String} location Location of meta box: 'normal', 'side'.
* @param {Boolean} hasChanged Whether the meta box has changed.
*
* @return {Object} Action object
*/
export function metaBoxStateChanged( location, hasChanged ) {
return {
type: 'META_BOX_STATE_CHANGED',
location,
hasChanged,
};
}
/**
* Returns an action object used to toggle a feature flag
*
* @param {String} feature Featurre name.
*
* @return {Object} Action object
*/
export function toggleFeature( feature ) {
return {
type: 'TOGGLE_FEATURE',
feature,
};
}
export const createSuccessNotice = partial( createNotice, 'success' );
export const createInfoNotice = partial( createNotice, 'info' );
export const createErrorNotice = partial( createNotice, 'error' );
export const createWarningNotice = partial( createNotice, 'warning' );
/**
* Returns an action object used to fetch a single reusable block or all
* reusable blocks from the REST API into the store.
*
* @param {?string} id If given, only a single reusable block with this ID will be fetched
* @return {Object} Action object
*/
export function fetchReusableBlocks( id ) {
return {
type: 'FETCH_REUSABLE_BLOCKS',
id,
};
}
/**
* Returns an action object used to insert or update a reusable block into the store.
*
* @param {Object} id The ID of the reusable block to update
* @param {Object} reusableBlock The new reusable block object. Any omitted keys are not changed
* @return {Object} Action object
*/
export function updateReusableBlock( id, reusableBlock ) {
return {
type: 'UPDATE_REUSABLE_BLOCK',
id,
reusableBlock,
};
}
/**
* Returns an action object used to save a reusable block that's in the store
* to the REST API.
*
* @param {Object} id The ID of the reusable block to save
* @return {Object} Action object
*/
export function saveReusableBlock( id ) {
return {
type: 'SAVE_REUSABLE_BLOCK',
id,
};
}
/**
* Returns an action object used to convert a reusable block into a static
* block.
*
* @param {Object} uid The ID of the block to attach
* @return {Object} Action object
*/
export function convertBlockToStatic( uid ) {
return {
type: 'CONVERT_BLOCK_TO_STATIC',
uid,
};
}
/**
* Returns an action object used to convert a static block into a reusable
* block.
*
* @param {Object} uid The ID of the block to detach
* @return {Object} Action object
*/
export function convertBlockToReusable( uid ) {
return {
type: 'CONVERT_BLOCK_TO_REUSABLE',
uid,
};
}