Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 }));
}
})
addMiddleware([ELEMENT_DROPPED], ({ store, next, action }) => {
next(action);
const state = store.getState();
const target = getElementWithChildren(state, action.payload.target.id);
if (!target) {
return;
}
const plugin = getPlugins("pb-page-element").find(pl => pl.elementType === target.type);
if (!plugin) {
return;
}
invariant(
plugin.onReceived,
"To accept drops, element plugin must implement `onReceived` function"
);
export default connect(state => ({
element: getElementWithChildren(state, getActiveElementId(state))
}))(SaveAction);
}
const plugin = getPlugins("pb-page-element").find(pl => pl.elementType === target.type);
if (!plugin) {
return;
}
invariant(
plugin.onReceived,
"To accept drops, element plugin must implement `onReceived` function"
);
let { source } = action.payload;
if (source.path) {
source = getElementWithChildren(state, source.id);
}
const targetPlugin = getPlugins("pb-page-element").find(pl => pl.elementType === target.type);
if (!targetPlugin) {
return;
}
targetPlugin.onReceived({
source,
target,
position: action.payload.target.position
});
});