# all files / src/js/base/module/ Editor.js

73.29% Statements 321/438
46.6% Branches 89/191
67.42% Functions 60/89
73.23% Lines 320/437

    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
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    8391×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×
    2×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×

    97×

    97×
    1261×
    1261×
    15×
    15×
    15×

    1261×

    97×

    97×
    1×

    97×
    582×
    582×

    582×

    97×
    2×

    97×
    2×

    97×
    2×

    97×
    3×

    97×
    3×

    97×
    4×
    1×

    3×
    3×
    3×
    3×

    97×
    7×
    1×

    6×
    6×
    6×
    6×

    97×
    3×
    1×

    2×
    2×
    2×
    2×

    97×
    5×
    5×

    5×

    97×
    1×
    1×
    1×
    1×

    97×

    97×
    7×
    7×
    7×
    7×
    7×
    7×
    2×

    5×

    5×
    5×

    5×

    5×

    5×
    5×
    5×
    5×
    5×

    5×
    5×
    5×
    2×

    3×

    5×
    5×
    5×
    5×
    5×
    5×

    97×
    1×
    1×
    1×
    1×

    1×
    1×

    97×
    2×
    2×

    97×
    1×
    1×
    1×

    97×

    97×

    97×

    1×
    97×

    97×
    1×

    1×
    1×
    1×
    1×

    1×

    1×
    1×

    32×
    32×

    1×

    1×

    1×
    1×

    1×

    97×

    97×
    97×
    16×

    97×
    21×

    3×

    97×
    97×

    97×

    97×

    97×

    97×
    97×

    1×
    2×

    1×
    1×
    1×
    1×

    1×

    1×

    1×
    1×

    1×
    1×

    1×

    1×

    1×
    23×
    23×
    1×

    23×
    5×
    5×

    18×

    1×
    2×
    2×
    2×

    1×
    154×

    1×
    21×

    21×

    1×
    2×

    1×

    1×

    1×
    75×

    1×

    1×
    262×
    262×
    44×

    262×

    1×

    1×
    1×
    1×
    1×

    1×

    1×
    1×
    1×
    1×

    1×
    61×

    61×

    1×
    61×
    61×
    61×
    46×

    1×
    1×
    1×

    1×

    1×
    1×
    1×
    1×

    1×

    1×
    1940×
    44×
    44×
    44×

    1×
    1×
    1×
    1×
    1×

    1×
    1×

    1×

    1×
    1×
    1×
    1×
    1×

    1×

    1×

    1×

    1×

    5×

    5×

    2×
    1×

    2×
    2×
    2×
    2×
    2×
    2×

    1×

    1×
    1×
    1×
    1×
    1×

    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×

    1×
    2×

    2×
    2×

    2×

    2×

    2×

    1×

    1×

    1×

    1×

    1×

    1×

    1×
    131×

    1×

    65×
    65×

    1×
    1×

    1×
    1×

    1×
    61×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/Editor.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var env_1 = require("../core/env");
    var key_1 = require("../core/key");
    var func_1 = require("../core/func");
    var lists_1 = require("../core/lists");
    var dom_1 = require("../core/dom");
    var range_1 = require("../core/range");
    var async_1 = require("../core/async");
    var History_1 = require("../editing/History");
    var Style_1 = require("../editing/Style");
    var Typing_1 = require("../editing/Typing");
    var Table_1 = require("../editing/Table");
    var Bullet_1 = require("../editing/Bullet");
    var KEY_BOGUS = 'bogus';
    /**
     * @class Editor
     */
    var Editor = /** @class */ (function () {
        function Editor(context) {
            var _this = this;
            this.context = context;
            this.$note = context.layoutInfo.note;
            this.$editor = context.layoutInfo.editor;
            this.$editable = context.layoutInfo.editable;
            this.options = context.options;
            this.lang = this.options.langInfo;
            this.editable = this.$editable[0];
            this.lastRange = null;
            this.style = new Style_1["default"]();
            this.table = new Table_1["default"]();
            this.typing = new Typing_1["default"](context);
            this.bullet = new Bullet_1["default"]();
            this.history = new History_1["default"](this.$editable);
            this.context.memo('help.undo', this.lang.help.undo);
            this.context.memo('help.redo', this.lang.help.redo);
            this.context.memo('help.tab', this.lang.help.tab);
            this.context.memo('help.untab', this.lang.help.untab);
            this.context.memo('help.insertParagraph', this.lang.help.insertParagraph);
            this.context.memo('help.insertOrderedList', this.lang.help.insertOrderedList);
            this.context.memo('help.insertUnorderedList', this.lang.help.insertUnorderedList);
            this.context.memo('help.indent', this.lang.help.indent);
            this.context.memo('help.outdent', this.lang.help.outdent);
            this.context.memo('help.formatPara', this.lang.help.formatPara);
            this.context.memo('help.insertHorizontalRule', this.lang.help.insertHorizontalRule);
            this.context.memo('help.fontName', this.lang.help.fontName);
            // native commands(with execCommand), generate function for execCommand
            var commands = [
                'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript',
                'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull',
                'formatBlock', 'removeFormat', 'backColor',
            ];
            for (var idx = 0, len = commands.length; idx < len; idx++) {
                this[commands[idx]] = (function (sCmd) {
                    return function (value) {
                        _this.beforeCommand();
                        document.execCommand(sCmd, false, value);
                        _this.afterCommand(true);
                    };
                })(commands[idx]);
                this.context.memo('help.' + commands[idx], this.lang.help[commands[idx]]);
            }
            this.fontName = this.wrapCommand(function (value) {
                return _this.fontStyling('font-family', "\'" + value + "\'");
            });
            this.fontSize = this.wrapCommand(function (value) {
                return _this.fontStyling('font-size', value + 'px');
            });
            for (var idx = 1; idx <= 6; idx++) {
                this['formatH' + idx] = (function (idx) {
                    return function () {
                        _this.formatBlock('H' + idx);
                    };
                })(idx);
                this.context.memo('help.formatH' + idx, this.lang.help['formatH' + idx]);
            }
            ;
            this.insertParagraph = this.wrapCommand(function () {
                _this.typing.insertParagraph(_this.editable);
            });
            this.insertOrderedList = this.wrapCommand(function () {
                _this.bullet.insertOrderedList(_this.editable);
            });
            this.insertUnorderedList = this.wrapCommand(function () {
                _this.bullet.insertUnorderedList(_this.editable);
            });
            this.indent = this.wrapCommand(function () {
                _this.bullet.indent(_this.editable);
            });
            this.outdent = this.wrapCommand(function () {
                _this.bullet.outdent(_this.editable);
            });
            /**
             * insertNode
             * insert node
             * @param {Node} node
             */
            this.insertNode = this.wrapCommand(function (node) {
                if (_this.isLimited(jquery_1["default"](node).text().length)) {
                    return;
                }
                var rng = _this.getLastRange();
                rng.insertNode(node);
                range_1["default"].createFromNodeAfter(node).select();
                _this.setLastRange();
            });
            /**
             * insert text
             * @param {String} text
             */
            this.insertText = this.wrapCommand(function (text) {
                if (_this.isLimited(text.length)) {
                    return;
                }
                var rng = _this.getLastRange();
                var textNode = rng.insertNode(dom_1["default"].createText(text));
                range_1["default"].create(textNode, dom_1["default"].nodeLength(textNode)).select();
                _this.setLastRange();
            });
            /**
             * paste HTML
             * @param {String} markup
             */
            this.pasteHTML = this.wrapCommand(function (markup) {
                if (_this.isLimited(markup.length)) {
                    return;
                }
                markup = _this.context.invoke('codeview.purify', markup);
                var contents = _this.getLastRange().pasteHTML(markup);
                range_1["default"].createFromNodeAfter(lists_1["default"].last(contents)).select();
                _this.setLastRange();
            });
            /**
             * formatBlock
             *
             * @param {String} tagName
             */
            this.formatBlock = this.wrapCommand(function (tagName, $target) {
                var onApplyCustomStyle = _this.options.callbacks.onApplyCustomStyle;
                Iif (onApplyCustomStyle) {
                    onApplyCustomStyle.call(_this, $target, _this.context, _this.onFormatBlock);
                }
                else {
                    _this.onFormatBlock(tagName, $target);
                }
            });
            /**
             * insert horizontal rule
             */
            this.insertHorizontalRule = this.wrapCommand(function () {
                var hrNode = _this.getLastRange().insertNode(dom_1["default"].create('HR'));
                Eif (hrNode.nextSibling) {
                    range_1["default"].create(hrNode.nextSibling, 0).normalize().select();
                    _this.setLastRange();
                }
            });
            /**
             * lineHeight
             * @param {String} value
             */
            this.lineHeight = this.wrapCommand(function (value) {
                _this.style.stylePara(_this.getLastRange(), {
                    lineHeight: value
                });
            });
            /**
             * create link (command)
             *
             * @param {Object} linkInfo
             */
            this.createLink = this.wrapCommand(function (linkInfo) {
                var linkUrl = linkInfo.url;
                var linkText = linkInfo.text;
                var isNewWindow = linkInfo.isNewWindow;
                var rng = linkInfo.range || _this.getLastRange();
                var additionalTextLength = linkText.length - rng.toString().length;
                if (additionalTextLength > 0 && _this.isLimited(additionalTextLength)) {
                    return;
                }
                var isTextChanged = rng.toString() !== linkText;
                // handle spaced urls from input
                Eif (typeof linkUrl === 'string') {
                    linkUrl = linkUrl.trim();
                }
                Iif (_this.options.onCreateLink) {
                    linkUrl = _this.options.onCreateLink(linkUrl);
                }
                else {
                    // if url doesn't have any protocol and not even a relative or a label, use http:// as default
                    linkUrl = /^([A-Za-z][A-Za-z0-9+-.]*\:|#|\/)/.test(linkUrl)
                        ? linkUrl : 'http://' + linkUrl;
                }
                var anchors = [];
                Eif (isTextChanged) {
                    rng = rng.deleteContents();
                    var anchor = rng.insertNode(jquery_1["default"]('<A>' + linkText + '</A>')[0]);
                    anchors.push(anchor);
                }
                else {
                    anchors = _this.style.styleNodes(rng, {
                        nodeName: 'A',
                        expandClosestSibling: true,
                        onlyPartialContains: true
                    });
                }
                jquery_1["default"].each(anchors, function (idx, anchor) {
                    jquery_1["default"](anchor).attr('href', linkUrl);
                    if (isNewWindow) {
                        jquery_1["default"](anchor).attr('target', '_blank');
                    }
                    else {
                        jquery_1["default"](anchor).removeAttr('target');
                    }
                });
                var startRange = range_1["default"].createFromNodeBefore(lists_1["default"].head(anchors));
                var startPoint = startRange.getStartPoint();
                var endRange = range_1["default"].createFromNodeAfter(lists_1["default"].last(anchors));
                var endPoint = endRange.getEndPoint();
                range_1["default"].create(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset).select();
                _this.setLastRange();
            });
            /**
             * setting color
             *
             * @param {Object} sObjColor  color code
             * @param {String} sObjColor.foreColor foreground color
             * @param {String} sObjColor.backColor background color
             */
            this.color = this.wrapCommand(function (colorInfo) {
                var foreColor = colorInfo.foreColor;
                var backColor = colorInfo.backColor;
                Eif (foreColor) {
                    document.execCommand('foreColor', false, foreColor);
                }
                Eif (backColor) {
                    document.execCommand('backColor', false, backColor);
                }
            });
            /**
             * Set foreground color
             *
             * @param {String} colorCode foreground color code
             */
            this.foreColor = this.wrapCommand(function (colorInfo) {
                document.execCommand('styleWithCSS', false, true);
                document.execCommand('foreColor', false, colorInfo);
            });
            /**
             * insert Table
             *
             * @param {String} dimension of table (ex : "5x5")
             */
            this.insertTable = this.wrapCommand(function (dim) {
                var dimension = dim.split('x');
                var rng = _this.getLastRange().deleteContents();
                rng.insertNode(_this.table.createTable(dimension[0], dimension[1], _this.options));
            });
            /**
             * remove media object and Figure Elements if media object is img with Figure.
             */
            this.removeMedia = this.wrapCommand(function () {
                var $target = jquery_1["default"](_this.restoreTarget()).parent();
                if ($target.parent('figure').length) {
                    $target.parent('figure').remove();
                }
                else {
                    $target = jquery_1["default"](_this.restoreTarget()).detach();
                }
                _this.context.triggerEvent('media.delete', $target, _this.$editable);
            });
            /**
             * float me
             *
             * @param {String} value
             */
            this.floatMe = this.wrapCommand(function (value) {
                var $target = jquery_1["default"](_this.restoreTarget());
                $target.toggleClass('note-float-left', value === 'left');
                $target.toggleClass('note-float-right', value === 'right');
                $target.css('float', (value === 'none' ? '' : value));
            });
            /**
             * resize overlay element
             * @param {String} value
             */
            this.resize = this.wrapCommand(function (value) {
                var $target = jquery_1["default"](_this.restoreTarget());
                value = parseFloat(value);
                if (value === 0) {
                    $target.css('width', '');
                }
                else {
                    $target.css({
                        width: value * 100 + '%',
                        height: ''
                    });
                }
            });
        }
        Editor.prototype.initialize = function () {
            var _this = this;
            // bind custom events
            this.$editable.on('keydown', function (event) {
                Iif (event.keyCode === key_1["default"].code.ENTER) {
                    _this.context.triggerEvent('enter', event);
                }
                _this.context.triggerEvent('keydown', event);
                Eif (!event.isDefaultPrevented()) {
                    Eif (_this.options.shortcuts) {
                        _this.handleKeyMap(event);
                    }
                    else {
                        _this.preventDefaultEditableShortCuts(event);
                    }
                }
                Iif (_this.isLimited(1, event)) {
                    return false;
                }
            }).on('keyup', function (event) {
                _this.setLastRange();
                _this.context.triggerEvent('keyup', event);
            }).on('focus', function (event) {
                _this.setLastRange();
                _this.context.triggerEvent('focus', event);
            }).on('blur', function (event) {
                _this.context.triggerEvent('blur', event);
            }).on('mousedown', function (event) {
                _this.context.triggerEvent('mousedown', event);
            }).on('mouseup', function (event) {
                _this.setLastRange();
                _this.context.triggerEvent('mouseup', event);
            }).on('scroll', function (event) {
                _this.context.triggerEvent('scroll', event);
            }).on('paste', function (event) {
                _this.setLastRange();
                _this.context.triggerEvent('paste', event);
            });
            this.$editable.attr('spellcheck', this.options.spellCheck);
            // init content before set event
            this.$editable.html(dom_1["default"].html(this.$note) || dom_1["default"].emptyPara);
            this.$editable.on(env_1["default"].inputEventName, func_1["default"].debounce(function () {
                _this.context.triggerEvent('change', _this.$editable.html(), _this.$editable);
            }, 10));
            this.$editor.on('focusin', function (event) {
                _this.context.triggerEvent('focusin', event);
            }).on('focusout', function (event) {
                _this.context.triggerEvent('focusout', event);
            });
            Eif (!this.options.airMode) {
                Iif (this.options.width) {
                    this.$editor.outerWidth(this.options.width);
                }
                Iif (this.options.height) {
                    this.$editable.outerHeight(this.options.height);
                }
                Iif (this.options.maxHeight) {
                    this.$editable.css('max-height', this.options.maxHeight);
                }
                Iif (this.options.minHeight) {
                    this.$editable.css('min-height', this.options.minHeight);
                }
            }
            this.history.recordUndo();
            this.setLastRange();
        };
        Editor.prototype.destroy = function () {
            this.$editable.off();
        };
        Editor.prototype.handleKeyMap = function (event) {
            var keyMap = this.options.keyMap[env_1["default"].isMac ? 'mac' : 'pc'];
            var keys = [];
            Iif (event.metaKey) {
                keys.push('CMD');
            }
            Iif (event.ctrlKey && !event.altKey) {
                keys.push('CTRL');
            }
            Iif (event.shiftKey) {
                keys.push('SHIFT');
            }
            var keyName = key_1["default"].nameFromCode[event.keyCode];
            Iif (keyName) {
                keys.push(keyName);
            }
            var eventName = keyMap[keys.join('+')];
            Iif (eventName) {
                if (this.context.invoke(eventName) !== false) {
                    event.preventDefault();
                }
            }
            else Iif (key_1["default"].isEdit(event.keyCode)) {
                this.afterCommand();
            }
        };
        Editor.prototype.preventDefaultEditableShortCuts = function (event) {
            // B(Bold, 66) / I(Italic, 73) / U(Underline, 85)
            if ((event.ctrlKey || event.metaKey) &&
                lists_1["default"].contains([66, 73, 85], event.keyCode)) {
                event.preventDefault();
            }
        };
        Editor.prototype.isLimited = function (pad, event) {
            pad = pad || 0;
            if (typeof event !== 'undefined') {
                Iif (key_1["default"].isMove(event.keyCode) ||
                    (event.ctrlKey || event.metaKey) ||
                    lists_1["default"].contains([key_1["default"].code.BACKSPACE, key_1["default"].code.DELETE], event.keyCode)) {
                    return false;
                }
            }
            if (this.options.maxTextLength > 0) {
                Eif ((this.$editable.text().length + pad) >= this.options.maxTextLength) {
                    return true;
                }
            }
            return false;
        };
        /**
         * create range
         * @return {WrappedRange}
         */
        Editor.prototype.createRange = function () {
            this.focus();
            this.setLastRange();
            return this.getLastRange();
        };
        Editor.prototype.setLastRange = function () {
            this.lastRange = range_1["default"].create(this.editable);
        };
        Editor.prototype.getLastRange = function () {
            Iif (!this.lastRange) {
                this.setLastRange();
            }
            return this.lastRange;
        };
        /**
         * saveRange
         *
         * save current range
         *
         * @param {Boolean} [thenCollapse=false]
         */
        Editor.prototype.saveRange = function (thenCollapse) {
            Iif (thenCollapse) {
                this.getLastRange().collapse().select();
            }
        };
        /**
         * restoreRange
         *
         * restore lately range
         */
        Editor.prototype.restoreRange = function () {
            if (this.lastRange) {
                this.lastRange.select();
                this.focus();
            }
        };
        Editor.prototype.saveTarget = function (node) {
            this.$editable.data('target', node);
        };
        Editor.prototype.clearTarget = function () {
            this.$editable.removeData('target');
        };
        Editor.prototype.restoreTarget = function () {
            return this.$editable.data('target');
        };
        /**
         * currentStyle
         *
         * current style
         * @return {Object|Boolean} unfocus
         */
        Editor.prototype.currentStyle = function () {
            var rng = range_1["default"].create();
            if (rng) {
                rng = rng.normalize();
            }
            return rng ? this.style.current(rng) : this.style.fromNode(this.$editable);
        };
        /**
         * style from node
         *
         * @param {jQuery} $node
         * @return {Object}
         */
        Editor.prototype.styleFromNode = function ($node) {
            return this.style.fromNode($node);
        };
        /**
         * undo
         */
        Editor.prototype.undo = function () {
            this.context.triggerEvent('before.command', this.$editable.html());
            this.history.undo();
            this.context.triggerEvent('change', this.$editable.html(), this.$editable);
        };
        /*
        * commit
        */
        Editor.prototype.commit = function () {
            this.context.triggerEvent('before.command', this.$editable.html());
            this.history.commit();
            this.context.triggerEvent('change', this.$editable.html(), this.$editable);
        };
        /**
         * redo
         */
        Editor.prototype.redo = function () {
            this.context.triggerEvent('before.command', this.$editable.html());
            this.history.redo();
            this.context.triggerEvent('change', this.$editable.html(), this.$editable);
        };
        /**
         * before command
         */
        Editor.prototype.beforeCommand = function () {
            this.context.triggerEvent('before.command', this.$editable.html());
            // keep focus on editable before command execution
            this.focus();
        };
        /**
         * after command
         * @param {Boolean} isPreventTrigger
         */
        Editor.prototype.afterCommand = function (isPreventTrigger) {
            this.normalizeContent();
            this.history.recordUndo();
            if (!isPreventTrigger) {
                this.context.triggerEvent('change', this.$editable.html(), this.$editable);
            }
        };
        /**
         * handle tab key
         */
        Editor.prototype.tab = function () {
            var rng = this.getLastRange();
            Iif (rng.isCollapsed() && rng.isOnCell()) {
                this.table.tab(rng);
            }
            else {
                Iif (this.options.tabSize === 0) {
                    return false;
                }
                Eif (!this.isLimited(this.options.tabSize)) {
                    this.beforeCommand();
                    this.typing.insertTab(rng, this.options.tabSize);
                    this.afterCommand();
                }
            }
        };
        /**
         * handle shift+tab key
         */
        Editor.prototype.untab = function () {
            var rng = this.getLastRange();
            if (rng.isCollapsed() && rng.isOnCell()) {
                this.table.tab(rng, true);
            }
            else {
                if (this.options.tabSize === 0) {
                    return false;
                }
            }
        };
        /**
         * run given function between beforeCommand and afterCommand
         */
        Editor.prototype.wrapCommand = function (fn) {
            return function () {
                this.beforeCommand();
                fn.apply(this, arguments);
                this.afterCommand();
            };
        };
        /**
         * insert image
         *
         * @param {String} src
         * @param {String|Function} param
         * @return {Promise}
         */
        Editor.prototype.insertImage = function (src, param) {
            var _this = this;
            return async_1.createImage(src, param).then(function ($image) {
                _this.beforeCommand();
                Iif (typeof param === 'function') {
                    param($image);
                }
                else {
                    Eif (typeof param === 'string') {
                        $image.attr('data-filename', param);
                    }
                    $image.css('width', Math.min(_this.$editable.width(), $image.width()));
                }
                $image.show();
                range_1["default"].create(_this.editable).insertNode($image[0]);
                range_1["default"].createFromNodeAfter($image[0]).select();
                _this.setLastRange();
                _this.afterCommand();
            }).fail(function (e) {
                _this.context.triggerEvent('image.upload.error', e);
            });
        };
        /**
         * insertImages
         * @param {File[]} files
         */
        Editor.prototype.insertImagesAsDataURL = function (files) {
            var _this = this;
            jquery_1["default"].each(files, function (idx, file) {
                var filename = file.name;
                if (_this.options.maximumImageFileSize && _this.options.maximumImageFileSize < file.size) {
                    _this.context.triggerEvent('image.upload.error', _this.lang.image.maximumFileSizeError);
                }
                else {
                    async_1.readFileAsDataURL(file).then(function (dataURL) {
                        return _this.insertImage(dataURL, filename);
                    }).fail(function () {
                        _this.context.triggerEvent('image.upload.error');
                    });
                }
            });
        };
        /**
         * insertImagesOrCallback
         * @param {File[]} files
         */
        Editor.prototype.insertImagesOrCallback = function (files) {
            var callbacks = this.options.callbacks;
            // If onImageUpload set,
            if (callbacks.onImageUpload) {
                this.context.triggerEvent('image.upload', files);
                // else insert Image as dataURL
            }
            else {
                this.insertImagesAsDataURL(files);
            }
        };
        /**
         * return selected plain text
         * @return {String} text
         */
        Editor.prototype.getSelectedText = function () {
            var rng = this.getLastRange();
            // if range on anchor, expand range with anchor
            if (rng.isOnAnchor()) {
                rng = range_1["default"].createFromNode(dom_1["default"].ancestor(rng.sc, dom_1["default"].isAnchor));
            }
            return rng.toString();
        };
        Editor.prototype.onFormatBlock = function (tagName, $target) {
            // [workaround] for MSIE, IE need `<`
            document.execCommand('FormatBlock', false, env_1["default"].isMSIE ? '<' + tagName + '>' : tagName);
            // support custom class
            if ($target && $target.length) {
                // find the exact element has given tagName
                if ($target[0].tagName.toUpperCase() !== tagName.toUpperCase()) {
                    $target = $target.find(tagName);
                }
                Eif ($target && $target.length) {
                    var className = $target[0].className || '';
                    Eif (className) {
                        var currentRange = this.createRange();
                        var $parent = jquery_1["default"]([currentRange.sc, currentRange.ec]).closest(tagName);
                        $parent.addClass(className);
                    }
                }
            }
        };
        Editor.prototype.formatPara = function () {
            this.formatBlock('P');
        };
        Editor.prototype.fontStyling = function (target, value) {
            var rng = this.getLastRange();
            Eif (rng) {
                var spans = this.style.styleNodes(rng);
                jquery_1["default"](spans).css(target, value);
                // [workaround] added styled bogus span for style
                //  - also bogus character needed for cursor position
                Eif (rng.isCollapsed()) {
                    var firstSpan = lists_1["default"].head(spans);
                    Eif (firstSpan && !dom_1["default"].nodeLength(firstSpan)) {
                        firstSpan.innerHTML = dom_1["default"].ZERO_WIDTH_NBSP_CHAR;
                        range_1["default"].createFromNodeAfter(firstSpan.firstChild).select();
                        this.setLastRange();
                        this.$editable.data(KEY_BOGUS, firstSpan);
                    }
                }
            }
        };
        /**
         * unlink
         *
         * @type command
         */
        Editor.prototype.unlink = function () {
            var rng = this.getLastRange();
            if (rng.isOnAnchor()) {
                var anchor = dom_1["default"].ancestor(rng.sc, dom_1["default"].isAnchor);
                rng = range_1["default"].createFromNode(anchor);
                rng.select();
                this.setLastRange();
                this.beforeCommand();
                document.execCommand('unlink');
                this.afterCommand();
            }
        };
        /**
         * returns link info
         *
         * @return {Object}
         * @return {WrappedRange} return.range
         * @return {String} return.text
         * @return {Boolean} [return.isNewWindow=true]
         * @return {String} [return.url=""]
         */
        Editor.prototype.getLinkInfo = function () {
            var rng = this.getLastRange().expand(dom_1["default"].isAnchor);
            // Get the first anchor on range(for edit).
            var $anchor = jquery_1["default"](lists_1["default"].head(rng.nodes(dom_1["default"].isAnchor)));
            var linkInfo = {
                range: rng,
                text: rng.toString(),
                url: $anchor.length ? $anchor.attr('href') : ''
            };
            // When anchor exists,
            Eif ($anchor.length) {
                // Set isNewWindow by checking its target.
                linkInfo.isNewWindow = $anchor.attr('target') === '_blank';
            }
            return linkInfo;
        };
        Editor.prototype.addRow = function (position) {
            var rng = this.getLastRange(this.$editable);
            if (rng.isCollapsed() && rng.isOnCell()) {
                this.beforeCommand();
                this.table.addRow(rng, position);
                this.afterCommand();
            }
        };
        Editor.prototype.addCol = function (position) {
            var rng = this.getLastRange(this.$editable);
            if (rng.isCollapsed() && rng.isOnCell()) {
                this.beforeCommand();
                this.table.addCol(rng, position);
                this.afterCommand();
            }
        };
        Editor.prototype.deleteRow = function () {
            var rng = this.getLastRange(this.$editable);
            if (rng.isCollapsed() && rng.isOnCell()) {
                this.beforeCommand();
                this.table.deleteRow(rng);
                this.afterCommand();
            }
        };
        Editor.prototype.deleteCol = function () {
            var rng = this.getLastRange(this.$editable);
            if (rng.isCollapsed() && rng.isOnCell()) {
                this.beforeCommand();
                this.table.deleteCol(rng);
                this.afterCommand();
            }
        };
        Editor.prototype.deleteTable = function () {
            var rng = this.getLastRange(this.$editable);
            if (rng.isCollapsed() && rng.isOnCell()) {
                this.beforeCommand();
                this.table.deleteTable(rng);
                this.afterCommand();
            }
        };
        /**
         * @param {Position} pos
         * @param {jQuery} $target - target element
         * @param {Boolean} [bKeepRatio] - keep ratio
         */
        Editor.prototype.resizeTo = function (pos, $target, bKeepRatio) {
            var imageSize;
            if (bKeepRatio) {
                var newRatio = pos.y / pos.x;
                var ratio = $target.data('ratio');
                imageSize = {
                    width: ratio > newRatio ? pos.x : pos.y / ratio,
                    height: ratio > newRatio ? pos.x * ratio : pos.y
                };
            }
            else {
                imageSize = {
                    width: pos.x,
                    height: pos.y
                };
            }
            $target.css(imageSize);
        };
        /**
         * returns whether editable area has focus or not.
         */
        Editor.prototype.hasFocus = function () {
            return this.$editable.is(':focus');
        };
        /**
         * set focus
         */
        Editor.prototype.focus = function () {
            // [workaround] Screen will move when page is scolled in IE.
            //  - do focus when not focused
            Eif (!this.hasFocus()) {
                this.$editable.focus();
            }
        };
        /**
         * returns whether contents is empty or not.
         * @return {Boolean}
         */
        Editor.prototype.isEmpty = function () {
            return dom_1["default"].isEmpty(this.$editable[0]) || dom_1["default"].emptyPara === this.$editable.html();
        };
        /**
         * Removes all contents and restores the editable instance to an _emptyPara_.
         */
        Editor.prototype.empty = function () {
            this.context.invoke('code', dom_1["default"].emptyPara);
        };
        /**
         * normalize content
         */
        Editor.prototype.normalizeContent = function () {
            this.$editable[0].normalize();
        };
        return Editor;
    }());
    exports["default"] = Editor;

    },'src/js/base/module/Editor.js',{"jquery":"/Users/lqez/Dev/summernote/node_modules/jquery/dist/jquery.js","../core/env":"/Users/lqez/Dev/summernote/src/js/base/core/env.js","../core/key":"/Users/lqez/Dev/summernote/src/js/base/core/key.js","../core/func":"/Users/lqez/Dev/summernote/src/js/base/core/func.js","../core/lists":"/Users/lqez/Dev/summernote/src/js/base/core/lists.js","../core/dom":"/Users/lqez/Dev/summernote/src/js/base/core/dom.js","../core/range":"/Users/lqez/Dev/summernote/src/js/base/core/range.js","../core/async":"/Users/lqez/Dev/summernote/src/js/base/core/async.js","../editing/History":"/Users/lqez/Dev/summernote/src/js/base/editing/History.js","../editing/Style":"/Users/lqez/Dev/summernote/src/js/base/editing/Style.js","../editing/Typing":"/Users/lqez/Dev/summernote/src/js/base/editing/Typing.js","../editing/Table":"/Users/lqez/Dev/summernote/src/js/base/editing/Table.js","../editing/Bullet":"/Users/lqez/Dev/summernote/src/js/base/editing/Bullet.js"}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,