@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,187 @@
1
+ import { BasePlugin } from "../base_plugin";
2
+ import { getNextColor, isEqual, toZone } from "../helpers/index";
3
+ import { Mode } from "../model";
4
+ import { Command, GridRenderingContext, Highlight, LAYERS, Zone } from "../types/index";
5
+
6
+ /**
7
+ * HighlightPlugin
8
+ */
9
+ export class HighlightPlugin extends BasePlugin {
10
+ static modes: Mode[] = ["normal", "readonly"];
11
+ static layers = [LAYERS.Highlights];
12
+ static getters = ["getHighlights"];
13
+ private highlights: Highlight[] = [];
14
+ private color: string = "#000";
15
+ private highlightSelectionEnabled = false;
16
+ private pendingHighlights: Highlight[] = [];
17
+
18
+ // ---------------------------------------------------------------------------
19
+ // Command Handling
20
+ // ---------------------------------------------------------------------------
21
+
22
+ handle(cmd: Command) {
23
+ switch (cmd.type) {
24
+ case "ADD_HIGHLIGHTS":
25
+ this.addHighlights(cmd.ranges);
26
+ break;
27
+ case "REMOVE_ALL_HIGHLIGHTS":
28
+ this.highlights = [];
29
+ break;
30
+ case "REMOVE_HIGHLIGHTS":
31
+ this.removeHighlights(cmd.ranges);
32
+ break;
33
+ case "SELECT_CELL":
34
+ case "SET_SELECTION":
35
+ if (this.highlightSelectionEnabled) {
36
+ this.highlightSelection();
37
+ }
38
+ break;
39
+ case "START_SELECTION_EXPANSION":
40
+ this.color = getNextColor();
41
+ break;
42
+ case "HIGHLIGHT_SELECTION":
43
+ this.highlightSelectionEnabled = cmd.enabled;
44
+ if (!cmd.enabled) {
45
+ this.dispatch("RESET_PENDING_HIGHLIGHT");
46
+ }
47
+ break;
48
+ case "RESET_PENDING_HIGHLIGHT":
49
+ this.pendingHighlights = [];
50
+ break;
51
+ case "ADD_PENDING_HIGHLIGHTS":
52
+ this.addPendingHighlight(cmd.ranges);
53
+ break;
54
+ case "SET_HIGHLIGHT_COLOR":
55
+ this.color = cmd.color;
56
+ }
57
+ }
58
+
59
+ // ---------------------------------------------------------------------------
60
+ // Getters
61
+ // ---------------------------------------------------------------------------
62
+
63
+ getHighlights(): Highlight[] {
64
+ return this.highlights;
65
+ }
66
+
67
+ // ---------------------------------------------------------------------------
68
+ // Other
69
+ // ---------------------------------------------------------------------------
70
+
71
+ private addHighlights(ranges: { [range: string]: string }) {
72
+ let highlights = this.prepareHighlights(ranges);
73
+ this.highlights = this.highlights.concat(highlights);
74
+ }
75
+
76
+ private addPendingHighlight(ranges: { [range: string]: string }) {
77
+ let highlights = this.prepareHighlights(ranges);
78
+ this.pendingHighlights = this.pendingHighlights.concat(highlights);
79
+ }
80
+
81
+ private prepareHighlights(ranges: { [range: string]: string }): Highlight[] {
82
+ if (Object.keys(ranges).length === 0) {
83
+ return [];
84
+ }
85
+ return Object.keys(ranges)
86
+ .map((r1c1) => {
87
+ const [xc, sheet] = r1c1.split("!").reverse();
88
+ const sheetId = sheet
89
+ ? this.getters.getSheetIdByName(sheet)!
90
+ : this.getters.getActiveSheet();
91
+ const zone: Zone = this.getters.expandZone(toZone(xc));
92
+ return { zone, color: ranges[r1c1], sheet: sheetId };
93
+ })
94
+ .filter(
95
+ (x) =>
96
+ x.zone.top >= 0 &&
97
+ x.zone.left >= 0 &&
98
+ x.zone.bottom < this.workbook.activeSheet.rows.length &&
99
+ x.zone.right < this.workbook.activeSheet.cols.length
100
+ );
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @param ranges {"[sheet!]XC": color}
106
+ * @private
107
+ */
108
+ private removeHighlights(ranges: { [range: string]: string }) {
109
+ const activeSheetId = this.getters.getActiveSheet();
110
+ const rangesBySheets = {};
111
+ for (let [range, color] of Object.entries(ranges)) {
112
+ const [xc, sheetName] = range.split("!").reverse();
113
+ const sheetId = this.getters.getSheetIdByName(sheetName);
114
+ rangesBySheets[sheetId || activeSheetId] = Object.assign(
115
+ { [xc]: color },
116
+ rangesBySheets[sheetId || activeSheetId] || {}
117
+ );
118
+ }
119
+ const shouldBeKept = (highlight: Highlight) =>
120
+ !(
121
+ rangesBySheets[highlight.sheet] &&
122
+ rangesBySheets[highlight.sheet][this.getters.zoneToXC(highlight.zone)] === highlight.color
123
+ );
124
+ this.highlights = this.highlights.filter(shouldBeKept);
125
+ }
126
+
127
+ /**
128
+ * Highlight selected zones (which are not already highlighted).
129
+ */
130
+ private highlightSelection() {
131
+ this.removePendingHighlights();
132
+ const zones = this.getters.getSelectedZones().filter((z) => !this.isHighlighted(z));
133
+ const ranges = {};
134
+ let color = this.color;
135
+ for (const zone of zones) {
136
+ ranges[this.getters.zoneToXC(zone)] = color;
137
+ color = getNextColor();
138
+ }
139
+ this.dispatch("ADD_HIGHLIGHTS", { ranges });
140
+ this.dispatch("ADD_PENDING_HIGHLIGHTS", { ranges });
141
+ }
142
+
143
+ private isHighlighted(zone: Zone): boolean {
144
+ return !!this.highlights.find((h) => isEqual(h.zone, zone));
145
+ }
146
+
147
+ /**
148
+ * Remove pending highlights which are not selected.
149
+ * Highlighted zones which are selected are still considered
150
+ * pending.
151
+ */
152
+ private removePendingHighlights() {
153
+ const ranges = {};
154
+ const [selected, notSelected] = this.pendingHighlights.reduce(
155
+ ([y, n], highlight) =>
156
+ this.getters.isSelected(highlight.zone) ? [[...y, highlight], n] : [y, [...n, highlight]],
157
+ [[], []]
158
+ );
159
+ for (const { zone, color } of notSelected) {
160
+ ranges[this.getters.zoneToXC(zone)] = color;
161
+ }
162
+ this.dispatch("REMOVE_HIGHLIGHTS", { ranges });
163
+ this.pendingHighlights = selected;
164
+ }
165
+
166
+ // ---------------------------------------------------------------------------
167
+ // Grid rendering
168
+ // ---------------------------------------------------------------------------
169
+
170
+ drawGrid(renderingContext: GridRenderingContext) {
171
+ // rendering selection highlights
172
+ const { ctx, viewport, thinLineWidth } = renderingContext;
173
+ const sheetId = this.getters.getActiveSheet();
174
+ const lineWidth = 3 * thinLineWidth;
175
+ ctx.lineWidth = lineWidth;
176
+ for (let h of this.highlights.filter((highlight) => highlight.sheet === sheetId)) {
177
+ const [x, y, width, height] = this.getters.getRect(h.zone, viewport);
178
+ if (width > 0 && height > 0) {
179
+ ctx.strokeStyle = h.color!;
180
+ ctx.strokeRect(x + lineWidth / 2, y + lineWidth / 2, width - lineWidth, height - lineWidth);
181
+ ctx.globalCompositeOperation = "source-over";
182
+ ctx.fillStyle = h.color! + "20";
183
+ ctx.fillRect(x + lineWidth, y + lineWidth, width - 2 * lineWidth, height - 2 * lineWidth);
184
+ }
185
+ }
186
+ }
187
+ }
@@ -0,0 +1,32 @@
1
+ import { BasePlugin } from "../base_plugin";
2
+ import { Registry } from "../registry";
3
+ import { AutofillPlugin } from "./autofill";
4
+ import { ChartPlugin } from "./chart";
5
+ import { ClipboardPlugin } from "./clipboard";
6
+ import { ConditionalFormatPlugin } from "./conditional_format";
7
+ import { CorePlugin } from "./core";
8
+ import { EditionPlugin } from "./edition";
9
+ import { EvaluationPlugin } from "./evaluation";
10
+ import { FigurePlugin } from "./figures";
11
+ import { FormattingPlugin } from "./formatting";
12
+ import { HighlightPlugin } from "./highlight";
13
+ import { MergePlugin } from "./merge";
14
+ import { RendererPlugin } from "./renderer";
15
+ import { SelectionPlugin } from "./selection";
16
+ import { SelectionInputPlugin } from "./selection_inputs";
17
+
18
+ export const pluginRegistry = new Registry<typeof BasePlugin>()
19
+ .add("core", CorePlugin)
20
+ .add("evaluation", EvaluationPlugin)
21
+ .add("clipboard", ClipboardPlugin)
22
+ .add("merge", MergePlugin)
23
+ .add("formatting", FormattingPlugin)
24
+ .add("edition", EditionPlugin)
25
+ .add("selection", SelectionPlugin)
26
+ .add("highlight", HighlightPlugin)
27
+ .add("selectionInput", SelectionInputPlugin)
28
+ .add("conditional formatting", ConditionalFormatPlugin)
29
+ .add("figures", FigurePlugin)
30
+ .add("chart", ChartPlugin)
31
+ .add("grid renderer", RendererPlugin)
32
+ .add("autofill", AutofillPlugin);