all files / editor-manager/plugin/ formats.js

93.33% Statements 294/315
90.36% Branches 253/280
100% Functions 23/23
93.33% Lines 294/315
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496   1892× 1892× 1892×   1892× 1892× 1892× 1892× 1892×   1747× 1747× 1747× 1747×   53× 41×   53×     91× 91× 91× 91× 17× 17× 17×         17× 17×           91×         452× 192× 192×   192×   192× 192× 192× 192× 192× 192×   191×   191×                             191× 11× 11× 11× 11× 11× 11× 11× 11×       11×                         451×   13× 13×             13×                     10× 10×   10×           10×   10× 10× 10× 10×   10×                         10× 10×         161× 161× 161×       161× 161× 161× 161× 11× 11× 11× 11× 11×   11× 18× 18× 18× 37× 37×   18× 18×     11× 18× 18× 18× 18×       18× 18×   18× 18× 18× 18×           18× 18×         18×   18× 18×         18×       11× 11×   161× 161× 161× 267×   257×     161× 267× 267× 267× 53× 53×     47×         42×         214× 214×   267×         18×   249× 249×   249×   249×   249×   249× 249×   247×               241×   249×   241× 236×   236×     161×                   161× 161× 161× 161× 161× 47× 47×   161× 161×     161×     159×   161× 119×                 22× 22× 22× 16×         161× 161× 161× 26× 26×         161× 161× 161× 50×     50× 50× 18× 18×         249× 249× 249× 1120×     1747×        
define(["require", "exports", "./../../common/constant", "@syncfusion/ej2-base", "../../common/util", "./dom-node", "./nodecutter"], function (require, exports, EVENTS, ej2_base_1, util_1, dom_node_1, nodecutter_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Formats = (function () {
        function Formats(parent) {
            this.blockquotePrevent = false;
            this.parent = parent;
            this.addEventListener();
        }
        Formats.prototype.addEventListener = function () {
            this.parent.observer.on(EVENTS.FORMAT_TYPE, this.applyFormats, this);
            this.parent.observer.on(EVENTS.KEY_UP_HANDLER, this.onKeyUp, this);
            this.parent.observer.on(EVENTS.KEY_DOWN_HANDLER, this.onKeyDown, this);
            this.parent.observer.on(EVENTS.BLOCKQUOTE_LIST_HANDLE, this.blockQuotesHandled, this);
            this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
        };
        Formats.prototype.removeEventListener = function () {
            this.parent.observer.off(EVENTS.FORMAT_TYPE, this.applyFormats);
            this.parent.observer.off(EVENTS.KEY_UP_HANDLER, this.onKeyUp);
            this.parent.observer.off(EVENTS.KEY_DOWN_HANDLER, this.onKeyDown);
            this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
        };
        Formats.prototype.getParentNode = function (node) {
            for (; node.parentNode && node.parentNode !== this.parent.editableElement; null) {
                node = node.parentNode;
            }
            return node;
        };
        Formats.prototype.blockQuotesHandled = function () {
            this.blockquotePrevent = true;
        };
        Formats.prototype.onKeyUp = function (e) {
            var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
            var endCon = range.endContainer;
            var lastChild = endCon.lastChild;
            if (e.event.which === 13 && range.startContainer === endCon && endCon.nodeType !== 3) {
                var pTag = ej2_base_1.createElement('p');
                pTag.innerHTML = '<br>';
                Iif (!ej2_base_1.isNullOrUndefined(lastChild) && lastChild && lastChild.nodeName === 'BR' && (lastChild.previousSibling && lastChild.previousSibling.nodeName === 'TABLE')) {
                    endCon.replaceChild(pTag, lastChild);
                    this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, pTag, 0);
                }
                else {
                    var brNode = this.parent.nodeSelection.getSelectionNodeCollectionBr(range)[0];
                    Iif (!ej2_base_1.isNullOrUndefined(brNode) && brNode.nodeName === 'BR' && (brNode.previousSibling && brNode.previousSibling.nodeName === 'TABLE')) {
                        endCon.replaceChild(pTag, brNode);
                        this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, pTag, 0);
                    }
                }
            }
            if (e.enterAction !== 'BR' && !ej2_base_1.isNullOrUndefined(range.startContainer) && !ej2_base_1.isNullOrUndefined(range.startContainer.parentElement) && range.startContainer === range.endContainer && range.startContainer.nodeName === '#text' && range.startContainer.parentElement.classList.contains('e-content') && range.startContainer.parentElement.isContentEditable) {
                var pTag = ej2_base_1.createElement(e.enterAction);
                range.startContainer.parentElement.insertBefore(pTag, range.startContainer);
                pTag.appendChild(range.startContainer);
                this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, pTag, 1);
            }
        };
        Formats.prototype.getBlockParent = function (node, endNode) {
            var currentParent = node;
            while (node !== endNode) {
                currentParent = node;
                node = node.parentElement;
            }
            return currentParent;
        };
        Formats.prototype.onKeyDown = function (e) {
            if (e.event.which === 13 && !this.blockquotePrevent) {
                var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
                var startCon = (range.startContainer.textContent.length === 0 || range.startContainer.nodeName === 'PRE')
                    ? range.startContainer : range.startContainer.parentElement;
                var endCon = (range.endContainer.textContent.length === 0 || range.endContainer.nodeName === 'PRE')
                    ? range.endContainer : range.endContainer.parentElement;
                var preElem = ej2_base_1.closest(startCon, 'pre');
                var endPreElem = ej2_base_1.closest(endCon, 'pre');
                var blockquoteEle = ej2_base_1.closest(startCon, 'blockquote');
                var endBlockquoteEle = ej2_base_1.closest(endCon, 'blockquote');
                var liParent = !ej2_base_1.isNullOrUndefined(preElem) && !ej2_base_1.isNullOrUndefined(preElem.parentElement) && preElem.parentElement.tagName === 'LI';
                if (liParent) {
                    return;
                }
                if (((ej2_base_1.isNullOrUndefined(preElem) && !ej2_base_1.isNullOrUndefined(endPreElem)) || (!ej2_base_1.isNullOrUndefined(preElem) && ej2_base_1.isNullOrUndefined(endPreElem)))) {
                    e.event.preventDefault();
                    this.deleteContent(range);
                    this.removeCodeContent(range);
                    range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
                    this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, endCon, 0);
                }
                if (e.event.which === 13 && ((!ej2_base_1.isNullOrUndefined(blockquoteEle) && !ej2_base_1.isNullOrUndefined(endBlockquoteEle)) ||
                    (!ej2_base_1.isNullOrUndefined(blockquoteEle) && ej2_base_1.isNullOrUndefined(endBlockquoteEle)))) {
                    var startParent = this.getBlockParent(range.startContainer, blockquoteEle);
                    if ((startParent.textContent.charCodeAt(0) === 8203 &&
                        startParent.textContent.length === 1) || (startParent.textContent.length === 0 &&
                        startParent.querySelectorAll('img').length === 0 &&
                        startParent.querySelectorAll('table').length === 0)) {
                        e.event.preventDefault();
                        Eif (ej2_base_1.isNullOrUndefined(startParent.nextElementSibling)) {
                            this.paraFocus(startParent.parentElement === this.parent.editableElement ?
                                startParent : startParent.parentElement);
                        }
                        else {
                            var nodeCutter = new nodecutter_1.NodeCutter();
                            var newElem = nodeCutter.SplitNode(range, startParent.parentElement, false).cloneNode(true);
                            this.paraFocus(startParent.parentElement === this.parent.editableElement ?
                                startParent : startParent.parentElement);
                        }
                    }
                }
                if (e.event.which === 13 && !ej2_base_1.isNullOrUndefined(preElem) && !ej2_base_1.isNullOrUndefined(endPreElem)) {
                    e.event.preventDefault();
                    this.deleteContent(range);
                    this.removeCodeContent(range);
                    range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
                    var lastEmpty = range.startContainer.childNodes[range.endOffset];
                    var lastBeforeBr = range.startContainer.childNodes[range.endOffset - 1];
                    var startParent = range.startContainer;
                    Iif (!ej2_base_1.isNullOrUndefined(lastEmpty) && !ej2_base_1.isNullOrUndefined(lastBeforeBr) && ej2_base_1.isNullOrUndefined(lastEmpty.nextSibling) &&
                        lastEmpty.nodeName === 'BR' && lastBeforeBr.nodeName === 'BR') {
                        this.paraFocus(range.startContainer, e.enterAction);
                    }
                    else if ((startParent.textContent.charCodeAt(0) === 8203 &&
                        startParent.textContent.length === 1) || startParent.textContent.length === 0) {
                        while (startParent.parentElement.nodeName !== 'PRE' &&
                            (startParent.textContent.length === 1 || startParent.textContent.length === 0)) {
                            startParent = startParent.parentElement;
                        }
                        if (!ej2_base_1.isNullOrUndefined(startParent.previousSibling) && startParent.previousSibling.nodeName === 'BR' &&
                            ej2_base_1.isNullOrUndefined(startParent.nextSibling)) {
                            this.paraFocus(startParent.parentElement);
                        }
                        else {
                            this.isNotEndCursor(preElem, range);
                        }
                    }
                    else {
                        this.isNotEndCursor(preElem, range);
                    }
                }
            }
            this.blockquotePrevent = false;
        };
        Formats.prototype.removeCodeContent = function (range) {
            var regEx = new RegExp('\uFEFF', 'g');
            if (!ej2_base_1.isNullOrUndefined(range.endContainer.textContent.match(regEx))) {
                var pointer = range.endContainer.textContent.charCodeAt(range.endOffset - 1) === 65279 ?
                    range.endOffset - 2 : range.endOffset;
                range.endContainer.textContent = range.endContainer.textContent.replace(regEx, '');
                if (range.endContainer.textContent === '') {
                    this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, range.endContainer.parentElement, 0);
                }
                else {
                    this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, range.endContainer, pointer);
                }
            }
        };
        Formats.prototype.deleteContent = function (range) {
            if (range.startContainer !== range.endContainer || range.startOffset !== range.endOffset) {
                range.deleteContents();
            }
        };
        Formats.prototype.paraFocus = function (referNode, enterAction) {
            var insertTag;
            Iif (enterAction === 'DIV') {
                insertTag = ej2_base_1.createElement('div');
                insertTag.innerHTML = '<br>';
            }
            else Iif (enterAction === 'BR') {
                insertTag = ej2_base_1.createElement('br');
            }
            else {
                insertTag = ej2_base_1.createElement('p');
                insertTag.innerHTML = '<br>';
            }
            this.parent.domNode.insertAfter(insertTag, referNode);
            this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, insertTag, 0);
            ej2_base_1.detach(referNode.lastChild);
        };
        Formats.prototype.isNotEndCursor = function (preElem, range) {
            var nodeCutter = new nodecutter_1.NodeCutter();
            var isEnd = range.startOffset === preElem.lastChild.textContent.length &&
                preElem.lastChild.textContent === range.startContainer.textContent;
            if (preElem.textContent.indexOf(range.startContainer.textContent) === 0 &&
                ((range.startOffset === 0 && range.endOffset === 0) || range.startContainer.nodeName === 'PRE')) {
                this.insertMarker(preElem, range);
                var brTag = ej2_base_1.createElement('br');
                preElem.childNodes[range.endOffset].parentElement.insertBefore(brTag, preElem.childNodes[range.endOffset]);
            }
            else {
                var cloneNode = nodeCutter.SplitNode(range, preElem, true);
                this.insertMarker(preElem, range);
                var previousSib = preElem.previousElementSibling;
                Eif (previousSib.tagName === 'PRE') {
                    previousSib.insertAdjacentHTML('beforeend', '<br>' + cloneNode.innerHTML);
                    ej2_base_1.detach(preElem);
                }
            }
            this.setCursorPosition(isEnd, preElem);
        };
        Formats.prototype.setCursorPosition = function (isEnd, preElem) {
            var isEmpty = false;
            var markerElem = this.parent.editableElement.querySelector('.tempSpan');
            var mrkParentElem = markerElem.parentElement;
            markerElem.parentNode.textContent === '' ? isEmpty = true :
                this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, markerElem, 0);
            if (isEnd) {
                if (isEmpty) {
                    Eif (mrkParentElem === preElem) {
                        this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, markerElem, 0);
                        ej2_base_1.detach(markerElem);
                    }
                    else {
                        this.focusSelectionParent(markerElem, mrkParentElem);
                    }
                }
                else {
                    var brElm = ej2_base_1.createElement('br');
                    this.parent.domNode.insertAfter(brElm, markerElem);
                    this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, markerElem, 0);
                    ej2_base_1.detach(markerElem);
                }
            }
            else {
                isEmpty ? this.focusSelectionParent(markerElem, mrkParentElem) : ej2_base_1.detach(markerElem);
            }
        };
        Formats.prototype.focusSelectionParent = function (markerElem, tempSpanPElem) {
            ej2_base_1.detach(markerElem);
            tempSpanPElem.innerHTML = '\u200B';
            this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, tempSpanPElem, 0);
        };
        Formats.prototype.insertMarker = function (preElem, range) {
            var tempSpan = ej2_base_1.createElement('span', { className: 'tempSpan' });
            if (range.startContainer.nodeName === 'PRE') {
                preElem.childNodes[range.endOffset].parentElement.insertBefore(tempSpan, preElem.childNodes[range.endOffset]);
            }
            else {
                range.startContainer.parentElement.insertBefore(tempSpan, range.startContainer);
            }
        };
        Formats.prototype.applyFormats = function (e) {
            var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
            var isSelectAll = false;
            if (this.parent.editableElement === range.endContainer &&
                !ej2_base_1.isNullOrUndefined(this.parent.editableElement.children[range.endOffset - 1]) &&
                this.parent.editableElement.children[range.endOffset - 1].tagName === 'TABLE' && !range.collapsed) {
                isSelectAll = true;
            }
            var save = this.parent.nodeSelection.save(range, this.parent.currentDocument);
            this.parent.domNode.setMarker(save);
            var formatsNodes = this.parent.domNode.blockNodes(true);
            if (e.enterAction === 'BR') {
                this.setSelectionBRConfig();
                var allSelectedNode = this.parent.nodeSelection.getSelectedNodes(this.parent.currentDocument);
                var selectedNodes = this.parent.nodeSelection.getSelectionNodes(allSelectedNode);
                var currentFormatNodes = [];
                if (selectedNodes.length === 0) {
                    selectedNodes.push(formatsNodes[0]);
                }
                for (var i = 0; i < selectedNodes.length; i++) {
                    var currentNode = selectedNodes[i];
                    var previousCurrentNode = void 0;
                    while (!this.parent.domNode.isBlockNode(currentNode) && currentNode !== this.parent.editableElement) {
                        previousCurrentNode = currentNode;
                        currentNode = currentNode.parentElement;
                    }
                    Eif (this.parent.domNode.isBlockNode(currentNode) && currentNode === this.parent.editableElement) {
                        currentFormatNodes.push(previousCurrentNode);
                    }
                }
                for (var i = 0; i < currentFormatNodes.length; i++) {
                    Eif (!this.parent.domNode.isBlockNode(currentFormatNodes[i])) {
                        var currentNode = currentFormatNodes[i];
                        var previousNode = currentNode;
                        while (currentNode === this.parent.editableElement) {
                            previousNode = currentNode;
                            currentNode = currentNode.parentElement;
                        }
                        var tempElem = void 0;
                        Eif (this.parent.domNode.isBlockNode(previousNode.parentElement) &&
                            previousNode.parentElement === this.parent.editableElement) {
                            tempElem = ej2_base_1.createElement('div');
                            previousNode.parentElement.insertBefore(tempElem, previousNode);
                            tempElem.appendChild(previousNode);
                            if (previousNode.textContent.length === 0) {
                                previousNode.appendChild(ej2_base_1.createElement('br'));
                            }
                        }
                        else {
                            tempElem = previousNode;
                        }
                        var preNode = tempElem.previousSibling;
                        while (!ej2_base_1.isNullOrUndefined(preNode) && preNode.nodeName !== 'BR' &&
                            !this.parent.domNode.isBlockNode(preNode)) {
                            tempElem.firstChild.parentElement.insertBefore(preNode, tempElem.firstChild);
                            preNode = tempElem.previousSibling;
                        }
                        if (!ej2_base_1.isNullOrUndefined(preNode) && preNode.nodeName === 'BR') {
                            ej2_base_1.detach(preNode);
                        }
                        var postNode = tempElem.nextSibling;
                        while (!ej2_base_1.isNullOrUndefined(postNode) && postNode.nodeName !== 'BR' &&
                            !this.parent.domNode.isBlockNode(postNode)) {
                            tempElem.appendChild(postNode);
                            postNode = tempElem.nextSibling;
                        }
                        if (!ej2_base_1.isNullOrUndefined(postNode) && postNode.nodeName === 'BR') {
                            ej2_base_1.detach(postNode);
                        }
                    }
                }
                this.setSelectionBRConfig();
                formatsNodes = this.parent.domNode.blockNodes();
            }
            var isWholeBlockquoteNotSelected = false;
            var isPartiallySelected = false;
            for (var i = 0; i < formatsNodes.length; i++) {
                if (ej2_base_1.isNullOrUndefined(ej2_base_1.closest(formatsNodes[0], 'blockquote')) ||
                    ej2_base_1.isNullOrUndefined(ej2_base_1.closest(formatsNodes[formatsNodes.length - 1], 'blockquote'))) {
                    isPartiallySelected = true;
                }
            }
            for (var i = 0; i < formatsNodes.length; i++) {
                var parentNode = void 0;
                var replaceHTML = void 0;
                if (e.subCommand.toLowerCase() === 'blockquote') {
                    parentNode = this.getParentNode(formatsNodes[i]);
                    if (e.enterAction === 'BR') {
                        replaceHTML = parentNode.innerHTML;
                    }
                    else {
                        if (!ej2_base_1.isNullOrUndefined(ej2_base_1.closest(formatsNodes[i], 'table')) && this.parent.editableElement.contains(ej2_base_1.closest(formatsNodes[i], 'table'))) {
                            replaceHTML = !ej2_base_1.isNullOrUndefined(ej2_base_1.closest((formatsNodes[i]), 'blockquote')) ?
                                ej2_base_1.closest((formatsNodes[i]), 'blockquote').outerHTML :
                                (formatsNodes[i]).outerHTML;
                        }
                        else {
                            replaceHTML = parentNode.outerHTML;
                        }
                    }
                }
                else {
                    parentNode = formatsNodes[i];
                    replaceHTML = parentNode.innerHTML;
                }
                if ((e.subCommand.toLowerCase() === 'blockquote' && e.subCommand.toLowerCase() === parentNode.tagName.toLowerCase() && isPartiallySelected) ||
                    ((e.subCommand.toLowerCase() === parentNode.tagName.toLowerCase() &&
                        (e.subCommand.toLowerCase() !== 'pre' && e.subCommand.toLowerCase() !== 'blockquote' ||
                            (!ej2_base_1.isNullOrUndefined(e.exeValue) && e.exeValue.name === 'dropDownSelect'))) ||
                        ej2_base_1.isNullOrUndefined(parentNode.parentNode) || (parentNode.tagName === 'TABLE' && e.subCommand.toLowerCase() === 'pre'))) {
                    continue;
                }
                this.cleanFormats(parentNode, e.subCommand);
                var replaceNode = (e.subCommand.toLowerCase() === 'pre' && parentNode.tagName.toLowerCase() === 'pre') ?
                    'p' : e.subCommand;
                var isToggleBlockquoteList = e.subCommand.toLowerCase() === parentNode.tagName.toLowerCase() &&
                    e.subCommand.toLowerCase() === 'blockquote' && this.parent.domNode.isList(parentNode.firstElementChild);
                var ensureNode = parentNode.tagName === 'TABLE' ?
                    (!ej2_base_1.isNullOrUndefined(ej2_base_1.closest((formatsNodes[i]), 'blockquote')) ? ej2_base_1.closest((formatsNodes[i]), 'blockquote') : parentNode) : parentNode;
                var isToggleBlockquote = (e.subCommand.toLowerCase() === ensureNode.tagName.toLowerCase())
                    && e.subCommand.toLowerCase() === 'blockquote';
                var replaceTag = void 0;
                if (isToggleBlockquoteList) {
                    replaceTag = replaceHTML.replace('<blockquote>', '').replace('</blockquote>', '');
                }
                else if (isToggleBlockquote && ej2_base_1.closest(formatsNodes[0], 'blockquote') && ej2_base_1.closest(formatsNodes[formatsNodes.length - 1], 'blockquote')) {
                    if (ej2_base_1.isNullOrUndefined(formatsNodes[0].previousSibling) && ej2_base_1.isNullOrUndefined(formatsNodes[formatsNodes.length - 1].nextSibling)) {
                        replaceTag = replaceHTML.replace(/<blockquote[^>]*>|<\/blockquote>/g, '');
                    }
                    else {
                        isWholeBlockquoteNotSelected = true;
                        if (i === 0) {
                            var tempCloseSpanElem = ej2_base_1.createElement('span');
                            tempCloseSpanElem.classList.add('e-rte-blockquote-close');
                            formatsNodes[i].parentNode.insertBefore(tempCloseSpanElem, formatsNodes[i]);
                        }
                        if (i === formatsNodes.length - 1) {
                            var tempOpenSpanElem = ej2_base_1.createElement('span');
                            tempOpenSpanElem.classList.add('e-rte-blockquote-open');
                            this.parent.domNode.insertAfter(tempOpenSpanElem, formatsNodes[i]);
                        }
                    }
                }
                else {
                    replaceTag = this.parent.domNode.createTagString(replaceNode, (e.subCommand.toLowerCase() === 'blockquote' ? null : parentNode), replaceHTML.replace(/>\s+</g, '><'));
                }
                if (parentNode.tagName === 'LI') {
                    parentNode.innerHTML = '';
                    parentNode.insertAdjacentHTML('beforeend', replaceTag);
                }
                else if (!isWholeBlockquoteNotSelected) {
                    var currentTag = ((!ej2_base_1.isNullOrUndefined(ej2_base_1.closest(formatsNodes[i], 'table')) && this.parent.editableElement.contains(ej2_base_1.closest(formatsNodes[i], 'table'))) ?
                        (!ej2_base_1.isNullOrUndefined(ej2_base_1.closest((formatsNodes[i]), 'blockquote')) ? ej2_base_1.closest((formatsNodes[i]), 'blockquote') : formatsNodes[i]) : parentNode);
                    this.parent.domNode.replaceWith(currentTag, replaceTag);
                }
            }
            if (isWholeBlockquoteNotSelected) {
                var blockquoteElem = this.parent.editableElement.querySelectorAll('.e-rte-blockquote-open, .e-rte-blockquote-close');
                for (var i = 0; i < blockquoteElem.length; i++) {
                    var blockquoteNode = blockquoteElem[i].parentElement;
                    var blockquoteContent = blockquoteNode.innerHTML;
                    blockquoteContent = blockquoteContent.replace(/<span class="e-rte-blockquote-open"><\/span>/g, '<blockquote>');
                    blockquoteContent = blockquoteContent.replace(/<span class="e-rte-blockquote-close"><\/span>/g, '</blockquote>');
                    if (blockquoteElem[0].parentElement === blockquoteElem[1].parentElement) {
                        this.parent.domNode.replaceWith(blockquoteNode, this.parent.domNode.openTagString(blockquoteNode) +
                            blockquoteContent.trim() + this.parent.domNode.closeTagString(blockquoteNode));
                        break;
                    }
                    else if (i === blockquoteElem.length - 1 && !ej2_base_1.isNullOrUndefined(blockquoteElem[i]) && !ej2_base_1.isNullOrUndefined(blockquoteElem[i - 1]) &&
                        blockquoteElem[i].parentElement !== blockquoteElem[i - 1].parentElement) {
                        this.parent.domNode.replaceWith(blockquoteNode, blockquoteContent.trim());
                    }
                    else {
                        this.parent.domNode.replaceWith(blockquoteNode, this.parent.domNode.openTagString(blockquoteNode) +
                            blockquoteContent.trim() + this.parent.domNode.closeTagString(blockquoteNode));
                    }
                }
            }
            this.preFormatMerge();
            this.blockquotesFormatMerge(e.enterAction);
            var startNode = this.parent.editableElement.querySelector('.' + dom_node_1.markerClassName.startSelection);
            var endNode = this.parent.editableElement.querySelector('.' + dom_node_1.markerClassName.endSelection);
            if (!ej2_base_1.isNullOrUndefined(startNode) && !ej2_base_1.isNullOrUndefined(endNode)) {
                startNode = startNode.lastChild;
                endNode = endNode.lastChild;
            }
            save = this.parent.domNode.saveMarker(save);
            Iif (util_1.isIDevice()) {
                util_1.setEditFrameFocus(this.parent.editableElement, e.selector);
            }
            if (isSelectAll) {
                this.parent.nodeSelection.setSelectionText(this.parent.currentDocument, startNode, endNode, 0, endNode.textContent.length);
            }
            else {
                save.restore();
            }
            if (e.callBack) {
                e.callBack({
                    requestType: e.subCommand,
                    editorMode: 'HTML',
                    event: e.event,
                    range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
                    elements: this.parent.domNode.blockNodes()
                });
            }
        };
        Formats.prototype.setSelectionBRConfig = function () {
            var startElem = this.parent.editableElement.querySelector('.' + dom_node_1.markerClassName.startSelection);
            var endElem = this.parent.editableElement.querySelector('.' + dom_node_1.markerClassName.endSelection);
            if (ej2_base_1.isNullOrUndefined(endElem)) {
                this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, startElem, 0);
            }
            else {
                this.parent.nodeSelection.setSelectionText(this.parent.currentDocument, startElem, endElem, 0, 0);
            }
        };
        Formats.prototype.preFormatMerge = function () {
            var preNodes = this.parent.editableElement.querySelectorAll('PRE');
            Eif (!ej2_base_1.isNullOrUndefined(preNodes)) {
                for (var i = 0; i < preNodes.length; i++) {
                    var previousSib = preNodes[i].previousElementSibling;
                    if (!ej2_base_1.isNullOrUndefined(previousSib) && previousSib.tagName === 'PRE') {
                        previousSib.insertAdjacentHTML('beforeend', '<br>' + preNodes[i].innerHTML);
                        ej2_base_1.detach(preNodes[i]);
                    }
                }
            }
        };
        Formats.prototype.blockquotesFormatMerge = function (enterAction) {
            var blockquoteNodes = this.parent.editableElement.querySelectorAll('BLOCKQUOTE');
            Eif (!ej2_base_1.isNullOrUndefined(blockquoteNodes)) {
                for (var i = 0; i < blockquoteNodes.length; i++) {
                    Iif (blockquoteNodes[i].innerHTML.trim() === '') {
                        ej2_base_1.detach(blockquoteNodes[i]);
                    }
                    var previousSib = blockquoteNodes[i].previousElementSibling;
                    if (!ej2_base_1.isNullOrUndefined(previousSib) && previousSib.tagName === 'BLOCKQUOTE') {
                        previousSib.insertAdjacentHTML('beforeend', (enterAction === 'BR' ? '<br>' : '') + blockquoteNodes[i].innerHTML);
                        ej2_base_1.detach(blockquoteNodes[i]);
                    }
                }
            }
        };
        Formats.prototype.cleanFormats = function (element, tagName) {
            var ignoreAttr = ['display', 'font-size', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'font-weight'];
            tagName = tagName.toLowerCase();
            for (var i = 0; i < ignoreAttr.length && (tagName !== 'p' && tagName !== 'blockquote' && tagName !== 'pre'); i++) {
                element.style.removeProperty(ignoreAttr[i]);
            }
        };
        Formats.prototype.destroy = function () {
            this.removeEventListener();
        };
        return Formats;
    }());
    exports.Formats = Formats;
});