/
actions.js
238 lines (213 loc) · 4.29 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
/**
* External Dependencies
*/
import uuid from 'uuid/v4';
import { partial } from 'lodash';
/**
* Returns an action object used in signalling that the block 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,
};
}
export function focusBlock( uid, config ) {
return {
type: 'UPDATE_FOCUS',
uid,
config,
};
}
export function deselectBlock( uid ) {
return {
type: 'TOGGLE_BLOCK_SELECTED',
selected: false,
uid,
};
}
export function multiSelect( start, end ) {
return {
type: 'MULTI_SELECT',
start,
end,
};
}
export function clearSelectedBlock() {
return {
type: 'CLEAR_SELECTED_BLOCK',
};
}
export function replaceBlocks( uids, blocks ) {
return {
type: 'REPLACE_BLOCKS',
uids,
blocks,
};
}
export function insertBlock( block, after ) {
return insertBlocks( [ block ], after );
}
export function insertBlocks( blocks, after ) {
return {
type: 'INSERT_BLOCKS',
blocks,
after,
};
}
export function showInsertionPoint() {
return {
type: 'SHOW_INSERTION_POINT',
};
}
export function hideInsertionPoint() {
return {
type: 'HIDE_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 the post should be queued
* for autosave after a delay.
*
* @return {Object} Action object
*/
export function queueAutosave() {
return {
type: 'QUEUE_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 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 to create a notice
*
* @param {String} status The notice status
* @param {WPElement} content The notice content
* @param {String} id The notice id
*
* @return {Object} Action object
*/
export function createNotice( status, content, id = uuid() ) {
return {
type: 'CREATE_NOTICE',
notice: {
id,
status,
content,
},
};
}
/**
* 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,
};
}
export const createSuccessNotice = partial( createNotice, 'success' );
export const createErrorNotice = partial( createNotice, 'error' );
export const createWarningNotice = partial( createNotice, 'warning' );