@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,457 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { HEADER_HEIGHT, HEADER_WIDTH, MIN_COL_WIDTH, MIN_ROW_HEIGHT } from "../constants";
|
|
3
|
+
import { Col, Row, SpreadsheetEnv, Viewport } from "../types/index";
|
|
4
|
+
import { ContextMenuType } from "./grid";
|
|
5
|
+
import { startDnd } from "./helpers/drag_and_drop";
|
|
6
|
+
|
|
7
|
+
const { Component } = owl;
|
|
8
|
+
const { xml, css } = owl.tags;
|
|
9
|
+
const { useState } = owl.hooks;
|
|
10
|
+
|
|
11
|
+
// -----------------------------------------------------------------------------
|
|
12
|
+
// Resizer component
|
|
13
|
+
// -----------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
abstract class AbstractResizer extends Component<any, SpreadsheetEnv> {
|
|
16
|
+
PADDING: number = 0;
|
|
17
|
+
MAX_SIZE_MARGIN: number = 0;
|
|
18
|
+
MIN_ELEMENT_SIZE: number = 0;
|
|
19
|
+
lastSelectedElement: number | null = null;
|
|
20
|
+
lastElement: number | null = null;
|
|
21
|
+
getters = this.env.getters;
|
|
22
|
+
dispatch = this.env.dispatch;
|
|
23
|
+
|
|
24
|
+
state = useState({
|
|
25
|
+
isActive: <boolean>false,
|
|
26
|
+
isResizing: <boolean>false,
|
|
27
|
+
activeElement: <number>0,
|
|
28
|
+
styleValue: <number>0,
|
|
29
|
+
delta: <number>0,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
abstract _getEvOffset(ev: MouseEvent): number;
|
|
33
|
+
|
|
34
|
+
abstract _getStateOffset(): number;
|
|
35
|
+
|
|
36
|
+
abstract _getViewportOffset(): number;
|
|
37
|
+
|
|
38
|
+
abstract _getClientPosition(ev: MouseEvent): number;
|
|
39
|
+
|
|
40
|
+
abstract _getElementIndex(index: number): number;
|
|
41
|
+
|
|
42
|
+
abstract _getElement(index: number): Col | Row;
|
|
43
|
+
|
|
44
|
+
abstract _getHeaderSize(): number;
|
|
45
|
+
|
|
46
|
+
abstract _getMaxSize(): number;
|
|
47
|
+
|
|
48
|
+
abstract _updateSize(): void;
|
|
49
|
+
|
|
50
|
+
abstract _selectElement(index: number, ctrlKey: boolean): void;
|
|
51
|
+
|
|
52
|
+
abstract _increaseSelection(index: number): void;
|
|
53
|
+
|
|
54
|
+
abstract _fitElementSize(index: number): void;
|
|
55
|
+
|
|
56
|
+
abstract _getType(): ContextMenuType;
|
|
57
|
+
|
|
58
|
+
abstract _getActiveElements(): Set<number>;
|
|
59
|
+
|
|
60
|
+
abstract _getXY(ev: MouseEvent): { x: number; y: number };
|
|
61
|
+
|
|
62
|
+
_computeHandleDisplay(ev: MouseEvent) {
|
|
63
|
+
const index = this._getEvOffset(ev);
|
|
64
|
+
const elementIndex = this._getElementIndex(index);
|
|
65
|
+
if (elementIndex < 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const element = this._getElement(elementIndex);
|
|
69
|
+
const offset = this._getStateOffset();
|
|
70
|
+
if (
|
|
71
|
+
index - (element.start - offset) < this.PADDING &&
|
|
72
|
+
elementIndex !== this._getViewportOffset()
|
|
73
|
+
) {
|
|
74
|
+
this.state.isActive = true;
|
|
75
|
+
this.state.styleValue = element.start - offset - this._getHeaderSize();
|
|
76
|
+
this.state.activeElement = elementIndex - 1;
|
|
77
|
+
} else if (element.end - offset - index < this.PADDING) {
|
|
78
|
+
this.state.isActive = true;
|
|
79
|
+
this.state.styleValue = element.end - offset - this._getHeaderSize();
|
|
80
|
+
this.state.activeElement = elementIndex;
|
|
81
|
+
} else {
|
|
82
|
+
this.state.isActive = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
onMouseMove(ev: MouseEvent) {
|
|
87
|
+
if (this.state.isResizing) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this._computeHandleDisplay(ev);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onMouseLeave() {
|
|
94
|
+
this.state.isActive = this.state.isResizing;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
onDblClick() {
|
|
98
|
+
this._fitElementSize(this.state.activeElement);
|
|
99
|
+
this.state.isResizing = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
onMouseDown(ev: MouseEvent) {
|
|
103
|
+
this.state.isResizing = true;
|
|
104
|
+
this.state.delta = 0;
|
|
105
|
+
|
|
106
|
+
const initialIndex = this._getClientPosition(ev);
|
|
107
|
+
const styleValue = this.state.styleValue;
|
|
108
|
+
const size = this._getElement(this.state.activeElement).size;
|
|
109
|
+
const minSize = styleValue - size + this.MIN_ELEMENT_SIZE;
|
|
110
|
+
const maxSize = this._getMaxSize();
|
|
111
|
+
const onMouseUp = (ev: MouseEvent) => {
|
|
112
|
+
this.state.isResizing = false;
|
|
113
|
+
if (this.state.delta !== 0) {
|
|
114
|
+
this._updateSize();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const onMouseMove = (ev: MouseEvent) => {
|
|
118
|
+
this.state.delta = this._getClientPosition(ev) - initialIndex;
|
|
119
|
+
this.state.styleValue = styleValue + this.state.delta;
|
|
120
|
+
if (this.state.styleValue < minSize) {
|
|
121
|
+
this.state.styleValue = minSize;
|
|
122
|
+
this.state.delta = this.MIN_ELEMENT_SIZE - size;
|
|
123
|
+
}
|
|
124
|
+
if (this.state.styleValue > maxSize) {
|
|
125
|
+
this.state.styleValue = maxSize;
|
|
126
|
+
this.state.delta = maxSize - styleValue;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
startDnd(onMouseMove, onMouseUp);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
select(ev: MouseEvent) {
|
|
133
|
+
if (ev.button > 0) {
|
|
134
|
+
// not main button, probably a context menu
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const index = this._getElementIndex(this._getEvOffset(ev));
|
|
138
|
+
if (index < 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.lastElement = index;
|
|
142
|
+
this.dispatch(ev.ctrlKey ? "START_SELECTION_EXPANSION" : "START_SELECTION");
|
|
143
|
+
if (ev.shiftKey) {
|
|
144
|
+
this._increaseSelection(index);
|
|
145
|
+
} else {
|
|
146
|
+
this.lastSelectedElement = index;
|
|
147
|
+
this._selectElement(index, ev.ctrlKey);
|
|
148
|
+
}
|
|
149
|
+
const initialIndex = this._getClientPosition(ev);
|
|
150
|
+
const initialOffset = this._getEvOffset(ev);
|
|
151
|
+
const onMouseMoveSelect = (ev: MouseEvent) => {
|
|
152
|
+
const offset = this._getClientPosition(ev) - initialIndex + initialOffset;
|
|
153
|
+
const index = this._getElementIndex(offset);
|
|
154
|
+
if (index !== this.lastElement && index !== -1) {
|
|
155
|
+
this._increaseSelection(index);
|
|
156
|
+
this.lastElement = index;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const onMouseUpSelect = () => {
|
|
160
|
+
this.lastElement = null;
|
|
161
|
+
this.dispatch(ev.ctrlKey ? "PREPARE_SELECTION_EXPANSION" : "STOP_SELECTION");
|
|
162
|
+
};
|
|
163
|
+
startDnd(onMouseMoveSelect, onMouseUpSelect);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
onMouseUp(ev: MouseEvent) {
|
|
167
|
+
this.lastElement = null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
onContextMenu(ev: MouseEvent) {
|
|
171
|
+
ev.preventDefault();
|
|
172
|
+
const index = this._getElementIndex(this._getEvOffset(ev));
|
|
173
|
+
if (index < 0) return;
|
|
174
|
+
if (!this._getActiveElements().has(index)) {
|
|
175
|
+
this.lastSelectedElement = index;
|
|
176
|
+
this._selectElement(index, false);
|
|
177
|
+
}
|
|
178
|
+
const type = this._getType();
|
|
179
|
+
const { x, y } = this._getXY(ev);
|
|
180
|
+
this.trigger("open-contextmenu", { type, x, y });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export class ColResizer extends AbstractResizer {
|
|
185
|
+
static template = xml/* xml */ `
|
|
186
|
+
<div class="o-col-resizer" t-on-mousemove.self="onMouseMove" t-on-mouseleave="onMouseLeave" t-on-mousedown.self.prevent="select"
|
|
187
|
+
t-on-mouseup.self="onMouseUp" t-on-contextmenu.self="onContextMenu">
|
|
188
|
+
<t t-if="state.isActive">
|
|
189
|
+
<div class="o-handle" t-on-mousedown="onMouseDown" t-on-dblclick="onDblClick" t-on-contextmenu.prevent=""
|
|
190
|
+
t-attf-style="left:{{state.styleValue - 2}}px;">
|
|
191
|
+
<div class="dragging" t-if="state.isResizing"/>
|
|
192
|
+
</div>
|
|
193
|
+
</t>
|
|
194
|
+
</div>`;
|
|
195
|
+
|
|
196
|
+
static style = css/* scss */ `
|
|
197
|
+
.o-col-resizer {
|
|
198
|
+
position: absolute;
|
|
199
|
+
top: 0;
|
|
200
|
+
left: ${HEADER_WIDTH}px;
|
|
201
|
+
right: 0;
|
|
202
|
+
height: ${HEADER_HEIGHT}px;
|
|
203
|
+
.o-handle {
|
|
204
|
+
position: absolute;
|
|
205
|
+
height: ${HEADER_HEIGHT}px;
|
|
206
|
+
width: 4px;
|
|
207
|
+
cursor: e-resize;
|
|
208
|
+
background-color: #3266ca;
|
|
209
|
+
}
|
|
210
|
+
.dragging {
|
|
211
|
+
top: ${HEADER_HEIGHT}px;
|
|
212
|
+
position: absolute;
|
|
213
|
+
margin-left: 2px;
|
|
214
|
+
width: 1px;
|
|
215
|
+
height: 10000px;
|
|
216
|
+
background-color: #3266ca;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
`;
|
|
220
|
+
|
|
221
|
+
constructor() {
|
|
222
|
+
super(...arguments);
|
|
223
|
+
this.PADDING = 15;
|
|
224
|
+
this.MAX_SIZE_MARGIN = 90;
|
|
225
|
+
this.MIN_ELEMENT_SIZE = MIN_COL_WIDTH;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_getEvOffset(ev: MouseEvent): number {
|
|
229
|
+
return ev.offsetX + HEADER_WIDTH;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_getStateOffset(): number {
|
|
233
|
+
return this.props.viewport.offsetX - HEADER_WIDTH;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
_getViewportOffset(): number {
|
|
237
|
+
return this.props.viewport.left;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
_getClientPosition(ev: MouseEvent): number {
|
|
241
|
+
return ev.clientX;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
_getElementIndex(index: number): number {
|
|
245
|
+
return this.getters.getColIndex(index, this.props.viewport.left);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
_getElement(index: number): Col {
|
|
249
|
+
return this.getters.getCol(this.getters.getActiveSheet(), index);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
_getBottomRightValue(element: Col): number {
|
|
253
|
+
return element.end;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
_getHeaderSize(): number {
|
|
257
|
+
return HEADER_WIDTH;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
_getMaxSize(): number {
|
|
261
|
+
return this.el!.clientWidth;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_updateSize(): void {
|
|
265
|
+
const index = this.state.activeElement;
|
|
266
|
+
const size = this.state.delta + this._getElement(index).size;
|
|
267
|
+
const cols = this.getters.getActiveCols();
|
|
268
|
+
this.dispatch("RESIZE_COLUMNS", {
|
|
269
|
+
sheet: this.getters.getActiveSheet(),
|
|
270
|
+
cols: cols.has(index) ? [...cols] : [index],
|
|
271
|
+
size,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
_selectElement(index: number, ctrlKey: boolean): void {
|
|
276
|
+
this.dispatch("SELECT_COLUMN", { index, createRange: ctrlKey });
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
_increaseSelection(index: number): void {
|
|
280
|
+
this.dispatch("SELECT_COLUMN", { index, updateRange: true });
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
_fitElementSize(index: number): void {
|
|
284
|
+
const cols = this.getters.getActiveCols();
|
|
285
|
+
this.dispatch("AUTORESIZE_COLUMNS", {
|
|
286
|
+
sheet: this.getters.getActiveSheet(),
|
|
287
|
+
cols: cols.has(index) ? [...cols] : [index],
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
_getType(): ContextMenuType {
|
|
292
|
+
return "COL";
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
_getActiveElements(): Set<number> {
|
|
296
|
+
return this.getters.getActiveCols();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
_getXY(ev: MouseEvent): { x: number; y: number } {
|
|
300
|
+
return {
|
|
301
|
+
x: ev.offsetX + HEADER_WIDTH,
|
|
302
|
+
y: ev.offsetY,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export class RowResizer extends AbstractResizer {
|
|
308
|
+
static template = xml/* xml */ `
|
|
309
|
+
<div class="o-row-resizer" t-on-mousemove.self="onMouseMove" t-on-mouseleave="onMouseLeave" t-on-mousedown.self.prevent="select"
|
|
310
|
+
t-on-mouseup.self="onMouseUp" t-on-contextmenu.self="onContextMenu">
|
|
311
|
+
<t t-if="state.isActive">
|
|
312
|
+
<div class="o-handle" t-on-mousedown="onMouseDown" t-on-dblclick="onDblClick" t-on-contextmenu.prevent=""
|
|
313
|
+
t-attf-style="top:{{state.styleValue - 2}}px;">
|
|
314
|
+
<div class="dragging" t-if="state.isResizing"/>
|
|
315
|
+
</div>
|
|
316
|
+
</t>
|
|
317
|
+
</div>`;
|
|
318
|
+
|
|
319
|
+
static style = css/* scss */ `
|
|
320
|
+
.o-row-resizer {
|
|
321
|
+
position: absolute;
|
|
322
|
+
top: ${HEADER_HEIGHT}px;
|
|
323
|
+
left: 0;
|
|
324
|
+
right: 0;
|
|
325
|
+
width: ${HEADER_WIDTH}px;
|
|
326
|
+
height: 100%;
|
|
327
|
+
.o-handle {
|
|
328
|
+
position: absolute;
|
|
329
|
+
height: 4px;
|
|
330
|
+
width: ${HEADER_WIDTH}px;
|
|
331
|
+
cursor: n-resize;
|
|
332
|
+
background-color: #3266ca;
|
|
333
|
+
}
|
|
334
|
+
.dragging {
|
|
335
|
+
left: ${HEADER_WIDTH}px;
|
|
336
|
+
position: absolute;
|
|
337
|
+
margin-top: 2px;
|
|
338
|
+
width: 10000px;
|
|
339
|
+
height: 1px;
|
|
340
|
+
background-color: #3266ca;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
`;
|
|
344
|
+
|
|
345
|
+
constructor() {
|
|
346
|
+
super(...arguments);
|
|
347
|
+
this.PADDING = 5;
|
|
348
|
+
this.MAX_SIZE_MARGIN = 60;
|
|
349
|
+
this.MIN_ELEMENT_SIZE = MIN_ROW_HEIGHT;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
_getEvOffset(ev: MouseEvent): number {
|
|
353
|
+
return ev.offsetY + HEADER_HEIGHT;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
_getStateOffset(): number {
|
|
357
|
+
return this.props.viewport.offsetY - HEADER_HEIGHT;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
_getViewportOffset(): number {
|
|
361
|
+
return this.props.viewport.top;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
_getClientPosition(ev: MouseEvent): number {
|
|
365
|
+
return ev.clientY;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
_getElementIndex(index: number): number {
|
|
369
|
+
return this.getters.getRowIndex(index, this.props.viewport.top);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
_getElement(index: number): Row {
|
|
373
|
+
return this.getters.getRow(this.getters.getActiveSheet(), index);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
_getHeaderSize(): number {
|
|
377
|
+
return HEADER_HEIGHT;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
_getMaxSize(): number {
|
|
381
|
+
return this.el!.clientHeight;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
_updateSize(): void {
|
|
385
|
+
const index = this.state.activeElement;
|
|
386
|
+
const size = this.state.delta + this._getElement(index).size;
|
|
387
|
+
const rows = this.getters.getActiveRows();
|
|
388
|
+
this.dispatch("RESIZE_ROWS", {
|
|
389
|
+
sheet: this.getters.getActiveSheet(),
|
|
390
|
+
rows: rows.has(index) ? [...rows] : [index],
|
|
391
|
+
size,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
_selectElement(index: number, ctrlKey: boolean): void {
|
|
396
|
+
this.dispatch("SELECT_ROW", { index, createRange: ctrlKey });
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
_increaseSelection(index: number): void {
|
|
400
|
+
this.dispatch("SELECT_ROW", { index, updateRange: true });
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
_fitElementSize(index: number): void {
|
|
404
|
+
const rows = this.getters.getActiveRows();
|
|
405
|
+
this.dispatch("AUTORESIZE_ROWS", {
|
|
406
|
+
sheet: this.getters.getActiveSheet(),
|
|
407
|
+
rows: rows.has(index) ? [...rows] : [index],
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
_getType(): ContextMenuType {
|
|
412
|
+
return "ROW";
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
_getActiveElements(): Set<number> {
|
|
416
|
+
return this.getters.getActiveRows();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
_getXY(ev: MouseEvent): { x: number; y: number } {
|
|
420
|
+
return {
|
|
421
|
+
x: ev.offsetX,
|
|
422
|
+
y: ev.offsetY + HEADER_HEIGHT,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface Props {
|
|
428
|
+
viewport: Viewport;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export class Overlay extends Component<Props, SpreadsheetEnv> {
|
|
432
|
+
static template = xml/* xml */ `
|
|
433
|
+
<div class="o-overlay">
|
|
434
|
+
<ColResizer viewport="props.viewport"/>
|
|
435
|
+
<RowResizer viewport="props.viewport"/>
|
|
436
|
+
<div class="all" t-on-mousedown.self="selectAll"/>
|
|
437
|
+
</div>`;
|
|
438
|
+
|
|
439
|
+
static style = css/* scss */ `
|
|
440
|
+
.o-overlay {
|
|
441
|
+
.all {
|
|
442
|
+
position: absolute;
|
|
443
|
+
top: 0;
|
|
444
|
+
left: 0;
|
|
445
|
+
right: 0;
|
|
446
|
+
width: ${HEADER_WIDTH}px;
|
|
447
|
+
height: ${HEADER_HEIGHT}px;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
`;
|
|
451
|
+
|
|
452
|
+
static components = { ColResizer, RowResizer };
|
|
453
|
+
|
|
454
|
+
selectAll() {
|
|
455
|
+
this.env.dispatch("SELECT_ALL");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ScrollDirection = "horizontal" | "vertical";
|
|
2
|
+
|
|
3
|
+
export class ScrollBar {
|
|
4
|
+
private direction: ScrollDirection;
|
|
5
|
+
el: HTMLElement;
|
|
6
|
+
constructor(el: HTMLElement | null, direction: ScrollDirection) {
|
|
7
|
+
this.el = el!;
|
|
8
|
+
this.direction = direction;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get scroll(): number {
|
|
12
|
+
return this.direction === "horizontal" ? this.el.scrollLeft : this.el.scrollTop;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set scroll(value: number) {
|
|
16
|
+
if (this.direction === "horizontal") {
|
|
17
|
+
this.el.scrollLeft = value;
|
|
18
|
+
} else {
|
|
19
|
+
this.el.scrollTop = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { uuidv4 } from "../helpers/index";
|
|
3
|
+
import { SpreadsheetEnv } from "../types";
|
|
4
|
+
|
|
5
|
+
const { Component } = owl;
|
|
6
|
+
|
|
7
|
+
const { xml, css } = owl.tags;
|
|
8
|
+
|
|
9
|
+
const TEMPLATE = xml/* xml */ `
|
|
10
|
+
<div class="o-selection">
|
|
11
|
+
<t t-foreach="ranges" t-as="range" t-key="range.id">
|
|
12
|
+
<input
|
|
13
|
+
type="text"
|
|
14
|
+
spellcheck="false"
|
|
15
|
+
t-on-change="onInputChanged(range.id)"
|
|
16
|
+
t-on-focus="focus(range.id)"
|
|
17
|
+
t-att-value="range.xc"
|
|
18
|
+
t-attf-style="color: {{range.color || '#000'}}"
|
|
19
|
+
t-att-class="range.isFocused ? 'o-focused' : ''"
|
|
20
|
+
/>
|
|
21
|
+
<button
|
|
22
|
+
class="o-remove-selection"
|
|
23
|
+
t-if="ranges.length > 1"
|
|
24
|
+
t-on-click="removeInput(range.id)">✖</button>
|
|
25
|
+
</t>
|
|
26
|
+
|
|
27
|
+
<div class="o-selection-controls">
|
|
28
|
+
<button
|
|
29
|
+
t-if="canAddRange"
|
|
30
|
+
t-on-click="addEmptyInput"
|
|
31
|
+
class="o-btn o-add-selection">Add another range</button>
|
|
32
|
+
<button
|
|
33
|
+
class="o-btn o-selection-ok"
|
|
34
|
+
t-if="hasFocus"
|
|
35
|
+
t-on-click="disable">OK</button>
|
|
36
|
+
</div>
|
|
37
|
+
</div>`;
|
|
38
|
+
|
|
39
|
+
const CSS = css/* scss */ `
|
|
40
|
+
.o-selection {
|
|
41
|
+
input {
|
|
42
|
+
display: inline-block;
|
|
43
|
+
padding: 4px 6px;
|
|
44
|
+
border-radius: 4px;
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
border: 1px solid #dadce0;
|
|
47
|
+
width: 100%;
|
|
48
|
+
}
|
|
49
|
+
input:focus {
|
|
50
|
+
outline: none;
|
|
51
|
+
}
|
|
52
|
+
input.o-focused {
|
|
53
|
+
border-color: #3266ca;
|
|
54
|
+
border-width: 2px;
|
|
55
|
+
padding: 3px 5px;
|
|
56
|
+
}
|
|
57
|
+
button.o-remove-selection {
|
|
58
|
+
margin-left: -30px;
|
|
59
|
+
background: transparent;
|
|
60
|
+
border: none;
|
|
61
|
+
color: #333;
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
}
|
|
64
|
+
button.o-btn {
|
|
65
|
+
margin: 8px 1px;
|
|
66
|
+
border-radius: 4px;
|
|
67
|
+
background: transparent;
|
|
68
|
+
border: 1px solid #dadce0;
|
|
69
|
+
color: #188038;
|
|
70
|
+
font-weight: bold;
|
|
71
|
+
font-size: 14px;
|
|
72
|
+
height: 25px;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
|
|
77
|
+
interface Props {
|
|
78
|
+
ranges: string[];
|
|
79
|
+
maximumRanges?: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* This component can be used when the user needs to input some
|
|
84
|
+
* ranges. He can either input the ranges with the regular DOM `<input/>`
|
|
85
|
+
* displayed or by selecting zones on the grid.
|
|
86
|
+
*
|
|
87
|
+
* A `selection-changed` event is triggered every time the input value
|
|
88
|
+
* changes.
|
|
89
|
+
*/
|
|
90
|
+
export class SelectionInput extends Component<Props, SpreadsheetEnv> {
|
|
91
|
+
static template = TEMPLATE;
|
|
92
|
+
static style = CSS;
|
|
93
|
+
private id = uuidv4();
|
|
94
|
+
private previousRanges: string[] = this.props.ranges || [];
|
|
95
|
+
private getters = this.env.getters;
|
|
96
|
+
private dispatch = this.env.dispatch;
|
|
97
|
+
|
|
98
|
+
get ranges() {
|
|
99
|
+
return this.getters.getSelectionInput(this.id);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get hasFocus(): boolean {
|
|
103
|
+
return this.ranges.filter((i) => i.isFocused).length > 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get canAddRange(): boolean {
|
|
107
|
+
return !this.props.maximumRanges || this.ranges.length < this.props.maximumRanges;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
mounted() {
|
|
111
|
+
this.dispatch("ENABLE_NEW_SELECTION_INPUT", {
|
|
112
|
+
id: this.id,
|
|
113
|
+
initialRanges: this.props.ranges,
|
|
114
|
+
maximumRanges: this.props.maximumRanges,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async willUnmount() {
|
|
119
|
+
this.dispatch("DISABLE_SELECTION_INPUT", { id: this.id });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async patched() {
|
|
123
|
+
const value = this.getters.getSelectionInputValue(this.id);
|
|
124
|
+
if (this.previousRanges.join() !== value.join()) {
|
|
125
|
+
this.triggerChange();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private triggerChange() {
|
|
130
|
+
const ranges = this.getters.getSelectionInputValue(this.id);
|
|
131
|
+
this.trigger("selection-changed", { ranges });
|
|
132
|
+
this.previousRanges = ranges;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
focus(rangeId: string | null) {
|
|
136
|
+
this.dispatch("FOCUS_RANGE", {
|
|
137
|
+
id: this.id,
|
|
138
|
+
rangeId,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
addEmptyInput() {
|
|
143
|
+
this.dispatch("ADD_EMPTY_RANGE", { id: this.id });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
removeInput(rangeId: string) {
|
|
147
|
+
this.dispatch("REMOVE_RANGE", { id: this.id, rangeId });
|
|
148
|
+
this.triggerChange();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
onInputChanged(rangeId: string, ev: InputEvent) {
|
|
152
|
+
const target = ev.target as HTMLInputElement;
|
|
153
|
+
this.dispatch("CHANGE_RANGE", {
|
|
154
|
+
id: this.id,
|
|
155
|
+
rangeId,
|
|
156
|
+
value: target.value,
|
|
157
|
+
});
|
|
158
|
+
target.blur();
|
|
159
|
+
this.triggerChange();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
disable() {
|
|
163
|
+
this.dispatch("FOCUS_RANGE", {
|
|
164
|
+
id: this.id,
|
|
165
|
+
rangeId: null,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|