activeadmin_quill_editor 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62b302336cebcf361ba3a1ccb584cfd7b4d6236c
4
- data.tar.gz: 42811147a4164fa34ece06570d72f221ec20c7c7
3
+ metadata.gz: a8779e983b004bbbba08b5eaebeb8f24ecf6be88
4
+ data.tar.gz: 143fcced1a344c6c10e5b45b7d57c5e5d6c5ff5e
5
5
  SHA512:
6
- metadata.gz: c2b171a855d2c339a79752eaba70059df2902187d3c186272050bd5c11e0895bfdb0701ba5574835d53f8d1729aae61c5a2892eefd4643f856c4c8c21f27ac86
7
- data.tar.gz: 2ded2a7e70cf00b817f9007279fed50408096282eb01c91523798cd85568b7391664990be8c8c6cb257ef6fb5b5033aa0da2816205bbd4963c0c0f1e1076f2e2
6
+ metadata.gz: 5ff21b3249db6c130af802028609b6fb6b4c6a95ac9ce28d1b711dc26cd9aa9531fb83981bc979d49ba9b89bfa98dbf328f6254db82e8f62bac6e070a9446dfc
7
+ data.tar.gz: c3511d083ac1212977d591c28ee073935e6a11988af17e5b13251557d9a42b049572d55e901caede299e22c123ab024952f062d53135f93b51369570f787cf43
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Quill Editor v1.3.3
2
+ * Quill Editor v1.3.6
3
3
  * https://quilljs.com/
4
4
  * Copyright (c) 2014, Jason Chen
5
5
  * Copyright (c) 2013, salesforce.com
@@ -13,7 +13,7 @@
13
13
  exports["Quill"] = factory();
14
14
  else
15
15
  root["Quill"] = factory();
16
- })(this, function() {
16
+ })(typeof self !== 'undefined' ? self : this, function() {
17
17
  return /******/ (function(modules) { // webpackBootstrap
18
18
  /******/ // The module cache
19
19
  /******/ var installedModules = {};
@@ -117,8 +117,8 @@ var Parchment = {
117
117
  Attribute: attributor_1.default,
118
118
  Class: class_1.default,
119
119
  Style: style_1.default,
120
- Store: store_1.default
121
- }
120
+ Store: store_1.default,
121
+ },
122
122
  };
123
123
  exports.default = Parchment;
124
124
 
@@ -172,16 +172,15 @@ var Scope;
172
172
  Scope[Scope["INLINE_ATTRIBUTE"] = 5] = "INLINE_ATTRIBUTE";
173
173
  Scope[Scope["ANY"] = 15] = "ANY";
174
174
  })(Scope = exports.Scope || (exports.Scope = {}));
175
- ;
176
175
  function create(input, value) {
177
176
  var match = query(input);
178
177
  if (match == null) {
179
178
  throw new ParchmentError("Unable to create " + input + " blot");
180
179
  }
181
180
  var BlotClass = match;
182
- var node = (input instanceof Node || input['nodeType'] === Node.TEXT_NODE) ?
183
- input :
184
- BlotClass.create(value);
181
+ var node =
182
+ // @ts-ignore
183
+ input instanceof Node || input['nodeType'] === Node.TEXT_NODE ? input : BlotClass.create(value);
185
184
  return new BlotClass(node, value);
186
185
  }
187
186
  exports.create = create;
@@ -189,6 +188,7 @@ function find(node, bubble) {
189
188
  if (bubble === void 0) { bubble = false; }
190
189
  if (node == null)
191
190
  return null;
191
+ // @ts-ignore
192
192
  if (node[exports.DATA_KEY] != null)
193
193
  return node[exports.DATA_KEY].blot;
194
194
  if (bubble)
@@ -201,6 +201,7 @@ function query(query, scope) {
201
201
  var match;
202
202
  if (typeof query === 'string') {
203
203
  match = types[query] || attributes[query];
204
+ // @ts-ignore
204
205
  }
205
206
  else if (query instanceof Text || query['nodeType'] === Node.TEXT_NODE) {
206
207
  match = types['text'];
@@ -224,7 +225,8 @@ function query(query, scope) {
224
225
  }
225
226
  if (match == null)
226
227
  return null;
227
- if ((scope & Scope.LEVEL & match.scope) && (scope & Scope.TYPE & match.scope))
228
+ // @ts-ignore
229
+ if (scope & Scope.LEVEL & match.scope && scope & Scope.TYPE & match.scope)
228
230
  return match;
229
231
  return null;
230
232
  }
@@ -1531,7 +1533,7 @@ Quill.DEFAULTS = {
1531
1533
  Quill.events = _emitter4.default.events;
1532
1534
  Quill.sources = _emitter4.default.sources;
1533
1535
  // eslint-disable-next-line no-undef
1534
- Quill.version = false ? 'dev' : "1.3.3";
1536
+ Quill.version = false ? 'dev' : "1.3.6";
1535
1537
 
1536
1538
  Quill.imports = {
1537
1539
  'delta': _quillDelta2.default,
@@ -1852,7 +1854,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
1852
1854
 
1853
1855
  var debug = (0, _logger2.default)('quill:events');
1854
1856
 
1855
- var EVENTS = ['selectionchange', 'mousedown', 'mouseup'];
1857
+ var EVENTS = ['selectionchange', 'mousedown', 'mouseup', 'click'];
1856
1858
 
1857
1859
  EVENTS.forEach(function (eventName) {
1858
1860
  document.addEventListener(eventName, function () {
@@ -2136,17 +2138,26 @@ var Attributor = /** @class */ (function () {
2136
2138
  };
2137
2139
  Attributor.prototype.canAdd = function (node, value) {
2138
2140
  var match = Registry.query(node, Registry.Scope.BLOT & (this.scope | Registry.Scope.TYPE));
2139
- if (match != null && (this.whitelist == null || this.whitelist.indexOf(value) > -1)) {
2141
+ if (match == null)
2142
+ return false;
2143
+ if (this.whitelist == null)
2140
2144
  return true;
2145
+ if (typeof value === 'string') {
2146
+ return this.whitelist.indexOf(value.replace(/["']/g, '')) > -1;
2147
+ }
2148
+ else {
2149
+ return this.whitelist.indexOf(value) > -1;
2141
2150
  }
2142
- return false;
2143
2151
  };
2144
2152
  Attributor.prototype.remove = function (node) {
2145
2153
  node.removeAttribute(this.keyName);
2146
2154
  };
2147
2155
  Attributor.prototype.value = function (node) {
2148
2156
  var value = node.getAttribute(this.keyName);
2149
- return this.canAdd(node, value) ? value : '';
2157
+ if (this.canAdd(node, value) && value) {
2158
+ return value;
2159
+ }
2160
+ return '';
2150
2161
  };
2151
2162
  return Attributor;
2152
2163
  }());
@@ -2388,7 +2399,7 @@ var _code = __webpack_require__(13);
2388
2399
 
2389
2400
  var _code2 = _interopRequireDefault(_code);
2390
2401
 
2391
- var _cursor = __webpack_require__(23);
2402
+ var _cursor = __webpack_require__(24);
2392
2403
 
2393
2404
  var _cursor2 = _interopRequireDefault(_cursor);
2394
2405
 
@@ -3304,21 +3315,31 @@ var shadow_1 = __webpack_require__(30);
3304
3315
  var Registry = __webpack_require__(1);
3305
3316
  var ContainerBlot = /** @class */ (function (_super) {
3306
3317
  __extends(ContainerBlot, _super);
3307
- function ContainerBlot() {
3308
- return _super !== null && _super.apply(this, arguments) || this;
3318
+ function ContainerBlot(domNode) {
3319
+ var _this = _super.call(this, domNode) || this;
3320
+ _this.build();
3321
+ return _this;
3309
3322
  }
3310
3323
  ContainerBlot.prototype.appendChild = function (other) {
3311
3324
  this.insertBefore(other);
3312
3325
  };
3313
3326
  ContainerBlot.prototype.attach = function () {
3314
- var _this = this;
3315
3327
  _super.prototype.attach.call(this);
3328
+ this.children.forEach(function (child) {
3329
+ child.attach();
3330
+ });
3331
+ };
3332
+ ContainerBlot.prototype.build = function () {
3333
+ var _this = this;
3316
3334
  this.children = new linked_list_1.default();
3317
3335
  // Need to be reversed for if DOM nodes already in order
3318
- [].slice.call(this.domNode.childNodes).reverse().forEach(function (node) {
3336
+ [].slice
3337
+ .call(this.domNode.childNodes)
3338
+ .reverse()
3339
+ .forEach(function (node) {
3319
3340
  try {
3320
3341
  var child = makeBlot(node);
3321
- _this.insertBefore(child, _this.children.head);
3342
+ _this.insertBefore(child, _this.children.head || undefined);
3322
3343
  }
3323
3344
  catch (err) {
3324
3345
  if (err instanceof Registry.ParchmentError)
@@ -3352,7 +3373,8 @@ var ContainerBlot = /** @class */ (function (_super) {
3352
3373
  ContainerBlot.prototype.descendants = function (criteria, index, length) {
3353
3374
  if (index === void 0) { index = 0; }
3354
3375
  if (length === void 0) { length = Number.MAX_VALUE; }
3355
- var descendants = [], lengthLeft = length;
3376
+ var descendants = [];
3377
+ var lengthLeft = length;
3356
3378
  this.children.forEachAt(index, length, function (child, index, length) {
3357
3379
  if ((criteria.blotName == null && criteria(child)) ||
3358
3380
  (criteria.blotName != null && child instanceof criteria)) {
@@ -3382,14 +3404,15 @@ var ContainerBlot = /** @class */ (function (_super) {
3382
3404
  child.insertAt(offset, value, def);
3383
3405
  }
3384
3406
  else {
3385
- var blot = (def == null) ? Registry.create('text', value) : Registry.create(value, def);
3407
+ var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
3386
3408
  this.appendChild(blot);
3387
3409
  }
3388
3410
  };
3389
3411
  ContainerBlot.prototype.insertBefore = function (childBlot, refBlot) {
3390
- if (this.statics.allowedChildren != null && !this.statics.allowedChildren.some(function (child) {
3391
- return childBlot instanceof child;
3392
- })) {
3412
+ if (this.statics.allowedChildren != null &&
3413
+ !this.statics.allowedChildren.some(function (child) {
3414
+ return childBlot instanceof child;
3415
+ })) {
3393
3416
  throw new Registry.ParchmentError("Cannot insert " + childBlot.statics.blotName + " into " + this.statics.blotName);
3394
3417
  }
3395
3418
  childBlot.insertInto(this, refBlot);
@@ -3460,7 +3483,8 @@ var ContainerBlot = /** @class */ (function (_super) {
3460
3483
  };
3461
3484
  ContainerBlot.prototype.update = function (mutations, context) {
3462
3485
  var _this = this;
3463
- var addedNodes = [], removedNodes = [];
3486
+ var addedNodes = [];
3487
+ var removedNodes = [];
3464
3488
  mutations.forEach(function (mutation) {
3465
3489
  if (mutation.target === _this.domNode && mutation.type === 'childList') {
3466
3490
  addedNodes.push.apply(addedNodes, mutation.addedNodes);
@@ -3471,8 +3495,10 @@ var ContainerBlot = /** @class */ (function (_super) {
3471
3495
  // Check node has actually been removed
3472
3496
  // One exception is Chrome does not immediately remove IFRAMEs
3473
3497
  // from DOM but MutationRecord is correct in its reported removal
3474
- if (node.parentNode != null && node.tagName !== 'IFRAME' &&
3475
- (document.body.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY)) {
3498
+ if (node.parentNode != null &&
3499
+ // @ts-ignore
3500
+ node.tagName !== 'IFRAME' &&
3501
+ document.body.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) {
3476
3502
  return;
3477
3503
  }
3478
3504
  var blot = Registry.find(node);
@@ -3482,16 +3508,19 @@ var ContainerBlot = /** @class */ (function (_super) {
3482
3508
  blot.detach();
3483
3509
  }
3484
3510
  });
3485
- addedNodes.filter(function (node) {
3511
+ addedNodes
3512
+ .filter(function (node) {
3486
3513
  return node.parentNode == _this.domNode;
3487
- }).sort(function (a, b) {
3514
+ })
3515
+ .sort(function (a, b) {
3488
3516
  if (a === b)
3489
3517
  return 0;
3490
3518
  if (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) {
3491
3519
  return 1;
3492
3520
  }
3493
3521
  return -1;
3494
- }).forEach(function (node) {
3522
+ })
3523
+ .forEach(function (node) {
3495
3524
  var refBlot = null;
3496
3525
  if (node.nextSibling != null) {
3497
3526
  refBlot = Registry.find(node.nextSibling);
@@ -3501,7 +3530,7 @@ var ContainerBlot = /** @class */ (function (_super) {
3501
3530
  if (blot.parent != null) {
3502
3531
  blot.parent.removeChild(_this);
3503
3532
  }
3504
- _this.insertBefore(blot, refBlot);
3533
+ _this.insertBefore(blot, refBlot || undefined);
3505
3534
  }
3506
3535
  });
3507
3536
  };
@@ -3516,9 +3545,12 @@ function makeBlot(node) {
3516
3545
  catch (e) {
3517
3546
  blot = Registry.create(Registry.Scope.INLINE);
3518
3547
  [].slice.call(node.childNodes).forEach(function (child) {
3548
+ // @ts-ignore
3519
3549
  blot.domNode.appendChild(child);
3520
3550
  });
3521
- node.parentNode.replaceChild(blot.domNode, node);
3551
+ if (node.parentNode) {
3552
+ node.parentNode.replaceChild(blot.domNode, node);
3553
+ }
3522
3554
  blot.attach();
3523
3555
  }
3524
3556
  }
@@ -3550,8 +3582,10 @@ var container_1 = __webpack_require__(17);
3550
3582
  var Registry = __webpack_require__(1);
3551
3583
  var FormatBlot = /** @class */ (function (_super) {
3552
3584
  __extends(FormatBlot, _super);
3553
- function FormatBlot() {
3554
- return _super !== null && _super.apply(this, arguments) || this;
3585
+ function FormatBlot(domNode) {
3586
+ var _this = _super.call(this, domNode) || this;
3587
+ _this.attributes = new store_1.default(_this.domNode);
3588
+ return _this;
3555
3589
  }
3556
3590
  FormatBlot.formats = function (domNode) {
3557
3591
  if (typeof this.tagName === 'string') {
@@ -3562,10 +3596,6 @@ var FormatBlot = /** @class */ (function (_super) {
3562
3596
  }
3563
3597
  return undefined;
3564
3598
  };
3565
- FormatBlot.prototype.attach = function () {
3566
- _super.prototype.attach.call(this);
3567
- this.attributes = new store_1.default(this.domNode);
3568
- };
3569
3599
  FormatBlot.prototype.format = function (name, value) {
3570
3600
  var format = Registry.query(name);
3571
3601
  if (format instanceof attributor_1.default) {
@@ -4100,7 +4130,7 @@ var _code = __webpack_require__(13);
4100
4130
 
4101
4131
  var _code2 = _interopRequireDefault(_code);
4102
4132
 
4103
- var _container = __webpack_require__(24);
4133
+ var _container = __webpack_require__(25);
4104
4134
 
4105
4135
  var _container2 = _interopRequireDefault(_container);
4106
4136
 
@@ -4326,224 +4356,604 @@ exports.default = Scroll;
4326
4356
  Object.defineProperty(exports, "__esModule", {
4327
4357
  value: true
4328
4358
  });
4359
+ exports.SHORTKEY = exports.default = undefined;
4329
4360
 
4330
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4361
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4331
4362
 
4332
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
4363
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4333
4364
 
4334
4365
  var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4335
4366
 
4367
+ var _clone = __webpack_require__(21);
4368
+
4369
+ var _clone2 = _interopRequireDefault(_clone);
4370
+
4371
+ var _deepEqual = __webpack_require__(11);
4372
+
4373
+ var _deepEqual2 = _interopRequireDefault(_deepEqual);
4374
+
4375
+ var _extend = __webpack_require__(3);
4376
+
4377
+ var _extend2 = _interopRequireDefault(_extend);
4378
+
4379
+ var _quillDelta = __webpack_require__(2);
4380
+
4381
+ var _quillDelta2 = _interopRequireDefault(_quillDelta);
4382
+
4383
+ var _op = __webpack_require__(20);
4384
+
4385
+ var _op2 = _interopRequireDefault(_op);
4386
+
4336
4387
  var _parchment = __webpack_require__(0);
4337
4388
 
4338
4389
  var _parchment2 = _interopRequireDefault(_parchment);
4339
4390
 
4340
- var _text = __webpack_require__(7);
4391
+ var _quill = __webpack_require__(5);
4341
4392
 
4342
- var _text2 = _interopRequireDefault(_text);
4393
+ var _quill2 = _interopRequireDefault(_quill);
4394
+
4395
+ var _logger = __webpack_require__(10);
4396
+
4397
+ var _logger2 = _interopRequireDefault(_logger);
4398
+
4399
+ var _module = __webpack_require__(9);
4400
+
4401
+ var _module2 = _interopRequireDefault(_module);
4343
4402
 
4344
4403
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
4345
4404
 
4405
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4406
+
4346
4407
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4347
4408
 
4348
4409
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
4349
4410
 
4350
4411
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
4351
4412
 
4352
- var Cursor = function (_Parchment$Embed) {
4353
- _inherits(Cursor, _Parchment$Embed);
4413
+ var debug = (0, _logger2.default)('quill:keyboard');
4354
4414
 
4355
- _createClass(Cursor, null, [{
4356
- key: 'value',
4357
- value: function value() {
4358
- return undefined;
4415
+ var SHORTKEY = /Mac/i.test(navigator.platform) ? 'metaKey' : 'ctrlKey';
4416
+
4417
+ var Keyboard = function (_Module) {
4418
+ _inherits(Keyboard, _Module);
4419
+
4420
+ _createClass(Keyboard, null, [{
4421
+ key: 'match',
4422
+ value: function match(evt, binding) {
4423
+ binding = normalize(binding);
4424
+ if (['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].some(function (key) {
4425
+ return !!binding[key] !== evt[key] && binding[key] !== null;
4426
+ })) {
4427
+ return false;
4428
+ }
4429
+ return binding.key === (evt.which || evt.keyCode);
4359
4430
  }
4360
4431
  }]);
4361
4432
 
4362
- function Cursor(domNode, selection) {
4363
- _classCallCheck(this, Cursor);
4433
+ function Keyboard(quill, options) {
4434
+ _classCallCheck(this, Keyboard);
4364
4435
 
4365
- var _this = _possibleConstructorReturn(this, (Cursor.__proto__ || Object.getPrototypeOf(Cursor)).call(this, domNode));
4436
+ var _this = _possibleConstructorReturn(this, (Keyboard.__proto__ || Object.getPrototypeOf(Keyboard)).call(this, quill, options));
4366
4437
 
4367
- _this.selection = selection;
4368
- _this.textNode = document.createTextNode(Cursor.CONTENTS);
4369
- _this.domNode.appendChild(_this.textNode);
4370
- _this._length = 0;
4438
+ _this.bindings = {};
4439
+ Object.keys(_this.options.bindings).forEach(function (name) {
4440
+ if (name === 'list autofill' && quill.scroll.whitelist != null && !quill.scroll.whitelist['list']) {
4441
+ return;
4442
+ }
4443
+ if (_this.options.bindings[name]) {
4444
+ _this.addBinding(_this.options.bindings[name]);
4445
+ }
4446
+ });
4447
+ _this.addBinding({ key: Keyboard.keys.ENTER, shiftKey: null }, handleEnter);
4448
+ _this.addBinding({ key: Keyboard.keys.ENTER, metaKey: null, ctrlKey: null, altKey: null }, function () {});
4449
+ if (/Firefox/i.test(navigator.userAgent)) {
4450
+ // Need to handle delete and backspace for Firefox in the general case #1171
4451
+ _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true }, handleBackspace);
4452
+ _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true }, handleDelete);
4453
+ } else {
4454
+ _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true, prefix: /^.?$/ }, handleBackspace);
4455
+ _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true, suffix: /^.?$/ }, handleDelete);
4456
+ }
4457
+ _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: false }, handleDeleteRange);
4458
+ _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: false }, handleDeleteRange);
4459
+ _this.addBinding({ key: Keyboard.keys.BACKSPACE, altKey: null, ctrlKey: null, metaKey: null, shiftKey: null }, { collapsed: true, offset: 0 }, handleBackspace);
4460
+ _this.listen();
4371
4461
  return _this;
4372
4462
  }
4373
4463
 
4374
- _createClass(Cursor, [{
4375
- key: 'detach',
4376
- value: function detach() {
4377
- // super.detach() will also clear domNode.__blot
4378
- if (this.parent != null) this.parent.removeChild(this);
4379
- }
4380
- }, {
4381
- key: 'format',
4382
- value: function format(name, value) {
4383
- if (this._length !== 0) {
4384
- return _get(Cursor.prototype.__proto__ || Object.getPrototypeOf(Cursor.prototype), 'format', this).call(this, name, value);
4464
+ _createClass(Keyboard, [{
4465
+ key: 'addBinding',
4466
+ value: function addBinding(key) {
4467
+ var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4468
+ var handler = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4469
+
4470
+ var binding = normalize(key);
4471
+ if (binding == null || binding.key == null) {
4472
+ return debug.warn('Attempted to add invalid keyboard binding', binding);
4385
4473
  }
4386
- var target = this,
4387
- index = 0;
4388
- while (target != null && target.statics.scope !== _parchment2.default.Scope.BLOCK_BLOT) {
4389
- index += target.offset(target.parent);
4390
- target = target.parent;
4474
+ if (typeof context === 'function') {
4475
+ context = { handler: context };
4391
4476
  }
4392
- if (target != null) {
4393
- this._length = Cursor.CONTENTS.length;
4394
- target.optimize();
4395
- target.formatAt(index, Cursor.CONTENTS.length, name, value);
4396
- this._length = 0;
4477
+ if (typeof handler === 'function') {
4478
+ handler = { handler: handler };
4397
4479
  }
4480
+ binding = (0, _extend2.default)(binding, context, handler);
4481
+ this.bindings[binding.key] = this.bindings[binding.key] || [];
4482
+ this.bindings[binding.key].push(binding);
4398
4483
  }
4399
4484
  }, {
4400
- key: 'index',
4401
- value: function index(node, offset) {
4402
- if (node === this.textNode) return 0;
4403
- return _get(Cursor.prototype.__proto__ || Object.getPrototypeOf(Cursor.prototype), 'index', this).call(this, node, offset);
4404
- }
4405
- }, {
4406
- key: 'length',
4407
- value: function length() {
4408
- return this._length;
4409
- }
4410
- }, {
4411
- key: 'position',
4412
- value: function position() {
4413
- return [this.textNode, this.textNode.data.length];
4414
- }
4415
- }, {
4416
- key: 'remove',
4417
- value: function remove() {
4418
- _get(Cursor.prototype.__proto__ || Object.getPrototypeOf(Cursor.prototype), 'remove', this).call(this);
4419
- this.parent = null;
4420
- }
4421
- }, {
4422
- key: 'restore',
4423
- value: function restore() {
4424
- if (this.selection.composing || this.parent == null) return;
4425
- var textNode = this.textNode;
4426
- var range = this.selection.getNativeRange();
4427
- var restoreText = void 0,
4428
- start = void 0,
4429
- end = void 0;
4430
- if (range != null && range.start.node === textNode && range.end.node === textNode) {
4431
- var _ref = [textNode, range.start.offset, range.end.offset];
4432
- restoreText = _ref[0];
4433
- start = _ref[1];
4434
- end = _ref[2];
4435
- }
4436
- // Link format will insert text outside of anchor tag
4437
- while (this.domNode.lastChild != null && this.domNode.lastChild !== this.textNode) {
4438
- this.domNode.parentNode.insertBefore(this.domNode.lastChild, this.domNode);
4439
- }
4440
- if (this.textNode.data !== Cursor.CONTENTS) {
4441
- var text = this.textNode.data.split(Cursor.CONTENTS).join('');
4442
- if (this.next instanceof _text2.default) {
4443
- restoreText = this.next.domNode;
4444
- this.next.insertAt(0, text);
4445
- this.textNode.data = Cursor.CONTENTS;
4446
- } else {
4447
- this.textNode.data = text;
4448
- this.parent.insertBefore(_parchment2.default.create(this.textNode), this);
4449
- this.textNode = document.createTextNode(Cursor.CONTENTS);
4450
- this.domNode.appendChild(this.textNode);
4451
- }
4452
- }
4453
- this.remove();
4454
- if (start != null) {
4455
- var _map = [start, end].map(function (offset) {
4456
- return Math.max(0, Math.min(restoreText.data.length, offset - 1));
4485
+ key: 'listen',
4486
+ value: function listen() {
4487
+ var _this2 = this;
4488
+
4489
+ this.quill.root.addEventListener('keydown', function (evt) {
4490
+ if (evt.defaultPrevented) return;
4491
+ var which = evt.which || evt.keyCode;
4492
+ var bindings = (_this2.bindings[which] || []).filter(function (binding) {
4493
+ return Keyboard.match(evt, binding);
4457
4494
  });
4495
+ if (bindings.length === 0) return;
4496
+ var range = _this2.quill.getSelection();
4497
+ if (range == null || !_this2.quill.hasFocus()) return;
4458
4498
 
4459
- var _map2 = _slicedToArray(_map, 2);
4499
+ var _quill$getLine = _this2.quill.getLine(range.index),
4500
+ _quill$getLine2 = _slicedToArray(_quill$getLine, 2),
4501
+ line = _quill$getLine2[0],
4502
+ offset = _quill$getLine2[1];
4460
4503
 
4461
- start = _map2[0];
4462
- end = _map2[1];
4504
+ var _quill$getLeaf = _this2.quill.getLeaf(range.index),
4505
+ _quill$getLeaf2 = _slicedToArray(_quill$getLeaf, 2),
4506
+ leafStart = _quill$getLeaf2[0],
4507
+ offsetStart = _quill$getLeaf2[1];
4463
4508
 
4464
- return {
4465
- startNode: restoreText,
4466
- startOffset: start,
4467
- endNode: restoreText,
4468
- endOffset: end
4469
- };
4470
- }
4471
- }
4472
- }, {
4473
- key: 'update',
4474
- value: function update(mutations, context) {
4475
- var _this2 = this;
4509
+ var _ref = range.length === 0 ? [leafStart, offsetStart] : _this2.quill.getLeaf(range.index + range.length),
4510
+ _ref2 = _slicedToArray(_ref, 2),
4511
+ leafEnd = _ref2[0],
4512
+ offsetEnd = _ref2[1];
4476
4513
 
4477
- if (mutations.some(function (mutation) {
4478
- return mutation.type === 'characterData' && mutation.target === _this2.textNode;
4479
- })) {
4480
- var range = this.restore();
4481
- if (range) context.range = range;
4482
- }
4483
- }
4484
- }, {
4485
- key: 'value',
4486
- value: function value() {
4487
- return '';
4514
+ var prefixText = leafStart instanceof _parchment2.default.Text ? leafStart.value().slice(0, offsetStart) : '';
4515
+ var suffixText = leafEnd instanceof _parchment2.default.Text ? leafEnd.value().slice(offsetEnd) : '';
4516
+ var curContext = {
4517
+ collapsed: range.length === 0,
4518
+ empty: range.length === 0 && line.length() <= 1,
4519
+ format: _this2.quill.getFormat(range),
4520
+ offset: offset,
4521
+ prefix: prefixText,
4522
+ suffix: suffixText
4523
+ };
4524
+ var prevented = bindings.some(function (binding) {
4525
+ if (binding.collapsed != null && binding.collapsed !== curContext.collapsed) return false;
4526
+ if (binding.empty != null && binding.empty !== curContext.empty) return false;
4527
+ if (binding.offset != null && binding.offset !== curContext.offset) return false;
4528
+ if (Array.isArray(binding.format)) {
4529
+ // any format is present
4530
+ if (binding.format.every(function (name) {
4531
+ return curContext.format[name] == null;
4532
+ })) {
4533
+ return false;
4534
+ }
4535
+ } else if (_typeof(binding.format) === 'object') {
4536
+ // all formats must match
4537
+ if (!Object.keys(binding.format).every(function (name) {
4538
+ if (binding.format[name] === true) return curContext.format[name] != null;
4539
+ if (binding.format[name] === false) return curContext.format[name] == null;
4540
+ return (0, _deepEqual2.default)(binding.format[name], curContext.format[name]);
4541
+ })) {
4542
+ return false;
4543
+ }
4544
+ }
4545
+ if (binding.prefix != null && !binding.prefix.test(curContext.prefix)) return false;
4546
+ if (binding.suffix != null && !binding.suffix.test(curContext.suffix)) return false;
4547
+ return binding.handler.call(_this2, range, curContext) !== true;
4548
+ });
4549
+ if (prevented) {
4550
+ evt.preventDefault();
4551
+ }
4552
+ });
4488
4553
  }
4489
4554
  }]);
4490
4555
 
4491
- return Cursor;
4492
- }(_parchment2.default.Embed);
4556
+ return Keyboard;
4557
+ }(_module2.default);
4493
4558
 
4494
- Cursor.blotName = 'cursor';
4495
- Cursor.className = 'ql-cursor';
4496
- Cursor.tagName = 'span';
4497
- Cursor.CONTENTS = '\uFEFF'; // Zero width no break space
4559
+ Keyboard.keys = {
4560
+ BACKSPACE: 8,
4561
+ TAB: 9,
4562
+ ENTER: 13,
4563
+ ESCAPE: 27,
4564
+ LEFT: 37,
4565
+ UP: 38,
4566
+ RIGHT: 39,
4567
+ DOWN: 40,
4568
+ DELETE: 46
4569
+ };
4498
4570
 
4571
+ Keyboard.DEFAULTS = {
4572
+ bindings: {
4573
+ 'bold': makeFormatHandler('bold'),
4574
+ 'italic': makeFormatHandler('italic'),
4575
+ 'underline': makeFormatHandler('underline'),
4576
+ 'indent': {
4577
+ // highlight tab or tab at beginning of list, indent or blockquote
4578
+ key: Keyboard.keys.TAB,
4579
+ format: ['blockquote', 'indent', 'list'],
4580
+ handler: function handler(range, context) {
4581
+ if (context.collapsed && context.offset !== 0) return true;
4582
+ this.quill.format('indent', '+1', _quill2.default.sources.USER);
4583
+ }
4584
+ },
4585
+ 'outdent': {
4586
+ key: Keyboard.keys.TAB,
4587
+ shiftKey: true,
4588
+ format: ['blockquote', 'indent', 'list'],
4589
+ // highlight tab or tab at beginning of list, indent or blockquote
4590
+ handler: function handler(range, context) {
4591
+ if (context.collapsed && context.offset !== 0) return true;
4592
+ this.quill.format('indent', '-1', _quill2.default.sources.USER);
4593
+ }
4594
+ },
4595
+ 'outdent backspace': {
4596
+ key: Keyboard.keys.BACKSPACE,
4597
+ collapsed: true,
4598
+ shiftKey: null,
4599
+ metaKey: null,
4600
+ ctrlKey: null,
4601
+ altKey: null,
4602
+ format: ['indent', 'list'],
4603
+ offset: 0,
4604
+ handler: function handler(range, context) {
4605
+ if (context.format.indent != null) {
4606
+ this.quill.format('indent', '-1', _quill2.default.sources.USER);
4607
+ } else if (context.format.list != null) {
4608
+ this.quill.format('list', false, _quill2.default.sources.USER);
4609
+ }
4610
+ }
4611
+ },
4612
+ 'indent code-block': makeCodeBlockHandler(true),
4613
+ 'outdent code-block': makeCodeBlockHandler(false),
4614
+ 'remove tab': {
4615
+ key: Keyboard.keys.TAB,
4616
+ shiftKey: true,
4617
+ collapsed: true,
4618
+ prefix: /\t$/,
4619
+ handler: function handler(range) {
4620
+ this.quill.deleteText(range.index - 1, 1, _quill2.default.sources.USER);
4621
+ }
4622
+ },
4623
+ 'tab': {
4624
+ key: Keyboard.keys.TAB,
4625
+ handler: function handler(range) {
4626
+ this.quill.history.cutoff();
4627
+ var delta = new _quillDelta2.default().retain(range.index).delete(range.length).insert('\t');
4628
+ this.quill.updateContents(delta, _quill2.default.sources.USER);
4629
+ this.quill.history.cutoff();
4630
+ this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
4631
+ }
4632
+ },
4633
+ 'list empty enter': {
4634
+ key: Keyboard.keys.ENTER,
4635
+ collapsed: true,
4636
+ format: ['list'],
4637
+ empty: true,
4638
+ handler: function handler(range, context) {
4639
+ this.quill.format('list', false, _quill2.default.sources.USER);
4640
+ if (context.format.indent) {
4641
+ this.quill.format('indent', false, _quill2.default.sources.USER);
4642
+ }
4643
+ }
4644
+ },
4645
+ 'checklist enter': {
4646
+ key: Keyboard.keys.ENTER,
4647
+ collapsed: true,
4648
+ format: { list: 'checked' },
4649
+ handler: function handler(range) {
4650
+ var _quill$getLine3 = this.quill.getLine(range.index),
4651
+ _quill$getLine4 = _slicedToArray(_quill$getLine3, 2),
4652
+ line = _quill$getLine4[0],
4653
+ offset = _quill$getLine4[1];
4499
4654
 
4500
- exports.default = Cursor;
4655
+ var formats = (0, _extend2.default)({}, line.formats(), { list: 'checked' });
4656
+ var delta = new _quillDelta2.default().retain(range.index).insert('\n', formats).retain(line.length() - offset - 1).retain(1, { list: 'unchecked' });
4657
+ this.quill.updateContents(delta, _quill2.default.sources.USER);
4658
+ this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
4659
+ this.quill.scrollIntoView();
4660
+ }
4661
+ },
4662
+ 'header enter': {
4663
+ key: Keyboard.keys.ENTER,
4664
+ collapsed: true,
4665
+ format: ['header'],
4666
+ suffix: /^$/,
4667
+ handler: function handler(range, context) {
4668
+ var _quill$getLine5 = this.quill.getLine(range.index),
4669
+ _quill$getLine6 = _slicedToArray(_quill$getLine5, 2),
4670
+ line = _quill$getLine6[0],
4671
+ offset = _quill$getLine6[1];
4501
4672
 
4502
- /***/ }),
4503
- /* 24 */
4504
- /***/ (function(module, exports, __webpack_require__) {
4673
+ var delta = new _quillDelta2.default().retain(range.index).insert('\n', context.format).retain(line.length() - offset - 1).retain(1, { header: null });
4674
+ this.quill.updateContents(delta, _quill2.default.sources.USER);
4675
+ this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
4676
+ this.quill.scrollIntoView();
4677
+ }
4678
+ },
4679
+ 'list autofill': {
4680
+ key: ' ',
4681
+ collapsed: true,
4682
+ format: { list: false },
4683
+ prefix: /^\s*?(\d+\.|-|\*|\[ ?\]|\[x\])$/,
4684
+ handler: function handler(range, context) {
4685
+ var length = context.prefix.length;
4505
4686
 
4506
- "use strict";
4687
+ var _quill$getLine7 = this.quill.getLine(range.index),
4688
+ _quill$getLine8 = _slicedToArray(_quill$getLine7, 2),
4689
+ line = _quill$getLine8[0],
4690
+ offset = _quill$getLine8[1];
4507
4691
 
4692
+ if (offset > length) return true;
4693
+ var value = void 0;
4694
+ switch (context.prefix.trim()) {
4695
+ case '[]':case '[ ]':
4696
+ value = 'unchecked';
4697
+ break;
4698
+ case '[x]':
4699
+ value = 'checked';
4700
+ break;
4701
+ case '-':case '*':
4702
+ value = 'bullet';
4703
+ break;
4704
+ default:
4705
+ value = 'ordered';
4706
+ }
4707
+ this.quill.insertText(range.index, ' ', _quill2.default.sources.USER);
4708
+ this.quill.history.cutoff();
4709
+ var delta = new _quillDelta2.default().retain(range.index - offset).delete(length + 1).retain(line.length() - 2 - offset).retain(1, { list: value });
4710
+ this.quill.updateContents(delta, _quill2.default.sources.USER);
4711
+ this.quill.history.cutoff();
4712
+ this.quill.setSelection(range.index - length, _quill2.default.sources.SILENT);
4713
+ }
4714
+ },
4715
+ 'code exit': {
4716
+ key: Keyboard.keys.ENTER,
4717
+ collapsed: true,
4718
+ format: ['code-block'],
4719
+ prefix: /\n\n$/,
4720
+ suffix: /^\s+$/,
4721
+ handler: function handler(range) {
4722
+ var _quill$getLine9 = this.quill.getLine(range.index),
4723
+ _quill$getLine10 = _slicedToArray(_quill$getLine9, 2),
4724
+ line = _quill$getLine10[0],
4725
+ offset = _quill$getLine10[1];
4508
4726
 
4509
- Object.defineProperty(exports, "__esModule", {
4510
- value: true
4511
- });
4727
+ var delta = new _quillDelta2.default().retain(range.index + line.length() - offset - 2).retain(1, { 'code-block': null }).delete(1);
4728
+ this.quill.updateContents(delta, _quill2.default.sources.USER);
4729
+ }
4730
+ },
4731
+ 'embed left': makeEmbedArrowHandler(Keyboard.keys.LEFT, false),
4732
+ 'embed left shift': makeEmbedArrowHandler(Keyboard.keys.LEFT, true),
4733
+ 'embed right': makeEmbedArrowHandler(Keyboard.keys.RIGHT, false),
4734
+ 'embed right shift': makeEmbedArrowHandler(Keyboard.keys.RIGHT, true)
4735
+ }
4736
+ };
4512
4737
 
4513
- var _parchment = __webpack_require__(0);
4738
+ function makeEmbedArrowHandler(key, shiftKey) {
4739
+ var _ref3;
4514
4740
 
4515
- var _parchment2 = _interopRequireDefault(_parchment);
4741
+ var where = key === Keyboard.keys.LEFT ? 'prefix' : 'suffix';
4742
+ return _ref3 = {
4743
+ key: key,
4744
+ shiftKey: shiftKey,
4745
+ altKey: null
4746
+ }, _defineProperty(_ref3, where, /^$/), _defineProperty(_ref3, 'handler', function handler(range) {
4747
+ var index = range.index;
4748
+ if (key === Keyboard.keys.RIGHT) {
4749
+ index += range.length + 1;
4750
+ }
4516
4751
 
4517
- var _block = __webpack_require__(4);
4752
+ var _quill$getLeaf3 = this.quill.getLeaf(index),
4753
+ _quill$getLeaf4 = _slicedToArray(_quill$getLeaf3, 1),
4754
+ leaf = _quill$getLeaf4[0];
4518
4755
 
4519
- var _block2 = _interopRequireDefault(_block);
4756
+ if (!(leaf instanceof _parchment2.default.Embed)) return true;
4757
+ if (key === Keyboard.keys.LEFT) {
4758
+ if (shiftKey) {
4759
+ this.quill.setSelection(range.index - 1, range.length + 1, _quill2.default.sources.USER);
4760
+ } else {
4761
+ this.quill.setSelection(range.index - 1, _quill2.default.sources.USER);
4762
+ }
4763
+ } else {
4764
+ if (shiftKey) {
4765
+ this.quill.setSelection(range.index, range.length + 1, _quill2.default.sources.USER);
4766
+ } else {
4767
+ this.quill.setSelection(range.index + range.length + 1, _quill2.default.sources.USER);
4768
+ }
4769
+ }
4770
+ return false;
4771
+ }), _ref3;
4772
+ }
4520
4773
 
4521
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
4774
+ function handleBackspace(range, context) {
4775
+ if (range.index === 0 || this.quill.getLength() <= 1) return;
4522
4776
 
4523
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4777
+ var _quill$getLine11 = this.quill.getLine(range.index),
4778
+ _quill$getLine12 = _slicedToArray(_quill$getLine11, 1),
4779
+ line = _quill$getLine12[0];
4524
4780
 
4525
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
4781
+ var formats = {};
4782
+ if (context.offset === 0) {
4783
+ var _quill$getLine13 = this.quill.getLine(range.index - 1),
4784
+ _quill$getLine14 = _slicedToArray(_quill$getLine13, 1),
4785
+ prev = _quill$getLine14[0];
4526
4786
 
4527
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
4787
+ if (prev != null && prev.length() > 1) {
4788
+ var curFormats = line.formats();
4789
+ var prevFormats = this.quill.getFormat(range.index - 1, 1);
4790
+ formats = _op2.default.attributes.diff(curFormats, prevFormats) || {};
4791
+ }
4792
+ }
4793
+ // Check for astral symbols
4794
+ var length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
4795
+ this.quill.deleteText(range.index - length, length, _quill2.default.sources.USER);
4796
+ if (Object.keys(formats).length > 0) {
4797
+ this.quill.formatLine(range.index - length, length, formats, _quill2.default.sources.USER);
4798
+ }
4799
+ this.quill.focus();
4800
+ }
4528
4801
 
4529
- var Container = function (_Parchment$Container) {
4530
- _inherits(Container, _Parchment$Container);
4802
+ function handleDelete(range, context) {
4803
+ // Check for astral symbols
4804
+ var length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix) ? 2 : 1;
4805
+ if (range.index >= this.quill.getLength() - length) return;
4806
+ var formats = {},
4807
+ nextLength = 0;
4531
4808
 
4532
- function Container() {
4533
- _classCallCheck(this, Container);
4809
+ var _quill$getLine15 = this.quill.getLine(range.index),
4810
+ _quill$getLine16 = _slicedToArray(_quill$getLine15, 1),
4811
+ line = _quill$getLine16[0];
4534
4812
 
4535
- return _possibleConstructorReturn(this, (Container.__proto__ || Object.getPrototypeOf(Container)).apply(this, arguments));
4813
+ if (context.offset >= line.length() - 1) {
4814
+ var _quill$getLine17 = this.quill.getLine(range.index + 1),
4815
+ _quill$getLine18 = _slicedToArray(_quill$getLine17, 1),
4816
+ next = _quill$getLine18[0];
4817
+
4818
+ if (next) {
4819
+ var curFormats = line.formats();
4820
+ var nextFormats = this.quill.getFormat(range.index, 1);
4821
+ formats = _op2.default.attributes.diff(curFormats, nextFormats) || {};
4822
+ nextLength = next.length();
4823
+ }
4824
+ }
4825
+ this.quill.deleteText(range.index, length, _quill2.default.sources.USER);
4826
+ if (Object.keys(formats).length > 0) {
4827
+ this.quill.formatLine(range.index + nextLength - 1, length, formats, _quill2.default.sources.USER);
4828
+ }
4829
+ }
4830
+
4831
+ function handleDeleteRange(range) {
4832
+ var lines = this.quill.getLines(range);
4833
+ var formats = {};
4834
+ if (lines.length > 1) {
4835
+ var firstFormats = lines[0].formats();
4836
+ var lastFormats = lines[lines.length - 1].formats();
4837
+ formats = _op2.default.attributes.diff(lastFormats, firstFormats) || {};
4838
+ }
4839
+ this.quill.deleteText(range, _quill2.default.sources.USER);
4840
+ if (Object.keys(formats).length > 0) {
4841
+ this.quill.formatLine(range.index, 1, formats, _quill2.default.sources.USER);
4842
+ }
4843
+ this.quill.setSelection(range.index, _quill2.default.sources.SILENT);
4844
+ this.quill.focus();
4845
+ }
4846
+
4847
+ function handleEnter(range, context) {
4848
+ var _this3 = this;
4849
+
4850
+ if (range.length > 0) {
4851
+ this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change
4852
+ }
4853
+ var lineFormats = Object.keys(context.format).reduce(function (lineFormats, format) {
4854
+ if (_parchment2.default.query(format, _parchment2.default.Scope.BLOCK) && !Array.isArray(context.format[format])) {
4855
+ lineFormats[format] = context.format[format];
4856
+ }
4857
+ return lineFormats;
4858
+ }, {});
4859
+ this.quill.insertText(range.index, '\n', lineFormats, _quill2.default.sources.USER);
4860
+ // Earlier scroll.deleteAt might have messed up our selection,
4861
+ // so insertText's built in selection preservation is not reliable
4862
+ this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
4863
+ this.quill.focus();
4864
+ Object.keys(context.format).forEach(function (name) {
4865
+ if (lineFormats[name] != null) return;
4866
+ if (Array.isArray(context.format[name])) return;
4867
+ if (name === 'link') return;
4868
+ _this3.quill.format(name, context.format[name], _quill2.default.sources.USER);
4869
+ });
4870
+ }
4871
+
4872
+ function makeCodeBlockHandler(indent) {
4873
+ return {
4874
+ key: Keyboard.keys.TAB,
4875
+ shiftKey: !indent,
4876
+ format: { 'code-block': true },
4877
+ handler: function handler(range) {
4878
+ var CodeBlock = _parchment2.default.query('code-block');
4879
+ var index = range.index,
4880
+ length = range.length;
4881
+
4882
+ var _quill$scroll$descend = this.quill.scroll.descendant(CodeBlock, index),
4883
+ _quill$scroll$descend2 = _slicedToArray(_quill$scroll$descend, 2),
4884
+ block = _quill$scroll$descend2[0],
4885
+ offset = _quill$scroll$descend2[1];
4886
+
4887
+ if (block == null) return;
4888
+ var scrollIndex = this.quill.getIndex(block);
4889
+ var start = block.newlineIndex(offset, true) + 1;
4890
+ var end = block.newlineIndex(scrollIndex + offset + length);
4891
+ var lines = block.domNode.textContent.slice(start, end).split('\n');
4892
+ offset = 0;
4893
+ lines.forEach(function (line, i) {
4894
+ if (indent) {
4895
+ block.insertAt(start + offset, CodeBlock.TAB);
4896
+ offset += CodeBlock.TAB.length;
4897
+ if (i === 0) {
4898
+ index += CodeBlock.TAB.length;
4899
+ } else {
4900
+ length += CodeBlock.TAB.length;
4901
+ }
4902
+ } else if (line.startsWith(CodeBlock.TAB)) {
4903
+ block.deleteAt(start + offset, CodeBlock.TAB.length);
4904
+ offset -= CodeBlock.TAB.length;
4905
+ if (i === 0) {
4906
+ index -= CodeBlock.TAB.length;
4907
+ } else {
4908
+ length -= CodeBlock.TAB.length;
4909
+ }
4910
+ }
4911
+ offset += line.length + 1;
4912
+ });
4913
+ this.quill.update(_quill2.default.sources.USER);
4914
+ this.quill.setSelection(index, length, _quill2.default.sources.SILENT);
4915
+ }
4916
+ };
4917
+ }
4918
+
4919
+ function makeFormatHandler(format) {
4920
+ return {
4921
+ key: format[0].toUpperCase(),
4922
+ shortKey: true,
4923
+ handler: function handler(range, context) {
4924
+ this.quill.format(format, !context.format[format], _quill2.default.sources.USER);
4925
+ }
4926
+ };
4927
+ }
4928
+
4929
+ function normalize(binding) {
4930
+ if (typeof binding === 'string' || typeof binding === 'number') {
4931
+ return normalize({ key: binding });
4932
+ }
4933
+ if ((typeof binding === 'undefined' ? 'undefined' : _typeof(binding)) === 'object') {
4934
+ binding = (0, _clone2.default)(binding, false);
4935
+ }
4936
+ if (typeof binding.key === 'string') {
4937
+ if (Keyboard.keys[binding.key.toUpperCase()] != null) {
4938
+ binding.key = Keyboard.keys[binding.key.toUpperCase()];
4939
+ } else if (binding.key.length === 1) {
4940
+ binding.key = binding.key.toUpperCase().charCodeAt(0);
4941
+ } else {
4942
+ return null;
4943
+ }
4536
4944
  }
4945
+ if (binding.shortKey) {
4946
+ binding[SHORTKEY] = binding.shortKey;
4947
+ delete binding.shortKey;
4948
+ }
4949
+ return binding;
4950
+ }
4537
4951
 
4538
- return Container;
4539
- }(_parchment2.default.Container);
4540
-
4541
- Container.allowedChildren = [_block2.default, _block.BlockEmbed, Container];
4542
-
4543
- exports.default = Container;
4952
+ exports.default = Keyboard;
4953
+ exports.SHORTKEY = SHORTKEY;
4544
4954
 
4545
4955
  /***/ }),
4546
- /* 25 */
4956
+ /* 24 */
4547
4957
  /***/ (function(module, exports, __webpack_require__) {
4548
4958
 
4549
4959
  "use strict";
@@ -4553,10 +4963,12 @@ Object.defineProperty(exports, "__esModule", {
4553
4963
  value: true
4554
4964
  });
4555
4965
 
4556
- var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4966
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4557
4967
 
4558
4968
  var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
4559
4969
 
4970
+ var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4971
+
4560
4972
  var _parchment = __webpack_require__(0);
4561
4973
 
4562
4974
  var _parchment2 = _interopRequireDefault(_parchment);
@@ -4573,95 +4985,198 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
4573
4985
 
4574
4986
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
4575
4987
 
4576
- var GUARD_TEXT = '\uFEFF';
4988
+ var Cursor = function (_Parchment$Embed) {
4989
+ _inherits(Cursor, _Parchment$Embed);
4577
4990
 
4578
- var Embed = function (_Parchment$Embed) {
4579
- _inherits(Embed, _Parchment$Embed);
4991
+ _createClass(Cursor, null, [{
4992
+ key: 'value',
4993
+ value: function value() {
4994
+ return undefined;
4995
+ }
4996
+ }]);
4580
4997
 
4581
- function Embed(node) {
4582
- _classCallCheck(this, Embed);
4998
+ function Cursor(domNode, selection) {
4999
+ _classCallCheck(this, Cursor);
4583
5000
 
4584
- var _this = _possibleConstructorReturn(this, (Embed.__proto__ || Object.getPrototypeOf(Embed)).call(this, node));
5001
+ var _this = _possibleConstructorReturn(this, (Cursor.__proto__ || Object.getPrototypeOf(Cursor)).call(this, domNode));
4585
5002
 
4586
- _this.contentNode = document.createElement('span');
4587
- _this.contentNode.setAttribute('contenteditable', false);
4588
- [].slice.call(_this.domNode.childNodes).forEach(function (childNode) {
4589
- _this.contentNode.appendChild(childNode);
4590
- });
4591
- _this.leftGuard = document.createTextNode(GUARD_TEXT);
4592
- _this.rightGuard = document.createTextNode(GUARD_TEXT);
4593
- _this.domNode.appendChild(_this.leftGuard);
4594
- _this.domNode.appendChild(_this.contentNode);
4595
- _this.domNode.appendChild(_this.rightGuard);
5003
+ _this.selection = selection;
5004
+ _this.textNode = document.createTextNode(Cursor.CONTENTS);
5005
+ _this.domNode.appendChild(_this.textNode);
5006
+ _this._length = 0;
4596
5007
  return _this;
4597
5008
  }
4598
5009
 
4599
- _createClass(Embed, [{
5010
+ _createClass(Cursor, [{
5011
+ key: 'detach',
5012
+ value: function detach() {
5013
+ // super.detach() will also clear domNode.__blot
5014
+ if (this.parent != null) this.parent.removeChild(this);
5015
+ }
5016
+ }, {
5017
+ key: 'format',
5018
+ value: function format(name, value) {
5019
+ if (this._length !== 0) {
5020
+ return _get(Cursor.prototype.__proto__ || Object.getPrototypeOf(Cursor.prototype), 'format', this).call(this, name, value);
5021
+ }
5022
+ var target = this,
5023
+ index = 0;
5024
+ while (target != null && target.statics.scope !== _parchment2.default.Scope.BLOCK_BLOT) {
5025
+ index += target.offset(target.parent);
5026
+ target = target.parent;
5027
+ }
5028
+ if (target != null) {
5029
+ this._length = Cursor.CONTENTS.length;
5030
+ target.optimize();
5031
+ target.formatAt(index, Cursor.CONTENTS.length, name, value);
5032
+ this._length = 0;
5033
+ }
5034
+ }
5035
+ }, {
4600
5036
  key: 'index',
4601
5037
  value: function index(node, offset) {
4602
- if (node === this.leftGuard) return 0;
4603
- if (node === this.rightGuard) return 1;
4604
- return _get(Embed.prototype.__proto__ || Object.getPrototypeOf(Embed.prototype), 'index', this).call(this, node, offset);
5038
+ if (node === this.textNode) return 0;
5039
+ return _get(Cursor.prototype.__proto__ || Object.getPrototypeOf(Cursor.prototype), 'index', this).call(this, node, offset);
5040
+ }
5041
+ }, {
5042
+ key: 'length',
5043
+ value: function length() {
5044
+ return this._length;
5045
+ }
5046
+ }, {
5047
+ key: 'position',
5048
+ value: function position() {
5049
+ return [this.textNode, this.textNode.data.length];
5050
+ }
5051
+ }, {
5052
+ key: 'remove',
5053
+ value: function remove() {
5054
+ _get(Cursor.prototype.__proto__ || Object.getPrototypeOf(Cursor.prototype), 'remove', this).call(this);
5055
+ this.parent = null;
4605
5056
  }
4606
5057
  }, {
4607
5058
  key: 'restore',
4608
- value: function restore(node) {
4609
- var range = void 0,
4610
- textNode = void 0;
4611
- var text = node.data.split(GUARD_TEXT).join('');
4612
- if (node === this.leftGuard) {
4613
- if (this.prev instanceof _text2.default) {
4614
- var prevLength = this.prev.length();
4615
- this.prev.insertAt(prevLength, text);
4616
- range = {
4617
- startNode: this.prev.domNode,
4618
- startOffset: prevLength + text.length
4619
- };
4620
- } else {
4621
- textNode = document.createTextNode(text);
4622
- this.parent.insertBefore(_parchment2.default.create(textNode), this);
4623
- range = {
4624
- startNode: textNode,
4625
- startOffset: text.length
4626
- };
4627
- }
4628
- } else if (node === this.rightGuard) {
5059
+ value: function restore() {
5060
+ if (this.selection.composing || this.parent == null) return;
5061
+ var textNode = this.textNode;
5062
+ var range = this.selection.getNativeRange();
5063
+ var restoreText = void 0,
5064
+ start = void 0,
5065
+ end = void 0;
5066
+ if (range != null && range.start.node === textNode && range.end.node === textNode) {
5067
+ var _ref = [textNode, range.start.offset, range.end.offset];
5068
+ restoreText = _ref[0];
5069
+ start = _ref[1];
5070
+ end = _ref[2];
5071
+ }
5072
+ // Link format will insert text outside of anchor tag
5073
+ while (this.domNode.lastChild != null && this.domNode.lastChild !== this.textNode) {
5074
+ this.domNode.parentNode.insertBefore(this.domNode.lastChild, this.domNode);
5075
+ }
5076
+ if (this.textNode.data !== Cursor.CONTENTS) {
5077
+ var text = this.textNode.data.split(Cursor.CONTENTS).join('');
4629
5078
  if (this.next instanceof _text2.default) {
5079
+ restoreText = this.next.domNode;
4630
5080
  this.next.insertAt(0, text);
4631
- range = {
4632
- startNode: this.next.domNode,
4633
- startOffset: text.length
4634
- };
5081
+ this.textNode.data = Cursor.CONTENTS;
4635
5082
  } else {
4636
- textNode = document.createTextNode(text);
4637
- this.parent.insertBefore(_parchment2.default.create(textNode), this.next);
4638
- range = {
4639
- startNode: textNode,
4640
- startOffset: text.length
4641
- };
5083
+ this.textNode.data = text;
5084
+ this.parent.insertBefore(_parchment2.default.create(this.textNode), this);
5085
+ this.textNode = document.createTextNode(Cursor.CONTENTS);
5086
+ this.domNode.appendChild(this.textNode);
4642
5087
  }
4643
5088
  }
4644
- node.data = GUARD_TEXT;
4645
- return range;
5089
+ this.remove();
5090
+ if (start != null) {
5091
+ var _map = [start, end].map(function (offset) {
5092
+ return Math.max(0, Math.min(restoreText.data.length, offset - 1));
5093
+ });
5094
+
5095
+ var _map2 = _slicedToArray(_map, 2);
5096
+
5097
+ start = _map2[0];
5098
+ end = _map2[1];
5099
+
5100
+ return {
5101
+ startNode: restoreText,
5102
+ startOffset: start,
5103
+ endNode: restoreText,
5104
+ endOffset: end
5105
+ };
5106
+ }
4646
5107
  }
4647
5108
  }, {
4648
5109
  key: 'update',
4649
5110
  value: function update(mutations, context) {
4650
5111
  var _this2 = this;
4651
5112
 
4652
- mutations.forEach(function (mutation) {
4653
- if (mutation.type === 'characterData' && (mutation.target === _this2.leftGuard || mutation.target === _this2.rightGuard)) {
4654
- var range = _this2.restore(mutation.target);
4655
- if (range) context.range = range;
4656
- }
4657
- });
5113
+ if (mutations.some(function (mutation) {
5114
+ return mutation.type === 'characterData' && mutation.target === _this2.textNode;
5115
+ })) {
5116
+ var range = this.restore();
5117
+ if (range) context.range = range;
5118
+ }
5119
+ }
5120
+ }, {
5121
+ key: 'value',
5122
+ value: function value() {
5123
+ return '';
4658
5124
  }
4659
5125
  }]);
4660
5126
 
4661
- return Embed;
5127
+ return Cursor;
4662
5128
  }(_parchment2.default.Embed);
4663
5129
 
4664
- exports.default = Embed;
5130
+ Cursor.blotName = 'cursor';
5131
+ Cursor.className = 'ql-cursor';
5132
+ Cursor.tagName = 'span';
5133
+ Cursor.CONTENTS = '\uFEFF'; // Zero width no break space
5134
+
5135
+
5136
+ exports.default = Cursor;
5137
+
5138
+ /***/ }),
5139
+ /* 25 */
5140
+ /***/ (function(module, exports, __webpack_require__) {
5141
+
5142
+ "use strict";
5143
+
5144
+
5145
+ Object.defineProperty(exports, "__esModule", {
5146
+ value: true
5147
+ });
5148
+
5149
+ var _parchment = __webpack_require__(0);
5150
+
5151
+ var _parchment2 = _interopRequireDefault(_parchment);
5152
+
5153
+ var _block = __webpack_require__(4);
5154
+
5155
+ var _block2 = _interopRequireDefault(_block);
5156
+
5157
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5158
+
5159
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5160
+
5161
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
5162
+
5163
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
5164
+
5165
+ var Container = function (_Parchment$Container) {
5166
+ _inherits(Container, _Parchment$Container);
5167
+
5168
+ function Container() {
5169
+ _classCallCheck(this, Container);
5170
+
5171
+ return _possibleConstructorReturn(this, (Container.__proto__ || Object.getPrototypeOf(Container)).apply(this, arguments));
5172
+ }
5173
+
5174
+ return Container;
5175
+ }(_parchment2.default.Container);
5176
+
5177
+ Container.allowedChildren = [_block2.default, _block.BlockEmbed, Container];
5178
+
5179
+ exports.default = Container;
4665
5180
 
4666
5181
  /***/ }),
4667
5182
  /* 26 */
@@ -4735,6 +5250,10 @@ exports.ColorStyle = ColorStyle;
4735
5250
  "use strict";
4736
5251
 
4737
5252
 
5253
+ Object.defineProperty(exports, "__esModule", {
5254
+ value: true
5255
+ });
5256
+
4738
5257
  var _parchment = __webpack_require__(0);
4739
5258
 
4740
5259
  var _parchment2 = _interopRequireDefault(_parchment);
@@ -4751,15 +5270,15 @@ var _break = __webpack_require__(16);
4751
5270
 
4752
5271
  var _break2 = _interopRequireDefault(_break);
4753
5272
 
4754
- var _container = __webpack_require__(24);
5273
+ var _container = __webpack_require__(25);
4755
5274
 
4756
5275
  var _container2 = _interopRequireDefault(_container);
4757
5276
 
4758
- var _cursor = __webpack_require__(23);
5277
+ var _cursor = __webpack_require__(24);
4759
5278
 
4760
5279
  var _cursor2 = _interopRequireDefault(_cursor);
4761
5280
 
4762
- var _embed = __webpack_require__(25);
5281
+ var _embed = __webpack_require__(35);
4763
5282
 
4764
5283
  var _embed2 = _interopRequireDefault(_embed);
4765
5284
 
@@ -4783,7 +5302,7 @@ var _history = __webpack_require__(42);
4783
5302
 
4784
5303
  var _history2 = _interopRequireDefault(_history);
4785
5304
 
4786
- var _keyboard = __webpack_require__(35);
5305
+ var _keyboard = __webpack_require__(23);
4787
5306
 
4788
5307
  var _keyboard2 = _interopRequireDefault(_keyboard);
4789
5308
 
@@ -4807,7 +5326,7 @@ _quill2.default.register({
4807
5326
 
4808
5327
  _parchment2.default.register(_block2.default, _break2.default, _cursor2.default, _inline2.default, _scroll2.default, _text2.default);
4809
5328
 
4810
- module.exports = _quill2.default;
5329
+ exports.default = _quill2.default;
4811
5330
 
4812
5331
  /***/ }),
4813
5332
  /* 30 */
@@ -4820,7 +5339,8 @@ var Registry = __webpack_require__(1);
4820
5339
  var ShadowBlot = /** @class */ (function () {
4821
5340
  function ShadowBlot(domNode) {
4822
5341
  this.domNode = domNode;
4823
- this.attach();
5342
+ // @ts-ignore
5343
+ this.domNode[Registry.DATA_KEY] = { blot: this };
4824
5344
  }
4825
5345
  Object.defineProperty(ShadowBlot.prototype, "statics", {
4826
5346
  // Hack for accessing inherited static methods
@@ -4861,7 +5381,9 @@ var ShadowBlot = /** @class */ (function () {
4861
5381
  return node;
4862
5382
  };
4863
5383
  ShadowBlot.prototype.attach = function () {
4864
- this.domNode[Registry.DATA_KEY] = { blot: this };
5384
+ if (this.parent != null) {
5385
+ this.scroll = this.parent.scroll;
5386
+ }
4865
5387
  };
4866
5388
  ShadowBlot.prototype.clone = function () {
4867
5389
  var domNode = this.domNode.cloneNode(false);
@@ -4870,6 +5392,7 @@ var ShadowBlot = /** @class */ (function () {
4870
5392
  ShadowBlot.prototype.detach = function () {
4871
5393
  if (this.parent != null)
4872
5394
  this.parent.removeChild(this);
5395
+ // @ts-ignore
4873
5396
  delete this.domNode[Registry.DATA_KEY];
4874
5397
  };
4875
5398
  ShadowBlot.prototype.deleteAt = function (index, length) {
@@ -4888,22 +5411,26 @@ var ShadowBlot = /** @class */ (function () {
4888
5411
  }
4889
5412
  };
4890
5413
  ShadowBlot.prototype.insertAt = function (index, value, def) {
4891
- var blot = (def == null) ? Registry.create('text', value) : Registry.create(value, def);
5414
+ var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
4892
5415
  var ref = this.split(index);
4893
5416
  this.parent.insertBefore(blot, ref);
4894
5417
  };
4895
5418
  ShadowBlot.prototype.insertInto = function (parentBlot, refBlot) {
5419
+ if (refBlot === void 0) { refBlot = null; }
4896
5420
  if (this.parent != null) {
4897
5421
  this.parent.children.remove(this);
4898
5422
  }
5423
+ var refDomNode = null;
4899
5424
  parentBlot.children.insertBefore(this, refBlot);
4900
5425
  if (refBlot != null) {
4901
- var refDomNode = refBlot.domNode;
5426
+ refDomNode = refBlot.domNode;
4902
5427
  }
4903
- if (this.next == null || this.domNode.nextSibling != refDomNode) {
4904
- parentBlot.domNode.insertBefore(this.domNode, (typeof refDomNode !== 'undefined') ? refDomNode : null);
5428
+ if (this.domNode.parentNode != parentBlot.domNode ||
5429
+ this.domNode.nextSibling != refDomNode) {
5430
+ parentBlot.domNode.insertBefore(this.domNode, refDomNode);
4905
5431
  }
4906
5432
  this.parent = parentBlot;
5433
+ this.attach();
4907
5434
  };
4908
5435
  ShadowBlot.prototype.isolate = function (index, length) {
4909
5436
  var target = this.split(index);
@@ -4913,7 +5440,6 @@ var ShadowBlot = /** @class */ (function () {
4913
5440
  ShadowBlot.prototype.length = function () {
4914
5441
  return 1;
4915
5442
  };
4916
- ;
4917
5443
  ShadowBlot.prototype.offset = function (root) {
4918
5444
  if (root === void 0) { root = this.parent; }
4919
5445
  if (this.parent == null || this == root)
@@ -4922,7 +5448,9 @@ var ShadowBlot = /** @class */ (function () {
4922
5448
  };
4923
5449
  ShadowBlot.prototype.optimize = function (context) {
4924
5450
  // TODO clean up once we use WeakMap
5451
+ // @ts-ignore
4925
5452
  if (this.domNode[Registry.DATA_KEY] != null) {
5453
+ // @ts-ignore
4926
5454
  delete this.domNode[Registry.DATA_KEY].mutations;
4927
5455
  }
4928
5456
  };
@@ -4981,6 +5509,7 @@ var AttributorStore = /** @class */ (function () {
4981
5509
  this.build();
4982
5510
  }
4983
5511
  AttributorStore.prototype.attribute = function (attribute, value) {
5512
+ // verb
4984
5513
  if (value) {
4985
5514
  if (attribute.add(this.domNode, value)) {
4986
5515
  if (attribute.value(this.domNode) != null) {
@@ -5002,7 +5531,10 @@ var AttributorStore = /** @class */ (function () {
5002
5531
  var attributes = attributor_1.default.keys(this.domNode);
5003
5532
  var classes = class_1.default.keys(this.domNode);
5004
5533
  var styles = style_1.default.keys(this.domNode);
5005
- attributes.concat(classes).concat(styles).forEach(function (name) {
5534
+ attributes
5535
+ .concat(classes)
5536
+ .concat(styles)
5537
+ .forEach(function (name) {
5006
5538
  var attr = Registry.query(name, Registry.Scope.ATTRIBUTE);
5007
5539
  if (attr instanceof attributor_1.default) {
5008
5540
  _this.attributes[attr.attrName] = attr;
@@ -5067,7 +5599,10 @@ var ClassAttributor = /** @class */ (function (_super) {
5067
5599
  }
5068
5600
  ClassAttributor.keys = function (node) {
5069
5601
  return (node.getAttribute('class') || '').split(/\s+/).map(function (name) {
5070
- return name.split('-').slice(0, -1).join('-');
5602
+ return name
5603
+ .split('-')
5604
+ .slice(0, -1)
5605
+ .join('-');
5071
5606
  });
5072
5607
  };
5073
5608
  ClassAttributor.prototype.add = function (node, value) {
@@ -5116,9 +5651,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
5116
5651
  var attributor_1 = __webpack_require__(12);
5117
5652
  function camelize(name) {
5118
5653
  var parts = name.split('-');
5119
- var rest = parts.slice(1).map(function (part) {
5654
+ var rest = parts
5655
+ .slice(1)
5656
+ .map(function (part) {
5120
5657
  return part[0].toUpperCase() + part.slice(1);
5121
- }).join('');
5658
+ })
5659
+ .join('');
5122
5660
  return parts[0] + rest;
5123
5661
  }
5124
5662
  var StyleAttributor = /** @class */ (function (_super) {
@@ -5135,16 +5673,19 @@ var StyleAttributor = /** @class */ (function (_super) {
5135
5673
  StyleAttributor.prototype.add = function (node, value) {
5136
5674
  if (!this.canAdd(node, value))
5137
5675
  return false;
5676
+ // @ts-ignore
5138
5677
  node.style[camelize(this.keyName)] = value;
5139
5678
  return true;
5140
5679
  };
5141
5680
  StyleAttributor.prototype.remove = function (node) {
5681
+ // @ts-ignore
5142
5682
  node.style[camelize(this.keyName)] = '';
5143
5683
  if (!node.getAttribute('style')) {
5144
5684
  node.removeAttribute('style');
5145
5685
  }
5146
5686
  };
5147
5687
  StyleAttributor.prototype.value = function (node) {
5688
+ // @ts-ignore
5148
5689
  var value = node.style[camelize(this.keyName)];
5149
5690
  return this.canAdd(node, value) ? value : '';
5150
5691
  };
@@ -5166,656 +5707,169 @@ Object.defineProperty(exports, "__esModule", {
5166
5707
 
5167
5708
  var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
5168
5709
 
5169
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5170
-
5171
- var Theme = function () {
5172
- function Theme(quill, options) {
5173
- _classCallCheck(this, Theme);
5174
-
5175
- this.quill = quill;
5176
- this.options = options;
5177
- this.modules = {};
5178
- }
5179
-
5180
- _createClass(Theme, [{
5181
- key: 'init',
5182
- value: function init() {
5183
- var _this = this;
5184
-
5185
- Object.keys(this.options.modules).forEach(function (name) {
5186
- if (_this.modules[name] == null) {
5187
- _this.addModule(name);
5188
- }
5189
- });
5190
- }
5191
- }, {
5192
- key: 'addModule',
5193
- value: function addModule(name) {
5194
- var moduleClass = this.quill.constructor.import('modules/' + name);
5195
- this.modules[name] = new moduleClass(this.quill, this.options.modules[name] || {});
5196
- return this.modules[name];
5197
- }
5198
- }]);
5199
-
5200
- return Theme;
5201
- }();
5202
-
5203
- Theme.DEFAULTS = {
5204
- modules: {}
5205
- };
5206
- Theme.themes = {
5207
- 'default': Theme
5208
- };
5209
-
5210
- exports.default = Theme;
5211
-
5212
- /***/ }),
5213
- /* 35 */
5214
- /***/ (function(module, exports, __webpack_require__) {
5215
-
5216
- "use strict";
5217
-
5218
-
5219
- Object.defineProperty(exports, "__esModule", {
5220
- value: true
5221
- });
5222
- exports.SHORTKEY = exports.default = undefined;
5223
-
5224
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
5225
-
5226
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
5227
-
5228
- var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
5229
-
5230
- var _clone = __webpack_require__(21);
5231
-
5232
- var _clone2 = _interopRequireDefault(_clone);
5233
-
5234
- var _deepEqual = __webpack_require__(11);
5235
-
5236
- var _deepEqual2 = _interopRequireDefault(_deepEqual);
5237
-
5238
- var _extend = __webpack_require__(3);
5239
-
5240
- var _extend2 = _interopRequireDefault(_extend);
5241
-
5242
- var _quillDelta = __webpack_require__(2);
5243
-
5244
- var _quillDelta2 = _interopRequireDefault(_quillDelta);
5245
-
5246
- var _op = __webpack_require__(20);
5247
-
5248
- var _op2 = _interopRequireDefault(_op);
5249
-
5250
- var _parchment = __webpack_require__(0);
5251
-
5252
- var _parchment2 = _interopRequireDefault(_parchment);
5253
-
5254
- var _embed = __webpack_require__(25);
5255
-
5256
- var _embed2 = _interopRequireDefault(_embed);
5257
-
5258
- var _quill = __webpack_require__(5);
5259
-
5260
- var _quill2 = _interopRequireDefault(_quill);
5261
-
5262
- var _logger = __webpack_require__(10);
5263
-
5264
- var _logger2 = _interopRequireDefault(_logger);
5265
-
5266
- var _module = __webpack_require__(9);
5267
-
5268
- var _module2 = _interopRequireDefault(_module);
5269
-
5270
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5271
-
5272
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5273
-
5274
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5275
-
5276
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
5277
-
5278
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
5279
-
5280
- var debug = (0, _logger2.default)('quill:keyboard');
5281
-
5282
- var SHORTKEY = /Mac/i.test(navigator.platform) ? 'metaKey' : 'ctrlKey';
5283
-
5284
- var Keyboard = function (_Module) {
5285
- _inherits(Keyboard, _Module);
5286
-
5287
- _createClass(Keyboard, null, [{
5288
- key: 'match',
5289
- value: function match(evt, binding) {
5290
- binding = normalize(binding);
5291
- if (['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].some(function (key) {
5292
- return !!binding[key] !== evt[key] && binding[key] !== null;
5293
- })) {
5294
- return false;
5295
- }
5296
- return binding.key === (evt.which || evt.keyCode);
5297
- }
5298
- }]);
5299
-
5300
- function Keyboard(quill, options) {
5301
- _classCallCheck(this, Keyboard);
5302
-
5303
- var _this = _possibleConstructorReturn(this, (Keyboard.__proto__ || Object.getPrototypeOf(Keyboard)).call(this, quill, options));
5304
-
5305
- _this.bindings = {};
5306
- Object.keys(_this.options.bindings).forEach(function (name) {
5307
- if (name === 'list autofill' && quill.scroll.whitelist != null && !quill.scroll.whitelist['list']) {
5308
- return;
5309
- }
5310
- if (_this.options.bindings[name]) {
5311
- _this.addBinding(_this.options.bindings[name]);
5312
- }
5313
- });
5314
- _this.addBinding({ key: Keyboard.keys.ENTER, shiftKey: null }, handleEnter);
5315
- _this.addBinding({ key: Keyboard.keys.ENTER, metaKey: null, ctrlKey: null, altKey: null }, function () {});
5316
- if (/Firefox/i.test(navigator.userAgent)) {
5317
- // Need to handle delete and backspace for Firefox in the general case #1171
5318
- _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true }, handleBackspace);
5319
- _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true }, handleDelete);
5320
- } else {
5321
- _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true, prefix: /^.?$/ }, handleBackspace);
5322
- _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true, suffix: /^.?$/ }, handleDelete);
5323
- }
5324
- _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: false }, handleDeleteRange);
5325
- _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: false }, handleDeleteRange);
5326
- _this.addBinding({ key: Keyboard.keys.BACKSPACE, altKey: null, ctrlKey: null, metaKey: null, shiftKey: null }, { collapsed: true, offset: 0 }, handleBackspace);
5327
- _this.listen();
5328
- return _this;
5329
- }
5330
-
5331
- _createClass(Keyboard, [{
5332
- key: 'addBinding',
5333
- value: function addBinding(key) {
5334
- var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5335
- var handler = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5336
-
5337
- var binding = normalize(key);
5338
- if (binding == null || binding.key == null) {
5339
- return debug.warn('Attempted to add invalid keyboard binding', binding);
5340
- }
5341
- if (typeof context === 'function') {
5342
- context = { handler: context };
5343
- }
5344
- if (typeof handler === 'function') {
5345
- handler = { handler: handler };
5346
- }
5347
- binding = (0, _extend2.default)(binding, context, handler);
5348
- this.bindings[binding.key] = this.bindings[binding.key] || [];
5349
- this.bindings[binding.key].push(binding);
5350
- }
5351
- }, {
5352
- key: 'listen',
5353
- value: function listen() {
5354
- var _this2 = this;
5355
-
5356
- this.quill.root.addEventListener('keydown', function (evt) {
5357
- if (evt.defaultPrevented) return;
5358
- var which = evt.which || evt.keyCode;
5359
- var bindings = (_this2.bindings[which] || []).filter(function (binding) {
5360
- return Keyboard.match(evt, binding);
5361
- });
5362
- if (bindings.length === 0) return;
5363
- var range = _this2.quill.getSelection();
5364
- if (range == null || !_this2.quill.hasFocus()) return;
5365
-
5366
- var _quill$getLine = _this2.quill.getLine(range.index),
5367
- _quill$getLine2 = _slicedToArray(_quill$getLine, 2),
5368
- line = _quill$getLine2[0],
5369
- offset = _quill$getLine2[1];
5370
-
5371
- var _quill$getLeaf = _this2.quill.getLeaf(range.index),
5372
- _quill$getLeaf2 = _slicedToArray(_quill$getLeaf, 2),
5373
- leafStart = _quill$getLeaf2[0],
5374
- offsetStart = _quill$getLeaf2[1];
5375
-
5376
- var _ref = range.length === 0 ? [leafStart, offsetStart] : _this2.quill.getLeaf(range.index + range.length),
5377
- _ref2 = _slicedToArray(_ref, 2),
5378
- leafEnd = _ref2[0],
5379
- offsetEnd = _ref2[1];
5380
-
5381
- var prefixText = leafStart instanceof _parchment2.default.Text ? leafStart.value().slice(0, offsetStart) : '';
5382
- var suffixText = leafEnd instanceof _parchment2.default.Text ? leafEnd.value().slice(offsetEnd) : '';
5383
- var curContext = {
5384
- collapsed: range.length === 0,
5385
- empty: range.length === 0 && line.length() <= 1,
5386
- format: _this2.quill.getFormat(range),
5387
- offset: offset,
5388
- prefix: prefixText,
5389
- suffix: suffixText
5390
- };
5391
- var prevented = bindings.some(function (binding) {
5392
- if (binding.collapsed != null && binding.collapsed !== curContext.collapsed) return false;
5393
- if (binding.empty != null && binding.empty !== curContext.empty) return false;
5394
- if (binding.offset != null && binding.offset !== curContext.offset) return false;
5395
- if (Array.isArray(binding.format)) {
5396
- // any format is present
5397
- if (binding.format.every(function (name) {
5398
- return curContext.format[name] == null;
5399
- })) {
5400
- return false;
5401
- }
5402
- } else if (_typeof(binding.format) === 'object') {
5403
- // all formats must match
5404
- if (!Object.keys(binding.format).every(function (name) {
5405
- if (binding.format[name] === true) return curContext.format[name] != null;
5406
- if (binding.format[name] === false) return curContext.format[name] == null;
5407
- return (0, _deepEqual2.default)(binding.format[name], curContext.format[name]);
5408
- })) {
5409
- return false;
5410
- }
5411
- }
5412
- if (binding.prefix != null && !binding.prefix.test(curContext.prefix)) return false;
5413
- if (binding.suffix != null && !binding.suffix.test(curContext.suffix)) return false;
5414
- return binding.handler.call(_this2, range, curContext) !== true;
5415
- });
5416
- if (prevented) {
5417
- evt.preventDefault();
5710
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5711
+
5712
+ var Theme = function () {
5713
+ function Theme(quill, options) {
5714
+ _classCallCheck(this, Theme);
5715
+
5716
+ this.quill = quill;
5717
+ this.options = options;
5718
+ this.modules = {};
5719
+ }
5720
+
5721
+ _createClass(Theme, [{
5722
+ key: 'init',
5723
+ value: function init() {
5724
+ var _this = this;
5725
+
5726
+ Object.keys(this.options.modules).forEach(function (name) {
5727
+ if (_this.modules[name] == null) {
5728
+ _this.addModule(name);
5418
5729
  }
5419
5730
  });
5420
5731
  }
5732
+ }, {
5733
+ key: 'addModule',
5734
+ value: function addModule(name) {
5735
+ var moduleClass = this.quill.constructor.import('modules/' + name);
5736
+ this.modules[name] = new moduleClass(this.quill, this.options.modules[name] || {});
5737
+ return this.modules[name];
5738
+ }
5421
5739
  }]);
5422
5740
 
5423
- return Keyboard;
5424
- }(_module2.default);
5741
+ return Theme;
5742
+ }();
5425
5743
 
5426
- Keyboard.keys = {
5427
- BACKSPACE: 8,
5428
- TAB: 9,
5429
- ENTER: 13,
5430
- ESCAPE: 27,
5431
- LEFT: 37,
5432
- UP: 38,
5433
- RIGHT: 39,
5434
- DOWN: 40,
5435
- DELETE: 46
5744
+ Theme.DEFAULTS = {
5745
+ modules: {}
5746
+ };
5747
+ Theme.themes = {
5748
+ 'default': Theme
5436
5749
  };
5437
5750
 
5438
- Keyboard.DEFAULTS = {
5439
- bindings: {
5440
- 'bold': makeFormatHandler('bold'),
5441
- 'italic': makeFormatHandler('italic'),
5442
- 'underline': makeFormatHandler('underline'),
5443
- 'indent': {
5444
- // highlight tab or tab at beginning of list, indent or blockquote
5445
- key: Keyboard.keys.TAB,
5446
- format: ['blockquote', 'indent', 'list'],
5447
- handler: function handler(range, context) {
5448
- if (context.collapsed && context.offset !== 0) return true;
5449
- this.quill.format('indent', '+1', _quill2.default.sources.USER);
5450
- }
5451
- },
5452
- 'outdent': {
5453
- key: Keyboard.keys.TAB,
5454
- shiftKey: true,
5455
- format: ['blockquote', 'indent', 'list'],
5456
- // highlight tab or tab at beginning of list, indent or blockquote
5457
- handler: function handler(range, context) {
5458
- if (context.collapsed && context.offset !== 0) return true;
5459
- this.quill.format('indent', '-1', _quill2.default.sources.USER);
5460
- }
5461
- },
5462
- 'outdent backspace': {
5463
- key: Keyboard.keys.BACKSPACE,
5464
- collapsed: true,
5465
- shiftKey: null,
5466
- metaKey: null,
5467
- ctrlKey: null,
5468
- altKey: null,
5469
- format: ['indent', 'list'],
5470
- offset: 0,
5471
- handler: function handler(range, context) {
5472
- if (context.format.indent != null) {
5473
- this.quill.format('indent', '-1', _quill2.default.sources.USER);
5474
- } else if (context.format.list != null) {
5475
- this.quill.format('list', false, _quill2.default.sources.USER);
5476
- }
5477
- }
5478
- },
5479
- 'indent code-block': makeCodeBlockHandler(true),
5480
- 'outdent code-block': makeCodeBlockHandler(false),
5481
- 'remove tab': {
5482
- key: Keyboard.keys.TAB,
5483
- shiftKey: true,
5484
- collapsed: true,
5485
- prefix: /\t$/,
5486
- handler: function handler(range) {
5487
- this.quill.deleteText(range.index - 1, 1, _quill2.default.sources.USER);
5488
- }
5489
- },
5490
- 'tab': {
5491
- key: Keyboard.keys.TAB,
5492
- handler: function handler(range) {
5493
- this.quill.history.cutoff();
5494
- var delta = new _quillDelta2.default().retain(range.index).delete(range.length).insert('\t');
5495
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5496
- this.quill.history.cutoff();
5497
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5498
- }
5499
- },
5500
- 'list empty enter': {
5501
- key: Keyboard.keys.ENTER,
5502
- collapsed: true,
5503
- format: ['list'],
5504
- empty: true,
5505
- handler: function handler(range, context) {
5506
- this.quill.format('list', false, _quill2.default.sources.USER);
5507
- if (context.format.indent) {
5508
- this.quill.format('indent', false, _quill2.default.sources.USER);
5509
- }
5510
- }
5511
- },
5512
- 'checklist enter': {
5513
- key: Keyboard.keys.ENTER,
5514
- collapsed: true,
5515
- format: { list: 'checked' },
5516
- handler: function handler(range) {
5517
- var _quill$getLine3 = this.quill.getLine(range.index),
5518
- _quill$getLine4 = _slicedToArray(_quill$getLine3, 2),
5519
- line = _quill$getLine4[0],
5520
- offset = _quill$getLine4[1];
5521
-
5522
- var delta = new _quillDelta2.default().retain(range.index).insert('\n', { list: 'checked' }).retain(line.length() - offset - 1).retain(1, { list: 'unchecked' });
5523
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5524
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5525
- this.quill.scrollIntoView();
5526
- }
5527
- },
5528
- 'header enter': {
5529
- key: Keyboard.keys.ENTER,
5530
- collapsed: true,
5531
- format: ['header'],
5532
- suffix: /^$/,
5533
- handler: function handler(range, context) {
5534
- var _quill$getLine5 = this.quill.getLine(range.index),
5535
- _quill$getLine6 = _slicedToArray(_quill$getLine5, 2),
5536
- line = _quill$getLine6[0],
5537
- offset = _quill$getLine6[1];
5538
-
5539
- var delta = new _quillDelta2.default().retain(range.index).insert('\n', context.format).retain(line.length() - offset - 1).retain(1, { header: null });
5540
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5541
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5542
- this.quill.scrollIntoView();
5543
- }
5544
- },
5545
- 'list autofill': {
5546
- key: ' ',
5547
- collapsed: true,
5548
- format: { list: false },
5549
- prefix: /^\s*?(1\.|-|\[ ?\]|\[x\])$/,
5550
- handler: function handler(range, context) {
5551
- var length = context.prefix.length;
5552
-
5553
- var _quill$getLine7 = this.quill.getLine(range.index),
5554
- _quill$getLine8 = _slicedToArray(_quill$getLine7, 2),
5555
- line = _quill$getLine8[0],
5556
- offset = _quill$getLine8[1];
5751
+ exports.default = Theme;
5557
5752
 
5558
- if (offset > length) return true;
5559
- var value = void 0;
5560
- switch (context.prefix.trim()) {
5561
- case '[]':case '[ ]':
5562
- value = 'unchecked';
5563
- break;
5564
- case '[x]':
5565
- value = 'checked';
5566
- break;
5567
- case '-':
5568
- value = 'bullet';
5569
- break;
5570
- default:
5571
- value = 'ordered';
5572
- }
5573
- this.quill.insertText(range.index, ' ', _quill2.default.sources.USER);
5574
- this.quill.history.cutoff();
5575
- var delta = new _quillDelta2.default().retain(range.index - offset).delete(length + 1).retain(line.length() - 2 - offset).retain(1, { list: value });
5576
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5577
- this.quill.history.cutoff();
5578
- this.quill.setSelection(range.index - length, _quill2.default.sources.SILENT);
5579
- }
5580
- },
5581
- 'code exit': {
5582
- key: Keyboard.keys.ENTER,
5583
- collapsed: true,
5584
- format: ['code-block'],
5585
- prefix: /\n\n$/,
5586
- suffix: /^\s+$/,
5587
- handler: function handler(range) {
5588
- var _quill$getLine9 = this.quill.getLine(range.index),
5589
- _quill$getLine10 = _slicedToArray(_quill$getLine9, 2),
5590
- line = _quill$getLine10[0],
5591
- offset = _quill$getLine10[1];
5753
+ /***/ }),
5754
+ /* 35 */
5755
+ /***/ (function(module, exports, __webpack_require__) {
5592
5756
 
5593
- var delta = new _quillDelta2.default().retain(range.index + line.length() - offset - 2).retain(1, { 'code-block': null }).delete(1);
5594
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5595
- }
5596
- },
5597
- 'embed left': makeEmbedArrowHandler(Keyboard.keys.LEFT, false),
5598
- 'embed left shift': makeEmbedArrowHandler(Keyboard.keys.LEFT, true),
5599
- 'embed right': makeEmbedArrowHandler(Keyboard.keys.RIGHT, false),
5600
- 'embed right shift': makeEmbedArrowHandler(Keyboard.keys.RIGHT, true)
5601
- }
5602
- };
5757
+ "use strict";
5603
5758
 
5604
- function makeEmbedArrowHandler(key, shiftKey) {
5605
- var _ref3;
5606
5759
 
5607
- var where = key === Keyboard.keys.LEFT ? 'prefix' : 'suffix';
5608
- return _ref3 = {
5609
- key: key,
5610
- shiftKey: shiftKey
5611
- }, _defineProperty(_ref3, where, /^$/), _defineProperty(_ref3, 'handler', function handler(range) {
5612
- var index = range.index;
5613
- if (key === Keyboard.keys.RIGHT) {
5614
- index += range.length + 1;
5615
- }
5760
+ Object.defineProperty(exports, "__esModule", {
5761
+ value: true
5762
+ });
5616
5763
 
5617
- var _quill$getLeaf3 = this.quill.getLeaf(index),
5618
- _quill$getLeaf4 = _slicedToArray(_quill$getLeaf3, 1),
5619
- leaf = _quill$getLeaf4[0];
5764
+ var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
5620
5765
 
5621
- if (!(leaf instanceof _embed2.default)) return true;
5622
- if (key === Keyboard.keys.LEFT) {
5623
- if (shiftKey) {
5624
- this.quill.setSelection(range.index - 1, range.length + 1, _quill2.default.sources.USER);
5625
- } else {
5626
- this.quill.setSelection(range.index - 1, _quill2.default.sources.USER);
5627
- }
5628
- } else {
5629
- if (shiftKey) {
5630
- this.quill.setSelection(range.index, range.length + 1, _quill2.default.sources.USER);
5631
- } else {
5632
- this.quill.setSelection(range.index + range.length + 1, _quill2.default.sources.USER);
5633
- }
5634
- }
5635
- return false;
5636
- }), _ref3;
5637
- }
5766
+ var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
5638
5767
 
5639
- function handleBackspace(range, context) {
5640
- if (range.index === 0 || this.quill.getLength() <= 1) return;
5768
+ var _parchment = __webpack_require__(0);
5641
5769
 
5642
- var _quill$getLine11 = this.quill.getLine(range.index),
5643
- _quill$getLine12 = _slicedToArray(_quill$getLine11, 1),
5644
- line = _quill$getLine12[0];
5770
+ var _parchment2 = _interopRequireDefault(_parchment);
5645
5771
 
5646
- var formats = {};
5647
- if (context.offset === 0) {
5648
- var _quill$getLine13 = this.quill.getLine(range.index - 1),
5649
- _quill$getLine14 = _slicedToArray(_quill$getLine13, 1),
5650
- prev = _quill$getLine14[0];
5772
+ var _text = __webpack_require__(7);
5651
5773
 
5652
- if (prev != null && prev.length() > 1) {
5653
- var curFormats = line.formats();
5654
- var prevFormats = this.quill.getFormat(range.index - 1, 1);
5655
- formats = _op2.default.attributes.diff(curFormats, prevFormats) || {};
5656
- }
5657
- }
5658
- // Check for astral symbols
5659
- var length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
5660
- this.quill.deleteText(range.index - length, length, _quill2.default.sources.USER);
5661
- if (Object.keys(formats).length > 0) {
5662
- this.quill.formatLine(range.index - length, length, formats, _quill2.default.sources.USER);
5663
- }
5664
- this.quill.focus();
5665
- }
5774
+ var _text2 = _interopRequireDefault(_text);
5666
5775
 
5667
- function handleDelete(range, context) {
5668
- // Check for astral symbols
5669
- var length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix) ? 2 : 1;
5670
- if (range.index >= this.quill.getLength() - length) return;
5671
- var formats = {},
5672
- nextLength = 0;
5776
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5673
5777
 
5674
- var _quill$getLine15 = this.quill.getLine(range.index),
5675
- _quill$getLine16 = _slicedToArray(_quill$getLine15, 1),
5676
- line = _quill$getLine16[0];
5778
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5677
5779
 
5678
- if (context.offset >= line.length() - 1) {
5679
- var _quill$getLine17 = this.quill.getLine(range.index + 1),
5680
- _quill$getLine18 = _slicedToArray(_quill$getLine17, 1),
5681
- next = _quill$getLine18[0];
5780
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
5682
5781
 
5683
- if (next) {
5684
- var curFormats = line.formats();
5685
- var nextFormats = this.quill.getFormat(range.index, 1);
5686
- formats = _op2.default.attributes.diff(curFormats, nextFormats) || {};
5687
- nextLength = next.length();
5688
- }
5689
- }
5690
- this.quill.deleteText(range.index, length, _quill2.default.sources.USER);
5691
- if (Object.keys(formats).length > 0) {
5692
- this.quill.formatLine(range.index + nextLength - 1, length, formats, _quill2.default.sources.USER);
5693
- }
5694
- }
5782
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
5695
5783
 
5696
- function handleDeleteRange(range) {
5697
- var lines = this.quill.getLines(range);
5698
- var formats = {};
5699
- if (lines.length > 1) {
5700
- var firstFormats = lines[0].formats();
5701
- var lastFormats = lines[lines.length - 1].formats();
5702
- formats = _op2.default.attributes.diff(lastFormats, firstFormats) || {};
5703
- }
5704
- this.quill.deleteText(range, _quill2.default.sources.USER);
5705
- if (Object.keys(formats).length > 0) {
5706
- this.quill.formatLine(range.index, 1, formats, _quill2.default.sources.USER);
5707
- }
5708
- this.quill.setSelection(range.index, _quill2.default.sources.SILENT);
5709
- this.quill.focus();
5710
- }
5784
+ var GUARD_TEXT = '\uFEFF';
5711
5785
 
5712
- function handleEnter(range, context) {
5713
- var _this3 = this;
5786
+ var Embed = function (_Parchment$Embed) {
5787
+ _inherits(Embed, _Parchment$Embed);
5714
5788
 
5715
- if (range.length > 0) {
5716
- this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change
5717
- }
5718
- var lineFormats = Object.keys(context.format).reduce(function (lineFormats, format) {
5719
- if (_parchment2.default.query(format, _parchment2.default.Scope.BLOCK) && !Array.isArray(context.format[format])) {
5720
- lineFormats[format] = context.format[format];
5721
- }
5722
- return lineFormats;
5723
- }, {});
5724
- this.quill.insertText(range.index, '\n', lineFormats, _quill2.default.sources.USER);
5725
- // Earlier scroll.deleteAt might have messed up our selection,
5726
- // so insertText's built in selection preservation is not reliable
5727
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5728
- this.quill.focus();
5729
- Object.keys(context.format).forEach(function (name) {
5730
- if (lineFormats[name] != null) return;
5731
- if (Array.isArray(context.format[name])) return;
5732
- if (name === 'link') return;
5733
- _this3.quill.format(name, context.format[name], _quill2.default.sources.USER);
5734
- });
5735
- }
5789
+ function Embed(node) {
5790
+ _classCallCheck(this, Embed);
5736
5791
 
5737
- function makeCodeBlockHandler(indent) {
5738
- return {
5739
- key: Keyboard.keys.TAB,
5740
- shiftKey: !indent,
5741
- format: { 'code-block': true },
5742
- handler: function handler(range) {
5743
- var CodeBlock = _parchment2.default.query('code-block');
5744
- var index = range.index,
5745
- length = range.length;
5792
+ var _this = _possibleConstructorReturn(this, (Embed.__proto__ || Object.getPrototypeOf(Embed)).call(this, node));
5746
5793
 
5747
- var _quill$scroll$descend = this.quill.scroll.descendant(CodeBlock, index),
5748
- _quill$scroll$descend2 = _slicedToArray(_quill$scroll$descend, 2),
5749
- block = _quill$scroll$descend2[0],
5750
- offset = _quill$scroll$descend2[1];
5794
+ _this.contentNode = document.createElement('span');
5795
+ _this.contentNode.setAttribute('contenteditable', false);
5796
+ [].slice.call(_this.domNode.childNodes).forEach(function (childNode) {
5797
+ _this.contentNode.appendChild(childNode);
5798
+ });
5799
+ _this.leftGuard = document.createTextNode(GUARD_TEXT);
5800
+ _this.rightGuard = document.createTextNode(GUARD_TEXT);
5801
+ _this.domNode.appendChild(_this.leftGuard);
5802
+ _this.domNode.appendChild(_this.contentNode);
5803
+ _this.domNode.appendChild(_this.rightGuard);
5804
+ return _this;
5805
+ }
5751
5806
 
5752
- if (block == null) return;
5753
- var scrollIndex = this.quill.getIndex(block);
5754
- var start = block.newlineIndex(offset, true) + 1;
5755
- var end = block.newlineIndex(scrollIndex + offset + length);
5756
- var lines = block.domNode.textContent.slice(start, end).split('\n');
5757
- offset = 0;
5758
- lines.forEach(function (line, i) {
5759
- if (indent) {
5760
- block.insertAt(start + offset, CodeBlock.TAB);
5761
- offset += CodeBlock.TAB.length;
5762
- if (i === 0) {
5763
- index += CodeBlock.TAB.length;
5764
- } else {
5765
- length += CodeBlock.TAB.length;
5766
- }
5767
- } else if (line.startsWith(CodeBlock.TAB)) {
5768
- block.deleteAt(start + offset, CodeBlock.TAB.length);
5769
- offset -= CodeBlock.TAB.length;
5770
- if (i === 0) {
5771
- index -= CodeBlock.TAB.length;
5772
- } else {
5773
- length -= CodeBlock.TAB.length;
5774
- }
5807
+ _createClass(Embed, [{
5808
+ key: 'index',
5809
+ value: function index(node, offset) {
5810
+ if (node === this.leftGuard) return 0;
5811
+ if (node === this.rightGuard) return 1;
5812
+ return _get(Embed.prototype.__proto__ || Object.getPrototypeOf(Embed.prototype), 'index', this).call(this, node, offset);
5813
+ }
5814
+ }, {
5815
+ key: 'restore',
5816
+ value: function restore(node) {
5817
+ var range = void 0,
5818
+ textNode = void 0;
5819
+ var text = node.data.split(GUARD_TEXT).join('');
5820
+ if (node === this.leftGuard) {
5821
+ if (this.prev instanceof _text2.default) {
5822
+ var prevLength = this.prev.length();
5823
+ this.prev.insertAt(prevLength, text);
5824
+ range = {
5825
+ startNode: this.prev.domNode,
5826
+ startOffset: prevLength + text.length
5827
+ };
5828
+ } else {
5829
+ textNode = document.createTextNode(text);
5830
+ this.parent.insertBefore(_parchment2.default.create(textNode), this);
5831
+ range = {
5832
+ startNode: textNode,
5833
+ startOffset: text.length
5834
+ };
5775
5835
  }
5776
- offset += line.length + 1;
5777
- });
5778
- this.quill.update(_quill2.default.sources.USER);
5779
- this.quill.setSelection(index, length, _quill2.default.sources.SILENT);
5836
+ } else if (node === this.rightGuard) {
5837
+ if (this.next instanceof _text2.default) {
5838
+ this.next.insertAt(0, text);
5839
+ range = {
5840
+ startNode: this.next.domNode,
5841
+ startOffset: text.length
5842
+ };
5843
+ } else {
5844
+ textNode = document.createTextNode(text);
5845
+ this.parent.insertBefore(_parchment2.default.create(textNode), this.next);
5846
+ range = {
5847
+ startNode: textNode,
5848
+ startOffset: text.length
5849
+ };
5850
+ }
5851
+ }
5852
+ node.data = GUARD_TEXT;
5853
+ return range;
5780
5854
  }
5781
- };
5782
- }
5855
+ }, {
5856
+ key: 'update',
5857
+ value: function update(mutations, context) {
5858
+ var _this2 = this;
5783
5859
 
5784
- function makeFormatHandler(format) {
5785
- return {
5786
- key: format[0].toUpperCase(),
5787
- shortKey: true,
5788
- handler: function handler(range, context) {
5789
- this.quill.format(format, !context.format[format], _quill2.default.sources.USER);
5860
+ mutations.forEach(function (mutation) {
5861
+ if (mutation.type === 'characterData' && (mutation.target === _this2.leftGuard || mutation.target === _this2.rightGuard)) {
5862
+ var range = _this2.restore(mutation.target);
5863
+ if (range) context.range = range;
5864
+ }
5865
+ });
5790
5866
  }
5791
- };
5792
- }
5867
+ }]);
5793
5868
 
5794
- function normalize(binding) {
5795
- if (typeof binding === 'string' || typeof binding === 'number') {
5796
- return normalize({ key: binding });
5797
- }
5798
- if ((typeof binding === 'undefined' ? 'undefined' : _typeof(binding)) === 'object') {
5799
- binding = (0, _clone2.default)(binding, false);
5800
- }
5801
- if (typeof binding.key === 'string') {
5802
- if (Keyboard.keys[binding.key.toUpperCase()] != null) {
5803
- binding.key = Keyboard.keys[binding.key.toUpperCase()];
5804
- } else if (binding.key.length === 1) {
5805
- binding.key = binding.key.toUpperCase().charCodeAt(0);
5806
- } else {
5807
- return null;
5808
- }
5809
- }
5810
- if (binding.shortKey) {
5811
- binding[SHORTKEY] = binding.shortKey;
5812
- delete binding.shortKey;
5813
- }
5814
- return binding;
5815
- }
5869
+ return Embed;
5870
+ }(_parchment2.default.Embed);
5816
5871
 
5817
- exports.default = Keyboard;
5818
- exports.SHORTKEY = SHORTKEY;
5872
+ exports.default = Embed;
5819
5873
 
5820
5874
  /***/ }),
5821
5875
  /* 36 */
@@ -6065,13 +6119,13 @@ var History = function (_Module) {
6065
6119
  value: function change(source, dest) {
6066
6120
  if (this.stack[source].length === 0) return;
6067
6121
  var delta = this.stack[source].pop();
6122
+ this.stack[dest].push(delta);
6068
6123
  this.lastRecorded = 0;
6069
6124
  this.ignoreChange = true;
6070
6125
  this.quill.updateContents(delta[source], _quill2.default.sources.USER);
6071
6126
  this.ignoreChange = false;
6072
6127
  var index = getLastChangeIndex(delta[source]);
6073
6128
  this.quill.setSelection(index);
6074
- this.stack[dest].push(delta);
6075
6129
  }
6076
6130
  }, {
6077
6131
  key: 'clear',
@@ -6177,7 +6231,7 @@ exports.getLastChangeIndex = getLastChangeIndex;
6177
6231
  Object.defineProperty(exports, "__esModule", { value: true });
6178
6232
  var LinkedList = /** @class */ (function () {
6179
6233
  function LinkedList() {
6180
- this.head = this.tail = undefined;
6234
+ this.head = this.tail = null;
6181
6235
  this.length = 0;
6182
6236
  }
6183
6237
  LinkedList.prototype.append = function () {
@@ -6185,20 +6239,22 @@ var LinkedList = /** @class */ (function () {
6185
6239
  for (var _i = 0; _i < arguments.length; _i++) {
6186
6240
  nodes[_i] = arguments[_i];
6187
6241
  }
6188
- this.insertBefore(nodes[0], undefined);
6242
+ this.insertBefore(nodes[0], null);
6189
6243
  if (nodes.length > 1) {
6190
6244
  this.append.apply(this, nodes.slice(1));
6191
6245
  }
6192
6246
  };
6193
6247
  LinkedList.prototype.contains = function (node) {
6194
6248
  var cur, next = this.iterator();
6195
- while (cur = next()) {
6249
+ while ((cur = next())) {
6196
6250
  if (cur === node)
6197
6251
  return true;
6198
6252
  }
6199
6253
  return false;
6200
6254
  };
6201
6255
  LinkedList.prototype.insertBefore = function (node, refNode) {
6256
+ if (!node)
6257
+ return;
6202
6258
  node.next = refNode;
6203
6259
  if (refNode != null) {
6204
6260
  node.prev = refNode.prev;
@@ -6216,7 +6272,7 @@ var LinkedList = /** @class */ (function () {
6216
6272
  this.tail = node;
6217
6273
  }
6218
6274
  else {
6219
- node.prev = undefined;
6275
+ node.prev = null;
6220
6276
  this.head = this.tail = node;
6221
6277
  }
6222
6278
  this.length += 1;
@@ -6257,9 +6313,10 @@ var LinkedList = /** @class */ (function () {
6257
6313
  LinkedList.prototype.find = function (index, inclusive) {
6258
6314
  if (inclusive === void 0) { inclusive = false; }
6259
6315
  var cur, next = this.iterator();
6260
- while (cur = next()) {
6316
+ while ((cur = next())) {
6261
6317
  var length = cur.length();
6262
- if (index < length || (inclusive && index === length && (cur.next == null || cur.next.length() !== 0))) {
6318
+ if (index < length ||
6319
+ (inclusive && index === length && (cur.next == null || cur.next.length() !== 0))) {
6263
6320
  return [cur, index];
6264
6321
  }
6265
6322
  index -= length;
@@ -6268,7 +6325,7 @@ var LinkedList = /** @class */ (function () {
6268
6325
  };
6269
6326
  LinkedList.prototype.forEach = function (callback) {
6270
6327
  var cur, next = this.iterator();
6271
- while (cur = next()) {
6328
+ while ((cur = next())) {
6272
6329
  callback(cur);
6273
6330
  }
6274
6331
  };
@@ -6296,7 +6353,7 @@ var LinkedList = /** @class */ (function () {
6296
6353
  };
6297
6354
  LinkedList.prototype.reduce = function (callback, memo) {
6298
6355
  var cur, next = this.iterator();
6299
- while (cur = next()) {
6356
+ while ((cur = next())) {
6300
6357
  memo = callback(memo, cur);
6301
6358
  }
6302
6359
  return memo;
@@ -6330,18 +6387,19 @@ var OBSERVER_CONFIG = {
6330
6387
  characterData: true,
6331
6388
  characterDataOldValue: true,
6332
6389
  childList: true,
6333
- subtree: true
6390
+ subtree: true,
6334
6391
  };
6335
6392
  var MAX_OPTIMIZE_ITERATIONS = 100;
6336
6393
  var ScrollBlot = /** @class */ (function (_super) {
6337
6394
  __extends(ScrollBlot, _super);
6338
6395
  function ScrollBlot(node) {
6339
6396
  var _this = _super.call(this, node) || this;
6340
- _this.parent = null;
6397
+ _this.scroll = _this;
6341
6398
  _this.observer = new MutationObserver(function (mutations) {
6342
6399
  _this.update(mutations);
6343
6400
  });
6344
6401
  _this.observer.observe(_this.domNode, OBSERVER_CONFIG);
6402
+ _this.attach();
6345
6403
  return _this;
6346
6404
  }
6347
6405
  ScrollBlot.prototype.detach = function () {
@@ -6385,14 +6443,21 @@ var ScrollBlot = /** @class */ (function (_super) {
6385
6443
  return;
6386
6444
  if (blot.domNode.parentNode == null)
6387
6445
  return;
6446
+ // @ts-ignore
6388
6447
  if (blot.domNode[Registry.DATA_KEY].mutations == null) {
6448
+ // @ts-ignore
6389
6449
  blot.domNode[Registry.DATA_KEY].mutations = [];
6390
6450
  }
6391
6451
  if (markParent)
6392
6452
  mark(blot.parent);
6393
6453
  };
6394
6454
  var optimize = function (blot) {
6395
- if (blot.domNode[Registry.DATA_KEY] == null || blot.domNode[Registry.DATA_KEY].mutations == null) {
6455
+ // Post-order traversal
6456
+ if (
6457
+ // @ts-ignore
6458
+ blot.domNode[Registry.DATA_KEY] == null ||
6459
+ // @ts-ignore
6460
+ blot.domNode[Registry.DATA_KEY].mutations == null) {
6396
6461
  return;
6397
6462
  }
6398
6463
  if (blot instanceof container_1.default) {
@@ -6440,24 +6505,35 @@ var ScrollBlot = /** @class */ (function (_super) {
6440
6505
  if (context === void 0) { context = {}; }
6441
6506
  mutations = mutations || this.observer.takeRecords();
6442
6507
  // TODO use WeakMap
6443
- mutations.map(function (mutation) {
6508
+ mutations
6509
+ .map(function (mutation) {
6444
6510
  var blot = Registry.find(mutation.target, true);
6445
6511
  if (blot == null)
6446
- return;
6512
+ return null;
6513
+ // @ts-ignore
6447
6514
  if (blot.domNode[Registry.DATA_KEY].mutations == null) {
6515
+ // @ts-ignore
6448
6516
  blot.domNode[Registry.DATA_KEY].mutations = [mutation];
6449
6517
  return blot;
6450
6518
  }
6451
6519
  else {
6520
+ // @ts-ignore
6452
6521
  blot.domNode[Registry.DATA_KEY].mutations.push(mutation);
6453
6522
  return null;
6454
6523
  }
6455
- }).forEach(function (blot) {
6456
- if (blot == null || blot === _this || blot.domNode[Registry.DATA_KEY] == null)
6524
+ })
6525
+ .forEach(function (blot) {
6526
+ if (blot == null ||
6527
+ blot === _this ||
6528
+ //@ts-ignore
6529
+ blot.domNode[Registry.DATA_KEY] == null)
6457
6530
  return;
6531
+ // @ts-ignore
6458
6532
  blot.update(blot.domNode[Registry.DATA_KEY].mutations || [], context);
6459
6533
  });
6534
+ // @ts-ignore
6460
6535
  if (this.domNode[Registry.DATA_KEY].mutations != null) {
6536
+ // @ts-ignore
6461
6537
  _super.prototype.update.call(this, this.domNode[Registry.DATA_KEY].mutations, context);
6462
6538
  }
6463
6539
  this.optimize(mutations, context);
@@ -6494,7 +6570,9 @@ var Registry = __webpack_require__(1);
6494
6570
  function isEqual(obj1, obj2) {
6495
6571
  if (Object.keys(obj1).length !== Object.keys(obj2).length)
6496
6572
  return false;
6573
+ // @ts-ignore
6497
6574
  for (var prop in obj1) {
6575
+ // @ts-ignore
6498
6576
  if (obj1[prop] !== obj2[prop])
6499
6577
  return false;
6500
6578
  }
@@ -6616,7 +6694,7 @@ var BlockBlot = /** @class */ (function (_super) {
6616
6694
  };
6617
6695
  BlockBlot.prototype.update = function (mutations, context) {
6618
6696
  if (navigator.userAgent.match(/Trident/)) {
6619
- this.attach();
6697
+ this.build();
6620
6698
  }
6621
6699
  else {
6622
6700
  _super.prototype.update.call(this, mutations, context);
@@ -6709,8 +6787,9 @@ var TextBlot = /** @class */ (function (_super) {
6709
6787
  };
6710
6788
  TextBlot.value = function (domNode) {
6711
6789
  var text = domNode.data;
6712
- if (text["normalize"])
6713
- text = text["normalize"]();
6790
+ // @ts-ignore
6791
+ if (text['normalize'])
6792
+ text = text['normalize']();
6714
6793
  return text;
6715
6794
  };
6716
6795
  TextBlot.prototype.deleteAt = function (index, length) {
@@ -6939,6 +7018,7 @@ function diff_main(text1, text2, cursor_pos) {
6939
7018
  if (cursor_pos != null) {
6940
7019
  diffs = fix_cursor(diffs, cursor_pos);
6941
7020
  }
7021
+ diffs = fix_emoji(diffs);
6942
7022
  return diffs;
6943
7023
  };
6944
7024
 
@@ -7528,7 +7608,46 @@ function fix_cursor (diffs, cursor_pos) {
7528
7608
  return diffs;
7529
7609
  }
7530
7610
  }
7611
+ }
7612
+
7613
+ /*
7614
+ * Check diff did not split surrogate pairs.
7615
+ * Ex. [0, '\uD83D'], [-1, '\uDC36'], [1, '\uDC2F'] -> [-1, '\uD83D\uDC36'], [1, '\uD83D\uDC2F']
7616
+ * '\uD83D\uDC36' === '🐶', '\uD83D\uDC2F' === '🐯'
7617
+ *
7618
+ * @param {Array} diffs Array of diff tuples
7619
+ * @return {Array} Array of diff tuples
7620
+ */
7621
+ function fix_emoji (diffs) {
7622
+ var compact = false;
7623
+ var starts_with_pair_end = function(str) {
7624
+ return str.charCodeAt(0) >= 0xDC00 && str.charCodeAt(0) <= 0xDFFF;
7625
+ }
7626
+ var ends_with_pair_start = function(str) {
7627
+ return str.charCodeAt(str.length-1) >= 0xD800 && str.charCodeAt(str.length-1) <= 0xDBFF;
7628
+ }
7629
+ for (var i = 2; i < diffs.length; i += 1) {
7630
+ if (diffs[i-2][0] === DIFF_EQUAL && ends_with_pair_start(diffs[i-2][1]) &&
7631
+ diffs[i-1][0] === DIFF_DELETE && starts_with_pair_end(diffs[i-1][1]) &&
7632
+ diffs[i][0] === DIFF_INSERT && starts_with_pair_end(diffs[i][1])) {
7633
+ compact = true;
7634
+
7635
+ diffs[i-1][1] = diffs[i-2][1].slice(-1) + diffs[i-1][1];
7636
+ diffs[i][1] = diffs[i-2][1].slice(-1) + diffs[i][1];
7531
7637
 
7638
+ diffs[i-2][1] = diffs[i-2][1].slice(0, -1);
7639
+ }
7640
+ }
7641
+ if (!compact) {
7642
+ return diffs;
7643
+ }
7644
+ var fixed_diffs = [];
7645
+ for (var i = 0; i < diffs.length; i += 1) {
7646
+ if (diffs[i][1].length > 0) {
7647
+ fixed_diffs.push(diffs[i]);
7648
+ }
7649
+ }
7650
+ return fixed_diffs;
7532
7651
  }
7533
7652
 
7534
7653
  /*
@@ -8060,10 +8179,12 @@ var Clipboard = function (_Module) {
8060
8179
  var source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _quill2.default.sources.API;
8061
8180
 
8062
8181
  if (typeof index === 'string') {
8063
- return this.quill.setContents(this.convert(index), html);
8182
+ this.quill.setContents(this.convert(index), html);
8183
+ this.quill.setSelection(0, _quill2.default.sources.SILENT);
8064
8184
  } else {
8065
8185
  var paste = this.convert(html);
8066
- return this.quill.updateContents(new _quillDelta2.default().retain(index).concat(paste), source);
8186
+ this.quill.updateContents(new _quillDelta2.default().retain(index).concat(paste), source);
8187
+ this.quill.setSelection(index + paste.length(), _quill2.default.sources.SILENT);
8067
8188
  }
8068
8189
  }
8069
8190
  }, {
@@ -8204,11 +8325,11 @@ function matchAttributor(node, delta) {
8204
8325
  if (formats[attr.attrName]) return;
8205
8326
  }
8206
8327
  attr = ATTRIBUTE_ATTRIBUTORS[name];
8207
- if (attr != null && attr.attrName === name) {
8328
+ if (attr != null && (attr.attrName === name || attr.keyName === name)) {
8208
8329
  formats[attr.attrName] = attr.value(node) || undefined;
8209
8330
  }
8210
8331
  attr = STYLE_ATTRIBUTORS[name];
8211
- if (attr != null && attr.attrName === name) {
8332
+ if (attr != null && (attr.attrName === name || attr.keyName === name)) {
8212
8333
  attr = STYLE_ATTRIBUTORS[name];
8213
8334
  formats[attr.attrName] = attr.value(node) || undefined;
8214
8335
  }
@@ -8397,5 +8518,5 @@ module.exports = __webpack_require__(29);
8397
8518
 
8398
8519
 
8399
8520
  /***/ })
8400
- /******/ ]);
8521
+ /******/ ])["default"];
8401
8522
  });