@odoo/o-spreadsheet 14.0.1 → 15.0.0

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.
Files changed (203) hide show
  1. package/dist/o_spreadsheet.cjs.js +31302 -0
  2. package/dist/o_spreadsheet.d.ts +6604 -0
  3. package/dist/o_spreadsheet.esm.js +31257 -0
  4. package/dist/o_spreadsheet.iife.js +31304 -0
  5. package/dist/o_spreadsheet.iife.min.js +3071 -0
  6. package/package.json +57 -15
  7. package/.eslintrc.json +0 -20
  8. package/.husky/post-checkout +0 -9
  9. package/.husky/pre-commit +0 -39
  10. package/.prettierignore +0 -1
  11. package/astToFormula.patch +0 -0
  12. package/demo/data.js +0 -255
  13. package/demo/index.html +0 -9
  14. package/demo/libs/Chart.bundle.js +0 -20755
  15. package/demo/main.js +0 -101
  16. package/doc/readme.md +0 -46
  17. package/rollup.config.js +0 -23
  18. package/src/base_plugin.ts +0 -102
  19. package/src/components/autofill.ts +0 -146
  20. package/src/components/bottom_bar.ts +0 -199
  21. package/src/components/color_picker.ts +0 -150
  22. package/src/components/composer/autocomplete_dropdown.ts +0 -135
  23. package/src/components/composer/composer.ts +0 -487
  24. package/src/components/composer/content_editable_helper.ts +0 -146
  25. package/src/components/figures/chart.ts +0 -70
  26. package/src/components/figures/container.ts +0 -268
  27. package/src/components/figures/text_figure.ts +0 -36
  28. package/src/components/grid.ts +0 -635
  29. package/src/components/helpers/dom_helpers.ts +0 -7
  30. package/src/components/helpers/drag_and_drop.ts +0 -17
  31. package/src/components/icons.ts +0 -36
  32. package/src/components/index.ts +0 -1
  33. package/src/components/menu.ts +0 -288
  34. package/src/components/overlay.ts +0 -457
  35. package/src/components/scrollbar.ts +0 -22
  36. package/src/components/selection_input.ts +0 -168
  37. package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
  38. package/src/components/side_panel/chart_panel.ts +0 -104
  39. package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
  40. package/src/components/side_panel/conditional_formatting.ts +0 -396
  41. package/src/components/side_panel/side_panel.ts +0 -127
  42. package/src/components/side_panel/translations_terms.ts +0 -45
  43. package/src/components/spreadsheet.ts +0 -198
  44. package/src/components/top_bar.ts +0 -535
  45. package/src/constants.ts +0 -26
  46. package/src/data.ts +0 -149
  47. package/src/fonts.ts +0 -41
  48. package/src/formulas/compiler.ts +0 -258
  49. package/src/formulas/composer_tokenizer.ts +0 -70
  50. package/src/formulas/index.ts +0 -15
  51. package/src/formulas/normalize.ts +0 -52
  52. package/src/formulas/parser.ts +0 -280
  53. package/src/formulas/range_tokenizer.ts +0 -97
  54. package/src/formulas/tokenizer.ts +0 -242
  55. package/src/functions/arguments.ts +0 -114
  56. package/src/functions/dates.ts +0 -302
  57. package/src/functions/helpers.ts +0 -592
  58. package/src/functions/index.ts +0 -52
  59. package/src/functions/module_database.ts +0 -282
  60. package/src/functions/module_date.ts +0 -743
  61. package/src/functions/module_info.ts +0 -69
  62. package/src/functions/module_logical.ts +0 -208
  63. package/src/functions/module_lookup.ts +0 -185
  64. package/src/functions/module_math.ts +0 -1252
  65. package/src/functions/module_operators.ts +0 -291
  66. package/src/functions/module_statistical.ts +0 -882
  67. package/src/functions/module_text.ts +0 -370
  68. package/src/helpers/color.ts +0 -30
  69. package/src/helpers/coordinates.ts +0 -71
  70. package/src/helpers/grid_manipulation.ts +0 -68
  71. package/src/helpers/index.ts +0 -7
  72. package/src/helpers/misc.ts +0 -76
  73. package/src/helpers/numbers.ts +0 -117
  74. package/src/helpers/uuid.ts +0 -19
  75. package/src/helpers/zones.ts +0 -263
  76. package/src/history.ts +0 -186
  77. package/src/index.ts +0 -84
  78. package/src/model.ts +0 -261
  79. package/src/plugins/autofill.ts +0 -412
  80. package/src/plugins/chart.ts +0 -404
  81. package/src/plugins/clipboard.ts +0 -461
  82. package/src/plugins/conditional_format.ts +0 -445
  83. package/src/plugins/core.ts +0 -1502
  84. package/src/plugins/edition.ts +0 -157
  85. package/src/plugins/evaluation.ts +0 -428
  86. package/src/plugins/figures.ts +0 -123
  87. package/src/plugins/formatting.ts +0 -630
  88. package/src/plugins/highlight.ts +0 -187
  89. package/src/plugins/index.ts +0 -32
  90. package/src/plugins/merge.ts +0 -524
  91. package/src/plugins/renderer.ts +0 -571
  92. package/src/plugins/selection.ts +0 -562
  93. package/src/plugins/selection_inputs.ts +0 -326
  94. package/src/registries/autofill_modifiers.ts +0 -76
  95. package/src/registries/autofill_rules.ts +0 -98
  96. package/src/registries/figure_registry.ts +0 -30
  97. package/src/registries/index.ts +0 -7
  98. package/src/registries/menu_items_registry.ts +0 -110
  99. package/src/registries/menus/cell_menu_registry.ts +0 -79
  100. package/src/registries/menus/col_menu_registry.ts +0 -63
  101. package/src/registries/menus/index.ts +0 -6
  102. package/src/registries/menus/menu_items_actions.ts +0 -425
  103. package/src/registries/menus/row_menu_registry.ts +0 -63
  104. package/src/registries/menus/sheet_menu_registry.ts +0 -75
  105. package/src/registries/menus/topbar_menu_registry.ts +0 -204
  106. package/src/registries/side_panel_registry.ts +0 -26
  107. package/src/registries/topbar_component_registry.ts +0 -12
  108. package/src/registry.ts +0 -51
  109. package/src/translation.ts +0 -44
  110. package/src/types/autofill.ts +0 -48
  111. package/src/types/chart.ts +0 -26
  112. package/src/types/commands.ts +0 -716
  113. package/src/types/conditional_formatting.ts +0 -124
  114. package/src/types/env.ts +0 -13
  115. package/src/types/functions.ts +0 -35
  116. package/src/types/getters.ts +0 -103
  117. package/src/types/index.ts +0 -20
  118. package/src/types/misc.ts +0 -143
  119. package/src/types/rendering.ts +0 -41
  120. package/src/types/workbook_data.ts +0 -62
  121. package/tests/__mocks__/uuid.ts +0 -7
  122. package/tests/canvas.mock.ts +0 -34
  123. package/tests/components/__mocks__/content_editable_helper.ts +0 -79
  124. package/tests/components/__mocks__/scrollbar.ts +0 -18
  125. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
  126. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
  127. package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
  128. package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
  129. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
  130. package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
  131. package/tests/components/autocomplete_dropdown_test.ts +0 -315
  132. package/tests/components/autofill_test.ts +0 -167
  133. package/tests/components/bottom_bar_test.ts +0 -262
  134. package/tests/components/chart_side_panel_test.ts +0 -123
  135. package/tests/components/composer_test.ts +0 -400
  136. package/tests/components/context_menu_test.ts +0 -825
  137. package/tests/components/grid_manipulation_test.ts +0 -163
  138. package/tests/components/grid_test.ts +0 -581
  139. package/tests/components/overlay_test.ts +0 -541
  140. package/tests/components/selection_input_test.ts +0 -259
  141. package/tests/components/side_panel_test.ts +0 -148
  142. package/tests/components/spreadsheet_test.ts +0 -194
  143. package/tests/components/top_bar_test.ts +0 -427
  144. package/tests/data_test.ts +0 -175
  145. package/tests/dom_helper.ts +0 -42
  146. package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
  147. package/tests/formulas/compiler_test.ts +0 -266
  148. package/tests/formulas/composer_tokenizer_test.ts +0 -137
  149. package/tests/formulas/expressions_test.ts +0 -57
  150. package/tests/formulas/formulas_test.ts +0 -80
  151. package/tests/formulas/normalize_test.ts +0 -82
  152. package/tests/formulas/parser_test.ts +0 -224
  153. package/tests/formulas/range_tokenizer_test.ts +0 -187
  154. package/tests/formulas/tokenizer_test.ts +0 -164
  155. package/tests/functions/arguments_test.ts +0 -141
  156. package/tests/functions/dates_test.ts +0 -1081
  157. package/tests/functions/functions_test.ts +0 -53
  158. package/tests/functions/helper_test.ts +0 -98
  159. package/tests/functions/module_database_test.ts +0 -311
  160. package/tests/functions/module_date_test.ts +0 -941
  161. package/tests/functions/module_info_test.ts +0 -139
  162. package/tests/functions/module_logical_test.ts +0 -369
  163. package/tests/functions/module_lookup_test.ts +0 -541
  164. package/tests/functions/module_math_test.ts +0 -2482
  165. package/tests/functions/module_operators_test.ts +0 -955
  166. package/tests/functions/module_statistical_test.ts +0 -2014
  167. package/tests/functions/module_text_test.ts +0 -667
  168. package/tests/helpers/coordinates_test.ts +0 -25
  169. package/tests/helpers/misc_test.ts +0 -95
  170. package/tests/helpers/numbers_test.ts +0 -196
  171. package/tests/helpers/zones_test.ts +0 -97
  172. package/tests/helpers.ts +0 -384
  173. package/tests/menu_items_registry_test.ts +0 -540
  174. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
  175. package/tests/model/plugins/chart_test.ts +0 -562
  176. package/tests/model_test.ts +0 -82
  177. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
  178. package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
  179. package/tests/plugins/autofill_test.ts +0 -457
  180. package/tests/plugins/borders_test.ts +0 -295
  181. package/tests/plugins/clipboard_test.ts +0 -1180
  182. package/tests/plugins/conditional_formatting_test.ts +0 -1253
  183. package/tests/plugins/core_test.ts +0 -614
  184. package/tests/plugins/edition_test.ts +0 -100
  185. package/tests/plugins/evaluation_async_test.ts +0 -332
  186. package/tests/plugins/evaluation_dates_test.ts +0 -79
  187. package/tests/plugins/evaluation_test.ts +0 -901
  188. package/tests/plugins/figures_test.ts +0 -327
  189. package/tests/plugins/formatting_test.ts +0 -391
  190. package/tests/plugins/grid_manipulation_test.ts +0 -1366
  191. package/tests/plugins/highlight_test.ts +0 -413
  192. package/tests/plugins/history_test.ts +0 -142
  193. package/tests/plugins/import_export_test.ts +0 -276
  194. package/tests/plugins/merges_test.ts +0 -490
  195. package/tests/plugins/navigation_test.ts +0 -181
  196. package/tests/plugins/plugins/evaluation_test.ts +0 -111
  197. package/tests/plugins/renderer_test.ts +0 -598
  198. package/tests/plugins/resizing_test.ts +0 -152
  199. package/tests/plugins/selection_input_test.ts +0 -409
  200. package/tests/plugins/selection_test.ts +0 -442
  201. package/tests/plugins/sheets_test.ts +0 -643
  202. package/tests/plugins/style_test.ts +0 -90
  203. package/tsconfig.json +0 -22
package/demo/main.js DELETED
@@ -1,101 +0,0 @@
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 DELETED
@@ -1,46 +0,0 @@
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/rollup.config.js DELETED
@@ -1,23 +0,0 @@
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
- };
@@ -1,102 +0,0 @@
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
- }
@@ -1,146 +0,0 @@
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
- }
@@ -1,199 +0,0 @@
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
- }