suneditor 2.47.7 → 2.47.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suneditor",
3
- "version": "2.47.7",
3
+ "version": "2.47.8",
4
4
  "description": "Vanilla JavaScript WYSIWYG web editor (2.x legacy version, actively maintained)",
5
5
  "author": "JiHong.Lee",
6
6
  "license": "MIT",
package/src/lib/core.js CHANGED
@@ -1057,20 +1057,22 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
1057
1057
  */
1058
1058
  setRange: function (startCon, startOff, endCon, endOff) {
1059
1059
  if (!startCon || !endCon) return;
1060
- if (startOff > startCon.textContent.length) startOff = startCon.textContent.length;
1061
- if (endOff > endCon.textContent.length) endOff = endCon.textContent.length;
1060
+ if ((util.isBreak(startCon) || startCon.nodeType === 3) && startOff > startCon.textContent.length) startOff = startCon.textContent.length;
1061
+ if ((util.isBreak(endCon) || endCon.nodeType === 3) && endOff > endCon.textContent.length) endOff = endCon.textContent.length;
1062
1062
  if (util.isFormatElement(startCon)) {
1063
- startCon = startCon.childNodes[startOff] || startCon.childNodes[startOff - 1] || startCon;
1064
- startOff = startOff > 0 ? startCon.nodeType === 1 ? 1 : startCon.textContent ? startCon.textContent.length : 0 : 0;
1063
+ startCon = startCon.childNodes[startOff > 0 ? startCon.childNodes.length - 1 : 0] || startCon;
1064
+ startOff = startOff > 0 ? (startCon.nodeType === 1 && !util.isBreak(startCon) ? 1 : startCon.textContent ? startCon.textContent.length : 0) : 0;
1065
1065
  }
1066
1066
  if (util.isFormatElement(endCon)) {
1067
- endCon = endCon.childNodes[endOff] || endCon.childNodes[endOff - 1] || endCon;
1068
- endOff = endOff > 0 ? endCon.nodeType === 1 ? 1 : endCon.textContent ? endCon.textContent.length : 0 : 0;
1067
+ endCon = endCon.childNodes[endOff > 0 ? endCon.childNodes.length - 1 : 0] || endCon;
1068
+ endOff = endOff > 0 ? (endCon.nodeType === 1 && !util.isBreak(endCon) ? 1 : endCon.textContent ? endCon.textContent.length : 0) : 0;
1069
1069
  }
1070
1070
 
1071
1071
  const range = this._wd.createRange();
1072
1072
 
1073
1073
  try {
1074
+ if (startOff > startCon.textContent.length) startOff = startCon.textContent.length;
1075
+ if (endOff > endCon.textContent.length) endOff = endCon.textContent.length;
1074
1076
  range.setStart(startCon, startOff);
1075
1077
  range.setEnd(endCon, endOff);
1076
1078
  } catch (error) {
@@ -1574,7 +1576,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
1574
1576
  let formatEl = util.getFormatElement(selectionNode, null);
1575
1577
 
1576
1578
  if (util.isListCell(formatEl)) {
1577
- this.insertNode(element, selectionNode === formatEl ? null : r.container.nextSibling, false);
1579
+ this.insertNode(element, selectionNode === formatEl ? null : (selectionNode || r.container).nextSibling, false);
1578
1580
  if (!element.nextSibling) element.parentNode.appendChild(util.createElement('BR'));
1579
1581
  } else {
1580
1582
  if (this.getRange().collapsed && (r.container.nodeType === 3 || util.isBreak(r.container))) {
@@ -1669,7 +1671,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
1669
1671
  const isList = util.isListCell(container.parentNode);
1670
1672
  let componentTop, wScroll, w;
1671
1673
  // top
1672
- if (isList ? !container.previousSibling : !util.isFormatElement(container.previousElementSibling)) {
1674
+ if (isList ? !container.previousSibling || util.isComponent(container.previousElementSibling) : !util.isFormatElement(container.previousElementSibling)) {
1673
1675
  this._variable._lineBreakComp = container;
1674
1676
  wScroll = context.element.wysiwyg.scrollTop;
1675
1677
  componentTop = util.getOffset(element, context.element.wysiwygFrame).top + wScroll;
@@ -1682,7 +1684,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
1682
1684
  t_style.display = 'none';
1683
1685
  }
1684
1686
  // bottom
1685
- if (isList ? !container.nextSibling : !util.isFormatElement(container.nextElementSibling)) {
1687
+ if (isList ? !container.nextSibling || util.isComponent(container.nextElementSibling) : !util.isFormatElement(container.nextElementSibling)) {
1686
1688
  if (!componentTop) {
1687
1689
  this._variable._lineBreakComp = container;
1688
1690
  wScroll = context.element.wysiwyg.scrollTop;
@@ -1803,7 +1805,9 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
1803
1805
  const depthFormat = util.getParentElement(container, function (current) { return this.isRangeFormatElement(current) || this.isListCell(current); }.bind(util));
1804
1806
  afterNode = util.splitElement(container, r.offset, !depthFormat ? 0 : util.getElementDepth(depthFormat) + 1);
1805
1807
  if (!afterNode) {
1806
- tempAfterNode = afterNode = line;
1808
+ if (!util.isListCell(line)) {
1809
+ tempAfterNode = afterNode = line;
1810
+ }
1807
1811
  } else if (insertListCell) {
1808
1812
  if (line.contains(container)) {
1809
1813
  const subList = util.isList(line.lastElementChild);
@@ -6232,9 +6236,22 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
6232
6236
  commonCon.parentNode.insertBefore(format, commonCon);
6233
6237
  format.appendChild(commonCon);
6234
6238
  }
6239
+
6240
+ if (util.isWysiwygDiv(commonCon)) {
6241
+ format = util.createElement(formatName || options.defaultTag);
6242
+ format.innerHTML = commonCon.innerHTML;
6243
+ commonCon.innerHTML = '';
6244
+ commonCon.appendChild(format);
6245
+ this.effectNode = null;
6246
+ this.setRange(format, 1, format, 1);
6247
+ return;
6248
+ }
6235
6249
 
6236
- if (util.isBreak(format.nextSibling)) util.removeItem(format.nextSibling);
6237
- if (util.isBreak(format.previousSibling)) util.removeItem(format.previousSibling);
6250
+ if (format) {
6251
+ if (util.isBreak(format.nextSibling)) util.removeItem(format.nextSibling);
6252
+ if (util.isBreak(format.previousSibling)) util.removeItem(format.previousSibling);
6253
+ }
6254
+
6238
6255
  if (util.isBreak(focusNode)) {
6239
6256
  const zeroWidth = util.createTextNode(util.zeroWidthSpace);
6240
6257
  focusNode.parentNode.insertBefore(zeroWidth, focusNode);
@@ -7196,16 +7213,20 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
7196
7213
 
7197
7214
  // component
7198
7215
  if (!selectRange && formatEl && (range.startOffset === 0 || (selectionNode === formatEl ? !!formatEl.childNodes[range.startOffset] : false))) {
7216
+ const isList = util.isListCell(formatEl);
7199
7217
  const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : selectionNode;
7200
- const prev = formatEl.previousSibling;
7218
+ const prev = isList ? sel.previousSibling : formatEl.previousSibling;
7201
7219
  // select file component
7202
- const ignoreZWS = (commonCon.nodeType === 3 || util.isBreak(commonCon)) && !commonCon.previousSibling && range.startOffset === 0;
7203
- if (sel && !sel.previousSibling && ( (commonCon && util.isComponent(commonCon.previousSibling)) || (ignoreZWS && util.isComponent(prev)))) {
7220
+ const ignoreZWS = isList || (commonCon.nodeType === 3 || util.isBreak(commonCon)) && !commonCon.previousSibling && range.startOffset === 0;
7221
+ if (sel && ((isList || !sel.previousSibling)) && ((commonCon && util.isComponent(commonCon.previousSibling)) || (ignoreZWS && util.isComponent(prev)))) {
7204
7222
  const fileComponentInfo = core.getFileComponent(prev);
7205
7223
  if (fileComponentInfo) {
7206
7224
  e.preventDefault();
7207
7225
  e.stopPropagation();
7208
- if (formatEl.textContent.length === 0) util.removeItem(formatEl);
7226
+
7227
+ if (isList) util.removeItem(sel);
7228
+ else if (formatEl.textContent.length === 0) util.removeItem(formatEl);
7229
+
7209
7230
  if (core.selectComponent(fileComponentInfo.target, fileComponentInfo.pluginName) === false) core.blur();
7210
7231
  } else if (util.isComponent(prev)) {
7211
7232
  e.preventDefault();
@@ -7736,6 +7757,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
7736
7757
  break;
7737
7758
  }
7738
7759
 
7760
+ if (core.currentFileComponentInfo) core.controllersOff();
7761
+
7739
7762
  if (shift && keyCode === 16) {
7740
7763
  e.preventDefault();
7741
7764
  e.stopPropagation();
@@ -7876,7 +7899,6 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
7876
7899
 
7877
7900
  const selectedComponentInfo = core.getFileComponent(selectionNodeDeepestFirstChild);
7878
7901
  if (!(e.keyCode === 16 || e.shiftKey) && selectedComponentInfo) core.selectComponent(selectedComponentInfo.target, selectedComponentInfo.pluginName);
7879
- else if (core.currentFileComponentInfo) core.controllersOff();
7880
7902
 
7881
7903
  /** when format tag deleted */
7882
7904
  if (keyCode === 8 && util.isWysiwygDiv(selectionNode) && selectionNode.textContent === '' && selectionNode.children.length === 0) {