@trebco/treb 31.9.1 → 32.3.1

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 (35) hide show
  1. package/dist/treb-spreadsheet.mjs +15 -15
  2. package/i18n/languages/treb-i18n-da.mjs +1 -0
  3. package/i18n/languages/treb-i18n-de.mjs +1 -0
  4. package/i18n/languages/treb-i18n-es.mjs +1 -0
  5. package/i18n/languages/treb-i18n-fr.mjs +1 -0
  6. package/i18n/languages/treb-i18n-it.mjs +1 -0
  7. package/i18n/languages/treb-i18n-nl.mjs +1 -0
  8. package/i18n/languages/treb-i18n-no.mjs +1 -0
  9. package/i18n/languages/treb-i18n-pl.mjs +1 -0
  10. package/i18n/languages/treb-i18n-pt.mjs +1 -0
  11. package/i18n/languages/treb-i18n-sv.mjs +1 -0
  12. package/package.json +1 -1
  13. package/treb-base-types/src/style.ts +20 -0
  14. package/treb-base-types/src/union.ts +6 -0
  15. package/treb-base-types/src/value-type.ts +13 -0
  16. package/treb-calculator/src/calculator.ts +20 -1
  17. package/treb-calculator/src/descriptors.ts +49 -4
  18. package/treb-calculator/src/expression-calculator.ts +263 -12
  19. package/treb-calculator/src/functions/base-functions.ts +49 -0
  20. package/treb-calculator/src/functions/fp.ts +339 -0
  21. package/treb-calculator/src/functions/gamma.ts +143 -0
  22. package/treb-calculator/src/functions/lambda-functions.ts +96 -0
  23. package/treb-calculator/src/functions/statistics-functions.ts +88 -0
  24. package/treb-data-model/src/data_model.ts +28 -13
  25. package/treb-data-model/src/named.ts +7 -0
  26. package/treb-data-model/src/sheet.ts +19 -2
  27. package/treb-embed/src/embedded-spreadsheet.ts +22 -5
  28. package/treb-embed/style/theme-defaults.scss +0 -22
  29. package/treb-grid/src/editors/editor.ts +14 -0
  30. package/treb-grid/src/types/grid.ts +74 -28
  31. package/treb-parser/src/parser-types.ts +24 -0
  32. package/treb-parser/src/parser.ts +157 -223
  33. package/dist/treb-export-worker.mjs +0 -2
  34. package/dist/treb.d.ts +0 -2235
  35. package/treb-calculator/tsconfig.json +0 -7
package/dist/treb.d.ts DELETED
@@ -1,2235 +0,0 @@
1
- /*! API v31.9. Copyright 2018-2024 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
-
3
- /**
4
- * add our tag to the map
5
- */
6
- declare global {
7
- interface HTMLElementTagNameMap {
8
- 'treb-spreadsheet': HTMLElement & {
9
- instance: {
10
- sheet: EmbeddedSpreadsheet | undefined;
11
- } | undefined;
12
- };
13
- }
14
- }
15
- /**
16
- * API class for creating spreadsheets. this is intended as a singleton,
17
- * we will export an instance of the class.
18
- */
19
- export declare class TREBGlobal {
20
-
21
- /**
22
- * Package version
23
- */
24
- version: string;
25
-
26
- /**
27
- * Create a spreadsheet. The `USER_DATA_TYPE` template parameter is the type
28
- * assigned to the `user_data` field of the spreadsheet instance -- it can
29
- * help simplify typing if you are storing extra data in spreadsheet
30
- * files.
31
- *
32
- * Just ignore this parameter if you don't need it.
33
- *
34
- * @typeParam USER_DATA_TYPE - type for the `user_data` field in the
35
- * spreadsheet instance
36
- */
37
- CreateSpreadsheet<USER_DATA_TYPE = unknown>(options: EmbeddedSpreadsheetOptions): EmbeddedSpreadsheet<USER_DATA_TYPE>;
38
- }
39
-
40
- /** single instance of factory class */
41
- export declare const TREB: TREBGlobal;
42
-
43
- /**
44
- * options for creating spreadsheet
45
- */
46
- export interface EmbeddedSpreadsheetOptions {
47
-
48
- /** containing HTML element */
49
- container?: string | HTMLElement;
50
-
51
- /** allow drag-and-drop files */
52
- dnd?: boolean;
53
-
54
- /**
55
- * expandable grid. if this option is false, the grid will always
56
- * stay the same size -- if you keep pressing down arrow, it won't
57
- * grow. defaults to true.
58
- */
59
- expand?: boolean;
60
-
61
- /**
62
- * key in localStorage for persisting document.
63
- * @deprecated - this was renamed to local_storage for clarity. if both
64
- * storage_key and local_storage are set we will use the value in local_storage.
65
- */
66
- storage_key?: string | boolean;
67
-
68
- /**
69
- * persist user changes to document in browser localStorage.
70
- *
71
- * if set to a string, the value is used as the storage key.
72
- *
73
- * if set to `true`, we will generate a storage key based on the page URI.
74
- * don't do that if you have multiple spreadsheets on a single page, or
75
- * they will overwrite each other.
76
- */
77
- local_storage?: string | boolean;
78
-
79
- /** don't load immediately (?) */
80
- toll_initial_load?: boolean;
81
-
82
- /** show formula bar. default true. */
83
- formula_bar?: boolean;
84
-
85
- /** expand formula bar */
86
- expand_formula_button?: boolean;
87
-
88
- /** scroll to cell on load */
89
- scroll?: string | ICellAddress;
90
-
91
- /** sheet to show on load, overrides anything in the model */
92
- sheet?: string;
93
-
94
- /** add resizable wrapper */
95
- resizable?: boolean;
96
-
97
- /** even if we allow resizing, constrain width. this is to support fixed width columns. */
98
- constrain_width?: boolean;
99
-
100
- /** export to xlsx, now optional */
101
- export?: boolean;
102
-
103
- /**
104
- * fetch network document. this is a replacement for the old
105
- * (deprecated) option `network_document`.
106
- */
107
- document?: string;
108
-
109
- /**
110
- * fetch network document (URI)
111
- * @deprecated - use `document`
112
- */
113
- network_document?: string;
114
-
115
- /** freeze rows */
116
- freeze_rows?: number;
117
-
118
- /** freeze columns */
119
- freeze_columns?: number;
120
-
121
- /** row/column headers */
122
- headers?: boolean;
123
-
124
- /** recalculate on load */
125
- recalculate?: boolean;
126
-
127
- /** show scrollbars */
128
- scrollbars?: boolean;
129
-
130
- /** show tab bar (multi sheet) */
131
- tab_bar?: boolean | 'auto';
132
-
133
- /**
134
- * allow add/delete tab
135
- */
136
- add_tab?: boolean;
137
-
138
- /**
139
- * show delete tab
140
- * @deprecated - implied by add_tab
141
- */
142
- delete_tab?: boolean;
143
-
144
- /** set a reference in global (self) */
145
- global_name?: string;
146
-
147
- /** support undo */
148
- undo?: boolean;
149
-
150
- /** support in-cell editor */
151
- in_cell_editor?: boolean;
152
-
153
- /** prompt "you have unsaved changes" */
154
- prompt_save?: boolean;
155
-
156
- /**
157
- * toolbar display option. true or false means include/don't include
158
- * the toolbar (and the toolbar button). setting to "narrow" means
159
- * include the toolbar, but use a narrow version (it compresses the
160
- * align/justify groups).
161
- *
162
- * the toolbar usually starts hidden. if you set this option to "show",
163
- * it will start visible. same for "show-narrow".
164
- */
165
- toolbar?: boolean | 'show' | 'narrow' | 'show-narrow';
166
-
167
- /** include the file menu in the toolbar */
168
- file_menu?: boolean;
169
-
170
- /** include the font scale control in the toolbar */
171
- font_scale?: boolean;
172
-
173
- /** include the font stack control in the toolbar */
174
- font_stack?: boolean;
175
-
176
- /** include the insert/remove table button in the toolbar */
177
- table_button?: boolean;
178
-
179
- /** include the freeze button in the toolbar */
180
- freeze_button?: boolean;
181
-
182
- /** include the chart menu in the toolbar */
183
- chart_menu?: boolean;
184
-
185
- /** include a recalculate button in the toolbar */
186
- toolbar_recalculate_button?: boolean;
187
-
188
- /** better support for headless operations (default false) */
189
- headless?: boolean;
190
-
191
- /** max size for image, in bytes */
192
- max_file_size?: number;
193
-
194
- /** initial scale */
195
- scale?: number;
196
-
197
- /**
198
- * show scale control (slider) under the spreadsheet.
199
- */
200
- scale_control?: boolean;
201
-
202
- /**
203
- * show the stats panel under the spreadsheet.
204
- */
205
- stats?: boolean;
206
-
207
- /**
208
- * save/load scale. this can optionally have a string key to disambiguate
209
- */
210
- persist_scale?: boolean | string;
211
-
212
- /**
213
- * target window for hyperlinks (default _blank); set false to disable hyperlinks altogether
214
- */
215
- hyperlinks?: string | false;
216
-
217
- /**
218
- * enable handling complex numbers in function calculation. turning this
219
- * off doesn't actually disable complex numbers. it means that functions
220
- * will not return complex numbers unless one of the arguments is complex.
221
- * @see https://docs.treb.app/en/complex-numbers
222
- *
223
- * in version 25, complex defaults to `off`.
224
- */
225
- complex?: 'on' | 'off';
226
-
227
- /**
228
- * for rendering the imaginary number. this is intended to support
229
- * switching to a different character for rendering, or adding a leading
230
- * space/half-space/hair-space.
231
- *
232
- * this _does_not_ change how you enter imaginary numbers, you still have
233
- * to use `i` (lower-case ascii i).
234
- */
235
- imaginary_value?: string;
236
-
237
- /**
238
- * support markdown formatting for text in cells and comments. at the
239
- * moment we only support bold, italic, and strike text.
240
- */
241
- markdown?: boolean;
242
-
243
- /**
244
- * show tinted colors in toolbar color dropdowns. as of version 25
245
- * this defaults to true (used to be false).
246
- */
247
- tint_theme_colors?: boolean;
248
-
249
- /**
250
- * show a spinner for long-running operations
251
- */
252
- spinner?: boolean;
253
-
254
- /**
255
- * start with sidebar closed. defaults to false.
256
- */
257
- collapsed?: boolean;
258
-
259
- /**
260
- * show the revert button in the sidebar. see the `Revert` method. this
261
- * was renamed from `revert` to avoid any ambiguity.
262
- */
263
- revert_button?: boolean;
264
-
265
- /**
266
- * show the revert indicator. this is an indicator that shows on the
267
- * top-left of the spreadsheet when a network document has local changes.
268
- */
269
- revert_indicator?: boolean;
270
-
271
- /**
272
- * handle the F9 key and recalculate the spreadsheet. for compatibility.
273
- * we're leaving this option to default `false` for now, but that may
274
- * change in the future. key modifiers have no effect.
275
- */
276
- recalculate_on_f9?: boolean;
277
-
278
- /**
279
- * indent/outdent buttons; default false
280
- */
281
- indent_buttons?: boolean;
282
-
283
- /**
284
- * enable spill arrays and spill references. this is on by default
285
- * starting in 30.1.0. set to false to disable.
286
- */
287
- spill?: boolean;
288
-
289
- /**
290
- * language. at the moment this controls spreadsheet function names
291
- * only; the plan is to expand to the rest of the interface over time.
292
- * should be an ISO 639-1 language code, like "en", "fr" or "sv" (case
293
- * insensitive). we only support a limited subset of languages at the
294
- * moment.
295
- *
296
- * leave blank or set to "locale" to use the current locale.
297
- */
298
- language?: string;
299
- }
300
-
301
- /**
302
- * Structure represents a cell address. Note that row and column are 0-based.
303
- */
304
- export interface ICellAddress {
305
-
306
- /** 0-based row */
307
- row: number;
308
-
309
- /** 0-based column */
310
- column: number;
311
- absolute_row?: boolean;
312
- absolute_column?: boolean;
313
- sheet_id?: number;
314
-
315
- /** spill reference */
316
- spill?: boolean;
317
- }
318
-
319
- /**
320
- * embedded spreadsheet
321
- */
322
- export declare class EmbeddedSpreadsheet<USER_DATA_TYPE = unknown> {
323
-
324
- /**
325
- * convenience function returns the name of the active sheet. if the
326
- * sheet name has spaces or other characters that require quoting, it
327
- * will be quoted using single quotes.
328
- */
329
- get active_sheet(): string;
330
-
331
- /** document name (metadata) */
332
- get document_name(): string | undefined;
333
-
334
- /** document name (metadata) */
335
- set document_name(name: string | undefined);
336
-
337
- /**
338
- * opaque user data (metadata). `USER_DATA_TYPE` is a template
339
- * parameter you can set when creating the spreadsheet.
340
- */
341
- get user_data(): USER_DATA_TYPE | undefined;
342
-
343
- /**
344
- * opaque user data (metadata). `USER_DATA_TYPE` is a template
345
- * parameter you can set when creating the spreadsheet.
346
- */
347
- set user_data(data: USER_DATA_TYPE | undefined);
348
-
349
- /** current grid scale */
350
- get scale(): number;
351
-
352
- /** current grid scale */
353
- set scale(value: number);
354
-
355
- /** headless state */
356
- get headless(): boolean;
357
-
358
- /** headless state */
359
- set headless(value: boolean);
360
-
361
- /**
362
- * state is the current revision of the document. it is preserved any
363
- * time the document is saved. it should be a consistent indication of
364
- * the document version and can be used to compare versions.
365
- *
366
- * state is an atomically-incrementing integer but rolls over at 2^16.
367
- */
368
- get state(): number;
369
-
370
- /**
371
- * this flag indicates we can revert the document. what that means is
372
- * we loaded a user-created version from localStorage, but there's a
373
- * backing network or inline document. or we did load the original version
374
- * but the user has made some document changes.
375
- *
376
- * it's like `dirty`, but that uses the load source as the ground truth,
377
- * which means if you load a modified document from localStorage it's
378
- * initially considered not-dirty (which is maybe just a bad design?)
379
- *
380
- * the intent of this field is to support enabling/disabling revert
381
- * logic, or to add a visual indicator that you are not looking at the
382
- * canonical version.
383
- */
384
- get can_revert(): boolean;
385
-
386
- /**
387
- * indicates the current revision of the document is not equal to the
388
- * last-saved revision of the document.
389
- */
390
- get dirty(): boolean;
391
-
392
- /**
393
- * explicitly set or clear the dirty flag. it's intended for use by clients
394
- * that have their own save routine.
395
- */
396
- set dirty(value: boolean);
397
-
398
- /**
399
- * returns the names of all sheets in the current document
400
- */
401
- get sheet_names(): string[];
402
-
403
- /**
404
- * set or remove an external editor. external editor is an interface used
405
- * to support outside tooling by highlighting a list of arguments and
406
- * responding to selection.
407
- */
408
- ExternalEditor(config?: Partial<ExternalEditorConfig>): void;
409
-
410
- /**
411
- * @internalRemarks removing internal flag
412
- */
413
- ConditionalFormatDuplicateValues(range: RangeReference | undefined, options: ConditionalFormatDuplicateValuesOptions): ConditionalFormat;
414
-
415
- /**
416
- * @internalRemarks removing internal flag
417
- */
418
- ConditionalFormatGradient(range: RangeReference | undefined, options: ConditionalFormatGradientOptions | StandardGradient): ConditionalFormat;
419
-
420
- /**
421
- * @internalRemarks removing internal flag
422
- */
423
- ConditionalFormatCellMatch(range: RangeReference | undefined, options: ConditionalFormatCellMatchOptions): ConditionalFormat;
424
-
425
- /**
426
- * @internalRemarks removing internal flag
427
- */
428
- ConditionalFormatExpression(range: RangeReference | undefined, options: CondifionalFormatExpressionOptions): ConditionalFormat;
429
-
430
- /**
431
- * remove conditional format
432
- *
433
- * @internalRemarks removing internal flag
434
- */
435
- RemoveConditionalFormat(format: ConditionalFormat): void;
436
-
437
- /**
438
- * clear conditional formats from the target range (or currently selected
439
- * range). we operate on format objects, meaning we'll remove the whole
440
- * format object rather than clip the area.
441
- *
442
- * @internalRemarks removing internal flag
443
- */
444
- RemoveConditionalFormats(range?: RangeReference): void;
445
-
446
- /** dynamically load language module */
447
- LoadLanguage(language?: string): Promise<void>;
448
-
449
- /**
450
- * Use this function to batch multiple document changes. Essentially the
451
- * grid stops broadcasting events for the duration of the function call,
452
- * and collects them instead. After the function call we update as necessary.
453
- */
454
- Batch(func: () => void, paint?: boolean): void;
455
-
456
- /** set freeze area */
457
- Freeze(rows?: number, columns?: number): void;
458
-
459
- /** freeze at current selection */
460
- FreezeSelection(): void;
461
-
462
- /** return current freeze area */
463
- GetFreeze(): FreezePane;
464
-
465
- /**
466
- * Update theme from CSS. Because the spreadsheet is painted, not
467
- * rendered, you need to notifiy us if external style (CSS) properties
468
- * have changed. We will update and repaint.
469
- */
470
- UpdateTheme(): void;
471
-
472
- /**
473
- * Get sheet ID, by name (sheet name) or index. This may be useful for
474
- * constructing references programatically.
475
- *
476
- * @remarks
477
- *
478
- * Sheet IDs are positive integers. IDs are ephemeral, they should not be
479
- * retained after a document is closed or reloaded. They will likely (almost)
480
- * always be the same, but that's not guaranteed, so don't rely on them.
481
- *
482
- * @param sheet - sheet name or index. sheet names are matched case-insensitively.
483
- *
484
- * @returns ID, or undefined if the index is not found (0 is not a valid
485
- * sheet ID, so you can test for falsy).
486
- *
487
- * @public
488
- */
489
- GetSheetID(sheet: string | number): number | undefined;
490
-
491
- /**
492
- * insert a table in the given range. optionally include a totals row.
493
- * this method does not make any changes to content or layout. it just
494
- * converts the range to a table.
495
- *
496
- * @param reference
497
- */
498
- InsertTable(range?: RangeReference, options?: InsertTableOptions): void;
499
- RemoveTable(range?: RangeReference): void;
500
- UpdateTableStyle(range?: RangeReference, theme?: TableTheme | number): void;
501
- SetTabColor(sheet?: number | string, color?: Color): void;
502
-
503
- /**
504
- * Add a sheet, optionally named.
505
- */
506
- AddSheet(name?: string): number;
507
- RemoveConnectedChart(id: number): void;
508
- UpdateConnectedChart(id: number, formula: string): void;
509
-
510
- /**
511
- * Insert an annotation node. Usually this means inserting a chart. Regarding
512
- * the argument separator, see the Evaluate function.
513
- *
514
- * @param formula - annotation formula. For charts, the chart formula.
515
- * @param type - annotation type. Defaults to `treb-chart`.
516
- * @param rect - coordinates, or a range reference for layout.
517
- * @param options - evaluate options. because this function used to take
518
- * the argument separator, we allow that to be passed directly, but this
519
- * is deprecated. new code should use the options object.
520
- */
521
- InsertAnnotation(formula: string, type?: AnnotationType, rect?: IRectangle | RangeReference, options?: EvaluateOptions | ',' | ';'): void;
522
-
523
- /**
524
- * Insert an image. This method will open a file chooser and (if an image
525
- * is selected) insert the image into the document.
526
- */
527
- InsertImage(): void;
528
-
529
- /**
530
- * Rename a sheet.
531
- *
532
- * @param index - old name or index of sheet. leave undefined to use
533
- * current active sheet.
534
- *
535
- * @public
536
- */
537
- RenameSheet(index: string | number | undefined, new_name: string): void;
538
-
539
- /**
540
- * Delete a sheet.
541
- *
542
- * @param index - sheet name or index. Leave undefined to delete the active sheet.
543
- *
544
- * @public
545
- */
546
- DeleteSheet(index?: string | number): void;
547
-
548
- /**
549
- * Show or hide sheet. This is a replacement for the `ShowSheet` method,
550
- * because that name is somewhat ambiguous.
551
- *
552
- * @param index - sheet name or index.
553
- *
554
- * @public
555
- */
556
- HideSheet(index?: number | string, hide?: boolean): void;
557
-
558
- /** list sheets in the model */
559
- ListSheets(): {
560
- name: string;
561
- hidden?: boolean;
562
- }[];
563
-
564
- /**
565
- * Show or hide sheet. This method is deprecated because it's ambiguous.
566
- * To set a sheet's visibility, use `HideSheet`. To activate a sheet, use
567
- * `ActivateSheet`.
568
- *
569
- * @param index - sheet name or index.
570
- *
571
- * @see HideSheet
572
- * @deprecated Use `HideSheet` instead.
573
- */
574
- ShowSheet(index?: number | string, show?: boolean): void;
575
-
576
- /**
577
- * Activate sheet.
578
- *
579
- * @param index - sheet name or index.
580
- *
581
- * @public
582
- */
583
- ActivateSheet(index: number | string): void;
584
-
585
- /**
586
- * Set width of column(s).
587
- *
588
- * @param column - column, or columns (array), or undefined means all columns
589
- * @param width - desired width (can be 0) or undefined means 'auto-size'
590
- *
591
- * @public
592
- */
593
- SetColumnWidth(column?: number | number[], width?: number): void;
594
-
595
- /**
596
- * Set height of row(s).
597
- *
598
- * @param row - row, or rows (array), or undefined means all rows
599
- * @param height - desired height (can be 0) or undefined means 'auto-size'
600
- *
601
- * @public
602
- */
603
- SetRowHeight(row?: number | number[], height?: number): void;
604
-
605
- /**
606
- * Insert row(s).
607
- *
608
- * @param before_row - leave undefined to use current selection.
609
- *
610
- * @public
611
- */
612
- InsertRows(before_row?: number, count?: number): void;
613
-
614
- /**
615
- * Insert column(s).
616
- *
617
- * @param before_column - leave undefined to use current selection.
618
- *
619
- * @public
620
- */
621
- InsertColumns(before_column?: number, count?: number): void;
622
-
623
- /**
624
- * Delete row(s).
625
- *
626
- * @param start_row - leave undefined to use current selection. in this
627
- * case the `count` parameter will be ignored and all rows in the selection
628
- * will be deleted.
629
- */
630
- DeleteRows(start_row?: number, count?: number): void;
631
-
632
- /**
633
- * Delete columns(s).
634
- *
635
- * @param start_column - leave undefined to use current selection. in this
636
- * case the `count` parameter will be ignored and all columns in the
637
- * selection will be deleted.
638
- */
639
- DeleteColumns(start_column?: number, count?: number): void;
640
-
641
- /**
642
- * filter a table. the reference can be the table name, or a cell in the table.
643
- * if the reference is an area (range), we're going to look at the top-left
644
- * cell.
645
- *
646
- * this method uses a function to filter rows based on cell values. leave the
647
- * function undefined to show all rows. this is a shortcut for "unfilter".
648
- *
649
- * @param column - the column to sort on. values from this column will be
650
- * passed to the filter function.
651
- *
652
- * @param filter - a callback function to filter based on cell values. this
653
- * will be called with the cell value (formula), the calculated value (if any),
654
- * and the cell style. return false to hide the row, and true to show the row.
655
- * if the filter parameter is omitted, all values will be shown.
656
- *
657
- */
658
- FilterTable(reference: RangeReference, column?: number, filter?: TableFilterFunction): void;
659
-
660
- /**
661
- * sort a table. the reference can be the table name, or a cell in the table.
662
- * if the reference is an area (range), we're going to look at the top-left
663
- * cell.
664
- */
665
- SortTable(reference: RangeReference, options?: Partial<TableSortOptions>): void;
666
-
667
- /**
668
- * Merge cells in range.
669
- *
670
- * @param range - target range. leave undefined to use current selection.
671
- *
672
- * @public
673
- */
674
- MergeCells(range?: RangeReference): void;
675
-
676
- /**
677
- * Unmerge cells in range.
678
- *
679
- * @param range - target range. leave undefined to use current selection.
680
- *
681
- * @public
682
- */
683
- UnmergeCells(range?: RangeReference): void;
684
-
685
- /**
686
- * revert to the network version of this document, if `local_storage`
687
- * is set and the create options had either `document` or `inline-document`
688
- * set.
689
- *
690
- * FIXME: we should adjust for documents that fail to load.
691
- */
692
- Revert(): void;
693
-
694
- /**
695
- * Export to XLSX file.
696
- *
697
- * @remarks
698
- *
699
- * this requires a bunch of processing -- one, we do this in a worker, and
700
- * two, it's demand loaded so we don't bloat up this embed script.
701
- */
702
- Export(): void;
703
-
704
- /**
705
- * Focus the grid.
706
- *
707
- * @public
708
- */
709
- Focus(): void;
710
-
711
- /**
712
- * Update layout and repaint if necessary.
713
- *
714
- * @remarks
715
- *
716
- * This method should be called when the container is resized, to
717
- * trigger an update to layout. It should be called automatically
718
- * by a resize observer set in the containing tag class, but you
719
- * can call it manually if necessary.
720
- *
721
- * @public
722
- */
723
- Resize(): void;
724
-
725
- /**
726
- * Clear/reset sheet. This will reset the undo stack as well,
727
- * so it cannot be undone.
728
- *
729
- * @public
730
- */
731
- Reset(): void;
732
-
733
- /**
734
- * load a document from from local storage, using the given key.
735
- * this method will also set the local option for the storage key, so the
736
- * document will potentially be saved on modification.
737
- */
738
- LoadFromLocalStorage(key: string): boolean;
739
-
740
- /**
741
- * load a network document by URI. CORS headers must be set appropriately
742
- * on documents originating from different hosts.
743
- */
744
- LoadNetworkDocument(uri: string, options?: EmbeddedSpreadsheetOptions): Promise<void>;
745
-
746
- /**
747
- * Load a desktop file. This method will show a file chooser and open
748
- * the selected file (if any).
749
- *
750
- * @public
751
- */
752
- LoadLocalFile(): Promise<void>;
753
-
754
- /**
755
- * Export sheet as CSV/TSV. This is an internal method called by the save
756
- * document methods, but you can call it directly if you want the text as
757
- * a string.
758
- *
759
- * @returns string
760
- *
761
- * @public
762
- */
763
- ExportDelimited(options?: ExportOptions): string;
764
-
765
- /**
766
- * @deprecated - use SaveToDesktop
767
- *
768
- * @param filename
769
- * @param additional_options
770
- */
771
- SaveLocalFile(filename?: string, additional_options?: SaveOptions): void;
772
-
773
- /**
774
- * Save the current document to a desktop file. This is the new version
775
- * of the method, renamed from SaveLocalFile.
776
- *
777
- * @param filename Filename or extension to use the document name.
778
- */
779
- SaveToDesktop(filename?: string, additional_options?: SaveOptions): void;
780
-
781
- /**
782
- * Load CSV from string. This is used internally when loading network
783
- * documents and local files, but you can call it directly if you have
784
- * a CSV file as text.
785
- *
786
- * @public
787
- */
788
- LoadCSV(csv: string, source?: LoadSource): void;
789
-
790
- /**
791
- * get or set the current scroll offset. scroll offset is automatically
792
- * saved if you save the document or switch tabs; this is for saving/
793
- * restoring scroll if you cache the containing element.
794
- */
795
- ScrollOffset(offset?: Point): Point | undefined;
796
-
797
- /**
798
- * unserialize document from data.
799
- */
800
- LoadDocument(data: TREBDocument, options?: LoadDocumentOptions): void;
801
-
802
- /**
803
- * Set note (comment) in cell.
804
- *
805
- * @param address target address, or leave undefined to use current selection.
806
- * @param note note text, or leave undefined to clear existing note.
807
- */
808
- SetNote(address: AddressReference | undefined, note?: string): void;
809
-
810
- /**
811
- * set or clear cell valiation.
812
- *
813
- * @param target - target cell/area
814
- * @param validation - a spreadsheet range, list of data, or undefined. pass
815
- * undefined to remove existing cell validation.
816
- * @param error - setting an invalid value in the target cell is an error (and
817
- * is blocked). defaults to false.
818
- */
819
- SetValidation(target: RangeReference, validation?: RangeReference | CellValue[], error?: boolean): void;
820
-
821
- /**
822
- * Delete a macro function.
823
- *
824
- * @public
825
- */
826
- RemoveFunction(name: string): void;
827
-
828
- /**
829
- * Create a macro function.
830
- *
831
- * FIXME: this needs a control for argument separator, like other
832
- * functions that use formulas (@see SetRange)
833
- *
834
- * @public
835
- */
836
- DefineFunction(name: string, argument_names?: string | string[], function_def?: string): void;
837
-
838
- /**
839
- * Serialize document to a plain javascript object. The result is suitable
840
- * for converting to JSON. This method is used by the SaveLocalFile and
841
- * SaveLocalStorage methods, but you can call it directly if you want to
842
- * save the document some other way.
843
- *
844
- * @public
845
- */
846
- SerializeDocument(options?: SerializeOptions): TREBDocument;
847
-
848
- /**
849
- * Recalculate sheet.
850
- *
851
- * @public
852
- */
853
- Recalculate(): void;
854
-
855
- /**
856
- * Save document to local storage.
857
- *
858
- * @param key optional storage key. if omitted, the method will use
859
- * the key from local options (set at create time).
860
- */
861
- SaveLocalStorage(key?: string | undefined): void;
862
-
863
- /**
864
- * Revert state one level from the undo stack.
865
- *
866
- * @public
867
- */
868
- Undo(): void;
869
-
870
- /**
871
- * Show the about dialog.
872
- *
873
- * @public
874
- */
875
- About(): void;
876
-
877
- /**
878
- * scroll the given address into view. it could be at either side
879
- * of the window. optionally use smooth scrolling.
880
- */
881
- ScrollIntoView(address: AddressReference, smooth?: boolean): void;
882
-
883
- /**
884
- * Scroll to the given address. In the current implementation this method
885
- * will not change sheets, although it probably should if the reference
886
- * is to a different sheet.
887
- *
888
- * @public
889
- */
890
- ScrollTo(address: AddressReference, options?: SheetScrollOptions): void;
891
-
892
- /**
893
- * Resolve a string address/range to an address or area (range) object.
894
- *
895
- * @param reference A string like "A1" or "Sheet1!B2:C3". If a sheet name
896
- * is not included, the current active sheet is used. You can also pass a
897
- * named range as reference.
898
- *
899
- * @public
900
- */
901
- Resolve(reference: string): ICellAddress | IArea | undefined;
902
-
903
- /**
904
- * Convert an address/range object to a string. this is a convenience
905
- * function for composing formulas.
906
- *
907
- * @param ref sheet reference as a string or structured object
908
- * @param [qualified=true] include sheet names
909
- * @param [named=true] resolve to named ranges, where applicable
910
- */
911
- Unresolve(ref: RangeReference, qualified?: boolean, named?: boolean): string;
912
-
913
- /**
914
- * Evaluate an arbitrary expression in the spreadsheet. You should generally
915
- * use sheet names when referring to cells, to avoid ambiguity. Otherwise
916
- * cell references will resolve to the active sheet.
917
- *
918
- * @param expression - an expression in spreadsheet language
919
- * @param options - options for parsing the passed function
920
- *
921
- * @public
922
- */
923
- Evaluate(expression: string, options?: EvaluateOptions): CellValue | CellValue[][];
924
-
925
- /**
926
- * Returns the current selection, as a string address or range.
927
- *
928
- * @param qualified include sheet name in result. default true.
929
- *
930
- * @returns selection as a string, or empty string if there's no selection.
931
- *
932
- * @public
933
- */
934
- GetSelection(qualified?: boolean): string;
935
-
936
- /**
937
- * Parse a string and return a number (if possible).
938
- *
939
- * @public
940
- */
941
- ParseNumber(text: string): number | Complex | boolean | string | undefined;
942
-
943
- /**
944
- * Format a number with an arbitrary formatter.
945
- *
946
- * @public
947
- */
948
- FormatNumber(value: number | Complex, format?: string): string;
949
-
950
- /**
951
- * convert a javascript date (or timestamp) to a spreadsheet date
952
- */
953
- SpreadsheetDate(javascript_date: number | Date): number;
954
-
955
- /**
956
- * convert a spreadsheet date to a javascript date
957
- */
958
- JavascriptDate(spreadsheet_date: number): number;
959
-
960
- /**
961
- * Apply borders to range.
962
- *
963
- * @param range pass `undefined` as range to apply to current selection.
964
- *
965
- * @remarks
966
- *
967
- * Borders are part of style, but setting/removing borders is more
968
- * complicated than setting other style properties. usually you want
969
- * things to apply to ranges, rather than individual cells. removing
970
- * borders needs to consider neighbor borders. and so on.
971
- *
972
- * @public
973
- */
974
- ApplyBorders(range: RangeReference | undefined, borders: BorderConstants, width?: number): void;
975
-
976
- /**
977
- * Apply style to range.
978
- *
979
- * @param range pass `undefined` as range to apply to current selection.
980
- * @param delta apply over existing properties. default true.
981
- *
982
- * @remarks
983
- *
984
- * Don't use this method to set borders, use `ApplyBorders`.
985
- *
986
- * @public
987
- */
988
- ApplyStyle(range?: RangeReference, style?: CellStyle, delta?: boolean): void;
989
-
990
- /**
991
- * Remove a named range (removes the name, not the range).
992
- *
993
- * @public
994
- */
995
- ClearName(name: string): void;
996
-
997
- /**
998
- * Create a named range or named expression. A named range refers to an
999
- * address or range. A named expression can be any value or formula. To set
1000
- * the value as a literal string, enclose the string in double-quotes (as
1001
- * you would when using a string as a function argument).
1002
- *
1003
- * @param value range, value or expression
1004
- *
1005
- * @remarks
1006
- *
1007
- * This function used to support passing `undefined` as the value,
1008
- * which meant "create a named range using current selection". We don't
1009
- * support that any more but you can accompilsh that with
1010
- * `sheet.DefineName("Name", sheet.GetSelection())`.
1011
- *
1012
- * @public
1013
- */
1014
- DefineName(name: string, value: RangeReference | CellValue, scope?: string | number, overwrite?: boolean): void;
1015
-
1016
- /**
1017
- * Set or remove a link in a cell.
1018
- *
1019
- * @param target http/https URL or a spreadsheet reference (as text). set blank to remove link.
1020
- *
1021
- * @public
1022
- */
1023
- SetLink(address?: AddressReference, target?: string): void;
1024
-
1025
- /**
1026
- * Select a range. This function will change sheets if your reference
1027
- * refers to a different sheet. if the argument is undefined or falsy
1028
- * it will remove the selection (set to no selection).
1029
- *
1030
- * @public
1031
- */
1032
- Select(range?: RangeReference): void;
1033
-
1034
- /**
1035
- * override for paste method omits the data parameter.
1036
- */
1037
- Paste(target?: RangeReference, options?: PasteOptions): void;
1038
-
1039
- /**
1040
- * standard paste method accepts data argument
1041
- *
1042
- * @param target
1043
- * @param data
1044
- * @param options
1045
- */
1046
- Paste(target?: RangeReference, data?: ClipboardData, options?: PasteOptions): void;
1047
-
1048
- /**
1049
- * copy data. this method returns the copied data. it does not put it on
1050
- * the system clipboard. this is for API access when the system clipboard
1051
- * might not be available.
1052
- */
1053
- Copy(source?: RangeReference): ClipboardData;
1054
-
1055
- /**
1056
- * cut data. this method returns the cut data. it does not put it on the
1057
- * system clipboard. this method is similar to the Copy method, with
1058
- * two differences: (1) we remove the source data, effectively clearing
1059
- * the source range; and (2) the clipboard data retains references, meaning
1060
- * if you paste the data in a different location it will refer to the same
1061
- * cells.
1062
- */
1063
- Cut(source?: RangeReference): ClipboardData;
1064
-
1065
- /**
1066
- *
1067
- * @param range target range. leave undefined to use current selection.
1068
- *
1069
- * @public
1070
- */
1071
- GetRange(range?: RangeReference, options?: GetRangeOptions): CellValue | CellValue[][] | undefined;
1072
-
1073
- /**
1074
- * returns the style from the target address or range.
1075
- *
1076
- * @param range - target range. leave undefined to use current selection
1077
- * @param apply_theme - include theme defaults when returning style
1078
- *
1079
- */
1080
- GetStyle(range?: RangeReference, apply_theme?: boolean): CellStyle | CellStyle[][] | undefined;
1081
-
1082
- /**
1083
- * Set data in range.
1084
- *
1085
- * @param range target range. leave undefined to use current selection.
1086
- *
1087
- * @public
1088
- */
1089
- SetRange(range?: RangeReference, data?: CellValue | CellValue[][], options?: SetRangeOptions): void;
1090
-
1091
- /**
1092
- * Subscribe to spreadsheet events
1093
- * @param subscriber - callback function
1094
- * @returns a token used to cancel the subscription
1095
- */
1096
- Subscribe(subscriber: (event: EmbeddedSheetEvent) => void): number;
1097
-
1098
- /**
1099
- * Cancel subscription
1100
- * @param token - the token returned from `Subscribe`
1101
- */
1102
- Cancel(token: number): void;
1103
- }
1104
-
1105
- /**
1106
- * options for saving files. we add the option for JSON formatting.
1107
- */
1108
- export interface SaveOptions extends SerializeOptions {
1109
-
1110
- /** pretty json formatting */
1111
- pretty?: boolean;
1112
- }
1113
-
1114
- /**
1115
- * options for the LoadDocument method
1116
- */
1117
- export interface LoadDocumentOptions {
1118
- scroll?: string | ICellAddress;
1119
- flush?: boolean;
1120
- recalculate?: boolean;
1121
- override_sheet?: string;
1122
- }
1123
-
1124
- /**
1125
- * options for the GetRange method
1126
- */
1127
- export interface GetRangeOptions {
1128
-
1129
- /**
1130
- * return formatted values (apply number formats and return strings)
1131
- * @deprecated
1132
- */
1133
- formatted?: boolean;
1134
-
1135
- /**
1136
- * return formulas instead of values. formula takes precedence over
1137
- * "formatted"; if you pass both, returned values will *not* be formatted.
1138
- * @deprecated
1139
- */
1140
- formula?: boolean;
1141
-
1142
- /**
1143
- * by default, GetRange returns cell values. the optional type field
1144
- * can be used to returns data in different formats.
1145
- *
1146
- * @remarks
1147
- *
1148
- * `formatted` returns formatted values, applying number formatting and
1149
- * returning strings.
1150
- *
1151
- * `A1` returns cell formulas instead of values, in A1 format.
1152
- *
1153
- * `R1C1` returns cell formauls in R1C1 format.
1154
- *
1155
- * `formula` is an alias for 'A1', for backwards compatibility.
1156
- *
1157
- */
1158
- type?: 'formatted' | 'A1' | 'R1C1' | 'formula';
1159
- }
1160
-
1161
- /**
1162
- * options for the ScrollTo method.
1163
- *
1164
- * @remarks
1165
- *
1166
- * this method was renamed because of a conflict with a DOM type,
1167
- * which was causing problems with the documentation generator.
1168
- */
1169
- export interface SheetScrollOptions {
1170
-
1171
- /** scroll in x-direction. defaults to true. */
1172
- x?: boolean;
1173
-
1174
- /** scroll in y-direction. defaults to true. */
1175
- y?: boolean;
1176
-
1177
- /**
1178
- * smooth scrolling, if supported. we use scrollTo so support is as here:
1179
- * https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo
1180
- */
1181
- smooth?: boolean;
1182
- }
1183
-
1184
- /**
1185
- * function type used for filtering tables
1186
- */
1187
- export type TableFilterFunction = (value: CellValue, calculated_value: CellValue, style: CellStyle) => boolean;
1188
- export interface FreezePane {
1189
- rows: number;
1190
- columns: number;
1191
- }
1192
- export interface CondifionalFormatExpressionOptions {
1193
- style: CellStyle;
1194
- expression: string;
1195
- options?: EvaluateOptions;
1196
- }
1197
- export interface ConditionalFormatGradientOptions {
1198
-
1199
- /** property defaults to fill */
1200
- property?: 'fill' | 'text';
1201
-
1202
- /** defaults to RGB */
1203
- color_space?: 'HSL' | 'RGB';
1204
-
1205
- /** gradient stops, required */
1206
- stops: Array<{
1207
- value: number;
1208
- color: Color;
1209
- }>;
1210
-
1211
- /** min and max are optional. if not provided, we use the min/max of the range of data. */
1212
- min?: number;
1213
-
1214
- /** min and max are optional. if not provided, we use the min/max of the range of data. */
1215
- max?: number;
1216
- }
1217
- export type StandardGradient = 'red-green' | 'green-red' | 'red-yellow-green' | 'green-yellow-red';
1218
- export interface ConditionalFormatCellMatchOptions {
1219
- style: CellStyle;
1220
- expression: string;
1221
- options?: EvaluateOptions;
1222
- }
1223
- export interface ConditionalFormatDuplicateValuesOptions {
1224
- style: CellStyle;
1225
-
1226
- /** true to highlight unique cells, false to highlight duplicates. defaults to false. */
1227
- unique?: boolean;
1228
- }
1229
-
1230
- /**
1231
- * union, plus we're adding a state used to track application.
1232
- * that state is serialized if it's true.
1233
- * we also add an internal field that will be type-specific, and not serialized.
1234
- *
1235
- * ...everybody has a vertex now, we could standardize it
1236
- *
1237
- * update: adding a priority field, optional
1238
- *
1239
- */
1240
- export type ConditionalFormat = {
1241
- internal?: unknown;
1242
- priority?: number;
1243
- } & (ConditionalFormatDuplicateValues | ConditionalFormatExpression | ConditionalFormatCellMatch | ConditionalFormatGradient);
1244
-
1245
- /**
1246
- * conditional format predicated on an expression. if the expression
1247
- * evaluates to true, we apply the style. otherwise no.
1248
- */
1249
- export interface ConditionalFormatExpression extends CondifionalFormatExpressionOptions {
1250
- type: 'expression';
1251
- area: IArea;
1252
- }
1253
- export interface ConditionalFormatGradient extends ConditionalFormatGradientOptions {
1254
- type: 'gradient';
1255
- area: IArea;
1256
- }
1257
- export interface ConditionalFormatCellMatch extends ConditionalFormatCellMatchOptions {
1258
- type: 'cell-match';
1259
- area: IArea;
1260
- }
1261
- export interface ConditionalFormatDuplicateValues extends ConditionalFormatDuplicateValuesOptions {
1262
- type: 'duplicate-values';
1263
- area: IArea;
1264
- }
1265
-
1266
- /**
1267
- * Structure represents a 2d range of cells.
1268
- */
1269
- export interface IArea {
1270
- start: ICellAddress;
1271
- end: ICellAddress;
1272
- }
1273
- export type Color = ThemeColor | HTMLColor | NullColor;
1274
-
1275
- /**
1276
- * style properties applied to a single cell, row, column, or sheet.
1277
- * when rendering a cell, we composite all styles that might apply.
1278
- */
1279
- export interface CellStyle {
1280
-
1281
- /** horizontal align defaults to left */
1282
- horizontal_align?: HorizontalAlign;
1283
-
1284
- /** vertical align defaults to bottom */
1285
- vertical_align?: VerticalAlign;
1286
-
1287
- /** representation for NaN */
1288
- nan?: string;
1289
-
1290
- /** number format, either a symbolic name like "General" or a format string */
1291
- number_format?: string;
1292
-
1293
- /** wrap text */
1294
- wrap?: boolean;
1295
-
1296
- /**
1297
- * font size. we recommend using relative font sizes (either % or em)
1298
- * which will be relative to the theme font size.
1299
- */
1300
- font_size?: FontSize;
1301
-
1302
- /** font face. this can be a comma-delimited list, like CSS */
1303
- font_face?: string;
1304
-
1305
- /** flag */
1306
- bold?: boolean;
1307
-
1308
- /** flag */
1309
- italic?: boolean;
1310
-
1311
- /** flag */
1312
- underline?: boolean;
1313
-
1314
- /** flag */
1315
- strike?: boolean;
1316
-
1317
- /** border weight */
1318
- border_top?: number;
1319
-
1320
- /** border weight */
1321
- border_right?: number;
1322
-
1323
- /** border weight */
1324
- border_left?: number;
1325
-
1326
- /** border weight */
1327
- border_bottom?: number;
1328
-
1329
- /** text color */
1330
- text?: Color;
1331
-
1332
- /** background color */
1333
- fill?: Color;
1334
-
1335
- /** border color */
1336
- border_top_fill?: Color;
1337
-
1338
- /** border color */
1339
- border_left_fill?: Color;
1340
-
1341
- /** border color */
1342
- border_right_fill?: Color;
1343
-
1344
- /** border color */
1345
- border_bottom_fill?: Color;
1346
-
1347
- /** text indent */
1348
- indent?: number;
1349
-
1350
- /**
1351
- * cell is locked for editing
1352
- */
1353
- locked?: boolean;
1354
- }
1355
-
1356
- /** horizontal align constants for cell style */
1357
- export type HorizontalAlign = '' | 'left' | 'center' | 'right';
1358
-
1359
- /** vertical align constants for cell style */
1360
- export type VerticalAlign = '' | 'top' | 'bottom' | 'middle';
1361
- export type ThemeColorType = 'Background' | 'Text' | 'Background2' | 'Text2' | 'Accent' | 'Accent2' | 'Accent3' | 'Accent4' | 'Accent5' | 'Accent6';
1362
-
1363
- /**
1364
- * font size for cell style. we generally prefer relative sizes
1365
- * (percent or em) because they are relative to the default theme
1366
- * size, which might be different on different platforms.
1367
- */
1368
- export interface FontSize {
1369
- unit: 'pt' | 'px' | 'em' | '%';
1370
- value: number;
1371
- }
1372
- export interface HTMLColor {
1373
- text: string;
1374
- }
1375
- export interface ThemeColor {
1376
- theme: number | ThemeColorType;
1377
- tint?: number;
1378
- }
1379
- export interface NullColor {
1380
- }
1381
- export declare const ThemeColorIndex: (color: ThemeColor) => number;
1382
- export declare const IsHTMLColor: (color?: Color) => color is HTMLColor;
1383
- export declare const IsThemeColor: (color?: Color) => color is ThemeColor;
1384
- export declare const IsDefinedColor: (color?: Color) => color is (ThemeColor | HTMLColor);
1385
-
1386
- /**
1387
- * options for the evaluate function
1388
- */
1389
- export interface EvaluateOptions {
1390
-
1391
- /**
1392
- * argument separator to use when parsing input. set this option to
1393
- * use a consistent argument separator independent of current locale.
1394
- */
1395
- argument_separator?: ',' | ';';
1396
-
1397
- /**
1398
- * allow R1C1-style references. the Evaluate function cannot use
1399
- * relative references (e.g. R[-1]C[0]), so those will always fail.
1400
- * however it may be useful to use direct R1C1 references (e.g. R3C4),
1401
- * so we optionally support that behind this flag.
1402
- */
1403
- r1c1?: boolean;
1404
- }
1405
-
1406
- /**
1407
- * options for serializing data
1408
- */
1409
- export interface SerializeOptions {
1410
-
1411
- /** optimize for size */
1412
- optimize?: 'size' | 'speed';
1413
-
1414
- /** include the rendered/calculated value in export */
1415
- rendered_values?: boolean;
1416
-
1417
- /** translate colors to xlsx-friendly values */
1418
- export_colors?: boolean;
1419
-
1420
- /** export cells that have no value, but have a border or background color */
1421
- decorated_cells?: boolean;
1422
-
1423
- /** prune unused rows/columns */
1424
- shrink?: boolean;
1425
-
1426
- /**
1427
- * include tables. tables will be serialized in the model, so we can
1428
- * drop them from cells. but you can leave them in if that's useful.
1429
- */
1430
- tables?: boolean;
1431
-
1432
- /** share resources (images, for now) to prevent writing data URIs more than once */
1433
- share_resources?: boolean;
1434
-
1435
- /**
1436
- * if a function has an export() handler, call that
1437
- */
1438
- export_functions?: boolean;
1439
- }
1440
- export type AnnotationType = 'treb-chart' | 'image' | 'textbox' | 'external';
1441
- export interface Point {
1442
- x: number;
1443
- y: number;
1444
- }
1445
-
1446
- /** structure represents rectangle coordinates */
1447
- export interface IRectangle {
1448
- top: number;
1449
- left: number;
1450
- width: number;
1451
- height: number;
1452
- }
1453
- export type CellValue = undefined | string | number | boolean | Complex | DimensionedQuantity;
1454
-
1455
- /**
1456
- * Complex number type
1457
- */
1458
- export interface Complex {
1459
- real: number;
1460
- imaginary: number;
1461
- }
1462
-
1463
- /**
1464
- * dimensioned quantity: 3.2 m/s, 2kg, 5m, &c.
1465
- */
1466
- export interface DimensionedQuantity {
1467
- value: number;
1468
- unit: string;
1469
- }
1470
-
1471
- /**
1472
- * composite styling for tables.
1473
- */
1474
- export interface TableTheme {
1475
-
1476
- /** the first row in a table, showing column titles. */
1477
- header?: CellStyle;
1478
-
1479
- /**
1480
- * odd rows in the table. we count the title row as zero, so
1481
- * the first row in the table containing data is 1, hence odd.
1482
- */
1483
- odd?: CellStyle;
1484
-
1485
- /**
1486
- * even rows in the table.
1487
- */
1488
- even?: CellStyle;
1489
-
1490
- /**
1491
- * styling for the totals row, if included. this will be the last
1492
- * row in the table.
1493
- */
1494
- total?: CellStyle;
1495
- }
1496
-
1497
- /**
1498
- * type represents a reference passed in to API functions. it can be an
1499
- * address object, or a string.
1500
- */
1501
- export type AddressReference = string | ICellAddress;
1502
-
1503
- /**
1504
- * type represents a reference passed in to API functions. it can be an
1505
- * address object, an area (range) object, or a string.
1506
- */
1507
- export type RangeReference = string | ICellAddress | IArea;
1508
- export interface TableSortOptions {
1509
-
1510
- /**
1511
- * when sorting, column is relative to the table (and 0-based). so the
1512
- * first column in the table is 0, regardless of where the table is in
1513
- * the spreadsheet. defaults to 0, if not specified.
1514
- */
1515
- column: number;
1516
-
1517
- /**
1518
- * sort type. defaults to 'auto'. 'auto' looks at the values in the column,
1519
- * and uses text sort if there are more strings, or numeric if there are
1520
- * more numbers. if it's even, sorts as text.
1521
- */
1522
- type: TableSortType;
1523
-
1524
- /** ascending sort. defaults to true. */
1525
- asc: boolean;
1526
- }
1527
- export type TableSortType = 'text' | 'numeric' | 'auto';
1528
-
1529
- /** clipboard data is a 2d array */
1530
- export type ClipboardData = ClipboardDataElement[][];
1531
-
1532
- /**
1533
- * optional paste options. we can paste formulas or values, and we
1534
- * can use the source style, target style, or just use the source
1535
- * number formats.
1536
- */
1537
- export interface PasteOptions {
1538
-
1539
- /**
1540
- * when clipboard data includes formulas, optionally paste calculated
1541
- * values instead of the original formulas. defaults to false.
1542
- */
1543
- values?: boolean;
1544
-
1545
- /**
1546
- * when pasting data from the clipboard, we can copy formatting/style
1547
- * from the original data, or we can retain the target range formatting
1548
- * and just paste data. a third option allows pasting source number
1549
- * formats but dropping other style information.
1550
- *
1551
- * defaults to "source", meaning paste source styles.
1552
- */
1553
- formatting?: 'source' | 'target' | 'number-formats';
1554
- }
1555
-
1556
- /**
1557
- * this is a structure for copy/paste data. clipboard data may include
1558
- * relative formauls and resolved styles, so it's suitable for pasting into
1559
- * other areas of the spreadsheet.
1560
- */
1561
- export interface ClipboardDataElement {
1562
-
1563
- /** calculated cell value */
1564
- calculated: CellValue;
1565
-
1566
- /** the actual cell value or formula */
1567
- value: CellValue;
1568
-
1569
- /** cell style. this may include row/column styles from the copy source */
1570
- style?: CellStyle;
1571
-
1572
- /** area. if this cell is part of an array, this is the array range */
1573
- area?: IArea;
1574
- }
1575
- export declare type BorderConstants = "none" | "all" | "outside" | "top" | "bottom" | "left" | "right";
1576
-
1577
- /**
1578
- * options for the SetRange method
1579
- */
1580
- export interface SetRangeOptions {
1581
-
1582
- /** transpose rectangular array before inserting */
1583
- transpose?: boolean;
1584
-
1585
- /** recycle values (R-style) */
1586
- recycle?: boolean;
1587
-
1588
- /** apply as an array (as if you pressed ctrl+shift+enter) */
1589
- array?: boolean;
1590
-
1591
- /** spill over */
1592
- spill?: boolean;
1593
-
1594
- /**
1595
- * argument separator to use when parsing the input formula. set this
1596
- * option to call SetRange with a consistent argument separator,
1597
- * independent of current locale.
1598
- */
1599
- argument_separator?: ',' | ';';
1600
-
1601
- /**
1602
- * allow R1C1-style references; these can be either absolute
1603
- * addresses (e.g. R2C4) or relative to the cell (e.g. R[-3]C[0]).
1604
- */
1605
- r1c1?: boolean;
1606
- }
1607
- export interface ExternalEditorConfig {
1608
-
1609
- /**
1610
- * list of dependencies to highlight. we support undefined entries in
1611
- * this list so you can use the result of `EmbeddedSpreadsheet.Resolve`,
1612
- * which may return undefined.
1613
- */
1614
- dependencies: DependencyList;
1615
-
1616
- /**
1617
- * this callback will be called when the selection changes in the
1618
- * spreadsheet and this external editor is active. return an updated
1619
- * list of dependencies to highlight.
1620
- *
1621
- * NOTE: this is currently synchronous, but don't rely on that. it
1622
- * might switch to async in the future depending on how it works in
1623
- * practice.
1624
- */
1625
- update: ExternalEditorCallback;
1626
-
1627
- /**
1628
- * a list of nodes that will serve as editors. when you attach, we will do
1629
- * an initial pass of context highlighting. we highlight on text changes
1630
- * and insert references if you make a selection in the spreadsheet while
1631
- * an editor is focused.
1632
- */
1633
- nodes: HTMLElement[];
1634
-
1635
- /**
1636
- * assume that we're editing a formula. does not require leading `=`.
1637
- * defaults to `true` for historical reasons.
1638
- */
1639
- assume_formula?: boolean;
1640
- }
1641
- export type DependencyList = Array<IArea | ICellAddress | undefined>;
1642
- export type ExternalEditorCallback = (selection?: string) => DependencyList | undefined;
1643
-
1644
- /**
1645
- * this is the document type used by TREB. it has a lot of small variations
1646
- * for historical reasons and backwards compatibility. usually it's preferable
1647
- * to let TREB create and manage these documents rather than creating them
1648
- * manually.
1649
- */
1650
- export interface TREBDocument {
1651
-
1652
- /** app name, as identifier */
1653
- app: string;
1654
-
1655
- /** app version. we'll warn if you use a file from a newer version */
1656
- version: string;
1657
-
1658
- /**
1659
- * revision number. this is a value that increments on any document change,
1660
- * useful for checking if a document is "dirty".
1661
- */
1662
- revision?: number;
1663
-
1664
- /** document name */
1665
- name?: string;
1666
-
1667
- /**
1668
- * opaque user data. we don't read or parse this, but applications can
1669
- * use it to store arbitrary data.
1670
- */
1671
- user_data?: unknown;
1672
-
1673
- /**
1674
- * per-sheet data. this should be an array, but for historical reasons
1675
- * we still support a single sheet outside of an array.
1676
- */
1677
- sheet_data?: SerializedSheet | SerializedSheet[];
1678
-
1679
- /** document decimal mark */
1680
- decimal_mark?: '.' | ',';
1681
-
1682
- /** active sheet. if unset we'll show the first un-hidden sheet */
1683
- active_sheet?: number;
1684
-
1685
- /**
1686
- * this document includes rendered calculated values. using this lets the
1687
- * app show a document faster, without requiring an initial calculation.
1688
- */
1689
- rendered_values?: boolean;
1690
-
1691
- /** document named ranges @deprecated */
1692
- named_ranges?: Record<string, IArea>;
1693
-
1694
- /** document named expressions @deprecated */
1695
- named_expressions?: SerializedNamedExpression[];
1696
-
1697
- /**
1698
- * new consolidated named ranges & expressions
1699
- */
1700
- named?: SerializedNamed[];
1701
-
1702
- /** document macro functions */
1703
- macro_functions?: SerializedMacroFunction[];
1704
-
1705
- /** document tables */
1706
- tables?: Table[];
1707
-
1708
- /** document shared resources (usually images) */
1709
- shared_resources?: Record<string, string>;
1710
- }
1711
- export declare type LoadSource = "drag-and-drop" | "local-file" | "network-file" | "local-storage" | "inline-document" | "undo";
1712
-
1713
- /**
1714
- * EmbeddedSheetEvent is a discriminated union. Switch on the `type` field
1715
- * of the event.
1716
- */
1717
- export type EmbeddedSheetEvent = DocumentChangeEvent | DocumentResetEvent | DocumentLoadEvent | ThemeChangeEvent | ViewChangeEvent | DataChangeEvent | FocusViewEvent | SelectionEvent | ResizeEvent | AnnotationSelectionEvent;
1718
-
1719
- /**
1720
- * options when inserting a table into a sheet
1721
- */
1722
- export interface InsertTableOptions {
1723
-
1724
- /**
1725
- * include a totals/summation row. this impacts the layout and styling:
1726
- * totals row have a unique style and are not included when sorting.
1727
- * defaults to true.
1728
- */
1729
- totals_row?: boolean;
1730
-
1731
- /**
1732
- * show a sort button in table headers. defaults to true.
1733
- */
1734
- sortable?: boolean;
1735
-
1736
- /**
1737
- * base theme color, or a set of styles for the table. useful values for
1738
- * theme color are accent colors 4 (the default), 5, 7 and 9.
1739
- */
1740
- theme?: number | TableTheme;
1741
- }
1742
- export interface ResizeEvent {
1743
- type: 'resize';
1744
- }
1745
- export declare type LoadType = "treb" | "csv" | "xlsx";
1746
-
1747
- /**
1748
- * This event is sent when the view changes -- at the moment, that only
1749
- * means the view scale has been changed. We might use it in the future
1750
- * for other things.
1751
- */
1752
- export interface ViewChangeEvent {
1753
- type: 'view-change';
1754
- }
1755
-
1756
- /**
1757
- * this event is sent when the theme is updated. it's intended for any
1758
- * subscribers to update corresponding colors or fonts.
1759
- */
1760
- export interface ThemeChangeEvent {
1761
- type: 'theme-change';
1762
- }
1763
-
1764
- /**
1765
- * This event is sent when a document is loaded, and also on undo. The
1766
- * source field can help determine if it was triggered by an undo operation.
1767
- */
1768
- export interface DocumentLoadEvent {
1769
- type: 'load';
1770
- source?: LoadSource;
1771
- file_type?: LoadType;
1772
- }
1773
-
1774
- /**
1775
- * This event is sent when the document is reset.
1776
- */
1777
- export interface DocumentResetEvent {
1778
- type: 'reset';
1779
- }
1780
-
1781
- /**
1782
- * This event is sent when data in the spreadsheet changes, but there are
1783
- * no structural or cell changes. For example, the `RAND` function returns
1784
- * a new value on every calculation, but the function itself does not change.
1785
- */
1786
- export interface DataChangeEvent {
1787
- type: 'data';
1788
- }
1789
-
1790
- /**
1791
- * This event is sent when the value of a cell changes, or when the document
1792
- * structure chages. Structure changes might be inserting/deleting rows or
1793
- * columns, or adding/removing a sheet.
1794
- */
1795
- export interface DocumentChangeEvent {
1796
- type: 'document-change';
1797
- }
1798
-
1799
- /**
1800
- * This event is sent when the spreadsheet selection changes. Use the
1801
- * `GetSelection` method to get the address of the current selection.
1802
- */
1803
- export interface SelectionEvent {
1804
- type: 'selection';
1805
- }
1806
-
1807
- /**
1808
- * this event is used when an annotation is selected. we're not changing
1809
- * the original selection event, because I don't want to break anything.
1810
- */
1811
- export interface AnnotationSelectionEvent {
1812
- type: 'annotation-selection';
1813
- }
1814
-
1815
- /**
1816
- * This event is sent when the focused view changes, if you have more
1817
- * than one view.
1818
- */
1819
- export interface FocusViewEvent {
1820
- type: 'focus-view';
1821
- }
1822
-
1823
- /**
1824
- * serialized type is a composite of expression/range. we determine
1825
- * what it is when parsing the expression. this simplifies passing these
1826
- * things around.
1827
- *
1828
- * (named expressions and ranges they have slightly different behavior,
1829
- * which is why we have a distinction at all).
1830
- *
1831
- */
1832
- export interface SerializedNamed {
1833
- name: string;
1834
-
1835
- /** expression or address/area */
1836
- expression: string;
1837
-
1838
- /** scope is a sheet name (not ID) */
1839
- scope?: string;
1840
- }
1841
- export interface SerializedSheet {
1842
-
1843
- /** cell data */
1844
- data: SerializedCellData;
1845
-
1846
- /** top-level sheet style, if any */
1847
- sheet_style: CellStyle;
1848
-
1849
- /** row count */
1850
- rows: number;
1851
-
1852
- /** column count */
1853
- columns: number;
1854
-
1855
- /**
1856
- * cell styles is for empty cells that have styling
1857
- */
1858
- cell_styles: CellStyleRecord[];
1859
-
1860
- /**
1861
- * @deprecated use `styles` instead
1862
- */
1863
- cell_style_refs?: CellStyle[];
1864
-
1865
- /**
1866
- * new implementation
1867
- */
1868
- styles?: CellStyle[];
1869
-
1870
- /**
1871
- * per-row styles
1872
- */
1873
- row_style: Record<number, CellStyle | number>;
1874
-
1875
- /**
1876
- * per-column styles
1877
- */
1878
- column_style: Record<number, CellStyle | number>;
1879
-
1880
- /**
1881
- * @deprecated no one uses this anymore and it's weird
1882
- */
1883
- row_pattern?: CellStyle[];
1884
-
1885
- /** default for new rows */
1886
- default_row_height?: number;
1887
-
1888
- /** default for new columns */
1889
- default_column_width?: number;
1890
-
1891
- /** list of row heights. we use a Record instead of an array because it's sparse */
1892
- row_height?: Record<number, number>;
1893
-
1894
- /** list of column widths. we use a Record instead of an array because it's sparse */
1895
- column_width?: Record<number, number>;
1896
-
1897
- /**
1898
- * @deprecated these were moved to the containing document
1899
- */
1900
- named_ranges?: Record<string, IArea>;
1901
- freeze?: FreezePane;
1902
-
1903
- /** sheet ID, for serializing references */
1904
- id?: number;
1905
-
1906
- /** sheet name */
1907
- name?: string;
1908
-
1909
- /** tab color */
1910
- tab_color?: Color;
1911
-
1912
- /** current active selection */
1913
- selection: SerializedGridSelection;
1914
-
1915
- /** */
1916
- annotations?: Partial<AnnotationData>[];
1917
-
1918
- /** current scroll position */
1919
- scroll?: ScrollOffset;
1920
-
1921
- /** visible flag. we only support visible/hidden */
1922
- visible?: boolean;
1923
-
1924
- /** testing */
1925
- background_image?: string;
1926
- }
1927
- export interface ScrollOffset {
1928
- x: number;
1929
- y: number;
1930
- }
1931
- export interface CellStyleRecord {
1932
- row: number;
1933
- column: number;
1934
- ref: number;
1935
- rows?: number;
1936
- }
1937
- export type SerializedCellData = CellDataWithAddress[] | NestedRowData[] | NestedColumnData[];
1938
- export interface BaseCellData {
1939
- value: CellValue;
1940
- style_ref?: number;
1941
- calculated?: CellValue;
1942
- table?: Table;
1943
- area?: IArea;
1944
- merge_area?: IArea;
1945
- calculated_type?: SerializedValueType;
1946
- note?: string;
1947
- hyperlink?: string;
1948
- type?: SerializedValueType;
1949
- sheet_id?: number;
1950
- spill?: IArea;
1951
- }
1952
-
1953
- /**
1954
- * this type is for serialized data that includes the row and column
1955
- * in each cell. this was the original serialized data type, and is
1956
- * still supported. current serialization will group data into rows or
1957
- * columns, whichever results in a smaller overall serialized representation.
1958
- */
1959
- export interface CellDataWithAddress extends BaseCellData {
1960
- row: number;
1961
- column: number;
1962
- }
1963
- export interface NestedCellData {
1964
- cells: BaseCellData[];
1965
- }
1966
-
1967
- /**
1968
- * this type is for serialized data that is grouped by row, with each
1969
- * cell referencing a column in the spreadsheet.
1970
- */
1971
- export interface CellDataWithColumn extends BaseCellData {
1972
- column: number;
1973
- }
1974
- export interface NestedRowData extends NestedCellData {
1975
- row: number;
1976
- cells: CellDataWithColumn[];
1977
- }
1978
-
1979
- /**
1980
- * this type is for serialized data that is grouped by column, with each
1981
- * cell referencing a row in the spreadsheet.
1982
- */
1983
- export interface CellDataWithRow extends BaseCellData {
1984
- row: number;
1985
- }
1986
- export interface NestedColumnData extends NestedCellData {
1987
- column: number;
1988
- cells: CellDataWithRow[];
1989
- }
1990
-
1991
- /**
1992
- * struct representing a table
1993
- */
1994
- export interface Table {
1995
-
1996
- /**
1997
- * table must have a name
1998
- */
1999
- name: string;
2000
-
2001
- /** table area */
2002
- area: IArea;
2003
-
2004
- /**
2005
- * table column headers. normalize case before inserting.
2006
- */
2007
- columns?: string[];
2008
-
2009
- /**
2010
- * table has a totals row. this impacts layout and what's included
2011
- * in the range when you refer to a column. also on import/export, the
2012
- * AutoFilter element should exclude the totals row.
2013
- *
2014
- * NOTE: xlsx actually uses an integer for this -- can it be > 1?
2015
- */
2016
- totals_row?: boolean;
2017
-
2018
- /**
2019
- * table is sortable. defaults to true. if false, disables UI sorting.
2020
- */
2021
- sortable?: boolean;
2022
-
2023
- /**
2024
- * theme for table. we have a default, but you can set explicitly.
2025
- */
2026
- theme?: TableTheme;
2027
-
2028
- /**
2029
- * sort data. sorts are hard, meaning we actually move data around.
2030
- * (not meaning difficult). we may keep track of the last sort so we
2031
- * can toggle asc/desc, for example. atm this will not survive serialization.
2032
- */
2033
- sort?: TableSortOptions;
2034
- }
2035
-
2036
- /**
2037
- * string types for import/export
2038
- *
2039
- * @internalRemarks
2040
- *
2041
- * temporarily switching to literal, see what happens to API
2042
- *
2043
- */
2044
- export type SerializedValueType = // typeof ValueTypeList[number];
2045
- 'undefined' | 'formula' | 'string' | 'number' | 'boolean' | 'object' | 'error' | 'complex' | 'array' | 'dimensioned_quantity';
2046
-
2047
- /**
2048
- * temporarily splitting into a serialized version that uses IArea instead
2049
- * of Area. we should do this for the actual selection type, but it breaks
2050
- * too many things atm to do that immediately. TODO/FIXME.
2051
- */
2052
- export interface SerializedGridSelection {
2053
-
2054
- /** target or main cell in the selection */
2055
- target: ICellAddress;
2056
-
2057
- /** selection area */
2058
- area: IArea;
2059
-
2060
- /** there is nothing selected, even though this object exists */
2061
- empty?: boolean;
2062
-
2063
- /** for cacheing addtional selections. optimally don't serialize */
2064
- rendered?: boolean;
2065
- }
2066
- export type AnnotationData = AnnotationChartData | AnnotationImageData | AnnotationExternalData | AnnotationTextBoxData;
2067
- export interface ImageSize {
2068
- width: number;
2069
- height: number;
2070
- }
2071
- export interface ImageAnnotationData {
2072
- src: string;
2073
-
2074
- /**/
2075
- scale?: string;
2076
- original_size?: ImageSize;
2077
- }
2078
-
2079
- /**
2080
- * splitting persisted data from the annotation class. that class might
2081
- * disappear in the future in favor of just a type. this interface should
2082
- * fully match the old Partial<Annotation> we used before. note that we
2083
- * used to define values for all members, but they may now be undefined
2084
- * because the Annotation class as a Partial instance of this data.
2085
- *
2086
- * conceptually annotation was originally intended to support types other
2087
- * than our own charts and images, but no one ever used it. so we could
2088
- * lock down the `type` field if we wanted to. or perhaps have an `external`
2089
- * type with opaque data. TODO.
2090
- *
2091
- */
2092
- export interface AnnotationDataBase {
2093
-
2094
- /** the new layout, persisted and takes preference over the old one */
2095
- layout?: AnnotationLayout;
2096
-
2097
- /**
2098
- * adding cell style as a convenient store for font stack; atm we are
2099
- * ignoring everything but the font_face attribute
2100
- */
2101
- style?: CellStyle;
2102
-
2103
- /**
2104
- * the old layout used rectangles, and we need to keep support for
2105
- * that. this is not the layout rectangle. this rectangle is just
2106
- * for serialization/deserialization. the actual rectangle is maintained
2107
- * in the Annotation class.
2108
- */
2109
- rect?: Partial<IRectangle>;
2110
-
2111
- /** annotation can be resized. this is advisory, for UI */
2112
- resizable: boolean;
2113
-
2114
- /** annotation can be moved. this is advisory, for UI */
2115
- movable: boolean;
2116
-
2117
- /** annotation can be removed/deleted. this is advisory, for UI */
2118
- removable: boolean;
2119
-
2120
- /** annotation can be selected. this is advisory, for UI */
2121
- selectable: boolean;
2122
-
2123
- /** move when resizing/inserting rows/columns */
2124
- move_with_cells: boolean;
2125
-
2126
- /** resize when resizing/inserting rows/columns */
2127
- resize_with_cells: boolean;
2128
-
2129
- /**
2130
- * optional formula. the formula will be updated on structure events
2131
- * (insert/delete row/column).
2132
- */
2133
- formula: string;
2134
-
2135
- /**
2136
- * extent, useful for exporting. we could probably serialize this,
2137
- * just be sure to clear it when layout changes so it will be
2138
- * recalculated.
2139
- *
2140
- * the idea is to know the bottom/right row/column of the annotation,
2141
- * so when we preserve/restore the sheet we don't trim those rows/columns.
2142
- * they don't need any data, but it just looks bad. we can do this
2143
- * dynamically but since it won't change all that often, we might
2144
- * as well precalculate.
2145
- */
2146
- extent: ICellAddress;
2147
- }
2148
- export interface AnnotationImageData extends AnnotationDataBase {
2149
- type: 'image';
2150
- data: ImageAnnotationData;
2151
- }
2152
- export interface AnnotationChartData extends AnnotationDataBase {
2153
- type: 'treb-chart';
2154
- }
2155
- export interface AnnotationTextBoxData extends AnnotationDataBase {
2156
- type: 'textbox';
2157
-
2158
- /**
2159
- * @internalRemarks
2160
- * what's with this weird structure? did we inherit it? can we clean it up?
2161
- */
2162
- data: {
2163
- style?: CellStyle;
2164
- paragraphs: {
2165
- style?: CellStyle;
2166
- content: {
2167
- text: string;
2168
- style?: CellStyle;
2169
- }[];
2170
- }[];
2171
- };
2172
- }
2173
- export interface AnnotationExternalData extends AnnotationDataBase {
2174
- type: 'external';
2175
- data: Record<string, string>;
2176
- }
2177
-
2178
- /**
2179
- * represents the layout of an annotation, reference to the sheet
2180
- */
2181
- export interface AnnotationLayout {
2182
- tl: Corner;
2183
- br: Corner;
2184
- }
2185
-
2186
- /**
2187
- * offset from corner, as % of cell
2188
- */
2189
- export interface AddressOffset {
2190
- x: number;
2191
- y: number;
2192
- }
2193
-
2194
- /**
2195
- * represents one corner of a layout rectangle
2196
- */
2197
- export interface Corner {
2198
- address: ICellAddress;
2199
- offset: AddressOffset;
2200
- }
2201
- export interface SerializedMacroFunction {
2202
- name: string;
2203
- function_def: string;
2204
- argument_names?: string[];
2205
- description?: string;
2206
- }
2207
-
2208
- /**
2209
- * this type is no longer in use, but we retain it to parse old documents
2210
- * that use it.
2211
- *
2212
- * @deprecated
2213
- */
2214
- export interface SerializedNamedExpression {
2215
- name: string;
2216
- expression: string;
2217
- }
2218
-
2219
- /**
2220
- * options for exporting CSV/TSV
2221
- */
2222
- export interface ExportOptions {
2223
-
2224
- /** comma or tab */
2225
- delimiter?: ',' | '\t';
2226
-
2227
- /** optionally choose a sheet to export (defaults to active sheet) */
2228
- sheet?: string | number;
2229
-
2230
- /** export formulas not values */
2231
- formulas?: boolean;
2232
-
2233
- /** use number formats when exporting numbers */
2234
- formatted?: boolean;
2235
- }