@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,198 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { BOTTOMBAR_HEIGHT, TOPBAR_HEIGHT } from "../constants";
|
|
3
|
+
import { Model } from "../model";
|
|
4
|
+
import { SelectionMode } from "../plugins/selection";
|
|
5
|
+
import { BottomBar } from "./bottom_bar";
|
|
6
|
+
import { Grid } from "./grid";
|
|
7
|
+
import { SidePanel } from "./side_panel/side_panel";
|
|
8
|
+
import { TopBar } from "./top_bar";
|
|
9
|
+
|
|
10
|
+
const { Component, useState } = owl;
|
|
11
|
+
const { useRef, useExternalListener } = owl.hooks;
|
|
12
|
+
const { xml, css } = owl.tags;
|
|
13
|
+
const { useSubEnv } = owl.hooks;
|
|
14
|
+
|
|
15
|
+
// -----------------------------------------------------------------------------
|
|
16
|
+
// SpreadSheet
|
|
17
|
+
// -----------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const TEMPLATE = xml/* xml */ `
|
|
20
|
+
<div class="o-spreadsheet" t-on-save-requested="save" t-on-keydown="onKeydown">
|
|
21
|
+
<TopBar t-on-click="focusGrid" class="o-two-columns"/>
|
|
22
|
+
<Grid model="model" t-ref="grid" t-att-class="{'o-two-columns': !sidePanel.isOpen}"/>
|
|
23
|
+
<SidePanel t-if="sidePanel.isOpen"
|
|
24
|
+
t-on-close-side-panel="sidePanel.isOpen = false"
|
|
25
|
+
component="sidePanel.component"
|
|
26
|
+
panelProps="sidePanel.panelProps"/>
|
|
27
|
+
<BottomBar t-on-click="focusGrid" class="o-two-columns"/>
|
|
28
|
+
</div>`;
|
|
29
|
+
|
|
30
|
+
const CSS = css/* scss */ `
|
|
31
|
+
.o-spreadsheet {
|
|
32
|
+
display: grid;
|
|
33
|
+
grid-template-rows: ${TOPBAR_HEIGHT}px auto ${BOTTOMBAR_HEIGHT + 1}px;
|
|
34
|
+
grid-template-columns: auto 350px;
|
|
35
|
+
* {
|
|
36
|
+
font-family: "Roboto", "RobotoDraft", Helvetica, Arial, sans-serif;
|
|
37
|
+
}
|
|
38
|
+
&,
|
|
39
|
+
*,
|
|
40
|
+
*:before,
|
|
41
|
+
*:after {
|
|
42
|
+
box-sizing: content-box;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.o-two-columns {
|
|
47
|
+
grid-column: 1 / 3;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.o-icon {
|
|
51
|
+
width: 18px;
|
|
52
|
+
height: 18px;
|
|
53
|
+
opacity: 0.6;
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
interface Props {
|
|
58
|
+
data?: any;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const t = (s: string): string => s;
|
|
62
|
+
|
|
63
|
+
export class Spreadsheet extends Component<Props> {
|
|
64
|
+
static template = TEMPLATE;
|
|
65
|
+
static style = CSS;
|
|
66
|
+
static components = { TopBar, Grid, BottomBar, SidePanel };
|
|
67
|
+
static _t = t;
|
|
68
|
+
|
|
69
|
+
model = new Model(this.props.data, {
|
|
70
|
+
notifyUser: (content: string) => this.trigger("notify-user", { content }),
|
|
71
|
+
askConfirmation: (content: string, confirm: () => any, cancel?: () => any) =>
|
|
72
|
+
this.trigger("ask-confirmation", { content, confirm, cancel }),
|
|
73
|
+
editText: (title: string, placeholder: string, callback: (text: string | null) => any) =>
|
|
74
|
+
this.trigger("edit-text", { title, placeholder, callback }),
|
|
75
|
+
openSidePanel: (panel: string, panelProps: any = {}) => this.openSidePanel(panel, panelProps),
|
|
76
|
+
evalContext: { env: this.env },
|
|
77
|
+
});
|
|
78
|
+
grid = useRef("grid");
|
|
79
|
+
|
|
80
|
+
sidePanel = useState({ isOpen: false, panelProps: {} } as {
|
|
81
|
+
isOpen: boolean;
|
|
82
|
+
component?: string;
|
|
83
|
+
panelProps: any;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// last string that was cut or copied. It is necessary so we can make the
|
|
87
|
+
// difference between a paste coming from the sheet itself, or from the
|
|
88
|
+
// os clipboard
|
|
89
|
+
private clipBoardString: string = "";
|
|
90
|
+
|
|
91
|
+
constructor() {
|
|
92
|
+
super(...arguments);
|
|
93
|
+
useSubEnv({
|
|
94
|
+
openSidePanel: (panel: string, panelProps: any = {}) => this.openSidePanel(panel, panelProps),
|
|
95
|
+
toggleSidePanel: (panel: string, panelProps: any = {}) =>
|
|
96
|
+
this.toggleSidePanel(panel, panelProps),
|
|
97
|
+
dispatch: this.model.dispatch,
|
|
98
|
+
getters: this.model.getters,
|
|
99
|
+
_t: Spreadsheet._t,
|
|
100
|
+
clipboard: navigator.clipboard,
|
|
101
|
+
export: this.model.exportData.bind(this.model),
|
|
102
|
+
});
|
|
103
|
+
useExternalListener(window as any, "resize", this.render);
|
|
104
|
+
useExternalListener(document.body, "cut", this.copy.bind(this, true));
|
|
105
|
+
useExternalListener(document.body, "copy", this.copy.bind(this, false));
|
|
106
|
+
useExternalListener(document.body, "paste", this.paste);
|
|
107
|
+
useExternalListener(document.body, "keyup", this.onKeyup.bind(this));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
mounted() {
|
|
111
|
+
this.model.on("update", this, this.render);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
willUnmount() {
|
|
115
|
+
this.model.off("update", this);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
destroy() {
|
|
119
|
+
this.model.destroy();
|
|
120
|
+
super.destroy();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
openSidePanel(panel: string, panelProps: any) {
|
|
124
|
+
this.sidePanel.component = panel;
|
|
125
|
+
this.sidePanel.panelProps = panelProps;
|
|
126
|
+
this.sidePanel.isOpen = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
toggleSidePanel(panel: string, panelProps: any) {
|
|
130
|
+
if (this.sidePanel.isOpen && panel === this.sidePanel.component) {
|
|
131
|
+
this.sidePanel.isOpen = false;
|
|
132
|
+
} else {
|
|
133
|
+
this.openSidePanel(panel, panelProps);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
focusGrid() {
|
|
137
|
+
(<any>this.grid.comp).focus();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
copy(cut: boolean, ev: ClipboardEvent) {
|
|
141
|
+
if (!this.grid.el!.contains(document.activeElement)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
/* If we are currently editing a cell, let the default behavior */
|
|
145
|
+
if (this.model.getters.getEditionMode() !== "inactive") {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const type = cut ? "CUT" : "COPY";
|
|
149
|
+
const target = this.model.getters.getSelectedZones();
|
|
150
|
+
this.model.dispatch(type, { target });
|
|
151
|
+
const content = this.model.getters.getClipboardContent();
|
|
152
|
+
this.clipBoardString = content;
|
|
153
|
+
ev.clipboardData!.setData("text/plain", content);
|
|
154
|
+
ev.preventDefault();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
paste(ev: ClipboardEvent) {
|
|
158
|
+
if (!this.grid.el!.contains(document.activeElement)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const clipboardData = ev.clipboardData!;
|
|
162
|
+
if (clipboardData.types.indexOf("text/plain") > -1) {
|
|
163
|
+
const content = clipboardData.getData("text/plain");
|
|
164
|
+
const target = this.model.getters.getSelectedZones();
|
|
165
|
+
if (this.clipBoardString === content) {
|
|
166
|
+
// the paste actually comes from o-spreadsheet itself
|
|
167
|
+
this.model.dispatch("PASTE", { target, interactive: true });
|
|
168
|
+
} else {
|
|
169
|
+
this.model.dispatch("PASTE_FROM_OS_CLIPBOARD", {
|
|
170
|
+
target,
|
|
171
|
+
text: content,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
save() {
|
|
178
|
+
this.trigger("save-content", {
|
|
179
|
+
data: this.model.exportData(),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
onKeyup(ev: KeyboardEvent) {
|
|
184
|
+
if (ev.key === "Control" && this.model.getters.getSelectionMode() !== SelectionMode.expanding) {
|
|
185
|
+
this.model.dispatch("STOP_SELECTION");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
onKeydown(ev: KeyboardEvent) {
|
|
190
|
+
if (ev.key === "Control" && !ev.repeat) {
|
|
191
|
+
this.model.dispatch(
|
|
192
|
+
this.model.getters.getSelectionMode() === SelectionMode.idle
|
|
193
|
+
? "PREPARE_SELECTION_EXPANSION"
|
|
194
|
+
: "START_SELECTION_EXPANSION"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|