@odoo/o-spreadsheet 14.0.0 → 14.0.1

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 (198) hide show
  1. package/.eslintrc.json +20 -0
  2. package/.husky/post-checkout +9 -0
  3. package/.husky/pre-commit +39 -0
  4. package/.prettierignore +1 -0
  5. package/astToFormula.patch +0 -0
  6. package/demo/data.js +255 -0
  7. package/demo/index.html +9 -0
  8. package/demo/libs/Chart.bundle.js +20755 -0
  9. package/demo/main.js +101 -0
  10. package/doc/readme.md +46 -0
  11. package/package.json +3 -17
  12. package/rollup.config.js +23 -0
  13. package/src/base_plugin.ts +102 -0
  14. package/src/components/autofill.ts +146 -0
  15. package/src/components/bottom_bar.ts +199 -0
  16. package/src/components/color_picker.ts +150 -0
  17. package/src/components/composer/autocomplete_dropdown.ts +135 -0
  18. package/src/components/composer/composer.ts +487 -0
  19. package/src/components/composer/content_editable_helper.ts +146 -0
  20. package/src/components/figures/chart.ts +70 -0
  21. package/src/components/figures/container.ts +268 -0
  22. package/src/components/figures/text_figure.ts +36 -0
  23. package/src/components/grid.ts +635 -0
  24. package/src/components/helpers/dom_helpers.ts +7 -0
  25. package/src/components/helpers/drag_and_drop.ts +17 -0
  26. package/src/components/icons.ts +36 -0
  27. package/src/components/index.ts +1 -0
  28. package/src/components/menu.ts +288 -0
  29. package/src/components/overlay.ts +457 -0
  30. package/src/components/scrollbar.ts +22 -0
  31. package/src/components/selection_input.ts +168 -0
  32. package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
  33. package/src/components/side_panel/chart_panel.ts +104 -0
  34. package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
  35. package/src/components/side_panel/conditional_formatting.ts +396 -0
  36. package/src/components/side_panel/side_panel.ts +127 -0
  37. package/src/components/side_panel/translations_terms.ts +45 -0
  38. package/src/components/spreadsheet.ts +198 -0
  39. package/src/components/top_bar.ts +535 -0
  40. package/src/constants.ts +26 -0
  41. package/src/data.ts +149 -0
  42. package/src/fonts.ts +41 -0
  43. package/src/formulas/compiler.ts +258 -0
  44. package/src/formulas/composer_tokenizer.ts +70 -0
  45. package/src/formulas/index.ts +15 -0
  46. package/src/formulas/normalize.ts +52 -0
  47. package/src/formulas/parser.ts +280 -0
  48. package/src/formulas/range_tokenizer.ts +97 -0
  49. package/src/formulas/tokenizer.ts +242 -0
  50. package/src/functions/arguments.ts +114 -0
  51. package/src/functions/dates.ts +302 -0
  52. package/src/functions/helpers.ts +592 -0
  53. package/src/functions/index.ts +52 -0
  54. package/src/functions/module_database.ts +282 -0
  55. package/src/functions/module_date.ts +743 -0
  56. package/src/functions/module_info.ts +69 -0
  57. package/src/functions/module_logical.ts +208 -0
  58. package/src/functions/module_lookup.ts +185 -0
  59. package/src/functions/module_math.ts +1252 -0
  60. package/src/functions/module_operators.ts +291 -0
  61. package/src/functions/module_statistical.ts +882 -0
  62. package/src/functions/module_text.ts +370 -0
  63. package/src/helpers/color.ts +30 -0
  64. package/src/helpers/coordinates.ts +71 -0
  65. package/src/helpers/grid_manipulation.ts +68 -0
  66. package/src/helpers/index.ts +7 -0
  67. package/src/helpers/misc.ts +76 -0
  68. package/src/helpers/numbers.ts +117 -0
  69. package/src/helpers/uuid.ts +19 -0
  70. package/src/helpers/zones.ts +263 -0
  71. package/src/history.ts +186 -0
  72. package/src/index.ts +84 -0
  73. package/src/model.ts +261 -0
  74. package/src/plugins/autofill.ts +412 -0
  75. package/src/plugins/chart.ts +404 -0
  76. package/src/plugins/clipboard.ts +461 -0
  77. package/src/plugins/conditional_format.ts +445 -0
  78. package/src/plugins/core.ts +1502 -0
  79. package/src/plugins/edition.ts +157 -0
  80. package/src/plugins/evaluation.ts +428 -0
  81. package/src/plugins/figures.ts +123 -0
  82. package/src/plugins/formatting.ts +630 -0
  83. package/src/plugins/highlight.ts +187 -0
  84. package/src/plugins/index.ts +32 -0
  85. package/src/plugins/merge.ts +524 -0
  86. package/src/plugins/renderer.ts +571 -0
  87. package/src/plugins/selection.ts +562 -0
  88. package/src/plugins/selection_inputs.ts +326 -0
  89. package/src/registries/autofill_modifiers.ts +76 -0
  90. package/src/registries/autofill_rules.ts +98 -0
  91. package/src/registries/figure_registry.ts +30 -0
  92. package/src/registries/index.ts +7 -0
  93. package/src/registries/menu_items_registry.ts +110 -0
  94. package/src/registries/menus/cell_menu_registry.ts +79 -0
  95. package/src/registries/menus/col_menu_registry.ts +63 -0
  96. package/src/registries/menus/index.ts +6 -0
  97. package/src/registries/menus/menu_items_actions.ts +425 -0
  98. package/src/registries/menus/row_menu_registry.ts +63 -0
  99. package/src/registries/menus/sheet_menu_registry.ts +75 -0
  100. package/src/registries/menus/topbar_menu_registry.ts +204 -0
  101. package/src/registries/side_panel_registry.ts +26 -0
  102. package/src/registries/topbar_component_registry.ts +12 -0
  103. package/src/registry.ts +51 -0
  104. package/src/translation.ts +44 -0
  105. package/src/types/autofill.ts +48 -0
  106. package/src/types/chart.ts +26 -0
  107. package/src/types/commands.ts +716 -0
  108. package/src/types/conditional_formatting.ts +124 -0
  109. package/src/types/env.ts +13 -0
  110. package/src/types/functions.ts +35 -0
  111. package/src/types/getters.ts +103 -0
  112. package/src/types/index.ts +20 -0
  113. package/src/types/misc.ts +143 -0
  114. package/src/types/rendering.ts +41 -0
  115. package/src/types/workbook_data.ts +62 -0
  116. package/tests/__mocks__/uuid.ts +7 -0
  117. package/tests/canvas.mock.ts +34 -0
  118. package/tests/components/__mocks__/content_editable_helper.ts +79 -0
  119. package/tests/components/__mocks__/scrollbar.ts +18 -0
  120. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
  121. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
  122. package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
  123. package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
  124. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
  125. package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
  126. package/tests/components/autocomplete_dropdown_test.ts +315 -0
  127. package/tests/components/autofill_test.ts +167 -0
  128. package/tests/components/bottom_bar_test.ts +262 -0
  129. package/tests/components/chart_side_panel_test.ts +123 -0
  130. package/tests/components/composer_test.ts +400 -0
  131. package/tests/components/context_menu_test.ts +825 -0
  132. package/tests/components/grid_manipulation_test.ts +163 -0
  133. package/tests/components/grid_test.ts +581 -0
  134. package/tests/components/overlay_test.ts +541 -0
  135. package/tests/components/selection_input_test.ts +259 -0
  136. package/tests/components/side_panel_test.ts +148 -0
  137. package/tests/components/spreadsheet_test.ts +194 -0
  138. package/tests/components/top_bar_test.ts +427 -0
  139. package/tests/data_test.ts +175 -0
  140. package/tests/dom_helper.ts +42 -0
  141. package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
  142. package/tests/formulas/compiler_test.ts +266 -0
  143. package/tests/formulas/composer_tokenizer_test.ts +137 -0
  144. package/tests/formulas/expressions_test.ts +57 -0
  145. package/tests/formulas/formulas_test.ts +80 -0
  146. package/tests/formulas/normalize_test.ts +82 -0
  147. package/tests/formulas/parser_test.ts +224 -0
  148. package/tests/formulas/range_tokenizer_test.ts +187 -0
  149. package/tests/formulas/tokenizer_test.ts +164 -0
  150. package/tests/functions/arguments_test.ts +141 -0
  151. package/tests/functions/dates_test.ts +1081 -0
  152. package/tests/functions/functions_test.ts +53 -0
  153. package/tests/functions/helper_test.ts +98 -0
  154. package/tests/functions/module_database_test.ts +311 -0
  155. package/tests/functions/module_date_test.ts +941 -0
  156. package/tests/functions/module_info_test.ts +139 -0
  157. package/tests/functions/module_logical_test.ts +369 -0
  158. package/tests/functions/module_lookup_test.ts +541 -0
  159. package/tests/functions/module_math_test.ts +2482 -0
  160. package/tests/functions/module_operators_test.ts +955 -0
  161. package/tests/functions/module_statistical_test.ts +2014 -0
  162. package/tests/functions/module_text_test.ts +667 -0
  163. package/tests/helpers/coordinates_test.ts +25 -0
  164. package/tests/helpers/misc_test.ts +95 -0
  165. package/tests/helpers/numbers_test.ts +196 -0
  166. package/tests/helpers/zones_test.ts +97 -0
  167. package/tests/helpers.ts +384 -0
  168. package/tests/menu_items_registry_test.ts +540 -0
  169. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
  170. package/tests/model/plugins/chart_test.ts +562 -0
  171. package/tests/model_test.ts +82 -0
  172. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
  173. package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
  174. package/tests/plugins/autofill_test.ts +457 -0
  175. package/tests/plugins/borders_test.ts +295 -0
  176. package/tests/plugins/clipboard_test.ts +1180 -0
  177. package/tests/plugins/conditional_formatting_test.ts +1253 -0
  178. package/tests/plugins/core_test.ts +614 -0
  179. package/tests/plugins/edition_test.ts +100 -0
  180. package/tests/plugins/evaluation_async_test.ts +332 -0
  181. package/tests/plugins/evaluation_dates_test.ts +79 -0
  182. package/tests/plugins/evaluation_test.ts +901 -0
  183. package/tests/plugins/figures_test.ts +327 -0
  184. package/tests/plugins/formatting_test.ts +391 -0
  185. package/tests/plugins/grid_manipulation_test.ts +1366 -0
  186. package/tests/plugins/highlight_test.ts +413 -0
  187. package/tests/plugins/history_test.ts +142 -0
  188. package/tests/plugins/import_export_test.ts +276 -0
  189. package/tests/plugins/merges_test.ts +490 -0
  190. package/tests/plugins/navigation_test.ts +181 -0
  191. package/tests/plugins/plugins/evaluation_test.ts +111 -0
  192. package/tests/plugins/renderer_test.ts +598 -0
  193. package/tests/plugins/resizing_test.ts +152 -0
  194. package/tests/plugins/selection_input_test.ts +409 -0
  195. package/tests/plugins/selection_test.ts +442 -0
  196. package/tests/plugins/sheets_test.ts +643 -0
  197. package/tests/plugins/style_test.ts +90 -0
  198. package/tsconfig.json +22 -0
@@ -0,0 +1,716 @@
1
+ import { BorderCommand, ConditionalFormat, CreateChartDefinition, Style, Zone } from "./index";
2
+ import { Cell } from "./misc";
3
+ import { Figure } from "./workbook_data";
4
+
5
+ // -----------------------------------------------------------------------------
6
+ // Grid commands
7
+ // -----------------------------------------------------------------------------
8
+
9
+ /**
10
+ * There are two kinds of commands: Primitive and Local
11
+ *
12
+ * - Primitive commands are commands that
13
+ * 1. manipulate the imported/exported spreadsheet state
14
+ * 2. are "low level" => cannot be converted into lower level commands
15
+ * 3. make sense when sent by the network to another user
16
+ *
17
+ * - Local commands: every other command.
18
+ * 1. manipulate the local state (such as the selection, or the clipboard)
19
+ * 2. can often be converted into primitive commands
20
+ * 3. do not make sense to send by network to another user.
21
+ *
22
+ * For example, "RESIZE_COLUMNS" is a primitive command. "AUTORESIZE_COLUMNS"
23
+ * can be (locally) converted into a "RESIZE_COLUMNS", and therefore, is not a
24
+ * primitive command.
25
+ *
26
+ * Primitive commands should be "device agnostic". This means that they should
27
+ * contain all the information necessary to perform their job. Local commands
28
+ * can use inferred information from the local internal state, such as the
29
+ * active sheet.
30
+ */
31
+
32
+ interface BaseCommand {
33
+ interactive?: boolean;
34
+ }
35
+
36
+ // Primitive Commands
37
+ // ------------------------------------------------
38
+ export interface UpdateCellCommand extends BaseCommand {
39
+ type: "UPDATE_CELL";
40
+ sheet: string;
41
+ col: number;
42
+ row: number;
43
+ content?: string;
44
+ style?: number;
45
+ border?: number;
46
+ format?: string;
47
+ }
48
+
49
+ export interface ResizeColumnsCommand extends BaseCommand {
50
+ type: "RESIZE_COLUMNS";
51
+ sheet: string;
52
+ cols: number[];
53
+ size: number;
54
+ }
55
+
56
+ export interface ResizeRowsCommand extends BaseCommand {
57
+ type: "RESIZE_ROWS";
58
+ sheet: string;
59
+ rows: number[];
60
+ size: number;
61
+ }
62
+
63
+ /**
64
+ * Todo: add a string "id" field, and change the code to use internally a uuid.
65
+ */
66
+ export interface CreateSheetCommand extends BaseCommand {
67
+ type: "CREATE_SHEET";
68
+ id: string;
69
+ name?: string;
70
+ cols?: number;
71
+ rows?: number;
72
+ activate?: boolean;
73
+ }
74
+
75
+ export interface MoveSheetCommand extends BaseCommand {
76
+ type: "MOVE_SHEET";
77
+ sheet: string;
78
+ direction: "left" | "right";
79
+ }
80
+
81
+ export interface RenameSheetCommand extends BaseCommand {
82
+ type: "RENAME_SHEET";
83
+ sheet: string;
84
+ name?: string;
85
+ }
86
+
87
+ export interface DuplicateSheetCommand extends BaseCommand {
88
+ type: "DUPLICATE_SHEET";
89
+ sheet: string;
90
+ id: string;
91
+ name: string;
92
+ }
93
+
94
+ export interface DeleteSheetCommand extends BaseCommand {
95
+ type: "DELETE_SHEET";
96
+ sheet: string;
97
+ }
98
+
99
+ export interface DeleteSheetConfirmationCommand extends BaseCommand {
100
+ type: "DELETE_SHEET_CONFIRMATION";
101
+ sheet: string;
102
+ }
103
+
104
+ export interface AddMergeCommand extends BaseCommand {
105
+ type: "ADD_MERGE";
106
+ sheet: string;
107
+ zone: Zone;
108
+ force?: boolean;
109
+ }
110
+
111
+ export interface RemoveMergeCommand extends BaseCommand {
112
+ type: "REMOVE_MERGE";
113
+ sheet: string;
114
+ zone: Zone;
115
+ }
116
+
117
+ export interface AddFormattingCommand extends BaseCommand {
118
+ type: "SET_FORMATTING";
119
+ sheet: string;
120
+ target: Zone[];
121
+ style?: Style;
122
+ border?: BorderCommand;
123
+ }
124
+
125
+ export interface ClearFormattingCommand extends BaseCommand {
126
+ type: "CLEAR_FORMATTING";
127
+ sheet: string;
128
+ target: Zone[];
129
+ }
130
+
131
+ export interface SetFormatterCommand extends BaseCommand {
132
+ type: "SET_FORMATTER";
133
+ sheet: string;
134
+ target: Zone[];
135
+ formatter: string;
136
+ }
137
+
138
+ export interface SetDecimalCommand extends BaseCommand {
139
+ type: "SET_DECIMAL";
140
+ sheet: string;
141
+ target: Zone[];
142
+ step: number;
143
+ }
144
+
145
+ /**
146
+ * todo: add sheet argument...
147
+ * todo: use id instead of a list. this is not safe to serialize and send to
148
+ * another user
149
+ */
150
+ export interface AddConditionalFormatCommand extends BaseCommand {
151
+ type: "ADD_CONDITIONAL_FORMAT";
152
+ cf: ConditionalFormat;
153
+ sheet: string;
154
+ }
155
+
156
+ export interface RemoveConditionalFormatCommand extends BaseCommand {
157
+ type: "REMOVE_CONDITIONAL_FORMAT";
158
+ id: string;
159
+ sheet: string;
160
+ }
161
+
162
+ export interface RemoveColumnsCommand extends BaseCommand {
163
+ type: "REMOVE_COLUMNS";
164
+ columns: number[];
165
+ sheet: string; //Not used for now
166
+ }
167
+
168
+ export interface RemoveRowsCommand extends BaseCommand {
169
+ type: "REMOVE_ROWS";
170
+ rows: number[];
171
+ sheet: string; //Not used for now
172
+ }
173
+
174
+ export interface AddColumnsCommand extends BaseCommand {
175
+ type: "ADD_COLUMNS";
176
+ column: number;
177
+ sheet: string; //Not used for now
178
+ quantity: number;
179
+ position: "before" | "after";
180
+ }
181
+
182
+ export interface AddRowsCommand extends BaseCommand {
183
+ type: "ADD_ROWS";
184
+ row: number;
185
+ sheet: string; //Not used for now
186
+ quantity: number;
187
+ position: "before" | "after";
188
+ }
189
+
190
+ // Local Commands
191
+ // ------------------------------------------------
192
+ export interface CopyCommand extends BaseCommand {
193
+ type: "COPY";
194
+ target: Zone[];
195
+ }
196
+
197
+ export interface CutCommand extends BaseCommand {
198
+ type: "CUT";
199
+ target: Zone[];
200
+ }
201
+
202
+ export interface PasteCommand extends BaseCommand {
203
+ type: "PASTE";
204
+ target: Zone[];
205
+ onlyValue?: boolean;
206
+ onlyFormat?: boolean;
207
+ force?: boolean;
208
+ }
209
+
210
+ export interface PasteCellCommand extends BaseCommand {
211
+ type: "PASTE_CELL";
212
+ origin: Cell | null;
213
+ originCol: number;
214
+ originRow: number;
215
+ col: number;
216
+ row: number;
217
+ sheet: string;
218
+ cut?: boolean;
219
+ onlyValue: boolean;
220
+ onlyFormat: boolean;
221
+ }
222
+
223
+ export interface AutoFillCellCommand extends BaseCommand {
224
+ type: "AUTOFILL_CELL";
225
+ originCol: number;
226
+ originRow: number;
227
+ col: number;
228
+ row: number;
229
+ content?: string;
230
+ style?: number;
231
+ border?: number;
232
+ format?: string;
233
+ }
234
+
235
+ export interface ActivatePaintFormatCommand extends BaseCommand {
236
+ type: "ACTIVATE_PAINT_FORMAT";
237
+ target: Zone[];
238
+ }
239
+
240
+ export interface PasteFromOSClipboardCommand extends BaseCommand {
241
+ type: "PASTE_FROM_OS_CLIPBOARD";
242
+ target: Zone[];
243
+ text: string;
244
+ }
245
+
246
+ export interface AutoresizeColumnsCommand extends BaseCommand {
247
+ type: "AUTORESIZE_COLUMNS";
248
+ sheet: string;
249
+ cols: number[];
250
+ }
251
+
252
+ export interface AutoresizeRowsCommand extends BaseCommand {
253
+ type: "AUTORESIZE_ROWS";
254
+ sheet: string;
255
+ rows: number[];
256
+ }
257
+
258
+ export interface MovePositionCommand extends BaseCommand {
259
+ type: "MOVE_POSITION";
260
+ deltaX: number;
261
+ deltaY: number;
262
+ }
263
+
264
+ export interface ActivateSheetCommand extends BaseCommand {
265
+ type: "ACTIVATE_SHEET";
266
+ from: string;
267
+ to: string;
268
+ }
269
+
270
+ export interface SelectCellCommand extends BaseCommand {
271
+ type: "SELECT_CELL";
272
+ col: number;
273
+ row: number;
274
+ }
275
+
276
+ export interface SetSelectionCommand extends BaseCommand {
277
+ type: "SET_SELECTION";
278
+ anchor: [number, number];
279
+ zones: Zone[];
280
+ strict?: boolean;
281
+ }
282
+
283
+ /**
284
+ * Set the selection mode to `selecting`.
285
+ * The user is currently selecting some cells.
286
+ */
287
+ export interface StartSelectionCommand extends BaseCommand {
288
+ type: "START_SELECTION";
289
+ }
290
+
291
+ /**
292
+ * Set the selection mode to `readyToExpand`.
293
+ * The user is ready to expand the selected zones with a new
294
+ * selection (i.e. add an other zone the to currently selected zones).
295
+ * In other words, the next selection will be added to the
296
+ * current selection if this mode is active.
297
+ */
298
+ export interface PrepareExpansionCommand extends BaseCommand {
299
+ type: "PREPARE_SELECTION_EXPANSION";
300
+ }
301
+
302
+ /**
303
+ * Set the selection mode to `expanding`.
304
+ * This mode means that the user is currently selecting
305
+ * a new zone which will be added to the current selection.
306
+ */
307
+ export interface StartExpansionCommand extends BaseCommand {
308
+ type: "START_SELECTION_EXPANSION";
309
+ }
310
+
311
+ /**
312
+ * Set the selection mode to `idle`.
313
+ */
314
+ export interface StopSelectionCommand extends BaseCommand {
315
+ type: "STOP_SELECTION";
316
+ }
317
+
318
+ /**
319
+ * When selection highlight is enabled, every selection will
320
+ * be highlighted. Each selected zone have a different color.
321
+ */
322
+ export interface HighlightSelectionCommand extends BaseCommand {
323
+ type: "HIGHLIGHT_SELECTION";
324
+ enabled: boolean;
325
+ }
326
+
327
+ /**
328
+ * Add some highlights as pending highlights.
329
+ * When highlight selection is enabled, pending highlights
330
+ * are removed at every new selection.
331
+ */
332
+ export interface AddPendingHighlightCommand extends BaseCommand {
333
+ type: "ADD_PENDING_HIGHLIGHTS";
334
+ ranges: { [range: string]: string };
335
+ }
336
+
337
+ /**
338
+ * Removes all pending highlights.
339
+ */
340
+ export interface ResetPendingHighlightCommand extends BaseCommand {
341
+ type: "RESET_PENDING_HIGHLIGHT";
342
+ }
343
+
344
+ /**
345
+ * Set a color to be used for the next selection to highlight.
346
+ * The color is only used when selection highlight is enabled.
347
+ */
348
+ export interface SetColorCommand extends BaseCommand {
349
+ type: "SET_HIGHLIGHT_COLOR";
350
+ color: string;
351
+ }
352
+
353
+ export interface SelectColumnCommand extends BaseCommand {
354
+ type: "SELECT_COLUMN";
355
+ index: number;
356
+ createRange?: boolean;
357
+ updateRange?: boolean;
358
+ }
359
+
360
+ export interface SelectRowCommand extends BaseCommand {
361
+ type: "SELECT_ROW";
362
+ index: number;
363
+ createRange?: boolean;
364
+ updateRange?: boolean;
365
+ }
366
+
367
+ export interface SelectAllCommand extends BaseCommand {
368
+ type: "SELECT_ALL";
369
+ }
370
+
371
+ export interface AlterSelectionCommand extends BaseCommand {
372
+ type: "ALTER_SELECTION";
373
+ delta?: [number, number];
374
+ cell?: [number, number];
375
+ }
376
+
377
+ export interface EvaluateCellsCommand extends BaseCommand {
378
+ type: "EVALUATE_CELLS";
379
+ onlyWaiting?: boolean;
380
+ }
381
+
382
+ export interface AddHighlightsCommand extends BaseCommand {
383
+ type: "ADD_HIGHLIGHTS";
384
+ ranges: { [range: string]: string };
385
+ }
386
+
387
+ /**
388
+ * Remove the given highlights.
389
+ */
390
+ export interface RemoveHighlightsCommand extends BaseCommand {
391
+ type: "REMOVE_HIGHLIGHTS";
392
+ /**
393
+ * Ranges to remove. Keys are ranges in XC format and values
394
+ * are the associated colors.
395
+ * e.g. { B4: "#e2e2e2" }
396
+ */
397
+ ranges: { [range: string]: string };
398
+ }
399
+ export interface RemoveAllHighlightsCommand extends BaseCommand {
400
+ type: "REMOVE_ALL_HIGHLIGHTS";
401
+ }
402
+
403
+ export interface StartComposerSelectionCommand extends BaseCommand {
404
+ type: "START_COMPOSER_SELECTION";
405
+ }
406
+
407
+ export interface StopComposerSelectionCommand extends BaseCommand {
408
+ type: "STOP_COMPOSER_SELECTION";
409
+ }
410
+
411
+ export interface StartEditionCommand extends BaseCommand {
412
+ type: "START_EDITION";
413
+ text?: string;
414
+ }
415
+
416
+ export interface StopEditionCommand extends BaseCommand {
417
+ type: "STOP_EDITION";
418
+ cancel?: boolean;
419
+ }
420
+
421
+ export interface SetCurrentContentCommand extends BaseCommand {
422
+ type: "SET_CURRENT_CONTENT";
423
+ content: string;
424
+ }
425
+
426
+ export interface SetValueCommand extends BaseCommand {
427
+ type: "SET_VALUE";
428
+ xc: string;
429
+ text: string;
430
+ sheetId?: string;
431
+ }
432
+ export interface ShowFormulaCommand extends BaseCommand {
433
+ type: "SET_FORMULA_VISIBILITY";
434
+ show: boolean;
435
+ }
436
+
437
+ export interface DeleteContentCommand extends BaseCommand {
438
+ type: "DELETE_CONTENT";
439
+ sheet: string;
440
+ target: Zone[];
441
+ }
442
+
443
+ export interface ClearCellCommand extends BaseCommand {
444
+ type: "CLEAR_CELL";
445
+ sheet: string;
446
+ col: number;
447
+ row: number;
448
+ }
449
+
450
+ export interface UndoCommand extends BaseCommand {
451
+ type: "UNDO";
452
+ }
453
+
454
+ export interface RedoCommand extends BaseCommand {
455
+ type: "REDO";
456
+ }
457
+
458
+ export interface StartCommand extends BaseCommand {
459
+ type: "START";
460
+ }
461
+
462
+ export interface AutofillCommand extends BaseCommand {
463
+ type: "AUTOFILL";
464
+ }
465
+
466
+ export interface AutofillSelectCommand extends BaseCommand {
467
+ type: "AUTOFILL_SELECT";
468
+ col: number;
469
+ row: number;
470
+ }
471
+
472
+ export interface AutofillAutoCommand extends BaseCommand {
473
+ type: "AUTOFILL_AUTO";
474
+ }
475
+
476
+ /**
477
+ * Create a new state for a SelectionInput component
478
+ */
479
+ export interface NewInputCommand extends BaseCommand {
480
+ type: "ENABLE_NEW_SELECTION_INPUT";
481
+ /**
482
+ * Identifier to use to reference this state.
483
+ */
484
+ id: string;
485
+ /**
486
+ * Initial ranges for the state.
487
+ * e.g. ["B4", "A1:A3"]
488
+ */
489
+ initialRanges?: string[];
490
+ /**
491
+ * Maximum number of ranges allowed
492
+ */
493
+ maximumRanges?: number;
494
+ }
495
+
496
+ /**
497
+ * Delete an identified SelectionInput state.
498
+ */
499
+ export interface RemoveInputCommand extends BaseCommand {
500
+ type: "DISABLE_SELECTION_INPUT";
501
+ /** SelectionComponent id */
502
+ id: string;
503
+ }
504
+
505
+ /**
506
+ * Set the focus on a given range of a SelectionComponent state.
507
+ */
508
+ export interface FocusInputCommand extends BaseCommand {
509
+ type: "FOCUS_RANGE";
510
+ /** SelectionComponent id */
511
+ id: string;
512
+ /**
513
+ * Range to focus. If `null` is given, removes the focus entirely.
514
+ */
515
+ rangeId: string | null;
516
+ }
517
+
518
+ /**
519
+ * Add an empty range at the end of a SelectionComponent state
520
+ * and focus it.
521
+ */
522
+ export interface AddEmptyRangeCommand extends BaseCommand {
523
+ type: "ADD_EMPTY_RANGE";
524
+ /** SelectionComponent id */
525
+ id: string;
526
+ }
527
+
528
+ /**
529
+ * Remove a given range in a SelectionComponent state
530
+ */
531
+ export interface RemoveRangeCommand extends BaseCommand {
532
+ type: "REMOVE_RANGE";
533
+ /** SelectionComponent id */
534
+ id: string;
535
+ /** The range to be removed */
536
+ rangeId: string;
537
+ }
538
+
539
+ /**
540
+ * Set a new value for a given range of a SelectionComponent state.
541
+ */
542
+ export interface ChangeRangeCommand extends BaseCommand {
543
+ type: "CHANGE_RANGE";
544
+ /** SelectionComponent id */
545
+ id: string;
546
+ /** The range to be changed */
547
+ rangeId: string;
548
+ /**
549
+ * Range to set in the input. Invalid ranges are also accepted.
550
+ * e.g. "B2:B3" or the invalid "A5:"
551
+ */
552
+ value: string;
553
+ }
554
+
555
+ export interface CreateFigureCommand extends BaseCommand {
556
+ type: "CREATE_FIGURE";
557
+ figure: Figure<any>;
558
+ sheet: string; // id of the target sheet
559
+ }
560
+
561
+ export interface SelectFigureCommand extends BaseCommand {
562
+ type: "SELECT_FIGURE";
563
+ id: string;
564
+ }
565
+
566
+ export interface UpdateFigureCommand extends BaseCommand, Partial<Figure<any>> {
567
+ type: "UPDATE_FIGURE";
568
+ id: string;
569
+ }
570
+
571
+ export interface DeleteFigureCommand extends BaseCommand {
572
+ type: "DELETE_FIGURE";
573
+ id: string;
574
+ }
575
+
576
+ export interface CreateChartCommand extends BaseCommand {
577
+ type: "CREATE_CHART";
578
+ id: string;
579
+ sheetId: string;
580
+ definition: CreateChartDefinition;
581
+ }
582
+
583
+ export interface UpdateChartCommand extends BaseCommand {
584
+ type: "UPDATE_CHART";
585
+ id: string;
586
+ definition: CreateChartDefinition;
587
+ }
588
+
589
+ export type Command =
590
+ | NewInputCommand
591
+ | RemoveInputCommand
592
+ | FocusInputCommand
593
+ | AddEmptyRangeCommand
594
+ | RemoveRangeCommand
595
+ | ChangeRangeCommand
596
+ | UpdateCellCommand
597
+ | CopyCommand
598
+ | CutCommand
599
+ | PasteCommand
600
+ | PasteCellCommand
601
+ | AutoFillCellCommand
602
+ | PasteFromOSClipboardCommand
603
+ | ActivatePaintFormatCommand
604
+ | ResizeRowsCommand
605
+ | ResizeColumnsCommand
606
+ | AutoresizeColumnsCommand
607
+ | AutoresizeRowsCommand
608
+ | MovePositionCommand
609
+ | CreateSheetCommand
610
+ | MoveSheetCommand
611
+ | RenameSheetCommand
612
+ | DuplicateSheetCommand
613
+ | DeleteSheetCommand
614
+ | DeleteSheetConfirmationCommand
615
+ | ActivateSheetCommand
616
+ | StartSelectionCommand
617
+ | StartExpansionCommand
618
+ | PrepareExpansionCommand
619
+ | StopSelectionCommand
620
+ | SelectCellCommand
621
+ | SetSelectionCommand
622
+ | SelectColumnCommand
623
+ | SelectRowCommand
624
+ | SelectAllCommand
625
+ | AlterSelectionCommand
626
+ | DeleteContentCommand
627
+ | EvaluateCellsCommand
628
+ | AddConditionalFormatCommand
629
+ | RemoveConditionalFormatCommand
630
+ | AddHighlightsCommand
631
+ | RemoveHighlightsCommand
632
+ | RemoveAllHighlightsCommand
633
+ | HighlightSelectionCommand
634
+ | AddPendingHighlightCommand
635
+ | ResetPendingHighlightCommand
636
+ | SetColorCommand
637
+ | StartComposerSelectionCommand
638
+ | StopComposerSelectionCommand
639
+ | StartEditionCommand
640
+ | StopEditionCommand
641
+ | AddMergeCommand
642
+ | RemoveMergeCommand
643
+ | SetCurrentContentCommand
644
+ | SetValueCommand
645
+ | AddFormattingCommand
646
+ | ClearFormattingCommand
647
+ | SetFormatterCommand
648
+ | SetDecimalCommand
649
+ | ClearCellCommand
650
+ | UndoCommand
651
+ | RedoCommand
652
+ | StartCommand
653
+ | RemoveRowsCommand
654
+ | RemoveColumnsCommand
655
+ | AddRowsCommand
656
+ | CreateChartCommand
657
+ | UpdateChartCommand
658
+ | AddColumnsCommand
659
+ | AutofillCommand
660
+ | AutofillSelectCommand
661
+ | ShowFormulaCommand
662
+ | AutofillAutoCommand
663
+ | CreateFigureCommand
664
+ | SelectFigureCommand
665
+ | UpdateFigureCommand
666
+ | DeleteFigureCommand;
667
+
668
+ export interface CommandSuccess {
669
+ status: "SUCCESS";
670
+ }
671
+ export interface CommandCancelled {
672
+ status: "CANCELLED";
673
+ reason: CancelledReason;
674
+ }
675
+
676
+ export const enum CancelledReason {
677
+ Unknown,
678
+ WillRemoveExistingMerge,
679
+ MergeIsDestructive,
680
+ EmptyUndoStack,
681
+ EmptyRedoStack,
682
+ NotEnoughColumns,
683
+ NotEnoughRows,
684
+ NotEnoughSheets,
685
+ WrongSheetName,
686
+ WrongSheetMove,
687
+ SelectionOutOfBound,
688
+ WrongPasteSelection,
689
+ EmptyClipboard,
690
+ InvalidRange,
691
+ InputAlreadyFocused,
692
+ MaximumRangesReached,
693
+ InvalidChartDefinition,
694
+ InvalidAutofillSelection,
695
+ }
696
+
697
+ export type CommandResult = CommandSuccess | CommandCancelled;
698
+
699
+ export interface CommandHandler {
700
+ allowDispatch(command: Command): CommandResult;
701
+ beforeHandle(command: Command): void;
702
+ handle(command: Command): void;
703
+ finalize(command: Command): void;
704
+ }
705
+
706
+ export interface CommandDispatcher {
707
+ dispatch<T extends CommandTypes, C extends Extract<Command, { type: T }>>(
708
+ type: {} extends Omit<C, "type"> ? T : never
709
+ ): CommandResult;
710
+ dispatch<T extends CommandTypes, C extends Extract<Command, { type: T }>>(
711
+ type: T,
712
+ r: Omit<C, "type">
713
+ ): CommandResult;
714
+ }
715
+
716
+ export type CommandTypes = Command["type"];