@talrace/ngx-noder 19.0.66 → 19.0.68

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.
@@ -633,13 +633,7 @@ class EditorService {
633
633
  this._clipboardData$ = new BehaviorSubject('');
634
634
  this._hasSelection$ = new BehaviorSubject(false);
635
635
  this._historyInfo$ = new BehaviorSubject(new OperationsHistoryInfoModel(-1, -1));
636
- this._toggleSidenav$ = new BehaviorSubject({
637
- open: false,
638
- component: null,
639
- focus: false,
640
- data: null
641
- });
642
- this._isSidenavLocked = false;
636
+ this._toggleSidenav$ = new Subject();
643
637
  this._displayGrammarError$ = new Subject();
644
638
  this._applyGrammarSuggestion$ = new Subject();
645
639
  this._ignoreGrammarError$ = new Subject();
@@ -771,9 +765,6 @@ class EditorService {
771
765
  get toggleSidenav$() {
772
766
  return this._toggleSidenav$.asObservable();
773
767
  }
774
- get isSidenavLocked() {
775
- return this._isSidenavLocked;
776
- }
777
768
  get displayGrammarError$() {
778
769
  return this._displayGrammarError$.asObservable();
779
770
  }
@@ -1194,14 +1185,8 @@ class EditorService {
1194
1185
  this._toggleSidenav$.next({ open: true, component, focus });
1195
1186
  }
1196
1187
  closeSidenav() {
1197
- if (this.isSidenavLocked) {
1198
- return;
1199
- }
1200
1188
  this._toggleSidenav$.next({ open: false, component: null, focus: false });
1201
1189
  }
1202
- lockSidenav(value) {
1203
- this._isSidenavLocked = value;
1204
- }
1205
1190
  changedTableSize(insertIndex, sessionId) {
1206
1191
  this._changedTableSize$.next({ insertIndex, sessionId });
1207
1192
  }
@@ -1462,7 +1447,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImpor
1462
1447
  class ExternalComponent extends BaseNoderComponent {
1463
1448
  constructor() {
1464
1449
  super(...arguments);
1465
- this.focusSidenav = true;
1450
+ this.focusSidenav = false;
1466
1451
  this.isText = false; // this will substitute component block by in editor text (getText() will be used as a value)
1467
1452
  }
1468
1453
  getText() {
@@ -9757,7 +9742,9 @@ class EditSession {
9757
9742
  }
9758
9743
  insertElementByDocumentIndex(insertElement) {
9759
9744
  const elementPosition = ContentHelper.documentIndexToParagraphIndex(this.displayData.paragraphs, insertElement.element.insertIndex);
9760
- return this.insertElement(elementPosition, insertElement.element);
9745
+ const { endPosition } = this.insertElement(elementPosition, insertElement.element);
9746
+ this.selection.placeCursor(endPosition);
9747
+ return endPosition;
9761
9748
  }
9762
9749
  insertBreakByDocumentIndex(insertElement) {
9763
9750
  const elementPosition = ContentHelper.documentIndexToParagraphIndex(this.displayData.paragraphs, insertElement.insertIndex);
@@ -9979,10 +9966,9 @@ class EditSession {
9979
9966
  const endPosition = this.displayData.insertText(position, CUSTOM_ELEMENT_MARKER);
9980
9967
  const model = this.model.elements.find(x => x.insertIndex === insertIndex);
9981
9968
  const type = this.customContentService.findComponentType(model.type);
9982
- this.addComponent(this.customComponents.customElements, model, type);
9969
+ const component = this.addComponent(this.customComponents.customElements, model, type);
9983
9970
  this.displayData.updateNextLineIndexes(position.row, endPosition.row);
9984
- this.selection.placeCursor(endPosition);
9985
- return endPosition;
9971
+ return { endPosition, component };
9986
9972
  }
9987
9973
  insertBreak(position, breakType) {
9988
9974
  const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.displayData.paragraphs, position);
@@ -10041,7 +10027,7 @@ class EditSession {
10041
10027
  }
10042
10028
  insertContents(insertIndex, contents) {
10043
10029
  OperationsHelper.insertContents(this.model, contents, insertIndex, this.generalProperties.numberings, contents.numberings);
10044
- const endIndex = insertIndex + contents.content.length - 1;
10030
+ const endIndex = insertIndex + contents.content.length;
10045
10031
  this.insertComponents(this.model.tables, this.customComponents.tables, NoderTableComponent, insertIndex, endIndex);
10046
10032
  this.insertComponents(this.model.images, this.customComponents.images, NoderImageComponent, insertIndex, endIndex);
10047
10033
  this.insertComponents(this.model.tabs, this.customComponents.tabs, NoderTabComponent, insertIndex, endIndex);
@@ -10122,6 +10108,7 @@ class EditSession {
10122
10108
  customElements.push(customElement);
10123
10109
  }
10124
10110
  customElement.instance.initialize();
10111
+ return customElement;
10125
10112
  }
10126
10113
  applyToolbarStyles() {
10127
10114
  // undefined - value wasn't set
@@ -15647,7 +15634,7 @@ class Editor {
15647
15634
  this.mainRenderer.onResize(true);
15648
15635
  };
15649
15636
  this.onDocumentChange = (range) => {
15650
- let lastRow = range.start.row === range.end.row ? range.end.row : Infinity;
15637
+ const lastRow = range.start.row === range.end.row ? range.end.row : Infinity;
15651
15638
  this.renderer.updateLines(range.start.row, lastRow);
15652
15639
  // Update cursor because tab characters can influence the cursor position.
15653
15640
  this.renderer.updateCursor();
@@ -15803,7 +15790,7 @@ class Editor {
15803
15790
  }
15804
15791
  this.saveInsertBreakToHistory(insertBreak);
15805
15792
  const endPoint = this.session.insertBreak(this.selection.cursor, breakType);
15806
- let lastRow = this.selection.cursor.row === endPoint.row ? endPoint.row : Infinity;
15793
+ const lastRow = this.selection.cursor.row === endPoint.row ? endPoint.row : Infinity;
15807
15794
  this.renderer.updateLines(this.selection.cursor.row, lastRow);
15808
15795
  this.renderer.updateCursor();
15809
15796
  this.rerenderMarker();
@@ -15870,73 +15857,43 @@ class Editor {
15870
15857
  this.onContentChange();
15871
15858
  }
15872
15859
  insertImage(imageData) {
15873
- if (!this.selection.isEmpty && !this.selection.isFocused) {
15874
- const startIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.range.start);
15875
- const pageFormat = this.session.displayData.getPageFormatAtPosition(startIndex);
15876
- const adjustedImage = ImageHelper.getImageWithAllowedSize(imageData, pageFormat.contentWidth);
15877
- const insertImage = new InsertImageModel({ insertIndex: startIndex, imageData: adjustedImage });
15878
- this.replaceBy(new ReplaceModel({ insertImage }));
15879
- return;
15880
- }
15881
- const startPoint = this.selection.isFocused
15882
- ? new CursorParagraph(this.selection.cursor.row, this.selection.cursor.column + 1)
15883
- : this.selection.cursor;
15884
- const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, startPoint);
15860
+ const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.range.start);
15885
15861
  const pageFormat = this.session.displayData.getPageFormatAtPosition(insertIndex);
15886
15862
  const adjustedImage = ImageHelper.getImageWithAllowedSize(imageData, pageFormat.contentWidth);
15887
15863
  const insertImage = new InsertImageModel({ insertIndex, imageData: adjustedImage });
15864
+ if (!this.selection.isEmpty) {
15865
+ this.replaceBy(new ReplaceModel({ insertImage }));
15866
+ return;
15867
+ }
15888
15868
  this.saveInsertImageToHistory(insertImage);
15889
- const endPoint = this.session.insertImage(startPoint, adjustedImage);
15890
- let lastRow = startPoint.row === endPoint.row ? endPoint.row : Infinity;
15891
- this.renderer.updateLines(startPoint.row, lastRow);
15869
+ const endPoint = this.session.insertImage(this.selection.cursor, adjustedImage);
15870
+ const lastRow = this.selection.cursor.row === endPoint.row ? endPoint.row : Infinity;
15871
+ this.renderer.updateLines(this.selection.cursor.row, lastRow);
15892
15872
  this.renderer.updateCursor();
15893
15873
  this.rerenderMarker();
15894
15874
  this.onContentChange();
15895
15875
  }
15896
15876
  insertLink(linkDataModel) {
15897
- if (!this.selection.isEmpty && !this.selection.isFocused) {
15898
- const startIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.range.start);
15899
- const insertLink = new InsertLinkModel({ insertIndex: startIndex, linkDataModel });
15877
+ const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.range.start);
15878
+ const insertLink = new InsertLinkModel({ insertIndex, linkDataModel });
15879
+ if (!this.selection.isEmpty) {
15900
15880
  this.replaceBy(new ReplaceModel({ insertLink }));
15901
15881
  return;
15902
15882
  }
15903
- const startPoint = this.selection.isFocused
15904
- ? new CursorParagraph(this.selection.cursor.row, this.selection.cursor.column + 1)
15905
- : this.selection.cursor;
15906
- const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, startPoint);
15907
- const insertLink = new InsertLinkModel({ insertIndex, linkDataModel });
15908
15883
  this.saveInsertLinkToHistory(insertLink);
15909
- this.session.insertLink(startPoint, linkDataModel);
15884
+ this.session.insertLink(this.selection.cursor, linkDataModel);
15910
15885
  this.renderer.updateCursor();
15911
15886
  this.rerenderMarker();
15912
15887
  this.onContentChange();
15913
15888
  }
15914
15889
  insertTable(tableData) {
15915
- if (!this.selection.isEmpty && !this.selection.isFocused) {
15916
- const start = this.selection.range.start;
15917
- const end = this.selection.range.end;
15918
- const startIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, start);
15919
- const endIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, end);
15920
- const isNumbering = !!this.session.displayData.paragraphs[start.row].paragraphSettings.numberingData.numberingId;
15921
- const noParagraphLeft = startIndex !== 0 && !this.session.model.paragraphs.find(x => x.insertIndex === startIndex - 1);
15922
- const noParagraphRight = !this.session.model.paragraphs.find(x => x.insertIndex === endIndex);
15923
- const insertTable = new InsertTableModel({
15924
- insertIndex: startIndex,
15925
- rowsCount: tableData.rows,
15926
- columnsCount: tableData.columns,
15927
- insertParagraphBefore: isNumbering || noParagraphLeft,
15928
- insertParagraphAfter: isNumbering || noParagraphRight
15929
- });
15930
- this.replaceBy(new ReplaceModel({ insertTable }));
15931
- return;
15932
- }
15933
- const startPoint = this.selection.isFocused
15934
- ? new CursorParagraph(this.selection.cursor.row, this.selection.cursor.column + 1)
15935
- : this.selection.cursor;
15936
- const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, startPoint);
15937
- const isNumbering = !!this.session.displayData.paragraphs[startPoint.row].paragraphSettings.numberingData.numberingId;
15890
+ const start = this.selection.range.start;
15891
+ const end = this.selection.range.end;
15892
+ const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, start);
15893
+ const endIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, end);
15894
+ const isNumbering = !!this.session.displayData.paragraphs[start.row].paragraphSettings.numberingData.numberingId;
15938
15895
  const noParagraphLeft = insertIndex !== 0 && !this.session.model.paragraphs.find(x => x.insertIndex === insertIndex - 1);
15939
- const noParagraphRight = !this.session.model.paragraphs.find(x => x.insertIndex === insertIndex);
15896
+ const noParagraphRight = !this.session.model.paragraphs.find(x => x.insertIndex === endIndex);
15940
15897
  const insertTable = new InsertTableModel({
15941
15898
  insertIndex,
15942
15899
  rowsCount: tableData.rows,
@@ -15944,10 +15901,14 @@ class Editor {
15944
15901
  insertParagraphBefore: isNumbering || noParagraphLeft,
15945
15902
  insertParagraphAfter: isNumbering || noParagraphRight
15946
15903
  });
15904
+ if (!this.selection.isEmpty) {
15905
+ this.replaceBy(new ReplaceModel({ insertTable }));
15906
+ return;
15907
+ }
15947
15908
  this.saveInsertTableToHistory(insertTable);
15948
- const endPoint = this.session.insertTable(startPoint, insertTable);
15949
- let lastRow = startPoint.row === endPoint.row ? endPoint.row : Infinity;
15950
- this.renderer.updateLines(startPoint.row, lastRow);
15909
+ const endPoint = this.session.insertTable(this.selection.cursor, insertTable);
15910
+ const lastRow = this.selection.cursor.row === endPoint.row ? endPoint.row : Infinity;
15911
+ this.renderer.updateLines(this.selection.cursor.row, lastRow);
15951
15912
  this.renderer.updateCursor();
15952
15913
  this.onContentChange();
15953
15914
  this.rerenderMarker();
@@ -16195,7 +16156,7 @@ class Editor {
16195
16156
  });
16196
16157
  this.saveReplaceToHistory(range, replaceModel);
16197
16158
  const endPosition = this.session.replace(replaceModel);
16198
- let lastRow = range.start.row === endPosition.row ? endPosition.row : Infinity;
16159
+ const lastRow = range.start.row === endPosition.row ? endPosition.row : Infinity;
16199
16160
  this.renderer.updateLines(range.start.row, lastRow);
16200
16161
  }
16201
16162
  else {
@@ -16622,28 +16583,20 @@ class Editor {
16622
16583
  this.commandsService.createCommand(SaveCommandsHelper.getApplyDocumentPageFormatCommand(redo, this.targets));
16623
16584
  }
16624
16585
  createCustomElement(data) {
16625
- if (!this.selection.isEmpty && !this.selection.isFocused) {
16626
- const startIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.range.start);
16627
- const insertElement = new InsertElementModel({ element: new ElementModel({ ...data, insertIndex: startIndex }) });
16586
+ const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.range.start);
16587
+ const insertElement = new InsertElementModel({ element: new ElementModel({ ...data, insertIndex }) });
16588
+ if (!this.selection.isEmpty) {
16628
16589
  this.replaceBy(new ReplaceModel({ insertElement }));
16629
- this.focusCustomElement(startIndex).catch(() => {
16630
- // continue regardless error
16631
- });
16590
+ const component = this.session.displayData.customComponents.customElements.find(x => x.instance.insertIndex === insertIndex);
16591
+ this.selection.focus(component, this.selection.cursor);
16632
16592
  return;
16633
16593
  }
16634
- const startPoint = this.selection.isFocused
16635
- ? new CursorParagraph(this.selection.cursor.row, this.selection.cursor.column + 1)
16636
- : this.selection.cursor;
16637
- const insertIndex = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, startPoint);
16638
- const insertElement = new InsertElementModel({ element: new ElementModel({ ...data, insertIndex }) });
16639
16594
  this.saveInsertElementToHistory(insertElement);
16640
- const endPoint = this.session.insertElement(startPoint, data);
16641
- this.onDocumentChange(new Range(startPoint, endPoint));
16595
+ const { endPosition, component } = this.session.insertElement(this.selection.cursor, data);
16596
+ this.selection.focus(component, this.selection.cursor);
16597
+ this.onDocumentChange(new Range(this.selection.cursor, endPosition));
16642
16598
  this.onSelectionChange();
16643
16599
  this.onContentChange();
16644
- this.focusCustomElement(insertIndex).catch(() => {
16645
- // continue regardless error
16646
- });
16647
16600
  }
16648
16601
  replaceByCustomElement(textKey, model) {
16649
16602
  const index = ContentHelper.paragraphPositionToDocumentIndex(this.session.displayData.paragraphs, this.selection.cursor);
@@ -16836,7 +16789,7 @@ class Editor {
16836
16789
  const replaceModel = new ReplaceModel({ insertText, delete: deleteModel });
16837
16790
  this.saveReplaceToHistory(paragraphRange, replaceModel);
16838
16791
  const endPosition = session.session.replace(replaceModel);
16839
- let lastRow = paragraphRange.start.row === endPosition.row ? endPosition.row : Infinity;
16792
+ const lastRow = paragraphRange.start.row === endPosition.row ? endPosition.row : Infinity;
16840
16793
  this.renderer.updateLines(paragraphRange.start.row, lastRow);
16841
16794
  this.onContentChange();
16842
16795
  }
@@ -17120,13 +17073,11 @@ class Editor {
17120
17073
  links: [],
17121
17074
  comments: []
17122
17075
  });
17123
- this.editorService.lockSidenav(true);
17124
17076
  this.insertContent(insertIndex, nextElementContents);
17125
- this.focusCustomElement(insertIndex + 1)
17126
- .then(() => this.editorService.lockSidenav(false))
17127
- .catch(() => {
17128
- // continue regardless error
17129
- });
17077
+ const component = this.session.customComponents.customElements.find(x => x.instance.content.insertIndex === insertIndex + 1);
17078
+ const position = this.session.displayData.indexToPosition(component.instance.insertIndex, 0);
17079
+ this.selection.focus(component, position);
17080
+ this.onSelectionChange();
17130
17081
  }
17131
17082
  insertContent(insertIndex, contents) {
17132
17083
  const insertContents = new InsertContentsModel({ insertIndex, contents });
@@ -17301,6 +17252,7 @@ class Editor {
17301
17252
  }
17302
17253
  const position = this.session.displayData.indexToPosition(index, 0);
17303
17254
  this.selection.focus(component, position);
17255
+ this.renderer.hideCursor();
17304
17256
  this.onSelectionChange();
17305
17257
  }
17306
17258
  scrollCursorIntoMainView(offset) {
@@ -17926,21 +17878,6 @@ class Editor {
17926
17878
  this.overlayService.open(CommentPopupComponent, {}, hintX, hintY);
17927
17879
  event?.stopPropagation();
17928
17880
  }
17929
- focusCustomElement(insertIndex) {
17930
- return new Promise(resolve => {
17931
- setTimeout(() => {
17932
- // Need to skip micro tasks for a render element before focus
17933
- const component = this.session.customComponents.customElements.find(x => x.instance.content.insertIndex === insertIndex);
17934
- if (component) {
17935
- const position = this.session.displayData.indexToPosition(component.instance.insertIndex, 0);
17936
- this.selection.focus(component, position);
17937
- this.onSelectionChange();
17938
- this.scrollCursorIntoMainView();
17939
- }
17940
- resolve();
17941
- });
17942
- });
17943
- }
17944
17881
  }
17945
17882
 
17946
17883
  const EDITOR_VERSION = '2';
@@ -18475,14 +18412,7 @@ class EditorComponent {
18475
18412
  }
18476
18413
  toggleSidenavSubscription() {
18477
18414
  return this.editorService.toggleSidenav$.subscribe(data => {
18478
- const isSameComponent = this.sidenavComponentRef?.componentType === data.component;
18479
- if (data.open && (isSameComponent || this.editorService.isSidenavLocked)) {
18480
- const instance = this.sidenavComponentRef.instance;
18481
- for (const [key, value] of Object.entries(data.data || {})) {
18482
- if (key in instance) {
18483
- this.sidenavComponentRef.setInput(key, value);
18484
- }
18485
- }
18415
+ if (this.sidenavComponentRef?.componentType === data.component) {
18486
18416
  return;
18487
18417
  }
18488
18418
  this.removeSidenavComponent();
@@ -18500,9 +18430,6 @@ class EditorComponent {
18500
18430
  this.sidenav.close().catch(() => {
18501
18431
  // continue regardless of error
18502
18432
  });
18503
- if (this.editor.selection.isFocused) {
18504
- this.editor.selection.blur();
18505
- }
18506
18433
  }
18507
18434
  this.cdr.markForCheck();
18508
18435
  });