Ejemplo n.º 1
0
    serverFeedbackHandlers.set('Neos.Neos.Ui:ReloadContentOutOfBand/Main', (feedbackPayload, {store, globalRegistry}) => {
        const {contextPath, renderedContent, nodeDomAddress} = feedbackPayload;
        const domNode = nodeDomAddress && findNodeInGuestFrame(
            nodeDomAddress.contextPath,
            nodeDomAddress.fusionPath
        );

        // We need to create the new DOM nodes from within the iframe document,
        // because many frameworkds (e.g. CKE, React) use the following checks
        // `obj instanceof obj.ownerDocument.defaultView.Node`
        // which would fail if this node was created in Host
        const tempNodeInGuest = getGuestFrameDocument().createElement('div');
        tempNodeInGuest.innerHTML = renderedContent;
        const contentElement = tempNodeInGuest
            .querySelector(`[data-__neos-node-contextpath="${contextPath}"]`);

        if (!contentElement) {
            console.error(`!!! Content Element with context path "${contextPath}" not found in returned HTML from server (which you see below) - Reloading the full page!`);
            console.log(renderedContent);

            getGuestFrameDocument().location.reload();
            return;
        }

        const fusionPath = contentElement.dataset.__neosFusionPath;

        domNode.parentElement.replaceChild(contentElement, domNode);

        const children = findAllChildNodes(contentElement);

        const nodes = Object.assign(
            {[contextPath]: selectors.CR.Nodes.byContextPathSelector(contextPath)(store.getState())},
            ...children.map(el => {
                const contextPath = el.getAttribute('data-__neos-node-contextpath');
                return {[contextPath]: selectors.CR.Nodes.byContextPathSelector(contextPath)(store.getState())};
            })
        );
        const nodeTypesRegistry = globalRegistry.get('@neos-project/neos-ui-contentrepository');
        const inlineEditorRegistry = globalRegistry.get('inlineEditors');

        //
        // Initialize the newly rendered node and all nodes that came with it
        //
        [contentElement, ...children].forEach(
            initializeContentDomNode({
                store,
                globalRegistry,
                nodeTypesRegistry,
                inlineEditorRegistry,
                nodes
            })
        );
        store.dispatch(actions.CR.Nodes.focus(contextPath, fusionPath));
        store.dispatch(actions.UI.ContentCanvas.requestScrollIntoView(true));
    });
Ejemplo n.º 2
0
    serverFeedbackHandlers.add('Neos.Neos.Ui:RenderContentOutOfBand', (feedbackPayload, {store, globalRegistry}) => {
        const {contextPath, renderedContent, parentDomAddress, siblingDomAddress, mode} = feedbackPayload;
        const parentElement = parentDomAddress && findNodeInGuestFrame(
            parentDomAddress.contextPath,
            parentDomAddress.fusionPath
        );
        const siblingElement = siblingDomAddress && findNodeInGuestFrame(
            siblingDomAddress.contextPath,
            siblingDomAddress.fusionPath
        );
        const contentElement = (new DOMParser())
            .parseFromString(renderedContent, 'text/html')
            .querySelector(`[data-__neos-node-contextpath="${contextPath}"]`);

        if (!contentElement) {
            console.warn(`!!! Content Element with context path "${contextPath}" not found in returned HTML from server (which you see below) - Reloading the full page!`);
            console.log(renderedContent);

            getGuestFrameDocument().location.reload();
            return;
        }

        const fusionPath = contentElement.dataset.__neosFusionPath;

        switch (mode) {
            case 'before':
                siblingElement.parentNode.insertBefore(contentElement, siblingElement);
                break;

            case 'after':
                siblingElement.parentNode.insertBefore(contentElement, siblingElement.nextSibling);
                break;

            case 'into':
            default:
                parentElement.appendChild(contentElement);
                break;
        }

        const children = findAllChildNodes(contentElement);

        const nodes = new Map(
            Object.assign(
                {[contextPath]: selectors.CR.Nodes.byContextPathSelector(contextPath)(store.getState())},
                ...children.map(el => {
                    const contextPath = el.getAttribute('data-__neos-node-contextpath');
                    return {[contextPath]: selectors.CR.Nodes.byContextPathSelector(contextPath)(store.getState())};
                })
            )
        );
        const nodeTypesRegistry = globalRegistry.get('@neos-project/neos-ui-contentrepository');
        const inlineEditorRegistry = globalRegistry.get('inlineEditors');

        if (parentElement.querySelector(`.${style.addEmptyContentCollectionOverlay}`)) {
            parentElement.querySelector(`.${style.addEmptyContentCollectionOverlay}`).remove();
        }

        //
        // Initialize the newly rendered node and all nodes that came with it
        //
        [contentElement, ...children].forEach(
            initializeContentDomNode({
                store,
                globalRegistry,
                nodeTypesRegistry,
                inlineEditorRegistry,
                nodes
            })
        );
        store.dispatch(actions.CR.Nodes.focus(contextPath, fusionPath));
    });