@trebco/treb 25.5.0 → 25.6.0

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.
@@ -88,7 +88,7 @@ import type { GridOptions } from './grid_options';
88
88
  import { BorderConstants } from './border_constants';
89
89
  import type { SerializeOptions } from './serialize_options';
90
90
  import { UA } from '../util/ua';
91
- import { Annotation } from './annotation';
91
+ import { Annotation, type AnnotationData } from './annotation';
92
92
  import { Autocomplete } from '../editors/autocomplete';
93
93
 
94
94
  import { MouseDrag } from './drag_mask';
@@ -468,21 +468,21 @@ export class Grid extends GridBase {
468
468
  * @param target new parameter allows setting annotation as rect or as
469
469
  * cell range
470
470
  */
471
- public CreateAnnotation(properties: Partial<Annotation> = {}, add_to_sheet = true, offset = false, target?: Partial<Area>|IRectangle): Annotation {
472
- const annotation = new Annotation(properties as Partial<Annotation>);
471
+ public CreateAnnotation(properties: Partial<AnnotationData> = {}, add_to_sheet = true, offset = false, target?: Partial<Area>|IRectangle): Annotation {
472
+ const annotation = new Annotation(properties);
473
473
 
474
474
  if (offset) {
475
475
 
476
476
  // to offset, we have to have layout (or at least scaled rect)
477
- if (!annotation.layout && annotation.scaled_rect) {
478
- annotation.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
477
+ if (!annotation.data.layout && annotation.scaled_rect) {
478
+ annotation.data.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
479
479
  }
480
480
 
481
- if (!annotation.layout) {
481
+ if (!annotation.data.layout) {
482
482
  console.warn(`can't offset annotation without layout`);
483
483
  }
484
484
  else {
485
- let target_rect = this.layout.AnnotationLayoutToRect(annotation.layout).Shift(20, 20);
485
+ let target_rect = this.layout.AnnotationLayoutToRect(annotation.data.layout).Shift(20, 20);
486
486
  let recheck = true;
487
487
  while (recheck) {
488
488
  recheck = false;
@@ -495,19 +495,19 @@ export class Grid extends GridBase {
495
495
  }
496
496
  }
497
497
  }
498
- annotation.layout = this.layout.RectToAnnotationLayout(target_rect);
498
+ annotation.data.layout = this.layout.RectToAnnotationLayout(target_rect);
499
499
  }
500
500
  }
501
501
 
502
502
  if (target) {
503
503
  if (Rectangle.IsRectangle(target)) {
504
504
  // console.info('creating from rectangle,', target);
505
- annotation.layout = undefined;
505
+ annotation.data.layout = undefined;
506
506
  annotation.rect = Rectangle.Create(target);
507
507
  }
508
508
  else if (target.start) {
509
509
  annotation.rect = undefined;
510
- annotation.layout = this.layout.AddressToAnnotationLayout(target.start, target.end||target.start);
510
+ annotation.data.layout = this.layout.AddressToAnnotationLayout(target.start, target.end||target.start);
511
511
  }
512
512
  }
513
513
 
@@ -569,8 +569,8 @@ export class Grid extends GridBase {
569
569
  this.grid_events.Publish(event);
570
570
  }
571
571
 
572
- if (annotation.layout) {
573
- this.EnsureAddress(annotation.layout.br.address, 1);
572
+ if (annotation.data.layout) {
573
+ this.EnsureAddress(annotation.data.layout.br.address, 1);
574
574
  }
575
575
 
576
576
  });
@@ -710,11 +710,11 @@ export class Grid extends GridBase {
710
710
  element.style.left = (rect.left) + 'px';
711
711
  }
712
712
 
713
- annotation.extent = undefined; // reset
713
+ annotation.data.extent = undefined; // reset
714
714
  this.grid_events.Publish({ type: 'annotation', event: 'move', annotation });
715
715
 
716
716
  // annotation.rect = rect.Scale(1/this.layout.scale);
717
- annotation.layout = this.layout.RectToAnnotationLayout(rect);
717
+ annotation.data.layout = this.layout.RectToAnnotationLayout(rect);
718
718
 
719
719
  }
720
720
 
@@ -730,8 +730,8 @@ export class Grid extends GridBase {
730
730
 
731
731
  if (add_to_layout) {
732
732
  this.layout.AddAnnotation(annotation);
733
- if (annotation.layout) {
734
- this.EnsureAddress(annotation.layout.br.address, 1);
733
+ if (annotation.data.layout) {
734
+ this.EnsureAddress(annotation.data.layout.br.address, 1);
735
735
  }
736
736
  }
737
737
  else {
@@ -2560,7 +2560,7 @@ export class Grid extends GridBase {
2560
2560
  const annotation = this.editing_annotation;
2561
2561
  this.ClearAdditionalSelections();
2562
2562
  this.ClearSelection(this.active_selection);
2563
- annotation.formula = event.value ? this.FixFormula(event.value) : '';
2563
+ annotation.data.formula = event.value ? this.FixFormula(event.value) : '';
2564
2564
  const node = this.editing_annotation.view[this.view_index]?.node;
2565
2565
  if (node) {
2566
2566
  node.focus();
@@ -2784,10 +2784,10 @@ export class Grid extends GridBase {
2784
2784
  const start = this.render_tiles.start;
2785
2785
  const end = this.render_tiles.end;
2786
2786
 
2787
- const row_list = [];
2787
+ const row_list: number[] = [];
2788
2788
  for (let row = start.row; row <= end.row; row++) row_list.push(row);
2789
2789
 
2790
- const column_list = [];
2790
+ const column_list: number[] = [];
2791
2791
  for (let column = start.column; column <= end.column; column++) column_list.push(column);
2792
2792
 
2793
2793
  // FIXME: multiple tiles
@@ -2959,11 +2959,11 @@ export class Grid extends GridBase {
2959
2959
  const node = annotation.view[this.view_index]?.node;
2960
2960
  if (node) { nodes.push(node); }
2961
2961
 
2962
- if (y <= annotation.scaled_rect.top && annotation.move_with_cells) {
2962
+ if (y <= annotation.scaled_rect.top && annotation.data.move_with_cells) {
2963
2963
  move_annotation_list.push({ annotation, y: annotation.scaled_rect.top, nodes });
2964
2964
  }
2965
2965
 
2966
- else if (y > annotation.scaled_rect.top && annotation.resize_with_cells) {
2966
+ else if (y > annotation.scaled_rect.top && annotation.data.resize_with_cells) {
2967
2967
  size_annotation_list.push({ annotation, height: annotation.scaled_rect.height, nodes });
2968
2968
  }
2969
2969
 
@@ -3081,13 +3081,13 @@ export class Grid extends GridBase {
3081
3081
 
3082
3082
  for (const { annotation } of move_annotation_list) {
3083
3083
  if (annotation.scaled_rect) {
3084
- annotation.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3084
+ annotation.data.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3085
3085
  }
3086
3086
  }
3087
3087
 
3088
3088
  for (const { annotation } of size_annotation_list) {
3089
3089
  if (annotation.scaled_rect) {
3090
- annotation.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3090
+ annotation.data.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3091
3091
  }
3092
3092
  const view = annotation.view[this.view_index];
3093
3093
  if (view && view.resize_callback) {
@@ -3233,10 +3233,10 @@ export class Grid extends GridBase {
3233
3233
  const node = annotation.view[this.view_index]?.node;
3234
3234
  if (node) { nodes.push(node); }
3235
3235
 
3236
- if (x <= annotation.scaled_rect.left && annotation.move_with_cells) {
3236
+ if (x <= annotation.scaled_rect.left && annotation.data.move_with_cells) {
3237
3237
  move_annotation_list.push({ annotation, x: annotation.scaled_rect.left, nodes });
3238
3238
  }
3239
- else if (x > annotation.scaled_rect.left && annotation.resize_with_cells) {
3239
+ else if (x > annotation.scaled_rect.left && annotation.data.resize_with_cells) {
3240
3240
  size_annotation_list.push({ annotation, width: annotation.scaled_rect.width, nodes });
3241
3241
  }
3242
3242
  }
@@ -3345,13 +3345,13 @@ export class Grid extends GridBase {
3345
3345
 
3346
3346
  for (const { annotation } of move_annotation_list) {
3347
3347
  if (annotation.scaled_rect) {
3348
- annotation.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3348
+ annotation.data.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3349
3349
  }
3350
3350
  }
3351
3351
 
3352
3352
  for (const { annotation } of size_annotation_list) {
3353
3353
  if (annotation.scaled_rect) {
3354
- annotation.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3354
+ annotation.data.layout = this.layout.RectToAnnotationLayout(annotation.scaled_rect);
3355
3355
  }
3356
3356
  const view = annotation.view[this.view_index];
3357
3357
  if (view && view.resize_callback) {
@@ -5868,8 +5868,8 @@ export class Grid extends GridBase {
5868
5868
  private HideGridSelection() {
5869
5869
  this.UpdateAddressLabel(undefined, '');
5870
5870
 
5871
- const formula = (this.selected_annotation && this.selected_annotation.formula) ?
5872
- this.selected_annotation.formula : '';
5871
+ const formula = (this.selected_annotation && this.selected_annotation.data.formula) ?
5872
+ this.selected_annotation.data.formula : '';
5873
5873
 
5874
5874
  this.UpdateFormulaBarFormula(formula);
5875
5875
  this.layout.ShowSelections(false);
@@ -2188,9 +2188,9 @@ export class GridBase {
2188
2188
 
2189
2189
  // annotations
2190
2190
  for (const annotation of sheet.annotations) {
2191
- if (annotation.formula) {
2191
+ if (annotation.data.formula) {
2192
2192
  let modified = false;
2193
- const parsed = this.parser.Parse(annotation.formula || '');
2193
+ const parsed = this.parser.Parse(annotation.data.formula || '');
2194
2194
  if (parsed.expression) {
2195
2195
  this.parser.Walk(parsed.expression, (element: ExpressionUnit) => {
2196
2196
  if (element.type === 'address') {
@@ -2202,7 +2202,7 @@ export class GridBase {
2202
2202
  return true; // continue walk
2203
2203
  });
2204
2204
  if (modified) {
2205
- annotation.formula = '=' + this.parser.Render(parsed.expression, { missing: '' });
2205
+ annotation.data.formula = '=' + this.parser.Render(parsed.expression, { missing: '' });
2206
2206
  changes++;
2207
2207
  }
2208
2208
  }
@@ -2770,12 +2770,12 @@ export class GridBase {
2770
2770
  });
2771
2771
 
2772
2772
  for (const annotation of sheet.annotations) {
2773
- if (annotation.formula) {
2774
- const modified = this.PatchFormulasInternal(annotation.formula || '',
2773
+ if (annotation.data.formula) {
2774
+ const modified = this.PatchFormulasInternal(annotation.data.formula || '',
2775
2775
  command.before_row, command.count, 0, 0,
2776
2776
  target_sheet_name, is_target);
2777
2777
  if (modified) {
2778
- annotation.formula = modified;
2778
+ annotation.data.formula = modified;
2779
2779
  }
2780
2780
  }
2781
2781
  }
@@ -2794,11 +2794,11 @@ export class GridBase {
2794
2794
  const first = command.before_row;
2795
2795
 
2796
2796
  for (const annotation of target_sheet.annotations) {
2797
- if (annotation.layout) {
2797
+ if (annotation.data.layout) {
2798
2798
  const [start, end, endy] = [
2799
- annotation.layout.tl.address.row,
2800
- annotation.layout.br.address.row,
2801
- annotation.layout.br.offset.y,
2799
+ annotation.data.layout.tl.address.row,
2800
+ annotation.data.layout.br.address.row,
2801
+ annotation.data.layout.br.offset.y,
2802
2802
  ];
2803
2803
 
2804
2804
  if (first <= start ) {
@@ -2806,15 +2806,15 @@ export class GridBase {
2806
2806
  // start case 1: starts above the annotation (including exactly at the top)
2807
2807
 
2808
2808
  // shift
2809
- annotation.layout.tl.address.row += command.count;
2810
- annotation.layout.br.address.row += command.count;
2809
+ annotation.data.layout.tl.address.row += command.count;
2810
+ annotation.data.layout.br.address.row += command.count;
2811
2811
 
2812
2812
  }
2813
2813
  else if (first < end || first === end && endy > 0) {
2814
2814
 
2815
2815
  // start case 2: starts in the annotation, omitting the first row
2816
2816
 
2817
- annotation.layout.br.address.row += command.count;
2817
+ annotation.data.layout.br.address.row += command.count;
2818
2818
 
2819
2819
  // size changing
2820
2820
  resize_annotations_list.push(annotation);
@@ -2839,16 +2839,16 @@ export class GridBase {
2839
2839
  const last = command.before_row - command.count - 1;
2840
2840
 
2841
2841
  for (const annotation of target_sheet.annotations) {
2842
- if (annotation.layout) {
2842
+ if (annotation.data.layout) {
2843
2843
 
2844
2844
  // start and end row of the annotation. recall that in
2845
2845
  // this layout, the annotation may extend into the (first,last)
2846
2846
  // row but not beyond it. the offset is _within_ the row.
2847
2847
 
2848
2848
  const [start, end, endy] = [
2849
- annotation.layout.tl.address.row,
2850
- annotation.layout.br.address.row,
2851
- annotation.layout.br.offset.y,
2849
+ annotation.data.layout.tl.address.row,
2850
+ annotation.data.layout.br.address.row,
2851
+ annotation.data.layout.br.offset.y,
2852
2852
  ];
2853
2853
 
2854
2854
  if (first <= start ) {
@@ -2860,8 +2860,8 @@ export class GridBase {
2860
2860
  // end case 1: ends before the annotation
2861
2861
 
2862
2862
  // shift
2863
- annotation.layout.tl.address.row += command.count;
2864
- annotation.layout.br.address.row += command.count;
2863
+ annotation.data.layout.tl.address.row += command.count;
2864
+ annotation.data.layout.br.address.row += command.count;
2865
2865
 
2866
2866
  }
2867
2867
  else if (last < end - 1 || (last === end -1 && endy > 0)) {
@@ -2869,9 +2869,9 @@ export class GridBase {
2869
2869
  // end case 2: ends before the end of the annotation
2870
2870
 
2871
2871
  // shift + cut
2872
- annotation.layout.tl.address.row = first;
2873
- annotation.layout.tl.offset.y = 0;
2874
- annotation.layout.br.address.row += command.count;
2872
+ annotation.data.layout.tl.address.row = first;
2873
+ annotation.data.layout.tl.offset.y = 0;
2874
+ annotation.data.layout.br.address.row += command.count;
2875
2875
 
2876
2876
  // size changing
2877
2877
  resize_annotations_list.push(annotation);
@@ -2897,7 +2897,7 @@ export class GridBase {
2897
2897
  // end case 2: ends before the end of the annotation
2898
2898
 
2899
2899
  // shorten
2900
- annotation.layout.br.address.row += command.count;
2900
+ annotation.data.layout.br.address.row += command.count;
2901
2901
 
2902
2902
  // size changing
2903
2903
  resize_annotations_list.push(annotation);
@@ -2908,8 +2908,8 @@ export class GridBase {
2908
2908
  // end case 3: ends after the annotation
2909
2909
 
2910
2910
  // clip
2911
- annotation.layout.br.address.row = first;
2912
- annotation.layout.br.offset.y = 0;
2911
+ annotation.data.layout.br.address.row = first;
2912
+ annotation.data.layout.br.offset.y = 0;
2913
2913
 
2914
2914
  // size changing
2915
2915
  resize_annotations_list.push(annotation);
@@ -3096,12 +3096,12 @@ export class GridBase {
3096
3096
  });
3097
3097
 
3098
3098
  for (const annotation of sheet.annotations) {
3099
- if (annotation.formula) {
3100
- const modified = this.PatchFormulasInternal(annotation.formula,
3099
+ if (annotation.data.formula) {
3100
+ const modified = this.PatchFormulasInternal(annotation.data.formula,
3101
3101
  0, 0, command.before_column, command.count,
3102
3102
  target_sheet_name, is_target);
3103
3103
  if (modified) {
3104
- annotation.formula = modified;
3104
+ annotation.data.formula = modified;
3105
3105
  }
3106
3106
  }
3107
3107
  }
@@ -3119,11 +3119,11 @@ export class GridBase {
3119
3119
  const first = command.before_column;
3120
3120
 
3121
3121
  for (const annotation of target_sheet.annotations) {
3122
- if (annotation.layout) {
3122
+ if (annotation.data.layout) {
3123
3123
  const [start, end, endx] = [
3124
- annotation.layout.tl.address.column,
3125
- annotation.layout.br.address.column,
3126
- annotation.layout.br.offset.x,
3124
+ annotation.data.layout.tl.address.column,
3125
+ annotation.data.layout.br.address.column,
3126
+ annotation.data.layout.br.offset.x,
3127
3127
  ];
3128
3128
 
3129
3129
  if (first <= start ) {
@@ -3131,15 +3131,15 @@ export class GridBase {
3131
3131
  // start case 1: starts to the left of the annotation (including exactly at the left)
3132
3132
 
3133
3133
  // shift
3134
- annotation.layout.tl.address.column += command.count;
3135
- annotation.layout.br.address.column += command.count;
3134
+ annotation.data.layout.tl.address.column += command.count;
3135
+ annotation.data.layout.br.address.column += command.count;
3136
3136
 
3137
3137
  }
3138
3138
  else if (first < end || first === end && endx > 0) {
3139
3139
 
3140
3140
  // start case 2: starts in the annotation, omitting the first column
3141
3141
 
3142
- annotation.layout.br.address.column += command.count;
3142
+ annotation.data.layout.br.address.column += command.count;
3143
3143
 
3144
3144
  // size changing
3145
3145
  resize_annotations_list.push(annotation);
@@ -3164,16 +3164,16 @@ export class GridBase {
3164
3164
  const last = command.before_column - command.count - 1;
3165
3165
 
3166
3166
  for (const annotation of target_sheet.annotations) {
3167
- if (annotation.layout) {
3167
+ if (annotation.data.layout) {
3168
3168
 
3169
3169
  // start and end column of the annotation. recall that in
3170
3170
  // this layout, the annotation may extend into the (first,last)
3171
3171
  // column but not beyond it. the offset is _within_ the column.
3172
3172
 
3173
3173
  const [start, end, endx] = [
3174
- annotation.layout.tl.address.column,
3175
- annotation.layout.br.address.column,
3176
- annotation.layout.br.offset.x,
3174
+ annotation.data.layout.tl.address.column,
3175
+ annotation.data.layout.br.address.column,
3176
+ annotation.data.layout.br.offset.x,
3177
3177
  ];
3178
3178
 
3179
3179
  if (first <= start ) {
@@ -3185,8 +3185,8 @@ export class GridBase {
3185
3185
  // end case 1: ends before the annotation
3186
3186
 
3187
3187
  // shift
3188
- annotation.layout.tl.address.column += command.count;
3189
- annotation.layout.br.address.column += command.count;
3188
+ annotation.data.layout.tl.address.column += command.count;
3189
+ annotation.data.layout.br.address.column += command.count;
3190
3190
 
3191
3191
  }
3192
3192
  else if (last < end - 1 || (last === end -1 && endx > 0)) {
@@ -3194,9 +3194,9 @@ export class GridBase {
3194
3194
  // end case 2: ends before the end of the annotation
3195
3195
 
3196
3196
  // shift + cut
3197
- annotation.layout.tl.address.column = first;
3198
- annotation.layout.tl.offset.x = 0;
3199
- annotation.layout.br.address.column += command.count;
3197
+ annotation.data.layout.tl.address.column = first;
3198
+ annotation.data.layout.tl.offset.x = 0;
3199
+ annotation.data.layout.br.address.column += command.count;
3200
3200
 
3201
3201
  // size changing
3202
3202
  resize_annotations_list.push(annotation);
@@ -3222,7 +3222,7 @@ export class GridBase {
3222
3222
  // end case 2: ends before the end of the annotation
3223
3223
 
3224
3224
  // shorten
3225
- annotation.layout.br.address.column += command.count;
3225
+ annotation.data.layout.br.address.column += command.count;
3226
3226
 
3227
3227
  // size changing
3228
3228
  resize_annotations_list.push(annotation);
@@ -3233,8 +3233,8 @@ export class GridBase {
3233
3233
  // end case 3: ends after the annotation
3234
3234
 
3235
3235
  // clip
3236
- annotation.layout.br.address.column = first;
3237
- annotation.layout.br.offset.x = 0;
3236
+ annotation.data.layout.br.address.column = first;
3237
+ annotation.data.layout.br.offset.x = 0;
3238
3238
 
3239
3239
  // size changing
3240
3240
  resize_annotations_list.push(annotation);
@@ -2512,12 +2512,12 @@ export class Sheet {
2512
2512
  // push out for annotations
2513
2513
 
2514
2514
  for (const annotation of this.annotations) {
2515
- if (!annotation.extent) {
2515
+ if (!annotation.data.extent) {
2516
2516
  this.CalculateAnnotationExtent(annotation);
2517
2517
  }
2518
- if (annotation.extent) {
2519
- rows = Math.max(rows, annotation.extent.row + 1);
2520
- columns = Math.max(columns, annotation.extent.column + 1);
2518
+ if (annotation.data.extent) {
2519
+ rows = Math.max(rows, annotation.data.extent.row + 1);
2520
+ columns = Math.max(columns, annotation.data.extent.column + 1);
2521
2521
  }
2522
2522
  }
2523
2523
 
@@ -2769,22 +2769,22 @@ export class Sheet {
2769
2769
  // at some point, we just need to make sure that happens before this
2770
2770
  // is called
2771
2771
 
2772
- if (annotation.layout) {
2773
- annotation.extent = { ...annotation.layout.br.address };
2772
+ if (annotation.data.layout) {
2773
+ annotation.data.extent = { ...annotation.data.layout.br.address };
2774
2774
  return;
2775
2775
  }
2776
2776
 
2777
2777
  // 1000 here is just sanity check, it might be larger
2778
2778
  const sanity = 1000;
2779
2779
 
2780
- annotation.extent = { row: 0, column: 0 };
2780
+ annotation.data.extent = { row: 0, column: 0 };
2781
2781
 
2782
2782
  let right = annotation.rect?.right;
2783
2783
  if (right && this.default_column_width) { // also sanity check
2784
2784
  for (let i = 0; right >= 0 && i < sanity; i++) {
2785
2785
  right -= this.GetColumnWidth(i); // FIXME: check // it's ok, rect is scaled to unit
2786
2786
  if (right < 0) {
2787
- annotation.extent.column = i;
2787
+ annotation.data.extent.column = i;
2788
2788
  break;
2789
2789
  }
2790
2790
  }
@@ -2795,7 +2795,7 @@ export class Sheet {
2795
2795
  for (let i = 0; bottom >= 0 && i < sanity; i++) {
2796
2796
  bottom -= this.GetRowHeight(i); // FIXME: check // it's ok, rect is scaled to unit
2797
2797
  if (bottom < 0) {
2798
- annotation.extent.row = i;
2798
+ annotation.data.extent.row = i;
2799
2799
  break;
2800
2800
  }
2801
2801
  }
@@ -20,7 +20,7 @@
20
20
  */
21
21
 
22
22
  import type { IArea, SerializedCellData, Style } from 'treb-base-types';
23
- import type { Annotation } from './annotation';
23
+ import type { Annotation, AnnotationData } from './annotation';
24
24
  import type { GridSelection } from './grid_selection';
25
25
 
26
26
  export interface UpdateHints {
@@ -82,7 +82,7 @@ export interface SerializedSheet {
82
82
  name?: string;
83
83
 
84
84
  selection: GridSelection;
85
- annotations?: Partial<Annotation>[];
85
+ annotations?: Partial<AnnotationData>[]; // Partial<Annotation>[];
86
86
  scroll?: ScrollOffset;
87
87
 
88
88
  visible?: boolean;