How to use the @webiny/app-page-builder/editor/redux.addReducer function in @webiny/app-page-builder

To help you get started, we’ve selected a few @webiny/app-page-builder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
});

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;
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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;
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
// 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 } });
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
});
});

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;
};
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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);
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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 = [];
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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);
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
}
);

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) {
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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 => {
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
{
                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);

@webiny/app-page-builder

[![](https://img.shields.io/npm/dw/@webiny/app-page-builder.svg)](https://www.npmjs.com/package/@webiny/app-page-builder) [![](https://img.shields.io/npm/v/@webiny/app-page-builder.svg)](https://www.npmjs.com/package/@webiny/app-page-builder) [![code sty

MIT
Latest version published 2 days ago

Package Health Score

80 / 100
Full package analysis

Similar packages