@syncfusion/ej2-richtexteditor 23.1.40 → 23.1.43

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.
@@ -3363,10 +3363,10 @@ class ToolbarRenderer {
3363
3363
  if (!this.parent.enabled) {
3364
3364
  return;
3365
3365
  }
3366
+ this.parent.trigger('toolbarClick', args);
3366
3367
  if (!this.parent.readonly || isNullOrUndefined(args.item)) {
3367
3368
  this.parent.notify(toolbarClick, args);
3368
3369
  }
3369
- this.parent.trigger('toolbarClick', args);
3370
3370
  }
3371
3371
  dropDownSelected(args) {
3372
3372
  this.parent.notify(dropDownSelect, args);
@@ -3554,6 +3554,7 @@ class ToolbarRenderer {
3554
3554
  args.cancel = true;
3555
3555
  return;
3556
3556
  }
3557
+ proxy.parent.notify(selectionRestore, {});
3557
3558
  const element = (args.event) ? args.event.target : null;
3558
3559
  proxy.currentElement = dropDown.element;
3559
3560
  proxy.currentDropdown = dropDown;
@@ -3580,6 +3581,12 @@ class ToolbarRenderer {
3580
3581
  }
3581
3582
  args.element.tabIndex = -1;
3582
3583
  dropDown.element.removeAttribute('type');
3584
+ dropDown.element.onmousedown = () => {
3585
+ proxy.parent.notify(selectionSave, {});
3586
+ };
3587
+ dropDown.element.onkeydown = () => {
3588
+ proxy.parent.notify(selectionSave, {});
3589
+ };
3583
3590
  return dropDown;
3584
3591
  }
3585
3592
  // eslint-disable-next-line
@@ -4799,6 +4806,7 @@ class ToolbarAction {
4799
4806
  */
4800
4807
  class Toolbar$2 {
4801
4808
  constructor(parent, serviceLocator) {
4809
+ this.tools = {};
4802
4810
  this.parent = parent;
4803
4811
  this.isToolbar = false;
4804
4812
  this.locator = serviceLocator;
@@ -7836,20 +7844,20 @@ class Formatter {
7836
7844
  }
7837
7845
  if (isNullOrUndefined(args)) {
7838
7846
  const action = event.action;
7847
+ args = {};
7848
+ const items = {
7849
+ originalEvent: event, cancel: false,
7850
+ requestType: action || (event.key + 'Key'),
7851
+ itemCollection: value
7852
+ };
7853
+ extend(args, args, items, true);
7839
7854
  if (action !== 'tab' && action !== 'enter' && action !== 'space' && action !== 'escape') {
7840
- args = {};
7841
7855
  if (self.editorMode === 'Markdown' && action === 'insert-table') {
7842
7856
  value = {
7843
7857
  'headingText': self.localeObj.getConstant('TableHeadingText'),
7844
7858
  'colText': self.localeObj.getConstant('TableColText')
7845
7859
  };
7846
7860
  }
7847
- const items = {
7848
- originalEvent: event, cancel: false,
7849
- requestType: action || (event.key + 'Key'),
7850
- itemCollection: value
7851
- };
7852
- extend(args, args, items, true);
7853
7861
  self.trigger(actionBegin, args, (actionBeginArgs) => {
7854
7862
  if (actionBeginArgs.cancel) {
7855
7863
  if (action === 'paste' || action === 'cut' || action === 'copy') {
@@ -7858,20 +7866,22 @@ class Formatter {
7858
7866
  }
7859
7867
  });
7860
7868
  }
7861
- const isTableModule = isNullOrUndefined(self.tableModule) ? true : self.tableModule ?
7862
- self.tableModule.ensureInsideTableList : false;
7863
- if ((event.which === 9 && isTableModule) || event.which !== 9) {
7864
- if (event.which === 13 && self.editorMode === 'HTML') {
7865
- value = {
7866
- 'enterAction': self.enterKey
7867
- };
7869
+ if (!args.cancel) {
7870
+ const isTableModule = isNullOrUndefined(self.tableModule) ? true : self.tableModule ?
7871
+ self.tableModule.ensureInsideTableList : false;
7872
+ if ((event.which === 9 && isTableModule) || event.which !== 9) {
7873
+ if (event.which === 13 && self.editorMode === 'HTML') {
7874
+ value = {
7875
+ 'enterAction': self.enterKey
7876
+ };
7877
+ }
7878
+ this.editorManager.observer.notify((event.type === 'keydown' ? KEY_DOWN : KEY_UP), {
7879
+ event: event,
7880
+ callBack: this.onSuccess.bind(this, self),
7881
+ value: value,
7882
+ enterAction: self.enterKey
7883
+ });
7868
7884
  }
7869
- this.editorManager.observer.notify((event.type === 'keydown' ? KEY_DOWN : KEY_UP), {
7870
- event: event,
7871
- callBack: this.onSuccess.bind(this, self),
7872
- value: value,
7873
- enterAction: self.enterKey
7874
- });
7875
7885
  }
7876
7886
  }
7877
7887
  else if (!isNullOrUndefined(args) && args.item.command && args.item.subCommand && ((args.item.command !== args.item.subCommand
@@ -12565,7 +12575,7 @@ class NodeCutter {
12565
12575
  node = parent.childNodes[index];
12566
12576
  fragment = this.spliceEmptyNode(fragment, false);
12567
12577
  if (fragment && fragment.childNodes.length > 0) {
12568
- const isEmpty = (fragment.childNodes.length === 1 && fragment.childNodes[0].nodeName !== 'IMG'
12578
+ const isEmpty = (fragment.childNodes.length === 1 && fragment.childNodes[0].nodeName !== 'IMG' && !(fragment.querySelectorAll('img').length > 0)
12569
12579
  && this.isRteElm(fragment) && fragment.textContent === '') ? true : false;
12570
12580
  if (!isEmpty) {
12571
12581
  if (node) {
@@ -13431,6 +13441,11 @@ class InsertHtml {
13431
13441
  : lastSelectionNode.previousSibling) : lastSelectionNode;
13432
13442
  while (!isNullOrUndefined(lastSelectionNode) && lastSelectionNode.nodeName !== '#text' && lastSelectionNode.nodeName !== 'IMG' &&
13433
13443
  lastSelectionNode.nodeName !== 'BR' && lastSelectionNode.nodeName !== 'HR') {
13444
+ if (!isNullOrUndefined(lastSelectionNode.lastChild) && (lastSelectionNode.lastChild.nodeName === 'P' &&
13445
+ lastSelectionNode.lastChild.innerHTML === '')) {
13446
+ const lineBreak = createElement('br');
13447
+ lastSelectionNode.lastChild.appendChild(lineBreak);
13448
+ }
13434
13449
  lastSelectionNode = lastSelectionNode.lastChild;
13435
13450
  }
13436
13451
  lastSelectionNode = isNullOrUndefined(lastSelectionNode) ? node : lastSelectionNode;
@@ -13897,7 +13912,7 @@ class LinkCommand {
13897
13912
  for (let i = 0; i < blockNodes.length; i++) {
13898
13913
  const linkNode = blockNodes[i].querySelectorAll('a');
13899
13914
  for (let j = 0; j < linkNode.length; j++) {
13900
- if (document.getSelection().containsNode(linkNode[j], true)) {
13915
+ if (this.parent.currentDocument.getSelection().containsNode(linkNode[j], true)) {
13901
13916
  linkNode[j].outerHTML = linkNode[j].innerHTML;
13902
13917
  }
13903
13918
  }
@@ -17729,8 +17744,10 @@ class MsWordPaste {
17729
17744
  else {
17730
17745
  continue;
17731
17746
  }
17732
- isCroppedImage = this.extractCropValue('cropl', fullImg[i]) > 0 &&
17733
- this.extractCropValue('cropt', fullImg[i]) > 0 ? true : false;
17747
+ isCroppedImage = ((this.extractCropValue('cropl', fullImg[i]) > 0 &&
17748
+ this.extractCropValue('cropt', fullImg[i]) > 0) ||
17749
+ this.extractCropValue('cropr', fullImg[i]) > 0 ||
17750
+ this.extractCropValue('cropb', fullImg[i])) ? true : false;
17734
17751
  if (isCroppedImage) {
17735
17752
  goalWidth = this.extractCropValue('wgoal', fullImg[i]);
17736
17753
  goalHeight = this.extractCropValue('hgoal', fullImg[i]);
@@ -17757,7 +17774,7 @@ class MsWordPaste {
17757
17774
  }
17758
17775
  extractCropValue(crop, rtfData) {
17759
17776
  // eslint-disable-next-line security/detect-non-literal-regexp
17760
- const result = new RegExp('\\\\pic' + crop + '(\\-?\\d+)\\\\').exec(rtfData.replace('\r\n\\', '\\'))[1];
17777
+ const result = new RegExp('\\\\pic' + crop + '(\\-?\\d+)\\\\').exec(rtfData.replace(/\r\n\\/g, '\\').replace(/\n/g, '\\'))[1];
17761
17778
  return parseInt(result, 10);
17762
17779
  }
17763
17780
  removeClassName(elm) {
@@ -17796,6 +17813,10 @@ class MsWordPaste {
17796
17813
  return removableElement;
17797
17814
  }
17798
17815
  removeUnwantedElements(elm) {
17816
+ let styleElm = elm.querySelector('style');
17817
+ if (!isNullOrUndefined(styleElm)) {
17818
+ detach(styleElm);
17819
+ }
17799
17820
  let innerElement = elm.innerHTML;
17800
17821
  for (let i = 0; i < this.removableElements.length; i++) {
17801
17822
  // eslint-disable-next-line security/detect-non-literal-regexp
@@ -18093,10 +18114,8 @@ class MsWordPaste {
18093
18114
  }
18094
18115
  if (!isNullOrUndefined(listNodes[i].getAttribute('style'))) {
18095
18116
  listNodes[i].setAttribute('style', listNodes[i].getAttribute('style').replace('text-align:start;', ''));
18096
- if (listNodes[i].style.textAlign !== '') {
18097
- listNodes[i].setAttribute('style', 'text-align:' + listNodes[i].style.textAlign);
18098
- currentListStyle = listNodes[i].getAttribute('style');
18099
- }
18117
+ listNodes[i].style.textIndent = '';
18118
+ currentListStyle = listNodes[i].getAttribute('style');
18100
18119
  }
18101
18120
  collection.push({
18102
18121
  listType: type, content: tempNode, nestedLevel: level, class: currentClassName,
@@ -18304,8 +18323,7 @@ class MsWordPaste {
18304
18323
  }
18305
18324
  }
18306
18325
  prevList.setAttribute('class', collection[index].class);
18307
- const currentStyle = prevList.getAttribute('style');
18308
- prevList.setAttribute('style', (!isNullOrUndefined(currentStyle) ? currentStyle : ''));
18326
+ prevList.setAttribute('style', (!isNullOrUndefined(collection[index].listStyle) ? collection[index].listStyle : ''));
18309
18327
  pLevel = collection[index].nestedLevel;
18310
18328
  listCount++;
18311
18329
  if (!isNullOrUndefined(collection[index].start)) {
@@ -18748,7 +18766,7 @@ class EmojiPickerAction {
18748
18766
  }
18749
18767
  emojiInsert(args) {
18750
18768
  const node = document.createTextNode(args.value);
18751
- const selection = window.getSelection();
18769
+ const selection = this.parent.currentDocument.getSelection();
18752
18770
  const range = selection.getRangeAt(0);
18753
18771
  const cursorPos = range.startOffset;
18754
18772
  for (let i = cursorPos - 1; i >= cursorPos - 15; i--) {
@@ -19119,10 +19137,15 @@ class FormatPainterActions {
19119
19137
  return this.INVALID_TAGS.indexOf(node.tagName) > -1;
19120
19138
  }
19121
19139
  findCurrentContext(parentElem) {
19122
- if (closest(parentElem, 'p')) {
19140
+ const closestParagraph = closest(parentElem, 'p');
19141
+ const closestList = closest(parentElem, 'li');
19142
+ if (closestParagraph && !closestList) {
19123
19143
  return 'Text';
19124
19144
  }
19125
19145
  else if (closest(parentElem, 'li')) {
19146
+ if (!isNullOrUndefined(closestParagraph) && !isNullOrUndefined(closestList) && closestParagraph.textContent.trim() !== closestList.textContent.trim()) {
19147
+ return 'Text';
19148
+ }
19126
19149
  return 'List';
19127
19150
  }
19128
19151
  else if (closest(parentElem, 'td') || closest(parentElem, 'tr') || closest(parentElem, 'th')) {
@@ -19180,7 +19203,7 @@ class FormatPainterActions {
19180
19203
  const cloneElementNode = isNullOrUndefined(cloneListParentNode) ? element : element.firstChild;
19181
19204
  for (let index = 0; index < nodes.length; index++) {
19182
19205
  if (this.INVALID_TAGS.indexOf(nodes[index].nodeName) > -1 ||
19183
- nodes[index].querySelectorAll('a,img,audio,video,iframe').length > 0) {
19206
+ nodes[index].querySelectorAll('img,audio,video,iframe').length > 0) {
19184
19207
  continue;
19185
19208
  }
19186
19209
  const cloneParentNode = cloneElementNode.cloneNode(false);
@@ -20258,7 +20281,7 @@ class HtmlEditor {
20258
20281
  detach(currentChildNode[i]);
20259
20282
  i--;
20260
20283
  }
20261
- if (focusNode.textContent.replace(regEx, '') === currentChildNode[i].textContent) {
20284
+ if (!isNullOrUndefined(currentChildNode[i]) && focusNode.textContent.replace(regEx, '') === currentChildNode[i].textContent) {
20262
20285
  pointer = focusNode.textContent.length > 1 ?
20263
20286
  (focusNode.textContent === currentChildNode[i].textContent ? pointer :
20264
20287
  pointer - (focusNode.textContent.length - focusNode.textContent.replace(regEx, '').length)) :
@@ -22815,7 +22838,7 @@ class EmojiPicker {
22815
22838
  }
22816
22839
  else if (isNullOrUndefined(args.x) && isNullOrUndefined(args.y) && !this.parent.inlineMode.enable && isNullOrUndefined(this.parent.quickToolbarSettings.text)) {
22817
22840
  target = this.parent.inputElement;
22818
- if (window.getSelection().rangeCount > 0) {
22841
+ if (this.parent.contentModule.getDocument().getSelection().rangeCount > 0) {
22819
22842
  const coordinates = this.getCoordinates();
22820
22843
  xValue = coordinates.left;
22821
22844
  yValue = coordinates.top;
@@ -22823,7 +22846,7 @@ class EmojiPicker {
22823
22846
  }
22824
22847
  else if (isNullOrUndefined(args.x) && isNullOrUndefined(args.y) && (this.parent.inlineMode.enable || !isNullOrUndefined(this.parent.quickToolbarSettings.text))) {
22825
22848
  this.parent.notify(hidePopup, {});
22826
- if (window.getSelection().rangeCount > 0) {
22849
+ if (this.parent.contentModule.getDocument().getSelection().rangeCount > 0) {
22827
22850
  const coordinates = this.getCoordinates();
22828
22851
  xValue = coordinates.left;
22829
22852
  yValue = coordinates.top;
@@ -23412,7 +23435,7 @@ class EmojiPicker {
23412
23435
  }
23413
23436
  onkeyPress(e) {
23414
23437
  const originalEvent = e.args;
23415
- const selection = window.getSelection();
23438
+ const selection = this.parent.contentModule.getDocument().getSelection();
23416
23439
  if (selection.rangeCount <= 0) {
23417
23440
  return;
23418
23441
  }
@@ -23442,7 +23465,10 @@ class EmojiPicker {
23442
23465
  }
23443
23466
  onkeyUp(e) {
23444
23467
  const originalEvent = e.args;
23445
- const selection = window.getSelection();
23468
+ const selection = this.parent.contentModule.getDocument().getSelection();
23469
+ if (selection.rangeCount <= 0) {
23470
+ return;
23471
+ }
23446
23472
  const range = selection.getRangeAt(0);
23447
23473
  const cursorPos = range.startOffset;
23448
23474
  // eslint-disable-next-line
@@ -23465,7 +23491,7 @@ class EmojiPicker {
23465
23491
  }
23466
23492
  getCoordinates() {
23467
23493
  let coordinates;
23468
- const selection = window.getSelection();
23494
+ const selection = this.parent.contentModule.getDocument().getSelection();
23469
23495
  const range = selection.getRangeAt(0);
23470
23496
  let firstChild;
23471
23497
  if (range.startContainer.nodeName === 'P' || range.startContainer.nodeName === 'DIV') {
@@ -25636,7 +25662,7 @@ class Image$1 {
25636
25662
  }
25637
25663
  }
25638
25664
  if (target.tagName !== 'IMG') {
25639
- let items = this.contentModule.getEditPanel().querySelectorAll('img');
25665
+ const items = this.contentModule.getEditPanel().querySelectorAll('img');
25640
25666
  for (let i = 0; i < items.length; i++) {
25641
25667
  removeClass([items[i]], 'e-img-focus');
25642
25668
  removeClass([items[i]], 'e-resize');
@@ -31440,7 +31466,7 @@ class EnterKeyAction {
31440
31466
  }
31441
31467
  this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), insertElem.nextElementSibling, 0);
31442
31468
  }
31443
- else if (nearBlockNode.textContent.length === 0 && !(!isNullOrUndefined(nearBlockNode.childNodes[0]) && nearBlockNode.childNodes[0].nodeName === 'IMG')) {
31469
+ else if (nearBlockNode.textContent.length === 0 && !(!isNullOrUndefined(nearBlockNode.childNodes[0]) && nearBlockNode.childNodes[0].nodeName === 'IMG') && !(nearBlockNode.querySelectorAll('img').length > 0)) {
31444
31470
  if (!isNullOrUndefined(nearBlockNode.children[0]) && nearBlockNode.children[0].tagName !== 'BR') {
31445
31471
  const newElem = this.parent.formatter.editorManager.nodeCutter.SplitNode(this.range, nearBlockNode, false).cloneNode(true);
31446
31472
  this.parent.formatter.editorManager.domNode.insertAfter(newElem, nearBlockNode);
@@ -32378,13 +32404,14 @@ let RichTextEditor = class RichTextEditor extends Component {
32378
32404
  this.formatter.editorManager.nodeSelection.setCursorPoint(this.contentModule.getDocument(), range.startContainer, range.startOffset);
32379
32405
  }
32380
32406
  }
32381
- const notFormatPainterCopy = !isNullOrUndefined(e.action) && e.action !== 'format-copy';
32382
- if (this.formatter.getUndoRedoStack().length === 0 && notFormatPainterCopy) {
32407
+ const notFormatPainterCopy = isNullOrUndefined(e.action) ? true : (e.action !== 'format-copy' ? true : false);
32408
+ if (this.formatter.getUndoRedoStack().length === 0 && notFormatPainterCopy &&
32409
+ !(e.altKey || e.shiftKey || (e.altKey && e.shiftKey && e.which === 67))) {
32383
32410
  this.formatter.saveData();
32384
32411
  }
32385
32412
  if (e.action !== 'insert-link' &&
32386
32413
  e.action !== 'format-copy' && e.action !== 'format-paste' &&
32387
- (!e.target || (e.target.classList.contains('e-mention') && e.code !== 'Tab')) &&
32414
+ (!e.target || !(e.target.classList.contains('e-mention') && e.code === 'Tab')) &&
32388
32415
  (e.action && e.action !== 'paste' && e.action !== 'space'
32389
32416
  || e.which === 9 || (e.code === 'Backspace' && e.which === 8))) {
32390
32417
  let FormatPainterEscapeAction = false;
@@ -33495,8 +33522,8 @@ let RichTextEditor = class RichTextEditor extends Component {
33495
33522
  }
33496
33523
  else {
33497
33524
  if (target === 'windowResize' && heightPercent) {
33498
- // cntEle hide the borderBottom of RichTextEditor. so removed the 2px of cntEle height.
33499
- heightValue = parseInt(heightValue) - 2 + 'px';
33525
+ //cntEle hide the borderBottom of RichTextEditor. so removed the 2px of cntEle height.
33526
+ heightValue = parseInt(heightValue, 10) - 2 + 'px';
33500
33527
  }
33501
33528
  setStyleAttribute(cntEle, { height: heightValue, marginTop: topValue + 'px' });
33502
33529
  }
@@ -33520,7 +33547,7 @@ let RichTextEditor = class RichTextEditor extends Component {
33520
33547
  * @public
33521
33548
  */
33522
33549
  getHtml() {
33523
- const htmlValue = this.contentModule.getEditPanel().innerHTML;
33550
+ const htmlValue = this.removeResizeElement(this.contentModule.getEditPanel().innerHTML);
33524
33551
  return (this.enableXhtml && (htmlValue === '<p><br></p>' || htmlValue === '<div><br></div>' ||
33525
33552
  htmlValue === '<br>') ? null : this.serializeValue(htmlValue));
33526
33553
  }
@@ -33531,7 +33558,7 @@ let RichTextEditor = class RichTextEditor extends Component {
33531
33558
  * @public
33532
33559
  */
33533
33560
  getXhtml() {
33534
- let currentValue = this.value;
33561
+ let currentValue = this.removeResizeElement(this.value);
33535
33562
  if (!isNullOrUndefined(currentValue) && this.enableXhtml) {
33536
33563
  currentValue = this.htmlEditorModule.xhtmlValidation.selfEncloseValidation(currentValue);
33537
33564
  }
@@ -33772,14 +33799,11 @@ let RichTextEditor = class RichTextEditor extends Component {
33772
33799
  }
33773
33800
  getUpdatedValue() {
33774
33801
  let value;
33775
- if (!isNullOrUndefined(this.tableModule)) {
33776
- this.tableModule.removeResizeElement();
33777
- }
33778
33802
  const getTextArea = this.element.querySelector('.e-rte-srctextarea');
33779
33803
  if (this.editorMode === 'HTML') {
33780
33804
  value = (this.inputElement.innerHTML === '<p><br></p>' || this.inputElement.innerHTML === '<div><br></div>' ||
33781
33805
  this.inputElement.innerHTML === '<br>') ? null : this.enableHtmlEncode ?
33782
- this.encode(decode(this.inputElement.innerHTML)) : this.inputElement.innerHTML;
33806
+ this.encode(decode(this.removeResizeElement(this.inputElement.innerHTML))) : this.inputElement.innerHTML;
33783
33807
  if (getTextArea && getTextArea.style.display === 'block') {
33784
33808
  value = getTextArea.value;
33785
33809
  }
@@ -33788,6 +33812,9 @@ let RichTextEditor = class RichTextEditor extends Component {
33788
33812
  value = this.inputElement.value === '' ? null :
33789
33813
  this.inputElement.value;
33790
33814
  }
33815
+ if (value != null && !this.enableHtmlEncode) {
33816
+ value = this.removeResizeElement(value);
33817
+ }
33791
33818
  return value;
33792
33819
  }
33793
33820
  updateValueOnIdle() {
@@ -33803,6 +33830,17 @@ let RichTextEditor = class RichTextEditor extends Component {
33803
33830
  clearTimeout(this.idleInterval);
33804
33831
  this.idleInterval = setTimeout(this.updateValueOnIdle.bind(this), 0);
33805
33832
  }
33833
+ removeResizeElement(value) {
33834
+ let valueElementWrapper = document.createElement("div");
33835
+ valueElementWrapper.innerHTML = value;
33836
+ let item = valueElementWrapper.querySelectorAll('.e-column-resize, .e-row-resize, .e-table-box, .e-table-rhelper, .e-img-resize');
33837
+ if (item.length > 0) {
33838
+ for (let i = 0; i < item.length; i++) {
33839
+ detach(item[i]);
33840
+ }
33841
+ }
33842
+ return valueElementWrapper.innerHTML;
33843
+ }
33806
33844
  updateStatus(e) {
33807
33845
  if (!isNullOrUndefined(e.html) || !isNullOrUndefined(e.markdown)) {
33808
33846
  const status = this.formatter.editorManager.undoRedoManager.getUndoStatus();
@@ -33851,6 +33889,7 @@ let RichTextEditor = class RichTextEditor extends Component {
33851
33889
  this.notify(focusChange, {});
33852
33890
  const value = this.getUpdatedValue();
33853
33891
  this.setProperties({ value: value });
33892
+ this.valueContainer.value = this.value;
33854
33893
  this.notify(toolbarRefresh, { args: e, documentNode: document });
33855
33894
  this.isValueChangeBlurhandler = true;
33856
33895
  this.invokeChangeEvent();