How to use @webiny/app-page-builder - 10 common examples

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 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;
        if (element.elements && typeof element.elements[0] === "string") {
            delete element["elements"];
        }
        updateChildPaths(element);
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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 => {
        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) => {
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;
        if (element.elements && typeof element.elements[0] === "string") {
            delete element["elements"];
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 / plugins / elements / column / index.js View on Github external
// 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) {
        redux.store.dispatch(elementCreated({ element: newColumn, source }));
    }
};
github webiny / webiny-js / packages / app-page-builder / src / editor / plugins / elements / block / index.js View on Github external
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) {
                redux.store.dispatch(elementCreated({ element, source }));
            }
        },
        onChildDeleted({ element }) {
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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;

    // Check if API call is necessary
    if (!dataChanged(revision)) {
        return;
    }

    lastSavedRevision = revision;

@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 13 days ago

Package Health Score

80 / 100
Full package analysis

Similar packages