@odoo/o-spreadsheet 1.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 +78 -0
- package/readme.md +39 -0
- 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
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@odoo/o-spreadsheet",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A spreadsheet component",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"serve": "live-server --open=demo",
|
|
8
|
+
"dev": "npm-run-all build --parallel serve \"build:* -- --watch\"",
|
|
9
|
+
"build:js": "tsc --module es6 --outDir dist/js --incremental",
|
|
10
|
+
"build:all": "tsc --module es6 --outDir dist/js",
|
|
11
|
+
"build:bundle": "rollup -c -m",
|
|
12
|
+
"build": "npm run build:js && npm run build:bundle",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"test:watch": "jest --watch",
|
|
15
|
+
"prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,demo/*.js} --write",
|
|
16
|
+
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,demo/*.js} --check",
|
|
17
|
+
"dist": "npm run build:all && npm run build:bundle",
|
|
18
|
+
"prepare": "husky install"
|
|
19
|
+
},
|
|
20
|
+
"browserslist": [
|
|
21
|
+
"last 1 Chrome versions"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"owl",
|
|
25
|
+
"spreadsheet",
|
|
26
|
+
"odoo"
|
|
27
|
+
],
|
|
28
|
+
"author": "Gery Debongnie",
|
|
29
|
+
"license": "LGPL-3.0-or-later",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/chart.js": "^2.9.24",
|
|
32
|
+
"@types/jest": "^27.0.1",
|
|
33
|
+
"@types/node": "^13.11.1",
|
|
34
|
+
"babel-eslint": "^10.1.0",
|
|
35
|
+
"eslint": "^6.8.0",
|
|
36
|
+
"git-rev-sync": "^2.0.0",
|
|
37
|
+
"husky": "^7.0.4",
|
|
38
|
+
"jest": "^27.2.0",
|
|
39
|
+
"jest-environment-jsdom": "^27.2.0",
|
|
40
|
+
"lint-staged": "^12.1.2",
|
|
41
|
+
"live-server": "^1.2.1",
|
|
42
|
+
"mockdate": "^3.0.2",
|
|
43
|
+
"npm-run-all": "^4.1.5",
|
|
44
|
+
"prettier": "2.3.1",
|
|
45
|
+
"rollup": "^2.38.5",
|
|
46
|
+
"ts-jest": "^27.0.5",
|
|
47
|
+
"typescript": "^4.4.3"
|
|
48
|
+
},
|
|
49
|
+
"prettier": {
|
|
50
|
+
"printWidth": 100
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@odoo/owl": "^1.4.10"
|
|
54
|
+
},
|
|
55
|
+
"jest": {
|
|
56
|
+
"roots": [
|
|
57
|
+
"<rootDir>/src",
|
|
58
|
+
"<rootDir>/tests"
|
|
59
|
+
],
|
|
60
|
+
"transform": {
|
|
61
|
+
"^.+\\.ts?$": "ts-jest"
|
|
62
|
+
},
|
|
63
|
+
"verbose": false,
|
|
64
|
+
"testEnvironment": "jsdom",
|
|
65
|
+
"testRegex": "(/tests/.*(test|spec))\\.ts?$",
|
|
66
|
+
"moduleFileExtensions": [
|
|
67
|
+
"ts",
|
|
68
|
+
"tsx",
|
|
69
|
+
"js",
|
|
70
|
+
"jsx",
|
|
71
|
+
"json",
|
|
72
|
+
"node"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"lint-staged": {
|
|
76
|
+
"{src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,demo/*.js}": "prettier --write"
|
|
77
|
+
}
|
|
78
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# o-spreadsheet
|
|
2
|
+
|
|
3
|
+
a.k.a. "Owly Sheet"
|
|
4
|
+
|
|
5
|
+
Spreadsheet component, written in Owl.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
install nodejs 12.0 at least
|
|
10
|
+
|
|
11
|
+
## Scripts
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# install dependencies
|
|
15
|
+
npm install
|
|
16
|
+
|
|
17
|
+
# build o_spreadsheet.js in dist/
|
|
18
|
+
npm run build
|
|
19
|
+
|
|
20
|
+
# build stuff, start a live server, build with --watch
|
|
21
|
+
npm run dev
|
|
22
|
+
|
|
23
|
+
# run the test suite
|
|
24
|
+
npm run test
|
|
25
|
+
npm run test -- --watch
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Code
|
|
29
|
+
|
|
30
|
+
Most of the code is contained in the following four modules:
|
|
31
|
+
|
|
32
|
+
- `formulas`
|
|
33
|
+
- `functions`
|
|
34
|
+
- `model`
|
|
35
|
+
- `ui`
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
See [documentation](doc/readme.md).
|
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
|
+
}
|