Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
export const deactivateElement = createAction(DEACTIVATE_ELEMENT);
addReducer([DEACTIVATE_ELEMENT], "ui.activeElement", () => null);
export const focusSlateEditor = createAction(FOCUS_SLATE_EDITOR);
addReducer([FOCUS_SLATE_EDITOR], "ui.slateFocused", () => true);
export const blurSlateEditor = createAction(BLUR_SLATE_EDITOR);
addReducer([BLUR_SLATE_EDITOR], "ui.slateFocused", () => false);
export const dragStart = createAction(DRAG_START);
addReducer([DRAG_START], "ui.dragging", () => true);
export const dragEnd = createAction(DRAG_END);
addReducer([DRAG_END], "ui.dragging", () => false);
export const elementCreated = createAction(ELEMENT_CREATED);
export const updateElement = createAction(UPDATE_ELEMENT);
addReducer(
[UPDATE_ELEMENT],
action => {
const { element } = action.payload;
if (element.type === "document") {
return "page.content";
}
// .slice(2) removes `0.` from the beginning of the generated path
return "page.content." + action.payload.element.path.replace(/\./g, ".elements.").slice(2);
},
(state, action) => {
const { element, merge = false } = action.payload;
return;
}
if (debouncedSave) {
debouncedSave.cancel();
}
debouncedSave = debounce(() => store.dispatch(saveRevision(null, { onFinish })), 1000);
debouncedSave();
}
);
const startSaving = { type: START_SAVING, payload: { progress: true } };
const finishSaving = { type: FINISH_SAVING, payload: { progress: false } };
addReducer([START_SAVING, FINISH_SAVING], "ui.saving", (state, action) => {
return action.payload.progress;
});
addMiddleware([SAVING_REVISION], ({ store, next, action }) => {
next(action);
const data: Object = getPage(store.getState());
if (data.locked) {
return;
}
// Construct page payload
const revision = pick(data, ["title", "snippet", "url", "settings"]);
revision.content = data.content.present;
revision.category = data.category.id;
// Flatten page content
const flattenContent = el => {
let els = {};
el.elements =
Array.isArray(el.elements) &&
el.elements.map(child => {
els = { ...els, ...flattenContent(child) };
return child.id;
});
els[el.id] = el;
return els;
};
addReducer([FLATTEN_ELEMENTS], "elements", (state, action) => {
return action.payload;
});
addMiddleware(
[UPDATE_ELEMENT, DELETE_ELEMENT, "@@redux-undo/UNDO", "@@redux-undo/REDO", "@@redux-undo/INIT"],
({ store, next, action }) => {
const result = next(action);
const state = store.getState();
if (state.page.content) {
const content = dotProp.get(state, "page.content.present") || null;
if (!content) {
return result;
}
const elements = flattenContent(cloneDeep(content));
store.dispatch({ type: FLATTEN_ELEMENTS, payload: elements, meta: { log: true } });
});
});
export const updateRevision = createAction(UPDATE_REVISION);
addMiddleware([UPDATE_REVISION], ({ store, next, action }) => {
next(action);
if (action.payload.history === false) {
return;
}
const { onFinish } = action.meta;
store.dispatch(saveRevision(null, { onFinish }));
});
addReducer([UPDATE_REVISION], "page", (state, action) => {
return { ...state, ...action.payload };
});
// Flatten page content
const flattenContent = el => {
let els = {};
el.elements =
Array.isArray(el.elements) &&
el.elements.map(child => {
els = { ...els, ...flattenContent(child) };
return child.id;
});
els[el.id] = el;
return els;
};
return dotProp.set(state, `${plugin.type}`, typePlugins);
});
export const highlightElement = createAction(HIGHLIGHT_ELEMENT, { log: false });
addReducer([HIGHLIGHT_ELEMENT], "ui.highlightElement", (state, action) => {
return action.payload.element ? action.payload.element : null;
});
export const activateElement = createAction(ACTIVATE_ELEMENT);
addReducer([ACTIVATE_ELEMENT], "ui.activeElement", (state, action) => {
return action.payload.element;
});
export const deactivateElement = createAction(DEACTIVATE_ELEMENT);
addReducer([DEACTIVATE_ELEMENT], "ui.activeElement", () => null);
export const focusSlateEditor = createAction(FOCUS_SLATE_EDITOR);
addReducer([FOCUS_SLATE_EDITOR], "ui.slateFocused", () => true);
export const blurSlateEditor = createAction(BLUR_SLATE_EDITOR);
addReducer([BLUR_SLATE_EDITOR], "ui.slateFocused", () => false);
export const dragStart = createAction(DRAG_START);
addReducer([DRAG_START], "ui.dragging", () => true);
export const dragEnd = createAction(DRAG_END);
addReducer([DRAG_END], "ui.dragging", () => false);
export const elementCreated = createAction(ELEMENT_CREATED);
export const updateElement = createAction(UPDATE_ELEMENT);
return true;
}
}
);
}
);
addReducer(
["@@redux-undo/UNDO", "@@redux-undo/REDO", "@@redux-undo/INIT"],
"page.content",
state => state
);
/***************** EDITOR ACTIONS *****************/
addReducer([SETUP_EDITOR], null, (state, action) => {
return { ...state, ...action.payload };
});
export const togglePlugin = createAction(TOGGLE_PLUGIN);
addReducer([TOGGLE_PLUGIN], "ui.plugins", (state, action) => {
const { name, params, closeOtherInGroup = false } = action.payload;
const plugin = getPlugin(name);
if (!plugin) {
return state;
}
let typePlugins = dotProp.get(state, plugin.type);
if (!Array.isArray(typePlugins)) {
typePlugins = [];
let typePlugins = dotProp.get(state, plugin.type);
if (!Array.isArray(typePlugins)) {
typePlugins = [];
}
const alreadyActive = typePlugins.findIndex(pl => pl.name === plugin.name);
if (alreadyActive > -1) {
typePlugins = dotProp.delete(typePlugins, alreadyActive);
}
return dotProp.set(state, `${plugin.type}`, typePlugins);
});
export const highlightElement = createAction(HIGHLIGHT_ELEMENT, { log: false });
addReducer([HIGHLIGHT_ELEMENT], "ui.highlightElement", (state, action) => {
return action.payload.element ? action.payload.element : null;
});
export const activateElement = createAction(ACTIVATE_ELEMENT);
addReducer([ACTIVATE_ELEMENT], "ui.activeElement", (state, action) => {
return action.payload.element;
});
export const deactivateElement = createAction(DEACTIVATE_ELEMENT);
addReducer([DEACTIVATE_ELEMENT], "ui.activeElement", () => null);
export const focusSlateEditor = createAction(FOCUS_SLATE_EDITOR);
addReducer([FOCUS_SLATE_EDITOR], "ui.slateFocused", () => true);
export const blurSlateEditor = createAction(BLUR_SLATE_EDITOR);
addReducer([BLUR_SLATE_EDITOR], "ui.slateFocused", () => false);
}
);
addReducer(
["@@redux-undo/UNDO", "@@redux-undo/REDO", "@@redux-undo/INIT"],
"page.content",
state => state
);
/***************** EDITOR ACTIONS *****************/
addReducer([SETUP_EDITOR], null, (state, action) => {
return { ...state, ...action.payload };
});
export const togglePlugin = createAction(TOGGLE_PLUGIN);
addReducer([TOGGLE_PLUGIN], "ui.plugins", (state, action) => {
const { name, params, closeOtherInGroup = false } = action.payload;
const plugin = getPlugin(name);
if (!plugin) {
return state;
}
let typePlugins = dotProp.get(state, plugin.type);
if (!Array.isArray(typePlugins)) {
typePlugins = [];
}
const alreadyActive = typePlugins.findIndex(pl => pl.name === plugin.name);
if (alreadyActive > -1) {
export const highlightElement = createAction(HIGHLIGHT_ELEMENT, { log: false });
addReducer([HIGHLIGHT_ELEMENT], "ui.highlightElement", (state, action) => {
return action.payload.element ? action.payload.element : null;
});
export const activateElement = createAction(ACTIVATE_ELEMENT);
addReducer([ACTIVATE_ELEMENT], "ui.activeElement", (state, action) => {
return action.payload.element;
});
export const deactivateElement = createAction(DEACTIVATE_ELEMENT);
addReducer([DEACTIVATE_ELEMENT], "ui.activeElement", () => null);
export const focusSlateEditor = createAction(FOCUS_SLATE_EDITOR);
addReducer([FOCUS_SLATE_EDITOR], "ui.slateFocused", () => true);
export const blurSlateEditor = createAction(BLUR_SLATE_EDITOR);
addReducer([BLUR_SLATE_EDITOR], "ui.slateFocused", () => false);
export const dragStart = createAction(DRAG_START);
addReducer([DRAG_START], "ui.dragging", () => true);
export const dragEnd = createAction(DRAG_END);
addReducer([DRAG_END], "ui.dragging", () => false);
export const elementCreated = createAction(ELEMENT_CREATED);
export const updateElement = createAction(UPDATE_ELEMENT);
addReducer(
[UPDATE_ELEMENT],
action => {
{
initTypes: ["@@redux-undo/INIT"],
ignoreInitialState: true,
filter: action => {
if (action.payload && action.payload.history === false) {
return false;
}
return true;
}
}
);
}
);
addReducer(
["@@redux-undo/UNDO", "@@redux-undo/REDO", "@@redux-undo/INIT"],
"page.content",
state => state
);
/***************** EDITOR ACTIONS *****************/
addReducer([SETUP_EDITOR], null, (state, action) => {
return { ...state, ...action.payload };
});
export const togglePlugin = createAction(TOGGLE_PLUGIN);
addReducer([TOGGLE_PLUGIN], "ui.plugins", (state, action) => {
const { name, params, closeOtherInGroup = false } = action.payload;
const plugin = getPlugin(name);