activeadmin_quill_editor 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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);
4493
-
4494
- Cursor.blotName = 'cursor';
4495
- Cursor.className = 'ql-cursor';
4496
- Cursor.tagName = 'span';
4497
- Cursor.CONTENTS = '\uFEFF'; // Zero width no break space
4498
-
4499
-
4500
- exports.default = Cursor;
4501
-
4502
- /***/ }),
4503
- /* 24 */
4504
- /***/ (function(module, exports, __webpack_require__) {
4505
-
4506
- "use strict";
4507
-
4556
+ return Keyboard;
4557
+ }(_module2.default);
4508
4558
 
4509
- Object.defineProperty(exports, "__esModule", {
4510
- value: true
4511
- });
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
+ };
4512
4570
 
4513
- var _parchment = __webpack_require__(0);
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];
4514
4654
 
4515
- var _parchment2 = _interopRequireDefault(_parchment);
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];
4516
4672
 
4517
- var _block = __webpack_require__(4);
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;
4518
4686
 
4519
- var _block2 = _interopRequireDefault(_block);
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];
4520
4691
 
4521
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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];
4522
4726
 
4523
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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
+ };
4524
4737
 
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; }
4738
+ function makeEmbedArrowHandler(key, shiftKey) {
4739
+ var _ref3;
4526
4740
 
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; }
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
+ }
4528
4751
 
4529
- var Container = function (_Parchment$Container) {
4530
- _inherits(Container, _Parchment$Container);
4752
+ var _quill$getLeaf3 = this.quill.getLeaf(index),
4753
+ _quill$getLeaf4 = _slicedToArray(_quill$getLeaf3, 1),
4754
+ leaf = _quill$getLeaf4[0];
4531
4755
 
4532
- function Container() {
4533
- _classCallCheck(this, Container);
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
+ }
4534
4773
 
4535
- return _possibleConstructorReturn(this, (Container.__proto__ || Object.getPrototypeOf(Container)).apply(this, arguments));
4774
+ function handleBackspace(range, context) {
4775
+ if (range.index === 0 || this.quill.getLength() <= 1) return;
4776
+
4777
+ var _quill$getLine11 = this.quill.getLine(range.index),
4778
+ _quill$getLine12 = _slicedToArray(_quill$getLine11, 1),
4779
+ line = _quill$getLine12[0];
4780
+
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];
4786
+
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);
4536
4798
  }
4799
+ this.quill.focus();
4800
+ }
4537
4801
 
4538
- return Container;
4539
- }(_parchment2.default.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;
4540
4808
 
4541
- Container.allowedChildren = [_block2.default, _block.BlockEmbed, Container];
4809
+ var _quill$getLine15 = this.quill.getLine(range.index),
4810
+ _quill$getLine16 = _slicedToArray(_quill$getLine15, 1),
4811
+ line = _quill$getLine16[0];
4542
4812
 
4543
- exports.default = Container;
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
+ }
4944
+ }
4945
+ if (binding.shortKey) {
4946
+ binding[SHORTKEY] = binding.shortKey;
4947
+ delete binding.shortKey;
4948
+ }
4949
+ return binding;
4950
+ }
4951
+
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, [{
4600
- key: 'index',
4601
- 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);
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);
4605
5015
  }
4606
5016
  }, {
4607
- 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) {
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
+ }, {
5036
+ key: 'index',
5037
+ value: function index(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;
5056
+ }
5057
+ }, {
5058
+ key: 'restore',
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 */
@@ -4824,6 +5339,10 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
4824
5339
 
4825
5340
  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; }; }();
4826
5341
 
5342
+ var _keyboard = __webpack_require__(23);
5343
+
5344
+ var _keyboard2 = _interopRequireDefault(_keyboard);
5345
+
4827
5346
  var _dropdown = __webpack_require__(107);
4828
5347
 
4829
5348
  var _dropdown2 = _interopRequireDefault(_dropdown);
@@ -4832,6 +5351,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
4832
5351
 
4833
5352
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4834
5353
 
5354
+ var optionsCounter = 0;
5355
+
5356
+ function toggleAriaAttribute(element, attribute) {
5357
+ element.setAttribute(attribute, !(element.getAttribute(attribute) === 'true'));
5358
+ }
5359
+
4835
5360
  var Picker = function () {
4836
5361
  function Picker(select) {
4837
5362
  var _this = this;
@@ -4843,18 +5368,45 @@ var Picker = function () {
4843
5368
  this.buildPicker();
4844
5369
  this.select.style.display = 'none';
4845
5370
  this.select.parentNode.insertBefore(this.container, this.select);
5371
+
4846
5372
  this.label.addEventListener('mousedown', function () {
4847
- _this.container.classList.toggle('ql-expanded');
5373
+ _this.togglePicker();
5374
+ });
5375
+ this.label.addEventListener('keydown', function (event) {
5376
+ switch (event.keyCode) {
5377
+ // Allows the "Enter" key to open the picker
5378
+ case _keyboard2.default.keys.ENTER:
5379
+ _this.togglePicker();
5380
+ break;
5381
+
5382
+ // Allows the "Escape" key to close the picker
5383
+ case _keyboard2.default.keys.ESCAPE:
5384
+ _this.escape();
5385
+ event.preventDefault();
5386
+ break;
5387
+ default:
5388
+ }
4848
5389
  });
4849
5390
  this.select.addEventListener('change', this.update.bind(this));
4850
5391
  }
4851
5392
 
4852
5393
  _createClass(Picker, [{
5394
+ key: 'togglePicker',
5395
+ value: function togglePicker() {
5396
+ this.container.classList.toggle('ql-expanded');
5397
+ // Toggle aria-expanded and aria-hidden to make the picker accessible
5398
+ toggleAriaAttribute(this.label, 'aria-expanded');
5399
+ toggleAriaAttribute(this.options, 'aria-hidden');
5400
+ }
5401
+ }, {
4853
5402
  key: 'buildItem',
4854
5403
  value: function buildItem(option) {
4855
5404
  var _this2 = this;
4856
5405
 
4857
5406
  var item = document.createElement('span');
5407
+ item.tabIndex = '0';
5408
+ item.setAttribute('role', 'button');
5409
+
4858
5410
  item.classList.add('ql-picker-item');
4859
5411
  if (option.hasAttribute('value')) {
4860
5412
  item.setAttribute('data-value', option.getAttribute('value'));
@@ -4865,6 +5417,23 @@ var Picker = function () {
4865
5417
  item.addEventListener('click', function () {
4866
5418
  _this2.selectItem(item, true);
4867
5419
  });
5420
+ item.addEventListener('keydown', function (event) {
5421
+ switch (event.keyCode) {
5422
+ // Allows the "Enter" key to select an item
5423
+ case _keyboard2.default.keys.ENTER:
5424
+ _this2.selectItem(item, true);
5425
+ event.preventDefault();
5426
+ break;
5427
+
5428
+ // Allows the "Escape" key to close the picker
5429
+ case _keyboard2.default.keys.ESCAPE:
5430
+ _this2.escape();
5431
+ event.preventDefault();
5432
+ break;
5433
+ default:
5434
+ }
5435
+ });
5436
+
4868
5437
  return item;
4869
5438
  }
4870
5439
  }, {
@@ -4873,6 +5442,9 @@ var Picker = function () {
4873
5442
  var label = document.createElement('span');
4874
5443
  label.classList.add('ql-picker-label');
4875
5444
  label.innerHTML = _dropdown2.default;
5445
+ label.tabIndex = '0';
5446
+ label.setAttribute('role', 'button');
5447
+ label.setAttribute('aria-expanded', 'false');
4876
5448
  this.container.appendChild(label);
4877
5449
  return label;
4878
5450
  }
@@ -4883,6 +5455,18 @@ var Picker = function () {
4883
5455
 
4884
5456
  var options = document.createElement('span');
4885
5457
  options.classList.add('ql-picker-options');
5458
+
5459
+ // Don't want screen readers to read this until options are visible
5460
+ options.setAttribute('aria-hidden', 'true');
5461
+ options.tabIndex = '-1';
5462
+
5463
+ // Need a unique id for aria-controls
5464
+ options.id = 'ql-picker-options-' + optionsCounter;
5465
+ optionsCounter += 1;
5466
+ this.label.setAttribute('aria-controls', options.id);
5467
+
5468
+ this.options = options;
5469
+
4886
5470
  [].slice.call(this.select.options).forEach(function (option) {
4887
5471
  var item = _this3.buildItem(option);
4888
5472
  options.appendChild(item);
@@ -4904,10 +5488,25 @@ var Picker = function () {
4904
5488
  this.label = this.buildLabel();
4905
5489
  this.buildOptions();
4906
5490
  }
5491
+ }, {
5492
+ key: 'escape',
5493
+ value: function escape() {
5494
+ var _this5 = this;
5495
+
5496
+ // Close menu and return focus to trigger label
5497
+ this.close();
5498
+ // Need setTimeout for accessibility to ensure that the browser executes
5499
+ // focus on the next process thread and after any DOM content changes
5500
+ setTimeout(function () {
5501
+ return _this5.label.focus();
5502
+ }, 1);
5503
+ }
4907
5504
  }, {
4908
5505
  key: 'close',
4909
5506
  value: function close() {
4910
5507
  this.container.classList.remove('ql-expanded');
5508
+ this.label.setAttribute('aria-expanded', 'false');
5509
+ this.options.setAttribute('aria-hidden', 'true');
4911
5510
  }
4912
5511
  }, {
4913
5512
  key: 'selectItem',
@@ -4972,6 +5571,10 @@ exports.default = Picker;
4972
5571
  "use strict";
4973
5572
 
4974
5573
 
5574
+ Object.defineProperty(exports, "__esModule", {
5575
+ value: true
5576
+ });
5577
+
4975
5578
  var _parchment = __webpack_require__(0);
4976
5579
 
4977
5580
  var _parchment2 = _interopRequireDefault(_parchment);
@@ -4988,15 +5591,15 @@ var _break = __webpack_require__(16);
4988
5591
 
4989
5592
  var _break2 = _interopRequireDefault(_break);
4990
5593
 
4991
- var _container = __webpack_require__(24);
5594
+ var _container = __webpack_require__(25);
4992
5595
 
4993
5596
  var _container2 = _interopRequireDefault(_container);
4994
5597
 
4995
- var _cursor = __webpack_require__(23);
5598
+ var _cursor = __webpack_require__(24);
4996
5599
 
4997
5600
  var _cursor2 = _interopRequireDefault(_cursor);
4998
5601
 
4999
- var _embed = __webpack_require__(25);
5602
+ var _embed = __webpack_require__(35);
5000
5603
 
5001
5604
  var _embed2 = _interopRequireDefault(_embed);
5002
5605
 
@@ -5020,7 +5623,7 @@ var _history = __webpack_require__(42);
5020
5623
 
5021
5624
  var _history2 = _interopRequireDefault(_history);
5022
5625
 
5023
- var _keyboard = __webpack_require__(35);
5626
+ var _keyboard = __webpack_require__(23);
5024
5627
 
5025
5628
  var _keyboard2 = _interopRequireDefault(_keyboard);
5026
5629
 
@@ -5044,7 +5647,7 @@ _quill2.default.register({
5044
5647
 
5045
5648
  _parchment2.default.register(_block2.default, _break2.default, _cursor2.default, _inline2.default, _scroll2.default, _text2.default);
5046
5649
 
5047
- module.exports = _quill2.default;
5650
+ exports.default = _quill2.default;
5048
5651
 
5049
5652
  /***/ }),
5050
5653
  /* 30 */
@@ -5057,7 +5660,8 @@ var Registry = __webpack_require__(1);
5057
5660
  var ShadowBlot = /** @class */ (function () {
5058
5661
  function ShadowBlot(domNode) {
5059
5662
  this.domNode = domNode;
5060
- this.attach();
5663
+ // @ts-ignore
5664
+ this.domNode[Registry.DATA_KEY] = { blot: this };
5061
5665
  }
5062
5666
  Object.defineProperty(ShadowBlot.prototype, "statics", {
5063
5667
  // Hack for accessing inherited static methods
@@ -5098,7 +5702,9 @@ var ShadowBlot = /** @class */ (function () {
5098
5702
  return node;
5099
5703
  };
5100
5704
  ShadowBlot.prototype.attach = function () {
5101
- this.domNode[Registry.DATA_KEY] = { blot: this };
5705
+ if (this.parent != null) {
5706
+ this.scroll = this.parent.scroll;
5707
+ }
5102
5708
  };
5103
5709
  ShadowBlot.prototype.clone = function () {
5104
5710
  var domNode = this.domNode.cloneNode(false);
@@ -5107,6 +5713,7 @@ var ShadowBlot = /** @class */ (function () {
5107
5713
  ShadowBlot.prototype.detach = function () {
5108
5714
  if (this.parent != null)
5109
5715
  this.parent.removeChild(this);
5716
+ // @ts-ignore
5110
5717
  delete this.domNode[Registry.DATA_KEY];
5111
5718
  };
5112
5719
  ShadowBlot.prototype.deleteAt = function (index, length) {
@@ -5125,22 +5732,26 @@ var ShadowBlot = /** @class */ (function () {
5125
5732
  }
5126
5733
  };
5127
5734
  ShadowBlot.prototype.insertAt = function (index, value, def) {
5128
- var blot = (def == null) ? Registry.create('text', value) : Registry.create(value, def);
5735
+ var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
5129
5736
  var ref = this.split(index);
5130
5737
  this.parent.insertBefore(blot, ref);
5131
5738
  };
5132
5739
  ShadowBlot.prototype.insertInto = function (parentBlot, refBlot) {
5740
+ if (refBlot === void 0) { refBlot = null; }
5133
5741
  if (this.parent != null) {
5134
5742
  this.parent.children.remove(this);
5135
5743
  }
5744
+ var refDomNode = null;
5136
5745
  parentBlot.children.insertBefore(this, refBlot);
5137
5746
  if (refBlot != null) {
5138
- var refDomNode = refBlot.domNode;
5747
+ refDomNode = refBlot.domNode;
5139
5748
  }
5140
- if (this.next == null || this.domNode.nextSibling != refDomNode) {
5141
- parentBlot.domNode.insertBefore(this.domNode, (typeof refDomNode !== 'undefined') ? refDomNode : null);
5749
+ if (this.domNode.parentNode != parentBlot.domNode ||
5750
+ this.domNode.nextSibling != refDomNode) {
5751
+ parentBlot.domNode.insertBefore(this.domNode, refDomNode);
5142
5752
  }
5143
5753
  this.parent = parentBlot;
5754
+ this.attach();
5144
5755
  };
5145
5756
  ShadowBlot.prototype.isolate = function (index, length) {
5146
5757
  var target = this.split(index);
@@ -5150,7 +5761,6 @@ var ShadowBlot = /** @class */ (function () {
5150
5761
  ShadowBlot.prototype.length = function () {
5151
5762
  return 1;
5152
5763
  };
5153
- ;
5154
5764
  ShadowBlot.prototype.offset = function (root) {
5155
5765
  if (root === void 0) { root = this.parent; }
5156
5766
  if (this.parent == null || this == root)
@@ -5159,7 +5769,9 @@ var ShadowBlot = /** @class */ (function () {
5159
5769
  };
5160
5770
  ShadowBlot.prototype.optimize = function (context) {
5161
5771
  // TODO clean up once we use WeakMap
5772
+ // @ts-ignore
5162
5773
  if (this.domNode[Registry.DATA_KEY] != null) {
5774
+ // @ts-ignore
5163
5775
  delete this.domNode[Registry.DATA_KEY].mutations;
5164
5776
  }
5165
5777
  };
@@ -5218,6 +5830,7 @@ var AttributorStore = /** @class */ (function () {
5218
5830
  this.build();
5219
5831
  }
5220
5832
  AttributorStore.prototype.attribute = function (attribute, value) {
5833
+ // verb
5221
5834
  if (value) {
5222
5835
  if (attribute.add(this.domNode, value)) {
5223
5836
  if (attribute.value(this.domNode) != null) {
@@ -5239,7 +5852,10 @@ var AttributorStore = /** @class */ (function () {
5239
5852
  var attributes = attributor_1.default.keys(this.domNode);
5240
5853
  var classes = class_1.default.keys(this.domNode);
5241
5854
  var styles = style_1.default.keys(this.domNode);
5242
- attributes.concat(classes).concat(styles).forEach(function (name) {
5855
+ attributes
5856
+ .concat(classes)
5857
+ .concat(styles)
5858
+ .forEach(function (name) {
5243
5859
  var attr = Registry.query(name, Registry.Scope.ATTRIBUTE);
5244
5860
  if (attr instanceof attributor_1.default) {
5245
5861
  _this.attributes[attr.attrName] = attr;
@@ -5304,7 +5920,10 @@ var ClassAttributor = /** @class */ (function (_super) {
5304
5920
  }
5305
5921
  ClassAttributor.keys = function (node) {
5306
5922
  return (node.getAttribute('class') || '').split(/\s+/).map(function (name) {
5307
- return name.split('-').slice(0, -1).join('-');
5923
+ return name
5924
+ .split('-')
5925
+ .slice(0, -1)
5926
+ .join('-');
5308
5927
  });
5309
5928
  };
5310
5929
  ClassAttributor.prototype.add = function (node, value) {
@@ -5316,743 +5935,262 @@ var ClassAttributor = /** @class */ (function (_super) {
5316
5935
  };
5317
5936
  ClassAttributor.prototype.remove = function (node) {
5318
5937
  var matches = match(node, this.keyName);
5319
- matches.forEach(function (name) {
5320
- node.classList.remove(name);
5321
- });
5322
- if (node.classList.length === 0) {
5323
- node.removeAttribute('class');
5324
- }
5325
- };
5326
- ClassAttributor.prototype.value = function (node) {
5327
- var result = match(node, this.keyName)[0] || '';
5328
- var value = result.slice(this.keyName.length + 1); // +1 for hyphen
5329
- return this.canAdd(node, value) ? value : '';
5330
- };
5331
- return ClassAttributor;
5332
- }(attributor_1.default));
5333
- exports.default = ClassAttributor;
5334
-
5335
-
5336
- /***/ }),
5337
- /* 33 */
5338
- /***/ (function(module, exports, __webpack_require__) {
5339
-
5340
- "use strict";
5341
-
5342
- var __extends = (this && this.__extends) || (function () {
5343
- var extendStatics = Object.setPrototypeOf ||
5344
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5345
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5346
- return function (d, b) {
5347
- extendStatics(d, b);
5348
- function __() { this.constructor = d; }
5349
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5350
- };
5351
- })();
5352
- Object.defineProperty(exports, "__esModule", { value: true });
5353
- var attributor_1 = __webpack_require__(12);
5354
- function camelize(name) {
5355
- var parts = name.split('-');
5356
- var rest = parts.slice(1).map(function (part) {
5357
- return part[0].toUpperCase() + part.slice(1);
5358
- }).join('');
5359
- return parts[0] + rest;
5360
- }
5361
- var StyleAttributor = /** @class */ (function (_super) {
5362
- __extends(StyleAttributor, _super);
5363
- function StyleAttributor() {
5364
- return _super !== null && _super.apply(this, arguments) || this;
5365
- }
5366
- StyleAttributor.keys = function (node) {
5367
- return (node.getAttribute('style') || '').split(';').map(function (value) {
5368
- var arr = value.split(':');
5369
- return arr[0].trim();
5370
- });
5371
- };
5372
- StyleAttributor.prototype.add = function (node, value) {
5373
- if (!this.canAdd(node, value))
5374
- return false;
5375
- node.style[camelize(this.keyName)] = value;
5376
- return true;
5377
- };
5378
- StyleAttributor.prototype.remove = function (node) {
5379
- node.style[camelize(this.keyName)] = '';
5380
- if (!node.getAttribute('style')) {
5381
- node.removeAttribute('style');
5382
- }
5383
- };
5384
- StyleAttributor.prototype.value = function (node) {
5385
- var value = node.style[camelize(this.keyName)];
5386
- return this.canAdd(node, value) ? value : '';
5387
- };
5388
- return StyleAttributor;
5389
- }(attributor_1.default));
5390
- exports.default = StyleAttributor;
5391
-
5392
-
5393
- /***/ }),
5394
- /* 34 */
5395
- /***/ (function(module, exports, __webpack_require__) {
5396
-
5397
- "use strict";
5398
-
5399
-
5400
- Object.defineProperty(exports, "__esModule", {
5401
- value: true
5402
- });
5403
-
5404
- 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; }; }();
5405
-
5406
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5407
-
5408
- var Theme = function () {
5409
- function Theme(quill, options) {
5410
- _classCallCheck(this, Theme);
5411
-
5412
- this.quill = quill;
5413
- this.options = options;
5414
- this.modules = {};
5415
- }
5416
-
5417
- _createClass(Theme, [{
5418
- key: 'init',
5419
- value: function init() {
5420
- var _this = this;
5421
-
5422
- Object.keys(this.options.modules).forEach(function (name) {
5423
- if (_this.modules[name] == null) {
5424
- _this.addModule(name);
5425
- }
5426
- });
5427
- }
5428
- }, {
5429
- key: 'addModule',
5430
- value: function addModule(name) {
5431
- var moduleClass = this.quill.constructor.import('modules/' + name);
5432
- this.modules[name] = new moduleClass(this.quill, this.options.modules[name] || {});
5433
- return this.modules[name];
5434
- }
5435
- }]);
5436
-
5437
- return Theme;
5438
- }();
5439
-
5440
- Theme.DEFAULTS = {
5441
- modules: {}
5442
- };
5443
- Theme.themes = {
5444
- 'default': Theme
5445
- };
5446
-
5447
- exports.default = Theme;
5448
-
5449
- /***/ }),
5450
- /* 35 */
5451
- /***/ (function(module, exports, __webpack_require__) {
5452
-
5453
- "use strict";
5454
-
5455
-
5456
- Object.defineProperty(exports, "__esModule", {
5457
- value: true
5458
- });
5459
- exports.SHORTKEY = exports.default = undefined;
5460
-
5461
- 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; };
5462
-
5463
- 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"); } }; }();
5464
-
5465
- 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; }; }();
5466
-
5467
- var _clone = __webpack_require__(21);
5468
-
5469
- var _clone2 = _interopRequireDefault(_clone);
5470
-
5471
- var _deepEqual = __webpack_require__(11);
5472
-
5473
- var _deepEqual2 = _interopRequireDefault(_deepEqual);
5474
-
5475
- var _extend = __webpack_require__(3);
5476
-
5477
- var _extend2 = _interopRequireDefault(_extend);
5478
-
5479
- var _quillDelta = __webpack_require__(2);
5480
-
5481
- var _quillDelta2 = _interopRequireDefault(_quillDelta);
5482
-
5483
- var _op = __webpack_require__(20);
5484
-
5485
- var _op2 = _interopRequireDefault(_op);
5486
-
5487
- var _parchment = __webpack_require__(0);
5488
-
5489
- var _parchment2 = _interopRequireDefault(_parchment);
5490
-
5491
- var _embed = __webpack_require__(25);
5492
-
5493
- var _embed2 = _interopRequireDefault(_embed);
5494
-
5495
- var _quill = __webpack_require__(5);
5496
-
5497
- var _quill2 = _interopRequireDefault(_quill);
5498
-
5499
- var _logger = __webpack_require__(10);
5500
-
5501
- var _logger2 = _interopRequireDefault(_logger);
5502
-
5503
- var _module = __webpack_require__(9);
5504
-
5505
- var _module2 = _interopRequireDefault(_module);
5506
-
5507
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5508
-
5509
- 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; }
5510
-
5511
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5512
-
5513
- 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; }
5514
-
5515
- 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; }
5516
-
5517
- var debug = (0, _logger2.default)('quill:keyboard');
5518
-
5519
- var SHORTKEY = /Mac/i.test(navigator.platform) ? 'metaKey' : 'ctrlKey';
5520
-
5521
- var Keyboard = function (_Module) {
5522
- _inherits(Keyboard, _Module);
5523
-
5524
- _createClass(Keyboard, null, [{
5525
- key: 'match',
5526
- value: function match(evt, binding) {
5527
- binding = normalize(binding);
5528
- if (['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].some(function (key) {
5529
- return !!binding[key] !== evt[key] && binding[key] !== null;
5530
- })) {
5531
- return false;
5532
- }
5533
- return binding.key === (evt.which || evt.keyCode);
5534
- }
5535
- }]);
5536
-
5537
- function Keyboard(quill, options) {
5538
- _classCallCheck(this, Keyboard);
5539
-
5540
- var _this = _possibleConstructorReturn(this, (Keyboard.__proto__ || Object.getPrototypeOf(Keyboard)).call(this, quill, options));
5541
-
5542
- _this.bindings = {};
5543
- Object.keys(_this.options.bindings).forEach(function (name) {
5544
- if (name === 'list autofill' && quill.scroll.whitelist != null && !quill.scroll.whitelist['list']) {
5545
- return;
5546
- }
5547
- if (_this.options.bindings[name]) {
5548
- _this.addBinding(_this.options.bindings[name]);
5549
- }
5550
- });
5551
- _this.addBinding({ key: Keyboard.keys.ENTER, shiftKey: null }, handleEnter);
5552
- _this.addBinding({ key: Keyboard.keys.ENTER, metaKey: null, ctrlKey: null, altKey: null }, function () {});
5553
- if (/Firefox/i.test(navigator.userAgent)) {
5554
- // Need to handle delete and backspace for Firefox in the general case #1171
5555
- _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true }, handleBackspace);
5556
- _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true }, handleDelete);
5557
- } else {
5558
- _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true, prefix: /^.?$/ }, handleBackspace);
5559
- _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true, suffix: /^.?$/ }, handleDelete);
5560
- }
5561
- _this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: false }, handleDeleteRange);
5562
- _this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: false }, handleDeleteRange);
5563
- _this.addBinding({ key: Keyboard.keys.BACKSPACE, altKey: null, ctrlKey: null, metaKey: null, shiftKey: null }, { collapsed: true, offset: 0 }, handleBackspace);
5564
- _this.listen();
5565
- return _this;
5566
- }
5567
-
5568
- _createClass(Keyboard, [{
5569
- key: 'addBinding',
5570
- value: function addBinding(key) {
5571
- var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5572
- var handler = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5573
-
5574
- var binding = normalize(key);
5575
- if (binding == null || binding.key == null) {
5576
- return debug.warn('Attempted to add invalid keyboard binding', binding);
5577
- }
5578
- if (typeof context === 'function') {
5579
- context = { handler: context };
5580
- }
5581
- if (typeof handler === 'function') {
5582
- handler = { handler: handler };
5583
- }
5584
- binding = (0, _extend2.default)(binding, context, handler);
5585
- this.bindings[binding.key] = this.bindings[binding.key] || [];
5586
- this.bindings[binding.key].push(binding);
5587
- }
5588
- }, {
5589
- key: 'listen',
5590
- value: function listen() {
5591
- var _this2 = this;
5592
-
5593
- this.quill.root.addEventListener('keydown', function (evt) {
5594
- if (evt.defaultPrevented) return;
5595
- var which = evt.which || evt.keyCode;
5596
- var bindings = (_this2.bindings[which] || []).filter(function (binding) {
5597
- return Keyboard.match(evt, binding);
5598
- });
5599
- if (bindings.length === 0) return;
5600
- var range = _this2.quill.getSelection();
5601
- if (range == null || !_this2.quill.hasFocus()) return;
5602
-
5603
- var _quill$getLine = _this2.quill.getLine(range.index),
5604
- _quill$getLine2 = _slicedToArray(_quill$getLine, 2),
5605
- line = _quill$getLine2[0],
5606
- offset = _quill$getLine2[1];
5607
-
5608
- var _quill$getLeaf = _this2.quill.getLeaf(range.index),
5609
- _quill$getLeaf2 = _slicedToArray(_quill$getLeaf, 2),
5610
- leafStart = _quill$getLeaf2[0],
5611
- offsetStart = _quill$getLeaf2[1];
5612
-
5613
- var _ref = range.length === 0 ? [leafStart, offsetStart] : _this2.quill.getLeaf(range.index + range.length),
5614
- _ref2 = _slicedToArray(_ref, 2),
5615
- leafEnd = _ref2[0],
5616
- offsetEnd = _ref2[1];
5617
-
5618
- var prefixText = leafStart instanceof _parchment2.default.Text ? leafStart.value().slice(0, offsetStart) : '';
5619
- var suffixText = leafEnd instanceof _parchment2.default.Text ? leafEnd.value().slice(offsetEnd) : '';
5620
- var curContext = {
5621
- collapsed: range.length === 0,
5622
- empty: range.length === 0 && line.length() <= 1,
5623
- format: _this2.quill.getFormat(range),
5624
- offset: offset,
5625
- prefix: prefixText,
5626
- suffix: suffixText
5627
- };
5628
- var prevented = bindings.some(function (binding) {
5629
- if (binding.collapsed != null && binding.collapsed !== curContext.collapsed) return false;
5630
- if (binding.empty != null && binding.empty !== curContext.empty) return false;
5631
- if (binding.offset != null && binding.offset !== curContext.offset) return false;
5632
- if (Array.isArray(binding.format)) {
5633
- // any format is present
5634
- if (binding.format.every(function (name) {
5635
- return curContext.format[name] == null;
5636
- })) {
5637
- return false;
5638
- }
5639
- } else if (_typeof(binding.format) === 'object') {
5640
- // all formats must match
5641
- if (!Object.keys(binding.format).every(function (name) {
5642
- if (binding.format[name] === true) return curContext.format[name] != null;
5643
- if (binding.format[name] === false) return curContext.format[name] == null;
5644
- return (0, _deepEqual2.default)(binding.format[name], curContext.format[name]);
5645
- })) {
5646
- return false;
5647
- }
5648
- }
5649
- if (binding.prefix != null && !binding.prefix.test(curContext.prefix)) return false;
5650
- if (binding.suffix != null && !binding.suffix.test(curContext.suffix)) return false;
5651
- return binding.handler.call(_this2, range, curContext) !== true;
5652
- });
5653
- if (prevented) {
5654
- evt.preventDefault();
5655
- }
5656
- });
5657
- }
5658
- }]);
5659
-
5660
- return Keyboard;
5661
- }(_module2.default);
5662
-
5663
- Keyboard.keys = {
5664
- BACKSPACE: 8,
5665
- TAB: 9,
5666
- ENTER: 13,
5667
- ESCAPE: 27,
5668
- LEFT: 37,
5669
- UP: 38,
5670
- RIGHT: 39,
5671
- DOWN: 40,
5672
- DELETE: 46
5673
- };
5674
-
5675
- Keyboard.DEFAULTS = {
5676
- bindings: {
5677
- 'bold': makeFormatHandler('bold'),
5678
- 'italic': makeFormatHandler('italic'),
5679
- 'underline': makeFormatHandler('underline'),
5680
- 'indent': {
5681
- // highlight tab or tab at beginning of list, indent or blockquote
5682
- key: Keyboard.keys.TAB,
5683
- format: ['blockquote', 'indent', 'list'],
5684
- handler: function handler(range, context) {
5685
- if (context.collapsed && context.offset !== 0) return true;
5686
- this.quill.format('indent', '+1', _quill2.default.sources.USER);
5687
- }
5688
- },
5689
- 'outdent': {
5690
- key: Keyboard.keys.TAB,
5691
- shiftKey: true,
5692
- format: ['blockquote', 'indent', 'list'],
5693
- // highlight tab or tab at beginning of list, indent or blockquote
5694
- handler: function handler(range, context) {
5695
- if (context.collapsed && context.offset !== 0) return true;
5696
- this.quill.format('indent', '-1', _quill2.default.sources.USER);
5697
- }
5698
- },
5699
- 'outdent backspace': {
5700
- key: Keyboard.keys.BACKSPACE,
5701
- collapsed: true,
5702
- shiftKey: null,
5703
- metaKey: null,
5704
- ctrlKey: null,
5705
- altKey: null,
5706
- format: ['indent', 'list'],
5707
- offset: 0,
5708
- handler: function handler(range, context) {
5709
- if (context.format.indent != null) {
5710
- this.quill.format('indent', '-1', _quill2.default.sources.USER);
5711
- } else if (context.format.list != null) {
5712
- this.quill.format('list', false, _quill2.default.sources.USER);
5713
- }
5714
- }
5715
- },
5716
- 'indent code-block': makeCodeBlockHandler(true),
5717
- 'outdent code-block': makeCodeBlockHandler(false),
5718
- 'remove tab': {
5719
- key: Keyboard.keys.TAB,
5720
- shiftKey: true,
5721
- collapsed: true,
5722
- prefix: /\t$/,
5723
- handler: function handler(range) {
5724
- this.quill.deleteText(range.index - 1, 1, _quill2.default.sources.USER);
5725
- }
5726
- },
5727
- 'tab': {
5728
- key: Keyboard.keys.TAB,
5729
- handler: function handler(range) {
5730
- this.quill.history.cutoff();
5731
- var delta = new _quillDelta2.default().retain(range.index).delete(range.length).insert('\t');
5732
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5733
- this.quill.history.cutoff();
5734
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5735
- }
5736
- },
5737
- 'list empty enter': {
5738
- key: Keyboard.keys.ENTER,
5739
- collapsed: true,
5740
- format: ['list'],
5741
- empty: true,
5742
- handler: function handler(range, context) {
5743
- this.quill.format('list', false, _quill2.default.sources.USER);
5744
- if (context.format.indent) {
5745
- this.quill.format('indent', false, _quill2.default.sources.USER);
5938
+ matches.forEach(function (name) {
5939
+ node.classList.remove(name);
5940
+ });
5941
+ if (node.classList.length === 0) {
5942
+ node.removeAttribute('class');
5746
5943
  }
5747
- }
5748
- },
5749
- 'checklist enter': {
5750
- key: Keyboard.keys.ENTER,
5751
- collapsed: true,
5752
- format: { list: 'checked' },
5753
- handler: function handler(range) {
5754
- var _quill$getLine3 = this.quill.getLine(range.index),
5755
- _quill$getLine4 = _slicedToArray(_quill$getLine3, 2),
5756
- line = _quill$getLine4[0],
5757
- offset = _quill$getLine4[1];
5944
+ };
5945
+ ClassAttributor.prototype.value = function (node) {
5946
+ var result = match(node, this.keyName)[0] || '';
5947
+ var value = result.slice(this.keyName.length + 1); // +1 for hyphen
5948
+ return this.canAdd(node, value) ? value : '';
5949
+ };
5950
+ return ClassAttributor;
5951
+ }(attributor_1.default));
5952
+ exports.default = ClassAttributor;
5758
5953
 
5759
- var delta = new _quillDelta2.default().retain(range.index).insert('\n', { list: 'checked' }).retain(line.length() - offset - 1).retain(1, { list: 'unchecked' });
5760
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5761
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5762
- this.quill.scrollIntoView();
5763
- }
5764
- },
5765
- 'header enter': {
5766
- key: Keyboard.keys.ENTER,
5767
- collapsed: true,
5768
- format: ['header'],
5769
- suffix: /^$/,
5770
- handler: function handler(range, context) {
5771
- var _quill$getLine5 = this.quill.getLine(range.index),
5772
- _quill$getLine6 = _slicedToArray(_quill$getLine5, 2),
5773
- line = _quill$getLine6[0],
5774
- offset = _quill$getLine6[1];
5775
5954
 
5776
- var delta = new _quillDelta2.default().retain(range.index).insert('\n', context.format).retain(line.length() - offset - 1).retain(1, { header: null });
5777
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5778
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5779
- this.quill.scrollIntoView();
5780
- }
5781
- },
5782
- 'list autofill': {
5783
- key: ' ',
5784
- collapsed: true,
5785
- format: { list: false },
5786
- prefix: /^\s*?(1\.|-|\[ ?\]|\[x\])$/,
5787
- handler: function handler(range, context) {
5788
- var length = context.prefix.length;
5955
+ /***/ }),
5956
+ /* 33 */
5957
+ /***/ (function(module, exports, __webpack_require__) {
5789
5958
 
5790
- var _quill$getLine7 = this.quill.getLine(range.index),
5791
- _quill$getLine8 = _slicedToArray(_quill$getLine7, 2),
5792
- line = _quill$getLine8[0],
5793
- offset = _quill$getLine8[1];
5959
+ "use strict";
5794
5960
 
5795
- if (offset > length) return true;
5796
- var value = void 0;
5797
- switch (context.prefix.trim()) {
5798
- case '[]':case '[ ]':
5799
- value = 'unchecked';
5800
- break;
5801
- case '[x]':
5802
- value = 'checked';
5803
- break;
5804
- case '-':
5805
- value = 'bullet';
5806
- break;
5807
- default:
5808
- value = 'ordered';
5961
+ var __extends = (this && this.__extends) || (function () {
5962
+ var extendStatics = Object.setPrototypeOf ||
5963
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5964
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5965
+ return function (d, b) {
5966
+ extendStatics(d, b);
5967
+ function __() { this.constructor = d; }
5968
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5969
+ };
5970
+ })();
5971
+ Object.defineProperty(exports, "__esModule", { value: true });
5972
+ var attributor_1 = __webpack_require__(12);
5973
+ function camelize(name) {
5974
+ var parts = name.split('-');
5975
+ var rest = parts
5976
+ .slice(1)
5977
+ .map(function (part) {
5978
+ return part[0].toUpperCase() + part.slice(1);
5979
+ })
5980
+ .join('');
5981
+ return parts[0] + rest;
5982
+ }
5983
+ var StyleAttributor = /** @class */ (function (_super) {
5984
+ __extends(StyleAttributor, _super);
5985
+ function StyleAttributor() {
5986
+ return _super !== null && _super.apply(this, arguments) || this;
5987
+ }
5988
+ StyleAttributor.keys = function (node) {
5989
+ return (node.getAttribute('style') || '').split(';').map(function (value) {
5990
+ var arr = value.split(':');
5991
+ return arr[0].trim();
5992
+ });
5993
+ };
5994
+ StyleAttributor.prototype.add = function (node, value) {
5995
+ if (!this.canAdd(node, value))
5996
+ return false;
5997
+ // @ts-ignore
5998
+ node.style[camelize(this.keyName)] = value;
5999
+ return true;
6000
+ };
6001
+ StyleAttributor.prototype.remove = function (node) {
6002
+ // @ts-ignore
6003
+ node.style[camelize(this.keyName)] = '';
6004
+ if (!node.getAttribute('style')) {
6005
+ node.removeAttribute('style');
5809
6006
  }
5810
- this.quill.insertText(range.index, ' ', _quill2.default.sources.USER);
5811
- this.quill.history.cutoff();
5812
- var delta = new _quillDelta2.default().retain(range.index - offset).delete(length + 1).retain(line.length() - 2 - offset).retain(1, { list: value });
5813
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5814
- this.quill.history.cutoff();
5815
- this.quill.setSelection(range.index - length, _quill2.default.sources.SILENT);
5816
- }
5817
- },
5818
- 'code exit': {
5819
- key: Keyboard.keys.ENTER,
5820
- collapsed: true,
5821
- format: ['code-block'],
5822
- prefix: /\n\n$/,
5823
- suffix: /^\s+$/,
5824
- handler: function handler(range) {
5825
- var _quill$getLine9 = this.quill.getLine(range.index),
5826
- _quill$getLine10 = _slicedToArray(_quill$getLine9, 2),
5827
- line = _quill$getLine10[0],
5828
- offset = _quill$getLine10[1];
6007
+ };
6008
+ StyleAttributor.prototype.value = function (node) {
6009
+ // @ts-ignore
6010
+ var value = node.style[camelize(this.keyName)];
6011
+ return this.canAdd(node, value) ? value : '';
6012
+ };
6013
+ return StyleAttributor;
6014
+ }(attributor_1.default));
6015
+ exports.default = StyleAttributor;
5829
6016
 
5830
- var delta = new _quillDelta2.default().retain(range.index + line.length() - offset - 2).retain(1, { 'code-block': null }).delete(1);
5831
- this.quill.updateContents(delta, _quill2.default.sources.USER);
5832
- }
5833
- },
5834
- 'embed left': makeEmbedArrowHandler(Keyboard.keys.LEFT, false),
5835
- 'embed left shift': makeEmbedArrowHandler(Keyboard.keys.LEFT, true),
5836
- 'embed right': makeEmbedArrowHandler(Keyboard.keys.RIGHT, false),
5837
- 'embed right shift': makeEmbedArrowHandler(Keyboard.keys.RIGHT, true)
6017
+
6018
+ /***/ }),
6019
+ /* 34 */
6020
+ /***/ (function(module, exports, __webpack_require__) {
6021
+
6022
+ "use strict";
6023
+
6024
+
6025
+ Object.defineProperty(exports, "__esModule", {
6026
+ value: true
6027
+ });
6028
+
6029
+ 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; }; }();
6030
+
6031
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6032
+
6033
+ var Theme = function () {
6034
+ function Theme(quill, options) {
6035
+ _classCallCheck(this, Theme);
6036
+
6037
+ this.quill = quill;
6038
+ this.options = options;
6039
+ this.modules = {};
5838
6040
  }
5839
- };
5840
6041
 
5841
- function makeEmbedArrowHandler(key, shiftKey) {
5842
- var _ref3;
6042
+ _createClass(Theme, [{
6043
+ key: 'init',
6044
+ value: function init() {
6045
+ var _this = this;
5843
6046
 
5844
- var where = key === Keyboard.keys.LEFT ? 'prefix' : 'suffix';
5845
- return _ref3 = {
5846
- key: key,
5847
- shiftKey: shiftKey
5848
- }, _defineProperty(_ref3, where, /^$/), _defineProperty(_ref3, 'handler', function handler(range) {
5849
- var index = range.index;
5850
- if (key === Keyboard.keys.RIGHT) {
5851
- index += range.length + 1;
6047
+ Object.keys(this.options.modules).forEach(function (name) {
6048
+ if (_this.modules[name] == null) {
6049
+ _this.addModule(name);
6050
+ }
6051
+ });
6052
+ }
6053
+ }, {
6054
+ key: 'addModule',
6055
+ value: function addModule(name) {
6056
+ var moduleClass = this.quill.constructor.import('modules/' + name);
6057
+ this.modules[name] = new moduleClass(this.quill, this.options.modules[name] || {});
6058
+ return this.modules[name];
5852
6059
  }
6060
+ }]);
5853
6061
 
5854
- var _quill$getLeaf3 = this.quill.getLeaf(index),
5855
- _quill$getLeaf4 = _slicedToArray(_quill$getLeaf3, 1),
5856
- leaf = _quill$getLeaf4[0];
6062
+ return Theme;
6063
+ }();
5857
6064
 
5858
- if (!(leaf instanceof _embed2.default)) return true;
5859
- if (key === Keyboard.keys.LEFT) {
5860
- if (shiftKey) {
5861
- this.quill.setSelection(range.index - 1, range.length + 1, _quill2.default.sources.USER);
5862
- } else {
5863
- this.quill.setSelection(range.index - 1, _quill2.default.sources.USER);
5864
- }
5865
- } else {
5866
- if (shiftKey) {
5867
- this.quill.setSelection(range.index, range.length + 1, _quill2.default.sources.USER);
5868
- } else {
5869
- this.quill.setSelection(range.index + range.length + 1, _quill2.default.sources.USER);
5870
- }
5871
- }
5872
- return false;
5873
- }), _ref3;
5874
- }
6065
+ Theme.DEFAULTS = {
6066
+ modules: {}
6067
+ };
6068
+ Theme.themes = {
6069
+ 'default': Theme
6070
+ };
5875
6071
 
5876
- function handleBackspace(range, context) {
5877
- if (range.index === 0 || this.quill.getLength() <= 1) return;
6072
+ exports.default = Theme;
5878
6073
 
5879
- var _quill$getLine11 = this.quill.getLine(range.index),
5880
- _quill$getLine12 = _slicedToArray(_quill$getLine11, 1),
5881
- line = _quill$getLine12[0];
6074
+ /***/ }),
6075
+ /* 35 */
6076
+ /***/ (function(module, exports, __webpack_require__) {
5882
6077
 
5883
- var formats = {};
5884
- if (context.offset === 0) {
5885
- var _quill$getLine13 = this.quill.getLine(range.index - 1),
5886
- _quill$getLine14 = _slicedToArray(_quill$getLine13, 1),
5887
- prev = _quill$getLine14[0];
6078
+ "use strict";
5888
6079
 
5889
- if (prev != null && prev.length() > 1) {
5890
- var curFormats = line.formats();
5891
- var prevFormats = this.quill.getFormat(range.index - 1, 1);
5892
- formats = _op2.default.attributes.diff(curFormats, prevFormats) || {};
5893
- }
5894
- }
5895
- // Check for astral symbols
5896
- var length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
5897
- this.quill.deleteText(range.index - length, length, _quill2.default.sources.USER);
5898
- if (Object.keys(formats).length > 0) {
5899
- this.quill.formatLine(range.index - length, length, formats, _quill2.default.sources.USER);
5900
- }
5901
- this.quill.focus();
5902
- }
5903
6080
 
5904
- function handleDelete(range, context) {
5905
- // Check for astral symbols
5906
- var length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix) ? 2 : 1;
5907
- if (range.index >= this.quill.getLength() - length) return;
5908
- var formats = {},
5909
- nextLength = 0;
6081
+ Object.defineProperty(exports, "__esModule", {
6082
+ value: true
6083
+ });
6084
+
6085
+ 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; }; }();
5910
6086
 
5911
- var _quill$getLine15 = this.quill.getLine(range.index),
5912
- _quill$getLine16 = _slicedToArray(_quill$getLine15, 1),
5913
- line = _quill$getLine16[0];
6087
+ 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); } };
5914
6088
 
5915
- if (context.offset >= line.length() - 1) {
5916
- var _quill$getLine17 = this.quill.getLine(range.index + 1),
5917
- _quill$getLine18 = _slicedToArray(_quill$getLine17, 1),
5918
- next = _quill$getLine18[0];
6089
+ var _parchment = __webpack_require__(0);
5919
6090
 
5920
- if (next) {
5921
- var curFormats = line.formats();
5922
- var nextFormats = this.quill.getFormat(range.index, 1);
5923
- formats = _op2.default.attributes.diff(curFormats, nextFormats) || {};
5924
- nextLength = next.length();
5925
- }
5926
- }
5927
- this.quill.deleteText(range.index, length, _quill2.default.sources.USER);
5928
- if (Object.keys(formats).length > 0) {
5929
- this.quill.formatLine(range.index + nextLength - 1, length, formats, _quill2.default.sources.USER);
5930
- }
5931
- }
6091
+ var _parchment2 = _interopRequireDefault(_parchment);
5932
6092
 
5933
- function handleDeleteRange(range) {
5934
- var lines = this.quill.getLines(range);
5935
- var formats = {};
5936
- if (lines.length > 1) {
5937
- var firstFormats = lines[0].formats();
5938
- var lastFormats = lines[lines.length - 1].formats();
5939
- formats = _op2.default.attributes.diff(lastFormats, firstFormats) || {};
5940
- }
5941
- this.quill.deleteText(range, _quill2.default.sources.USER);
5942
- if (Object.keys(formats).length > 0) {
5943
- this.quill.formatLine(range.index, 1, formats, _quill2.default.sources.USER);
5944
- }
5945
- this.quill.setSelection(range.index, _quill2.default.sources.SILENT);
5946
- this.quill.focus();
5947
- }
6093
+ var _text = __webpack_require__(7);
5948
6094
 
5949
- function handleEnter(range, context) {
5950
- var _this3 = this;
6095
+ var _text2 = _interopRequireDefault(_text);
5951
6096
 
5952
- if (range.length > 0) {
5953
- this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change
5954
- }
5955
- var lineFormats = Object.keys(context.format).reduce(function (lineFormats, format) {
5956
- if (_parchment2.default.query(format, _parchment2.default.Scope.BLOCK) && !Array.isArray(context.format[format])) {
5957
- lineFormats[format] = context.format[format];
5958
- }
5959
- return lineFormats;
5960
- }, {});
5961
- this.quill.insertText(range.index, '\n', lineFormats, _quill2.default.sources.USER);
5962
- // Earlier scroll.deleteAt might have messed up our selection,
5963
- // so insertText's built in selection preservation is not reliable
5964
- this.quill.setSelection(range.index + 1, _quill2.default.sources.SILENT);
5965
- this.quill.focus();
5966
- Object.keys(context.format).forEach(function (name) {
5967
- if (lineFormats[name] != null) return;
5968
- if (Array.isArray(context.format[name])) return;
5969
- if (name === 'link') return;
5970
- _this3.quill.format(name, context.format[name], _quill2.default.sources.USER);
5971
- });
5972
- }
6097
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5973
6098
 
5974
- function makeCodeBlockHandler(indent) {
5975
- return {
5976
- key: Keyboard.keys.TAB,
5977
- shiftKey: !indent,
5978
- format: { 'code-block': true },
5979
- handler: function handler(range) {
5980
- var CodeBlock = _parchment2.default.query('code-block');
5981
- var index = range.index,
5982
- length = range.length;
6099
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5983
6100
 
5984
- var _quill$scroll$descend = this.quill.scroll.descendant(CodeBlock, index),
5985
- _quill$scroll$descend2 = _slicedToArray(_quill$scroll$descend, 2),
5986
- block = _quill$scroll$descend2[0],
5987
- offset = _quill$scroll$descend2[1];
6101
+ 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; }
5988
6102
 
5989
- if (block == null) return;
5990
- var scrollIndex = this.quill.getIndex(block);
5991
- var start = block.newlineIndex(offset, true) + 1;
5992
- var end = block.newlineIndex(scrollIndex + offset + length);
5993
- var lines = block.domNode.textContent.slice(start, end).split('\n');
5994
- offset = 0;
5995
- lines.forEach(function (line, i) {
5996
- if (indent) {
5997
- block.insertAt(start + offset, CodeBlock.TAB);
5998
- offset += CodeBlock.TAB.length;
5999
- if (i === 0) {
6000
- index += CodeBlock.TAB.length;
6001
- } else {
6002
- length += CodeBlock.TAB.length;
6003
- }
6004
- } else if (line.startsWith(CodeBlock.TAB)) {
6005
- block.deleteAt(start + offset, CodeBlock.TAB.length);
6006
- offset -= CodeBlock.TAB.length;
6007
- if (i === 0) {
6008
- index -= CodeBlock.TAB.length;
6009
- } else {
6010
- length -= CodeBlock.TAB.length;
6011
- }
6103
+ 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; }
6104
+
6105
+ var GUARD_TEXT = '\uFEFF';
6106
+
6107
+ var Embed = function (_Parchment$Embed) {
6108
+ _inherits(Embed, _Parchment$Embed);
6109
+
6110
+ function Embed(node) {
6111
+ _classCallCheck(this, Embed);
6112
+
6113
+ var _this = _possibleConstructorReturn(this, (Embed.__proto__ || Object.getPrototypeOf(Embed)).call(this, node));
6114
+
6115
+ _this.contentNode = document.createElement('span');
6116
+ _this.contentNode.setAttribute('contenteditable', false);
6117
+ [].slice.call(_this.domNode.childNodes).forEach(function (childNode) {
6118
+ _this.contentNode.appendChild(childNode);
6119
+ });
6120
+ _this.leftGuard = document.createTextNode(GUARD_TEXT);
6121
+ _this.rightGuard = document.createTextNode(GUARD_TEXT);
6122
+ _this.domNode.appendChild(_this.leftGuard);
6123
+ _this.domNode.appendChild(_this.contentNode);
6124
+ _this.domNode.appendChild(_this.rightGuard);
6125
+ return _this;
6126
+ }
6127
+
6128
+ _createClass(Embed, [{
6129
+ key: 'index',
6130
+ value: function index(node, offset) {
6131
+ if (node === this.leftGuard) return 0;
6132
+ if (node === this.rightGuard) return 1;
6133
+ return _get(Embed.prototype.__proto__ || Object.getPrototypeOf(Embed.prototype), 'index', this).call(this, node, offset);
6134
+ }
6135
+ }, {
6136
+ key: 'restore',
6137
+ value: function restore(node) {
6138
+ var range = void 0,
6139
+ textNode = void 0;
6140
+ var text = node.data.split(GUARD_TEXT).join('');
6141
+ if (node === this.leftGuard) {
6142
+ if (this.prev instanceof _text2.default) {
6143
+ var prevLength = this.prev.length();
6144
+ this.prev.insertAt(prevLength, text);
6145
+ range = {
6146
+ startNode: this.prev.domNode,
6147
+ startOffset: prevLength + text.length
6148
+ };
6149
+ } else {
6150
+ textNode = document.createTextNode(text);
6151
+ this.parent.insertBefore(_parchment2.default.create(textNode), this);
6152
+ range = {
6153
+ startNode: textNode,
6154
+ startOffset: text.length
6155
+ };
6012
6156
  }
6013
- offset += line.length + 1;
6014
- });
6015
- this.quill.update(_quill2.default.sources.USER);
6016
- this.quill.setSelection(index, length, _quill2.default.sources.SILENT);
6157
+ } else if (node === this.rightGuard) {
6158
+ if (this.next instanceof _text2.default) {
6159
+ this.next.insertAt(0, text);
6160
+ range = {
6161
+ startNode: this.next.domNode,
6162
+ startOffset: text.length
6163
+ };
6164
+ } else {
6165
+ textNode = document.createTextNode(text);
6166
+ this.parent.insertBefore(_parchment2.default.create(textNode), this.next);
6167
+ range = {
6168
+ startNode: textNode,
6169
+ startOffset: text.length
6170
+ };
6171
+ }
6172
+ }
6173
+ node.data = GUARD_TEXT;
6174
+ return range;
6017
6175
  }
6018
- };
6019
- }
6176
+ }, {
6177
+ key: 'update',
6178
+ value: function update(mutations, context) {
6179
+ var _this2 = this;
6020
6180
 
6021
- function makeFormatHandler(format) {
6022
- return {
6023
- key: format[0].toUpperCase(),
6024
- shortKey: true,
6025
- handler: function handler(range, context) {
6026
- this.quill.format(format, !context.format[format], _quill2.default.sources.USER);
6181
+ mutations.forEach(function (mutation) {
6182
+ if (mutation.type === 'characterData' && (mutation.target === _this2.leftGuard || mutation.target === _this2.rightGuard)) {
6183
+ var range = _this2.restore(mutation.target);
6184
+ if (range) context.range = range;
6185
+ }
6186
+ });
6027
6187
  }
6028
- };
6029
- }
6188
+ }]);
6030
6189
 
6031
- function normalize(binding) {
6032
- if (typeof binding === 'string' || typeof binding === 'number') {
6033
- return normalize({ key: binding });
6034
- }
6035
- if ((typeof binding === 'undefined' ? 'undefined' : _typeof(binding)) === 'object') {
6036
- binding = (0, _clone2.default)(binding, false);
6037
- }
6038
- if (typeof binding.key === 'string') {
6039
- if (Keyboard.keys[binding.key.toUpperCase()] != null) {
6040
- binding.key = Keyboard.keys[binding.key.toUpperCase()];
6041
- } else if (binding.key.length === 1) {
6042
- binding.key = binding.key.toUpperCase().charCodeAt(0);
6043
- } else {
6044
- return null;
6045
- }
6046
- }
6047
- if (binding.shortKey) {
6048
- binding[SHORTKEY] = binding.shortKey;
6049
- delete binding.shortKey;
6050
- }
6051
- return binding;
6052
- }
6190
+ return Embed;
6191
+ }(_parchment2.default.Embed);
6053
6192
 
6054
- exports.default = Keyboard;
6055
- exports.SHORTKEY = SHORTKEY;
6193
+ exports.default = Embed;
6056
6194
 
6057
6195
  /***/ }),
6058
6196
  /* 36 */
@@ -6358,13 +6496,13 @@ var History = function (_Module) {
6358
6496
  value: function change(source, dest) {
6359
6497
  if (this.stack[source].length === 0) return;
6360
6498
  var delta = this.stack[source].pop();
6499
+ this.stack[dest].push(delta);
6361
6500
  this.lastRecorded = 0;
6362
6501
  this.ignoreChange = true;
6363
6502
  this.quill.updateContents(delta[source], _quill2.default.sources.USER);
6364
6503
  this.ignoreChange = false;
6365
6504
  var index = getLastChangeIndex(delta[source]);
6366
6505
  this.quill.setSelection(index);
6367
- this.stack[dest].push(delta);
6368
6506
  }
6369
6507
  }, {
6370
6508
  key: 'clear',
@@ -6488,7 +6626,7 @@ var _emitter = __webpack_require__(8);
6488
6626
 
6489
6627
  var _emitter2 = _interopRequireDefault(_emitter);
6490
6628
 
6491
- var _keyboard = __webpack_require__(35);
6629
+ var _keyboard = __webpack_require__(23);
6492
6630
 
6493
6631
  var _keyboard2 = _interopRequireDefault(_keyboard);
6494
6632
 
@@ -6553,7 +6691,7 @@ var BaseTheme = function (_Theme) {
6553
6691
  });
6554
6692
  }
6555
6693
  };
6556
- document.body.addEventListener('click', listener);
6694
+ quill.emitter.listenDOM('click', document.body, listener);
6557
6695
  return _this;
6558
6696
  }
6559
6697
 
@@ -6812,7 +6950,7 @@ exports.default = BaseTheme;
6812
6950
  Object.defineProperty(exports, "__esModule", { value: true });
6813
6951
  var LinkedList = /** @class */ (function () {
6814
6952
  function LinkedList() {
6815
- this.head = this.tail = undefined;
6953
+ this.head = this.tail = null;
6816
6954
  this.length = 0;
6817
6955
  }
6818
6956
  LinkedList.prototype.append = function () {
@@ -6820,20 +6958,22 @@ var LinkedList = /** @class */ (function () {
6820
6958
  for (var _i = 0; _i < arguments.length; _i++) {
6821
6959
  nodes[_i] = arguments[_i];
6822
6960
  }
6823
- this.insertBefore(nodes[0], undefined);
6961
+ this.insertBefore(nodes[0], null);
6824
6962
  if (nodes.length > 1) {
6825
6963
  this.append.apply(this, nodes.slice(1));
6826
6964
  }
6827
6965
  };
6828
6966
  LinkedList.prototype.contains = function (node) {
6829
6967
  var cur, next = this.iterator();
6830
- while (cur = next()) {
6968
+ while ((cur = next())) {
6831
6969
  if (cur === node)
6832
6970
  return true;
6833
6971
  }
6834
6972
  return false;
6835
6973
  };
6836
6974
  LinkedList.prototype.insertBefore = function (node, refNode) {
6975
+ if (!node)
6976
+ return;
6837
6977
  node.next = refNode;
6838
6978
  if (refNode != null) {
6839
6979
  node.prev = refNode.prev;
@@ -6851,7 +6991,7 @@ var LinkedList = /** @class */ (function () {
6851
6991
  this.tail = node;
6852
6992
  }
6853
6993
  else {
6854
- node.prev = undefined;
6994
+ node.prev = null;
6855
6995
  this.head = this.tail = node;
6856
6996
  }
6857
6997
  this.length += 1;
@@ -6892,9 +7032,10 @@ var LinkedList = /** @class */ (function () {
6892
7032
  LinkedList.prototype.find = function (index, inclusive) {
6893
7033
  if (inclusive === void 0) { inclusive = false; }
6894
7034
  var cur, next = this.iterator();
6895
- while (cur = next()) {
7035
+ while ((cur = next())) {
6896
7036
  var length = cur.length();
6897
- if (index < length || (inclusive && index === length && (cur.next == null || cur.next.length() !== 0))) {
7037
+ if (index < length ||
7038
+ (inclusive && index === length && (cur.next == null || cur.next.length() !== 0))) {
6898
7039
  return [cur, index];
6899
7040
  }
6900
7041
  index -= length;
@@ -6903,7 +7044,7 @@ var LinkedList = /** @class */ (function () {
6903
7044
  };
6904
7045
  LinkedList.prototype.forEach = function (callback) {
6905
7046
  var cur, next = this.iterator();
6906
- while (cur = next()) {
7047
+ while ((cur = next())) {
6907
7048
  callback(cur);
6908
7049
  }
6909
7050
  };
@@ -6931,7 +7072,7 @@ var LinkedList = /** @class */ (function () {
6931
7072
  };
6932
7073
  LinkedList.prototype.reduce = function (callback, memo) {
6933
7074
  var cur, next = this.iterator();
6934
- while (cur = next()) {
7075
+ while ((cur = next())) {
6935
7076
  memo = callback(memo, cur);
6936
7077
  }
6937
7078
  return memo;
@@ -6965,18 +7106,19 @@ var OBSERVER_CONFIG = {
6965
7106
  characterData: true,
6966
7107
  characterDataOldValue: true,
6967
7108
  childList: true,
6968
- subtree: true
7109
+ subtree: true,
6969
7110
  };
6970
7111
  var MAX_OPTIMIZE_ITERATIONS = 100;
6971
7112
  var ScrollBlot = /** @class */ (function (_super) {
6972
7113
  __extends(ScrollBlot, _super);
6973
7114
  function ScrollBlot(node) {
6974
7115
  var _this = _super.call(this, node) || this;
6975
- _this.parent = null;
7116
+ _this.scroll = _this;
6976
7117
  _this.observer = new MutationObserver(function (mutations) {
6977
7118
  _this.update(mutations);
6978
7119
  });
6979
7120
  _this.observer.observe(_this.domNode, OBSERVER_CONFIG);
7121
+ _this.attach();
6980
7122
  return _this;
6981
7123
  }
6982
7124
  ScrollBlot.prototype.detach = function () {
@@ -7020,14 +7162,21 @@ var ScrollBlot = /** @class */ (function (_super) {
7020
7162
  return;
7021
7163
  if (blot.domNode.parentNode == null)
7022
7164
  return;
7165
+ // @ts-ignore
7023
7166
  if (blot.domNode[Registry.DATA_KEY].mutations == null) {
7167
+ // @ts-ignore
7024
7168
  blot.domNode[Registry.DATA_KEY].mutations = [];
7025
7169
  }
7026
7170
  if (markParent)
7027
7171
  mark(blot.parent);
7028
7172
  };
7029
7173
  var optimize = function (blot) {
7030
- if (blot.domNode[Registry.DATA_KEY] == null || blot.domNode[Registry.DATA_KEY].mutations == null) {
7174
+ // Post-order traversal
7175
+ if (
7176
+ // @ts-ignore
7177
+ blot.domNode[Registry.DATA_KEY] == null ||
7178
+ // @ts-ignore
7179
+ blot.domNode[Registry.DATA_KEY].mutations == null) {
7031
7180
  return;
7032
7181
  }
7033
7182
  if (blot instanceof container_1.default) {
@@ -7075,24 +7224,35 @@ var ScrollBlot = /** @class */ (function (_super) {
7075
7224
  if (context === void 0) { context = {}; }
7076
7225
  mutations = mutations || this.observer.takeRecords();
7077
7226
  // TODO use WeakMap
7078
- mutations.map(function (mutation) {
7227
+ mutations
7228
+ .map(function (mutation) {
7079
7229
  var blot = Registry.find(mutation.target, true);
7080
7230
  if (blot == null)
7081
- return;
7231
+ return null;
7232
+ // @ts-ignore
7082
7233
  if (blot.domNode[Registry.DATA_KEY].mutations == null) {
7234
+ // @ts-ignore
7083
7235
  blot.domNode[Registry.DATA_KEY].mutations = [mutation];
7084
7236
  return blot;
7085
7237
  }
7086
7238
  else {
7239
+ // @ts-ignore
7087
7240
  blot.domNode[Registry.DATA_KEY].mutations.push(mutation);
7088
7241
  return null;
7089
7242
  }
7090
- }).forEach(function (blot) {
7091
- if (blot == null || blot === _this || blot.domNode[Registry.DATA_KEY] == null)
7243
+ })
7244
+ .forEach(function (blot) {
7245
+ if (blot == null ||
7246
+ blot === _this ||
7247
+ //@ts-ignore
7248
+ blot.domNode[Registry.DATA_KEY] == null)
7092
7249
  return;
7250
+ // @ts-ignore
7093
7251
  blot.update(blot.domNode[Registry.DATA_KEY].mutations || [], context);
7094
7252
  });
7253
+ // @ts-ignore
7095
7254
  if (this.domNode[Registry.DATA_KEY].mutations != null) {
7255
+ // @ts-ignore
7096
7256
  _super.prototype.update.call(this, this.domNode[Registry.DATA_KEY].mutations, context);
7097
7257
  }
7098
7258
  this.optimize(mutations, context);
@@ -7129,7 +7289,9 @@ var Registry = __webpack_require__(1);
7129
7289
  function isEqual(obj1, obj2) {
7130
7290
  if (Object.keys(obj1).length !== Object.keys(obj2).length)
7131
7291
  return false;
7292
+ // @ts-ignore
7132
7293
  for (var prop in obj1) {
7294
+ // @ts-ignore
7133
7295
  if (obj1[prop] !== obj2[prop])
7134
7296
  return false;
7135
7297
  }
@@ -7251,7 +7413,7 @@ var BlockBlot = /** @class */ (function (_super) {
7251
7413
  };
7252
7414
  BlockBlot.prototype.update = function (mutations, context) {
7253
7415
  if (navigator.userAgent.match(/Trident/)) {
7254
- this.attach();
7416
+ this.build();
7255
7417
  }
7256
7418
  else {
7257
7419
  _super.prototype.update.call(this, mutations, context);
@@ -7344,8 +7506,9 @@ var TextBlot = /** @class */ (function (_super) {
7344
7506
  };
7345
7507
  TextBlot.value = function (domNode) {
7346
7508
  var text = domNode.data;
7347
- if (text["normalize"])
7348
- text = text["normalize"]();
7509
+ // @ts-ignore
7510
+ if (text['normalize'])
7511
+ text = text['normalize']();
7349
7512
  return text;
7350
7513
  };
7351
7514
  TextBlot.prototype.deleteAt = function (index, length) {
@@ -7574,6 +7737,7 @@ function diff_main(text1, text2, cursor_pos) {
7574
7737
  if (cursor_pos != null) {
7575
7738
  diffs = fix_cursor(diffs, cursor_pos);
7576
7739
  }
7740
+ diffs = fix_emoji(diffs);
7577
7741
  return diffs;
7578
7742
  };
7579
7743
 
@@ -8163,7 +8327,46 @@ function fix_cursor (diffs, cursor_pos) {
8163
8327
  return diffs;
8164
8328
  }
8165
8329
  }
8330
+ }
8331
+
8332
+ /*
8333
+ * Check diff did not split surrogate pairs.
8334
+ * Ex. [0, '\uD83D'], [-1, '\uDC36'], [1, '\uDC2F'] -> [-1, '\uD83D\uDC36'], [1, '\uD83D\uDC2F']
8335
+ * '\uD83D\uDC36' === '🐶', '\uD83D\uDC2F' === '🐯'
8336
+ *
8337
+ * @param {Array} diffs Array of diff tuples
8338
+ * @return {Array} Array of diff tuples
8339
+ */
8340
+ function fix_emoji (diffs) {
8341
+ var compact = false;
8342
+ var starts_with_pair_end = function(str) {
8343
+ return str.charCodeAt(0) >= 0xDC00 && str.charCodeAt(0) <= 0xDFFF;
8344
+ }
8345
+ var ends_with_pair_start = function(str) {
8346
+ return str.charCodeAt(str.length-1) >= 0xD800 && str.charCodeAt(str.length-1) <= 0xDBFF;
8347
+ }
8348
+ for (var i = 2; i < diffs.length; i += 1) {
8349
+ if (diffs[i-2][0] === DIFF_EQUAL && ends_with_pair_start(diffs[i-2][1]) &&
8350
+ diffs[i-1][0] === DIFF_DELETE && starts_with_pair_end(diffs[i-1][1]) &&
8351
+ diffs[i][0] === DIFF_INSERT && starts_with_pair_end(diffs[i][1])) {
8352
+ compact = true;
8353
+
8354
+ diffs[i-1][1] = diffs[i-2][1].slice(-1) + diffs[i-1][1];
8355
+ diffs[i][1] = diffs[i-2][1].slice(-1) + diffs[i][1];
8166
8356
 
8357
+ diffs[i-2][1] = diffs[i-2][1].slice(0, -1);
8358
+ }
8359
+ }
8360
+ if (!compact) {
8361
+ return diffs;
8362
+ }
8363
+ var fixed_diffs = [];
8364
+ for (var i = 0; i < diffs.length; i += 1) {
8365
+ if (diffs[i][1].length > 0) {
8366
+ fixed_diffs.push(diffs[i]);
8367
+ }
8368
+ }
8369
+ return fixed_diffs;
8167
8370
  }
8168
8371
 
8169
8372
  /*
@@ -8695,10 +8898,12 @@ var Clipboard = function (_Module) {
8695
8898
  var source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _quill2.default.sources.API;
8696
8899
 
8697
8900
  if (typeof index === 'string') {
8698
- return this.quill.setContents(this.convert(index), html);
8901
+ this.quill.setContents(this.convert(index), html);
8902
+ this.quill.setSelection(0, _quill2.default.sources.SILENT);
8699
8903
  } else {
8700
8904
  var paste = this.convert(html);
8701
- return this.quill.updateContents(new _quillDelta2.default().retain(index).concat(paste), source);
8905
+ this.quill.updateContents(new _quillDelta2.default().retain(index).concat(paste), source);
8906
+ this.quill.setSelection(index + paste.length(), _quill2.default.sources.SILENT);
8702
8907
  }
8703
8908
  }
8704
8909
  }, {
@@ -8839,11 +9044,11 @@ function matchAttributor(node, delta) {
8839
9044
  if (formats[attr.attrName]) return;
8840
9045
  }
8841
9046
  attr = ATTRIBUTE_ATTRIBUTORS[name];
8842
- if (attr != null && attr.attrName === name) {
9047
+ if (attr != null && (attr.attrName === name || attr.keyName === name)) {
8843
9048
  formats[attr.attrName] = attr.value(node) || undefined;
8844
9049
  }
8845
9050
  attr = STYLE_ATTRIBUTORS[name];
8846
- if (attr != null && attr.attrName === name) {
9051
+ if (attr != null && (attr.attrName === name || attr.keyName === name)) {
8847
9052
  attr = STYLE_ATTRIBUTORS[name];
8848
9053
  formats[attr.attrName] = attr.value(node) || undefined;
8849
9054
  }
@@ -9760,6 +9965,10 @@ exports.default = SnowTheme;
9760
9965
  "use strict";
9761
9966
 
9762
9967
 
9968
+ Object.defineProperty(exports, "__esModule", {
9969
+ value: true
9970
+ });
9971
+
9763
9972
  var _core = __webpack_require__(29);
9764
9973
 
9765
9974
  var _core2 = _interopRequireDefault(_core);
@@ -9928,7 +10137,7 @@ _core2.default.register({
9928
10137
  'ui/tooltip': _tooltip2.default
9929
10138
  }, true);
9930
10139
 
9931
- module.exports = _core2.default;
10140
+ exports.default = _core2.default;
9932
10141
 
9933
10142
  /***/ }),
9934
10143
  /* 64 */
@@ -10116,7 +10325,7 @@ var _block = __webpack_require__(4);
10116
10325
 
10117
10326
  var _block2 = _interopRequireDefault(_block);
10118
10327
 
10119
- var _container = __webpack_require__(24);
10328
+ var _container = __webpack_require__(25);
10120
10329
 
10121
10330
  var _container2 = _interopRequireDefault(_container);
10122
10331
 
@@ -10680,7 +10889,7 @@ var _createClass = function () { function defineProperties(target, props) { for
10680
10889
 
10681
10890
  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); } };
10682
10891
 
10683
- var _embed = __webpack_require__(25);
10892
+ var _embed = __webpack_require__(35);
10684
10893
 
10685
10894
  var _embed2 = _interopRequireDefault(_embed);
10686
10895
 
@@ -11276,5 +11485,5 @@ module.exports = __webpack_require__(63);
11276
11485
 
11277
11486
 
11278
11487
  /***/ })
11279
- /******/ ]);
11488
+ /******/ ])["default"];
11280
11489
  });