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cms-ui-react/./src/delivery-property-renderer/delivery-property-renderer.ts"],"sourcesContent":["// property name with these prefix need to be removed when searching DOM\r\nconst propertyPrefix = [\"icontent_\", \"ichangetrackable_\", \"iversionable_\", \"iroutable_\"];\r\n\r\nconst selector = (propertyName: string): string => {\r\n propertyPrefix.forEach(function (prefix) {\r\n if (propertyName.indexOf(prefix) === 0) {\r\n propertyName = propertyName.substring(prefix.length);\r\n }\r\n });\r\n\r\n return \"[data-epi-property-name='\" + propertyName + \"' i], [data-epi-edit='\" + propertyName + \"' i]\";\r\n};\r\n\r\nconst filterNestedNodes = (nodes: NodeListOf): HTMLElement[] => {\r\n const result: HTMLElement[] = [];\r\n nodes.forEach((x) => {\r\n const htmlEl = x as HTMLElement;\r\n if (htmlEl.parentElement && htmlEl.parentElement.closest(\"[data-epi-property-name],[data-epi-edit]\")) {\r\n return;\r\n }\r\n result.push(htmlEl);\r\n });\r\n return result;\r\n};\r\n\r\nexport const loadPropertiesFromElement = (container: ParentNode, propertyName: string): HTMLElement[] => {\r\n return filterNestedNodes(container.querySelectorAll(selector(propertyName)));\r\n};\r\n\r\nexport const tryGetBlockElement = (container: ParentNode, blockId: string): HTMLElement | null => {\r\n if (!blockId) {\r\n return null;\r\n }\r\n\r\n const contentLinkParts = blockId.split(\"_\");\r\n const id = contentLinkParts[0];\r\n const blockNode = container.querySelector(`[data-epi-block-id=\"${id}\"]`);\r\n if (blockNode) {\r\n return blockNode as HTMLElement;\r\n }\r\n\r\n return container.querySelector(`[data-epi-block-id^=\"${id}_\"]`);\r\n};\r\n","import { loadPropertiesFromElement, tryGetBlockElement } from \"./element-properties-loader\";\r\n\r\nfunction replaceNode(node: HTMLElement, updatedNode: HTMLElement) {\r\n if (updatedNode) {\r\n node.innerHTML = updatedNode.innerHTML;\r\n\r\n if (node.tagName === updatedNode.tagName) {\r\n const updatedAttributes = updatedNode.attributes;\r\n for (let i = 0; i < updatedAttributes.length; i++) {\r\n const updatedAttribute = updatedAttributes[i];\r\n node.setAttribute(updatedAttribute.name, updatedAttribute.value);\r\n }\r\n\r\n // make sure to clean up attributes which no longer exist on the updated DOM node\r\n const attributes = node.attributes;\r\n for (let i = 0; i < attributes.length; i++) {\r\n const attribute = attributes[i];\r\n if (!updatedNode.getAttribute(attribute.name)) {\r\n node.removeAttribute(attribute.name);\r\n }\r\n }\r\n }\r\n } else {\r\n node.remove();\r\n }\r\n}\r\n\r\n(function () {\r\n // Client side property renderer for NCD. Request page html from the delivery site and partial refresh the property DOM.\r\n\r\n function updateHtmlDom(newHtmlContent: any, updatedProperties: any, saveContentLink: string) {\r\n const page = document.createElement(\"html\");\r\n page.innerHTML = newHtmlContent;\r\n\r\n const updatedBlockNode = tryGetBlockElement(page, saveContentLink);\r\n if (updatedBlockNode) {\r\n const existingBlockNode = tryGetBlockElement(document, saveContentLink);\r\n if (existingBlockNode) {\r\n replaceNode(existingBlockNode, updatedBlockNode);\r\n return;\r\n }\r\n }\r\n\r\n updatedProperties.forEach(function (property: any) {\r\n if (!property.successful) {\r\n return;\r\n }\r\n\r\n const updatedNode = loadPropertiesFromElement(page, property.name)[0];\r\n loadPropertiesFromElement(document, property.name).forEach(function (node) {\r\n // skip rendering properties that set `data-epi-edit` or has `data-epi-property-render`==\"none\"\r\n // this will typically happen if the client wants the OPE to work but wants to take care of rendering on their own (i.e. React\r\n if (node.getAttribute(\"data-epi-edit\") || node.getAttribute(\"data-epi-property-render\") === \"none\") {\r\n return;\r\n }\r\n // skip rendering if partial renderer is requested\r\n if (node.getAttribute(\"data-epi-property-render\") === \"partial\" && !property.forceRender) {\r\n return;\r\n }\r\n replaceNode(node, updatedNode);\r\n });\r\n });\r\n }\r\n\r\n function getUpdatedPageContentAsync(contentLink: string) {\r\n // Replace url with updated ContentLink\r\n const url = location.href.replace(/,,[\\d_]+/, \",,\" + contentLink);\r\n return fetch(url, { cache: \"no-cache\" }).then(function (response) {\r\n if (response.ok && !response.redirected) {\r\n return response.text();\r\n } else {\r\n throw new Error(response.statusText);\r\n }\r\n });\r\n }\r\n\r\n function subscribeEvent() {\r\n const epi = (window as any).epi;\r\n if (epi.isEditable) {\r\n epi.subscribe(\"contentSaved\", function (message: any) {\r\n if (!message.properties || !Array.isArray(message.properties)) {\r\n return;\r\n }\r\n\r\n getUpdatedPageContentAsync(message.contentLink)\r\n .then(function (data) {\r\n updateHtmlDom(data, message.properties, message.contentLink);\r\n epi.publish(\"epiReloadProperties\");\r\n })\r\n .catch(function (error) {\r\n console.error(\"An error has occurred during fetch operation.\", error);\r\n });\r\n });\r\n }\r\n }\r\n\r\n window.addEventListener(\"load\", function () {\r\n const epi = (window as any).epi;\r\n\r\n if (!epi) {\r\n return;\r\n }\r\n if (epi.ready === true) {\r\n subscribeEvent();\r\n } else {\r\n epi.subscribe(\"epiReady\", subscribeEvent);\r\n }\r\n });\r\n})();\r\n"],"names":["propertyPrefix","loadPropertiesFromElement","container","propertyName","nodes","result","forEach","x","htmlEl","parentElement","closest","push","filterNestedNodes","querySelectorAll","prefix","indexOf","substring","length","selector","tryGetBlockElement","blockId","id","split","querySelector","replaceNode","node","updatedNode","innerHTML","tagName","updatedAttributes","attributes","i","updatedAttribute","setAttribute","name","value","attribute","getAttribute","removeAttribute","remove","subscribeEvent","epi","window","isEditable","subscribe","message","properties","Array","isArray","contentLink","url","location","href","replace","fetch","cache","then","response","ok","redirected","text","Error","statusText","getUpdatedPageContentAsync","data","newHtmlContent","updatedProperties","saveContentLink","page","document","createElement","updatedBlockNode","existingBlockNode","property","successful","forceRender","updateHtmlDom","publish","catch","error","console","addEventListener","ready"],"sourceRoot":""}