Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onReceived({ source, target, position = null }) {
let dispatchNew = false;
let element;
if (source.path) {
// $FlowFixMe
element = cloneElement(source);
} else {
dispatchNew = true;
element = createElement(source.type, {}, target);
}
const block = addElementToParent(element, target, position);
// Dispatch update action
redux.store.dispatch(updateElement({ element: block }));
// Delete exiting element
if (source.path) {
redux.store.dispatch(deleteElement({ element: source }));
}
if (dispatchNew) {
const handleDroppedElement = (source, target, position) => {
let dispatchNew = false;
let element;
if (source.path) {
// $FlowFixMe
element = cloneElement(source);
} else {
dispatchNew = true;
element = createElement(source.type, {}, target);
}
target = addElementToParent(element, target, position);
redux.store.dispatch(updateElement({ element: target }));
if (source.path) {
redux.store.dispatch(deleteElement({ element: source }));
}
if (dispatchNew) {
redux.store.dispatch(elementCreated({ element, source }));
}
};
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();
}
// $FlowFixMe
newColumn = set(newColumn, "data.width", row.elements[targetIndex].data.width);
row = addElementToParent(newColumn, row, targetIndex + 1);
redux.store.dispatch(updateElement({ element: row }));
if (source.path) {
redux.store.dispatch(deleteElement({ element: source }));
}
if (dispatchNew) {
onReceived({ source, target, position = null }) {
let dispatchNew = false;
let element;
if (source.path) {
// $FlowFixMe
element = cloneElement(source);
} else {
dispatchNew = true;
element = createElement(source.type, {}, target);
}
let column;
if (element.type !== "column") {
column = createColumn({ elements: [element] });
}
// Add new child element
let row = addElementToParent(column || element, target, position);
// Recalculate column widths
row = distributeColumnWidths(row);
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 }));
}
})