@syncfusion/ej2-richtexteditor 23.1.41 → 23.1.44

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);
@@ -4806,6 +4806,7 @@ class ToolbarAction {
4806
4806
  */
4807
4807
  class Toolbar$2 {
4808
4808
  constructor(parent, serviceLocator) {
4809
+ this.tools = {};
4809
4810
  this.parent = parent;
4810
4811
  this.isToolbar = false;
4811
4812
  this.locator = serviceLocator;
@@ -13440,7 +13441,8 @@ class InsertHtml {
13440
13441
  : lastSelectionNode.previousSibling) : lastSelectionNode;
13441
13442
  while (!isNullOrUndefined(lastSelectionNode) && lastSelectionNode.nodeName !== '#text' && lastSelectionNode.nodeName !== 'IMG' &&
13442
13443
  lastSelectionNode.nodeName !== 'BR' && lastSelectionNode.nodeName !== 'HR') {
13443
- if (!isNullOrUndefined(lastSelectionNode.lastChild) && (lastSelectionNode.lastChild.nodeName === 'P' && lastSelectionNode.lastChild.innerHTML === '')) {
13444
+ if (!isNullOrUndefined(lastSelectionNode.lastChild) && (lastSelectionNode.lastChild.nodeName === 'P' &&
13445
+ lastSelectionNode.lastChild.innerHTML === '')) {
13444
13446
  const lineBreak = createElement('br');
13445
13447
  lastSelectionNode.lastChild.appendChild(lineBreak);
13446
13448
  }
@@ -13598,14 +13600,18 @@ class InsertHtml {
13598
13600
  }
13599
13601
  static removeEmptyElements(element) {
13600
13602
  const emptyElements = element.querySelectorAll(':empty');
13601
- for (let i = 0; i < emptyElements.length; i++) {
13603
+ const nonSvgEmptyElements = Array.from(emptyElements).filter(element => {
13604
+ // Check if the element is an SVG element or an ancestor of an SVG element
13605
+ return !element.closest('svg') && !element.closest('canvas');
13606
+ });
13607
+ for (let i = 0; i < nonSvgEmptyElements.length; i++) {
13602
13608
  let lineWithDiv = true;
13603
- if (emptyElements[i].tagName === 'DIV') {
13604
- lineWithDiv = emptyElements[i].style.borderBottom === 'none' ||
13605
- emptyElements[i].style.borderBottom === '' ? true : false;
13609
+ if (nonSvgEmptyElements[i].tagName === 'DIV') {
13610
+ lineWithDiv = nonSvgEmptyElements[i].style.borderBottom === 'none' ||
13611
+ nonSvgEmptyElements[i].style.borderBottom === '' ? true : false;
13606
13612
  }
13607
- if (SELF_CLOSING_TAGS.indexOf(emptyElements[i].tagName.toLowerCase()) < 0 && lineWithDiv) {
13608
- const detachableElement = this.findDetachEmptyElem(emptyElements[i]);
13613
+ if (SELF_CLOSING_TAGS.indexOf(nonSvgEmptyElements[i].tagName.toLowerCase()) < 0 && lineWithDiv) {
13614
+ const detachableElement = this.findDetachEmptyElem(nonSvgEmptyElements[i]);
13609
13615
  if (!isNullOrUndefined(detachableElement)) {
13610
13616
  detach(detachableElement);
13611
13617
  }
@@ -13720,6 +13726,12 @@ class LinkCommand {
13720
13726
  || e.event.keyCode === 13) || e.item.action === 'Paste' || range.collapsed || text) {
13721
13727
  const anchor = this.createAchorNode(e);
13722
13728
  anchor.innerText = e.item.text === '' ? e.item.url : e.item.text;
13729
+ const text = anchor.innerText;
13730
+ // Replace spaces with non-breaking spaces
13731
+ const modifiedText = text.replace(/ +/g, function (match) {
13732
+ return '\u00A0'.repeat(match.length);
13733
+ });
13734
+ anchor.innerText = modifiedText;
13723
13735
  e.item.selection.restore();
13724
13736
  InsertHtml.Insert(this.parent.currentDocument, anchor, this.parent.editableElement);
13725
13737
  if (e.event && e.event.type === 'keydown' && (e.event.keyCode === 32
@@ -13910,7 +13922,7 @@ class LinkCommand {
13910
13922
  for (let i = 0; i < blockNodes.length; i++) {
13911
13923
  const linkNode = blockNodes[i].querySelectorAll('a');
13912
13924
  for (let j = 0; j < linkNode.length; j++) {
13913
- if (document.getSelection().containsNode(linkNode[j], true)) {
13925
+ if (this.parent.currentDocument.getSelection().containsNode(linkNode[j], true)) {
13914
13926
  linkNode[j].outerHTML = linkNode[j].innerHTML;
13915
13927
  }
13916
13928
  }
@@ -17744,8 +17756,8 @@ class MsWordPaste {
17744
17756
  }
17745
17757
  isCroppedImage = ((this.extractCropValue('cropl', fullImg[i]) > 0 &&
17746
17758
  this.extractCropValue('cropt', fullImg[i]) > 0) ||
17747
- (this.extractCropValue('cropr', fullImg[i]) > 0 &&
17748
- this.extractCropValue('cropb', fullImg[i]))) ? true : false;
17759
+ this.extractCropValue('cropr', fullImg[i]) > 0 ||
17760
+ this.extractCropValue('cropb', fullImg[i])) ? true : false;
17749
17761
  if (isCroppedImage) {
17750
17762
  goalWidth = this.extractCropValue('wgoal', fullImg[i]);
17751
17763
  goalHeight = this.extractCropValue('hgoal', fullImg[i]);
@@ -17772,7 +17784,7 @@ class MsWordPaste {
17772
17784
  }
17773
17785
  extractCropValue(crop, rtfData) {
17774
17786
  // eslint-disable-next-line security/detect-non-literal-regexp
17775
- const result = new RegExp('\\\\pic' + crop + '(\\-?\\d+)\\\\').exec(rtfData.replace(/\r\n\\/g, '\\'))[1];
17787
+ const result = new RegExp('\\\\pic' + crop + '(\\-?\\d+)\\\\').exec(rtfData.replace(/\r\n\\/g, '\\').replace(/\n/g, '\\'))[1];
17776
17788
  return parseInt(result, 10);
17777
17789
  }
17778
17790
  removeClassName(elm) {
@@ -17811,6 +17823,10 @@ class MsWordPaste {
17811
17823
  return removableElement;
17812
17824
  }
17813
17825
  removeUnwantedElements(elm) {
17826
+ let styleElm = elm.querySelector('style');
17827
+ if (!isNullOrUndefined(styleElm)) {
17828
+ detach(styleElm);
17829
+ }
17814
17830
  let innerElement = elm.innerHTML;
17815
17831
  for (let i = 0; i < this.removableElements.length; i++) {
17816
17832
  // eslint-disable-next-line security/detect-non-literal-regexp
@@ -18108,10 +18124,8 @@ class MsWordPaste {
18108
18124
  }
18109
18125
  if (!isNullOrUndefined(listNodes[i].getAttribute('style'))) {
18110
18126
  listNodes[i].setAttribute('style', listNodes[i].getAttribute('style').replace('text-align:start;', ''));
18111
- if (listNodes[i].style.textAlign !== '') {
18112
- listNodes[i].setAttribute('style', 'text-align:' + listNodes[i].style.textAlign);
18113
- currentListStyle = listNodes[i].getAttribute('style');
18114
- }
18127
+ listNodes[i].style.textIndent = '';
18128
+ currentListStyle = listNodes[i].getAttribute('style');
18115
18129
  }
18116
18130
  collection.push({
18117
18131
  listType: type, content: tempNode, nestedLevel: level, class: currentClassName,
@@ -18319,8 +18333,7 @@ class MsWordPaste {
18319
18333
  }
18320
18334
  }
18321
18335
  prevList.setAttribute('class', collection[index].class);
18322
- const currentStyle = prevList.getAttribute('style');
18323
- prevList.setAttribute('style', (!isNullOrUndefined(currentStyle) ? currentStyle : ''));
18336
+ prevList.setAttribute('style', (!isNullOrUndefined(collection[index].listStyle) ? collection[index].listStyle : ''));
18324
18337
  pLevel = collection[index].nestedLevel;
18325
18338
  listCount++;
18326
18339
  if (!isNullOrUndefined(collection[index].start)) {
@@ -18763,7 +18776,7 @@ class EmojiPickerAction {
18763
18776
  }
18764
18777
  emojiInsert(args) {
18765
18778
  const node = document.createTextNode(args.value);
18766
- const selection = window.getSelection();
18779
+ const selection = this.parent.currentDocument.getSelection();
18767
18780
  const range = selection.getRangeAt(0);
18768
18781
  const cursorPos = range.startOffset;
18769
18782
  for (let i = cursorPos - 1; i >= cursorPos - 15; i--) {
@@ -22835,7 +22848,7 @@ class EmojiPicker {
22835
22848
  }
22836
22849
  else if (isNullOrUndefined(args.x) && isNullOrUndefined(args.y) && !this.parent.inlineMode.enable && isNullOrUndefined(this.parent.quickToolbarSettings.text)) {
22837
22850
  target = this.parent.inputElement;
22838
- if (window.getSelection().rangeCount > 0) {
22851
+ if (this.parent.contentModule.getDocument().getSelection().rangeCount > 0) {
22839
22852
  const coordinates = this.getCoordinates();
22840
22853
  xValue = coordinates.left;
22841
22854
  yValue = coordinates.top;
@@ -22843,7 +22856,7 @@ class EmojiPicker {
22843
22856
  }
22844
22857
  else if (isNullOrUndefined(args.x) && isNullOrUndefined(args.y) && (this.parent.inlineMode.enable || !isNullOrUndefined(this.parent.quickToolbarSettings.text))) {
22845
22858
  this.parent.notify(hidePopup, {});
22846
- if (window.getSelection().rangeCount > 0) {
22859
+ if (this.parent.contentModule.getDocument().getSelection().rangeCount > 0) {
22847
22860
  const coordinates = this.getCoordinates();
22848
22861
  xValue = coordinates.left;
22849
22862
  yValue = coordinates.top;
@@ -23432,7 +23445,7 @@ class EmojiPicker {
23432
23445
  }
23433
23446
  onkeyPress(e) {
23434
23447
  const originalEvent = e.args;
23435
- const selection = window.getSelection();
23448
+ const selection = this.parent.contentModule.getDocument().getSelection();
23436
23449
  if (selection.rangeCount <= 0) {
23437
23450
  return;
23438
23451
  }
@@ -23462,7 +23475,10 @@ class EmojiPicker {
23462
23475
  }
23463
23476
  onkeyUp(e) {
23464
23477
  const originalEvent = e.args;
23465
- const selection = window.getSelection();
23478
+ const selection = this.parent.contentModule.getDocument().getSelection();
23479
+ if (selection.rangeCount <= 0) {
23480
+ return;
23481
+ }
23466
23482
  const range = selection.getRangeAt(0);
23467
23483
  const cursorPos = range.startOffset;
23468
23484
  // eslint-disable-next-line
@@ -23485,7 +23501,7 @@ class EmojiPicker {
23485
23501
  }
23486
23502
  getCoordinates() {
23487
23503
  let coordinates;
23488
- const selection = window.getSelection();
23504
+ const selection = this.parent.contentModule.getDocument().getSelection();
23489
23505
  const range = selection.getRangeAt(0);
23490
23506
  let firstChild;
23491
23507
  if (range.startContainer.nodeName === 'P' || range.startContainer.nodeName === 'DIV') {
@@ -25221,9 +25237,10 @@ class Image$1 {
25221
25237
  const getAlt = (e.selectNode[0].getAttribute('alt') === null) ? '' :
25222
25238
  e.selectNode[0].getAttribute('alt');
25223
25239
  const content = '<div class="e-rte-field' + ' ' + this.parent.cssClass + '">' +
25224
- '<input type="text" spellcheck="false" value="' + getAlt + '" class="e-input e-img-alt' + ' ' + this.parent.cssClass + '" placeholder="' + altText + '"/>' +
25240
+ '<input type="text" spellcheck="false" class="e-input e-img-alt' + ' ' + this.parent.cssClass + '" placeholder="' + altText + '"/>' +
25225
25241
  '</div>';
25226
25242
  const contentElem = parseHtml(content);
25243
+ contentElem.querySelector('input').setAttribute('value', getAlt);
25227
25244
  altWrap.appendChild(contentElem);
25228
25245
  const inputAlt = altWrap.querySelector('.e-img-alt');
25229
25246
  const altArgs = {
@@ -25656,7 +25673,7 @@ class Image$1 {
25656
25673
  }
25657
25674
  }
25658
25675
  if (target.tagName !== 'IMG') {
25659
- let items = this.contentModule.getEditPanel().querySelectorAll('img');
25676
+ const items = this.contentModule.getEditPanel().querySelectorAll('img');
25660
25677
  for (let i = 0; i < items.length; i++) {
25661
25678
  removeClass([items[i]], 'e-img-focus');
25662
25679
  removeClass([items[i]], 'e-resize');
@@ -25755,14 +25772,12 @@ class Image$1 {
25755
25772
  this.changedWidthValue = null;
25756
25773
  this.changedHeightValue = null;
25757
25774
  const content = '<div class="e-rte-label' + ' ' + this.parent.cssClass + '"><label>' + imgWidth +
25758
- '</label></div><div class="e-rte-field' + ' ' + this.parent.cssClass + '"><input type="text" id="imgwidth" class="e-img-width' + ' ' + this.parent.cssClass + '" value=' +
25759
- widthVal
25760
- + ' /></div>' +
25775
+ '</label></div><div class="e-rte-field' + ' ' + this.parent.cssClass + '"><input type="text" id="imgwidth" class="e-img-width' + ' ' + this.parent.cssClass + '/></div>' +
25761
25776
  '<div class="e-rte-label' + ' ' + this.parent.cssClass + '">' + '<label>' + imgHeight + '</label></div><div class="e-rte-field' + ' ' + this.parent.cssClass + '"> ' +
25762
- '<input type="text" id="imgheight" class="e-img-height' + ' ' + this.parent.cssClass + '" value=' +
25763
- heightVal
25764
- + ' /></div>';
25777
+ '<input type="text" id="imgheight" class="e-img-height' + ' ' + this.parent.cssClass + '"/></div>';
25765
25778
  const contentElem = parseHtml(content);
25779
+ contentElem.getElementById('imgwidth').setAttribute('value', widthVal);
25780
+ contentElem.getElementById('imgheight').setAttribute('value', heightVal);
25766
25781
  imgSizeWrap.appendChild(contentElem);
25767
25782
  this.widthNum = new TextBox({
25768
25783
  value: formatUnit(widthVal),
@@ -31705,6 +31720,14 @@ class EnterKeyAction {
31705
31720
  else if ((this.parent.enterKey === 'P' && !shiftKey) || (this.parent.shiftEnterKey === 'P' && shiftKey)) {
31706
31721
  insertElem = this.parent.createElement('p');
31707
31722
  }
31723
+ const previousBlockNode = this.parent.formatter.editorManager.domNode.blockNodes()[0].previousSibling;
31724
+ const nextBlockNode = this.parent.formatter.editorManager.domNode.blockNodes()[0].nextSibling;
31725
+ if (!isNullOrUndefined(previousBlockNode) && previousBlockNode.hasAttribute('style')) {
31726
+ insertElem.setAttribute('style', previousBlockNode.getAttribute('style'));
31727
+ }
31728
+ if (isNullOrUndefined(previousBlockNode) && !isNullOrUndefined(nextBlockNode) && nextBlockNode.hasAttribute('style')) {
31729
+ insertElem.setAttribute('style', nextBlockNode.getAttribute('style'));
31730
+ }
31708
31731
  return insertElem;
31709
31732
  }
31710
31733
  }
@@ -32399,7 +32422,8 @@ let RichTextEditor = class RichTextEditor extends Component {
32399
32422
  }
32400
32423
  }
32401
32424
  const notFormatPainterCopy = isNullOrUndefined(e.action) ? true : (e.action !== 'format-copy' ? true : false);
32402
- if (this.formatter.getUndoRedoStack().length === 0 && notFormatPainterCopy && !(e.altKey || e.shiftKey || (e.altKey && e.shiftKey && e.which == 67))) {
32425
+ if (this.formatter.getUndoRedoStack().length === 0 && notFormatPainterCopy &&
32426
+ !(e.altKey || e.shiftKey || (e.altKey && e.shiftKey && e.which === 67))) {
32403
32427
  this.formatter.saveData();
32404
32428
  }
32405
32429
  if (e.action !== 'insert-link' &&
@@ -33515,8 +33539,8 @@ let RichTextEditor = class RichTextEditor extends Component {
33515
33539
  }
33516
33540
  else {
33517
33541
  if (target === 'windowResize' && heightPercent) {
33518
- // cntEle hide the borderBottom of RichTextEditor. so removed the 2px of cntEle height.
33519
- heightValue = parseInt(heightValue) - 2 + 'px';
33542
+ //cntEle hide the borderBottom of RichTextEditor. so removed the 2px of cntEle height.
33543
+ heightValue = parseInt(heightValue, 10) - 2 + 'px';
33520
33544
  }
33521
33545
  setStyleAttribute(cntEle, { height: heightValue, marginTop: topValue + 'px' });
33522
33546
  }
@@ -33540,7 +33564,7 @@ let RichTextEditor = class RichTextEditor extends Component {
33540
33564
  * @public
33541
33565
  */
33542
33566
  getHtml() {
33543
- const htmlValue = this.contentModule.getEditPanel().innerHTML;
33567
+ const htmlValue = this.removeResizeElement(this.contentModule.getEditPanel().innerHTML);
33544
33568
  return (this.enableXhtml && (htmlValue === '<p><br></p>' || htmlValue === '<div><br></div>' ||
33545
33569
  htmlValue === '<br>') ? null : this.serializeValue(htmlValue));
33546
33570
  }
@@ -33551,7 +33575,7 @@ let RichTextEditor = class RichTextEditor extends Component {
33551
33575
  * @public
33552
33576
  */
33553
33577
  getXhtml() {
33554
- let currentValue = this.value;
33578
+ let currentValue = this.removeResizeElement(this.value);
33555
33579
  if (!isNullOrUndefined(currentValue) && this.enableXhtml) {
33556
33580
  currentValue = this.htmlEditorModule.xhtmlValidation.selfEncloseValidation(currentValue);
33557
33581
  }
@@ -33792,14 +33816,11 @@ let RichTextEditor = class RichTextEditor extends Component {
33792
33816
  }
33793
33817
  getUpdatedValue() {
33794
33818
  let value;
33795
- if (!isNullOrUndefined(this.tableModule)) {
33796
- this.tableModule.removeResizeElement();
33797
- }
33798
33819
  const getTextArea = this.element.querySelector('.e-rte-srctextarea');
33799
33820
  if (this.editorMode === 'HTML') {
33800
33821
  value = (this.inputElement.innerHTML === '<p><br></p>' || this.inputElement.innerHTML === '<div><br></div>' ||
33801
33822
  this.inputElement.innerHTML === '<br>') ? null : this.enableHtmlEncode ?
33802
- this.encode(decode(this.inputElement.innerHTML)) : this.inputElement.innerHTML;
33823
+ this.encode(decode(this.removeResizeElement(this.inputElement.innerHTML))) : this.inputElement.innerHTML;
33803
33824
  if (getTextArea && getTextArea.style.display === 'block') {
33804
33825
  value = getTextArea.value;
33805
33826
  }
@@ -33808,6 +33829,9 @@ let RichTextEditor = class RichTextEditor extends Component {
33808
33829
  value = this.inputElement.value === '' ? null :
33809
33830
  this.inputElement.value;
33810
33831
  }
33832
+ if (value != null && !this.enableHtmlEncode) {
33833
+ value = this.removeResizeElement(value);
33834
+ }
33811
33835
  return value;
33812
33836
  }
33813
33837
  updateValueOnIdle() {
@@ -33823,6 +33847,17 @@ let RichTextEditor = class RichTextEditor extends Component {
33823
33847
  clearTimeout(this.idleInterval);
33824
33848
  this.idleInterval = setTimeout(this.updateValueOnIdle.bind(this), 0);
33825
33849
  }
33850
+ removeResizeElement(value) {
33851
+ let valueElementWrapper = document.createElement("div");
33852
+ valueElementWrapper.innerHTML = value;
33853
+ let item = valueElementWrapper.querySelectorAll('.e-column-resize, .e-row-resize, .e-table-box, .e-table-rhelper, .e-img-resize');
33854
+ if (item.length > 0) {
33855
+ for (let i = 0; i < item.length; i++) {
33856
+ detach(item[i]);
33857
+ }
33858
+ }
33859
+ return valueElementWrapper.innerHTML;
33860
+ }
33826
33861
  updateStatus(e) {
33827
33862
  if (!isNullOrUndefined(e.html) || !isNullOrUndefined(e.markdown)) {
33828
33863
  const status = this.formatter.editorManager.undoRedoManager.getUndoStatus();
@@ -33871,6 +33906,7 @@ let RichTextEditor = class RichTextEditor extends Component {
33871
33906
  this.notify(focusChange, {});
33872
33907
  const value = this.getUpdatedValue();
33873
33908
  this.setProperties({ value: value });
33909
+ this.valueContainer.value = this.value;
33874
33910
  this.notify(toolbarRefresh, { args: e, documentNode: document });
33875
33911
  this.isValueChangeBlurhandler = true;
33876
33912
  this.invokeChangeEvent();