@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/clipboard.ts
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
import { BasePlugin } from "../base_plugin";
|
|
2
|
-
import { clip, toXC } from "../helpers/index";
|
|
3
|
-
import { Mode } from "../model";
|
|
4
|
-
import { _lt } from "../translation";
|
|
5
|
-
import {
|
|
6
|
-
CancelledReason,
|
|
7
|
-
Cell,
|
|
8
|
-
Command,
|
|
9
|
-
CommandResult,
|
|
10
|
-
GridRenderingContext,
|
|
11
|
-
LAYERS,
|
|
12
|
-
Zone,
|
|
13
|
-
} from "../types/index";
|
|
14
|
-
|
|
15
|
-
interface ClipboardCell {
|
|
16
|
-
cell: Cell | null;
|
|
17
|
-
col: number;
|
|
18
|
-
row: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Clipboard Plugin
|
|
23
|
-
*
|
|
24
|
-
* This clipboard manages all cut/copy/paste interactions internal to the
|
|
25
|
-
* application, and with the OS clipboard as well.
|
|
26
|
-
*/
|
|
27
|
-
export class ClipboardPlugin extends BasePlugin {
|
|
28
|
-
static layers = [LAYERS.Clipboard];
|
|
29
|
-
static getters = ["getClipboardContent", "isPaintingFormat", "getPasteZones"];
|
|
30
|
-
static modes: Mode[] = ["normal", "readonly"];
|
|
31
|
-
|
|
32
|
-
private status: "empty" | "visible" | "invisible" = "empty";
|
|
33
|
-
private shouldCut?: boolean;
|
|
34
|
-
private zones: Zone[] = [];
|
|
35
|
-
private cells?: ClipboardCell[][];
|
|
36
|
-
private originSheet: string = this.workbook.activeSheet.id;
|
|
37
|
-
private _isPaintingFormat: boolean = false;
|
|
38
|
-
private pasteOnlyValue: boolean = false;
|
|
39
|
-
private pasteOnlyFormat: boolean = false;
|
|
40
|
-
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// Command Handling
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
|
|
45
|
-
allowDispatch(cmd: Command): CommandResult {
|
|
46
|
-
if (cmd.type === "PASTE") {
|
|
47
|
-
return this.isPasteAllowed(cmd.target);
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
status: "SUCCESS",
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
handle(cmd: Command) {
|
|
55
|
-
switch (cmd.type) {
|
|
56
|
-
case "COPY":
|
|
57
|
-
this.cutOrCopy(cmd.target, false);
|
|
58
|
-
break;
|
|
59
|
-
case "CUT":
|
|
60
|
-
this.cutOrCopy(cmd.target, true);
|
|
61
|
-
break;
|
|
62
|
-
case "PASTE":
|
|
63
|
-
this.pasteOnlyValue = "onlyValue" in cmd && !!cmd.onlyValue;
|
|
64
|
-
const onlyFormat = "onlyFormat" in cmd ? !!cmd.onlyFormat : this._isPaintingFormat;
|
|
65
|
-
this._isPaintingFormat = false;
|
|
66
|
-
this.pasteOnlyFormat = !this.pasteOnlyValue && onlyFormat;
|
|
67
|
-
if (cmd.interactive) {
|
|
68
|
-
this.interactivePaste(cmd.target);
|
|
69
|
-
} else {
|
|
70
|
-
this.pasteFromModel(cmd.target);
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
case "PASTE_CELL":
|
|
74
|
-
this.pasteCell(cmd.origin, cmd.col, cmd.row, cmd.onlyValue, cmd.onlyFormat);
|
|
75
|
-
break;
|
|
76
|
-
case "PASTE_FROM_OS_CLIPBOARD":
|
|
77
|
-
this.pasteFromClipboard(cmd.target, cmd.text);
|
|
78
|
-
break;
|
|
79
|
-
case "ACTIVATE_PAINT_FORMAT":
|
|
80
|
-
this._isPaintingFormat = true;
|
|
81
|
-
this.cutOrCopy(cmd.target, false);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
// Getters
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Format the current clipboard to a string suitable for being pasted in other
|
|
92
|
-
* programs.
|
|
93
|
-
*
|
|
94
|
-
* - add a tab character between each concecutive cells
|
|
95
|
-
* - add a newline character between each line
|
|
96
|
-
*
|
|
97
|
-
* Note that it returns \t if the clipboard is empty. This is necessary for the
|
|
98
|
-
* clipboard copy event to add it as data, otherwise an empty string is not
|
|
99
|
-
* considered as a copy content.
|
|
100
|
-
*/
|
|
101
|
-
getClipboardContent(): string {
|
|
102
|
-
if (!this.cells) {
|
|
103
|
-
return "\t";
|
|
104
|
-
}
|
|
105
|
-
return (
|
|
106
|
-
this.cells
|
|
107
|
-
.map((cells) => {
|
|
108
|
-
return cells.map((c) => (c.cell ? this.getters.getCellText(c.cell) : "")).join("\t");
|
|
109
|
-
})
|
|
110
|
-
.join("\n") || "\t"
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
getPasteZones(target: Zone[]): Zone[] {
|
|
115
|
-
if (!this.cells) {
|
|
116
|
-
return target;
|
|
117
|
-
}
|
|
118
|
-
const height = this.cells.length;
|
|
119
|
-
const width = this.cells[0].length;
|
|
120
|
-
const selection = target[target.length - 1];
|
|
121
|
-
const pasteZones: Zone[] = [];
|
|
122
|
-
let col = selection.left;
|
|
123
|
-
let row = selection.top;
|
|
124
|
-
const repX = Math.max(1, Math.floor((selection.right + 1 - selection.left) / width));
|
|
125
|
-
const repY = Math.max(1, Math.floor((selection.bottom + 1 - selection.top) / height));
|
|
126
|
-
for (let x = 1; x <= repX; x++) {
|
|
127
|
-
for (let y = 1; y <= repY; y++) {
|
|
128
|
-
pasteZones.push({
|
|
129
|
-
left: col,
|
|
130
|
-
top: row,
|
|
131
|
-
right: col - 1 + x * width,
|
|
132
|
-
bottom: row - 1 + y * height,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return pasteZones;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
isPaintingFormat(): boolean {
|
|
140
|
-
return this._isPaintingFormat;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// ---------------------------------------------------------------------------
|
|
144
|
-
// Private methods
|
|
145
|
-
// ---------------------------------------------------------------------------
|
|
146
|
-
|
|
147
|
-
private cutOrCopy(zones: Zone[], cut: boolean) {
|
|
148
|
-
const tops = new Set(zones.map((z) => z.top));
|
|
149
|
-
const bottoms = new Set(zones.map((z) => z.bottom));
|
|
150
|
-
const areZonesCompatible = tops.size === 1 && bottoms.size === 1;
|
|
151
|
-
let clippedZones = areZonesCompatible ? zones : [zones[zones.length - 1]];
|
|
152
|
-
clippedZones = clippedZones.map((z) => Object.assign({}, z));
|
|
153
|
-
|
|
154
|
-
const cells: ClipboardCell[][] = [];
|
|
155
|
-
let { top, bottom } = clippedZones[0];
|
|
156
|
-
for (let r = top; r <= bottom; r++) {
|
|
157
|
-
const row: ClipboardCell[] = [];
|
|
158
|
-
cells.push(row);
|
|
159
|
-
for (let zone of clippedZones) {
|
|
160
|
-
let { left, right } = zone;
|
|
161
|
-
for (let c = left; c <= right; c++) {
|
|
162
|
-
const cell = this.getters.getCell(c, r);
|
|
163
|
-
row.push({
|
|
164
|
-
cell: cell ? Object.assign({}, cell) : null,
|
|
165
|
-
col: c,
|
|
166
|
-
row: r,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
this.status = "visible";
|
|
172
|
-
this.shouldCut = cut;
|
|
173
|
-
this.zones = clippedZones;
|
|
174
|
-
this.cells = cells;
|
|
175
|
-
this.originSheet = this.workbook.activeSheet.id;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private pasteFromClipboard(target: Zone[], content: string) {
|
|
179
|
-
this.status = "invisible";
|
|
180
|
-
const values = content
|
|
181
|
-
.replace(/\r/g, "")
|
|
182
|
-
.split("\n")
|
|
183
|
-
.map((vals) => vals.split("\t"));
|
|
184
|
-
const { left: activeCol, top: activeRow } = target[0];
|
|
185
|
-
const width = Math.max.apply(
|
|
186
|
-
Math,
|
|
187
|
-
values.map((a) => a.length)
|
|
188
|
-
);
|
|
189
|
-
const height = values.length;
|
|
190
|
-
this.addMissingDimensions(width, height, activeCol, activeRow);
|
|
191
|
-
for (let i = 0; i < values.length; i++) {
|
|
192
|
-
for (let j = 0; j < values[i].length; j++) {
|
|
193
|
-
const xc = toXC(activeCol + j, activeRow + i);
|
|
194
|
-
this.dispatch("SET_VALUE", { xc, text: values[i][j] });
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
this.dispatch("SET_SELECTION", {
|
|
198
|
-
anchor: [activeCol, activeRow],
|
|
199
|
-
zones: [
|
|
200
|
-
{
|
|
201
|
-
left: activeCol,
|
|
202
|
-
top: activeRow,
|
|
203
|
-
right: activeCol + width - 1,
|
|
204
|
-
bottom: activeRow + height - 1,
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private isPasteAllowed(target: Zone[]): CommandResult {
|
|
211
|
-
const { zones, cells, status } = this;
|
|
212
|
-
// cannot paste if we have a clipped zone larger than a cell and multiple
|
|
213
|
-
// zones selected
|
|
214
|
-
if (!zones || !cells || status === "empty") {
|
|
215
|
-
return { status: "CANCELLED", reason: CancelledReason.EmptyClipboard };
|
|
216
|
-
} else if (target.length > 1 && (cells.length > 1 || cells[0].length > 1)) {
|
|
217
|
-
return { status: "CANCELLED", reason: CancelledReason.WrongPasteSelection };
|
|
218
|
-
}
|
|
219
|
-
return { status: "SUCCESS" };
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private pasteFromModel(target: Zone[]) {
|
|
223
|
-
const { cells, shouldCut } = this;
|
|
224
|
-
if (!cells) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
this.status = shouldCut ? "empty" : "invisible";
|
|
228
|
-
if (shouldCut) {
|
|
229
|
-
this.clearCutZone();
|
|
230
|
-
}
|
|
231
|
-
const height = cells.length;
|
|
232
|
-
const width = cells[0].length;
|
|
233
|
-
if (target.length > 1) {
|
|
234
|
-
for (let zone of target) {
|
|
235
|
-
for (let i = zone.left; i <= zone.right; i++) {
|
|
236
|
-
for (let j = zone.top; j <= zone.bottom; j++) {
|
|
237
|
-
this.pasteZone(width, height, i, j);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const selection = target[target.length - 1];
|
|
244
|
-
let col = selection.left;
|
|
245
|
-
let row = selection.top;
|
|
246
|
-
const repX = Math.max(1, Math.floor((selection.right + 1 - selection.left) / width));
|
|
247
|
-
const repY = Math.max(1, Math.floor((selection.bottom + 1 - selection.top) / height));
|
|
248
|
-
for (let x = 0; x < repX; x++) {
|
|
249
|
-
for (let y = 0; y < repY; y++) {
|
|
250
|
-
this.pasteZone(width, height, col + x * width, row + y * height);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (height > 1 || width > 1) {
|
|
255
|
-
const newSelection = {
|
|
256
|
-
left: col,
|
|
257
|
-
top: row,
|
|
258
|
-
right: col + repX * width - 1,
|
|
259
|
-
bottom: row + repY * height - 1,
|
|
260
|
-
};
|
|
261
|
-
const [anchorCol, anchorRow] = this.getters.getSelection().anchor;
|
|
262
|
-
const newCol = clip(anchorCol, col, col + repX * width - 1);
|
|
263
|
-
const newRow = clip(anchorRow, row, row + repY * height - 1);
|
|
264
|
-
this.dispatch("SET_SELECTION", {
|
|
265
|
-
anchor: [newCol, newRow],
|
|
266
|
-
zones: [newSelection],
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
private clearCutZone() {
|
|
272
|
-
for (let row of this.cells!) {
|
|
273
|
-
for (let cell of row) {
|
|
274
|
-
if (cell) {
|
|
275
|
-
this.dispatch("CLEAR_CELL", {
|
|
276
|
-
sheet: this.originSheet,
|
|
277
|
-
col: cell.col,
|
|
278
|
-
row: cell.row,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
private pasteZone(width: number, height: number, col: number, row: number) {
|
|
286
|
-
// first, add missing cols/rows if needed
|
|
287
|
-
this.addMissingDimensions(width, height, col, row);
|
|
288
|
-
// then, perform the actual paste operation
|
|
289
|
-
for (let r = 0; r < height; r++) {
|
|
290
|
-
const rowCells = this.cells![r];
|
|
291
|
-
for (let c = 0; c < width; c++) {
|
|
292
|
-
const originCell = rowCells[c];
|
|
293
|
-
this.dispatch("PASTE_CELL", {
|
|
294
|
-
origin: originCell.cell,
|
|
295
|
-
originCol: originCell.col,
|
|
296
|
-
originRow: originCell.row,
|
|
297
|
-
col: col + c,
|
|
298
|
-
row: row + r,
|
|
299
|
-
sheet: this.originSheet,
|
|
300
|
-
cut: this.shouldCut,
|
|
301
|
-
onlyValue: this.pasteOnlyValue,
|
|
302
|
-
onlyFormat: this.pasteOnlyFormat,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
private addMissingDimensions(width, height, col, row) {
|
|
309
|
-
const { cols, rows } = this.workbook.activeSheet;
|
|
310
|
-
const missingRows = height + row - rows.length;
|
|
311
|
-
if (missingRows > 0) {
|
|
312
|
-
this.dispatch("ADD_ROWS", {
|
|
313
|
-
row: rows.length - 1,
|
|
314
|
-
sheet: this.workbook.activeSheet.id,
|
|
315
|
-
quantity: missingRows,
|
|
316
|
-
position: "after",
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
const missingCols = width + col - cols.length;
|
|
320
|
-
if (missingCols > 0) {
|
|
321
|
-
this.dispatch("ADD_COLUMNS", {
|
|
322
|
-
column: cols.length - 1,
|
|
323
|
-
sheet: this.workbook.activeSheet.id,
|
|
324
|
-
quantity: missingCols,
|
|
325
|
-
position: "after",
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
pasteCell(
|
|
331
|
-
origin: Cell | null,
|
|
332
|
-
col: number,
|
|
333
|
-
row: number,
|
|
334
|
-
onlyValue: boolean,
|
|
335
|
-
onlyFormat: boolean
|
|
336
|
-
) {
|
|
337
|
-
const targetCell = this.getters.getCell(col, row);
|
|
338
|
-
if (origin) {
|
|
339
|
-
let style = origin.style;
|
|
340
|
-
let border = origin.border;
|
|
341
|
-
let format = origin.format;
|
|
342
|
-
let content: string | undefined = origin.content || "";
|
|
343
|
-
|
|
344
|
-
if (onlyValue) {
|
|
345
|
-
style = targetCell ? targetCell.style : undefined;
|
|
346
|
-
border = targetCell ? targetCell.border : undefined;
|
|
347
|
-
format = targetCell ? targetCell.format : undefined;
|
|
348
|
-
|
|
349
|
-
if (targetCell) {
|
|
350
|
-
if (targetCell.type === "date") {
|
|
351
|
-
format = targetCell.value.format;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (origin.type === "formula" || origin.type === "date") {
|
|
355
|
-
content = this.valueToContent(origin.value);
|
|
356
|
-
}
|
|
357
|
-
} else if (onlyFormat) {
|
|
358
|
-
content = targetCell ? targetCell.content : "";
|
|
359
|
-
} else if (origin.type === "formula") {
|
|
360
|
-
const offsetX = col - origin.col;
|
|
361
|
-
const offsetY = row - origin.row;
|
|
362
|
-
content = this.getters.applyOffset(content, offsetX, offsetY);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
let newCell = {
|
|
366
|
-
style: style,
|
|
367
|
-
border: border,
|
|
368
|
-
format: format,
|
|
369
|
-
sheet: this.workbook.activeSheet.id,
|
|
370
|
-
col: col,
|
|
371
|
-
row: row,
|
|
372
|
-
content: content,
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
this.dispatch("UPDATE_CELL", newCell);
|
|
376
|
-
}
|
|
377
|
-
if (!origin && targetCell) {
|
|
378
|
-
if (onlyValue) {
|
|
379
|
-
if (targetCell.content) {
|
|
380
|
-
//this.history.updateCell(targetCell, "content", undefined);
|
|
381
|
-
this.history.updateCell(targetCell, "content", "");
|
|
382
|
-
this.history.updateCell(targetCell, "value", "");
|
|
383
|
-
}
|
|
384
|
-
} else if (onlyFormat) {
|
|
385
|
-
if (targetCell.style) {
|
|
386
|
-
this.history.updateCell(targetCell, "style", undefined);
|
|
387
|
-
}
|
|
388
|
-
if (targetCell.border) {
|
|
389
|
-
this.history.updateCell(targetCell, "border", undefined);
|
|
390
|
-
}
|
|
391
|
-
if (targetCell.format) {
|
|
392
|
-
this.history.updateCell(targetCell, "format", undefined);
|
|
393
|
-
}
|
|
394
|
-
} else {
|
|
395
|
-
this.dispatch("CLEAR_CELL", {
|
|
396
|
-
sheet: this.workbook.activeSheet.id,
|
|
397
|
-
col: col,
|
|
398
|
-
row: row,
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
private valueToContent(cellValue: any): string {
|
|
405
|
-
switch (typeof cellValue) {
|
|
406
|
-
case "number":
|
|
407
|
-
return cellValue.toString();
|
|
408
|
-
case "string":
|
|
409
|
-
return cellValue;
|
|
410
|
-
case "boolean":
|
|
411
|
-
return cellValue ? "TRUE" : "FALSE";
|
|
412
|
-
case "object":
|
|
413
|
-
return cellValue.value.toString();
|
|
414
|
-
default:
|
|
415
|
-
return "";
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
interactivePaste(target: Zone[]) {
|
|
420
|
-
const result = this.dispatch("PASTE", { target, onlyFormat: false });
|
|
421
|
-
|
|
422
|
-
if (result.status === "CANCELLED") {
|
|
423
|
-
if (result.reason === CancelledReason.WrongPasteSelection) {
|
|
424
|
-
this.ui.notifyUser(_lt("This operation is not allowed with multiple selections."));
|
|
425
|
-
}
|
|
426
|
-
if (result.reason === CancelledReason.WillRemoveExistingMerge) {
|
|
427
|
-
this.ui.askConfirmation(
|
|
428
|
-
_lt("Pasting here will remove existing merge(s). Paste anyway?"),
|
|
429
|
-
() => this.dispatch("PASTE", { target, onlyFormat: false, force: true })
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// ---------------------------------------------------------------------------
|
|
436
|
-
// Grid rendering
|
|
437
|
-
// ---------------------------------------------------------------------------
|
|
438
|
-
|
|
439
|
-
drawGrid(renderingContext: GridRenderingContext) {
|
|
440
|
-
const { viewport, ctx, thinLineWidth } = renderingContext;
|
|
441
|
-
const zones = this.zones;
|
|
442
|
-
if (
|
|
443
|
-
this.status !== "visible" ||
|
|
444
|
-
!zones.length ||
|
|
445
|
-
this.originSheet !== this.getters.getActiveSheet()
|
|
446
|
-
) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
ctx.save();
|
|
450
|
-
ctx.setLineDash([8, 5]);
|
|
451
|
-
ctx.strokeStyle = "#3266ca";
|
|
452
|
-
ctx.lineWidth = 3.3 * thinLineWidth;
|
|
453
|
-
for (const zone of zones) {
|
|
454
|
-
const [x, y, width, height] = this.getters.getRect(zone, viewport);
|
|
455
|
-
if (width > 0 && height > 0) {
|
|
456
|
-
ctx.strokeRect(x, y, width, height);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
ctx.restore();
|
|
460
|
-
}
|
|
461
|
-
}
|