diff --git a/addons/spreadsheet/static/src/actions/spreadsheet_download_action.js b/addons/spreadsheet/static/src/actions/spreadsheet_download_action.js index d5cc51305f5..7eb1fe08c39 100644 --- a/addons/spreadsheet/static/src/actions/spreadsheet_download_action.js +++ b/addons/spreadsheet/static/src/actions/spreadsheet_download_action.js @@ -13,7 +13,7 @@ const { Model } = spreadsheet; async function downloadSpreadsheet(env, action) { const { orm, name, data, stateUpdateMessages } = action.params; const dataSources = new DataSources(orm); - const model = new Model(migrate(data), { dataSources }, stateUpdateMessages); + const model = new Model(migrate(data), { external: { dataSources } }, stateUpdateMessages); await dataSources.waitForAllLoaded(); await waitForDataLoaded(model); const { files } = model.exportXLSX(); diff --git a/addons/spreadsheet/static/src/chart/plugins/chart_odoo_menu_plugin.js b/addons/spreadsheet/static/src/chart/plugins/chart_odoo_menu_plugin.js index b2acb6317af..8139a1a07db 100644 --- a/addons/spreadsheet/static/src/chart/plugins/chart_odoo_menu_plugin.js +++ b/addons/spreadsheet/static/src/chart/plugins/chart_odoo_menu_plugin.js @@ -5,8 +5,8 @@ const { coreTypes } = spreadsheet; /** Plugin that link charts with Odoo menus. It can contain either the Id of the odoo menu, or its xml id. */ export default class ChartOdooMenuPlugin extends spreadsheet.CorePlugin { - constructor() { - super(...arguments); + constructor(config) { + super(config); this.odooMenuReference = {}; } diff --git a/addons/spreadsheet/static/src/chart/plugins/odoo_chart_core_plugin.js b/addons/spreadsheet/static/src/chart/plugins/odoo_chart_core_plugin.js index 93ca305968f..38b32b6ee00 100644 --- a/addons/spreadsheet/static/src/chart/plugins/odoo_chart_core_plugin.js +++ b/addons/spreadsheet/static/src/chart/plugins/odoo_chart_core_plugin.js @@ -16,9 +16,9 @@ const { CorePlugin } = spreadsheet; */ export default class OdooChartCorePlugin extends CorePlugin { - constructor(getters, history, range, dispatch, config, uuidGenerator) { - super(getters, history, range, dispatch, config, uuidGenerator); - this.dataSources = config.dataSources; + constructor(config) { + super(config); + this.dataSources = config.external.dataSources; /** @type {Object.} */ this.charts = {}; diff --git a/addons/spreadsheet/static/src/currency/plugins/currency.js b/addons/spreadsheet/static/src/currency/plugins/currency.js index 8e5bde59cd7..cb3f7b095b1 100644 --- a/addons/spreadsheet/static/src/currency/plugins/currency.js +++ b/addons/spreadsheet/static/src/currency/plugins/currency.js @@ -11,9 +11,9 @@ const DATA_SOURCE_ID = "CURRENCIES"; */ class CurrencyPlugin extends spreadsheet.UIPlugin { - constructor(getters, history, dispatch, config) { - super(getters, history, dispatch, config); - this.dataSources = config.dataSources; + constructor(config) { + super(config); + this.dataSources = config.external.dataSources; if (this.dataSources) { this.dataSources.add(DATA_SOURCE_ID, CurrencyDataSource); } diff --git a/addons/spreadsheet/static/src/global_filters/plugins/global_filters_core_plugin.js b/addons/spreadsheet/static/src/global_filters/plugins/global_filters_core_plugin.js index fff18246cd6..89672629265 100644 --- a/addons/spreadsheet/static/src/global_filters/plugins/global_filters_core_plugin.js +++ b/addons/spreadsheet/static/src/global_filters/plugins/global_filters_core_plugin.js @@ -29,8 +29,8 @@ import { checkFiltersTypeValueCombination } from "@spreadsheet/global_filters/he import { _t } from "@web/core/l10n/translation"; export class GlobalFiltersCorePlugin extends spreadsheet.CorePlugin { - constructor() { - super(...arguments); + constructor(config) { + super(config); /** @type {Object.} */ this.globalFilters = {}; } diff --git a/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js b/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js index 1421ddcd56d..7c13cce76e2 100644 --- a/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js +++ b/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js @@ -43,9 +43,9 @@ const { UuidGenerator } = spreadsheet.helpers; const uuidGenerator = new UuidGenerator(); export default class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin { - constructor(getters, history, dispatch, config) { - super(getters, history, dispatch, config); - this.orm = config.evalContext.env ? config.evalContext.env.services.orm : undefined; + constructor(config) { + super(config); + this.orm = config.external.env ? config.external.env.services.orm : undefined; /** * Cache record display names for relation filters. * For each filter, contains a promise resolving to diff --git a/addons/spreadsheet/static/src/ir_ui_menu/ir_ui_menu_plugin.js b/addons/spreadsheet/static/src/ir_ui_menu/ir_ui_menu_plugin.js index 6dae208cc54..7b8d85f999b 100644 --- a/addons/spreadsheet/static/src/ir_ui_menu/ir_ui_menu_plugin.js +++ b/addons/spreadsheet/static/src/ir_ui_menu/ir_ui_menu_plugin.js @@ -3,9 +3,9 @@ import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended"; const { CorePlugin } = spreadsheet; export default class IrMenuPlugin extends CorePlugin { - constructor(getters, history, range, dispatch, config, uuidGenerator) { - super(getters, history, range, dispatch, config, uuidGenerator); - this.env = config.evalContext.env; + constructor(config) { + super(config); + this.env = config.external.env; } /** diff --git a/addons/spreadsheet/static/src/list/index.js b/addons/spreadsheet/static/src/list/index.js index 3192cac9f3f..1edbe1c2587 100644 --- a/addons/spreadsheet/static/src/list/index.js +++ b/addons/spreadsheet/static/src/list/index.js @@ -32,16 +32,12 @@ cellMenuRegistry.add("list_see_record", { name: _lt("See record"), sequence: 200, action: async (env) => { - const sheetId = env.model.getters.getActiveSheetId(); - const { col, row } = env.model.getters.getPosition(); - const position = env.model.getters.getMainCellPosition(sheetId, col, row); - await SEE_RECORD_LIST({ sheetId, ...position }, env); + const position = env.model.getters.getActivePosition(); + await SEE_RECORD_LIST(position, env); }, isVisible: (env) => { - const sheetId = env.model.getters.getActiveSheetId(); - const { col, row } = env.model.getters.getPosition(); - const position = env.model.getters.getMainCellPosition(sheetId, col, row); - return SEE_RECORD_LIST_VISIBLE({ sheetId, ...position }, env); + const position = env.model.getters.getActivePosition(); + return SEE_RECORD_LIST_VISIBLE(position, env); }, }); diff --git a/addons/spreadsheet/static/src/list/list_actions.js b/addons/spreadsheet/static/src/list/list_actions.js index b387613619c..44d15176216 100644 --- a/addons/spreadsheet/static/src/list/list_actions.js +++ b/addons/spreadsheet/static/src/list/list_actions.js @@ -5,8 +5,8 @@ import { getFirstListFunction, getNumberOfListFormulas } from "./list_helpers"; const { astToFormula } = spreadsheet; -export const SEE_RECORD_LIST = async ({ sheetId, col, row }, env) => { - const cell = env.model.getters.getCell(sheetId, col, row); +export const SEE_RECORD_LIST = async (position, env) => { + const cell = env.model.getters.getCell(position); if (!cell) { return; } @@ -14,7 +14,7 @@ export const SEE_RECORD_LIST = async ({ sheetId, col, row }, env) => { const evaluatedArgs = args .map(astToFormula) .map((arg) => env.model.getters.evaluateFormula(arg)); - const listId = env.model.getters.getListIdFromPosition(sheetId, col, row); + const listId = env.model.getters.getListIdFromPosition(position); const { model } = env.model.getters.getListDefinition(listId); const dataSource = await env.model.getters.getAsyncListDataSource(listId); const recordId = dataSource.getIdFromPosition(evaluatedArgs[1] - 1); @@ -32,7 +32,7 @@ export const SEE_RECORD_LIST = async ({ sheetId, col, row }, env) => { export const SEE_RECORD_LIST_VISIBLE = (position, env) => { const evaluatedCell = env.model.getters.getEvaluatedCell(position); - const cell = env.model.getters.getCell(position.sheetId, position.col, position.row); + const cell = env.model.getters.getCell(position); return ( evaluatedCell.type !== "empty" && evaluatedCell.type !== "error" && diff --git a/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js b/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js index 2df5e6515ed..ee4c1423794 100644 --- a/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js +++ b/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js @@ -31,9 +31,9 @@ import { sprintf } from "@web/core/utils/strings"; const { CorePlugin } = spreadsheet; export default class ListCorePlugin extends CorePlugin { - constructor(getters, history, range, dispatch, config, uuidGenerator) { - super(getters, history, range, dispatch, config, uuidGenerator); - this.dataSources = config.dataSources; + constructor(config) { + super(config); + this.dataSources = config.external.dataSources; this.nextId = 1; /** @type {Object.} */ @@ -80,16 +80,8 @@ export default class ListCorePlugin extends CorePlugin { handle(cmd) { switch (cmd.type) { case "INSERT_ODOO_LIST": { - const { - sheetId, - col, - row, - id, - definition, - dataSourceId, - linesNumber, - columns, - } = cmd; + const { sheetId, col, row, id, definition, dataSourceId, linesNumber, columns } = + cmd; const anchor = [col, row]; this._addList(id, definition, dataSourceId, linesNumber); this._insertList(sheetId, anchor, id, linesNumber, columns); diff --git a/addons/spreadsheet/static/src/list/plugins/list_ui_plugin.js b/addons/spreadsheet/static/src/list/plugins/list_ui_plugin.js index 04ad509ad05..7be05a16971 100644 --- a/addons/spreadsheet/static/src/list/plugins/list_ui_plugin.js +++ b/addons/spreadsheet/static/src/list/plugins/list_ui_plugin.js @@ -11,11 +11,11 @@ const { astToFormula } = spreadsheet; */ export default class ListUIPlugin extends spreadsheet.UIPlugin { - constructor(getters, history, dispatch, config, selection) { - super(getters, history, dispatch, config, selection); + constructor(config) { + super(config); /** @type {string} */ this.selectedListId = undefined; - this.env = config.evalContext.env; + this.env = config.external.env; } beforeHandle(cmd) { @@ -146,14 +146,12 @@ export default class ListUIPlugin extends spreadsheet.UIPlugin { * Get the id of the list at the given position. Returns undefined if there * is no list at this position * - * @param {string} sheetId Id of the sheet - * @param {number} col Index of the col - * @param {number} row Index of the row + * @param {{ sheetId: string; col: number; row: number}} position * * @returns {string|undefined} */ - getListIdFromPosition(sheetId, col, row) { - const cell = this.getters.getCell(sheetId, col, row); + getListIdFromPosition(position) { + const cell = this.getters.getCell(position); if (cell && cell.isFormula) { const listFunction = getFirstListFunction(cell.content); if (listFunction) { diff --git a/addons/spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js b/addons/spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js index b1870c456e6..273451c40ec 100644 --- a/addons/spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js +++ b/addons/spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js @@ -4402,14 +4402,14 @@ } getFilterValues(position) { const sheetId = this.env.model.getters.getActiveSheetId(); - const filter = this.env.model.getters.getFilter(sheetId, position.col, position.row); + const filter = this.env.model.getters.getFilter({ sheetId, ...position }); if (!filter) { return []; } const cellValues = (filter.filteredZone ? positions(filter.filteredZone) : []) .filter(({ row }) => !this.env.model.getters.isRowHidden(sheetId, row)) .map(({ col, row }) => this.env.model.getters.getEvaluatedCell({ sheetId, col, row }).formattedValue); - const filterValues = this.env.model.getters.getFilterValues(sheetId, position.col, position.row); + const filterValues = this.env.model.getters.getFilterValues({ sheetId, ...position }); const strValues = [...cellValues, ...filterValues]; const normalizedFilteredValues = filterValues.map(toLowerCase); // Set with lowercase values to avoid duplicates @@ -4442,7 +4442,7 @@ get filterTable() { const sheetId = this.env.model.getters.getActiveSheetId(); const position = this.props.filterPosition; - return this.env.model.getters.getFilterTable(sheetId, position.col, position.row); + return this.env.model.getters.getFilterTable({ sheetId, ...position }); } get displayedValues() { if (!this.state.textFilter) { @@ -5006,7 +5006,7 @@ unlink() { const sheetId = this.env.model.getters.getActiveSheetId(); const { col, row } = this.props.cellPosition; - const style = this.env.model.getters.getCellComputedStyle(sheetId, col, row); + const style = this.env.model.getters.getCellComputedStyle({ sheetId, col, row }); const textColor = (style === null || style === void 0 ? void 0 : style.textColor) === LINK_COLOR ? undefined : style === null || style === void 0 ? void 0 : style.textColor; this.env.model.dispatch("UPDATE_CELL", { col, @@ -5022,11 +5022,8 @@ LinkDisplay.size = { width: LINK_TOOLTIP_WIDTH, height: LINK_TOOLTIP_HEIGHT }; const LinkCellPopoverBuilder = { onHover: (position, getters) => { - const sheetId = getters.getActiveSheetId(); const cell = getters.getEvaluatedCell(position); - const shouldDisplayLink = !getters.isDashboard() && - cell.link && - getters.isVisibleInViewport(sheetId, position.col, position.row); + const shouldDisplayLink = !getters.isDashboard() && cell.link && getters.isVisibleInViewport(position); if (!shouldDisplayLink) return { isOpen: false }; return { @@ -5800,15 +5797,12 @@ return "neutral"; } function getChartPositionAtCenterOfViewport(getters, chartSize) { - const { x: viewportX, y: viewportY } = getters.getMainViewportCoordinates(); + const { x, y } = getters.getMainViewportCoordinates(); const { offsetX, offsetY } = getters.getActiveSheetScrollInfo(); - const { width, height } = getters.getSheetViewDimension(); - const rect = getters.getVisibleRect(getters.getActiveMainViewport()); - const scrollableViewportWidth = Math.min(rect.width, width - viewportX); - const scrollableViewportHeight = Math.min(rect.height, height - viewportY); + const { width, height } = getters.getVisibleRect(getters.getActiveMainViewport()); const position = { - x: viewportX + offsetX + Math.max(0, (scrollableViewportWidth - chartSize.width) / 2), - y: viewportY + offsetY + Math.max(0, (scrollableViewportHeight - chartSize.height) / 2), + x: x + offsetX + Math.max(0, (width - chartSize.width) / 2), + y: y + offsetY + Math.max(0, (height - chartSize.height) / 2), }; // Position at the center of the scrollable viewport return position; } @@ -6684,7 +6678,7 @@ } const dataSets = [zoneToXc(dataSetZone)]; const sheetId = getters.getActiveSheetId(); - const topLeftCell = getters.getCell(sheetId, zone.left, zone.top); + const topLeftCell = getters.getCell({ sheetId, col: zone.left, row: zone.top }); if (getZoneArea(zone) === 1 && (topLeftCell === null || topLeftCell === void 0 ? void 0 : topLeftCell.content)) { return { type: "scorecard", @@ -7377,10 +7371,10 @@ if (env.model.getters.doesIntersectMerge(sheetId, zone)) { multiColumns = false; let table; - for (let r = zone.top; r <= zone.bottom; r++) { + for (let row = zone.top; row <= zone.bottom; row++) { table = []; - for (let c = zone.left; c <= zone.right; c++) { - let merge = env.model.getters.getMerge(sheetId, c, r); + for (let col = zone.left; col <= zone.right; col++) { + let merge = env.model.getters.getMerge({ sheetId, col, row }); if (merge && !table.includes(merge.id.toString())) { table.push(merge.id.toString()); } @@ -8041,7 +8035,7 @@ env.openSidePanel("CustomCurrency", {}); }; const INSERT_LINK = (env) => { - let { col, row } = env.model.getters.getPosition(); + let { col, row } = env.model.getters.getActivePosition(); env.model.dispatch("OPEN_CELL_POPOVER", { col, row, popoverType: "LinkEditor" }); }; //------------------------------------------------------------------------------ @@ -8540,7 +8534,7 @@ }) .addChild("sort_range", ["data"], { name: _lt("Sort range"), - sequence: 62, + sequence: 20, isVisible: IS_ONLY_ONE_RANGE, separator: true, }) @@ -8871,15 +8865,15 @@ separator: true, }) .addChild("add_data_filter", ["data"], { - name: _lt("Add Filter"), - sequence: 20, + name: _lt("Create filter"), + sequence: 10, action: FILTERS_CREATE_FILTER_TABLE, isVisible: (env) => !SELECTION_CONTAINS_FILTER(env), isEnabled: (env) => SELECTION_IS_CONTINUOUS(env), }) .addChild("remove_data_filter", ["data"], { - name: _lt("Remove Filter"), - sequence: 20, + name: _lt("Remove filter"), + sequence: 10, action: FILTERS_REMOVE_FILTER_TABLE, isVisible: SELECTION_CONTAINS_FILTER, }); @@ -19408,7 +19402,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * and UI plugins handling transient data. */ class BasePlugin { - constructor(stateObserver, dispatch, config) { + constructor(stateObserver, dispatch) { this.history = Object.assign(Object.create(stateObserver), { update: stateObserver.addChange.bind(stateObserver, this), selectCell: () => { }, @@ -19489,10 +19483,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * They can draw on the grid canvas. */ class UIPlugin extends BasePlugin { - constructor(getters, state, dispatch, config, selection) { - super(state, dispatch, config); + constructor({ getters, stateObserver, dispatch, uiActions, selection }) { + super(stateObserver, dispatch); this.getters = getters; - this.ui = config; + this.ui = uiActions; this.selection = selection; } // --------------------------------------------------------------------------- @@ -19537,8 +19531,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } case "START_EDITION": if (cmd.selection) { - const sheetId = this.getters.getActiveSheetId(); - const content = cmd.text || this.getComposerContent({ sheetId, ...this.getters.getPosition() }); + const content = cmd.text || this.getComposerContent(this.getters.getActivePosition()); return this.validateSelection(content.length, cmd.selection.start, cmd.selection.end); } else { @@ -19640,7 +19633,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A break; case "ACTIVATE_SHEET": if (cmd.sheetIdFrom !== cmd.sheetIdTo) { - const { col, row } = this.getters.getNextVisibleCellPosition(cmd.sheetIdTo, 0, 0); + const { col, row } = this.getters.getNextVisibleCellPosition({ + sheetId: cmd.sheetIdTo, + col: 0, + row: 0, + }); const zone = this.getters.expandZone(cmd.sheetIdTo, positionToZone({ col, row })); this.selection.resetAnchor(this, { cell: { col, row }, zone }); } @@ -19675,8 +19672,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } getCurrentContent() { if (this.mode === "inactive") { - const sheetId = this.getters.getActiveSheetId(); - return this.getComposerContent({ sheetId, ...this.getters.getPosition() }); + return this.getComposerContent(this.getters.getActivePosition()); } return this.currentContent; } @@ -19801,7 +19797,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A str = `${str}%`; } const sheetId = this.getters.getActiveSheetId(); - const { col, row } = this.getters.getPosition(); + const { col, row } = this.getters.getActivePosition(); this.col = col; this.sheetId = sheetId; this.row = row; @@ -19818,7 +19814,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A stopEdition() { if (this.mode !== "inactive") { this.cancelEdition(); - const { col, row } = this.getters.getMainCellPosition(this.sheetId, this.col, this.row); + const col = this.col; + const row = this.row; let content = this.currentContent; const didChange = this.initialContent !== content; if (!didChange) { @@ -19826,7 +19823,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } if (content) { const sheetId = this.getters.getActiveSheetId(); - const cell = this.getters.getEvaluatedCell({ sheetId, col, row }); + const cell = this.getters.getEvaluatedCell({ sheetId, col: this.col, row: this.row }); if (content.startsWith("=")) { const left = this.currentTokens.filter((t) => t.type === "LEFT_PAREN").length; const right = this.currentTokens.filter((t) => t.type === "RIGHT_PAREN").length; @@ -19870,17 +19867,12 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A }); } } - getComposerContent({ sheetId, col, row }) { - const { col: mainCol, row: mainRow } = this.getters.getMainCellPosition(sheetId, col, row); - const cell = this.getters.getCell(sheetId, mainCol, mainRow); + getComposerContent(position) { + const cell = this.getters.getCell(position); if (cell === null || cell === void 0 ? void 0 : cell.isFormula) { return cell.content; } - const { format, value, type, formattedValue } = this.getters.getEvaluatedCell({ - sheetId, - col: mainCol, - row: mainRow, - }); + const { format, value, type, formattedValue } = this.getters.getEvaluatedCell(position); switch (type) { case CellValueType.text: case CellValueType.empty: @@ -20896,13 +20888,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A rect: undefined, delimitation: undefined, }); - const { col, row } = this.env.model.getters.getPosition(); - this.zone = this.env.model.getters.expandZone(this.env.model.getters.getActiveSheetId(), { - left: col, - right: col, - top: row, - bottom: row, - }); + const { sheetId, col, row } = this.env.model.getters.getActivePosition(); + this.zone = this.env.model.getters.expandZone(sheetId, positionToZone({ col, row })); this.rect = this.env.model.getters.getVisibleRect(this.zone); owl.onMounted(() => { const el = this.gridComposerRef.el; @@ -20926,10 +20913,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A get containerStyle() { const isFormula = this.env.model.getters.getCurrentContent().startsWith("="); const cell = this.env.model.getters.getActiveCell(); - const position = this.env.model.getters.getPosition(); - const sheetId = this.env.model.getters.getActiveSheetId(); - const cellPosition = this.env.model.getters.getMainCellPosition(sheetId, position.col, position.row); - const style = this.env.model.getters.getCellComputedStyle(sheetId, cellPosition.col, cellPosition.row); + const position = this.env.model.getters.getActivePosition(); + const style = this.env.model.getters.getCellComputedStyle(position); // position style const { x: left, y: top, width, height } = this.rect; // color style @@ -21039,7 +21024,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } isFilterActive(position) { const sheetId = this.env.model.getters.getActiveSheetId(); - return this.env.model.getters.isFilterActive(sheetId, position.col, position.row); + return this.env.model.getters.isFilterActive({ sheetId, ...position }); } toggleFilterMenu(position) { const activePopoverType = this.env.model.getters.getPersistentPopoverTypeAtPosition(position); @@ -22747,7 +22732,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A }, "CTRL+HOME": () => { const sheetId = this.env.model.getters.getActiveSheetId(); - const { col, row } = this.env.model.getters.getNextVisibleCellPosition(sheetId, 0, 0); + const { col, row } = this.env.model.getters.getNextVisibleCellPosition({ + sheetId, + col: 0, + row: 0, + }); this.env.model.selection.selectCell(col, row); }, "CTRL+END": () => { @@ -22763,7 +22752,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A left: 0, right: this.env.model.getters.getNumberCols(sheetId) - 1, }; - const position = this.env.model.getters.getPosition(); + const position = this.env.model.getters.getActivePosition(); this.env.model.selection.selectZone({ cell: position, zone: newZone }); }, "CTRL+ ": () => { @@ -22773,7 +22762,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A top: 0, bottom: this.env.model.getters.getNumberRows(sheetId) - 1, }; - const position = this.env.model.getters.getPosition(); + const position = this.env.model.getters.getActivePosition(); this.env.model.selection.selectZone({ cell: position, zone: newZone }); }, "CTRL+SHIFT+ ": () => { @@ -26691,9 +26680,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * They should not be concerned about UI parts or transient state. */ class CorePlugin extends BasePlugin { - constructor(getters, stateObserver, range, dispatch, config, uuidGenerator) { - super(stateObserver, dispatch, config); - this.dispatch = dispatch; + constructor({ getters, stateObserver, range, dispatch, uuidGenerator }) { + super(stateObserver, dispatch); this.range = range; range.addRangeProvider(this.adaptRanges.bind(this)); this.getters = getters; @@ -26837,7 +26825,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A // --------------------------------------------------------------------------- // Getters // --------------------------------------------------------------------------- - getCellBorder(sheetId, col, row) { + getCellBorder({ sheetId, col, row }) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const border = { top: (_c = (_b = (_a = this.borders[sheetId]) === null || _a === void 0 ? void 0 : _a[col]) === null || _b === void 0 ? void 0 : _b[row]) === null || _c === void 0 ? void 0 : _c.horizontal, @@ -26861,8 +26849,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A ensureColumnBorderContinuity(sheetId, leftColumn, rightColumn) { const targetCols = range(leftColumn + 1, rightColumn); for (let row = 0; row < this.getters.getNumberRows(sheetId); row++) { - const leftBorder = this.getCellBorder(sheetId, leftColumn, row); - const rightBorder = this.getCellBorder(sheetId, rightColumn, row); + const leftBorder = this.getCellBorder({ sheetId, col: leftColumn, row }); + const rightBorder = this.getCellBorder({ sheetId, col: rightColumn, row }); if (leftBorder && rightBorder) { const commonSides = this.getCommonSides(leftBorder, rightBorder); for (let col of targetCols) { @@ -26879,8 +26867,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A ensureRowBorderContinuity(sheetId, topRow, bottomRow) { const targetRows = range(topRow + 1, bottomRow); for (let col = 0; col < this.getters.getNumberCols(sheetId); col++) { - const aboveBorder = this.getCellBorder(sheetId, col, topRow); - const belowBorder = this.getCellBorder(sheetId, col, bottomRow); + const aboveBorder = this.getCellBorder({ sheetId, col, row: topRow }); + const belowBorder = this.getCellBorder({ sheetId, col, row: bottomRow }); if (aboveBorder && belowBorder) { const commonSides = this.getCommonSides(aboveBorder, belowBorder); for (let row of targetRows) { @@ -27056,7 +27044,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ addBorder(sheetId, col, row, border) { this.setBorder(sheetId, col, row, { - ...this.getCellBorder(sheetId, col, row), + ...this.getCellBorder({ sheetId, col, row }), ...border, }); } @@ -27110,8 +27098,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ addBordersToMerge(sheetId, zone) { const { left, right, top, bottom } = zone; - const bordersTopLeft = this.getCellBorder(sheetId, left, top); - const bordersBottomRight = this.getCellBorder(sheetId, right, bottom); + const bordersTopLeft = this.getCellBorder({ sheetId, col: left, row: top }); + const bordersBottomRight = this.getCellBorder({ sheetId, col: right, row: bottom }); this.clearBorders(sheetId, [zone]); if (bordersTopLeft === null || bordersTopLeft === void 0 ? void 0 : bordersTopLeft.top) { this.setBorders(sheetId, [{ ...zone, bottom: top }], "top"); @@ -27171,7 +27159,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (let sheet of data.sheets) { for (let col = 0; col < sheet.colNumber; col++) { for (let row = 0; row < sheet.rowNumber; row++) { - const border = this.getCellBorder(sheet.id, col, row); + const border = this.getCellBorder({ sheetId: sheet.id, col, row }); if (border) { const xc = toXC(col, row); const cell = sheet.cells[xc]; @@ -27353,9 +27341,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const positions = Object.keys(this.cells[_sheet.id] || {}) .map((cellId) => this.getters.getCellPosition(cellId)) .sort((a, b) => (a.col === b.col ? a.row - b.row : a.col - b.col)); - for (const { col, row } of positions) { - const cell = this.getters.getCell(_sheet.id, col, row); - const xc = toXC(col, row); + for (const position of positions) { + const cell = this.getters.getCell(position); + const xc = toXC(position.col, position.row); cells[xc] = { style: cell.style ? getItemId(cell.style, styles) : undefined, format: cell.format ? getItemId(cell.format, formats) : undefined, @@ -27413,9 +27401,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A getFormulaCellContent(sheetId, cell) { return this.buildFormulaContent(sheetId, cell); } - getCellStyle({ sheetId, col, row }) { + getCellStyle(position) { var _a; - return ((_a = this.getters.getCell(sheetId, col, row)) === null || _a === void 0 ? void 0 : _a.style) || {}; + return ((_a = this.getters.getCell(position)) === null || _a === void 0 ? void 0 : _a.style) || {}; } /** * Converts a zone to a XC coordinate system @@ -27437,8 +27425,16 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A zone = this.getters.expandZone(sheetId, zone); const topLeft = toXC(zone.left, zone.top, fixedParts[0]); const botRight = toXC(zone.right, zone.bottom, fixedParts.length > 1 ? fixedParts[1] : fixedParts[0]); - const cellTopLeft = this.getters.getMainCellPosition(sheetId, zone.left, zone.top); - const cellBotRight = this.getters.getMainCellPosition(sheetId, zone.right, zone.bottom); + const cellTopLeft = this.getters.getMainCellPosition({ + sheetId, + col: zone.left, + row: zone.top, + }); + const cellBotRight = this.getters.getMainCellPosition({ + sheetId, + col: zone.right, + row: zone.bottom, + }); const sameCell = cellTopLeft.col === cellBotRight.col && cellTopLeft.row === cellBotRight.row; if (topLeft != botRight && !sameCell) { return topLeft + ":" + botRight; @@ -27449,7 +27445,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (let zone of target) { for (let col = zone.left; col <= zone.right; col++) { for (let row = zone.top; row <= zone.bottom; row++) { - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell({ sheetId, col, row }); this.dispatch("UPDATE_CELL", { sheetId, col, @@ -27491,8 +27487,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ getFormat(sheetId, col, row) { const format = {}; - const { col: mainCol, row: mainRow } = this.getters.getMainCellPosition(sheetId, col, row); - const cell = this.getters.getCell(sheetId, mainCol, mainRow); + const position = this.getters.getMainCellPosition({ sheetId, col, row }); + const cell = this.getters.getCell(position); if (cell) { if (cell.style) { format["style"] = cell.style; @@ -27510,7 +27506,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } updateCell(sheetId, col, row, after) { var _a; - const before = this.getters.getCell(sheetId, col, row); + const before = this.getters.getCell({ sheetId, col, row }); const hasContent = "content" in after || "formula" in after; // Compute the new cell properties const afterContent = hasContent @@ -28457,15 +28453,15 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A getFilterTables(sheetId) { return this.tables[sheetId] ? Object.values(this.tables[sheetId]).filter(isDefined$1) : []; } - getFilter(sheetId, col, row) { + getFilter(position) { var _a; - return (_a = this.getFilterTable(sheetId, col, row)) === null || _a === void 0 ? void 0 : _a.filters.find((filter) => filter.col === col); + return (_a = this.getFilterTable(position)) === null || _a === void 0 ? void 0 : _a.filters.find((filter) => filter.col === position.col); } - getFilterId(sheetId, col, row) { + getFilterId(position) { var _a; - return (_a = this.getFilter(sheetId, col, row)) === null || _a === void 0 ? void 0 : _a.id; + return (_a = this.getFilter(position)) === null || _a === void 0 ? void 0 : _a.id; } - getFilterTable(sheetId, col, row) { + getFilterTable({ sheetId, col, row }) { return this.getFilterTables(sheetId).find((filterTable) => isInside(col, row, filterTable.zone)); } /** Get the filter tables that are fully inside the given zone */ @@ -28564,15 +28560,16 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A return false; } for (const col of range(zone.left, zone.right + 1)) { + const position = { sheetId, col, row }; // Since this plugin is loaded before CellPlugin, the getters still give us the old cell content - const cellContent = (_a = this.getters.getCell(sheetId, col, row)) === null || _a === void 0 ? void 0 : _a.content; + const cellContent = (_a = this.getters.getCell(position)) === null || _a === void 0 ? void 0 : _a.content; if (cellContent) { return false; } - if (this.getters.getFilter(sheetId, col, row)) { + if (this.getters.getFilter(position)) { return false; } - if (this.getters.isInMerge(sheetId, col, row)) { + if (this.getters.isInMerge(position)) { return false; } } @@ -28753,12 +28750,12 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * Return the height the cell should have in the sheet, which is either DEFAULT_CELL_HEIGHT if the cell is in a multi-row * merge, or the height of the cell computed based on its font size. */ - getCellHeight(sheetId, col, row) { - const merge = this.getters.getMerge(sheetId, col, row); + getCellHeight(position) { + const merge = this.getters.getMerge(position); if (merge && merge.bottom !== merge.top) { return DEFAULT_CELL_HEIGHT; } - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell(position); // TO DO: take multiline cells into account to compute the cell height return getDefaultCellHeight(cell === null || cell === void 0 ? void 0 : cell.style); } @@ -28775,8 +28772,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const cell = this.getters.getCellById(cellIds[i]); if (!cell) continue; - const { col, row } = this.getters.getCellPosition(cell.id); - const cellHeight = this.getCellHeight(sheetId, col, row); + const position = this.getters.getCellPosition(cell.id); + const cellHeight = this.getCellHeight(position); if (cellHeight > maxHeight && cellHeight > DEFAULT_CELL_HEIGHT) { maxHeight = cellHeight; } @@ -29082,7 +29079,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A .map((mergeId) => this.getMergeById(sheetId, parseInt(mergeId, 10))) .filter(isDefined$1); } - getMerge(sheetId, col, row) { + getMerge({ sheetId, col, row }) { var _a; const sheetMap = this.mergeCellMap[sheetId]; const mergeId = sheetMap ? col in sheetMap && ((_a = sheetMap[col]) === null || _a === void 0 ? void 0 : _a[row]) : undefined; @@ -29109,15 +29106,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * if they have at least a common cell */ doesIntersectMerge(sheetId, zone) { - const { left, right, top, bottom } = zone; - for (let row = top; row <= bottom; row++) { - for (let col = left; col <= right; col++) { - if (this.getMerge(sheetId, col, row)) { - return true; - } - } - } - return false; + return positions(zone).some(({ col, row }) => this.getMerge({ sheetId, col, row }) !== undefined); } /** * Returns true if two columns have at least one merge in common @@ -29158,31 +29147,31 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A return isEqual(result, zone) ? result : this.expandZone(sheetId, result); } isInSameMerge(sheetId, colA, rowA, colB, rowB) { - const mergeA = this.getMerge(sheetId, colA, rowA); - const mergeB = this.getMerge(sheetId, colB, rowB); + const mergeA = this.getMerge({ sheetId, col: colA, row: rowA }); + const mergeB = this.getMerge({ sheetId, col: colB, row: rowB }); if (!mergeA || !mergeB) { return false; } return isEqual(mergeA, mergeB); } - isInMerge(sheetId, col, row) { + isInMerge({ sheetId, col, row }) { var _a; const sheetMap = this.mergeCellMap[sheetId]; return sheetMap ? col in sheetMap && Boolean((_a = sheetMap[col]) === null || _a === void 0 ? void 0 : _a[row]) : false; } - getMainCellPosition(sheetId, col, row) { - if (!this.isInMerge(sheetId, col, row)) { - return { col, row }; + getMainCellPosition(position) { + if (!this.isInMerge(position)) { + return position; } - const mergeTopLeftPos = this.getMerge(sheetId, col, row).topLeft; - return { col: mergeTopLeftPos.col, row: mergeTopLeftPos.row }; + const mergeTopLeftPos = this.getMerge(position).topLeft; + return { sheetId: position.sheetId, col: mergeTopLeftPos.col, row: mergeTopLeftPos.row }; } - getBottomLeftCell(sheetId, col, row) { - if (!this.isInMerge(sheetId, col, row)) { - return { col, row }; + getBottomLeftCell(position) { + if (!this.isInMerge(position)) { + return position; } - const { bottom, left } = this.getMerge(sheetId, col, row); - return { col: left, row: bottom }; + const { bottom, left } = this.getMerge(position); + return { sheetId: position.sheetId, col: left, row: bottom }; } isMergeHidden(sheetId, merge) { const hiddenColsGroups = this.getters.getHiddenColsGroups(sheetId); @@ -29203,7 +29192,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * Check if the zone represents a single cell or a single merge. */ isSingleCellOrMerge(sheetId, zone) { - const merge = this.getMerge(sheetId, zone.left, zone.top); + const merge = this.getMerge({ sheetId, col: zone.left, row: zone.top }); if (merge) { return isEqual(zone, merge); } @@ -29225,7 +29214,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (let row = top; row <= bottom; row++) { for (let col = left; col <= right; col++) { if (col !== left || row !== top) { - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell({ sheetId, col, row }); if (cell && cell.content !== "") { return true; } @@ -29274,11 +29263,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * Except for the top-left cell. */ checkMergedContentUpdate(cmd) { - const { col, row, sheetId, content } = cmd; + const { col, row, content } = cmd; if (content === undefined) { return 0 /* CommandResult.Success */; } - const { col: mainCol, row: mainRow } = this.getMainCellPosition(sheetId, col, row); + const { col: mainCol, row: mainRow } = this.getMainCellPosition(cmd); if (mainCol === col && mainRow === row) { return 0 /* CommandResult.Success */; } @@ -29299,7 +29288,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A if (tl === br) { return; } - const topLeft = this.getters.getCell(sheetId, left, top); + const topLeft = this.getters.getCell({ sheetId, col: left, row: top }); let id = this.nextId++; this.history.update("merges", sheetId, id, this.getters.getRangeFromSheetXC(sheetId, zoneToXc({ left, top, right, bottom }))); let previousMerges = new Set(); @@ -29314,7 +29303,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A content: "", }); } - const merge = this.getMerge(sheetId, col, row); + const merge = this.getMerge({ sheetId, col, row }); if (merge) { previousMerges.add(merge.id); } @@ -29323,16 +29312,13 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } for (let mergeId of previousMerges) { const { top, bottom, left, right } = this.getMergeById(sheetId, mergeId); - for (let r = top; r <= bottom; r++) { - for (let c = left; c <= right; c++) { - const merge = this.getMerge(sheetId, c, r); + for (let row = top; row <= bottom; row++) { + for (let col = left; col <= right; col++) { + const position = { sheetId, col, row }; + const merge = this.getMerge(position); if (!merge || merge.id !== id) { - this.history.update("mergeCellMap", sheetId, c, r, undefined); - this.dispatch("CLEAR_CELL", { - sheetId, - col: c, - row: r, - }); + this.history.update("mergeCellMap", sheetId, col, row, undefined); + this.dispatch("CLEAR_CELL", position); } } } @@ -29341,7 +29327,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } removeMerge(sheetId, zone) { const { left, top, bottom, right } = zone; - const merge = this.getMerge(sheetId, left, top); + const merge = this.getMerge({ sheetId, col: left, row: top }); if (merge === undefined || !isEqual(zone, merge)) { throw new Error(_lt("Invalid merge zone")); } @@ -30083,7 +30069,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } return row; } - getCell(sheetId, col, row) { + getCell({ sheetId, col, row }) { var _a; const sheet = this.tryGetSheet(sheetId); const cellId = (_a = sheet === null || sheet === void 0 ? void 0 : sheet.rows[row]) === null || _a === void 0 ? void 0 : _a.cells[col]; @@ -30173,7 +30159,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ isEmpty(sheetId, zone) { return positions(zone) - .map(({ col, row }) => this.getCell(sheetId, col, row)) + .map(({ col, row }) => this.getCell({ sheetId, col, row })) .every((cell) => !cell || cell.content === ""); } updateCellPosition(cmd) { @@ -30823,11 +30809,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const functionMap = functionRegistry.mapping; class EvaluationPlugin extends UIPlugin { - constructor(getters, state, dispatch, config, selection) { - super(getters, state, dispatch, config, selection); + constructor(config) { + super(config); this.isUpToDate = false; this.evaluatedCells = {}; - this.evalContext = config.evalContext; + this.evalContext = config.external; } // --------------------------------------------------------------------------- // Command Handling @@ -30887,7 +30873,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } getEvaluatedCell({ sheetId, col, row }) { var _a, _b, _c; - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell({ sheetId, col, row }); if (cell === undefined) { return createEvaluatedCell(""); } @@ -31013,7 +30999,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A if (!getters.tryGetSheet(range.sheetId)) { throw new Error(_lt("Invalid sheet name")); } - cell = getters.getCell(range.sheetId, range.zone.left, range.zone.top); + cell = getters.getCell({ sheetId: range.sheetId, col: range.zone.left, row: range.zone.top }); if (!cell || cell.content === "") { // magic "empty" value // Returning {value: null} instead of undefined will ensure that we don't @@ -31055,7 +31041,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (let col = zone.left; col <= zone.right; col++) { const rowValues = []; for (let row = zone.top; row <= zone.bottom; row++) { - const cell = evalContext.getters.getCell(range.sheetId, col, row); + const cell = evalContext.getters.getCell({ sheetId: range.sheetId, col, row }); rowValues.push(cell ? getEvaluatedCell(cell) : undefined); } result.push(rowValues); @@ -31097,11 +31083,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A exportForExcel(data) { for (let sheet of data.sheets) { for (const xc in sheet.cells) { - const { col, row } = toCartesian(xc); - const cell = this.getters.getCell(sheet.id, col, row); + const position = { sheetId: sheet.id, ...toCartesian(xc) }; + const cell = this.getters.getCell(position); if (cell) { const exportedCellData = sheet.cells[xc]; - exportedCellData.value = this.getEvaluatedCell({ sheetId: sheet.id, col, row }).value; + exportedCellData.value = this.getEvaluatedCell(position).value; exportedCellData.isFormula = cell.isFormula && !this.isBadExpression(cell.content); } } @@ -31184,7 +31170,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } const col = mainRange.zone.left; const row = mainRange.zone.top; - const style = this.getters.getCellComputedStyle(mainRange.sheetId, col, row); + const sheetId = mainRange.sheetId; + const style = this.getters.getCellComputedStyle({ sheetId, col, row }); return style.fillColor || BACKGROUND_CHART_COLOR; } } @@ -31293,26 +31280,27 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A // --------------------------------------------------------------------------- // Getters // --------------------------------------------------------------------------- - getCellComputedStyle(sheetId, col, row) { + getCellComputedStyle(position) { var _a; // TODO move this getter out of CF: it also depends on filters and link - const cell = this.getters.getCell(sheetId, col, row); + const { sheetId, col, row } = position; + const cell = this.getters.getCell(position); const styles = this.computedStyles[sheetId]; const cfStyle = styles && ((_a = styles[col]) === null || _a === void 0 ? void 0 : _a[row]); const computedStyle = { ...cell === null || cell === void 0 ? void 0 : cell.style, ...cfStyle, }; - const evaluatedCell = this.getters.getEvaluatedCell({ sheetId, col, row }); + const evaluatedCell = this.getters.getEvaluatedCell(position); if (evaluatedCell.link && !computedStyle.textColor) { computedStyle.textColor = LINK_COLOR; } - if (this.getters.isFilterHeader(sheetId, col, row)) { + if (this.getters.isFilterHeader(position)) { computedStyle.bold = true; } return computedStyle; } - getConditionalIcon(col, row) { + getConditionalIcon({ col, row }) { var _a; const activeSheet = this.getters.getActiveSheetId(); const icon = this.computedIcons[activeSheet]; @@ -31571,7 +31559,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A allowDispatch(cmd) { switch (cmd.type) { case "UPDATE_FILTER": - if (!this.getters.getFilterId(cmd.sheetId, cmd.col, cmd.row)) { + if (!this.getters.getFilterId(cmd)) { return 77 /* CommandResult.FilterNotFound */; } break; @@ -31608,7 +31596,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const filterValues = {}; for (const copiedFilter of this.getters.getFilters(cmd.sheetId)) { const zone = copiedFilter.zoneWithHeaders; - const newFilter = this.getters.getFilter(cmd.sheetIdTo, zone.left, zone.top); + const newFilter = this.getters.getFilter({ + sheetId: cmd.sheetIdTo, + col: zone.left, + row: zone.top, + }); filterValues[newFilter.id] = ((_a = this.filterValues[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[copiedFilter.id]) || []; } this.filterValues[cmd.sheetIdTo] = filterValues; @@ -31629,7 +31621,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } return this.hiddenRows.has(row); } - getCellBorderWithFilterBorder(sheetId, col, row) { + getCellBorderWithFilterBorder(position) { + const { sheetId, col, row } = position; let filterBorder = undefined; for (let filters of this.getters.getFilterTables(sheetId)) { const zone = filters.zone; @@ -31649,7 +31642,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A }; } } - const cellBorder = this.getters.getCellBorder(sheetId, col, row); + const cellBorder = this.getters.getCellBorder(position); // Use removeFalsyAttributes to avoid overwriting filter borders with undefined values const border = { ...filterBorder, ...removeFalsyAttributes(cellBorder || {}) }; return isObjectEmptyRecursive(border) ? null : border; @@ -31671,23 +31664,25 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } return headers; } - getFilterValues(sheetId, col, row) { - const id = this.getters.getFilterId(sheetId, col, row); + getFilterValues(position) { + const id = this.getters.getFilterId(position); + const sheetId = position.sheetId; if (!id || !this.filterValues[sheetId]) return []; return this.filterValues[sheetId][id] || []; } - isFilterHeader(sheetId, col, row) { + isFilterHeader({ sheetId, col, row }) { const headers = this.getFilterHeaders(sheetId); return headers.some((header) => header.col === col && header.row === row); } - isFilterActive(sheetId, col, row) { + isFilterActive(position) { var _a, _b; - const id = this.getters.getFilterId(sheetId, col, row); + const id = this.getters.getFilterId(position); + const sheetId = position.sheetId; return Boolean(id && ((_b = (_a = this.filterValues[sheetId]) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.length)); } updateFilter({ col, row, values, sheetId }) { - const id = this.getters.getFilterId(sheetId, col, row); + const id = this.getters.getFilterId({ sheetId, col, row }); if (!id) return; if (!this.filterValues[sheetId]) @@ -31723,8 +31718,13 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const filters = []; const headerNames = []; for (const i of range(0, zoneToDimension(tableZone).width)) { - const filteredValues = this.getFilterValues(sheetData.id, tableZone.left + i, tableZone.top); - const filter = this.getters.getFilter(sheetData.id, tableZone.left + i, tableZone.top); + const position = { + sheetId: sheetData.id, + col: tableZone.left + i, + row: tableZone.top, + }; + const filteredValues = this.getFilterValues(position); + const filter = this.getters.getFilter(position); if (!filter) continue; const valuesInFilterZone = filter.filteredZone @@ -31858,8 +31858,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A if (!position) { position = this.getters.getSheetPosition(sheetId); } - const mainCellPosition = this.getters.getMainCellPosition(sheetId, position.col, position.row); - const { col, row } = this.getters.getNextVisibleCellPosition(sheetId, mainCellPosition.col, mainCellPosition.row); + const mainCellPosition = this.getters.getMainCellPosition({ sheetId, ...position }); + const { col, row } = this.getters.getNextVisibleCellPosition(mainCellPosition); if (isInside(col, this.boundaries.top, this.boundaries)) { this.adjustPositionX(col); } @@ -31919,16 +31919,24 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.adjustViewportZoneX(); this.adjustViewportZoneY(); } + /** + * + * @param zone + * @returns Computes the absolute coordinate of a given zone inside the viewport + */ getRect(zone) { const targetZone = intersection(zone, this.zone); if (targetZone) { + const x = this.getters.getColRowOffset("COL", this.zone.left, targetZone.left) + + this.offsetCorrectionX; + const y = this.getters.getColRowOffset("ROW", this.zone.top, targetZone.top) + this.offsetCorrectionY; + const width = Math.min(this.getters.getColRowOffset("COL", targetZone.left, targetZone.right + 1), this.width); + const height = Math.min(this.getters.getColRowOffset("ROW", targetZone.top, targetZone.bottom + 1), this.height); return { - x: this.getters.getColRowOffset("COL", this.zone.left, targetZone.left) + - this.offsetCorrectionX, - y: this.getters.getColRowOffset("ROW", this.zone.top, targetZone.top) + - this.offsetCorrectionY, - width: this.getters.getColRowOffset("COL", targetZone.left, targetZone.right + 1), - height: this.getters.getColRowOffset("ROW", targetZone.top, targetZone.bottom + 1), + x, + y, + width, + height, }; } else { @@ -32334,7 +32342,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A /** * Check if a given position is visible in the viewport. */ - isVisibleInViewport(sheetId, col, row) { + isVisibleInViewport({ sheetId, col, row }) { return this.getSubViewports(sheetId).some((pane) => pane.isVisible(col, row)); } // => return s the new offset @@ -32952,7 +32960,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const sheetId = this.getters.getActiveSheetId(); for (let xc of source) { const { col, row } = toCartesian(xc); - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell({ sheetId, col, row }); cellsData.push({ col, row, @@ -32967,8 +32975,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const newRule = this.getRule(cellData.cell, cells); rule = newRule || rule; } - const { sheetId, col, row } = cellData; - const border = this.getters.getCellBorder(sheetId, col, row) || undefined; + const border = this.getters.getCellBorder(cellData) || undefined; nextCells.push({ data: { ...cellData, border }, rule, @@ -33003,21 +33010,22 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A : position[second].value; } autoFillMerge(originCol, originRow, col, row) { - const activeSheet = this.getters.getActiveSheet(); - if (this.getters.isInMerge(activeSheet.id, col, row) && - !this.getters.isInMerge(activeSheet.id, originCol, originRow)) { - const zone = this.getters.getMerge(activeSheet.id, col, row); + const sheetId = this.getters.getActiveSheetId(); + const position = { sheetId, col, row }; + const originPosition = { sheetId, col: originCol, row: originRow }; + if (this.getters.isInMerge(position) && !this.getters.isInMerge(originPosition)) { + const zone = this.getters.getMerge(position); if (zone) { this.dispatch("REMOVE_MERGE", { - sheetId: activeSheet.id, + sheetId, target: [zone], }); } } - const originMerge = this.getters.getMerge(activeSheet.id, originCol, originRow); + const originMerge = this.getters.getMerge(originPosition); if ((originMerge === null || originMerge === void 0 ? void 0 : originMerge.topLeft.col) === originCol && (originMerge === null || originMerge === void 0 ? void 0 : originMerge.topLeft.row) === originRow) { this.dispatch("ADD_MERGE", { - sheetId: activeSheet.id, + sheetId, target: [ { top: row, @@ -33129,7 +33137,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ findAdjacentData(sheetId, col, row) { const sheet = this.getters.getSheet(sheetId); - const mainCellPosition = this.getters.getMainCellPosition(sheetId, col, row); + const mainCellPosition = this.getters.getMainCellPosition({ sheetId, col, row }); const zone = this.findSuitableZoneToSum(sheet, mainCellPosition.col, mainCellPosition.row); if (zone) { return this.getters.expandZone(sheetId, zone); @@ -33350,6 +33358,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.persistentPopover = { col: cmd.col, row: cmd.row, + sheetId: this.getters.getActiveSheetId(), type: cmd.popoverType, }; break; @@ -33361,11 +33370,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A getCellPopover({ col, row }) { var _a, _b; const sheetId = this.getters.getActiveSheetId(); - if (this.persistentPopover && - this.getters.isVisibleInViewport(sheetId, this.persistentPopover.col, this.persistentPopover.row)) { - const mainPosition = this.getters.getMainCellPosition(sheetId, this.persistentPopover.col, this.persistentPopover.row); + if (this.persistentPopover && this.getters.isVisibleInViewport(this.persistentPopover)) { + const position = this.getters.getMainCellPosition(this.persistentPopover); const popover = (_b = (_a = cellPopoverRegistry - .get(this.persistentPopover.type)).onOpen) === null || _b === void 0 ? void 0 : _b.call(_a, { sheetId, ...mainPosition }, this.getters); + .get(this.persistentPopover.type)).onOpen) === null || _b === void 0 ? void 0 : _b.call(_a, position, this.getters); return !(popover === null || popover === void 0 ? void 0 : popover.isOpen) ? { isOpen: false } : { @@ -33375,19 +33383,19 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } if (col === undefined || row === undefined || - !this.getters.isVisibleInViewport(sheetId, col, row)) { + !this.getters.isVisibleInViewport({ sheetId, col, row })) { return { isOpen: false }; } - const mainPosition = this.getters.getMainCellPosition(sheetId, col, row); + const position = this.getters.getMainCellPosition({ sheetId, col, row }); const popover = cellPopoverRegistry .getAll() - .map((matcher) => { var _a; return (_a = matcher.onHover) === null || _a === void 0 ? void 0 : _a.call(matcher, { sheetId, ...mainPosition }, this.getters); }) + .map((matcher) => { var _a; return (_a = matcher.onHover) === null || _a === void 0 ? void 0 : _a.call(matcher, position, this.getters); }) .find((popover) => popover === null || popover === void 0 ? void 0 : popover.isOpen); return !(popover === null || popover === void 0 ? void 0 : popover.isOpen) ? { isOpen: false } : { ...popover, - ...this.computePopoverProps(mainPosition, popover.cellCorner), + ...this.computePopoverProps(position, popover.cellCorner), }; } getPersistentPopoverTypeAtPosition({ col, row }) { @@ -33408,7 +33416,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } computePopoverPosition({ col, row }, corner) { const sheetId = this.getters.getActiveSheetId(); - const merge = this.getters.getMerge(sheetId, col, row); + const merge = this.getters.getMerge({ sheetId, col, row }); if (merge) { col = corner === "TopRight" ? merge.right : merge.left; row = corner === "TopRight" ? merge.top : merge.bottom; @@ -33424,7 +33432,6 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } } CellPopoverPlugin.getters = ["getCellPopover", "getPersistentPopoverTypeAtPosition"]; - CellPopoverPlugin.modes = ["normal"]; const BORDER_COLOR = "#8B008B"; const BACKGROUND_COLOR = "#8B008B33"; @@ -33585,10 +33592,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } //modulo of negative value to be able to cycle in both directions with previous and next nextIndex = ((nextIndex % matches.length) + matches.length) % matches.length; - if (this.selectedMatchIndex === null || this.selectedMatchIndex !== nextIndex) { - this.selectedMatchIndex = nextIndex; - this.selection.selectCell(matches[nextIndex].col, matches[nextIndex].row); - } + this.selectedMatchIndex = nextIndex; + this.selection.selectCell(matches[nextIndex].col, matches[nextIndex].row); for (let index = 0; index < this.searchMatches.length; index++) { this.searchMatches[index].selected = index === this.selectedMatchIndex; } @@ -33617,7 +33622,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const matches = this.searchMatches; const selectedMatch = matches[this.selectedMatchIndex]; const sheetId = this.getters.getActiveSheetId(); - const cell = this.getters.getCell(sheetId, selectedMatch.col, selectedMatch.row); + const cell = this.getters.getCell({ sheetId, ...selectedMatch }); if ((cell === null || cell === void 0 ? void 0 : cell.isFormula) && !this.searchOptions.searchFormulas) { this.selectNextCell(Direction.next); } @@ -33648,12 +33653,12 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.replace(replaceWith); } } - getSearchableString({ sheetId, col, row }) { - const cell = this.getters.getCell(sheetId, col, row); + getSearchableString(position) { + const cell = this.getters.getCell(position); if (this.searchOptions.searchFormulas && (cell === null || cell === void 0 ? void 0 : cell.isFormula)) { return cell.content; } - return this.getters.getEvaluatedCell({ sheetId, col, row }).formattedValue; + return this.getters.getEvaluatedCell(position).formattedValue; } // --------------------------------------------------------------------------- // Grid rendering @@ -33662,7 +33667,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const { ctx } = renderingContext; const sheetId = this.getters.getActiveSheetId(); for (const match of this.searchMatches) { - const merge = this.getters.getMerge(sheetId, match.col, match.row); + const merge = this.getters.getMerge({ sheetId, col: match.col, row: match.row }); const left = merge ? merge.left : match.col; const right = merge ? merge.right : match.col; const top = merge ? merge.top : match.row; @@ -33741,7 +33746,6 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A return undefined; } } - FormatPlugin.modes = ["normal"]; class HeaderVisibilityUIPlugin extends UIPlugin { isRowHidden(sheetId, index) { @@ -33755,8 +33759,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A ? this.isColHidden(sheetId, index) : this.isRowHidden(sheetId, index); } - getNextVisibleCellPosition(sheetId, col, row) { + getNextVisibleCellPosition({ sheetId, col, row }) { return { + sheetId, col: this.findVisibleHeader(sheetId, "COL", range(col, this.getters.getNumberCols(sheetId))), row: this.findVisibleHeader(sheetId, "ROW", range(row, this.getters.getNumberRows(sheetId))), }; @@ -34259,10 +34264,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const sheetId = this.getters.getActiveSheetId(); let col = base; while (col < max) { - const nextCell = this.getters.getEvaluatedCell({ sheetId, col: col + 1, row }); - const nextCellBorder = this.getters.getCellBorderWithFilterBorder(sheetId, col + 1, row); + const position = { sheetId, col: col + 1, row }; + const nextCell = this.getters.getEvaluatedCell(position); + const nextCellBorder = this.getters.getCellBorderWithFilterBorder(position); if (nextCell.type !== CellValueType.empty || - this.getters.isInMerge(sheetId, col + 1, row) || + this.getters.isInMerge(position) || (nextCellBorder === null || nextCellBorder === void 0 ? void 0 : nextCellBorder.left)) { return col; } @@ -34274,10 +34280,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const sheetId = this.getters.getActiveSheetId(); let col = base; while (col > min) { - const previousCell = this.getters.getEvaluatedCell({ sheetId, col: col - 1, row }); - const previousCellBorder = this.getters.getCellBorderWithFilterBorder(sheetId, col - 1, row); + const position = { sheetId, col: col - 1, row }; + const previousCell = this.getters.getEvaluatedCell(position); + const previousCellBorder = this.getters.getCellBorderWithFilterBorder(position); if (previousCell.type !== CellValueType.empty || - this.getters.isInMerge(sheetId, col - 1, row) || + this.getters.isInMerge(position) || (previousCellBorder === null || previousCellBorder === void 0 ? void 0 : previousCellBorder.right)) { return col; } @@ -34285,13 +34292,13 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } return col; } - computeCellAlignment({ sheetId, col, row }, isOverflowing) { - const cell = this.getters.getCell(sheetId, col, row); + computeCellAlignment(position, isOverflowing) { + const cell = this.getters.getCell(position); if ((cell === null || cell === void 0 ? void 0 : cell.isFormula) && this.getters.shouldShowFormulas()) { return "left"; } - const { align } = this.getters.getCellStyle({ sheetId, col, row }); - const evaluatedCell = this.getters.getEvaluatedCell({ sheetId, col, row }); + const { align } = this.getters.getCellStyle(position); + const evaluatedCell = this.getters.getEvaluatedCell(position); if (isOverflowing && evaluatedCell.type === CellValueType.number) { return align !== "center" ? "left" : align; } @@ -34303,7 +34310,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const right = visibleCols[visibleCols.length - 1]; const col = zone.left; const row = zone.top; - const cell = this.getters.getEvaluatedCell({ sheetId, col, row }); + const position = { sheetId, col, row }; + const cell = this.getters.getEvaluatedCell(position); const showFormula = this.getters.shouldShowFormulas(); const { x, y, width, height } = this.getters.getVisibleRect(zone); const box = { @@ -34311,14 +34319,14 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A y, width, height, - border: this.getters.getCellBorderWithFilterBorder(sheetId, col, row) || undefined, - style: this.getters.getCellComputedStyle(sheetId, col, row), + border: this.getters.getCellBorderWithFilterBorder(position) || undefined, + style: this.getters.getCellComputedStyle(position), }; if (cell.type === CellValueType.empty) { return box; } /** Icon CF */ - const cfIcon = this.getters.getConditionalIcon(col, row); + const cfIcon = this.getters.getConditionalIcon(position); const fontSizePX = computeTextFontSizeInPixels(box.style); const iconBoxWidth = cfIcon ? 2 * MIN_CF_ICON_MARGIN + fontSizePX : 0; if (cfIcon) { @@ -34330,10 +34338,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A }; } /** Filter Header */ - box.isFilterHeader = this.getters.isFilterHeader(sheetId, col, row); + box.isFilterHeader = this.getters.isFilterHeader(position); const headerIconWidth = box.isFilterHeader ? ICON_EDGE_LENGTH + FILTER_ICON_MARGIN : 0; /** Content */ - const position = { sheetId, col, row }; const text = this.getters.getCellText(position, showFormula); const textWidth = this.getters.getTextWidth(position); const wrapping = this.getters.getCellStyle(position).wrapping || "overflow"; @@ -34363,10 +34370,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } else if (isOverflowing && wrapping === "overflow") { let nextColIndex, previousColIndex; - const isCellInMerge = this.getters.isInMerge(sheetId, col, row); + const isCellInMerge = this.getters.isInMerge(position); if (isCellInMerge) { // Always clip merges - nextColIndex = this.getters.getMerge(sheetId, col, row).right; + nextColIndex = this.getters.getMerge(position).right; previousColIndex = col; } else { @@ -34427,12 +34434,13 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const bottom = visibleRows[visibleRows.length - 1]; const viewport = { left, right, top, bottom }; const sheetId = this.getters.getActiveSheetId(); - for (const rowNumber of visibleRows) { - for (const colNumber of visibleCols) { - if (this.getters.isInMerge(sheetId, colNumber, rowNumber)) { + for (const row of visibleRows) { + for (const col of visibleCols) { + const position = { sheetId, col, row }; + if (this.getters.isInMerge(position)) { continue; } - boxes.push(this.createZoneBox(sheetId, positionToZone({ col: colNumber, row: rowNumber }))); + boxes.push(this.createZoneBox(sheetId, positionToZone(position))); } } for (const merge of this.getters.getMerges(sheetId)) { @@ -34441,7 +34449,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } if (overlap(merge, viewport)) { const box = this.createZoneBox(sheetId, merge); - const borderBottomRight = this.getters.getCellBorder(sheetId, merge.right, merge.bottom); + const borderBottomRight = this.getters.getCellBorder({ + sheetId, + col: merge.right, + row: merge.bottom, + }); box.border = { ...box.border, bottom: borderBottomRight ? borderBottomRight.bottom : undefined, @@ -34465,8 +34477,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * This plugin handles this internal state. */ class SelectionInputPlugin extends UIPlugin { - constructor(getters, state, dispatch, config, selection, initialRanges, inputHasSingleRange) { - super(getters, state, dispatch, config, selection); + constructor(config, initialRanges, inputHasSingleRange) { + super(config); this.inputHasSingleRange = inputHasSingleRange; this.ranges = []; this.focusedRangeIndex = null; @@ -34539,7 +34551,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } case "ACTIVATE_SHEET": { if (cmd.sheetIdFrom !== cmd.sheetIdTo) { - const { col, row } = this.getters.getNextVisibleCellPosition(cmd.sheetIdTo, 0, 0); + const { col, row } = this.getters.getNextVisibleCellPosition({ + sheetId: cmd.sheetIdTo, + col: 0, + row: 0, + }); const zone = this.getters.expandZone(cmd.sheetIdTo, positionToZone({ col, row })); this.selection.resetAnchor(this, { cell: { col, row }, zone }); } @@ -34684,9 +34700,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * This plugin handles this internal state. */ class SelectionInputsManagerPlugin extends UIPlugin { - constructor(getters, state, dispatch, config, selection) { - super(getters, state, dispatch, config, selection); - this.state = state; + constructor(config) { + super(config); this.config = config; this.inputs = {}; this.focusedInputId = null; @@ -34740,7 +34755,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A if (cmd.id !== this.focusedInputId) { const input = this.inputs[cmd.id]; const range = input.ranges.find((range) => range.id === cmd.rangeId); - const zone = toZone((range === null || range === void 0 ? void 0 : range.xc) || "A1"); + const sheetId = this.getters.getActiveSheetId(); + const zone = this.getters.getRangeFromSheetXC(sheetId, (range === null || range === void 0 ? void 0 : range.xc) || "A1").zone; this.selection.capture(input, { cell: { col: zone.left, row: zone.top }, zone }, { handleEvent: input.handleEvent.bind(input) }); this.focusedInputId = cmd.id; } @@ -34792,7 +34808,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A // Other // --------------------------------------------------------------------------- initInput(id, initialRanges, inputHasSingleRange = false) { - this.inputs[id] = new SelectionInputPlugin(this.getters, this.state, this.dispatch, this.config, this.selection, initialRanges, inputHasSingleRange); + this.inputs[id] = new SelectionInputPlugin(this.config, initialRanges, inputHasSingleRange); if (initialRanges.length === 0) { const input = this.inputs[id]; const anchor = { @@ -35346,12 +35362,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A return 0 /* CommandResult.Success */; } /*Test the presence of single cells*/ - for (let row = zone.top; row <= zone.bottom; row++) { - for (let col = zone.left; col <= zone.right; col++) { - if (!this.getters.isInMerge(sheetId, col, row)) { - return 61 /* CommandResult.InvalidSortZone */; - } - } + const singleCells = positions(zone).some(({ col, row }) => !this.getters.isInMerge({ sheetId, col, row })); + if (singleCells) { + return 61 /* CommandResult.InvalidSortZone */; } return 0 /* CommandResult.Success */; } @@ -35397,7 +35410,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const { left, right, top, bottom } = expandedZone; for (let c = left; c <= right; c++) { for (let r = top; r <= bottom; r++) { - const { col, row } = this.getters.getMainCellPosition(sheetId, c, r); + const { col, row } = this.getters.getMainCellPosition({ sheetId, col: c, row: r }); cell = this.getters.getEvaluatedCell({ sheetId, col, row }); if (cell.formattedValue) { return true; @@ -35541,7 +35554,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } sortZone(sheetId, anchor, zone, sortDirection, options) { const [stepX, stepY] = this.mainCellsSteps(sheetId, zone); - let sortingCol = this.getters.getMainCellPosition(sheetId, anchor.col, anchor.row).col; // fetch anchor + let sortingCol = this.getters.getMainCellPosition({ + sheetId, + col: anchor.col, + row: anchor.row, + }).col; // fetch anchor let sortZone = Object.assign({}, zone); // Update in case of merges in the zone let cellPositions = this.mainCells(sheetId, zone); @@ -35557,7 +35574,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (let c = 0; c < width; c++) { for (let r = 0; r < height; r++) { let { col, row, sheetId } = cellPositions[c][sortedIndex[r]]; - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell({ sheetId, col, row }); let newCol = sortZone.left + c * stepX; let newRow = sortZone.top + r * stepY; let newCellValues = { @@ -35592,7 +35609,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * Note: it is assumed all merges are the same in the zone. */ mainCellsSteps(sheetId, zone) { - const merge = this.getters.getMerge(sheetId, zone.left, zone.top); + const merge = this.getters.getMerge({ sheetId, col: zone.left, row: zone.top }); const stepX = merge ? merge.right - merge.left + 1 : 1; const stepY = merge ? merge.bottom - merge.top + 1 : 1; return [stepX, stepY]; @@ -35693,22 +35710,20 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A // --------------------------------------------------------------------------- // Getters // --------------------------------------------------------------------------- - getCellWidth(sheetId, { col, row }) { - const position = { sheetId, col, row }; + getCellWidth(position) { let contentWidth = this.getTextWidth(position); - const icon = this.getters.getConditionalIcon(col, row); + const icon = this.getters.getConditionalIcon(position); if (icon) { contentWidth += computeIconWidth(this.getters.getCellStyle(position)); } - const isFilterHeader = this.getters.isFilterHeader(sheetId, col, row); + const isFilterHeader = this.getters.isFilterHeader(position); if (isFilterHeader) { contentWidth += ICON_EDGE_LENGTH + FILTER_ICON_MARGIN; } if (contentWidth > 0) { contentWidth += 2 * PADDING_AUTORESIZE_HORIZONTAL; if (this.getters.getCellStyle(position).wrapping === "wrap") { - const zone = positionToZone({ col, row }); - const colWidth = this.getters.getColSize(this.getters.getActiveSheetId(), zone.left); + const colWidth = this.getters.getColSize(this.getters.getActiveSheetId(), position.col); return Math.min(colWidth, contentWidth); } } @@ -35716,16 +35731,15 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } getTextWidth(position) { const text = this.getters.getCellText(position, this.getters.shouldShowFormulas()); - const { sheetId, col, row } = position; - return computeTextWidth(this.ctx, text, this.getters.getCellComputedStyle(sheetId, col, row)); + return computeTextWidth(this.ctx, text, this.getters.getCellComputedStyle(position)); } - getCellText({ sheetId, col, row }, showFormula = false) { - const cell = this.getters.getCell(sheetId, col, row); + getCellText(position, showFormula = false) { + const cell = this.getters.getCell(position); if (showFormula && (cell === null || cell === void 0 ? void 0 : cell.isFormula)) { return cell.content; } else { - return this.getters.getEvaluatedCell({ sheetId, col, row }).formattedValue; + return this.getters.getEvaluatedCell(position).formattedValue; } } getCellMultiLineText(position, width) { @@ -35830,7 +35844,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A // --------------------------------------------------------------------------- getColMaxWidth(sheetId, index) { const cellsPositions = positions(this.getters.getColsZone(sheetId, index, index)); - const sizes = cellsPositions.map((position) => this.getCellWidth(sheetId, position)); + const sizes = cellsPositions.map((position) => this.getCellWidth({ sheetId, ...position })); return Math.max(0, ...sizes); } splitWordToSpecificWidth(ctx, word, width, style) { @@ -35940,11 +35954,12 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (let row of rowsIndex) { let cellsInRow = []; for (let col of columnsIndex) { + const position = { col, row, sheetId }; cellsInRow.push({ - cell: getters.getCell(sheetId, col, row), - evaluatedCell: getters.getEvaluatedCell({ sheetId, col, row }), - border: getters.getCellBorder(sheetId, col, row) || undefined, - position: { col, row, sheetId }, + cell: getters.getCell(position), + evaluatedCell: getters.getEvaluatedCell(position), + border: getters.getCellBorder(position) || undefined, + position, }); } cellsInClipboard.push(cellsInRow); @@ -35954,7 +35969,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A for (const table of this.getters.getFilterTablesInZone(sheetId, zone)) { const values = []; for (const col of range(table.zone.left, table.zone.right + 1)) { - values.push(this.getters.getFilterValues(sheetId, col, table.zone.top)); + values.push(this.getters.getFilterValues({ sheetId, col, row: table.zone.top })); } tables.push({ filtersValues: values, zone: table.zone }); } @@ -36186,7 +36201,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const { sheetId, col, row } = target; const targetCell = this.getters.getEvaluatedCell(target); if ((clipboardOption === null || clipboardOption === void 0 ? void 0 : clipboardOption.pasteOption) !== "onlyValue") { - const targetBorders = this.getters.getCellBorder(sheetId, col, row); + const targetBorders = this.getters.getCellBorder(target); const originBorders = origin.border; const border = { top: (targetBorders === null || targetBorders === void 0 ? void 0 : targetBorders.top) || (originBorders === null || originBorders === void 0 ? void 0 : originBorders.top), @@ -36248,9 +36263,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ pasteMergeIfExist(origin, target) { let { sheetId, col, row } = origin; - const { col: mainCellColOrigin, row: mainCellRowOrigin } = this.getters.getMainCellPosition(sheetId, col, row); + const { col: mainCellColOrigin, row: mainCellRowOrigin } = this.getters.getMainCellPosition(origin); if (mainCellColOrigin === col && mainCellRowOrigin === row) { - const merge = this.getters.getMerge(sheetId, col, row); + const merge = this.getters.getMerge(origin); if (!merge) { return; } @@ -36712,8 +36727,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * SelectionPlugin */ class GridSelectionPlugin extends UIPlugin { - constructor(getters, state, dispatch, config, selection) { - super(getters, state, dispatch, config, selection); + constructor(config) { + super(config); this.gridSelection = { anchor: { cell: { col: 0, row: 0 }, @@ -36799,7 +36814,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A sheetIdTo: firstSheetId, sheetIdFrom: firstSheetId, }); - const { col, row } = this.getters.getNextVisibleCellPosition(firstSheetId, 0, 0); + const { col, row } = this.getters.getNextVisibleCellPosition({ + sheetId: firstSheetId, + col: 0, + row: 0, + }); this.selectCell(col, row); this.selection.registerAsDefault(this, this.gridSelection.anchor, { handleEvent: this.handleEvent.bind(this), @@ -36819,7 +36838,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.selection.resetDefaultAnchor(this, deepCopy(this.gridSelection.anchor)); } else { - const { col, row } = this.getters.getNextVisibleCellPosition(cmd.sheetIdTo, 0, 0); + const { col, row } = this.getters.getNextVisibleCellPosition({ + sheetId: cmd.sheetIdTo, + col: 0, + row: 0, + }); this.selectCell(col, row); } break; @@ -36918,10 +36941,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A return this.activeSheet.id; } getActiveCell() { - const sheetId = this.getters.getActiveSheetId(); - const { col, row } = this.gridSelection.anchor.cell; - const mainPosition = this.getters.getMainCellPosition(sheetId, col, row); - return this.getters.getEvaluatedCell({ sheetId, ...mainPosition }); + return this.getters.getEvaluatedCell(this.getActivePosition()); } getActiveCols() { const activeCols = new Set(); @@ -36964,21 +36984,26 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A getSelectedFigureId() { return this.selectedFigureId; } - getPosition() { - return { col: this.gridSelection.anchor.cell.col, row: this.gridSelection.anchor.cell.row }; + getActivePosition() { + return this.getters.getMainCellPosition({ + sheetId: this.getActiveSheetId(), + col: this.gridSelection.anchor.cell.col, + row: this.gridSelection.anchor.cell.row, + }); } getSheetPosition(sheetId) { if (sheetId === this.getters.getActiveSheetId()) { - return this.getPosition(); + return this.getActivePosition(); } else { const sheetData = this.sheetsData[sheetId]; return sheetData ? { + sheetId, col: sheetData.gridSelection.anchor.cell.col, row: sheetData.gridSelection.anchor.cell.row, } - : this.getters.getNextVisibleCellPosition(sheetId, 0, 0); + : this.getters.getNextVisibleCellPosition({ sheetId, col: 0, row: 0 }); } } getStatisticFnResults() { @@ -37251,21 +37276,15 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } ctx.globalCompositeOperation = "source-over"; // active zone - const activeSheet = this.getters.getActiveSheetId(); - const { col, row } = this.getPosition(); + const position = this.getActivePosition(); ctx.strokeStyle = SELECTION_BORDER_COLOR; ctx.lineWidth = 3 * thinLineWidth; let zone; - if (this.getters.isInMerge(activeSheet, col, row)) { - zone = this.getters.getMerge(activeSheet, col, row); + if (this.getters.isInMerge(position)) { + zone = this.getters.getMerge(position); } else { - zone = { - top: row, - bottom: row, - left: col, - right: col, - }; + zone = positionToZone(position); } const { x, y, width, height } = this.getters.getVisibleRect(zone); if (width > 0 && height > 0) { @@ -37287,7 +37306,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A "getAggregate", "getSelectedFigureId", "getSelection", - "getPosition", + "getActivePosition", "getSheetPosition", "isSelected", "getElementsFromSelection", @@ -37614,13 +37633,14 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A const sheetId = this.env.model.getters.getActiveSheetId(); for (const col of this.env.model.getters.getSheetViewVisibleCols()) { for (const row of this.env.model.getters.getSheetViewVisibleRows()) { - const action = this.getClickableAction({ sheetId, col, row }); + const position = { sheetId, col, row }; + const action = this.getClickableAction(position); if (!action) { continue; } let zone; - if (this.env.model.getters.isInMerge(sheetId, col, row)) { - zone = this.env.model.getters.getMerge(sheetId, col, row); + if (this.env.model.getters.isInMerge(position)) { + zone = this.env.model.getters.getMerge(position); } else { zone = positionToZone({ col, row }); @@ -38305,7 +38325,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A } updateCellState() { const zones = this.env.model.getters.getSelectedZones(); - const sheetId = this.env.model.getters.getActiveSheetId(); + const { col, row, sheetId } = this.env.model.getters.getActivePosition(); this.inMerge = false; const { top, left, right, bottom } = this.env.model.getters.getSelectedZone(); const { xSplit, ySplit } = this.env.model.getters.getPaneDivisions(sheetId); @@ -38315,13 +38335,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A (left < xSplit && xSplit <= right) || (top < ySplit && ySplit <= bottom); if (!this.cannotMerge) { - const { col, row } = this.env.model.getters.getPosition(); - const zone = this.env.model.getters.expandZone(sheetId, { - left: col, - right: col, - top: row, - bottom: row, - }); + const zone = this.env.model.getters.expandZone(sheetId, positionToZone({ col, row })); this.inMerge = isEqual(zones[0], zone); } this.undoTool = this.env.model.getters.canUndo(); @@ -40092,7 +40106,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A */ addCellToSelection(col, row) { const sheetId = this.getters.getActiveSheetId(); - ({ col, row } = this.getters.getMainCellPosition(sheetId, col, row)); + ({ col, row } = this.getters.getMainCellPosition({ sheetId, col, row })); const zone = this.getters.expandZone(sheetId, positionToZone({ col, row })); return this.processEvent({ type: "ZonesSelected", @@ -40451,8 +40465,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * check if the merge containing the cell is empty. */ isCellEmpty({ col, row }, sheetId = this.getters.getActiveSheetId()) { - const mainCellPosition = this.getters.getMainCellPosition(sheetId, col, row); - const cell = this.getters.getEvaluatedCell({ sheetId, ...mainCellPosition }); + const position = this.getters.getMainCellPosition({ sheetId, col, row }); + const cell = this.getters.getEvaluatedCell(position); return cell.type === CellValueType.empty; } /** Computes the next cell position in the given direction by crossing through merges and skipping hidden cells. @@ -42066,7 +42080,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * 2. This allows us to define its type by using the interface CommandDispatcher */ this.dispatch = (type, payload) => { - const command = { type, ...payload }; + const command = { ...payload, type }; let status = this.status; if (this.getters.isReadonly() && !canExecuteInReadonly(command)) { return new DispatchResult(65 /* CommandResult.Readonly */); @@ -42111,7 +42125,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * A command dispatched from this function is not added to the history. */ this.dispatchFromCorePlugin = (type, payload) => { - const command = { type, ...payload }; + const command = { ...payload, type }; const previousStatus = this.status; this.status = 2 /* Status.RunningCore */; const handlers = this.isReplayingCommand @@ -42127,7 +42141,6 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.uuidGenerator = uuidGenerator; this.config = this.setupConfig(config); this.session = this.setupSession(workbookData.revisionId); - this.config.moveClient = this.session.move.bind(this.session); this.history = new LocalHistory(this.dispatchFromCorePlugin, this.session); this.coreGetters = {}; this.range = new RangeAdapter(this.coreGetters); @@ -42150,6 +42163,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.uuidGenerator.setIsFastStrategy(true); // Initiate stream processor this.selection = new SelectionStreamProcessor(this.getters); + this.corePluginConfig = this.setupCorePluginConfig(); + this.uiPluginConfig = this.setupUiPluginConfig(); // registering plugins for (let Plugin of corePluginRegistry.getAll()) { this.setupCorePlugin(Plugin, workbookData); @@ -42198,7 +42213,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A this.session.leave(); } setupUiPlugin(Plugin) { - const plugin = new Plugin(this.getters, this.state, this.dispatch, this.config, this.selection); + const plugin = new Plugin(this.uiPluginConfig); for (let name of Plugin.getters) { if (!(name in plugin)) { throw new Error(`Invalid getter name: ${name} for plugin ${plugin.constructor}`); @@ -42220,7 +42235,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A * reason why the model could not add dynamically a plugin while it is running. */ setupCorePlugin(Plugin, data) { - const plugin = new Plugin(this.coreGetters, this.state, this.range, this.dispatchFromCorePlugin, this.config, this.uuidGenerator); + const plugin = new Plugin(this.corePluginConfig); for (let name of Plugin.getters) { if (!(name in plugin)) { throw new Error(`Invalid getter name: ${name} for plugin ${plugin.constructor}`); @@ -42267,7 +42282,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A return { ...config, mode: config.mode || "normal", - evalContext: config.evalContext || {}, + external: config.external || {}, transportService, client, moveClient: () => { }, @@ -42275,6 +42290,27 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A notifyUI: (payload) => this.trigger("notify-ui", payload), }; } + setupCorePluginConfig() { + return { + getters: this.coreGetters, + stateObserver: this.state, + range: this.range, + dispatch: this.dispatchFromCorePlugin, + uuidGenerator: this.uuidGenerator, + external: this.config.external, + }; + } + setupUiPluginConfig() { + return { + getters: this.getters, + stateObserver: this.state, + dispatch: this.dispatch, + selection: this.selection, + moveClient: this.session.move.bind(this.session), + external: this.config.external, + uiActions: this.config, + }; + } // --------------------------------------------------------------------------- // Command Handling // --------------------------------------------------------------------------- @@ -42505,8 +42541,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A Object.defineProperty(exports, '__esModule', { value: true }); exports.__info__.version = '2.0.0'; - exports.__info__.date = '2022-11-24T09:39:42.179Z'; - exports.__info__.hash = '277a39f'; + exports.__info__.date = '2022-11-25T15:03:52.691Z'; + exports.__info__.hash = 'ab6f47f'; })(this.o_spreadsheet = this.o_spreadsheet || {}, owl); //# sourceMappingURL=o_spreadsheet.js.map diff --git a/addons/spreadsheet/static/src/pivot/index.js b/addons/spreadsheet/static/src/pivot/index.js index 5a33a9e006c..07896ab450a 100644 --- a/addons/spreadsheet/static/src/pivot/index.js +++ b/addons/spreadsheet/static/src/pivot/index.js @@ -31,16 +31,12 @@ cellMenuRegistry.add("pivot_see_records", { name: _lt("See records"), sequence: 175, action: async (env) => { - const sheetId = env.model.getters.getActiveSheetId(); - const { col, row } = env.model.getters.getPosition(); - const position = env.model.getters.getMainCellPosition(sheetId, col, row); - await SEE_RECORDS_PIVOT({ sheetId, ...position }, env); + const position = env.model.getters.getActivePosition(); + await SEE_RECORDS_PIVOT(position, env); }, isVisible: (env) => { - const sheetId = env.model.getters.getActiveSheetId(); - const { col, row } = env.model.getters.getPosition(); - const position = env.model.getters.getMainCellPosition(sheetId, col, row); - return SEE_RECORDS_PIVOT_VISIBLE({ sheetId, ...position }, env); + const position = env.model.getters.getActivePosition(); + return SEE_RECORDS_PIVOT_VISIBLE(position, env); }, }); diff --git a/addons/spreadsheet/static/src/pivot/pivot_actions.js b/addons/spreadsheet/static/src/pivot/pivot_actions.js index e91f4eb3926..576bfdddd13 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_actions.js +++ b/addons/spreadsheet/static/src/pivot/pivot_actions.js @@ -4,8 +4,8 @@ import { getFirstPivotFunction, getNumberOfPivotFormulas } from "./pivot_helpers const { astToFormula } = spreadsheet; -export const SEE_RECORDS_PIVOT = async ({ sheetId, col, row }, env) => { - const cell = env.model.getters.getCell(sheetId, col, row); +export const SEE_RECORDS_PIVOT = async (position, env) => { + const cell = env.model.getters.getCell(position); if (!cell) { return; } @@ -13,7 +13,7 @@ export const SEE_RECORDS_PIVOT = async ({ sheetId, col, row }, env) => { const evaluatedArgs = args .map(astToFormula) .map((arg) => env.model.getters.evaluateFormula(arg)); - const pivotId = env.model.getters.getPivotIdFromPosition(sheetId, col, row); + const pivotId = env.model.getters.getPivotIdFromPosition(position); const { model } = env.model.getters.getPivotDefinition(pivotId); const dataSource = await env.model.getters.getAsyncPivotDataSource(pivotId); const slice = functionName === "ODOO.PIVOT.HEADER" ? 1 : 2; @@ -40,7 +40,7 @@ export const SEE_RECORDS_PIVOT = async ({ sheetId, col, row }, env) => { export const SEE_RECORDS_PIVOT_VISIBLE = (position, env) => { const evaluatedCell = env.model.getters.getEvaluatedCell(position); - const cell = env.model.getters.getCell(position.sheetId, position.col, position.row); + const cell = env.model.getters.getCell(position); return ( evaluatedCell.type !== "empty" && evaluatedCell.type !== "error" && diff --git a/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js b/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js index c7a6d2cf024..d79104a29f6 100644 --- a/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js +++ b/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js @@ -36,9 +36,9 @@ import { sprintf } from "@web/core/utils/strings"; const { CorePlugin } = spreadsheet; export default class PivotCorePlugin extends CorePlugin { - constructor(getters, history, range, dispatch, config, uuidGenerator) { - super(getters, history, range, dispatch, config, uuidGenerator); - this.dataSources = config.dataSources; + constructor(config) { + super(config); + this.dataSources = config.external.dataSources; this.nextId = 1; /** @type {Object.} */ diff --git a/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js b/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js index ac17b071d0f..979f307f9cb 100644 --- a/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js +++ b/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js @@ -43,8 +43,8 @@ function pivotPeriodToFilterValue(timeRange, value) { } export default class PivotUIPlugin extends spreadsheet.UIPlugin { - constructor() { - super(...arguments); + constructor(config) { + super(config); /** @type {string} */ this.selectedPivotId = undefined; this.selection.observe(this, { @@ -60,7 +60,7 @@ export default class PivotUIPlugin extends spreadsheet.UIPlugin { case "ZonesSelected": { const sheetId = this.getters.getActiveSheetId(); const { col, row } = event.anchor.cell; - const cell = this.getters.getCell(sheetId, col, row); + const cell = this.getters.getCell({ sheetId, col, row }); if (cell !== undefined && cell.content.startsWith("=ODOO.PIVOT.HEADER(")) { const filters = this.getFiltersMatchingPivot(cell.content); this.dispatch("SET_MANY_GLOBAL_FILTER_VALUE", { filters }); @@ -136,14 +136,12 @@ export default class PivotUIPlugin extends spreadsheet.UIPlugin { * Get the id of the pivot at the given position. Returns undefined if there * is no pivot at this position * - * @param {string} sheetId Id of the sheet - * @param {number} col Index of the col - * @param {number} row Index of the row + * @param {{ sheetId: string; col: number; row: number}} position * * @returns {string|undefined} */ - getPivotIdFromPosition(sheetId, col, row) { - const cell = this.getters.getCell(sheetId, col, row); + getPivotIdFromPosition(position) { + const cell = this.getters.getCell(position); if (cell && cell.isFormula) { const pivotFunction = getFirstPivotFunction(cell.content); if (pivotFunction) { diff --git a/addons/spreadsheet/static/tests/charts/model/link_chart_plugin_test.js b/addons/spreadsheet/static/tests/charts/model/link_chart_plugin_test.js index f24e2fd7726..0fd6ba4d60a 100644 --- a/addons/spreadsheet/static/tests/charts/model/link_chart_plugin_test.js +++ b/addons/spreadsheet/static/tests/charts/model/link_chart_plugin_test.js @@ -124,7 +124,7 @@ QUnit.module( "Links between charts and ir.menus are correctly imported/exported", async function (assert) { const env = await makeTestEnv({ serverData: this.serverData }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); createBasicChart(model, chartId); model.dispatch("LINK_ODOO_MENU_TO_CHART", { chartId, @@ -136,7 +136,7 @@ QUnit.module( 1, "Link to odoo menu is exported" ); - const importedModel = new Model(exportedData, { evalContext: { env } }); + const importedModel = new Model(exportedData, { external: { env } }); const chartMenu = importedModel.getters.getChartOdooMenu(chartId); assert.equal(chartMenu.id, 1, "Link to odoo menu is imported"); } @@ -144,7 +144,7 @@ QUnit.module( QUnit.test("Can undo-redo a LINK_ODOO_MENU_TO_CHART", async function (assert) { const env = await makeTestEnv({ serverData: this.serverData }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); createBasicChart(model, chartId); model.dispatch("LINK_ODOO_MENU_TO_CHART", { chartId, @@ -159,7 +159,7 @@ QUnit.module( QUnit.test("link is removed when figure is deleted", async function (assert) { const env = await makeTestEnv({ serverData: this.serverData }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); createBasicChart(model, chartId); model.dispatch("LINK_ODOO_MENU_TO_CHART", { chartId, diff --git a/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js b/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js index 4922a23a85a..7a1121e0838 100644 --- a/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js +++ b/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js @@ -378,8 +378,7 @@ QUnit.module("spreadsheet > Global filters model", {}, () => { assert.equal(listDomain.length, 7, "it should have updated the list domain"); const newModel = new Model(model.exportData(), { - evalContext: model.config.evalContext, - dataSources: model.config.dataSources, + external: model.config.external, }); assert.equal(newModel.getters.getGlobalFilters().length, 2); @@ -639,8 +638,10 @@ QUnit.module("spreadsheet > Global filters model", {}, () => { const model = new Model( {}, { - dataSources: new DataSources({ ...orm, silent: orm }), - evalContext: { env: { services: { orm } } }, + external: { + dataSources: new DataSources({ ...orm, silent: orm }), + env: { services: { orm } }, + }, } ); setupDataSourceEvaluation(model); diff --git a/addons/spreadsheet/static/tests/links/model/link_menu_cells_test.js b/addons/spreadsheet/static/tests/links/model/link_menu_cells_test.js index 53984990764..d12901e1620 100644 --- a/addons/spreadsheet/static/tests/links/model/link_menu_cells_test.js +++ b/addons/spreadsheet/static/tests/links/model/link_menu_cells_test.js @@ -26,7 +26,7 @@ function beforeEach() { QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => { QUnit.test("ir.menu linked based on xml id", async function (assert) { const env = await makeTestEnv({ serverData: getMenuServerData() }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); setCellContent(model, "A1", "[label](odoo://ir_menu_xml_id/test_menu)"); const cell = getCell(model, "A1"); const evaluatedCell = getEvaluatedCell(model, "A1"); @@ -46,7 +46,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => { QUnit.test("ir.menu linked based on record id", async function (assert) { const env = await makeTestEnv({ serverData: getMenuServerData() }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); setCellContent(model, "A1", "[label](odoo://ir_menu_id/2)"); const cell = getCell(model, "A1"); const evaluatedCell = getEvaluatedCell(model, "A1"); @@ -66,7 +66,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => { QUnit.test("ir.menu linked based on xml id which does not exists", async function (assert) { const env = await makeTestEnv({ serverData: getMenuServerData() }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); setCellContent(model, "A1", "[label](odoo://ir_menu_xml_id/does_not_exists)"); assert.equal( getCell(model, "A1").content, @@ -81,7 +81,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => { QUnit.test("ir.menu linked based on record id which does not exists", async function (assert) { const env = await makeTestEnv({ serverData: getMenuServerData() }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); setCellContent(model, "A1", "[label](odoo://ir_menu_id/9999)"); assert.equal(getCell(model, "A1").content, "[label](odoo://ir_menu_id/9999)"); assert.equal(getEvaluatedCell(model, "A1").value, "#LINK"); @@ -93,7 +93,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => { QUnit.test("Odoo link cells can be imported/exported", async function (assert) { const env = await makeTestEnv({ serverData: getMenuServerData() }); - const model = new Model({}, { evalContext: { env } }); + const model = new Model({}, { external: { env } }); setCellContent(model, "A1", "[label](odoo://ir_menu_id/2)"); let cell = getCell(model, "A1"); let evaluatedCell = getEvaluatedCell(model, "A1"); @@ -109,7 +109,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => { "odoo://ir_menu_id/2", "The link url should reference the correct menu" ); - const model2 = new Model(model.exportData(), { evalContext: { env } }); + const model2 = new Model(model.exportData(), { external: { env } }); cell = getCell(model2, "A1"); evaluatedCell = getEvaluatedCell(model, "A1"); assert.equal(evaluatedCell.value, "label", "The value should be the menu name"); diff --git a/addons/spreadsheet/static/tests/links/open_links_tests.js b/addons/spreadsheet/static/tests/links/open_links_tests.js index 113592d8445..381bd210263 100644 --- a/addons/spreadsheet/static/tests/links/open_links_tests.js +++ b/addons/spreadsheet/static/tests/links/open_links_tests.js @@ -41,7 +41,7 @@ QUnit.test("click a web link", async (assert) => { }, ], }; - const model = new Model(data, { evalContext: { env } }); + const model = new Model(data, { external: { env } }); const cell = getEvaluatedCell(model, "A1"); assert.strictEqual(urlRepresentation(cell.link, model.getters), "https://odoo.com"); openLink(cell.link, env); @@ -68,7 +68,7 @@ QUnit.test("click a menu link", async (assert) => { }, ], }; - const model = new Model(data, { evalContext: { env } }); + const model = new Model(data, { external: { env } }); const cell = getEvaluatedCell(model, "A1"); assert.strictEqual(urlRepresentation(cell.link, model.getters), "menu with xmlid"); openLink(cell.link, env); @@ -112,7 +112,7 @@ QUnit.test("click a menu link", async (assert) => { }, ], }; - const model = new Model(data, { evalContext: { env } }); + const model = new Model(data, { external: { env } }); const cell = getEvaluatedCell(model, "A1"); assert.strictEqual(urlRepresentation(cell.link, model.getters), "an odoo view"); openLink(cell.link, env); diff --git a/addons/spreadsheet/static/tests/lists/list_plugin_test.js b/addons/spreadsheet/static/tests/lists/list_plugin_test.js index b47e4b3b9a7..745f50fab08 100644 --- a/addons/spreadsheet/static/tests/lists/list_plugin_test.js +++ b/addons/spreadsheet/static/tests/lists/list_plugin_test.js @@ -101,7 +101,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => { QUnit.test("can select a List from cell formula", async function (assert) { const { model } = await createSpreadsheetWithList(); const sheetId = model.getters.getActiveSheetId(); - const listId = model.getters.getListIdFromPosition(sheetId, 0, 0); + const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 }); model.dispatch("SELECT_ODOO_LIST", { listId }); const selectedListId = model.getters.getSelectedListId(); assert.strictEqual(selectedListId, "1"); @@ -113,7 +113,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => { const { model } = await createSpreadsheetWithList(); setCellContent(model, "A1", `=-ODOO.LIST("1","1","foo")`); const sheetId = model.getters.getActiveSheetId(); - const listId = model.getters.getListIdFromPosition(sheetId, 0, 0); + const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 }); model.dispatch("SELECT_ODOO_LIST", { listId }); const selectedListId = model.getters.getSelectedListId(); assert.strictEqual(selectedListId, "1"); @@ -125,7 +125,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => { const { model } = await createSpreadsheetWithList(); setCellContent(model, "A1", `=3*ODOO.LIST("1","1","foo")`); const sheetId = model.getters.getActiveSheetId(); - const listId = model.getters.getListIdFromPosition(sheetId, 0, 0); + const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 }); model.dispatch("SELECT_ODOO_LIST", { listId }); const selectedListId = model.getters.getSelectedListId(); assert.strictEqual(selectedListId, "1"); @@ -143,7 +143,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => { const { model } = await createSpreadsheetWithList(); setCellContent(model, "A1", `=SUM(ODOO.LIST("1","1","foo"),1)`); const sheetId = model.getters.getActiveSheetId(); - const listId = model.getters.getListIdFromPosition(sheetId, 0, 0); + const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 }); model.dispatch("SELECT_ODOO_LIST", { listId }); const selectedListId = model.getters.getSelectedListId(); assert.strictEqual(selectedListId, "1"); @@ -156,7 +156,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => { setCellContent(model, "A1", `=ODOO.LIST(G10,"1","foo")`); setCellContent(model, "G10", "1"); const sheetId = model.getters.getActiveSheetId(); - const listId = model.getters.getListIdFromPosition(sheetId, 0, 0); + const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 }); model.dispatch("SELECT_ODOO_LIST", { listId }); const selectedListId = model.getters.getSelectedListId(); assert.strictEqual(selectedListId, "1"); diff --git a/addons/spreadsheet/static/tests/pivots/model/pivot_plugin_test.js b/addons/spreadsheet/static/tests/pivots/model/pivot_plugin_test.js index 24bd6d7ebb2..0659bae1260 100644 --- a/addons/spreadsheet/static/tests/pivots/model/pivot_plugin_test.js +++ b/addons/spreadsheet/static/tests/pivots/model/pivot_plugin_test.js @@ -28,7 +28,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => { `, }); const sheetId = model.getters.getActiveSheetId(); - const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2); + const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 }); model.dispatch("SELECT_PIVOT", { pivotId }); const selectedPivotId = model.getters.getSelectedPivotId(); assert.strictEqual(selectedPivotId, "1"); @@ -50,7 +50,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => { text: `=-PIVOT("1","probability","bar","false","foo","2")`, }); const sheetId = model.getters.getActiveSheetId(); - const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2); + const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 }); model.dispatch("SELECT_PIVOT", { pivotId }); const selectedPivotId = model.getters.getSelectedPivotId(); assert.strictEqual(selectedPivotId, "1"); @@ -73,7 +73,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => { text: `=3*PIVOT("1","probability","bar","false","foo","2")+2`, }); const sheetId = model.getters.getActiveSheetId(); - const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2); + const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 }); model.dispatch("SELECT_PIVOT", { pivotId }); const selectedPivotId = model.getters.getSelectedPivotId(); assert.strictEqual(selectedPivotId, "1"); @@ -96,7 +96,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => { text: `=SUM(PIVOT("1","probability","bar","false","foo","2"),PIVOT("1","probability","bar","false","foo","2"))`, }); const sheetId = model.getters.getActiveSheetId(); - const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2); + const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 }); model.dispatch("SELECT_PIVOT", { pivotId }); const selectedPivotId = model.getters.getSelectedPivotId(); assert.strictEqual(selectedPivotId, "1"); @@ -110,7 +110,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => { setCellContent(model, "C3", `=ODOO.PIVOT(G10,"probability","bar","false","foo","2")+2`); setCellContent(model, "G10", "1"); const sheetId = model.getters.getActiveSheetId(); - const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2); + const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 }); model.dispatch("SELECT_PIVOT", { pivotId }); const selectedPivotId = model.getters.getSelectedPivotId(); assert.strictEqual(selectedPivotId, "1"); @@ -133,7 +133,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => { text: `=3*SUM(PIVOT("1","probability","bar","false","foo","2"),PIVOT("1","probability","bar","false","foo","2"))+2*PIVOT("1","probability","bar","false","foo","2")`, }); const sheetId = model.getters.getActiveSheetId(); - const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2); + const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 }); model.dispatch("SELECT_PIVOT", { pivotId }); const selectedPivotId = model.getters.getSelectedPivotId(); assert.strictEqual(selectedPivotId, "1"); diff --git a/addons/spreadsheet/static/tests/utils/chart.js b/addons/spreadsheet/static/tests/utils/chart.js index aa8c0957e0d..113e58be098 100644 --- a/addons/spreadsheet/static/tests/utils/chart.js +++ b/addons/spreadsheet/static/tests/utils/chart.js @@ -38,7 +38,7 @@ export async function createSpreadsheetWithChart(params = {}) { insertChartInSpreadsheet(model, params.type); - const env = model.config.evalContext.env; + const env = model.config.external.env; env.model = model; await nextTick(); return { model, env }; diff --git a/addons/spreadsheet/static/tests/utils/getters.js b/addons/spreadsheet/static/tests/utils/getters.js index a55f0b6461e..471e0d01a47 100644 --- a/addons/spreadsheet/static/tests/utils/getters.js +++ b/addons/spreadsheet/static/tests/utils/getters.js @@ -18,7 +18,7 @@ export function getCellValue(model, xc, sheetId = model.getters.getActiveSheetId */ export function getCell(model, xc, sheetId = model.getters.getActiveSheetId()) { const { col, row } = toCartesian(xc); - return model.getters.getCell(sheetId, col, row); + return model.getters.getCell({ sheetId, col, row }); } export function getEvaluatedCell(model, xc, sheetId = model.getters.getActiveSheetId()) { diff --git a/addons/spreadsheet/static/tests/utils/list.js b/addons/spreadsheet/static/tests/utils/list.js index 5ea6502ef0b..faf52dd925c 100644 --- a/addons/spreadsheet/static/tests/utils/list.js +++ b/addons/spreadsheet/static/tests/utils/list.js @@ -62,7 +62,7 @@ export async function createSpreadsheetWithList(params = {}) { sheetId: params.sheetId, }); - const env = model.config.evalContext.env; + const env = model.config.external.env; env.model = model; await waitForDataSourcesLoaded(model); return { model, env }; diff --git a/addons/spreadsheet/static/tests/utils/model.js b/addons/spreadsheet/static/tests/utils/model.js index 31a4a7e9de3..fe75b039fe5 100644 --- a/addons/spreadsheet/static/tests/utils/model.js +++ b/addons/spreadsheet/static/tests/utils/model.js @@ -16,7 +16,7 @@ const { Model } = spreadsheet; */ export function setupDataSourceEvaluation(model) { - model.config.dataSources.addEventListener("data-source-updated", () => { + model.config.external.dataSources.addEventListener("data-source-updated", () => { const sheetId = model.getters.getActiveSheetId(); model.dispatch("EVALUATE_CELLS", { sheetId }); }); @@ -37,9 +37,10 @@ export async function createModelWithDataSource(params = {}) { mockRPC: params.mockRPC, }); const model = new Model(params.spreadsheetData, { - evalContext: { env }, - //@ts-ignore - dataSources: new DataSources(env.services.orm.silent), + external: { + env, + dataSources: new DataSources(env.services.orm.silent), + }, }); setupDataSourceEvaluation(model); await nextTick(); // initial async formulas loading @@ -61,7 +62,7 @@ export async function waitForDataSourcesLoaded(model) { // Read a first time in order to trigger the RPC readAllCellsValue(); //@ts-ignore - await model.config.dataSources.waitForAllLoaded(); + await model.config.external.dataSources.waitForAllLoaded(); await nextTick(); // Read a second time to trigger the compute format (which could trigger a RPC for currency, in list) readAllCellsValue(); diff --git a/addons/spreadsheet/static/tests/utils/pivot.js b/addons/spreadsheet/static/tests/utils/pivot.js index 1ff20fdf088..39af528544c 100644 --- a/addons/spreadsheet/static/tests/utils/pivot.js +++ b/addons/spreadsheet/static/tests/utils/pivot.js @@ -32,7 +32,7 @@ export async function insertPivotInSpreadsheet(model, params) { }, name: "Partner Pivot", }; - const dataSource = model.config.dataSources.create(PivotDataSource, definition); + const dataSource = model.config.external.dataSources.create(PivotDataSource, definition); await dataSource.load(); const { cols, rows, measures } = dataSource.getTableStructure().export(); const table = { @@ -68,7 +68,7 @@ export async function createSpreadsheetWithPivot(params = {}) { }); const arch = params.arch || serverData.views["partner,false,pivot"]; await insertPivotInSpreadsheet(model, { arch }); - const env = model.config.evalContext.env; + const env = model.config.external.env; env.model = model; await waitForDataSourcesLoaded(model); return { model, env }; diff --git a/addons/spreadsheet/static/tests/utils/ui.js b/addons/spreadsheet/static/tests/utils/ui.js index 24acf92b838..182bfc8c221 100644 --- a/addons/spreadsheet/static/tests/utils/ui.js +++ b/addons/spreadsheet/static/tests/utils/ui.js @@ -21,7 +21,7 @@ export async function mountSpreadsheet(model) { const app = new App(Spreadsheet, { props: { model }, templates: templates, - env: model.config.evalContext.env, + env: model.config.external.env, test: true, }); registerCleanup(() => app.destroy()); diff --git a/addons/spreadsheet_account/static/src/index.js b/addons/spreadsheet_account/static/src/index.js index 88c7e8e6117..339905b9b27 100644 --- a/addons/spreadsheet_account/static/src/index.js +++ b/addons/spreadsheet_account/static/src/index.js @@ -17,9 +17,8 @@ cellMenuRegistry.add("move_lines_see_records", { name: _lt("See records"), sequence: 176, async action(env) { - const sheetId = env.model.getters.getActiveSheetId(); - const { col, row } = env.model.getters.getPosition(); - const cell = env.model.getters.getCell(sheetId, col, row); + const position = env.model.getters.getActivePosition(); + const cell = env.model.getters.getCell(position); const { args } = getFirstAccountFunction(cell.content); let [code, date_range, offset, companyId, includeUnposted] = args .map(astToFormula) @@ -38,11 +37,9 @@ cellMenuRegistry.add("move_lines_see_records", { await env.services.action.doAction(action); }, isVisible: (env) => { - const sheetId = env.model.getters.getActiveSheetId(); - const { col, row } = env.model.getters.getPosition(); - const position = env.model.getters.getMainCellPosition(sheetId, col, row); - const evaluatedCell = env.model.getters.getEvaluatedCell({ sheetId, ...position }); - const cell = env.model.getters.getCell(sheetId, position.col, position.row); + const position = env.model.getters.getActivePosition(); + const evaluatedCell = env.model.getters.getEvaluatedCell(position); + const cell = env.model.getters.getCell(position); return ( !evaluatedCell.error && evaluatedCell.value !== "" && diff --git a/addons/spreadsheet_account/static/src/plugins/accounting_plugin.js b/addons/spreadsheet_account/static/src/plugins/accounting_plugin.js index aa689a0a3c1..cd1e780a544 100644 --- a/addons/spreadsheet_account/static/src/plugins/accounting_plugin.js +++ b/addons/spreadsheet_account/static/src/plugins/accounting_plugin.js @@ -9,9 +9,9 @@ const DATA_SOURCE_ID = "ACCOUNTING_AGGREGATES"; */ export default class AccountingPlugin extends spreadsheet.UIPlugin { - constructor(getters, history, dispatch, config) { - super(getters, history, dispatch, config); - this.dataSources = config.dataSources; + constructor(config) { + super(config); + this.dataSources = config.external.dataSources; if (this.dataSources) { this.dataSources.add(DATA_SOURCE_ID, AccountingDataSource); } diff --git a/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js b/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js index b3a44dbc77d..6fe9062ebc1 100644 --- a/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js +++ b/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js @@ -62,7 +62,7 @@ QUnit.module("spreadsheet_account > Accounting Drill down", { beforeEach }, () = } }, }); - const env = model.config.evalContext.env; + const env = model.config.external.env; env.model = model; setCellContent(model, "A1", `=ODOO.BALANCE("100", 2020)`); setCellContent(model, "A2", `=ODOO.BALANCE("100", 0)`); diff --git a/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/dashboard_loader.js b/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/dashboard_loader.js index 7a43ab79464..c59f41bb23a 100644 --- a/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/dashboard_loader.js +++ b/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/dashboard_loader.js @@ -211,9 +211,8 @@ export class DashboardLoader { const model = new Model( migrate(JSON.parse(data)), { - evalContext: { env: this.env, orm: this.orm }, + external: { env: this.env, orm: this.orm, dataSources }, mode: "dashboard", - dataSources, }, revisions ); diff --git a/addons/spreadsheet_dashboard/static/src/bundle/pivot/clickable_cell.js b/addons/spreadsheet_dashboard/static/src/bundle/pivot/clickable_cell.js index 4bcd425a482..d57b6ccb85e 100644 --- a/addons/spreadsheet_dashboard/static/src/bundle/pivot/clickable_cell.js +++ b/addons/spreadsheet_dashboard/static/src/bundle/pivot/clickable_cell.js @@ -14,15 +14,15 @@ clickableCellRegistry.add("pivot", { clickableCellRegistry.add("pivot_set_filter_matching", { condition: (position, env) => { - const cell = env.model.getters.getCell(position.sheetId, position.col, position.row); + const cell = env.model.getters.getCell(position); return ( SEE_RECORDS_PIVOT_VISIBLE(position, env) && getFirstPivotFunction(cell.content).functionName === "ODOO.PIVOT.HEADER" && env.model.getters.getFiltersMatchingPivot(cell.content).length > 0 ); }, - action: ({ sheetId, col, row }, env) => { - const cell = env.model.getters.getCell(sheetId, col, row); + action: (position, env) => { + const cell = env.model.getters.getCell(position); const filters = env.model.getters.getFiltersMatchingPivot(cell.content); env.model.dispatch("SET_MANY_GLOBAL_FILTER_VALUE", { filters }); },