@odoo/o-spreadsheet 14.0.1 → 14.0.2

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 +17836 -0
  2. package/dist/o_spreadsheet.d.ts +4102 -0
  3. package/dist/o_spreadsheet.esm.js +17801 -0
  4. package/dist/o_spreadsheet.iife.js +17838 -0
  5. package/dist/o_spreadsheet.iife.min.js +1440 -0
  6. package/package.json +27 -7
  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,370 +0,0 @@
1
- import { _lt } from "../translation";
2
- import { FunctionDescription } from "../types";
3
- import { args } from "./arguments";
4
- import { reduceArgs, toBoolean, toNumber, toString } from "./helpers";
5
-
6
- // -----------------------------------------------------------------------------
7
- // CHAR
8
- // -----------------------------------------------------------------------------
9
- export const CHAR: FunctionDescription = {
10
- description: _lt("Gets character associated with number."),
11
- args: args(`
12
- table_number (number) ${_lt(
13
- "The number of the character to look up from the current Unicode table in decimal format."
14
- )}
15
- `),
16
- returns: ["STRING"],
17
- compute: function (table_number: any): string {
18
- const _tableNumber = Math.trunc(toNumber(table_number));
19
- if (_tableNumber < 1) {
20
- throw new Error(
21
- _lt("Function CHAR parameter 1 value %s is out of range.", _tableNumber.toString())
22
- );
23
- }
24
- return String.fromCharCode(_tableNumber);
25
- },
26
- };
27
-
28
- // -----------------------------------------------------------------------------
29
- // CONCATENATE
30
- // -----------------------------------------------------------------------------
31
- export const CONCATENATE: FunctionDescription = {
32
- description: _lt("Appends strings to one another."),
33
- args: args(`
34
- string1 (string, range<string>) ${_lt("The initial string.")}
35
- string2 (string, range<string>, optional, repeating) ${_lt(
36
- "More strings to append in sequence."
37
- )}
38
- `),
39
- returns: ["STRING"],
40
- compute: function (): string {
41
- return reduceArgs(arguments, (acc, a) => acc + toString(a), "");
42
- },
43
- };
44
-
45
- // -----------------------------------------------------------------------------
46
- // EXACT
47
- // -----------------------------------------------------------------------------
48
- export const EXACT: FunctionDescription = {
49
- description: _lt("Tests whether two strings are identical."),
50
- args: args(`
51
- string1 (string) ${_lt("The first string to compare.")}
52
- string2 (string) ${_lt("The second string to compare.")}
53
- `),
54
- returns: ["BOOLEAN"],
55
- compute: function (string1: any, string2: any): boolean {
56
- return toString(string1) === toString(string2);
57
- },
58
- };
59
-
60
- // -----------------------------------------------------------------------------
61
- // FIND
62
- // -----------------------------------------------------------------------------
63
- export const FIND: FunctionDescription = {
64
- description: _lt("First position of string found in text, case-sensitive."),
65
- args: args(`
66
- search_for (string) ${_lt("The string to look for within text_to_search.")}
67
- text_to_search (string) ${_lt("The text to search for the first occurrence of search_for.")}
68
- starting_at (number, optional, default=1 ) ${_lt(
69
- "The character within text_to_search at which to start the search."
70
- )}
71
- `),
72
- returns: ["NUMBER"],
73
- compute: function (search_for: any, text_to_search: any, starting_at: any = 1): number {
74
- const _textToSearch = toString(text_to_search);
75
- if (_textToSearch === "") {
76
- throw new Error(_lt(`Function FIND parameter 2 value should be non-empty.`));
77
- }
78
-
79
- const _startingAt = toNumber(starting_at);
80
- if (_startingAt === 0) {
81
- throw new Error(
82
- _lt(`Function FIND parameter 3 value is 0. It should be greater than or equal to 1.`)
83
- );
84
- }
85
-
86
- const _searchFor = toString(search_for);
87
- const result = _textToSearch.indexOf(_searchFor, _startingAt - 1);
88
- if (result < 0) {
89
- throw new Error(
90
- _lt(
91
- "In FIND evaluation, cannot find '%s' within '%s'.",
92
- _searchFor.toString(),
93
- _textToSearch
94
- )
95
- );
96
- }
97
- return result + 1;
98
- },
99
- };
100
-
101
- // -----------------------------------------------------------------------------
102
- // JOIN
103
- // -----------------------------------------------------------------------------
104
- export const JOIN: FunctionDescription = {
105
- description: _lt("Concatenates elements of arrays with delimiter."),
106
- args: args(`
107
- delimiter (string) ${_lt("The character or string to place between each concatenated value.")}
108
- value_or_array1 (string, range<string>) ${_lt(
109
- "The value or values to be appended using delimiter."
110
- )}
111
- value_or_array2 (string, range<string>, optional, repeating) ${_lt(
112
- "More values to be appended using delimiter."
113
- )}
114
- `),
115
- returns: ["STRING"],
116
- compute: function (delimiter: any, ...values_or_arrays: any): string {
117
- const _delimiter = toString(delimiter);
118
- return reduceArgs(
119
- values_or_arrays,
120
- (acc, a) => (acc ? acc + _delimiter : "") + toString(a),
121
- ""
122
- );
123
- },
124
- };
125
-
126
- // -----------------------------------------------------------------------------
127
- // LEFT
128
- // -----------------------------------------------------------------------------
129
- export const LEFT: FunctionDescription = {
130
- description: _lt("Substring from beginning of specified string."),
131
- args: args(`
132
- text (string) ${_lt("The string from which the left portion will be returned.")}
133
- number_of_characters (number, optional, default=1) ${_lt(
134
- "The number of characters to return from the left side of string."
135
- )}
136
- `),
137
- returns: ["STRING"],
138
- compute: function (text: any, number_of_characters: any = 1): string {
139
- const _numberOfCharacters = toNumber(number_of_characters);
140
- if (_numberOfCharacters < 0) {
141
- throw new Error(
142
- _lt(`Function LEFT parameter 2 value is negative. It should be positive or zero.`)
143
- );
144
- }
145
- return toString(text).substring(0, _numberOfCharacters);
146
- },
147
- };
148
-
149
- // -----------------------------------------------------------------------------
150
- // LEN
151
- // -----------------------------------------------------------------------------
152
- export const LEN: FunctionDescription = {
153
- description: _lt("Length of a string."),
154
- args: args(`
155
- text (string) ${_lt("The string whose length will be returned.")}
156
- `),
157
- returns: ["NUMBER"],
158
- compute: function (text: any): number {
159
- return toString(text).length;
160
- },
161
- };
162
-
163
- // -----------------------------------------------------------------------------
164
- // LOWER
165
- // -----------------------------------------------------------------------------
166
- export const LOWER: FunctionDescription = {
167
- description: _lt("Converts a specified string to lowercase."),
168
- args: args(`
169
- text (string) ${_lt("The string to convert to lowercase.")}
170
- `),
171
- returns: ["STRING"],
172
- compute: function (text: any): string {
173
- return toString(text).toLowerCase();
174
- },
175
- };
176
-
177
- // -----------------------------------------------------------------------------
178
- // REPLACE
179
- // -----------------------------------------------------------------------------
180
- export const REPLACE: FunctionDescription = {
181
- description: _lt("Replaces part of a text string with different text."),
182
- args: args(`
183
- text (string) ${_lt("The text, a part of which will be replaced.")}
184
- position (number) ${_lt("The position where the replacement will begin (starting from 1).")}
185
- length (number) ${_lt("The number of characters in the text to be replaced.")}
186
- new_text (string) ${_lt("The text which will be inserted into the original text.")}
187
- `),
188
- returns: ["STRING"],
189
- compute: function (text: any, position: any, length: any, new_text: any): string {
190
- const _position = toNumber(position);
191
- if (_position < 1) {
192
- throw new Error(
193
- _lt(
194
- "Function REPLACE parameter 2 value is %s. It should be greater than or equal to 1.",
195
- toString(_position)
196
- )
197
- );
198
- }
199
-
200
- const _text = toString(text);
201
- const _length = toNumber(length);
202
- const _newText = toString(new_text);
203
- return _text.substring(0, _position - 1) + _newText + _text.substring(_position - 1 + _length);
204
- },
205
- };
206
-
207
- // -----------------------------------------------------------------------------
208
- // RIGHT
209
- // -----------------------------------------------------------------------------
210
- export const RIGHT: FunctionDescription = {
211
- description: _lt("A substring from the end of a specified string."),
212
- args: args(`
213
- text (string) ${_lt("The string from which the right portion will be returned.")}
214
- number_of_characters (number, optional, default=1) ${_lt(
215
- "The number of characters to return from the right side of string."
216
- )}
217
- `),
218
- returns: ["STRING"],
219
- compute: function (text: any, number_of_characters: any = 1): string {
220
- const _numberOfCharacters = toNumber(number_of_characters);
221
- if (_numberOfCharacters < 0) {
222
- throw new Error(
223
- _lt(`Function RIGHT parameter 2 value is negative. It should be positive or zero.`)
224
- );
225
- }
226
- const _text = toString(text);
227
- const stringLength = _text.length;
228
- return _text.substring(stringLength - _numberOfCharacters, stringLength);
229
- },
230
- };
231
-
232
- // -----------------------------------------------------------------------------
233
- // SEARCH
234
- // -----------------------------------------------------------------------------
235
- export const SEARCH: FunctionDescription = {
236
- description: _lt("First position of string found in text, ignoring case."),
237
- args: args(`
238
- search_for (string) ${_lt("The string to look for within text_to_search.")}
239
- text_to_search (string) ${_lt("The text to search for the first occurrence of search_for.")}
240
- starting_at (number, optional, default=1 ) ${_lt(
241
- "The character within text_to_search at which to start the search."
242
- )}
243
- `),
244
- returns: ["NUMBER"],
245
- compute: function (search_for: any, text_to_search: any, starting_at: any = 1): number {
246
- const _textToSearch = toString(text_to_search).toLowerCase();
247
- if (_textToSearch === "") {
248
- throw new Error(_lt(`Function SEARCH parameter 2 value should be non-empty.`));
249
- }
250
-
251
- const _startingAt = toNumber(starting_at);
252
- if (_startingAt === 0) {
253
- throw new Error(
254
- _lt(`Function SEARCH parameter 3 value is 0. It should be greater than or equal to 1.`)
255
- );
256
- }
257
-
258
- const _searchFor = toString(search_for).toLowerCase();
259
- const result = _textToSearch.indexOf(_searchFor, _startingAt - 1);
260
- if (result < 0) {
261
- throw new Error(
262
- _lt("In SEARCH evaluation, cannot find '%s' within '%s'.", _searchFor, _textToSearch)
263
- );
264
- }
265
- return result + 1;
266
- },
267
- };
268
-
269
- // -----------------------------------------------------------------------------
270
- // SUBSTITUTE
271
- // -----------------------------------------------------------------------------
272
- export const SUBSTITUTE: FunctionDescription = {
273
- description: _lt("Replaces existing text with new text in a string."),
274
- args: args(`
275
- text_to_search (string) ${_lt("The text within which to search and replace.")}
276
- search_for (string) ${_lt("The string to search for within text_to_search.")}
277
- replace_with (string) ${_lt("The string that will replace search_for.")}
278
- occurrence_number (number, optional) ${_lt(
279
- "The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced."
280
- )}
281
- `),
282
- returns: ["NUMBER"],
283
- compute: function (
284
- text_to_search: any,
285
- search_for: any,
286
- replace_with: any,
287
- occurrence_number: any = undefined
288
- ): string {
289
- const _occurrenceNumber = toNumber(occurrence_number);
290
- if (_occurrenceNumber < 0) {
291
- throw new Error(
292
- _lt(`Function SUBSTITUTE parameter 4 value is negative. It should be positive or zero.`)
293
- );
294
- }
295
-
296
- const _textToSearch = toString(text_to_search);
297
- const _searchFor = toString(search_for);
298
- if (_searchFor === "") {
299
- return _textToSearch;
300
- }
301
-
302
- const _replaceWith = toString(replace_with);
303
- const reg = new RegExp(_searchFor, "g");
304
- if (_occurrenceNumber === 0) {
305
- return _textToSearch.replace(reg, _replaceWith);
306
- }
307
-
308
- let n = 0;
309
- return _textToSearch.replace(reg, (text) => (++n === _occurrenceNumber ? _replaceWith : text));
310
- },
311
- };
312
-
313
- // -----------------------------------------------------------------------------
314
- // TEXTJOIN
315
- // -----------------------------------------------------------------------------
316
- export const TEXTJOIN: FunctionDescription = {
317
- description: _lt("Combines text from multiple strings and/or arrays."),
318
- args: args(`
319
- delimiter (string) ${_lt(
320
- " A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated."
321
- )}
322
- ignore_empty (boolean) ${_lt(
323
- "A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result."
324
- )}
325
- text1 (string, range<string>) ${_lt(
326
- "Any text item. This could be a string, or an array of strings in a range."
327
- )}
328
- text2 (string, range<string>, optional, repeating) ${_lt("Additional text item(s).")}
329
- `),
330
- returns: ["STRING"],
331
- compute: function (delimiter: any, ignore_empty: any, ...texts_or_arrays: any): string {
332
- const _delimiter = toString(delimiter);
333
- const _ignoreEmpty = toBoolean(ignore_empty);
334
- let n = 0;
335
- return reduceArgs(
336
- texts_or_arrays,
337
- (acc, a) =>
338
- !(_ignoreEmpty && toString(a) === "") ? (n++ ? acc + _delimiter : "") + toString(a) : acc,
339
- ""
340
- );
341
- },
342
- };
343
-
344
- // -----------------------------------------------------------------------------
345
- // TRIM
346
- // -----------------------------------------------------------------------------
347
- export const TRIM: FunctionDescription = {
348
- description: _lt("Removes space characters."),
349
- args: args(`
350
- text (string) ${_lt("The text or reference to a cell containing text to be trimmed.")}
351
- `),
352
- returns: ["STRING"],
353
- compute: function (text: any): string {
354
- return toString(text).trim();
355
- },
356
- };
357
-
358
- // -----------------------------------------------------------------------------
359
- // UPPER
360
- // -----------------------------------------------------------------------------
361
- export const UPPER: FunctionDescription = {
362
- description: _lt("Converts a specified string to uppercase."),
363
- args: args(`
364
- text (string) ${_lt("The string to convert to uppercase.")}
365
- `),
366
- returns: ["STRING"],
367
- compute: function (text: any): string {
368
- return toString(text).toUpperCase();
369
- },
370
- };
@@ -1,30 +0,0 @@
1
- export const colors = [
2
- "#ff851b",
3
- "#0074d9",
4
- "#ffdc00",
5
- "#7fdbff",
6
- "#b10dc9",
7
- "#0ecc40",
8
- "#39cccc",
9
- "#f012be",
10
- "#3d9970",
11
- "#111111",
12
- "#01ff70",
13
- "#ff4136",
14
- "#aaaaaa",
15
- "#85144b",
16
- "#001f3f",
17
- ];
18
-
19
- /*
20
- * transform a color number (R * 256^2 + G * 256 + B) into classic RGB
21
- * */
22
- export function colorNumberString(color: number): string {
23
- return color.toString(16).padStart(6, "0");
24
- }
25
-
26
- let colorIndex = 0;
27
- export function getNextColor() {
28
- colorIndex = ++colorIndex % colors.length;
29
- return colors[colorIndex];
30
- }
@@ -1,71 +0,0 @@
1
- //------------------------------------------------------------------------------
2
- // Coordinate
3
- //------------------------------------------------------------------------------
4
-
5
- /**
6
- * Convert a (col) number to the corresponding letter.
7
- *
8
- * Examples:
9
- * 0 => 'A'
10
- * 25 => 'Z'
11
- * 26 => 'AA'
12
- * 27 => 'AB'
13
- */
14
- export function numberToLetters(n: number): string {
15
- if (n < 26) {
16
- return String.fromCharCode(65 + n);
17
- } else {
18
- return numberToLetters(Math.floor(n / 26) - 1) + numberToLetters(n % 26);
19
- }
20
- }
21
-
22
- /**
23
- * Convert a string (describing a column) to its number value.
24
- *
25
- * Examples:
26
- * 'A' => 0
27
- * 'Z' => 25
28
- * 'AA' => 26
29
- */
30
- export function lettersToNumber(letters: string): number {
31
- let result = 0;
32
- const l = letters.length;
33
- for (let i = 0; i < l; i++) {
34
- let n = letters.charCodeAt(i) - 65 + (i < l - 1 ? 1 : 0);
35
- result += n * 26 ** (l - i - 1);
36
- }
37
- return result;
38
- }
39
-
40
- /**
41
- * Convert a "XC" coordinate to cartesian coordinates.
42
- *
43
- * Examples:
44
- * A1 => [0,0]
45
- * B3 => [1,2]
46
- *
47
- * Note: it also accepts lowercase coordinates, but not fixed references
48
- */
49
- export function toCartesian(xc: string): [number, number] {
50
- xc = xc.toUpperCase();
51
- const [m, letters, numbers] = xc.match(/\$?([A-Z]*)\$?([0-9]*)/)!;
52
- if (m !== xc) {
53
- throw new Error(`Invalid cell description: ${xc}`);
54
- }
55
- const col = lettersToNumber(letters);
56
- const row = parseInt(numbers, 10) - 1;
57
- return [col, row];
58
- }
59
-
60
- /**
61
- * Convert from cartesian coordinate to the "XC" coordinate system.
62
- *
63
- * Examples:
64
- * [0,0] => A1
65
- * [1,2] => B3
66
- *
67
- * Note: it does not support fixed references
68
- */
69
- export function toXC(col: number, row: number): string {
70
- return numberToLetters(col) + String(row + 1);
71
- }
@@ -1,68 +0,0 @@
1
- /*
2
- * Contains all method to update ranges with grid_manipulation
3
- */
4
-
5
- import { toXC } from "./coordinates";
6
- import { toZone } from "./zones";
7
-
8
- export function updateRemoveColumns(range: string, columns: number[]): string | null {
9
- let { left, right, top, bottom } = toZone(range);
10
- columns = columns.slice().sort((a, b) => b - a);
11
- for (let column of columns) {
12
- if (left > column) {
13
- left -= 1;
14
- }
15
- if (left >= column || right >= column) {
16
- right -= 1;
17
- }
18
- }
19
- if (left > right) {
20
- return null;
21
- }
22
- return toXC(left, top) + ":" + toXC(right, bottom);
23
- }
24
-
25
- export function updateRemoveRows(range: string, rows: number[]): string | null {
26
- let { left, right, top, bottom } = toZone(range);
27
- rows = rows.slice().sort((a, b) => b - a);
28
- for (let row of rows) {
29
- if (top > row) {
30
- top -= 1;
31
- }
32
- if (top >= row || bottom >= row) {
33
- bottom -= 1;
34
- }
35
- }
36
- if (top > bottom) {
37
- return null;
38
- }
39
- return toXC(left, top) + ":" + toXC(right, bottom);
40
- }
41
-
42
- export function updateAddColumns(range: string, column: number, step: number): string | null {
43
- let { left, right, top, bottom } = toZone(range);
44
- if (left >= column) {
45
- left += step;
46
- }
47
- if (left >= column || right >= column) {
48
- right += step;
49
- }
50
- if (left > right) {
51
- return null;
52
- }
53
- return toXC(left, top) + ":" + toXC(right, bottom);
54
- }
55
-
56
- export function updateAddRows(range: string, row: number, step: number): string | null {
57
- let { left, right, top, bottom } = toZone(range);
58
- if (top >= row) {
59
- top += step;
60
- }
61
- if (top >= row || bottom >= row) {
62
- bottom += step;
63
- }
64
- if (top > bottom) {
65
- return null;
66
- }
67
- return toXC(left, top) + ":" + toXC(right, bottom);
68
- }
@@ -1,7 +0,0 @@
1
- export * from "./color";
2
- export * from "./coordinates";
3
- export * from "./grid_manipulation";
4
- export * from "./misc";
5
- export * from "./numbers";
6
- export * from "./uuid";
7
- export * from "./zones";
@@ -1,76 +0,0 @@
1
- //------------------------------------------------------------------------------
2
- // Miscellaneous
3
- //------------------------------------------------------------------------------
4
-
5
- /**
6
- * Stringify an object, like JSON.stringify, except that the first level of keys
7
- * is ordered.
8
- */
9
- export function stringify(obj: any): string {
10
- return JSON.stringify(obj, Object.keys(obj).sort());
11
- }
12
-
13
- /**
14
- * Deep copy arrays, plain objects and primitive values.
15
- * Throws an error for other types such as class instances.
16
- * Sparse arrays remain sparse.
17
- */
18
- export function deepCopy<T>(obj: T): T {
19
- const result: any = Array.isArray(obj) ? [] : {};
20
- switch (typeof obj) {
21
- case "object": {
22
- if (obj === null) {
23
- return obj;
24
- } else if (!(isPlainObject(obj) || obj instanceof Array)) {
25
- throw new Error("Unsupported type: only objects and arrays are supported");
26
- }
27
- for (const key in obj) {
28
- result[key] = deepCopy(obj[key]);
29
- }
30
- return result;
31
- }
32
- case "number":
33
- case "string":
34
- case "boolean":
35
- case "function":
36
- case "undefined":
37
- return obj;
38
- default:
39
- throw new Error(`Unsupported type: ${typeof obj}`);
40
- }
41
- }
42
-
43
- /**
44
- * Check if the object is a plain old javascript object.
45
- */
46
- function isPlainObject(obj: unknown): boolean {
47
- return typeof obj === "object" && obj?.constructor === Object;
48
- }
49
-
50
- /**
51
- * Sanitize the name of a sheet, by eventually removing quotes
52
- * @param sheetName name of the sheet, potentially quoted with single quotes
53
- */
54
- export function getUnquotedSheetName(sheetName: string): string {
55
- if (sheetName.startsWith("'")) {
56
- sheetName = sheetName.slice(1, -1).replace(/''/g, "'");
57
- }
58
- return sheetName;
59
- }
60
-
61
- /**
62
- * Add quotes around the sheet name if it contains a space
63
- * @param sheetName Name of the sheet
64
- */
65
- export function getComposerSheetName(sheetName: string): string {
66
- if (sheetName.includes(" ")) {
67
- sheetName = `'${sheetName}'`;
68
- }
69
- return sheetName;
70
- }
71
-
72
- export function clip(val: number, min: number, max: number): number {
73
- return val < min ? min : val > max ? max : val;
74
- }
75
-
76
- export const DEBUG: { [key: string]: any } = {};