@odoo/o-spreadsheet 14.0.1 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/o_spreadsheet.cjs.js +31302 -0
- package/dist/o_spreadsheet.d.ts +6604 -0
- package/dist/o_spreadsheet.esm.js +31257 -0
- package/dist/o_spreadsheet.iife.js +31304 -0
- package/dist/o_spreadsheet.iife.min.js +3071 -0
- package/package.json +57 -15
- package/.eslintrc.json +0 -20
- package/.husky/post-checkout +0 -9
- package/.husky/pre-commit +0 -39
- package/.prettierignore +0 -1
- package/astToFormula.patch +0 -0
- package/demo/data.js +0 -255
- package/demo/index.html +0 -9
- package/demo/libs/Chart.bundle.js +0 -20755
- package/demo/main.js +0 -101
- package/doc/readme.md +0 -46
- package/rollup.config.js +0 -23
- package/src/base_plugin.ts +0 -102
- package/src/components/autofill.ts +0 -146
- package/src/components/bottom_bar.ts +0 -199
- package/src/components/color_picker.ts +0 -150
- package/src/components/composer/autocomplete_dropdown.ts +0 -135
- package/src/components/composer/composer.ts +0 -487
- package/src/components/composer/content_editable_helper.ts +0 -146
- package/src/components/figures/chart.ts +0 -70
- package/src/components/figures/container.ts +0 -268
- package/src/components/figures/text_figure.ts +0 -36
- package/src/components/grid.ts +0 -635
- package/src/components/helpers/dom_helpers.ts +0 -7
- package/src/components/helpers/drag_and_drop.ts +0 -17
- package/src/components/icons.ts +0 -36
- package/src/components/index.ts +0 -1
- package/src/components/menu.ts +0 -288
- package/src/components/overlay.ts +0 -457
- package/src/components/scrollbar.ts +0 -22
- package/src/components/selection_input.ts +0 -168
- package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
- package/src/components/side_panel/chart_panel.ts +0 -104
- package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
- package/src/components/side_panel/conditional_formatting.ts +0 -396
- package/src/components/side_panel/side_panel.ts +0 -127
- package/src/components/side_panel/translations_terms.ts +0 -45
- package/src/components/spreadsheet.ts +0 -198
- package/src/components/top_bar.ts +0 -535
- package/src/constants.ts +0 -26
- package/src/data.ts +0 -149
- package/src/fonts.ts +0 -41
- package/src/formulas/compiler.ts +0 -258
- package/src/formulas/composer_tokenizer.ts +0 -70
- package/src/formulas/index.ts +0 -15
- package/src/formulas/normalize.ts +0 -52
- package/src/formulas/parser.ts +0 -280
- package/src/formulas/range_tokenizer.ts +0 -97
- package/src/formulas/tokenizer.ts +0 -242
- package/src/functions/arguments.ts +0 -114
- package/src/functions/dates.ts +0 -302
- package/src/functions/helpers.ts +0 -592
- package/src/functions/index.ts +0 -52
- package/src/functions/module_database.ts +0 -282
- package/src/functions/module_date.ts +0 -743
- package/src/functions/module_info.ts +0 -69
- package/src/functions/module_logical.ts +0 -208
- package/src/functions/module_lookup.ts +0 -185
- package/src/functions/module_math.ts +0 -1252
- package/src/functions/module_operators.ts +0 -291
- package/src/functions/module_statistical.ts +0 -882
- package/src/functions/module_text.ts +0 -370
- package/src/helpers/color.ts +0 -30
- package/src/helpers/coordinates.ts +0 -71
- package/src/helpers/grid_manipulation.ts +0 -68
- package/src/helpers/index.ts +0 -7
- package/src/helpers/misc.ts +0 -76
- package/src/helpers/numbers.ts +0 -117
- package/src/helpers/uuid.ts +0 -19
- package/src/helpers/zones.ts +0 -263
- package/src/history.ts +0 -186
- package/src/index.ts +0 -84
- package/src/model.ts +0 -261
- package/src/plugins/autofill.ts +0 -412
- package/src/plugins/chart.ts +0 -404
- package/src/plugins/clipboard.ts +0 -461
- package/src/plugins/conditional_format.ts +0 -445
- package/src/plugins/core.ts +0 -1502
- package/src/plugins/edition.ts +0 -157
- package/src/plugins/evaluation.ts +0 -428
- package/src/plugins/figures.ts +0 -123
- package/src/plugins/formatting.ts +0 -630
- package/src/plugins/highlight.ts +0 -187
- package/src/plugins/index.ts +0 -32
- package/src/plugins/merge.ts +0 -524
- package/src/plugins/renderer.ts +0 -571
- package/src/plugins/selection.ts +0 -562
- package/src/plugins/selection_inputs.ts +0 -326
- package/src/registries/autofill_modifiers.ts +0 -76
- package/src/registries/autofill_rules.ts +0 -98
- package/src/registries/figure_registry.ts +0 -30
- package/src/registries/index.ts +0 -7
- package/src/registries/menu_items_registry.ts +0 -110
- package/src/registries/menus/cell_menu_registry.ts +0 -79
- package/src/registries/menus/col_menu_registry.ts +0 -63
- package/src/registries/menus/index.ts +0 -6
- package/src/registries/menus/menu_items_actions.ts +0 -425
- package/src/registries/menus/row_menu_registry.ts +0 -63
- package/src/registries/menus/sheet_menu_registry.ts +0 -75
- package/src/registries/menus/topbar_menu_registry.ts +0 -204
- package/src/registries/side_panel_registry.ts +0 -26
- package/src/registries/topbar_component_registry.ts +0 -12
- package/src/registry.ts +0 -51
- package/src/translation.ts +0 -44
- package/src/types/autofill.ts +0 -48
- package/src/types/chart.ts +0 -26
- package/src/types/commands.ts +0 -716
- package/src/types/conditional_formatting.ts +0 -124
- package/src/types/env.ts +0 -13
- package/src/types/functions.ts +0 -35
- package/src/types/getters.ts +0 -103
- package/src/types/index.ts +0 -20
- package/src/types/misc.ts +0 -143
- package/src/types/rendering.ts +0 -41
- package/src/types/workbook_data.ts +0 -62
- package/tests/__mocks__/uuid.ts +0 -7
- package/tests/canvas.mock.ts +0 -34
- package/tests/components/__mocks__/content_editable_helper.ts +0 -79
- package/tests/components/__mocks__/scrollbar.ts +0 -18
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
- package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
- package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
- package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
- package/tests/components/autocomplete_dropdown_test.ts +0 -315
- package/tests/components/autofill_test.ts +0 -167
- package/tests/components/bottom_bar_test.ts +0 -262
- package/tests/components/chart_side_panel_test.ts +0 -123
- package/tests/components/composer_test.ts +0 -400
- package/tests/components/context_menu_test.ts +0 -825
- package/tests/components/grid_manipulation_test.ts +0 -163
- package/tests/components/grid_test.ts +0 -581
- package/tests/components/overlay_test.ts +0 -541
- package/tests/components/selection_input_test.ts +0 -259
- package/tests/components/side_panel_test.ts +0 -148
- package/tests/components/spreadsheet_test.ts +0 -194
- package/tests/components/top_bar_test.ts +0 -427
- package/tests/data_test.ts +0 -175
- package/tests/dom_helper.ts +0 -42
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
- package/tests/formulas/compiler_test.ts +0 -266
- package/tests/formulas/composer_tokenizer_test.ts +0 -137
- package/tests/formulas/expressions_test.ts +0 -57
- package/tests/formulas/formulas_test.ts +0 -80
- package/tests/formulas/normalize_test.ts +0 -82
- package/tests/formulas/parser_test.ts +0 -224
- package/tests/formulas/range_tokenizer_test.ts +0 -187
- package/tests/formulas/tokenizer_test.ts +0 -164
- package/tests/functions/arguments_test.ts +0 -141
- package/tests/functions/dates_test.ts +0 -1081
- package/tests/functions/functions_test.ts +0 -53
- package/tests/functions/helper_test.ts +0 -98
- package/tests/functions/module_database_test.ts +0 -311
- package/tests/functions/module_date_test.ts +0 -941
- package/tests/functions/module_info_test.ts +0 -139
- package/tests/functions/module_logical_test.ts +0 -369
- package/tests/functions/module_lookup_test.ts +0 -541
- package/tests/functions/module_math_test.ts +0 -2482
- package/tests/functions/module_operators_test.ts +0 -955
- package/tests/functions/module_statistical_test.ts +0 -2014
- package/tests/functions/module_text_test.ts +0 -667
- package/tests/helpers/coordinates_test.ts +0 -25
- package/tests/helpers/misc_test.ts +0 -95
- package/tests/helpers/numbers_test.ts +0 -196
- package/tests/helpers/zones_test.ts +0 -97
- package/tests/helpers.ts +0 -384
- package/tests/menu_items_registry_test.ts +0 -540
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
- package/tests/model/plugins/chart_test.ts +0 -562
- package/tests/model_test.ts +0 -82
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
- package/tests/plugins/autofill_test.ts +0 -457
- package/tests/plugins/borders_test.ts +0 -295
- package/tests/plugins/clipboard_test.ts +0 -1180
- package/tests/plugins/conditional_formatting_test.ts +0 -1253
- package/tests/plugins/core_test.ts +0 -614
- package/tests/plugins/edition_test.ts +0 -100
- package/tests/plugins/evaluation_async_test.ts +0 -332
- package/tests/plugins/evaluation_dates_test.ts +0 -79
- package/tests/plugins/evaluation_test.ts +0 -901
- package/tests/plugins/figures_test.ts +0 -327
- package/tests/plugins/formatting_test.ts +0 -391
- package/tests/plugins/grid_manipulation_test.ts +0 -1366
- package/tests/plugins/highlight_test.ts +0 -413
- package/tests/plugins/history_test.ts +0 -142
- package/tests/plugins/import_export_test.ts +0 -276
- package/tests/plugins/merges_test.ts +0 -490
- package/tests/plugins/navigation_test.ts +0 -181
- package/tests/plugins/plugins/evaluation_test.ts +0 -111
- package/tests/plugins/renderer_test.ts +0 -598
- package/tests/plugins/resizing_test.ts +0 -152
- package/tests/plugins/selection_input_test.ts +0 -409
- package/tests/plugins/selection_test.ts +0 -442
- package/tests/plugins/sheets_test.ts +0 -643
- package/tests/plugins/style_test.ts +0 -90
- package/tsconfig.json +0 -22
package/src/plugins/renderer.ts
DELETED
|
@@ -1,571 +0,0 @@
|
|
|
1
|
-
import { BasePlugin } from "../base_plugin";
|
|
2
|
-
import {
|
|
3
|
-
BACKGROUND_HEADER_ACTIVE_COLOR,
|
|
4
|
-
BACKGROUND_HEADER_COLOR,
|
|
5
|
-
BACKGROUND_HEADER_SELECTED_COLOR,
|
|
6
|
-
CELL_BORDER_COLOR,
|
|
7
|
-
DEFAULT_FONT,
|
|
8
|
-
DEFAULT_FONT_SIZE,
|
|
9
|
-
DEFAULT_FONT_WEIGHT,
|
|
10
|
-
HEADER_BORDER_COLOR,
|
|
11
|
-
HEADER_FONT_SIZE,
|
|
12
|
-
HEADER_HEIGHT,
|
|
13
|
-
HEADER_WIDTH,
|
|
14
|
-
TEXT_HEADER_COLOR,
|
|
15
|
-
} from "../constants";
|
|
16
|
-
import { fontSizeMap } from "../fonts";
|
|
17
|
-
import { overlap, toXC } from "../helpers/index";
|
|
18
|
-
import { Mode } from "../model";
|
|
19
|
-
import {
|
|
20
|
-
Box,
|
|
21
|
-
Cell,
|
|
22
|
-
GridRenderingContext,
|
|
23
|
-
Header,
|
|
24
|
-
LAYERS,
|
|
25
|
-
Rect,
|
|
26
|
-
Viewport,
|
|
27
|
-
Zone,
|
|
28
|
-
} from "../types/index";
|
|
29
|
-
|
|
30
|
-
// -----------------------------------------------------------------------------
|
|
31
|
-
// Constants, types, helpers, ...
|
|
32
|
-
// -----------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
function computeAlign(cell: Cell, isShowingFormulas: boolean): "right" | "center" | "left" {
|
|
35
|
-
if (cell.type === "formula" && isShowingFormulas) {
|
|
36
|
-
return "left";
|
|
37
|
-
} else if (cell.error || cell.pending) {
|
|
38
|
-
return "center";
|
|
39
|
-
}
|
|
40
|
-
switch (typeof cell.value) {
|
|
41
|
-
case "object":
|
|
42
|
-
case "number":
|
|
43
|
-
return "right";
|
|
44
|
-
case "boolean":
|
|
45
|
-
return "center";
|
|
46
|
-
default:
|
|
47
|
-
return "left";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function searchIndex(headers: Header[], offset: number): number {
|
|
52
|
-
let left = 0;
|
|
53
|
-
let right = headers.length - 1;
|
|
54
|
-
while (left <= right) {
|
|
55
|
-
const index = Math.floor((left + right) / 2);
|
|
56
|
-
const header = headers[index];
|
|
57
|
-
if (offset < header.start) {
|
|
58
|
-
right = index - 1;
|
|
59
|
-
} else if (offset > header.end) {
|
|
60
|
-
left = index + 1;
|
|
61
|
-
} else {
|
|
62
|
-
return index;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return -1;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export class RendererPlugin extends BasePlugin {
|
|
69
|
-
static layers = [LAYERS.Background, LAYERS.Headers];
|
|
70
|
-
static getters = [
|
|
71
|
-
"getColIndex",
|
|
72
|
-
"getRowIndex",
|
|
73
|
-
"getRect",
|
|
74
|
-
"snapViewportToCell",
|
|
75
|
-
"adjustViewportPosition",
|
|
76
|
-
"adjustViewportZone",
|
|
77
|
-
];
|
|
78
|
-
static modes: Mode[] = ["normal", "readonly"];
|
|
79
|
-
|
|
80
|
-
private boxes: Box[] = [];
|
|
81
|
-
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
// Getters
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Return the index of a column given an offset x and a visible left col index.
|
|
88
|
-
* It returns -1 if no column is found.
|
|
89
|
-
*/
|
|
90
|
-
getColIndex(x: number, left: number): number {
|
|
91
|
-
if (x < HEADER_WIDTH) {
|
|
92
|
-
return -1;
|
|
93
|
-
}
|
|
94
|
-
const cols = this.workbook.activeSheet.cols;
|
|
95
|
-
const adjustedX = x - HEADER_WIDTH + cols[left].start + 1;
|
|
96
|
-
return searchIndex(cols, adjustedX);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getRowIndex(y: number, top: number): number {
|
|
100
|
-
if (y < HEADER_HEIGHT) {
|
|
101
|
-
return -1;
|
|
102
|
-
}
|
|
103
|
-
const rows = this.workbook.activeSheet.rows;
|
|
104
|
-
const adjustedY = y - HEADER_HEIGHT + rows[top].start + 1;
|
|
105
|
-
return searchIndex(rows, adjustedY);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getRect(zone: Zone, viewport: Viewport): Rect {
|
|
109
|
-
const { left, top, right, bottom } = zone;
|
|
110
|
-
let { offsetY, offsetX } = viewport;
|
|
111
|
-
offsetX -= HEADER_WIDTH;
|
|
112
|
-
offsetY -= HEADER_HEIGHT;
|
|
113
|
-
const { cols, rows } = this.workbook.activeSheet;
|
|
114
|
-
const x = Math.max(cols[left].start - offsetX, HEADER_WIDTH);
|
|
115
|
-
const width = cols[right].end - offsetX - x;
|
|
116
|
-
const y = Math.max(rows[top].start - offsetY, HEADER_HEIGHT);
|
|
117
|
-
const height = rows[bottom].end - offsetY - y;
|
|
118
|
-
return [x, y, width, height];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Snap a viewport boundaries to exactly match the start of a cell.
|
|
123
|
-
* @param viewport
|
|
124
|
-
*/
|
|
125
|
-
snapViewportToCell(viewport: Viewport): Viewport {
|
|
126
|
-
const { cols, rows } = this.workbook.activeSheet;
|
|
127
|
-
const adjustedViewport = Object.assign({}, viewport);
|
|
128
|
-
adjustedViewport.offsetX = cols[viewport.left].start;
|
|
129
|
-
adjustedViewport.offsetY = rows[viewport.top].start;
|
|
130
|
-
return adjustedViewport;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Adjust the viewport until the active cell is completely visible inside it.
|
|
135
|
-
* @param viewport the viewport that will be adjusted
|
|
136
|
-
*/
|
|
137
|
-
adjustViewportPosition(viewport: Viewport): Viewport {
|
|
138
|
-
const adjustedViewport = Object.assign({}, viewport);
|
|
139
|
-
const { cols, rows } = this.workbook.activeSheet;
|
|
140
|
-
const [col, row] = this.getters.getPosition();
|
|
141
|
-
while (col >= adjustedViewport.right && col !== cols.length - 1) {
|
|
142
|
-
adjustedViewport.offsetX = cols[adjustedViewport.left].end;
|
|
143
|
-
this.adjustViewportZoneX(adjustedViewport);
|
|
144
|
-
}
|
|
145
|
-
while (col < adjustedViewport.left) {
|
|
146
|
-
adjustedViewport.offsetX = cols[adjustedViewport.left - 1].start;
|
|
147
|
-
this.adjustViewportZoneX(adjustedViewport);
|
|
148
|
-
}
|
|
149
|
-
while (row >= adjustedViewport.bottom && row !== rows.length - 1) {
|
|
150
|
-
adjustedViewport.offsetY = rows[adjustedViewport.top].end;
|
|
151
|
-
this.adjustViewportZoneY(adjustedViewport);
|
|
152
|
-
}
|
|
153
|
-
while (row < adjustedViewport.top) {
|
|
154
|
-
adjustedViewport.offsetY = rows[adjustedViewport.top - 1].start;
|
|
155
|
-
this.adjustViewportZoneY(adjustedViewport);
|
|
156
|
-
}
|
|
157
|
-
return adjustedViewport;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
adjustViewportZone(viewport: Viewport): Viewport {
|
|
161
|
-
const adjustedViewport = Object.assign({}, viewport);
|
|
162
|
-
this.adjustViewportZoneX(adjustedViewport);
|
|
163
|
-
this.adjustViewportZoneY(adjustedViewport);
|
|
164
|
-
return adjustedViewport;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private adjustViewportZoneX(viewport: Viewport) {
|
|
168
|
-
const { cols } = this.workbook.activeSheet;
|
|
169
|
-
const { width, offsetX } = viewport;
|
|
170
|
-
viewport.left = this.getColIndex(offsetX + HEADER_WIDTH, 0);
|
|
171
|
-
const x = width + offsetX - HEADER_WIDTH;
|
|
172
|
-
viewport.right = cols.length - 1;
|
|
173
|
-
for (let i = viewport.left; i < cols.length; i++) {
|
|
174
|
-
if (x < cols[i].end) {
|
|
175
|
-
viewport.right = i;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private adjustViewportZoneY(viewport: Viewport) {
|
|
182
|
-
const { rows } = this.workbook.activeSheet;
|
|
183
|
-
const { height, offsetY } = viewport;
|
|
184
|
-
viewport.top = this.getRowIndex(offsetY + HEADER_HEIGHT, 0);
|
|
185
|
-
|
|
186
|
-
let y = height + offsetY - HEADER_HEIGHT;
|
|
187
|
-
viewport.bottom = rows.length - 1;
|
|
188
|
-
for (let i = viewport.top; i < rows.length; i++) {
|
|
189
|
-
if (y < rows[i].end) {
|
|
190
|
-
viewport.bottom = i;
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ---------------------------------------------------------------------------
|
|
197
|
-
// Grid rendering
|
|
198
|
-
// ---------------------------------------------------------------------------
|
|
199
|
-
|
|
200
|
-
drawGrid(renderingContext: GridRenderingContext, layer: LAYERS) {
|
|
201
|
-
switch (layer) {
|
|
202
|
-
case LAYERS.Background:
|
|
203
|
-
this.boxes = this.getGridBoxes(renderingContext);
|
|
204
|
-
this.drawBackground(renderingContext);
|
|
205
|
-
this.drawCellBackground(renderingContext);
|
|
206
|
-
this.drawBorders(renderingContext);
|
|
207
|
-
this.drawTexts(renderingContext);
|
|
208
|
-
break;
|
|
209
|
-
case LAYERS.Headers:
|
|
210
|
-
this.drawHeaders(renderingContext);
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private drawBackground(renderingContext: GridRenderingContext) {
|
|
216
|
-
const { ctx, viewport, thinLineWidth } = renderingContext;
|
|
217
|
-
let { width, height, offsetX, offsetY, top, left, bottom, right } = viewport;
|
|
218
|
-
const { rows, cols } = this.workbook.activeSheet;
|
|
219
|
-
|
|
220
|
-
// white background
|
|
221
|
-
ctx.fillStyle = "white";
|
|
222
|
-
ctx.fillRect(0, 0, viewport.width, viewport.height);
|
|
223
|
-
|
|
224
|
-
// background grid
|
|
225
|
-
offsetX -= HEADER_WIDTH;
|
|
226
|
-
offsetY -= HEADER_HEIGHT;
|
|
227
|
-
|
|
228
|
-
ctx.lineWidth = 2 * thinLineWidth;
|
|
229
|
-
ctx.strokeStyle = CELL_BORDER_COLOR;
|
|
230
|
-
ctx.beginPath();
|
|
231
|
-
|
|
232
|
-
// vertical lines
|
|
233
|
-
const lineHeight = Math.min(height, rows[bottom].end - offsetY);
|
|
234
|
-
for (let i = left; i <= right; i++) {
|
|
235
|
-
const x = cols[i].end - offsetX;
|
|
236
|
-
ctx.moveTo(x, 0);
|
|
237
|
-
ctx.lineTo(x, lineHeight);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// horizontal lines
|
|
241
|
-
const lineWidth = Math.min(width, cols[right].end - offsetX);
|
|
242
|
-
for (let i = top; i <= bottom; i++) {
|
|
243
|
-
const y = rows[i].end - offsetY;
|
|
244
|
-
ctx.moveTo(0, y);
|
|
245
|
-
ctx.lineTo(lineWidth, y);
|
|
246
|
-
}
|
|
247
|
-
ctx.stroke();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
private drawCellBackground(renderingContext: GridRenderingContext) {
|
|
251
|
-
const { ctx, thinLineWidth } = renderingContext;
|
|
252
|
-
ctx.lineWidth = 0.3 * thinLineWidth;
|
|
253
|
-
const inset = 0.1 * thinLineWidth;
|
|
254
|
-
ctx.strokeStyle = "#111";
|
|
255
|
-
for (let box of this.boxes) {
|
|
256
|
-
// fill color
|
|
257
|
-
let style = box.style;
|
|
258
|
-
if (style && style.fillColor && style.fillColor !== "#ffffff") {
|
|
259
|
-
ctx.fillStyle = style.fillColor;
|
|
260
|
-
ctx.fillRect(box.x, box.y, box.width, box.height);
|
|
261
|
-
ctx.strokeRect(box.x + inset, box.y + inset, box.width - 2 * inset, box.height - 2 * inset);
|
|
262
|
-
}
|
|
263
|
-
if (box.error) {
|
|
264
|
-
ctx.fillStyle = "red";
|
|
265
|
-
ctx.beginPath();
|
|
266
|
-
ctx.moveTo(box.x + box.width - 5, box.y);
|
|
267
|
-
ctx.lineTo(box.x + box.width, box.y);
|
|
268
|
-
ctx.lineTo(box.x + box.width, box.y + 5);
|
|
269
|
-
ctx.fill();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
private drawBorders(renderingContext: GridRenderingContext) {
|
|
275
|
-
const { ctx, thinLineWidth } = renderingContext;
|
|
276
|
-
for (let box of this.boxes) {
|
|
277
|
-
// fill color
|
|
278
|
-
let border = box.border;
|
|
279
|
-
if (border) {
|
|
280
|
-
const { x, y, width, height } = box;
|
|
281
|
-
if (border.left) {
|
|
282
|
-
drawBorder(border.left, x, y, x, y + height);
|
|
283
|
-
}
|
|
284
|
-
if (border.top) {
|
|
285
|
-
drawBorder(border.top, x, y, x + width, y);
|
|
286
|
-
}
|
|
287
|
-
if (border.right) {
|
|
288
|
-
drawBorder(border.right, x + width, y, x + width, y + height);
|
|
289
|
-
}
|
|
290
|
-
if (border.bottom) {
|
|
291
|
-
drawBorder(border.bottom, x, y + height, x + width, y + height);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function drawBorder([style, color], x1, y1, x2, y2) {
|
|
296
|
-
ctx.strokeStyle = color;
|
|
297
|
-
ctx.lineWidth = (style === "thin" ? 2 : 3) * thinLineWidth;
|
|
298
|
-
ctx.beginPath();
|
|
299
|
-
ctx.moveTo(x1, y1);
|
|
300
|
-
ctx.lineTo(x2, y2);
|
|
301
|
-
ctx.stroke();
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
private drawTexts(renderingContext: GridRenderingContext) {
|
|
306
|
-
const { ctx, thinLineWidth } = renderingContext;
|
|
307
|
-
ctx.textBaseline = "middle";
|
|
308
|
-
let currentFont;
|
|
309
|
-
for (let box of this.boxes) {
|
|
310
|
-
if (box.text) {
|
|
311
|
-
const style = box.style || {};
|
|
312
|
-
const align = box.align!;
|
|
313
|
-
const italic = style.italic ? "italic " : "";
|
|
314
|
-
const weight = style.bold ? "bold" : DEFAULT_FONT_WEIGHT;
|
|
315
|
-
const sizeInPt = style.fontSize || DEFAULT_FONT_SIZE;
|
|
316
|
-
const size = fontSizeMap[sizeInPt];
|
|
317
|
-
const font = `${italic}${weight} ${size}px ${DEFAULT_FONT}`;
|
|
318
|
-
if (font !== currentFont) {
|
|
319
|
-
currentFont = font;
|
|
320
|
-
ctx.font = font;
|
|
321
|
-
}
|
|
322
|
-
ctx.fillStyle = style.textColor || "#000";
|
|
323
|
-
let x: number;
|
|
324
|
-
let y = box.y + box.height / 2 + 1;
|
|
325
|
-
if (align === "left") {
|
|
326
|
-
x = box.x + 3;
|
|
327
|
-
} else if (align === "right") {
|
|
328
|
-
x = box.x + box.width - 3;
|
|
329
|
-
} else {
|
|
330
|
-
x = box.x + box.width / 2;
|
|
331
|
-
}
|
|
332
|
-
ctx.textAlign = align;
|
|
333
|
-
if (box.clipRect) {
|
|
334
|
-
ctx.save();
|
|
335
|
-
ctx.beginPath();
|
|
336
|
-
ctx.rect(...box.clipRect);
|
|
337
|
-
ctx.clip();
|
|
338
|
-
}
|
|
339
|
-
ctx.fillText(box.text, Math.round(x), Math.round(y));
|
|
340
|
-
if (style.strikethrough) {
|
|
341
|
-
if (align === "right") {
|
|
342
|
-
x = x - box.textWidth;
|
|
343
|
-
} else if (align === "center") {
|
|
344
|
-
x = x - box.textWidth / 2;
|
|
345
|
-
}
|
|
346
|
-
ctx.fillRect(x, y, box.textWidth, 2.6 * thinLineWidth);
|
|
347
|
-
}
|
|
348
|
-
if (box.clipRect) {
|
|
349
|
-
ctx.restore();
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
private drawHeaders(renderingContext: GridRenderingContext) {
|
|
356
|
-
const { ctx, viewport, thinLineWidth } = renderingContext;
|
|
357
|
-
let { width, height, offsetX, offsetY, left, top, right, bottom } = viewport;
|
|
358
|
-
offsetX -= HEADER_WIDTH;
|
|
359
|
-
offsetY -= HEADER_HEIGHT;
|
|
360
|
-
const selection = this.getters.getSelectedZones();
|
|
361
|
-
const { cols, rows } = this.workbook.activeSheet;
|
|
362
|
-
const activeCols = this.getters.getActiveCols();
|
|
363
|
-
const activeRows = this.getters.getActiveRows();
|
|
364
|
-
|
|
365
|
-
ctx.fillStyle = BACKGROUND_HEADER_COLOR;
|
|
366
|
-
ctx.font = `400 ${HEADER_FONT_SIZE}px ${DEFAULT_FONT}`;
|
|
367
|
-
ctx.textAlign = "center";
|
|
368
|
-
ctx.textBaseline = "middle";
|
|
369
|
-
ctx.lineWidth = thinLineWidth;
|
|
370
|
-
ctx.strokeStyle = "#333";
|
|
371
|
-
|
|
372
|
-
// background
|
|
373
|
-
ctx.fillRect(0, 0, width, HEADER_HEIGHT);
|
|
374
|
-
ctx.fillRect(0, 0, HEADER_WIDTH, height);
|
|
375
|
-
// selection background
|
|
376
|
-
ctx.fillStyle = BACKGROUND_HEADER_SELECTED_COLOR;
|
|
377
|
-
for (let zone of selection) {
|
|
378
|
-
const x1 = Math.max(HEADER_WIDTH, cols[zone.left].start - offsetX);
|
|
379
|
-
const x2 = Math.max(HEADER_WIDTH, cols[zone.right].end - offsetX);
|
|
380
|
-
const y1 = Math.max(HEADER_HEIGHT, rows[zone.top].start - offsetY);
|
|
381
|
-
const y2 = Math.max(HEADER_HEIGHT, rows[zone.bottom].end - offsetY);
|
|
382
|
-
ctx.fillStyle = activeCols.has(zone.left)
|
|
383
|
-
? BACKGROUND_HEADER_ACTIVE_COLOR
|
|
384
|
-
: BACKGROUND_HEADER_SELECTED_COLOR;
|
|
385
|
-
ctx.fillRect(x1, 0, x2 - x1, HEADER_HEIGHT);
|
|
386
|
-
ctx.fillStyle = activeRows.has(zone.top)
|
|
387
|
-
? BACKGROUND_HEADER_ACTIVE_COLOR
|
|
388
|
-
: BACKGROUND_HEADER_SELECTED_COLOR;
|
|
389
|
-
ctx.fillRect(0, y1, HEADER_WIDTH, y2 - y1);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// 2 main lines
|
|
393
|
-
ctx.beginPath();
|
|
394
|
-
ctx.moveTo(HEADER_WIDTH, 0);
|
|
395
|
-
ctx.lineTo(HEADER_WIDTH, height);
|
|
396
|
-
ctx.moveTo(0, HEADER_HEIGHT);
|
|
397
|
-
ctx.lineTo(width, HEADER_HEIGHT);
|
|
398
|
-
ctx.strokeStyle = HEADER_BORDER_COLOR;
|
|
399
|
-
ctx.stroke();
|
|
400
|
-
|
|
401
|
-
ctx.beginPath();
|
|
402
|
-
// column text + separator
|
|
403
|
-
for (let i = left; i <= right; i++) {
|
|
404
|
-
const col = cols[i];
|
|
405
|
-
ctx.fillStyle = activeCols.has(i) ? "#fff" : TEXT_HEADER_COLOR;
|
|
406
|
-
ctx.fillText(col.name, (col.start + col.end) / 2 - offsetX, HEADER_HEIGHT / 2);
|
|
407
|
-
ctx.moveTo(col.end - offsetX, 0);
|
|
408
|
-
ctx.lineTo(col.end - offsetX, HEADER_HEIGHT);
|
|
409
|
-
}
|
|
410
|
-
// row text + separator
|
|
411
|
-
for (let i = top; i <= bottom; i++) {
|
|
412
|
-
const row = rows[i];
|
|
413
|
-
ctx.fillStyle = activeRows.has(i) ? "#fff" : TEXT_HEADER_COLOR;
|
|
414
|
-
|
|
415
|
-
ctx.fillText(row.name, HEADER_WIDTH / 2, (row.start + row.end) / 2 - offsetY);
|
|
416
|
-
ctx.moveTo(0, row.end - offsetY);
|
|
417
|
-
ctx.lineTo(HEADER_WIDTH, row.end - offsetY);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
ctx.stroke();
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
private hasContent(col: number, row: number): boolean {
|
|
424
|
-
const { cells, mergeCellMap } = this.workbook.activeSheet;
|
|
425
|
-
const xc = toXC(col, row);
|
|
426
|
-
const cell = cells[xc];
|
|
427
|
-
return (cell && cell.content) || ((xc in mergeCellMap) as any);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
private getGridBoxes(renderingContext: GridRenderingContext): Box[] {
|
|
431
|
-
const { viewport } = renderingContext;
|
|
432
|
-
let { right, left, top, bottom, offsetX, offsetY } = viewport;
|
|
433
|
-
offsetX -= HEADER_WIDTH;
|
|
434
|
-
offsetY -= HEADER_HEIGHT;
|
|
435
|
-
|
|
436
|
-
const result: Box[] = [];
|
|
437
|
-
const { cols, rows, mergeCellMap, cells, merges } = this.workbook.activeSheet;
|
|
438
|
-
// process all visible cells
|
|
439
|
-
for (let rowNumber = top; rowNumber <= bottom; rowNumber++) {
|
|
440
|
-
let row = rows[rowNumber];
|
|
441
|
-
for (let colNumber = left; colNumber <= right; colNumber++) {
|
|
442
|
-
let cell = row.cells[colNumber];
|
|
443
|
-
if (cell && !(cell.xc in mergeCellMap)) {
|
|
444
|
-
let col = cols[colNumber];
|
|
445
|
-
const text = this.getters.getCellText(cell);
|
|
446
|
-
const textWidth = this.getters.getCellWidth(cell);
|
|
447
|
-
let style = this.getters.getCellStyle(cell);
|
|
448
|
-
const conditionalStyle = this.getters.getConditionalStyle(cell.xc);
|
|
449
|
-
if (conditionalStyle) {
|
|
450
|
-
style = Object.assign({}, style, conditionalStyle);
|
|
451
|
-
}
|
|
452
|
-
const align = text
|
|
453
|
-
? (style && style.align) || computeAlign(cell, this.getters.shouldShowFormulas())
|
|
454
|
-
: undefined;
|
|
455
|
-
let clipRect: Rect | null = null;
|
|
456
|
-
if (text && textWidth > cols[cell.col].size) {
|
|
457
|
-
let c: number;
|
|
458
|
-
let width: number;
|
|
459
|
-
switch (align) {
|
|
460
|
-
case "left":
|
|
461
|
-
c = cell.col;
|
|
462
|
-
while (c < right && !this.hasContent(c + 1, cell.row)) {
|
|
463
|
-
c++;
|
|
464
|
-
}
|
|
465
|
-
width = cols[c].end - col.start;
|
|
466
|
-
if (width < textWidth) {
|
|
467
|
-
clipRect = [col.start - offsetX, row.start - offsetY, width, row.size];
|
|
468
|
-
}
|
|
469
|
-
break;
|
|
470
|
-
case "right":
|
|
471
|
-
c = cell.col;
|
|
472
|
-
while (c > left && !this.hasContent(c - 1, cell.row)) {
|
|
473
|
-
c--;
|
|
474
|
-
}
|
|
475
|
-
width = col.end - cols[c].start;
|
|
476
|
-
if (width < textWidth) {
|
|
477
|
-
clipRect = [cols[c].start - offsetX, row.start - offsetY, width, row.size];
|
|
478
|
-
}
|
|
479
|
-
break;
|
|
480
|
-
case "center":
|
|
481
|
-
let c1 = colNumber;
|
|
482
|
-
while (c1 > left && !this.hasContent(c1 - 1, rowNumber)) {
|
|
483
|
-
c1--;
|
|
484
|
-
}
|
|
485
|
-
let c2 = colNumber;
|
|
486
|
-
while (c2 < right && !this.hasContent(c2 + 1, rowNumber)) {
|
|
487
|
-
c2++;
|
|
488
|
-
}
|
|
489
|
-
const colLeft = Math.min(c1, colNumber);
|
|
490
|
-
const colRight = Math.max(c2, colNumber);
|
|
491
|
-
width = cols[colRight].end - cols[colLeft].start;
|
|
492
|
-
if (width < textWidth || colLeft === colNumber || colRight === colNumber) {
|
|
493
|
-
clipRect = [cols[colLeft].start - offsetX, row.start - offsetY, width, row.size];
|
|
494
|
-
}
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
result.push({
|
|
500
|
-
x: col.start - offsetX,
|
|
501
|
-
y: row.start - offsetY,
|
|
502
|
-
width: col.size,
|
|
503
|
-
height: row.size,
|
|
504
|
-
text,
|
|
505
|
-
textWidth,
|
|
506
|
-
border: this.getters.getCellBorder(cell),
|
|
507
|
-
style,
|
|
508
|
-
align,
|
|
509
|
-
clipRect,
|
|
510
|
-
error: cell.error,
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// process all visible merges
|
|
517
|
-
for (let id in merges) {
|
|
518
|
-
let merge = merges[id];
|
|
519
|
-
if (overlap(merge, viewport)) {
|
|
520
|
-
const refCell = cells[merge.topLeft];
|
|
521
|
-
const bottomRight = cells[toXC(merge.right, merge.bottom)];
|
|
522
|
-
const width = cols[merge.right].end - cols[merge.left].start;
|
|
523
|
-
let text, textWidth, style, align, border;
|
|
524
|
-
if (refCell || bottomRight) {
|
|
525
|
-
text = refCell ? this.getters.getCellText(refCell) : "";
|
|
526
|
-
textWidth = refCell ? this.getters.getCellWidth(refCell) : null;
|
|
527
|
-
const cfStyle = this.getters.getConditionalStyle(merge.topLeft);
|
|
528
|
-
style = cfStyle ? cfStyle : refCell ? this.getters.getCellStyle(refCell) : null;
|
|
529
|
-
align = text
|
|
530
|
-
? (style && style.align) || computeAlign(refCell, this.getters.shouldShowFormulas())
|
|
531
|
-
: null;
|
|
532
|
-
const borderTopLeft = refCell ? this.getters.getCellBorder(refCell) : null;
|
|
533
|
-
const borderBottomRight = bottomRight ? this.getters.getCellBorder(bottomRight) : null;
|
|
534
|
-
border = {
|
|
535
|
-
bottom: borderBottomRight ? borderBottomRight.bottom : null,
|
|
536
|
-
left: borderTopLeft ? borderTopLeft.left : null,
|
|
537
|
-
right: borderBottomRight ? borderBottomRight.right : null,
|
|
538
|
-
top: borderTopLeft ? borderTopLeft.top : null,
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
style = style || {};
|
|
542
|
-
// Small trick: the code that draw the background color skips the color
|
|
543
|
-
// #ffffff. But for merges, we actually need to draw the background,
|
|
544
|
-
// otherwise the grid is visible. So, we change the #ffffff color to the
|
|
545
|
-
// color #fff, which is actually the same.
|
|
546
|
-
if (!style.fillColor || style.fillColor === "#ffffff") {
|
|
547
|
-
style = Object.create(style);
|
|
548
|
-
style.fillColor = "#fff";
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const x = cols[merge.left].start - offsetX;
|
|
552
|
-
const y = rows[merge.top].start - offsetY;
|
|
553
|
-
const height = rows[merge.bottom].end - rows[merge.top].start;
|
|
554
|
-
result.push({
|
|
555
|
-
x: x,
|
|
556
|
-
y: y,
|
|
557
|
-
width,
|
|
558
|
-
height,
|
|
559
|
-
text,
|
|
560
|
-
textWidth,
|
|
561
|
-
border,
|
|
562
|
-
style,
|
|
563
|
-
align,
|
|
564
|
-
clipRect: [x, y, width, height],
|
|
565
|
-
error: refCell ? refCell.error : undefined,
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
return result;
|
|
570
|
-
}
|
|
571
|
-
}
|