Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const splitColumn = (source, target) => {
let dispatchNew = false;
let row = getParentElementWithChildren(redux.store.getState(), target.id);
// $FlowFixMe
const targetIndex = row.elements.findIndex(el => el.id === target.id);
// Split target column in half
// $FlowFixMe
row.elements[targetIndex].data.width /= 2;
// Create a new column with half of the original target width
let newColumn;
if (source.path) {
// $FlowFixMe
newColumn = cloneElement(source);
} else {
dispatchNew = true;
newColumn = createColumn();
}
addMiddleware([DELETE_ELEMENT], ({ store, next, action }) => {
next(action);
store.dispatch(deactivateElement());
const state = store.getState();
let { element } = action.payload;
let parent = getParentElementWithChildren(state, element.id);
// Remove child from parent
// $FlowFixMe
if (!parent) {
return;
}
const index = parent.elements.findIndex(el => el.id === element.id);
parent = dotProp.delete(parent, "elements." + index);
store.dispatch(updateElement({ element: parent }));
// Execute `onChildDeleted` if defined
const plugin = getPlugin(parent.type);
if (!plugin) {
return;
}
canDelete({ element }) {
const parent = getParentElementWithChildren(redux.store.getState(), element.id);
return parent.elements.length > 1;
},
onReceived({ source, target, position = null }) {
duplicate: ({ element }) => () => {
const state = redux.store.getState();
element = getElementWithChildren(state, element.id);
const parent = getParentElementWithChildren(state, element.id);
const position = parent.elements.findIndex(el => el.id === element.id) + 1;
const newElement = set(parent, "elements", [
...parent.elements.slice(0, position),
cloneElement(element),
...(position < parent.elements.length ? parent.elements.slice(position) : [])
]);
return redux.store.dispatch(updateElement({ element: newElement }));
}
})