@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
package/demo/main.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { demoData, makeLargeDataset } from "./data.js";
|
|
2
|
+
owl.config.mode = "dev";
|
|
3
|
+
|
|
4
|
+
const { whenReady } = owl.utils;
|
|
5
|
+
const { Component } = owl;
|
|
6
|
+
const { xml, css } = owl.tags;
|
|
7
|
+
const { useSubEnv } = owl.hooks;
|
|
8
|
+
|
|
9
|
+
const Spreadsheet = o_spreadsheet.Spreadsheet;
|
|
10
|
+
const menuItemRegistry = o_spreadsheet.registries.topbarMenuRegistry;
|
|
11
|
+
|
|
12
|
+
menuItemRegistry.add("file", { name: "File", sequence: 10 });
|
|
13
|
+
menuItemRegistry.addChild("save", ["file"], {
|
|
14
|
+
name: "Save",
|
|
15
|
+
sequence: 30,
|
|
16
|
+
action: (env) => env.save(env.export()),
|
|
17
|
+
});
|
|
18
|
+
menuItemRegistry.addChild("clear", ["file"], {
|
|
19
|
+
name: "Clear save",
|
|
20
|
+
sequence: 30,
|
|
21
|
+
action: (env) => window.localStorage.removeItem("o-spreadsheet"),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
let start;
|
|
25
|
+
|
|
26
|
+
class App extends Component {
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
this.key = 1;
|
|
30
|
+
let cacheData;
|
|
31
|
+
try {
|
|
32
|
+
cacheData = JSON.parse(window.localStorage.getItem("o-spreadsheet"));
|
|
33
|
+
} catch (_) {
|
|
34
|
+
window.localStorage.removeItem("o-spreadsheet");
|
|
35
|
+
}
|
|
36
|
+
this.data = cacheData || demoData;
|
|
37
|
+
useSubEnv({
|
|
38
|
+
save: this.save.bind(this),
|
|
39
|
+
});
|
|
40
|
+
// this.data = makeLargeDataset(20, 10_000);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
mounted() {
|
|
44
|
+
console.log("Mounted: ", Date.now() - start);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
askConfirmation(ev) {
|
|
48
|
+
if (window.confirm(ev.detail.content)) {
|
|
49
|
+
ev.detail.confirm();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
notifyUser(ev) {
|
|
54
|
+
window.alert(ev.detail.content);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
editText(ev) {
|
|
58
|
+
const text = window.prompt(ev.detail.title, ev.detail.placeholder);
|
|
59
|
+
ev.detail.callback(text);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
saveContent(ev) {
|
|
63
|
+
this.save(ev.detail.data);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
save(content) {
|
|
67
|
+
window.localStorage.setItem("o-spreadsheet", JSON.stringify(content));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
App.template = xml`
|
|
72
|
+
<div>
|
|
73
|
+
<Spreadsheet data="data" t-key="key"
|
|
74
|
+
t-on-ask-confirmation="askConfirmation"
|
|
75
|
+
t-on-notify-user="notifyUser"
|
|
76
|
+
t-on-edit-text="editText"
|
|
77
|
+
t-on-save-content="saveContent"/>
|
|
78
|
+
</div>`;
|
|
79
|
+
App.style = css`
|
|
80
|
+
html {
|
|
81
|
+
height: 100%;
|
|
82
|
+
body {
|
|
83
|
+
height: 100%;
|
|
84
|
+
margin: 0px;
|
|
85
|
+
}
|
|
86
|
+
.o-spreadsheet {
|
|
87
|
+
width: 100%;
|
|
88
|
+
height: 100%;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
App.components = { Spreadsheet };
|
|
93
|
+
|
|
94
|
+
// Setup code
|
|
95
|
+
function setup() {
|
|
96
|
+
start = Date.now();
|
|
97
|
+
const app = new App();
|
|
98
|
+
|
|
99
|
+
app.mount(document.body);
|
|
100
|
+
}
|
|
101
|
+
whenReady(setup);
|
package/doc/readme.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# o-spreadsheet
|
|
2
|
+
|
|
3
|
+
## Integrating o-spreadsheet
|
|
4
|
+
|
|
5
|
+
The `o-spreadsheet` library is designed to be standalone, but easy to integrate.
|
|
6
|
+
Here is a list of all official extension points:
|
|
7
|
+
|
|
8
|
+
1. Adding functions: the `o_spreadsheet` object exports an `addFunction` method:
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
o_spreadsheet.addFunction("myfunc", {
|
|
12
|
+
description: "My custom Function",
|
|
13
|
+
compute: function (a, b) {
|
|
14
|
+
return 2 * (a + b);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The `addFunction` method takes a name and a function descriptor (it should
|
|
20
|
+
implement the `FunctionDescription` interface from the code `/functions/index.ts`).
|
|
21
|
+
|
|
22
|
+
2. Confirmation dialog: sometimes, `o-spreadsheet` needs to ask confirmation to
|
|
23
|
+
the user. For example, merging cells which have some text content is considered
|
|
24
|
+
a destructive operation. In that case, we want to display a nice modal dialog
|
|
25
|
+
to ask the user if it is okay.
|
|
26
|
+
|
|
27
|
+
To do that, the `o-spreadsheet` library will trigger a `ask-confirmation` event.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
class App extends Component {
|
|
31
|
+
static template = xml`<Spreadsheet data="data" t-on-ask-confirmation="askConfirmation"/>`;
|
|
32
|
+
static components = { Spreadsheet };
|
|
33
|
+
|
|
34
|
+
data = ...;
|
|
35
|
+
|
|
36
|
+
askConfirmation(ev) {
|
|
37
|
+
// open here a nice model dialog
|
|
38
|
+
if (window.confirm(ev.detail.content)) {
|
|
39
|
+
ev.detail.confirm();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. Notification dialog: sometimes, `o-spreadsheet` needs to notify the user that
|
|
45
|
+
some operation is not supported, or some other message. In that case, it will
|
|
46
|
+
trigger a `notify-user` event, with a `content` key with a message.
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odoo/o-spreadsheet",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.1",
|
|
4
4
|
"description": "A spreadsheet component",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
],
|
|
9
6
|
"scripts": {
|
|
10
7
|
"serve": "live-server --open=demo",
|
|
11
8
|
"dev": "npm-run-all build --parallel serve \"build:* -- --watch\"",
|
|
@@ -18,8 +15,7 @@
|
|
|
18
15
|
"prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,demo/*.js} --write",
|
|
19
16
|
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,demo/*.js} --check",
|
|
20
17
|
"dist": "npm run build:all && npm run build:bundle",
|
|
21
|
-
"prepare": "husky install"
|
|
22
|
-
"release": "node tools/release.js"
|
|
18
|
+
"prepare": "husky install"
|
|
23
19
|
},
|
|
24
20
|
"browserslist": [
|
|
25
21
|
"last 1 Chrome versions"
|
|
@@ -27,26 +23,16 @@
|
|
|
27
23
|
"keywords": [
|
|
28
24
|
"owl",
|
|
29
25
|
"spreadsheet",
|
|
30
|
-
"o-spreadsheet",
|
|
31
26
|
"odoo"
|
|
32
27
|
],
|
|
33
|
-
"author": "
|
|
28
|
+
"author": "Gery Debongnie",
|
|
34
29
|
"license": "LGPL-3.0-or-later",
|
|
35
|
-
"repository": {
|
|
36
|
-
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/odoo/o-spreadsheet.git"
|
|
38
|
-
},
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/odoo/o-spreadsheet/issues"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://github.com/odoo/o-spreadsheet#readme",
|
|
43
30
|
"devDependencies": {
|
|
44
31
|
"@types/chart.js": "^2.9.24",
|
|
45
32
|
"@types/jest": "^27.0.1",
|
|
46
33
|
"@types/node": "^13.11.1",
|
|
47
34
|
"babel-eslint": "^10.1.0",
|
|
48
35
|
"eslint": "^6.8.0",
|
|
49
|
-
"current-git-branch": "^1.1.0",
|
|
50
36
|
"git-rev-sync": "^2.0.0",
|
|
51
37
|
"husky": "^7.0.4",
|
|
52
38
|
"jest": "^27.2.0",
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { version } from "./package.json";
|
|
2
|
+
import git from "git-rev-sync";
|
|
3
|
+
|
|
4
|
+
let commitHash = "";
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
commitHash = git.short();
|
|
8
|
+
}
|
|
9
|
+
catch(_) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
input: "dist/js/index.js",
|
|
14
|
+
external: ["@odoo/owl"],
|
|
15
|
+
output: {
|
|
16
|
+
file: "dist/o_spreadsheet.js",
|
|
17
|
+
format: "iife",
|
|
18
|
+
name: "o_spreadsheet",
|
|
19
|
+
extend: true,
|
|
20
|
+
globals: { "@odoo/owl": "owl" /*, "chart.js": "chart_js" */ },
|
|
21
|
+
outro: `exports.__info__.version = '${version}';\nexports.__info__.date = '${new Date().toISOString()}';\nexports.__info__.hash = '${commitHash}';`,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { WHistory, WorkbookHistory } from "./history";
|
|
2
|
+
import { Mode, ModelConfig } from "./model";
|
|
3
|
+
import {
|
|
4
|
+
Command,
|
|
5
|
+
CommandDispatcher,
|
|
6
|
+
CommandHandler,
|
|
7
|
+
CommandResult,
|
|
8
|
+
Getters,
|
|
9
|
+
GridRenderingContext,
|
|
10
|
+
LAYERS,
|
|
11
|
+
Workbook,
|
|
12
|
+
WorkbookData,
|
|
13
|
+
} from "./types/index";
|
|
14
|
+
|
|
15
|
+
type UIActions = Pick<ModelConfig, "askConfirmation" | "notifyUser" | "openSidePanel" | "editText">;
|
|
16
|
+
/**
|
|
17
|
+
* BasePlugin
|
|
18
|
+
*
|
|
19
|
+
* Since the spreadsheet internal state is quite complex, it is split into
|
|
20
|
+
* multiple parts, each managing a specific concern.
|
|
21
|
+
*
|
|
22
|
+
* This file introduce the BasePlugin, which is the common class that defines
|
|
23
|
+
* how each of these model sub parts should interact with each other.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export class BasePlugin implements CommandHandler {
|
|
27
|
+
static layers: LAYERS[] = [];
|
|
28
|
+
static getters: string[] = [];
|
|
29
|
+
static modes: Mode[] = ["headless", "normal", "readonly"];
|
|
30
|
+
|
|
31
|
+
protected workbook: Workbook;
|
|
32
|
+
protected getters: Getters;
|
|
33
|
+
protected history: WorkbookHistory;
|
|
34
|
+
protected dispatch: CommandDispatcher["dispatch"];
|
|
35
|
+
protected currentMode: Mode;
|
|
36
|
+
protected ui: UIActions;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
workbook: Workbook,
|
|
40
|
+
getters: Getters,
|
|
41
|
+
history: WHistory,
|
|
42
|
+
dispatch: CommandDispatcher["dispatch"],
|
|
43
|
+
config: ModelConfig
|
|
44
|
+
) {
|
|
45
|
+
this.workbook = workbook;
|
|
46
|
+
this.getters = getters;
|
|
47
|
+
this.history = Object.assign(Object.create(history), {
|
|
48
|
+
updateLocalState: history.updateStateFromRoot.bind(history, this),
|
|
49
|
+
});
|
|
50
|
+
this.dispatch = dispatch;
|
|
51
|
+
this.currentMode = config.mode;
|
|
52
|
+
this.ui = config;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Command handling
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Before a command is accepted, the model will ask each plugin if the command
|
|
61
|
+
* is allowed. If all of then return true, then we can proceed. Otherwise,
|
|
62
|
+
* the command is cancelled.
|
|
63
|
+
*
|
|
64
|
+
* There should not be any side effects in this method.
|
|
65
|
+
*/
|
|
66
|
+
allowDispatch(command: Command): CommandResult {
|
|
67
|
+
return { status: "SUCCESS" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* This method is useful when a plugin need to perform some action before a
|
|
72
|
+
* command is handled in another plugin. This should only be used if it is not
|
|
73
|
+
* possible to do the work in the handle method.
|
|
74
|
+
*/
|
|
75
|
+
beforeHandle(command: Command): void {}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* This is the standard place to handle any command. Most of the plugin
|
|
79
|
+
* command handling work should take place here.
|
|
80
|
+
*/
|
|
81
|
+
handle(command: Command): void {}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sometimes, it is useful to perform some work after a command (and all its
|
|
85
|
+
* subcommands) has been completely handled. For example, when we paste
|
|
86
|
+
* multiple cells, we only want to reevaluate the cell values once at the end.
|
|
87
|
+
*/
|
|
88
|
+
finalize(command: Command): void {}
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Grid rendering
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
drawGrid(ctx: GridRenderingContext, layer: LAYERS) {}
|
|
95
|
+
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// Import/Export
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
import(data: WorkbookData) {}
|
|
101
|
+
export(data: WorkbookData) {}
|
|
102
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { clip } from "../helpers/misc";
|
|
3
|
+
import { SpreadsheetEnv, Viewport } from "../types";
|
|
4
|
+
import { startDnd } from "./helpers/drag_and_drop";
|
|
5
|
+
|
|
6
|
+
const { Component } = owl;
|
|
7
|
+
const { xml, css } = owl.tags;
|
|
8
|
+
const { useState } = owl.hooks;
|
|
9
|
+
|
|
10
|
+
// -----------------------------------------------------------------------------
|
|
11
|
+
// Autofill
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
const TEMPLATE = xml/* xml */ `
|
|
15
|
+
<div class="o-autofill" t-on-mousedown="onMouseDown" t-att-style="style" t-on-dblclick="onDblClick">
|
|
16
|
+
<div class="o-autofill-handler" t-att-style="styleHandler"/>
|
|
17
|
+
<t t-set="tooltip" t-value="getTooltip()"/>
|
|
18
|
+
<div t-if="tooltip" class="o-autofill-nextvalue" t-att-style="styleNextvalue">
|
|
19
|
+
<t t-component="tooltip.component" t-props="tooltip.props"/>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
const CSS = css/* scss */ `
|
|
25
|
+
.o-autofill {
|
|
26
|
+
height: 6px;
|
|
27
|
+
width: 6px;
|
|
28
|
+
border: 1px solid white;
|
|
29
|
+
position: absolute;
|
|
30
|
+
background-color: #1a73e8;
|
|
31
|
+
|
|
32
|
+
.o-autofill-handler {
|
|
33
|
+
position: absolute;
|
|
34
|
+
height: 8px;
|
|
35
|
+
width: 8px;
|
|
36
|
+
|
|
37
|
+
&:hover {
|
|
38
|
+
cursor: crosshair;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.o-autofill-nextvalue {
|
|
43
|
+
position: absolute;
|
|
44
|
+
background-color: white;
|
|
45
|
+
border: 1px solid black;
|
|
46
|
+
padding: 5px;
|
|
47
|
+
font-size: 12px;
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
white-space: nowrap;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
interface Props {
|
|
55
|
+
position: Position;
|
|
56
|
+
viewport: Viewport;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface Position {
|
|
60
|
+
top: number;
|
|
61
|
+
left: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface State {
|
|
65
|
+
position: Position;
|
|
66
|
+
handler: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class Autofill extends Component<Props, SpreadsheetEnv> {
|
|
70
|
+
static template = TEMPLATE;
|
|
71
|
+
static style = CSS;
|
|
72
|
+
|
|
73
|
+
state: State = useState({
|
|
74
|
+
position: { left: 0, top: 0 },
|
|
75
|
+
handler: false,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
get style() {
|
|
79
|
+
const { left, top } = this.props.position;
|
|
80
|
+
return `top:${top}px;left:${left}px`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get styleHandler() {
|
|
84
|
+
let position: Position = this.state.handler ? this.state.position : { left: 0, top: 0 };
|
|
85
|
+
return `top:${position.top}px;left:${position.left}px;`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get styleNextvalue() {
|
|
89
|
+
let position: Position = this.state.handler ? this.state.position : { left: 0, top: 0 };
|
|
90
|
+
return `top:${position.top + 5}px;left:${position.left + 15}px;`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getTooltip() {
|
|
94
|
+
const tooltip = this.env.getters.getAutofillTooltip();
|
|
95
|
+
if (tooltip && !tooltip.component) {
|
|
96
|
+
tooltip.component = TooltipComponent;
|
|
97
|
+
}
|
|
98
|
+
return tooltip;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onMouseDown(ev: MouseEvent) {
|
|
102
|
+
this.state.handler = true;
|
|
103
|
+
this.state.position = { left: 0, top: 0 };
|
|
104
|
+
const start = { left: ev.clientX, top: ev.clientY };
|
|
105
|
+
let lastCol: number | undefined;
|
|
106
|
+
let lastRow: number | undefined;
|
|
107
|
+
|
|
108
|
+
const onMouseUp = () => {
|
|
109
|
+
this.state.handler = false;
|
|
110
|
+
this.env.dispatch("AUTOFILL");
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const onMouseMove = (ev: MouseEvent) => {
|
|
114
|
+
this.state.position = {
|
|
115
|
+
left: ev.clientX - start.left,
|
|
116
|
+
top: ev.clientY - start.top,
|
|
117
|
+
};
|
|
118
|
+
const parent = this.el!.parentElement! as HTMLElement;
|
|
119
|
+
const position = parent.getBoundingClientRect();
|
|
120
|
+
const col = this.env.getters.getColIndex(
|
|
121
|
+
ev.clientX - position.left,
|
|
122
|
+
this.props.viewport.left
|
|
123
|
+
);
|
|
124
|
+
const row = this.env.getters.getRowIndex(ev.clientY - position.top, this.props.viewport.top);
|
|
125
|
+
if (lastCol !== col || lastRow !== row) {
|
|
126
|
+
const sheetId = this.env.getters.getActiveSheet();
|
|
127
|
+
lastCol = col === -1 ? lastCol : clip(col, 0, this.env.getters.getNumberCols(sheetId));
|
|
128
|
+
lastRow = row === -1 ? lastRow : clip(row, 0, this.env.getters.getNumberRows(sheetId));
|
|
129
|
+
if (lastCol !== undefined && lastRow !== undefined) {
|
|
130
|
+
this.env.dispatch("AUTOFILL_SELECT", { col: lastCol, row: lastRow });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
startDnd(onMouseMove, onMouseUp);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
onDblClick() {
|
|
138
|
+
this.env.dispatch("AUTOFILL_AUTO");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
class TooltipComponent extends Component<Props> {
|
|
143
|
+
static template = xml/* xml */ `
|
|
144
|
+
<div t-esc="props.content"/>
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { BACKGROUND_GRAY_COLOR, BOTTOMBAR_HEIGHT, HEADER_WIDTH } from "../constants";
|
|
3
|
+
import { uuidv4 } from "../helpers/index";
|
|
4
|
+
import { MenuItemRegistry, sheetMenuRegistry } from "../registries/index";
|
|
5
|
+
import { SpreadsheetEnv } from "../types";
|
|
6
|
+
import { LIST, PLUS, TRIANGLE_DOWN_ICON } from "./icons";
|
|
7
|
+
import { Menu, MenuState } from "./menu";
|
|
8
|
+
const { Component } = owl;
|
|
9
|
+
const { xml, css } = owl.tags;
|
|
10
|
+
const { useState } = owl.hooks;
|
|
11
|
+
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
// SpreadSheet
|
|
14
|
+
// -----------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
const TEMPLATE = xml/* xml */ `
|
|
17
|
+
<div class="o-spreadsheet-bottom-bar">
|
|
18
|
+
<div class="o-sheet-item o-add-sheet" t-on-click="addSheet">${PLUS}</div>
|
|
19
|
+
<div class="o-sheet-item o-list-sheets" t-on-click="listSheets">${LIST}</div>
|
|
20
|
+
<div class="o-all-sheets">
|
|
21
|
+
<t t-foreach="getters.getSheets()" t-as="sheet" t-key="sheet.id">
|
|
22
|
+
<div class="o-sheet-item o-sheet" t-on-click="activateSheet(sheet.id)"
|
|
23
|
+
t-on-contextmenu.prevent="onContextMenu(sheet.id)"
|
|
24
|
+
t-att-title="sheet.name"
|
|
25
|
+
t-att-data-id="sheet.id"
|
|
26
|
+
t-att-class="{active: sheet.id === getters.getActiveSheet()}">
|
|
27
|
+
<span class="o-sheet-name" t-esc="sheet.name" t-on-dblclick="onDblClick(sheet.id)"/>
|
|
28
|
+
<span class="o-sheet-icon" t-on-click.stop="onIconClick(sheet.id)">${TRIANGLE_DOWN_ICON}</span>
|
|
29
|
+
</div>
|
|
30
|
+
</t>
|
|
31
|
+
</div>
|
|
32
|
+
<t t-set="aggregate" t-value="getters.getAggregate()"/>
|
|
33
|
+
<div t-if="aggregate !== null" class="o-aggregate">Sum: <t t-esc="aggregate"/></div>
|
|
34
|
+
<Menu t-if="menuState.isOpen"
|
|
35
|
+
position="menuState.position"
|
|
36
|
+
menuItems="menuState.menuItems"
|
|
37
|
+
t-on-close="menuState.isOpen=false"/>
|
|
38
|
+
</div>`;
|
|
39
|
+
|
|
40
|
+
const CSS = css/* scss */ `
|
|
41
|
+
.o-spreadsheet-bottom-bar {
|
|
42
|
+
background-color: ${BACKGROUND_GRAY_COLOR};
|
|
43
|
+
padding-left: ${HEADER_WIDTH}px;
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
font-size: 15px;
|
|
47
|
+
border-top: 1px solid lightgrey;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
|
|
50
|
+
.o-add-sheet,
|
|
51
|
+
.o-list-sheets {
|
|
52
|
+
margin-right: 5px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.o-sheet-item {
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
padding: 5px;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
&:hover {
|
|
61
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.o-all-sheets {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
max-width: 80%;
|
|
69
|
+
overflow: hidden;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.o-sheet {
|
|
73
|
+
color: #666;
|
|
74
|
+
padding: 0 15px;
|
|
75
|
+
padding-right: 10px;
|
|
76
|
+
height: ${BOTTOMBAR_HEIGHT}px;
|
|
77
|
+
line-height: ${BOTTOMBAR_HEIGHT}px;
|
|
78
|
+
user-select: none;
|
|
79
|
+
white-space: nowrap;
|
|
80
|
+
|
|
81
|
+
&.active {
|
|
82
|
+
color: #484;
|
|
83
|
+
background-color: white;
|
|
84
|
+
box-shadow: 0 1px 3px 1px rgba(60, 64, 67, 0.15);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.o-sheet-icon {
|
|
88
|
+
margin-left: 5px;
|
|
89
|
+
|
|
90
|
+
&:hover {
|
|
91
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.o-aggregate {
|
|
97
|
+
background-color: white;
|
|
98
|
+
margin-left: auto;
|
|
99
|
+
font-size: 14px;
|
|
100
|
+
margin-right: 20px;
|
|
101
|
+
padding: 4px 8px;
|
|
102
|
+
color: #333;
|
|
103
|
+
border-radius: 3px;
|
|
104
|
+
box-shadow: 0 1px 3px 1px rgba(60, 64, 67, 0.15);
|
|
105
|
+
}
|
|
106
|
+
.fade-enter-active {
|
|
107
|
+
transition: opacity 0.5s;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.fade-enter {
|
|
111
|
+
opacity: 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
export class BottomBar extends Component<{}, SpreadsheetEnv> {
|
|
117
|
+
static template = TEMPLATE;
|
|
118
|
+
static style = CSS;
|
|
119
|
+
static components = { Menu };
|
|
120
|
+
|
|
121
|
+
getters = this.env.getters;
|
|
122
|
+
menuState: MenuState = useState({ isOpen: false, position: null, menuItems: [] });
|
|
123
|
+
|
|
124
|
+
mounted() {
|
|
125
|
+
this.focusSheet();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
patched() {
|
|
129
|
+
this.focusSheet();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
focusSheet() {
|
|
133
|
+
const div = this.el!.querySelector(`[data-id="${this.getters.getActiveSheet()}"]`);
|
|
134
|
+
if (div && div.scrollIntoView) {
|
|
135
|
+
div.scrollIntoView();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
addSheet() {
|
|
140
|
+
this.env.dispatch("CREATE_SHEET", { activate: true, id: uuidv4() });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
listSheets(ev: MouseEvent) {
|
|
144
|
+
const registry = new MenuItemRegistry();
|
|
145
|
+
const from = this.getters.getActiveSheet();
|
|
146
|
+
let i = 0;
|
|
147
|
+
for (let sheet of this.getters.getSheets()) {
|
|
148
|
+
registry.add(sheet.id, {
|
|
149
|
+
name: sheet.name,
|
|
150
|
+
sequence: i,
|
|
151
|
+
action: (env) => env.dispatch("ACTIVATE_SHEET", { from, to: sheet.id }),
|
|
152
|
+
});
|
|
153
|
+
i++;
|
|
154
|
+
}
|
|
155
|
+
this.openContextMenu(ev.currentTarget as HTMLElement, registry);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
activateSheet(name: string) {
|
|
159
|
+
this.env.dispatch("ACTIVATE_SHEET", { from: this.getters.getActiveSheet(), to: name });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
onDblClick(sheet: string) {
|
|
163
|
+
this.env.dispatch("RENAME_SHEET", { interactive: true, sheet });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
openContextMenu(target: HTMLElement, registry: MenuItemRegistry) {
|
|
167
|
+
const x = target.offsetLeft;
|
|
168
|
+
const y = target.offsetTop;
|
|
169
|
+
this.menuState.isOpen = true;
|
|
170
|
+
this.menuState.menuItems = registry.getAll().filter((x) => x.isVisible(this.env));
|
|
171
|
+
this.menuState.position = {
|
|
172
|
+
x,
|
|
173
|
+
y,
|
|
174
|
+
height: 400,
|
|
175
|
+
width: this.el!.clientWidth,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
onIconClick(sheet: string, ev: MouseEvent) {
|
|
180
|
+
if (this.getters.getActiveSheet() !== sheet) {
|
|
181
|
+
this.activateSheet(sheet);
|
|
182
|
+
}
|
|
183
|
+
if (this.menuState.isOpen) {
|
|
184
|
+
this.menuState.isOpen = false;
|
|
185
|
+
} else {
|
|
186
|
+
this.openContextMenu(
|
|
187
|
+
(ev.currentTarget as HTMLElement).parentElement as HTMLElement,
|
|
188
|
+
sheetMenuRegistry
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
onContextMenu(sheet: string, ev: MouseEvent) {
|
|
194
|
+
if (this.getters.getActiveSheet() !== sheet) {
|
|
195
|
+
this.activateSheet(sheet);
|
|
196
|
+
}
|
|
197
|
+
this.openContextMenu(ev.currentTarget as HTMLElement, sheetMenuRegistry);
|
|
198
|
+
}
|
|
199
|
+
}
|