@trebco/treb 25.7.5 → 25.8.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.
package/dist/treb.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /*! API v25.7. Copyright 2018-2023 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
1
+ /*! API v25.8. Copyright 2018-2023 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
2
 
3
3
  /**
4
4
  * add our tag to the map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "25.7.5",
3
+ "version": "25.8.0",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -66,6 +66,9 @@ export interface ImportedSheetData {
66
66
  // new
67
67
  annotations?: AnchoredAnnotation[];
68
68
 
69
+ // new
70
+ outline?: number[];
71
+
69
72
  hidden?: boolean;
70
73
 
71
74
  }
@@ -228,6 +228,9 @@ export class EmbeddedSpreadsheet {
228
228
  /** @internal */
229
229
  public static enable_formatter = false;
230
230
 
231
+ /** @internal */
232
+ public static one_time_warnings: Record<string, boolean> = {};
233
+
231
234
  /**
232
235
  * this flag will be set on LoadDocument. the intent is to be able to
233
236
  * know if you have loaded a network document, which may happen before you
@@ -650,7 +653,11 @@ export class EmbeddedSpreadsheet {
650
653
  //this.extra_calculator = //new Calculator(this.model);
651
654
  // this.CreateCalculator(this.model);
652
655
 
653
- this.grid = new Grid(grid_options, this.parser, this.model);
656
+ // update: tell the grid if we don't want to initialize the DOM,
657
+ // if we don't have a container. that's distinct (at the moment)
658
+ // from headless, which is a state that can change.
659
+
660
+ this.grid = new Grid(grid_options, this.parser, this.model, undefined, !!container);
654
661
 
655
662
  if (this.options.headless) {
656
663
  this.grid.headless = true; // FIXME: move into grid options
@@ -865,8 +872,11 @@ export class EmbeddedSpreadsheet {
865
872
 
866
873
  }
867
874
  else {
868
- console.info('not initializing grid; don\'t call UI functions');
869
- this.grid.headless = true; // ensure
875
+ if (!EmbeddedSpreadsheet.one_time_warnings.headless) {
876
+ EmbeddedSpreadsheet.one_time_warnings.headless = true;
877
+ console.info('not initializing layout; don\'t call UI functions');
878
+ }
879
+ // this.grid.headless = true; // ensure
870
880
  }
871
881
 
872
882
  // moved up so we can share parser w/ grid
@@ -478,6 +478,7 @@ export class Importer {
478
478
  // data (and row heights)
479
479
 
480
480
  const row_heights: number[] = [];
481
+ const outline: number[] = [];
481
482
 
482
483
  const rows = FindAll('worksheet/sheetData/row');
483
484
 
@@ -491,6 +492,12 @@ export class Importer {
491
492
  height = Math.round(num * 4 / 3); // seems to be the excel unit -> pixel ratio
492
493
  }
493
494
  }
495
+ if (row.a$?.outlineLevel) {
496
+ const num = Number(row.a$.outlineLevel);
497
+ if (!isNaN(num)) {
498
+ outline[row_index - 1] = num;
499
+ }
500
+ }
494
501
 
495
502
  // if there's a height which is not === default height, but
496
503
  // the customHeight attribute is not set, then it's been auto-sized.
@@ -867,6 +874,10 @@ export class Importer {
867
874
  styles: this.workbook?.style_cache?.CellXfToStyles() || [],
868
875
  };
869
876
 
877
+ if (outline.length) {
878
+ result.outline = outline;
879
+ }
880
+
870
881
  if (sheet.visible_state === VisibleState.hidden || sheet.visible_state === VisibleState.very_hidden) {
871
882
  result.hidden = true;
872
883
  }
@@ -151,7 +151,7 @@ export abstract class BaseLayout {
151
151
  this.scroll_reference_node.scrollTop = offset.y;
152
152
  }
153
153
 
154
- protected dropdown_caret: SVGSVGElement;
154
+ protected dropdown_caret!: SVGSVGElement;
155
155
 
156
156
  /** we have to disable mock selection for IE or it breaks key handling */
157
157
  private trident = ((typeof navigator !== 'undefined') &&
@@ -162,9 +162,9 @@ export abstract class BaseLayout {
162
162
 
163
163
  private tooltip_state?: 'up' | 'left';
164
164
 
165
- private tooltip: HTMLDivElement;
165
+ private tooltip!: HTMLDivElement;
166
166
 
167
- private dropdown_list: HTMLDivElement;
167
+ private dropdown_list!: HTMLDivElement;
168
168
  private dropdown_caret_visible = false;
169
169
  private dropdown_callback?: (value: CellValue) => void;
170
170
  private dropdown_selected?: HTMLElement;
@@ -174,10 +174,9 @@ export abstract class BaseLayout {
174
174
  // private error_highlight: HTMLDivElement;
175
175
  // private error_highlight_timeout?: any;
176
176
 
177
- private note_node: HTMLDivElement;
178
- private sort_button: HTMLButtonElement;
179
-
180
- private title_node: HTMLDivElement;
177
+ private note_node!: HTMLDivElement;
178
+ private sort_button!: HTMLButtonElement;
179
+ private title_node!: HTMLDivElement;
181
180
 
182
181
  private row_cache: number[] = [];
183
182
  private column_cache: number[] = [];
@@ -188,7 +187,11 @@ export abstract class BaseLayout {
188
187
  private initialized = false;
189
188
 
190
189
 
191
- constructor(protected model: DataModel, protected view: ViewModel) {
190
+ constructor(protected model: DataModel, protected view: ViewModel, mock = false) {
191
+
192
+ if (mock) {
193
+ return;
194
+ }
192
195
 
193
196
  // now attaching to node... no longer global
194
197
  // actually if we are not in a web component, we might as well
@@ -0,0 +1,33 @@
1
+
2
+ import type { DataModel, ViewModel } from '../types/data_model';
3
+ import type { Tile } from '../types/tile';
4
+ import { BaseLayout } from './base_layout';
5
+
6
+ export class MockLayout extends BaseLayout {
7
+
8
+ public constructor(model: DataModel, view: ViewModel) {
9
+ super(model, view, true);
10
+ }
11
+
12
+ public InitializeInternal(container: HTMLElement, scroll_callback: () => void): void {
13
+
14
+ }
15
+
16
+ protected UpdateGridTemplates(columns: boolean, rows: boolean): void {
17
+
18
+ }
19
+
20
+ protected UpdateTileGridPosition(tile: Tile): void {
21
+
22
+ }
23
+
24
+ protected UpdateContainingGrid(): void {
25
+
26
+ }
27
+
28
+ public ResizeCursor(resize?: 'row' | 'column' | undefined): void {
29
+
30
+ }
31
+
32
+ }
33
+
@@ -81,7 +81,13 @@ export interface ViewData {
81
81
 
82
82
  export interface ImageAnnotationData {
83
83
  src: string;
84
- scale: string;
84
+
85
+ /**
86
+ * @privateRemarks
87
+ * why is this a string?
88
+ */
89
+ scale: string;
90
+
85
91
  original_size: {
86
92
  width: number;
87
93
  height: number;
@@ -65,6 +65,7 @@ import { TabBar } from './tab_bar';
65
65
  import type { StatsEntry } from './tab_bar';
66
66
 
67
67
  import { Sheet } from './sheet';
68
+ import { MockLayout } from '../layout/mock-layout';
68
69
  import type { BaseLayout } from '../layout/base_layout';
69
70
  import { TileRange } from '../layout/base_layout';
70
71
 
@@ -328,10 +329,10 @@ export class Grid extends GridBase {
328
329
  private render_token = 0;
329
330
 
330
331
  /** */
331
- private tile_renderer: TileRenderer;
332
+ private tile_renderer?: TileRenderer;
332
333
 
333
334
  /** */
334
- private selection_renderer: SelectionRenderer;
335
+ private selection_renderer?: SelectionRenderer;
335
336
 
336
337
  // FIXME: move [why?]
337
338
 
@@ -346,7 +347,8 @@ export class Grid extends GridBase {
346
347
  options: GridOptions = {},
347
348
  parser: Parser,
348
349
  model: DataModel,
349
- theme: Theme = DefaultTheme) {
350
+ theme: Theme = DefaultTheme,
351
+ initialze_dom = true ) {
350
352
 
351
353
  super(options, parser, model);
352
354
 
@@ -356,6 +358,12 @@ export class Grid extends GridBase {
356
358
 
357
359
  this.theme = JSON.parse(JSON.stringify(theme));
358
360
 
361
+ if (!initialze_dom) {
362
+ this.headless = true;
363
+ this.layout = new MockLayout(this.model, this.view);
364
+ return;
365
+ }
366
+
359
367
  this.layout = new GridLayout(this.model, this.view);
360
368
 
361
369
  if (options.initial_scale) {
@@ -1226,6 +1234,10 @@ export class Grid extends GridBase {
1226
1234
  */
1227
1235
  public Initialize(view_node: HTMLElement, toll_initial_render = false): void {
1228
1236
 
1237
+ if (!this.tile_renderer || !this.selection_renderer) {
1238
+ return;
1239
+ }
1240
+
1229
1241
  // grid no longer has access to the outer container, it just has
1230
1242
  // the "view" container. so we need to move things like UA classes
1231
1243
  // outside of this class. we should move theme parsing as well, so
@@ -2054,7 +2066,6 @@ export class Grid extends GridBase {
2054
2066
  }
2055
2067
 
2056
2068
  protected RenameSheetInternal(target: Sheet, name: string) {
2057
- console.info("RIS");
2058
2069
  super.RenameSheetInternal(target, name);
2059
2070
  this.tab_bar?.Update();
2060
2071
 
@@ -2126,6 +2137,10 @@ export class Grid extends GridBase {
2126
2137
 
2127
2138
  private AutoSizeColumn(sheet: Sheet, column: number, allow_shrink = true): void {
2128
2139
 
2140
+ if (!this.tile_renderer) {
2141
+ return;
2142
+ }
2143
+
2129
2144
  // const context = Sheet.measurement_canvas.getContext('2d');
2130
2145
  // if (!context) return;
2131
2146
 
@@ -2730,7 +2745,7 @@ export class Grid extends GridBase {
2730
2745
 
2731
2746
  private Repaint(force = false, full_tile = false, force_headers = false) {
2732
2747
 
2733
- if (this.headless) { return; }
2748
+ if (this.headless || !this.tile_renderer) { return; }
2734
2749
 
2735
2750
  if (this.tile_update_pending) {
2736
2751
  this.tile_update_pending = false;
@@ -3498,6 +3513,10 @@ export class Grid extends GridBase {
3498
3513
  event.stopPropagation();
3499
3514
  event.preventDefault();
3500
3515
 
3516
+ if (!this.selection_renderer) {
3517
+ return;
3518
+ }
3519
+
3501
3520
  // needed for legacy
3502
3521
 
3503
3522
  if (this.cell_resize.row >= 0 || this.cell_resize.column >= 0) {
@@ -4617,7 +4636,7 @@ export class Grid extends GridBase {
4617
4636
  const show_primary_selection = this.hide_selection ? false :
4618
4637
  (!this.editing_state) || (this.editing_cell.sheet_id === this.active_sheet.id);
4619
4638
 
4620
- this.selection_renderer.RenderSelections(show_primary_selection, rerender);
4639
+ this.selection_renderer?.RenderSelections(show_primary_selection, rerender);
4621
4640
  }
4622
4641
 
4623
4642
  /**
@@ -6877,7 +6896,7 @@ export class Grid extends GridBase {
6877
6896
  // columns. we should be able to fix this, or we can just flush
6878
6897
  // all overflows and force them to get recreated.
6879
6898
 
6880
- this.tile_renderer.FlushOverflows();
6899
+ this.tile_renderer?.FlushOverflows();
6881
6900
 
6882
6901
  // note event is sent in exec command, not implicit here
6883
6902
 
@@ -148,6 +148,13 @@ export class Sheet {
148
148
  return this._image;
149
149
  }
150
150
 
151
+ /**
152
+ * @internal
153
+ *
154
+ * testing, not serialized atm
155
+ */
156
+ public outline: number[] | undefined;
157
+
151
158
  /** internal ID */
152
159
  // tslint:disable-next-line: variable-name
153
160
  private id_: number;
@@ -2686,6 +2693,10 @@ export class Sheet {
2686
2693
 
2687
2694
  const styles = data.styles;
2688
2695
 
2696
+ if (data.outline) {
2697
+ this.outline = data.outline;
2698
+ }
2699
+
2689
2700
  // adding sheet style...
2690
2701
 
2691
2702
  // 0 is implicitly just a general style