@odoo/o-spreadsheet 14.0.1 → 14.0.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.
Files changed (204) hide show
  1. package/dist/o_spreadsheet.cjs.js +17836 -0
  2. package/dist/o_spreadsheet.d.ts +4102 -0
  3. package/dist/o_spreadsheet.esm.js +17801 -0
  4. package/dist/o_spreadsheet.iife.js +17838 -0
  5. package/dist/o_spreadsheet.iife.min.js +1440 -0
  6. package/package.json +27 -7
  7. package/readme.md +10 -0
  8. package/.eslintrc.json +0 -20
  9. package/.husky/post-checkout +0 -9
  10. package/.husky/pre-commit +0 -39
  11. package/.prettierignore +0 -1
  12. package/astToFormula.patch +0 -0
  13. package/demo/data.js +0 -255
  14. package/demo/index.html +0 -9
  15. package/demo/libs/Chart.bundle.js +0 -20755
  16. package/demo/main.js +0 -101
  17. package/doc/readme.md +0 -46
  18. package/rollup.config.js +0 -23
  19. package/src/base_plugin.ts +0 -102
  20. package/src/components/autofill.ts +0 -146
  21. package/src/components/bottom_bar.ts +0 -199
  22. package/src/components/color_picker.ts +0 -150
  23. package/src/components/composer/autocomplete_dropdown.ts +0 -135
  24. package/src/components/composer/composer.ts +0 -487
  25. package/src/components/composer/content_editable_helper.ts +0 -146
  26. package/src/components/figures/chart.ts +0 -70
  27. package/src/components/figures/container.ts +0 -268
  28. package/src/components/figures/text_figure.ts +0 -36
  29. package/src/components/grid.ts +0 -635
  30. package/src/components/helpers/dom_helpers.ts +0 -7
  31. package/src/components/helpers/drag_and_drop.ts +0 -17
  32. package/src/components/icons.ts +0 -36
  33. package/src/components/index.ts +0 -1
  34. package/src/components/menu.ts +0 -288
  35. package/src/components/overlay.ts +0 -457
  36. package/src/components/scrollbar.ts +0 -22
  37. package/src/components/selection_input.ts +0 -168
  38. package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
  39. package/src/components/side_panel/chart_panel.ts +0 -104
  40. package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
  41. package/src/components/side_panel/conditional_formatting.ts +0 -396
  42. package/src/components/side_panel/side_panel.ts +0 -127
  43. package/src/components/side_panel/translations_terms.ts +0 -45
  44. package/src/components/spreadsheet.ts +0 -198
  45. package/src/components/top_bar.ts +0 -535
  46. package/src/constants.ts +0 -26
  47. package/src/data.ts +0 -149
  48. package/src/fonts.ts +0 -41
  49. package/src/formulas/compiler.ts +0 -258
  50. package/src/formulas/composer_tokenizer.ts +0 -70
  51. package/src/formulas/index.ts +0 -15
  52. package/src/formulas/normalize.ts +0 -52
  53. package/src/formulas/parser.ts +0 -280
  54. package/src/formulas/range_tokenizer.ts +0 -97
  55. package/src/formulas/tokenizer.ts +0 -242
  56. package/src/functions/arguments.ts +0 -114
  57. package/src/functions/dates.ts +0 -302
  58. package/src/functions/helpers.ts +0 -592
  59. package/src/functions/index.ts +0 -52
  60. package/src/functions/module_database.ts +0 -282
  61. package/src/functions/module_date.ts +0 -743
  62. package/src/functions/module_info.ts +0 -69
  63. package/src/functions/module_logical.ts +0 -208
  64. package/src/functions/module_lookup.ts +0 -185
  65. package/src/functions/module_math.ts +0 -1252
  66. package/src/functions/module_operators.ts +0 -291
  67. package/src/functions/module_statistical.ts +0 -882
  68. package/src/functions/module_text.ts +0 -370
  69. package/src/helpers/color.ts +0 -30
  70. package/src/helpers/coordinates.ts +0 -71
  71. package/src/helpers/grid_manipulation.ts +0 -68
  72. package/src/helpers/index.ts +0 -7
  73. package/src/helpers/misc.ts +0 -76
  74. package/src/helpers/numbers.ts +0 -117
  75. package/src/helpers/uuid.ts +0 -19
  76. package/src/helpers/zones.ts +0 -263
  77. package/src/history.ts +0 -186
  78. package/src/index.ts +0 -84
  79. package/src/model.ts +0 -261
  80. package/src/plugins/autofill.ts +0 -412
  81. package/src/plugins/chart.ts +0 -404
  82. package/src/plugins/clipboard.ts +0 -461
  83. package/src/plugins/conditional_format.ts +0 -445
  84. package/src/plugins/core.ts +0 -1502
  85. package/src/plugins/edition.ts +0 -157
  86. package/src/plugins/evaluation.ts +0 -428
  87. package/src/plugins/figures.ts +0 -123
  88. package/src/plugins/formatting.ts +0 -630
  89. package/src/plugins/highlight.ts +0 -187
  90. package/src/plugins/index.ts +0 -32
  91. package/src/plugins/merge.ts +0 -524
  92. package/src/plugins/renderer.ts +0 -571
  93. package/src/plugins/selection.ts +0 -562
  94. package/src/plugins/selection_inputs.ts +0 -326
  95. package/src/registries/autofill_modifiers.ts +0 -76
  96. package/src/registries/autofill_rules.ts +0 -98
  97. package/src/registries/figure_registry.ts +0 -30
  98. package/src/registries/index.ts +0 -7
  99. package/src/registries/menu_items_registry.ts +0 -110
  100. package/src/registries/menus/cell_menu_registry.ts +0 -79
  101. package/src/registries/menus/col_menu_registry.ts +0 -63
  102. package/src/registries/menus/index.ts +0 -6
  103. package/src/registries/menus/menu_items_actions.ts +0 -425
  104. package/src/registries/menus/row_menu_registry.ts +0 -63
  105. package/src/registries/menus/sheet_menu_registry.ts +0 -75
  106. package/src/registries/menus/topbar_menu_registry.ts +0 -204
  107. package/src/registries/side_panel_registry.ts +0 -26
  108. package/src/registries/topbar_component_registry.ts +0 -12
  109. package/src/registry.ts +0 -51
  110. package/src/translation.ts +0 -44
  111. package/src/types/autofill.ts +0 -48
  112. package/src/types/chart.ts +0 -26
  113. package/src/types/commands.ts +0 -716
  114. package/src/types/conditional_formatting.ts +0 -124
  115. package/src/types/env.ts +0 -13
  116. package/src/types/functions.ts +0 -35
  117. package/src/types/getters.ts +0 -103
  118. package/src/types/index.ts +0 -20
  119. package/src/types/misc.ts +0 -143
  120. package/src/types/rendering.ts +0 -41
  121. package/src/types/workbook_data.ts +0 -62
  122. package/tests/__mocks__/uuid.ts +0 -7
  123. package/tests/canvas.mock.ts +0 -34
  124. package/tests/components/__mocks__/content_editable_helper.ts +0 -79
  125. package/tests/components/__mocks__/scrollbar.ts +0 -18
  126. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
  127. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
  128. package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
  129. package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
  130. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
  131. package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
  132. package/tests/components/autocomplete_dropdown_test.ts +0 -315
  133. package/tests/components/autofill_test.ts +0 -167
  134. package/tests/components/bottom_bar_test.ts +0 -262
  135. package/tests/components/chart_side_panel_test.ts +0 -123
  136. package/tests/components/composer_test.ts +0 -400
  137. package/tests/components/context_menu_test.ts +0 -825
  138. package/tests/components/grid_manipulation_test.ts +0 -163
  139. package/tests/components/grid_test.ts +0 -581
  140. package/tests/components/overlay_test.ts +0 -541
  141. package/tests/components/selection_input_test.ts +0 -259
  142. package/tests/components/side_panel_test.ts +0 -148
  143. package/tests/components/spreadsheet_test.ts +0 -194
  144. package/tests/components/top_bar_test.ts +0 -427
  145. package/tests/data_test.ts +0 -175
  146. package/tests/dom_helper.ts +0 -42
  147. package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
  148. package/tests/formulas/compiler_test.ts +0 -266
  149. package/tests/formulas/composer_tokenizer_test.ts +0 -137
  150. package/tests/formulas/expressions_test.ts +0 -57
  151. package/tests/formulas/formulas_test.ts +0 -80
  152. package/tests/formulas/normalize_test.ts +0 -82
  153. package/tests/formulas/parser_test.ts +0 -224
  154. package/tests/formulas/range_tokenizer_test.ts +0 -187
  155. package/tests/formulas/tokenizer_test.ts +0 -164
  156. package/tests/functions/arguments_test.ts +0 -141
  157. package/tests/functions/dates_test.ts +0 -1081
  158. package/tests/functions/functions_test.ts +0 -53
  159. package/tests/functions/helper_test.ts +0 -98
  160. package/tests/functions/module_database_test.ts +0 -311
  161. package/tests/functions/module_date_test.ts +0 -941
  162. package/tests/functions/module_info_test.ts +0 -139
  163. package/tests/functions/module_logical_test.ts +0 -369
  164. package/tests/functions/module_lookup_test.ts +0 -541
  165. package/tests/functions/module_math_test.ts +0 -2482
  166. package/tests/functions/module_operators_test.ts +0 -955
  167. package/tests/functions/module_statistical_test.ts +0 -2014
  168. package/tests/functions/module_text_test.ts +0 -667
  169. package/tests/helpers/coordinates_test.ts +0 -25
  170. package/tests/helpers/misc_test.ts +0 -95
  171. package/tests/helpers/numbers_test.ts +0 -196
  172. package/tests/helpers/zones_test.ts +0 -97
  173. package/tests/helpers.ts +0 -384
  174. package/tests/menu_items_registry_test.ts +0 -540
  175. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
  176. package/tests/model/plugins/chart_test.ts +0 -562
  177. package/tests/model_test.ts +0 -82
  178. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
  179. package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
  180. package/tests/plugins/autofill_test.ts +0 -457
  181. package/tests/plugins/borders_test.ts +0 -295
  182. package/tests/plugins/clipboard_test.ts +0 -1180
  183. package/tests/plugins/conditional_formatting_test.ts +0 -1253
  184. package/tests/plugins/core_test.ts +0 -614
  185. package/tests/plugins/edition_test.ts +0 -100
  186. package/tests/plugins/evaluation_async_test.ts +0 -332
  187. package/tests/plugins/evaluation_dates_test.ts +0 -79
  188. package/tests/plugins/evaluation_test.ts +0 -901
  189. package/tests/plugins/figures_test.ts +0 -327
  190. package/tests/plugins/formatting_test.ts +0 -391
  191. package/tests/plugins/grid_manipulation_test.ts +0 -1366
  192. package/tests/plugins/highlight_test.ts +0 -413
  193. package/tests/plugins/history_test.ts +0 -142
  194. package/tests/plugins/import_export_test.ts +0 -276
  195. package/tests/plugins/merges_test.ts +0 -490
  196. package/tests/plugins/navigation_test.ts +0 -181
  197. package/tests/plugins/plugins/evaluation_test.ts +0 -111
  198. package/tests/plugins/renderer_test.ts +0 -598
  199. package/tests/plugins/resizing_test.ts +0 -152
  200. package/tests/plugins/selection_input_test.ts +0 -409
  201. package/tests/plugins/selection_test.ts +0 -442
  202. package/tests/plugins/sheets_test.ts +0 -643
  203. package/tests/plugins/style_test.ts +0 -90
  204. package/tsconfig.json +0 -22
@@ -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
- }