tinymce-rails 5.7.1 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/source/tinymce/tinymce.js +1193 -964
  3. data/lib/tinymce/rails/version.rb +2 -2
  4. data/vendor/assets/javascripts/tinymce/langs/{readme.md → README.md} +0 -0
  5. data/vendor/assets/javascripts/tinymce/plugins/advlist/plugin.js +1 -1
  6. data/vendor/assets/javascripts/tinymce/plugins/anchor/plugin.js +1 -1
  7. data/vendor/assets/javascripts/tinymce/plugins/autolink/plugin.js +1 -1
  8. data/vendor/assets/javascripts/tinymce/plugins/autoresize/plugin.js +1 -1
  9. data/vendor/assets/javascripts/tinymce/plugins/autosave/plugin.js +1 -1
  10. data/vendor/assets/javascripts/tinymce/plugins/bbcode/plugin.js +1 -1
  11. data/vendor/assets/javascripts/tinymce/plugins/charmap/plugin.js +2 -2
  12. data/vendor/assets/javascripts/tinymce/plugins/code/plugin.js +1 -1
  13. data/vendor/assets/javascripts/tinymce/plugins/codesample/plugin.js +1 -1
  14. data/vendor/assets/javascripts/tinymce/plugins/colorpicker/plugin.js +1 -1
  15. data/vendor/assets/javascripts/tinymce/plugins/contextmenu/plugin.js +1 -1
  16. data/vendor/assets/javascripts/tinymce/plugins/directionality/plugin.js +2 -2
  17. data/vendor/assets/javascripts/tinymce/plugins/emoticons/plugin.js +1 -1
  18. data/vendor/assets/javascripts/tinymce/plugins/fullpage/plugin.js +1 -1
  19. data/vendor/assets/javascripts/tinymce/plugins/fullscreen/plugin.js +2 -2
  20. data/vendor/assets/javascripts/tinymce/plugins/help/plugin.js +2 -2
  21. data/vendor/assets/javascripts/tinymce/plugins/hr/plugin.js +1 -1
  22. data/vendor/assets/javascripts/tinymce/plugins/image/plugin.js +2 -2
  23. data/vendor/assets/javascripts/tinymce/plugins/imagetools/plugin.js +2 -2
  24. data/vendor/assets/javascripts/tinymce/plugins/importcss/plugin.js +1 -1
  25. data/vendor/assets/javascripts/tinymce/plugins/insertdatetime/plugin.js +1 -1
  26. data/vendor/assets/javascripts/tinymce/plugins/legacyoutput/plugin.js +1 -1
  27. data/vendor/assets/javascripts/tinymce/plugins/link/plugin.js +1 -1
  28. data/vendor/assets/javascripts/tinymce/plugins/lists/plugin.js +2 -2
  29. data/vendor/assets/javascripts/tinymce/plugins/media/plugin.js +2 -2
  30. data/vendor/assets/javascripts/tinymce/plugins/nonbreaking/plugin.js +1 -1
  31. data/vendor/assets/javascripts/tinymce/plugins/noneditable/plugin.js +1 -1
  32. data/vendor/assets/javascripts/tinymce/plugins/pagebreak/plugin.js +1 -1
  33. data/vendor/assets/javascripts/tinymce/plugins/paste/plugin.js +2 -2
  34. data/vendor/assets/javascripts/tinymce/plugins/preview/plugin.js +1 -1
  35. data/vendor/assets/javascripts/tinymce/plugins/print/plugin.js +1 -1
  36. data/vendor/assets/javascripts/tinymce/plugins/quickbars/plugin.js +2 -2
  37. data/vendor/assets/javascripts/tinymce/plugins/save/plugin.js +1 -1
  38. data/vendor/assets/javascripts/tinymce/plugins/searchreplace/plugin.js +2 -2
  39. data/vendor/assets/javascripts/tinymce/plugins/spellchecker/plugin.js +1 -1
  40. data/vendor/assets/javascripts/tinymce/plugins/tabfocus/plugin.js +1 -1
  41. data/vendor/assets/javascripts/tinymce/plugins/table/plugin.js +2 -2
  42. data/vendor/assets/javascripts/tinymce/plugins/template/plugin.js +1 -1
  43. data/vendor/assets/javascripts/tinymce/plugins/textcolor/plugin.js +1 -1
  44. data/vendor/assets/javascripts/tinymce/plugins/textpattern/plugin.js +2 -2
  45. data/vendor/assets/javascripts/tinymce/plugins/toc/plugin.js +1 -1
  46. data/vendor/assets/javascripts/tinymce/plugins/visualblocks/plugin.js +1 -1
  47. data/vendor/assets/javascripts/tinymce/plugins/visualchars/plugin.js +2 -2
  48. data/vendor/assets/javascripts/tinymce/plugins/wordcount/plugin.js +1 -1
  49. data/vendor/assets/javascripts/tinymce/skins/ui/oxide-dark/skin.css +1 -1
  50. data/vendor/assets/javascripts/tinymce/skins/ui/oxide-dark/skin.min.css +1 -1
  51. data/vendor/assets/javascripts/tinymce/skins/ui/oxide/skin.css +1 -1
  52. data/vendor/assets/javascripts/tinymce/skins/ui/oxide/skin.min.css +1 -1
  53. data/vendor/assets/javascripts/tinymce/themes/mobile/theme.js +2 -2
  54. data/vendor/assets/javascripts/tinymce/themes/silver/theme.js +2 -2
  55. data/vendor/assets/javascripts/tinymce/tinymce.d.ts +6 -1
  56. data/vendor/assets/javascripts/tinymce/tinymce.js +2 -2
  57. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b234fea66f361a361266406d0efca1a818e0baf682cfb8ea7767b11d7df537a6
4
- data.tar.gz: 6d99aa630bf351c1667e8663b3d488f96eff5450a879948781ecd3ae3c8cb6a5
3
+ metadata.gz: 2e895482a995fdfe18407ebcb8e8dfacffe635fd677d113fac18a5b16e32c39d
4
+ data.tar.gz: 3a25e9b6d3637d63c9f3900aea076690781b69e3c687eebfa25ff5de6e33fb1c
5
5
  SHA512:
6
- metadata.gz: 0eb32ff441d04558f7c0d8cd376cbfc01108275786212d09aa80283182125c8c7db5d7cacd0d89aad47b743797ebdbc6c77b04c71182a590be7d67f9ecc29ebe
7
- data.tar.gz: '091bbcd6597d13369b4977426b8bcbf67d9b1ac5097ecbc409f207061e2f5ca83b603563abda94ccb64c32a48a2cc55fd37001bd34119eae74bfc5e74fb2c031'
6
+ metadata.gz: 689ea6dbaefe12f0ca67c71075b9e7c45347b93e70372b387062db25085972ac5d7c38a390f8e0671b67072f003a6a7ab609317970443f0ff21a0983e2efd977
7
+ data.tar.gz: 786d93116ce63655873dbc2ff785873a4a1c4eb58a76b92088917eb224ab7688102009e73cf38847ab5ec35870b4408414ff9d6a10e944c59b4e2bdb00fca67f
@@ -4,7 +4,7 @@
4
4
  * For LGPL see License.txt in the project root for license information.
5
5
  * For commercial licenses see https://www.tiny.cloud/
6
6
  *
7
- * Version: 5.7.1 (2021-03-17)
7
+ * Version: 5.8.0 (2021-05-06)
8
8
  */
9
9
  (function () {
10
10
  'use strict';
@@ -109,6 +109,48 @@
109
109
  return false;
110
110
  });
111
111
 
112
+ var typeOf$1 = function (x) {
113
+ var t = typeof x;
114
+ if (x === null) {
115
+ return 'null';
116
+ } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
117
+ return 'array';
118
+ } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
119
+ return 'string';
120
+ } else {
121
+ return t;
122
+ }
123
+ };
124
+ var isType = function (type) {
125
+ return function (value) {
126
+ return typeOf$1(value) === type;
127
+ };
128
+ };
129
+ var isSimpleType = function (type) {
130
+ return function (value) {
131
+ return typeof value === type;
132
+ };
133
+ };
134
+ var eq$1 = function (t) {
135
+ return function (a) {
136
+ return t === a;
137
+ };
138
+ };
139
+ var isString = isType('string');
140
+ var isObject = isType('object');
141
+ var isArray = isType('array');
142
+ var isNull = eq$1(null);
143
+ var isBoolean = isSimpleType('boolean');
144
+ var isUndefined = eq$1(undefined);
145
+ var isNullable = function (a) {
146
+ return a === null || a === undefined;
147
+ };
148
+ var isNonNullable = function (a) {
149
+ return !isNullable(a);
150
+ };
151
+ var isFunction = isSimpleType('function');
152
+ var isNumber = isSimpleType('number');
153
+
112
154
  var noop = function () {
113
155
  };
114
156
  var compose = function (fa, fb) {
@@ -272,48 +314,6 @@
272
314
  from: from
273
315
  };
274
316
 
275
- var typeOf$1 = function (x) {
276
- var t = typeof x;
277
- if (x === null) {
278
- return 'null';
279
- } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
280
- return 'array';
281
- } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
282
- return 'string';
283
- } else {
284
- return t;
285
- }
286
- };
287
- var isType = function (type) {
288
- return function (value) {
289
- return typeOf$1(value) === type;
290
- };
291
- };
292
- var isSimpleType = function (type) {
293
- return function (value) {
294
- return typeof value === type;
295
- };
296
- };
297
- var eq$1 = function (t) {
298
- return function (a) {
299
- return t === a;
300
- };
301
- };
302
- var isString = isType('string');
303
- var isObject = isType('object');
304
- var isArray = isType('array');
305
- var isNull = eq$1(null);
306
- var isBoolean = isSimpleType('boolean');
307
- var isUndefined = eq$1(undefined);
308
- var isNullable = function (a) {
309
- return a === null || a === undefined;
310
- };
311
- var isNonNullable = function (a) {
312
- return !isNullable(a);
313
- };
314
- var isFunction = isSimpleType('function');
315
- var isNumber = isSimpleType('number');
316
-
317
317
  var nativeSlice = Array.prototype.slice;
318
318
  var nativeIndexOf = Array.prototype.indexOf;
319
319
  var nativePush = Array.prototype.push;
@@ -811,6 +811,9 @@
811
811
  var trim = blank(/^\s+|\s+$/g);
812
812
  var lTrim = blank(/^\s+/g);
813
813
  var rTrim = blank(/\s+$/g);
814
+ var isNotEmpty = function (s) {
815
+ return s.length > 0;
816
+ };
814
817
 
815
818
  var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
816
819
  var checkContains = function (target) {
@@ -1146,7 +1149,8 @@
1146
1149
  return;
1147
1150
  }
1148
1151
  if (!p[cn]) {
1149
- p[cn] = noop;
1152
+ p[cn] = function () {
1153
+ };
1150
1154
  de = 1;
1151
1155
  }
1152
1156
  ns[cn] = p[cn];
@@ -10712,6 +10716,9 @@
10712
10716
  var isInlineFormat = function (format) {
10713
10717
  return hasNonNullableKey(format, 'inline');
10714
10718
  };
10719
+ var hasBlockChildren = function (dom, elm) {
10720
+ return exists(elm.childNodes, dom.isBlock);
10721
+ };
10715
10722
 
10716
10723
  var isBookmarkNode$2 = isBookmarkNode$1;
10717
10724
  var getParents$2 = getParents$1;
@@ -11441,6 +11448,8 @@
11441
11448
  SPACEBAR: 32,
11442
11449
  TAB: 9,
11443
11450
  UP: 38,
11451
+ PAGE_UP: 33,
11452
+ PAGE_DOWN: 34,
11444
11453
  END: 35,
11445
11454
  HOME: 36,
11446
11455
  modifierPressed: function (e) {
@@ -14020,6 +14029,108 @@
14020
14029
  return { serialize: serialize };
14021
14030
  };
14022
14031
 
14032
+ var nonInheritableStyles = new Set();
14033
+ (function () {
14034
+ var nonInheritableStylesArr = [
14035
+ 'margin',
14036
+ 'margin-left',
14037
+ 'margin-right',
14038
+ 'margin-top',
14039
+ 'margin-bottom',
14040
+ 'padding',
14041
+ 'padding-left',
14042
+ 'padding-right',
14043
+ 'padding-top',
14044
+ 'padding-bottom',
14045
+ 'border',
14046
+ 'border-width',
14047
+ 'border-style',
14048
+ 'border-color',
14049
+ 'background',
14050
+ 'background-attachment',
14051
+ 'background-clip',
14052
+ 'background-color',
14053
+ 'background-image',
14054
+ 'background-origin',
14055
+ 'background-position',
14056
+ 'background-repeat',
14057
+ 'background-size',
14058
+ 'float',
14059
+ 'position',
14060
+ 'left',
14061
+ 'right',
14062
+ 'top',
14063
+ 'bottom',
14064
+ 'z-index',
14065
+ 'display',
14066
+ 'transform',
14067
+ 'width',
14068
+ 'max-width',
14069
+ 'min-width',
14070
+ 'height',
14071
+ 'max-height',
14072
+ 'min-height',
14073
+ 'overflow',
14074
+ 'overflow-x',
14075
+ 'overflow-y',
14076
+ 'text-overflow',
14077
+ 'vertical-align',
14078
+ 'transition',
14079
+ 'transition-delay',
14080
+ 'transition-duration',
14081
+ 'transition-property',
14082
+ 'transition-timing-function'
14083
+ ];
14084
+ each(nonInheritableStylesArr, function (style) {
14085
+ nonInheritableStyles.add(style);
14086
+ });
14087
+ }());
14088
+ var shorthandStyleProps = [
14089
+ 'font',
14090
+ 'text-decoration',
14091
+ 'text-emphasis'
14092
+ ];
14093
+ var getStyleProps = function (dom, node) {
14094
+ return keys(dom.parseStyle(dom.getAttrib(node, 'style')));
14095
+ };
14096
+ var isNonInheritableStyle = function (style) {
14097
+ return nonInheritableStyles.has(style);
14098
+ };
14099
+ var hasInheritableStyles = function (dom, node) {
14100
+ return forall(getStyleProps(dom, node), function (style) {
14101
+ return !isNonInheritableStyle(style);
14102
+ });
14103
+ };
14104
+ var getLonghandStyleProps = function (styles) {
14105
+ return filter(styles, function (style) {
14106
+ return exists(shorthandStyleProps, function (prop) {
14107
+ return startsWith(style, prop);
14108
+ });
14109
+ });
14110
+ };
14111
+ var hasStyleConflict = function (dom, node, parentNode) {
14112
+ var nodeStyleProps = getStyleProps(dom, node);
14113
+ var parentNodeStyleProps = getStyleProps(dom, parentNode);
14114
+ var valueMismatch = function (prop) {
14115
+ var nodeValue = dom.getStyle(node, prop);
14116
+ var parentValue = dom.getStyle(parentNode, prop);
14117
+ return isNotEmpty(nodeValue) && isNotEmpty(parentValue) && nodeValue !== parentValue;
14118
+ };
14119
+ return exists(nodeStyleProps, function (nodeStyleProp) {
14120
+ var propExists = function (props) {
14121
+ return exists(props, function (prop) {
14122
+ return prop === nodeStyleProp;
14123
+ });
14124
+ };
14125
+ if (!propExists(parentNodeStyleProps) && propExists(shorthandStyleProps)) {
14126
+ var longhandProps = getLonghandStyleProps(parentNodeStyleProps);
14127
+ return exists(longhandProps, valueMismatch);
14128
+ } else {
14129
+ return valueMismatch(nodeStyleProp);
14130
+ }
14131
+ });
14132
+ };
14133
+
14023
14134
  var isChar = function (forward, predicate, pos) {
14024
14135
  return Optional.from(pos.container()).filter(isText$1).exists(function (text) {
14025
14136
  var delta = forward ? 0 : -1;
@@ -14949,11 +15060,20 @@
14949
15060
  var textInlineElements = editor.schema.getTextInlineElements();
14950
15061
  var dom = editor.dom;
14951
15062
  if (merge) {
14952
- var root_1 = editor.getBody(), elementUtils_1 = ElementUtils(dom);
15063
+ var root_1 = editor.getBody();
15064
+ var elementUtils_1 = ElementUtils(dom);
14953
15065
  Tools.each(dom.select('*[data-mce-fragment]'), function (node) {
14954
- for (var testNode = node.parentNode; testNode && testNode !== root_1; testNode = testNode.parentNode) {
14955
- if (textInlineElements[node.nodeName.toLowerCase()] && elementUtils_1.compare(testNode, node)) {
14956
- dom.remove(node, true);
15066
+ var isInline = isNonNullable(textInlineElements[node.nodeName.toLowerCase()]);
15067
+ if (isInline && hasInheritableStyles(dom, node)) {
15068
+ for (var parentNode = node.parentNode; isNonNullable(parentNode) && parentNode !== root_1; parentNode = parentNode.parentNode) {
15069
+ var styleConflict = hasStyleConflict(dom, node, parentNode);
15070
+ if (styleConflict) {
15071
+ break;
15072
+ }
15073
+ if (elementUtils_1.compare(parentNode, node)) {
15074
+ dom.remove(node, true);
15075
+ break;
15076
+ }
14957
15077
  }
14958
15078
  }
14959
15079
  });
@@ -15404,7 +15524,7 @@
15404
15524
  if (matchName(ed.dom, node, format) && matchItems(dom, node, format, 'attributes', similar, vars) && matchItems(dom, node, format, 'styles', similar, vars)) {
15405
15525
  if (classes = format.classes) {
15406
15526
  for (x = 0; x < classes.length; x++) {
15407
- if (!ed.dom.hasClass(node, classes[x])) {
15527
+ if (!ed.dom.hasClass(node, replaceVars(classes[x], vars))) {
15408
15528
  return;
15409
15529
  }
15410
15530
  }
@@ -16145,6 +16265,10 @@
16145
16265
  };
16146
16266
  var process = function (node) {
16147
16267
  var lastContentEditable, hasContentEditableState;
16268
+ var parentNode = node.parentNode;
16269
+ if (isText$1(node) && hasBlockChildren(dom, parentNode)) {
16270
+ removeFormat(ed, format, vars, parentNode, parentNode);
16271
+ }
16148
16272
  if (isElement$1(node) && dom.getContentEditable(node)) {
16149
16273
  lastContentEditable = contentEditable;
16150
16274
  contentEditable = dom.getContentEditable(node) === 'true';
@@ -16465,6 +16589,9 @@
16465
16589
  }
16466
16590
  if (isSelectorFormat(format)) {
16467
16591
  var found = applyNodeStyle(formatList, node);
16592
+ if (isText$1(node) && hasBlockChildren(dom, node.parentNode)) {
16593
+ applyNodeStyle(formatList, node.parentNode);
16594
+ }
16468
16595
  if (!hasFormatProperty(format, 'inline') || found) {
16469
16596
  currentWrapElm = null;
16470
16597
  return;
@@ -17638,13 +17765,18 @@
17638
17765
  var isRtc = function (editor) {
17639
17766
  return has(editor.plugins, 'rtc');
17640
17767
  };
17768
+ var getRtcSetup = function (editor) {
17769
+ return get$1(editor.plugins, 'rtc').bind(function (rtcPlugin) {
17770
+ return Optional.from(rtcPlugin.setup);
17771
+ });
17772
+ };
17641
17773
  var setup$5 = function (editor) {
17642
17774
  var editorCast = editor;
17643
- return get$1(editor.plugins, 'rtc').fold(function () {
17775
+ return getRtcSetup(editor).fold(function () {
17644
17776
  editorCast.rtcInstance = makePlainAdaptor(editor);
17645
17777
  return Optional.none();
17646
- }, function (rtc) {
17647
- return Optional.some(rtc.setup().then(function (rtcEditor) {
17778
+ }, function (setup) {
17779
+ return Optional.some(setup().then(function (rtcEditor) {
17648
17780
  editorCast.rtcInstance = makeRtcAdaptor(rtcEditor);
17649
17781
  return rtcEditor.rtc.isRemote;
17650
17782
  }, function (err) {
@@ -20669,7 +20801,7 @@
20669
20801
  defaultBlock: 'div'
20670
20802
  },
20671
20803
  {
20672
- selector: 'img,table',
20804
+ selector: 'img,table,audio,video',
20673
20805
  collapsed: false,
20674
20806
  styles: { float: 'left' },
20675
20807
  preview: 'font-family font-size'
@@ -20691,7 +20823,7 @@
20691
20823
  preview: 'font-family font-size'
20692
20824
  },
20693
20825
  {
20694
- selector: 'img',
20826
+ selector: 'img,audio,video',
20695
20827
  collapsed: false,
20696
20828
  styles: {
20697
20829
  display: 'block',
@@ -20726,7 +20858,7 @@
20726
20858
  defaultBlock: 'div'
20727
20859
  },
20728
20860
  {
20729
- selector: 'img,table',
20861
+ selector: 'img,table,audio,video',
20730
20862
  collapsed: false,
20731
20863
  styles: { float: 'right' },
20732
20864
  preview: 'font-family font-size'
@@ -20881,7 +21013,7 @@
20881
21013
  },
20882
21014
  removeformat: [
20883
21015
  {
20884
- selector: 'b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins',
21016
+ selector: 'b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,small',
20885
21017
  remove: 'all',
20886
21018
  split: true,
20887
21019
  expand: false,
@@ -20911,7 +21043,7 @@
20911
21043
  }
20912
21044
  ]
20913
21045
  };
20914
- Tools.each('p h1 h2 h3 h4 h5 h6 div address pre div dt dd samp'.split(/\s/), function (name) {
21046
+ Tools.each('p h1 h2 h3 h4 h5 h6 div address pre dt dd samp'.split(/\s/), function (name) {
20915
21047
  formats[name] = {
20916
21048
  block: name,
20917
21049
  remove: 'all'
@@ -22330,978 +22462,995 @@
22330
22462
  }
22331
22463
  };
22332
22464
 
22333
- var setCaretPosition = function (editor, pos) {
22334
- var rng = editor.dom.createRng();
22335
- rng.setStart(pos.container(), pos.offset());
22336
- rng.setEnd(pos.container(), pos.offset());
22337
- editor.selection.setRng(rng);
22465
+ var BreakType;
22466
+ (function (BreakType) {
22467
+ BreakType[BreakType['Br'] = 0] = 'Br';
22468
+ BreakType[BreakType['Block'] = 1] = 'Block';
22469
+ BreakType[BreakType['Wrap'] = 2] = 'Wrap';
22470
+ BreakType[BreakType['Eol'] = 3] = 'Eol';
22471
+ }(BreakType || (BreakType = {})));
22472
+ var flip = function (direction, positions) {
22473
+ return direction === HDirection.Backwards ? reverse(positions) : positions;
22338
22474
  };
22339
- var setSelected = function (state, elm) {
22340
- if (state) {
22341
- elm.setAttribute('data-mce-selected', 'inline-boundary');
22475
+ var walk$3 = function (direction, caretWalker, pos) {
22476
+ return direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos);
22477
+ };
22478
+ var getBreakType = function (scope, direction, currentPos, nextPos) {
22479
+ if (isBr(nextPos.getNode(direction === HDirection.Forwards))) {
22480
+ return BreakType.Br;
22481
+ } else if (isInSameBlock(currentPos, nextPos) === false) {
22482
+ return BreakType.Block;
22342
22483
  } else {
22343
- elm.removeAttribute('data-mce-selected');
22484
+ return BreakType.Wrap;
22344
22485
  }
22345
22486
  };
22346
- var renderCaretLocation = function (editor, caret, location) {
22347
- return renderCaret(caret, location).map(function (pos) {
22348
- setCaretPosition(editor, pos);
22349
- return location;
22350
- });
22351
- };
22352
- var findLocation$1 = function (editor, caret, forward) {
22353
- var rootNode = editor.getBody();
22354
- var from = CaretPosition.fromRangeStart(editor.selection.getRng());
22355
- var isInlineTarget$1 = curry(isInlineTarget, editor);
22356
- var location = findLocation(forward, isInlineTarget$1, rootNode, from);
22357
- return location.bind(function (location) {
22358
- return renderCaretLocation(editor, caret, location);
22359
- });
22360
- };
22361
- var toggleInlines = function (isInlineTarget, dom, elms) {
22362
- var inlineBoundaries = map(descendants$1(SugarElement.fromDom(dom.getRoot()), '*[data-mce-selected="inline-boundary"]'), function (e) {
22363
- return e.dom;
22364
- });
22365
- var selectedInlines = filter(inlineBoundaries, isInlineTarget);
22366
- var targetInlines = filter(elms, isInlineTarget);
22367
- each(difference(selectedInlines, targetInlines), curry(setSelected, false));
22368
- each(difference(targetInlines, selectedInlines), curry(setSelected, true));
22369
- };
22370
- var safeRemoveCaretContainer = function (editor, caret) {
22371
- if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) {
22372
- var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
22373
- if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) {
22374
- setCaretPosition(editor, removeAndReposition(caret.get(), pos));
22375
- caret.set(null);
22487
+ var getPositionsUntil = function (predicate, direction, scope, start) {
22488
+ var caretWalker = CaretWalker(scope);
22489
+ var currentPos = start, nextPos;
22490
+ var positions = [];
22491
+ while (currentPos) {
22492
+ nextPos = walk$3(direction, caretWalker, currentPos);
22493
+ if (!nextPos) {
22494
+ break;
22376
22495
  }
22496
+ if (isBr(nextPos.getNode(false))) {
22497
+ if (direction === HDirection.Forwards) {
22498
+ return {
22499
+ positions: flip(direction, positions).concat([nextPos]),
22500
+ breakType: BreakType.Br,
22501
+ breakAt: Optional.some(nextPos)
22502
+ };
22503
+ } else {
22504
+ return {
22505
+ positions: flip(direction, positions),
22506
+ breakType: BreakType.Br,
22507
+ breakAt: Optional.some(nextPos)
22508
+ };
22509
+ }
22510
+ }
22511
+ if (!nextPos.isVisible()) {
22512
+ currentPos = nextPos;
22513
+ continue;
22514
+ }
22515
+ if (predicate(currentPos, nextPos)) {
22516
+ var breakType = getBreakType(scope, direction, currentPos, nextPos);
22517
+ return {
22518
+ positions: flip(direction, positions),
22519
+ breakType: breakType,
22520
+ breakAt: Optional.some(nextPos)
22521
+ };
22522
+ }
22523
+ positions.push(nextPos);
22524
+ currentPos = nextPos;
22377
22525
  }
22526
+ return {
22527
+ positions: flip(direction, positions),
22528
+ breakType: BreakType.Eol,
22529
+ breakAt: Optional.none()
22530
+ };
22378
22531
  };
22379
- var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) {
22380
- if (editor.selection.isCollapsed()) {
22381
- var inlines = filter(elms, isInlineTarget);
22382
- each(inlines, function (_inline) {
22383
- var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
22384
- readLocation(isInlineTarget, editor.getBody(), pos).bind(function (location) {
22385
- return renderCaretLocation(editor, caret, location);
22386
- });
22387
- });
22388
- }
22389
- };
22390
- var move = function (editor, caret, forward) {
22391
- return isInlineBoundariesEnabled(editor) ? findLocation$1(editor, caret, forward).isSome() : false;
22532
+ var getAdjacentLinePositions = function (direction, getPositionsUntilBreak, scope, start) {
22533
+ return getPositionsUntilBreak(scope, start).breakAt.map(function (pos) {
22534
+ var positions = getPositionsUntilBreak(scope, pos).positions;
22535
+ return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions);
22536
+ }).getOr([]);
22392
22537
  };
22393
- var moveWord = function (forward, editor, _caret) {
22394
- return isInlineBoundariesEnabled(editor) ? moveByWord(forward, editor) : false;
22538
+ var findClosestHorizontalPositionFromPoint = function (positions, x) {
22539
+ return foldl(positions, function (acc, newPos) {
22540
+ return acc.fold(function () {
22541
+ return Optional.some(newPos);
22542
+ }, function (lastPos) {
22543
+ return lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), function (lastRect, newRect) {
22544
+ var lastDist = Math.abs(x - lastRect.left);
22545
+ var newDist = Math.abs(x - newRect.left);
22546
+ return newDist <= lastDist ? newPos : lastPos;
22547
+ }).or(acc);
22548
+ });
22549
+ }, Optional.none());
22395
22550
  };
22396
- var setupSelectedState = function (editor) {
22397
- var caret = Cell(null);
22398
- var isInlineTarget$1 = curry(isInlineTarget, editor);
22399
- editor.on('NodeChange', function (e) {
22400
- if (isInlineBoundariesEnabled(editor) && !(Env.browser.isIE() && e.initial)) {
22401
- toggleInlines(isInlineTarget$1, editor.dom, e.parents);
22402
- safeRemoveCaretContainer(editor, caret);
22403
- renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents);
22404
- }
22551
+ var findClosestHorizontalPosition = function (positions, pos) {
22552
+ return head(pos.getClientRects()).bind(function (targetRect) {
22553
+ return findClosestHorizontalPositionFromPoint(positions, targetRect.left);
22405
22554
  });
22406
- return caret;
22407
22555
  };
22408
- var moveNextWord = curry(moveWord, true);
22409
- var movePrevWord = curry(moveWord, false);
22410
-
22411
- var rangeFromPositions = function (from, to) {
22412
- var range = document.createRange();
22413
- range.setStart(from.container(), from.offset());
22414
- range.setEnd(to.container(), to.offset());
22415
- return range;
22556
+ var getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1);
22557
+ var getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1);
22558
+ var isAtFirstLine = function (scope, pos) {
22559
+ return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone();
22416
22560
  };
22417
- var hasOnlyTwoOrLessPositionsLeft = function (elm) {
22418
- return lift2(firstPositionIn(elm), lastPositionIn(elm), function (firstPos, lastPos) {
22419
- var normalizedFirstPos = normalizePosition(true, firstPos);
22420
- var normalizedLastPos = normalizePosition(false, lastPos);
22421
- return nextPosition(elm, normalizedFirstPos).forall(function (pos) {
22422
- return pos.isEqual(normalizedLastPos);
22423
- });
22424
- }).getOr(true);
22561
+ var isAtLastLine = function (scope, pos) {
22562
+ return getPositionsUntilNextLine(scope, pos).breakAt.isNone();
22425
22563
  };
22426
- var setCaretLocation = function (editor, caret) {
22427
- return function (location) {
22428
- return renderCaret(caret, location).exists(function (pos) {
22429
- setCaretPosition(editor, pos);
22430
- return true;
22564
+ var getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine);
22565
+ var getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine);
22566
+ var getFirstLinePositions = function (scope) {
22567
+ return firstPositionIn(scope).map(function (pos) {
22568
+ return [pos].concat(getPositionsUntilNextLine(scope, pos).positions);
22569
+ }).getOr([]);
22570
+ };
22571
+ var getLastLinePositions = function (scope) {
22572
+ return lastPositionIn(scope).map(function (pos) {
22573
+ return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos);
22574
+ }).getOr([]);
22575
+ };
22576
+
22577
+ var getNodeClientRects = function (node) {
22578
+ var toArrayWithNode = function (clientRects) {
22579
+ return map(clientRects, function (clientRect) {
22580
+ clientRect = clone$2(clientRect);
22581
+ clientRect.node = node;
22582
+ return clientRect;
22431
22583
  });
22432
22584
  };
22585
+ if (isElement$1(node)) {
22586
+ return toArrayWithNode(node.getClientRects());
22587
+ }
22588
+ if (isText$1(node)) {
22589
+ var rng = node.ownerDocument.createRange();
22590
+ rng.setStart(node, 0);
22591
+ rng.setEnd(node, node.data.length);
22592
+ return toArrayWithNode(rng.getClientRects());
22593
+ }
22433
22594
  };
22434
- var deleteFromTo = function (editor, caret, from, to) {
22435
- var rootNode = editor.getBody();
22436
- var isInlineTarget$1 = curry(isInlineTarget, editor);
22437
- editor.undoManager.ignore(function () {
22438
- editor.selection.setRng(rangeFromPositions(from, to));
22439
- editor.execCommand('Delete');
22440
- readLocation(isInlineTarget$1, rootNode, CaretPosition.fromRangeStart(editor.selection.getRng())).map(inside).map(setCaretLocation(editor, caret));
22441
- });
22442
- editor.nodeChanged();
22443
- };
22444
- var rescope$1 = function (rootNode, node) {
22445
- var parentBlock = getParentBlock(node, rootNode);
22446
- return parentBlock ? parentBlock : rootNode;
22595
+ var getClientRects = function (nodes) {
22596
+ return bind(nodes, getNodeClientRects);
22447
22597
  };
22448
- var backspaceDeleteCollapsed = function (editor, caret, forward, from) {
22449
- var rootNode = rescope$1(editor.getBody(), from.container());
22450
- var isInlineTarget$1 = curry(isInlineTarget, editor);
22451
- var fromLocation = readLocation(isInlineTarget$1, rootNode, from);
22452
- return fromLocation.bind(function (location) {
22453
- if (forward) {
22454
- return location.fold(constant(Optional.some(inside(location))), Optional.none, constant(Optional.some(outside(location))), Optional.none);
22455
- } else {
22456
- return location.fold(Optional.none, constant(Optional.some(outside(location))), Optional.none, constant(Optional.some(inside(location))));
22598
+
22599
+ var VDirection;
22600
+ (function (VDirection) {
22601
+ VDirection[VDirection['Up'] = -1] = 'Up';
22602
+ VDirection[VDirection['Down'] = 1] = 'Down';
22603
+ }(VDirection || (VDirection = {})));
22604
+ var findUntil$1 = function (direction, root, predicateFn, node) {
22605
+ while (node = findNode(node, direction, isEditableCaretCandidate, root)) {
22606
+ if (predicateFn(node)) {
22607
+ return;
22457
22608
  }
22458
- }).map(setCaretLocation(editor, caret)).getOrThunk(function () {
22459
- var toPosition = navigate(forward, rootNode, from);
22460
- var toLocation = toPosition.bind(function (pos) {
22461
- return readLocation(isInlineTarget$1, rootNode, pos);
22462
- });
22463
- return lift2(fromLocation, toLocation, function () {
22464
- return findRootInline(isInlineTarget$1, rootNode, from).exists(function (elm) {
22465
- if (hasOnlyTwoOrLessPositionsLeft(elm)) {
22466
- deleteElement(editor, forward, SugarElement.fromDom(elm));
22467
- return true;
22468
- } else {
22469
- return false;
22470
- }
22471
- });
22472
- }).orThunk(function () {
22473
- return toLocation.bind(function (_) {
22474
- return toPosition.map(function (to) {
22475
- if (forward) {
22476
- deleteFromTo(editor, caret, from, to);
22477
- } else {
22478
- deleteFromTo(editor, caret, to, from);
22479
- }
22480
- return true;
22481
- });
22482
- });
22483
- }).getOr(false);
22484
- });
22609
+ }
22485
22610
  };
22486
- var backspaceDelete$6 = function (editor, caret, forward) {
22487
- if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) {
22488
- var from = CaretPosition.fromRangeStart(editor.selection.getRng());
22489
- return backspaceDeleteCollapsed(editor, caret, forward, from);
22611
+ var walkUntil = function (direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) {
22612
+ var line = 0;
22613
+ var result = [];
22614
+ var add = function (node) {
22615
+ var i, clientRect, clientRects;
22616
+ clientRects = getClientRects([node]);
22617
+ if (direction === -1) {
22618
+ clientRects = clientRects.reverse();
22619
+ }
22620
+ for (i = 0; i < clientRects.length; i++) {
22621
+ clientRect = clientRects[i];
22622
+ if (isBeflowFn(clientRect, targetClientRect)) {
22623
+ continue;
22624
+ }
22625
+ if (result.length > 0 && isAboveFn(clientRect, last$1(result))) {
22626
+ line++;
22627
+ }
22628
+ clientRect.line = line;
22629
+ if (predicateFn(clientRect)) {
22630
+ return true;
22631
+ }
22632
+ result.push(clientRect);
22633
+ }
22634
+ };
22635
+ var targetClientRect = last$1(caretPosition.getClientRects());
22636
+ if (!targetClientRect) {
22637
+ return result;
22490
22638
  }
22491
- return false;
22639
+ var node = caretPosition.getNode();
22640
+ add(node);
22641
+ findUntil$1(direction, root, add, node);
22642
+ return result;
22492
22643
  };
22493
-
22494
- var getParentInlines = function (rootElm, startElm) {
22495
- var parents = parentsAndSelf(startElm, rootElm);
22496
- return findIndex(parents, isBlock).fold(constant(parents), function (index) {
22497
- return parents.slice(0, index);
22498
- });
22644
+ var aboveLineNumber = function (lineNumber, clientRect) {
22645
+ return clientRect.line > lineNumber;
22499
22646
  };
22500
- var hasOnlyOneChild$1 = function (elm) {
22501
- return children(elm).length === 1;
22647
+ var isLineNumber = function (lineNumber, clientRect) {
22648
+ return clientRect.line === lineNumber;
22502
22649
  };
22503
- var deleteLastPosition = function (forward, editor, target, parentInlines) {
22504
- var isFormatElement$1 = curry(isFormatElement, editor);
22505
- var formatNodes = map(filter(parentInlines, isFormatElement$1), function (elm) {
22506
- return elm.dom;
22507
- });
22508
- if (formatNodes.length === 0) {
22509
- deleteElement(editor, forward, target);
22650
+ var upUntil = curry(walkUntil, VDirection.Up, isAbove, isBelow);
22651
+ var downUntil = curry(walkUntil, VDirection.Down, isBelow, isAbove);
22652
+ var positionsUntil = function (direction, root, predicateFn, node) {
22653
+ var caretWalker = CaretWalker(root);
22654
+ var walkFn, isBelowFn, isAboveFn, caretPosition;
22655
+ var result = [];
22656
+ var line = 0, clientRect;
22657
+ var getClientRect = function (caretPosition) {
22658
+ if (direction === 1) {
22659
+ return last$1(caretPosition.getClientRects());
22660
+ }
22661
+ return last$1(caretPosition.getClientRects());
22662
+ };
22663
+ if (direction === 1) {
22664
+ walkFn = caretWalker.next;
22665
+ isBelowFn = isBelow;
22666
+ isAboveFn = isAbove;
22667
+ caretPosition = CaretPosition.after(node);
22510
22668
  } else {
22511
- var pos = replaceWithCaretFormat(target.dom, formatNodes);
22512
- editor.selection.setRng(pos.toRange());
22669
+ walkFn = caretWalker.prev;
22670
+ isBelowFn = isAbove;
22671
+ isAboveFn = isBelow;
22672
+ caretPosition = CaretPosition.before(node);
22513
22673
  }
22514
- };
22515
- var deleteCaret$2 = function (editor, forward) {
22516
- var rootElm = SugarElement.fromDom(editor.getBody());
22517
- var startElm = SugarElement.fromDom(editor.selection.getStart());
22518
- var parentInlines = filter(getParentInlines(rootElm, startElm), hasOnlyOneChild$1);
22519
- return last(parentInlines).exists(function (target) {
22520
- var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
22521
- if (willDeleteLastPositionInElement(forward, fromPos, target.dom) && !isEmptyCaretFormatElement(target)) {
22522
- deleteLastPosition(forward, editor, target, parentInlines);
22523
- return true;
22524
- } else {
22525
- return false;
22674
+ var targetClientRect = getClientRect(caretPosition);
22675
+ do {
22676
+ if (!caretPosition.isVisible()) {
22677
+ continue;
22526
22678
  }
22527
- });
22679
+ clientRect = getClientRect(caretPosition);
22680
+ if (isAboveFn(clientRect, targetClientRect)) {
22681
+ continue;
22682
+ }
22683
+ if (result.length > 0 && isBelowFn(clientRect, last$1(result))) {
22684
+ line++;
22685
+ }
22686
+ clientRect = clone$2(clientRect);
22687
+ clientRect.position = caretPosition;
22688
+ clientRect.line = line;
22689
+ if (predicateFn(clientRect)) {
22690
+ return result;
22691
+ }
22692
+ result.push(clientRect);
22693
+ } while (caretPosition = walkFn(caretPosition));
22694
+ return result;
22528
22695
  };
22529
- var backspaceDelete$7 = function (editor, forward) {
22530
- return editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : false;
22696
+ var isAboveLine = function (lineNumber) {
22697
+ return function (clientRect) {
22698
+ return aboveLineNumber(lineNumber, clientRect);
22699
+ };
22700
+ };
22701
+ var isLine = function (lineNumber) {
22702
+ return function (clientRect) {
22703
+ return isLineNumber(lineNumber, clientRect);
22704
+ };
22531
22705
  };
22532
22706
 
22533
- var deleteElement$2 = function (editor, forward, element) {
22534
- editor._selectionOverrides.hideFakeCaret();
22535
- deleteElement(editor, forward, SugarElement.fromDom(element));
22536
- return true;
22707
+ var isContentEditableFalse$8 = isContentEditableFalse;
22708
+ var findNode$1 = findNode;
22709
+ var distanceToRectLeft = function (clientRect, clientX) {
22710
+ return Math.abs(clientRect.left - clientX);
22537
22711
  };
22538
- var deleteCaret$3 = function (editor, forward) {
22539
- var isNearMedia = forward ? isBeforeMedia : isAfterMedia;
22540
- var direction = forward ? HDirection.Forwards : HDirection.Backwards;
22541
- var fromPos = getNormalizedRangeEndPoint(direction, editor.getBody(), editor.selection.getRng());
22542
- if (isNearMedia(fromPos)) {
22543
- return deleteElement$2(editor, forward, fromPos.getNode(!forward));
22544
- } else {
22545
- return Optional.from(normalizePosition(forward, fromPos)).filter(function (pos) {
22546
- return isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos);
22547
- }).exists(function (pos) {
22548
- return deleteElement$2(editor, forward, pos.getNode(!forward));
22549
- });
22550
- }
22712
+ var distanceToRectRight = function (clientRect, clientX) {
22713
+ return Math.abs(clientRect.right - clientX);
22551
22714
  };
22552
- var deleteRange$2 = function (editor, forward) {
22553
- var selectedNode = editor.selection.getNode();
22554
- return isMedia(selectedNode) ? deleteElement$2(editor, forward, selectedNode) : false;
22715
+ var isInsideX = function (clientX, clientRect) {
22716
+ return clientX >= clientRect.left && clientX <= clientRect.right;
22555
22717
  };
22556
- var backspaceDelete$8 = function (editor, forward) {
22557
- return editor.selection.isCollapsed() ? deleteCaret$3(editor, forward) : deleteRange$2(editor, forward);
22718
+ var isInsideY = function (clientY, clientRect) {
22719
+ return clientY >= clientRect.top && clientY <= clientRect.bottom;
22558
22720
  };
22559
-
22560
- var isEditable$1 = function (target) {
22561
- return closest(target, function (elm) {
22562
- return isContentEditableTrue(elm.dom) || isContentEditableFalse(elm.dom);
22563
- }).exists(function (elm) {
22564
- return isContentEditableTrue(elm.dom);
22721
+ var findClosestClientRect = function (clientRects, clientX) {
22722
+ return reduce(clientRects, function (oldClientRect, clientRect) {
22723
+ var oldDistance = Math.min(distanceToRectLeft(oldClientRect, clientX), distanceToRectRight(oldClientRect, clientX));
22724
+ var newDistance = Math.min(distanceToRectLeft(clientRect, clientX), distanceToRectRight(clientRect, clientX));
22725
+ if (isInsideX(clientX, clientRect)) {
22726
+ return clientRect;
22727
+ }
22728
+ if (isInsideX(clientX, oldClientRect)) {
22729
+ return oldClientRect;
22730
+ }
22731
+ if (newDistance === oldDistance && isContentEditableFalse$8(clientRect.node)) {
22732
+ return clientRect;
22733
+ }
22734
+ if (newDistance < oldDistance) {
22735
+ return clientRect;
22736
+ }
22737
+ return oldClientRect;
22565
22738
  });
22566
22739
  };
22567
- var parseIndentValue = function (value) {
22568
- var number = parseInt(value, 10);
22569
- return isNaN(number) ? 0 : number;
22570
- };
22571
- var getIndentStyleName = function (useMargin, element) {
22572
- var indentStyleName = useMargin || isTable$1(element) ? 'margin' : 'padding';
22573
- var suffix = get$5(element, 'direction') === 'rtl' ? '-right' : '-left';
22574
- return indentStyleName + suffix;
22740
+ var walkUntil$1 = function (direction, root, predicateFn, startNode, includeChildren) {
22741
+ var node = findNode$1(startNode, direction, isEditableCaretCandidate, root, !includeChildren);
22742
+ do {
22743
+ if (!node || predicateFn(node)) {
22744
+ return;
22745
+ }
22746
+ } while (node = findNode$1(node, direction, isEditableCaretCandidate, root));
22575
22747
  };
22576
- var indentElement = function (dom, command, useMargin, value, unit, element) {
22577
- var indentStyleName = getIndentStyleName(useMargin, SugarElement.fromDom(element));
22578
- if (command === 'outdent') {
22579
- var styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value);
22580
- dom.setStyle(element, indentStyleName, styleValue ? styleValue + unit : '');
22581
- } else {
22582
- var styleValue = parseIndentValue(element.style[indentStyleName]) + value + unit;
22583
- dom.setStyle(element, indentStyleName, styleValue);
22748
+ var findLineNodeRects = function (root, targetNodeRect, includeChildren) {
22749
+ if (includeChildren === void 0) {
22750
+ includeChildren = true;
22584
22751
  }
22752
+ var clientRects = [];
22753
+ var collect = function (checkPosFn, node) {
22754
+ var lineRects = filter(getClientRects([node]), function (clientRect) {
22755
+ return !checkPosFn(clientRect, targetNodeRect);
22756
+ });
22757
+ clientRects = clientRects.concat(lineRects);
22758
+ return lineRects.length === 0;
22759
+ };
22760
+ clientRects.push(targetNodeRect);
22761
+ walkUntil$1(VDirection.Up, root, curry(collect, isAbove), targetNodeRect.node, includeChildren);
22762
+ walkUntil$1(VDirection.Down, root, curry(collect, isBelow), targetNodeRect.node, includeChildren);
22763
+ return clientRects;
22585
22764
  };
22586
- var validateBlocks = function (editor, blocks) {
22587
- return forall(blocks, function (block) {
22588
- var indentStyleName = getIndentStyleName(shouldIndentUseMargin(editor), block);
22589
- var intentValue = getRaw(block, indentStyleName).map(parseIndentValue).getOr(0);
22590
- var contentEditable = editor.dom.getContentEditable(block.dom);
22591
- return contentEditable !== 'false' && intentValue > 0;
22592
- });
22765
+ var getFakeCaretTargets = function (root) {
22766
+ return filter(from$1(root.getElementsByTagName('*')), isFakeCaretTarget);
22593
22767
  };
22594
- var canOutdent = function (editor) {
22595
- var blocks = getBlocksToIndent(editor);
22596
- return !editor.mode.isReadOnly() && (blocks.length > 1 || validateBlocks(editor, blocks));
22768
+ var caretInfo = function (clientRect, clientX) {
22769
+ return {
22770
+ node: clientRect.node,
22771
+ before: distanceToRectLeft(clientRect, clientX) < distanceToRectRight(clientRect, clientX)
22772
+ };
22597
22773
  };
22598
- var isListComponent = function (el) {
22599
- return isList(el) || isListItem(el);
22774
+ var closestFakeCaret = function (root, clientX, clientY) {
22775
+ var fakeTargetNodeRects = getClientRects(getFakeCaretTargets(root));
22776
+ var targetNodeRects = filter(fakeTargetNodeRects, curry(isInsideY, clientY));
22777
+ var closestNodeRect = findClosestClientRect(targetNodeRects, clientX);
22778
+ if (closestNodeRect) {
22779
+ var includeChildren = !isTable(closestNodeRect.node) && !isMedia(closestNodeRect.node);
22780
+ closestNodeRect = findClosestClientRect(findLineNodeRects(root, closestNodeRect, includeChildren), clientX);
22781
+ if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
22782
+ return caretInfo(closestNodeRect, clientX);
22783
+ }
22784
+ }
22785
+ return null;
22600
22786
  };
22601
- var parentIsListComponent = function (el) {
22602
- return parent(el).map(isListComponent).getOr(false);
22787
+
22788
+ var moveToRange = function (editor, rng) {
22789
+ editor.selection.setRng(rng);
22790
+ scrollRangeIntoView(editor, editor.selection.getRng());
22603
22791
  };
22604
- var getBlocksToIndent = function (editor) {
22605
- return filter(map(editor.selection.getSelectedBlocks(), SugarElement.fromDom), function (el) {
22606
- return !isListComponent(el) && !parentIsListComponent(el) && isEditable$1(el);
22607
- });
22792
+ var renderRangeCaretOpt = function (editor, range, scrollIntoView) {
22793
+ return Optional.some(renderRangeCaret(editor, range, scrollIntoView));
22608
22794
  };
22609
- var handle = function (editor, command) {
22610
- var dom = editor.dom, selection = editor.selection, formatter = editor.formatter;
22611
- var indentation = getIndentation(editor);
22612
- var indentUnit = /[a-z%]+$/i.exec(indentation)[0];
22613
- var indentValue = parseInt(indentation, 10);
22614
- var useMargin = shouldIndentUseMargin(editor);
22615
- var forcedRootBlock = getForcedRootBlock(editor);
22616
- if (!editor.queryCommandState('InsertUnorderedList') && !editor.queryCommandState('InsertOrderedList')) {
22617
- if (forcedRootBlock === '' && !dom.getParent(selection.getNode(), dom.isBlock)) {
22618
- formatter.apply('div');
22795
+ var moveHorizontally = function (editor, direction, range, isBefore, isAfter, isElement) {
22796
+ var forwards = direction === HDirection.Forwards;
22797
+ var caretWalker = CaretWalker(editor.getBody());
22798
+ var getNextPosFn = curry(getVisualCaretPosition, forwards ? caretWalker.next : caretWalker.prev);
22799
+ var isBeforeFn = forwards ? isBefore : isAfter;
22800
+ if (!range.collapsed) {
22801
+ var node = getSelectedNode(range);
22802
+ if (isElement(node)) {
22803
+ return showCaret(direction, editor, node, direction === HDirection.Backwards, false);
22619
22804
  }
22620
22805
  }
22621
- each(getBlocksToIndent(editor), function (block) {
22622
- indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom);
22623
- });
22624
- };
22625
-
22626
- var backspaceDelete$9 = function (editor, _forward) {
22627
- if (editor.selection.isCollapsed() && canOutdent(editor)) {
22628
- var dom = editor.dom;
22629
- var rng = editor.selection.getRng();
22630
- var pos = CaretPosition.fromRangeStart(rng);
22631
- var block = dom.getParent(rng.startContainer, dom.isBlock);
22632
- if (block !== null && isAtStartOfBlock(SugarElement.fromDom(block), pos)) {
22633
- handle(editor, 'outdent');
22634
- return true;
22806
+ var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
22807
+ if (isBeforeFn(caretPosition)) {
22808
+ return selectNode(editor, caretPosition.getNode(!forwards));
22809
+ }
22810
+ var nextCaretPosition = normalizePosition(forwards, getNextPosFn(caretPosition));
22811
+ var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range);
22812
+ if (!nextCaretPosition) {
22813
+ return rangeIsInContainerBlock ? Optional.some(range) : Optional.none();
22814
+ }
22815
+ if (isBeforeFn(nextCaretPosition)) {
22816
+ return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, false);
22817
+ }
22818
+ var peekCaretPosition = getNextPosFn(nextCaretPosition);
22819
+ if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
22820
+ if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
22821
+ return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, false);
22635
22822
  }
22636
22823
  }
22637
- return false;
22824
+ if (rangeIsInContainerBlock) {
22825
+ return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false);
22826
+ }
22827
+ return Optional.none();
22638
22828
  };
22639
-
22640
- var nativeCommand = function (editor, command) {
22641
- editor.getDoc().execCommand(command, false, null);
22829
+ var moveVertically = function (editor, direction, range, isBefore, isAfter, isElement) {
22830
+ var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
22831
+ var caretClientRect = last$1(caretPosition.getClientRects());
22832
+ var forwards = direction === VDirection.Down;
22833
+ if (!caretClientRect) {
22834
+ return Optional.none();
22835
+ }
22836
+ var walkerFn = forwards ? downUntil : upUntil;
22837
+ var linePositions = walkerFn(editor.getBody(), isAboveLine(1), caretPosition);
22838
+ var nextLinePositions = filter(linePositions, isLine(1));
22839
+ var clientX = caretClientRect.left;
22840
+ var nextLineRect = findClosestClientRect(nextLinePositions, clientX);
22841
+ if (nextLineRect && isElement(nextLineRect.node)) {
22842
+ var dist1 = Math.abs(clientX - nextLineRect.left);
22843
+ var dist2 = Math.abs(clientX - nextLineRect.right);
22844
+ return showCaret(direction, editor, nextLineRect.node, dist1 < dist2, false);
22845
+ }
22846
+ var currentNode;
22847
+ if (isBefore(caretPosition)) {
22848
+ currentNode = caretPosition.getNode();
22849
+ } else if (isAfter(caretPosition)) {
22850
+ currentNode = caretPosition.getNode(true);
22851
+ } else {
22852
+ currentNode = getSelectedNode(range);
22853
+ }
22854
+ if (currentNode) {
22855
+ var caretPositions = positionsUntil(direction, editor.getBody(), isAboveLine(1), currentNode);
22856
+ var closestNextLineRect = findClosestClientRect(filter(caretPositions, isLine(1)), clientX);
22857
+ if (closestNextLineRect) {
22858
+ return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
22859
+ }
22860
+ closestNextLineRect = last$1(filter(caretPositions, isLine(0)));
22861
+ if (closestNextLineRect) {
22862
+ return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
22863
+ }
22864
+ }
22865
+ if (nextLinePositions.length === 0) {
22866
+ return getLineEndPoint(editor, forwards).filter(forwards ? isAfter : isBefore).map(function (pos) {
22867
+ return renderRangeCaret(editor, pos.toRange(), false);
22868
+ });
22869
+ }
22870
+ return Optional.none();
22642
22871
  };
22643
- var deleteCommand = function (editor, caret) {
22644
- if (backspaceDelete$9(editor)) {
22645
- return;
22646
- } else if (backspaceDelete$4(editor, false)) {
22647
- return;
22648
- } else if (backspaceDelete$3(editor, false)) {
22649
- return;
22650
- } else if (backspaceDelete$6(editor, caret, false)) {
22651
- return;
22652
- } else if (backspaceDelete$1(editor, false)) {
22653
- return;
22654
- } else if (backspaceDelete(editor)) {
22655
- return;
22656
- } else if (backspaceDelete$5(editor, false)) {
22657
- return;
22658
- } else if (backspaceDelete$8(editor, false)) {
22659
- return;
22660
- } else if (backspaceDelete$2(editor)) {
22661
- return;
22662
- } else if (backspaceDelete$7(editor, false)) {
22663
- return;
22872
+ var getLineEndPoint = function (editor, forward) {
22873
+ var rng = editor.selection.getRng();
22874
+ var body = editor.getBody();
22875
+ if (forward) {
22876
+ var from = CaretPosition.fromRangeEnd(rng);
22877
+ var result = getPositionsUntilNextLine(body, from);
22878
+ return last(result.positions);
22664
22879
  } else {
22665
- nativeCommand(editor, 'Delete');
22666
- paddEmptyBody(editor);
22880
+ var from = CaretPosition.fromRangeStart(rng);
22881
+ var result = getPositionsUntilPreviousLine(body, from);
22882
+ return head(result.positions);
22667
22883
  }
22668
22884
  };
22669
- var forwardDeleteCommand = function (editor, caret) {
22670
- if (backspaceDelete$4(editor, true)) {
22671
- return;
22672
- } else if (backspaceDelete$3(editor, true)) {
22673
- return;
22674
- } else if (backspaceDelete$6(editor, caret, true)) {
22675
- return;
22676
- } else if (backspaceDelete$1(editor, true)) {
22677
- return;
22678
- } else if (backspaceDelete(editor)) {
22679
- return;
22680
- } else if (backspaceDelete$5(editor, true)) {
22681
- return;
22682
- } else if (backspaceDelete$8(editor, true)) {
22683
- return;
22684
- } else if (backspaceDelete$2(editor)) {
22685
- return;
22686
- } else if (backspaceDelete$7(editor, true)) {
22687
- return;
22885
+ var moveToLineEndPoint = function (editor, forward, isElementPosition) {
22886
+ return getLineEndPoint(editor, forward).filter(isElementPosition).exists(function (pos) {
22887
+ editor.selection.setRng(pos.toRange());
22888
+ return true;
22889
+ });
22890
+ };
22891
+
22892
+ var setCaretPosition = function (editor, pos) {
22893
+ var rng = editor.dom.createRng();
22894
+ rng.setStart(pos.container(), pos.offset());
22895
+ rng.setEnd(pos.container(), pos.offset());
22896
+ editor.selection.setRng(rng);
22897
+ };
22898
+ var setSelected = function (state, elm) {
22899
+ if (state) {
22900
+ elm.setAttribute('data-mce-selected', 'inline-boundary');
22688
22901
  } else {
22689
- nativeCommand(editor, 'ForwardDelete');
22902
+ elm.removeAttribute('data-mce-selected');
22690
22903
  }
22691
22904
  };
22692
- var setup$8 = function (editor, caret) {
22693
- editor.addCommand('delete', function () {
22694
- deleteCommand(editor, caret);
22905
+ var renderCaretLocation = function (editor, caret, location) {
22906
+ return renderCaret(caret, location).map(function (pos) {
22907
+ setCaretPosition(editor, pos);
22908
+ return location;
22695
22909
  });
22696
- editor.addCommand('forwardDelete', function () {
22697
- forwardDeleteCommand(editor, caret);
22910
+ };
22911
+ var findLocation$1 = function (editor, caret, forward) {
22912
+ var rootNode = editor.getBody();
22913
+ var from = CaretPosition.fromRangeStart(editor.selection.getRng());
22914
+ var isInlineTarget$1 = curry(isInlineTarget, editor);
22915
+ var location = findLocation(forward, isInlineTarget$1, rootNode, from);
22916
+ return location.bind(function (location) {
22917
+ return renderCaretLocation(editor, caret, location);
22698
22918
  });
22699
22919
  };
22700
-
22701
- var SIGNIFICANT_MOVE = 5;
22702
- var LONGPRESS_DELAY = 400;
22703
- var getTouch = function (event) {
22704
- if (event.touches === undefined || event.touches.length !== 1) {
22705
- return Optional.none();
22706
- }
22707
- return Optional.some(event.touches[0]);
22920
+ var toggleInlines = function (isInlineTarget, dom, elms) {
22921
+ var inlineBoundaries = map(descendants$1(SugarElement.fromDom(dom.getRoot()), '*[data-mce-selected="inline-boundary"]'), function (e) {
22922
+ return e.dom;
22923
+ });
22924
+ var selectedInlines = filter(inlineBoundaries, isInlineTarget);
22925
+ var targetInlines = filter(elms, isInlineTarget);
22926
+ each(difference(selectedInlines, targetInlines), curry(setSelected, false));
22927
+ each(difference(targetInlines, selectedInlines), curry(setSelected, true));
22708
22928
  };
22709
- var isFarEnough = function (touch, data) {
22710
- var distX = Math.abs(touch.clientX - data.x);
22711
- var distY = Math.abs(touch.clientY - data.y);
22712
- return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
22929
+ var safeRemoveCaretContainer = function (editor, caret) {
22930
+ if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) {
22931
+ var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
22932
+ if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) {
22933
+ setCaretPosition(editor, removeAndReposition(caret.get(), pos));
22934
+ caret.set(null);
22935
+ }
22936
+ }
22713
22937
  };
22714
- var setup$9 = function (editor) {
22715
- var startData = Cell(Optional.none());
22716
- var longpressFired = Cell(false);
22717
- var debounceLongpress = last$2(function (e) {
22718
- editor.fire('longpress', __assign(__assign({}, e), { type: 'longpress' }));
22719
- longpressFired.set(true);
22720
- }, LONGPRESS_DELAY);
22721
- editor.on('touchstart', function (e) {
22722
- getTouch(e).each(function (touch) {
22723
- debounceLongpress.cancel();
22724
- var data = {
22725
- x: touch.clientX,
22726
- y: touch.clientY,
22727
- target: e.target
22728
- };
22729
- debounceLongpress.throttle(e);
22730
- longpressFired.set(false);
22731
- startData.set(Optional.some(data));
22732
- });
22733
- }, true);
22734
- editor.on('touchmove', function (e) {
22735
- debounceLongpress.cancel();
22736
- getTouch(e).each(function (touch) {
22737
- startData.get().each(function (data) {
22738
- if (isFarEnough(touch, data)) {
22739
- startData.set(Optional.none());
22740
- longpressFired.set(false);
22741
- editor.fire('longpresscancel');
22742
- }
22938
+ var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) {
22939
+ if (editor.selection.isCollapsed()) {
22940
+ var inlines = filter(elms, isInlineTarget);
22941
+ each(inlines, function (_inline) {
22942
+ var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
22943
+ readLocation(isInlineTarget, editor.getBody(), pos).bind(function (location) {
22944
+ return renderCaretLocation(editor, caret, location);
22743
22945
  });
22744
22946
  });
22745
- }, true);
22746
- editor.on('touchend touchcancel', function (e) {
22747
- debounceLongpress.cancel();
22748
- if (e.type === 'touchcancel') {
22749
- return;
22750
- }
22751
- startData.get().filter(function (data) {
22752
- return data.target.isEqualNode(e.target);
22753
- }).each(function () {
22754
- if (longpressFired.get()) {
22755
- e.preventDefault();
22756
- } else {
22757
- editor.fire('tap', __assign(__assign({}, e), { type: 'tap' }));
22758
- }
22759
- });
22760
- }, true);
22947
+ }
22761
22948
  };
22762
-
22763
- var isBlockElement = function (blockElements, node) {
22764
- return blockElements.hasOwnProperty(node.nodeName);
22949
+ var move = function (editor, caret, forward) {
22950
+ return isInlineBoundariesEnabled(editor) ? findLocation$1(editor, caret, forward).isSome() : false;
22765
22951
  };
22766
- var isValidTarget = function (blockElements, node) {
22767
- if (isText$1(node)) {
22768
- return true;
22769
- } else if (isElement$1(node)) {
22770
- return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node);
22952
+ var moveWord = function (forward, editor, _caret) {
22953
+ return isInlineBoundariesEnabled(editor) ? moveByWord(forward, editor) : false;
22954
+ };
22955
+ var setupSelectedState = function (editor) {
22956
+ var caret = Cell(null);
22957
+ var isInlineTarget$1 = curry(isInlineTarget, editor);
22958
+ editor.on('NodeChange', function (e) {
22959
+ if (isInlineBoundariesEnabled(editor) && !(Env.browser.isIE() && e.initial)) {
22960
+ toggleInlines(isInlineTarget$1, editor.dom, e.parents);
22961
+ safeRemoveCaretContainer(editor, caret);
22962
+ renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents);
22963
+ }
22964
+ });
22965
+ return caret;
22966
+ };
22967
+ var moveNextWord = curry(moveWord, true);
22968
+ var movePrevWord = curry(moveWord, false);
22969
+ var moveToLineEndPoint$1 = function (editor, forward, caret) {
22970
+ if (isInlineBoundariesEnabled(editor)) {
22971
+ var linePoint = getLineEndPoint(editor, forward).getOrThunk(function () {
22972
+ var rng = editor.selection.getRng();
22973
+ return forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng);
22974
+ });
22975
+ return readLocation(curry(isInlineTarget, editor), editor.getBody(), linePoint).exists(function (loc) {
22976
+ var outsideLoc = outside(loc);
22977
+ return renderCaret(caret, outsideLoc).exists(function (pos) {
22978
+ setCaretPosition(editor, pos);
22979
+ return true;
22980
+ });
22981
+ });
22771
22982
  } else {
22772
22983
  return false;
22773
22984
  }
22774
22985
  };
22775
- var hasBlockParent = function (blockElements, root, node) {
22776
- return exists(parents$1(SugarElement.fromDom(node), SugarElement.fromDom(root)), function (elm) {
22777
- return isBlockElement(blockElements, elm.dom);
22778
- });
22986
+
22987
+ var rangeFromPositions = function (from, to) {
22988
+ var range = document.createRange();
22989
+ range.setStart(from.container(), from.offset());
22990
+ range.setEnd(to.container(), to.offset());
22991
+ return range;
22779
22992
  };
22780
- var shouldRemoveTextNode = function (blockElements, node) {
22781
- if (isText$1(node)) {
22782
- if (node.nodeValue.length === 0) {
22783
- return true;
22784
- } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) {
22993
+ var hasOnlyTwoOrLessPositionsLeft = function (elm) {
22994
+ return lift2(firstPositionIn(elm), lastPositionIn(elm), function (firstPos, lastPos) {
22995
+ var normalizedFirstPos = normalizePosition(true, firstPos);
22996
+ var normalizedLastPos = normalizePosition(false, lastPos);
22997
+ return nextPosition(elm, normalizedFirstPos).forall(function (pos) {
22998
+ return pos.isEqual(normalizedLastPos);
22999
+ });
23000
+ }).getOr(true);
23001
+ };
23002
+ var setCaretLocation = function (editor, caret) {
23003
+ return function (location) {
23004
+ return renderCaret(caret, location).exists(function (pos) {
23005
+ setCaretPosition(editor, pos);
22785
23006
  return true;
22786
- }
22787
- }
22788
- return false;
23007
+ });
23008
+ };
22789
23009
  };
22790
- var addRootBlocks = function (editor) {
22791
- var dom = editor.dom, selection = editor.selection;
22792
- var schema = editor.schema, blockElements = schema.getBlockElements();
22793
- var node = selection.getStart();
23010
+ var deleteFromTo = function (editor, caret, from, to) {
22794
23011
  var rootNode = editor.getBody();
22795
- var rootBlockNode, tempNode, wrapped;
22796
- var forcedRootBlock = getForcedRootBlock(editor);
22797
- if (!node || !isElement$1(node) || !forcedRootBlock) {
22798
- return;
22799
- }
22800
- var rootNodeName = rootNode.nodeName.toLowerCase();
22801
- if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) {
22802
- return;
22803
- }
22804
- var rng = selection.getRng();
22805
- var startContainer = rng.startContainer;
22806
- var startOffset = rng.startOffset;
22807
- var endContainer = rng.endContainer;
22808
- var endOffset = rng.endOffset;
22809
- var restoreSelection = hasFocus$1(editor);
22810
- node = rootNode.firstChild;
22811
- while (node) {
22812
- if (isValidTarget(blockElements, node)) {
22813
- if (shouldRemoveTextNode(blockElements, node)) {
22814
- tempNode = node;
22815
- node = node.nextSibling;
22816
- dom.remove(tempNode);
22817
- continue;
22818
- }
22819
- if (!rootBlockNode) {
22820
- rootBlockNode = dom.create(forcedRootBlock, getForcedRootBlockAttrs(editor));
22821
- node.parentNode.insertBefore(rootBlockNode, node);
22822
- wrapped = true;
22823
- }
22824
- tempNode = node;
22825
- node = node.nextSibling;
22826
- rootBlockNode.appendChild(tempNode);
23012
+ var isInlineTarget$1 = curry(isInlineTarget, editor);
23013
+ editor.undoManager.ignore(function () {
23014
+ editor.selection.setRng(rangeFromPositions(from, to));
23015
+ editor.execCommand('Delete');
23016
+ readLocation(isInlineTarget$1, rootNode, CaretPosition.fromRangeStart(editor.selection.getRng())).map(inside).map(setCaretLocation(editor, caret));
23017
+ });
23018
+ editor.nodeChanged();
23019
+ };
23020
+ var rescope$1 = function (rootNode, node) {
23021
+ var parentBlock = getParentBlock(node, rootNode);
23022
+ return parentBlock ? parentBlock : rootNode;
23023
+ };
23024
+ var backspaceDeleteCollapsed = function (editor, caret, forward, from) {
23025
+ var rootNode = rescope$1(editor.getBody(), from.container());
23026
+ var isInlineTarget$1 = curry(isInlineTarget, editor);
23027
+ var fromLocation = readLocation(isInlineTarget$1, rootNode, from);
23028
+ return fromLocation.bind(function (location) {
23029
+ if (forward) {
23030
+ return location.fold(constant(Optional.some(inside(location))), Optional.none, constant(Optional.some(outside(location))), Optional.none);
22827
23031
  } else {
22828
- rootBlockNode = null;
22829
- node = node.nextSibling;
23032
+ return location.fold(Optional.none, constant(Optional.some(outside(location))), Optional.none, constant(Optional.some(inside(location))));
22830
23033
  }
22831
- }
22832
- if (wrapped && restoreSelection) {
22833
- rng.setStart(startContainer, startOffset);
22834
- rng.setEnd(endContainer, endOffset);
22835
- selection.setRng(rng);
22836
- editor.nodeChanged();
22837
- }
23034
+ }).map(setCaretLocation(editor, caret)).getOrThunk(function () {
23035
+ var toPosition = navigate(forward, rootNode, from);
23036
+ var toLocation = toPosition.bind(function (pos) {
23037
+ return readLocation(isInlineTarget$1, rootNode, pos);
23038
+ });
23039
+ return lift2(fromLocation, toLocation, function () {
23040
+ return findRootInline(isInlineTarget$1, rootNode, from).exists(function (elm) {
23041
+ if (hasOnlyTwoOrLessPositionsLeft(elm)) {
23042
+ deleteElement(editor, forward, SugarElement.fromDom(elm));
23043
+ return true;
23044
+ } else {
23045
+ return false;
23046
+ }
23047
+ });
23048
+ }).orThunk(function () {
23049
+ return toLocation.bind(function (_) {
23050
+ return toPosition.map(function (to) {
23051
+ if (forward) {
23052
+ deleteFromTo(editor, caret, from, to);
23053
+ } else {
23054
+ deleteFromTo(editor, caret, to, from);
23055
+ }
23056
+ return true;
23057
+ });
23058
+ });
23059
+ }).getOr(false);
23060
+ });
22838
23061
  };
22839
- var setup$a = function (editor) {
22840
- if (getForcedRootBlock(editor)) {
22841
- editor.on('NodeChange', curry(addRootBlocks, editor));
23062
+ var backspaceDelete$6 = function (editor, caret, forward) {
23063
+ if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) {
23064
+ var from = CaretPosition.fromRangeStart(editor.selection.getRng());
23065
+ return backspaceDeleteCollapsed(editor, caret, forward, from);
22842
23066
  }
23067
+ return false;
22843
23068
  };
22844
23069
 
22845
- var findBlockCaretContainer = function (editor) {
22846
- return descendant(SugarElement.fromDom(editor.getBody()), '*[data-mce-caret]').fold(constant(null), function (elm) {
22847
- return elm.dom;
23070
+ var getParentInlines = function (rootElm, startElm) {
23071
+ var parents = parentsAndSelf(startElm, rootElm);
23072
+ return findIndex(parents, isBlock).fold(constant(parents), function (index) {
23073
+ return parents.slice(0, index);
22848
23074
  });
22849
23075
  };
22850
- var removeIeControlRect = function (editor) {
22851
- editor.selection.setRng(editor.selection.getRng());
23076
+ var hasOnlyOneChild$1 = function (elm) {
23077
+ return children(elm).length === 1;
22852
23078
  };
22853
- var showBlockCaretContainer = function (editor, blockCaretContainer) {
22854
- if (blockCaretContainer.hasAttribute('data-mce-caret')) {
22855
- showCaretContainerBlock(blockCaretContainer);
22856
- removeIeControlRect(editor);
22857
- editor.selection.scrollIntoView(blockCaretContainer);
23079
+ var deleteLastPosition = function (forward, editor, target, parentInlines) {
23080
+ var isFormatElement$1 = curry(isFormatElement, editor);
23081
+ var formatNodes = map(filter(parentInlines, isFormatElement$1), function (elm) {
23082
+ return elm.dom;
23083
+ });
23084
+ if (formatNodes.length === 0) {
23085
+ deleteElement(editor, forward, target);
23086
+ } else {
23087
+ var pos = replaceWithCaretFormat(target.dom, formatNodes);
23088
+ editor.selection.setRng(pos.toRange());
22858
23089
  }
22859
23090
  };
22860
- var handleBlockContainer = function (editor, e) {
22861
- var blockCaretContainer = findBlockCaretContainer(editor);
22862
- if (!blockCaretContainer) {
22863
- return;
22864
- }
22865
- if (e.type === 'compositionstart') {
22866
- e.preventDefault();
22867
- e.stopPropagation();
22868
- showBlockCaretContainer(editor, blockCaretContainer);
22869
- return;
22870
- }
22871
- if (hasContent(blockCaretContainer)) {
22872
- showBlockCaretContainer(editor, blockCaretContainer);
22873
- editor.undoManager.add();
22874
- }
23091
+ var deleteCaret$2 = function (editor, forward) {
23092
+ var rootElm = SugarElement.fromDom(editor.getBody());
23093
+ var startElm = SugarElement.fromDom(editor.selection.getStart());
23094
+ var parentInlines = filter(getParentInlines(rootElm, startElm), hasOnlyOneChild$1);
23095
+ return last(parentInlines).exists(function (target) {
23096
+ var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
23097
+ if (willDeleteLastPositionInElement(forward, fromPos, target.dom) && !isEmptyCaretFormatElement(target)) {
23098
+ deleteLastPosition(forward, editor, target, parentInlines);
23099
+ return true;
23100
+ } else {
23101
+ return false;
23102
+ }
23103
+ });
22875
23104
  };
22876
- var setup$b = function (editor) {
22877
- editor.on('keyup compositionstart', curry(handleBlockContainer, editor));
23105
+ var backspaceDelete$7 = function (editor, forward) {
23106
+ return editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : false;
22878
23107
  };
22879
23108
 
22880
- var BreakType;
22881
- (function (BreakType) {
22882
- BreakType[BreakType['Br'] = 0] = 'Br';
22883
- BreakType[BreakType['Block'] = 1] = 'Block';
22884
- BreakType[BreakType['Wrap'] = 2] = 'Wrap';
22885
- BreakType[BreakType['Eol'] = 3] = 'Eol';
22886
- }(BreakType || (BreakType = {})));
22887
- var flip = function (direction, positions) {
22888
- return direction === HDirection.Backwards ? reverse(positions) : positions;
22889
- };
22890
- var walk$3 = function (direction, caretWalker, pos) {
22891
- return direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos);
23109
+ var deleteElement$2 = function (editor, forward, element) {
23110
+ editor._selectionOverrides.hideFakeCaret();
23111
+ deleteElement(editor, forward, SugarElement.fromDom(element));
23112
+ return true;
22892
23113
  };
22893
- var getBreakType = function (scope, direction, currentPos, nextPos) {
22894
- if (isBr(nextPos.getNode(direction === HDirection.Forwards))) {
22895
- return BreakType.Br;
22896
- } else if (isInSameBlock(currentPos, nextPos) === false) {
22897
- return BreakType.Block;
23114
+ var deleteCaret$3 = function (editor, forward) {
23115
+ var isNearMedia = forward ? isBeforeMedia : isAfterMedia;
23116
+ var direction = forward ? HDirection.Forwards : HDirection.Backwards;
23117
+ var fromPos = getNormalizedRangeEndPoint(direction, editor.getBody(), editor.selection.getRng());
23118
+ if (isNearMedia(fromPos)) {
23119
+ return deleteElement$2(editor, forward, fromPos.getNode(!forward));
22898
23120
  } else {
22899
- return BreakType.Wrap;
22900
- }
22901
- };
22902
- var getPositionsUntil = function (predicate, direction, scope, start) {
22903
- var caretWalker = CaretWalker(scope);
22904
- var currentPos = start, nextPos;
22905
- var positions = [];
22906
- while (currentPos) {
22907
- nextPos = walk$3(direction, caretWalker, currentPos);
22908
- if (!nextPos) {
22909
- break;
22910
- }
22911
- if (isBr(nextPos.getNode(false))) {
22912
- if (direction === HDirection.Forwards) {
22913
- return {
22914
- positions: flip(direction, positions).concat([nextPos]),
22915
- breakType: BreakType.Br,
22916
- breakAt: Optional.some(nextPos)
22917
- };
22918
- } else {
22919
- return {
22920
- positions: flip(direction, positions),
22921
- breakType: BreakType.Br,
22922
- breakAt: Optional.some(nextPos)
22923
- };
22924
- }
22925
- }
22926
- if (!nextPos.isVisible()) {
22927
- currentPos = nextPos;
22928
- continue;
22929
- }
22930
- if (predicate(currentPos, nextPos)) {
22931
- var breakType = getBreakType(scope, direction, currentPos, nextPos);
22932
- return {
22933
- positions: flip(direction, positions),
22934
- breakType: breakType,
22935
- breakAt: Optional.some(nextPos)
22936
- };
22937
- }
22938
- positions.push(nextPos);
22939
- currentPos = nextPos;
23121
+ return Optional.from(normalizePosition(forward, fromPos)).filter(function (pos) {
23122
+ return isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos);
23123
+ }).exists(function (pos) {
23124
+ return deleteElement$2(editor, forward, pos.getNode(!forward));
23125
+ });
22940
23126
  }
22941
- return {
22942
- positions: flip(direction, positions),
22943
- breakType: BreakType.Eol,
22944
- breakAt: Optional.none()
22945
- };
22946
23127
  };
22947
- var getAdjacentLinePositions = function (direction, getPositionsUntilBreak, scope, start) {
22948
- return getPositionsUntilBreak(scope, start).breakAt.map(function (pos) {
22949
- var positions = getPositionsUntilBreak(scope, pos).positions;
22950
- return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions);
22951
- }).getOr([]);
23128
+ var deleteRange$2 = function (editor, forward) {
23129
+ var selectedNode = editor.selection.getNode();
23130
+ return isMedia(selectedNode) ? deleteElement$2(editor, forward, selectedNode) : false;
22952
23131
  };
22953
- var findClosestHorizontalPositionFromPoint = function (positions, x) {
22954
- return foldl(positions, function (acc, newPos) {
22955
- return acc.fold(function () {
22956
- return Optional.some(newPos);
22957
- }, function (lastPos) {
22958
- return lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), function (lastRect, newRect) {
22959
- var lastDist = Math.abs(x - lastRect.left);
22960
- var newDist = Math.abs(x - newRect.left);
22961
- return newDist <= lastDist ? newPos : lastPos;
22962
- }).or(acc);
22963
- });
22964
- }, Optional.none());
23132
+ var backspaceDelete$8 = function (editor, forward) {
23133
+ return editor.selection.isCollapsed() ? deleteCaret$3(editor, forward) : deleteRange$2(editor, forward);
22965
23134
  };
22966
- var findClosestHorizontalPosition = function (positions, pos) {
22967
- return head(pos.getClientRects()).bind(function (targetRect) {
22968
- return findClosestHorizontalPositionFromPoint(positions, targetRect.left);
23135
+
23136
+ var isEditable$1 = function (target) {
23137
+ return closest(target, function (elm) {
23138
+ return isContentEditableTrue(elm.dom) || isContentEditableFalse(elm.dom);
23139
+ }).exists(function (elm) {
23140
+ return isContentEditableTrue(elm.dom);
22969
23141
  });
22970
23142
  };
22971
- var getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1);
22972
- var getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1);
22973
- var isAtFirstLine = function (scope, pos) {
22974
- return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone();
23143
+ var parseIndentValue = function (value) {
23144
+ var number = parseInt(value, 10);
23145
+ return isNaN(number) ? 0 : number;
22975
23146
  };
22976
- var isAtLastLine = function (scope, pos) {
22977
- return getPositionsUntilNextLine(scope, pos).breakAt.isNone();
23147
+ var getIndentStyleName = function (useMargin, element) {
23148
+ var indentStyleName = useMargin || isTable$1(element) ? 'margin' : 'padding';
23149
+ var suffix = get$5(element, 'direction') === 'rtl' ? '-right' : '-left';
23150
+ return indentStyleName + suffix;
22978
23151
  };
22979
- var getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine);
22980
- var getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine);
22981
- var getFirstLinePositions = function (scope) {
22982
- return firstPositionIn(scope).map(function (pos) {
22983
- return [pos].concat(getPositionsUntilNextLine(scope, pos).positions);
22984
- }).getOr([]);
23152
+ var indentElement = function (dom, command, useMargin, value, unit, element) {
23153
+ var indentStyleName = getIndentStyleName(useMargin, SugarElement.fromDom(element));
23154
+ if (command === 'outdent') {
23155
+ var styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value);
23156
+ dom.setStyle(element, indentStyleName, styleValue ? styleValue + unit : '');
23157
+ } else {
23158
+ var styleValue = parseIndentValue(element.style[indentStyleName]) + value + unit;
23159
+ dom.setStyle(element, indentStyleName, styleValue);
23160
+ }
22985
23161
  };
22986
- var getLastLinePositions = function (scope) {
22987
- return lastPositionIn(scope).map(function (pos) {
22988
- return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos);
22989
- }).getOr([]);
23162
+ var validateBlocks = function (editor, blocks) {
23163
+ return forall(blocks, function (block) {
23164
+ var indentStyleName = getIndentStyleName(shouldIndentUseMargin(editor), block);
23165
+ var intentValue = getRaw(block, indentStyleName).map(parseIndentValue).getOr(0);
23166
+ var contentEditable = editor.dom.getContentEditable(block.dom);
23167
+ return contentEditable !== 'false' && intentValue > 0;
23168
+ });
22990
23169
  };
22991
-
22992
- var getNodeClientRects = function (node) {
22993
- var toArrayWithNode = function (clientRects) {
22994
- return map(clientRects, function (clientRect) {
22995
- clientRect = clone$2(clientRect);
22996
- clientRect.node = node;
22997
- return clientRect;
22998
- });
22999
- };
23000
- if (isElement$1(node)) {
23001
- return toArrayWithNode(node.getClientRects());
23002
- }
23003
- if (isText$1(node)) {
23004
- var rng = node.ownerDocument.createRange();
23005
- rng.setStart(node, 0);
23006
- rng.setEnd(node, node.data.length);
23007
- return toArrayWithNode(rng.getClientRects());
23008
- }
23170
+ var canOutdent = function (editor) {
23171
+ var blocks = getBlocksToIndent(editor);
23172
+ return !editor.mode.isReadOnly() && (blocks.length > 1 || validateBlocks(editor, blocks));
23009
23173
  };
23010
- var getClientRects = function (nodes) {
23011
- return bind(nodes, getNodeClientRects);
23174
+ var isListComponent = function (el) {
23175
+ return isList(el) || isListItem(el);
23012
23176
  };
23013
-
23014
- var VDirection;
23015
- (function (VDirection) {
23016
- VDirection[VDirection['Up'] = -1] = 'Up';
23017
- VDirection[VDirection['Down'] = 1] = 'Down';
23018
- }(VDirection || (VDirection = {})));
23019
- var findUntil$1 = function (direction, root, predicateFn, node) {
23020
- while (node = findNode(node, direction, isEditableCaretCandidate, root)) {
23021
- if (predicateFn(node)) {
23022
- return;
23023
- }
23024
- }
23177
+ var parentIsListComponent = function (el) {
23178
+ return parent(el).map(isListComponent).getOr(false);
23025
23179
  };
23026
- var walkUntil = function (direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) {
23027
- var line = 0;
23028
- var result = [];
23029
- var add = function (node) {
23030
- var i, clientRect, clientRects;
23031
- clientRects = getClientRects([node]);
23032
- if (direction === -1) {
23033
- clientRects = clientRects.reverse();
23034
- }
23035
- for (i = 0; i < clientRects.length; i++) {
23036
- clientRect = clientRects[i];
23037
- if (isBeflowFn(clientRect, targetClientRect)) {
23038
- continue;
23039
- }
23040
- if (result.length > 0 && isAboveFn(clientRect, last$1(result))) {
23041
- line++;
23042
- }
23043
- clientRect.line = line;
23044
- if (predicateFn(clientRect)) {
23045
- return true;
23046
- }
23047
- result.push(clientRect);
23180
+ var getBlocksToIndent = function (editor) {
23181
+ return filter(map(editor.selection.getSelectedBlocks(), SugarElement.fromDom), function (el) {
23182
+ return !isListComponent(el) && !parentIsListComponent(el) && isEditable$1(el);
23183
+ });
23184
+ };
23185
+ var handle = function (editor, command) {
23186
+ var dom = editor.dom, selection = editor.selection, formatter = editor.formatter;
23187
+ var indentation = getIndentation(editor);
23188
+ var indentUnit = /[a-z%]+$/i.exec(indentation)[0];
23189
+ var indentValue = parseInt(indentation, 10);
23190
+ var useMargin = shouldIndentUseMargin(editor);
23191
+ var forcedRootBlock = getForcedRootBlock(editor);
23192
+ if (!editor.queryCommandState('InsertUnorderedList') && !editor.queryCommandState('InsertOrderedList')) {
23193
+ if (forcedRootBlock === '' && !dom.getParent(selection.getNode(), dom.isBlock)) {
23194
+ formatter.apply('div');
23048
23195
  }
23049
- };
23050
- var targetClientRect = last$1(caretPosition.getClientRects());
23051
- if (!targetClientRect) {
23052
- return result;
23053
23196
  }
23054
- var node = caretPosition.getNode();
23055
- add(node);
23056
- findUntil$1(direction, root, add, node);
23057
- return result;
23058
- };
23059
- var aboveLineNumber = function (lineNumber, clientRect) {
23060
- return clientRect.line > lineNumber;
23061
- };
23062
- var isLineNumber = function (lineNumber, clientRect) {
23063
- return clientRect.line === lineNumber;
23197
+ each(getBlocksToIndent(editor), function (block) {
23198
+ indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom);
23199
+ });
23064
23200
  };
23065
- var upUntil = curry(walkUntil, VDirection.Up, isAbove, isBelow);
23066
- var downUntil = curry(walkUntil, VDirection.Down, isBelow, isAbove);
23067
- var positionsUntil = function (direction, root, predicateFn, node) {
23068
- var caretWalker = CaretWalker(root);
23069
- var walkFn, isBelowFn, isAboveFn, caretPosition;
23070
- var result = [];
23071
- var line = 0, clientRect;
23072
- var getClientRect = function (caretPosition) {
23073
- if (direction === 1) {
23074
- return last$1(caretPosition.getClientRects());
23201
+
23202
+ var backspaceDelete$9 = function (editor, _forward) {
23203
+ if (editor.selection.isCollapsed() && canOutdent(editor)) {
23204
+ var dom = editor.dom;
23205
+ var rng = editor.selection.getRng();
23206
+ var pos = CaretPosition.fromRangeStart(rng);
23207
+ var block = dom.getParent(rng.startContainer, dom.isBlock);
23208
+ if (block !== null && isAtStartOfBlock(SugarElement.fromDom(block), pos)) {
23209
+ handle(editor, 'outdent');
23210
+ return true;
23075
23211
  }
23076
- return last$1(caretPosition.getClientRects());
23077
- };
23078
- if (direction === 1) {
23079
- walkFn = caretWalker.next;
23080
- isBelowFn = isBelow;
23081
- isAboveFn = isAbove;
23082
- caretPosition = CaretPosition.after(node);
23083
- } else {
23084
- walkFn = caretWalker.prev;
23085
- isBelowFn = isAbove;
23086
- isAboveFn = isBelow;
23087
- caretPosition = CaretPosition.before(node);
23088
23212
  }
23089
- var targetClientRect = getClientRect(caretPosition);
23090
- do {
23091
- if (!caretPosition.isVisible()) {
23092
- continue;
23093
- }
23094
- clientRect = getClientRect(caretPosition);
23095
- if (isAboveFn(clientRect, targetClientRect)) {
23096
- continue;
23097
- }
23098
- if (result.length > 0 && isBelowFn(clientRect, last$1(result))) {
23099
- line++;
23100
- }
23101
- clientRect = clone$2(clientRect);
23102
- clientRect.position = caretPosition;
23103
- clientRect.line = line;
23104
- if (predicateFn(clientRect)) {
23105
- return result;
23106
- }
23107
- result.push(clientRect);
23108
- } while (caretPosition = walkFn(caretPosition));
23109
- return result;
23110
- };
23111
- var isAboveLine = function (lineNumber) {
23112
- return function (clientRect) {
23113
- return aboveLineNumber(lineNumber, clientRect);
23114
- };
23115
- };
23116
- var isLine = function (lineNumber) {
23117
- return function (clientRect) {
23118
- return isLineNumber(lineNumber, clientRect);
23119
- };
23213
+ return false;
23120
23214
  };
23121
23215
 
23122
- var isContentEditableFalse$8 = isContentEditableFalse;
23123
- var findNode$1 = findNode;
23124
- var distanceToRectLeft = function (clientRect, clientX) {
23125
- return Math.abs(clientRect.left - clientX);
23126
- };
23127
- var distanceToRectRight = function (clientRect, clientX) {
23128
- return Math.abs(clientRect.right - clientX);
23216
+ var nativeCommand = function (editor, command) {
23217
+ editor.getDoc().execCommand(command, false, null);
23129
23218
  };
23130
- var isInsideX = function (clientX, clientRect) {
23131
- return clientX >= clientRect.left && clientX <= clientRect.right;
23219
+ var deleteCommand = function (editor, caret) {
23220
+ if (backspaceDelete$9(editor)) {
23221
+ return;
23222
+ } else if (backspaceDelete$4(editor, false)) {
23223
+ return;
23224
+ } else if (backspaceDelete$3(editor, false)) {
23225
+ return;
23226
+ } else if (backspaceDelete$6(editor, caret, false)) {
23227
+ return;
23228
+ } else if (backspaceDelete$1(editor, false)) {
23229
+ return;
23230
+ } else if (backspaceDelete(editor)) {
23231
+ return;
23232
+ } else if (backspaceDelete$5(editor, false)) {
23233
+ return;
23234
+ } else if (backspaceDelete$8(editor, false)) {
23235
+ return;
23236
+ } else if (backspaceDelete$2(editor)) {
23237
+ return;
23238
+ } else if (backspaceDelete$7(editor, false)) {
23239
+ return;
23240
+ } else {
23241
+ nativeCommand(editor, 'Delete');
23242
+ paddEmptyBody(editor);
23243
+ }
23132
23244
  };
23133
- var isInsideY = function (clientY, clientRect) {
23134
- return clientY >= clientRect.top && clientY <= clientRect.bottom;
23245
+ var forwardDeleteCommand = function (editor, caret) {
23246
+ if (backspaceDelete$4(editor, true)) {
23247
+ return;
23248
+ } else if (backspaceDelete$3(editor, true)) {
23249
+ return;
23250
+ } else if (backspaceDelete$6(editor, caret, true)) {
23251
+ return;
23252
+ } else if (backspaceDelete$1(editor, true)) {
23253
+ return;
23254
+ } else if (backspaceDelete(editor)) {
23255
+ return;
23256
+ } else if (backspaceDelete$5(editor, true)) {
23257
+ return;
23258
+ } else if (backspaceDelete$8(editor, true)) {
23259
+ return;
23260
+ } else if (backspaceDelete$2(editor)) {
23261
+ return;
23262
+ } else if (backspaceDelete$7(editor, true)) {
23263
+ return;
23264
+ } else {
23265
+ nativeCommand(editor, 'ForwardDelete');
23266
+ }
23135
23267
  };
23136
- var findClosestClientRect = function (clientRects, clientX) {
23137
- return reduce(clientRects, function (oldClientRect, clientRect) {
23138
- var oldDistance = Math.min(distanceToRectLeft(oldClientRect, clientX), distanceToRectRight(oldClientRect, clientX));
23139
- var newDistance = Math.min(distanceToRectLeft(clientRect, clientX), distanceToRectRight(clientRect, clientX));
23140
- if (isInsideX(clientX, clientRect)) {
23141
- return clientRect;
23142
- }
23143
- if (isInsideX(clientX, oldClientRect)) {
23144
- return oldClientRect;
23145
- }
23146
- if (newDistance === oldDistance && isContentEditableFalse$8(clientRect.node)) {
23147
- return clientRect;
23148
- }
23149
- if (newDistance < oldDistance) {
23150
- return clientRect;
23151
- }
23152
- return oldClientRect;
23268
+ var setup$8 = function (editor, caret) {
23269
+ editor.addCommand('delete', function () {
23270
+ deleteCommand(editor, caret);
23271
+ });
23272
+ editor.addCommand('forwardDelete', function () {
23273
+ forwardDeleteCommand(editor, caret);
23153
23274
  });
23154
23275
  };
23155
- var walkUntil$1 = function (direction, root, predicateFn, startNode, includeChildren) {
23156
- var node = findNode$1(startNode, direction, isEditableCaretCandidate, root, !includeChildren);
23157
- do {
23158
- if (!node || predicateFn(node)) {
23159
- return;
23160
- }
23161
- } while (node = findNode$1(node, direction, isEditableCaretCandidate, root));
23162
- };
23163
- var findLineNodeRects = function (root, targetNodeRect, includeChildren) {
23164
- if (includeChildren === void 0) {
23165
- includeChildren = true;
23276
+
23277
+ var SIGNIFICANT_MOVE = 5;
23278
+ var LONGPRESS_DELAY = 400;
23279
+ var getTouch = function (event) {
23280
+ if (event.touches === undefined || event.touches.length !== 1) {
23281
+ return Optional.none();
23166
23282
  }
23167
- var clientRects = [];
23168
- var collect = function (checkPosFn, node) {
23169
- var lineRects = filter(getClientRects([node]), function (clientRect) {
23170
- return !checkPosFn(clientRect, targetNodeRect);
23171
- });
23172
- clientRects = clientRects.concat(lineRects);
23173
- return lineRects.length === 0;
23174
- };
23175
- clientRects.push(targetNodeRect);
23176
- walkUntil$1(VDirection.Up, root, curry(collect, isAbove), targetNodeRect.node, includeChildren);
23177
- walkUntil$1(VDirection.Down, root, curry(collect, isBelow), targetNodeRect.node, includeChildren);
23178
- return clientRects;
23179
- };
23180
- var getFakeCaretTargets = function (root) {
23181
- return filter(from$1(root.getElementsByTagName('*')), isFakeCaretTarget);
23283
+ return Optional.some(event.touches[0]);
23182
23284
  };
23183
- var caretInfo = function (clientRect, clientX) {
23184
- return {
23185
- node: clientRect.node,
23186
- before: distanceToRectLeft(clientRect, clientX) < distanceToRectRight(clientRect, clientX)
23187
- };
23285
+ var isFarEnough = function (touch, data) {
23286
+ var distX = Math.abs(touch.clientX - data.x);
23287
+ var distY = Math.abs(touch.clientY - data.y);
23288
+ return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
23188
23289
  };
23189
- var closestFakeCaret = function (root, clientX, clientY) {
23190
- var fakeTargetNodeRects = getClientRects(getFakeCaretTargets(root));
23191
- var targetNodeRects = filter(fakeTargetNodeRects, curry(isInsideY, clientY));
23192
- var closestNodeRect = findClosestClientRect(targetNodeRects, clientX);
23193
- if (closestNodeRect) {
23194
- var includeChildren = !isTable(closestNodeRect.node) && !isMedia(closestNodeRect.node);
23195
- closestNodeRect = findClosestClientRect(findLineNodeRects(root, closestNodeRect, includeChildren), clientX);
23196
- if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
23197
- return caretInfo(closestNodeRect, clientX);
23290
+ var setup$9 = function (editor) {
23291
+ var startData = Cell(Optional.none());
23292
+ var longpressFired = Cell(false);
23293
+ var debounceLongpress = last$2(function (e) {
23294
+ editor.fire('longpress', __assign(__assign({}, e), { type: 'longpress' }));
23295
+ longpressFired.set(true);
23296
+ }, LONGPRESS_DELAY);
23297
+ editor.on('touchstart', function (e) {
23298
+ getTouch(e).each(function (touch) {
23299
+ debounceLongpress.cancel();
23300
+ var data = {
23301
+ x: touch.clientX,
23302
+ y: touch.clientY,
23303
+ target: e.target
23304
+ };
23305
+ debounceLongpress.throttle(e);
23306
+ longpressFired.set(false);
23307
+ startData.set(Optional.some(data));
23308
+ });
23309
+ }, true);
23310
+ editor.on('touchmove', function (e) {
23311
+ debounceLongpress.cancel();
23312
+ getTouch(e).each(function (touch) {
23313
+ startData.get().each(function (data) {
23314
+ if (isFarEnough(touch, data)) {
23315
+ startData.set(Optional.none());
23316
+ longpressFired.set(false);
23317
+ editor.fire('longpresscancel');
23318
+ }
23319
+ });
23320
+ });
23321
+ }, true);
23322
+ editor.on('touchend touchcancel', function (e) {
23323
+ debounceLongpress.cancel();
23324
+ if (e.type === 'touchcancel') {
23325
+ return;
23198
23326
  }
23199
- }
23200
- return null;
23327
+ startData.get().filter(function (data) {
23328
+ return data.target.isEqualNode(e.target);
23329
+ }).each(function () {
23330
+ if (longpressFired.get()) {
23331
+ e.preventDefault();
23332
+ } else {
23333
+ editor.fire('tap', __assign(__assign({}, e), { type: 'tap' }));
23334
+ }
23335
+ });
23336
+ }, true);
23201
23337
  };
23202
23338
 
23203
- var moveToRange = function (editor, rng) {
23204
- editor.selection.setRng(rng);
23205
- scrollRangeIntoView(editor, editor.selection.getRng());
23339
+ var isBlockElement = function (blockElements, node) {
23340
+ return blockElements.hasOwnProperty(node.nodeName);
23206
23341
  };
23207
- var renderRangeCaretOpt = function (editor, range, scrollIntoView) {
23208
- return Optional.some(renderRangeCaret(editor, range, scrollIntoView));
23342
+ var isValidTarget = function (blockElements, node) {
23343
+ if (isText$1(node)) {
23344
+ return true;
23345
+ } else if (isElement$1(node)) {
23346
+ return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node);
23347
+ } else {
23348
+ return false;
23349
+ }
23209
23350
  };
23210
- var moveHorizontally = function (editor, direction, range, isBefore, isAfter, isElement) {
23211
- var forwards = direction === HDirection.Forwards;
23212
- var caretWalker = CaretWalker(editor.getBody());
23213
- var getNextPosFn = curry(getVisualCaretPosition, forwards ? caretWalker.next : caretWalker.prev);
23214
- var isBeforeFn = forwards ? isBefore : isAfter;
23215
- if (!range.collapsed) {
23216
- var node = getSelectedNode(range);
23217
- if (isElement(node)) {
23218
- return showCaret(direction, editor, node, direction === HDirection.Backwards, false);
23351
+ var hasBlockParent = function (blockElements, root, node) {
23352
+ return exists(parents$1(SugarElement.fromDom(node), SugarElement.fromDom(root)), function (elm) {
23353
+ return isBlockElement(blockElements, elm.dom);
23354
+ });
23355
+ };
23356
+ var shouldRemoveTextNode = function (blockElements, node) {
23357
+ if (isText$1(node)) {
23358
+ if (node.nodeValue.length === 0) {
23359
+ return true;
23360
+ } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) {
23361
+ return true;
23219
23362
  }
23220
23363
  }
23221
- var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
23222
- if (isBeforeFn(caretPosition)) {
23223
- return selectNode(editor, caretPosition.getNode(!forwards));
23224
- }
23225
- var nextCaretPosition = normalizePosition(forwards, getNextPosFn(caretPosition));
23226
- var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range);
23227
- if (!nextCaretPosition) {
23228
- return rangeIsInContainerBlock ? Optional.some(range) : Optional.none();
23364
+ return false;
23365
+ };
23366
+ var addRootBlocks = function (editor) {
23367
+ var dom = editor.dom, selection = editor.selection;
23368
+ var schema = editor.schema, blockElements = schema.getBlockElements();
23369
+ var node = selection.getStart();
23370
+ var rootNode = editor.getBody();
23371
+ var rootBlockNode, tempNode, wrapped;
23372
+ var forcedRootBlock = getForcedRootBlock(editor);
23373
+ if (!node || !isElement$1(node) || !forcedRootBlock) {
23374
+ return;
23229
23375
  }
23230
- if (isBeforeFn(nextCaretPosition)) {
23231
- return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, false);
23376
+ var rootNodeName = rootNode.nodeName.toLowerCase();
23377
+ if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) {
23378
+ return;
23232
23379
  }
23233
- var peekCaretPosition = getNextPosFn(nextCaretPosition);
23234
- if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
23235
- if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
23236
- return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, false);
23380
+ var rng = selection.getRng();
23381
+ var startContainer = rng.startContainer;
23382
+ var startOffset = rng.startOffset;
23383
+ var endContainer = rng.endContainer;
23384
+ var endOffset = rng.endOffset;
23385
+ var restoreSelection = hasFocus$1(editor);
23386
+ node = rootNode.firstChild;
23387
+ while (node) {
23388
+ if (isValidTarget(blockElements, node)) {
23389
+ if (shouldRemoveTextNode(blockElements, node)) {
23390
+ tempNode = node;
23391
+ node = node.nextSibling;
23392
+ dom.remove(tempNode);
23393
+ continue;
23394
+ }
23395
+ if (!rootBlockNode) {
23396
+ rootBlockNode = dom.create(forcedRootBlock, getForcedRootBlockAttrs(editor));
23397
+ node.parentNode.insertBefore(rootBlockNode, node);
23398
+ wrapped = true;
23399
+ }
23400
+ tempNode = node;
23401
+ node = node.nextSibling;
23402
+ rootBlockNode.appendChild(tempNode);
23403
+ } else {
23404
+ rootBlockNode = null;
23405
+ node = node.nextSibling;
23237
23406
  }
23238
23407
  }
23239
- if (rangeIsInContainerBlock) {
23240
- return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false);
23408
+ if (wrapped && restoreSelection) {
23409
+ rng.setStart(startContainer, startOffset);
23410
+ rng.setEnd(endContainer, endOffset);
23411
+ selection.setRng(rng);
23412
+ editor.nodeChanged();
23241
23413
  }
23242
- return Optional.none();
23243
23414
  };
23244
- var moveVertically = function (editor, direction, range, isBefore, isAfter, isElement) {
23245
- var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
23246
- var caretClientRect = last$1(caretPosition.getClientRects());
23247
- var forwards = direction === VDirection.Down;
23248
- if (!caretClientRect) {
23249
- return Optional.none();
23250
- }
23251
- var walkerFn = forwards ? downUntil : upUntil;
23252
- var linePositions = walkerFn(editor.getBody(), isAboveLine(1), caretPosition);
23253
- var nextLinePositions = filter(linePositions, isLine(1));
23254
- var clientX = caretClientRect.left;
23255
- var nextLineRect = findClosestClientRect(nextLinePositions, clientX);
23256
- if (nextLineRect && isElement(nextLineRect.node)) {
23257
- var dist1 = Math.abs(clientX - nextLineRect.left);
23258
- var dist2 = Math.abs(clientX - nextLineRect.right);
23259
- return showCaret(direction, editor, nextLineRect.node, dist1 < dist2, false);
23415
+ var setup$a = function (editor) {
23416
+ if (getForcedRootBlock(editor)) {
23417
+ editor.on('NodeChange', curry(addRootBlocks, editor));
23260
23418
  }
23261
- var currentNode;
23262
- if (isBefore(caretPosition)) {
23263
- currentNode = caretPosition.getNode();
23264
- } else if (isAfter(caretPosition)) {
23265
- currentNode = caretPosition.getNode(true);
23266
- } else {
23267
- currentNode = getSelectedNode(range);
23419
+ };
23420
+
23421
+ var findBlockCaretContainer = function (editor) {
23422
+ return descendant(SugarElement.fromDom(editor.getBody()), '*[data-mce-caret]').fold(constant(null), function (elm) {
23423
+ return elm.dom;
23424
+ });
23425
+ };
23426
+ var removeIeControlRect = function (editor) {
23427
+ editor.selection.setRng(editor.selection.getRng());
23428
+ };
23429
+ var showBlockCaretContainer = function (editor, blockCaretContainer) {
23430
+ if (blockCaretContainer.hasAttribute('data-mce-caret')) {
23431
+ showCaretContainerBlock(blockCaretContainer);
23432
+ removeIeControlRect(editor);
23433
+ editor.selection.scrollIntoView(blockCaretContainer);
23268
23434
  }
23269
- if (currentNode) {
23270
- var caretPositions = positionsUntil(direction, editor.getBody(), isAboveLine(1), currentNode);
23271
- var closestNextLineRect = findClosestClientRect(filter(caretPositions, isLine(1)), clientX);
23272
- if (closestNextLineRect) {
23273
- return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
23274
- }
23275
- closestNextLineRect = last$1(filter(caretPositions, isLine(0)));
23276
- if (closestNextLineRect) {
23277
- return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
23278
- }
23435
+ };
23436
+ var handleBlockContainer = function (editor, e) {
23437
+ var blockCaretContainer = findBlockCaretContainer(editor);
23438
+ if (!blockCaretContainer) {
23439
+ return;
23279
23440
  }
23280
- if (nextLinePositions.length === 0) {
23281
- return getLineEndPoint(editor, forwards).filter(forwards ? isAfter : isBefore).map(function (pos) {
23282
- return renderRangeCaret(editor, pos.toRange(), false);
23283
- });
23441
+ if (e.type === 'compositionstart') {
23442
+ e.preventDefault();
23443
+ e.stopPropagation();
23444
+ showBlockCaretContainer(editor, blockCaretContainer);
23445
+ return;
23284
23446
  }
23285
- return Optional.none();
23286
- };
23287
- var getLineEndPoint = function (editor, forward) {
23288
- var rng = editor.selection.getRng();
23289
- var body = editor.getBody();
23290
- if (forward) {
23291
- var from = CaretPosition.fromRangeEnd(rng);
23292
- var result = getPositionsUntilNextLine(body, from);
23293
- return last(result.positions);
23294
- } else {
23295
- var from = CaretPosition.fromRangeStart(rng);
23296
- var result = getPositionsUntilPreviousLine(body, from);
23297
- return head(result.positions);
23447
+ if (hasContent(blockCaretContainer)) {
23448
+ showBlockCaretContainer(editor, blockCaretContainer);
23449
+ editor.undoManager.add();
23298
23450
  }
23299
23451
  };
23300
- var moveToLineEndPoint = function (editor, forward, isElementPosition) {
23301
- return getLineEndPoint(editor, forward).filter(isElementPosition).exists(function (pos) {
23302
- editor.selection.setRng(pos.toRange());
23303
- return true;
23304
- });
23452
+ var setup$b = function (editor) {
23453
+ editor.on('keyup compositionstart', curry(handleBlockContainer, editor));
23305
23454
  };
23306
23455
 
23307
23456
  var isContentEditableFalse$9 = isContentEditableFalse;
@@ -23373,7 +23522,7 @@
23373
23522
  return true;
23374
23523
  });
23375
23524
  };
23376
- var moveToLineEndPoint$1 = function (editor, forward) {
23525
+ var moveToLineEndPoint$2 = function (editor, forward) {
23377
23526
  var isCefPosition = forward ? isAfterContentEditableFalse : isBeforeContentEditableFalse;
23378
23527
  return moveToLineEndPoint(editor, forward, isCefPosition);
23379
23528
  };
@@ -23495,7 +23644,7 @@
23495
23644
  return true;
23496
23645
  });
23497
23646
  };
23498
- var moveToLineEndPoint$2 = function (editor, forward) {
23647
+ var moveToLineEndPoint$3 = function (editor, forward) {
23499
23648
  var isNearMedia = forward ? isAfterMedia : isBeforeMedia;
23500
23649
  return moveToLineEndPoint(editor, forward, isNearMedia);
23501
23650
  };
@@ -24672,32 +24821,40 @@
24672
24821
  });
24673
24822
  };
24674
24823
 
24675
- var executeKeydownOverride$2 = function (editor, evt) {
24824
+ var executeKeydownOverride$2 = function (editor, caret, evt) {
24676
24825
  execute([
24677
24826
  {
24678
24827
  keyCode: VK.END,
24679
- action: action(moveToLineEndPoint$1, editor, true)
24828
+ action: action(moveToLineEndPoint$2, editor, true)
24680
24829
  },
24681
24830
  {
24682
24831
  keyCode: VK.HOME,
24683
- action: action(moveToLineEndPoint$1, editor, false)
24832
+ action: action(moveToLineEndPoint$2, editor, false)
24684
24833
  },
24685
24834
  {
24686
24835
  keyCode: VK.END,
24687
- action: action(moveToLineEndPoint$2, editor, true)
24836
+ action: action(moveToLineEndPoint$3, editor, true)
24688
24837
  },
24689
24838
  {
24690
24839
  keyCode: VK.HOME,
24691
- action: action(moveToLineEndPoint$2, editor, false)
24840
+ action: action(moveToLineEndPoint$3, editor, false)
24841
+ },
24842
+ {
24843
+ keyCode: VK.END,
24844
+ action: action(moveToLineEndPoint$1, editor, true, caret)
24845
+ },
24846
+ {
24847
+ keyCode: VK.HOME,
24848
+ action: action(moveToLineEndPoint$1, editor, false, caret)
24692
24849
  }
24693
24850
  ], evt).each(function (_) {
24694
24851
  evt.preventDefault();
24695
24852
  });
24696
24853
  };
24697
- var setup$f = function (editor) {
24854
+ var setup$f = function (editor, caret) {
24698
24855
  editor.on('keydown', function (evt) {
24699
24856
  if (evt.isDefaultPrevented() === false) {
24700
- executeKeydownOverride$2(editor, evt);
24857
+ executeKeydownOverride$2(editor, caret, evt);
24701
24858
  }
24702
24859
  });
24703
24860
  };
@@ -24727,6 +24884,54 @@
24727
24884
  });
24728
24885
  };
24729
24886
 
24887
+ var platform$2 = detect$3();
24888
+ var executeKeyupAction = function (editor, caret, evt) {
24889
+ execute([
24890
+ {
24891
+ keyCode: VK.PAGE_UP,
24892
+ action: action(moveToLineEndPoint$1, editor, false, caret)
24893
+ },
24894
+ {
24895
+ keyCode: VK.PAGE_DOWN,
24896
+ action: action(moveToLineEndPoint$1, editor, true, caret)
24897
+ }
24898
+ ], evt);
24899
+ };
24900
+ var stopImmediatePropagation = function (e) {
24901
+ return e.stopImmediatePropagation();
24902
+ };
24903
+ var isPageUpDown = function (evt) {
24904
+ return evt.keyCode === VK.PAGE_UP || evt.keyCode === VK.PAGE_DOWN;
24905
+ };
24906
+ var setNodeChangeBlocker = function (blocked, editor, block) {
24907
+ if (block && !blocked.get()) {
24908
+ editor.on('NodeChange', stopImmediatePropagation, true);
24909
+ } else if (!block && blocked.get()) {
24910
+ editor.off('NodeChange', stopImmediatePropagation);
24911
+ }
24912
+ blocked.set(block);
24913
+ };
24914
+ var setup$h = function (editor, caret) {
24915
+ if (platform$2.os.isOSX()) {
24916
+ return;
24917
+ }
24918
+ var blocked = Cell(false);
24919
+ editor.on('keydown', function (evt) {
24920
+ if (isPageUpDown(evt)) {
24921
+ setNodeChangeBlocker(blocked, editor, true);
24922
+ }
24923
+ });
24924
+ editor.on('keyup', function (evt) {
24925
+ if (evt.isDefaultPrevented() === false) {
24926
+ executeKeyupAction(editor, caret, evt);
24927
+ }
24928
+ if (isPageUpDown(evt) && blocked.get()) {
24929
+ setNodeChangeBlocker(blocked, editor, false);
24930
+ editor.nodeChanged();
24931
+ }
24932
+ });
24933
+ };
24934
+
24730
24935
  var insertTextAtPosition = function (text, pos) {
24731
24936
  var container = pos.container();
24732
24937
  var offset = pos.offset();
@@ -24793,7 +24998,7 @@
24793
24998
  evt.preventDefault();
24794
24999
  });
24795
25000
  };
24796
- var setup$h = function (editor) {
25001
+ var setup$i = function (editor) {
24797
25002
  editor.on('keydown', function (evt) {
24798
25003
  if (evt.isDefaultPrevented() === false) {
24799
25004
  executeKeydownOverride$3(editor, evt);
@@ -24807,12 +25012,13 @@
24807
25012
  setup$c(editor, caret);
24808
25013
  setup$d(editor, caret);
24809
25014
  setup$e(editor);
24810
- setup$h(editor);
25015
+ setup$i(editor);
24811
25016
  setup$g(editor);
24812
- setup$f(editor);
25017
+ setup$f(editor, caret);
25018
+ setup$h(editor, caret);
24813
25019
  return caret;
24814
25020
  };
24815
- var setup$i = function (editor) {
25021
+ var setup$j = function (editor) {
24816
25022
  if (!isRtc(editor)) {
24817
25023
  return registerKeyboardOverrides(editor);
24818
25024
  } else {
@@ -24929,7 +25135,7 @@
24929
25135
  });
24930
25136
  });
24931
25137
  };
24932
- var setup$j = function (editor) {
25138
+ var setup$k = function (editor) {
24933
25139
  preventSummaryToggle(editor);
24934
25140
  filterDetails(editor);
24935
25141
  };
@@ -24959,7 +25165,7 @@
24959
25165
  }
24960
25166
  editor.selection.setRng(normalize$2(rng));
24961
25167
  };
24962
- var setup$k = function (editor) {
25168
+ var setup$l = function (editor) {
24963
25169
  editor.on('click', function (e) {
24964
25170
  if (e.detail >= 3) {
24965
25171
  normalizeSelection$1(editor);
@@ -25299,7 +25505,7 @@
25299
25505
  }
25300
25506
  };
25301
25507
 
25302
- var setup$l = function (editor) {
25508
+ var setup$m = function (editor) {
25303
25509
  var renderFocusCaret = first(function () {
25304
25510
  if (!editor.removed && editor.getBody().contains(document.activeElement)) {
25305
25511
  var rng = editor.selection.getRng();
@@ -25317,7 +25523,7 @@
25317
25523
  });
25318
25524
  };
25319
25525
 
25320
- var setup$m = function (editor) {
25526
+ var setup$n = function (editor) {
25321
25527
  editor.on('init', function () {
25322
25528
  editor.on('focusin', function (e) {
25323
25529
  var target = e.target;
@@ -25536,8 +25742,8 @@
25536
25742
  }
25537
25743
  });
25538
25744
  init(editor);
25539
- setup$l(editor);
25540
25745
  setup$m(editor);
25746
+ setup$n(editor);
25541
25747
  };
25542
25748
  var isWithinCaretContainer = function (node) {
25543
25749
  return isCaretContainer(node) || startsWithCaretContainer(node) || endsWithCaretContainer(node);
@@ -25675,7 +25881,7 @@
25675
25881
  var hideFakeCaret = function () {
25676
25882
  fakeCaret.hide();
25677
25883
  };
25678
- if (Env.ceFalse) {
25884
+ if (Env.ceFalse && !isRtc(editor)) {
25679
25885
  registerEvents();
25680
25886
  }
25681
25887
  return {
@@ -26067,44 +26273,69 @@
26067
26273
  var sel = editor.selection.getSel();
26068
26274
  return !sel || !sel.rangeCount || sel.rangeCount === 0;
26069
26275
  };
26070
- removeBlockQuoteOnBackSpace();
26071
- emptyEditorWhenDeleting();
26072
- if (!Env.windowsPhone) {
26073
- normalizeSelection();
26074
- }
26075
- if (isWebKit) {
26076
- inputMethodFocus();
26077
- selectControlElements();
26078
- setDefaultBlockType();
26079
- blockFormSubmitInsideEditor();
26080
- disableBackspaceIntoATable();
26081
- removeAppleInterchangeBrs();
26082
- if (Env.iOS) {
26083
- restoreFocusOnKeyDown();
26084
- bodyHeight();
26085
- tapLinksAndImages();
26086
- } else {
26276
+ var setupRtc = function () {
26277
+ if (isWebKit) {
26278
+ selectControlElements();
26279
+ blockFormSubmitInsideEditor();
26087
26280
  selectAll();
26281
+ if (Env.iOS) {
26282
+ restoreFocusOnKeyDown();
26283
+ bodyHeight();
26284
+ tapLinksAndImages();
26285
+ }
26088
26286
  }
26089
- }
26090
- if (Env.ie >= 11) {
26091
- bodyHeight();
26092
- disableBackspaceIntoATable();
26093
- }
26094
- if (Env.ie) {
26095
- selectAll();
26096
- disableAutoUrlDetect();
26097
- ieInternalDragAndDrop();
26098
- }
26099
- if (isGecko) {
26100
- removeHrOnBackspace();
26101
- focusBody();
26102
- removeStylesWhenDeletingAcrossBlockElements();
26103
- setGeckoEditingOptions();
26104
- addBrAfterLastLinks();
26105
- showBrokenImageIcon();
26106
- blockCmdArrowNavigation();
26107
- disableBackspaceIntoATable();
26287
+ if (isGecko) {
26288
+ focusBody();
26289
+ setGeckoEditingOptions();
26290
+ showBrokenImageIcon();
26291
+ blockCmdArrowNavigation();
26292
+ }
26293
+ };
26294
+ var setup = function () {
26295
+ removeBlockQuoteOnBackSpace();
26296
+ emptyEditorWhenDeleting();
26297
+ if (!Env.windowsPhone) {
26298
+ normalizeSelection();
26299
+ }
26300
+ if (isWebKit) {
26301
+ inputMethodFocus();
26302
+ selectControlElements();
26303
+ setDefaultBlockType();
26304
+ blockFormSubmitInsideEditor();
26305
+ disableBackspaceIntoATable();
26306
+ removeAppleInterchangeBrs();
26307
+ if (Env.iOS) {
26308
+ restoreFocusOnKeyDown();
26309
+ bodyHeight();
26310
+ tapLinksAndImages();
26311
+ } else {
26312
+ selectAll();
26313
+ }
26314
+ }
26315
+ if (Env.ie >= 11) {
26316
+ bodyHeight();
26317
+ disableBackspaceIntoATable();
26318
+ }
26319
+ if (Env.ie) {
26320
+ selectAll();
26321
+ disableAutoUrlDetect();
26322
+ ieInternalDragAndDrop();
26323
+ }
26324
+ if (isGecko) {
26325
+ removeHrOnBackspace();
26326
+ focusBody();
26327
+ removeStylesWhenDeletingAcrossBlockElements();
26328
+ setGeckoEditingOptions();
26329
+ addBrAfterLastLinks();
26330
+ showBrokenImageIcon();
26331
+ blockCmdArrowNavigation();
26332
+ disableBackspaceIntoATable();
26333
+ }
26334
+ };
26335
+ if (isRtc(editor)) {
26336
+ setupRtc();
26337
+ } else {
26338
+ setup();
26108
26339
  }
26109
26340
  return {
26110
26341
  refreshContentEditable: refreshContentEditable,
@@ -26325,7 +26556,7 @@
26325
26556
  };
26326
26557
  promiseObj.all(makeStylesheetLoadingPromises(editor, css, fontCss)).then(loaded).catch(loaded);
26327
26558
  };
26328
- var preInit = function (editor, rtcMode) {
26559
+ var preInit = function (editor) {
26329
26560
  var settings = editor.settings, doc = editor.getDoc(), body = editor.getBody();
26330
26561
  if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
26331
26562
  doc.body.spellcheck = false;
@@ -26349,7 +26580,7 @@
26349
26580
  editor.on('SetContent', function () {
26350
26581
  editor.addVisual(editor.getBody());
26351
26582
  });
26352
- if (rtcMode === false) {
26583
+ if (!isRtc(editor)) {
26353
26584
  editor.load({
26354
26585
  initial: true,
26355
26586
  format: 'html'
@@ -26428,28 +26659,28 @@
26428
26659
  editor._nodeChangeDispatcher = new NodeChange(editor);
26429
26660
  editor._selectionOverrides = SelectionOverrides(editor);
26430
26661
  setup$9(editor);
26431
- setup$j(editor);
26662
+ setup$k(editor);
26432
26663
  if (!isRtc(editor)) {
26433
- setup$k(editor);
26664
+ setup$l(editor);
26434
26665
  }
26435
- var caret = setup$i(editor);
26666
+ var caret = setup$j(editor);
26436
26667
  setup$8(editor, caret);
26437
26668
  setup$a(editor);
26438
26669
  setup$7(editor);
26439
26670
  firePreInit(editor);
26440
26671
  setup$5(editor).fold(function () {
26441
- preInit(editor, false);
26672
+ preInit(editor);
26442
26673
  }, function (loadingRtc) {
26443
26674
  editor.setProgressState(true);
26444
- loadingRtc.then(function (rtcMode) {
26675
+ loadingRtc.then(function (_rtcMode) {
26445
26676
  editor.setProgressState(false);
26446
- preInit(editor, rtcMode);
26677
+ preInit(editor);
26447
26678
  }, function (err) {
26448
26679
  editor.notificationManager.open({
26449
26680
  type: 'error',
26450
26681
  text: String(err)
26451
26682
  });
26452
- preInit(editor, true);
26683
+ preInit(editor);
26453
26684
  });
26454
26685
  });
26455
26686
  };
@@ -26992,10 +27223,8 @@
26992
27223
  }).getOr('');
26993
27224
  };
26994
27225
  var lineHeightAction = function (editor, lineHeight) {
26995
- editor.undoManager.transact(function () {
26996
- editor.formatter.toggle('lineheight', { value: String(lineHeight) });
26997
- editor.nodeChanged();
26998
- });
27226
+ editor.formatter.toggle('lineheight', { value: String(lineHeight) });
27227
+ editor.nodeChanged();
26999
27228
  };
27000
27229
 
27001
27230
  var processValue = function (value) {
@@ -28829,8 +29058,8 @@
28829
29058
  suffix: null,
28830
29059
  $: DomQuery,
28831
29060
  majorVersion: '5',
28832
- minorVersion: '7.1',
28833
- releaseDate: '2021-03-17',
29061
+ minorVersion: '8.0',
29062
+ releaseDate: '2021-05-06',
28834
29063
  editors: legacyEditors,
28835
29064
  i18n: I18n,
28836
29065
  activeEditor: null,