@odoo/o-spreadsheet 14.0.1 → 15.0.0

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 (203) hide show
  1. package/dist/o_spreadsheet.cjs.js +31302 -0
  2. package/dist/o_spreadsheet.d.ts +6604 -0
  3. package/dist/o_spreadsheet.esm.js +31257 -0
  4. package/dist/o_spreadsheet.iife.js +31304 -0
  5. package/dist/o_spreadsheet.iife.min.js +3071 -0
  6. package/package.json +57 -15
  7. package/.eslintrc.json +0 -20
  8. package/.husky/post-checkout +0 -9
  9. package/.husky/pre-commit +0 -39
  10. package/.prettierignore +0 -1
  11. package/astToFormula.patch +0 -0
  12. package/demo/data.js +0 -255
  13. package/demo/index.html +0 -9
  14. package/demo/libs/Chart.bundle.js +0 -20755
  15. package/demo/main.js +0 -101
  16. package/doc/readme.md +0 -46
  17. package/rollup.config.js +0 -23
  18. package/src/base_plugin.ts +0 -102
  19. package/src/components/autofill.ts +0 -146
  20. package/src/components/bottom_bar.ts +0 -199
  21. package/src/components/color_picker.ts +0 -150
  22. package/src/components/composer/autocomplete_dropdown.ts +0 -135
  23. package/src/components/composer/composer.ts +0 -487
  24. package/src/components/composer/content_editable_helper.ts +0 -146
  25. package/src/components/figures/chart.ts +0 -70
  26. package/src/components/figures/container.ts +0 -268
  27. package/src/components/figures/text_figure.ts +0 -36
  28. package/src/components/grid.ts +0 -635
  29. package/src/components/helpers/dom_helpers.ts +0 -7
  30. package/src/components/helpers/drag_and_drop.ts +0 -17
  31. package/src/components/icons.ts +0 -36
  32. package/src/components/index.ts +0 -1
  33. package/src/components/menu.ts +0 -288
  34. package/src/components/overlay.ts +0 -457
  35. package/src/components/scrollbar.ts +0 -22
  36. package/src/components/selection_input.ts +0 -168
  37. package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
  38. package/src/components/side_panel/chart_panel.ts +0 -104
  39. package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
  40. package/src/components/side_panel/conditional_formatting.ts +0 -396
  41. package/src/components/side_panel/side_panel.ts +0 -127
  42. package/src/components/side_panel/translations_terms.ts +0 -45
  43. package/src/components/spreadsheet.ts +0 -198
  44. package/src/components/top_bar.ts +0 -535
  45. package/src/constants.ts +0 -26
  46. package/src/data.ts +0 -149
  47. package/src/fonts.ts +0 -41
  48. package/src/formulas/compiler.ts +0 -258
  49. package/src/formulas/composer_tokenizer.ts +0 -70
  50. package/src/formulas/index.ts +0 -15
  51. package/src/formulas/normalize.ts +0 -52
  52. package/src/formulas/parser.ts +0 -280
  53. package/src/formulas/range_tokenizer.ts +0 -97
  54. package/src/formulas/tokenizer.ts +0 -242
  55. package/src/functions/arguments.ts +0 -114
  56. package/src/functions/dates.ts +0 -302
  57. package/src/functions/helpers.ts +0 -592
  58. package/src/functions/index.ts +0 -52
  59. package/src/functions/module_database.ts +0 -282
  60. package/src/functions/module_date.ts +0 -743
  61. package/src/functions/module_info.ts +0 -69
  62. package/src/functions/module_logical.ts +0 -208
  63. package/src/functions/module_lookup.ts +0 -185
  64. package/src/functions/module_math.ts +0 -1252
  65. package/src/functions/module_operators.ts +0 -291
  66. package/src/functions/module_statistical.ts +0 -882
  67. package/src/functions/module_text.ts +0 -370
  68. package/src/helpers/color.ts +0 -30
  69. package/src/helpers/coordinates.ts +0 -71
  70. package/src/helpers/grid_manipulation.ts +0 -68
  71. package/src/helpers/index.ts +0 -7
  72. package/src/helpers/misc.ts +0 -76
  73. package/src/helpers/numbers.ts +0 -117
  74. package/src/helpers/uuid.ts +0 -19
  75. package/src/helpers/zones.ts +0 -263
  76. package/src/history.ts +0 -186
  77. package/src/index.ts +0 -84
  78. package/src/model.ts +0 -261
  79. package/src/plugins/autofill.ts +0 -412
  80. package/src/plugins/chart.ts +0 -404
  81. package/src/plugins/clipboard.ts +0 -461
  82. package/src/plugins/conditional_format.ts +0 -445
  83. package/src/plugins/core.ts +0 -1502
  84. package/src/plugins/edition.ts +0 -157
  85. package/src/plugins/evaluation.ts +0 -428
  86. package/src/plugins/figures.ts +0 -123
  87. package/src/plugins/formatting.ts +0 -630
  88. package/src/plugins/highlight.ts +0 -187
  89. package/src/plugins/index.ts +0 -32
  90. package/src/plugins/merge.ts +0 -524
  91. package/src/plugins/renderer.ts +0 -571
  92. package/src/plugins/selection.ts +0 -562
  93. package/src/plugins/selection_inputs.ts +0 -326
  94. package/src/registries/autofill_modifiers.ts +0 -76
  95. package/src/registries/autofill_rules.ts +0 -98
  96. package/src/registries/figure_registry.ts +0 -30
  97. package/src/registries/index.ts +0 -7
  98. package/src/registries/menu_items_registry.ts +0 -110
  99. package/src/registries/menus/cell_menu_registry.ts +0 -79
  100. package/src/registries/menus/col_menu_registry.ts +0 -63
  101. package/src/registries/menus/index.ts +0 -6
  102. package/src/registries/menus/menu_items_actions.ts +0 -425
  103. package/src/registries/menus/row_menu_registry.ts +0 -63
  104. package/src/registries/menus/sheet_menu_registry.ts +0 -75
  105. package/src/registries/menus/topbar_menu_registry.ts +0 -204
  106. package/src/registries/side_panel_registry.ts +0 -26
  107. package/src/registries/topbar_component_registry.ts +0 -12
  108. package/src/registry.ts +0 -51
  109. package/src/translation.ts +0 -44
  110. package/src/types/autofill.ts +0 -48
  111. package/src/types/chart.ts +0 -26
  112. package/src/types/commands.ts +0 -716
  113. package/src/types/conditional_formatting.ts +0 -124
  114. package/src/types/env.ts +0 -13
  115. package/src/types/functions.ts +0 -35
  116. package/src/types/getters.ts +0 -103
  117. package/src/types/index.ts +0 -20
  118. package/src/types/misc.ts +0 -143
  119. package/src/types/rendering.ts +0 -41
  120. package/src/types/workbook_data.ts +0 -62
  121. package/tests/__mocks__/uuid.ts +0 -7
  122. package/tests/canvas.mock.ts +0 -34
  123. package/tests/components/__mocks__/content_editable_helper.ts +0 -79
  124. package/tests/components/__mocks__/scrollbar.ts +0 -18
  125. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
  126. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
  127. package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
  128. package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
  129. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
  130. package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
  131. package/tests/components/autocomplete_dropdown_test.ts +0 -315
  132. package/tests/components/autofill_test.ts +0 -167
  133. package/tests/components/bottom_bar_test.ts +0 -262
  134. package/tests/components/chart_side_panel_test.ts +0 -123
  135. package/tests/components/composer_test.ts +0 -400
  136. package/tests/components/context_menu_test.ts +0 -825
  137. package/tests/components/grid_manipulation_test.ts +0 -163
  138. package/tests/components/grid_test.ts +0 -581
  139. package/tests/components/overlay_test.ts +0 -541
  140. package/tests/components/selection_input_test.ts +0 -259
  141. package/tests/components/side_panel_test.ts +0 -148
  142. package/tests/components/spreadsheet_test.ts +0 -194
  143. package/tests/components/top_bar_test.ts +0 -427
  144. package/tests/data_test.ts +0 -175
  145. package/tests/dom_helper.ts +0 -42
  146. package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
  147. package/tests/formulas/compiler_test.ts +0 -266
  148. package/tests/formulas/composer_tokenizer_test.ts +0 -137
  149. package/tests/formulas/expressions_test.ts +0 -57
  150. package/tests/formulas/formulas_test.ts +0 -80
  151. package/tests/formulas/normalize_test.ts +0 -82
  152. package/tests/formulas/parser_test.ts +0 -224
  153. package/tests/formulas/range_tokenizer_test.ts +0 -187
  154. package/tests/formulas/tokenizer_test.ts +0 -164
  155. package/tests/functions/arguments_test.ts +0 -141
  156. package/tests/functions/dates_test.ts +0 -1081
  157. package/tests/functions/functions_test.ts +0 -53
  158. package/tests/functions/helper_test.ts +0 -98
  159. package/tests/functions/module_database_test.ts +0 -311
  160. package/tests/functions/module_date_test.ts +0 -941
  161. package/tests/functions/module_info_test.ts +0 -139
  162. package/tests/functions/module_logical_test.ts +0 -369
  163. package/tests/functions/module_lookup_test.ts +0 -541
  164. package/tests/functions/module_math_test.ts +0 -2482
  165. package/tests/functions/module_operators_test.ts +0 -955
  166. package/tests/functions/module_statistical_test.ts +0 -2014
  167. package/tests/functions/module_text_test.ts +0 -667
  168. package/tests/helpers/coordinates_test.ts +0 -25
  169. package/tests/helpers/misc_test.ts +0 -95
  170. package/tests/helpers/numbers_test.ts +0 -196
  171. package/tests/helpers/zones_test.ts +0 -97
  172. package/tests/helpers.ts +0 -384
  173. package/tests/menu_items_registry_test.ts +0 -540
  174. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
  175. package/tests/model/plugins/chart_test.ts +0 -562
  176. package/tests/model_test.ts +0 -82
  177. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
  178. package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
  179. package/tests/plugins/autofill_test.ts +0 -457
  180. package/tests/plugins/borders_test.ts +0 -295
  181. package/tests/plugins/clipboard_test.ts +0 -1180
  182. package/tests/plugins/conditional_formatting_test.ts +0 -1253
  183. package/tests/plugins/core_test.ts +0 -614
  184. package/tests/plugins/edition_test.ts +0 -100
  185. package/tests/plugins/evaluation_async_test.ts +0 -332
  186. package/tests/plugins/evaluation_dates_test.ts +0 -79
  187. package/tests/plugins/evaluation_test.ts +0 -901
  188. package/tests/plugins/figures_test.ts +0 -327
  189. package/tests/plugins/formatting_test.ts +0 -391
  190. package/tests/plugins/grid_manipulation_test.ts +0 -1366
  191. package/tests/plugins/highlight_test.ts +0 -413
  192. package/tests/plugins/history_test.ts +0 -142
  193. package/tests/plugins/import_export_test.ts +0 -276
  194. package/tests/plugins/merges_test.ts +0 -490
  195. package/tests/plugins/navigation_test.ts +0 -181
  196. package/tests/plugins/plugins/evaluation_test.ts +0 -111
  197. package/tests/plugins/renderer_test.ts +0 -598
  198. package/tests/plugins/resizing_test.ts +0 -152
  199. package/tests/plugins/selection_input_test.ts +0 -409
  200. package/tests/plugins/selection_test.ts +0 -442
  201. package/tests/plugins/sheets_test.ts +0 -643
  202. package/tests/plugins/style_test.ts +0 -90
  203. package/tsconfig.json +0 -22
@@ -1,282 +0,0 @@
1
- import { _lt } from "../translation";
2
- import { FunctionDescription } from "../types";
3
- import { args } from "./arguments";
4
- import { toString, visitMatchingRanges } from "./helpers";
5
- import { PRODUCT, SUM } from "./module_math";
6
- import { AVERAGE, COUNT, COUNTA, MAX, MIN, STDEV, STDEVP, VAR, VARP } from "./module_statistical";
7
-
8
- function getMatchingCells(database: any, field: any, criteria: any): any[] {
9
- // Exemple :
10
- //
11
- // # DATABASE # CRITERIA # field = "C"
12
- //
13
- // | A | B | C | | A | C |
14
- // |===========| |=======|
15
- // | 1 | x | j | |<2 | j |
16
- // | 1 | Z | k | | | 7 |
17
- // | 5 | y | 7 |
18
-
19
- // 1 - Select coordinates of database columns
20
- const indexColNameDB = new Map();
21
- const dimRowDB = database.length;
22
- for (let indexCol = dimRowDB - 1; indexCol >= 0; indexCol--) {
23
- indexColNameDB.set(toString(database[indexCol][0]).toUpperCase(), indexCol);
24
- } // Ex: indexColNameDB = {A => 0, B => 1, C => 2}
25
-
26
- // 2 - Check if the field parameter exists in the column names of the database
27
- const typeofField = typeof field;
28
- let index;
29
- if (typeofField === "number") {
30
- // field may either be a text label corresponding to a column header in the
31
- // first row of database or a numeric index indicating which column to consider,
32
- // where the first column has the value 1.
33
- index = Math.trunc(field) - 1;
34
- if (index < 0 || index > dimRowDB - 1) {
35
- throw new Error(
36
- _lt(
37
- "Function [[FUNCTION_NAME]] parameter 2 value is %s. Valid values are between 1 and %s inclusive.",
38
- field,
39
- dimRowDB
40
- )
41
- );
42
- }
43
- } else {
44
- const colName = typeofField === "string" ? field.toUpperCase() : field;
45
- index = indexColNameDB.get(colName);
46
- if (index === undefined) {
47
- throw new Error(
48
- _lt(
49
- "Function [[FUNCTION_NAME]] parameter 2 value is %s. It should be one of: %s.",
50
- field,
51
- [...indexColNameDB.keys()].map((v) => "'" + v + "'").join(", ")
52
- )
53
- );
54
- }
55
- } // Ex: index = 2
56
-
57
- // 3 - For each criteria row, find database row that correspond
58
- const dimColCriteria = criteria[0].length;
59
-
60
- if (dimColCriteria < 2) {
61
- throw new Error(_lt(`[[FUNCTION_NAME]] criteria range must be at least 2 rows.`));
62
- }
63
-
64
- let matchingRows: Set<number> = new Set();
65
- const dimColDB = database[0].length;
66
- for (let indexRow = 1; indexRow < dimColCriteria; indexRow++) {
67
- let args: any[] = [];
68
- let existColNameDB = true;
69
- for (let indexCol = 0; indexCol < criteria.length; indexCol++) {
70
- const curentName = toString(criteria[indexCol][0]).toUpperCase();
71
- const indexColDB = indexColNameDB.get(curentName);
72
- const criter = criteria[indexCol][indexRow];
73
- if (criter !== undefined) {
74
- if (indexColDB !== undefined) {
75
- args.push([database[indexColDB].slice(1, dimColDB)]);
76
- args.push(criter);
77
- } else {
78
- existColNameDB = false;
79
- break;
80
- }
81
- }
82
- }
83
- // Ex: args1 = [[1,1,5], "<2", ["j","k",7], "j"]
84
- // Ex: args2 = [["j","k",7], "7"]
85
-
86
- if (existColNameDB) {
87
- if (args.length > 0) {
88
- visitMatchingRanges(
89
- args,
90
- (i, j) => {
91
- matchingRows.add(j);
92
- },
93
- true
94
- );
95
- } else {
96
- // return indices of each database row when a criteria table row is void
97
- matchingRows = new Set(Array(dimColDB - 1).keys());
98
- break;
99
- }
100
- }
101
- } // Ex: matchingRows = {0, 2}
102
-
103
- // 4 - return for each database row corresponding, the cells corresponding to
104
- // the field parameter
105
- const fieldCol: any[] = database[index];
106
- // Ex: fieldCol = ["C", "j", "k", 7]
107
- const matchingCells = [...matchingRows].map((x) => fieldCol[x + 1]);
108
- // Ex: matchingCells = ["j", 7]
109
-
110
- return matchingCells;
111
- }
112
-
113
- const databaseArgs = args(`
114
- database (range) ${_lt(
115
- "The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values."
116
- )}
117
- field (any) ${_lt(
118
- "Indicates which column in database contains the values to be extracted and operated on."
119
- )}
120
- criteria (range) ${_lt(
121
- "An array or range containing zero or more criteria to filter the database values by before operating."
122
- )}
123
- `);
124
-
125
- // -----------------------------------------------------------------------------
126
- // DAVERAGE
127
- // -----------------------------------------------------------------------------
128
- export const DAVERAGE: FunctionDescription = {
129
- description: _lt("Average of a set of values from a table-like range."),
130
- args: databaseArgs,
131
- returns: ["NUMBER"],
132
- compute: function (database: any, field: any, criteria: any): number {
133
- const cells = getMatchingCells(database, field, criteria);
134
- return AVERAGE.compute([cells]);
135
- },
136
- };
137
-
138
- // -----------------------------------------------------------------------------
139
- // DCOUNT
140
- // -----------------------------------------------------------------------------
141
- export const DCOUNT: FunctionDescription = {
142
- description: _lt("Counts values from a table-like range."),
143
- args: databaseArgs,
144
- returns: ["NUMBER"],
145
- compute: function (database: any, field: any, criteria: any): number {
146
- const cells = getMatchingCells(database, field, criteria);
147
- return COUNT.compute([cells]);
148
- },
149
- };
150
-
151
- // -----------------------------------------------------------------------------
152
- // DCOUNTA
153
- // -----------------------------------------------------------------------------
154
- export const DCOUNTA: FunctionDescription = {
155
- description: _lt("Counts values and text from a table-like range."),
156
- args: databaseArgs,
157
- returns: ["NUMBER"],
158
- compute: function (database: any, field: any, criteria: any): number {
159
- const cells = getMatchingCells(database, field, criteria);
160
- return COUNTA.compute([cells]);
161
- },
162
- };
163
-
164
- // -----------------------------------------------------------------------------
165
- // DGET
166
- // -----------------------------------------------------------------------------
167
- export const DGET: FunctionDescription = {
168
- description: _lt("Single value from a table-like range."),
169
- args: databaseArgs,
170
- returns: ["NUMBER"],
171
- compute: function (database: any, field: any, criteria: any): any {
172
- const cells = getMatchingCells(database, field, criteria);
173
- if (cells.length > 1) {
174
- throw new Error(_lt(`More than one match found in DGET evaluation.`));
175
- }
176
- return cells[0];
177
- },
178
- };
179
-
180
- // -----------------------------------------------------------------------------
181
- // DMAX
182
- // -----------------------------------------------------------------------------
183
- export const DMAX: FunctionDescription = {
184
- description: _lt("Maximum of values from a table-like range."),
185
- args: databaseArgs,
186
- returns: ["NUMBER"],
187
- compute: function (database: any, field: any, criteria: any): number {
188
- const cells = getMatchingCells(database, field, criteria);
189
- return MAX.compute([cells]);
190
- },
191
- };
192
-
193
- // -----------------------------------------------------------------------------
194
- // DMIN
195
- // -----------------------------------------------------------------------------
196
- export const DMIN: FunctionDescription = {
197
- description: _lt("Minimum of values from a table-like range."),
198
- args: databaseArgs,
199
- returns: ["NUMBER"],
200
- compute: function (database: any, field: any, criteria: any): number {
201
- const cells = getMatchingCells(database, field, criteria);
202
- return MIN.compute([cells]);
203
- },
204
- };
205
-
206
- // -----------------------------------------------------------------------------
207
- // DPRODUCT
208
- // -----------------------------------------------------------------------------
209
- export const DPRODUCT: FunctionDescription = {
210
- description: _lt("Product of values from a table-like range."),
211
- args: databaseArgs,
212
- returns: ["NUMBER"],
213
- compute: function (database: any, field: any, criteria: any): number {
214
- const cells = getMatchingCells(database, field, criteria);
215
- return PRODUCT.compute([cells]);
216
- },
217
- };
218
-
219
- // -----------------------------------------------------------------------------
220
- // DSTDEV
221
- // -----------------------------------------------------------------------------
222
- export const DSTDEV: FunctionDescription = {
223
- description: _lt("Standard deviation of population sample from table."),
224
- args: databaseArgs,
225
- returns: ["NUMBER"],
226
- compute: function (database: any, field: any, criteria: any): number {
227
- const cells = getMatchingCells(database, field, criteria);
228
- return STDEV.compute([cells]);
229
- },
230
- };
231
-
232
- // -----------------------------------------------------------------------------
233
- // DSTDEVP
234
- // -----------------------------------------------------------------------------
235
- export const DSTDEVP: FunctionDescription = {
236
- description: _lt("Standard deviation of entire population from table."),
237
- args: databaseArgs,
238
- returns: ["NUMBER"],
239
- compute: function (database: any, field: any, criteria: any): number {
240
- const cells = getMatchingCells(database, field, criteria);
241
- return STDEVP.compute([cells]);
242
- },
243
- };
244
-
245
- // -----------------------------------------------------------------------------
246
- // DSUM
247
- // -----------------------------------------------------------------------------
248
- export const DSUM: FunctionDescription = {
249
- description: _lt("Sum of values from a table-like range."),
250
- args: databaseArgs,
251
- returns: ["NUMBER"],
252
- compute: function (database: any, field: any, criteria: any): number {
253
- const cells = getMatchingCells(database, field, criteria);
254
- return SUM.compute([cells]);
255
- },
256
- };
257
-
258
- // -----------------------------------------------------------------------------
259
- // DVAR
260
- // -----------------------------------------------------------------------------
261
- export const DVAR: FunctionDescription = {
262
- description: _lt("Variance of population sample from table-like range."),
263
- args: databaseArgs,
264
- returns: ["NUMBER"],
265
- compute: function (database: any, field: any, criteria: any): number {
266
- const cells = getMatchingCells(database, field, criteria);
267
- return VAR.compute([cells]);
268
- },
269
- };
270
-
271
- // -----------------------------------------------------------------------------
272
- // DVARP
273
- // -----------------------------------------------------------------------------
274
- export const DVARP: FunctionDescription = {
275
- description: _lt("Variance of a population from a table-like range."),
276
- args: databaseArgs,
277
- returns: ["NUMBER"],
278
- compute: function (database: any, field: any, criteria: any): number {
279
- const cells = getMatchingCells(database, field, criteria);
280
- return VARP.compute([cells]);
281
- },
282
- };