@odoo/o-spreadsheet 14.0.1 → 14.0.3
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/dist/o-spreadsheet.cjs.js +17880 -0
- package/dist/o-spreadsheet.d.ts +4119 -0
- package/dist/o-spreadsheet.esm.js +17845 -0
- package/dist/o-spreadsheet.iife.js +17882 -0
- package/dist/o-spreadsheet.iife.min.js +1446 -0
- package/package.json +32 -9
- package/readme.md +10 -0
- package/.eslintrc.json +0 -20
- package/.husky/post-checkout +0 -9
- package/.husky/pre-commit +0 -39
- package/.prettierignore +0 -1
- package/astToFormula.patch +0 -0
- package/demo/data.js +0 -255
- package/demo/index.html +0 -9
- package/demo/libs/Chart.bundle.js +0 -20755
- package/demo/main.js +0 -101
- package/doc/readme.md +0 -46
- package/rollup.config.js +0 -23
- package/src/base_plugin.ts +0 -102
- package/src/components/autofill.ts +0 -146
- package/src/components/bottom_bar.ts +0 -199
- package/src/components/color_picker.ts +0 -150
- package/src/components/composer/autocomplete_dropdown.ts +0 -135
- package/src/components/composer/composer.ts +0 -487
- package/src/components/composer/content_editable_helper.ts +0 -146
- package/src/components/figures/chart.ts +0 -70
- package/src/components/figures/container.ts +0 -268
- package/src/components/figures/text_figure.ts +0 -36
- package/src/components/grid.ts +0 -635
- package/src/components/helpers/dom_helpers.ts +0 -7
- package/src/components/helpers/drag_and_drop.ts +0 -17
- package/src/components/icons.ts +0 -36
- package/src/components/index.ts +0 -1
- package/src/components/menu.ts +0 -288
- package/src/components/overlay.ts +0 -457
- package/src/components/scrollbar.ts +0 -22
- package/src/components/selection_input.ts +0 -168
- package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
- package/src/components/side_panel/chart_panel.ts +0 -104
- package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
- package/src/components/side_panel/conditional_formatting.ts +0 -396
- package/src/components/side_panel/side_panel.ts +0 -127
- package/src/components/side_panel/translations_terms.ts +0 -45
- package/src/components/spreadsheet.ts +0 -198
- package/src/components/top_bar.ts +0 -535
- package/src/constants.ts +0 -26
- package/src/data.ts +0 -149
- package/src/fonts.ts +0 -41
- package/src/formulas/compiler.ts +0 -258
- package/src/formulas/composer_tokenizer.ts +0 -70
- package/src/formulas/index.ts +0 -15
- package/src/formulas/normalize.ts +0 -52
- package/src/formulas/parser.ts +0 -280
- package/src/formulas/range_tokenizer.ts +0 -97
- package/src/formulas/tokenizer.ts +0 -242
- package/src/functions/arguments.ts +0 -114
- package/src/functions/dates.ts +0 -302
- package/src/functions/helpers.ts +0 -592
- package/src/functions/index.ts +0 -52
- package/src/functions/module_database.ts +0 -282
- package/src/functions/module_date.ts +0 -743
- package/src/functions/module_info.ts +0 -69
- package/src/functions/module_logical.ts +0 -208
- package/src/functions/module_lookup.ts +0 -185
- package/src/functions/module_math.ts +0 -1252
- package/src/functions/module_operators.ts +0 -291
- package/src/functions/module_statistical.ts +0 -882
- package/src/functions/module_text.ts +0 -370
- package/src/helpers/color.ts +0 -30
- package/src/helpers/coordinates.ts +0 -71
- package/src/helpers/grid_manipulation.ts +0 -68
- package/src/helpers/index.ts +0 -7
- package/src/helpers/misc.ts +0 -76
- package/src/helpers/numbers.ts +0 -117
- package/src/helpers/uuid.ts +0 -19
- package/src/helpers/zones.ts +0 -263
- package/src/history.ts +0 -186
- package/src/index.ts +0 -84
- package/src/model.ts +0 -261
- package/src/plugins/autofill.ts +0 -412
- package/src/plugins/chart.ts +0 -404
- package/src/plugins/clipboard.ts +0 -461
- package/src/plugins/conditional_format.ts +0 -445
- package/src/plugins/core.ts +0 -1502
- package/src/plugins/edition.ts +0 -157
- package/src/plugins/evaluation.ts +0 -428
- package/src/plugins/figures.ts +0 -123
- package/src/plugins/formatting.ts +0 -630
- package/src/plugins/highlight.ts +0 -187
- package/src/plugins/index.ts +0 -32
- package/src/plugins/merge.ts +0 -524
- package/src/plugins/renderer.ts +0 -571
- package/src/plugins/selection.ts +0 -562
- package/src/plugins/selection_inputs.ts +0 -326
- package/src/registries/autofill_modifiers.ts +0 -76
- package/src/registries/autofill_rules.ts +0 -98
- package/src/registries/figure_registry.ts +0 -30
- package/src/registries/index.ts +0 -7
- package/src/registries/menu_items_registry.ts +0 -110
- package/src/registries/menus/cell_menu_registry.ts +0 -79
- package/src/registries/menus/col_menu_registry.ts +0 -63
- package/src/registries/menus/index.ts +0 -6
- package/src/registries/menus/menu_items_actions.ts +0 -425
- package/src/registries/menus/row_menu_registry.ts +0 -63
- package/src/registries/menus/sheet_menu_registry.ts +0 -75
- package/src/registries/menus/topbar_menu_registry.ts +0 -204
- package/src/registries/side_panel_registry.ts +0 -26
- package/src/registries/topbar_component_registry.ts +0 -12
- package/src/registry.ts +0 -51
- package/src/translation.ts +0 -44
- package/src/types/autofill.ts +0 -48
- package/src/types/chart.ts +0 -26
- package/src/types/commands.ts +0 -716
- package/src/types/conditional_formatting.ts +0 -124
- package/src/types/env.ts +0 -13
- package/src/types/functions.ts +0 -35
- package/src/types/getters.ts +0 -103
- package/src/types/index.ts +0 -20
- package/src/types/misc.ts +0 -143
- package/src/types/rendering.ts +0 -41
- package/src/types/workbook_data.ts +0 -62
- package/tests/__mocks__/uuid.ts +0 -7
- package/tests/canvas.mock.ts +0 -34
- package/tests/components/__mocks__/content_editable_helper.ts +0 -79
- package/tests/components/__mocks__/scrollbar.ts +0 -18
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
- package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
- package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
- package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
- package/tests/components/autocomplete_dropdown_test.ts +0 -315
- package/tests/components/autofill_test.ts +0 -167
- package/tests/components/bottom_bar_test.ts +0 -262
- package/tests/components/chart_side_panel_test.ts +0 -123
- package/tests/components/composer_test.ts +0 -400
- package/tests/components/context_menu_test.ts +0 -825
- package/tests/components/grid_manipulation_test.ts +0 -163
- package/tests/components/grid_test.ts +0 -581
- package/tests/components/overlay_test.ts +0 -541
- package/tests/components/selection_input_test.ts +0 -259
- package/tests/components/side_panel_test.ts +0 -148
- package/tests/components/spreadsheet_test.ts +0 -194
- package/tests/components/top_bar_test.ts +0 -427
- package/tests/data_test.ts +0 -175
- package/tests/dom_helper.ts +0 -42
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
- package/tests/formulas/compiler_test.ts +0 -266
- package/tests/formulas/composer_tokenizer_test.ts +0 -137
- package/tests/formulas/expressions_test.ts +0 -57
- package/tests/formulas/formulas_test.ts +0 -80
- package/tests/formulas/normalize_test.ts +0 -82
- package/tests/formulas/parser_test.ts +0 -224
- package/tests/formulas/range_tokenizer_test.ts +0 -187
- package/tests/formulas/tokenizer_test.ts +0 -164
- package/tests/functions/arguments_test.ts +0 -141
- package/tests/functions/dates_test.ts +0 -1081
- package/tests/functions/functions_test.ts +0 -53
- package/tests/functions/helper_test.ts +0 -98
- package/tests/functions/module_database_test.ts +0 -311
- package/tests/functions/module_date_test.ts +0 -941
- package/tests/functions/module_info_test.ts +0 -139
- package/tests/functions/module_logical_test.ts +0 -369
- package/tests/functions/module_lookup_test.ts +0 -541
- package/tests/functions/module_math_test.ts +0 -2482
- package/tests/functions/module_operators_test.ts +0 -955
- package/tests/functions/module_statistical_test.ts +0 -2014
- package/tests/functions/module_text_test.ts +0 -667
- package/tests/helpers/coordinates_test.ts +0 -25
- package/tests/helpers/misc_test.ts +0 -95
- package/tests/helpers/numbers_test.ts +0 -196
- package/tests/helpers/zones_test.ts +0 -97
- package/tests/helpers.ts +0 -384
- package/tests/menu_items_registry_test.ts +0 -540
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
- package/tests/model/plugins/chart_test.ts +0 -562
- package/tests/model_test.ts +0 -82
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
- package/tests/plugins/autofill_test.ts +0 -457
- package/tests/plugins/borders_test.ts +0 -295
- package/tests/plugins/clipboard_test.ts +0 -1180
- package/tests/plugins/conditional_formatting_test.ts +0 -1253
- package/tests/plugins/core_test.ts +0 -614
- package/tests/plugins/edition_test.ts +0 -100
- package/tests/plugins/evaluation_async_test.ts +0 -332
- package/tests/plugins/evaluation_dates_test.ts +0 -79
- package/tests/plugins/evaluation_test.ts +0 -901
- package/tests/plugins/figures_test.ts +0 -327
- package/tests/plugins/formatting_test.ts +0 -391
- package/tests/plugins/grid_manipulation_test.ts +0 -1366
- package/tests/plugins/highlight_test.ts +0 -413
- package/tests/plugins/history_test.ts +0 -142
- package/tests/plugins/import_export_test.ts +0 -276
- package/tests/plugins/merges_test.ts +0 -490
- package/tests/plugins/navigation_test.ts +0 -181
- package/tests/plugins/plugins/evaluation_test.ts +0 -111
- package/tests/plugins/renderer_test.ts +0 -598
- package/tests/plugins/resizing_test.ts +0 -152
- package/tests/plugins/selection_input_test.ts +0 -409
- package/tests/plugins/selection_test.ts +0 -442
- package/tests/plugins/sheets_test.ts +0 -643
- package/tests/plugins/style_test.ts +0 -90
- package/tsconfig.json +0 -22
|
@@ -1,487 +0,0 @@
|
|
|
1
|
-
import * as owl from "@odoo/owl";
|
|
2
|
-
import { fontSizeMap } from "../../fonts";
|
|
3
|
-
import { composerTokenize, EnrichedToken, rangeReference } from "../../formulas/index";
|
|
4
|
-
import { colors, DEBUG, getComposerSheetName } from "../../helpers/index";
|
|
5
|
-
import { Rect, SpreadsheetEnv, Zone } from "../../types/index";
|
|
6
|
-
import { TextValueProvider } from "./autocomplete_dropdown";
|
|
7
|
-
import { ContentEditableHelper } from "./content_editable_helper";
|
|
8
|
-
|
|
9
|
-
const { Component } = owl;
|
|
10
|
-
const { useRef, useState } = owl.hooks;
|
|
11
|
-
const { xml, css } = owl.tags;
|
|
12
|
-
|
|
13
|
-
export const FunctionColor = "#4a4e4d";
|
|
14
|
-
export const OperatorColor = "#3da4ab";
|
|
15
|
-
export const StringColor = "#f6cd61";
|
|
16
|
-
export const NumberColor = "#02c39a";
|
|
17
|
-
export const MatchingParenColor = "pink";
|
|
18
|
-
|
|
19
|
-
const tokenColor = {
|
|
20
|
-
OPERATOR: OperatorColor,
|
|
21
|
-
NUMBER: NumberColor,
|
|
22
|
-
STRING: StringColor,
|
|
23
|
-
BOOLEAN: NumberColor,
|
|
24
|
-
FUNCTION: FunctionColor,
|
|
25
|
-
DEBUGGER: OperatorColor,
|
|
26
|
-
LEFT_PAREN: OperatorColor,
|
|
27
|
-
RIGHT_PAREN: OperatorColor,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const TEMPLATE = xml/* xml */ `
|
|
31
|
-
<div class="o-composer-container" t-att-style="containerStyle">
|
|
32
|
-
<div class="o-composer"
|
|
33
|
-
t-att-style="composerStyle"
|
|
34
|
-
t-ref="o_composer"
|
|
35
|
-
tabindex="1"
|
|
36
|
-
contenteditable="true"
|
|
37
|
-
spellcheck="false"
|
|
38
|
-
|
|
39
|
-
t-on-keydown="onKeydown"
|
|
40
|
-
t-on-input="onInput"
|
|
41
|
-
t-on-keyup="onKeyup"
|
|
42
|
-
|
|
43
|
-
t-on-blur="saveSelection"
|
|
44
|
-
t-on-click="onClick"
|
|
45
|
-
/>
|
|
46
|
-
<TextValueProvider
|
|
47
|
-
t-if="autoCompleteState.showProvider"
|
|
48
|
-
t-ref="o_autocomplete_provider"
|
|
49
|
-
search="autoCompleteState.search"
|
|
50
|
-
provider="autoCompleteState.provider"
|
|
51
|
-
t-on-completed="onCompleted"
|
|
52
|
-
/>
|
|
53
|
-
</div>
|
|
54
|
-
`;
|
|
55
|
-
const CSS = css/* scss */ `
|
|
56
|
-
.o-composer-container {
|
|
57
|
-
box-sizing: border-box;
|
|
58
|
-
position: absolute;
|
|
59
|
-
padding: 0;
|
|
60
|
-
margin: 0;
|
|
61
|
-
border: 0;
|
|
62
|
-
z-index: 5;
|
|
63
|
-
.o-composer {
|
|
64
|
-
caret-color: black;
|
|
65
|
-
box-sizing: border-box;
|
|
66
|
-
background-color: white;
|
|
67
|
-
padding-left: 2px;
|
|
68
|
-
padding-right: 2px;
|
|
69
|
-
border: 1.6px solid #3266ca;
|
|
70
|
-
white-space: nowrap;
|
|
71
|
-
&:focus {
|
|
72
|
-
outline: none;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
|
|
78
|
-
export class Composer extends Component<any, SpreadsheetEnv> {
|
|
79
|
-
static template = TEMPLATE;
|
|
80
|
-
static style = CSS;
|
|
81
|
-
static components = { TextValueProvider };
|
|
82
|
-
|
|
83
|
-
composerRef = useRef("o_composer");
|
|
84
|
-
autoCompleteRef = useRef("o_autocomplete_provider");
|
|
85
|
-
|
|
86
|
-
getters = this.env.getters;
|
|
87
|
-
dispatch = this.env.dispatch;
|
|
88
|
-
|
|
89
|
-
zone: Zone;
|
|
90
|
-
rect: Rect;
|
|
91
|
-
|
|
92
|
-
selectionEnd: number = 0;
|
|
93
|
-
selectionStart: number = 0;
|
|
94
|
-
contentHelper: ContentEditableHelper;
|
|
95
|
-
|
|
96
|
-
autoCompleteState = useState({
|
|
97
|
-
showProvider: false,
|
|
98
|
-
provider: "functions",
|
|
99
|
-
search: "",
|
|
100
|
-
});
|
|
101
|
-
tokenAtCursor: EnrichedToken | void = undefined;
|
|
102
|
-
|
|
103
|
-
// we can't allow input events to be triggered while we remove and add back the content of the composer in processContent
|
|
104
|
-
shouldProcessInputEvents: boolean = false;
|
|
105
|
-
// a composer edits a single cell. After that, it is done and should not
|
|
106
|
-
// modify the model anymore.
|
|
107
|
-
isDone: boolean = false;
|
|
108
|
-
refSelectionStart: number = 0;
|
|
109
|
-
tokens: EnrichedToken[] = [];
|
|
110
|
-
|
|
111
|
-
keyMapping: { [key: string]: Function } = {
|
|
112
|
-
Enter: this.processEnterKey,
|
|
113
|
-
Escape: this.processEscapeKey,
|
|
114
|
-
Tab: (ev: KeyboardEvent) => this.processTabKey(ev),
|
|
115
|
-
F2: () => console.warn("Not implemented"),
|
|
116
|
-
F4: () => console.warn("Not implemented"),
|
|
117
|
-
ArrowUp: this.processArrowKeys,
|
|
118
|
-
ArrowDown: this.processArrowKeys,
|
|
119
|
-
ArrowLeft: this.processArrowKeys,
|
|
120
|
-
ArrowRight: this.processArrowKeys,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
constructor() {
|
|
124
|
-
super(...arguments);
|
|
125
|
-
this.contentHelper = new ContentEditableHelper(this.composerRef.el!);
|
|
126
|
-
const [col, row] = this.getters.getPosition();
|
|
127
|
-
this.zone = this.getters.expandZone({ left: col, right: col, top: row, bottom: row });
|
|
128
|
-
this.rect = this.getters.getRect(this.zone, this.props.viewport);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
mounted() {
|
|
132
|
-
DEBUG.composer = this;
|
|
133
|
-
|
|
134
|
-
const el = this.composerRef.el!;
|
|
135
|
-
|
|
136
|
-
this.contentHelper.updateEl(el);
|
|
137
|
-
const currentContent = this.getters.getCurrentContent();
|
|
138
|
-
if (currentContent) {
|
|
139
|
-
this.contentHelper.insertText(currentContent);
|
|
140
|
-
this.contentHelper.selectRange(currentContent.length, currentContent.length);
|
|
141
|
-
}
|
|
142
|
-
this.processContent();
|
|
143
|
-
|
|
144
|
-
el.style.width = (Math.max(el.scrollWidth + 10, this.rect[2] + 0.5) + "px") as string;
|
|
145
|
-
el.style.height = (this.rect[3] + 0.5 + "px") as string;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
willUnmount(): void {
|
|
149
|
-
delete DEBUG.composer;
|
|
150
|
-
this.trigger("composer-unmounted");
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
get containerStyle() {
|
|
154
|
-
const style = this.getters.getCurrentStyle();
|
|
155
|
-
const [x, y, , height] = this.rect;
|
|
156
|
-
const weight = `font-weight:${style.bold ? "bold" : 500};`;
|
|
157
|
-
const italic = style.italic ? `font-style: italic;` : ``;
|
|
158
|
-
const strikethrough = style.strikethrough ? `text-decoration:line-through;` : ``;
|
|
159
|
-
return `left: ${x - 1}px;
|
|
160
|
-
top:${y}px;
|
|
161
|
-
height:${height}px;
|
|
162
|
-
font-size:${fontSizeMap[style.fontSize || 10]}px;
|
|
163
|
-
${weight}${italic}${strikethrough}`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
get composerStyle() {
|
|
167
|
-
const style = this.getters.getCurrentStyle();
|
|
168
|
-
const cell = this.getters.getActiveCell() || { type: "text" };
|
|
169
|
-
const height = this.rect[3];
|
|
170
|
-
const align = "align" in style ? style.align : cell.type === "number" ? "right" : "left";
|
|
171
|
-
return `text-align:${align};
|
|
172
|
-
line-height:${height - 1.5}px;`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// ---------------------------------------------------------------------------
|
|
176
|
-
// Handlers
|
|
177
|
-
// ---------------------------------------------------------------------------
|
|
178
|
-
|
|
179
|
-
processArrowKeys(ev: KeyboardEvent) {
|
|
180
|
-
if (this.getters.getEditionMode() === "selecting") {
|
|
181
|
-
ev.preventDefault();
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
ev.stopPropagation();
|
|
185
|
-
const autoCompleteComp = this.autoCompleteRef.comp as TextValueProvider;
|
|
186
|
-
if (
|
|
187
|
-
["ArrowUp", "ArrowDown"].includes(ev.key) &&
|
|
188
|
-
this.autoCompleteState.showProvider &&
|
|
189
|
-
autoCompleteComp
|
|
190
|
-
) {
|
|
191
|
-
ev.preventDefault();
|
|
192
|
-
if (ev.key === "ArrowUp") {
|
|
193
|
-
autoCompleteComp.moveUp();
|
|
194
|
-
} else {
|
|
195
|
-
autoCompleteComp.moveDown();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
processTabKey(ev: KeyboardEvent) {
|
|
201
|
-
ev.preventDefault();
|
|
202
|
-
ev.stopPropagation();
|
|
203
|
-
const autoCompleteComp = this.autoCompleteRef.comp as TextValueProvider;
|
|
204
|
-
if (this.autoCompleteState.showProvider && autoCompleteComp) {
|
|
205
|
-
const autoCompleteValue = autoCompleteComp.getValueToFill();
|
|
206
|
-
if (autoCompleteValue) {
|
|
207
|
-
this.autoComplete(autoCompleteValue);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
} else {
|
|
211
|
-
// when completing with tab, if there is no value to complete, the active cell will be moved to the right.
|
|
212
|
-
// we can't let the model think that it is for a ref selection.
|
|
213
|
-
// todo: check if this can be removed someday
|
|
214
|
-
this.dispatch("STOP_COMPOSER_SELECTION");
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const deltaX = ev.shiftKey ? -1 : 1;
|
|
218
|
-
this.isDone = true;
|
|
219
|
-
this.dispatch("MOVE_POSITION", { deltaX, deltaY: 0 });
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
processEnterKey(ev: KeyboardEvent) {
|
|
223
|
-
ev.preventDefault();
|
|
224
|
-
ev.stopPropagation();
|
|
225
|
-
const autoCompleteComp = this.autoCompleteRef.comp as TextValueProvider;
|
|
226
|
-
if (this.autoCompleteState.showProvider && autoCompleteComp) {
|
|
227
|
-
const autoCompleteValue = autoCompleteComp.getValueToFill();
|
|
228
|
-
if (autoCompleteValue) {
|
|
229
|
-
this.autoComplete(autoCompleteValue);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
this.dispatch("STOP_EDITION");
|
|
234
|
-
this.dispatch("MOVE_POSITION", {
|
|
235
|
-
deltaX: 0,
|
|
236
|
-
deltaY: ev.shiftKey ? -1 : 1,
|
|
237
|
-
});
|
|
238
|
-
this.isDone = true;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
processEscapeKey() {
|
|
242
|
-
this.dispatch("STOP_EDITION", { cancel: true });
|
|
243
|
-
this.isDone = true;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
onKeydown(ev: KeyboardEvent) {
|
|
247
|
-
let handler = this.keyMapping[ev.key];
|
|
248
|
-
if (handler) {
|
|
249
|
-
return handler.call(this, ev);
|
|
250
|
-
}
|
|
251
|
-
ev.stopPropagation();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/*
|
|
255
|
-
* Triggered automatically by the content-editable between the keydown and key up
|
|
256
|
-
* */
|
|
257
|
-
onInput(ev: KeyboardEvent) {
|
|
258
|
-
if (this.isDone || !this.shouldProcessInputEvents) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const el = this.composerRef.el! as HTMLInputElement;
|
|
262
|
-
if (el.clientWidth !== el.scrollWidth) {
|
|
263
|
-
el.style.width = `${el.scrollWidth + 20}px`;
|
|
264
|
-
}
|
|
265
|
-
const content = el.childNodes.length ? el.textContent! : "";
|
|
266
|
-
this.dispatch("SET_CURRENT_CONTENT", { content });
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
onKeyup(ev: KeyboardEvent) {
|
|
270
|
-
if (
|
|
271
|
-
this.isDone ||
|
|
272
|
-
[
|
|
273
|
-
"Control",
|
|
274
|
-
"Shift",
|
|
275
|
-
"ArrowUp",
|
|
276
|
-
"ArrowDown",
|
|
277
|
-
"ArrowLeft",
|
|
278
|
-
"ArrowRight",
|
|
279
|
-
"Tab",
|
|
280
|
-
"Enter",
|
|
281
|
-
].includes(ev.key)
|
|
282
|
-
) {
|
|
283
|
-
// already processed in keydown
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
ev.preventDefault();
|
|
287
|
-
ev.stopPropagation();
|
|
288
|
-
|
|
289
|
-
// reset the state of the ref selector and autocomplete for safety.
|
|
290
|
-
// They will be set correctly if needed in `processTokenAtCursor`
|
|
291
|
-
this.autoCompleteState.showProvider = false;
|
|
292
|
-
this.autoCompleteState.search = "";
|
|
293
|
-
this.dispatch("STOP_COMPOSER_SELECTION");
|
|
294
|
-
if (ev.ctrlKey && ev.key === " ") {
|
|
295
|
-
this.autoCompleteState.showProvider = true;
|
|
296
|
-
} else {
|
|
297
|
-
this.processContent();
|
|
298
|
-
this.processTokenAtCursor();
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
onClick(ev: MouseEvent) {
|
|
303
|
-
ev.stopPropagation();
|
|
304
|
-
this.processContent();
|
|
305
|
-
this.processTokenAtCursor();
|
|
306
|
-
}
|
|
307
|
-
onCompleted(ev: CustomEvent) {
|
|
308
|
-
this.autoComplete(ev.detail.text);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// ---------------------------------------------------------------------------
|
|
312
|
-
// Private
|
|
313
|
-
// ---------------------------------------------------------------------------
|
|
314
|
-
|
|
315
|
-
processContent() {
|
|
316
|
-
this.shouldProcessInputEvents = false;
|
|
317
|
-
let value = this.getters.getCurrentContent();
|
|
318
|
-
this.tokenAtCursor = undefined;
|
|
319
|
-
if (value.startsWith("=")) {
|
|
320
|
-
this.saveSelection();
|
|
321
|
-
this.contentHelper.removeAll(); // remove the content of the composer, to be added just after
|
|
322
|
-
this.contentHelper.selectRange(0, 0); // move the cursor inside the composer at 0 0.
|
|
323
|
-
this.dispatch("REMOVE_ALL_HIGHLIGHTS"); //cleanup highlights for references
|
|
324
|
-
|
|
325
|
-
const refUsed = {};
|
|
326
|
-
let lastUsedColorIndex = 0;
|
|
327
|
-
|
|
328
|
-
this.tokens = composerTokenize(value);
|
|
329
|
-
if (this.selectionStart === this.selectionEnd && this.selectionEnd === 0) {
|
|
330
|
-
this.tokenAtCursor = undefined;
|
|
331
|
-
} else {
|
|
332
|
-
this.tokenAtCursor = this.tokens.find(
|
|
333
|
-
(t) => t.start <= this.selectionStart! && t.end >= this.selectionEnd!
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
for (let token of this.tokens) {
|
|
337
|
-
switch (token.type) {
|
|
338
|
-
case "OPERATOR":
|
|
339
|
-
case "NUMBER":
|
|
340
|
-
case "FUNCTION":
|
|
341
|
-
case "COMMA":
|
|
342
|
-
case "BOOLEAN":
|
|
343
|
-
this.contentHelper.insertText(token.value, tokenColor[token.type]);
|
|
344
|
-
break;
|
|
345
|
-
case "SYMBOL":
|
|
346
|
-
let value = token.value;
|
|
347
|
-
const [xc, sheet] = value.split("!").reverse();
|
|
348
|
-
if (rangeReference.test(xc)) {
|
|
349
|
-
const refSanitized =
|
|
350
|
-
getComposerSheetName(
|
|
351
|
-
sheet
|
|
352
|
-
? `${sheet}`
|
|
353
|
-
: `${this.getters.getSheetName(this.getters.getEditionSheet())}`
|
|
354
|
-
) +
|
|
355
|
-
"!" +
|
|
356
|
-
xc.replace(/\$/g, "");
|
|
357
|
-
if (!refUsed[refSanitized]) {
|
|
358
|
-
refUsed[refSanitized] = colors[lastUsedColorIndex];
|
|
359
|
-
lastUsedColorIndex = ++lastUsedColorIndex % colors.length;
|
|
360
|
-
}
|
|
361
|
-
this.contentHelper.insertText(value, refUsed[refSanitized]);
|
|
362
|
-
} else {
|
|
363
|
-
this.contentHelper.insertText(value);
|
|
364
|
-
}
|
|
365
|
-
break;
|
|
366
|
-
case "LEFT_PAREN":
|
|
367
|
-
case "RIGHT_PAREN":
|
|
368
|
-
// Compute the matching parenthesis
|
|
369
|
-
if (
|
|
370
|
-
this.tokenAtCursor &&
|
|
371
|
-
["LEFT_PAREN", "RIGHT_PAREN"].includes(this.tokenAtCursor.type) &&
|
|
372
|
-
this.tokenAtCursor.parenIndex &&
|
|
373
|
-
this.tokenAtCursor.parenIndex === token.parenIndex
|
|
374
|
-
) {
|
|
375
|
-
this.contentHelper.insertText(token.value, MatchingParenColor);
|
|
376
|
-
} else {
|
|
377
|
-
this.contentHelper.insertText(token.value);
|
|
378
|
-
}
|
|
379
|
-
break;
|
|
380
|
-
default:
|
|
381
|
-
this.contentHelper.insertText(token.value);
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// Put the cursor back where it was
|
|
387
|
-
this.contentHelper.selectRange(this.selectionStart, this.selectionEnd);
|
|
388
|
-
if (Object.keys(refUsed).length) {
|
|
389
|
-
this.dispatch("ADD_HIGHLIGHTS", { ranges: refUsed });
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
this.shouldProcessInputEvents = true;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Compute the state of the composer from the tokenAtCursor.
|
|
397
|
-
* If the token is a bool, function or symbol we have to initialize the autocomplete engine.
|
|
398
|
-
* If it's a comma, left_paren or operator we have to initialize the range selection.
|
|
399
|
-
*/
|
|
400
|
-
processTokenAtCursor() {
|
|
401
|
-
if (!this.tokenAtCursor) {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
if (["BOOLEAN", "FUNCTION", "SYMBOL"].includes(this.tokenAtCursor.type)) {
|
|
405
|
-
if (this.tokenAtCursor.value.length > 0) {
|
|
406
|
-
this.autoCompleteState.search = this.tokenAtCursor.value;
|
|
407
|
-
this.autoCompleteState.showProvider = true;
|
|
408
|
-
}
|
|
409
|
-
} else if (["COMMA", "LEFT_PAREN", "OPERATOR", "SPACE"].includes(this.tokenAtCursor.type)) {
|
|
410
|
-
// we need to reset the anchor of the selection to the active cell, so the next Arrow key down
|
|
411
|
-
// is relative the to the cell we edit
|
|
412
|
-
this.dispatch("START_COMPOSER_SELECTION");
|
|
413
|
-
// We set this variable to store the start of the selection, to allow
|
|
414
|
-
// to replace selections (ex: select twice a cell should only be added
|
|
415
|
-
// once)
|
|
416
|
-
this.refSelectionStart = this.selectionStart;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
addText(text: string) {
|
|
421
|
-
this.contentHelper.selectRange(this.selectionStart, this.selectionEnd);
|
|
422
|
-
this.contentHelper.insertText(text);
|
|
423
|
-
this.selectionStart = this.selectionEnd = this.selectionStart + text.length;
|
|
424
|
-
this.contentHelper.selectRange(this.selectionStart, this.selectionEnd);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
addTextFromSelection() {
|
|
428
|
-
const zone = this.getters.getSelectedZones()[0];
|
|
429
|
-
let selection = this.getters.zoneToXC(zone);
|
|
430
|
-
if (this.refSelectionStart) {
|
|
431
|
-
this.selectionStart = this.refSelectionStart;
|
|
432
|
-
}
|
|
433
|
-
if (this.getters.getEditionSheet() !== this.getters.getActiveSheet()) {
|
|
434
|
-
const sheetName = getComposerSheetName(
|
|
435
|
-
this.getters.getSheetName(this.getters.getActiveSheet())!
|
|
436
|
-
);
|
|
437
|
-
selection = `${sheetName}!${selection}`;
|
|
438
|
-
}
|
|
439
|
-
this.addText(selection);
|
|
440
|
-
this.processContent();
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
autoComplete(value: string) {
|
|
444
|
-
this.saveSelection();
|
|
445
|
-
if (value) {
|
|
446
|
-
if (this.tokenAtCursor) {
|
|
447
|
-
let start = this.tokenAtCursor.end;
|
|
448
|
-
let end = this.tokenAtCursor.end;
|
|
449
|
-
|
|
450
|
-
if (["SYMBOL", "FUNCTION"].includes(this.tokenAtCursor.type)) {
|
|
451
|
-
start = this.tokenAtCursor.start;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (this.autoCompleteState.provider && this.tokens.length) {
|
|
455
|
-
value += "(";
|
|
456
|
-
|
|
457
|
-
const currentTokenIndex = this.tokens
|
|
458
|
-
.map((token) => token.start)
|
|
459
|
-
.indexOf(this.tokenAtCursor.start);
|
|
460
|
-
if (currentTokenIndex + 1 < this.tokens.length) {
|
|
461
|
-
const nextToken = this.tokens[currentTokenIndex + 1];
|
|
462
|
-
if (nextToken.type === "LEFT_PAREN") {
|
|
463
|
-
end++;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
this.selectionStart = start;
|
|
468
|
-
this.selectionEnd = end;
|
|
469
|
-
}
|
|
470
|
-
this.addText(value);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
this.autoCompleteState.search = "";
|
|
474
|
-
this.autoCompleteState.showProvider = false;
|
|
475
|
-
this.processContent();
|
|
476
|
-
this.processTokenAtCursor();
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Save the current selection
|
|
481
|
-
*/
|
|
482
|
-
saveSelection() {
|
|
483
|
-
const selection = this.contentHelper.getCurrentSelection();
|
|
484
|
-
this.selectionStart = selection.start;
|
|
485
|
-
this.selectionEnd = selection.end;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
export class ContentEditableHelper {
|
|
2
|
-
el: HTMLElement;
|
|
3
|
-
constructor(el: HTMLElement | null) {
|
|
4
|
-
this.el = el!;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
updateEl(el: HTMLElement) {
|
|
8
|
-
this.el = el;
|
|
9
|
-
this.el.focus();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* select the text at position start to end, no matter the children
|
|
14
|
-
*/
|
|
15
|
-
selectRange(start: number, end: number) {
|
|
16
|
-
let selection = window.getSelection()!;
|
|
17
|
-
this.removeSelection();
|
|
18
|
-
let range = document.createRange();
|
|
19
|
-
if (start == end && start === 0) {
|
|
20
|
-
range.setStart(this.el, 0);
|
|
21
|
-
range.setEnd(this.el, 0);
|
|
22
|
-
} else {
|
|
23
|
-
if (start < 0 || end > this.el!.textContent!.length) {
|
|
24
|
-
console.warn(
|
|
25
|
-
`wrong selection asked start ${start}, end ${end}, text content length ${
|
|
26
|
-
this.el!.textContent!.length
|
|
27
|
-
}`
|
|
28
|
-
);
|
|
29
|
-
if (start < 0) start = 0;
|
|
30
|
-
if (end > this.el!.textContent!.length) end = this.el!.textContent!.length;
|
|
31
|
-
}
|
|
32
|
-
let startNode = this.findChildAtCharacterIndex(start);
|
|
33
|
-
let endNode = this.findChildAtCharacterIndex(end);
|
|
34
|
-
range.setStart(startNode.node, startNode.offset);
|
|
35
|
-
range.setEnd(endNode.node, endNode.offset);
|
|
36
|
-
}
|
|
37
|
-
selection.addRange(range);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* finds the dom element that contains the character at `offset`
|
|
42
|
-
*/
|
|
43
|
-
private findChildAtCharacterIndex(offset: number): { node: Node; offset: number } {
|
|
44
|
-
let it = this.iterateChildren(this.el);
|
|
45
|
-
let current, previous;
|
|
46
|
-
let usedCharacters = offset;
|
|
47
|
-
do {
|
|
48
|
-
current = it.next();
|
|
49
|
-
if (!current.done && !current.value.hasChildNodes()) {
|
|
50
|
-
if (current.value.textContent && current.value.textContent.length < usedCharacters) {
|
|
51
|
-
usedCharacters -= current.value.textContent.length;
|
|
52
|
-
} else {
|
|
53
|
-
it.return(current.value);
|
|
54
|
-
}
|
|
55
|
-
previous = current.value;
|
|
56
|
-
}
|
|
57
|
-
} while (!current.done);
|
|
58
|
-
|
|
59
|
-
if (current.value) {
|
|
60
|
-
return { node: current.value, offset: usedCharacters };
|
|
61
|
-
}
|
|
62
|
-
return { node: previous, offset: usedCharacters };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Iterate over the dom tree starting at `el` and over all the children depth first.
|
|
67
|
-
* */
|
|
68
|
-
private *iterateChildren(el): Generator<Node> {
|
|
69
|
-
yield el;
|
|
70
|
-
if (el.hasChildNodes()) {
|
|
71
|
-
for (let child of el.childNodes) {
|
|
72
|
-
yield* this.iterateChildren(child);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* insert text at the current selection point. If a selection of 1 or more elements is done,
|
|
79
|
-
* the selection is replaced by the text to be inserted
|
|
80
|
-
* */
|
|
81
|
-
insertText(value: string, color: string = "#000") {
|
|
82
|
-
document.execCommand("foreColor", false, color);
|
|
83
|
-
document.execCommand("insertText", false, value);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* remove the current selection of the user
|
|
88
|
-
* */
|
|
89
|
-
removeSelection() {
|
|
90
|
-
let selection = window.getSelection()!;
|
|
91
|
-
selection.removeAllRanges();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
removeAll() {
|
|
95
|
-
if (this.el) {
|
|
96
|
-
while (this.el.firstChild) {
|
|
97
|
-
this.el.removeChild(this.el.firstChild);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* finds the indexes of the current selection.
|
|
104
|
-
* */
|
|
105
|
-
getCurrentSelection() {
|
|
106
|
-
let { startElement, endElement, startSelectionOffset, endSelectionOffset } =
|
|
107
|
-
this.getStartAndEndSelection();
|
|
108
|
-
let startSizeBefore = this.findSizeBeforeElement(startElement!);
|
|
109
|
-
let endSizeBefore = this.findSizeBeforeElement(endElement!);
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
start: startSizeBefore + startSelectionOffset,
|
|
113
|
-
end: endSizeBefore + endSelectionOffset,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private findSizeBeforeElement(nodeToFind: Node): number {
|
|
118
|
-
let it = this.iterateChildren(this.el);
|
|
119
|
-
let usedCharacters = 0;
|
|
120
|
-
let current = it.next();
|
|
121
|
-
|
|
122
|
-
while (!current.done && current.value !== nodeToFind) {
|
|
123
|
-
if (!current.value.hasChildNodes()) {
|
|
124
|
-
if (current.value.textContent) {
|
|
125
|
-
usedCharacters += current.value.textContent.length;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
current = it.next();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return usedCharacters;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private getStartAndEndSelection() {
|
|
135
|
-
const selection = document.getSelection()!;
|
|
136
|
-
|
|
137
|
-
const range = selection.getRangeAt(0);
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
startElement: range.startContainer,
|
|
141
|
-
startSelectionOffset: range.startOffset,
|
|
142
|
-
endElement: range.endContainer,
|
|
143
|
-
endSelectionOffset: range.endOffset,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Component, hooks, tags } from "@odoo/owl";
|
|
2
|
-
import Chart from "chart.js";
|
|
3
|
-
import { ChartDefinition, Figure, SpreadsheetEnv } from "../../types";
|
|
4
|
-
|
|
5
|
-
const { xml, css } = tags;
|
|
6
|
-
const { useRef } = hooks;
|
|
7
|
-
|
|
8
|
-
const TEMPLATE = xml/* xml */ `
|
|
9
|
-
<div class="o-chart-container">
|
|
10
|
-
<canvas t-ref="graphContainer" />
|
|
11
|
-
</div>`;
|
|
12
|
-
|
|
13
|
-
// -----------------------------------------------------------------------------
|
|
14
|
-
// STYLE
|
|
15
|
-
// -----------------------------------------------------------------------------
|
|
16
|
-
const CSS = css/* scss */ `
|
|
17
|
-
.o-chart-container {
|
|
18
|
-
width: 100%;
|
|
19
|
-
height: 100%;
|
|
20
|
-
position: relative;
|
|
21
|
-
|
|
22
|
-
> canvas {
|
|
23
|
-
background-color: white;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
interface Props {
|
|
29
|
-
figure: Figure<ChartDefinition>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class ChartFigure extends Component<Props, SpreadsheetEnv> {
|
|
33
|
-
static template = TEMPLATE;
|
|
34
|
-
static style = CSS;
|
|
35
|
-
static components = {};
|
|
36
|
-
|
|
37
|
-
canvas = useRef("graphContainer");
|
|
38
|
-
private chart?: Chart;
|
|
39
|
-
|
|
40
|
-
mounted() {
|
|
41
|
-
this.createChart();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
patched() {
|
|
45
|
-
const figure = this.props.figure;
|
|
46
|
-
const chartData = this.env.getters.getChartRuntime(figure.id);
|
|
47
|
-
if (chartData) {
|
|
48
|
-
if (chartData.data && chartData.data.datasets) {
|
|
49
|
-
Object.assign(this.chart!.data!.datasets, chartData.data.datasets);
|
|
50
|
-
Object.assign(this.chart!.data.labels, chartData.data.labels);
|
|
51
|
-
} else {
|
|
52
|
-
this.chart!.data.datasets = undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.chart!.update({ duration: 0 });
|
|
56
|
-
} else {
|
|
57
|
-
this.chart && this.chart.destroy();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private createChart() {
|
|
62
|
-
const figure = this.props.figure;
|
|
63
|
-
const charData = this.env.getters.getChartRuntime(figure.id);
|
|
64
|
-
if (charData) {
|
|
65
|
-
const canvas = this.canvas.el as HTMLCanvasElement;
|
|
66
|
-
const ctx = canvas.getContext("2d")!;
|
|
67
|
-
this.chart = new window.Chart(ctx, charData);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|