@trebco/treb 23.6.5 → 25.0.0-rc2
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/.eslintignore +8 -0
- package/.eslintrc.js +164 -0
- package/README-shadow-DOM.md +88 -0
- package/README.md +37 -130
- package/api-config.json +29 -0
- package/api-generator/api-generator-types.ts +82 -0
- package/api-generator/api-generator.ts +1172 -0
- package/api-generator/package.json +3 -0
- package/build/treb-spreadsheet.mjs +14 -0
- package/{treb.d.ts → build/treb.d.ts} +323 -271
- package/esbuild-custom-element.mjs +336 -0
- package/esbuild.js +305 -0
- package/package.json +49 -14
- package/treb-base-types/package.json +5 -0
- package/treb-base-types/src/api_types.ts +36 -0
- package/treb-base-types/src/area.ts +583 -0
- package/treb-base-types/src/basic_types.ts +45 -0
- package/treb-base-types/src/cell.ts +612 -0
- package/treb-base-types/src/cells.ts +1066 -0
- package/treb-base-types/src/color.ts +124 -0
- package/treb-base-types/src/import.ts +71 -0
- package/treb-base-types/src/index-standalone.ts +29 -0
- package/treb-base-types/src/index.ts +42 -0
- package/treb-base-types/src/layout.ts +47 -0
- package/treb-base-types/src/localization.ts +187 -0
- package/treb-base-types/src/rectangle.ts +145 -0
- package/treb-base-types/src/render_text.ts +72 -0
- package/treb-base-types/src/style.ts +545 -0
- package/treb-base-types/src/table.ts +109 -0
- package/treb-base-types/src/text_part.ts +54 -0
- package/treb-base-types/src/theme.ts +608 -0
- package/treb-base-types/src/union.ts +152 -0
- package/treb-base-types/src/value-type.ts +164 -0
- package/treb-base-types/style/resizable.css +59 -0
- package/treb-calculator/modern.tsconfig.json +11 -0
- package/treb-calculator/package.json +5 -0
- package/treb-calculator/src/calculator.ts +2546 -0
- package/treb-calculator/src/complex-math.ts +558 -0
- package/treb-calculator/src/dag/array-vertex.ts +198 -0
- package/treb-calculator/src/dag/graph.ts +951 -0
- package/treb-calculator/src/dag/leaf_vertex.ts +118 -0
- package/treb-calculator/src/dag/spreadsheet_vertex.ts +327 -0
- package/treb-calculator/src/dag/spreadsheet_vertex_base.ts +44 -0
- package/treb-calculator/src/dag/vertex.ts +352 -0
- package/treb-calculator/src/descriptors.ts +162 -0
- package/treb-calculator/src/expression-calculator.ts +1069 -0
- package/treb-calculator/src/function-error.ts +103 -0
- package/treb-calculator/src/function-library.ts +103 -0
- package/treb-calculator/src/functions/base-functions.ts +1214 -0
- package/treb-calculator/src/functions/checkbox.ts +164 -0
- package/treb-calculator/src/functions/complex-functions.ts +253 -0
- package/treb-calculator/src/functions/finance-functions.ts +399 -0
- package/treb-calculator/src/functions/information-functions.ts +102 -0
- package/treb-calculator/src/functions/matrix-functions.ts +182 -0
- package/treb-calculator/src/functions/sparkline.ts +335 -0
- package/treb-calculator/src/functions/statistics-functions.ts +350 -0
- package/treb-calculator/src/functions/text-functions.ts +298 -0
- package/treb-calculator/src/index.ts +27 -0
- package/treb-calculator/src/notifier-types.ts +59 -0
- package/treb-calculator/src/primitives.ts +428 -0
- package/treb-calculator/src/utilities.ts +305 -0
- package/treb-charts/package.json +5 -0
- package/treb-charts/src/chart-functions.ts +156 -0
- package/treb-charts/src/chart-types.ts +230 -0
- package/treb-charts/src/chart.ts +1288 -0
- package/treb-charts/src/index.ts +24 -0
- package/treb-charts/src/main.ts +37 -0
- package/treb-charts/src/rectangle.ts +52 -0
- package/treb-charts/src/renderer.ts +1841 -0
- package/treb-charts/src/util.ts +122 -0
- package/treb-charts/style/charts.scss +221 -0
- package/treb-charts/style/old-charts.scss +250 -0
- package/treb-embed/markup/layout.html +137 -0
- package/treb-embed/markup/toolbar.html +175 -0
- package/treb-embed/modern.tsconfig.json +25 -0
- package/treb-embed/src/custom-element/content-types.d.ts +18 -0
- package/treb-embed/src/custom-element/global.d.ts +11 -0
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +1228 -0
- package/treb-embed/src/custom-element/treb-global.ts +44 -0
- package/treb-embed/src/custom-element/treb-spreadsheet-element.ts +52 -0
- package/treb-embed/src/embedded-spreadsheet.ts +5358 -0
- package/treb-embed/src/index.ts +16 -0
- package/treb-embed/src/language-model.ts +41 -0
- package/treb-embed/src/options.ts +298 -0
- package/treb-embed/src/progress-dialog.ts +228 -0
- package/treb-embed/src/selection-state.ts +16 -0
- package/treb-embed/src/spinner.ts +42 -0
- package/treb-embed/src/toolbar-message.ts +96 -0
- package/treb-embed/src/types.ts +167 -0
- package/treb-embed/style/autocomplete.scss +103 -0
- package/treb-embed/style/dark-theme.scss +114 -0
- package/treb-embed/style/defaults.scss +36 -0
- package/treb-embed/style/dialog.scss +181 -0
- package/treb-embed/style/dropdown-select.scss +101 -0
- package/treb-embed/style/formula-bar.scss +193 -0
- package/treb-embed/style/grid.scss +374 -0
- package/treb-embed/style/layout.scss +424 -0
- package/treb-embed/style/mouse-mask.scss +67 -0
- package/treb-embed/style/note.scss +92 -0
- package/treb-embed/style/overlay-editor.scss +102 -0
- package/treb-embed/style/spinner.scss +92 -0
- package/treb-embed/style/tab-bar.scss +228 -0
- package/treb-embed/style/table.scss +80 -0
- package/treb-embed/style/theme-defaults.scss +444 -0
- package/treb-embed/style/toolbar.scss +416 -0
- package/treb-embed/style/tooltip.scss +68 -0
- package/treb-embed/style/treb-icons.scss +130 -0
- package/treb-embed/style/treb-spreadsheet-element.scss +20 -0
- package/treb-embed/style/z-index.scss +43 -0
- package/treb-export/docs/charts.md +68 -0
- package/treb-export/modern.tsconfig.json +19 -0
- package/treb-export/package.json +4 -0
- package/treb-export/src/address-type.ts +77 -0
- package/treb-export/src/base-template.ts +22 -0
- package/treb-export/src/column-width.ts +85 -0
- package/treb-export/src/drawing2/chart-template-components2.ts +389 -0
- package/treb-export/src/drawing2/chart2.ts +282 -0
- package/treb-export/src/drawing2/column-chart-template2.ts +521 -0
- package/treb-export/src/drawing2/donut-chart-template2.ts +296 -0
- package/treb-export/src/drawing2/drawing2.ts +355 -0
- package/treb-export/src/drawing2/embedded-image.ts +71 -0
- package/treb-export/src/drawing2/scatter-chart-template2.ts +555 -0
- package/treb-export/src/export-worker/export-worker.ts +99 -0
- package/treb-export/src/export-worker/index-modern.ts +22 -0
- package/treb-export/src/export2.ts +2204 -0
- package/treb-export/src/import2.ts +882 -0
- package/treb-export/src/relationship.ts +36 -0
- package/treb-export/src/shared-strings2.ts +128 -0
- package/treb-export/src/template-2.ts +22 -0
- package/treb-export/src/unescape_xml.ts +47 -0
- package/treb-export/src/workbook-sheet2.ts +182 -0
- package/treb-export/src/workbook-style2.ts +1285 -0
- package/treb-export/src/workbook-theme2.ts +88 -0
- package/treb-export/src/workbook2.ts +491 -0
- package/treb-export/src/xml-utils.ts +201 -0
- package/treb-export/template/base/[Content_Types].xml +2 -0
- package/treb-export/template/base/_rels/.rels +2 -0
- package/treb-export/template/base/docProps/app.xml +2 -0
- package/treb-export/template/base/docProps/core.xml +12 -0
- package/treb-export/template/base/xl/_rels/workbook.xml.rels +2 -0
- package/treb-export/template/base/xl/sharedStrings.xml +2 -0
- package/treb-export/template/base/xl/styles.xml +2 -0
- package/treb-export/template/base/xl/theme/theme1.xml +2 -0
- package/treb-export/template/base/xl/workbook.xml +2 -0
- package/treb-export/template/base/xl/worksheets/sheet1.xml +2 -0
- package/treb-export/template/base.xlsx +0 -0
- package/treb-format/package.json +8 -0
- package/treb-format/src/format.test.ts +213 -0
- package/treb-format/src/format.ts +942 -0
- package/treb-format/src/format_cache.ts +199 -0
- package/treb-format/src/format_parser.ts +723 -0
- package/treb-format/src/index.ts +25 -0
- package/treb-format/src/number_format_section.ts +100 -0
- package/treb-format/src/value_parser.ts +337 -0
- package/treb-grid/package.json +5 -0
- package/treb-grid/src/editors/autocomplete.ts +394 -0
- package/treb-grid/src/editors/autocomplete_matcher.ts +260 -0
- package/treb-grid/src/editors/formula_bar.ts +473 -0
- package/treb-grid/src/editors/formula_editor_base.ts +910 -0
- package/treb-grid/src/editors/overlay_editor.ts +511 -0
- package/treb-grid/src/index.ts +37 -0
- package/treb-grid/src/layout/base_layout.ts +2618 -0
- package/treb-grid/src/layout/grid_layout.ts +299 -0
- package/treb-grid/src/layout/rectangle_cache.ts +86 -0
- package/treb-grid/src/render/selection-renderer.ts +414 -0
- package/treb-grid/src/render/svg_header_overlay.ts +93 -0
- package/treb-grid/src/render/svg_selection_block.ts +187 -0
- package/treb-grid/src/render/tile_renderer.ts +2122 -0
- package/treb-grid/src/types/annotation.ts +216 -0
- package/treb-grid/src/types/border_constants.ts +34 -0
- package/treb-grid/src/types/clipboard_data.ts +31 -0
- package/treb-grid/src/types/data_model.ts +334 -0
- package/treb-grid/src/types/drag_mask.ts +81 -0
- package/treb-grid/src/types/grid.ts +7743 -0
- package/treb-grid/src/types/grid_base.ts +3644 -0
- package/treb-grid/src/types/grid_command.ts +470 -0
- package/treb-grid/src/types/grid_events.ts +124 -0
- package/treb-grid/src/types/grid_options.ts +97 -0
- package/treb-grid/src/types/grid_selection.ts +60 -0
- package/treb-grid/src/types/named_range.ts +369 -0
- package/treb-grid/src/types/scale-control.ts +202 -0
- package/treb-grid/src/types/serialize_options.ts +72 -0
- package/treb-grid/src/types/set_range_options.ts +52 -0
- package/treb-grid/src/types/sheet.ts +3099 -0
- package/treb-grid/src/types/sheet_types.ts +95 -0
- package/treb-grid/src/types/tab_bar.ts +464 -0
- package/treb-grid/src/types/tile.ts +59 -0
- package/treb-grid/src/types/update_flags.ts +75 -0
- package/treb-grid/src/util/dom_utilities.ts +44 -0
- package/treb-grid/src/util/fontmetrics2.ts +179 -0
- package/treb-grid/src/util/ua.ts +104 -0
- package/treb-logo.svg +18 -0
- package/treb-parser/package.json +5 -0
- package/treb-parser/src/csv-parser.ts +122 -0
- package/treb-parser/src/index.ts +25 -0
- package/treb-parser/src/md-parser.ts +526 -0
- package/treb-parser/src/parser-types.ts +397 -0
- package/treb-parser/src/parser.test.ts +298 -0
- package/treb-parser/src/parser.ts +2673 -0
- package/treb-utils/package.json +5 -0
- package/treb-utils/src/dispatch.ts +57 -0
- package/treb-utils/src/event_source.ts +147 -0
- package/treb-utils/src/ievent_source.ts +33 -0
- package/treb-utils/src/index.ts +31 -0
- package/treb-utils/src/measurement.ts +174 -0
- package/treb-utils/src/resizable.ts +160 -0
- package/treb-utils/src/scale.ts +137 -0
- package/treb-utils/src/serialize_html.ts +124 -0
- package/treb-utils/src/template.ts +70 -0
- package/treb-utils/src/validate_uri.ts +61 -0
- package/tsconfig.json +10 -0
- package/tsproject.json +30 -0
- package/util/license-plugin-esbuild.js +86 -0
- package/util/list-css-vars.sh +46 -0
- package/README-esm.md +0 -37
- package/treb-bundle.css +0 -2
- package/treb-bundle.mjs +0 -15
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of TREB.
|
|
3
|
+
*
|
|
4
|
+
* TREB is free software: you can redistribute it and/or modify it under the
|
|
5
|
+
* terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
* Foundation, either version 3 of the License, or (at your option) any
|
|
7
|
+
* later version.
|
|
8
|
+
*
|
|
9
|
+
* TREB is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
10
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
11
|
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
12
|
+
* details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU General Public License along
|
|
15
|
+
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*
|
|
17
|
+
* Copyright 2022-2023 trebco, llc.
|
|
18
|
+
* info@treb.app
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { BaseLayout } from './base_layout';
|
|
23
|
+
import type { Tile } from '../types/tile';
|
|
24
|
+
import { DOMUtilities } from '../util/dom_utilities';
|
|
25
|
+
import type { DataModel, ViewModel } from '../types/data_model';
|
|
26
|
+
|
|
27
|
+
const SVGNS = 'http://www.w3.org/2000/svg';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* we used to have two layouts, this one and a legacy layout for IE11.
|
|
31
|
+
* since we dropped that one we could merge this with the base layout
|
|
32
|
+
* class (not strictly necessary, but would be cleaner & easier to follow).
|
|
33
|
+
*/
|
|
34
|
+
export class GridLayout extends BaseLayout {
|
|
35
|
+
|
|
36
|
+
constructor(model: DataModel, view: ViewModel){
|
|
37
|
+
super(model, view);
|
|
38
|
+
|
|
39
|
+
// nodes always exist
|
|
40
|
+
|
|
41
|
+
// everything except the selection node and the mouse
|
|
42
|
+
// mask needs to get attached to a container, when it's
|
|
43
|
+
// available
|
|
44
|
+
|
|
45
|
+
this.column_header = DOMUtilities.CreateDiv('treb-top-header');
|
|
46
|
+
this.row_header = DOMUtilities.CreateDiv('treb-left-header');
|
|
47
|
+
|
|
48
|
+
this.corner = DOMUtilities.CreateDiv('treb-corner');
|
|
49
|
+
this.corner_canvas = document.createElement('canvas');
|
|
50
|
+
this.corner.appendChild(this.corner_canvas);
|
|
51
|
+
|
|
52
|
+
this.contents = DOMUtilities.CreateDiv('treb-contents');
|
|
53
|
+
this.buffer_canvas = DOMUtilities.Create('canvas', 'treb-buffer-canvas', this.contents);
|
|
54
|
+
|
|
55
|
+
// selection node attached to contents
|
|
56
|
+
this.grid_selection = document.createElementNS(SVGNS, 'svg');
|
|
57
|
+
this.grid_selection.classList.add('treb-grid-selection');
|
|
58
|
+
this.contents.appendChild(this.grid_selection);
|
|
59
|
+
|
|
60
|
+
// selection node for frozen rows
|
|
61
|
+
this.row_header_selection = document.createElementNS(SVGNS, 'svg');
|
|
62
|
+
this.row_header_selection.classList.add('frozen-selection');
|
|
63
|
+
this.row_header_selection.classList.add('frozen-selection-rows');
|
|
64
|
+
this.column_header.appendChild(this.row_header_selection);
|
|
65
|
+
this.row_header_annotations = DOMUtilities.CreateDiv('frozen-annotation-container frozen-annotation-container-rows', this.column_header);
|
|
66
|
+
|
|
67
|
+
// ...columns
|
|
68
|
+
this.column_header_selection = document.createElementNS(SVGNS, 'svg');
|
|
69
|
+
this.column_header_selection.classList.add('frozen-selection');
|
|
70
|
+
this.column_header_selection.classList.add('frozen-selection-columns');
|
|
71
|
+
this.row_header.appendChild(this.column_header_selection);
|
|
72
|
+
this.column_header_annotations = DOMUtilities.CreateDiv('frozen-annotation-container frozen-annotation-container-columns', this.row_header);
|
|
73
|
+
|
|
74
|
+
// ...corner
|
|
75
|
+
this.corner_selection = document.createElementNS(SVGNS, 'svg');
|
|
76
|
+
this.corner_selection.classList.add('frozen-selection');
|
|
77
|
+
this.corner.appendChild(this.corner_selection);
|
|
78
|
+
this.corner_annotations = DOMUtilities.CreateDiv('frozen-annotation-container frozen-annotation-container-corner', this.corner);
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
this.annotation_container = DOMUtilities.CreateDiv('treb-annotation-container');
|
|
82
|
+
|
|
83
|
+
this.grid_cover = DOMUtilities.CreateDiv('tile-cover grid-cover');
|
|
84
|
+
this.column_header_cover = DOMUtilities.CreateDiv('tile-cover column-header-cover');
|
|
85
|
+
this.row_header_cover = DOMUtilities.CreateDiv('tile-cover row-header-cover');
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** attach node structure to container */
|
|
90
|
+
public InitializeInternal(container: HTMLElement, scroll_callback: () => void): void {
|
|
91
|
+
|
|
92
|
+
this.container = container;
|
|
93
|
+
// this.container.classList.add('treb-grid-layout');
|
|
94
|
+
|
|
95
|
+
this.scroll_reference_node = this.container;
|
|
96
|
+
|
|
97
|
+
container.appendChild(this.column_header);
|
|
98
|
+
container.appendChild(this.row_header);
|
|
99
|
+
container.appendChild(this.corner);
|
|
100
|
+
container.appendChild(this.contents);
|
|
101
|
+
container.appendChild(this.annotation_container);
|
|
102
|
+
container.appendChild(this.grid_cover);
|
|
103
|
+
container.appendChild(this.column_header_cover);
|
|
104
|
+
container.appendChild(this.row_header_cover);
|
|
105
|
+
container.appendChild(this.mock_selection);
|
|
106
|
+
|
|
107
|
+
this.container.addEventListener('scroll', () => scroll_callback());
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public ResizeCursor(resize?: 'row'|'column'): void {
|
|
112
|
+
switch (resize) {
|
|
113
|
+
case 'row':
|
|
114
|
+
this.row_header_cover.classList.add('resize');
|
|
115
|
+
break;
|
|
116
|
+
case 'column':
|
|
117
|
+
this.column_header_cover.classList.add('resize');
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
this.row_header_cover.classList.remove('resize');
|
|
121
|
+
this.column_header_cover.classList.remove('resize');
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
protected UpdateTileGridPosition(tile: Tile): void {
|
|
127
|
+
tile.style.gridColumn = `${tile.tile_position.column + 1} / ${tile.tile_position.column + 2}`;
|
|
128
|
+
tile.style.gridRow = `${tile.tile_position.row + 1} / ${tile.tile_position.row + 2}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected UpdateContainingGrid(): void {
|
|
132
|
+
|
|
133
|
+
if (!this.container) throw new Error('missing container');
|
|
134
|
+
|
|
135
|
+
this.header_size.width = this.header_offset.x;
|
|
136
|
+
this.header_size.height = this.header_offset.y;
|
|
137
|
+
|
|
138
|
+
// update the containing grid (layout for column/row headers)
|
|
139
|
+
|
|
140
|
+
let x = this.header_offset.x;
|
|
141
|
+
let y = this.header_offset.y;
|
|
142
|
+
|
|
143
|
+
if (this.view.active_sheet.freeze.columns) {
|
|
144
|
+
for (let i = 0; i < this.view.active_sheet.freeze.columns; i++) x += this.ColumnWidth(i);
|
|
145
|
+
}
|
|
146
|
+
if (this.view.active_sheet.freeze.rows) {
|
|
147
|
+
for (let i = 0; i < this.view.active_sheet.freeze.rows; i++) y += this.RowHeight(i);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// this.container.style.gridTemplateColumns = `${x}px auto`;
|
|
151
|
+
// this.container.style.gridTemplateRows = `${y}px auto`;
|
|
152
|
+
this.container.style.gridTemplateColumns = `${this.header_offset.x}px auto`;
|
|
153
|
+
this.container.style.gridTemplateRows = `${this.header_offset.y}px auto`;
|
|
154
|
+
|
|
155
|
+
this.corner_canvas.setAttribute('width', `${this.dpr * x}`);
|
|
156
|
+
this.corner_canvas.setAttribute('height', `${this.dpr * y}`);
|
|
157
|
+
|
|
158
|
+
this.column_header.style.height = `${y}px`;
|
|
159
|
+
|
|
160
|
+
this.corner_canvas.style.width = `${x}px`;
|
|
161
|
+
this.corner_canvas.style.height = `${y}px`;
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
protected UpdateGridTemplates(columns = true, rows = true): void {
|
|
166
|
+
|
|
167
|
+
let width = 0;
|
|
168
|
+
let height = 0;
|
|
169
|
+
|
|
170
|
+
// update grids
|
|
171
|
+
|
|
172
|
+
this.column_header.style.gridTemplateColumns =
|
|
173
|
+
this.contents.style.gridTemplateColumns =
|
|
174
|
+
this.column_header_tiles.map((tile) => {
|
|
175
|
+
width += tile.logical_size.width;
|
|
176
|
+
return `${tile.logical_size.width}px`;
|
|
177
|
+
}).join(' ');
|
|
178
|
+
|
|
179
|
+
this.column_header.style.gridTemplateRows = `${this.header_offset.y}px auto`;
|
|
180
|
+
|
|
181
|
+
this.row_header.style.gridTemplateRows =
|
|
182
|
+
this.contents.style.gridTemplateRows =
|
|
183
|
+
this.row_header_tiles.map((tile) => {
|
|
184
|
+
height += tile.logical_size.height;
|
|
185
|
+
return `${tile.logical_size.height}px`;
|
|
186
|
+
}).join(' ');
|
|
187
|
+
|
|
188
|
+
// frozen selection -- now used for selection highlights
|
|
189
|
+
// as well (moved from render headers)
|
|
190
|
+
|
|
191
|
+
let y = this.header_offset.y;
|
|
192
|
+
if (this.view.active_sheet.freeze.rows) {
|
|
193
|
+
// let y = 0;
|
|
194
|
+
for (let i = 0; i < this.view.active_sheet.freeze.rows; i++) {
|
|
195
|
+
y += this.RowHeight(i);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.column_header.style.height = `${y}px`;
|
|
200
|
+
|
|
201
|
+
this.row_header_selection.style.display = 'block';
|
|
202
|
+
this.row_header_selection.style.width = `${width}px`;
|
|
203
|
+
this.corner_selection.style.height =
|
|
204
|
+
this.row_header_selection.style.height = `${y}px`;
|
|
205
|
+
this.corner_selection.style.top =
|
|
206
|
+
this.row_header_selection.style.top = '0px';
|
|
207
|
+
this.row_header_selection.style.left = `0px`;
|
|
208
|
+
|
|
209
|
+
let x = this.header_offset.x;
|
|
210
|
+
if (this.view.active_sheet.freeze.columns) {
|
|
211
|
+
for (let i = 0; i < this.view.active_sheet.freeze.columns; i++) {
|
|
212
|
+
x += this.ColumnWidth(i);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
this.column_header_selection.style.display = 'block';
|
|
216
|
+
this.corner_selection.style.width =
|
|
217
|
+
this.column_header_selection.style.width = `${x}px`;
|
|
218
|
+
this.column_header_selection.style.height = `${height}px`;
|
|
219
|
+
this.column_header_selection.style.top = `0px`;
|
|
220
|
+
this.corner_selection.style.left =
|
|
221
|
+
this.column_header_selection.style.left = '0px'; // `${this.model.sheet.header_offset.x}px`;
|
|
222
|
+
|
|
223
|
+
// --
|
|
224
|
+
|
|
225
|
+
const scaled_header = {
|
|
226
|
+
x: this.view.active_sheet.header_offset.x * this.scale,
|
|
227
|
+
y: this.view.active_sheet.header_offset.y * this.scale,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const freeze = this.view.active_sheet.freeze;
|
|
231
|
+
|
|
232
|
+
if (freeze.rows && freeze.columns) {
|
|
233
|
+
this.row_header_annotations.style.display = 'block';
|
|
234
|
+
this.column_header_annotations.style.display = 'block';
|
|
235
|
+
this.corner_annotations.style.display = 'block';
|
|
236
|
+
}
|
|
237
|
+
else if (freeze.rows) {
|
|
238
|
+
this.row_header_annotations.style.display = 'block';
|
|
239
|
+
this.column_header_annotations.style.display = 'none';
|
|
240
|
+
this.corner_annotations.style.display = 'none';
|
|
241
|
+
}
|
|
242
|
+
else if (freeze.columns) {
|
|
243
|
+
this.row_header_annotations.style.display = 'none';
|
|
244
|
+
this.column_header_annotations.style.display = 'block';
|
|
245
|
+
this.corner_annotations.style.display = 'none';
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this.row_header_annotations.style.display = 'none';
|
|
249
|
+
this.column_header_annotations.style.display = 'none';
|
|
250
|
+
this.corner_annotations.style.display = 'none';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this.row_header_annotations.style.width = `${width}px`;
|
|
254
|
+
this.corner_annotations.style.height =
|
|
255
|
+
this.row_header_annotations.style.height = `${y - scaled_header.y}px`;
|
|
256
|
+
this.corner_annotations.style.top =
|
|
257
|
+
this.row_header_annotations.style.top = `${scaled_header.y}px`;
|
|
258
|
+
|
|
259
|
+
this.column_header_annotations.style.width =
|
|
260
|
+
this.corner_annotations.style.width = `${x - scaled_header.x}px`;
|
|
261
|
+
this.column_header_annotations.style.height = `${height}px`;
|
|
262
|
+
this.corner_annotations.style.left =
|
|
263
|
+
this.column_header_annotations.style.left = `${scaled_header.x}px`;
|
|
264
|
+
|
|
265
|
+
/*
|
|
266
|
+
// dev
|
|
267
|
+
this.column_header_annotations.style.background = `rgba(255, 0, 0, .2)`;
|
|
268
|
+
this.row_header_annotations.style.background = `rgba(255, 0, 0, .2)`;
|
|
269
|
+
this.corner_annotations.style.background = `rgba(0, 255, 0, .2)`;
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
this.corner_selection.style.display = 'block';
|
|
273
|
+
|
|
274
|
+
/*
|
|
275
|
+
if (this.model.sheet.freeze.rows && this.model.sheet.freeze.columns) {
|
|
276
|
+
this.frozen_corner_selection.style.display = 'block';
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
this.frozen_corner_selection.style.display = 'none';
|
|
280
|
+
}
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
// main selection
|
|
284
|
+
|
|
285
|
+
this.grid_selection.style.width = `${width}px`;
|
|
286
|
+
this.grid_selection.style.height = `${height}px`;
|
|
287
|
+
this.grid_selection.style.top = `${this.header_offset.y}px`;
|
|
288
|
+
this.grid_selection.style.left = `${this.header_offset.x}px`;
|
|
289
|
+
|
|
290
|
+
// annotations
|
|
291
|
+
|
|
292
|
+
this.annotation_container.style.width = `${width}px`;
|
|
293
|
+
this.annotation_container.style.height = `${height}px`;
|
|
294
|
+
this.annotation_container.style.top = `${this.header_offset.y}px`;
|
|
295
|
+
this.annotation_container.style.left = `${this.header_offset.x}px`;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of TREB.
|
|
3
|
+
*
|
|
4
|
+
* TREB is free software: you can redistribute it and/or modify it under the
|
|
5
|
+
* terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
* Foundation, either version 3 of the License, or (at your option) any
|
|
7
|
+
* later version.
|
|
8
|
+
*
|
|
9
|
+
* TREB is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
10
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
11
|
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
12
|
+
* details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU General Public License along
|
|
15
|
+
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*
|
|
17
|
+
* Copyright 2022-2023 trebco, llc.
|
|
18
|
+
* info@treb.app
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { Rectangle } from 'treb-base-types';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* FIXME: efficiency of using sparse arrays here?
|
|
26
|
+
*
|
|
27
|
+
* (vs what, a lookup table? sparse arrays are basically a lookup
|
|
28
|
+
* table, and we can assume they're reasonably efficient)
|
|
29
|
+
*/
|
|
30
|
+
/*export*/ class RectangleCache {
|
|
31
|
+
|
|
32
|
+
private cache: Rectangle[][] = [];
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
|
|
36
|
+
private hits = 0;
|
|
37
|
+
private misses = 0;
|
|
38
|
+
|
|
39
|
+
public Stats(){
|
|
40
|
+
return {
|
|
41
|
+
hits: this.hits,
|
|
42
|
+
misses: this.misses,
|
|
43
|
+
hit_rate: (this.hits + this.misses) ? this.hits / (this.hits + this.misses) : 0,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/** flush cache */
|
|
50
|
+
public Clear(){
|
|
51
|
+
this.cache = [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* cache lookup.
|
|
56
|
+
* FIXME: why row/column and not address type?
|
|
57
|
+
*/
|
|
58
|
+
public Get(column: number, row: number): Rectangle|undefined {
|
|
59
|
+
|
|
60
|
+
if (!this.cache[column]) return undefined;
|
|
61
|
+
const rect = this.cache[column][row];
|
|
62
|
+
return rect ? rect.Shift(0, 0) : undefined;
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
if (this.cache[column]) {
|
|
66
|
+
const rect = this.cache[column][row];
|
|
67
|
+
if (rect) {
|
|
68
|
+
this.hits++;
|
|
69
|
+
return rect.Shift(0, 0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
this.misses++;
|
|
73
|
+
return undefined;
|
|
74
|
+
*/
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* cache set.
|
|
79
|
+
* FIXME: why row/column and not address type?
|
|
80
|
+
*/
|
|
81
|
+
public Set(column: number, row: number, rect: Rectangle) {
|
|
82
|
+
if (!this.cache[column]) this.cache[column] = [];
|
|
83
|
+
this.cache[column][row] = rect.Shift(0, 0); // clone
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|