el-header-and-footer 0.0.54 → 0.0.55

Sign up to get free protection for your applications and to get access to all the features.
@@ -1016,6 +1016,25 @@ class ElHeaderAndFooterComponent {
1016
1016
  }
1017
1017
  }
1018
1018
  }
1019
+ // getToday() {
1020
+ // const currentDate = new Date();
1021
+ // const day = currentDate.getDate() ;
1022
+ // const month = currentDate.getMonth() + 1;
1023
+ // const year = currentDate.getFullYear();
1024
+ // const formattedDate = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
1025
+ // this.today = formattedDate;
1026
+ // // const label = `{(${this.today})}`;
1027
+ // const label = `{(date)}`;
1028
+ // const htmlContent = ` ${label} `;
1029
+ // const editor = document.getElementById(this.editorId);
1030
+ // if (editor) {
1031
+ // this.editorText += `<div> ${htmlContent} </div>`;
1032
+ // this.sanitizedContent = this.editorText;
1033
+ // } else {
1034
+ // this.editorText += `<div> ${htmlContent} </div>`;
1035
+ // this.sanitizedContent = this.editorText;
1036
+ // }
1037
+ // }
1019
1038
  getToday() {
1020
1039
  const currentDate = new Date();
1021
1040
  const day = currentDate.getDate();
@@ -1027,13 +1046,43 @@ class ElHeaderAndFooterComponent {
1027
1046
  const label = `{(date)}`;
1028
1047
  const htmlContent = ` ${label} `;
1029
1048
  const editor = document.getElementById(this.editorId);
1030
- if (editor) {
1031
- this.editorText += `<div> ${htmlContent} </div>`;
1032
- this.sanitizedContent = this.editorText;
1033
- }
1034
- else {
1035
- this.editorText += `<div> ${htmlContent} </div>`;
1036
- this.sanitizedContent = this.editorText;
1049
+ this.insertAtCaret(htmlContent);
1050
+ // if (editor) {
1051
+ // this.editorText += `<div> ${htmlContent} </div>`;
1052
+ // this.sanitizedContent = this.editorText;
1053
+ // } else {
1054
+ // this.editorText += `<div> ${htmlContent} </div>`;
1055
+ // this.sanitizedContent = this.editorText;
1056
+ // }
1057
+ }
1058
+ insertAtCaret(newData) {
1059
+ const selection = window.getSelection();
1060
+ if (selection && selection.rangeCount > 0) {
1061
+ // Get the current range (caret position)
1062
+ const range = selection.getRangeAt(0);
1063
+ // Create a document fragment to insert (allows handling HTML strings)
1064
+ const fragment = document.createDocumentFragment();
1065
+ const tempDiv = document.createElement('div');
1066
+ tempDiv.innerHTML = newData;
1067
+ // Append the new data to the fragment (supports HTML insertion)
1068
+ while (tempDiv.firstChild) {
1069
+ fragment.appendChild(tempDiv.firstChild);
1070
+ }
1071
+ // Insert the fragment at the caret position
1072
+ range.deleteContents(); // Remove any selected content if applicable
1073
+ range.insertNode(fragment);
1074
+ // Move the caret after the inserted content
1075
+ const lastChild = fragment.lastChild;
1076
+ if (lastChild) {
1077
+ range.setStartAfter(lastChild);
1078
+ range.setEndAfter(lastChild);
1079
+ selection.removeAllRanges();
1080
+ selection.addRange(range);
1081
+ }
1082
+ let editor = document.getElementById('editor');
1083
+ if (editor) {
1084
+ this.moveCaretToEnd(editor);
1085
+ }
1037
1086
  }
1038
1087
  }
1039
1088
  insertPageNumber() {