export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
    switch (action.type) {
        case system.INIT: {
            draft.isHidden = $get(['payload', 'ui', 'drawer', 'isHidden'], action) || false;
            draft.collapsedMenuGroups = $get(['payload', 'ui', 'drawer', 'collapsedMenuGroups'], action) || ['content'];
            break;
        }
        case actionTypes.TOGGLE: {
            draft.isHidden = !draft.isHidden;
            break;
        }
        case actionTypes.HIDE: {
            draft.isHidden = true;
            break;
        }
        case actionTypes.TOGGLE_MENU_GROUP: {
            const groupId = action.payload;
            if (draft.collapsedMenuGroups.includes(groupId)) {
                draft.collapsedMenuGroups = draft.collapsedMenuGroups.filter(i => i !== groupId);
            } else {
                draft.collapsedMenuGroups.push(groupId);
            }
            break;
        }
    }
});
export const createNodeEnvelope = (node: NodeEnvelope | NodeContextPath) => {
    let contextPath = '';

    if (typeof node === 'object') {
        contextPath = $get(['contextPath'], node) || $get(['$node'], node);
    } else if (typeof node === 'string') {
        contextPath = node;
    }

    if (!contextPath) {
        throw new Error('A FlowQuery context must either be a string, an object with a contextPath property or an array of those items.');
    }

    return {$node: contextPath};
};
Exemple #3
0
export const reducer = (globalState: GlobalState, action: InitAction | Action) => {
    // TODO: substitute global state with State when conversion of all CR reducers is done
    const mockDefaultState = {cr: {contentDimensions: {}}};
    const state = $get(['cr', 'contentDimensions'], globalState) || mockDefaultState;
    const newState = subReducer(state, action);
    return $set(['cr', 'contentDimensions'], newState, globalState);
};
export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
    switch (action.type) {
        case system.INIT: {
            draft.toggledGroups = $get(['payload', 'ui', 'addNodeModal', 'toggledGroups'], action) || [];
            break;
        }
        case actionTypes.OPEN: {
            if (typeof action.payload.contextPath !== 'string') {
                throw new Error(errorMessages.ERROR_INVALID_CONTEXTPATH);
            }
            if (typeof action.payload.fusionPath !== 'string') {
                throw new Error(errorMessages.ERROR_INVALID_FUSIONPATH);
            }
            draft.contextPath = action.payload.contextPath;
            draft.fusionPath = action.payload.fusionPath;
            break;
        }
        case actionTypes.CLOSE: {
            draft.contextPath = null;
            draft.fusionPath = null;
            break;
        }
        case actionTypes.TOGGLE_GROUP: {
            const groupId = action.payload;
            if (draft.toggledGroups.includes(groupId)) {
                draft.toggledGroups = draft.toggledGroups.filter(i => i !== groupId);
            } else {
                draft.toggledGroups.push(groupId);
            }
            break;
        }
    }
});
export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
    switch (action.type) {
        case system.INIT: {
            draft.isHidden = $get(['payload', 'ui', 'leftSideBar', 'isHidden'], action) || false;
            draft.contentTree.isHidden = $get(['payload', 'ui', 'leftSideBar', 'contentTree', 'isHidden'], action) || false;
            break;
        }
        case actionTypes.TOGGLE: {
            draft.isHidden = !draft.isHidden;
            break;
        }
        case actionTypes.TOGGLE_CONTENT_TREE: {
            draft.contentTree.isHidden = !draft.contentTree.isHidden;
            break;
        }
    }
});
 Object.keys(elementConfigurations).forEach(elementName => {
     const elementValue = $get([elementName], values);
     const elementConfiguration = elementConfigurations[elementName];
     const elementErrors = validateElement(elementValue, elementConfiguration);
     if (elementErrors && elementErrors.length > 0) {
         hasErrors = true;
         errors[elementName] = elementErrors;
     }
 });
 (state: GlobalState, {reference}: {reference: NodeContextPath | null, role: string}) => {
     if (reference === null) {
         return null;
     }
     const elevatedReference = elevator(reference);
     if (elevatedReference) {
         return $get(['cr', 'nodes', 'byContextPath', elevatedReference], state) || null;
     }
     return null;
 },
export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
    switch (action.type) {
        case system.INIT: {
            draft.backgroundColor = $get(['payload', 'ui', 'contentCanvas', 'backgroundColor'], action);
            draft.src = $get(['payload', 'ui', 'contentCanvas', 'src'], action) || null;
            break;
        }
        case actionTypes.SET_PREVIEW_URL: {
            draft.previewUrl = action.payload;
            break;
        }
        case actionTypes.SET_SRC: {
            draft.src = action.payload.src;
            break;
        }
        case actionTypes.FORMATTING_UNDER_CURSOR: {
            draft.formattingUnderCursor = action.payload;
            break;
        }
        case actionTypes.SET_CURRENTLY_EDITED_PROPERTY_NAME: {
            draft.currentlyEditedPropertyName = action.payload;
            break;
        }
        case actionTypes.STOP_LOADING: {
            draft.isLoading = false;
            break;
        }
        case actionTypes.START_LOADING: {
            draft.isLoading = true;
            break;
        }
        case actionTypes.REQUEST_SCROLL_INTO_VIEW: {
            draft.shouldScrollIntoView = action.payload;
            break;
        }
        case actionTypes.REQUEST_REGAIN_CONTROL: {
            draft.src = '';
            break;
        }
    }
});
    const q = (context: ContextProperties | string, ignoreMiddleware: boolean = false) => {
        let finalContext: NodeContextPath[];
        if (typeof context === 'object' && typeof $get(['contextPath'], context) === 'string') {
            finalContext = [$get(['contextPath'], context) as string];
        } else if (typeof context === 'string') {
            finalContext = [context];
        } else if (Array.isArray(context)) {
            finalContext = context;
        } else {
            throw new Error('Please provide either a string, an array or an object containing a `contextPath` to the FlowQuery API.');
        }

        const chain = [
            {
                type: 'createContext',
                payload: finalContext.map(createNodeEnvelope)
            }
        ];

        return createChainableApi(operations, chain, ignoreMiddleware);
    };
export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
    switch (action.type) {
        case actionTypes.COMMIT: {
            const {focusedNode, propertyId, value, hooks} = action.payload;
            const focusedNodePath = focusedNode.contextPath;
            const currentPropertyValue = $get(['properties', propertyId], focusedNode);
            const transientValueDiffers = (value !== null) && (value !== currentPropertyValue);
            if (typeof draft.valuesByNodePath[focusedNodePath] !== 'object') {
                draft.valuesByNodePath[focusedNodePath] = {};
            }
            const focusedValues = draft.valuesByNodePath[focusedNodePath];
            if (focusedValues) { // dummy type guard
                // if hooks are defined for given property, the value should not be cleared even if it doesn't differ
                if (transientValueDiffers || hooks) {
                    focusedValues[propertyId] = hooks ? {value, hooks} : {value};
                } else {
                    delete focusedValues[propertyId];
                }
            }
            break;
        }
        case actionTypes.DISCARD: {
            draft.shouldPromptToHandleUnappliedChanges = false;
            delete draft.valuesByNodePath[action.payload.focusedNodeContextPath];
            break;
        }
        case actionTypes.CLEAR: {
            draft.shouldPromptToHandleUnappliedChanges = false;
            delete draft.valuesByNodePath[action.payload.focusedNodeContextPath];
            break;
        }
        case actionTypes.ESCAPE: {
            draft.shouldPromptToHandleUnappliedChanges = true;
            break;
        }
        case actionTypes.RESUME: {
            draft.shouldPromptToHandleUnappliedChanges = false;
            break;
        }
        case actionTypes.SECONDARY_OPEN: {
            draft.secondaryInspectorIsOpen = true;
            break;
        }
        case actionTypes.SECONDARY_CLOSE: {
            draft.secondaryInspectorIsOpen = false;
            break;
        }
        case actionTypes.SECONDARY_TOGGLE: {
            draft.secondaryInspectorIsOpen = !draft.secondaryInspectorIsOpen;
            break;
        }
    }
});