@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.
- package/dist/treb-spreadsheet-light.mjs +12 -12
- package/dist/treb-spreadsheet.mjs +12 -12
- package/dist/treb.d.ts +121 -82
- package/eslint.config.js +21 -0
- package/package.json +6 -6
- package/treb-base-types/src/area.ts +4 -2
- package/treb-base-types/src/cell.ts +1 -1
- package/treb-base-types/src/cells.ts +16 -7
- package/treb-base-types/src/dom-utilities.ts +4 -2
- package/treb-base-types/src/import.ts +2 -2
- package/treb-base-types/src/rectangle.ts +5 -5
- package/treb-base-types/src/union.ts +6 -1
- package/treb-base-types/src/value-type.ts +1 -1
- package/treb-calculator/src/calculator.ts +114 -165
- package/treb-calculator/src/dag/calculation_leaf_vertex.ts +1 -2
- package/treb-calculator/src/dag/graph.ts +3 -3
- package/treb-calculator/src/dag/spreadsheet_vertex.ts +2 -2
- package/treb-calculator/src/dag/state_leaf_vertex.ts +2 -4
- package/treb-calculator/src/descriptors.ts +28 -2
- package/treb-calculator/src/expression-calculator.ts +25 -34
- package/treb-calculator/src/function-error.ts +2 -2
- package/treb-calculator/src/function-library.ts +16 -0
- package/treb-calculator/src/functions/base-functions.ts +185 -211
- package/treb-calculator/src/functions/checkbox.ts +0 -1
- package/treb-calculator/src/functions/complex-functions.ts +49 -47
- package/treb-calculator/src/functions/finance-functions.ts +10 -10
- package/treb-calculator/src/functions/function-utilities.ts +26 -0
- package/treb-calculator/src/functions/information-functions.ts +21 -41
- package/treb-calculator/src/functions/matrix-functions.ts +8 -1
- package/treb-calculator/src/functions/sparkline.ts +6 -4
- package/treb-calculator/src/functions/statistics-functions.ts +21 -17
- package/treb-calculator/src/functions/text-functions.ts +14 -13
- package/treb-calculator/src/primitives.ts +48 -37
- package/treb-calculator/src/utilities.ts +117 -134
- package/treb-charts/src/chart-functions.ts +3 -3
- package/treb-charts/src/chart-types.ts +42 -1
- package/treb-charts/src/chart-utils.ts +155 -113
- package/treb-charts/src/chart.ts +6 -5
- package/treb-charts/src/default-chart-renderer.ts +6 -5
- package/treb-charts/src/renderer.ts +12 -11
- package/treb-charts/src/util.ts +25 -36
- package/treb-data-model/package.json +5 -0
- package/{treb-grid/src/types → treb-data-model/src}/annotation.ts +2 -2
- package/{treb-grid/src/types → treb-data-model/src}/conditional_format.ts +20 -0
- package/{treb-grid/src/types → treb-data-model/src}/data_model.ts +231 -133
- package/treb-data-model/src/index.ts +45 -0
- package/{treb-grid/src/types/named_range.ts → treb-data-model/src/named.ts} +459 -376
- package/{treb-grid/src/types → treb-data-model/src}/sheet.ts +13 -5
- package/treb-data-model/src/sheet_collection.ts +114 -0
- package/{treb-grid/src/types → treb-data-model/src}/sheet_types.ts +6 -3
- package/treb-embed/modern.tsconfig.json +1 -0
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +2 -2
- package/treb-embed/src/embedded-spreadsheet.ts +125 -270
- package/treb-embed/src/selection-state.ts +1 -1
- package/treb-embed/src/toolbar-message.ts +1 -1
- package/treb-embed/src/types.ts +13 -5
- package/treb-export/src/export-worker/export-worker.ts +22 -7
- package/treb-export/src/export2.ts +110 -41
- package/treb-export/src/import2.ts +6 -5
- package/treb-export/src/workbook2.ts +31 -13
- package/treb-export/src/xml-utils.ts +5 -1
- package/treb-format/src/format.ts +8 -6
- package/treb-grid/src/editors/autocomplete.ts +2 -2
- package/treb-grid/src/editors/autocomplete_matcher.ts +57 -19
- package/treb-grid/src/editors/editor.ts +27 -25
- package/treb-grid/src/editors/formula_bar.ts +5 -5
- package/treb-grid/src/editors/overlay_editor.ts +1 -2
- package/treb-grid/src/index.ts +0 -11
- package/treb-grid/src/layout/base_layout.ts +20 -8
- package/treb-grid/src/layout/grid_layout.ts +2 -2
- package/treb-grid/src/layout/mock-layout.ts +5 -6
- package/treb-grid/src/render/selection-renderer.ts +2 -3
- package/treb-grid/src/render/tile_renderer.ts +1 -1
- package/treb-grid/src/types/grid.ts +95 -66
- package/treb-grid/src/types/grid_base.ts +76 -60
- package/treb-grid/src/types/grid_command.ts +3 -2
- package/treb-grid/src/types/grid_events.ts +12 -6
- package/treb-grid/src/types/tab_bar.ts +1 -2
- package/treb-parser/src/parser-types.ts +2 -1
- package/treb-parser/src/parser.ts +7 -5
- package/treb-utils/src/event_source.ts +1 -1
- package/treb-utils/src/serialize_html.ts +31 -6
- package/.eslintignore +0 -8
- package/.eslintrc.cjs +0 -168
- package/treb-grid/src/layout/rectangle_cache.ts +0 -86
- /package/{treb-grid/src/types → treb-data-model/src}/serialize_options.ts +0 -0
- /package/{treb-grid/src/types/grid_selection.ts → treb-data-model/src/sheet_selection.ts} +0 -0
|
@@ -34,7 +34,7 @@ export interface ArgumentDescriptor {
|
|
|
34
34
|
|
|
35
35
|
name?: string;
|
|
36
36
|
description?: string;
|
|
37
|
-
default?:
|
|
37
|
+
default?: number|string|boolean;
|
|
38
38
|
|
|
39
39
|
// moved from function arrays:
|
|
40
40
|
|
|
@@ -70,6 +70,15 @@ export interface ArgumentDescriptor {
|
|
|
70
70
|
*/
|
|
71
71
|
metadata?: boolean;
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* new flag for automating array application. set this flag to allow
|
|
75
|
+
* unrolling of array parameters. @see ApplyArray in `utilities.ts`.
|
|
76
|
+
*
|
|
77
|
+
* if this flag is set in any argument descriptor in a function, we'll
|
|
78
|
+
* apply arrays. that's done when the function is installed.
|
|
79
|
+
*/
|
|
80
|
+
unroll?: boolean;
|
|
81
|
+
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
/**
|
|
@@ -108,8 +117,13 @@ export interface CompositeFunctionDescriptor {
|
|
|
108
117
|
/**
|
|
109
118
|
* the actual function. if this is an object member and needs access
|
|
110
119
|
* to the containing instance, make sure to bind it to that instance.
|
|
120
|
+
*
|
|
121
|
+
* FIXME: this should change to unknown, but that's going to cause
|
|
122
|
+
* a lot of issues
|
|
123
|
+
*
|
|
111
124
|
*/
|
|
112
|
-
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
fn: (...args: any[]) => UnionValue;
|
|
113
127
|
|
|
114
128
|
/**
|
|
115
129
|
* limited visibility
|
|
@@ -152,8 +166,18 @@ export interface CompositeFunctionDescriptor {
|
|
|
152
166
|
/**
|
|
153
167
|
* @internal
|
|
154
168
|
*/
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
170
|
export?: (...args: any[]) => string;
|
|
156
171
|
|
|
172
|
+
/**
|
|
173
|
+
* flag indicating we've unrolled this function. it's possible functions
|
|
174
|
+
* will run through the registration process more than once and we don't
|
|
175
|
+
* want to have extra depth.
|
|
176
|
+
*
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
unrolled?: boolean;
|
|
180
|
+
|
|
157
181
|
}
|
|
158
182
|
|
|
159
183
|
export interface FunctionMap {
|
|
@@ -172,3 +196,5 @@ export interface ExtendedFunctionDescriptor extends CompositeFunctionDescriptor
|
|
|
172
196
|
export interface ExtendedFunctionMap {
|
|
173
197
|
[index: string]: ExtendedFunctionDescriptor;
|
|
174
198
|
}
|
|
199
|
+
|
|
200
|
+
export type IntrinsicValue = number|string|boolean|undefined;
|
|
@@ -21,20 +21,22 @@
|
|
|
21
21
|
|
|
22
22
|
import type { FunctionLibrary } from './function-library';
|
|
23
23
|
import type { Cell, ICellAddress,
|
|
24
|
-
|
|
24
|
+
UnionValue, CellValue,
|
|
25
25
|
ArrayUnion,
|
|
26
26
|
NumberUnion,
|
|
27
27
|
UndefinedUnion,
|
|
28
|
-
ComplexUnion
|
|
28
|
+
ComplexUnion,
|
|
29
|
+
DimensionedQuantityUnion} from 'treb-base-types';
|
|
29
30
|
import { ValueType, GetValueType } from 'treb-base-types';
|
|
30
31
|
import type { Parser, ExpressionUnit, UnitBinary, UnitIdentifier,
|
|
31
32
|
UnitGroup, UnitUnary, UnitAddress, UnitRange, UnitCall, UnitDimensionedQuantity, UnitStructuredReference } from 'treb-parser';
|
|
32
|
-
import type { DataModel, MacroFunction, Sheet } from 'treb-
|
|
33
|
+
import type { DataModel, MacroFunction, Sheet } from 'treb-data-model';
|
|
33
34
|
import { NameError, ReferenceError, ExpressionError, UnknownError } from './function-error';
|
|
34
35
|
import { ReturnType } from './descriptors';
|
|
35
36
|
|
|
36
37
|
import * as Primitives from './primitives';
|
|
37
38
|
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
40
|
export type ExtendedExpressionUnit = ExpressionUnit & { user_data: any }; // export for MC overload
|
|
39
41
|
|
|
40
42
|
// FIXME: move
|
|
@@ -96,7 +98,7 @@ export class ExpressionCalculator {
|
|
|
96
98
|
// protected sheet_name_map: {[index: string]: number} = {};
|
|
97
99
|
|
|
98
100
|
// local reference
|
|
99
|
-
protected named_range_map: {[index: string]: Area} = {};
|
|
101
|
+
// protected named_range_map: {[index: string]: Area} = {};
|
|
100
102
|
|
|
101
103
|
// protected bound_name_stack: Array<Record<string, ExpressionUnit>> = [];
|
|
102
104
|
|
|
@@ -123,7 +125,7 @@ export class ExpressionCalculator {
|
|
|
123
125
|
*/
|
|
124
126
|
|
|
125
127
|
this.data_model = model;
|
|
126
|
-
this.named_range_map = model.named_ranges.Map();
|
|
128
|
+
// this.named_range_map = model.named_ranges.Map();
|
|
127
129
|
this.context.model = model;
|
|
128
130
|
|
|
129
131
|
}
|
|
@@ -216,6 +218,7 @@ export class ExpressionCalculator {
|
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
/** breaking this out to de-dupe */
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
219
222
|
protected GetMetadata(arg: ExpressionUnit, map_result: (cell_data: Cell, address: ICellAddress) => any): UnionValue /*UnionOrArray*/ {
|
|
220
223
|
|
|
221
224
|
// FIXME: we used to restrict this to non-cell functions, now
|
|
@@ -250,13 +253,14 @@ export class ExpressionCalculator {
|
|
|
250
253
|
|
|
251
254
|
case 'identifier':
|
|
252
255
|
{
|
|
253
|
-
const named_range = this.named_range_map[arg.name.toUpperCase()];
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
256
|
+
// const named_range = this.named_range_map[arg.name.toUpperCase()];
|
|
257
|
+
const named_range = this.data_model.GetName(arg.name, this.context.address.sheet_id || 0);
|
|
258
|
+
if (named_range?.type === 'range') {
|
|
259
|
+
if (named_range.area.count === 1) {
|
|
260
|
+
address = named_range.area.start; // FIXME: range?
|
|
257
261
|
}
|
|
258
262
|
else {
|
|
259
|
-
range = named_range;
|
|
263
|
+
range = named_range.area;
|
|
260
264
|
}
|
|
261
265
|
}
|
|
262
266
|
}
|
|
@@ -726,7 +730,7 @@ export class ExpressionCalculator {
|
|
|
726
730
|
value: expression.value,
|
|
727
731
|
unit: expr.unit.name,
|
|
728
732
|
},
|
|
729
|
-
};
|
|
733
|
+
} as DimensionedQuantityUnion;
|
|
730
734
|
};
|
|
731
735
|
|
|
732
736
|
}
|
|
@@ -938,30 +942,22 @@ export class ExpressionCalculator {
|
|
|
938
942
|
}
|
|
939
943
|
*/
|
|
940
944
|
|
|
941
|
-
const named_range = this.named_range_map[upper_case];
|
|
945
|
+
// const named_range = this.named_range_map[upper_case];
|
|
946
|
+
const named_range = this.data_model.GetName(upper_case, this.context.address.sheet_id || 0);
|
|
942
947
|
|
|
943
|
-
if (named_range) {
|
|
944
|
-
if (named_range.count === 1) {
|
|
945
|
-
return this.CellFunction4(named_range.start, named_range.start);
|
|
948
|
+
if (named_range?.type === 'range') {
|
|
949
|
+
if (named_range.area.count === 1) {
|
|
950
|
+
return this.CellFunction4(named_range.area.start, named_range.area.start);
|
|
946
951
|
}
|
|
947
952
|
else {
|
|
948
|
-
return this.CellFunction4(named_range.start, named_range.end);
|
|
953
|
+
return this.CellFunction4(named_range.area.start, named_range.area.end);
|
|
949
954
|
}
|
|
950
955
|
}
|
|
951
956
|
|
|
952
|
-
const
|
|
953
|
-
if (
|
|
954
|
-
return this.CalculateExpression(
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
/*
|
|
958
|
-
const bound_names = this.context.name_stack[0];
|
|
959
|
-
|
|
960
|
-
if (bound_names && bound_names[upper_case]) {
|
|
961
|
-
const bound_expression = bound_names[upper_case];
|
|
962
|
-
return this.CalculateExpression(bound_expression);
|
|
957
|
+
const named2 = this.data_model.GetName(identifier, this.context.address.sheet_id || 0);
|
|
958
|
+
if (named2 && named2.type === 'expression') {
|
|
959
|
+
return this.CalculateExpression(named2.expression as ExtendedExpressionUnit);
|
|
963
960
|
}
|
|
964
|
-
*/
|
|
965
961
|
|
|
966
962
|
// console.info( '** identifier', {identifier, expr, context: this.context});
|
|
967
963
|
|
|
@@ -1052,16 +1048,11 @@ export class ExpressionCalculator {
|
|
|
1052
1048
|
return (expr.user_data = () => {
|
|
1053
1049
|
return {
|
|
1054
1050
|
type: ValueType.array,
|
|
1055
|
-
value: expr.values.map((row
|
|
1051
|
+
value: expr.values.map((row) => (Array.isArray(row) ? row : [row]).map((value) => {
|
|
1056
1052
|
return { type: GetValueType(value), value } as UnionValue;
|
|
1057
1053
|
})),
|
|
1058
1054
|
} as ArrayUnion;
|
|
1059
1055
|
})();
|
|
1060
|
-
/*
|
|
1061
|
-
return (expr.user_data = () => expr.values.map(row => (Array.isArray(row) ? row : [row]).map(value => {
|
|
1062
|
-
return { value, type: GetValueType(value) }
|
|
1063
|
-
})))(); // check
|
|
1064
|
-
*/
|
|
1065
1056
|
}
|
|
1066
1057
|
|
|
1067
1058
|
default:
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import type { UnionValue} from 'treb-base-types';
|
|
22
|
+
import type { ErrorUnion, UnionValue} from 'treb-base-types';
|
|
23
23
|
import { ValueType } from 'treb-base-types';
|
|
24
24
|
|
|
25
25
|
export enum ErrorType {
|
|
@@ -70,7 +70,7 @@ export const ArgumentError = (): UnionValue => {
|
|
|
70
70
|
return { type: ValueType.error, value: ErrorType.Argument };
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
export const ValueError = (): UnionValue => {
|
|
73
|
+
export const ValueError = (): /* UnionValue */ ErrorUnion => {
|
|
74
74
|
return { type: ValueType.error, value: ErrorType.Value };
|
|
75
75
|
};
|
|
76
76
|
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import type {
|
|
23
23
|
ExtendedFunctionDescriptor, CompositeFunctionDescriptor,
|
|
24
24
|
FunctionMap, ExtendedFunctionMap } from './descriptors';
|
|
25
|
+
import { ApplyArrayX } from './utilities';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* singleton (static instance) of function library; includes utility methods
|
|
@@ -66,6 +67,21 @@ export class FunctionLibrary {
|
|
|
66
67
|
const descriptor = map[name] as ExtendedFunctionDescriptor;
|
|
67
68
|
descriptor.canonical_name = name;
|
|
68
69
|
|
|
70
|
+
if (!descriptor.unrolled) {
|
|
71
|
+
|
|
72
|
+
// potentially apply a wrapper to unroll loops
|
|
73
|
+
|
|
74
|
+
const unroll = descriptor.arguments?.map(test => !!test.unroll);
|
|
75
|
+
if (unroll?.some(value => !!value)) {
|
|
76
|
+
descriptor.fn = ApplyArrayX(unroll, descriptor.fn);
|
|
77
|
+
descriptor.unrolled = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// we could set that flag even if we don't do anything,
|
|
81
|
+
// sp we don't check again (minor optimization)
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
69
85
|
this.functions[normalized] = descriptor;
|
|
70
86
|
}
|
|
71
87
|
|