@trebco/treb 25.2.0 → 25.4.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/{.eslintrc.js → .eslintrc.cjs} +4 -0
- package/api-generator/api-generator.ts +25 -55
- package/dist/treb-spreadsheet.mjs +9 -9
- package/dist/treb.d.ts +1 -1
- package/esbuild-custom-element.mjs +5 -264
- package/esbuild-utils.mjs +273 -0
- package/package.json +2 -2
- package/treb-base-types/src/cell.ts +23 -22
- package/treb-base-types/src/cells.ts +55 -2
- package/treb-base-types/src/union.ts +2 -1
- package/treb-calculator/src/calculator.ts +8 -5
- package/treb-calculator/src/dag/array-vertex.ts +22 -22
- package/treb-calculator/src/dag/graph.ts +25 -23
- package/treb-calculator/src/dag/leaf_vertex.ts +23 -22
- package/treb-calculator/src/dag/spreadsheet_vertex.ts +25 -23
- package/treb-calculator/src/expression-calculator.ts +23 -22
- package/treb-calculator/src/function-error.ts +23 -22
- package/treb-calculator/src/functions/base-functions.ts +3 -2
- package/treb-calculator/src/functions/checkbox.ts +23 -22
- package/treb-calculator/src/functions/complex-functions.ts +2 -1
- package/treb-calculator/src/functions/finance-functions.ts +22 -22
- package/treb-calculator/src/functions/information-functions.ts +22 -22
- package/treb-calculator/src/functions/matrix-functions.ts +2 -1
- package/treb-calculator/src/functions/statistics-functions.ts +22 -22
- package/treb-calculator/src/functions/text-functions.ts +23 -22
- package/treb-calculator/src/primitives.ts +23 -22
- package/treb-calculator/src/utilities.ts +23 -24
- package/treb-charts/src/chart-functions.ts +22 -22
- package/treb-charts/src/chart.ts +6 -3
- package/treb-charts/src/renderer.ts +25 -23
- package/treb-charts/src/util.ts +23 -22
- package/treb-embed/modern.tsconfig.json +3 -2
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +10 -14
- package/treb-embed/src/embedded-spreadsheet.ts +53 -44
- package/treb-embed/src/progress-dialog.ts +0 -3
- package/treb-embed/src/types.ts +13 -3
- package/treb-embed/style/layout.scss +32 -29
- package/treb-export/src/drawing2/chart2.ts +2 -2
- package/treb-export/src/drawing2/drawing2.ts +6 -4
- package/treb-export/src/export-worker/export-worker.ts +22 -24
- package/treb-export/src/export-worker/index-modern.ts +2 -1
- package/treb-export/src/export2.ts +15 -8
- package/treb-export/src/import2.ts +10 -5
- package/treb-export/src/workbook-sheet2.ts +2 -1
- package/treb-format/src/format.ts +23 -22
- package/treb-format/src/format_parser.ts +23 -22
- package/treb-format/src/value_parser.ts +23 -22
- package/treb-grid/src/editors/formula_bar.ts +2 -1
- package/treb-grid/src/editors/formula_editor_base.ts +4 -2
- package/treb-grid/src/editors/overlay_editor.ts +2 -1
- package/treb-grid/src/index.ts +12 -9
- package/treb-grid/src/layout/base_layout.ts +4 -2
- package/treb-grid/src/render/selection-renderer.ts +25 -23
- package/treb-grid/src/render/tile_renderer.ts +6 -4
- package/treb-grid/src/types/annotation.ts +33 -37
- package/treb-grid/src/types/data_model.ts +30 -22
- package/treb-grid/src/types/grid.ts +55 -584
- package/treb-grid/src/types/grid_base.ts +401 -7
- package/treb-grid/src/types/grid_events.ts +3 -0
- package/treb-grid/src/types/grid_selection.ts +22 -22
- package/treb-grid/src/types/named_range.ts +22 -22
- package/treb-grid/src/types/sheet.ts +8 -7
- package/treb-grid/src/types/sheet_types.ts +11 -7
- package/treb-grid/src/types/tab_bar.ts +1 -1
- package/treb-parser/src/parser.ts +5 -4
- package/tsproject.json +3 -4
- package/tsconfig.json +0 -10
- /package/treb-embed/src/{custom-element/content-types.d.ts → content-types.d.ts} +0 -0
|
@@ -19,51 +19,54 @@
|
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import {
|
|
23
|
-
Area,
|
|
22
|
+
import type {
|
|
24
23
|
Cell,
|
|
25
24
|
Theme,
|
|
26
|
-
Style,
|
|
27
25
|
IArea,
|
|
28
|
-
Extent,
|
|
29
|
-
Is2DArray,
|
|
26
|
+
Extent,
|
|
30
27
|
CellValue,
|
|
28
|
+
ICellAddress,
|
|
29
|
+
ImportedSheetData,
|
|
30
|
+
Complex,
|
|
31
|
+
IRectangle} from 'treb-base-types';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
Area,
|
|
35
|
+
Style,
|
|
36
|
+
Is2DArray,
|
|
31
37
|
Rectangle,
|
|
32
38
|
ValueType,
|
|
33
39
|
Localization,
|
|
34
|
-
ICellAddress,
|
|
35
40
|
IsCellAddress,
|
|
36
|
-
ValidationType,
|
|
37
|
-
ImportedSheetData,
|
|
41
|
+
ValidationType,
|
|
38
42
|
LoadThemeProperties,
|
|
39
43
|
DefaultTheme,
|
|
40
44
|
ComplexToString,
|
|
41
|
-
Complex,
|
|
42
|
-
IRectangle,
|
|
43
45
|
IsComplex,
|
|
44
46
|
TextPartFlag,
|
|
45
|
-
Table,
|
|
46
|
-
TableSortType,
|
|
47
|
-
TableSortOptions,
|
|
48
|
-
DefaultTableSortOptions,
|
|
49
47
|
} from 'treb-base-types';
|
|
50
48
|
|
|
51
|
-
import {
|
|
52
|
-
Parser,
|
|
53
|
-
|
|
49
|
+
import type {
|
|
50
|
+
Parser,
|
|
51
|
+
ExpressionUnit} from 'treb-parser';
|
|
52
|
+
import {
|
|
53
|
+
DecimalMarkType,
|
|
54
|
+
ArgumentSeparatorType,
|
|
54
55
|
QuotedSheetNameRegex,
|
|
55
|
-
MDParser
|
|
56
|
+
MDParser,
|
|
56
57
|
} from 'treb-parser';
|
|
57
58
|
|
|
58
59
|
import { Yield, SerializeHTML } from 'treb-utils';
|
|
59
|
-
import {
|
|
60
|
+
import type { ParseResult as ParseResult2 } from 'treb-format';
|
|
61
|
+
import { NumberFormatCache, LotusDate, ValueParser, Hints, NumberFormat } from 'treb-format';
|
|
60
62
|
import { SelectionRenderer } from '../render/selection-renderer';
|
|
61
63
|
|
|
62
64
|
import { TabBar } from './tab_bar';
|
|
63
65
|
import type { StatsEntry } from './tab_bar';
|
|
64
66
|
|
|
65
67
|
import { Sheet } from './sheet';
|
|
66
|
-
import {
|
|
68
|
+
import type { BaseLayout } from '../layout/base_layout';
|
|
69
|
+
import { TileRange } from '../layout/base_layout';
|
|
67
70
|
|
|
68
71
|
// this was conditional compilation. we're dropping as we no longer support IE11.
|
|
69
72
|
// import { CreateLayout } from '@grid-conditional/layout_manager';
|
|
@@ -77,8 +80,9 @@ import type { GridSelection } from './grid_selection';
|
|
|
77
80
|
import { OverlayEditor, OverlayEditorResult } from '../editors/overlay_editor';
|
|
78
81
|
|
|
79
82
|
import { TileRenderer } from '../render/tile_renderer';
|
|
80
|
-
import {
|
|
81
|
-
import
|
|
83
|
+
import type { GridEvent } from './grid_events';
|
|
84
|
+
import { ErrorCode } from './grid_events';
|
|
85
|
+
import type { LegacySerializedSheet } from './sheet_types';
|
|
82
86
|
import { FormulaBar } from '../editors/formula_bar';
|
|
83
87
|
import type { GridOptions } from './grid_options';
|
|
84
88
|
import { BorderConstants } from './border_constants';
|
|
@@ -89,37 +93,24 @@ import { Autocomplete } from '../editors/autocomplete';
|
|
|
89
93
|
|
|
90
94
|
import { MouseDrag } from './drag_mask';
|
|
91
95
|
|
|
92
|
-
import {
|
|
93
|
-
Command,
|
|
96
|
+
import type {
|
|
97
|
+
Command,
|
|
94
98
|
SetRangeCommand, FreezeCommand,
|
|
95
99
|
InsertRowsCommand, InsertColumnsCommand, SetNameCommand,
|
|
96
|
-
ActivateSheetCommand,
|
|
97
|
-
|
|
100
|
+
ActivateSheetCommand, DataValidationCommand,
|
|
101
|
+
ResizeRowsCommand, ResizeColumnsCommand,
|
|
98
102
|
SelectCommand
|
|
99
103
|
} from './grid_command';
|
|
104
|
+
import { CommandKey
|
|
105
|
+
} from './grid_command';
|
|
100
106
|
|
|
101
107
|
import type { DataModel, SerializedModel } from './data_model';
|
|
102
108
|
|
|
103
109
|
import { DOMUtilities } from '../util/dom_utilities';
|
|
104
110
|
import { GridBase } from './grid_base';
|
|
105
111
|
import type { SetRangeOptions } from './set_range_options';
|
|
106
|
-
|
|
107
|
-
// can we move style to embed? [TEMP]
|
|
108
|
-
// import '../../style/grid-layout.scss';
|
|
109
|
-
// import '../../style/grid.scss';
|
|
110
|
-
|
|
111
112
|
import type { ClipboardCellData } from './clipboard_data';
|
|
112
113
|
|
|
113
|
-
/*
|
|
114
|
-
interface ClipboardCellData {
|
|
115
|
-
address: ICellAddress;
|
|
116
|
-
data: CellValue;
|
|
117
|
-
type: ValueType;
|
|
118
|
-
style?: Style.Properties;
|
|
119
|
-
array?: {rows: number, columns: number};
|
|
120
|
-
}
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
114
|
interface DoubleClickData {
|
|
124
115
|
timeout?: number;
|
|
125
116
|
address?: ICellAddress;
|
|
@@ -298,16 +289,6 @@ export class Grid extends GridBase {
|
|
|
298
289
|
empty: true,
|
|
299
290
|
};
|
|
300
291
|
|
|
301
|
-
/* *
|
|
302
|
-
* this selection is for highlighting only
|
|
303
|
-
* /
|
|
304
|
-
private readonly highlight_selection: GridSelection = {
|
|
305
|
-
target: { row: 0, column: 0 },
|
|
306
|
-
area: new Area({ row: 0, column: 0 }),
|
|
307
|
-
empty: true,
|
|
308
|
-
};
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
292
|
/**
|
|
312
293
|
* active selection when selecting arguments (while editing)
|
|
313
294
|
*/
|
|
@@ -322,19 +303,6 @@ export class Grid extends GridBase {
|
|
|
322
303
|
*/
|
|
323
304
|
private nub_select_flag = false;
|
|
324
305
|
|
|
325
|
-
/**
|
|
326
|
-
* current mouse move cell
|
|
327
|
-
*/
|
|
328
|
-
// private hover_cell: ICellAddress = { row: -1, column: -1 };
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* flag indicating we're showing a note, so we can stop
|
|
332
|
-
*/
|
|
333
|
-
// private hover_note_visible = false;
|
|
334
|
-
|
|
335
|
-
/** same for title/link info */
|
|
336
|
-
// private hover_tracking_link = false;
|
|
337
|
-
|
|
338
306
|
/**
|
|
339
307
|
* additional selections that are rendered but not otherwise used.
|
|
340
308
|
* this array is now readonly, so we can bind it to the selection
|
|
@@ -365,20 +333,10 @@ export class Grid extends GridBase {
|
|
|
365
333
|
/** */
|
|
366
334
|
private selection_renderer: SelectionRenderer;
|
|
367
335
|
|
|
368
|
-
// FIXME: move
|
|
336
|
+
// FIXME: move [why?]
|
|
369
337
|
|
|
370
|
-
// private tab_bar?: HTMLElement;
|
|
371
338
|
private tab_bar?: TabBar;
|
|
372
339
|
|
|
373
|
-
/**
|
|
374
|
-
* replacement for global style default properties.
|
|
375
|
-
* FIXME: move (model?)
|
|
376
|
-
*
|
|
377
|
-
* SEE comment in sheet class
|
|
378
|
-
*/
|
|
379
|
-
//private readonly theme_style_properties: Style.Properties =
|
|
380
|
-
// Style.Composite([Style.DefaultProperties]);
|
|
381
|
-
|
|
382
340
|
// --- constructor -----------------------------------------------------------
|
|
383
341
|
|
|
384
342
|
/**
|
|
@@ -488,24 +446,6 @@ export class Grid extends GridBase {
|
|
|
488
446
|
|
|
489
447
|
}
|
|
490
448
|
|
|
491
|
-
/**
|
|
492
|
-
* set hyperlink, like set note
|
|
493
|
-
*/
|
|
494
|
-
public SetLink(address?: ICellAddress, reference?: string): void {
|
|
495
|
-
|
|
496
|
-
if (!address) {
|
|
497
|
-
if (this.primary_selection.empty) return;
|
|
498
|
-
address = this.primary_selection.target;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
this.ExecCommand({
|
|
502
|
-
key: CommandKey.SetLink,
|
|
503
|
-
area: address,
|
|
504
|
-
reference,
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
|
|
509
449
|
/** find an annotation, given a node */
|
|
510
450
|
public FindAnnotation(node: HTMLElement): Annotation|undefined {
|
|
511
451
|
for (const annotation of this.active_sheet.annotations) {
|
|
@@ -528,7 +468,7 @@ export class Grid extends GridBase {
|
|
|
528
468
|
* @param target new parameter allows setting annotation as rect or as
|
|
529
469
|
* cell range
|
|
530
470
|
*/
|
|
531
|
-
public CreateAnnotation(properties:
|
|
471
|
+
public CreateAnnotation(properties: Partial<Annotation> = {}, add_to_sheet = true, offset = false, target?: Partial<Area>|IRectangle): Annotation {
|
|
532
472
|
const annotation = new Annotation(properties as Partial<Annotation>);
|
|
533
473
|
|
|
534
474
|
if (offset) {
|
|
@@ -583,31 +523,6 @@ export class Grid extends GridBase {
|
|
|
583
523
|
return annotation;
|
|
584
524
|
}
|
|
585
525
|
|
|
586
|
-
/*
|
|
587
|
-
public UpdateScale(scale = 1): void {
|
|
588
|
-
|
|
589
|
-
this.layout.scale = scale;
|
|
590
|
-
this.UpdateLayout();
|
|
591
|
-
this.UpdateAnnotationLayout();
|
|
592
|
-
this.layout.UpdateAnnotation(this.active_sheet.annotations);
|
|
593
|
-
this.layout.ApplyTheme(this.theme);
|
|
594
|
-
this.overlay_editor?.UpdateTheme(scale);
|
|
595
|
-
this.tab_bar?.UpdateScale(scale);
|
|
596
|
-
|
|
597
|
-
this.grid_events.Publish({
|
|
598
|
-
type: 'scale',
|
|
599
|
-
scale,
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
for (const sheet of this.model.sheets.list) {
|
|
603
|
-
for (const annotation of sheet.annotations) {
|
|
604
|
-
annotation.dirty = true;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
*/
|
|
610
|
-
|
|
611
526
|
/** placeholder */
|
|
612
527
|
public UpdateAnnotationLayout(): void {
|
|
613
528
|
// ...
|
|
@@ -861,11 +776,6 @@ export class Grid extends GridBase {
|
|
|
861
776
|
if (annotation === this.active_sheet.annotations[i]) {
|
|
862
777
|
this.active_sheet.annotations.splice(i, 1);
|
|
863
778
|
|
|
864
|
-
/*
|
|
865
|
-
if (annotation.node && annotation.node.parentElement) {
|
|
866
|
-
annotation.node.parentElement.removeChild(annotation.node);
|
|
867
|
-
}
|
|
868
|
-
*/
|
|
869
779
|
this.layout.RemoveAnnotation(annotation);
|
|
870
780
|
|
|
871
781
|
this.grid_events.Publish({
|
|
@@ -911,80 +821,6 @@ export class Grid extends GridBase {
|
|
|
911
821
|
|
|
912
822
|
}
|
|
913
823
|
|
|
914
|
-
/**
|
|
915
|
-
* clear sheet, reset all data
|
|
916
|
-
*/
|
|
917
|
-
public Reset(): void {
|
|
918
|
-
this.ExecCommand({ key: CommandKey.Reset });
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* reset sheet, set data from CSV
|
|
923
|
-
*
|
|
924
|
-
* FIXME: this is problematic, because it runs around the exec command
|
|
925
|
-
* system. however it doesn't seem like a good candidate for a separate
|
|
926
|
-
* command. it should maybe move to the import class? (...)
|
|
927
|
-
*
|
|
928
|
-
* one problem with that is that import is really, really heavy (jszip).
|
|
929
|
-
* it seems wasteful to require all that just to import csv.
|
|
930
|
-
*/
|
|
931
|
-
public FromCSV(text: string): void {
|
|
932
|
-
|
|
933
|
-
// CSV assumes dot-decimal, correct? if we want to use the
|
|
934
|
-
// parser we will have to check (and set/reset) the separator
|
|
935
|
-
|
|
936
|
-
const toggle_separator = this.parser.decimal_mark === DecimalMarkType.Comma;
|
|
937
|
-
|
|
938
|
-
if (toggle_separator) {
|
|
939
|
-
// swap
|
|
940
|
-
this.parser.argument_separator = ArgumentSeparatorType.Comma;
|
|
941
|
-
this.parser.decimal_mark = DecimalMarkType.Period;
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
const records = ParseCSV(text);
|
|
945
|
-
const arr = records.map((record) =>
|
|
946
|
-
record.map((field) => {
|
|
947
|
-
if (field) {
|
|
948
|
-
const tmp = this.parser.Parse(field);
|
|
949
|
-
if (tmp.expression?.type === 'complex') {
|
|
950
|
-
return tmp.expression as Complex;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return ValueParser.TryParse(field).value;
|
|
954
|
-
}));
|
|
955
|
-
|
|
956
|
-
if (toggle_separator) {
|
|
957
|
-
// reset
|
|
958
|
-
this.parser.argument_separator = ArgumentSeparatorType.Semicolon;
|
|
959
|
-
this.parser.decimal_mark = DecimalMarkType.Comma;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
const end = {
|
|
963
|
-
row: Math.max(0, arr.length - 1),
|
|
964
|
-
column: arr.reduce((max, row) => Math.max(max, Math.max(0, row.length - 1)), 0),
|
|
965
|
-
};
|
|
966
|
-
|
|
967
|
-
// NOTE: SetRange here does not need to be translated, because
|
|
968
|
-
// we're not expecting spreadsheet functions in the CSV. CSV should
|
|
969
|
-
// be data only. Famous last words.
|
|
970
|
-
|
|
971
|
-
this.ExecCommand([
|
|
972
|
-
{ key: CommandKey.Reset },
|
|
973
|
-
{
|
|
974
|
-
key: CommandKey.SetRange,
|
|
975
|
-
area: { start: { row: 0, column: 0 }, end },
|
|
976
|
-
value: arr,
|
|
977
|
-
},
|
|
978
|
-
|
|
979
|
-
// we took this out because the data may require a layout update
|
|
980
|
-
// (rebuilding tiles); in that case, this will be duplicative. maybe
|
|
981
|
-
// should use setTimeout or some sort of queue...
|
|
982
|
-
|
|
983
|
-
// { key: CommandKey.ResizeColumns }, // auto
|
|
984
|
-
]);
|
|
985
|
-
|
|
986
|
-
}
|
|
987
|
-
|
|
988
824
|
/**
|
|
989
825
|
* show or hide headers
|
|
990
826
|
*
|
|
@@ -1179,65 +1015,6 @@ export class Grid extends GridBase {
|
|
|
1179
1015
|
|
|
1180
1016
|
}
|
|
1181
1017
|
|
|
1182
|
-
/* *
|
|
1183
|
-
* why does this not take the composite object? (...)
|
|
1184
|
-
* A: it's used for xlsx import. still, we could wrap it.
|
|
1185
|
-
* /
|
|
1186
|
-
public FromData(
|
|
1187
|
-
cell_data: any[],
|
|
1188
|
-
column_widths: number[],
|
|
1189
|
-
row_heights: number[],
|
|
1190
|
-
styles: Style.Properties[],
|
|
1191
|
-
render = false): void {
|
|
1192
|
-
|
|
1193
|
-
this.RemoveAnnotationNodes();
|
|
1194
|
-
|
|
1195
|
-
this.UpdateSheets([Sheet.Blank(this.theme_style_properties).toJSON()], true);
|
|
1196
|
-
|
|
1197
|
-
// FIXME: are there named ranges in the data? (...)
|
|
1198
|
-
|
|
1199
|
-
this.model.named_ranges.Reset();
|
|
1200
|
-
this.model.macro_functions = {};
|
|
1201
|
-
|
|
1202
|
-
this.ClearSelection(this.primary_selection);
|
|
1203
|
-
|
|
1204
|
-
this.cells.FromJSON(cell_data);
|
|
1205
|
-
|
|
1206
|
-
// 0 is implicitly just a general style
|
|
1207
|
-
|
|
1208
|
-
const cs = (this.active_sheet as any).cell_style;
|
|
1209
|
-
for (const info of cell_data) {
|
|
1210
|
-
if (info.style_ref) {
|
|
1211
|
-
if (!cs[info.column]) cs[info.column] = [];
|
|
1212
|
-
cs[info.column][info.row] = styles[info.style_ref];
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
for (let i = 0; i < column_widths.length; i++) {
|
|
1217
|
-
if (typeof column_widths[i] !== 'undefined') {
|
|
1218
|
-
this.active_sheet.SetColumnWidth(i, column_widths[i]);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
for (let i = 0; i < row_heights.length; i++) {
|
|
1223
|
-
if (typeof row_heights[i] !== 'undefined') {
|
|
1224
|
-
this.active_sheet.SetRowHeight(i, row_heights[i]);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// no longer sending explicit layout event here
|
|
1229
|
-
|
|
1230
|
-
this.QueueLayoutUpdate();
|
|
1231
|
-
|
|
1232
|
-
this.StyleDefaultFromTheme();
|
|
1233
|
-
|
|
1234
|
-
if (render) {
|
|
1235
|
-
this.Repaint(false, false); // true, true);
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
}
|
|
1239
|
-
*/
|
|
1240
|
-
|
|
1241
1018
|
/**
|
|
1242
1019
|
* This function is called via Shift+PageUp/PageDown. We need
|
|
1243
1020
|
* to update to account for hidden sheets, which can't be activated.
|
|
@@ -1273,149 +1050,6 @@ export class Grid extends GridBase {
|
|
|
1273
1050
|
|
|
1274
1051
|
}
|
|
1275
1052
|
|
|
1276
|
-
/** insert sheet at the given index (or current index) */
|
|
1277
|
-
public InsertSheet(index?: number, name?: string): void {
|
|
1278
|
-
|
|
1279
|
-
if (typeof index === 'undefined') {
|
|
1280
|
-
if (!this.model.sheets.list.some((sheet, i) => {
|
|
1281
|
-
if (sheet === this.active_sheet) {
|
|
1282
|
-
index = i + 1;
|
|
1283
|
-
return true;
|
|
1284
|
-
}
|
|
1285
|
-
return false;
|
|
1286
|
-
})) {
|
|
1287
|
-
throw new Error('invalid index');
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
this.ExecCommand({
|
|
1292
|
-
key: CommandKey.AddSheet,
|
|
1293
|
-
insert_index: index,
|
|
1294
|
-
name,
|
|
1295
|
-
show: true,
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
public DeleteSheetID(id: number): void {
|
|
1301
|
-
this.ExecCommand({
|
|
1302
|
-
key: CommandKey.DeleteSheet,
|
|
1303
|
-
id,
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
/**
|
|
1308
|
-
* delete sheet, by index or (omitting index) the current active sheet
|
|
1309
|
-
*/
|
|
1310
|
-
public DeleteSheet(index?: number): void {
|
|
1311
|
-
|
|
1312
|
-
if (typeof index === 'undefined') {
|
|
1313
|
-
if (!this.model.sheets.list.some((sheet, i) => {
|
|
1314
|
-
if (sheet === this.active_sheet) {
|
|
1315
|
-
index = i;
|
|
1316
|
-
return true;
|
|
1317
|
-
}
|
|
1318
|
-
return false;
|
|
1319
|
-
})) {
|
|
1320
|
-
throw new Error('invalid index');
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
this.ExecCommand({
|
|
1325
|
-
key: CommandKey.DeleteSheet,
|
|
1326
|
-
index,
|
|
1327
|
-
});
|
|
1328
|
-
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* duplicate sheet by index or (omitting index) the current active sheet
|
|
1333
|
-
*/
|
|
1334
|
-
public DuplicateSheet(index?: number, name?: string, insert_before?: number|string): void {
|
|
1335
|
-
|
|
1336
|
-
const command: DuplicateSheetCommand = {
|
|
1337
|
-
key: CommandKey.DuplicateSheet,
|
|
1338
|
-
new_name: name,
|
|
1339
|
-
insert_before,
|
|
1340
|
-
};
|
|
1341
|
-
|
|
1342
|
-
if (typeof index === 'undefined') {
|
|
1343
|
-
command.id = this.active_sheet.id;
|
|
1344
|
-
}
|
|
1345
|
-
else {
|
|
1346
|
-
command.index = index;
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
this.ExecCommand(command);
|
|
1350
|
-
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
public AddSheet(name?: string): void {
|
|
1354
|
-
this.ExecCommand({
|
|
1355
|
-
key: CommandKey.AddSheet,
|
|
1356
|
-
name,
|
|
1357
|
-
show: true,
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
/**
|
|
1362
|
-
* activate sheet, by name or index number
|
|
1363
|
-
* @param sheet number (index into the array) or string (name)
|
|
1364
|
-
*/
|
|
1365
|
-
public ActivateSheet(sheet: number | string): void {
|
|
1366
|
-
|
|
1367
|
-
const index = (typeof sheet === 'number') ? sheet : undefined;
|
|
1368
|
-
const name = (typeof sheet === 'string') ? sheet : undefined;
|
|
1369
|
-
|
|
1370
|
-
this.ExecCommand({
|
|
1371
|
-
key: CommandKey.ActivateSheet,
|
|
1372
|
-
index,
|
|
1373
|
-
name,
|
|
1374
|
-
});
|
|
1375
|
-
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
/**
|
|
1379
|
-
* activate sheet, by ID
|
|
1380
|
-
*/
|
|
1381
|
-
public ActivateSheetID(id: number): void {
|
|
1382
|
-
this.ExecCommand({
|
|
1383
|
-
key: CommandKey.ActivateSheet,
|
|
1384
|
-
id,
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
public ShowAll(): void {
|
|
1389
|
-
|
|
1390
|
-
// obviously there are better ways to do this, but this
|
|
1391
|
-
// will use the execcommand system and _should_ only fire
|
|
1392
|
-
// a single event (FIXME: check)
|
|
1393
|
-
|
|
1394
|
-
const commands: ShowSheetCommand[] = [];
|
|
1395
|
-
for (let index = 0; index < this.model.sheets.length; index++) {
|
|
1396
|
-
commands.push({
|
|
1397
|
-
key: CommandKey.ShowSheet,
|
|
1398
|
-
index,
|
|
1399
|
-
show: true,
|
|
1400
|
-
});
|
|
1401
|
-
}
|
|
1402
|
-
this.ExecCommand(commands);
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
public ShowSheet(index: number|string = 0, show = true): void {
|
|
1406
|
-
|
|
1407
|
-
const command: ShowSheetCommand = {
|
|
1408
|
-
key: CommandKey.ShowSheet,
|
|
1409
|
-
show,
|
|
1410
|
-
};
|
|
1411
|
-
|
|
1412
|
-
if (typeof index === 'string') { command.name = index; }
|
|
1413
|
-
else { command.index = index; }
|
|
1414
|
-
|
|
1415
|
-
this.ExecCommand(command);
|
|
1416
|
-
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
1053
|
/**
|
|
1420
1054
|
* UpdateSheets means "set these as the sheets, drop any old stuff".
|
|
1421
1055
|
* there's an implicit reset (in fact we may do that twice in some
|
|
@@ -1512,16 +1146,6 @@ export class Grid extends GridBase {
|
|
|
1512
1146
|
this.Repaint(true);
|
|
1513
1147
|
}
|
|
1514
1148
|
|
|
1515
|
-
/* *
|
|
1516
|
-
* splitting the old UpdateTheme, since that is becoming more
|
|
1517
|
-
* important for post-constructor theme updates, and the name applies
|
|
1518
|
-
* more to that function than to what we do at startup.
|
|
1519
|
-
* /
|
|
1520
|
-
public ApplyTheme(): void {
|
|
1521
|
-
this.UpdateTheme(true);
|
|
1522
|
-
}
|
|
1523
|
-
*/
|
|
1524
|
-
|
|
1525
1149
|
/**
|
|
1526
1150
|
* @param initial first call, from the grid Initialize() method
|
|
1527
1151
|
*/
|
|
@@ -2235,32 +1859,6 @@ export class Grid extends GridBase {
|
|
|
2235
1859
|
|
|
2236
1860
|
}
|
|
2237
1861
|
|
|
2238
|
-
/**
|
|
2239
|
-
* API method
|
|
2240
|
-
*/
|
|
2241
|
-
public SetRowHeight(row?: number | number[], height?: number, shrink = true): void {
|
|
2242
|
-
this.ExecCommand({
|
|
2243
|
-
key: CommandKey.ResizeRows,
|
|
2244
|
-
row,
|
|
2245
|
-
height,
|
|
2246
|
-
shrink,
|
|
2247
|
-
});
|
|
2248
|
-
}
|
|
2249
|
-
|
|
2250
|
-
/**
|
|
2251
|
-
* API method
|
|
2252
|
-
*
|
|
2253
|
-
* @param column column, columns, or undefined means all columns
|
|
2254
|
-
* @param width target width, or undefined means auto-size
|
|
2255
|
-
*/
|
|
2256
|
-
public SetColumnWidth(column?: number | number[], width = 0): void {
|
|
2257
|
-
this.ExecCommand({
|
|
2258
|
-
key: CommandKey.ResizeColumns,
|
|
2259
|
-
column,
|
|
2260
|
-
width,
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
1862
|
/**
|
|
2265
1863
|
* applies the given style properties to the passed array, or to the
|
|
2266
1864
|
* current primary selection
|
|
@@ -2306,14 +1904,14 @@ export class Grid extends GridBase {
|
|
|
2306
1904
|
this.DelayedRender(force, area);
|
|
2307
1905
|
}
|
|
2308
1906
|
|
|
2309
|
-
|
|
1907
|
+
/* *
|
|
2310
1908
|
* API method
|
|
2311
1909
|
*
|
|
2312
1910
|
* @param area
|
|
2313
1911
|
* @param borders
|
|
2314
1912
|
* @param color
|
|
2315
1913
|
* @param width
|
|
2316
|
-
|
|
1914
|
+
* /
|
|
2317
1915
|
public ApplyBorders(area?: Area, borders: BorderConstants = BorderConstants.None, color?: string, width = 1): void {
|
|
2318
1916
|
|
|
2319
1917
|
if (!area) {
|
|
@@ -2334,6 +1932,7 @@ export class Grid extends GridBase {
|
|
|
2334
1932
|
});
|
|
2335
1933
|
|
|
2336
1934
|
}
|
|
1935
|
+
*/
|
|
2337
1936
|
|
|
2338
1937
|
/** updated API method, probably change the name */
|
|
2339
1938
|
public ApplyBorders2(area?: Area, borders: BorderConstants = BorderConstants.None, color?: Style.Color, width = 1): void {
|
|
@@ -2357,24 +1956,6 @@ export class Grid extends GridBase {
|
|
|
2357
1956
|
|
|
2358
1957
|
}
|
|
2359
1958
|
|
|
2360
|
-
/** return freeze area */
|
|
2361
|
-
public GetFreeze(): FreezePane {
|
|
2362
|
-
return { ...this.active_sheet.freeze };
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
/**
|
|
2366
|
-
* freeze rows or columns. set to 0 (or call with no arguments) to un-freeze.
|
|
2367
|
-
*
|
|
2368
|
-
* highglight is shown by default, but we can hide it(mostly for document load)
|
|
2369
|
-
*/
|
|
2370
|
-
public Freeze(rows = 0, columns = 0, highlight_transition = true): void {
|
|
2371
|
-
this.ExecCommand({
|
|
2372
|
-
key: CommandKey.Freeze,
|
|
2373
|
-
rows,
|
|
2374
|
-
columns,
|
|
2375
|
-
highlight_transition,
|
|
2376
|
-
});
|
|
2377
|
-
}
|
|
2378
1959
|
|
|
2379
1960
|
/**
|
|
2380
1961
|
* batch updates. returns all the events that _would_ have been sent.
|
|
@@ -2396,66 +1977,7 @@ export class Grid extends GridBase {
|
|
|
2396
1977
|
return events;
|
|
2397
1978
|
}
|
|
2398
1979
|
|
|
2399
|
-
/**
|
|
2400
|
-
* insert column(s) at some specific point
|
|
2401
|
-
*/
|
|
2402
|
-
public InsertColumns(before_column = 0, count = 1): void {
|
|
2403
|
-
this.ExecCommand({
|
|
2404
|
-
key: CommandKey.InsertColumns,
|
|
2405
|
-
before_column,
|
|
2406
|
-
count,
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
/** move sheet (X) before sheet (Y) */
|
|
2411
|
-
public ReorderSheet(index: number, move_before: number): void {
|
|
2412
|
-
this.ExecCommand({
|
|
2413
|
-
key: CommandKey.ReorderSheet,
|
|
2414
|
-
index,
|
|
2415
|
-
move_before,
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
|
|
2419
|
-
/**
|
|
2420
|
-
* rename active sheet
|
|
2421
|
-
*/
|
|
2422
|
-
public RenameSheet(sheet: Sheet, name: string): void {
|
|
2423
|
-
this.ExecCommand({
|
|
2424
|
-
key: CommandKey.RenameSheet,
|
|
2425
|
-
new_name: name,
|
|
2426
|
-
id: sheet.id,
|
|
2427
|
-
});
|
|
2428
|
-
}
|
|
2429
|
-
|
|
2430
|
-
/* *
|
|
2431
|
-
* insert row at cursor
|
|
2432
|
-
* /
|
|
2433
|
-
public InsertRow(): void {
|
|
2434
|
-
if (this.primary_selection.empty) { return; }
|
|
2435
|
-
const area = this.primary_selection.area;
|
|
2436
|
-
const before_row = area.entire_column ? 0 : area.start.row;
|
|
2437
|
-
this.InsertRows(before_row, 1);
|
|
2438
|
-
}
|
|
2439
|
-
*/
|
|
2440
|
-
|
|
2441
|
-
/**
|
|
2442
|
-
* insert rows(s) at some specific point
|
|
2443
|
-
*/
|
|
2444
|
-
public InsertRows(before_row = 0, count = 1): void {
|
|
2445
|
-
this.ExecCommand({
|
|
2446
|
-
key: CommandKey.InsertRows,
|
|
2447
|
-
before_row,
|
|
2448
|
-
count,
|
|
2449
|
-
});
|
|
2450
|
-
}
|
|
2451
1980
|
|
|
2452
|
-
/**
|
|
2453
|
-
* return the table (if any) at the given address
|
|
2454
|
-
*/
|
|
2455
|
-
public GetTableReference(address: ICellAddress): Table|undefined {
|
|
2456
|
-
const sheet = this.model.sheets.Find(address.sheet_id || this.active_sheet.id);
|
|
2457
|
-
return sheet?.CellData(address).table || undefined;
|
|
2458
|
-
}
|
|
2459
1981
|
|
|
2460
1982
|
/**
|
|
2461
1983
|
* scrolls so that the given cell is in the top-left (assuming that is
|
|
@@ -2828,44 +2350,17 @@ export class Grid extends GridBase {
|
|
|
2828
2350
|
*/
|
|
2829
2351
|
private HighlightFreezeArea() {
|
|
2830
2352
|
|
|
2831
|
-
|
|
2353
|
+
for (const node of [
|
|
2832
2354
|
this.layout.corner_selection,
|
|
2833
2355
|
this.layout.row_header_selection,
|
|
2834
2356
|
this.layout.column_header_selection]) {
|
|
2835
2357
|
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
//}
|
|
2843
|
-
//else {
|
|
2844
|
-
node.classList.add('highlight-area');
|
|
2845
|
-
//}
|
|
2846
|
-
|
|
2847
|
-
/*
|
|
2848
|
-
node.style.transition = 'background .33s, border-bottom-color .33s, border-right-color .33s';
|
|
2849
|
-
node.style.background = this.theme.frozen_highlight_overlay;
|
|
2850
|
-
|
|
2851
|
-
if (this.theme.frozen_highlight_border) {
|
|
2852
|
-
node.style.borderBottomColor = this.theme.frozen_highlight_border;
|
|
2853
|
-
node.style.borderRightColor = this.theme.frozen_highlight_border;
|
|
2854
|
-
}
|
|
2855
|
-
*/
|
|
2856
|
-
|
|
2857
|
-
setTimeout(() => {
|
|
2858
|
-
//if (UA.trident) {
|
|
2859
|
-
// node.setAttribute('class', base_class);
|
|
2860
|
-
//}
|
|
2861
|
-
//else {
|
|
2862
|
-
node.classList.remove('highlight-area');
|
|
2863
|
-
//}
|
|
2864
|
-
// node.style.background = 'transparent';
|
|
2865
|
-
// node.style.borderBottomColor = 'transparent';
|
|
2866
|
-
// node.style.borderRightColor = 'transparent';
|
|
2867
|
-
}, 400);
|
|
2868
|
-
}
|
|
2358
|
+
node.classList.add('highlight-area');
|
|
2359
|
+
setTimeout(() => {
|
|
2360
|
+
node.classList.remove('highlight-area');
|
|
2361
|
+
}, 400);
|
|
2362
|
+
|
|
2363
|
+
}
|
|
2869
2364
|
|
|
2870
2365
|
}
|
|
2871
2366
|
|
|
@@ -6349,22 +5844,6 @@ export class Grid extends GridBase {
|
|
|
6349
5844
|
|
|
6350
5845
|
}
|
|
6351
5846
|
|
|
6352
|
-
/**
|
|
6353
|
-
* add an additional selection to the list. don't add it if already
|
|
6354
|
-
* on the list (don't stack).
|
|
6355
|
-
*
|
|
6356
|
-
* we now support empty selections (hiding) in the case of references
|
|
6357
|
-
* to other sheets. if we don't do that, the colors get out of sync.
|
|
6358
|
-
*/
|
|
6359
|
-
private AddAdditionalSelection(target: ICellAddress, area: Area): boolean {
|
|
6360
|
-
const label = area.spreadsheet_label;
|
|
6361
|
-
if (this.additional_selections.some((test) => {
|
|
6362
|
-
return (test.area.spreadsheet_label === label);
|
|
6363
|
-
})) return false;
|
|
6364
|
-
this.additional_selections.push({ target, area });
|
|
6365
|
-
return true;
|
|
6366
|
-
}
|
|
6367
|
-
|
|
6368
5847
|
/** remove all additonla (argument) selections */
|
|
6369
5848
|
private ClearAdditionalSelections() {
|
|
6370
5849
|
|
|
@@ -6761,11 +6240,6 @@ export class Grid extends GridBase {
|
|
|
6761
6240
|
|
|
6762
6241
|
// mouse down events for selection
|
|
6763
6242
|
this.layout.grid_cover.addEventListener('mousedown', (event) => this.MouseDown_Grid(event));
|
|
6764
|
-
//this.layout.grid_cover.addEventListener('mouseup', () => {
|
|
6765
|
-
// // console.info('cfu', this.capture);
|
|
6766
|
-
// this.Focus();
|
|
6767
|
-
//})
|
|
6768
|
-
|
|
6769
6243
|
this.layout.column_header_cover.addEventListener('mousedown', (event) => this.MouseDown_ColumnHeader(event));
|
|
6770
6244
|
this.layout.row_header_cover.addEventListener('mousedown', (event) => this.MouseDown_RowHeader(event));
|
|
6771
6245
|
|
|
@@ -6780,12 +6254,6 @@ export class Grid extends GridBase {
|
|
|
6780
6254
|
// this.container.addEventListener('keydown', (event) => this.KeyDown(event));
|
|
6781
6255
|
this.overlay_editor?.edit_node.addEventListener('keydown', (event) => this.OverlayKeyDown(event));
|
|
6782
6256
|
|
|
6783
|
-
/*
|
|
6784
|
-
this.container.addEventListener('compositionstart', (event) => {
|
|
6785
|
-
console.info('composition start!');
|
|
6786
|
-
});
|
|
6787
|
-
*/
|
|
6788
|
-
|
|
6789
6257
|
// select all?
|
|
6790
6258
|
this.layout.corner.addEventListener('dblclick', () => {
|
|
6791
6259
|
this.SelectAll();
|
|
@@ -6794,6 +6262,7 @@ export class Grid extends GridBase {
|
|
|
6794
6262
|
// this is for resize: we want to repaint on scale events. we should
|
|
6795
6263
|
// probably not do this synchronously, because scale changes are usually
|
|
6796
6264
|
// repeated.
|
|
6265
|
+
|
|
6797
6266
|
window.addEventListener('resize', () => {
|
|
6798
6267
|
const update = this.layout.UpdateDPR();
|
|
6799
6268
|
if (update) {
|
|
@@ -7084,6 +6553,11 @@ export class Grid extends GridBase {
|
|
|
7084
6553
|
area.Resize(paste_areas[0].rows, paste_areas[0].columns);
|
|
7085
6554
|
}
|
|
7086
6555
|
|
|
6556
|
+
if (!this.ValidatePasteAreas(paste_areas)) {
|
|
6557
|
+
this.Error(ErrorCode.invalid_area_for_paste);
|
|
6558
|
+
return;
|
|
6559
|
+
}
|
|
6560
|
+
|
|
7087
6561
|
// paste in, offsetting for the paste area. this part loops
|
|
7088
6562
|
// when recycling, so that the offsets are corrected
|
|
7089
6563
|
|
|
@@ -7124,14 +6598,6 @@ export class Grid extends GridBase {
|
|
|
7124
6598
|
}
|
|
7125
6599
|
}
|
|
7126
6600
|
|
|
7127
|
-
/*
|
|
7128
|
-
const cell = this.model.sheet.cells.GetCell(target_address, true);
|
|
7129
|
-
if (cell) {
|
|
7130
|
-
cell.Set(data);
|
|
7131
|
-
this.model.sheet.UpdateCellStyle(target_address, cell_info.style, false, true);
|
|
7132
|
-
}
|
|
7133
|
-
*/
|
|
7134
|
-
|
|
7135
6601
|
if (cell_info.array) {
|
|
7136
6602
|
|
|
7137
6603
|
const target_array = {
|
|
@@ -7215,6 +6681,11 @@ export class Grid extends GridBase {
|
|
|
7215
6681
|
area.Resize(paste_areas[0].rows, paste_areas[0].columns);
|
|
7216
6682
|
}
|
|
7217
6683
|
|
|
6684
|
+
if (!this.ValidatePasteAreas(paste_areas)) {
|
|
6685
|
+
this.Error(ErrorCode.invalid_area_for_paste);
|
|
6686
|
+
return;
|
|
6687
|
+
}
|
|
6688
|
+
|
|
7218
6689
|
for (const paste_area of paste_areas) {
|
|
7219
6690
|
//for (let r = 0; r < lines.length; r++) {
|
|
7220
6691
|
for (let r = 0; r < source.length; r++) {
|