@trebco/treb 28.17.5 → 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 -2
  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
@@ -19,9 +19,8 @@
19
19
  *
20
20
  */
21
21
 
22
- import type { DataModel, ViewModel } from './data_model';
22
+ import type { DataModel, ViewModel, Sheet } from 'treb-data-model';
23
23
  import { EventSource } from 'treb-utils';
24
- import type { Sheet } from './sheet';
25
24
  import type { BaseLayout } from '../layout/base_layout';
26
25
  import { MouseDrag } from './drag_mask';
27
26
  import type { GridOptions } from './grid_options';
@@ -95,7 +95,8 @@ export interface UnitImaginary extends BaseUnit {
95
95
  /**
96
96
  * expression unit representing an array of primitive values. array
97
97
  * can contain mixed values, and holes. array cannot contain arrays,
98
- * or any other complex type.
98
+ * or any other complex type (including complex, apparently. we should
99
+ * remedy that).
99
100
  */
100
101
  export interface UnitArray extends BaseUnit {
101
102
  type: 'array';
@@ -104,7 +104,7 @@ const UC_Z = 0x5a;
104
104
  const LC_Z = 0x7a;
105
105
 
106
106
  const LC_I = 0x69;
107
- const LC_J = 0x6a;
107
+ // const LC_J = 0x6a;
108
108
 
109
109
  const ACCENTED_RANGE_START = 192;
110
110
  const ACCENTED_RANGE_END = 312;
@@ -289,7 +289,7 @@ export class Parser {
289
289
  // uses it. this test only works because we know the internal type
290
290
  // representation, but that's fragile and not a good idea. FIXME
291
291
 
292
- if ((argument_separator as any) === (decimal_mark as any)) {
292
+ if ((argument_separator as string) === (decimal_mark as string)) {
293
293
  throw new Error('invalid locale setting');
294
294
  }
295
295
 
@@ -452,7 +452,7 @@ export class Parser {
452
452
  const {
453
453
  convert_decimal,
454
454
  convert_argument_separator,
455
- convert_imaginary_number,
455
+ // convert_imaginary_number,
456
456
  long_structured_references,
457
457
  table_name
458
458
  } = options;
@@ -467,10 +467,12 @@ export class Parser {
467
467
  separator = '; ';
468
468
  }
469
469
 
470
+ /*
470
471
  let imaginary_character = this.imaginary_number;
471
472
  if (convert_imaginary_number) {
472
473
  imaginary_character = convert_imaginary_number;
473
474
  }
475
+ */
474
476
 
475
477
  // this is only used if we're converting.
476
478
 
@@ -1821,7 +1823,7 @@ export class Parser {
1821
1823
  }
1822
1824
  else {
1823
1825
  this.error = `multiple expressions`;
1824
- this.error_position = (element as any).position;
1826
+ this.error_position = (element as {position?: number}).position;
1825
1827
  this.valid = false;
1826
1828
  return {
1827
1829
  type: 'group',
@@ -2258,7 +2260,7 @@ export class Parser {
2258
2260
  // whitespace around column names is also ignored, but spaces within
2259
2261
  // a column name are OK, at least within the second set of brackets.
2260
2262
 
2261
- const index = position;
2263
+ // const index = position;
2262
2264
  const token_length = token.length;
2263
2265
 
2264
2266
  const label = token;
@@ -25,7 +25,7 @@
25
25
  let subscription_token_generator = 1000;
26
26
 
27
27
  interface EventSubscription<T> {
28
- subscriber: (event: T) => any;
28
+ subscriber: (event: T) => void;
29
29
  token: number;
30
30
  }
31
31
 
@@ -28,18 +28,35 @@ interface StringMap {
28
28
  */
29
29
  let default_properties: StringMap|undefined;
30
30
 
31
+ const PropertyMap = (source: CSSStyleDeclaration): StringMap => {
32
+
33
+ const map: StringMap = {};
34
+
35
+ // you can iterate this thing, although apparently ts won't allow
36
+ // it because it's not in the spec? should probably play ball
37
+
38
+ for (let i = 0; i < source.length; i++) {
39
+ const key = source[i];
40
+ map[key] = source.getPropertyValue(key);
41
+ }
42
+
43
+ return map;
44
+
45
+ }
46
+
31
47
  /**
32
48
  * get applied style as text (for attribute)
33
49
  */
34
50
  const GetAppliedStyle = (node: Element, computed: CSSStyleDeclaration, defaults: StringMap) => {
35
51
 
36
52
  const applied: StringMap = {};
37
-
38
- Array.prototype.forEach.call(computed, (key) => {
39
- if (computed[key] !== defaults[key]) {
40
- applied[key] = computed[key];
53
+ const computed_map = PropertyMap(computed);
54
+
55
+ for (const key of Object.keys(computed_map)) {
56
+ if (computed_map[key] !== defaults[key]) {
57
+ applied[key] = defaults[key];
41
58
  }
42
- });
59
+ }
43
60
 
44
61
  return (Object.keys(applied).map((key) => `${key}: ${applied[key]}`).join('; ') +
45
62
  '; ' + (node.getAttribute('style') || '')).trim().replace(/"/g, '\'');
@@ -58,13 +75,21 @@ const RenderNode = (node: Element, defaults: StringMap) => {
58
75
  (clone as HTMLElement).removeAttribute('class');
59
76
  (clone as HTMLElement).setAttribute('style', style);
60
77
 
78
+ let computed_map: StringMap|undefined;
79
+
61
80
  Array.prototype.forEach.call(node.childNodes, (child: Node) => {
62
81
 
63
82
  switch (child.nodeType) {
64
83
 
65
84
  case Node.ELEMENT_NODE:
85
+
66
86
  // here we use the parent as the default style, assuming the child will inherit
67
- clone.appendChild(RenderNode(child as Element, computed as any));
87
+
88
+ // create on demand, if necessary
89
+ if (!computed_map) {
90
+ computed_map = PropertyMap(computed);
91
+ }
92
+ clone.appendChild(RenderNode(child as Element, computed_map));
68
93
  break;
69
94
 
70
95
  case Node.TEXT_NODE:
package/.eslintignore DELETED
@@ -1,8 +0,0 @@
1
-
2
- node_modules
3
- dist
4
- build
5
- declaration
6
- treb.d.ts
7
-
8
-
package/.eslintrc.cjs DELETED
@@ -1,168 +0,0 @@
1
- module.exports = {
2
- env: {
3
- 'browser': true,
4
- 'node': true,
5
- },
6
- root: true,
7
- parser: '@typescript-eslint/parser',
8
- plugins: [
9
- '@typescript-eslint',
10
- ],
11
- extends: [
12
- 'eslint:recommended',
13
- 'plugin:@typescript-eslint/eslint-recommended',
14
- 'plugin:@typescript-eslint/recommended',
15
- ],
16
-
17
- rules: {
18
- 'no-irregular-whitespace': [
19
- 'error',
20
- {
21
- skipComments: true,
22
- }
23
- ],
24
- 'camelcase': 'off',
25
- '@typescript-eslint/no-unsafe-declaration-merging': 'error',
26
- '@typescript-eslint/camelcase': 'off',
27
- // '@typescript-eslint/explicit-function-return-type': 'off',
28
- '@typescript-eslint/quotes': [
29
- 'error',
30
- 'single',
31
- { 'allowTemplateLiterals': true },
32
- ],
33
- 'brace-style': 'off',
34
- '@typescript-eslint/brace-style': [
35
- 'error',
36
- 'stroustrup',
37
- { 'allowSingleLine': true },
38
- ],
39
- '@typescript-eslint/interface-name-prefix': 'off',
40
-
41
- /*
42
-
43
- FIXME: needs configuration. I'm ok with it generally but why split
44
- accessors for the same field?
45
-
46
- UPDATE: see also https://eslint.org/docs/rules/grouped-accessor-pairs
47
-
48
- not sure how these work together
49
-
50
- '@typescript-eslint/member-ordering': [
51
- 'error',
52
- ],
53
- */
54
-
55
- 'grouped-accessor-pairs': ['error', 'getBeforeSet'],
56
-
57
- '@typescript-eslint/consistent-type-imports': 'error',
58
- // '@typescript-eslint/consistent-type-exports': 'error',
59
-
60
- }
61
-
62
- /*
63
- "rules": {
64
- "@typescript-eslint/adjacent-overload-signatures": "error",
65
- "@typescript-eslint/array-type": "error",
66
- "@typescript-eslint/ban-types": "error",
67
- "@typescript-eslint/class-name-casing": "error",
68
- "@typescript-eslint/consistent-type-assertions": "error",
69
- "@typescript-eslint/indent": [
70
- 2
71
- ],
72
- "@typescript-eslint/no-empty-function": "error",
73
- "@typescript-eslint/no-empty-interface": "error",
74
- "@typescript-eslint/no-explicit-any": "off",
75
- "@typescript-eslint/no-misused-new": "error",
76
- "@typescript-eslint/no-namespace": "error",
77
- "@typescript-eslint/no-parameter-properties": "off",
78
- "@typescript-eslint/no-use-before-define": "off",
79
- "@typescript-eslint/no-var-requires": "error",
80
- "@typescript-eslint/prefer-for-of": "error",
81
- "@typescript-eslint/prefer-function-type": "error",
82
- "@typescript-eslint/prefer-namespace-keyword": "error",
83
- "@typescript-eslint/quotes": [
84
- "error",
85
- "single"
86
- ],
87
- "@typescript-eslint/triple-slash-reference": "error",
88
- "@typescript-eslint/unified-signatures": "error",
89
- "camelcase": "off",
90
- "complexity": "off",
91
- "constructor-super": "error",
92
- "curly": [
93
- "error",
94
- "multi-line"
95
- ],
96
- "dot-notation": "error",
97
- "eqeqeq": [
98
- "error",
99
- "smart"
100
- ],
101
- "guard-for-in": "error",
102
- "id-blacklist": "error",
103
- "id-match": "error",
104
- "import/order": "off",
105
- "max-classes-per-file": [
106
- "error",
107
- 1
108
- ],
109
- "new-parens": "error",
110
- "no-bitwise": "error",
111
- "no-caller": "error",
112
- "no-cond-assign": "error",
113
- "no-console": "off",
114
- "no-debugger": "error",
115
- "no-empty": "error",
116
- "no-eval": "error",
117
- "no-fallthrough": "off",
118
- "no-invalid-this": "off",
119
- "no-multiple-empty-lines": "off",
120
- "no-new-wrappers": "error",
121
- "no-shadow": [
122
- "error",
123
- {
124
- "hoist": "all"
125
- }
126
- ],
127
- "no-throw-literal": "error",
128
- "no-trailing-spaces": "error",
129
- "no-undef-init": "error",
130
- "no-underscore-dangle": "error",
131
- "no-unsafe-finally": "error",
132
- "no-unused-expressions": "error",
133
- "no-unused-labels": "error",
134
- "no-var": "error",
135
- "object-shorthand": "error",
136
- "one-var": [
137
- "error",
138
- "never"
139
- ],
140
- "prefer-arrow/prefer-arrow-functions": "error",
141
- "prefer-const": "error",
142
- "quote-props": [
143
- "error",
144
- "as-needed"
145
- ],
146
- "radix": "error",
147
- "spaced-comment": "error",
148
- "use-isnan": "error",
149
- "valid-typeof": "off",
150
-
151
- / *
152
- "@typescript-eslint/tslint/config": [
153
- "error",
154
- {
155
- "rules": {
156
- "jsdoc-format": true,
157
- "no-reference-import": true,
158
- "one-line": [
159
- true,
160
- "check-open-brace"
161
- ]
162
- }
163
- }
164
- ]
165
- * /
166
- }
167
- */
168
- };
@@ -1,86 +0,0 @@
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-2024 trebco, llc.
18
- * info@treb.app
19
- *
20
- */
21
-
22
- import type { Rectangle } from 'treb-base-types';
23
-
24
- /**
25
- * FIXME: efficiency of using sparse arrays here?
26
- *
27
- * (vs what, a lookup table? sparse arrays are basically a lookup
28
- * table, and we can assume they're reasonably efficient)
29
- */
30
- /*export*/ class RectangleCache {
31
-
32
- private cache: Rectangle[][] = [];
33
-
34
- /*
35
-
36
- private hits = 0;
37
- private misses = 0;
38
-
39
- public Stats(){
40
- return {
41
- hits: this.hits,
42
- misses: this.misses,
43
- hit_rate: (this.hits + this.misses) ? this.hits / (this.hits + this.misses) : 0,
44
- };
45
- }
46
-
47
- */
48
-
49
- /** flush cache */
50
- public Clear(){
51
- this.cache = [];
52
- }
53
-
54
- /**
55
- * cache lookup.
56
- * FIXME: why row/column and not address type?
57
- */
58
- public Get(column: number, row: number): Rectangle|undefined {
59
-
60
- if (!this.cache[column]) return undefined;
61
- const rect = this.cache[column][row];
62
- return rect ? rect.Shift(0, 0) : undefined;
63
-
64
- /*
65
- if (this.cache[column]) {
66
- const rect = this.cache[column][row];
67
- if (rect) {
68
- this.hits++;
69
- return rect.Shift(0, 0);
70
- }
71
- }
72
- this.misses++;
73
- return undefined;
74
- */
75
- }
76
-
77
- /**
78
- * cache set.
79
- * FIXME: why row/column and not address type?
80
- */
81
- public Set(column: number, row: number, rect: Rectangle) {
82
- if (!this.cache[column]) this.cache[column] = [];
83
- this.cache[column][row] = rect.Shift(0, 0); // clone
84
- }
85
-
86
- }