UNPKG

angular-xml-editor

Version:
1,162 lines (1,155 loc) 439 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('@angular/core'), require('@angular/common'), require('@angular/forms')) : typeof define === 'function' && define.amd ? define('angular-xml-editor', ['exports', 'rxjs', '@angular/core', '@angular/common', '@angular/forms'], factory) : (factory((global['angular-xml-editor'] = {}),global.rxjs,global.ng.core,global.ng.common,global.ng.forms)); }(this, (function (exports,rxjs,i0,i1,forms) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var XmlEditorDebugger = /** @class */ (function () { function XmlEditorDebugger() { this.actualCursorPosChanged$ = new rxjs.Subject(); this.inputSelectionChanged$ = new rxjs.Subject(); } /** * @param {?} pos * @return {?} */ XmlEditorDebugger.prototype.setActualCursorPos = /** * @param {?} pos * @return {?} */ function (pos) { this.actualCursorPosChanged$.next(pos); }; /** * @param {?} info * @return {?} */ XmlEditorDebugger.prototype.setInputSelection = /** * @param {?} info * @return {?} */ function (info) { this.inputSelectionChanged$.next(info); }; /** * @return {?} */ XmlEditorDebugger.prototype.ngOnDestroy = /** * @return {?} */ function () { this.actualCursorPosChanged$.complete(); this.inputSelectionChanged$.complete(); }; return XmlEditorDebugger; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var XmlToolbox = /** @class */ (function () { function XmlToolbox() { } /** * @param {?} node * @return {?} */ XmlToolbox.IsTextOrCommentNode = /** * @param {?} node * @return {?} */ function (node) { switch (node.nodeType) { case Node.TEXT_NODE: // text node case Node.COMMENT_NODE: return true; default: return false; } // return ((node.nodeType === System.Xml.XmlText) || (node.nodeType === System.Xml.XmlComment)); }; /** * @param {?} node * @return {?} */ XmlToolbox.GetNodeDebugContext = /** * @param {?} node * @return {?} */ function (node) { if (node === null || node === undefined) { return 'NULL'; } if (node.nodeType === Node.TEXT_NODE) { if (node.textContent === ' ' || node.textContent === String.fromCharCode(160)) { return "TextContent!Parent=" + XmlToolbox.GetNodeDebugContext(node.parentNode); } else { return "TextContent='" + node.textContent + "'"; } } /** @type {?} */ var asElem = /** @type {?} */ (node); if (asElem === undefined) { return "localName: " + node.nodeName + ", nodeType:" + node.nodeType; } else { return asElem.outerHTML; } }; return XmlToolbox; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var Xml2htmlAttributeWorker = /** @class */ (function () { function Xml2htmlAttributeWorker(rules) { this.rules = rules; } /** writes the given attributes to the html node in data-attribute-syntax **/ /** * writes the given attributes to the html node in data-attribute-syntax * * @param {?} xmlElement * @param {?} htmlElement * @return {?} */ Xml2htmlAttributeWorker.prototype.writeAllXmlAttributesToHtml = /** * writes the given attributes to the html node in data-attribute-syntax * * @param {?} xmlElement * @param {?} htmlElement * @return {?} */ function (xmlElement, htmlElement) { /** @type {?} */ var attributes = xmlElement.attributes; for (var i = 0; i < attributes.length; ++i) { /** @type {?} */ var attr = attributes[i]; this.writeAttributeToHtml(htmlElement, attr.name, attr.value); } }; /** writes the given attribute value to the html node in data-attribute-syntax **/ /** * writes the given attribute value to the html node in data-attribute-syntax * * @param {?} htmlElement * @param {?} key * @param {?} value * @return {?} */ Xml2htmlAttributeWorker.prototype.writeAttributeToHtml = /** * writes the given attribute value to the html node in data-attribute-syntax * * @param {?} htmlElement * @param {?} key * @param {?} value * @return {?} */ function (htmlElement, key, value) { /** @type {?} */ var name = "" + Xml2htmlAttributeWorker.DataAttribPraefix + key; if (value && value.length > 0) { htmlElement.setAttribute(name, value); } else { htmlElement.removeAttribute(name); } this.updateAttributesDescriptionInHtmlElement(htmlElement); }; /** writes the given attribute value from the html node data-attribute-syntax **/ /** * writes the given attribute value from the html node data-attribute-syntax * * @param {?} htmlElement * @param {?} key * @return {?} */ Xml2htmlAttributeWorker.prototype.getAttributeValueFromHtml = /** * writes the given attribute value from the html node data-attribute-syntax * * @param {?} htmlElement * @param {?} key * @return {?} */ function (htmlElement, key) { /** @type {?} */ var attributes = htmlElement.attributes; for (var i = 0; i < attributes.length; ++i) { if (attributes[i].name === "" + Xml2htmlAttributeWorker.DataAttribPraefix + key) { return attributes[i].value; } } return undefined; }; /** writes the given attribute value to the xml node (and gets it from the html node from data-attribute-syntax) **/ /** * writes the given attribute value to the xml node (and gets it from the html node from data-attribute-syntax) * * @param {?} htmlElement * @param {?} xmlElement * @return {?} */ Xml2htmlAttributeWorker.prototype.writeAllHtmlAttributesToXml = /** * writes the given attribute value to the xml node (and gets it from the html node from data-attribute-syntax) * * @param {?} htmlElement * @param {?} xmlElement * @return {?} */ function (htmlElement, xmlElement) { /** @type {?} */ var attributes = htmlElement.attributes; for (var i = 0; i < attributes.length; ++i) { /** @type {?} */ var attr = attributes[i]; if (attr.name.startsWith(Xml2htmlAttributeWorker.DataAttribPraefix)) { xmlElement.setAttribute(attr.name.substr(Xml2htmlAttributeWorker.DataAttribPraefix.length), attr.value); } } }; /** * updates the 'for human eyes' only description of the attributes inside a html node * * @param {?} htmlElement * @return {?} */ Xml2htmlAttributeWorker.prototype.updateAttributesDescriptionInHtmlElement = /** * updates the 'for human eyes' only description of the attributes inside a html node * * @param {?} htmlElement * @return {?} */ function (htmlElement) { /** @type {?} */ var attributes = htmlElement.attributes; /** @type {?} */ var allAttributes = ''; for (var i = 0; i < attributes.length; ++i) { /** @type {?} */ var attr = attributes[i]; if (attr.name.startsWith(Xml2htmlAttributeWorker.DataAttribPraefix)) { allAttributes = allAttributes + " " + attr.name.substr(Xml2htmlAttributeWorker.DataAttribPraefix.length) + "=\"" + attr.value + "\""; } } if (allAttributes.length > 0) { htmlElement.setAttribute('data-attributes', allAttributes); } else { htmlElement.removeAttribute('data-attributes'); } }; Xml2htmlAttributeWorker.DataAttribPraefix = 'data-attribute-'; return Xml2htmlAttributeWorker; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var Xml2html = /** @class */ (function () { function Xml2html(rules) { this.rules = rules; this.attributeWorker = new Xml2htmlAttributeWorker(rules); } /** * @param {?} node * @return {?} */ Xml2html.getTagNameFromNode = /** * @param {?} node * @return {?} */ function (node) { /** @type {?} */ var elem = /** @type {?} */ (node); /** @type {?} */ var name = ''; if (elem) { name = elem.getAttribute(Xml2html.DataTagName); } if (name === undefined || name === null || name === '') { throw new Error("node has no DataTagName attribute " + XmlToolbox.GetNodeDebugContext(node)); } return name; }; /** * @param {?} node * @return {?} */ Xml2html.isFloatingElement = /** * @param {?} node * @return {?} */ function (node) { /** @type {?} */ var elem = /** @type {?} */ (node); if (elem && elem.classList) { return elem.classList.contains(Xml2html.FloatingTagClassName); } return false; }; /** * @param {?} node * @return {?} */ Xml2html.isNoClosingElement = /** * @param {?} node * @return {?} */ function (node) { /** @type {?} */ var elem = /** @type {?} */ (node); if (elem && elem.classList) { return elem.classList.contains(Xml2html.NoClosingTagClassName); } return false; }; /** * @param {?} xml * @return {?} */ Xml2html.prototype.ToHtml = /** * @param {?} xml * @return {?} */ function (xml) { if (xml === '' || xml === undefined || xml === null) { return ''; } // alert(xml); // remove newline / carriage return xml = xml.replace(/\n/g, ''); xml = xml.replace(/\r/g, ''); // remove whitespace (tabs) before tags xml = xml.replace(/[\t]+\</g, '<'); // remove whitespace between tags xml = xml.replace(/\>[\t]+\</g, '><'); // remove whitespace after tags xml = xml.replace(/\>[\t]+$/g, '>'); /** @type {?} */ var domparser = new DOMParser(); /** @type {?} */ var domdoc = domparser.parseFromString(xml, 'text/xml'); /** @type {?} */ var targetDocument = new Document(); if (domdoc.documentElement === null) { return ''; } /** @type {?} */ var body = this.GetHtmlElementFromXmlElement(domdoc.documentElement, targetDocument); if (body && body.nodeType === Node.ELEMENT_NODE) { /** @type {?} */ var html = ( /** @type {?} */(body)).outerHTML; return html; } else { throw new Error("root node " + XmlToolbox.GetNodeDebugContext(body) + " is no element"); } }; /** * @param {?} ruleElem * @return {?} */ Xml2html.prototype.createNewElementHtml = /** * @param {?} ruleElem * @return {?} */ function (ruleElem) { /** @type {?} */ var elem = this.createNewElementByName(ruleElem.tagName); return elem.outerHTML; }; /** * @param {?} tagName * @return {?} */ Xml2html.prototype.createNewElementByName = /** * @param {?} tagName * @return {?} */ function (tagName) { /** @type {?} */ var tempDoc = new Document(); /** @type {?} */ var newElement = tempDoc.createElement('div'); /** @type {?} */ var rule = this.rules.ruleElements.get(tagName); if (rule && rule.floating === true) { newElement.classList.add(Xml2html.FloatingTagClassName); } // visualize closing tag or not? if (rule && rule.empty === true) { newElement.classList.add(Xml2html.NoClosingTagClassName); } newElement.setAttribute(Xml2html.DataTagName, tagName); return newElement; }; /** * @param {?} node * @param {?} targetDocument * @return {?} */ Xml2html.prototype.GetHtmlElementFromXmlElement = /** * @param {?} node * @param {?} targetDocument * @return {?} */ function (node, targetDocument) { switch (node.nodeType) { case Node.ELEMENT_NODE: // element node /** @type {?} */ var asElement = /** @type {?} */ (node); /** @type {?} */ var nodeName = asElement.nodeName; /** @type {?} */ var newElement = targetDocument.createElement('div'); /** @type {?} */ var rule = this.rules.ruleElements.get(nodeName); if (rule && rule.floating) { newElement.classList.add(Xml2html.FloatingTagClassName); } // visualize closing tag or not? if (rule && rule.empty) { newElement.classList.add(Xml2html.NoClosingTagClassName); } newElement.setAttribute(Xml2html.DataTagName, nodeName); /** @type {?} */ var children = asElement.childNodes; if (children.length === 0) { newElement.appendChild(targetDocument.createTextNode('')); // to prevent non closing tags } else { for (var i = 0; i < children.length; ++i) { /** @type {?} */ var childAsHtml = this.GetHtmlElementFromXmlElement(children[i], targetDocument); if (childAsHtml !== undefined) { newElement.appendChild(childAsHtml); } } } // insert attributes this.attributeWorker.writeAllXmlAttributesToHtml(asElement, newElement); return newElement; case Node.TEXT_NODE: // text node /** @type {?} */ var content = ( /** @type {?} */(node)).textContent; if (content.length > 0) { return targetDocument.createTextNode(content); } else { return undefined; } case Node.COMMENT_NODE: // create element node newElement = targetDocument.createElement('div'); newElement.classList.add(Xml2html.CommentTagClassName); newElement.setAttribute(Xml2html.DataTagName, 'comment'); newElement.textContent = ( /** @type {?} */(node)).textContent; return newElement; /* yet not implemented types */ case Node.PROCESSING_INSTRUCTION_NODE: console.warn("nodeType \"PROCESSING_INSTRUCTION_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " not implemented yet"); return undefined; case Node.DOCUMENT_NODE: throw new Error("nodeType \"Node.DOCUMENT_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " not implemented yet"); case Node.DOCUMENT_TYPE_NODE: throw new Error("nodeType \"Node.DOCUMENT_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " not implemented yet"); case Node.DOCUMENT_FRAGMENT_NODE: throw new Error("nodeType \"Node.DOCUMENT_FRAGMENT_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " not implemented yet"); /* Depreached node types */ case Node.ATTRIBUTE_NODE: throw new Error("nodeType \"Node.ATTRIBUTE_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " is depreached"); case Node.CDATA_SECTION_NODE: throw new Error("nodeType \"Node.CDATA_SECTION_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " is depreached"); case Node.ENTITY_REFERENCE_NODE: throw new Error("nodeType \"Node.ENTITY_REFERENCE_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " is depreached"); case Node.ENTITY_NODE: throw new Error("nodeType \"Node.ENTITY_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " is depreached"); case Node.NOTATION_NODE: throw new Error("nodeType \"Node.NOTATION_NODE\" " + XmlToolbox.GetNodeDebugContext(node) + " is depreached"); default: // tslint:disable-next-line:max-line-length throw new Error("unknown xmlElement nodeType " + node.nodeType + " in value: " + XmlToolbox.GetNodeDebugContext(node)); } }; Xml2html.DataTagName = 'data-tagname'; Xml2html.NoClosingTagClassName = 'xmlTagNoClosing'; Xml2html.FloatingTagClassName = 'floating'; Xml2html.CommentTagClassName = 'comment'; return Xml2html; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var DomDummyNodeManager = /** @class */ (function () { function DomDummyNodeManager() { } /** * @param {?} node * @return {?} */ DomDummyNodeManager.IsDummyNode = /** * @param {?} node * @return {?} */ function (node) { /** @type {?} */ var asElem = /** @type {?} */ (node); if (asElem && node.nodeType === Node.ELEMENT_NODE) { return asElem.classList.contains(DomDummyNodeManager.DummyNodeClassName); } return false; }; /** * @param {?} node * @return {?} */ DomDummyNodeManager.IsBeforeFirstTagDummyNode = /** * @param {?} node * @return {?} */ function (node) { if (DomDummyNodeManager.IsDummyNode(node)) { /** @type {?} */ var asElem = /** @type {?} */ (node); if (asElem && node.nodeType === Node.ELEMENT_NODE) { return asElem.classList.contains(DomDummyNodeManager.DummyNodeBeforeFirstTagClassName); } return false; } else { return false; } }; /** * @param {?} node * @return {?} */ DomDummyNodeManager.getPreviousSibling = /** * @param {?} node * @return {?} */ function (node) { if (!node) { return undefined; } while (node) { node = node.previousSibling; if (node) { if (DomDummyNodeManager.IsDummyNode(node)) ; else { return node; } } } return undefined; }; /** * @param {?} node * @return {?} */ DomDummyNodeManager.getNextSibling = /** * @param {?} node * @return {?} */ function (node) { if (!node) { return undefined; } while (node) { node = node.nextSibling; if (node) { if (DomDummyNodeManager.IsDummyNode(node)) ; else { return node; } } } return undefined; }; /** * @param {?} node * @return {?} */ DomDummyNodeManager.getChildNodeCount = /** * @param {?} node * @return {?} */ function (node) { if (!node) { return 0; } /** @type {?} */ var count = 0; for (var i = 0; i < node.childNodes.length; i++) { if (!DomDummyNodeManager.IsDummyNode(node.childNodes[i])) { count++; } } return count; }; /** * @param {?} node * @return {?} */ DomDummyNodeManager.getFirstChild = /** * @param {?} node * @return {?} */ function (node) { if (!node) { return undefined; } /** @type {?} */ var first = /** @type {?} */ (node.firstChild); while (DomDummyNodeManager.IsDummyNode(first)) { first = first.nextSibling; } return first; }; /** * @param {?} node * @return {?} */ DomDummyNodeManager.getLastChild = /** * @param {?} node * @return {?} */ function (node) { if (!node) { return undefined; } /** @type {?} */ var last = /** @type {?} */ (node.lastChild); while (DomDummyNodeManager.IsDummyNode(last)) { last = last.previousSibling; } return last; }; /** * @param {?} node * @param {?=} nodeDepth * @return {?} */ DomDummyNodeManager.prototype.RemoveAllDummyNodes = /** * @param {?} node * @param {?=} nodeDepth * @return {?} */ function (node, nodeDepth) { var _this = this; if (nodeDepth === void 0) { nodeDepth = 0; } /** @type {?} */ var children = []; for (var i = 0; i < node.childNodes.length; ++i) { children.push(node.childNodes[i]); } // delete all dummy node children children.forEach(function (child) { if (DomDummyNodeManager.IsDummyNode(child)) { node.removeChild(child); } }); children = []; for (var i = 0; i < node.childNodes.length; ++i) { children.push(node.childNodes[i]); } // update child nodes children.forEach(function (child) { _this.RemoveAllDummyNodes(child, nodeDepth + 1); }); }; /** * @param {?} node * @param {?=} nodeDepth * @return {?} */ DomDummyNodeManager.prototype.UpdateDummyNodes = /** * @param {?} node * @param {?=} nodeDepth * @return {?} */ function (node, nodeDepth) { var _this = this; if (nodeDepth === void 0) { nodeDepth = 0; } /** @type {?} */ var document = node.ownerDocument; /** @type {?} */ var asElement = /** @type {?} */ (node); /** @type {?} */ var children = []; for (var i = 0; i < node.childNodes.length; ++i) { children.push(node.childNodes[i]); } if (asElement && !DomDummyNodeManager.IsDummyNode(asElement) && !DomDummyNodeManager.IsDummyNode(asElement.parentElement)) { if (asElement.nodeType === Node.TEXT_NODE) { /** @type {?} */ var before = asElement.previousSibling; if (before.nodeType === Node.TEXT_NODE) ; else { if (!DomDummyNodeManager.IsDummyNode(before)) { asElement.parentNode.insertBefore(this.createDummyNode(document), asElement); } } } if (asElement.nodeType === Node.ELEMENT_NODE) { /** @type {?} */ var firstChild = node.firstChild; if (!firstChild) { // create dummy node in empty tag node.appendChild(this.createDummyNode(document)); firstChild = node.firstChild; } if (Xml2html.isNoClosingElement(node)) ; else { firstChild = node.firstChild; if (!firstChild) { // create dummy node in empty tag node.appendChild(this.createDummyNode(document)); firstChild = node.firstChild; } // Insert a dummy node before the first child if (!DomDummyNodeManager.IsDummyNode(firstChild)) { if (firstChild) { node.insertBefore(this.createDummyNode(document), firstChild); firstChild = node.firstChild; } else { node.appendChild(this.createDummyNode(document)); } } /** @type {?} */ var lastChild = node.lastChild; if (!DomDummyNodeManager.IsDummyNode(lastChild)) { node.appendChild(this.createDummyNode(document)); lastChild = node.lastChild; } // Insert a dummy node before the first (dummy child) but optical in front of the node (to show the cursor in front of the node) if (nodeDepth > 0) { if (DomDummyNodeManager.IsDummyNode(firstChild) && !DomDummyNodeManager.IsBeforeFirstTagDummyNode(firstChild)) { /** @type {?} */ var dummyNode = this.createDummyNode(document); dummyNode.classList.add(DomDummyNodeManager.DummyNodeBeforeFirstTagClassName); asElement.insertBefore(dummyNode, firstChild); } } } } } // update child nodes children.forEach(function (child) { _this.UpdateDummyNodes(child, nodeDepth + 1); }); }; /** * @param {?} targetDocument * @param {?=} content * @return {?} */ DomDummyNodeManager.prototype.createDummyNode = /** * @param {?} targetDocument * @param {?=} content * @return {?} */ function (targetDocument, content) { /** @type {?} */ var dummyNode = targetDocument.createElement('span'); /** @type {?} */ var dummy2TextNode; if (content === undefined) { dummy2TextNode = targetDocument.createTextNode(DomDummyNodeManager.DummyNodeContent); } else { dummy2TextNode = targetDocument.createTextNode(content); } dummyNode.classList.add(DomDummyNodeManager.DummyNodeClassName); dummyNode.appendChild(dummy2TextNode); return dummyNode; }; DomDummyNodeManager.DummyNodeClassName = 'dummyNode'; DomDummyNodeManager.DummyNodeBeforeFirstTagClassName = 'beforefirstTag'; DomDummyNodeManager.DummyNodeContent = String.fromCharCode(160); return DomDummyNodeManager; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var XmlCursorPos = /** @class */ (function () { function XmlCursorPos() { this.ActualNode = null; // no node selected this.PosAtNode = XMLCursorPositions.CursorOnCompleteNode; this.PosInTextnode = 0; } /** * @param {?} position * @return {?} */ XmlCursorPos.getXmlCursorPositionDebugName = /** * @param {?} position * @return {?} */ function (position) { switch (position) { case XMLCursorPositions.CursorOnCompleteNode: return 'CursorOnCompleteNode'; case XMLCursorPositions.CursorBehindNode: return 'CursorBehindNode'; case XMLCursorPositions.CursorInEmptyNode: return 'CursorInEmptyNode'; case XMLCursorPositions.CursorInsideTextNode: return 'CursorInsideTextNode'; case XMLCursorPositions.CursorInFrontOfNode: return 'CursorInFrontOfNode'; default: return "unknown cursorPos " + position; } }; /** * @param {?} pos * @return {?} */ XmlCursorPos.getSelectionForPos = /** * @param {?} pos * @return {?} */ function (pos) { if (DomDummyNodeManager.IsDummyNode(pos.ActualNode)) { throw new Error("XmlCursorPos.getSelectionForPos: pos.AktNode " + pos.getDebugDescription() + " is a dummy node!"); } if (DomDummyNodeManager.IsDummyNode(pos.ActualNode.parentElement)) { throw new Error("XmlCursorPos.getSelectionForPos: pos.AktNode.parentElement " + pos.getDebugDescription() + " is a dummy node!"); } switch (pos.PosAtNode) { case XMLCursorPositions.CursorOnCompleteNode: // (0) /** @type {?} */ var firstChild = pos.ActualNode.firstChild; if (DomDummyNodeManager.IsBeforeFirstTagDummyNode(firstChild)) { return { node: firstChild.firstChild, // text inside BeforeFirstTagDummyNod offset: 0 }; } else { return { node: pos.ActualNode, offset: 0 }; } case XMLCursorPositions.CursorInFrontOfNode: // (1) // (1) if (pos.ActualNode.nodeType === Node.TEXT_NODE) { /** @type {?} */ var dummyBefore = pos.ActualNode.previousSibling; if (DomDummyNodeManager.IsDummyNode(dummyBefore)) { return { node: dummyBefore.firstChild, // before text node offset: 1 }; } else { throw new Error('XMLCursorPositions.CursorInFrontOfNode (1):text node: is no dummy node: ' + pos.getDebugDescription()); } } else { // no text node firstChild = pos.ActualNode.firstChild; if (DomDummyNodeManager.IsBeforeFirstTagDummyNode(firstChild)) { return { node: firstChild.firstChild, // text inside BeforeFirstTagDummyNod offset: 1 }; } if (Xml2html.isNoClosingElement(pos.ActualNode) && DomDummyNodeManager.IsDummyNode(firstChild)) { return { node: firstChild.firstChild, offset: 1 }; } throw new Error('XMLCursorPositions.CursorInFrontOfNode (1):no text node: dont know what to do! '); } break; case XMLCursorPositions.CursorBehindNode: // (7, 11) /** @type {?} */ var dummyAfter = pos.ActualNode.nextSibling; if (DomDummyNodeManager.IsDummyNode(dummyAfter)) { return { node: dummyAfter.firstChild, // before text node offset: 0 }; } else { throw new Error("XMLCursorPositionen.CursorBehindNode should only be set, when the element has no next sibling."); } case XMLCursorPositions.CursorInEmptyNode: /** @type {?} */ var lastChild = pos.ActualNode.lastChild; if (!DomDummyNodeManager.IsDummyNode(firstChild) && !DomDummyNodeManager.IsBeforeFirstTagDummyNode(firstChild)) { return { node: lastChild.firstChild, // text inside DummyNode offset: 0 }; } break; case XMLCursorPositions.CursorInsideTextNode: return { node: pos.ActualNode, offset: pos.PosInTextnode }; } throw new Error("showCursor.getSelectionForPos unknown CursorPos " + pos.getDebugDescription()); }; /** * @return {?} */ XmlCursorPos.prototype.clone = /** * @return {?} */ function () { /** @type {?} */ var klon = new XmlCursorPos(); klon.SetCursor(this.ActualNode, this.PosAtNode, this.PosInTextnode); return klon; }; /** * @param {?} otherPos * @return {?} */ XmlCursorPos.prototype.equals = /** * @param {?} otherPos * @return {?} */ function (otherPos) { if (!otherPos) { return false; } if (otherPos.ActualNode !== this.ActualNode) { return false; } if (otherPos.PosAtNode !== this.PosAtNode) { return false; } if (this.PosAtNode === XMLCursorPositions.CursorInsideTextNode && this.PosInTextnode !== otherPos.PosInTextnode) { return false; } return true; }; /** * @return {?} */ XmlCursorPos.prototype.getDebugDescription = /** * @return {?} */ function () { return "node:" + XmlToolbox.GetNodeDebugContext(this.ActualNode) + ", pos:" + XmlCursorPos.getXmlCursorPositionDebugName(this.PosAtNode) + ", posInText:" + this.PosInTextnode; }; /** * @param {?} actualNode * @param {?} posAtNode * @param {?=} posInTextnode * @return {?} */ XmlCursorPos.prototype.SetCursor = /** * @param {?} actualNode * @param {?} posAtNode * @param {?=} posInTextnode * @return {?} */ function (actualNode, posAtNode, posInTextnode) { if (posInTextnode === void 0) { posInTextnode = 0; } if (!actualNode) { throw new Error('actualNode is null'); } if (actualNode !== this.ActualNode) ; else { if (posAtNode !== this.PosAtNode) ; else { if (posInTextnode !== this.PosInTextnode) ; } } this.ActualNode = actualNode; this.PosAtNode = posAtNode; this.PosInTextnode = posInTextnode; }; /** * @param {?} node * @return {?} */ XmlCursorPos.prototype.setCursorBehindNodeForDefaultOrRightMovement = /** * @param {?} node * @return {?} */ function (node) { /** @type {?} */ var nextSibling = DomDummyNodeManager.getNextSibling(node); if (nextSibling) { this.SetCursor(nextSibling, XMLCursorPositions.CursorInFrontOfNode); } else { this.SetCursor(node, XMLCursorPositions.CursorBehindNode); } }; /** * @param {?} node * @return {?} */ XmlCursorPos.prototype.setCursorpBehindNodeForLeftMovement = /** * @param {?} node * @return {?} */ function (node) { if (XmlToolbox.IsTextOrCommentNode(node)) { // For a text node, the cursor is placed after the last character. this.SetCursor(node, XMLCursorPositions.CursorInsideTextNode, Math.max(0, node.textContent.length - 1)); } else { /** @type {?} */ var childNodeCount = DomDummyNodeManager.getChildNodeCount(node); if (childNodeCount === 0) { // There are no children in the node. if (!Xml2html.isNoClosingElement(node)) { // If the cursor shows a close tag, then put it in the empty node this.SetCursor(node, XMLCursorPositions.CursorInEmptyNode); } else { // If the cursor does not display a close tag, then place it before the empty node. this.SetCursor(node, XMLCursorPositions.CursorInFrontOfNode); } } else { // There are children in node this.SetCursor(DomDummyNodeManager.getLastChild(node), XMLCursorPositions.CursorBehindNode); } } }; return XmlCursorPos; }()); /** @enum {number} */ var XMLCursorPositions = { CursorInFrontOfNode: 0, CursorOnCompleteNode: 1, CursorInEmptyNode: 2, CursorInsideTextNode: 3, CursorBehindNode: 4, }; XMLCursorPositions[XMLCursorPositions.CursorInFrontOfNode] = 'CursorInFrontOfNode'; XMLCursorPositions[XMLCursorPositions.CursorOnCompleteNode] = 'CursorOnCompleteNode'; XMLCursorPositions[XMLCursorPositions.CursorInEmptyNode] = 'CursorInEmptyNode'; XMLCursorPositions[XMLCursorPositions.CursorInsideTextNode] = 'CursorInsideTextNode'; XMLCursorPositions[XMLCursorPositions.CursorBehindNode] = 'CursorBehindNode'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var XmlCursorPosMover = /** @class */ (function () { function XmlCursorPosMover() { } /** * @param {?} pos * @param {?} rootNode * @param {?} xmlRules * @return {?} */ XmlCursorPosMover.moveLeft = /** * @param {?} pos * @param {?} rootNode * @param {?} xmlRules * @return {?} */ function (pos, rootNode, xmlRules) { if (pos === undefined) { return false; } switch (pos.PosAtNode) { case XMLCursorPositions.CursorOnCompleteNode: // Put in front of the node pos.SetCursor(pos.ActualNode, XMLCursorPositions.CursorInFrontOfNode); break; case XMLCursorPositions.CursorInFrontOfNode: if (pos.ActualNode === rootNode) { return false; } else { /** @type {?} */ var previousSibling = DomDummyNodeManager.getPreviousSibling(pos.ActualNode); if (previousSibling) { // Previous sibling node exists pos.setCursorpBehindNodeForLeftMovement(previousSibling); } else { // no previous sibling node available -> set before parent node pos.SetCursor(pos.ActualNode.parentNode, XMLCursorPositions.CursorInFrontOfNode); } } break; case XMLCursorPositions.CursorBehindNode: pos.setCursorpBehindNodeForLeftMovement(pos.ActualNode); break; case XMLCursorPositions.CursorInEmptyNode: // Put in front of the node pos.SetCursor(pos.ActualNode, XMLCursorPositions.CursorInFrontOfNode); break; case XMLCursorPositions.CursorInsideTextNode: if (XmlToolbox.IsTextOrCommentNode(pos.ActualNode)) { // Node is Textnode if (pos.PosInTextnode > 1) { // Cursor one character to the left pos.SetCursor(pos.ActualNode, pos.PosAtNode, pos.PosInTextnode - 1); } else { // Put in front of the node pos.SetCursor(pos.ActualNode, XMLCursorPositions.CursorInFrontOfNode); } } else { /** @type {?} */ var elemt = /** @type {?} */ (pos.ActualNode); throw new Error("XMLCursorPos.MoveLeft: CursorPos is XMLCursorPositionen.CursorInnerhalbDesTextNodes,\n but no text node has been chosen, but the node " + (elemt ? elemt.outerHTML : '')); } break; default: throw new Error("XMLCursorPos.MoveLeft: unknown CursorPos " + pos.PosAtNode); } return true; }; /** * @param {?} pos * @param {?} rootNode * @param {?} xmlRules * @return {?} */ XmlCursorPosMover.moveRight = /** * @param {?} pos * @param {?} rootNode * @param {?} xmlRules * @return {?} */ function (pos, rootNode, xmlRules) { if (pos === undefined) { return false; } switch (pos.PosAtNode) { case XMLCursorPositions.CursorOnCompleteNode: /** @type {?} */ var tagName = Xml2html.getTagNameFromNode(pos.ActualNode); /** @type {?} */ var rule = xmlRules.ruleElements.get(tagName); if (rule && rule.empty === true) { pos.setCursorBehindNodeForDefaultOrRightMovement(pos.ActualNode); } else { /** @type {?} */ var firstChild = DomDummyNodeManager.getFirstChild(pos.ActualNode); if (firstChild) { pos.SetCursor(firstChild, XMLCursorPositions.CursorInFrontOfNode); } else { pos.SetCursor(pos.ActualNode, XMLCursorPositions.CursorInEmptyNode); } } break; case XMLCursorPositions.CursorBehi