@odoo/o-spreadsheet 14.0.1 → 14.0.3

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 +17880 -0
  2. package/dist/o-spreadsheet.d.ts +4119 -0
  3. package/dist/o-spreadsheet.esm.js +17845 -0
  4. package/dist/o-spreadsheet.iife.js +17882 -0
  5. package/dist/o-spreadsheet.iife.min.js +1446 -0
  6. package/package.json +32 -9
  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,1180 +0,0 @@
1
- import { Model } from "../../src/model";
2
- import { ClipboardPlugin } from "../../src/plugins/clipboard";
3
- import { CancelledReason, ConditionalFormat, Style, Zone } from "../../src/types/index";
4
- import "../canvas.mock";
5
- import { getCell, getGrid, target, zone } from "../helpers";
6
-
7
- function getClipboardVisibleZones(model: Model): Zone[] {
8
- const clipboardPlugin = (model as any).handlers.find((h) => h instanceof ClipboardPlugin);
9
- return clipboardPlugin.status === "visible" ? clipboardPlugin.zones : [];
10
- }
11
-
12
- function createEqualCF(
13
- ranges: string[],
14
- value: string,
15
- style: Style,
16
- id: string
17
- ): ConditionalFormat {
18
- return {
19
- ranges,
20
- id,
21
- rule: { values: [value], operator: "Equal", type: "CellIsRule", style },
22
- };
23
- }
24
-
25
- describe("clipboard", () => {
26
- test("can copy and paste a cell", () => {
27
- const model = new Model();
28
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
29
-
30
- expect(model["workbook"].activeSheet.cells).toEqual({
31
- B2: { col: 1, row: 1, content: "b2", type: "text", value: "b2", xc: "B2" },
32
- });
33
-
34
- model.dispatch("COPY", { target: target("B2") });
35
- model.dispatch("PASTE", { target: target("D2") });
36
- expect(model["workbook"].activeSheet.cells).toEqual({
37
- B2: { col: 1, row: 1, content: "b2", type: "text", value: "b2", xc: "B2" },
38
- D2: { col: 3, row: 1, content: "b2", type: "text", value: "b2", xc: "D2" },
39
- });
40
- expect(getClipboardVisibleZones(model).length).toBe(0);
41
- });
42
-
43
- test("can cut and paste a cell", () => {
44
- const model = new Model();
45
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
46
- expect(model["workbook"].activeSheet.cells).toEqual({
47
- B2: { col: 1, row: 1, content: "b2", type: "text", value: "b2", xc: "B2" },
48
- });
49
-
50
- model.dispatch("CUT", { target: target("B2") });
51
- expect(model["workbook"].activeSheet.cells).toEqual({
52
- B2: { col: 1, row: 1, content: "b2", type: "text", value: "b2", xc: "B2" },
53
- });
54
- model.dispatch("PASTE", { target: target("D2") });
55
-
56
- expect(model["workbook"].activeSheet.cells).toEqual({
57
- D2: { col: 3, row: 1, content: "b2", type: "text", value: "b2", xc: "D2" },
58
- });
59
-
60
- expect(getClipboardVisibleZones(model).length).toBe(0);
61
-
62
- // select D3 and paste. it should do nothing
63
- model.dispatch("PASTE", { target: target("D3:D3") });
64
-
65
- expect(getCell(model, "D3")).toBeNull();
66
- });
67
-
68
- test("paste without copied value", () => {
69
- const model = new Model();
70
- const result = model.dispatch("PASTE", { target: target("D2") });
71
- expect(result).toEqual({
72
- status: "CANCELLED",
73
- reason: CancelledReason.EmptyClipboard,
74
- });
75
- });
76
-
77
- test("paste zones without copied value", () => {
78
- const model = new Model();
79
- const zones = target("A1,B2");
80
- const pasteZone = model.getters.getPasteZones(zones);
81
- expect(pasteZone).toEqual(zones);
82
- });
83
-
84
- test("can cut and paste a cell in differents sheets", () => {
85
- const model = new Model();
86
- model.dispatch("SET_VALUE", { xc: "A1", text: "a1" });
87
- model.dispatch("CUT", { target: target("A1") });
88
- const to = model.getters.getActiveSheet();
89
- model.dispatch("CREATE_SHEET", { activate: true, id: "42" });
90
- const from = model.getters.getActiveSheet();
91
- model.dispatch("SET_VALUE", { xc: "A1", text: "a1Sheet2" });
92
- model.dispatch("PASTE", { target: target("B2") });
93
- expect(model["workbook"].activeSheet.cells).toEqual({
94
- A1: { col: 0, row: 0, content: "a1Sheet2", type: "text", value: "a1Sheet2", xc: "A1" },
95
- B2: { col: 1, row: 1, content: "a1", type: "text", value: "a1", xc: "B2" },
96
- });
97
- model.dispatch("ACTIVATE_SHEET", { from, to });
98
- expect(model["workbook"].activeSheet.cells).toEqual({});
99
-
100
- expect(getClipboardVisibleZones(model).length).toBe(0);
101
-
102
- // select D3 and paste. it should do nothing
103
- model.dispatch("PASTE", { target: target("D3:D3") });
104
-
105
- expect(getCell(model, "D3")).toBeNull();
106
- });
107
-
108
- test("can cut and paste a zone inside the cut zone", () => {
109
- const model = new Model();
110
- model.dispatch("SET_VALUE", { xc: "A1", text: "a1" });
111
- model.dispatch("SET_VALUE", { xc: "A2", text: "a2" });
112
-
113
- model.dispatch("CUT", { target: target("A1:A2") });
114
- expect(getGrid(model)).toEqual({ A1: "a1", A2: "a2" });
115
-
116
- model.dispatch("PASTE", { target: target("A2") });
117
- expect(getGrid(model)).toEqual({ A2: "a1", A3: "a2" });
118
- });
119
-
120
- test("can copy a cell with style", () => {
121
- const model = new Model();
122
- const sheet1 = model["workbook"].activeSheet.id;
123
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
124
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
125
- model.dispatch("SET_FORMATTING", {
126
- sheet: sheet1,
127
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
128
- style: { bold: true },
129
- });
130
- expect(getCell(model, "B2")!.style).toBe(2);
131
-
132
- model.dispatch("COPY", { target: target("B2") });
133
- model.dispatch("PASTE", { target: target("C2") });
134
-
135
- expect(getCell(model, "B2")!.style).toBe(2);
136
- expect(getCell(model, "C2")!.style).toBe(2);
137
- });
138
-
139
- test("can copy into a cell with style", () => {
140
- const model = new Model();
141
- // set value and style in B2
142
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
143
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
144
- model.dispatch("SET_FORMATTING", {
145
- sheet: "Sheet1",
146
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
147
- style: { bold: true },
148
- });
149
- expect(getCell(model, "B2")!.style).toBe(2);
150
-
151
- // set value in A1, select and copy it
152
- model.dispatch("SET_VALUE", { xc: "A1", text: "a1" });
153
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
154
- model.dispatch("COPY", { target: target("A1") });
155
-
156
- // select B2 again and paste
157
- model.dispatch("PASTE", { target: target("B2") });
158
-
159
- expect(getCell(model, "B2")!.value).toBe("a1");
160
- expect(getCell(model, "B2")!.style).not.toBeDefined();
161
- });
162
-
163
- test("can copy from an empty cell into a cell with style", () => {
164
- const model = new Model();
165
- const sheet1 = model["workbook"].activeSheet.id;
166
- // set value and style in B2
167
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
168
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
169
- model.dispatch("SET_FORMATTING", {
170
- sheet: sheet1,
171
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
172
- style: { bold: true },
173
- });
174
- expect(getCell(model, "B2")!.style).toBe(2);
175
-
176
- // set value in A1, select and copy it
177
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
178
- model.dispatch("COPY", { target: target("A1") });
179
-
180
- model.dispatch("PASTE", { target: target("B2") });
181
-
182
- expect(getCell(model, "B2")).toBeNull();
183
- });
184
-
185
- test("can copy a cell with borders", () => {
186
- const model = new Model();
187
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
188
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
189
- model.dispatch("SET_FORMATTING", {
190
- sheet: model.getters.getActiveSheet(),
191
- target: model.getters.getSelectedZones(),
192
- border: "bottom",
193
- });
194
- expect(getCell(model, "B2")!.border).toBe(2);
195
-
196
- model.dispatch("COPY", { target: target("B2") });
197
- model.dispatch("PASTE", { target: target("C2") });
198
-
199
- expect(getCell(model, "B2")!.border).toBe(2);
200
- expect(getCell(model, "C2")!.border).toBe(2);
201
- });
202
-
203
- test("can copy a cell with a formatter", () => {
204
- const model = new Model();
205
- model.dispatch("SET_VALUE", { xc: "B2", text: "0.451" });
206
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
207
- model.dispatch("SET_FORMATTER", {
208
- sheet: model.getters.getActiveSheet(),
209
- target: model.getters.getSelectedZones(),
210
- formatter: "0.00%",
211
- });
212
- expect(model.getters.getCellText(getCell(model, "B2")!)).toBe("45.10%");
213
-
214
- model.dispatch("COPY", { target: target("B2") });
215
- model.dispatch("PASTE", { target: target("C2") });
216
-
217
- expect(model.getters.getCellText(getCell(model, "C2")!)).toBe("45.10%");
218
- });
219
-
220
- test("can copy and paste merged content", () => {
221
- const model = new Model({
222
- sheets: [
223
- {
224
- colNumber: 5,
225
- rowNumber: 5,
226
- merges: ["B1:C2"],
227
- },
228
- ],
229
- });
230
- model.dispatch("COPY", { target: target("B1") });
231
- model.dispatch("PASTE", { target: target("B4") });
232
- expect(model.getters.isInMerge("B4")).toBe(true);
233
- expect(model.getters.isInMerge("B5")).toBe(true);
234
- expect(model.getters.isInMerge("C4")).toBe(true);
235
- expect(model.getters.isInMerge("B5")).toBe(true);
236
- });
237
-
238
- test("can cut and paste merged content", () => {
239
- const model = new Model({
240
- sheets: [
241
- {
242
- colNumber: 5,
243
- rowNumber: 5,
244
- merges: ["B1:C2"],
245
- },
246
- ],
247
- });
248
- model.dispatch("CUT", { target: target("B1") });
249
- model.dispatch("PASTE", { target: target("B4") });
250
- expect(model.getters.isInMerge("B1")).toBe(false);
251
- expect(model.getters.isInMerge("B2")).toBe(false);
252
- expect(model.getters.isInMerge("C1")).toBe(false);
253
- expect(model.getters.isInMerge("B2")).toBe(false);
254
- expect(model.getters.isInMerge("B4")).toBe(true);
255
- expect(model.getters.isInMerge("B5")).toBe(true);
256
- expect(model.getters.isInMerge("C4")).toBe(true);
257
- expect(model.getters.isInMerge("B5")).toBe(true);
258
- });
259
-
260
- test("paste on existing merge removes existing merge", () => {
261
- const model = new Model({
262
- sheets: [
263
- {
264
- colNumber: 5,
265
- rowNumber: 5,
266
- merges: ["B2:C4"],
267
- },
268
- ],
269
- });
270
- model.dispatch("COPY", { target: target("B2") });
271
- model.dispatch("PASTE", { target: target("A1") });
272
- expect(model.getters.isInMerge("B2")).toBe(true);
273
- expect(model.getters.isInMerge("B3")).toBe(true);
274
- expect(model.getters.isInMerge("B4")).toBe(false);
275
- expect(model.getters.isInMerge("C2")).toBe(false);
276
- expect(model.getters.isInMerge("C3")).toBe(false);
277
- expect(model.getters.isInMerge("C4")).toBe(false);
278
- });
279
-
280
- test("copy/paste a merge from one page to another", () => {
281
- const model = new Model({
282
- sheets: [
283
- {
284
- colNumber: 5,
285
- rowNumber: 5,
286
- merges: ["B2:C3"],
287
- },
288
- {
289
- colNumber: 5,
290
- rowNumber: 5,
291
- },
292
- ],
293
- });
294
- const sheet1 = model["workbook"].visibleSheets[0];
295
- const sheet2 = model["workbook"].visibleSheets[1];
296
- model.dispatch("COPY", { target: target("B2") });
297
- model.dispatch("ACTIVATE_SHEET", { from: sheet1, to: sheet2 });
298
- model.dispatch("PASTE", { target: target("A1") });
299
- expect(model.getters.isInMerge("A1")).toBe(true);
300
- expect(model.getters.isInMerge("A2")).toBe(true);
301
- expect(model.getters.isInMerge("B1")).toBe(true);
302
- expect(model.getters.isInMerge("B2")).toBe(true);
303
- });
304
-
305
- test("Pasting content that will destroy a merge will ask for confirmation", async () => {
306
- const askConfirmation = jest.fn();
307
- const model = new Model(
308
- {
309
- sheets: [
310
- {
311
- colNumber: 5,
312
- rowNumber: 5,
313
- merges: ["B2:C3"],
314
- },
315
- {
316
- colNumber: 5,
317
- rowNumber: 5,
318
- },
319
- ],
320
- },
321
- { askConfirmation }
322
- );
323
-
324
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
325
- const selection = model.getters.getSelection().zones;
326
- model.dispatch("COPY", { target: selection });
327
-
328
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
329
- model.dispatch("PASTE", { target: model.getters.getSelectedZones(), interactive: true });
330
- expect(askConfirmation).toHaveBeenCalled();
331
- });
332
-
333
- test("Pasting content that will destroy a merge will fail if not forced", async () => {
334
- const model = new Model({
335
- sheets: [
336
- {
337
- colNumber: 5,
338
- rowNumber: 5,
339
- merges: ["B2:C3"],
340
- },
341
- {
342
- colNumber: 5,
343
- rowNumber: 5,
344
- },
345
- ],
346
- });
347
-
348
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
349
- const selection = model.getters.getSelection().zones;
350
- model.dispatch("COPY", { target: selection });
351
- const result = model.dispatch("PASTE", { target: target("A1") });
352
- expect(result).toEqual({
353
- status: "CANCELLED",
354
- reason: CancelledReason.WillRemoveExistingMerge,
355
- });
356
- expect(model.getters.isInMerge("A1")).toBe(false);
357
- expect(model.getters.isInMerge("A2")).toBe(false);
358
- expect(model.getters.isInMerge("B1")).toBe(false);
359
- expect(model.getters.isInMerge("B2")).toBe(true);
360
- expect(model.getters.isInMerge("B3")).toBe(true);
361
- expect(model.getters.isInMerge("C2")).toBe(true);
362
- expect(model.getters.isInMerge("C3")).toBe(true);
363
- });
364
-
365
- test("Pasting content that will destroy a merge will be applied if forced", async () => {
366
- const model = new Model({
367
- sheets: [
368
- {
369
- colNumber: 5,
370
- rowNumber: 5,
371
- merges: ["B2:C3"],
372
- },
373
- {
374
- colNumber: 5,
375
- rowNumber: 5,
376
- },
377
- ],
378
- });
379
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
380
- const selection = model.getters.getSelection().zones;
381
- model.dispatch("COPY", { target: selection });
382
- model.dispatch("PASTE", { target: target("A1"), force: true });
383
- expect(model.getters.isInMerge("A1")).toBe(true);
384
- expect(model.getters.isInMerge("A2")).toBe(true);
385
- expect(model.getters.isInMerge("B1")).toBe(true);
386
- expect(model.getters.isInMerge("B2")).toBe(true);
387
- expect(model.getters.isInMerge("B3")).toBe(false);
388
- expect(model.getters.isInMerge("C2")).toBe(false);
389
- expect(model.getters.isInMerge("C3")).toBe(false);
390
- });
391
-
392
- test("cutting a cell with style remove the cell", () => {
393
- const model = new Model();
394
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
395
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
396
- model.dispatch("SET_FORMATTING", {
397
- sheet: "Sheet1",
398
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
399
- style: { bold: true },
400
- });
401
-
402
- model.dispatch("CUT", { target: target("B2") });
403
- model.dispatch("PASTE", { target: target("C2") });
404
-
405
- expect(model["workbook"].activeSheet.cells).toEqual({
406
- C2: { col: 2, style: 2, row: 1, content: "b2", type: "text", value: "b2", xc: "C2" },
407
- });
408
- });
409
-
410
- test("getClipboardContent export formatted string", () => {
411
- const model = new Model();
412
- model.dispatch("SET_VALUE", { xc: "B2", text: "abc" });
413
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
414
- model.dispatch("COPY", { target: target("B2") });
415
- expect(model.getters.getClipboardContent()).toBe("abc");
416
-
417
- model.dispatch("SET_VALUE", { xc: "B2", text: "= 1 + 2" });
418
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
419
- model.dispatch("COPY", { target: target("B2") });
420
- expect(model.getters.getClipboardContent()).toBe("3");
421
- });
422
-
423
- test("can copy a rectangular selection", () => {
424
- const model = new Model();
425
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
426
- model.dispatch("SET_VALUE", { xc: "B3", text: "b3" });
427
- model.dispatch("SET_VALUE", { xc: "C2", text: "c2" });
428
- model.dispatch("SET_VALUE", { xc: "C3", text: "c3" });
429
-
430
- model.dispatch("COPY", { target: target("B2:C3") });
431
-
432
- expect(getCell(model, "D1")).toBeNull();
433
- expect(getCell(model, "D2")).toBeNull();
434
- expect(getCell(model, "E1")).toBeNull();
435
- expect(getCell(model, "E2")).toBeNull();
436
-
437
- model.dispatch("PASTE", { target: target("D1:D1") });
438
-
439
- expect(getCell(model, "D1")!.content).toBe("b2");
440
- expect(getCell(model, "D2")!.content).toBe("b3");
441
- expect(getCell(model, "E1")!.content).toBe("c2");
442
- expect(getCell(model, "E2")!.content).toBe("c3");
443
- });
444
-
445
- test("empty clipboard: getClipboardContent returns a tab", () => {
446
- const model = new Model();
447
- expect(model.getters.getClipboardContent()).toBe("\t");
448
- });
449
-
450
- test("getClipboardContent exports multiple cells", () => {
451
- const model = new Model();
452
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
453
- model.dispatch("SET_VALUE", { xc: "B3", text: "b3" });
454
- model.dispatch("SET_VALUE", { xc: "C2", text: "c2" });
455
- model.dispatch("SET_VALUE", { xc: "C3", text: "c3" });
456
- model.dispatch("COPY", { target: target("B2:C3") });
457
- expect(model.getters.getClipboardContent()).toBe("b2\tc2\nb3\tc3");
458
- });
459
-
460
- test("can paste multiple cells from os clipboard", () => {
461
- const model = new Model();
462
- model.dispatch("PASTE_FROM_OS_CLIPBOARD", { text: "a\t1\nb\t2", target: target("C1") });
463
-
464
- expect(getCell(model, "C1")!.content).toBe("a");
465
- expect(getCell(model, "C2")!.content).toBe("b");
466
- expect(getCell(model, "D1")!.content).toBe("1");
467
- expect(getCell(model, "D2")!.content).toBe("2");
468
- });
469
-
470
- test("pasting numbers from windows clipboard => interpreted as number", () => {
471
- const model = new Model();
472
- model.dispatch("PASTE_FROM_OS_CLIPBOARD", { text: "1\r\n2\r\n3", target: target("C1") });
473
-
474
- expect(getCell(model, "C1")!.content).toBe("1");
475
- expect(getCell(model, "C1")!.type).toBe("number");
476
- expect(getCell(model, "C2")!.content).toBe("2");
477
- expect(getCell(model, "C2")!.type).toBe("number");
478
- expect(getCell(model, "C3")!.content).toBe("3");
479
- expect(getCell(model, "C3")!.type).toBe("number");
480
- });
481
-
482
- test("incompatible multiple selections: only last one is actually copied", () => {
483
- const model = new Model();
484
- model.dispatch("SET_VALUE", { xc: "A1", text: "a1" });
485
- model.dispatch("SET_VALUE", { xc: "A2", text: "a2" });
486
- model.dispatch("SET_VALUE", { xc: "C1", text: "c1" });
487
- model.dispatch("COPY", { target: target("A1:A2,C1") });
488
-
489
- expect(getClipboardVisibleZones(model).length).toBe(1);
490
-
491
- model.dispatch("SELECT_CELL", { col: 4, row: 0 });
492
- model.dispatch("PASTE", { target: target("E1") });
493
- expect(getCell(model, "E1")!.content).toBe("c1");
494
- expect(getCell(model, "E2")).toBeNull();
495
- });
496
-
497
- test("compatible multiple selections: each column is copied", () => {
498
- const model = new Model();
499
- model.dispatch("SET_VALUE", { xc: "A1", text: "a1" });
500
- model.dispatch("SET_VALUE", { xc: "A2", text: "a2" });
501
- model.dispatch("SET_VALUE", { xc: "C1", text: "c1" });
502
- model.dispatch("SET_VALUE", { xc: "C2", text: "c2" });
503
- model.dispatch("COPY", { target: target("A1:A2,C1:C2") });
504
-
505
- expect(getClipboardVisibleZones(model).length).toBe(2);
506
-
507
- model.dispatch("PASTE", { target: target("E1") });
508
- expect(getCell(model, "E1")!.content).toBe("a1");
509
- expect(getCell(model, "E2")!.content).toBe("a2");
510
- expect(getCell(model, "F1")!.content).toBe("c1");
511
- expect(getCell(model, "F2")!.content).toBe("c2");
512
- });
513
-
514
- test("pasting a value in a larger selection", () => {
515
- const model = new Model();
516
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
517
- model.dispatch("COPY", { target: target("A1:A1") });
518
-
519
- model.dispatch("PASTE", { target: target("C2:E3") });
520
- expect(getCell(model, "C2")!.content).toBe("1");
521
- expect(getCell(model, "C3")!.content).toBe("1");
522
- expect(getCell(model, "D2")!.content).toBe("1");
523
- expect(getCell(model, "D3")!.content).toBe("1");
524
- expect(getCell(model, "E2")!.content).toBe("1");
525
- expect(getCell(model, "E3")!.content).toBe("1");
526
- });
527
-
528
- test("selection is updated to contain exactly the new pasted zone", () => {
529
- const model = new Model();
530
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
531
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
532
- model.dispatch("COPY", { target: target("A1:A2") });
533
-
534
- // select C1:C3
535
- model.dispatch("SELECT_CELL", { col: 2, row: 0 });
536
- model.dispatch("ALTER_SELECTION", { cell: [2, 2] });
537
-
538
- expect(model.getters.getSelectedZones()[0]).toEqual({ top: 0, left: 2, bottom: 2, right: 2 });
539
- model.dispatch("PASTE", { target: target("C1:C3") });
540
- expect(model.getters.getSelectedZones()[0]).toEqual({ top: 0, left: 2, bottom: 1, right: 2 });
541
- expect(getCell(model, "C1")!.content).toBe("1");
542
- expect(getCell(model, "C2")!.content).toBe("2");
543
- expect(getCell(model, "C3")).toBeNull();
544
- });
545
-
546
- test("selection is not changed if pasting a single value into two zones", () => {
547
- const model = new Model();
548
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
549
- model.dispatch("COPY", { target: [zone("A1:A1")] });
550
-
551
- model.dispatch("SELECT_CELL", { col: 2, row: 0 });
552
- model.dispatch("START_SELECTION_EXPANSION");
553
- model.dispatch("SELECT_CELL", { col: 4, row: 0 });
554
-
555
- model.dispatch("PASTE", { target: target("C1,E1") });
556
- expect(model.getters.getSelectedZones()[0]).toEqual({ top: 0, left: 2, bottom: 0, right: 2 });
557
- expect(model.getters.getSelectedZones()[1]).toEqual({ top: 0, left: 4, bottom: 0, right: 4 });
558
- });
559
-
560
- test("pasting a value in multiple zones", () => {
561
- const model = new Model();
562
- model.dispatch("SET_VALUE", { xc: "A1", text: "33" });
563
- model.dispatch("COPY", { target: target("A1:A1") });
564
-
565
- model.dispatch("PASTE", { target: target("C1,E1") });
566
-
567
- expect(getCell(model, "C1")!.content).toBe("33");
568
- expect(getCell(model, "E1")!.content).toBe("33");
569
- });
570
-
571
- test("pasting is not allowed if multiple selection and more than one value", () => {
572
- const model = new Model();
573
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
574
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
575
- model.dispatch("COPY", { target: target("A1:A2") });
576
- const result = model.dispatch("PASTE", { target: target("C1,E1") });
577
-
578
- expect(result).toEqual({ status: "CANCELLED", reason: CancelledReason.WrongPasteSelection });
579
- });
580
-
581
- test("pasting with multiple selection and more than one value will warn user", async () => {
582
- const notifyUser = jest.fn();
583
- const model = new Model({}, { notifyUser });
584
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
585
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
586
- model.dispatch("COPY", { target: target("A1:A2") });
587
-
588
- model.dispatch("SELECT_CELL", { col: 2, row: 3 });
589
- model.dispatch("START_SELECTION_EXPANSION");
590
- model.dispatch("SELECT_CELL", { col: 4, row: 5 });
591
- model.dispatch("PASTE", { target: model.getters.getSelectedZones(), interactive: true });
592
- expect(notifyUser).toHaveBeenCalled();
593
- });
594
-
595
- test("can copy and paste a cell with STRING content", () => {
596
- const model = new Model();
597
- model.dispatch("SET_VALUE", { xc: "B2", text: '="test"' });
598
-
599
- expect(model["workbook"].activeSheet.cells["B2"].content).toEqual('="test"');
600
- expect(model["workbook"].activeSheet.cells["B2"].value).toEqual("test");
601
-
602
- model.dispatch("COPY", { target: target("B2") });
603
- model.dispatch("PASTE", { target: target("D2") });
604
- expect(model["workbook"].activeSheet.cells["B2"].content).toEqual('="test"');
605
- expect(model["workbook"].activeSheet.cells["B2"].value).toEqual("test");
606
- expect(model["workbook"].activeSheet.cells["D2"].content).toEqual('="test"');
607
- expect(model["workbook"].activeSheet.cells["D2"].value).toEqual("test");
608
- expect(getClipboardVisibleZones(model).length).toBe(0);
609
- });
610
-
611
- test("can undo a paste operation", () => {
612
- const model = new Model();
613
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
614
-
615
- model.dispatch("COPY", { target: target("B2") });
616
- model.dispatch("PASTE", { target: target("D2") });
617
- expect(getCell(model, "D2")).toBeDefined();
618
- model.dispatch("UNDO");
619
- expect(getCell(model, "D2")).toBeNull();
620
- });
621
-
622
- test("can paste-format a cell with style", () => {
623
- const model = new Model();
624
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
625
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
626
- model.dispatch("SET_FORMATTING", {
627
- sheet: "Sheet1",
628
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
629
- style: { bold: true },
630
- });
631
- expect(getCell(model, "B2")!.style).toBe(2);
632
-
633
- model.dispatch("COPY", { target: target("B2") });
634
- model.dispatch("PASTE", { target: target("C2"), onlyFormat: true });
635
- expect(getCell(model, "C2")!.content).toBe("");
636
- expect(getCell(model, "C2")!.style).toBe(2);
637
- });
638
-
639
- test("can copy and paste format", () => {
640
- const model = new Model();
641
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
642
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
643
- model.dispatch("SET_FORMATTING", {
644
- sheet: "Sheet1",
645
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
646
- style: { bold: true },
647
- });
648
- expect(getCell(model, "B2")!.style).toBe(2);
649
-
650
- model.dispatch("COPY", { target: target("B2") });
651
- model.dispatch("PASTE", { target: target("C2"), onlyFormat: true });
652
- expect(getCell(model, "C2")!.content).toBe("");
653
- expect(getCell(model, "C2")!.style).toBe(2);
654
- });
655
-
656
- test("paste format does not remove content", () => {
657
- const model = new Model();
658
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
659
- model.dispatch("SET_VALUE", { xc: "C2", text: "c2" });
660
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
661
- model.dispatch("SET_FORMATTING", {
662
- sheet: "Sheet1",
663
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
664
- style: { bold: true },
665
- });
666
- expect(getCell(model, "B2")!.style).toBe(2);
667
-
668
- model.dispatch("COPY", { target: target("B2") });
669
- model.dispatch("PASTE", { target: target("C2"), onlyFormat: true });
670
-
671
- expect(getCell(model, "C2")!.content).toBe("c2");
672
- expect(getCell(model, "C2")!.style).toBe(2);
673
- });
674
-
675
- test("can undo a paste format", () => {
676
- const model = new Model();
677
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
678
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
679
- model.dispatch("SET_FORMATTING", {
680
- sheet: "Sheet1",
681
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
682
- style: { bold: true },
683
- });
684
- model.dispatch("COPY", { target: [zone("B2:B2")] });
685
- model.dispatch("PASTE", { target: target("C2"), onlyFormat: true });
686
-
687
- expect(getCell(model, "C2")!.content).toBe("");
688
- expect(getCell(model, "C2")!.style).toBe(2);
689
-
690
- model.dispatch("UNDO");
691
- expect(getCell(model, "C2")).toBeNull();
692
- });
693
-
694
- test("can copy and paste value only", () => {
695
- const model = new Model();
696
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
697
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
698
- model.dispatch("COPY", { target: target("B2") });
699
- model.dispatch("PASTE", { target: target("C2"), onlyValue: true });
700
- expect(getCell(model, "C2")!.content).toBe("b2");
701
- });
702
-
703
- test("can copy a cell with a style and paste value only", () => {
704
- const model = new Model();
705
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
706
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
707
- model.dispatch("SET_FORMATTING", {
708
- sheet: "Sheet1",
709
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
710
- style: { bold: true },
711
- });
712
- expect(getCell(model, "B2")!.style).toBe(2);
713
-
714
- model.dispatch("COPY", { target: target("B2") });
715
- model.dispatch("PASTE", { target: target("C2"), onlyValue: true });
716
-
717
- expect(getCell(model, "C2")!.value).toBe("b2");
718
- expect(getCell(model, "C2")!.style).not.toBeDefined();
719
- });
720
-
721
- test("can copy a cell with a border and paste value only", () => {
722
- const model = new Model();
723
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
724
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
725
- model.dispatch("SET_FORMATTING", {
726
- sheet: model.getters.getActiveSheet(),
727
- target: model.getters.getSelectedZones(),
728
- border: "bottom",
729
- });
730
- expect(getCell(model, "B2")!.border).toBe(2);
731
-
732
- model.dispatch("COPY", { target: target("B2") });
733
- model.dispatch("PASTE", { target: target("C2"), onlyValue: true });
734
-
735
- expect(getCell(model, "C2")!.value).toBe("b2");
736
- expect(getCell(model, "C2")!.border).not.toBeDefined();
737
- });
738
-
739
- test("can copy a cell with a formatter and paste value only", () => {
740
- const model = new Model();
741
- model.dispatch("SET_VALUE", { xc: "B2", text: "0.451" });
742
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
743
- model.dispatch("SET_FORMATTER", {
744
- sheet: model.getters.getActiveSheet(),
745
- target: model.getters.getSelectedZones(),
746
- formatter: "0.00%",
747
- });
748
- expect(model.getters.getCellText(getCell(model, "B2")!)).toBe("45.10%");
749
-
750
- model.dispatch("COPY", { target: target("B2") });
751
- model.dispatch("PASTE", { target: target("C2"), onlyValue: true });
752
-
753
- expect(model.getters.getCellText(getCell(model, "C2")!)).toBe("0.451");
754
- });
755
-
756
- test("can copy a cell with a conditional format and paste value only", () => {
757
- const model = new Model({
758
- sheets: [
759
- {
760
- colNumber: 5,
761
- rowNumber: 5,
762
- },
763
- ],
764
- });
765
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
766
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
767
- model.dispatch("SET_VALUE", { xc: "C1", text: "1" });
768
- model.dispatch("SET_VALUE", { xc: "C2", text: "2" });
769
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
770
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
771
- sheet: model.getters.getActiveSheet(),
772
- });
773
- model.dispatch("COPY", { target: target("A1") });
774
- model.dispatch("PASTE", { target: target("C1"), onlyValue: true });
775
- model.dispatch("COPY", { target: target("A2") });
776
- model.dispatch("PASTE", { target: target("C2"), onlyValue: true });
777
- expect(model.getters.getConditionalStyle("A1")).toEqual({ fillColor: "#FF0000" });
778
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
779
- expect(model.getters.getConditionalStyle("C1")).toBeUndefined();
780
- expect(model.getters.getConditionalStyle("C2")).toBeUndefined();
781
- });
782
-
783
- test("paste value only does not remove style", () => {
784
- const model = new Model();
785
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
786
- model.dispatch("SET_VALUE", { xc: "C3", text: "c3" });
787
- model.dispatch("SELECT_CELL", { col: 2, row: 2 });
788
- model.dispatch("SET_FORMATTING", {
789
- sheet: "Sheet1",
790
- target: [{ left: 2, right: 2, top: 2, bottom: 2 }],
791
- style: { bold: true },
792
- });
793
- expect(getCell(model, "C3")!.style).toBe(2);
794
-
795
- model.dispatch("COPY", { target: target("B2") });
796
- model.dispatch("PASTE", { target: target("C3"), onlyValue: true });
797
-
798
- expect(getCell(model, "C3")!.content).toBe("b2");
799
- expect(getCell(model, "C3")!.style).toBe(2);
800
- });
801
-
802
- test("paste value only does not remove border", () => {
803
- const model = new Model();
804
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
805
- model.dispatch("SET_VALUE", { xc: "C3", text: "c3" });
806
- model.dispatch("SELECT_CELL", { col: 2, row: 2 });
807
- model.dispatch("SET_FORMATTING", {
808
- sheet: model.getters.getActiveSheet(),
809
- target: model.getters.getSelectedZones(),
810
- border: "bottom",
811
- });
812
- expect(getCell(model, "C3")!.border).toBe(2);
813
-
814
- model.dispatch("COPY", { target: target("B2") });
815
- model.dispatch("PASTE", { target: target("C3"), onlyValue: true });
816
-
817
- expect(getCell(model, "C3")!.content).toBe("b2");
818
- expect(getCell(model, "C3")!.border).toBe(2);
819
- });
820
-
821
- test("paste value only does not remove formating", () => {
822
- const model = new Model();
823
- model.dispatch("SET_VALUE", { xc: "B2", text: "42" });
824
- model.dispatch("SET_VALUE", { xc: "C3", text: "0.451" });
825
- model.dispatch("SELECT_CELL", { col: 2, row: 2 });
826
- model.dispatch("SET_FORMATTER", {
827
- sheet: model.getters.getActiveSheet(),
828
- target: model.getters.getSelectedZones(),
829
- formatter: "0.00%",
830
- });
831
- expect(model.getters.getCellText(getCell(model, "C3")!)).toBe("45.10%");
832
-
833
- model.dispatch("COPY", { target: target("B2") });
834
- model.dispatch("PASTE", { target: target("C3"), onlyValue: true });
835
-
836
- expect(model.getters.getCellText(getCell(model, "C3")!)).toBe("4200.00%");
837
- });
838
-
839
- test("can copy a formula and paste value only", () => {
840
- const model = new Model();
841
- model.dispatch("SET_VALUE", { xc: "A1", text: "=SUM(1+2)" });
842
- model.dispatch("SET_VALUE", { xc: "A2", text: "=EQ(42,42)" });
843
- model.dispatch("SET_VALUE", { xc: "A3", text: '=CONCAT("Ki","kou")' });
844
- model.dispatch("COPY", { target: [zone("A1:A3")] });
845
- model.dispatch("PASTE", { target: target("B1"), onlyValue: true });
846
- expect(getCell(model, "B1")!.content).toBe("3");
847
- expect(getCell(model, "B2")!.content).toBe("TRUE");
848
- expect(getCell(model, "B3")!.content).toBe("Kikou");
849
- });
850
-
851
- test("can undo a paste value only", () => {
852
- const model = new Model();
853
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
854
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
855
- model.dispatch("SET_FORMATTING", {
856
- sheet: "Sheet1",
857
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
858
- style: { bold: true },
859
- });
860
- model.dispatch("COPY", { target: [zone("B2:B2")] });
861
- model.dispatch("PASTE", { target: target("C2"), onlyValue: true });
862
-
863
- expect(getCell(model, "C2")!.content).toBe("b2");
864
- expect(getCell(model, "C2")!.style).not.toBeDefined();
865
-
866
- model.dispatch("UNDO");
867
- expect(getCell(model, "C2")).toBeNull();
868
- });
869
-
870
- test("can copy and paste a formula and update the refs", () => {
871
- const model = new Model();
872
- model.dispatch("SET_VALUE", { xc: "A1", text: "=SUM(C1:C2)" });
873
- model.dispatch("COPY", { target: target("A1") });
874
- model.dispatch("PASTE", { target: target("B2") });
875
- expect(getCell(model, "B2")!.content).toBe("=SUM(D2:D3)");
876
- });
877
-
878
- test.each([
879
- ["=SUM(C1:C2)", "=SUM(D2:D3)"],
880
- ["=$C1", "=$C2"],
881
- ["=SUM($C1:D$1)", "=SUM($C2:E$1)"],
882
- ])("can copy and paste formula with $refs", (value, expected) => {
883
- const model = new Model();
884
- model.dispatch("SET_VALUE", { xc: "A1", text: value });
885
- model.dispatch("COPY", { target: target("A1") });
886
- model.dispatch("PASTE", { target: target("B2") });
887
- expect(getCell(model, "B2")!.content).toBe(expected);
888
- });
889
-
890
- test("can copy format from empty cell to another cell to clear format", () => {
891
- const model = new Model();
892
-
893
- // write something in B2 and set its format
894
- model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
895
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
896
- model.dispatch("SET_FORMATTING", {
897
- sheet: "Sheet1",
898
- target: [{ left: 1, right: 1, top: 1, bottom: 1 }],
899
- style: { bold: true },
900
- });
901
- expect(getCell(model, "B2")!.style).toBe(2);
902
-
903
- // select A1 and copy format
904
- model.dispatch("COPY", { target: target("A1") });
905
-
906
- // select B2 and paste format
907
- model.dispatch("PASTE", { target: target("B2"), onlyFormat: true });
908
-
909
- expect(getCell(model, "B2")!.content).toBe("b2");
910
- expect(getCell(model, "B2")!.style).not.toBeDefined();
911
- });
912
-
913
- test("can copy and paste a conditional formatted cell", () => {
914
- const model = new Model({
915
- sheets: [
916
- {
917
- colNumber: 5,
918
- rowNumber: 5,
919
- },
920
- ],
921
- });
922
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
923
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
924
- model.dispatch("SET_VALUE", { xc: "C1", text: "1" });
925
- model.dispatch("SET_VALUE", { xc: "C2", text: "2" });
926
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
927
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
928
- sheet: model.getters.getActiveSheet(),
929
- });
930
- model.dispatch("COPY", { target: target("A1") });
931
- model.dispatch("PASTE", { target: target("C1") });
932
- model.dispatch("COPY", { target: target("A2") });
933
- model.dispatch("PASTE", { target: target("C2") });
934
- expect(model.getters.getConditionalStyle("A1")).toEqual({ fillColor: "#FF0000" });
935
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
936
- expect(model.getters.getConditionalStyle("C1")).toEqual({ fillColor: "#FF0000" });
937
- expect(model.getters.getConditionalStyle("C2")).toBeUndefined();
938
- });
939
- test("can cut and paste a conditional formatted cell", () => {
940
- const model = new Model({
941
- sheets: [
942
- {
943
- colNumber: 5,
944
- rowNumber: 5,
945
- },
946
- ],
947
- });
948
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
949
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
950
- model.dispatch("SET_VALUE", { xc: "C1", text: "1" });
951
- model.dispatch("SET_VALUE", { xc: "C2", text: "2" });
952
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
953
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
954
- sheet: model.getters.getActiveSheet(),
955
- });
956
- model.dispatch("CUT", { target: target("A1") });
957
- model.dispatch("PASTE", { target: target("C1") });
958
- model.dispatch("CUT", { target: target("A2") });
959
- model.dispatch("PASTE", { target: target("C2") });
960
- expect(model.getters.getConditionalStyle("A1")).toBeUndefined();
961
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
962
- expect(model.getters.getConditionalStyle("C1")).toEqual({ fillColor: "#FF0000" });
963
- expect(model.getters.getConditionalStyle("C2")).toBeUndefined();
964
- });
965
-
966
- test("can copy and paste a conditional formatted zone", () => {
967
- const model = new Model({
968
- sheets: [
969
- {
970
- colNumber: 5,
971
- rowNumber: 5,
972
- },
973
- ],
974
- });
975
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
976
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
977
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
978
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
979
- sheet: model.getters.getActiveSheet(),
980
- });
981
- model.dispatch("COPY", { target: target("A1:A2") });
982
- model.dispatch("PASTE", { target: target("B1") });
983
- model.dispatch("PASTE", { target: target("C1") });
984
- expect(model.getters.getConditionalStyle("A1")).toEqual({ fillColor: "#FF0000" });
985
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
986
- expect(model.getters.getConditionalStyle("B1")).toEqual({ fillColor: "#FF0000" });
987
- expect(model.getters.getConditionalStyle("B2")).toBeUndefined();
988
- expect(model.getters.getConditionalStyle("C1")).toEqual({ fillColor: "#FF0000" });
989
- expect(model.getters.getConditionalStyle("C2")).toBeUndefined();
990
- model.dispatch("SET_VALUE", { xc: "C1", text: "2" });
991
- model.dispatch("SET_VALUE", { xc: "C2", text: "1" });
992
- expect(model.getters.getConditionalStyle("C1")).toBeUndefined();
993
- expect(model.getters.getConditionalStyle("C2")).toEqual({ fillColor: "#FF0000" });
994
- });
995
-
996
- test("can cut and paste a conditional formatted zone", () => {
997
- const model = new Model({
998
- sheets: [
999
- {
1000
- colNumber: 5,
1001
- rowNumber: 5,
1002
- },
1003
- ],
1004
- });
1005
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
1006
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
1007
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
1008
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
1009
- sheet: model.getters.getActiveSheet(),
1010
- });
1011
- model.dispatch("CUT", { target: target("A1:A2") });
1012
- model.dispatch("PASTE", { target: target("B1") });
1013
- expect(model.getters.getConditionalStyle("A1")).toBeUndefined();
1014
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
1015
- expect(model.getters.getConditionalStyle("B1")).toEqual({ fillColor: "#FF0000" });
1016
- expect(model.getters.getConditionalStyle("B2")).toBeUndefined();
1017
- model.dispatch("SET_VALUE", { xc: "B1", text: "2" });
1018
- model.dispatch("SET_VALUE", { xc: "B2", text: "1" });
1019
- expect(model.getters.getConditionalStyle("B1")).toBeUndefined();
1020
- expect(model.getters.getConditionalStyle("B2")).toEqual({ fillColor: "#FF0000" });
1021
- });
1022
-
1023
- test("can copy and paste a conditional formatted cell to another page", () => {
1024
- const model = new Model({
1025
- sheets: [
1026
- {
1027
- colNumber: 5,
1028
- rowNumber: 5,
1029
- },
1030
- {
1031
- colNumber: 5,
1032
- rowNumber: 5,
1033
- },
1034
- ],
1035
- });
1036
- const sheet1 = model["workbook"].visibleSheets[0];
1037
- const sheet2 = model["workbook"].visibleSheets[1];
1038
-
1039
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
1040
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
1041
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
1042
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
1043
- sheet: model.getters.getActiveSheet(),
1044
- });
1045
- model.dispatch("COPY", { target: target("A1:A2") });
1046
- model.dispatch("ACTIVATE_SHEET", { from: sheet1, to: sheet2 });
1047
- model.dispatch("PASTE", { target: target("A1") });
1048
- expect(model.getters.getConditionalStyle("A1")).toEqual({ fillColor: "#FF0000" });
1049
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
1050
- model.dispatch("SET_VALUE", { xc: "A1", text: "2" });
1051
- model.dispatch("SET_VALUE", { xc: "A2", text: "1" });
1052
- expect(model.getters.getConditionalStyle("A1")).toBeUndefined();
1053
- expect(model.getters.getConditionalStyle("A2")).toEqual({ fillColor: "#FF0000" });
1054
- });
1055
-
1056
- test("can cut and paste a conditional formatted cell to another page", () => {
1057
- const model = new Model({
1058
- sheets: [
1059
- {
1060
- colNumber: 5,
1061
- rowNumber: 5,
1062
- },
1063
- {
1064
- colNumber: 5,
1065
- rowNumber: 5,
1066
- },
1067
- ],
1068
- });
1069
- const sheet1 = model["workbook"].visibleSheets[0];
1070
- const sheet2 = model["workbook"].visibleSheets[1];
1071
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
1072
- model.dispatch("SET_VALUE", { xc: "A2", text: "2" });
1073
- model.dispatch("ADD_CONDITIONAL_FORMAT", {
1074
- cf: createEqualCF(["A1", "A2"], "1", { fillColor: "#FF0000" }, "1"),
1075
- sheet: model.getters.getActiveSheet(),
1076
- });
1077
- model.dispatch("CUT", { target: target("A1:A2") });
1078
- model.dispatch("ACTIVATE_SHEET", { from: sheet1, to: sheet2 });
1079
- model.dispatch("PASTE", { target: target("A1") });
1080
- expect(model.getters.getConditionalStyle("A1")).toEqual({ fillColor: "#FF0000" });
1081
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
1082
- model.dispatch("SET_VALUE", { xc: "A1", text: "2" });
1083
- model.dispatch("SET_VALUE", { xc: "A2", text: "1" });
1084
- expect(model.getters.getConditionalStyle("A1")).toBeUndefined();
1085
- expect(model.getters.getConditionalStyle("A2")).toEqual({ fillColor: "#FF0000" });
1086
- model.dispatch("ACTIVATE_SHEET", { from: sheet2, to: sheet1 });
1087
- expect(model.getters.getConditionalStyle("A1")).toBeUndefined();
1088
- expect(model.getters.getConditionalStyle("A2")).toBeUndefined();
1089
- });
1090
-
1091
- test("can copy and paste a cell which contains a cross-sheet reference", () => {
1092
- const model = new Model();
1093
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet2" });
1094
- model.dispatch("SET_VALUE", { xc: "B2", text: "=Sheet2!B2" });
1095
-
1096
- model.dispatch("COPY", { target: target("B2") });
1097
- model.dispatch("PASTE", { target: target("B3") });
1098
- expect(model.getters.getCell(1, 2)!.content).toBe("=Sheet2!B3");
1099
- });
1100
-
1101
- test("can copy and paste a cell which contains a cross-sheet reference with a space in the name", () => {
1102
- const model = new Model();
1103
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet 2" });
1104
- model.dispatch("SET_VALUE", { xc: "B2", text: "='Sheet 2'!B2" });
1105
-
1106
- model.dispatch("COPY", { target: target("B2") });
1107
- model.dispatch("PASTE", { target: target("B3") });
1108
- expect(model.getters.getCell(1, 2)!.content).toBe("='Sheet 2'!B3");
1109
- });
1110
-
1111
- test("can copy and paste a cell which contains a cross-sheet reference in a smaller sheet", () => {
1112
- const model = new Model();
1113
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet2", rows: 2, cols: 2 });
1114
- model.dispatch("SET_VALUE", { xc: "A1", text: "=Sheet2!A1:A2" });
1115
-
1116
- model.dispatch("COPY", { target: target("A1") });
1117
- model.dispatch("PASTE", { target: target("A2") });
1118
- expect(model.getters.getCell(0, 1)!.content).toBe("=Sheet2!A2:A3");
1119
- });
1120
-
1121
- test("can copy and paste a cell which contains a cross-sheet reference to a range", () => {
1122
- const model = new Model();
1123
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet2" });
1124
- model.dispatch("SET_VALUE", { xc: "A1", text: "=SUM(Sheet2!A2:A5)" });
1125
-
1126
- model.dispatch("COPY", { target: target("A1") });
1127
- model.dispatch("PASTE", { target: target("B1") });
1128
- expect(model.getters.getCell(1, 0)!.content).toBe("=SUM(Sheet2!B2:B5)");
1129
- });
1130
- });
1131
-
1132
- describe("clipboard: pasting outside of sheet", () => {
1133
- test("can copy and paste a full column", () => {
1134
- const model = new Model();
1135
- model.dispatch("SET_VALUE", { xc: "A1", text: "txt" });
1136
-
1137
- const currentRowNumber = model["workbook"].activeSheet.rows.length;
1138
-
1139
- model.dispatch("COPY", { target: [model.getters.getColsZone(0, 0)] });
1140
- model.dispatch("PASTE", { target: target("B2") });
1141
- expect(model["workbook"].activeSheet.rows.length).toBe(currentRowNumber + 1);
1142
- expect(getCell(model, "B2")!.content).toBe("txt");
1143
- });
1144
-
1145
- test("can copy and paste a full row", () => {
1146
- const model = new Model();
1147
- model.dispatch("SET_VALUE", { xc: "A1", text: "txt" });
1148
-
1149
- const currentColNumber = model["workbook"].activeSheet.cols.length;
1150
-
1151
- model.dispatch("COPY", { target: [model.getters.getRowsZone(0, 0)] });
1152
- model.dispatch("PASTE", { target: target("B2") });
1153
- expect(model["workbook"].activeSheet.cols.length).toBe(currentColNumber + 1);
1154
- expect(getCell(model, "B2")!.content).toBe("txt");
1155
- });
1156
-
1157
- test("can paste multiple cells from os to outside of sheet", () => {
1158
- const model = new Model();
1159
-
1160
- model.dispatch("CREATE_SHEET", { activate: true, id: "2", name: "sheet2", rows: 2, cols: 2 });
1161
- model.dispatch("PASTE_FROM_OS_CLIPBOARD", {
1162
- text: "A\nque\tcoucou\nBOB",
1163
- target: target("B2"),
1164
- });
1165
- expect(getCell(model, "B2")!.content).toBe("A");
1166
- expect(getCell(model, "B3")!.content).toBe("que");
1167
- expect(getCell(model, "C3")!.content).toBe("coucou");
1168
- expect(getCell(model, "B4")!.content).toBe("BOB");
1169
-
1170
- model.dispatch("CREATE_SHEET", { activate: true, id: "3", name: "sheet3", rows: 2, cols: 2 });
1171
- model.dispatch("PASTE_FROM_OS_CLIPBOARD", {
1172
- text: "A\nque\tcoucou\tPatrick",
1173
- target: target("B2"),
1174
- });
1175
- expect(getCell(model, "B2")!.content).toBe("A");
1176
- expect(getCell(model, "B3")!.content).toBe("que");
1177
- expect(getCell(model, "C3")!.content).toBe("coucou");
1178
- expect(getCell(model, "D3")!.content).toBe("Patrick");
1179
- });
1180
- });