GPQAPP

Форк
0
/
summernote-lite.js 
10783 строки · 337.5 Кб
1
/*!
2
 * 
3
 * Super simple WYSIWYG editor v0.8.20
4
 * https://summernote.org
5
 *
6
 *
7
 * Copyright 2013- Alan Hong and contributors
8
 * Summernote may be freely distributed under the MIT license.
9
 *
10
 * Date: 2021-10-14T21:15Z
11
 *
12
 */
13
(function webpackUniversalModuleDefinition(root, factory) {
14
	if(typeof exports === 'object' && typeof module === 'object')
15
		module.exports = factory(require("jQuery"));
16
	else if(typeof define === 'function' && define.amd)
17
		define(["jQuery"], factory);
18
	else {
19
		var a = typeof exports === 'object' ? factory(require("jQuery")) : factory(root["jQuery"]);
20
		for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
21
	}
22
})(self, function(__WEBPACK_EXTERNAL_MODULE__1145__) {
23
return /******/ (() => { // webpackBootstrap
24
/******/ 	"use strict";
25
/******/ 	var __webpack_modules__ = ({
26

27
/***/ 9770:
28
/***/ ((__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) => {
29

30
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1145);
31
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
32

33
(jquery__WEBPACK_IMPORTED_MODULE_0___default().summernote) = (jquery__WEBPACK_IMPORTED_MODULE_0___default().summernote) || {
34
  lang: {}
35
};
36
jquery__WEBPACK_IMPORTED_MODULE_0___default().extend((jquery__WEBPACK_IMPORTED_MODULE_0___default().summernote.lang), {
37
  'en-US': {
38
    font: {
39
      bold: 'Bold',
40
      italic: 'Italic',
41
      underline: 'Underline',
42
      clear: 'Remove Font Style',
43
      height: 'Line Height',
44
      name: 'Font Family',
45
      strikethrough: 'Strikethrough',
46
      subscript: 'Subscript',
47
      superscript: 'Superscript',
48
      size: 'Font Size',
49
      sizeunit: 'Font Size Unit'
50
    },
51
    image: {
52
      image: 'Picture',
53
      insert: 'Insert Image',
54
      resizeFull: 'Resize full',
55
      resizeHalf: 'Resize half',
56
      resizeQuarter: 'Resize quarter',
57
      resizeNone: 'Original size',
58
      floatLeft: 'Float Left',
59
      floatRight: 'Float Right',
60
      floatNone: 'Remove float',
61
      shapeRounded: 'Shape: Rounded',
62
      shapeCircle: 'Shape: Circle',
63
      shapeThumbnail: 'Shape: Thumbnail',
64
      shapeNone: 'Shape: None',
65
      dragImageHere: 'Drag image or text here',
66
      dropImage: 'Drop image or Text',
67
      selectFromFiles: 'Select from files',
68
      maximumFileSize: 'Maximum file size',
69
      maximumFileSizeError: 'Maximum file size exceeded.',
70
      url: 'Image URL',
71
      remove: 'Remove Image',
72
      original: 'Original'
73
    },
74
    video: {
75
      video: 'Video',
76
      videoLink: 'Video Link',
77
      insert: 'Insert Video',
78
      url: 'Video URL',
79
      providers: '(YouTube, Google Drive, Vimeo, Vine, Instagram, DailyMotion, Youku, Peertube)'
80
    },
81
    link: {
82
      link: 'Link',
83
      insert: 'Insert Link',
84
      unlink: 'Unlink',
85
      edit: 'Edit',
86
      textToDisplay: 'Text to display',
87
      url: 'To what URL should this link go?',
88
      openInNewWindow: 'Open in new window',
89
      useProtocol: 'Use default protocol'
90
    },
91
    table: {
92
      table: 'Table',
93
      addRowAbove: 'Add row above',
94
      addRowBelow: 'Add row below',
95
      addColLeft: 'Add column left',
96
      addColRight: 'Add column right',
97
      delRow: 'Delete row',
98
      delCol: 'Delete column',
99
      delTable: 'Delete table'
100
    },
101
    hr: {
102
      insert: 'Insert Horizontal Rule'
103
    },
104
    style: {
105
      style: 'Style',
106
      p: 'Normal',
107
      blockquote: 'Quote',
108
      pre: 'Code',
109
      h1: 'Header 1',
110
      h2: 'Header 2',
111
      h3: 'Header 3',
112
      h4: 'Header 4',
113
      h5: 'Header 5',
114
      h6: 'Header 6'
115
    },
116
    lists: {
117
      unordered: 'Unordered list',
118
      ordered: 'Ordered list'
119
    },
120
    options: {
121
      help: 'Help',
122
      fullscreen: 'Full Screen',
123
      codeview: 'Code View'
124
    },
125
    paragraph: {
126
      paragraph: 'Paragraph',
127
      outdent: 'Outdent',
128
      indent: 'Indent',
129
      left: 'Align left',
130
      center: 'Align center',
131
      right: 'Align right',
132
      justify: 'Justify full'
133
    },
134
    color: {
135
      recent: 'Recent Color',
136
      more: 'More Color',
137
      background: 'Background Color',
138
      foreground: 'Text Color',
139
      transparent: 'Transparent',
140
      setTransparent: 'Set transparent',
141
      reset: 'Reset',
142
      resetToDefault: 'Reset to default',
143
      cpSelect: 'Select'
144
    },
145
    shortcut: {
146
      shortcuts: 'Keyboard shortcuts',
147
      close: 'Close',
148
      textFormatting: 'Text formatting',
149
      action: 'Action',
150
      paragraphFormatting: 'Paragraph formatting',
151
      documentStyle: 'Document Style',
152
      extraKeys: 'Extra keys'
153
    },
154
    help: {
155
      'escape': 'Escape',
156
      'insertParagraph': 'Insert Paragraph',
157
      'undo': 'Undo the last command',
158
      'redo': 'Redo the last command',
159
      'tab': 'Tab',
160
      'untab': 'Untab',
161
      'bold': 'Set a bold style',
162
      'italic': 'Set a italic style',
163
      'underline': 'Set a underline style',
164
      'strikethrough': 'Set a strikethrough style',
165
      'removeFormat': 'Clean a style',
166
      'justifyLeft': 'Set left align',
167
      'justifyCenter': 'Set center align',
168
      'justifyRight': 'Set right align',
169
      'justifyFull': 'Set full align',
170
      'insertUnorderedList': 'Toggle unordered list',
171
      'insertOrderedList': 'Toggle ordered list',
172
      'outdent': 'Outdent on current paragraph',
173
      'indent': 'Indent on current paragraph',
174
      'formatPara': 'Change current block\'s format as a paragraph(P tag)',
175
      'formatH1': 'Change current block\'s format as H1',
176
      'formatH2': 'Change current block\'s format as H2',
177
      'formatH3': 'Change current block\'s format as H3',
178
      'formatH4': 'Change current block\'s format as H4',
179
      'formatH5': 'Change current block\'s format as H5',
180
      'formatH6': 'Change current block\'s format as H6',
181
      'insertHorizontalRule': 'Insert horizontal rule',
182
      'linkDialog.show': 'Show Link Dialog'
183
    },
184
    history: {
185
      undo: 'Undo',
186
      redo: 'Redo'
187
    },
188
    specialChar: {
189
      specialChar: 'SPECIAL CHARACTERS',
190
      select: 'Select Special characters'
191
    },
192
    output: {
193
      noSelection: 'No Selection Made!'
194
    }
195
  }
196
});
197

198
/***/ }),
199

200
/***/ 1145:
201
/***/ ((module) => {
202

203
module.exports = __WEBPACK_EXTERNAL_MODULE__1145__;
204

205
/***/ })
206

207
/******/ 	});
208
/************************************************************************/
209
/******/ 	// The module cache
210
/******/ 	var __webpack_module_cache__ = {};
211
/******/ 	
212
/******/ 	// The require function
213
/******/ 	function __webpack_require__(moduleId) {
214
/******/ 		// Check if module is in cache
215
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
216
/******/ 		if (cachedModule !== undefined) {
217
/******/ 			return cachedModule.exports;
218
/******/ 		}
219
/******/ 		// Create a new module (and put it into the cache)
220
/******/ 		var module = __webpack_module_cache__[moduleId] = {
221
/******/ 			// no module.id needed
222
/******/ 			// no module.loaded needed
223
/******/ 			exports: {}
224
/******/ 		};
225
/******/ 	
226
/******/ 		// Execute the module function
227
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
228
/******/ 	
229
/******/ 		// Return the exports of the module
230
/******/ 		return module.exports;
231
/******/ 	}
232
/******/ 	
233
/************************************************************************/
234
/******/ 	/* webpack/runtime/compat get default export */
235
/******/ 	(() => {
236
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
237
/******/ 		__webpack_require__.n = (module) => {
238
/******/ 			var getter = module && module.__esModule ?
239
/******/ 				() => (module['default']) :
240
/******/ 				() => (module);
241
/******/ 			__webpack_require__.d(getter, { a: getter });
242
/******/ 			return getter;
243
/******/ 		};
244
/******/ 	})();
245
/******/ 	
246
/******/ 	/* webpack/runtime/define property getters */
247
/******/ 	(() => {
248
/******/ 		// define getter functions for harmony exports
249
/******/ 		__webpack_require__.d = (exports, definition) => {
250
/******/ 			for(var key in definition) {
251
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
252
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
253
/******/ 				}
254
/******/ 			}
255
/******/ 		};
256
/******/ 	})();
257
/******/ 	
258
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
259
/******/ 	(() => {
260
/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
261
/******/ 	})();
262
/******/ 	
263
/******/ 	/* webpack/runtime/make namespace object */
264
/******/ 	(() => {
265
/******/ 		// define __esModule on exports
266
/******/ 		__webpack_require__.r = (exports) => {
267
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
268
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
269
/******/ 			}
270
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
271
/******/ 		};
272
/******/ 	})();
273
/******/ 	
274
/************************************************************************/
275
var __webpack_exports__ = {};
276
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
277
(() => {
278
// ESM COMPAT FLAG
279
__webpack_require__.r(__webpack_exports__);
280

281
// EXTERNAL MODULE: external "jQuery"
282
var external_jQuery_ = __webpack_require__(1145);
283
var external_jQuery_default = /*#__PURE__*/__webpack_require__.n(external_jQuery_);
284
// EXTERNAL MODULE: ./src/lang/summernote-en-US.js
285
var summernote_en_US = __webpack_require__(9770);
286
;// CONCATENATED MODULE: ./src/js/core/env.js
287

288
/**
289
 * returns whether font is installed or not.
290
 *
291
 * @param {String} fontName
292
 * @return {Boolean}
293
 */
294

295
var genericFontFamilies = ['sans-serif', 'serif', 'monospace', 'cursive', 'fantasy'];
296

297
function validFontName(fontName) {
298
  return external_jQuery_default().inArray(fontName.toLowerCase(), genericFontFamilies) === -1 ? "'".concat(fontName, "'") : fontName;
299
}
300

301
function isFontInstalled(fontName) {
302
  var testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS';
303
  var testText = 'mmmmmmmmmmwwwww';
304
  var testSize = '200px';
305
  var canvas = document.createElement('canvas');
306
  var context = canvas.getContext('2d');
307
  context.font = testSize + " '" + testFontName + "'";
308
  var originalWidth = context.measureText(testText).width;
309
  context.font = testSize + ' ' + validFontName(fontName) + ', "' + testFontName + '"';
310
  var width = context.measureText(testText).width;
311
  return originalWidth !== width;
312
}
313

314
var userAgent = navigator.userAgent;
315
var isMSIE = /MSIE|Trident/i.test(userAgent);
316
var browserVersion;
317

318
if (isMSIE) {
319
  var matches = /MSIE (\d+[.]\d+)/.exec(userAgent);
320

321
  if (matches) {
322
    browserVersion = parseFloat(matches[1]);
323
  }
324

325
  matches = /Trident\/.*rv:([0-9]{1,}[.0-9]{0,})/.exec(userAgent);
326

327
  if (matches) {
328
    browserVersion = parseFloat(matches[1]);
329
  }
330
}
331

332
var isEdge = /Edge\/\d+/.test(userAgent);
333
var isSupportTouch = 'ontouchstart' in window || navigator.MaxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; // [workaround] IE doesn't have input events for contentEditable
334
// - see: https://goo.gl/4bfIvA
335

336
var inputEventName = isMSIE ? 'DOMCharacterDataModified DOMSubtreeModified DOMNodeInserted' : 'input';
337
/**
338
 * @class core.env
339
 *
340
 * Object which check platform and agent
341
 *
342
 * @singleton
343
 * @alternateClassName env
344
 */
345

346
/* harmony default export */ const env = ({
347
  isMac: navigator.appVersion.indexOf('Mac') > -1,
348
  isMSIE: isMSIE,
349
  isEdge: isEdge,
350
  isFF: !isEdge && /firefox/i.test(userAgent),
351
  isPhantom: /PhantomJS/i.test(userAgent),
352
  isWebkit: !isEdge && /webkit/i.test(userAgent),
353
  isChrome: !isEdge && /chrome/i.test(userAgent),
354
  isSafari: !isEdge && /safari/i.test(userAgent) && !/chrome/i.test(userAgent),
355
  browserVersion: browserVersion,
356
  isSupportTouch: isSupportTouch,
357
  isFontInstalled: isFontInstalled,
358
  isW3CRangeSupport: !!document.createRange,
359
  inputEventName: inputEventName,
360
  genericFontFamilies: genericFontFamilies,
361
  validFontName: validFontName
362
});
363
;// CONCATENATED MODULE: ./src/js/core/func.js
364

365
/**
366
 * @class core.func
367
 *
368
 * func utils (for high-order func's arg)
369
 *
370
 * @singleton
371
 * @alternateClassName func
372
 */
373

374
function eq(itemA) {
375
  return function (itemB) {
376
    return itemA === itemB;
377
  };
378
}
379

380
function eq2(itemA, itemB) {
381
  return itemA === itemB;
382
}
383

384
function peq2(propName) {
385
  return function (itemA, itemB) {
386
    return itemA[propName] === itemB[propName];
387
  };
388
}
389

390
function ok() {
391
  return true;
392
}
393

394
function fail() {
395
  return false;
396
}
397

398
function not(f) {
399
  return function () {
400
    return !f.apply(f, arguments);
401
  };
402
}
403

404
function and(fA, fB) {
405
  return function (item) {
406
    return fA(item) && fB(item);
407
  };
408
}
409

410
function func_self(a) {
411
  return a;
412
}
413

414
function invoke(obj, method) {
415
  return function () {
416
    return obj[method].apply(obj, arguments);
417
  };
418
}
419

420
var idCounter = 0;
421
/**
422
 * reset globally-unique id
423
 *
424
 */
425

426
function resetUniqueId() {
427
  idCounter = 0;
428
}
429
/**
430
 * generate a globally-unique id
431
 *
432
 * @param {String} [prefix]
433
 */
434

435

436
function uniqueId(prefix) {
437
  var id = ++idCounter + '';
438
  return prefix ? prefix + id : id;
439
}
440
/**
441
 * returns bnd (bounds) from rect
442
 *
443
 * - IE Compatibility Issue: http://goo.gl/sRLOAo
444
 * - Scroll Issue: http://goo.gl/sNjUc
445
 *
446
 * @param {Rect} rect
447
 * @return {Object} bounds
448
 * @return {Number} bounds.top
449
 * @return {Number} bounds.left
450
 * @return {Number} bounds.width
451
 * @return {Number} bounds.height
452
 */
453

454

455
function rect2bnd(rect) {
456
  var $document = external_jQuery_default()(document);
457
  return {
458
    top: rect.top + $document.scrollTop(),
459
    left: rect.left + $document.scrollLeft(),
460
    width: rect.right - rect.left,
461
    height: rect.bottom - rect.top
462
  };
463
}
464
/**
465
 * returns a copy of the object where the keys have become the values and the values the keys.
466
 * @param {Object} obj
467
 * @return {Object}
468
 */
469

470

471
function invertObject(obj) {
472
  var inverted = {};
473

474
  for (var key in obj) {
475
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
476
      inverted[obj[key]] = key;
477
    }
478
  }
479

480
  return inverted;
481
}
482
/**
483
 * @param {String} namespace
484
 * @param {String} [prefix]
485
 * @return {String}
486
 */
487

488

489
function namespaceToCamel(namespace, prefix) {
490
  prefix = prefix || '';
491
  return prefix + namespace.split('.').map(function (name) {
492
    return name.substring(0, 1).toUpperCase() + name.substring(1);
493
  }).join('');
494
}
495
/**
496
 * Returns a function, that, as long as it continues to be invoked, will not
497
 * be triggered. The function will be called after it stops being called for
498
 * N milliseconds. If `immediate` is passed, trigger the function on the
499
 * leading edge, instead of the trailing.
500
 * @param {Function} func
501
 * @param {Number} wait
502
 * @param {Boolean} immediate
503
 * @return {Function}
504
 */
505

506

507
function debounce(func, wait, immediate) {
508
  var timeout;
509
  return function () {
510
    var context = this;
511
    var args = arguments;
512

513
    var later = function later() {
514
      timeout = null;
515

516
      if (!immediate) {
517
        func.apply(context, args);
518
      }
519
    };
520

521
    var callNow = immediate && !timeout;
522
    clearTimeout(timeout);
523
    timeout = setTimeout(later, wait);
524

525
    if (callNow) {
526
      func.apply(context, args);
527
    }
528
  };
529
}
530
/**
531
 *
532
 * @param {String} url
533
 * @return {Boolean}
534
 */
535

536

537
function isValidUrl(url) {
538
  var expression = /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi;
539
  return expression.test(url);
540
}
541

542
/* harmony default export */ const func = ({
543
  eq: eq,
544
  eq2: eq2,
545
  peq2: peq2,
546
  ok: ok,
547
  fail: fail,
548
  self: func_self,
549
  not: not,
550
  and: and,
551
  invoke: invoke,
552
  resetUniqueId: resetUniqueId,
553
  uniqueId: uniqueId,
554
  rect2bnd: rect2bnd,
555
  invertObject: invertObject,
556
  namespaceToCamel: namespaceToCamel,
557
  debounce: debounce,
558
  isValidUrl: isValidUrl
559
});
560
;// CONCATENATED MODULE: ./src/js/core/lists.js
561

562
/**
563
 * returns the first item of an array.
564
 *
565
 * @param {Array} array
566
 */
567

568
function head(array) {
569
  return array[0];
570
}
571
/**
572
 * returns the last item of an array.
573
 *
574
 * @param {Array} array
575
 */
576

577

578
function last(array) {
579
  return array[array.length - 1];
580
}
581
/**
582
 * returns everything but the last entry of the array.
583
 *
584
 * @param {Array} array
585
 */
586

587

588
function initial(array) {
589
  return array.slice(0, array.length - 1);
590
}
591
/**
592
 * returns the rest of the items in an array.
593
 *
594
 * @param {Array} array
595
 */
596

597

598
function tail(array) {
599
  return array.slice(1);
600
}
601
/**
602
 * returns item of array
603
 */
604

605

606
function find(array, pred) {
607
  for (var idx = 0, len = array.length; idx < len; idx++) {
608
    var item = array[idx];
609

610
    if (pred(item)) {
611
      return item;
612
    }
613
  }
614
}
615
/**
616
 * returns true if all of the values in the array pass the predicate truth test.
617
 */
618

619

620
function lists_all(array, pred) {
621
  for (var idx = 0, len = array.length; idx < len; idx++) {
622
    if (!pred(array[idx])) {
623
      return false;
624
    }
625
  }
626

627
  return true;
628
}
629
/**
630
 * returns true if the value is present in the list.
631
 */
632

633

634
function contains(array, item) {
635
  if (array && array.length && item) {
636
    if (array.indexOf) {
637
      return array.indexOf(item) !== -1;
638
    } else if (array.contains) {
639
      // `DOMTokenList` doesn't implement `.indexOf`, but it implements `.contains`
640
      return array.contains(item);
641
    }
642
  }
643

644
  return false;
645
}
646
/**
647
 * get sum from a list
648
 *
649
 * @param {Array} array - array
650
 * @param {Function} fn - iterator
651
 */
652

653

654
function sum(array, fn) {
655
  fn = fn || func.self;
656
  return array.reduce(function (memo, v) {
657
    return memo + fn(v);
658
  }, 0);
659
}
660
/**
661
 * returns a copy of the collection with array type.
662
 * @param {Collection} collection - collection eg) node.childNodes, ...
663
 */
664

665

666
function from(collection) {
667
  var result = [];
668
  var length = collection.length;
669
  var idx = -1;
670

671
  while (++idx < length) {
672
    result[idx] = collection[idx];
673
  }
674

675
  return result;
676
}
677
/**
678
 * returns whether list is empty or not
679
 */
680

681

682
function isEmpty(array) {
683
  return !array || !array.length;
684
}
685
/**
686
 * cluster elements by predicate function.
687
 *
688
 * @param {Array} array - array
689
 * @param {Function} fn - predicate function for cluster rule
690
 * @param {Array[]}
691
 */
692

693

694
function clusterBy(array, fn) {
695
  if (!array.length) {
696
    return [];
697
  }
698

699
  var aTail = tail(array);
700
  return aTail.reduce(function (memo, v) {
701
    var aLast = last(memo);
702

703
    if (fn(last(aLast), v)) {
704
      aLast[aLast.length] = v;
705
    } else {
706
      memo[memo.length] = [v];
707
    }
708

709
    return memo;
710
  }, [[head(array)]]);
711
}
712
/**
713
 * returns a copy of the array with all false values removed
714
 *
715
 * @param {Array} array - array
716
 * @param {Function} fn - predicate function for cluster rule
717
 */
718

719

720
function compact(array) {
721
  var aResult = [];
722

723
  for (var idx = 0, len = array.length; idx < len; idx++) {
724
    if (array[idx]) {
725
      aResult.push(array[idx]);
726
    }
727
  }
728

729
  return aResult;
730
}
731
/**
732
 * produces a duplicate-free version of the array
733
 *
734
 * @param {Array} array
735
 */
736

737

738
function unique(array) {
739
  var results = [];
740

741
  for (var idx = 0, len = array.length; idx < len; idx++) {
742
    if (!contains(results, array[idx])) {
743
      results.push(array[idx]);
744
    }
745
  }
746

747
  return results;
748
}
749
/**
750
 * returns next item.
751
 * @param {Array} array
752
 */
753

754

755
function next(array, item) {
756
  if (array && array.length && item) {
757
    var idx = array.indexOf(item);
758
    return idx === -1 ? null : array[idx + 1];
759
  }
760

761
  return null;
762
}
763
/**
764
 * returns prev item.
765
 * @param {Array} array
766
 */
767

768

769
function prev(array, item) {
770
  if (array && array.length && item) {
771
    var idx = array.indexOf(item);
772
    return idx === -1 ? null : array[idx - 1];
773
  }
774

775
  return null;
776
}
777
/**
778
 * @class core.list
779
 *
780
 * list utils
781
 *
782
 * @singleton
783
 * @alternateClassName list
784
 */
785

786

787
/* harmony default export */ const lists = ({
788
  head: head,
789
  last: last,
790
  initial: initial,
791
  tail: tail,
792
  prev: prev,
793
  next: next,
794
  find: find,
795
  contains: contains,
796
  all: lists_all,
797
  sum: sum,
798
  from: from,
799
  isEmpty: isEmpty,
800
  clusterBy: clusterBy,
801
  compact: compact,
802
  unique: unique
803
});
804
;// CONCATENATED MODULE: ./src/js/core/dom.js
805

806

807

808

809
var NBSP_CHAR = String.fromCharCode(160);
810
var ZERO_WIDTH_NBSP_CHAR = "\uFEFF";
811
/**
812
 * @method isEditable
813
 *
814
 * returns whether node is `note-editable` or not.
815
 *
816
 * @param {Node} node
817
 * @return {Boolean}
818
 */
819

820
function isEditable(node) {
821
  return node && external_jQuery_default()(node).hasClass('note-editable');
822
}
823
/**
824
 * @method isControlSizing
825
 *
826
 * returns whether node is `note-control-sizing` or not.
827
 *
828
 * @param {Node} node
829
 * @return {Boolean}
830
 */
831

832

833
function isControlSizing(node) {
834
  return node && external_jQuery_default()(node).hasClass('note-control-sizing');
835
}
836
/**
837
 * @method makePredByNodeName
838
 *
839
 * returns predicate which judge whether nodeName is same
840
 *
841
 * @param {String} nodeName
842
 * @return {Function}
843
 */
844

845

846
function makePredByNodeName(nodeName) {
847
  nodeName = nodeName.toUpperCase();
848
  return function (node) {
849
    return node && node.nodeName.toUpperCase() === nodeName;
850
  };
851
}
852
/**
853
 * @method isText
854
 *
855
 *
856
 *
857
 * @param {Node} node
858
 * @return {Boolean} true if node's type is text(3)
859
 */
860

861

862
function isText(node) {
863
  return node && node.nodeType === 3;
864
}
865
/**
866
 * @method isElement
867
 *
868
 *
869
 *
870
 * @param {Node} node
871
 * @return {Boolean} true if node's type is element(1)
872
 */
873

874

875
function isElement(node) {
876
  return node && node.nodeType === 1;
877
}
878
/**
879
 * ex) br, col, embed, hr, img, input, ...
880
 * @see http://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
881
 */
882

883

884
function isVoid(node) {
885
  return node && /^BR|^IMG|^HR|^IFRAME|^BUTTON|^INPUT|^AUDIO|^VIDEO|^EMBED/.test(node.nodeName.toUpperCase());
886
}
887

888
function isPara(node) {
889
  if (isEditable(node)) {
890
    return false;
891
  } // Chrome(v31.0), FF(v25.0.1) use DIV for paragraph
892

893

894
  return node && /^DIV|^P|^LI|^H[1-7]/.test(node.nodeName.toUpperCase());
895
}
896

897
function isHeading(node) {
898
  return node && /^H[1-7]/.test(node.nodeName.toUpperCase());
899
}
900

901
var isPre = makePredByNodeName('PRE');
902
var isLi = makePredByNodeName('LI');
903

904
function isPurePara(node) {
905
  return isPara(node) && !isLi(node);
906
}
907

908
var isTable = makePredByNodeName('TABLE');
909
var isData = makePredByNodeName('DATA');
910

911
function isInline(node) {
912
  return !isBodyContainer(node) && !isList(node) && !isHr(node) && !isPara(node) && !isTable(node) && !isBlockquote(node) && !isData(node);
913
}
914

915
function isList(node) {
916
  return node && /^UL|^OL/.test(node.nodeName.toUpperCase());
917
}
918

919
var isHr = makePredByNodeName('HR');
920

921
function isCell(node) {
922
  return node && /^TD|^TH/.test(node.nodeName.toUpperCase());
923
}
924

925
var isBlockquote = makePredByNodeName('BLOCKQUOTE');
926

927
function isBodyContainer(node) {
928
  return isCell(node) || isBlockquote(node) || isEditable(node);
929
}
930

931
var isAnchor = makePredByNodeName('A');
932

933
function isParaInline(node) {
934
  return isInline(node) && !!ancestor(node, isPara);
935
}
936

937
function isBodyInline(node) {
938
  return isInline(node) && !ancestor(node, isPara);
939
}
940

941
var isBody = makePredByNodeName('BODY');
942
/**
943
 * returns whether nodeB is closest sibling of nodeA
944
 *
945
 * @param {Node} nodeA
946
 * @param {Node} nodeB
947
 * @return {Boolean}
948
 */
949

950
function isClosestSibling(nodeA, nodeB) {
951
  return nodeA.nextSibling === nodeB || nodeA.previousSibling === nodeB;
952
}
953
/**
954
 * returns array of closest siblings with node
955
 *
956
 * @param {Node} node
957
 * @param {function} [pred] - predicate function
958
 * @return {Node[]}
959
 */
960

961

962
function withClosestSiblings(node, pred) {
963
  pred = pred || func.ok;
964
  var siblings = [];
965

966
  if (node.previousSibling && pred(node.previousSibling)) {
967
    siblings.push(node.previousSibling);
968
  }
969

970
  siblings.push(node);
971

972
  if (node.nextSibling && pred(node.nextSibling)) {
973
    siblings.push(node.nextSibling);
974
  }
975

976
  return siblings;
977
}
978
/**
979
 * blank HTML for cursor position
980
 * - [workaround] old IE only works with &nbsp;
981
 * - [workaround] IE11 and other browser works with bogus br
982
 */
983

984

985
var blankHTML = env.isMSIE && env.browserVersion < 11 ? '&nbsp;' : '<br>';
986
/**
987
 * @method nodeLength
988
 *
989
 * returns #text's text size or element's childNodes size
990
 *
991
 * @param {Node} node
992
 */
993

994
function nodeLength(node) {
995
  if (isText(node)) {
996
    return node.nodeValue.length;
997
  }
998

999
  if (node) {
1000
    return node.childNodes.length;
1001
  }
1002

1003
  return 0;
1004
}
1005
/**
1006
 * returns whether deepest child node is empty or not.
1007
 *
1008
 * @param {Node} node
1009
 * @return {Boolean}
1010
 */
1011

1012

1013
function deepestChildIsEmpty(node) {
1014
  do {
1015
    if (node.firstElementChild === null || node.firstElementChild.innerHTML === '') break;
1016
  } while (node = node.firstElementChild);
1017

1018
  return dom_isEmpty(node);
1019
}
1020
/**
1021
 * returns whether node is empty or not.
1022
 *
1023
 * @param {Node} node
1024
 * @return {Boolean}
1025
 */
1026

1027

1028
function dom_isEmpty(node) {
1029
  var len = nodeLength(node);
1030

1031
  if (len === 0) {
1032
    return true;
1033
  } else if (!isText(node) && len === 1 && node.innerHTML === blankHTML) {
1034
    // ex) <p><br></p>, <span><br></span>
1035
    return true;
1036
  } else if (lists.all(node.childNodes, isText) && node.innerHTML === '') {
1037
    // ex) <p></p>, <span></span>
1038
    return true;
1039
  }
1040

1041
  return false;
1042
}
1043
/**
1044
 * padding blankHTML if node is empty (for cursor position)
1045
 */
1046

1047

1048
function paddingBlankHTML(node) {
1049
  if (!isVoid(node) && !nodeLength(node)) {
1050
    node.innerHTML = blankHTML;
1051
  }
1052
}
1053
/**
1054
 * find nearest ancestor predicate hit
1055
 *
1056
 * @param {Node} node
1057
 * @param {Function} pred - predicate function
1058
 */
1059

1060

1061
function ancestor(node, pred) {
1062
  while (node) {
1063
    if (pred(node)) {
1064
      return node;
1065
    }
1066

1067
    if (isEditable(node)) {
1068
      break;
1069
    }
1070

1071
    node = node.parentNode;
1072
  }
1073

1074
  return null;
1075
}
1076
/**
1077
 * find nearest ancestor only single child blood line and predicate hit
1078
 *
1079
 * @param {Node} node
1080
 * @param {Function} pred - predicate function
1081
 */
1082

1083

1084
function singleChildAncestor(node, pred) {
1085
  node = node.parentNode;
1086

1087
  while (node) {
1088
    if (nodeLength(node) !== 1) {
1089
      break;
1090
    }
1091

1092
    if (pred(node)) {
1093
      return node;
1094
    }
1095

1096
    if (isEditable(node)) {
1097
      break;
1098
    }
1099

1100
    node = node.parentNode;
1101
  }
1102

1103
  return null;
1104
}
1105
/**
1106
 * returns new array of ancestor nodes (until predicate hit).
1107
 *
1108
 * @param {Node} node
1109
 * @param {Function} [optional] pred - predicate function
1110
 */
1111

1112

1113
function listAncestor(node, pred) {
1114
  pred = pred || func.fail;
1115
  var ancestors = [];
1116
  ancestor(node, function (el) {
1117
    if (!isEditable(el)) {
1118
      ancestors.push(el);
1119
    }
1120

1121
    return pred(el);
1122
  });
1123
  return ancestors;
1124
}
1125
/**
1126
 * find farthest ancestor predicate hit
1127
 */
1128

1129

1130
function lastAncestor(node, pred) {
1131
  var ancestors = listAncestor(node);
1132
  return lists.last(ancestors.filter(pred));
1133
}
1134
/**
1135
 * returns common ancestor node between two nodes.
1136
 *
1137
 * @param {Node} nodeA
1138
 * @param {Node} nodeB
1139
 */
1140

1141

1142
function commonAncestor(nodeA, nodeB) {
1143
  var ancestors = listAncestor(nodeA);
1144

1145
  for (var n = nodeB; n; n = n.parentNode) {
1146
    if (ancestors.indexOf(n) > -1) return n;
1147
  }
1148

1149
  return null; // difference document area
1150
}
1151
/**
1152
 * listing all previous siblings (until predicate hit).
1153
 *
1154
 * @param {Node} node
1155
 * @param {Function} [optional] pred - predicate function
1156
 */
1157

1158

1159
function listPrev(node, pred) {
1160
  pred = pred || func.fail;
1161
  var nodes = [];
1162

1163
  while (node) {
1164
    if (pred(node)) {
1165
      break;
1166
    }
1167

1168
    nodes.push(node);
1169
    node = node.previousSibling;
1170
  }
1171

1172
  return nodes;
1173
}
1174
/**
1175
 * listing next siblings (until predicate hit).
1176
 *
1177
 * @param {Node} node
1178
 * @param {Function} [pred] - predicate function
1179
 */
1180

1181

1182
function listNext(node, pred) {
1183
  pred = pred || func.fail;
1184
  var nodes = [];
1185

1186
  while (node) {
1187
    if (pred(node)) {
1188
      break;
1189
    }
1190

1191
    nodes.push(node);
1192
    node = node.nextSibling;
1193
  }
1194

1195
  return nodes;
1196
}
1197
/**
1198
 * listing descendant nodes
1199
 *
1200
 * @param {Node} node
1201
 * @param {Function} [pred] - predicate function
1202
 */
1203

1204

1205
function listDescendant(node, pred) {
1206
  var descendants = [];
1207
  pred = pred || func.ok; // start DFS(depth first search) with node
1208

1209
  (function fnWalk(current) {
1210
    if (node !== current && pred(current)) {
1211
      descendants.push(current);
1212
    }
1213

1214
    for (var idx = 0, len = current.childNodes.length; idx < len; idx++) {
1215
      fnWalk(current.childNodes[idx]);
1216
    }
1217
  })(node);
1218

1219
  return descendants;
1220
}
1221
/**
1222
 * wrap node with new tag.
1223
 *
1224
 * @param {Node} node
1225
 * @param {Node} tagName of wrapper
1226
 * @return {Node} - wrapper
1227
 */
1228

1229

1230
function wrap(node, wrapperName) {
1231
  var parent = node.parentNode;
1232
  var wrapper = external_jQuery_default()('<' + wrapperName + '>')[0];
1233
  parent.insertBefore(wrapper, node);
1234
  wrapper.appendChild(node);
1235
  return wrapper;
1236
}
1237
/**
1238
 * insert node after preceding
1239
 *
1240
 * @param {Node} node
1241
 * @param {Node} preceding - predicate function
1242
 */
1243

1244

1245
function insertAfter(node, preceding) {
1246
  var next = preceding.nextSibling;
1247
  var parent = preceding.parentNode;
1248

1249
  if (next) {
1250
    parent.insertBefore(node, next);
1251
  } else {
1252
    parent.appendChild(node);
1253
  }
1254

1255
  return node;
1256
}
1257
/**
1258
 * append elements.
1259
 *
1260
 * @param {Node} node
1261
 * @param {Collection} aChild
1262
 */
1263

1264

1265
function appendChildNodes(node, aChild) {
1266
  external_jQuery_default().each(aChild, function (idx, child) {
1267
    node.appendChild(child);
1268
  });
1269
  return node;
1270
}
1271
/**
1272
 * returns whether boundaryPoint is left edge or not.
1273
 *
1274
 * @param {BoundaryPoint} point
1275
 * @return {Boolean}
1276
 */
1277

1278

1279
function isLeftEdgePoint(point) {
1280
  return point.offset === 0;
1281
}
1282
/**
1283
 * returns whether boundaryPoint is right edge or not.
1284
 *
1285
 * @param {BoundaryPoint} point
1286
 * @return {Boolean}
1287
 */
1288

1289

1290
function isRightEdgePoint(point) {
1291
  return point.offset === nodeLength(point.node);
1292
}
1293
/**
1294
 * returns whether boundaryPoint is edge or not.
1295
 *
1296
 * @param {BoundaryPoint} point
1297
 * @return {Boolean}
1298
 */
1299

1300

1301
function isEdgePoint(point) {
1302
  return isLeftEdgePoint(point) || isRightEdgePoint(point);
1303
}
1304
/**
1305
 * returns whether node is left edge of ancestor or not.
1306
 *
1307
 * @param {Node} node
1308
 * @param {Node} ancestor
1309
 * @return {Boolean}
1310
 */
1311

1312

1313
function isLeftEdgeOf(node, ancestor) {
1314
  while (node && node !== ancestor) {
1315
    if (position(node) !== 0) {
1316
      return false;
1317
    }
1318

1319
    node = node.parentNode;
1320
  }
1321

1322
  return true;
1323
}
1324
/**
1325
 * returns whether node is right edge of ancestor or not.
1326
 *
1327
 * @param {Node} node
1328
 * @param {Node} ancestor
1329
 * @return {Boolean}
1330
 */
1331

1332

1333
function isRightEdgeOf(node, ancestor) {
1334
  if (!ancestor) {
1335
    return false;
1336
  }
1337

1338
  while (node && node !== ancestor) {
1339
    if (position(node) !== nodeLength(node.parentNode) - 1) {
1340
      return false;
1341
    }
1342

1343
    node = node.parentNode;
1344
  }
1345

1346
  return true;
1347
}
1348
/**
1349
 * returns whether point is left edge of ancestor or not.
1350
 * @param {BoundaryPoint} point
1351
 * @param {Node} ancestor
1352
 * @return {Boolean}
1353
 */
1354

1355

1356
function isLeftEdgePointOf(point, ancestor) {
1357
  return isLeftEdgePoint(point) && isLeftEdgeOf(point.node, ancestor);
1358
}
1359
/**
1360
 * returns whether point is right edge of ancestor or not.
1361
 * @param {BoundaryPoint} point
1362
 * @param {Node} ancestor
1363
 * @return {Boolean}
1364
 */
1365

1366

1367
function isRightEdgePointOf(point, ancestor) {
1368
  return isRightEdgePoint(point) && isRightEdgeOf(point.node, ancestor);
1369
}
1370
/**
1371
 * returns offset from parent.
1372
 *
1373
 * @param {Node} node
1374
 */
1375

1376

1377
function position(node) {
1378
  var offset = 0;
1379

1380
  while (node = node.previousSibling) {
1381
    offset += 1;
1382
  }
1383

1384
  return offset;
1385
}
1386

1387
function hasChildren(node) {
1388
  return !!(node && node.childNodes && node.childNodes.length);
1389
}
1390
/**
1391
 * returns previous boundaryPoint
1392
 *
1393
 * @param {BoundaryPoint} point
1394
 * @param {Boolean} isSkipInnerOffset
1395
 * @return {BoundaryPoint}
1396
 */
1397

1398

1399
function prevPoint(point, isSkipInnerOffset) {
1400
  var node;
1401
  var offset;
1402

1403
  if (point.offset === 0) {
1404
    if (isEditable(point.node)) {
1405
      return null;
1406
    }
1407

1408
    node = point.node.parentNode;
1409
    offset = position(point.node);
1410
  } else if (hasChildren(point.node)) {
1411
    node = point.node.childNodes[point.offset - 1];
1412
    offset = nodeLength(node);
1413
  } else {
1414
    node = point.node;
1415
    offset = isSkipInnerOffset ? 0 : point.offset - 1;
1416
  }
1417

1418
  return {
1419
    node: node,
1420
    offset: offset
1421
  };
1422
}
1423
/**
1424
 * returns next boundaryPoint
1425
 *
1426
 * @param {BoundaryPoint} point
1427
 * @param {Boolean} isSkipInnerOffset
1428
 * @return {BoundaryPoint}
1429
 */
1430

1431

1432
function nextPoint(point, isSkipInnerOffset) {
1433
  var node, offset;
1434

1435
  if (nodeLength(point.node) === point.offset) {
1436
    if (isEditable(point.node)) {
1437
      return null;
1438
    }
1439

1440
    var nextTextNode = getNextTextNode(point.node);
1441

1442
    if (nextTextNode) {
1443
      node = nextTextNode;
1444
      offset = 0;
1445
    } else {
1446
      node = point.node.parentNode;
1447
      offset = position(point.node) + 1;
1448
    }
1449
  } else if (hasChildren(point.node)) {
1450
    node = point.node.childNodes[point.offset];
1451
    offset = 0;
1452
  } else {
1453
    node = point.node;
1454
    offset = isSkipInnerOffset ? nodeLength(point.node) : point.offset + 1;
1455
  }
1456

1457
  return {
1458
    node: node,
1459
    offset: offset
1460
  };
1461
}
1462
/**
1463
 * returns next boundaryPoint with empty node
1464
 *
1465
 * @param {BoundaryPoint} point
1466
 * @param {Boolean} isSkipInnerOffset
1467
 * @return {BoundaryPoint}
1468
 */
1469

1470

1471
function nextPointWithEmptyNode(point, isSkipInnerOffset) {
1472
  var node,
1473
      offset = 0; // if node is empty string node, return current node's sibling.
1474

1475
  if (dom_isEmpty(point.node)) {
1476
    if (point.node === null) {
1477
      return null;
1478
    }
1479

1480
    node = point.node.nextSibling;
1481
    offset = 0;
1482
    return {
1483
      node: node,
1484
      offset: offset
1485
    };
1486
  }
1487

1488
  if (nodeLength(point.node) === point.offset) {
1489
    if (isEditable(point.node)) {
1490
      return null;
1491
    }
1492

1493
    node = point.node.parentNode;
1494
    offset = position(point.node) + 1; // if next node is editable ,  return current node's sibling node.
1495

1496
    if (isEditable(node)) {
1497
      node = point.node.nextSibling;
1498
      offset = 0;
1499
    }
1500
  } else if (hasChildren(point.node)) {
1501
    node = point.node.childNodes[point.offset];
1502
    offset = 0;
1503

1504
    if (dom_isEmpty(node)) {
1505
      if (!dom_isEmpty(point.node.nextSibling)) {
1506
        return {
1507
          node: point.node.nextSibling,
1508
          offset: offset
1509
        };
1510
      }
1511

1512
      return null;
1513
    }
1514
  } else {
1515
    node = point.node;
1516
    offset = isSkipInnerOffset ? nodeLength(point.node) : point.offset + 1;
1517

1518
    if (dom_isEmpty(node)) {
1519
      return null;
1520
    }
1521
  }
1522

1523
  return {
1524
    node: node,
1525
    offset: offset
1526
  };
1527
}
1528
/*
1529
* returns the next Text node index or 0 if not found.
1530
*/
1531

1532

1533
function getNextTextNode(actual) {
1534
  if (!actual.nextSibling) return undefined;
1535
  if (actual.parent !== actual.nextSibling.parent) return undefined;
1536
  if (isText(actual.nextSibling)) return actual.nextSibling;else return getNextTextNode(actual.nextSibling);
1537
}
1538
/**
1539
 * returns whether pointA and pointB is same or not.
1540
 *
1541
 * @param {BoundaryPoint} pointA
1542
 * @param {BoundaryPoint} pointB
1543
 * @return {Boolean}
1544
 */
1545

1546

1547
function isSamePoint(pointA, pointB) {
1548
  return pointA.node === pointB.node && pointA.offset === pointB.offset;
1549
}
1550
/**
1551
 * returns whether point is visible (can set cursor) or not.
1552
 *
1553
 * @param {BoundaryPoint} point
1554
 * @return {Boolean}
1555
 */
1556

1557

1558
function isVisiblePoint(point) {
1559
  if (isText(point.node) || !hasChildren(point.node) || dom_isEmpty(point.node)) {
1560
    return true;
1561
  }
1562

1563
  var leftNode = point.node.childNodes[point.offset - 1];
1564
  var rightNode = point.node.childNodes[point.offset];
1565

1566
  if ((!leftNode || isVoid(leftNode)) && (!rightNode || isVoid(rightNode)) || isTable(rightNode)) {
1567
    return true;
1568
  }
1569

1570
  return false;
1571
}
1572
/**
1573
 * @method prevPointUtil
1574
 *
1575
 * @param {BoundaryPoint} point
1576
 * @param {Function} pred
1577
 * @return {BoundaryPoint}
1578
 */
1579

1580

1581
function prevPointUntil(point, pred) {
1582
  while (point) {
1583
    if (pred(point)) {
1584
      return point;
1585
    }
1586

1587
    point = prevPoint(point);
1588
  }
1589

1590
  return null;
1591
}
1592
/**
1593
 * @method nextPointUntil
1594
 *
1595
 * @param {BoundaryPoint} point
1596
 * @param {Function} pred
1597
 * @return {BoundaryPoint}
1598
 */
1599

1600

1601
function nextPointUntil(point, pred) {
1602
  while (point) {
1603
    if (pred(point)) {
1604
      return point;
1605
    }
1606

1607
    point = nextPoint(point);
1608
  }
1609

1610
  return null;
1611
}
1612
/**
1613
 * returns whether point has character or not.
1614
 *
1615
 * @param {Point} point
1616
 * @return {Boolean}
1617
 */
1618

1619

1620
function isCharPoint(point) {
1621
  if (!isText(point.node)) {
1622
    return false;
1623
  }
1624

1625
  var ch = point.node.nodeValue.charAt(point.offset - 1);
1626
  return ch && ch !== ' ' && ch !== NBSP_CHAR;
1627
}
1628
/**
1629
 * returns whether point has space or not.
1630
 *
1631
 * @param {Point} point
1632
 * @return {Boolean}
1633
 */
1634

1635

1636
function isSpacePoint(point) {
1637
  if (!isText(point.node)) {
1638
    return false;
1639
  }
1640

1641
  var ch = point.node.nodeValue.charAt(point.offset - 1);
1642
  return ch === ' ' || ch === NBSP_CHAR;
1643
}
1644
/**
1645
 * @method walkPoint
1646
 *
1647
 * @param {BoundaryPoint} startPoint
1648
 * @param {BoundaryPoint} endPoint
1649
 * @param {Function} handler
1650
 * @param {Boolean} isSkipInnerOffset
1651
 */
1652

1653

1654
function walkPoint(startPoint, endPoint, handler, isSkipInnerOffset) {
1655
  var point = startPoint;
1656

1657
  while (point) {
1658
    handler(point);
1659

1660
    if (isSamePoint(point, endPoint)) {
1661
      break;
1662
    }
1663

1664
    var isSkipOffset = isSkipInnerOffset && startPoint.node !== point.node && endPoint.node !== point.node;
1665
    point = nextPointWithEmptyNode(point, isSkipOffset);
1666
  }
1667
}
1668
/**
1669
 * @method makeOffsetPath
1670
 *
1671
 * return offsetPath(array of offset) from ancestor
1672
 *
1673
 * @param {Node} ancestor - ancestor node
1674
 * @param {Node} node
1675
 */
1676

1677

1678
function makeOffsetPath(ancestor, node) {
1679
  var ancestors = listAncestor(node, func.eq(ancestor));
1680
  return ancestors.map(position).reverse();
1681
}
1682
/**
1683
 * @method fromOffsetPath
1684
 *
1685
 * return element from offsetPath(array of offset)
1686
 *
1687
 * @param {Node} ancestor - ancestor node
1688
 * @param {array} offsets - offsetPath
1689
 */
1690

1691

1692
function fromOffsetPath(ancestor, offsets) {
1693
  var current = ancestor;
1694

1695
  for (var i = 0, len = offsets.length; i < len; i++) {
1696
    if (current.childNodes.length <= offsets[i]) {
1697
      current = current.childNodes[current.childNodes.length - 1];
1698
    } else {
1699
      current = current.childNodes[offsets[i]];
1700
    }
1701
  }
1702

1703
  return current;
1704
}
1705
/**
1706
 * @method splitNode
1707
 *
1708
 * split element or #text
1709
 *
1710
 * @param {BoundaryPoint} point
1711
 * @param {Object} [options]
1712
 * @param {Boolean} [options.isSkipPaddingBlankHTML] - default: false
1713
 * @param {Boolean} [options.isNotSplitEdgePoint] - default: false
1714
 * @param {Boolean} [options.isDiscardEmptySplits] - default: false
1715
 * @return {Node} right node of boundaryPoint
1716
 */
1717

1718

1719
function splitNode(point, options) {
1720
  var isSkipPaddingBlankHTML = options && options.isSkipPaddingBlankHTML;
1721
  var isNotSplitEdgePoint = options && options.isNotSplitEdgePoint;
1722
  var isDiscardEmptySplits = options && options.isDiscardEmptySplits;
1723

1724
  if (isDiscardEmptySplits) {
1725
    isSkipPaddingBlankHTML = true;
1726
  } // edge case
1727

1728

1729
  if (isEdgePoint(point) && (isText(point.node) || isNotSplitEdgePoint)) {
1730
    if (isLeftEdgePoint(point)) {
1731
      return point.node;
1732
    } else if (isRightEdgePoint(point)) {
1733
      return point.node.nextSibling;
1734
    }
1735
  } // split #text
1736

1737

1738
  if (isText(point.node)) {
1739
    return point.node.splitText(point.offset);
1740
  } else {
1741
    var childNode = point.node.childNodes[point.offset];
1742
    var clone = insertAfter(point.node.cloneNode(false), point.node);
1743
    appendChildNodes(clone, listNext(childNode));
1744

1745
    if (!isSkipPaddingBlankHTML) {
1746
      paddingBlankHTML(point.node);
1747
      paddingBlankHTML(clone);
1748
    }
1749

1750
    if (isDiscardEmptySplits) {
1751
      if (dom_isEmpty(point.node)) {
1752
        remove(point.node);
1753
      }
1754

1755
      if (dom_isEmpty(clone)) {
1756
        remove(clone);
1757
        return point.node.nextSibling;
1758
      }
1759
    }
1760

1761
    return clone;
1762
  }
1763
}
1764
/**
1765
 * @method splitTree
1766
 *
1767
 * split tree by point
1768
 *
1769
 * @param {Node} root - split root
1770
 * @param {BoundaryPoint} point
1771
 * @param {Object} [options]
1772
 * @param {Boolean} [options.isSkipPaddingBlankHTML] - default: false
1773
 * @param {Boolean} [options.isNotSplitEdgePoint] - default: false
1774
 * @return {Node} right node of boundaryPoint
1775
 */
1776

1777

1778
function splitTree(root, point, options) {
1779
  // ex) [#text, <span>, <p>]
1780
  var ancestors = listAncestor(point.node, func.eq(root));
1781

1782
  if (!ancestors.length) {
1783
    return null;
1784
  } else if (ancestors.length === 1) {
1785
    return splitNode(point, options);
1786
  }
1787

1788
  return ancestors.reduce(function (node, parent) {
1789
    if (node === point.node) {
1790
      node = splitNode(point, options);
1791
    }
1792

1793
    return splitNode({
1794
      node: parent,
1795
      offset: node ? position(node) : nodeLength(parent)
1796
    }, options);
1797
  });
1798
}
1799
/**
1800
 * split point
1801
 *
1802
 * @param {Point} point
1803
 * @param {Boolean} isInline
1804
 * @return {Object}
1805
 */
1806

1807

1808
function splitPoint(point, isInline) {
1809
  // find splitRoot, container
1810
  //  - inline: splitRoot is a child of paragraph
1811
  //  - block: splitRoot is a child of bodyContainer
1812
  var pred = isInline ? isPara : isBodyContainer;
1813
  var ancestors = listAncestor(point.node, pred);
1814
  var topAncestor = lists.last(ancestors) || point.node;
1815
  var splitRoot, container;
1816

1817
  if (pred(topAncestor)) {
1818
    splitRoot = ancestors[ancestors.length - 2];
1819
    container = topAncestor;
1820
  } else {
1821
    splitRoot = topAncestor;
1822
    container = splitRoot.parentNode;
1823
  } // if splitRoot is exists, split with splitTree
1824

1825

1826
  var pivot = splitRoot && splitTree(splitRoot, point, {
1827
    isSkipPaddingBlankHTML: isInline,
1828
    isNotSplitEdgePoint: isInline
1829
  }); // if container is point.node, find pivot with point.offset
1830

1831
  if (!pivot && container === point.node) {
1832
    pivot = point.node.childNodes[point.offset];
1833
  }
1834

1835
  return {
1836
    rightNode: pivot,
1837
    container: container
1838
  };
1839
}
1840

1841
function create(nodeName) {
1842
  return document.createElement(nodeName);
1843
}
1844

1845
function createText(text) {
1846
  return document.createTextNode(text);
1847
}
1848
/**
1849
 * @method remove
1850
 *
1851
 * remove node, (isRemoveChild: remove child or not)
1852
 *
1853
 * @param {Node} node
1854
 * @param {Boolean} isRemoveChild
1855
 */
1856

1857

1858
function remove(node, isRemoveChild) {
1859
  if (!node || !node.parentNode) {
1860
    return;
1861
  }
1862

1863
  if (node.removeNode) {
1864
    return node.removeNode(isRemoveChild);
1865
  }
1866

1867
  var parent = node.parentNode;
1868

1869
  if (!isRemoveChild) {
1870
    var nodes = [];
1871

1872
    for (var i = 0, len = node.childNodes.length; i < len; i++) {
1873
      nodes.push(node.childNodes[i]);
1874
    }
1875

1876
    for (var _i = 0, _len = nodes.length; _i < _len; _i++) {
1877
      parent.insertBefore(nodes[_i], node);
1878
    }
1879
  }
1880

1881
  parent.removeChild(node);
1882
}
1883
/**
1884
 * @method removeWhile
1885
 *
1886
 * @param {Node} node
1887
 * @param {Function} pred
1888
 */
1889

1890

1891
function removeWhile(node, pred) {
1892
  while (node) {
1893
    if (isEditable(node) || !pred(node)) {
1894
      break;
1895
    }
1896

1897
    var parent = node.parentNode;
1898
    remove(node);
1899
    node = parent;
1900
  }
1901
}
1902
/**
1903
 * @method replace
1904
 *
1905
 * replace node with provided nodeName
1906
 *
1907
 * @param {Node} node
1908
 * @param {String} nodeName
1909
 * @return {Node} - new node
1910
 */
1911

1912

1913
function replace(node, nodeName) {
1914
  if (node.nodeName.toUpperCase() === nodeName.toUpperCase()) {
1915
    return node;
1916
  }
1917

1918
  var newNode = create(nodeName);
1919

1920
  if (node.style.cssText) {
1921
    newNode.style.cssText = node.style.cssText;
1922
  }
1923

1924
  appendChildNodes(newNode, lists.from(node.childNodes));
1925
  insertAfter(newNode, node);
1926
  remove(node);
1927
  return newNode;
1928
}
1929

1930
var isTextarea = makePredByNodeName('TEXTAREA');
1931
/**
1932
 * @param {jQuery} $node
1933
 * @param {Boolean} [stripLinebreaks] - default: false
1934
 */
1935

1936
function value($node, stripLinebreaks) {
1937
  var val = isTextarea($node[0]) ? $node.val() : $node.html();
1938

1939
  if (stripLinebreaks) {
1940
    return val.replace(/[\n\r]/g, '');
1941
  }
1942

1943
  return val;
1944
}
1945
/**
1946
 * @method html
1947
 *
1948
 * get the HTML contents of node
1949
 *
1950
 * @param {jQuery} $node
1951
 * @param {Boolean} [isNewlineOnBlock]
1952
 */
1953

1954

1955
function html($node, isNewlineOnBlock) {
1956
  var markup = value($node);
1957

1958
  if (isNewlineOnBlock) {
1959
    var regexTag = /<(\/?)(\b(?!!)[^>\s]*)(.*?)(\s*\/?>)/g;
1960
    markup = markup.replace(regexTag, function (match, endSlash, name) {
1961
      name = name.toUpperCase();
1962
      var isEndOfInlineContainer = /^DIV|^TD|^TH|^P|^LI|^H[1-7]/.test(name) && !!endSlash;
1963
      var isBlockNode = /^BLOCKQUOTE|^TABLE|^TBODY|^TR|^HR|^UL|^OL/.test(name);
1964
      return match + (isEndOfInlineContainer || isBlockNode ? '\n' : '');
1965
    });
1966
    markup = markup.trim();
1967
  }
1968

1969
  return markup;
1970
}
1971

1972
function posFromPlaceholder(placeholder) {
1973
  var $placeholder = external_jQuery_default()(placeholder);
1974
  var pos = $placeholder.offset();
1975
  var height = $placeholder.outerHeight(true); // include margin
1976

1977
  return {
1978
    left: pos.left,
1979
    top: pos.top + height
1980
  };
1981
}
1982

1983
function attachEvents($node, events) {
1984
  Object.keys(events).forEach(function (key) {
1985
    $node.on(key, events[key]);
1986
  });
1987
}
1988

1989
function detachEvents($node, events) {
1990
  Object.keys(events).forEach(function (key) {
1991
    $node.off(key, events[key]);
1992
  });
1993
}
1994
/**
1995
 * @method isCustomStyleTag
1996
 *
1997
 * assert if a node contains a "note-styletag" class,
1998
 * which implies that's a custom-made style tag node
1999
 *
2000
 * @param {Node} an HTML DOM node
2001
 */
2002

2003

2004
function isCustomStyleTag(node) {
2005
  return node && !isText(node) && lists.contains(node.classList, 'note-styletag');
2006
}
2007

2008
/* harmony default export */ const dom = ({
2009
  /** @property {String} NBSP_CHAR */
2010
  NBSP_CHAR: NBSP_CHAR,
2011

2012
  /** @property {String} ZERO_WIDTH_NBSP_CHAR */
2013
  ZERO_WIDTH_NBSP_CHAR: ZERO_WIDTH_NBSP_CHAR,
2014

2015
  /** @property {String} blank */
2016
  blank: blankHTML,
2017

2018
  /** @property {String} emptyPara */
2019
  emptyPara: "<p>".concat(blankHTML, "</p>"),
2020
  makePredByNodeName: makePredByNodeName,
2021
  isEditable: isEditable,
2022
  isControlSizing: isControlSizing,
2023
  isText: isText,
2024
  isElement: isElement,
2025
  isVoid: isVoid,
2026
  isPara: isPara,
2027
  isPurePara: isPurePara,
2028
  isHeading: isHeading,
2029
  isInline: isInline,
2030
  isBlock: func.not(isInline),
2031
  isBodyInline: isBodyInline,
2032
  isBody: isBody,
2033
  isParaInline: isParaInline,
2034
  isPre: isPre,
2035
  isList: isList,
2036
  isTable: isTable,
2037
  isData: isData,
2038
  isCell: isCell,
2039
  isBlockquote: isBlockquote,
2040
  isBodyContainer: isBodyContainer,
2041
  isAnchor: isAnchor,
2042
  isDiv: makePredByNodeName('DIV'),
2043
  isLi: isLi,
2044
  isBR: makePredByNodeName('BR'),
2045
  isSpan: makePredByNodeName('SPAN'),
2046
  isB: makePredByNodeName('B'),
2047
  isU: makePredByNodeName('U'),
2048
  isS: makePredByNodeName('S'),
2049
  isI: makePredByNodeName('I'),
2050
  isImg: makePredByNodeName('IMG'),
2051
  isTextarea: isTextarea,
2052
  deepestChildIsEmpty: deepestChildIsEmpty,
2053
  isEmpty: dom_isEmpty,
2054
  isEmptyAnchor: func.and(isAnchor, dom_isEmpty),
2055
  isClosestSibling: isClosestSibling,
2056
  withClosestSiblings: withClosestSiblings,
2057
  nodeLength: nodeLength,
2058
  isLeftEdgePoint: isLeftEdgePoint,
2059
  isRightEdgePoint: isRightEdgePoint,
2060
  isEdgePoint: isEdgePoint,
2061
  isLeftEdgeOf: isLeftEdgeOf,
2062
  isRightEdgeOf: isRightEdgeOf,
2063
  isLeftEdgePointOf: isLeftEdgePointOf,
2064
  isRightEdgePointOf: isRightEdgePointOf,
2065
  prevPoint: prevPoint,
2066
  nextPoint: nextPoint,
2067
  nextPointWithEmptyNode: nextPointWithEmptyNode,
2068
  isSamePoint: isSamePoint,
2069
  isVisiblePoint: isVisiblePoint,
2070
  prevPointUntil: prevPointUntil,
2071
  nextPointUntil: nextPointUntil,
2072
  isCharPoint: isCharPoint,
2073
  isSpacePoint: isSpacePoint,
2074
  walkPoint: walkPoint,
2075
  ancestor: ancestor,
2076
  singleChildAncestor: singleChildAncestor,
2077
  listAncestor: listAncestor,
2078
  lastAncestor: lastAncestor,
2079
  listNext: listNext,
2080
  listPrev: listPrev,
2081
  listDescendant: listDescendant,
2082
  commonAncestor: commonAncestor,
2083
  wrap: wrap,
2084
  insertAfter: insertAfter,
2085
  appendChildNodes: appendChildNodes,
2086
  position: position,
2087
  hasChildren: hasChildren,
2088
  makeOffsetPath: makeOffsetPath,
2089
  fromOffsetPath: fromOffsetPath,
2090
  splitTree: splitTree,
2091
  splitPoint: splitPoint,
2092
  create: create,
2093
  createText: createText,
2094
  remove: remove,
2095
  removeWhile: removeWhile,
2096
  replace: replace,
2097
  html: html,
2098
  value: value,
2099
  posFromPlaceholder: posFromPlaceholder,
2100
  attachEvents: attachEvents,
2101
  detachEvents: detachEvents,
2102
  isCustomStyleTag: isCustomStyleTag
2103
});
2104
;// CONCATENATED MODULE: ./src/js/Context.js
2105
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2106

2107
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
2108

2109
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2110

2111

2112

2113

2114

2115

2116
var Context = /*#__PURE__*/function () {
2117
  /**
2118
   * @param {jQuery} $note
2119
   * @param {Object} options
2120
   */
2121
  function Context($note, options) {
2122
    _classCallCheck(this, Context);
2123

2124
    this.$note = $note;
2125
    this.memos = {};
2126
    this.modules = {};
2127
    this.layoutInfo = {};
2128
    this.options = external_jQuery_default().extend(true, {}, options); // init ui with options
2129

2130
    (external_jQuery_default()).summernote.ui = external_jQuery_default().summernote.ui_template(this.options);
2131
    this.ui = (external_jQuery_default()).summernote.ui;
2132
    this.initialize();
2133
  }
2134
  /**
2135
   * create layout and initialize modules and other resources
2136
   */
2137

2138

2139
  _createClass(Context, [{
2140
    key: "initialize",
2141
    value: function initialize() {
2142
      this.layoutInfo = this.ui.createLayout(this.$note);
2143

2144
      this._initialize();
2145

2146
      this.$note.hide();
2147
      return this;
2148
    }
2149
    /**
2150
     * destroy modules and other resources and remove layout
2151
     */
2152

2153
  }, {
2154
    key: "destroy",
2155
    value: function destroy() {
2156
      this._destroy();
2157

2158
      this.$note.removeData('summernote');
2159
      this.ui.removeLayout(this.$note, this.layoutInfo);
2160
    }
2161
    /**
2162
     * destory modules and other resources and initialize it again
2163
     */
2164

2165
  }, {
2166
    key: "reset",
2167
    value: function reset() {
2168
      var disabled = this.isDisabled();
2169
      this.code(dom.emptyPara);
2170

2171
      this._destroy();
2172

2173
      this._initialize();
2174

2175
      if (disabled) {
2176
        this.disable();
2177
      }
2178
    }
2179
  }, {
2180
    key: "_initialize",
2181
    value: function _initialize() {
2182
      var _this = this;
2183

2184
      // set own id
2185
      this.options.id = func.uniqueId(external_jQuery_default().now()); // set default container for tooltips, popovers, and dialogs
2186

2187
      this.options.container = this.options.container || this.layoutInfo.editor; // add optional buttons
2188

2189
      var buttons = external_jQuery_default().extend({}, this.options.buttons);
2190
      Object.keys(buttons).forEach(function (key) {
2191
        _this.memo('button.' + key, buttons[key]);
2192
      });
2193
      var modules = external_jQuery_default().extend({}, this.options.modules, (external_jQuery_default()).summernote.plugins || {}); // add and initialize modules
2194

2195
      Object.keys(modules).forEach(function (key) {
2196
        _this.module(key, modules[key], true);
2197
      });
2198
      Object.keys(this.modules).forEach(function (key) {
2199
        _this.initializeModule(key);
2200
      });
2201
    }
2202
  }, {
2203
    key: "_destroy",
2204
    value: function _destroy() {
2205
      var _this2 = this;
2206

2207
      // destroy modules with reversed order
2208
      Object.keys(this.modules).reverse().forEach(function (key) {
2209
        _this2.removeModule(key);
2210
      });
2211
      Object.keys(this.memos).forEach(function (key) {
2212
        _this2.removeMemo(key);
2213
      }); // trigger custom onDestroy callback
2214

2215
      this.triggerEvent('destroy', this);
2216
    }
2217
  }, {
2218
    key: "code",
2219
    value: function code(html) {
2220
      var isActivated = this.invoke('codeview.isActivated');
2221

2222
      if (html === undefined) {
2223
        this.invoke('codeview.sync');
2224
        return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html();
2225
      } else {
2226
        if (isActivated) {
2227
          this.invoke('codeview.sync', html);
2228
        } else {
2229
          this.layoutInfo.editable.html(html);
2230
        }
2231

2232
        this.$note.val(html);
2233
        this.triggerEvent('change', html, this.layoutInfo.editable);
2234
      }
2235
    }
2236
  }, {
2237
    key: "isDisabled",
2238
    value: function isDisabled() {
2239
      return this.layoutInfo.editable.attr('contenteditable') === 'false';
2240
    }
2241
  }, {
2242
    key: "enable",
2243
    value: function enable() {
2244
      this.layoutInfo.editable.attr('contenteditable', true);
2245
      this.invoke('toolbar.activate', true);
2246
      this.triggerEvent('disable', false);
2247
      this.options.editing = true;
2248
    }
2249
  }, {
2250
    key: "disable",
2251
    value: function disable() {
2252
      // close codeview if codeview is opend
2253
      if (this.invoke('codeview.isActivated')) {
2254
        this.invoke('codeview.deactivate');
2255
      }
2256

2257
      this.layoutInfo.editable.attr('contenteditable', false);
2258
      this.options.editing = false;
2259
      this.invoke('toolbar.deactivate', true);
2260
      this.triggerEvent('disable', true);
2261
    }
2262
  }, {
2263
    key: "triggerEvent",
2264
    value: function triggerEvent() {
2265
      var namespace = lists.head(arguments);
2266
      var args = lists.tail(lists.from(arguments));
2267
      var callback = this.options.callbacks[func.namespaceToCamel(namespace, 'on')];
2268

2269
      if (callback) {
2270
        callback.apply(this.$note[0], args);
2271
      }
2272

2273
      this.$note.trigger('summernote.' + namespace, args);
2274
    }
2275
  }, {
2276
    key: "initializeModule",
2277
    value: function initializeModule(key) {
2278
      var module = this.modules[key];
2279
      module.shouldInitialize = module.shouldInitialize || func.ok;
2280

2281
      if (!module.shouldInitialize()) {
2282
        return;
2283
      } // initialize module
2284

2285

2286
      if (module.initialize) {
2287
        module.initialize();
2288
      } // attach events
2289

2290

2291
      if (module.events) {
2292
        dom.attachEvents(this.$note, module.events);
2293
      }
2294
    }
2295
  }, {
2296
    key: "module",
2297
    value: function module(key, ModuleClass, withoutIntialize) {
2298
      if (arguments.length === 1) {
2299
        return this.modules[key];
2300
      }
2301

2302
      this.modules[key] = new ModuleClass(this);
2303

2304
      if (!withoutIntialize) {
2305
        this.initializeModule(key);
2306
      }
2307
    }
2308
  }, {
2309
    key: "removeModule",
2310
    value: function removeModule(key) {
2311
      var module = this.modules[key];
2312

2313
      if (module.shouldInitialize()) {
2314
        if (module.events) {
2315
          dom.detachEvents(this.$note, module.events);
2316
        }
2317

2318
        if (module.destroy) {
2319
          module.destroy();
2320
        }
2321
      }
2322

2323
      delete this.modules[key];
2324
    }
2325
  }, {
2326
    key: "memo",
2327
    value: function memo(key, obj) {
2328
      if (arguments.length === 1) {
2329
        return this.memos[key];
2330
      }
2331

2332
      this.memos[key] = obj;
2333
    }
2334
  }, {
2335
    key: "removeMemo",
2336
    value: function removeMemo(key) {
2337
      if (this.memos[key] && this.memos[key].destroy) {
2338
        this.memos[key].destroy();
2339
      }
2340

2341
      delete this.memos[key];
2342
    }
2343
    /**
2344
     * Some buttons need to change their visual style immediately once they get pressed
2345
     */
2346

2347
  }, {
2348
    key: "createInvokeHandlerAndUpdateState",
2349
    value: function createInvokeHandlerAndUpdateState(namespace, value) {
2350
      var _this3 = this;
2351

2352
      return function (event) {
2353
        _this3.createInvokeHandler(namespace, value)(event);
2354

2355
        _this3.invoke('buttons.updateCurrentStyle');
2356
      };
2357
    }
2358
  }, {
2359
    key: "createInvokeHandler",
2360
    value: function createInvokeHandler(namespace, value) {
2361
      var _this4 = this;
2362

2363
      return function (event) {
2364
        event.preventDefault();
2365
        var $target = external_jQuery_default()(event.target);
2366

2367
        _this4.invoke(namespace, value || $target.closest('[data-value]').data('value'), $target);
2368
      };
2369
    }
2370
  }, {
2371
    key: "invoke",
2372
    value: function invoke() {
2373
      var namespace = lists.head(arguments);
2374
      var args = lists.tail(lists.from(arguments));
2375
      var splits = namespace.split('.');
2376
      var hasSeparator = splits.length > 1;
2377
      var moduleName = hasSeparator && lists.head(splits);
2378
      var methodName = hasSeparator ? lists.last(splits) : lists.head(splits);
2379
      var module = this.modules[moduleName || 'editor'];
2380

2381
      if (!moduleName && this[methodName]) {
2382
        return this[methodName].apply(this, args);
2383
      } else if (module && module[methodName] && module.shouldInitialize()) {
2384
        return module[methodName].apply(module, args);
2385
      }
2386
    }
2387
  }]);
2388

2389
  return Context;
2390
}();
2391

2392

2393
;// CONCATENATED MODULE: ./src/js/summernote.js
2394

2395

2396

2397

2398
external_jQuery_default().fn.extend({
2399
  /**
2400
   * Summernote API
2401
   *
2402
   * @param {Object|String}
2403
   * @return {this}
2404
   */
2405
  summernote: function summernote() {
2406
    var type = external_jQuery_default().type(lists.head(arguments));
2407
    var isExternalAPICalled = type === 'string';
2408
    var hasInitOptions = type === 'object';
2409
    var options = external_jQuery_default().extend({}, (external_jQuery_default()).summernote.options, hasInitOptions ? lists.head(arguments) : {}); // Update options
2410

2411
    options.langInfo = external_jQuery_default().extend(true, {}, (external_jQuery_default()).summernote.lang["en-US"], (external_jQuery_default()).summernote.lang[options.lang]);
2412
    options.icons = external_jQuery_default().extend(true, {}, (external_jQuery_default()).summernote.options.icons, options.icons);
2413
    options.tooltip = options.tooltip === 'auto' ? !env.isSupportTouch : options.tooltip;
2414
    this.each(function (idx, note) {
2415
      var $note = external_jQuery_default()(note);
2416

2417
      if (!$note.data('summernote')) {
2418
        var context = new Context($note, options);
2419
        $note.data('summernote', context);
2420
        $note.data('summernote').triggerEvent('init', context.layoutInfo);
2421
      }
2422
    });
2423
    var $note = this.first();
2424

2425
    if ($note.length) {
2426
      var context = $note.data('summernote');
2427

2428
      if (isExternalAPICalled) {
2429
        return context.invoke.apply(context, lists.from(arguments));
2430
      } else if (options.focus) {
2431
        context.invoke('editor.focus');
2432
      }
2433
    }
2434

2435
    return this;
2436
  }
2437
});
2438
;// CONCATENATED MODULE: ./src/js/core/range.js
2439
function range_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2440

2441
function range_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
2442

2443
function range_createClass(Constructor, protoProps, staticProps) { if (protoProps) range_defineProperties(Constructor.prototype, protoProps); if (staticProps) range_defineProperties(Constructor, staticProps); return Constructor; }
2444

2445

2446

2447

2448

2449

2450
/**
2451
 * return boundaryPoint from TextRange, inspired by Andy Na's HuskyRange.js
2452
 *
2453
 * @param {TextRange} textRange
2454
 * @param {Boolean} isStart
2455
 * @return {BoundaryPoint}
2456
 *
2457
 * @see http://msdn.microsoft.com/en-us/library/ie/ms535872(v=vs.85).aspx
2458
 */
2459

2460
function textRangeToPoint(textRange, isStart) {
2461
  var container = textRange.parentElement();
2462
  var offset;
2463
  var tester = document.body.createTextRange();
2464
  var prevContainer;
2465
  var childNodes = lists.from(container.childNodes);
2466

2467
  for (offset = 0; offset < childNodes.length; offset++) {
2468
    if (dom.isText(childNodes[offset])) {
2469
      continue;
2470
    }
2471

2472
    tester.moveToElementText(childNodes[offset]);
2473

2474
    if (tester.compareEndPoints('StartToStart', textRange) >= 0) {
2475
      break;
2476
    }
2477

2478
    prevContainer = childNodes[offset];
2479
  }
2480

2481
  if (offset !== 0 && dom.isText(childNodes[offset - 1])) {
2482
    var textRangeStart = document.body.createTextRange();
2483
    var curTextNode = null;
2484
    textRangeStart.moveToElementText(prevContainer || container);
2485
    textRangeStart.collapse(!prevContainer);
2486
    curTextNode = prevContainer ? prevContainer.nextSibling : container.firstChild;
2487
    var pointTester = textRange.duplicate();
2488
    pointTester.setEndPoint('StartToStart', textRangeStart);
2489
    var textCount = pointTester.text.replace(/[\r\n]/g, '').length;
2490

2491
    while (textCount > curTextNode.nodeValue.length && curTextNode.nextSibling) {
2492
      textCount -= curTextNode.nodeValue.length;
2493
      curTextNode = curTextNode.nextSibling;
2494
    } // [workaround] enforce IE to re-reference curTextNode, hack
2495

2496

2497
    var dummy = curTextNode.nodeValue; // eslint-disable-line
2498

2499
    if (isStart && curTextNode.nextSibling && dom.isText(curTextNode.nextSibling) && textCount === curTextNode.nodeValue.length) {
2500
      textCount -= curTextNode.nodeValue.length;
2501
      curTextNode = curTextNode.nextSibling;
2502
    }
2503

2504
    container = curTextNode;
2505
    offset = textCount;
2506
  }
2507

2508
  return {
2509
    cont: container,
2510
    offset: offset
2511
  };
2512
}
2513
/**
2514
 * return TextRange from boundary point (inspired by google closure-library)
2515
 * @param {BoundaryPoint} point
2516
 * @return {TextRange}
2517
 */
2518

2519

2520
function pointToTextRange(point) {
2521
  var textRangeInfo = function textRangeInfo(container, offset) {
2522
    var node, isCollapseToStart;
2523

2524
    if (dom.isText(container)) {
2525
      var prevTextNodes = dom.listPrev(container, func.not(dom.isText));
2526
      var prevContainer = lists.last(prevTextNodes).previousSibling;
2527
      node = prevContainer || container.parentNode;
2528
      offset += lists.sum(lists.tail(prevTextNodes), dom.nodeLength);
2529
      isCollapseToStart = !prevContainer;
2530
    } else {
2531
      node = container.childNodes[offset] || container;
2532

2533
      if (dom.isText(node)) {
2534
        return textRangeInfo(node, 0);
2535
      }
2536

2537
      offset = 0;
2538
      isCollapseToStart = false;
2539
    }
2540

2541
    return {
2542
      node: node,
2543
      collapseToStart: isCollapseToStart,
2544
      offset: offset
2545
    };
2546
  };
2547

2548
  var textRange = document.body.createTextRange();
2549
  var info = textRangeInfo(point.node, point.offset);
2550
  textRange.moveToElementText(info.node);
2551
  textRange.collapse(info.collapseToStart);
2552
  textRange.moveStart('character', info.offset);
2553
  return textRange;
2554
}
2555
/**
2556
   * Wrapped Range
2557
   *
2558
   * @constructor
2559
   * @param {Node} sc - start container
2560
   * @param {Number} so - start offset
2561
   * @param {Node} ec - end container
2562
   * @param {Number} eo - end offset
2563
   */
2564

2565

2566
var WrappedRange = /*#__PURE__*/function () {
2567
  function WrappedRange(sc, so, ec, eo) {
2568
    range_classCallCheck(this, WrappedRange);
2569

2570
    this.sc = sc;
2571
    this.so = so;
2572
    this.ec = ec;
2573
    this.eo = eo; // isOnEditable: judge whether range is on editable or not
2574

2575
    this.isOnEditable = this.makeIsOn(dom.isEditable); // isOnList: judge whether range is on list node or not
2576

2577
    this.isOnList = this.makeIsOn(dom.isList); // isOnAnchor: judge whether range is on anchor node or not
2578

2579
    this.isOnAnchor = this.makeIsOn(dom.isAnchor); // isOnCell: judge whether range is on cell node or not
2580

2581
    this.isOnCell = this.makeIsOn(dom.isCell); // isOnData: judge whether range is on data node or not
2582

2583
    this.isOnData = this.makeIsOn(dom.isData);
2584
  } // nativeRange: get nativeRange from sc, so, ec, eo
2585

2586

2587
  range_createClass(WrappedRange, [{
2588
    key: "nativeRange",
2589
    value: function nativeRange() {
2590
      if (env.isW3CRangeSupport) {
2591
        var w3cRange = document.createRange();
2592
        w3cRange.setStart(this.sc, this.so);
2593
        w3cRange.setEnd(this.ec, this.eo);
2594
        return w3cRange;
2595
      } else {
2596
        var textRange = pointToTextRange({
2597
          node: this.sc,
2598
          offset: this.so
2599
        });
2600
        textRange.setEndPoint('EndToEnd', pointToTextRange({
2601
          node: this.ec,
2602
          offset: this.eo
2603
        }));
2604
        return textRange;
2605
      }
2606
    }
2607
  }, {
2608
    key: "getPoints",
2609
    value: function getPoints() {
2610
      return {
2611
        sc: this.sc,
2612
        so: this.so,
2613
        ec: this.ec,
2614
        eo: this.eo
2615
      };
2616
    }
2617
  }, {
2618
    key: "getStartPoint",
2619
    value: function getStartPoint() {
2620
      return {
2621
        node: this.sc,
2622
        offset: this.so
2623
      };
2624
    }
2625
  }, {
2626
    key: "getEndPoint",
2627
    value: function getEndPoint() {
2628
      return {
2629
        node: this.ec,
2630
        offset: this.eo
2631
      };
2632
    }
2633
    /**
2634
     * select update visible range
2635
     */
2636

2637
  }, {
2638
    key: "select",
2639
    value: function select() {
2640
      var nativeRng = this.nativeRange();
2641

2642
      if (env.isW3CRangeSupport) {
2643
        var selection = document.getSelection();
2644

2645
        if (selection.rangeCount > 0) {
2646
          selection.removeAllRanges();
2647
        }
2648

2649
        selection.addRange(nativeRng);
2650
      } else {
2651
        nativeRng.select();
2652
      }
2653

2654
      return this;
2655
    }
2656
    /**
2657
     * Moves the scrollbar to start container(sc) of current range
2658
     *
2659
     * @return {WrappedRange}
2660
     */
2661

2662
  }, {
2663
    key: "scrollIntoView",
2664
    value: function scrollIntoView(container) {
2665
      var height = external_jQuery_default()(container).height();
2666

2667
      if (container.scrollTop + height < this.sc.offsetTop) {
2668
        container.scrollTop += Math.abs(container.scrollTop + height - this.sc.offsetTop);
2669
      }
2670

2671
      return this;
2672
    }
2673
    /**
2674
     * @return {WrappedRange}
2675
     */
2676

2677
  }, {
2678
    key: "normalize",
2679
    value: function normalize() {
2680
      /**
2681
       * @param {BoundaryPoint} point
2682
       * @param {Boolean} isLeftToRight - true: prefer to choose right node
2683
       *                                - false: prefer to choose left node
2684
       * @return {BoundaryPoint}
2685
       */
2686
      var getVisiblePoint = function getVisiblePoint(point, isLeftToRight) {
2687
        if (!point) {
2688
          return point;
2689
        } // Just use the given point [XXX:Adhoc]
2690
        //  - case 01. if the point is on the middle of the node
2691
        //  - case 02. if the point is on the right edge and prefer to choose left node
2692
        //  - case 03. if the point is on the left edge and prefer to choose right node
2693
        //  - case 04. if the point is on the right edge and prefer to choose right node but the node is void
2694
        //  - case 05. if the point is on the left edge and prefer to choose left node but the node is void
2695
        //  - case 06. if the point is on the block node and there is no children
2696

2697

2698
        if (dom.isVisiblePoint(point)) {
2699
          if (!dom.isEdgePoint(point) || dom.isRightEdgePoint(point) && !isLeftToRight || dom.isLeftEdgePoint(point) && isLeftToRight || dom.isRightEdgePoint(point) && isLeftToRight && dom.isVoid(point.node.nextSibling) || dom.isLeftEdgePoint(point) && !isLeftToRight && dom.isVoid(point.node.previousSibling) || dom.isBlock(point.node) && dom.isEmpty(point.node)) {
2700
            return point;
2701
          }
2702
        } // point on block's edge
2703

2704

2705
        var block = dom.ancestor(point.node, dom.isBlock);
2706
        var hasRightNode = false;
2707

2708
        if (!hasRightNode) {
2709
          var prevPoint = dom.prevPoint(point) || {
2710
            node: null
2711
          };
2712
          hasRightNode = (dom.isLeftEdgePointOf(point, block) || dom.isVoid(prevPoint.node)) && !isLeftToRight;
2713
        }
2714

2715
        var hasLeftNode = false;
2716

2717
        if (!hasLeftNode) {
2718
          var _nextPoint = dom.nextPoint(point) || {
2719
            node: null
2720
          };
2721

2722
          hasLeftNode = (dom.isRightEdgePointOf(point, block) || dom.isVoid(_nextPoint.node)) && isLeftToRight;
2723
        }
2724

2725
        if (hasRightNode || hasLeftNode) {
2726
          // returns point already on visible point
2727
          if (dom.isVisiblePoint(point)) {
2728
            return point;
2729
          } // reverse direction
2730

2731

2732
          isLeftToRight = !isLeftToRight;
2733
        }
2734

2735
        var nextPoint = isLeftToRight ? dom.nextPointUntil(dom.nextPoint(point), dom.isVisiblePoint) : dom.prevPointUntil(dom.prevPoint(point), dom.isVisiblePoint);
2736
        return nextPoint || point;
2737
      };
2738

2739
      var endPoint = getVisiblePoint(this.getEndPoint(), false);
2740
      var startPoint = this.isCollapsed() ? endPoint : getVisiblePoint(this.getStartPoint(), true);
2741
      return new WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
2742
    }
2743
    /**
2744
     * returns matched nodes on range
2745
     *
2746
     * @param {Function} [pred] - predicate function
2747
     * @param {Object} [options]
2748
     * @param {Boolean} [options.includeAncestor]
2749
     * @param {Boolean} [options.fullyContains]
2750
     * @return {Node[]}
2751
     */
2752

2753
  }, {
2754
    key: "nodes",
2755
    value: function nodes(pred, options) {
2756
      pred = pred || func.ok;
2757
      var includeAncestor = options && options.includeAncestor;
2758
      var fullyContains = options && options.fullyContains; // TODO compare points and sort
2759

2760
      var startPoint = this.getStartPoint();
2761
      var endPoint = this.getEndPoint();
2762
      var nodes = [];
2763
      var leftEdgeNodes = [];
2764
      dom.walkPoint(startPoint, endPoint, function (point) {
2765
        if (dom.isEditable(point.node)) {
2766
          return;
2767
        }
2768

2769
        var node;
2770

2771
        if (fullyContains) {
2772
          if (dom.isLeftEdgePoint(point)) {
2773
            leftEdgeNodes.push(point.node);
2774
          }
2775

2776
          if (dom.isRightEdgePoint(point) && lists.contains(leftEdgeNodes, point.node)) {
2777
            node = point.node;
2778
          }
2779
        } else if (includeAncestor) {
2780
          node = dom.ancestor(point.node, pred);
2781
        } else {
2782
          node = point.node;
2783
        }
2784

2785
        if (node && pred(node)) {
2786
          nodes.push(node);
2787
        }
2788
      }, true);
2789
      return lists.unique(nodes);
2790
    }
2791
    /**
2792
     * returns commonAncestor of range
2793
     * @return {Element} - commonAncestor
2794
     */
2795

2796
  }, {
2797
    key: "commonAncestor",
2798
    value: function commonAncestor() {
2799
      return dom.commonAncestor(this.sc, this.ec);
2800
    }
2801
    /**
2802
     * returns expanded range by pred
2803
     *
2804
     * @param {Function} pred - predicate function
2805
     * @return {WrappedRange}
2806
     */
2807

2808
  }, {
2809
    key: "expand",
2810
    value: function expand(pred) {
2811
      var startAncestor = dom.ancestor(this.sc, pred);
2812
      var endAncestor = dom.ancestor(this.ec, pred);
2813

2814
      if (!startAncestor && !endAncestor) {
2815
        return new WrappedRange(this.sc, this.so, this.ec, this.eo);
2816
      }
2817

2818
      var boundaryPoints = this.getPoints();
2819

2820
      if (startAncestor) {
2821
        boundaryPoints.sc = startAncestor;
2822
        boundaryPoints.so = 0;
2823
      }
2824

2825
      if (endAncestor) {
2826
        boundaryPoints.ec = endAncestor;
2827
        boundaryPoints.eo = dom.nodeLength(endAncestor);
2828
      }
2829

2830
      return new WrappedRange(boundaryPoints.sc, boundaryPoints.so, boundaryPoints.ec, boundaryPoints.eo);
2831
    }
2832
    /**
2833
     * @param {Boolean} isCollapseToStart
2834
     * @return {WrappedRange}
2835
     */
2836

2837
  }, {
2838
    key: "collapse",
2839
    value: function collapse(isCollapseToStart) {
2840
      if (isCollapseToStart) {
2841
        return new WrappedRange(this.sc, this.so, this.sc, this.so);
2842
      } else {
2843
        return new WrappedRange(this.ec, this.eo, this.ec, this.eo);
2844
      }
2845
    }
2846
    /**
2847
     * splitText on range
2848
     */
2849

2850
  }, {
2851
    key: "splitText",
2852
    value: function splitText() {
2853
      var isSameContainer = this.sc === this.ec;
2854
      var boundaryPoints = this.getPoints();
2855

2856
      if (dom.isText(this.ec) && !dom.isEdgePoint(this.getEndPoint())) {
2857
        this.ec.splitText(this.eo);
2858
      }
2859

2860
      if (dom.isText(this.sc) && !dom.isEdgePoint(this.getStartPoint())) {
2861
        boundaryPoints.sc = this.sc.splitText(this.so);
2862
        boundaryPoints.so = 0;
2863

2864
        if (isSameContainer) {
2865
          boundaryPoints.ec = boundaryPoints.sc;
2866
          boundaryPoints.eo = this.eo - this.so;
2867
        }
2868
      }
2869

2870
      return new WrappedRange(boundaryPoints.sc, boundaryPoints.so, boundaryPoints.ec, boundaryPoints.eo);
2871
    }
2872
    /**
2873
     * delete contents on range
2874
     * @return {WrappedRange}
2875
     */
2876

2877
  }, {
2878
    key: "deleteContents",
2879
    value: function deleteContents() {
2880
      if (this.isCollapsed()) {
2881
        return this;
2882
      }
2883

2884
      var rng = this.splitText();
2885
      var nodes = rng.nodes(null, {
2886
        fullyContains: true
2887
      }); // find new cursor point
2888

2889
      var point = dom.prevPointUntil(rng.getStartPoint(), function (point) {
2890
        return !lists.contains(nodes, point.node);
2891
      });
2892
      var emptyParents = [];
2893
      external_jQuery_default().each(nodes, function (idx, node) {
2894
        // find empty parents
2895
        var parent = node.parentNode;
2896

2897
        if (point.node !== parent && dom.nodeLength(parent) === 1) {
2898
          emptyParents.push(parent);
2899
        }
2900

2901
        dom.remove(node, false);
2902
      }); // remove empty parents
2903

2904
      external_jQuery_default().each(emptyParents, function (idx, node) {
2905
        dom.remove(node, false);
2906
      });
2907
      return new WrappedRange(point.node, point.offset, point.node, point.offset).normalize();
2908
    }
2909
    /**
2910
     * makeIsOn: return isOn(pred) function
2911
     */
2912

2913
  }, {
2914
    key: "makeIsOn",
2915
    value: function makeIsOn(pred) {
2916
      return function () {
2917
        var ancestor = dom.ancestor(this.sc, pred);
2918
        return !!ancestor && ancestor === dom.ancestor(this.ec, pred);
2919
      };
2920
    }
2921
    /**
2922
     * @param {Function} pred
2923
     * @return {Boolean}
2924
     */
2925

2926
  }, {
2927
    key: "isLeftEdgeOf",
2928
    value: function isLeftEdgeOf(pred) {
2929
      if (!dom.isLeftEdgePoint(this.getStartPoint())) {
2930
        return false;
2931
      }
2932

2933
      var node = dom.ancestor(this.sc, pred);
2934
      return node && dom.isLeftEdgeOf(this.sc, node);
2935
    }
2936
    /**
2937
     * returns whether range was collapsed or not
2938
     */
2939

2940
  }, {
2941
    key: "isCollapsed",
2942
    value: function isCollapsed() {
2943
      return this.sc === this.ec && this.so === this.eo;
2944
    }
2945
    /**
2946
     * wrap inline nodes which children of body with paragraph
2947
     *
2948
     * @return {WrappedRange}
2949
     */
2950

2951
  }, {
2952
    key: "wrapBodyInlineWithPara",
2953
    value: function wrapBodyInlineWithPara() {
2954
      if (dom.isBodyContainer(this.sc) && dom.isEmpty(this.sc)) {
2955
        this.sc.innerHTML = dom.emptyPara;
2956
        return new WrappedRange(this.sc.firstChild, 0, this.sc.firstChild, 0);
2957
      }
2958
      /**
2959
       * [workaround] firefox often create range on not visible point. so normalize here.
2960
       *  - firefox: |<p>text</p>|
2961
       *  - chrome: <p>|text|</p>
2962
       */
2963

2964

2965
      var rng = this.normalize();
2966

2967
      if (dom.isParaInline(this.sc) || dom.isPara(this.sc)) {
2968
        return rng;
2969
      } // find inline top ancestor
2970

2971

2972
      var topAncestor;
2973

2974
      if (dom.isInline(rng.sc)) {
2975
        var ancestors = dom.listAncestor(rng.sc, func.not(dom.isInline));
2976
        topAncestor = lists.last(ancestors);
2977

2978
        if (!dom.isInline(topAncestor)) {
2979
          topAncestor = ancestors[ancestors.length - 2] || rng.sc.childNodes[rng.so];
2980
        }
2981
      } else {
2982
        topAncestor = rng.sc.childNodes[rng.so > 0 ? rng.so - 1 : 0];
2983
      }
2984

2985
      if (topAncestor) {
2986
        // siblings not in paragraph
2987
        var inlineSiblings = dom.listPrev(topAncestor, dom.isParaInline).reverse();
2988
        inlineSiblings = inlineSiblings.concat(dom.listNext(topAncestor.nextSibling, dom.isParaInline)); // wrap with paragraph
2989

2990
        if (inlineSiblings.length) {
2991
          var para = dom.wrap(lists.head(inlineSiblings), 'p');
2992
          dom.appendChildNodes(para, lists.tail(inlineSiblings));
2993
        }
2994
      }
2995

2996
      return this.normalize();
2997
    }
2998
    /**
2999
     * insert node at current cursor
3000
     *
3001
     * @param {Node} node
3002
     * @return {Node}
3003
     */
3004

3005
  }, {
3006
    key: "insertNode",
3007
    value: function insertNode(node) {
3008
      var rng = this;
3009

3010
      if (dom.isText(node) || dom.isInline(node)) {
3011
        rng = this.wrapBodyInlineWithPara().deleteContents();
3012
      }
3013

3014
      var info = dom.splitPoint(rng.getStartPoint(), dom.isInline(node));
3015

3016
      if (info.rightNode) {
3017
        info.rightNode.parentNode.insertBefore(node, info.rightNode);
3018

3019
        if (dom.isEmpty(info.rightNode) && dom.isPara(node)) {
3020
          info.rightNode.parentNode.removeChild(info.rightNode);
3021
        }
3022
      } else {
3023
        info.container.appendChild(node);
3024
      }
3025

3026
      return node;
3027
    }
3028
    /**
3029
     * insert html at current cursor
3030
     */
3031

3032
  }, {
3033
    key: "pasteHTML",
3034
    value: function pasteHTML(markup) {
3035
      markup = external_jQuery_default().trim(markup);
3036
      var contentsContainer = external_jQuery_default()('<div></div>').html(markup)[0];
3037
      var childNodes = lists.from(contentsContainer.childNodes); // const rng = this.wrapBodyInlineWithPara().deleteContents();
3038

3039
      var rng = this;
3040
      var reversed = false;
3041

3042
      if (rng.so >= 0) {
3043
        childNodes = childNodes.reverse();
3044
        reversed = true;
3045
      }
3046

3047
      childNodes = childNodes.map(function (childNode) {
3048
        return rng.insertNode(childNode);
3049
      });
3050

3051
      if (reversed) {
3052
        childNodes = childNodes.reverse();
3053
      }
3054

3055
      return childNodes;
3056
    }
3057
    /**
3058
     * returns text in range
3059
     *
3060
     * @return {String}
3061
     */
3062

3063
  }, {
3064
    key: "toString",
3065
    value: function toString() {
3066
      var nativeRng = this.nativeRange();
3067
      return env.isW3CRangeSupport ? nativeRng.toString() : nativeRng.text;
3068
    }
3069
    /**
3070
     * returns range for word before cursor
3071
     *
3072
     * @param {Boolean} [findAfter] - find after cursor, default: false
3073
     * @return {WrappedRange}
3074
     */
3075

3076
  }, {
3077
    key: "getWordRange",
3078
    value: function getWordRange(findAfter) {
3079
      var endPoint = this.getEndPoint();
3080

3081
      if (!dom.isCharPoint(endPoint)) {
3082
        return this;
3083
      }
3084

3085
      var startPoint = dom.prevPointUntil(endPoint, function (point) {
3086
        return !dom.isCharPoint(point);
3087
      });
3088

3089
      if (findAfter) {
3090
        endPoint = dom.nextPointUntil(endPoint, function (point) {
3091
          return !dom.isCharPoint(point);
3092
        });
3093
      }
3094

3095
      return new WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
3096
    }
3097
    /**
3098
     * returns range for words before cursor
3099
     *
3100
     * @param {Boolean} [findAfter] - find after cursor, default: false
3101
     * @return {WrappedRange}
3102
     */
3103

3104
  }, {
3105
    key: "getWordsRange",
3106
    value: function getWordsRange(findAfter) {
3107
      var endPoint = this.getEndPoint();
3108

3109
      var isNotTextPoint = function isNotTextPoint(point) {
3110
        return !dom.isCharPoint(point) && !dom.isSpacePoint(point);
3111
      };
3112

3113
      if (isNotTextPoint(endPoint)) {
3114
        return this;
3115
      }
3116

3117
      var startPoint = dom.prevPointUntil(endPoint, isNotTextPoint);
3118

3119
      if (findAfter) {
3120
        endPoint = dom.nextPointUntil(endPoint, isNotTextPoint);
3121
      }
3122

3123
      return new WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
3124
    }
3125
    /**
3126
     * returns range for words before cursor that match with a Regex
3127
     *
3128
     * example:
3129
     *  range: 'hi @Peter Pan'
3130
     *  regex: '/@[a-z ]+/i'
3131
     *  return range: '@Peter Pan'
3132
     *
3133
     * @param {RegExp} [regex]
3134
     * @return {WrappedRange|null}
3135
     */
3136

3137
  }, {
3138
    key: "getWordsMatchRange",
3139
    value: function getWordsMatchRange(regex) {
3140
      var endPoint = this.getEndPoint();
3141
      var startPoint = dom.prevPointUntil(endPoint, function (point) {
3142
        if (!dom.isCharPoint(point) && !dom.isSpacePoint(point)) {
3143
          return true;
3144
        }
3145

3146
        var rng = new WrappedRange(point.node, point.offset, endPoint.node, endPoint.offset);
3147
        var result = regex.exec(rng.toString());
3148
        return result && result.index === 0;
3149
      });
3150
      var rng = new WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
3151
      var text = rng.toString();
3152
      var result = regex.exec(text);
3153

3154
      if (result && result[0].length === text.length) {
3155
        return rng;
3156
      } else {
3157
        return null;
3158
      }
3159
    }
3160
    /**
3161
     * create offsetPath bookmark
3162
     *
3163
     * @param {Node} editable
3164
     */
3165

3166
  }, {
3167
    key: "bookmark",
3168
    value: function bookmark(editable) {
3169
      return {
3170
        s: {
3171
          path: dom.makeOffsetPath(editable, this.sc),
3172
          offset: this.so
3173
        },
3174
        e: {
3175
          path: dom.makeOffsetPath(editable, this.ec),
3176
          offset: this.eo
3177
        }
3178
      };
3179
    }
3180
    /**
3181
     * create offsetPath bookmark base on paragraph
3182
     *
3183
     * @param {Node[]} paras
3184
     */
3185

3186
  }, {
3187
    key: "paraBookmark",
3188
    value: function paraBookmark(paras) {
3189
      return {
3190
        s: {
3191
          path: lists.tail(dom.makeOffsetPath(lists.head(paras), this.sc)),
3192
          offset: this.so
3193
        },
3194
        e: {
3195
          path: lists.tail(dom.makeOffsetPath(lists.last(paras), this.ec)),
3196
          offset: this.eo
3197
        }
3198
      };
3199
    }
3200
    /**
3201
     * getClientRects
3202
     * @return {Rect[]}
3203
     */
3204

3205
  }, {
3206
    key: "getClientRects",
3207
    value: function getClientRects() {
3208
      var nativeRng = this.nativeRange();
3209
      return nativeRng.getClientRects();
3210
    }
3211
  }]);
3212

3213
  return WrappedRange;
3214
}();
3215
/**
3216
 * Data structure
3217
 *  * BoundaryPoint: a point of dom tree
3218
 *  * BoundaryPoints: two boundaryPoints corresponding to the start and the end of the Range
3219
 *
3220
 * See to http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Position
3221
 */
3222

3223

3224
/* harmony default export */ const range = ({
3225
  /**
3226
   * create Range Object From arguments or Browser Selection
3227
   *
3228
   * @param {Node} sc - start container
3229
   * @param {Number} so - start offset
3230
   * @param {Node} ec - end container
3231
   * @param {Number} eo - end offset
3232
   * @return {WrappedRange}
3233
   */
3234
  create: function create(sc, so, ec, eo) {
3235
    if (arguments.length === 4) {
3236
      return new WrappedRange(sc, so, ec, eo);
3237
    } else if (arguments.length === 2) {
3238
      // collapsed
3239
      ec = sc;
3240
      eo = so;
3241
      return new WrappedRange(sc, so, ec, eo);
3242
    } else {
3243
      var wrappedRange = this.createFromSelection();
3244

3245
      if (!wrappedRange && arguments.length === 1) {
3246
        var bodyElement = arguments[0];
3247

3248
        if (dom.isEditable(bodyElement)) {
3249
          bodyElement = bodyElement.lastChild;
3250
        }
3251

3252
        return this.createFromBodyElement(bodyElement, dom.emptyPara === arguments[0].innerHTML);
3253
      }
3254

3255
      return wrappedRange;
3256
    }
3257
  },
3258
  createFromBodyElement: function createFromBodyElement(bodyElement) {
3259
    var isCollapseToStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3260
    var wrappedRange = this.createFromNode(bodyElement);
3261
    return wrappedRange.collapse(isCollapseToStart);
3262
  },
3263
  createFromSelection: function createFromSelection() {
3264
    var sc, so, ec, eo;
3265

3266
    if (env.isW3CRangeSupport) {
3267
      var selection = document.getSelection();
3268

3269
      if (!selection || selection.rangeCount === 0) {
3270
        return null;
3271
      } else if (dom.isBody(selection.anchorNode)) {
3272
        // Firefox: returns entire body as range on initialization.
3273
        // We won't never need it.
3274
        return null;
3275
      }
3276

3277
      var nativeRng = selection.getRangeAt(0);
3278
      sc = nativeRng.startContainer;
3279
      so = nativeRng.startOffset;
3280
      ec = nativeRng.endContainer;
3281
      eo = nativeRng.endOffset;
3282
    } else {
3283
      // IE8: TextRange
3284
      var textRange = document.selection.createRange();
3285
      var textRangeEnd = textRange.duplicate();
3286
      textRangeEnd.collapse(false);
3287
      var textRangeStart = textRange;
3288
      textRangeStart.collapse(true);
3289
      var startPoint = textRangeToPoint(textRangeStart, true);
3290
      var endPoint = textRangeToPoint(textRangeEnd, false); // same visible point case: range was collapsed.
3291

3292
      if (dom.isText(startPoint.node) && dom.isLeftEdgePoint(startPoint) && dom.isTextNode(endPoint.node) && dom.isRightEdgePoint(endPoint) && endPoint.node.nextSibling === startPoint.node) {
3293
        startPoint = endPoint;
3294
      }
3295

3296
      sc = startPoint.cont;
3297
      so = startPoint.offset;
3298
      ec = endPoint.cont;
3299
      eo = endPoint.offset;
3300
    }
3301

3302
    return new WrappedRange(sc, so, ec, eo);
3303
  },
3304

3305
  /**
3306
   * @method
3307
   *
3308
   * create WrappedRange from node
3309
   *
3310
   * @param {Node} node
3311
   * @return {WrappedRange}
3312
   */
3313
  createFromNode: function createFromNode(node) {
3314
    var sc = node;
3315
    var so = 0;
3316
    var ec = node;
3317
    var eo = dom.nodeLength(ec); // browsers can't target a picture or void node
3318

3319
    if (dom.isVoid(sc)) {
3320
      so = dom.listPrev(sc).length - 1;
3321
      sc = sc.parentNode;
3322
    }
3323

3324
    if (dom.isBR(ec)) {
3325
      eo = dom.listPrev(ec).length - 1;
3326
      ec = ec.parentNode;
3327
    } else if (dom.isVoid(ec)) {
3328
      eo = dom.listPrev(ec).length;
3329
      ec = ec.parentNode;
3330
    }
3331

3332
    return this.create(sc, so, ec, eo);
3333
  },
3334

3335
  /**
3336
   * create WrappedRange from node after position
3337
   *
3338
   * @param {Node} node
3339
   * @return {WrappedRange}
3340
   */
3341
  createFromNodeBefore: function createFromNodeBefore(node) {
3342
    return this.createFromNode(node).collapse(true);
3343
  },
3344

3345
  /**
3346
   * create WrappedRange from node after position
3347
   *
3348
   * @param {Node} node
3349
   * @return {WrappedRange}
3350
   */
3351
  createFromNodeAfter: function createFromNodeAfter(node) {
3352
    return this.createFromNode(node).collapse();
3353
  },
3354

3355
  /**
3356
   * @method
3357
   *
3358
   * create WrappedRange from bookmark
3359
   *
3360
   * @param {Node} editable
3361
   * @param {Object} bookmark
3362
   * @return {WrappedRange}
3363
   */
3364
  createFromBookmark: function createFromBookmark(editable, bookmark) {
3365
    var sc = dom.fromOffsetPath(editable, bookmark.s.path);
3366
    var so = bookmark.s.offset;
3367
    var ec = dom.fromOffsetPath(editable, bookmark.e.path);
3368
    var eo = bookmark.e.offset;
3369
    return new WrappedRange(sc, so, ec, eo);
3370
  },
3371

3372
  /**
3373
   * @method
3374
   *
3375
   * create WrappedRange from paraBookmark
3376
   *
3377
   * @param {Object} bookmark
3378
   * @param {Node[]} paras
3379
   * @return {WrappedRange}
3380
   */
3381
  createFromParaBookmark: function createFromParaBookmark(bookmark, paras) {
3382
    var so = bookmark.s.offset;
3383
    var eo = bookmark.e.offset;
3384
    var sc = dom.fromOffsetPath(lists.head(paras), bookmark.s.path);
3385
    var ec = dom.fromOffsetPath(lists.last(paras), bookmark.e.path);
3386
    return new WrappedRange(sc, so, ec, eo);
3387
  }
3388
});
3389
;// CONCATENATED MODULE: ./src/js/core/key.js
3390

3391

3392
var KEY_MAP = {
3393
  'BACKSPACE': 8,
3394
  'TAB': 9,
3395
  'ENTER': 13,
3396
  'ESCAPE': 27,
3397
  'SPACE': 32,
3398
  'DELETE': 46,
3399
  // Arrow
3400
  'LEFT': 37,
3401
  'UP': 38,
3402
  'RIGHT': 39,
3403
  'DOWN': 40,
3404
  // Number: 0-9
3405
  'NUM0': 48,
3406
  'NUM1': 49,
3407
  'NUM2': 50,
3408
  'NUM3': 51,
3409
  'NUM4': 52,
3410
  'NUM5': 53,
3411
  'NUM6': 54,
3412
  'NUM7': 55,
3413
  'NUM8': 56,
3414
  // Alphabet: a-z
3415
  'B': 66,
3416
  'E': 69,
3417
  'I': 73,
3418
  'J': 74,
3419
  'K': 75,
3420
  'L': 76,
3421
  'R': 82,
3422
  'S': 83,
3423
  'U': 85,
3424
  'V': 86,
3425
  'Y': 89,
3426
  'Z': 90,
3427
  'SLASH': 191,
3428
  'LEFTBRACKET': 219,
3429
  'BACKSLASH': 220,
3430
  'RIGHTBRACKET': 221,
3431
  // Navigation
3432
  'HOME': 36,
3433
  'END': 35,
3434
  'PAGEUP': 33,
3435
  'PAGEDOWN': 34
3436
};
3437
/**
3438
 * @class core.key
3439
 *
3440
 * Object for keycodes.
3441
 *
3442
 * @singleton
3443
 * @alternateClassName key
3444
 */
3445

3446
/* harmony default export */ const key = ({
3447
  /**
3448
   * @method isEdit
3449
   *
3450
   * @param {Number} keyCode
3451
   * @return {Boolean}
3452
   */
3453
  isEdit: function isEdit(keyCode) {
3454
    return lists.contains([KEY_MAP.BACKSPACE, KEY_MAP.TAB, KEY_MAP.ENTER, KEY_MAP.SPACE, KEY_MAP.DELETE], keyCode);
3455
  },
3456

3457
  /**
3458
   * @method isMove
3459
   *
3460
   * @param {Number} keyCode
3461
   * @return {Boolean}
3462
   */
3463
  isMove: function isMove(keyCode) {
3464
    return lists.contains([KEY_MAP.LEFT, KEY_MAP.UP, KEY_MAP.RIGHT, KEY_MAP.DOWN], keyCode);
3465
  },
3466

3467
  /**
3468
   * @method isNavigation
3469
   *
3470
   * @param {Number} keyCode
3471
   * @return {Boolean}
3472
   */
3473
  isNavigation: function isNavigation(keyCode) {
3474
    return lists.contains([KEY_MAP.HOME, KEY_MAP.END, KEY_MAP.PAGEUP, KEY_MAP.PAGEDOWN], keyCode);
3475
  },
3476

3477
  /**
3478
   * @property {Object} nameFromCode
3479
   * @property {String} nameFromCode.8 "BACKSPACE"
3480
   */
3481
  nameFromCode: func.invertObject(KEY_MAP),
3482
  code: KEY_MAP
3483
});
3484
;// CONCATENATED MODULE: ./src/js/core/async.js
3485

3486
/**
3487
 * @method readFileAsDataURL
3488
 *
3489
 * read contents of file as representing URL
3490
 *
3491
 * @param {File} file
3492
 * @return {Promise} - then: dataUrl
3493
 */
3494

3495
function readFileAsDataURL(file) {
3496
  return external_jQuery_default().Deferred(function (deferred) {
3497
    external_jQuery_default().extend(new FileReader(), {
3498
      onload: function onload(e) {
3499
        var dataURL = e.target.result;
3500
        deferred.resolve(dataURL);
3501
      },
3502
      onerror: function onerror(err) {
3503
        deferred.reject(err);
3504
      }
3505
    }).readAsDataURL(file);
3506
  }).promise();
3507
}
3508
/**
3509
 * @method createImage
3510
 *
3511
 * create `<image>` from url string
3512
 *
3513
 * @param {String} url
3514
 * @return {Promise} - then: $image
3515
 */
3516

3517
function createImage(url) {
3518
  return external_jQuery_default().Deferred(function (deferred) {
3519
    var $img = external_jQuery_default()('<img>');
3520
    $img.one('load', function () {
3521
      $img.off('error abort');
3522
      deferred.resolve($img);
3523
    }).one('error abort', function () {
3524
      $img.off('load').detach();
3525
      deferred.reject($img);
3526
    }).css({
3527
      display: 'none'
3528
    }).appendTo(document.body).attr('src', url);
3529
  }).promise();
3530
}
3531
;// CONCATENATED MODULE: ./src/js/editing/History.js
3532
function History_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3533

3534
function History_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3535

3536
function History_createClass(Constructor, protoProps, staticProps) { if (protoProps) History_defineProperties(Constructor.prototype, protoProps); if (staticProps) History_defineProperties(Constructor, staticProps); return Constructor; }
3537

3538

3539

3540
var History = /*#__PURE__*/function () {
3541
  function History(context) {
3542
    History_classCallCheck(this, History);
3543

3544
    this.stack = [];
3545
    this.stackOffset = -1;
3546
    this.context = context;
3547
    this.$editable = context.layoutInfo.editable;
3548
    this.editable = this.$editable[0];
3549
  }
3550

3551
  History_createClass(History, [{
3552
    key: "makeSnapshot",
3553
    value: function makeSnapshot() {
3554
      var rng = range.create(this.editable);
3555
      var emptyBookmark = {
3556
        s: {
3557
          path: [],
3558
          offset: 0
3559
        },
3560
        e: {
3561
          path: [],
3562
          offset: 0
3563
        }
3564
      };
3565
      return {
3566
        contents: this.$editable.html(),
3567
        bookmark: rng && rng.isOnEditable() ? rng.bookmark(this.editable) : emptyBookmark
3568
      };
3569
    }
3570
  }, {
3571
    key: "applySnapshot",
3572
    value: function applySnapshot(snapshot) {
3573
      if (snapshot.contents !== null) {
3574
        this.$editable.html(snapshot.contents);
3575
      }
3576

3577
      if (snapshot.bookmark !== null) {
3578
        range.createFromBookmark(this.editable, snapshot.bookmark).select();
3579
      }
3580
    }
3581
    /**
3582
    * @method rewind
3583
    * Rewinds the history stack back to the first snapshot taken.
3584
    * Leaves the stack intact, so that "Redo" can still be used.
3585
    */
3586

3587
  }, {
3588
    key: "rewind",
3589
    value: function rewind() {
3590
      // Create snap shot if not yet recorded
3591
      if (this.$editable.html() !== this.stack[this.stackOffset].contents) {
3592
        this.recordUndo();
3593
      } // Return to the first available snapshot.
3594

3595

3596
      this.stackOffset = 0; // Apply that snapshot.
3597

3598
      this.applySnapshot(this.stack[this.stackOffset]);
3599
    }
3600
    /**
3601
    *  @method commit
3602
    *  Resets history stack, but keeps current editor's content.
3603
    */
3604

3605
  }, {
3606
    key: "commit",
3607
    value: function commit() {
3608
      // Clear the stack.
3609
      this.stack = []; // Restore stackOffset to its original value.
3610

3611
      this.stackOffset = -1; // Record our first snapshot (of nothing).
3612

3613
      this.recordUndo();
3614
    }
3615
    /**
3616
    * @method reset
3617
    * Resets the history stack completely; reverting to an empty editor.
3618
    */
3619

3620
  }, {
3621
    key: "reset",
3622
    value: function reset() {
3623
      // Clear the stack.
3624
      this.stack = []; // Restore stackOffset to its original value.
3625

3626
      this.stackOffset = -1; // Clear the editable area.
3627

3628
      this.$editable.html(''); // Record our first snapshot (of nothing).
3629

3630
      this.recordUndo();
3631
    }
3632
    /**
3633
     * undo
3634
     */
3635

3636
  }, {
3637
    key: "undo",
3638
    value: function undo() {
3639
      // Create snap shot if not yet recorded
3640
      if (this.$editable.html() !== this.stack[this.stackOffset].contents) {
3641
        this.recordUndo();
3642
      }
3643

3644
      if (this.stackOffset > 0) {
3645
        this.stackOffset--;
3646
        this.applySnapshot(this.stack[this.stackOffset]);
3647
      }
3648
    }
3649
    /**
3650
     * redo
3651
     */
3652

3653
  }, {
3654
    key: "redo",
3655
    value: function redo() {
3656
      if (this.stack.length - 1 > this.stackOffset) {
3657
        this.stackOffset++;
3658
        this.applySnapshot(this.stack[this.stackOffset]);
3659
      }
3660
    }
3661
    /**
3662
     * recorded undo
3663
     */
3664

3665
  }, {
3666
    key: "recordUndo",
3667
    value: function recordUndo() {
3668
      this.stackOffset++; // Wash out stack after stackOffset
3669

3670
      if (this.stack.length > this.stackOffset) {
3671
        this.stack = this.stack.slice(0, this.stackOffset);
3672
      } // Create new snapshot and push it to the end
3673

3674

3675
      this.stack.push(this.makeSnapshot()); // If the stack size reachs to the limit, then slice it
3676

3677
      if (this.stack.length > this.context.options.historyLimit) {
3678
        this.stack.shift();
3679
        this.stackOffset -= 1;
3680
      }
3681
    }
3682
  }]);
3683

3684
  return History;
3685
}();
3686

3687

3688
;// CONCATENATED MODULE: ./src/js/editing/Style.js
3689
function Style_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3690

3691
function Style_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3692

3693
function Style_createClass(Constructor, protoProps, staticProps) { if (protoProps) Style_defineProperties(Constructor.prototype, protoProps); if (staticProps) Style_defineProperties(Constructor, staticProps); return Constructor; }
3694

3695

3696

3697

3698

3699

3700
var Style = /*#__PURE__*/function () {
3701
  function Style() {
3702
    Style_classCallCheck(this, Style);
3703
  }
3704

3705
  Style_createClass(Style, [{
3706
    key: "jQueryCSS",
3707
    value:
3708
    /**
3709
     * @method jQueryCSS
3710
     *
3711
     * [workaround] for old jQuery
3712
     * passing an array of style properties to .css()
3713
     * will result in an object of property-value pairs.
3714
     * (compability with version < 1.9)
3715
     *
3716
     * @private
3717
     * @param  {jQuery} $obj
3718
     * @param  {Array} propertyNames - An array of one or more CSS properties.
3719
     * @return {Object}
3720
     */
3721
    function jQueryCSS($obj, propertyNames) {
3722
      var result = {};
3723
      external_jQuery_default().each(propertyNames, function (idx, propertyName) {
3724
        result[propertyName] = $obj.css(propertyName);
3725
      });
3726
      return result;
3727
    }
3728
    /**
3729
     * returns style object from node
3730
     *
3731
     * @param {jQuery} $node
3732
     * @return {Object}
3733
     */
3734

3735
  }, {
3736
    key: "fromNode",
3737
    value: function fromNode($node) {
3738
      var properties = ['font-family', 'font-size', 'text-align', 'list-style-type', 'line-height'];
3739
      var styleInfo = this.jQueryCSS($node, properties) || {};
3740
      var fontSize = $node[0].style.fontSize || styleInfo['font-size'];
3741
      styleInfo['font-size'] = parseInt(fontSize, 10);
3742
      styleInfo['font-size-unit'] = fontSize.match(/[a-z%]+$/);
3743
      return styleInfo;
3744
    }
3745
    /**
3746
     * paragraph level style
3747
     *
3748
     * @param {WrappedRange} rng
3749
     * @param {Object} styleInfo
3750
     */
3751

3752
  }, {
3753
    key: "stylePara",
3754
    value: function stylePara(rng, styleInfo) {
3755
      external_jQuery_default().each(rng.nodes(dom.isPara, {
3756
        includeAncestor: true
3757
      }), function (idx, para) {
3758
        external_jQuery_default()(para).css(styleInfo);
3759
      });
3760
    }
3761
    /**
3762
     * insert and returns styleNodes on range.
3763
     *
3764
     * @param {WrappedRange} rng
3765
     * @param {Object} [options] - options for styleNodes
3766
     * @param {String} [options.nodeName] - default: `SPAN`
3767
     * @param {Boolean} [options.expandClosestSibling] - default: `false`
3768
     * @param {Boolean} [options.onlyPartialContains] - default: `false`
3769
     * @return {Node[]}
3770
     */
3771

3772
  }, {
3773
    key: "styleNodes",
3774
    value: function styleNodes(rng, options) {
3775
      rng = rng.splitText();
3776
      var nodeName = options && options.nodeName || 'SPAN';
3777
      var expandClosestSibling = !!(options && options.expandClosestSibling);
3778
      var onlyPartialContains = !!(options && options.onlyPartialContains);
3779

3780
      if (rng.isCollapsed()) {
3781
        return [rng.insertNode(dom.create(nodeName))];
3782
      }
3783

3784
      var pred = dom.makePredByNodeName(nodeName);
3785
      var nodes = rng.nodes(dom.isText, {
3786
        fullyContains: true
3787
      }).map(function (text) {
3788
        return dom.singleChildAncestor(text, pred) || dom.wrap(text, nodeName);
3789
      });
3790

3791
      if (expandClosestSibling) {
3792
        if (onlyPartialContains) {
3793
          var nodesInRange = rng.nodes(); // compose with partial contains predication
3794

3795
          pred = func.and(pred, function (node) {
3796
            return lists.contains(nodesInRange, node);
3797
          });
3798
        }
3799

3800
        return nodes.map(function (node) {
3801
          var siblings = dom.withClosestSiblings(node, pred);
3802
          var head = lists.head(siblings);
3803
          var tails = lists.tail(siblings);
3804
          external_jQuery_default().each(tails, function (idx, elem) {
3805
            dom.appendChildNodes(head, elem.childNodes);
3806
            dom.remove(elem);
3807
          });
3808
          return lists.head(siblings);
3809
        });
3810
      } else {
3811
        return nodes;
3812
      }
3813
    }
3814
    /**
3815
     * get current style on cursor
3816
     *
3817
     * @param {WrappedRange} rng
3818
     * @return {Object} - object contains style properties.
3819
     */
3820

3821
  }, {
3822
    key: "current",
3823
    value: function current(rng) {
3824
      var $cont = external_jQuery_default()(!dom.isElement(rng.sc) ? rng.sc.parentNode : rng.sc);
3825
      var styleInfo = this.fromNode($cont); // document.queryCommandState for toggle state
3826
      // [workaround] prevent Firefox nsresult: "0x80004005 (NS_ERROR_FAILURE)"
3827

3828
      try {
3829
        styleInfo = external_jQuery_default().extend(styleInfo, {
3830
          'font-bold': document.queryCommandState('bold') ? 'bold' : 'normal',
3831
          'font-italic': document.queryCommandState('italic') ? 'italic' : 'normal',
3832
          'font-underline': document.queryCommandState('underline') ? 'underline' : 'normal',
3833
          'font-subscript': document.queryCommandState('subscript') ? 'subscript' : 'normal',
3834
          'font-superscript': document.queryCommandState('superscript') ? 'superscript' : 'normal',
3835
          'font-strikethrough': document.queryCommandState('strikethrough') ? 'strikethrough' : 'normal',
3836
          'font-family': document.queryCommandValue('fontname') || styleInfo['font-family']
3837
        });
3838
      } catch (e) {// eslint-disable-next-line
3839
      } // list-style-type to list-style(unordered, ordered)
3840

3841

3842
      if (!rng.isOnList()) {
3843
        styleInfo['list-style'] = 'none';
3844
      } else {
3845
        var orderedTypes = ['circle', 'disc', 'disc-leading-zero', 'square'];
3846
        var isUnordered = orderedTypes.indexOf(styleInfo['list-style-type']) > -1;
3847
        styleInfo['list-style'] = isUnordered ? 'unordered' : 'ordered';
3848
      }
3849

3850
      var para = dom.ancestor(rng.sc, dom.isPara);
3851

3852
      if (para && para.style['line-height']) {
3853
        styleInfo['line-height'] = para.style.lineHeight;
3854
      } else {
3855
        var lineHeight = parseInt(styleInfo['line-height'], 10) / parseInt(styleInfo['font-size'], 10);
3856
        styleInfo['line-height'] = lineHeight.toFixed(1);
3857
      }
3858

3859
      styleInfo.anchor = rng.isOnAnchor() && dom.ancestor(rng.sc, dom.isAnchor);
3860
      styleInfo.ancestors = dom.listAncestor(rng.sc, dom.isEditable);
3861
      styleInfo.range = rng;
3862
      return styleInfo;
3863
    }
3864
  }]);
3865

3866
  return Style;
3867
}();
3868

3869

3870
;// CONCATENATED MODULE: ./src/js/editing/Bullet.js
3871
function Bullet_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3872

3873
function Bullet_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3874

3875
function Bullet_createClass(Constructor, protoProps, staticProps) { if (protoProps) Bullet_defineProperties(Constructor.prototype, protoProps); if (staticProps) Bullet_defineProperties(Constructor, staticProps); return Constructor; }
3876

3877

3878

3879

3880

3881

3882

3883
var Bullet = /*#__PURE__*/function () {
3884
  function Bullet() {
3885
    Bullet_classCallCheck(this, Bullet);
3886
  }
3887

3888
  Bullet_createClass(Bullet, [{
3889
    key: "insertOrderedList",
3890
    value:
3891
    /**
3892
     * toggle ordered list
3893
     */
3894
    function insertOrderedList(editable) {
3895
      this.toggleList('OL', editable);
3896
    }
3897
    /**
3898
     * toggle unordered list
3899
     */
3900

3901
  }, {
3902
    key: "insertUnorderedList",
3903
    value: function insertUnorderedList(editable) {
3904
      this.toggleList('UL', editable);
3905
    }
3906
    /**
3907
     * indent
3908
     */
3909

3910
  }, {
3911
    key: "indent",
3912
    value: function indent(editable) {
3913
      var _this = this;
3914

3915
      var rng = range.create(editable).wrapBodyInlineWithPara();
3916
      var paras = rng.nodes(dom.isPara, {
3917
        includeAncestor: true
3918
      });
3919
      var clustereds = lists.clusterBy(paras, func.peq2('parentNode'));
3920
      external_jQuery_default().each(clustereds, function (idx, paras) {
3921
        var head = lists.head(paras);
3922

3923
        if (dom.isLi(head)) {
3924
          var previousList = _this.findList(head.previousSibling);
3925

3926
          if (previousList) {
3927
            paras.map(function (para) {
3928
              return previousList.appendChild(para);
3929
            });
3930
          } else {
3931
            _this.wrapList(paras, head.parentNode.nodeName);
3932

3933
            paras.map(function (para) {
3934
              return para.parentNode;
3935
            }).map(function (para) {
3936
              return _this.appendToPrevious(para);
3937
            });
3938
          }
3939
        } else {
3940
          external_jQuery_default().each(paras, function (idx, para) {
3941
            external_jQuery_default()(para).css('marginLeft', function (idx, val) {
3942
              return (parseInt(val, 10) || 0) + 25;
3943
            });
3944
          });
3945
        }
3946
      });
3947
      rng.select();
3948
    }
3949
    /**
3950
     * outdent
3951
     */
3952

3953
  }, {
3954
    key: "outdent",
3955
    value: function outdent(editable) {
3956
      var _this2 = this;
3957

3958
      var rng = range.create(editable).wrapBodyInlineWithPara();
3959
      var paras = rng.nodes(dom.isPara, {
3960
        includeAncestor: true
3961
      });
3962
      var clustereds = lists.clusterBy(paras, func.peq2('parentNode'));
3963
      external_jQuery_default().each(clustereds, function (idx, paras) {
3964
        var head = lists.head(paras);
3965

3966
        if (dom.isLi(head)) {
3967
          _this2.releaseList([paras]);
3968
        } else {
3969
          external_jQuery_default().each(paras, function (idx, para) {
3970
            external_jQuery_default()(para).css('marginLeft', function (idx, val) {
3971
              val = parseInt(val, 10) || 0;
3972
              return val > 25 ? val - 25 : '';
3973
            });
3974
          });
3975
        }
3976
      });
3977
      rng.select();
3978
    }
3979
    /**
3980
     * toggle list
3981
     *
3982
     * @param {String} listName - OL or UL
3983
     */
3984

3985
  }, {
3986
    key: "toggleList",
3987
    value: function toggleList(listName, editable) {
3988
      var _this3 = this;
3989

3990
      var rng = range.create(editable).wrapBodyInlineWithPara();
3991
      var paras = rng.nodes(dom.isPara, {
3992
        includeAncestor: true
3993
      });
3994
      var bookmark = rng.paraBookmark(paras);
3995
      var clustereds = lists.clusterBy(paras, func.peq2('parentNode')); // paragraph to list
3996

3997
      if (lists.find(paras, dom.isPurePara)) {
3998
        var wrappedParas = [];
3999
        external_jQuery_default().each(clustereds, function (idx, paras) {
4000
          wrappedParas = wrappedParas.concat(_this3.wrapList(paras, listName));
4001
        });
4002
        paras = wrappedParas; // list to paragraph or change list style
4003
      } else {
4004
        var diffLists = rng.nodes(dom.isList, {
4005
          includeAncestor: true
4006
        }).filter(function (listNode) {
4007
          return !external_jQuery_default().nodeName(listNode, listName);
4008
        });
4009

4010
        if (diffLists.length) {
4011
          external_jQuery_default().each(diffLists, function (idx, listNode) {
4012
            dom.replace(listNode, listName);
4013
          });
4014
        } else {
4015
          paras = this.releaseList(clustereds, true);
4016
        }
4017
      }
4018

4019
      range.createFromParaBookmark(bookmark, paras).select();
4020
    }
4021
    /**
4022
     * @param {Node[]} paras
4023
     * @param {String} listName
4024
     * @return {Node[]}
4025
     */
4026

4027
  }, {
4028
    key: "wrapList",
4029
    value: function wrapList(paras, listName) {
4030
      var head = lists.head(paras);
4031
      var last = lists.last(paras);
4032
      var prevList = dom.isList(head.previousSibling) && head.previousSibling;
4033
      var nextList = dom.isList(last.nextSibling) && last.nextSibling;
4034
      var listNode = prevList || dom.insertAfter(dom.create(listName || 'UL'), last); // P to LI
4035

4036
      paras = paras.map(function (para) {
4037
        return dom.isPurePara(para) ? dom.replace(para, 'LI') : para;
4038
      }); // append to list(<ul>, <ol>)
4039

4040
      dom.appendChildNodes(listNode, paras);
4041

4042
      if (nextList) {
4043
        dom.appendChildNodes(listNode, lists.from(nextList.childNodes));
4044
        dom.remove(nextList);
4045
      }
4046

4047
      return paras;
4048
    }
4049
    /**
4050
     * @method releaseList
4051
     *
4052
     * @param {Array[]} clustereds
4053
     * @param {Boolean} isEscapseToBody
4054
     * @return {Node[]}
4055
     */
4056

4057
  }, {
4058
    key: "releaseList",
4059
    value: function releaseList(clustereds, isEscapseToBody) {
4060
      var _this4 = this;
4061

4062
      var releasedParas = [];
4063
      external_jQuery_default().each(clustereds, function (idx, paras) {
4064
        var head = lists.head(paras);
4065
        var last = lists.last(paras);
4066
        var headList = isEscapseToBody ? dom.lastAncestor(head, dom.isList) : head.parentNode;
4067
        var parentItem = headList.parentNode;
4068

4069
        if (headList.parentNode.nodeName === 'LI') {
4070
          paras.map(function (para) {
4071
            var newList = _this4.findNextSiblings(para);
4072

4073
            if (parentItem.nextSibling) {
4074
              parentItem.parentNode.insertBefore(para, parentItem.nextSibling);
4075
            } else {
4076
              parentItem.parentNode.appendChild(para);
4077
            }
4078

4079
            if (newList.length) {
4080
              _this4.wrapList(newList, headList.nodeName);
4081

4082
              para.appendChild(newList[0].parentNode);
4083
            }
4084
          });
4085

4086
          if (headList.children.length === 0) {
4087
            parentItem.removeChild(headList);
4088
          }
4089

4090
          if (parentItem.childNodes.length === 0) {
4091
            parentItem.parentNode.removeChild(parentItem);
4092
          }
4093
        } else {
4094
          var lastList = headList.childNodes.length > 1 ? dom.splitTree(headList, {
4095
            node: last.parentNode,
4096
            offset: dom.position(last) + 1
4097
          }, {
4098
            isSkipPaddingBlankHTML: true
4099
          }) : null;
4100
          var middleList = dom.splitTree(headList, {
4101
            node: head.parentNode,
4102
            offset: dom.position(head)
4103
          }, {
4104
            isSkipPaddingBlankHTML: true
4105
          });
4106
          paras = isEscapseToBody ? dom.listDescendant(middleList, dom.isLi) : lists.from(middleList.childNodes).filter(dom.isLi); // LI to P
4107

4108
          if (isEscapseToBody || !dom.isList(headList.parentNode)) {
4109
            paras = paras.map(function (para) {
4110
              return dom.replace(para, 'P');
4111
            });
4112
          }
4113

4114
          external_jQuery_default().each(lists.from(paras).reverse(), function (idx, para) {
4115
            dom.insertAfter(para, headList);
4116
          }); // remove empty lists
4117

4118
          var rootLists = lists.compact([headList, middleList, lastList]);
4119
          external_jQuery_default().each(rootLists, function (idx, rootList) {
4120
            var listNodes = [rootList].concat(dom.listDescendant(rootList, dom.isList));
4121
            external_jQuery_default().each(listNodes.reverse(), function (idx, listNode) {
4122
              if (!dom.nodeLength(listNode)) {
4123
                dom.remove(listNode, true);
4124
              }
4125
            });
4126
          });
4127
        }
4128

4129
        releasedParas = releasedParas.concat(paras);
4130
      });
4131
      return releasedParas;
4132
    }
4133
    /**
4134
     * @method appendToPrevious
4135
     *
4136
     * Appends list to previous list item, if
4137
     * none exist it wraps the list in a new list item.
4138
     *
4139
     * @param {HTMLNode} ListItem
4140
     * @return {HTMLNode}
4141
     */
4142

4143
  }, {
4144
    key: "appendToPrevious",
4145
    value: function appendToPrevious(node) {
4146
      return node.previousSibling ? dom.appendChildNodes(node.previousSibling, [node]) : this.wrapList([node], 'LI');
4147
    }
4148
    /**
4149
     * @method findList
4150
     *
4151
     * Finds an existing list in list item
4152
     *
4153
     * @param {HTMLNode} ListItem
4154
     * @return {Array[]}
4155
     */
4156

4157
  }, {
4158
    key: "findList",
4159
    value: function findList(node) {
4160
      return node ? lists.find(node.children, function (child) {
4161
        return ['OL', 'UL'].indexOf(child.nodeName) > -1;
4162
      }) : null;
4163
    }
4164
    /**
4165
     * @method findNextSiblings
4166
     *
4167
     * Finds all list item siblings that follow it
4168
     *
4169
     * @param {HTMLNode} ListItem
4170
     * @return {HTMLNode}
4171
     */
4172

4173
  }, {
4174
    key: "findNextSiblings",
4175
    value: function findNextSiblings(node) {
4176
      var siblings = [];
4177

4178
      while (node.nextSibling) {
4179
        siblings.push(node.nextSibling);
4180
        node = node.nextSibling;
4181
      }
4182

4183
      return siblings;
4184
    }
4185
  }]);
4186

4187
  return Bullet;
4188
}();
4189

4190

4191
;// CONCATENATED MODULE: ./src/js/editing/Typing.js
4192
function Typing_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4193

4194
function Typing_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4195

4196
function Typing_createClass(Constructor, protoProps, staticProps) { if (protoProps) Typing_defineProperties(Constructor.prototype, protoProps); if (staticProps) Typing_defineProperties(Constructor, staticProps); return Constructor; }
4197

4198

4199

4200

4201

4202
/**
4203
 * @class editing.Typing
4204
 *
4205
 * Typing
4206
 *
4207
 */
4208

4209
var Typing = /*#__PURE__*/function () {
4210
  function Typing(context) {
4211
    Typing_classCallCheck(this, Typing);
4212

4213
    // a Bullet instance to toggle lists off
4214
    this.bullet = new Bullet();
4215
    this.options = context.options;
4216
  }
4217
  /**
4218
   * insert tab
4219
   *
4220
   * @param {WrappedRange} rng
4221
   * @param {Number} tabsize
4222
   */
4223

4224

4225
  Typing_createClass(Typing, [{
4226
    key: "insertTab",
4227
    value: function insertTab(rng, tabsize) {
4228
      var tab = dom.createText(new Array(tabsize + 1).join(dom.NBSP_CHAR));
4229
      rng = rng.deleteContents();
4230
      rng.insertNode(tab, true);
4231
      rng = range.create(tab, tabsize);
4232
      rng.select();
4233
    }
4234
    /**
4235
     * insert paragraph
4236
     *
4237
     * @param {jQuery} $editable
4238
     * @param {WrappedRange} rng Can be used in unit tests to "mock" the range
4239
     *
4240
     * blockquoteBreakingLevel
4241
     *   0 - No break, the new paragraph remains inside the quote
4242
     *   1 - Break the first blockquote in the ancestors list
4243
     *   2 - Break all blockquotes, so that the new paragraph is not quoted (this is the default)
4244
     */
4245

4246
  }, {
4247
    key: "insertParagraph",
4248
    value: function insertParagraph(editable, rng) {
4249
      rng = rng || range.create(editable); // deleteContents on range.
4250

4251
      rng = rng.deleteContents(); // Wrap range if it needs to be wrapped by paragraph
4252

4253
      rng = rng.wrapBodyInlineWithPara(); // finding paragraph
4254

4255
      var splitRoot = dom.ancestor(rng.sc, dom.isPara);
4256
      var nextPara; // on paragraph: split paragraph
4257

4258
      if (splitRoot) {
4259
        // if it is an empty line with li
4260
        if (dom.isLi(splitRoot) && (dom.isEmpty(splitRoot) || dom.deepestChildIsEmpty(splitRoot))) {
4261
          // toggle UL/OL and escape
4262
          this.bullet.toggleList(splitRoot.parentNode.nodeName);
4263
          return;
4264
        } else {
4265
          var blockquote = null;
4266

4267
          if (this.options.blockquoteBreakingLevel === 1) {
4268
            blockquote = dom.ancestor(splitRoot, dom.isBlockquote);
4269
          } else if (this.options.blockquoteBreakingLevel === 2) {
4270
            blockquote = dom.lastAncestor(splitRoot, dom.isBlockquote);
4271
          }
4272

4273
          if (blockquote) {
4274
            // We're inside a blockquote and options ask us to break it
4275
            nextPara = external_jQuery_default()(dom.emptyPara)[0]; // If the split is right before a <br>, remove it so that there's no "empty line"
4276
            // after the split in the new blockquote created
4277

4278
            if (dom.isRightEdgePoint(rng.getStartPoint()) && dom.isBR(rng.sc.nextSibling)) {
4279
              external_jQuery_default()(rng.sc.nextSibling).remove();
4280
            }
4281

4282
            var split = dom.splitTree(blockquote, rng.getStartPoint(), {
4283
              isDiscardEmptySplits: true
4284
            });
4285

4286
            if (split) {
4287
              split.parentNode.insertBefore(nextPara, split);
4288
            } else {
4289
              dom.insertAfter(nextPara, blockquote); // There's no split if we were at the end of the blockquote
4290
            }
4291
          } else {
4292
            nextPara = dom.splitTree(splitRoot, rng.getStartPoint()); // not a blockquote, just insert the paragraph
4293

4294
            var emptyAnchors = dom.listDescendant(splitRoot, dom.isEmptyAnchor);
4295
            emptyAnchors = emptyAnchors.concat(dom.listDescendant(nextPara, dom.isEmptyAnchor));
4296
            external_jQuery_default().each(emptyAnchors, function (idx, anchor) {
4297
              dom.remove(anchor);
4298
            }); // replace empty heading, pre or custom-made styleTag with P tag
4299

4300
            if ((dom.isHeading(nextPara) || dom.isPre(nextPara) || dom.isCustomStyleTag(nextPara)) && dom.isEmpty(nextPara)) {
4301
              nextPara = dom.replace(nextPara, 'p');
4302
            }
4303
          }
4304
        } // no paragraph: insert empty paragraph
4305

4306
      } else {
4307
        var next = rng.sc.childNodes[rng.so];
4308
        nextPara = external_jQuery_default()(dom.emptyPara)[0];
4309

4310
        if (next) {
4311
          rng.sc.insertBefore(nextPara, next);
4312
        } else {
4313
          rng.sc.appendChild(nextPara);
4314
        }
4315
      }
4316

4317
      range.create(nextPara, 0).normalize().select().scrollIntoView(editable);
4318
    }
4319
  }]);
4320

4321
  return Typing;
4322
}();
4323

4324

4325
;// CONCATENATED MODULE: ./src/js/editing/Table.js
4326
function Table_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4327

4328
function Table_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4329

4330
function Table_createClass(Constructor, protoProps, staticProps) { if (protoProps) Table_defineProperties(Constructor.prototype, protoProps); if (staticProps) Table_defineProperties(Constructor, staticProps); return Constructor; }
4331

4332

4333

4334

4335

4336
/**
4337
 * @class Create a virtual table to create what actions to do in change.
4338
 * @param {object} startPoint Cell selected to apply change.
4339
 * @param {enum} where  Where change will be applied Row or Col. Use enum: TableResultAction.where
4340
 * @param {enum} action Action to be applied. Use enum: TableResultAction.requestAction
4341
 * @param {object} domTable Dom element of table to make changes.
4342
 */
4343

4344
var TableResultAction = function TableResultAction(startPoint, where, action, domTable) {
4345
  var _startPoint = {
4346
    'colPos': 0,
4347
    'rowPos': 0
4348
  };
4349
  var _virtualTable = [];
4350
  var _actionCellList = []; /// ///////////////////////////////////////////
4351
  // Private functions
4352
  /// ///////////////////////////////////////////
4353

4354
  /**
4355
   * Set the startPoint of action.
4356
   */
4357

4358
  function setStartPoint() {
4359
    if (!startPoint || !startPoint.tagName || startPoint.tagName.toLowerCase() !== 'td' && startPoint.tagName.toLowerCase() !== 'th') {
4360
      // Impossible to identify start Cell point
4361
      return;
4362
    }
4363

4364
    _startPoint.colPos = startPoint.cellIndex;
4365

4366
    if (!startPoint.parentElement || !startPoint.parentElement.tagName || startPoint.parentElement.tagName.toLowerCase() !== 'tr') {
4367
      // Impossible to identify start Row point
4368
      return;
4369
    }
4370

4371
    _startPoint.rowPos = startPoint.parentElement.rowIndex;
4372
  }
4373
  /**
4374
   * Define virtual table position info object.
4375
   *
4376
   * @param {int} rowIndex Index position in line of virtual table.
4377
   * @param {int} cellIndex Index position in column of virtual table.
4378
   * @param {object} baseRow Row affected by this position.
4379
   * @param {object} baseCell Cell affected by this position.
4380
   * @param {bool} isSpan Inform if it is an span cell/row.
4381
   */
4382

4383

4384
  function setVirtualTablePosition(rowIndex, cellIndex, baseRow, baseCell, isRowSpan, isColSpan, isVirtualCell) {
4385
    var objPosition = {
4386
      'baseRow': baseRow,
4387
      'baseCell': baseCell,
4388
      'isRowSpan': isRowSpan,
4389
      'isColSpan': isColSpan,
4390
      'isVirtual': isVirtualCell
4391
    };
4392

4393
    if (!_virtualTable[rowIndex]) {
4394
      _virtualTable[rowIndex] = [];
4395
    }
4396

4397
    _virtualTable[rowIndex][cellIndex] = objPosition;
4398
  }
4399
  /**
4400
   * Create action cell object.
4401
   *
4402
   * @param {object} virtualTableCellObj Object of specific position on virtual table.
4403
   * @param {enum} resultAction Action to be applied in that item.
4404
   */
4405

4406

4407
  function getActionCell(virtualTableCellObj, resultAction, virtualRowPosition, virtualColPosition) {
4408
    return {
4409
      'baseCell': virtualTableCellObj.baseCell,
4410
      'action': resultAction,
4411
      'virtualTable': {
4412
        'rowIndex': virtualRowPosition,
4413
        'cellIndex': virtualColPosition
4414
      }
4415
    };
4416
  }
4417
  /**
4418
   * Recover free index of row to append Cell.
4419
   *
4420
   * @param {int} rowIndex Index of row to find free space.
4421
   * @param {int} cellIndex Index of cell to find free space in table.
4422
   */
4423

4424

4425
  function recoverCellIndex(rowIndex, cellIndex) {
4426
    if (!_virtualTable[rowIndex]) {
4427
      return cellIndex;
4428
    }
4429

4430
    if (!_virtualTable[rowIndex][cellIndex]) {
4431
      return cellIndex;
4432
    }
4433

4434
    var newCellIndex = cellIndex;
4435

4436
    while (_virtualTable[rowIndex][newCellIndex]) {
4437
      newCellIndex++;
4438

4439
      if (!_virtualTable[rowIndex][newCellIndex]) {
4440
        return newCellIndex;
4441
      }
4442
    }
4443
  }
4444
  /**
4445
   * Recover info about row and cell and add information to virtual table.
4446
   *
4447
   * @param {object} row Row to recover information.
4448
   * @param {object} cell Cell to recover information.
4449
   */
4450

4451

4452
  function addCellInfoToVirtual(row, cell) {
4453
    var cellIndex = recoverCellIndex(row.rowIndex, cell.cellIndex);
4454
    var cellHasColspan = cell.colSpan > 1;
4455
    var cellHasRowspan = cell.rowSpan > 1;
4456
    var isThisSelectedCell = row.rowIndex === _startPoint.rowPos && cell.cellIndex === _startPoint.colPos;
4457
    setVirtualTablePosition(row.rowIndex, cellIndex, row, cell, cellHasRowspan, cellHasColspan, false); // Add span rows to virtual Table.
4458

4459
    var rowspanNumber = cell.attributes.rowSpan ? parseInt(cell.attributes.rowSpan.value, 10) : 0;
4460

4461
    if (rowspanNumber > 1) {
4462
      for (var rp = 1; rp < rowspanNumber; rp++) {
4463
        var rowspanIndex = row.rowIndex + rp;
4464
        adjustStartPoint(rowspanIndex, cellIndex, cell, isThisSelectedCell);
4465
        setVirtualTablePosition(rowspanIndex, cellIndex, row, cell, true, cellHasColspan, true);
4466
      }
4467
    } // Add span cols to virtual table.
4468

4469

4470
    var colspanNumber = cell.attributes.colSpan ? parseInt(cell.attributes.colSpan.value, 10) : 0;
4471

4472
    if (colspanNumber > 1) {
4473
      for (var cp = 1; cp < colspanNumber; cp++) {
4474
        var cellspanIndex = recoverCellIndex(row.rowIndex, cellIndex + cp);
4475
        adjustStartPoint(row.rowIndex, cellspanIndex, cell, isThisSelectedCell);
4476
        setVirtualTablePosition(row.rowIndex, cellspanIndex, row, cell, cellHasRowspan, true, true);
4477
      }
4478
    }
4479
  }
4480
  /**
4481
   * Process validation and adjust of start point if needed
4482
   *
4483
   * @param {int} rowIndex
4484
   * @param {int} cellIndex
4485
   * @param {object} cell
4486
   * @param {bool} isSelectedCell
4487
   */
4488

4489

4490
  function adjustStartPoint(rowIndex, cellIndex, cell, isSelectedCell) {
4491
    if (rowIndex === _startPoint.rowPos && _startPoint.colPos >= cell.cellIndex && cell.cellIndex <= cellIndex && !isSelectedCell) {
4492
      _startPoint.colPos++;
4493
    }
4494
  }
4495
  /**
4496
   * Create virtual table of cells with all cells, including span cells.
4497
   */
4498

4499

4500
  function createVirtualTable() {
4501
    var rows = domTable.rows;
4502

4503
    for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
4504
      var cells = rows[rowIndex].cells;
4505

4506
      for (var cellIndex = 0; cellIndex < cells.length; cellIndex++) {
4507
        addCellInfoToVirtual(rows[rowIndex], cells[cellIndex]);
4508
      }
4509
    }
4510
  }
4511
  /**
4512
   * Get action to be applied on the cell.
4513
   *
4514
   * @param {object} cell virtual table cell to apply action
4515
   */
4516

4517

4518
  function getDeleteResultActionToCell(cell) {
4519
    switch (where) {
4520
      case TableResultAction.where.Column:
4521
        if (cell.isColSpan) {
4522
          return TableResultAction.resultAction.SubtractSpanCount;
4523
        }
4524

4525
        break;
4526

4527
      case TableResultAction.where.Row:
4528
        if (!cell.isVirtual && cell.isRowSpan) {
4529
          return TableResultAction.resultAction.AddCell;
4530
        } else if (cell.isRowSpan) {
4531
          return TableResultAction.resultAction.SubtractSpanCount;
4532
        }
4533

4534
        break;
4535
    }
4536

4537
    return TableResultAction.resultAction.RemoveCell;
4538
  }
4539
  /**
4540
   * Get action to be applied on the cell.
4541
   *
4542
   * @param {object} cell virtual table cell to apply action
4543
   */
4544

4545

4546
  function getAddResultActionToCell(cell) {
4547
    switch (where) {
4548
      case TableResultAction.where.Column:
4549
        if (cell.isColSpan) {
4550
          return TableResultAction.resultAction.SumSpanCount;
4551
        } else if (cell.isRowSpan && cell.isVirtual) {
4552
          return TableResultAction.resultAction.Ignore;
4553
        }
4554

4555
        break;
4556

4557
      case TableResultAction.where.Row:
4558
        if (cell.isRowSpan) {
4559
          return TableResultAction.resultAction.SumSpanCount;
4560
        } else if (cell.isColSpan && cell.isVirtual) {
4561
          return TableResultAction.resultAction.Ignore;
4562
        }
4563

4564
        break;
4565
    }
4566

4567
    return TableResultAction.resultAction.AddCell;
4568
  }
4569

4570
  function init() {
4571
    setStartPoint();
4572
    createVirtualTable();
4573
  } /// ///////////////////////////////////////////
4574
  // Public functions
4575
  /// ///////////////////////////////////////////
4576

4577
  /**
4578
   * Recover array os what to do in table.
4579
   */
4580

4581

4582
  this.getActionList = function () {
4583
    var fixedRow = where === TableResultAction.where.Row ? _startPoint.rowPos : -1;
4584
    var fixedCol = where === TableResultAction.where.Column ? _startPoint.colPos : -1;
4585
    var actualPosition = 0;
4586
    var canContinue = true;
4587

4588
    while (canContinue) {
4589
      var rowPosition = fixedRow >= 0 ? fixedRow : actualPosition;
4590
      var colPosition = fixedCol >= 0 ? fixedCol : actualPosition;
4591
      var row = _virtualTable[rowPosition];
4592

4593
      if (!row) {
4594
        canContinue = false;
4595
        return _actionCellList;
4596
      }
4597

4598
      var cell = row[colPosition];
4599

4600
      if (!cell) {
4601
        canContinue = false;
4602
        return _actionCellList;
4603
      } // Define action to be applied in this cell
4604

4605

4606
      var resultAction = TableResultAction.resultAction.Ignore;
4607

4608
      switch (action) {
4609
        case TableResultAction.requestAction.Add:
4610
          resultAction = getAddResultActionToCell(cell);
4611
          break;
4612

4613
        case TableResultAction.requestAction.Delete:
4614
          resultAction = getDeleteResultActionToCell(cell);
4615
          break;
4616
      }
4617

4618
      _actionCellList.push(getActionCell(cell, resultAction, rowPosition, colPosition));
4619

4620
      actualPosition++;
4621
    }
4622

4623
    return _actionCellList;
4624
  };
4625

4626
  init();
4627
};
4628
/**
4629
*
4630
* Where action occours enum.
4631
*/
4632

4633

4634
TableResultAction.where = {
4635
  'Row': 0,
4636
  'Column': 1
4637
};
4638
/**
4639
*
4640
* Requested action to apply enum.
4641
*/
4642

4643
TableResultAction.requestAction = {
4644
  'Add': 0,
4645
  'Delete': 1
4646
};
4647
/**
4648
*
4649
* Result action to be executed enum.
4650
*/
4651

4652
TableResultAction.resultAction = {
4653
  'Ignore': 0,
4654
  'SubtractSpanCount': 1,
4655
  'RemoveCell': 2,
4656
  'AddCell': 3,
4657
  'SumSpanCount': 4
4658
};
4659
/**
4660
 *
4661
 * @class editing.Table
4662
 *
4663
 * Table
4664
 *
4665
 */
4666

4667
var Table = /*#__PURE__*/function () {
4668
  function Table() {
4669
    Table_classCallCheck(this, Table);
4670
  }
4671

4672
  Table_createClass(Table, [{
4673
    key: "tab",
4674
    value:
4675
    /**
4676
     * handle tab key
4677
     *
4678
     * @param {WrappedRange} rng
4679
     * @param {Boolean} isShift
4680
     */
4681
    function tab(rng, isShift) {
4682
      var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
4683
      var table = dom.ancestor(cell, dom.isTable);
4684
      var cells = dom.listDescendant(table, dom.isCell);
4685
      var nextCell = lists[isShift ? 'prev' : 'next'](cells, cell);
4686

4687
      if (nextCell) {
4688
        range.create(nextCell, 0).select();
4689
      }
4690
    }
4691
    /**
4692
     * Add a new row
4693
     *
4694
     * @param {WrappedRange} rng
4695
     * @param {String} position (top/bottom)
4696
     * @return {Node}
4697
     */
4698

4699
  }, {
4700
    key: "addRow",
4701
    value: function addRow(rng, position) {
4702
      var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
4703
      var currentTr = external_jQuery_default()(cell).closest('tr');
4704
      var trAttributes = this.recoverAttributes(currentTr);
4705
      var html = external_jQuery_default()('<tr' + trAttributes + '></tr>');
4706
      var vTable = new TableResultAction(cell, TableResultAction.where.Row, TableResultAction.requestAction.Add, external_jQuery_default()(currentTr).closest('table')[0]);
4707
      var actions = vTable.getActionList();
4708

4709
      for (var idCell = 0; idCell < actions.length; idCell++) {
4710
        var currentCell = actions[idCell];
4711
        var tdAttributes = this.recoverAttributes(currentCell.baseCell);
4712

4713
        switch (currentCell.action) {
4714
          case TableResultAction.resultAction.AddCell:
4715
            html.append('<td' + tdAttributes + '>' + dom.blank + '</td>');
4716
            break;
4717

4718
          case TableResultAction.resultAction.SumSpanCount:
4719
            {
4720
              if (position === 'top') {
4721
                var baseCellTr = currentCell.baseCell.parent;
4722
                var isTopFromRowSpan = (!baseCellTr ? 0 : currentCell.baseCell.closest('tr').rowIndex) <= currentTr[0].rowIndex;
4723

4724
                if (isTopFromRowSpan) {
4725
                  var newTd = external_jQuery_default()('<div></div>').append(external_jQuery_default()('<td' + tdAttributes + '>' + dom.blank + '</td>').removeAttr('rowspan')).html();
4726
                  html.append(newTd);
4727
                  break;
4728
                }
4729
              }
4730

4731
              var rowspanNumber = parseInt(currentCell.baseCell.rowSpan, 10);
4732
              rowspanNumber++;
4733
              currentCell.baseCell.setAttribute('rowSpan', rowspanNumber);
4734
            }
4735
            break;
4736
        }
4737
      }
4738

4739
      if (position === 'top') {
4740
        currentTr.before(html);
4741
      } else {
4742
        var cellHasRowspan = cell.rowSpan > 1;
4743

4744
        if (cellHasRowspan) {
4745
          var lastTrIndex = currentTr[0].rowIndex + (cell.rowSpan - 2);
4746
          external_jQuery_default()(external_jQuery_default()(currentTr).parent().find('tr')[lastTrIndex]).after(external_jQuery_default()(html));
4747
          return;
4748
        }
4749

4750
        currentTr.after(html);
4751
      }
4752
    }
4753
    /**
4754
     * Add a new col
4755
     *
4756
     * @param {WrappedRange} rng
4757
     * @param {String} position (left/right)
4758
     * @return {Node}
4759
     */
4760

4761
  }, {
4762
    key: "addCol",
4763
    value: function addCol(rng, position) {
4764
      var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
4765
      var row = external_jQuery_default()(cell).closest('tr');
4766
      var rowsGroup = external_jQuery_default()(row).siblings();
4767
      rowsGroup.push(row);
4768
      var vTable = new TableResultAction(cell, TableResultAction.where.Column, TableResultAction.requestAction.Add, external_jQuery_default()(row).closest('table')[0]);
4769
      var actions = vTable.getActionList();
4770

4771
      for (var actionIndex = 0; actionIndex < actions.length; actionIndex++) {
4772
        var currentCell = actions[actionIndex];
4773
        var tdAttributes = this.recoverAttributes(currentCell.baseCell);
4774

4775
        switch (currentCell.action) {
4776
          case TableResultAction.resultAction.AddCell:
4777
            if (position === 'right') {
4778
              external_jQuery_default()(currentCell.baseCell).after('<td' + tdAttributes + '>' + dom.blank + '</td>');
4779
            } else {
4780
              external_jQuery_default()(currentCell.baseCell).before('<td' + tdAttributes + '>' + dom.blank + '</td>');
4781
            }
4782

4783
            break;
4784

4785
          case TableResultAction.resultAction.SumSpanCount:
4786
            if (position === 'right') {
4787
              var colspanNumber = parseInt(currentCell.baseCell.colSpan, 10);
4788
              colspanNumber++;
4789
              currentCell.baseCell.setAttribute('colSpan', colspanNumber);
4790
            } else {
4791
              external_jQuery_default()(currentCell.baseCell).before('<td' + tdAttributes + '>' + dom.blank + '</td>');
4792
            }
4793

4794
            break;
4795
        }
4796
      }
4797
    }
4798
    /*
4799
    * Copy attributes from element.
4800
    *
4801
    * @param {object} Element to recover attributes.
4802
    * @return {string} Copied string elements.
4803
    */
4804

4805
  }, {
4806
    key: "recoverAttributes",
4807
    value: function recoverAttributes(el) {
4808
      var resultStr = '';
4809

4810
      if (!el) {
4811
        return resultStr;
4812
      }
4813

4814
      var attrList = el.attributes || [];
4815

4816
      for (var i = 0; i < attrList.length; i++) {
4817
        if (attrList[i].name.toLowerCase() === 'id') {
4818
          continue;
4819
        }
4820

4821
        if (attrList[i].specified) {
4822
          resultStr += ' ' + attrList[i].name + '=\'' + attrList[i].value + '\'';
4823
        }
4824
      }
4825

4826
      return resultStr;
4827
    }
4828
    /**
4829
     * Delete current row
4830
     *
4831
     * @param {WrappedRange} rng
4832
     * @return {Node}
4833
     */
4834

4835
  }, {
4836
    key: "deleteRow",
4837
    value: function deleteRow(rng) {
4838
      var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
4839
      var row = external_jQuery_default()(cell).closest('tr');
4840
      var cellPos = row.children('td, th').index(external_jQuery_default()(cell));
4841
      var rowPos = row[0].rowIndex;
4842
      var vTable = new TableResultAction(cell, TableResultAction.where.Row, TableResultAction.requestAction.Delete, external_jQuery_default()(row).closest('table')[0]);
4843
      var actions = vTable.getActionList();
4844

4845
      for (var actionIndex = 0; actionIndex < actions.length; actionIndex++) {
4846
        if (!actions[actionIndex]) {
4847
          continue;
4848
        }
4849

4850
        var baseCell = actions[actionIndex].baseCell;
4851
        var virtualPosition = actions[actionIndex].virtualTable;
4852
        var hasRowspan = baseCell.rowSpan && baseCell.rowSpan > 1;
4853
        var rowspanNumber = hasRowspan ? parseInt(baseCell.rowSpan, 10) : 0;
4854

4855
        switch (actions[actionIndex].action) {
4856
          case TableResultAction.resultAction.Ignore:
4857
            continue;
4858

4859
          case TableResultAction.resultAction.AddCell:
4860
            {
4861
              var nextRow = row.next('tr')[0];
4862

4863
              if (!nextRow) {
4864
                continue;
4865
              }
4866

4867
              var cloneRow = row[0].cells[cellPos];
4868

4869
              if (hasRowspan) {
4870
                if (rowspanNumber > 2) {
4871
                  rowspanNumber--;
4872
                  nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
4873
                  nextRow.cells[cellPos].setAttribute('rowSpan', rowspanNumber);
4874
                  nextRow.cells[cellPos].innerHTML = '';
4875
                } else if (rowspanNumber === 2) {
4876
                  nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
4877
                  nextRow.cells[cellPos].removeAttribute('rowSpan');
4878
                  nextRow.cells[cellPos].innerHTML = '';
4879
                }
4880
              }
4881
            }
4882
            continue;
4883

4884
          case TableResultAction.resultAction.SubtractSpanCount:
4885
            if (hasRowspan) {
4886
              if (rowspanNumber > 2) {
4887
                rowspanNumber--;
4888
                baseCell.setAttribute('rowSpan', rowspanNumber);
4889

4890
                if (virtualPosition.rowIndex !== rowPos && baseCell.cellIndex === cellPos) {
4891
                  baseCell.innerHTML = '';
4892
                }
4893
              } else if (rowspanNumber === 2) {
4894
                baseCell.removeAttribute('rowSpan');
4895

4896
                if (virtualPosition.rowIndex !== rowPos && baseCell.cellIndex === cellPos) {
4897
                  baseCell.innerHTML = '';
4898
                }
4899
              }
4900
            }
4901

4902
            continue;
4903

4904
          case TableResultAction.resultAction.RemoveCell:
4905
            // Do not need remove cell because row will be deleted.
4906
            continue;
4907
        }
4908
      }
4909

4910
      row.remove();
4911
    }
4912
    /**
4913
     * Delete current col
4914
     *
4915
     * @param {WrappedRange} rng
4916
     * @return {Node}
4917
     */
4918

4919
  }, {
4920
    key: "deleteCol",
4921
    value: function deleteCol(rng) {
4922
      var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
4923
      var row = external_jQuery_default()(cell).closest('tr');
4924
      var cellPos = row.children('td, th').index(external_jQuery_default()(cell));
4925
      var vTable = new TableResultAction(cell, TableResultAction.where.Column, TableResultAction.requestAction.Delete, external_jQuery_default()(row).closest('table')[0]);
4926
      var actions = vTable.getActionList();
4927

4928
      for (var actionIndex = 0; actionIndex < actions.length; actionIndex++) {
4929
        if (!actions[actionIndex]) {
4930
          continue;
4931
        }
4932

4933
        switch (actions[actionIndex].action) {
4934
          case TableResultAction.resultAction.Ignore:
4935
            continue;
4936

4937
          case TableResultAction.resultAction.SubtractSpanCount:
4938
            {
4939
              var baseCell = actions[actionIndex].baseCell;
4940
              var hasColspan = baseCell.colSpan && baseCell.colSpan > 1;
4941

4942
              if (hasColspan) {
4943
                var colspanNumber = baseCell.colSpan ? parseInt(baseCell.colSpan, 10) : 0;
4944

4945
                if (colspanNumber > 2) {
4946
                  colspanNumber--;
4947
                  baseCell.setAttribute('colSpan', colspanNumber);
4948

4949
                  if (baseCell.cellIndex === cellPos) {
4950
                    baseCell.innerHTML = '';
4951
                  }
4952
                } else if (colspanNumber === 2) {
4953
                  baseCell.removeAttribute('colSpan');
4954

4955
                  if (baseCell.cellIndex === cellPos) {
4956
                    baseCell.innerHTML = '';
4957
                  }
4958
                }
4959
              }
4960
            }
4961
            continue;
4962

4963
          case TableResultAction.resultAction.RemoveCell:
4964
            dom.remove(actions[actionIndex].baseCell, true);
4965
            continue;
4966
        }
4967
      }
4968
    }
4969
    /**
4970
     * create empty table element
4971
     *
4972
     * @param {Number} rowCount
4973
     * @param {Number} colCount
4974
     * @return {Node}
4975
     */
4976

4977
  }, {
4978
    key: "createTable",
4979
    value: function createTable(colCount, rowCount, options) {
4980
      var tds = [];
4981
      var tdHTML;
4982

4983
      for (var idxCol = 0; idxCol < colCount; idxCol++) {
4984
        tds.push('<td>' + dom.blank + '</td>');
4985
      }
4986

4987
      tdHTML = tds.join('');
4988
      var trs = [];
4989
      var trHTML;
4990

4991
      for (var idxRow = 0; idxRow < rowCount; idxRow++) {
4992
        trs.push('<tr>' + tdHTML + '</tr>');
4993
      }
4994

4995
      trHTML = trs.join('');
4996
      var $table = external_jQuery_default()('<table>' + trHTML + '</table>');
4997

4998
      if (options && options.tableClassName) {
4999
        $table.addClass(options.tableClassName);
5000
      }
5001

5002
      return $table[0];
5003
    }
5004
    /**
5005
     * Delete current table
5006
     *
5007
     * @param {WrappedRange} rng
5008
     * @return {Node}
5009
     */
5010

5011
  }, {
5012
    key: "deleteTable",
5013
    value: function deleteTable(rng) {
5014
      var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
5015
      external_jQuery_default()(cell).closest('table').remove();
5016
    }
5017
  }]);
5018

5019
  return Table;
5020
}();
5021

5022

5023
;// CONCATENATED MODULE: ./src/js/module/Editor.js
5024
function Editor_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5025

5026
function Editor_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
5027

5028
function Editor_createClass(Constructor, protoProps, staticProps) { if (protoProps) Editor_defineProperties(Constructor.prototype, protoProps); if (staticProps) Editor_defineProperties(Constructor, staticProps); return Constructor; }
5029

5030

5031

5032

5033

5034

5035

5036

5037

5038

5039

5040

5041

5042

5043
var KEY_BOGUS = 'bogus';
5044
/**
5045
 * @class Editor
5046
 */
5047

5048
var Editor = /*#__PURE__*/function () {
5049
  function Editor(context) {
5050
    var _this = this;
5051

5052
    Editor_classCallCheck(this, Editor);
5053

5054
    this.context = context;
5055
    this.$note = context.layoutInfo.note;
5056
    this.$editor = context.layoutInfo.editor;
5057
    this.$editable = context.layoutInfo.editable;
5058
    this.options = context.options;
5059
    this.lang = this.options.langInfo;
5060
    this.editable = this.$editable[0];
5061
    this.lastRange = null;
5062
    this.snapshot = null;
5063
    this.style = new Style();
5064
    this.table = new Table();
5065
    this.typing = new Typing(context);
5066
    this.bullet = new Bullet();
5067
    this.history = new History(context);
5068
    this.context.memo('help.escape', this.lang.help.escape);
5069
    this.context.memo('help.undo', this.lang.help.undo);
5070
    this.context.memo('help.redo', this.lang.help.redo);
5071
    this.context.memo('help.tab', this.lang.help.tab);
5072
    this.context.memo('help.untab', this.lang.help.untab);
5073
    this.context.memo('help.insertParagraph', this.lang.help.insertParagraph);
5074
    this.context.memo('help.insertOrderedList', this.lang.help.insertOrderedList);
5075
    this.context.memo('help.insertUnorderedList', this.lang.help.insertUnorderedList);
5076
    this.context.memo('help.indent', this.lang.help.indent);
5077
    this.context.memo('help.outdent', this.lang.help.outdent);
5078
    this.context.memo('help.formatPara', this.lang.help.formatPara);
5079
    this.context.memo('help.insertHorizontalRule', this.lang.help.insertHorizontalRule);
5080
    this.context.memo('help.fontName', this.lang.help.fontName); // native commands(with execCommand), generate function for execCommand
5081

5082
    var commands = ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'formatBlock', 'removeFormat', 'backColor'];
5083

5084
    for (var idx = 0, len = commands.length; idx < len; idx++) {
5085
      this[commands[idx]] = function (sCmd) {
5086
        return function (value) {
5087
          _this.beforeCommand();
5088

5089
          document.execCommand(sCmd, false, value);
5090

5091
          _this.afterCommand(true);
5092
        };
5093
      }(commands[idx]);
5094

5095
      this.context.memo('help.' + commands[idx], this.lang.help[commands[idx]]);
5096
    }
5097

5098
    this.fontName = this.wrapCommand(function (value) {
5099
      return _this.fontStyling('font-family', env.validFontName(value));
5100
    });
5101
    this.fontSize = this.wrapCommand(function (value) {
5102
      var unit = _this.currentStyle()['font-size-unit'];
5103

5104
      return _this.fontStyling('font-size', value + unit);
5105
    });
5106
    this.fontSizeUnit = this.wrapCommand(function (value) {
5107
      var size = _this.currentStyle()['font-size'];
5108

5109
      return _this.fontStyling('font-size', size + value);
5110
    });
5111

5112
    for (var _idx = 1; _idx <= 6; _idx++) {
5113
      this['formatH' + _idx] = function (idx) {
5114
        return function () {
5115
          _this.formatBlock('H' + idx);
5116
        };
5117
      }(_idx);
5118

5119
      this.context.memo('help.formatH' + _idx, this.lang.help['formatH' + _idx]);
5120
    }
5121

5122
    this.insertParagraph = this.wrapCommand(function () {
5123
      _this.typing.insertParagraph(_this.editable);
5124
    });
5125
    this.insertOrderedList = this.wrapCommand(function () {
5126
      _this.bullet.insertOrderedList(_this.editable);
5127
    });
5128
    this.insertUnorderedList = this.wrapCommand(function () {
5129
      _this.bullet.insertUnorderedList(_this.editable);
5130
    });
5131
    this.indent = this.wrapCommand(function () {
5132
      _this.bullet.indent(_this.editable);
5133
    });
5134
    this.outdent = this.wrapCommand(function () {
5135
      _this.bullet.outdent(_this.editable);
5136
    });
5137
    /**
5138
     * insertNode
5139
     * insert node
5140
     * @param {Node} node
5141
     */
5142

5143
    this.insertNode = this.wrapCommand(function (node) {
5144
      if (_this.isLimited(external_jQuery_default()(node).text().length)) {
5145
        return;
5146
      }
5147

5148
      var rng = _this.getLastRange();
5149

5150
      rng.insertNode(node);
5151

5152
      _this.setLastRange(range.createFromNodeAfter(node).select());
5153
    });
5154
    /**
5155
     * insert text
5156
     * @param {String} text
5157
     */
5158

5159
    this.insertText = this.wrapCommand(function (text) {
5160
      if (_this.isLimited(text.length)) {
5161
        return;
5162
      }
5163

5164
      var rng = _this.getLastRange();
5165

5166
      var textNode = rng.insertNode(dom.createText(text));
5167

5168
      _this.setLastRange(range.create(textNode, dom.nodeLength(textNode)).select());
5169
    });
5170
    /**
5171
     * paste HTML
5172
     * @param {String} markup
5173
     */
5174

5175
    this.pasteHTML = this.wrapCommand(function (markup) {
5176
      if (_this.isLimited(markup.length)) {
5177
        return;
5178
      }
5179

5180
      markup = _this.context.invoke('codeview.purify', markup);
5181

5182
      var contents = _this.getLastRange().pasteHTML(markup);
5183

5184
      _this.setLastRange(range.createFromNodeAfter(lists.last(contents)).select());
5185
    });
5186
    /**
5187
     * formatBlock
5188
     *
5189
     * @param {String} tagName
5190
     */
5191

5192
    this.formatBlock = this.wrapCommand(function (tagName, $target) {
5193
      var onApplyCustomStyle = _this.options.callbacks.onApplyCustomStyle;
5194

5195
      if (onApplyCustomStyle) {
5196
        onApplyCustomStyle.call(_this, $target, _this.context, _this.onFormatBlock);
5197
      } else {
5198
        _this.onFormatBlock(tagName, $target);
5199
      }
5200
    });
5201
    /**
5202
     * insert horizontal rule
5203
     */
5204

5205
    this.insertHorizontalRule = this.wrapCommand(function () {
5206
      var hrNode = _this.getLastRange().insertNode(dom.create('HR'));
5207

5208
      if (hrNode.nextSibling) {
5209
        _this.setLastRange(range.create(hrNode.nextSibling, 0).normalize().select());
5210
      }
5211
    });
5212
    /**
5213
     * lineHeight
5214
     * @param {String} value
5215
     */
5216

5217
    this.lineHeight = this.wrapCommand(function (value) {
5218
      _this.style.stylePara(_this.getLastRange(), {
5219
        lineHeight: value
5220
      });
5221
    });
5222
    /**
5223
     * create link (command)
5224
     *
5225
     * @param {Object} linkInfo
5226
     */
5227

5228
    this.createLink = this.wrapCommand(function (linkInfo) {
5229
      var linkUrl = linkInfo.url;
5230
      var linkText = linkInfo.text;
5231
      var isNewWindow = linkInfo.isNewWindow;
5232
      var checkProtocol = linkInfo.checkProtocol;
5233

5234
      var rng = linkInfo.range || _this.getLastRange();
5235

5236
      var additionalTextLength = linkText.length - rng.toString().length;
5237

5238
      if (additionalTextLength > 0 && _this.isLimited(additionalTextLength)) {
5239
        return;
5240
      }
5241

5242
      var isTextChanged = rng.toString() !== linkText; // handle spaced urls from input
5243

5244
      if (typeof linkUrl === 'string') {
5245
        linkUrl = linkUrl.trim();
5246
      }
5247

5248
      if (_this.options.onCreateLink) {
5249
        linkUrl = _this.options.onCreateLink(linkUrl);
5250
      } else if (checkProtocol) {
5251
        // if url doesn't have any protocol and not even a relative or a label, use http:// as default
5252
        linkUrl = /^([A-Za-z][A-Za-z0-9+-.]*\:|#|\/)/.test(linkUrl) ? linkUrl : _this.options.defaultProtocol + linkUrl;
5253
      }
5254

5255
      var anchors = [];
5256

5257
      if (isTextChanged) {
5258
        rng = rng.deleteContents();
5259
        var anchor = rng.insertNode(external_jQuery_default()('<A>' + linkText + '</A>')[0]);
5260
        anchors.push(anchor);
5261
      } else {
5262
        anchors = _this.style.styleNodes(rng, {
5263
          nodeName: 'A',
5264
          expandClosestSibling: true,
5265
          onlyPartialContains: true
5266
        });
5267
      }
5268

5269
      external_jQuery_default().each(anchors, function (idx, anchor) {
5270
        external_jQuery_default()(anchor).attr('href', linkUrl);
5271

5272
        if (isNewWindow) {
5273
          external_jQuery_default()(anchor).attr('target', '_blank');
5274
        } else {
5275
          external_jQuery_default()(anchor).removeAttr('target');
5276
        }
5277
      });
5278

5279
      _this.setLastRange(_this.createRangeFromList(anchors).select());
5280
    });
5281
    /**
5282
     * setting color
5283
     *
5284
     * @param {Object} sObjColor  color code
5285
     * @param {String} sObjColor.foreColor foreground color
5286
     * @param {String} sObjColor.backColor background color
5287
     */
5288

5289
    this.color = this.wrapCommand(function (colorInfo) {
5290
      var foreColor = colorInfo.foreColor;
5291
      var backColor = colorInfo.backColor;
5292

5293
      if (foreColor) {
5294
        document.execCommand('foreColor', false, foreColor);
5295
      }
5296

5297
      if (backColor) {
5298
        document.execCommand('backColor', false, backColor);
5299
      }
5300
    });
5301
    /**
5302
     * Set foreground color
5303
     *
5304
     * @param {String} colorCode foreground color code
5305
     */
5306

5307
    this.foreColor = this.wrapCommand(function (colorInfo) {
5308
      document.execCommand('foreColor', false, colorInfo);
5309
    });
5310
    /**
5311
     * insert Table
5312
     *
5313
     * @param {String} dimension of table (ex : "5x5")
5314
     */
5315

5316
    this.insertTable = this.wrapCommand(function (dim) {
5317
      var dimension = dim.split('x');
5318

5319
      var rng = _this.getLastRange().deleteContents();
5320

5321
      rng.insertNode(_this.table.createTable(dimension[0], dimension[1], _this.options));
5322
    });
5323
    /**
5324
     * remove media object and Figure Elements if media object is img with Figure.
5325
     */
5326

5327
    this.removeMedia = this.wrapCommand(function () {
5328
      var $target = external_jQuery_default()(_this.restoreTarget()).parent();
5329

5330
      if ($target.closest('figure').length) {
5331
        $target.closest('figure').remove();
5332
      } else {
5333
        $target = external_jQuery_default()(_this.restoreTarget()).detach();
5334
      }
5335

5336
      _this.context.triggerEvent('media.delete', $target, _this.$editable);
5337
    });
5338
    /**
5339
     * float me
5340
     *
5341
     * @param {String} value
5342
     */
5343

5344
    this.floatMe = this.wrapCommand(function (value) {
5345
      var $target = external_jQuery_default()(_this.restoreTarget());
5346
      $target.toggleClass('note-float-left', value === 'left');
5347
      $target.toggleClass('note-float-right', value === 'right');
5348
      $target.css('float', value === 'none' ? '' : value);
5349
    });
5350
    /**
5351
     * resize overlay element
5352
     * @param {String} value
5353
     */
5354

5355
    this.resize = this.wrapCommand(function (value) {
5356
      var $target = external_jQuery_default()(_this.restoreTarget());
5357
      value = parseFloat(value);
5358

5359
      if (value === 0) {
5360
        $target.css('width', '');
5361
      } else {
5362
        $target.css({
5363
          width: value * 100 + '%',
5364
          height: ''
5365
        });
5366
      }
5367
    });
5368
  }
5369

5370
  Editor_createClass(Editor, [{
5371
    key: "initialize",
5372
    value: function initialize() {
5373
      var _this2 = this;
5374

5375
      // bind custom events
5376
      this.$editable.on('keydown', function (event) {
5377
        if (event.keyCode === key.code.ENTER) {
5378
          _this2.context.triggerEvent('enter', event);
5379
        }
5380

5381
        _this2.context.triggerEvent('keydown', event); // keep a snapshot to limit text on input event
5382

5383

5384
        _this2.snapshot = _this2.history.makeSnapshot();
5385
        _this2.hasKeyShortCut = false;
5386

5387
        if (!event.isDefaultPrevented()) {
5388
          if (_this2.options.shortcuts) {
5389
            _this2.hasKeyShortCut = _this2.handleKeyMap(event);
5390
          } else {
5391
            _this2.preventDefaultEditableShortCuts(event);
5392
          }
5393
        }
5394

5395
        if (_this2.isLimited(1, event)) {
5396
          var lastRange = _this2.getLastRange();
5397

5398
          if (lastRange.eo - lastRange.so === 0) {
5399
            return false;
5400
          }
5401
        }
5402

5403
        _this2.setLastRange(); // record undo in the key event except keyMap.
5404

5405

5406
        if (_this2.options.recordEveryKeystroke) {
5407
          if (_this2.hasKeyShortCut === false) {
5408
            _this2.history.recordUndo();
5409
          }
5410
        }
5411
      }).on('keyup', function (event) {
5412
        _this2.setLastRange();
5413

5414
        _this2.context.triggerEvent('keyup', event);
5415
      }).on('focus', function (event) {
5416
        _this2.setLastRange();
5417

5418
        _this2.context.triggerEvent('focus', event);
5419
      }).on('blur', function (event) {
5420
        _this2.context.triggerEvent('blur', event);
5421
      }).on('mousedown', function (event) {
5422
        _this2.context.triggerEvent('mousedown', event);
5423
      }).on('mouseup', function (event) {
5424
        _this2.setLastRange();
5425

5426
        _this2.history.recordUndo();
5427

5428
        _this2.context.triggerEvent('mouseup', event);
5429
      }).on('scroll', function (event) {
5430
        _this2.context.triggerEvent('scroll', event);
5431
      }).on('paste', function (event) {
5432
        _this2.setLastRange();
5433

5434
        _this2.context.triggerEvent('paste', event);
5435
      }).on('input', function () {
5436
        // To limit composition characters (e.g. Korean)
5437
        if (_this2.isLimited(0) && _this2.snapshot) {
5438
          _this2.history.applySnapshot(_this2.snapshot);
5439
        }
5440
      });
5441
      this.$editable.attr('spellcheck', this.options.spellCheck);
5442
      this.$editable.attr('autocorrect', this.options.spellCheck);
5443

5444
      if (this.options.disableGrammar) {
5445
        this.$editable.attr('data-gramm', false);
5446
      } // init content before set event
5447

5448

5449
      this.$editable.html(dom.html(this.$note) || dom.emptyPara);
5450
      this.$editable.on(env.inputEventName, func.debounce(function () {
5451
        _this2.context.triggerEvent('change', _this2.$editable.html(), _this2.$editable);
5452
      }, 10));
5453
      this.$editable.on('focusin', function (event) {
5454
        _this2.context.triggerEvent('focusin', event);
5455
      }).on('focusout', function (event) {
5456
        _this2.context.triggerEvent('focusout', event);
5457
      });
5458

5459
      if (this.options.airMode) {
5460
        if (this.options.overrideContextMenu) {
5461
          this.$editor.on('contextmenu', function (event) {
5462
            _this2.context.triggerEvent('contextmenu', event);
5463

5464
            return false;
5465
          });
5466
        }
5467
      } else {
5468
        if (this.options.width) {
5469
          this.$editor.outerWidth(this.options.width);
5470
        }
5471

5472
        if (this.options.height) {
5473
          this.$editable.outerHeight(this.options.height);
5474
        }
5475

5476
        if (this.options.maxHeight) {
5477
          this.$editable.css('max-height', this.options.maxHeight);
5478
        }
5479

5480
        if (this.options.minHeight) {
5481
          this.$editable.css('min-height', this.options.minHeight);
5482
        }
5483
      }
5484

5485
      this.history.recordUndo();
5486
      this.setLastRange();
5487
    }
5488
  }, {
5489
    key: "destroy",
5490
    value: function destroy() {
5491
      this.$editable.off();
5492
    }
5493
  }, {
5494
    key: "handleKeyMap",
5495
    value: function handleKeyMap(event) {
5496
      var keyMap = this.options.keyMap[env.isMac ? 'mac' : 'pc'];
5497
      var keys = [];
5498

5499
      if (event.metaKey) {
5500
        keys.push('CMD');
5501
      }
5502

5503
      if (event.ctrlKey && !event.altKey) {
5504
        keys.push('CTRL');
5505
      }
5506

5507
      if (event.shiftKey) {
5508
        keys.push('SHIFT');
5509
      }
5510

5511
      var keyName = key.nameFromCode[event.keyCode];
5512

5513
      if (keyName) {
5514
        keys.push(keyName);
5515
      }
5516

5517
      var eventName = keyMap[keys.join('+')];
5518

5519
      if (keyName === 'TAB' && !this.options.tabDisable) {
5520
        this.afterCommand();
5521
      } else if (eventName) {
5522
        if (this.context.invoke(eventName) !== false) {
5523
          event.preventDefault(); // if keyMap action was invoked
5524

5525
          return true;
5526
        }
5527
      } else if (key.isEdit(event.keyCode)) {
5528
        this.afterCommand();
5529
      }
5530

5531
      return false;
5532
    }
5533
  }, {
5534
    key: "preventDefaultEditableShortCuts",
5535
    value: function preventDefaultEditableShortCuts(event) {
5536
      // B(Bold, 66) / I(Italic, 73) / U(Underline, 85)
5537
      if ((event.ctrlKey || event.metaKey) && lists.contains([66, 73, 85], event.keyCode)) {
5538
        event.preventDefault();
5539
      }
5540
    }
5541
  }, {
5542
    key: "isLimited",
5543
    value: function isLimited(pad, event) {
5544
      pad = pad || 0;
5545

5546
      if (typeof event !== 'undefined') {
5547
        if (key.isMove(event.keyCode) || key.isNavigation(event.keyCode) || event.ctrlKey || event.metaKey || lists.contains([key.code.BACKSPACE, key.code.DELETE], event.keyCode)) {
5548
          return false;
5549
        }
5550
      }
5551

5552
      if (this.options.maxTextLength > 0) {
5553
        if (this.$editable.text().length + pad > this.options.maxTextLength) {
5554
          return true;
5555
        }
5556
      }
5557

5558
      return false;
5559
    }
5560
    /**
5561
     * create range
5562
     * @return {WrappedRange}
5563
     */
5564

5565
  }, {
5566
    key: "createRange",
5567
    value: function createRange() {
5568
      this.focus();
5569
      this.setLastRange();
5570
      return this.getLastRange();
5571
    }
5572
    /**
5573
     * create a new range from the list of elements
5574
     *
5575
     * @param {list} dom element list
5576
     * @return {WrappedRange}
5577
     */
5578

5579
  }, {
5580
    key: "createRangeFromList",
5581
    value: function createRangeFromList(lst) {
5582
      var startRange = range.createFromNodeBefore(lists.head(lst));
5583
      var startPoint = startRange.getStartPoint();
5584
      var endRange = range.createFromNodeAfter(lists.last(lst));
5585
      var endPoint = endRange.getEndPoint();
5586
      return range.create(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
5587
    }
5588
    /**
5589
     * set the last range
5590
     *
5591
     * if given rng is exist, set rng as the last range
5592
     * or create a new range at the end of the document
5593
     *
5594
     * @param {WrappedRange} rng
5595
     */
5596

5597
  }, {
5598
    key: "setLastRange",
5599
    value: function setLastRange(rng) {
5600
      if (rng) {
5601
        this.lastRange = rng;
5602
      } else {
5603
        this.lastRange = range.create(this.editable);
5604

5605
        if (external_jQuery_default()(this.lastRange.sc).closest('.note-editable').length === 0) {
5606
          this.lastRange = range.createFromBodyElement(this.editable);
5607
        }
5608
      }
5609
    }
5610
    /**
5611
     * get the last range
5612
     *
5613
     * if there is a saved last range, return it
5614
     * or create a new range and return it
5615
     *
5616
     * @return {WrappedRange}
5617
     */
5618

5619
  }, {
5620
    key: "getLastRange",
5621
    value: function getLastRange() {
5622
      if (!this.lastRange) {
5623
        this.setLastRange();
5624
      }
5625

5626
      return this.lastRange;
5627
    }
5628
    /**
5629
     * saveRange
5630
     *
5631
     * save current range
5632
     *
5633
     * @param {Boolean} [thenCollapse=false]
5634
     */
5635

5636
  }, {
5637
    key: "saveRange",
5638
    value: function saveRange(thenCollapse) {
5639
      if (thenCollapse) {
5640
        this.getLastRange().collapse().select();
5641
      }
5642
    }
5643
    /**
5644
     * restoreRange
5645
     *
5646
     * restore lately range
5647
     */
5648

5649
  }, {
5650
    key: "restoreRange",
5651
    value: function restoreRange() {
5652
      if (this.lastRange) {
5653
        this.lastRange.select();
5654
        this.focus();
5655
      }
5656
    }
5657
  }, {
5658
    key: "saveTarget",
5659
    value: function saveTarget(node) {
5660
      this.$editable.data('target', node);
5661
    }
5662
  }, {
5663
    key: "clearTarget",
5664
    value: function clearTarget() {
5665
      this.$editable.removeData('target');
5666
    }
5667
  }, {
5668
    key: "restoreTarget",
5669
    value: function restoreTarget() {
5670
      return this.$editable.data('target');
5671
    }
5672
    /**
5673
     * currentStyle
5674
     *
5675
     * current style
5676
     * @return {Object|Boolean} unfocus
5677
     */
5678

5679
  }, {
5680
    key: "currentStyle",
5681
    value: function currentStyle() {
5682
      var rng = range.create();
5683

5684
      if (rng) {
5685
        rng = rng.normalize();
5686
      }
5687

5688
      return rng ? this.style.current(rng) : this.style.fromNode(this.$editable);
5689
    }
5690
    /**
5691
     * style from node
5692
     *
5693
     * @param {jQuery} $node
5694
     * @return {Object}
5695
     */
5696

5697
  }, {
5698
    key: "styleFromNode",
5699
    value: function styleFromNode($node) {
5700
      return this.style.fromNode($node);
5701
    }
5702
    /**
5703
     * undo
5704
     */
5705

5706
  }, {
5707
    key: "undo",
5708
    value: function undo() {
5709
      this.context.triggerEvent('before.command', this.$editable.html());
5710
      this.history.undo();
5711
      this.context.triggerEvent('change', this.$editable.html(), this.$editable);
5712
    }
5713
    /*
5714
    * commit
5715
    */
5716

5717
  }, {
5718
    key: "commit",
5719
    value: function commit() {
5720
      this.context.triggerEvent('before.command', this.$editable.html());
5721
      this.history.commit();
5722
      this.context.triggerEvent('change', this.$editable.html(), this.$editable);
5723
    }
5724
    /**
5725
     * redo
5726
     */
5727

5728
  }, {
5729
    key: "redo",
5730
    value: function redo() {
5731
      this.context.triggerEvent('before.command', this.$editable.html());
5732
      this.history.redo();
5733
      this.context.triggerEvent('change', this.$editable.html(), this.$editable);
5734
    }
5735
    /**
5736
     * before command
5737
     */
5738

5739
  }, {
5740
    key: "beforeCommand",
5741
    value: function beforeCommand() {
5742
      this.context.triggerEvent('before.command', this.$editable.html()); // Set styleWithCSS before run a command
5743

5744
      document.execCommand('styleWithCSS', false, this.options.styleWithCSS); // keep focus on editable before command execution
5745

5746
      this.focus();
5747
    }
5748
    /**
5749
     * after command
5750
     * @param {Boolean} isPreventTrigger
5751
     */
5752

5753
  }, {
5754
    key: "afterCommand",
5755
    value: function afterCommand(isPreventTrigger) {
5756
      this.normalizeContent();
5757
      this.history.recordUndo();
5758

5759
      if (!isPreventTrigger) {
5760
        this.context.triggerEvent('change', this.$editable.html(), this.$editable);
5761
      }
5762
    }
5763
    /**
5764
     * handle tab key
5765
     */
5766

5767
  }, {
5768
    key: "tab",
5769
    value: function tab() {
5770
      var rng = this.getLastRange();
5771

5772
      if (rng.isCollapsed() && rng.isOnCell()) {
5773
        this.table.tab(rng);
5774
      } else {
5775
        if (this.options.tabSize === 0) {
5776
          return false;
5777
        }
5778

5779
        if (!this.isLimited(this.options.tabSize)) {
5780
          this.beforeCommand();
5781
          this.typing.insertTab(rng, this.options.tabSize);
5782
          this.afterCommand();
5783
        }
5784
      }
5785
    }
5786
    /**
5787
     * handle shift+tab key
5788
     */
5789

5790
  }, {
5791
    key: "untab",
5792
    value: function untab() {
5793
      var rng = this.getLastRange();
5794

5795
      if (rng.isCollapsed() && rng.isOnCell()) {
5796
        this.table.tab(rng, true);
5797
      } else {
5798
        if (this.options.tabSize === 0) {
5799
          return false;
5800
        }
5801
      }
5802
    }
5803
    /**
5804
     * run given function between beforeCommand and afterCommand
5805
     */
5806

5807
  }, {
5808
    key: "wrapCommand",
5809
    value: function wrapCommand(fn) {
5810
      return function () {
5811
        this.beforeCommand();
5812
        fn.apply(this, arguments);
5813
        this.afterCommand();
5814
      };
5815
    }
5816
    /**
5817
     * insert image
5818
     *
5819
     * @param {String} src
5820
     * @param {String|Function} param
5821
     * @return {Promise}
5822
     */
5823

5824
  }, {
5825
    key: "insertImage",
5826
    value: function insertImage(src, param) {
5827
      var _this3 = this;
5828

5829
      return createImage(src, param).then(function ($image) {
5830
        _this3.beforeCommand();
5831

5832
        if (typeof param === 'function') {
5833
          param($image);
5834
        } else {
5835
          if (typeof param === 'string') {
5836
            $image.attr('data-filename', param);
5837
          }
5838

5839
          $image.css('width', Math.min(_this3.$editable.width(), $image.width()));
5840
        }
5841

5842
        $image.show();
5843

5844
        _this3.getLastRange().insertNode($image[0]);
5845

5846
        _this3.setLastRange(range.createFromNodeAfter($image[0]).select());
5847

5848
        _this3.afterCommand();
5849
      }).fail(function (e) {
5850
        _this3.context.triggerEvent('image.upload.error', e);
5851
      });
5852
    }
5853
    /**
5854
     * insertImages
5855
     * @param {File[]} files
5856
     */
5857

5858
  }, {
5859
    key: "insertImagesAsDataURL",
5860
    value: function insertImagesAsDataURL(files) {
5861
      var _this4 = this;
5862

5863
      external_jQuery_default().each(files, function (idx, file) {
5864
        var filename = file.name;
5865

5866
        if (_this4.options.maximumImageFileSize && _this4.options.maximumImageFileSize < file.size) {
5867
          _this4.context.triggerEvent('image.upload.error', _this4.lang.image.maximumFileSizeError);
5868
        } else {
5869
          readFileAsDataURL(file).then(function (dataURL) {
5870
            return _this4.insertImage(dataURL, filename);
5871
          }).fail(function () {
5872
            _this4.context.triggerEvent('image.upload.error');
5873
          });
5874
        }
5875
      });
5876
    }
5877
    /**
5878
     * insertImagesOrCallback
5879
     * @param {File[]} files
5880
     */
5881

5882
  }, {
5883
    key: "insertImagesOrCallback",
5884
    value: function insertImagesOrCallback(files) {
5885
      var callbacks = this.options.callbacks; // If onImageUpload set,
5886

5887
      if (callbacks.onImageUpload) {
5888
        this.context.triggerEvent('image.upload', files); // else insert Image as dataURL
5889
      } else {
5890
        this.insertImagesAsDataURL(files);
5891
      }
5892
    }
5893
    /**
5894
     * return selected plain text
5895
     * @return {String} text
5896
     */
5897

5898
  }, {
5899
    key: "getSelectedText",
5900
    value: function getSelectedText() {
5901
      var rng = this.getLastRange(); // if range on anchor, expand range with anchor
5902

5903
      if (rng.isOnAnchor()) {
5904
        rng = range.createFromNode(dom.ancestor(rng.sc, dom.isAnchor));
5905
      }
5906

5907
      return rng.toString();
5908
    }
5909
  }, {
5910
    key: "onFormatBlock",
5911
    value: function onFormatBlock(tagName, $target) {
5912
      // [workaround] for MSIE, IE need `<`
5913
      document.execCommand('FormatBlock', false, env.isMSIE ? '<' + tagName + '>' : tagName); // support custom class
5914

5915
      if ($target && $target.length) {
5916
        // find the exact element has given tagName
5917
        if ($target[0].tagName.toUpperCase() !== tagName.toUpperCase()) {
5918
          $target = $target.find(tagName);
5919
        }
5920

5921
        if ($target && $target.length) {
5922
          var currentRange = this.createRange();
5923
          var $parent = external_jQuery_default()([currentRange.sc, currentRange.ec]).closest(tagName); // remove class added for current block
5924

5925
          $parent.removeClass();
5926
          var className = $target[0].className || '';
5927

5928
          if (className) {
5929
            $parent.addClass(className);
5930
          }
5931
        }
5932
      }
5933
    }
5934
  }, {
5935
    key: "formatPara",
5936
    value: function formatPara() {
5937
      this.formatBlock('P');
5938
    }
5939
  }, {
5940
    key: "fontStyling",
5941
    value: function fontStyling(target, value) {
5942
      var rng = this.getLastRange();
5943

5944
      if (rng !== '') {
5945
        var spans = this.style.styleNodes(rng);
5946
        this.$editor.find('.note-status-output').html('');
5947
        external_jQuery_default()(spans).css(target, value); // [workaround] added styled bogus span for style
5948
        //  - also bogus character needed for cursor position
5949

5950
        if (rng.isCollapsed()) {
5951
          var firstSpan = lists.head(spans);
5952

5953
          if (firstSpan && !dom.nodeLength(firstSpan)) {
5954
            firstSpan.innerHTML = dom.ZERO_WIDTH_NBSP_CHAR;
5955
            range.createFromNode(firstSpan.firstChild).select();
5956
            this.setLastRange();
5957
            this.$editable.data(KEY_BOGUS, firstSpan);
5958
          }
5959
        } else {
5960
          this.setLastRange(this.createRangeFromList(spans).select());
5961
        }
5962
      } else {
5963
        var noteStatusOutput = external_jQuery_default().now();
5964
        this.$editor.find('.note-status-output').html('<div id="note-status-output-' + noteStatusOutput + '" class="alert alert-info">' + this.lang.output.noSelection + '</div>');
5965
        setTimeout(function () {
5966
          external_jQuery_default()('#note-status-output-' + noteStatusOutput).remove();
5967
        }, 5000);
5968
      }
5969
    }
5970
    /**
5971
     * unlink
5972
     *
5973
     * @type command
5974
     */
5975

5976
  }, {
5977
    key: "unlink",
5978
    value: function unlink() {
5979
      var rng = this.getLastRange();
5980

5981
      if (rng.isOnAnchor()) {
5982
        var anchor = dom.ancestor(rng.sc, dom.isAnchor);
5983
        rng = range.createFromNode(anchor);
5984
        rng.select();
5985
        this.setLastRange();
5986
        this.beforeCommand();
5987
        document.execCommand('unlink');
5988
        this.afterCommand();
5989
      }
5990
    }
5991
    /**
5992
     * returns link info
5993
     *
5994
     * @return {Object}
5995
     * @return {WrappedRange} return.range
5996
     * @return {String} return.text
5997
     * @return {Boolean} [return.isNewWindow=true]
5998
     * @return {String} [return.url=""]
5999
     */
6000

6001
  }, {
6002
    key: "getLinkInfo",
6003
    value: function getLinkInfo() {
6004
      var rng = this.getLastRange().expand(dom.isAnchor); // Get the first anchor on range(for edit).
6005

6006
      var $anchor = external_jQuery_default()(lists.head(rng.nodes(dom.isAnchor)));
6007
      var linkInfo = {
6008
        range: rng,
6009
        text: rng.toString(),
6010
        url: $anchor.length ? $anchor.attr('href') : ''
6011
      }; // When anchor exists,
6012

6013
      if ($anchor.length) {
6014
        // Set isNewWindow by checking its target.
6015
        linkInfo.isNewWindow = $anchor.attr('target') === '_blank';
6016
      }
6017

6018
      return linkInfo;
6019
    }
6020
  }, {
6021
    key: "addRow",
6022
    value: function addRow(position) {
6023
      var rng = this.getLastRange(this.$editable);
6024

6025
      if (rng.isCollapsed() && rng.isOnCell()) {
6026
        this.beforeCommand();
6027
        this.table.addRow(rng, position);
6028
        this.afterCommand();
6029
      }
6030
    }
6031
  }, {
6032
    key: "addCol",
6033
    value: function addCol(position) {
6034
      var rng = this.getLastRange(this.$editable);
6035

6036
      if (rng.isCollapsed() && rng.isOnCell()) {
6037
        this.beforeCommand();
6038
        this.table.addCol(rng, position);
6039
        this.afterCommand();
6040
      }
6041
    }
6042
  }, {
6043
    key: "deleteRow",
6044
    value: function deleteRow() {
6045
      var rng = this.getLastRange(this.$editable);
6046

6047
      if (rng.isCollapsed() && rng.isOnCell()) {
6048
        this.beforeCommand();
6049
        this.table.deleteRow(rng);
6050
        this.afterCommand();
6051
      }
6052
    }
6053
  }, {
6054
    key: "deleteCol",
6055
    value: function deleteCol() {
6056
      var rng = this.getLastRange(this.$editable);
6057

6058
      if (rng.isCollapsed() && rng.isOnCell()) {
6059
        this.beforeCommand();
6060
        this.table.deleteCol(rng);
6061
        this.afterCommand();
6062
      }
6063
    }
6064
  }, {
6065
    key: "deleteTable",
6066
    value: function deleteTable() {
6067
      var rng = this.getLastRange(this.$editable);
6068

6069
      if (rng.isCollapsed() && rng.isOnCell()) {
6070
        this.beforeCommand();
6071
        this.table.deleteTable(rng);
6072
        this.afterCommand();
6073
      }
6074
    }
6075
    /**
6076
     * @param {Position} pos
6077
     * @param {jQuery} $target - target element
6078
     * @param {Boolean} [bKeepRatio] - keep ratio
6079
     */
6080

6081
  }, {
6082
    key: "resizeTo",
6083
    value: function resizeTo(pos, $target, bKeepRatio) {
6084
      var imageSize;
6085

6086
      if (bKeepRatio) {
6087
        var newRatio = pos.y / pos.x;
6088
        var ratio = $target.data('ratio');
6089
        imageSize = {
6090
          width: ratio > newRatio ? pos.x : pos.y / ratio,
6091
          height: ratio > newRatio ? pos.x * ratio : pos.y
6092
        };
6093
      } else {
6094
        imageSize = {
6095
          width: pos.x,
6096
          height: pos.y
6097
        };
6098
      }
6099

6100
      $target.css(imageSize);
6101
    }
6102
    /**
6103
     * returns whether editable area has focus or not.
6104
     */
6105

6106
  }, {
6107
    key: "hasFocus",
6108
    value: function hasFocus() {
6109
      return this.$editable.is(':focus');
6110
    }
6111
    /**
6112
     * set focus
6113
     */
6114

6115
  }, {
6116
    key: "focus",
6117
    value: function focus() {
6118
      // [workaround] Screen will move when page is scolled in IE.
6119
      //  - do focus when not focused
6120
      if (!this.hasFocus()) {
6121
        this.$editable.focus();
6122
      }
6123
    }
6124
    /**
6125
     * returns whether contents is empty or not.
6126
     * @return {Boolean}
6127
     */
6128

6129
  }, {
6130
    key: "isEmpty",
6131
    value: function isEmpty() {
6132
      return dom.isEmpty(this.$editable[0]) || dom.emptyPara === this.$editable.html();
6133
    }
6134
    /**
6135
     * Removes all contents and restores the editable instance to an _emptyPara_.
6136
     */
6137

6138
  }, {
6139
    key: "empty",
6140
    value: function empty() {
6141
      this.context.invoke('code', dom.emptyPara);
6142
    }
6143
    /**
6144
     * normalize content
6145
     */
6146

6147
  }, {
6148
    key: "normalizeContent",
6149
    value: function normalizeContent() {
6150
      this.$editable[0].normalize();
6151
    }
6152
  }]);
6153

6154
  return Editor;
6155
}();
6156

6157

6158
;// CONCATENATED MODULE: ./src/js/module/Clipboard.js
6159
function Clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6160

6161
function Clipboard_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6162

6163
function Clipboard_createClass(Constructor, protoProps, staticProps) { if (protoProps) Clipboard_defineProperties(Constructor.prototype, protoProps); if (staticProps) Clipboard_defineProperties(Constructor, staticProps); return Constructor; }
6164

6165

6166

6167
var Clipboard = /*#__PURE__*/function () {
6168
  function Clipboard(context) {
6169
    Clipboard_classCallCheck(this, Clipboard);
6170

6171
    this.context = context;
6172
    this.$editable = context.layoutInfo.editable;
6173
  }
6174

6175
  Clipboard_createClass(Clipboard, [{
6176
    key: "initialize",
6177
    value: function initialize() {
6178
      this.$editable.on('paste', this.pasteByEvent.bind(this));
6179
    }
6180
    /**
6181
     * paste by clipboard event
6182
     *
6183
     * @param {Event} event
6184
     */
6185

6186
  }, {
6187
    key: "pasteByEvent",
6188
    value: function pasteByEvent(event) {
6189
      var _this = this;
6190

6191
      var clipboardData = event.originalEvent.clipboardData;
6192

6193
      if (clipboardData && clipboardData.items && clipboardData.items.length) {
6194
        var item = clipboardData.items.length > 1 ? clipboardData.items[1] : lists.head(clipboardData.items);
6195

6196
        if (item.kind === 'file' && item.type.indexOf('image/') !== -1) {
6197
          // paste img file
6198
          this.context.invoke('editor.insertImagesOrCallback', [item.getAsFile()]);
6199
          event.preventDefault();
6200
        } else if (item.kind === 'string') {
6201
          // paste text with maxTextLength check
6202
          if (this.context.invoke('editor.isLimited', clipboardData.getData('Text').length)) {
6203
            event.preventDefault();
6204
          }
6205
        }
6206
      } else if (window.clipboardData) {
6207
        // for IE
6208
        var text = window.clipboardData.getData('text');
6209

6210
        if (this.context.invoke('editor.isLimited', text.length)) {
6211
          event.preventDefault();
6212
        }
6213
      } // Call editor.afterCommand after proceeding default event handler
6214

6215

6216
      setTimeout(function () {
6217
        _this.context.invoke('editor.afterCommand');
6218
      }, 10);
6219
    }
6220
  }]);
6221

6222
  return Clipboard;
6223
}();
6224

6225

6226
;// CONCATENATED MODULE: ./src/js/module/Dropzone.js
6227
function Dropzone_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6228

6229
function Dropzone_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6230

6231
function Dropzone_createClass(Constructor, protoProps, staticProps) { if (protoProps) Dropzone_defineProperties(Constructor.prototype, protoProps); if (staticProps) Dropzone_defineProperties(Constructor, staticProps); return Constructor; }
6232

6233

6234

6235
var Dropzone = /*#__PURE__*/function () {
6236
  function Dropzone(context) {
6237
    Dropzone_classCallCheck(this, Dropzone);
6238

6239
    this.context = context;
6240
    this.$eventListener = external_jQuery_default()(document);
6241
    this.$editor = context.layoutInfo.editor;
6242
    this.$editable = context.layoutInfo.editable;
6243
    this.options = context.options;
6244
    this.lang = this.options.langInfo;
6245
    this.documentEventHandlers = {};
6246
    this.$dropzone = external_jQuery_default()(['<div class="note-dropzone">', '<div class="note-dropzone-message"></div>', '</div>'].join('')).prependTo(this.$editor);
6247
  }
6248
  /**
6249
   * attach Drag and Drop Events
6250
   */
6251

6252

6253
  Dropzone_createClass(Dropzone, [{
6254
    key: "initialize",
6255
    value: function initialize() {
6256
      if (this.options.disableDragAndDrop) {
6257
        // prevent default drop event
6258
        this.documentEventHandlers.onDrop = function (e) {
6259
          e.preventDefault();
6260
        }; // do not consider outside of dropzone
6261

6262

6263
        this.$eventListener = this.$dropzone;
6264
        this.$eventListener.on('drop', this.documentEventHandlers.onDrop);
6265
      } else {
6266
        this.attachDragAndDropEvent();
6267
      }
6268
    }
6269
    /**
6270
     * attach Drag and Drop Events
6271
     */
6272

6273
  }, {
6274
    key: "attachDragAndDropEvent",
6275
    value: function attachDragAndDropEvent() {
6276
      var _this = this;
6277

6278
      var collection = external_jQuery_default()();
6279
      var $dropzoneMessage = this.$dropzone.find('.note-dropzone-message');
6280

6281
      this.documentEventHandlers.onDragenter = function (e) {
6282
        var isCodeview = _this.context.invoke('codeview.isActivated');
6283

6284
        var hasEditorSize = _this.$editor.width() > 0 && _this.$editor.height() > 0;
6285

6286
        if (!isCodeview && !collection.length && hasEditorSize) {
6287
          _this.$editor.addClass('dragover');
6288

6289
          _this.$dropzone.width(_this.$editor.width());
6290

6291
          _this.$dropzone.height(_this.$editor.height());
6292

6293
          $dropzoneMessage.text(_this.lang.image.dragImageHere);
6294
        }
6295

6296
        collection = collection.add(e.target);
6297
      };
6298

6299
      this.documentEventHandlers.onDragleave = function (e) {
6300
        collection = collection.not(e.target); // If nodeName is BODY, then just make it over (fix for IE)
6301

6302
        if (!collection.length || e.target.nodeName === 'BODY') {
6303
          collection = external_jQuery_default()();
6304

6305
          _this.$editor.removeClass('dragover');
6306
        }
6307
      };
6308

6309
      this.documentEventHandlers.onDrop = function () {
6310
        collection = external_jQuery_default()();
6311

6312
        _this.$editor.removeClass('dragover');
6313
      }; // show dropzone on dragenter when dragging a object to document
6314
      // -but only if the editor is visible, i.e. has a positive width and height
6315

6316

6317
      this.$eventListener.on('dragenter', this.documentEventHandlers.onDragenter).on('dragleave', this.documentEventHandlers.onDragleave).on('drop', this.documentEventHandlers.onDrop); // change dropzone's message on hover.
6318

6319
      this.$dropzone.on('dragenter', function () {
6320
        _this.$dropzone.addClass('hover');
6321

6322
        $dropzoneMessage.text(_this.lang.image.dropImage);
6323
      }).on('dragleave', function () {
6324
        _this.$dropzone.removeClass('hover');
6325

6326
        $dropzoneMessage.text(_this.lang.image.dragImageHere);
6327
      }); // attach dropImage
6328

6329
      this.$dropzone.on('drop', function (event) {
6330
        var dataTransfer = event.originalEvent.dataTransfer; // stop the browser from opening the dropped content
6331

6332
        event.preventDefault();
6333

6334
        if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
6335
          _this.$editable.focus();
6336

6337
          _this.context.invoke('editor.insertImagesOrCallback', dataTransfer.files);
6338
        } else {
6339
          external_jQuery_default().each(dataTransfer.types, function (idx, type) {
6340
            // skip moz-specific types
6341
            if (type.toLowerCase().indexOf('_moz_') > -1) {
6342
              return;
6343
            }
6344

6345
            var content = dataTransfer.getData(type);
6346

6347
            if (type.toLowerCase().indexOf('text') > -1) {
6348
              _this.context.invoke('editor.pasteHTML', content);
6349
            } else {
6350
              external_jQuery_default()(content).each(function (idx, item) {
6351
                _this.context.invoke('editor.insertNode', item);
6352
              });
6353
            }
6354
          });
6355
        }
6356
      }).on('dragover', false); // prevent default dragover event
6357
    }
6358
  }, {
6359
    key: "destroy",
6360
    value: function destroy() {
6361
      var _this2 = this;
6362

6363
      Object.keys(this.documentEventHandlers).forEach(function (key) {
6364
        _this2.$eventListener.off(key.substr(2).toLowerCase(), _this2.documentEventHandlers[key]);
6365
      });
6366
      this.documentEventHandlers = {};
6367
    }
6368
  }]);
6369

6370
  return Dropzone;
6371
}();
6372

6373

6374
;// CONCATENATED MODULE: ./src/js/module/Codeview.js
6375
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
6376

6377
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6378

6379
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6380

6381
function Codeview_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6382

6383
function Codeview_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6384

6385
function Codeview_createClass(Constructor, protoProps, staticProps) { if (protoProps) Codeview_defineProperties(Constructor.prototype, protoProps); if (staticProps) Codeview_defineProperties(Constructor, staticProps); return Constructor; }
6386

6387

6388

6389
/**
6390
 * @class Codeview
6391
 */
6392

6393
var CodeView = /*#__PURE__*/function () {
6394
  function CodeView(context) {
6395
    Codeview_classCallCheck(this, CodeView);
6396

6397
    this.context = context;
6398
    this.$editor = context.layoutInfo.editor;
6399
    this.$editable = context.layoutInfo.editable;
6400
    this.$codable = context.layoutInfo.codable;
6401
    this.options = context.options;
6402
    this.CodeMirrorConstructor = window.CodeMirror;
6403

6404
    if (this.options.codemirror.CodeMirrorConstructor) {
6405
      this.CodeMirrorConstructor = this.options.codemirror.CodeMirrorConstructor;
6406
    }
6407
  }
6408

6409
  Codeview_createClass(CodeView, [{
6410
    key: "sync",
6411
    value: function sync(html) {
6412
      var isCodeview = this.isActivated();
6413
      var CodeMirror = this.CodeMirrorConstructor;
6414

6415
      if (isCodeview) {
6416
        if (html) {
6417
          if (CodeMirror) {
6418
            this.$codable.data('cmEditor').getDoc().setValue(html);
6419
          } else {
6420
            this.$codable.val(html);
6421
          }
6422
        } else {
6423
          if (CodeMirror) {
6424
            this.$codable.data('cmEditor').save();
6425
          }
6426
        }
6427
      }
6428
    }
6429
  }, {
6430
    key: "initialize",
6431
    value: function initialize() {
6432
      var _this = this;
6433

6434
      this.$codable.on('keyup', function (event) {
6435
        if (event.keyCode === key.code.ESCAPE) {
6436
          _this.deactivate();
6437
        }
6438
      });
6439
    }
6440
    /**
6441
     * @return {Boolean}
6442
     */
6443

6444
  }, {
6445
    key: "isActivated",
6446
    value: function isActivated() {
6447
      return this.$editor.hasClass('codeview');
6448
    }
6449
    /**
6450
     * toggle codeview
6451
     */
6452

6453
  }, {
6454
    key: "toggle",
6455
    value: function toggle() {
6456
      if (this.isActivated()) {
6457
        this.deactivate();
6458
      } else {
6459
        this.activate();
6460
      }
6461

6462
      this.context.triggerEvent('codeview.toggled');
6463
    }
6464
    /**
6465
     * purify input value
6466
     * @param value
6467
     * @returns {*}
6468
     */
6469

6470
  }, {
6471
    key: "purify",
6472
    value: function purify(value) {
6473
      if (this.options.codeviewFilter) {
6474
        // filter code view regex
6475
        value = value.replace(this.options.codeviewFilterRegex, ''); // allow specific iframe tag
6476

6477
        if (this.options.codeviewIframeFilter) {
6478
          var whitelist = this.options.codeviewIframeWhitelistSrc.concat(this.options.codeviewIframeWhitelistSrcBase);
6479
          value = value.replace(/(<iframe.*?>.*?(?:<\/iframe>)?)/gi, function (tag) {
6480
            // remove if src attribute is duplicated
6481
            if (/<.+src(?==?('|"|\s)?)[\s\S]+src(?=('|"|\s)?)[^>]*?>/i.test(tag)) {
6482
              return '';
6483
            }
6484

6485
            var _iterator = _createForOfIteratorHelper(whitelist),
6486
                _step;
6487

6488
            try {
6489
              for (_iterator.s(); !(_step = _iterator.n()).done;) {
6490
                var src = _step.value;
6491

6492
                // pass if src is trusted
6493
                if (new RegExp('src="(https?:)?\/\/' + src.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '\/(.+)"').test(tag)) {
6494
                  return tag;
6495
                }
6496
              }
6497
            } catch (err) {
6498
              _iterator.e(err);
6499
            } finally {
6500
              _iterator.f();
6501
            }
6502

6503
            return '';
6504
          });
6505
        }
6506
      }
6507

6508
      return value;
6509
    }
6510
    /**
6511
     * activate code view
6512
     */
6513

6514
  }, {
6515
    key: "activate",
6516
    value: function activate() {
6517
      var _this2 = this;
6518

6519
      var CodeMirror = this.CodeMirrorConstructor;
6520
      this.$codable.val(dom.html(this.$editable, this.options.prettifyHtml));
6521
      this.$codable.height(this.$editable.height());
6522
      this.context.invoke('toolbar.updateCodeview', true);
6523
      this.context.invoke('airPopover.updateCodeview', true);
6524
      this.$editor.addClass('codeview');
6525
      this.$codable.focus(); // activate CodeMirror as codable
6526

6527
      if (CodeMirror) {
6528
        var cmEditor = CodeMirror.fromTextArea(this.$codable[0], this.options.codemirror); // CodeMirror TernServer
6529

6530
        if (this.options.codemirror.tern) {
6531
          var server = new CodeMirror.TernServer(this.options.codemirror.tern);
6532
          cmEditor.ternServer = server;
6533
          cmEditor.on('cursorActivity', function (cm) {
6534
            server.updateArgHints(cm);
6535
          });
6536
        }
6537

6538
        cmEditor.on('blur', function (event) {
6539
          _this2.context.triggerEvent('blur.codeview', cmEditor.getValue(), event);
6540
        });
6541
        cmEditor.on('change', function () {
6542
          _this2.context.triggerEvent('change.codeview', cmEditor.getValue(), cmEditor);
6543
        }); // CodeMirror hasn't Padding.
6544

6545
        cmEditor.setSize(null, this.$editable.outerHeight());
6546
        this.$codable.data('cmEditor', cmEditor);
6547
      } else {
6548
        this.$codable.on('blur', function (event) {
6549
          _this2.context.triggerEvent('blur.codeview', _this2.$codable.val(), event);
6550
        });
6551
        this.$codable.on('input', function () {
6552
          _this2.context.triggerEvent('change.codeview', _this2.$codable.val(), _this2.$codable);
6553
        });
6554
      }
6555
    }
6556
    /**
6557
     * deactivate code view
6558
     */
6559

6560
  }, {
6561
    key: "deactivate",
6562
    value: function deactivate() {
6563
      var CodeMirror = this.CodeMirrorConstructor; // deactivate CodeMirror as codable
6564

6565
      if (CodeMirror) {
6566
        var cmEditor = this.$codable.data('cmEditor');
6567
        this.$codable.val(cmEditor.getValue());
6568
        cmEditor.toTextArea();
6569
      }
6570

6571
      var value = this.purify(dom.value(this.$codable, this.options.prettifyHtml) || dom.emptyPara);
6572
      var isChange = this.$editable.html() !== value;
6573
      this.$editable.html(value);
6574
      this.$editable.height(this.options.height ? this.$codable.height() : 'auto');
6575
      this.$editor.removeClass('codeview');
6576

6577
      if (isChange) {
6578
        this.context.triggerEvent('change', this.$editable.html(), this.$editable);
6579
      }
6580

6581
      this.$editable.focus();
6582
      this.context.invoke('toolbar.updateCodeview', false);
6583
      this.context.invoke('airPopover.updateCodeview', false);
6584
    }
6585
  }, {
6586
    key: "destroy",
6587
    value: function destroy() {
6588
      if (this.isActivated()) {
6589
        this.deactivate();
6590
      }
6591
    }
6592
  }]);
6593

6594
  return CodeView;
6595
}();
6596

6597

6598
;// CONCATENATED MODULE: ./src/js/module/Statusbar.js
6599
function Statusbar_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6600

6601
function Statusbar_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6602

6603
function Statusbar_createClass(Constructor, protoProps, staticProps) { if (protoProps) Statusbar_defineProperties(Constructor.prototype, protoProps); if (staticProps) Statusbar_defineProperties(Constructor, staticProps); return Constructor; }
6604

6605

6606
var EDITABLE_PADDING = 24;
6607

6608
var Statusbar = /*#__PURE__*/function () {
6609
  function Statusbar(context) {
6610
    Statusbar_classCallCheck(this, Statusbar);
6611

6612
    this.$document = external_jQuery_default()(document);
6613
    this.$statusbar = context.layoutInfo.statusbar;
6614
    this.$editable = context.layoutInfo.editable;
6615
    this.$codable = context.layoutInfo.codable;
6616
    this.options = context.options;
6617
  }
6618

6619
  Statusbar_createClass(Statusbar, [{
6620
    key: "initialize",
6621
    value: function initialize() {
6622
      var _this = this;
6623

6624
      if (this.options.airMode || this.options.disableResizeEditor) {
6625
        this.destroy();
6626
        return;
6627
      }
6628

6629
      this.$statusbar.on('mousedown', function (event) {
6630
        event.preventDefault();
6631
        event.stopPropagation();
6632

6633
        var editableTop = _this.$editable.offset().top - _this.$document.scrollTop();
6634

6635
        var editableCodeTop = _this.$codable.offset().top - _this.$document.scrollTop();
6636

6637
        var onMouseMove = function onMouseMove(event) {
6638
          var height = event.clientY - (editableTop + EDITABLE_PADDING);
6639
          var heightCode = event.clientY - (editableCodeTop + EDITABLE_PADDING);
6640
          height = _this.options.minheight > 0 ? Math.max(height, _this.options.minheight) : height;
6641
          height = _this.options.maxHeight > 0 ? Math.min(height, _this.options.maxHeight) : height;
6642
          heightCode = _this.options.minheight > 0 ? Math.max(heightCode, _this.options.minheight) : heightCode;
6643
          heightCode = _this.options.maxHeight > 0 ? Math.min(heightCode, _this.options.maxHeight) : heightCode;
6644

6645
          _this.$editable.height(height);
6646

6647
          _this.$codable.height(heightCode);
6648
        };
6649

6650
        _this.$document.on('mousemove', onMouseMove).one('mouseup', function () {
6651
          _this.$document.off('mousemove', onMouseMove);
6652
        });
6653
      });
6654
    }
6655
  }, {
6656
    key: "destroy",
6657
    value: function destroy() {
6658
      this.$statusbar.off();
6659
      this.$statusbar.addClass('locked');
6660
    }
6661
  }]);
6662

6663
  return Statusbar;
6664
}();
6665

6666

6667
;// CONCATENATED MODULE: ./src/js/module/Fullscreen.js
6668
function Fullscreen_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6669

6670
function Fullscreen_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6671

6672
function Fullscreen_createClass(Constructor, protoProps, staticProps) { if (protoProps) Fullscreen_defineProperties(Constructor.prototype, protoProps); if (staticProps) Fullscreen_defineProperties(Constructor, staticProps); return Constructor; }
6673

6674

6675

6676
var Fullscreen = /*#__PURE__*/function () {
6677
  function Fullscreen(context) {
6678
    var _this = this;
6679

6680
    Fullscreen_classCallCheck(this, Fullscreen);
6681

6682
    this.context = context;
6683
    this.$editor = context.layoutInfo.editor;
6684
    this.$toolbar = context.layoutInfo.toolbar;
6685
    this.$editable = context.layoutInfo.editable;
6686
    this.$codable = context.layoutInfo.codable;
6687
    this.$window = external_jQuery_default()(window);
6688
    this.$scrollbar = external_jQuery_default()('html, body');
6689
    this.scrollbarClassName = 'note-fullscreen-body';
6690

6691
    this.onResize = function () {
6692
      _this.resizeTo({
6693
        h: _this.$window.height() - _this.$toolbar.outerHeight()
6694
      });
6695
    };
6696
  }
6697

6698
  Fullscreen_createClass(Fullscreen, [{
6699
    key: "resizeTo",
6700
    value: function resizeTo(size) {
6701
      this.$editable.css('height', size.h);
6702
      this.$codable.css('height', size.h);
6703

6704
      if (this.$codable.data('cmeditor')) {
6705
        this.$codable.data('cmeditor').setsize(null, size.h);
6706
      }
6707
    }
6708
    /**
6709
     * toggle fullscreen
6710
     */
6711

6712
  }, {
6713
    key: "toggle",
6714
    value: function toggle() {
6715
      this.$editor.toggleClass('fullscreen');
6716
      var isFullscreen = this.isFullscreen();
6717
      this.$scrollbar.toggleClass(this.scrollbarClassName, isFullscreen);
6718

6719
      if (isFullscreen) {
6720
        this.$editable.data('orgHeight', this.$editable.css('height'));
6721
        this.$editable.data('orgMaxHeight', this.$editable.css('maxHeight'));
6722
        this.$editable.css('maxHeight', '');
6723
        this.$window.on('resize', this.onResize).trigger('resize');
6724
      } else {
6725
        this.$window.off('resize', this.onResize);
6726
        this.resizeTo({
6727
          h: this.$editable.data('orgHeight')
6728
        });
6729
        this.$editable.css('maxHeight', this.$editable.css('orgMaxHeight'));
6730
      }
6731

6732
      this.context.invoke('toolbar.updateFullscreen', isFullscreen);
6733
    }
6734
  }, {
6735
    key: "isFullscreen",
6736
    value: function isFullscreen() {
6737
      return this.$editor.hasClass('fullscreen');
6738
    }
6739
  }, {
6740
    key: "destroy",
6741
    value: function destroy() {
6742
      this.$scrollbar.removeClass(this.scrollbarClassName);
6743
    }
6744
  }]);
6745

6746
  return Fullscreen;
6747
}();
6748

6749

6750
;// CONCATENATED MODULE: ./src/js/module/Handle.js
6751
function Handle_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6752

6753
function Handle_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6754

6755
function Handle_createClass(Constructor, protoProps, staticProps) { if (protoProps) Handle_defineProperties(Constructor.prototype, protoProps); if (staticProps) Handle_defineProperties(Constructor, staticProps); return Constructor; }
6756

6757

6758

6759

6760
var Handle = /*#__PURE__*/function () {
6761
  function Handle(context) {
6762
    var _this = this;
6763

6764
    Handle_classCallCheck(this, Handle);
6765

6766
    this.context = context;
6767
    this.$document = external_jQuery_default()(document);
6768
    this.$editingArea = context.layoutInfo.editingArea;
6769
    this.options = context.options;
6770
    this.lang = this.options.langInfo;
6771
    this.events = {
6772
      'summernote.mousedown': function summernoteMousedown(we, e) {
6773
        if (_this.update(e.target, e)) {
6774
          e.preventDefault();
6775
        }
6776
      },
6777
      'summernote.keyup summernote.scroll summernote.change summernote.dialog.shown': function summernoteKeyupSummernoteScrollSummernoteChangeSummernoteDialogShown() {
6778
        _this.update();
6779
      },
6780
      'summernote.disable summernote.blur': function summernoteDisableSummernoteBlur() {
6781
        _this.hide();
6782
      },
6783
      'summernote.codeview.toggled': function summernoteCodeviewToggled() {
6784
        _this.update();
6785
      }
6786
    };
6787
  }
6788

6789
  Handle_createClass(Handle, [{
6790
    key: "initialize",
6791
    value: function initialize() {
6792
      var _this2 = this;
6793

6794
      this.$handle = external_jQuery_default()(['<div class="note-handle">', '<div class="note-control-selection">', '<div class="note-control-selection-bg"></div>', '<div class="note-control-holder note-control-nw"></div>', '<div class="note-control-holder note-control-ne"></div>', '<div class="note-control-holder note-control-sw"></div>', '<div class="', this.options.disableResizeImage ? 'note-control-holder' : 'note-control-sizing', ' note-control-se"></div>', this.options.disableResizeImage ? '' : '<div class="note-control-selection-info"></div>', '</div>', '</div>'].join('')).prependTo(this.$editingArea);
6795
      this.$handle.on('mousedown', function (event) {
6796
        if (dom.isControlSizing(event.target)) {
6797
          event.preventDefault();
6798
          event.stopPropagation();
6799

6800
          var $target = _this2.$handle.find('.note-control-selection').data('target');
6801

6802
          var posStart = $target.offset();
6803

6804
          var scrollTop = _this2.$document.scrollTop();
6805

6806
          var onMouseMove = function onMouseMove(event) {
6807
            _this2.context.invoke('editor.resizeTo', {
6808
              x: event.clientX - posStart.left,
6809
              y: event.clientY - (posStart.top - scrollTop)
6810
            }, $target, !event.shiftKey);
6811

6812
            _this2.update($target[0], event);
6813
          };
6814

6815
          _this2.$document.on('mousemove', onMouseMove).one('mouseup', function (e) {
6816
            e.preventDefault();
6817

6818
            _this2.$document.off('mousemove', onMouseMove);
6819

6820
            _this2.context.invoke('editor.afterCommand');
6821
          });
6822

6823
          if (!$target.data('ratio')) {
6824
            // original ratio.
6825
            $target.data('ratio', $target.height() / $target.width());
6826
          }
6827
        }
6828
      }); // Listen for scrolling on the handle overlay.
6829

6830
      this.$handle.on('wheel', function (e) {
6831
        e.preventDefault();
6832

6833
        _this2.update();
6834
      });
6835
    }
6836
  }, {
6837
    key: "destroy",
6838
    value: function destroy() {
6839
      this.$handle.remove();
6840
    }
6841
  }, {
6842
    key: "update",
6843
    value: function update(target, event) {
6844
      if (this.context.isDisabled()) {
6845
        return false;
6846
      }
6847

6848
      var isImage = dom.isImg(target);
6849
      var $selection = this.$handle.find('.note-control-selection');
6850
      this.context.invoke('imagePopover.update', target, event);
6851

6852
      if (isImage) {
6853
        var $image = external_jQuery_default()(target);
6854
        var position = $image.position();
6855
        var pos = {
6856
          left: position.left + parseInt($image.css('marginLeft'), 10),
6857
          top: position.top + parseInt($image.css('marginTop'), 10)
6858
        }; // exclude margin
6859

6860
        var imageSize = {
6861
          w: $image.outerWidth(false),
6862
          h: $image.outerHeight(false)
6863
        };
6864
        $selection.css({
6865
          display: 'block',
6866
          left: pos.left,
6867
          top: pos.top,
6868
          width: imageSize.w,
6869
          height: imageSize.h
6870
        }).data('target', $image); // save current image element.
6871

6872
        var origImageObj = new Image();
6873
        origImageObj.src = $image.attr('src');
6874
        var sizingText = imageSize.w + 'x' + imageSize.h + ' (' + this.lang.image.original + ': ' + origImageObj.width + 'x' + origImageObj.height + ')';
6875
        $selection.find('.note-control-selection-info').text(sizingText);
6876
        this.context.invoke('editor.saveTarget', target);
6877
      } else {
6878
        this.hide();
6879
      }
6880

6881
      return isImage;
6882
    }
6883
    /**
6884
     * hide
6885
     *
6886
     * @param {jQuery} $handle
6887
     */
6888

6889
  }, {
6890
    key: "hide",
6891
    value: function hide() {
6892
      this.context.invoke('editor.clearTarget');
6893
      this.$handle.children().hide();
6894
    }
6895
  }]);
6896

6897
  return Handle;
6898
}();
6899

6900

6901
;// CONCATENATED MODULE: ./src/js/module/AutoLink.js
6902
function AutoLink_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6903

6904
function AutoLink_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6905

6906
function AutoLink_createClass(Constructor, protoProps, staticProps) { if (protoProps) AutoLink_defineProperties(Constructor.prototype, protoProps); if (staticProps) AutoLink_defineProperties(Constructor, staticProps); return Constructor; }
6907

6908

6909

6910

6911
var defaultScheme = 'http://';
6912
var linkPattern = /^([A-Za-z][A-Za-z0-9+-.]*\:[\/]{2}|tel:|mailto:[A-Z0-9._%+-]+@|xmpp:[A-Z0-9._%+-]+@)?(www\.)?(.+)$/i;
6913

6914
var AutoLink = /*#__PURE__*/function () {
6915
  function AutoLink(context) {
6916
    var _this = this;
6917

6918
    AutoLink_classCallCheck(this, AutoLink);
6919

6920
    this.context = context;
6921
    this.options = context.options;
6922
    this.events = {
6923
      'summernote.keyup': function summernoteKeyup(we, e) {
6924
        if (!e.isDefaultPrevented()) {
6925
          _this.handleKeyup(e);
6926
        }
6927
      },
6928
      'summernote.keydown': function summernoteKeydown(we, e) {
6929
        _this.handleKeydown(e);
6930
      }
6931
    };
6932
  }
6933

6934
  AutoLink_createClass(AutoLink, [{
6935
    key: "initialize",
6936
    value: function initialize() {
6937
      this.lastWordRange = null;
6938
    }
6939
  }, {
6940
    key: "destroy",
6941
    value: function destroy() {
6942
      this.lastWordRange = null;
6943
    }
6944
  }, {
6945
    key: "replace",
6946
    value: function replace() {
6947
      if (!this.lastWordRange) {
6948
        return;
6949
      }
6950

6951
      var keyword = this.lastWordRange.toString();
6952
      var match = keyword.match(linkPattern);
6953

6954
      if (match && (match[1] || match[2])) {
6955
        var link = match[1] ? keyword : defaultScheme + keyword;
6956
        var urlText = this.options.showDomainOnlyForAutolink ? keyword.replace(/^(?:https?:\/\/)?(?:tel?:?)?(?:mailto?:?)?(?:xmpp?:?)?(?:www\.)?/i, '').split('/')[0] : keyword;
6957
        var node = external_jQuery_default()('<a></a>').html(urlText).attr('href', link)[0];
6958

6959
        if (this.context.options.linkTargetBlank) {
6960
          external_jQuery_default()(node).attr('target', '_blank');
6961
        }
6962

6963
        this.lastWordRange.insertNode(node);
6964
        this.lastWordRange = null;
6965
        this.context.invoke('editor.focus');
6966
      }
6967
    }
6968
  }, {
6969
    key: "handleKeydown",
6970
    value: function handleKeydown(e) {
6971
      if (lists.contains([key.code.ENTER, key.code.SPACE], e.keyCode)) {
6972
        var wordRange = this.context.invoke('editor.createRange').getWordRange();
6973
        this.lastWordRange = wordRange;
6974
      }
6975
    }
6976
  }, {
6977
    key: "handleKeyup",
6978
    value: function handleKeyup(e) {
6979
      if (lists.contains([key.code.ENTER, key.code.SPACE], e.keyCode)) {
6980
        this.replace();
6981
      }
6982
    }
6983
  }]);
6984

6985
  return AutoLink;
6986
}();
6987

6988

6989
;// CONCATENATED MODULE: ./src/js/module/AutoSync.js
6990
function AutoSync_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6991

6992
function AutoSync_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6993

6994
function AutoSync_createClass(Constructor, protoProps, staticProps) { if (protoProps) AutoSync_defineProperties(Constructor.prototype, protoProps); if (staticProps) AutoSync_defineProperties(Constructor, staticProps); return Constructor; }
6995

6996

6997
/**
6998
 * textarea auto sync.
6999
 */
7000

7001
var AutoSync = /*#__PURE__*/function () {
7002
  function AutoSync(context) {
7003
    var _this = this;
7004

7005
    AutoSync_classCallCheck(this, AutoSync);
7006

7007
    this.$note = context.layoutInfo.note;
7008
    this.events = {
7009
      'summernote.change': function summernoteChange() {
7010
        _this.$note.val(context.invoke('code'));
7011
      }
7012
    };
7013
  }
7014

7015
  AutoSync_createClass(AutoSync, [{
7016
    key: "shouldInitialize",
7017
    value: function shouldInitialize() {
7018
      return dom.isTextarea(this.$note[0]);
7019
    }
7020
  }]);
7021

7022
  return AutoSync;
7023
}();
7024

7025

7026
;// CONCATENATED MODULE: ./src/js/module/AutoReplace.js
7027
function AutoReplace_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7028

7029
function AutoReplace_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
7030

7031
function AutoReplace_createClass(Constructor, protoProps, staticProps) { if (protoProps) AutoReplace_defineProperties(Constructor.prototype, protoProps); if (staticProps) AutoReplace_defineProperties(Constructor, staticProps); return Constructor; }
7032

7033

7034

7035

7036

7037
var AutoReplace = /*#__PURE__*/function () {
7038
  function AutoReplace(context) {
7039
    var _this = this;
7040

7041
    AutoReplace_classCallCheck(this, AutoReplace);
7042

7043
    this.context = context;
7044
    this.options = context.options.replace || {};
7045
    this.keys = [key.code.ENTER, key.code.SPACE, key.code.PERIOD, key.code.COMMA, key.code.SEMICOLON, key.code.SLASH];
7046
    this.previousKeydownCode = null;
7047
    this.events = {
7048
      'summernote.keyup': function summernoteKeyup(we, e) {
7049
        if (!e.isDefaultPrevented()) {
7050
          _this.handleKeyup(e);
7051
        }
7052
      },
7053
      'summernote.keydown': function summernoteKeydown(we, e) {
7054
        _this.handleKeydown(e);
7055
      }
7056
    };
7057
  }
7058

7059
  AutoReplace_createClass(AutoReplace, [{
7060
    key: "shouldInitialize",
7061
    value: function shouldInitialize() {
7062
      return !!this.options.match;
7063
    }
7064
  }, {
7065
    key: "initialize",
7066
    value: function initialize() {
7067
      this.lastWord = null;
7068
    }
7069
  }, {
7070
    key: "destroy",
7071
    value: function destroy() {
7072
      this.lastWord = null;
7073
    }
7074
  }, {
7075
    key: "replace",
7076
    value: function replace() {
7077
      if (!this.lastWord) {
7078
        return;
7079
      }
7080

7081
      var self = this;
7082
      var keyword = this.lastWord.toString();
7083
      this.options.match(keyword, function (match) {
7084
        if (match) {
7085
          var node = '';
7086

7087
          if (typeof match === 'string') {
7088
            node = dom.createText(match);
7089
          } else if (match instanceof jQuery) {
7090
            node = match[0];
7091
          } else if (match instanceof Node) {
7092
            node = match;
7093
          }
7094

7095
          if (!node) return;
7096
          self.lastWord.insertNode(node);
7097
          self.lastWord = null;
7098
          self.context.invoke('editor.focus');
7099
        }
7100
      });
7101
    }
7102
  }, {
7103
    key: "handleKeydown",
7104
    value: function handleKeydown(e) {
7105
      // this forces it to remember the last whole word, even if multiple termination keys are pressed
7106
      // before the previous key is let go.
7107
      if (this.previousKeydownCode && lists.contains(this.keys, this.previousKeydownCode)) {
7108
        this.previousKeydownCode = e.keyCode;
7109
        return;
7110
      }
7111

7112
      if (lists.contains(this.keys, e.keyCode)) {
7113
        var wordRange = this.context.invoke('editor.createRange').getWordRange();
7114
        this.lastWord = wordRange;
7115
      }
7116

7117
      this.previousKeydownCode = e.keyCode;
7118
    }
7119
  }, {
7120
    key: "handleKeyup",
7121
    value: function handleKeyup(e) {
7122
      if (lists.contains(this.keys, e.keyCode)) {
7123
        this.replace();
7124
      }
7125
    }
7126
  }]);
7127

7128
  return AutoReplace;
7129
}();
7130

7131

7132
;// CONCATENATED MODULE: ./src/js/module/Placeholder.js
7133
function Placeholder_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7134

7135
function Placeholder_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
7136

7137
function Placeholder_createClass(Constructor, protoProps, staticProps) { if (protoProps) Placeholder_defineProperties(Constructor.prototype, protoProps); if (staticProps) Placeholder_defineProperties(Constructor, staticProps); return Constructor; }
7138

7139

7140

7141
var Placeholder = /*#__PURE__*/function () {
7142
  function Placeholder(context) {
7143
    var _this = this;
7144

7145
    Placeholder_classCallCheck(this, Placeholder);
7146

7147
    this.context = context;
7148
    this.$editingArea = context.layoutInfo.editingArea;
7149
    this.options = context.options;
7150

7151
    if (this.options.inheritPlaceholder === true) {
7152
      // get placeholder value from the original element
7153
      this.options.placeholder = this.context.$note.attr('placeholder') || this.options.placeholder;
7154
    }
7155

7156
    this.events = {
7157
      'summernote.init summernote.change': function summernoteInitSummernoteChange() {
7158
        _this.update();
7159
      },
7160
      'summernote.codeview.toggled': function summernoteCodeviewToggled() {
7161
        _this.update();
7162
      }
7163
    };
7164
  }
7165

7166
  Placeholder_createClass(Placeholder, [{
7167
    key: "shouldInitialize",
7168
    value: function shouldInitialize() {
7169
      return !!this.options.placeholder;
7170
    }
7171
  }, {
7172
    key: "initialize",
7173
    value: function initialize() {
7174
      var _this2 = this;
7175

7176
      this.$placeholder = external_jQuery_default()('<div class="note-placeholder"></div>');
7177
      this.$placeholder.on('click', function () {
7178
        _this2.context.invoke('focus');
7179
      }).html(this.options.placeholder).prependTo(this.$editingArea);
7180
      this.update();
7181
    }
7182
  }, {
7183
    key: "destroy",
7184
    value: function destroy() {
7185
      this.$placeholder.remove();
7186
    }
7187
  }, {
7188
    key: "update",
7189
    value: function update() {
7190
      var isShow = !this.context.invoke('codeview.isActivated') && this.context.invoke('editor.isEmpty');
7191
      this.$placeholder.toggle(isShow);
7192
    }
7193
  }]);
7194

7195
  return Placeholder;
7196
}();
7197

7198

7199
;// CONCATENATED MODULE: ./src/js/module/Buttons.js
7200
function Buttons_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7201

7202
function Buttons_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
7203

7204
function Buttons_createClass(Constructor, protoProps, staticProps) { if (protoProps) Buttons_defineProperties(Constructor.prototype, protoProps); if (staticProps) Buttons_defineProperties(Constructor, staticProps); return Constructor; }
7205

7206

7207

7208

7209

7210

7211
var Buttons = /*#__PURE__*/function () {
7212
  function Buttons(context) {
7213
    Buttons_classCallCheck(this, Buttons);
7214

7215
    this.ui = (external_jQuery_default()).summernote.ui;
7216
    this.context = context;
7217
    this.$toolbar = context.layoutInfo.toolbar;
7218
    this.options = context.options;
7219
    this.lang = this.options.langInfo;
7220
    this.invertedKeyMap = func.invertObject(this.options.keyMap[env.isMac ? 'mac' : 'pc']);
7221
  }
7222

7223
  Buttons_createClass(Buttons, [{
7224
    key: "representShortcut",
7225
    value: function representShortcut(editorMethod) {
7226
      var shortcut = this.invertedKeyMap[editorMethod];
7227

7228
      if (!this.options.shortcuts || !shortcut) {
7229
        return '';
7230
      }
7231

7232
      if (env.isMac) {
7233
        shortcut = shortcut.replace('CMD', '⌘').replace('SHIFT', '⇧');
7234
      }
7235

7236
      shortcut = shortcut.replace('BACKSLASH', '\\').replace('SLASH', '/').replace('LEFTBRACKET', '[').replace('RIGHTBRACKET', ']');
7237
      return ' (' + shortcut + ')';
7238
    }
7239
  }, {
7240
    key: "button",
7241
    value: function button(o) {
7242
      if (!this.options.tooltip && o.tooltip) {
7243
        delete o.tooltip;
7244
      }
7245

7246
      o.container = this.options.container;
7247
      return this.ui.button(o);
7248
    }
7249
  }, {
7250
    key: "initialize",
7251
    value: function initialize() {
7252
      this.addToolbarButtons();
7253
      this.addImagePopoverButtons();
7254
      this.addLinkPopoverButtons();
7255
      this.addTablePopoverButtons();
7256
      this.fontInstalledMap = {};
7257
    }
7258
  }, {
7259
    key: "destroy",
7260
    value: function destroy() {
7261
      delete this.fontInstalledMap;
7262
    }
7263
  }, {
7264
    key: "isFontInstalled",
7265
    value: function isFontInstalled(name) {
7266
      if (!Object.prototype.hasOwnProperty.call(this.fontInstalledMap, name)) {
7267
        this.fontInstalledMap[name] = env.isFontInstalled(name) || lists.contains(this.options.fontNamesIgnoreCheck, name);
7268
      }
7269

7270
      return this.fontInstalledMap[name];
7271
    }
7272
  }, {
7273
    key: "isFontDeservedToAdd",
7274
    value: function isFontDeservedToAdd(name) {
7275
      name = name.toLowerCase();
7276
      return name !== '' && this.isFontInstalled(name) && env.genericFontFamilies.indexOf(name) === -1;
7277
    }
7278
  }, {
7279
    key: "colorPalette",
7280
    value: function colorPalette(className, tooltip, backColor, foreColor) {
7281
      var _this = this;
7282

7283
      return this.ui.buttonGroup({
7284
        className: 'note-color ' + className,
7285
        children: [this.button({
7286
          className: 'note-current-color-button',
7287
          contents: this.ui.icon(this.options.icons.font + ' note-recent-color'),
7288
          tooltip: tooltip,
7289
          click: function click(e) {
7290
            var $button = external_jQuery_default()(e.currentTarget);
7291

7292
            if (backColor && foreColor) {
7293
              _this.context.invoke('editor.color', {
7294
                backColor: $button.attr('data-backColor'),
7295
                foreColor: $button.attr('data-foreColor')
7296
              });
7297
            } else if (backColor) {
7298
              _this.context.invoke('editor.color', {
7299
                backColor: $button.attr('data-backColor')
7300
              });
7301
            } else if (foreColor) {
7302
              _this.context.invoke('editor.color', {
7303
                foreColor: $button.attr('data-foreColor')
7304
              });
7305
            }
7306
          },
7307
          callback: function callback($button) {
7308
            var $recentColor = $button.find('.note-recent-color');
7309

7310
            if (backColor) {
7311
              $recentColor.css('background-color', _this.options.colorButton.backColor);
7312
              $button.attr('data-backColor', _this.options.colorButton.backColor);
7313
            }
7314

7315
            if (foreColor) {
7316
              $recentColor.css('color', _this.options.colorButton.foreColor);
7317
              $button.attr('data-foreColor', _this.options.colorButton.foreColor);
7318
            } else {
7319
              $recentColor.css('color', 'transparent');
7320
            }
7321
          }
7322
        }), this.button({
7323
          className: 'dropdown-toggle',
7324
          contents: this.ui.dropdownButtonContents('', this.options),
7325
          tooltip: this.lang.color.more,
7326
          data: {
7327
            toggle: 'dropdown'
7328
          }
7329
        }), this.ui.dropdown({
7330
          items: (backColor ? ['<div class="note-palette">', '<div class="note-palette-title">' + this.lang.color.background + '</div>', '<div>', '<button type="button" class="note-color-reset btn btn-light btn-default" data-event="backColor" data-value="transparent">', this.lang.color.transparent, '</button>', '</div>', '<div class="note-holder" data-event="backColor"><!-- back colors --></div>', '<div>', '<button type="button" class="note-color-select btn btn-light btn-default" data-event="openPalette" data-value="backColorPicker-' + this.options.id + '">', this.lang.color.cpSelect, '</button>', '<input type="color" id="backColorPicker-' + this.options.id + '" class="note-btn note-color-select-btn" value="' + this.options.colorButton.backColor + '" data-event="backColorPalette-' + this.options.id + '">', '</div>', '<div class="note-holder-custom" id="backColorPalette-' + this.options.id + '" data-event="backColor"></div>', '</div>'].join('') : '') + (foreColor ? ['<div class="note-palette">', '<div class="note-palette-title">' + this.lang.color.foreground + '</div>', '<div>', '<button type="button" class="note-color-reset btn btn-light btn-default" data-event="removeFormat" data-value="foreColor">', this.lang.color.resetToDefault, '</button>', '</div>', '<div class="note-holder" data-event="foreColor"><!-- fore colors --></div>', '<div>', '<button type="button" class="note-color-select btn btn-light btn-default" data-event="openPalette" data-value="foreColorPicker-' + this.options.id + '">', this.lang.color.cpSelect, '</button>', '<input type="color" id="foreColorPicker-' + this.options.id + '" class="note-btn note-color-select-btn" value="' + this.options.colorButton.foreColor + '" data-event="foreColorPalette-' + this.options.id + '">', '</div>', // Fix missing Div, Commented to find easily if it's wrong
7331
          '<div class="note-holder-custom" id="foreColorPalette-' + this.options.id + '" data-event="foreColor"></div>', '</div>'].join('') : ''),
7332
          callback: function callback($dropdown) {
7333
            $dropdown.find('.note-holder').each(function (idx, item) {
7334
              var $holder = external_jQuery_default()(item);
7335
              $holder.append(_this.ui.palette({
7336
                colors: _this.options.colors,
7337
                colorsName: _this.options.colorsName,
7338
                eventName: $holder.data('event'),
7339
                container: _this.options.container,
7340
                tooltip: _this.options.tooltip
7341
              }).render());
7342
            });
7343
            /* TODO: do we have to record recent custom colors within cookies? */
7344

7345
            var customColors = [['#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF']];
7346
            $dropdown.find('.note-holder-custom').each(function (idx, item) {
7347
              var $holder = external_jQuery_default()(item);
7348
              $holder.append(_this.ui.palette({
7349
                colors: customColors,
7350
                colorsName: customColors,
7351
                eventName: $holder.data('event'),
7352
                container: _this.options.container,
7353
                tooltip: _this.options.tooltip
7354
              }).render());
7355
            });
7356
            $dropdown.find('input[type=color]').each(function (idx, item) {
7357
              external_jQuery_default()(item).change(function () {
7358
                var $chip = $dropdown.find('#' + external_jQuery_default()(this).data('event')).find('.note-color-btn').first();
7359
                var color = this.value.toUpperCase();
7360
                $chip.css('background-color', color).attr('aria-label', color).attr('data-value', color).attr('data-original-title', color);
7361
                $chip.click();
7362
              });
7363
            });
7364
          },
7365
          click: function click(event) {
7366
            event.stopPropagation();
7367
            var $parent = external_jQuery_default()('.' + className).find('.note-dropdown-menu');
7368
            var $button = external_jQuery_default()(event.target);
7369
            var eventName = $button.data('event');
7370
            var value = $button.attr('data-value');
7371

7372
            if (eventName === 'openPalette') {
7373
              var $picker = $parent.find('#' + value);
7374
              var $palette = external_jQuery_default()($parent.find('#' + $picker.data('event')).find('.note-color-row')[0]); // Shift palette chips
7375

7376
              var $chip = $palette.find('.note-color-btn').last().detach(); // Set chip attributes
7377

7378
              var color = $picker.val();
7379
              $chip.css('background-color', color).attr('aria-label', color).attr('data-value', color).attr('data-original-title', color);
7380
              $palette.prepend($chip);
7381
              $picker.click();
7382
            } else {
7383
              if (lists.contains(['backColor', 'foreColor'], eventName)) {
7384
                var key = eventName === 'backColor' ? 'background-color' : 'color';
7385
                var $color = $button.closest('.note-color').find('.note-recent-color');
7386
                var $currentButton = $button.closest('.note-color').find('.note-current-color-button');
7387
                $color.css(key, value);
7388
                $currentButton.attr('data-' + eventName, value);
7389
              }
7390

7391
              _this.context.invoke('editor.' + eventName, value);
7392
            }
7393
          }
7394
        })]
7395
      }).render();
7396
    }
7397
  }, {
7398
    key: "addToolbarButtons",
7399
    value: function addToolbarButtons() {
7400
      var _this2 = this;
7401

7402
      this.context.memo('button.style', function () {
7403
        return _this2.ui.buttonGroup([_this2.button({
7404
          className: 'dropdown-toggle',
7405
          contents: _this2.ui.dropdownButtonContents(_this2.ui.icon(_this2.options.icons.magic), _this2.options),
7406
          tooltip: _this2.lang.style.style,
7407
          data: {
7408
            toggle: 'dropdown'
7409
          }
7410
        }), _this2.ui.dropdown({
7411
          className: 'dropdown-style',
7412
          items: _this2.options.styleTags,
7413
          title: _this2.lang.style.style,
7414
          template: function template(item) {
7415
            // TBD: need to be simplified
7416
            if (typeof item === 'string') {
7417
              item = {
7418
                tag: item,
7419
                title: Object.prototype.hasOwnProperty.call(_this2.lang.style, item) ? _this2.lang.style[item] : item
7420
              };
7421
            }
7422

7423
            var tag = item.tag;
7424
            var title = item.title;
7425
            var style = item.style ? ' style="' + item.style + '" ' : '';
7426
            var className = item.className ? ' class="' + item.className + '"' : '';
7427
            return '<' + tag + style + className + '>' + title + '</' + tag + '>';
7428
          },
7429
          click: _this2.context.createInvokeHandler('editor.formatBlock')
7430
        })]).render();
7431
      });
7432

7433
      var _loop = function _loop(styleIdx, styleLen) {
7434
        var item = _this2.options.styleTags[styleIdx];
7435

7436
        _this2.context.memo('button.style.' + item, function () {
7437
          return _this2.button({
7438
            className: 'note-btn-style-' + item,
7439
            contents: '<div data-value="' + item + '">' + item.toUpperCase() + '</div>',
7440
            tooltip: _this2.lang.style[item],
7441
            click: _this2.context.createInvokeHandler('editor.formatBlock')
7442
          }).render();
7443
        });
7444
      };
7445

7446
      for (var styleIdx = 0, styleLen = this.options.styleTags.length; styleIdx < styleLen; styleIdx++) {
7447
        _loop(styleIdx, styleLen);
7448
      }
7449

7450
      this.context.memo('button.bold', function () {
7451
        return _this2.button({
7452
          className: 'note-btn-bold',
7453
          contents: _this2.ui.icon(_this2.options.icons.bold),
7454
          tooltip: _this2.lang.font.bold + _this2.representShortcut('bold'),
7455
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.bold')
7456
        }).render();
7457
      });
7458
      this.context.memo('button.italic', function () {
7459
        return _this2.button({
7460
          className: 'note-btn-italic',
7461
          contents: _this2.ui.icon(_this2.options.icons.italic),
7462
          tooltip: _this2.lang.font.italic + _this2.representShortcut('italic'),
7463
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.italic')
7464
        }).render();
7465
      });
7466
      this.context.memo('button.underline', function () {
7467
        return _this2.button({
7468
          className: 'note-btn-underline',
7469
          contents: _this2.ui.icon(_this2.options.icons.underline),
7470
          tooltip: _this2.lang.font.underline + _this2.representShortcut('underline'),
7471
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.underline')
7472
        }).render();
7473
      });
7474
      this.context.memo('button.clear', function () {
7475
        return _this2.button({
7476
          contents: _this2.ui.icon(_this2.options.icons.eraser),
7477
          tooltip: _this2.lang.font.clear + _this2.representShortcut('removeFormat'),
7478
          click: _this2.context.createInvokeHandler('editor.removeFormat')
7479
        }).render();
7480
      });
7481
      this.context.memo('button.strikethrough', function () {
7482
        return _this2.button({
7483
          className: 'note-btn-strikethrough',
7484
          contents: _this2.ui.icon(_this2.options.icons.strikethrough),
7485
          tooltip: _this2.lang.font.strikethrough + _this2.representShortcut('strikethrough'),
7486
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.strikethrough')
7487
        }).render();
7488
      });
7489
      this.context.memo('button.superscript', function () {
7490
        return _this2.button({
7491
          className: 'note-btn-superscript',
7492
          contents: _this2.ui.icon(_this2.options.icons.superscript),
7493
          tooltip: _this2.lang.font.superscript,
7494
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.superscript')
7495
        }).render();
7496
      });
7497
      this.context.memo('button.subscript', function () {
7498
        return _this2.button({
7499
          className: 'note-btn-subscript',
7500
          contents: _this2.ui.icon(_this2.options.icons.subscript),
7501
          tooltip: _this2.lang.font.subscript,
7502
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.subscript')
7503
        }).render();
7504
      });
7505
      this.context.memo('button.fontname', function () {
7506
        var styleInfo = _this2.context.invoke('editor.currentStyle');
7507

7508
        if (_this2.options.addDefaultFonts) {
7509
          // Add 'default' fonts into the fontnames array if not exist
7510
          external_jQuery_default().each(styleInfo['font-family'].split(','), function (idx, fontname) {
7511
            fontname = fontname.trim().replace(/['"]+/g, '');
7512

7513
            if (_this2.isFontDeservedToAdd(fontname)) {
7514
              if (_this2.options.fontNames.indexOf(fontname) === -1) {
7515
                _this2.options.fontNames.push(fontname);
7516
              }
7517
            }
7518
          });
7519
        }
7520

7521
        return _this2.ui.buttonGroup([_this2.button({
7522
          className: 'dropdown-toggle',
7523
          contents: _this2.ui.dropdownButtonContents('<span class="note-current-fontname"></span>', _this2.options),
7524
          tooltip: _this2.lang.font.name,
7525
          data: {
7526
            toggle: 'dropdown'
7527
          }
7528
        }), _this2.ui.dropdownCheck({
7529
          className: 'dropdown-fontname',
7530
          checkClassName: _this2.options.icons.menuCheck,
7531
          items: _this2.options.fontNames.filter(_this2.isFontInstalled.bind(_this2)),
7532
          title: _this2.lang.font.name,
7533
          template: function template(item) {
7534
            return '<span style="font-family: ' + env.validFontName(item) + '">' + item + '</span>';
7535
          },
7536
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.fontName')
7537
        })]).render();
7538
      });
7539
      this.context.memo('button.fontsize', function () {
7540
        return _this2.ui.buttonGroup([_this2.button({
7541
          className: 'dropdown-toggle',
7542
          contents: _this2.ui.dropdownButtonContents('<span class="note-current-fontsize"></span>', _this2.options),
7543
          tooltip: _this2.lang.font.size,
7544
          data: {
7545
            toggle: 'dropdown'
7546
          }
7547
        }), _this2.ui.dropdownCheck({
7548
          className: 'dropdown-fontsize',
7549
          checkClassName: _this2.options.icons.menuCheck,
7550
          items: _this2.options.fontSizes,
7551
          title: _this2.lang.font.size,
7552
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.fontSize')
7553
        })]).render();
7554
      });
7555
      this.context.memo('button.fontsizeunit', function () {
7556
        return _this2.ui.buttonGroup([_this2.button({
7557
          className: 'dropdown-toggle',
7558
          contents: _this2.ui.dropdownButtonContents('<span class="note-current-fontsizeunit"></span>', _this2.options),
7559
          tooltip: _this2.lang.font.sizeunit,
7560
          data: {
7561
            toggle: 'dropdown'
7562
          }
7563
        }), _this2.ui.dropdownCheck({
7564
          className: 'dropdown-fontsizeunit',
7565
          checkClassName: _this2.options.icons.menuCheck,
7566
          items: _this2.options.fontSizeUnits,
7567
          title: _this2.lang.font.sizeunit,
7568
          click: _this2.context.createInvokeHandlerAndUpdateState('editor.fontSizeUnit')
7569
        })]).render();
7570
      });
7571
      this.context.memo('button.color', function () {
7572
        return _this2.colorPalette('note-color-all', _this2.lang.color.recent, true, true);
7573
      });
7574
      this.context.memo('button.forecolor', function () {
7575
        return _this2.colorPalette('note-color-fore', _this2.lang.color.foreground, false, true);
7576
      });
7577
      this.context.memo('button.backcolor', function () {
7578
        return _this2.colorPalette('note-color-back', _this2.lang.color.background, true, false);
7579
      });
7580
      this.context.memo('button.ul', function () {
7581
        return _this2.button({
7582
          contents: _this2.ui.icon(_this2.options.icons.unorderedlist),
7583
          tooltip: _this2.lang.lists.unordered + _this2.representShortcut('insertUnorderedList'),
7584
          click: _this2.context.createInvokeHandler('editor.insertUnorderedList')
7585
        }).render();
7586
      });
7587
      this.context.memo('button.ol', function () {
7588
        return _this2.button({
7589
          contents: _this2.ui.icon(_this2.options.icons.orderedlist),
7590
          tooltip: _this2.lang.lists.ordered + _this2.representShortcut('insertOrderedList'),
7591
          click: _this2.context.createInvokeHandler('editor.insertOrderedList')
7592
        }).render();
7593
      });
7594
      var justifyLeft = this.button({
7595
        contents: this.ui.icon(this.options.icons.alignLeft),
7596
        tooltip: this.lang.paragraph.left + this.representShortcut('justifyLeft'),
7597
        click: this.context.createInvokeHandler('editor.justifyLeft')
7598
      });
7599
      var justifyCenter = this.button({
7600
        contents: this.ui.icon(this.options.icons.alignCenter),
7601
        tooltip: this.lang.paragraph.center + this.representShortcut('justifyCenter'),
7602
        click: this.context.createInvokeHandler('editor.justifyCenter')
7603
      });
7604
      var justifyRight = this.button({
7605
        contents: this.ui.icon(this.options.icons.alignRight),
7606
        tooltip: this.lang.paragraph.right + this.representShortcut('justifyRight'),
7607
        click: this.context.createInvokeHandler('editor.justifyRight')
7608
      });
7609
      var justifyFull = this.button({
7610
        contents: this.ui.icon(this.options.icons.alignJustify),
7611
        tooltip: this.lang.paragraph.justify + this.representShortcut('justifyFull'),
7612
        click: this.context.createInvokeHandler('editor.justifyFull')
7613
      });
7614
      var outdent = this.button({
7615
        contents: this.ui.icon(this.options.icons.outdent),
7616
        tooltip: this.lang.paragraph.outdent + this.representShortcut('outdent'),
7617
        click: this.context.createInvokeHandler('editor.outdent')
7618
      });
7619
      var indent = this.button({
7620
        contents: this.ui.icon(this.options.icons.indent),
7621
        tooltip: this.lang.paragraph.indent + this.representShortcut('indent'),
7622
        click: this.context.createInvokeHandler('editor.indent')
7623
      });
7624
      this.context.memo('button.justifyLeft', func.invoke(justifyLeft, 'render'));
7625
      this.context.memo('button.justifyCenter', func.invoke(justifyCenter, 'render'));
7626
      this.context.memo('button.justifyRight', func.invoke(justifyRight, 'render'));
7627
      this.context.memo('button.justifyFull', func.invoke(justifyFull, 'render'));
7628
      this.context.memo('button.outdent', func.invoke(outdent, 'render'));
7629
      this.context.memo('button.indent', func.invoke(indent, 'render'));
7630
      this.context.memo('button.paragraph', function () {
7631
        return _this2.ui.buttonGroup([_this2.button({
7632
          className: 'dropdown-toggle',
7633
          contents: _this2.ui.dropdownButtonContents(_this2.ui.icon(_this2.options.icons.alignLeft), _this2.options),
7634
          tooltip: _this2.lang.paragraph.paragraph,
7635
          data: {
7636
            toggle: 'dropdown'
7637
          }
7638
        }), _this2.ui.dropdown([_this2.ui.buttonGroup({
7639
          className: 'note-align',
7640
          children: [justifyLeft, justifyCenter, justifyRight, justifyFull]
7641
        }), _this2.ui.buttonGroup({
7642
          className: 'note-list',
7643
          children: [outdent, indent]
7644
        })])]).render();
7645
      });
7646
      this.context.memo('button.height', function () {
7647
        return _this2.ui.buttonGroup([_this2.button({
7648
          className: 'dropdown-toggle',
7649
          contents: _this2.ui.dropdownButtonContents(_this2.ui.icon(_this2.options.icons.textHeight), _this2.options),
7650
          tooltip: _this2.lang.font.height,
7651
          data: {
7652
            toggle: 'dropdown'
7653
          }
7654
        }), _this2.ui.dropdownCheck({
7655
          items: _this2.options.lineHeights,
7656
          checkClassName: _this2.options.icons.menuCheck,
7657
          className: 'dropdown-line-height',
7658
          title: _this2.lang.font.height,
7659
          click: _this2.context.createInvokeHandler('editor.lineHeight')
7660
        })]).render();
7661
      });
7662
      this.context.memo('button.table', function () {
7663
        return _this2.ui.buttonGroup([_this2.button({
7664
          className: 'dropdown-toggle',
7665
          contents: _this2.ui.dropdownButtonContents(_this2.ui.icon(_this2.options.icons.table), _this2.options),
7666
          tooltip: _this2.lang.table.table,
7667
          data: {
7668
            toggle: 'dropdown'
7669
          }
7670
        }), _this2.ui.dropdown({
7671
          title: _this2.lang.table.table,
7672
          className: 'note-table',
7673
          items: ['<div class="note-dimension-picker">', '<div class="note-dimension-picker-mousecatcher" data-event="insertTable" data-value="1x1"></div>', '<div class="note-dimension-picker-highlighted"></div>', '<div class="note-dimension-picker-unhighlighted"></div>', '</div>', '<div class="note-dimension-display">1 x 1</div>'].join('')
7674
        })], {
7675
          callback: function callback($node) {
7676
            var $catcher = $node.find('.note-dimension-picker-mousecatcher');
7677
            $catcher.css({
7678
              width: _this2.options.insertTableMaxSize.col + 'em',
7679
              height: _this2.options.insertTableMaxSize.row + 'em'
7680
            }).mouseup(_this2.context.createInvokeHandler('editor.insertTable')).on('mousemove', _this2.tableMoveHandler.bind(_this2));
7681
          }
7682
        }).render();
7683
      });
7684
      this.context.memo('button.link', function () {
7685
        return _this2.button({
7686
          contents: _this2.ui.icon(_this2.options.icons.link),
7687
          tooltip: _this2.lang.link.link + _this2.representShortcut('linkDialog.show'),
7688
          click: _this2.context.createInvokeHandler('linkDialog.show')
7689
        }).render();
7690
      });
7691
      this.context.memo('button.picture', function () {
7692
        return _this2.button({
7693
          contents: _this2.ui.icon(_this2.options.icons.picture),
7694
          tooltip: _this2.lang.image.image,
7695
          click: _this2.context.createInvokeHandler('imageDialog.show')
7696
        }).render();
7697
      });
7698
      this.context.memo('button.video', function () {
7699
        return _this2.button({
7700
          contents: _this2.ui.icon(_this2.options.icons.video),
7701
          tooltip: _this2.lang.video.video,
7702
          click: _this2.context.createInvokeHandler('videoDialog.show')
7703
        }).render();
7704
      });
7705
      this.context.memo('button.hr', function () {
7706
        return _this2.button({
7707
          contents: _this2.ui.icon(_this2.options.icons.minus),
7708
          tooltip: _this2.lang.hr.insert + _this2.representShortcut('insertHorizontalRule'),
7709
          click: _this2.context.createInvokeHandler('editor.insertHorizontalRule')
7710
        }).render();
7711
      });
7712
      this.context.memo('button.fullscreen', function () {
7713
        return _this2.button({
7714
          className: 'btn-fullscreen note-codeview-keep',
7715
          contents: _this2.ui.icon(_this2.options.icons.arrowsAlt),
7716
          tooltip: _this2.lang.options.fullscreen,
7717
          click: _this2.context.createInvokeHandler('fullscreen.toggle')
7718
        }).render();
7719
      });
7720
      this.context.memo('button.codeview', function () {
7721
        return _this2.button({
7722
          className: 'btn-codeview note-codeview-keep',
7723
          contents: _this2.ui.icon(_this2.options.icons.code),
7724
          tooltip: _this2.lang.options.codeview,
7725
          click: _this2.context.createInvokeHandler('codeview.toggle')
7726
        }).render();
7727
      });
7728
      this.context.memo('button.redo', function () {
7729
        return _this2.button({
7730
          contents: _this2.ui.icon(_this2.options.icons.redo),
7731
          tooltip: _this2.lang.history.redo + _this2.representShortcut('redo'),
7732
          click: _this2.context.createInvokeHandler('editor.redo')
7733
        }).render();
7734
      });
7735
      this.context.memo('button.undo', function () {
7736
        return _this2.button({
7737
          contents: _this2.ui.icon(_this2.options.icons.undo),
7738
          tooltip: _this2.lang.history.undo + _this2.representShortcut('undo'),
7739
          click: _this2.context.createInvokeHandler('editor.undo')
7740
        }).render();
7741
      });
7742
      this.context.memo('button.help', function () {
7743
        return _this2.button({
7744
          contents: _this2.ui.icon(_this2.options.icons.question),
7745
          tooltip: _this2.lang.options.help,
7746
          click: _this2.context.createInvokeHandler('helpDialog.show')
7747
        }).render();
7748
      });
7749
    }
7750
    /**
7751
     * image: [
7752
     *   ['imageResize', ['resizeFull', 'resizeHalf', 'resizeQuarter', 'resizeNone']],
7753
     *   ['float', ['floatLeft', 'floatRight', 'floatNone']],
7754
     *   ['remove', ['removeMedia']],
7755
     * ],
7756
     */
7757

7758
  }, {
7759
    key: "addImagePopoverButtons",
7760
    value: function addImagePopoverButtons() {
7761
      var _this3 = this;
7762

7763
      // Image Size Buttons
7764
      this.context.memo('button.resizeFull', function () {
7765
        return _this3.button({
7766
          contents: '<span class="note-fontsize-10">100%</span>',
7767
          tooltip: _this3.lang.image.resizeFull,
7768
          click: _this3.context.createInvokeHandler('editor.resize', '1')
7769
        }).render();
7770
      });
7771
      this.context.memo('button.resizeHalf', function () {
7772
        return _this3.button({
7773
          contents: '<span class="note-fontsize-10">50%</span>',
7774
          tooltip: _this3.lang.image.resizeHalf,
7775
          click: _this3.context.createInvokeHandler('editor.resize', '0.5')
7776
        }).render();
7777
      });
7778
      this.context.memo('button.resizeQuarter', function () {
7779
        return _this3.button({
7780
          contents: '<span class="note-fontsize-10">25%</span>',
7781
          tooltip: _this3.lang.image.resizeQuarter,
7782
          click: _this3.context.createInvokeHandler('editor.resize', '0.25')
7783
        }).render();
7784
      });
7785
      this.context.memo('button.resizeNone', function () {
7786
        return _this3.button({
7787
          contents: _this3.ui.icon(_this3.options.icons.rollback),
7788
          tooltip: _this3.lang.image.resizeNone,
7789
          click: _this3.context.createInvokeHandler('editor.resize', '0')
7790
        }).render();
7791
      }); // Float Buttons
7792

7793
      this.context.memo('button.floatLeft', function () {
7794
        return _this3.button({
7795
          contents: _this3.ui.icon(_this3.options.icons.floatLeft),
7796
          tooltip: _this3.lang.image.floatLeft,
7797
          click: _this3.context.createInvokeHandler('editor.floatMe', 'left')
7798
        }).render();
7799
      });
7800
      this.context.memo('button.floatRight', function () {
7801
        return _this3.button({
7802
          contents: _this3.ui.icon(_this3.options.icons.floatRight),
7803
          tooltip: _this3.lang.image.floatRight,
7804
          click: _this3.context.createInvokeHandler('editor.floatMe', 'right')
7805
        }).render();
7806
      });
7807
      this.context.memo('button.floatNone', function () {
7808
        return _this3.button({
7809
          contents: _this3.ui.icon(_this3.options.icons.rollback),
7810
          tooltip: _this3.lang.image.floatNone,
7811
          click: _this3.context.createInvokeHandler('editor.floatMe', 'none')
7812
        }).render();
7813
      }); // Remove Buttons
7814

7815
      this.context.memo('button.removeMedia', function () {
7816
        return _this3.button({
7817
          contents: _this3.ui.icon(_this3.options.icons.trash),
7818
          tooltip: _this3.lang.image.remove,
7819
          click: _this3.context.createInvokeHandler('editor.removeMedia')
7820
        }).render();
7821
      });
7822
    }
7823
  }, {
7824
    key: "addLinkPopoverButtons",
7825
    value: function addLinkPopoverButtons() {
7826
      var _this4 = this;
7827

7828
      this.context.memo('button.linkDialogShow', function () {
7829
        return _this4.button({
7830
          contents: _this4.ui.icon(_this4.options.icons.link),
7831
          tooltip: _this4.lang.link.edit,
7832
          click: _this4.context.createInvokeHandler('linkDialog.show')
7833
        }).render();
7834
      });
7835
      this.context.memo('button.unlink', function () {
7836
        return _this4.button({
7837
          contents: _this4.ui.icon(_this4.options.icons.unlink),
7838
          tooltip: _this4.lang.link.unlink,
7839
          click: _this4.context.createInvokeHandler('editor.unlink')
7840
        }).render();
7841
      });
7842
    }
7843
    /**
7844
     * table : [
7845
     *  ['add', ['addRowDown', 'addRowUp', 'addColLeft', 'addColRight']],
7846
     *  ['delete', ['deleteRow', 'deleteCol', 'deleteTable']]
7847
     * ],
7848
     */
7849

7850
  }, {
7851
    key: "addTablePopoverButtons",
7852
    value: function addTablePopoverButtons() {
7853
      var _this5 = this;
7854

7855
      this.context.memo('button.addRowUp', function () {
7856
        return _this5.button({
7857
          className: 'btn-md',
7858
          contents: _this5.ui.icon(_this5.options.icons.rowAbove),
7859
          tooltip: _this5.lang.table.addRowAbove,
7860
          click: _this5.context.createInvokeHandler('editor.addRow', 'top')
7861
        }).render();
7862
      });
7863
      this.context.memo('button.addRowDown', function () {
7864
        return _this5.button({
7865
          className: 'btn-md',
7866
          contents: _this5.ui.icon(_this5.options.icons.rowBelow),
7867
          tooltip: _this5.lang.table.addRowBelow,
7868
          click: _this5.context.createInvokeHandler('editor.addRow', 'bottom')
7869
        }).render();
7870
      });
7871
      this.context.memo('button.addColLeft', function () {
7872
        return _this5.button({
7873
          className: 'btn-md',
7874
          contents: _this5.ui.icon(_this5.options.icons.colBefore),
7875
          tooltip: _this5.lang.table.addColLeft,
7876
          click: _this5.context.createInvokeHandler('editor.addCol', 'left')
7877
        }).render();
7878
      });
7879
      this.context.memo('button.addColRight', function () {
7880
        return _this5.button({
7881
          className: 'btn-md',
7882
          contents: _this5.ui.icon(_this5.options.icons.colAfter),
7883
          tooltip: _this5.lang.table.addColRight,
7884
          click: _this5.context.createInvokeHandler('editor.addCol', 'right')
7885
        }).render();
7886
      });
7887
      this.context.memo('button.deleteRow', function () {
7888
        return _this5.button({
7889
          className: 'btn-md',
7890
          contents: _this5.ui.icon(_this5.options.icons.rowRemove),
7891
          tooltip: _this5.lang.table.delRow,
7892
          click: _this5.context.createInvokeHandler('editor.deleteRow')
7893
        }).render();
7894
      });
7895
      this.context.memo('button.deleteCol', function () {
7896
        return _this5.button({
7897
          className: 'btn-md',
7898
          contents: _this5.ui.icon(_this5.options.icons.colRemove),
7899
          tooltip: _this5.lang.table.delCol,
7900
          click: _this5.context.createInvokeHandler('editor.deleteCol')
7901
        }).render();
7902
      });
7903
      this.context.memo('button.deleteTable', function () {
7904
        return _this5.button({
7905
          className: 'btn-md',
7906
          contents: _this5.ui.icon(_this5.options.icons.trash),
7907
          tooltip: _this5.lang.table.delTable,
7908
          click: _this5.context.createInvokeHandler('editor.deleteTable')
7909
        }).render();
7910
      });
7911
    }
7912
  }, {
7913
    key: "build",
7914
    value: function build($container, groups) {
7915
      for (var groupIdx = 0, groupLen = groups.length; groupIdx < groupLen; groupIdx++) {
7916
        var group = groups[groupIdx];
7917
        var groupName = Array.isArray(group) ? group[0] : group;
7918
        var buttons = Array.isArray(group) ? group.length === 1 ? [group[0]] : group[1] : [group];
7919
        var $group = this.ui.buttonGroup({
7920
          className: 'note-' + groupName
7921
        }).render();
7922

7923
        for (var idx = 0, len = buttons.length; idx < len; idx++) {
7924
          var btn = this.context.memo('button.' + buttons[idx]);
7925

7926
          if (btn) {
7927
            $group.append(typeof btn === 'function' ? btn(this.context) : btn);
7928
          }
7929
        }
7930

7931
        $group.appendTo($container);
7932
      }
7933
    }
7934
    /**
7935
     * @param {jQuery} [$container]
7936
     */
7937

7938
  }, {
7939
    key: "updateCurrentStyle",
7940
    value: function updateCurrentStyle($container) {
7941
      var $cont = $container || this.$toolbar;
7942
      var styleInfo = this.context.invoke('editor.currentStyle');
7943
      this.updateBtnStates($cont, {
7944
        '.note-btn-bold': function noteBtnBold() {
7945
          return styleInfo['font-bold'] === 'bold';
7946
        },
7947
        '.note-btn-italic': function noteBtnItalic() {
7948
          return styleInfo['font-italic'] === 'italic';
7949
        },
7950
        '.note-btn-underline': function noteBtnUnderline() {
7951
          return styleInfo['font-underline'] === 'underline';
7952
        },
7953
        '.note-btn-subscript': function noteBtnSubscript() {
7954
          return styleInfo['font-subscript'] === 'subscript';
7955
        },
7956
        '.note-btn-superscript': function noteBtnSuperscript() {
7957
          return styleInfo['font-superscript'] === 'superscript';
7958
        },
7959
        '.note-btn-strikethrough': function noteBtnStrikethrough() {
7960
          return styleInfo['font-strikethrough'] === 'strikethrough';
7961
        }
7962
      });
7963

7964
      if (styleInfo['font-family']) {
7965
        var fontNames = styleInfo['font-family'].split(',').map(function (name) {
7966
          return name.replace(/[\'\"]/g, '').replace(/\s+$/, '').replace(/^\s+/, '');
7967
        });
7968
        var fontName = lists.find(fontNames, this.isFontInstalled.bind(this));
7969
        $cont.find('.dropdown-fontname a').each(function (idx, item) {
7970
          var $item = external_jQuery_default()(item); // always compare string to avoid creating another func.
7971

7972
          var isChecked = $item.data('value') + '' === fontName + '';
7973
          $item.toggleClass('checked', isChecked);
7974
        });
7975
        $cont.find('.note-current-fontname').text(fontName).css('font-family', fontName);
7976
      }
7977

7978
      if (styleInfo['font-size']) {
7979
        var fontSize = styleInfo['font-size'];
7980
        $cont.find('.dropdown-fontsize a').each(function (idx, item) {
7981
          var $item = external_jQuery_default()(item); // always compare with string to avoid creating another func.
7982

7983
          var isChecked = $item.data('value') + '' === fontSize + '';
7984
          $item.toggleClass('checked', isChecked);
7985
        });
7986
        $cont.find('.note-current-fontsize').text(fontSize);
7987
        var fontSizeUnit = styleInfo['font-size-unit'];
7988
        $cont.find('.dropdown-fontsizeunit a').each(function (idx, item) {
7989
          var $item = external_jQuery_default()(item);
7990
          var isChecked = $item.data('value') + '' === fontSizeUnit + '';
7991
          $item.toggleClass('checked', isChecked);
7992
        });
7993
        $cont.find('.note-current-fontsizeunit').text(fontSizeUnit);
7994
      }
7995

7996
      if (styleInfo['line-height']) {
7997
        var lineHeight = styleInfo['line-height'];
7998
        $cont.find('.dropdown-line-height a').each(function (idx, item) {
7999
          var $item = external_jQuery_default()(item); // always compare with string to avoid creating another func.
8000

8001
          var isChecked = external_jQuery_default()(item).data('value') + '' === lineHeight + '';
8002
          $item.toggleClass('checked', isChecked);
8003
        });
8004
        $cont.find('.note-current-line-height').text(lineHeight);
8005
      }
8006
    }
8007
  }, {
8008
    key: "updateBtnStates",
8009
    value: function updateBtnStates($container, infos) {
8010
      var _this6 = this;
8011

8012
      external_jQuery_default().each(infos, function (selector, pred) {
8013
        _this6.ui.toggleBtnActive($container.find(selector), pred());
8014
      });
8015
    }
8016
  }, {
8017
    key: "tableMoveHandler",
8018
    value: function tableMoveHandler(event) {
8019
      var PX_PER_EM = 18;
8020
      var $picker = external_jQuery_default()(event.target.parentNode); // target is mousecatcher
8021

8022
      var $dimensionDisplay = $picker.next();
8023
      var $catcher = $picker.find('.note-dimension-picker-mousecatcher');
8024
      var $highlighted = $picker.find('.note-dimension-picker-highlighted');
8025
      var $unhighlighted = $picker.find('.note-dimension-picker-unhighlighted');
8026
      var posOffset; // HTML5 with jQuery - e.offsetX is undefined in Firefox
8027

8028
      if (event.offsetX === undefined) {
8029
        var posCatcher = external_jQuery_default()(event.target).offset();
8030
        posOffset = {
8031
          x: event.pageX - posCatcher.left,
8032
          y: event.pageY - posCatcher.top
8033
        };
8034
      } else {
8035
        posOffset = {
8036
          x: event.offsetX,
8037
          y: event.offsetY
8038
        };
8039
      }
8040

8041
      var dim = {
8042
        c: Math.ceil(posOffset.x / PX_PER_EM) || 1,
8043
        r: Math.ceil(posOffset.y / PX_PER_EM) || 1
8044
      };
8045
      $highlighted.css({
8046
        width: dim.c + 'em',
8047
        height: dim.r + 'em'
8048
      });
8049
      $catcher.data('value', dim.c + 'x' + dim.r);
8050

8051
      if (dim.c > 3 && dim.c < this.options.insertTableMaxSize.col) {
8052
        $unhighlighted.css({
8053
          width: dim.c + 1 + 'em'
8054
        });
8055
      }
8056

8057
      if (dim.r > 3 && dim.r < this.options.insertTableMaxSize.row) {
8058
        $unhighlighted.css({
8059
          height: dim.r + 1 + 'em'
8060
        });
8061
      }
8062

8063
      $dimensionDisplay.html(dim.c + ' x ' + dim.r);
8064
    }
8065
  }]);
8066

8067
  return Buttons;
8068
}();
8069

8070

8071
;// CONCATENATED MODULE: ./src/js/module/Toolbar.js
8072
function Toolbar_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8073

8074
function Toolbar_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8075

8076
function Toolbar_createClass(Constructor, protoProps, staticProps) { if (protoProps) Toolbar_defineProperties(Constructor.prototype, protoProps); if (staticProps) Toolbar_defineProperties(Constructor, staticProps); return Constructor; }
8077

8078

8079

8080
var Toolbar = /*#__PURE__*/function () {
8081
  function Toolbar(context) {
8082
    Toolbar_classCallCheck(this, Toolbar);
8083

8084
    this.context = context;
8085
    this.$window = external_jQuery_default()(window);
8086
    this.$document = external_jQuery_default()(document);
8087
    this.ui = (external_jQuery_default()).summernote.ui;
8088
    this.$note = context.layoutInfo.note;
8089
    this.$editor = context.layoutInfo.editor;
8090
    this.$toolbar = context.layoutInfo.toolbar;
8091
    this.$editable = context.layoutInfo.editable;
8092
    this.$statusbar = context.layoutInfo.statusbar;
8093
    this.options = context.options;
8094
    this.isFollowing = false;
8095
    this.followScroll = this.followScroll.bind(this);
8096
  }
8097

8098
  Toolbar_createClass(Toolbar, [{
8099
    key: "shouldInitialize",
8100
    value: function shouldInitialize() {
8101
      return !this.options.airMode;
8102
    }
8103
  }, {
8104
    key: "initialize",
8105
    value: function initialize() {
8106
      var _this = this;
8107

8108
      this.options.toolbar = this.options.toolbar || [];
8109

8110
      if (!this.options.toolbar.length) {
8111
        this.$toolbar.hide();
8112
      } else {
8113
        this.context.invoke('buttons.build', this.$toolbar, this.options.toolbar);
8114
      }
8115

8116
      if (this.options.toolbarContainer) {
8117
        this.$toolbar.appendTo(this.options.toolbarContainer);
8118
      }
8119

8120
      this.changeContainer(false);
8121
      this.$note.on('summernote.keyup summernote.mouseup summernote.change', function () {
8122
        _this.context.invoke('buttons.updateCurrentStyle');
8123
      });
8124
      this.context.invoke('buttons.updateCurrentStyle');
8125

8126
      if (this.options.followingToolbar) {
8127
        this.$window.on('scroll resize', this.followScroll);
8128
      }
8129
    }
8130
  }, {
8131
    key: "destroy",
8132
    value: function destroy() {
8133
      this.$toolbar.children().remove();
8134

8135
      if (this.options.followingToolbar) {
8136
        this.$window.off('scroll resize', this.followScroll);
8137
      }
8138
    }
8139
  }, {
8140
    key: "followScroll",
8141
    value: function followScroll() {
8142
      if (this.$editor.hasClass('fullscreen')) {
8143
        return false;
8144
      }
8145

8146
      var editorHeight = this.$editor.outerHeight();
8147
      var editorWidth = this.$editor.width();
8148
      var toolbarHeight = this.$toolbar.height();
8149
      var statusbarHeight = this.$statusbar.height(); // check if the web app is currently using another static bar
8150

8151
      var otherBarHeight = 0;
8152

8153
      if (this.options.otherStaticBar) {
8154
        otherBarHeight = external_jQuery_default()(this.options.otherStaticBar).outerHeight();
8155
      }
8156

8157
      var currentOffset = this.$document.scrollTop();
8158
      var editorOffsetTop = this.$editor.offset().top;
8159
      var editorOffsetBottom = editorOffsetTop + editorHeight;
8160
      var activateOffset = editorOffsetTop - otherBarHeight;
8161
      var deactivateOffsetBottom = editorOffsetBottom - otherBarHeight - toolbarHeight - statusbarHeight;
8162

8163
      if (!this.isFollowing && currentOffset > activateOffset && currentOffset < deactivateOffsetBottom - toolbarHeight) {
8164
        this.isFollowing = true;
8165
        this.$editable.css({
8166
          marginTop: this.$toolbar.outerHeight()
8167
        });
8168
        this.$toolbar.css({
8169
          position: 'fixed',
8170
          top: otherBarHeight,
8171
          width: editorWidth,
8172
          zIndex: 1000
8173
        });
8174
      } else if (this.isFollowing && (currentOffset < activateOffset || currentOffset > deactivateOffsetBottom)) {
8175
        this.isFollowing = false;
8176
        this.$toolbar.css({
8177
          position: 'relative',
8178
          top: 0,
8179
          width: '100%',
8180
          zIndex: 'auto'
8181
        });
8182
        this.$editable.css({
8183
          marginTop: ''
8184
        });
8185
      }
8186
    }
8187
  }, {
8188
    key: "changeContainer",
8189
    value: function changeContainer(isFullscreen) {
8190
      if (isFullscreen) {
8191
        this.$toolbar.prependTo(this.$editor);
8192
      } else {
8193
        if (this.options.toolbarContainer) {
8194
          this.$toolbar.appendTo(this.options.toolbarContainer);
8195
        }
8196
      }
8197

8198
      if (this.options.followingToolbar) {
8199
        this.followScroll();
8200
      }
8201
    }
8202
  }, {
8203
    key: "updateFullscreen",
8204
    value: function updateFullscreen(isFullscreen) {
8205
      this.ui.toggleBtnActive(this.$toolbar.find('.btn-fullscreen'), isFullscreen);
8206
      this.changeContainer(isFullscreen);
8207
    }
8208
  }, {
8209
    key: "updateCodeview",
8210
    value: function updateCodeview(isCodeview) {
8211
      this.ui.toggleBtnActive(this.$toolbar.find('.btn-codeview'), isCodeview);
8212

8213
      if (isCodeview) {
8214
        this.deactivate();
8215
      } else {
8216
        this.activate();
8217
      }
8218
    }
8219
  }, {
8220
    key: "activate",
8221
    value: function activate(isIncludeCodeview) {
8222
      var $btn = this.$toolbar.find('button');
8223

8224
      if (!isIncludeCodeview) {
8225
        $btn = $btn.not('.note-codeview-keep');
8226
      }
8227

8228
      this.ui.toggleBtn($btn, true);
8229
    }
8230
  }, {
8231
    key: "deactivate",
8232
    value: function deactivate(isIncludeCodeview) {
8233
      var $btn = this.$toolbar.find('button');
8234

8235
      if (!isIncludeCodeview) {
8236
        $btn = $btn.not('.note-codeview-keep');
8237
      }
8238

8239
      this.ui.toggleBtn($btn, false);
8240
    }
8241
  }]);
8242

8243
  return Toolbar;
8244
}();
8245

8246

8247
;// CONCATENATED MODULE: ./src/js/module/LinkDialog.js
8248
function LinkDialog_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8249

8250
function LinkDialog_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8251

8252
function LinkDialog_createClass(Constructor, protoProps, staticProps) { if (protoProps) LinkDialog_defineProperties(Constructor.prototype, protoProps); if (staticProps) LinkDialog_defineProperties(Constructor, staticProps); return Constructor; }
8253

8254

8255

8256

8257

8258

8259
var LinkDialog = /*#__PURE__*/function () {
8260
  function LinkDialog(context) {
8261
    LinkDialog_classCallCheck(this, LinkDialog);
8262

8263
    this.context = context;
8264
    this.ui = (external_jQuery_default()).summernote.ui;
8265
    this.$body = external_jQuery_default()(document.body);
8266
    this.$editor = context.layoutInfo.editor;
8267
    this.options = context.options;
8268
    this.lang = this.options.langInfo;
8269
    context.memo('help.linkDialog.show', this.options.langInfo.help['linkDialog.show']);
8270
  }
8271

8272
  LinkDialog_createClass(LinkDialog, [{
8273
    key: "initialize",
8274
    value: function initialize() {
8275
      var $container = this.options.dialogsInBody ? this.$body : this.options.container;
8276
      var body = ['<div class="form-group note-form-group">', "<label for=\"note-dialog-link-txt-".concat(this.options.id, "\" class=\"note-form-label\">").concat(this.lang.link.textToDisplay, "</label>"), "<input id=\"note-dialog-link-txt-".concat(this.options.id, "\" class=\"note-link-text form-control note-form-control note-input\" type=\"text\"/>"), '</div>', '<div class="form-group note-form-group">', "<label for=\"note-dialog-link-url-".concat(this.options.id, "\" class=\"note-form-label\">").concat(this.lang.link.url, "</label>"), "<input id=\"note-dialog-link-url-".concat(this.options.id, "\" class=\"note-link-url form-control note-form-control note-input\" type=\"text\" value=\"http://\"/>"), '</div>', !this.options.disableLinkTarget ? external_jQuery_default()('<div></div>').append(this.ui.checkbox({
8277
        className: 'sn-checkbox-open-in-new-window',
8278
        text: this.lang.link.openInNewWindow,
8279
        checked: true
8280
      }).render()).html() : '', external_jQuery_default()('<div></div>').append(this.ui.checkbox({
8281
        className: 'sn-checkbox-use-protocol',
8282
        text: this.lang.link.useProtocol,
8283
        checked: true
8284
      }).render()).html()].join('');
8285
      var buttonClass = 'btn btn-primary note-btn note-btn-primary note-link-btn';
8286
      var footer = "<input type=\"button\" href=\"#\" class=\"".concat(buttonClass, "\" value=\"").concat(this.lang.link.insert, "\" disabled>");
8287
      this.$dialog = this.ui.dialog({
8288
        className: 'link-dialog',
8289
        title: this.lang.link.insert,
8290
        fade: this.options.dialogsFade,
8291
        body: body,
8292
        footer: footer
8293
      }).render().appendTo($container);
8294
    }
8295
  }, {
8296
    key: "destroy",
8297
    value: function destroy() {
8298
      this.ui.hideDialog(this.$dialog);
8299
      this.$dialog.remove();
8300
    }
8301
  }, {
8302
    key: "bindEnterKey",
8303
    value: function bindEnterKey($input, $btn) {
8304
      $input.on('keypress', function (event) {
8305
        if (event.keyCode === key.code.ENTER) {
8306
          event.preventDefault();
8307
          $btn.trigger('click');
8308
        }
8309
      });
8310
    }
8311
    /**
8312
     * toggle update button
8313
     */
8314

8315
  }, {
8316
    key: "toggleLinkBtn",
8317
    value: function toggleLinkBtn($linkBtn, $linkText, $linkUrl) {
8318
      this.ui.toggleBtn($linkBtn, $linkText.val() && $linkUrl.val());
8319
    }
8320
    /**
8321
     * Show link dialog and set event handlers on dialog controls.
8322
     *
8323
     * @param {Object} linkInfo
8324
     * @return {Promise}
8325
     */
8326

8327
  }, {
8328
    key: "showLinkDialog",
8329
    value: function showLinkDialog(linkInfo) {
8330
      var _this = this;
8331

8332
      return external_jQuery_default().Deferred(function (deferred) {
8333
        var $linkText = _this.$dialog.find('.note-link-text');
8334

8335
        var $linkUrl = _this.$dialog.find('.note-link-url');
8336

8337
        var $linkBtn = _this.$dialog.find('.note-link-btn');
8338

8339
        var $openInNewWindow = _this.$dialog.find('.sn-checkbox-open-in-new-window input[type=checkbox]');
8340

8341
        var $useProtocol = _this.$dialog.find('.sn-checkbox-use-protocol input[type=checkbox]');
8342

8343
        _this.ui.onDialogShown(_this.$dialog, function () {
8344
          _this.context.triggerEvent('dialog.shown'); // If no url was given and given text is valid URL then copy that into URL Field
8345

8346

8347
          if (!linkInfo.url && func.isValidUrl(linkInfo.text)) {
8348
            linkInfo.url = linkInfo.text;
8349
          }
8350

8351
          $linkText.on('input paste propertychange', function () {
8352
            // If linktext was modified by input events,
8353
            // cloning text from linkUrl will be stopped.
8354
            linkInfo.text = $linkText.val();
8355

8356
            _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
8357
          }).val(linkInfo.text);
8358
          $linkUrl.on('input paste propertychange', function () {
8359
            // Display same text on `Text to display` as default
8360
            // when linktext has no text
8361
            if (!linkInfo.text) {
8362
              $linkText.val($linkUrl.val());
8363
            }
8364

8365
            _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
8366
          }).val(linkInfo.url);
8367

8368
          if (!env.isSupportTouch) {
8369
            $linkUrl.trigger('focus');
8370
          }
8371

8372
          _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
8373

8374
          _this.bindEnterKey($linkUrl, $linkBtn);
8375

8376
          _this.bindEnterKey($linkText, $linkBtn);
8377

8378
          var isNewWindowChecked = linkInfo.isNewWindow !== undefined ? linkInfo.isNewWindow : _this.context.options.linkTargetBlank;
8379
          $openInNewWindow.prop('checked', isNewWindowChecked);
8380
          var useProtocolChecked = linkInfo.url ? false : _this.context.options.useProtocol;
8381
          $useProtocol.prop('checked', useProtocolChecked);
8382
          $linkBtn.one('click', function (event) {
8383
            event.preventDefault();
8384
            deferred.resolve({
8385
              range: linkInfo.range,
8386
              url: $linkUrl.val(),
8387
              text: $linkText.val(),
8388
              isNewWindow: $openInNewWindow.is(':checked'),
8389
              checkProtocol: $useProtocol.is(':checked')
8390
            });
8391

8392
            _this.ui.hideDialog(_this.$dialog);
8393
          });
8394
        });
8395

8396
        _this.ui.onDialogHidden(_this.$dialog, function () {
8397
          // detach events
8398
          $linkText.off();
8399
          $linkUrl.off();
8400
          $linkBtn.off();
8401

8402
          if (deferred.state() === 'pending') {
8403
            deferred.reject();
8404
          }
8405
        });
8406

8407
        _this.ui.showDialog(_this.$dialog);
8408
      }).promise();
8409
    }
8410
    /**
8411
     * @param {Object} layoutInfo
8412
     */
8413

8414
  }, {
8415
    key: "show",
8416
    value: function show() {
8417
      var _this2 = this;
8418

8419
      var linkInfo = this.context.invoke('editor.getLinkInfo');
8420
      this.context.invoke('editor.saveRange');
8421
      this.showLinkDialog(linkInfo).then(function (linkInfo) {
8422
        _this2.context.invoke('editor.restoreRange');
8423

8424
        _this2.context.invoke('editor.createLink', linkInfo);
8425
      }).fail(function () {
8426
        _this2.context.invoke('editor.restoreRange');
8427
      });
8428
    }
8429
  }]);
8430

8431
  return LinkDialog;
8432
}();
8433

8434

8435
;// CONCATENATED MODULE: ./src/js/module/LinkPopover.js
8436
function LinkPopover_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8437

8438
function LinkPopover_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8439

8440
function LinkPopover_createClass(Constructor, protoProps, staticProps) { if (protoProps) LinkPopover_defineProperties(Constructor.prototype, protoProps); if (staticProps) LinkPopover_defineProperties(Constructor, staticProps); return Constructor; }
8441

8442

8443

8444

8445

8446
var LinkPopover = /*#__PURE__*/function () {
8447
  function LinkPopover(context) {
8448
    var _this = this;
8449

8450
    LinkPopover_classCallCheck(this, LinkPopover);
8451

8452
    this.context = context;
8453
    this.ui = (external_jQuery_default()).summernote.ui;
8454
    this.options = context.options;
8455
    this.events = {
8456
      'summernote.keyup summernote.mouseup summernote.change summernote.scroll': function summernoteKeyupSummernoteMouseupSummernoteChangeSummernoteScroll() {
8457
        _this.update();
8458
      },
8459
      'summernote.disable summernote.dialog.shown': function summernoteDisableSummernoteDialogShown() {
8460
        _this.hide();
8461
      },
8462
      'summernote.blur': function summernoteBlur(we, e) {
8463
        if (e.originalEvent && e.originalEvent.relatedTarget) {
8464
          if (!_this.$popover[0].contains(e.originalEvent.relatedTarget)) {
8465
            _this.hide();
8466
          }
8467
        } else {
8468
          _this.hide();
8469
        }
8470
      }
8471
    };
8472
  }
8473

8474
  LinkPopover_createClass(LinkPopover, [{
8475
    key: "shouldInitialize",
8476
    value: function shouldInitialize() {
8477
      return !lists.isEmpty(this.options.popover.link);
8478
    }
8479
  }, {
8480
    key: "initialize",
8481
    value: function initialize() {
8482
      this.$popover = this.ui.popover({
8483
        className: 'note-link-popover',
8484
        callback: function callback($node) {
8485
          var $content = $node.find('.popover-content,.note-popover-content');
8486
          $content.prepend('<span><a target="_blank"></a>&nbsp;</span>');
8487
        }
8488
      }).render().appendTo(this.options.container);
8489
      var $content = this.$popover.find('.popover-content,.note-popover-content');
8490
      this.context.invoke('buttons.build', $content, this.options.popover.link);
8491
      this.$popover.on('mousedown', function (e) {
8492
        e.preventDefault();
8493
      });
8494
    }
8495
  }, {
8496
    key: "destroy",
8497
    value: function destroy() {
8498
      this.$popover.remove();
8499
    }
8500
  }, {
8501
    key: "update",
8502
    value: function update() {
8503
      // Prevent focusing on editable when invoke('code') is executed
8504
      if (!this.context.invoke('editor.hasFocus')) {
8505
        this.hide();
8506
        return;
8507
      }
8508

8509
      var rng = this.context.invoke('editor.getLastRange');
8510

8511
      if (rng.isCollapsed() && rng.isOnAnchor()) {
8512
        var anchor = dom.ancestor(rng.sc, dom.isAnchor);
8513
        var href = external_jQuery_default()(anchor).attr('href');
8514
        this.$popover.find('a').attr('href', href).text(href);
8515
        var pos = dom.posFromPlaceholder(anchor);
8516
        var containerOffset = external_jQuery_default()(this.options.container).offset();
8517
        pos.top -= containerOffset.top;
8518
        pos.left -= containerOffset.left;
8519
        this.$popover.css({
8520
          display: 'block',
8521
          left: pos.left,
8522
          top: pos.top
8523
        });
8524
      } else {
8525
        this.hide();
8526
      }
8527
    }
8528
  }, {
8529
    key: "hide",
8530
    value: function hide() {
8531
      this.$popover.hide();
8532
    }
8533
  }]);
8534

8535
  return LinkPopover;
8536
}();
8537

8538

8539
;// CONCATENATED MODULE: ./src/js/module/ImageDialog.js
8540
function ImageDialog_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8541

8542
function ImageDialog_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8543

8544
function ImageDialog_createClass(Constructor, protoProps, staticProps) { if (protoProps) ImageDialog_defineProperties(Constructor.prototype, protoProps); if (staticProps) ImageDialog_defineProperties(Constructor, staticProps); return Constructor; }
8545

8546

8547

8548

8549

8550
var ImageDialog = /*#__PURE__*/function () {
8551
  function ImageDialog(context) {
8552
    ImageDialog_classCallCheck(this, ImageDialog);
8553

8554
    this.context = context;
8555
    this.ui = (external_jQuery_default()).summernote.ui;
8556
    this.$body = external_jQuery_default()(document.body);
8557
    this.$editor = context.layoutInfo.editor;
8558
    this.options = context.options;
8559
    this.lang = this.options.langInfo;
8560
  }
8561

8562
  ImageDialog_createClass(ImageDialog, [{
8563
    key: "initialize",
8564
    value: function initialize() {
8565
      var imageLimitation = '';
8566

8567
      if (this.options.maximumImageFileSize) {
8568
        var unit = Math.floor(Math.log(this.options.maximumImageFileSize) / Math.log(1024));
8569
        var readableSize = (this.options.maximumImageFileSize / Math.pow(1024, unit)).toFixed(2) * 1 + ' ' + ' KMGTP'[unit] + 'B';
8570
        imageLimitation = "<small>".concat(this.lang.image.maximumFileSize + ' : ' + readableSize, "</small>");
8571
      }
8572

8573
      var $container = this.options.dialogsInBody ? this.$body : this.options.container;
8574
      var body = ['<div class="form-group note-form-group note-group-select-from-files">', '<label for="note-dialog-image-file-' + this.options.id + '" class="note-form-label">' + this.lang.image.selectFromFiles + '</label>', '<input id="note-dialog-image-file-' + this.options.id + '" class="note-image-input form-control-file note-form-control note-input" ', ' type="file" name="files" accept="' + this.options.acceptImageFileTypes + '" multiple="multiple"/>', imageLimitation, '</div>', '<div class="form-group note-group-image-url">', '<label for="note-dialog-image-url-' + this.options.id + '" class="note-form-label">' + this.lang.image.url + '</label>', '<input id="note-dialog-image-url-' + this.options.id + '" class="note-image-url form-control note-form-control note-input" type="text"/>', '</div>'].join('');
8575
      var buttonClass = 'btn btn-primary note-btn note-btn-primary note-image-btn';
8576
      var footer = "<input type=\"button\" href=\"#\" class=\"".concat(buttonClass, "\" value=\"").concat(this.lang.image.insert, "\" disabled>");
8577
      this.$dialog = this.ui.dialog({
8578
        title: this.lang.image.insert,
8579
        fade: this.options.dialogsFade,
8580
        body: body,
8581
        footer: footer
8582
      }).render().appendTo($container);
8583
    }
8584
  }, {
8585
    key: "destroy",
8586
    value: function destroy() {
8587
      this.ui.hideDialog(this.$dialog);
8588
      this.$dialog.remove();
8589
    }
8590
  }, {
8591
    key: "bindEnterKey",
8592
    value: function bindEnterKey($input, $btn) {
8593
      $input.on('keypress', function (event) {
8594
        if (event.keyCode === key.code.ENTER) {
8595
          event.preventDefault();
8596
          $btn.trigger('click');
8597
        }
8598
      });
8599
    }
8600
  }, {
8601
    key: "show",
8602
    value: function show() {
8603
      var _this = this;
8604

8605
      this.context.invoke('editor.saveRange');
8606
      this.showImageDialog().then(function (data) {
8607
        // [workaround] hide dialog before restore range for IE range focus
8608
        _this.ui.hideDialog(_this.$dialog);
8609

8610
        _this.context.invoke('editor.restoreRange');
8611

8612
        if (typeof data === 'string') {
8613
          // image url
8614
          // If onImageLinkInsert set,
8615
          if (_this.options.callbacks.onImageLinkInsert) {
8616
            _this.context.triggerEvent('image.link.insert', data);
8617
          } else {
8618
            _this.context.invoke('editor.insertImage', data);
8619
          }
8620
        } else {
8621
          // array of files
8622
          _this.context.invoke('editor.insertImagesOrCallback', data);
8623
        }
8624
      }).fail(function () {
8625
        _this.context.invoke('editor.restoreRange');
8626
      });
8627
    }
8628
    /**
8629
     * show image dialog
8630
     *
8631
     * @param {jQuery} $dialog
8632
     * @return {Promise}
8633
     */
8634

8635
  }, {
8636
    key: "showImageDialog",
8637
    value: function showImageDialog() {
8638
      var _this2 = this;
8639

8640
      return external_jQuery_default().Deferred(function (deferred) {
8641
        var $imageInput = _this2.$dialog.find('.note-image-input');
8642

8643
        var $imageUrl = _this2.$dialog.find('.note-image-url');
8644

8645
        var $imageBtn = _this2.$dialog.find('.note-image-btn');
8646

8647
        _this2.ui.onDialogShown(_this2.$dialog, function () {
8648
          _this2.context.triggerEvent('dialog.shown'); // Cloning imageInput to clear element.
8649

8650

8651
          $imageInput.replaceWith($imageInput.clone().on('change', function (event) {
8652
            deferred.resolve(event.target.files || event.target.value);
8653
          }).val(''));
8654
          $imageUrl.on('input paste propertychange', function () {
8655
            _this2.ui.toggleBtn($imageBtn, $imageUrl.val());
8656
          }).val('');
8657

8658
          if (!env.isSupportTouch) {
8659
            $imageUrl.trigger('focus');
8660
          }
8661

8662
          $imageBtn.click(function (event) {
8663
            event.preventDefault();
8664
            deferred.resolve($imageUrl.val());
8665
          });
8666

8667
          _this2.bindEnterKey($imageUrl, $imageBtn);
8668
        });
8669

8670
        _this2.ui.onDialogHidden(_this2.$dialog, function () {
8671
          $imageInput.off();
8672
          $imageUrl.off();
8673
          $imageBtn.off();
8674

8675
          if (deferred.state() === 'pending') {
8676
            deferred.reject();
8677
          }
8678
        });
8679

8680
        _this2.ui.showDialog(_this2.$dialog);
8681
      });
8682
    }
8683
  }]);
8684

8685
  return ImageDialog;
8686
}();
8687

8688

8689
;// CONCATENATED MODULE: ./src/js/module/ImagePopover.js
8690
function ImagePopover_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8691

8692
function ImagePopover_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8693

8694
function ImagePopover_createClass(Constructor, protoProps, staticProps) { if (protoProps) ImagePopover_defineProperties(Constructor.prototype, protoProps); if (staticProps) ImagePopover_defineProperties(Constructor, staticProps); return Constructor; }
8695

8696

8697

8698

8699
/**
8700
 * Image popover module
8701
 *  mouse events that show/hide popover will be handled by Handle.js.
8702
 *  Handle.js will receive the events and invoke 'imagePopover.update'.
8703
 */
8704

8705
var ImagePopover = /*#__PURE__*/function () {
8706
  function ImagePopover(context) {
8707
    var _this = this;
8708

8709
    ImagePopover_classCallCheck(this, ImagePopover);
8710

8711
    this.context = context;
8712
    this.ui = (external_jQuery_default()).summernote.ui;
8713
    this.editable = context.layoutInfo.editable[0];
8714
    this.options = context.options;
8715
    this.events = {
8716
      'summernote.disable summernote.dialog.shown': function summernoteDisableSummernoteDialogShown() {
8717
        _this.hide();
8718
      },
8719
      'summernote.blur': function summernoteBlur(we, e) {
8720
        if (e.originalEvent && e.originalEvent.relatedTarget) {
8721
          if (!_this.$popover[0].contains(e.originalEvent.relatedTarget)) {
8722
            _this.hide();
8723
          }
8724
        } else {
8725
          _this.hide();
8726
        }
8727
      }
8728
    };
8729
  }
8730

8731
  ImagePopover_createClass(ImagePopover, [{
8732
    key: "shouldInitialize",
8733
    value: function shouldInitialize() {
8734
      return !lists.isEmpty(this.options.popover.image);
8735
    }
8736
  }, {
8737
    key: "initialize",
8738
    value: function initialize() {
8739
      this.$popover = this.ui.popover({
8740
        className: 'note-image-popover'
8741
      }).render().appendTo(this.options.container);
8742
      var $content = this.$popover.find('.popover-content,.note-popover-content');
8743
      this.context.invoke('buttons.build', $content, this.options.popover.image);
8744
      this.$popover.on('mousedown', function (e) {
8745
        e.preventDefault();
8746
      });
8747
    }
8748
  }, {
8749
    key: "destroy",
8750
    value: function destroy() {
8751
      this.$popover.remove();
8752
    }
8753
  }, {
8754
    key: "update",
8755
    value: function update(target, event) {
8756
      if (dom.isImg(target)) {
8757
        var position = external_jQuery_default()(target).offset();
8758
        var containerOffset = external_jQuery_default()(this.options.container).offset();
8759
        var pos = {};
8760

8761
        if (this.options.popatmouse) {
8762
          pos.left = event.pageX - 20;
8763
          pos.top = event.pageY;
8764
        } else {
8765
          pos = position;
8766
        }
8767

8768
        pos.top -= containerOffset.top;
8769
        pos.left -= containerOffset.left;
8770
        this.$popover.css({
8771
          display: 'block',
8772
          left: pos.left,
8773
          top: pos.top
8774
        });
8775
      } else {
8776
        this.hide();
8777
      }
8778
    }
8779
  }, {
8780
    key: "hide",
8781
    value: function hide() {
8782
      this.$popover.hide();
8783
    }
8784
  }]);
8785

8786
  return ImagePopover;
8787
}();
8788

8789

8790
;// CONCATENATED MODULE: ./src/js/module/TablePopover.js
8791
function TablePopover_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8792

8793
function TablePopover_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8794

8795
function TablePopover_createClass(Constructor, protoProps, staticProps) { if (protoProps) TablePopover_defineProperties(Constructor.prototype, protoProps); if (staticProps) TablePopover_defineProperties(Constructor, staticProps); return Constructor; }
8796

8797

8798

8799

8800

8801

8802
var TablePopover = /*#__PURE__*/function () {
8803
  function TablePopover(context) {
8804
    var _this = this;
8805

8806
    TablePopover_classCallCheck(this, TablePopover);
8807

8808
    this.context = context;
8809
    this.ui = (external_jQuery_default()).summernote.ui;
8810
    this.options = context.options;
8811
    this.events = {
8812
      'summernote.mousedown': function summernoteMousedown(we, e) {
8813
        _this.update(e.target);
8814
      },
8815
      'summernote.keyup summernote.scroll summernote.change': function summernoteKeyupSummernoteScrollSummernoteChange() {
8816
        _this.update();
8817
      },
8818
      'summernote.disable summernote.dialog.shown': function summernoteDisableSummernoteDialogShown() {
8819
        _this.hide();
8820
      },
8821
      'summernote.blur': function summernoteBlur(we, e) {
8822
        if (e.originalEvent && e.originalEvent.relatedTarget) {
8823
          if (!_this.$popover[0].contains(e.originalEvent.relatedTarget)) {
8824
            _this.hide();
8825
          }
8826
        } else {
8827
          _this.hide();
8828
        }
8829
      }
8830
    };
8831
  }
8832

8833
  TablePopover_createClass(TablePopover, [{
8834
    key: "shouldInitialize",
8835
    value: function shouldInitialize() {
8836
      return !lists.isEmpty(this.options.popover.table);
8837
    }
8838
  }, {
8839
    key: "initialize",
8840
    value: function initialize() {
8841
      this.$popover = this.ui.popover({
8842
        className: 'note-table-popover'
8843
      }).render().appendTo(this.options.container);
8844
      var $content = this.$popover.find('.popover-content,.note-popover-content');
8845
      this.context.invoke('buttons.build', $content, this.options.popover.table); // [workaround] Disable Firefox's default table editor
8846

8847
      if (env.isFF) {
8848
        document.execCommand('enableInlineTableEditing', false, false);
8849
      }
8850

8851
      this.$popover.on('mousedown', function (e) {
8852
        e.preventDefault();
8853
      });
8854
    }
8855
  }, {
8856
    key: "destroy",
8857
    value: function destroy() {
8858
      this.$popover.remove();
8859
    }
8860
  }, {
8861
    key: "update",
8862
    value: function update(target) {
8863
      if (this.context.isDisabled()) {
8864
        return false;
8865
      }
8866

8867
      var isCell = dom.isCell(target) || dom.isCell(target === null || target === void 0 ? void 0 : target.parentElement);
8868

8869
      if (isCell) {
8870
        var pos = dom.posFromPlaceholder(target);
8871
        var containerOffset = external_jQuery_default()(this.options.container).offset();
8872
        pos.top -= containerOffset.top;
8873
        pos.left -= containerOffset.left;
8874
        this.$popover.css({
8875
          display: 'block',
8876
          left: pos.left,
8877
          top: pos.top
8878
        });
8879
      } else {
8880
        this.hide();
8881
      }
8882

8883
      return isCell;
8884
    }
8885
  }, {
8886
    key: "hide",
8887
    value: function hide() {
8888
      this.$popover.hide();
8889
    }
8890
  }]);
8891

8892
  return TablePopover;
8893
}();
8894

8895

8896
;// CONCATENATED MODULE: ./src/js/module/VideoDialog.js
8897
function VideoDialog_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8898

8899
function VideoDialog_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8900

8901
function VideoDialog_createClass(Constructor, protoProps, staticProps) { if (protoProps) VideoDialog_defineProperties(Constructor.prototype, protoProps); if (staticProps) VideoDialog_defineProperties(Constructor, staticProps); return Constructor; }
8902

8903

8904

8905

8906

8907
var VideoDialog = /*#__PURE__*/function () {
8908
  function VideoDialog(context) {
8909
    VideoDialog_classCallCheck(this, VideoDialog);
8910

8911
    this.context = context;
8912
    this.ui = (external_jQuery_default()).summernote.ui;
8913
    this.$body = external_jQuery_default()(document.body);
8914
    this.$editor = context.layoutInfo.editor;
8915
    this.options = context.options;
8916
    this.lang = this.options.langInfo;
8917
  }
8918

8919
  VideoDialog_createClass(VideoDialog, [{
8920
    key: "initialize",
8921
    value: function initialize() {
8922
      var $container = this.options.dialogsInBody ? this.$body : this.options.container;
8923
      var body = ['<div class="form-group note-form-group row-fluid">', "<label for=\"note-dialog-video-url-".concat(this.options.id, "\" class=\"note-form-label\">").concat(this.lang.video.url, " <small class=\"text-muted\">").concat(this.lang.video.providers, "</small></label>"), "<input id=\"note-dialog-video-url-".concat(this.options.id, "\" class=\"note-video-url form-control note-form-control note-input\" type=\"text\"/>"), '</div>'].join('');
8924
      var buttonClass = 'btn btn-primary note-btn note-btn-primary note-video-btn';
8925
      var footer = "<input type=\"button\" href=\"#\" class=\"".concat(buttonClass, "\" value=\"").concat(this.lang.video.insert, "\" disabled>");
8926
      this.$dialog = this.ui.dialog({
8927
        title: this.lang.video.insert,
8928
        fade: this.options.dialogsFade,
8929
        body: body,
8930
        footer: footer
8931
      }).render().appendTo($container);
8932
    }
8933
  }, {
8934
    key: "destroy",
8935
    value: function destroy() {
8936
      this.ui.hideDialog(this.$dialog);
8937
      this.$dialog.remove();
8938
    }
8939
  }, {
8940
    key: "bindEnterKey",
8941
    value: function bindEnterKey($input, $btn) {
8942
      $input.on('keypress', function (event) {
8943
        if (event.keyCode === key.code.ENTER) {
8944
          event.preventDefault();
8945
          $btn.trigger('click');
8946
        }
8947
      });
8948
    }
8949
  }, {
8950
    key: "createVideoNode",
8951
    value: function createVideoNode(url) {
8952
      // video url patterns(youtube, instagram, vimeo, dailymotion, youku, peertube, mp4, ogg, webm)
8953
      var ytRegExp = /\/\/(?:(?:www|m)\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w|-]{11})(?:(?:[\?&]t=)(\S+))?$/;
8954
      var ytRegExpForStart = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/;
8955
      var ytMatch = url.match(ytRegExp);
8956
      var gdRegExp = /(?:\.|\/\/)drive\.google\.com\/file\/d\/(.[a-zA-Z0-9_-]*)\/view/;
8957
      var gdMatch = url.match(gdRegExp);
8958
      var igRegExp = /(?:www\.|\/\/)instagram\.com\/p\/(.[a-zA-Z0-9_-]*)/;
8959
      var igMatch = url.match(igRegExp);
8960
      var vRegExp = /\/\/vine\.co\/v\/([a-zA-Z0-9]+)/;
8961
      var vMatch = url.match(vRegExp);
8962
      var vimRegExp = /\/\/(player\.)?vimeo\.com\/([a-z]*\/)*(\d+)[?]?.*/;
8963
      var vimMatch = url.match(vimRegExp);
8964
      var dmRegExp = /.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/;
8965
      var dmMatch = url.match(dmRegExp);
8966
      var youkuRegExp = /\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/;
8967
      var youkuMatch = url.match(youkuRegExp);
8968
      var peerTubeRegExp = /\/\/(.*)\/videos\/watch\/([^?]*)(?:\?(?:start=(\w*))?(?:&stop=(\w*))?(?:&loop=([10]))?(?:&autoplay=([10]))?(?:&muted=([10]))?)?/;
8969
      var peerTubeMatch = url.match(peerTubeRegExp);
8970
      var qqRegExp = /\/\/v\.qq\.com.*?vid=(.+)/;
8971
      var qqMatch = url.match(qqRegExp);
8972
      var qqRegExp2 = /\/\/v\.qq\.com\/x?\/?(page|cover).*?\/([^\/]+)\.html\??.*/;
8973
      var qqMatch2 = url.match(qqRegExp2);
8974
      var mp4RegExp = /^.+.(mp4|m4v)$/;
8975
      var mp4Match = url.match(mp4RegExp);
8976
      var oggRegExp = /^.+.(ogg|ogv)$/;
8977
      var oggMatch = url.match(oggRegExp);
8978
      var webmRegExp = /^.+.(webm)$/;
8979
      var webmMatch = url.match(webmRegExp);
8980
      var fbRegExp = /(?:www\.|\/\/)facebook\.com\/([^\/]+)\/videos\/([0-9]+)/;
8981
      var fbMatch = url.match(fbRegExp);
8982
      var $video;
8983

8984
      if (ytMatch && ytMatch[1].length === 11) {
8985
        var youtubeId = ytMatch[1];
8986
        var start = 0;
8987

8988
        if (typeof ytMatch[2] !== 'undefined') {
8989
          var ytMatchForStart = ytMatch[2].match(ytRegExpForStart);
8990

8991
          if (ytMatchForStart) {
8992
            for (var n = [3600, 60, 1], i = 0, r = n.length; i < r; i++) {
8993
              start += typeof ytMatchForStart[i + 1] !== 'undefined' ? n[i] * parseInt(ytMatchForStart[i + 1], 10) : 0;
8994
            }
8995
          }
8996
        }
8997

8998
        $video = external_jQuery_default()('<iframe>').attr('frameborder', 0).attr('src', '//www.youtube.com/embed/' + youtubeId + (start > 0 ? '?start=' + start : '')).attr('width', '640').attr('height', '360');
8999
      } else if (gdMatch && gdMatch[0].length) {
9000
        $video = external_jQuery_default()('<iframe>').attr('frameborder', 0).attr('src', 'https://drive.google.com/file/d/' + gdMatch[1] + '/preview').attr('width', '640').attr('height', '480');
9001
      } else if (igMatch && igMatch[0].length) {
9002
        $video = external_jQuery_default()('<iframe>').attr('frameborder', 0).attr('src', 'https://instagram.com/p/' + igMatch[1] + '/embed/').attr('width', '612').attr('height', '710').attr('scrolling', 'no').attr('allowtransparency', 'true');
9003
      } else if (vMatch && vMatch[0].length) {
9004
        $video = external_jQuery_default()('<iframe>').attr('frameborder', 0).attr('src', vMatch[0] + '/embed/simple').attr('width', '600').attr('height', '600').attr('class', 'vine-embed');
9005
      } else if (vimMatch && vimMatch[3].length) {
9006
        $video = external_jQuery_default()('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>').attr('frameborder', 0).attr('src', '//player.vimeo.com/video/' + vimMatch[3]).attr('width', '640').attr('height', '360');
9007
      } else if (dmMatch && dmMatch[2].length) {
9008
        $video = external_jQuery_default()('<iframe>').attr('frameborder', 0).attr('src', '//www.dailymotion.com/embed/video/' + dmMatch[2]).attr('width', '640').attr('height', '360');
9009
      } else if (youkuMatch && youkuMatch[1].length) {
9010
        $video = external_jQuery_default()('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>').attr('frameborder', 0).attr('height', '498').attr('width', '510').attr('src', '//player.youku.com/embed/' + youkuMatch[1]);
9011
      } else if (peerTubeMatch && peerTubeMatch[0].length) {
9012
        var begin = 0;
9013
        if (peerTubeMatch[2] !== 'undefined') begin = peerTubeMatch[2];
9014
        var end = 0;
9015
        if (peerTubeMatch[3] !== 'undefined') end = peerTubeMatch[3];
9016
        var loop = 0;
9017
        if (peerTubeMatch[4] !== 'undefined') loop = peerTubeMatch[4];
9018
        var autoplay = 0;
9019
        if (peerTubeMatch[5] !== 'undefined') autoplay = peerTubeMatch[5];
9020
        var muted = 0;
9021
        if (peerTubeMatch[6] !== 'undefined') muted = peerTubeMatch[6];
9022
        $video = external_jQuery_default()('<iframe allowfullscreen sandbox="allow-same-origin allow-scripts allow-popups">').attr('frameborder', 0).attr('src', '//' + peerTubeMatch[1] + '/videos/embed/' + peerTubeMatch[2] + "?loop=" + loop + "&autoplay=" + autoplay + "&muted=" + muted + (begin > 0 ? '&start=' + begin : '') + (end > 0 ? '&end=' + start : '')).attr('width', '560').attr('height', '315');
9023
      } else if (qqMatch && qqMatch[1].length || qqMatch2 && qqMatch2[2].length) {
9024
        var vid = qqMatch && qqMatch[1].length ? qqMatch[1] : qqMatch2[2];
9025
        $video = external_jQuery_default()('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>').attr('frameborder', 0).attr('height', '310').attr('width', '500').attr('src', 'https://v.qq.com/txp/iframe/player.html?vid=' + vid + '&amp;auto=0');
9026
      } else if (mp4Match || oggMatch || webmMatch) {
9027
        $video = external_jQuery_default()('<video controls>').attr('src', url).attr('width', '640').attr('height', '360');
9028
      } else if (fbMatch && fbMatch[0].length) {
9029
        $video = external_jQuery_default()('<iframe>').attr('frameborder', 0).attr('src', 'https://www.facebook.com/plugins/video.php?href=' + encodeURIComponent(fbMatch[0]) + '&show_text=0&width=560').attr('width', '560').attr('height', '301').attr('scrolling', 'no').attr('allowtransparency', 'true');
9030
      } else {
9031
        // this is not a known video link. Now what, Cat? Now what?
9032
        return false;
9033
      }
9034

9035
      $video.addClass('note-video-clip');
9036
      return $video[0];
9037
    }
9038
  }, {
9039
    key: "show",
9040
    value: function show() {
9041
      var _this = this;
9042

9043
      var text = this.context.invoke('editor.getSelectedText');
9044
      this.context.invoke('editor.saveRange');
9045
      this.showVideoDialog(text).then(function (url) {
9046
        // [workaround] hide dialog before restore range for IE range focus
9047
        _this.ui.hideDialog(_this.$dialog);
9048

9049
        _this.context.invoke('editor.restoreRange'); // build node
9050

9051

9052
        var $node = _this.createVideoNode(url);
9053

9054
        if ($node) {
9055
          // insert video node
9056
          _this.context.invoke('editor.insertNode', $node);
9057
        }
9058
      }).fail(function () {
9059
        _this.context.invoke('editor.restoreRange');
9060
      });
9061
    }
9062
    /**
9063
     * show video dialog
9064
     *
9065
     * @param {jQuery} $dialog
9066
     * @return {Promise}
9067
     */
9068

9069
  }, {
9070
    key: "showVideoDialog",
9071
    value: function showVideoDialog() {
9072
      var _this2 = this;
9073

9074
      return external_jQuery_default().Deferred(function (deferred) {
9075
        var $videoUrl = _this2.$dialog.find('.note-video-url');
9076

9077
        var $videoBtn = _this2.$dialog.find('.note-video-btn');
9078

9079
        _this2.ui.onDialogShown(_this2.$dialog, function () {
9080
          _this2.context.triggerEvent('dialog.shown');
9081

9082
          $videoUrl.on('input paste propertychange', function () {
9083
            _this2.ui.toggleBtn($videoBtn, $videoUrl.val());
9084
          });
9085

9086
          if (!env.isSupportTouch) {
9087
            $videoUrl.trigger('focus');
9088
          }
9089

9090
          $videoBtn.click(function (event) {
9091
            event.preventDefault();
9092
            deferred.resolve($videoUrl.val());
9093
          });
9094

9095
          _this2.bindEnterKey($videoUrl, $videoBtn);
9096
        });
9097

9098
        _this2.ui.onDialogHidden(_this2.$dialog, function () {
9099
          $videoUrl.off();
9100
          $videoBtn.off();
9101

9102
          if (deferred.state() === 'pending') {
9103
            deferred.reject();
9104
          }
9105
        });
9106

9107
        _this2.ui.showDialog(_this2.$dialog);
9108
      });
9109
    }
9110
  }]);
9111

9112
  return VideoDialog;
9113
}();
9114

9115

9116
;// CONCATENATED MODULE: ./src/js/module/HelpDialog.js
9117
function HelpDialog_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9118

9119
function HelpDialog_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
9120

9121
function HelpDialog_createClass(Constructor, protoProps, staticProps) { if (protoProps) HelpDialog_defineProperties(Constructor.prototype, protoProps); if (staticProps) HelpDialog_defineProperties(Constructor, staticProps); return Constructor; }
9122

9123

9124

9125

9126
var HelpDialog = /*#__PURE__*/function () {
9127
  function HelpDialog(context) {
9128
    HelpDialog_classCallCheck(this, HelpDialog);
9129

9130
    this.context = context;
9131
    this.ui = (external_jQuery_default()).summernote.ui;
9132
    this.$body = external_jQuery_default()(document.body);
9133
    this.$editor = context.layoutInfo.editor;
9134
    this.options = context.options;
9135
    this.lang = this.options.langInfo;
9136
  }
9137

9138
  HelpDialog_createClass(HelpDialog, [{
9139
    key: "initialize",
9140
    value: function initialize() {
9141
      var $container = this.options.dialogsInBody ? this.$body : this.options.container;
9142
      var body = ['<p class="text-center">', '<a href="http://summernote.org/" target="_blank" rel="noopener noreferrer">Summernote 0.8.20</a> · ', '<a href="https://github.com/summernote/summernote" target="_blank" rel="noopener noreferrer">Project</a> · ', '<a href="https://github.com/summernote/summernote/issues" target="_blank" rel="noopener noreferrer">Issues</a>', '</p>'].join('');
9143
      this.$dialog = this.ui.dialog({
9144
        title: this.lang.options.help,
9145
        fade: this.options.dialogsFade,
9146
        body: this.createShortcutList(),
9147
        footer: body,
9148
        callback: function callback($node) {
9149
          $node.find('.modal-body,.note-modal-body').css({
9150
            'max-height': 300,
9151
            'overflow': 'scroll'
9152
          });
9153
        }
9154
      }).render().appendTo($container);
9155
    }
9156
  }, {
9157
    key: "destroy",
9158
    value: function destroy() {
9159
      this.ui.hideDialog(this.$dialog);
9160
      this.$dialog.remove();
9161
    }
9162
  }, {
9163
    key: "createShortcutList",
9164
    value: function createShortcutList() {
9165
      var _this = this;
9166

9167
      var keyMap = this.options.keyMap[env.isMac ? 'mac' : 'pc'];
9168
      return Object.keys(keyMap).map(function (key) {
9169
        var command = keyMap[key];
9170
        var $row = external_jQuery_default()('<div><div class="help-list-item"></div></div>');
9171
        $row.append(external_jQuery_default()('<label><kbd>' + key + '</kdb></label>').css({
9172
          'width': 180,
9173
          'margin-right': 10
9174
        })).append(external_jQuery_default()('<span></span>').html(_this.context.memo('help.' + command) || command));
9175
        return $row.html();
9176
      }).join('');
9177
    }
9178
    /**
9179
     * show help dialog
9180
     *
9181
     * @return {Promise}
9182
     */
9183

9184
  }, {
9185
    key: "showHelpDialog",
9186
    value: function showHelpDialog() {
9187
      var _this2 = this;
9188

9189
      return external_jQuery_default().Deferred(function (deferred) {
9190
        _this2.ui.onDialogShown(_this2.$dialog, function () {
9191
          _this2.context.triggerEvent('dialog.shown');
9192

9193
          deferred.resolve();
9194
        });
9195

9196
        _this2.ui.showDialog(_this2.$dialog);
9197
      }).promise();
9198
    }
9199
  }, {
9200
    key: "show",
9201
    value: function show() {
9202
      var _this3 = this;
9203

9204
      this.context.invoke('editor.saveRange');
9205
      this.showHelpDialog().then(function () {
9206
        _this3.context.invoke('editor.restoreRange');
9207
      });
9208
    }
9209
  }]);
9210

9211
  return HelpDialog;
9212
}();
9213

9214

9215
;// CONCATENATED MODULE: ./src/js/module/AirPopover.js
9216
function AirPopover_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9217

9218
function AirPopover_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
9219

9220
function AirPopover_createClass(Constructor, protoProps, staticProps) { if (protoProps) AirPopover_defineProperties(Constructor.prototype, protoProps); if (staticProps) AirPopover_defineProperties(Constructor, staticProps); return Constructor; }
9221

9222

9223

9224
var AIRMODE_POPOVER_X_OFFSET = -5;
9225
var AIRMODE_POPOVER_Y_OFFSET = 5;
9226

9227
var AirPopover = /*#__PURE__*/function () {
9228
  function AirPopover(context) {
9229
    var _this = this;
9230

9231
    AirPopover_classCallCheck(this, AirPopover);
9232

9233
    this.context = context;
9234
    this.ui = (external_jQuery_default()).summernote.ui;
9235
    this.options = context.options;
9236
    this.hidable = true;
9237
    this.onContextmenu = false;
9238
    this.pageX = null;
9239
    this.pageY = null;
9240
    this.events = {
9241
      'summernote.contextmenu': function summernoteContextmenu(e) {
9242
        if (_this.options.editing) {
9243
          e.preventDefault();
9244
          e.stopPropagation();
9245
          _this.onContextmenu = true;
9246

9247
          _this.update(true);
9248
        }
9249
      },
9250
      'summernote.mousedown': function summernoteMousedown(we, e) {
9251
        _this.pageX = e.pageX;
9252
        _this.pageY = e.pageY;
9253
      },
9254
      'summernote.keyup summernote.mouseup summernote.scroll': function summernoteKeyupSummernoteMouseupSummernoteScroll(we, e) {
9255
        if (_this.options.editing && !_this.onContextmenu) {
9256
          _this.pageX = e.pageX;
9257
          _this.pageY = e.pageY;
9258

9259
          _this.update();
9260
        }
9261

9262
        _this.onContextmenu = false;
9263
      },
9264
      'summernote.disable summernote.change summernote.dialog.shown summernote.blur': function summernoteDisableSummernoteChangeSummernoteDialogShownSummernoteBlur() {
9265
        _this.hide();
9266
      },
9267
      'summernote.focusout': function summernoteFocusout() {
9268
        if (!_this.$popover.is(':active,:focus')) {
9269
          _this.hide();
9270
        }
9271
      }
9272
    };
9273
  }
9274

9275
  AirPopover_createClass(AirPopover, [{
9276
    key: "shouldInitialize",
9277
    value: function shouldInitialize() {
9278
      return this.options.airMode && !lists.isEmpty(this.options.popover.air);
9279
    }
9280
  }, {
9281
    key: "initialize",
9282
    value: function initialize() {
9283
      var _this2 = this;
9284

9285
      this.$popover = this.ui.popover({
9286
        className: 'note-air-popover'
9287
      }).render().appendTo(this.options.container);
9288
      var $content = this.$popover.find('.popover-content');
9289
      this.context.invoke('buttons.build', $content, this.options.popover.air); // disable hiding this popover preemptively by 'summernote.blur' event.
9290

9291
      this.$popover.on('mousedown', function () {
9292
        _this2.hidable = false;
9293
      }); // (re-)enable hiding after 'summernote.blur' has been handled (aka. ignored).
9294

9295
      this.$popover.on('mouseup', function () {
9296
        _this2.hidable = true;
9297
      });
9298
    }
9299
  }, {
9300
    key: "destroy",
9301
    value: function destroy() {
9302
      this.$popover.remove();
9303
    }
9304
  }, {
9305
    key: "update",
9306
    value: function update(forcelyOpen) {
9307
      var styleInfo = this.context.invoke('editor.currentStyle');
9308

9309
      if (styleInfo.range && (!styleInfo.range.isCollapsed() || forcelyOpen)) {
9310
        var rect = {
9311
          left: this.pageX,
9312
          top: this.pageY
9313
        };
9314
        var containerOffset = external_jQuery_default()(this.options.container).offset();
9315
        rect.top -= containerOffset.top;
9316
        rect.left -= containerOffset.left;
9317
        this.$popover.css({
9318
          display: 'block',
9319
          left: Math.max(rect.left, 0) + AIRMODE_POPOVER_X_OFFSET,
9320
          top: rect.top + AIRMODE_POPOVER_Y_OFFSET
9321
        });
9322
        this.context.invoke('buttons.updateCurrentStyle', this.$popover);
9323
      } else {
9324
        this.hide();
9325
      }
9326
    }
9327
  }, {
9328
    key: "updateCodeview",
9329
    value: function updateCodeview(isCodeview) {
9330
      this.ui.toggleBtnActive(this.$popover.find('.btn-codeview'), isCodeview);
9331

9332
      if (isCodeview) {
9333
        this.hide();
9334
      }
9335
    }
9336
  }, {
9337
    key: "hide",
9338
    value: function hide() {
9339
      if (this.hidable) {
9340
        this.$popover.hide();
9341
      }
9342
    }
9343
  }]);
9344

9345
  return AirPopover;
9346
}();
9347

9348

9349
;// CONCATENATED MODULE: ./src/js/module/HintPopover.js
9350
function HintPopover_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9351

9352
function HintPopover_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
9353

9354
function HintPopover_createClass(Constructor, protoProps, staticProps) { if (protoProps) HintPopover_defineProperties(Constructor.prototype, protoProps); if (staticProps) HintPopover_defineProperties(Constructor, staticProps); return Constructor; }
9355

9356

9357

9358

9359

9360

9361

9362
var POPOVER_DIST = 5;
9363

9364
var HintPopover = /*#__PURE__*/function () {
9365
  function HintPopover(context) {
9366
    var _this = this;
9367

9368
    HintPopover_classCallCheck(this, HintPopover);
9369

9370
    this.context = context;
9371
    this.ui = (external_jQuery_default()).summernote.ui;
9372
    this.$editable = context.layoutInfo.editable;
9373
    this.options = context.options;
9374
    this.hint = this.options.hint || [];
9375
    this.direction = this.options.hintDirection || 'bottom';
9376
    this.hints = Array.isArray(this.hint) ? this.hint : [this.hint];
9377
    this.events = {
9378
      'summernote.keyup': function summernoteKeyup(we, e) {
9379
        if (!e.isDefaultPrevented()) {
9380
          _this.handleKeyup(e);
9381
        }
9382
      },
9383
      'summernote.keydown': function summernoteKeydown(we, e) {
9384
        _this.handleKeydown(e);
9385
      },
9386
      'summernote.disable summernote.dialog.shown summernote.blur': function summernoteDisableSummernoteDialogShownSummernoteBlur() {
9387
        _this.hide();
9388
      }
9389
    };
9390
  }
9391

9392
  HintPopover_createClass(HintPopover, [{
9393
    key: "shouldInitialize",
9394
    value: function shouldInitialize() {
9395
      return this.hints.length > 0;
9396
    }
9397
  }, {
9398
    key: "initialize",
9399
    value: function initialize() {
9400
      var _this2 = this;
9401

9402
      this.lastWordRange = null;
9403
      this.matchingWord = null;
9404
      this.$popover = this.ui.popover({
9405
        className: 'note-hint-popover',
9406
        hideArrow: true,
9407
        direction: ''
9408
      }).render().appendTo(this.options.container);
9409
      this.$popover.hide();
9410
      this.$content = this.$popover.find('.popover-content,.note-popover-content');
9411
      this.$content.on('click', '.note-hint-item', function (e) {
9412
        _this2.$content.find('.active').removeClass('active');
9413

9414
        external_jQuery_default()(e.currentTarget).addClass('active');
9415

9416
        _this2.replace();
9417
      });
9418
      this.$popover.on('mousedown', function (e) {
9419
        e.preventDefault();
9420
      });
9421
    }
9422
  }, {
9423
    key: "destroy",
9424
    value: function destroy() {
9425
      this.$popover.remove();
9426
    }
9427
  }, {
9428
    key: "selectItem",
9429
    value: function selectItem($item) {
9430
      this.$content.find('.active').removeClass('active');
9431
      $item.addClass('active');
9432
      this.$content[0].scrollTop = $item[0].offsetTop - this.$content.innerHeight() / 2;
9433
    }
9434
  }, {
9435
    key: "moveDown",
9436
    value: function moveDown() {
9437
      var $current = this.$content.find('.note-hint-item.active');
9438
      var $next = $current.next();
9439

9440
      if ($next.length) {
9441
        this.selectItem($next);
9442
      } else {
9443
        var $nextGroup = $current.parent().next();
9444

9445
        if (!$nextGroup.length) {
9446
          $nextGroup = this.$content.find('.note-hint-group').first();
9447
        }
9448

9449
        this.selectItem($nextGroup.find('.note-hint-item').first());
9450
      }
9451
    }
9452
  }, {
9453
    key: "moveUp",
9454
    value: function moveUp() {
9455
      var $current = this.$content.find('.note-hint-item.active');
9456
      var $prev = $current.prev();
9457

9458
      if ($prev.length) {
9459
        this.selectItem($prev);
9460
      } else {
9461
        var $prevGroup = $current.parent().prev();
9462

9463
        if (!$prevGroup.length) {
9464
          $prevGroup = this.$content.find('.note-hint-group').last();
9465
        }
9466

9467
        this.selectItem($prevGroup.find('.note-hint-item').last());
9468
      }
9469
    }
9470
  }, {
9471
    key: "replace",
9472
    value: function replace() {
9473
      var $item = this.$content.find('.note-hint-item.active');
9474

9475
      if ($item.length) {
9476
        var node = this.nodeFromItem($item); // If matchingWord length = 0 -> capture OK / open hint / but as mention capture "" (\w*)
9477

9478
        if (this.matchingWord !== null && this.matchingWord.length === 0) {
9479
          this.lastWordRange.so = this.lastWordRange.eo; // Else si > 0 and normal case -> adjust range "before" for correct position of insertion
9480
        } else if (this.matchingWord !== null && this.matchingWord.length > 0 && !this.lastWordRange.isCollapsed()) {
9481
          var rangeCompute = this.lastWordRange.eo - this.lastWordRange.so - this.matchingWord.length;
9482

9483
          if (rangeCompute > 0) {
9484
            this.lastWordRange.so += rangeCompute;
9485
          }
9486
        }
9487

9488
        this.lastWordRange.insertNode(node);
9489

9490
        if (this.options.hintSelect === 'next') {
9491
          var blank = document.createTextNode('');
9492
          external_jQuery_default()(node).after(blank);
9493
          range.createFromNodeBefore(blank).select();
9494
        } else {
9495
          range.createFromNodeAfter(node).select();
9496
        }
9497

9498
        this.lastWordRange = null;
9499
        this.hide();
9500
        this.context.invoke('editor.focus');
9501
        this.context.triggerEvent('change', this.$editable.html(), this.$editable);
9502
      }
9503
    }
9504
  }, {
9505
    key: "nodeFromItem",
9506
    value: function nodeFromItem($item) {
9507
      var hint = this.hints[$item.data('index')];
9508
      var item = $item.data('item');
9509
      var node = hint.content ? hint.content(item) : item;
9510

9511
      if (typeof node === 'string') {
9512
        node = dom.createText(node);
9513
      }
9514

9515
      return node;
9516
    }
9517
  }, {
9518
    key: "createItemTemplates",
9519
    value: function createItemTemplates(hintIdx, items) {
9520
      var hint = this.hints[hintIdx];
9521
      return items.map(function (item
9522
      /*, idx */
9523
      ) {
9524
        var $item = external_jQuery_default()('<div class="note-hint-item"></div>');
9525
        $item.append(hint.template ? hint.template(item) : item + '');
9526
        $item.data({
9527
          'index': hintIdx,
9528
          'item': item
9529
        });
9530
        return $item;
9531
      });
9532
    }
9533
  }, {
9534
    key: "handleKeydown",
9535
    value: function handleKeydown(e) {
9536
      if (!this.$popover.is(':visible')) {
9537
        return;
9538
      }
9539

9540
      if (e.keyCode === key.code.ENTER) {
9541
        e.preventDefault();
9542
        this.replace();
9543
      } else if (e.keyCode === key.code.UP) {
9544
        e.preventDefault();
9545
        this.moveUp();
9546
      } else if (e.keyCode === key.code.DOWN) {
9547
        e.preventDefault();
9548
        this.moveDown();
9549
      }
9550
    }
9551
  }, {
9552
    key: "searchKeyword",
9553
    value: function searchKeyword(index, keyword, callback) {
9554
      var hint = this.hints[index];
9555

9556
      if (hint && hint.match.test(keyword) && hint.search) {
9557
        var matches = hint.match.exec(keyword);
9558
        this.matchingWord = matches[0];
9559
        hint.search(matches[1], callback);
9560
      } else {
9561
        callback();
9562
      }
9563
    }
9564
  }, {
9565
    key: "createGroup",
9566
    value: function createGroup(idx, keyword) {
9567
      var _this3 = this;
9568

9569
      var $group = external_jQuery_default()('<div class="note-hint-group note-hint-group-' + idx + '"></div>');
9570
      this.searchKeyword(idx, keyword, function (items) {
9571
        items = items || [];
9572

9573
        if (items.length) {
9574
          $group.html(_this3.createItemTemplates(idx, items));
9575

9576
          _this3.show();
9577
        }
9578
      });
9579
      return $group;
9580
    }
9581
  }, {
9582
    key: "handleKeyup",
9583
    value: function handleKeyup(e) {
9584
      var _this4 = this;
9585

9586
      if (!lists.contains([key.code.ENTER, key.code.UP, key.code.DOWN], e.keyCode)) {
9587
        var _range = this.context.invoke('editor.getLastRange');
9588

9589
        var wordRange, keyword;
9590

9591
        if (this.options.hintMode === 'words') {
9592
          wordRange = _range.getWordsRange(_range);
9593
          keyword = wordRange.toString();
9594
          this.hints.forEach(function (hint) {
9595
            if (hint.match.test(keyword)) {
9596
              wordRange = _range.getWordsMatchRange(hint.match);
9597
              return false;
9598
            }
9599
          });
9600

9601
          if (!wordRange) {
9602
            this.hide();
9603
            return;
9604
          }
9605

9606
          keyword = wordRange.toString();
9607
        } else {
9608
          wordRange = _range.getWordRange();
9609
          keyword = wordRange.toString();
9610
        }
9611

9612
        if (this.hints.length && keyword) {
9613
          this.$content.empty();
9614
          var bnd = func.rect2bnd(lists.last(wordRange.getClientRects()));
9615
          var containerOffset = external_jQuery_default()(this.options.container).offset();
9616

9617
          if (bnd) {
9618
            bnd.top -= containerOffset.top;
9619
            bnd.left -= containerOffset.left;
9620
            this.$popover.hide();
9621
            this.lastWordRange = wordRange;
9622
            this.hints.forEach(function (hint, idx) {
9623
              if (hint.match.test(keyword)) {
9624
                _this4.createGroup(idx, keyword).appendTo(_this4.$content);
9625
              }
9626
            }); // select first .note-hint-item
9627

9628
            this.$content.find('.note-hint-item:first').addClass('active'); // set position for popover after group is created
9629

9630
            if (this.direction === 'top') {
9631
              this.$popover.css({
9632
                left: bnd.left,
9633
                top: bnd.top - this.$popover.outerHeight() - POPOVER_DIST
9634
              });
9635
            } else {
9636
              this.$popover.css({
9637
                left: bnd.left,
9638
                top: bnd.top + bnd.height + POPOVER_DIST
9639
              });
9640
            }
9641
          }
9642
        } else {
9643
          this.hide();
9644
        }
9645
      }
9646
    }
9647
  }, {
9648
    key: "show",
9649
    value: function show() {
9650
      this.$popover.show();
9651
    }
9652
  }, {
9653
    key: "hide",
9654
    value: function hide() {
9655
      this.$popover.hide();
9656
    }
9657
  }]);
9658

9659
  return HintPopover;
9660
}();
9661

9662

9663
;// CONCATENATED MODULE: ./src/js/settings.js
9664

9665

9666

9667

9668

9669

9670

9671

9672

9673

9674

9675

9676

9677

9678

9679

9680

9681

9682

9683

9684

9685

9686

9687

9688

9689

9690

9691

9692
(external_jQuery_default()).summernote = external_jQuery_default().extend((external_jQuery_default()).summernote, {
9693
  version: '0.8.20',
9694
  plugins: {},
9695
  dom: dom,
9696
  range: range,
9697
  lists: lists,
9698
  options: {
9699
    langInfo: (external_jQuery_default()).summernote.lang["en-US"],
9700
    editing: true,
9701
    modules: {
9702
      'editor': Editor,
9703
      'clipboard': Clipboard,
9704
      'dropzone': Dropzone,
9705
      'codeview': CodeView,
9706
      'statusbar': Statusbar,
9707
      'fullscreen': Fullscreen,
9708
      'handle': Handle,
9709
      // FIXME: HintPopover must be front of autolink
9710
      //  - Script error about range when Enter key is pressed on hint popover
9711
      'hintPopover': HintPopover,
9712
      'autoLink': AutoLink,
9713
      'autoSync': AutoSync,
9714
      'autoReplace': AutoReplace,
9715
      'placeholder': Placeholder,
9716
      'buttons': Buttons,
9717
      'toolbar': Toolbar,
9718
      'linkDialog': LinkDialog,
9719
      'linkPopover': LinkPopover,
9720
      'imageDialog': ImageDialog,
9721
      'imagePopover': ImagePopover,
9722
      'tablePopover': TablePopover,
9723
      'videoDialog': VideoDialog,
9724
      'helpDialog': HelpDialog,
9725
      'airPopover': AirPopover
9726
    },
9727
    buttons: {},
9728
    lang: 'en-US',
9729
    followingToolbar: false,
9730
    toolbarPosition: 'top',
9731
    otherStaticBar: '',
9732
    // toolbar
9733
    codeviewKeepButton: false,
9734
    toolbar: [['style', ['style']], ['font', ['bold', 'underline', 'clear']], ['fontname', ['fontname']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture', 'video']], ['view', ['fullscreen', 'codeview', 'help']]],
9735
    // popover
9736
    popatmouse: true,
9737
    popover: {
9738
      image: [['resize', ['resizeFull', 'resizeHalf', 'resizeQuarter', 'resizeNone']], ['float', ['floatLeft', 'floatRight', 'floatNone']], ['remove', ['removeMedia']]],
9739
      link: [['link', ['linkDialogShow', 'unlink']]],
9740
      table: [['add', ['addRowDown', 'addRowUp', 'addColLeft', 'addColRight']], ['delete', ['deleteRow', 'deleteCol', 'deleteTable']]],
9741
      air: [['color', ['color']], ['font', ['bold', 'underline', 'clear']], ['para', ['ul', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture']], ['view', ['fullscreen', 'codeview']]]
9742
    },
9743
    // air mode: inline editor
9744
    airMode: false,
9745
    overrideContextMenu: false,
9746
    // TBD
9747
    width: null,
9748
    height: null,
9749
    linkTargetBlank: true,
9750
    useProtocol: true,
9751
    defaultProtocol: 'http://',
9752
    focus: false,
9753
    tabDisabled: false,
9754
    tabSize: 4,
9755
    styleWithCSS: false,
9756
    shortcuts: true,
9757
    textareaAutoSync: true,
9758
    tooltip: 'auto',
9759
    container: null,
9760
    maxTextLength: 0,
9761
    blockquoteBreakingLevel: 2,
9762
    spellCheck: true,
9763
    disableGrammar: false,
9764
    placeholder: null,
9765
    inheritPlaceholder: false,
9766
    // TODO: need to be documented
9767
    recordEveryKeystroke: false,
9768
    historyLimit: 200,
9769
    // TODO: need to be documented
9770
    showDomainOnlyForAutolink: false,
9771
    // TODO: need to be documented
9772
    hintMode: 'word',
9773
    hintSelect: 'after',
9774
    hintDirection: 'bottom',
9775
    styleTags: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
9776
    fontNames: ['Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', 'Helvetica Neue', 'Helvetica', 'Impact', 'Lucida Grande', 'Tahoma', 'Times New Roman', 'Verdana'],
9777
    fontNamesIgnoreCheck: [],
9778
    addDefaultFonts: true,
9779
    fontSizes: ['8', '9', '10', '11', '12', '14', '18', '24', '36'],
9780
    fontSizeUnits: ['px', 'pt'],
9781
    // pallete colors(n x n)
9782
    colors: [['#000000', '#424242', '#636363', '#9C9C94', '#CEC6CE', '#EFEFEF', '#F7F7F7', '#FFFFFF'], ['#FF0000', '#FF9C00', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#9C00FF', '#FF00FF'], ['#F7C6CE', '#FFE7CE', '#FFEFC6', '#D6EFD6', '#CEDEE7', '#CEE7F7', '#D6D6E7', '#E7D6DE'], ['#E79C9C', '#FFC69C', '#FFE79C', '#B5D6A5', '#A5C6CE', '#9CC6EF', '#B5A5D6', '#D6A5BD'], ['#E76363', '#F7AD6B', '#FFD663', '#94BD7B', '#73A5AD', '#6BADDE', '#8C7BC6', '#C67BA5'], ['#CE0000', '#E79439', '#EFC631', '#6BA54A', '#4A7B8C', '#3984C6', '#634AA5', '#A54A7B'], ['#9C0000', '#B56308', '#BD9400', '#397B21', '#104A5A', '#085294', '#311873', '#731842'], ['#630000', '#7B3900', '#846300', '#295218', '#083139', '#003163', '#21104A', '#4A1031']],
9783
    // http://chir.ag/projects/name-that-color/
9784
    colorsName: [['Black', 'Tundora', 'Dove Gray', 'Star Dust', 'Pale Slate', 'Gallery', 'Alabaster', 'White'], ['Red', 'Orange Peel', 'Yellow', 'Green', 'Cyan', 'Blue', 'Electric Violet', 'Magenta'], ['Azalea', 'Karry', 'Egg White', 'Zanah', 'Botticelli', 'Tropical Blue', 'Mischka', 'Twilight'], ['Tonys Pink', 'Peach Orange', 'Cream Brulee', 'Sprout', 'Casper', 'Perano', 'Cold Purple', 'Careys Pink'], ['Mandy', 'Rajah', 'Dandelion', 'Olivine', 'Gulf Stream', 'Viking', 'Blue Marguerite', 'Puce'], ['Guardsman Red', 'Fire Bush', 'Golden Dream', 'Chelsea Cucumber', 'Smalt Blue', 'Boston Blue', 'Butterfly Bush', 'Cadillac'], ['Sangria', 'Mai Tai', 'Buddha Gold', 'Forest Green', 'Eden', 'Venice Blue', 'Meteorite', 'Claret'], ['Rosewood', 'Cinnamon', 'Olive', 'Parsley', 'Tiber', 'Midnight Blue', 'Valentino', 'Loulou']],
9785
    colorButton: {
9786
      foreColor: '#000000',
9787
      backColor: '#FFFF00'
9788
    },
9789
    lineHeights: ['1.0', '1.2', '1.4', '1.5', '1.6', '1.8', '2.0', '3.0'],
9790
    tableClassName: 'table table-bordered',
9791
    insertTableMaxSize: {
9792
      col: 10,
9793
      row: 10
9794
    },
9795
    // By default, dialogs are attached in container.
9796
    dialogsInBody: false,
9797
    dialogsFade: false,
9798
    maximumImageFileSize: null,
9799
    acceptImageFileTypes: "image/*",
9800
    callbacks: {
9801
      onBeforeCommand: null,
9802
      onBlur: null,
9803
      onBlurCodeview: null,
9804
      onChange: null,
9805
      onChangeCodeview: null,
9806
      onDialogShown: null,
9807
      onEnter: null,
9808
      onFocus: null,
9809
      onImageLinkInsert: null,
9810
      onImageUpload: null,
9811
      onImageUploadError: null,
9812
      onInit: null,
9813
      onKeydown: null,
9814
      onKeyup: null,
9815
      onMousedown: null,
9816
      onMouseup: null,
9817
      onPaste: null,
9818
      onScroll: null
9819
    },
9820
    codemirror: {
9821
      mode: 'text/html',
9822
      htmlMode: true,
9823
      lineNumbers: true
9824
    },
9825
    codeviewFilter: true,
9826
    codeviewFilterRegex: /<\/*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|ilayer|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|t(?:itle|extarea)|xml)[^>]*?>/gi,
9827
    codeviewIframeFilter: true,
9828
    codeviewIframeWhitelistSrc: [],
9829
    codeviewIframeWhitelistSrcBase: ['www.youtube.com', 'www.youtube-nocookie.com', 'www.facebook.com', 'vine.co', 'instagram.com', 'player.vimeo.com', 'www.dailymotion.com', 'player.youku.com', 'jumpingbean.tv', 'v.qq.com'],
9830
    keyMap: {
9831
      pc: {
9832
        'ESC': 'escape',
9833
        'ENTER': 'insertParagraph',
9834
        'CTRL+Z': 'undo',
9835
        'CTRL+Y': 'redo',
9836
        'TAB': 'tab',
9837
        'SHIFT+TAB': 'untab',
9838
        'CTRL+B': 'bold',
9839
        'CTRL+I': 'italic',
9840
        'CTRL+U': 'underline',
9841
        'CTRL+SHIFT+S': 'strikethrough',
9842
        'CTRL+BACKSLASH': 'removeFormat',
9843
        'CTRL+SHIFT+L': 'justifyLeft',
9844
        'CTRL+SHIFT+E': 'justifyCenter',
9845
        'CTRL+SHIFT+R': 'justifyRight',
9846
        'CTRL+SHIFT+J': 'justifyFull',
9847
        'CTRL+SHIFT+NUM7': 'insertUnorderedList',
9848
        'CTRL+SHIFT+NUM8': 'insertOrderedList',
9849
        'CTRL+LEFTBRACKET': 'outdent',
9850
        'CTRL+RIGHTBRACKET': 'indent',
9851
        'CTRL+NUM0': 'formatPara',
9852
        'CTRL+NUM1': 'formatH1',
9853
        'CTRL+NUM2': 'formatH2',
9854
        'CTRL+NUM3': 'formatH3',
9855
        'CTRL+NUM4': 'formatH4',
9856
        'CTRL+NUM5': 'formatH5',
9857
        'CTRL+NUM6': 'formatH6',
9858
        'CTRL+ENTER': 'insertHorizontalRule',
9859
        'CTRL+K': 'linkDialog.show'
9860
      },
9861
      mac: {
9862
        'ESC': 'escape',
9863
        'ENTER': 'insertParagraph',
9864
        'CMD+Z': 'undo',
9865
        'CMD+SHIFT+Z': 'redo',
9866
        'TAB': 'tab',
9867
        'SHIFT+TAB': 'untab',
9868
        'CMD+B': 'bold',
9869
        'CMD+I': 'italic',
9870
        'CMD+U': 'underline',
9871
        'CMD+SHIFT+S': 'strikethrough',
9872
        'CMD+BACKSLASH': 'removeFormat',
9873
        'CMD+SHIFT+L': 'justifyLeft',
9874
        'CMD+SHIFT+E': 'justifyCenter',
9875
        'CMD+SHIFT+R': 'justifyRight',
9876
        'CMD+SHIFT+J': 'justifyFull',
9877
        'CMD+SHIFT+NUM7': 'insertUnorderedList',
9878
        'CMD+SHIFT+NUM8': 'insertOrderedList',
9879
        'CMD+LEFTBRACKET': 'outdent',
9880
        'CMD+RIGHTBRACKET': 'indent',
9881
        'CMD+NUM0': 'formatPara',
9882
        'CMD+NUM1': 'formatH1',
9883
        'CMD+NUM2': 'formatH2',
9884
        'CMD+NUM3': 'formatH3',
9885
        'CMD+NUM4': 'formatH4',
9886
        'CMD+NUM5': 'formatH5',
9887
        'CMD+NUM6': 'formatH6',
9888
        'CMD+ENTER': 'insertHorizontalRule',
9889
        'CMD+K': 'linkDialog.show'
9890
      }
9891
    },
9892
    icons: {
9893
      'align': 'note-icon-align',
9894
      'alignCenter': 'note-icon-align-center',
9895
      'alignJustify': 'note-icon-align-justify',
9896
      'alignLeft': 'note-icon-align-left',
9897
      'alignRight': 'note-icon-align-right',
9898
      'rowBelow': 'note-icon-row-below',
9899
      'colBefore': 'note-icon-col-before',
9900
      'colAfter': 'note-icon-col-after',
9901
      'rowAbove': 'note-icon-row-above',
9902
      'rowRemove': 'note-icon-row-remove',
9903
      'colRemove': 'note-icon-col-remove',
9904
      'indent': 'note-icon-align-indent',
9905
      'outdent': 'note-icon-align-outdent',
9906
      'arrowsAlt': 'note-icon-arrows-alt',
9907
      'bold': 'note-icon-bold',
9908
      'caret': 'note-icon-caret',
9909
      'circle': 'note-icon-circle',
9910
      'close': 'note-icon-close',
9911
      'code': 'note-icon-code',
9912
      'eraser': 'note-icon-eraser',
9913
      'floatLeft': 'note-icon-float-left',
9914
      'floatRight': 'note-icon-float-right',
9915
      'font': 'note-icon-font',
9916
      'frame': 'note-icon-frame',
9917
      'italic': 'note-icon-italic',
9918
      'link': 'note-icon-link',
9919
      'unlink': 'note-icon-chain-broken',
9920
      'magic': 'note-icon-magic',
9921
      'menuCheck': 'note-icon-menu-check',
9922
      'minus': 'note-icon-minus',
9923
      'orderedlist': 'note-icon-orderedlist',
9924
      'pencil': 'note-icon-pencil',
9925
      'picture': 'note-icon-picture',
9926
      'question': 'note-icon-question',
9927
      'redo': 'note-icon-redo',
9928
      'rollback': 'note-icon-rollback',
9929
      'square': 'note-icon-square',
9930
      'strikethrough': 'note-icon-strikethrough',
9931
      'subscript': 'note-icon-subscript',
9932
      'superscript': 'note-icon-superscript',
9933
      'table': 'note-icon-table',
9934
      'textHeight': 'note-icon-text-height',
9935
      'trash': 'note-icon-trash',
9936
      'underline': 'note-icon-underline',
9937
      'undo': 'note-icon-undo',
9938
      'unorderedlist': 'note-icon-unorderedlist',
9939
      'video': 'note-icon-video'
9940
    }
9941
  }
9942
});
9943
;// CONCATENATED MODULE: ./src/js/renderer.js
9944
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
9945

9946
function renderer_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9947

9948
function renderer_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
9949

9950
function renderer_createClass(Constructor, protoProps, staticProps) { if (protoProps) renderer_defineProperties(Constructor.prototype, protoProps); if (staticProps) renderer_defineProperties(Constructor, staticProps); return Constructor; }
9951

9952

9953

9954
var Renderer = /*#__PURE__*/function () {
9955
  function Renderer(markup, children, options, callback) {
9956
    renderer_classCallCheck(this, Renderer);
9957

9958
    this.markup = markup;
9959
    this.children = children;
9960
    this.options = options;
9961
    this.callback = callback;
9962
  }
9963

9964
  renderer_createClass(Renderer, [{
9965
    key: "render",
9966
    value: function render($parent) {
9967
      var $node = external_jQuery_default()(this.markup);
9968

9969
      if (this.options && this.options.contents) {
9970
        $node.html(this.options.contents);
9971
      }
9972

9973
      if (this.options && this.options.className) {
9974
        $node.addClass(this.options.className);
9975
      }
9976

9977
      if (this.options && this.options.data) {
9978
        external_jQuery_default().each(this.options.data, function (k, v) {
9979
          $node.attr('data-' + k, v);
9980
        });
9981
      }
9982

9983
      if (this.options && this.options.click) {
9984
        $node.on('click', this.options.click);
9985
      }
9986

9987
      if (this.children) {
9988
        var $container = $node.find('.note-children-container');
9989
        this.children.forEach(function (child) {
9990
          child.render($container.length ? $container : $node);
9991
        });
9992
      }
9993

9994
      if (this.callback) {
9995
        this.callback($node, this.options);
9996
      }
9997

9998
      if (this.options && this.options.callback) {
9999
        this.options.callback($node);
10000
      }
10001

10002
      if ($parent) {
10003
        $parent.append($node);
10004
      }
10005

10006
      return $node;
10007
    }
10008
  }]);
10009

10010
  return Renderer;
10011
}();
10012

10013
/* harmony default export */ const renderer = ({
10014
  create: function create(markup, callback) {
10015
    return function () {
10016
      var options = _typeof(arguments[1]) === 'object' ? arguments[1] : arguments[0];
10017
      var children = Array.isArray(arguments[0]) ? arguments[0] : [];
10018

10019
      if (options && options.children) {
10020
        children = options.children;
10021
      }
10022

10023
      return new Renderer(markup, children, options, callback);
10024
    };
10025
  }
10026
});
10027
;// CONCATENATED MODULE: ./src/styles/lite/js/TooltipUI.js
10028
function TooltipUI_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10029

10030
function TooltipUI_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
10031

10032
function TooltipUI_createClass(Constructor, protoProps, staticProps) { if (protoProps) TooltipUI_defineProperties(Constructor.prototype, protoProps); if (staticProps) TooltipUI_defineProperties(Constructor, staticProps); return Constructor; }
10033

10034

10035

10036
var TooltipUI = /*#__PURE__*/function () {
10037
  function TooltipUI($node, options) {
10038
    TooltipUI_classCallCheck(this, TooltipUI);
10039

10040
    this.$node = $node;
10041
    this.options = external_jQuery_default().extend({}, {
10042
      title: '',
10043
      target: options.container,
10044
      trigger: 'hover focus',
10045
      placement: 'bottom'
10046
    }, options); // create tooltip node
10047

10048
    this.$tooltip = external_jQuery_default()(['<div class="note-tooltip">', '<div class="note-tooltip-arrow"></div>', '<div class="note-tooltip-content"></div>', '</div>'].join('')); // define event
10049

10050
    if (this.options.trigger !== 'manual') {
10051
      var showCallback = this.show.bind(this);
10052
      var hideCallback = this.hide.bind(this);
10053
      var toggleCallback = this.toggle.bind(this);
10054
      this.options.trigger.split(' ').forEach(function (eventName) {
10055
        if (eventName === 'hover') {
10056
          $node.off('mouseenter mouseleave');
10057
          $node.on('mouseenter', showCallback).on('mouseleave', hideCallback);
10058
        } else if (eventName === 'click') {
10059
          $node.on('click', toggleCallback);
10060
        } else if (eventName === 'focus') {
10061
          $node.on('focus', showCallback).on('blur', hideCallback);
10062
        }
10063
      });
10064
    }
10065
  }
10066

10067
  TooltipUI_createClass(TooltipUI, [{
10068
    key: "show",
10069
    value: function show() {
10070
      var $node = this.$node;
10071
      var offset = $node.offset();
10072
      var targetOffset = external_jQuery_default()(this.options.target).offset();
10073
      offset.top -= targetOffset.top;
10074
      offset.left -= targetOffset.left;
10075
      var $tooltip = this.$tooltip;
10076
      var title = this.options.title || $node.attr('title') || $node.data('title');
10077
      var placement = this.options.placement || $node.data('placement');
10078
      $tooltip.addClass(placement);
10079
      $tooltip.find('.note-tooltip-content').text(title);
10080
      $tooltip.appendTo(this.options.target);
10081
      var nodeWidth = $node.outerWidth();
10082
      var nodeHeight = $node.outerHeight();
10083
      var tooltipWidth = $tooltip.outerWidth();
10084
      var tooltipHeight = $tooltip.outerHeight();
10085

10086
      if (placement === 'bottom') {
10087
        $tooltip.css({
10088
          top: offset.top + nodeHeight,
10089
          left: offset.left + (nodeWidth / 2 - tooltipWidth / 2)
10090
        });
10091
      } else if (placement === 'top') {
10092
        $tooltip.css({
10093
          top: offset.top - tooltipHeight,
10094
          left: offset.left + (nodeWidth / 2 - tooltipWidth / 2)
10095
        });
10096
      } else if (placement === 'left') {
10097
        $tooltip.css({
10098
          top: offset.top + (nodeHeight / 2 - tooltipHeight / 2),
10099
          left: offset.left - tooltipWidth
10100
        });
10101
      } else if (placement === 'right') {
10102
        $tooltip.css({
10103
          top: offset.top + (nodeHeight / 2 - tooltipHeight / 2),
10104
          left: offset.left + nodeWidth
10105
        });
10106
      }
10107

10108
      $tooltip.addClass('in');
10109
    }
10110
  }, {
10111
    key: "hide",
10112
    value: function hide() {
10113
      var _this = this;
10114

10115
      this.$tooltip.removeClass('in');
10116
      setTimeout(function () {
10117
        _this.$tooltip.remove();
10118
      }, 200);
10119
    }
10120
  }, {
10121
    key: "toggle",
10122
    value: function toggle() {
10123
      if (this.$tooltip.hasClass('in')) {
10124
        this.hide();
10125
      } else {
10126
        this.show();
10127
      }
10128
    }
10129
  }]);
10130

10131
  return TooltipUI;
10132
}();
10133

10134
/* harmony default export */ const js_TooltipUI = (TooltipUI);
10135
;// CONCATENATED MODULE: ./src/styles/lite/js/DropdownUI.js
10136
function DropdownUI_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10137

10138
function DropdownUI_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
10139

10140
function DropdownUI_createClass(Constructor, protoProps, staticProps) { if (protoProps) DropdownUI_defineProperties(Constructor.prototype, protoProps); if (staticProps) DropdownUI_defineProperties(Constructor, staticProps); return Constructor; }
10141

10142

10143

10144
var DropdownUI = /*#__PURE__*/function () {
10145
  function DropdownUI($node, options) {
10146
    DropdownUI_classCallCheck(this, DropdownUI);
10147

10148
    this.$button = $node;
10149
    this.options = external_jQuery_default().extend({}, {
10150
      target: options.container
10151
    }, options);
10152
    this.setEvent();
10153
  }
10154

10155
  DropdownUI_createClass(DropdownUI, [{
10156
    key: "setEvent",
10157
    value: function setEvent() {
10158
      var _this = this;
10159

10160
      this.$button.on('click', function (e) {
10161
        _this.toggle();
10162

10163
        e.stopImmediatePropagation();
10164
      });
10165
    }
10166
  }, {
10167
    key: "clear",
10168
    value: function clear() {
10169
      var $parent = external_jQuery_default()('.note-btn-group.open');
10170
      $parent.find('.note-btn.active').removeClass('active');
10171
      $parent.removeClass('open');
10172
    }
10173
  }, {
10174
    key: "show",
10175
    value: function show() {
10176
      this.$button.addClass('active');
10177
      this.$button.parent().addClass('open');
10178
      var $dropdown = this.$button.next();
10179
      var offset = $dropdown.offset();
10180
      var width = $dropdown.outerWidth();
10181
      var windowWidth = external_jQuery_default()(window).width();
10182
      var targetMarginRight = parseFloat(external_jQuery_default()(this.options.target).css('margin-right'));
10183

10184
      if (offset.left + width > windowWidth - targetMarginRight) {
10185
        $dropdown.css('margin-left', windowWidth - targetMarginRight - (offset.left + width));
10186
      } else {
10187
        $dropdown.css('margin-left', '');
10188
      }
10189
    }
10190
  }, {
10191
    key: "hide",
10192
    value: function hide() {
10193
      this.$button.removeClass('active');
10194
      this.$button.parent().removeClass('open');
10195
    }
10196
  }, {
10197
    key: "toggle",
10198
    value: function toggle() {
10199
      var isOpened = this.$button.parent().hasClass('open');
10200
      this.clear();
10201

10202
      if (isOpened) {
10203
        this.hide();
10204
      } else {
10205
        this.show();
10206
      }
10207
    }
10208
  }]);
10209

10210
  return DropdownUI;
10211
}();
10212

10213
external_jQuery_default()(document).on('click', function (e) {
10214
  if (!external_jQuery_default()(e.target).closest('.note-btn-group').length) {
10215
    external_jQuery_default()('.note-btn-group.open').removeClass('open');
10216
    external_jQuery_default()('.note-btn-group .note-btn.active').removeClass('active');
10217
  }
10218
});
10219
external_jQuery_default()(document).on('click.note-dropdown-menu', function (e) {
10220
  external_jQuery_default()(e.target).closest('.note-dropdown-menu').parent().removeClass('open');
10221
  external_jQuery_default()(e.target).closest('.note-dropdown-menu').parent().find('.note-btn.active').removeClass('active');
10222
});
10223
/* harmony default export */ const js_DropdownUI = (DropdownUI);
10224
;// CONCATENATED MODULE: ./src/styles/lite/js/ModalUI.js
10225
function ModalUI_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10226

10227
function ModalUI_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
10228

10229
function ModalUI_createClass(Constructor, protoProps, staticProps) { if (protoProps) ModalUI_defineProperties(Constructor.prototype, protoProps); if (staticProps) ModalUI_defineProperties(Constructor, staticProps); return Constructor; }
10230

10231

10232

10233
var ModalUI = /*#__PURE__*/function () {
10234
  function ModalUI($node
10235
  /*, options */
10236
  ) {
10237
    ModalUI_classCallCheck(this, ModalUI);
10238

10239
    this.$modal = $node;
10240
    this.$backdrop = external_jQuery_default()('<div class="note-modal-backdrop"></div>');
10241
  }
10242

10243
  ModalUI_createClass(ModalUI, [{
10244
    key: "show",
10245
    value: function show() {
10246
      var _this = this;
10247

10248
      this.$backdrop.appendTo(document.body).show();
10249
      this.$modal.addClass('open').show();
10250
      this.$modal.trigger('note.modal.show');
10251
      this.$modal.off('click', '.close').on('click', '.close', this.hide.bind(this));
10252
      this.$modal.on('keydown', function (event) {
10253
        if (event.which === 27) {
10254
          event.preventDefault();
10255

10256
          _this.hide();
10257
        }
10258
      });
10259
    }
10260
  }, {
10261
    key: "hide",
10262
    value: function hide() {
10263
      this.$modal.removeClass('open').hide();
10264
      this.$backdrop.hide();
10265
      this.$modal.trigger('note.modal.hide');
10266
      this.$modal.off('keydown');
10267
    }
10268
  }]);
10269

10270
  return ModalUI;
10271
}();
10272

10273
/* harmony default export */ const js_ModalUI = (ModalUI);
10274
;// CONCATENATED MODULE: ./src/styles/lite/summernote-lite.js
10275

10276

10277

10278

10279

10280

10281

10282
var editor = renderer.create('<div class="note-editor note-frame"></div>');
10283
var toolbar = renderer.create('<div class="note-toolbar" role="toolbar"></div>');
10284
var editingArea = renderer.create('<div class="note-editing-area"></div>');
10285
var codable = renderer.create('<textarea class="note-codable" aria-multiline="true"></textarea>');
10286
var editable = renderer.create('<div class="note-editable" contentEditable="true" role="textbox" aria-multiline="true"></div>');
10287
var statusbar = renderer.create(['<output class="note-status-output" role="status" aria-live="polite"></output>', '<div class="note-statusbar" role="status">', '<div class="note-resizebar" aria-label="resize">', '<div class="note-icon-bar"></div>', '<div class="note-icon-bar"></div>', '<div class="note-icon-bar"></div>', '</div>', '</div>'].join(''));
10288
var airEditor = renderer.create('<div class="note-editor note-airframe"></div>');
10289
var airEditable = renderer.create(['<div class="note-editable" contentEditable="true" role="textbox" aria-multiline="true"></div>', '<output class="note-status-output" role="status" aria-live="polite"></output>'].join(''));
10290
var buttonGroup = renderer.create('<div class="note-btn-group"></div>');
10291
var summernote_lite_button = renderer.create('<button type="button" class="note-btn" tabindex="-1"></button>', function ($node, options) {
10292
  // set button type
10293
  if (options && options.tooltip) {
10294
    $node.attr({
10295
      'aria-label': options.tooltip
10296
    });
10297
    $node.data('_lite_tooltip', new js_TooltipUI($node, {
10298
      title: options.tooltip,
10299
      container: options.container
10300
    })).on('click', function (e) {
10301
      external_jQuery_default()(e.currentTarget).data('_lite_tooltip').hide();
10302
    });
10303
  }
10304

10305
  if (options.contents) {
10306
    $node.html(options.contents);
10307
  }
10308

10309
  if (options && options.data && options.data.toggle === 'dropdown') {
10310
    $node.data('_lite_dropdown', new js_DropdownUI($node, {
10311
      container: options.container
10312
    }));
10313
  }
10314

10315
  if (options && options.codeviewKeepButton) {
10316
    $node.addClass('note-codeview-keep');
10317
  }
10318
});
10319
var dropdown = renderer.create('<div class="note-dropdown-menu" role="list"></div>', function ($node, options) {
10320
  var markup = Array.isArray(options.items) ? options.items.map(function (item) {
10321
    var value = typeof item === 'string' ? item : item.value || '';
10322
    var content = options.template ? options.template(item) : item;
10323
    var $temp = external_jQuery_default()('<a class="note-dropdown-item" href="#" data-value="' + value + '" role="listitem" aria-label="' + value + '"></a>');
10324
    $temp.html(content).data('item', item);
10325
    return $temp;
10326
  }) : options.items;
10327
  $node.html(markup).attr({
10328
    'aria-label': options.title
10329
  });
10330
  $node.on('click', '> .note-dropdown-item', function (e) {
10331
    var $a = external_jQuery_default()(this);
10332
    var item = $a.data('item');
10333
    var value = $a.data('value');
10334

10335
    if (item.click) {
10336
      item.click($a);
10337
    } else if (options.itemClick) {
10338
      options.itemClick(e, item, value);
10339
    }
10340
  });
10341

10342
  if (options && options.codeviewKeepButton) {
10343
    $node.addClass('note-codeview-keep');
10344
  }
10345
});
10346
var dropdownCheck = renderer.create('<div class="note-dropdown-menu note-check" role="list"></div>', function ($node, options) {
10347
  var markup = Array.isArray(options.items) ? options.items.map(function (item) {
10348
    var value = typeof item === 'string' ? item : item.value || '';
10349
    var content = options.template ? options.template(item) : item;
10350
    var $temp = external_jQuery_default()('<a class="note-dropdown-item" href="#" data-value="' + value + '" role="listitem" aria-label="' + item + '"></a>');
10351
    $temp.html([icon(options.checkClassName), ' ', content]).data('item', item);
10352
    return $temp;
10353
  }) : options.items;
10354
  $node.html(markup).attr({
10355
    'aria-label': options.title
10356
  });
10357
  $node.on('click', '> .note-dropdown-item', function (e) {
10358
    var $a = external_jQuery_default()(this);
10359
    var item = $a.data('item');
10360
    var value = $a.data('value');
10361

10362
    if (item.click) {
10363
      item.click($a);
10364
    } else if (options.itemClick) {
10365
      options.itemClick(e, item, value);
10366
    }
10367
  });
10368

10369
  if (options && options.codeviewKeepButton) {
10370
    $node.addClass('note-codeview-keep');
10371
  }
10372
});
10373

10374
var dropdownButtonContents = function dropdownButtonContents(contents, options) {
10375
  return contents + ' ' + icon(options.icons.caret, 'span');
10376
};
10377

10378
var dropdownButton = function dropdownButton(opt, callback) {
10379
  return buttonGroup([summernote_lite_button({
10380
    className: 'dropdown-toggle',
10381
    contents: opt.title + ' ' + icon('note-icon-caret'),
10382
    tooltip: opt.tooltip,
10383
    data: {
10384
      toggle: 'dropdown'
10385
    }
10386
  }), dropdown({
10387
    className: opt.className,
10388
    items: opt.items,
10389
    template: opt.template,
10390
    itemClick: opt.itemClick
10391
  })], {
10392
    callback: callback
10393
  }).render();
10394
};
10395

10396
var dropdownCheckButton = function dropdownCheckButton(opt, callback) {
10397
  return buttonGroup([summernote_lite_button({
10398
    className: 'dropdown-toggle',
10399
    contents: opt.title + ' ' + icon('note-icon-caret'),
10400
    tooltip: opt.tooltip,
10401
    data: {
10402
      toggle: 'dropdown'
10403
    }
10404
  }), dropdownCheck({
10405
    className: opt.className,
10406
    checkClassName: opt.checkClassName,
10407
    items: opt.items,
10408
    template: opt.template,
10409
    itemClick: opt.itemClick
10410
  })], {
10411
    callback: callback
10412
  }).render();
10413
};
10414

10415
var paragraphDropdownButton = function paragraphDropdownButton(opt) {
10416
  return buttonGroup([summernote_lite_button({
10417
    className: 'dropdown-toggle',
10418
    contents: opt.title + ' ' + icon('note-icon-caret'),
10419
    tooltip: opt.tooltip,
10420
    data: {
10421
      toggle: 'dropdown'
10422
    }
10423
  }), dropdown([buttonGroup({
10424
    className: 'note-align',
10425
    children: opt.items[0]
10426
  }), buttonGroup({
10427
    className: 'note-list',
10428
    children: opt.items[1]
10429
  })])]).render();
10430
};
10431

10432
var tableMoveHandler = function tableMoveHandler(event, col, row) {
10433
  var PX_PER_EM = 18;
10434
  var $picker = external_jQuery_default()(event.target.parentNode); // target is mousecatcher
10435

10436
  var $dimensionDisplay = $picker.next();
10437
  var $catcher = $picker.find('.note-dimension-picker-mousecatcher');
10438
  var $highlighted = $picker.find('.note-dimension-picker-highlighted');
10439
  var $unhighlighted = $picker.find('.note-dimension-picker-unhighlighted');
10440
  var posOffset; // HTML5 with jQuery - e.offsetX is undefined in Firefox
10441

10442
  if (event.offsetX === undefined) {
10443
    var posCatcher = external_jQuery_default()(event.target).offset();
10444
    posOffset = {
10445
      x: event.pageX - posCatcher.left,
10446
      y: event.pageY - posCatcher.top
10447
    };
10448
  } else {
10449
    posOffset = {
10450
      x: event.offsetX,
10451
      y: event.offsetY
10452
    };
10453
  }
10454

10455
  var dim = {
10456
    c: Math.ceil(posOffset.x / PX_PER_EM) || 1,
10457
    r: Math.ceil(posOffset.y / PX_PER_EM) || 1
10458
  };
10459
  $highlighted.css({
10460
    width: dim.c + 'em',
10461
    height: dim.r + 'em'
10462
  });
10463
  $catcher.data('value', dim.c + 'x' + dim.r);
10464

10465
  if (dim.c > 3 && dim.c < col) {
10466
    $unhighlighted.css({
10467
      width: dim.c + 1 + 'em'
10468
    });
10469
  }
10470

10471
  if (dim.r > 3 && dim.r < row) {
10472
    $unhighlighted.css({
10473
      height: dim.r + 1 + 'em'
10474
    });
10475
  }
10476

10477
  $dimensionDisplay.html(dim.c + ' x ' + dim.r);
10478
};
10479

10480
var tableDropdownButton = function tableDropdownButton(opt) {
10481
  return buttonGroup([summernote_lite_button({
10482
    className: 'dropdown-toggle',
10483
    contents: opt.title + ' ' + icon('note-icon-caret'),
10484
    tooltip: opt.tooltip,
10485
    data: {
10486
      toggle: 'dropdown'
10487
    }
10488
  }), dropdown({
10489
    className: 'note-table',
10490
    items: ['<div class="note-dimension-picker">', '<div class="note-dimension-picker-mousecatcher" data-event="insertTable" data-value="1x1"></div>', '<div class="note-dimension-picker-highlighted"></div>', '<div class="note-dimension-picker-unhighlighted"></div>', '</div>', '<div class="note-dimension-display">1 x 1</div>'].join('')
10491
  })], {
10492
    callback: function callback($node) {
10493
      var $catcher = $node.find('.note-dimension-picker-mousecatcher');
10494
      $catcher.css({
10495
        width: opt.col + 'em',
10496
        height: opt.row + 'em'
10497
      }).mouseup(opt.itemClick).mousemove(function (e) {
10498
        tableMoveHandler(e, opt.col, opt.row);
10499
      });
10500
    }
10501
  }).render();
10502
};
10503

10504
var palette = renderer.create('<div class="note-color-palette"></div>', function ($node, options) {
10505
  var contents = [];
10506

10507
  for (var row = 0, rowSize = options.colors.length; row < rowSize; row++) {
10508
    var eventName = options.eventName;
10509
    var colors = options.colors[row];
10510
    var colorsName = options.colorsName[row];
10511
    var buttons = [];
10512

10513
    for (var col = 0, colSize = colors.length; col < colSize; col++) {
10514
      var color = colors[col];
10515
      var colorName = colorsName[col];
10516
      buttons.push(['<button type="button" class="note-btn note-color-btn"', 'style="background-color:', color, '" ', 'data-event="', eventName, '" ', 'data-value="', color, '" ', 'data-title="', colorName, '" ', 'aria-label="', colorName, '" ', 'data-toggle="button" tabindex="-1"></button>'].join(''));
10517
    }
10518

10519
    contents.push('<div class="note-color-row">' + buttons.join('') + '</div>');
10520
  }
10521

10522
  $node.html(contents.join(''));
10523
  $node.find('.note-color-btn').each(function () {
10524
    external_jQuery_default()(this).data('_lite_tooltip', new js_TooltipUI(external_jQuery_default()(this), {
10525
      container: options.container
10526
    }));
10527
  });
10528
});
10529

10530
var colorDropdownButton = function colorDropdownButton(opt, type) {
10531
  return buttonGroup({
10532
    className: 'note-color',
10533
    children: [summernote_lite_button({
10534
      className: 'note-current-color-button',
10535
      contents: opt.title,
10536
      tooltip: opt.lang.color.recent,
10537
      click: opt.currentClick,
10538
      callback: function callback($button) {
10539
        var $recentColor = $button.find('.note-recent-color');
10540

10541
        if (type !== 'foreColor') {
10542
          $recentColor.css('background-color', '#FFFF00');
10543
          $button.attr('data-backColor', '#FFFF00');
10544
        }
10545
      }
10546
    }), summernote_lite_button({
10547
      className: 'dropdown-toggle',
10548
      contents: icon('note-icon-caret'),
10549
      tooltip: opt.lang.color.more,
10550
      data: {
10551
        toggle: 'dropdown'
10552
      }
10553
    }), dropdown({
10554
      items: ['<div>', '<div class="note-btn-group btn-background-color">', '<div class="note-palette-title">' + opt.lang.color.background + '</div>', '<div>', '<button type="button" class="note-color-reset note-btn note-btn-block" data-event="backColor" data-value="transparent">', opt.lang.color.transparent, '</button>', '</div>', '<div class="note-holder" data-event="backColor"></div>', '<div class="btn-sm">', '<input type="color" id="html5bcp" class="note-btn btn-default" value="#21104A" style="width:100%;" data-value="cp">', '<button type="button" class="note-color-reset btn" data-event="backColor" data-value="cpbackColor">', opt.lang.color.cpSelect, '</button>', '</div>', '</div>', '<div class="note-btn-group btn-foreground-color">', '<div class="note-palette-title">' + opt.lang.color.foreground + '</div>', '<div>', '<button type="button" class="note-color-reset note-btn note-btn-block" data-event="removeFormat" data-value="foreColor">', opt.lang.color.resetToDefault, '</button>', '</div>', '<div class="note-holder" data-event="foreColor"></div>', '<div class="btn-sm">', '<input type="color" id="html5fcp" class="note-btn btn-default" value="#21104A" style="width:100%;" data-value="cp">', '<button type="button" class="note-color-reset btn" data-event="foreColor" data-value="cpforeColor">', opt.lang.color.cpSelect, '</button>', '</div>', '</div>', '</div>'].join(''),
10555
      callback: function callback($dropdown) {
10556
        $dropdown.find('.note-holder').each(function () {
10557
          var $holder = external_jQuery_default()(this);
10558
          $holder.append(palette({
10559
            colors: opt.colors,
10560
            eventName: $holder.data('event')
10561
          }).render());
10562
        });
10563

10564
        if (type === 'fore') {
10565
          $dropdown.find('.btn-background-color').hide();
10566
          $dropdown.css({
10567
            'min-width': '210px'
10568
          });
10569
        } else if (type === 'back') {
10570
          $dropdown.find('.btn-foreground-color').hide();
10571
          $dropdown.css({
10572
            'min-width': '210px'
10573
          });
10574
        }
10575
      },
10576
      click: function click(event) {
10577
        var $button = external_jQuery_default()(event.target);
10578
        var eventName = $button.data('event');
10579
        var value = $button.data('value');
10580
        var foreinput = document.getElementById('html5fcp').value;
10581
        var backinput = document.getElementById('html5bcp').value;
10582

10583
        if (value === 'cp') {
10584
          event.stopPropagation();
10585
        } else if (value === 'cpbackColor') {
10586
          value = backinput;
10587
        } else if (value === 'cpforeColor') {
10588
          value = foreinput;
10589
        }
10590

10591
        if (eventName && value) {
10592
          var key = eventName === 'backColor' ? 'background-color' : 'color';
10593
          var $color = $button.closest('.note-color').find('.note-recent-color');
10594
          var $currentButton = $button.closest('.note-color').find('.note-current-color-button');
10595
          $color.css(key, value);
10596
          $currentButton.attr('data-' + eventName, value);
10597

10598
          if (type === 'fore') {
10599
            opt.itemClick('foreColor', value);
10600
          } else if (type === 'back') {
10601
            opt.itemClick('backColor', value);
10602
          } else {
10603
            opt.itemClick(eventName, value);
10604
          }
10605
        }
10606
      }
10607
    })]
10608
  }).render();
10609
};
10610

10611
var dialog = renderer.create('<div class="note-modal" aria-hidden="false" tabindex="-1" role="dialog"></div>', function ($node, options) {
10612
  if (options.fade) {
10613
    $node.addClass('fade');
10614
  }
10615

10616
  $node.attr({
10617
    'aria-label': options.title
10618
  });
10619
  $node.html(['<div class="note-modal-content">', options.title ? '<div class="note-modal-header"><button type="button" class="close" aria-label="Close" aria-hidden="true"><i class="note-icon-close"></i></button><h4 class="note-modal-title">' + options.title + '</h4></div>' : '', '<div class="note-modal-body">' + options.body + '</div>', options.footer ? '<div class="note-modal-footer">' + options.footer + '</div>' : '', '</div>'].join(''));
10620
  $node.data('modal', new js_ModalUI($node, options));
10621
});
10622

10623
var videoDialog = function videoDialog(opt) {
10624
  var body = '<div class="note-form-group">' + '<label for="note-dialog-video-url-' + opt.id + '" class="note-form-label">' + opt.lang.video.url + ' <small class="text-muted">' + opt.lang.video.providers + '</small></label>' + '<input id="note-dialog-video-url-' + opt.id + '" class="note-video-url note-input" type="text"/>' + '</div>';
10625
  var footer = ['<button type="button" href="#" class="note-btn note-btn-primary note-video-btn disabled" disabled>', opt.lang.video.insert, '</button>'].join('');
10626
  return dialog({
10627
    title: opt.lang.video.insert,
10628
    fade: opt.fade,
10629
    body: body,
10630
    footer: footer
10631
  }).render();
10632
};
10633

10634
var imageDialog = function imageDialog(opt) {
10635
  var body = '<div class="note-form-group note-group-select-from-files">' + '<label for="note-dialog-image-file-' + opt.id + '" class="note-form-label">' + opt.lang.image.selectFromFiles + '</label>' + '<input id="note-dialog-image-file-' + opt.id + '" class="note-note-image-input note-input" type="file" name="files" accept="image/*" multiple="multiple"/>' + opt.imageLimitation + '</div>' + '<div class="note-form-group">' + '<label for="note-dialog-image-url-' + opt.id + '" class="note-form-label">' + opt.lang.image.url + '</label>' + '<input id="note-dialog-image-url-' + opt.id + '" class="note-image-url note-input" type="text"/>' + '</div>';
10636
  var footer = ['<button href="#" type="button" class="note-btn note-btn-primary note-btn-large note-image-btn disabled" disabled>', opt.lang.image.insert, '</button>'].join('');
10637
  return dialog({
10638
    title: opt.lang.image.insert,
10639
    fade: opt.fade,
10640
    body: body,
10641
    footer: footer
10642
  }).render();
10643
};
10644

10645
var linkDialog = function linkDialog(opt) {
10646
  var body = '<div class="note-form-group">' + '<label for="note-dialog-link-txt-' + opt.id + '" class="note-form-label">' + opt.lang.link.textToDisplay + '</label>' + '<input id="note-dialog-link-txt-' + opt.id + '" class="note-link-text note-input" type="text"/>' + '</div>' + '<div class="note-form-group">' + '<label for="note-dialog-link-url-' + opt.id + '" class="note-form-label">' + opt.lang.link.url + '</label>' + '<input id="note-dialog-link-url-' + opt.id + '" class="note-link-url note-input" type="text" value="http://"/>' + '</div>' + (!opt.disableLinkTarget ? '<div class="checkbox"><label for="note-dialog-link-nw-' + opt.id + '"><input id="note-dialog-link-nw-' + opt.id + '" type="checkbox" checked> ' + opt.lang.link.openInNewWindow + '</label></div>' : '') + '<div class="checkbox"><label for="note-dialog-link-up-' + opt.id + '"><input id="note-dialog-link-up-' + opt.id + '" type="checkbox" checked> ' + opt.lang.link.useProtocol + '</label></div>';
10647
  var footer = ['<button href="#" type="button" class="note-btn note-btn-primary note-link-btn disabled" disabled>', opt.lang.link.insert, '</button>'].join('');
10648
  return dialog({
10649
    className: 'link-dialog',
10650
    title: opt.lang.link.insert,
10651
    fade: opt.fade,
10652
    body: body,
10653
    footer: footer
10654
  }).render();
10655
};
10656

10657
var popover = renderer.create(['<div class="note-popover bottom">', '<div class="note-popover-arrow"></div>', '<div class="popover-content note-children-container"></div>', '</div>'].join(''), function ($node, options) {
10658
  var direction = typeof options.direction !== 'undefined' ? options.direction : 'bottom';
10659
  $node.addClass(direction).hide();
10660

10661
  if (options.hideArrow) {
10662
    $node.find('.note-popover-arrow').hide();
10663
  }
10664
});
10665
var summernote_lite_checkbox = renderer.create('<div class="checkbox"></div>', function ($node, options) {
10666
  $node.html(['<label' + (options.id ? ' for="note-' + options.id + '"' : '') + '>', '<input role="checkbox" type="checkbox"' + (options.id ? ' id="note-' + options.id + '"' : ''), options.checked ? ' checked' : '', ' aria-checked="' + (options.checked ? 'true' : 'false') + '"/>', options.text ? options.text : '', '</label>'].join(''));
10667
});
10668

10669
var icon = function icon(iconClassName, tagName) {
10670
  if (iconClassName.match(/^</)) {
10671
    return iconClassName;
10672
  }
10673

10674
  tagName = tagName || 'i';
10675
  return '<' + tagName + ' class="' + iconClassName + '"></' + tagName + '>';
10676
};
10677

10678
var ui = function ui(editorOptions) {
10679
  return {
10680
    editor: editor,
10681
    toolbar: toolbar,
10682
    editingArea: editingArea,
10683
    codable: codable,
10684
    editable: editable,
10685
    statusbar: statusbar,
10686
    airEditor: airEditor,
10687
    airEditable: airEditable,
10688
    buttonGroup: buttonGroup,
10689
    button: summernote_lite_button,
10690
    dropdown: dropdown,
10691
    dropdownCheck: dropdownCheck,
10692
    dropdownButton: dropdownButton,
10693
    dropdownButtonContents: dropdownButtonContents,
10694
    dropdownCheckButton: dropdownCheckButton,
10695
    paragraphDropdownButton: paragraphDropdownButton,
10696
    tableDropdownButton: tableDropdownButton,
10697
    colorDropdownButton: colorDropdownButton,
10698
    palette: palette,
10699
    dialog: dialog,
10700
    videoDialog: videoDialog,
10701
    imageDialog: imageDialog,
10702
    linkDialog: linkDialog,
10703
    popover: popover,
10704
    checkbox: summernote_lite_checkbox,
10705
    icon: icon,
10706
    options: editorOptions,
10707
    toggleBtn: function toggleBtn($btn, isEnable) {
10708
      $btn.toggleClass('disabled', !isEnable);
10709
      $btn.attr('disabled', !isEnable);
10710
    },
10711
    toggleBtnActive: function toggleBtnActive($btn, isActive) {
10712
      $btn.toggleClass('active', isActive);
10713
    },
10714
    check: function check($dom, value) {
10715
      $dom.find('.checked').removeClass('checked');
10716
      $dom.find('[data-value="' + value + '"]').addClass('checked');
10717
    },
10718
    onDialogShown: function onDialogShown($dialog, handler) {
10719
      $dialog.one('note.modal.show', handler);
10720
    },
10721
    onDialogHidden: function onDialogHidden($dialog, handler) {
10722
      $dialog.one('note.modal.hide', handler);
10723
    },
10724
    showDialog: function showDialog($dialog) {
10725
      $dialog.data('modal').show();
10726
    },
10727
    hideDialog: function hideDialog($dialog) {
10728
      $dialog.data('modal').hide();
10729
    },
10730

10731
    /**
10732
     * get popover content area
10733
     *
10734
     * @param $popover
10735
     * @returns {*}
10736
     */
10737
    getPopoverContent: function getPopoverContent($popover) {
10738
      return $popover.find('.note-popover-content');
10739
    },
10740

10741
    /**
10742
     * get dialog's body area
10743
     *
10744
     * @param $dialog
10745
     * @returns {*}
10746
     */
10747
    getDialogBody: function getDialogBody($dialog) {
10748
      return $dialog.find('.note-modal-body');
10749
    },
10750
    createLayout: function createLayout($note) {
10751
      var $editor = (editorOptions.airMode ? airEditor([editingArea([codable(), airEditable()])]) : editorOptions.toolbarPosition === 'bottom' ? editor([editingArea([codable(), editable()]), toolbar(), statusbar()]) : editor([toolbar(), editingArea([codable(), editable()]), statusbar()])).render();
10752
      $editor.insertAfter($note);
10753
      return {
10754
        note: $note,
10755
        editor: $editor,
10756
        toolbar: $editor.find('.note-toolbar'),
10757
        editingArea: $editor.find('.note-editing-area'),
10758
        editable: $editor.find('.note-editable'),
10759
        codable: $editor.find('.note-codable'),
10760
        statusbar: $editor.find('.note-statusbar')
10761
      };
10762
    },
10763
    removeLayout: function removeLayout($note, layoutInfo) {
10764
      $note.html(layoutInfo.editable.html());
10765
      layoutInfo.editor.remove();
10766
      $note.off('summernote'); // remove summernote custom event
10767

10768
      $note.show();
10769
    }
10770
  };
10771
};
10772

10773
(external_jQuery_default()).summernote = external_jQuery_default().extend((external_jQuery_default()).summernote, {
10774
  ui_template: ui,
10775
  "interface": 'lite'
10776
});
10777
})();
10778

10779
/******/ 	return __webpack_exports__;
10780
/******/ })()
10781
;
10782
});
10783
//# sourceMappingURL=summernote-lite.js.map

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.