@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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { _lt } from "../../translation";
|
|
2
|
+
import { SpreadsheetEnv } from "../../types";
|
|
3
|
+
import { MenuItemRegistry } from "../menu_items_registry";
|
|
4
|
+
import * as ACTIONS from "./menu_items_actions";
|
|
5
|
+
|
|
6
|
+
//------------------------------------------------------------------------------
|
|
7
|
+
// Context Menu Registry
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
export const cellMenuRegistry = new MenuItemRegistry();
|
|
11
|
+
|
|
12
|
+
cellMenuRegistry
|
|
13
|
+
.add("cut", {
|
|
14
|
+
name: _lt("Cut"),
|
|
15
|
+
sequence: 10,
|
|
16
|
+
action: ACTIONS.CUT_ACTION,
|
|
17
|
+
})
|
|
18
|
+
.add("copy", {
|
|
19
|
+
name: _lt("Copy"),
|
|
20
|
+
sequence: 20,
|
|
21
|
+
action: ACTIONS.COPY_ACTION,
|
|
22
|
+
})
|
|
23
|
+
.add("paste", {
|
|
24
|
+
name: _lt("Paste"),
|
|
25
|
+
sequence: 30,
|
|
26
|
+
action: ACTIONS.PASTE_ACTION,
|
|
27
|
+
})
|
|
28
|
+
.add("paste_special", {
|
|
29
|
+
name: _lt("Paste special"),
|
|
30
|
+
sequence: 40,
|
|
31
|
+
separator: true,
|
|
32
|
+
})
|
|
33
|
+
.addChild("paste_value_only", ["paste_special"], {
|
|
34
|
+
name: _lt("Paste values only"),
|
|
35
|
+
sequence: 10,
|
|
36
|
+
action: ACTIONS.PASTE_VALUE_ACTION,
|
|
37
|
+
})
|
|
38
|
+
.addChild("paste_format_only", ["paste_special"], {
|
|
39
|
+
name: _lt("Paste format only"),
|
|
40
|
+
sequence: 20,
|
|
41
|
+
action: ACTIONS.PASTE_FORMAT_ACTION,
|
|
42
|
+
})
|
|
43
|
+
.add("add_row_before", {
|
|
44
|
+
name: ACTIONS.CELL_INSERT_ROWS_BEFORE_NAME,
|
|
45
|
+
sequence: 50,
|
|
46
|
+
action: ACTIONS.INSERT_ROWS_BEFORE_ACTION,
|
|
47
|
+
})
|
|
48
|
+
.add("add_column_before", {
|
|
49
|
+
name: ACTIONS.CELL_INSERT_COLUMNS_BEFORE_NAME,
|
|
50
|
+
sequence: 70,
|
|
51
|
+
action: ACTIONS.INSERT_COLUMNS_BEFORE_ACTION,
|
|
52
|
+
separator: true,
|
|
53
|
+
})
|
|
54
|
+
.add("delete_row", {
|
|
55
|
+
name: ACTIONS.REMOVE_ROWS_NAME,
|
|
56
|
+
sequence: 90,
|
|
57
|
+
action: ACTIONS.REMOVE_ROWS_ACTION,
|
|
58
|
+
})
|
|
59
|
+
.add("delete_column", {
|
|
60
|
+
name: ACTIONS.REMOVE_COLUMNS_NAME,
|
|
61
|
+
sequence: 100,
|
|
62
|
+
action: ACTIONS.REMOVE_COLUMNS_ACTION,
|
|
63
|
+
separator: true,
|
|
64
|
+
})
|
|
65
|
+
.add("clear_cell", {
|
|
66
|
+
name: _lt("Clear cell"),
|
|
67
|
+
sequence: 110,
|
|
68
|
+
action: ACTIONS.DELETE_CONTENT_ACTION,
|
|
69
|
+
isEnabled: (env: SpreadsheetEnv) => {
|
|
70
|
+
const cell = env.getters.getActiveCell();
|
|
71
|
+
return Boolean(cell && cell.content);
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
.add("conditional_formatting", {
|
|
75
|
+
name: _lt("Conditional formatting"),
|
|
76
|
+
sequence: 120,
|
|
77
|
+
action: ACTIONS.OPEN_CF_SIDEPANEL_ACTION,
|
|
78
|
+
separator: true,
|
|
79
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { _lt } from "../../translation";
|
|
2
|
+
import { MenuItemRegistry } from "../menu_items_registry";
|
|
3
|
+
import * as ACTIONS from "./menu_items_actions";
|
|
4
|
+
|
|
5
|
+
export const colMenuRegistry = new MenuItemRegistry();
|
|
6
|
+
|
|
7
|
+
colMenuRegistry
|
|
8
|
+
.add("cut", {
|
|
9
|
+
name: _lt("Cut"),
|
|
10
|
+
sequence: 10,
|
|
11
|
+
action: ACTIONS.CUT_ACTION,
|
|
12
|
+
})
|
|
13
|
+
.add("copy", {
|
|
14
|
+
name: _lt("Copy"),
|
|
15
|
+
sequence: 20,
|
|
16
|
+
action: ACTIONS.COPY_ACTION,
|
|
17
|
+
})
|
|
18
|
+
.add("paste", {
|
|
19
|
+
name: _lt("Paste"),
|
|
20
|
+
sequence: 30,
|
|
21
|
+
action: ACTIONS.PASTE_ACTION,
|
|
22
|
+
})
|
|
23
|
+
.add("paste_special", {
|
|
24
|
+
name: _lt("Paste special"),
|
|
25
|
+
sequence: 40,
|
|
26
|
+
separator: true,
|
|
27
|
+
})
|
|
28
|
+
.addChild("paste_value_only", ["paste_special"], {
|
|
29
|
+
name: _lt("Paste value only"),
|
|
30
|
+
sequence: 10,
|
|
31
|
+
action: ACTIONS.PASTE_VALUE_ACTION,
|
|
32
|
+
})
|
|
33
|
+
.addChild("paste_format_only", ["paste_special"], {
|
|
34
|
+
name: _lt("Paste format only"),
|
|
35
|
+
sequence: 20,
|
|
36
|
+
action: ACTIONS.PASTE_FORMAT_ACTION,
|
|
37
|
+
})
|
|
38
|
+
.add("add_column_before", {
|
|
39
|
+
name: ACTIONS.COLUMN_INSERT_COLUMNS_BEFORE_NAME,
|
|
40
|
+
sequence: 50,
|
|
41
|
+
action: ACTIONS.INSERT_COLUMNS_BEFORE_ACTION,
|
|
42
|
+
})
|
|
43
|
+
.add("add_column_after", {
|
|
44
|
+
name: ACTIONS.COLUMN_INSERT_COLUMNS_AFTER_NAME,
|
|
45
|
+
sequence: 60,
|
|
46
|
+
action: ACTIONS.INSERT_COLUMNS_AFTER_ACTION,
|
|
47
|
+
})
|
|
48
|
+
.add("delete_column", {
|
|
49
|
+
name: ACTIONS.REMOVE_COLUMNS_NAME,
|
|
50
|
+
sequence: 70,
|
|
51
|
+
action: ACTIONS.REMOVE_COLUMNS_ACTION,
|
|
52
|
+
})
|
|
53
|
+
.add("clear_column", {
|
|
54
|
+
name: ACTIONS.DELETE_CONTENT_COLUMNS_NAME,
|
|
55
|
+
sequence: 80,
|
|
56
|
+
action: ACTIONS.DELETE_CONTENT_COLUMNS_ACTION,
|
|
57
|
+
separator: true,
|
|
58
|
+
})
|
|
59
|
+
.add("conditional_formatting", {
|
|
60
|
+
name: _lt("Conditional formatting"),
|
|
61
|
+
sequence: 90,
|
|
62
|
+
action: ACTIONS.OPEN_CF_SIDEPANEL_ACTION,
|
|
63
|
+
});
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { numberToLetters, uuidv4 } from "../../helpers/index";
|
|
2
|
+
import { _lt } from "../../translation";
|
|
3
|
+
import { SpreadsheetEnv, Style } from "../../types/index";
|
|
4
|
+
|
|
5
|
+
//------------------------------------------------------------------------------
|
|
6
|
+
// Helpers
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
function getColumnsNumber(env: SpreadsheetEnv): number {
|
|
10
|
+
const activeCols = env.getters.getActiveCols();
|
|
11
|
+
if (activeCols.size) {
|
|
12
|
+
return activeCols.size;
|
|
13
|
+
} else {
|
|
14
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
15
|
+
return zone.right - zone.left + 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getRowsNumber(env: SpreadsheetEnv): number {
|
|
20
|
+
const activeRows = env.getters.getActiveRows();
|
|
21
|
+
if (activeRows.size) {
|
|
22
|
+
return activeRows.size;
|
|
23
|
+
} else {
|
|
24
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
25
|
+
return zone.bottom - zone.top + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function setFormatter(env: SpreadsheetEnv, formatter: string) {
|
|
30
|
+
env.dispatch("SET_FORMATTER", {
|
|
31
|
+
sheet: env.getters.getActiveSheet(),
|
|
32
|
+
target: env.getters.getSelectedZones(),
|
|
33
|
+
formatter,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function setStyle(env: SpreadsheetEnv, style: Style) {
|
|
38
|
+
env.dispatch("SET_FORMATTING", {
|
|
39
|
+
sheet: env.getters.getActiveSheet(),
|
|
40
|
+
target: env.getters.getSelectedZones(),
|
|
41
|
+
style,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//------------------------------------------------------------------------------
|
|
46
|
+
// Simple actions
|
|
47
|
+
//------------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
export const UNDO_ACTION = (env: SpreadsheetEnv) => env.dispatch("UNDO");
|
|
50
|
+
|
|
51
|
+
export const REDO_ACTION = (env: SpreadsheetEnv) => env.dispatch("REDO");
|
|
52
|
+
|
|
53
|
+
export const COPY_ACTION = async (env: SpreadsheetEnv) => {
|
|
54
|
+
env.dispatch("COPY", { target: env.getters.getSelectedZones() });
|
|
55
|
+
await env.clipboard.writeText(env.getters.getClipboardContent());
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const CUT_ACTION = async (env: SpreadsheetEnv) => {
|
|
59
|
+
env.dispatch("CUT", { target: env.getters.getSelectedZones() });
|
|
60
|
+
await env.clipboard.writeText(env.getters.getClipboardContent());
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const PASTE_ACTION = async (env: SpreadsheetEnv) => {
|
|
64
|
+
const spreadsheetClipboard = env.getters.getClipboardContent();
|
|
65
|
+
let osClipboard;
|
|
66
|
+
try {
|
|
67
|
+
osClipboard = await env.clipboard.readText();
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// Permission is required to read the clipboard.
|
|
70
|
+
console.warn("The OS clipboard could not be read.");
|
|
71
|
+
console.error(e);
|
|
72
|
+
}
|
|
73
|
+
const target = env.getters.getSelectedZones();
|
|
74
|
+
if (osClipboard && osClipboard !== spreadsheetClipboard) {
|
|
75
|
+
env.dispatch("PASTE_FROM_OS_CLIPBOARD", {
|
|
76
|
+
target,
|
|
77
|
+
text: osClipboard,
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
env.dispatch("PASTE", { target, interactive: true });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const PASTE_VALUE_ACTION = (env: SpreadsheetEnv) =>
|
|
85
|
+
env.dispatch("PASTE", { target: env.getters.getSelectedZones(), onlyValue: true });
|
|
86
|
+
|
|
87
|
+
export const PASTE_FORMAT_ACTION = (env: SpreadsheetEnv) =>
|
|
88
|
+
env.dispatch("PASTE", { target: env.getters.getSelectedZones(), onlyFormat: true });
|
|
89
|
+
|
|
90
|
+
export const DELETE_CONTENT_ACTION = (env: SpreadsheetEnv) =>
|
|
91
|
+
env.dispatch("DELETE_CONTENT", {
|
|
92
|
+
sheet: env.getters.getActiveSheet(),
|
|
93
|
+
target: env.getters.getSelectedZones(),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const SET_FORMULA_VISIBILITY_ACTION = (env: SpreadsheetEnv) =>
|
|
97
|
+
env.dispatch("SET_FORMULA_VISIBILITY", { show: !env.getters.shouldShowFormulas() });
|
|
98
|
+
|
|
99
|
+
//------------------------------------------------------------------------------
|
|
100
|
+
// Grid manipulations
|
|
101
|
+
//------------------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
export const DELETE_CONTENT_ROWS_NAME = (env: SpreadsheetEnv) => {
|
|
104
|
+
let first: number;
|
|
105
|
+
let last: number;
|
|
106
|
+
const activesRows = env.getters.getActiveRows();
|
|
107
|
+
if (activesRows.size !== 0) {
|
|
108
|
+
first = Math.min(...activesRows);
|
|
109
|
+
last = Math.max(...activesRows);
|
|
110
|
+
} else {
|
|
111
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
112
|
+
first = zone.top;
|
|
113
|
+
last = zone.bottom;
|
|
114
|
+
}
|
|
115
|
+
if (first === last) {
|
|
116
|
+
return _lt("Clear row %s", (first + 1).toString());
|
|
117
|
+
}
|
|
118
|
+
return _lt("Clear rows %s - %s", (first + 1).toString(), (last + 1).toString());
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const DELETE_CONTENT_ROWS_ACTION = (env: SpreadsheetEnv) => {
|
|
122
|
+
const target = [...env.getters.getActiveRows()].map((index) =>
|
|
123
|
+
env.getters.getRowsZone(index, index)
|
|
124
|
+
);
|
|
125
|
+
env.dispatch("DELETE_CONTENT", {
|
|
126
|
+
target,
|
|
127
|
+
sheet: env.getters.getActiveSheet(),
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const DELETE_CONTENT_COLUMNS_NAME = (env: SpreadsheetEnv) => {
|
|
132
|
+
let first: number;
|
|
133
|
+
let last: number;
|
|
134
|
+
const activeCols = env.getters.getActiveCols();
|
|
135
|
+
if (activeCols.size !== 0) {
|
|
136
|
+
first = Math.min(...activeCols);
|
|
137
|
+
last = Math.max(...activeCols);
|
|
138
|
+
} else {
|
|
139
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
140
|
+
first = zone.left;
|
|
141
|
+
last = zone.right;
|
|
142
|
+
}
|
|
143
|
+
if (first === last) {
|
|
144
|
+
return _lt("Clear column %s", numberToLetters(first));
|
|
145
|
+
}
|
|
146
|
+
return _lt("Clear columns %s - %s", numberToLetters(first), numberToLetters(last));
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const DELETE_CONTENT_COLUMNS_ACTION = (env: SpreadsheetEnv) => {
|
|
150
|
+
const target = [...env.getters.getActiveCols()].map((index) =>
|
|
151
|
+
env.getters.getColsZone(index, index)
|
|
152
|
+
);
|
|
153
|
+
env.dispatch("DELETE_CONTENT", {
|
|
154
|
+
target,
|
|
155
|
+
sheet: env.getters.getActiveSheet(),
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const REMOVE_ROWS_NAME = (env: SpreadsheetEnv) => {
|
|
160
|
+
let first: number;
|
|
161
|
+
let last: number;
|
|
162
|
+
const activesRows = env.getters.getActiveRows();
|
|
163
|
+
if (activesRows.size !== 0) {
|
|
164
|
+
first = Math.min(...activesRows);
|
|
165
|
+
last = Math.max(...activesRows);
|
|
166
|
+
} else {
|
|
167
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
168
|
+
first = zone.top;
|
|
169
|
+
last = zone.bottom;
|
|
170
|
+
}
|
|
171
|
+
if (first === last) {
|
|
172
|
+
return _lt("Delete row %s", (first + 1).toString());
|
|
173
|
+
}
|
|
174
|
+
return _lt("Delete rows %s - %s", (first + 1).toString(), (last + 1).toString());
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const REMOVE_ROWS_ACTION = (env: SpreadsheetEnv) => {
|
|
178
|
+
let rows = [...env.getters.getActiveRows()];
|
|
179
|
+
if (!rows.length) {
|
|
180
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
181
|
+
for (let i = zone.top; i <= zone.bottom; i++) {
|
|
182
|
+
rows.push(i);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
env.dispatch("REMOVE_ROWS", {
|
|
186
|
+
sheet: env.getters.getActiveSheet(),
|
|
187
|
+
rows,
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const REMOVE_COLUMNS_NAME = (env: SpreadsheetEnv) => {
|
|
192
|
+
let first: number;
|
|
193
|
+
let last: number;
|
|
194
|
+
const activeCols = env.getters.getActiveCols();
|
|
195
|
+
if (activeCols.size !== 0) {
|
|
196
|
+
first = Math.min(...activeCols);
|
|
197
|
+
last = Math.max(...activeCols);
|
|
198
|
+
} else {
|
|
199
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
200
|
+
first = zone.left;
|
|
201
|
+
last = zone.right;
|
|
202
|
+
}
|
|
203
|
+
if (first === last) {
|
|
204
|
+
return _lt("Delete column %s", numberToLetters(first));
|
|
205
|
+
}
|
|
206
|
+
return _lt("Delete columns %s - %s", numberToLetters(first), numberToLetters(last));
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export const REMOVE_COLUMNS_ACTION = (env: SpreadsheetEnv) => {
|
|
210
|
+
let columns = [...env.getters.getActiveCols()];
|
|
211
|
+
if (!columns.length) {
|
|
212
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
213
|
+
for (let i = zone.left; i <= zone.right; i++) {
|
|
214
|
+
columns.push(i);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
env.dispatch("REMOVE_COLUMNS", {
|
|
218
|
+
sheet: env.getters.getActiveSheet(),
|
|
219
|
+
columns,
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const MENU_INSERT_ROWS_BEFORE_NAME = (env: SpreadsheetEnv) => {
|
|
224
|
+
const number = getRowsNumber(env);
|
|
225
|
+
if (number === 1) {
|
|
226
|
+
return _lt("Row above");
|
|
227
|
+
}
|
|
228
|
+
return _lt("%s Rows above", number.toString());
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export const ROW_INSERT_ROWS_BEFORE_NAME = (env: SpreadsheetEnv) => {
|
|
232
|
+
const number = getRowsNumber(env);
|
|
233
|
+
return number === 1 ? _lt("Insert row above") : _lt("Insert %s rows above", number.toString());
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export const CELL_INSERT_ROWS_BEFORE_NAME = (env: SpreadsheetEnv) => {
|
|
237
|
+
const number = getRowsNumber(env);
|
|
238
|
+
if (number === 1) {
|
|
239
|
+
return _lt("Insert row");
|
|
240
|
+
}
|
|
241
|
+
return _lt("Insert %s rows", number.toString());
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export const INSERT_ROWS_BEFORE_ACTION = (env: SpreadsheetEnv) => {
|
|
245
|
+
const activeRows = env.getters.getActiveRows();
|
|
246
|
+
let row: number;
|
|
247
|
+
let quantity: number;
|
|
248
|
+
if (activeRows.size) {
|
|
249
|
+
row = Math.min(...activeRows);
|
|
250
|
+
quantity = activeRows.size;
|
|
251
|
+
} else {
|
|
252
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
253
|
+
row = zone.top;
|
|
254
|
+
quantity = zone.bottom - zone.top + 1;
|
|
255
|
+
}
|
|
256
|
+
env.dispatch("ADD_ROWS", {
|
|
257
|
+
sheet: env.getters.getActiveSheet(),
|
|
258
|
+
position: "before",
|
|
259
|
+
row,
|
|
260
|
+
quantity,
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export const MENU_INSERT_ROWS_AFTER_NAME = (env: SpreadsheetEnv) => {
|
|
265
|
+
const number = getRowsNumber(env);
|
|
266
|
+
if (number === 1) {
|
|
267
|
+
return _lt("Row below");
|
|
268
|
+
}
|
|
269
|
+
return _lt("%s Rows below", number.toString());
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export const ROW_INSERT_ROWS_AFTER_NAME = (env: SpreadsheetEnv) => {
|
|
273
|
+
const number = getRowsNumber(env);
|
|
274
|
+
return number === 1 ? _lt("Insert row below") : _lt("Insert %s rows below", number.toString());
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export const INSERT_ROWS_AFTER_ACTION = (env: SpreadsheetEnv) => {
|
|
278
|
+
const activeRows = env.getters.getActiveRows();
|
|
279
|
+
let row: number;
|
|
280
|
+
let quantity: number;
|
|
281
|
+
if (activeRows.size) {
|
|
282
|
+
row = Math.max(...activeRows);
|
|
283
|
+
quantity = activeRows.size;
|
|
284
|
+
} else {
|
|
285
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
286
|
+
row = zone.bottom;
|
|
287
|
+
quantity = zone.bottom - zone.top + 1;
|
|
288
|
+
}
|
|
289
|
+
env.dispatch("ADD_ROWS", {
|
|
290
|
+
sheet: env.getters.getActiveSheet(),
|
|
291
|
+
position: "after",
|
|
292
|
+
row,
|
|
293
|
+
quantity,
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export const MENU_INSERT_COLUMNS_BEFORE_NAME = (env: SpreadsheetEnv) => {
|
|
298
|
+
const number = getColumnsNumber(env);
|
|
299
|
+
if (number === 1) {
|
|
300
|
+
return _lt("Column left");
|
|
301
|
+
}
|
|
302
|
+
return _lt("%s Columns left", number.toString());
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export const COLUMN_INSERT_COLUMNS_BEFORE_NAME = (env: SpreadsheetEnv) => {
|
|
306
|
+
const number = getColumnsNumber(env);
|
|
307
|
+
return number === 1
|
|
308
|
+
? _lt("Insert column left")
|
|
309
|
+
: _lt("Insert %s columns left", number.toString());
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export const CELL_INSERT_COLUMNS_BEFORE_NAME = (env: SpreadsheetEnv) => {
|
|
313
|
+
const number = getColumnsNumber(env);
|
|
314
|
+
if (number === 1) {
|
|
315
|
+
return _lt("Insert column");
|
|
316
|
+
}
|
|
317
|
+
return _lt("Insert %s columns", number.toString());
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const INSERT_COLUMNS_BEFORE_ACTION = (env: SpreadsheetEnv) => {
|
|
321
|
+
const activeCols = env.getters.getActiveCols();
|
|
322
|
+
let column: number;
|
|
323
|
+
let quantity: number;
|
|
324
|
+
if (activeCols.size) {
|
|
325
|
+
column = Math.min(...activeCols);
|
|
326
|
+
quantity = activeCols.size;
|
|
327
|
+
} else {
|
|
328
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
329
|
+
column = zone.left;
|
|
330
|
+
quantity = zone.right - zone.left + 1;
|
|
331
|
+
}
|
|
332
|
+
env.dispatch("ADD_COLUMNS", {
|
|
333
|
+
sheet: env.getters.getActiveSheet(),
|
|
334
|
+
position: "before",
|
|
335
|
+
column,
|
|
336
|
+
quantity,
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export const MENU_INSERT_COLUMNS_AFTER_NAME = (env: SpreadsheetEnv) => {
|
|
341
|
+
const number = getColumnsNumber(env);
|
|
342
|
+
if (number === 1) {
|
|
343
|
+
return _lt("Column right");
|
|
344
|
+
}
|
|
345
|
+
return _lt("%s Columns right", number.toString());
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export const COLUMN_INSERT_COLUMNS_AFTER_NAME = (env: SpreadsheetEnv) => {
|
|
349
|
+
const number = getColumnsNumber(env);
|
|
350
|
+
return number === 1
|
|
351
|
+
? _lt("Insert column right")
|
|
352
|
+
: _lt("Insert %s columns right", number.toString());
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export const INSERT_COLUMNS_AFTER_ACTION = (env: SpreadsheetEnv) => {
|
|
356
|
+
const activeCols = env.getters.getActiveCols();
|
|
357
|
+
let column: number;
|
|
358
|
+
let quantity: number;
|
|
359
|
+
if (activeCols.size) {
|
|
360
|
+
column = Math.max(...activeCols);
|
|
361
|
+
quantity = activeCols.size;
|
|
362
|
+
} else {
|
|
363
|
+
const zone = env.getters.getSelectedZones()[0];
|
|
364
|
+
column = zone.right;
|
|
365
|
+
quantity = zone.right - zone.left + 1;
|
|
366
|
+
}
|
|
367
|
+
env.dispatch("ADD_COLUMNS", {
|
|
368
|
+
sheet: env.getters.getActiveSheet(),
|
|
369
|
+
position: "after",
|
|
370
|
+
column,
|
|
371
|
+
quantity,
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
//------------------------------------------------------------------------------
|
|
376
|
+
// Sheets
|
|
377
|
+
//------------------------------------------------------------------------------
|
|
378
|
+
|
|
379
|
+
export const CREATE_SHEET_ACTION = (env: SpreadsheetEnv) => {
|
|
380
|
+
env.dispatch("CREATE_SHEET", { activate: true, id: uuidv4() });
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
//------------------------------------------------------------------------------
|
|
384
|
+
// Charts
|
|
385
|
+
//------------------------------------------------------------------------------
|
|
386
|
+
|
|
387
|
+
export const CREATE_CHART = (env: SpreadsheetEnv) => {
|
|
388
|
+
env.openSidePanel("ChartPanel");
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
//------------------------------------------------------------------------------
|
|
392
|
+
// Style/Format
|
|
393
|
+
//------------------------------------------------------------------------------
|
|
394
|
+
|
|
395
|
+
export const FORMAT_AUTO_ACTION = (env: SpreadsheetEnv) => setFormatter(env, "");
|
|
396
|
+
|
|
397
|
+
export const FORMAT_NUMBER_ACTION = (env: SpreadsheetEnv) => setFormatter(env, "#,##0.00");
|
|
398
|
+
|
|
399
|
+
export const FORMAT_PERCENT_ACTION = (env: SpreadsheetEnv) => setFormatter(env, "0.00%");
|
|
400
|
+
|
|
401
|
+
export const FORMAT_DATE_ACTION = (env: SpreadsheetEnv) => setFormatter(env, "m/d/yyyy");
|
|
402
|
+
|
|
403
|
+
export const FORMAT_TIME_ACTION = (env: SpreadsheetEnv) => setFormatter(env, "hh:mm:ss a");
|
|
404
|
+
|
|
405
|
+
export const FORMAT_DATE_TIME_ACTION = (env: SpreadsheetEnv) =>
|
|
406
|
+
setFormatter(env, "m/d/yyyy hh:mm:ss");
|
|
407
|
+
|
|
408
|
+
export const FORMAT_DURATION_ACTION = (env: SpreadsheetEnv) => setFormatter(env, "hhhh:mm:ss");
|
|
409
|
+
|
|
410
|
+
export const FORMAT_BOLD_ACTION = (env: SpreadsheetEnv) =>
|
|
411
|
+
setStyle(env, { bold: !env.getters.getCurrentStyle().bold });
|
|
412
|
+
|
|
413
|
+
export const FORMAT_ITALIC_ACTION = (env: SpreadsheetEnv) =>
|
|
414
|
+
setStyle(env, { italic: !env.getters.getCurrentStyle().italic });
|
|
415
|
+
|
|
416
|
+
export const FORMAT_STRIKETHROUGH_ACTION = (env: SpreadsheetEnv) =>
|
|
417
|
+
setStyle(env, { strikethrough: !env.getters.getCurrentStyle().strikethrough });
|
|
418
|
+
|
|
419
|
+
//------------------------------------------------------------------------------
|
|
420
|
+
// Side panel
|
|
421
|
+
//------------------------------------------------------------------------------
|
|
422
|
+
|
|
423
|
+
export const OPEN_CF_SIDEPANEL_ACTION = (env: SpreadsheetEnv) => {
|
|
424
|
+
env.openSidePanel("ConditionalFormatting", { selection: env.getters.getSelectedZones() });
|
|
425
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { _lt } from "../../translation";
|
|
2
|
+
import { MenuItemRegistry } from "../menu_items_registry";
|
|
3
|
+
import * as ACTIONS from "./menu_items_actions";
|
|
4
|
+
|
|
5
|
+
export const rowMenuRegistry = new MenuItemRegistry();
|
|
6
|
+
|
|
7
|
+
rowMenuRegistry
|
|
8
|
+
.add("cut", {
|
|
9
|
+
name: _lt("Cut"),
|
|
10
|
+
sequence: 10,
|
|
11
|
+
action: ACTIONS.CUT_ACTION,
|
|
12
|
+
})
|
|
13
|
+
.add("copy", {
|
|
14
|
+
name: _lt("Copy"),
|
|
15
|
+
sequence: 20,
|
|
16
|
+
action: ACTIONS.COPY_ACTION,
|
|
17
|
+
})
|
|
18
|
+
.add("paste", {
|
|
19
|
+
name: _lt("Paste"),
|
|
20
|
+
sequence: 30,
|
|
21
|
+
action: ACTIONS.PASTE_ACTION,
|
|
22
|
+
})
|
|
23
|
+
.add("paste_special", {
|
|
24
|
+
name: _lt("Paste special"),
|
|
25
|
+
sequence: 40,
|
|
26
|
+
separator: true,
|
|
27
|
+
})
|
|
28
|
+
.addChild("paste_value_only", ["paste_special"], {
|
|
29
|
+
name: _lt("Paste value only"),
|
|
30
|
+
sequence: 10,
|
|
31
|
+
action: ACTIONS.PASTE_VALUE_ACTION,
|
|
32
|
+
})
|
|
33
|
+
.addChild("paste_format_only", ["paste_special"], {
|
|
34
|
+
name: _lt("Paste format only"),
|
|
35
|
+
sequence: 20,
|
|
36
|
+
action: ACTIONS.PASTE_FORMAT_ACTION,
|
|
37
|
+
})
|
|
38
|
+
.add("add_row_before", {
|
|
39
|
+
name: ACTIONS.ROW_INSERT_ROWS_BEFORE_NAME,
|
|
40
|
+
sequence: 50,
|
|
41
|
+
action: ACTIONS.INSERT_ROWS_BEFORE_ACTION,
|
|
42
|
+
})
|
|
43
|
+
.add("add_row_after", {
|
|
44
|
+
name: ACTIONS.ROW_INSERT_ROWS_AFTER_NAME,
|
|
45
|
+
sequence: 60,
|
|
46
|
+
action: ACTIONS.INSERT_ROWS_AFTER_ACTION,
|
|
47
|
+
})
|
|
48
|
+
.add("delete_row", {
|
|
49
|
+
name: ACTIONS.REMOVE_ROWS_NAME,
|
|
50
|
+
sequence: 70,
|
|
51
|
+
action: ACTIONS.REMOVE_ROWS_ACTION,
|
|
52
|
+
})
|
|
53
|
+
.add("clear_row", {
|
|
54
|
+
name: ACTIONS.DELETE_CONTENT_ROWS_NAME,
|
|
55
|
+
sequence: 80,
|
|
56
|
+
action: ACTIONS.DELETE_CONTENT_ROWS_ACTION,
|
|
57
|
+
separator: true,
|
|
58
|
+
})
|
|
59
|
+
.add("conditional_formatting", {
|
|
60
|
+
name: _lt("Conditional formatting"),
|
|
61
|
+
sequence: 90,
|
|
62
|
+
action: ACTIONS.OPEN_CF_SIDEPANEL_ACTION,
|
|
63
|
+
});
|