@trebco/treb 28.17.4 → 29.1.2

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.
Files changed (87) hide show
  1. package/dist/treb-spreadsheet-light.mjs +12 -12
  2. package/dist/treb-spreadsheet.mjs +12 -12
  3. package/dist/treb.d.ts +121 -82
  4. package/eslint.config.js +21 -0
  5. package/package.json +6 -6
  6. package/treb-base-types/src/area.ts +4 -2
  7. package/treb-base-types/src/cell.ts +1 -1
  8. package/treb-base-types/src/cells.ts +16 -7
  9. package/treb-base-types/src/dom-utilities.ts +4 -2
  10. package/treb-base-types/src/import.ts +2 -2
  11. package/treb-base-types/src/rectangle.ts +5 -5
  12. package/treb-base-types/src/union.ts +6 -1
  13. package/treb-base-types/src/value-type.ts +1 -1
  14. package/treb-calculator/src/calculator.ts +114 -165
  15. package/treb-calculator/src/dag/calculation_leaf_vertex.ts +1 -2
  16. package/treb-calculator/src/dag/graph.ts +3 -3
  17. package/treb-calculator/src/dag/spreadsheet_vertex.ts +2 -2
  18. package/treb-calculator/src/dag/state_leaf_vertex.ts +2 -4
  19. package/treb-calculator/src/descriptors.ts +28 -2
  20. package/treb-calculator/src/expression-calculator.ts +25 -34
  21. package/treb-calculator/src/function-error.ts +2 -2
  22. package/treb-calculator/src/function-library.ts +16 -0
  23. package/treb-calculator/src/functions/base-functions.ts +185 -211
  24. package/treb-calculator/src/functions/checkbox.ts +0 -1
  25. package/treb-calculator/src/functions/complex-functions.ts +49 -47
  26. package/treb-calculator/src/functions/finance-functions.ts +10 -10
  27. package/treb-calculator/src/functions/function-utilities.ts +26 -0
  28. package/treb-calculator/src/functions/information-functions.ts +21 -41
  29. package/treb-calculator/src/functions/matrix-functions.ts +8 -1
  30. package/treb-calculator/src/functions/sparkline.ts +6 -4
  31. package/treb-calculator/src/functions/statistics-functions.ts +21 -17
  32. package/treb-calculator/src/functions/text-functions.ts +14 -13
  33. package/treb-calculator/src/primitives.ts +48 -37
  34. package/treb-calculator/src/utilities.ts +117 -134
  35. package/treb-charts/src/chart-functions.ts +3 -3
  36. package/treb-charts/src/chart-types.ts +42 -1
  37. package/treb-charts/src/chart-utils.ts +155 -113
  38. package/treb-charts/src/chart.ts +6 -5
  39. package/treb-charts/src/default-chart-renderer.ts +6 -5
  40. package/treb-charts/src/renderer.ts +12 -11
  41. package/treb-charts/src/util.ts +25 -36
  42. package/treb-data-model/package.json +5 -0
  43. package/{treb-grid/src/types → treb-data-model/src}/annotation.ts +2 -2
  44. package/{treb-grid/src/types → treb-data-model/src}/conditional_format.ts +20 -0
  45. package/{treb-grid/src/types → treb-data-model/src}/data_model.ts +231 -133
  46. package/treb-data-model/src/index.ts +45 -0
  47. package/{treb-grid/src/types/named_range.ts → treb-data-model/src/named.ts} +459 -376
  48. package/{treb-grid/src/types → treb-data-model/src}/sheet.ts +13 -5
  49. package/treb-data-model/src/sheet_collection.ts +114 -0
  50. package/{treb-grid/src/types → treb-data-model/src}/sheet_types.ts +6 -3
  51. package/treb-embed/modern.tsconfig.json +1 -0
  52. package/treb-embed/src/custom-element/spreadsheet-constructor.ts +2 -3
  53. package/treb-embed/src/embedded-spreadsheet.ts +125 -270
  54. package/treb-embed/src/selection-state.ts +1 -1
  55. package/treb-embed/src/toolbar-message.ts +1 -1
  56. package/treb-embed/src/types.ts +13 -5
  57. package/treb-export/src/export-worker/export-worker.ts +22 -7
  58. package/treb-export/src/export2.ts +110 -41
  59. package/treb-export/src/import2.ts +6 -5
  60. package/treb-export/src/workbook2.ts +31 -13
  61. package/treb-export/src/xml-utils.ts +5 -1
  62. package/treb-format/src/format.ts +8 -6
  63. package/treb-grid/src/editors/autocomplete.ts +2 -2
  64. package/treb-grid/src/editors/autocomplete_matcher.ts +57 -19
  65. package/treb-grid/src/editors/editor.ts +27 -25
  66. package/treb-grid/src/editors/formula_bar.ts +5 -5
  67. package/treb-grid/src/editors/overlay_editor.ts +1 -2
  68. package/treb-grid/src/index.ts +0 -11
  69. package/treb-grid/src/layout/base_layout.ts +20 -8
  70. package/treb-grid/src/layout/grid_layout.ts +2 -2
  71. package/treb-grid/src/layout/mock-layout.ts +5 -6
  72. package/treb-grid/src/render/selection-renderer.ts +2 -3
  73. package/treb-grid/src/render/tile_renderer.ts +1 -1
  74. package/treb-grid/src/types/grid.ts +95 -66
  75. package/treb-grid/src/types/grid_base.ts +76 -60
  76. package/treb-grid/src/types/grid_command.ts +3 -2
  77. package/treb-grid/src/types/grid_events.ts +12 -6
  78. package/treb-grid/src/types/tab_bar.ts +1 -2
  79. package/treb-parser/src/parser-types.ts +2 -1
  80. package/treb-parser/src/parser.ts +7 -5
  81. package/treb-utils/src/event_source.ts +1 -1
  82. package/treb-utils/src/serialize_html.ts +31 -6
  83. package/.eslintignore +0 -8
  84. package/.eslintrc.cjs +0 -168
  85. package/treb-grid/src/layout/rectangle_cache.ts +0 -86
  86. /package/{treb-grid/src/types → treb-data-model/src}/serialize_options.ts +0 -0
  87. /package/{treb-grid/src/types/grid_selection.ts → treb-data-model/src/sheet_selection.ts} +0 -0
@@ -39,8 +39,8 @@ import type { TextPart ,
39
39
 
40
40
  import type { FreezePane, SerializedSheet, ScrollOffset } from './sheet_types';
41
41
  import type { SerializeOptions } from './serialize_options';
42
- import type { GridSelection } from './grid_selection';
43
- import { CreateSelection } from './grid_selection';
42
+ import type { GridSelection } from './sheet_selection';
43
+ import { CreateSelection } from './sheet_selection';
44
44
  import { Annotation } from './annotation';
45
45
  import type { ConditionalFormatList } from './conditional_format';
46
46
 
@@ -2506,6 +2506,7 @@ export class Sheet {
2506
2506
  }
2507
2507
  }
2508
2508
 
2509
+ /*
2509
2510
  const translate_border_color = (color: string | undefined, default_color: string | undefined): string | undefined => {
2510
2511
  if (typeof color !== 'undefined' && color !== 'none') {
2511
2512
  if (color === default_color) {
@@ -2517,6 +2518,7 @@ export class Sheet {
2517
2518
  }
2518
2519
  return undefined;
2519
2520
  }
2521
+ */
2520
2522
 
2521
2523
  const translate_border_fill = (color: Color = {}, default_color: Color = {}) => {
2522
2524
  const result: Color = {
@@ -3070,6 +3072,12 @@ export class Sheet {
3070
3072
 
3071
3073
  for (const key of keys) {
3072
3074
  if (typeof column_style[key] !== 'undefined') {
3075
+
3076
+ // what's the correct pattern (if any) for this? these
3077
+ // are the same type so the type of the indexed value should
3078
+ // be equivalent... no? maybe there is no correct way
3079
+
3080
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3073
3081
  (overrides as any)[key] = properties[key];
3074
3082
  }
3075
3083
  }
@@ -3171,8 +3179,8 @@ export class Sheet {
3171
3179
 
3172
3180
  public BleedFlush(area: IArea) {
3173
3181
 
3174
- let rows = [Math.max(0, area.start.row - 1), area.end.row + 1];
3175
- let cols = [Math.max(0, area.start.column - 1), area.end.column + 1];
3182
+ const rows = [Math.max(0, area.start.row - 1), area.end.row + 1];
3183
+ const cols = [Math.max(0, area.start.column - 1), area.end.column + 1];
3176
3184
 
3177
3185
  for (let row = rows[0]; row <= rows[1]; row++) {
3178
3186
  for (let column = cols[0]; column <= cols[1]; column++) {
@@ -3323,7 +3331,7 @@ export class Sheet {
3323
3331
  }
3324
3332
  else {
3325
3333
  if (result.type === ValueType.boolean || result.type === ValueType.number) {
3326
- if(!!result.value) {
3334
+ if(result.value) {
3327
3335
  for (let row = area.start.row; row <= area.end.row; row++) {
3328
3336
  if (!temp[row]) { temp[row] = []; }
3329
3337
  for (let column = area.start.column; column <= area.end.column; column++) {
@@ -0,0 +1,114 @@
1
+
2
+ import type { Sheet } from './sheet';
3
+
4
+ /**
5
+ * we spend a lot of time looking up sheets by name, or id, or
6
+ * sometimes index. it makes sense to have a class that can
7
+ * support all of these, ideally without looping.
8
+ *
9
+ * we just have to make sure that no one is assigning to the
10
+ * array, or we'll lose track.
11
+ *
12
+ * also there are some operations -- rename, in particular -- that
13
+ * require updating indexes.
14
+ *
15
+ *
16
+ * FIXME: new file (1 class per file)
17
+ */
18
+ export class SheetCollection {
19
+
20
+ /**
21
+ * returns a read-only copy of the list. useful for indexing or
22
+ * functional-style calls. it's not actually read-only, but it's a
23
+ * copy, so changes will be ignored.
24
+ */
25
+ public get list() {
26
+ return this.sheets_.slice(0);
27
+ }
28
+
29
+ /**
30
+ * length of list
31
+ */
32
+ public get length() {
33
+ return this.sheets_.length;
34
+ }
35
+
36
+ /** map of (normalized) name -> sheet */
37
+ protected names: Map<string, Sheet> = new Map();
38
+
39
+ /** map of id -> sheet */
40
+ protected ids: Map<number, Sheet> = new Map();
41
+
42
+ /** the actual list */
43
+ private sheets_: Sheet[] = [];
44
+
45
+ /**
46
+ * remove any existing sheets and add the passed list. updates indexes.
47
+ */
48
+ public Assign(sheets: Sheet[]) {
49
+ this.sheets_ = [...sheets];
50
+ this.UpdateIndexes();
51
+ }
52
+
53
+ /**
54
+ * add a new sheet to the end of the list (push). updates indexes.
55
+ */
56
+ public Add(sheet: Sheet) {
57
+ this.sheets_.push(sheet);
58
+ this.UpdateIndexes();
59
+ }
60
+
61
+ /**
62
+ * wrapper for array splice. updates indexes.
63
+ */
64
+ public Splice(insert_index: number, delete_count: number, ...items: Sheet[]) {
65
+ this.sheets_.splice(insert_index, delete_count, ...items);
66
+ this.UpdateIndexes();
67
+ }
68
+
69
+ /**
70
+ * so our new strategy is to add lookup methods first -- then
71
+ * we can fix the underlying storage implementation.
72
+ *
73
+ * NOTE we normalize strings here so you do not need to do it (don't)
74
+ */
75
+ public Find(id: string|number): Sheet|undefined {
76
+
77
+ // console.info('get', typeof id);
78
+
79
+ if (typeof id === 'string') {
80
+ return this.names.get(id.toLocaleUpperCase());
81
+ }
82
+ else {
83
+ return this.ids.get(id);
84
+ }
85
+
86
+ return undefined;
87
+ }
88
+
89
+ /** get name for sheet with given id */
90
+ public Name(id: number): string|undefined {
91
+ return this.ids.get(id)?.name || undefined;
92
+ }
93
+
94
+ /** get ID for sheet with given name */
95
+ public ID(name: string): number|undefined {
96
+ return this.names.get(name.toLocaleUpperCase())?.id || undefined;
97
+ }
98
+
99
+ /** not sure why this is private, makes it a little more complicated */
100
+ public UpdateIndexes(): void {
101
+
102
+ this.names.clear();
103
+ this.ids.clear();
104
+
105
+ for (const sheet of this.sheets_) {
106
+ const uc = sheet.name.toLocaleUpperCase();
107
+ this.names.set(uc, sheet);
108
+ this.ids.set(sheet.id, sheet);
109
+ }
110
+
111
+ }
112
+
113
+
114
+ }
@@ -19,9 +19,9 @@
19
19
  *
20
20
  */
21
21
 
22
- import type { IArea, SerializedCellData, Style, CellStyle } from 'treb-base-types';
23
- import type { Annotation, AnnotationData } from './annotation';
24
- import type { GridSelection, SerializedGridSelection } from './grid_selection';
22
+ import type { IArea, SerializedCellData, CellStyle } from 'treb-base-types';
23
+ import type { AnnotationData } from './annotation';
24
+ import type { GridSelection, SerializedGridSelection } from './sheet_selection';
25
25
  import type { ConditionalFormatList } from './conditional_format';
26
26
 
27
27
  export interface UpdateHints {
@@ -142,5 +142,8 @@ export interface SerializedSheet {
142
142
  /**
143
143
  * support for legacy sheet data
144
144
  * (I think we can drop)
145
+ *
146
+ * @internal
147
+ * @deprecated
145
148
  */
146
149
  export type LegacySerializedSheet = SerializedSheet & { primary_selection?: GridSelection }
@@ -6,6 +6,7 @@
6
6
  "../treb-utils/**/*.ts",
7
7
  "../treb-grid/**/*.ts",
8
8
  "../treb-charts/**/*.ts",
9
+ "../treb-data-model/**/*.ts",
9
10
  "../treb-export/**/*.ts",
10
11
  "../treb-format/**/*.ts",
11
12
  "../treb-parser/**/*.ts",
@@ -146,9 +146,8 @@ export class SpreadsheetConstructor<USER_DATA_TYPE = unknown> {
146
146
  if (this.root) {
147
147
 
148
148
  const names = this.root.getAttributeNames();
149
- console.info({names});
150
149
 
151
- for (let name of names) {
150
+ for (const name of names) {
152
151
 
153
152
  switch (name) {
154
153
 
@@ -612,7 +611,7 @@ export class SpreadsheetConstructor<USER_DATA_TYPE = unknown> {
612
611
 
613
612
  comment_box.value = '';
614
613
 
615
- for (const [key, value] of Object.entries(this.toolbar_controls)) {
614
+ for (const value of Object.values(this.toolbar_controls)) {
616
615
  if (value) {
617
616
  // value.classList.remove('treb-active');
618
617
  value.removeAttribute('active');