Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
middleware: ({ store, action, next }: Object) => {
const { element, source } = action.payload;
next(action);
// Check the source of the element (could be `saved` element which behaves differently from other elements)
const sourcePlugin = getPlugin(source.type);
if (!sourcePlugin) {
return;
}
const { onCreate } = sourcePlugin;
if (!onCreate || onCreate !== "skip") {
// If source element does not define a specific `onCreate` behavior - continue with the actual element plugin
const plugin = getPlugin(element.type);
if (!plugin) {
return;
}
const { onCreate } = plugin;
if (onCreate && onCreate === "open-settings") {
store.dispatch(activateElement({ element: element.id }));
store.dispatch(togglePlugin({ name: "cms-element-settings-advanced" }));
}
}
const HorizontalAlignActionFlex = ({ element, children, alignElement, align }: Object) => {
const plugin = getPlugin(element.type);
if (!plugin) {
return null;
}
return React.cloneElement(children, { onClick: alignElement, icon: icons[align] });
};
static canHaveChildren(node: Object) {
const plugin = getPlugin(node.type);
return plugin ? plugin.canHaveChildren : false;
}
export const createElement = (type: string, options: Object = {}, parent: ?ElementType) => {
const plugin = getPlugin(type);
invariant(plugin, `Missing element plugin "${type}"!`);
return {
id: shortid.generate(),
data: {},
elements: [],
path: "",
...plugin.create(options, parent)
};
};
const actions = plugin.settings.map(pl => {
if (typeof pl === "string") {
return { plugin: getPlugin(pl || divider), options: {} };
}
if (Array.isArray(pl)) {
return { plugin: getPlugin(pl[0] || divider), options: pl[1] };
}
return null;
});
const CloneAction = ({ element, children, duplicate }: Object) => {
const plugin = getPlugin(element.type);
if (!plugin) {
return null;
}
return React.cloneElement(children, { onClick: duplicate });
};
const EditElementDialog = (props: Props) => {
const { open, onClose, onSubmit, plugin: pluginName } = props;
const plugin = getPlugin(pluginName);
return (
<dialog open="{open}">
{plugin && (
<form>
{({ submit, Bind }) => (
Update {plugin.title}
<input label="{"Name"}">
</form></dialog>
const getFileUploader = () => {
const withFileUploadPlugin = getPlugin("with-file-upload-uploader");
invariant(
withFileUploadPlugin,
`"withFileUpload" component's uploader plugin (type "webiny-file-upload-uploader") not found.`
);
return file => {
return withFileUploadPlugin.upload(file);
};
};