@trebco/treb 27.5.3 → 27.9.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.
Files changed (48) hide show
  1. package/dist/treb-spreadsheet.mjs +14 -14
  2. package/dist/treb.d.ts +37 -23
  3. package/notes/conditional-fomratring.md +29 -0
  4. package/package.json +3 -3
  5. package/treb-base-types/src/area.ts +181 -0
  6. package/treb-base-types/src/evaluate-options.ts +21 -0
  7. package/treb-base-types/src/gradient.ts +97 -0
  8. package/treb-base-types/src/import.ts +2 -1
  9. package/treb-base-types/src/index.ts +2 -0
  10. package/treb-calculator/src/calculator.ts +205 -132
  11. package/treb-calculator/src/dag/calculation_leaf_vertex.ts +97 -0
  12. package/treb-calculator/src/dag/graph.ts +10 -22
  13. package/treb-calculator/src/dag/{leaf_vertex.ts → state_leaf_vertex.ts} +3 -3
  14. package/treb-calculator/src/descriptors.ts +10 -3
  15. package/treb-calculator/src/expression-calculator.ts +1 -1
  16. package/treb-calculator/src/function-library.ts +25 -22
  17. package/treb-calculator/src/functions/base-functions.ts +166 -5
  18. package/treb-calculator/src/index.ts +6 -6
  19. package/treb-calculator/src/notifier-types.ts +1 -1
  20. package/treb-calculator/src/utilities.ts +2 -2
  21. package/treb-charts/src/util.ts +2 -2
  22. package/treb-embed/src/embedded-spreadsheet.ts +382 -71
  23. package/treb-embed/style/formula-bar.scss +2 -0
  24. package/treb-embed/style/theme-defaults.scss +46 -15
  25. package/treb-export/src/export-worker/export-worker.ts +0 -13
  26. package/treb-export/src/export2.ts +187 -2
  27. package/treb-export/src/import2.ts +169 -4
  28. package/treb-export/src/workbook-style2.ts +56 -8
  29. package/treb-export/src/workbook2.ts +10 -1
  30. package/treb-grid/src/editors/editor.ts +1276 -0
  31. package/treb-grid/src/editors/external_editor.ts +113 -0
  32. package/treb-grid/src/editors/formula_bar.ts +450 -474
  33. package/treb-grid/src/editors/overlay_editor.ts +437 -512
  34. package/treb-grid/src/index.ts +2 -1
  35. package/treb-grid/src/layout/base_layout.ts +24 -16
  36. package/treb-grid/src/render/tile_renderer.ts +2 -1
  37. package/treb-grid/src/types/conditional_format.ts +168 -0
  38. package/treb-grid/src/types/data_model.ts +130 -3
  39. package/treb-grid/src/types/external_editor_config.ts +47 -0
  40. package/treb-grid/src/types/grid.ts +96 -45
  41. package/treb-grid/src/types/grid_base.ts +187 -35
  42. package/treb-grid/src/types/scale-control.ts +1 -1
  43. package/treb-grid/src/types/sheet.ts +330 -26
  44. package/treb-grid/src/types/sheet_types.ts +4 -0
  45. package/treb-grid/src/util/dom_utilities.ts +58 -25
  46. package/treb-grid/src/editors/formula_editor_base.ts +0 -912
  47. package/treb-grid/src/types/external_editor.ts +0 -27
  48. /package/{README-shadow-DOM.md → notes/shadow-DOM.md} +0 -0
@@ -1,24 +1,24 @@
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 {
23
23
  ExtendedFunctionDescriptor, CompositeFunctionDescriptor,
24
24
  FunctionMap, ExtendedFunctionMap } from './descriptors';
@@ -80,9 +80,12 @@ export class FunctionLibrary {
80
80
  }
81
81
 
82
82
  /** get a list, for AC services */
83
- public List() {
83
+ public List(filter_internal = true) {
84
84
  const list: ExtendedFunctionMap = {};
85
85
  for (const key of Object.keys(this.functions)) {
86
+ if (filter_internal && this.functions[key].visibility === 'internal') {
87
+ continue;
88
+ }
86
89
  list[key] = this.functions[key];
87
90
  }
88
91
  return list;
@@ -21,10 +21,10 @@
21
21
 
22
22
  import type { FunctionMap } from '../descriptors';
23
23
  import * as Utils from '../utilities';
24
- import { ReferenceError, NotImplError, NAError, ArgumentError, DivideByZeroError, ValueError } from '../function-error';
24
+ import { ReferenceError, NotImplError, NAError, ArgumentError, DivideByZeroError, ValueError, NameError } from '../function-error';
25
25
  import type { UnionValue,
26
26
  RenderFunctionResult, RenderFunctionOptions, Complex } from 'treb-base-types';
27
- import { Box, ValueType, GetValueType, ComplexOrReal } from 'treb-base-types';
27
+ import { Box, ValueType, GetValueType, ComplexOrReal, IsComplex } from 'treb-base-types';
28
28
  import { Sparkline } from './sparkline';
29
29
  import { LotusDate, UnlotusDate } from 'treb-format';
30
30
 
@@ -427,7 +427,7 @@ export const BaseFunctionLibrary: FunctionMap = {
427
427
  description: 'Counts cells that contain numbers',
428
428
  fn: (...args: unknown[]): UnionValue => {
429
429
  return Box(Utils.FlattenUnboxed(args).reduce((a: number, b: unknown) => {
430
- if (typeof b === 'number') return a + 1;
430
+ if (typeof b === 'number' || IsComplex(b)) return a + 1;
431
431
  return a;
432
432
  }, 0));
433
433
  },
@@ -456,7 +456,7 @@ export const BaseFunctionLibrary: FunctionMap = {
456
456
  },
457
457
 
458
458
  Not: {
459
- fn: (...args: unknown[]): UnionValue => {
459
+ fn: Utils.ApplyAsArray((...args: unknown[]): UnionValue => {
460
460
  if (args.length === 0) {
461
461
  return ArgumentError();
462
462
  }
@@ -464,7 +464,7 @@ export const BaseFunctionLibrary: FunctionMap = {
464
464
  return Box(!args[0]);
465
465
  }
466
466
  return Box(true);
467
- }
467
+ })
468
468
  },
469
469
 
470
470
  If: {
@@ -1126,6 +1126,167 @@ export const BaseFunctionLibrary: FunctionMap = {
1126
1126
  fn: (...args: unknown[]): UnionValue => {
1127
1127
  return { type: ValueType.object, value: args, key: 'sparkline-data' };
1128
1128
  },
1129
+ },
1130
+
1131
+ UniqueValues: {
1132
+ arguments: [
1133
+ { name: 'range', boxed: true },
1134
+ ],
1135
+ visibility: 'internal',
1136
+ fn: (area: UnionValue): UnionValue => {
1137
+
1138
+ if (area.type === ValueType.array) {
1139
+
1140
+ const cols = area.value.length;
1141
+ const rows = area.value[0]?.length;
1142
+
1143
+ // how is uniqueness defined in this context? (...)
1144
+
1145
+ const Normalize = (cell?: UnionValue): string|number|boolean => {
1146
+
1147
+ if (!cell) {
1148
+ return '';
1149
+ }
1150
+ else switch (cell.type) {
1151
+ case ValueType.string:
1152
+ case ValueType.number:
1153
+ case ValueType.boolean:
1154
+ return cell.value;
1155
+
1156
+ case ValueType.undefined:
1157
+ return '';
1158
+
1159
+ default:
1160
+ console.info("check", cell, cell.value)
1161
+ return cell.value?.toString() || '';
1162
+ }
1163
+
1164
+ };
1165
+
1166
+ const set: Set<number|string|boolean> = new Set();
1167
+ const duplicates: Set<number|string|boolean> = new Set();
1168
+
1169
+ for (const column of area.value) {
1170
+ for (const cell of column) {
1171
+ const normalized = Normalize(cell);
1172
+ if (set.has(normalized)) {
1173
+ duplicates.add(normalized);
1174
+ }
1175
+ else {
1176
+ set.add(normalized);
1177
+ }
1178
+ }
1179
+ }
1180
+
1181
+ const result: UnionValue[][] = [];
1182
+ for (const column of area.value) {
1183
+ const column_result: UnionValue[] = [];
1184
+ for (const cell of column) {
1185
+ const value = Normalize(cell);
1186
+ column_result.push({
1187
+ type: ValueType.boolean,
1188
+ value: !duplicates.has(value),
1189
+ });
1190
+ }
1191
+ result.push(column_result);
1192
+ }
1193
+
1194
+ return {
1195
+ type: ValueType.array,
1196
+ value: result,
1197
+ };
1198
+
1199
+ }
1200
+
1201
+ // if it's not an array, by definition it's unique
1202
+
1203
+ return {
1204
+ type: ValueType.boolean,
1205
+ value: true,
1206
+ }
1207
+
1208
+ },
1209
+ },
1210
+
1211
+ Gradient: {
1212
+ arguments: [
1213
+ { name: 'range', boxed: true },
1214
+ { name: 'min', },
1215
+ { name: 'max', },
1216
+ ],
1217
+ visibility: 'internal',
1218
+ fn: (area: UnionValue, static_min?: number, static_max?: number): UnionValue => {
1219
+
1220
+ const tmp = Utils.FlattenBoxed([area]);
1221
+
1222
+ let sum = 0;
1223
+ let count = 0;
1224
+ let min = 0;
1225
+ let max = 0;
1226
+
1227
+ for (const ref of tmp as UnionValue[]) {
1228
+ if (ref.type === ValueType.error) {
1229
+ return ref;
1230
+ }
1231
+ if (ref.type === ValueType.number) {
1232
+ if (count === 0) {
1233
+ min = ref.value;
1234
+ max = ref.value;
1235
+ }
1236
+ else {
1237
+ min = Math.min(min, ref.value);
1238
+ max = Math.max(max, ref.value);
1239
+ }
1240
+ count++;
1241
+ }
1242
+ }
1243
+
1244
+ if (typeof static_max === 'number') {
1245
+ max = static_max;
1246
+ }
1247
+ if (typeof static_min === 'number') {
1248
+ min = static_min;
1249
+ }
1250
+
1251
+ let range = max - min;
1252
+
1253
+ let rows = 1;
1254
+ let columns = 1;
1255
+
1256
+ if (area.type === ValueType.array) {
1257
+
1258
+ rows = area.value.length;
1259
+ columns = area.value[0]?.length || 0;
1260
+
1261
+ const result: UnionValue[][] = [];
1262
+ for (let r = 0; r < rows; r++) {
1263
+ const row: UnionValue[] = [];
1264
+ for (let c = 0; c < columns; c++) {
1265
+ const src = area.value[r][c];
1266
+ if (src.type === ValueType.number) {
1267
+ let calc = 0;
1268
+ if (range > 0) {
1269
+ calc = (src.value - min) / range;
1270
+ }
1271
+ row.push({ type: ValueType.number, value: calc });
1272
+ }
1273
+ else {
1274
+ row.push({ type: ValueType.undefined });
1275
+ }
1276
+
1277
+ }
1278
+ result.push(row);
1279
+ }
1280
+
1281
+ return { type: ValueType.array, value: result };
1282
+
1283
+
1284
+ }
1285
+ else {
1286
+ return ArgumentError();
1287
+ }
1288
+
1289
+ },
1129
1290
  }
1130
1291
 
1131
1292
  };
@@ -19,9 +19,9 @@
19
19
  *
20
20
  */
21
21
 
22
- export * from './calculator';
23
- // export * from './pack-results';
24
-
25
- // for annotations that have dependencies
26
-
27
- export {LeafVertex} from './dag/leaf_vertex';
22
+ export * from './calculator';
23
+ // export * from './pack-results';
24
+
25
+ // for annotations that have dependencies
26
+
27
+ export type { LeafVertex } from './dag/graph';
@@ -19,7 +19,7 @@
19
19
  *
20
20
  */
21
21
 
22
- import type { LeafVertex } from './dag/leaf_vertex';
22
+ import type { LeafVertex } from './dag/graph';
23
23
  import type { Area } from 'treb-base-types';
24
24
 
25
25
  export interface NotifierType {
@@ -180,10 +180,10 @@ export const UndefinedToEmptyString = (args: any[]): any[] => {
180
180
  export const ApplyArrayFunc = (base: (...args: any[]) => any) => {
181
181
  return (a: any) => {
182
182
  if (Array.isArray(a)) {
183
- const tmp = [];
183
+ const tmp: any[] = [];
184
184
  const rows = a[0].length;
185
185
  for (let c = 0; c < a.length; c++) {
186
- const col = [];
186
+ const col: any[] = [];
187
187
  for (let r = 0; r < rows; r++) col[r] = base(a[c][r]);
188
188
  tmp.push(col);
189
189
  }
@@ -38,7 +38,7 @@ export class Util {
38
38
  * given a passed range, find the best scale range. count is just a
39
39
  * suggestion -- we try to get as close as possible.
40
40
  */
41
- public static Scale(min: number, max: number, count = 6.5): RangeScale {
41
+ public static Scale(min: number, max: number, count = 6.5, limit_count?: boolean, discrete?: boolean): RangeScale {
42
42
 
43
43
  /*
44
44
  const range = max - min;
@@ -71,7 +71,7 @@ export class Util {
71
71
 
72
72
  return { scale, step, count, min, max };
73
73
  */
74
- return Scale(min, max, count);
74
+ return Scale(min, max, count, limit_count, discrete);
75
75
 
76
76
  }
77
77