@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,400 +0,0 @@
1
- import { colors, toZone } from "../../src/helpers/index";
2
- import { Model } from "../../src/model";
3
- import { HighlightPlugin } from "../../src/plugins/highlight";
4
- import { triggerMouseEvent } from "../dom_helper";
5
- import { getActiveXc, getCell, GridParent, makeTestFixture, nextTick } from "../helpers";
6
- import { ContentEditableHelper } from "./__mocks__/content_editable_helper";
7
- jest.mock("../../src/components/composer/content_editable_helper", () =>
8
- require("./__mocks__/content_editable_helper")
9
- );
10
-
11
- let model: Model;
12
- let composerEl: Element;
13
- let canvasEl: Element;
14
- let fixture: HTMLElement;
15
- let parent: GridParent;
16
-
17
- function getHighlights(model: Model): any[] {
18
- const highlightPlugin = (model as any).handlers.find((h) => h instanceof HighlightPlugin);
19
- return highlightPlugin.highlights;
20
- }
21
-
22
- async function typeInComposer(text: string, fromScratch: boolean = true) {
23
- if (fromScratch) {
24
- await startComposition();
25
- }
26
- composerEl.append(text);
27
- composerEl.dispatchEvent(new Event("input"));
28
- composerEl.dispatchEvent(new Event("keyup", { bubbles: true }));
29
- await nextTick();
30
- }
31
-
32
- async function startComposition(key: string = "Enter") {
33
- canvasEl.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true }));
34
- await nextTick();
35
- composerEl = fixture.querySelector("div.o-composer")!;
36
- }
37
-
38
- async function keydown(key: string, options: any = {}) {
39
- composerEl.dispatchEvent(
40
- new KeyboardEvent("keydown", Object.assign({ key, bubbles: true }, options))
41
- );
42
- await nextTick();
43
- }
44
-
45
- beforeEach(async () => {
46
- fixture = makeTestFixture();
47
- model = new Model();
48
- parent = new GridParent(model);
49
- await parent.mount(fixture);
50
- canvasEl = parent.grid.el;
51
- });
52
-
53
- afterEach(() => {
54
- fixture.remove();
55
- });
56
-
57
- describe("ranges and highlights", () => {
58
- test("=+Click Cell, the cell ref should be colored", async () => {
59
- await typeInComposer("=");
60
- triggerMouseEvent("canvas", "mousedown", 300, 200);
61
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
62
- await nextTick();
63
- expect(model.getters.getCurrentContent()).toBe("=C8");
64
- expect(
65
- (parent.grid.comp.composer.comp.contentHelper as ContentEditableHelper).colors["C8"]
66
- ).toBe(colors[0]);
67
- });
68
-
69
- test("=+Click range, the range ref should be colored", async () => {
70
- await typeInComposer("=");
71
- triggerMouseEvent("canvas", "mousedown", 300, 200);
72
- triggerMouseEvent("canvas", "mousemove", 200, 200);
73
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 200, clientY: 200 }));
74
- await nextTick();
75
- expect(model.getters.getCurrentContent()).toBe("=B8:C8");
76
- expect(
77
- (parent.grid.comp.composer.comp.contentHelper as ContentEditableHelper).colors["B8:C8"]
78
- ).toBe(colors[0]);
79
- });
80
-
81
- test("=Key DOWN in A1, should select and highlight A2", async () => {
82
- await typeInComposer("=");
83
- await keydown("ArrowDown");
84
- expect(model.getters.getCurrentContent()).toBe("=A2");
85
- });
86
-
87
- test("=Key DOWN+DOWN in A1, should select and highlight A3", async () => {
88
- await typeInComposer("=");
89
- await keydown("ArrowDown");
90
- await keydown("ArrowDown");
91
- expect(model.getters.getCurrentContent()).toBe("=A3");
92
- });
93
-
94
- test("=Key RIGHT in A1, should select and highlight B1", async () => {
95
- await typeInComposer("=");
96
- await keydown("ArrowRight");
97
- expect(model.getters.getCurrentContent()).toBe("=B1");
98
- });
99
-
100
- test("=Key UP in B2, should select and highlight B1", async () => {
101
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
102
- await typeInComposer("=");
103
- await keydown("ArrowUp");
104
- expect(model.getters.getCurrentContent()).toBe("=B1");
105
- });
106
-
107
- test("=Key LEFT in B2, should select and highlight A2", async () => {
108
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
109
- await typeInComposer("=");
110
- await keydown("ArrowLeft");
111
- expect(model.getters.getCurrentContent()).toBe("=A2");
112
- });
113
-
114
- test("=Key DOWN and UP in B2, should select and highlight B2", async () => {
115
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
116
- await typeInComposer("=");
117
- await keydown("ArrowDown");
118
- await keydown("ArrowUp");
119
- expect(model.getters.getCurrentContent()).toBe("=B2");
120
- });
121
-
122
- test("=key UP 2 times and key DOWN in B2, should select and highlight B2", async () => {
123
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
124
- await typeInComposer("=");
125
- await keydown("ArrowUp");
126
- await keydown("ArrowUp");
127
- await keydown("ArrowDown");
128
- expect(model.getters.getCurrentContent()).toBe("=B2");
129
- });
130
-
131
- test("While selecting a ref, Shift+UP/DOWN/LEFT/RIGHT extend the range selection and updates the composer", async () => {
132
- await typeInComposer("=");
133
- await keydown("ArrowDown");
134
- expect(model.getters.getCurrentContent()).toBe("=A2");
135
- await keydown("ArrowDown", { shiftKey: true });
136
- expect(model.getters.getCurrentContent()).toBe("=A2:A3");
137
- await keydown("ArrowRight", { shiftKey: true });
138
- expect(model.getters.getCurrentContent()).toBe("=A2:B3");
139
- await keydown("ArrowUp", { shiftKey: true });
140
- expect(model.getters.getCurrentContent()).toBe("=A2:B2");
141
- await keydown("ArrowLeft", { shiftKey: true });
142
- expect(model.getters.getCurrentContent()).toBe("=A2");
143
- });
144
-
145
- test("Create a ref with merges with keyboard -> the merge should be treated as one cell", async () => {
146
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
147
- model.dispatch("ALTER_SELECTION", { delta: [1, 1] });
148
- const sheet1 = model["workbook"].visibleSheets[0];
149
- model.dispatch("ADD_MERGE", { sheet: sheet1, zone: toZone("B2:C3") });
150
- model.dispatch("SELECT_CELL", { col: 2, row: 0 });
151
- await typeInComposer("=");
152
- await keydown("ArrowDown");
153
- expect(model.getters.getCurrentContent()).toBe("=B2");
154
- expect(getHighlights(model)).toHaveLength(1);
155
- expect(getHighlights(model)[0].zone).toMatchObject({
156
- top: 1,
157
- bottom: 2,
158
- left: 1,
159
- right: 2,
160
- });
161
- await keydown("ArrowDown");
162
- expect(model.getters.getCurrentContent()).toBe("=C4");
163
- });
164
- });
165
-
166
- describe("composer", () => {
167
- test("starting the edition with enter, the composer should have the focus", async () => {
168
- await startComposition();
169
- expect(model.getters.getEditionMode()).toBe("editing");
170
- expect(model.getters.getPosition()).toEqual([0, 0]);
171
- expect(document.activeElement).toBe(fixture.querySelector("div.o-composer")!);
172
- });
173
-
174
- test("starting the edition with a key stroke =, the composer should have the focus after the key input", async () => {
175
- await startComposition("=");
176
- expect(composerEl.textContent).toBe("=");
177
- });
178
-
179
- test("starting the edition with a key stroke B, the composer should have the focus after the key input", async () => {
180
- await startComposition("b");
181
- expect(composerEl.textContent).toBe("b");
182
- });
183
-
184
- test("type '=', backspace and select a cell should not add it", async () => {
185
- await typeInComposer("=");
186
- model.dispatch("SET_CURRENT_CONTENT", { content: "" });
187
- const cehMock = parent.grid.comp.composer.comp.contentHelper as ContentEditableHelper;
188
- cehMock.removeAll();
189
- composerEl.dispatchEvent(new Event("keyup"));
190
- triggerMouseEvent("canvas", "mousedown", 300, 200);
191
- await nextTick();
192
- expect(getActiveXc(model)).toBe("C8");
193
- expect(fixture.getElementsByClassName("o-composer")).toHaveLength(0);
194
- });
195
-
196
- test("type '=', select twice a cell", async () => {
197
- await typeInComposer("=");
198
- expect(model.getters.getEditionMode()).toBe("selecting");
199
- triggerMouseEvent("canvas", "mousedown", 300, 200);
200
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
201
- await nextTick();
202
- expect(model.getters.getEditionMode()).toBe("selecting");
203
- triggerMouseEvent("canvas", "mousedown", 300, 200);
204
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
205
- await nextTick();
206
- expect(composerEl.textContent).toBe("=C8");
207
- });
208
-
209
- test("type '=', select a cell, press enter", async () => {
210
- await typeInComposer("=");
211
- triggerMouseEvent("canvas", "mousedown", 300, 200);
212
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
213
- await nextTick();
214
- expect(composerEl.textContent).toBe("=C8");
215
- expect(model.getters.getEditionMode()).toBe("selecting");
216
- await keydown("Enter");
217
- expect(model.getters.getEditionMode()).toBe("inactive");
218
- expect(getCell(model, "A1")!.content).toBe("=C8");
219
- });
220
-
221
- test("clicking on the composer while typing text (not formula) does not duplicates text", async () => {
222
- await typeInComposer("a");
223
- composerEl.dispatchEvent(new MouseEvent("click"));
224
- await nextTick();
225
- expect(composerEl.textContent).toBe("a");
226
- });
227
-
228
- test("typing incorrect formula then enter exits the edit mode and moves to the next cell down", async () => {
229
- await startComposition();
230
- await typeInComposer("=qsdf");
231
- await keydown("Enter");
232
- expect(getCell(model, "A1")!.content).toBe("=qsdf");
233
- expect(getCell(model, "A1")!.value).toBe("#BAD_EXPR");
234
- });
235
-
236
- test("typing text then enter exits the edit mode and moves to the next cell down", async () => {
237
- await startComposition();
238
- await typeInComposer("qsdf");
239
- await keydown("Enter");
240
- expect(getCell(model, "A1")!.content).toBe("qsdf");
241
- expect(getCell(model, "A1")!.value).toBe("qsdf");
242
- });
243
-
244
- test("typing CTRL+C does not type C in the cell", async () => {
245
- canvasEl.dispatchEvent(
246
- new KeyboardEvent("keydown", { key: "c", ctrlKey: true, bubbles: true })
247
- );
248
- await nextTick();
249
- expect(model.getters.getCurrentContent()).toBe("");
250
- });
251
- test("keyup event triggered after edition end", async () => {
252
- canvasEl.dispatchEvent(
253
- new KeyboardEvent("keydown", Object.assign({ key: "d", bubbles: true }))
254
- );
255
- await nextTick();
256
- const composerEl = fixture.querySelector("div.o-composer")!;
257
- expect(model.getters.getEditionMode()).toBe("editing");
258
- // Enter is pressed really fast while another character is pressed such that
259
- // the character keyup event happens after the Enter
260
- composerEl.dispatchEvent(
261
- new KeyboardEvent("keydown", Object.assign({ key: "Enter", bubbles: true }))
262
- );
263
- composerEl.dispatchEvent(
264
- new KeyboardEvent("keyup", Object.assign({ key: "Enter", bubbles: true }))
265
- );
266
- composerEl.dispatchEvent(
267
- new KeyboardEvent("keyup", Object.assign({ key: "d", bubbles: true }))
268
- );
269
- await nextTick();
270
- expect(model.getters.getEditionMode()).toBe("inactive");
271
- });
272
-
273
- test("typing a formula with a space should put the composer in 'selecting' mode", async () => {
274
- await startComposition();
275
- await typeInComposer("= ");
276
- expect(model.getters.getEditionMode()).toBe("selecting");
277
- });
278
-
279
- test("type '=', select a cell in another sheet", async () => {
280
- await typeInComposer("=");
281
- expect(model.getters.getEditionMode()).toBe("selecting");
282
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet2", activate: true });
283
- triggerMouseEvent("canvas", "mousedown", 300, 200);
284
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
285
- await nextTick();
286
- expect(model.getters.getEditionMode()).toBe("selecting");
287
- triggerMouseEvent("canvas", "mousedown", 300, 200);
288
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
289
- await nextTick();
290
- expect(composerEl.textContent).toBe("=Sheet2!C8");
291
- });
292
-
293
- test("type =, select a cell in another sheet with space in name", async () => {
294
- await typeInComposer("=");
295
- expect(model.getters.getEditionMode()).toBe("selecting");
296
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet 2", activate: true });
297
- triggerMouseEvent("canvas", "mousedown", 300, 200);
298
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
299
- await nextTick();
300
- expect(model.getters.getEditionMode()).toBe("selecting");
301
- triggerMouseEvent("canvas", "mousedown", 300, 200);
302
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
303
- await nextTick();
304
- expect(composerEl.textContent).toBe("='Sheet 2'!C8");
305
- });
306
-
307
- test("type '=', select a cell in another sheet, select a cell in the active sheet", async () => {
308
- await typeInComposer("=");
309
- const sheet = model.getters.getActiveSheet();
310
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet2", activate: true });
311
- triggerMouseEvent("canvas", "mousedown", 300, 200);
312
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
313
- await nextTick();
314
- triggerMouseEvent("canvas", "mousedown", 300, 200);
315
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
316
- await nextTick();
317
- model.dispatch("ACTIVATE_SHEET", { from: "42", to: sheet });
318
- triggerMouseEvent("canvas", "mousedown", 300, 200);
319
- window.dispatchEvent(new MouseEvent("mouseup", { clientX: 300, clientY: 200 }));
320
- await nextTick();
321
- expect(composerEl.textContent).toBe("=C8");
322
- });
323
- });
324
-
325
- describe("composer highlights color", () => {
326
- test("colors start with first color", async () => {
327
- model.dispatch("SET_VALUE", { xc: "A1", text: "=a1+a2" });
328
- await startComposition();
329
- expect(getHighlights(model).length).toBe(2);
330
- expect(getHighlights(model)[0].color).toBe(colors[0]);
331
- expect(getHighlights(model)[1].color).toBe(colors[1]);
332
- });
333
-
334
- test("colors always start with first color", async () => {
335
- model.dispatch("SET_VALUE", { xc: "A1", text: "=b1+b2" });
336
- model.dispatch("SET_VALUE", { xc: "A2", text: "=b1+b3" });
337
- await startComposition();
338
- expect(getHighlights(model).length).toBe(2);
339
- expect(getHighlights(model)[0].color).toBe(colors[0]);
340
- expect(getHighlights(model)[1].color).toBe(colors[1]);
341
-
342
- document.activeElement!.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
343
- await nextTick();
344
- canvasEl.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
345
- await nextTick();
346
- expect(getHighlights(model).length).toBe(2);
347
- expect(getHighlights(model)[0].color).toBe(colors[0]);
348
- expect(getHighlights(model)[1].color).toBe(colors[1]);
349
- });
350
-
351
- test("highlight do not duplicate", async () => {
352
- model.dispatch("SET_VALUE", { xc: "A1", text: "=a1+a1" });
353
- await startComposition();
354
- expect(getHighlights(model).length).toBe(1);
355
- expect(getHighlights(model)[0].color).toBe(colors[0]);
356
- });
357
-
358
- test("highlight range", async () => {
359
- model.dispatch("SET_VALUE", { xc: "A1", text: "=sum(a1:a10)" });
360
- await startComposition();
361
- expect(getHighlights(model).length).toBe(1);
362
- expect(getHighlights(model)[0].color).toBe(colors[0]);
363
- expect(composerEl.textContent).toBe("=sum(a1:a10)");
364
- });
365
-
366
- test("highlight 'reverse' ranges", async () => {
367
- model.dispatch("SET_VALUE", { xc: "A1", text: "=sum(B3:a1)" });
368
- await startComposition();
369
- expect(getHighlights(model)[0].zone).toEqual({ left: 0, right: 1, top: 0, bottom: 2 });
370
- });
371
-
372
- test.each(["=A0", "=ZZ1", "=A101"])("Do not highlight invalid ref", async (ref) => {
373
- model.dispatch("SET_VALUE", { xc: "A1", text: ref });
374
- await startComposition();
375
- expect(getHighlights(model).length).toBe(0);
376
- expect(composerEl.textContent).toBe(ref);
377
- });
378
-
379
- test("highlight cross-sheet ranges", async () => {
380
- model.dispatch("CREATE_SHEET", { id: "42", name: "Sheet2" });
381
- model.dispatch("SET_VALUE", { xc: "A1", text: "=B1+Sheet2!A1" });
382
- await startComposition();
383
- const highlights = getHighlights(model);
384
- expect(highlights).toHaveLength(2);
385
- expect(highlights[0].sheet).toBe(model.getters.getActiveSheet());
386
- expect(highlights[0].zone).toEqual({ left: 1, right: 1, top: 0, bottom: 0 });
387
- expect(highlights[1].sheet).toBe("42");
388
- expect(highlights[1].zone).toEqual({ left: 0, right: 0, top: 0, bottom: 0 });
389
- });
390
-
391
- test("composer is resized when input content is larger than composer", async () => {
392
- await typeInComposer("Hello");
393
- const composerEl = fixture.querySelector("div.o-composer")! as HTMLElement;
394
- const styleSpy = jest.spyOn(composerEl.style, "width", "set");
395
- jest.spyOn(composerEl, "clientWidth", "get").mockImplementation(() => 100);
396
- jest.spyOn(composerEl, "scrollWidth", "get").mockImplementation(() => 120);
397
- await typeInComposer("world", false);
398
- expect(styleSpy).toHaveBeenCalledWith("140px"); // scrollWidth + padding 20px
399
- });
400
- });