all files / spreadsheet/actions/ note.js

97.71% Statements 554/567
92.99% Branches 411/442
96.83% Functions 61/63
97.85% Lines 547/559
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 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 8071×                     1×   1× 1× 1× 1446× 1446× 1446× 1446×   1× 1449× 1449× 1449× 4× 4× 4× 4× 3× 3×   4×   4× 4× 3×       1449× 1449× 1449×   1× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446× 1446×   1× 1449× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38×     1× 220144×   1× 420×   1× 252×   1× 158× 158× 241×   6×   1× 8× 8× 8× 8× 7× 7×   7× 4×     3×       1× 33× 33× 33× 33× 29× 29× 2×   29× 29× 29× 29× 29× 29×     1× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 5×   17× 9×   17× 17× 17× 5× 5×   17×     17× 5× 5×       1× 14×   14× 14× 14× 14× 14×   14× 14×       1× 217×   217×   217× 56× 56× 56× 69× 18× 6×         12×         69× 7× 2×     5×         217× 210× 2×   2× 2× 2× 2×   210× 204× 204×   210×     1× 11× 11× 11× 11× 11× 11× 3×   8× 8× 8× 8× 12× 4× 4× 1×   3× 3×       8× 1×     7× 7× 3×     1× 8× 8× 8× 8× 8× 8× 2×   6× 6× 6× 6× 6× 6× 6×   1× 1×       1× 7× 7×   1× 2×   1× 3×   1× 99× 99× 99× 99× 99× 99× 25×     74× 74× 74× 74× 74× 33× 33×   74× 40×   74× 74× 74× 74×   99× 99×   1× 32× 32× 32× 8×   32× 13×     1× 69× 69×   1× 106× 106× 106× 106×     103×         103× 103× 103×             3×   106× 106× 106× 106×   106× 106× 106× 106× 3×     103×   106× 106× 106× 106× 106× 106× 106× 70×     36×   106× 106× 106×       1× 106× 106× 106× 106× 106× 106× 106× 106× 106× 3× 3×     103×   106×   106× 106× 106× 44× 44×     62× 62×   106× 106× 106× 106× 106× 103× 103×     3×     1× 70× 70× 62×   62×     62× 62×       1× 27× 27× 27× 21× 21× 21× 19×     6× 3× 2× 4× 2×           1× 145× 145× 145× 49× 49× 49× 49× 48×     145× 50× 50× 49×     145× 145× 144×   145× 38×   145× 145× 3×     1× 714× 714× 714× 714× 670× 669×   670× 3×   670×   44× 44× 44× 94× 94×   94× 7× 7× 7× 7× 4× 4× 4× 4× 4×   4× 4× 4×     94× 8×       86×     44× 37×     1× 74× 74× 74× 5× 5× 5× 5×   74× 74× 5× 5×   74× 51×   74×   1× 715× 715× 715× 1088× 715×   373× 371× 14×         1× 65× 1×   65× 65×   1× 27× 27× 27× 27× 27× 27× 25× 25× 25× 22× 22× 13×     25× 10× 10×       25× 25× 15× 15×     12× 20× 20× 20× 3× 3× 3×     9× 9× 9× 6×       1× 7× 7× 7× 7× 7× 7× 7×     1× 5× 5× 5× 5× 4× 6× 6×         5× 5× 4× 6× 3×       3×         1× 44× 44× 48× 2× 5× 4× 4× 4× 4× 4× 4× 3×     1×             1× 49× 49× 1×   49× 12× 33× 11× 10× 10× 10×       37× 36× 36× 6×   36× 1×   36× 36× 24× 24× 23× 22×         23× 7×                 1× 72×     112× 72× 55× 23×     32×       17× 9×       1× 8× 8× 6× 6× 4× 4× 4× 4× 4× 4×       1× 21× 18× 18× 18× 18× 1×   18× 18× 18× 18× 12× 9× 9× 9× 3×   9×       3×   12× 11× 11× 5×   11× 2×       6× 6× 6× 6×   6× 5× 5× 5× 5× 5×   5× 5× 1×           1×   1×    
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
define(["require", "exports", "../common/index", "@syncfusion/ej2-base", "../../workbook/common/index", "../../workbook/index", "../../workbook/index"], function (require, exports, index_1, ej2_base_1, index_2, index_3, index_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SpreadsheetNote = (function () {
        function SpreadsheetNote(parent) {
            this.activeNoteCell = null;
            this.isShowAllNotes = false;
            this.parent = parent;
            this.addEventListener();
        }
        SpreadsheetNote.prototype.destroy = function () {
            var _this = this;
            this.removeEventListener();
            if (!this.parent.isDestroyed && !this.parent.refreshing) {
                var noteIndicators = this.parent.element.getElementsByClassName('e-addNoteIndicator');
                while (noteIndicators.length) {
                    var cellEle = ej2_base_1.closest(noteIndicators[0], '.e-cell');
                    if (cellEle) {
                        ej2_base_1.EventHandler.remove(cellEle, 'mouseover', this.mouseOver);
                        ej2_base_1.EventHandler.remove(cellEle, 'mouseout', this.mouseOut);
                    }
                    ej2_base_1.detach(noteIndicators[0]);
                }
                this.parent.sheets.forEach(function (sheet) {
                    if (sheet.notes) {
                        sheet.notes.forEach(function (note) { return _this.removeNoteElement(note); });
                    }
                });
            }
            this.activeNoteCell = null;
            this.isShowAllNotes = null;
            this.parent = null;
        };
        SpreadsheetNote.prototype.addEventListener = function () {
            this.parent.on(index_1.addNote, this.addNote, this);
            this.parent.on(index_1.editNote, this.editNote, this);
            this.parent.on(index_1.deleteNote, this.deleteNote, this);
            this.parent.on(index_1.createNoteIndicator, this.createNoteIndicator, this);
            this.parent.on(index_1.showNote, this.showNote, this);
            this.parent.on(index_1.removeNoteContainer, this.removeNoteContainer, this);
            this.parent.on(index_1.updateNoteContainer, this.updateNoteContainer, this);
            this.parent.on(index_1.showHideNote, this.showHideNote, this);
            this.parent.on(index_4.importModelUpdate, this.updateNotesFromSheet, this);
            this.parent.on(index_1.navigateNextPrevNote, this.navigateNextPrevNote, this);
            this.parent.on(index_1.showAllNotes, this.showAllNotes, this);
            this.parent.on(index_1.processSheetNotes, this.processSheetNotes, this);
            this.parent.on(index_1.noteUndoRedo, this.noteUndoRedo, this);
            this.parent.on(index_2.sheetsDestroyed, this.sheetDestroyHandler, this);
        };
        SpreadsheetNote.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_1.addNote, this.addNote);
                this.parent.off(index_1.editNote, this.editNote);
                this.parent.off(index_1.showNote, this.showNote);
                this.parent.off(index_1.deleteNote, this.deleteNote);
                this.parent.off(index_1.createNoteIndicator, this.createNoteIndicator);
                this.parent.off(index_1.removeNoteContainer, this.removeNoteContainer);
                this.parent.off(index_1.updateNoteContainer, this.updateNoteContainer);
                this.parent.off(index_1.showHideNote, this.showHideNote);
                this.parent.off(index_4.importModelUpdate, this.updateNotesFromSheet);
                this.parent.off(index_1.navigateNextPrevNote, this.navigateNextPrevNote);
                this.parent.off(index_1.showAllNotes, this.showAllNotes);
                this.parent.off(index_1.processSheetNotes, this.processSheetNotes);
                this.parent.off(index_1.noteUndoRedo, this.noteUndoRedo);
                this.parent.off(index_2.sheetsDestroyed, this.sheetDestroyHandler);
            }
        };
        SpreadsheetNote.prototype.getModuleName = function () {
            return 'spreadsheetNote';
        };
        SpreadsheetNote.prototype.getNoteId = function (note) {
            return "e-note-container-" + note.id;
        };
        SpreadsheetNote.prototype.getNoteConnectorId = function (note) {
            return "e-note-connector-" + note.id;
        };
        SpreadsheetNote.prototype.getNoteByCellIndex = function (rowIndex, columnIndex) {
            var sheet = this.parent.getActiveSheet();
            if (sheet && sheet.notes) {
                return sheet.notes.find(function (note) { return note.rowIdx === rowIndex && note.colIdx === columnIndex; });
            }
            return undefined;
        };
        SpreadsheetNote.prototype.showHideNote = function () {
            var sheet = this.parent.getActiveSheet();
            var idx = index_2.getCellIndexes(sheet.activeCell);
            var note = this.getNoteByCellIndex(idx[0], idx[1]);
            if (note) {
                note.isVisible = !note.isVisible;
                index_3.updateCell(this.parent, sheet, { rowIdx: note.rowIdx, colIdx: note.colIdx, preventEvt: true,
                    cell: { notes: note } });
                if (note.isVisible) {
                    this.parent.notify(index_1.showNote, { rowIndex: idx[0], columnIndex: idx[1], isNoteEditable: false, isScrollWithNote: true });
                }
                else {
                    this.removeNoteElement(note);
                }
            }
        };
        SpreadsheetNote.prototype.addNote = function () {
            var sheet = this.parent.getActiveSheet();
            var cellIndexes = index_2.getCellIndexes(this.parent.getActiveSheet().activeCell);
            var targetElement = this.parent.getCell(cellIndexes[0], cellIndexes[1]);
            if (!ej2_base_1.isNullOrUndefined(targetElement) && ((targetElement.children.length === 0) || (targetElement.children.length > 0 && targetElement.children[targetElement.childElementCount - 1].className.indexOf('e-addNoteIndicator') === -1))) {
                var note = { id: ej2_base_1.getUniqueID('e_note'), rowIdx: cellIndexes[0], colIdx: cellIndexes[1], text: '', isVisible: this.isShowAllNotes };
                if (!sheet.notes) {
                    sheet.notes = [];
                }
                this.activeNoteCell = [cellIndexes[0], cellIndexes[1]];
                index_3.updateCell(this.parent, sheet, { rowIdx: cellIndexes[0], colIdx: cellIndexes[1], preventEvt: true, cell: { isNoteEditable: true } });
                this.parent.setUsedRange(cellIndexes[0], cellIndexes[1], sheet);
                this.insertNoteSorted(sheet, note);
                this.createNoteIndicator({ targetElement: targetElement, rowIndex: cellIndexes[0], columnIndex: cellIndexes[1] });
                this.createNoteContainer(note, targetElement, false, true, false, sheet.name + "!" + sheet.activeCell);
            }
        };
        SpreadsheetNote.prototype.deleteNote = function (args) {
            var sheet = this.parent.getActiveSheet();
            var cellIndexes = index_2.getCellIndexes(this.parent.getActiveSheet().activeCell);
            var rowIndex = !ej2_base_1.isNullOrUndefined(args) && !ej2_base_1.isNullOrUndefined(args.rowIndex) ? args.rowIndex : cellIndexes[0];
            var columnIndex = !ej2_base_1.isNullOrUndefined(args) && !ej2_base_1.isNullOrUndefined(args.columnIndex) ? args.columnIndex : cellIndexes[1];
            var targetElement = this.parent.getCell(rowIndex, columnIndex);
            Eif (targetElement.children.length > 0 && targetElement.children[targetElement.children.length - 1].className.indexOf('e-addNoteIndicator') > -1) {
                targetElement.removeChild(targetElement.children[targetElement.children.length - 1]);
                ej2_base_1.EventHandler.remove(targetElement, 'mouseover', this.mouseOver);
                ej2_base_1.EventHandler.remove(targetElement, 'mouseout', this.mouseOut);
                var address = index_3.getSheetName(this.parent, this.parent.activeSheetIndex) + '!' + this.parent.getActiveSheet().activeCell;
                var note = this.getNoteByCellIndex(rowIndex, columnIndex);
                if (!ej2_base_1.isNullOrUndefined(args) && args.isDeleteFromMenu) {
                    this.parent.notify(index_1.setActionData, { args: { action: 'beforeCellSave', eventArgs: { address: address } } });
                }
                if (note) {
                    this.removeNoteElement(note);
                }
                this.syncNoteToSheetArray(sheet, rowIndex, columnIndex, null);
                var cell = index_3.getCell(rowIndex, columnIndex, sheet);
                if (cell && cell.notes) {
                    delete cell.notes;
                    index_3.updateCell(this.parent, sheet, { rowIdx: rowIndex, colIdx: columnIndex, preventEvt: true, cell: cell });
                }
                Iif (this.activeNoteCell && this.activeNoteCell[0] === rowIndex && this.activeNoteCell[1] === columnIndex) {
                    this.activeNoteCell = null;
                }
                if (!ej2_base_1.isNullOrUndefined(args) && args.isDeleteFromMenu) {
                    var eventArgs = { notes: note, address: address };
                    this.parent.notify(index_1.completeAction, { eventArgs: eventArgs, action: 'deleteNote' });
                }
            }
        };
        SpreadsheetNote.prototype.editNote = function () {
            var cellIndexes = !ej2_base_1.isNullOrUndefined(this.activeNoteCell) ?
                this.activeNoteCell : index_2.getCellIndexes(this.parent.getActiveSheet().activeCell);
            var note = this.getNoteByCellIndex(cellIndexes[0], cellIndexes[1]);
            Eif (note) {
                this.showNote({ rowIndex: cellIndexes[0], columnIndex: cellIndexes[1], isNoteEditable: true });
                var noteContainerElement = document.getElementById(this.getNoteId(note));
                index_3.updateCell(this.parent, this.parent.getActiveSheet(), { rowIdx: cellIndexes[0], colIdx: cellIndexes[1], preventEvt: true,
                    cell: { isNoteEditable: true } });
                Eif (noteContainerElement) {
                    this.getNoteFocus(noteContainerElement);
                }
            }
        };
        SpreadsheetNote.prototype.createNoteIndicator = function (args) {
            var triangleDirection = this.parent.enableRtl
                ? 'left: 0; border-right: 8px solid transparent;' : 'right: 0; border-left: 8px solid transparent;';
            var noteIndicator = this.parent.createElement('div', { className: 'e-addNoteIndicator',
                styles: "position: absolute; top: 0; width: 0; height: 0; border-top: 8px solid red; cursor: pointer; " + triangleDirection });
            if (args.targetElement.children.length > 0) {
                var rowHeight = index_3.getRowHeight(this.parent.getActiveSheet(), args.rowIndex);
                var defaultFilterButtonHeight = 20;
                for (var i = 0; i < args.targetElement.childElementCount; i++) {
                    if (args.targetElement.children[i].className.indexOf('e-filter-btn') > -1) {
                        if (this.parent.enableRtl) {
                            noteIndicator.style.left = (rowHeight < (defaultFilterButtonHeight + 10) ?
                                (args.targetElement.children[i].getBoundingClientRect().width <= 0 ? defaultFilterButtonHeight :
                                    args.targetElement.children[i].getBoundingClientRect().width) : 0 + 2) + 'px';
                        }
                        else {
                            noteIndicator.style.right = (rowHeight < (defaultFilterButtonHeight + 10) ?
                                (args.targetElement.children[i].getBoundingClientRect().width <= 0 ? defaultFilterButtonHeight :
                                    args.targetElement.children[i].getBoundingClientRect().width) : 0 + 2) + 'px';
                        }
                    }
                    if (args.targetElement.children[i].className.indexOf('e-validation-list') > -1) {
                        if (this.parent.enableRtl) {
                            noteIndicator.style.left = (args.targetElement.children[i].getBoundingClientRect().width || 20) + 2 + "px";
                        }
                        else {
                            noteIndicator.style.right = (args.targetElement.children[i].getBoundingClientRect().width || 20) + 2 + "px";
                        }
                    }
                }
            }
            if (!ej2_base_1.isNullOrUndefined(args.targetElement) && (args.targetElement.children.length === 0) || (args.targetElement.children.length > 0 && args.targetElement.children[args.targetElement.childElementCount - 1].className.indexOf('e-addNoteIndicator') === -1)) {
                if (args.cell && typeof args.cell.notes === 'string') {
                    var note = { id: ej2_base_1.getUniqueID('e_note'), rowIdx: args.rowIndex, colIdx: args.columnIndex,
                        text: args.cell.notes, isVisible: this.isShowAllNotes };
                    args.cell.notes = note;
                    var sheet = this.parent.getActiveSheet();
                    index_3.updateCell(this.parent, sheet, { rowIdx: args.rowIndex, colIdx: args.columnIndex, preventEvt: true, cell: { notes: note } });
                    this.syncNoteToSheetArray(sheet, note.rowIdx, note.colIdx, note);
                }
                if (!args.skipEvent) {
                    ej2_base_1.EventHandler.add(args.targetElement, 'mouseover', this.mouseOver, [this, args.rowIndex, args.columnIndex]);
                    ej2_base_1.EventHandler.add(args.targetElement, 'mouseout', this.mouseOut, this);
                }
                args.targetElement.appendChild(noteIndicator);
            }
        };
        SpreadsheetNote.prototype.mouseOver = function () {
            var args = this;
            var noteModule = args[0];
            var rowIndex = args[1];
            var columnIndex = args[2];
            var note = noteModule.getNoteByCellIndex(rowIndex, columnIndex);
            if (!note || note.isVisible) {
                return;
            }
            var sheet = noteModule.parent.getActiveSheet();
            Eif (sheet.notes) {
                var isOtherNoteEditState_1;
                sheet.notes.forEach(function (note) {
                    if ((note.rowIdx !== rowIndex || note.colIdx !== columnIndex)) {
                        var cell = note.rowIdx !== undefined && index_3.getCell(note.rowIdx, note.colIdx, sheet, false, true);
                        if (cell && cell.isNoteEditable) {
                            isOtherNoteEditState_1 = true;
                        }
                        else Eif (!note.isVisible) {
                            noteModule.removeNoteElement(note);
                        }
                    }
                });
                if (isOtherNoteEditState_1) {
                    return;
                }
            }
            noteModule.activeNoteCell = [rowIndex, columnIndex];
            if (!note || !noteModule.isNoteElementVisible(note)) {
                noteModule.showNote({ rowIndex: rowIndex, columnIndex: columnIndex, isNoteEditable: false });
            }
        };
        SpreadsheetNote.prototype.mouseOut = function (e) {
            var args = this;
            var noteModule = args[0] ? args[0] : this.parent.spreadsheetNoteModule;
            var rowIndex = !ej2_base_1.isNullOrUndefined(args[1]) ? args[1] : (this.activeNoteCell ? this.activeNoteCell[0] : undefined);
            var columnIndex = !ej2_base_1.isNullOrUndefined(args[2]) ? args[2] : (this.activeNoteCell ? this.activeNoteCell[1] : undefined);
            var note = noteModule.getNoteByCellIndex(rowIndex, columnIndex);
            if (!note || note.isVisible) {
                return;
            }
            var relatedTarget = e.relatedTarget;
            var noteId = noteModule.getNoteId(note);
            var noteContainer = noteId && document.getElementById(noteId);
            var noteConnectorId = noteModule.getNoteConnectorId(note);
            var noteConnector = noteConnectorId && document.getElementById(noteConnectorId);
            Eif (noteContainer) {
                if (!(document.activeElement.className.indexOf('e-addNoteContainer') > -1 ||
                    (relatedTarget && ((relatedTarget === noteContainer) || (relatedTarget === noteConnector))))) {
                    noteModule.removeNoteElement(note);
                    this.activeNoteCell = null;
                }
            }
        };
        SpreadsheetNote.prototype.isNoteElementVisible = function (note) {
            var noteContainer = document.getElementById(this.getNoteId(note));
            return noteContainer && noteContainer.style.display !== 'none';
        };
        SpreadsheetNote.prototype.containerFocusIn = function (e) {
            e.target.style.zIndex = '6';
        };
        SpreadsheetNote.prototype.containerFocusOut = function (e) {
            e.target.style.zIndex = '5';
        };
        SpreadsheetNote.prototype.createNoteContainer = function (note, targetElement, isShowNote, isNoteEditable, isRender, address) {
            var cellRect = targetElement.getBoundingClientRect();
            var noteId = this.getNoteId(note);
            var connectorId = this.getNoteConnectorId(note);
            var noteContainer = document.getElementById(noteId);
            var connectorLine = document.getElementById(connectorId);
            if (noteContainer && connectorLine) {
                this.updateExistingNoteDisplay(noteContainer, connectorLine, note, cellRect, isShowNote, isNoteEditable, isRender);
            }
            else {
                noteContainer = this.parent.createElement('textarea', { id: noteId, className: 'e-addNoteContainer', attrs: { 'aria-label': 'Note' } });
                connectorLine = this.parent.createElement('canvas', { id: connectorId, className: 'e-connectorLine' });
                this.createContainer(noteContainer, note, cellRect, isShowNote, isRender);
                this.createConnectorLine(connectorLine, noteContainer, cellRect);
                if (address) {
                    var eventArgs = { notes: note, noteContainer: noteContainer, address: address };
                    this.parent.notify(index_1.completeAction, { eventArgs: eventArgs, action: 'addNoteOpen' });
                }
                if (isNoteEditable) {
                    this.getNoteFocus(noteContainer);
                }
                ej2_base_1.EventHandler.add(noteContainer, 'focus', this.containerFocusIn, this);
                ej2_base_1.EventHandler.add(noteContainer, 'blur', this.containerFocusOut, this);
                ej2_base_1.EventHandler.add(noteContainer, 'mouseout', this.mouseOut, [this, note.rowIdx, note.colIdx]);
                ej2_base_1.EventHandler.add(connectorLine, 'mouseout', this.mouseOut, [this, note.rowIdx, note.colIdx]);
            }
            ej2_base_1.EventHandler.remove(targetElement, 'mouseout', this.mouseOut);
            ej2_base_1.EventHandler.add(targetElement, 'mouseout', this.mouseOut, [this, note.rowIdx, note.colIdx]);
        };
        SpreadsheetNote.prototype.updateExistingNoteDisplay = function (noteContainer, connectorLine, note, cellRect, isShowNote, isNoteEditable, isRender) {
            this.createContainer(noteContainer, note, cellRect, isShowNote, isRender);
            this.createConnectorLine(connectorLine, noteContainer, cellRect);
            if (isShowNote && (!noteContainer.value || noteContainer.value !== note.text)) {
                noteContainer.value = note.text || '';
            }
            if (isNoteEditable) {
                this.getNoteFocus(noteContainer);
            }
        };
        SpreadsheetNote.prototype.getNoteFocus = function (noteContainerElement) {
            noteContainerElement.selectionStart = noteContainerElement.value.length;
            noteContainerElement.focus();
        };
        SpreadsheetNote.prototype.createContainer = function (noteContainer, note, cellRect, isShowNote, isRender) {
            var containerTop = 5;
            var selectAllCell = this.parent.element.getElementsByClassName('e-select-all-cell')[0];
            var scroller = this.parent.element.getElementsByClassName('e-scroller')[0];
            if (!ej2_base_1.isNullOrUndefined(selectAllCell) && !ej2_base_1.isNullOrUndefined(scroller) &&
                cellRect.top >= selectAllCell.getBoundingClientRect().bottom &&
                cellRect.top <= scroller.getBoundingClientRect().top) {
                var isViewableArea = this.parent.enableRtl ?
                    cellRect.left <= selectAllCell.getBoundingClientRect().left &&
                        cellRect.left >= scroller.getBoundingClientRect().left :
                    cellRect.right >= selectAllCell.getBoundingClientRect().right &&
                        cellRect.right <= scroller.getBoundingClientRect().right;
                Eif (isViewableArea) {
                    noteContainer.style.display = 'block';
                    containerTop = cellRect.top === selectAllCell.getBoundingClientRect().bottom ? 0 : containerTop;
                }
                else {
                    noteContainer.style.display = 'none';
                }
            }
            else {
                noteContainer.style.display = 'none';
            }
            var elementClientRect = this.parent.element.getBoundingClientRect();
            var elementPosition = this.parent.element.style.getPropertyValue('position');
            noteContainer.style.position = 'absolute';
            noteContainer.style.top = (cellRect.top - (elementClientRect.top - (elementPosition === 'absolute' ? 0 :
                this.parent.element.offsetTop)) - containerTop) + 'px';
            var leftPos;
            var noteWidth = 120;
            var offsetLeft = (elementPosition === 'absolute' ? 0 : this.parent.element.offsetLeft);
            if (this.parent.enableRtl) {
                leftPos = cellRect.left - (elementClientRect.left - offsetLeft) - noteWidth - 10;
            }
            else {
                leftPos = cellRect.left + cellRect.width - (elementClientRect.left - offsetLeft) + 10;
            }
            noteContainer.style.left = leftPos + "px";
            noteContainer.style.width = noteContainer.style.width || noteWidth + "px";
            noteContainer.style.height = noteContainer.style.height || '120px';
            noteContainer.style.zIndex = '5';
            noteContainer.style.color = 'black';
            noteContainer.style.backgroundColor = 'lightyellow';
            if (isShowNote && !ej2_base_1.isNullOrUndefined(note) && !ej2_base_1.isNullOrUndefined(note.text)) {
                noteContainer.innerHTML = note.text;
            }
            else {
                noteContainer.innerHTML = this.parent.author ? this.parent.author + ':\n' : '';
            }
            var isActiveNote = isRender && document.activeElement === noteContainer;
            this.parent.element.appendChild(noteContainer);
            Iif (isActiveNote) {
                this.getNoteFocus(noteContainer);
            }
        };
        SpreadsheetNote.prototype.createConnectorLine = function (connectorLine, noteContainer, cellRect) {
            var lineWidth = 100;
            connectorLine.style.width = lineWidth + "px";
            connectorLine.style.position = 'absolute';
            connectorLine.style.zIndex = '1';
            var context = connectorLine.getContext('2d');
            var elementClientRect = this.parent.element.getBoundingClientRect();
            var elementPosition = this.parent.element.style.getPropertyValue('position');
            var offsetLeft = (elementPosition === 'absolute' ? 0 : this.parent.element.offsetLeft);
            if (this.parent.enableRtl) {
                connectorLine.style.left = cellRect.left - (elementClientRect.left - offsetLeft) - lineWidth + 'px';
                connectorLine.style.transform = 'scaleX(-1)';
            }
            else {
                connectorLine.style.left = cellRect.left + cellRect.width - (elementClientRect.left - offsetLeft) + 'px';
            }
            connectorLine.style.top = (noteContainer.getBoundingClientRect().top - (elementClientRect.top - (elementPosition === 'absolute' ?
                0 : this.parent.element.offsetTop)) - 5) + 'px';
            context.clearRect(0, 0, connectorLine.width, connectorLine.height);
            context.beginPath();
            if (noteContainer.getBoundingClientRect().top === cellRect.top) {
                context.moveTo(0, 16);
                context.lineTo(30, 15);
            }
            else {
                context.moveTo(0, 30);
                context.lineTo(30, 15);
            }
            context.strokeStyle = 'black';
            context.lineWidth = 5;
            context.stroke();
            this.parent.element.appendChild(connectorLine);
            if (noteContainer.getBoundingClientRect().top > 0) {
                connectorLine.style.display = 'block';
                connectorLine.style.zIndex = '4';
            }
            else {
                connectorLine.style.display = 'none';
            }
        };
        SpreadsheetNote.prototype.showNote = function (args) {
            var note = this.getNoteByCellIndex(args.rowIndex, args.columnIndex);
            if (note) {
                var targetElement = !ej2_base_1.isNullOrUndefined(this.parent.getCell(args.rowIndex, args.columnIndex)) ?
                    this.parent.getCell(args.rowIndex, args.columnIndex) : args.cellElement;
                Eif (!ej2_base_1.isNullOrUndefined(targetElement)
                    && (args.isScrollWithNote || (targetElement.children !== null && targetElement.children.length > 0 &&
                        targetElement.children[targetElement.children.length - 1].classList.contains('e-addNoteIndicator')))) {
                    this.activeNoteCell = [args.rowIndex, args.columnIndex];
                    this.createNoteContainer(note, targetElement, true, args.isNoteEditable, args.isRender);
                }
            }
        };
        SpreadsheetNote.prototype.removeNoteContainer = function (args) {
            var _this = this;
            var sheet = this.parent.getActiveSheet();
            if (args && !ej2_base_1.isNullOrUndefined(args.rowIndex) && !ej2_base_1.isNullOrUndefined(args.columnIndex)) {
                var cell = index_3.getCell(args.rowIndex, args.columnIndex, sheet, false, true);
                var note = cell.notes;
                if (note) {
                    this.removeNoteElement(note);
                }
            }
            else if (ej2_base_1.isNullOrUndefined(args)) {
                if (sheet.notes) {
                    sheet.notes.forEach(function (note) {
                        if (!note.isVisible) {
                            _this.removeNoteElement(note);
                        }
                    });
                }
            }
        };
        SpreadsheetNote.prototype.removeNoteElement = function (note) {
            var noteContainer = document.getElementById(this.getNoteId(note));
            var connectorLine = document.getElementById(this.getNoteConnectorId(note));
            if (noteContainer) {
                ej2_base_1.EventHandler.remove(noteContainer, 'mouseout', this.mouseOut);
                ej2_base_1.EventHandler.remove(noteContainer, 'focus', this.containerFocusIn);
                ej2_base_1.EventHandler.remove(noteContainer, 'blur', this.containerFocusOut);
                if (this.parent.element.contains(noteContainer)) {
                    this.parent.element.removeChild(noteContainer);
                }
            }
            if (connectorLine) {
                ej2_base_1.EventHandler.remove(connectorLine, 'mouseout', this.mouseOut);
                if (this.parent.element.contains(connectorLine)) {
                    this.parent.element.removeChild(connectorLine);
                }
            }
            var targetElement = this.parent.getCell(note.rowIdx, note.colIdx);
            if (targetElement) {
                ej2_base_1.EventHandler.remove(targetElement, 'mouseout', this.mouseOut);
            }
            if (this.activeNoteCell && this.activeNoteCell[0] === note.rowIdx && this.activeNoteCell[1] === note.colIdx) {
                this.activeNoteCell = null;
            }
            var cell = note.rowIdx !== undefined && index_3.getCell(note.rowIdx, note.colIdx, this.parent.getActiveSheet(), false, true);
            if (cell && cell.notes && cell.isNoteEditable) {
                cell.isNoteEditable = false;
            }
        };
        SpreadsheetNote.prototype.updateNoteContainer = function () {
            var _this = this;
            var sheet = this.parent.getActiveSheet();
            this.removeNoteElementsFromOtherSheets();
            if (!sheet.notes || sheet.notes.length === 0) {
                if (this.parent.selectionModule) {
                    this.parent.selectionModule.isNoteActiveElement = false;
                }
                if (this.activeNoteCell) {
                    this.activeNoteCell = null;
                }
                return;
            }
            this.parent.selectionModule.isNoteActiveElement = false;
            var activeNoteFound = false;
            sheet.notes.forEach(function (note) {
                var noteContainer = document.getElementById(_this.getNoteId(note));
                var hasFocus = noteContainer ? (document.activeElement === noteContainer ||
                    (note.rowIdx !== undefined && index_3.getCell(note.rowIdx, note.colIdx, sheet, false, true).isNoteEditable)) : false;
                if (hasFocus) {
                    activeNoteFound = true;
                    _this.parent.selectionModule.isNoteActiveElement = true;
                    _this.activeNoteCell = [note.rowIdx, note.colIdx];
                    if ((ej2_base_1.isNullOrUndefined(note.text) && noteContainer.value) || note.text !== noteContainer.value) {
                        var address = index_3.getSheetName(_this.parent, _this.parent.activeSheetIndex) + '!' + index_2.getRangeAddress([note.rowIdx, note.colIdx]);
                        _this.parent.notify(index_1.setActionData, { args: { action: 'beforeCellSave', eventArgs: { address: address } } });
                        var eventAction = note.text ? 'editNote' : 'addNote';
                        note.text = noteContainer.value;
                        index_3.updateCell(_this.parent, sheet, { rowIdx: note.rowIdx, colIdx: note.colIdx, preventEvt: true,
                            cell: { notes: note, isNoteEditable: true } });
                        _this.syncNoteToSheetArray(sheet, note.rowIdx, note.colIdx, note);
                        var eventArgs = { notes: note, address: address };
                        _this.parent.notify(index_1.completeAction, { eventArgs: eventArgs, action: eventAction });
                    }
                }
                if (note.isVisible || hasFocus) {
                    _this.parent.notify(index_1.showNote, { rowIndex: note.rowIdx, columnIndex: note.colIdx, isNoteEditable: hasFocus,
                        isScrollWithNote: true });
                }
                else {
                    _this.removeNoteElement(note);
                }
            });
            if (!activeNoteFound) {
                this.activeNoteCell = null;
            }
        };
        SpreadsheetNote.prototype.sheetDestroyHandler = function (args) {
            var _this = this;
            var noteContainers = [].slice.call(this.parent.element.getElementsByClassName('e-addNoteContainer'));
            noteContainers.forEach(function (noteContainer) {
                ej2_base_1.EventHandler.remove(noteContainer, 'mouseout', _this.mouseOut);
                ej2_base_1.EventHandler.remove(noteContainer, 'focus', _this.containerFocusIn);
                ej2_base_1.EventHandler.remove(noteContainer, 'blur', _this.containerFocusOut);
                noteContainer.parentElement.removeChild(noteContainer);
            });
            var connectorLines = [].slice.call(this.parent.element.getElementsByClassName('e-connectorLine'));
            connectorLines.forEach(function (connectorLine) {
                ej2_base_1.EventHandler.remove(connectorLine, 'mouseout', _this.mouseOut);
                connectorLine.parentElement.removeChild(connectorLine);
            });
            if (ej2_base_1.isNullOrUndefined(args.sheetIndex)) {
                this.isShowAllNotes = false;
            }
            this.activeNoteCell = null;
        };
        SpreadsheetNote.prototype.removeNoteElementsFromOtherSheets = function () {
            var _this = this;
            var activeSheetIndex = this.parent.activeSheetIndex;
            this.parent.sheets.forEach(function (sheet, index) {
                if (index === activeSheetIndex) {
                    return;
                }
                if (sheet.notes) {
                    sheet.notes.forEach(function (note) {
                        _this.removeNoteElement(note);
                    });
                }
            });
        };
        SpreadsheetNote.prototype.insertNoteSorted = function (sheet, note) {
            if (!sheet.notes) {
                sheet.notes = [];
            }
            var idx = index_2.getSortedIndex(sheet.notes, [note.rowIdx, note.colIdx], false);
            sheet.notes.splice(idx, 0, note);
        };
        SpreadsheetNote.prototype.navigateNextPrevNote = function (args) {
            var sheetCount = this.parent.sheets.length;
            var startSheetIdx = this.parent.activeSheetIndex;
            var activeSheet = this.parent.getActiveSheet();
            var addr = index_2.getCellIndexes(activeSheet.activeCell);
            var currentColl = activeSheet.notes ? activeSheet.notes : [];
            if (currentColl.length > 0) {
                var pos = index_2.getSortedIndex(currentColl, addr, false);
                var exactIdx = -1;
                if (pos < currentColl.length) {
                    var note = currentColl[pos];
                    if (note.rowIdx === addr[0] && note.colIdx === addr[1]) {
                        exactIdx = pos;
                    }
                }
                if (exactIdx === -1 && pos > 0) {
                    var prevNote = currentColl[pos - 1];
                    Iif (prevNote.rowIdx === addr[0] && prevNote.colIdx === addr[1]) {
                        exactIdx = pos - 1;
                    }
                }
                var idx = args.isNext ? (exactIdx > -1 ? exactIdx + 1 : pos) : (exactIdx > -1 ? exactIdx - 1 : pos - 1);
                if (idx >= 0 && idx < currentColl.length) {
                    this.navigateToNote(currentColl[idx], startSheetIdx);
                    return;
                }
            }
            for (var i = 1; i < sheetCount; i++) {
                var sheetIdx = (startSheetIdx + (args.isNext ? i : -i) + sheetCount) % sheetCount;
                var sheet = this.parent.sheets[sheetIdx];
                if (sheet.notes && sheet.notes.length > 0) {
                    var note = args.isNext ? sheet.notes[0] : sheet.notes[sheet.notes.length - 1];
                    this.navigateToNote(note, sheetIdx);
                    return;
                }
            }
            Eif (currentColl.length > 0) {
                var note = args.isNext ? currentColl[0] : currentColl[currentColl.length - 1];
                if (note.rowIdx !== addr[0] || note.colIdx !== addr[1]) {
                    this.navigateToNote(note, startSheetIdx);
                }
            }
        };
        SpreadsheetNote.prototype.navigateToNote = function (note, sheetIndex) {
            var _this = this;
            var sheetName = index_3.getSheetName(this.parent, sheetIndex);
            var address = index_2.getRangeAddress([note.rowIdx, note.colIdx]);
            this.parent.goTo(sheetName + "!" + address);
            setTimeout(function () {
                _this.activeNoteCell = [note.rowIdx, note.colIdx];
                _this.parent.notify(index_1.editNote, null);
            });
        };
        SpreadsheetNote.prototype.showAllNotes = function () {
            var _this = this;
            this.isShowAllNotes = !this.isShowAllNotes;
            this.parent.sheets.forEach(function (sheet) {
                if (sheet.notes) {
                    sheet.notes.forEach(function (note) {
                        note.isVisible = _this.isShowAllNotes;
                        index_3.updateCell(_this.parent, sheet, { rowIdx: note.rowIdx, colIdx: note.colIdx, preventEvt: true,
                            cell: { notes: __assign({}, note, { isVisible: _this.isShowAllNotes }) } });
                    });
                }
            });
            var activeSheet = this.parent.getActiveSheet();
            if (activeSheet && activeSheet.notes) {
                activeSheet.notes.forEach(function (note) {
                    if (_this.isShowAllNotes) {
                        _this.parent.notify(index_1.showNote, { rowIndex: note.rowIdx, columnIndex: note.colIdx, isNoteEditable: false,
                            isScrollWithNote: true });
                    }
                    else {
                        _this.removeNoteElement(note);
                    }
                });
            }
        };
        SpreadsheetNote.prototype.updateNotesFromSheet = function () {
            var cell;
            this.parent.sheets.forEach(function (sheet) {
                if (sheet.notes && sheet.notes.length > 0) {
                    sheet.notes.forEach(function (note) {
                        if (note.address) {
                            note.rowIdx = note.address[0];
                            note.colIdx = note.address[1];
                            delete note.address;
                            note.id = ej2_base_1.getUniqueID('e_note');
                            cell = index_3.getCell(note.rowIdx, note.colIdx, sheet);
                            if (cell) {
                                cell.notes = note;
                            }
                            else {
                                index_4.setCell(note.rowIdx, note.colIdx, sheet, { notes: note });
                            }
                        }
                    });
                }
            });
        };
        SpreadsheetNote.prototype.processSheetNotes = function (args) {
            var sheet = args.sheet;
            if (!sheet.notes) {
                sheet.notes = [];
            }
            if (args.isDelete) {
                if (args.id) {
                    var noteIndex = sheet.notes.findIndex(function (n) { return n.id === args.id; });
                    if (noteIndex > -1) {
                        var noteToRemove = sheet.notes[noteIndex];
                        this.removeNoteElement(noteToRemove);
                        sheet.notes.splice(noteIndex, 1);
                    }
                }
            }
            else if (args.note) {
                var note = args.note;
                if (!note.id) {
                    note.id = ej2_base_1.getUniqueID('e_note');
                }
                if (ej2_base_1.isNullOrUndefined(note.isVisible)) {
                    note.isVisible = false;
                }
                this.syncNoteToSheetArray(sheet, note.rowIdx, note.colIdx, note);
                if (args.isRefresh && !ej2_base_1.isNullOrUndefined(args.sheetIdx) && args.sheetIdx === this.parent.activeSheetIndex) {
                    var targetElement = this.parent.getCell(note.rowIdx, note.colIdx);
                    if (targetElement) {
                        if (!targetElement.querySelector('.e-addNoteIndicator')) {
                            this.createNoteIndicator({
                                targetElement: targetElement, rowIndex: note.rowIdx,
                                columnIndex: note.colIdx, skipEvent: false
                            });
                        }
                        if (note.isVisible) {
                            this.showNote({
                                rowIndex: note.rowIdx, columnIndex: note.colIdx, isNoteEditable: false,
                                isScrollWithNote: true, cellElement: targetElement
                            });
                        }
                    }
                }
            }
        };
        SpreadsheetNote.prototype.syncNoteToSheetArray = function (sheet, rowIdx, colIdx, note) {
            Iif (!sheet.notes) {
                sheet.notes = [];
            }
            var existingIdx = sheet.notes.findIndex(function (n) { return n.rowIdx === rowIdx && n.colIdx === colIdx; });
            if (note) {
                if (existingIdx > -1) {
                    sheet.notes[existingIdx] = note;
                }
                else {
                    this.insertNoteSorted(sheet, note);
                }
            }
            else {
                if (existingIdx > -1) {
                    sheet.notes.splice(existingIdx, 1);
                }
            }
        };
        SpreadsheetNote.prototype.detachNoteIndicator = function (rowIdx, colIdx) {
            var cellElement = this.parent.getCell(rowIdx, colIdx);
            if (cellElement) {
                var indicator = cellElement.querySelector('.e-addNoteIndicator');
                if (indicator) {
                    ej2_base_1.EventHandler.remove(indicator, 'mouseover', this.mouseOver);
                    ej2_base_1.EventHandler.remove(indicator, 'mouseout', this.mouseOut);
                    delete indicator.dataset.commentListenersAdded;
                    delete indicator.dataset.commentRowIndex;
                    delete indicator.dataset.commentColIndex;
                    ej2_base_1.detach(indicator);
                }
            }
        };
        SpreadsheetNote.prototype.noteUndoRedo = function (args) {
            if (args && args.cellIdx && !ej2_base_1.isNullOrUndefined(args.sheetIdx)) {
                var sheet = this.parent.sheets[args.sheetIdx];
                var row_1 = args.cellIdx[0];
                var col_1 = args.cellIdx[1];
                if (!sheet.notes) {
                    sheet.notes = [];
                }
                var cell = index_3.getCell(row_1, col_1, sheet);
                var model = cell && cell.notes;
                var existing_1 = sheet.notes.find(function (n) { return n.rowIdx === row_1 && n.colIdx === col_1; });
                if (model) {
                    if (existing_1) {
                        var idxInColl = sheet.notes.findIndex(function (n) { return n.id === existing_1.id; });
                        Eif (idxInColl > -1) {
                            if (model.id !== existing_1.id) {
                                model.id = existing_1.id;
                            }
                            sheet.notes[idxInColl] = model;
                        }
                    }
                    else {
                        this.insertNoteSorted(sheet, model);
                    }
                    if (this.parent.activeSheetIndex === args.sheetIdx) {
                        var td = this.parent.getCell(row_1, col_1);
                        if (td && !td.querySelector('.e-addNoteIndicator')) {
                            this.createNoteIndicator({ targetElement: td, rowIndex: row_1, columnIndex: col_1 });
                        }
                        if (model.isVisible) {
                            this.parent.notify(index_1.showNote, { rowIndex: row_1, columnIndex: col_1, isNoteEditable: false, isScrollWithNote: true });
                        }
                    }
                }
                else Eif (existing_1) {
                    var i = sheet.notes.findIndex(function (n) { return n.id === existing_1.id; });
                    Eif (i > -1) {
                        sheet.notes.splice(i, 1);
                    }
                    if (this.parent.activeSheetIndex === args.sheetIdx) {
                        this.detachNoteIndicator(row_1, col_1);
                        var cellToUpdate = index_3.getCell(row_1, col_1, sheet);
                        Eif (cellToUpdate) {
                            delete cellToUpdate.notes;
                            index_3.updateCell(this.parent, sheet, { rowIdx: row_1, colIdx: col_1, preventEvt: true, cell: cellToUpdate });
                        }
                        var noteContainer = document.getElementById(this.getNoteId(existing_1));
                        if (noteContainer) {
                            this.removeNoteElement(existing_1);
                        }
                    }
                }
            }
        };
        return SpreadsheetNote;
    }());
    exports.SpreadsheetNote = SpreadsheetNote;
});