@trebco/treb 25.5.0 → 25.6.1

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.5. Copyright 2018-2023 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
1
+ /*! API v25.6. 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
@@ -367,7 +367,7 @@ export declare class EmbeddedSpreadsheet {
367
367
  * @param argument_separator - the argument separator to use when evaluating
368
368
  * the function. defaults to current locale.
369
369
  */
370
- InsertAnnotation(formula: string, type?: string, rect?: IRectangle | RangeReference, argument_separator?: ',' | ';'): void;
370
+ InsertAnnotation(formula: string, type?: AnnotationType, rect?: IRectangle | RangeReference, argument_separator?: ',' | ';'): void;
371
371
 
372
372
  /**
373
373
  * Insert an image. This method will open a file chooser and (if an image
@@ -952,6 +952,7 @@ export interface FreezePane {
952
952
  rows: number;
953
953
  columns: number;
954
954
  }
955
+ export type AnnotationType = 'treb-chart' | 'image' | 'external';
955
956
  export declare type BorderConstants = "none" | "all" | "outside" | "top" | "bottom" | "left" | "right";
956
957
 
957
958
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "25.5.0",
3
+ "version": "25.6.1",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -1,30 +1,31 @@
1
- /*
2
- * This file is part of TREB.
3
- *
4
- * TREB is free software: you can redistribute it and/or modify it under the
5
- * terms of the GNU General Public License as published by the Free Software
6
- * Foundation, either version 3 of the License, or (at your option) any
7
- * later version.
8
- *
9
- * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
- * details.
13
- *
14
- * You should have received a copy of the GNU General Public License along
15
- * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
- *
17
- * Copyright 2022-2023 trebco, llc.
18
- * info@treb.app
19
- *
20
- */
21
-
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2023 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+
22
22
  import type { Style } from './style';
23
23
  import type { ValueType } from './value-type';
24
24
  import type { IArea } from './area';
25
25
  import type { AnnotationLayout } from './layout';
26
26
  import type { DataValidation } from './cell';
27
27
  import type { Table } from './table';
28
+ import type { AnnotationType } from 'treb-grid';
28
29
 
29
30
  export interface CellParseResult {
30
31
  row: number,
@@ -43,7 +44,7 @@ export interface CellParseResult {
43
44
 
44
45
  export interface AnchoredAnnotation {
45
46
  layout: AnnotationLayout;
46
- type?: string;
47
+ type?: AnnotationType;
47
48
  formula?: string;
48
49
  }
49
50
 
@@ -63,10 +63,6 @@ export interface Table {
63
63
  */
64
64
  name: string;
65
65
 
66
- /**
67
- * column names. these are the same (icase) as text in the first row
68
- */
69
-
70
66
  /** table area */
71
67
  area: IArea;
72
68
 
@@ -1774,13 +1774,13 @@ export class Calculator extends Graph {
1774
1774
  }
1775
1775
 
1776
1776
  for (const entry of list) {
1777
- if (entry.formula) {
1777
+ if (entry.data.formula) {
1778
1778
  if (!entry.temp.vertex) {
1779
1779
  entry.temp.vertex = new LeafVertex();
1780
1780
  }
1781
1781
  const vertex = entry.temp.vertex as LeafVertex;
1782
1782
  this.AddLeafVertex(vertex);
1783
- this.UpdateLeafVertex(vertex, entry.formula, context);
1783
+ this.UpdateLeafVertex(vertex, entry.data.formula, context);
1784
1784
  }
1785
1785
  }
1786
1786
 
@@ -29,7 +29,8 @@ import type {
29
29
  SerializedModel, FreezePane, SerializedSheet,
30
30
  SheetChangeEvent, GridOptions,
31
31
  GridSelection, CellEvent, FunctionDescriptor,
32
- AnnotationViewData,
32
+ AnnotationViewData,
33
+ AnnotationType,
33
34
  } from 'treb-grid';
34
35
 
35
36
  import {
@@ -1891,7 +1892,7 @@ export class EmbeddedSpreadsheet {
1891
1892
  * @param argument_separator - the argument separator to use when evaluating
1892
1893
  * the function. defaults to current locale.
1893
1894
  */
1894
- public InsertAnnotation(formula: string, type = 'treb-chart', rect?: IRectangle|RangeReference, argument_separator?: ','|';'): void {
1895
+ public InsertAnnotation(formula: string, type: AnnotationType = 'treb-chart', rect?: IRectangle|RangeReference, argument_separator?: ','|';'): void {
1895
1896
 
1896
1897
  let target: IRectangle | Partial<Area> | undefined;
1897
1898
 
@@ -3171,7 +3172,7 @@ export class EmbeddedSpreadsheet {
3171
3172
  }
3172
3173
 
3173
3174
  for (const annotation of sheet.annotations || []) {
3174
- if (annotation.type === 'image' && annotation.data.src) {
3175
+ if (annotation.type === 'image' && annotation.data?.src) {
3175
3176
  annotation.data.src = Store(annotation.data.src);
3176
3177
  }
3177
3178
  }
@@ -4350,15 +4351,20 @@ export class EmbeddedSpreadsheet {
4350
4351
  const annotation = this.grid.CreateAnnotation({
4351
4352
  type: 'image',
4352
4353
  formula: '',
4354
+ data: {
4355
+ scale: '',
4356
+ src: contents,
4357
+ original_size: { width: img.width || 300, height: img.height || 300 },
4358
+ },
4353
4359
  }, undefined, undefined, {
4354
4360
  top: 30,
4355
4361
  left: 30,
4356
4362
  width: img.width || 300,
4357
- height: img.height || 300
4363
+ height: img.height || 300,
4358
4364
  });
4359
4365
 
4360
- annotation.data.src = contents;
4361
- annotation.data.original_size = { width: img.width || 300, height: img.height || 300 };
4366
+ // annotation.data.src = contents;
4367
+ // annotation.data.original_size = { width: img.width || 300, height: img.height || 300 };
4362
4368
 
4363
4369
  }
4364
4370
 
@@ -4613,9 +4619,12 @@ export class EmbeddedSpreadsheet {
4613
4619
  annotation.dirty = false;
4614
4620
  }
4615
4621
 
4616
- if (view.content_node && annotation.data) {
4622
+ // why was this testing for data? that would always exist on an annotation
4623
+ // instance (but not in our new data type). maybe some legacy thing?
4617
4624
 
4618
- if (annotation.type === 'treb-chart') {
4625
+ if (view.content_node ) { // && annotation.annotation_data.data) {
4626
+
4627
+ if (annotation.data.type === 'treb-chart') {
4619
4628
 
4620
4629
  // if (!(self as any).TREB || !(self as any).TREB.CreateChart2) {
4621
4630
  // console.warn('missing chart library');
@@ -4633,8 +4642,8 @@ export class EmbeddedSpreadsheet {
4633
4642
 
4634
4643
  const update_chart = () => {
4635
4644
 
4636
- if (annotation.formula) {
4637
- const parse_result = this.parser.Parse(annotation.formula);
4645
+ if (annotation.data.formula) {
4646
+ const parse_result = this.parser.Parse(annotation.data.formula);
4638
4647
  if (parse_result &&
4639
4648
  parse_result.expression &&
4640
4649
  parse_result.expression.type === 'call') {
@@ -4686,16 +4695,16 @@ export class EmbeddedSpreadsheet {
4686
4695
  }
4687
4696
 
4688
4697
  }
4689
- else if (annotation.type === 'image') {
4690
- if (typeof annotation.data.src === 'string') {
4698
+ else if (annotation.data.type === 'image') {
4699
+ if (typeof annotation.data.data?.src === 'string') {
4691
4700
 
4692
- const reference = ValidateURI(annotation.data.src);
4701
+ const reference = ValidateURI(annotation.data.data.src);
4693
4702
  if (reference) {
4694
4703
 
4695
4704
  const img = document.createElement('img');
4696
4705
  img.src = reference;
4697
4706
 
4698
- if (annotation.data.scale === 'fixed') {
4707
+ if (annotation.data.data.scale === 'fixed') {
4699
4708
  img.style.position = 'relative';
4700
4709
  img.style.left = '50%';
4701
4710
  img.style.top = '50%';
@@ -5044,7 +5053,7 @@ export class EmbeddedSpreadsheet {
5044
5053
  for (const sheet_data of sheets) {
5045
5054
 
5046
5055
  if (sheet_data.annotations) {
5047
- for (const annotation of (sheet_data.annotations as Annotation[])) {
5056
+ for (const annotation of (sheet_data.annotations)) {
5048
5057
  if (annotation.formula) {
5049
5058
  const translated = translate(annotation.formula);
5050
5059
  if (translated) {
@@ -5161,7 +5170,7 @@ export class EmbeddedSpreadsheet {
5161
5170
  sheet.background_image = Unshare(sheet.background_image);
5162
5171
  }
5163
5172
  for (const annotation of sheet.annotations || []) {
5164
- if (annotation.type === 'image' && annotation.data.src) {
5173
+ if (annotation.type === 'image' && annotation.data?.src) {
5165
5174
  annotation.data.src = Unshare(annotation.data.src);
5166
5175
  }
5167
5176
  }
@@ -53,7 +53,7 @@
53
53
  // more specific about what we unset in order to avoid any
54
54
  // unexpected side effects.
55
55
 
56
- // all: revert;
56
+ all: revert;
57
57
  box-sizing: border-box;
58
58
 
59
59
  }
@@ -286,7 +286,7 @@
286
286
 
287
287
  .treb-layout-sidebar > button, .treb-toggle-sidebar-button {
288
288
 
289
- all: initial;
289
+ // all: initial;
290
290
  padding: 0;
291
291
  margin: 0;
292
292
  border: 0;
@@ -376,7 +376,7 @@
376
376
  // OK, but then we can't scope properly. so no.
377
377
 
378
378
  .treb-resize-rect {
379
- all: initial;
379
+ // all: initial;
380
380
  z-index: 9998; // ugh
381
381
  position: fixed;
382
382
  top: 0px;
@@ -388,7 +388,7 @@
388
388
  }
389
389
 
390
390
  .treb-resize-mask {
391
- all: initial;
391
+ // all: initial;
392
392
  z-index: 9999; // ugh
393
393
  position: fixed;
394
394
  top: 0px;
@@ -35,7 +35,7 @@ import { template } from './template-2';
35
35
  import type { SerializedSheet } from 'treb-grid';
36
36
 
37
37
  import type { IArea, ICellAddress, CellValue, DataValidation,
38
- AnnotationLayout, Corner as LayoutCorner, Cell } from 'treb-base-types';
38
+ AnnotationLayout, Corner as LayoutCorner, Cell, Rectangle } from 'treb-base-types';
39
39
  import { Area, Cells, ValueType, Style, ValidationType } from 'treb-base-types';
40
40
 
41
41
  // import * as xmlparser from 'fast-xml-parser';
@@ -61,6 +61,7 @@ import type { ImageOptions } from './drawing2/embedded-image';
61
61
  import type { TwoCellAnchor } from './drawing2/drawing2';
62
62
  import { Drawing } from './drawing2/drawing2';
63
63
  import type { TableDescription, TableFooterType } from './workbook2';
64
+ import type { AnnotationData } from 'treb-grid/src/types/annotation';
64
65
 
65
66
  export class Exporter {
66
67
 
@@ -651,12 +652,7 @@ export class Exporter {
651
652
  * the target units are.
652
653
  */
653
654
  public AnnotationRectToAnchor(
654
- annotation_rect: {
655
- left: number;
656
- top: number;
657
- width: number;
658
- height: number;
659
- },
655
+ src_rect: Partial<Rectangle>,
660
656
  sheet: SerializedSheet): TwoCellAnchor {
661
657
 
662
658
  const anchor: TwoCellAnchor = {
@@ -664,6 +660,11 @@ export class Exporter {
664
660
  to: {row: -1, column: -1},
665
661
  };
666
662
 
663
+ const annotation_rect = {
664
+ top: 0, left: 0, width: 301, height: 301,
665
+ ...src_rect,
666
+ };
667
+
667
668
  const rect = {
668
669
  ...annotation_rect, // {top, left, width, height}
669
670
  right: annotation_rect.left + annotation_rect.width,
@@ -706,7 +707,7 @@ export class Exporter {
706
707
 
707
708
  const images: Array<{ anchor: TwoCellAnchor, options: ImageOptions }> = [];
708
709
 
709
- for (const annotation of sheet_source.annotations || []) {
710
+ for (const annotation of (sheet_source.annotations as Array<AnnotationData & {rect?: Partial<Rectangle>}>) || []) {
710
711
  if (annotation.type === 'image' && annotation.data?.src) {
711
712
 
712
713
  // this is (should be) a data URI in base64. at least (atm)
@@ -940,9 +941,14 @@ export class Exporter {
940
941
  }
941
942
  }
942
943
 
943
- if (annotation.rect) {
944
+ // FIXME: fix this type (this happened when we switched from annotation
945
+ // class to a data interface)
946
+
947
+ const rect = (annotation as AnnotationData & { rect?: Partial<Rectangle>}).rect;
948
+
949
+ if (rect) {
944
950
  charts.push({
945
- anchor: this.AnnotationRectToAnchor(annotation.rect, sheet_source), options});
951
+ anchor: this.AnnotationRectToAnchor(rect, sheet_source), options});
946
952
  // sheet.AddChart(this.AnnotationRectToAnchor(annotation.rect, sheet_source), options);
947
953
  }
948
954
  else if (annotation.layout) {
@@ -37,6 +37,7 @@ import { XMLUtils } from './xml-utils';
37
37
 
38
38
  // import { one_hundred_pixels } from './constants';
39
39
  import { ColumnWidthToPixels } from './column-width';
40
+ import type { AnnotationType } from 'treb-grid';
40
41
 
41
42
  interface SharedFormula {
42
43
  row: number;
@@ -697,7 +698,7 @@ export class Importer {
697
698
  br: AnchorToCorner(descriptor.anchor.to),
698
699
  };
699
700
 
700
- let type: string|undefined;
701
+ let type: AnnotationType|undefined;
701
702
  const args: Array<string|undefined> = [];
702
703
  let func = '';
703
704
  const series = descriptor.chart?.series;
@@ -37,4 +37,5 @@ export { BorderConstants } from './types/border_constants';
37
37
  export type { SerializeOptions } from './types/serialize_options';
38
38
  export type { FunctionDescriptor, ArgumentDescriptor } from './editors/autocomplete_matcher';
39
39
  export { UA } from './util/ua';
40
- export type { SetRangeOptions } from './types/set_range_options';
40
+ export type { SetRangeOptions } from './types/set_range_options';
41
+ export type { AnnotationData, AnnotationType } from './types/annotation';
@@ -672,21 +672,21 @@ export abstract class BaseLayout {
672
672
  // be persisted (assuming it's saved). eventually this should
673
673
  // be superfluous...
674
674
 
675
- if (annotation.rect && !annotation.layout) {
675
+ if (annotation.rect && !annotation.data.layout) {
676
676
 
677
677
  // this is breaking on freeze when the spreadsheet is scrolled because
678
678
  // the top-left uses the freeze panes. stop doing that.
679
679
 
680
680
  annotation.scaled_rect = annotation.rect.Scale(this.scale);
681
- annotation.layout = this.RectToAnnotationLayout(annotation.scaled_rect);
681
+ annotation.data.layout = this.RectToAnnotationLayout(annotation.scaled_rect);
682
682
  }
683
683
 
684
684
 
685
685
  // FIXME: merge cells? [...]
686
686
 
687
- if (annotation.layout) {
687
+ if (annotation.data.layout) {
688
688
 
689
- const rect = this.AnnotationLayoutToRect(annotation.layout);
689
+ const rect = this.AnnotationLayoutToRect(annotation.data.layout);
690
690
  rect.ApplyStyle(view.node);
691
691
 
692
692
  // NOTE: we still set the scaled rect, because that's used in
@@ -949,9 +949,9 @@ export abstract class BaseLayout {
949
949
  }
950
950
 
951
951
  }, () => {
952
- annotation.extent = undefined; // reset
952
+ annotation.data.extent = undefined; // reset
953
953
  // annotation.rect = rect.Scale(1/this.scale);
954
- annotation.layout = this.RectToAnnotationLayout(rect);
954
+ annotation.data.layout = this.RectToAnnotationLayout(rect);
955
955
  // this.grid_events.Publish({ type: 'annotation', annotation, event: 'move' });
956
956
  resolve({ type: 'annotation', annotation, event: 'move' })
957
957
  });
@@ -969,11 +969,14 @@ export abstract class BaseLayout {
969
969
  node.focus();
970
970
 
971
971
  let aspect = 0;
972
- if (annotation.data?.original_size
973
- && annotation.data.original_size.width
974
- && annotation.data.original_size.height) {
975
- aspect = annotation.data.original_size.width /
976
- annotation.data.original_size.height;
972
+ if (annotation.data.type === 'image') {
973
+ if (annotation.data.data
974
+ && annotation.data.data.original_size
975
+ && annotation.data.data.original_size.width
976
+ && annotation.data.data.original_size.height) {
977
+ aspect = annotation.data.data.original_size.width /
978
+ annotation.data.data.original_size.height;
979
+ }
977
980
  }
978
981
 
979
982
  const bounds = node.getBoundingClientRect();
@@ -1029,9 +1032,9 @@ export abstract class BaseLayout {
1029
1032
  }
1030
1033
 
1031
1034
  }, () => {
1032
- annotation.extent = undefined; // reset
1035
+ annotation.data.extent = undefined; // reset
1033
1036
  // annotation.rect = rect.Scale(1/this.scale);
1034
- annotation.layout = this.RectToAnnotationLayout(rect);
1037
+ annotation.data.layout = this.RectToAnnotationLayout(rect);
1035
1038
 
1036
1039
  // this.grid_events.Publish({ type: 'annotation', annotation, event: 'resize' });
1037
1040
  resolve({ type: 'annotation', annotation, event: 'resize' });