UNPKG

@contentstack/live-preview-utils

Version:

Contentstack provides the Live Preview SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane.

1 lines 2.19 kB
{"version":3,"sources":["../../../../src/visualBuilder/utils/getMultilinePlaintext.ts"],"sourcesContent":["\nexport function getMultilinePlaintext(editableElement: Element): string {\n let newValue = '';\n let isOnFreshLine = true;\n\n // Recursive function to navigate childNodes and build linebreaks with text\n function parseChildNodesForValueAndLines(childNodes: NodeListOf<ChildNode>) {\n for (let i = 0; i < childNodes.length; i++) {\n const childNode = childNodes[i];\n\n if (childNode.nodeName === 'BR') {\n // BRs are always line breaks which means the next loop is on a fresh line\n newValue += '\\n';\n isOnFreshLine = true;\n continue;\n }\n\n // We may or may not need to create a new line\n if (childNode.nodeName === 'DIV' && isOnFreshLine === false && i !== 0) {\n // Divs create new lines for themselves if they aren't already on one\n newValue += '\\n';\n }\n\n // Whether we created a new line or not, we'll use it for this content so the next loop will not be on a fresh line:\n isOnFreshLine = false;\n\n // Add the text content if this is a text node:\n if (childNode.nodeType === 3 && childNode.textContent && childNode.textContent.trim() !== '') {\n newValue += childNode.textContent;\n }\n\n // If this node has children, get into them as well:\n parseChildNodesForValueAndLines(childNode.childNodes);\n }\n }\n\n parseChildNodesForValueAndLines(editableElement.childNodes);\n\n return newValue;\n\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,SAAS,sBAAsB,iBAAkC;AACtE,MAAI,WAAW;AACf,MAAI,gBAAgB;AAGpB,WAAS,gCAAgC,YAAmC;AACxE,aAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AACxC,YAAM,YAAY,WAAW,CAAC;AAE9B,UAAI,UAAU,aAAa,MAAM;AAE7B,oBAAY;AACZ,wBAAgB;AAChB;AAAA,MACJ;AAGA,UAAI,UAAU,aAAa,SAAS,kBAAkB,SAAS,MAAM,GAAG;AAEpE,oBAAY;AAAA,MAChB;AAGA,sBAAgB;AAGhB,UAAI,UAAU,aAAa,KAAK,UAAU,eAAe,UAAU,YAAY,KAAK,MAAM,IAAI;AAC1F,oBAAY,UAAU;AAAA,MAC1B;AAGA,sCAAgC,UAAU,UAAU;AAAA,IACxD;AAAA,EACJ;AAEA,kCAAgC,gBAAgB,UAAU;AAE1D,SAAO;AAET;","names":[]}