@trebco/treb 29.5.2 → 29.6.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /*! API v29.5. Copyright 2018-2024 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
1
+ /*! API v29.6. Copyright 2018-2024 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
2
 
3
3
  /**
4
4
  * add our tag to the map
@@ -388,8 +388,6 @@ export declare class EmbeddedSpreadsheet<USER_DATA_TYPE = unknown> {
388
388
  * Use this function to batch multiple document changes. Essentially the
389
389
  * grid stops broadcasting events for the duration of the function call,
390
390
  * and collects them instead. After the function call we update as necessary.
391
- *
392
- * @public
393
391
  */
394
392
  Batch(func: () => void, paint?: boolean): Promise<void>;
395
393
 
@@ -964,6 +962,38 @@ export declare class EmbeddedSpreadsheet<USER_DATA_TYPE = unknown> {
964
962
  */
965
963
  Select(range?: RangeReference): void;
966
964
 
965
+ /**
966
+ *
967
+ * @param target - the target to paste data into. this can be larger
968
+ * than the clipboard data, in which case values will be recycled in
969
+ * blocks. if the target is smaller than the source data, we will expand
970
+ * it.
971
+ *
972
+ * @param data - clipboard data to paste.
973
+ *
974
+ * @param style - optional paste style. default is to paste formulas and
975
+ * source formatting. paste options can be usef to paste values, values
976
+ * and number formats, or retain the target formatting.
977
+ */
978
+ Paste(target?: RangeReference, data?: ClipboardData | undefined, options?: PasteOptions): Promise<void>;
979
+
980
+ /**
981
+ * copy data. this method returns the copied data. it does not put it on
982
+ * the system clipboard. this is for API access when the system clipboard
983
+ * might not be available.
984
+ */
985
+ Copy(source?: RangeReference): ClipboardData;
986
+
987
+ /**
988
+ * cut data. this method returns the cut data. it does not put it on the
989
+ * system clipboard. this method is similar to the Copy method, with
990
+ * two differences: (1) we remove the source data, effectively clearing
991
+ * the source range; and (2) the clipboard data retains references, meaning
992
+ * if you paste the data in a different location it will refer to the same
993
+ * cells.
994
+ */
995
+ Cut(source?: RangeReference): ClipboardData;
996
+
967
997
  /**
968
998
  *
969
999
  * @param range target range. leave undefined to use current selection.
@@ -1004,6 +1034,50 @@ export declare class EmbeddedSpreadsheet<USER_DATA_TYPE = unknown> {
1004
1034
  Cancel(token: number): void;
1005
1035
  }
1006
1036
 
1037
+ /**
1038
+ * this is a structure for copy/paste data. clipboard data may include
1039
+ * relative formauls and resolved styles, so it's suitable for pasting into
1040
+ * other areas of the spreadsheet.
1041
+ */
1042
+ export interface ClipboardDataElement {
1043
+
1044
+ /** calculated cell value */
1045
+ calculated: CellValue;
1046
+
1047
+ /** the actual cell value or formula */
1048
+ value: CellValue;
1049
+
1050
+ /** cell style. this may include row/column styles from the copy source */
1051
+ style?: CellStyle;
1052
+ }
1053
+
1054
+ /** clipboard data is a 2d array */
1055
+ export type ClipboardData = ClipboardDataElement[][];
1056
+
1057
+ /**
1058
+ * optional paste options. we can paste formulas or values, and we
1059
+ * can use the source style, target style, or just use the source
1060
+ * number formats.
1061
+ */
1062
+ export interface PasteOptions {
1063
+
1064
+ /**
1065
+ * when clipboard data includes formulas, optionally paste calculated
1066
+ * values instead of the original formulas. defaults to false.
1067
+ */
1068
+ values?: boolean;
1069
+
1070
+ /**
1071
+ * when pasting data from the clipboard, we can copy formatting/style
1072
+ * from the original data, or we can retain the target range formatting
1073
+ * and just paste data. a third option allows pasting source number
1074
+ * formats but dropping other style information.
1075
+ *
1076
+ * defaults to "source", meaning paste source styles.
1077
+ */
1078
+ formatting?: 'source' | 'target' | 'number-formats';
1079
+ }
1080
+
1007
1081
  /**
1008
1082
  * options for saving files. we add the option for JSON formatting.
1009
1083
  */
@@ -1087,46 +1161,6 @@ export interface SheetScrollOptions {
1087
1161
  * function type used for filtering tables
1088
1162
  */
1089
1163
  export type TableFilterFunction = (value: CellValue, calculated_value: CellValue, style: CellStyle) => boolean;
1090
- export interface FreezePane {
1091
- rows: number;
1092
- columns: number;
1093
- }
1094
-
1095
- /**
1096
- * options for serializing data
1097
- */
1098
- export interface SerializeOptions {
1099
-
1100
- /** optimize for size */
1101
- optimize?: 'size' | 'speed';
1102
-
1103
- /** include the rendered/calculated value in export */
1104
- rendered_values?: boolean;
1105
-
1106
- /** translate colors to xlsx-friendly values */
1107
- export_colors?: boolean;
1108
-
1109
- /** export cells that have no value, but have a border or background color */
1110
- decorated_cells?: boolean;
1111
-
1112
- /** prune unused rows/columns */
1113
- shrink?: boolean;
1114
-
1115
- /**
1116
- * include tables. tables will be serialized in the model, so we can
1117
- * drop them from cells. but you can leave them in if that's useful.
1118
- */
1119
- tables?: boolean;
1120
-
1121
- /** share resources (images, for now) to prevent writing data URIs more than once */
1122
- share_resources?: boolean;
1123
-
1124
- /**
1125
- * if a function has an export() handler, call that
1126
- */
1127
- export_functions?: boolean;
1128
- }
1129
- export type AnnotationType = 'treb-chart' | 'image' | 'textbox' | 'external';
1130
1164
 
1131
1165
  /**
1132
1166
  * Structure represents a 2d range of cells.
@@ -1350,6 +1384,46 @@ export interface EvaluateOptions {
1350
1384
  */
1351
1385
  r1c1?: boolean;
1352
1386
  }
1387
+ export interface FreezePane {
1388
+ rows: number;
1389
+ columns: number;
1390
+ }
1391
+
1392
+ /**
1393
+ * options for serializing data
1394
+ */
1395
+ export interface SerializeOptions {
1396
+
1397
+ /** optimize for size */
1398
+ optimize?: 'size' | 'speed';
1399
+
1400
+ /** include the rendered/calculated value in export */
1401
+ rendered_values?: boolean;
1402
+
1403
+ /** translate colors to xlsx-friendly values */
1404
+ export_colors?: boolean;
1405
+
1406
+ /** export cells that have no value, but have a border or background color */
1407
+ decorated_cells?: boolean;
1408
+
1409
+ /** prune unused rows/columns */
1410
+ shrink?: boolean;
1411
+
1412
+ /**
1413
+ * include tables. tables will be serialized in the model, so we can
1414
+ * drop them from cells. but you can leave them in if that's useful.
1415
+ */
1416
+ tables?: boolean;
1417
+
1418
+ /** share resources (images, for now) to prevent writing data URIs more than once */
1419
+ share_resources?: boolean;
1420
+
1421
+ /**
1422
+ * if a function has an export() handler, call that
1423
+ */
1424
+ export_functions?: boolean;
1425
+ }
1426
+ export type AnnotationType = 'treb-chart' | 'image' | 'textbox' | 'external';
1353
1427
  export declare type BorderConstants = "none" | "all" | "outside" | "top" | "bottom" | "left" | "right";
1354
1428
 
1355
1429
  /**
@@ -1589,23 +1663,6 @@ export interface SelectionEvent {
1589
1663
  export interface FocusViewEvent {
1590
1664
  type: 'focus-view';
1591
1665
  }
1592
- export interface SerializedMacroFunction {
1593
- name: string;
1594
- function_def: string;
1595
- argument_names?: string[];
1596
- description?: string;
1597
- }
1598
-
1599
- /**
1600
- * this type is no longer in use, but we retain it to parse old documents
1601
- * that use it.
1602
- *
1603
- * @deprecated
1604
- */
1605
- export interface SerializedNamedExpression {
1606
- name: string;
1607
- expression: string;
1608
- }
1609
1666
 
1610
1667
  /**
1611
1668
  * serialized type is a composite of expression/range. we determine
@@ -1970,6 +2027,23 @@ export interface Corner {
1970
2027
  address: ICellAddress;
1971
2028
  offset: AddressOffset;
1972
2029
  }
2030
+ export interface SerializedMacroFunction {
2031
+ name: string;
2032
+ function_def: string;
2033
+ argument_names?: string[];
2034
+ description?: string;
2035
+ }
2036
+
2037
+ /**
2038
+ * this type is no longer in use, but we retain it to parse old documents
2039
+ * that use it.
2040
+ *
2041
+ * @deprecated
2042
+ */
2043
+ export interface SerializedNamedExpression {
2044
+ name: string;
2045
+ expression: string;
2046
+ }
1973
2047
 
1974
2048
  /**
1975
2049
  * options for exporting CSV/TSV
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "29.5.2",
3
+ "version": "29.6.2",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -147,7 +147,7 @@ export const MatrixFunctionLibrary: FunctionMap = {
147
147
  },
148
148
 
149
149
  MMult: {
150
- description: 'Returns the dot product of A and B',
150
+ description: 'Returns the dot product A B',
151
151
  arguments: [
152
152
  { name: 'A', boxed: true },
153
153
  { name: 'B', boxed: true },
@@ -21,34 +21,13 @@
21
21
 
22
22
  import type { Sheet } from './sheet';
23
23
  import { SheetCollection } from './sheet_collection';
24
+ import { type UnitAddress, type UnitStructuredReference, type UnitRange, Parser, QuotedSheetNameRegex, DecimalMarkType, ArgumentSeparatorType } from 'treb-parser';
24
25
  import type { IArea, ICellAddress, Table, CellStyle } from 'treb-base-types';
25
- import type { SerializedSheet } from './sheet_types';
26
- import { type ExpressionUnit, type UnitAddress, type UnitStructuredReference, type UnitRange, Parser, QuotedSheetNameRegex, DecimalMarkType, ArgumentSeparatorType } from 'treb-parser';
27
26
  import { Area, IsCellAddress, Style } from 'treb-base-types';
28
27
  import type { SerializedNamed } from './named';
29
28
  import { NamedRangeManager } from './named';
29
+ import type { ConnectedElementType, MacroFunction } from './types';
30
30
 
31
- export interface ConnectedElementType {
32
- formula: string;
33
- update?: (instance: ConnectedElementType) => void;
34
- internal?: unknown; // opaque type to prevent circular dependencies
35
- }
36
-
37
- export interface SerializedMacroFunction {
38
- name: string;
39
- function_def: string;
40
- argument_names?: string[];
41
- description?: string;
42
- }
43
-
44
- /**
45
- * we define this as extending the serialized version, rather
46
- * than taking out the parameter, so we can make that def public
47
- * in the API types.
48
- */
49
- export interface MacroFunction extends SerializedMacroFunction {
50
- expression?: ExpressionUnit;
51
- }
52
31
 
53
32
  /**
54
33
  *
@@ -546,43 +525,3 @@ export class DataModel {
546
525
 
547
526
  }
548
527
 
549
- /**
550
- * @internal
551
- */
552
- export interface ViewModel {
553
- active_sheet: Sheet;
554
- view_index: number;
555
- }
556
-
557
- /**
558
- * this type is no longer in use, but we retain it to parse old documents
559
- * that use it.
560
- *
561
- * @deprecated
562
- */
563
- export interface SerializedNamedExpression {
564
- name: string;
565
- expression: string;
566
- }
567
-
568
- export interface SerializedModel {
569
- sheet_data: SerializedSheet[];
570
- active_sheet: number;
571
-
572
- /** @deprecated */
573
- named_ranges?: Record<string, IArea>;
574
-
575
- /** @deprecated */
576
- named_expressions?: SerializedNamedExpression[];
577
-
578
- /**
579
- * new type for consolidated named ranges & expressions. the old
580
- * types are retained for backwards compatibility on import but we won't
581
- * export them anymore.
582
- */
583
- named?: SerializedNamed[];
584
-
585
- macro_functions?: MacroFunction[];
586
- tables?: Table[];
587
- decimal_mark?: ','|'.';
588
- }
@@ -20,16 +20,6 @@
20
20
  */
21
21
 
22
22
  export { DataModel } from './data_model';
23
-
24
- export type {
25
- MacroFunction,
26
- ConnectedElementType,
27
- SerializedNamedExpression,
28
- SerializedModel,
29
- ViewModel,
30
- SerializedMacroFunction,
31
- } from './data_model';
32
-
33
23
  export type { SerializedNamed } from './named';
34
24
 
35
25
  export { Sheet } from './sheet';
@@ -43,3 +33,5 @@ export type { ViewData as AnnotationViewData } from './annotation';
43
33
  export type { AnnotationData, AnnotationType } from './annotation';
44
34
 
45
35
  export * from './data-validation';
36
+ export * from './types';
37
+
@@ -74,4 +74,9 @@ export interface SerializeOptions {
74
74
  */
75
75
  export_functions?: boolean;
76
76
 
77
+ /**
78
+ * @internal
79
+ */
80
+ apply_row_pattern?: boolean;
81
+
77
82
  }
@@ -2519,8 +2519,6 @@ export class Sheet {
2519
2519
 
2520
2520
  // same here (note broken naming)
2521
2521
  const sheet_style = JSON.parse(JSON.stringify(this.sheet_style));
2522
- // const row_style = JSON.parse(JSON.stringify(this.row_styles));
2523
- // const column_style = JSON.parse(JSON.stringify(this.column_styles));
2524
2522
  const row_pattern = JSON.parse(JSON.stringify(this.row_pattern));
2525
2523
 
2526
2524
  // row and column styles are Record<number, props> and not arrays.
@@ -2545,13 +2543,36 @@ export class Sheet {
2545
2543
  }
2546
2544
  }
2547
2545
 
2548
- for (const key of Object.keys(this.row_styles)) {
2549
- const index = Number(key);
2550
- const style = this.row_styles[index];
2551
- if (style) {
2552
- const reference = StyleToRef(style);
2546
+ if (this.row_pattern && this.row_pattern.length && options.apply_row_pattern) {
2547
+
2548
+ let count = this.rows + 1;
2549
+
2550
+ for (const key of Object.keys(this.row_styles)) {
2551
+ const index = Number(key);
2552
+ if (!isNaN(index) && index >= count) { count = index + 1; }
2553
+ }
2554
+
2555
+ for (let i = 0; i< count; i++) {
2556
+ const pattern = this.row_pattern[i % this.row_pattern.length];
2557
+ const style = this.row_styles[i] || {};
2558
+ const composite = Style.Composite([pattern, style]);
2559
+ const reference = StyleToRef(composite);
2560
+
2553
2561
  if (reference) {
2554
- row_style[index] = reference;
2562
+ row_style[i] = reference;
2563
+ }
2564
+ }
2565
+
2566
+ }
2567
+ else {
2568
+ for (const key of Object.keys(this.row_styles)) {
2569
+ const index = Number(key);
2570
+ const style = this.row_styles[index];
2571
+ if (style) {
2572
+ const reference = StyleToRef(style);
2573
+ if (reference) {
2574
+ row_style[index] = reference;
2575
+ }
2555
2576
  }
2556
2577
  }
2557
2578
  }
@@ -0,0 +1,71 @@
1
+
2
+ import type { SerializedSheet } from './sheet_types';
3
+ import type { Sheet } from './sheet';
4
+ import type { IArea } from 'treb-base-types';
5
+ import type { SerializedNamed } from './named';
6
+ import type { Table } from 'treb-base-types';
7
+ import type { ExpressionUnit } from 'treb-parser';
8
+
9
+ export interface ConnectedElementType {
10
+ formula: string;
11
+ update?: (instance: ConnectedElementType) => void;
12
+ internal?: unknown; // opaque type to prevent circular dependencies
13
+ }
14
+
15
+ export interface SerializedMacroFunction {
16
+ name: string;
17
+ function_def: string;
18
+ argument_names?: string[];
19
+ description?: string;
20
+ }
21
+
22
+ /**
23
+ * we define this as extending the serialized version, rather
24
+ * than taking out the parameter, so we can make that def public
25
+ * in the API types.
26
+ */
27
+ export interface MacroFunction extends SerializedMacroFunction {
28
+ expression?: ExpressionUnit;
29
+ }
30
+
31
+ /**
32
+ * @internal
33
+ */
34
+ export interface ViewModel {
35
+ active_sheet: Sheet;
36
+ view_index: number;
37
+ }
38
+
39
+ /**
40
+ * this type is no longer in use, but we retain it to parse old documents
41
+ * that use it.
42
+ *
43
+ * @deprecated
44
+ */
45
+ export interface SerializedNamedExpression {
46
+ name: string;
47
+ expression: string;
48
+ }
49
+
50
+ export interface SerializedModel {
51
+ sheet_data: SerializedSheet[];
52
+ active_sheet: number;
53
+
54
+ /** @deprecated */
55
+ named_ranges?: Record<string, IArea>;
56
+
57
+ /** @deprecated */
58
+ named_expressions?: SerializedNamedExpression[];
59
+
60
+ /**
61
+ * new type for consolidated named ranges & expressions. the old
62
+ * types are retained for backwards compatibility on import but we won't
63
+ * export them anymore.
64
+ */
65
+ named?: SerializedNamed[];
66
+
67
+ macro_functions?: MacroFunction[];
68
+ tables?: Table[];
69
+ decimal_mark?: ','|'.';
70
+ }
71
+