@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.
- package/.eslintrc.json +20 -0
- package/.husky/post-checkout +9 -0
- package/.husky/pre-commit +39 -0
- package/.prettierignore +1 -0
- package/astToFormula.patch +0 -0
- package/demo/data.js +255 -0
- package/demo/index.html +9 -0
- package/demo/libs/Chart.bundle.js +20755 -0
- package/demo/main.js +101 -0
- package/doc/readme.md +46 -0
- package/package.json +3 -17
- package/rollup.config.js +23 -0
- package/src/base_plugin.ts +102 -0
- package/src/components/autofill.ts +146 -0
- package/src/components/bottom_bar.ts +199 -0
- package/src/components/color_picker.ts +150 -0
- package/src/components/composer/autocomplete_dropdown.ts +135 -0
- package/src/components/composer/composer.ts +487 -0
- package/src/components/composer/content_editable_helper.ts +146 -0
- package/src/components/figures/chart.ts +70 -0
- package/src/components/figures/container.ts +268 -0
- package/src/components/figures/text_figure.ts +36 -0
- package/src/components/grid.ts +635 -0
- package/src/components/helpers/dom_helpers.ts +7 -0
- package/src/components/helpers/drag_and_drop.ts +17 -0
- package/src/components/icons.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/components/menu.ts +288 -0
- package/src/components/overlay.ts +457 -0
- package/src/components/scrollbar.ts +22 -0
- package/src/components/selection_input.ts +168 -0
- package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
- package/src/components/side_panel/chart_panel.ts +104 -0
- package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
- package/src/components/side_panel/conditional_formatting.ts +396 -0
- package/src/components/side_panel/side_panel.ts +127 -0
- package/src/components/side_panel/translations_terms.ts +45 -0
- package/src/components/spreadsheet.ts +198 -0
- package/src/components/top_bar.ts +535 -0
- package/src/constants.ts +26 -0
- package/src/data.ts +149 -0
- package/src/fonts.ts +41 -0
- package/src/formulas/compiler.ts +258 -0
- package/src/formulas/composer_tokenizer.ts +70 -0
- package/src/formulas/index.ts +15 -0
- package/src/formulas/normalize.ts +52 -0
- package/src/formulas/parser.ts +280 -0
- package/src/formulas/range_tokenizer.ts +97 -0
- package/src/formulas/tokenizer.ts +242 -0
- package/src/functions/arguments.ts +114 -0
- package/src/functions/dates.ts +302 -0
- package/src/functions/helpers.ts +592 -0
- package/src/functions/index.ts +52 -0
- package/src/functions/module_database.ts +282 -0
- package/src/functions/module_date.ts +743 -0
- package/src/functions/module_info.ts +69 -0
- package/src/functions/module_logical.ts +208 -0
- package/src/functions/module_lookup.ts +185 -0
- package/src/functions/module_math.ts +1252 -0
- package/src/functions/module_operators.ts +291 -0
- package/src/functions/module_statistical.ts +882 -0
- package/src/functions/module_text.ts +370 -0
- package/src/helpers/color.ts +30 -0
- package/src/helpers/coordinates.ts +71 -0
- package/src/helpers/grid_manipulation.ts +68 -0
- package/src/helpers/index.ts +7 -0
- package/src/helpers/misc.ts +76 -0
- package/src/helpers/numbers.ts +117 -0
- package/src/helpers/uuid.ts +19 -0
- package/src/helpers/zones.ts +263 -0
- package/src/history.ts +186 -0
- package/src/index.ts +84 -0
- package/src/model.ts +261 -0
- package/src/plugins/autofill.ts +412 -0
- package/src/plugins/chart.ts +404 -0
- package/src/plugins/clipboard.ts +461 -0
- package/src/plugins/conditional_format.ts +445 -0
- package/src/plugins/core.ts +1502 -0
- package/src/plugins/edition.ts +157 -0
- package/src/plugins/evaluation.ts +428 -0
- package/src/plugins/figures.ts +123 -0
- package/src/plugins/formatting.ts +630 -0
- package/src/plugins/highlight.ts +187 -0
- package/src/plugins/index.ts +32 -0
- package/src/plugins/merge.ts +524 -0
- package/src/plugins/renderer.ts +571 -0
- package/src/plugins/selection.ts +562 -0
- package/src/plugins/selection_inputs.ts +326 -0
- package/src/registries/autofill_modifiers.ts +76 -0
- package/src/registries/autofill_rules.ts +98 -0
- package/src/registries/figure_registry.ts +30 -0
- package/src/registries/index.ts +7 -0
- package/src/registries/menu_items_registry.ts +110 -0
- package/src/registries/menus/cell_menu_registry.ts +79 -0
- package/src/registries/menus/col_menu_registry.ts +63 -0
- package/src/registries/menus/index.ts +6 -0
- package/src/registries/menus/menu_items_actions.ts +425 -0
- package/src/registries/menus/row_menu_registry.ts +63 -0
- package/src/registries/menus/sheet_menu_registry.ts +75 -0
- package/src/registries/menus/topbar_menu_registry.ts +204 -0
- package/src/registries/side_panel_registry.ts +26 -0
- package/src/registries/topbar_component_registry.ts +12 -0
- package/src/registry.ts +51 -0
- package/src/translation.ts +44 -0
- package/src/types/autofill.ts +48 -0
- package/src/types/chart.ts +26 -0
- package/src/types/commands.ts +716 -0
- package/src/types/conditional_formatting.ts +124 -0
- package/src/types/env.ts +13 -0
- package/src/types/functions.ts +35 -0
- package/src/types/getters.ts +103 -0
- package/src/types/index.ts +20 -0
- package/src/types/misc.ts +143 -0
- package/src/types/rendering.ts +41 -0
- package/src/types/workbook_data.ts +62 -0
- package/tests/__mocks__/uuid.ts +7 -0
- package/tests/canvas.mock.ts +34 -0
- package/tests/components/__mocks__/content_editable_helper.ts +79 -0
- package/tests/components/__mocks__/scrollbar.ts +18 -0
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
- package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
- package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
- package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
- package/tests/components/autocomplete_dropdown_test.ts +315 -0
- package/tests/components/autofill_test.ts +167 -0
- package/tests/components/bottom_bar_test.ts +262 -0
- package/tests/components/chart_side_panel_test.ts +123 -0
- package/tests/components/composer_test.ts +400 -0
- package/tests/components/context_menu_test.ts +825 -0
- package/tests/components/grid_manipulation_test.ts +163 -0
- package/tests/components/grid_test.ts +581 -0
- package/tests/components/overlay_test.ts +541 -0
- package/tests/components/selection_input_test.ts +259 -0
- package/tests/components/side_panel_test.ts +148 -0
- package/tests/components/spreadsheet_test.ts +194 -0
- package/tests/components/top_bar_test.ts +427 -0
- package/tests/data_test.ts +175 -0
- package/tests/dom_helper.ts +42 -0
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
- package/tests/formulas/compiler_test.ts +266 -0
- package/tests/formulas/composer_tokenizer_test.ts +137 -0
- package/tests/formulas/expressions_test.ts +57 -0
- package/tests/formulas/formulas_test.ts +80 -0
- package/tests/formulas/normalize_test.ts +82 -0
- package/tests/formulas/parser_test.ts +224 -0
- package/tests/formulas/range_tokenizer_test.ts +187 -0
- package/tests/formulas/tokenizer_test.ts +164 -0
- package/tests/functions/arguments_test.ts +141 -0
- package/tests/functions/dates_test.ts +1081 -0
- package/tests/functions/functions_test.ts +53 -0
- package/tests/functions/helper_test.ts +98 -0
- package/tests/functions/module_database_test.ts +311 -0
- package/tests/functions/module_date_test.ts +941 -0
- package/tests/functions/module_info_test.ts +139 -0
- package/tests/functions/module_logical_test.ts +369 -0
- package/tests/functions/module_lookup_test.ts +541 -0
- package/tests/functions/module_math_test.ts +2482 -0
- package/tests/functions/module_operators_test.ts +955 -0
- package/tests/functions/module_statistical_test.ts +2014 -0
- package/tests/functions/module_text_test.ts +667 -0
- package/tests/helpers/coordinates_test.ts +25 -0
- package/tests/helpers/misc_test.ts +95 -0
- package/tests/helpers/numbers_test.ts +196 -0
- package/tests/helpers/zones_test.ts +97 -0
- package/tests/helpers.ts +384 -0
- package/tests/menu_items_registry_test.ts +540 -0
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
- package/tests/model/plugins/chart_test.ts +562 -0
- package/tests/model_test.ts +82 -0
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
- package/tests/plugins/autofill_test.ts +457 -0
- package/tests/plugins/borders_test.ts +295 -0
- package/tests/plugins/clipboard_test.ts +1180 -0
- package/tests/plugins/conditional_formatting_test.ts +1253 -0
- package/tests/plugins/core_test.ts +614 -0
- package/tests/plugins/edition_test.ts +100 -0
- package/tests/plugins/evaluation_async_test.ts +332 -0
- package/tests/plugins/evaluation_dates_test.ts +79 -0
- package/tests/plugins/evaluation_test.ts +901 -0
- package/tests/plugins/figures_test.ts +327 -0
- package/tests/plugins/formatting_test.ts +391 -0
- package/tests/plugins/grid_manipulation_test.ts +1366 -0
- package/tests/plugins/highlight_test.ts +413 -0
- package/tests/plugins/history_test.ts +142 -0
- package/tests/plugins/import_export_test.ts +276 -0
- package/tests/plugins/merges_test.ts +490 -0
- package/tests/plugins/navigation_test.ts +181 -0
- package/tests/plugins/plugins/evaluation_test.ts +111 -0
- package/tests/plugins/renderer_test.ts +598 -0
- package/tests/plugins/resizing_test.ts +152 -0
- package/tests/plugins/selection_input_test.ts +409 -0
- package/tests/plugins/selection_test.ts +442 -0
- package/tests/plugins/sheets_test.ts +643 -0
- package/tests/plugins/style_test.ts +90 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { SpreadsheetEnv } from "../types/env";
|
|
3
|
+
const { Component } = owl;
|
|
4
|
+
const { css, xml } = owl.tags;
|
|
5
|
+
|
|
6
|
+
const COLORS = [
|
|
7
|
+
[
|
|
8
|
+
"#000000",
|
|
9
|
+
"#434343",
|
|
10
|
+
"#666666",
|
|
11
|
+
"#999999",
|
|
12
|
+
"#b7b7b7",
|
|
13
|
+
"#cccccc",
|
|
14
|
+
"#d9d9d9",
|
|
15
|
+
"#efefef",
|
|
16
|
+
"#f3f3f3",
|
|
17
|
+
"#ffffff",
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"#980000",
|
|
21
|
+
"#ff0000",
|
|
22
|
+
"#ff9900",
|
|
23
|
+
"#ffff00",
|
|
24
|
+
"#00ff00",
|
|
25
|
+
"#00ffff",
|
|
26
|
+
"#4a86e8",
|
|
27
|
+
"#0000ff",
|
|
28
|
+
"#9900ff",
|
|
29
|
+
"#ff00ff",
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
"#e6b8af",
|
|
33
|
+
"#f4cccc",
|
|
34
|
+
"#fce5cd",
|
|
35
|
+
"#fff2cc",
|
|
36
|
+
"#d9ead3",
|
|
37
|
+
"#d0e0e3",
|
|
38
|
+
"#c9daf8",
|
|
39
|
+
"#cfe2f3",
|
|
40
|
+
"#d9d2e9",
|
|
41
|
+
"#ead1dc",
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"#dd7e6b",
|
|
45
|
+
"#ea9999",
|
|
46
|
+
"#f9cb9c",
|
|
47
|
+
"#ffe599",
|
|
48
|
+
"#b6d7a8",
|
|
49
|
+
"#a2c4c9",
|
|
50
|
+
"#a4c2f4",
|
|
51
|
+
"#9fc5e8",
|
|
52
|
+
"#b4a7d6",
|
|
53
|
+
"#d5a6bd",
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"#cc4125",
|
|
57
|
+
"#e06666",
|
|
58
|
+
"#f6b26b",
|
|
59
|
+
"#ffd966",
|
|
60
|
+
"#93c47d",
|
|
61
|
+
"#76a5af",
|
|
62
|
+
"#6d9eeb",
|
|
63
|
+
"#6fa8dc",
|
|
64
|
+
"#8e7cc3",
|
|
65
|
+
"#c27ba0",
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
"#a61c00",
|
|
69
|
+
"#cc0000",
|
|
70
|
+
"#e69138",
|
|
71
|
+
"#f1c232",
|
|
72
|
+
"#6aa84f",
|
|
73
|
+
"#45818e",
|
|
74
|
+
"#3c78d8",
|
|
75
|
+
"#3d85c6",
|
|
76
|
+
"#674ea7",
|
|
77
|
+
"#a64d79",
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"#85200c",
|
|
81
|
+
"#990000",
|
|
82
|
+
"#b45f06",
|
|
83
|
+
"#bf9000",
|
|
84
|
+
"#38761d",
|
|
85
|
+
"#134f5c",
|
|
86
|
+
"#1155cc",
|
|
87
|
+
"#0b5394",
|
|
88
|
+
"#351c75",
|
|
89
|
+
"#741b47",
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
"#5b0f00",
|
|
93
|
+
"#660000",
|
|
94
|
+
"#783f04",
|
|
95
|
+
"#7f6000",
|
|
96
|
+
"#274e13",
|
|
97
|
+
"#0c343d",
|
|
98
|
+
"#1c4587",
|
|
99
|
+
"#073763",
|
|
100
|
+
"#20124d",
|
|
101
|
+
"#4c1130",
|
|
102
|
+
],
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
export class ColorPicker extends Component<any, SpreadsheetEnv> {
|
|
106
|
+
static template = xml/* xml */ `
|
|
107
|
+
<div class="o-color-picker" t-on-click="onColorClick">
|
|
108
|
+
<div class="o-color-picker-line" t-foreach="COLORS" t-as="colors" t-key="colors">
|
|
109
|
+
<t t-foreach="colors" t-as="color" t-key="color">
|
|
110
|
+
<div class="o-color-picker-line-item" t-att-data-color="color" t-attf-style="background-color:{{color}};"></div>
|
|
111
|
+
</t>
|
|
112
|
+
</div>
|
|
113
|
+
</div>`;
|
|
114
|
+
|
|
115
|
+
static style = css/* scss */ `
|
|
116
|
+
.o-color-picker {
|
|
117
|
+
position: absolute;
|
|
118
|
+
top: calc(100% + 5px);
|
|
119
|
+
left: 0;
|
|
120
|
+
z-index: 10;
|
|
121
|
+
box-shadow: 1px 2px 5px 2px rgba(51, 51, 51, 0.15);
|
|
122
|
+
background-color: white;
|
|
123
|
+
padding: 6px 0px;
|
|
124
|
+
|
|
125
|
+
.o-color-picker-line {
|
|
126
|
+
display: flex;
|
|
127
|
+
padding: 3px 6px;
|
|
128
|
+
.o-color-picker-line-item {
|
|
129
|
+
width: 18px;
|
|
130
|
+
height: 18px;
|
|
131
|
+
margin: 0px 2px;
|
|
132
|
+
border-radius: 50px;
|
|
133
|
+
border: 1px solid #c0c0c0;
|
|
134
|
+
&:hover {
|
|
135
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
136
|
+
outline: 1px solid gray;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
COLORS = COLORS;
|
|
143
|
+
|
|
144
|
+
onColorClick(ev: MouseEvent) {
|
|
145
|
+
const color = (ev.target as HTMLElement).dataset.color;
|
|
146
|
+
if (color) {
|
|
147
|
+
this.trigger("color-picked", { color });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { functionRegistry } from "../../functions/index";
|
|
3
|
+
import { Registry } from "../../registry";
|
|
4
|
+
|
|
5
|
+
const { Component, useState } = owl;
|
|
6
|
+
const { xml, css } = owl.tags;
|
|
7
|
+
const functions = functionRegistry.content;
|
|
8
|
+
|
|
9
|
+
// -----------------------------------------------------------------------------
|
|
10
|
+
// Autocomplete Value Providers
|
|
11
|
+
// -----------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
interface AutocompleteValue {
|
|
14
|
+
text: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type AutocompleteProvider = () => Promise<AutocompleteValue[]>;
|
|
19
|
+
|
|
20
|
+
const providerRegistry = new Registry<AutocompleteProvider>();
|
|
21
|
+
|
|
22
|
+
providerRegistry.add("functions", async function () {
|
|
23
|
+
return Object.keys(functions).map((key) => {
|
|
24
|
+
return {
|
|
25
|
+
text: key,
|
|
26
|
+
description: functions[key].description,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// -----------------------------------------------------------------------------
|
|
32
|
+
// Autocomplete DropDown component
|
|
33
|
+
// -----------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
const TEMPLATE = xml/* xml */ `
|
|
36
|
+
<div t-att-class="{'o-autocomplete-dropdown':state.values.length}" >
|
|
37
|
+
<t t-foreach="state.values" t-as="v" t-key="v.text">
|
|
38
|
+
<div t-att-class="{'o-autocomplete-value-focus': state.selectedIndex === v_index}" t-on-click.stop.prevent="fillValue(v_index)">
|
|
39
|
+
<div class="o-autocomplete-value" t-esc="v.text"/>
|
|
40
|
+
<div class="o-autocomplete-description" t-esc="v.description" t-if="state.selectedIndex === v_index"/>
|
|
41
|
+
</div>
|
|
42
|
+
</t>
|
|
43
|
+
</div>`;
|
|
44
|
+
|
|
45
|
+
const CSS = css/* scss */ `
|
|
46
|
+
.o-autocomplete-dropdown {
|
|
47
|
+
width: 260px;
|
|
48
|
+
margin: 4px;
|
|
49
|
+
background-color: #fff;
|
|
50
|
+
box-shadow: 0 1px 4px 3px rgba(60, 64, 67, 0.15);
|
|
51
|
+
|
|
52
|
+
& > div:hover {
|
|
53
|
+
background-color: #f2f2f2;
|
|
54
|
+
}
|
|
55
|
+
.o-autocomplete-value-focus {
|
|
56
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
& > div {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
padding: 1px 0 5px 5px;
|
|
63
|
+
.o-autocomplete-description {
|
|
64
|
+
padding: 0 0 0 5px;
|
|
65
|
+
font-size: 11px;
|
|
66
|
+
white-space: nowrap;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
text-overflow: ellipsis;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
interface Props {
|
|
75
|
+
provider: string;
|
|
76
|
+
filter?: (searchTerm: string, vals: AutocompleteValue[]) => AutocompleteValue[];
|
|
77
|
+
search: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export abstract class TextValueProvider extends Component<Props> {
|
|
81
|
+
static template = TEMPLATE;
|
|
82
|
+
static style = CSS;
|
|
83
|
+
|
|
84
|
+
state = useState({
|
|
85
|
+
values: <AutocompleteValue[]>[],
|
|
86
|
+
selectedIndex: 0,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
mounted() {
|
|
90
|
+
this.filter(this.props.search);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
willUpdateProps(nextProps: any): Promise<void> {
|
|
94
|
+
if (nextProps.search !== this.props.search) {
|
|
95
|
+
this.filter(nextProps.search);
|
|
96
|
+
}
|
|
97
|
+
return super.willUpdateProps(nextProps);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async filter(searchTerm: string) {
|
|
101
|
+
const provider = providerRegistry.get(this.props.provider);
|
|
102
|
+
let values = await provider();
|
|
103
|
+
if (this.props.filter) {
|
|
104
|
+
values = this.props.filter(searchTerm, values);
|
|
105
|
+
} else {
|
|
106
|
+
values = values
|
|
107
|
+
.filter((t) => t.text.toUpperCase().startsWith(searchTerm.toUpperCase()))
|
|
108
|
+
.sort((l, r) => (l.text < r.text ? -1 : l.text > r.text ? 1 : 0));
|
|
109
|
+
}
|
|
110
|
+
this.state.values = values.slice(0, 10);
|
|
111
|
+
this.state.selectedIndex = 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fillValue(index) {
|
|
115
|
+
this.state.selectedIndex = index;
|
|
116
|
+
this.trigger("completed", { text: this.getValueToFill() });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
moveDown() {
|
|
120
|
+
this.state.selectedIndex = (this.state.selectedIndex + 1) % this.state.values.length;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
moveUp() {
|
|
124
|
+
this.state.selectedIndex--;
|
|
125
|
+
if (this.state.selectedIndex < 0) {
|
|
126
|
+
this.state.selectedIndex = this.state.values.length - 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getValueToFill(): string | void {
|
|
131
|
+
if (this.state.values.length) {
|
|
132
|
+
return this.state.values[this.state.selectedIndex].text;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|