@talrace/ngx-noder 19.0.67 → 19.0.69

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.
@@ -489,6 +489,15 @@ class FormatStyleHelper {
489
489
  }
490
490
  }
491
491
 
492
+ class FontMetric {
493
+ constructor(width, ascent, descent) {
494
+ this.width = width;
495
+ this.ascent = ascent;
496
+ this.descent = descent;
497
+ this.height = ascent + descent;
498
+ }
499
+ }
500
+
492
501
  class FontMetrics {
493
502
  static { this.storageKey = 'metrics'; }
494
503
  static { this.versionKey = 'editorVersion'; }
@@ -515,7 +524,7 @@ class FontMetrics {
515
524
  this.fontStringMap[contentStyle] = identifier;
516
525
  }
517
526
  this.metrics[identifier] ??= {};
518
- if (!this.metrics[identifier][ch] || isNaN(this.metrics[identifier][ch].font)) {
527
+ if (!this.metrics[identifier][ch]) {
519
528
  this.metrics[identifier][ch] = this.calculateCanvas(ch, contentStyle);
520
529
  localStorage.setItem(this.storageKey, JSON.stringify(this.metrics));
521
530
  }
@@ -523,53 +532,10 @@ class FontMetrics {
523
532
  }
524
533
  static calculateCanvas(ch, contentStyle) {
525
534
  this.canvasNode ||= document.createElement('canvas');
526
- const fontBaseLine = this.fontBaseline(contentStyle, ch);
527
535
  const context = this.canvasNode.getContext('2d');
528
536
  context.font = contentStyle;
529
- const textMetrics = context.measureText(ch);
530
- return {
531
- width: textMetrics.width,
532
- height: textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent,
533
- font: fontBaseLine.font,
534
- ascent: textMetrics.fontBoundingBoxAscent,
535
- descent: textMetrics.fontBoundingBoxDescent
536
- };
537
- }
538
- static fontBaseline(contentStyle, text) {
539
- const container = document.body;
540
- this.measureDiv ||= document.createElement('div');
541
- this.strut ||= document.createElement('span');
542
- if (text === ' ') {
543
- text = 'X';
544
- }
545
- this.measureDiv.style.font = contentStyle;
546
- this.measureDiv.style.lineHeight = '1';
547
- this.measureDiv.style.position = 'absolute';
548
- this.measureDiv.style.visibility = 'hidden';
549
- this.measureDiv.style.margin = '0';
550
- this.measureDiv.style.padding = '0';
551
- this.measureDiv.innerHTML = text;
552
- this.strut.style.fontSize = '0';
553
- this.strut.style.verticalAlign = 'baseline';
554
- this.strut.style.padding = '0 10px';
555
- this.measureDiv.classList.add('font-baseline');
556
- this.measureDiv.appendChild(this.strut);
557
- container.appendChild(this.measureDiv);
558
- const computedStyle = window.getComputedStyle(this.measureDiv);
559
- const fontSize = parseFloat(computedStyle.fontSize);
560
- const baselineHeight = fontSize - this.strut.offsetTop;
561
- const strutHeight = this.measureDiv.offsetHeight;
562
- const lineHeight = parseFloat(computedStyle.lineHeight) || this.measureDiv.offsetHeight;
563
- this.measureDiv.parentNode.removeChild(this.measureDiv);
564
- this.measureDiv.innerHTML = '';
565
- this.strut.innerHTML = '';
566
- return {
567
- baseline: baselineHeight,
568
- content: strutHeight,
569
- font: fontSize,
570
- line: lineHeight,
571
- multiplier: fontSize / baselineHeight
572
- };
537
+ const metric = context.measureText(ch);
538
+ return new FontMetric(metric.width, metric.fontBoundingBoxAscent, metric.fontBoundingBoxDescent);
573
539
  }
574
540
  }
575
541
 
@@ -1154,8 +1120,8 @@ class EditorService {
1154
1120
  changeImageStyle(value) {
1155
1121
  this._changeImageStyle$.next(value);
1156
1122
  }
1157
- rerender(index = 0) {
1158
- this._rerender$.next(index);
1123
+ rerender(index, sessionId) {
1124
+ this._rerender$.next({ index, sessionId });
1159
1125
  }
1160
1126
  createCustomComponent(model) {
1161
1127
  this._createCustomComponent$.next(model);
@@ -1418,7 +1384,7 @@ class BaseNoderComponent extends DestroyComponent {
1418
1384
  return [];
1419
1385
  }
1420
1386
  rerender() {
1421
- this.editorService.rerender(this.insertIndex);
1387
+ this.editorService.rerender(this.insertIndex, this.sessionId);
1422
1388
  }
1423
1389
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: BaseNoderComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
1424
1390
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.5", type: BaseNoderComponent, isStandalone: true, inputs: { content: "content", sessionId: "sessionId", contentWidth: "contentWidth", generalProperties: "generalProperties" }, host: { properties: { "class.focused": "this.focused", "attr.data-session-id": "this.sessionId", "attr.data-insert-index": "this.insertIndex" } }, usesInheritance: true, ngImport: i0 }); }
@@ -7456,15 +7422,14 @@ class DisplayTokenHelper {
7456
7422
  }
7457
7423
  return result;
7458
7424
  }
7459
- return [this.getComponentToken(component, fontString, index)];
7425
+ return [this.getComponentToken(component, index)];
7460
7426
  }
7461
- static getComponentToken(component, fontString, index) {
7427
+ static getComponentToken(component, index) {
7462
7428
  const ascent = component.instance.ascent() ?? 0;
7463
7429
  const descent = component.instance.descent() ?? 0;
7464
7430
  return new DisplayToken({
7465
7431
  width: component.instance.width(),
7466
7432
  height: ascent + descent,
7467
- font: FontMetrics.measureCharSize('0', fontString).font,
7468
7433
  ascent,
7469
7434
  descent,
7470
7435
  displayValue: this.getComponentDisplayValue(component.instance),
@@ -7472,7 +7437,7 @@ class DisplayTokenHelper {
7472
7437
  });
7473
7438
  }
7474
7439
  static getTableTokens(component, fontString, index, withNumbering) {
7475
- const tableToken = this.getComponentToken(component, fontString, index);
7440
+ const tableToken = this.getComponentToken(component, index);
7476
7441
  if (!withNumbering) {
7477
7442
  return [tableToken];
7478
7443
  }
@@ -8257,9 +8222,6 @@ class DisplayData extends EventEmitting {
8257
8222
  getParagraphContent(index) {
8258
8223
  return this.paragraphs[index]?.content || '';
8259
8224
  }
8260
- getAllParagraphsContent() {
8261
- return this.paragraphs.map(x => x.content);
8262
- }
8263
8225
  getParagraphSettings(index) {
8264
8226
  return this.paragraphs[index]?.paragraphSettings || null;
8265
8227
  }
@@ -8278,48 +8240,18 @@ class DisplayData extends EventEmitting {
8278
8240
  getTextRange(range) {
8279
8241
  return this.getParagraphsContentForRange(range).join(NEW_LINE_MARKUP);
8280
8242
  }
8281
- positionToIndex(position, startRow = 0) {
8282
- let index = 0;
8283
- const endRow = Math.min(position.row, this.paragraphs.length);
8284
- for (let i = startRow || 0; i < endRow; i++) {
8285
- index += this.paragraphs[i].content.length + 1;
8286
- }
8287
- return index + position.column;
8243
+ positionToIndex(position) {
8244
+ return this.paragraphs[position.row].startIndex + position.column;
8288
8245
  }
8289
- indexToPosition(positionIndex, startRow) {
8290
- const newlineLength = NEW_LINE_MARKUP.length;
8291
- for (let lineIndex = startRow || 0; lineIndex < this.paragraphs.length; lineIndex++) {
8292
- positionIndex -= this.paragraphs[lineIndex].content.length + newlineLength;
8293
- if (positionIndex < 0) {
8294
- const column = positionIndex + this.paragraphs[lineIndex].content.length + newlineLength;
8295
- return new CursorParagraph(lineIndex, column);
8296
- }
8297
- }
8298
- const column = positionIndex + this.paragraphs[this.paragraphs.length - 1].content.length + newlineLength;
8299
- return new CursorParagraph(this.paragraphs.length - 1, column);
8246
+ indexToPosition(positionIndex) {
8247
+ const paragraph = this.paragraphs.findLastIndex(x => x.startIndex <= positionIndex);
8248
+ return new CursorParagraph(paragraph, positionIndex - this.paragraphs[paragraph].startIndex);
8300
8249
  }
8301
8250
  indexesToRange(startIndex, endIndex) {
8302
- const startPoint = this.indexToPosition(startIndex, 0);
8303
- const endPoint = this.indexToPosition(endIndex, 0);
8251
+ const startPoint = this.indexToPosition(startIndex);
8252
+ const endPoint = this.indexToPosition(endIndex);
8304
8253
  return new Range(startPoint, endPoint);
8305
8254
  }
8306
- getSelectedParagraphsByRange(range) {
8307
- const newlineLength = NEW_LINE_MARKUP.length;
8308
- let start = 0;
8309
- let end = 0;
8310
- let i;
8311
- const row = Math.min(range.end.row, this.paragraphs.length - 1);
8312
- for (i = 0; i < row; i++) {
8313
- if (i < range.start.row) {
8314
- start += this.paragraphs[i].content.length + newlineLength;
8315
- }
8316
- end += this.paragraphs[i].content.length + newlineLength;
8317
- }
8318
- if (i < this.paragraphs.length) {
8319
- end += this.paragraphs[i].content.length;
8320
- }
8321
- return { start, end };
8322
- }
8323
8255
  getPositionAfterBreak(position, breakType) {
8324
8256
  if (breakType === BreakTypes.TextWrapping) {
8325
8257
  return position;
@@ -9833,7 +9765,7 @@ class EditSession {
9833
9765
  const imageComponentRef = this.customComponents.images.find(x => x.instance.insertIndex === applyImage.insertIndex);
9834
9766
  imageComponentRef.instance.resize({ width: applyImage.width, height: applyImage.height });
9835
9767
  OperationsHelper.applyImageStyle(this.model, applyImage);
9836
- const start = this.displayData.indexToPosition(applyImage.insertIndex, 0);
9768
+ const start = this.displayData.indexToPosition(applyImage.insertIndex);
9837
9769
  this.displayData.updateNextLineIndexes(start.row, this.displayData.paragraphs.length - 1);
9838
9770
  }
9839
9771
  restoreTextStyles(formats, linkFormats) {
@@ -10044,8 +9976,8 @@ class EditSession {
10044
9976
  }
10045
9977
  removeMoveRange(moveModel) {
10046
9978
  const endIndex = moveModel.sourceStartIndex + moveModel.sourceCount - 1;
10047
- const startPosition = this.displayData.indexToPosition(moveModel.sourceStartIndex, 0);
10048
- const endPosition = this.displayData.indexToPosition(endIndex + 1, 0);
9979
+ const startPosition = this.displayData.indexToPosition(moveModel.sourceStartIndex);
9980
+ const endPosition = this.displayData.indexToPosition(endIndex + 1);
10049
9981
  const sourceRange = new Range(startPosition, endPosition);
10050
9982
  this.displayData.removeRange(sourceRange);
10051
9983
  CustomComponentHelper.applyRemovingComponents(this.customComponents.tables, moveModel.sourceStartIndex, endIndex);
@@ -10070,8 +10002,8 @@ class EditSession {
10070
10002
  this.displayData.updateNextLineIndexes(startPosition.row, endPosition.row);
10071
10003
  this.selection.placeCursor(endPosition);
10072
10004
  this.applyToolbarStyles();
10073
- const newStartPosition = this.displayData.indexToPosition(moveIndex, 0);
10074
- const newEndPosition = this.displayData.indexToPosition(moveIndex + moveModel.sourceCount, 0);
10005
+ const newStartPosition = this.displayData.indexToPosition(moveIndex);
10006
+ const newEndPosition = this.displayData.indexToPosition(moveIndex + moveModel.sourceCount);
10075
10007
  return new Range(newStartPosition, newEndPosition);
10076
10008
  }
10077
10009
  isPositionInRange(position, range) {
@@ -12619,7 +12551,7 @@ class RegulatorService {
12619
12551
  });
12620
12552
  }
12621
12553
  getSessionModel(sessionId) {
12622
- return this.sessions.find(x => x.sessionId === sessionId);
12554
+ return this.currentSession.sessionId === sessionId ? this.currentSession : this.sessions.find(x => x.sessionId === sessionId);
12623
12555
  }
12624
12556
  getSession(sessionId) {
12625
12557
  return this.getSessionModel(sessionId).session;
@@ -12752,6 +12684,9 @@ class RegulatorService {
12752
12684
  }
12753
12685
  });
12754
12686
  }
12687
+ rerender(index, sessionId) {
12688
+ this.getSession(sessionId).rerender(index);
12689
+ }
12755
12690
  toggleGrammarChecks(value) {
12756
12691
  this.grammarEnabled = value;
12757
12692
  if (this.grammarEnabled) {
@@ -13043,16 +12978,16 @@ class TableOverlayMenuComponent {
13043
12978
  const insertRowsBelowMessage = this.selectedRowsCount > 1
13044
12979
  ? this.translateService.instant('NODER.COMPLEX_LABEL.INSERT_ROWS_BELOW', { count: this.selectedRowsCount })
13045
12980
  : this.translateService.instant('NODER.LABEL.INSERT_ROW_BELOW');
13046
- const insertColumnsLeftMessage = this.selectedRowsCount > 1
12981
+ const insertColumnsLeftMessage = this.selectedColumnsCount > 1
13047
12982
  ? this.translateService.instant('NODER.COMPLEX_LABEL.INSERT_COLUMNS_TO_THE_LEFT', { count: this.selectedColumnsCount })
13048
12983
  : this.translateService.instant('NODER.LABEL.INSERT_COLUMN_TO_THE_LEFT');
13049
- const insertColumnsRightMessage = this.selectedRowsCount > 1
12984
+ const insertColumnsRightMessage = this.selectedColumnsCount > 1
13050
12985
  ? this.translateService.instant('NODER.COMPLEX_LABEL.INSERT_COLUMNS_TO_THE_RIGHT', { count: this.selectedColumnsCount })
13051
12986
  : this.translateService.instant('NODER.LABEL.INSERT_COLUMN_TO_THE_RIGHT');
13052
12987
  const removeRowsMessage = this.selectedRowsCount > 1
13053
12988
  ? this.translateService.instant('NODER.COMPLEX_LABEL.REMOVE_ROWS', { count: this.selectedRowsCount })
13054
12989
  : this.translateService.instant('NODER.LABEL.REMOVE_ROW');
13055
- const removeColumnsMessage = this.selectedRowsCount > 1
12990
+ const removeColumnsMessage = this.selectedColumnsCount > 1
13056
12991
  ? this.translateService.instant('NODER.COMPLEX_LABEL.REMOVE_COLUMNS', { count: this.selectedColumnsCount })
13057
12992
  : this.translateService.instant('NODER.LABEL.REMOVE_COLUMN');
13058
12993
  const removeTableMessage = this.translateService.instant('NODER.LABEL.REMOVE_TABLE');
@@ -13476,15 +13411,17 @@ class TableSelection {
13476
13411
  }
13477
13412
  getTargetsForMenuOverlay(selectionRange) {
13478
13413
  return new SelectionRangeModel({
13479
- startIndex: this.getTargetRowStartIndex(selectionRange.rowIndexes.startIndex),
13480
- endIndex: this.getTargetRowEndIndex(selectionRange.rowIndexes.endIndex)
13414
+ startIndex: this.getTargetRowStartIndex(selectionRange.rowIndexes.startIndex, selectionRange.cellIndexes.startIndex, selectionRange.cellIndexes.endIndex),
13415
+ endIndex: this.getTargetRowEndIndex(selectionRange.rowIndexes.endIndex, selectionRange.cellIndexes.startIndex, selectionRange.cellIndexes.endIndex)
13481
13416
  }, {
13482
13417
  startIndex: this.getTargetColumnStartIndex(selectionRange.rowIndexes.startIndex, selectionRange.rowIndexes.endIndex, selectionRange.cellIndexes.startIndex),
13483
13418
  endIndex: this.getTargetColumnEndIndex(selectionRange.rowIndexes.startIndex, selectionRange.rowIndexes.endIndex, selectionRange.cellIndexes.endIndex)
13484
13419
  });
13485
13420
  }
13486
- getTargetRowStartIndex(startIndex) {
13487
- const mergedRowCells = this.rowMatrix[startIndex].cells.filter(x => x.cell.rowSpan > 1 && x.componentRef.instance.cell.verticalMerge);
13421
+ getTargetRowStartIndex(startIndex, cellStartIndex, cellEndIndex) {
13422
+ const mergedRowCells = this.rowMatrix[startIndex].cells
13423
+ .slice(cellStartIndex, cellEndIndex + 1)
13424
+ .filter(x => x.cell.rowSpan > 1 && x.componentRef.instance.cell.verticalMerge);
13488
13425
  if (!mergedRowCells.length) {
13489
13426
  return startIndex;
13490
13427
  }
@@ -13499,8 +13436,10 @@ class TableSelection {
13499
13436
  }
13500
13437
  return index + 1;
13501
13438
  }
13502
- getTargetRowEndIndex(endIndex) {
13503
- const mergedRowCells = this.rowMatrix[endIndex].cells.filter(x => x.cell.rowSpan > 1 && x.componentRef.instance.cell.verticalMerge);
13439
+ getTargetRowEndIndex(endIndex, cellStartIndex, cellEndIndex) {
13440
+ const mergedRowCells = this.rowMatrix[endIndex].cells
13441
+ .slice(cellStartIndex, cellEndIndex + 1)
13442
+ .filter(x => x.cell.rowSpan > 1 && x.componentRef.instance.cell.verticalMerge);
13504
13443
  if (!mergedRowCells.length) {
13505
13444
  return endIndex + 1;
13506
13445
  }
@@ -15629,7 +15568,6 @@ class Editor {
15629
15568
  this.subscriptions = [];
15630
15569
  this.commentCreateRequests = [];
15631
15570
  this.emojiRegex = /\p{Extended_Pictographic}(?:\p{Emoji_Modifier}|\u{200D}\p{Extended_Pictographic})*/gu;
15632
- this.isRerenderSubscriptionOpen = true;
15633
15571
  this.rerenderResize = () => {
15634
15572
  this.mainRenderer.onResize(true);
15635
15573
  };
@@ -17075,7 +17013,7 @@ class Editor {
17075
17013
  });
17076
17014
  this.insertContent(insertIndex, nextElementContents);
17077
17015
  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);
17016
+ const position = this.session.displayData.indexToPosition(component.instance.insertIndex);
17079
17017
  this.selection.focus(component, position);
17080
17018
  this.onSelectionChange();
17081
17019
  }
@@ -17250,7 +17188,7 @@ class Editor {
17250
17188
  if (!component) {
17251
17189
  return;
17252
17190
  }
17253
- const position = this.session.displayData.indexToPosition(index, 0);
17191
+ const position = this.session.displayData.indexToPosition(index);
17254
17192
  this.selection.focus(component, position);
17255
17193
  this.renderer.hideCursor();
17256
17194
  this.onSelectionChange();
@@ -17532,9 +17470,7 @@ class Editor {
17532
17470
  return this.editorService.setImageStyle$.subscribe(image => this.applyImageStyles(image));
17533
17471
  }
17534
17472
  rerenderSubscription() {
17535
- return this.editorService.rerender$.pipe(filter(() => this.isRerenderSubscriptionOpen)).subscribe(index => {
17536
- this.session.rerender(index);
17537
- });
17473
+ return this.editorService.rerender$.subscribe(x => this.regulatorService.rerender(x.index, x.sessionId));
17538
17474
  }
17539
17475
  createCustomComponentSubscription() {
17540
17476
  return this.editorService.createCustomComponent$.subscribe(model => {
@@ -17834,9 +17770,7 @@ class Editor {
17834
17770
  this.changeCellsWidth(table.rows, scalingRatio);
17835
17771
  });
17836
17772
  this.selection.navigateFileStart();
17837
- this.isRerenderSubscriptionOpen = false;
17838
17773
  this.regulatorService.addMainSession(this.model, scalingRatio, this.container);
17839
- this.isRerenderSubscriptionOpen = true;
17840
17774
  this.textInput = new TextInput(this.mainRenderer.container);
17841
17775
  this.mainRenderer.textarea = this.textInput.input;
17842
17776
  this.touchHandler.destroy();