-
Notifications
You must be signed in to change notification settings - Fork 82
/
actions.js
371 lines (328 loc) · 6.97 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
import { mergeDeep } from "timm";
import _ from "underscore";
import { uuid } from "visual/utils/uuid";
import { fontSelector } from "./selectors";
export const HYDRATE = "HYDRATE";
export const EDITOR_RENDERED = "EDITOR_RENDERED";
export const UPDATE_PAGE = "UPDATE_PAGE";
export const UPDATE_BLOCKS = "UPDATE_BLOCKS";
export const ADD_BLOCK = "ADD_BLOCK";
export const REMOVE_BLOCK = "REMOVE_BLOCK";
export const REORDER_BLOCKS = "REORDER_BLOCKS";
export const CREATE_GLOBAL_BLOCK = "CREATE_GLOBAL_BLOCK";
export const UPDATE_GLOBAL_BLOCK = "UPDATE_GLOBAL_BLOCK";
export const DELETE_GLOBAL_BLOCK = "DELETE_GLOBAL_BLOCK";
export const CREATE_SAVED_BLOCK = "CREATE_SAVED_BLOCK";
export const UPDATE_SAVED_BLOCK = "UPDATE_SAVED_BLOCK";
export const DELETE_SAVED_BLOCK = "DELETE_SAVED_BLOCK";
export const CREATE_RULES = "CREATE_RULES";
export const UPDATE_RULES = "UPDATE_RULES";
export const UPDATE_UI = "UPDATE_UI";
export const COPY_ELEMENT = "COPY_ELEMENT";
export const IMPORT_TEMPLATE = "IMPORT_TEMPLATE";
export const IMPORT_KIT = "IMPORT_KIT";
export const UPDATE_CURRENT_KIT_ID = "UPDATE_CURRENT_KIT_ID";
export const UPDATE_CURRENT_STYLE_ID = "UPDATE_CURRENT_STYLE_ID";
export const UPDATE_CURRENT_STYLE = "UPDATE_CURRENT_STYLE";
export const UPDATE_EXTRA_FONT_STYLES = "UPDATE_EXTRA_FONT_STYLES";
export const PUBLISH = "PUBLISH";
export const ADD_FONTS = "ADD_FONTS";
export const DELETE_FONTS = "DELETE_FONTS";
export const UPDATE_SCREENSHOT = "UPDATE_SCREENSHOT";
export const UPDATE_DISABLED_ELEMENTS = "UPDATE_DISABLED_ELEMENTS";
export const UPDATE_TRIGGERS = "UPDATE_TRIGGERS";
export function hydrate({
project,
fonts,
page,
globalBlocks,
savedBlocks,
blocksThumbnailSizes
}) {
return {
type: HYDRATE,
payload: {
project,
fonts,
page,
globalBlocks,
savedBlocks,
blocksThumbnailSizes
}
};
}
export function editorRendered() {
return {
type: EDITOR_RENDERED
};
}
// project
export function updateCurrentStyleId(id) {
return {
type: UPDATE_CURRENT_STYLE_ID,
payload: id
};
}
export function updateCurrentStyle(currentStyle) {
return {
type: UPDATE_CURRENT_STYLE,
payload: currentStyle
};
}
export function updateExtraFontStyles(extraFontStyles) {
return {
type: UPDATE_EXTRA_FONT_STYLES,
payload: extraFontStyles
};
}
export function updateCurrentKitId(id) {
return {
type: UPDATE_CURRENT_KIT_ID,
payload: id
};
}
export function publish() {
return dispatch => {
return new Promise((res, rej) => {
dispatch({
type: PUBLISH,
meta: {
onSuccess: res,
onError: rej
}
});
});
};
}
export function addFonts(addedFonts) {
return (dispatch, getState) => {
const usedFonts = fontSelector(getState());
const newFonts = addedFonts.reduce((acc, curr) => {
const { type, fonts } = curr;
const fontData = (usedFonts[type] && usedFonts[type].data) || [];
// Separated Deleted Font with Normal Font
const [deletedFonts, normalFont] = _.partition(fonts, font =>
font.hasOwnProperty("deleted")
);
const newFonts = normalFont.map(font => ({ ...font, brizyId: uuid() }));
// Make new Data, check deleted Font
return {
...acc,
[`${type}`]: {
data: fontData
.map(
font =>
deletedFonts.find(({ brizyId }) => font.brizyId === brizyId) ||
font
)
.concat(newFonts)
}
};
}, {});
return dispatch({
type: ADD_FONTS,
payload: mergeDeep(usedFonts, newFonts)
});
};
}
export function deleteFont({ type, fonts: removedFonts }) {
return (dispatch, getState) => {
const fonts = fontSelector(getState());
const fontData = (fonts[type] && fonts[type].data) || [];
const dataFonts = {
[`${type}`]: {
data: fontData.map(font =>
removedFonts.some(({ brizyId }) => brizyId === font.brizyId)
? { ...font, deleted: true }
: font
)
}
};
return dispatch({
type: DELETE_FONTS,
payload: mergeDeep(fonts, dataFonts)
});
};
}
export function updateRules({ data, meta }) {
return {
type: UPDATE_RULES,
payload: data,
meta
};
}
// pages
export function updatePage({ data, status, meta }) {
return {
type: UPDATE_PAGE,
payload: {
data,
...(status ? { status } : {})
},
meta: {
is_autosave: 1,
...meta
}
};
}
export function updateBlocks({ blocks, meta }) {
return {
type: UPDATE_BLOCKS,
payload: {
blocks
},
meta: {
is_autosave: 1,
...meta
}
};
}
export function addBlock(block, meta = {}) {
return {
type: ADD_BLOCK,
payload: block,
meta
};
}
export function removeBlock({ index }) {
return {
type: REMOVE_BLOCK,
payload: {
index
}
};
}
export function reorderBlocks({ oldIndex, newIndex }) {
return {
type: REORDER_BLOCKS,
payload: {
oldIndex,
newIndex
}
};
}
// globalBlocks
export function createGlobalBlock({ id, data, meta }) {
return {
type: CREATE_GLOBAL_BLOCK,
payload: {
id,
data
},
meta
};
}
export function updateGlobalBlock({ id, data, meta }) {
return {
type: UPDATE_GLOBAL_BLOCK,
payload: {
id,
data
},
meta: {
is_autosave: 1,
...meta
}
};
}
export function deleteGlobalBlock({ id }) {
return {
type: DELETE_GLOBAL_BLOCK,
payload: {
id
}
};
}
// saved blocks
export function createSavedBlock({ id, data, meta }) {
return {
type: CREATE_SAVED_BLOCK,
payload: {
id,
data
},
meta
};
}
export function updateSavedBlock({ id, data, meta }) {
return {
type: UPDATE_SAVED_BLOCK,
payload: {
id,
data
},
meta: {
is_autosave: 0,
...meta
}
};
}
export function deleteSavedBlock({ id, meta }) {
return {
type: DELETE_SAVED_BLOCK,
payload: {
id
},
meta
};
}
// templates
export function importTemplate(template, meta = {}) {
return {
type: IMPORT_TEMPLATE,
payload: template,
meta
};
}
// kits
export function importKit(kit) {
return {
type: IMPORT_KIT,
payload: kit
};
}
// ui
export function updateUI(key, value) {
return {
type: UPDATE_UI,
key,
value
};
}
export function setDeviceMode(mode) {
return updateUI("deviceMode", mode);
}
// copy
export function updateCopiedElement(value) {
return {
type: COPY_ELEMENT,
value
};
}
// disabled elements
export function updateDisabledElements(value) {
return {
type: UPDATE_DISABLED_ELEMENTS,
payload: value
};
}
// update triggers
export function updateTriggers(data, meta) {
return {
type: UPDATE_TRIGGERS,
payload: {
data
},
meta
};
}
export function updateScreenshot({ blockId, data, meta }) {
return {
type: UPDATE_SCREENSHOT,
payload: {
blockId,
data
},
meta
};
}